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;
45 .int ammo_plasma = _STAT(PLASMA);
46 .int ammo_fuel = _STAT(FUEL);
58 /** fields which are explicitly/manually set are marked with "M", fields set automatically are marked with "A" */
60 ATTRIB(Weapon, m_id, int, 0);
61 /** the canonical spawnfunc name */
62 ATTRIB(Weapon, m_canonical_spawnfunc, string);
63 /** control what happens when this weapon is spawned */
64 METHOD(Weapon, m_spawnfunc_hookreplace, Weapon(Weapon this, entity e)) { return this; }
65 /** A: WEPSET_id : WEPSET_... */
66 ATTRIB(Weapon, weapons, WepSet, '0 0 0');
67 /** M: ammotype : main ammo type */
68 ATTRIB(Weapon, ammo_type, int, RESOURCE_NONE);
69 /** M: impulse : weapon impulse */
70 ATTRIB(Weapon, impulse, int, -1);
71 /** M: flags : WEPSPAWNFLAG_... combined */
72 ATTRIB(Weapon, spawnflags, int, 0);
73 /** M: rating : bot weapon priority */
74 ATTRIB(Weapon, bot_pickupbasevalue, float, 0);
75 /** M: color : waypointsprite color */
76 ATTRIB(Weapon, wpcolor, vector, '0 0 0');
77 /** M: modelname : name of model (without g_ v_ or h_ prefixes) */
78 ATTRIB(Weapon, mdl, string, "");
79 /** M: model MDL_id_ITEM */
80 ATTRIB(Weapon, m_model, entity);
81 /** M: crosshair : per-weapon crosshair: "CrosshairImage Size" */
82 ATTRIB(Weapon, w_crosshair, string, "gfx/crosshairmoustache");
83 /** A: crosshair : per-weapon crosshair size (argument two of "crosshair" field) */
84 ATTRIB(Weapon, w_crosshair_size, float, 1);
85 /** A: reticle : per-weapon zoom reticle */
86 ATTRIB(Weapon, w_reticle, string, string_null);
87 /** M: wepimg : "weaponfoobar" side view image file of weapon. WEAPONTODO: Move out of skin files, move to common files */
88 ATTRIB(Weapon, model2, string, "");
89 /** M: refname : reference name name */
90 ATTRIB(Weapon, netname, string, "");
91 /** M: wepname : human readable name */
92 ATTRIB(Weapon, m_name, string, "AOL CD Thrower");
94 ATTRIB(Weapon, m_pickup, entity);
96 /** (SERVER) setup weapon data */
97 METHOD(Weapon, wr_setup, void(Weapon this, entity actor, .entity weaponentity)) {}
98 /** (SERVER) logic to run every frame */
99 METHOD(Weapon, wr_think, void(Weapon this, entity actor, .entity weaponentity, int fire)) {}
100 /** (SERVER) checks ammo for weapon primary */
101 METHOD(Weapon, wr_checkammo1, bool(Weapon this, entity actor, .entity weaponentity)) {return false;}
102 /** (SERVER) checks ammo for weapon second */
103 METHOD(Weapon, wr_checkammo2, bool(Weapon this, entity actor, .entity weaponentity)) {return false;}
104 /** (SERVER) runs bot aiming code for this weapon */
105 METHOD(Weapon, wr_aim, void(Weapon this, entity actor, .entity weaponentity)) {}
106 /** (BOTH) precaches models/sounds used by this weapon, also sets up weapon properties */
107 METHOD(Weapon, wr_init, void(Weapon this)) {}
108 /** (SERVER) notification number for suicide message (may inspect w_deathtype for details) */
109 METHOD(Weapon, wr_suicidemessage, entity(Weapon this)) {return NULL;}
110 /** (SERVER) notification number for kill message (may inspect w_deathtype for details) */
111 METHOD(Weapon, wr_killmessage, entity(Weapon this)) {return NULL;}
112 /** (SERVER) handles reloading for weapon */
113 METHOD(Weapon, wr_reload, void(Weapon this, entity actor, .entity weaponentity)) {}
114 /** (SERVER) clears fields that the weapon may use */
115 METHOD(Weapon, wr_resetplayer, void(Weapon this, entity actor)) {}
116 /** (CLIENT) impact effect for weapon explosion */
117 METHOD(Weapon, wr_impacteffect, void(Weapon this, entity actor)) {}
118 /** (SERVER) called whenever a player dies */
119 METHOD(Weapon, wr_playerdeath, void(Weapon this, entity actor, .entity weaponentity)) {}
120 /** (SERVER) logic to run when weapon is lost */
121 METHOD(Weapon, wr_gonethink, void(Weapon this, entity actor, .entity weaponentity)) {}
122 /** (ALL) dump weapon cvars to config in data directory (see: sv_cmd dumpweapons) */
123 METHOD(Weapon, wr_config, void(Weapon this)) {}
124 /** (BOTH) weapon specific zoom reticle */
125 METHOD(Weapon, wr_zoom, bool(Weapon this, entity actor)) {
126 // no weapon specific image for this weapon
129 /** (CLIENT) weapon specific view model */
130 METHOD(Weapon, wr_viewmodel, string(Weapon this, entity wep)) { return string_null; }
131 /** (CLIENT) weapon specific glow */
132 METHOD(Weapon, wr_glow, vector(Weapon this, entity actor, entity wepent)) { return '0 0 0'; }
133 /** (SERVER) the weapon is dropped */
134 METHOD(Weapon, wr_drop, void(Weapon this, entity actor, .entity weaponentity)) {}
135 /** (SERVER) a weapon is picked up */
136 METHOD(Weapon, wr_pickup, void(Weapon this, entity actor, .entity weaponentity)) {}
137 /** (SERVER) update cvar based properties */
138 METHOD(Weapon, wr_update, void(Weapon this)) {}
139 METHOD(Weapon, display, void(entity this, void(string name, string icon) returns)) {
140 returns(this.m_name, this.model2 ? sprintf("/gfx/hud/%s/%s", cvar_string("menu_skin"), this.model2) : string_null);
146 void weapon_defaultspawnfunc(entity this, Weapon e);
147 #define SPAWNFUNC_WEAPON(name, weapon) \
148 spawnfunc(name) { weapon_defaultspawnfunc(this, weapon); }
152 #define SPAWNFUNC_WEAPON(name, weapon)
156 #include <common/items/_mod.qh>
157 CLASS(WeaponPickup, Pickup)
158 ATTRIB(WeaponPickup, m_weapon, Weapon);
159 ATTRIB(WeaponPickup, m_name, string);
161 ATTRIB(WeaponPickup, m_sound, Sound, SND_WEAPONPICKUP);
164 ATTRIB(WeaponPickup, m_itemflags, int, FL_WEAPON);
165 float weapon_pickupevalfunc(entity player, entity item);
166 ATTRIB(WeaponPickup, m_pickupevalfunc, float(entity player, entity item), weapon_pickupevalfunc);
168 CONSTRUCTOR(WeaponPickup, Weapon w) {
169 CONSTRUCT(WeaponPickup);
171 this.m_name = w.m_name;
173 this.m_model = w.m_model;
176 this.m_botvalue = w.bot_pickupbasevalue;
180 METHOD(WeaponPickup, giveTo, bool(entity this, entity item, entity player))
182 bool b = Item_GiveTo(item, player);
184 LOG_TRACEF("entity %i picked up %s", player, this.m_name);
189 ENDCLASS(WeaponPickup)
191 CLASS(OffhandWeapon, Object)
192 METHOD(OffhandWeapon, offhand_think, void(OffhandWeapon this, entity player, bool key_pressed)) {}
193 ENDCLASS(OffhandWeapon)
196 .OffhandWeapon offhand;
200 int max_shot_distance = 32768; // determined by world mins/maxs when map loads
204 const int WEP_TYPE_OTHER = 0x00; // not for damaging people
205 const int WEP_TYPE_SPLASH = 0x01; // splash damage
206 const int WEP_TYPE_HITSCAN = 0x02; // hitscan
207 const int WEP_TYPEMASK = 0x0F;
208 const int WEP_FLAG_CANCLIMB = 0x10; // can be used for movement
209 const int WEP_FLAG_NORMAL = 0x20; // in "most weapons" set
210 const int WEP_FLAG_HIDDEN = 0x40; // hides from menu
211 const int WEP_FLAG_RELOADABLE = 0x80; // can has reload
212 const int WEP_FLAG_SUPERWEAPON = 0x100; // powerup timer
213 const int WEP_FLAG_MUTATORBLOCKED = 0x200; // hides from impulse 99 etc. (mutators are allowed to clear this flag)
214 const int WEP_TYPE_MELEE_PRI = 0x400; // primary attack is melee swing (for animation)
215 const int WEP_TYPE_MELEE_SEC = 0x800; // secondary attack is melee swing (for animation)
216 const int WEP_FLAG_DUALWIELD = 0x1000; // weapon can be dual wielded
217 const int WEP_FLAG_NODUAL = 0x2000; // weapon doesn't work well with dual wielding (fireball etc just explode on fire), doesn't currently prevent anything
218 const int WEP_FLAG_PENETRATEWALLS = 0x4000; // weapon has high calibur bullets that can penetrate thick walls (WEAPONTODO)
221 string weaponorder_byid;
224 string W_FixWeaponOrder(string order, float complete);
225 string W_UndeprecateName(string s);
226 string W_NameWeaponOrder(string order);
227 string W_NumberWeaponOrder(string order);
228 string W_FixWeaponOrder_BuildImpulseList(string o);
229 string W_FixWeaponOrder_AllowIncomplete(entity this, string order);
230 string W_FixWeaponOrder_ForceComplete(string order);
231 void W_RandomWeapons(entity e, int n);
233 string GetAmmoPicture(int ammotype);
236 int GetAmmoTypeFromNum(int i);
237 int GetAmmoStat(int ammotype);
240 string W_Sound(string w_snd);
241 string W_Model(string w_mdl);