]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapons.qh
Some more cleanup
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapons.qh
1 #ifndef MENUQC
2 #include "calculations.qh"
3 #endif
4
5 const float MAX_SHOT_DISTANCE = 32768;
6
7 // weapon pickup ratings for bot logic
8 const float BOT_PICKUP_RATING_LOW  =  2500;
9 const float BOT_PICKUP_RATING_MID  =  5000;
10 const float BOT_PICKUP_RATING_HIGH = 10000;
11
12 // weapon flags
13 const float WEP_TYPE_OTHER          =  0x00; // not for damaging people
14 const float WEP_TYPE_SPLASH         =  0x01; // splash damage
15 const float WEP_TYPE_HITSCAN        =  0x02; // hitscan
16 const float WEP_TYPEMASK            =  0x0F;
17 const float WEP_FLAG_CANCLIMB       =  0x10; // can be used for movement
18 const float WEP_FLAG_NORMAL         =  0x20; // in "most weapons" set
19 const float WEP_FLAG_HIDDEN         =  0x40; // hides from menu
20 const float WEP_FLAG_RELOADABLE     =  0x80; // can has reload
21 const float WEP_FLAG_SUPERWEAPON    = 0x100; // powerup timer
22 const float WEP_FLAG_MUTATORBLOCKED = 0x200; // hides from impulse 99 etc. (mutators are allowed to clear this flag)
23
24 // weapon requests
25 const float WR_SETUP          =  1; // (SERVER) setup weapon data
26 const float WR_THINK          =  2; // (SERVER) logic to run every frame
27 const float WR_CHECKAMMO1     =  3; // (SERVER) checks ammo for weapon primary
28 const float WR_CHECKAMMO2     =  4; // (SERVER) checks ammo for weapon second
29 const float WR_AIM            =  5; // (SERVER) runs bot aiming code for this weapon
30 const float WR_INIT           =  6; // (BOTH)   precaches models/sounds used by this weapon, also sets up weapon properties
31 const float WR_SUICIDEMESSAGE =  7; // (SERVER) notification number for suicide message (may inspect w_deathtype for details)
32 const float WR_KILLMESSAGE    =  8; // (SERVER) notification number for kill message (may inspect w_deathtype for details)
33 const float WR_RELOAD         =  9; // (SERVER) handles reloading for weapon
34 const float WR_RESETPLAYER    = 10; // (SERVER) clears fields that the weapon may use
35 const float WR_IMPACTEFFECT   = 11; // (CLIENT) impact effect for weapon explosion
36 const float WR_SWITCHABLE     = 12; // (CLIENT) decides whether the player is able to switch away from this weapon
37 const float WR_PLAYERDEATH    = 13; // (SERVER) called whenever a player dies
38 const float WR_GONETHINK      = 14; // (SERVER) logic to run when weapon is lost/switched away from
39 const float WR_CONFIG         = 15; // (ALL)    dump weapon cvars to config in data directory (see: sv_cmd dumpweapons)
40 const float WR_ZOOMRETICLE    = 16; // (CLIENT) weapon specific zoom reticle
41
42 // variables:
43 string weaponorder_byid;
44
45 // weapon sets
46 typedef vector WepSet;
47 WepSet WepSet_FromWeapon(float a);
48 #ifdef SVQC
49 void WepSet_AddStat();
50 void WriteWepSet(float dest, WepSet w);
51 #endif
52 #ifdef CSQC
53 WepSet WepSet_GetFromStat();
54 WepSet ReadWepSet();
55 #endif
56
57 // weapon name macros
58 #define WEP_FIRST 1
59 #define WEP_MAXCOUNT 24 // Increase as needed. Can be up to three times as much.
60 float WEP_COUNT;
61 float WEP_LAST;
62 WepSet WEPSET_ALL;
63 WepSet WEPSET_SUPERWEAPONS;
64
65 // functions:
66 entity get_weaponinfo(float id);
67 string W_FixWeaponOrder(string order, float complete);
68 string W_NameWeaponOrder(string order);
69 string W_NumberWeaponOrder(string order);
70 string W_FixWeaponOrder_BuildImpulseList(string o);
71 string W_FixWeaponOrder_AllowIncomplete(string order);
72 string W_FixWeaponOrder_ForceComplete(string order);
73 void W_RandomWeapons(entity e, float n);
74 string W_Name(float weaponid);
75
76 #ifdef CSQC
77 .float GetAmmoFieldFromNum(float i);
78 string GetAmmoPicture(.float ammotype);
79 float GetAmmoStat(.float ammotype);
80 #endif
81
82 // ammo types
83 .float ammo_shells;
84 .float ammo_nails;
85 .float ammo_rockets;
86 .float ammo_cells;
87 .float ammo_fuel;
88 .float ammo_none;
89
90 // other useful macros
91 #define WEP_ACTION(wpn,wrequest) (get_weaponinfo(wpn)).weapon_func(wrequest)
92 #define AMMO_VAL(wpn) ((get_weaponinfo(wpn)).ammo_field)
93
94
95 // ======================
96 //  Configuration Macros
97 // ======================
98
99 // create cvars for weapon settings
100 #define WEP_ADD_CVAR_NONE(wepname,name) [[last]] float autocvar_g_balance_##wepname##_##name;
101
102 #define WEP_ADD_CVAR_PRI(wepname,name) WEP_ADD_CVAR_NONE(wepname, primary_##name)
103 #define WEP_ADD_CVAR_SEC(wepname,name) WEP_ADD_CVAR_NONE(wepname, secondary_##name)
104 #define WEP_ADD_CVAR_BOTH(wepname,name) \
105         WEP_ADD_CVAR_PRI(wepname, name) \
106         WEP_ADD_CVAR_SEC(wepname, name)
107
108 #define WEP_ADD_CVAR(wepid,wepname,mode,name) WEP_ADD_CVAR_##mode(wepname, name)
109
110 // create properties for weapon settings
111 #define WEP_ADD_PROP(wepid,wepname,type,prop,name) \
112         .type ##prop; \
113         [[last]] type autocvar_g_balance_##wepname##_##name;
114
115 // read cvars from weapon settings
116 #define WEP_CVAR(wepname,name) autocvar_g_balance_##wepname##_##name
117 #define WEP_CVAR_PRI(wepname,name) WEP_CVAR(wepname, primary_##name)
118 #define WEP_CVAR_SEC(wepname,name) WEP_CVAR(wepname, secondary_##name)
119 #define WEP_CVAR_BOTH(wepname,isprimary,name) ((isprimary) ? WEP_CVAR_PRI(wepname, name) : WEP_CVAR_SEC(wepname, name))
120
121 // set initialization values for weapon settings
122 #define WEP_SKIPCVAR(unuseda,unusedb,unusedc,unusedd) /* skip cvars */
123 #define WEP_SET_PROP(wepid,wepname,type,prop,name) get_weaponinfo(WEP_##wepid).##prop = autocvar_g_balance_##wepname##_##name;
124
125
126 // =====================
127 //  Weapon Registration
128 // =====================
129
130 float w_null(float dummy);
131
132 void register_weapon(
133         float id,
134         WepSet bit,
135         float(float) func,
136         .float ammotype,
137         float i,
138         float weapontype,
139         float pickupbasevalue,
140         vector clr,
141         string modelname,
142         string shortname,
143         string wname);
144
145 void register_weapons_done();
146
147 // entity properties of weaponinfo:
148 .float weapon; // WEP_...
149 .WepSet weapons; // WEPSET_...
150 .string netname; // short name
151 .string message; // human readable name
152 .float(float) weapon_func; // w_...
153 .vector wpcolor; // waypointsprite color
154 .string mdl; // modelname without g_, v_, w_
155 .string model; // full name of g_ model
156 .float spawnflags; // WEPSPAWNFLAG_... combined
157 .float impulse; // weapon impulse
158 .float bot_pickupbasevalue; // bot weapon priority
159 .string model2; // wpn- sprite name
160 ..float ammo_field; // main ammo field
161
162 // note: the fabs call is just there to hide "if result is constant" warning
163 #define REGISTER_WEAPON_2(id,bit,func,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname) \
164         float id; \
165         WepSet bit; \
166         float func(float); \
167         void RegisterWeapons_##id() \
168         { \
169                 WEP_LAST = (id = WEP_FIRST + WEP_COUNT); \
170                 bit = WepSet_FromWeapon(id); \
171                 WEPSET_ALL |= bit; \
172                 if((weapontype) & WEP_FLAG_SUPERWEAPON) \
173                         WEPSET_SUPERWEAPONS |= bit; \
174                 ++WEP_COUNT; \
175                 register_weapon(id,bit,func,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname); \
176         } \
177         ACCUMULATE_FUNCTION(RegisterWeapons, RegisterWeapons_##id)
178 #ifdef MENUQC
179 #define REGISTER_WEAPON(id,func,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname) \
180         REGISTER_WEAPON_2(WEP_##id,WEPSET_##id,w_null,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname)
181 #else
182 #define REGISTER_WEAPON(id,func,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname) \
183         REGISTER_WEAPON_2(WEP_##id,WEPSET_##id,func,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname)
184 #endif
185
186 #include "all.qh"
187
188 #undef WEP_ADD_CVAR_MO_PRI
189 #undef WEP_ADD_CVAR_MO_SEC
190 #undef WEP_ADD_CVAR_MO_BOTH
191 #undef WEP_ADD_CVAR_MO_NONE
192 #undef WEP_ADD_CVAR
193 #undef WEP_ADD_PROP
194 #undef REGISTER_WEAPON
195
196 ACCUMULATE_FUNCTION(RegisterWeapons, register_weapons_done);