| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include "g_local.h" |
| 24 |
|
| 25 |
|
| 26 |
void InitTrigger( gentity_t *self ) { |
| 27 |
if (!VectorCompare (self->s.angles, vec3_origin)) |
| 28 |
G_SetMovedir (self->s.angles, self->movedir); |
| 29 |
|
| 30 |
trap_SetBrushModel( self, self->model ); |
| 31 |
self->r.contents = CONTENTS_TRIGGER; |
| 32 |
self->r.svFlags = SVF_NOCLIENT; |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
void multi_wait( gentity_t *ent ) { |
| 38 |
ent->nextthink = 0; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
void multi_trigger( gentity_t *ent, gentity_t *activator ) { |
| 46 |
ent->activator = activator; |
| 47 |
if ( ent->nextthink ) { |
| 48 |
return; |
| 49 |
} |
| 50 |
|
| 51 |
if ( activator->client ) { |
| 52 |
if ( ( ent->spawnflags & 1 ) && |
| 53 |
activator->client->sess.sessionTeam != TEAM_RED ) { |
| 54 |
return; |
| 55 |
} |
| 56 |
if ( ( ent->spawnflags & 2 ) && |
| 57 |
activator->client->sess.sessionTeam != TEAM_BLUE ) { |
| 58 |
return; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
G_UseTargets (ent, ent->activator); |
| 63 |
|
| 64 |
if ( ent->wait > 0 ) { |
| 65 |
ent->think = multi_wait; |
| 66 |
ent->nextthink = level.time + ( ent->wait + ent->random * crandom() ) * 1000; |
| 67 |
} else { |
| 68 |
|
| 69 |
|
| 70 |
ent->touch = 0; |
| 71 |
ent->nextthink = level.time + FRAMETIME; |
| 72 |
ent->think = G_FreeEntity; |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
void Use_Multi( gentity_t *ent, gentity_t *other, gentity_t *activator ) { |
| 77 |
multi_trigger( ent, activator ); |
| 78 |
} |
| 79 |
|
| 80 |
void Touch_Multi( gentity_t *self, gentity_t *other, trace_t *trace ) { |
| 81 |
if( !other->client ) { |
| 82 |
return; |
| 83 |
} |
| 84 |
multi_trigger( self, other ); |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
void SP_trigger_multiple( gentity_t *ent ) { |
| 95 |
G_SpawnFloat( "wait", "0.5", &ent->wait ); |
| 96 |
G_SpawnFloat( "random", "0", &ent->random ); |
| 97 |
|
| 98 |
if ( ent->random >= ent->wait && ent->wait >= 0 ) { |
| 99 |
ent->random = ent->wait - FRAMETIME; |
| 100 |
G_Printf( "trigger_multiple has random >= wait\n" ); |
| 101 |
} |
| 102 |
|
| 103 |
ent->touch = Touch_Multi; |
| 104 |
ent->use = Use_Multi; |
| 105 |
|
| 106 |
InitTrigger( ent ); |
| 107 |
trap_LinkEntity (ent); |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
void trigger_always_think( gentity_t *ent ) { |
| 121 |
G_UseTargets(ent, ent); |
| 122 |
G_FreeEntity( ent ); |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
void SP_trigger_always (gentity_t *ent) { |
| 129 |
|
| 130 |
ent->nextthink = level.time + 300; |
| 131 |
ent->think = trigger_always_think; |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
void trigger_push_touch (gentity_t *self, gentity_t *other, trace_t *trace ) { |
| 144 |
|
| 145 |
if ( !other->client ) { |
| 146 |
return; |
| 147 |
} |
| 148 |
|
| 149 |
BG_TouchJumpPad( &other->client->ps, &self->s ); |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
void AimAtTarget( gentity_t *self ) { |
| 161 |
gentity_t *ent; |
| 162 |
vec3_t origin; |
| 163 |
float height, gravity, time, forward; |
| 164 |
float dist; |
| 165 |
|
| 166 |
VectorAdd( self->r.absmin, self->r.absmax, origin ); |
| 167 |
VectorScale ( origin, 0.5, origin ); |
| 168 |
|
| 169 |
ent = G_PickTarget( self->target ); |
| 170 |
if ( !ent ) { |
| 171 |
G_FreeEntity( self ); |
| 172 |
return; |
| 173 |
} |
| 174 |
|
| 175 |
height = ent->s.origin[2] - origin[2]; |
| 176 |
gravity = g_gravity.value; |
| 177 |
time = sqrt( height / ( .5 * gravity ) ); |
| 178 |
if ( !time ) { |
| 179 |
G_FreeEntity( self ); |
| 180 |
return; |
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
VectorSubtract ( ent->s.origin, origin, self->s.origin2 ); |
| 185 |
self->s.origin2[2] = 0; |
| 186 |
dist = VectorNormalize( self->s.origin2); |
| 187 |
|
| 188 |
forward = dist / time; |
| 189 |
VectorScale( self->s.origin2, forward, self->s.origin2 ); |
| 190 |
|
| 191 |
self->s.origin2[2] = time * gravity; |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
void SP_trigger_push( gentity_t *self ) { |
| 200 |
InitTrigger (self); |
| 201 |
|
| 202 |
|
| 203 |
self->r.svFlags &= ~SVF_NOCLIENT; |
| 204 |
|
| 205 |
|
| 206 |
G_SoundIndex("sound/world/jumppad.wav"); |
| 207 |
|
| 208 |
self->s.eType = ET_PUSH_TRIGGER; |
| 209 |
self->touch = trigger_push_touch; |
| 210 |
self->think = AimAtTarget; |
| 211 |
self->nextthink = level.time + FRAMETIME; |
| 212 |
trap_LinkEntity (self); |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
void Use_target_push( gentity_t *self, gentity_t *other, gentity_t *activator ) { |
| 217 |
if ( !activator->client ) { |
| 218 |
return; |
| 219 |
} |
| 220 |
|
| 221 |
if ( activator->client->ps.pm_type != PM_NORMAL ) { |
| 222 |
return; |
| 223 |
} |
| 224 |
if ( activator->client->ps.powerups[PW_FLIGHT] ) { |
| 225 |
return; |
| 226 |
} |
| 227 |
|
| 228 |
VectorCopy (self->s.origin2, activator->client->ps.velocity); |
| 229 |
|
| 230 |
|
| 231 |
if ( activator->fly_sound_debounce_time < level.time ) { |
| 232 |
activator->fly_sound_debounce_time = level.time + 1500; |
| 233 |
G_Sound( activator, CHAN_AUTO, self->noise_index ); |
| 234 |
} |
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
void SP_target_push( gentity_t *self ) { |
| 243 |
if (!self->speed) { |
| 244 |
self->speed = 1000; |
| 245 |
} |
| 246 |
G_SetMovedir (self->s.angles, self->s.origin2); |
| 247 |
VectorScale (self->s.origin2, self->speed, self->s.origin2); |
| 248 |
|
| 249 |
if ( self->spawnflags & 1 ) { |
| 250 |
self->noise_index = G_SoundIndex("sound/world/jumppad.wav"); |
| 251 |
} else { |
| 252 |
self->noise_index = G_SoundIndex("sound/misc/windfly.wav"); |
| 253 |
} |
| 254 |
if ( self->target ) { |
| 255 |
VectorCopy( self->s.origin, self->r.absmin ); |
| 256 |
VectorCopy( self->s.origin, self->r.absmax ); |
| 257 |
self->think = AimAtTarget; |
| 258 |
self->nextthink = level.time + FRAMETIME; |
| 259 |
} |
| 260 |
self->use = Use_target_push; |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
void trigger_teleporter_touch (gentity_t *self, gentity_t *other, trace_t *trace ) { |
| 272 |
gentity_t *dest; |
| 273 |
|
| 274 |
if ( !other->client ) { |
| 275 |
return; |
| 276 |
} |
| 277 |
if ( other->client->ps.pm_type == PM_DEAD ) { |
| 278 |
return; |
| 279 |
} |
| 280 |
|
| 281 |
if ( ( self->spawnflags & 1 ) && |
| 282 |
other->client->sess.sessionTeam != TEAM_SPECTATOR ) { |
| 283 |
return; |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
dest = G_PickTarget( self->target ); |
| 288 |
if (!dest) { |
| 289 |
G_Printf ("Couldn't find teleporter destination\n"); |
| 290 |
return; |
| 291 |
} |
| 292 |
|
| 293 |
TeleportPlayer( other, dest->s.origin, dest->s.angles ); |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
void SP_trigger_teleport( gentity_t *self ) { |
| 306 |
InitTrigger (self); |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
if ( self->spawnflags & 1 ) { |
| 311 |
self->r.svFlags |= SVF_NOCLIENT; |
| 312 |
} else { |
| 313 |
self->r.svFlags &= ~SVF_NOCLIENT; |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
G_SoundIndex("sound/world/jumppad.wav"); |
| 318 |
|
| 319 |
self->s.eType = ET_TELEPORT_TRIGGER; |
| 320 |
self->touch = trigger_teleporter_touch; |
| 321 |
|
| 322 |
trap_LinkEntity (self); |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
void hurt_use( gentity_t *self, gentity_t *other, gentity_t *activator ) { |
| 347 |
if ( self->r.linked ) { |
| 348 |
trap_UnlinkEntity( self ); |
| 349 |
} else { |
| 350 |
trap_LinkEntity( self ); |
| 351 |
} |
| 352 |
} |
| 353 |
|
| 354 |
void hurt_touch( gentity_t *self, gentity_t *other, trace_t *trace ) { |
| 355 |
int dflags; |
| 356 |
|
| 357 |
if ( !other->takedamage ) { |
| 358 |
return; |
| 359 |
} |
| 360 |
|
| 361 |
if ( self->timestamp > level.time ) { |
| 362 |
return; |
| 363 |
} |
| 364 |
|
| 365 |
if ( self->spawnflags & 16 ) { |
| 366 |
self->timestamp = level.time + 1000; |
| 367 |
} else { |
| 368 |
self->timestamp = level.time + FRAMETIME; |
| 369 |
} |
| 370 |
|
| 371 |
|
| 372 |
if ( !(self->spawnflags & 4) ) { |
| 373 |
G_Sound( other, CHAN_AUTO, self->noise_index ); |
| 374 |
} |
| 375 |
|
| 376 |
if (self->spawnflags & 8) |
| 377 |
dflags = DAMAGE_NO_PROTECTION; |
| 378 |
else |
| 379 |
dflags = 0; |
| 380 |
G_Damage (other, self, self, NULL, NULL, self->damage, dflags, MOD_TRIGGER_HURT); |
| 381 |
} |
| 382 |
|
| 383 |
void SP_trigger_hurt( gentity_t *self ) { |
| 384 |
InitTrigger (self); |
| 385 |
|
| 386 |
self->noise_index = G_SoundIndex( "sound/world/electro.wav" ); |
| 387 |
self->touch = hurt_touch; |
| 388 |
|
| 389 |
if ( !self->damage ) { |
| 390 |
self->damage = 5; |
| 391 |
} |
| 392 |
|
| 393 |
self->use = hurt_use; |
| 394 |
|
| 395 |
|
| 396 |
if ( self->spawnflags & 1 ) { |
| 397 |
trap_UnlinkEntity (self); |
| 398 |
} |
| 399 |
else { |
| 400 |
trap_LinkEntity (self); |
| 401 |
} |
| 402 |
} |
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
void func_timer_think( gentity_t *self ) { |
| 426 |
G_UseTargets (self, self->activator); |
| 427 |
|
| 428 |
self->nextthink = level.time + 1000 * ( self->wait + crandom() * self->random ); |
| 429 |
} |
| 430 |
|
| 431 |
void func_timer_use( gentity_t *self, gentity_t *other, gentity_t *activator ) { |
| 432 |
self->activator = activator; |
| 433 |
|
| 434 |
|
| 435 |
if ( self->nextthink ) { |
| 436 |
self->nextthink = 0; |
| 437 |
return; |
| 438 |
} |
| 439 |
|
| 440 |
|
| 441 |
func_timer_think (self); |
| 442 |
} |
| 443 |
|
| 444 |
void SP_func_timer( gentity_t *self ) { |
| 445 |
G_SpawnFloat( "random", "1", &self->random); |
| 446 |
G_SpawnFloat( "wait", "1", &self->wait ); |
| 447 |
|
| 448 |
self->use = func_timer_use; |
| 449 |
self->think = func_timer_think; |
| 450 |
|
| 451 |
if ( self->random >= self->wait ) { |
| 452 |
self->random = self->wait - FRAMETIME; |
| 453 |
G_Printf( "func_timer at %s has random >= wait\n", vtos( self->s.origin ) ); |
| 454 |
} |
| 455 |
|
| 456 |
if ( self->spawnflags & 1 ) { |
| 457 |
self->nextthink = level.time + FRAMETIME; |
| 458 |
self->activator = self; |
| 459 |
} |
| 460 |
|
| 461 |
self->r.svFlags = SVF_NOCLIENT; |
| 462 |
} |
| 463 |
|
| 464 |
|