Merge branch 'master' into Mario/wepent_experimental
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / overkill / sv_overkill.qc
1 #include "sv_overkill.qh"
2
3 #include "hmg.qh"
4 #include "rpc.qh"
5
6 bool autocvar_g_overkill_powerups_replace;
7
8 bool autocvar_g_overkill_filter_healthmega;
9 bool autocvar_g_overkill_filter_armormedium;
10 bool autocvar_g_overkill_filter_armorbig;
11 bool autocvar_g_overkill_filter_armormega;
12
13 .float ok_item;
14
15 .Weapon ok_lastwep[MAX_WEAPONSLOTS];
16
17 void ok_Initialize();
18
19 REGISTER_MUTATOR(ok, cvar("g_overkill") && !cvar("g_instagib") && !g_nexball && cvar_string("g_mod_balance") == "Overkill")
20 {
21         MUTATOR_ONADD
22         {
23                 ok_Initialize();
24         }
25
26         MUTATOR_ONREMOVE
27         {
28                 WEP_RPC.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
29                 WEP_HMG.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
30         }
31 }
32
33 void W_Blaster_Attack(entity, .entity, float, float, float, float, float, float, float, float, float, float);
34 spawnfunc(weapon_hmg);
35 spawnfunc(weapon_rpc);
36
37 MUTATOR_HOOKFUNCTION(ok, Damage_Calculate, CBC_ORDER_LAST)
38 {
39         entity frag_attacker = M_ARGV(1, entity);
40         entity frag_target = M_ARGV(2, entity);
41         float frag_deathtype = M_ARGV(3, float);
42
43         if(IS_PLAYER(frag_attacker) && (IS_PLAYER(frag_target) || IS_VEHICLE(frag_target) || IS_TURRET(frag_target)))
44         if(DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
45         {
46                 if(frag_attacker != frag_target)
47                 if(!STAT(FROZEN, frag_target))
48                 if(!IS_DEAD(frag_target))
49                 {
50                         Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE);
51                         M_ARGV(6, vector) = '0 0 0'; // force
52                 }
53
54                 M_ARGV(4, float) = 0; // damage
55         }
56 }
57
58 void ok_DropItem(entity this, entity targ)
59 {
60         entity e = new(droppedweapon); // hax
61         e.ok_item = true;
62         e.noalign = true;
63         e.pickup_anyway = true;
64         e.spawnfunc_checked = true;
65         spawnfunc_item_armor_small(e);
66         if (!wasfreed(e)) { // might have been blocked by a mutator
67         set_movetype(e, MOVETYPE_TOSS);
68         e.gravity = 1;
69         e.reset = SUB_Remove;
70         setorigin(e, this.origin + '0 0 32');
71         e.velocity = '0 0 200' + normalize(targ.origin - this.origin) * 500;
72         SUB_SetFade(e, time + 5, 1);
73         }
74 }
75
76 MUTATOR_HOOKFUNCTION(ok, PlayerDies)
77 {
78         entity frag_attacker = M_ARGV(1, entity);
79         entity frag_target = M_ARGV(2, entity);
80
81         entity targ = ((frag_attacker) ? frag_attacker : frag_target);
82
83         ok_DropItem(frag_target, targ);
84
85         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
86         {
87                 .entity weaponentity = weaponentities[slot];
88
89                 frag_target.ok_lastwep[slot] = frag_target.(weaponentity).m_switchweapon;
90         }
91 }
92
93 MUTATOR_HOOKFUNCTION(ok, MonsterDropItem)
94 {
95         entity mon = M_ARGV(0, entity);
96         entity olditem = M_ARGV(1, entity);
97         entity frag_attacker = M_ARGV(2, entity);
98
99         delete(olditem);
100
101         M_ARGV(1, entity) = NULL;
102
103         ok_DropItem(mon, frag_attacker);
104 }
105
106 MUTATOR_HOOKFUNCTION(ok, ForbidThrowCurrentWeapon)
107 {
108         return true;
109 }
110
111 MUTATOR_HOOKFUNCTION(ok, PlayerPreThink)
112 {
113         if(gameover)
114                 return;
115
116         entity player = M_ARGV(0, entity);
117
118         if(IS_DEAD(player) || !IS_PLAYER(player) || STAT(FROZEN, player))
119                 return;
120
121         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
122         {
123                 .entity weaponentity = weaponentities[slot];
124                 entity thiswep = player.(weaponentity);
125
126                 if(player.ok_lastwep[slot] && player.ok_lastwep[slot] != WEP_Null)
127                 {
128                         Weapon newwep = player.ok_lastwep[slot];
129                         if(player.ok_lastwep[slot] == WEP_HMG)
130                                 newwep = WEP_MACHINEGUN;
131                         if(player.ok_lastwep[slot] == WEP_RPC)
132                                 newwep = WEP_VORTEX;
133                         thiswep.m_switchweapon = newwep;
134                         player.ok_lastwep[slot] = WEP_Null;
135                 }
136         }
137
138         if(PHYS_INPUT_BUTTON_ATCK2(player))
139         if( !forbidWeaponUse(player) || player.weapon_blocked // allow if weapon is blocked
140                 || (round_handler_IsActive() && !round_handler_IsRoundStarted()) )
141         if(time >= player.jump_interval)
142         {
143                 player.jump_interval = time + WEP_CVAR_PRI(blaster, refire) * W_WeaponRateFactor(player);
144                 makevectors(player.v_angle);
145
146                 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
147                 {
148                         .entity weaponentity = weaponentities[slot];
149
150                         if(player.(weaponentity).m_weapon == WEP_Null && slot != 0)
151                                 continue;
152
153                         Weapon oldwep = player.(weaponentity).m_weapon;
154                         player.(weaponentity).m_weapon = WEP_BLASTER;
155                         W_Blaster_Attack(
156                                 player,
157                                 weaponentity,
158                                 WEP_BLASTER.m_id | HITTYPE_SECONDARY,
159                                 WEP_CVAR_SEC(vaporizer, shotangle),
160                                 WEP_CVAR_SEC(vaporizer, damage),
161                                 WEP_CVAR_SEC(vaporizer, edgedamage),
162                                 WEP_CVAR_SEC(vaporizer, radius),
163                                 WEP_CVAR_SEC(vaporizer, force),
164                                 WEP_CVAR_SEC(vaporizer, speed),
165                                 WEP_CVAR_SEC(vaporizer, spread),
166                                 WEP_CVAR_SEC(vaporizer, delay),
167                                 WEP_CVAR_SEC(vaporizer, lifetime)
168                         );
169                         player.(weaponentity).m_weapon = oldwep;
170                 }
171         }
172
173         PHYS_INPUT_BUTTON_ATCK2(player) = false;
174 }
175
176 MUTATOR_HOOKFUNCTION(ok, PlayerSpawn)
177 {
178         entity player = M_ARGV(0, entity);
179
180         // if player changed their weapon while dead, don't switch to their death weapon
181         if(player.impulse)
182         {
183                 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
184                 {
185                         player.ok_lastwep[slot] = WEP_Null;
186                 }
187         }
188 }
189
190 void self_spawnfunc_weapon_hmg(entity this) { spawnfunc_weapon_hmg(this); }
191 void self_spawnfunc_weapon_rpc(entity this) { spawnfunc_weapon_rpc(this); }
192
193 MUTATOR_HOOKFUNCTION(ok, OnEntityPreSpawn)
194 {
195         entity ent = M_ARGV(0, entity);
196
197         if(autocvar_g_powerups)
198         if(autocvar_g_overkill_powerups_replace)
199         {
200                 if(ent.classname == "item_strength")
201                 {
202                         entity wep = new(weapon_hmg);
203                         setorigin(wep, ent.origin);
204                         setmodel(wep, MDL_OK_HMG);
205                         wep.ok_item = true;
206                         wep.noalign = ent.noalign;
207                         wep.cnt = ent.cnt;
208                         wep.team = ent.team;
209                         wep.respawntime = g_pickup_respawntime_superweapon;
210                         wep.pickup_anyway = true;
211                         wep.spawnfunc_checked = true;
212                         setthink(wep, self_spawnfunc_weapon_hmg);
213                         wep.nextthink = time + 0.1;
214                         return true;
215                 }
216                 else if(ent.classname == "item_invincible")
217                 {
218                         entity wep = new(weapon_rpc);
219                         setorigin(wep, ent.origin);
220                         setmodel(wep, MDL_OK_RPC);
221                         wep.ok_item = true;
222                         wep.noalign = ent.noalign;
223                         wep.cnt = ent.cnt;
224                         wep.team = ent.team;
225                         wep.respawntime = g_pickup_respawntime_superweapon;
226                         wep.pickup_anyway = true;
227                         wep.spawnfunc_checked = true;
228                         setthink(wep, self_spawnfunc_weapon_rpc);
229                         wep.nextthink = time + 0.1;
230                         return true;
231                 }
232         }
233 }
234
235 MUTATOR_HOOKFUNCTION(ok, FilterItem)
236 {
237         entity item = M_ARGV(0, entity);
238
239         if(item.ok_item)
240                 return false;
241
242         switch(item.itemdef)
243         {
244                 case ITEM_HealthMega: return autocvar_g_overkill_filter_healthmega;
245                 case ITEM_ArmorMedium: return autocvar_g_overkill_filter_armormedium;
246                 case ITEM_ArmorBig: return autocvar_g_overkill_filter_armorbig;
247                 case ITEM_ArmorMega: return autocvar_g_overkill_filter_armormega;
248         }
249
250         return true;
251 }
252
253 MUTATOR_HOOKFUNCTION(ok, SetStartItems, CBC_ORDER_LAST)
254 {
255         WepSet ok_start_items = (WEPSET(MACHINEGUN) | WEPSET(VORTEX) | WEPSET(SHOTGUN));
256
257         if(WEP_RPC.weaponstart > 0) { ok_start_items |= WEPSET(RPC); }
258         if(WEP_HMG.weaponstart > 0) { ok_start_items |= WEPSET(HMG); }
259
260         start_items |= IT_UNLIMITED_WEAPON_AMMO;
261         start_weapons = warmup_start_weapons = ok_start_items;
262 }
263
264 MUTATOR_HOOKFUNCTION(ok, SetWeaponArena)
265 {
266         // turn weapon arena off
267         M_ARGV(0, string) = "off";
268 }
269
270 MUTATOR_HOOKFUNCTION(ok, BuildMutatorsString)
271 {
272         M_ARGV(0, string) = strcat(M_ARGV(0, string), ":OK");
273 }
274
275 MUTATOR_HOOKFUNCTION(ok, BuildMutatorsPrettyString)
276 {
277         M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Overkill");
278 }
279
280 MUTATOR_HOOKFUNCTION(ok, SetModname)
281 {
282         M_ARGV(0, string) = "Overkill";
283         return true;
284 }
285
286 void ok_SetCvars()
287 {
288         // hack to force overkill playermodels
289         cvar_settemp("sv_defaultcharacter", "1");
290         cvar_settemp("sv_defaultplayermodel", "models/ok_player/okrobot1.dpm models/ok_player/okrobot2.dpm models/ok_player/okrobot3.dpm models/ok_player/okrobot4.dpm models/ok_player/okmale1.dpm models/ok_player/okmale2.dpm models/ok_player/okmale3.dpm models/ok_player/okmale4.dpm");
291         cvar_settemp("sv_defaultplayermodel_red", "models/ok_player/okrobot1.dpm models/ok_player/okrobot2.dpm models/ok_player/okrobot3.dpm models/ok_player/okrobot4.dpm");
292         cvar_settemp("sv_defaultplayermodel_blue", "models/ok_player/okmale1.dpm models/ok_player/okmale2.dpm models/ok_player/okmale3.dpm models/ok_player/okmale4.dpm");
293 }
294
295 void ok_Initialize()
296 {
297         ok_SetCvars();
298
299         precache_all_playermodels("models/ok_player/*.dpm");
300
301         WEP_RPC.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
302         WEP_HMG.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
303
304         WEP_SHOTGUN.mdl = "ok_shotgun";
305         WEP_MACHINEGUN.mdl = "ok_mg";
306         WEP_VORTEX.mdl = "ok_sniper";
307 }