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