]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/overkill/sv_overkill.qc
Merge branch 'martin-t/weaponorder' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / overkill / sv_overkill.qc
1 #include "sv_overkill.qh"
2
3 #include "okshotgun.qh"
4 #include "okhmg.qh"
5 #include "okrpc.qh"
6
7 bool autocvar_g_overkill_powerups_replace;
8
9 bool autocvar_g_overkill_itemwaypoints = true;
10
11 .Weapon ok_lastwep[MAX_WEAPONSLOTS];
12
13 IntrusiveList g_overkill_items;
14 STATIC_INIT(overkill)
15 {
16         g_overkill_items = IL_NEW();
17         IL_PUSH(g_overkill_items, ITEM_HealthMega);
18         IL_PUSH(g_overkill_items, ITEM_ArmorSmall);
19         IL_PUSH(g_overkill_items, ITEM_ArmorMedium);
20         IL_PUSH(g_overkill_items, ITEM_ArmorBig);
21         IL_PUSH(g_overkill_items, ITEM_ArmorMega);
22 }
23
24 /// \brief Returns a random classname of the overkill item.
25 /// \param[in] prefix Prefix of the cvars that hold probabilities.
26 /// \return Random classname of the overkill item.
27 string RandomItems_GetRandomOverkillItemClassName(string prefix)
28 {
29         RandomSelection_Init();
30         IL_EACH(g_overkill_items, !(it.spawnflags & ITEM_FLAG_MUTATORBLOCKED) &&
31                 Item_IsDefinitionAllowed(it),
32         {
33                 string cvar_name = sprintf("g_%s_%s_probability", prefix,
34                         it.m_canonical_spawnfunc);
35                 if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
36                 {
37                         LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
38                         continue;
39                 }
40                 RandomSelection_AddString(it.m_canonical_spawnfunc, cvar(cvar_name), 1);
41         });
42         string cvar_name = sprintf("g_%s_weapon_okhmg_probability", prefix);
43         if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
44         {
45                 LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
46         }
47         else
48         {
49                 RandomSelection_AddString("weapon_okhmg", cvar(cvar_name), 1);
50         }
51         cvar_name = sprintf("g_%s_weapon_okrpc_probability", prefix);
52         if (!(cvar_type(cvar_name) & CVAR_TYPEFLAG_EXISTS))
53         {
54                 LOG_WARNF("Random items: cvar %s doesn't exist.", cvar_name);
55         }
56         else
57         {
58                 RandomSelection_AddString("weapon_okrpc", cvar(cvar_name), 1);
59         }
60         return RandomSelection_chosen_string;
61 }
62
63
64 MUTATOR_HOOKFUNCTION(ok, RandomItems_GetRandomItemClassName)
65 {
66         M_ARGV(1, string) = RandomItems_GetRandomOverkillItemClassName(
67                 M_ARGV(0, string));
68         return true;
69 }
70
71 MUTATOR_HOOKFUNCTION(ok, Damage_Calculate, CBC_ORDER_LAST)
72 {
73         entity frag_attacker = M_ARGV(1, entity);
74         entity frag_target = M_ARGV(2, entity);
75         float frag_deathtype = M_ARGV(3, float);
76
77         if(IS_PLAYER(frag_attacker) && (IS_PLAYER(frag_target) || IS_VEHICLE(frag_target) || IS_TURRET(frag_target)))
78         if(DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
79         {
80                 if(frag_attacker != frag_target)
81                 if(!STAT(FROZEN, frag_target))
82                 if(!IS_DEAD(frag_target))
83                 {
84                         M_ARGV(6, vector) = '0 0 0'; // force
85                 }
86
87                 M_ARGV(4, float) = 0; // damage
88         }
89 }
90
91 void ok_DropItem(entity this, entity targ)
92 {
93         entity e = spawn();
94         e.ok_item = true;
95         Item_InitializeLoot(e, "item_armor_small", this.origin + '0 0 32',
96                 '0 0 200' + normalize(targ.origin - this.origin) * 500, 5);
97 }
98
99 MUTATOR_HOOKFUNCTION(ok, PlayerDies)
100 {
101         entity frag_attacker = M_ARGV(1, entity);
102         entity frag_target = M_ARGV(2, entity);
103
104         entity targ = ((IS_PLAYER(frag_attacker)) ? frag_attacker : frag_target);
105
106         ok_DropItem(frag_target, targ);
107
108         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
109         {
110                 .entity weaponentity = weaponentities[slot];
111
112                 frag_target.ok_lastwep[slot] = frag_target.(weaponentity).m_switchweapon;
113         }
114 }
115
116 MUTATOR_HOOKFUNCTION(ok, MonsterDropItem)
117 {
118         entity mon = M_ARGV(0, entity);
119         entity olditem = M_ARGV(1, entity);
120         entity frag_attacker = M_ARGV(2, entity);
121
122         delete(olditem);
123
124         M_ARGV(1, entity) = NULL;
125
126         ok_DropItem(mon, frag_attacker);
127 }
128
129 MUTATOR_HOOKFUNCTION(ok, ForbidThrowCurrentWeapon)
130 {
131         return true;
132 }
133
134 MUTATOR_HOOKFUNCTION(ok, PlayerPreThink)
135 {
136         if (game_stopped)
137         {
138                 return;
139         }
140         entity player = M_ARGV(0, entity);
141         if (!IS_PLAYER(player) || IS_DEAD(player) || STAT(FROZEN, player))
142         {
143                 return;
144         }
145         if (!PHYS_INPUT_BUTTON_ATCK2(player) || weaponLocked(player) ||
146                 !(round_handler_IsActive() && !round_handler_IsRoundStarted()))
147         {
148                 return;
149         }
150         // Allow secondary blaster during countdown.
151         for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
152         {
153                 .entity weaponentity = weaponentities[slot];
154                 Weapon weapon = player.(weaponentity).m_weapon;
155                 if (weapon == WEP_Null && slot != 0)
156                 {
157                         continue;
158                 }
159                 weapon.wr_think(weapon, player, weaponentity, 2);
160         }
161         PHYS_INPUT_BUTTON_ATCK2(player) = false;
162 }
163
164 MUTATOR_HOOKFUNCTION(ok, ForbidRandomStartWeapons)
165 {
166         return true;
167 }
168
169 MUTATOR_HOOKFUNCTION(ok, PlayerWeaponSelect)
170 {
171         entity player = M_ARGV(0, entity);
172
173         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
174         {
175                 .entity weaponentity = weaponentities[slot];
176                 entity thiswep = player.(weaponentity);
177
178                 if(player.ok_lastwep[slot] && player.ok_lastwep[slot] != WEP_Null)
179                 {
180                         Weapon newwep = player.ok_lastwep[slot];
181                         if(player.ok_lastwep[slot] == WEP_OVERKILL_HMG)
182                                 newwep = WEP_OVERKILL_MACHINEGUN;
183                         if(player.ok_lastwep[slot] == WEP_OVERKILL_RPC)
184                                 newwep = WEP_OVERKILL_NEX;
185                         thiswep.m_switchweapon = newwep;
186                         player.ok_lastwep[slot] = WEP_Null;
187                 }
188         }
189 }
190
191 bool ok_HandleItemWaypoints(entity e)
192 {
193         if(!autocvar_g_overkill_itemwaypoints)
194                 return false; // don't handle it
195
196         switch(e.itemdef)
197         {
198                 case ITEM_HealthMega: return true;
199                 case ITEM_ArmorMedium: return true;
200                 case ITEM_ArmorBig: return true;
201                 case ITEM_ArmorMega: return true;
202         }
203
204         return false;
205 }
206
207 MUTATOR_HOOKFUNCTION(ok, Item_RespawnCountdown)
208 {
209         entity item = M_ARGV(0, entity);
210         return ok_HandleItemWaypoints(item);
211 }
212
213 MUTATOR_HOOKFUNCTION(ok, Item_ScheduleRespawn)
214 {
215         entity item = M_ARGV(0, entity);
216         return ok_HandleItemWaypoints(item);
217 }
218
219 MUTATOR_HOOKFUNCTION(ok, FilterItem)
220 {
221         entity item = M_ARGV(0, entity);
222
223         if (item.ok_item)
224         {
225                 return false;
226         }
227         switch(item.itemdef)
228         {
229                 case ITEM_HealthMega: return autocvar_g_overkill_filter_healthmega;
230                 case ITEM_ArmorMedium: return autocvar_g_overkill_filter_armormedium;
231                 case ITEM_ArmorBig: return autocvar_g_overkill_filter_armorbig;
232                 case ITEM_ArmorMega: return autocvar_g_overkill_filter_armormega;
233         }
234         if (!autocvar_g_powerups || !autocvar_g_overkill_powerups_replace)
235         {
236                 return true;
237         }
238         if (item.classname == "item_strength")
239         {
240                 entity wep = new(weapon_okhmg);
241                 setorigin(wep, item.origin);
242                 wep.ok_item = true;
243                 wep.noalign = Item_ShouldKeepPosition(item);
244                 wep.cnt = item.cnt;
245                 wep.team = item.team;
246                 wep.respawntime = g_pickup_respawntime_superweapon;
247                 wep.pickup_anyway = true;
248                 wep.spawnfunc_checked = true;
249                 Item_Initialize(wep, "weapon_okhmg"); // doesn't actually use spawnfunc
250                 return true;
251         }
252         else if (item.classname == "item_shield")
253         {
254                 entity wep = new(weapon_okrpc);
255                 setorigin(wep, item.origin);
256                 wep.ok_item = true;
257                 wep.noalign = Item_ShouldKeepPosition(item);
258                 wep.cnt = item.cnt;
259                 wep.team = item.team;
260                 wep.respawntime = g_pickup_respawntime_superweapon;
261                 wep.pickup_anyway = true;
262                 wep.spawnfunc_checked = true;
263                 Item_Initialize(wep, "weapon_okrpc"); // doesn't actually use spawnfunc
264                 return true;
265         }
266         return true;
267 }
268
269 MUTATOR_HOOKFUNCTION(ok, SetStartItems, CBC_ORDER_LAST)
270 {
271         WepSet ok_start_items = (WEPSET(OVERKILL_MACHINEGUN) | WEPSET(OVERKILL_NEX) | WEPSET(OVERKILL_SHOTGUN));
272
273         if(WEP_OVERKILL_RPC.weaponstart > 0) { ok_start_items |= WEPSET(OVERKILL_RPC); }
274         if(WEP_OVERKILL_HMG.weaponstart > 0) { ok_start_items |= WEPSET(OVERKILL_HMG); }
275
276         // this gives unlimited ammo (the 4 types) but not fuel
277         // using `g_use_ammunition` instead gives also fuel which is unnecessary and distracting in the HUD
278         start_items |= IT_UNLIMITED_AMMO;
279
280         start_weapons = warmup_start_weapons = ok_start_items;
281 }
282
283 MUTATOR_HOOKFUNCTION(ok, SetWeaponArena)
284 {
285         // turn weapon arena off
286         M_ARGV(0, string) = "off";
287 }
288
289 MUTATOR_HOOKFUNCTION(ok, BuildMutatorsString)
290 {
291         M_ARGV(0, string) = strcat(M_ARGV(0, string), ":OK");
292 }
293
294 MUTATOR_HOOKFUNCTION(ok, BuildMutatorsPrettyString)
295 {
296         M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Overkill");
297 }
298
299 MUTATOR_HOOKFUNCTION(ok, SetModname)
300 {
301         M_ARGV(0, string) = "Overkill";
302         return true;
303 }
304