]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mutators/gamemode_keyhunt.qc
Merge remote-tracking branch 'origin/master' into samual/notification_rewrite
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / gamemode_keyhunt.qc
index 4d76b26954e466cb53a2ffe3b6cd7983cc42756d..9bf9498c5c4fcc76646489f8ec186d4635e8e6cd 100644 (file)
@@ -32,18 +32,18 @@ float kh_no_radar_circles;
 .float siren_time;  //  time delay the siren
 //.float stuff_time;  //  time delay to stuffcmd a cvar
 
-float test[17] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
-//test[0] = status of dropped keys, test[1 - 16] = player #
+float kh_keystatus[17];
+//kh_keystatus[0] = status of dropped keys, kh_keystatus[1 - 16] = player #
 //replace 17 with cvar("maxplayers") or similar !!!!!!!!!
 //for(i = 0; i < maxplayers; ++i)
-//     test[i] = "0";
+//     kh_keystatus[i] = "0";
 
 float kh_Team_ByID(float t)
 {
-       if(t == 0) return COLOR_TEAM1;
-       if(t == 1) return COLOR_TEAM2;
-       if(t == 2) return COLOR_TEAM3;
-       if(t == 3) return COLOR_TEAM4;
+       if(t == 0) return FL_TEAM_1;
+       if(t == 1) return FL_TEAM_2;
+       if(t == 2) return FL_TEAM_3;
+       if(t == 3) return FL_TEAM_4;
        return 0;
 }
 
@@ -58,6 +58,7 @@ float kh_interferemsg_time, kh_interferemsg_team;
 .float kh_dropperteam;
 .entity kh_previous_owner;
 .float kh_previous_owner_playerid;
+.float kh_cp_duration;
 
 string kh_sound_capture = "kh/capture.wav";
 string kh_sound_destroy = "kh/destroy.wav";
@@ -121,7 +122,7 @@ void kh_update_state()
 
 
 var kh_Think_t kh_Controller_Thinkfunc;
-void kh_Controller_SetThink(float t, string msg, kh_Think_t func)  // runs occasionaly
+void kh_Controller_SetThink(float t, string msg, float centerprint_duration, kh_Think_t func)  // runs occasionaly
 {
        kh_Controller_Thinkfunc = func;
        kh_controller.cnt = ceil(t);
@@ -130,10 +131,17 @@ void kh_Controller_SetThink(float t, string msg, kh_Think_t func)  // runs occas
        if(msg == "")
                kh_Controller_Waitmsg = "";
        else
+       {
+               kh_controller.kh_cp_duration = centerprint_duration;
                kh_Controller_Waitmsg = strzone(msg);
+       }
        if(t == 0)
                kh_controller.nextthink = time; // force
 }
+void kh_Controller_SetThink_NoMsg(float t, kh_Think_t func)  // runs occasionaly
+{
+       kh_Controller_SetThink(t, "", 0, func);
+}
 
 void kh_Controller_Think()  // called a lot
 {
@@ -154,7 +162,7 @@ void kh_Controller_Think()  // called a lot
 
                        FOR_EACH_PLAYER(e)
                                if(clienttype(e) == CLIENTTYPE_REAL)
-                                       centerprint_atprio(e, CENTERPRIO_SPAM, s);
+                                       Send_CSQC_Centerprint_Generic(e, CPID_KH_MSG, s, self.kh_cp_duration, 0);
                }
                self.cnt -= 1;
        }
@@ -334,7 +342,7 @@ void kh_Key_AssignTo(entity key, entity player)  // runs every time a key is pic
                        key.kh_next.kh_prev = key;
 
                float i;
-               i = test[key.owner.playerid];
+               i = kh_keystatus[key.owner.playerid];
                        if(key.netname == "^1red key")
                                i += 1;
                        if(key.netname == "^4blue key")
@@ -343,7 +351,7 @@ void kh_Key_AssignTo(entity key, entity player)  // runs every time a key is pic
                                i += 4;
                        if(key.netname == "^6pink key")
                                i += 8;
-               test[key.owner.playerid] = i;
+               kh_keystatus[key.owner.playerid] = i;
 
                kh_Key_Attach(key);
 
@@ -353,13 +361,13 @@ void kh_Key_AssignTo(entity key, entity player)  // runs every time a key is pic
                        WaypointSprite_AttachCarrier("", player, RADARICON_FLAGCARRIER, colormapPaletteColor(player.team - 1, 0));
                        player.waypointsprite_attachedforcarrier.waypointsprite_visible_for_player = kh_KeyCarrier_waypointsprite_visible_for_player;
                        WaypointSprite_UpdateRule(player.waypointsprite_attachedforcarrier, player.team, SPRITERULE_TEAMPLAY);
-                       if(player.team == COLOR_TEAM1)
+                       if(player.team == FL_TEAM_1)
                                WaypointSprite_UpdateSprites(player.waypointsprite_attachedforcarrier, "keycarrier-red", "keycarrier-friend", "keycarrier-red");
-                       else if(player.team == COLOR_TEAM2)
+                       else if(player.team == FL_TEAM_2)
                                WaypointSprite_UpdateSprites(player.waypointsprite_attachedforcarrier, "keycarrier-blue", "keycarrier-friend", "keycarrier-blue");
-                       else if(player.team == COLOR_TEAM3)
+                       else if(player.team == FL_TEAM_3)
                                WaypointSprite_UpdateSprites(player.waypointsprite_attachedforcarrier, "keycarrier-yellow", "keycarrier-friend", "keycarrier-yellow");
-                       else if(player.team == COLOR_TEAM4)
+                       else if(player.team == FL_TEAM_4)
                                WaypointSprite_UpdateSprites(player.waypointsprite_attachedforcarrier, "keycarrier-pink", "keycarrier-friend", "keycarrier-pink");
                        if(!kh_no_radar_circles)
                                WaypointSprite_Ping(player.waypointsprite_attachedforcarrier);
@@ -404,6 +412,13 @@ void kh_Key_Damage(entity inflictor, entity attacker, float damage, float deatht
 {
        if(self.owner)
                return;
+       if(ITEM_DAMAGE_NEEDKILL(deathtype))
+       {
+               // touching lava, or hurt trigger
+               // what shall we do?
+               // immediately return is bad
+               // maybe start a shorter countdown?
+       }
        if(vlen(force) <= 0)
                return;
        if(time > self.pushltime)
@@ -413,7 +428,7 @@ void kh_Key_Damage(entity inflictor, entity attacker, float damage, float deatht
 
 void kh_Key_Collect(entity key, entity player)  //a player picks up a dropped key
 {
-       sound(player, CHAN_AUTO, kh_sound_collect, VOL_BASE, ATTN_NORM);
+       sound(player, CH_TRIGGER, kh_sound_collect, VOL_BASE, ATTN_NORM);
 
        if(key.kh_dropperteam != player.team)
        {
@@ -433,6 +448,15 @@ void kh_Key_Touch()  // runs many, many times when a key has been dropped and ca
 
        if(self.owner) // already carried
                return;
+
+       if(ITEM_TOUCH_NEEDKILL())
+       {
+               // touching sky, or nodrop
+               // what shall we do?
+               // immediately return is bad
+               // maybe start a shorter countdown?
+       }
+
        if(other.classname != "player")
                return;
        if(other.deadflag != DEAD_NO)
@@ -486,7 +510,7 @@ void kh_FinishRound()  // runs when a team captures the keys
                kh_Key_Remove(key);
        kh_no_radar_circles = FALSE;
 
-       kh_Controller_SetThink(autocvar_g_balance_keyhunt_delay_round, "Round starts in ", kh_StartRound);
+       kh_Controller_SetThink(autocvar_g_balance_keyhunt_delay_round, "Round starts in ", 1, kh_StartRound);
 }
 
 void kh_WinnerTeam(float teem)  // runs when a team wins
@@ -517,10 +541,12 @@ void kh_WinnerTeam(float teem)  // runs when a team wins
                        bprint(key.owner.netname);
                        first = FALSE;
                }
-       bprint("^7 captured the keys for the ", ColoredTeamName(teem), "\n");
+       bprint("^7 captured the keys for the ", Team_ColoredFullName(teem), "\n");
 
        first = TRUE;
        midpoint = '0 0 0';
+       firstorigin = '0 0 0';
+       lastorigin = '0 0 0';
        FOR_EACH_KH_KEY(key)
        {
                vector thisorigin;
@@ -541,7 +567,7 @@ void kh_WinnerTeam(float teem)  // runs when a team wins
                te_lightning2(world, lastorigin, firstorigin);
        }
        midpoint = midpoint * (1 / kh_teams);
-       te_customflash(midpoint, 1000, 1, TeamColor(teem) * 0.5 + '0.5 0.5 0.5');  // make the color >=0.5 in each component
+       te_customflash(midpoint, 1000, 1, Team_ColorRGB(teem) * 0.5 + '0.5 0.5 0.5');  // make the color >=0.5 in each component
 
        play2all(kh_sound_capture);
        kh_FinishRound();
@@ -570,7 +596,7 @@ void kh_LoserTeam(float teem, entity lostkey)  // runs when a player pushes a fl
                kh_Scores_Event(attacker, world, "push", autocvar_g_balance_keyhunt_score_push, 0);
                PlayerScore_Add(attacker, SP_KH_PUSHES, 1);
                centerprint(attacker, "Your push is the best!");
-               bprint("The ", ColoredTeamName(teem), "^7 could not take care of the ", lostkey.netname, "^7 when ", attacker.netname, "^7 came\n");
+               bprint("The ", Team_ColoredFullName(teem), "^7 could not take care of the ", lostkey.netname, "^7 when ", attacker.netname, "^7 came\n");
        }
        else
        {
@@ -630,7 +656,7 @@ void kh_LoserTeam(float teem, entity lostkey)  // runs when a player pushes a fl
                        --j;
                }
 
-               bprint("The ", ColoredTeamName(teem), "^7 could not take care of the ", lostkey.netname, "\n");
+               bprint("The ", Team_ColoredFullName(teem), "^7 could not take care of the ", lostkey.netname, "\n");
        }
        play2all(kh_sound_destroy);
        te_tarexplosion(lostkey.origin);
@@ -664,7 +690,7 @@ void kh_Key_Think()  // runs all the time
        {
                if(self.siren_time < time)
                {
-                       sound(self.owner, CHAN_AUTO, kh_sound_alarm, VOL_BASE, ATTN_NORM);  // play a simple alarm
+                       sound(self.owner, CH_TRIGGER, kh_sound_alarm, VOL_BASE, ATTN_NORM);  // play a simple alarm
                        self.siren_time = time + 2.5;  // repeat every 2.5 seconds
                }
 
@@ -685,11 +711,11 @@ void kh_Key_Think()  // runs all the time
                {
                        if(head.team == kh_interferemsg_team)
                                if(head.kh_next)
-                                       centerprint(head, "All keys are in your team's hands!\n\nMeet the other key carriers ^1NOW^7!");
+                                       Send_CSQC_Centerprint_Generic(head, CPID_KH_MSG, "All keys are in your team's hands!\n\nMeet the other key carriers ^1NOW^7!", 0, 0);
                                else
-                                       centerprint(head, "All keys are in your team's hands!\n\nHelp the key carriers to meet!");
+                                       Send_CSQC_Centerprint_Generic(head, CPID_KH_MSG, "All keys are in your team's hands!\n\nHelp the key carriers to meet!", 0, 0);
                        else
-                               centerprint(head, strcat("All keys are in the ", ColoredTeamName(kh_interferemsg_team), "^7's hands!\n\nInterfere ^1NOW^7!"));
+                               Send_CSQC_Centerprint_Generic(head, CPID_KH_MSG, strcat("All keys are in the ", Team_ColoredFullName(kh_interferemsg_team), "^7's hands!\n\nInterfere ^1NOW^7!"), 0, 0);
                }
        }
 
@@ -722,21 +748,21 @@ void kh_Key_Spawn(entity initial_owner, float angle, float i)  // runs every tim
        key.kh_dropperteam = 0;
        key.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
        setsize(key, KH_KEY_MIN, KH_KEY_MAX);
-       key.colormod = TeamColor(initial_owner.team) * KH_KEY_BRIGHTNESS;
+       key.colormod = Team_ColorRGB(initial_owner.team) * KH_KEY_BRIGHTNESS;
        key.reset = key_reset;
 
        switch(initial_owner.team)
        {
-               case COLOR_TEAM1:
+               case FL_TEAM_1:
                        key.netname = "^1red key";
                        break;
-               case COLOR_TEAM2:
+               case FL_TEAM_2:
                        key.netname = "^4blue key";
                        break;
-               case COLOR_TEAM3:
+               case FL_TEAM_3:
                        key.netname = "^3yellow key";
                        break;
-               case COLOR_TEAM4:
+               case FL_TEAM_4:
                        key.netname = "^6pink key";
                        break;
                default:
@@ -799,7 +825,7 @@ void kh_Key_DropOne(entity key)
        key.pushltime = time + autocvar_g_balance_keyhunt_protecttime;
        key.kh_dropperteam = key.team;
 
-       sound(player, CHAN_AUTO, kh_sound_drop, VOL_BASE, ATTN_NORM);
+       sound(player, CH_TRIGGER, kh_sound_drop, VOL_BASE, ATTN_NORM);
 }
 
 void kh_Key_DropAll(entity player, float suicide) // runs whenever a player dies
@@ -825,7 +851,7 @@ void kh_Key_DropAll(entity player, float suicide) // runs whenever a player dies
                        if(suicide)
                                key.kh_dropperteam = player.team;
                }
-               sound(player, CHAN_AUTO, kh_sound_drop, VOL_BASE, ATTN_NORM);
+               sound(player, CH_TRIGGER, kh_sound_drop, VOL_BASE, ATTN_NORM);
        }
 }
 
@@ -850,7 +876,7 @@ string kh_CheckEnoughPlayers()  // checks enough player are present, runs after
                {
                        if(result != "")
                                result = strcat(result, ", ");
-                       result = strcat(result, ColoredTeamName(teem));
+                       result = strcat(result, Team_ColoredFullName(teem));
                }
        }
        return result;
@@ -862,15 +888,15 @@ void kh_WaitForPlayers()  // delay start of the round until enough players are p
 
        if(time < game_starttime)
        {
-               kh_Controller_SetThink(game_starttime - time + 0.1, "", kh_WaitForPlayers);
+               kh_Controller_SetThink_NoMsg(game_starttime - time + 0.1, kh_WaitForPlayers);
                return;
        }
 
        teams_missing = kh_CheckEnoughPlayers();
        if(teams_missing == "")
-               kh_Controller_SetThink(autocvar_g_balance_keyhunt_delay_round, "Round starts in ", kh_StartRound);
+               kh_Controller_SetThink(autocvar_g_balance_keyhunt_delay_round, "Round starts in ", 1, kh_StartRound);
        else
-               kh_Controller_SetThink(1, strcat("Waiting for players to join...\n\nNeed active players for: ", teams_missing), kh_WaitForPlayers);
+               kh_Controller_SetThink(1, strcat("Waiting for players to join...\n\nNeed active players for: ", teams_missing), -1, kh_WaitForPlayers);
 }
 
 void kh_EnableTrackingDevice()  // runs after each round
@@ -879,7 +905,7 @@ void kh_EnableTrackingDevice()  // runs after each round
 
        FOR_EACH_PLAYER(player)
                if(clienttype(player) == CLIENTTYPE_REAL)
-                       centerprint_expire(player, CENTERPRIO_SPAM);
+                       Send_CSQC_Centerprint_Generic_Expire(player, CPID_KH_MSG);
 
        kh_tracking_enabled = TRUE;
 }
@@ -892,26 +918,26 @@ void kh_StartRound()  // runs at the start of each round
 
        if(time < game_starttime)
        {
-               kh_Controller_SetThink(game_starttime - time + 0.1, "", kh_WaitForPlayers);
+               kh_Controller_SetThink_NoMsg(game_starttime - time + 0.1, kh_WaitForPlayers);
                return;
        }
 
        teams_missing = kh_CheckEnoughPlayers();
        if(teams_missing != "")
        {
-               kh_Controller_SetThink(1, strcat("Waiting for players to join...\n\nNeed active players for: ", teams_missing), kh_WaitForPlayers);
+               kh_Controller_SetThink(1, strcat("Waiting for players to join...\n\nNeed active players for: ", teams_missing), -1, kh_WaitForPlayers);
                return;
        }
 
        FOR_EACH_PLAYER(player)
                if(clienttype(player) == CLIENTTYPE_REAL)
-                       centerprint_expire(player, CENTERPRIO_SPAM);
+                       Send_CSQC_Centerprint_Generic_Expire(player, CPID_KH_MSG);
 
        for(i = 0; i < kh_teams; ++i)
        {
                teem = kh_Team_ByID(i);
                players = 0;
-               entity my_player;
+               entity my_player = world;
                FOR_EACH_PLAYER(player)
                        if(player.deadflag == DEAD_NO)
                                if(!player.BUTTON_CHAT)
@@ -925,7 +951,7 @@ void kh_StartRound()  // runs at the start of each round
        }
 
        kh_tracking_enabled = FALSE;
-       kh_Controller_SetThink(autocvar_g_balance_keyhunt_delay_tracking, "Scanning frequency range...", kh_EnableTrackingDevice);
+       kh_Controller_SetThink(autocvar_g_balance_keyhunt_delay_tracking, "Scanning frequency range...", -1, kh_EnableTrackingDevice);
 }
 
 float kh_HandleFrags(entity attacker, entity targ, float f)  // adds to the player score
@@ -977,7 +1003,7 @@ void kh_Initialize()  // sets up th KH environment
        // make a KH entity for controlling the game
        kh_controller = spawn();
        kh_controller.think = kh_Controller_Think;
-       kh_Controller_SetThink(0, "", kh_WaitForPlayers);
+       kh_Controller_SetThink_NoMsg(0, kh_WaitForPlayers);
 
        setmodel(kh_controller, "models/keyhunt/key.md3");
        kh_key_dropped = kh_controller.modelindex;
@@ -1082,13 +1108,11 @@ MUTATOR_DEFINITION(gamemode_keyhunt)
        {
                if(time > 1) // game loads at time 1
                        error("This is a game type and it cannot be added at runtime.");
-               g_keyhunt = 1;
                kh_Initialize();
        }
 
        MUTATOR_ONREMOVE
        {
-               g_keyhunt = 0;
                error("This is a game type and it cannot be removed at runtime.");
        }