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