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 if((numspawned + numkilled) < maxspawned)
82 if(time >= last_check)
84 invasion_SpawnMonsters();
85 last_check = time + 2;
91 if(numspawned < 1 || numkilled < numspawned)
92 return 0; // nothing has spawned yet, or there are still alive monsters
94 if(roundcnt >= maxrounds)
100 entity winner = world;
101 float winning_score = 0;
103 FOR_EACH_PLAYER(head)
105 if(PlayerScore_Add(head, SP_INVASION_KILLS, 0) > winning_score)
111 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_PLAYER_WIN, winner.netname);
112 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_PLAYER_WIN, winner.netname);
115 round_handler_Init(5, autocvar_g_invasion_warmup, autocvar_g_invasion_round_timelimit);
120 float Invasion_CheckPlayers()
125 void Invasion_RoundStart()
128 float numplayers = 0;
132 e.player_blocked = 0;
141 maxspawned = rint(autocvar_g_invasion_monster_count * roundcnt / 0.7);
143 maxspawned = autocvar_g_invasion_monster_count;
145 monster_skill += 0.01 * numplayers;
148 MUTATOR_HOOKFUNCTION(invasion_MonsterDies)
152 if(IS_PLAYER(frag_attacker))
153 PlayerScore_Add(frag_attacker, SP_INVASION_KILLS, +1);
158 MUTATOR_HOOKFUNCTION(invasion_MonsterSpawn)
160 if(self.realowner == world)
162 WaypointSprite_Kill(self.sprite);
163 if(self.weaponentity) remove(self.weaponentity);
170 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_BOTCLIP | DPCONTENTS_MONSTERCLIP;
175 MUTATOR_HOOKFUNCTION(invasion_PlayerThink)
177 monsters_total = maxspawned; // TODO: make sure numspawned never exceeds maxspawned
178 monsters_killed = numkilled;
183 MUTATOR_HOOKFUNCTION(invasion_PlayerSpawn)
185 self.bot_attack = FALSE;
189 MUTATOR_HOOKFUNCTION(invasion_PlayerDamage)
191 if(IS_PLAYER(frag_attacker) && IS_PLAYER(frag_target))
194 frag_force = '0 0 0';
197 if(frag_attacker.flags & FL_MONSTER && frag_target.flags & FL_MONSTER)
203 void invasion_ScoreRules()
205 ScoreRules_basics(0, SFL_SORT_PRIO_SECONDARY, 0, FALSE);
206 ScoreInfo_SetLabel_PlayerScore(SP_INVASION_KILLS, "kills", SFL_SORT_PRIO_PRIMARY);
207 ScoreRules_basics_end();
210 void invasion_Initialize()
212 invasion_ScoreRules();
214 round_handler_Spawn(Invasion_CheckPlayers, Invasion_CheckWinner, Invasion_RoundStart);
215 round_handler_Init(5, autocvar_g_invasion_warmup, autocvar_g_invasion_round_timelimit);
217 allowed_to_spawn = TRUE;
219 monster_skill = 0.01;
224 MUTATOR_DEFINITION(gamemode_invasion)
226 MUTATOR_HOOK(MonsterDies, invasion_MonsterDies, CBC_ORDER_ANY);
227 MUTATOR_HOOK(MonsterSpawn, invasion_MonsterSpawn, CBC_ORDER_ANY);
228 MUTATOR_HOOK(PlayerPreThink, invasion_PlayerThink, CBC_ORDER_ANY);
229 MUTATOR_HOOK(PlayerSpawn, invasion_PlayerSpawn, CBC_ORDER_ANY);
230 MUTATOR_HOOK(PlayerDamage_Calculate, invasion_PlayerDamage, CBC_ORDER_ANY);
234 if(time > 1) // game loads at time 1
235 error("This is a game type and it cannot be added at runtime.");
236 invasion_Initialize();
238 cvar_settemp("g_monsters", "1");
241 MUTATOR_ONROLLBACK_OR_REMOVE
243 // we actually cannot roll back invasion_Initialize here
244 // BUT: we don't need to! If this gets called, adding always
250 print("This is a game type and it cannot be removed at runtime.");