3 #include <common/items/item/pickup.qh>
4 #include <common/resources/resources.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, 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, "");
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);
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");
80 ATTRIB(Weapon, m_pickup, entity);
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
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);
134 void weapon_defaultspawnfunc(entity this, Weapon e);
135 #define SPAWNFUNC_WEAPON(name, weapon) \
136 spawnfunc(name) { weapon_defaultspawnfunc(this, weapon); }
138 #define SPAWNFUNC_WEAPON_COND(name, cond, wep1, wep2) \
139 SPAWNFUNC_WEAPON(name, (cond ? wep1 : wep2))
143 #define SPAWNFUNC_WEAPON(name, weapon)
147 #include <common/items/_mod.qh>
148 CLASS(WeaponPickup, Pickup)
149 ATTRIB(WeaponPickup, m_weapon, Weapon);
150 ATTRIB(WeaponPickup, m_name, string);
152 ATTRIB(WeaponPickup, m_sound, Sound, SND_WEAPONPICKUP);
155 ATTRIB(WeaponPickup, m_itemflags, int, FL_WEAPON);
156 float weapon_pickupevalfunc(entity player, entity item);
157 ATTRIB(WeaponPickup, m_pickupevalfunc, float(entity player, entity item), weapon_pickupevalfunc);
159 CONSTRUCTOR(WeaponPickup, Weapon w) {
160 CONSTRUCT(WeaponPickup);
162 this.m_name = w.m_name;
164 this.m_model = w.m_model;
167 this.m_botvalue = w.bot_pickupbasevalue;
171 METHOD(WeaponPickup, giveTo, bool(entity this, entity item, entity player))
173 bool b = Item_GiveTo(item, player);
175 //LOG_TRACEF("entity %i picked up %s", player, this.m_name);
180 ENDCLASS(WeaponPickup)
182 CLASS(OffhandWeapon, Object)
183 METHOD(OffhandWeapon, offhand_think, void(OffhandWeapon this, entity player, bool key_pressed)) {}
184 ENDCLASS(OffhandWeapon)
187 .OffhandWeapon offhand;
191 int max_shot_distance = 32768; // determined by world mins/maxs when map loads
195 const int WEP_TYPE_OTHER = BIT(0); // not for damaging people
196 const int WEP_TYPE_SPLASH = BIT(1); // splash damage
197 const int WEP_TYPE_HITSCAN = BIT(2); // hitscan
198 const int WEP_FLAG_CANCLIMB = BIT(3); // can be used for movement
199 const int WEP_FLAG_NORMAL = BIT(4); // in "most weapons" set
200 const int WEP_FLAG_HIDDEN = BIT(5); // hides from menu
201 const int WEP_FLAG_RELOADABLE = BIT(6); // can has reload
202 const int WEP_FLAG_SUPERWEAPON = BIT(7); // powerup timer
203 const int WEP_FLAG_MUTATORBLOCKED = BIT(8); // hides from impulse 99 etc. (mutators are allowed to clear this flag)
204 const int WEP_TYPE_MELEE_PRI = BIT(9); // primary attack is melee swing (for animation)
205 const int WEP_TYPE_MELEE_SEC = BIT(10); // secondary attack is melee swing (for animation)
206 const int WEP_FLAG_DUALWIELD = BIT(11); // weapon can be dual wielded
207 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
208 const int WEP_FLAG_PENETRATEWALLS = BIT(13); // weapon has high calibur bullets that can penetrate thick walls (WEAPONTODO)
209 const int WEP_FLAG_BLEED = BIT(14); // weapon pierces and causes bleeding (used for damage effects)
210 const int WEP_FLAG_NOTRUEAIM = BIT(15); // weapon doesn't aim directly at targets
211 const int WEP_FLAG_SPECIALATTACK = BIT(16); // marked as a special attack (not a true weapon), hidden from most weapon lists
214 string weaponorder_byid;
217 string W_FixWeaponOrder(string order, float complete);
218 string W_UndeprecateName(string s);
219 string W_NameWeaponOrder(string order);
220 string W_NumberWeaponOrder(string order);
221 string W_FixWeaponOrder_BuildImpulseList(string o);
222 string W_FixWeaponOrder_AllowIncomplete(entity this, string order);
223 string W_FixWeaponOrder_ForceComplete(string order);
224 WepSet W_RandomWeapons(entity e, WepSet remaining, int n);
226 string GetAmmoPicture(Resource ammotype);
228 string GetAmmoName(Resource ammotype);
230 entity GetAmmoItem(Resource ammotype);
233 Resource GetAmmoTypeFromNum(int i);
235 int GetAmmoStat(Resource ammotype);
238 string W_Sound(string w_snd);
239 string W_Model(string w_mdl);