]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapons.qh
Merge branch 'Mario/qc_updates' into TimePath/csqc_prediction
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapons.qh
1 #ifndef WEAPONS_H
2 #define WEAPONS_H
3
4 #ifndef MENUQC
5 #include "calculations.qh"
6 #endif
7
8 const int MAX_SHOT_DISTANCE = 32768;
9
10 // weapon pickup ratings for bot logic
11 const int BOT_PICKUP_RATING_LOW  =  2500;
12 const int BOT_PICKUP_RATING_MID  =  5000;
13 const int BOT_PICKUP_RATING_HIGH = 10000;
14
15 // weapon flags
16 const int WEP_TYPE_OTHER          =  0x00; // not for damaging people
17 const int WEP_TYPE_SPLASH         =  0x01; // splash damage
18 const int WEP_TYPE_HITSCAN        =  0x02; // hitscan
19 const int WEP_TYPEMASK            =  0x0F;
20 const int WEP_FLAG_CANCLIMB       =  0x10; // can be used for movement
21 const int WEP_FLAG_NORMAL         =  0x20; // in "most weapons" set
22 const int WEP_FLAG_HIDDEN         =  0x40; // hides from menu
23 const int WEP_FLAG_RELOADABLE     =  0x80; // can has reload
24 const int WEP_FLAG_SUPERWEAPON    = 0x100; // powerup timer
25 const int WEP_FLAG_MUTATORBLOCKED = 0x200; // hides from impulse 99 etc. (mutators are allowed to clear this flag)
26
27 // weapon requests
28 const int WR_SETUP          =  1; // (SERVER) setup weapon data
29 const int WR_THINK          =  2; // (SERVER) logic to run every frame
30 const int WR_CHECKAMMO1     =  3; // (SERVER) checks ammo for weapon primary
31 const int WR_CHECKAMMO2     =  4; // (SERVER) checks ammo for weapon second
32 const int WR_AIM            =  5; // (SERVER) runs bot aiming code for this weapon
33 const int WR_INIT           =  6; // (BOTH)   precaches models/sounds used by this weapon, also sets up weapon properties
34 const int WR_SUICIDEMESSAGE =  7; // (SERVER) notification number for suicide message (may inspect w_deathtype for details)
35 const int WR_KILLMESSAGE    =  8; // (SERVER) notification number for kill message (may inspect w_deathtype for details)
36 const int WR_RELOAD         =  9; // (SERVER) handles reloading for weapon
37 const int WR_RESETPLAYER    = 10; // (SERVER) clears fields that the weapon may use
38 const int WR_IMPACTEFFECT   = 11; // (CLIENT) impact effect for weapon explosion
39 const int WR_PLAYERDEATH    = 12; // (SERVER) called whenever a player dies
40 const int WR_GONETHINK      = 13; // (SERVER) logic to run when weapon is lost
41 const int WR_CONFIG         = 14; // (ALL)    dump weapon cvars to config in data directory (see: sv_cmd dumpweapons)
42 const int WR_ZOOMRETICLE    = 15; // (CLIENT) weapon specific zoom reticle
43 const int WR_DROP           = 16; // (SERVER) the weapon is dropped
44 const int WR_PICKUP         = 17; // (SERVER) a weapon is picked up
45
46 // variables:
47 string weaponorder_byid;
48
49 // weapon sets
50 typedef vector WepSet;
51 WepSet WepSet_FromWeapon(float a);
52 #ifdef SVQC
53 void WepSet_AddStat();
54 void WriteWepSet(float dest, WepSet w);
55 #endif
56 #ifdef CSQC
57 WepSet WepSet_GetFromStat();
58 WepSet ReadWepSet();
59 #endif
60
61 // weapon name macros
62 #define WEP_FIRST 1
63 #define WEP_MAXCOUNT 24 // Increase as needed. Can be up to three times as much.
64 int WEP_COUNT;
65 int WEP_LAST;
66 WepSet WEPSET_ALL;
67 WepSet WEPSET_SUPERWEAPONS;
68
69 // functions:
70 entity get_weaponinfo(float id);
71 string W_FixWeaponOrder(string order, float complete);
72 string W_NameWeaponOrder(string order);
73 string W_NumberWeaponOrder(string order);
74 string W_FixWeaponOrder_BuildImpulseList(string o);
75 string W_FixWeaponOrder_AllowIncomplete(string order);
76 string W_FixWeaponOrder_ForceComplete(string order);
77 void W_RandomWeapons(entity e, float n);
78
79 string GetAmmoPicture(.float ammotype);
80
81 #ifdef CSQC
82 .float GetAmmoFieldFromNum(int i);
83 int GetAmmoStat(.float ammotype);
84 #endif
85
86 // ammo types
87 .float ammo_shells;
88 .float ammo_nails;
89 .float ammo_rockets;
90 .float ammo_cells;
91 .float ammo_plasma;
92 .float ammo_fuel;
93 .float ammo_none;
94
95 // other useful macros
96 #define WEP_ACTION(wpn,wrequest) (get_weaponinfo(wpn)).weapon_func(wrequest)
97 #define WEP_AMMO(wpn) ((get_weaponinfo(WEP_##wpn)).ammo_field) // only used inside weapon files/with direct name, don't duplicate prefix
98 #define WEP_NAME(wpn) ((get_weaponinfo(wpn)).message)
99
100
101 // ======================
102 //  Configuration Macros
103 // ======================
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) get_weaponinfo(WEP_##wepid).##prop = autocvar_g_balance_##wepname##_##name;
130
131
132 // =====================
133 //  Weapon Registration
134 // =====================
135
136 float w_null(float dummy);
137
138 void register_weapon(
139         float id,
140         WepSet bit,
141         float(float) func,
142         .float ammotype,
143         float i,
144         float weapontype,
145         float pickupbasevalue,
146         vector clr,
147         string modelname,
148         string simplemdl,
149         string crosshair,
150         string wepimg,
151         string refname,
152         string wepname);
153
154 void register_weapons_done();
155
156 // entity properties of weaponinfo:
157 // fields which are explicitly/manually set are marked with "M", fields set automatically are marked with "A"
158 .int weapon;                // M: WEP_id    // WEP_...
159 .WepSet weapons;            // A: WEPSET_id // WEPSET_...
160 .float(float) weapon_func;  // M: function  // w_...
161 ..float ammo_field;         // M: ammotype  // main ammo field
162 .int impulse;               // M: impulse   // weapon impulse
163 .int spawnflags;            // M: flags     // WEPSPAWNFLAG_... combined
164 .float bot_pickupbasevalue; // M: rating    // bot weapon priority
165 .vector wpcolor;            // M: color     // waypointsprite color
166 .string wpmodel;            // A: wpn-id    // wpn- sprite name
167 .string mdl;                // M: modelname // name of model (without g_ v_ or h_ prefixes)
168 .string model;              // A: modelname // full path to g_ model
169 .string w_simplemdl;        // M: simplemdl // simpleitems weapon model/image
170 .string w_crosshair;        // M: crosshair // per-weapon crosshair: "CrosshairImage Size"
171 .float w_crosshair_size;    // A: crosshair // per-weapon crosshair size (argument two of "crosshair" field)
172 .string model2;             // M: wepimg    // "weaponfoobar" side view image file of weapon // WEAPONTODO: Move out of skin files, move to common files
173 .string netname;            // M: refname   // reference name name
174 .string message;            // M: wepname   // human readable name
175
176
177 // note: the fabs call is just there to hide "if result is constant" warning
178 #define REGISTER_WEAPON_2(id,bit,function,ammotype,impulse,flags,rating,color,modelname,simplemdl,crosshair,wepimg,refname,wepname) \
179         int id; \
180         WepSet bit; \
181         float function(float); \
182         void RegisterWeapons_##id() \
183         { \
184                 WEP_LAST = (id = WEP_FIRST + WEP_COUNT); \
185                 bit = WepSet_FromWeapon(id); \
186                 WEPSET_ALL |= bit; \
187                 if((flags) & WEP_FLAG_SUPERWEAPON) \
188                         WEPSET_SUPERWEAPONS |= bit; \
189                 ++WEP_COUNT; \
190                 register_weapon(id,bit,function,ammotype,impulse,flags,rating,color,modelname,simplemdl,crosshair,wepimg,refname,wepname); \
191         } \
192         ACCUMULATE_FUNCTION(RegisterWeapons, RegisterWeapons_##id)
193 #ifdef MENUQC
194 #define REGISTER_WEAPON(id,function,ammotype,impulse,flags,rating,color,modelname,simplemdl,crosshair,wepimg,refname,wepname) \
195         REGISTER_WEAPON_2(WEP_##id,WEPSET_##id,w_null,ammotype,impulse,flags,rating,color,modelname,simplemdl,crosshair,wepimg,refname,wepname)
196 #else
197 #define REGISTER_WEAPON(id,function,ammotype,impulse,flags,rating,color,modelname,simplemdl,crosshair,wepimg,refname,wepname) \
198         REGISTER_WEAPON_2(WEP_##id,WEPSET_##id,function,ammotype,impulse,flags,rating,color,modelname,simplemdl,crosshair,wepimg,refname,wepname)
199 #endif
200
201 #include "all.qh"
202
203 #undef WEP_ADD_CVAR_MO_PRI
204 #undef WEP_ADD_CVAR_MO_SEC
205 #undef WEP_ADD_CVAR_MO_BOTH
206 #undef WEP_ADD_CVAR_MO_NONE
207 #undef WEP_ADD_CVAR
208 #undef WEP_ADD_PROP
209 #undef REGISTER_WEAPON
210
211 ACCUMULATE_FUNCTION(RegisterWeapons, register_weapons_done);
212 #endif