From 08214a6d173731c938ef5e0f43b2f340ac615a3a Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 14 Oct 2015 23:20:44 +1000 Subject: [PATCH] Clean up GetTeamCount --- .../gamemodes/gamemode/nexball/nexball.qc | 6 ++ qcsrc/server/mutators/events.qh | 2 + qcsrc/server/mutators/gamemode_assault.qc | 19 +++++-- qcsrc/server/mutators/gamemode_ca.qc | 2 +- qcsrc/server/mutators/gamemode_domination.qc | 24 +++++++- qcsrc/server/mutators/gamemode_keyhunt.qc | 2 +- qcsrc/server/mutators/gamemode_onslaught.qc | 3 +- qcsrc/server/teamplay.qc | 57 +++++-------------- 8 files changed, 61 insertions(+), 54 deletions(-) diff --git a/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc b/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc index 1e60ab8ea..385e4eb09 100644 --- a/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc +++ b/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc @@ -1017,6 +1017,12 @@ MUTATOR_HOOKFUNCTION(nb, FilterItem) return false; } +MUTATOR_HOOKFUNCTION(nb, GetTeamCount) +{ + ret_string = "nexball_team"; + return true; +} + REGISTER_MUTATOR(nb, g_nexball) { ActivateTeamplay(); diff --git a/qcsrc/server/mutators/events.qh b/qcsrc/server/mutators/events.qh index b71d9f94f..5ab1258e6 100644 --- a/qcsrc/server/mutators/events.qh +++ b/qcsrc/server/mutators/events.qh @@ -122,6 +122,8 @@ MUTATOR_HOOKABLE(MatchEnd, EV_NO_ARGS); #define EV_GetTeamCount(i, o) \ /**/ i(float, ret_float) \ /**/ o(float, ret_float) \ + /**/ i(string, ret_string) \ + /**/ o(string, ret_string) \ /**/ float ret_float; MUTATOR_HOOKABLE(GetTeamCount, EV_GetTeamCount); diff --git a/qcsrc/server/mutators/gamemode_assault.qc b/qcsrc/server/mutators/gamemode_assault.qc index 1ae2a6269..c53511cfa 100644 --- a/qcsrc/server/mutators/gamemode_assault.qc +++ b/qcsrc/server/mutators/gamemode_assault.qc @@ -530,7 +530,7 @@ void havocbot_ast_reset_role(entity bot) } // mutator hooks -MUTATOR_HOOKFUNCTION(assault, PlayerSpawn) +MUTATOR_HOOKFUNCTION(as, PlayerSpawn) {SELFPARAM(); if(self.team == assault_attacker_team) Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_ATTACKING); @@ -540,7 +540,7 @@ MUTATOR_HOOKFUNCTION(assault, PlayerSpawn) return false; } -MUTATOR_HOOKFUNCTION(assault, TurretSpawn) +MUTATOR_HOOKFUNCTION(as, TurretSpawn) {SELFPARAM(); if(!self.team || self.team == MAX_SHOT_DISTANCE) self.team = 5; // this gets reversed when match starts? @@ -548,24 +548,31 @@ MUTATOR_HOOKFUNCTION(assault, TurretSpawn) return false; } -MUTATOR_HOOKFUNCTION(assault, VehicleSpawn) +MUTATOR_HOOKFUNCTION(as, VehicleSpawn) {SELFPARAM(); self.nextthink = time + 0.5; return false; } -MUTATOR_HOOKFUNCTION(assault, HavocBot_ChooseRole) +MUTATOR_HOOKFUNCTION(as, HavocBot_ChooseRole) {SELFPARAM(); havocbot_ast_reset_role(self); return true; } -MUTATOR_HOOKFUNCTION(assault, PlayHitsound) +MUTATOR_HOOKFUNCTION(as, PlayHitsound) { return (frag_victim.classname == "func_assault_destructible"); } +MUTATOR_HOOKFUNCTION(as, GetTeamCount) +{ + // assault always has 2 teams + c1 = c2 = 0; + return true; +} + // scoreboard setup void assault_ScoreRules() { @@ -575,7 +582,7 @@ void assault_ScoreRules() ScoreRules_basics_end(); } -REGISTER_MUTATOR(assault, g_assault) +REGISTER_MUTATOR(as, g_assault) { ActivateTeamplay(); have_team_spawns = -1; // request team spawns diff --git a/qcsrc/server/mutators/gamemode_ca.qc b/qcsrc/server/mutators/gamemode_ca.qc index b514fa296..dc6dca021 100644 --- a/qcsrc/server/mutators/gamemode_ca.qc +++ b/qcsrc/server/mutators/gamemode_ca.qc @@ -255,7 +255,7 @@ MUTATOR_HOOKFUNCTION(ca, reset_map_global) MUTATOR_HOOKFUNCTION(ca, GetTeamCount, CBC_ORDER_EXCLUSIVE) { ret_float = ca_teams; - return 0; + return false; } entity ca_LastPlayerForTeam() diff --git a/qcsrc/server/mutators/gamemode_domination.qc b/qcsrc/server/mutators/gamemode_domination.qc index 740d16c62..2c124b5de 100644 --- a/qcsrc/server/mutators/gamemode_domination.qc +++ b/qcsrc/server/mutators/gamemode_domination.qc @@ -417,8 +417,30 @@ void havocbot_role_dom() MUTATOR_HOOKFUNCTION(dom, GetTeamCount) { + // fallback? ret_float = domination_teams; - return 0; + ret_string = "dom_team"; + + entity head = find(world, classname, ret_string); + while(head) + { + if(head.netname != "") + { + switch(head.team) + { + 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, ret_string); + } + + ret_string = string_null; + + return true; } MUTATOR_HOOKFUNCTION(dom, reset_map_players) diff --git a/qcsrc/server/mutators/gamemode_keyhunt.qc b/qcsrc/server/mutators/gamemode_keyhunt.qc index 5ff452408..1affe8ed0 100644 --- a/qcsrc/server/mutators/gamemode_keyhunt.qc +++ b/qcsrc/server/mutators/gamemode_keyhunt.qc @@ -1082,7 +1082,7 @@ MUTATOR_HOOKFUNCTION(kh, MatchEnd) MUTATOR_HOOKFUNCTION(kh, GetTeamCount, CBC_ORDER_EXCLUSIVE) { ret_float = kh_teams; - return 0; + return false; } MUTATOR_HOOKFUNCTION(kh, SpectateCopy) diff --git a/qcsrc/server/mutators/gamemode_onslaught.qc b/qcsrc/server/mutators/gamemode_onslaught.qc index 869cd90d2..cc6ad200c 100644 --- a/qcsrc/server/mutators/gamemode_onslaught.qc +++ b/qcsrc/server/mutators/gamemode_onslaught.qc @@ -1937,8 +1937,7 @@ MUTATOR_HOOKFUNCTION(ons, HavocBot_ChooseRole) MUTATOR_HOOKFUNCTION(ons, GetTeamCount) { // onslaught is special - entity tmp_entity; - for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext) + for(entity tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext) { switch(tmp_entity.team) { diff --git a/qcsrc/server/teamplay.qc b/qcsrc/server/teamplay.qc index 73ab0cefe..253697905 100644 --- a/qcsrc/server/teamplay.qc +++ b/qcsrc/server/teamplay.qc @@ -231,45 +231,19 @@ void SetPlayerTeam(entity pl, float t, float s, float noprint) // 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) @@ -281,20 +255,17 @@ void CheckAllowedTeams (entity for_whom) // 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); } } -- 2.39.2