📄 g_func.c
字号:
{
VectorClear (ent->s.angles);
ent->solid = SOLID_BSP;
ent->movetype = MOVETYPE_PUSH;
gi.setmodel (ent, ent->model);
ent->blocked = plat_blocked;
if (!ent->speed)
ent->speed = 20;
else
ent->speed *= 0.1;
if (!ent->accel)
ent->accel = 5;
else
ent->accel *= 0.1;
if (!ent->decel)
ent->decel = 5;
else
ent->decel *= 0.1;
if (!ent->dmg)
ent->dmg = 2;
if (!st.lip)
st.lip = 8;
// pos1 is the top position, pos2 is the bottom
VectorCopy (ent->s.origin, ent->pos1);
VectorCopy (ent->s.origin, ent->pos2);
if (st.height)
ent->pos2[2] -= st.height;
else
ent->pos2[2] -= (ent->maxs[2] - ent->mins[2]) - st.lip;
ent->use = Use_Plat;
plat_spawn_inside_trigger (ent); // the "start moving" trigger
if (ent->targetname)
{
ent->moveinfo.state = STATE_UP;
}
else
{
VectorCopy (ent->pos2, ent->s.origin);
gi.linkentity (ent);
ent->moveinfo.state = STATE_BOTTOM;
}
ent->moveinfo.speed = ent->speed;
ent->moveinfo.accel = ent->accel;
ent->moveinfo.decel = ent->decel;
ent->moveinfo.wait = ent->wait;
VectorCopy (ent->pos1, ent->moveinfo.start_origin);
VectorCopy (ent->s.angles, ent->moveinfo.start_angles);
VectorCopy (ent->pos2, ent->moveinfo.end_origin);
VectorCopy (ent->s.angles, ent->moveinfo.end_angles);
ent->moveinfo.sound_start = gi.soundindex ("plats/pt1_strt.wav");
ent->moveinfo.sound_middle = gi.soundindex ("plats/pt1_mid.wav");
ent->moveinfo.sound_end = gi.soundindex ("plats/pt1_end.wav");
}
//====================================================================
/*QUAKED func_rotating (0 .5 .8) ? START_ON REVERSE X_AXIS Y_AXIS TOUCH_PAIN STOP ANIMATED ANIMATED_FAST
You need to have an origin brush as part of this entity. The center of that brush will be
the point around which it is rotated. It will rotate around the Z axis by default. You can
check either the X_AXIS or Y_AXIS box to change that.
"speed" determines how fast it moves; default value is 100.
"dmg" damage to inflict when blocked (2 default)
REVERSE will cause the it to rotate in the opposite direction.
STOP mean it will stop moving instead of pushing entities
*/
void rotating_blocked (edict_t *self, edict_t *other)
{
T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, self->dmg, 1, 0, MOD_CRUSH);
}
void rotating_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
if (self->avelocity[0] || self->avelocity[1] || self->avelocity[2])
T_Damage (other, self, self, vec3_origin, other->s.origin, vec3_origin, self->dmg, 1, 0, MOD_CRUSH);
}
void rotating_use (edict_t *self, edict_t *other, edict_t *activator)
{
if (!VectorCompare (self->avelocity, vec3_origin))
{
self->s.sound = 0;
VectorClear (self->avelocity);
self->touch = NULL;
}
else
{
self->s.sound = self->moveinfo.sound_middle;
VectorScale (self->movedir, self->speed, self->avelocity);
if (self->spawnflags & 16)
self->touch = rotating_touch;
}
}
void SP_func_rotating (edict_t *ent)
{
ent->solid = SOLID_BSP;
if (ent->spawnflags & 32)
ent->movetype = MOVETYPE_STOP;
else
ent->movetype = MOVETYPE_PUSH;
// set the axis of rotation
VectorClear(ent->movedir);
if (ent->spawnflags & 4)
ent->movedir[2] = 1.0;
else if (ent->spawnflags & 8)
ent->movedir[0] = 1.0;
else // Z_AXIS
ent->movedir[1] = 1.0;
// check for reverse rotation
if (ent->spawnflags & 2)
VectorNegate (ent->movedir, ent->movedir);
if (!ent->speed)
ent->speed = 100;
if (!ent->dmg)
ent->dmg = 2;
// ent->moveinfo.sound_middle = "doors/hydro1.wav";
ent->use = rotating_use;
if (ent->dmg)
ent->blocked = rotating_blocked;
if (ent->spawnflags & 1)
ent->use (ent, NULL, NULL);
if (ent->spawnflags & 64)
ent->s.effects |= EF_ANIM_ALL;
if (ent->spawnflags & 128)
ent->s.effects |= EF_ANIM_ALLFAST;
gi.setmodel (ent, ent->model);
gi.linkentity (ent);
}
/*
======================================================================
BUTTONS
======================================================================
*/
/*QUAKED func_button (0 .5 .8) ?
When a button is touched, it moves some distance in the direction of it's angle, triggers all of it's targets, waits some time, then returns to it's original position where it can be triggered again.
"angle" determines the opening direction
"target" all entities with a matching targetname will be used
"speed" override the default 40 speed
"wait" override the default 1 second wait (-1 = never return)
"lip" override the default 4 pixel lip remaining at end of move
"health" if set, the button must be killed instead of touched
"sounds"
1) silent
2) steam metal
3) wooden clunk
4) metallic click
5) in-out
*/
void button_done (edict_t *self)
{
self->moveinfo.state = STATE_BOTTOM;
self->s.effects &= ~EF_ANIM23;
self->s.effects |= EF_ANIM01;
}
void button_return (edict_t *self)
{
self->moveinfo.state = STATE_DOWN;
Move_Calc (self, self->moveinfo.start_origin, button_done);
self->s.frame = 0;
if (self->health)
self->takedamage = DAMAGE_YES;
}
void button_wait (edict_t *self)
{
self->moveinfo.state = STATE_TOP;
self->s.effects &= ~EF_ANIM01;
self->s.effects |= EF_ANIM23;
G_UseTargets (self, self->activator);
self->s.frame = 1;
if (self->moveinfo.wait >= 0)
{
self->nextthink = level.time + self->moveinfo.wait;
self->think = button_return;
}
}
void button_fire (edict_t *self)
{
if (self->moveinfo.state == STATE_UP || self->moveinfo.state == STATE_TOP)
return;
self->moveinfo.state = STATE_UP;
if (self->moveinfo.sound_start && !(self->flags & FL_TEAMSLAVE))
gi.sound (self, CHAN_NO_PHS_ADD+CHAN_VOICE, self->moveinfo.sound_start, 1, ATTN_STATIC, 0);
Move_Calc (self, self->moveinfo.end_origin, button_wait);
}
void button_use (edict_t *self, edict_t *other, edict_t *activator)
{
self->activator = activator;
button_fire (self);
}
void button_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
if (!other->client)
return;
if (other->health <= 0)
return;
self->activator = other;
button_fire (self);
}
void button_killed (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
self->activator = attacker;
self->health = self->max_health;
self->takedamage = DAMAGE_NO;
button_fire (self);
}
void SP_func_button (edict_t *ent)
{
vec3_t abs_movedir;
float dist;
G_SetMovedir (ent->s.angles, ent->movedir);
ent->movetype = MOVETYPE_STOP;
ent->solid = SOLID_BSP;
gi.setmodel (ent, ent->model);
if (ent->sounds != 1)
ent->moveinfo.sound_start = gi.soundindex ("switches/butn2.wav");
if (!ent->speed)
ent->speed = 40;
if (!ent->accel)
ent->accel = ent->speed;
if (!ent->decel)
ent->decel = ent->speed;
if (!ent->wait)
ent->wait = 3;
if (!st.lip)
st.lip = 4;
VectorCopy (ent->s.origin, ent->pos1);
abs_movedir[0] = fabs(ent->movedir[0]);
abs_movedir[1] = fabs(ent->movedir[1]);
abs_movedir[2] = fabs(ent->movedir[2]);
dist = abs_movedir[0] * ent->size[0] + abs_movedir[1] * ent->size[1] + abs_movedir[2] * ent->size[2] - st.lip;
VectorMA (ent->pos1, dist, ent->movedir, ent->pos2);
ent->use = button_use;
ent->s.effects |= EF_ANIM01;
if (ent->health)
{
ent->max_health = ent->health;
ent->die = button_killed;
ent->takedamage = DAMAGE_YES;
}
else if (! ent->targetname)
ent->touch = button_touch;
ent->moveinfo.state = STATE_BOTTOM;
ent->moveinfo.speed = ent->speed;
ent->moveinfo.accel = ent->accel;
ent->moveinfo.decel = ent->decel;
ent->moveinfo.wait = ent->wait;
VectorCopy (ent->pos1, ent->moveinfo.start_origin);
VectorCopy (ent->s.angles, ent->moveinfo.start_angles);
VectorCopy (ent->pos2, ent->moveinfo.end_origin);
VectorCopy (ent->s.angles, ent->moveinfo.end_angles);
gi.linkentity (ent);
}
/*
======================================================================
DOORS
spawn a trigger surrounding the entire team unless it is
already targeted by another
======================================================================
*/
/*QUAKED func_door (0 .5 .8) ? START_OPEN x CRUSHER NOMONSTER ANIMATED TOGGLE ANIMATED_FAST
TOGGLE wait in both the start and end states for a trigger event.
START_OPEN the door to moves to its destination when spawned, and operate in reverse. It is used to temporarily or permanently close off an area when triggered (not useful for touch or takedamage doors).
NOMONSTER monsters will not trigger this door
"message" is printed when the door is touched if it is a trigger door and it hasn't been fired yet
"angle" determines the opening direction
"targetname" if set, no touch field will be spawned and a remote button or trigger field activates the door.
"health" if set, door must be shot open
"speed" movement speed (100 default)
"wait" wait before returning (3 default, -1 = never return)
"lip" lip remaining at end of move (8 default)
"dmg" damage to inflict when blocked (2 default)
"sounds"
1) silent
2) light
3) medium
4) heavy
*/
void door_use_areaportals (edict_t *self, qboolean open)
{
edict_t *t = NULL;
if (!self->target)
return;
while ((t = G_Find (t, FOFS(targetname), self->target)))
{
if (Q_stricmp(t->classname, "func_areaportal") == 0)
{
gi.SetAreaPortalState (t->style, open);
}
}
}
void door_go_down (edict_t *self);
void door_hit_top (edict_t *self)
{
if (!(self->flags & FL_TEAMSLAVE))
{
if (self->moveinfo.sound_end)
gi.sound (self, CHAN_NO_PHS_ADD+CHAN_VOICE, self->moveinfo.sound_end, 1, ATTN_STATIC, 0);
self->s.sound = 0;
}
self->moveinfo.state = STATE_TOP;
if (self->spawnflags & DOOR_TOGGLE)
return;
if (self->moveinfo.wait >= 0)
{
self->think = door_go_down;
self->nextthink = level.time + self->moveinfo.wait;
}
}
void door_hit_bottom (edict_t *self)
{
if (!(self->flags & FL_TEAMSLAVE))
{
if (self->moveinfo.sound_end)
gi.sound (self, CHAN_NO_PHS_ADD+CHAN_VOICE, self->moveinfo.sound_end, 1, ATTN_STATIC, 0);
self->s.sound = 0;
}
self->moveinfo.state = STATE_BOTTOM;
door_use_areaportals (self, false);
}
void door_go_down (edict_t *self)
{
if (!(self->flags & FL_TEAMSLAVE))
{
if (self->moveinfo.sound_start)
gi.sound (self, CHAN_NO_PHS_ADD+CHAN_VOICE, self->moveinfo.sound_start, 1, ATTN_STATIC, 0);
self->s.sound = self->moveinfo.sound_middle;
}
if (self->max_health)
{
self->takedamage = DAMAGE_YES;
self->health = self->max_health;
}
self->moveinfo.state = STATE_DOWN;
if (strcmp(self->classname, "func_door") == 0)
Move_Calc (self, self->moveinfo.start_origin, door_hit_bottom);
else if (strcmp(self->classname, "func_door_rotating") == 0)
AngleMove_Calc (self, door_hit_bottom);
}
void door_go_up (edict_t *self, edict_t *activator)
{
if (self->moveinfo.state == STATE_UP)
return; // already going up
if (self->moveinfo.state == STATE_TOP)
{ // reset top wait time
if (self->moveinfo.wait >= 0)
self->nextthink = level.time + self->moveinfo.wait;
return;
}
if (!(self->flags & FL_TEAMSLAVE))
{
if (self->moveinfo.sound_start)
gi.sound (self, CHAN_NO_PHS_ADD+CHAN_VOICE, self->moveinfo.sound_start, 1, ATTN_STATIC, 0);
self->s.sound = self->moveinfo.sound_middle;
}
self->moveinfo.state = STATE_UP;
if (strcmp(self->classname, "func_door") == 0)
Move_Calc (self, self->moveinfo.end_origin, door_hit_top);
else if (strcmp(self->classname, "func_door_rotating") == 0)
AngleMove_Calc (self, door_hit_top);
G_UseTargets (self, activator);
door_use_areaportals (self, true);
}
void door_use (edict_t *self, edict_t *other, edict_t *activator)
{
edict_t *ent;
if (self->flags & FL_TEAMSLAVE)
return;
if (self->spawnflags & DOOR_TOGGLE)
{
if (self->moveinfo.state == STATE_UP || self->moveinfo.state == STATE_TOP)
{
// trigger all paired doors
for (ent = self ; ent ; ent = ent->teamchain)
{
ent->message = NULL;
ent->touch = NULL;
door_go_down (ent);
}
return;
}
}
// trigger all paired doors
for (ent = self ; ent ; ent = ent->teamchain)
{
ent->message = NULL;
ent->touch = NULL;
door_go_up (ent, activator);
}
};
void Touch_DoorTrigger (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
if (other->health <= 0)
return;
if (!(other->svflags & SVF_MONSTER) && (!other->client))
return;
if ((self->owner->spawnflags & DOOR_NOMONSTER) && (other->svflags & SVF_MONSTER))
return;
if (level.time < self->touch_debounce_time)
return;
self->touch_debounce_time = level.time + 1.0;
door_use (self->owner, other, other);
}
void Think_CalcMoveSpeed (edict_t *self)
{
edict_t *ent;
float min;
float time;
float newspeed;
float ratio;
float dist;
if (self->flags & FL_TEAMSLAVE)
return; // only the team master does this
// find the smallest distance any member of the team will be moving
min = fabs(self->moveinfo.distance);
for (ent = self->teamchain; ent; ent = ent->teamchain)
{
dist = fabs(ent->moveinfo.distance);
if (dist < min)
min = dist;
}
time = min / self->moveinfo.speed;
// adjust speeds so they will all complete at the same time
for (ent = self; ent; ent = ent->teamchain)
{
newspeed = fabs(ent->moveinfo.distance) / time;
ratio = newspeed / ent->moveinfo.speed;
if (ent->moveinfo.accel == ent->moveinfo.speed)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -