]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapons.qh
Whoops, left that in there by mistake
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapons.qh
1 #ifndef MENUQC
2 #include "calculations.qh"
3 #endif
4
5 const float BOT_PICKUP_RATING_LOW       = 2500;
6 const float BOT_PICKUP_RATING_MID       = 5000;
7 const float BOT_PICKUP_RATING_HIGH      = 10000;
8
9 const float WEP_TYPE_OTHER            =  0x00; // not for damaging people
10 const float WEP_TYPE_SPLASH           =  0x01; // splash damage
11 const float WEP_TYPE_HITSCAN          =  0x02; // hitscan
12 const float WEP_TYPEMASK            =  0x0F;
13 const float WEP_FLAG_CANCLIMB       =  0x10; // can be used for movement
14 const float WEP_FLAG_NORMAL         =  0x20; // in "most weapons" set
15 const float WEP_FLAG_HIDDEN         =  0x40; // hides from menu
16 const float WEP_FLAG_RELOADABLE     =  0x80; // can has reload
17 const float WEP_FLAG_SUPERWEAPON    = 0x100; // powerup timer
18 const float WEP_FLAG_MUTATORBLOCKED = 0x200; // hides from impulse 99 etc. (mutators are allowed to clear this flag)
19
20 const float MAX_SHOT_DISTANCE = 32768;
21
22 // weapon requests // WEAPONTODO
23 #define WR_SETUP          1 // (SERVER) setup weapon data
24 #define WR_THINK          2 // (SERVER) logic to run every frame
25 #define WR_CHECKAMMO1     3 // (SERVER) checks ammo for weapon
26 #define WR_CHECKAMMO2     4 // (SERVER) checks ammo for weapon
27 #define WR_AIM            5 // (SERVER) runs bot aiming code for this weapon
28 #define WR_INIT           6 // (BOTH) precaches models/sounds used by this weapon
29 #define WR_SUICIDEMESSAGE 7 // (SERVER) notification number for suicide message (may inspect w_deathtype for details)
30 #define WR_KILLMESSAGE    8 // (SERVER) notification number for kill message (may inspect w_deathtype for details)
31 #define WR_RELOAD         9 // (SERVER) does not need to do anything
32 #define WR_RESETPLAYER    10 // (SERVER) does not need to do anything
33 #define WR_IMPACTEFFECT   11 // (CLIENT) impact effect
34 #define WR_SWITCHABLE     12 // (CLIENT) impact effect
35 #define WR_PLAYERDEATH    13 // (SERVER) does not need to do anything
36 #define WR_GONETHINK      14 // (SERVER) logic to run every frame, also if no longer having the weapon as long as the switch away has not been performed
37 #define WR_CONFIG         15 // (ALL)
38 #define WR_ZOOMRETICLE    16 // (CLIENT) weapon specific zoom reticle
39
40 // WEAPONTODO
41 const float     IT_UNLIMITED_WEAPON_AMMO     = 1;
42 // when this bit is set, using a weapon does not reduce ammo. Checkpoints can give this powerup.
43 const float     IT_UNLIMITED_SUPERWEAPONS    = 2;
44 // when this bit is set, superweapons don't expire. Checkpoints can give this powerup.
45 const float   IT_CTF_SHIELDED              = 4; // set for the flag shield
46 const float   IT_USING_JETPACK             = 8; // confirmation that button is pressed
47 const float   IT_JETPACK                   = 16; // actual item
48 const float   IT_FUEL_REGEN                = 32; // fuel regeneration trigger
49 WANT_CONST float   IT_SHELLS                    = 256;
50 WANT_CONST float   IT_NAILS                     = 512;
51 WANT_CONST float   IT_ROCKETS                   = 1024;
52 WANT_CONST float   IT_CELLS                     = 2048;
53 const float   IT_SUPERWEAPON               = 4096;
54 const float   IT_FUEL                      = 128;
55 const float   IT_STRENGTH                  = 8192;
56 const float   IT_INVINCIBLE                = 16384;
57 const float   IT_HEALTH                    = 32768;
58 // union:
59         // for items:
60         WANT_CONST float        IT_KEY1                                 = 131072;
61         WANT_CONST float        IT_KEY2                                 = 262144;
62         // for players:
63         const float     IT_RED_FLAG_TAKEN               = 32768;
64         const float     IT_RED_FLAG_LOST                = 65536;
65         const float     IT_RED_FLAG_CARRYING            = 98304;
66         const float     IT_BLUE_FLAG_TAKEN              = 131072;
67         const float     IT_BLUE_FLAG_LOST               = 262144;
68         const float     IT_BLUE_FLAG_CARRYING   = 393216;
69 // end
70 const float   IT_5HP                       = 524288;
71 const float   IT_25HP                      = 1048576;
72 const float   IT_ARMOR_SHARD               = 2097152;
73 const float   IT_ARMOR                     = 4194304;
74
75 const float   IT_AMMO                      = 3968; // IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS | IT_FUEL;
76 const float   IT_PICKUPMASK                = 51; // IT_FUEL_REGEN | IT_JETPACK | IT_UNLIMITED_AMMO; // strength and invincible are handled separately
77 const float   IT_UNLIMITED_AMMO            = 3; // IT_UNLIMITED_SUPERWEAPONS | IT_UNLIMITED_WEAPON_AMMO;
78
79 const float AMMO_COUNT = 4; // amount of ammo types to show in the inventory panel
80
81 // variables:
82 string weaponorder_byid;
83
84 // Weapon sets
85 typedef vector WepSet;
86 WepSet WepSet_FromWeapon(float a);
87 #ifdef SVQC
88 void WepSet_AddStat();
89 void WriteWepSet(float dest, WepSet w);
90 #endif
91 #ifdef CSQC
92 WepSet WepSet_GetFromStat();
93 WepSet ReadWepSet();
94 #endif
95
96 // Weapon name macros
97 #define WEP_FIRST 1
98 #define WEP_MAXCOUNT 24 // Increase as needed. Can be up to three times as much.
99 float WEP_COUNT;
100 float WEP_LAST;
101 WepSet WEPSET_ALL;
102 WepSet WEPSET_SUPERWEAPONS;
103
104 // functions:
105 entity get_weaponinfo(float id);
106 string W_FixWeaponOrder(string order, float complete);
107 string W_NameWeaponOrder(string order);
108 string W_NumberWeaponOrder(string order);
109 string W_FixWeaponOrder_BuildImpulseList(string o);
110 string W_FixWeaponOrder_AllowIncomplete(string order);
111 string W_FixWeaponOrder_ForceComplete(string order);
112
113 void W_RandomWeapons(entity e, float n);
114
115 string W_Name(float weaponid);
116
117
118 // ammo types
119 .float ammo_shells;
120 .float ammo_nails;
121 .float ammo_rockets;
122 .float ammo_cells;
123 .float ammo_fuel;
124 .float ammo_none;
125
126 // entity properties of weaponinfo:
127 .float weapon; // WEP_...
128 .WepSet weapons; // WEPSET_...
129 .string netname; // short name
130 .string message; // human readable name
131 .float items; // IT_... // WEAPONTODO: I thought I removed items from weapons... ?
132 .float(float) weapon_func; // w_...
133 .vector wpcolor; // waypointsprite color
134 .string mdl; // modelname without g_, v_, w_
135 .string model; // full name of g_ model
136 .float spawnflags; // WEPSPAWNFLAG_... combined
137 .float impulse; // weapon impulse
138 .float bot_pickupbasevalue; // bot weapon priority
139 .string model2; // wpn- sprite name
140 ..float current_ammo; // main ammo field
141
142 // other useful macros
143 #define WEP_ACTION(wpn,wrequest) (get_weaponinfo(wpn)).weapon_func(wrequest)
144 #define AMMO_VAL(wpn) ((get_weaponinfo(wpn)).current_ammo)
145
146 // =====================
147 //  Weapon Registration
148 // =====================
149
150 // create cvars for weapon settings
151 #define WEP_ADD_CVAR_NONE(wepname,name) final float autocvar_g_balance_##wepname##_##name;
152
153 #define WEP_ADD_CVAR_PRI(wepname,name) WEP_ADD_CVAR_NONE(wepname, primary_##name)
154 #define WEP_ADD_CVAR_SEC(wepname,name) WEP_ADD_CVAR_NONE(wepname, secondary_##name)
155 #define WEP_ADD_CVAR_BOTH(wepname,name) \
156         WEP_ADD_CVAR_PRI(wepname, name) \
157         WEP_ADD_CVAR_SEC(wepname, name)
158         
159 #define WEP_ADD_CVAR(wepid,wepname,mode,name) WEP_ADD_CVAR_##mode(wepname, name)
160
161 // create properties for weapon settings
162 #define WEP_ADD_PROP(wepid,wepname,type,prop,name) \
163         .type ##prop; \
164         final type autocvar_g_balance_##wepname##_##name;
165
166 // read cvars from weapon settings
167 #define WEP_CVAR(wepname,name) autocvar_g_balance_##wepname##_##name
168 #define WEP_CVAR_PRI(wepname,name) WEP_CVAR(wepname, primary_##name)
169 #define WEP_CVAR_SEC(wepname,name) WEP_CVAR(wepname, secondary_##name)
170 #define WEP_CVAR_BOTH(wepname,isprimary,name) ((isprimary) ? WEP_CVAR_PRI(wepname, name) : WEP_CVAR_SEC(wepname, name))
171
172 // set initialization values for weapon settings
173 #define WEP_SKIPCVAR(unuseda,unusedb,unusedc,unusedd) /* skip cvars */
174 #define WEP_SET_PROP(wepid,wepname,type,prop,name) get_weaponinfo(WEP_##wepid).##prop = autocvar_g_balance_##wepname##_##name;
175
176 float w_null(float dummy);
177 void register_weapon(float id, WepSet bit, float(float) func, .float ammotype, float i, float weapontype, float pickupbasevalue, vector clr, string modelname, string shortname, string wname);
178 void register_weapons_done();
179
180 // note: the fabs call is just there to hide "if result is constant" warning
181 #define REGISTER_WEAPON_2(id,bit,func,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname) \
182         float id; \
183         WepSet bit; \
184         float func(float); \
185         void RegisterWeapons_##id() \
186         { \
187                 WEP_LAST = (id = WEP_FIRST + WEP_COUNT); \
188                 bit = WepSet_FromWeapon(id); \
189                 WEPSET_ALL |= bit; \
190                 if((weapontype) & WEP_FLAG_SUPERWEAPON) \
191                         WEPSET_SUPERWEAPONS |= bit; \
192                 ++WEP_COUNT; \
193                 register_weapon(id,bit,func,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname); \
194         } \
195         ACCUMULATE_FUNCTION(RegisterWeapons, RegisterWeapons_##id)
196 #ifdef MENUQC
197 #define REGISTER_WEAPON(id,func,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname) \
198         REGISTER_WEAPON_2(WEP_##id,WEPSET_##id,w_null,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname)
199 #else
200 #define REGISTER_WEAPON(id,func,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname) \
201         REGISTER_WEAPON_2(WEP_##id,WEPSET_##id,func,ammotype,i,weapontype,pickupbasevalue,clr,modelname,shortname,wname)
202 #endif
203
204 #include "all.qh"
205
206 #undef WEP_ADD_CVAR_MO_PRI
207 #undef WEP_ADD_CVAR_MO_SEC
208 #undef WEP_ADD_CVAR_MO_BOTH
209 #undef WEP_ADD_CVAR_MO_NONE
210 #undef WEP_ADD_CVAR
211 #undef WEP_ADD_PROP
212 #undef REGISTER_WEAPON
213
214 ACCUMULATE_FUNCTION(RegisterWeapons, register_weapons_done);