]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon.qh
cf0f637f0324d614da2ffe5212cf408a5988f357
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon.qh
1 #pragma once
2
3 #include <common/items/item/pickup.qh>
4 #include <common/resources/resources.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, Resource, 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     /** M: deprecated refname : old reference name for compatibility with weapons that were renamed */
80     ATTRIB(Weapon, m_deprecated_netname, string, "");
81
82     ATTRIB(Weapon, m_pickup, entity);
83
84     /** (SERVER) setup weapon data */
85     METHOD(Weapon, wr_setup, void(Weapon this, entity actor, .entity weaponentity)) {}
86     /** (SERVER) logic to run every frame */
87     METHOD(Weapon, wr_think, void(Weapon this, entity actor, .entity weaponentity, int fire)) {}
88     /** (SERVER) checks ammo for weapon primary */
89     METHOD(Weapon, wr_checkammo1, bool(Weapon this, entity actor, .entity weaponentity)) {return false;}
90     /** (SERVER) checks ammo for weapon second */
91     METHOD(Weapon, wr_checkammo2, bool(Weapon this, entity actor, .entity weaponentity)) {return false;}
92     /** (SERVER) runs bot aiming code for this weapon */
93     METHOD(Weapon, wr_aim, void(Weapon this, entity actor, .entity weaponentity)) {}
94     /** (BOTH)   precaches models/sounds used by this weapon, also sets up weapon properties */
95     METHOD(Weapon, wr_init, void(Weapon this)) {}
96     /** (SERVER) notification number for suicide message (may inspect w_deathtype for details) */
97     METHOD(Weapon, wr_suicidemessage, entity(Weapon this)) {return NULL;}
98     /** (SERVER) notification number for kill message (may inspect w_deathtype for details) */
99     METHOD(Weapon, wr_killmessage, entity(Weapon this)) {return NULL;}
100     /** (SERVER) handles reloading for weapon */
101     METHOD(Weapon, wr_reload, void(Weapon this, entity actor, .entity weaponentity)) {}
102     /** (SERVER) clears fields that the weapon may use */
103     METHOD(Weapon, wr_resetplayer, void(Weapon this, entity actor)) {}
104     /** (CLIENT) impact effect for weapon explosion */
105     METHOD(Weapon, wr_impacteffect, void(Weapon this, entity actor)) {}
106     /** (SERVER) called whenever a player dies */
107     METHOD(Weapon, wr_playerdeath, void(Weapon this, entity actor, .entity weaponentity)) {}
108     /** (SERVER) logic to run when weapon is lost */
109     METHOD(Weapon, wr_gonethink, void(Weapon this, entity actor, .entity weaponentity)) {}
110     /** (SERVER) dump weapon cvars to config in data directory (see: sv_cmd dumpweapons) */
111     METHOD(Weapon, wr_config, void(Weapon this)) {}
112     /** (BOTH) weapon specific zoom reticle */
113     METHOD(Weapon, wr_zoom, bool(Weapon this, entity actor)) {
114         // no weapon specific image for this weapon
115         return false;
116     }
117     /** (CLIENT) check whether the weapon should zoom (special handling) */
118     METHOD(Weapon, wr_zoomdir, bool(Weapon this)) {return false;}
119     /** (CLIENT) weapon specific view model */
120     METHOD(Weapon, wr_viewmodel, string(Weapon this, entity wep)) { return string_null; }
121     /** (BOTH) weapon specific glow */
122     METHOD(Weapon, wr_glow, vector(Weapon this, int actor_colors, entity wepent)) { return '0 0 0'; }
123     /** (SERVER) the weapon is dropped */
124     METHOD(Weapon, wr_drop, void(Weapon this, entity actor, .entity weaponentity)) {}
125     /** (SERVER) a weapon is picked up */
126     METHOD(Weapon, wr_pickup, void(Weapon this, entity actor, .entity weaponentity)) {}
127     /** (SERVER) update cvar based properties */
128     METHOD(Weapon, wr_update, void(Weapon this)) {}
129         METHOD(Weapon, display, void(entity this, void(string name, string icon) returns)) {
130                 returns(this.m_name, this.model2 ? sprintf("/gfx/hud/%s/%s", cvar_string("menu_skin"), this.model2) : string_null);
131         }
132 ENDCLASS(Weapon)
133
134 #ifdef SVQC
135
136 void weapon_defaultspawnfunc(entity this, Weapon e);
137 #define SPAWNFUNC_WEAPON(name, weapon) \
138     spawnfunc(name) { weapon_defaultspawnfunc(this, weapon); }
139
140 #define SPAWNFUNC_WEAPON_COND(name, cond, wep1, wep2) \
141         SPAWNFUNC_WEAPON(name, (cond ? wep1 : wep2))
142
143 #else
144
145 #define SPAWNFUNC_WEAPON(name, weapon)
146
147 #endif
148
149 #include <common/items/_mod.qh>
150 CLASS(WeaponPickup, Pickup)
151     ATTRIB(WeaponPickup, m_weapon, Weapon);
152     ATTRIB(WeaponPickup, m_name, string);
153 #ifdef GAMEQC
154     ATTRIB(WeaponPickup, m_sound, Sound, SND_WEAPONPICKUP);
155 #endif
156 #ifdef SVQC
157     ATTRIB(WeaponPickup, m_itemflags, int, FL_WEAPON);
158     float weapon_pickupevalfunc(entity player, entity item);
159     ATTRIB(WeaponPickup, m_pickupevalfunc, float(entity player, entity item), weapon_pickupevalfunc);
160 #endif
161     CONSTRUCTOR(WeaponPickup, Weapon w) {
162         CONSTRUCT(WeaponPickup);
163         this.m_weapon = w;
164         this.m_name = w.m_name;
165 #ifdef GAMEQC
166         this.m_model = w.m_model;
167 #endif
168 #ifdef SVQC
169         this.m_botvalue = w.bot_pickupbasevalue;
170 #endif
171     }
172 #ifdef SVQC
173     METHOD(WeaponPickup, giveTo, bool(entity this, entity item, entity player))
174     {
175         bool b = Item_GiveTo(item, player);
176         //if (b) {
177             //LOG_TRACEF("entity %i picked up %s", player, this.m_name);
178         //}
179         return b;
180     }
181 #endif
182 ENDCLASS(WeaponPickup)
183
184 CLASS(OffhandWeapon, Object)
185     METHOD(OffhandWeapon, offhand_think, void(OffhandWeapon this, entity player, bool key_pressed)) {}
186 ENDCLASS(OffhandWeapon)
187
188 #ifdef SVQC
189 .OffhandWeapon offhand;
190 #endif
191
192 #ifdef GAMEQC
193 int max_shot_distance = 32768; // determined by world mins/maxs when map loads
194 #endif
195
196 // weapon flags
197 const int WEP_TYPE_OTHER          =  BIT(0); // not for damaging people
198 const int WEP_TYPE_SPLASH         =  BIT(1); // splash damage
199 const int WEP_TYPE_HITSCAN        =  BIT(2); // hitscan
200 const int WEP_FLAG_CANCLIMB       =  BIT(3); // can be used for movement
201 const int WEP_FLAG_NORMAL         =  BIT(4); // in "most weapons" set
202 const int WEP_FLAG_HIDDEN         =  BIT(5); // hides from menu
203 const int WEP_FLAG_RELOADABLE     =  BIT(6); // can has reload
204 const int WEP_FLAG_SUPERWEAPON    =  BIT(7); // powerup timer
205 const int WEP_FLAG_MUTATORBLOCKED =  BIT(8); // hides from impulse 99 etc. (mutators are allowed to clear this flag)
206 const int WEP_TYPE_MELEE_PRI      =  BIT(9); // primary attack is melee swing (for animation)
207 const int WEP_TYPE_MELEE_SEC      =  BIT(10); // secondary attack is melee swing (for animation)
208 const int WEP_FLAG_DUALWIELD      =  BIT(11); // weapon can be dual wielded
209 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
210 const int WEP_FLAG_PENETRATEWALLS =  BIT(13); // weapon has high calibur bullets that can penetrate thick walls (WEAPONTODO)
211 const int WEP_FLAG_BLEED          =  BIT(14); // weapon pierces and causes bleeding (used for damage effects)
212 const int WEP_FLAG_NOTRUEAIM      =  BIT(15); // weapon doesn't aim directly at targets
213 const int WEP_FLAG_SPECIALATTACK  =  BIT(16); // marked as a special attack (not a true weapon), hidden from most weapon lists
214
215 // variables:
216 string weaponorder_byid;
217
218 // functions:
219 string W_FixWeaponOrder(string order, float complete);
220 string W_NameWeaponOrder(string order);
221 string W_NumberWeaponOrder(string order);
222 string W_FixWeaponOrder_BuildImpulseList(string o);
223 string W_FixWeaponOrder_AllowIncomplete(entity this, string order);
224 string W_FixWeaponOrder_ForceComplete(string order);
225 WepSet W_RandomWeapons(entity e, WepSet remaining, int n);
226
227 string GetAmmoPicture(Resource ammotype);
228
229 string GetAmmoName(Resource ammotype);
230
231 entity GetAmmoItem(Resource ammotype);
232
233 #ifdef CSQC
234 int GetAmmoStat(Resource ammotype);
235 #endif
236
237 string W_Sound(string w_snd);
238 string W_Model(string w_mdl);