]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/all.qh
Remove redundant get_weaponinfo calls
[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 WepSet_AddStat_InMap();
59 void WriteWepSet(float dest, WepSet w);
60 #endif
61 #ifdef CSQC
62 WepSet WepSet_GetFromStat();
63 WepSet WepSet_GetFromStat_InMap();
64 WepSet ReadWepSet();
65 #endif
66
67 // weapon name macros
68 const int WEP_FIRST = 1;
69 #define WEP_MAXCOUNT 24 // Increase as needed. Can be up to three times as much.
70 int WEP_COUNT;
71 #define WEP_LAST (WEP_FIRST + WEP_COUNT - 1)
72 WepSet WEPSET_ALL;
73 WepSet WEPSET_SUPERWEAPONS;
74
75 // functions:
76 entity get_weaponinfo(int id);
77 string W_FixWeaponOrder(string order, float complete);
78 string W_UndeprecateName(string s);
79 string W_NameWeaponOrder(string order);
80 string W_NumberWeaponOrder(string order);
81 string W_FixWeaponOrder_BuildImpulseList(string o);
82 string W_FixWeaponOrder_AllowIncomplete(string order);
83 string W_FixWeaponOrder_ForceComplete(string order);
84 void W_RandomWeapons(entity e, float n);
85
86 string GetAmmoPicture(.int ammotype);
87
88 #ifdef CSQC
89 .int GetAmmoFieldFromNum(int i);
90 int GetAmmoStat(.int ammotype);
91 #endif
92
93 // ammo types
94 .int ammo_shells;
95 .int ammo_nails;
96 .int ammo_rockets;
97 .int ammo_cells;
98 .int ammo_plasma;
99 .int ammo_fuel;
100 .int ammo_none;
101
102 // other useful macros
103 #define WEP_ACTION(wpn,wrequest) (get_weaponinfo(wpn)).weapon_func(wrequest)
104 #define WEP_AMMO(wpn) (WEP_##wpn.ammo_field) // only used inside weapon files/with direct name, don't duplicate prefix
105 #define WEP_NAME(wpn) ((get_weaponinfo(wpn)).message)
106
107
108 // ======================
109 //  Configuration Macros
110 // ======================
111
112 // create cvars for weapon settings
113 #define WEP_ADD_CVAR_NONE(wepname,name) [[last]] float autocvar_g_balance_##wepname##_##name;
114
115 #define WEP_ADD_CVAR_PRI(wepname,name) WEP_ADD_CVAR_NONE(wepname, primary_##name)
116 #define WEP_ADD_CVAR_SEC(wepname,name) WEP_ADD_CVAR_NONE(wepname, secondary_##name)
117 #define WEP_ADD_CVAR_BOTH(wepname,name) \
118         WEP_ADD_CVAR_PRI(wepname, name) \
119         WEP_ADD_CVAR_SEC(wepname, name)
120
121 #define WEP_ADD_CVAR(wepid,wepname,mode,name) WEP_ADD_CVAR_##mode(wepname, name)
122
123 // create properties for weapon settings
124 #define WEP_ADD_PROP(wepid,wepname,type,prop,name) \
125         .type prop; \
126         [[last]] type autocvar_g_balance_##wepname##_##name;
127
128 // read cvars from weapon settings
129 #define WEP_CVAR(wepname,name) autocvar_g_balance_##wepname##_##name
130 #define WEP_CVAR_PRI(wepname,name) WEP_CVAR(wepname, primary_##name)
131 #define WEP_CVAR_SEC(wepname,name) WEP_CVAR(wepname, secondary_##name)
132 #define WEP_CVAR_BOTH(wepname,isprimary,name) ((isprimary) ? WEP_CVAR_PRI(wepname, name) : WEP_CVAR_SEC(wepname, name))
133
134 // set initialization values for weapon settings
135 #define WEP_SKIP_CVAR(unuseda,unusedb,unusedc,unusedd) /* skip cvars */
136 #define WEP_SET_PROP(wepid,wepname,type,prop,name) WEP_##wepid.prop = autocvar_g_balance_##wepname##_##name;
137
138
139 // =====================
140 //  Weapon Registration
141 // =====================
142
143 CLASS(Weapon, Object)
144         ATTRIB(Weapon, m_id, int, 0)
145         // entity properties of weaponinfo:
146     // fields which are explicitly/manually set are marked with "M", fields set automatically are marked with "A"
147     .int weapon;                // M: WEP_id    // WEP_...
148     .WepSet weapons;            // A: WEPSET_id // WEPSET_...
149     .float(float) weapon_func;  // M: function  // w_...
150     ..int ammo_field;           // M: ammotype  // main ammo field
151     .int impulse;               // M: impulse   // weapon impulse
152     .int spawnflags;            // M: flags     // WEPSPAWNFLAG_... combined
153     .float bot_pickupbasevalue; // M: rating    // bot weapon priority
154     .vector wpcolor;            // M: color     // waypointsprite color
155     .string wpmodel;            // A: wpn-id    // wpn- sprite name
156     .string mdl;                // M: modelname // name of model (without g_ v_ or h_ prefixes)
157     .string model;              // A: modelname // full path to g_ model
158     .string w_simplemdl;        // M: simplemdl // simpleitems weapon model/image
159     .string w_crosshair;        // M: crosshair // per-weapon crosshair: "CrosshairImage Size"
160     .float w_crosshair_size;    // A: crosshair // per-weapon crosshair size (argument two of "crosshair" field)
161     .string model2;             // M: wepimg    // "weaponfoobar" side view image file of weapon // WEAPONTODO: Move out of skin files, move to common files
162     .string netname;            // M: refname   // reference name name
163     .string message;            // M: wepname   // human readable name
164         CONSTRUCTOR(Weapon,
165                 bool(int) function,
166                 .int ammotype,
167                 int i,
168                 int weapontype,
169                 float pickupbasevalue,
170                 vector clr,
171                 string modelname,
172                 string simplemdl,
173                 string crosshair,
174                 string wepimg,
175                 string refname,
176                 string wepname
177         ) {
178                 CONSTRUCT(Weapon);
179                 this.weapon_func = function;
180                 this.ammo_field = ammotype;
181                 this.impulse = i;
182                 this.spawnflags = weapontype;
183                 this.bot_pickupbasevalue = pickupbasevalue;
184                 this.wpcolor = clr;
185                 this.mdl = modelname;
186                 this.model = strzone(strcat("models/weapons/g_", modelname, ".md3"));
187                 this.w_simplemdl = strzone(simplemdl); // simpleitems weapon model/image
188                 this.w_crosshair = strzone(car(crosshair));
189                 string s = cdr(crosshair);
190                 this.w_crosshair_size = ((s != "") ? stof(s) : 1); // so that we can scale the crosshair from code (for compat)
191                 this.model2 = strzone(wepimg);
192                 this.netname = refname;
193                 this.message = wepname;
194                 return this;
195         }
196         void register_weapon(entity this, int id, WepSet bit)
197         {
198                 this.classname = "weapon_info";
199                 this.weapon = id;
200                 this.weapons = bit;
201                 this.wpmodel = strzone(strcat("wpn-", ftos(id)));
202                 #ifdef CSQC
203                 this.weapon_func(WR_INIT);
204                 #endif
205         }
206 ENDCLASS(Weapon)
207
208 void RegisterWeapons();
209 REGISTER_REGISTRY(RegisterWeapons)
210 entity weapon_info[WEP_MAXCOUNT], weapon_info_first, weapon_info_last;
211 entity dummy_weapon_info;
212
213 #define _REGISTER_WEAPON(id, function, ammotype, impulse, flags, rating, color, modelname, simplemdl, crosshair, wepimg, refname, wepname) \
214         WepSet WEPSET_##id; \
215         REGISTER(RegisterWeapons, WEP, weapon_info, WEP_COUNT, id, m_id, \
216                 NEW(Weapon, function, ammotype, impulse, flags, rating, color, modelname, simplemdl, crosshair, wepimg, refname, wepname) \
217         ) { \
218                 this.m_id++; \
219                 WEPSET_ALL |= (WEPSET_##id = WepSet_FromWeapon(this.m_id)); \
220                 if ((flags) & WEP_FLAG_SUPERWEAPON) WEPSET_SUPERWEAPONS |= WEPSET_##id; \
221                 register_weapon(this, this.m_id, WEPSET_##id); \
222         }
223
224 bool w_null(int) { return false; }
225
226 #ifndef MENUQC
227         #define REGISTER_WEAPON(id, function, ammotype, impulse, flags, rating, color, modelname, simplemdl, crosshair, wepimg, refname, wepname) \
228         bool function(int); \
229         _REGISTER_WEAPON(id, function, ammotype, impulse, flags, rating, color, modelname, simplemdl, crosshair, wepimg, refname, wepname)
230 #else
231         #define REGISTER_WEAPON(id, function, ammotype, impulse, flags, rating, color, modelname, simplemdl, crosshair, wepimg, refname, wepname) \
232                 _REGISTER_WEAPON(id, w_null,   ammotype, impulse, flags, rating, color, modelname, simplemdl, crosshair, wepimg, refname, wepname)
233 #endif
234
235 #include "all.inc"
236
237 #undef WEP_ADD_CVAR_MO_PRI
238 #undef WEP_ADD_CVAR_MO_SEC
239 #undef WEP_ADD_CVAR_MO_BOTH
240 #undef WEP_ADD_CVAR_MO_NONE
241 #undef WEP_ADD_CVAR
242 #undef WEP_ADD_PROP
243 void register_weapons_done();
244 ACCUMULATE_FUNCTION(RegisterWeapons, register_weapons_done);
245 #endif