1 void invasion_spawnpoint()
3 if not(g_invasion) { remove(self); return; }
5 self.classname = "invasion_spawnpoint";
8 float invasion_PickMonster(float supermonster_count)
10 if(autocvar_g_invasion_zombies_only)
16 RandomSelection_Init();
18 for(i = MON_FIRST; i <= MON_LAST; ++i)
20 mon = get_monsterinfo(i);
21 if((mon.spawnflags & MONSTER_TYPE_FLY) || (mon.spawnflags & MONSTER_TYPE_SWIM) || (mon.spawnflags & MON_FLAG_SUPERMONSTER && supermonster_count >= 1))
22 continue; // flying/swimming monsters not yet supported
24 RandomSelection_Add(world, i, "", 1, 1);
27 return RandomSelection_chosen_float;
30 entity invasion_PickSpawn()
34 RandomSelection_Init();
36 for(e = world;(e = find(e, classname, "invasion_spawnpoint")); )
37 RandomSelection_Add(e, 0, string_null, 1, 1);
39 return RandomSelection_chosen_ent;
42 void invasion_SpawnChosenMonster(float mon)
44 entity spawn_point, monster;
46 spawn_point = invasion_PickSpawn();
48 if(spawn_point == world)
50 dprint("Warning: couldn't find any invasion_spawnpoint spawnpoints, no monsters will spawn!\n");
54 monster = spawnmonster("", mon, spawn_point, spawn_point, spawn_point.origin, FALSE, 2);
56 if(roundcnt >= maxrounds)
57 monster.spawnflags |= MONSTERFLAG_MINIBOSS;
60 void invasion_SpawnMonsters(float supermonster_count)
62 float chosen_monster = invasion_PickMonster(supermonster_count);
64 invasion_SpawnChosenMonster(chosen_monster);
67 float Invasion_CheckWinner()
70 if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
72 FOR_EACH_MONSTER(head)
75 if(roundcnt >= maxrounds)
81 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
82 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
83 round_handler_Init(5, autocvar_g_invasion_warmup, autocvar_g_invasion_round_timelimit);
88 if(roundcnt >= maxrounds)
93 invasion_SpawnMonsters(0);
98 float total_alive_monsters = 0, supermonster_count = 0;
100 FOR_EACH_MONSTER(head) if(head.health > 0)
102 if((get_monsterinfo(head.monsterid)).spawnflags & MON_FLAG_SUPERMONSTER)
103 ++supermonster_count;
104 ++total_alive_monsters;
107 if((total_alive_monsters + numkilled) < maxspawned && maxcurrent < 10) // 10 at a time should be plenty
109 if(time >= last_check)
111 invasion_SpawnMonsters(supermonster_count);
112 last_check = time + 2;
119 if(numspawned < 1 || numkilled < maxspawned)
120 return 0; // nothing has spawned yet, or there are still alive monsters
122 if(roundcnt >= maxrounds)
128 entity winner = world;
129 float winning_score = 0;
131 FOR_EACH_PLAYER(head)
133 float cs = PlayerScore_Add(head, SP_KILLS, 0);
134 if(cs > winning_score)
143 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_PLAYER_WIN, winner.netname);
144 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_PLAYER_WIN, winner.netname);
147 round_handler_Init(5, autocvar_g_invasion_warmup, autocvar_g_invasion_round_timelimit);
152 float Invasion_CheckPlayers()
157 void Invasion_RoundStart()
160 float numplayers = 0;
163 e.player_blocked = 0;
174 maxspawned = rint(autocvar_g_invasion_monster_count * (roundcnt * 0.5));
176 maxspawned = autocvar_g_invasion_monster_count;
178 monster_skill += 0.1 * numplayers;
181 MUTATOR_HOOKFUNCTION(invasion_MonsterDies)
183 if not(self.monster_respawned)
188 if(IS_PLAYER(frag_attacker))
189 PlayerScore_Add(frag_attacker, SP_KILLS, +1);
195 MUTATOR_HOOKFUNCTION(invasion_MonsterSpawn)
197 if not(self.spawnflags & MONSTERFLAG_SPAWNED)
199 monster_remove(self);
203 if(roundcnt < maxrounds && self.spawnflags & MONSTERFLAG_MINIBOSS)
204 self.spawnflags &= ~MONSTERFLAG_MINIBOSS;
206 if not(self.monster_respawned)
212 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_BOTCLIP | DPCONTENTS_MONSTERCLIP;
217 MUTATOR_HOOKFUNCTION(invasion_PlayerThink)
219 monsters_total = maxspawned; // TODO: make sure numspawned never exceeds maxspawned
220 monsters_killed = numkilled;
225 MUTATOR_HOOKFUNCTION(invasion_PlayerSpawn)
227 self.bot_attack = FALSE;
231 MUTATOR_HOOKFUNCTION(invasion_PlayerDamage)
233 if(IS_PLAYER(frag_attacker) && IS_PLAYER(frag_target) && frag_attacker != frag_target)
236 frag_force = '0 0 0';
242 MUTATOR_HOOKFUNCTION(invasion_PlayerCommand)
244 if(MUTATOR_RETURNVALUE) // command was already handled?
247 if(cmd_name == "debuginvasion")
249 sprint(self, strcat("maxspawned = ", ftos(maxspawned), "\n"));
250 sprint(self, strcat("numspawned = ", ftos(numspawned), "\n"));
251 sprint(self, strcat("numkilled = ", ftos(numkilled), "\n"));
252 sprint(self, strcat("roundcnt = ", ftos(roundcnt), "\n"));
253 sprint(self, strcat("monsters_total = ", ftos(monsters_total), "\n"));
254 sprint(self, strcat("monsters_killed = ", ftos(monsters_killed), "\n"));
255 sprint(self, strcat("monster_skill = ", ftos(monster_skill), "\n"));
263 MUTATOR_HOOKFUNCTION(invasion_SetStartItems)
266 start_armorvalue = 200;
271 void invasion_ScoreRules()
273 ScoreRules_basics(0, 0, 0, FALSE);
274 ScoreInfo_SetLabel_PlayerScore(SP_KILLS, "frags", SFL_SORT_PRIO_PRIMARY);
275 ScoreRules_basics_end();
278 void invasion_Initialize()
280 independent_players = 1; // to disable extra useless scores
282 invasion_ScoreRules();
284 independent_players = 0;
286 round_handler_Spawn(Invasion_CheckPlayers, Invasion_CheckWinner, Invasion_RoundStart);
287 round_handler_Init(5, autocvar_g_invasion_warmup, autocvar_g_invasion_round_timelimit);
289 allowed_to_spawn = TRUE;
296 MUTATOR_DEFINITION(gamemode_invasion)
298 MUTATOR_HOOK(MonsterDies, invasion_MonsterDies, CBC_ORDER_ANY);
299 MUTATOR_HOOK(MonsterSpawn, invasion_MonsterSpawn, CBC_ORDER_ANY);
300 MUTATOR_HOOK(PlayerPreThink, invasion_PlayerThink, CBC_ORDER_ANY);
301 MUTATOR_HOOK(PlayerSpawn, invasion_PlayerSpawn, CBC_ORDER_ANY);
302 MUTATOR_HOOK(PlayerDamage_Calculate, invasion_PlayerDamage, CBC_ORDER_ANY);
303 MUTATOR_HOOK(SV_ParseClientCommand, invasion_PlayerCommand, CBC_ORDER_ANY);
304 MUTATOR_HOOK(SetStartItems, invasion_SetStartItems, CBC_ORDER_ANY);
310 if(time > 1) // game loads at time 1
311 error("This is a game type and it cannot be added at runtime.");
312 invasion_Initialize();
314 cvar_settemp("g_monsters", "1");
316 for(i = MON_FIRST; i <= MON_LAST; ++i)
317 get_monsterinfo(i).spawnflags &= ~MON_FLAG_MUTATORBLOCKED;
320 MUTATOR_ONROLLBACK_OR_REMOVE
322 // we actually cannot roll back invasion_Initialize here
323 // BUT: we don't need to! If this gets called, adding always
329 print("This is a game type and it cannot be removed at runtime.");