Weapons: remove WEP_ACTION
[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(id, inst) \
56         WepSet WEPSET_##id; \
57         REGISTER(RegisterWeapons, WEP, weapon_info, WEP_COUNT, id, m_id, inst) { \
58                 this.m_id++; \
59                 WEPSET_ALL |= (WEPSET_##id = WepSet_FromWeapon(this.m_id)); \
60                 if ((this.spawnflags) & WEP_FLAG_SUPERWEAPON) WEPSET_SUPERWEAPONS |= WEPSET_##id; \
61                 register_weapon(this, this.m_id, WEPSET_##id); \
62                 localcmd(sprintf("alias weapon_%s \"impulse %d\"\n", this.netname, 230 + this.m_id - 1)); \
63         } \
64         REGISTER_INIT(WEP, id)
65
66 // create cvars for weapon settings
67 #define WEP_ADD_CVAR_NONE(wepname,name) [[last]] float autocvar_g_balance_##wepname##_##name;
68
69 #define WEP_ADD_CVAR_PRI(wepname,name) WEP_ADD_CVAR_NONE(wepname, primary_##name)
70 #define WEP_ADD_CVAR_SEC(wepname,name) WEP_ADD_CVAR_NONE(wepname, secondary_##name)
71 #define WEP_ADD_CVAR_BOTH(wepname,name) \
72         WEP_ADD_CVAR_PRI(wepname, name) \
73         WEP_ADD_CVAR_SEC(wepname, name)
74
75 #define WEP_ADD_CVAR(wepid,wepname,mode,name) WEP_ADD_CVAR_##mode(wepname, name)
76
77 // create properties for weapon settings
78 #define WEP_ADD_PROP(wepid,wepname,type,prop,name) \
79         .type prop; \
80         [[last]] type autocvar_g_balance_##wepname##_##name;
81
82 // read cvars from weapon settings
83 #define WEP_CVAR(wepname,name) autocvar_g_balance_##wepname##_##name
84 #define WEP_CVAR_PRI(wepname,name) WEP_CVAR(wepname, primary_##name)
85 #define WEP_CVAR_SEC(wepname,name) WEP_CVAR(wepname, secondary_##name)
86 #define WEP_CVAR_BOTH(wepname,isprimary,name) ((isprimary) ? WEP_CVAR_PRI(wepname, name) : WEP_CVAR_SEC(wepname, name))
87
88 // set initialization values for weapon settings
89 #define WEP_SKIP_CVAR(unuseda,unusedb,unusedc,unusedd) /* skip cvars */
90 #define WEP_SET_PROP(wepid,wepname,type,prop,name) WEP_##wepid.prop = autocvar_g_balance_##wepname##_##name;
91
92 #include "all.inc"
93
94 void register_weapons_done()
95 {
96         dummy_weapon_info = NEW(Weapon);
97
98         weaponorder_byid = "";
99         for (int i = WEP_MAXCOUNT - 1; i >= 0; --i)
100                 if (weapon_info[i])
101                         weaponorder_byid = strcat(weaponorder_byid, " ", ftos(i));
102         weaponorder_byid = strzone(substring(weaponorder_byid, 1, strlen(weaponorder_byid) - 1));
103 }
104
105 ACCUMULATE_FUNCTION(RegisterWeapons, register_weapons_done)
106 #endif