]> de.git.xonotic.org Git - voretournament/voretournament.git/blobdiff - data/qcsrc/server/bot/havocbot/vore_ai.qc
Tweak bot AI and make bots able to play with the slow swallowing feature
[voretournament/voretournament.git] / data / qcsrc / server / bot / havocbot / vore_ai.qc
index 728580fea8716016a7871cc493ceee6c0e62c018..8f413afff4cc4c3e1cc53d74833fc23fbf6b7042 100644 (file)
-entity Swallow_distance_check_bot(entity e)
-{
-       // check if we can swallow a player instead of firing our weapon
-       vector w_shotorg, w_shotdir;
-       w_shotorg = self.origin + self.view_ofs;
-       w_shotdir = v_forward;
-
-       WarpZone_traceline_antilag(e, w_shotorg, w_shotorg + w_shotdir * cvar("g_balance_vore_swallow_range"), FALSE, e, ANTILAG_LATENCY(e));
-       if(trace_fraction < 1)
-       if(trace_ent.classname == "player")
-               return trace_ent;
-       return world;
-}
+.float status_teamhealing; // 0 = can't team heal, 1 = can team heal, 2 = team healing right now
+.float hold_BUTTON_ATCK; // marks the bot holding the fire button after having decided on his prey
 
 float Swallow_condition_check_bot(entity prey)
 {
-       // checks the necessary conditions for a bot to swallow another player
-       if(prey != self && prey.classname == "player" && prey.eater.classname != "player" && prey.deadflag == DEAD_NO && !prey.BUTTON_CHAT) // we can't swallow someone who's already in someone else's stomach
-       if(self.eater.classname != "player" && self.stomach_load < cvar("g_balance_vore_swallow_limit") && self.deadflag == DEAD_NO) // we can't swallow players while inside someone's stomach ourselves
-       if not(cvar("g_vore_biggergut") && prey.stomach_load > self.stomach_load)
+       // checks the necessary conditions for a bot to swallow a player
+
+       if(Swallow_condition_check(prey)) // check the normal conditions of the vore system
+       if(time >= prey.spawnshieldtime) // spawn shield means you are invincible
+       if not(prey.BUTTON_CHAT) // don't eat players who are chatting
        if(self.health > cvar("g_balance_vore_kick_damage_max")) // explained below
-       if not(prey.team == self.team && teamplay)
                return TRUE;
        return FALSE;
 }
 
-.float swallow_retry, decide_delay1, decide_delay2;
-void Vore_AI()
+.float decide_swallow, decide_pred, decide_prey;
+void Vore_AI_Teamheal(entity prey)
 {
-       if(cvar("bot_nofire") || !skill)
+       // allows bots to use the teamheal feature and heal damaged team mates
+       // the prey entity is only used when it's available (a player is detected in range)
+
+       entity head;
+
+       if not(teams_matter && cvar("g_balance_vore_teamheal") && cvar("g_vore_teamvore"))
                return;
+       if(self.deadflag != DEAD_NO || self.stat_eaten || self.flagcarried || self.digesting) // a flag carrier can't waste time on team healing
+       {
+               self.status_teamhealing = 0;
+               return;
+       }
 
-// --------------------------------
-// Predator bot behavior:
-// --------------------------------
+       // if a teamheal is ongoing, decide whether or not to abandon it when seeing a foe we can attack
+       // this only causes the bot to regurgitate their team mate when seeing an enemy, with the hope that our enemy will still be there once we can swallow
+       // the higher the skill, the greater the chance a bot will abandon a team heal for an enemy
+       if(self.status_teamhealing > 1)
+       if(Swallow_condition_check_bot(prey))
+       if(prey.team != self.team)
+       if(random() * 10 < cvar("bot_ai_vore_teamhealabandon") * skill / self.bot_voreteamheal) // there are 10 bot skill steps
+               self.BUTTON_REGURGITATE = TRUE; // release the team mate
 
-       // finding and swallowing a victim:
+       // decide if we can teamheal or not
+       if(self.stomach_load)
+       {
+               self.status_teamhealing = 2; // consider a team mate is in our stomach and we are teamhealing, until proven otherwise below
 
-       // aim toward the nearest possible victim. The greater the skill the quicker the aim. This only does the aiming, checking and swallowing is handled below
-       entity scan;
-       scan = findradius(self.origin, cvar("g_balance_vore_swallow_range"));
-       if(Swallow_condition_check_bot(scan))
-               bot_aimdir(scan.origin + scan.view_ofs - self.origin - self.view_ofs, -1);
+               FOR_EACH_PLAYER(head)
+               {
+                       if(head.predator == self)
+                       if(head.team != self.team)
+                       {
+                               self.status_teamhealing = 0; // there's a foe in our stomach, we can't teamheal now
+                               return;
+                       }
+               }
+       }
+       else
+               self.status_teamhealing = 1; // if our stomach is empty, it means we can decide to teamheal
 
-       // now do the actual checking and swallowing
-       entity prey;
-       float random_try;
-       float decide_prey, decide_pred;
+       // now that we're decided if we can teamheal or not, lets go ahead and do so
 
-       prey = Swallow_distance_check_bot(self);
-       random_try = random() * 10; // there are 10 bot skill steps
-       if(prey.items & IT_STRENGTH) // avoid eating bots that have the Strenght powerup
-               random_try /= cvar("bot_ai_vore_decide_fear");
-       if(prey.items & IT_INVINCIBLE) // avoid eating bots that have the Invincible powerup
-               random_try /= cvar("bot_ai_vore_decide_fear");
-       decide_prey = cvar("bot_ai_vore_decide_prey") / (skill * 2 + 1);
-       decide_pred = cvar("bot_ai_vore_decide_pred") / (skill * 2 + 1);
+       // if we are holding a team mate that's been healed to the limit, we can release them
+       if not(cvar("bot_ai_vore_keepinstomach"))
+       FOR_EACH_PLAYER(head)
+       {
+               if(head.predator == self) // head is automatically a team mate, or we wouldn't be reaching this part of the code
+               if(head.health >= cvar("g_balance_vore_teamheal_stable"))
+                       self.BUTTON_REGURGITATE = TRUE; // release the team mate
+       }
 
+       // check if we can heal a team mate we come across, and if so swallow them
+       if(prey.team == self.team)
        if(Swallow_condition_check_bot(prey))
-       if(time > self.swallow_retry)
+       if(prey.health < cvar("g_balance_vore_teamheal_stable"))
+       if not(prey.digesting) // if our team mate is digesting someone, he likely wouldn't want us ruining his frag
+       if not(prey.flagcarried) // don't eat the flag carrier and ruin his job
+       if not(prey.BUTTON_ATCK || prey.BUTTON_ATCK2) // our team mate wouldn't want us eating him while he's firing
        {
-               // the greater the skill, the higher the chance bots will swallow someone each attempt
-               if(skill >= random_try)
+               if(time > self.decide_swallow)
                {
-                       self.BUTTON_ATCK = TRUE; // swallow
-                       self.decide_delay1 = time + decide_pred; // time before the bot decides what to do with their prey
+                       if(skill >= random() * 10) // there are 10 bot skill steps
+                               self.hold_BUTTON_ATCK = TRUE; // swallow the team mate
+                       self.decide_swallow = time + cvar("bot_ai_vore_decide_swallow") / self.bot_vorethinkpred; // this is needed to take a proper decision, otherwise the code would execute each frame and return TRUE quickly
                }
-               self.swallow_retry = time + 0.5; // bots retry swallowing every 0.5 seconds, otherwise each frame would be random chance
        }
+       else
+               self.hold_BUTTON_ATCK = FALSE;
+}
+
+void Vore_AI()
+{
+       // main vore AI code
+
+       if(!cvar("g_vore")) // the vore system is disabled
+               return;
+       if(self.deadflag != DEAD_NO || cvar("bot_nofire") || !skill || (g_rpg && cvar("g_rpg_botattack") < 1))
+               return;
+
+       float randomtry;
+       randomtry = random() * 10; // there are 10 bot skill steps
 
-       // deciding what to do with a victim:
+// --------------------------------
+// Predator bot behavior:
+// --------------------------------
 
-       if(self.stomach_load > 0 && time > self.decide_delay1)
+       if(!self.stat_eaten)
        {
-               // if the predator's health is smaller than the maximum amount of damage a stomach kick can do, regurgitate the player(s)
-               // otherwise the predator is putting himself at risk by keeping someone inside
-               if(self.health <= cvar("g_balance_vore_kick_damage_max"))
-                       self.BUTTON_REGURGITATE = TRUE;
+               // finding and swallowing a player
+
+               // aim toward the nearest possible victim. The greater the skill, the quicker the aim
+               // this only does the aiming, checking and swallowing is handled below
+               entity head;
+               head = findradius(self.origin, cvar("g_balance_vore_swallow_range"));
+               while(head)
+               {
+                       if(Swallow_condition_check_bot(head))
+                               bot_aimdir(head.origin + head.view_ofs - self.origin - self.view_ofs, -1);
+                       head = head.chain;
+               }
+
+               // now do the actual checking and swallowing
+               entity prey;
+               float decide_pred_time, fear;
+
+               prey = Swallow_player_check();
+               fear = 1;
+
+               // check if we should run the Teamhealing AI rather than continuing with the normal vore AI
+               Vore_AI_Teamheal(prey);
+               if(self.status_teamhealing > 1) // if we are teamhealing, there's nothing to do from here on
+                       return;
 
-               else if(!self.digesting)
+               if(prey.items & IT_STRENGTH) // avoid eating bots that have the Strenght powerup
+                       fear += cvar("bot_ai_vore_fear") * self.bot_vorefear;
+               if(prey.items & IT_INVINCIBLE) // avoid eating bots that have the Invincible powerup
+                       fear += cvar("bot_ai_vore_fear") * self.bot_vorefear;
+               fear += self.stomach_load; // the bigger our stomach, the less we want to put someone else in there
+               decide_pred_time = cvar("bot_ai_vore_decide_pred") / skill / self.bot_vorethinkpred;
+
+               if(Swallow_condition_check_bot(prey))
                {
-                       // the higher the skill, the faster bots will start to digest you
-                       if(skill >= random_try)
-                               self.BUTTON_DIGEST = TRUE; // digest
+                       if(time > self.decide_swallow)
+                       {
+                               // the greater the skill, the higher the chance bots will swallow someone each attempt
+                               if(skill / fear >= randomtry)
+                               if not(teams_matter && prey.team == self.team)
+                               {
+                                       self.hold_BUTTON_ATCK = TRUE; // swallow
+                                       self.decide_pred = time + decide_pred_time; // time before the bot decides what to do with his prey
+                               }
+                               self.decide_swallow = time + cvar("bot_ai_vore_decide_swallow") / self.bot_vorethinkpred; // this is needed to take a proper decision, otherwise the code would execute each frame and return TRUE quickly
+                       }
+               }
+               else
+                       self.hold_BUTTON_ATCK = FALSE;
+
+               // if the bot is holding the firing button, apply that to the actual fire key
+               if(self.hold_BUTTON_ATCK)
+                       self.BUTTON_ATCK = TRUE;
 
-                       self.decide_delay1 = time + decide_pred; // time before the bot decides what to do with their prey
+               // deciding what to do with a victim:
+
+               if(self.stomach_load && time > self.decide_pred)
+               {
+                       // if the predator's health is smaller than the maximum damage a stomach kick can do, regurgitate the player(s)
+                       // otherwise the predator is putting himself at risk by keeping you inside
+                       // TODO: make bots also know the amount of damage boost a melee attack can do
+                       if(self.health <= cvar("g_balance_vore_kick_damage_max"))
+                               self.BUTTON_REGURGITATE = TRUE;
+
+                       else if(!self.digesting && cvar("g_vore_digestion"))
+                       {
+                               // the higher the skill, the faster bots will start to digest
+                               if not(g_rpg && cvar("g_rpg_botattack") < 2)
+                               if(skill >= randomtry)
+                                       self.BUTTON_DIGEST = TRUE; // digest
+
+                               self.decide_pred = time + decide_pred_time; // time before the bot decides what to do with his prey
+                       }
                }
        }
 
@@ -91,14 +183,36 @@ void Vore_AI()
 // Prey bot behavior:
 // --------------------------------
 
-       // all we can do in the stomach is kick and do some damage / try to escape
-       if(self.eater.classname == "player" && time > self.decide_delay2)
+       if(self.stat_eaten && time > self.decide_prey)
        {
-               // the higher the skill, the more the bot will kick in your stomack
-               if(skill >= random_try)
-               if(self.team != self.eater.team) // if someone from the same team somehow made it in the belly, don't kick the eater
-                       self.BUTTON_ATCK = TRUE; // kick
+               // all we can do in the stomach is kick and do some damage / try to escape, or leave if the circumstances allow it and we should
+
+               float decide_prey_time;
+               decide_prey_time = cvar("bot_ai_vore_decide_prey") / skill / self.bot_vorethinkprey;
+
+               if(cvar("g_vore_kick"))
+               if not(g_rpg && cvar("g_rpg_botattack") < 2)
+               if not(teams_matter && self.team == self.predator.team)
+               {
+                       // the higher the skill, the more the bot will kick in your stomack
+                       if(skill >= randomtry)
+                       if not(teams_matter && self.team == self.predator.team) // if someone from the same team is in the belly, don't kick the predator
+                               self.BUTTON_ATCK = TRUE; // kick
+               }
+
+               // if a bot can willingly leave the predator, do so unless there's a reason not to
+               if(self.stat_canleave)
+               {
+                       if(self.predator.digesting) // our predator is digesting, so get out of him regardless of who he is
+                               self.BUTTON_JUMP = TRUE; // leave
+                       else if not(g_rpg && cvar("g_rpg_botattack") < 2)
+                       {
+                               if not(teams_matter && self.team == self.predator.team && cvar("g_balance_vore_teamheal") && self.health < cvar("g_balance_vore_teamheal_stable")) // we are being team healed, don't leave
+                               if not(teams_matter && self.team == self.predator.team && cvar("bot_ai_vore_stayinstomach")) // bots are not supposed to leave a team mate's stomach automatically
+                                       self.BUTTON_JUMP = TRUE; // leave
+                       }
+               }
 
-               self.decide_delay2 = time + decide_prey; // time before the bot decides what to do with their predator
+               self.decide_prey = time + decide_prey_time; // time before the bot decides what to do with their predator
        }
 }
\ No newline at end of file