1 void invasion_spawnpoint()
3 if not(g_invasion) { remove(self); return; }
5 self.classname = "invasion_spawnpoint";
8 float invasion_PickMonster()
10 if(autocvar_g_invasion_zombies_only)
11 return MONSTER_ZOMBIE;
15 RandomSelection_Init();
17 for(i = MONSTER_FIRST + 1; i < MONSTER_LAST; ++i)
19 if(i == MONSTER_STINGRAY || i == MONSTER_WYVERN)
20 continue; // flying/swimming monsters not yet supported
22 RandomSelection_Add(world, i, "", 1, 1);
25 return RandomSelection_chosen_float;
28 entity invasion_PickSpawn()
32 RandomSelection_Init();
34 for(e = world;(e = find(e, classname, "invasion_spawnpoint")); )
35 RandomSelection_Add(e, 0, string_null, 1, 1);
37 return RandomSelection_chosen_ent;
40 void invasion_SpawnChosenMonster(float mon)
42 entity spawn_point, monster;
44 spawn_point = invasion_PickSpawn();
46 if(spawn_point == world)
48 dprint("Warning: couldn't find any invasion_spawnpoint spawnpoints, no monsters will spawn!\n");
52 monster = spawnmonster("", mon, spawn_point, spawn_point, spawn_point.origin, FALSE, 2);
55 void invasion_SpawnMonsters()
57 float chosen_monster = invasion_PickMonster();
59 invasion_SpawnChosenMonster(chosen_monster);
62 float Invasion_CheckWinner()
65 if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
67 FOR_EACH_MONSTER(head)
69 WaypointSprite_Kill(head.sprite);
70 if(head.weaponentity) remove(head.weaponentity);
74 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
75 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
76 round_handler_Init(5, autocvar_g_invasion_warmup, autocvar_g_invasion_round_timelimit);
80 float total_alive_monsters = 0;
82 FOR_EACH_MONSTER(head) if(head.health > 0)
83 ++total_alive_monsters;
85 if((total_alive_monsters + numkilled) < maxspawned)
87 if(time >= last_check)
89 invasion_SpawnMonsters();
90 last_check = time + 2;
96 if(numspawned < 1 || numkilled < maxspawned)
97 return 0; // nothing has spawned yet, or there are still alive monsters
99 if(roundcnt >= maxrounds)
105 entity winner = world;
106 float winning_score = 0;
108 FOR_EACH_PLAYER(head)
110 float cs = PlayerScore_Add(head, SP_INVASION_KILLS, 0);
111 if(cs > winning_score)
120 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_PLAYER_WIN, winner.netname);
121 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_PLAYER_WIN, winner.netname);
124 round_handler_Init(5, autocvar_g_invasion_warmup, autocvar_g_invasion_round_timelimit);
129 float Invasion_CheckPlayers()
134 void Invasion_RoundStart()
137 float numplayers = 0;
140 e.player_blocked = 0;
150 maxspawned = rint(autocvar_g_invasion_monster_count * (roundcnt * 0.5));
152 maxspawned = autocvar_g_invasion_monster_count;
154 monster_skill += 0.01 * numplayers;
157 MUTATOR_HOOKFUNCTION(invasion_MonsterDies)
161 if(IS_PLAYER(frag_attacker))
162 PlayerScore_Add(frag_attacker, SP_INVASION_KILLS, +1);
167 MUTATOR_HOOKFUNCTION(invasion_MonsterSpawn)
169 if(self.realowner == world)
171 WaypointSprite_Kill(self.sprite);
172 if(self.weaponentity) remove(self.weaponentity);
179 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_BOTCLIP | DPCONTENTS_MONSTERCLIP;
184 MUTATOR_HOOKFUNCTION(invasion_PlayerThink)
186 monsters_total = maxspawned; // TODO: make sure numspawned never exceeds maxspawned
187 monsters_killed = numkilled;
192 MUTATOR_HOOKFUNCTION(invasion_PlayerSpawn)
194 self.bot_attack = FALSE;
198 MUTATOR_HOOKFUNCTION(invasion_PlayerDamage)
200 if(IS_PLAYER(frag_attacker) && IS_PLAYER(frag_target) && frag_attacker != frag_target)
203 frag_force = '0 0 0';
206 if(frag_attacker.flags & FL_MONSTER && frag_target.flags & FL_MONSTER && frag_attacker != frag_target)
212 MUTATOR_HOOKFUNCTION(invasion_PlayerCommand)
214 if(MUTATOR_RETURNVALUE) // command was already handled?
217 if(cmd_name == "debuginvasion")
219 sprint(self, strcat("maxspawned = ", ftos(maxspawned), "\n"));
220 sprint(self, strcat("numspawned = ", ftos(numspawned), "\n"));
221 sprint(self, strcat("numkilled = ", ftos(numkilled), "\n"));
222 sprint(self, strcat("roundcnt = ", ftos(roundcnt), "\n"));
223 sprint(self, strcat("monsters_total = ", ftos(monsters_total), "\n"));
224 sprint(self, strcat("monsters_killed = ", ftos(monsters_killed), "\n"));
232 void invasion_ScoreRules()
234 ScoreRules_basics(0, SFL_SORT_PRIO_SECONDARY, 0, FALSE);
235 ScoreInfo_SetLabel_PlayerScore(SP_INVASION_KILLS, "kills", SFL_SORT_PRIO_PRIMARY);
236 ScoreRules_basics_end();
239 void invasion_Initialize()
241 invasion_ScoreRules();
243 round_handler_Spawn(Invasion_CheckPlayers, Invasion_CheckWinner, Invasion_RoundStart);
244 round_handler_Init(5, autocvar_g_invasion_warmup, autocvar_g_invasion_round_timelimit);
246 allowed_to_spawn = TRUE;
253 MUTATOR_DEFINITION(gamemode_invasion)
255 MUTATOR_HOOK(MonsterDies, invasion_MonsterDies, CBC_ORDER_ANY);
256 MUTATOR_HOOK(MonsterSpawn, invasion_MonsterSpawn, CBC_ORDER_ANY);
257 MUTATOR_HOOK(PlayerPreThink, invasion_PlayerThink, CBC_ORDER_ANY);
258 MUTATOR_HOOK(PlayerSpawn, invasion_PlayerSpawn, CBC_ORDER_ANY);
259 MUTATOR_HOOK(PlayerDamage_Calculate, invasion_PlayerDamage, CBC_ORDER_ANY);
260 MUTATOR_HOOK(SV_ParseClientCommand, invasion_PlayerCommand, CBC_ORDER_ANY);
264 if(time > 1) // game loads at time 1
265 error("This is a game type and it cannot be added at runtime.");
266 invasion_Initialize();
268 cvar_settemp("g_monsters", "1");
271 MUTATOR_ONROLLBACK_OR_REMOVE
273 // we actually cannot roll back invasion_Initialize here
274 // BUT: we don't need to! If this gets called, adding always
280 print("This is a game type and it cannot be removed at runtime.");