3 #include <common/resources.qh>
4 #include <common/items/item/pickup.qh>
5 #include <common/stats.qh>
8 #include <common/effects/qc/_mod.qh>
11 USING(WepSet, vector);
13 const int MAX_WEAPONSLOTS = 2;
14 .entity weaponentities[MAX_WEAPONSLOTS];
16 int weaponslot(.entity weaponentity)
18 for (int i = 0; i < MAX_WEAPONSLOTS; ++i)
20 if (weaponentities[i] == weaponentity)
28 // weapon states (actor.(weaponentity).state)
29 /** no weapon selected */
30 const int WS_CLEAR = 0;
32 const int WS_RAISE = 1;
33 /** deselecting frame */
34 const int WS_DROP = 2;
36 const int WS_INUSE = 3;
38 const int WS_READY = 4;
40 /** fields which are explicitly/manually set are marked with "M", fields set automatically are marked with "A" */
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, RESOURCE_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 /** M: model MDL_id_ITEM */
60 ATTRIB(Weapon, m_model, entity);
61 /** M: crosshair : per-weapon crosshair: "CrosshairImage Size" */
62 ATTRIB(Weapon, w_crosshair, string, "gfx/crosshairmoustache");
63 /** A: crosshair : per-weapon crosshair size (argument two of "crosshair" field) */
64 ATTRIB(Weapon, w_crosshair_size, float, 1);
65 /** A: reticle : per-weapon zoom reticle */
66 ATTRIB(Weapon, w_reticle, string, string_null);
67 /** M: wepimg : "weaponfoobar" side view image file of weapon. WEAPONTODO: Move out of skin files, move to common files */
68 ATTRIB(Weapon, model2, string, "");
69 /** M: refname : reference name name */
70 ATTRIB(Weapon, netname, string, "");
71 /** M: wepname : human readable name */
72 ATTRIB(Weapon, m_name, string, "AOL CD Thrower");
74 ATTRIB(Weapon, m_pickup, entity);
76 /** (SERVER) setup weapon data */
77 METHOD(Weapon, wr_setup, void(Weapon this, entity actor, .entity weaponentity)) {}
78 /** (SERVER) logic to run every frame */
79 METHOD(Weapon, wr_think, void(Weapon this, entity actor, .entity weaponentity, int fire)) {}
80 /** (SERVER) checks ammo for weapon primary */
81 METHOD(Weapon, wr_checkammo1, bool(Weapon this, entity actor, .entity weaponentity)) {return false;}
82 /** (SERVER) checks ammo for weapon second */
83 METHOD(Weapon, wr_checkammo2, bool(Weapon this, entity actor, .entity weaponentity)) {return false;}
84 /** (SERVER) runs bot aiming code for this weapon */
85 METHOD(Weapon, wr_aim, void(Weapon this, entity actor, .entity weaponentity)) {}
86 /** (BOTH) precaches models/sounds used by this weapon, also sets up weapon properties */
87 METHOD(Weapon, wr_init, void(Weapon this)) {}
88 /** (SERVER) notification number for suicide message (may inspect w_deathtype for details) */
89 METHOD(Weapon, wr_suicidemessage, entity(Weapon this)) {return NULL;}
90 /** (SERVER) notification number for kill message (may inspect w_deathtype for details) */
91 METHOD(Weapon, wr_killmessage, entity(Weapon this)) {return NULL;}
92 /** (SERVER) handles reloading for weapon */
93 METHOD(Weapon, wr_reload, void(Weapon this, entity actor, .entity weaponentity)) {}
94 /** (SERVER) clears fields that the weapon may use */
95 METHOD(Weapon, wr_resetplayer, void(Weapon this, entity actor)) {}
96 /** (CLIENT) impact effect for weapon explosion */
97 METHOD(Weapon, wr_impacteffect, void(Weapon this, entity actor)) {}
98 /** (SERVER) called whenever a player dies */
99 METHOD(Weapon, wr_playerdeath, void(Weapon this, entity actor, .entity weaponentity)) {}
100 /** (SERVER) logic to run when weapon is lost */
101 METHOD(Weapon, wr_gonethink, void(Weapon this, entity actor, .entity weaponentity)) {}
102 /** (ALL) dump weapon cvars to config in data directory (see: sv_cmd dumpweapons) */
103 METHOD(Weapon, wr_config, void(Weapon this)) {}
104 /** (BOTH) weapon specific zoom reticle */
105 METHOD(Weapon, wr_zoom, bool(Weapon this, entity actor)) {
106 // no weapon specific image for this weapon
109 /** (CLIENT) check whether the weapon should zoom (special handling) */
110 METHOD(Weapon, wr_zoomdir, bool(Weapon this)) {return false;}
111 /** (CLIENT) weapon specific view model */
112 METHOD(Weapon, wr_viewmodel, string(Weapon this, entity wep)) { return string_null; }
113 /** (CLIENT) weapon specific glow */
114 METHOD(Weapon, wr_glow, vector(Weapon this, entity actor, entity wepent)) { return '0 0 0'; }
115 /** (SERVER) the weapon is dropped */
116 METHOD(Weapon, wr_drop, void(Weapon this, entity actor, .entity weaponentity)) {}
117 /** (SERVER) a weapon is picked up */
118 METHOD(Weapon, wr_pickup, void(Weapon this, entity actor, .entity weaponentity)) {}
119 /** (SERVER) update cvar based properties */
120 METHOD(Weapon, wr_update, void(Weapon this)) {}
121 METHOD(Weapon, display, void(entity this, void(string name, string icon) returns)) {
122 returns(this.m_name, this.model2 ? sprintf("/gfx/hud/%s/%s", cvar_string("menu_skin"), this.model2) : string_null);
128 void weapon_defaultspawnfunc(entity this, Weapon e);
129 #define SPAWNFUNC_WEAPON(name, weapon) \
130 spawnfunc(name) { weapon_defaultspawnfunc(this, weapon); }
134 #define SPAWNFUNC_WEAPON(name, weapon)
138 #include <common/items/_mod.qh>
139 CLASS(WeaponPickup, Pickup)
140 ATTRIB(WeaponPickup, m_weapon, Weapon);
141 ATTRIB(WeaponPickup, m_name, string);
143 ATTRIB(WeaponPickup, m_sound, Sound, SND_WEAPONPICKUP);
146 ATTRIB(WeaponPickup, m_itemflags, int, FL_WEAPON);
147 float weapon_pickupevalfunc(entity player, entity item);
148 ATTRIB(WeaponPickup, m_pickupevalfunc, float(entity player, entity item), weapon_pickupevalfunc);
150 CONSTRUCTOR(WeaponPickup, Weapon w) {
151 CONSTRUCT(WeaponPickup);
153 this.m_name = w.m_name;
155 this.m_model = w.m_model;
158 this.m_botvalue = w.bot_pickupbasevalue;
162 METHOD(WeaponPickup, giveTo, bool(entity this, entity item, entity player))
164 bool b = Item_GiveTo(item, player);
166 LOG_TRACEF("entity %i picked up %s", player, this.m_name);
171 ENDCLASS(WeaponPickup)
173 CLASS(OffhandWeapon, Object)
174 METHOD(OffhandWeapon, offhand_think, void(OffhandWeapon this, entity player, bool key_pressed)) {}
175 ENDCLASS(OffhandWeapon)
178 .OffhandWeapon offhand;
182 int max_shot_distance = 32768; // determined by world mins/maxs when map loads
186 const int WEP_TYPE_OTHER = BIT(0); // not for damaging people
187 const int WEP_TYPE_SPLASH = BIT(1); // splash damage
188 const int WEP_TYPE_HITSCAN = BIT(2); // hitscan
189 const int WEP_FLAG_CANCLIMB = BIT(3); // can be used for movement
190 const int WEP_FLAG_NORMAL = BIT(4); // in "most weapons" set
191 const int WEP_FLAG_HIDDEN = BIT(5); // hides from menu
192 const int WEP_FLAG_RELOADABLE = BIT(6); // can has reload
193 const int WEP_FLAG_SUPERWEAPON = BIT(7); // powerup timer
194 const int WEP_FLAG_MUTATORBLOCKED = BIT(8); // hides from impulse 99 etc. (mutators are allowed to clear this flag)
195 const int WEP_TYPE_MELEE_PRI = BIT(9); // primary attack is melee swing (for animation)
196 const int WEP_TYPE_MELEE_SEC = BIT(10); // secondary attack is melee swing (for animation)
197 const int WEP_FLAG_DUALWIELD = BIT(11); // weapon can be dual wielded
198 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
199 const int WEP_FLAG_PENETRATEWALLS = BIT(13); // weapon has high calibur bullets that can penetrate thick walls (WEAPONTODO)
202 string weaponorder_byid;
205 string W_FixWeaponOrder(string order, float complete);
206 string W_UndeprecateName(string s);
207 string W_NameWeaponOrder(string order);
208 string W_NumberWeaponOrder(string order);
209 string W_FixWeaponOrder_BuildImpulseList(string o);
210 string W_FixWeaponOrder_AllowIncomplete(entity this, string order);
211 string W_FixWeaponOrder_ForceComplete(string order);
212 WepSet W_RandomWeapons(entity e, WepSet remaining, int n);
214 string GetAmmoPicture(int ammotype);
217 int GetAmmoTypeFromNum(int i);
218 int GetAmmoStat(int ammotype);
221 string W_Sound(string w_snd);
222 string W_Model(string w_mdl);