| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#include "g_local.h" |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
typedef struct { |
| 37 |
gentity_t *ent; |
| 38 |
vec3_t origin; |
| 39 |
vec3_t angles; |
| 40 |
float deltayaw; |
| 41 |
} pushed_t; |
| 42 |
pushed_t pushed[MAX_GENTITIES], *pushed_p; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
gentity_t *G_TestEntityPosition( gentity_t *ent ) { |
| 52 |
trace_t tr; |
| 53 |
int mask; |
| 54 |
|
| 55 |
if ( ent->clipmask ) { |
| 56 |
mask = ent->clipmask; |
| 57 |
} else { |
| 58 |
mask = MASK_SOLID; |
| 59 |
} |
| 60 |
if ( ent->client ) { |
| 61 |
trap_Trace( &tr, ent->client->ps.origin, ent->r.mins, ent->r.maxs, ent->client->ps.origin, ent->s.number, mask ); |
| 62 |
} else { |
| 63 |
trap_Trace( &tr, ent->s.pos.trBase, ent->r.mins, ent->r.maxs, ent->s.pos.trBase, ent->s.number, mask ); |
| 64 |
} |
| 65 |
|
| 66 |
if (tr.startsolid) |
| 67 |
return &g_entities[ tr.entityNum ]; |
| 68 |
|
| 69 |
return NULL; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
void G_CreateRotationMatrix(vec3_t angles, vec3_t matrix[3]) { |
| 78 |
AngleVectors(angles, matrix[0], matrix[1], matrix[2]); |
| 79 |
VectorInverse(matrix[1]); |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
void G_TransposeMatrix(vec3_t matrix[3], vec3_t transpose[3]) { |
| 88 |
int i, j; |
| 89 |
for (i = 0; i < 3; i++) { |
| 90 |
for (j = 0; j < 3; j++) { |
| 91 |
transpose[i][j] = matrix[j][i]; |
| 92 |
} |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
void G_RotatePoint(vec3_t point, vec3_t matrix[3]) { |
| 102 |
vec3_t tvec; |
| 103 |
|
| 104 |
VectorCopy(point, tvec); |
| 105 |
point[0] = DotProduct(matrix[0], tvec); |
| 106 |
point[1] = DotProduct(matrix[1], tvec); |
| 107 |
point[2] = DotProduct(matrix[2], tvec); |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
qboolean G_TryPushingEntity( gentity_t *check, gentity_t *pusher, vec3_t move, vec3_t amove ) { |
| 118 |
vec3_t matrix[3], transpose[3]; |
| 119 |
vec3_t org, org2, move2; |
| 120 |
gentity_t *block; |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
if ( ( pusher->s.eFlags & EF_MOVER_STOP ) && |
| 125 |
check->s.groundEntityNum != pusher->s.number ) { |
| 126 |
return qfalse; |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
if (pushed_p > &pushed[MAX_GENTITIES]) { |
| 131 |
G_Error( "pushed_p > &pushed[MAX_GENTITIES]" ); |
| 132 |
} |
| 133 |
pushed_p->ent = check; |
| 134 |
VectorCopy (check->s.pos.trBase, pushed_p->origin); |
| 135 |
VectorCopy (check->s.apos.trBase, pushed_p->angles); |
| 136 |
if ( check->client ) { |
| 137 |
pushed_p->deltayaw = check->client->ps.delta_angles[YAW]; |
| 138 |
VectorCopy (check->client->ps.origin, pushed_p->origin); |
| 139 |
} |
| 140 |
pushed_p++; |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
G_CreateRotationMatrix( amove, transpose ); |
| 145 |
G_TransposeMatrix( transpose, matrix ); |
| 146 |
if ( check->client ) { |
| 147 |
VectorSubtract (check->client->ps.origin, pusher->r.currentOrigin, org); |
| 148 |
} |
| 149 |
else { |
| 150 |
VectorSubtract (check->s.pos.trBase, pusher->r.currentOrigin, org); |
| 151 |
} |
| 152 |
VectorCopy( org, org2 ); |
| 153 |
G_RotatePoint( org2, matrix ); |
| 154 |
VectorSubtract (org2, org, move2); |
| 155 |
|
| 156 |
VectorAdd (check->s.pos.trBase, move, check->s.pos.trBase); |
| 157 |
VectorAdd (check->s.pos.trBase, move2, check->s.pos.trBase); |
| 158 |
if ( check->client ) { |
| 159 |
VectorAdd (check->client->ps.origin, move, check->client->ps.origin); |
| 160 |
VectorAdd (check->client->ps.origin, move2, check->client->ps.origin); |
| 161 |
|
| 162 |
check->client->ps.delta_angles[YAW] += ANGLE2SHORT(amove[YAW]); |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
if ( check->s.groundEntityNum != pusher->s.number ) { |
| 167 |
check->s.groundEntityNum = ENTITYNUM_NONE; |
| 168 |
} |
| 169 |
|
| 170 |
block = G_TestEntityPosition( check ); |
| 171 |
if (!block) { |
| 172 |
|
| 173 |
if ( check->client ) { |
| 174 |
VectorCopy( check->client->ps.origin, check->r.currentOrigin ); |
| 175 |
} else { |
| 176 |
VectorCopy( check->s.pos.trBase, check->r.currentOrigin ); |
| 177 |
} |
| 178 |
trap_LinkEntity (check); |
| 179 |
return qtrue; |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
VectorCopy( (pushed_p-1)->origin, check->s.pos.trBase); |
| 186 |
if ( check->client ) { |
| 187 |
VectorCopy( (pushed_p-1)->origin, check->client->ps.origin); |
| 188 |
} |
| 189 |
VectorCopy( (pushed_p-1)->angles, check->s.apos.trBase ); |
| 190 |
block = G_TestEntityPosition (check); |
| 191 |
if ( !block ) { |
| 192 |
check->s.groundEntityNum = ENTITYNUM_NONE; |
| 193 |
pushed_p--; |
| 194 |
return qtrue; |
| 195 |
} |
| 196 |
|
| 197 |
|
| 198 |
return qfalse; |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
qboolean G_CheckProxMinePosition( gentity_t *check ) { |
| 207 |
vec3_t start, end; |
| 208 |
trace_t tr; |
| 209 |
|
| 210 |
VectorMA(check->s.pos.trBase, 0.125, check->movedir, start); |
| 211 |
VectorMA(check->s.pos.trBase, 2, check->movedir, end); |
| 212 |
trap_Trace( &tr, start, NULL, NULL, end, check->s.number, MASK_SOLID ); |
| 213 |
|
| 214 |
if (tr.startsolid || tr.fraction < 1) |
| 215 |
return qfalse; |
| 216 |
|
| 217 |
return qtrue; |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
qboolean G_TryPushingProxMine( gentity_t *check, gentity_t *pusher, vec3_t move, vec3_t amove ) { |
| 226 |
vec3_t forward, right, up; |
| 227 |
vec3_t org, org2, move2; |
| 228 |
int ret; |
| 229 |
|
| 230 |
|
| 231 |
VectorSubtract (vec3_origin, amove, org); |
| 232 |
AngleVectors (org, forward, right, up); |
| 233 |
|
| 234 |
|
| 235 |
VectorAdd (check->s.pos.trBase, move, check->s.pos.trBase); |
| 236 |
|
| 237 |
|
| 238 |
VectorSubtract (check->s.pos.trBase, pusher->r.currentOrigin, org); |
| 239 |
org2[0] = DotProduct (org, forward); |
| 240 |
org2[1] = -DotProduct (org, right); |
| 241 |
org2[2] = DotProduct (org, up); |
| 242 |
VectorSubtract (org2, org, move2); |
| 243 |
VectorAdd (check->s.pos.trBase, move2, check->s.pos.trBase); |
| 244 |
|
| 245 |
ret = G_CheckProxMinePosition( check ); |
| 246 |
if (ret) { |
| 247 |
VectorCopy( check->s.pos.trBase, check->r.currentOrigin ); |
| 248 |
trap_LinkEntity (check); |
| 249 |
} |
| 250 |
return ret; |
| 251 |
} |
| 252 |
|
| 253 |
void G_ExplodeMissile( gentity_t *ent ); |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
qboolean G_MoverPush( gentity_t *pusher, vec3_t move, vec3_t amove, gentity_t **obstacle ) { |
| 265 |
int i, e; |
| 266 |
gentity_t *check; |
| 267 |
vec3_t mins, maxs; |
| 268 |
pushed_t *p; |
| 269 |
int entityList[MAX_GENTITIES]; |
| 270 |
int listedEntities; |
| 271 |
vec3_t totalMins, totalMaxs; |
| 272 |
|
| 273 |
*obstacle = NULL; |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
if ( pusher->r.currentAngles[0] || pusher->r.currentAngles[1] || pusher->r.currentAngles[2] |
| 279 |
|| amove[0] || amove[1] || amove[2] ) { |
| 280 |
float radius; |
| 281 |
|
| 282 |
radius = RadiusFromBounds( pusher->r.mins, pusher->r.maxs ); |
| 283 |
for ( i = 0 ; i < 3 ; i++ ) { |
| 284 |
mins[i] = pusher->r.currentOrigin[i] + move[i] - radius; |
| 285 |
maxs[i] = pusher->r.currentOrigin[i] + move[i] + radius; |
| 286 |
totalMins[i] = mins[i] - move[i]; |
| 287 |
totalMaxs[i] = maxs[i] - move[i]; |
| 288 |
} |
| 289 |
} else { |
| 290 |
for (i=0 ; i<3 ; i++) { |
| 291 |
mins[i] = pusher->r.absmin[i] + move[i]; |
| 292 |
maxs[i] = pusher->r.absmax[i] + move[i]; |
| 293 |
} |
| 294 |
|
| 295 |
VectorCopy( pusher->r.absmin, totalMins ); |
| 296 |
VectorCopy( pusher->r.absmax, totalMaxs ); |
| 297 |
for (i=0 ; i<3 ; i++) { |
| 298 |
if ( move[i] > 0 ) { |
| 299 |
totalMaxs[i] += move[i]; |
| 300 |
} else { |
| 301 |
totalMins[i] += move[i]; |
| 302 |
} |
| 303 |
} |
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
trap_UnlinkEntity( pusher ); |
| 308 |
|
| 309 |
listedEntities = trap_EntitiesInBox( totalMins, totalMaxs, entityList, MAX_GENTITIES ); |
| 310 |
|
| 311 |
|
| 312 |
VectorAdd( pusher->r.currentOrigin, move, pusher->r.currentOrigin ); |
| 313 |
VectorAdd( pusher->r.currentAngles, amove, pusher->r.currentAngles ); |
| 314 |
trap_LinkEntity( pusher ); |
| 315 |
|
| 316 |
|
| 317 |
for ( e = 0 ; e < listedEntities ; e++ ) { |
| 318 |
check = &g_entities[ entityList[ e ] ]; |
| 319 |
|
| 320 |
#ifdef MISSIONPACK |
| 321 |
if ( check->s.eType == ET_MISSILE ) { |
| 322 |
|
| 323 |
if ( !strcmp(check->classname, "prox mine") ) { |
| 324 |
|
| 325 |
if ( check->enemy == pusher ) { |
| 326 |
if (!G_TryPushingProxMine( check, pusher, move, amove )) { |
| 327 |
|
| 328 |
check->s.loopSound = 0; |
| 329 |
G_AddEvent( check, EV_PROXIMITY_MINE_TRIGGER, 0 ); |
| 330 |
G_ExplodeMissile(check); |
| 331 |
if (check->activator) { |
| 332 |
G_FreeEntity(check->activator); |
| 333 |
check->activator = NULL; |
| 334 |
} |
| 335 |
|
| 336 |
} |
| 337 |
} |
| 338 |
else { |
| 339 |
|
| 340 |
if (!G_CheckProxMinePosition( check )) { |
| 341 |
|
| 342 |
check->s.loopSound = 0; |
| 343 |
G_AddEvent( check, EV_PROXIMITY_MINE_TRIGGER, 0 ); |
| 344 |
G_ExplodeMissile(check); |
| 345 |
if (check->activator) { |
| 346 |
G_FreeEntity(check->activator); |
| 347 |
check->activator = NULL; |
| 348 |
} |
| 349 |
|
| 350 |
} |
| 351 |
} |
| 352 |
continue; |
| 353 |
} |
| 354 |
} |
| 355 |
#endif |
| 356 |
|
| 357 |
if ( check->s.eType != ET_ITEM && check->s.eType != ET_PLAYER && !check->physicsObject ) { |
| 358 |
continue; |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
if ( check->s.groundEntityNum != pusher->s.number ) { |
| 363 |
|
| 364 |
if ( check->r.absmin[0] >= maxs[0] |
| 365 |
|| check->r.absmin[1] >= maxs[1] |
| 366 |
|| check->r.absmin[2] >= maxs[2] |
| 367 |
|| check->r.absmax[0] <= mins[0] |
| 368 |
|| check->r.absmax[1] <= mins[1] |
| 369 |
|| check->r.absmax[2] <= mins[2] ) { |
| 370 |
continue; |
| 371 |
} |
| 372 |
|
| 373 |
|
| 374 |
if (!G_TestEntityPosition (check)) { |
| 375 |
continue; |
| 376 |
} |
| 377 |
} |
| 378 |
|
| 379 |
|
| 380 |
if ( G_TryPushingEntity( check, pusher, move, amove ) ) { |
| 381 |
continue; |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
if ( pusher->s.pos.trType == TR_SINE || pusher->s.apos.trType == TR_SINE ) { |
| 388 |
G_Damage( check, pusher, pusher, NULL, NULL, 99999, 0, MOD_CRUSH ); |
| 389 |
continue; |
| 390 |
} |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
*obstacle = check; |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
for ( p=pushed_p-1 ; p>=pushed ; p-- ) { |
| 400 |
VectorCopy (p->origin, p->ent->s.pos.trBase); |
| 401 |
VectorCopy (p->angles, p->ent->s.apos.trBase); |
| 402 |
if ( p->ent->client ) { |
| 403 |
p->ent->client->ps.delta_angles[YAW] = p->deltayaw; |
| 404 |
VectorCopy (p->origin, p->ent->client->ps.origin); |
| 405 |
} |
| 406 |
trap_LinkEntity (p->ent); |
| 407 |
} |
| 408 |
return qfalse; |
| 409 |
} |
| 410 |
|
| 411 |
return qtrue; |
| 412 |
} |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
void G_MoverTeam( gentity_t *ent ) { |
| 421 |
vec3_t move, amove; |
| 422 |
gentity_t *part, *obstacle; |
| 423 |
vec3_t origin, angles; |
| 424 |
|
| 425 |
obstacle = NULL; |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
pushed_p = pushed; |
| 431 |
for (part = ent ; part ; part=part->teamchain) { |
| 432 |
|
| 433 |
BG_EvaluateTrajectory( &part->s.pos, level.time, origin ); |
| 434 |
BG_EvaluateTrajectory( &part->s.apos, level.time, angles ); |
| 435 |
VectorSubtract( origin, part->r.currentOrigin, move ); |
| 436 |
VectorSubtract( angles, part->r.currentAngles, amove ); |
| 437 |
if ( !G_MoverPush( part, move, amove, &obstacle ) ) { |
| 438 |
break; |
| 439 |
} |
| 440 |
} |
| 441 |
|
| 442 |
if (part) { |
| 443 |
|
| 444 |
for ( part = ent ; part ; part = part->teamchain ) { |
| 445 |
part->s.pos.trTime += level.time - level.previousTime; |
| 446 |
part->s.apos.trTime += level.time - level.previousTime; |
| 447 |
BG_EvaluateTrajectory( &part->s.pos, level.time, part->r.currentOrigin ); |
| 448 |
BG_EvaluateTrajectory( &part->s.apos, level.time, part->r.currentAngles ); |
| 449 |
trap_LinkEntity( part ); |
| 450 |
} |
| 451 |
|
| 452 |
|
| 453 |
if (ent->blocked) { |
| 454 |
ent->blocked( ent, obstacle ); |
| 455 |
} |
| 456 |
return; |
| 457 |
} |
| 458 |
|
| 459 |
|
| 460 |
for ( part = ent ; part ; part = part->teamchain ) { |
| 461 |
|
| 462 |
if ( part->s.pos.trType == TR_LINEAR_STOP ) { |
| 463 |
if ( level.time >= part->s.pos.trTime + part->s.pos.trDuration ) { |
| 464 |
if ( part->reached ) { |
| 465 |
part->reached( part ); |
| 466 |
} |
| 467 |
} |
| 468 |
} |
| 469 |
} |
| 470 |
} |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
void G_RunMover( gentity_t *ent ) { |
| 479 |
|
| 480 |
|
| 481 |
if ( ent->flags & FL_TEAMMEMBER ) { |
| 482 |
return; |
| 483 |
} |
| 484 |
|
| 485 |
|
| 486 |
if ( ent->s.pos.trType != TR_STATIONARY || ent->s.apos.trType != TR_STATIONARY ) { |
| 487 |
G_MoverTeam( ent ); |
| 488 |
} |
| 489 |
|
| 490 |
|
| 491 |
G_RunThink( ent ); |
| 492 |
} |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
void SetMoverState( gentity_t *ent, moverState_t moverState, int time ) { |
| 510 |
vec3_t delta; |
| 511 |
float f; |
| 512 |
|
| 513 |
ent->moverState = moverState; |
| 514 |
|
| 515 |
ent->s.pos.trTime = time; |
| 516 |
switch( moverState ) { |
| 517 |
case MOVER_POS1: |
| 518 |
VectorCopy( ent->pos1, ent->s.pos.trBase ); |
| 519 |
ent->s.pos.trType = TR_STATIONARY; |
| 520 |
break; |
| 521 |
case MOVER_POS2: |
| 522 |
VectorCopy( ent->pos2, ent->s.pos.trBase ); |
| 523 |
ent->s.pos.trType = TR_STATIONARY; |
| 524 |
break; |
| 525 |
case MOVER_1TO2: |
| 526 |
VectorCopy( ent->pos1, ent->s.pos.trBase ); |
| 527 |
VectorSubtract( ent->pos2, ent->pos1, delta ); |
| 528 |
f = 1000.0 / ent->s.pos.trDuration; |
| 529 |
VectorScale( delta, f, ent->s.pos.trDelta ); |
| 530 |
ent->s.pos.trType = TR_LINEAR_STOP; |
| 531 |
break; |
| 532 |
case MOVER_2TO1: |
| 533 |
VectorCopy( ent->pos2, ent->s.pos.trBase ); |
| 534 |
VectorSubtract( ent->pos1, ent->pos2, delta ); |
| 535 |
f = 1000.0 / ent->s.pos.trDuration; |
| 536 |
VectorScale( delta, f, ent->s.pos.trDelta ); |
| 537 |
ent->s.pos.trType = TR_LINEAR_STOP; |
| 538 |
break; |
| 539 |
} |
| 540 |
BG_EvaluateTrajectory( &ent->s.pos, level.time, ent->r.currentOrigin ); |
| 541 |
trap_LinkEntity( ent ); |
| 542 |
} |
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
void MatchTeam( gentity_t *teamLeader, int moverState, int time ) { |
| 553 |
gentity_t *member; |
| 554 |
|
| 555 |
for ( member = teamLeader ; member ; member = member->teamchain ) { |
| 556 |
SetMoverState( member, moverState, time ); |
| 557 |
} |
| 558 |
} |
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
void ReturnToPos1( gentity_t *ent ) { |
| 568 |
MatchTeam( ent, MOVER_2TO1, level.time ); |
| 569 |
|
| 570 |
|
| 571 |
ent->s.loopSound = ent->soundLoop; |
| 572 |
|
| 573 |
|
| 574 |
if ( ent->sound2to1 ) { |
| 575 |
G_AddEvent( ent, EV_GENERAL_SOUND, ent->sound2to1 ); |
| 576 |
} |
| 577 |
} |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
void Reached_BinaryMover( gentity_t *ent ) { |
| 586 |
|
| 587 |
|
| 588 |
ent->s.loopSound = ent->soundLoop; |
| 589 |
|
| 590 |
if ( ent->moverState == MOVER_1TO2 ) { |
| 591 |
|
| 592 |
SetMoverState( ent, MOVER_POS2, level.time ); |
| 593 |
|
| 594 |
|
| 595 |
if ( ent->soundPos2 ) { |
| 596 |
G_AddEvent( ent, EV_GENERAL_SOUND, ent->soundPos2 ); |
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
ent->think = ReturnToPos1; |
| 601 |
ent->nextthink = level.time + ent->wait; |
| 602 |
|
| 603 |
|
| 604 |
if ( !ent->activator ) { |
| 605 |
ent->activator = ent; |
| 606 |
} |
| 607 |
G_UseTargets( ent, ent->activator ); |
| 608 |
} else if ( ent->moverState == MOVER_2TO1 ) { |
| 609 |
|
| 610 |
SetMoverState( ent, MOVER_POS1, level.time ); |
| 611 |
|
| 612 |
|
| 613 |
if ( ent->soundPos1 ) { |
| 614 |
G_AddEvent( ent, EV_GENERAL_SOUND, ent->soundPos1 ); |
| 615 |
} |
| 616 |
|
| 617 |
|
| 618 |
if ( ent->teammaster == ent || !ent->teammaster ) { |
| 619 |
trap_AdjustAreaPortalState( ent, qfalse ); |
| 620 |
} |
| 621 |
} else { |
| 622 |
G_Error( "Reached_BinaryMover: bad moverState" ); |
| 623 |
} |
| 624 |
} |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
void Use_BinaryMover( gentity_t *ent, gentity_t *other, gentity_t *activator ) { |
| 633 |
int total; |
| 634 |
int partial; |
| 635 |
|
| 636 |
|
| 637 |
if ( ent->flags & FL_TEAMMEMBER ) { |
| 638 |
Use_BinaryMover( ent->teammaster, other, activator ); |
| 639 |
return; |
| 640 |
} |
| 641 |
|
| 642 |
ent->activator = activator; |
| 643 |
|
| 644 |
if ( ent->moverState == MOVER_POS1 ) { |
| 645 |
|
| 646 |
|
| 647 |
MatchTeam( ent, MOVER_1TO2, level.time + 50 ); |
| 648 |
|
| 649 |
|
| 650 |
if ( ent->sound1to2 ) { |
| 651 |
G_AddEvent( ent, EV_GENERAL_SOUND, ent->sound1to2 ); |
| 652 |
} |
| 653 |
|
| 654 |
|
| 655 |
ent->s.loopSound = ent->soundLoop; |
| 656 |
|
| 657 |
|
| 658 |
if ( ent->teammaster == ent || !ent->teammaster ) { |
| 659 |
trap_AdjustAreaPortalState( ent, qtrue ); |
| 660 |
} |
| 661 |
return; |
| 662 |
} |
| 663 |
|
| 664 |
|
| 665 |
if ( ent->moverState == MOVER_POS2 ) { |
| 666 |
ent->nextthink = level.time + ent->wait; |
| 667 |
return; |
| 668 |
} |
| 669 |
|
| 670 |
|
| 671 |
if ( ent->moverState == MOVER_2TO1 ) { |
| 672 |
total = ent->s.pos.trDuration; |
| 673 |
partial = level.time - ent->s.pos.trTime; |
| 674 |
if ( partial > total ) { |
| 675 |
partial = total; |
| 676 |
} |
| 677 |
|
| 678 |
MatchTeam( ent, MOVER_1TO2, level.time - ( total - partial ) ); |
| 679 |
|
| 680 |
if ( ent->sound1to2 ) { |
| 681 |
G_AddEvent( ent, EV_GENERAL_SOUND, ent->sound1to2 ); |
| 682 |
} |
| 683 |
return; |
| 684 |
} |
| 685 |
|
| 686 |
|
| 687 |
if ( ent->moverState == MOVER_1TO2 ) { |
| 688 |
total = ent->s.pos.trDuration; |
| 689 |
partial = level.time - ent->s.pos.trTime; |
| 690 |
if ( partial > total ) { |
| 691 |
partial = total; |
| 692 |
} |
| 693 |
|
| 694 |
MatchTeam( ent, MOVER_2TO1, level.time - ( total - partial ) ); |
| 695 |
|
| 696 |
if ( ent->sound2to1 ) { |
| 697 |
G_AddEvent( ent, EV_GENERAL_SOUND, ent->sound2to1 ); |
| 698 |
} |
| 699 |
return; |
| 700 |
} |
| 701 |
} |
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
void InitMover( gentity_t *ent ) { |
| 714 |
vec3_t move; |
| 715 |
float distance; |
| 716 |
float light; |
| 717 |
vec3_t color; |
| 718 |
qboolean lightSet, colorSet; |
| 719 |
char *sound; |
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
if ( ent->model2 ) { |
| 724 |
ent->s.modelindex2 = G_ModelIndex( ent->model2 ); |
| 725 |
} |
| 726 |
|
| 727 |
|
| 728 |
if ( G_SpawnString( "noise", "100", &sound ) ) { |
| 729 |
ent->s.loopSound = G_SoundIndex( sound ); |
| 730 |
} |
| 731 |
|
| 732 |
|
| 733 |
lightSet = G_SpawnFloat( "light", "100", &light ); |
| 734 |
colorSet = G_SpawnVector( "color", "1 1 1", color ); |
| 735 |
if ( lightSet || colorSet ) { |
| 736 |
int r, g, b, i; |
| 737 |
|
| 738 |
r = color[0] * 255; |
| 739 |
if ( r > 255 ) { |
| 740 |
r = 255; |
| 741 |
} |
| 742 |
g = color[1] * 255; |
| 743 |
if ( g > 255 ) { |
| 744 |
g = 255; |
| 745 |
} |
| 746 |
b = color[2] * 255; |
| 747 |
if ( b > 255 ) { |
| 748 |
b = 255; |
| 749 |
} |
| 750 |
i = light / 4; |
| 751 |
if ( i > 255 ) { |
| 752 |
i = 255; |
| 753 |
} |
| 754 |
ent->s.constantLight = r | ( g << 8 ) | ( b << 16 ) | ( i << 24 ); |
| 755 |
} |
| 756 |
|
| 757 |
|
| 758 |
ent->use = Use_BinaryMover; |
| 759 |
ent->reached = Reached_BinaryMover; |
| 760 |
|
| 761 |
ent->moverState = MOVER_POS1; |
| 762 |
ent->r.svFlags = SVF_USE_CURRENT_ORIGIN; |
| 763 |
ent->s.eType = ET_MOVER; |
| 764 |
VectorCopy (ent->pos1, ent->r.currentOrigin); |
| 765 |
trap_LinkEntity (ent); |
| 766 |
|
| 767 |
ent->s.pos.trType = TR_STATIONARY; |
| 768 |
VectorCopy( ent->pos1, ent->s.pos.trBase ); |
| 769 |
|
| 770 |
|
| 771 |
VectorSubtract( ent->pos2, ent->pos1, move ); |
| 772 |
distance = VectorLength( move ); |
| 773 |
if ( ! ent->speed ) { |
| 774 |
ent->speed = 100; |
| 775 |
} |
| 776 |
VectorScale( move, ent->speed, ent->s.pos.trDelta ); |
| 777 |
ent->s.pos.trDuration = distance * 1000 / ent->speed; |
| 778 |
if ( ent->s.pos.trDuration <= 0 ) { |
| 779 |
ent->s.pos.trDuration = 1; |
| 780 |
} |
| 781 |
} |
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
void Blocked_Door( gentity_t *ent, gentity_t *other ) { |
| 801 |
|
| 802 |
if ( !other->client ) { |
| 803 |
|
| 804 |
if( other->s.eType == ET_ITEM && other->item->giType == IT_TEAM ) { |
| 805 |
Team_DroppedFlagThink( other ); |
| 806 |
return; |
| 807 |
} |
| 808 |
G_TempEntity( other->s.origin, EV_ITEM_POP ); |
| 809 |
G_FreeEntity( other ); |
| 810 |
return; |
| 811 |
} |
| 812 |
|
| 813 |
if ( ent->damage ) { |
| 814 |
G_Damage( other, ent, ent, NULL, NULL, ent->damage, 0, MOD_CRUSH ); |
| 815 |
} |
| 816 |
if ( ent->spawnflags & 4 ) { |
| 817 |
return; |
| 818 |
} |
| 819 |
|
| 820 |
|
| 821 |
Use_BinaryMover( ent, ent, other ); |
| 822 |
} |
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
static void Touch_DoorTriggerSpectator( gentity_t *ent, gentity_t *other, trace_t *trace ) { |
| 830 |
int axis; |
| 831 |
float doorMin, doorMax; |
| 832 |
vec3_t origin; |
| 833 |
|
| 834 |
axis = ent->count; |
| 835 |
|
| 836 |
doorMin = ent->r.absmin[axis] + 100; |
| 837 |
doorMax = ent->r.absmax[axis] - 100; |
| 838 |
|
| 839 |
VectorCopy(other->client->ps.origin, origin); |
| 840 |
|
| 841 |
if (origin[axis] < doorMin || origin[axis] > doorMax) return; |
| 842 |
|
| 843 |
if (fabs(origin[axis] - doorMax) < fabs(origin[axis] - doorMin)) { |
| 844 |
origin[axis] = doorMin - 10; |
| 845 |
} else { |
| 846 |
origin[axis] = doorMax + 10; |
| 847 |
} |
| 848 |
|
| 849 |
TeleportPlayer(other, origin, tv(10000000.0, 0, 0)); |
| 850 |
} |
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
void Touch_DoorTrigger( gentity_t *ent, gentity_t *other, trace_t *trace ) { |
| 858 |
if ( other->client && other->client->sess.sessionTeam == TEAM_SPECTATOR ) { |
| 859 |
|
| 860 |
if ( ent->parent->moverState != MOVER_1TO2 && |
| 861 |
ent->parent->moverState != MOVER_POS2) { |
| 862 |
Touch_DoorTriggerSpectator( ent, other, trace ); |
| 863 |
} |
| 864 |
} |
| 865 |
else if ( ent->parent->moverState != MOVER_1TO2 ) { |
| 866 |
Use_BinaryMover( ent->parent, ent, other ); |
| 867 |
} |
| 868 |
} |
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
void Think_SpawnNewDoorTrigger( gentity_t *ent ) { |
| 880 |
gentity_t *other; |
| 881 |
vec3_t mins, maxs; |
| 882 |
int i, best; |
| 883 |
|
| 884 |
if (!ent) { |
| 885 |
return; |
| 886 |
} |
| 887 |
|
| 888 |
|
| 889 |
for ( other = ent ; other ; other = other->teamchain ) { |
| 890 |
other->takedamage = qtrue; |
| 891 |
} |
| 892 |
|
| 893 |
|
| 894 |
VectorCopy (ent->r.absmin, mins); |
| 895 |
VectorCopy (ent->r.absmax, maxs); |
| 896 |
|
| 897 |
for (other = ent->teamchain ; other ; other=other->teamchain) { |
| 898 |
AddPointToBounds (other->r.absmin, mins, maxs); |
| 899 |
AddPointToBounds (other->r.absmax, mins, maxs); |
| 900 |
} |
| 901 |
|
| 902 |
|
| 903 |
best = 0; |
| 904 |
for ( i = 1 ; i < 3 ; i++ ) { |
| 905 |
if ( maxs[i] - mins[i] < maxs[best] - mins[best] ) { |
| 906 |
best = i; |
| 907 |
} |
| 908 |
} |
| 909 |
maxs[best] += 120; |
| 910 |
mins[best] -= 120; |
| 911 |
|
| 912 |
|
| 913 |
other = G_Spawn (); |
| 914 |
other->classname = "door_trigger"; |
| 915 |
VectorCopy (mins, other->r.mins); |
| 916 |
VectorCopy (maxs, other->r.maxs); |
| 917 |
other->parent = ent; |
| 918 |
other->r.contents = CONTENTS_TRIGGER; |
| 919 |
other->touch = Touch_DoorTrigger; |
| 920 |
|
| 921 |
other->count = best; |
| 922 |
trap_LinkEntity (other); |
| 923 |
|
| 924 |
MatchTeam( ent, ent->moverState, level.time ); |
| 925 |
} |
| 926 |
|
| 927 |
void Think_MatchTeam( gentity_t *ent ) { |
| 928 |
MatchTeam( ent, ent->moverState, level.time ); |
| 929 |
} |
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
void SP_func_door (gentity_t *ent) { |
| 949 |
vec3_t abs_movedir; |
| 950 |
float distance; |
| 951 |
vec3_t size; |
| 952 |
float lip; |
| 953 |
|
| 954 |
ent->sound1to2 = ent->sound2to1 = G_SoundIndex("sound/movers/doors/dr1_strt.wav"); |
| 955 |
ent->soundPos1 = ent->soundPos2 = G_SoundIndex("sound/movers/doors/dr1_end.wav"); |
| 956 |
|
| 957 |
ent->blocked = Blocked_Door; |
| 958 |
|
| 959 |
|
| 960 |
if (!ent->speed) |
| 961 |
ent->speed = 400; |
| 962 |
|
| 963 |
|
| 964 |
if (!ent->wait) |
| 965 |
ent->wait = 2; |
| 966 |
ent->wait *= 1000; |
| 967 |
|
| 968 |
|
| 969 |
G_SpawnFloat( "lip", "8", &lip ); |
| 970 |
|
| 971 |
|
| 972 |
G_SpawnInt( "dmg", "2", &ent->damage ); |
| 973 |
|
| 974 |
|
| 975 |
VectorCopy( ent->s.origin, ent->pos1 ); |
| 976 |
|
| 977 |
|
| 978 |
trap_SetBrushModel( ent, ent->model ); |
| 979 |
G_SetMovedir (ent->s.angles, ent->movedir); |
| 980 |
abs_movedir[0] = fabs(ent->movedir[0]); |
| 981 |
abs_movedir[1] = fabs(ent->movedir[1]); |
| 982 |
abs_movedir[2] = fabs(ent->movedir[2]); |
| 983 |
VectorSubtract( ent->r.maxs, ent->r.mins, size ); |
| 984 |
distance = DotProduct( abs_movedir, size ) - lip; |
| 985 |
VectorMA( ent->pos1, distance, ent->movedir, ent->pos2 ); |
| 986 |
|
| 987 |
|
| 988 |
if ( ent->spawnflags & 1 ) { |
| 989 |
vec3_t temp; |
| 990 |
|
| 991 |
VectorCopy( ent->pos2, temp ); |
| 992 |
VectorCopy( ent->s.origin, ent->pos2 ); |
| 993 |
VectorCopy( temp, ent->pos1 ); |
| 994 |
} |
| 995 |
|
| 996 |
InitMover( ent ); |
| 997 |
|
| 998 |
ent->nextthink = level.time + FRAMETIME; |
| 999 |
|
| 1000 |
if ( ! (ent->flags & FL_TEAMMEMBER ) ) { |
| 1001 |
int health; |
| 1002 |
|
| 1003 |
G_SpawnInt( "health", "0", &health ); |
| 1004 |
if ( health ) { |
| 1005 |
ent->takedamage = qtrue; |
| 1006 |
} |
| 1007 |
if ( ent->targetname || health ) { |
| 1008 |
|
| 1009 |
ent->think = Think_MatchTeam; |
| 1010 |
} else { |
| 1011 |
ent->think = Think_SpawnNewDoorTrigger; |
| 1012 |
} |
| 1013 |
} |
| 1014 |
|
| 1015 |
|
| 1016 |
} |
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
void Touch_Plat( gentity_t *ent, gentity_t *other, trace_t *trace ) { |
| 1034 |
if ( !other->client || other->client->ps.stats[STAT_HEALTH] <= 0 ) { |
| 1035 |
return; |
| 1036 |
} |
| 1037 |
|
| 1038 |
|
| 1039 |
if ( ent->moverState == MOVER_POS2 ) { |
| 1040 |
ent->nextthink = level.time + 1000; |
| 1041 |
} |
| 1042 |
} |
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
void Touch_PlatCenterTrigger(gentity_t *ent, gentity_t *other, trace_t *trace ) { |
| 1052 |
if ( !other->client ) { |
| 1053 |
return; |
| 1054 |
} |
| 1055 |
|
| 1056 |
if ( ent->parent->moverState == MOVER_POS1 ) { |
| 1057 |
Use_BinaryMover( ent->parent, ent, other ); |
| 1058 |
} |
| 1059 |
} |
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
void SpawnPlatTrigger( gentity_t *ent ) { |
| 1072 |
gentity_t *trigger; |
| 1073 |
vec3_t tmin, tmax; |
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
trigger = G_Spawn(); |
| 1078 |
trigger->classname = "plat_trigger"; |
| 1079 |
trigger->touch = Touch_PlatCenterTrigger; |
| 1080 |
trigger->r.contents = CONTENTS_TRIGGER; |
| 1081 |
trigger->parent = ent; |
| 1082 |
|
| 1083 |
tmin[0] = ent->pos1[0] + ent->r.mins[0] + 33; |
| 1084 |
tmin[1] = ent->pos1[1] + ent->r.mins[1] + 33; |
| 1085 |
tmin[2] = ent->pos1[2] + ent->r.mins[2]; |
| 1086 |
|
| 1087 |
tmax[0] = ent->pos1[0] + ent->r.maxs[0] - 33; |
| 1088 |
tmax[1] = ent->pos1[1] + ent->r.maxs[1] - 33; |
| 1089 |
tmax[2] = ent->pos1[2] + ent->r.maxs[2] + 8; |
| 1090 |
|
| 1091 |
if ( tmax[0] <= tmin[0] ) { |
| 1092 |
tmin[0] = ent->pos1[0] + (ent->r.mins[0] + ent->r.maxs[0]) *0.5; |
| 1093 |
tmax[0] = tmin[0] + 1; |
| 1094 |
} |
| 1095 |
if ( tmax[1] <= tmin[1] ) { |
| 1096 |
tmin[1] = ent->pos1[1] + (ent->r.mins[1] + ent->r.maxs[1]) *0.5; |
| 1097 |
tmax[1] = tmin[1] + 1; |
| 1098 |
} |
| 1099 |
|
| 1100 |
VectorCopy (tmin, trigger->r.mins); |
| 1101 |
VectorCopy (tmax, trigger->r.maxs); |
| 1102 |
|
| 1103 |
trap_LinkEntity (trigger); |
| 1104 |
} |
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
void SP_func_plat (gentity_t *ent) { |
| 1119 |
float lip, height; |
| 1120 |
|
| 1121 |
ent->sound1to2 = ent->sound2to1 = G_SoundIndex("sound/movers/plats/pt1_strt.wav"); |
| 1122 |
ent->soundPos1 = ent->soundPos2 = G_SoundIndex("sound/movers/plats/pt1_end.wav"); |
| 1123 |
|
| 1124 |
VectorClear (ent->s.angles); |
| 1125 |
|
| 1126 |
G_SpawnFloat( "speed", "200", &ent->speed ); |
| 1127 |
G_SpawnInt( "dmg", "2", &ent->damage ); |
| 1128 |
G_SpawnFloat( "wait", "1", &ent->wait ); |
| 1129 |
G_SpawnFloat( "lip", "8", &lip ); |
| 1130 |
|
| 1131 |
ent->wait = 1000; |
| 1132 |
|
| 1133 |
|
| 1134 |
trap_SetBrushModel( ent, ent->model ); |
| 1135 |
|
| 1136 |
if ( !G_SpawnFloat( "height", "0", &height ) ) { |
| 1137 |
height = (ent->r.maxs[2] - ent->r.mins[2]) - lip; |
| 1138 |
} |
| 1139 |
|
| 1140 |
|
| 1141 |
VectorCopy( ent->s.origin, ent->pos2 ); |
| 1142 |
VectorCopy( ent->pos2, ent->pos1 ); |
| 1143 |
ent->pos1[2] -= height; |
| 1144 |
|
| 1145 |
InitMover( ent ); |
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
ent->touch = Touch_Plat; |
| 1150 |
|
| 1151 |
ent->blocked = Blocked_Door; |
| 1152 |
|
| 1153 |
ent->parent = ent; |
| 1154 |
|
| 1155 |
|
| 1156 |
if ( !ent->targetname ) { |
| 1157 |
SpawnPlatTrigger(ent); |
| 1158 |
} |
| 1159 |
} |
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
void Touch_Button(gentity_t *ent, gentity_t *other, trace_t *trace ) { |
| 1177 |
if ( !other->client ) { |
| 1178 |
return; |
| 1179 |
} |
| 1180 |
|
| 1181 |
if ( ent->moverState == MOVER_POS1 ) { |
| 1182 |
Use_BinaryMover( ent, other, other ); |
| 1183 |
} |
| 1184 |
} |
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
void SP_func_button( gentity_t *ent ) { |
| 1201 |
vec3_t abs_movedir; |
| 1202 |
float distance; |
| 1203 |
vec3_t size; |
| 1204 |
float lip; |
| 1205 |
|
| 1206 |
ent->sound1to2 = G_SoundIndex("sound/movers/switches/butn2.wav"); |
| 1207 |
|
| 1208 |
if ( !ent->speed ) { |
| 1209 |
ent->speed = 40; |
| 1210 |
} |
| 1211 |
|
| 1212 |
if ( !ent->wait ) { |
| 1213 |
ent->wait = 1; |
| 1214 |
} |
| 1215 |
ent->wait *= 1000; |
| 1216 |
|
| 1217 |
|
| 1218 |
VectorCopy( ent->s.origin, ent->pos1 ); |
| 1219 |
|
| 1220 |
|
| 1221 |
trap_SetBrushModel( ent, ent->model ); |
| 1222 |
|
| 1223 |
G_SpawnFloat( "lip", "4", &lip ); |
| 1224 |
|
| 1225 |
G_SetMovedir( ent->s.angles, ent->movedir ); |
| 1226 |
abs_movedir[0] = fabs(ent->movedir[0]); |
| 1227 |
abs_movedir[1] = fabs(ent->movedir[1]); |
| 1228 |
abs_movedir[2] = fabs(ent->movedir[2]); |
| 1229 |
VectorSubtract( ent->r.maxs, ent->r.mins, size ); |
| 1230 |
distance = abs_movedir[0] * size[0] + abs_movedir[1] * size[1] + abs_movedir[2] * size[2] - lip; |
| 1231 |
VectorMA (ent->pos1, distance, ent->movedir, ent->pos2); |
| 1232 |
|
| 1233 |
if (ent->health) { |
| 1234 |
|
| 1235 |
ent->takedamage = qtrue; |
| 1236 |
} else { |
| 1237 |
|
| 1238 |
ent->touch = Touch_Button; |
| 1239 |
} |
| 1240 |
|
| 1241 |
InitMover( ent ); |
| 1242 |
} |
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
#define TRAIN_START_ON 1 |
| 1256 |
#define TRAIN_TOGGLE 2 |
| 1257 |
#define TRAIN_BLOCK_STOPS 4 |
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
void Think_BeginMoving( gentity_t *ent ) { |
| 1267 |
ent->s.pos.trTime = level.time; |
| 1268 |
ent->s.pos.trType = TR_LINEAR_STOP; |
| 1269 |
} |
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
void Reached_Train( gentity_t *ent ) { |
| 1277 |
gentity_t *next; |
| 1278 |
float speed; |
| 1279 |
vec3_t move; |
| 1280 |
float length; |
| 1281 |
|
| 1282 |
|
| 1283 |
next = ent->nextTrain; |
| 1284 |
if ( !next || !next->nextTrain ) { |
| 1285 |
return; |
| 1286 |
} |
| 1287 |
|
| 1288 |
|
| 1289 |
G_UseTargets( next, NULL ); |
| 1290 |
|
| 1291 |
|
| 1292 |
ent->nextTrain = next->nextTrain; |
| 1293 |
VectorCopy( next->s.origin, ent->pos1 ); |
| 1294 |
VectorCopy( next->nextTrain->s.origin, ent->pos2 ); |
| 1295 |
|
| 1296 |
|
| 1297 |
if ( next->speed ) { |
| 1298 |
speed = next->speed; |
| 1299 |
} else { |
| 1300 |
|
| 1301 |
speed = ent->speed; |
| 1302 |
} |
| 1303 |
if ( speed < 1 ) { |
| 1304 |
speed = 1; |
| 1305 |
} |
| 1306 |
|
| 1307 |
|
| 1308 |
VectorSubtract( ent->pos2, ent->pos1, move ); |
| 1309 |
length = VectorLength( move ); |
| 1310 |
|
| 1311 |
ent->s.pos.trDuration = length * 1000 / speed; |
| 1312 |
|
| 1313 |
|
| 1314 |
ent->r.svFlags &= ~SVF_NOCLIENT; |
| 1315 |
|
| 1316 |
|
| 1317 |
if(ent->s.pos.trDuration<1) { |
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
ent->s.pos.trDuration=1; |
| 1327 |
|
| 1328 |
|
| 1329 |
ent->r.svFlags |= SVF_NOCLIENT; |
| 1330 |
} |
| 1331 |
|
| 1332 |
|
| 1333 |
ent->s.loopSound = next->soundLoop; |
| 1334 |
|
| 1335 |
|
| 1336 |
SetMoverState( ent, MOVER_1TO2, level.time ); |
| 1337 |
|
| 1338 |
|
| 1339 |
if ( next->wait ) { |
| 1340 |
ent->nextthink = level.time + next->wait * 1000; |
| 1341 |
ent->think = Think_BeginMoving; |
| 1342 |
ent->s.pos.trType = TR_STATIONARY; |
| 1343 |
} |
| 1344 |
} |
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
void Think_SetupTrainTargets( gentity_t *ent ) { |
| 1355 |
gentity_t *path, *next, *start; |
| 1356 |
|
| 1357 |
ent->nextTrain = G_Find( NULL, FOFS(targetname), ent->target ); |
| 1358 |
if ( !ent->nextTrain ) { |
| 1359 |
G_Printf( "func_train at %s with an unfound target\n", |
| 1360 |
vtos(ent->r.absmin) ); |
| 1361 |
return; |
| 1362 |
} |
| 1363 |
|
| 1364 |
start = NULL; |
| 1365 |
for ( path = ent->nextTrain ; path != start ; path = next ) { |
| 1366 |
if ( !start ) { |
| 1367 |
start = path; |
| 1368 |
} |
| 1369 |
|
| 1370 |
if ( !path->target ) { |
| 1371 |
G_Printf( "Train corner at %s without a target\n", |
| 1372 |
vtos(path->s.origin) ); |
| 1373 |
return; |
| 1374 |
} |
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
next = NULL; |
| 1380 |
do { |
| 1381 |
next = G_Find( next, FOFS(targetname), path->target ); |
| 1382 |
if ( !next ) { |
| 1383 |
G_Printf( "Train corner at %s without a target path_corner\n", |
| 1384 |
vtos(path->s.origin) ); |
| 1385 |
return; |
| 1386 |
} |
| 1387 |
} while ( strcmp( next->classname, "path_corner" ) ); |
| 1388 |
|
| 1389 |
path->nextTrain = next; |
| 1390 |
} |
| 1391 |
|
| 1392 |
|
| 1393 |
Reached_Train( ent ); |
| 1394 |
} |
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
void SP_path_corner( gentity_t *self ) { |
| 1405 |
if ( !self->targetname ) { |
| 1406 |
G_Printf ("path_corner with no targetname at %s\n", vtos(self->s.origin)); |
| 1407 |
G_FreeEntity( self ); |
| 1408 |
return; |
| 1409 |
} |
| 1410 |
|
| 1411 |
} |
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
void SP_func_train (gentity_t *self) { |
| 1428 |
VectorClear (self->s.angles); |
| 1429 |
|
| 1430 |
if (self->spawnflags & TRAIN_BLOCK_STOPS) { |
| 1431 |
self->damage = 0; |
| 1432 |
} else { |
| 1433 |
if (!self->damage) { |
| 1434 |
self->damage = 2; |
| 1435 |
} |
| 1436 |
} |
| 1437 |
|
| 1438 |
if ( !self->speed ) { |
| 1439 |
self->speed = 100; |
| 1440 |
} |
| 1441 |
|
| 1442 |
if ( !self->target ) { |
| 1443 |
G_Printf ("func_train without a target at %s\n", vtos(self->r.absmin)); |
| 1444 |
G_FreeEntity( self ); |
| 1445 |
return; |
| 1446 |
} |
| 1447 |
|
| 1448 |
trap_SetBrushModel( self, self->model ); |
| 1449 |
InitMover( self ); |
| 1450 |
|
| 1451 |
self->reached = Reached_Train; |
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
self->nextthink = level.time + FRAMETIME; |
| 1456 |
self->think = Think_SetupTrainTargets; |
| 1457 |
} |
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
void SP_func_static( gentity_t *ent ) { |
| 1475 |
trap_SetBrushModel( ent, ent->model ); |
| 1476 |
InitMover( ent ); |
| 1477 |
VectorCopy( ent->s.origin, ent->s.pos.trBase ); |
| 1478 |
VectorCopy( ent->s.origin, ent->r.currentOrigin ); |
| 1479 |
} |
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
void SP_func_rotating (gentity_t *ent) { |
| 1503 |
if ( !ent->speed ) { |
| 1504 |
ent->speed = 100; |
| 1505 |
} |
| 1506 |
|
| 1507 |
|
| 1508 |
ent->s.apos.trType = TR_LINEAR; |
| 1509 |
if ( ent->spawnflags & 4 ) { |
| 1510 |
ent->s.apos.trDelta[2] = ent->speed; |
| 1511 |
} else if ( ent->spawnflags & 8 ) { |
| 1512 |
ent->s.apos.trDelta[0] = ent->speed; |
| 1513 |
} else { |
| 1514 |
ent->s.apos.trDelta[1] = ent->speed; |
| 1515 |
} |
| 1516 |
|
| 1517 |
if (!ent->damage) { |
| 1518 |
ent->damage = 2; |
| 1519 |
} |
| 1520 |
|
| 1521 |
trap_SetBrushModel( ent, ent->model ); |
| 1522 |
InitMover( ent ); |
| 1523 |
|
| 1524 |
VectorCopy( ent->s.origin, ent->s.pos.trBase ); |
| 1525 |
VectorCopy( ent->s.pos.trBase, ent->r.currentOrigin ); |
| 1526 |
VectorCopy( ent->s.apos.trBase, ent->r.currentAngles ); |
| 1527 |
|
| 1528 |
trap_LinkEntity( ent ); |
| 1529 |
} |
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
void SP_func_bobbing (gentity_t *ent) { |
| 1552 |
float height; |
| 1553 |
float phase; |
| 1554 |
|
| 1555 |
G_SpawnFloat( "speed", "4", &ent->speed ); |
| 1556 |
G_SpawnFloat( "height", "32", &height ); |
| 1557 |
G_SpawnInt( "dmg", "2", &ent->damage ); |
| 1558 |
G_SpawnFloat( "phase", "0", &phase ); |
| 1559 |
|
| 1560 |
trap_SetBrushModel( ent, ent->model ); |
| 1561 |
InitMover( ent ); |
| 1562 |
|
| 1563 |
VectorCopy( ent->s.origin, ent->s.pos.trBase ); |
| 1564 |
VectorCopy( ent->s.origin, ent->r.currentOrigin ); |
| 1565 |
|
| 1566 |
ent->s.pos.trDuration = ent->speed * 1000; |
| 1567 |
ent->s.pos.trTime = ent->s.pos.trDuration * phase; |
| 1568 |
ent->s.pos.trType = TR_SINE; |
| 1569 |
|
| 1570 |
|
| 1571 |
if ( ent->spawnflags & 1 ) { |
| 1572 |
ent->s.pos.trDelta[0] = height; |
| 1573 |
} else if ( ent->spawnflags & 2 ) { |
| 1574 |
ent->s.pos.trDelta[1] = height; |
| 1575 |
} else { |
| 1576 |
ent->s.pos.trDelta[2] = height; |
| 1577 |
} |
| 1578 |
} |
| 1579 |
|
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
void SP_func_pendulum(gentity_t *ent) { |
| 1601 |
float freq; |
| 1602 |
float length; |
| 1603 |
float phase; |
| 1604 |
float speed; |
| 1605 |
|
| 1606 |
G_SpawnFloat( "speed", "30", &speed ); |
| 1607 |
G_SpawnInt( "dmg", "2", &ent->damage ); |
| 1608 |
G_SpawnFloat( "phase", "0", &phase ); |
| 1609 |
|
| 1610 |
trap_SetBrushModel( ent, ent->model ); |
| 1611 |
|
| 1612 |
|
| 1613 |
length = fabs( ent->r.mins[2] ); |
| 1614 |
if ( length < 8 ) { |
| 1615 |
length = 8; |
| 1616 |
} |
| 1617 |
|
| 1618 |
freq = 1 / ( M_PI * 2 ) * sqrt( g_gravity.value / ( 3 * length ) ); |
| 1619 |
|
| 1620 |
ent->s.pos.trDuration = ( 1000 / freq ); |
| 1621 |
|
| 1622 |
InitMover( ent ); |
| 1623 |
|
| 1624 |
VectorCopy( ent->s.origin, ent->s.pos.trBase ); |
| 1625 |
VectorCopy( ent->s.origin, ent->r.currentOrigin ); |
| 1626 |
|
| 1627 |
VectorCopy( ent->s.angles, ent->s.apos.trBase ); |
| 1628 |
|
| 1629 |
ent->s.apos.trDuration = 1000 / freq; |
| 1630 |
ent->s.apos.trTime = ent->s.apos.trDuration * phase; |
| 1631 |
ent->s.apos.trType = TR_SINE; |
| 1632 |
ent->s.apos.trDelta[2] = speed; |
| 1633 |
} |