]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapons.qh
No need for that extra prefix
[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
39 // WEAPONTODO
40 const float     IT_UNLIMITED_WEAPON_AMMO     = 1;
41 // when this bit is set, using a weapon does not reduce ammo. Checkpoints can give this powerup.
42 const float     IT_UNLIMITED_SUPERWEAPONS    = 2;
43 // when this bit is set, superweapons don't expire. Checkpoints can give this powerup.
44 const float   IT_CTF_SHIELDED              = 4; // set for the flag shield
45 const float   IT_USING_JETPACK             = 8; // confirmation that button is pressed
46 const float   IT_JETPACK                   = 16; // actual item
47 const float   IT_FUEL_REGEN                = 32; // fuel regeneration trigger
48 WANT_CONST float   IT_SHELLS                    = 256;
49 WANT_CONST float   IT_NAILS                     = 512;
50 WANT_CONST float   IT_ROCKETS                   = 1024;
51 WANT_CONST float   IT_CELLS                     = 2048;
52 const float   IT_SUPERWEAPON               = 4096;
53 const float   IT_FUEL                      = 128;
54 const float   IT_STRENGTH                  = 8192;
55 const float   IT_INVINCIBLE                = 16384;
56 const float   IT_HEALTH                    = 32768;
57 // union:
58         // for items:
59         WANT_CONST float        IT_KEY1                                 = 131072;
60         WANT_CONST float        IT_KEY2                                 = 262144;
61         // for players:
62         const float     IT_RED_FLAG_TAKEN               = 32768;
63         const float     IT_RED_FLAG_LOST                = 65536;
64         const float     IT_RED_FLAG_CARRYING            = 98304;
65         const float     IT_BLUE_FLAG_TAKEN              = 131072;
66         const float     IT_BLUE_FLAG_LOST               = 262144;
67         const float     IT_BLUE_FLAG_CARRYING   = 393216;
68 // end
69 const float   IT_5HP                       = 524288;
70 const float   IT_25HP                      = 1048576;
71 const float   IT_ARMOR_SHARD               = 2097152;
72 const float   IT_ARMOR                     = 4194304;
73
74 const float   IT_AMMO                      = 3968; // IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS | IT_FUEL;
75 const float   IT_PICKUPMASK                = 51; // IT_FUEL_REGEN | IT_JETPACK | IT_UNLIMITED_AMMO; // strength and invincible are handled separately
76 const float   IT_UNLIMITED_AMMO            = 3; // IT_UNLIMITED_SUPERWEAPONS | IT_UNLIMITED_WEAPON_AMMO;
77
78 const float AMMO_COUNT = 4; // amount of ammo types to show in the inventory panel
79
80 // variables:
81 string weaponorder_byid;
82
83 // Weapon sets
84 typedef vector WepSet;
85 WepSet WepSet_FromWeapon(float a);
86 #ifdef SVQC
87 void WepSet_AddStat();
88 void WriteWepSet(float dest, WepSet w);
89 #endif
90 #ifdef CSQC
91 WepSet WepSet_GetFromStat();
92 WepSet ReadWepSet();
93 #endif
94
95 // Weapon name macros
96 #define WEP_FIRST 1
97 #define WEP_MAXCOUNT 24 // Increase as needed. Can be up to three times as much.
98 float WEP_COUNT;
99 float WEP_LAST;
100 WepSet WEPSET_ALL;
101 WepSet WEPSET_SUPERWEAPONS;
102
103 // functions:
104 entity get_weaponinfo(float id);
105 string W_FixWeaponOrder(string order, float complete);
106 string W_NameWeaponOrder(string order);
107 string W_NumberWeaponOrder(string order);
108 string W_FixWeaponOrder_BuildImpulseList(string o);
109 string W_FixWeaponOrder_AllowIncomplete(string order);
110 string W_FixWeaponOrder_ForceComplete(string order);
111
112 void W_RandomWeapons(entity e, float n);
113
114 string W_Name(float weaponid);
115
116 float W_AmmoItemCode(float wpn);
117
118
119 // ammo types
120 .float ammo_shells;
121 .float ammo_nails;
122 .float ammo_rockets;
123 .float ammo_cells;
124 .float ammo_fuel;
125 .float ammo_none;
126 .float ammo_broken; // dummy
127
128 // entity properties of weaponinfo:
129 .float weapon; // WEP_...
130 .WepSet weapons; // WEPSET_...
131 .string netname; // short name
132 .string message; // human readable name
133 .float items; // IT_...
134 .float(float) weapon_func; // w_...
135 .string mdl; // modelname without g_, v_, w_
136 .string model; // full name of g_ model
137 .float spawnflags; // WEPSPAWNFLAG_... combined
138 .float impulse; // weapon impulse
139 .float bot_pickupbasevalue; // bot weapon priority
140 .string model2; // wpn- sprite name
141 ..float current_ammo; // main ammo field
142
143 // other useful macros
144 #define WEP_ACTION(wpn,wrequest) (get_weaponinfo(wpn)).weapon_func(wrequest)
145
146
147 // =====================
148 //  Weapon Registration
149 // =====================
150
151 // create cvars for weapon settings
152 #define WEP_ADD_CVAR_PRI(wepname,name) final float autocvar_g_balance_##wepname##_primary_##name;
153 #define WEP_ADD_CVAR_SEC(wepname,name) final float autocvar_g_balance_##wepname##_secondary_##name;
154 #define WEP_ADD_CVAR_BOTH(wepname,name) \
155         final float autocvar_g_balance_##wepname##_primary_##name; \
156         final float autocvar_g_balance_##wepname##_secondary_##name;
157 #define WEP_ADD_CVAR_NONE(wepname,name) final float autocvar_g_balance_##wepname##_##name;
158 #define WEP_ADD_CVAR(wepid,wepname,mode,name) WEP_ADD_CVAR_##mode(wepname, name)
159
160 // create properties for weapon settings
161 #define WEP_ADD_PROP(wepid,wepname,type,prop,name) \
162         .type ##prop; \
163         final type autocvar_g_balance_##wepname##_##name;
164
165 // read cvars from weapon settings
166 #define WEP_CVAR(wepname,name) autocvar_g_balance_##wepname##_##name
167 #define WEP_CVAR_PRI(wepname,name) WEP_CVAR(wepname, primary_##name)
168 #define WEP_CVAR_SEC(wepname,name) WEP_CVAR(wepname, secondary_##name)
169 #define WEP_CVAR_BOTH(wepname,isprimary,name) ((isprimary) ? WEP_CVAR_PRI(wepname, name) : WEP_CVAR_SEC(wepname, name))
170
171 // set initialization values for weapon settings
172 #define WEP_SKIPCVAR(unuseda,unusedb,unusedc,unusedd) /* skip cvars */
173 #define WEP_SET_PROP(wepid,wepname,type,prop,name) get_weaponinfo(WEP_##wepid).##prop = autocvar_g_balance_##wepname##_##name;
174
175 float w_null(float dummy);
176 void register_weapon(float id, WepSet bit, float(float) func, .float ammotype, float i, float weapontype, float pickupbasevalue, string modelname, string shortname, string wname);
177 void register_weapons_done();
178
179 // note: the fabs call is just there to hide "if result is constant" warning
180 #define REGISTER_WEAPON_2(id,bit,func,ammotype,i,weapontype,pickupbasevalue,modelname,shortname,wname) \
181         float id; \
182         WepSet bit; \
183         float func(float); \
184         void RegisterWeapons_##id() \
185         { \
186                 WEP_LAST = (id = WEP_FIRST + WEP_COUNT); \
187                 bit = WepSet_FromWeapon(id); \
188                 WEPSET_ALL |= bit; \
189                 if((weapontype) & WEP_FLAG_SUPERWEAPON) \
190                         WEPSET_SUPERWEAPONS |= bit; \
191                 ++WEP_COUNT; \
192                 register_weapon(id,bit,func,ammotype,i,weapontype,pickupbasevalue,modelname,shortname,wname); \
193         } \
194         ACCUMULATE_FUNCTION(RegisterWeapons, RegisterWeapons_##id)
195 #ifdef MENUQC
196 #define REGISTER_WEAPON(id,func,ammotype,i,weapontype,pickupbasevalue,modelname,shortname,wname) \
197         REGISTER_WEAPON_2(WEP_##id,WEPSET_##id,w_null,ammotype,i,weapontype,pickupbasevalue,modelname,shortname,wname)
198 #else
199 #define REGISTER_WEAPON(id,func,ammotype,i,weapontype,pickupbasevalue,modelname,shortname,wname) \
200         REGISTER_WEAPON_2(WEP_##id,WEPSET_##id,func,ammotype,i,weapontype,pickupbasevalue,modelname,shortname,wname)
201 #endif
202
203 #include "all.qh"
204
205 #undef WEP_ADD_CVAR_MO_PRI
206 #undef WEP_ADD_CVAR_MO_SEC
207 #undef WEP_ADD_CVAR_MO_BOTH
208 #undef WEP_ADD_CVAR_MO_NONE
209 #undef WEP_ADD_CVAR
210 #undef WEP_ADD_PROP
211 #undef REGISTER_WEAPON
212
213 ACCUMULATE_FUNCTION(RegisterWeapons, register_weapons_done);