1 // rough simulation of walking from one point to another to test if a path
2 // can be traveled, used by havocbot
6 float navigation_testtracewalk;
7 float(entity e, vector start, vector m1, vector m2, vector end) tracewalk =
13 local float totaldist;
16 local float ignorehazards;
17 if (navigation_testtracewalk)
19 if (navigation_testtracewalk > 1)
20 dprint("tracewalk: ");
22 //te_knightspike(end);
23 //te_lightning2(world, start, end);
28 dist = totaldist = vlen(move);
29 dir = normalize(move);
31 ignorehazards = FALSE;
32 //self.angles = vectoangles(dir);
33 traceline(start, start, FALSE, e);
34 if (trace_dpstartcontents & (DPCONTENTS_SLIME | DPCONTENTS_LAVA))
36 tracebox(start, m1, m2, start, TRUE, e);
40 if (navigation_testtracewalk)
42 if (navigation_testtracewalk > 1)
43 dprint("bad-start\n");
44 te_knightspike(start);
52 if (boxesoverlap(end, end, org + m1 + '-1 -1 -1', org + m2 + '1 1 1'))
54 if (navigation_testtracewalk)
56 if (navigation_testtracewalk > 1)
65 if (navigation_testtracewalk)
69 particle(org, '0 0 0', 104, 8);
73 dist = dist - stepdist;
74 traceline(org, org, FALSE, e);
77 if (trace_dpstartcontents & (DPCONTENTS_SLIME | DPCONTENTS_LAVA))
79 if (navigation_testtracewalk)
81 if (navigation_testtracewalk > 1)
85 // hazards blocking path
89 if (trace_dpstartcontents & DPCONTENTS_LIQUIDSMASK)
91 move = normalize(end - org);
92 tracebox(org, m1, m2, org + move * stepdist, MOVE_WORLDONLY, e);
93 if (trace_fraction < 1)
95 if (navigation_testtracewalk)
97 if (navigation_testtracewalk > 1)
98 dprint("swimming-hit-something\n");
99 //particle(org, move * 64, 104, 4);
109 move = dir * stepdist + org;
110 tracebox(org, m1, m2, move, MOVE_WORLDONLY, e);
111 if (trace_fraction < 1)
113 tracebox(org + stepheightvec, m1, m2, move + stepheightvec, MOVE_WORLDONLY, e);
114 if (trace_fraction < 1 || trace_startsolid)
116 if (navigation_testtracewalk)
118 if (navigation_testtracewalk > 1)
119 dprint("hit-something\n");
120 //move = normalize(end - org);
121 //particle(org, move * 64, 104, 4);
129 tracebox(move, m1, m2, move + '0 0 -65536', FALSE, e);
131 // trace down from stepheight as far as possible and move there,
132 // if this starts in solid we try again without the stepup, and
133 // if that also fails we assume it is a wall
134 // (this is the same logic as the Quake walkmove function used)
135 tracebox(move + '0 0 18', m1, m2, move + '0 0 -65536', FALSE, e);
136 if (trace_startsolid)
138 tracebox(move, m1, m2, move + '0 0 -65536', FALSE, e);
139 if (trace_startsolid)
141 if (navigation_testtracewalk)
143 if (navigation_testtracewalk > 1)
144 dprint("hit-something\n");
145 //move = normalize(end - org);
146 //particle(org, move * 64, 104, 4);
154 // moved successfully
155 if (navigation_testtracewalk > 1)
160 if (navigation_testtracewalk)
162 if (navigation_testtracewalk > 1)
163 dprint("wrong-place\n");
167 // moved but didn't arrive at the intended destination
172 // grenade tracing to decide the best pitch to fire at
175 entity tracetossfaketarget;
177 // traces multiple trajectories to find one that will impact the target
178 // 'end' vector is the place it aims for,
179 // returns TRUE only if it hit targ (don't target non-solid entities)
180 vector findtrajectory_velocity;
181 float(vector org, vector m1, vector m2, entity targ, float shotspeed, float shotspeedupward, float maxtime, float shotdelay, entity ignore) findtrajectorywithleading =
183 local float c, savesolid, shottime;
184 local vector dir, end, v;
186 return FALSE; // could cause division by zero if calculated
187 if (targ.solid < SOLID_BBOX) // SOLID_NOT and SOLID_TRIGGER
188 return FALSE; // could never hit it
190 tracetossent = spawn();
191 tracetossent.owner = ignore;
192 setsize(tracetossent, m1, m2);
193 savesolid = targ.solid;
194 targ.solid = SOLID_NOT;
195 shottime = ((vlen(targ.origin - org) / shotspeed) + shotdelay);
196 v = targ.velocity * shottime + targ.origin;
197 tracebox(targ.origin, targ.mins, targ.maxs, v, FALSE, targ);
199 end = v + (targ.mins + targ.maxs) * 0.5;
200 if ((vlen(end - org) / shotspeed + 0.2) > maxtime)
203 targ.solid = savesolid;
207 if (!tracetossfaketarget)
208 tracetossfaketarget = spawn();
209 tracetossfaketarget.solid = savesolid;
210 tracetossfaketarget.movetype = targ.movetype;
211 setmodel(tracetossfaketarget, targ.model); // no low precision
212 tracetossfaketarget.model = targ.model;
213 tracetossfaketarget.modelindex = targ.modelindex;
214 setsize(tracetossfaketarget, targ.mins, targ.maxs);
215 setorigin(tracetossfaketarget, v);
218 dir = normalize(end - org);
219 while (c < 10) // 10 traces
221 setorigin(tracetossent, org); // reset
222 tracetossent.velocity = findtrajectory_velocity = normalize(dir) * shotspeed + shotspeedupward * '0 0 1';
223 tracetoss(tracetossent, ignore); // love builtin functions...
224 if (trace_ent == tracetossfaketarget) // done
226 targ.solid = savesolid;
229 tracetossfaketarget.solid = SOLID_NOT;
230 tracetossfaketarget.movetype = MOVETYPE_NONE;
231 tracetossfaketarget.model = "";
232 tracetossfaketarget.modelindex = 0;
233 // relink to remove it from physics considerations
234 setorigin(tracetossfaketarget, v);
238 dir_z = dir_z + 0.1; // aim up a little more
241 targ.solid = savesolid;
244 tracetossfaketarget.solid = SOLID_NOT;
245 tracetossfaketarget.movetype = MOVETYPE_NONE;
246 tracetossfaketarget.model = "";
247 tracetossfaketarget.modelindex = 0;
248 // relink to remove it from physics considerations
249 setorigin(tracetossfaketarget, v);
251 // leave a valid one even if it won't reach
252 findtrajectory_velocity = normalize(end - org) * shotspeed + shotspeedupward * '0 0 1';
260 .void(float t, float f1, float f2, entity e1, vector v1, vector v2, vector v3, vector v4) lag_func;
262 // upto 5 queued messages
266 .entity lag1_entity1;
275 .entity lag2_entity1;
284 .entity lag3_entity1;
293 .entity lag4_entity1;
302 .entity lag5_entity1;
310 if (self.lag1_time) if (time > self.lag1_time) {self.lag_func(self.lag1_time, self.lag1_float1, self.lag1_float2, self.lag1_entity1, self.lag1_vec1, self.lag1_vec2, self.lag1_vec3, self.lag1_vec4);self.lag1_time = 0;}
311 if (self.lag2_time) if (time > self.lag2_time) {self.lag_func(self.lag2_time, self.lag2_float1, self.lag2_float2, self.lag2_entity1, self.lag2_vec1, self.lag2_vec2, self.lag2_vec3, self.lag2_vec4);self.lag2_time = 0;}
312 if (self.lag3_time) if (time > self.lag3_time) {self.lag_func(self.lag3_time, self.lag3_float1, self.lag3_float2, self.lag3_entity1, self.lag3_vec1, self.lag3_vec2, self.lag3_vec3, self.lag3_vec4);self.lag3_time = 0;}
313 if (self.lag4_time) if (time > self.lag4_time) {self.lag_func(self.lag4_time, self.lag4_float1, self.lag4_float2, self.lag4_entity1, self.lag4_vec1, self.lag4_vec2, self.lag4_vec3, self.lag4_vec4);self.lag4_time = 0;}
314 if (self.lag5_time) if (time > self.lag5_time) {self.lag_func(self.lag5_time, self.lag5_float1, self.lag5_float2, self.lag5_entity1, self.lag5_vec1, self.lag5_vec2, self.lag5_vec3, self.lag5_vec4);self.lag5_time = 0;}
317 float(float t, float f1, float f2, entity e1, vector v1, vector v2, vector v3, vector v4) lag_additem =
319 if (self.lag1_time == 0) {self.lag1_time = t;self.lag1_float1 = f1;self.lag1_float2 = f2;self.lag1_entity1 = e1;self.lag1_vec1 = v1;self.lag1_vec2 = v2;self.lag1_vec3 = v3;self.lag1_vec4 = v4;return TRUE;}
320 if (self.lag2_time == 0) {self.lag2_time = t;self.lag2_float1 = f1;self.lag2_float2 = f2;self.lag2_entity1 = e1;self.lag2_vec1 = v1;self.lag2_vec2 = v2;self.lag2_vec3 = v3;self.lag2_vec4 = v4;return TRUE;}
321 if (self.lag3_time == 0) {self.lag3_time = t;self.lag3_float1 = f1;self.lag3_float2 = f2;self.lag3_entity1 = e1;self.lag3_vec1 = v1;self.lag3_vec2 = v2;self.lag3_vec3 = v3;self.lag3_vec4 = v4;return TRUE;}
322 if (self.lag4_time == 0) {self.lag4_time = t;self.lag4_float1 = f1;self.lag4_float2 = f2;self.lag4_entity1 = e1;self.lag4_vec1 = v1;self.lag4_vec2 = v2;self.lag4_vec3 = v3;self.lag4_vec4 = v4;return TRUE;}
323 if (self.lag5_time == 0) {self.lag5_time = t;self.lag5_float1 = f1;self.lag5_float2 = f2;self.lag5_entity1 = e1;self.lag5_vec1 = v1;self.lag5_vec2 = v2;self.lag5_vec3 = v3;self.lag5_vec4 = v4;return TRUE;}
324 // no room for it (what is the best thing to do here??)
329 // Random skill system
330 .float bot_thinkskill;
331 .float bot_mouseskill;
332 .float bot_predictionskill;
333 .float bot_offsetskill;
336 // waypoint navigation system
338 // itemscore = (howmuchmoreIwant / howmuchIcanwant) / itemdistance
339 // waypointscore = 0.7 / waypointdistance
341 .entity wp00, wp01, wp02, wp03, wp04, wp05, wp06, wp07;
342 .entity wp08, wp09, wp10, wp11, wp12, wp13, wp14, wp15;
343 .entity wp16, wp17, wp18, wp19, wp20, wp21, wp22, wp23, wp24, wp25, wp26, wp27, wp28, wp29, wp30, wp31;
344 .float wp00mincost, wp01mincost, wp02mincost, wp03mincost, wp04mincost, wp05mincost, wp06mincost, wp07mincost;
345 .float wp08mincost, wp09mincost, wp10mincost, wp11mincost, wp12mincost, wp13mincost, wp14mincost, wp15mincost;
346 .float wp16mincost, wp17mincost, wp18mincost, wp19mincost, wp20mincost, wp21mincost, wp22mincost, wp23mincost, wp24mincost, wp25mincost, wp26mincost, wp27mincost, wp28mincost, wp29mincost, wp30mincost, wp31mincost;
347 .float wpfire, wpcost;
350 .vector wpnearestpoint;
352 // stack of current goals (the last one of which may be an item or other
353 // desirable object, the rest are typically waypoints to reach it)
354 .entity goalcurrent, goalstack01, goalstack02, goalstack03;
355 .entity goalstack04, goalstack05, goalstack06, goalstack07;
356 .entity goalstack08, goalstack09, goalstack10, goalstack11;
357 .entity goalstack12, goalstack13, goalstack14, goalstack15;
358 .entity goalstack16, goalstack17, goalstack18, goalstack19;
359 .entity goalstack20, goalstack21, goalstack22, goalstack23;
360 .entity goalstack24, goalstack25, goalstack26, goalstack27;
361 .entity goalstack28, goalstack29, goalstack30, goalstack31;
363 .entity nearestwaypoint;
364 .float nearestwaypointtimeout;
366 // used during navigation_goalrating_begin/end sessions
367 float navigation_bestrating;
368 entity navigation_bestgoal;
374 /////////////////////////////////////////////////////////////////////////////
375 // waypoint management
376 /////////////////////////////////////////////////////////////////////////////
378 // waypoints with this flag are not saved, they are automatically generated
379 // waypoints like jump pads, teleporters, and items
380 float WAYPOINTFLAG_GENERATED = 8388608;
381 float WAYPOINTFLAG_ITEM = 4194304;
382 float WAYPOINTFLAG_TELEPORT = 2097152;
383 float WAYPOINTFLAG_NORELINK = 1048576;
385 // add a new link to the waypoint, replacing the furthest link it already has
386 void(entity from, entity to) waypoint_addlink =
392 if (from.wpflags & WAYPOINTFLAG_NORELINK)
395 if (from.wp00 == to) return;if (from.wp01 == to) return;if (from.wp02 == to) return;if (from.wp03 == to) return;
396 if (from.wp04 == to) return;if (from.wp05 == to) return;if (from.wp06 == to) return;if (from.wp07 == to) return;
397 if (from.wp08 == to) return;if (from.wp09 == to) return;if (from.wp10 == to) return;if (from.wp11 == to) return;
398 if (from.wp12 == to) return;if (from.wp13 == to) return;if (from.wp14 == to) return;if (from.wp15 == to) return;
399 if (from.wp16 == to) return;if (from.wp17 == to) return;if (from.wp18 == to) return;if (from.wp19 == to) return;
400 if (from.wp20 == to) return;if (from.wp21 == to) return;if (from.wp22 == to) return;if (from.wp23 == to) return;
401 if (from.wp24 == to) return;if (from.wp25 == to) return;if (from.wp26 == to) return;if (from.wp27 == to) return;
402 if (from.wp28 == to) return;if (from.wp29 == to) return;if (from.wp30 == to) return;if (from.wp31 == to) return;
404 if (to.wpisbox || from.wpisbox)
406 // if either is a box we have to find the nearest points on them to
407 // calculate the distance properly
408 local vector v1, v2, m1, m2;
412 v1_x = bound(m1_x, v1_x, m2_x);
413 v1_y = bound(m1_y, v1_y, m2_y);
414 v1_z = bound(m1_z, v1_z, m2_z);
418 v2_x = bound(m1_x, v2_x, m2_x);
419 v2_y = bound(m1_y, v2_y, m2_y);
420 v2_z = bound(m1_z, v2_z, m2_z);
425 c = vlen(to.origin - from.origin);
427 if (from.wp31mincost < c) return;
428 if (from.wp30mincost < c) {from.wp31 = to;from.wp31mincost = c;return;} from.wp31 = from.wp30;from.wp31mincost = from.wp30mincost;
429 if (from.wp29mincost < c) {from.wp30 = to;from.wp30mincost = c;return;} from.wp30 = from.wp29;from.wp30mincost = from.wp29mincost;
430 if (from.wp28mincost < c) {from.wp29 = to;from.wp29mincost = c;return;} from.wp29 = from.wp28;from.wp29mincost = from.wp28mincost;
431 if (from.wp27mincost < c) {from.wp28 = to;from.wp28mincost = c;return;} from.wp28 = from.wp27;from.wp28mincost = from.wp27mincost;
432 if (from.wp26mincost < c) {from.wp27 = to;from.wp27mincost = c;return;} from.wp27 = from.wp26;from.wp27mincost = from.wp26mincost;
433 if (from.wp25mincost < c) {from.wp26 = to;from.wp26mincost = c;return;} from.wp26 = from.wp25;from.wp26mincost = from.wp25mincost;
434 if (from.wp24mincost < c) {from.wp25 = to;from.wp25mincost = c;return;} from.wp25 = from.wp24;from.wp25mincost = from.wp24mincost;
435 if (from.wp23mincost < c) {from.wp24 = to;from.wp24mincost = c;return;} from.wp24 = from.wp23;from.wp24mincost = from.wp23mincost;
436 if (from.wp22mincost < c) {from.wp23 = to;from.wp23mincost = c;return;} from.wp23 = from.wp22;from.wp23mincost = from.wp22mincost;
437 if (from.wp21mincost < c) {from.wp22 = to;from.wp22mincost = c;return;} from.wp22 = from.wp21;from.wp22mincost = from.wp21mincost;
438 if (from.wp20mincost < c) {from.wp21 = to;from.wp21mincost = c;return;} from.wp21 = from.wp20;from.wp21mincost = from.wp20mincost;
439 if (from.wp19mincost < c) {from.wp20 = to;from.wp20mincost = c;return;} from.wp20 = from.wp19;from.wp20mincost = from.wp19mincost;
440 if (from.wp18mincost < c) {from.wp19 = to;from.wp19mincost = c;return;} from.wp19 = from.wp18;from.wp19mincost = from.wp18mincost;
441 if (from.wp17mincost < c) {from.wp18 = to;from.wp18mincost = c;return;} from.wp18 = from.wp17;from.wp18mincost = from.wp17mincost;
442 if (from.wp16mincost < c) {from.wp17 = to;from.wp17mincost = c;return;} from.wp17 = from.wp16;from.wp17mincost = from.wp16mincost;
443 if (from.wp15mincost < c) {from.wp16 = to;from.wp16mincost = c;return;} from.wp16 = from.wp15;from.wp16mincost = from.wp15mincost;
444 if (from.wp14mincost < c) {from.wp15 = to;from.wp15mincost = c;return;} from.wp15 = from.wp14;from.wp15mincost = from.wp14mincost;
445 if (from.wp13mincost < c) {from.wp14 = to;from.wp14mincost = c;return;} from.wp14 = from.wp13;from.wp14mincost = from.wp13mincost;
446 if (from.wp12mincost < c) {from.wp13 = to;from.wp13mincost = c;return;} from.wp13 = from.wp12;from.wp13mincost = from.wp12mincost;
447 if (from.wp11mincost < c) {from.wp12 = to;from.wp12mincost = c;return;} from.wp12 = from.wp11;from.wp12mincost = from.wp11mincost;
448 if (from.wp10mincost < c) {from.wp11 = to;from.wp11mincost = c;return;} from.wp11 = from.wp10;from.wp11mincost = from.wp10mincost;
449 if (from.wp09mincost < c) {from.wp10 = to;from.wp10mincost = c;return;} from.wp10 = from.wp09;from.wp10mincost = from.wp09mincost;
450 if (from.wp08mincost < c) {from.wp09 = to;from.wp09mincost = c;return;} from.wp09 = from.wp08;from.wp09mincost = from.wp08mincost;
451 if (from.wp07mincost < c) {from.wp08 = to;from.wp08mincost = c;return;} from.wp08 = from.wp07;from.wp08mincost = from.wp07mincost;
452 if (from.wp06mincost < c) {from.wp07 = to;from.wp07mincost = c;return;} from.wp07 = from.wp06;from.wp07mincost = from.wp06mincost;
453 if (from.wp05mincost < c) {from.wp06 = to;from.wp06mincost = c;return;} from.wp06 = from.wp05;from.wp06mincost = from.wp05mincost;
454 if (from.wp04mincost < c) {from.wp05 = to;from.wp05mincost = c;return;} from.wp05 = from.wp04;from.wp05mincost = from.wp04mincost;
455 if (from.wp03mincost < c) {from.wp04 = to;from.wp04mincost = c;return;} from.wp04 = from.wp03;from.wp04mincost = from.wp03mincost;
456 if (from.wp02mincost < c) {from.wp03 = to;from.wp03mincost = c;return;} from.wp03 = from.wp02;from.wp03mincost = from.wp02mincost;
457 if (from.wp01mincost < c) {from.wp02 = to;from.wp02mincost = c;return;} from.wp02 = from.wp01;from.wp02mincost = from.wp01mincost;
458 if (from.wp00mincost < c) {from.wp01 = to;from.wp01mincost = c;return;} from.wp01 = from.wp00;from.wp01mincost = from.wp00mincost;
459 from.wp00 = to;from.wp00mincost = c;return;
462 // relink this waypoint
463 // (precompile a list of all reachable waypoints from this waypoint)
465 void() waypoint_think =
468 local vector sv, sm1, sm2, ev, em1, em2;
469 //dprint("waypoint_think wpisbox = ", ftos(self.wpisbox), "\n");
470 sm1 = self.origin + self.mins;
471 sm2 = self.origin + self.maxs;
472 e = find(world, classname, "waypoint");
473 stepheightvec = cvar("sv_stepheight") * '0 0 1';
476 if (boxesoverlap(self.absmin, self.absmax, e.absmin, e.absmax))
478 waypoint_addlink(self, e);
479 waypoint_addlink(e, self);
484 sv_x = bound(sm1_x, sv_x, sm2_x);
485 sv_y = bound(sm1_y, sv_y, sm2_y);
486 sv_z = bound(sm1_z, sv_z, sm2_z);
488 em1 = e.origin + e.mins;
489 em2 = e.origin + e.maxs;
490 ev_x = bound(em1_x, ev_x, em2_x);
491 ev_y = bound(em1_y, ev_y, em2_y);
492 ev_z = bound(em1_z, ev_z, em2_z);
493 if (vlen(ev - sv) < self.wp31mincost)
495 navigation_testtracewalk = 0;
498 tracebox(sv - PL_MIN_z * '0 0 1', PL_MIN, PL_MAX, sv, FALSE, self);
499 if (!trace_startsolid)
501 //dprint("sv deviation", vtos(trace_endpos - sv), "\n");
502 sv = trace_endpos + '0 0 1';
507 tracebox(ev - PL_MIN_z * '0 0 1', PL_MIN, PL_MAX, ev, FALSE, e);
508 if (!trace_startsolid)
510 //dprint("ev deviation", vtos(trace_endpos - ev), "\n");
511 ev = trace_endpos + '0 0 1';
514 //traceline(self.origin, e.origin, FALSE, world);
515 //if (trace_fraction == 1)
517 if (tracewalk(self, sv, PL_MIN, PL_MAX, ev))
518 waypoint_addlink(self, e);
520 if (tracewalk(e, ev, PL_MIN, PL_MAX, sv))
521 waypoint_addlink(e, self);
524 e = find(e, classname, "waypoint");
526 navigation_testtracewalk = 0;
529 void(entity wp) waypoint_clearlinks =
531 // clear links to other waypoints
533 f = 1050; // maximum search range for other waypoints
534 wp.wp00 = wp.wp01 = wp.wp02 = wp.wp03 = wp.wp04 = wp.wp05 = wp.wp06 = wp.wp07 = world;wp.wp00mincost = wp.wp01mincost = wp.wp02mincost = wp.wp03mincost = wp.wp04mincost = wp.wp05mincost = wp.wp06mincost = wp.wp07mincost = f;
535 wp.wp08 = wp.wp09 = wp.wp10 = wp.wp11 = wp.wp12 = wp.wp13 = wp.wp14 = wp.wp15 = world;wp.wp08mincost = wp.wp09mincost = wp.wp10mincost = wp.wp11mincost = wp.wp12mincost = wp.wp13mincost = wp.wp14mincost = wp.wp15mincost = f;
536 wp.wp16 = wp.wp17 = wp.wp18 = wp.wp19 = wp.wp20 = wp.wp21 = wp.wp22 = wp.wp23 = world;wp.wp16mincost = wp.wp17mincost = wp.wp18mincost = wp.wp19mincost = wp.wp20mincost = wp.wp21mincost = wp.wp22mincost = wp.wp23mincost = f;
537 wp.wp24 = wp.wp25 = wp.wp26 = wp.wp27 = wp.wp28 = wp.wp29 = wp.wp30 = wp.wp31 = world;wp.wp24mincost = wp.wp25mincost = wp.wp26mincost = wp.wp27mincost = wp.wp28mincost = wp.wp29mincost = wp.wp30mincost = wp.wp31mincost = f;
540 // tell a waypoint to relink
541 void(entity wp) waypoint_schedulerelink =
545 // TODO: add some sort of visible box in edit mode for box waypoints
546 if (cvar("g_waypointeditor"))
551 setmodel(wp, "models/runematch/rune.mdl"); wp.effects = EF_LOWPRECISION;
556 wp.wpisbox = vlen(wp.size) > 0;
559 if (!(wp.wpflags & WAYPOINTFLAG_NORELINK))
560 waypoint_clearlinks(wp);
561 // schedule an actual relink on next frame
562 wp.think = waypoint_think;
564 wp.effects = EF_LOWPRECISION;
567 // create a new waypoint and automatically link it to other waypoints, and link
568 // them back to it as well
569 // (suitable for waypoint editor)
570 entity(vector m1, vector m2, float f) waypoint_spawn =
574 org = (m1 + m2) * 0.5;
577 w = find(world, classname, "waypoint");
580 // if a matching waypoint already exists, don't add a duplicate
581 if (w.origin == org && w.mins == m1 && w.maxs == m2)
583 w = find(w, classname, "waypoint");
586 w.classname = "waypoint";
589 setsize(w, PL_MIN + m1, PL_MAX + m2);
591 if(!(f & WAYPOINTFLAG_GENERATED))
593 org = w.origin + '0 0 2';
594 tracebox(org, w.mins, w.maxs, w.origin, MOVE_WORLDONLY, w);
597 org = w.origin + '2 2 2';
598 tracebox(org, w.mins, w.maxs, w.origin, MOVE_WORLDONLY, w);
601 org = w.origin + '-2 -2 2';
602 tracebox(org, w.mins, w.maxs, w.origin, MOVE_WORLDONLY, w);
605 org = w.origin + '-2 2 2';
606 tracebox(org, w.mins, w.maxs, w.origin, MOVE_WORLDONLY, w);
609 org = w.origin + '2 -2 2';
610 tracebox(org, w.mins, w.maxs, w.origin, MOVE_WORLDONLY, w);
613 // this WP is in solid, refuse it
614 dprint("Killed a waypoint that was stuck in solid at ", vtos(org), "\n");
623 org = org * 0.05 + trace_endpos * 0.95; // don't trust the trace fully
624 tracebox(org, w.mins, w.maxs, org - '0 0 128', MOVE_WORLDONLY, w);
626 if(trace_fraction == 1 || trace_startsolid)
628 // this WP is in air, refuse it
629 dprint("Killed a waypoint that was stuck in air/ceiling at ", vtos(w.origin), "\n");
633 trace_endpos_z += 0.1; // don't trust the trace fully
635 // dprint("Moved waypoint at ", vtos(w.origin), " by ", ftos(vlen(w.origin - trace_endpos)));
636 // dprint(" direction: ", vtos((trace_endpos - w.origin)), "\n");
638 setorigin(w, trace_endpos);
643 waypoint_clearlinks(w);
644 //waypoint_schedulerelink(w);
648 // waypoint map entity
651 setorigin(self, self.origin);
652 // schedule a relink after other waypoints have had a chance to spawn
653 waypoint_clearlinks(self);
654 //waypoint_schedulerelink(self);
657 // remove a waypoint, and schedule all neighbors to relink
658 void(entity e) waypoint_remove =
660 // tell all linked waypoints that they need to relink
661 waypoint_schedulerelink(e.wp00);
662 waypoint_schedulerelink(e.wp01);
663 waypoint_schedulerelink(e.wp02);
664 waypoint_schedulerelink(e.wp03);
665 waypoint_schedulerelink(e.wp04);
666 waypoint_schedulerelink(e.wp05);
667 waypoint_schedulerelink(e.wp06);
668 waypoint_schedulerelink(e.wp07);
669 waypoint_schedulerelink(e.wp08);
670 waypoint_schedulerelink(e.wp09);
671 waypoint_schedulerelink(e.wp10);
672 waypoint_schedulerelink(e.wp11);
673 waypoint_schedulerelink(e.wp12);
674 waypoint_schedulerelink(e.wp13);
675 waypoint_schedulerelink(e.wp14);
676 waypoint_schedulerelink(e.wp15);
677 waypoint_schedulerelink(e.wp16);
678 waypoint_schedulerelink(e.wp17);
679 waypoint_schedulerelink(e.wp18);
680 waypoint_schedulerelink(e.wp19);
681 waypoint_schedulerelink(e.wp20);
682 waypoint_schedulerelink(e.wp21);
683 waypoint_schedulerelink(e.wp22);
684 waypoint_schedulerelink(e.wp23);
685 waypoint_schedulerelink(e.wp24);
686 waypoint_schedulerelink(e.wp25);
687 waypoint_schedulerelink(e.wp26);
688 waypoint_schedulerelink(e.wp27);
689 waypoint_schedulerelink(e.wp28);
690 waypoint_schedulerelink(e.wp29);
691 waypoint_schedulerelink(e.wp30);
692 waypoint_schedulerelink(e.wp31);
693 // and now remove the waypoint
697 // empties the map of waypoints
698 void() waypoint_removeall =
700 local entity head, next;
701 head = findchain(classname, "waypoint");
710 // tell all waypoints to relink
711 // (is this useful at all?)
712 void() waypoint_schedulerelinkall =
715 head = findchain(classname, "waypoint");
718 waypoint_schedulerelink(head);
723 // save waypoints to gamedir/data/maps/mapname.waypoints
724 // TODO: support saving wayboxes
725 void() waypoint_saveall =
727 local string filename, s;
730 filename = strcat("maps/", mapname);
731 filename = strcat(filename, ".waypoints");
732 file = fopen(filename, FILE_WRITE);
736 w = findchain(classname, "waypoint");
739 if (!(w.wpflags & WAYPOINTFLAG_GENERATED))
741 s = strcat(vtos(w.origin + w.mins), "\n");
742 s = strcat(s, vtos(w.origin + w.maxs));
744 s = strcat(s, ftos(w.wpflags));
754 bprint(" waypoints to maps/");
756 bprint(".waypoints\n");
760 bprint("waypoint save to ");
766 // load waypoints from file
767 float() waypoint_loadall =
769 local string filename, s;
770 local float file, cwp, cwb, fl;
774 filename = strcat("maps/", mapname);
775 filename = strcat(filename, ".waypoints");
776 file = fopen(filename, FILE_READ);
793 waypoint_spawn(m1, m2, fl);
802 dprint(" waypoints and ");
804 dprint(" wayboxes from maps/");
806 dprint(".waypoints\n");
810 dprint("waypoint load from ");
817 void(entity e) waypoint_spawnforitem =
822 if(!bot_waypoints_for_items)
825 org = e.origin + (e.mins + e.maxs) * 0.5;
826 org_z = e.origin_z + e.mins_z - PL_MIN_z + 1;
827 e.nearestwaypointtimeout = time + 1000000000;
828 // don't spawn an item waypoint if it already exists
829 w = findchain(classname, "waypoint");
832 if (vlen(w.size) > 1)
834 if (boxesoverlap(org, org, w.absmin, w.absmax))
836 e.nearestwaypoint = w;
842 if (vlen(w.origin - org) < 16)
844 e.nearestwaypoint = w;
850 e.nearestwaypoint = waypoint_spawn(org, org, WAYPOINTFLAG_GENERATED | WAYPOINTFLAG_ITEM);
853 void(entity e, vector destination, float timetaken) waypoint_spawnforteleporter =
857 w = waypoint_spawn(e.absmin, e.absmax, WAYPOINTFLAG_GENERATED | WAYPOINTFLAG_TELEPORT | WAYPOINTFLAG_NORELINK);
858 dw = waypoint_spawn(destination, destination, WAYPOINTFLAG_GENERATED);
859 // one way link to the destination
861 w.wp00mincost = timetaken; // this is just for jump pads
862 // the teleporter's nearest waypoint is this one
863 // (teleporters are not goals, so this is probably useless)
864 e.nearestwaypoint = w;
865 e.nearestwaypointtimeout = time + 1000000000;
872 /////////////////////////////////////////////////////////////////////////////
874 /////////////////////////////////////////////////////////////////////////////
876 // completely empty the goal stack, used when deciding where to go
877 void() navigation_clearroute =
879 self.goalcurrent = world;
880 self.goalstack01 = world;
881 self.goalstack02 = world;
882 self.goalstack03 = world;
883 self.goalstack04 = world;
884 self.goalstack05 = world;
885 self.goalstack06 = world;
886 self.goalstack07 = world;
887 self.goalstack08 = world;
888 self.goalstack09 = world;
889 self.goalstack10 = world;
890 self.goalstack11 = world;
891 self.goalstack12 = world;
892 self.goalstack13 = world;
893 self.goalstack14 = world;
894 self.goalstack15 = world;
895 self.goalstack16 = world;
896 self.goalstack17 = world;
897 self.goalstack18 = world;
898 self.goalstack19 = world;
899 self.goalstack20 = world;
900 self.goalstack21 = world;
901 self.goalstack22 = world;
902 self.goalstack23 = world;
903 self.goalstack24 = world;
904 self.goalstack25 = world;
905 self.goalstack26 = world;
906 self.goalstack27 = world;
907 self.goalstack28 = world;
908 self.goalstack29 = world;
909 self.goalstack30 = world;
910 self.goalstack31 = world;
913 // add a new goal at the beginning of the stack
914 // (in other words: add a new prerequisite before going to the later goals)
915 void(entity e) navigation_pushroute =
917 self.goalstack31 = self.goalstack30;
918 self.goalstack30 = self.goalstack29;
919 self.goalstack29 = self.goalstack28;
920 self.goalstack28 = self.goalstack27;
921 self.goalstack27 = self.goalstack26;
922 self.goalstack26 = self.goalstack25;
923 self.goalstack25 = self.goalstack24;
924 self.goalstack24 = self.goalstack23;
925 self.goalstack23 = self.goalstack22;
926 self.goalstack22 = self.goalstack21;
927 self.goalstack21 = self.goalstack20;
928 self.goalstack20 = self.goalstack19;
929 self.goalstack19 = self.goalstack18;
930 self.goalstack18 = self.goalstack17;
931 self.goalstack17 = self.goalstack16;
932 self.goalstack16 = self.goalstack15;
933 self.goalstack15 = self.goalstack14;
934 self.goalstack14 = self.goalstack13;
935 self.goalstack13 = self.goalstack12;
936 self.goalstack12 = self.goalstack11;
937 self.goalstack11 = self.goalstack10;
938 self.goalstack10 = self.goalstack09;
939 self.goalstack09 = self.goalstack08;
940 self.goalstack08 = self.goalstack07;
941 self.goalstack07 = self.goalstack06;
942 self.goalstack06 = self.goalstack05;
943 self.goalstack05 = self.goalstack04;
944 self.goalstack04 = self.goalstack03;
945 self.goalstack03 = self.goalstack02;
946 self.goalstack02 = self.goalstack01;
947 self.goalstack01 = self.goalcurrent;
948 self.goalcurrent = e;
951 // remove first goal from stack
952 // (in other words: remove a prerequisite for reaching the later goals)
953 // (used when a waypoint is reached)
954 void() navigation_poproute =
956 self.goalcurrent = self.goalstack01;
957 self.goalstack01 = self.goalstack02;
958 self.goalstack02 = self.goalstack03;
959 self.goalstack03 = self.goalstack04;
960 self.goalstack04 = self.goalstack05;
961 self.goalstack05 = self.goalstack06;
962 self.goalstack06 = self.goalstack07;
963 self.goalstack07 = self.goalstack08;
964 self.goalstack08 = self.goalstack09;
965 self.goalstack09 = self.goalstack10;
966 self.goalstack10 = self.goalstack11;
967 self.goalstack11 = self.goalstack12;
968 self.goalstack12 = self.goalstack13;
969 self.goalstack13 = self.goalstack14;
970 self.goalstack14 = self.goalstack15;
971 self.goalstack15 = self.goalstack16;
972 self.goalstack16 = self.goalstack17;
973 self.goalstack17 = self.goalstack18;
974 self.goalstack18 = self.goalstack19;
975 self.goalstack19 = self.goalstack20;
976 self.goalstack20 = self.goalstack21;
977 self.goalstack21 = self.goalstack22;
978 self.goalstack22 = self.goalstack23;
979 self.goalstack23 = self.goalstack24;
980 self.goalstack24 = self.goalstack25;
981 self.goalstack25 = self.goalstack26;
982 self.goalstack26 = self.goalstack27;
983 self.goalstack27 = self.goalstack28;
984 self.goalstack28 = self.goalstack29;
985 self.goalstack29 = self.goalstack30;
986 self.goalstack30 = self.goalstack31;
987 self.goalstack31 = world;
990 // find the waypoint near a dynamic goal such as a dropped weapon
991 entity(entity player, float walkfromwp) navigation_findnearestwaypoint =
993 local entity waylist, w, best;
994 local float dist, bestdist;
996 org = player.origin + (player.mins_z - PL_MIN_z) * '0 0 1';
997 if(player.tag_entity)
998 org = org + player.tag_entity.origin;
999 if (navigation_testtracewalk)
1003 waylist = findchain(classname, "waypoint");
1004 // do two scans, because box test is cheaper
1008 // if object is touching waypoint
1009 if (boxesoverlap(org, org, w.absmin, w.absmax))
1013 // box check failed, try walk
1017 // if object can walk from waypoint
1020 local vector wm1, wm2;
1021 wm1 = w.origin + w.mins;
1022 wm2 = w.origin + w.maxs;
1023 v_x = bound(wm1_x, org_x, wm2_x);
1024 v_y = bound(wm1_y, org_y, wm2_y);
1025 v_z = bound(wm1_z, org_z, wm2_z);
1029 dist = vlen(v - org);
1030 if (bestdist > dist)
1034 traceline(v, org, TRUE, player);
1035 if (trace_fraction == 1)
1036 if (tracewalk(player, v, PL_MIN, PL_MAX, org))
1044 traceline(v, org, TRUE, player);
1045 if (trace_fraction == 1)
1046 if (tracewalk(player, org, PL_MIN, PL_MAX, v))
1058 // finds the waypoints near the bot initiating a navigation query
1059 void() navigation_markroutes_nearestwaypoints =
1063 local vector v, m1, m2;
1064 //navigation_testtracewalk = TRUE;
1065 head = findchain(classname, "waypoint");
1068 m1 = head.origin + head.mins;
1069 m2 = head.origin + head.maxs;
1071 v_x = bound(m1_x, v_x, m2_x);
1072 v_y = bound(m1_y, v_y, m2_y);
1073 v_z = bound(m1_z, v_z, m2_z);
1074 dist = vlen(v - self.origin);
1079 // if bot is very near a waypoint don't bother doing a trace
1080 head.wpnearestpoint = v;
1081 head.wpcost = dist + head.dmg;
1087 tracebox(self.origin, '-16 -16 0', '16 16 0', v, TRUE, self);
1088 if (trace_fraction == 1)
1090 if (tracewalk(self, self.origin, self.mins, self.maxs, v))
1092 head.wpnearestpoint = v;
1093 head.wpcost = dist + head.dmg;
1102 //navigation_testtracewalk = FALSE;
1105 // updates a path link if a waypoint link is better than the current one
1106 void(entity w, entity wp, float cost2, vector p) navigation_markroutes_checkwaypoint =
1115 v_x = bound(m1_x, p_x, m2_x);
1116 v_y = bound(m1_y, p_y, m2_y);
1117 v_z = bound(m1_z, p_z, m2_z);
1121 cost2 = cost2 + vlen(v);
1122 if (wp.wpcost > cost2)
1127 wp.wpnearestpoint = v;
1131 // queries the entire waypoint network for pathes leading away from the bot
1132 void() navigation_markroutes =
1134 local entity w, wp, waylist;
1135 local float searching, cost, cost2;
1137 w = waylist = findchain(classname, "waypoint");
1140 w.wpnearestpoint = '0 0 0';
1141 w.wpcost = 10000000;
1146 navigation_markroutes_nearestwaypoints();
1159 p = w.wpnearestpoint;
1160 wp = w.wp00;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp00mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1161 wp = w.wp01;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp01mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1162 wp = w.wp02;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp02mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1163 wp = w.wp03;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp03mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1164 wp = w.wp04;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp04mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1165 wp = w.wp05;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp05mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1166 wp = w.wp06;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp06mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1167 wp = w.wp07;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp07mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1168 wp = w.wp08;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp08mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1169 wp = w.wp09;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp09mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1170 wp = w.wp10;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp10mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1171 wp = w.wp11;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp11mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1172 wp = w.wp12;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp12mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1173 wp = w.wp13;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp13mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1174 wp = w.wp14;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp14mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1175 wp = w.wp15;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp15mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1176 wp = w.wp16;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp16mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1177 wp = w.wp17;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp17mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1178 wp = w.wp18;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp18mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1179 wp = w.wp19;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp19mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1180 wp = w.wp20;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp20mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1181 wp = w.wp21;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp21mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1182 wp = w.wp22;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp22mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1183 wp = w.wp23;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp23mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1184 wp = w.wp24;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp24mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1185 wp = w.wp25;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp25mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1186 wp = w.wp26;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp26mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1187 wp = w.wp27;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp27mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1188 wp = w.wp28;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp28mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1189 wp = w.wp29;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp29mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1190 wp = w.wp30;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp30mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1191 wp = w.wp31;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp31mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1192 }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
1199 // updates the best goal according to a weighted calculation of travel cost and item value of a new proposed item
1200 void(entity e, float f) navigation_routerating =
1204 //te_wizspike(e.origin);
1207 // update the cached waypoint link on a dynamic item entity
1208 if (time > e.nearestwaypointtimeout)
1210 e.nearestwaypoint = navigation_findnearestwaypoint(e, TRUE);
1211 e.nearestwaypointtimeout = time + random() * 3 + 5;
1213 if (e.nearestwaypoint)
1214 if (e.nearestwaypoint.wpcost < 10000000)
1216 //te_wizspike(e.nearestwaypoint.wpnearestpoint);
1217 f = f / ((e.nearestwaypoint.wpcost + vlen(e.origin - e.nearestwaypoint.wpnearestpoint)) * 0.001 + 1);
1218 if (navigation_bestrating < f)
1220 navigation_bestrating = f;
1221 navigation_bestgoal = e;
1226 // replaces the goal stack with the path to a given item
1227 void(entity e) navigation_routetogoal =
1229 // if already going to this goal, don't stop
1230 //if (self.goalentity == e)
1232 // clear the route and add the new one
1233 navigation_clearroute();
1234 self.goalentity = e;
1235 // if there is no goal, just exit
1238 // put the entity on the goal stack as the only item
1239 navigation_pushroute(e);
1240 //te_smallflash((e.absmin + e.absmax) * 0.5);
1241 //bprint("navigation_routetogoal(");
1245 tracebox(self.origin, '-16 -16 0', '16 16 0', e.origin, TRUE, self);
1246 if (trace_fraction == 1)
1247 if (tracewalk(self, self.origin, PL_MIN, PL_MAX, e.origin))
1249 // see if there are waypoints describing a path to the item
1250 e = e.nearestwaypoint;
1255 //te_smallflash((e.absmin + e.absmax) * 0.5);
1256 //tracebox(self.origin, '-16 -16 0', '16 16 0', e.origin, TRUE, self);
1257 //if (trace_fraction == 1)
1258 //if (tracewalk(self, self.origin, PL_MIN, PL_MAX, e.origin))
1260 // add the waypoint to the path
1261 navigation_pushroute(e);
1267 // removes any currently touching waypoints from the goal stack
1268 // (this is how bots detect if they have reached a goal)
1269 void() navigation_poptouchedgoals =
1271 local vector org, m1, m2;
1272 org = self.origin;// + self.velocity * 0.1;
1273 m1 = org + self.mins;
1274 m2 = org + self.maxs;
1275 while (self.goalcurrent && boxesoverlap(m1, m2, self.goalcurrent.absmin, self.goalcurrent.absmax))
1276 navigation_poproute();
1279 // begin a goal selection session (queries waypoint network)
1280 void() navigation_goalrating_start =
1282 navigation_bestrating = -1;
1283 navigation_bestgoal = world;
1284 navigation_markroutes();
1287 // ends a goal selection session (updates goal stack to the best goal)
1288 void() navigation_goalrating_end =
1290 navigation_routetogoal(navigation_bestgoal);
1297 //////////////////////////////////////////////////////////////////////////////
1298 // general bot functions
1299 //////////////////////////////////////////////////////////////////////////////
1301 .float isbot; // true if this client is actually a bot
1312 .float bot_dodgerating;
1314 //.float bot_painintensity;
1315 .float bot_firetimer;
1316 //.float bot_oldhealth;
1319 .entity bot_aimtarg;
1320 .float bot_aimlatency;
1321 .vector bot_aimselforigin;
1322 .vector bot_aimselfvelocity;
1323 .vector bot_aimtargorigin;
1324 .vector bot_aimtargvelocity;
1327 .float(entity player, entity item) bot_pickupevalfunc;
1328 .float bot_pickupbasevalue;
1331 // used for aiming currently
1332 // FIXME: make the weapon code use these and then replace the calculations here with a call to the weapon code
1336 const float BOTSKINS = 19;
1337 const float BOTNAMES = 32;
1338 string(float r) bot_namefornumber =
1340 if (r < 1) return "Thunderstorm";
1341 if (r < 2) return "Darkness";
1342 if (r < 3) return "Scorcher";
1343 if (r < 4) return "Paranoia";
1344 if (r < 5) return "Eureka";
1345 if (r < 6) return "Mystery";
1346 if (r < 7) return "Toxic";
1347 if (r < 8) return "Dominion";
1348 if (r < 9) return "Pegasus";
1349 if (r < 10) return "Sensible";
1350 if (r < 11) return "Gator";
1351 if (r < 12) return "Kangaroo";
1352 if (r < 13) return "Deadline";
1353 if (r < 14) return "Frosty";
1354 if (r < 15) return "Roadkill";
1355 if (r < 16) return "Death";
1356 if (r < 17) return "Panic";
1357 if (r < 18) return "Discovery";
1358 if (r < 19) return "Shadow";
1359 if (r < 20) return "Acidic";
1360 if (r < 21) return "Dominator";
1361 if (r < 22) return "Hellfire";
1362 if (r < 23) return "Necrotic";
1363 if (r < 24) return "Newbie";
1364 if (r < 25) return "Spellbinder";
1365 if (r < 26) return "Lion";
1366 if (r < 27) return "Controlled";
1367 if (r < 28) return "Airhead";
1368 if (r < 29) return "Delirium";
1369 if (r < 30) return "Resurrection";
1370 if (r < 31) return "Danger";
1374 string(float r) bot_skinfornumber =
1376 if (r < 1) {self.playermodel = "models/player/carni.zym" ;self.playerskin = "0";return "Carni" ;}
1377 else if (r < 2) {self.playermodel = "models/player/carni.zym" ;self.playerskin = "1";return "Armored Carni" ;}
1378 else if (r < 3) {self.playermodel = "models/player/crash.zym" ;self.playerskin = "0";return "Quark" ;}
1379 else if (r < 4) {self.playermodel = "models/player/grunt.zym" ;self.playerskin = "0";return "Grunt" ;}
1380 else if (r < 5) {self.playermodel = "models/player/headhunter.zym" ;self.playerskin = "0";return "HeadHunter" ;}
1381 else if (r < 6) {self.playermodel = "models/player/insurrectionist.zym";self.playerskin = "0";return "Insurrectionist";}
1382 else if (r < 7) {self.playermodel = "models/player/lurk.zym" ;self.playerskin = "0";return "Lurk" ;}
1383 else if (r < 8) {self.playermodel = "models/player/lurk.zym" ;self.playerskin = "1";return "Reptile" ;}
1384 else if (r < 9) {self.playermodel = "models/player/lycanthrope.zym" ;self.playerskin = "0";return "Lycanthrope" ;}
1385 else if (r < 10) {self.playermodel = "models/player/marine.zym" ;self.playerskin = "0";return "Marine" ;}
1386 else if (r < 11) {self.playermodel = "models/player/nexus.zym" ;self.playerskin = "0";return "Nexus" ;}
1387 else if (r < 12) {self.playermodel = "models/player/nexus.zym" ;self.playerskin = "1";return "Mulder" ;}
1388 else if (r < 13) {self.playermodel = "models/player/nexus.zym" ;self.playerskin = "2";return "Xolar" ;}
1389 else if (r < 14) {self.playermodel = "models/player/pyria.zym" ;self.playerskin = "0";return "Pyria" ;}
1390 else if (r < 15) {self.playermodel = "models/player/shock.zym" ;self.playerskin = "0";return "Shock" ;}
1391 else if (r < 16) {self.playermodel = "models/player/skadi.zym" ;self.playerskin = "0";return "Skadi" ;}
1392 else if (r < 17) {self.playermodel = "models/player/specop.zym" ;self.playerskin = "0";return "Specop" ;}
1393 else {self.playermodel = "models/player/visitant.zym" ;self.playerskin = "0";return "Fricka" ;}
1396 void() bot_setnameandstuff =
1398 local string name, prefix, suffix;
1399 local float r, b, shirt, pants;
1401 prefix = cvar_string("bot_prefix");
1402 suffix = cvar_string("bot_suffix");
1404 // this is really only a default, JoinBestTeam is called later
1405 pants = bound(0, floor(random() * 13), 13);
1406 //shirt = bound(0, floor(random() * 16), 15);
1408 self.clientcolors = shirt * 16 + pants;
1409 self.team = pants + 1;
1411 // now pick a name...
1413 if (cvar("bot_usemodelnames"))
1415 // first see if all skins are taken
1419 name = bot_skinfornumber(b);
1422 while (b < BOTSKINS && find(world, netname, name));
1424 // randomly pick a skin, if it's taken either repeat until we find one,
1425 // or give up if we already know all skins are taken
1428 r = floor(random() * BOTSKINS);
1429 name = bot_skinfornumber(r);
1431 while (b < BOTSKINS && find(world, netname, name));
1435 // first see if all names are taken
1439 name = bot_namefornumber(b);
1442 while (b < BOTNAMES && find(world, netname, name));
1444 // randomly pick a name, if it's taken either repeat until we find one,
1445 // or give up if we already know all names are taken
1448 r = floor(random() * BOTNAMES);
1449 name = bot_namefornumber(r);
1451 while (b < BOTNAMES && find(world, netname, name));
1453 // randomly pick a skin
1454 bot_skinfornumber(floor(random() * BOTSKINS));
1456 if(!cvar("g_campaign"))
1457 self.netname = strzone(strcat(prefix, name, suffix));
1459 self.netname = name;
1462 float bot_ignore_bots; // let bots not attack other bots (only works in non-teamplay)
1463 float(entity e) bot_shouldattack =
1465 if (e.team == self.team)
1475 if(clienttype(e) == CLIENTTYPE_BOT)
1486 void(float t, float f1, float f2, entity e1, vector v1, vector v2, vector v3, vector v4) bot_lagfunc =
1488 self.bot_aimtarg = e1;
1489 self.bot_aimlatency = self.ping; // FIXME? Shouldn't this be in the lag item?
1490 self.bot_aimselforigin = v1;
1491 self.bot_aimselfvelocity = v2;
1492 self.bot_aimtargorigin = v3;
1493 self.bot_aimtargvelocity = v4;
1495 self.bot_canfire = (random() < 0.8);
1497 self.bot_canfire = (random() < 0.9);
1499 self.bot_canfire = (random() < 0.95);
1501 self.bot_canfire = 1;
1504 .float bot_badaimtime;
1505 .float bot_aimthinktime;
1506 .vector bot_mouseaim;
1507 .vector bot_badaimoffset;
1508 .vector bot_1st_order_aimfilter;
1509 .vector bot_2nd_order_aimfilter;
1510 .vector bot_3th_order_aimfilter;
1511 .vector bot_4th_order_aimfilter;
1512 .vector bot_5th_order_aimfilter;
1513 .vector bot_olddesiredang;
1514 float(vector v, float maxfiredeviation) bot_aimdir =
1517 local float snapcos;
1518 local vector olddir, newdir, desireddir;
1520 makevectors(self.v_angle);
1521 olddir = newdir = v_forward;
1522 desireddir = normalize(v);
1523 snapcos = cos(cvar("bot_ai_aimskill_snapangle") * frametime * (skill + 1) * 0.5);
1524 if (desireddir * olddir < v_forward_x)
1525 newdir = desireddir;
1528 local float blendrate;
1529 blendrate = cvar("bot_ai_aimskill_blendrate") * frametime * (skill + 1) * 0.5;
1530 newdir = olddir + (desireddir - olddir) * bound(0, blendrate, 1);
1533 // decide whether to fire this time
1534 if ((desireddir * newdir) >= cos(maxfiredeviation))
1535 self.bot_firetimer = time + 0.3;
1537 self.v_angle = vectoangles(newdir);
1538 self.v_angle_x = self.v_angle_x * -1;
1540 makevectors(self.v_angle);
1541 shotorg = self.origin + self.view_ofs;
1544 return time < self.bot_firetimer;
1548 local vector desiredang, diffang;
1550 //dprint("aim ", self.netname, ": old:", vtos(self.v_angle));
1551 // make sure v_angle is sane first
1552 //self.v_angle_x = bound(-180, self.v_angle_x, 180);
1553 //while (self.v_angle_x < -180) self.v_angle_x = self.v_angle_x + 360;
1554 //while (self.v_angle_x >= 180) self.v_angle_x = self.v_angle_x - 360;
1555 while (self.v_angle_y < -180) self.v_angle_y = self.v_angle_y + 360;
1556 while (self.v_angle_y >= 180) self.v_angle_y = self.v_angle_y - 360;
1557 //while (self.v_angle_z < -180) self.v_angle_z = self.v_angle_z + 360;
1558 //while (self.v_angle_z >= 180) self.v_angle_z = self.v_angle_z - 360;
1561 // get the desired angles to aim at
1562 //dprint(" at:", vtos(v));
1564 //te_lightning2(world, self.origin + self.view_ofs, self.origin + self.view_ofs + v * 200);
1565 if (time >= self.bot_badaimtime)
1567 self.bot_badaimtime = max(self.bot_badaimtime + 0.3, time);
1568 self.bot_badaimoffset = randomvec() * bound(0, 5 - 0.5 * (skill+self.bot_offsetskill), 5);
1570 desiredang = vectoangles(v) + self.bot_badaimoffset*cvar("bot_ai_aimskill_offset");
1571 //dprint(" desired:", vtos(desiredang));
1572 if (desiredang_x >= 180)
1573 desiredang_x = desiredang_x - 360;
1574 desiredang_x = 0 - desiredang_x;
1575 desiredang_z = self.v_angle_z;
1576 desiredang_x = bound(-90, desiredang_x, 90);
1577 //dprint(" / ", vtos(desiredang));
1579 //// pain throws off aim
1580 //if (self.bot_painintensity)
1582 // // shake from pain
1583 // desiredang = desiredang + randomvec() * self.bot_painintensity * 0.2;
1586 // calculate turn angles
1587 diffang = (desiredang - self.bot_olddesiredang)*(1/frametime);
1588 self.bot_olddesiredang = desiredang;
1589 //dprint(" diff:", vtos(diffang));
1592 while (diffang_y < -180)
1593 diffang_y = diffang_y + 360;
1594 while (diffang_y > 180)
1595 diffang_y = diffang_y - 360;
1597 // Here we will try to anticipate the comming aiming direction
1598 self.bot_1st_order_aimfilter= self.bot_1st_order_aimfilter
1599 + (diffang - self.bot_1st_order_aimfilter) * bound(0, cvar("bot_ai_aimskill_order_filter_1st"),1);
1600 self.bot_2nd_order_aimfilter= self.bot_2nd_order_aimfilter
1601 + (self.bot_1st_order_aimfilter - self.bot_2nd_order_aimfilter) * bound(0, cvar("bot_ai_aimskill_order_filter_2nd"),1);
1602 self.bot_3th_order_aimfilter= self.bot_3th_order_aimfilter
1603 + (self.bot_2nd_order_aimfilter - self.bot_3th_order_aimfilter) * bound(0, cvar("bot_ai_aimskill_order_filter_3th"),1);
1604 self.bot_4th_order_aimfilter= self.bot_4th_order_aimfilter
1605 + (self.bot_3th_order_aimfilter - self.bot_4th_order_aimfilter) * bound(0, cvar("bot_ai_aimskill_order_filter_4th"),1);
1606 self.bot_5th_order_aimfilter= self.bot_5th_order_aimfilter
1607 + (self.bot_4th_order_aimfilter - self.bot_5th_order_aimfilter) * bound(0, cvar("bot_ai_aimskill_order_filter_5th"),1);
1610 //blend = (bound(0,skill,10)*0.1)*pow(1-bound(0,skill,10)*0.05,2.5)*5.656854249; //Plot formule before changing !
1611 blend = bound(0,skill,10)*0.1;
1612 desiredang = desiredang + blend *
1614 self.bot_1st_order_aimfilter * cvar("bot_ai_aimskill_order_mix_1st")
1615 + self.bot_2nd_order_aimfilter * cvar("bot_ai_aimskill_order_mix_2nd")
1616 + self.bot_3th_order_aimfilter * cvar("bot_ai_aimskill_order_mix_3th")
1617 + self.bot_4th_order_aimfilter * cvar("bot_ai_aimskill_order_mix_4th")
1618 + self.bot_5th_order_aimfilter * cvar("bot_ai_aimskill_order_mix_5th")
1620 while (desiredang_z < -180)
1621 desiredang_z = desiredang_z + 360;
1622 while (desiredang_z > 180)
1623 desiredang_z = desiredang_z - 360;
1624 // calculate turn angles
1625 diffang = desiredang - self.bot_mouseaim;
1626 //dprint(" diff:", vtos(diffang));
1629 while (diffang_y < -180)
1630 diffang_y = diffang_y + 360;
1631 while (diffang_y > 180)
1632 diffang_y = diffang_y - 360;
1634 if (time >= self.bot_aimthinktime)
1636 self.bot_aimthinktime = max(self.bot_aimthinktime + 0.5 - 0.05*(skill+self.bot_thinkskill), time);
1637 self.bot_mouseaim = self.bot_mouseaim + diffang * (1-random()*0.1*bound(1,10-skill,10));
1640 //self.v_angle = self.v_angle + diffang * bound(0, r * frametime * (skill * 0.5 + 2), 1);
1642 desiredang = self.bot_mouseaim*bound(0,cvar("bot_ai_aimskill_think"),1) + desiredang * bound(0,(1-cvar("bot_ai_aimskill_think")),1);
1644 // calculate turn angles
1645 diffang = desiredang - self.v_angle;
1646 //dprint(" diff:", vtos(diffang));
1649 while (diffang_y < -180)
1650 diffang_y = diffang_y + 360;
1651 while (diffang_y > 180)
1652 diffang_y = diffang_y - 360;
1653 // calculate turn angles
1654 diffang = desiredang - self.v_angle;
1655 //dprint(" diff:", vtos(diffang));
1658 while (diffang_y < -180)
1659 diffang_y = diffang_y + 360;
1660 while (diffang_y > 180)
1661 diffang_y = diffang_y - 360;
1664 dist = vlen(diffang);
1665 //diffang = diffang + randomvec() * (dist * 0.05 * (3.5 - bound(0, skill, 3)));
1668 local float r, fixedrate, blendrate;
1669 fixedrate = cvar("bot_ai_aimskill_fixedrate") / bound(1,dist,1000);
1670 blendrate = cvar("bot_ai_aimskill_blendrate");
1671 r = max(fixedrate, blendrate);
1672 //self.v_angle = self.v_angle + diffang * bound(frametime, r * frametime * (2+skill*skill*0.05-random()*0.05*(10-skill)), 1);
1673 self.v_angle = self.v_angle + diffang * bound(frametime, r * frametime * (2+pow(skill+self.bot_mouseskill,3)*0.005-random()), 1);
1674 self.v_angle = self.v_angle * bound(0,cvar("bot_ai_aimskill_mouse"),1) + desiredang * bound(0,(1-cvar("bot_ai_aimskill_mouse")),1);
1675 //self.v_angle = self.v_angle + diffang * bound(0, r * frametime * (skill * 0.5 + 2), 1);
1676 //self.v_angle = self.v_angle + diffang * (1/ blendrate);
1678 while (self.v_angle_y < -180)
1679 self.v_angle_y = self.v_angle_y + 360;
1680 while (self.v_angle_y >= 180)
1681 self.v_angle_y = self.v_angle_y - 360;
1682 //dprint(" turn:", vtos(self.v_angle));
1684 makevectors(self.v_angle);
1685 shotorg = self.origin + self.view_ofs;
1686 shotdir = v_forward;
1688 //dprint(" dir:", vtos(v_forward));
1689 //te_lightning2(world, shotorg, shotorg + shotdir * 100);
1691 // calculate turn angles again
1692 diffang = desiredang - self.v_angle;
1693 while (diffang_y < -180)
1694 diffang_y = diffang_y + 360;
1695 while (diffang_y > 180)
1696 diffang_y = diffang_y - 360;
1698 //bprint("e ");bprintvector(diffang);bprint(" < ");bprintfloat(maxfiredeviation);bprint("\n");
1700 // decide whether to fire this time
1701 // note the maxfiredeviation is in degrees so this has to convert to radians first
1702 //if ((normalize(v) * shotdir) >= cos(maxfiredeviation * (3.14159265358979323846 / 180)))
1703 if ((normalize(v) * shotdir) >= cos(maxfiredeviation * (3.14159265358979323846 / 180)))
1704 self.bot_firetimer = time + 0.3/bound(1,skill*0.3,3);
1705 traceline(shotorg,shotorg+shotdir*1000,FALSE,world);
1706 if ( vlen(trace_endpos-shotorg)>bound(0,skill*20,20) && random()<bound(0,skill*0.5,10)*frametime*2 )
1707 self.bot_canfire = 0;
1708 //dprint(ftos(maxfiredeviation),"\n");
1709 //dprint(" diff:", vtos(diffang), "\n");
1711 return self.bot_canfire && (time < self.bot_firetimer);
1714 vector(vector targorigin, vector targvelocity, float shotspeed, float shotdelay) bot_shotlead =
1716 // Try to add code here that predicts gravity effect here, no clue HOW to though ... well not yet atleast...
1717 return targorigin + targvelocity * (shotdelay + vlen(targorigin - shotorg) / shotspeed);
1720 float(float shotspeed, float shotspeedupward, float maxshottime, float applygravity) bot_aim =
1726 dprint("bot_aim(", ftos(shotspeed));
1727 dprint(", ", ftos(shotspeedupward));
1728 dprint(", ", ftos(maxshottime));
1729 dprint(", ", ftos(applygravity));
1734 dprint("bot_aim: WARNING: weapon ", W_Name(self.weapon), " shotspeed is zero!\n");
1735 shotspeed = 1000000;
1739 dprint("bot_aim: WARNING: weapon ", W_Name(self.weapon), " maxshottime is zero!\n");
1742 makevectors(self.v_angle);
1743 shotorg = self.origin + self.view_ofs;
1744 shotdir = v_forward;
1745 v = bot_shotlead(self.bot_aimtargorigin, self.bot_aimtargvelocity, shotspeed, self.bot_aimlatency);
1746 local float distanceratio;
1747 distanceratio =sqrt(bound(0,skill,10000))*0.3*(vlen(v-shotorg)-100)/cvar("bot_ai_aimskill_firetolerance_distdegrees");
1748 distanceratio = bound(0,distanceratio,1);
1749 r = (cvar("bot_ai_aimskill_firetolerance_maxdegrees")-cvar("bot_ai_aimskill_firetolerance_mindegrees"))
1750 * (1-distanceratio) + cvar("bot_ai_aimskill_firetolerance_mindegrees");
1751 if (applygravity && self.bot_aimtarg)
1753 if (!findtrajectorywithleading(shotorg, '0 0 0', '0 0 0', self.bot_aimtarg, shotspeed, shotspeedupward, maxshottime, 0, self))
1755 f = bot_aimdir(findtrajectory_velocity - shotspeedupward * '0 0 1', r);
1759 f = bot_aimdir(v - shotorg, r);
1760 //dprint("AIM: ");dprint(vtos(self.bot_aimtargorigin));dprint(" + ");dprint(vtos(self.bot_aimtargvelocity));dprint(" * ");dprint(ftos(self.bot_aimlatency + vlen(self.bot_aimtargorigin - shotorg) / shotspeed));dprint(" = ");dprint(vtos(v));dprint(" : aimdir = ");dprint(vtos(normalize(v - shotorg)));dprint(" : ");dprint(vtos(shotdir));dprint("\n");
1761 traceline(shotorg, shotorg + shotdir * 10000, FALSE, self);
1762 if (trace_ent.takedamage)
1763 if (trace_fraction < 1)
1764 if (!bot_shouldattack(trace_ent))
1766 traceline(shotorg, self.bot_aimtargorigin, FALSE, self);
1767 if (trace_fraction < 1)
1768 if (trace_ent != self.enemy)
1769 if (!bot_shouldattack(trace_ent))
1772 if (r > maxshottime * shotspeed)
1777 // TODO: move this painintensity code to the player damage code
1780 //if (self.bot_painintensity > 0)
1781 // self.bot_painintensity = self.bot_painintensity - (skill + 1) * 40 * frametime;
1783 //self.bot_painintensity = self.bot_painintensity + self.bot_oldhealth - self.health;
1784 //self.bot_painintensity = bound(0, self.bot_painintensity, 100);
1786 if(cvar("g_campaign") && !campaign_bots_may_start)
1788 self.nextthink = time + 0.5;
1794 self.v_angle = self.angles;
1796 self.fixangle = FALSE;
1801 self.dmg_inflictor = world;
1803 // calculate an aiming latency based on the skill setting
1804 // (simulated network latency + naturally delayed reflexes)
1805 //self.ping = 0.7 - bound(0, 0.05 * skill, 0.5); // moved the reflexes to bot_aimdir (under the name 'think')
1806 // minimum ping 20+10 random
1807 self.ping = bound(0,0.07 - bound(0, skill * 0.005,0.05)+random()*0.01,0.65); // Now holds real lag to server, and higer skill players take a less laggy server
1808 // skill 10 = ping 0.2 (adrenaline)
1809 // skill 0 = ping 0.7 (slightly drunk)
1821 self.buttonchat = 0;
1824 // if dead, just wait until we can respawn
1827 if (self.deadflag == DEAD_DEAD)
1828 self.button2 = 1; // press jump to respawn
1832 // now call the current bot AI (havocbot for example)
1836 entity bot_strategytoken;
1839 void() bot_relinkplayerlist =
1842 local entity prevbot;
1845 player_list = e = findchainflags(flags, FL_CLIENT);
1850 player_count = player_count + 1;
1851 e.nextplayer = e.chain;
1852 if (clienttype(e) == CLIENTTYPE_BOT)
1855 prevbot.nextbot = e;
1859 currentbots = currentbots + 1;
1863 dprint(strcat("relink: ", ftos(currentbots), " bots seen.\n"));
1864 bot_strategytoken = bot_list;
1867 void() havocbot_setupbot;
1868 float JoinBestTeam(entity pl, float only_return_best);
1870 void() bot_clientconnect =
1872 if (clienttype(self) != CLIENTTYPE_BOT)
1874 self.lag_func = bot_lagfunc;
1876 self.createdtime = self.nextthink;
1877 JoinBestTeam(self, FALSE);
1878 havocbot_setupbot();
1879 self.bot_mouseskill=random()-0.5;
1880 self.bot_thinkskill=random()-0.5;
1881 self.bot_predictionskill=random()-0.5;
1882 self.bot_offsetskill=random()-0.5;
1885 entity() bot_spawn =
1887 local entity oldself, bot;
1888 bot = spawnclient();
1891 currentbots = currentbots + 1;
1894 bot_setnameandstuff();
1896 PutClientInServer();
1902 void CheckAllowedTeams(); void GetTeamCounts(entity other); float c1, c2, c3, c4;
1903 void() bot_removefromlargestteam =
1905 local float besttime, bestcount, thiscount;
1906 local entity best, head;
1907 CheckAllowedTeams();
1908 GetTeamCounts(world);
1909 head = findchainfloat(isbot, TRUE);
1913 besttime = head.createdtime;
1917 if(head.team == COLOR_TEAM1)
1919 else if(head.team == COLOR_TEAM2)
1921 else if(head.team == COLOR_TEAM3)
1923 else if(head.team == COLOR_TEAM4)
1927 if (thiscount > bestcount)
1929 bestcount = thiscount;
1930 besttime = head.createdtime;
1933 else if (thiscount == bestcount && besttime < head.createdtime)
1935 besttime = head.createdtime;
1940 currentbots = currentbots - 1;
1944 void() bot_removenewest =
1946 local float besttime;
1947 local entity best, head;
1951 bot_removefromlargestteam();
1955 head = findchainfloat(isbot, TRUE);
1959 besttime = head.createdtime;
1962 if (besttime < head.createdtime)
1964 besttime = head.createdtime;
1969 currentbots = currentbots - 1;
1973 float botframe_waypointeditorlightningtime;
1974 void() botframe_showwaypointlinks =
1976 local entity player, head, w;
1977 if (time < botframe_waypointeditorlightningtime)
1979 botframe_waypointeditorlightningtime = time + 0.5;
1980 player = find(world, classname, "player");
1984 if (player.flags & FL_ONGROUND)
1986 //navigation_testtracewalk = TRUE;
1987 head = navigation_findnearestwaypoint(player, FALSE);
1988 //navigation_testtracewalk = FALSE;
1991 w = head ;if (w) te_lightning2(world, w.origin, player.origin);
1992 w = head.wp00;if (w) te_lightning2(world, w.origin, head.origin);
1993 w = head.wp01;if (w) te_lightning2(world, w.origin, head.origin);
1994 w = head.wp02;if (w) te_lightning2(world, w.origin, head.origin);
1995 w = head.wp03;if (w) te_lightning2(world, w.origin, head.origin);
1996 w = head.wp04;if (w) te_lightning2(world, w.origin, head.origin);
1997 w = head.wp05;if (w) te_lightning2(world, w.origin, head.origin);
1998 w = head.wp06;if (w) te_lightning2(world, w.origin, head.origin);
1999 w = head.wp07;if (w) te_lightning2(world, w.origin, head.origin);
2000 w = head.wp08;if (w) te_lightning2(world, w.origin, head.origin);
2001 w = head.wp09;if (w) te_lightning2(world, w.origin, head.origin);
2002 w = head.wp10;if (w) te_lightning2(world, w.origin, head.origin);
2003 w = head.wp11;if (w) te_lightning2(world, w.origin, head.origin);
2004 w = head.wp12;if (w) te_lightning2(world, w.origin, head.origin);
2005 w = head.wp13;if (w) te_lightning2(world, w.origin, head.origin);
2006 w = head.wp14;if (w) te_lightning2(world, w.origin, head.origin);
2007 w = head.wp15;if (w) te_lightning2(world, w.origin, head.origin);
2008 w = head.wp16;if (w) te_lightning2(world, w.origin, head.origin);
2009 w = head.wp17;if (w) te_lightning2(world, w.origin, head.origin);
2010 w = head.wp18;if (w) te_lightning2(world, w.origin, head.origin);
2011 w = head.wp19;if (w) te_lightning2(world, w.origin, head.origin);
2012 w = head.wp20;if (w) te_lightning2(world, w.origin, head.origin);
2013 w = head.wp21;if (w) te_lightning2(world, w.origin, head.origin);
2014 w = head.wp22;if (w) te_lightning2(world, w.origin, head.origin);
2015 w = head.wp23;if (w) te_lightning2(world, w.origin, head.origin);
2016 w = head.wp24;if (w) te_lightning2(world, w.origin, head.origin);
2017 w = head.wp25;if (w) te_lightning2(world, w.origin, head.origin);
2018 w = head.wp26;if (w) te_lightning2(world, w.origin, head.origin);
2019 w = head.wp27;if (w) te_lightning2(world, w.origin, head.origin);
2020 w = head.wp28;if (w) te_lightning2(world, w.origin, head.origin);
2021 w = head.wp29;if (w) te_lightning2(world, w.origin, head.origin);
2022 w = head.wp30;if (w) te_lightning2(world, w.origin, head.origin);
2023 w = head.wp31;if (w) te_lightning2(world, w.origin, head.origin);
2026 player = find(player, classname, "player");
2030 entity botframe_dangerwaypoint;
2031 void() botframe_updatedangerousobjects =
2033 local entity head, bot_dodgelist;
2034 local vector m1, m2, v;
2035 local float c, d, danger;
2037 bot_dodgelist = findchainfloat(bot_dodge, TRUE);
2038 botframe_dangerwaypoint = find(botframe_dangerwaypoint, classname, "waypoint");
2039 while (botframe_dangerwaypoint != world)
2042 m1 = botframe_dangerwaypoint.mins;
2043 m2 = botframe_dangerwaypoint.maxs;
2044 head = bot_dodgelist;
2048 v_x = bound(m1_x, v_x, m2_x);
2049 v_y = bound(m1_y, v_y, m2_y);
2050 v_z = bound(m1_z, v_z, m2_z);
2051 d = head.bot_dodgerating - vlen(head.origin - v);
2054 traceline(head.origin, v, TRUE, world);
2055 if (trace_fraction == 1)
2056 danger = danger + d;
2060 botframe_dangerwaypoint.dmg = danger;
2064 botframe_dangerwaypoint = find(botframe_dangerwaypoint, classname, "waypoint");
2069 float botframe_spawnedwaypoints;
2070 float botframe_nextthink;
2071 void() bot_serverframe =
2073 float realplayers, bots, activerealplayers;
2076 if (intermission_running)
2082 activerealplayers = 0;
2085 FOR_EACH_REALCLIENT(head)
2087 if(head.classname == "player" || cvar("g_lms") || cvar("g_arena"))
2088 ++activerealplayers;
2092 // add/remove bots if needed to make sure there are at least
2093 // minplayers+bot_number, or remove all bots if no one is playing
2094 // But don't remove bots immediately on level change, as the real players
2095 // usually haven't rejoined yet
2096 bots_would_leave = FALSE;
2097 if (realplayers || cvar("bot_join_empty") || (currentbots > 0 && time < 5))
2099 float realminplayers, minplayers;
2100 realminplayers = cvar("minplayers");
2101 minplayers = max(0, floor(realminplayers));
2103 float realminbots, minbots;
2104 realminbots = cvar("bot_number");
2105 minbots = max(0, floor(realminbots));
2107 bots = min(max(minbots, minplayers - activerealplayers), maxclients - realplayers);
2109 bots_would_leave = TRUE;
2113 // if there are no players, remove bots
2117 bot_ignore_bots = cvar("bot_ignore_bots");
2119 // only add one bot per frame to avoid utter chaos
2120 if(time > botframe_nextthink)
2122 //dprint(ftos(bots), " ? ", ftos(currentbots), "\n");
2123 while (currentbots < bots)
2125 if (bot_spawn() == world)
2127 bprint("Can not add bot, server full.\n");
2128 botframe_nextthink = time + 10;
2132 while (currentbots > bots)
2136 if(botframe_spawnedwaypoints)
2138 if(cvar("waypoint_benchmark"))
2142 if (currentbots > 0 || cvar("g_waypointeditor"))
2143 if (!botframe_spawnedwaypoints)
2145 botframe_spawnedwaypoints = TRUE;
2147 waypoint_schedulerelinkall();
2152 // cycle the goal token from one bot to the next each frame
2153 // (this prevents them from all doing waypoint searches on the same
2154 // frame, which causes choppy framerates)
2155 if (bot_strategytoken)
2156 bot_strategytoken = bot_strategytoken.nextbot;
2157 if (!bot_strategytoken)
2158 bot_strategytoken = bot_list;
2160 botframe_updatedangerousobjects();
2163 if (cvar("g_waypointeditor"))
2164 botframe_showwaypointlinks();