Cleanup g_newtrig.c and add sanity checks

This commit is contained in:
Yamagi Burmeister 2014-01-26 16:16:23 +01:00
parent b81736eece
commit 762208bceb

View file

@ -1,113 +1,158 @@
// g_newtrig.c /*
// pmack * =======================================================================
// october 1997 *
* Rogue specific triggers.
*
* =======================================================================
*/
#include "header/local.h" #include "header/local.h"
#define TELEPORT_PLAYER_ONLY 1 #define TELEPORT_PLAYER_ONLY 1
#define TELEPORT_SILENT 2 #define TELEPORT_SILENT 2
#define TELEPORT_CTF_ONLY 4 #define TELEPORT_CTF_ONLY 4
#define TELEPORT_START_ON 8 #define TELEPORT_START_ON 8
extern void TeleportEffect (vec3_t origin); extern void TeleportEffect(vec3_t origin);
/*QUAKED info_teleport_destination (.5 .5 .5) (-16 -16 -24) (16 16 32) /*
Destination marker for a teleporter. * QUAKED info_teleport_destination (.5 .5 .5) (-16 -16 -24) (16 16 32)
*/ *
void SP_info_teleport_destination (edict_t *self) * Destination marker for a teleporter.
*/
void
SP_info_teleport_destination(edict_t *self)
{ {
} }
/*QUAKED trigger_teleport (.5 .5 .5) ? player_only silent ctf_only start_on /*
Any object touching this will be transported to the corresponding * QUAKED trigger_teleport (.5 .5 .5) ? player_only silent ctf_only start_on
info_teleport_destination entity. You must set the "target" field, *
and create an object with a "targetname" field that matches. * Any object touching this will be transported to the corresponding
* info_teleport_destination entity. You must set the "target" field,
If the trigger_teleport has a targetname, it will only teleport * and create an object with a "targetname" field that matches.
entities when it has been fired. *
* If the trigger_teleport has a targetname, it will only teleport
player_only: only players are teleported * entities when it has been fired.
silent: <not used right now> *
ctf_only: <not used right now> * player_only: only players are teleported
start_on: when trigger has targetname, start active, deactivate when used. * silent: <not used right now>
*/ * ctf_only: <not used right now>
void trigger_teleport_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf) * start_on: when trigger has targetname, start active, deactivate when used.
*/
void
trigger_teleport_touch(edict_t *self, edict_t *other, cplane_t *plane /* unused */,
csurface_t *surf /* unused */)
{ {
edict_t *dest; edict_t *dest;
int i; int i;
if(!(other->client)) if (!self || !other)
{
return; return;
}
if(self->delay) if (!(other->client))
{
return; return;
}
dest = G_Find (NULL, FOFS(targetname), self->target); if (self->delay)
if(!dest) {
return;
}
dest = G_Find(NULL, FOFS(targetname), self->target);
if (!dest)
{ {
gi.dprintf("Teleport Destination not found!\n"); gi.dprintf("Teleport Destination not found!\n");
return; return;
} }
gi.WriteByte (svc_temp_entity); gi.WriteByte(svc_temp_entity);
gi.WriteByte (TE_TELEPORT_EFFECT); gi.WriteByte(TE_TELEPORT_EFFECT);
gi.WritePosition (other->s.origin); gi.WritePosition(other->s.origin);
gi.multicast (other->s.origin, MULTICAST_PVS); gi.multicast(other->s.origin, MULTICAST_PVS);
// unlink to make sure it can't possibly interfere with KillBox /* unlink to make sure it can't possibly interfere with KillBox */
gi.unlinkentity (other); gi.unlinkentity(other);
VectorCopy (dest->s.origin, other->s.origin); VectorCopy(dest->s.origin, other->s.origin);
VectorCopy (dest->s.origin, other->s.old_origin); VectorCopy(dest->s.origin, other->s.old_origin);
other->s.origin[2] += 10; other->s.origin[2] += 10;
// clear the velocity and hold them in place briefly /* clear the velocity and hold them in place briefly */
VectorClear (other->velocity); VectorClear(other->velocity);
if(other->client)
if (other->client)
{ {
other->client->ps.pmove.pm_time = 160>>3; // hold time other->client->ps.pmove.pm_time = 160 >> 3; /* hold time */
other->client->ps.pmove.pm_flags |= PMF_TIME_TELEPORT; other->client->ps.pmove.pm_flags |= PMF_TIME_TELEPORT;
// draw the teleport splash at source and on the player /* draw the teleport splash at source and on the player */
other->s.event = EV_PLAYER_TELEPORT; other->s.event = EV_PLAYER_TELEPORT;
// set angles /* set angles */
for (i=0 ; i<3 ; i++) for (i = 0; i < 3; i++)
other->client->ps.pmove.delta_angles[i] = ANGLE2SHORT(dest->s.angles[i] - other->client->resp.cmd_angles[i]); {
other->client->ps.pmove.delta_angles[i] = ANGLE2SHORT(
dest->s.angles[i] - other->client->resp.cmd_angles[i]);
}
VectorClear (other->client->ps.viewangles); VectorClear(other->client->ps.viewangles);
VectorClear (other->client->v_angle); VectorClear(other->client->v_angle);
} }
VectorClear(other->s.angles);
VectorClear (other->s.angles); /* kill anything at the destination */
KillBox(other);
// kill anything at the destination gi.linkentity(other);
KillBox (other);
gi.linkentity (other);
} }
void trigger_teleport_use (edict_t *self, edict_t *other, edict_t *activator) void
trigger_teleport_use(edict_t *self, edict_t *other /* unused */, edict_t *activator /* unused */)
{ {
if(self->delay) if (!self)
{
return;
}
if (self->delay)
{
self->delay = 0; self->delay = 0;
}
else else
{
self->delay = 1; self->delay = 1;
}
} }
void SP_trigger_teleport(edict_t *self) void
SP_trigger_teleport(edict_t *self)
{ {
if (!self)
{
return;
}
if (!self->wait) if (!self->wait)
{
self->wait = 0.2; self->wait = 0.2;
}
self->delay = 0; self->delay = 0;
if (self->targetname) if (self->targetname)
{ {
self->use = trigger_teleport_use; self->use = trigger_teleport_use;
if(!(self->spawnflags & TELEPORT_START_ON))
if (!(self->spawnflags & TELEPORT_START_ON))
{
self->delay = 1; self->delay = 1;
}
} }
self->touch = trigger_teleport_touch; self->touch = trigger_teleport_touch;
@ -116,60 +161,89 @@ void SP_trigger_teleport(edict_t *self)
self->movetype = MOVETYPE_NONE; self->movetype = MOVETYPE_NONE;
if (!VectorCompare(self->s.angles, vec3_origin)) if (!VectorCompare(self->s.angles, vec3_origin))
G_SetMovedir (self->s.angles, self->movedir); {
G_SetMovedir(self->s.angles, self->movedir);
}
gi.setmodel (self, self->model); gi.setmodel(self, self->model);
gi.linkentity (self); gi.linkentity(self);
} }
// *************************** /*
// TRIGGER_DISGUISE * QUAKED trigger_disguise (.5 .5 .5) ? TOGGLE START_ON REMOVE
// *************************** *
* Anything passing through this trigger when it is active will
* be marked as disguised.
*
* TOGGLE - field is turned off and on when used.
* START_ON - field is active when spawned.
* REMOVE - field removes the disguise
*/
/*QUAKED trigger_disguise (.5 .5 .5) ? TOGGLE START_ON REMOVE void
Anything passing through this trigger when it is active will trigger_disguise_touch(edict_t *self, edict_t *other, cplane_t *plane /* unused */,
be marked as disguised. csurface_t *surf /* unused */)
TOGGLE - field is turned off and on when used.
START_ON - field is active when spawned.
REMOVE - field removes the disguise
*/
void trigger_disguise_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{ {
if (!self || !other)
{
return;
}
if (other->client) if (other->client)
{ {
if(self->spawnflags & 4) if (self->spawnflags & 4)
{
other->flags &= ~FL_DISGUISED; other->flags &= ~FL_DISGUISED;
}
else else
{
other->flags |= FL_DISGUISED; other->flags |= FL_DISGUISED;
}
} }
} }
void trigger_disguise_use (edict_t *self, edict_t *other, edict_t *activator) void
trigger_disguise_use(edict_t *self, edict_t *other /* unused */, edict_t *activator /* unused */)
{ {
if(self->solid == SOLID_NOT) if (!self)
{
return;
}
if (self->solid == SOLID_NOT)
{
self->solid = SOLID_TRIGGER; self->solid = SOLID_TRIGGER;
}
else else
{
self->solid = SOLID_NOT; self->solid = SOLID_NOT;
}
gi.linkentity(self); gi.linkentity(self);
} }
void SP_trigger_disguise (edict_t *self) void
SP_trigger_disguise(edict_t *self)
{ {
if(self->spawnflags & 2) if (!self)
{
return;
}
if (self->spawnflags & 2)
{
self->solid = SOLID_TRIGGER; self->solid = SOLID_TRIGGER;
}
else else
{
self->solid = SOLID_NOT; self->solid = SOLID_NOT;
}
self->touch = trigger_disguise_touch; self->touch = trigger_disguise_touch;
self->use = trigger_disguise_use; self->use = trigger_disguise_use;
self->movetype = MOVETYPE_NONE; self->movetype = MOVETYPE_NONE;
self->svflags = SVF_NOCLIENT; self->svflags = SVF_NOCLIENT;
gi.setmodel (self, self->model); gi.setmodel(self, self->model);
gi.linkentity(self); gi.linkentity(self);
} }