]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mutators/mutator/gamemode_domination.qc
Merge branch 'master' into Mario/teams_bitflag
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator / gamemode_domination.qc
index 01c5e4bd827041c26779e972d4c70674b6d4717b..3f75db9f387c320ab72a94840fa1badd366138a7 100644 (file)
@@ -82,7 +82,7 @@ int autocvar_g_domination_teams_override;
 void dom_EventLog(string mode, float team_before, entity actor) // use an alias for easy changing and quick editing later
 {
        if(autocvar_sv_eventlog)
-               GameLogEcho(strcat(":dom:", mode, ":", ftos(team_before), ((actor != world) ? (strcat(":", ftos(actor.playerid))) : "")));
+               GameLogEcho(strcat(":dom:", mode, ":", ftos(team_before), ((actor != NULL) ? (strcat(":", ftos(actor.playerid))) : "")));
 }
 
 void set_dom_state(entity e)
@@ -107,7 +107,7 @@ void dompoint_captured(entity this)
        this.cnt = -1;
 
        dom_EventLog("taken", this.team, this.dmg_inflictor);
-       this.dmg_inflictor = world;
+       this.dmg_inflictor = NULL;
 
        this.goalentity = head;
        this.model = head.mdl;
@@ -127,12 +127,12 @@ void dompoint_captured(entity this)
        if(domination_roundbased)
                bprint(sprintf("^3%s^3%s\n", head.netname, this.message));
        else
-               Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_DOMINATION_CAPTURE_TIME, head.netname, this.message, points, wait_time);
+               Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_DOMINATION_CAPTURE_TIME, head.netname, this.message, points, wait_time);
 
        if(this.enemy.playerid == this.enemy_playerid)
                PlayerScore_Add(this.enemy, SP_DOM_TAKES, 1);
        else
-               this.enemy = world;
+               this.enemy = NULL;
 
        if (head.noise != "")
                if(this.enemy)
@@ -165,7 +165,6 @@ void dompoint_captured(entity this)
        WaypointSprite_UpdateSprites(this.sprite, msg, WP_Null, WP_Null);
 
        total_pps = 0, pps_red = 0, pps_blue = 0, pps_yellow = 0, pps_pink = 0;
-       for(head = world; (head = find(head, classname, "dom_controlpoint")) != world; )
        FOREACH_ENTITY_CLASS("dom_controlpoint", true, LAMBDA(
                if (autocvar_g_domination_point_amt)
                        points = autocvar_g_domination_point_amt;
@@ -246,15 +245,15 @@ void dompointthink(entity this)
                        PlayerScore_Add(this.enemy, SP_DOM_TICKS, fragamt);
                }
                else
-                       this.enemy = world;
+                       this.enemy = NULL;
        }
 }
 
-void dompointtouch(entity this)
+void dompointtouch(entity this, entity toucher)
 {
-       if (!IS_PLAYER(other))
+       if (!IS_PLAYER(toucher))
                return;
-       if (other.health < 1)
+       if (toucher.health < 1)
                return;
 
        if(round_handler_IsActive() && !round_handler_IsRoundStarted())
@@ -264,8 +263,8 @@ void dompointtouch(entity this)
                return;
 
        // only valid teams can claim it
-       entity head = find(world, classname, "dom_team");
-       while (head && head.team != other.team)
+       entity head = find(NULL, classname, "dom_team");
+       while (head && head.team != toucher.team)
                head = find(head, classname, "dom_team");
        if (!head || head.netname == "" || head == this.goalentity)
                return;
@@ -274,9 +273,9 @@ void dompointtouch(entity this)
 
        this.team = this.goalentity.team; // this stores the PREVIOUS team!
 
-       this.cnt = other.team;
+       this.cnt = toucher.team;
        this.owner = head; // team to switch to after the delay
-       this.dmg_inflictor = other;
+       this.dmg_inflictor = toucher;
 
        // this.state = 1;
        // this.delay = time + cvar("g_domination_point_capturetime");
@@ -284,10 +283,10 @@ void dompointtouch(entity this)
        //this.think = dompoint_captured;
 
        // go to neutral team in the mean time
-       head = find(world, classname, "dom_team");
+       head = find(NULL, classname, "dom_team");
        while (head && head.netname != "")
                head = find(head, classname, "dom_team");
-       if(head == world)
+       if(head == NULL)
                return;
 
        WaypointSprite_UpdateSprites(this.sprite, WP_DomNeut, WP_Null, WP_Null);
@@ -299,8 +298,8 @@ void dompointtouch(entity this)
        this.modelindex = head.dmg;
        this.skin = head.skin;
 
-       this.enemy = other; // individual player scoring
-       this.enemy_playerid = other.playerid;
+       this.enemy = toucher; // individual player scoring
+       this.enemy_playerid = toucher.playerid;
        dompoint_captured(this);
 }
 
@@ -308,11 +307,11 @@ void dom_controlpoint_setup(entity this)
 {
        entity head;
        // find the spawnfunc_dom_team representing unclaimed points
-       head = find(world, classname, "dom_team");
+       head = find(NULL, classname, "dom_team");
        while(head && head.netname != "")
                head = find(head, classname, "dom_team");
        if (!head)
-               objerror("no spawnfunc_dom_team with netname \"\" found\n");
+               objerror(this, "no spawnfunc_dom_team with netname \"\" found\n");
 
        // copy important properties from spawnfunc_dom_team entity
        this.goalentity = head;
@@ -362,16 +361,15 @@ void dom_controlpoint_setup(entity this)
 float total_controlpoints;
 void Domination_count_controlpoints()
 {
-       entity e;
        total_controlpoints = redowned = blueowned = yellowowned = pinkowned = 0;
-       for(e = world; (e = find(e, classname, "dom_controlpoint")) != world; )
+       FOREACH_ENTITY_CLASS("dom_controlpoint", true,
        {
                ++total_controlpoints;
-               redowned += (e.goalentity.team == NUM_TEAM_1);
-               blueowned += (e.goalentity.team == NUM_TEAM_2);
-               yellowowned += (e.goalentity.team == NUM_TEAM_3);
-               pinkowned += (e.goalentity.team == NUM_TEAM_4);
-       }
+               redowned += (it.goalentity.team == NUM_TEAM_1);
+               blueowned += (it.goalentity.team == NUM_TEAM_2);
+               yellowowned += (it.goalentity.team == NUM_TEAM_3);
+               pinkowned += (it.goalentity.team == NUM_TEAM_4);
+       });
 }
 
 float Domination_GetWinnerTeam()
@@ -405,8 +403,8 @@ float Domination_CheckWinner()
 {
        if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
        {
-               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
-               Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
+               Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_OVER);
+               Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_OVER);
                round_handler_Init(5, autocvar_g_domination_warmup, autocvar_g_domination_round_timelimit);
                return 1;
        }
@@ -420,14 +418,14 @@ float Domination_CheckWinner()
 
        if(winner_team > 0)
        {
-               Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
-               Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
+               Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
+               Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
                TeamScore_AddToTeam(winner_team, ST_DOM_CAPS, +1);
        }
        else if(winner_team == -1)
        {
-               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
-               Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
+               Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_TIED);
+               Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_TIED);
        }
 
        round_handler_Init(5, autocvar_g_domination_warmup, autocvar_g_domination_round_timelimit);
@@ -469,7 +467,7 @@ MUTATOR_HOOKFUNCTION(dom, GetTeamCount)
        M_ARGV(0, float) = domination_teams;
        string ret_string = "dom_team";
 
-       entity head = find(world, classname, ret_string);
+       entity head = find(NULL, classname, ret_string);
        while(head)
        {
                if(head.netname != "")
@@ -495,13 +493,13 @@ MUTATOR_HOOKFUNCTION(dom, reset_map_players)
 {
        total_pps = 0, pps_red = 0, pps_blue = 0, pps_yellow = 0, pps_pink = 0;
        FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
-               WITHSELF(it, PutClientInServer());
+               PutClientInServer(it);
                if(domination_roundbased)
                        it.player_blocked = 1;
                if(IS_REAL_CLIENT(it))
                        set_dom_state(it);
        ));
-       return 1;
+       return true;
 }
 
 MUTATOR_HOOKFUNCTION(dom, PlayerSpawn)
@@ -513,7 +511,6 @@ MUTATOR_HOOKFUNCTION(dom, PlayerSpawn)
                player.player_blocked = 1;
        else
                player.player_blocked = 0;
-       return false;
 }
 
 MUTATOR_HOOKFUNCTION(dom, ClientConnect)
@@ -603,7 +600,7 @@ spawnfunc(dom_team)
 }
 
 // scoreboard setup
-void ScoreRules_dom(float teams)
+void ScoreRules_dom(int teams)
 {
        if(domination_roundbased)
        {
@@ -679,15 +676,22 @@ void dom_spawnteams(int teams)
 void dom_DelayedInit(entity this) // Do this check with a delay so we can wait for teams to be set up.
 {
        // if no teams are found, spawn defaults
-       if(find(world, classname, "dom_team") == world || autocvar_g_domination_teams_override >= 2)
+       if(find(NULL, classname, "dom_team") == NULL || autocvar_g_domination_teams_override >= 2)
        {
                LOG_TRACE("No \"dom_team\" entities found on this map, creating them anyway.\n");
                domination_teams = bound(2, ((autocvar_g_domination_teams_override < 2) ? autocvar_g_domination_default_teams : autocvar_g_domination_teams_override), 4);
                dom_spawnteams(domination_teams);
        }
 
-       CheckAllowedTeams(world);
-       domination_teams = ((c4>=0) ? 4 : (c3>=0) ? 3 : 2);
+       CheckAllowedTeams(NULL);
+       //domination_teams = ((c4>=0) ? 4 : (c3>=0) ? 3 : 2);
+
+       int teams = 0;
+       if(c1 >= 0) teams |= BIT(0);
+       if(c2 >= 0) teams |= BIT(1);
+       if(c3 >= 0) teams |= BIT(2);
+       if(c4 >= 0) teams |= BIT(3);
+       domination_teams = teams;
 
        domination_roundbased = autocvar_g_domination_roundbased;
 
@@ -703,7 +707,7 @@ void dom_DelayedInit(entity this) // Do this check with a delay so we can wait f
 void dom_Initialize()
 {
        g_domination = true;
-       InitializeEntity(world, dom_DelayedInit, INITPRIO_GAMETYPE);
+       InitializeEntity(NULL, dom_DelayedInit, INITPRIO_GAMETYPE);
 }
 
 #endif