]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mutators/mutator/gamemode_keyhunt.qc
Merge branch 'Mario/teams_bitflag' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator / gamemode_keyhunt.qc
index 6bb53b7c5925e38f2d4bf3f8c65c526133e53273..1ffe6e60c07518e44d625b9551a7ac1db74db995 100644 (file)
@@ -144,7 +144,7 @@ const float SP_KH_DESTROYS = 6;
 const float SP_KH_PICKUPS = 7;
 const float SP_KH_KCKILLS = 8;
 const float SP_KH_LOSSES = 9;
-void kh_ScoreRules(float teams)
+void kh_ScoreRules(int teams)
 {
        ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, true);
        ScoreInfo_SetLabel_TeamScore(  ST_KH_CAPS,      "caps",      SFL_SORT_PRIO_SECONDARY);
@@ -200,7 +200,7 @@ void kh_update_state()
                if(key.owner)
                        key.owner.kh_state |= pow(32, key.count) * 31;
        }
-       //print(ftos((nextent(world)).kh_state), "\n");
+       //print(ftos((nextent(NULL)).kh_state), "\n");
 }
 
 
@@ -307,7 +307,7 @@ void kh_Key_Attach(entity key)  // runs when a player picks up a key and several
 #endif
        key.flags = 0;
        key.solid = SOLID_NOT;
-       key.movetype = MOVETYPE_NONE;
+       set_movetype(key, MOVETYPE_NONE);
        key.team = key.owner.team;
        key.nextthink = time;
        key.damageforcescale = 0;
@@ -336,17 +336,17 @@ void kh_Key_Detach(entity key) // runs every time a key is dropped or lost. Runs
                setorigin(first, first.origin + 0.5 * KH_PLAYER_ATTACHMENT_DIST);
        }
        // in any case:
-       setattachment(key, world, "");
+       setattachment(key, NULL, "");
        setorigin(key, key.owner.origin + '0 0 1' * (STAT(PL_MIN, NULL).z - KH_KEY_MIN_z));
        key.angles = key.owner.angles;
 #else
        setorigin(key, key.owner.origin + key.origin.z * '0 0 1');
-       setattachment(key, world, "");
+       setattachment(key, NULL, "");
        key.angles_y += key.owner.angles.y;
 #endif
        key.flags = FL_ITEM;
        key.solid = SOLID_TRIGGER;
-       key.movetype = MOVETYPE_TOSS;
+       set_movetype(key, MOVETYPE_TOSS);
        key.pain_finished = time + autocvar_g_balance_keyhunt_delay_return;
        key.damageforcescale = autocvar_g_balance_keyhunt_damageforcescale;
        key.takedamage = DAMAGE_YES;
@@ -373,10 +373,10 @@ void kh_Key_AssignTo(entity key, entity player)  // runs every time a key is pic
                if(key.kh_next)
                        key.kh_next.kh_prev = key.kh_prev;
                key.kh_prev.kh_next = key.kh_next;
-               key.kh_next = world;
-               key.kh_prev = world;
+               key.kh_next = NULL;
+               key.kh_prev = NULL;
 
-               if(key.owner.kh_next == world)
+               if(key.owner.kh_next == NULL)
                {
                        // No longer a key carrier
                        if(!kh_no_radar_circles)
@@ -410,7 +410,7 @@ void kh_Key_AssignTo(entity key, entity player)  // runs every time a key is pic
 
                kh_Key_Attach(key);
 
-               if(key.kh_next == world)
+               if(key.kh_next == NULL)
                {
                        // player is now a key carrier
                        entity wp = WaypointSprite_AttachCarrier(WP_Null, player, RADARICON_FLAGCARRIER);
@@ -433,7 +433,7 @@ void kh_Key_AssignTo(entity key, entity player)  // runs every time a key is pic
        // moved that here, also update if there's no player
        kh_update_state();
 
-       key.pusher = world;
+       key.pusher = NULL;
 
        ownerteam = kh_Key_AllOwnedByWhichTeam();
        if(ownerteam != ownerteam0)
@@ -500,12 +500,12 @@ void kh_Key_Collect(entity key, entity player)  //a player picks up a dropped ke
                PlayerScore_Add(player, SP_KH_PICKUPS, 1);
        }
        key.kh_dropperteam = 0;
-       Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_ENT(key, INFO_KEYHUNT_PICKUP), player.netname);
+       Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_ENT(key, INFO_KEYHUNT_PICKUP), player.netname);
 
        kh_Key_AssignTo(key, player); // this also updates .kh_state
 }
 
-void kh_Key_Touch(entity this)  // runs many, many times when a key has been dropped and can be picked up
+void kh_Key_Touch(entity this, entity toucher)  // runs many, many times when a key has been dropped and can be picked up
 {
        if(intermission_running)
                return;
@@ -521,21 +521,21 @@ void kh_Key_Touch(entity this)  // runs many, many times when a key has been dro
                // maybe start a shorter countdown?
        }
 
-       if (!IS_PLAYER(other))
+       if (!IS_PLAYER(toucher))
                return;
-       if(IS_DEAD(other))
+       if(IS_DEAD(toucher))
                return;
-       if(other == this.enemy)
+       if(toucher == this.enemy)
                if(time < this.kh_droptime + autocvar_g_balance_keyhunt_delay_collect)
                        return;  // you just dropped it!
-       kh_Key_Collect(this, other);
+       kh_Key_Collect(this, toucher);
 }
 
 void kh_Key_Remove(entity key)  // runs after when all the keys have been collected or when a key has been dropped for more than X seconds
 {
        entity o;
        o = key.owner;
-       kh_Key_AssignTo(key, world);
+       kh_Key_AssignTo(key, NULL);
        if(o) // it was attached
                WaypointSprite_Kill(key.waypointsprite_attachedforcarrier);
        else // it was dropped
@@ -574,7 +574,7 @@ void kh_FinishRound()  // runs when a team captures the keys
                kh_Key_Remove(key);
        kh_no_radar_circles = false;
 
-       Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_KEYHUNT_ROUNDSTART, autocvar_g_balance_keyhunt_delay_round);
+       Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_KEYHUNT_ROUNDSTART, autocvar_g_balance_keyhunt_delay_round);
        kh_Controller_SetThink(autocvar_g_balance_keyhunt_delay_round, kh_StartRound);
 }
 
@@ -609,7 +609,7 @@ void kh_WinnerTeam(float teem)  // runs when a team wins // Samual: Teem?.... TE
                        first = false;
                }
 
-       Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM(teem, INFO_KEYHUNT_CAPTURE), keyowner);
+       Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(teem, INFO_KEYHUNT_CAPTURE), keyowner);
 
        first = true;
        midpoint = '0 0 0';
@@ -624,7 +624,7 @@ void kh_WinnerTeam(float teem)  // runs when a team wins // Samual: Teem?.... TE
                midpoint += thisorigin;
 
                if(!first)
-                       te_lightning2(world, lastorigin, thisorigin);
+                       te_lightning2(NULL, lastorigin, thisorigin);
                lastorigin = thisorigin;
                if(first)
                        firstorigin = thisorigin;
@@ -632,7 +632,7 @@ void kh_WinnerTeam(float teem)  // runs when a team wins // Samual: Teem?.... TE
        }
        if(kh_teams > 2)
        {
-               te_lightning2(world, lastorigin, firstorigin);
+               te_lightning2(NULL, lastorigin, firstorigin);
        }
        midpoint = midpoint * (1 / kh_teams);
        te_customflash(midpoint, 1000, 1, Team_ColorRGB(teem) * 0.5 + '0.5 0.5 0.5');  // make the color >=0.5 in each component
@@ -648,7 +648,7 @@ void kh_LoserTeam(float teem, entity lostkey)  // runs when a player pushes a fl
        float keys;
        float f;
 
-       attacker = world;
+       attacker = NULL;
        if(lostkey.pusher)
                if(lostkey.pusher.team != teem)
                        if(IS_PLAYER(lostkey.pusher))
@@ -659,9 +659,9 @@ void kh_LoserTeam(float teem, entity lostkey)  // runs when a player pushes a fl
        if(attacker)
        {
                if(lostkey.kh_previous_owner)
-                       kh_Scores_Event(lostkey.kh_previous_owner, world, "pushed", 0, -autocvar_g_balance_keyhunt_score_push);
+                       kh_Scores_Event(lostkey.kh_previous_owner, NULL, "pushed", 0, -autocvar_g_balance_keyhunt_score_push);
                        // don't actually GIVE him the -nn points, just log
-               kh_Scores_Event(attacker, world, "push", autocvar_g_balance_keyhunt_score_push, 0);
+               kh_Scores_Event(attacker, NULL, "push", autocvar_g_balance_keyhunt_score_push, 0);
                PlayerScore_Add(attacker, SP_KH_PUSHES, 1);
                //centerprint(attacker, "Your push is the best!"); // does this really need to exist?
        }
@@ -677,7 +677,7 @@ void kh_LoserTeam(float teem, entity lostkey)  // runs when a player pushes a fl
                                ++keys;
 
                if(lostkey.kh_previous_owner)
-                       kh_Scores_Event(lostkey.kh_previous_owner, world, "destroyed", 0, -autocvar_g_balance_keyhunt_score_destroyed);
+                       kh_Scores_Event(lostkey.kh_previous_owner, NULL, "destroyed", 0, -autocvar_g_balance_keyhunt_score_destroyed);
                        // don't actually GIVE him the -nn points, just log
 
                if(lostkey.kh_previous_owner.playerid == lostkey.kh_previous_owner_playerid)
@@ -689,7 +689,7 @@ void kh_LoserTeam(float teem, entity lostkey)  // runs when a player pushes a fl
                        if(key.owner && key.team != teem)
                        {
                                f = DistributeEvenly_Get(of);
-                               kh_Scores_Event(key.owner, world, "destroyed_holdingkey", f, 0);
+                               kh_Scores_Event(key.owner, NULL, "destroyed_holdingkey", f, 0);
                        }
 
                fragsleft = DistributeEvenly_Get(players);
@@ -711,14 +711,14 @@ void kh_LoserTeam(float teem, entity lostkey)  // runs when a player pushes a fl
 
                        FOREACH_CLIENT(IS_PLAYER(it) && it.team == thisteam, LAMBDA(
                                f = DistributeEvenly_Get(1);
-                               kh_Scores_Event(it, world, "destroyed", f, 0);
+                               kh_Scores_Event(it, NULL, "destroyed", f, 0);
                        ));
 
                        --j;
                }
        }
 
-       Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_ENT(lostkey, INFO_KEYHUNT_LOST), lostkey.kh_previous_owner.netname);
+       Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_ENT(lostkey, INFO_KEYHUNT_LOST), lostkey.kh_previous_owner.netname);
 
        play2all(SND(KH_DESTROY));
        te_tarexplosion(lostkey.origin);
@@ -782,7 +782,7 @@ LABEL(not_winning)
 
 void key_reset(entity this)
 {
-       kh_Key_AssignTo(this, world);
+       kh_Key_AssignTo(this, NULL);
        kh_Key_Remove(this);
 }
 
@@ -833,7 +833,7 @@ void kh_Key_Spawn(entity initial_owner, float _angle, float i)  // runs every ti
 
        Send_Notification(NOTIF_ONE, initial_owner, MSG_CENTER, APP_TEAM_NUM(initial_owner.team, CENTER_KEYHUNT_START));
 
-       WaypointSprite_Spawn(WP_KeyDropped, 0, 0, key, '0 0 1' * KH_KEY_WP_ZSHIFT, world, key.team, key, waypointsprite_attachedforcarrier, false, RADARICON_FLAG);
+       WaypointSprite_Spawn(WP_KeyDropped, 0, 0, key, '0 0 1' * KH_KEY_WP_ZSHIFT, NULL, key.team, key, waypointsprite_attachedforcarrier, false, RADARICON_FLAG);
        key.waypointsprite_attachedforcarrier.waypointsprite_visible_for_player = kh_Key_waypointsprite_visible_for_player;
 
        kh_Key_AssignTo(key, initial_owner);
@@ -874,12 +874,12 @@ void kh_Key_DropOne(entity key)
 
        kh_Scores_Event(player, key, "dropkey", 0, 0);
        PlayerScore_Add(player, SP_KH_LOSSES, 1);
-       Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_ENT(key, INFO_KEYHUNT_DROP), player.netname);
+       Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_ENT(key, INFO_KEYHUNT_DROP), player.netname);
 
-       kh_Key_AssignTo(key, world);
+       kh_Key_AssignTo(key, NULL);
        makevectors(player.v_angle);
        key.velocity = W_CalculateProjectileVelocity(player, player.velocity, autocvar_g_balance_keyhunt_throwvelocity * v_forward, false);
-       key.pusher = world;
+       key.pusher = NULL;
        key.pushltime = time + autocvar_g_balance_keyhunt_protecttime;
        key.kh_dropperteam = key.team;
 
@@ -892,7 +892,7 @@ void kh_Key_DropAll(entity player, float suicide) // runs whenever a player dies
        entity mypusher;
        if(player.kh_next)
        {
-               mypusher = world;
+               mypusher = NULL;
                if(player.pusher)
                        if(time < player.pushltime)
                                mypusher = player.pusher;
@@ -900,8 +900,8 @@ void kh_Key_DropAll(entity player, float suicide) // runs whenever a player dies
                {
                        kh_Scores_Event(player, key, "losekey", 0, 0);
                        PlayerScore_Add(player, SP_KH_LOSSES, 1);
-                       Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_ENT(key, INFO_KEYHUNT_LOST), player.netname);
-                       kh_Key_AssignTo(key, world);
+                       Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_ENT(key, INFO_KEYHUNT_LOST), player.netname);
+                       kh_Key_AssignTo(key, NULL);
                        makevectors('-1 0 0' * (45 + 45 * random()) + '0 360 0' * random());
                        key.velocity = W_CalculateProjectileVelocity(player, player.velocity, autocvar_g_balance_keyhunt_dropvelocity * v_forward, false);
                        key.pusher = mypusher;
@@ -944,9 +944,9 @@ void kh_WaitForPlayers()  // delay start of the round until enough players are p
        if(KH_READY_TEAMS_OK())
        {
                if(prev_missing_teams_mask > 0)
-                       Kill_Notification(NOTIF_ALL, world, MSG_CENTER, CPID_MISSING_TEAMS);
+                       Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_MISSING_TEAMS);
                prev_missing_teams_mask = -1;
-               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_KEYHUNT_ROUNDSTART, autocvar_g_balance_keyhunt_delay_round);
+               Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_KEYHUNT_ROUNDSTART, autocvar_g_balance_keyhunt_delay_round);
                kh_Controller_SetThink(autocvar_g_balance_keyhunt_delay_round, kh_StartRound);
        }
        else
@@ -954,17 +954,23 @@ void kh_WaitForPlayers()  // delay start of the round until enough players are p
                if(player_count == 0)
                {
                        if(prev_missing_teams_mask > 0)
-                               Kill_Notification(NOTIF_ALL, world, MSG_CENTER, CPID_MISSING_TEAMS);
+                               Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_MISSING_TEAMS);
                        prev_missing_teams_mask = -1;
                }
                else
                {
-                       float missing_teams_mask = boolean(p1) + boolean(p2) * 2;
-                       if(kh_teams >= 3) missing_teams_mask += boolean(p3) * 4;
-                       if(kh_teams >= 4) missing_teams_mask += boolean(p4) * 8;
+                       int missing_teams_mask = 0;
+                       if(kh_teams & BIT(0))
+                               missing_teams_mask += boolean(p1) * 1;
+                       if(kh_teams & BIT(1))
+                               missing_teams_mask += boolean(p2) * 2;
+                       if(kh_teams & BIT(2))
+                               missing_teams_mask += boolean(p3) * 4;
+                       if(kh_teams & BIT(3))
+                               missing_teams_mask += boolean(p4) * 8;
                        if(prev_missing_teams_mask != missing_teams_mask)
                        {
-                               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
+                               Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
                                prev_missing_teams_mask = missing_teams_mask;
                        }
                }
@@ -974,8 +980,8 @@ void kh_WaitForPlayers()  // delay start of the round until enough players are p
 
 void kh_EnableTrackingDevice()  // runs after each round
 {
-       Kill_Notification(NOTIF_ALL, world, MSG_CENTER, CPID_KEYHUNT);
-       Kill_Notification(NOTIF_ALL, world, MSG_CENTER, CPID_KEYHUNT_OTHER);
+       Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_KEYHUNT);
+       Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_KEYHUNT_OTHER);
 
        kh_tracking_enabled = true;
 }
@@ -997,14 +1003,14 @@ void kh_StartRound()  // runs at the start of each round
                return;
        }
 
-       Kill_Notification(NOTIF_ALL, world, MSG_CENTER, CPID_KEYHUNT);
-       Kill_Notification(NOTIF_ALL, world, MSG_CENTER, CPID_KEYHUNT_OTHER);
+       Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_KEYHUNT);
+       Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_KEYHUNT_OTHER);
 
        for(i = 0; i < kh_teams; ++i)
        {
                teem = kh_Team_ByID(i);
                players = 0;
-               entity my_player = world;
+               entity my_player = NULL;
                FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
                        if(!IS_DEAD(it) && !PHYS_INPUT_BUTTON_CHAT(it) && it.team == teem)
                        {
@@ -1017,7 +1023,7 @@ void kh_StartRound()  // runs at the start of each round
        }
 
        kh_tracking_enabled = false;
-       Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_KEYHUNT_SCAN, autocvar_g_balance_keyhunt_delay_tracking);
+       Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_KEYHUNT_SCAN, autocvar_g_balance_keyhunt_delay_tracking);
        kh_Controller_SetThink(autocvar_g_balance_keyhunt_delay_tracking, kh_EnableTrackingDevice);
 }
 
@@ -1033,7 +1039,7 @@ float kh_HandleFrags(entity attacker, entity targ, float f)  // adds to the play
                        entity k;
                        float nk;
                        nk = 0;
-                       for(k = targ.kh_next; k != world; k = k.kh_next)
+                       for(k = targ.kh_next; k != NULL; k = k.kh_next)
                                ++nk;
                        kh_Scores_Event(attacker, targ.kh_next, "carrierfrag", -nk * autocvar_g_balance_keyhunt_score_collect, 0);
                }
@@ -1056,6 +1062,14 @@ void kh_Initialize()  // sets up th KH environment
                kh_teams = autocvar_g_keyhunt_teams;
        kh_teams = bound(2, kh_teams, 4);
 
+       int teams = 0;
+       if(kh_teams >= 1) teams |= BIT(0);
+       if(kh_teams >= 2) teams |= BIT(1);
+       if(kh_teams >= 3) teams |= BIT(2);
+       if(kh_teams >= 4) teams |= BIT(3);
+
+       kh_teams = teams; // now set it?
+
        // make a KH entity for controlling the game
        kh_controller = spawn();
        setthink(kh_controller, kh_Controller_Think);
@@ -1086,7 +1100,7 @@ void kh_finalize()
        // to be called before intermission
        kh_FinishRound();
        remove(kh_controller);
-       kh_controller = world;
+       kh_controller = NULL;
 }
 
 // legacy bot role