mirror of
https://github.com/yquake2/rogue.git
synced 2024-11-22 20:31:50 +00:00
Cleanup g_newfnc.c and add santiy checks
This commit is contained in:
parent
579b6cc413
commit
4816a3ae03
1 changed files with 266 additions and 134 deletions
288
src/g_newfnc.c
288
src/g_newfnc.c
|
@ -1,7 +1,12 @@
|
|||
#include "header/local.h"
|
||||
/*
|
||||
* =======================================================================
|
||||
*
|
||||
* Rogue specific level functions.
|
||||
*
|
||||
* =======================================================================
|
||||
*/
|
||||
|
||||
//void plat_CalcMove (edict_t *ent, vec3_t dest, void(*func)(edict_t*));
|
||||
void Move_Calc (edict_t *ent, vec3_t dest, void(*func)(edict_t*));
|
||||
#include "header/local.h"
|
||||
|
||||
void fd_secret_move1(edict_t *self);
|
||||
void fd_secret_move2(edict_t *self);
|
||||
|
@ -10,63 +15,106 @@ void fd_secret_move4(edict_t *self);
|
|||
void fd_secret_move5(edict_t *self);
|
||||
void fd_secret_move6(edict_t *self);
|
||||
void fd_secret_done(edict_t *self);
|
||||
void Move_Calc(edict_t *ent, vec3_t dest, void (*func)(edict_t *));
|
||||
|
||||
/*
|
||||
=============================================================================
|
||||
|
||||
SECRET DOORS
|
||||
|
||||
=============================================================================
|
||||
* =============================================================================
|
||||
*
|
||||
* SECRET DOORS
|
||||
*
|
||||
* =============================================================================
|
||||
*/
|
||||
|
||||
#define SEC_OPEN_ONCE 1 // stays open
|
||||
#define SEC_1ST_LEFT 2 // 1st move is left of arrow
|
||||
#define SEC_1ST_DOWN 4 // 1st move is down from arrow
|
||||
#define SEC_NO_SHOOT 8 // only opened by trigger
|
||||
#define SEC_YES_SHOOT 16 // shootable even if targeted
|
||||
#define SEC_OPEN_ONCE 1 /* stays open */
|
||||
#define SEC_1ST_LEFT 2 /* 1st move is left of arrow */
|
||||
#define SEC_1ST_DOWN 4 /* 1st move is down from arrow */
|
||||
#define SEC_NO_SHOOT 8 /* only opened by trigger */
|
||||
#define SEC_YES_SHOOT 16 /* shootable even if targeted */
|
||||
#define SEC_MOVE_RIGHT 32
|
||||
#define SEC_MOVE_FORWARD 64
|
||||
|
||||
void fd_secret_use (edict_t *self, edict_t *other, edict_t *activator)
|
||||
void
|
||||
fd_secret_use(edict_t *self, edict_t *other /* unused */, edict_t *activator /* unused */)
|
||||
{
|
||||
edict_t *ent;
|
||||
|
||||
if (self->flags & FL_TEAMSLAVE)
|
||||
if (!self)
|
||||
{
|
||||
return;
|
||||
|
||||
// trigger all paired doors
|
||||
for (ent = self ; ent ; ent = ent->teamchain)
|
||||
Move_Calc(ent, ent->moveinfo.start_origin, fd_secret_move1);
|
||||
|
||||
}
|
||||
|
||||
void fd_secret_killed (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
|
||||
if (self->flags & FL_TEAMSLAVE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* trigger all paired doors */
|
||||
for (ent = self; ent; ent = ent->teamchain)
|
||||
{
|
||||
Move_Calc(ent, ent->moveinfo.start_origin, fd_secret_move1);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
fd_secret_killed(edict_t *self, edict_t *inflictor, edict_t *attacker,
|
||||
int damage, vec3_t point)
|
||||
{
|
||||
if (!self || !inflictor || !attacker)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
self->health = self->max_health;
|
||||
self->takedamage = DAMAGE_NO;
|
||||
|
||||
if (self->flags & FL_TEAMSLAVE && self->teammaster && self->teammaster->takedamage != DAMAGE_NO)
|
||||
if (self->flags & FL_TEAMSLAVE && self->teammaster &&
|
||||
(self->teammaster->takedamage != DAMAGE_NO))
|
||||
{
|
||||
fd_secret_killed(self->teammaster, inflictor, attacker, damage, point);
|
||||
}
|
||||
else
|
||||
{
|
||||
fd_secret_use(self, inflictor, attacker);
|
||||
}
|
||||
}
|
||||
|
||||
// Wait after first movement...
|
||||
void fd_secret_move1(edict_t *self)
|
||||
void
|
||||
fd_secret_move1(edict_t *self)
|
||||
{
|
||||
if (!self)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
self->nextthink = level.time + 1.0;
|
||||
self->think = fd_secret_move2;
|
||||
}
|
||||
|
||||
// Start moving sideways w/sound...
|
||||
void fd_secret_move2(edict_t *self)
|
||||
/*
|
||||
* Start moving sideways w/sound...
|
||||
*/
|
||||
void
|
||||
fd_secret_move2(edict_t *self)
|
||||
{
|
||||
if (!self)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Move_Calc(self, self->moveinfo.end_origin, fd_secret_move3);
|
||||
}
|
||||
|
||||
// Wait here until time to go back...
|
||||
void fd_secret_move3(edict_t *self)
|
||||
/*
|
||||
* Wait here until time to go back...
|
||||
*/
|
||||
void
|
||||
fd_secret_move3(edict_t *self)
|
||||
{
|
||||
if (!self)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(self->spawnflags & SEC_OPEN_ONCE))
|
||||
{
|
||||
self->nextthink = level.time + self->wait;
|
||||
|
@ -74,26 +122,54 @@ void fd_secret_move3(edict_t *self)
|
|||
}
|
||||
}
|
||||
|
||||
// Move backward...
|
||||
void fd_secret_move4(edict_t *self)
|
||||
/*
|
||||
* Move backward...
|
||||
*/
|
||||
void
|
||||
fd_secret_move4(edict_t *self)
|
||||
{
|
||||
if (!self)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Move_Calc(self, self->moveinfo.start_origin, fd_secret_move5);
|
||||
}
|
||||
|
||||
// Wait 1 second...
|
||||
void fd_secret_move5(edict_t *self)
|
||||
/*
|
||||
* Wait 1 second...
|
||||
*/
|
||||
void
|
||||
fd_secret_move5(edict_t *self)
|
||||
{
|
||||
if (!self)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
self->nextthink = level.time + 1.0;
|
||||
self->think = fd_secret_move6;
|
||||
}
|
||||
|
||||
void fd_secret_move6(edict_t *self)
|
||||
void
|
||||
fd_secret_move6(edict_t *self)
|
||||
{
|
||||
if (!self)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Move_Calc(self, self->move_origin, fd_secret_done);
|
||||
}
|
||||
|
||||
void fd_secret_done(edict_t *self)
|
||||
void
|
||||
fd_secret_done(edict_t *self)
|
||||
{
|
||||
if (!self)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!self->targetname || self->spawnflags & SEC_YES_SHOOT)
|
||||
{
|
||||
self->health = 1;
|
||||
|
@ -102,29 +178,46 @@ void fd_secret_done(edict_t *self)
|
|||
}
|
||||
}
|
||||
|
||||
void secret_blocked(edict_t *self, edict_t *other)
|
||||
void
|
||||
secret_blocked(edict_t *self, edict_t *other)
|
||||
{
|
||||
if (!self || !other)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(self->flags & FL_TEAMSLAVE))
|
||||
T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, self->dmg, 0, 0, MOD_CRUSH);
|
||||
{
|
||||
T_Damage(other, self, self, vec3_origin, other->s.origin,
|
||||
vec3_origin, self->dmg, 0, 0, MOD_CRUSH);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
secret_touch
|
||||
|
||||
Prints messages
|
||||
================
|
||||
* Prints messages
|
||||
*/
|
||||
void secret_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
|
||||
void
|
||||
secret_touch(edict_t *self, edict_t *other, cplane_t *plane /* unused */, csurface_t *surf /* unused */)
|
||||
{
|
||||
if (!self || !other)
|
||||
{
|
||||
if (other->health <= 0)
|
||||
return;
|
||||
}
|
||||
|
||||
if (other->health <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(other->client))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (self->monsterinfo.attack_finished > level.time)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
self->monsterinfo.attack_finished = level.time + 2;
|
||||
|
||||
|
@ -134,36 +227,43 @@ void secret_touch(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *su
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*QUAKED func_door_secret2 (0 .5 .8) ? open_once 1st_left 1st_down no_shoot always_shoot slide_right slide_forward
|
||||
Basic secret door. Slides back, then to the left. Angle determines direction.
|
||||
|
||||
FLAGS:
|
||||
open_once = not implemented yet
|
||||
1st_left = 1st move is left/right of arrow
|
||||
1st_down = 1st move is forwards/backwards
|
||||
no_shoot = not implemented yet
|
||||
always_shoot = even if targeted, keep shootable
|
||||
reverse_left = the sideways move will be to right of arrow
|
||||
reverse_back = the to/fro move will be forward
|
||||
|
||||
VALUES:
|
||||
wait = # of seconds before coming back (5 default)
|
||||
dmg = damage to inflict when blocked (2 default)
|
||||
|
||||
/*
|
||||
* QUAKED func_door_secret2 (0 .5 .8) ? open_once 1st_left 1st_down no_shoot always_shoot slide_right slide_forward
|
||||
*
|
||||
* Basic secret door. Slides back, then to the left. Angle determines direction.
|
||||
*
|
||||
* FLAGS:
|
||||
* open_once = not implemented yet
|
||||
* 1st_left = 1st move is left/right of arrow
|
||||
* 1st_down = 1st move is forwards/backwards
|
||||
* no_shoot = not implemented yet
|
||||
* always_shoot = even if targeted, keep shootable
|
||||
* reverse_left = the sideways move will be to right of arrow
|
||||
* reverse_back = the to/fro move will be forward
|
||||
*
|
||||
* VALUES:
|
||||
* wait = # of seconds before coming back (5 default)
|
||||
* dmg = damage to inflict when blocked (2 default)
|
||||
*/
|
||||
|
||||
void SP_func_door_secret2 (edict_t *ent)
|
||||
void
|
||||
SP_func_door_secret2(edict_t *ent)
|
||||
{
|
||||
vec3_t forward, right, up;
|
||||
float lrSize = 0, fbSize = 0;
|
||||
|
||||
if (!ent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ent->moveinfo.sound_start = gi.soundindex("doors/dr1_strt.wav");
|
||||
ent->moveinfo.sound_middle = gi.soundindex("doors/dr1_mid.wav");
|
||||
ent->moveinfo.sound_end = gi.soundindex("doors/dr1_end.wav");
|
||||
|
||||
if (!ent->dmg)
|
||||
{
|
||||
ent->dmg = 2;
|
||||
}
|
||||
|
||||
AngleVectors(ent->s.angles, forward, right, up);
|
||||
VectorCopy(ent->s.origin, ent->move_origin);
|
||||
|
@ -174,12 +274,12 @@ void SP_func_door_secret2 (edict_t *ent)
|
|||
ent->solid = SOLID_BSP;
|
||||
gi.setmodel(ent, ent->model);
|
||||
|
||||
if(ent->move_angles[1] == 0 || ent->move_angles[1] == 180)
|
||||
if ((ent->move_angles[1] == 0) || (ent->move_angles[1] == 180))
|
||||
{
|
||||
lrSize = ent->size[1];
|
||||
fbSize = ent->size[0];
|
||||
}
|
||||
else if(ent->move_angles[1] == 90 || ent->move_angles[1] == 270)
|
||||
else if ((ent->move_angles[1] == 90) || (ent->move_angles[1] == 270))
|
||||
{
|
||||
lrSize = ent->size[0];
|
||||
fbSize = ent->size[1];
|
||||
|
@ -190,14 +290,18 @@ void SP_func_door_secret2 (edict_t *ent)
|
|||
}
|
||||
|
||||
if (ent->spawnflags & SEC_MOVE_FORWARD)
|
||||
{
|
||||
VectorScale(forward, fbSize, forward);
|
||||
}
|
||||
else
|
||||
{
|
||||
VectorScale(forward, fbSize * -1, forward);
|
||||
}
|
||||
|
||||
if (ent->spawnflags & SEC_MOVE_RIGHT)
|
||||
{
|
||||
VectorScale(right, lrSize, right);
|
||||
}
|
||||
else
|
||||
{
|
||||
VectorScale(right, lrSize * -1, right);
|
||||
|
@ -228,18 +332,27 @@ void SP_func_door_secret2 (edict_t *ent)
|
|||
ent->takedamage = DAMAGE_YES;
|
||||
ent->die = fd_secret_killed;
|
||||
}
|
||||
|
||||
if (!ent->wait)
|
||||
ent->wait = 5; // 5 seconds before closing
|
||||
{
|
||||
ent->wait = 5; /* 5 seconds before closing */
|
||||
}
|
||||
|
||||
gi.linkentity(ent);
|
||||
}
|
||||
|
||||
// ==================================================
|
||||
/* ================================================== */
|
||||
|
||||
#define FWALL_START_ON 1
|
||||
|
||||
void force_wall_think(edict_t *self)
|
||||
void
|
||||
force_wall_think(edict_t *self)
|
||||
{
|
||||
if (!self)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!self->wait)
|
||||
{
|
||||
gi.WriteByte(svc_temp_entity);
|
||||
|
@ -254,8 +367,15 @@ void force_wall_think(edict_t *self)
|
|||
self->nextthink = level.time + 0.1;
|
||||
}
|
||||
|
||||
void force_wall_use (edict_t *self, edict_t *other, edict_t *activator)
|
||||
void
|
||||
force_wall_use(edict_t *self, edict_t *other /* activator */,
|
||||
edict_t *activator /* activator */)
|
||||
{
|
||||
if (!self)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!self->wait)
|
||||
{
|
||||
self->wait = 1;
|
||||
|
@ -270,21 +390,29 @@ void force_wall_use (edict_t *self, edict_t *other, edict_t *activator)
|
|||
self->think = force_wall_think;
|
||||
self->nextthink = level.time + 0.1;
|
||||
self->solid = SOLID_BSP;
|
||||
KillBox(self); // Is this appropriate?
|
||||
KillBox(self); /* Is this appropriate? */
|
||||
gi.linkentity(self);
|
||||
}
|
||||
}
|
||||
|
||||
/*QUAKED func_force_wall (1 0 1) ? start_on
|
||||
A vertical particle force wall. Turns on and solid when triggered.
|
||||
If someone is in the force wall when it turns on, they're telefragged.
|
||||
|
||||
start_on - forcewall begins activated. triggering will turn it off.
|
||||
style - color of particles to use.
|
||||
208: green, 240: red, 241: blue, 224: orange
|
||||
/*
|
||||
* QUAKED func_force_wall (1 0 1) ? start_on
|
||||
*
|
||||
* A vertical particle force wall. Turns on and solid when triggered.
|
||||
* If someone is in the force wall when it turns on, they're telefragged.
|
||||
*
|
||||
* start_on - forcewall begins activated. triggering will turn it off.
|
||||
* style - color of particles to use.
|
||||
* 208: green, 240: red, 241: blue, 224: orange
|
||||
*/
|
||||
void SP_func_force_wall(edict_t *ent)
|
||||
void
|
||||
SP_func_force_wall(edict_t *ent)
|
||||
{
|
||||
if (!ent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
gi.setmodel(ent, ent->model);
|
||||
|
||||
ent->offset[0] = (ent->absmax[0] + ent->absmin[0]) / 2;
|
||||
|
@ -293,6 +421,7 @@ void SP_func_force_wall(edict_t *ent)
|
|||
|
||||
ent->pos1[2] = ent->absmax[2];
|
||||
ent->pos2[2] = ent->absmax[2];
|
||||
|
||||
if (ent->size[0] > ent->size[1])
|
||||
{
|
||||
ent->pos1[0] = ent->absmin[0];
|
||||
|
@ -309,7 +438,9 @@ void SP_func_force_wall(edict_t *ent)
|
|||
}
|
||||
|
||||
if (!ent->style)
|
||||
{
|
||||
ent->style = 208;
|
||||
}
|
||||
|
||||
ent->movetype = MOVETYPE_NONE;
|
||||
ent->wait = 1;
|
||||
|
@ -321,7 +452,9 @@ void SP_func_force_wall(edict_t *ent)
|
|||
ent->nextthink = level.time + 0.1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ent->solid = SOLID_NOT;
|
||||
}
|
||||
|
||||
ent->use = force_wall_use;
|
||||
|
||||
|
@ -329,4 +462,3 @@ void SP_func_force_wall(edict_t *ent)
|
|||
|
||||
gi.linkentity(ent);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue