1 void invasion_spawnpoint()
3 if not(g_invasion) { remove(self); return; }
5 self.classname = "invasion_spawnpoint";
8 float invasion_PickMonster(float have_shamblers)
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 || (i == MONSTER_SHAMBLER && have_shamblers >= 1))
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(float have_shamblers)
57 float chosen_monster = invasion_PickMonster(have_shamblers);
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);
71 if(head.iceblock) remove(head.iceblock);
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);
87 float total_alive_monsters = 0, shamblers = 0;
89 FOR_EACH_MONSTER(head) if(head.health > 0)
91 if(head.monsterid == MONSTER_SHAMBLER)
93 ++total_alive_monsters;
96 if((total_alive_monsters + numkilled) < maxspawned && maxcurrent < 10) // 10 at a time should be plenty
98 if(time >= last_check)
100 invasion_SpawnMonsters(shamblers);
101 last_check = time + 2;
107 if(numspawned < 1 || numkilled < maxspawned)
108 return 0; // nothing has spawned yet, or there are still alive monsters
110 if(roundcnt >= maxrounds)
116 entity winner = world;
117 float winning_score = 0;
119 FOR_EACH_PLAYER(head)
121 float cs = PlayerScore_Add(head, SP_KILLS, 0);
122 if(cs > winning_score)
131 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_PLAYER_WIN, winner.netname);
132 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_PLAYER_WIN, winner.netname);
135 round_handler_Init(5, autocvar_g_invasion_warmup, autocvar_g_invasion_round_timelimit);
140 float Invasion_CheckPlayers()
145 void Invasion_RoundStart()
148 float numplayers = 0;
151 e.player_blocked = 0;
162 maxspawned = rint(autocvar_g_invasion_monster_count * (roundcnt * 0.5));
164 maxspawned = autocvar_g_invasion_monster_count;
166 monster_skill += 0.1 * numplayers;
169 MUTATOR_HOOKFUNCTION(invasion_MonsterDies)
174 if(IS_PLAYER(frag_attacker))
175 PlayerScore_Add(frag_attacker, SP_KILLS, +1);
180 MUTATOR_HOOKFUNCTION(invasion_MonsterSpawn)
182 if(self.realowner == world)
184 WaypointSprite_Kill(self.sprite);
185 if(self.weaponentity) remove(self.weaponentity);
186 if(self.iceblock) remove(self.iceblock);
194 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_BOTCLIP | DPCONTENTS_MONSTERCLIP;
199 MUTATOR_HOOKFUNCTION(invasion_PlayerThink)
201 monsters_total = maxspawned; // TODO: make sure numspawned never exceeds maxspawned
202 monsters_killed = numkilled;
207 MUTATOR_HOOKFUNCTION(invasion_PlayerSpawn)
209 self.bot_attack = FALSE;
213 MUTATOR_HOOKFUNCTION(invasion_PlayerDamage)
215 if(IS_PLAYER(frag_attacker) && IS_PLAYER(frag_target) && frag_attacker != frag_target)
218 frag_force = '0 0 0';
221 if(frag_attacker.flags & FL_MONSTER && frag_target.flags & FL_MONSTER && frag_attacker != frag_target)
227 MUTATOR_HOOKFUNCTION(invasion_PlayerCommand)
229 if(MUTATOR_RETURNVALUE) // command was already handled?
232 if(cmd_name == "debuginvasion")
234 sprint(self, strcat("maxspawned = ", ftos(maxspawned), "\n"));
235 sprint(self, strcat("numspawned = ", ftos(numspawned), "\n"));
236 sprint(self, strcat("numkilled = ", ftos(numkilled), "\n"));
237 sprint(self, strcat("roundcnt = ", ftos(roundcnt), "\n"));
238 sprint(self, strcat("monsters_total = ", ftos(monsters_total), "\n"));
239 sprint(self, strcat("monsters_killed = ", ftos(monsters_killed), "\n"));
240 sprint(self, strcat("monster_skill = ", ftos(monster_skill), "\n"));
248 MUTATOR_HOOKFUNCTION(invasion_SetStartItems)
250 start_armorvalue = 100;
255 void invasion_ScoreRules()
257 ScoreRules_basics(0, 0, 0, FALSE);
258 ScoreInfo_SetLabel_PlayerScore(SP_KILLS, "frags", SFL_SORT_PRIO_PRIMARY);
259 ScoreRules_basics_end();
262 void invasion_Initialize()
264 independent_players = 1; // to disable extra useless scores
266 invasion_ScoreRules();
268 independent_players = 0;
270 round_handler_Spawn(Invasion_CheckPlayers, Invasion_CheckWinner, Invasion_RoundStart);
271 round_handler_Init(5, autocvar_g_invasion_warmup, autocvar_g_invasion_round_timelimit);
273 allowed_to_spawn = TRUE;
280 MUTATOR_DEFINITION(gamemode_invasion)
282 MUTATOR_HOOK(MonsterDies, invasion_MonsterDies, CBC_ORDER_ANY);
283 MUTATOR_HOOK(MonsterSpawn, invasion_MonsterSpawn, CBC_ORDER_ANY);
284 MUTATOR_HOOK(PlayerPreThink, invasion_PlayerThink, CBC_ORDER_ANY);
285 MUTATOR_HOOK(PlayerSpawn, invasion_PlayerSpawn, CBC_ORDER_ANY);
286 MUTATOR_HOOK(PlayerDamage_Calculate, invasion_PlayerDamage, CBC_ORDER_ANY);
287 MUTATOR_HOOK(SV_ParseClientCommand, invasion_PlayerCommand, CBC_ORDER_ANY);
288 MUTATOR_HOOK(SetStartItems, invasion_SetStartItems, CBC_ORDER_ANY);
292 if(time > 1) // game loads at time 1
293 error("This is a game type and it cannot be added at runtime.");
294 invasion_Initialize();
296 cvar_settemp("g_monsters", "1");
299 MUTATOR_ONROLLBACK_OR_REMOVE
301 // we actually cannot roll back invasion_Initialize here
302 // BUT: we don't need to! If this gets called, adding always
308 print("This is a game type and it cannot be removed at runtime.");