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