1 void spawnfunc_invasion_spawnpoint()
3 if(!g_invasion) { remove(self); return; }
5 self.classname = "invasion_spawnpoint";
7 if(autocvar_g_invasion_zombies_only) // precache only if it hasn't been already
9 MON_ACTION(self.monsterid, MR_PRECACHE);
12 float invasion_PickMonster(float supermonster_count)
14 if(autocvar_g_invasion_zombies_only)
20 RandomSelection_Init();
22 for(i = MON_FIRST; i <= MON_LAST; ++i)
24 mon = get_monsterinfo(i);
25 if((mon.spawnflags & MONSTER_TYPE_FLY) || (mon.spawnflags & MONSTER_TYPE_SWIM) || ((mon.spawnflags & MON_FLAG_SUPERMONSTER) && supermonster_count >= 1))
26 continue; // flying/swimming monsters not yet supported
28 RandomSelection_Add(world, i, string_null, 1, 1);
31 return RandomSelection_chosen_float;
34 entity invasion_PickSpawn()
38 RandomSelection_Init();
40 for(e = world;(e = find(e, classname, "invasion_spawnpoint")); )
42 RandomSelection_Add(e, 0, string_null, 1, ((time >= e.spawnshieldtime) ? 0.2 : 1)); // give recently used spawnpoints a very low rating
43 e.spawnshieldtime = time + autocvar_g_invasion_spawnpoint_spawn_delay;
46 return RandomSelection_chosen_ent;
49 void invasion_SpawnChosenMonster(float mon)
51 entity spawn_point, monster;
53 spawn_point = invasion_PickSpawn();
55 if(spawn_point == world)
57 dprint("Warning: couldn't find any invasion_spawnpoint spawnpoints, attempting to spawn monsters in random locations\n");
59 setsize(e, (get_monsterinfo(mon)).mins, (get_monsterinfo(mon)).maxs);
61 if(MoveToRandomMapLocation(e, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY, 10, 1024, 256))
62 monster = spawnmonster("", mon, world, world, e.origin, FALSE, FALSE, 2);
66 e.nextthink = time + 0.1;
69 monster = spawnmonster("", ((spawn_point.monsterid) ? spawn_point.monsterid : mon), spawn_point, spawn_point, spawn_point.origin, FALSE, FALSE, 2);
71 if(spawn_point) monster.target2 = spawn_point.target2;
72 monster.spawnshieldtime = time;
73 if(spawn_point && spawn_point.target_range) monster.target_range = spawn_point.target_range;
76 if(spawn_point && spawn_point.team && inv_monsters_perteam[spawn_point.team] > 0)
77 monster.team = spawn_point.team;
80 RandomSelection_Init();
81 if(inv_monsters_perteam[NUM_TEAM_1] > 0) RandomSelection_Add(world, NUM_TEAM_1, string_null, 1, 1);
82 if(inv_monsters_perteam[NUM_TEAM_2] > 0) RandomSelection_Add(world, NUM_TEAM_2, string_null, 1, 1);
83 if(invasion_teams >= 3) if(inv_monsters_perteam[NUM_TEAM_3] > 0) { RandomSelection_Add(world, NUM_TEAM_3, string_null, 1, 1); }
84 if(invasion_teams >= 4) if(inv_monsters_perteam[NUM_TEAM_4] > 0) { RandomSelection_Add(world, NUM_TEAM_4, string_null, 1, 1); }
86 monster.team = RandomSelection_chosen_float;
91 monster_setupcolors(monster);
95 WaypointSprite_UpdateTeamRadar(monster.sprite, RADARICON_DANGER, ((monster.team) ? Team_ColorRGB(monster.team) : '1 0 0'));
97 monster.sprite.team = 0;
98 monster.sprite.SendFlags |= 1;
102 monster.monster_attack = FALSE; // it's the player's job to kill all the monsters
104 if(inv_roundcnt >= inv_maxrounds)
105 monster.spawnflags |= MONSTERFLAG_MINIBOSS; // last round spawns minibosses
108 void invasion_SpawnMonsters(float supermonster_count)
110 float chosen_monster = invasion_PickMonster(supermonster_count);
112 invasion_SpawnChosenMonster(chosen_monster);
115 float Invasion_CheckWinner()
118 if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
120 FOR_EACH_MONSTER(head)
121 monster_remove(head);
123 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
124 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
125 round_handler_Init(5, autocvar_g_invasion_warmup, autocvar_g_invasion_round_timelimit);
129 float total_alive_monsters = 0, supermonster_count = 0, red_alive = 0, blue_alive = 0, yellow_alive = 0, pink_alive = 0;
131 FOR_EACH_MONSTER(head) if(head.health > 0)
133 if((get_monsterinfo(head.monsterid)).spawnflags & MON_FLAG_SUPERMONSTER)
134 ++supermonster_count;
135 ++total_alive_monsters;
140 case NUM_TEAM_1: ++red_alive; break;
141 case NUM_TEAM_2: ++blue_alive; break;
142 case NUM_TEAM_3: ++yellow_alive; break;
143 case NUM_TEAM_4: ++pink_alive; break;
147 if((total_alive_monsters + inv_numkilled) < inv_maxspawned && inv_maxcurrent < inv_maxspawned)
149 if(time >= inv_lastcheck)
151 invasion_SpawnMonsters(supermonster_count);
152 inv_lastcheck = time + autocvar_g_invasion_spawn_delay;
158 if(inv_numspawned < 1)
159 return 0; // nothing has spawned yet
163 if(((red_alive > 0) + (blue_alive > 0) + (yellow_alive > 0) + (pink_alive > 0)) > 1)
166 else if(inv_numkilled < inv_maxspawned)
169 entity winner = world;
170 float winning_score = 0, winner_team = 0;
175 if(red_alive > 0) { winner_team = NUM_TEAM_1; }
177 if(winner_team) { winner_team = 0; }
178 else { winner_team = NUM_TEAM_2; }
180 if(winner_team) { winner_team = 0; }
181 else { winner_team = NUM_TEAM_3; }
183 if(winner_team) { winner_team = 0; }
184 else { winner_team = NUM_TEAM_4; }
187 FOR_EACH_PLAYER(head)
189 float cs = PlayerScore_Add(head, SP_KILLS, 0);
190 if(cs > winning_score)
197 FOR_EACH_MONSTER(head)
198 monster_remove(head);
204 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_));
205 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_));
210 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_PLAYER_WIN, winner.netname);
211 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_PLAYER_WIN, winner.netname);
214 round_handler_Init(5, autocvar_g_invasion_warmup, autocvar_g_invasion_round_timelimit);
219 float Invasion_CheckPlayers()
224 void Invasion_RoundStart()
227 float numplayers = 0;
230 e.player_blocked = 0;
234 if(inv_roundcnt < inv_maxrounds)
235 inv_roundcnt += 1; // a limiter to stop crazy counts
237 inv_monsterskill = inv_roundcnt + max(1, numplayers * 0.3);
243 inv_maxspawned = rint(max(autocvar_g_invasion_monster_count, autocvar_g_invasion_monster_count * (inv_roundcnt * 0.5)));
247 DistributeEvenly_Init(inv_maxspawned, invasion_teams);
248 inv_monsters_perteam[NUM_TEAM_1] = DistributeEvenly_Get(1);
249 inv_monsters_perteam[NUM_TEAM_2] = DistributeEvenly_Get(1);
250 if(invasion_teams >= 3) inv_monsters_perteam[NUM_TEAM_3] = DistributeEvenly_Get(1);
251 if(invasion_teams >= 4) inv_monsters_perteam[NUM_TEAM_4] = DistributeEvenly_Get(1);
255 MUTATOR_HOOKFUNCTION(invasion_MonsterDies)
257 if(!(self.spawnflags & MONSTERFLAG_RESPAWNED))
261 if(teamplay) { inv_monsters_perteam[self.team] -= 1; }
263 if(IS_PLAYER(frag_attacker))
264 if(SAME_TEAM(frag_attacker, self)) // in non-teamplay modes, same team = same player, so this works
265 PlayerScore_Add(frag_attacker, SP_KILLS, -1);
268 PlayerScore_Add(frag_attacker, SP_KILLS, +1);
270 TeamScore_AddToTeam(frag_attacker.team, ST_INV_KILLS, +1);
277 MUTATOR_HOOKFUNCTION(invasion_MonsterSpawn)
279 if(!(self.spawnflags & MONSTERFLAG_SPAWNED))
282 if(!(self.spawnflags & MONSTERFLAG_RESPAWNED))
288 self.monster_skill = inv_monsterskill;
290 if((get_monsterinfo(self.monsterid)).spawnflags & MON_FLAG_SUPERMONSTER)
291 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_INVASION_SUPERMONSTER, M_NAME(self.monsterid));
293 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_BOTCLIP | DPCONTENTS_MONSTERCLIP;
298 MUTATOR_HOOKFUNCTION(invasion_OnEntityPreSpawn)
300 if(startsWith(self.classname, "monster_"))
301 if(!(self.spawnflags & MONSTERFLAG_SPAWNED))
307 MUTATOR_HOOKFUNCTION(invasion_StartFrame)
309 monsters_total = inv_maxspawned; // TODO: make sure numspawned never exceeds maxspawned
310 monsters_killed = inv_numkilled;
315 MUTATOR_HOOKFUNCTION(invasion_PlayerRegen)
317 // no regeneration in invasion
321 MUTATOR_HOOKFUNCTION(invasion_PlayerSpawn)
323 self.bot_attack = FALSE;
327 MUTATOR_HOOKFUNCTION(invasion_PlayerDamage)
329 if(IS_PLAYER(frag_attacker) && IS_PLAYER(frag_target) && frag_attacker != frag_target)
332 frag_force = '0 0 0';
338 MUTATOR_HOOKFUNCTION(invasion_PlayerCommand)
340 if(MUTATOR_RETURNVALUE) // command was already handled?
343 if(cmd_name == "debuginvasion")
345 sprint(self, strcat("inv_maxspawned = ", ftos(inv_maxspawned), "\n"));
346 sprint(self, strcat("inv_numspawned = ", ftos(inv_numspawned), "\n"));
347 sprint(self, strcat("inv_numkilled = ", ftos(inv_numkilled), "\n"));
348 sprint(self, strcat("inv_roundcnt = ", ftos(inv_roundcnt), "\n"));
349 sprint(self, strcat("monsters_total = ", ftos(monsters_total), "\n"));
350 sprint(self, strcat("monsters_killed = ", ftos(monsters_killed), "\n"));
351 sprint(self, strcat("inv_monsterskill = ", ftos(inv_monsterskill), "\n"));
359 MUTATOR_HOOKFUNCTION(invasion_BotShouldAttack)
361 if(!(checkentity.flags & FL_MONSTER))
367 MUTATOR_HOOKFUNCTION(invasion_SetStartItems)
370 start_armorvalue = 200;
375 MUTATOR_HOOKFUNCTION(invasion_AccuracyTargetValid)
377 if(frag_target.flags & FL_MONSTER)
378 return MUT_ACCADD_INVALID;
379 return MUT_ACCADD_INDIFFERENT;
382 MUTATOR_HOOKFUNCTION(invasion_AllowMobSpawning)
384 // monster spawning disabled during an invasion
388 MUTATOR_HOOKFUNCTION(invasion_GetTeamCount)
390 ret_float = invasion_teams;
394 void invasion_ScoreRules(float inv_teams)
396 if(inv_teams) { CheckAllowedTeams(world); }
397 ScoreRules_basics(inv_teams, 0, 0, FALSE);
398 if(inv_teams) ScoreInfo_SetLabel_TeamScore(ST_INV_KILLS, "frags", SFL_SORT_PRIO_PRIMARY);
399 ScoreInfo_SetLabel_PlayerScore(SP_KILLS, "frags", ((inv_teams) ? SFL_SORT_PRIO_SECONDARY : SFL_SORT_PRIO_PRIMARY));
400 ScoreRules_basics_end();
403 void invasion_DelayedInit() // Do this check with a delay so we can wait for teams to be set up.
405 if(autocvar_g_invasion_teams)
406 invasion_teams = bound(2, autocvar_g_invasion_teams, 4);
410 independent_players = 1; // to disable extra useless scores
412 invasion_ScoreRules(invasion_teams);
414 independent_players = 0;
416 round_handler_Spawn(Invasion_CheckPlayers, Invasion_CheckWinner, Invasion_RoundStart);
417 round_handler_Init(5, autocvar_g_invasion_warmup, autocvar_g_invasion_round_timelimit);
420 inv_maxrounds = 15; // 15?
423 void invasion_Initialize()
425 if(autocvar_g_invasion_zombies_only)
426 MON_ACTION(MON_ZOMBIE, MR_PRECACHE);
431 for(i = MON_FIRST; i <= MON_LAST; ++i)
433 mon = get_monsterinfo(i);
434 if((mon.spawnflags & MONSTER_TYPE_FLY) || (mon.spawnflags & MONSTER_TYPE_SWIM))
435 continue; // flying/swimming monsters not yet supported
437 MON_ACTION(i, MR_PRECACHE);
441 InitializeEntity(world, invasion_DelayedInit, INITPRIO_GAMETYPE);
444 MUTATOR_DEFINITION(gamemode_invasion)
446 MUTATOR_HOOK(MonsterDies, invasion_MonsterDies, CBC_ORDER_ANY);
447 MUTATOR_HOOK(MonsterSpawn, invasion_MonsterSpawn, CBC_ORDER_ANY);
448 MUTATOR_HOOK(OnEntityPreSpawn, invasion_OnEntityPreSpawn, CBC_ORDER_ANY);
449 MUTATOR_HOOK(SV_StartFrame, invasion_StartFrame, CBC_ORDER_ANY);
450 MUTATOR_HOOK(PlayerRegen, invasion_PlayerRegen, CBC_ORDER_ANY);
451 MUTATOR_HOOK(PlayerSpawn, invasion_PlayerSpawn, CBC_ORDER_ANY);
452 MUTATOR_HOOK(PlayerDamage_Calculate, invasion_PlayerDamage, CBC_ORDER_ANY);
453 MUTATOR_HOOK(SV_ParseClientCommand, invasion_PlayerCommand, CBC_ORDER_ANY);
454 MUTATOR_HOOK(BotShouldAttack, invasion_BotShouldAttack, CBC_ORDER_ANY);
455 MUTATOR_HOOK(SetStartItems, invasion_SetStartItems, CBC_ORDER_ANY);
456 MUTATOR_HOOK(AccuracyTargetValid, invasion_AccuracyTargetValid, CBC_ORDER_ANY);
457 MUTATOR_HOOK(AllowMobSpawning, invasion_AllowMobSpawning, CBC_ORDER_ANY);
458 MUTATOR_HOOK(GetTeamCount, invasion_GetTeamCount, CBC_ORDER_ANY);
462 if(time > 1) // game loads at time 1
463 error("This is a game type and it cannot be added at runtime.");
464 invasion_Initialize();
466 cvar_settemp("g_monsters", "1");
469 MUTATOR_ONROLLBACK_OR_REMOVE
471 // we actually cannot roll back invasion_Initialize here
472 // BUT: we don't need to! If this gets called, adding always
478 print("This is a game type and it cannot be removed at runtime.");