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