]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/mutator_minstagib.qc
980f2d53b6a0c614536a1d31b52c698d405c0d7e
[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 = g_minstagib_invis_alpha;
150                         self.exteriorweaponentity.alpha = 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_PlayStrengthSound)
203 {
204         // You shall not play!
205         return TRUE;
206 }
207
208 MUTATOR_HOOKFUNCTION(minstagib_PlayerDamage)
209 {
210         if(autocvar_g_friendlyfire == 0 && !IsDifferentTeam(frag_target, frag_attacker) && IS_PLAYER(frag_target))
211                 frag_damage = 0;
212                 
213         if(IS_PLAYER(frag_target))
214         {
215                 if ((frag_deathtype == DEATH_FALL)  ||
216                         (frag_deathtype == DEATH_DROWN) ||
217                         (frag_deathtype == DEATH_SLIME) ||
218                         (frag_deathtype == DEATH_LAVA))
219                 {
220                         frag_damage = 0;
221                 }
222                 
223                 if (frag_target.armorvalue && (frag_deathtype == WEP_MINSTANEX) && frag_damage)
224                 {
225                         frag_target.armorvalue -= 1;
226                         Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_MINSTA_LIVES_REMAINING, frag_target.armorvalue);
227                         frag_damage = 0;
228                         frag_target.hitsound += 1;
229                         frag_attacker.hitsound += 1; // TODO change this to a future specific hitsound for armor hit
230                 }
231                 if (DEATH_ISWEAPON(frag_deathtype, WEP_LASER))
232                 {
233                         frag_damage = 0;
234                         frag_mirrordamage = 0;
235                         if (frag_target != frag_attacker)
236                         {
237                                 if ((frag_target.health >= 1) && IS_PLAYER(frag_target))
238                                         Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_MINSTA_SECONDARY);
239                                 frag_force = '0 0 0';
240                                 // keep mirrorfrag_force
241                                 frag_attacker = frag_target;
242                         }
243                 }
244         }
245         
246         if(frag_mirrordamage > 0)
247         {
248                 // just lose extra LIVES, don't kill the player for mirror damage
249                 if(frag_attacker.armorvalue > 0)
250                 {
251                         frag_attacker.armorvalue = frag_attacker.armorvalue - 1;
252                         Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_MINSTA_LIVES_REMAINING, frag_attacker.armorvalue);
253                         frag_attacker.hitsound += 1;
254                 }
255                 frag_mirrordamage = 0;
256         }
257         
258         if(frag_target.items & IT_STRENGTH)
259                 yoda = 1;
260                 
261         return FALSE;
262 }
263
264 MUTATOR_HOOKFUNCTION(minstagib_SetStartItems)
265 {
266         start_ammo_cells = cvar("g_minstagib_ammo_start");
267         
268         g_pinata = 0; // incompatible
269         g_weapon_stay = 0; // incompatible
270         g_bloodloss = 0; // incompatible
271         start_health = 100;
272         start_armorvalue = 0;
273         WEPSET_COPY_AW(start_weapons, WEP_MINSTANEX);
274         g_minstagib_invis_alpha = cvar("g_minstagib_invis_alpha");
275         start_items |= IT_UNLIMITED_SUPERWEAPONS;
276
277         if (g_minstagib_invis_alpha <= 0)
278                 g_minstagib_invis_alpha = -1;
279                 
280         return FALSE;
281 }
282
283 MUTATOR_HOOKFUNCTION(minstagib_FilterItem)
284 {
285         if(self.classname == "item_cells")
286                 return TRUE; // no normal cells?
287                 
288         if(self.weapon == WEP_MINSTANEX && self.classname == "droppedweapon")
289         {
290                 self.ammo_cells = autocvar_g_minstagib_ammo_drop;
291                 return FALSE;
292         }
293         
294         if(self.weapon == WEP_ROCKET_LAUNCHER || self.weapon == WEP_NEX)
295         {
296                 entity e = spawn();
297                 setorigin(e, self.origin);
298                 entity oldself;
299                 oldself = self;
300                 self = e;
301                 spawnfunc_item_minst_cells();
302                 self = oldself;
303                 return TRUE;
304         }
305                 
306         if(self.flags & FL_POWERUP)
307                 return FALSE;
308                 
309         if(self.ammo_cells > autocvar_g_minstagib_ammo_drop && self.classname != "item_minst_cells")
310                 self.ammo_cells = autocvar_g_minstagib_ammo_drop;
311                 
312         if(self.ammo_cells && !self.weapon)
313                 return FALSE;
314                 
315         return TRUE;
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 (clienttype(giveplayer) == CLIENTTYPE_REAL)
335                 {
336                         if(giveplayer.health <= 5)
337                                 AnnounceTo(giveplayer, "lastsecond");
338                         else if(giveplayer.health < 50)
339                                 AnnounceTo(giveplayer, "narrowly");
340                 }
341
342                 if(giveplayer.health < 100)
343                         giveplayer.health = 100;
344                         
345                 player_pickedup = TRUE;
346         }
347         
348         if(giveitem.max_health)
349         {
350                 giveplayer.armorvalue = bound(giveplayer.armorvalue, 999, giveplayer.armorvalue + autocvar_g_minstagib_extralives);
351                 sprint(giveplayer, "^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(PlayStrengthSound, minstagib_PlayStrengthSound, CBC_ORDER_ANY);
400         MUTATOR_HOOK(MakePlayerObserver, minstagib_MakePlayerObserver, CBC_ORDER_ANY);
401         MUTATOR_HOOK(SetStartItems, minstagib_SetStartItems, CBC_ORDER_ANY);
402         MUTATOR_HOOK(Item_GiveTo, minstagib_GiveItem, CBC_ORDER_ANY);
403         MUTATOR_HOOK(FilterItem, minstagib_FilterItem, 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 }