Merge branch 'master' into TimePath/csqc_viewmodels
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / all.qh
1 #ifndef WEAPONS_ALL_H
2 #define WEAPONS_ALL_H
3
4 #include "../command/all.qh"
5 #include "../stats.qh"
6 #include "config.qh"
7
8 // weapon sets
9 typedef vector WepSet;
10 #ifdef SVQC
11 void WriteWepSet(float dest, WepSet w);
12 #endif
13
14 #ifdef CSQC
15 WepSet WepSet_GetFromStat();
16 WepSet WepSet_GetFromStat_InMap();
17 WepSet ReadWepSet();
18 #endif
19
20 #include "weapon.qh"
21
22 #ifndef MENUQC
23 #include "calculations.qh"
24 #include "../models/all.qh"
25 #endif
26
27 #include "../util.qh"
28
29 #ifdef SVQC
30 #include "../../server/bot/aim.qh"
31 #endif
32
33 REGISTRY(Weapons, 72) // Increase as needed. Can be up to 72.
34 #define Weapons_from(i) _Weapons_from(i, WEP_Null)
35 #define get_weaponinfo(i) Weapons_from(i)
36 REGISTER_REGISTRY(Weapons)
37 STATIC_INIT(WeaponPickup) { FOREACH(Weapons, true, LAMBDA(it.m_pickup = NEW(WeaponPickup, it))); }
38
39 .WepSet m_wepset;
40 #define WEPSET(id) (WEP_##id.m_wepset)
41 #define WepSet_FromWeapon(i) (Weapons_from(i).m_wepset)
42 WepSet _WepSet_FromWeapon(int i);
43 STATIC_INIT(WepSets)
44 {
45     FOREACH(Weapons, true, LAMBDA(it.m_wepset = _WepSet_FromWeapon(it.m_id)));
46 }
47
48 GENERIC_COMMAND(dumpweapons, "Dump all weapons into weapons_dump.txt") // WEAPONTODO: make this work with other progs than just server
49 {
50     switch(request)
51     {
52         case CMD_REQUEST_COMMAND:
53         {
54             #ifdef SVQC
55             wep_config_file = -1;
56             wep_config_alsoprint = -1;
57             string filename = argv(1);
58
59             if(filename == "")
60             {
61                 filename = "weapons_dump.cfg";
62                 wep_config_alsoprint = false;
63             }
64             else if(filename == "-")
65             {
66                 filename = "weapons_dump.cfg";
67                 wep_config_alsoprint = true;
68             }
69             wep_config_file = fopen(filename, FILE_WRITE);
70
71             if(wep_config_file >= 0)
72             {
73                 Dump_Weapon_Settings();
74                 LOG_INFO(sprintf("Dumping weapons... File located in ^2data/data/%s^7.\n", filename));
75                 fclose(wep_config_file);
76                 wep_config_file = -1;
77                 wep_config_alsoprint = -1;
78             }
79             else
80             {
81                 LOG_INFO(sprintf("^1Error: ^7Could not open file '%s'!\n", filename));
82             }
83             #else
84             LOG_INFO(_("Weapons dump command only works with sv_cmd.\n"));
85             #endif
86             return;
87         }
88
89         default:
90         case CMD_REQUEST_USAGE:
91         {
92             LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " dumpweapons [filename]"));
93             LOG_INFO("  Where 'filename' is the file to write (default is weapons_dump.cfg),\n");
94             LOG_INFO("  if supplied with '-' output to console as well as default,\n");
95             LOG_INFO("  if left blank, it will only write to default.\n");
96             return;
97         }
98     }
99 }
100
101 #define REGISTER_WEAPON(id, inst) \
102     /* WepSet WEPSET_##id; */ \
103     REGISTER(Weapons, WEP, id, m_id, inst)
104
105 // create cvars for weapon settings
106 #define WEP_ADD_CVAR_NONE(wepname,name) [[last]] float autocvar_g_balance_##wepname##_##name;
107
108 #define WEP_ADD_CVAR_PRI(wepname,name) WEP_ADD_CVAR_NONE(wepname, primary_##name)
109 #define WEP_ADD_CVAR_SEC(wepname,name) WEP_ADD_CVAR_NONE(wepname, secondary_##name)
110 #define WEP_ADD_CVAR_BOTH(wepname,name) \
111     WEP_ADD_CVAR_PRI(wepname, name) \
112     WEP_ADD_CVAR_SEC(wepname, name)
113
114 #define WEP_ADD_CVAR(wepid,wepname,mode,name) WEP_ADD_CVAR_##mode(wepname, name)
115
116 // create properties for weapon settings
117 #define WEP_ADD_PROP(wepid,wepname,type,prop,name) \
118     .type prop; \
119     [[last]] type autocvar_g_balance_##wepname##_##name;
120
121 // read cvars from weapon settings
122 #define WEP_CVAR(wepname,name) autocvar_g_balance_##wepname##_##name
123 #define WEP_CVAR_PRI(wepname,name) WEP_CVAR(wepname, primary_##name)
124 #define WEP_CVAR_SEC(wepname,name) WEP_CVAR(wepname, secondary_##name)
125 #define WEP_CVAR_BOTH(wepname,isprimary,name) ((isprimary) ? WEP_CVAR_PRI(wepname, name) : WEP_CVAR_SEC(wepname, name))
126
127 // set initialization values for weapon settings
128 #define WEP_SKIP_CVAR(unuseda,unusedb,unusedc,unusedd) /* skip cvars */
129 #define WEP_SET_PROP(wepid,wepname,type,prop,name) WEP_##wepid.prop = autocvar_g_balance_##wepname##_##name;
130
131 const int WEP_FIRST = 1;
132 #define WEP_LAST (Weapons_COUNT - 1)
133 WepSet WEPSET_ALL;
134 WepSet WEPSET_SUPERWEAPONS;
135
136 REGISTER_WEAPON(Null, NEW(Weapon));
137
138 #include "all.inc"
139
140 // TODO: remove after 0.8.2. Retains impulse number compatibility because 0.8.1 clients don't reload the weapons.cfg
141 #define WEP_HARDCODED_IMPULSES 20
142
143 // TODO: invert after 0.8.2. Will require moving 'best weapon' impulses
144 #define WEP_IMPULSE_BEGIN 230
145 #define WEP_IMPULSE_END bound(WEP_IMPULSE_BEGIN, WEP_IMPULSE_BEGIN + (Weapons_COUNT - 1) - 1, 253)
146
147 REGISTRY_SORT(Weapons, WEP_HARDCODED_IMPULSES + 1)
148 REGISTRY_CHECK(Weapons)
149
150 STATIC_INIT(register_weapons_done)
151 {
152     FOREACH(Weapons, true, LAMBDA(
153         it.m_id = i;
154         WepSet set = it.m_wepset;
155         WEPSET_ALL |= set;
156         if ((it.spawnflags) & WEP_FLAG_SUPERWEAPON) WEPSET_SUPERWEAPONS |= set;
157         it.weapon = it.m_id;
158         it.weapons = set;
159         int imp = WEP_IMPULSE_BEGIN + it.m_id - 1;
160         if (imp <= WEP_IMPULSE_END)
161             localcmd(sprintf("alias weapon_%s \"impulse %d\"\n", it.netname, imp));
162         else
163             LOG_TRACEF(_("Impulse limit exceeded, weapon will not be directly accessible: %s\n"), it.netname);
164     ));
165     #ifdef CSQC
166     FOREACH(Weapons, true, LAMBDA(it.wr_init(it)));
167     #endif
168     weaponorder_byid = "";
169     for (int i = Weapons_MAX - 1; i >= 1; --i)
170         if (Weapons_from(i))
171             weaponorder_byid = strcat(weaponorder_byid, " ", ftos(i));
172     weaponorder_byid = strzone(substring(weaponorder_byid, 1, strlen(weaponorder_byid) - 1));
173 }
174
175 #ifndef MENUQC
176
177 .entity weaponchild;
178 .entity exteriorweaponentity;
179 .vector weaponentity_glowmod;
180
181 //.int weapon; // current weapon
182 #ifdef SVQC
183 .int switchweapon = _STAT(SWITCHWEAPON);
184 .int switchingweapon = _STAT(SWITCHINGWEAPON);
185 #endif
186 .string weaponname; // name of .weapon
187
188 .vector spawnorigin; // for casings
189
190 // weapon animation vectors:
191 .vector anim_fire1;
192 .vector anim_fire2;
193 .vector anim_idle;
194 .vector anim_reload;
195
196 // static frame globals
197
198 ENUMCLASS(WFRAME)
199 CASE(WFRAME, DONTCHANGE)
200 CASE(WFRAME, FIRE1)
201 CASE(WFRAME, FIRE2)
202 CASE(WFRAME, IDLE)
203 CASE(WFRAME, RELOAD)
204 ENUMCLASS_END(WFRAME)
205
206 .WFRAME wframe;
207
208 vector shotorg_adjust_values(vector vecs, bool y_is_right, bool visual, int algn);
209 void CL_WeaponEntity_SetModel(entity this, string name);
210 #endif
211
212 #endif