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, float movemode) 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, MOVE_NORMAL, e);
34 if (trace_dpstartcontents & (DPCONTENTS_SLIME | DPCONTENTS_LAVA))
36 tracebox(start, m1, m2, start, MOVE_NOMONSTERS, 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, MOVE_NORMAL, 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, movemode, 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, movemode, e);
111 if (trace_fraction < 1)
113 tracebox(org + stepheightvec, m1, m2, move + stepheightvec, movemode, 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 // trace down from stepheight as far as possible and move there,
130 // if this starts in solid we try again without the stepup, and
131 // if that also fails we assume it is a wall
132 // (this is the same logic as the Quake walkmove function used)
133 tracebox(move, m1, m2, move + '0 0 -65536', movemode, e);
135 if (trace_startsolid)
137 tracebox(move, m1, m2, move + '0 0 -65536', FALSE, e);
138 if (trace_startsolid)
140 if (navigation_testtracewalk)
142 if (navigation_testtracewalk > 1)
143 dprint("hit-something\n");
144 //move = normalize(end - org);
145 //particle(org, move * 64, 104, 4);
153 // moved successfully
154 if (navigation_testtracewalk > 1)
159 if (navigation_testtracewalk)
161 if (navigation_testtracewalk > 1)
162 dprint("wrong-place\n");
166 // moved but didn't arrive at the intended destination
171 // grenade tracing to decide the best pitch to fire at
174 entity tracetossfaketarget;
176 // traces multiple trajectories to find one that will impact the target
177 // 'end' vector is the place it aims for,
178 // returns TRUE only if it hit targ (don't target non-solid entities)
179 vector findtrajectory_velocity;
180 float(vector org, vector m1, vector m2, entity targ, float shotspeed, float shotspeedupward, float maxtime, float shotdelay, entity ignore) findtrajectorywithleading =
182 local float c, savesolid, shottime;
183 local vector dir, end, v;
185 return FALSE; // could cause division by zero if calculated
186 if (targ.solid < SOLID_BBOX) // SOLID_NOT and SOLID_TRIGGER
187 return FALSE; // could never hit it
189 tracetossent = spawn();
190 tracetossent.owner = ignore;
191 setsize(tracetossent, m1, m2);
192 savesolid = targ.solid;
193 targ.solid = SOLID_NOT;
194 shottime = ((vlen(targ.origin - org) / shotspeed) + shotdelay);
195 v = targ.velocity * shottime + targ.origin;
196 tracebox(targ.origin, targ.mins, targ.maxs, v, FALSE, targ);
198 end = v + (targ.mins + targ.maxs) * 0.5;
199 if ((vlen(end - org) / shotspeed + 0.2) > maxtime)
202 targ.solid = savesolid;
206 if (!tracetossfaketarget)
207 tracetossfaketarget = spawn();
208 tracetossfaketarget.solid = savesolid;
209 tracetossfaketarget.movetype = targ.movetype;
210 setmodel(tracetossfaketarget, targ.model); // no low precision
211 tracetossfaketarget.model = targ.model;
212 tracetossfaketarget.modelindex = targ.modelindex;
213 setsize(tracetossfaketarget, targ.mins, targ.maxs);
214 setorigin(tracetossfaketarget, v);
217 dir = normalize(end - org);
218 while (c < 10) // 10 traces
220 setorigin(tracetossent, org); // reset
221 tracetossent.velocity = findtrajectory_velocity = normalize(dir) * shotspeed + shotspeedupward * '0 0 1';
222 tracetoss(tracetossent, ignore); // love builtin functions...
223 if (trace_ent == tracetossfaketarget) // done
225 targ.solid = savesolid;
228 tracetossfaketarget.solid = SOLID_NOT;
229 tracetossfaketarget.movetype = MOVETYPE_NONE;
230 tracetossfaketarget.model = "";
231 tracetossfaketarget.modelindex = 0;
232 // relink to remove it from physics considerations
233 setorigin(tracetossfaketarget, v);
237 dir_z = dir_z + 0.1; // aim up a little more
240 targ.solid = savesolid;
243 tracetossfaketarget.solid = SOLID_NOT;
244 tracetossfaketarget.movetype = MOVETYPE_NONE;
245 tracetossfaketarget.model = "";
246 tracetossfaketarget.modelindex = 0;
247 // relink to remove it from physics considerations
248 setorigin(tracetossfaketarget, v);
250 // leave a valid one even if it won't reach
251 findtrajectory_velocity = normalize(end - org) * shotspeed + shotspeedupward * '0 0 1';
259 .void(float t, float f1, float f2, entity e1, vector v1, vector v2, vector v3, vector v4) lag_func;
261 // upto 5 queued messages
265 .entity lag1_entity1;
274 .entity lag2_entity1;
283 .entity lag3_entity1;
292 .entity lag4_entity1;
301 .entity lag5_entity1;
309 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;}
310 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;}
311 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;}
312 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;}
313 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;}
316 float(float t, float f1, float f2, entity e1, vector v1, vector v2, vector v3, vector v4) lag_additem =
318 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;}
319 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;}
320 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;}
321 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;}
322 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;}
323 // no room for it (what is the best thing to do here??)
328 // Random skill system
329 .float bot_thinkskill;
330 .float bot_mouseskill;
331 .float bot_predictionskill;
332 .float bot_offsetskill;
335 // waypoint navigation system
337 // itemscore = (howmuchmoreIwant / howmuchIcanwant) / itemdistance
338 // waypointscore = 0.7 / waypointdistance
340 .entity wp00, wp01, wp02, wp03, wp04, wp05, wp06, wp07;
341 .entity wp08, wp09, wp10, wp11, wp12, wp13, wp14, wp15;
342 .entity wp16, wp17, wp18, wp19, wp20, wp21, wp22, wp23, wp24, wp25, wp26, wp27, wp28, wp29, wp30, wp31;
343 .float wp00mincost, wp01mincost, wp02mincost, wp03mincost, wp04mincost, wp05mincost, wp06mincost, wp07mincost;
344 .float wp08mincost, wp09mincost, wp10mincost, wp11mincost, wp12mincost, wp13mincost, wp14mincost, wp15mincost;
345 .float wp16mincost, wp17mincost, wp18mincost, wp19mincost, wp20mincost, wp21mincost, wp22mincost, wp23mincost, wp24mincost, wp25mincost, wp26mincost, wp27mincost, wp28mincost, wp29mincost, wp30mincost, wp31mincost;
346 .float wpfire, wpcost, wpconsidered;
349 .vector wpnearestpoint;
351 // stack of current goals (the last one of which may be an item or other
352 // desirable object, the rest are typically waypoints to reach it)
353 .entity goalcurrent, goalstack01, goalstack02, goalstack03;
354 .entity goalstack04, goalstack05, goalstack06, goalstack07;
355 .entity goalstack08, goalstack09, goalstack10, goalstack11;
356 .entity goalstack12, goalstack13, goalstack14, goalstack15;
357 .entity goalstack16, goalstack17, goalstack18, goalstack19;
358 .entity goalstack20, goalstack21, goalstack22, goalstack23;
359 .entity goalstack24, goalstack25, goalstack26, goalstack27;
360 .entity goalstack28, goalstack29, goalstack30, goalstack31;
362 .entity nearestwaypoint;
363 .float nearestwaypointtimeout;
365 // used during navigation_goalrating_begin/end sessions
366 float navigation_bestrating;
367 entity navigation_bestgoal;
373 /////////////////////////////////////////////////////////////////////////////
374 // waypoint management
375 /////////////////////////////////////////////////////////////////////////////
377 // waypoints with this flag are not saved, they are automatically generated
378 // waypoints like jump pads, teleporters, and items
379 float WAYPOINTFLAG_GENERATED = 8388608;
380 float WAYPOINTFLAG_ITEM = 4194304;
381 float WAYPOINTFLAG_TELEPORT = 2097152;
382 float WAYPOINTFLAG_NORELINK = 1048576;
384 // add a new link to the waypoint, replacing the furthest link it already has
385 void(entity from, entity to) waypoint_addlink =
391 if (from.wpflags & WAYPOINTFLAG_NORELINK)
394 if (from.wp00 == to) return;if (from.wp01 == to) return;if (from.wp02 == to) return;if (from.wp03 == to) return;
395 if (from.wp04 == to) return;if (from.wp05 == to) return;if (from.wp06 == to) return;if (from.wp07 == to) return;
396 if (from.wp08 == to) return;if (from.wp09 == to) return;if (from.wp10 == to) return;if (from.wp11 == to) return;
397 if (from.wp12 == to) return;if (from.wp13 == to) return;if (from.wp14 == to) return;if (from.wp15 == to) return;
398 if (from.wp16 == to) return;if (from.wp17 == to) return;if (from.wp18 == to) return;if (from.wp19 == to) return;
399 if (from.wp20 == to) return;if (from.wp21 == to) return;if (from.wp22 == to) return;if (from.wp23 == to) return;
400 if (from.wp24 == to) return;if (from.wp25 == to) return;if (from.wp26 == to) return;if (from.wp27 == to) return;
401 if (from.wp28 == to) return;if (from.wp29 == to) return;if (from.wp30 == to) return;if (from.wp31 == to) return;
403 if (to.wpisbox || from.wpisbox)
405 // if either is a box we have to find the nearest points on them to
406 // calculate the distance properly
407 local vector v1, v2, m1, m2;
411 v1_x = bound(m1_x, v1_x, m2_x);
412 v1_y = bound(m1_y, v1_y, m2_y);
413 v1_z = bound(m1_z, v1_z, m2_z);
417 v2_x = bound(m1_x, v2_x, m2_x);
418 v2_y = bound(m1_y, v2_y, m2_y);
419 v2_z = bound(m1_z, v2_z, m2_z);
424 c = vlen(to.origin - from.origin);
426 if (from.wp31mincost < c) return;
427 if (from.wp30mincost < c) {from.wp31 = to;from.wp31mincost = c;return;} from.wp31 = from.wp30;from.wp31mincost = from.wp30mincost;
428 if (from.wp29mincost < c) {from.wp30 = to;from.wp30mincost = c;return;} from.wp30 = from.wp29;from.wp30mincost = from.wp29mincost;
429 if (from.wp28mincost < c) {from.wp29 = to;from.wp29mincost = c;return;} from.wp29 = from.wp28;from.wp29mincost = from.wp28mincost;
430 if (from.wp27mincost < c) {from.wp28 = to;from.wp28mincost = c;return;} from.wp28 = from.wp27;from.wp28mincost = from.wp27mincost;
431 if (from.wp26mincost < c) {from.wp27 = to;from.wp27mincost = c;return;} from.wp27 = from.wp26;from.wp27mincost = from.wp26mincost;
432 if (from.wp25mincost < c) {from.wp26 = to;from.wp26mincost = c;return;} from.wp26 = from.wp25;from.wp26mincost = from.wp25mincost;
433 if (from.wp24mincost < c) {from.wp25 = to;from.wp25mincost = c;return;} from.wp25 = from.wp24;from.wp25mincost = from.wp24mincost;
434 if (from.wp23mincost < c) {from.wp24 = to;from.wp24mincost = c;return;} from.wp24 = from.wp23;from.wp24mincost = from.wp23mincost;
435 if (from.wp22mincost < c) {from.wp23 = to;from.wp23mincost = c;return;} from.wp23 = from.wp22;from.wp23mincost = from.wp22mincost;
436 if (from.wp21mincost < c) {from.wp22 = to;from.wp22mincost = c;return;} from.wp22 = from.wp21;from.wp22mincost = from.wp21mincost;
437 if (from.wp20mincost < c) {from.wp21 = to;from.wp21mincost = c;return;} from.wp21 = from.wp20;from.wp21mincost = from.wp20mincost;
438 if (from.wp19mincost < c) {from.wp20 = to;from.wp20mincost = c;return;} from.wp20 = from.wp19;from.wp20mincost = from.wp19mincost;
439 if (from.wp18mincost < c) {from.wp19 = to;from.wp19mincost = c;return;} from.wp19 = from.wp18;from.wp19mincost = from.wp18mincost;
440 if (from.wp17mincost < c) {from.wp18 = to;from.wp18mincost = c;return;} from.wp18 = from.wp17;from.wp18mincost = from.wp17mincost;
441 if (from.wp16mincost < c) {from.wp17 = to;from.wp17mincost = c;return;} from.wp17 = from.wp16;from.wp17mincost = from.wp16mincost;
442 if (from.wp15mincost < c) {from.wp16 = to;from.wp16mincost = c;return;} from.wp16 = from.wp15;from.wp16mincost = from.wp15mincost;
443 if (from.wp14mincost < c) {from.wp15 = to;from.wp15mincost = c;return;} from.wp15 = from.wp14;from.wp15mincost = from.wp14mincost;
444 if (from.wp13mincost < c) {from.wp14 = to;from.wp14mincost = c;return;} from.wp14 = from.wp13;from.wp14mincost = from.wp13mincost;
445 if (from.wp12mincost < c) {from.wp13 = to;from.wp13mincost = c;return;} from.wp13 = from.wp12;from.wp13mincost = from.wp12mincost;
446 if (from.wp11mincost < c) {from.wp12 = to;from.wp12mincost = c;return;} from.wp12 = from.wp11;from.wp12mincost = from.wp11mincost;
447 if (from.wp10mincost < c) {from.wp11 = to;from.wp11mincost = c;return;} from.wp11 = from.wp10;from.wp11mincost = from.wp10mincost;
448 if (from.wp09mincost < c) {from.wp10 = to;from.wp10mincost = c;return;} from.wp10 = from.wp09;from.wp10mincost = from.wp09mincost;
449 if (from.wp08mincost < c) {from.wp09 = to;from.wp09mincost = c;return;} from.wp09 = from.wp08;from.wp09mincost = from.wp08mincost;
450 if (from.wp07mincost < c) {from.wp08 = to;from.wp08mincost = c;return;} from.wp08 = from.wp07;from.wp08mincost = from.wp07mincost;
451 if (from.wp06mincost < c) {from.wp07 = to;from.wp07mincost = c;return;} from.wp07 = from.wp06;from.wp07mincost = from.wp06mincost;
452 if (from.wp05mincost < c) {from.wp06 = to;from.wp06mincost = c;return;} from.wp06 = from.wp05;from.wp06mincost = from.wp05mincost;
453 if (from.wp04mincost < c) {from.wp05 = to;from.wp05mincost = c;return;} from.wp05 = from.wp04;from.wp05mincost = from.wp04mincost;
454 if (from.wp03mincost < c) {from.wp04 = to;from.wp04mincost = c;return;} from.wp04 = from.wp03;from.wp04mincost = from.wp03mincost;
455 if (from.wp02mincost < c) {from.wp03 = to;from.wp03mincost = c;return;} from.wp03 = from.wp02;from.wp03mincost = from.wp02mincost;
456 if (from.wp01mincost < c) {from.wp02 = to;from.wp02mincost = c;return;} from.wp02 = from.wp01;from.wp02mincost = from.wp01mincost;
457 if (from.wp00mincost < c) {from.wp01 = to;from.wp01mincost = c;return;} from.wp01 = from.wp00;from.wp01mincost = from.wp00mincost;
458 from.wp00 = to;from.wp00mincost = c;return;
461 // relink this waypoint
462 // (precompile a list of all reachable waypoints from this waypoint)
464 void() waypoint_think =
467 local vector sv, sm1, sm2, ev, em1, em2, dv;
468 //dprint("waypoint_think wpisbox = ", ftos(self.wpisbox), "\n");
469 sm1 = self.origin + self.mins;
470 sm2 = self.origin + self.maxs;
471 e = find(world, classname, "waypoint");
472 stepheightvec = cvar("sv_stepheight") * '0 0 1';
475 if (boxesoverlap(self.absmin, self.absmax, e.absmin, e.absmax))
477 waypoint_addlink(self, e);
478 waypoint_addlink(e, self);
483 sv_x = bound(sm1_x, sv_x, sm2_x);
484 sv_y = bound(sm1_y, sv_y, sm2_y);
485 sv_z = bound(sm1_z, sv_z, sm2_z);
487 em1 = e.origin + e.mins;
488 em2 = e.origin + e.maxs;
489 ev_x = bound(em1_x, ev_x, em2_x);
490 ev_y = bound(em1_y, ev_y, em2_y);
491 ev_z = bound(em1_z, ev_z, em2_z);
494 if (vlen(dv) < 1050) // max search distance in XY
496 navigation_testtracewalk = 0;
499 tracebox(sv - PL_MIN_z * '0 0 1', PL_MIN, PL_MAX, sv, FALSE, self);
500 if (!trace_startsolid)
502 //dprint("sv deviation", vtos(trace_endpos - sv), "\n");
503 sv = trace_endpos + '0 0 1';
508 tracebox(ev - PL_MIN_z * '0 0 1', PL_MIN, PL_MAX, ev, FALSE, e);
509 if (!trace_startsolid)
511 //dprint("ev deviation", vtos(trace_endpos - ev), "\n");
512 ev = trace_endpos + '0 0 1';
515 //traceline(self.origin, e.origin, FALSE, world);
516 //if (trace_fraction == 1)
518 if (tracewalk(self, sv, PL_MIN, PL_MAX, ev, MOVE_NOMONSTERS))
519 waypoint_addlink(self, e);
521 if (tracewalk(e, ev, PL_MIN, PL_MAX, sv, MOVE_NOMONSTERS))
522 waypoint_addlink(e, self);
525 e = find(e, classname, "waypoint");
527 navigation_testtracewalk = 0;
530 void(entity wp) waypoint_clearlinks =
532 // clear links to other waypoints
535 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;
536 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;
537 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;
538 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;
541 // tell a waypoint to relink
542 void(entity wp) waypoint_schedulerelink =
546 // TODO: add some sort of visible box in edit mode for box waypoints
547 if (cvar("g_waypointeditor"))
552 setmodel(wp, "models/runematch/rune.mdl"); wp.effects = EF_LOWPRECISION;
557 wp.wpisbox = vlen(wp.size) > 0;
560 if (!(wp.wpflags & WAYPOINTFLAG_NORELINK))
561 waypoint_clearlinks(wp);
562 // schedule an actual relink on next frame
563 wp.think = waypoint_think;
565 wp.effects = EF_LOWPRECISION;
568 // create a new waypoint and automatically link it to other waypoints, and link
569 // them back to it as well
570 // (suitable for waypoint editor)
571 entity(vector m1, vector m2, float f) waypoint_spawn =
575 org = (m1 + m2) * 0.5;
578 w = find(world, classname, "waypoint");
581 // if a matching waypoint already exists, don't add a duplicate
582 if (w.origin == org && w.mins == m1 && w.maxs == m2)
584 w = find(w, classname, "waypoint");
587 w.classname = "waypoint";
590 setsize(w, PL_MIN + m1, PL_MAX + m2);
592 if(!(f & WAYPOINTFLAG_GENERATED))
594 org = w.origin + '0 0 2';
595 tracebox(org, w.mins, w.maxs, w.origin, MOVE_WORLDONLY, w);
598 org = w.origin + '2 2 2';
599 tracebox(org, w.mins, w.maxs, w.origin, MOVE_WORLDONLY, w);
602 org = w.origin + '-2 -2 2';
603 tracebox(org, w.mins, w.maxs, w.origin, MOVE_WORLDONLY, w);
606 org = w.origin + '-2 2 2';
607 tracebox(org, w.mins, w.maxs, w.origin, MOVE_WORLDONLY, w);
610 org = w.origin + '2 -2 2';
611 tracebox(org, w.mins, w.maxs, w.origin, MOVE_WORLDONLY, w);
614 // this WP is in solid, refuse it
615 dprint("Killed a waypoint that was stuck in solid at ", vtos(org), "\n");
624 org = org * 0.05 + trace_endpos * 0.95; // don't trust the trace fully
625 tracebox(org, w.mins, w.maxs, org - '0 0 128', MOVE_WORLDONLY, w);
627 if(trace_fraction == 1 || trace_startsolid)
629 // this WP is in air, refuse it
630 dprint("Killed a waypoint that was stuck in air/ceiling at ", vtos(w.origin), "\n");
634 trace_endpos_z += 0.1; // don't trust the trace fully
636 // dprint("Moved waypoint at ", vtos(w.origin), " by ", ftos(vlen(w.origin - trace_endpos)));
637 // dprint(" direction: ", vtos((trace_endpos - w.origin)), "\n");
639 setorigin(w, trace_endpos);
644 waypoint_clearlinks(w);
645 //waypoint_schedulerelink(w);
649 // waypoint map entity
652 setorigin(self, self.origin);
653 // schedule a relink after other waypoints have had a chance to spawn
654 waypoint_clearlinks(self);
655 //waypoint_schedulerelink(self);
658 // remove a waypoint, and schedule all neighbors to relink
659 void(entity e) waypoint_remove =
661 // tell all linked waypoints that they need to relink
662 waypoint_schedulerelink(e.wp00);
663 waypoint_schedulerelink(e.wp01);
664 waypoint_schedulerelink(e.wp02);
665 waypoint_schedulerelink(e.wp03);
666 waypoint_schedulerelink(e.wp04);
667 waypoint_schedulerelink(e.wp05);
668 waypoint_schedulerelink(e.wp06);
669 waypoint_schedulerelink(e.wp07);
670 waypoint_schedulerelink(e.wp08);
671 waypoint_schedulerelink(e.wp09);
672 waypoint_schedulerelink(e.wp10);
673 waypoint_schedulerelink(e.wp11);
674 waypoint_schedulerelink(e.wp12);
675 waypoint_schedulerelink(e.wp13);
676 waypoint_schedulerelink(e.wp14);
677 waypoint_schedulerelink(e.wp15);
678 waypoint_schedulerelink(e.wp16);
679 waypoint_schedulerelink(e.wp17);
680 waypoint_schedulerelink(e.wp18);
681 waypoint_schedulerelink(e.wp19);
682 waypoint_schedulerelink(e.wp20);
683 waypoint_schedulerelink(e.wp21);
684 waypoint_schedulerelink(e.wp22);
685 waypoint_schedulerelink(e.wp23);
686 waypoint_schedulerelink(e.wp24);
687 waypoint_schedulerelink(e.wp25);
688 waypoint_schedulerelink(e.wp26);
689 waypoint_schedulerelink(e.wp27);
690 waypoint_schedulerelink(e.wp28);
691 waypoint_schedulerelink(e.wp29);
692 waypoint_schedulerelink(e.wp30);
693 waypoint_schedulerelink(e.wp31);
694 // and now remove the waypoint
698 // empties the map of waypoints
699 void() waypoint_removeall =
701 local entity head, next;
702 head = findchain(classname, "waypoint");
711 // tell all waypoints to relink
712 // (is this useful at all?)
713 void() waypoint_schedulerelinkall =
716 head = findchain(classname, "waypoint");
719 waypoint_schedulerelink(head);
724 // save waypoints to gamedir/data/maps/mapname.waypoints
725 // TODO: support saving wayboxes
726 void() waypoint_saveall =
728 local string filename, s;
731 filename = strcat("maps/", mapname);
732 filename = strcat(filename, ".waypoints");
733 file = fopen(filename, FILE_WRITE);
737 w = findchain(classname, "waypoint");
740 if (!(w.wpflags & WAYPOINTFLAG_GENERATED))
742 s = strcat(vtos(w.origin + w.mins), "\n");
743 s = strcat(s, vtos(w.origin + w.maxs));
745 s = strcat(s, ftos(w.wpflags));
755 bprint(" waypoints to maps/");
757 bprint(".waypoints\n");
761 bprint("waypoint save to ");
767 // load waypoints from file
768 float() waypoint_loadall =
770 local string filename, s;
771 local float file, cwp, cwb, fl;
775 filename = strcat("maps/", mapname);
776 filename = strcat(filename, ".waypoints");
777 file = fopen(filename, FILE_READ);
794 waypoint_spawn(m1, m2, fl);
803 dprint(" waypoints and ");
805 dprint(" wayboxes from maps/");
807 dprint(".waypoints\n");
811 dprint("waypoint load from ");
818 void(entity e) waypoint_spawnforitem =
823 if(!bot_waypoints_for_items)
826 org = e.origin + (e.mins + e.maxs) * 0.5;
827 org_z = e.origin_z + e.mins_z - PL_MIN_z + 1;
828 e.nearestwaypointtimeout = time + 1000000000;
829 // don't spawn an item waypoint if it already exists
830 w = findchain(classname, "waypoint");
833 if (vlen(w.size) > 1)
835 if (boxesoverlap(org, org, w.absmin, w.absmax))
837 e.nearestwaypoint = w;
843 if (vlen(w.origin - org) < 16)
845 e.nearestwaypoint = w;
851 e.nearestwaypoint = waypoint_spawn(org, org, WAYPOINTFLAG_GENERATED | WAYPOINTFLAG_ITEM);
854 void(entity e, vector destination, float timetaken) waypoint_spawnforteleporter =
858 w = waypoint_spawn(e.absmin, e.absmax, WAYPOINTFLAG_GENERATED | WAYPOINTFLAG_TELEPORT | WAYPOINTFLAG_NORELINK);
859 dw = waypoint_spawn(destination, destination, WAYPOINTFLAG_GENERATED);
860 // one way link to the destination
862 w.wp00mincost = timetaken; // this is just for jump pads
863 // the teleporter's nearest waypoint is this one
864 // (teleporters are not goals, so this is probably useless)
865 e.nearestwaypoint = w;
866 e.nearestwaypointtimeout = time + 1000000000;
873 /////////////////////////////////////////////////////////////////////////////
875 /////////////////////////////////////////////////////////////////////////////
877 // completely empty the goal stack, used when deciding where to go
878 void() navigation_clearroute =
880 self.goalcurrent = world;
881 self.goalstack01 = world;
882 self.goalstack02 = world;
883 self.goalstack03 = world;
884 self.goalstack04 = world;
885 self.goalstack05 = world;
886 self.goalstack06 = world;
887 self.goalstack07 = world;
888 self.goalstack08 = world;
889 self.goalstack09 = world;
890 self.goalstack10 = world;
891 self.goalstack11 = world;
892 self.goalstack12 = world;
893 self.goalstack13 = world;
894 self.goalstack14 = world;
895 self.goalstack15 = world;
896 self.goalstack16 = world;
897 self.goalstack17 = world;
898 self.goalstack18 = world;
899 self.goalstack19 = world;
900 self.goalstack20 = world;
901 self.goalstack21 = world;
902 self.goalstack22 = world;
903 self.goalstack23 = world;
904 self.goalstack24 = world;
905 self.goalstack25 = world;
906 self.goalstack26 = world;
907 self.goalstack27 = world;
908 self.goalstack28 = world;
909 self.goalstack29 = world;
910 self.goalstack30 = world;
911 self.goalstack31 = world;
914 // add a new goal at the beginning of the stack
915 // (in other words: add a new prerequisite before going to the later goals)
916 void(entity e) navigation_pushroute =
918 self.goalstack31 = self.goalstack30;
919 self.goalstack30 = self.goalstack29;
920 self.goalstack29 = self.goalstack28;
921 self.goalstack28 = self.goalstack27;
922 self.goalstack27 = self.goalstack26;
923 self.goalstack26 = self.goalstack25;
924 self.goalstack25 = self.goalstack24;
925 self.goalstack24 = self.goalstack23;
926 self.goalstack23 = self.goalstack22;
927 self.goalstack22 = self.goalstack21;
928 self.goalstack21 = self.goalstack20;
929 self.goalstack20 = self.goalstack19;
930 self.goalstack19 = self.goalstack18;
931 self.goalstack18 = self.goalstack17;
932 self.goalstack17 = self.goalstack16;
933 self.goalstack16 = self.goalstack15;
934 self.goalstack15 = self.goalstack14;
935 self.goalstack14 = self.goalstack13;
936 self.goalstack13 = self.goalstack12;
937 self.goalstack12 = self.goalstack11;
938 self.goalstack11 = self.goalstack10;
939 self.goalstack10 = self.goalstack09;
940 self.goalstack09 = self.goalstack08;
941 self.goalstack08 = self.goalstack07;
942 self.goalstack07 = self.goalstack06;
943 self.goalstack06 = self.goalstack05;
944 self.goalstack05 = self.goalstack04;
945 self.goalstack04 = self.goalstack03;
946 self.goalstack03 = self.goalstack02;
947 self.goalstack02 = self.goalstack01;
948 self.goalstack01 = self.goalcurrent;
949 self.goalcurrent = e;
952 // remove first goal from stack
953 // (in other words: remove a prerequisite for reaching the later goals)
954 // (used when a waypoint is reached)
955 void() navigation_poproute =
957 self.goalcurrent = self.goalstack01;
958 self.goalstack01 = self.goalstack02;
959 self.goalstack02 = self.goalstack03;
960 self.goalstack03 = self.goalstack04;
961 self.goalstack04 = self.goalstack05;
962 self.goalstack05 = self.goalstack06;
963 self.goalstack06 = self.goalstack07;
964 self.goalstack07 = self.goalstack08;
965 self.goalstack08 = self.goalstack09;
966 self.goalstack09 = self.goalstack10;
967 self.goalstack10 = self.goalstack11;
968 self.goalstack11 = self.goalstack12;
969 self.goalstack12 = self.goalstack13;
970 self.goalstack13 = self.goalstack14;
971 self.goalstack14 = self.goalstack15;
972 self.goalstack15 = self.goalstack16;
973 self.goalstack16 = self.goalstack17;
974 self.goalstack17 = self.goalstack18;
975 self.goalstack18 = self.goalstack19;
976 self.goalstack19 = self.goalstack20;
977 self.goalstack20 = self.goalstack21;
978 self.goalstack21 = self.goalstack22;
979 self.goalstack22 = self.goalstack23;
980 self.goalstack23 = self.goalstack24;
981 self.goalstack24 = self.goalstack25;
982 self.goalstack25 = self.goalstack26;
983 self.goalstack26 = self.goalstack27;
984 self.goalstack27 = self.goalstack28;
985 self.goalstack28 = self.goalstack29;
986 self.goalstack29 = self.goalstack30;
987 self.goalstack30 = self.goalstack31;
988 self.goalstack31 = world;
991 // find the waypoint near a dynamic goal such as a dropped weapon
992 entity(entity player, float walkfromwp) navigation_findnearestwaypoint =
994 local entity waylist, w, best;
995 local float dist, bestdist;
996 local vector v, org, pm1, pm2;
997 pm1 = player.origin + PL_MIN;
998 pm2 = player.origin + PL_MAX;
999 waylist = findchain(classname, "waypoint");
1000 // do two scans, because box test is cheaper
1004 // if object is touching waypoint
1005 if (boxesoverlap(pm1, pm2, w.absmin, w.absmax))
1010 org = player.origin + (player.mins_z - PL_MIN_z) * '0 0 1';
1011 if(player.tag_entity)
1012 org = org + player.tag_entity.origin;
1013 if (navigation_testtracewalk)
1018 // box check failed, try walk
1022 // if object can walk from waypoint
1025 local vector wm1, wm2;
1026 wm1 = w.origin + w.mins;
1027 wm2 = w.origin + w.maxs;
1028 v_x = bound(wm1_x, org_x, wm2_x);
1029 v_y = bound(wm1_y, org_y, wm2_y);
1030 v_z = bound(wm1_z, org_z, wm2_z);
1034 dist = vlen(v - org);
1035 if (bestdist > dist)
1039 traceline(v, org, TRUE, player);
1040 if (trace_fraction == 1)
1041 if (tracewalk(player, v, PL_MIN, PL_MAX, org, MOVE_NORMAL))
1049 traceline(v, org, TRUE, player);
1050 if (trace_fraction == 1)
1051 if (tracewalk(player, org, PL_MIN, PL_MAX, v, MOVE_NORMAL))
1063 // finds the waypoints near the bot initiating a navigation query
1064 float(entity waylist, float maxdist) navigation_markroutes_nearestwaypoints =
1067 local vector v, m1, m2, diff;
1069 //navigation_testtracewalk = TRUE;
1074 if (!head.wpconsidered)
1078 m1 = head.origin + head.mins;
1079 m2 = head.origin + head.maxs;
1081 v_x = bound(m1_x, v_x, m2_x);
1082 v_y = bound(m1_y, v_y, m2_y);
1083 v_z = bound(m1_z, v_z, m2_z);
1087 diff = v - self.origin;
1088 diff_z = max(0, diff_z);
1089 if (vlen(diff) < maxdist)
1091 head.wpconsidered = TRUE;
1092 if (tracewalk(self, self.origin, self.mins, self.maxs, v, MOVE_NORMAL))
1094 head.wpnearestpoint = v;
1095 head.wpcost = vlen(v - self.origin) + head.dmg;
1104 //navigation_testtracewalk = FALSE;
1108 // updates a path link if a waypoint link is better than the current one
1109 void(entity w, entity wp, float cost2, vector p) navigation_markroutes_checkwaypoint =
1118 v_x = bound(m1_x, p_x, m2_x);
1119 v_y = bound(m1_y, p_y, m2_y);
1120 v_z = bound(m1_z, p_z, m2_z);
1124 cost2 = cost2 + vlen(v);
1125 if (wp.wpcost > cost2)
1130 wp.wpnearestpoint = v;
1134 // queries the entire waypoint network for pathes leading away from the bot
1135 void() navigation_markroutes =
1137 local entity w, wp, waylist;
1138 local float searching, cost, cost2;
1140 w = waylist = findchain(classname, "waypoint");
1143 w.wpconsidered = FALSE;
1144 w.wpnearestpoint = '0 0 0';
1145 w.wpcost = 10000000;
1150 // try a short range search for the nearest waypoints, and expand the
1151 // search repeatedly if none are found
1152 if (!navigation_markroutes_nearestwaypoints(waylist, 250))
1153 if (!navigation_markroutes_nearestwaypoints(waylist, 1000))
1154 navigation_markroutes_nearestwaypoints(waylist, 1000000);
1167 p = w.wpnearestpoint;
1168 wp = w.wp00;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp00mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1169 wp = w.wp01;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp01mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1170 wp = w.wp02;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp02mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1171 wp = w.wp03;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp03mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1172 wp = w.wp04;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp04mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1173 wp = w.wp05;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp05mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1174 wp = w.wp06;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp06mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1175 wp = w.wp07;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp07mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1176 wp = w.wp08;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp08mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1177 wp = w.wp09;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp09mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1178 wp = w.wp10;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp10mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1179 wp = w.wp11;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp11mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1180 wp = w.wp12;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp12mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1181 wp = w.wp13;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp13mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1182 wp = w.wp14;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp14mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1183 wp = w.wp15;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp15mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1184 wp = w.wp16;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp16mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1185 wp = w.wp17;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp17mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1186 wp = w.wp18;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp18mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1187 wp = w.wp19;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp19mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1188 wp = w.wp20;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp20mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1189 wp = w.wp21;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp21mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1190 wp = w.wp22;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp22mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1191 wp = w.wp23;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp23mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1192 wp = w.wp24;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp24mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1193 wp = w.wp25;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp25mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1194 wp = w.wp26;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp26mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1195 wp = w.wp27;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp27mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1196 wp = w.wp28;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp28mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1197 wp = w.wp29;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp29mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1198 wp = w.wp30;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp30mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1199 wp = w.wp31;if (wp){cost2 = cost + wp.dmg;if (wp.wpcost > cost2 + wp.wp31mincost) navigation_markroutes_checkwaypoint(w, wp, cost2, p);
1200 }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
1207 // updates the best goal according to a weighted calculation of travel cost and item value of a new proposed item
1208 void(entity e, float f) navigation_routerating =
1212 //te_wizspike(e.origin);
1215 // update the cached waypoint link on a dynamic item entity
1216 if (time > e.nearestwaypointtimeout)
1218 e.nearestwaypoint = navigation_findnearestwaypoint(e, TRUE);
1219 e.nearestwaypointtimeout = time + random() * 3 + 5;
1221 //dprint(e.classname, " ", ftos(f));
1222 if (e.nearestwaypoint)
1223 if (e.nearestwaypoint.wpcost < 10000000)
1225 //te_wizspike(e.nearestwaypoint.wpnearestpoint);
1226 //dprint(e.classname, " ", ftos(f), "*(500/(500+", ftos((e.nearestwaypoint.wpcost + vlen(e.origin - e.nearestwaypoint.wpnearestpoint))), " = ");
1227 f = f * 500 / ((e.nearestwaypoint.wpcost + vlen(e.origin - e.nearestwaypoint.wpnearestpoint)) + 500);
1229 if (navigation_bestrating < f)
1231 navigation_bestrating = f;
1232 navigation_bestgoal = e;
1238 // replaces the goal stack with the path to a given item
1239 void(entity e) navigation_routetogoal =
1241 // if already going to this goal, don't stop
1242 //if (self.goalentity == e)
1244 // clear the route and add the new one
1245 navigation_clearroute();
1246 self.goalentity = e;
1247 // if there is no goal, just exit
1250 // put the entity on the goal stack as the only item
1251 navigation_pushroute(e);
1252 //te_smallflash((e.absmin + e.absmax) * 0.5);
1253 //bprint("navigation_routetogoal(");
1257 //tracebox(self.origin, '-16 -16 0', '16 16 0', e.origin, TRUE, self);
1258 //if (trace_fraction == 1)
1259 if (tracewalk(self, self.origin, PL_MIN, PL_MAX, e.origin, MOVE_NORMAL))
1261 // see if there are waypoints describing a path to the item
1262 e = e.nearestwaypoint;
1267 //te_smallflash((e.absmin + e.absmax) * 0.5);
1268 //tracebox(self.origin, '-16 -16 0', '16 16 0', e.origin, TRUE, self);
1269 //if (trace_fraction == 1)
1270 //if (tracewalk(self, self.origin, PL_MIN, PL_MAX, e.origin, MOVE_NORMAL))
1272 // add the waypoint to the path
1273 navigation_pushroute(e);
1279 // removes any currently touching waypoints from the goal stack
1280 // (this is how bots detect if they have reached a goal)
1281 void() navigation_poptouchedgoals =
1283 local vector org, m1, m2;
1284 org = self.origin;// + self.velocity * 0.1;
1285 m1 = org + self.mins;
1286 m2 = org + self.maxs;
1287 while (self.goalcurrent && boxesoverlap(m1, m2, self.goalcurrent.absmin, self.goalcurrent.absmax))
1288 navigation_poproute();
1291 // begin a goal selection session (queries waypoint network)
1292 void() navigation_goalrating_start =
1294 navigation_bestrating = -1;
1295 navigation_bestgoal = world;
1296 navigation_markroutes();
1299 // ends a goal selection session (updates goal stack to the best goal)
1300 void() navigation_goalrating_end =
1302 navigation_routetogoal(navigation_bestgoal);
1309 //////////////////////////////////////////////////////////////////////////////
1310 // general bot functions
1311 //////////////////////////////////////////////////////////////////////////////
1313 .float isbot; // true if this client is actually a bot
1322 .float bot_preferredcolors;
1326 .float bot_dodgerating;
1328 //.float bot_painintensity;
1329 .float bot_firetimer;
1330 //.float bot_oldhealth;
1333 .entity bot_aimtarg;
1334 .float bot_aimlatency;
1335 .vector bot_aimselforigin;
1336 .vector bot_aimselfvelocity;
1337 .vector bot_aimtargorigin;
1338 .vector bot_aimtargvelocity;
1341 .float(entity player, entity item) bot_pickupevalfunc;
1342 .float bot_pickupbasevalue;
1345 // used for aiming currently
1346 // FIXME: make the weapon code use these and then replace the calculations here with a call to the weapon code
1350 const float BOTSKINS = 19;
1351 const float BOTNAMES = 32;
1352 string(float r) bot_namefornumber =
1354 if (r < 1) return "Thunderstorm";
1355 if (r < 2) return "Darkness";
1356 if (r < 3) return "Scorcher";
1357 if (r < 4) return "Paranoia";
1358 if (r < 5) return "Eureka";
1359 if (r < 6) return "Mystery";
1360 if (r < 7) return "Toxic";
1361 if (r < 8) return "Dominion";
1362 if (r < 9) return "Pegasus";
1363 if (r < 10) return "Sensible";
1364 if (r < 11) return "Gator";
1365 if (r < 12) return "Kangaroo";
1366 if (r < 13) return "Deadline";
1367 if (r < 14) return "Frosty";
1368 if (r < 15) return "Roadkill";
1369 if (r < 16) return "Death";
1370 if (r < 17) return "Panic";
1371 if (r < 18) return "Discovery";
1372 if (r < 19) return "Shadow";
1373 if (r < 20) return "Acidic";
1374 if (r < 21) return "Dominator";
1375 if (r < 22) return "Hellfire";
1376 if (r < 23) return "Necrotic";
1377 if (r < 24) return "Newbie";
1378 if (r < 25) return "Spellbinder";
1379 if (r < 26) return "Lion";
1380 if (r < 27) return "Controlled";
1381 if (r < 28) return "Airhead";
1382 if (r < 29) return "Delirium";
1383 if (r < 30) return "Resurrection";
1384 if (r < 31) return "Danger";
1388 string(float r) bot_skinfornumber =
1390 if (r < 1) {self.playermodel = "models/player/carni.zym" ;self.playerskin = "0";return "Carni" ;}
1391 else if (r < 2) {self.playermodel = "models/player/carni.zym" ;self.playerskin = "1";return "Armored Carni" ;}
1392 else if (r < 3) {self.playermodel = "models/player/crash.zym" ;self.playerskin = "0";return "Quark" ;}
1393 else if (r < 4) {self.playermodel = "models/player/grunt.zym" ;self.playerskin = "0";return "Grunt" ;}
1394 else if (r < 5) {self.playermodel = "models/player/headhunter.zym" ;self.playerskin = "0";return "HeadHunter" ;}
1395 else if (r < 6) {self.playermodel = "models/player/insurrectionist.zym";self.playerskin = "0";return "Insurrectionist";}
1396 else if (r < 7) {self.playermodel = "models/player/lurk.zym" ;self.playerskin = "0";return "Lurk" ;}
1397 else if (r < 8) {self.playermodel = "models/player/lurk.zym" ;self.playerskin = "1";return "Reptile" ;}
1398 else if (r < 9) {self.playermodel = "models/player/lycanthrope.zym" ;self.playerskin = "0";return "Lycanthrope" ;}
1399 else if (r < 10) {self.playermodel = "models/player/marine.zym" ;self.playerskin = "0";return "Marine" ;}
1400 else if (r < 11) {self.playermodel = "models/player/nexus.zym" ;self.playerskin = "0";return "Nexus" ;}
1401 else if (r < 12) {self.playermodel = "models/player/nexus.zym" ;self.playerskin = "1";return "Mulder" ;}
1402 else if (r < 13) {self.playermodel = "models/player/nexus.zym" ;self.playerskin = "2";return "Xolar" ;}
1403 else if (r < 14) {self.playermodel = "models/player/pyria.zym" ;self.playerskin = "0";return "Pyria" ;}
1404 else if (r < 15) {self.playermodel = "models/player/shock.zym" ;self.playerskin = "0";return "Shock" ;}
1405 else if (r < 16) {self.playermodel = "models/player/skadi.zym" ;self.playerskin = "0";return "Skadi" ;}
1406 else if (r < 17) {self.playermodel = "models/player/specop.zym" ;self.playerskin = "0";return "Specop" ;}
1407 else {self.playermodel = "models/player/visitant.zym" ;self.playerskin = "0";return "Fricka" ;}
1410 void() bot_setnameandstuff =
1412 local string name, prefix, suffix;
1413 local float r, b, shirt, pants;
1415 prefix = cvar_string("bot_prefix");
1416 suffix = cvar_string("bot_suffix");
1418 // this is really only a default, JoinBestTeam is called later
1419 pants = bound(0, floor(random() * 13), 13);
1420 //shirt = bound(0, floor(random() * 16), 15);
1422 self.clientcolors = shirt * 16 + pants;
1423 self.bot_preferredcolors = self.clientcolors;
1424 self.team = pants + 1;
1426 // now pick a name...
1428 if (cvar("bot_usemodelnames"))
1430 // first see if all skins are taken
1434 name = bot_skinfornumber(b);
1437 while (b < BOTSKINS && find(world, netname, name));
1439 // randomly pick a skin, if it's taken either repeat until we find one,
1440 // or give up if we already know all skins are taken
1443 r = floor(random() * BOTSKINS);
1444 name = bot_skinfornumber(r);
1446 while (b < BOTSKINS && find(world, netname, name));
1450 // first see if all names are taken
1454 name = bot_namefornumber(b);
1457 while (b < BOTNAMES && find(world, netname, name));
1459 // randomly pick a name, if it's taken either repeat until we find one,
1460 // or give up if we already know all names are taken
1463 r = floor(random() * BOTNAMES);
1464 name = bot_namefornumber(r);
1466 while (b < BOTNAMES && find(world, netname, name));
1468 // randomly pick a skin
1469 bot_skinfornumber(floor(random() * BOTSKINS));
1471 if(!cvar("g_campaign"))
1472 self.netname = strzone(strcat(prefix, name, suffix));
1474 self.netname = name;
1477 void() bot_endgame =
1480 //dprint("bot_endgame\n");
1484 setcolor(e, e.bot_preferredcolors);
1487 // if dynamic waypoints are ever implemented, save them here
1490 float bot_ignore_bots; // let bots not attack other bots (only works in non-teamplay)
1491 float(entity e) bot_shouldattack =
1493 if (e.team == self.team)
1503 if(clienttype(e) == CLIENTTYPE_BOT)
1514 void(float t, float f1, float f2, entity e1, vector v1, vector v2, vector v3, vector v4) bot_lagfunc =
1516 self.bot_aimtarg = e1;
1517 self.bot_aimlatency = self.ping; // FIXME? Shouldn't this be in the lag item?
1518 self.bot_aimselforigin = v1;
1519 self.bot_aimselfvelocity = v2;
1520 self.bot_aimtargorigin = v3;
1521 self.bot_aimtargvelocity = v4;
1523 self.bot_canfire = (random() < 0.8);
1525 self.bot_canfire = (random() < 0.9);
1527 self.bot_canfire = (random() < 0.95);
1529 self.bot_canfire = 1;
1532 .float bot_nextthink;
1533 .float bot_badaimtime;
1534 .float bot_aimthinktime;
1535 .vector bot_mouseaim;
1536 .vector bot_badaimoffset;
1537 .vector bot_1st_order_aimfilter;
1538 .vector bot_2nd_order_aimfilter;
1539 .vector bot_3th_order_aimfilter;
1540 .vector bot_4th_order_aimfilter;
1541 .vector bot_5th_order_aimfilter;
1542 .vector bot_olddesiredang;
1543 float(vector v, float maxfiredeviation) bot_aimdir =
1546 local float snapcos;
1547 local vector olddir, newdir, desireddir;
1549 makevectors(self.v_angle);
1550 olddir = newdir = v_forward;
1551 desireddir = normalize(v);
1552 snapcos = cos(cvar("bot_ai_aimskill_snapangle") * frametime * (skill + 1) * 0.5);
1553 if (desireddir * olddir < v_forward_x)
1554 newdir = desireddir;
1557 local float blendrate;
1558 blendrate = cvar("bot_ai_aimskill_blendrate") * frametime * (skill + 1) * 0.5;
1559 newdir = olddir + (desireddir - olddir) * bound(0, blendrate, 1);
1562 // decide whether to fire this time
1563 if ((desireddir * newdir) >= cos(maxfiredeviation))
1564 self.bot_firetimer = time + 0.3;
1566 self.v_angle = vectoangles(newdir);
1567 self.v_angle_x = self.v_angle_x * -1;
1569 makevectors(self.v_angle);
1570 shotorg = self.origin + self.view_ofs;
1573 return time < self.bot_firetimer;
1577 local vector desiredang, diffang;
1579 //dprint("aim ", self.netname, ": old:", vtos(self.v_angle));
1580 // make sure v_angle is sane first
1581 self.v_angle_y = self.v_angle_y - floor(self.v_angle_y / 360) * 360;
1584 // get the desired angles to aim at
1585 //dprint(" at:", vtos(v));
1587 //te_lightning2(world, self.origin + self.view_ofs, self.origin + self.view_ofs + v * 200);
1588 if (time >= self.bot_badaimtime)
1590 self.bot_badaimtime = max(self.bot_badaimtime + 0.3, time);
1591 self.bot_badaimoffset = randomvec() * bound(0, 5 - 0.5 * (skill+self.bot_offsetskill), 5) * cvar("bot_ai_aimskill_offset");
1593 desiredang = vectoangles(v) + self.bot_badaimoffset;
1594 //dprint(" desired:", vtos(desiredang));
1595 if (desiredang_x >= 180)
1596 desiredang_x = desiredang_x - 360;
1597 desiredang_x = bound(-90, 0 - desiredang_x, 90);
1598 desiredang_z = self.v_angle_z;
1599 //dprint(" / ", vtos(desiredang));
1601 //// pain throws off aim
1602 //if (self.bot_painintensity)
1604 // // shake from pain
1605 // desiredang = desiredang + randomvec() * self.bot_painintensity * 0.2;
1608 // calculate turn angles
1609 diffang = (desiredang - self.bot_olddesiredang);
1611 diffang_y = diffang_y - floor(diffang_y / 360) * 360;
1612 if (diffang_y >= 180)
1613 diffang_y = diffang_y - 360;
1614 self.bot_olddesiredang = desiredang;
1615 //dprint(" diff:", vtos(diffang));
1617 // Here we will try to anticipate the comming aiming direction
1618 self.bot_1st_order_aimfilter= self.bot_1st_order_aimfilter
1619 + (diffang * (1 / frametime) - self.bot_1st_order_aimfilter) * bound(0, cvar("bot_ai_aimskill_order_filter_1st"),1);
1620 self.bot_2nd_order_aimfilter= self.bot_2nd_order_aimfilter
1621 + (self.bot_1st_order_aimfilter - self.bot_2nd_order_aimfilter) * bound(0, cvar("bot_ai_aimskill_order_filter_2nd"),1);
1622 self.bot_3th_order_aimfilter= self.bot_3th_order_aimfilter
1623 + (self.bot_2nd_order_aimfilter - self.bot_3th_order_aimfilter) * bound(0, cvar("bot_ai_aimskill_order_filter_3th"),1);
1624 self.bot_4th_order_aimfilter= self.bot_4th_order_aimfilter
1625 + (self.bot_3th_order_aimfilter - self.bot_4th_order_aimfilter) * bound(0, cvar("bot_ai_aimskill_order_filter_4th"),1);
1626 self.bot_5th_order_aimfilter= self.bot_5th_order_aimfilter
1627 + (self.bot_4th_order_aimfilter - self.bot_5th_order_aimfilter) * bound(0, cvar("bot_ai_aimskill_order_filter_5th"),1);
1630 //blend = (bound(0,skill,10)*0.1)*pow(1-bound(0,skill,10)*0.05,2.5)*5.656854249; //Plot formule before changing !
1631 blend = bound(0,skill,10)*0.1;
1632 desiredang = desiredang + blend *
1634 self.bot_1st_order_aimfilter * cvar("bot_ai_aimskill_order_mix_1st")
1635 + self.bot_2nd_order_aimfilter * cvar("bot_ai_aimskill_order_mix_2nd")
1636 + self.bot_3th_order_aimfilter * cvar("bot_ai_aimskill_order_mix_3th")
1637 + self.bot_4th_order_aimfilter * cvar("bot_ai_aimskill_order_mix_4th")
1638 + self.bot_5th_order_aimfilter * cvar("bot_ai_aimskill_order_mix_5th")
1641 // calculate turn angles
1642 diffang = desiredang - self.bot_mouseaim;
1644 diffang_y = diffang_y - floor(diffang_y / 360) * 360;
1645 if (diffang_y >= 180)
1646 diffang_y = diffang_y - 360;
1647 //dprint(" diff:", vtos(diffang));
1649 if (time >= self.bot_aimthinktime)
1651 self.bot_aimthinktime = max(self.bot_aimthinktime + 0.5 - 0.05*(skill+self.bot_thinkskill), time);
1652 self.bot_mouseaim = self.bot_mouseaim + diffang * (1-random()*0.1*bound(1,10-skill,10));
1655 //self.v_angle = self.v_angle + diffang * bound(0, r * frametime * (skill * 0.5 + 2), 1);
1657 diffang = self.bot_mouseaim - desiredang;
1659 diffang_y = diffang_y - floor(diffang_y / 360) * 360;
1660 if (diffang_y >= 180)
1661 diffang_y = diffang_y - 360;
1662 desiredang = desiredang + diffang * bound(0,cvar("bot_ai_aimskill_think"),1);
1664 // calculate turn angles
1665 diffang = desiredang - self.v_angle;
1667 diffang_y = diffang_y - floor(diffang_y / 360) * 360;
1668 if (diffang_y >= 180)
1669 diffang_y = diffang_y - 360;
1670 //dprint(" diff:", vtos(diffang));
1673 dist = vlen(diffang);
1674 //diffang = diffang + randomvec() * (dist * 0.05 * (3.5 - bound(0, skill, 3)));
1677 local float r, fixedrate, blendrate;
1678 fixedrate = cvar("bot_ai_aimskill_fixedrate") / bound(1,dist,1000);
1679 blendrate = cvar("bot_ai_aimskill_blendrate");
1680 r = max(fixedrate, blendrate);
1681 //self.v_angle = self.v_angle + diffang * bound(frametime, r * frametime * (2+skill*skill*0.05-random()*0.05*(10-skill)), 1);
1682 self.v_angle = self.v_angle + diffang * bound(frametime, r * frametime * (2+pow(skill+self.bot_mouseskill,3)*0.005-random()), 1);
1683 self.v_angle = self.v_angle * bound(0,cvar("bot_ai_aimskill_mouse"),1) + desiredang * bound(0,(1-cvar("bot_ai_aimskill_mouse")),1);
1684 //self.v_angle = self.v_angle + diffang * bound(0, r * frametime * (skill * 0.5 + 2), 1);
1685 //self.v_angle = self.v_angle + diffang * (1/ blendrate);
1687 self.v_angle_y = self.v_angle_y - floor(self.v_angle_y / 360) * 360;
1688 //dprint(" turn:", vtos(self.v_angle));
1690 makevectors(self.v_angle);
1691 shotorg = self.origin + self.view_ofs;
1692 shotdir = v_forward;
1694 //dprint(" dir:", vtos(v_forward));
1695 //te_lightning2(world, shotorg, shotorg + shotdir * 100);
1697 // calculate turn angles again
1698 //diffang = desiredang - self.v_angle;
1699 //diffang_y = diffang_y - floor(diffang_y / 360) * 360;
1700 //if (diffang_y >= 180)
1701 // diffang_y = diffang_y - 360;
1703 //dprint("e ", vtos(diffang), " < ", ftos(maxfiredeviation), "\n");
1705 // decide whether to fire this time
1706 // note the maxfiredeviation is in degrees so this has to convert to radians first
1707 //if ((normalize(v) * shotdir) >= cos(maxfiredeviation * (3.14159265358979323846 / 180)))
1708 if ((normalize(v) * shotdir) >= cos(maxfiredeviation * (3.14159265358979323846 / 180)))
1709 if (vlen(trace_endpos-shotorg) < 500+500*bound(0, skill, 10) || random()*random()>bound(0,skill*0.05,1))
1710 self.bot_firetimer = time + bound(0.1, 0.5-skill*0.05, 0.5);
1711 //traceline(shotorg,shotorg+shotdir*1000,FALSE,world);
1712 //dprint(ftos(maxfiredeviation),"\n");
1713 //dprint(" diff:", vtos(diffang), "\n");
1715 return self.bot_canfire && (time < self.bot_firetimer);
1718 vector(vector targorigin, vector targvelocity, float shotspeed, float shotdelay) bot_shotlead =
1720 // Try to add code here that predicts gravity effect here, no clue HOW to though ... well not yet atleast...
1721 return targorigin + targvelocity * (shotdelay + vlen(targorigin - shotorg) / shotspeed);
1724 float(float shotspeed, float shotspeedupward, float maxshottime, float applygravity) bot_aim =
1730 dprint("bot_aim(", ftos(shotspeed));
1731 dprint(", ", ftos(shotspeedupward));
1732 dprint(", ", ftos(maxshottime));
1733 dprint(", ", ftos(applygravity));
1738 dprint("bot_aim: WARNING: weapon ", W_Name(self.weapon), " shotspeed is zero!\n");
1739 shotspeed = 1000000;
1743 dprint("bot_aim: WARNING: weapon ", W_Name(self.weapon), " maxshottime is zero!\n");
1746 makevectors(self.v_angle);
1747 shotorg = self.origin + self.view_ofs;
1748 shotdir = v_forward;
1749 v = bot_shotlead(self.bot_aimtargorigin, self.bot_aimtargvelocity, shotspeed, self.bot_aimlatency);
1750 local float distanceratio;
1751 distanceratio =sqrt(bound(0,skill,10000))*0.3*(vlen(v-shotorg)-100)/cvar("bot_ai_aimskill_firetolerance_distdegrees");
1752 distanceratio = bound(0,distanceratio,1);
1753 r = (cvar("bot_ai_aimskill_firetolerance_maxdegrees")-cvar("bot_ai_aimskill_firetolerance_mindegrees"))
1754 * (1-distanceratio) + cvar("bot_ai_aimskill_firetolerance_mindegrees");
1755 if (applygravity && self.bot_aimtarg)
1757 if (!findtrajectorywithleading(shotorg, '0 0 0', '0 0 0', self.bot_aimtarg, shotspeed, shotspeedupward, maxshottime, 0, self))
1759 f = bot_aimdir(findtrajectory_velocity - shotspeedupward * '0 0 1', r);
1763 f = bot_aimdir(v - shotorg, r);
1764 //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");
1765 traceline(shotorg, shotorg + shotdir * 10000, FALSE, self);
1766 if (trace_ent.takedamage)
1767 if (trace_fraction < 1)
1768 if (!bot_shouldattack(trace_ent))
1770 traceline(shotorg, self.bot_aimtargorigin, FALSE, self);
1771 if (trace_fraction < 1)
1772 if (trace_ent != self.enemy)
1773 if (!bot_shouldattack(trace_ent))
1776 if (r > maxshottime * shotspeed)
1781 // TODO: move this painintensity code to the player damage code
1784 if (self.bot_nextthink > time)
1786 self.bot_nextthink = self.bot_nextthink + cvar("bot_ai_thinkinterval");
1787 //if (self.bot_painintensity > 0)
1788 // self.bot_painintensity = self.bot_painintensity - (skill + 1) * 40 * frametime;
1790 //self.bot_painintensity = self.bot_painintensity + self.bot_oldhealth - self.health;
1791 //self.bot_painintensity = bound(0, self.bot_painintensity, 100);
1793 if(time < restart_countdown || ((cvar("g_campaign") && !campaign_bots_may_start)))
1795 self.nextthink = time + 0.5;
1801 self.v_angle = self.angles;
1803 self.fixangle = FALSE;
1808 self.dmg_inflictor = world;
1810 // calculate an aiming latency based on the skill setting
1811 // (simulated network latency + naturally delayed reflexes)
1812 //self.ping = 0.7 - bound(0, 0.05 * skill, 0.5); // moved the reflexes to bot_aimdir (under the name 'think')
1813 // minimum ping 20+10 random
1814 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
1815 // skill 10 = ping 0.2 (adrenaline)
1816 // skill 0 = ping 0.7 (slightly drunk)
1828 self.buttonchat = 0;
1831 // if dead, just wait until we can respawn
1834 if (self.deadflag == DEAD_DEAD)
1835 self.button2 = 1; // press jump to respawn
1839 // now call the current bot AI (havocbot for example)
1843 entity bot_strategytoken;
1844 float bot_strategytoken_taken;
1847 void() bot_relinkplayerlist =
1850 local entity prevbot;
1853 player_list = e = findchainflags(flags, FL_CLIENT);
1858 player_count = player_count + 1;
1859 e.nextplayer = e.chain;
1860 if (clienttype(e) == CLIENTTYPE_BOT)
1863 prevbot.nextbot = e;
1867 currentbots = currentbots + 1;
1871 dprint(strcat("relink: ", ftos(currentbots), " bots seen.\n"));
1872 bot_strategytoken = bot_list;
1873 bot_strategytoken_taken = TRUE;
1876 void() havocbot_setupbot;
1877 float JoinBestTeam(entity pl, float only_return_best);
1879 void() bot_clientconnect =
1881 if (clienttype(self) != CLIENTTYPE_BOT)
1883 self.bot_nextthink = time - random();
1884 self.lag_func = bot_lagfunc;
1886 self.createdtime = self.nextthink;
1887 JoinBestTeam(self, FALSE);
1888 havocbot_setupbot();
1889 self.bot_mouseskill=random()-0.5;
1890 self.bot_thinkskill=random()-0.5;
1891 self.bot_predictionskill=random()-0.5;
1892 self.bot_offsetskill=random()-0.5;
1895 entity() bot_spawn =
1897 local entity oldself, bot;
1898 bot = spawnclient();
1901 currentbots = currentbots + 1;
1904 bot_setnameandstuff();
1906 PutClientInServer();
1912 void CheckAllowedTeams(entity for_whom); void GetTeamCounts(entity other); float c1, c2, c3, c4;
1913 void() bot_removefromlargestteam =
1915 local float besttime, bestcount, thiscount;
1916 local entity best, head;
1917 CheckAllowedTeams(world);
1918 GetTeamCounts(world);
1919 head = findchainfloat(isbot, TRUE);
1923 besttime = head.createdtime;
1927 if(head.team == COLOR_TEAM1)
1929 else if(head.team == COLOR_TEAM2)
1931 else if(head.team == COLOR_TEAM3)
1933 else if(head.team == COLOR_TEAM4)
1937 if (thiscount > bestcount)
1939 bestcount = thiscount;
1940 besttime = head.createdtime;
1943 else if (thiscount == bestcount && besttime < head.createdtime)
1945 besttime = head.createdtime;
1950 currentbots = currentbots - 1;
1954 void() bot_removenewest =
1956 local float besttime;
1957 local entity best, head;
1961 bot_removefromlargestteam();
1965 head = findchainfloat(isbot, TRUE);
1969 besttime = head.createdtime;
1972 if (besttime < head.createdtime)
1974 besttime = head.createdtime;
1979 currentbots = currentbots - 1;
1983 float botframe_waypointeditorlightningtime;
1984 void() botframe_showwaypointlinks =
1986 local entity player, head, w;
1987 if (time < botframe_waypointeditorlightningtime)
1989 botframe_waypointeditorlightningtime = time + 0.5;
1990 player = find(world, classname, "player");
1994 if (player.flags & FL_ONGROUND)
1996 //navigation_testtracewalk = TRUE;
1997 head = navigation_findnearestwaypoint(player, FALSE);
1998 //navigation_testtracewalk = FALSE;
2001 w = head ;if (w) te_lightning2(world, w.origin, player.origin);
2002 w = head.wp00;if (w) te_lightning2(world, w.origin, head.origin);
2003 w = head.wp01;if (w) te_lightning2(world, w.origin, head.origin);
2004 w = head.wp02;if (w) te_lightning2(world, w.origin, head.origin);
2005 w = head.wp03;if (w) te_lightning2(world, w.origin, head.origin);
2006 w = head.wp04;if (w) te_lightning2(world, w.origin, head.origin);
2007 w = head.wp05;if (w) te_lightning2(world, w.origin, head.origin);
2008 w = head.wp06;if (w) te_lightning2(world, w.origin, head.origin);
2009 w = head.wp07;if (w) te_lightning2(world, w.origin, head.origin);
2010 w = head.wp08;if (w) te_lightning2(world, w.origin, head.origin);
2011 w = head.wp09;if (w) te_lightning2(world, w.origin, head.origin);
2012 w = head.wp10;if (w) te_lightning2(world, w.origin, head.origin);
2013 w = head.wp11;if (w) te_lightning2(world, w.origin, head.origin);
2014 w = head.wp12;if (w) te_lightning2(world, w.origin, head.origin);
2015 w = head.wp13;if (w) te_lightning2(world, w.origin, head.origin);
2016 w = head.wp14;if (w) te_lightning2(world, w.origin, head.origin);
2017 w = head.wp15;if (w) te_lightning2(world, w.origin, head.origin);
2018 w = head.wp16;if (w) te_lightning2(world, w.origin, head.origin);
2019 w = head.wp17;if (w) te_lightning2(world, w.origin, head.origin);
2020 w = head.wp18;if (w) te_lightning2(world, w.origin, head.origin);
2021 w = head.wp19;if (w) te_lightning2(world, w.origin, head.origin);
2022 w = head.wp20;if (w) te_lightning2(world, w.origin, head.origin);
2023 w = head.wp21;if (w) te_lightning2(world, w.origin, head.origin);
2024 w = head.wp22;if (w) te_lightning2(world, w.origin, head.origin);
2025 w = head.wp23;if (w) te_lightning2(world, w.origin, head.origin);
2026 w = head.wp24;if (w) te_lightning2(world, w.origin, head.origin);
2027 w = head.wp25;if (w) te_lightning2(world, w.origin, head.origin);
2028 w = head.wp26;if (w) te_lightning2(world, w.origin, head.origin);
2029 w = head.wp27;if (w) te_lightning2(world, w.origin, head.origin);
2030 w = head.wp28;if (w) te_lightning2(world, w.origin, head.origin);
2031 w = head.wp29;if (w) te_lightning2(world, w.origin, head.origin);
2032 w = head.wp30;if (w) te_lightning2(world, w.origin, head.origin);
2033 w = head.wp31;if (w) te_lightning2(world, w.origin, head.origin);
2036 player = find(player, classname, "player");
2040 entity botframe_dangerwaypoint;
2041 void(float maxupdate) botframe_updatedangerousobjects =
2043 local entity head, bot_dodgelist;
2044 local vector m1, m2, v;
2045 local float c, d, danger;
2047 bot_dodgelist = findchainfloat(bot_dodge, TRUE);
2048 botframe_dangerwaypoint = find(botframe_dangerwaypoint, classname, "waypoint");
2049 while (botframe_dangerwaypoint != world)
2052 m1 = botframe_dangerwaypoint.mins;
2053 m2 = botframe_dangerwaypoint.maxs;
2054 head = bot_dodgelist;
2058 v_x = bound(m1_x, v_x, m2_x);
2059 v_y = bound(m1_y, v_y, m2_y);
2060 v_z = bound(m1_z, v_z, m2_z);
2061 d = head.bot_dodgerating - vlen(head.origin - v);
2064 traceline(head.origin, v, TRUE, world);
2065 if (trace_fraction == 1)
2066 danger = danger + d;
2070 botframe_dangerwaypoint.dmg = danger;
2074 botframe_dangerwaypoint = find(botframe_dangerwaypoint, classname, "waypoint");
2079 float botframe_spawnedwaypoints;
2080 float botframe_nextthink;
2081 float botframe_nextdangertime;
2083 float autoskill_nextthink;
2084 .float totalfrags_lastcheck;
2085 void(float factor) autoskill =
2093 FOR_EACH_PLAYER(head)
2095 if(clienttype(head) == CLIENTTYPE_REAL)
2096 bestplayer = max(bestplayer, head.totalfrags - head.totalfrags_lastcheck);
2098 bestbot = max(bestbot, head.totalfrags - head.totalfrags_lastcheck);
2101 dprint("autoskill: best player got ", ftos(bestplayer), ", ");
2102 dprint("best bot got ", ftos(bestbot), "; ");
2103 if(bestbot < 0 || bestplayer < 0)
2105 dprint("not doing anything\n");
2106 // don't return, let it reset all counters below
2108 else if(bestbot <= bestplayer * factor - 2)
2110 if(cvar("skill") < 17)
2112 dprint("2 frags difference, increasing skill\n");
2113 cvar_set("skill", ftos(cvar("skill") + 1));
2114 bprint("^2SKILL UP!^7 Now at level ", ftos(cvar("skill")), "\n");
2117 else if(bestbot >= bestplayer * factor + 2)
2119 if(cvar("skill") > 0)
2121 dprint("2 frags difference, decreasing skill\n");
2122 cvar_set("skill", ftos(cvar("skill") - 1));
2123 bprint("^1SKILL DOWN!^7 Now at level ", ftos(cvar("skill")), "\n");
2128 dprint("not doing anything\n");
2130 // don't reset counters, wait for them to accumulate
2133 FOR_EACH_PLAYER(head)
2134 head.totalfrags_lastcheck = head.totalfrags;
2137 void() bot_serverframe =
2139 float realplayers, bots, activerealplayers;
2142 if (intermission_running)
2148 if(time > autoskill_nextthink)
2151 a = cvar("skill_auto");
2152 if(!cvar("g_campaign"))
2155 autoskill_nextthink = time + 5;
2158 activerealplayers = 0;
2161 FOR_EACH_REALCLIENT(head)
2163 if(head.classname == "player" || g_lms || g_arena)
2164 ++activerealplayers;
2168 // add/remove bots if needed to make sure there are at least
2169 // minplayers+bot_number, or remove all bots if no one is playing
2170 // But don't remove bots immediately on level change, as the real players
2171 // usually haven't rejoined yet
2172 bots_would_leave = FALSE;
2173 if (realplayers || cvar("bot_join_empty") || (currentbots > 0 && time < 5))
2175 float realminplayers, minplayers;
2176 realminplayers = cvar("minplayers");
2177 minplayers = max(0, floor(realminplayers));
2179 float realminbots, minbots;
2180 if(cvar("bot_vs_human"))
2181 realminbots = ceil(fabs(cvar("bot_vs_human")) * activerealplayers);
2183 realminbots = cvar("bot_number");
2184 minbots = max(0, floor(realminbots));
2186 bots = min(max(minbots, minplayers - activerealplayers), maxclients - realplayers);
2188 bots_would_leave = TRUE;
2192 // if there are no players, remove bots
2196 bot_ignore_bots = cvar("bot_ignore_bots");
2198 // only add one bot per frame to avoid utter chaos
2199 if(time > botframe_nextthink)
2201 //dprint(ftos(bots), " ? ", ftos(currentbots), "\n");
2202 while (currentbots < bots)
2204 if (bot_spawn() == world)
2206 bprint("Can not add bot, server full.\n");
2207 botframe_nextthink = time + 10;
2211 while (currentbots > bots)
2215 if(botframe_spawnedwaypoints)
2217 if(cvar("waypoint_benchmark"))
2221 if (currentbots > 0 || cvar("g_waypointeditor"))
2222 if (!botframe_spawnedwaypoints)
2224 botframe_spawnedwaypoints = TRUE;
2226 waypoint_schedulerelinkall();
2231 // cycle the goal token from one bot to the next each frame
2232 // (this prevents them from all doing waypoint searches on the same
2233 // frame, which causes choppy framerates)
2234 if (bot_strategytoken_taken)
2236 bot_strategytoken_taken = FALSE;
2237 if (bot_strategytoken)
2238 bot_strategytoken = bot_strategytoken.nextbot;
2239 if (!bot_strategytoken)
2240 bot_strategytoken = bot_list;
2243 if (botframe_nextdangertime < time)
2245 local float interval;
2246 interval = cvar("bot_ai_dangerdetectioninterval");
2247 if (botframe_nextdangertime < time - interval * 1.5)
2248 botframe_nextdangertime = time;
2249 botframe_nextdangertime = botframe_nextdangertime + interval;
2250 botframe_updatedangerousobjects(cvar("bot_ai_dangerdetectionupdates"));
2254 if (cvar("g_waypointeditor"))
2255 botframe_showwaypointlinks();