]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mutators/gamemode_freezetag.qc
Merge branch 'master' of git://de.git.xonotic.org/xonotic/xonotic-data.pk3dir
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / gamemode_freezetag.qc
index fa5a365ba48316b07c96ed3cdfc6b53619b3a2bb..c43a398754c34b0e513e60f189423e2a12f78406 100644 (file)
@@ -22,12 +22,11 @@ void freezetag_CheckWinner()
                return; // we still have active players on two or more teams, nobody won yet
 
        entity e, winner;
-       string teamname;
        winner = world;
 
        FOR_EACH_PLAYER(e)
        {
-               if(e.freezetag_frozen == 0 && e.classname == "player" && e.health >= 1) // here's one player from the winning team... good
+               if(e.freezetag_frozen == 0 && e.health >= 1) // here's one player from the winning team... good
                {
                        winner = e;
                        break; // break, we found the winner
@@ -36,18 +35,8 @@ void freezetag_CheckWinner()
 
        if(winner != world) // just in case a winner wasn't found
        {
-               if(winner.team == COLOR_TEAM1)
-                       teamname = "^1Red Team";
-               else if(winner.team == COLOR_TEAM2)
-                       teamname = "^4Blue Team";
-               else if(winner.team == COLOR_TEAM3)
-                       teamname = "^3Yellow Team";
-               else
-                       teamname = "^6Pink Team";
-               FOR_EACH_PLAYER(e) {
-                       centerprint(e, strcat(teamname, "^5 wins the round, all other teams were frozen.\n"));
-               }
-               bprint(teamname, "^5 wins the round since all the other teams were frozen.\n");
+               Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner.team, CENTER_FREEZETAG_ROUND_WIN_));
+               Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner.team, INFO_FREEZETAG_ROUND_WIN_));
                TeamScore_AddToTeam(winner.team, ST_SCORE, +1);
        }
 
@@ -129,17 +118,126 @@ void freezetag_Unfreeze(entity attacker)
                WaypointSprite_Kill(self.waypointsprite_attached);
 }
 
+
+// ================
+// Bot player logic
+// ================
+
+void() havocbot_role_ft_freeing;
+void() havocbot_role_ft_offense;
+
+void havocbot_goalrating_freeplayers(float ratingscale, vector org, float sradius)
+{
+       entity head;
+       float distance;
+
+       FOR_EACH_PLAYER(head)
+       {
+               if ((head != self) && (head.team == self.team))
+               {
+                       if (head.freezetag_frozen)
+                       {
+                               distance = vlen(head.origin - org);
+                               if (distance > sradius)
+                                       continue;
+                               navigation_routerating(head, ratingscale, 2000);
+                       }
+                       else
+                       {
+                               // If teamate is not frozen still seek them out as fight better
+                               // in a group.
+                               navigation_routerating(head, ratingscale/3, 2000);
+                       }
+               }
+       }
+}
+
+void havocbot_role_ft_offense()
+{
+       entity head;
+       float unfrozen;
+
+       if(self.deadflag != DEAD_NO)
+               return;
+
+       if (!self.havocbot_role_timeout)
+               self.havocbot_role_timeout = time + random() * 10 + 20;
+
+       // Count how many players on team are unfrozen.
+       unfrozen = 0;
+       FOR_EACH_PLAYER(head)
+       {
+               if ((head.team == self.team) && (!head.freezetag_frozen))
+                       unfrozen++;
+       }
+
+       // If only one left on team or if role has timed out then start trying to free players.
+       if (((unfrozen == 0) && (!self.freezetag_frozen)) || (time > self.havocbot_role_timeout))
+       {
+               dprint("changing role to freeing\n");
+               self.havocbot_role = havocbot_role_ft_freeing;
+               self.havocbot_role_timeout = 0;
+               return;
+       }
+
+       if (time > self.bot_strategytime)
+       {
+               self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
+
+               navigation_goalrating_start();
+               havocbot_goalrating_items(10000, self.origin, 10000);
+               havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
+               havocbot_goalrating_freeplayers(9000, self.origin, 10000);
+               //havocbot_goalrating_waypoints(1, self.origin, 1000);
+               navigation_goalrating_end();
+       }
+}
+
+void havocbot_role_ft_freeing()
+{
+       if(self.deadflag != DEAD_NO)
+               return;
+
+       if (!self.havocbot_role_timeout)
+               self.havocbot_role_timeout = time + random() * 10 + 20;
+
+       if (time > self.havocbot_role_timeout)
+       {
+               dprint("changing role to offense\n");
+               self.havocbot_role = havocbot_role_ft_offense;
+               self.havocbot_role_timeout = 0;
+               return;
+       }
+
+       if (time > self.bot_strategytime)
+       {
+               self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
+
+               navigation_goalrating_start();
+               havocbot_goalrating_items(8000, self.origin, 10000);
+               havocbot_goalrating_enemyplayers(10000, self.origin, 10000);
+               havocbot_goalrating_freeplayers(20000, self.origin, 10000);
+               //havocbot_goalrating_waypoints(1, self.origin, 1000);
+               navigation_goalrating_end();
+       }
+}
+
+
+// ==============
+// Hook Functions
+// ==============
+
 MUTATOR_HOOKFUNCTION(freezetag_RemovePlayer)
 {
-       if(self.freezetag_frozen == 0)
+       if(self.freezetag_frozen == 0 && self.health >= 1)
        {
-               if(self.team == COLOR_TEAM1)
+               if(self.team == NUM_TEAM_1)
                        --redalive;
-               else if(self.team == COLOR_TEAM2)
+               else if(self.team == NUM_TEAM_2)
                        --bluealive;
-               else if(self.team == COLOR_TEAM3)
+               else if(self.team == NUM_TEAM_3)
                        --yellowalive;
-               else if(self.team == COLOR_TEAM4)
+               else if(self.team == NUM_TEAM_4)
                        --pinkalive;
                --totalalive;
        }
@@ -156,33 +254,32 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerDies)
 {
        if(self.freezetag_frozen == 0)
        {
-               if(self.team == COLOR_TEAM1)
+               if(self.team == NUM_TEAM_1)
                        --redalive;
-               else if(self.team == COLOR_TEAM2)
+               else if(self.team == NUM_TEAM_2)
                        --bluealive;
-               else if(self.team == COLOR_TEAM3)
+               else if(self.team == NUM_TEAM_3)
                        --yellowalive;
-               else if(self.team == COLOR_TEAM4)
+               else if(self.team == NUM_TEAM_4)
                        --pinkalive;
                --totalalive;
 
-        freezetag_Freeze(frag_attacker);
+               freezetag_Freeze(frag_attacker);
        }
 
-    if(frag_attacker.classname == STR_PLAYER)
-        centerprint(frag_attacker, strcat("^2You froze ^7", frag_target.netname, ".\n"));
-
        if(frag_attacker == frag_target || frag_attacker == world)
        {
-        if(frag_target.classname == STR_PLAYER)
-            centerprint(frag_target, "^1You froze yourself.\n");
-               bprint("^7", frag_target.netname, "^1 froze himself.\n");
+               if(frag_target.classname == STR_PLAYER)
+                       Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_SELF);
+               Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_SELF, frag_target.netname);
        }
        else
        {
-        if(frag_target.classname == STR_PLAYER)
-            centerprint(frag_target, strcat("^1You were frozen by ^7", frag_attacker.netname, ".\n"));
-               bprint("^7", frag_target.netname, "^1 was frozen by ^7", frag_attacker.netname, ".\n");
+               if(frag_target.classname == STR_PLAYER)
+                       Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_FROZEN, frag_attacker.netname);
+               if(frag_attacker.classname == STR_PLAYER)
+                       Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_FREEZETAG_FREEZE, frag_target.netname);
+               Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_FREEZE, frag_target.netname, frag_attacker.netname);
        }
 
        frag_target.health = 1; // "respawn" the player :P
@@ -194,7 +291,7 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerDies)
 
 MUTATOR_HOOKFUNCTION(freezetag_PlayerSpawn)
 {
-    freezetag_Unfreeze(world); // start by making sure that all ice blocks are removed
+       freezetag_Unfreeze(world); // start by making sure that all ice blocks are removed
 
        if(total_players == 1 && time > game_starttime) // only one player active on server, start a new match immediately
        if(!next_round && warmup && (time < warmup - autocvar_g_freezetag_warmup || time > warmup)) // not awaiting next round
@@ -204,7 +301,7 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerSpawn)
        }
        if(warmup && time > warmup) // spawn too late, freeze player
        {
-               centerprint(self, "^1You spawned after the round started, you'll spawn as frozen.\n");
+               Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_SPAWN_LATE);
                freezetag_Freeze(world);
        }
 
@@ -268,15 +365,9 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink)
                                }
                        }
 
-                       if(n > 1)
-                               centerprint(self, strcat("^5You were revived by ^7", o.netname, "^5 et al.\n"));
-                       else
-                               centerprint(self, strcat("^5You were revived by ^7", o.netname, "^5.\n"));
-                       centerprint(o, strcat("^5You revived ^7", self.netname, "^5.\n"));
-                       if(n > 1)
-                               bprint("^7", o.netname, "^5 et al revived ^7", self.netname, "^5.\n");
-                       else
-                               bprint("^7", o.netname, "^5 revived ^7", self.netname, "^5.\n");
+                       Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
+                       Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
+                       Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVE, self.netname, o.netname);
                }
 
                // now find EVERY teammate within reviving radius, set their revive_progress values correct
@@ -335,6 +426,19 @@ MUTATOR_HOOKFUNCTION(freezetag_ForbidThrowCurrentWeapon)
        return 0;
 }
 
+MUTATOR_HOOKFUNCTION(freezetag_BotRoles)
+{
+       if not(self.deadflag)
+       {
+               if (random() < 0.5)
+                       self.havocbot_role = havocbot_role_ft_freeing;
+               else
+                       self.havocbot_role = havocbot_role_ft_offense;
+       }
+       
+       return TRUE;
+}
+
 MUTATOR_DEFINITION(gamemode_freezetag)
 {
        MUTATOR_HOOK(MakePlayerObserver, freezetag_RemovePlayer, CBC_ORDER_ANY);
@@ -346,19 +450,26 @@ MUTATOR_DEFINITION(gamemode_freezetag)
        MUTATOR_HOOK(PlayerPhysics, freezetag_PlayerPhysics, CBC_ORDER_FIRST);
        MUTATOR_HOOK(PlayerDamage_Calculate, freezetag_PlayerDamage_Calculate, CBC_ORDER_ANY);
        MUTATOR_HOOK(ForbidThrowCurrentWeapon, freezetag_ForbidThrowCurrentWeapon, CBC_ORDER_FIRST); //first, last or any? dunno.
+       MUTATOR_HOOK(HavocBot_ChooseRule, freezetag_BotRoles, CBC_ORDER_ANY);
 
        MUTATOR_ONADD
        {
                if(time > 1) // game loads at time 1
                        error("This is a game type and it cannot be added at runtime.");
-               g_freezetag = 1;
                freezetag_Initialize();
        }
 
+       MUTATOR_ONROLLBACK_OR_REMOVE
+       {
+               // we actually cannot roll back freezetag_Initialize here
+               // BUT: we don't need to! If this gets called, adding always
+               // succeeds.
+       }
+
        MUTATOR_ONREMOVE
        {
-               g_freezetag = 0;
-               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;