X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fserver%2Fmutators%2Fmutator%2Fgamemode_invasion.qc;h=1d9dc662017f7743f212588be4a96ba0c8a7f1c4;hp=7c949d8663625e207db2ece50ac03d993d999d2c;hb=f34fd47ee0a7f283ab60592a17399ec5a500416c;hpb=6a611fb362129440369cb09a590023d6292102e9 diff --git a/qcsrc/server/mutators/mutator/gamemode_invasion.qc b/qcsrc/server/mutators/mutator/gamemode_invasion.qc index 7c949d866..1d9dc6620 100644 --- a/qcsrc/server/mutators/mutator/gamemode_invasion.qc +++ b/qcsrc/server/mutators/mutator/gamemode_invasion.qc @@ -1,66 +1,4 @@ #include "gamemode_invasion.qh" -#ifndef GAMEMODE_INVASION_H -#define GAMEMODE_INVASION_H - -#define autocvar_g_invasion_point_limit cvar("g_invasion_point_limit") -int autocvar_g_invasion_teams; -bool autocvar_g_invasion_team_spawns; -bool g_invasion; -void invasion_Initialize(); - -REGISTER_MUTATOR(inv, false) -{ - MUTATOR_ONADD - { - if (time > 1) // game loads at time 1 - error("This is a game type and it cannot be added at runtime."); - g_invasion = true; - invasion_Initialize(); - - cvar_settemp("g_monsters", "1"); - - SetLimits(autocvar_g_invasion_point_limit, autocvar_leadlimit_override, autocvar_timelimit_override, -1); - if (autocvar_g_invasion_teams >= 2) - { - ActivateTeamplay(); - if (autocvar_g_invasion_team_spawns) - have_team_spawns = -1; // request team spawns - } - } - - MUTATOR_ONROLLBACK_OR_REMOVE - { - // we actually cannot roll back invasion_Initialize here - // BUT: we don't need to! If this gets called, adding always - // succeeds. - } - - MUTATOR_ONREMOVE - { - LOG_INFO("This is a game type and it cannot be removed at runtime."); - return -1; - } - - return 0; -} - -float inv_numspawned; -float inv_maxspawned; -float inv_roundcnt; -float inv_maxrounds; -float inv_numkilled; -float inv_lastcheck; -float inv_maxcurrent; - -float invasion_teams; -float inv_monsters_perteam[17]; - -float inv_monsterskill; - -const float ST_INV_KILLS = 1; -#endif - -#ifdef IMPLEMENTATION #include #include @@ -77,7 +15,7 @@ float autocvar_g_invasion_spawn_delay; spawnfunc(invasion_spawnpoint) { - if(!g_invasion) { remove(this); return; } + if(!g_invasion) { delete(this); return; } this.classname = "invasion_spawnpoint"; @@ -112,15 +50,13 @@ float invasion_PickMonster(float supermonster_count) entity invasion_PickSpawn() { - entity e; - RandomSelection_Init(); - for(e = NULL;(e = find(e, classname, "invasion_spawnpoint")); ) + FOREACH_ENTITY_CLASS("invasion_spawnpoint", true, { - RandomSelection_Add(e, 0, string_null, 1, ((time >= e.spawnshieldtime) ? 0.2 : 1)); // give recently used spawnpoints a very low rating - e.spawnshieldtime = time + autocvar_g_invasion_spawnpoint_spawn_delay; - } + RandomSelection_Add(it, 0, string_null, 1, ((time >= it.spawnshieldtime) ? 0.2 : 1)); // give recently used spawnpoints a very low rating + it.spawnshieldtime = time + autocvar_g_invasion_spawnpoint_spawn_delay; + }); return RandomSelection_chosen_ent; } @@ -133,7 +69,7 @@ void invasion_SpawnChosenMonster(float mon) if(spawn_point == NULL) { - LOG_TRACE("Warning: couldn't find any invasion_spawnpoint spawnpoints, attempting to spawn monsters in random locations\n"); + LOG_TRACE("Warning: couldn't find any invasion_spawnpoint spawnpoints, attempting to spawn monsters in random locations"); entity e = spawn(); setsize(e, (get_monsterinfo(mon)).mins, (get_monsterinfo(mon)).maxs); @@ -195,7 +131,11 @@ float Invasion_CheckWinner() { if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0) { - FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(Monster_Remove(it))); + IL_EACH(g_monsters, true, + { + Monster_Remove(it); + }); + IL_CLEAR(g_monsters); Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_OVER); Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_OVER); @@ -205,23 +145,21 @@ float Invasion_CheckWinner() float total_alive_monsters = 0, supermonster_count = 0, red_alive = 0, blue_alive = 0, yellow_alive = 0, pink_alive = 0; - FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA( - if(it.health > 0) - { - if((get_monsterinfo(it.monsterid)).spawnflags & MON_FLAG_SUPERMONSTER) - ++supermonster_count; - ++total_alive_monsters; + IL_EACH(g_monsters, it.health > 0, + { + if((get_monsterinfo(it.monsterid)).spawnflags & MON_FLAG_SUPERMONSTER) + ++supermonster_count; + ++total_alive_monsters; - if(teamplay) - switch(it.team) - { - case NUM_TEAM_1: ++red_alive; break; - case NUM_TEAM_2: ++blue_alive; break; - case NUM_TEAM_3: ++yellow_alive; break; - case NUM_TEAM_4: ++pink_alive; break; - } + if(teamplay) + switch(it.team) + { + case NUM_TEAM_1: ++red_alive; break; + case NUM_TEAM_2: ++blue_alive; break; + case NUM_TEAM_3: ++yellow_alive; break; + case NUM_TEAM_4: ++pink_alive; break; } - )); + }); if((total_alive_monsters + inv_numkilled) < inv_maxspawned && inv_maxcurrent < inv_maxspawned) { @@ -274,7 +212,11 @@ float Invasion_CheckWinner() )); } - FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(Monster_Remove(it))); + IL_EACH(g_monsters, true, + { + Monster_Remove(it); + }); + IL_CLEAR(g_monsters); if(teamplay) { @@ -481,7 +423,7 @@ MUTATOR_HOOKFUNCTION(inv, AllowMobButcher) return true; } -void invasion_ScoreRules(float inv_teams) +void invasion_ScoreRules(int inv_teams) { if(inv_teams) { CheckAllowedTeams(NULL); } ScoreRules_basics(inv_teams, 0, 0, false); @@ -493,7 +435,16 @@ void invasion_ScoreRules(float inv_teams) void invasion_DelayedInit(entity this) // Do this check with a delay so we can wait for teams to be set up. { if(autocvar_g_invasion_teams) + { invasion_teams = bound(2, autocvar_g_invasion_teams, 4); + int teams = 0; + if(invasion_teams >= 1) teams |= BIT(0); + if(invasion_teams >= 2) teams |= BIT(1); + if(invasion_teams >= 3) teams |= BIT(2); + if(invasion_teams >= 4) teams |= BIT(3); + + invasion_teams = teams; // now set it? + } else invasion_teams = 0; @@ -531,5 +482,3 @@ void invasion_Initialize() InitializeEntity(NULL, invasion_DelayedInit, INITPRIO_GAMETYPE); } - -#endif