]> git.xonotic.org Git - voretournament/voretournament.git/blob - data/qcsrc/server/bot/havocbot/vore_ai.qc
Team healing AI now working as intended, but not ready yet. Also fix another tiny...
[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 in team games, and use this feature to heal damaged team mates
31
32         if not(teamplay)
33                 return;
34
35         self.status_teamhealing = 1; // start from the premise we can teamheal until proven otherwise
36         if(self.deadflag != DEAD_NO || self.eater.classname == "player" || self.flagcarried)
37         {
38                 self.status_teamhealing = 0;
39                 return;
40         }
41
42         // if we are holding a team mate that's been healed to the max, we can release them
43         // also use this check to not go any further if someone from the enemy team is in our stomach
44         entity head;
45         if(self.stomach_load)
46         {
47                 FOR_EACH_PLAYER(head)
48                 {
49                         if(head.eater.classname == "player")
50                         {
51                                 if(head.team == self.team)
52                                 {
53                                         self.status_teamhealing = 2;
54                                         if(head.health >= cvar("g_balance_vore_teamheal_stable"))
55                                                 self.BUTTON_REGURGITATE = TRUE; // release the team mate
56                                 }
57                                 else
58                                 {
59                                         self.status_teamhealing = 0; // someone from the enemy team is in our belly, which means we can't be teamhealing any more
60                                         return;
61                                 }
62                         }
63                 }
64         }
65
66         // check if we can heal a damaged team mate we came across, and if so swallow them
67         if(self.status_teamhealing)
68         if(prey.classname == "player" && prey.team == self.team)
69         if not(prey.flagcarried) // don't eat the flag carrier and ruin his job
70         if(Swallow_condition_check_bot(prey))
71         if(prey.health < cvar("g_balance_vore_teamheal_stable"))
72                 self.BUTTON_ATCK = TRUE; // swallow
73 }
74
75 .float swallow_retry, decide_delay1, decide_delay2;
76 void Vore_AI()
77 {
78         if(cvar("bot_nofire") || !skill)
79                 return;
80
81 // --------------------------------
82 // Predator bot behavior:
83 // --------------------------------
84
85         // finding and swallowing a victim:
86
87         // 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
88         entity scan;
89         scan = findradius(self.origin, cvar("g_balance_vore_swallow_range"));
90         if(Swallow_condition_check_bot(scan))
91                 bot_aimdir(scan.origin + scan.view_ofs - self.origin - self.view_ofs, -1);
92
93         // now do the actual checking and swallowing
94         entity prey;
95         float random_try;
96         float decide_prey, decide_pred;
97
98         prey = Swallow_distance_check_bot(self);
99         random_try = random() * 10; // there are 10 bot skill steps
100         if(prey.items & IT_STRENGTH) // avoid eating bots that have the Strenght powerup
101                 random_try /= cvar("bot_ai_vore_decide_fear");
102         if(prey.items & IT_INVINCIBLE) // avoid eating bots that have the Invincible powerup
103                 random_try /= cvar("bot_ai_vore_decide_fear");
104         decide_prey = cvar("bot_ai_vore_decide_prey") / (skill * 2 + 1);
105         decide_pred = cvar("bot_ai_vore_decide_pred") / (skill * 2 + 1);
106
107         if(time > self.swallow_retry)
108         if(Swallow_condition_check_bot(prey))
109         {
110                 // the greater the skill, the higher the chance bots will swallow someone each attempt
111                 if(skill >= random_try)
112                 if not(teamplay && prey.team == self.team)
113                 {
114                         self.BUTTON_ATCK = TRUE; // swallow
115                         self.decide_delay1 = time + decide_pred; // time before the bot decides what to do with their prey
116                 }
117                 self.swallow_retry = time + 0.5; // bots retry swallowing every 0.5 seconds, otherwise each frame would be random chance
118         }
119
120         Vore_AI_Teamheal(prey);
121         if(self.status_teamhealing > 1) // if we are teamhealing, there's nothing to do from here on
122                 return;
123
124         // deciding what to do with a victim:
125
126         if(self.stomach_load > 0 && time > self.decide_delay1)
127         {
128                 // if the predator's health is smaller than the maximum amount of damage a stomach kick can do, regurgitate the player(s)
129                 // otherwise the predator is putting himself at risk by keeping someone inside
130                 if(self.health <= cvar("g_balance_vore_kick_damage_max"))
131                         self.BUTTON_REGURGITATE = TRUE;
132
133                 else if(!self.digesting)
134                 {
135                         // the higher the skill, the faster bots will start to digest you
136                         if(skill >= random_try)
137                                 self.BUTTON_DIGEST = TRUE; // digest
138
139                         self.decide_delay1 = time + decide_pred; // time before the bot decides what to do with their prey
140                 }
141         }
142
143 // --------------------------------
144 // Prey bot behavior:
145 // --------------------------------
146
147         // all we can do in the stomach is kick and do some damage / try to escape
148         if(self.eater.classname == "player" && time > self.decide_delay2)
149         {
150                 // the higher the skill, the more the bot will kick in your stomack
151                 if(skill >= random_try)
152                 if not(teamplay && prey.team == self.team) // if someone from the same team somehow made it in the belly, don't kick the eater
153                         self.BUTTON_ATCK = TRUE; // kick
154
155                 self.decide_delay2 = time + decide_prey; // time before the bot decides what to do with their predator
156         }
157 }