1 #define HAVOCBOT_ONS_ROLE_NONE 0
2 #define HAVOCBOT_ONS_ROLE_DEFENSE 2
3 #define HAVOCBOT_ONS_ROLE_ASSISTANT 4
4 #define HAVOCBOT_ONS_ROLE_OFFENSE 8
6 .float havocbot_role_flags;
9 .void() havocbot_previous_role;
11 void() havocbot_role_ons_defense;
12 void() havocbot_role_ons_offense;
13 void() havocbot_role_ons_assistant;
15 void(entity bot) havocbot_ons_reset_role;
16 void(float ratingscale, vector org, float sradius) havocbot_goalrating_items;
17 void(float ratingscale, vector org, float sradius) havocbot_goalrating_enemyplayers;
22 float (entity controlpoint, float team) onslaught_controlpoint_can_be_linked;
23 float (entity controlpoint, float team) onslaught_controlpoint_attackable;
25 void havocbot_role_ons_setrole(entity bot, float role)
27 dprint(strcat(bot.netname," switched to "));
30 case HAVOCBOT_ONS_ROLE_DEFENSE:
32 bot.havocbot_role = havocbot_role_ons_defense;
33 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_DEFENSE;
34 bot.havocbot_role_timeout = 0;
36 case HAVOCBOT_ONS_ROLE_ASSISTANT:
38 bot.havocbot_role = havocbot_role_ons_assistant;
39 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_ASSISTANT;
40 bot.havocbot_role_timeout = 0;
42 case HAVOCBOT_ONS_ROLE_OFFENSE:
44 bot.havocbot_role = havocbot_role_ons_offense;
45 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_OFFENSE;
46 bot.havocbot_role_timeout = 0;
52 float havocbot_ons_teamcount(entity bot, float role)
58 if(head.team==self.team)
59 if(head.havocbot_role_flags & role)
65 void havocbot_goalrating_ons_controlpoints_attack(float ratingscale)
67 local entity cps, cp, wp, bestwp;
68 local float radius, found, bestcounter, status;
70 for (cps = findchain(classname, "onslaught_controlpoint_shield"); cps; cps = cps.chain)
72 // Found its corresponding onslaught_controlpoint entity (...)
73 for (cp = findradius(cps.origin, 100); cp; cp = cp.chain)
75 if(cp.classname=="onslaught_controlpoint")
82 status = onslaught_controlpoint_attackable(cp, self.team);
84 dprint(self.classname," found a controlpoint with status ",ftos(status),"\n");
86 if(status==1 || status == 3)
89 // Rate waypoints near it
92 bestcounter = 99999999999;
93 for(radius=0; radius<1000 && !found; radius+=500)
95 for(wp=findradius(cp.origin,radius); wp; wp=wp.chain)
97 if(wp.classname=="waypoint")
98 if(checkpvs(wp.origin,cp))
101 if(wp.cnt<bestcounter)
104 bestcounter = wp.cnt;
115 navigation_routerating(bestwp, ratingscale, 10000);
118 dprint("attackable controlpoint found at ", vtos(cp.origin) ,"\n");
120 else if(status==2 || status==4)
123 if not(bot_waypoints_for_items)
125 navigation_routerating(cp, ratingscale, 10000);
129 for (wp = findradius(cp.origin,100); wp; wp = wp.chain)
131 if(wp.classname=="waypoint")
133 navigation_routerating(wp, ratingscale, 10000);
137 dprint("touchable controlpoint found at ", vtos(cp.origin) ,"\n");
142 void havocbot_goalrating_ons_generator_attack(float ratingscale)
144 local entity g, wp, bestwp;
145 local float radius, found, bestcounter;
147 for (g = findchain(classname, "onslaught_generator"); g; g = g.chain)
149 if(g.team == self.team || g.isshielded)
152 // Should be attacked
153 // Rate waypoints near it
156 bestcounter = 99999999999;
157 for(radius=0; radius<1500 && !found; radius+=500)
159 for(wp=findradius(g.origin,radius); wp; wp=wp.chain)
161 if(wp.classname=="waypoint")
162 if(checkpvs(wp.origin,g))
165 if(wp.cnt<bestcounter)
168 bestcounter = wp.cnt;
179 dprint("waypoints found around generator\n");
180 navigation_routerating(bestwp, ratingscale, 10000);
185 dprint("generator found without waypoints around\n");
186 // if there aren't waypoints near the generator go straight to it
187 navigation_routerating(g, ratingscale, 10000);
192 void havocbot_role_ons_offense()
194 if(self.deadflag != DEAD_NO)
196 havocbot_ons_reset_role(self);
200 // Set the role timeout if necessary
201 if (!self.havocbot_role_timeout)
202 self.havocbot_role_timeout = time + 120;
204 if (time > self.havocbot_role_timeout)
206 havocbot_ons_reset_role(self);
210 if (self.bot_strategytime < time)
212 navigation_goalrating_start();
213 havocbot_goalrating_enemyplayers(20000, self.origin, 500);
214 havocbot_goalrating_ons_generator_attack(20000);
215 havocbot_goalrating_ons_controlpoints_attack(20000);
216 havocbot_goalrating_items(15000, self.origin, 1000);
217 havocbot_goalrating_items(2500, self.origin, 10000);
218 navigation_goalrating_end();
220 self.bot_strategytime = time + cvar("bot_ai_strategyinterval");
224 void havocbot_role_ons_assistant()
226 havocbot_ons_reset_role(self);
229 void havocbot_role_ons_defense()
231 havocbot_ons_reset_role(self);
234 void havocbot_ons_reset_role(entity bot)
239 if(self.deadflag != DEAD_NO)
242 // TODO: Defend control points or generator if necessary
244 // if there is only me on the team switch to offense
246 FOR_EACH_PLAYER(head)
247 if(head.team==self.team)
252 havocbot_role_ons_setrole(bot, HAVOCBOT_ONS_ROLE_OFFENSE);
256 havocbot_role_ons_setrole(bot, HAVOCBOT_ONS_ROLE_OFFENSE);
259 void havocbot_chooserole_ons()
261 havocbot_ons_reset_role(self);