Xonotic
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 
12 
13 const int MAX_WEAPONSLOTS = 2;
15 
16 int weaponslot(.entity weaponentity)
17 {
18  for (int i = 0; i < MAX_WEAPONSLOTS; ++i)
19  {
20  if (weaponentities[i] == weaponentity)
21  {
22  return i;
23  }
24  }
25  return 0;
26 }
27 
28 // weapon states (actor.(weaponentity).state)
30 const int WS_CLEAR = 0;
32 const int WS_RAISE = 1;
34 const int WS_DROP = 2;
36 const int WS_INUSE = 3;
38 const int WS_READY = 4;
39 
42  ATTRIB(Weapon, m_id, int, 0);
44  ATTRIB(Weapon, m_canonical_spawnfunc, string);
46  METHOD(Weapon, m_spawnfunc_hookreplace, Weapon(Weapon this, entity e)) { return this; }
48  ATTRIB(Weapon, ammo_type, Resource, RES_NONE);
50  ATTRIB(Weapon, impulse, int, -1);
56  ATTRIB(Weapon, wpcolor, vector, '0 0 0');
58  ATTRIB(Weapon, mdl, string, "");
59 #ifdef GAMEQC
60 
61  ATTRIB(Weapon, m_model, entity);
63  ATTRIB(Weapon, m_muzzlemodel, entity, MDL_Null);
65  ATTRIB(Weapon, m_muzzleeffect, entity);
66 #endif
67 
68  ATTRIB(Weapon, w_crosshair, string, "gfx/crosshairmoustache");
70  ATTRIB(Weapon, w_crosshair_size, float, 1);
72  ATTRIB(Weapon, w_reticle, string, string_null);
74  ATTRIB(Weapon, model2, string, "");
76  ATTRIB(Weapon, netname, string, "");
78  ATTRIB(Weapon, m_name, string, "AOL CD Thrower");
79 
80  ATTRIB(Weapon, m_pickup, entity);
81 
83  METHOD(Weapon, wr_setup, void(Weapon this, entity actor, .entity weaponentity)) {}
85  METHOD(Weapon, wr_think, void(Weapon this, entity actor, .entity weaponentity, int fire)) {}
87  METHOD(Weapon, wr_checkammo1, bool(Weapon this, entity actor, .entity weaponentity)) {return false;}
89  METHOD(Weapon, wr_checkammo2, bool(Weapon this, entity actor, .entity weaponentity)) {return false;}
91  METHOD(Weapon, wr_aim, void(Weapon this, entity actor, .entity weaponentity)) {}
93  METHOD(Weapon, wr_init, void(Weapon this)) {}
95  METHOD(Weapon, wr_suicidemessage, entity(Weapon this)) {return NULL;}
97  METHOD(Weapon, wr_killmessage, entity(Weapon this)) {return NULL;}
99  METHOD(Weapon, wr_reload, void(Weapon this, entity actor, .entity weaponentity)) {}
101  METHOD(Weapon, wr_resetplayer, void(Weapon this, entity actor)) {}
103  METHOD(Weapon, wr_impacteffect, void(Weapon this, entity actor)) {}
105  METHOD(Weapon, wr_playerdeath, void(Weapon this, entity actor, .entity weaponentity)) {}
107  METHOD(Weapon, wr_gonethink, void(Weapon this, entity actor, .entity weaponentity)) {}
109  METHOD(Weapon, wr_config, void(Weapon this)) {}
111  METHOD(Weapon, wr_zoom, bool(Weapon this, entity actor)) {
112  // no weapon specific image for this weapon
113  return false;
114  }
116  METHOD(Weapon, wr_zoomdir, bool(Weapon this)) {return false;}
118  METHOD(Weapon, wr_viewmodel, string(Weapon this, entity wep)) { return string_null; }
120  METHOD(Weapon, wr_glow, vector(Weapon this, entity actor, entity wepent)) { return '0 0 0'; }
122  METHOD(Weapon, wr_drop, void(Weapon this, entity actor, .entity weaponentity)) {}
124  METHOD(Weapon, wr_pickup, void(Weapon this, entity actor, .entity weaponentity)) {}
126  METHOD(Weapon, wr_update, void(Weapon this)) {}
127  METHOD(Weapon, display, void(entity this, void(string name, string icon) returns)) {
128  returns(this.m_name, this.model2 ? sprintf("/gfx/hud/%s/%s", cvar_string("menu_skin"), this.model2) : string_null);
129  }
131 
132 #ifdef SVQC
133 
135 #define SPAWNFUNC_WEAPON(name, weapon) \
136  spawnfunc(name) { weapon_defaultspawnfunc(this, weapon); }
137 
138 #define SPAWNFUNC_WEAPON_COND(name, cond, wep1, wep2) \
139  SPAWNFUNC_WEAPON(name, (cond ? wep1 : wep2))
140 
141 #else
142 
143 #define SPAWNFUNC_WEAPON(name, weapon)
144 
145 #endif
146 
147 #include <common/items/_mod.qh>
149  ATTRIB(WeaponPickup, m_weapon, Weapon);
150  ATTRIB(WeaponPickup, m_name, string);
151 #ifdef GAMEQC
152  ATTRIB(WeaponPickup, m_sound, Sound, SND_WEAPONPICKUP);
153 #endif
154 #ifdef SVQC
155  ATTRIB(WeaponPickup, m_itemflags, int, FL_WEAPON);
156  float weapon_pickupevalfunc(entity player, entity item);
157  ATTRIB(WeaponPickup, m_pickupevalfunc, float(entity player, entity item), weapon_pickupevalfunc);
158 #endif
161  this.m_weapon = w;
162  this.m_name = w.m_name;
163 #ifdef GAMEQC
164  this.m_model = w.m_model;
165 #endif
166 #ifdef SVQC
167  this.m_botvalue = w.bot_pickupbasevalue;
168 #endif
169  }
170 #ifdef SVQC
171  METHOD(WeaponPickup, giveTo, bool(entity this, entity item, entity player))
172  {
173  bool b = Item_GiveTo(item, player);
174  //if (b) {
175  //LOG_TRACEF("entity %i picked up %s", player, this.m_name);
176  //}
177  return b;
178  }
179 #endif
181 
183  METHOD(OffhandWeapon, offhand_think, void(OffhandWeapon this, entity player, bool key_pressed)) {}
185 
186 #ifdef SVQC
187 .OffhandWeapon offhand;
188 #endif
189 
190 #ifdef GAMEQC
191 int max_shot_distance = 32768; // determined by world mins/maxs when map loads
192 #endif
193 
194 // weapon flags
195 const int WEP_TYPE_OTHER = BIT(0); // not for damaging people
196 const int WEP_TYPE_SPLASH = BIT(1); // splash damage
197 const int WEP_TYPE_HITSCAN = BIT(2); // hitscan
198 const int WEP_FLAG_CANCLIMB = BIT(3); // can be used for movement
199 const int WEP_FLAG_NORMAL = BIT(4); // in "most weapons" set
200 const int WEP_FLAG_HIDDEN = BIT(5); // hides from menu
201 const int WEP_FLAG_RELOADABLE = BIT(6); // can has reload
202 const int WEP_FLAG_SUPERWEAPON = BIT(7); // powerup timer
203 const int WEP_FLAG_MUTATORBLOCKED = BIT(8); // hides from impulse 99 etc. (mutators are allowed to clear this flag)
204 const int WEP_TYPE_MELEE_PRI = BIT(9); // primary attack is melee swing (for animation)
205 const int WEP_TYPE_MELEE_SEC = BIT(10); // secondary attack is melee swing (for animation)
206 const int WEP_FLAG_DUALWIELD = BIT(11); // weapon can be dual wielded
207 const 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
208 const int WEP_FLAG_PENETRATEWALLS = BIT(13); // weapon has high calibur bullets that can penetrate thick walls (WEAPONTODO)
209 const int WEP_FLAG_BLEED = BIT(14); // weapon pierces and causes bleeding (used for damage effects)
210 const int WEP_FLAG_NOTRUEAIM = BIT(15); // weapon doesn't aim directly at targets
211 const int WEP_FLAG_SPECIALATTACK = BIT(16); // marked as a special attack (not a true weapon), hidden from most weapon lists
212 
213 // variables:
215 
216 // functions:
217 string W_FixWeaponOrder(string order, float complete);
218 string W_UndeprecateName(string s);
219 string W_NameWeaponOrder(string order);
220 string W_NumberWeaponOrder(string order);
221 string W_FixWeaponOrder_BuildImpulseList(string o);
222 string W_FixWeaponOrder_AllowIncomplete(entity this, string order);
223 string W_FixWeaponOrder_ForceComplete(string order);
224 WepSet W_RandomWeapons(entity e, WepSet remaining, int n);
225 
226 string GetAmmoPicture(Resource ammotype);
227 
228 string GetAmmoName(Resource ammotype);
229 
230 entity GetAmmoItem(Resource ammotype);
231 
232 #ifdef CSQC
233 Resource GetAmmoTypeFromNum(int i);
234 
235 int GetAmmoStat(Resource ammotype);
236 #endif
237 
238 string W_Sound(string w_snd);
239 string W_Model(string w_mdl);
string W_Sound(string w_snd)
Definition: all.qc:281
vector WepSet
Definition: weapon.qh:11
const int WEP_FLAG_PENETRATEWALLS
Definition: weapon.qh:208
const int WEP_FLAG_NODUAL
Definition: weapon.qh:207
string GetAmmoPicture(Resource ammotype)
Definition: all.qc:206
void weapon_defaultspawnfunc(entity this, Weapon wpn)
Definition: spawning.qc:30
string string_null
Definition: nil.qh:9
const int WEP_FLAG_RELOADABLE
Definition: weapon.qh:201
string W_UndeprecateName(string s)
Definition: all.qc:110
const int WS_RAISE
raise frame
Definition: weapon.qh:32
string W_FixWeaponOrder_ForceComplete(string order)
Definition: all.qc:182
CLASS(Object) Object
Definition: oo.qh:318
const int WS_CLEAR
no weapon selected
Definition: weapon.qh:30
string W_FixWeaponOrder(string order, float complete)
Definition: all.qc:95
entity() spawn
string netname
Definition: powerups.qc:20
string m_name
M: wepname : human readable name.
Definition: weapon.qh:78
float bot_pickupbasevalue
Definition: bot.qh:66
entity GetAmmoItem(Resource ammotype)
Definition: all.qc:234
Definition: pickup.qh:22
const int WS_DROP
deselecting frame
Definition: weapon.qh:34
const int WEP_FLAG_HIDDEN
Definition: weapon.qh:200
#define METHOD(cname, name, prototype)
Definition: oo.qh:257
#define CONSTRUCT(cname,...)
Definition: oo.qh:111
const int WS_READY
idle frame
Definition: weapon.qh:38
const int WEP_TYPE_SPLASH
Definition: weapon.qh:196
string W_FixWeaponOrder_AllowIncomplete(entity this, string order)
Definition: all.qc:177
float impulse
Definition: progsdefs.qc:158
float spawnflags
Definition: progsdefs.qc:191
#define ATTRIB(...)
Definition: oo.qh:136
int weaponslot(.entity weaponentity)
Definition: weapon.qh:16
string W_Model(string w_mdl)
Definition: all.qc:288
float bot_pickupbasevalue
M: rating : bot weapon priority.
Definition: weapon.qh:54
int m_id
Definition: effect.qh:19
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition: bits.qh:8
string W_FixWeaponOrder_BuildImpulseList(string o)
Definition: all.qc:162
float weapon_pickupevalfunc(entity player, entity item)
Definition: items.qc:799
const int MAX_WEAPONSLOTS
Definition: weapon.qh:13
const int WEP_TYPE_MELEE_SEC
Definition: weapon.qh:205
#define NULL
Definition: post.qh:17
entity this
Definition: self.qh:83
Definition: sound.qh:119
string W_NumberWeaponOrder(string order)
Definition: all.qc:136
string weaponorder_byid
Definition: weapon.qh:214
const int WEP_TYPE_OTHER
Definition: weapon.qh:195
vector(float skel, float bonenum) _skel_get_boneabs_hidden
const int WEP_FLAG_CANCLIMB
Definition: weapon.qh:198
const int WS_INUSE
fire state
Definition: weapon.qh:36
const int WEP_FLAG_SPECIALATTACK
Definition: weapon.qh:211
string W_NameWeaponOrder(string order)
Definition: all.qc:125
WepSet W_RandomWeapons(entity e, WepSet remaining, int n)
Definition: all.qc:188
#define ENDCLASS(cname)
Definition: oo.qh:269
const int WEP_FLAG_NOTRUEAIM
Definition: weapon.qh:210
entity weaponentities[MAX_WEAPONSLOTS]
Definition: weapon.qh:14
bool Item_GiveTo(entity item, entity player)
Definition: items.qc:479
string GetAmmoName(Resource ammotype)
Definition: all.qc:220
const int WEP_FLAG_NORMAL
Definition: weapon.qh:199
const int WEP_FLAG_MUTATORBLOCKED
Definition: weapon.qh:203
#define USING(name, T)
Definition: _all.inc:72
const int WEP_FLAG_DUALWIELD
Definition: weapon.qh:206
const int WEP_FLAG_BLEED
Definition: weapon.qh:209
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition: weapon.qh:41
#define CONSTRUCTOR(cname,...)
Definition: oo.qh:201
const int WEP_TYPE_HITSCAN
Definition: weapon.qh:197
const int WEP_FLAG_SUPERWEAPON
Definition: weapon.qh:202
const int WEP_TYPE_MELEE_PRI
Definition: weapon.qh:204
string m_name
Definition: scores.qh:135