Debian Codegraph @

code/botlib/be_aas_reach.c

raw symbols SCIP
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22
23 /*****************************************************************************
24 * name: be_aas_reach.c
25 *
26 * desc: reachability calculations
27 *
28 * $Archive: /MissionPack/code/botlib/be_aas_reach.c $
29 *
30 *****************************************************************************/
31
32 #include "../qcommon/q_shared.h"
33 #include "l_log.h"
34 #include "l_memory.h"
35 #include "l_script.h"
36 #include "l_libvar.h"
37 #include "l_precomp.h"
38 #include "l_struct.h"
39 #include "aasfile.h"
40 #include "botlib.h"
41 #include "be_aas.h"
42 #include "be_aas_funcs.h"
43 #include "be_aas_def.h"
44
45 extern int Sys_MilliSeconds(void);
46
47
48 extern botlib_import_t botimport;
49
50 //#define REACH_DEBUG
51
52 //NOTE: all travel times are in hundreth of a second
53 //maximum number of reachability links
54 #define AAS_MAX_REACHABILITYSIZE 65536
55 //number of areas reachability is calculated for each frame
56 #define REACHABILITYAREASPERCYCLE 15
57 //number of units reachability points are placed inside the areas
58 #define INSIDEUNITS 2
59 #define INSIDEUNITS_WALKEND 5
60 #define INSIDEUNITS_WALKSTART 0.1
61 #define INSIDEUNITS_WATERJUMP 15
62 //area flag used for weapon jumping
63 #define AREA_WEAPONJUMP 8192 //valid area to weapon jump to
64 //number of reachabilities of each type
65 int reach_swim; //swim
66 int reach_equalfloor; //walk on floors with equal height
67 int reach_step; //step up
68 int reach_walk; //walk of step
69 int reach_barrier; //jump up to a barrier
70 int reach_waterjump; //jump out of water
71 int reach_walkoffledge; //walk of a ledge
72 int reach_jump; //jump
73 int reach_ladder; //climb or descent a ladder
74 int reach_teleport; //teleport
75 int reach_elevator; //use an elevator
76 int reach_funcbob; //use a func bob
77 int reach_grapple; //grapple hook
78 int reach_doublejump; //double jump
79 int reach_rampjump; //ramp jump
80 int reach_strafejump; //strafe jump (just normal jump but further)
81 int reach_rocketjump; //rocket jump
82 int reach_bfgjump; //bfg jump
83 int reach_jumppad; //jump pads
84 //if true grapple reachabilities are skipped
85 int calcgrapplereach;
86 //linked reachability
87 typedef struct aas_lreachability_s
88 {
89 int areanum; //number of the reachable area
90 int facenum; //number of the face towards the other area
91 int edgenum; //number of the edge towards the other area
92 vec3_t start; //start point of inter area movement
93 vec3_t end; //end point of inter area movement
94 int traveltype; //type of travel required to get to the area
95 unsigned short int traveltime; //travel time of the inter area movement
96 //
97 struct aas_lreachability_s *next;
98 } aas_lreachability_t;
99 //temporary reachabilities
100 aas_lreachability_t *reachabilityheap; //heap with reachabilities
101 aas_lreachability_t *nextreachability; //next free reachability from the heap
102 aas_lreachability_t **areareachability; //reachability links for every area
103 int numlreachabilities;
104
105 //===========================================================================
106 // returns the surface area of the given face
107 //
108 // Parameter: -
109 // Returns: -
110 // Changes Globals: -
111 //===========================================================================
112 float AAS_FaceArea(aas_face_t *face)
113 {
114 int i, edgenum, side;
115 float total;
116 vec_t *v;
117 vec3_t d1, d2, cross;
118 aas_edge_t *edge;
119
120 edgenum = aasworld.edgeindex[face->firstedge];
121 side = edgenum < 0;
122 edge = &aasworld.edges[abs(edgenum)];
123 v = aasworld.vertexes[edge->v[side]];
124
125 total = 0;
126 for (i = 1; i < face->numedges - 1; i++)
127 {
128 edgenum = aasworld.edgeindex[face->firstedge + i];
129 side = edgenum < 0;
130 edge = &aasworld.edges[abs(edgenum)];
131 VectorSubtract(aasworld.vertexes[edge->v[side]], v, d1);
132 VectorSubtract(aasworld.vertexes[edge->v[!side]], v, d2);
133 CrossProduct(d1, d2, cross);
134 total += 0.5 * VectorLength(cross);
135 } //end for
136 return total;
137 } //end of the function AAS_FaceArea
138 //===========================================================================
139 // returns the volume of an area
140 //
141 // Parameter: -
142 // Returns: -
143 // Changes Globals: -
144 //===========================================================================
145 float AAS_AreaVolume(int areanum)
146 {
147 int i, edgenum, facenum, side;
148 vec_t d, a, volume;
149 vec3_t corner;
150 aas_plane_t *plane;
151 aas_edge_t *edge;
152 aas_face_t *face;
153 aas_area_t *area;
154
155 area = &aasworld.areas[areanum];
156 facenum = aasworld.faceindex[area->firstface];
157 face = &aasworld.faces[abs(facenum)];
158 edgenum = aasworld.edgeindex[face->firstedge];
159 edge = &aasworld.edges[abs(edgenum)];
160 //
161 VectorCopy(aasworld.vertexes[edge->v[0]], corner);
162
163 //make tetrahedrons to all other faces
164 volume = 0;
165 for (i = 0; i < area->numfaces; i++)
166 {
167 facenum = abs(aasworld.faceindex[area->firstface + i]);
168 face = &aasworld.faces[facenum];
169 side = face->backarea != areanum;
170 plane = &aasworld.planes[face->planenum ^ side];
171 d = -(DotProduct (corner, plane->normal) - plane->dist);
172 a = AAS_FaceArea(face);
173 volume += d * a;
174 } //end for
175
176 volume /= 3;
177 return volume;
178 } //end of the function AAS_AreaVolume
179 //===========================================================================
180 //
181 // Parameter: -
182 // Returns: -
183 // Changes Globals: -
184 //===========================================================================
185 int AAS_BestReachableLinkArea(aas_link_t *areas)
186 {
187 aas_link_t *link;
188
189 for (link = areas; link; link = link->next_area)
190 {
191 if (AAS_AreaGrounded(link->areanum) || AAS_AreaSwim(link->areanum))
192 {
193 return link->areanum;
194 } //end if
195 } //end for
196 //
197 for (link = areas; link; link = link->next_area)
198 {
199 if (link->areanum) return link->areanum;
200 //FIXME: this is a bad idea when the reachability is not yet
201 // calculated when the level items are loaded
202 if (AAS_AreaReachability(link->areanum))
203 return link->areanum;
204 } //end for
205 return 0;
206 } //end of the function AAS_BestReachableLinkArea
207 //===========================================================================
208 //
209 // Parameter: -
210 // Returns: -
211 // Changes Globals: -
212 //===========================================================================
213 int AAS_GetJumpPadInfo(int ent, vec3_t areastart, vec3_t absmins, vec3_t absmaxs, vec3_t velocity)
214 {
215 int modelnum, ent2;
216 float speed, height, gravity, time, dist, forward;
217 vec3_t origin, angles, teststart, ent2origin;
218 aas_trace_t trace;
219 char model[MAX_EPAIRKEY];
220 char target[MAX_EPAIRKEY], targetname[MAX_EPAIRKEY];
221
222 //
223 AAS_FloatForBSPEpairKey(ent, "speed", &speed);
224 if (!speed) speed = 1000;
225 VectorClear(angles);
226 //get the mins, maxs and origin of the model
227 AAS_ValueForBSPEpairKey(ent, "model", model, MAX_EPAIRKEY);
228 if (model[0]) modelnum = atoi(model+1);
229 else modelnum = 0;
230 AAS_BSPModelMinsMaxsOrigin(modelnum, angles, absmins, absmaxs, origin);
231 VectorAdd(origin, absmins, absmins);
232 VectorAdd(origin, absmaxs, absmaxs);
233 VectorAdd(absmins, absmaxs, origin);
234 VectorScale (origin, 0.5, origin);
235
236 //get the start areas
237 VectorCopy(origin, teststart);
238 teststart[2] += 64;
239 trace = AAS_TraceClientBBox(teststart, origin, PRESENCE_CROUCH, -1);
240 if (trace.startsolid)
241 {
242 botimport.Print(PRT_MESSAGE, "trigger_push start solid\n");
243 VectorCopy(origin, areastart);
244 } //end if
245 else
246 {
247 VectorCopy(trace.endpos, areastart);
248 } //end else
249 areastart[2] += 0.125;
250 //
251 //AAS_DrawPermanentCross(origin, 4, 4);
252 //get the target entity
253 AAS_ValueForBSPEpairKey(ent, "target", target, MAX_EPAIRKEY);
254 for (ent2 = AAS_NextBSPEntity(0); ent2; ent2 = AAS_NextBSPEntity(ent2))
255 {
256 if (!AAS_ValueForBSPEpairKey(ent2, "targetname", targetname, MAX_EPAIRKEY)) continue;
257 if (!strcmp(targetname, target)) break;
258 } //end for
259 if (!ent2)
260 {
261 botimport.Print(PRT_MESSAGE, "trigger_push without target entity %s\n", target);
262 return qfalse;
263 } //end if
264 AAS_VectorForBSPEpairKey(ent2, "origin", ent2origin);
265 //
266 height = ent2origin[2] - origin[2];
267 gravity = aassettings.phys_gravity;
268 time = sqrt( height / ( 0.5 * gravity ) );
269 if (!time)
270 {
271 botimport.Print(PRT_MESSAGE, "trigger_push without time\n");
272 return qfalse;
273 } //end if
274 // set s.origin2 to the push velocity
275 VectorSubtract ( ent2origin, origin, velocity);
276 dist = VectorNormalize( velocity);
277 forward = dist / time;
278 //FIXME: why multiply by 1.1
279 forward *= 1.1f;
280 VectorScale(velocity, forward, velocity);
281 velocity[2] = time * gravity;
282 return qtrue;
283 } //end of the function AAS_GetJumpPadInfo
284 //===========================================================================
285 //
286 // Parameter: -
287 // Returns: -
288 // Changes Globals: -
289 //===========================================================================
290 int AAS_BestReachableFromJumpPadArea(vec3_t origin, vec3_t mins, vec3_t maxs)
291 {
292 int ent, bot_visualizejumppads, bestareanum;
293 float volume, bestareavolume;
294 vec3_t areastart, cmdmove, bboxmins, bboxmaxs;
295 vec3_t absmins, absmaxs, velocity;
296 aas_clientmove_t move;
297 aas_link_t *areas, *link;
298 char classname[MAX_EPAIRKEY];
299
300 #ifdef BSPC
301 bot_visualizejumppads = 0;
302 #else
303 bot_visualizejumppads = LibVarValue("bot_visualizejumppads", "0");
304 #endif
305 VectorAdd(origin, mins, bboxmins);
306 VectorAdd(origin, maxs, bboxmaxs);
307 for (ent = AAS_NextBSPEntity(0); ent; ent = AAS_NextBSPEntity(ent))
308 {
309 if (!AAS_ValueForBSPEpairKey(ent, "classname", classname, MAX_EPAIRKEY)) continue;
310 if (strcmp(classname, "trigger_push")) continue;
311 //
312 if (!AAS_GetJumpPadInfo(ent, areastart, absmins, absmaxs, velocity)) continue;
313 //get the areas the jump pad brush is in
314 areas = AAS_LinkEntityClientBBox(absmins, absmaxs, -1, PRESENCE_CROUCH);
315 for (link = areas; link; link = link->next_area)
316 {
317 if (AAS_AreaJumpPad(link->areanum)) break;
318 } //end for
319 if (!link)
320 {
321 botimport.Print(PRT_MESSAGE, "trigger_push not in any jump pad area\n");
322 AAS_UnlinkFromAreas(areas);
323 continue;
324 } //end if
325 //
326 //botimport.Print(PRT_MESSAGE, "found a trigger_push with velocity %f %f %f\n", velocity[0], velocity[1], velocity[2]);
327 //
328 VectorSet(cmdmove, 0, 0, 0);
329 Com_Memset(&move, 0, sizeof(aas_clientmove_t));
330 AAS_ClientMovementHitBBox(&move, -1, areastart, PRESENCE_NORMAL, qfalse,
331 velocity, cmdmove, 0, 30, 0.1f, bboxmins, bboxmaxs, bot_visualizejumppads);
332 if (move.frames < 30)
333 {
334 bestareanum = 0;
335 bestareavolume = 0;
336 for (link = areas; link; link = link->next_area)
337 {
338 if (!AAS_AreaJumpPad(link->areanum)) continue;
339 volume = AAS_AreaVolume(link->areanum);
340 if (volume >= bestareavolume)
341 {
342 bestareanum = link->areanum;
343 bestareavolume = volume;
344 } //end if
345 } //end if
346 AAS_UnlinkFromAreas(areas);
347 return bestareanum;
348 } //end if
349 AAS_UnlinkFromAreas(areas);
350 } //end for
351 return 0;
352 } //end of the function AAS_BestReachableFromJumpPadArea
353 //===========================================================================
354 //
355 // Parameter: -
356 // Returns: -
357 // Changes Globals: -
358 //===========================================================================
359 int AAS_BestReachableArea(vec3_t origin, vec3_t mins, vec3_t maxs, vec3_t goalorigin)
360 {
361 int areanum, i, j, k, l;
362 aas_link_t *areas;
363 vec3_t absmins, absmaxs;
364 //vec3_t bbmins, bbmaxs;
365 vec3_t start, end;
366 aas_trace_t trace;
367
368 if (!aasworld.loaded)
369 {
370 botimport.Print(PRT_ERROR, "AAS_BestReachableArea: aas not loaded\n");
371 return 0;
372 } //end if
373 //find a point in an area
374 VectorCopy(origin, start);
375 areanum = AAS_PointAreaNum(start);
376 //while no area found fudge around a little
377 for (i = 0; i < 5 && !areanum; i++)
378 {
379 for (j = 0; j < 5 && !areanum; j++)
380 {
381 for (k = -1; k <= 1 && !areanum; k++)
382 {
383 for (l = -1; l <= 1 && !areanum; l++)
384 {
385 VectorCopy(origin, start);
386 start[0] += (float) j * 4 * k;
387 start[1] += (float) j * 4 * l;
388 start[2] += (float) i * 4;
389 areanum = AAS_PointAreaNum(start);
390 } //end for
391 } //end for
392 } //end for
393 } //end for
394 //if an area was found
395 if (areanum)
396 {
397 //drop client bbox down and try again
398 VectorCopy(start, end);
399 start[2] += 0.25;
400 end[2] -= 50;
401 trace = AAS_TraceClientBBox(start, end, PRESENCE_CROUCH, -1);
402 if (!trace.startsolid)
403 {
404 areanum = AAS_PointAreaNum(trace.endpos);
405 VectorCopy(trace.endpos, goalorigin);
406 //FIXME: cannot enable next line right now because the reachability
407 // does not have to be calculated when the level items are loaded
408 //if the origin is in an area with reachability
409 //if (AAS_AreaReachability(areanum)) return areanum;
410 if (areanum) return areanum;
411 } //end if
412 else
413 {
414 //it can very well happen that the AAS_PointAreaNum function tells that
415 //a point is in an area and that starting an AAS_TraceClientBBox from that
416 //point will return trace.startsolid qtrue
417 #if 0
418 if (AAS_PointAreaNum(start))
419 {
420 Log_Write("point %f %f %f in area %d but trace startsolid", start[0], start[1], start[2], areanum);
421 AAS_DrawPermanentCross(start, 4, LINECOLOR_RED);
422 } //end if
423 botimport.Print(PRT_MESSAGE, "AAS_BestReachableArea: start solid\n");
424 #endif
425 VectorCopy(start, goalorigin);
426 return areanum;
427 } //end else
428 } //end if
429 //
430 //AAS_PresenceTypeBoundingBox(PRESENCE_CROUCH, bbmins, bbmaxs);
431 //NOTE: the goal origin does not have to be in the goal area
432 // because the bot will have to move towards the item origin anyway
433 VectorCopy(origin, goalorigin);
434 //
435 VectorAdd(origin, mins, absmins);
436 VectorAdd(origin, maxs, absmaxs);
437 //add bounding box size
438 //VectorSubtract(absmins, bbmaxs, absmins);
439 //VectorSubtract(absmaxs, bbmins, absmaxs);
440 //link an invalid (-1) entity
441 areas = AAS_LinkEntityClientBBox(absmins, absmaxs, -1, PRESENCE_CROUCH);
442 //get the reachable link area
443 areanum = AAS_BestReachableLinkArea(areas);
444 //unlink the invalid entity
445 AAS_UnlinkFromAreas(areas);
446 //
447 return areanum;
448 } //end of the function AAS_BestReachableArea
449 //===========================================================================
450 //
451 // Parameter: -
452 // Returns: -
453 // Changes Globals: -
454 //===========================================================================
455 void AAS_SetupReachabilityHeap(void)
456 {
457 int i;
458
459 reachabilityheap = (aas_lreachability_t *) GetClearedMemory(
460 AAS_MAX_REACHABILITYSIZE * sizeof(aas_lreachability_t));
461 for (i = 0; i < AAS_MAX_REACHABILITYSIZE-1; i++)
462 {
463 reachabilityheap[i].next = &reachabilityheap[i+1];
464 } //end for
465 reachabilityheap[AAS_MAX_REACHABILITYSIZE-1].next = NULL;
466 nextreachability = reachabilityheap;
467 numlreachabilities = 0;
468 } //end of the function AAS_InitReachabilityHeap
469 //===========================================================================
470 //
471 // Parameter: -
472 // Returns: -
473 // Changes Globals: -
474 //===========================================================================
475 void AAS_ShutDownReachabilityHeap(void)
476 {
477 FreeMemory(reachabilityheap);
478 numlreachabilities = 0;
479 } //end of the function AAS_ShutDownReachabilityHeap
480 //===========================================================================
481 // returns a reachability link
482 //
483 // Parameter: -
484 // Returns: -
485 // Changes Globals: -
486 //===========================================================================
487 aas_lreachability_t *AAS_AllocReachability(void)
488 {
489 aas_lreachability_t *r;
490
491 if (!nextreachability) return NULL;
492 //make sure the error message only shows up once
493 if (!nextreachability->next) AAS_Error("AAS_MAX_REACHABILITYSIZE\n");
494 //
495 r = nextreachability;
496 nextreachability = nextreachability->next;
497 numlreachabilities++;
498 return r;
499 } //end of the function AAS_AllocReachability
500 //===========================================================================
501 // frees a reachability link
502 //
503 // Parameter: -
504 // Returns: -
505 // Changes Globals: -
506 //===========================================================================
507 void AAS_FreeReachability(aas_lreachability_t *lreach)
508 {
509 Com_Memset(lreach, 0, sizeof(aas_lreachability_t));
510
511 lreach->next = nextreachability;
512 nextreachability = lreach;
513 numlreachabilities--;
514 } //end of the function AAS_FreeReachability
515 //===========================================================================
516 // returns qtrue if the area has reachability links
517 //
518 // Parameter: -
519 // Returns: -
520 // Changes Globals: -
521 //===========================================================================
522 int AAS_AreaReachability(int areanum)
523 {
524 if (areanum < 0 || areanum >= aasworld.numareas)
525 {
526 AAS_Error("AAS_AreaReachability: areanum %d out of range\n", areanum);
527 return 0;
528 } //end if
529 return aasworld.areasettings[areanum].numreachableareas;
530 } //end of the function AAS_AreaReachability
531 //===========================================================================
532 // returns the surface area of all ground faces together of the area
533 //
534 // Parameter: -
535 // Returns: -
536 // Changes Globals: -
537 //===========================================================================
538 float AAS_AreaGroundFaceArea(int areanum)
539 {
540 int i;
541 float total;
542 aas_area_t *area;
543 aas_face_t *face;
544
545 total = 0;
546 area = &aasworld.areas[areanum];
547 for (i = 0; i < area->numfaces; i++)
548 {
549 face = &aasworld.faces[abs(aasworld.faceindex[area->firstface + i])];
550 if (!(face->faceflags & FACE_GROUND)) continue;
551 //
552 total += AAS_FaceArea(face);
553 } //end for
554 return total;
555 } //end of the function AAS_AreaGroundFaceArea
556 //===========================================================================
557 // returns the center of a face
558 //
559 // Parameter: -
560 // Returns: -
561 // Changes Globals: -
562 //===========================================================================
563 void AAS_FaceCenter(int facenum, vec3_t center)
564 {
565 int i;
566 float scale;
567 aas_face_t *face;
568 aas_edge_t *edge;
569
570 face = &aasworld.faces[facenum];
571
572 VectorClear(center);
573 for (i = 0; i < face->numedges; i++)
574 {
575 edge = &aasworld.edges[abs(aasworld.edgeindex[face->firstedge + i])];
576 VectorAdd(center, aasworld.vertexes[edge->v[0]], center);
577 VectorAdd(center, aasworld.vertexes[edge->v[1]], center);
578 } //end for
579 scale = 0.5 / face->numedges;
580 VectorScale(center, scale, center);
581 } //end of the function AAS_FaceCenter
582 //===========================================================================
583 // returns the maximum distance a player can fall before being damaged
584 // damage = deltavelocity*deltavelocity * 0.0001
585 //
586 // Parameter: -
587 // Returns: -
588 // Changes Globals: -
589 //===========================================================================
590 int AAS_FallDamageDistance(void)
591 {
592 float maxzvelocity, gravity, t;
593
594 maxzvelocity = sqrt(30 * 10000);
595 gravity = aassettings.phys_gravity;
596 t = maxzvelocity / gravity;
597 return 0.5 * gravity * t * t;
598 } //end of the function AAS_FallDamageDistance
599 //===========================================================================
600 // distance = 0.5 * gravity * t * t
601 // vel = t * gravity
602 // damage = vel * vel * 0.0001
603 //
604 // Parameter: -
605 // Returns: -
606 // Changes Globals: -
607 //===========================================================================
608 float AAS_FallDelta(float distance)
609 {
610 float t, delta, gravity;
611
612 gravity = aassettings.phys_gravity;
613 t = sqrt(fabs(distance) * 2 / gravity);
614 delta = t * gravity;
615 return delta * delta * 0.0001;
616 } //end of the function AAS_FallDelta
617 //===========================================================================
618 //
619 // Parameter: -
620 // Returns: -
621 // Changes Globals: -
622 //===========================================================================
623 float AAS_MaxJumpHeight(float phys_jumpvel)
624 {
625 float phys_gravity;
626
627 phys_gravity = aassettings.phys_gravity;
628 //maximum height a player can jump with the given initial z velocity
629 return 0.5 * phys_gravity * (phys_jumpvel / phys_gravity) * (phys_jumpvel / phys_gravity);
630 } //end of the function MaxJumpHeight
631 //===========================================================================
632 // returns true if a player can only crouch in the area
633 //
634 // Parameter: -
635 // Returns: -
636 // Changes Globals: -
637 //===========================================================================
638 float AAS_MaxJumpDistance(float phys_jumpvel)
639 {
640 float phys_gravity, phys_maxvelocity, t;
641
642 phys_gravity = aassettings.phys_gravity;
643 phys_maxvelocity = aassettings.phys_maxvelocity;
644 //time a player takes to fall the height
645 t = sqrt(aassettings.rs_maxjumpfallheight / (0.5 * phys_gravity));
646 //maximum distance
647 return phys_maxvelocity * (t + phys_jumpvel / phys_gravity);
648 } //end of the function AAS_MaxJumpDistance
649 //===========================================================================
650 // returns true if a player can only crouch in the area
651 //
652 // Parameter: -
653 // Returns: -
654 // Changes Globals: -
655 //===========================================================================
656 int AAS_AreaCrouch(int areanum)
657 {
658 if (!(aasworld.areasettings[areanum].presencetype & PRESENCE_NORMAL)) return qtrue;
659 else return qfalse;
660 } //end of the function AAS_AreaCrouch
661 //===========================================================================
662 // returns qtrue if it is possible to swim in the area
663 //
664 // Parameter: -
665 // Returns: -
666 // Changes Globals: -
667 //===========================================================================
668 int AAS_AreaSwim(int areanum)
669 {
670 if (aasworld.areasettings[areanum].areaflags & AREA_LIQUID) return qtrue;
671 else return qfalse;
672 } //end of the function AAS_AreaSwim
673 //===========================================================================
674 // returns qtrue if the area contains a liquid
675 //
676 // Parameter: -
677 // Returns: -
678 // Changes Globals: -
679 //===========================================================================
680 int AAS_AreaLiquid(int areanum)
681 {
682 if (aasworld.areasettings[areanum].areaflags & AREA_LIQUID) return qtrue;
683 else return qfalse;
684 } //end of the function AAS_AreaLiquid
685 //===========================================================================
686 //
687 // Parameter: -
688 // Returns: -
689 // Changes Globals: -
690 //===========================================================================
691 int AAS_AreaLava(int areanum)
692 {
693 return (aasworld.areasettings[areanum].contents & AREACONTENTS_LAVA);
694 } //end of the function AAS_AreaLava
695 //===========================================================================
696 //
697 // Parameter: -
698 // Returns: -
699 // Changes Globals: -
700 //===========================================================================
701 int AAS_AreaSlime(int areanum)
702 {
703 return (aasworld.areasettings[areanum].contents & AREACONTENTS_SLIME);
704 } //end of the function AAS_AreaSlime
705 //===========================================================================
706 // returns qtrue if the area contains ground faces
707 //
708 // Parameter: -
709 // Returns: -
710 // Changes Globals: -
711 //===========================================================================
712 int AAS_AreaGrounded(int areanum)
713 {
714 return (aasworld.areasettings[areanum].areaflags & AREA_GROUNDED);
715 } //end of the function AAS_AreaGround
716 //===========================================================================
717 // returns true if the area contains ladder faces
718 //
719 // Parameter: -
720 // Returns: -
721 // Changes Globals: -
722 //===========================================================================
723 int AAS_AreaLadder(int areanum)
724 {
725 return (aasworld.areasettings[areanum].areaflags & AREA_LADDER);
726 } //end of the function AAS_AreaLadder
727 //===========================================================================
728 //
729 // Parameter: -
730 // Returns: -
731 // Changes Globals: -
732 //===========================================================================
733 int AAS_AreaJumpPad(int areanum)
734 {
735 return (aasworld.areasettings[areanum].contents & AREACONTENTS_JUMPPAD);
736 } //end of the function AAS_AreaJumpPad
737 //===========================================================================
738 //
739 // Parameter: -
740 // Returns: -
741 // Changes Globals: -
742 //===========================================================================
743 int AAS_AreaTeleporter(int areanum)
744 {
745 return (aasworld.areasettings[areanum].contents & AREACONTENTS_TELEPORTER);
746 } //end of the function AAS_AreaTeleporter
747 //===========================================================================
748 //
749 // Parameter: -
750 // Returns: -
751 // Changes Globals: -
752 //===========================================================================
753 int AAS_AreaClusterPortal(int areanum)
754 {
755 return (aasworld.areasettings[areanum].contents & AREACONTENTS_CLUSTERPORTAL);
756 } //end of the function AAS_AreaClusterPortal
757 //===========================================================================
758 //
759 // Parameter: -
760 // Returns: -
761 // Changes Globals: -
762 //===========================================================================
763 int AAS_AreaDoNotEnter(int areanum)
764 {
765 return (aasworld.areasettings[areanum].contents & AREACONTENTS_DONOTENTER);
766 } //end of the function AAS_AreaDoNotEnter
767 //===========================================================================
768 // returns the time it takes perform a barrier jump
769 //
770 // Parameter: -
771 // Returns: -
772 // Changes Globals: -
773 //===========================================================================
774 unsigned short int AAS_BarrierJumpTravelTime(void)
775 {
776 return aassettings.phys_jumpvel / (aassettings.phys_gravity * 0.1);
777 } //end op the function AAS_BarrierJumpTravelTime
778 //===========================================================================
779 // returns true if there already exists a reachability from area1 to area2
780 //
781 // Parameter: -
782 // Returns: -
783 // Changes Globals: -
784 //===========================================================================
785 qboolean AAS_ReachabilityExists(int area1num, int area2num)
786 {
787 aas_lreachability_t *r;
788
789 for (r = areareachability[area1num]; r; r = r->next)
790 {
791 if (r->areanum == area2num) return qtrue;
792 } //end for
793 return qfalse;
794 } //end of the function AAS_ReachabilityExists
795 //===========================================================================
796 // returns true if there is a solid just after the end point when going
797 // from start to end
798 //
799 // Parameter: -
800 // Returns: -
801 // Changes Globals: -
802 //===========================================================================
803 int AAS_NearbySolidOrGap(vec3_t start, vec3_t end)
804 {
805 vec3_t dir, testpoint;
806 int areanum;
807
808 VectorSubtract(end, start, dir);
809 dir[2] = 0;
810 VectorNormalize(dir);
811 VectorMA(end, 48, dir, testpoint);
812
813 areanum = AAS_PointAreaNum(testpoint);
814 if (!areanum)
815 {
816 testpoint[2] += 16;
817 areanum = AAS_PointAreaNum(testpoint);
818 if (!areanum) return qtrue;
819 } //end if
820 VectorMA(end, 64, dir, testpoint);
821 areanum = AAS_PointAreaNum(testpoint);
822 if (areanum)
823 {
824 if (!AAS_AreaSwim(areanum) && !AAS_AreaGrounded(areanum)) return qtrue;
825 } //end if
826 return qfalse;
827 } //end of the function AAS_SolidGapTime
828 //===========================================================================
829 // searches for swim reachabilities between adjacent areas
830 //
831 // Parameter: -
832 // Returns: -
833 // Changes Globals: -
834 //===========================================================================
835 int AAS_Reachability_Swim(int area1num, int area2num)
836 {
837 int i, j, face1num, face2num, side1;
838 aas_area_t *area1, *area2;
839 aas_lreachability_t *lreach;
840 aas_face_t *face1;
841 aas_plane_t *plane;
842 vec3_t start;
843
844 if (!AAS_AreaSwim(area1num) || !AAS_AreaSwim(area2num)) return qfalse;
845 //if the second area is crouch only
846 if (!(aasworld.areasettings[area2num].presencetype & PRESENCE_NORMAL)) return qfalse;
847
848 area1 = &aasworld.areas[area1num];
849 area2 = &aasworld.areas[area2num];
850
851 //if the areas are not near enough
852 for (i = 0; i < 3; i++)
853 {
854 if (area1->mins[i] > area2->maxs[i] + 10) return qfalse;
855 if (area1->maxs[i] < area2->mins[i] - 10) return qfalse;
856 } //end for
857 //find a shared face and create a reachability link
858 for (i = 0; i < area1->numfaces; i++)
859 {
860 face1num = aasworld.faceindex[area1->firstface + i];
861 side1 = face1num < 0;
862 face1num = abs(face1num);
863 //
864 for (j = 0; j < area2->numfaces; j++)
865 {
866 face2num = abs(aasworld.faceindex[area2->firstface + j]);
867 //
868 if (face1num == face2num)
869 {
870 AAS_FaceCenter(face1num, start);
871 //
872 if (AAS_PointContents(start) & (CONTENTS_LAVA|CONTENTS_SLIME|CONTENTS_WATER))
873 {
874 //
875 face1 = &aasworld.faces[face1num];
876 //create a new reachability link
877 lreach = AAS_AllocReachability();
878 if (!lreach) return qfalse;
879 lreach->areanum = area2num;
880 lreach->facenum = face1num;
881 lreach->edgenum = 0;
882 VectorCopy(start, lreach->start);
883 plane = &aasworld.planes[face1->planenum ^ side1];
884 VectorMA(lreach->start, -INSIDEUNITS, plane->normal, lreach->end);
885 lreach->traveltype = TRAVEL_SWIM;
886 lreach->traveltime = 1;
887 //if the volume of the area is rather small
888 if (AAS_AreaVolume(area2num) < 800)
889 lreach->traveltime += 200;
890 //if (!(AAS_PointContents(start) & MASK_WATER)) lreach->traveltime += 500;
891 //link the reachability
892 lreach->next = areareachability[area1num];
893 areareachability[area1num] = lreach;
894 reach_swim++;
895 return qtrue;
896 } //end if
897 } //end if
898 } //end for
899 } //end for
900 return qfalse;
901 } //end of the function AAS_Reachability_Swim
902 //===========================================================================
903 // searches for reachabilities between adjacent areas with equal floor
904 // heights
905 //
906 // Parameter: -
907 // Returns: -
908 // Changes Globals: -
909 //===========================================================================
910 int AAS_Reachability_EqualFloorHeight(int area1num, int area2num)
911 {
912 int i, j, edgenum, edgenum1, edgenum2, foundreach, side;
913 float height, bestheight, length, bestlength;
914 vec3_t dir, start, end, normal, invgravity, gravitydirection = {0, 0, -1};
915 vec3_t edgevec;
916 aas_area_t *area1, *area2;
917 aas_face_t *face1, *face2;
918 aas_edge_t *edge;
919 aas_plane_t *plane2;
920 aas_lreachability_t lr, *lreach;
921
922 if (!AAS_AreaGrounded(area1num) || !AAS_AreaGrounded(area2num)) return qfalse;
923
924 area1 = &aasworld.areas[area1num];
925 area2 = &aasworld.areas[area2num];
926 //if the areas are not near enough in the x-y direction
927 for (i = 0; i < 2; i++)
928 {
929 if (area1->mins[i] > area2->maxs[i] + 10) return qfalse;
930 if (area1->maxs[i] < area2->mins[i] - 10) return qfalse;
931 } //end for
932 //if area 2 is too high above area 1
933 if (area2->mins[2] > area1->maxs[2]) return qfalse;
934 //
935 VectorCopy(gravitydirection, invgravity);
936 VectorInverse(invgravity);
937 //
938 bestheight = 99999;
939 bestlength = 0;
940 foundreach = qfalse;
941 Com_Memset(&lr, 0, sizeof(aas_lreachability_t)); //make the compiler happy
942 //
943 //check if the areas have ground faces with a common edge
944 //if existing use the lowest common edge for a reachability link
945 for (i = 0; i < area1->numfaces; i++)
946 {
947 face1 = &aasworld.faces[abs(aasworld.faceindex[area1->firstface + i])];
948 if (!(face1->faceflags & FACE_GROUND)) continue;
949 //
950 for (j = 0; j < area2->numfaces; j++)
951 {
952 face2 = &aasworld.faces[abs(aasworld.faceindex[area2->firstface + j])];
953 if (!(face2->faceflags & FACE_GROUND)) continue;
954 //if there is a common edge
955 for (edgenum1 = 0; edgenum1 < face1->numedges; edgenum1++)
956 {
957 for (edgenum2 = 0; edgenum2 < face2->numedges; edgenum2++)
958 {
959 if (abs(aasworld.edgeindex[face1->firstedge + edgenum1]) !=
960 abs(aasworld.edgeindex[face2->firstedge + edgenum2]))
961 continue;
962 edgenum = aasworld.edgeindex[face1->firstedge + edgenum1];
963 side = edgenum < 0;
964 edge = &aasworld.edges[abs(edgenum)];
965 //get the length of the edge
966 VectorSubtract(aasworld.vertexes[edge->v[1]],
967 aasworld.vertexes[edge->v[0]], dir);
968 length = VectorLength(dir);
969 //get the start point
970 VectorAdd(aasworld.vertexes[edge->v[0]],
971 aasworld.vertexes[edge->v[1]], start);
972 VectorScale(start, 0.5, start);
973 VectorCopy(start, end);
974 //get the end point several units inside area2
975 //and the start point several units inside area1
976 //NOTE: normal is pointing into area2 because the
977 //face edges are stored counter clockwise
978 VectorSubtract(aasworld.vertexes[edge->v[side]],
979 aasworld.vertexes[edge->v[!side]], edgevec);
980 plane2 = &aasworld.planes[face2->planenum];
981 CrossProduct(edgevec, plane2->normal, normal);
982 VectorNormalize(normal);
983 //
984 //VectorMA(start, -1, normal, start);
985 VectorMA(end, INSIDEUNITS_WALKEND, normal, end);
986 VectorMA(start, INSIDEUNITS_WALKSTART, normal, start);
987 end[2] += 0.125;
988 //
989 height = DotProduct(invgravity, start);
990 //NOTE: if there's nearby solid or a gap area after this area
991 //disabled this crap
992 //if (AAS_NearbySolidOrGap(start, end)) height += 200;
993 //NOTE: disabled because it disables reachabilities to very small areas
994 //if (AAS_PointAreaNum(end) != area2num) continue;
995 //get the longest lowest edge
996 if (height < bestheight ||
997 (height < bestheight + 1 && length > bestlength))
998 {
999 bestheight = height;
1000 bestlength = length;
1001 //create a new reachability link
1002 lr.areanum = area2num;
1003 lr.facenum = 0;
1004 lr.edgenum = edgenum;
1005 VectorCopy(start, lr.start);
1006 VectorCopy(end, lr.end);
1007 lr.traveltype = TRAVEL_WALK;
1008 lr.traveltime = 1;
1009 foundreach = qtrue;
1010 } //end if
1011 } //end for
1012 } //end for
1013 } //end for
1014 } //end for
1015 if (foundreach)
1016 {
1017 //create a new reachability link
1018 lreach = AAS_AllocReachability();
1019 if (!lreach) return qfalse;
1020 lreach->areanum = lr.areanum;
1021 lreach->facenum = lr.facenum;
1022 lreach->edgenum = lr.edgenum;
1023 VectorCopy(lr.start, lreach->start);
1024 VectorCopy(lr.end, lreach->end);
1025 lreach->traveltype = lr.traveltype;
1026 lreach->traveltime = lr.traveltime;
1027 lreach->next = areareachability[area1num];
1028 areareachability[area1num] = lreach;
1029 //if going into a crouch area
1030 if (!AAS_AreaCrouch(area1num) && AAS_AreaCrouch(area2num))
1031 {
1032 lreach->traveltime += aassettings.rs_startcrouch;
1033 } //end if
1034 /*
1035 //NOTE: if there's nearby solid or a gap area after this area
1036 if (!AAS_NearbySolidOrGap(lreach->start, lreach->end))
1037 {
1038 lreach->traveltime += 100;
1039 } //end if
1040 */
1041 //avoid rather small areas
1042 //if (AAS_AreaGroundFaceArea(lreach->areanum) < 500) lreach->traveltime += 100;
1043 //
1044 reach_equalfloor++;
1045 return qtrue;
1046 } //end if
1047 return qfalse;
1048 } //end of the function AAS_Reachability_EqualFloorHeight
1049 //===========================================================================
1050 // searches step, barrier, waterjump and walk off ledge reachabilities
1051 //
1052 // Parameter: -
1053 // Returns: -
1054 // Changes Globals: -
1055 //===========================================================================
1056 int AAS_Reachability_Step_Barrier_WaterJump_WalkOffLedge(int area1num, int area2num)
1057 {
1058 int i, j, k, l, edge1num, edge2num, areas[10], numareas;
1059 int ground_bestarea2groundedgenum, ground_foundreach;
1060 int water_bestarea2groundedgenum, water_foundreach;
1061 int side1, area1swim, faceside1, groundface1num;
1062 float dist, dist1, dist2, diff, ortdot;
1063 //float invgravitydot;
1064 float x1, x2, x3, x4, y1, y2, y3, y4, tmp, y;
1065 float length, ground_bestlength, water_bestlength, ground_bestdist, water_bestdist;
1066 vec3_t v1, v2, v3, v4, tmpv, p1area1, p1area2, p2area1, p2area2;
1067 vec3_t normal, ort, edgevec, start, end, dir;
1068 vec3_t ground_beststart = {0, 0, 0}, ground_bestend = {0, 0, 0}, ground_bestnormal = {0, 0, 0};
1069 vec3_t water_beststart = {0, 0, 0}, water_bestend = {0, 0, 0}, water_bestnormal = {0, 0, 0};
1070 vec3_t invgravity = {0, 0, 1};
1071 vec3_t testpoint;
1072 aas_plane_t *plane;
1073 aas_area_t *area1, *area2;
1074 aas_face_t *groundface1, *groundface2;
1075 aas_edge_t *edge1, *edge2;
1076 aas_lreachability_t *lreach;
1077 aas_trace_t trace;
1078
1079 //must be able to walk or swim in the first area
1080 if (!AAS_AreaGrounded(area1num) && !AAS_AreaSwim(area1num)) return qfalse;
1081 //
1082 if (!AAS_AreaGrounded(area2num) && !AAS_AreaSwim(area2num)) return qfalse;
1083 //
1084 area1 = &aasworld.areas[area1num];
1085 area2 = &aasworld.areas[area2num];
1086 //if the first area contains a liquid
1087 area1swim = AAS_AreaSwim(area1num);
1088 //if the areas are not near enough in the x-y direction
1089 for (i = 0; i < 2; i++)
1090 {
1091 if (area1->mins[i] > area2->maxs[i] + 10) return qfalse;
1092 if (area1->maxs[i] < area2->mins[i] - 10) return qfalse;
1093 } //end for
1094 //
1095 ground_foundreach = qfalse;
1096 ground_bestdist = 99999;
1097 ground_bestlength = 0;
1098 ground_bestarea2groundedgenum = 0;
1099 //
1100 water_foundreach = qfalse;
1101 water_bestdist = 99999;
1102 water_bestlength = 0;
1103 water_bestarea2groundedgenum = 0;
1104 //
1105 for (i = 0; i < area1->numfaces; i++)
1106 {
1107 groundface1num = aasworld.faceindex[area1->firstface + i];
1108 faceside1 = groundface1num < 0;
1109 groundface1 = &aasworld.faces[abs(groundface1num)];
1110 //if this isn't a ground face
1111 if (!(groundface1->faceflags & FACE_GROUND))
1112 {
1113 //if we can swim in the first area
1114 if (area1swim)
1115 {
1116 //face plane must be more or less horizontal
1117 plane = &aasworld.planes[groundface1->planenum ^ (!faceside1)];
1118 if (DotProduct(plane->normal, invgravity) < 0.7) continue;
1119 } //end if
1120 else
1121 {
1122 //if we can't swim in the area it must be a ground face
1123 continue;
1124 } //end else
1125 } //end if
1126 //
1127 for (k = 0; k < groundface1->numedges; k++)
1128 {
1129 edge1num = aasworld.edgeindex[groundface1->firstedge + k];
1130 side1 = (edge1num < 0);
1131 //NOTE: for water faces we must take the side area 1 is
1132 // on into account because the face is shared and doesn't
1133 // have to be oriented correctly
1134 if (!(groundface1->faceflags & FACE_GROUND)) side1 = (side1 == faceside1);
1135 edge1num = abs(edge1num);
1136 edge1 = &aasworld.edges[edge1num];
1137 //vertexes of the edge
1138 VectorCopy(aasworld.vertexes[edge1->v[!side1]], v1);
1139 VectorCopy(aasworld.vertexes[edge1->v[side1]], v2);
1140 //get a vertical plane through the edge
1141 //NOTE: normal is pointing into area 2 because the
1142 //face edges are stored counter clockwise
1143 VectorSubtract(v2, v1, edgevec);
1144 CrossProduct(edgevec, invgravity, normal);
1145 VectorNormalize(normal);
1146 dist = DotProduct(normal, v1);
1147 //check the faces from the second area
1148 for (j = 0; j < area2->numfaces; j++)
1149 {
1150 groundface2 = &aasworld.faces[abs(aasworld.faceindex[area2->firstface + j])];
1151 //must be a ground face
1152 if (!(groundface2->faceflags & FACE_GROUND)) continue;
1153 //check the edges of this ground face
1154 for (l = 0; l < groundface2->numedges; l++)
1155 {
1156 edge2num = abs(aasworld.edgeindex[groundface2->firstedge + l]);
1157 edge2 = &aasworld.edges[edge2num];
1158 //vertexes of the edge
1159 VectorCopy(aasworld.vertexes[edge2->v[0]], v3);
1160 VectorCopy(aasworld.vertexes[edge2->v[1]], v4);
1161 //check the distance between the two points and the vertical plane
1162 //through the edge of area1
1163 diff = DotProduct(normal, v3) - dist;
1164 if (diff < -0.1 || diff > 0.1) continue;
1165 diff = DotProduct(normal, v4) - dist;
1166 if (diff < -0.1 || diff > 0.1) continue;
1167 //
1168 //project the two ground edges into the step side plane
1169 //and calculate the shortest distance between the two
1170 //edges if they overlap in the direction orthogonal to
1171 //the gravity direction
1172 CrossProduct(invgravity, normal, ort);
1173 //invgravitydot = DotProduct(invgravity, invgravity);
1174 ortdot = DotProduct(ort, ort);
1175 //projection into the step plane
1176 //NOTE: since gravity is vertical this is just the z coordinate
1177 y1 = v1[2];//DotProduct(v1, invgravity) / invgravitydot;
1178 y2 = v2[2];//DotProduct(v2, invgravity) / invgravitydot;
1179 y3 = v3[2];//DotProduct(v3, invgravity) / invgravitydot;
1180 y4 = v4[2];//DotProduct(v4, invgravity) / invgravitydot;
1181 //
1182 x1 = DotProduct(v1, ort) / ortdot;
1183 x2 = DotProduct(v2, ort) / ortdot;
1184 x3 = DotProduct(v3, ort) / ortdot;
1185 x4 = DotProduct(v4, ort) / ortdot;
1186 //
1187 if (x1 > x2)
1188 {
1189 tmp = x1; x1 = x2; x2 = tmp;
1190 tmp = y1; y1 = y2; y2 = tmp;
1191 VectorCopy(v1, tmpv); VectorCopy(v2, v1); VectorCopy(tmpv, v2);
1192 } //end if
1193 if (x3 > x4)
1194 {
1195 tmp = x3; x3 = x4; x4 = tmp;
1196 tmp = y3; y3 = y4; y4 = tmp;
1197 VectorCopy(v3, tmpv); VectorCopy(v4, v3); VectorCopy(tmpv, v4);
1198 } //end if
1199 //if the two projected edge lines have no overlap
1200 if (x2 <= x3 || x4 <= x1)
1201 {
1202 // Log_Write("lines no overlap: from area %d to %d\r\n", area1num, area2num);
1203 continue;
1204 } //end if
1205 //if the two lines fully overlap
1206 if ((x1 - 0.5 < x3 && x4 < x2 + 0.5) &&
1207 (x3 - 0.5 < x1 && x2 < x4 + 0.5))
1208 {
1209 dist1 = y3 - y1;
1210 dist2 = y4 - y2;
1211 VectorCopy(v1, p1area1);
1212 VectorCopy(v2, p2area1);
1213 VectorCopy(v3, p1area2);
1214 VectorCopy(v4, p2area2);
1215 } //end if
1216 else
1217 {
1218 //if the points are equal
1219 if (x1 > x3 - 0.1 && x1 < x3 + 0.1)
1220 {
1221 dist1 = y3 - y1;
1222 VectorCopy(v1, p1area1);
1223 VectorCopy(v3, p1area2);
1224 } //end if
1225 else if (x1 < x3)
1226 {
1227 y = y1 + (x3 - x1) * (y2 - y1) / (x2 - x1);
1228 dist1 = y3 - y;
1229 VectorCopy(v3, p1area1);
1230 p1area1[2] = y;
1231 VectorCopy(v3, p1area2);
1232 } //end if
1233 else
1234 {
1235 y = y3 + (x1 - x3) * (y4 - y3) / (x4 - x3);
1236 dist1 = y - y1;
1237 VectorCopy(v1, p1area1);
1238 VectorCopy(v1, p1area2);
1239 p1area2[2] = y;
1240 } //end if
1241 //if the points are equal
1242 if (x2 > x4 - 0.1 && x2 < x4 + 0.1)
1243 {
1244 dist2 = y4 - y2;
1245 VectorCopy(v2, p2area1);
1246 VectorCopy(v4, p2area2);
1247 } //end if
1248 else if (x2 < x4)
1249 {
1250 y = y3 + (x2 - x3) * (y4 - y3) / (x4 - x3);
1251 dist2 = y - y2;
1252 VectorCopy(v2, p2area1);
1253 VectorCopy(v2, p2area2);
1254 p2area2[2] = y;
1255 } //end if
1256 else
1257 {
1258 y = y1 + (x4 - x1) * (y2 - y1) / (x2 - x1);
1259 dist2 = y4 - y;
1260 VectorCopy(v4, p2area1);
1261 p2area1[2] = y;
1262 VectorCopy(v4, p2area2);
1263 } //end else
1264 } //end else
1265 //if both distances are pretty much equal
1266 //then we take the middle of the points
1267 if (dist1 > dist2 - 1 && dist1 < dist2 + 1)
1268 {
1269 dist = dist1;
1270 VectorAdd(p1area1, p2area1, start);
1271 VectorScale(start, 0.5, start);
1272 VectorAdd(p1area2, p2area2, end);
1273 VectorScale(end, 0.5, end);
1274 } //end if
1275 else if (dist1 < dist2)
1276 {
1277 dist = dist1;
1278 VectorCopy(p1area1, start);
1279 VectorCopy(p1area2, end);
1280 } //end else if
1281 else
1282 {
1283 dist = dist2;
1284 VectorCopy(p2area1, start);
1285 VectorCopy(p2area2, end);
1286 } //end else
1287 //get the length of the overlapping part of the edges of the two areas
1288 VectorSubtract(p2area2, p1area2, dir);
1289 length = VectorLength(dir);
1290 //
1291 if (groundface1->faceflags & FACE_GROUND)
1292 {
1293 //if the vertical distance is smaller
1294 if (dist < ground_bestdist ||
1295 //or the vertical distance is pretty much the same
1296 //but the overlapping part of the edges is longer
1297 (dist < ground_bestdist + 1 && length > ground_bestlength))
1298 {
1299 ground_bestdist = dist;
1300 ground_bestlength = length;
1301 ground_foundreach = qtrue;
1302 ground_bestarea2groundedgenum = edge1num;
1303 //best point towards area1
1304 VectorCopy(start, ground_beststart);
1305 //normal is pointing into area2
1306 VectorCopy(normal, ground_bestnormal);
1307 //best point towards area2
1308 VectorCopy(end, ground_bestend);
1309 } //end if
1310 } //end if
1311 else
1312 {
1313 //if the vertical distance is smaller
1314 if (dist < water_bestdist ||
1315 //or the vertical distance is pretty much the same
1316 //but the overlapping part of the edges is longer
1317 (dist < water_bestdist + 1 && length > water_bestlength))
1318 {
1319 water_bestdist = dist;
1320 water_bestlength = length;
1321 water_foundreach = qtrue;
1322 water_bestarea2groundedgenum = edge1num;
1323 //best point towards area1
1324 VectorCopy(start, water_beststart);
1325 //normal is pointing into area2
1326 VectorCopy(normal, water_bestnormal);
1327 //best point towards area2
1328 VectorCopy(end, water_bestend);
1329 } //end if
1330 } //end else
1331 } //end for
1332 } //end for
1333 } //end for
1334 } //end for
1335 //
1336 // NOTE: swim reachabilities are already filtered out
1337 //
1338 // Steps
1339 //
1340 // ---------
1341 // | step height -> TRAVEL_WALK
1342 //--------|
1343 //
1344 // ---------
1345 //~~~~~~~~| step height and low water -> TRAVEL_WALK
1346 //--------|
1347 //
1348 //~~~~~~~~~~~~~~~~~~
1349 // ---------
1350 // | step height and low water up to the step -> TRAVEL_WALK
1351 //--------|
1352 //
1353 //check for a step reachability
1354 if (ground_foundreach)
1355 {
1356 //if area2 is higher but lower than the maximum step height
1357 //NOTE: ground_bestdist >= 0 also catches equal floor reachabilities
1358 if (ground_bestdist >= 0 && ground_bestdist < aassettings.phys_maxstep)
1359 {
1360 //create walk reachability from area1 to area2
1361 lreach = AAS_AllocReachability();
1362 if (!lreach) return qfalse;
1363 lreach->areanum = area2num;
1364 lreach->facenum = 0;
1365 lreach->edgenum = ground_bestarea2groundedgenum;
1366 VectorMA(ground_beststart, INSIDEUNITS_WALKSTART, ground_bestnormal, lreach->start);
1367 VectorMA(ground_bestend, INSIDEUNITS_WALKEND, ground_bestnormal, lreach->end);
1368 lreach->traveltype = TRAVEL_WALK;
1369 lreach->traveltime = 0;//1;
1370 //if going into a crouch area
1371 if (!AAS_AreaCrouch(area1num) && AAS_AreaCrouch(area2num))
1372 {
1373 lreach->traveltime += aassettings.rs_startcrouch;
1374 } //end if
1375 lreach->next = areareachability[area1num];
1376 areareachability[area1num] = lreach;
1377 //NOTE: if there's nearby solid or a gap area after this area
1378 /*
1379 if (!AAS_NearbySolidOrGap(lreach->start, lreach->end))
1380 {
1381 lreach->traveltime += 100;
1382 } //end if
1383 */
1384 //avoid rather small areas
1385 //if (AAS_AreaGroundFaceArea(lreach->areanum) < 500) lreach->traveltime += 100;
1386 //
1387 reach_step++;
1388 return qtrue;
1389 } //end if
1390 } //end if
1391 //
1392 // Water Jumps
1393 //
1394 // ---------
1395 // |
1396 //~~~~~~~~|
1397 // |
1398 // | higher than step height and water up to waterjump height -> TRAVEL_WATERJUMP
1399 //--------|
1400 //
1401 //~~~~~~~~~~~~~~~~~~
1402 // ---------
1403 // |
1404 // |
1405 // |
1406 // | higher than step height and low water up to the step -> TRAVEL_WATERJUMP
1407 //--------|
1408 //
1409 //check for a waterjump reachability
1410 if (water_foundreach)
1411 {
1412 //get a test point a little bit towards area1
1413 VectorMA(water_bestend, -INSIDEUNITS, water_bestnormal, testpoint);
1414 //go down the maximum waterjump height
1415 testpoint[2] -= aassettings.phys_maxwaterjump;
1416 //if there IS water the sv_maxwaterjump height below the bestend point
1417 if (aasworld.areasettings[AAS_PointAreaNum(testpoint)].areaflags & AREA_LIQUID)
1418 {
1419 //don't create ridiculous water jump reachabilities from areas very far below
1420 //the water surface
1421 if (water_bestdist < aassettings.phys_maxwaterjump + 24)
1422 {
1423 //waterjumping from or towards a crouch only area is not possible in Quake2
1424 if ((aasworld.areasettings[area1num].presencetype & PRESENCE_NORMAL) &&
1425 (aasworld.areasettings[area2num].presencetype & PRESENCE_NORMAL))
1426 {
1427 //create water jump reachability from area1 to area2
1428 lreach = AAS_AllocReachability();
1429 if (!lreach) return qfalse;
1430 lreach->areanum = area2num;
1431 lreach->facenum = 0;
1432 lreach->edgenum = water_bestarea2groundedgenum;
1433 VectorCopy(water_beststart, lreach->start);
1434 VectorMA(water_bestend, INSIDEUNITS_WATERJUMP, water_bestnormal, lreach->end);
1435 lreach->traveltype = TRAVEL_WATERJUMP;
1436 lreach->traveltime = aassettings.rs_waterjump;
1437 lreach->next = areareachability[area1num];
1438 areareachability[area1num] = lreach;
1439 //we've got another waterjump reachability
1440 reach_waterjump++;
1441 return qtrue;
1442 } //end if
1443 } //end if
1444 } //end if
1445 } //end if
1446 //
1447 // Barrier Jumps
1448 //
1449 // ---------
1450 // |
1451 // |
1452 // |
1453 // | higher than step height lower than barrier height -> TRAVEL_BARRIERJUMP
1454 //--------|
1455 //
1456 // ---------
1457 // |
1458 // |
1459 // |
1460 //~~~~~~~~| higher than step height lower than barrier height
1461 //--------| and a thin layer of water in the area to jump from -> TRAVEL_BARRIERJUMP
1462 //
1463 //check for a barrier jump reachability
1464 if (ground_foundreach)
1465 {
1466 //if area2 is higher but lower than the maximum barrier jump height
1467 if (ground_bestdist > 0 && ground_bestdist < aassettings.phys_maxbarrier)
1468 {
1469 //if no water in area1 or a very thin layer of water on the ground
1470 if (!water_foundreach || (ground_bestdist - water_bestdist < 16))
1471 {
1472 //cannot perform a barrier jump towards or from a crouch area in Quake2
1473 if (!AAS_AreaCrouch(area1num) && !AAS_AreaCrouch(area2num))
1474 {
1475 //create barrier jump reachability from area1 to area2
1476 lreach = AAS_AllocReachability();
1477 if (!lreach) return qfalse;
1478 lreach->areanum = area2num;
1479 lreach->facenum = 0;
1480 lreach->edgenum = ground_bestarea2groundedgenum;
1481 VectorMA(ground_beststart, INSIDEUNITS_WALKSTART, ground_bestnormal, lreach->start);
1482 VectorMA(ground_bestend, INSIDEUNITS_WALKEND, ground_bestnormal, lreach->end);
1483 lreach->traveltype = TRAVEL_BARRIERJUMP;
1484 lreach->traveltime = aassettings.rs_barrierjump;//AAS_BarrierJumpTravelTime();
1485 lreach->next = areareachability[area1num];
1486 areareachability[area1num] = lreach;
1487 //we've got another barrierjump reachability
1488 reach_barrier++;
1489 return qtrue;
1490 } //end if
1491 } //end if
1492 } //end if
1493 } //end if
1494 //
1495 // Walk and Walk Off Ledge
1496 //
1497 //--------|
1498 // | can walk or step back -> TRAVEL_WALK
1499 // ---------
1500 //
1501 //--------|
1502 // |
1503 // |
1504 // |
1505 // | cannot walk/step back -> TRAVEL_WALKOFFLEDGE
1506 // ---------
1507 //
1508 //--------|
1509 // |
1510 // |~~~~~~~~
1511 // |
1512 // | cannot step back but can waterjump back -> TRAVEL_WALKOFFLEDGE
1513 // --------- FIXME: create TRAVEL_WALK reach??
1514 //
1515 //check for a walk or walk off ledge reachability
1516 if (ground_foundreach)
1517 {
1518 if (ground_bestdist < 0)
1519 {
1520 if (ground_bestdist > -aassettings.phys_maxstep)
1521 {
1522 //create walk reachability from area1 to area2
1523 lreach = AAS_AllocReachability();
1524 if (!lreach) return qfalse;
1525 lreach->areanum = area2num;
1526 lreach->facenum = 0;
1527 lreach->edgenum = ground_bestarea2groundedgenum;
1528 VectorMA(ground_beststart, INSIDEUNITS_WALKSTART, ground_bestnormal, lreach->start);
1529 VectorMA(ground_bestend, INSIDEUNITS_WALKEND, ground_bestnormal, lreach->end);
1530 lreach->traveltype = TRAVEL_WALK;
1531 lreach->traveltime = 1;
1532 lreach->next = areareachability[area1num];
1533 areareachability[area1num] = lreach;
1534 //we've got another walk reachability
1535 reach_walk++;
1536 return qtrue;
1537 } //end if
1538 // if no maximum fall height set or less than the max
1539 if (!aassettings.rs_maxfallheight || fabs(ground_bestdist) < aassettings.rs_maxfallheight) {
1540 //trace a bounding box vertically to check for solids
1541 VectorMA(ground_bestend, INSIDEUNITS, ground_bestnormal, ground_bestend);
1542 VectorCopy(ground_bestend, start);
1543 start[2] = ground_beststart[2];
1544 VectorCopy(ground_bestend, end);
1545 end[2] += 4;
1546 trace = AAS_TraceClientBBox(start, end, PRESENCE_NORMAL, -1);
1547 //if no solids were found
1548 if (!trace.startsolid && trace.fraction >= 1.0)
1549 {
1550 //the trace end point must be in the goal area
1551 trace.endpos[2] += 1;
1552 if (AAS_PointAreaNum(trace.endpos) == area2num)
1553 {
1554 //if not going through a cluster portal
1555 numareas = AAS_TraceAreas(start, end, areas, NULL, ARRAY_LEN(areas));
1556 for (i = 0; i < numareas; i++)
1557 if (AAS_AreaClusterPortal(areas[i]))
1558 break;
1559 if (i >= numareas)
1560 {
1561 //create a walk off ledge reachability from area1 to area2
1562 lreach = AAS_AllocReachability();
1563 if (!lreach) return qfalse;
1564 lreach->areanum = area2num;
1565 lreach->facenum = 0;
1566 lreach->edgenum = ground_bestarea2groundedgenum;
1567 VectorCopy(ground_beststart, lreach->start);
1568 VectorCopy(ground_bestend, lreach->end);
1569 lreach->traveltype = TRAVEL_WALKOFFLEDGE;
1570 lreach->traveltime = aassettings.rs_startwalkoffledge + fabs(ground_bestdist) * 50 / aassettings.phys_gravity;
1571 //if falling from too high and not falling into water
1572 if (!AAS_AreaSwim(area2num) && !AAS_AreaJumpPad(area2num))
1573 {
1574 if (AAS_FallDelta(ground_bestdist) > aassettings.phys_falldelta5)
1575 {
1576 lreach->traveltime += aassettings.rs_falldamage5;
1577 } //end if
1578 if (AAS_FallDelta(ground_bestdist) > aassettings.phys_falldelta10)
1579 {
1580 lreach->traveltime += aassettings.rs_falldamage10;
1581 } //end if
1582 } //end if
1583 lreach->next = areareachability[area1num];
1584 areareachability[area1num] = lreach;
1585 //
1586 reach_walkoffledge++;
1587 //NOTE: don't create a weapon (rl, bfg) jump reachability here
1588 //because it interferes with other reachabilities
1589 //like the ladder reachability
1590 return qtrue;
1591 } //end if
1592 } //end if
1593 } //end if
1594 } //end if
1595 } //end else
1596 } //end if
1597 return qfalse;
1598 } //end of the function AAS_Reachability_Step_Barrier_WaterJump_WalkOffLedge
1599 //===========================================================================
1600 // returns the distance between the two vectors
1601 //
1602 // Parameter: -
1603 // Returns: -
1604 // Changes Globals: -
1605 //===========================================================================
1606 float VectorDistance(vec3_t v1, vec3_t v2)
1607 {
1608 vec3_t dir;
1609
1610 VectorSubtract(v2, v1, dir);
1611 return VectorLength(dir);
1612 } //end of the function VectorDistance
1613 //===========================================================================
1614 // returns true if the first vector is between the last two vectors
1615 //
1616 // Parameter: -
1617 // Returns: -
1618 // Changes Globals: -
1619 //===========================================================================
1620 int VectorBetweenVectors(vec3_t v, vec3_t v1, vec3_t v2)
1621 {
1622 vec3_t dir1, dir2;
1623
1624 VectorSubtract(v, v1, dir1);
1625 VectorSubtract(v, v2, dir2);
1626 return (DotProduct(dir1, dir2) <= 0);
1627 } //end of the function VectorBetweenVectors
1628 //===========================================================================
1629 // returns the mid point between the two vectors
1630 //
1631 // Parameter: -
1632 // Returns: -
1633 // Changes Globals: -
1634 //===========================================================================
1635 void VectorMiddle(vec3_t v1, vec3_t v2, vec3_t middle)
1636 {
1637 VectorAdd(v1, v2, middle);
1638 VectorScale(middle, 0.5, middle);
1639 } //end of the function VectorMiddle
1640 //===========================================================================
1641 // calculate a range of points closest to each other on both edges
1642 //
1643 // Parameter: beststart1 start of the range of points on edge v1-v2
1644 // beststart2 end of the range of points on edge v1-v2
1645 // bestend1 start of the range of points on edge v3-v4
1646 // bestend2 end of the range of points on edge v3-v4
1647 // bestdist best distance so far
1648 // Returns: -
1649 // Changes Globals: -
1650 //===========================================================================
1651 /*
1652 float AAS_ClosestEdgePoints(vec3_t v1, vec3_t v2, vec3_t v3, vec3_t v4,
1653 aas_plane_t *plane1, aas_plane_t *plane2,
1654 vec3_t beststart, vec3_t bestend, float bestdist)
1655 {
1656 vec3_t dir1, dir2, p1, p2, p3, p4;
1657 float a1, a2, b1, b2, dist;
1658 int founddist;
1659
1660 //edge vectors
1661 VectorSubtract(v2, v1, dir1);
1662 VectorSubtract(v4, v3, dir2);
1663 //get the horizontal directions
1664 dir1[2] = 0;
1665 dir2[2] = 0;
1666 //
1667 // p1 = point on an edge vector of area2 closest to v1
1668 // p2 = point on an edge vector of area2 closest to v2
1669 // p3 = point on an edge vector of area1 closest to v3
1670 // p4 = point on an edge vector of area1 closest to v4
1671 //
1672 if (dir2[0])
1673 {
1674 a2 = dir2[1] / dir2[0];
1675 b2 = v3[1] - a2 * v3[0];
1676 //point on the edge vector of area2 closest to v1
1677 p1[0] = (DotProduct(v1, dir2) - (a2 * dir2[0] + b2 * dir2[1])) / dir2[0];
1678 p1[1] = a2 * p1[0] + b2;
1679 //point on the edge vector of area2 closest to v2
1680 p2[0] = (DotProduct(v2, dir2) - (a2 * dir2[0] + b2 * dir2[1])) / dir2[0];
1681 p2[1] = a2 * p2[0] + b2;
1682 } //end if
1683 else
1684 {
1685 //point on the edge vector of area2 closest to v1
1686 p1[0] = v3[0];
1687 p1[1] = v1[1];
1688 //point on the edge vector of area2 closest to v2
1689 p2[0] = v3[0];
1690 p2[1] = v2[1];
1691 } //end else
1692 //
1693 if (dir1[0])
1694 {
1695 //
1696 a1 = dir1[1] / dir1[0];
1697 b1 = v1[1] - a1 * v1[0];
1698 //point on the edge vector of area1 closest to v3
1699 p3[0] = (DotProduct(v3, dir1) - (a1 * dir1[0] + b1 * dir1[1])) / dir1[0];
1700 p3[1] = a1 * p3[0] + b1;
1701 //point on the edge vector of area1 closest to v4
1702 p4[0] = (DotProduct(v4, dir1) - (a1 * dir1[0] + b1 * dir1[1])) / dir1[0];
1703 p4[1] = a1 * p4[0] + b1;
1704 } //end if
1705 else
1706 {
1707 //point on the edge vector of area1 closest to v3
1708 p3[0] = v1[0];
1709 p3[1] = v3[1];
1710 //point on the edge vector of area1 closest to v4
1711 p4[0] = v1[0];
1712 p4[1] = v4[1];
1713 } //end else
1714 //start with zero z-coordinates
1715 p1[2] = 0;
1716 p2[2] = 0;
1717 p3[2] = 0;
1718 p4[2] = 0;
1719 //calculate the z-coordinates from the ground planes
1720 p1[2] = (plane2->dist - DotProduct(plane2->normal, p1)) / plane2->normal[2];
1721 p2[2] = (plane2->dist - DotProduct(plane2->normal, p2)) / plane2->normal[2];
1722 p3[2] = (plane1->dist - DotProduct(plane1->normal, p3)) / plane1->normal[2];
1723 p4[2] = (plane1->dist - DotProduct(plane1->normal, p4)) / plane1->normal[2];
1724 //
1725 founddist = qfalse;
1726 //
1727 if (VectorBetweenVectors(p1, v3, v4))
1728 {
1729 dist = VectorDistance(v1, p1);
1730 if (dist > bestdist - 0.5 && dist < bestdist + 0.5)
1731 {
1732 VectorMiddle(beststart, v1, beststart);
1733 VectorMiddle(bestend, p1, bestend);
1734 } //end if
1735 else if (dist < bestdist)
1736 {
1737 bestdist = dist;
1738 VectorCopy(v1, beststart);
1739 VectorCopy(p1, bestend);
1740 } //end if
1741 founddist = qtrue;
1742 } //end if
1743 if (VectorBetweenVectors(p2, v3, v4))
1744 {
1745 dist = VectorDistance(v2, p2);
1746 if (dist > bestdist - 0.5 && dist < bestdist + 0.5)
1747 {
1748 VectorMiddle(beststart, v2, beststart);
1749 VectorMiddle(bestend, p2, bestend);
1750 } //end if
1751 else if (dist < bestdist)
1752 {
1753 bestdist = dist;
1754 VectorCopy(v2, beststart);
1755 VectorCopy(p2, bestend);
1756 } //end if
1757 founddist = qtrue;
1758 } //end else if
1759 if (VectorBetweenVectors(p3, v1, v2))
1760 {
1761 dist = VectorDistance(v3, p3);
1762 if (dist > bestdist - 0.5 && dist < bestdist + 0.5)
1763 {
1764 VectorMiddle(beststart, p3, beststart);
1765 VectorMiddle(bestend, v3, bestend);
1766 } //end if
1767 else if (dist < bestdist)
1768 {
1769 bestdist = dist;
1770 VectorCopy(p3, beststart);
1771 VectorCopy(v3, bestend);
1772 } //end if
1773 founddist = qtrue;
1774 } //end else if
1775 if (VectorBetweenVectors(p4, v1, v2))
1776 {
1777 dist = VectorDistance(v4, p4);
1778 if (dist > bestdist - 0.5 && dist < bestdist + 0.5)
1779 {
1780 VectorMiddle(beststart, p4, beststart);
1781 VectorMiddle(bestend, v4, bestend);
1782 } //end if
1783 else if (dist < bestdist)
1784 {
1785 bestdist = dist;
1786 VectorCopy(p4, beststart);
1787 VectorCopy(v4, bestend);
1788 } //end if
1789 founddist = qtrue;
1790 } //end else if
1791 //if no shortest distance was found the shortest distance
1792 //is between one of the vertexes of edge1 and one of edge2
1793 if (!founddist)
1794 {
1795 dist = VectorDistance(v1, v3);
1796 if (dist < bestdist)
1797 {
1798 bestdist = dist;
1799 VectorCopy(v1, beststart);
1800 VectorCopy(v3, bestend);
1801 } //end if
1802 dist = VectorDistance(v1, v4);
1803 if (dist < bestdist)
1804 {
1805 bestdist = dist;
1806 VectorCopy(v1, beststart);
1807 VectorCopy(v4, bestend);
1808 } //end if
1809 dist = VectorDistance(v2, v3);
1810 if (dist < bestdist)
1811 {
1812 bestdist = dist;
1813 VectorCopy(v2, beststart);
1814 VectorCopy(v3, bestend);
1815 } //end if
1816 dist = VectorDistance(v2, v4);
1817 if (dist < bestdist)
1818 {
1819 bestdist = dist;
1820 VectorCopy(v2, beststart);
1821 VectorCopy(v4, bestend);
1822 } //end if
1823 } //end if
1824 return bestdist;
1825 } //end of the function AAS_ClosestEdgePoints*/
1826
1827 float AAS_ClosestEdgePoints(vec3_t v1, vec3_t v2, vec3_t v3, vec3_t v4,
1828 aas_plane_t *plane1, aas_plane_t *plane2,
1829 vec3_t beststart1, vec3_t bestend1,
1830 vec3_t beststart2, vec3_t bestend2, float bestdist)
1831 {
1832 vec3_t dir1, dir2, p1, p2, p3, p4;
1833 float a1, a2, b1, b2, dist, dist1, dist2;
1834 int founddist;
1835
1836 //edge vectors
1837 VectorSubtract(v2, v1, dir1);
1838 VectorSubtract(v4, v3, dir2);
1839 //get the horizontal directions
1840 dir1[2] = 0;
1841 dir2[2] = 0;
1842 //
1843 // p1 = point on an edge vector of area2 closest to v1
1844 // p2 = point on an edge vector of area2 closest to v2
1845 // p3 = point on an edge vector of area1 closest to v3
1846 // p4 = point on an edge vector of area1 closest to v4
1847 //
1848 if (dir2[0])
1849 {
1850 a2 = dir2[1] / dir2[0];
1851 b2 = v3[1] - a2 * v3[0];
1852 //point on the edge vector of area2 closest to v1
1853 p1[0] = (DotProduct(v1, dir2) - (a2 * dir2[0] + b2 * dir2[1])) / dir2[0];
1854 p1[1] = a2 * p1[0] + b2;
1855 //point on the edge vector of area2 closest to v2
1856 p2[0] = (DotProduct(v2, dir2) - (a2 * dir2[0] + b2 * dir2[1])) / dir2[0];
1857 p2[1] = a2 * p2[0] + b2;
1858 } //end if
1859 else
1860 {
1861 //point on the edge vector of area2 closest to v1
1862 p1[0] = v3[0];
1863 p1[1] = v1[1];
1864 //point on the edge vector of area2 closest to v2
1865 p2[0] = v3[0];
1866 p2[1] = v2[1];
1867 } //end else
1868 //
1869 if (dir1[0])
1870 {
1871 //
1872 a1 = dir1[1] / dir1[0];
1873 b1 = v1[1] - a1 * v1[0];
1874 //point on the edge vector of area1 closest to v3
1875 p3[0] = (DotProduct(v3, dir1) - (a1 * dir1[0] + b1 * dir1[1])) / dir1[0];
1876 p3[1] = a1 * p3[0] + b1;
1877 //point on the edge vector of area1 closest to v4
1878 p4[0] = (DotProduct(v4, dir1) - (a1 * dir1[0] + b1 * dir1[1])) / dir1[0];
1879 p4[1] = a1 * p4[0] + b1;
1880 } //end if
1881 else
1882 {
1883 //point on the edge vector of area1 closest to v3
1884 p3[0] = v1[0];
1885 p3[1] = v3[1];
1886 //point on the edge vector of area1 closest to v4
1887 p4[0] = v1[0];
1888 p4[1] = v4[1];
1889 } //end else
1890 //start with zero z-coordinates
1891 p1[2] = 0;
1892 p2[2] = 0;
1893 p3[2] = 0;
1894 p4[2] = 0;
1895 //calculate the z-coordinates from the ground planes
1896 p1[2] = (plane2->dist - DotProduct(plane2->normal, p1)) / plane2->normal[2];
1897 p2[2] = (plane2->dist - DotProduct(plane2->normal, p2)) / plane2->normal[2];
1898 p3[2] = (plane1->dist - DotProduct(plane1->normal, p3)) / plane1->normal[2];
1899 p4[2] = (plane1->dist - DotProduct(plane1->normal, p4)) / plane1->normal[2];
1900 //
1901 founddist = qfalse;
1902 //
1903 if (VectorBetweenVectors(p1, v3, v4))
1904 {
1905 dist = VectorDistance(v1, p1);
1906 if (dist > bestdist - 0.5 && dist < bestdist + 0.5)
1907 {
1908 dist1 = VectorDistance(beststart1, v1);
1909 dist2 = VectorDistance(beststart2, v1);
1910 if (dist1 > dist2)
1911 {
1912 if (dist1 > VectorDistance(beststart1, beststart2)) VectorCopy(v1, beststart2);
1913 } //end if
1914 else
1915 {
1916 if (dist2 > VectorDistance(beststart1, beststart2)) VectorCopy(v1, beststart1);
1917 } //end else
1918 dist1 = VectorDistance(bestend1, p1);
1919 dist2 = VectorDistance(bestend2, p1);
1920 if (dist1 > dist2)
1921 {
1922 if (dist1 > VectorDistance(bestend1, bestend2)) VectorCopy(p1, bestend2);
1923 } //end if
1924 else
1925 {
1926 if (dist2 > VectorDistance(bestend1, bestend2)) VectorCopy(p1, bestend1);
1927 } //end else
1928 } //end if
1929 else if (dist < bestdist)
1930 {
1931 bestdist = dist;
1932 VectorCopy(v1, beststart1);
1933 VectorCopy(v1, beststart2);
1934 VectorCopy(p1, bestend1);
1935 VectorCopy(p1, bestend2);
1936 } //end if
1937 founddist = qtrue;
1938 } //end if
1939 if (VectorBetweenVectors(p2, v3, v4))
1940 {
1941 dist = VectorDistance(v2, p2);
1942 if (dist > bestdist - 0.5 && dist < bestdist + 0.5)
1943 {
1944 dist1 = VectorDistance(beststart1, v2);
1945 dist2 = VectorDistance(beststart2, v2);
1946 if (dist1 > dist2)
1947 {
1948 if (dist1 > VectorDistance(beststart1, beststart2)) VectorCopy(v2, beststart2);
1949 } //end if
1950 else
1951 {
1952 if (dist2 > VectorDistance(beststart1, beststart2)) VectorCopy(v2, beststart1);
1953 } //end else
1954 dist1 = VectorDistance(bestend1, p2);
1955 dist2 = VectorDistance(bestend2, p2);
1956 if (dist1 > dist2)
1957 {
1958 if (dist1 > VectorDistance(bestend1, bestend2)) VectorCopy(p2, bestend2);
1959 } //end if
1960 else
1961 {
1962 if (dist2 > VectorDistance(bestend1, bestend2)) VectorCopy(p2, bestend1);
1963 } //end else
1964 } //end if
1965 else if (dist < bestdist)
1966 {
1967 bestdist = dist;
1968 VectorCopy(v2, beststart1);
1969 VectorCopy(v2, beststart2);
1970 VectorCopy(p2, bestend1);
1971 VectorCopy(p2, bestend2);
1972 } //end if
1973 founddist = qtrue;
1974 } //end else if
1975 if (VectorBetweenVectors(p3, v1, v2))
1976 {
1977 dist = VectorDistance(v3, p3);
1978 if (dist > bestdist - 0.5 && dist < bestdist + 0.5)
1979 {
1980 dist1 = VectorDistance(beststart1, p3);
1981 dist2 = VectorDistance(beststart2, p3);
1982 if (dist1 > dist2)
1983 {
1984 if (dist1 > VectorDistance(beststart1, beststart2)) VectorCopy(p3, beststart2);
1985 } //end if
1986 else
1987 {
1988 if (dist2 > VectorDistance(beststart1, beststart2)) VectorCopy(p3, beststart1);
1989 } //end else
1990 dist1 = VectorDistance(bestend1, v3);
1991 dist2 = VectorDistance(bestend2, v3);
1992 if (dist1 > dist2)
1993 {
1994 if (dist1 > VectorDistance(bestend1, bestend2)) VectorCopy(v3, bestend2);
1995 } //end if
1996 else
1997 {
1998 if (dist2 > VectorDistance(bestend1, bestend2)) VectorCopy(v3, bestend1);
1999 } //end else
2000 } //end if
2001 else if (dist < bestdist)
2002 {
2003 bestdist = dist;
2004 VectorCopy(p3, beststart1);
2005 VectorCopy(p3, beststart2);
2006 VectorCopy(v3, bestend1);
2007 VectorCopy(v3, bestend2);
2008 } //end if
2009 founddist = qtrue;
2010 } //end else if
2011 if (VectorBetweenVectors(p4, v1, v2))
2012 {
2013 dist = VectorDistance(v4, p4);
2014 if (dist > bestdist - 0.5 && dist < bestdist + 0.5)
2015 {
2016 dist1 = VectorDistance(beststart1, p4);
2017 dist2 = VectorDistance(beststart2, p4);
2018 if (dist1 > dist2)
2019 {
2020 if (dist1 > VectorDistance(beststart1, beststart2)) VectorCopy(p4, beststart2);
2021 } //end if
2022 else
2023 {
2024 if (dist2 > VectorDistance(beststart1, beststart2)) VectorCopy(p4, beststart1);
2025 } //end else
2026 dist1 = VectorDistance(bestend1, v4);
2027 dist2 = VectorDistance(bestend2, v4);
2028 if (dist1 > dist2)
2029 {
2030 if (dist1 > VectorDistance(bestend1, bestend2)) VectorCopy(v4, bestend2);
2031 } //end if
2032 else
2033 {
2034 if (dist2 > VectorDistance(bestend1, bestend2)) VectorCopy(v4, bestend1);
2035 } //end else
2036 } //end if
2037 else if (dist < bestdist)
2038 {
2039 bestdist = dist;
2040 VectorCopy(p4, beststart1);
2041 VectorCopy(p4, beststart2);
2042 VectorCopy(v4, bestend1);
2043 VectorCopy(v4, bestend2);
2044 } //end if
2045 founddist = qtrue;
2046 } //end else if
2047 //if no shortest distance was found the shortest distance
2048 //is between one of the vertexes of edge1 and one of edge2
2049 if (!founddist)
2050 {
2051 dist = VectorDistance(v1, v3);
2052 if (dist < bestdist)
2053 {
2054 bestdist = dist;
2055 VectorCopy(v1, beststart1);
2056 VectorCopy(v1, beststart2);
2057 VectorCopy(v3, bestend1);
2058 VectorCopy(v3, bestend2);
2059 } //end if
2060 dist = VectorDistance(v1, v4);
2061 if (dist < bestdist)
2062 {
2063 bestdist = dist;
2064 VectorCopy(v1, beststart1);
2065 VectorCopy(v1, beststart2);
2066 VectorCopy(v4, bestend1);
2067 VectorCopy(v4, bestend2);
2068 } //end if
2069 dist = VectorDistance(v2, v3);
2070 if (dist < bestdist)
2071 {
2072 bestdist = dist;
2073 VectorCopy(v2, beststart1);
2074 VectorCopy(v2, beststart2);
2075 VectorCopy(v3, bestend1);
2076 VectorCopy(v3, bestend2);
2077 } //end if
2078 dist = VectorDistance(v2, v4);
2079 if (dist < bestdist)
2080 {
2081 bestdist = dist;
2082 VectorCopy(v2, beststart1);
2083 VectorCopy(v2, beststart2);
2084 VectorCopy(v4, bestend1);
2085 VectorCopy(v4, bestend2);
2086 } //end if
2087 } //end if
2088 return bestdist;
2089 } //end of the function AAS_ClosestEdgePoints
2090 //===========================================================================
2091 // creates possible jump reachabilities between the areas
2092 //
2093 // The two closest points on the ground of the areas are calculated
2094 // One of the points will be on an edge of a ground face of area1 and
2095 // one on an edge of a ground face of area2.
2096 // If there is a range of closest points the point in the middle of this range
2097 // is selected.
2098 // Between these two points there must be one or more gaps.
2099 // If the gaps exist a potential jump is predicted.
2100 //
2101 // Parameter: -
2102 // Returns: -
2103 // Changes Globals: -
2104 //===========================================================================
2105 int AAS_Reachability_Jump(int area1num, int area2num)
2106 {
2107 int i, j, k, l, face1num, face2num, edge1num, edge2num, traveltype;
2108 int stopevent, areas[10], numareas;
2109 float phys_jumpvel, maxjumpdistance, maxjumpheight, height, bestdist, speed;
2110 vec_t *v1, *v2, *v3, *v4;
2111 vec3_t beststart = {0}, beststart2 = {0}, bestend = {0}, bestend2 = {0};
2112 vec3_t teststart, testend, dir, velocity, cmdmove, up = {0, 0, 1}, sidewards;
2113 aas_area_t *area1, *area2;
2114 aas_face_t *face1, *face2;
2115 aas_edge_t *edge1, *edge2;
2116 aas_plane_t *plane1, *plane2, *plane;
2117 aas_trace_t trace;
2118 aas_clientmove_t move;
2119 aas_lreachability_t *lreach;
2120
2121 if (!AAS_AreaGrounded(area1num) || !AAS_AreaGrounded(area2num)) return qfalse;
2122 //cannot jump from or to a crouch area
2123 if (AAS_AreaCrouch(area1num) || AAS_AreaCrouch(area2num)) return qfalse;
2124 //
2125 area1 = &aasworld.areas[area1num];
2126 area2 = &aasworld.areas[area2num];
2127 //
2128 phys_jumpvel = aassettings.phys_jumpvel;
2129 //maximum distance a player can jump
2130 maxjumpdistance = 2 * AAS_MaxJumpDistance(phys_jumpvel);
2131 //maximum height a player can jump with the given initial z velocity
2132 maxjumpheight = AAS_MaxJumpHeight(phys_jumpvel);
2133
2134 //if the areas are not near enough in the x-y direction
2135 for (i = 0; i < 2; i++)
2136 {
2137 if (area1->mins[i] > area2->maxs[i] + maxjumpdistance) return qfalse;
2138 if (area1->maxs[i] < area2->mins[i] - maxjumpdistance) return qfalse;
2139 } //end for
2140 //if area2 is way to high to jump up to
2141 if (area2->mins[2] > area1->maxs[2] + maxjumpheight) return qfalse;
2142 //
2143 bestdist = 999999;
2144 //
2145 for (i = 0; i < area1->numfaces; i++)
2146 {
2147 face1num = aasworld.faceindex[area1->firstface + i];
2148 face1 = &aasworld.faces[abs(face1num)];
2149 //if not a ground face
2150 if (!(face1->faceflags & FACE_GROUND)) continue;
2151 //
2152 for (j = 0; j < area2->numfaces; j++)
2153 {
2154 face2num = aasworld.faceindex[area2->firstface + j];
2155 face2 = &aasworld.faces[abs(face2num)];
2156 //if not a ground face
2157 if (!(face2->faceflags & FACE_GROUND)) continue;
2158 //
2159 for (k = 0; k < face1->numedges; k++)
2160 {
2161 edge1num = abs(aasworld.edgeindex[face1->firstedge + k]);
2162 edge1 = &aasworld.edges[edge1num];
2163 for (l = 0; l < face2->numedges; l++)
2164 {
2165 edge2num = abs(aasworld.edgeindex[face2->firstedge + l]);
2166 edge2 = &aasworld.edges[edge2num];
2167 //calculate the minimum distance between the two edges
2168 v1 = aasworld.vertexes[edge1->v[0]];
2169 v2 = aasworld.vertexes[edge1->v[1]];
2170 v3 = aasworld.vertexes[edge2->v[0]];
2171 v4 = aasworld.vertexes[edge2->v[1]];
2172 //get the ground planes
2173 plane1 = &aasworld.planes[face1->planenum];
2174 plane2 = &aasworld.planes[face2->planenum];
2175 //
2176 bestdist = AAS_ClosestEdgePoints(v1, v2, v3, v4, plane1, plane2,
2177 beststart, bestend,
2178 beststart2, bestend2, bestdist);
2179 } //end for
2180 } //end for
2181 } //end for
2182 } //end for
2183 VectorMiddle(beststart, beststart2, beststart);
2184 VectorMiddle(bestend, bestend2, bestend);
2185 if (bestdist > 4 && bestdist < maxjumpdistance)
2186 {
2187 // Log_Write("shortest distance between %d and %d is %f\r\n", area1num, area2num, bestdist);
2188 // if very close and almost no height difference then the bot can walk
2189 if (bestdist <= 48 && fabs(beststart[2] - bestend[2]) < 8)
2190 {
2191 speed = 400;
2192 traveltype = TRAVEL_WALKOFFLEDGE;
2193 } //end if
2194 else if (AAS_HorizontalVelocityForJump(0, beststart, bestend, &speed))
2195 {
2196 //FIXME: why multiply with 1.2???
2197 speed *= 1.2f;
2198 traveltype = TRAVEL_WALKOFFLEDGE;
2199 } //end else if
2200 else
2201 {
2202 //get the horizontal speed for the jump, if it isn't possible to calculate this
2203 //speed (the jump is not possible) then there's no jump reachability created
2204 if (!AAS_HorizontalVelocityForJump(phys_jumpvel, beststart, bestend, &speed))
2205 return qfalse;
2206 speed *= 1.05f;
2207 traveltype = TRAVEL_JUMP;
2208 //
2209 //NOTE: test if the horizontal distance isn't too small
2210 VectorSubtract(bestend, beststart, dir);
2211 dir[2] = 0;
2212 if (VectorLength(dir) < 10)
2213 return qfalse;
2214 } //end if
2215 //
2216 VectorSubtract(bestend, beststart, dir);
2217 VectorNormalize(dir);
2218 VectorMA(beststart, 1, dir, teststart);
2219 //
2220 VectorCopy(teststart, testend);
2221 testend[2] -= 100;
2222 trace = AAS_TraceClientBBox(teststart, testend, PRESENCE_NORMAL, -1);
2223 //
2224 if (trace.startsolid)
2225 return qfalse;
2226 if (trace.fraction < 1)
2227 {
2228 plane = &aasworld.planes[trace.planenum];
2229 // if the bot can stand on the surface
2230 if (DotProduct(plane->normal, up) >= 0.7)
2231 {
2232 // if no lava or slime below
2233 if (!(AAS_PointContents(trace.endpos) & (CONTENTS_LAVA|CONTENTS_SLIME)))
2234 {
2235 if (teststart[2] - trace.endpos[2] <= aassettings.phys_maxbarrier)
2236 return qfalse;
2237 } //end if
2238 } //end if
2239 } //end if
2240 //
2241 VectorMA(bestend, -1, dir, teststart);
2242 //
2243 VectorCopy(teststart, testend);
2244 testend[2] -= 100;
2245 trace = AAS_TraceClientBBox(teststart, testend, PRESENCE_NORMAL, -1);
2246 //
2247 if (trace.startsolid)
2248 return qfalse;
2249 if (trace.fraction < 1)
2250 {
2251 plane = &aasworld.planes[trace.planenum];
2252 // if the bot can stand on the surface
2253 if (DotProduct(plane->normal, up) >= 0.7)
2254 {
2255 // if no lava or slime below
2256 if (!(AAS_PointContents(trace.endpos) & (CONTENTS_LAVA|CONTENTS_SLIME)))
2257 {
2258 if (teststart[2] - trace.endpos[2] <= aassettings.phys_maxbarrier)
2259 return qfalse;
2260 } //end if
2261 } //end if
2262 } //end if
2263 //
2264 // get command movement
2265 VectorClear(cmdmove);
2266 if ((traveltype & TRAVELTYPE_MASK) == TRAVEL_JUMP)
2267 cmdmove[2] = aassettings.phys_jumpvel;
2268 else
2269 cmdmove[2] = 0;
2270 //
2271 VectorSubtract(bestend, beststart, dir);
2272 dir[2] = 0;
2273 VectorNormalize(dir);
2274 CrossProduct(dir, up, sidewards);
2275 //
2276 stopevent = SE_HITGROUND|SE_ENTERWATER|SE_ENTERSLIME|SE_ENTERLAVA|SE_HITGROUNDDAMAGE;
2277 if (!AAS_AreaClusterPortal(area1num) && !AAS_AreaClusterPortal(area2num))
2278 stopevent |= SE_TOUCHCLUSTERPORTAL;
2279 //
2280 for (i = 0; i < 3; i++)
2281 {
2282 //
2283 if (i == 1)
2284 VectorAdd(testend, sidewards, testend);
2285 else if (i == 2)
2286 VectorSubtract(bestend, sidewards, testend);
2287 else
2288 VectorCopy(bestend, testend);
2289 VectorSubtract(testend, beststart, dir);
2290 dir[2] = 0;
2291 VectorNormalize(dir);
2292 VectorScale(dir, speed, velocity);
2293 //
2294 AAS_PredictClientMovement(&move, -1, beststart, PRESENCE_NORMAL, qtrue,
2295 velocity, cmdmove, 3, 30, 0.1f,
2296 stopevent, 0, qfalse);
2297 // if prediction time wasn't enough to fully predict the movement
2298 if (move.frames >= 30)
2299 return qfalse;
2300 // don't enter slime or lava and don't fall from too high
2301 if (move.stopevent & (SE_ENTERSLIME|SE_ENTERLAVA))
2302 return qfalse;
2303 // never jump or fall through a cluster portal
2304 if (move.stopevent & SE_TOUCHCLUSTERPORTAL)
2305 return qfalse;
2306 //the end position should be in area2, also test a little bit back
2307 //because the predicted jump could have rushed through the area
2308 VectorMA(move.endpos, -64, dir, teststart);
2309 teststart[2] += 1;
2310 numareas = AAS_TraceAreas(move.endpos, teststart, areas, NULL, ARRAY_LEN(areas));
2311 for (j = 0; j < numareas; j++)
2312 {
2313 if (areas[j] == area2num)
2314 break;
2315 } //end for
2316 if (j < numareas)
2317 break;
2318 }
2319 if (i >= 3)
2320 return qfalse;
2321 //
2322 #ifdef REACH_DEBUG
2323 //create the reachability
2324 Log_Write("jump reachability between %d and %d\r\n", area1num, area2num);
2325 #endif //REACH_DEBUG
2326 //create a new reachability link
2327 lreach = AAS_AllocReachability();
2328 if (!lreach) return qfalse;
2329 lreach->areanum = area2num;
2330 lreach->facenum = 0;
2331 lreach->edgenum = 0;
2332 VectorCopy(beststart, lreach->start);
2333 VectorCopy(bestend, lreach->end);
2334 lreach->traveltype = traveltype;
2335
2336 VectorSubtract(bestend, beststart, dir);
2337 height = dir[2];
2338 dir[2] = 0;
2339 if ((traveltype & TRAVELTYPE_MASK) == TRAVEL_WALKOFFLEDGE && height > VectorLength(dir))
2340 {
2341 lreach->traveltime = aassettings.rs_startwalkoffledge + height * 50 / aassettings.phys_gravity;
2342 }
2343 else
2344 {
2345 lreach->traveltime = aassettings.rs_startjump + VectorDistance(bestend, beststart) * 240 / aassettings.phys_maxwalkvelocity;
2346 } //end if
2347 //
2348 if (!AAS_AreaJumpPad(area2num))
2349 {
2350 if (AAS_FallDelta(beststart[2] - bestend[2]) > aassettings.phys_falldelta5)
2351 {
2352 lreach->traveltime += aassettings.rs_falldamage5;
2353 } //end if
2354 else if (AAS_FallDelta(beststart[2] - bestend[2]) > aassettings.phys_falldelta10)
2355 {
2356 lreach->traveltime += aassettings.rs_falldamage10;
2357 } //end if
2358 } //end if
2359 lreach->next = areareachability[area1num];
2360 areareachability[area1num] = lreach;
2361 //
2362 if ((traveltype & TRAVELTYPE_MASK) == TRAVEL_JUMP)
2363 reach_jump++;
2364 else
2365 reach_walkoffledge++;
2366 } //end if
2367 return qfalse;
2368 } //end of the function AAS_Reachability_Jump
2369 //===========================================================================
2370 // create a possible ladder reachability from area1 to area2
2371 //
2372 // Parameter: -
2373 // Returns: -
2374 // Changes Globals: -
2375 //===========================================================================
2376 int AAS_Reachability_Ladder(int area1num, int area2num)
2377 {
2378 int i, j, k, l, edge1num, edge2num, sharededgenum = 0, lowestedgenum = 0;
2379 int face1num, face2num, ladderface1num = 0, ladderface2num = 0;
2380 int ladderface1vertical, ladderface2vertical, firstv;
2381 float face1area, face2area, bestface1area = -9999, bestface2area = -9999;
2382 float phys_jumpvel, maxjumpheight;
2383 vec3_t area1point, area2point, v1, v2, up = {0, 0, 1};
2384 vec3_t mid, lowestpoint = {0, 0}, start, end, sharededgevec, dir;
2385 aas_area_t *area1, *area2;
2386 aas_face_t *face1, *face2, *ladderface1 = NULL, *ladderface2 = NULL;
2387 aas_plane_t *plane1, *plane2;
2388 aas_edge_t *sharededge, *edge1;
2389 aas_lreachability_t *lreach;
2390 aas_trace_t trace;
2391
2392 if (!AAS_AreaLadder(area1num) || !AAS_AreaLadder(area2num)) return qfalse;
2393 //
2394 phys_jumpvel = aassettings.phys_jumpvel;
2395 //maximum height a player can jump with the given initial z velocity
2396 maxjumpheight = AAS_MaxJumpHeight(phys_jumpvel);
2397
2398 area1 = &aasworld.areas[area1num];
2399 area2 = &aasworld.areas[area2num];
2400
2401 for (i = 0; i < area1->numfaces; i++)
2402 {
2403 face1num = aasworld.faceindex[area1->firstface + i];
2404 face1 = &aasworld.faces[abs(face1num)];
2405 //if not a ladder face
2406 if (!(face1->faceflags & FACE_LADDER)) continue;
2407 //
2408 for (j = 0; j < area2->numfaces; j++)
2409 {
2410 face2num = aasworld.faceindex[area2->firstface + j];
2411 face2 = &aasworld.faces[abs(face2num)];
2412 //if not a ladder face
2413 if (!(face2->faceflags & FACE_LADDER)) continue;
2414 //check if the faces share an edge
2415 for (k = 0; k < face1->numedges; k++)
2416 {
2417 edge1num = aasworld.edgeindex[face1->firstedge + k];
2418 for (l = 0; l < face2->numedges; l++)
2419 {
2420 edge2num = aasworld.edgeindex[face2->firstedge + l];
2421 if (abs(edge1num) == abs(edge2num))
2422 {
2423 //get the face with the largest area
2424 face1area = AAS_FaceArea(face1);
2425 face2area = AAS_FaceArea(face2);
2426 if (face1area > bestface1area && face2area > bestface2area)
2427 {
2428 bestface1area = face1area;
2429 bestface2area = face2area;
2430 ladderface1 = face1;
2431 ladderface2 = face2;
2432 ladderface1num = face1num;
2433 ladderface2num = face2num;
2434 sharededgenum = edge1num;
2435 } //end if
2436 break;
2437 } //end if
2438 } //end for
2439 if (l != face2->numedges) break;
2440 } //end for
2441 } //end for
2442 } //end for
2443 //
2444 if (ladderface1 && ladderface2)
2445 {
2446 //get the middle of the shared edge
2447 sharededge = &aasworld.edges[abs(sharededgenum)];
2448 firstv = sharededgenum < 0;
2449 //
2450 VectorCopy(aasworld.vertexes[sharededge->v[firstv]], v1);
2451 VectorCopy(aasworld.vertexes[sharededge->v[!firstv]], v2);
2452 VectorAdd(v1, v2, area1point);
2453 VectorScale(area1point, 0.5, area1point);
2454 VectorCopy(area1point, area2point);
2455 //
2456 //if the face plane in area 1 is pretty much vertical
2457 plane1 = &aasworld.planes[ladderface1->planenum ^ (ladderface1num < 0)];
2458 plane2 = &aasworld.planes[ladderface2->planenum ^ (ladderface2num < 0)];
2459 //
2460 //get the points really into the areas
2461 VectorSubtract(v2, v1, sharededgevec);
2462 CrossProduct(plane1->normal, sharededgevec, dir);
2463 VectorNormalize(dir);
2464 //NOTE: 32 because that's larger than 16 (bot bbox x,y)
2465 VectorMA(area1point, -32, dir, area1point);
2466 VectorMA(area2point, 32, dir, area2point);
2467 //
2468 ladderface1vertical = fabsf(DotProduct(plane1->normal, up)) < 0.1;
2469 ladderface2vertical = fabsf(DotProduct(plane2->normal, up)) < 0.1;
2470 //there's only reachability between vertical ladder faces
2471 if (!ladderface1vertical && !ladderface2vertical) return qfalse;
2472 //if both vertical ladder faces
2473 if (ladderface1vertical && ladderface2vertical
2474 //and the ladder faces do not make a sharp corner
2475 && DotProduct(plane1->normal, plane2->normal) > 0.7
2476 //and the shared edge is not too vertical
2477 && fabsf(DotProduct(sharededgevec, up)) < 0.7)
2478 {
2479 //create a new reachability link
2480 lreach = AAS_AllocReachability();
2481 if (!lreach) return qfalse;
2482 lreach->areanum = area2num;
2483 lreach->facenum = ladderface1num;
2484 lreach->edgenum = abs(sharededgenum);
2485 VectorCopy(area1point, lreach->start);
2486 //VectorCopy(area2point, lreach->end);
2487 VectorMA(area2point, -3, plane1->normal, lreach->end);
2488 lreach->traveltype = TRAVEL_LADDER;
2489 lreach->traveltime = 10;
2490 lreach->next = areareachability[area1num];
2491 areareachability[area1num] = lreach;
2492 //
2493 reach_ladder++;
2494 //create a new reachability link
2495 lreach = AAS_AllocReachability();
2496 if (!lreach) return qfalse;
2497 lreach->areanum = area1num;
2498 lreach->facenum = ladderface2num;
2499 lreach->edgenum = abs(sharededgenum);
2500 VectorCopy(area2point, lreach->start);
2501 //VectorCopy(area1point, lreach->end);
2502 VectorMA(area1point, -3, plane1->normal, lreach->end);
2503 lreach->traveltype = TRAVEL_LADDER;
2504 lreach->traveltime = 10;
2505 lreach->next = areareachability[area2num];
2506 areareachability[area2num] = lreach;
2507 //
2508 reach_ladder++;
2509 //
2510 return qtrue;
2511 } //end if
2512 //if the second ladder face is also a ground face
2513 //create ladder end (just ladder) reachability and
2514 //walk off a ladder (ledge) reachability
2515 if (ladderface1vertical && (ladderface2->faceflags & FACE_GROUND))
2516 {
2517 //create a new reachability link
2518 lreach = AAS_AllocReachability();
2519 if (!lreach) return qfalse;
2520 lreach->areanum = area2num;
2521 lreach->facenum = ladderface1num;
2522 lreach->edgenum = abs(sharededgenum);
2523 VectorCopy(area1point, lreach->start);
2524 VectorCopy(area2point, lreach->end);
2525 lreach->end[2] += 16;
2526 VectorMA(lreach->end, -15, plane1->normal, lreach->end);
2527 lreach->traveltype = TRAVEL_LADDER;
2528 lreach->traveltime = 10;
2529 lreach->next = areareachability[area1num];
2530 areareachability[area1num] = lreach;
2531 //
2532 reach_ladder++;
2533 //create a new reachability link
2534 lreach = AAS_AllocReachability();
2535 if (!lreach) return qfalse;
2536 lreach->areanum = area1num;
2537 lreach->facenum = ladderface2num;
2538 lreach->edgenum = abs(sharededgenum);
2539 VectorCopy(area2point, lreach->start);
2540 VectorCopy(area1point, lreach->end);
2541 lreach->traveltype = TRAVEL_WALKOFFLEDGE;
2542 lreach->traveltime = 10;
2543 lreach->next = areareachability[area2num];
2544 areareachability[area2num] = lreach;
2545 //
2546 reach_walkoffledge++;
2547 //
2548 return qtrue;
2549 } //end if
2550 //
2551 if (ladderface1vertical)
2552 {
2553 //find lowest edge of the ladder face
2554 lowestpoint[2] = 99999;
2555 for (i = 0; i < ladderface1->numedges; i++)
2556 {
2557 edge1num = abs(aasworld.edgeindex[ladderface1->firstedge + i]);
2558 edge1 = &aasworld.edges[edge1num];
2559 //
2560 VectorCopy(aasworld.vertexes[edge1->v[0]], v1);
2561 VectorCopy(aasworld.vertexes[edge1->v[1]], v2);
2562 //
2563 VectorAdd(v1, v2, mid);
2564 VectorScale(mid, 0.5, mid);
2565 //
2566 if (mid[2] < lowestpoint[2])
2567 {
2568 VectorCopy(mid, lowestpoint);
2569 lowestedgenum = edge1num;
2570 } //end if
2571 } //end for
2572 //
2573 plane1 = &aasworld.planes[ladderface1->planenum];
2574 //trace down in the middle of this edge
2575 VectorMA(lowestpoint, 5, plane1->normal, start);
2576 VectorCopy(start, end);
2577 start[2] += 5;
2578 end[2] -= 100;
2579 //trace without entity collision
2580 trace = AAS_TraceClientBBox(start, end, PRESENCE_NORMAL, -1);
2581 //
2582 //
2583 #ifdef REACH_DEBUG
2584 if (trace.startsolid)
2585 {
2586 Log_Write("trace from area %d started in solid\r\n", area1num);
2587 } //end if
2588 #endif //REACH_DEBUG
2589 //
2590 trace.endpos[2] += 1;
2591 area2num = AAS_PointAreaNum(trace.endpos);
2592 //
2593 area2 = &aasworld.areas[area2num];
2594 for (i = 0; i < area2->numfaces; i++)
2595 {
2596 face2num = aasworld.faceindex[area2->firstface + i];
2597 face2 = &aasworld.faces[abs(face2num)];
2598 //
2599 if (face2->faceflags & FACE_LADDER)
2600 {
2601 plane2 = &aasworld.planes[face2->planenum];
2602 if (fabsf(DotProduct(plane2->normal, up)) < 0.1) break;
2603 } //end if
2604 } //end for
2605 //if from another area without vertical ladder faces
2606 if (i >= area2->numfaces && area2num != area1num &&
2607 //the reachabilities shouldn't exist already
2608 !AAS_ReachabilityExists(area1num, area2num) &&
2609 !AAS_ReachabilityExists(area2num, area1num))
2610 {
2611 //if the height is jumpable
2612 if (start[2] - trace.endpos[2] < maxjumpheight)
2613 {
2614 //create a new reachability link
2615 lreach = AAS_AllocReachability();
2616 if (!lreach) return qfalse;
2617 lreach->areanum = area2num;
2618 lreach->facenum = ladderface1num;
2619 lreach->edgenum = lowestedgenum;
2620 VectorCopy(lowestpoint, lreach->start);
2621 VectorCopy(trace.endpos, lreach->end);
2622 lreach->traveltype = TRAVEL_LADDER;
2623 lreach->traveltime = 10;
2624 lreach->next = areareachability[area1num];
2625 areareachability[area1num] = lreach;
2626 //
2627 reach_ladder++;
2628 //create a new reachability link
2629 lreach = AAS_AllocReachability();
2630 if (!lreach) return qfalse;
2631 lreach->areanum = area1num;
2632 lreach->facenum = ladderface1num;
2633 lreach->edgenum = lowestedgenum;
2634 VectorCopy(trace.endpos, lreach->start);
2635 //get the end point a little bit into the ladder
2636 VectorMA(lowestpoint, -5, plane1->normal, lreach->end);
2637 //get the end point a little higher
2638 lreach->end[2] += 10;
2639 lreach->traveltype = TRAVEL_JUMP;
2640 lreach->traveltime = 10;
2641 lreach->next = areareachability[area2num];
2642 areareachability[area2num] = lreach;
2643 //
2644 reach_jump++;
2645 //
2646 return qtrue;
2647 #ifdef REACH_DEBUG
2648 Log_Write("jump up to ladder reach between %d and %d\r\n", area2num, area1num);
2649 #endif //REACH_DEBUG
2650 } //end if
2651 #ifdef REACH_DEBUG
2652 else Log_Write("jump too high between area %d and %d\r\n", area2num, area1num);
2653 #endif //REACH_DEBUG
2654 } //end if
2655 /*//if slime or lava below the ladder
2656 //try jump reachability from far towards the ladder
2657 if (aasworld.areasettings[area2num].contents & (AREACONTENTS_SLIME
2658 | AREACONTENTS_LAVA))
2659 {
2660 for (i = 20; i <= 120; i += 20)
2661 {
2662 //trace down in the middle of this edge
2663 VectorMA(lowestpoint, i, plane1->normal, start);
2664 VectorCopy(start, end);
2665 start[2] += 5;
2666 end[2] -= 100;
2667 //trace without entity collision
2668 trace = AAS_TraceClientBBox(start, end, PRESENCE_NORMAL, -1);
2669 //
2670 if (trace.startsolid) break;
2671 trace.endpos[2] += 1;
2672 area2num = AAS_PointAreaNum(trace.endpos);
2673 if (area2num == area1num) continue;
2674 //
2675 if (start[2] - trace.endpos[2] > maxjumpheight) continue;
2676 if (aasworld.areasettings[area2num].contents & (AREACONTENTS_SLIME
2677 | AREACONTENTS_LAVA)) continue;
2678 //
2679 //create a new reachability link
2680 lreach = AAS_AllocReachability();
2681 if (!lreach) return qfalse;
2682 lreach->areanum = area1num;
2683 lreach->facenum = ladderface1num;
2684 lreach->edgenum = lowestedgenum;
2685 VectorCopy(trace.endpos, lreach->start);
2686 VectorCopy(lowestpoint, lreach->end);
2687 lreach->end[2] += 5;
2688 lreach->traveltype = TRAVEL_JUMP;
2689 lreach->traveltime = 10;
2690 lreach->next = areareachability[area2num];
2691 areareachability[area2num] = lreach;
2692 //
2693 reach_jump++;
2694 //
2695 Log_Write("jump far to ladder reach between %d and %d\r\n", area2num, area1num);
2696 //
2697 break;
2698 } //end for
2699 } //end if*/
2700 } //end if
2701 } //end if
2702 return qfalse;
2703 } //end of the function AAS_Reachability_Ladder
2704 //===========================================================================
2705 //
2706 // Parameter: -
2707 // Returns: -
2708 // Changes Globals: -
2709 //===========================================================================
2710 int AAS_TravelFlagsForTeam(int ent)
2711 {
2712 int notteam;
2713
2714 if (!AAS_IntForBSPEpairKey(ent, "bot_notteam", &notteam))
2715 return 0;
2716 if (notteam == 1)
2717 return TRAVELFLAG_NOTTEAM1;
2718 if (notteam == 2)
2719 return TRAVELFLAG_NOTTEAM2;
2720 return 0;
2721 } //end of the function AAS_TravelFlagsForTeam
2722 //===========================================================================
2723 // create possible teleporter reachabilities
2724 // this is very game dependent.... :(
2725 //
2726 // classname = trigger_multiple or trigger_teleport
2727 // target = "t1"
2728 //
2729 // classname = target_teleporter
2730 // targetname = "t1"
2731 // target = "t2"
2732 //
2733 // classname = misc_teleporter_dest
2734 // targetname = "t2"
2735 //
2736 // Parameter: -
2737 // Returns: -
2738 // Changes Globals: -
2739 //===========================================================================
2740 void AAS_Reachability_Teleport(void)
2741 {
2742 int area1num, area2num;
2743 char target[MAX_EPAIRKEY], targetname[MAX_EPAIRKEY];
2744 char classname[MAX_EPAIRKEY], model[MAX_EPAIRKEY];
2745 int ent, dest;
2746 float angle;
2747 vec3_t origin, destorigin, mins, maxs, end, angles;
2748 vec3_t mid, velocity, cmdmove;
2749 aas_lreachability_t *lreach;
2750 aas_clientmove_t move;
2751 aas_trace_t trace;
2752 aas_link_t *areas, *link;
2753
2754 for (ent = AAS_NextBSPEntity(0); ent; ent = AAS_NextBSPEntity(ent))
2755 {
2756 if (!AAS_ValueForBSPEpairKey(ent, "classname", classname, MAX_EPAIRKEY)) continue;
2757 if (!strcmp(classname, "trigger_multiple"))
2758 {
2759 AAS_ValueForBSPEpairKey(ent, "model", model, MAX_EPAIRKEY);
2760 //#ifdef REACH_DEBUG
2761 botimport.Print(PRT_MESSAGE, "trigger_multiple model = \"%s\"\n", model);
2762 //#endif REACH_DEBUG
2763 VectorClear(angles);
2764 AAS_BSPModelMinsMaxsOrigin(atoi(model+1), angles, mins, maxs, origin);
2765 //
2766 if (!AAS_ValueForBSPEpairKey(ent, "target", target, MAX_EPAIRKEY))
2767 {
2768 botimport.Print(PRT_ERROR, "trigger_multiple at %1.0f %1.0f %1.0f without target\n",
2769 origin[0], origin[1], origin[2]);
2770 continue;
2771 } //end if
2772 for (dest = AAS_NextBSPEntity(0); dest; dest = AAS_NextBSPEntity(dest))
2773 {
2774 if (!AAS_ValueForBSPEpairKey(dest, "classname", classname, MAX_EPAIRKEY)) continue;
2775 if (!strcmp(classname, "target_teleporter"))
2776 {
2777 if (!AAS_ValueForBSPEpairKey(dest, "targetname", targetname, MAX_EPAIRKEY)) continue;
2778 if (!strcmp(targetname, target))
2779 {
2780 break;
2781 } //end if
2782 } //end if
2783 } //end for
2784 if (!dest)
2785 {
2786 continue;
2787 } //end if
2788 if (!AAS_ValueForBSPEpairKey(dest, "target", target, MAX_EPAIRKEY))
2789 {
2790 botimport.Print(PRT_ERROR, "target_teleporter without target\n");
2791 continue;
2792 } //end if
2793 } //end else
2794 else if (!strcmp(classname, "trigger_teleport"))
2795 {
2796 AAS_ValueForBSPEpairKey(ent, "model", model, MAX_EPAIRKEY);
2797 //#ifdef REACH_DEBUG
2798 botimport.Print(PRT_MESSAGE, "trigger_teleport model = \"%s\"\n", model);
2799 //#endif REACH_DEBUG
2800 VectorClear(angles);
2801 AAS_BSPModelMinsMaxsOrigin(atoi(model+1), angles, mins, maxs, origin);
2802 //
2803 if (!AAS_ValueForBSPEpairKey(ent, "target", target, MAX_EPAIRKEY))
2804 {
2805 botimport.Print(PRT_ERROR, "trigger_teleport at %1.0f %1.0f %1.0f without target\n",
2806 origin[0], origin[1], origin[2]);
2807 continue;
2808 } //end if
2809 } //end if
2810 else
2811 {
2812 continue;
2813 } //end else
2814 //
2815 for (dest = AAS_NextBSPEntity(0); dest; dest = AAS_NextBSPEntity(dest))
2816 {
2817 //classname should be misc_teleporter_dest
2818 //but I've also seen target_position and actually any
2819 //entity could be used... burp
2820 if (AAS_ValueForBSPEpairKey(dest, "targetname", targetname, MAX_EPAIRKEY))
2821 {
2822 if (!strcmp(targetname, target))
2823 {
2824 break;
2825 } //end if
2826 } //end if
2827 } //end for
2828 if (!dest)
2829 {
2830 botimport.Print(PRT_ERROR, "teleporter without misc_teleporter_dest (%s)\n", target);
2831 continue;
2832 } //end if
2833 if (!AAS_VectorForBSPEpairKey(dest, "origin", destorigin))
2834 {
2835 botimport.Print(PRT_ERROR, "teleporter destination (%s) without origin\n", target);
2836 continue;
2837 } //end if
2838 //
2839 area2num = AAS_PointAreaNum(destorigin);
2840 //if not teleported into a teleporter or into a jumppad
2841 if (!AAS_AreaTeleporter(area2num) && !AAS_AreaJumpPad(area2num))
2842 {
2843 VectorCopy(destorigin, end);
2844 end[2] -= 64;
2845 trace = AAS_TraceClientBBox(destorigin, end, PRESENCE_CROUCH, -1);
2846 if (trace.startsolid)
2847 {
2848 botimport.Print(PRT_ERROR, "teleporter destination (%s) in solid\n", target);
2849 continue;
2850 } //end if
2851 /*
2852 area2num = AAS_PointAreaNum(trace.endpos);
2853 //
2854 if (!AAS_AreaTeleporter(area2num) &&
2855 !AAS_AreaJumpPad(area2num) &&
2856 !AAS_AreaGrounded(area2num))
2857 {
2858 VectorCopy(trace.endpos, destorigin);
2859 }
2860 else*/
2861 {
2862 //predict where you'll end up
2863 AAS_FloatForBSPEpairKey(dest, "angle", &angle);
2864 if (angle)
2865 {
2866 VectorSet(angles, 0, angle, 0);
2867 AngleVectors(angles, velocity, NULL, NULL);
2868 VectorScale(velocity, 400, velocity);
2869 } //end if
2870 else
2871 {
2872 VectorClear(velocity);
2873 } //end else
2874 VectorClear(cmdmove);
2875 AAS_PredictClientMovement(&move, -1, destorigin, PRESENCE_NORMAL, qfalse,
2876 velocity, cmdmove, 0, 30, 0.1f,
2877 SE_HITGROUND|SE_ENTERWATER|SE_ENTERSLIME|
2878 SE_ENTERLAVA|SE_HITGROUNDDAMAGE|SE_TOUCHJUMPPAD|SE_TOUCHTELEPORTER, 0, qfalse); //qtrue);
2879 area2num = AAS_PointAreaNum(move.endpos);
2880 if (move.stopevent & (SE_ENTERSLIME|SE_ENTERLAVA))
2881 {
2882 botimport.Print(PRT_WARNING, "teleported into slime or lava at dest %s\n", target);
2883 } //end if
2884 VectorCopy(move.endpos, destorigin);
2885 } //end else
2886 } //end if
2887 //
2888 //botimport.Print(PRT_MESSAGE, "teleporter brush origin at %f %f %f\n", origin[0], origin[1], origin[2]);
2889 //botimport.Print(PRT_MESSAGE, "teleporter brush mins = %f %f %f\n", mins[0], mins[1], mins[2]);
2890 //botimport.Print(PRT_MESSAGE, "teleporter brush maxs = %f %f %f\n", maxs[0], maxs[1], maxs[2]);
2891 VectorAdd(origin, mins, mins);
2892 VectorAdd(origin, maxs, maxs);
2893 //
2894 VectorAdd(mins, maxs, mid);
2895 VectorScale(mid, 0.5, mid);
2896 //link an invalid (-1) entity
2897 areas = AAS_LinkEntityClientBBox(mins, maxs, -1, PRESENCE_CROUCH);
2898 if (!areas) botimport.Print(PRT_MESSAGE, "trigger_multiple not in any area\n");
2899 //
2900 for (link = areas; link; link = link->next_area)
2901 {
2902 //if (!AAS_AreaGrounded(link->areanum)) continue;
2903 if (!AAS_AreaTeleporter(link->areanum)) continue;
2904 //
2905 area1num = link->areanum;
2906 //create a new reachability link
2907 lreach = AAS_AllocReachability();
2908 if (!lreach) break;
2909 lreach->areanum = area2num;
2910 lreach->facenum = 0;
2911 lreach->edgenum = 0;
2912 VectorCopy(mid, lreach->start);
2913 VectorCopy(destorigin, lreach->end);
2914 lreach->traveltype = TRAVEL_TELEPORT;
2915 lreach->traveltype |= AAS_TravelFlagsForTeam(ent);
2916 lreach->traveltime = aassettings.rs_teleport;
2917 lreach->next = areareachability[area1num];
2918 areareachability[area1num] = lreach;
2919 //
2920 reach_teleport++;
2921 } //end for
2922 //unlink the invalid entity
2923 AAS_UnlinkFromAreas(areas);
2924 } //end for
2925 } //end of the function AAS_Reachability_Teleport
2926 //===========================================================================
2927 // create possible elevator (func_plat) reachabilities
2928 // this is very game dependent.... :(
2929 //
2930 // Parameter: -
2931 // Returns: -
2932 // Changes Globals: -
2933 //===========================================================================
2934 void AAS_Reachability_Elevator(void)
2935 {
2936 int area1num, area2num, modelnum, i, j, k, l, n, p;
2937 float lip, height, speed;
2938 char model[MAX_EPAIRKEY], classname[MAX_EPAIRKEY];
2939 int ent;
2940 vec3_t mins, maxs, origin, angles = {0, 0, 0};
2941 vec3_t pos1, pos2, mids, platbottom, plattop;
2942 vec3_t bottomorg, toporg, start, end, dir;
2943 vec_t xvals[8], yvals[8], xvals_top[8], yvals_top[8];
2944 aas_lreachability_t *lreach;
2945 aas_trace_t trace;
2946
2947 #ifdef REACH_DEBUG
2948 Log_Write("AAS_Reachability_Elevator\r\n");
2949 #endif //REACH_DEBUG
2950 for (ent = AAS_NextBSPEntity(0); ent; ent = AAS_NextBSPEntity(ent))
2951 {
2952 if (!AAS_ValueForBSPEpairKey(ent, "classname", classname, MAX_EPAIRKEY)) continue;
2953 if (!strcmp(classname, "func_plat"))
2954 {
2955 #ifdef REACH_DEBUG
2956 Log_Write("found func plat\r\n");
2957 #endif //REACH_DEBUG
2958 if (!AAS_ValueForBSPEpairKey(ent, "model", model, MAX_EPAIRKEY))
2959 {
2960 botimport.Print(PRT_ERROR, "func_plat without model\n");
2961 continue;
2962 } //end if
2963 //get the model number, and skip the leading *
2964 modelnum = atoi(model+1);
2965 if (modelnum <= 0)
2966 {
2967 botimport.Print(PRT_ERROR, "func_plat with invalid model number\n");
2968 continue;
2969 } //end if
2970 //get the mins, maxs and origin of the model
2971 //NOTE: the origin is usually (0,0,0) and the mins and maxs
2972 // are the absolute mins and maxs
2973 AAS_BSPModelMinsMaxsOrigin(modelnum, angles, mins, maxs, origin);
2974 //
2975 AAS_VectorForBSPEpairKey(ent, "origin", origin);
2976 //pos1 is the top position, pos2 is the bottom
2977 VectorCopy(origin, pos1);
2978 VectorCopy(origin, pos2);
2979 //get the lip of the plat
2980 AAS_FloatForBSPEpairKey(ent, "lip", &lip);
2981 if (!lip) lip = 8;
2982 //get the movement height of the plat
2983 AAS_FloatForBSPEpairKey(ent, "height", &height);
2984 if (!height) height = (maxs[2] - mins[2]) - lip;
2985 //get the speed of the plat
2986 AAS_FloatForBSPEpairKey(ent, "speed", &speed);
2987 if (!speed) speed = 200;
2988 //get bottom position below pos1
2989 pos2[2] -= height;
2990 //
2991 //get a point just above the plat in the bottom position
2992 VectorAdd(mins, maxs, mids);
2993 VectorMA(pos2, 0.5, mids, platbottom);
2994 platbottom[2] = maxs[2] - (pos1[2] - pos2[2]) + 2;
2995 //get a point just above the plat in the top position
2996 VectorAdd(mins, maxs, mids);
2997 VectorMA(pos2, 0.5, mids, plattop);
2998 plattop[2] = maxs[2] + 2;
2999 //
3000 /*if (!area1num)
3001 {
3002 Log_Write("no grounded area near plat bottom\r\n");
3003 continue;
3004 } //end if*/
3005 //get the mins and maxs a little larger
3006 for (i = 0; i < 3; i++)
3007 {
3008 mins[i] -= 1;
3009 maxs[i] += 1;
3010 } //end for
3011 //
3012 //botimport.Print(PRT_MESSAGE, "platbottom[2] = %1.1f plattop[2] = %1.1f\n", platbottom[2], plattop[2]);
3013 //
3014 VectorAdd(mins, maxs, mids);
3015 VectorScale(mids, 0.5, mids);
3016 //
3017 xvals[0] = mins[0]; xvals[1] = mids[0]; xvals[2] = maxs[0]; xvals[3] = mids[0];
3018 yvals[0] = mids[1]; yvals[1] = maxs[1]; yvals[2] = mids[1]; yvals[3] = mins[1];
3019 //
3020 xvals[4] = mins[0]; xvals[5] = maxs[0]; xvals[6] = maxs[0]; xvals[7] = mins[0];
3021 yvals[4] = maxs[1]; yvals[5] = maxs[1]; yvals[6] = mins[1]; yvals[7] = mins[1];
3022 //find adjacent areas around the bottom of the plat
3023 for (i = 0; i < 9; i++)
3024 {
3025 if (i < 8) //check at the sides of the plat
3026 {
3027 bottomorg[0] = origin[0] + xvals[i];
3028 bottomorg[1] = origin[1] + yvals[i];
3029 bottomorg[2] = platbottom[2] + 16;
3030 //get a grounded or swim area near the plat in the bottom position
3031 area1num = AAS_PointAreaNum(bottomorg);
3032 for (k = 0; k < 16; k++)
3033 {
3034 if (area1num)
3035 {
3036 if (AAS_AreaGrounded(area1num) || AAS_AreaSwim(area1num)) break;
3037 } //end if
3038 bottomorg[2] += 4;
3039 area1num = AAS_PointAreaNum(bottomorg);
3040 } //end if
3041 //if in solid
3042 if (k >= 16)
3043 {
3044 continue;
3045 } //end if
3046 } //end if
3047 else //at the middle of the plat
3048 {
3049 VectorCopy(plattop, bottomorg);
3050 bottomorg[2] += 24;
3051 area1num = AAS_PointAreaNum(bottomorg);
3052 if (!area1num) continue;
3053 VectorCopy(platbottom, bottomorg);
3054 bottomorg[2] += 24;
3055 } //end else
3056 //look at adjacent areas around the top of the plat
3057 //make larger steps to outside the plat every time
3058 for (n = 0; n < 3; n++)
3059 {
3060 for (k = 0; k < 3; k++)
3061 {
3062 mins[k] -= 4;
3063 maxs[k] += 4;
3064 } //end for
3065 xvals_top[0] = mins[0]; xvals_top[1] = mids[0]; xvals_top[2] = maxs[0]; xvals_top[3] = mids[0];
3066 yvals_top[0] = mids[1]; yvals_top[1] = maxs[1]; yvals_top[2] = mids[1]; yvals_top[3] = mins[1];
3067 //
3068 xvals_top[4] = mins[0]; xvals_top[5] = maxs[0]; xvals_top[6] = maxs[0]; xvals_top[7] = mins[0];
3069 yvals_top[4] = maxs[1]; yvals_top[5] = maxs[1]; yvals_top[6] = mins[1]; yvals_top[7] = mins[1];
3070 //
3071 for (j = 0; j < 8; j++)
3072 {
3073 toporg[0] = origin[0] + xvals_top[j];
3074 toporg[1] = origin[1] + yvals_top[j];
3075 toporg[2] = plattop[2] + 16;
3076 //get a grounded or swim area near the plat in the top position
3077 area2num = AAS_PointAreaNum(toporg);
3078 for (l = 0; l < 16; l++)
3079 {
3080 if (area2num)
3081 {
3082 if (AAS_AreaGrounded(area2num) || AAS_AreaSwim(area2num))
3083 {
3084 VectorCopy(plattop, start);
3085 start[2] += 32;
3086 VectorCopy(toporg, end);
3087 end[2] += 1;
3088 trace = AAS_TraceClientBBox(start, end, PRESENCE_CROUCH, -1);
3089 if (trace.fraction >= 1) break;
3090 } //end if
3091 } //end if
3092 toporg[2] += 4;
3093 area2num = AAS_PointAreaNum(toporg);
3094 } //end if
3095 //if in solid
3096 if (l >= 16) continue;
3097 //never create a reachability in the same area
3098 if (area2num == area1num) continue;
3099 //if the area isn't grounded
3100 if (!AAS_AreaGrounded(area2num)) continue;
3101 //if there already exists reachability between the areas
3102 if (AAS_ReachabilityExists(area1num, area2num)) continue;
3103 //if the reachability start is within the elevator bounding box
3104 VectorSubtract(bottomorg, platbottom, dir);
3105 VectorNormalize(dir);
3106 dir[0] = bottomorg[0] + 24 * dir[0];
3107 dir[1] = bottomorg[1] + 24 * dir[1];
3108 dir[2] = bottomorg[2];
3109 //
3110 for (p = 0; p < 3; p++)
3111 if (dir[p] < origin[p] + mins[p] || dir[p] > origin[p] + maxs[p]) break;
3112 if (p >= 3) continue;
3113 //create a new reachability link
3114 lreach = AAS_AllocReachability();
3115 if (!lreach) continue;
3116 lreach->areanum = area2num;
3117 //the facenum is the model number
3118 lreach->facenum = modelnum;
3119 //the edgenum is the height
3120 lreach->edgenum = (int) height;
3121 //
3122 VectorCopy(dir, lreach->start);
3123 VectorCopy(toporg, lreach->end);
3124 lreach->traveltype = TRAVEL_ELEVATOR;
3125 lreach->traveltype |= AAS_TravelFlagsForTeam(ent);
3126 lreach->traveltime = aassettings.rs_startelevator + height * 100 / speed;
3127 lreach->next = areareachability[area1num];
3128 areareachability[area1num] = lreach;
3129 //don't go any further to the outside
3130 n = 9999;
3131 //
3132 #ifdef REACH_DEBUG
3133 Log_Write("elevator reach from %d to %d\r\n", area1num, area2num);
3134 #endif //REACH_DEBUG
3135 //
3136 reach_elevator++;
3137 } //end for
3138 } //end for
3139 } //end for
3140 } //end if
3141 } //end for
3142 } //end of the function AAS_Reachability_Elevator
3143 //===========================================================================
3144 //
3145 // Parameter: -
3146 // Returns: -
3147 // Changes Globals: -
3148 //===========================================================================
3149 aas_lreachability_t *AAS_FindFaceReachabilities(vec3_t *facepoints, int numpoints, aas_plane_t *plane, int towardsface)
3150 {
3151 int i, j, k, l;
3152 int facenum, edgenum, bestfacenum;
3153 float *v1, *v2, *v3, *v4;
3154 float bestdist, speed, hordist, dist;
3155 vec3_t beststart = {0}, beststart2 = {0}, bestend = {0}, bestend2 = {0}, tmp, hordir, testpoint;
3156 aas_lreachability_t *lreach, *lreachabilities;
3157 aas_area_t *area;
3158 aas_face_t *face;
3159 aas_edge_t *edge;
3160 aas_plane_t *faceplane, *bestfaceplane;
3161
3162 //
3163 lreachabilities = NULL;
3164 bestfacenum = 0;
3165 bestfaceplane = NULL;
3166 //
3167 for (i = 1; i < aasworld.numareas; i++)
3168 {
3169 area = &aasworld.areas[i];
3170 // get the shortest distance between one of the func_bob start edges and
3171 // one of the face edges of area1
3172 bestdist = 999999;
3173 for (j = 0; j < area->numfaces; j++)
3174 {
3175 facenum = aasworld.faceindex[area->firstface + j];
3176 face = &aasworld.faces[abs(facenum)];
3177 //if not a ground face
3178 if (!(face->faceflags & FACE_GROUND)) continue;
3179 //get the ground planes
3180 faceplane = &aasworld.planes[face->planenum];
3181 //
3182 for (k = 0; k < face->numedges; k++)
3183 {
3184 edgenum = abs(aasworld.edgeindex[face->firstedge + k]);
3185 edge = &aasworld.edges[edgenum];
3186 //calculate the minimum distance between the two edges
3187 v1 = aasworld.vertexes[edge->v[0]];
3188 v2 = aasworld.vertexes[edge->v[1]];
3189 //
3190 for (l = 0; l < numpoints; l++)
3191 {
3192 v3 = facepoints[l];
3193 v4 = facepoints[(l+1) % numpoints];
3194 dist = AAS_ClosestEdgePoints(v1, v2, v3, v4, faceplane, plane,
3195 beststart, bestend,
3196 beststart2, bestend2, bestdist);
3197 if (dist < bestdist)
3198 {
3199 bestfacenum = facenum;
3200 bestfaceplane = faceplane;
3201 bestdist = dist;
3202 } //end if
3203 } //end for
3204 } //end for
3205 } //end for
3206 //
3207 if (bestdist > 192) continue;
3208 //
3209 VectorMiddle(beststart, beststart2, beststart);
3210 VectorMiddle(bestend, bestend2, bestend);
3211 //
3212 if (!towardsface)
3213 {
3214 VectorCopy(beststart, tmp);
3215 VectorCopy(bestend, beststart);
3216 VectorCopy(tmp, bestend);
3217 } //end if
3218 //
3219 VectorSubtract(bestend, beststart, hordir);
3220 hordir[2] = 0;
3221 hordist = VectorLength(hordir);
3222 //
3223 if (hordist > 2 * AAS_MaxJumpDistance(aassettings.phys_jumpvel)) continue;
3224 //the end point should not be significantly higher than the start point
3225 if (bestend[2] - 32 > beststart[2]) continue;
3226 //don't fall down too far
3227 if (bestend[2] < beststart[2] - 128) continue;
3228 //the distance should not be too far
3229 if (hordist > 32)
3230 {
3231 //check for walk off ledge
3232 if (!AAS_HorizontalVelocityForJump(0, beststart, bestend, &speed)) continue;
3233 } //end if
3234 //
3235 beststart[2] += 1;
3236 bestend[2] += 1;
3237 //
3238 if (towardsface) VectorCopy(bestend, testpoint);
3239 else VectorCopy(beststart, testpoint);
3240 if (bestfaceplane != NULL)
3241 testpoint[2] = (bestfaceplane->dist - DotProduct(bestfaceplane->normal, testpoint)) / bestfaceplane->normal[2];
3242 else
3243 testpoint[2] = 0;
3244 //
3245 if (!AAS_PointInsideFace(bestfacenum, testpoint, 0.1f))
3246 {
3247 //if the faces are not overlapping then only go down
3248 if (bestend[2] - 16 > beststart[2]) continue;
3249 } //end if
3250 lreach = AAS_AllocReachability();
3251 if (!lreach) return lreachabilities;
3252 lreach->areanum = i;
3253 lreach->facenum = 0;
3254 lreach->edgenum = 0;
3255 VectorCopy(beststart, lreach->start);
3256 VectorCopy(bestend, lreach->end);
3257 lreach->traveltype = 0;
3258 lreach->traveltime = 0;
3259 lreach->next = lreachabilities;
3260 lreachabilities = lreach;
3261 #ifndef BSPC
3262 if (towardsface) AAS_PermanentLine(lreach->start, lreach->end, 1);
3263 else AAS_PermanentLine(lreach->start, lreach->end, 2);
3264 #endif
3265 } //end for
3266 return lreachabilities;
3267 } //end of the function AAS_FindFaceReachabilities
3268 //===========================================================================
3269 //
3270 // Parameter: -
3271 // Returns: -
3272 // Changes Globals: -
3273 //===========================================================================
3274 void AAS_Reachability_FuncBobbing(void)
3275 {
3276 int ent, spawnflags, modelnum, axis;
3277 int i, numareas, areas[10];
3278 char classname[MAX_EPAIRKEY], model[MAX_EPAIRKEY];
3279 vec3_t origin, move_end, move_start, move_start_top, move_end_top;
3280 vec3_t mins, maxs, angles = {0, 0, 0};
3281 vec3_t start_edgeverts[4], end_edgeverts[4], mid;
3282 vec3_t org, start, end, dir, points[10];
3283 float height;
3284 aas_plane_t start_plane, end_plane;
3285 aas_lreachability_t *startreach, *endreach, *nextstartreach, *nextendreach, *lreach;
3286 aas_lreachability_t *firststartreach, *firstendreach;
3287
3288 for (ent = AAS_NextBSPEntity(0); ent; ent = AAS_NextBSPEntity(ent))
3289 {
3290 if (!AAS_ValueForBSPEpairKey(ent, "classname", classname, MAX_EPAIRKEY)) continue;
3291 if (strcmp(classname, "func_bobbing")) continue;
3292 AAS_FloatForBSPEpairKey(ent, "height", &height);
3293 if (!height) height = 32;
3294 //
3295 if (!AAS_ValueForBSPEpairKey(ent, "model", model, MAX_EPAIRKEY))
3296 {
3297 botimport.Print(PRT_ERROR, "func_bobbing without model\n");
3298 continue;
3299 } //end if
3300 //get the model number, and skip the leading *
3301 modelnum = atoi(model+1);
3302 if (modelnum <= 0)
3303 {
3304 botimport.Print(PRT_ERROR, "func_bobbing with invalid model number\n");
3305 continue;
3306 } //end if
3307 //if the entity has an origin set then use it
3308 if (!AAS_VectorForBSPEpairKey(ent, "origin", origin))
3309 VectorSet(origin, 0, 0, 0);
3310 //
3311 AAS_BSPModelMinsMaxsOrigin(modelnum, angles, mins, maxs, NULL);
3312 //
3313 VectorAdd(mins, origin, mins);
3314 VectorAdd(maxs, origin, maxs);
3315 //
3316 VectorAdd(mins, maxs, mid);
3317 VectorScale(mid, 0.5, mid);
3318 VectorCopy(mid, origin);
3319 //
3320 VectorCopy(origin, move_end);
3321 VectorCopy(origin, move_start);
3322 //
3323 AAS_IntForBSPEpairKey(ent, "spawnflags", &spawnflags);
3324 // set the axis of bobbing
3325 if (spawnflags & 1) axis = 0;
3326 else if (spawnflags & 2) axis = 1;
3327 else axis = 2;
3328 //
3329 move_start[axis] -= height;
3330 move_end[axis] += height;
3331 //
3332 Log_Write("funcbob model %d, start = {%1.1f, %1.1f, %1.1f} end = {%1.1f, %1.1f, %1.1f}\n",
3333 modelnum, move_start[0], move_start[1], move_start[2], move_end[0], move_end[1], move_end[2]);
3334 //
3335 #ifndef BSPC
3336 /*
3337 AAS_DrawPermanentCross(move_start, 4, 1);
3338 AAS_DrawPermanentCross(move_end, 4, 2);
3339 */
3340 #endif
3341 //
3342 for (i = 0; i < 4; i++)
3343 {
3344 VectorCopy(move_start, start_edgeverts[i]);
3345 start_edgeverts[i][2] += maxs[2] - mid[2]; //+ bbox maxs z
3346 start_edgeverts[i][2] += 24; //+ player origin to ground dist
3347 } //end for
3348 start_edgeverts[0][0] += maxs[0] - mid[0];
3349 start_edgeverts[0][1] += maxs[1] - mid[1];
3350 start_edgeverts[1][0] += maxs[0] - mid[0];
3351 start_edgeverts[1][1] += mins[1] - mid[1];
3352 start_edgeverts[2][0] += mins[0] - mid[0];
3353 start_edgeverts[2][1] += mins[1] - mid[1];
3354 start_edgeverts[3][0] += mins[0] - mid[0];
3355 start_edgeverts[3][1] += maxs[1] - mid[1];
3356 //
3357 start_plane.dist = start_edgeverts[0][2];
3358 VectorSet(start_plane.normal, 0, 0, 1);
3359 //
3360 for (i = 0; i < 4; i++)
3361 {
3362 VectorCopy(move_end, end_edgeverts[i]);
3363 end_edgeverts[i][2] += maxs[2] - mid[2]; //+ bbox maxs z
3364 end_edgeverts[i][2] += 24; //+ player origin to ground dist
3365 } //end for
3366 end_edgeverts[0][0] += maxs[0] - mid[0];
3367 end_edgeverts[0][1] += maxs[1] - mid[1];
3368 end_edgeverts[1][0] += maxs[0] - mid[0];
3369 end_edgeverts[1][1] += mins[1] - mid[1];
3370 end_edgeverts[2][0] += mins[0] - mid[0];
3371 end_edgeverts[2][1] += mins[1] - mid[1];
3372 end_edgeverts[3][0] += mins[0] - mid[0];
3373 end_edgeverts[3][1] += maxs[1] - mid[1];
3374 //
3375 end_plane.dist = end_edgeverts[0][2];
3376 VectorSet(end_plane.normal, 0, 0, 1);
3377 //
3378 #ifndef BSPC
3379 #if 0
3380 for (i = 0; i < 4; i++)
3381 {
3382 AAS_PermanentLine(start_edgeverts[i], start_edgeverts[(i+1)%4], 1);
3383 AAS_PermanentLine(end_edgeverts[i], end_edgeverts[(i+1)%4], 1);
3384 } //end for
3385 #endif
3386 #endif
3387 VectorCopy(move_start, move_start_top);
3388 move_start_top[2] += maxs[2] - mid[2] + 24; //+ bbox maxs z
3389 VectorCopy(move_end, move_end_top);
3390 move_end_top[2] += maxs[2] - mid[2] + 24; //+ bbox maxs z
3391 //
3392 if (!AAS_PointAreaNum(move_start_top)) continue;
3393 if (!AAS_PointAreaNum(move_end_top)) continue;
3394 //
3395 for (i = 0; i < 2; i++)
3396 {
3397 //
3398 if (i == 0)
3399 {
3400 firststartreach = AAS_FindFaceReachabilities(start_edgeverts, 4, &start_plane, qtrue);
3401 firstendreach = AAS_FindFaceReachabilities(end_edgeverts, 4, &end_plane, qfalse);
3402 } //end if
3403 else
3404 {
3405 firststartreach = AAS_FindFaceReachabilities(end_edgeverts, 4, &end_plane, qtrue);
3406 firstendreach = AAS_FindFaceReachabilities(start_edgeverts, 4, &start_plane, qfalse);
3407 } //end else
3408 //
3409 //create reachabilities from start to end
3410 for (startreach = firststartreach; startreach; startreach = nextstartreach)
3411 {
3412 nextstartreach = startreach->next;
3413 //
3414 //trace = AAS_TraceClientBBox(startreach->start, move_start_top, PRESENCE_NORMAL, -1);
3415 //if (trace.fraction < 1) continue;
3416 //
3417 for (endreach = firstendreach; endreach; endreach = nextendreach)
3418 {
3419 nextendreach = endreach->next;
3420 //
3421 //trace = AAS_TraceClientBBox(endreach->end, move_end_top, PRESENCE_NORMAL, -1);
3422 //if (trace.fraction < 1) continue;
3423 //
3424 Log_Write("funcbob reach from area %d to %d\n", startreach->areanum, endreach->areanum);
3425 //
3426 //
3427 if (i == 0) VectorCopy(move_start_top, org);
3428 else VectorCopy(move_end_top, org);
3429 VectorSubtract(startreach->start, org, dir);
3430 dir[2] = 0;
3431 VectorNormalize(dir);
3432 VectorCopy(startreach->start, start);
3433 VectorMA(startreach->start, 1, dir, start);
3434 start[2] += 1;
3435 VectorMA(startreach->start, 16, dir, end);
3436 end[2] += 1;
3437 //
3438 numareas = AAS_TraceAreas(start, end, areas, points, 10);
3439 if (numareas <= 0) continue;
3440 if (numareas > 1) VectorCopy(points[1], startreach->start);
3441 else VectorCopy(end, startreach->start);
3442 //
3443 if (!AAS_PointAreaNum(startreach->start)) continue;
3444 if (!AAS_PointAreaNum(endreach->end)) continue;
3445 //
3446 lreach = AAS_AllocReachability();
3447 lreach->areanum = endreach->areanum;
3448 if (i == 0) lreach->edgenum = ((int)move_start[axis] << 16) | ((int) move_end[axis] & 0x0000ffff);
3449 else lreach->edgenum = ((int)move_end[axis] << 16) | ((int) move_start[axis] & 0x0000ffff);
3450 lreach->facenum = (spawnflags << 16) | modelnum;
3451 VectorCopy(startreach->start, lreach->start);
3452 VectorCopy(endreach->end, lreach->end);
3453 #ifndef BSPC
3454 // AAS_DrawArrow(lreach->start, lreach->end, LINECOLOR_BLUE, LINECOLOR_YELLOW);
3455 // AAS_PermanentLine(lreach->start, lreach->end, 1);
3456 #endif
3457 lreach->traveltype = TRAVEL_FUNCBOB;
3458 lreach->traveltype |= AAS_TravelFlagsForTeam(ent);
3459 lreach->traveltime = aassettings.rs_funcbob;
3460 reach_funcbob++;
3461 lreach->next = areareachability[startreach->areanum];
3462 areareachability[startreach->areanum] = lreach;
3463 //
3464 } //end for
3465 } //end for
3466 for (startreach = firststartreach; startreach; startreach = nextstartreach)
3467 {
3468 nextstartreach = startreach->next;
3469 AAS_FreeReachability(startreach);
3470 } //end for
3471 for (endreach = firstendreach; endreach; endreach = nextendreach)
3472 {
3473 nextendreach = endreach->next;
3474 AAS_FreeReachability(endreach);
3475 } //end for
3476 //only go up with func_bobbing entities that go up and down
3477 if (!(spawnflags & 1) && !(spawnflags & 2)) break;
3478 } //end for
3479 } //end for
3480 } //end of the function AAS_Reachability_FuncBobbing
3481 //===========================================================================
3482 //
3483 // Parameter: -
3484 // Returns: -
3485 // Changes Globals: -
3486 //===========================================================================
3487 void AAS_Reachability_JumpPad(void)
3488 {
3489 int face2num, i, ret, area2num, visualize, ent, bot_visualizejumppads;
3490 //int modelnum, ent2;
3491 //float dist, time, height, gravity, forward;
3492 float speed, zvel;
3493 //float hordist;
3494 aas_face_t *face2;
3495 aas_area_t *area2;
3496 aas_lreachability_t *lreach;
3497 vec3_t areastart, facecenter, dir, cmdmove;
3498 vec3_t velocity, absmins, absmaxs;
3499 //vec3_t origin, ent2origin, angles, teststart;
3500 aas_clientmove_t move;
3501 //aas_trace_t trace;
3502 aas_link_t *areas, *link;
3503 //char target[MAX_EPAIRKEY], targetname[MAX_EPAIRKEY], model[MAX_EPAIRKEY];
3504 char classname[MAX_EPAIRKEY];
3505
3506 #ifdef BSPC
3507 bot_visualizejumppads = 0;
3508 #else
3509 bot_visualizejumppads = LibVarValue("bot_visualizejumppads", "0");
3510 #endif
3511 for (ent = AAS_NextBSPEntity(0); ent; ent = AAS_NextBSPEntity(ent))
3512 {
3513 if (!AAS_ValueForBSPEpairKey(ent, "classname", classname, MAX_EPAIRKEY)) continue;
3514 if (strcmp(classname, "trigger_push")) continue;
3515 //
3516 if (!AAS_GetJumpPadInfo(ent, areastart, absmins, absmaxs, velocity)) continue;
3517 /*
3518 //
3519 AAS_FloatForBSPEpairKey(ent, "speed", &speed);
3520 if (!speed) speed = 1000;
3521 // AAS_VectorForBSPEpairKey(ent, "angles", angles);
3522 // AAS_SetMovedir(angles, velocity);
3523 // VectorScale(velocity, speed, velocity);
3524 VectorClear(angles);
3525 //get the mins, maxs and origin of the model
3526 AAS_ValueForBSPEpairKey(ent, "model", model, MAX_EPAIRKEY);
3527 if (model[0]) modelnum = atoi(model+1);
3528 else modelnum = 0;
3529 AAS_BSPModelMinsMaxsOrigin(modelnum, angles, absmins, absmaxs, origin);
3530 VectorAdd(origin, absmins, absmins);
3531 VectorAdd(origin, absmaxs, absmaxs);
3532 //
3533 #ifdef REACH_DEBUG
3534 botimport.Print(PRT_MESSAGE, "absmins = %f %f %f\n", absmins[0], absmins[1], absmins[2]);
3535 botimport.Print(PRT_MESSAGE, "absmaxs = %f %f %f\n", absmaxs[0], absmaxs[1], absmaxs[2]);
3536 #endif REACH_DEBUG
3537 VectorAdd(absmins, absmaxs, origin);
3538 VectorScale (origin, 0.5, origin);
3539
3540 //get the start areas
3541 VectorCopy(origin, teststart);
3542 teststart[2] += 64;
3543 trace = AAS_TraceClientBBox(teststart, origin, PRESENCE_CROUCH, -1);
3544 if (trace.startsolid)
3545 {
3546 botimport.Print(PRT_MESSAGE, "trigger_push start solid\n");
3547 VectorCopy(origin, areastart);
3548 } //end if
3549 else
3550 {
3551 VectorCopy(trace.endpos, areastart);
3552 } //end else
3553 areastart[2] += 0.125;
3554 //
3555 //AAS_DrawPermanentCross(origin, 4, 4);
3556 //get the target entity
3557 AAS_ValueForBSPEpairKey(ent, "target", target, MAX_EPAIRKEY);
3558 for (ent2 = AAS_NextBSPEntity(0); ent2; ent2 = AAS_NextBSPEntity(ent2))
3559 {
3560 if (!AAS_ValueForBSPEpairKey(ent2, "targetname", targetname, MAX_EPAIRKEY)) continue;
3561 if (!strcmp(targetname, target)) break;
3562 } //end for
3563 if (!ent2)
3564 {
3565 botimport.Print(PRT_MESSAGE, "trigger_push without target entity %s\n", target);
3566 continue;
3567 } //end if
3568 AAS_VectorForBSPEpairKey(ent2, "origin", ent2origin);
3569 //
3570 height = ent2origin[2] - origin[2];
3571 gravity = aassettings.sv_gravity;
3572 time = sqrt( height / ( 0.5 * gravity ) );
3573 if (!time)
3574 {
3575 botimport.Print(PRT_MESSAGE, "trigger_push without time\n");
3576 continue;
3577 } //end if
3578 // set s.origin2 to the push velocity
3579 VectorSubtract ( ent2origin, origin, velocity);
3580 dist = VectorNormalize( velocity);
3581 forward = dist / time;
3582 //FIXME: why multiply by 1.1
3583 forward *= 1.1;
3584 VectorScale(velocity, forward, velocity);
3585 velocity[2] = time * gravity;
3586 */
3587 //get the areas the jump pad brush is in
3588 areas = AAS_LinkEntityClientBBox(absmins, absmaxs, -1, PRESENCE_CROUCH);
3589 /*
3590 for (link = areas; link; link = link->next_area)
3591 {
3592 if (link->areanum == 563)
3593 {
3594 ret = qfalse;
3595 }
3596 }
3597 */
3598 for (link = areas; link; link = link->next_area)
3599 {
3600 if (AAS_AreaJumpPad(link->areanum)) break;
3601 } //end for
3602 if (!link)
3603 {
3604 botimport.Print(PRT_MESSAGE, "trigger_push not in any jump pad area\n");
3605 AAS_UnlinkFromAreas(areas);
3606 continue;
3607 } //end if
3608 //
3609 botimport.Print(PRT_MESSAGE, "found a trigger_push with velocity %f %f %f\n", velocity[0], velocity[1], velocity[2]);
3610 //if there is a horizontal velocity check for a reachability without air control
3611 if (velocity[0] || velocity[1])
3612 {
3613 VectorSet(cmdmove, 0, 0, 0);
3614 //VectorCopy(velocity, cmdmove);
3615 //cmdmove[2] = 0;
3616 Com_Memset(&move, 0, sizeof(aas_clientmove_t));
3617 area2num = 0;
3618 for (i = 0; i < 20; i++)
3619 {
3620 AAS_PredictClientMovement(&move, -1, areastart, PRESENCE_NORMAL, qfalse,
3621 velocity, cmdmove, 0, 30, 0.1f,
3622 SE_HITGROUND|SE_ENTERWATER|SE_ENTERSLIME|
3623 SE_ENTERLAVA|SE_HITGROUNDDAMAGE|SE_TOUCHJUMPPAD|SE_TOUCHTELEPORTER, 0, bot_visualizejumppads);
3624 area2num = move.endarea;
3625 for (link = areas; link; link = link->next_area)
3626 {
3627 if (!AAS_AreaJumpPad(link->areanum)) continue;
3628 if (link->areanum == area2num) break;
3629 } //end if
3630 if (!link) break;
3631 VectorCopy(move.endpos, areastart);
3632 VectorCopy(move.velocity, velocity);
3633 } //end for
3634 if (area2num && i < 20)
3635 {
3636 for (link = areas; link; link = link->next_area)
3637 {
3638 if (!AAS_AreaJumpPad(link->areanum)) continue;
3639 if (AAS_ReachabilityExists(link->areanum, area2num)) continue;
3640 //create a rocket or bfg jump reachability from area1 to area2
3641 lreach = AAS_AllocReachability();
3642 if (!lreach)
3643 {
3644 AAS_UnlinkFromAreas(areas);
3645 return;
3646 } //end if
3647 lreach->areanum = area2num;
3648 //NOTE: the facenum is the Z velocity
3649 lreach->facenum = velocity[2];
3650 //NOTE: the edgenum is the horizontal velocity
3651 lreach->edgenum = sqrt(velocity[0] * velocity[0] + velocity[1] * velocity[1]);
3652 VectorCopy(areastart, lreach->start);
3653 VectorCopy(move.endpos, lreach->end);
3654 lreach->traveltype = TRAVEL_JUMPPAD;
3655 lreach->traveltype |= AAS_TravelFlagsForTeam(ent);
3656 lreach->traveltime = aassettings.rs_jumppad;
3657 lreach->next = areareachability[link->areanum];
3658 areareachability[link->areanum] = lreach;
3659 //
3660 reach_jumppad++;
3661 } //end for
3662 } //end if
3663 } //end if
3664 //
3665 if (fabs(velocity[0]) > 100 || fabs(velocity[1]) > 100) continue;
3666 //check for areas we can reach with air control
3667 for (area2num = 1; area2num < aasworld.numareas; area2num++)
3668 {
3669 visualize = qfalse;
3670 /*
3671 if (area2num == 3568)
3672 {
3673 for (link = areas; link; link = link->next_area)
3674 {
3675 if (link->areanum == 3380)
3676 {
3677 visualize = qtrue;
3678 botimport.Print(PRT_MESSAGE, "bah\n");
3679 } //end if
3680 } //end for
3681 } //end if*/
3682 //never try to go back to one of the original jumppad areas
3683 //and don't create reachabilities if they already exist
3684 for (link = areas; link; link = link->next_area)
3685 {
3686 if (AAS_ReachabilityExists(link->areanum, area2num)) break;
3687 if (AAS_AreaJumpPad(link->areanum))
3688 {
3689 if (link->areanum == area2num) break;
3690 } //end if
3691 } //end if
3692 if (link) continue;
3693 //
3694 area2 = &aasworld.areas[area2num];
3695 for (i = 0; i < area2->numfaces; i++)
3696 {
3697 face2num = aasworld.faceindex[area2->firstface + i];
3698 face2 = &aasworld.faces[abs(face2num)];
3699 //if it is not a ground face
3700 if (!(face2->faceflags & FACE_GROUND)) continue;
3701 //get the center of the face
3702 AAS_FaceCenter(face2num, facecenter);
3703 //only go higher up
3704 if (facecenter[2] < areastart[2]) continue;
3705 //get the jumppad jump z velocity
3706 zvel = velocity[2];
3707 //get the horizontal speed for the jump, if it isn't possible to calculate this
3708 //speed
3709 ret = AAS_HorizontalVelocityForJump(zvel, areastart, facecenter, &speed);
3710 if (ret && speed < 150)
3711 {
3712 //direction towards the face center
3713 VectorSubtract(facecenter, areastart, dir);
3714 dir[2] = 0;
3715 //hordist = VectorNormalize(dir);
3716 //if (hordist < 1.6 * facecenter[2] - areastart[2])
3717 {
3718 //get command movement
3719 VectorScale(dir, speed, cmdmove);
3720 //
3721 AAS_PredictClientMovement(&move, -1, areastart, PRESENCE_NORMAL, qfalse,
3722 velocity, cmdmove, 30, 30, 0.1f,
3723 SE_ENTERWATER|SE_ENTERSLIME|
3724 SE_ENTERLAVA|SE_HITGROUNDDAMAGE|
3725 SE_TOUCHJUMPPAD|SE_TOUCHTELEPORTER|SE_HITGROUNDAREA, area2num, visualize);
3726 //if prediction time wasn't enough to fully predict the movement
3727 //don't enter slime or lava and don't fall from too high
3728 if (move.frames < 30 &&
3729 !(move.stopevent & (SE_ENTERSLIME|SE_ENTERLAVA|SE_HITGROUNDDAMAGE))
3730 && (move.stopevent & (SE_HITGROUNDAREA|SE_TOUCHJUMPPAD|SE_TOUCHTELEPORTER)))
3731 {
3732 //never go back to the same jumppad
3733 for (link = areas; link; link = link->next_area)
3734 {
3735 if (link->areanum == move.endarea) break;
3736 }
3737 if (!link)
3738 {
3739 for (link = areas; link; link = link->next_area)
3740 {
3741 if (!AAS_AreaJumpPad(link->areanum)) continue;
3742 if (AAS_ReachabilityExists(link->areanum, area2num)) continue;
3743 //create a jumppad reachability from area1 to area2
3744 lreach = AAS_AllocReachability();
3745 if (!lreach)
3746 {
3747 AAS_UnlinkFromAreas(areas);
3748 return;
3749 } //end if
3750 lreach->areanum = move.endarea;
3751 //NOTE: the facenum is the Z velocity
3752 lreach->facenum = velocity[2];
3753 //NOTE: the edgenum is the horizontal velocity
3754 lreach->edgenum = sqrt(cmdmove[0] * cmdmove[0] + cmdmove[1] * cmdmove[1]);
3755 VectorCopy(areastart, lreach->start);
3756 VectorCopy(facecenter, lreach->end);
3757 lreach->traveltype = TRAVEL_JUMPPAD;
3758 lreach->traveltype |= AAS_TravelFlagsForTeam(ent);
3759 lreach->traveltime = aassettings.rs_aircontrolledjumppad;
3760 lreach->next = areareachability[link->areanum];
3761 areareachability[link->areanum] = lreach;
3762 //
3763 reach_jumppad++;
3764 } //end for
3765 }
3766 } //end if
3767 } //end if
3768 } //end for
3769 } //end for
3770 } //end for
3771 AAS_UnlinkFromAreas(areas);
3772 } //end for
3773 } //end of the function AAS_Reachability_JumpPad
3774 //===========================================================================
3775 // never point at ground faces
3776 // always a higher and pretty far area
3777 //
3778 // Parameter: -
3779 // Returns: -
3780 // Changes Globals: -
3781 //===========================================================================
3782 int AAS_Reachability_Grapple(int area1num, int area2num)
3783 {
3784 int face2num, i, j, areanum, numareas, areas[20];
3785 float mingrappleangle, z, hordist;
3786 bsp_trace_t bsptrace;
3787 aas_trace_t trace;
3788 aas_face_t *face2;
3789 aas_area_t *area1, *area2;
3790 aas_lreachability_t *lreach;
3791 vec3_t areastart = {0, 0, 0}, facecenter, start, end, dir, down = {0, 0, -1};
3792 vec_t *v;
3793
3794 //only grapple when on the ground or swimming
3795 if (!AAS_AreaGrounded(area1num) && !AAS_AreaSwim(area1num)) return qfalse;
3796 //don't grapple from a crouch area
3797 if (!(AAS_AreaPresenceType(area1num) & PRESENCE_NORMAL)) return qfalse;
3798 //NOTE: disabled area swim it doesn't work right
3799 if (AAS_AreaSwim(area1num)) return qfalse;
3800 //
3801 area1 = &aasworld.areas[area1num];
3802 area2 = &aasworld.areas[area2num];
3803 //don't grapple towards way lower areas
3804 if (area2->maxs[2] < area1->mins[2]) return qfalse;
3805 //
3806 VectorCopy(aasworld.areas[area1num].center, start);
3807 //if not a swim area
3808 if (!AAS_AreaSwim(area1num))
3809 {
3810 if (!AAS_PointAreaNum(start)) Log_Write("area %d center %f %f %f in solid?\r\n", area1num,
3811 start[0], start[1], start[2]);
3812 VectorCopy(start, end);
3813 end[2] -= 1000;
3814 trace = AAS_TraceClientBBox(start, end, PRESENCE_CROUCH, -1);
3815 if (trace.startsolid) return qfalse;
3816 VectorCopy(trace.endpos, areastart);
3817 } //end if
3818 else
3819 {
3820 if (!(AAS_PointContents(start) & (CONTENTS_LAVA|CONTENTS_SLIME|CONTENTS_WATER))) return qfalse;
3821 } //end else
3822 //
3823 //start is now the start point
3824 //
3825 for (i = 0; i < area2->numfaces; i++)
3826 {
3827 face2num = aasworld.faceindex[area2->firstface + i];
3828 face2 = &aasworld.faces[abs(face2num)];
3829 //if it is not a solid face
3830 if (!(face2->faceflags & FACE_SOLID)) continue;
3831 //direction towards the first vertex of the face
3832 v = aasworld.vertexes[aasworld.edges[abs(aasworld.edgeindex[face2->firstedge])].v[0]];
3833 VectorSubtract(v, areastart, dir);
3834 //if the face plane is facing away
3835 if (DotProduct(aasworld.planes[face2->planenum].normal, dir) > 0) continue;
3836 //get the center of the face
3837 AAS_FaceCenter(face2num, facecenter);
3838 //only go higher up with the grapple
3839 if (facecenter[2] < areastart[2] + 64) continue;
3840 //only use vertical faces or downward facing faces
3841 if (DotProduct(aasworld.planes[face2->planenum].normal, down) < 0) continue;
3842 //direction towards the face center
3843 VectorSubtract(facecenter, areastart, dir);
3844 //
3845 z = dir[2];
3846 dir[2] = 0;
3847 hordist = VectorLength(dir);
3848 if (!hordist) continue;
3849 //if too far
3850 if (hordist > 2000) continue;
3851 //check the minimal angle of the movement
3852 mingrappleangle = 15; //15 degrees
3853 if (z / hordist < tan(2 * M_PI * mingrappleangle / 360)) continue;
3854 //
3855 VectorCopy(facecenter, start);
3856 VectorMA(facecenter, -500, aasworld.planes[face2->planenum].normal, end);
3857 //
3858 bsptrace = AAS_Trace(start, NULL, NULL, end, 0, CONTENTS_SOLID);
3859 //the grapple won't stick to the sky and the grapple point should be near the AAS wall
3860 if ((bsptrace.surface.flags & SURF_SKY) || (bsptrace.fraction * 500 > 32)) continue;
3861 //trace a full bounding box from the area center on the ground to
3862 //the center of the face
3863 VectorSubtract(facecenter, areastart, dir);
3864 VectorNormalize(dir);
3865 VectorMA(areastart, 4, dir, start);
3866 VectorCopy(bsptrace.endpos, end);
3867 trace = AAS_TraceClientBBox(start, end, PRESENCE_NORMAL, -1);
3868 VectorSubtract(trace.endpos, facecenter, dir);
3869 if (VectorLength(dir) > 24) continue;
3870 //
3871 VectorCopy(trace.endpos, start);
3872 VectorCopy(trace.endpos, end);
3873 end[2] -= AAS_FallDamageDistance();
3874 trace = AAS_TraceClientBBox(start, end, PRESENCE_NORMAL, -1);
3875 if (trace.fraction >= 1) continue;
3876 //area to end in
3877 areanum = AAS_PointAreaNum(trace.endpos);
3878 //if not in lava or slime
3879 if (aasworld.areasettings[areanum].contents & (AREACONTENTS_SLIME|AREACONTENTS_LAVA))
3880 {
3881 continue;
3882 } //end if
3883 //do not go the the source area
3884 if (areanum == area1num) continue;
3885 //don't create reachabilities if they already exist
3886 if (AAS_ReachabilityExists(area1num, areanum)) continue;
3887 //only end in areas we can stand
3888 if (!AAS_AreaGrounded(areanum)) continue;
3889 //never go through cluster portals!!
3890 numareas = AAS_TraceAreas(areastart, bsptrace.endpos, areas, NULL, 20);
3891 if (numareas >= 20) continue;
3892 for (j = 0; j < numareas; j++)
3893 {
3894 if (aasworld.areasettings[areas[j]].contents & AREACONTENTS_CLUSTERPORTAL) break;
3895 } //end for
3896 if (j < numareas) continue;
3897 //create a new reachability link
3898 lreach = AAS_AllocReachability();
3899 if (!lreach) return qfalse;
3900 lreach->areanum = areanum;
3901 lreach->facenum = face2num;
3902 lreach->edgenum = 0;
3903 VectorCopy(areastart, lreach->start);
3904 //VectorCopy(facecenter, lreach->end);
3905 VectorCopy(bsptrace.endpos, lreach->end);
3906 lreach->traveltype = TRAVEL_GRAPPLEHOOK;
3907 VectorSubtract(lreach->end, lreach->start, dir);
3908 lreach->traveltime = aassettings.rs_startgrapple + VectorLength(dir) * 0.25;
3909 lreach->next = areareachability[area1num];
3910 areareachability[area1num] = lreach;
3911 //
3912 reach_grapple++;
3913 } //end for
3914 //
3915 return qfalse;
3916 } //end of the function AAS_Reachability_Grapple
3917 //===========================================================================
3918 //
3919 // Parameter: -
3920 // Returns: -
3921 // Changes Globals: -
3922 //===========================================================================
3923 void AAS_SetWeaponJumpAreaFlags(void)
3924 {
3925 int ent, i;
3926 vec3_t mins = {-15, -15, -15}, maxs = {15, 15, 15};
3927 vec3_t origin;
3928 int areanum, weaponjumpareas, spawnflags;
3929 char classname[MAX_EPAIRKEY];
3930
3931 weaponjumpareas = 0;
3932 for (ent = AAS_NextBSPEntity(0); ent; ent = AAS_NextBSPEntity(ent))
3933 {
3934 if (!AAS_ValueForBSPEpairKey(ent, "classname", classname, MAX_EPAIRKEY)) continue;
3935 if (
3936 !strcmp(classname, "item_armor_body") ||
3937 !strcmp(classname, "item_armor_combat") ||
3938 !strcmp(classname, "item_health_mega") ||
3939 !strcmp(classname, "weapon_grenadelauncher") ||
3940 !strcmp(classname, "weapon_rocketlauncher") ||
3941 !strcmp(classname, "weapon_lightning") ||
3942 !strcmp(classname, "weapon_plasmagun") ||
3943 !strcmp(classname, "weapon_railgun") ||
3944 !strcmp(classname, "weapon_bfg") ||
3945 !strcmp(classname, "item_quad") ||
3946 !strcmp(classname, "item_regen") ||
3947 !strcmp(classname, "item_invulnerability"))
3948 {
3949 if (AAS_VectorForBSPEpairKey(ent, "origin", origin))
3950 {
3951 spawnflags = 0;
3952 AAS_IntForBSPEpairKey(ent, "spawnflags", &spawnflags);
3953 //if not a stationary item
3954 if (!(spawnflags & 1))
3955 {
3956 if (!AAS_DropToFloor(origin, mins, maxs))
3957 {
3958 botimport.Print(PRT_MESSAGE, "%s in solid at (%1.1f %1.1f %1.1f)\n",
3959 classname, origin[0], origin[1], origin[2]);
3960 } //end if
3961 } //end if
3962 //areanum = AAS_PointAreaNum(origin);
3963 areanum = AAS_BestReachableArea(origin, mins, maxs, origin);
3964 //the bot may rocket jump towards this area
3965 aasworld.areasettings[areanum].areaflags |= AREA_WEAPONJUMP;
3966 //
3967 //if (!AAS_AreaGrounded(areanum))
3968 // botimport.Print(PRT_MESSAGE, "area not grounded\n");
3969 //
3970 weaponjumpareas++;
3971 } //end if
3972 } //end if
3973 } //end for
3974 for (i = 1; i < aasworld.numareas; i++)
3975 {
3976 if (aasworld.areasettings[i].contents & AREACONTENTS_JUMPPAD)
3977 {
3978 aasworld.areasettings[i].areaflags |= AREA_WEAPONJUMP;
3979 weaponjumpareas++;
3980 } //end if
3981 } //end for
3982 botimport.Print(PRT_MESSAGE, "%d weapon jump areas\n", weaponjumpareas);
3983 } //end of the function AAS_SetWeaponJumpAreaFlags
3984 //===========================================================================
3985 // create a possible weapon jump reachability from area1 to area2
3986 //
3987 // check if there's a cool item in the second area
3988 // check if area1 is lower than area2
3989 // check if the bot can rocketjump from area1 to area2
3990 //
3991 // Parameter: -
3992 // Returns: -
3993 // Changes Globals: -
3994 //===========================================================================
3995 int AAS_Reachability_WeaponJump(int area1num, int area2num)
3996 {
3997 int face2num, i, n, ret, visualize;
3998 float speed, zvel;
3999 //float hordist;
4000 aas_face_t *face2;
4001 aas_area_t *area1, *area2;
4002 aas_lreachability_t *lreach;
4003 vec3_t areastart, facecenter, start, end, dir, cmdmove;// teststart;
4004 vec3_t velocity;
4005 aas_clientmove_t move;
4006 aas_trace_t trace;
4007
4008 visualize = qfalse;
4009 // if (area1num == 4436 && area2num == 4318)
4010 // {
4011 // visualize = qtrue;
4012 // }
4013 if (!AAS_AreaGrounded(area1num) || AAS_AreaSwim(area1num)) return qfalse;
4014 if (!AAS_AreaGrounded(area2num)) return qfalse;
4015 //NOTE: only weapon jump towards areas with an interesting item in it??
4016 if (!(aasworld.areasettings[area2num].areaflags & AREA_WEAPONJUMP)) return qfalse;
4017 //
4018 area1 = &aasworld.areas[area1num];
4019 area2 = &aasworld.areas[area2num];
4020 //don't weapon jump towards way lower areas
4021 if (area2->maxs[2] < area1->mins[2]) return qfalse;
4022 //
4023 VectorCopy(aasworld.areas[area1num].center, start);
4024 //if not a swim area
4025 if (!AAS_PointAreaNum(start)) Log_Write("area %d center %f %f %f in solid?\r\n", area1num,
4026 start[0], start[1], start[2]);
4027 VectorCopy(start, end);
4028 end[2] -= 1000;
4029 trace = AAS_TraceClientBBox(start, end, PRESENCE_CROUCH, -1);
4030 if (trace.startsolid) return qfalse;
4031 VectorCopy(trace.endpos, areastart);
4032 //
4033 //areastart is now the start point
4034 //
4035 for (i = 0; i < area2->numfaces; i++)
4036 {
4037 face2num = aasworld.faceindex[area2->firstface + i];
4038 face2 = &aasworld.faces[abs(face2num)];
4039 //if it is not a solid face
4040 if (!(face2->faceflags & FACE_GROUND)) continue;
4041 //get the center of the face
4042 AAS_FaceCenter(face2num, facecenter);
4043 //only go higher up with weapon jumps
4044 if (facecenter[2] < areastart[2] + 64) continue;
4045 //NOTE: set to 2 to allow bfg jump reachabilities
4046 for (n = 0; n < 1/*2*/; n++)
4047 {
4048 //get the rocket jump z velocity
4049 if (n) zvel = AAS_BFGJumpZVelocity(areastart);
4050 else zvel = AAS_RocketJumpZVelocity(areastart);
4051 //get the horizontal speed for the jump, if it isn't possible to calculate this
4052 //speed (the jump is not possible) then there's no jump reachability created
4053 ret = AAS_HorizontalVelocityForJump(zvel, areastart, facecenter, &speed);
4054 if (ret && speed < 300)
4055 {
4056 //direction towards the face center
4057 VectorSubtract(facecenter, areastart, dir);
4058 dir[2] = 0;
4059 //hordist = VectorNormalize(dir);
4060 //if (hordist < 1.6 * (facecenter[2] - areastart[2]))
4061 {
4062 //get command movement
4063 VectorScale(dir, speed, cmdmove);
4064 VectorSet(velocity, 0, 0, zvel);
4065 /*
4066 //get command movement
4067 VectorScale(dir, speed, velocity);
4068 velocity[2] = zvel;
4069 VectorSet(cmdmove, 0, 0, 0);
4070 */
4071 //
4072 AAS_PredictClientMovement(&move, -1, areastart, PRESENCE_NORMAL, qtrue,
4073 velocity, cmdmove, 30, 30, 0.1f,
4074 SE_ENTERWATER|SE_ENTERSLIME|
4075 SE_ENTERLAVA|SE_HITGROUNDDAMAGE|
4076 SE_TOUCHJUMPPAD|SE_HITGROUND|SE_HITGROUNDAREA, area2num, visualize);
4077 //if prediction time wasn't enough to fully predict the movement
4078 //don't enter slime or lava and don't fall from too high
4079 if (move.frames < 30 &&
4080 !(move.stopevent & (SE_ENTERSLIME|SE_ENTERLAVA|SE_HITGROUNDDAMAGE))
4081 && (move.stopevent & (SE_HITGROUNDAREA|SE_TOUCHJUMPPAD)))
4082 {
4083 //create a rocket or bfg jump reachability from area1 to area2
4084 lreach = AAS_AllocReachability();
4085 if (!lreach) return qfalse;
4086 lreach->areanum = area2num;
4087 lreach->facenum = 0;
4088 lreach->edgenum = 0;
4089 VectorCopy(areastart, lreach->start);
4090 VectorCopy(facecenter, lreach->end);
4091 if (n)
4092 {
4093 lreach->traveltype = TRAVEL_BFGJUMP;
4094 lreach->traveltime = aassettings.rs_bfgjump;
4095 } //end if
4096 else
4097 {
4098 lreach->traveltype = TRAVEL_ROCKETJUMP;
4099 lreach->traveltime = aassettings.rs_rocketjump;
4100 } //end else
4101 lreach->next = areareachability[area1num];
4102 areareachability[area1num] = lreach;
4103 //
4104 reach_rocketjump++;
4105 return qtrue;
4106 } //end if
4107 } //end if
4108 } //end if
4109 } //end for
4110 } //end for
4111 //
4112 return qfalse;
4113 } //end of the function AAS_Reachability_WeaponJump
4114 //===========================================================================
4115 // calculates additional walk off ledge reachabilities for the given area
4116 //
4117 // Parameter: -
4118 // Returns: -
4119 // Changes Globals: -
4120 //===========================================================================
4121 void AAS_Reachability_WalkOffLedge(int areanum)
4122 {
4123 int i, j, k, l, m, n, p, areas[10], numareas;
4124 int face1num, face2num, face3num, edge1num, edge2num, edge3num;
4125 int otherareanum, gap, reachareanum, side;
4126 aas_area_t *area, *area2;
4127 aas_face_t *face1, *face2, *face3;
4128 aas_edge_t *edge;
4129 aas_plane_t *plane;
4130 vec_t *v1, *v2;
4131 vec3_t sharededgevec, mid, dir, testend;
4132 aas_lreachability_t *lreach;
4133 aas_trace_t trace;
4134
4135 if (!AAS_AreaGrounded(areanum) || AAS_AreaSwim(areanum)) return;
4136 //
4137 area = &aasworld.areas[areanum];
4138 //
4139 for (i = 0; i < area->numfaces; i++)
4140 {
4141 face1num = aasworld.faceindex[area->firstface + i];
4142 face1 = &aasworld.faces[abs(face1num)];
4143 //face 1 must be a ground face
4144 if (!(face1->faceflags & FACE_GROUND)) continue;
4145 //go through all the edges of this ground face
4146 for (k = 0; k < face1->numedges; k++)
4147 {
4148 edge1num = aasworld.edgeindex[face1->firstedge + k];
4149 //find another not ground face using this same edge
4150 for (j = 0; j < area->numfaces; j++)
4151 {
4152 face2num = aasworld.faceindex[area->firstface + j];
4153 face2 = &aasworld.faces[abs(face2num)];
4154 //face 2 may not be a ground face
4155 if (face2->faceflags & FACE_GROUND) continue;
4156 //compare all the edges
4157 for (l = 0; l < face2->numedges; l++)
4158 {
4159 edge2num = aasworld.edgeindex[face2->firstedge + l];
4160 if (abs(edge1num) == abs(edge2num))
4161 {
4162 //get the area at the other side of the face
4163 if (face2->frontarea == areanum) otherareanum = face2->backarea;
4164 else otherareanum = face2->frontarea;
4165 //
4166 area2 = &aasworld.areas[otherareanum];
4167 //if the other area is grounded!
4168 if (aasworld.areasettings[otherareanum].areaflags & AREA_GROUNDED)
4169 {
4170 //check for a possible gap
4171 gap = qfalse;
4172 for (n = 0; n < area2->numfaces; n++)
4173 {
4174 face3num = aasworld.faceindex[area2->firstface + n];
4175 //may not be the shared face of the two areas
4176 if (abs(face3num) == abs(face2num)) continue;
4177 //
4178 face3 = &aasworld.faces[abs(face3num)];
4179 //find an edge shared by all three faces
4180 for (m = 0; m < face3->numedges; m++)
4181 {
4182 edge3num = aasworld.edgeindex[face3->firstedge + m];
4183 //but the edge should be shared by all three faces
4184 if (abs(edge3num) == abs(edge1num))
4185 {
4186 if (!(face3->faceflags & FACE_SOLID))
4187 {
4188 gap = qtrue;
4189 break;
4190 } //end if
4191 //
4192 if (face3->faceflags & FACE_GROUND)
4193 {
4194 gap = qfalse;
4195 break;
4196 } //end if
4197 //FIXME: there are more situations to be handled
4198 gap = qtrue;
4199 break;
4200 } //end if
4201 } //end for
4202 if (m < face3->numedges) break;
4203 } //end for
4204 if (!gap) break;
4205 } //end if
4206 //check for a walk off ledge reachability
4207 edge = &aasworld.edges[abs(edge1num)];
4208 side = edge1num < 0;
4209 //
4210 v1 = aasworld.vertexes[edge->v[side]];
4211 v2 = aasworld.vertexes[edge->v[!side]];
4212 //
4213 plane = &aasworld.planes[face1->planenum];
4214 //get the points really into the areas
4215 VectorSubtract(v2, v1, sharededgevec);
4216 CrossProduct(plane->normal, sharededgevec, dir);
4217 VectorNormalize(dir);
4218 //
4219 VectorAdd(v1, v2, mid);
4220 VectorScale(mid, 0.5, mid);
4221 VectorMA(mid, 8, dir, mid);
4222 //
4223 VectorCopy(mid, testend);
4224 testend[2] -= 1000;
4225 trace = AAS_TraceClientBBox(mid, testend, PRESENCE_CROUCH, -1);
4226 //
4227 if (trace.startsolid)
4228 {
4229 //Log_Write("area %d: trace.startsolid\r\n", areanum);
4230 break;
4231 } //end if
4232 reachareanum = AAS_PointAreaNum(trace.endpos);
4233 if (reachareanum == areanum)
4234 {
4235 //Log_Write("area %d: same area\r\n", areanum);
4236 break;
4237 } //end if
4238 if (AAS_ReachabilityExists(areanum, reachareanum))
4239 {
4240 //Log_Write("area %d: reachability already exists\r\n", areanum);
4241 break;
4242 } //end if
4243 if (!AAS_AreaGrounded(reachareanum) && !AAS_AreaSwim(reachareanum))
4244 {
4245 //Log_Write("area %d, reach area %d: not grounded and not swim\r\n", areanum, reachareanum);
4246 break;
4247 } //end if
4248 //
4249 if (aasworld.areasettings[reachareanum].contents & (AREACONTENTS_SLIME
4250 | AREACONTENTS_LAVA))
4251 {
4252 //Log_Write("area %d, reach area %d: lava or slime\r\n", areanum, reachareanum);
4253 break;
4254 } //end if
4255 //if not going through a cluster portal
4256 numareas = AAS_TraceAreas(mid, testend, areas, NULL, ARRAY_LEN(areas));
4257 for (p = 0; p < numareas; p++)
4258 if (AAS_AreaClusterPortal(areas[p]))
4259 break;
4260 if (p < numareas)
4261 break;
4262 // if a maximum fall height is set and the bot would fall down further
4263 if (aassettings.rs_maxfallheight && fabs(mid[2] - trace.endpos[2]) > aassettings.rs_maxfallheight)
4264 break;
4265 //
4266 lreach = AAS_AllocReachability();
4267 if (!lreach) break;
4268 lreach->areanum = reachareanum;
4269 lreach->facenum = 0;
4270 lreach->edgenum = edge1num;
4271 VectorCopy(mid, lreach->start);
4272 VectorCopy(trace.endpos, lreach->end);
4273 lreach->traveltype = TRAVEL_WALKOFFLEDGE;
4274 lreach->traveltime = aassettings.rs_startwalkoffledge + fabs(mid[2] - trace.endpos[2]) * 50 / aassettings.phys_gravity;
4275 if (!AAS_AreaSwim(reachareanum) && !AAS_AreaJumpPad(reachareanum))
4276 {
4277 if (AAS_FallDelta(mid[2] - trace.endpos[2]) > aassettings.phys_falldelta5)
4278 {
4279 lreach->traveltime += aassettings.rs_falldamage5;
4280 } //end if
4281 else if (AAS_FallDelta(mid[2] - trace.endpos[2]) > aassettings.phys_falldelta10)
4282 {
4283 lreach->traveltime += aassettings.rs_falldamage10;
4284 } //end if
4285 } //end if
4286 lreach->next = areareachability[areanum];
4287 areareachability[areanum] = lreach;
4288 //we've got another walk off ledge reachability
4289 reach_walkoffledge++;
4290 } //end if
4291 } //end for
4292 } //end for
4293 } //end for
4294 } //end for
4295 } //end of the function AAS_Reachability_WalkOffLedge
4296 //===========================================================================
4297 //
4298 // Parameter: -
4299 // Returns: -
4300 // Changes Globals: -
4301 //===========================================================================
4302 void AAS_StoreReachability(void)
4303 {
4304 int i;
4305 aas_areasettings_t *areasettings;
4306 aas_lreachability_t *lreach;
4307 aas_reachability_t *reach;
4308
4309 if (aasworld.reachability) FreeMemory(aasworld.reachability);
4310 aasworld.reachability = (aas_reachability_t *) GetClearedMemory((numlreachabilities + 10) * sizeof(aas_reachability_t));
4311 aasworld.reachabilitysize = 1;
4312 for (i = 0; i < aasworld.numareas; i++)
4313 {
4314 areasettings = &aasworld.areasettings[i];
4315 areasettings->firstreachablearea = aasworld.reachabilitysize;
4316 areasettings->numreachableareas = 0;
4317 for (lreach = areareachability[i]; lreach; lreach = lreach->next)
4318 {
4319 reach = &aasworld.reachability[areasettings->firstreachablearea +
4320 areasettings->numreachableareas];
4321 reach->areanum = lreach->areanum;
4322 reach->facenum = lreach->facenum;
4323 reach->edgenum = lreach->edgenum;
4324 VectorCopy(lreach->start, reach->start);
4325 VectorCopy(lreach->end, reach->end);
4326 reach->traveltype = lreach->traveltype;
4327 reach->traveltime = lreach->traveltime;
4328 //
4329 areasettings->numreachableareas++;
4330 } //end for
4331 aasworld.reachabilitysize += areasettings->numreachableareas;
4332 } //end for
4333 } //end of the function AAS_StoreReachability
4334 //===========================================================================
4335 //
4336 // TRAVEL_WALK 100% equal floor height + steps
4337 // TRAVEL_CROUCH 100%
4338 // TRAVEL_BARRIERJUMP 100%
4339 // TRAVEL_JUMP 80%
4340 // TRAVEL_LADDER 100% + fall down from ladder + jump up to ladder
4341 // TRAVEL_WALKOFFLEDGE 90% walk off very steep walls?
4342 // TRAVEL_SWIM 100%
4343 // TRAVEL_WATERJUMP 100%
4344 // TRAVEL_TELEPORT 100%
4345 // TRAVEL_ELEVATOR 100%
4346 // TRAVEL_GRAPPLEHOOK 100%
4347 // TRAVEL_DOUBLEJUMP 0%
4348 // TRAVEL_RAMPJUMP 0%
4349 // TRAVEL_STRAFEJUMP 0%
4350 // TRAVEL_ROCKETJUMP 100% (currently limited towards areas with items)
4351 // TRAVEL_BFGJUMP 0% (currently disabled)
4352 // TRAVEL_JUMPPAD 100%
4353 // TRAVEL_FUNCBOB 100%
4354 //
4355 // Parameter: -
4356 // Returns: true if NOT finished
4357 // Changes Globals: -
4358 //===========================================================================
4359 int AAS_ContinueInitReachability(float time)
4360 {
4361 int i, j, todo, start_time;
4362 static float framereachability, reachability_delay;
4363 static int lastpercentage;
4364
4365 if (!aasworld.loaded) return qfalse;
4366 //if reachability is calculated for all areas
4367 if (aasworld.numreachabilityareas >= aasworld.numareas + 2) return qfalse;
4368 //if starting with area 1 (area 0 is a dummy)
4369 if (aasworld.numreachabilityareas == 1)
4370 {
4371 botimport.Print(PRT_MESSAGE, "calculating reachability...\n");
4372 lastpercentage = 0;
4373 framereachability = 2000;
4374 reachability_delay = 1000;
4375 } //end if
4376 //number of areas to calculate reachability for this cycle
4377 todo = aasworld.numreachabilityareas + (int) framereachability;
4378 start_time = Sys_MilliSeconds();
4379 //loop over the areas
4380 for (i = aasworld.numreachabilityareas; i < aasworld.numareas && i < todo; i++)
4381 {
4382 aasworld.numreachabilityareas++;
4383 //only create jumppad reachabilities from jumppad areas
4384 if (aasworld.areasettings[i].contents & AREACONTENTS_JUMPPAD)
4385 {
4386 continue;
4387 } //end if
4388 //loop over the areas
4389 for (j = 1; j < aasworld.numareas; j++)
4390 {
4391 if (i == j) continue;
4392 //never create reachabilities from teleporter or jumppad areas to regular areas
4393 if (aasworld.areasettings[i].contents & (AREACONTENTS_TELEPORTER|AREACONTENTS_JUMPPAD))
4394 {
4395 if (!(aasworld.areasettings[j].contents & (AREACONTENTS_TELEPORTER|AREACONTENTS_JUMPPAD)))
4396 {
4397 continue;
4398 } //end if
4399 } //end if
4400 //if there already is a reachability link from area i to j
4401 if (AAS_ReachabilityExists(i, j)) continue;
4402 //check for a swim reachability
4403 if (AAS_Reachability_Swim(i, j)) continue;
4404 //check for a simple walk on equal floor height reachability
4405 if (AAS_Reachability_EqualFloorHeight(i, j)) continue;
4406 //check for step, barrier, waterjump and walk off ledge reachabilities
4407 if (AAS_Reachability_Step_Barrier_WaterJump_WalkOffLedge(i, j)) continue;
4408 //check for ladder reachabilities
4409 if (AAS_Reachability_Ladder(i, j)) continue;
4410 //check for a jump reachability
4411 if (AAS_Reachability_Jump(i, j)) continue;
4412 } //end for
4413 //never create these reachabilities from teleporter or jumppad areas
4414 if (aasworld.areasettings[i].contents & (AREACONTENTS_TELEPORTER|AREACONTENTS_JUMPPAD))
4415 {
4416 continue;
4417 } //end if
4418 //loop over the areas
4419 for (j = 1; j < aasworld.numareas; j++)
4420 {
4421 if (i == j) continue;
4422 //
4423 if (AAS_ReachabilityExists(i, j)) continue;
4424 //check for a grapple hook reachability
4425 if (calcgrapplereach) AAS_Reachability_Grapple(i, j);
4426 //check for a weapon jump reachability
4427 AAS_Reachability_WeaponJump(i, j);
4428 } //end for
4429 //if the calculation took more time than the max reachability delay
4430 if (Sys_MilliSeconds() - start_time > (int) reachability_delay) break;
4431 //
4432 if (aasworld.numreachabilityareas * 1000 / aasworld.numareas > lastpercentage) break;
4433 } //end for
4434 //
4435 if (aasworld.numreachabilityareas == aasworld.numareas)
4436 {
4437 botimport.Print(PRT_MESSAGE, "\r%6.1f%%", (float) 100.0);
4438 botimport.Print(PRT_MESSAGE, "\nplease wait while storing reachability...\n");
4439 aasworld.numreachabilityareas++;
4440 } //end if
4441 //if this is the last step in the reachability calculations
4442 else if (aasworld.numreachabilityareas == aasworld.numareas + 1)
4443 {
4444 //create additional walk off ledge reachabilities for every area
4445 for (i = 1; i < aasworld.numareas; i++)
4446 {
4447 //only create jumppad reachabilities from jumppad areas
4448 if (aasworld.areasettings[i].contents & AREACONTENTS_JUMPPAD)
4449 {
4450 continue;
4451 } //end if
4452 AAS_Reachability_WalkOffLedge(i);
4453 } //end for
4454 //create jump pad reachabilities
4455 AAS_Reachability_JumpPad();
4456 //create teleporter reachabilities
4457 AAS_Reachability_Teleport();
4458 //create elevator (func_plat) reachabilities
4459 AAS_Reachability_Elevator();
4460 //create func_bobbing reachabilities
4461 AAS_Reachability_FuncBobbing();
4462 //
4463 #ifdef DEBUG
4464 botimport.Print(PRT_MESSAGE, "%6d reach swim\n", reach_swim);
4465 botimport.Print(PRT_MESSAGE, "%6d reach equal floor\n", reach_equalfloor);
4466 botimport.Print(PRT_MESSAGE, "%6d reach step\n", reach_step);
4467 botimport.Print(PRT_MESSAGE, "%6d reach barrier\n", reach_barrier);
4468 botimport.Print(PRT_MESSAGE, "%6d reach waterjump\n", reach_waterjump);
4469 botimport.Print(PRT_MESSAGE, "%6d reach walkoffledge\n", reach_walkoffledge);
4470 botimport.Print(PRT_MESSAGE, "%6d reach jump\n", reach_jump);
4471 botimport.Print(PRT_MESSAGE, "%6d reach ladder\n", reach_ladder);
4472 botimport.Print(PRT_MESSAGE, "%6d reach walk\n", reach_walk);
4473 botimport.Print(PRT_MESSAGE, "%6d reach teleport\n", reach_teleport);
4474 botimport.Print(PRT_MESSAGE, "%6d reach funcbob\n", reach_funcbob);
4475 botimport.Print(PRT_MESSAGE, "%6d reach elevator\n", reach_elevator);
4476 botimport.Print(PRT_MESSAGE, "%6d reach grapple\n", reach_grapple);
4477 botimport.Print(PRT_MESSAGE, "%6d reach rocketjump\n", reach_rocketjump);
4478 botimport.Print(PRT_MESSAGE, "%6d reach jumppad\n", reach_jumppad);
4479 #endif
4480 //*/
4481 //store all the reachabilities
4482 AAS_StoreReachability();
4483 //free the reachability link heap
4484 AAS_ShutDownReachabilityHeap();
4485 //
4486 FreeMemory(areareachability);
4487 //
4488 aasworld.numreachabilityareas++;
4489 //
4490 botimport.Print(PRT_MESSAGE, "calculating clusters...\n");
4491 } //end if
4492 else
4493 {
4494 lastpercentage = aasworld.numreachabilityareas * 1000 / aasworld.numareas;
4495 botimport.Print(PRT_MESSAGE, "\r%6.1f%%", (float) lastpercentage / 10);
4496 } //end else
4497 //not yet finished
4498 return qtrue;
4499 } //end of the function AAS_ContinueInitReachability
4500 //===========================================================================
4501 //
4502 // Parameter: -
4503 // Returns: -
4504 // Changes Globals: -
4505 //===========================================================================
4506 void AAS_InitReachability(void)
4507 {
4508 if (!aasworld.loaded) return;
4509
4510 if (aasworld.reachabilitysize)
4511 {
4512 #ifndef BSPC
4513 if (!((int)LibVarGetValue("forcereachability")))
4514 {
4515 aasworld.numreachabilityareas = aasworld.numareas + 2;
4516 return;
4517 } //end if
4518 #else
4519 aasworld.numreachabilityareas = aasworld.numareas + 2;
4520 return;
4521 #endif //BSPC
4522 } //end if
4523 #ifndef BSPC
4524 calcgrapplereach = LibVarGetValue("grapplereach");
4525 #endif
4526 aasworld.savefile = qtrue;
4527 //start with area 1 because area zero is a dummy
4528 aasworld.numreachabilityareas = 1;
4529 ////aasworld.numreachabilityareas = aasworld.numareas + 1; //only calculate entity reachabilities
4530 //setup the heap with reachability links
4531 AAS_SetupReachabilityHeap();
4532 //allocate area reachability link array
4533 areareachability = (aas_lreachability_t **) GetClearedMemory(
4534 aasworld.numareas * sizeof(aas_lreachability_t *));
4535 //
4536 AAS_SetWeaponJumpAreaFlags();
4537 } //end of the function AAS_InitReachable