3 #include "../items/item/pickup.qh"
6 const int MAX_WEAPONSLOTS = 2;
7 .entity weaponentities[MAX_WEAPONSLOTS];
9 int weaponslot(.entity weaponentity)
11 for (int i = 0; i < MAX_WEAPONSLOTS; ++i)
13 if (weaponentities[i] == weaponentity)
21 // weapon states (actor.(weaponentity).state)
22 /** no weapon selected */
23 const int WS_CLEAR = 0;
25 const int WS_RAISE = 1;
26 /** deselecting frame */
27 const int WS_DROP = 2;
29 const int WS_INUSE = 3;
31 const int WS_READY = 4;
38 .int ammo_plasma = _STAT(PLASMA);
39 .int ammo_fuel = _STAT(FUEL);
51 /** fields which are explicitly/manually set are marked with "M", fields set automatically are marked with "A" */
53 ATTRIB(Weapon, m_id, int, 0)
56 * you can recognize dummies when this == 0
58 ATTRIB(Weapon, weapon, int, 0);
59 /** A: WEPSET_id : WEPSET_... */
60 ATTRIB(Weapon, weapons, WepSet, '0 0 0');
61 /** M: ammotype : main ammo field */
62 ATTRIB(Weapon, ammo_field, .int, ammo_none);
63 /** M: impulse : weapon impulse */
64 ATTRIB(Weapon, impulse, int, -1);
65 /** M: flags : WEPSPAWNFLAG_... combined */
66 ATTRIB(Weapon, spawnflags, int, 0);
67 /** M: rating : bot weapon priority */
68 ATTRIB(Weapon, bot_pickupbasevalue, float, 0);
69 /** M: color : waypointsprite color */
70 ATTRIB(Weapon, wpcolor, vector, '0 0 0');
71 /** M: modelname : name of model (without g_ v_ or h_ prefixes) */
72 ATTRIB(Weapon, mdl, string, "");
73 /** M: model MDL_id_ITEM */
74 ATTRIB(Weapon, m_model, entity, NULL);
75 /** M: crosshair : per-weapon crosshair: "CrosshairImage Size" */
76 ATTRIB(Weapon, w_crosshair, string, "gfx/crosshair1");
77 /** A: crosshair : per-weapon crosshair size (argument two of "crosshair" field) */
78 ATTRIB(Weapon, w_crosshair_size, float, 1);
79 /** M: wepimg : "weaponfoobar" side view image file of weapon. WEAPONTODO: Move out of skin files, move to common files */
80 ATTRIB(Weapon, model2, string, "");
81 /** M: refname : reference name name */
82 ATTRIB(Weapon, netname, string, "");
83 /** M: wepname : human readable name */
84 ATTRIB(Weapon, m_name, string, "AOL CD Thrower");
86 ATTRIB(Weapon, m_pickup, entity, NULL);
88 /** (SERVER) setup weapon data */
89 METHOD(Weapon, wr_setup, void(Weapon this)) {}
90 /** (SERVER) logic to run every frame */
91 METHOD(Weapon, wr_think, void(Weapon this, entity actor, .entity weaponentity, int fire)) {}
92 /** (SERVER) checks ammo for weapon primary */
93 METHOD(Weapon, wr_checkammo1, bool(Weapon this)) {return false;}
94 /** (SERVER) checks ammo for weapon second */
95 METHOD(Weapon, wr_checkammo2, bool(Weapon this)) {return false;}
96 /** (SERVER) runs bot aiming code for this weapon */
97 METHOD(Weapon, wr_aim, void(Weapon this)) {}
98 /** (BOTH) precaches models/sounds used by this weapon, also sets up weapon properties */
99 METHOD(Weapon, wr_init, void(Weapon this)) {}
100 /** (SERVER) notification number for suicide message (may inspect w_deathtype for details) */
101 METHOD(Weapon, wr_suicidemessage, int(Weapon this)) {return 0;}
102 /** (SERVER) notification number for kill message (may inspect w_deathtype for details) */
103 METHOD(Weapon, wr_killmessage, int(Weapon this)) {return 0;}
104 /** (SERVER) handles reloading for weapon */
105 METHOD(Weapon, wr_reload, void(Weapon this)) {}
106 /** (SERVER) clears fields that the weapon may use */
107 METHOD(Weapon, wr_resetplayer, void(Weapon this)) {}
108 /** (CLIENT) impact effect for weapon explosion */
109 METHOD(Weapon, wr_impacteffect, void(Weapon this)) {}
110 /** (SERVER) called whenever a player dies */
111 METHOD(Weapon, wr_playerdeath, void(Weapon this)) {}
112 /** (SERVER) logic to run when weapon is lost */
113 METHOD(Weapon, wr_gonethink, void(Weapon this)) {}
114 /** (ALL) dump weapon cvars to config in data directory (see: sv_cmd dumpweapons) */
115 METHOD(Weapon, wr_config, void(Weapon this)) {}
116 /** (CLIENT) weapon specific zoom reticle */
117 METHOD(Weapon, wr_zoomreticle, bool(Weapon this)) {
118 // no weapon specific image for this weapon
121 /** (CLIENT) weapon specific glow */
122 METHOD(Weapon, wr_glow, vector(Weapon this)) { return '0 0 0'; }
123 /** (SERVER) the weapon is dropped */
124 METHOD(Weapon, wr_drop, void(Weapon this)) {}
125 /** (SERVER) a weapon is picked up */
126 METHOD(Weapon, wr_pickup, void(Weapon this)) {}
127 /** (SERVER) update cvar based properties */
128 METHOD(Weapon, wr_update, void(Weapon this)) {}
129 METHOD(Weapon, display, void(entity this, void(string name, string icon) returns)) {
130 returns(this.m_name, this.model2 ? sprintf("/gfx/hud/%s/%s", cvar_string("menu_skin"), this.model2) : string_null);
134 #include "../items/all.qh"
135 CLASS(WeaponPickup, Pickup)
136 ATTRIB(WeaponPickup, m_weapon, Weapon, NULL)
137 ATTRIB(WeaponPickup, m_name, string, string_null)
139 ATTRIB(WeaponPickup, m_sound, Sound, SND_WEAPONPICKUP)
142 ATTRIB(WeaponPickup, m_itemflags, int, FL_WEAPON)
143 float weapon_pickupevalfunc(entity player, entity item);
144 ATTRIB(WeaponPickup, m_pickupevalfunc, float(entity player, entity item), weapon_pickupevalfunc)
146 CONSTRUCTOR(WeaponPickup, Weapon w) {
147 CONSTRUCT(WeaponPickup);
149 this.m_name = w.m_name;
151 this.m_model = w.m_model;
154 this.m_botvalue = w.bot_pickupbasevalue;
158 METHOD(WeaponPickup, giveTo, bool(entity this, entity item, entity player))
160 bool b = Item_GiveTo(item, player);
162 LOG_TRACEF("entity %i picked up %s\n", player, this.m_name);
167 ENDCLASS(WeaponPickup)
169 CLASS(OffhandWeapon, Object)
170 METHOD(OffhandWeapon, offhand_think, void(OffhandWeapon this, entity player, bool key_pressed)) {}
171 ENDCLASS(OffhandWeapon)
174 .OffhandWeapon offhand;
177 const int MAX_SHOT_DISTANCE = 32768;
179 // weapon pickup ratings for bot logic
180 const int BOT_PICKUP_RATING_LOW = 2500;
181 const int BOT_PICKUP_RATING_MID = 5000;
182 const int BOT_PICKUP_RATING_HIGH = 10000;
185 const int WEP_TYPE_OTHER = 0x00; // not for damaging people
186 const int WEP_TYPE_SPLASH = 0x01; // splash damage
187 const int WEP_TYPE_HITSCAN = 0x02; // hitscan
188 const int WEP_TYPEMASK = 0x0F;
189 const int WEP_FLAG_CANCLIMB = 0x10; // can be used for movement
190 const int WEP_FLAG_NORMAL = 0x20; // in "most weapons" set
191 const int WEP_FLAG_HIDDEN = 0x40; // hides from menu
192 const int WEP_FLAG_RELOADABLE = 0x80; // can has reload
193 const int WEP_FLAG_SUPERWEAPON = 0x100; // powerup timer
194 const int WEP_FLAG_MUTATORBLOCKED = 0x200; // hides from impulse 99 etc. (mutators are allowed to clear this flag)
197 string weaponorder_byid;
200 string W_FixWeaponOrder(string order, float complete);
201 string W_UndeprecateName(string s);
202 string W_NameWeaponOrder(string order);
203 string W_NumberWeaponOrder(string order);
204 string W_FixWeaponOrder_BuildImpulseList(string o);
205 string W_FixWeaponOrder_AllowIncomplete(string order);
206 string W_FixWeaponOrder_ForceComplete(string order);
207 void W_RandomWeapons(entity e, float n);
209 string GetAmmoPicture(.int ammotype);
212 .int GetAmmoFieldFromNum(int i);
213 int GetAmmoStat(.int ammotype);
216 string W_Sound(string w_snd);
217 string W_Model(string w_mdl);
220 // other useful macros
221 #define WEP_AMMO(wpn) (WEP_##wpn.ammo_field) // only used inside weapon files/with direct name, don't duplicate prefix
222 #define WEP_NAME(wpn) ((Weapons_from(wpn)).m_name)