📄 g_mover.c
字号:
trigger->touch = Touch_PlatCenterTrigger;
trigger->r.contents = CONTENTS_TRIGGER;
trigger->parent = ent;
tmin[0] = ent->pos1[0] + ent->r.mins[0] + 33;
tmin[1] = ent->pos1[1] + ent->r.mins[1] + 33;
tmin[2] = ent->pos1[2] + ent->r.mins[2];
tmax[0] = ent->pos1[0] + ent->r.maxs[0] - 33;
tmax[1] = ent->pos1[1] + ent->r.maxs[1] - 33;
tmax[2] = ent->pos1[2] + ent->r.maxs[2] + 8;
if ( tmax[0] <= tmin[0] ) {
tmin[0] = ent->pos1[0] + (ent->r.mins[0] + ent->r.maxs[0]) *0.5;
tmax[0] = tmin[0] + 1;
}
if ( tmax[1] <= tmin[1] ) {
tmin[1] = ent->pos1[1] + (ent->r.mins[1] + ent->r.maxs[1]) *0.5;
tmax[1] = tmin[1] + 1;
}
VectorCopy (tmin, trigger->r.mins);
VectorCopy (tmax, trigger->r.maxs);
trap_LinkEntity (trigger);
}
/*QUAKED func_plat (0 .5 .8) ?
Plats are always drawn in the extended position so they will light correctly.
"lip" default 8, protrusion above rest position
"height" total height of movement, defaults to model height
"speed" overrides default 200.
"dmg" overrides default 2
"model2" .md3 model to also draw
"color" constantLight color
"light" constantLight radius
*/
void SP_func_plat (gentity_t *ent) {
float lip, height;
ent->sound1to2 = ent->sound2to1 = G_SoundIndex("sound/movers/plats/pt1_strt.wav");
ent->soundPos1 = ent->soundPos2 = G_SoundIndex("sound/movers/plats/pt1_end.wav");
VectorClear (ent->s.angles);
G_SpawnFloat( "speed", "200", &ent->speed );
G_SpawnInt( "dmg", "2", &ent->damage );
G_SpawnFloat( "wait", "1", &ent->wait );
G_SpawnFloat( "lip", "8", &lip );
ent->wait = 1000;
// create second position
trap_SetBrushModel( ent, ent->model );
if ( !G_SpawnFloat( "height", "0", &height ) ) {
height = (ent->r.maxs[2] - ent->r.mins[2]) - lip;
}
// pos1 is the rest (bottom) position, pos2 is the top
VectorCopy( ent->s.origin, ent->pos2 );
VectorCopy( ent->pos2, ent->pos1 );
ent->pos1[2] -= height;
InitMover( ent );
// touch function keeps the plat from returning while
// a live player is standing on it
ent->touch = Touch_Plat;
ent->blocked = Blocked_Door;
ent->parent = ent; // so it can be treated as a door
// spawn the trigger if one hasn't been custom made
if ( !ent->targetname ) {
SpawnPlatTrigger(ent);
}
}
/*
===============================================================================
BUTTON
===============================================================================
*/
/*
==============
Touch_Button
===============
*/
void Touch_Button(gentity_t *ent, gentity_t *other, trace_t *trace ) {
if ( !other->client ) {
return;
}
if ( ent->moverState == MOVER_POS1 ) {
Use_BinaryMover( ent, other, other );
}
}
/*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.
"model2" .md3 model to also draw
"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
"color" constantLight color
"light" constantLight radius
*/
void SP_func_button( gentity_t *ent ) {
vec3_t abs_movedir;
float distance;
vec3_t size;
float lip;
ent->sound1to2 = G_SoundIndex("sound/movers/switches/butn2.wav");
if ( !ent->speed ) {
ent->speed = 40;
}
if ( !ent->wait ) {
ent->wait = 1;
}
ent->wait *= 1000;
// first position
VectorCopy( ent->s.origin, ent->pos1 );
// calculate second position
trap_SetBrushModel( ent, ent->model );
G_SpawnFloat( "lip", "4", &lip );
G_SetMovedir( ent->s.angles, ent->movedir );
abs_movedir[0] = fabs(ent->movedir[0]);
abs_movedir[1] = fabs(ent->movedir[1]);
abs_movedir[2] = fabs(ent->movedir[2]);
VectorSubtract( ent->r.maxs, ent->r.mins, size );
distance = abs_movedir[0] * size[0] + abs_movedir[1] * size[1] + abs_movedir[2] * size[2] - lip;
VectorMA (ent->pos1, distance, ent->movedir, ent->pos2);
if (ent->health) {
// shootable button
ent->takedamage = qtrue;
} else {
// touchable button
ent->touch = Touch_Button;
}
InitMover( ent );
}
/*
===============================================================================
TRAIN
===============================================================================
*/
#define TRAIN_START_ON 1
#define TRAIN_TOGGLE 2
#define TRAIN_BLOCK_STOPS 4
/*
===============
Think_BeginMoving
The wait time at a corner has completed, so start moving again
===============
*/
void Think_BeginMoving( gentity_t *ent ) {
ent->s.pos.trTime = level.time;
ent->s.pos.trType = TR_LINEAR_STOP;
}
/*
===============
Reached_Train
===============
*/
void Reached_Train( gentity_t *ent ) {
gentity_t *next;
float speed;
vec3_t move;
float length;
// copy the apropriate values
next = ent->nextTrain;
if ( !next || !next->nextTrain ) {
return; // just stop
}
// fire all other targets
G_UseTargets( next, NULL );
// set the new trajectory
ent->nextTrain = next->nextTrain;
VectorCopy( next->s.origin, ent->pos1 );
VectorCopy( next->nextTrain->s.origin, ent->pos2 );
// if the path_corner has a speed, use that
if ( next->speed ) {
speed = next->speed;
} else {
// otherwise use the train's speed
speed = ent->speed;
}
if ( speed < 1 ) {
speed = 1;
}
// calculate duration
VectorSubtract( ent->pos2, ent->pos1, move );
length = VectorLength( move );
ent->s.pos.trDuration = length * 1000 / speed;
// looping sound
ent->s.loopSound = next->soundLoop;
// start it going
SetMoverState( ent, MOVER_1TO2, level.time );
// if there is a "wait" value on the target, don't start moving yet
if ( next->wait ) {
ent->nextthink = level.time + next->wait * 1000;
ent->think = Think_BeginMoving;
ent->s.pos.trType = TR_STATIONARY;
}
}
/*
===============
Think_SetupTrainTargets
Link all the corners together
===============
*/
void Think_SetupTrainTargets( gentity_t *ent ) {
gentity_t *path, *next, *start;
ent->nextTrain = G_Find( NULL, FOFS(targetname), ent->target );
if ( !ent->nextTrain ) {
G_Printf( "func_train at %s with an unfound target\n",
vtos(ent->r.absmin) );
return;
}
start = NULL;
for ( path = ent->nextTrain ; path != start ; path = next ) {
if ( !start ) {
start = path;
}
if ( !path->target ) {
G_Printf( "Train corner at %s without a target\n",
vtos(path->s.origin) );
return;
}
// find a path_corner among the targets
// there may also be other targets that get fired when the corner
// is reached
next = NULL;
do {
next = G_Find( next, FOFS(targetname), path->target );
if ( !next ) {
G_Printf( "Train corner at %s without a target path_corner\n",
vtos(path->s.origin) );
return;
}
} while ( strcmp( next->classname, "path_corner" ) );
path->nextTrain = next;
}
// start the train moving from the first corner
Reached_Train( ent );
}
/*QUAKED path_corner (.5 .3 0) (-8 -8 -8) (8 8 8)
Train path corners.
Target: next path corner and other targets to fire
"speed" speed to move to the next corner
"wait" seconds to wait before behining move to next corner
*/
void SP_path_corner( gentity_t *self ) {
if ( !self->targetname ) {
G_Printf ("path_corner with no targetname at %s\n", vtos(self->s.origin));
G_FreeEntity( self );
return;
}
// path corners don't need to be linked in
}
/*QUAKED func_train (0 .5 .8) ? START_ON TOGGLE BLOCK_STOPS
A train is a mover that moves between path_corner target points.
Trains MUST HAVE AN ORIGIN BRUSH.
The train spawns at the first target it is pointing at.
"model2" .md3 model to also draw
"speed" default 100
"dmg" default 2
"noise" looping sound to play when the train is in motion
"target" next path corner
"color" constantLight color
"light" constantLight radius
*/
void SP_func_train (gentity_t *self) {
VectorClear (self->s.angles);
if (self->spawnflags & TRAIN_BLOCK_STOPS) {
self->damage = 0;
} else {
if (!self->damage) {
self->damage = 2;
}
}
if ( !self->speed ) {
self->speed = 100;
}
if ( !self->target ) {
G_Printf ("func_train without a target at %s\n", vtos(self->r.absmin));
G_FreeEntity( self );
return;
}
trap_SetBrushModel( self, self->model );
InitMover( self );
self->reached = Reached_Train;
// start trains on the second frame, to make sure their targets have had
// a chance to spawn
self->nextthink = level.time + FRAMETIME;
self->think = Think_SetupTrainTargets;
}
/*
===============================================================================
STATIC
===============================================================================
*/
/*QUAKED func_static (0 .5 .8) ?
A bmodel that just sits there, doing nothing. Can be used for conditional walls and models.
"model2" .md3 model to also draw
"color" constantLight color
"light" constantLight radius
*/
void SP_func_static( gentity_t *ent ) {
trap_SetBrushModel( ent, ent->model );
InitMover( ent );
VectorCopy( ent->s.origin, ent->s.pos.trBase );
VectorCopy( ent->s.origin, ent->r.currentOrigin );
}
/*
===============================================================================
ROTATING
===============================================================================
*/
/*QUAKED func_rotating (0 .5 .8) ? START_ON - X_AXIS Y_AXIS
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.
"model2" .md3 model to also draw
"speed" determines how fast it moves; default value is 100.
"dmg" damage to inflict when blocked (2 default)
"color" constantLight color
"light" constantLight radius
*/
void SP_func_rotating (gentity_t *ent) {
if ( !ent->speed ) {
ent->speed = 100;
}
// set the axis of rotation
ent->s.apos.trType = TR_LINEAR;
if ( ent->spawnflags & 4 ) {
ent->s.apos.trDelta[2] = ent->speed;
} else if ( ent->spawnflags & 8 ) {
ent->s.apos.trDelta[0] = ent->speed;
} else {
ent->s.apos.trDelta[1] = ent->speed;
}
if (!ent->damage) {
ent->damage = 2;
}
trap_SetBrushModel( ent, ent->model );
InitMover( ent );
VectorCopy( ent->s.origin, ent->s.pos.trBase );
VectorCopy( ent->s.pos.trBase, ent->r.currentOrigin );
VectorCopy( ent->s.apos.trBase, ent->r.currentAngles );
trap_LinkEntity( ent );
}
/*
===============================================================================
BOBBING
===============================================================================
*/
/*QUAKED func_bobbing (0 .5 .8) ? X_AXIS Y_AXIS
Normally bobs on the Z axis
"model2" .md3 model to also draw
"height" amplitude of bob (32 default)
"speed" seconds to complete a bob cycle (4 default)
"phase" the 0.0 to 1.0 offset in the cycle to start at
"dmg" damage to inflict when blocked (2 default)
"color" constantLight color
"light" constantLight radius
*/
void SP_func_bobbing (gentity_t *ent) {
float height;
float phase;
G_SpawnFloat( "speed", "4", &ent->speed );
G_SpawnFloat( "height", "32", &height );
G_SpawnInt( "dmg", "2", &ent->damage );
G_SpawnFloat( "phase", "0", &phase );
trap_SetBrushModel( ent, ent->model );
InitMover( ent );
VectorCopy( ent->s.origin, ent->s.pos.trBase );
VectorCopy( ent->s.origin, ent->r.currentOrigin );
ent->s.pos.trDuration = ent->speed * 1000;
ent->s.pos.trTime = ent->s.pos.trDuration * phase;
ent->s.pos.trType = TR_SINE;
// set the axis of bobbing
if ( ent->spawnflags & 1 ) {
ent->s.pos.trDelta[0] = height;
} else if ( ent->spawnflags & 2 ) {
ent->s.pos.trDelta[1] = height;
} else {
ent->s.pos.trDelta[2] = height;
}
}
/*
===============================================================================
PENDULUM
===============================================================================
*/
/*QUAKED func_pendulum (0 .5 .8) ?
You need to have an origin brush as part of this entity.
Pendulums always swing north / south on unrotated models. Add an angles field to the model to allow rotation in other directions.
Pendulum frequency is a physical constant based on the length of the beam and gravity.
"model2" .md3 model to also draw
"speed" the number of degrees each way the pendulum swings, (30 default)
"phase" the 0.0 to 1.0 offset in the cycle to start at
"dmg" damage to inflict when blocked (2 default)
"color" constantLight color
"light" constantLight radius
*/
void SP_func_pendulum(gentity_t *ent) {
float freq;
float length;
float phase;
float speed;
G_SpawnFloat( "speed", "30", &speed );
G_SpawnInt( "dmg", "2", &ent->damage );
G_SpawnFloat( "phase", "0", &phase );
trap_SetBrushModel( ent, ent->model );
// find pendulum length
length = fabs( ent->r.mins[2] );
if ( length < 8 ) {
length = 8;
}
freq = 1 / ( M_PI * 2 ) * sqrt( g_gravity.value / ( 3 * length ) );
ent->s.pos.trDuration = ( 1000 / freq );
InitMover( ent );
VectorCopy( ent->s.origin, ent->s.pos.trBase );
VectorCopy( ent->s.origin, ent->r.currentOrigin );
VectorCopy( ent->s.angles, ent->s.apos.trBase );
ent->s.apos.trDuration = 1000 / freq;
ent->s.apos.trTime = ent->s.apos.trDuration * phase;
ent->s.apos.trType = TR_SINE;
ent->s.apos.trDelta[2] = speed;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -