]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/mutator_minstagib.qc
Move waypoint check to mutator (will add it back when we have a proper invisibility...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator_minstagib.qc
1 void spawnfunc_item_minst_cells (void) 
2 {
3         if not(g_minstagib) { remove(self); return; }
4         if not(self.ammo_cells)
5                 self.ammo_cells = autocvar_g_minstagib_ammo_drop;
6                 
7         StartItem ("models/items/a_cells.md3",
8                            "misc/itempickup.wav", 45, 0,
9                            "MinstaNex Ammo", IT_CELLS, 0, 0, generic_pickupevalfunc, 100);
10 }
11
12 void minstagib_health_mega()
13 {
14         self.max_health = 1;
15         StartItem ("models/items/g_h100.md3",
16                            "misc/megahealth.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
17                            "Extralife", IT_NAILS, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
18 }
19
20 .float minstagib_nextthink;
21 .float minstagib_needammo;
22 void minstagib_stop_countdown(entity e)
23 {
24         if (!e.minstagib_needammo)
25                 return;
26         Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER_CPID, CPID_MINSTA_FINDAMMO);
27         e.minstagib_needammo = FALSE;
28 }
29 void minstagib_ammocheck(void)
30 {
31         if (time < self.minstagib_nextthink)
32                 return;
33
34         if (self.deadflag || gameover)
35                 minstagib_stop_countdown(self);
36         else if (self.ammo_cells > 0 || (self.items & IT_UNLIMITED_WEAPON_AMMO))
37                 minstagib_stop_countdown(self);
38         else
39         {
40                 self.minstagib_needammo = TRUE;
41                 if (self.health == 5)
42                 {
43                         Damage(self, self, self, 5, DEATH_NOAMMO, self.origin, '0 0 0');
44                         AnnounceTo(self, "terminated");
45                 }
46                 else if (self.health == 10)
47                 {
48                         Damage(self, self, self, 5, DEATH_NOAMMO, self.origin, '0 0 0');
49                         AnnounceTo(self, "1");
50                 }
51                 else if (self.health == 20)
52                 {
53                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
54                         AnnounceTo(self, "2");
55                 }
56                 else if (self.health == 30)
57                 {
58                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
59                         AnnounceTo(self, "3");
60                 }
61                 else if (self.health == 40)
62                 {
63                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
64                         AnnounceTo(self, "4");
65                 }
66                 else if (self.health == 50)
67                 {
68                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
69                         AnnounceTo(self, "5");
70                 }
71                 else if (self.health == 60)
72                 {
73                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
74                         AnnounceTo(self, "6");
75                 }
76                 else if (self.health == 70)
77                 {
78                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
79                         AnnounceTo(self, "7");
80                 }
81                 else if (self.health == 80)
82                 {
83                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
84                         AnnounceTo(self, "8");
85                 }
86                 else if (self.health == 90)
87                 {
88                         Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_MINSTA_FINDAMMO);
89                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
90                         AnnounceTo(self, "9");
91                 }
92                 else if (self.health == 100)
93                 {
94                         Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_MINSTA_FINDAMMO_FIRST);
95                         Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
96                         if not(self.flags & FL_GODMODE)
97                                 AnnounceTo(self, "10");
98                 }
99         }
100         self.minstagib_nextthink = time + 1;
101 }
102
103 MUTATOR_HOOKFUNCTION(minstagib_BotShouldAttack)
104 {
105         if(checkentity.items & IT_STRENGTH)
106                 return TRUE;
107                 
108         return FALSE;
109 }
110
111 MUTATOR_HOOKFUNCTION(minstagib_MakePlayerObserver)
112 {
113         minstagib_stop_countdown(self);
114         return FALSE;
115 }
116
117 MUTATOR_HOOKFUNCTION(minstagib_PlayerSpawn)
118 {
119         self.effects |= EF_FULLBRIGHT;
120         return FALSE;
121 }
122
123 MUTATOR_HOOKFUNCTION(minstagib_PlayerPreThink)
124 {
125         minstagib_ammocheck();
126         return FALSE;
127 }
128
129 MUTATOR_HOOKFUNCTION(minstagib_PlayerPowerups)
130 {
131         if not(self.effects & EF_FULLBRIGHT)
132                 self.effects |= EF_FULLBRIGHT;
133
134         if (self.items & IT_STRENGTH)
135         {
136                 play_countdown(self.strength_finished, "misc/poweroff.wav");
137                 if (time > self.strength_finished)
138                 {
139                         self.alpha = default_player_alpha;
140                         self.exteriorweaponentity.alpha = default_weapon_alpha;
141                         self.items &~= IT_STRENGTH;
142                         Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERDOWN_INVISIBILITY);
143                 }
144         }
145         else
146         {
147                 if (time < self.strength_finished)
148                 {
149                         self.alpha = autocvar_g_minstagib_invis_alpha;
150                         self.exteriorweaponentity.alpha = autocvar_g_minstagib_invis_alpha;
151                         self.items |= IT_STRENGTH;
152                         Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_INVISIBILITY, self.netname);
153                         Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERUP_INVISIBILITY);
154                 }
155         }
156
157         if (self.items & IT_INVINCIBLE)
158         {
159                 play_countdown(self.invincible_finished, "misc/poweroff.wav");
160                 if (time > self.invincible_finished)
161                 {
162                         self.items &~= IT_INVINCIBLE;
163                         Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERDOWN_SPEED);
164                 }
165         }
166         else
167         {
168                 if (time < self.invincible_finished)
169                 {
170                         self.items |= IT_INVINCIBLE;
171                         Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_SPEED, self.netname);
172                         Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERUP_SPEED);
173                 }
174         }
175         return FALSE;
176 }
177
178 MUTATOR_HOOKFUNCTION(minstagib_PlayerPhysics)
179 {
180         if(self.items & IT_INVINCIBLE)
181                 self.stat_sv_maxspeed = self.stat_sv_maxspeed * autocvar_g_minstagib_speed_highspeed;
182                 
183         return FALSE;
184 }
185
186 MUTATOR_HOOKFUNCTION(minstagib_SplitHealthArmor)
187 {
188         damage_save = 0;
189         //damage_take = frag_damage; // frag_damage isn't even set here?!
190         
191         return FALSE;
192 }
193
194 MUTATOR_HOOKFUNCTION(minstagib_ForbidThrowing)
195 {
196         if (self.health < 1)
197                 return FALSE;
198                 
199         return TRUE;
200 }
201
202 MUTATOR_HOOKFUNCTION(minstagib_PlayerDamage)
203 {
204         if(autocvar_g_friendlyfire == 0 && !IsDifferentTeam(frag_target, frag_attacker) && IS_PLAYER(frag_target))
205                 frag_damage = 0;
206                 
207         if(IS_PLAYER(frag_target))
208         {
209                 if ((frag_deathtype == DEATH_FALL)  ||
210                         (frag_deathtype == DEATH_DROWN) ||
211                         (frag_deathtype == DEATH_SLIME) ||
212                         (frag_deathtype == DEATH_LAVA))
213                 {
214                         frag_damage = 0;
215                 }
216                 
217                 if (frag_target.armorvalue && (frag_deathtype == WEP_MINSTANEX) && frag_damage)
218                 {
219                         frag_target.armorvalue -= 1;
220                         Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_MINSTA_LIVES_REMAINING, frag_target.armorvalue);
221                         frag_damage = 0;
222                         frag_target.hitsound += 1;
223                         frag_attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
224                 }
225                 if (DEATH_ISWEAPON(frag_deathtype, WEP_LASER))
226                 {
227                         frag_damage = 0;
228                         frag_mirrordamage = 0;
229                         if (frag_target != frag_attacker)
230                         {
231                                 if ((frag_target.health >= 1) && IS_PLAYER(frag_target))
232                                         Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_MINSTA_SECONDARY);
233                                 frag_force = '0 0 0';
234                                 // keep mirrorfrag_force
235                                 frag_attacker = frag_target;
236                         }
237                 }
238         }
239         
240         if(frag_mirrordamage > 0)
241         {
242                 // just lose extra LIVES, don't kill the player for mirror damage
243                 if(frag_attacker.armorvalue > 0)
244                 {
245                         frag_attacker.armorvalue = frag_attacker.armorvalue - 1;
246                         Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_MINSTA_LIVES_REMAINING, frag_attacker.armorvalue);
247                         frag_attacker.hitsound += 1;
248                 }
249                 frag_mirrordamage = 0;
250         }
251         
252         if(frag_target.items & IT_STRENGTH)
253                 yoda = 1;
254                 
255         return FALSE;
256 }
257
258 MUTATOR_HOOKFUNCTION(minstagib_SetStartItems)
259 {
260         start_ammo_cells = cvar("g_minstagib_ammo_start");
261         
262         start_health = 100;
263         start_armorvalue = 0;
264         WEPSET_COPY_AW(start_weapons, WEP_MINSTANEX);
265         start_items |= IT_UNLIMITED_SUPERWEAPONS;
266                 
267         return FALSE;
268 }
269
270 MUTATOR_HOOKFUNCTION(minstagib_FilterItem)
271 {
272         if(self.classname == "item_cells")
273                 return TRUE; // no normal cells?
274                 
275         if(self.weapon == WEP_MINSTANEX && self.classname == "droppedweapon")
276         {
277                 self.ammo_cells = autocvar_g_minstagib_ammo_drop;
278                 return FALSE;
279         }
280         
281         if(self.weapon == WEP_ROCKET_LAUNCHER || self.weapon == WEP_NEX)
282         {
283                 entity e = spawn();
284                 setorigin(e, self.origin);
285                 entity oldself;
286                 oldself = self;
287                 self = e;
288                 spawnfunc_item_minst_cells();
289                 self = oldself;
290                 return TRUE;
291         }
292                 
293         if(self.flags & FL_POWERUP)
294                 return FALSE;
295                 
296         if(self.ammo_cells > autocvar_g_minstagib_ammo_drop && self.classname != "item_minst_cells")
297                 self.ammo_cells = autocvar_g_minstagib_ammo_drop;
298                 
299         if(self.ammo_cells && !self.weapon)
300                 return FALSE;
301                 
302         return TRUE;
303 }
304
305 MUTATOR_HOOKFUNCTION(minstagib_CustomizeWaypoint)
306 {
307         entity e = WaypointSprite_getviewentity(other);
308         
309         // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
310         // but only apply this to real players, not to spectators
311         if((self.owner.flags & FL_CLIENT) && (self.owner.items & IT_STRENGTH) && (e == other))
312         if(IsDifferentTeam(self.owner, e))
313                 return TRUE;
314         
315         return FALSE;
316 }
317
318 MUTATOR_HOOKFUNCTION(minstagib_ItemCountdown)
319 {
320         switch(self.items)
321         {
322                 case IT_STRENGTH:   item_name = "item-invis"; item_color = '0 0 1'; break;
323                 case IT_NAILS:      item_name = "item-extralife"; item_color = '1 0 0'; break;
324                 case IT_INVINCIBLE: item_name = "item-speed"; item_color = '1 0 1'; break;
325         }
326         return FALSE;
327 }
328
329 MUTATOR_HOOKFUNCTION(minstagib_GiveItem)
330 {
331         if(giveitem.ammo_cells)
332         {
333                 // play some cool sounds ;)
334                 if (IS_CLIENT(other))
335                 {
336                         if(other.health <= 5)
337                                 AnnounceTo(other, "lastsecond");
338                         else if(other.health < 50)
339                                 AnnounceTo(other, "narrowly");
340                 }
341
342                 if(other.health < 100)
343                         other.health = 100;
344                         
345                 player_pickedup = TRUE;
346         }
347         
348         if(giveitem.max_health)
349         {
350                 other.armorvalue = bound(other.armorvalue, 999, other.armorvalue + autocvar_g_minstagib_extralives);
351                 sprint(other, "^3You picked up some extra lives\n");
352                 player_pickedup = TRUE;
353         }
354                 
355         return TRUE;
356 }
357
358 MUTATOR_HOOKFUNCTION(minstagib_OnEntityPreSpawn)
359 {
360         if not(autocvar_g_powerups) { return FALSE; }
361         if not(self.classname == "item_strength" || self.classname == "item_invincible" || self.classname == "item_health_mega")
362                 return FALSE;
363         
364         entity e = spawn();
365         
366         if(random() < 0.3)
367                 e.think = spawnfunc_item_strength;
368         else if(random() < 0.6)
369                 e.think = minstagib_health_mega;
370         else
371                 e.think = spawnfunc_item_invincible;
372                 
373         e.nextthink = time + 0.1;
374         e.spawnflags = self.spawnflags;
375         e.noalign = self.noalign;
376         setorigin(e, self.origin);
377         
378         return TRUE;
379 }
380
381 MUTATOR_HOOKFUNCTION(minstagib_BuildMutatorsString)
382 {
383         ret_string = strcat(ret_string, ":MinstaGib");
384         return FALSE;
385 }
386
387 MUTATOR_HOOKFUNCTION(minstagib_BuildMutatorsPrettyString)
388 {
389         ret_string = strcat(ret_string, ", MinstaGib");
390         return FALSE;
391 }
392
393 MUTATOR_DEFINITION(mutator_minstagib)
394 {
395         MUTATOR_HOOK(BotShouldAttack, minstagib_BotShouldAttack, CBC_ORDER_ANY);
396         MUTATOR_HOOK(PlayerPhysics, minstagib_PlayerPhysics, CBC_ORDER_ANY);
397         MUTATOR_HOOK(PlayerSpawn, minstagib_PlayerSpawn, CBC_ORDER_ANY);
398         MUTATOR_HOOK(PlayerDamage_Calculate, minstagib_PlayerDamage, CBC_ORDER_ANY);
399         MUTATOR_HOOK(MakePlayerObserver, minstagib_MakePlayerObserver, CBC_ORDER_ANY);
400         MUTATOR_HOOK(SetStartItems, minstagib_SetStartItems, CBC_ORDER_ANY);
401         MUTATOR_HOOK(Item_GiveTo, minstagib_GiveItem, CBC_ORDER_ANY);
402         MUTATOR_HOOK(FilterItem, minstagib_FilterItem, CBC_ORDER_ANY);
403         MUTATOR_HOOK(CustomizeWaypoint, minstagib_CustomizeWaypoint, CBC_ORDER_ANY);
404         MUTATOR_HOOK(Item_RespawnCountdown, minstagib_ItemCountdown, CBC_ORDER_ANY);
405         MUTATOR_HOOK(PlayerDamage_SplitHealthArmor, minstagib_SplitHealthArmor, CBC_ORDER_ANY);
406         MUTATOR_HOOK(PlayerPowerups, minstagib_PlayerPowerups, CBC_ORDER_ANY);
407         MUTATOR_HOOK(ForbidThrowCurrentWeapon, minstagib_ForbidThrowing, CBC_ORDER_ANY);
408         MUTATOR_HOOK(PlayerPreThink, minstagib_PlayerPreThink, CBC_ORDER_ANY);
409         MUTATOR_HOOK(OnEntityPreSpawn, minstagib_OnEntityPreSpawn, CBC_ORDER_ANY);
410         MUTATOR_HOOK(BuildMutatorsString, minstagib_BuildMutatorsString, CBC_ORDER_ANY);
411         MUTATOR_HOOK(BuildMutatorsPrettyString, minstagib_BuildMutatorsPrettyString, CBC_ORDER_ANY);
412
413         return FALSE;
414 }