]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/all.qh
Merge branch 'terencehill/shuffleteams_fix' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / all.qh
1 #ifndef WEAPONS_ALL_H
2 #define WEAPONS_ALL_H
3
4 #ifndef MENUQC
5 #include "calculations.qh"
6 #endif
7
8 #include "../util.qh"
9 #ifdef SVQC
10 #include "../../server/bot/aim.qh"
11 #endif
12 const int MAX_SHOT_DISTANCE = 32768;
13
14 // weapon pickup ratings for bot logic
15 const int BOT_PICKUP_RATING_LOW  =  2500;
16 const int BOT_PICKUP_RATING_MID  =  5000;
17 const int BOT_PICKUP_RATING_HIGH = 10000;
18
19 // weapon flags
20 const int WEP_TYPE_OTHER          =  0x00; // not for damaging people
21 const int WEP_TYPE_SPLASH         =  0x01; // splash damage
22 const int WEP_TYPE_HITSCAN        =  0x02; // hitscan
23 const int WEP_TYPEMASK            =  0x0F;
24 const int WEP_FLAG_CANCLIMB       =  0x10; // can be used for movement
25 const int WEP_FLAG_NORMAL         =  0x20; // in "most weapons" set
26 const int WEP_FLAG_HIDDEN         =  0x40; // hides from menu
27 const int WEP_FLAG_RELOADABLE     =  0x80; // can has reload
28 const int WEP_FLAG_SUPERWEAPON    = 0x100; // powerup timer
29 const int WEP_FLAG_MUTATORBLOCKED = 0x200; // hides from impulse 99 etc. (mutators are allowed to clear this flag)
30
31 // weapon requests
32 const int WR_SETUP          =  1; // (SERVER) setup weapon data
33 const int WR_THINK          =  2; // (SERVER) logic to run every frame
34 const int WR_CHECKAMMO1     =  3; // (SERVER) checks ammo for weapon primary
35 const int WR_CHECKAMMO2     =  4; // (SERVER) checks ammo for weapon second
36 const int WR_AIM            =  5; // (SERVER) runs bot aiming code for this weapon
37 const int WR_INIT           =  6; // (BOTH)   precaches models/sounds used by this weapon, also sets up weapon properties
38 const int WR_SUICIDEMESSAGE =  7; // (SERVER) notification number for suicide message (may inspect w_deathtype for details)
39 const int WR_KILLMESSAGE    =  8; // (SERVER) notification number for kill message (may inspect w_deathtype for details)
40 const int WR_RELOAD         =  9; // (SERVER) handles reloading for weapon
41 const int WR_RESETPLAYER    = 10; // (SERVER) clears fields that the weapon may use
42 const int WR_IMPACTEFFECT   = 11; // (CLIENT) impact effect for weapon explosion
43 const int WR_PLAYERDEATH    = 12; // (SERVER) called whenever a player dies
44 const int WR_GONETHINK      = 13; // (SERVER) logic to run when weapon is lost
45 const int WR_CONFIG         = 14; // (ALL)    dump weapon cvars to config in data directory (see: sv_cmd dumpweapons)
46 const int WR_ZOOMRETICLE    = 15; // (CLIENT) weapon specific zoom reticle
47 const int WR_DROP           = 16; // (SERVER) the weapon is dropped
48 const int WR_PICKUP         = 17; // (SERVER) a weapon is picked up
49
50 // variables:
51 string weaponorder_byid;
52
53 // weapon sets
54 typedef vector WepSet;
55 WepSet WepSet_FromWeapon(int a);
56 #ifdef SVQC
57 void WepSet_AddStat();
58 void WriteWepSet(float dest, WepSet w);
59 #endif
60 #ifdef CSQC
61 WepSet WepSet_GetFromStat();
62 WepSet ReadWepSet();
63 #endif
64
65 // weapon name macros
66 #define WEP_FIRST 1
67 #define WEP_MAXCOUNT 24 // Increase as needed. Can be up to three times as much.
68 int WEP_COUNT;
69 int WEP_LAST;
70 WepSet WEPSET_ALL;
71 WepSet WEPSET_SUPERWEAPONS;
72
73 // functions:
74 entity get_weaponinfo(int id);
75 string W_FixWeaponOrder(string order, float complete);
76 string W_UndeprecateName(string s);
77 string W_NameWeaponOrder(string order);
78 string W_NumberWeaponOrder(string order);
79 string W_FixWeaponOrder_BuildImpulseList(string o);
80 string W_FixWeaponOrder_AllowIncomplete(string order);
81 string W_FixWeaponOrder_ForceComplete(string order);
82 void W_RandomWeapons(entity e, float n);
83
84 string GetAmmoPicture(.int ammotype);
85
86 #ifdef CSQC
87 .int GetAmmoFieldFromNum(int i);
88 int GetAmmoStat(.int ammotype);
89 #endif
90
91 // ammo types
92 .int ammo_shells;
93 .int ammo_nails;
94 .int ammo_rockets;
95 .int ammo_cells;
96 .int ammo_plasma;
97 .int ammo_fuel;
98 .int ammo_none;
99
100 // other useful macros
101 #define WEP_ACTION(wpn,wrequest) (get_weaponinfo(wpn)).weapon_func(wrequest)
102 #define WEP_AMMO(wpn) ((get_weaponinfo(WEP_##wpn)).ammo_field) // only used inside weapon files/with direct name, don't duplicate prefix
103 #define WEP_NAME(wpn) ((get_weaponinfo(wpn)).message)
104
105
106 // ======================
107 //  Configuration Macros
108 // ======================
109
110 // create cvars for weapon settings
111 #define WEP_ADD_CVAR_NONE(wepname,name) [[last]] float autocvar_g_balance_##wepname##_##name;
112
113 #define WEP_ADD_CVAR_PRI(wepname,name) WEP_ADD_CVAR_NONE(wepname, primary_##name)
114 #define WEP_ADD_CVAR_SEC(wepname,name) WEP_ADD_CVAR_NONE(wepname, secondary_##name)
115 #define WEP_ADD_CVAR_BOTH(wepname,name) \
116         WEP_ADD_CVAR_PRI(wepname, name) \
117         WEP_ADD_CVAR_SEC(wepname, name)
118
119 #define WEP_ADD_CVAR(wepid,wepname,mode,name) WEP_ADD_CVAR_##mode(wepname, name)
120
121 // create properties for weapon settings
122 #define WEP_ADD_PROP(wepid,wepname,type,prop,name) \
123         .type prop; \
124         [[last]] type autocvar_g_balance_##wepname##_##name;
125
126 // read cvars from weapon settings
127 #define WEP_CVAR(wepname,name) autocvar_g_balance_##wepname##_##name
128 #define WEP_CVAR_PRI(wepname,name) WEP_CVAR(wepname, primary_##name)
129 #define WEP_CVAR_SEC(wepname,name) WEP_CVAR(wepname, secondary_##name)
130 #define WEP_CVAR_BOTH(wepname,isprimary,name) ((isprimary) ? WEP_CVAR_PRI(wepname, name) : WEP_CVAR_SEC(wepname, name))
131
132 // set initialization values for weapon settings
133 #define WEP_SKIP_CVAR(unuseda,unusedb,unusedc,unusedd) /* skip cvars */
134 #define WEP_SET_PROP(wepid,wepname,type,prop,name) get_weaponinfo(WEP_##wepid).##prop = autocvar_g_balance_##wepname##_##name;
135
136
137 // =====================
138 //  Weapon Registration
139 // =====================
140
141 bool w_null(int dummy);
142
143 void register_weapon(
144         int id,
145         WepSet bit,
146         bool(int) func,
147         .int ammotype,
148         int i,
149         int weapontype,
150         float pickupbasevalue,
151         vector clr,
152         string modelname,
153         string simplemdl,
154         string crosshair,
155         string wepimg,
156         string refname,
157         string wepname);
158
159 void register_weapons_done();
160
161 // entity properties of weaponinfo:
162 // fields which are explicitly/manually set are marked with "M", fields set automatically are marked with "A"
163 .int weapon;                // M: WEP_id    // WEP_...
164 .WepSet weapons;            // A: WEPSET_id // WEPSET_...
165 .float(float) weapon_func;  // M: function  // w_...
166 ..int ammo_field;         // M: ammotype  // main ammo field
167 .int impulse;               // M: impulse   // weapon impulse
168 .int spawnflags;            // M: flags     // WEPSPAWNFLAG_... combined
169 .float bot_pickupbasevalue; // M: rating    // bot weapon priority
170 .vector wpcolor;            // M: color     // waypointsprite color
171 .string wpmodel;            // A: wpn-id    // wpn- sprite name
172 .string mdl;                // M: modelname // name of model (without g_ v_ or h_ prefixes)
173 .string model;              // A: modelname // full path to g_ model
174 .string w_simplemdl;        // M: simplemdl // simpleitems weapon model/image
175 .string w_crosshair;        // M: crosshair // per-weapon crosshair: "CrosshairImage Size"
176 .float w_crosshair_size;    // A: crosshair // per-weapon crosshair size (argument two of "crosshair" field)
177 .string model2;             // M: wepimg    // "weaponfoobar" side view image file of weapon // WEAPONTODO: Move out of skin files, move to common files
178 .string netname;            // M: refname   // reference name name
179 .string message;            // M: wepname   // human readable name
180
181
182 // note: the fabs call is just there to hide "if result is constant" warning
183 #define REGISTER_WEAPON_2(id,bit,function,ammotype,impulse,flags,rating,color,modelname,simplemdl,crosshair,wepimg,refname,wepname) \
184         int id; \
185         WepSet bit; \
186         bool function(int); \
187         void RegisterWeapons_##id() \
188         { \
189                 WEP_LAST = (id = WEP_FIRST + WEP_COUNT); \
190                 bit = WepSet_FromWeapon(id); \
191                 WEPSET_ALL |= bit; \
192                 if((flags) & WEP_FLAG_SUPERWEAPON) \
193                         WEPSET_SUPERWEAPONS |= bit; \
194                 ++WEP_COUNT; \
195                 register_weapon(id,bit,function,ammotype,impulse,flags,rating,color,modelname,simplemdl,crosshair,wepimg,refname,wepname); \
196         } \
197         ACCUMULATE_FUNCTION(RegisterWeapons, RegisterWeapons_##id)
198 #ifdef MENUQC
199 #define REGISTER_WEAPON(id,function,ammotype,impulse,flags,rating,color,modelname,simplemdl,crosshair,wepimg,refname,wepname) \
200         REGISTER_WEAPON_2(WEP_##id,WEPSET_##id,w_null,ammotype,impulse,flags,rating,color,modelname,simplemdl,crosshair,wepimg,refname,wepname)
201 #else
202 #define REGISTER_WEAPON(id,function,ammotype,impulse,flags,rating,color,modelname,simplemdl,crosshair,wepimg,refname,wepname) \
203         REGISTER_WEAPON_2(WEP_##id,WEPSET_##id,function,ammotype,impulse,flags,rating,color,modelname,simplemdl,crosshair,wepimg,refname,wepname)
204 #endif
205
206 #include "all.inc"
207
208 #undef WEP_ADD_CVAR_MO_PRI
209 #undef WEP_ADD_CVAR_MO_SEC
210 #undef WEP_ADD_CVAR_MO_BOTH
211 #undef WEP_ADD_CVAR_MO_NONE
212 #undef WEP_ADD_CVAR
213 #undef WEP_ADD_PROP
214 #undef REGISTER_WEAPON
215
216 ACCUMULATE_FUNCTION(RegisterWeapons, register_weapons_done);
217 #endif