]> 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 74c611ea18ddf6bdfe8f54dc94c3de1c29c59c57..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;
@@ -60,7 +60,7 @@ float havocbot_ctf_teamcount(entity bot, vector org, float radius)
        if not(teamplay)
                return 0;
 
-       float c;
+       float c = 0;
        entity head;
 
        FOR_EACH_PLAYER(head)
@@ -102,7 +102,7 @@ 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)
@@ -134,7 +134,7 @@ void havocbot_goalrating_ctf_enemybase(float ratingscale)
        if not(head)
                return;
 
-       navigation_routerating(head.basewaypoint, ratingscale, 10000);
+       navigation_routerating(head.bot_basewaypoint, ratingscale, 10000);
 }
 
 void havocbot_goalrating_ctf_ourstolenflag(float ratingscale)
@@ -143,7 +143,7 @@ void havocbot_goalrating_ctf_ourstolenflag(float ratingscale)
 
        mf = havocbot_ctf_find_flag(self);
 
-       if(mf.cnt == FLAG_BASE)
+       if(mf.ctf_status == FLAG_BASE)
                return;
 
        if(mf.tag_entity)
@@ -157,7 +157,7 @@ void havocbot_goalrating_ctf_droppedflags(float ratingscale, vector org, float r
        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)
@@ -295,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;
@@ -304,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);
@@ -359,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;
@@ -375,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;
@@ -437,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;
@@ -484,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;
@@ -536,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;
@@ -562,9 +562,8 @@ void havocbot_role_ctf_defense()
                navigation_goalrating_start();
 
                // if enemies are closer to our base, go there
-               entity head, closestplayer;
-               float distance, bestdistance;
-               distance = 10000;
+               entity head, closestplayer = world;
+               float distance, bestdistance = 10000;
                FOR_EACH_PLAYER(head)
                {
                        if(head.deadflag!=DEAD_NO)
@@ -596,20 +595,21 @@ void havocbot_role_ctf_defense()
 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)
@@ -635,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;