]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon.qh
Merge branch 'terencehill/noclip_death_fix' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon.qh
1 #pragma once
2
3 #include <common/resources.qh>
4 #include <common/items/item/pickup.qh>
5 #include <common/stats.qh>
6
7 #ifdef SVQC
8 #include <common/effects/qc/_mod.qh>
9 #endif
10
11 USING(WepSet, vector);
12
13 const int MAX_WEAPONSLOTS = 2;
14 .entity weaponentities[MAX_WEAPONSLOTS];
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)
29 /** no weapon selected */
30 const int WS_CLEAR  = 0;
31 /** raise frame */
32 const int WS_RAISE  = 1;
33 /** deselecting frame */
34 const int WS_DROP   = 2;
35 /** fire state */
36 const int WS_INUSE  = 3;
37 /** idle frame */
38 const int WS_READY  = 4;
39
40 /** fields which are explicitly/manually set are marked with "M", fields set automatically are marked with "A" */
41 CLASS(Weapon, Object)
42         ATTRIB(Weapon, m_id, int, 0);
43         /** the canonical spawnfunc name */
44     ATTRIB(Weapon, m_canonical_spawnfunc, string);
45     /** control what happens when this weapon is spawned */
46     METHOD(Weapon, m_spawnfunc_hookreplace, Weapon(Weapon this, entity e)) { return this; }
47     /** M: ammotype  : main ammo type */
48     ATTRIB(Weapon, ammo_type, int, RES_NONE);
49     /** M: impulse   : weapon impulse */
50     ATTRIB(Weapon, impulse, int, -1);
51     /** M: flags     : WEPSPAWNFLAG_... combined */
52     ATTRIB(Weapon, spawnflags, int, 0);
53     /** M: rating    : bot weapon priority */
54     ATTRIB(Weapon, bot_pickupbasevalue, float, 0);
55     /** M: color     : waypointsprite color */
56     ATTRIB(Weapon, wpcolor, vector, '0 0 0');
57     /** M: modelname : name of model (without g_ v_ or h_ prefixes) */
58     ATTRIB(Weapon, mdl, string, "");
59 #ifdef GAMEQC
60     /** M: model MDL_id_ITEM */
61     ATTRIB(Weapon, m_model, entity);
62     /** M: flash model MDL_id_MUZZLEFLASH */
63     ATTRIB(Weapon, m_muzzlemodel, entity, MDL_Null);
64     /** M: flash effect EFFECT_id_MUZZLEFLASH */
65     ATTRIB(Weapon, m_muzzleeffect, entity);
66 #endif
67     /** M: crosshair : per-weapon crosshair: "CrosshairImage Size" */
68     ATTRIB(Weapon, w_crosshair, string, "gfx/crosshairmoustache");
69     /** A: crosshair : per-weapon crosshair size (argument two of "crosshair" field) */
70     ATTRIB(Weapon, w_crosshair_size, float, 1);
71     /** A: reticle   : per-weapon zoom reticle */
72     ATTRIB(Weapon, w_reticle, string, string_null);
73     /** M: wepimg    : "weaponfoobar" side view image file of weapon. WEAPONTODO: Move out of skin files, move to common files */
74     ATTRIB(Weapon, model2, string, "");
75     /** M: refname   : reference name name */
76     ATTRIB(Weapon, netname, string, "");
77     /** M: wepname   : human readable name */
78     ATTRIB(Weapon, m_name, string, "AOL CD Thrower");
79
80     ATTRIB(Weapon, m_pickup, entity);
81
82     /** (SERVER) setup weapon data */
83     METHOD(Weapon, wr_setup, void(Weapon this, entity actor, .entity weaponentity)) {}
84     /** (SERVER) logic to run every frame */
85     METHOD(Weapon, wr_think, void(Weapon this, entity actor, .entity weaponentity, int fire)) {}
86     /** (SERVER) checks ammo for weapon primary */
87     METHOD(Weapon, wr_checkammo1, bool(Weapon this, entity actor, .entity weaponentity)) {return false;}
88     /** (SERVER) checks ammo for weapon second */
89     METHOD(Weapon, wr_checkammo2, bool(Weapon this, entity actor, .entity weaponentity)) {return false;}
90     /** (SERVER) runs bot aiming code for this weapon */
91     METHOD(Weapon, wr_aim, void(Weapon this, entity actor, .entity weaponentity)) {}
92     /** (BOTH)   precaches models/sounds used by this weapon, also sets up weapon properties */
93     METHOD(Weapon, wr_init, void(Weapon this)) {}
94     /** (SERVER) notification number for suicide message (may inspect w_deathtype for details) */
95     METHOD(Weapon, wr_suicidemessage, entity(Weapon this)) {return NULL;}
96     /** (SERVER) notification number for kill message (may inspect w_deathtype for details) */
97     METHOD(Weapon, wr_killmessage, entity(Weapon this)) {return NULL;}
98     /** (SERVER) handles reloading for weapon */
99     METHOD(Weapon, wr_reload, void(Weapon this, entity actor, .entity weaponentity)) {}
100     /** (SERVER) clears fields that the weapon may use */
101     METHOD(Weapon, wr_resetplayer, void(Weapon this, entity actor)) {}
102     /** (CLIENT) impact effect for weapon explosion */
103     METHOD(Weapon, wr_impacteffect, void(Weapon this, entity actor)) {}
104     /** (SERVER) called whenever a player dies */
105     METHOD(Weapon, wr_playerdeath, void(Weapon this, entity actor, .entity weaponentity)) {}
106     /** (SERVER) logic to run when weapon is lost */
107     METHOD(Weapon, wr_gonethink, void(Weapon this, entity actor, .entity weaponentity)) {}
108     /** (SERVER) dump weapon cvars to config in data directory (see: sv_cmd dumpweapons) */
109     METHOD(Weapon, wr_config, void(Weapon this)) {}
110     /** (BOTH) weapon specific zoom reticle */
111     METHOD(Weapon, wr_zoom, bool(Weapon this, entity actor)) {
112         // no weapon specific image for this weapon
113         return false;
114     }
115     /** (CLIENT) check whether the weapon should zoom (special handling) */
116     METHOD(Weapon, wr_zoomdir, bool(Weapon this)) {return false;}
117     /** (CLIENT) weapon specific view model */
118     METHOD(Weapon, wr_viewmodel, string(Weapon this, entity wep)) { return string_null; }
119     /** (BOTH) weapon specific glow */
120     METHOD(Weapon, wr_glow, vector(Weapon this, entity actor, entity wepent)) { return '0 0 0'; }
121     /** (SERVER) the weapon is dropped */
122     METHOD(Weapon, wr_drop, void(Weapon this, entity actor, .entity weaponentity)) {}
123     /** (SERVER) a weapon is picked up */
124     METHOD(Weapon, wr_pickup, void(Weapon this, entity actor, .entity weaponentity)) {}
125     /** (SERVER) update cvar based properties */
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         }
130 ENDCLASS(Weapon)
131
132 #ifdef SVQC
133
134 void weapon_defaultspawnfunc(entity this, Weapon e);
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(name) \
140     { \
141         entity wep = (cond) ? wep1 : wep2; \
142         weapon_defaultspawnfunc(this, wep); \
143     }
144
145 #else
146
147 #define SPAWNFUNC_WEAPON(name, weapon)
148
149 #endif
150
151 #include <common/items/_mod.qh>
152 CLASS(WeaponPickup, Pickup)
153     ATTRIB(WeaponPickup, m_weapon, Weapon);
154     ATTRIB(WeaponPickup, m_name, string);
155 #ifdef GAMEQC
156     ATTRIB(WeaponPickup, m_sound, Sound, SND_WEAPONPICKUP);
157 #endif
158 #ifdef SVQC
159     ATTRIB(WeaponPickup, m_itemflags, int, FL_WEAPON);
160     float weapon_pickupevalfunc(entity player, entity item);
161     ATTRIB(WeaponPickup, m_pickupevalfunc, float(entity player, entity item), weapon_pickupevalfunc);
162 #endif
163     CONSTRUCTOR(WeaponPickup, Weapon w) {
164         CONSTRUCT(WeaponPickup);
165         this.m_weapon = w;
166         this.m_name = w.m_name;
167 #ifdef GAMEQC
168         this.m_model = w.m_model;
169 #endif
170 #ifdef SVQC
171         this.m_botvalue = w.bot_pickupbasevalue;
172 #endif
173     }
174 #ifdef SVQC
175     METHOD(WeaponPickup, giveTo, bool(entity this, entity item, entity player))
176     {
177         bool b = Item_GiveTo(item, player);
178         //if (b) {
179             //LOG_TRACEF("entity %i picked up %s", player, this.m_name);
180         //}
181         return b;
182     }
183 #endif
184 ENDCLASS(WeaponPickup)
185
186 CLASS(OffhandWeapon, Object)
187     METHOD(OffhandWeapon, offhand_think, void(OffhandWeapon this, entity player, bool key_pressed)) {}
188 ENDCLASS(OffhandWeapon)
189
190 #ifdef SVQC
191 .OffhandWeapon offhand;
192 #endif
193
194 #ifdef GAMEQC
195 int max_shot_distance = 32768; // determined by world mins/maxs when map loads
196 #endif
197
198 // weapon flags
199 const int WEP_TYPE_OTHER          =  BIT(0); // not for damaging people
200 const int WEP_TYPE_SPLASH         =  BIT(1); // splash damage
201 const int WEP_TYPE_HITSCAN        =  BIT(2); // hitscan
202 const int WEP_FLAG_CANCLIMB       =  BIT(3); // can be used for movement
203 const int WEP_FLAG_NORMAL         =  BIT(4); // in "most weapons" set
204 const int WEP_FLAG_HIDDEN         =  BIT(5); // hides from menu
205 const int WEP_FLAG_RELOADABLE     =  BIT(6); // can has reload
206 const int WEP_FLAG_SUPERWEAPON    =  BIT(7); // powerup timer
207 const int WEP_FLAG_MUTATORBLOCKED =  BIT(8); // hides from impulse 99 etc. (mutators are allowed to clear this flag)
208 const int WEP_TYPE_MELEE_PRI      =  BIT(9); // primary attack is melee swing (for animation)
209 const int WEP_TYPE_MELEE_SEC      =  BIT(10); // secondary attack is melee swing (for animation)
210 const int WEP_FLAG_DUALWIELD      =  BIT(11); // weapon can be dual wielded
211 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
212 const int WEP_FLAG_PENETRATEWALLS =  BIT(13); // weapon has high calibur bullets that can penetrate thick walls (WEAPONTODO)
213 const int WEP_FLAG_BLEED          =  BIT(14); // weapon pierces and causes bleeding (used for damage effects)
214 const int WEP_FLAG_NOTRUEAIM      =  BIT(15); // weapon doesn't aim directly at targets
215 const int WEP_FLAG_SPECIALATTACK  =  BIT(16); // marked as a special attack (not a true weapon), hidden from most weapon lists
216
217 // variables:
218 string weaponorder_byid;
219
220 // functions:
221 string W_FixWeaponOrder(string order, float complete);
222 string W_UndeprecateName(string s);
223 string W_NameWeaponOrder(string order);
224 string W_NumberWeaponOrder(string order);
225 string W_FixWeaponOrder_BuildImpulseList(string o);
226 string W_FixWeaponOrder_AllowIncomplete(entity this, string order);
227 string W_FixWeaponOrder_ForceComplete(string order);
228 WepSet W_RandomWeapons(entity e, WepSet remaining, int n);
229
230 string GetAmmoPicture(int ammotype);
231
232 string GetAmmoName(int ammotype);
233
234 #ifdef CSQC
235 int GetAmmoTypeFromNum(int i);
236 int GetAmmoStat(int ammotype);
237 #endif
238
239 string W_Sound(string w_snd);
240 string W_Model(string w_mdl);