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