]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapons.qh
Merge remote-tracking branch 'origin/master' into samual/weapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapons.qh
1 #ifndef MENUQC
2 #include "calculations.qh"
3 #endif
4
5 const float BOT_PICKUP_RATING_LOW       = 2500;
6 const float BOT_PICKUP_RATING_MID       = 5000;
7 const float BOT_PICKUP_RATING_HIGH      = 10000;
8
9 const float WEP_TYPE_OTHER            =  0x00; // not for damaging people
10 const float WEP_TYPE_SPLASH           =  0x01; // splash damage
11 const float WEP_TYPE_HITSCAN          =  0x02; // hitscan
12 const float WEP_TYPEMASK            =  0x0F;
13 const float WEP_FLAG_CANCLIMB       =  0x10; // can be used for movement
14 const float WEP_FLAG_NORMAL         =  0x20; // in "most weapons" set
15 const float WEP_FLAG_HIDDEN         =  0x40; // hides from menu
16 const float WEP_FLAG_RELOADABLE     =  0x80; // can has reload
17 const float WEP_FLAG_SUPERWEAPON    = 0x100; // powerup timer
18 const float WEP_FLAG_MUTATORBLOCKED = 0x200; // hides from impulse 99 etc. (mutators are allowed to clear this flag)
19
20 const float MAX_SHOT_DISTANCE = 32768;
21
22 // weapon requests // WEAPONTODO
23 #define WR_SETUP          1 // (SERVER) setup weapon data
24 #define WR_THINK          2 // (SERVER) logic to run every frame
25 #define WR_CHECKAMMO1     3 // (SERVER) checks ammo for weapon
26 #define WR_CHECKAMMO2     4 // (SERVER) checks ammo for weapon
27 #define WR_AIM            5 // (SERVER) runs bot aiming code for this weapon
28 #define WR_INIT           6 // (BOTH) precaches models/sounds used by this weapon
29 #define WR_SUICIDEMESSAGE 7 // (SERVER) notification number for suicide message (may inspect w_deathtype for details)
30 #define WR_KILLMESSAGE    8 // (SERVER) notification number for kill message (may inspect w_deathtype for details)
31 #define WR_RELOAD         9 // (SERVER) does not need to do anything
32 #define WR_RESETPLAYER    10 // (SERVER) does not need to do anything
33 #define WR_IMPACTEFFECT   11 // (CLIENT) impact effect
34 #define WR_SWITCHABLE     12 // (CLIENT) impact effect
35 #define WR_PLAYERDEATH    13 // (SERVER) does not need to do anything
36 #define WR_GONETHINK      14 // (SERVER) logic to run every frame, also if no longer having the weapon as long as the switch away has not been performed
37 #define WR_CONFIG         15 // (ALL) 
38
39 // WEAPONTODO
40 const float     IT_UNLIMITED_WEAPON_AMMO     = 1;
41 // when this bit is set, using a weapon does not reduce ammo. Checkpoints can give this powerup.
42 const float     IT_UNLIMITED_SUPERWEAPONS    = 2;
43 // when this bit is set, superweapons don't expire. Checkpoints can give this powerup.
44 const float   IT_CTF_SHIELDED              = 4; // set for the flag shield
45 const float   IT_USING_JETPACK             = 8; // confirmation that button is pressed
46 const float   IT_JETPACK                   = 16; // actual item
47 const float   IT_FUEL_REGEN                = 32; // fuel regeneration trigger
48 WANT_CONST float   IT_SHELLS                    = 256;
49 WANT_CONST float   IT_NAILS                     = 512;
50 WANT_CONST float   IT_ROCKETS                   = 1024;
51 WANT_CONST float   IT_CELLS                     = 2048;
52 const float   IT_SUPERWEAPON               = 4096;
53 const float   IT_FUEL                      = 128;
54 const float   IT_STRENGTH                  = 8192;
55 const float   IT_INVINCIBLE                = 16384;
56 const float   IT_HEALTH                    = 32768;
57 // union:
58         // for items:
59         WANT_CONST float        IT_KEY1                                 = 131072;
60         WANT_CONST float        IT_KEY2                                 = 262144;
61         // for players:
62         const float     IT_RED_FLAG_TAKEN               = 32768;
63         const float     IT_RED_FLAG_LOST                = 65536;
64         const float     IT_RED_FLAG_CARRYING            = 98304;
65         const float     IT_BLUE_FLAG_TAKEN              = 131072;
66         const float     IT_BLUE_FLAG_LOST               = 262144;
67         const float     IT_BLUE_FLAG_CARRYING   = 393216;
68 // end
69 const float   IT_5HP                       = 524288;
70 const float   IT_25HP                      = 1048576;
71 const float   IT_ARMOR_SHARD               = 2097152;
72 const float   IT_ARMOR                     = 4194304;
73
74 const float   IT_AMMO                      = 3968; // IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS | IT_FUEL;
75 const float   IT_PICKUPMASK                = 51; // IT_FUEL_REGEN | IT_JETPACK | IT_UNLIMITED_AMMO; // strength and invincible are handled separately
76 const float   IT_UNLIMITED_AMMO            = 3; // IT_UNLIMITED_SUPERWEAPONS | IT_UNLIMITED_WEAPON_AMMO;
77
78 const float AMMO_COUNT = 4; // amount of ammo types to show in the inventory panel
79
80 // variables:
81 string weaponorder_byid;
82
83 // Weapon sets
84 typedef vector WepSet;
85 WepSet WepSet_FromWeapon(float a);
86 #ifdef SVQC
87 void WepSet_AddStat();
88 void WriteWepSet(float dest, WepSet w);
89 #endif
90 #ifdef CSQC
91 WepSet WepSet_GetFromStat();
92 WepSet ReadWepSet();
93 #endif
94
95 // Weapon name macros
96 #define WEP_FIRST 1
97 #define WEP_MAXCOUNT 24 // Increase as needed. Can be up to three times as much.
98 float WEP_COUNT;
99 float WEP_LAST;
100 WepSet WEPSET_ALL;
101 WepSet WEPSET_SUPERWEAPONS;
102
103 // functions:
104 entity get_weaponinfo(float id);
105 string W_FixWeaponOrder(string order, float complete);
106 string W_NameWeaponOrder(string order);
107 string W_NumberWeaponOrder(string order);
108
109 // ammo types
110 .float ammo_shells;
111 .float ammo_nails;
112 .float ammo_rockets;
113 .float ammo_cells;
114 .float ammo_fuel;
115 .float ammo_batteries; // dummy
116
117 // entity properties of weaponinfo:
118 .float weapon; // WEP_...
119 .WepSet weapons; // WEPSET_...
120 .string netname; // short name
121 .string message; // human readable name
122 .float items; // IT_...
123 .float(float) weapon_func; // w_...
124 .string mdl; // modelname without g_, v_, w_
125 .string model; // full name of g_ model
126 .float spawnflags; // WEPSPAWNFLAG_... combined
127 .float impulse; // weapon impulse
128 .float bot_pickupbasevalue; // bot weapon priority
129 .string model2; // wpn- sprite name
130 ..float ammo_field; // main ammo field
131
132 // other useful macros
133 #define WEP_ACTION(wpn,wrequest) (get_weaponinfo(wpn)).weapon_func(wrequest)
134
135 // =====================
136 //  Weapon Registration
137 // =====================
138
139 float w_null(float dummy);
140 void register_weapon(float id, WepSet bit, float(float) func, float ammotype, float i, float weapontype, float pickupbasevalue, string modelname, string shortname, string wname);
141 void register_weapons_done();
142
143 // note: the fabs call is just there to hide "if result is constant" warning
144 #define REGISTER_WEAPON_2(id,bit,func,ammotype,i,weapontype,pickupbasevalue,modelname,shortname,wname) \
145         float id; \
146         WepSet bit; \
147         float func(float); \
148         void RegisterWeapons_##id() \
149         { \
150                 WEP_LAST = (id = WEP_FIRST + WEP_COUNT); \
151                 bit = WepSet_FromWeapon(id); \
152                 WEPSET_ALL |= bit; \
153                 if((weapontype) & WEP_FLAG_SUPERWEAPON) \
154                         WEPSET_SUPERWEAPONS |= bit; \
155                 ++WEP_COUNT; \
156                 register_weapon(id,bit,func,ammotype,i,weapontype,pickupbasevalue,modelname,shortname,wname); \
157         } \
158         ACCUMULATE_FUNCTION(RegisterWeapons, RegisterWeapons_##id)
159 #ifdef MENUQC
160 #define REGISTER_WEAPON(id,func,ammotype,i,weapontype,pickupbasevalue,modelname,shortname,wname) \
161         REGISTER_WEAPON_2(WEP_##id,WEPSET_##id,w_null,ammotype,i,weapontype,pickupbasevalue,modelname,shortname,wname)
162 #else
163 #define REGISTER_WEAPON(id,func,ammotype,i,weapontype,pickupbasevalue,modelname,shortname,wname) \
164         REGISTER_WEAPON_2(WEP_##id,WEPSET_##id,func,ammotype,i,weapontype,pickupbasevalue,modelname,shortname,wname)
165 #endif
166
167 #define MO_NONE 0
168 #define MO_PRI 1
169 #define MO_SEC 2
170 #define MO_BOTH 3
171
172 #define WEP_DUPECHECK(dupecheck,cvar) \
173         #ifndef dupecheck \
174                 #define dupecheck \
175                 float cvar; \
176         #else \
177                 #error DUPLICATE WEAPON CVAR: cvar \
178         #endif
179
180 /*
181 #define WEP_CLEAN_DUPECHECK(dupecheck) \
182         #ifdef WEP_CVAR_##weapon##_##name \
183                 #undef WEP_CVAR_##weapon##_##name \
184         #endif
185 */
186
187 #define WEP_ADD_CVAR(weapon,mode,name) \
188         #if mode == MO_PRI \
189                 WEP_DUPECHECK(WEP_CVAR_P_##weapon##_##name, autocvar_g_balance_##weapon##_primary_##name) \
190         #endif \
191         #if mode == MO_SEC \
192                 WEP_DUPECHECK(WEP_CVAR_S_##weapon##_##name, autocvar_g_balance_##weapon##_secondary_##name) \
193         #endif \
194         #if mode == MO_BOTH \
195                 WEP_DUPECHECK(WEP_CVAR_P_##weapon##_##name, autocvar_g_balance_##weapon##_primary_##name) \
196                 WEP_DUPECHECK(WEP_CVAR_S_##weapon##_##name, autocvar_g_balance_##weapon##_secondary_##name) \
197         #endif \
198         #if mode == MO_NONE \
199                 WEP_DUPECHECK(WEP_CVAR_##weapon##_##name, autocvar_g_balance_##weapon##_##name) \
200         #endif
201
202 #define WEP_CVAR(weapon,name) autocvar_g_balance_##weapon##_##name
203 #define WEP_CVAR_PRI(weapon,name) WEP_CVAR(weapon, primary_##name)
204 #define WEP_CVAR_SEC(weapon,name) WEP_CVAR(weapon, secondary_##name)
205 #define WEP_CVAR_BOTH(weapon,mode,name) ((mode == MO_PRI) ? WEP_CVAR_PRI(weapon, name) : WEP_CVAR_SEC(weapon, name))
206
207 #define WEP_ADD_PROP(weapon,prop,name) \
208         .float ##prop; \
209         WEP_DUPECHECK(WEP_CVAR_##weapon##_##name, autocvar_g_balance_##weapon##_##name)
210
211 #define WEP_SET_PROP(wepid,weapon,prop,name) get_weaponinfo(##wepid).##prop = autocvar_g_balance_##weapon##_##name;
212
213 #define WEP_SET_PROPS(wepsettings,wepid) \
214         #define WEP_ADD_CVAR(weapon,mode,name) \
215         #define WEP_ADD_PROP(weapon,prop,name) WEP_SET_PROP(wepid,weapon,prop,name) \
216         wepsettings \
217         #undef WEP_ADD_CVAR \
218         #undef WEP_ADD_PROP
219
220 #include "all.qh"
221
222 #undef WEP_ADD_CVAR
223 #undef WEP_ADD_PROP
224 #undef REGISTER_WEAPON
225 ACCUMULATE_FUNCTION(RegisterWeapons, register_weapons_done);
226
227 string W_FixWeaponOrder(string order, float complete);
228 string W_NumberWeaponOrder(string order);
229 string W_NameWeaponOrder(string order);
230 string W_FixWeaponOrder_BuildImpulseList(string o);
231 string W_FixWeaponOrder_AllowIncomplete(string order);
232 string W_FixWeaponOrder_ForceComplete(string order);
233
234 void W_RandomWeapons(entity e, float n);
235
236 string W_Name(float weaponid);
237
238 float W_AmmoItemCode(float wpn);