#include "command/vote.qh"
-#include "mutators/mutators_include.qh"
+#include "mutators/all.qh"
-#include "../common/deathtypes.qh"
+#include "../common/deathtypes/all.qh"
+#include "../common/gamemodes/all.qh"
#include "../common/teams.qh"
void TeamchangeFrags(entity e)
GameLogEcho(strcat(":team:", ftos(player_id), ":", ftos(team_number), ":", ftos(type)));
}
-void default_delayedinit()
+void default_delayedinit(entity this)
{
if(!scores_initialized)
ScoreRules_generic();
void InitGameplayMode()
{
- float fraglimit_override, timelimit_override, leadlimit_override, qualifying_override;
-
- qualifying_override = -1;
-
VoteReset();
// find out good world mins/maxs bounds, either the static bounds found by looking for solid, or the mapinfo specified bounds
MapInfo_ClearTemps();
- // set both here, gamemode can override it later
- timelimit_override = autocvar_timelimit_override;
- fraglimit_override = autocvar_fraglimit_override;
- leadlimit_override = autocvar_leadlimit_override;
gamemode_name = MapInfo_Type_ToText(MapInfo_LoadedGametype);
- if(g_dm)
- {
- MUTATOR_ADD(gamemode_deathmatch);
- }
-
- if(g_tdm)
- {
- ActivateTeamplay();
- fraglimit_override = autocvar_g_tdm_point_limit;
- leadlimit_override = autocvar_g_tdm_point_leadlimit;
- if(autocvar_g_tdm_team_spawns)
- have_team_spawns = -1; // request team spawns
- MUTATOR_ADD(gamemode_tdm);
- }
-
- if(g_domination)
- {
- ActivateTeamplay();
- fraglimit_override = autocvar_g_domination_point_limit;
- leadlimit_override = autocvar_g_domination_point_leadlimit;
- if(autocvar_g_domination_roundbased && autocvar_g_domination_roundbased_point_limit)
- fraglimit_override = autocvar_g_domination_roundbased_point_limit;
- have_team_spawns = -1; // request team spawns
- MUTATOR_ADD(gamemode_domination);
- }
-
- if(g_ctf)
- {
- ActivateTeamplay();
- fraglimit_override = autocvar_capturelimit_override;
- leadlimit_override = autocvar_captureleadlimit_override;
- have_team_spawns = -1; // request team spawns
- MUTATOR_ADD(gamemode_ctf);
- }
-
- if(g_lms)
- {
- fraglimit_override = autocvar_g_lms_lives_override;
- leadlimit_override = 0; // not supported by LMS
- if(fraglimit_override == 0)
- fraglimit_override = -1;
- MUTATOR_ADD(gamemode_lms);
- }
-
- if(g_ca)
- {
- ActivateTeamplay();
- fraglimit_override = autocvar_g_ca_point_limit;
- leadlimit_override = autocvar_g_ca_point_leadlimit;
- if(autocvar_g_ca_team_spawns)
- have_team_spawns = -1; // request team spawns
- MUTATOR_ADD(gamemode_ca);
- }
-
- if(g_keyhunt)
- {
- ActivateTeamplay();
- fraglimit_override = autocvar_g_keyhunt_point_limit;
- leadlimit_override = autocvar_g_keyhunt_point_leadlimit;
- if(autocvar_g_keyhunt_team_spawns)
- have_team_spawns = -1; // request team spawns
- MUTATOR_ADD(gamemode_keyhunt);
- }
-
- if(g_freezetag)
- {
- ActivateTeamplay();
- fraglimit_override = autocvar_g_freezetag_point_limit;
- leadlimit_override = autocvar_g_freezetag_point_leadlimit;
- if(autocvar_g_freezetag_team_spawns)
- have_team_spawns = -1; // request team spawns
- MUTATOR_ADD(gamemode_freezetag);
- }
-
- if(g_assault)
- {
- ActivateTeamplay();
- have_team_spawns = -1; // request team spawns
- MUTATOR_ADD(gamemode_assault);
- }
-
- if(g_onslaught)
- {
- ActivateTeamplay();
- fraglimit_override = autocvar_g_onslaught_point_limit;
- have_team_spawns = -1; // request team spawns
- MUTATOR_ADD(gamemode_onslaught);
- }
-
- if(g_race)
- {
- if(autocvar_g_race_teams)
- {
- ActivateTeamplay();
- race_teams = bound(2, autocvar_g_race_teams, 4);
- have_team_spawns = -1; // request team spawns
- }
- else
- race_teams = 0;
- qualifying_override = autocvar_g_race_qualifying_timelimit_override;
- fraglimit_override = autocvar_g_race_laps_limit;
- leadlimit_override = 0; // currently not supported by race
-
- // we need to find out the correct value for g_race_qualifying
- float want_qualifying = ((qualifying_override >= 0) ? qualifying_override : autocvar_g_race_qualifying_timelimit) > 0;
-
- if(autocvar_g_campaign)
- {
- g_race_qualifying = 1;
- independent_players = 1;
- }
- else if(!autocvar_g_campaign && want_qualifying)
- {
- g_race_qualifying = 2;
- independent_players = 1;
- race_fraglimit = (race_fraglimit >= 0) ? fraglimit_override : autocvar_fraglimit;
- race_leadlimit = (race_leadlimit >= 0) ? leadlimit_override : autocvar_leadlimit;
- race_timelimit = (race_timelimit >= 0) ? timelimit_override : autocvar_timelimit;
- fraglimit_override = 0;
- leadlimit_override = 0;
- timelimit_override = autocvar_g_race_qualifying_timelimit;
- }
- else
- {
- g_race_qualifying = 0;
- }
-
- MUTATOR_ADD(gamemode_race);
- }
-
- if(g_cts)
- {
- g_race_qualifying = 1;
- fraglimit_override = 0;
- leadlimit_override = 0;
- independent_players = 1;
- MUTATOR_ADD(gamemode_cts);
- }
-
- if(g_nexball)
- {
- fraglimit_override = autocvar_g_nexball_goallimit;
- leadlimit_override = autocvar_g_nexball_goalleadlimit;
- ActivateTeamplay();
- have_team_spawns = -1; // request team spawns
- MUTATOR_ADD(gamemode_nexball);
- }
-
- if(g_keepaway)
- {
- MUTATOR_ADD(gamemode_keepaway);
- }
-
- if(g_invasion)
- {
- fraglimit_override = autocvar_g_invasion_point_limit;
- if(autocvar_g_invasion_teams >= 2)
- {
- ActivateTeamplay();
- if(autocvar_g_invasion_team_spawns)
- have_team_spawns = -1; // request team spawns
- }
- MUTATOR_ADD(gamemode_invasion);
- }
-
cache_mutatormsg = strzone("");
cache_lastmutatormsg = strzone("");
- // enforce the server's universal frag/time limits
- if(!autocvar_g_campaign)
- {
- if(fraglimit_override >= 0)
- cvar_set("fraglimit", ftos(fraglimit_override));
- if(timelimit_override >= 0)
- cvar_set("timelimit", ftos(timelimit_override));
- if(leadlimit_override >= 0)
- cvar_set("leadlimit", ftos(leadlimit_override));
- if(qualifying_override >= 0)
- cvar_set("g_race_qualifying_timelimit", ftos(qualifying_override));
- }
-
InitializeEntity(world, default_delayedinit, INITPRIO_GAMETYPE_FALLBACK);
}
return versionmsg;
}
-string getwelcomemessage(void)
+string getwelcomemessage()
{
string s, modifications, motd;
modifications = strcat(modifications, ", No start weapons");
if(cvar("sv_gravity") < stof(cvar_defstring("sv_gravity")))
modifications = strcat(modifications, ", Low gravity");
- if(g_cloaked && !g_cts)
- modifications = strcat(modifications, ", Cloaked");
if(g_weapon_stay && !g_cts)
modifications = strcat(modifications, ", Weapons stay");
if(g_jetpack)
if(modifications != "")
s = strcat(s, "^8\nactive modifications: ^3", modifications, "^8\n");
- if (cvar("g_nades"))
- s = strcat(s, "\n\n^3nades^8 are enabled, press 'g' to use them\n");
-
if(cache_lastmutatormsg != autocvar_g_mutatormsg)
{
if(cache_lastmutatormsg)
// set c1...c4 to show what teams are allowed
void CheckAllowedTeams (entity for_whom)
{SELFPARAM();
- float dm;
- entity head;
- string teament_name;
+ int dm = 0;
c1 = c2 = c3 = c4 = -1;
cb1 = cb2 = cb3 = cb4 = 0;
- teament_name = string_null;
- if(g_onslaught)
- {
- // onslaught is special
- head = findchain(classname, "onslaught_generator");
- while (head)
- {
- if (head.team == NUM_TEAM_1) c1 = 0;
- if (head.team == NUM_TEAM_2) c2 = 0;
- if (head.team == NUM_TEAM_3) c3 = 0;
- if (head.team == NUM_TEAM_4) c4 = 0;
- head = head.chain;
- }
- }
- else if(g_domination)
- teament_name = "dom_team";
- else if(g_ctf)
- teament_name = "ctf_team";
- else if(g_tdm)
- teament_name = "tdm_team";
- else if(g_nexball)
- teament_name = "nexball_team";
- else if(g_assault)
- c1 = c2 = 0; // Assault always has 2 teams
- else
- {
- // cover anything else by treating it like tdm with no teams spawned
- dm = 2;
+ string teament_name = string_null;
- MUTATOR_CALLHOOK(GetTeamCount, dm);
- dm = ret_float;
+ bool mutator_returnvalue = MUTATOR_CALLHOOK(GetTeamCount, dm, teament_name);
+ teament_name = ret_string;
+ dm = ret_float;
+ if(!mutator_returnvalue)
+ {
if(dm >= 4)
c1 = c2 = c3 = c4 = 0;
else if(dm >= 3)
// find out what teams are allowed if necessary
if(teament_name)
{
- head = find(world, classname, teament_name);
+ entity head = find(world, classname, teament_name);
while(head)
{
- if(!(g_domination && head.netname == ""))
+ switch(head.team)
{
- if(head.team == NUM_TEAM_1)
- c1 = 0;
- else if(head.team == NUM_TEAM_2)
- c2 = 0;
- else if(head.team == NUM_TEAM_3)
- c3 = 0;
- else if(head.team == NUM_TEAM_4)
- c4 = 0;
+ case NUM_TEAM_1: c1 = 0; break;
+ case NUM_TEAM_2: c2 = 0; break;
+ case NUM_TEAM_3: c3 = 0; break;
+ case NUM_TEAM_4: c4 = 0; break;
}
+
head = find(head, classname, teament_name);
}
}
// teams that are allowed will now have their player counts stored in c1...c4
void GetTeamCounts(entity ignore)
{
- entity head;
float value, bvalue;
// now count how many players are on each team already
// FIXME: also find and memorize the lowest-scoring bot on each team (in case players must be shuffled around)
// also remember the lowest-scoring player
- FOR_EACH_CLIENT(head)
- {
+ FOREACH_CLIENT(true, LAMBDA(
float t;
- if(IS_PLAYER(head) || head.caplayer)
- t = head.team;
- else if(head.team_forced > 0)
- t = head.team_forced; // reserve the spot
+ if(IS_PLAYER(it) || it.caplayer)
+ t = it.team;
+ else if(it.team_forced > 0)
+ t = it.team_forced; // reserve the spot
else
continue;
- if(head != ignore)// && head.netname != "")
+ if(it != ignore)// && it.netname != "")
{
- value = PlayerValue(head);
- if(IS_BOT_CLIENT(head))
+ value = PlayerValue(it);
+ if(IS_BOT_CLIENT(it))
bvalue = value;
else
bvalue = 0;
}
}
}
- }
+ ));
// if the player who has a forced team has not joined yet, reserve the spot
if(autocvar_g_campaign)
return RandomSelection_chosen_float;
}
-float JoinBestTeam(entity pl, float only_return_best, float forcebestteam)
+int JoinBestTeam(entity pl, bool only_return_best, bool forcebestteam)
{SELFPARAM();
float smallest, selectedteam;
LogTeamchange(pl.playerid, pl.team, 2); // log auto join
- if(pl.deadflag == DEAD_NO)
- Damage(pl, pl, pl, 100000, DEATH_TEAMCHANGE, pl.origin, '0 0 0');
+ if(!IS_DEAD(pl))
+ Damage(pl, pl, pl, 100000, DEATH_TEAMCHANGE.m_id, pl.origin, '0 0 0');
}
return smallest;
float scolor, dcolor, steam, dteam; //, dbotcount, scount, dcount;
// in normal deathmatch we can just apply the color and we're done
- if(!teamplay) {
+ if(!teamplay)
SetPlayerColors(self, _color);
+
+ if(!IS_CLIENT(self))
+ {
+ // since this is an engine function, and gamecode doesn't have any calls earlier than this, do the connecting message here
+ Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_CONNECTING, self.netname);
return;
}
+ if(!teamplay)
+ return;
+
scolor = self.clientcolors & 0x0F;
dcolor = _color & 0x0F;
TeamchangeFrags(self);
}
- // since this is an engine function, and gamecode doesn't have any calls earlier than this, do the connecting message here
- if(!IS_CLIENT(self))
- Send_Notification(NOTIF_ONE, self, MSG_INFO, INFO_CONNECTING, self.netname);
+ MUTATOR_CALLHOOK(Player_ChangeTeam, self, steam, dteam);
SetPlayerTeam(self, dteam, steam, !IS_CLIENT(self));
if(IS_PLAYER(self) && steam != dteam)
{
// kill player when changing teams
- if(self.deadflag == DEAD_NO)
- Damage(self, self, self, 100000, DEATH_TEAMCHANGE, self.origin, '0 0 0');
+ if(!IS_DEAD(self))
+ Damage(self, self, self, 100000, DEATH_TEAMCHANGE.m_id, self.origin, '0 0 0');
}
}
{
float smallestteam, smallestteam_count, steam;
float lowest_bot_score, lowest_player_score;
- entity head, lowest_bot, lowest_player, selected;
+ entity lowest_bot, lowest_player, selected;
smallestteam = 0;
smallestteam_count = 999999999;
lowest_player_score = 999999999;
// find the lowest-scoring player & bot of that team
- FOR_EACH_PLAYER(head)
- {
- if(head.team == steam)
+ FOREACH_CLIENT(IS_PLAYER(it) && it.team == steam, LAMBDA(
+ if(it.isbot)
{
- if(head.isbot)
+ if(it.totalfrags < lowest_bot_score)
{
- if(head.totalfrags < lowest_bot_score)
- {
- lowest_bot = head;
- lowest_bot_score = head.totalfrags;
- }
+ lowest_bot = it;
+ lowest_bot_score = it.totalfrags;
}
- else
+ }
+ else
+ {
+ if(it.totalfrags < lowest_player_score)
{
- if(head.totalfrags < lowest_player_score)
- {
- lowest_player = head;
- lowest_player_score = head.totalfrags;
- }
+ lowest_player = it;
+ lowest_player_score = it.totalfrags;
}
}
- }
+ ));
// prefers to move a bot...
if(lowest_bot != world)
TeamchangeFrags(selected);
SetPlayerTeam(selected, smallestteam, source_team, false);
- if(selected.deadflag == DEAD_NO)
- Damage(selected, selected, selected, 100000, DEATH_AUTOTEAMCHANGE, selected.origin, '0 0 0');
+ if(!IS_DEAD(selected))
+ Damage(selected, selected, selected, 100000, DEATH_AUTOTEAMCHANGE.m_id, selected.origin, '0 0 0');
Send_Notification(NOTIF_ONE, selected, MSG_CENTER, CENTER_DEATH_SELF_AUTOTEAMCHANGE, selected.team);
}