]> de.git.xonotic.org Git - voretournament/voretournament.git/blob - data/qcsrc/server/bot/havocbot/vore_ai.qc
Share some duplicated code instead
[voretournament/voretournament.git] / data / qcsrc / server / bot / havocbot / vore_ai.qc
1 .float status_teamhealing; // 0 = can't team heal, 1 = can team heal, 2 = team healing right now
2
3 float Swallow_condition_check_bot(entity prey)
4 {
5         // checks the necessary conditions for a bot to swallow another player
6
7         if(prey != self && prey.classname == "player" && prey.predator.classname != "player" && prey.deadflag == DEAD_NO && !prey.BUTTON_CHAT) // we can't swallow someone who's already in someone else's stomach
8         if(self.predator.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
9         if not(cvar("g_vore_biggergut") && prey.stomach_load > self.stomach_load)
10         if(self.health > cvar("g_balance_vore_kick_damage_max")) // explained below
11                 return TRUE;
12         return FALSE;
13 }
14
15 void Vore_AI_Teamheal(entity prey)
16 {
17         // allows bots to take advantage of the teamheal feature, and use it to heal damaged team mates
18         // the prey entity is only used when it's available (a player is detected in-range), otherwise the rest of the code executes as expected
19
20         // if a teamheal is ongoing, decide whether or not to abandon it when seeing a foe that we can attack instead
21         // this only causes the bot to regurgitate their team mate when seeing an enemy, with the hope that this enemy will still be there once we can swallow again
22         // the higher the skill, the greater the chance a bot will abandon a team heal for an enemy
23         if(self.status_teamhealing > 1)
24         if(Swallow_condition_check_bot(prey))
25         if(prey.team != self.team)
26         if(random() * 10 < cvar("bot_ai_vore_teamhealabandon") * skill / self.bot_voreteamheal) // there are 10 bot skill steps
27                 self.BUTTON_REGURGITATE = TRUE; // release the team mate
28
29         entity head;
30
31         if not(teams_matter && cvar("g_balance_vore_teamheal"))
32                 return;
33         if(self.deadflag != DEAD_NO || self.predator.classname == "player" || self.flagcarried || self.digesting) // a flag carrier can't waste time on team healing
34         {
35                 self.status_teamhealing = 0;
36                 return;
37         }
38
39         // decide if we can teamheal or not
40         if(self.stomach_load)
41         {
42                 self.status_teamhealing = 2; // consider a team mate is in our stomach and therefore we are teamhealing, until proven otherwise below
43
44                 FOR_EACH_PLAYER(head)
45                 {
46                         if(head.predator == self)
47                         if(head.team != self.team)
48                         {
49                                 self.status_teamhealing = 0; // there's a foe in our stomach, we can't teamheal now
50                                 return;
51                         }
52                 }
53         }
54         else
55                 self.status_teamhealing = 1; // if our stomach is empty, it means we can decide to teamheal
56
57         // now that we're decided if we can teamheal or not, lets go ahead and do so:
58
59         // if we are holding a team mate that's been healed to the maximum amount, we can release them
60         // not sure if this should be merged with the FOR_EACH_PLAYER check above. That would save an extra loop, but would be less correct
61         FOR_EACH_PLAYER(head)
62         {
63                 if(head.predator == self) // head is automatically a team mate, or we wouldn't be reaching this part of the code
64                 if(head.health >= cvar("g_balance_vore_teamheal_stable"))
65                         self.BUTTON_REGURGITATE = TRUE; // release the team mate
66         }
67
68         // check if we can heal a damaged team mate we came across, and if so swallow them
69         if(prey.classname == "player" && prey.team == self.team)
70         if(prey.health < cvar("g_balance_vore_teamheal_stable"))
71         if not(prey.digesting) // if our team mate is digesting someone, he likely wouldn't want us ruining his frag
72         if not(prey.flagcarried) // don't eat the flag carrier and ruin his job
73         if(Swallow_condition_check_bot(prey))
74                 self.BUTTON_ATCK = TRUE; // swallow
75 }
76
77 .float swallow_retry, decide_delay1, decide_delay2;
78 void Vore_AI()
79 {
80         if(cvar("bot_nofire") || !skill)
81                 return;
82
83 // --------------------------------
84 // Predator bot behavior:
85 // --------------------------------
86
87         // finding and swallowing a victim:
88
89         // 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
90         entity scan;
91         scan = findradius(self.origin, cvar("g_balance_vore_swallow_range"));
92         if(Swallow_condition_check_bot(scan))
93                 bot_aimdir(scan.origin + scan.view_ofs - self.origin - self.view_ofs, -1);
94
95         // now do the actual checking and swallowing
96         entity prey;
97         float random_try;
98         float decide_prey, decide_pred;
99
100         prey = Swallow_player_check();
101
102         // check if we should run the Teamhealing AI rather than continuing with the normal vore
103         Vore_AI_Teamheal(prey);
104         if(self.status_teamhealing > 1) // if we are teamhealing, there's nothing to do from here on
105                 return;
106
107         random_try = random() * 10; // there are 10 bot skill steps
108         if(prey.items & IT_STRENGTH) // avoid eating bots that have the Strenght powerup
109                 random_try /= cvar("bot_ai_vore_fear") * self.bot_vorefear;
110         if(prey.items & IT_INVINCIBLE) // avoid eating bots that have the Invincible powerup
111                 random_try /= cvar("bot_ai_vore_fear") * self.bot_vorefear;
112         decide_prey = cvar("bot_ai_vore_decide_prey") / (skill * 2 + 1) / self.bot_vorethink;
113         decide_pred = cvar("bot_ai_vore_decide_pred") / (skill * 2 + 1) / self.bot_vorethink;
114
115         if(time > self.swallow_retry)
116         if(Swallow_condition_check_bot(prey))
117         {
118                 // the greater the skill, the higher the chance bots will swallow someone each attempt
119                 if(skill >= random_try)
120                 if not(teams_matter && prey.team == self.team)
121                 {
122                         self.BUTTON_ATCK = TRUE; // swallow
123                         self.decide_delay1 = time + decide_pred; // time before the bot decides what to do with their prey
124                 }
125                 self.swallow_retry = time + 0.5; // bots retry swallowing every 0.5 seconds, otherwise each frame would be random chance
126         }
127
128         // deciding what to do with a victim:
129
130         if(self.stomach_load > 0 && time > self.decide_delay1)
131         {
132                 // if the predator's health is smaller than the maximum amount of damage a stomach kick can do, regurgitate the player(s)
133                 // otherwise the predator is putting himself at risk by keeping someone inside
134                 if(self.health <= cvar("g_balance_vore_kick_damage_max"))
135                         self.BUTTON_REGURGITATE = TRUE;
136
137                 else if(!self.digesting)
138                 {
139                         // the higher the skill, the faster bots will start to digest you
140                         if(skill >= random_try)
141                                 self.BUTTON_DIGEST = TRUE; // digest
142
143                         self.decide_delay1 = time + decide_pred; // time before the bot decides what to do with their prey
144                 }
145         }
146
147 // --------------------------------
148 // Prey bot behavior:
149 // --------------------------------
150
151         // 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
152         if(self.predator.classname == "player" && time > self.decide_delay2)
153         {
154                 if not(teams_matter && self.team == self.predator.team)
155                 {
156                         // the higher the skill, the more the bot will kick in your stomack
157                         if(skill >= random_try)
158                         if not(teams_matter && prey.team == self.team) // if someone from the same team somehow made it in the belly, don't kick the eater
159                                 self.BUTTON_ATCK = TRUE; // kick
160                 }
161
162                 // if a bot can willingly leave the predator, do so unless there's a reason not to
163                 if(self.stat_canleave)
164                 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
165                         self.BUTTON_JUMP = TRUE;
166
167                 self.decide_delay2 = time + decide_prey; // time before the bot decides what to do with their predator
168         }
169 }