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