]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Implemented basic keepaway bot AI.
authorPaul Scott <poogascott@gmail.com>
Sat, 4 Jun 2011 07:00:19 +0000 (17:00 +1000)
committerPaul Scott <poogascott@gmail.com>
Sat, 4 Jun 2011 07:00:19 +0000 (17:00 +1000)
qcsrc/server/bot/aim.qc
qcsrc/server/bot/havocbot/havocbot.qc
qcsrc/server/bot/havocbot/role_keepaway.qc [new file with mode: 0644]
qcsrc/server/bot/havocbot/roles.qc
qcsrc/server/mutators/gamemode_keepaway.qc

index 9ef109e2b585e3c76053c7b183fbc49da22543ff..b682044ec2b36c751b6eb96e433a0ddf9cd4089c 100644 (file)
@@ -113,6 +113,10 @@ float bot_shouldattack(entity e)
                if(e.freezetag_frozen)
                        return FALSE;
 
+       if (g_keepaway)
+               if (!e.ballcarried && !self.ballcarried)
+                       return FALSE;
+
        if(teams_matter)
        {
                if(e.team==0)
index dd111d9f00400f376eedd8ea6462ec90c3caaddd..5da945c90124d8d7262bdbd5830653860ad336d2 100644 (file)
@@ -2,6 +2,7 @@
 #include "role_ctf.qc"
 #include "role_onslaught.qc"
 #include "role_keyhunt.qc"
+#include "role_keepaway.qc"
 #include "roles.qc"
 
 void havocbot_ai()
diff --git a/qcsrc/server/bot/havocbot/role_keepaway.qc b/qcsrc/server/bot/havocbot/role_keepaway.qc
new file mode 100644 (file)
index 0000000..30d9649
--- /dev/null
@@ -0,0 +1,82 @@
+void() havocbot_role_ka_carrier;
+void() havocbot_role_ka_collector;
+void() havocbot_chooserole_ka;
+
+entity ka_ball;
+
+// Keepaway
+// If you don't have the ball, get it; if you do, kill people.
+
+void havocbot_goalrating_ball(float ratingscale, vector org)
+{
+       local float t, distance;
+       local entity ball_owner;
+       ball_owner = ka_ball.owner;
+
+       if (ball_owner == self)
+               return;
+
+       // If ball is carried by player then hunt them down.
+       if (ball_owner)
+       {
+               t = (self.health + self.armorvalue) / (ball_owner.health + ball_owner.armorvalue);
+               navigation_routerating(ball_owner, t * ratingscale, 2000);
+       }
+
+       // Ball has been dropped so collect.
+       navigation_routerating(ka_ball, ratingscale, 2000);
+};
+
+void havocbot_role_ka_carrier()
+{
+       if (self.deadflag != DEAD_NO)
+               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_waypoints(1, self.origin, 1000);
+               navigation_goalrating_end();
+       }
+
+       if (!self.ballcarried)
+       {
+               self.havocbot_role = havocbot_role_ka_collector;
+               self.bot_strategytime = 0;
+       }
+};
+
+void havocbot_role_ka_collector()
+{
+       if (self.deadflag != DEAD_NO)
+               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(1000, self.origin, 10000);
+               havocbot_goalrating_ball(20000, self.origin);
+               navigation_goalrating_end();
+       }
+
+       if (self.ballcarried)
+       {
+               self.havocbot_role = havocbot_role_ka_carrier;
+               self.bot_strategytime = 0;
+       }
+};
+
+void havocbot_chooserole_ka()
+{
+       if (self.ballcarried)
+               self.havocbot_role = havocbot_role_ka_carrier;
+       else
+               self.havocbot_role = havocbot_role_ka_collector;
+};
index 514c364ac723963e1617e17ee3bc5ac28287bbf6..6a6686003651ffd345a49fab270a94ee35f09324 100644 (file)
@@ -274,24 +274,6 @@ void havocbot_role_race()
        }
 };
 
-// Keepaway
-// If you don't have the ball, get it; if you do, kill people.
-void havocbot_role_ka()
-{
-       if(self.deadflag != DEAD_NO)
-               return;
-
-       if (self.bot_strategytime < time)
-       {
-               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_waypoints(1, self.origin, 1000);
-               navigation_goalrating_end();
-       }
-}
-
 void havocbot_chooserole_dm()
 {
        self.havocbot_role = havocbot_role_dm;
@@ -307,11 +289,6 @@ void havocbot_chooserole_dom()
        self.havocbot_role = havocbot_role_dom;
 };
 
-void havocbot_chooserole_ka()
-{
-       self.havocbot_role = havocbot_role_ka;
-}
-
 void havocbot_chooserole()
 {
        dprint("choosing a role...\n");
index 60c39d43410498bc752265a9d0d9e1f645da9ca2..440652a484798f1c8d684dcc963ac9372d1ad577 100644 (file)
@@ -4,6 +4,8 @@ void ka_RespawnBall(void);
 void ka_DropEvent(entity);
 void ka_TimeScoring(void);
 
+entity ka_ball;
+
 float ka_ballcarrier_waypointsprite_visible_for_player(entity);
 
 void ka_Initialize() // run at the start of a match, initiates game mode
@@ -50,6 +52,7 @@ void ka_SpawnBall() // loads various values for the ball, runs only once at star
        e.reset = ka_Reset;
        e.touch = ka_TouchEvent;
        e.owner = world;
+       ka_ball = e;
 
        InitializeEntity(e, ka_RespawnBall, INITPRIO_SETLOCATION); // is this the right priority? Neh, I have no idea.. Well-- it works! So. 
 }