3 #include "../items/item/pickup.qh"
5 const int MAX_WEAPONSLOTS = 2;
6 .entity weaponentities[MAX_WEAPONSLOTS];
8 int weaponslot(.entity weaponentity)
10 for (int i = 0; i < MAX_WEAPONSLOTS; ++i)
12 if (weaponentities[i] == weaponentity)
20 // weapon states (actor.(weaponentity).state)
21 /** no weapon selected */
22 const int WS_CLEAR = 0;
24 const int WS_RAISE = 1;
25 /** deselecting frame */
26 const int WS_DROP = 2;
28 const int WS_INUSE = 3;
30 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)
45 * you can recognize dummies when this == 0
47 ATTRIB(Weapon, weapon, int, 0);
48 /** A: WEPSET_id : WEPSET_... */
49 ATTRIB(Weapon, weapons, WepSet, '0 0 0');
50 /** M: ammotype : main ammo field */
51 ATTRIB(Weapon, ammo_field, .int, ammo_none);
52 /** M: impulse : weapon impulse */
53 ATTRIB(Weapon, impulse, int, -1);
54 /** M: flags : WEPSPAWNFLAG_... combined */
55 ATTRIB(Weapon, spawnflags, int, 0);
56 /** M: rating : bot weapon priority */
57 ATTRIB(Weapon, bot_pickupbasevalue, float, 0);
58 /** M: color : waypointsprite color */
59 ATTRIB(Weapon, wpcolor, vector, '0 0 0');
60 /** M: modelname : name of model (without g_ v_ or h_ prefixes) */
61 ATTRIB(Weapon, mdl, string, "");
62 /** M: model MDL_id_ITEM */
63 ATTRIB(Weapon, m_model, entity, NULL);
64 /** M: crosshair : per-weapon crosshair: "CrosshairImage Size" */
65 ATTRIB(Weapon, w_crosshair, string, "gfx/crosshair1");
66 /** A: crosshair : per-weapon crosshair size (argument two of "crosshair" field) */
67 ATTRIB(Weapon, w_crosshair_size, float, 1);
68 /** M: wepimg : "weaponfoobar" side view image file of weapon. WEAPONTODO: Move out of skin files, move to common files */
69 ATTRIB(Weapon, model2, string, "");
70 /** M: refname : reference name name */
71 ATTRIB(Weapon, netname, string, "");
72 /** M: wepname : human readable name */
73 ATTRIB(Weapon, m_name, string, "AOL CD Thrower");
75 ATTRIB(Weapon, m_pickup, entity, NULL);
77 /** (SERVER) setup weapon data */
78 METHOD(Weapon, wr_setup, void(Weapon this)) {}
79 /** (SERVER) logic to run every frame */
80 METHOD(Weapon, wr_think, void(Weapon this, entity actor, .entity weaponentity, int fire)) {}
81 /** (SERVER) checks ammo for weapon primary */
82 METHOD(Weapon, wr_checkammo1, bool(Weapon this)) {return false;}
83 /** (SERVER) checks ammo for weapon second */
84 METHOD(Weapon, wr_checkammo2, bool(Weapon this)) {return false;}
85 /** (SERVER) runs bot aiming code for this weapon */
86 METHOD(Weapon, wr_aim, void(Weapon this)) {}
87 /** (BOTH) precaches models/sounds used by this weapon, also sets up weapon properties */
88 METHOD(Weapon, wr_init, void(Weapon this)) {}
89 /** (SERVER) notification number for suicide message (may inspect w_deathtype for details) */
90 METHOD(Weapon, wr_suicidemessage, int(Weapon this)) {return 0;}
91 /** (SERVER) notification number for kill message (may inspect w_deathtype for details) */
92 METHOD(Weapon, wr_killmessage, int(Weapon this)) {return 0;}
93 /** (SERVER) handles reloading for weapon */
94 METHOD(Weapon, wr_reload, void(Weapon this)) {}
95 /** (SERVER) clears fields that the weapon may use */
96 METHOD(Weapon, wr_resetplayer, void(Weapon this)) {}
97 /** (CLIENT) impact effect for weapon explosion */
98 METHOD(Weapon, wr_impacteffect, void(Weapon this)) {}
99 /** (SERVER) called whenever a player dies */
100 METHOD(Weapon, wr_playerdeath, void(Weapon this)) {}
101 /** (SERVER) logic to run when weapon is lost */
102 METHOD(Weapon, wr_gonethink, void(Weapon this)) {}
103 /** (ALL) dump weapon cvars to config in data directory (see: sv_cmd dumpweapons) */
104 METHOD(Weapon, wr_config, void(Weapon this)) {}
105 /** (CLIENT) weapon specific zoom reticle */
106 METHOD(Weapon, wr_zoomreticle, bool(Weapon this)) {
107 // no weapon specific image for this weapon
110 /** (SERVER) the weapon is dropped */
111 METHOD(Weapon, wr_drop, void(Weapon this)) {}
112 /** (SERVER) a weapon is picked up */
113 METHOD(Weapon, wr_pickup, void(Weapon this)) {}
115 METHOD(Weapon, display, void(entity this, void(string name, string icon) returns)) {
116 returns(this.m_name, this.model2 ? sprintf("/gfx/hud/%s/%s", cvar_string("menu_skin"), this.model2) : string_null);
120 #include "../items/all.qh"
121 CLASS(WeaponPickup, Pickup)
122 ATTRIB(WeaponPickup, m_weapon, Weapon, NULL)
123 ATTRIB(WeaponPickup, m_name, string, string_null)
125 ATTRIB(WeaponPickup, m_sound, Sound, SND_WEAPONPICKUP)
128 ATTRIB(WeaponPickup, m_itemflags, int, FL_WEAPON)
129 float weapon_pickupevalfunc(entity player, entity item);
130 ATTRIB(WeaponPickup, m_pickupevalfunc, float(entity player, entity item), weapon_pickupevalfunc)
132 CONSTRUCTOR(WeaponPickup, Weapon w) {
133 CONSTRUCT(WeaponPickup);
135 this.m_name = w.m_name;
137 this.m_model = w.m_model;
140 this.m_botvalue = w.bot_pickupbasevalue;
144 METHOD(WeaponPickup, giveTo, bool(entity this, entity item, entity player))
146 bool b = Item_GiveTo(item, player);
148 LOG_TRACEF("entity %i picked up %s\n", player, this.m_name);
153 ENDCLASS(WeaponPickup)
155 CLASS(OffhandWeapon, Object)
156 METHOD(OffhandWeapon, offhand_think, void(OffhandWeapon this, entity player, bool key_pressed)) {}
157 ENDCLASS(OffhandWeapon)
160 .OffhandWeapon offhand;
163 const int MAX_SHOT_DISTANCE = 32768;
165 // weapon pickup ratings for bot logic
166 const int BOT_PICKUP_RATING_LOW = 2500;
167 const int BOT_PICKUP_RATING_MID = 5000;
168 const int BOT_PICKUP_RATING_HIGH = 10000;
171 const int WEP_TYPE_OTHER = 0x00; // not for damaging people
172 const int WEP_TYPE_SPLASH = 0x01; // splash damage
173 const int WEP_TYPE_HITSCAN = 0x02; // hitscan
174 const int WEP_TYPEMASK = 0x0F;
175 const int WEP_FLAG_CANCLIMB = 0x10; // can be used for movement
176 const int WEP_FLAG_NORMAL = 0x20; // in "most weapons" set
177 const int WEP_FLAG_HIDDEN = 0x40; // hides from menu
178 const int WEP_FLAG_RELOADABLE = 0x80; // can has reload
179 const int WEP_FLAG_SUPERWEAPON = 0x100; // powerup timer
180 const int WEP_FLAG_MUTATORBLOCKED = 0x200; // hides from impulse 99 etc. (mutators are allowed to clear this flag)
183 string weaponorder_byid;
186 string W_FixWeaponOrder(string order, float complete);
187 string W_UndeprecateName(string s);
188 string W_NameWeaponOrder(string order);
189 string W_NumberWeaponOrder(string order);
190 string W_FixWeaponOrder_BuildImpulseList(string o);
191 string W_FixWeaponOrder_AllowIncomplete(string order);
192 string W_FixWeaponOrder_ForceComplete(string order);
193 void W_RandomWeapons(entity e, float n);
195 string GetAmmoPicture(.int ammotype);
198 .int GetAmmoFieldFromNum(int i);
199 int GetAmmoStat(.int ammotype);
202 string W_Sound(string w_snd);
203 string W_Model(string w_mdl);
206 // other useful macros
207 #define WEP_AMMO(wpn) (WEP_##wpn.ammo_field) // only used inside weapon files/with direct name, don't duplicate prefix
208 #define WEP_NAME(wpn) ((get_weaponinfo(wpn)).m_name)