rogue/src/g_trigger.c

912 lines
15 KiB
C
Raw Normal View History

/* =======================================================================
*
* Trigger.
*
* =======================================================================
*/
2011-10-11 11:40:43 +00:00
#include "header/local.h"
2009-03-12 20:03:41 +00:00
#define TRIGGER_MONSTER 0x01
#define TRIGGER_NOT_PLAYER 0x02
#define TRIGGER_TRIGGERED 0x04
#define TRIGGER_TOGGLE 0x08
2014-02-22 12:20:22 +00:00
#define PUSH_ONCE 0x01
#define PUSH_START_OFF 0x02
#define PUSH_SILENT 0x04
static int windsound;
2014-02-22 12:20:22 +00:00
void
InitTrigger(edict_t *self)
2014-02-22 12:20:22 +00:00
{
if (!self)
{
return;
}
2014-02-22 12:20:22 +00:00
if (!VectorCompare(self->s.angles, vec3_origin))
{
G_SetMovedir(self->s.angles, self->movedir);
}
2009-03-12 20:03:41 +00:00
self->solid = SOLID_TRIGGER;
self->movetype = MOVETYPE_NONE;
gi.setmodel(self, self->model);
2009-03-12 20:03:41 +00:00
self->svflags = SVF_NOCLIENT;
}
2014-02-22 12:20:22 +00:00
/*
* the wait time has passed, so set
* back up for another activation
*/
void
multi_wait(edict_t *ent)
2014-02-22 12:20:22 +00:00
{
if (!ent)
{
return;
}
2014-02-22 12:20:22 +00:00
2009-03-12 20:03:41 +00:00
ent->nextthink = 0;
}
void
multi_trigger(edict_t *ent)
2014-02-22 12:20:22 +00:00
{
if (!ent)
{
return;
}
2014-02-22 12:20:22 +00:00
2009-03-12 20:03:41 +00:00
if (ent->nextthink)
{
return; /* already been triggered */
}
2009-03-12 20:03:41 +00:00
G_UseTargets(ent, ent->activator);
2009-03-12 20:03:41 +00:00
if (ent->wait > 0)
2009-03-12 20:03:41 +00:00
{
ent->think = multi_wait;
ent->nextthink = level.time + ent->wait;
}
else
2014-02-22 12:20:22 +00:00
{
/* we can't just remove (self) here, because
2014-02-22 12:20:22 +00:00
this is a touch function called while looping
through area links... */
2009-03-12 20:03:41 +00:00
ent->touch = NULL;
ent->nextthink = level.time + FRAMETIME;
ent->think = G_FreeEdict;
}
}
void
Use_Multi(edict_t *ent, edict_t *other /* unused */, edict_t *activator)
2014-02-22 12:20:22 +00:00
{
if (!ent || !activator)
2009-03-12 20:03:41 +00:00
{
return;
}
2014-02-22 12:20:22 +00:00
if (ent->spawnflags & TRIGGER_TOGGLE)
{
if (ent->solid == SOLID_TRIGGER)
{
2009-03-12 20:03:41 +00:00
ent->solid = SOLID_NOT;
}
2009-03-12 20:03:41 +00:00
else
{
2009-03-12 20:03:41 +00:00
ent->solid = SOLID_TRIGGER;
}
gi.linkentity(ent);
2009-03-12 20:03:41 +00:00
}
else
{
ent->activator = activator;
multi_trigger(ent);
2009-03-12 20:03:41 +00:00
}
}
void
Touch_Multi(edict_t *self, edict_t *other, cplane_t *plane /* unused */, csurface_t *surf /* unused */)
2014-02-22 12:20:22 +00:00
{
if (!self || !other)
{
return;
}
2014-02-22 12:20:22 +00:00
if (other->client)
2009-03-12 20:03:41 +00:00
{
if (self->spawnflags & 2)
{
2009-03-12 20:03:41 +00:00
return;
}
2009-03-12 20:03:41 +00:00
}
else if (other->svflags & SVF_MONSTER)
{
if (!(self->spawnflags & 1))
{
2009-03-12 20:03:41 +00:00
return;
}
2009-03-12 20:03:41 +00:00
}
else
{
2009-03-12 20:03:41 +00:00
return;
}
2009-03-12 20:03:41 +00:00
if (!VectorCompare(self->movedir, vec3_origin))
{
vec3_t forward;
2009-03-12 20:03:41 +00:00
AngleVectors(other->s.angles, forward, NULL, NULL);
2009-03-12 20:03:41 +00:00
if (_DotProduct(forward, self->movedir) < 0)
{
2009-03-12 20:03:41 +00:00
return;
}
2009-03-12 20:03:41 +00:00
}
self->activator = other;
multi_trigger(self);
2009-03-12 20:03:41 +00:00
}
/*
* QUAKED trigger_multiple (.5 .5 .5) ? MONSTER NOT_PLAYER TRIGGERED TOGGLE
* Variable sized repeatable trigger. Must be targeted at one or more entities.
* If "delay" is set, the trigger waits some time after activating before firing.
* "wait" : Seconds between triggerings. (.2 default)
*
* TOGGLE - using this trigger will activate/deactivate it. trigger will begin inactive.
*
* sounds
* 1) secret
* 2) beep beep
* 3) large switch
* 4)
* set "message" to text string
*/
void
trigger_enable(edict_t *self, edict_t *other /* unused */, edict_t *activator /* unused */)
2014-02-22 12:20:22 +00:00
{
if (!self)
{
return;
}
2014-02-22 12:20:22 +00:00
2009-03-12 20:03:41 +00:00
self->solid = SOLID_TRIGGER;
self->use = Use_Multi;
gi.linkentity(self);
2009-03-12 20:03:41 +00:00
}
void
SP_trigger_multiple(edict_t *ent)
2014-02-22 12:20:22 +00:00
{
if (!ent)
{
return;
}
2014-02-22 12:20:22 +00:00
2009-03-12 20:03:41 +00:00
if (ent->sounds == 1)
{
ent->noise_index = gi.soundindex("misc/secret.wav");
}
2009-03-12 20:03:41 +00:00
else if (ent->sounds == 2)
{
ent->noise_index = gi.soundindex("misc/talk.wav");
}
2009-03-12 20:03:41 +00:00
else if (ent->sounds == 3)
{
ent->noise_index = gi.soundindex("misc/trigger1.wav");
}
2009-03-12 20:03:41 +00:00
if (!ent->wait)
{
2009-03-12 20:03:41 +00:00
ent->wait = 0.2;
}
2009-03-12 20:03:41 +00:00
ent->touch = Touch_Multi;
ent->movetype = MOVETYPE_NONE;
ent->svflags |= SVF_NOCLIENT;
if (ent->spawnflags & (TRIGGER_TRIGGERED | TRIGGER_TOGGLE))
{
ent->solid = SOLID_NOT;
ent->use = trigger_enable;
}
else
{
ent->solid = SOLID_TRIGGER;
ent->use = Use_Multi;
}
if (!VectorCompare(ent->s.angles, vec3_origin))
{
G_SetMovedir(ent->s.angles, ent->movedir);
}
2009-03-12 20:03:41 +00:00
gi.setmodel(ent, ent->model);
gi.linkentity(ent);
2009-03-12 20:03:41 +00:00
}
/*
* QUAKED trigger_once (.5 .5 .5) ? x x TRIGGERED
2014-02-22 12:20:22 +00:00
*
* Triggers once, then removes itself.
* You must set the key "target" to the name of another object in the level that has a matching "targetname".
*
* If TRIGGERED, this trigger must be triggered before it is live.
*
* sounds
* 1) secret
* 2) beep beep
* 3) large switch
* 4)
*
* "message" string to be displayed when triggered
*/
void
SP_trigger_once(edict_t *ent)
2014-02-22 12:20:22 +00:00
{
if (!ent)
{
return;
}
2014-02-22 12:20:22 +00:00
/* make old maps work because I messed up on flag assignments here */
2009-03-12 20:03:41 +00:00
if (ent->spawnflags & 1)
{
vec3_t v;
2009-03-12 20:03:41 +00:00
VectorMA(ent->mins, 0.5, ent->size, v);
2009-03-12 20:03:41 +00:00
ent->spawnflags &= ~1;
ent->spawnflags |= 4;
gi.dprintf("fixed TRIGGERED flag on %s at %s\n", ent->classname, vtos(v));
}
ent->wait = -1;
SP_trigger_multiple(ent);
2009-03-12 20:03:41 +00:00
}
/*
* QUAKED trigger_relay (.5 .5 .5) (-8 -8 -8) (8 8 8)
2014-02-22 12:20:22 +00:00
*
* This fixed size trigger cannot be touched, it can only be fired by other events.
*/
void
trigger_relay_use(edict_t *self, edict_t *other /* unused */, edict_t *activator)
2014-02-22 12:20:22 +00:00
{
if (!self || !activator)
{
return;
}
2014-02-22 12:20:22 +00:00
G_UseTargets(self, activator);
2009-03-12 20:03:41 +00:00
}
void
SP_trigger_relay(edict_t *self)
2014-02-22 12:20:22 +00:00
{
if (!self)
{
return;
}
2014-02-22 12:20:22 +00:00
2009-03-12 20:03:41 +00:00
self->use = trigger_relay_use;
}
/*
* QUAKED trigger_key (.5 .5 .5) (-8 -8 -8) (8 8 8)
2014-02-22 12:20:22 +00:00
*
* A relay trigger that only fires it's targets if player has the proper key.
* Use "item" to specify the required key, for example "key_data_cd"
*/
void
trigger_key_use(edict_t *self, edict_t *other /* unused */, edict_t *activator)
2009-03-12 20:03:41 +00:00
{
int index;
2014-02-22 12:20:22 +00:00
if (!self|| !activator)
{
return;
}
2014-02-22 12:20:22 +00:00
2009-03-12 20:03:41 +00:00
if (!self->item)
{
2009-03-12 20:03:41 +00:00
return;
}
2009-03-12 20:03:41 +00:00
if (!activator->client)
{
2009-03-12 20:03:41 +00:00
return;
}
2009-03-12 20:03:41 +00:00
index = ITEM_INDEX(self->item);
2009-03-12 20:03:41 +00:00
if (!activator->client->pers.inventory[index])
{
if (level.time < self->touch_debounce_time)
{
2009-03-12 20:03:41 +00:00
return;
}
2009-03-12 20:03:41 +00:00
self->touch_debounce_time = level.time + 5.0;
gi.centerprintf(activator, "You need the %s", self->item->pickup_name);
gi.sound(activator, CHAN_AUTO, gi.soundindex("misc/keytry.wav"), 1, ATTN_NORM, 0);
2009-03-12 20:03:41 +00:00
return;
}
gi.sound(activator, CHAN_AUTO, gi.soundindex("misc/keyuse.wav"), 1, ATTN_NORM, 0);
2009-03-12 20:03:41 +00:00
if (coop->value)
{
int player;
edict_t *ent;
2009-03-12 20:03:41 +00:00
if (strcmp(self->item->classname, "key_power_cube") == 0)
{
int cube;
2009-03-12 20:03:41 +00:00
for (cube = 0; cube < 8; cube++)
{
2009-03-12 20:03:41 +00:00
if (activator->client->pers.power_cubes & (1 << cube))
{
2009-03-12 20:03:41 +00:00
break;
}
}
2009-03-12 20:03:41 +00:00
for (player = 1; player <= game.maxclients; player++)
{
ent = &g_edicts[player];
2009-03-12 20:03:41 +00:00
if (!ent->inuse)
{
2009-03-12 20:03:41 +00:00
continue;
}
2009-03-12 20:03:41 +00:00
if (!ent->client)
{
2009-03-12 20:03:41 +00:00
continue;
}
2009-03-12 20:03:41 +00:00
if (ent->client->pers.power_cubes & (1 << cube))
{
ent->client->pers.inventory[index]--;
ent->client->pers.power_cubes &= ~(1 << cube);
}
}
}
else
{
for (player = 1; player <= game.maxclients; player++)
{
ent = &g_edicts[player];
2009-03-12 20:03:41 +00:00
if (!ent->inuse)
{
2009-03-12 20:03:41 +00:00
continue;
}
2009-03-12 20:03:41 +00:00
if (!ent->client)
{
2009-03-12 20:03:41 +00:00
continue;
}
2009-03-12 20:03:41 +00:00
ent->client->pers.inventory[index] = 0;
}
}
}
else
{
activator->client->pers.inventory[index]--;
}
G_UseTargets(self, activator);
2009-03-12 20:03:41 +00:00
self->use = NULL;
}
void
SP_trigger_key(edict_t *self)
2014-02-22 12:20:22 +00:00
{
if (!self)
{
return;
}
2014-02-22 12:20:22 +00:00
2009-03-12 20:03:41 +00:00
if (!st.item)
{
gi.dprintf("no key item for trigger_key at %s\n", vtos(self->s.origin));
return;
}
self->item = FindItemByClassname(st.item);
2009-03-12 20:03:41 +00:00
if (!self->item)
{
gi.dprintf("item %s not found for trigger_key at %s\n", st.item,
vtos(self->s.origin));
2009-03-12 20:03:41 +00:00
return;
}
if (!self->target)
{
gi.dprintf("%s at %s has no target\n", self->classname,
vtos(self->s.origin));
2009-03-12 20:03:41 +00:00
return;
}
gi.soundindex("misc/keytry.wav");
gi.soundindex("misc/keyuse.wav");
2009-03-12 20:03:41 +00:00
self->use = trigger_key_use;
}
/*
* QUAKED trigger_counter (.5 .5 .5) ? nomessage
2014-02-22 12:20:22 +00:00
*
* Acts as an intermediary for an action that takes multiple inputs.
*
* If nomessage is not set, t will print "1 more.. " etc when triggered
* and "sequence complete" when finished.
*
2014-02-22 12:20:22 +00:00
* After the counter has been triggered "count" times (default 2),
* it will fire all of it's targets and remove itself.
*/
void
trigger_counter_use(edict_t *self, edict_t *other /* unused */, edict_t *activator)
2014-02-22 12:20:22 +00:00
{
if (!self || !activator)
{
return;
}
2014-02-22 12:20:22 +00:00
2009-03-12 20:03:41 +00:00
if (self->count == 0)
{
2009-03-12 20:03:41 +00:00
return;
}
2009-03-12 20:03:41 +00:00
self->count--;
if (self->count)
{
if (!(self->spawnflags & 1))
2009-03-12 20:03:41 +00:00
{
gi.centerprintf(activator, "%i more to go...", self->count);
gi.sound(activator, CHAN_AUTO, gi.soundindex("misc/talk1.wav"), 1, ATTN_NORM, 0);
2009-03-12 20:03:41 +00:00
}
2009-03-12 20:03:41 +00:00
return;
}
if (!(self->spawnflags & 1))
2009-03-12 20:03:41 +00:00
{
gi.centerprintf(activator, "Sequence completed!");
gi.sound(activator, CHAN_AUTO, gi.soundindex("misc/talk1.wav"), 1, ATTN_NORM, 0);
2009-03-12 20:03:41 +00:00
}
2009-03-12 20:03:41 +00:00
self->activator = activator;
multi_trigger(self);
2009-03-12 20:03:41 +00:00
}
void
SP_trigger_counter(edict_t *self)
2014-02-22 12:20:22 +00:00
{
if (!self)
{
return;
}
2014-02-22 12:20:22 +00:00
2009-03-12 20:03:41 +00:00
self->wait = -1;
2009-03-12 20:03:41 +00:00
if (!self->count)
{
2009-03-12 20:03:41 +00:00
self->count = 2;
}
2009-03-12 20:03:41 +00:00
self->use = trigger_counter_use;
}
/*
* QUAKED trigger_always (.5 .5 .5) (-8 -8 -8) (8 8 8)
2014-02-22 12:20:22 +00:00
*
* This trigger will always fire. It is activated by the world.
*/
void
SP_trigger_always(edict_t *ent)
2014-02-22 12:20:22 +00:00
{
if (!ent)
{
return;
}
2014-02-22 12:20:22 +00:00
/* we must have some delay to make sure our use targets are present */
2009-03-12 20:03:41 +00:00
if (ent->delay < 0.2)
{
2009-03-12 20:03:41 +00:00
ent->delay = 0.2;
}
2009-03-12 20:03:41 +00:00
G_UseTargets(ent, ent);
}
void
trigger_push_touch(edict_t *self, edict_t *other, cplane_t *plane /* unused */, csurface_t *surf /* unused */)
2014-02-22 12:20:22 +00:00
{
if (!self || !other)
{
return;
}
2014-02-22 12:20:22 +00:00
2009-03-12 20:03:41 +00:00
if (strcmp(other->classname, "grenade") == 0)
{
VectorScale(self->movedir, self->speed * 10, other->velocity);
2009-03-12 20:03:41 +00:00
}
else if (other->health > 0)
{
VectorScale(self->movedir, self->speed * 10, other->velocity);
2009-03-12 20:03:41 +00:00
if (other->client)
{
/* don't take falling damage immediately from this */
VectorCopy(other->velocity, other->client->oldvelocity);
if (!(self->spawnflags & PUSH_SILENT) &&
(other->fly_sound_debounce_time < level.time))
2009-03-12 20:03:41 +00:00
{
other->fly_sound_debounce_time = level.time + 1.5;
gi.sound(other, CHAN_AUTO, windsound, 1, ATTN_NORM, 0);
2009-03-12 20:03:41 +00:00
}
}
}
2009-03-12 20:03:41 +00:00
if (self->spawnflags & PUSH_ONCE)
{
G_FreeEdict(self);
}
2009-03-12 20:03:41 +00:00
}
void
trigger_push_use(edict_t *self, edict_t *other /* unused */, edict_t *activator /* unused */)
2014-02-22 12:20:22 +00:00
{
if (!self)
{
return;
}
2014-02-22 12:20:22 +00:00
2009-03-12 20:03:41 +00:00
if (self->solid == SOLID_NOT)
{
2009-03-12 20:03:41 +00:00
self->solid = SOLID_TRIGGER;
}
2009-03-12 20:03:41 +00:00
else
{
2009-03-12 20:03:41 +00:00
self->solid = SOLID_NOT;
}
gi.linkentity(self);
2009-03-12 20:03:41 +00:00
}
/*
* QUAKED trigger_push (.5 .5 .5) ? PUSH_ONCE START_OFF SILENT
* Pushes the player
* "speed" defaults to 1000
*
* If targeted, it will toggle on and off when used.
*
* START_OFF - toggled trigger_push begins in off setting
* SILENT - doesn't make wind noise
*/
void
SP_trigger_push(edict_t *self)
2014-02-22 12:20:22 +00:00
{
if (!self)
{
return;
}
2014-02-22 12:20:22 +00:00
InitTrigger(self);
windsound = gi.soundindex("misc/windfly.wav");
2009-03-12 20:03:41 +00:00
self->touch = trigger_push_touch;
2009-03-12 20:03:41 +00:00
if (!self->speed)
{
2009-03-12 20:03:41 +00:00
self->speed = 1000;
}
2009-03-12 20:03:41 +00:00
if (self->targetname) /* toggleable */
2009-03-12 20:03:41 +00:00
{
self->use = trigger_push_use;
if (self->spawnflags & PUSH_START_OFF)
{
2009-03-12 20:03:41 +00:00
self->solid = SOLID_NOT;
}
2009-03-12 20:03:41 +00:00
}
else if (self->spawnflags & PUSH_START_OFF)
2009-03-12 20:03:41 +00:00
{
gi.dprintf("trigger_push is START_OFF but not targeted.\n");
2009-03-12 20:03:41 +00:00
self->svflags = 0;
self->touch = NULL;
self->solid = SOLID_BSP;
self->movetype = MOVETYPE_PUSH;
}
gi.linkentity(self);
2009-03-12 20:03:41 +00:00
}
/*
* QUAKED trigger_hurt (.5 .5 .5) ? START_OFF TOGGLE SILENT NO_PROTECTION SLOW
2014-02-22 12:20:22 +00:00
*
* Any entity that touches this will be hurt.
*
* It does dmg points of damage each server frame
*
* SILENT supresses playing the sound
* SLOW changes the damage rate to once per second
* NO_PROTECTION *nothing* stops the damage
*
* "dmg" default 5 (whole numbers only)
*
*/
void
hurt_use(edict_t *self, edict_t *other /* unused */, edict_t *activator /* unused */)
2014-02-22 12:20:22 +00:00
{
if (!self)
{
return;
}
2014-02-22 12:20:22 +00:00
2009-03-12 20:03:41 +00:00
if (self->solid == SOLID_NOT)
{
2009-03-12 20:03:41 +00:00
self->solid = SOLID_TRIGGER;
}
2009-03-12 20:03:41 +00:00
else
{
2009-03-12 20:03:41 +00:00
self->solid = SOLID_NOT;
}
gi.linkentity(self);
2009-03-12 20:03:41 +00:00
if (!(self->spawnflags & 2))
{
2009-03-12 20:03:41 +00:00
self->use = NULL;
}
2009-03-12 20:03:41 +00:00
}
void
hurt_touch(edict_t *self, edict_t *other, cplane_t *plane /* unused */, csurface_t *surf /* unused */)
2009-03-12 20:03:41 +00:00
{
int dflags;
2014-02-22 12:20:22 +00:00
if (!self || !other)
{
return;
}
2014-02-22 12:20:22 +00:00
2009-03-12 20:03:41 +00:00
if (!other->takedamage)
{
2009-03-12 20:03:41 +00:00
return;
}
2009-03-12 20:03:41 +00:00
if (self->timestamp > level.time)
{
2009-03-12 20:03:41 +00:00
return;
}
2009-03-12 20:03:41 +00:00
if (self->spawnflags & 16)
{
2009-03-12 20:03:41 +00:00
self->timestamp = level.time + 1;
}
2009-03-12 20:03:41 +00:00
else
{
2009-03-12 20:03:41 +00:00
self->timestamp = level.time + FRAMETIME;
}
2009-03-12 20:03:41 +00:00
if (!(self->spawnflags & 4))
{
if ((level.framenum % 10) == 0)
{
gi.sound(other, CHAN_AUTO, self->noise_index, 1, ATTN_NORM, 0);
}
2009-03-12 20:03:41 +00:00
}
if (self->spawnflags & 8)
{
2009-03-12 20:03:41 +00:00
dflags = DAMAGE_NO_PROTECTION;
}
2009-03-12 20:03:41 +00:00
else
{
2009-03-12 20:03:41 +00:00
dflags = 0;
}
T_Damage(other, self, self, vec3_origin, other->s.origin, vec3_origin,
self->dmg, self->dmg, dflags, MOD_TRIGGER_HURT);
2009-03-12 20:03:41 +00:00
}
void
SP_trigger_hurt(edict_t *self)
2014-02-22 12:20:22 +00:00
{
if (!self)
{
return;
}
2014-02-22 12:20:22 +00:00
InitTrigger(self);
2009-03-12 20:03:41 +00:00
self->noise_index = gi.soundindex("world/electro.wav");
2009-03-12 20:03:41 +00:00
self->touch = hurt_touch;
if (!self->dmg)
{
2009-03-12 20:03:41 +00:00
self->dmg = 5;
}
2009-03-12 20:03:41 +00:00
if (self->spawnflags & 1)
{
2009-03-12 20:03:41 +00:00
self->solid = SOLID_NOT;
}
2009-03-12 20:03:41 +00:00
else
{
2009-03-12 20:03:41 +00:00
self->solid = SOLID_TRIGGER;
}
2009-03-12 20:03:41 +00:00
if (self->spawnflags & 2)
{
2009-03-12 20:03:41 +00:00
self->use = hurt_use;
}
2009-03-12 20:03:41 +00:00
gi.linkentity(self);
2009-03-12 20:03:41 +00:00
}
void
trigger_gravity_use(edict_t *self, edict_t *other /* unused */, edict_t *activator /* unused */)
2014-02-22 12:20:22 +00:00
{
if (!self)
{
return;
}
2014-02-22 12:20:22 +00:00
2009-03-12 20:03:41 +00:00
if (self->solid == SOLID_NOT)
{
2009-03-12 20:03:41 +00:00
self->solid = SOLID_TRIGGER;
}
2009-03-12 20:03:41 +00:00
else
{
2009-03-12 20:03:41 +00:00
self->solid = SOLID_NOT;
}
gi.linkentity(self);
2009-03-12 20:03:41 +00:00
}
/* PGM */
void
trigger_gravity_touch(edict_t *self, edict_t *other, cplane_t *plane /* unused */, csurface_t *surf /* unused */)
2014-02-22 12:20:22 +00:00
{
if (!self || !other)
{
return;
}
2014-02-22 12:20:22 +00:00
2009-03-12 20:03:41 +00:00
other->gravity = self->gravity;
}
/*
* QUAKED trigger_gravity (.5 .5 .5) ? TOGGLE START_OFF
* Changes the touching entites gravity to
* the value of "gravity". 1.0 is standard
* gravity for the level.
*
* TOGGLE - trigger_gravity can be turned on and off
* START_OFF - trigger_gravity starts turned off (implies TOGGLE)
*/
void
SP_trigger_gravity(edict_t *self)
2014-02-22 12:20:22 +00:00
{
if (!self)
{
return;
}
2014-02-22 12:20:22 +00:00
2009-03-12 20:03:41 +00:00
if (st.gravity == 0)
{
gi.dprintf("trigger_gravity without gravity set at %s\n", vtos(self->s.origin));
G_FreeEdict(self);
2009-03-12 20:03:41 +00:00
return;
}
InitTrigger(self);
2009-03-12 20:03:41 +00:00
self->gravity = strtof(st.gravity, (char **)NULL);
2009-03-12 20:03:41 +00:00
if (self->spawnflags & 1) /* TOGGLE */
{
2009-03-12 20:03:41 +00:00
self->use = trigger_gravity_use;
}
2009-03-12 20:03:41 +00:00
if (self->spawnflags & 2) /* START_OFF */
2009-03-12 20:03:41 +00:00
{
self->use = trigger_gravity_use;
self->solid = SOLID_NOT;
}
self->touch = trigger_gravity_touch;
gi.linkentity(self);
2009-03-12 20:03:41 +00:00
}
/*
* QUAKED trigger_monsterjump (.5 .5 .5) ?
2014-02-22 12:20:22 +00:00
*
* Walking monsters that touch this will jump in the direction of the trigger's angle
* "speed" default to 200, the speed thrown forward
* "height" default to 200, the speed thrown upwards
*/
void
trigger_monsterjump_touch(edict_t *self, edict_t *other, cplane_t *plane /* unused */, csurface_t *surf /* unused */)
2014-02-22 12:20:22 +00:00
{
if (!self || !other)
{
2009-03-12 20:03:41 +00:00
return;
}
2014-02-22 12:20:22 +00:00
if (other->flags & (FL_FLY | FL_SWIM))
{
return;
}
2009-03-12 20:03:41 +00:00
if (other->svflags & SVF_DEADMONSTER)
{
2009-03-12 20:03:41 +00:00
return;
}
if (!(other->svflags & SVF_MONSTER))
{
2009-03-12 20:03:41 +00:00
return;
}
2009-03-12 20:03:41 +00:00
/* set XY even if not on ground, so the jump will clear lips */
2009-03-12 20:03:41 +00:00
other->velocity[0] = self->movedir[0] * self->speed;
other->velocity[1] = self->movedir[1] * self->speed;
2009-03-12 20:03:41 +00:00
if (!other->groundentity)
{
2009-03-12 20:03:41 +00:00
return;
}
2009-03-12 20:03:41 +00:00
other->groundentity = NULL;
other->velocity[2] = self->movedir[2];
}
void
SP_trigger_monsterjump(edict_t *self)
2014-02-22 12:20:22 +00:00
{
if (!self)
{
return;
}
2014-02-22 12:20:22 +00:00
2009-03-12 20:03:41 +00:00
if (!self->speed)
{
2009-03-12 20:03:41 +00:00
self->speed = 200;
}
2009-03-12 20:03:41 +00:00
if (!st.height)
{
2009-03-12 20:03:41 +00:00
st.height = 200;
}
2009-03-12 20:03:41 +00:00
if (self->s.angles[YAW] == 0)
{
2009-03-12 20:03:41 +00:00
self->s.angles[YAW] = 360;
}
InitTrigger(self);
2009-03-12 20:03:41 +00:00
self->touch = trigger_monsterjump_touch;
self->movedir[2] = st.height;
}