]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Rudimentary freezetag bot ai working.
authorPaul Scott <poogascott@gmail.com>
Wed, 25 May 2011 03:53:21 +0000 (13:53 +1000)
committerRudolf Polzer <divVerent@xonotic.org>
Mon, 20 Jun 2011 08:25:27 +0000 (10:25 +0200)
qcsrc/server/bot/havocbot/role_freezetag.qc
qcsrc/server/bot/havocbot/roles.qc

index bd9330eb3250ac85609c1c7406c4877804c63565..cc5332022e2094750692c577d537ca53e08b9ef5 100644 (file)
 void() havocbot_role_ft_freeing;
 void() havocbot_role_ft_offense;
 
-void havocbot_goalrating_kh(float ratingscale_team, float ratingscale_dropped, float ratingscale_enemy)
+void havocbot_goalrating_freeplayers(float ratingscale, vector org, float sradius)
 {
        local entity head;
-       for (head = kh_worldkeylist; head; head = head.kh_worldkeynext)
+       float distance;
+
+       FOR_EACH_PLAYER(head)
        {
-               if(head.owner == self)
-                       continue;
-               if(!kh_tracking_enabled)
+               if ((head != self) && (head.team == self.team) && (head.freezetag_frozen))
                {
-                       // if it's carried by our team we know about it
-                       // otherwise we have to see it to know about it
-                       if(!head.owner || head.team != self.team)
-                       {
-                               traceline(self.origin + self.view_ofs, head.origin, MOVE_NOMONSTERS, self);
-                               if (trace_fraction < 1 && trace_ent != head)
-                                       continue; // skip what I can't see
-                       }
+                       distance = vlen(head.origin - org);
+                       if (distance > sradius)
+                               continue;
+                       navigation_routerating(head, ratingscale, 2000);
                }
-               if(!head.owner)
-                       navigation_routerating(head, ratingscale_dropped * BOT_PICKUP_RATING_HIGH, 100000);
-               else if(head.team == self.team)
-                       navigation_routerating(head.owner, ratingscale_team * BOT_PICKUP_RATING_HIGH, 100000);
-               else
-                       navigation_routerating(head.owner, ratingscale_enemy * BOT_PICKUP_RATING_HIGH, 100000);
        }
-
-       havocbot_goalrating_items(1, self.origin, 10000);
 };
 
-void havocbot_role_kh_carrier()
+void havocbot_role_ft_offense()
 {
        if(self.deadflag != DEAD_NO)
                return;
 
-       if (!(self.kh_next))
-       {
-               dprint("changing role to freelancer\n");
-               self.havocbot_role = havocbot_role_kh_freelancer;
-               self.havocbot_role_timeout = 0;
-               return;
-       }
-
-       if (self.bot_strategytime < time)
-       {
-               self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
-               navigation_goalrating_start();
-
-               if(kh_Key_AllOwnedByWhichTeam() == self.team)
-                       havocbot_goalrating_kh(10, 0.1, 0.1); // bring home
-               else
-                       havocbot_goalrating_kh(4, 4, 1); // play defensively
-
-               navigation_goalrating_end();
-       }
-}
-
-void havocbot_role_kh_defense()
-{
-       if(self.deadflag != DEAD_NO)
-               return;
-
-       if (self.kh_next)
-       {
-               dprint("changing role to carrier\n");
-               self.havocbot_role = havocbot_role_kh_carrier;
-               self.havocbot_role_timeout = 0;
-               return;
-       }
-
        if (!self.havocbot_role_timeout)
                self.havocbot_role_timeout = time + random() * 10 + 20;
+
        if (time > self.havocbot_role_timeout)
        {
-               dprint("changing role to freelancer\n");
-               self.havocbot_role = havocbot_role_kh_freelancer;
+               dprint("changing role to freeing\n");
+               self.havocbot_role = havocbot_role_ft_freeing;
                self.havocbot_role_timeout = 0;
                return;
        }
 
-       if (self.bot_strategytime < time)
+       if (time > self.bot_strategytime)
        {
-               float key_owner_team;
                self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
-               navigation_goalrating_start();
-
-               key_owner_team = kh_Key_AllOwnedByWhichTeam();
-               if(key_owner_team == self.team)
-                       havocbot_goalrating_kh(10, 0.1, 0.1); // defend key carriers
-               else if(key_owner_team == -1)
-                       havocbot_goalrating_kh(4, 1, 0.1); // play defensively
-               else
-                       havocbot_goalrating_kh(0.1, 0.1, 10); // ATTACK ANYWAY
 
+               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_kh_offense()
+void havocbot_role_ft_freeing()
 {
        if(self.deadflag != DEAD_NO)
                return;
 
-       if (self.kh_next)
-       {
-               dprint("changing role to carrier\n");
-               self.havocbot_role = havocbot_role_kh_carrier;
-               self.havocbot_role_timeout = 0;
-               return;
-       }
-
        if (!self.havocbot_role_timeout)
                self.havocbot_role_timeout = time + random() * 10 + 20;
-       if (time > self.havocbot_role_timeout)
-       {
-               dprint("changing role to freelancer\n");
-               self.havocbot_role = havocbot_role_kh_freelancer;
-               self.havocbot_role_timeout = 0;
-               return;
-       }
 
-       if (self.bot_strategytime < time)
-       {
-               float key_owner_team;
-
-               self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
-               navigation_goalrating_start();
-
-               key_owner_team = kh_Key_AllOwnedByWhichTeam();
-               if(key_owner_team == self.team)
-                       havocbot_goalrating_kh(10, 0.1, 0.1); // defend anyway
-               else if(key_owner_team == -1)
-                       havocbot_goalrating_kh(0.1, 1, 4); // play offensively
-               else
-                       havocbot_goalrating_kh(0.1, 0.1, 10); // ATTACK! EMERGENCY!
-
-               navigation_goalrating_end();
-       }
-};
-
-void havocbot_role_kh_freelancer()
-{
-       if(self.deadflag != DEAD_NO)
-               return;
-
-       if (self.kh_next)
-       {
-               dprint("changing role to carrier\n");
-               self.havocbot_role = havocbot_role_kh_carrier;
-               self.havocbot_role_timeout = 0;
-               return;
-       }
-
-       if (!self.havocbot_role_timeout)
-               self.havocbot_role_timeout = time + random() * 10 + 10;
        if (time > self.havocbot_role_timeout)
        {
-               if (random() < 0.5)
-               {
-                       dprint("changing role to offense\n");
-                       self.havocbot_role = havocbot_role_kh_offense;
-               }
-               else
-               {
-                       dprint("changing role to defense\n");
-                       self.havocbot_role = havocbot_role_kh_defense;
-               }
+               dprint("changing role to offense\n");
+               self.havocbot_role = havocbot_role_ft_offense;
                self.havocbot_role_timeout = 0;
                return;
        }
 
-       if (self.bot_strategytime < time)
+       if (time > self.bot_strategytime)
        {
-               float key_owner_team;
-
                self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
-               navigation_goalrating_start();
-
-               key_owner_team = kh_Key_AllOwnedByWhichTeam();
-               if(key_owner_team == self.team)
-                       havocbot_goalrating_kh(10, 0.1, 0.1); // defend anyway
-               else if(key_owner_team == -1)
-                       havocbot_goalrating_kh(1, 10, 4); // prefer dropped keys
-               else
-                       havocbot_goalrating_kh(0.1, 0.1, 10); // ATTACK ANYWAY
 
+               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();
        }
 };
@@ -195,5 +81,8 @@ void havocbot_chooserole_ft()
        if(self.deadflag != DEAD_NO)
                return;
 
-       self.havocbot_role = havocbot_role_ft_offensive;
+       if (random() < 0.5)
+               self.havocbot_role = havocbot_role_ft_freeing;
+       else
+               self.havocbot_role = havocbot_role_ft_offense;
 };
index a428cf48553543cefb82aaece76ec71656a2436d..96c901f9e9f301821d7cca6cedf05871f65bf731 100644 (file)
@@ -168,6 +168,9 @@ void havocbot_goalrating_enemyplayers(float ratingscale, vector org, float sradi
                        if (distance < 100 || distance > sradius)
                                continue;
 
+                       if (head.freezetag_frozen)
+                               continue;
+
                        if(g_minstagib)
                        if(head.items & IT_STRENGTH)
                                continue;