1 #define HAVOCBOT_AST_ROLE_NONE 0
2 #define HAVOCBOT_AST_ROLE_DEFENSE 2
3 #define HAVOCBOT_AST_ROLE_OFFENSE 4
5 .float havocbot_role_flags;
6 .float havocbot_attack_time;
9 .void() havocbot_previous_role;
11 void() havocbot_role_ast_defense;
12 void() havocbot_role_ast_offense;
13 .entity havocbot_ast_target;
15 entity havocbot_ast_core;
16 float havocbot_ast_core_unreachable;
18 void(entity bot) havocbot_ast_reset_role;
20 void(float ratingscale, vector org, float sradius) havocbot_goalrating_items;
21 void(float ratingscale, vector org, float sradius) havocbot_goalrating_enemyplayers;
23 void havocbot_ast_find_core()
25 entity are, to1, to2, to3;
27 if(havocbot_ast_core_unreachable)
30 are = findchain(classname, "target_assault_roundend");
32 for (; are; are = are.chain)
34 for(to1 = world; (to1 = find(to1, target, are.targetname)); )
36 if(to1.classname == "func_assault_destructible")
38 havocbot_ast_core = to1;
42 for(to2 = world; (to2 = find(to2, target, to1.targetname)); )
44 if(to2.classname == "func_assault_destructible")
46 havocbot_ast_core = to2;
50 for(to3 = world; (to3 = find(to3, target, to2.targetname)); )
52 if(to3.classname == "func_assault_destructible")
54 havocbot_ast_core = to3;
62 dprint("ERROR: Power core unreachable\n");
63 havocbot_ast_core_unreachable = TRUE;
66 void havocbot_goalrating_ast_core(float ratingscale)
69 float radius, found, bestvalue, c;
72 havocbot_ast_find_core();
74 if not(havocbot_ast_core)
77 if not(havocbot_ast_core.takedamage)
78 havocbot_ast_core.takedamage = TRUE;
80 p = 0.5 * (havocbot_ast_core.absmin + havocbot_ast_core.absmax);
81 // dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
83 te_lightning2(world, '0 0 0', p);
85 // Find and rate waypoints around it
88 bestvalue = 99999999999;
89 for(radius=0; radius<1000 && !found; radius+=500)
91 for(wp=findradius(p, radius); wp; wp=wp.chain)
93 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
94 if(wp.classname=="waypoint")
95 if(checkpvs(wp.origin, havocbot_ast_core))
109 dprint("waypoints around target were found\n");
110 // te_lightning2(world, '0 0 0', best.origin);
111 // te_knightspike(best.origin);
113 navigation_routerating(best, ratingscale, 10000);
116 self.havocbot_attack_time = 0;
118 if(checkpvs(self.view_ofs, havocbot_ast_core))
119 if(checkpvs(self.view_ofs, best))
121 // dprint("increasing attack time for this target\n");
122 self.havocbot_attack_time = time + 2;
127 void havocbot_goalrating_ast_targets(float ratingscale)
129 entity ad, best, pl, wp, tod;
130 float radius, found, bestvalue, c;
133 ad = findchain(classname, "func_assault_destructible");
135 for (; ad; ad = ad.chain)
140 if not(ad.bot_attack)
144 for(tod = world; (tod = find(tod, targetname, ad.target)); )
146 if(tod.classname == "target_objective_decrease")
148 if(tod.enemy.health > 0 && tod.enemy.health < ASSAULT_VALUE_INACTIVE)
150 // dprint(etos(ad),"\n");
159 dprint("target not found\n");
162 dprint("target #", etos(ad), " found\n");
165 p = 0.5 * (ad.absmin + ad.absmax);
166 // dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
167 // te_knightspike(p);
168 // te_lightning2(world, '0 0 0', p);
170 // Find and rate waypoints around it
173 bestvalue = 99999999999;
174 for(radius=0; radius<1500 && !found; radius+=500)
176 for(wp=findradius(p, radius); wp; wp=wp.chain)
178 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
179 if(wp.classname=="waypoint")
180 if(checkpvs(wp.origin, ad))
194 dprint("waypoints around target were found\n");
195 // te_lightning2(world, '0 0 0', best.origin);
196 // te_knightspike(best.origin);
198 navigation_routerating(best, ratingscale, 10000);
201 self.havocbot_attack_time = 0;
203 if(checkpvs(self.view_ofs,ad))
204 if(checkpvs(self.view_ofs,best))
206 // dprint("increasing attack time for this target\n");
207 self.havocbot_attack_time = time + 2;
213 void havocbot_role_ast_offense()
215 if(self.deadflag != DEAD_NO)
217 self.havocbot_attack_time = 0;
218 havocbot_ast_reset_role(self);
222 // Set the role timeout if necessary
223 if (!self.havocbot_role_timeout)
224 self.havocbot_role_timeout = time + 120;
226 if (time > self.havocbot_role_timeout)
228 havocbot_ast_reset_role(self);
232 if(self.havocbot_attack_time>time)
235 if (self.bot_strategytime < time)
237 navigation_goalrating_start();
238 /// havocbot_goalrating_enemyplayers(20000, self.origin, 650);
240 // if(!havocbot_goalrating_ast_generator_attack(20000))
241 // havocbot_goalrating_ast_controlpoints_attack(20000);
242 // havocbot_goalrating_ast_offenseitems(10000, self.origin, 10000);
244 havocbot_goalrating_ast_targets(20000);
245 /// havocbot_goalrating_items(10000, self.origin, 10000);
246 navigation_goalrating_end();
248 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
252 void havocbot_role_ast_defense()
254 if(self.deadflag != DEAD_NO)
256 self.havocbot_attack_time = 0;
257 havocbot_ast_reset_role(self);
261 // Set the role timeout if necessary
262 if (!self.havocbot_role_timeout)
263 self.havocbot_role_timeout = time + 120;
265 if (time > self.havocbot_role_timeout)
267 havocbot_ast_reset_role(self);
271 if(self.havocbot_attack_time>time)
274 if (self.bot_strategytime < time)
276 navigation_goalrating_start();
277 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
278 // if(!havocbot_goalrating_ast_generator_attack(20000))
279 // havocbot_goalrating_ast_controlpoints_attack(20000);
280 // havocbot_goalrating_ast_offenseitems(10000, self.origin, 10000);
281 havocbot_goalrating_items(10000, self.origin, 10000);
282 navigation_goalrating_end();
284 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
288 void havocbot_role_ast_setrole(entity bot, float role)
292 case HAVOCBOT_AST_ROLE_DEFENSE:
293 bot.havocbot_role = havocbot_role_ast_defense;
294 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
295 bot.havocbot_role_timeout = 0;
297 case HAVOCBOT_AST_ROLE_OFFENSE:
298 bot.havocbot_role = havocbot_role_ast_offense;
299 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
300 bot.havocbot_role_timeout = 0;
305 void havocbot_ast_reset_role(entity bot)
310 if(self.deadflag != DEAD_NO)
313 bot.havocbot_ast_target = world;
315 if(bot.team==assault_attacker_team)
316 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_OFFENSE);
318 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_DEFENSE);
321 void havocbot_chooserole_ast()
323 havocbot_ast_reset_role(self);