2 #include "calculations.qh"
5 const float MAX_SHOT_DISTANCE = 32768;
7 // weapon pickup ratings for bot logic
8 const float BOT_PICKUP_RATING_LOW = 2500;
9 const float BOT_PICKUP_RATING_MID = 5000;
10 const float BOT_PICKUP_RATING_HIGH = 10000;
13 const float WEP_TYPE_OTHER = 0x00; // not for damaging people
14 const float WEP_TYPE_SPLASH = 0x01; // splash damage
15 const float WEP_TYPE_HITSCAN = 0x02; // hitscan
16 const float WEP_TYPEMASK = 0x0F;
17 const float WEP_FLAG_CANCLIMB = 0x10; // can be used for movement
18 const float WEP_FLAG_NORMAL = 0x20; // in "most weapons" set
19 const float WEP_FLAG_HIDDEN = 0x40; // hides from menu
20 const float WEP_FLAG_RELOADABLE = 0x80; // can has reload
21 const float WEP_FLAG_SUPERWEAPON = 0x100; // powerup timer
22 const float WEP_FLAG_MUTATORBLOCKED = 0x200; // hides from impulse 99 etc. (mutators are allowed to clear this flag)
25 const float WR_SETUP = 1; // (SERVER) setup weapon data
26 const float WR_THINK = 2; // (SERVER) logic to run every frame
27 const float WR_CHECKAMMO1 = 3; // (SERVER) checks ammo for weapon primary
28 const float WR_CHECKAMMO2 = 4; // (SERVER) checks ammo for weapon second
29 const float WR_AIM = 5; // (SERVER) runs bot aiming code for this weapon
30 const float WR_INIT = 6; // (BOTH) precaches models/sounds used by this weapon, also sets up weapon properties
31 const float WR_SUICIDEMESSAGE = 7; // (SERVER) notification number for suicide message (may inspect w_deathtype for details)
32 const float WR_KILLMESSAGE = 8; // (SERVER) notification number for kill message (may inspect w_deathtype for details)
33 const float WR_RELOAD = 9; // (SERVER) handles reloading for weapon
34 const float WR_RESETPLAYER = 10; // (SERVER) clears fields that the weapon may use
35 const float WR_IMPACTEFFECT = 11; // (CLIENT) impact effect for weapon explosion
36 const float WR_SWITCHABLE = 12; // (CLIENT) decides whether the player is able to switch away from this weapon
37 const float WR_PLAYERDEATH = 13; // (SERVER) called whenever a player dies
38 const float WR_GONETHINK = 14; // (SERVER) logic to run when weapon is lost/switched away from
39 const float WR_CONFIG = 15; // (ALL) dump weapon cvars to config in data directory (see: sv_cmd dumpweapons)
40 const float WR_ZOOMRETICLE = 16; // (CLIENT) weapon specific zoom reticle
43 string weaponorder_byid;
46 typedef vector WepSet;
47 WepSet WepSet_FromWeapon(float a);
49 void WepSet_AddStat();
50 void WriteWepSet(float dest, WepSet w);
53 WepSet WepSet_GetFromStat();
59 #define WEP_MAXCOUNT 24 // Increase as needed. Can be up to three times as much.
63 WepSet WEPSET_SUPERWEAPONS;
66 entity get_weaponinfo(float id);
67 string W_FixWeaponOrder(string order, float complete);
68 string W_NameWeaponOrder(string order);
69 string W_NumberWeaponOrder(string order);
70 string W_FixWeaponOrder_BuildImpulseList(string o);
71 string W_FixWeaponOrder_AllowIncomplete(string order);
72 string W_FixWeaponOrder_ForceComplete(string order);
73 void W_RandomWeapons(entity e, float n);
76 .float GetAmmoFieldFromNum(float i);
77 string GetAmmoPicture(.float ammotype);
78 float GetAmmoStat(.float ammotype);
89 // other useful macros
90 #define WEP_ACTION(wpn,wrequest) (get_weaponinfo(wpn)).weapon_func(wrequest)
91 #define WEP_AMMO(wpn) ((get_weaponinfo(WEP_##wpn)).ammo_field)
92 #define WEP_NAME(wpn) ((get_weaponinfo(wpn)).message)
95 // ======================
96 // Configuration Macros
97 // ======================
99 // create cvars for weapon settings
100 #define WEP_ADD_CVAR_NONE(wepname,name) [[last]] float autocvar_g_balance_##wepname##_##name;
102 #define WEP_ADD_CVAR_PRI(wepname,name) WEP_ADD_CVAR_NONE(wepname, primary_##name)
103 #define WEP_ADD_CVAR_SEC(wepname,name) WEP_ADD_CVAR_NONE(wepname, secondary_##name)
104 #define WEP_ADD_CVAR_BOTH(wepname,name) \
105 WEP_ADD_CVAR_PRI(wepname, name) \
106 WEP_ADD_CVAR_SEC(wepname, name)
108 #define WEP_ADD_CVAR(wepid,wepname,mode,name) WEP_ADD_CVAR_##mode(wepname, name)
110 // create properties for weapon settings
111 #define WEP_ADD_PROP(wepid,wepname,type,prop,name) \
113 [[last]] type autocvar_g_balance_##wepname##_##name;
115 // read cvars from weapon settings
116 #define WEP_CVAR(wepname,name) autocvar_g_balance_##wepname##_##name
117 #define WEP_CVAR_PRI(wepname,name) WEP_CVAR(wepname, primary_##name)
118 #define WEP_CVAR_SEC(wepname,name) WEP_CVAR(wepname, secondary_##name)
119 #define WEP_CVAR_BOTH(wepname,isprimary,name) ((isprimary) ? WEP_CVAR_PRI(wepname, name) : WEP_CVAR_SEC(wepname, name))
121 // set initialization values for weapon settings
122 #define WEP_SKIPCVAR(unuseda,unusedb,unusedc,unusedd) /* skip cvars */
123 #define WEP_SET_PROP(wepid,wepname,type,prop,name) get_weaponinfo(WEP_##wepid).##prop = autocvar_g_balance_##wepname##_##name;
126 // =====================
127 // Weapon Registration
128 // =====================
130 float w_null(float dummy);
132 void register_weapon(
139 float pickupbasevalue,
145 void register_weapons_done();
147 // entity properties of weaponinfo:
148 .float weapon; // WEP_...
149 .WepSet weapons; // WEPSET_...
150 .string netname; // short name
151 .string message; // human readable name
152 .float(float) weapon_func; // w_...
153 .vector wpcolor; // waypointsprite color
154 .string mdl; // modelname without g_, v_, w_
155 .string model; // full name of g_ model
156 .float spawnflags; // WEPSPAWNFLAG_... combined
157 .float impulse; // weapon impulse
158 .float bot_pickupbasevalue; // bot weapon priority
159 .string model2; // wpn- sprite name
160 ..float ammo_field; // main ammo field
162 // note: the fabs call is just there to hide "if result is constant" warning
163 #define REGISTER_WEAPON_2(id,bit,func,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname) \
167 void RegisterWeapons_##id() \
169 WEP_LAST = (id = WEP_FIRST + WEP_COUNT); \
170 bit = WepSet_FromWeapon(id); \
172 if((weapontype) & WEP_FLAG_SUPERWEAPON) \
173 WEPSET_SUPERWEAPONS |= bit; \
175 register_weapon(id,bit,func,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname); \
177 ACCUMULATE_FUNCTION(RegisterWeapons, RegisterWeapons_##id)
179 #define REGISTER_WEAPON(id,func,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname) \
180 REGISTER_WEAPON_2(WEP_##id,WEPSET_##id,w_null,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname)
182 #define REGISTER_WEAPON(id,func,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname) \
183 REGISTER_WEAPON_2(WEP_##id,WEPSET_##id,func,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname)
188 #undef WEP_ADD_CVAR_MO_PRI
189 #undef WEP_ADD_CVAR_MO_SEC
190 #undef WEP_ADD_CVAR_MO_BOTH
191 #undef WEP_ADD_CVAR_MO_NONE
194 #undef REGISTER_WEAPON
196 ACCUMULATE_FUNCTION(RegisterWeapons, register_weapons_done);