OK weapons: Synced with master.
[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 string autocvar_g_overkill;
7
8 bool autocvar_g_overkill_powerups_replace;
9
10 bool autocvar_g_overkill_itemwaypoints = true;
11
12 .Weapon ok_lastwep[MAX_WEAPONSLOTS];
13
14 REGISTER_MUTATOR(ok, expr_evaluate(autocvar_g_overkill) && !cvar("g_instagib") && !g_nexball && cvar_string("g_mod_balance") == "Overkill")
15 {
16         MUTATOR_ONADD
17         {
18                 precache_all_playermodels("models/ok_player/*.dpm");
19
20                 if (autocvar_g_overkill_filter_healthmega)
21                 {
22                         ITEM_HealthMega.spawnflags |= ITEM_FLAG_MUTATORBLOCKED;
23                 }
24                 if (autocvar_g_overkill_filter_armormedium)
25                 {
26                         ITEM_ArmorMedium.spawnflags |= ITEM_FLAG_MUTATORBLOCKED;
27                 }
28                 if (autocvar_g_overkill_filter_armorbig)
29                 {
30                         ITEM_ArmorBig.spawnflags |= ITEM_FLAG_MUTATORBLOCKED;
31                 }
32                 if (autocvar_g_overkill_filter_armormega)
33                 {
34                         ITEM_ArmorMega.spawnflags |= ITEM_FLAG_MUTATORBLOCKED;
35                 }
36
37                 WEP_RPC.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
38                 WEP_HMG.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
39
40                 //WEP_SHOTGUN.mdl = "ok_shotgun";
41                 //WEP_MACHINEGUN.mdl = "ok_mg";
42                 //WEP_VORTEX.mdl = "ok_sniper";
43         }
44
45         MUTATOR_ONREMOVE
46         {
47                 ITEM_HealthMega.spawnflags &= ~ITEM_FLAG_MUTATORBLOCKED;
48                 ITEM_ArmorMedium.spawnflags &= ~ITEM_FLAG_MUTATORBLOCKED;
49                 ITEM_ArmorBig.spawnflags &= ~ITEM_FLAG_MUTATORBLOCKED;
50                 ITEM_ArmorMega.spawnflags &= ~ITEM_FLAG_MUTATORBLOCKED;
51
52                 WEP_RPC.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
53                 WEP_HMG.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
54         }
55 }
56
57 void W_Blaster_Attack(entity, .entity, float, float, float, float, float, float, float, float, float, float);
58
59 MUTATOR_HOOKFUNCTION(ok, Damage_Calculate, CBC_ORDER_LAST)
60 {
61         entity frag_attacker = M_ARGV(1, entity);
62         entity frag_target = M_ARGV(2, entity);
63         float frag_deathtype = M_ARGV(3, float);
64
65         if(IS_PLAYER(frag_attacker) && (IS_PLAYER(frag_target) || IS_VEHICLE(frag_target) || IS_TURRET(frag_target)))
66         if(DEATH_ISWEAPON(frag_deathtype, WEP_BLASTER))
67         {
68                 if(frag_attacker != frag_target)
69                 if(!STAT(FROZEN, frag_target))
70                 if(!IS_DEAD(frag_target))
71                 {
72                         Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_SECONDARY_NODAMAGE);
73                         M_ARGV(6, vector) = '0 0 0'; // force
74                 }
75
76                 M_ARGV(4, float) = 0; // damage
77         }
78 }
79
80 void ok_DropItem(entity this, entity targ)
81 {
82         entity e = spawn();
83         e.ok_item = true;
84         Item_InitializeLoot(e, "item_armor_small", this.origin + '0 0 32',
85                 '0 0 200' + normalize(targ.origin - this.origin) * 500, 5);
86 }
87
88 MUTATOR_HOOKFUNCTION(ok, PlayerDies)
89 {
90         entity frag_attacker = M_ARGV(1, entity);
91         entity frag_target = M_ARGV(2, entity);
92
93         entity targ = ((frag_attacker) ? frag_attacker : frag_target);
94
95         ok_DropItem(frag_target, targ);
96
97         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
98         {
99                 .entity weaponentity = weaponentities[slot];
100
101                 frag_target.ok_lastwep[slot] = frag_target.(weaponentity).m_switchweapon;
102         }
103 }
104
105 MUTATOR_HOOKFUNCTION(ok, MonsterDropItem)
106 {
107         entity mon = M_ARGV(0, entity);
108         entity olditem = M_ARGV(1, entity);
109         entity frag_attacker = M_ARGV(2, entity);
110
111         delete(olditem);
112
113         M_ARGV(1, entity) = NULL;
114
115         ok_DropItem(mon, frag_attacker);
116 }
117
118 MUTATOR_HOOKFUNCTION(ok, ForbidThrowCurrentWeapon)
119 {
120         return true;
121 }
122
123 MUTATOR_HOOKFUNCTION(ok, PlayerWeaponSelect)
124 {
125         entity player = M_ARGV(0, entity);
126
127         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
128         {
129                 .entity weaponentity = weaponentities[slot];
130                 entity thiswep = player.(weaponentity);
131
132                 if(player.ok_lastwep[slot] && player.ok_lastwep[slot] != WEP_Null)
133                 {
134                         Weapon newwep = player.ok_lastwep[slot];
135                         if(player.ok_lastwep[slot] == WEP_HMG)
136                                 newwep = WEP_MACHINEGUN;
137                         if(player.ok_lastwep[slot] == WEP_RPC)
138                                 newwep = WEP_VORTEX;
139                         thiswep.m_switchweapon = newwep;
140                         player.ok_lastwep[slot] = WEP_Null;
141                 }
142         }
143 }
144
145 void self_spawnfunc_weapon_hmg(entity this) { spawnfunc_weapon_hmg(this); }
146 void self_spawnfunc_weapon_rpc(entity this) { spawnfunc_weapon_rpc(this); }
147
148 MUTATOR_HOOKFUNCTION(ok, OnEntityPreSpawn)
149 {
150         entity ent = M_ARGV(0, entity);
151
152         if(autocvar_g_powerups)
153         if(autocvar_g_overkill_powerups_replace)
154         {
155                 if(ent.classname == "item_strength")
156                 {
157                         entity wep = new(weapon_hmg);
158                         setorigin(wep, ent.origin);
159                         setmodel(wep, MDL_OK_HMG);
160                         wep.ok_item = true;
161                         wep.noalign = ent.noalign;
162                         wep.cnt = ent.cnt;
163                         wep.team = ent.team;
164                         wep.respawntime = g_pickup_respawntime_superweapon;
165                         wep.pickup_anyway = true;
166                         wep.spawnfunc_checked = true;
167                         setthink(wep, self_spawnfunc_weapon_hmg);
168                         wep.nextthink = time + 0.1;
169                         return true;
170                 }
171                 else if(ent.classname == "item_shield")
172                 {
173                         entity wep = new(weapon_rpc);
174                         setorigin(wep, ent.origin);
175                         setmodel(wep, MDL_OK_RPC);
176                         wep.ok_item = true;
177                         wep.noalign = ent.noalign;
178                         wep.cnt = ent.cnt;
179                         wep.team = ent.team;
180                         wep.respawntime = g_pickup_respawntime_superweapon;
181                         wep.pickup_anyway = true;
182                         wep.spawnfunc_checked = true;
183                         setthink(wep, self_spawnfunc_weapon_rpc);
184                         wep.nextthink = time + 0.1;
185                         return true;
186                 }
187         }
188 }
189
190 bool ok_HandleItemWaypoints(entity e)
191 {
192         if(!autocvar_g_overkill_itemwaypoints)
193                 return false; // don't handle it
194
195         switch(e.itemdef)
196         {
197                 case ITEM_HealthMega: return true;
198                 case ITEM_ArmorMedium: return true;
199                 case ITEM_ArmorBig: return true;
200                 case ITEM_ArmorMega: return true;
201         }
202
203         return false;
204 }
205
206 MUTATOR_HOOKFUNCTION(ok, Item_RespawnCountdown)
207 {
208         entity item = M_ARGV(0, entity);
209         return ok_HandleItemWaypoints(item);
210 }
211
212 MUTATOR_HOOKFUNCTION(ok, Item_ScheduleRespawn)
213 {
214         entity item = M_ARGV(0, entity);
215         return ok_HandleItemWaypoints(item);
216 }
217
218 MUTATOR_HOOKFUNCTION(ok, FilterItem)
219 {
220         entity item = M_ARGV(0, entity);
221
222         if(item.ok_item)
223                 return false;
224
225         return true;
226 }
227
228 MUTATOR_HOOKFUNCTION(ok, SetStartItems, CBC_ORDER_LAST)
229 {
230         WepSet ok_start_items = (WEPSET(OVERKILL_MACHINEGUN) | WEPSET(OVERKILL_VORTEX) | WEPSET(OVERKILL_SHOTGUN));
231
232         if(WEP_RPC.weaponstart > 0) { ok_start_items |= WEPSET(RPC); }
233         if(WEP_HMG.weaponstart > 0) { ok_start_items |= WEPSET(HMG); }
234
235         start_items |= IT_UNLIMITED_WEAPON_AMMO;
236         start_weapons = warmup_start_weapons = ok_start_items;
237 }
238
239 MUTATOR_HOOKFUNCTION(ok, SetWeaponArena)
240 {
241         // turn weapon arena off
242         M_ARGV(0, string) = "off";
243 }
244
245 MUTATOR_HOOKFUNCTION(ok, BuildMutatorsString)
246 {
247         M_ARGV(0, string) = strcat(M_ARGV(0, string), ":OK");
248 }
249
250 MUTATOR_HOOKFUNCTION(ok, BuildMutatorsPrettyString)
251 {
252         M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Overkill");
253 }
254
255 MUTATOR_HOOKFUNCTION(ok, SetModname)
256 {
257         M_ARGV(0, string) = "Overkill";
258         return true;
259 }
260