]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mutators/gamemode_arena.qc
Fix this bug: If you open up a dialog/menu in game, and then leave focus of the Xonot...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / gamemode_arena.qc
index cc93dd3e4196e4d50bc4078f861d942576426bff..46b8faccc182bc60f5c8b997df036e77c0535196 100644 (file)
@@ -60,11 +60,11 @@ float Arena_CheckWinner()
 {
        entity e;
 
-       if(round_handler_GetTimeLeft() <= 0)
+       if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
        {
-               FOR_EACH_REALCLIENT(e)
-                       centerprint(e, "Round over, there's no winner");
-               bprint("Round over, there's no winner\n");
+               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
+               Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
+               round_handler_Init(5, autocvar_g_arena_warmup, autocvar_g_arena_round_timelimit);
                return 1;
        }
 
@@ -75,29 +75,30 @@ float Arena_CheckWinner()
        champion = world;
        FOR_EACH_CLIENT(e)
        {
-               if(e.spawned && e.classname == "player")
+               if(e.spawned && IS_PLAYER(e))
                        champion = e;
        }
 
        if(champion)
        {
-               FOR_EACH_REALCLIENT(e)
-                       centerprint(e, strcat("The Champion is ", champion.netname));
-               bprint("The Champion is ", champion.netname, "\n");
+               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_PLAYER_WIN, champion.netname);
+               Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_PLAYER_WIN, champion.netname);
                UpdateFrags(champion, +1);
        }
        else
        {
-               FOR_EACH_REALCLIENT(e)
-                       centerprint(e, "Round tied");
-               bprint("Round tied\n");
+               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
+               Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
        }
+       round_handler_Init(5, autocvar_g_arena_warmup, autocvar_g_arena_round_timelimit);
        return 1;
 }
 
 void Arena_AddChallengers()
 {
        entity e;
+       if(time < 2) // don't force players to spawn so early
+               return;
        e = self;
        while(numspawned < maxspawned && spawnqueue_first)
        {
@@ -117,25 +118,20 @@ void Arena_AddChallengers()
 float prev_numspawned;
 float Arena_CheckPlayers()
 {
-       entity e;
-
        Arena_AddChallengers();
 
        if(numspawned >= 2)
        {
-               if(prev_numspawned != -1)
-               {
-                       FOR_EACH_REALCLIENT(e)
-                               Send_CSQC_Centerprint_Generic_Expire(e, CPID_WAITING_PLAYERS);
-               }
+               if(prev_numspawned > 0)
+                       Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_PLAYERS);
                prev_numspawned = -1;
                return 1;
        }
 
        if(prev_numspawned != numspawned && numspawned == 1)
        {
-               FOR_EACH_REALCLIENT(e)
-                       Send_CSQC_Centerprint_Generic(e, CPID_WAITING_PLAYERS, "Waiting for players to join...", -1, 0);
+               if(maxspawned - numspawned > 0)
+                       Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_PLAYERS, maxspawned - numspawned);
                prev_numspawned = numspawned;
        }
 
@@ -173,14 +169,17 @@ MUTATOR_HOOKFUNCTION(arena_reset_map_players)
 
 MUTATOR_HOOKFUNCTION(arena_MakePlayerObserver)
 {
-       self.frags = FRAGS_PLAYER;
        if(self.version_mismatch)
        {
+               self.frags = FRAGS_SPECTATOR;
                Spawnqueue_Unmark(self);
                Spawnqueue_Remove(self);
        }
        else
+       {
+               self.frags = FRAGS_LMS_LOSER;
                Spawnqueue_Insert(self);
+       }
        return 1;
 }
 
@@ -207,18 +206,6 @@ MUTATOR_HOOKFUNCTION(arena_PlayerSpawn)
        return 1;
 }
 
-MUTATOR_HOOKFUNCTION(arena_PlayerPreThink)
-{
-       self.stat_respawn_time = 0;
-
-       // put dead players in the spawn queue
-       if(arena_roundbased)
-       if(self.deadflag && time - self.death_time >= 1.5)
-               PutClientInServer();
-
-       return 1;
-}
-
 MUTATOR_HOOKFUNCTION(arena_ForbidPlayerScore_Clear)
 {
        return 1;
@@ -227,23 +214,26 @@ MUTATOR_HOOKFUNCTION(arena_ForbidPlayerScore_Clear)
 MUTATOR_HOOKFUNCTION(arena_GiveFragsForKill)
 {
        if(arena_roundbased)
-               frag_score = 0;
+               frag_score = 0; // score will be given to the champion when the round ends
        return 1;
 }
 
 MUTATOR_HOOKFUNCTION(arena_PlayerDies)
 {
+       // put dead players in the spawn queue
+       if(arena_roundbased)
+               self.respawn_flags = (RESPAWN_FORCE | RESPAWN_SILENT);
+       else
+               self.respawn_flags = RESPAWN_SILENT;
        Spawnqueue_Unmark(self);
        return 1;
 }
 
 MUTATOR_HOOKFUNCTION(arena_SV_StartFrame)
 {
-       if(arena_roundbased) return 1;
-       if(time <= game_starttime) return 1;
        if(gameover) return 1;
-
-       Arena_AddChallengers();
+       if(time <= game_starttime || !arena_roundbased)
+               Arena_AddChallengers();
        return 1;
 }
 
@@ -252,7 +242,10 @@ void arena_Initialize()
        maxspawned = max(2, autocvar_g_arena_maxspawned);
        arena_roundbased = autocvar_g_arena_roundbased;
        if(arena_roundbased)
-               round_handler_Spawn(Arena_CheckPlayers, Arena_CheckWinner, Arena_RoundStart, 5, autocvar_g_arena_warmup, autocvar_g_arena_round_timelimit);
+       {
+               round_handler_Spawn(Arena_CheckPlayers, Arena_CheckWinner, Arena_RoundStart);
+               round_handler_Init(5, autocvar_g_arena_warmup, autocvar_g_arena_round_timelimit);
+       }
 }
 
 MUTATOR_DEFINITION(gamemode_arena)
@@ -263,7 +256,6 @@ MUTATOR_DEFINITION(gamemode_arena)
        MUTATOR_HOOK(PutClientInServer, arena_PutClientInServer, CBC_ORDER_ANY);
        MUTATOR_HOOK(ClientConnect, arena_ClientConnect, CBC_ORDER_ANY);
        MUTATOR_HOOK(PlayerSpawn, arena_PlayerSpawn, CBC_ORDER_ANY);
-       MUTATOR_HOOK(PlayerPreThink, arena_PlayerPreThink, CBC_ORDER_ANY);
        MUTATOR_HOOK(ForbidPlayerScore_Clear, arena_ForbidPlayerScore_Clear, CBC_ORDER_ANY);
        MUTATOR_HOOK(GiveFragsForKill, arena_GiveFragsForKill, CBC_ORDER_ANY);
        MUTATOR_HOOK(PlayerDies, arena_PlayerDies, CBC_ORDER_ANY);
@@ -278,7 +270,8 @@ MUTATOR_DEFINITION(gamemode_arena)
 
        MUTATOR_ONREMOVE
        {
-               error("This is a game type and it cannot be removed at runtime.");
+               print("This is a game type and it cannot be removed at runtime.");
+               return -1;
        }
 
        return 0;