| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
#include "../qcommon/q_shared.h" |
| 33 |
#include "l_memory.h" |
| 34 |
#include "l_script.h" |
| 35 |
#include "l_precomp.h" |
| 36 |
#include "l_struct.h" |
| 37 |
#include "l_libvar.h" |
| 38 |
#include "aasfile.h" |
| 39 |
#include "botlib.h" |
| 40 |
#include "be_aas.h" |
| 41 |
#include "be_aas_funcs.h" |
| 42 |
#include "be_aas_def.h" |
| 43 |
|
| 44 |
extern botlib_import_t botimport; |
| 45 |
|
| 46 |
aas_settings_t aassettings; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
int AAS_DropToFloor(vec3_t origin, vec3_t mins, vec3_t maxs) |
| 57 |
{ |
| 58 |
vec3_t end; |
| 59 |
bsp_trace_t trace; |
| 60 |
|
| 61 |
VectorCopy(origin, end); |
| 62 |
end[2] -= 100; |
| 63 |
trace = AAS_Trace(origin, mins, maxs, end, 0, CONTENTS_SOLID); |
| 64 |
if (trace.startsolid) return qfalse; |
| 65 |
VectorCopy(trace.endpos, origin); |
| 66 |
return qtrue; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
void AAS_InitSettings(void) |
| 75 |
{ |
| 76 |
aassettings.phys_gravitydirection[0] = 0; |
| 77 |
aassettings.phys_gravitydirection[1] = 0; |
| 78 |
aassettings.phys_gravitydirection[2] = -1; |
| 79 |
aassettings.phys_friction = LibVarValue("phys_friction", "6"); |
| 80 |
aassettings.phys_stopspeed = LibVarValue("phys_stopspeed", "100"); |
| 81 |
aassettings.phys_gravity = LibVarValue("phys_gravity", "800"); |
| 82 |
aassettings.phys_waterfriction = LibVarValue("phys_waterfriction", "1"); |
| 83 |
aassettings.phys_watergravity = LibVarValue("phys_watergravity", "400"); |
| 84 |
aassettings.phys_maxvelocity = LibVarValue("phys_maxvelocity", "320"); |
| 85 |
aassettings.phys_maxwalkvelocity = LibVarValue("phys_maxwalkvelocity", "320"); |
| 86 |
aassettings.phys_maxcrouchvelocity = LibVarValue("phys_maxcrouchvelocity", "100"); |
| 87 |
aassettings.phys_maxswimvelocity = LibVarValue("phys_maxswimvelocity", "150"); |
| 88 |
aassettings.phys_walkaccelerate = LibVarValue("phys_walkaccelerate", "10"); |
| 89 |
aassettings.phys_airaccelerate = LibVarValue("phys_airaccelerate", "1"); |
| 90 |
aassettings.phys_swimaccelerate = LibVarValue("phys_swimaccelerate", "4"); |
| 91 |
aassettings.phys_maxstep = LibVarValue("phys_maxstep", "19"); |
| 92 |
aassettings.phys_maxsteepness = LibVarValue("phys_maxsteepness", "0.7"); |
| 93 |
aassettings.phys_maxwaterjump = LibVarValue("phys_maxwaterjump", "18"); |
| 94 |
aassettings.phys_maxbarrier = LibVarValue("phys_maxbarrier", "33"); |
| 95 |
aassettings.phys_jumpvel = LibVarValue("phys_jumpvel", "270"); |
| 96 |
aassettings.phys_falldelta5 = LibVarValue("phys_falldelta5", "40"); |
| 97 |
aassettings.phys_falldelta10 = LibVarValue("phys_falldelta10", "60"); |
| 98 |
aassettings.rs_waterjump = LibVarValue("rs_waterjump", "400"); |
| 99 |
aassettings.rs_teleport = LibVarValue("rs_teleport", "50"); |
| 100 |
aassettings.rs_barrierjump = LibVarValue("rs_barrierjump", "100"); |
| 101 |
aassettings.rs_startcrouch = LibVarValue("rs_startcrouch", "300"); |
| 102 |
aassettings.rs_startgrapple = LibVarValue("rs_startgrapple", "500"); |
| 103 |
aassettings.rs_startwalkoffledge = LibVarValue("rs_startwalkoffledge", "70"); |
| 104 |
aassettings.rs_startjump = LibVarValue("rs_startjump", "300"); |
| 105 |
aassettings.rs_rocketjump = LibVarValue("rs_rocketjump", "500"); |
| 106 |
aassettings.rs_bfgjump = LibVarValue("rs_bfgjump", "500"); |
| 107 |
aassettings.rs_jumppad = LibVarValue("rs_jumppad", "250"); |
| 108 |
aassettings.rs_aircontrolledjumppad = LibVarValue("rs_aircontrolledjumppad", "300"); |
| 109 |
aassettings.rs_funcbob = LibVarValue("rs_funcbob", "300"); |
| 110 |
aassettings.rs_startelevator = LibVarValue("rs_startelevator", "50"); |
| 111 |
aassettings.rs_falldamage5 = LibVarValue("rs_falldamage5", "300"); |
| 112 |
aassettings.rs_falldamage10 = LibVarValue("rs_falldamage10", "500"); |
| 113 |
aassettings.rs_maxfallheight = LibVarValue("rs_maxfallheight", "0"); |
| 114 |
aassettings.rs_maxjumpfallheight = LibVarValue("rs_maxjumpfallheight", "450"); |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
int AAS_AgainstLadder(vec3_t origin) |
| 124 |
{ |
| 125 |
int areanum, i, facenum, side; |
| 126 |
vec3_t org; |
| 127 |
aas_plane_t *plane; |
| 128 |
aas_face_t *face; |
| 129 |
aas_area_t *area; |
| 130 |
|
| 131 |
VectorCopy(origin, org); |
| 132 |
areanum = AAS_PointAreaNum(org); |
| 133 |
if (!areanum) |
| 134 |
{ |
| 135 |
org[0] += 1; |
| 136 |
areanum = AAS_PointAreaNum(org); |
| 137 |
if (!areanum) |
| 138 |
{ |
| 139 |
org[1] += 1; |
| 140 |
areanum = AAS_PointAreaNum(org); |
| 141 |
if (!areanum) |
| 142 |
{ |
| 143 |
org[0] -= 2; |
| 144 |
areanum = AAS_PointAreaNum(org); |
| 145 |
if (!areanum) |
| 146 |
{ |
| 147 |
org[1] -= 2; |
| 148 |
areanum = AAS_PointAreaNum(org); |
| 149 |
} |
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
if (!areanum) return qfalse; |
| 155 |
|
| 156 |
if (!(aasworld.areasettings[areanum].areaflags & AREA_LADDER)) return qfalse; |
| 157 |
|
| 158 |
if (!(aasworld.areasettings[areanum].presencetype & PRESENCE_NORMAL)) return qfalse; |
| 159 |
|
| 160 |
area = &aasworld.areas[areanum]; |
| 161 |
for (i = 0; i < area->numfaces; i++) |
| 162 |
{ |
| 163 |
facenum = aasworld.faceindex[area->firstface + i]; |
| 164 |
side = facenum < 0; |
| 165 |
face = &aasworld.faces[abs(facenum)]; |
| 166 |
|
| 167 |
if (!(face->faceflags & FACE_LADDER)) continue; |
| 168 |
|
| 169 |
plane = &aasworld.planes[face->planenum ^ side]; |
| 170 |
|
| 171 |
if (fabsf(DotProduct(plane->normal, origin) - plane->dist) < 3) |
| 172 |
{ |
| 173 |
if (AAS_PointInsideFace(abs(facenum), origin, 0.1f)) return qtrue; |
| 174 |
} |
| 175 |
} |
| 176 |
return qfalse; |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
int AAS_OnGround(vec3_t origin, int presencetype, int passent) |
| 186 |
{ |
| 187 |
aas_trace_t trace; |
| 188 |
vec3_t end, up = {0, 0, 1}; |
| 189 |
aas_plane_t *plane; |
| 190 |
|
| 191 |
VectorCopy(origin, end); |
| 192 |
end[2] -= 10; |
| 193 |
|
| 194 |
trace = AAS_TraceClientBBox(origin, end, presencetype, passent); |
| 195 |
|
| 196 |
|
| 197 |
if (trace.startsolid) return qfalse; |
| 198 |
|
| 199 |
if (trace.fraction >= 1.0) return qfalse; |
| 200 |
|
| 201 |
if (origin[2] - trace.endpos[2] > 10) return qfalse; |
| 202 |
|
| 203 |
plane = AAS_PlaneFromNum(trace.planenum); |
| 204 |
if (DotProduct(plane->normal, up) < aassettings.phys_maxsteepness) return qfalse; |
| 205 |
|
| 206 |
return qtrue; |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
int AAS_Swimming(vec3_t origin) |
| 216 |
{ |
| 217 |
vec3_t testorg; |
| 218 |
|
| 219 |
VectorCopy(origin, testorg); |
| 220 |
testorg[2] -= 2; |
| 221 |
if (AAS_PointContents(testorg) & (CONTENTS_LAVA|CONTENTS_SLIME|CONTENTS_WATER)) return qtrue; |
| 222 |
return qfalse; |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
static vec3_t VEC_UP = {0, -1, 0}; |
| 231 |
static vec3_t MOVEDIR_UP = {0, 0, 1}; |
| 232 |
static vec3_t VEC_DOWN = {0, -2, 0}; |
| 233 |
static vec3_t MOVEDIR_DOWN = {0, 0, -1}; |
| 234 |
|
| 235 |
void AAS_SetMovedir(vec3_t angles, vec3_t movedir) |
| 236 |
{ |
| 237 |
if (VectorCompare(angles, VEC_UP)) |
| 238 |
{ |
| 239 |
VectorCopy(MOVEDIR_UP, movedir); |
| 240 |
} |
| 241 |
else if (VectorCompare(angles, VEC_DOWN)) |
| 242 |
{ |
| 243 |
VectorCopy(MOVEDIR_DOWN, movedir); |
| 244 |
} |
| 245 |
else |
| 246 |
{ |
| 247 |
AngleVectors(angles, movedir, NULL, NULL); |
| 248 |
} |
| 249 |
} |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
void AAS_JumpReachRunStart(aas_reachability_t *reach, vec3_t runstart) |
| 257 |
{ |
| 258 |
vec3_t hordir, start, cmdmove; |
| 259 |
aas_clientmove_t move; |
| 260 |
|
| 261 |
|
| 262 |
hordir[0] = reach->start[0] - reach->end[0]; |
| 263 |
hordir[1] = reach->start[1] - reach->end[1]; |
| 264 |
hordir[2] = 0; |
| 265 |
VectorNormalize(hordir); |
| 266 |
|
| 267 |
VectorCopy(reach->start, start); |
| 268 |
start[2] += 1; |
| 269 |
|
| 270 |
VectorScale(hordir, 400, cmdmove); |
| 271 |
|
| 272 |
AAS_PredictClientMovement(&move, -1, start, PRESENCE_NORMAL, qtrue, |
| 273 |
vec3_origin, cmdmove, 1, 2, 0.1f, |
| 274 |
SE_ENTERWATER|SE_ENTERSLIME|SE_ENTERLAVA| |
| 275 |
SE_HITGROUNDDAMAGE|SE_GAP, 0, qfalse); |
| 276 |
VectorCopy(move.endpos, runstart); |
| 277 |
|
| 278 |
if (move.stopevent & (SE_ENTERSLIME|SE_ENTERLAVA|SE_HITGROUNDDAMAGE)) |
| 279 |
{ |
| 280 |
VectorCopy(start, runstart); |
| 281 |
} |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
float AAS_WeaponJumpZVelocity(vec3_t origin, float radiusdamage) |
| 291 |
{ |
| 292 |
vec3_t kvel, v, start, end, forward, right, viewangles, dir; |
| 293 |
float mass, knockback, points; |
| 294 |
vec3_t rocketoffset = {8, 8, -8}; |
| 295 |
vec3_t botmins = {-16, -16, -24}; |
| 296 |
vec3_t botmaxs = {16, 16, 32}; |
| 297 |
bsp_trace_t bsptrace; |
| 298 |
|
| 299 |
|
| 300 |
viewangles[PITCH] = 90; |
| 301 |
viewangles[YAW] = 0; |
| 302 |
viewangles[ROLL] = 0; |
| 303 |
|
| 304 |
VectorCopy(origin, start); |
| 305 |
start[2] += 8; |
| 306 |
AngleVectors(viewangles, forward, right, NULL); |
| 307 |
start[0] += forward[0] * rocketoffset[0] + right[0] * rocketoffset[1]; |
| 308 |
start[1] += forward[1] * rocketoffset[0] + right[1] * rocketoffset[1]; |
| 309 |
start[2] += forward[2] * rocketoffset[0] + right[2] * rocketoffset[1] + rocketoffset[2]; |
| 310 |
|
| 311 |
VectorMA(start, 500, forward, end); |
| 312 |
|
| 313 |
bsptrace = AAS_Trace(start, NULL, NULL, end, 1, CONTENTS_SOLID); |
| 314 |
|
| 315 |
VectorAdd(botmins, botmaxs, v); |
| 316 |
VectorMA(origin, 0.5, v, v); |
| 317 |
VectorSubtract(bsptrace.endpos, v, v); |
| 318 |
|
| 319 |
points = radiusdamage - 0.5 * VectorLength(v); |
| 320 |
if (points < 0) points = 0; |
| 321 |
|
| 322 |
points *= 0.5; |
| 323 |
|
| 324 |
mass = 200; |
| 325 |
|
| 326 |
knockback = points; |
| 327 |
|
| 328 |
VectorSubtract(origin, bsptrace.endpos, dir); |
| 329 |
VectorNormalize(dir); |
| 330 |
|
| 331 |
VectorScale(dir, 1600.0 * (float)knockback / mass, kvel); |
| 332 |
|
| 333 |
return kvel[2] + aassettings.phys_jumpvel; |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
float AAS_RocketJumpZVelocity(vec3_t origin) |
| 342 |
{ |
| 343 |
|
| 344 |
return AAS_WeaponJumpZVelocity(origin, 120); |
| 345 |
} |
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
float AAS_BFGJumpZVelocity(vec3_t origin) |
| 353 |
{ |
| 354 |
|
| 355 |
return AAS_WeaponJumpZVelocity(origin, 120); |
| 356 |
} |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
void AAS_Accelerate(vec3_t velocity, float frametime, vec3_t wishdir, float wishspeed, float accel) |
| 365 |
{ |
| 366 |
|
| 367 |
int i; |
| 368 |
float addspeed, accelspeed, currentspeed; |
| 369 |
|
| 370 |
currentspeed = DotProduct(velocity, wishdir); |
| 371 |
addspeed = wishspeed - currentspeed; |
| 372 |
if (addspeed <= 0) { |
| 373 |
return; |
| 374 |
} |
| 375 |
accelspeed = accel*frametime*wishspeed; |
| 376 |
if (accelspeed > addspeed) { |
| 377 |
accelspeed = addspeed; |
| 378 |
} |
| 379 |
|
| 380 |
for (i=0 ; i<3 ; i++) { |
| 381 |
velocity[i] += accelspeed*wishdir[i]; |
| 382 |
} |
| 383 |
} |
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
void AAS_ApplyFriction(vec3_t vel, float friction, float stopspeed, |
| 392 |
float frametime) |
| 393 |
{ |
| 394 |
float speed, control, newspeed; |
| 395 |
|
| 396 |
|
| 397 |
speed = sqrt(vel[0] * vel[0] + vel[1] * vel[1]); |
| 398 |
if (speed) |
| 399 |
{ |
| 400 |
control = speed < stopspeed ? stopspeed : speed; |
| 401 |
newspeed = speed - frametime * control * friction; |
| 402 |
if (newspeed < 0) newspeed = 0; |
| 403 |
newspeed /= speed; |
| 404 |
vel[0] *= newspeed; |
| 405 |
vel[1] *= newspeed; |
| 406 |
} |
| 407 |
} |
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
int AAS_ClipToBBox(aas_trace_t *trace, vec3_t start, vec3_t end, int presencetype, vec3_t mins, vec3_t maxs) |
| 415 |
{ |
| 416 |
int i, j, side; |
| 417 |
float front, back, frac, planedist; |
| 418 |
vec3_t bboxmins, bboxmaxs, absmins, absmaxs, dir, mid; |
| 419 |
|
| 420 |
AAS_PresenceTypeBoundingBox(presencetype, bboxmins, bboxmaxs); |
| 421 |
VectorSubtract(mins, bboxmaxs, absmins); |
| 422 |
VectorSubtract(maxs, bboxmins, absmaxs); |
| 423 |
|
| 424 |
VectorCopy(end, trace->endpos); |
| 425 |
trace->fraction = 1; |
| 426 |
for (i = 0; i < 3; i++) |
| 427 |
{ |
| 428 |
if (start[i] < absmins[i] && end[i] < absmins[i]) return qfalse; |
| 429 |
if (start[i] > absmaxs[i] && end[i] > absmaxs[i]) return qfalse; |
| 430 |
} |
| 431 |
|
| 432 |
VectorSubtract(end, start, dir); |
| 433 |
frac = 1; |
| 434 |
for (i = 0; i < 3; i++) |
| 435 |
{ |
| 436 |
|
| 437 |
if (dir[i] > 0) planedist = absmins[i]; |
| 438 |
else planedist = absmaxs[i]; |
| 439 |
|
| 440 |
front = start[i] - planedist; |
| 441 |
back = end[i] - planedist; |
| 442 |
frac = front / (front-back); |
| 443 |
|
| 444 |
side = i + 1; |
| 445 |
if (side > 2) side = 0; |
| 446 |
mid[side] = start[side] + dir[side] * frac; |
| 447 |
if (mid[side] > absmins[side] && mid[side] < absmaxs[side]) |
| 448 |
{ |
| 449 |
|
| 450 |
side++; |
| 451 |
if (side > 2) side = 0; |
| 452 |
mid[side] = start[side] + dir[side] * frac; |
| 453 |
if (mid[side] > absmins[side] && mid[side] < absmaxs[side]) |
| 454 |
{ |
| 455 |
mid[i] = planedist; |
| 456 |
break; |
| 457 |
} |
| 458 |
} |
| 459 |
} |
| 460 |
|
| 461 |
if (i != 3) |
| 462 |
{ |
| 463 |
trace->startsolid = qfalse; |
| 464 |
trace->fraction = frac; |
| 465 |
trace->ent = 0; |
| 466 |
trace->planenum = 0; |
| 467 |
trace->area = 0; |
| 468 |
trace->lastarea = 0; |
| 469 |
|
| 470 |
for (j = 0; j < 3; j++) trace->endpos[j] = start[j] + dir[j] * frac; |
| 471 |
return qtrue; |
| 472 |
} |
| 473 |
return qfalse; |
| 474 |
} |
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
int AAS_ClientMovementPrediction(struct aas_clientmove_s *move, |
| 494 |
int entnum, vec3_t origin, |
| 495 |
int presencetype, int onground, |
| 496 |
vec3_t velocity, vec3_t cmdmove, |
| 497 |
int cmdframes, |
| 498 |
int maxframes, float frametime, |
| 499 |
int stopevent, int stopareanum, |
| 500 |
vec3_t mins, vec3_t maxs, int visualize) |
| 501 |
{ |
| 502 |
float phys_friction, phys_stopspeed, phys_gravity, phys_waterfriction; |
| 503 |
float phys_watergravity; |
| 504 |
float phys_walkaccelerate, phys_airaccelerate, phys_swimaccelerate; |
| 505 |
float phys_maxwalkvelocity, phys_maxcrouchvelocity, phys_maxswimvelocity; |
| 506 |
float phys_maxstep, phys_maxsteepness, phys_jumpvel, friction; |
| 507 |
float gravity, delta, maxvel, wishspeed, accelerate; |
| 508 |
|
| 509 |
|
| 510 |
int n, i, j, pc, step, swimming, crouch, event, jump_frame, areanum; |
| 511 |
int areas[20], numareas; |
| 512 |
vec3_t points[20]; |
| 513 |
vec3_t org, end, feet, start, stepend, lastorg, wishdir; |
| 514 |
vec3_t frame_test_vel, old_frame_test_vel, left_test_vel; |
| 515 |
vec3_t up = {0, 0, 1}; |
| 516 |
aas_plane_t *plane, *plane2; |
| 517 |
aas_trace_t trace, steptrace; |
| 518 |
|
| 519 |
if (frametime <= 0) frametime = 0.1f; |
| 520 |
|
| 521 |
phys_friction = aassettings.phys_friction; |
| 522 |
phys_stopspeed = aassettings.phys_stopspeed; |
| 523 |
phys_gravity = aassettings.phys_gravity; |
| 524 |
phys_waterfriction = aassettings.phys_waterfriction; |
| 525 |
phys_watergravity = aassettings.phys_watergravity; |
| 526 |
phys_maxwalkvelocity = aassettings.phys_maxwalkvelocity; |
| 527 |
phys_maxcrouchvelocity = aassettings.phys_maxcrouchvelocity; |
| 528 |
phys_maxswimvelocity = aassettings.phys_maxswimvelocity; |
| 529 |
phys_walkaccelerate = aassettings.phys_walkaccelerate; |
| 530 |
phys_airaccelerate = aassettings.phys_airaccelerate; |
| 531 |
phys_swimaccelerate = aassettings.phys_swimaccelerate; |
| 532 |
phys_maxstep = aassettings.phys_maxstep; |
| 533 |
phys_maxsteepness = aassettings.phys_maxsteepness; |
| 534 |
phys_jumpvel = aassettings.phys_jumpvel * frametime; |
| 535 |
|
| 536 |
Com_Memset(move, 0, sizeof(aas_clientmove_t)); |
| 537 |
Com_Memset(&trace, 0, sizeof(aas_trace_t)); |
| 538 |
|
| 539 |
VectorCopy(origin, org); |
| 540 |
org[2] += 0.25; |
| 541 |
|
| 542 |
VectorScale(velocity, frametime, frame_test_vel); |
| 543 |
|
| 544 |
jump_frame = -1; |
| 545 |
|
| 546 |
for (n = 0; n < maxframes; n++) |
| 547 |
{ |
| 548 |
swimming = AAS_Swimming(org); |
| 549 |
|
| 550 |
gravity = swimming ? phys_watergravity : phys_gravity; |
| 551 |
|
| 552 |
frame_test_vel[2] = frame_test_vel[2] - (gravity * 0.1 * frametime); |
| 553 |
|
| 554 |
if (onground || swimming) |
| 555 |
{ |
| 556 |
friction = swimming ? phys_waterfriction : phys_friction; |
| 557 |
|
| 558 |
VectorScale(frame_test_vel, 1/frametime, frame_test_vel); |
| 559 |
AAS_ApplyFriction(frame_test_vel, friction, phys_stopspeed, frametime); |
| 560 |
VectorScale(frame_test_vel, frametime, frame_test_vel); |
| 561 |
} |
| 562 |
crouch = qfalse; |
| 563 |
|
| 564 |
if (n < cmdframes) |
| 565 |
{ |
| 566 |
|
| 567 |
maxvel = phys_maxwalkvelocity; |
| 568 |
accelerate = phys_airaccelerate; |
| 569 |
VectorCopy(cmdmove, wishdir); |
| 570 |
if (onground) |
| 571 |
{ |
| 572 |
if (cmdmove[2] < -300) |
| 573 |
{ |
| 574 |
crouch = qtrue; |
| 575 |
maxvel = phys_maxcrouchvelocity; |
| 576 |
} |
| 577 |
|
| 578 |
if (!swimming && cmdmove[2] > 1) |
| 579 |
{ |
| 580 |
|
| 581 |
frame_test_vel[2] = phys_jumpvel - (gravity * 0.1 * frametime) + 5; |
| 582 |
jump_frame = n; |
| 583 |
|
| 584 |
accelerate = phys_airaccelerate; |
| 585 |
} |
| 586 |
else |
| 587 |
{ |
| 588 |
accelerate = phys_walkaccelerate; |
| 589 |
} |
| 590 |
|
| 591 |
} |
| 592 |
if (swimming) |
| 593 |
{ |
| 594 |
maxvel = phys_maxswimvelocity; |
| 595 |
accelerate = phys_swimaccelerate; |
| 596 |
|
| 597 |
} |
| 598 |
else |
| 599 |
{ |
| 600 |
wishdir[2] = 0; |
| 601 |
} |
| 602 |
|
| 603 |
wishspeed = VectorNormalize(wishdir); |
| 604 |
if (wishspeed > maxvel) wishspeed = maxvel; |
| 605 |
VectorScale(frame_test_vel, 1/frametime, frame_test_vel); |
| 606 |
AAS_Accelerate(frame_test_vel, frametime, wishdir, wishspeed, accelerate); |
| 607 |
VectorScale(frame_test_vel, frametime, frame_test_vel); |
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
} |
| 622 |
if (crouch) |
| 623 |
{ |
| 624 |
presencetype = PRESENCE_CROUCH; |
| 625 |
} |
| 626 |
else if (presencetype == PRESENCE_CROUCH) |
| 627 |
{ |
| 628 |
if (AAS_PointPresenceType(org) & PRESENCE_NORMAL) |
| 629 |
{ |
| 630 |
presencetype = PRESENCE_NORMAL; |
| 631 |
} |
| 632 |
} |
| 633 |
|
| 634 |
VectorCopy(org, lastorg); |
| 635 |
|
| 636 |
VectorCopy(frame_test_vel, left_test_vel); |
| 637 |
j = 0; |
| 638 |
do |
| 639 |
{ |
| 640 |
VectorAdd(org, left_test_vel, end); |
| 641 |
|
| 642 |
trace = AAS_TraceClientBBox(org, end, presencetype, entnum); |
| 643 |
|
| 644 |
|
| 645 |
if (visualize) |
| 646 |
{ |
| 647 |
if (trace.startsolid) botimport.Print(PRT_MESSAGE, "PredictMovement: start solid\n"); |
| 648 |
AAS_DebugLine(org, trace.endpos, LINECOLOR_RED); |
| 649 |
} |
| 650 |
|
| 651 |
|
| 652 |
if (stopevent & (SE_ENTERAREA|SE_TOUCHJUMPPAD|SE_TOUCHTELEPORTER|SE_TOUCHCLUSTERPORTAL)) |
| 653 |
{ |
| 654 |
numareas = AAS_TraceAreas(org, trace.endpos, areas, points, 20); |
| 655 |
for (i = 0; i < numareas; i++) |
| 656 |
{ |
| 657 |
if (stopevent & SE_ENTERAREA) |
| 658 |
{ |
| 659 |
if (areas[i] == stopareanum) |
| 660 |
{ |
| 661 |
VectorCopy(points[i], move->endpos); |
| 662 |
VectorScale(frame_test_vel, 1/frametime, move->velocity); |
| 663 |
move->endarea = areas[i]; |
| 664 |
move->trace = trace; |
| 665 |
move->stopevent = SE_ENTERAREA; |
| 666 |
move->presencetype = presencetype; |
| 667 |
move->endcontents = 0; |
| 668 |
move->time = n * frametime; |
| 669 |
move->frames = n; |
| 670 |
return qtrue; |
| 671 |
} |
| 672 |
} |
| 673 |
|
| 674 |
if ((stopevent & SE_TOUCHJUMPPAD) && n) |
| 675 |
{ |
| 676 |
if (aasworld.areasettings[areas[i]].contents & AREACONTENTS_JUMPPAD) |
| 677 |
{ |
| 678 |
VectorCopy(points[i], move->endpos); |
| 679 |
VectorScale(frame_test_vel, 1/frametime, move->velocity); |
| 680 |
move->endarea = areas[i]; |
| 681 |
move->trace = trace; |
| 682 |
move->stopevent = SE_TOUCHJUMPPAD; |
| 683 |
move->presencetype = presencetype; |
| 684 |
move->endcontents = 0; |
| 685 |
move->time = n * frametime; |
| 686 |
move->frames = n; |
| 687 |
return qtrue; |
| 688 |
} |
| 689 |
} |
| 690 |
if (stopevent & SE_TOUCHTELEPORTER) |
| 691 |
{ |
| 692 |
if (aasworld.areasettings[areas[i]].contents & AREACONTENTS_TELEPORTER) |
| 693 |
{ |
| 694 |
VectorCopy(points[i], move->endpos); |
| 695 |
move->endarea = areas[i]; |
| 696 |
VectorScale(frame_test_vel, 1/frametime, move->velocity); |
| 697 |
move->trace = trace; |
| 698 |
move->stopevent = SE_TOUCHTELEPORTER; |
| 699 |
move->presencetype = presencetype; |
| 700 |
move->endcontents = 0; |
| 701 |
move->time = n * frametime; |
| 702 |
move->frames = n; |
| 703 |
return qtrue; |
| 704 |
} |
| 705 |
} |
| 706 |
if (stopevent & SE_TOUCHCLUSTERPORTAL) |
| 707 |
{ |
| 708 |
if (aasworld.areasettings[areas[i]].contents & AREACONTENTS_CLUSTERPORTAL) |
| 709 |
{ |
| 710 |
VectorCopy(points[i], move->endpos); |
| 711 |
move->endarea = areas[i]; |
| 712 |
VectorScale(frame_test_vel, 1/frametime, move->velocity); |
| 713 |
move->trace = trace; |
| 714 |
move->stopevent = SE_TOUCHCLUSTERPORTAL; |
| 715 |
move->presencetype = presencetype; |
| 716 |
move->endcontents = 0; |
| 717 |
move->time = n * frametime; |
| 718 |
move->frames = n; |
| 719 |
return qtrue; |
| 720 |
} |
| 721 |
} |
| 722 |
} |
| 723 |
} |
| 724 |
|
| 725 |
if (stopevent & SE_HITBOUNDINGBOX) |
| 726 |
{ |
| 727 |
if (AAS_ClipToBBox(&trace, org, trace.endpos, presencetype, mins, maxs)) |
| 728 |
{ |
| 729 |
VectorCopy(trace.endpos, move->endpos); |
| 730 |
move->endarea = AAS_PointAreaNum(move->endpos); |
| 731 |
VectorScale(frame_test_vel, 1/frametime, move->velocity); |
| 732 |
move->trace = trace; |
| 733 |
move->stopevent = SE_HITBOUNDINGBOX; |
| 734 |
move->presencetype = presencetype; |
| 735 |
move->endcontents = 0; |
| 736 |
move->time = n * frametime; |
| 737 |
move->frames = n; |
| 738 |
return qtrue; |
| 739 |
} |
| 740 |
} |
| 741 |
|
| 742 |
VectorCopy(trace.endpos, org); |
| 743 |
|
| 744 |
if (trace.fraction < 1.0) |
| 745 |
{ |
| 746 |
|
| 747 |
plane = AAS_PlaneFromNum(trace.planenum); |
| 748 |
|
| 749 |
if (stopevent & SE_HITGROUNDAREA) |
| 750 |
{ |
| 751 |
if (DotProduct(plane->normal, up) > phys_maxsteepness) |
| 752 |
{ |
| 753 |
VectorCopy(org, start); |
| 754 |
start[2] += 0.5; |
| 755 |
if (AAS_PointAreaNum(start) == stopareanum) |
| 756 |
{ |
| 757 |
VectorCopy(start, move->endpos); |
| 758 |
move->endarea = stopareanum; |
| 759 |
VectorScale(frame_test_vel, 1/frametime, move->velocity); |
| 760 |
move->trace = trace; |
| 761 |
move->stopevent = SE_HITGROUNDAREA; |
| 762 |
move->presencetype = presencetype; |
| 763 |
move->endcontents = 0; |
| 764 |
move->time = n * frametime; |
| 765 |
move->frames = n; |
| 766 |
return qtrue; |
| 767 |
} |
| 768 |
} |
| 769 |
} |
| 770 |
|
| 771 |
step = qfalse; |
| 772 |
|
| 773 |
if (plane->normal[2] == 0 && (jump_frame < 0 || n - jump_frame > 2)) |
| 774 |
{ |
| 775 |
|
| 776 |
VectorMA(org, -0.25, plane->normal, start); |
| 777 |
VectorCopy(start, stepend); |
| 778 |
start[2] += phys_maxstep; |
| 779 |
steptrace = AAS_TraceClientBBox(start, stepend, presencetype, entnum); |
| 780 |
|
| 781 |
if (!steptrace.startsolid) |
| 782 |
{ |
| 783 |
plane2 = AAS_PlaneFromNum(steptrace.planenum); |
| 784 |
if (DotProduct(plane2->normal, up) > phys_maxsteepness) |
| 785 |
{ |
| 786 |
VectorSubtract(end, steptrace.endpos, left_test_vel); |
| 787 |
left_test_vel[2] = 0; |
| 788 |
frame_test_vel[2] = 0; |
| 789 |
|
| 790 |
if (visualize) |
| 791 |
{ |
| 792 |
if (steptrace.endpos[2] - org[2] > 0.125) |
| 793 |
{ |
| 794 |
VectorCopy(org, start); |
| 795 |
start[2] = steptrace.endpos[2]; |
| 796 |
AAS_DebugLine(org, start, LINECOLOR_BLUE); |
| 797 |
} |
| 798 |
} |
| 799 |
|
| 800 |
org[2] = steptrace.endpos[2]; |
| 801 |
step = qtrue; |
| 802 |
} |
| 803 |
} |
| 804 |
} |
| 805 |
|
| 806 |
if (!step) |
| 807 |
{ |
| 808 |
|
| 809 |
|
| 810 |
VectorMA(left_test_vel, -DotProduct(left_test_vel, plane->normal), |
| 811 |
plane->normal, left_test_vel); |
| 812 |
|
| 813 |
VectorCopy(frame_test_vel, old_frame_test_vel); |
| 814 |
|
| 815 |
|
| 816 |
VectorMA(frame_test_vel, -DotProduct(frame_test_vel, plane->normal), |
| 817 |
plane->normal, frame_test_vel); |
| 818 |
|
| 819 |
if (DotProduct(plane->normal, up) > phys_maxsteepness) |
| 820 |
{ |
| 821 |
onground = qtrue; |
| 822 |
} |
| 823 |
if (stopevent & SE_HITGROUNDDAMAGE) |
| 824 |
{ |
| 825 |
delta = 0; |
| 826 |
if (old_frame_test_vel[2] < 0 && |
| 827 |
frame_test_vel[2] > old_frame_test_vel[2] && |
| 828 |
!onground) |
| 829 |
{ |
| 830 |
delta = old_frame_test_vel[2]; |
| 831 |
} |
| 832 |
else if (onground) |
| 833 |
{ |
| 834 |
delta = frame_test_vel[2] - old_frame_test_vel[2]; |
| 835 |
} |
| 836 |
if (delta) |
| 837 |
{ |
| 838 |
delta = delta * 10; |
| 839 |
delta = delta * delta * 0.0001; |
| 840 |
if (swimming) delta = 0; |
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
if (delta > 40) |
| 848 |
{ |
| 849 |
VectorCopy(org, move->endpos); |
| 850 |
move->endarea = AAS_PointAreaNum(org); |
| 851 |
VectorCopy(frame_test_vel, move->velocity); |
| 852 |
move->trace = trace; |
| 853 |
move->stopevent = SE_HITGROUNDDAMAGE; |
| 854 |
move->presencetype = presencetype; |
| 855 |
move->endcontents = 0; |
| 856 |
move->time = n * frametime; |
| 857 |
move->frames = n; |
| 858 |
return qtrue; |
| 859 |
} |
| 860 |
} |
| 861 |
} |
| 862 |
} |
| 863 |
} |
| 864 |
|
| 865 |
if (++j > 20) return qfalse; |
| 866 |
|
| 867 |
} while(trace.fraction < 1.0); |
| 868 |
|
| 869 |
if (frame_test_vel[2] <= 10) |
| 870 |
{ |
| 871 |
|
| 872 |
VectorCopy(org, feet); |
| 873 |
feet[2] -= 22; |
| 874 |
pc = AAS_PointContents(feet); |
| 875 |
|
| 876 |
event = SE_NONE; |
| 877 |
if (pc & CONTENTS_LAVA) event |= SE_ENTERLAVA; |
| 878 |
if (pc & CONTENTS_SLIME) event |= SE_ENTERSLIME; |
| 879 |
if (pc & CONTENTS_WATER) event |= SE_ENTERWATER; |
| 880 |
|
| 881 |
areanum = AAS_PointAreaNum(org); |
| 882 |
if (aasworld.areasettings[areanum].contents & AREACONTENTS_LAVA) |
| 883 |
event |= SE_ENTERLAVA; |
| 884 |
if (aasworld.areasettings[areanum].contents & AREACONTENTS_SLIME) |
| 885 |
event |= SE_ENTERSLIME; |
| 886 |
if (aasworld.areasettings[areanum].contents & AREACONTENTS_WATER) |
| 887 |
event |= SE_ENTERWATER; |
| 888 |
|
| 889 |
if (event & stopevent) |
| 890 |
{ |
| 891 |
VectorCopy(org, move->endpos); |
| 892 |
move->endarea = areanum; |
| 893 |
VectorScale(frame_test_vel, 1/frametime, move->velocity); |
| 894 |
move->stopevent = event & stopevent; |
| 895 |
move->presencetype = presencetype; |
| 896 |
move->endcontents = pc; |
| 897 |
move->time = n * frametime; |
| 898 |
move->frames = n; |
| 899 |
return qtrue; |
| 900 |
} |
| 901 |
} |
| 902 |
|
| 903 |
onground = AAS_OnGround(org, presencetype, entnum); |
| 904 |
|
| 905 |
if (onground) |
| 906 |
{ |
| 907 |
if (stopevent & SE_HITGROUND) |
| 908 |
{ |
| 909 |
VectorCopy(org, move->endpos); |
| 910 |
move->endarea = AAS_PointAreaNum(org); |
| 911 |
VectorScale(frame_test_vel, 1/frametime, move->velocity); |
| 912 |
move->trace = trace; |
| 913 |
move->stopevent = SE_HITGROUND; |
| 914 |
move->presencetype = presencetype; |
| 915 |
move->endcontents = 0; |
| 916 |
move->time = n * frametime; |
| 917 |
move->frames = n; |
| 918 |
return qtrue; |
| 919 |
} |
| 920 |
} |
| 921 |
else if (stopevent & SE_LEAVEGROUND) |
| 922 |
{ |
| 923 |
VectorCopy(org, move->endpos); |
| 924 |
move->endarea = AAS_PointAreaNum(org); |
| 925 |
VectorScale(frame_test_vel, 1/frametime, move->velocity); |
| 926 |
move->trace = trace; |
| 927 |
move->stopevent = SE_LEAVEGROUND; |
| 928 |
move->presencetype = presencetype; |
| 929 |
move->endcontents = 0; |
| 930 |
move->time = n * frametime; |
| 931 |
move->frames = n; |
| 932 |
return qtrue; |
| 933 |
} |
| 934 |
else if (stopevent & SE_GAP) |
| 935 |
{ |
| 936 |
aas_trace_t gaptrace; |
| 937 |
|
| 938 |
VectorCopy(org, start); |
| 939 |
VectorCopy(start, end); |
| 940 |
end[2] -= 48 + aassettings.phys_maxbarrier; |
| 941 |
gaptrace = AAS_TraceClientBBox(start, end, PRESENCE_CROUCH, -1); |
| 942 |
|
| 943 |
if (!gaptrace.startsolid) |
| 944 |
{ |
| 945 |
|
| 946 |
if (gaptrace.endpos[2] < org[2] - aassettings.phys_maxstep - 1) |
| 947 |
{ |
| 948 |
if (!(AAS_PointContents(end) & CONTENTS_WATER)) |
| 949 |
{ |
| 950 |
VectorCopy(lastorg, move->endpos); |
| 951 |
move->endarea = AAS_PointAreaNum(lastorg); |
| 952 |
VectorScale(frame_test_vel, 1/frametime, move->velocity); |
| 953 |
move->trace = trace; |
| 954 |
move->stopevent = SE_GAP; |
| 955 |
move->presencetype = presencetype; |
| 956 |
move->endcontents = 0; |
| 957 |
move->time = n * frametime; |
| 958 |
move->frames = n; |
| 959 |
return qtrue; |
| 960 |
} |
| 961 |
} |
| 962 |
} |
| 963 |
} |
| 964 |
} |
| 965 |
|
| 966 |
VectorCopy(org, move->endpos); |
| 967 |
move->endarea = AAS_PointAreaNum(org); |
| 968 |
VectorScale(frame_test_vel, 1/frametime, move->velocity); |
| 969 |
move->stopevent = SE_NONE; |
| 970 |
move->presencetype = presencetype; |
| 971 |
move->endcontents = 0; |
| 972 |
move->time = n * frametime; |
| 973 |
move->frames = n; |
| 974 |
|
| 975 |
return qtrue; |
| 976 |
} |
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
int AAS_PredictClientMovement(struct aas_clientmove_s *move, |
| 984 |
int entnum, vec3_t origin, |
| 985 |
int presencetype, int onground, |
| 986 |
vec3_t velocity, vec3_t cmdmove, |
| 987 |
int cmdframes, |
| 988 |
int maxframes, float frametime, |
| 989 |
int stopevent, int stopareanum, int visualize) |
| 990 |
{ |
| 991 |
vec3_t mins, maxs; |
| 992 |
return AAS_ClientMovementPrediction(move, entnum, origin, presencetype, onground, |
| 993 |
velocity, cmdmove, cmdframes, maxframes, |
| 994 |
frametime, stopevent, stopareanum, |
| 995 |
mins, maxs, visualize); |
| 996 |
} |
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
int AAS_ClientMovementHitBBox(struct aas_clientmove_s *move, |
| 1004 |
int entnum, vec3_t origin, |
| 1005 |
int presencetype, int onground, |
| 1006 |
vec3_t velocity, vec3_t cmdmove, |
| 1007 |
int cmdframes, |
| 1008 |
int maxframes, float frametime, |
| 1009 |
vec3_t mins, vec3_t maxs, int visualize) |
| 1010 |
{ |
| 1011 |
return AAS_ClientMovementPrediction(move, entnum, origin, presencetype, onground, |
| 1012 |
velocity, cmdmove, cmdframes, maxframes, |
| 1013 |
frametime, SE_HITBOUNDINGBOX, 0, |
| 1014 |
mins, maxs, visualize); |
| 1015 |
} |
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
void AAS_TestMovementPrediction(int entnum, vec3_t origin, vec3_t dir) |
| 1023 |
{ |
| 1024 |
vec3_t velocity, cmdmove; |
| 1025 |
aas_clientmove_t move; |
| 1026 |
|
| 1027 |
VectorClear(velocity); |
| 1028 |
if (!AAS_Swimming(origin)) dir[2] = 0; |
| 1029 |
VectorNormalize(dir); |
| 1030 |
VectorScale(dir, 400, cmdmove); |
| 1031 |
cmdmove[2] = 224; |
| 1032 |
AAS_ClearShownDebugLines(); |
| 1033 |
AAS_PredictClientMovement(&move, entnum, origin, PRESENCE_NORMAL, qtrue, |
| 1034 |
velocity, cmdmove, 13, 13, 0.1f, SE_HITGROUND, 0, qtrue); |
| 1035 |
if (move.stopevent & SE_LEAVEGROUND) |
| 1036 |
{ |
| 1037 |
botimport.Print(PRT_MESSAGE, "leave ground\n"); |
| 1038 |
} |
| 1039 |
} |
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
int AAS_HorizontalVelocityForJump(float zvel, vec3_t start, vec3_t end, float *velocity) |
| 1052 |
{ |
| 1053 |
float phys_gravity, phys_maxvelocity; |
| 1054 |
float maxjump, height2fall, t, top; |
| 1055 |
vec3_t dir; |
| 1056 |
|
| 1057 |
phys_gravity = aassettings.phys_gravity; |
| 1058 |
phys_maxvelocity = aassettings.phys_maxvelocity; |
| 1059 |
|
| 1060 |
|
| 1061 |
maxjump = 0.5 * phys_gravity * (zvel / phys_gravity) * (zvel / phys_gravity); |
| 1062 |
|
| 1063 |
top = start[2] + maxjump; |
| 1064 |
|
| 1065 |
height2fall = top - end[2]; |
| 1066 |
|
| 1067 |
if (height2fall < 0) |
| 1068 |
{ |
| 1069 |
*velocity = phys_maxvelocity; |
| 1070 |
return 0; |
| 1071 |
} |
| 1072 |
|
| 1073 |
t = sqrt(height2fall / (0.5 * phys_gravity)); |
| 1074 |
|
| 1075 |
VectorSubtract(end, start, dir); |
| 1076 |
|
| 1077 |
if ( (t + zvel / phys_gravity) == 0.0f ) { |
| 1078 |
*velocity = phys_maxvelocity; |
| 1079 |
return 0; |
| 1080 |
} |
| 1081 |
|
| 1082 |
*velocity = sqrt(dir[0]*dir[0] + dir[1]*dir[1]) / (t + zvel / phys_gravity); |
| 1083 |
|
| 1084 |
if (*velocity > phys_maxvelocity) |
| 1085 |
{ |
| 1086 |
*velocity = phys_maxvelocity; |
| 1087 |
return 0; |
| 1088 |
} |
| 1089 |
return 1; |
| 1090 |
} |