djcev.com

//

Git Repos / fte_dogmode / qc / misc / teleporttrain.qc

Last update to this file was on 2024-03-24 at 02:40.

Show teleporttrain.qc

//==============================================================================
// misc_teleporttrain -- was plats.qc
// Code for the fixed teleporttrain written by c0burn and modified by ZungryWare
//==============================================================================

//======================================================================
// constants
//======================================================================

enum
{
TELEPORTTRAIN_NEXT,
TELEPORTTRAIN_WAIT,
TELEPORTTRAIN_FIND
};

//======================================================================
// forward declarations
//======================================================================

// misc_teleporttrain
void() misc_teleporttrain_calcmove;
void() misc_teleporttrain_next;
void() misc_teleporttrain_wait;
void() misc_teleporttrain_find;
void() misc_teleporttrain_use;
void(entity e) misc_teleporttrain_init;
void() misc_teleporttrain;

//------------------------------------------------------------------------------

/*QUAKED misc_teleporttrain (.5 .5 .5) (-16 -16 -16) (16 16 16) X DONT_ROTATE START_ON_WITH_TARGETNAME INVISIBLE X X X X NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER X NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY
{ model("progs/teleport.mdl"); }
This was used for the final boss level in the original game. In progs_dump you can use this as a moving decoration or even target it as a spawn point for a func_monster_spawner. Make sure and select the Don't Rotate spawnflag though or you'll experience a pretty hilarious effect!

You set this up like a func_train using path_corners. By default, it will move automatically between path corners upon map load. However, you can have it wait to move by giving it a targetname. If you need to target it as a spawner and want it to move on map load, use the Start On spawnflag.

You can add effects, use a custom model using the mdl_body keyvalue and even make it invisible with spawnflag 8.

Effects
0: "None (Default)"
1 : "Brightfield (yellow particles)"
4 : "Bright light"
8 : "Dim light"


Teleporter target for final boss level. Must target a series of 'path_corner' entities.
It will position itself on its first target at map load.
If a targetname is set, it must be triggered to start moving, otherwise it will start automatically.
*/
//----------------------------------------------------------------------
// class misc_teleporttrain: base_mapentity
// {
//--------------------------------------------------------------
void() misc_teleporttrain_calcmove =
{
local vector delta;
local float len, spd;

if (self.enemy == world)
{
dprint ("misc_teleporttrain_calcmove: enemy is "
"world!\n");
return;
}

delta = (self.enemy.origin + '16 16 16') - self.origin;
len = vlen (delta);
spd = vlen (self.velocity);

self.think = misc_teleporttrain_wait;
if (self.ltime)
self.nextthink = self.ltime + (len / spd);
else
self.nextthink = time + (len / spd);
};

//--------------------------------------------------------------
void() misc_teleporttrain_next =
{
local vector dir;

setorigin (self, self.enemy.origin + '16 16 16');

if (!self.target)
{
self.enemy = world;
return;
}

self.enemy = find (world, targetname, self.target);
if (self.enemy.classtype == CT_PATH_CORNER)
{
dir = normalize ((self.enemy.origin + '16 16 16') -
self.origin);
self.velocity = dir * self.speed;
self.target = self.enemy.target;
}
else
{
objerror ("misc_teleporttrain_next: unable to find "
"target\n");
remove (self);
return;
}

misc_teleporttrain_calcmove ();
};

//--------------------------------------------------------------
void() misc_teleporttrain_wait =
{
local float wait_time;

if (self.enemy != world && self.enemy.wait > 0)
wait_time = self.enemy.wait;
else
wait_time = 0.1;

self.velocity = '0 0 0';

self.think = misc_teleporttrain_next;
if (self.ltime)
self.nextthink = self.ltime + wait_time;
else
self.nextthink = time + wait_time;
};

//--------------------------------------------------------------
void() misc_teleporttrain_find =
{
// always start positioned on the first path_corner
self.enemy = find (world, targetname, self.target);
if (self.enemy.classtype == CT_PATH_CORNER)
{
setorigin (self, self.enemy.origin + '16 16 16');
// if the path_corner has the same target we already
// have, then the train should stop. Fix for dmd8 -- CEV
if (self.target == self.enemy.target)
{
self.think = sub_null;
self.touch = sub_null;
self.use = sub_null;
return;
}

// now set our target and continue
self.target = self.enemy.target;
}
else
{
objerror ("misc_teleporttrain_find: unable to find "
"target\n");
remove (self);
return;
}

if (self.spawnflags & 4)
// start immediately even with a targetname
misc_teleporttrain_next ();
else if (!self.targetname)
// not triggered, so start immediately
misc_teleporttrain_next ();
else
self.use = misc_teleporttrain_use;
};

//--------------------------------------------------------------
void() misc_teleporttrain_use =
{
if (self.velocity == '0 0 0')
misc_teleporttrain_next ();
};

//--------------------------------------------------------------
void(entity e) misc_teleporttrain_init =
{
e.classname = "misc_teleporttrain";
e.classtype = CT_MISC_TELEPORTTRAIN;
base_mapentity_init (e);

if (!e.target)
{
objerror ("misc_teleporttrain_init: no target!\n");
remove (e);
return;
}

if (e.speed <= 0)
e.speed = 100;

e.cnt = 1;
e.solid = SOLID_NOT;
e.movetype = MOVETYPE_FLY;

// custom custom_mdls -- dumptruck_ds
// precache_model ("progs/teleport.mdl");
precache_body_model (e, "progs/teleport.mdl");
// invisble -- dumptruck_ds
precache_model ("progs/s_null.spr");
if (e.spawnflags & 8)
body_model (e, "progs/s_null.spr");
else
body_model (e, "progs/teleport.mdl");

setsize (e, '-16 -16 -16', '16 16 16');
// setorigin (e, e.origin);

// Causes the ball to spin around like it was
// originally intended to.
if (!(e.spawnflags & 2))
// don't spin - helpful for invisible
// spawner -- dumptruck_ds
e.avelocity = '40 80 120';

// precache_sound ("misc/null.wav");
// e.noise = "misc/null.wav";
// e.noise1 = "misc/null.wav";

e.think = misc_teleporttrain_find;
if (e.ltime)
e.nextthink = e.ltime + 0.1;
else
e.nextthink = time + 0.1;
};

//--------------------------------------------------------------
void() misc_teleporttrain =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

misc_teleporttrain_init (self);
};
// };

Return to the top of this page or return to the overview of this repo.

Log teleporttrain.qc

Date Commit Message Author + -
2024-03-24 2nd pass refactor, rework QC class structure cev +108 -104
2024-01-31 Class based monster refactor & start projectiles cev +4 -6
2024-01-13 Refactored items into classes, fix teleporttrain cev +51 -8
2024-01-09 Continue OO / Class-based refactor cev +62 -35
2023-12-09 Start OO / class-based refactor, work on items cev +136 -130
2023-11-27 Code reorg, minor movement changes, misc cev +158  

Return to the top of this page or return to the overview of this repo.