Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
weapon.qh
Go to the documentation of this file.
1#pragma once
2
5#include <common/stats.qh>
6
7#ifdef SVQC
9#endif
10#ifndef SVQC
11#include <common/util.qh> // for icon_path_from_HUDskin
12#endif
13
15
16const int MAX_WEAPONSLOTS = 2;
18
19int weaponslot(.entity weaponentity)
20{
21 for (int i = 0; i < MAX_WEAPONSLOTS; ++i)
22 if (weaponentities[i] == weaponentity)
23 return i;
24 return 0;
25}
26
27#ifdef GAMEQC
28// weapon states (actor.(weaponentity).state)
30const int WS_CLEAR = 0;
32const int WS_RAISE = 1;
34const int WS_DROP = 2;
36const int WS_INUSE = 3;
38const int WS_READY = 4;
39#endif
40
43 ATTRIB(Weapon, m_id, int, 0);
44#ifdef SVQC
46 ATTRIB(Weapon, m_canonical_spawnfunc, string);
49 {
50 return this;
51 }
52
54#endif
58 ATTRIB(Weapon, impulse, int, -1);
63#ifdef GAMEQC
65 ATTRIB(Weapon, mdl, string, "");
67 ATTRIB(Weapon, m_model, entity);
71 ATTRIB(Weapon, m_muzzleeffect, entity);
72#endif
73#ifdef CSQC
75 ATTRIB(Weapon, w_crosshair, string, "gfx/crosshairmoustache");
81#endif
82 ATTRIB(Weapon, model2, string, "");
84 ATTRIB(Weapon, netname, string, "");
86 ATTRIB(Weapon, m_name, string, "AOL CD Thrower");
89
90#ifdef GAMEQC
91 ATTRIB(Weapon, m_pickup, entity);
92#endif
93
94#ifdef SVQC
96 METHOD(Weapon, wr_setup, void(Weapon this, entity actor, .entity weaponentity)) { }
98 METHOD(Weapon, wr_think, void(Weapon this, entity actor, .entity weaponentity, int fire)) { }
100 METHOD(Weapon, wr_checkammo1, bool(Weapon this, entity actor, .entity weaponentity))
101 {
102 return false;
103 }
104
105 METHOD(Weapon, wr_checkammo2, bool(Weapon this, entity actor, .entity weaponentity))
106 {
107 return false;
108 }
109
110 METHOD(Weapon, wr_aim, void(Weapon this, entity actor, .entity weaponentity)) { }
111#endif
112#ifdef GAMEQC
114 METHOD(Weapon, wr_init, void(Weapon this)) { }
115#endif
116#ifdef SVQC
119 {
120 return NULL;
121 }
122
124 {
125 return NULL;
126 }
127
128 METHOD(Weapon, wr_reload, void(Weapon this, entity actor, .entity weaponentity)) { }
130 METHOD(Weapon, wr_resetplayer, void(Weapon this, entity actor)) { }
132 METHOD(Weapon, wr_impacteffect, void(Weapon this, entity actor)) { }
134 METHOD(Weapon, wr_playerdeath, void(Weapon this, entity actor, .entity weaponentity)) { }
136 METHOD(Weapon, wr_gonethink, void(Weapon this, entity actor, .entity weaponentity)) { }
138 METHOD(Weapon, wr_config, void(Weapon this)) { }
139#endif
140#ifdef GAMEQC
142 METHOD(Weapon, wr_glow, vector(Weapon this, int actor_colors, entity wepent))
143 {
144 return '0 0 0';
145 }
146
147 METHOD(Weapon, wr_zoom, bool(Weapon this, entity actor))
148 {
149 // no weapon specific image for this weapon
150 return false;
151 }
152#endif
153#ifdef CSQC
156 {
157 return false;
158 }
159
161 {
162 return string_null;
163 }
164#endif
165#ifdef SVQC
167 METHOD(Weapon, wr_drop, void(Weapon this, entity actor, .entity weaponentity)) { }
169 METHOD(Weapon, wr_pickup, void(Weapon this, entity actor, .entity weaponentity)) { }
171 METHOD(Weapon, wr_update, void(Weapon this)) { }
172#endif
173#ifdef MENUQC
174 METHOD(Weapon, describe, string(Weapon this))
175 {
176 TC(Weapon, this);
177 return SUPER(Weapon).describe(this);
178 }
179#endif
180#ifndef SVQC
181 METHOD(Weapon, display, void(Weapon this, void(string name, string icon) returns))
182 {
183 returns(this.m_name, icon_path_from_HUDskin(this.model2));
184 }
185#endif
187
188#ifdef SVQC
189
191#define SPAWNFUNC_WEAPON(name, weapon) \
192 spawnfunc(name) \
193 { \
194 weapon_defaultspawnfunc(this, weapon); \
195 }
196
197#else
198
199#define SPAWNFUNC_WEAPON(name, weapon)
200
201#endif
202
203#ifdef GAMEQC
207 ATTRIB(WeaponPickup, m_sound, Sound, SND_WEAPONPICKUP);
208#ifdef SVQC
211 ATTRIB(WeaponPickup, m_pickupevalfunc, float(entity player, entity item), weapon_pickupevalfunc);
212#endif
214 {
216 this.m_weapon = w;
217 this.m_name = w.m_name;
218 this.m_model = w.m_model;
219#ifdef SVQC
221#endif
222 }
223#ifdef SVQC
224 METHOD(WeaponPickup, giveTo, bool(entity this, entity item, entity player))
225 {
226 bool b = Item_GiveTo(item, player);
227 //if (b)
228 //LOG_TRACEF("entity %i picked up %s", player, this.m_name);
229 return b;
230 }
231#endif
233
234#endif
235
236#ifdef SVQC
240
241.OffhandWeapon offhand;
242#endif
243
244#ifdef GAMEQC
245int max_shot_distance = 32768; // determined by world mins/maxs when map loads
246#endif
247
248#ifdef CSQC
250#endif
251
252// weapon flags
253const int WEP_TYPE_OTHER = BIT(0); // not for damaging people
254const int WEP_TYPE_SPLASH = BIT(1); // splash damage
255const int WEP_TYPE_HITSCAN = BIT(2); // hitscan
256const int WEP_FLAG_CANCLIMB = BIT(3); // can be used for movement
257const int WEP_FLAG_NORMAL = BIT(4); // in "most weapons" set
258const int WEP_FLAG_HIDDEN = BIT(5); // hides from menu
259const int WEP_FLAG_RELOADABLE = BIT(6); // can has reload
260const int WEP_FLAG_SUPERWEAPON = BIT(7); // powerup timer
261const int WEP_FLAG_MUTATORBLOCKED = BIT(8); // hides from impulse 99 etc. (mutators are allowed to clear this flag)
262const int WEP_TYPE_MELEE_PRI = BIT(9); // primary attack is melee swing (for animation)
263const int WEP_TYPE_MELEE_SEC = BIT(10); // secondary attack is melee swing (for animation)
264const int WEP_FLAG_DUALWIELD = BIT(11); // weapon can be dual wielded
265const int WEP_FLAG_NODUAL = BIT(12); // weapon doesn't work well with dual wielding (fireball etc just explode on fire), doesn't currently prevent anything
266const int WEP_FLAG_PENETRATEWALLS = BIT(13); // weapon has high calibur bullets that can penetrate thick walls (WEAPONTODO)
267const int WEP_FLAG_BLEED = BIT(14); // weapon pierces and causes bleeding (used for damage effects)
268const int WEP_FLAG_NOTRUEAIM = BIT(15); // weapon doesn't aim directly at targets
269const int WEP_FLAG_SPECIALATTACK = BIT(16); // special attack (not a true weapon); NOTE: if this flag is set then WEP_FLAG_HIDDEN must be set as well
270
271// variables:
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition bits.qh:8
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
virtual void offhand_think()
Definition weapon.qh:238
int m_botvalue
Definition pickup.qh:23
ATTRIB(WeaponPickup, m_weapon, Weapon)
virtual void giveTo()
Definition weapon.qh:224
WeaponPickup(Weapon w)
Definition weapon.qh:213
float weapon_pickupevalfunc(entity player, entity item)
int m_itemflags
Definition weapon.qh:209
Sound m_sound
Definition weapon.qh:207
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition weapon.qh:42
int impulse
M: impulse : weapon impulse.
Definition weapon.qh:58
virtual void wr_suicidemessage()
(SERVER) notification number for suicide message (may inspect w_deathtype for details)
Definition weapon.qh:118
virtual void wr_setup()
(SERVER) setup weapon data
Definition weapon.qh:96
virtual void wr_reload()
(SERVER) handles reloading for weapon
Definition weapon.qh:128
virtual void m_spawnfunc_hookreplace()
control what happens when this weapon is spawned
Definition weapon.qh:48
virtual void wr_think()
(SERVER) logic to run every frame
Definition weapon.qh:98
Resource ammo_type
M: ammotype : main ammo type.
Definition weapon.qh:56
string m_name
M: wepname : human readable name.
Definition weapon.qh:86
virtual void wr_impacteffect()
(CLIENT) impact effect for weapon explosion
Definition weapon.qh:132
virtual void wr_update()
(SERVER) update cvar based properties
Definition weapon.qh:171
ATTRIB(Weapon, m_pickup, entity)
virtual void wr_playerdeath()
(SERVER) called whenever a player dies
Definition weapon.qh:134
string w_crosshair
M: crosshair : per-weapon crosshair: "CrosshairImage Size".
Definition weapon.qh:75
vector m_color
M: color : waypointsprite color.
Definition weapon.qh:62
virtual void wr_glow()
(BOTH) weapon specific glow
Definition weapon.qh:142
virtual void wr_drop()
(SERVER) the weapon is dropped
Definition weapon.qh:167
string mdl
M: modelname : name of model (without g_ v_ or h_ prefixes)
Definition weapon.qh:65
ATTRIB(Weapon, m_canonical_spawnfunc, string)
the canonical spawnfunc name
int m_id
Definition weapon.qh:43
virtual void wr_aim()
(SERVER) runs bot aiming code for this weapon
Definition weapon.qh:110
virtual void wr_checkammo2()
(SERVER) checks ammo for weapon second
Definition weapon.qh:105
string netname
M: refname : reference name name.
Definition weapon.qh:84
virtual void wr_zoomdir()
(CLIENT) check whether the weapon should zoom (special handling)
Definition weapon.qh:155
virtual void wr_killmessage()
(SERVER) notification number for kill message (may inspect w_deathtype for details)
Definition weapon.qh:123
ATTRIB(Weapon, m_model, entity)
M: model MDL_id_ITEM.
virtual void wr_zoom()
(BOTH) weapon specific zoom reticle
Definition weapon.qh:147
int spawnflags
M: flags : WEPSPAWNFLAG_... combined.
Definition weapon.qh:60
virtual void wr_pickup()
(SERVER) a weapon is picked up
Definition weapon.qh:169
virtual void wr_init()
(BOTH) precaches models/sounds used by this weapon, also sets up weapon properties
Definition weapon.qh:114
float w_crosshair_size
A: crosshair : per-weapon crosshair size (argument two of "crosshair" field)
Definition weapon.qh:77
virtual void wr_checkammo1()
(SERVER) checks ammo for weapon primary
Definition weapon.qh:100
ATTRIB(Weapon, m_muzzleeffect, entity)
M: flash effect EFFECT_id_MUZZLEFLASH.
virtual void wr_gonethink()
(SERVER) logic to run when weapon is lost
Definition weapon.qh:136
string model2
M: wepimg : "weaponfoobar" side view image file of weapon.
Definition weapon.qh:82
virtual void wr_config()
(SERVER) dump weapon cvars to config in data directory (see: sv_cmd dumpweapons)
Definition weapon.qh:138
entity m_muzzlemodel
M: flash model MDL_id_MUZZLEFLASH.
Definition weapon.qh:69
string m_deprecated_netname
M: deprecated refname : old reference name for compatibility with weapons that were renamed.
Definition weapon.qh:88
virtual void describe()
Definition weapon.qh:174
string w_reticle
A: reticle : per-weapon zoom reticle.
Definition weapon.qh:79
virtual void wr_viewmodel()
(CLIENT) weapon specific view model
Definition weapon.qh:160
float bot_pickupbasevalue
M: rating : bot weapon priority.
Definition weapon.qh:53
virtual void wr_resetplayer()
(SERVER) clears fields that the weapon may use
Definition weapon.qh:130
string m_name
Definition scores.qh:142
const int FL_WEAPON
Definition constants.qh:83
entity() spawn
#define USING(name, T)
Definition _all.inc:72
#define TC(T, sym)
Definition _all.inc:82
string name
Definition menu.qh:30
string string_null
Definition nil.qh:9
#define SUPER(cname)
Definition oo.qh:231
#define CLASS(...)
Definition oo.qh:145
#define ENDCLASS(cname)
Definition oo.qh:281
#define METHOD(cname, name, prototype)
Definition oo.qh:269
#define ATTRIB(...)
Definition oo.qh:148
#define CONSTRUCTOR(cname,...)
Definition oo.qh:213
#define CONSTRUCT(cname,...)
Definition oo.qh:123
#define NULL
Definition post.qh:14
vector
Definition self.qh:92
entity this
Definition self.qh:72
bool Item_GiveTo(entity item, entity player)
Definition items.qc:522
string model2
const int WEP_FLAG_CANCLIMB
Definition weapon.qh:256
const int MAX_WEAPONSLOTS
Definition weapon.qh:16
const int WEP_FLAG_RELOADABLE
Definition weapon.qh:259
string weaponorder_byid
Definition weapon.qh:272
const int WEP_FLAG_NOTRUEAIM
Definition weapon.qh:268
const int WEP_TYPE_HITSCAN
Definition weapon.qh:255
const int WS_READY
idle frame
Definition weapon.qh:38
void weapon_defaultspawnfunc(entity this, Weapon e)
Definition spawning.qc:29
const int WEP_TYPE_MELEE_PRI
Definition weapon.qh:262
const int WEP_TYPE_SPLASH
Definition weapon.qh:254
int max_shot_distance
Definition weapon.qh:245
entity weaponentities[MAX_WEAPONSLOTS]
Definition weapon.qh:17
const int WS_CLEAR
no weapon selected
Definition weapon.qh:30
int autocvar_cl_tracers_teamcolor
Definition weapon.qh:249
const int WEP_FLAG_BLEED
Definition weapon.qh:267
const int WS_RAISE
raise frame
Definition weapon.qh:32
const int WEP_FLAG_SUPERWEAPON
Definition weapon.qh:260
const int WS_INUSE
fire state
Definition weapon.qh:36
const int WEP_FLAG_MUTATORBLOCKED
Definition weapon.qh:261
const int WEP_FLAG_DUALWIELD
Definition weapon.qh:264
vector WepSet
Definition weapon.qh:14
const int WEP_TYPE_MELEE_SEC
Definition weapon.qh:263
OffhandWeapon offhand
Definition weapon.qh:241
const int WEP_FLAG_PENETRATEWALLS
Definition weapon.qh:266
int weaponslot(.entity weaponentity)
Definition weapon.qh:19
const int WEP_FLAG_NODUAL
Definition weapon.qh:265
const int WEP_FLAG_HIDDEN
Definition weapon.qh:258
const int WS_DROP
deselecting frame
Definition weapon.qh:34
const int WEP_TYPE_OTHER
Definition weapon.qh:253
const int WEP_FLAG_NORMAL
Definition weapon.qh:257
const int WEP_FLAG_SPECIALATTACK
Definition weapon.qh:269
Weapon m_weapon
Definition wepent.qh:26