]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/mutator_zombie_apocalypse.qc
Merge branch 'master' into mario/monsters
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator_zombie_apocalypse.qc
1 // Zombie Apocalypse mutator - small side project
2 // Spawns a defined number of zombies at the start of a match
3
4 float za_numspawns, totalzombies, roundcnt, numzoms;
5 entity PickZombieSpawn()
6 {
7         entity sp;
8         
9         RandomSelection_Init();
10         
11         if(teamplay)
12         {
13                 for(sp = world; (sp = find(sp, classname, "info_player_team1")); )
14                 {
15                         RandomSelection_Add(sp, 0, string_null, 1, 1);
16                 }
17         }
18         else
19         {
20                 for(sp = world; (sp = find(sp, classname, "info_player_deathmatch")); )
21                 {
22                         RandomSelection_Add(sp, 0, string_null, 1, 1);
23                 }
24         }
25         
26         return RandomSelection_chosen_ent;
27 }
28
29 void zombie_spawn_somewhere ()
30 {
31         if(gameover) { return; }
32     
33     entity mon, sp;
34         
35         if(MoveToRandomMapLocation(self, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY, 10, 1024, 256))
36         {
37                 mon = spawnmonster("zombie", self, self, self.origin, TRUE, 2);
38                 tracebox(mon.origin, mon.mins, mon.maxs, mon.origin, MOVE_NOMONSTERS, mon);
39                 mon.spawnflags |= MONSTERFLAG_NORESPAWN;
40
41                 if(trace_startsolid)
42                 {
43                         sp = PickZombieSpawn();
44                         if(sp)
45                                 setorigin(mon, sp.origin);
46                 }
47                         
48         za_numspawns += 1;
49         }
50         else
51                 zombie_spawn_somewhere();
52 }
53
54 void() spawn_zombies;
55 void za_roundwon()
56 {
57         entity head;
58         FOR_EACH_PLAYER(head)
59         {
60                 Send_CSQC_Centerprint_Generic(head, CPID_MINSTA_FINDAMMO, "All the zombies have been exterminated! Prepare for round 2!", 0, 0);
61         }
62         
63         roundcnt += 1;
64         
65         numzoms = autocvar_g_za_monster_count * roundcnt;
66         
67         monsters_total = numzoms;
68         totalzombies = numzoms;
69         
70         self.think = spawn_zombies;
71         self.nextthink = time + 10;
72 }
73
74 void spawn_zombies ()
75 {
76         self.nextthink = time + 1;
77         
78         if(totalzombies < 1)
79         {
80                 self.think = za_roundwon;
81                 self.nextthink = time;
82                 return;
83         }
84         
85         if(gameover || numzoms <= 0)
86                 return;
87                 
88     entity e;
89     
90     print("Them zombies be spawnin'!\n");
91
92         while(numzoms > 0)
93         {
94         e = spawn();
95                 e.think = zombie_spawn_somewhere;
96         e.nextthink = time;
97
98                 numzoms -= 1;
99         }
100 }
101
102 void za_init ()
103 {
104     entity e;
105         
106         roundcnt = 1;
107         
108     numzoms = autocvar_g_za_monster_count * roundcnt;
109         
110         monsters_total = numzoms;
111         totalzombies = numzoms;
112         
113     e = spawn();
114         e.think = spawn_zombies;
115         e.nextthink = time + 3;
116 }
117
118 MUTATOR_HOOKFUNCTION(za_ZombieDies)
119 {
120         if(frag_attacker.classname == "player")
121                 PlayerScore_Add(frag_attacker, SP_SCORE, 1);
122         
123         totalzombies -= 1;
124         monsters_killed += 1;
125         return FALSE;
126 }
127
128 MUTATOR_HOOKFUNCTION(za_BuildMutatorsString)
129 {
130         ret_string = strcat(ret_string, ":Zombies");
131         return 0;
132 }
133
134 MUTATOR_HOOKFUNCTION(za_BuildMutatorsPrettyString)
135 {
136         ret_string = strcat(ret_string, ", Zombies");
137         return 0;
138 }
139
140 MUTATOR_DEFINITION(mutator_zombie_apocalypse)
141 {
142         MUTATOR_HOOK(MonsterDies, za_ZombieDies, CBC_ORDER_ANY);
143         MUTATOR_HOOK(BuildMutatorsString, za_BuildMutatorsString, CBC_ORDER_ANY);
144         MUTATOR_HOOK(BuildMutatorsPrettyString, za_BuildMutatorsPrettyString, CBC_ORDER_ANY);
145     
146     MUTATOR_ONADD
147     {
148         za_init();
149     }
150
151         return 0;
152 }