]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/havocbot/role_ctf.qc
Merge remote-tracking branch 'origin/master' into samual/mutator_ctf
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / havocbot / role_ctf.qc
index 0ec0abb3ce5c1427d7fb8140928bd65b75cb943a..0946f4342582fe7d974db23fbca2fef2579b7fbd 100644 (file)
@@ -23,7 +23,7 @@ void(float ratingscale, vector org, float sradius) havocbot_goalrating_enemyplay
 .float havocbot_cantfindflag;
 .float havocbot_role_timeout;
 .entity ctf_worldflagnext;
-.entity basewaypoint;
+.entity bot_basewaypoint;
 
 entity ctf_worldflaglist;
 vector havocbot_ctf_middlepoint;
@@ -40,7 +40,7 @@ entity havocbot_ctf_find_flag(entity bot)
                f = f.ctf_worldflagnext;
        }
        return world;
-};
+}
 
 entity havocbot_ctf_find_enemy_flag(entity bot)
 {
@@ -53,14 +53,14 @@ entity havocbot_ctf_find_enemy_flag(entity bot)
                f = f.ctf_worldflagnext;
        }
        return world;
-};
+}
 
 float havocbot_ctf_teamcount(entity bot, vector org, float radius)
 {
-       if not(teams_matter)
+       if not(teamplay)
                return 0;
 
-       float c;
+       float c = 0;
        entity head;
 
        FOR_EACH_PLAYER(head)
@@ -73,11 +73,11 @@ float havocbot_ctf_teamcount(entity bot, vector org, float radius)
        }
 
        return c;
-};
+}
 
 void havocbot_goalrating_ctf_ourflag(float ratingscale)
 {
-       local entity head;
+       entity head;
        head = ctf_worldflaglist;
        while (head)
        {
@@ -87,11 +87,11 @@ void havocbot_goalrating_ctf_ourflag(float ratingscale)
        }
        if (head)
                navigation_routerating(head, ratingscale, 10000);
-};
+}
 
 void havocbot_goalrating_ctf_ourbase(float ratingscale)
 {
-       local entity head;
+       entity head;
        head = ctf_worldflaglist;
        while (head)
        {
@@ -102,12 +102,12 @@ void havocbot_goalrating_ctf_ourbase(float ratingscale)
        if not(head)
                return;
 
-       navigation_routerating(head.basewaypoint, ratingscale, 10000);
-};
+       navigation_routerating(head.bot_basewaypoint, ratingscale, 10000);
+}
 
 void havocbot_goalrating_ctf_enemyflag(float ratingscale)
 {
-       local entity head;
+       entity head;
        head = ctf_worldflaglist;
        while (head)
        {
@@ -117,7 +117,7 @@ void havocbot_goalrating_ctf_enemyflag(float ratingscale)
        }
        if (head)
                navigation_routerating(head, ratingscale, 10000);
-};
+}
 
 void havocbot_goalrating_ctf_enemybase(float ratingscale)
 {
@@ -127,36 +127,37 @@ void havocbot_goalrating_ctf_enemybase(float ratingscale)
                return;
        }
 
-       local entity head;
+       entity head;
 
        head = havocbot_ctf_find_enemy_flag(self);
 
        if not(head)
                return;
 
-       navigation_routerating(head.basewaypoint, ratingscale, 10000);
-};
+       navigation_routerating(head.bot_basewaypoint, ratingscale, 10000);
+}
 
 void havocbot_goalrating_ctf_ourstolenflag(float ratingscale)
 {
-       local entity mf;
+       entity mf;
 
        mf = havocbot_ctf_find_flag(self);
 
-       if(mf.cnt == FLAG_BASE)
+       if(mf.ctf_status == FLAG_BASE)
                return;
 
-       navigation_routerating(mf, ratingscale, 10000);
-};
+       if(mf.tag_entity)
+               navigation_routerating(mf.tag_entity, ratingscale, 10000);
+}
 
 void havocbot_goalrating_ctf_droppedflags(float ratingscale, vector org, float radius)
 {
-       local entity head;
+       entity head;
        head = ctf_worldflaglist;
        while (head)
        {
                // flag is out in the field
-               if(head.cnt != FLAG_BASE)
+               if(head.ctf_status != FLAG_BASE)
                if(head.tag_entity==world)      // dropped
                {
                        if(radius)
@@ -170,12 +171,12 @@ void havocbot_goalrating_ctf_droppedflags(float ratingscale, vector org, float r
 
                head = head.ctf_worldflagnext;
        }
-};
+}
 
 void havocbot_goalrating_ctf_carrieritems(float ratingscale, vector org, float sradius)
 {
-       local entity head;
-       local float t;
+       entity head;
+       float t;
        head = findchainfloat(bot_pickup, TRUE);
        while (head)
        {
@@ -191,7 +192,7 @@ void havocbot_goalrating_ctf_carrieritems(float ratingscale, vector org, float s
                }
                head = head.chain;
        }
-};
+}
 
 void havocbot_role_ctf_setrole(entity bot, float role)
 {
@@ -203,6 +204,7 @@ void havocbot_role_ctf_setrole(entity bot, float role)
                        bot.havocbot_role = havocbot_role_ctf_carrier;
                        bot.havocbot_role_timeout = 0;
                        bot.havocbot_cantfindflag = time + 10;
+                       bot.bot_strategytime = 0;
                        break;
                case HAVOCBOT_CTF_ROLE_DEFENSE:
                        dprint("defense");
@@ -224,16 +226,18 @@ void havocbot_role_ctf_setrole(entity bot, float role)
                        bot.havocbot_previous_role = bot.havocbot_role;
                        bot.havocbot_role = havocbot_role_ctf_retriever;
                        bot.havocbot_role_timeout = time + 10;
+                       bot.bot_strategytime = 0;
                        break;
                case HAVOCBOT_CTF_ROLE_ESCORT:
                        dprint("escort");
                        bot.havocbot_previous_role = bot.havocbot_role;
                        bot.havocbot_role = havocbot_role_ctf_escort;
                        bot.havocbot_role_timeout = time + 30;
+                       bot.bot_strategytime = 0;
                        break;
        }
        dprint("\n");
-};
+}
 
 void havocbot_role_ctf_carrier()
 {
@@ -271,11 +275,11 @@ void havocbot_role_ctf_carrier()
                        return;
                }
        }
-};
+}
 
 void havocbot_role_ctf_escort()
 {
-       local entity mf, ef;
+       entity mf, ef;
 
        if(self.deadflag != DEAD_NO)
        {
@@ -291,7 +295,7 @@ void havocbot_role_ctf_escort()
 
        // If enemy flag is back on the base switch to previous role
        ef = havocbot_ctf_find_enemy_flag(self);
-       if(ef.cnt==FLAG_BASE)
+       if(ef.ctf_status==FLAG_BASE)
        {
                self.havocbot_role = self.havocbot_previous_role;
                self.havocbot_role_timeout = 0;
@@ -300,7 +304,7 @@ void havocbot_role_ctf_escort()
 
        // If the flag carrier reached the base switch to defense
        mf = havocbot_ctf_find_flag(self);
-       if(mf.cnt!=FLAG_BASE)
+       if(mf.ctf_status!=FLAG_BASE)
        if(vlen(ef.origin - mf.dropped_origin) < 300)
        {
                havocbot_role_ctf_setrole(self, HAVOCBOT_CTF_ROLE_DEFENSE);
@@ -331,12 +335,12 @@ void havocbot_role_ctf_escort()
                havocbot_goalrating_items(10000, self.origin, 10000);
                navigation_goalrating_end();
        }
-};
+}
 
 void havocbot_role_ctf_offense()
 {
-       local entity mf, ef;
-       local vector pos;
+       entity mf, ef;
+       vector pos;
 
        if(self.deadflag != DEAD_NO)
        {
@@ -355,7 +359,7 @@ void havocbot_role_ctf_offense()
        ef = havocbot_ctf_find_enemy_flag(self);
 
        // Own flag stolen
-       if(mf.cnt!=FLAG_BASE)
+       if(mf.ctf_status!=FLAG_BASE)
        {
                if(mf.tag_entity)
                        pos = mf.tag_entity.origin;
@@ -371,7 +375,7 @@ void havocbot_role_ctf_offense()
        }
 
        // Escort flag carrier
-       if(ef.cnt!=FLAG_BASE)
+       if(ef.ctf_status!=FLAG_BASE)
        {
                if(ef.tag_entity)
                        pos = ef.tag_entity.origin;
@@ -412,12 +416,12 @@ void havocbot_role_ctf_offense()
                havocbot_goalrating_items(1000, self.origin, 10000);
                navigation_goalrating_end();
        }
-};
+}
 
 // Retriever (temporary role):
 void havocbot_role_ctf_retriever()
 {
-       local entity mf;
+       entity mf;
 
        if(self.deadflag != DEAD_NO)
        {
@@ -433,7 +437,7 @@ void havocbot_role_ctf_retriever()
 
        // If flag is back on the base switch to previous role
        mf = havocbot_ctf_find_flag(self);
-       if(mf.cnt==FLAG_BASE)
+       if(mf.ctf_status==FLAG_BASE)
        {
                havocbot_ctf_reset_role(self);
                return;
@@ -450,7 +454,7 @@ void havocbot_role_ctf_retriever()
 
        if (self.bot_strategytime < time)
        {
-               local float radius;
+               float radius;
                radius = 10000;
 
                self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
@@ -461,11 +465,11 @@ void havocbot_role_ctf_retriever()
                havocbot_goalrating_items(500, self.origin, radius);
                navigation_goalrating_end();
        }
-};
+}
 
 void havocbot_role_ctf_middle()
 {
-       local entity mf;
+       entity mf;
 
        if(self.deadflag != DEAD_NO)
        {
@@ -480,7 +484,7 @@ void havocbot_role_ctf_middle()
        }
 
        mf = havocbot_ctf_find_flag(self);
-       if(mf.cnt!=FLAG_BASE)
+       if(mf.ctf_status!=FLAG_BASE)
        {
                havocbot_role_ctf_setrole(self, HAVOCBOT_CTF_ROLE_RETRIEVER);
                return;
@@ -497,7 +501,7 @@ void havocbot_role_ctf_middle()
 
        if (self.bot_strategytime < time)
        {
-               local vector org;
+               vector org;
 
                org = havocbot_ctf_middlepoint;
                org_z = self.origin_z;
@@ -512,11 +516,11 @@ void havocbot_role_ctf_middle()
                havocbot_goalrating_ctf_enemybase(2500);
                navigation_goalrating_end();
        }
-};
+}
 
 void havocbot_role_ctf_defense()
 {
-       local entity mf;
+       entity mf;
 
        if(self.deadflag != DEAD_NO)
        {
@@ -532,7 +536,7 @@ void havocbot_role_ctf_defense()
 
        // If own flag was captured
        mf = havocbot_ctf_find_flag(self);
-       if(mf.cnt!=FLAG_BASE)
+       if(mf.ctf_status!=FLAG_BASE)
        {
                havocbot_role_ctf_setrole(self, HAVOCBOT_CTF_ROLE_RETRIEVER);
                return;
@@ -548,8 +552,8 @@ void havocbot_role_ctf_defense()
        }
        if (self.bot_strategytime < time)
        {
-               local float radius;
-               local vector org;
+               float radius;
+               vector org;
 
                org = mf.dropped_origin;
                radius = havocbot_ctf_middlepoint_radius;
@@ -558,9 +562,8 @@ void havocbot_role_ctf_defense()
                navigation_goalrating_start();
 
                // if enemies are closer to our base, go there
-               local entity head, closestplayer;
-               local float distance, bestdistance;
-               distance = 10000;
+               entity head, closestplayer = world;
+               float distance, bestdistance = 10000;
                FOR_EACH_PLAYER(head)
                {
                        if(head.deadflag!=DEAD_NO)
@@ -587,32 +590,33 @@ void havocbot_role_ctf_defense()
                havocbot_goalrating_items(5000, self.origin, 10000);
                navigation_goalrating_end();
        }
-};
+}
 
 void havocbot_calculate_middlepoint()
 {
        entity f;
-       vector p1, p2;
+       vector s = '0 0 0';
+       vector fo = '0 0 0';
+       float n = 0;
 
        f = ctf_worldflaglist;
        while (f)
        {
-               if(p1)
-                       p2 = f.origin;
-               else
-                       p1 = f.origin;
-
+               fo = f.origin;
+               s = s + fo;
                f = f.ctf_worldflagnext;
        }
-       havocbot_ctf_middlepoint = p1 + ((p2-p1) * 0.5);
-       havocbot_ctf_middlepoint_radius  = vlen(p2-p1) * 0.5;
-};
+       if(!n)
+               return;
+       havocbot_ctf_middlepoint = s * (1.0 / n);
+       havocbot_ctf_middlepoint_radius  = vlen(fo - havocbot_ctf_middlepoint);
+}
 
 void havocbot_ctf_reset_role(entity bot)
 {
-       local float cdefense, cmiddle, coffense;
-       local entity mf, ef, head;
-       local float c;
+       float cdefense, cmiddle, coffense;
+       entity mf, ef, head;
+       float c;
 
        if(bot.deadflag != DEAD_NO)
                return;
@@ -631,14 +635,14 @@ void havocbot_ctf_reset_role(entity bot)
        ef = havocbot_ctf_find_enemy_flag(bot);
 
        // Retrieve stolen flag
-       if(mf.cnt!=FLAG_BASE)
+       if(mf.ctf_status!=FLAG_BASE)
        {
                havocbot_role_ctf_setrole(bot, HAVOCBOT_CTF_ROLE_RETRIEVER);
                return;
        }
 
        // If enemy flag is taken go to the middle to intercept pursuers
-       if(ef.cnt!=FLAG_BASE)
+       if(ef.ctf_status!=FLAG_BASE)
        {
                havocbot_role_ctf_setrole(bot, HAVOCBOT_CTF_ROLE_MIDDLE);
                return;
@@ -672,9 +676,9 @@ void havocbot_ctf_reset_role(entity bot)
                havocbot_role_ctf_setrole(bot, HAVOCBOT_CTF_ROLE_OFFENSE);
        else
                havocbot_role_ctf_setrole(bot, HAVOCBOT_CTF_ROLE_MIDDLE);
-};
+}
 
 void havocbot_chooserole_ctf()
 {
        havocbot_ctf_reset_role(self);
-};
+}