7b9b6e5f260ba3612bf16d398e5e8fc67c2c20b7
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / all.qh
1 #ifndef WEAPONS_ALL_H
2 #define WEAPONS_ALL_H
3
4 // weapon sets
5 typedef vector WepSet;
6 WepSet WepSet_FromWeapon(int a);
7 #ifdef SVQC
8 void WepSet_AddStat();
9 void WepSet_AddStat_InMap();
10 void WriteWepSet(float dest, WepSet w);
11 #endif
12
13 #ifdef CSQC
14 WepSet WepSet_GetFromStat();
15 WepSet WepSet_GetFromStat_InMap();
16 WepSet ReadWepSet();
17 #endif
18
19 #include "weapon.qh"
20
21 #ifndef MENUQC
22 #include "calculations.qh"
23 #include "../models/models.qh"
24 #endif
25
26 #include "../util.qh"
27
28 #ifdef SVQC
29 #include "../../server/bot/aim.qh"
30 #endif
31
32 const int WEP_FIRST = 1;
33 #define WEP_MAXCOUNT 72 // Increase as needed. Can be up to 72.
34 int WEP_COUNT;
35 #define WEP_LAST (WEP_FIRST + WEP_COUNT - 1)
36 WepSet WEPSET_ALL;
37 WepSet WEPSET_SUPERWEAPONS;
38
39 void RegisterWeapons();
40 REGISTER_REGISTRY(RegisterWeapons)
41 entity weapon_info[WEP_MAXCOUNT], weapon_info_first, weapon_info_last;
42 entity dummy_weapon_info;
43 #define WEP_Null dummy_weapon_info
44 entity get_weaponinfo(int id)
45 {
46         entity w;
47         if(id < WEP_FIRST || id > WEP_LAST)
48                 return dummy_weapon_info;
49         w = weapon_info[id - 1];
50         if(w)
51                 return w;
52         return dummy_weapon_info;
53 }
54
55 #define REGISTER_WEAPON(...) EVAL(OVERLOAD(REGISTER_WEAPON, __VA_ARGS__))
56
57 #define REGISTER_WEAPON_2(id, inst) \
58         WepSet WEPSET_##id; \
59         REGISTER(RegisterWeapons, WEP, weapon_info, WEP_COUNT, id, m_id, inst) { \
60                 this.m_id++; \
61                 WEPSET_ALL |= (WEPSET_##id = WepSet_FromWeapon(this.m_id)); \
62                 if ((this.spawnflags) & WEP_FLAG_SUPERWEAPON) WEPSET_SUPERWEAPONS |= WEPSET_##id; \
63                 register_weapon(this, this.m_id, WEPSET_##id); \
64                 localcmd(sprintf("alias weapon_%s \"impulse %d\"\n", this.netname, 230 + this.m_id - 1)); \
65         } \
66         REGISTER_INIT(WEP, id)
67
68 #define _REGISTER_WEAPON(id, function, ammotype, impulse, flags, rating, color, modelname, mdl, crosshair, wepimg, refname, wepname) \
69         REGISTER_WEAPON_2(id, NEW(Weapon, function, ammotype, impulse, flags, rating, color, modelname, mdl, crosshair, wepimg, refname, wepname))
70
71 #ifndef MENUQC
72         #define REGISTER_WEAPON_13(id, function, ammotype, impulse, flags, rating, color, modelname, mdl, crosshair, wepimg, refname, wepname) \
73         bool function(entity this, int); \
74         _REGISTER_WEAPON(id, function, ammotype, impulse, flags, rating, color, modelname, mdl, crosshair, wepimg, refname, wepname)
75 #else
76         #define REGISTER_WEAPON_13(id, function, ammotype, impulse, flags, rating, color, modelname, mdl, crosshair, wepimg, refname, wepname) \
77                 _REGISTER_WEAPON(id, w_new,   ammotype, impulse, flags, rating, color, modelname, NULL, crosshair, wepimg, refname, wepname)
78 #endif
79
80 // create cvars for weapon settings
81 #define WEP_ADD_CVAR_NONE(wepname,name) [[last]] float autocvar_g_balance_##wepname##_##name;
82
83 #define WEP_ADD_CVAR_PRI(wepname,name) WEP_ADD_CVAR_NONE(wepname, primary_##name)
84 #define WEP_ADD_CVAR_SEC(wepname,name) WEP_ADD_CVAR_NONE(wepname, secondary_##name)
85 #define WEP_ADD_CVAR_BOTH(wepname,name) \
86         WEP_ADD_CVAR_PRI(wepname, name) \
87         WEP_ADD_CVAR_SEC(wepname, name)
88
89 #define WEP_ADD_CVAR(wepid,wepname,mode,name) WEP_ADD_CVAR_##mode(wepname, name)
90
91 // create properties for weapon settings
92 #define WEP_ADD_PROP(wepid,wepname,type,prop,name) \
93         .type prop; \
94         [[last]] type autocvar_g_balance_##wepname##_##name;
95
96 // read cvars from weapon settings
97 #define WEP_CVAR(wepname,name) autocvar_g_balance_##wepname##_##name
98 #define WEP_CVAR_PRI(wepname,name) WEP_CVAR(wepname, primary_##name)
99 #define WEP_CVAR_SEC(wepname,name) WEP_CVAR(wepname, secondary_##name)
100 #define WEP_CVAR_BOTH(wepname,isprimary,name) ((isprimary) ? WEP_CVAR_PRI(wepname, name) : WEP_CVAR_SEC(wepname, name))
101
102 // set initialization values for weapon settings
103 #define WEP_SKIP_CVAR(unuseda,unusedb,unusedc,unusedd) /* skip cvars */
104 #define WEP_SET_PROP(wepid,wepname,type,prop,name) WEP_##wepid.prop = autocvar_g_balance_##wepname##_##name;
105
106 #include "all.inc"
107
108 void register_weapons_done()
109 {
110         dummy_weapon_info = NEW(Weapon);
111
112         weaponorder_byid = "";
113         for (int i = WEP_MAXCOUNT - 1; i >= 0; --i)
114                 if (weapon_info[i])
115                         weaponorder_byid = strcat(weaponorder_byid, " ", ftos(i));
116         weaponorder_byid = strzone(substring(weaponorder_byid, 1, strlen(weaponorder_byid) - 1));
117 }
118
119 ACCUMULATE_FUNCTION(RegisterWeapons, register_weapons_done)
120 #endif