2019-09-01 02:18:15 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016-2019 Marco Hladik <marco@icculus.org>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
2018-12-31 01:00:38 +00:00
|
|
|
|
2019-09-10 07:53:36 +00:00
|
|
|
/*QUAKED func_train (0 .5 .8) ? TRAIN_WAIT x x TRAIN_NOTSOLID
|
2019-09-07 03:37:06 +00:00
|
|
|
"targetname" Name
|
2019-09-09 16:55:58 +00:00
|
|
|
"target" First node.
|
2019-09-07 03:37:06 +00:00
|
|
|
"killtarget" Target to kill when triggered.
|
2019-09-10 07:53:36 +00:00
|
|
|
"dmg" Damage to inflict upon a person blocking the way.
|
|
|
|
"snd_move" Path to sound sample which plays when it's moving.
|
|
|
|
"snd_stop" Path to sound sample which plays when it stops moving.
|
2019-09-07 03:37:06 +00:00
|
|
|
|
2019-09-09 16:55:58 +00:00
|
|
|
Moving platform following along path_corner entities, aka nodes.
|
|
|
|
Most of its behaviour is controlled by the path_corner entities it passes over.
|
|
|
|
See the entity definition for path_corner to find out more.
|
|
|
|
|
|
|
|
Upon level entry, the func_train will spawn right where its first path_corner
|
|
|
|
node is. This is so you can light the func_train somewhere else - like a lonely
|
|
|
|
box somewhere outside the playable area.
|
2019-09-09 17:12:18 +00:00
|
|
|
|
|
|
|
Marking the func_train with the flag TRAIN_NOTSOLID will make entities not
|
|
|
|
collide with the train. This is best used for things in the distance or for
|
|
|
|
when lasers are following this train as a sort of guide.
|
2019-09-07 03:37:06 +00:00
|
|
|
*/
|
|
|
|
|
2019-09-10 07:53:36 +00:00
|
|
|
enumflags {
|
|
|
|
TRAIN_WAIT,
|
|
|
|
TRAIN_UNUSED1,
|
|
|
|
TRAIN_UNUSED2,
|
|
|
|
TRAIN_NOTSOLID
|
|
|
|
};
|
2019-09-09 16:55:58 +00:00
|
|
|
|
|
|
|
string g_strTrainMoveSnd[] = {
|
|
|
|
"common/null.wav",
|
|
|
|
"plats/bigmove1.wav",
|
|
|
|
"plats/bigmove2.wav",
|
|
|
|
"plats/elevmove1.wav",
|
|
|
|
"plats/elevmove2.wav",
|
|
|
|
"plats/elevmove3.wav",
|
|
|
|
"plats/freightmove1.wav",
|
|
|
|
"plats/freightmove2.wav",
|
|
|
|
"plats/heavymove1.wav",
|
|
|
|
"plats/rackmove1.wav",
|
|
|
|
"plats/railmove1.wav",
|
|
|
|
"plats/squeekmove1.wav",
|
|
|
|
"plats/talkmove1.wav",
|
|
|
|
"plats/talkmove2.wav"
|
|
|
|
};
|
|
|
|
string g_strTrainStopSnd[] = {
|
|
|
|
"common/null.wav",
|
|
|
|
"plats/bigstop1.wav",
|
|
|
|
"plats/bigstop2.wav",
|
|
|
|
"plats/freightstop1.wav",
|
|
|
|
"plats/heavystop2.wav",
|
|
|
|
"plats/rackstop1.wav",
|
|
|
|
"plats/railstop1.wav",
|
|
|
|
"plats/squeekstop1.wav",
|
|
|
|
"plats/talkstop1.wav"
|
|
|
|
};
|
|
|
|
|
2019-01-14 15:13:20 +00:00
|
|
|
class func_train:CBaseTrigger
|
2018-12-31 01:00:38 +00:00
|
|
|
{
|
2019-09-09 16:55:58 +00:00
|
|
|
float m_flWait;
|
2018-12-31 01:00:38 +00:00
|
|
|
float m_flSpeed;
|
2019-09-09 16:55:58 +00:00
|
|
|
float m_flDamage;
|
|
|
|
string m_strMoveSnd;
|
|
|
|
string m_strStopSnd;
|
2020-03-03 21:45:30 +00:00
|
|
|
string m_strOldTarget; /* specific to trains? */
|
2018-12-31 01:00:38 +00:00
|
|
|
|
2019-01-14 15:13:20 +00:00
|
|
|
void() func_train;
|
2019-03-19 19:01:24 +00:00
|
|
|
virtual void() NextPath;
|
|
|
|
virtual void() GoToTarget;
|
2018-12-31 01:00:38 +00:00
|
|
|
virtual void() Trigger;
|
2019-03-19 19:01:24 +00:00
|
|
|
virtual void() Respawn;
|
2019-09-09 16:55:58 +00:00
|
|
|
virtual void() Blocked;
|
2018-12-31 01:00:38 +00:00
|
|
|
};
|
|
|
|
|
2019-09-09 16:55:58 +00:00
|
|
|
void
|
|
|
|
func_train::Blocked(void)
|
|
|
|
{
|
2019-11-09 01:09:17 +00:00
|
|
|
/* HACK: Make corpses gib instantly */
|
2020-03-29 19:40:51 +00:00
|
|
|
if (other.solid == SOLID_CORPSE) {
|
2019-11-09 01:09:17 +00:00
|
|
|
Damage_Apply(other, this, 500, 0, DMG_EXPLODE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (other.takedamage != DAMAGE_NO) {
|
|
|
|
Damage_Apply(other, this, m_flDamage, 0, DMG_CRUSH);
|
|
|
|
} else {
|
|
|
|
remove(other);
|
|
|
|
}
|
2019-09-09 16:55:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
func_train::GoToTarget(void)
|
2018-12-31 01:00:38 +00:00
|
|
|
{
|
2019-09-09 16:55:58 +00:00
|
|
|
entity eNode;
|
2019-03-19 19:01:24 +00:00
|
|
|
float flTravelTime;
|
2019-09-09 16:55:58 +00:00
|
|
|
vector vecVelocity;
|
|
|
|
vector vecWorldPos;
|
2019-03-19 19:01:24 +00:00
|
|
|
|
2019-09-09 16:55:58 +00:00
|
|
|
eNode = find(world, CBaseTrigger::m_strTargetName, m_strTarget);
|
2018-12-31 01:00:38 +00:00
|
|
|
|
2019-09-09 16:55:58 +00:00
|
|
|
if (!eNode) {
|
2018-12-31 01:00:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-03 21:45:30 +00:00
|
|
|
vecWorldPos[0] = absmin[0] + (0.5 * (absmax[0] - absmin[0]));
|
|
|
|
vecWorldPos[1] = absmin[1] + (0.5 * (absmax[1] - absmin[1]));
|
2019-03-21 19:32:45 +00:00
|
|
|
vecWorldPos[2] = absmin[2] + (0.5 * (absmax[2] - absmin[2]));
|
|
|
|
|
2019-09-09 16:55:58 +00:00
|
|
|
vecVelocity = (eNode.origin - vecWorldPos);
|
|
|
|
flTravelTime = (vlen(vecVelocity) / m_flSpeed);
|
2019-01-14 15:13:20 +00:00
|
|
|
|
2019-03-19 19:01:24 +00:00
|
|
|
if (!flTravelTime) {
|
2020-03-31 07:04:05 +00:00
|
|
|
print("^1func_train::^3GoToTarget^7: Distance short, going next\n");
|
2020-03-29 19:40:51 +00:00
|
|
|
think = NextPath;
|
|
|
|
nextthink = ltime;
|
2019-03-19 19:01:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-09 16:55:58 +00:00
|
|
|
/* more stuff for the ears */
|
|
|
|
if (m_strMoveSnd) {
|
|
|
|
sound(this, CHAN_VOICE, m_strMoveSnd, 1.0, ATTN_NORM);
|
|
|
|
}
|
|
|
|
|
|
|
|
velocity = (vecVelocity * (1 / flTravelTime));
|
2019-03-19 19:01:24 +00:00
|
|
|
think = NextPath;
|
2019-09-01 20:39:56 +00:00
|
|
|
nextthink = (ltime + flTravelTime);
|
2018-12-31 01:00:38 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 16:55:58 +00:00
|
|
|
void
|
|
|
|
func_train::NextPath(void)
|
2018-12-31 01:00:38 +00:00
|
|
|
{
|
2019-09-09 16:55:58 +00:00
|
|
|
path_corner eNode;
|
|
|
|
eNode = (path_corner)find(world, CBaseTrigger::m_strTargetName, m_strTarget);
|
2019-03-19 19:01:24 +00:00
|
|
|
|
2019-09-09 16:55:58 +00:00
|
|
|
if (!eNode) {
|
|
|
|
return;
|
2019-03-19 19:01:24 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 16:55:58 +00:00
|
|
|
/* fire the path_corners' target */
|
|
|
|
if (eNode.m_strMessage) {
|
|
|
|
eNode.Trigger();
|
|
|
|
}
|
2019-03-21 19:32:45 +00:00
|
|
|
|
2019-09-09 16:55:58 +00:00
|
|
|
/* stuff for the ears */
|
|
|
|
if (m_strStopSnd) {
|
|
|
|
sound(this, CHAN_BODY, m_strStopSnd, 1.0, ATTN_NORM);
|
|
|
|
}
|
|
|
|
/* make the loopy noise stop */
|
|
|
|
if (m_strMoveSnd) {
|
2020-03-23 16:25:03 +00:00
|
|
|
sound(this, CHAN_VOICE, "common/null.wav", 1.0, ATTN_NORM);
|
2019-03-19 19:01:24 +00:00
|
|
|
}
|
2018-12-31 01:00:38 +00:00
|
|
|
|
2019-09-09 16:55:58 +00:00
|
|
|
setorigin(this, eNode.origin - (mins + maxs) * 0.5);
|
|
|
|
m_flSpeed = eNode.m_flSpeed;
|
|
|
|
m_flWait = eNode.m_flWait;
|
|
|
|
m_strTarget = eNode.m_strTarget;
|
|
|
|
velocity = [0,0,0];
|
2019-03-19 19:01:24 +00:00
|
|
|
|
2020-03-29 19:40:51 +00:00
|
|
|
/* warp next frame */
|
2019-09-09 16:55:58 +00:00
|
|
|
if (eNode.spawnflags & PC_TELEPORT) {
|
2020-03-31 07:04:05 +00:00
|
|
|
print(sprintf("^1func_train::^3NextPath^7: Node %s wants %s to teleport\n", eNode.m_strTargetName, m_strTargetName));
|
2020-03-29 19:40:51 +00:00
|
|
|
think = NextPath;
|
|
|
|
nextthink = ltime;
|
2019-09-09 16:55:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-01-18 20:06:23 +00:00
|
|
|
|
2019-09-09 16:55:58 +00:00
|
|
|
/* stop until triggered again */
|
2019-09-10 07:53:36 +00:00
|
|
|
if (eNode.spawnflags & PC_WAIT || spawnflags & TRAIN_WAIT) {
|
2019-01-18 20:06:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-03-19 19:01:24 +00:00
|
|
|
|
2019-09-09 16:55:58 +00:00
|
|
|
if (m_flWait > 0) {
|
|
|
|
think = GoToTarget;
|
|
|
|
nextthink = ltime + m_flWait;
|
|
|
|
} else {
|
|
|
|
GoToTarget();
|
|
|
|
}
|
|
|
|
}
|
2018-12-31 01:00:38 +00:00
|
|
|
|
2019-09-09 16:55:58 +00:00
|
|
|
void
|
|
|
|
func_train::Trigger(void)
|
|
|
|
{
|
|
|
|
GoToTarget();
|
2019-03-19 19:01:24 +00:00
|
|
|
}
|
2019-01-18 20:06:23 +00:00
|
|
|
|
2019-09-09 16:55:58 +00:00
|
|
|
void
|
|
|
|
func_train::Respawn(void)
|
2019-03-19 19:01:24 +00:00
|
|
|
{
|
2019-09-09 16:55:58 +00:00
|
|
|
solid = spawnflags & TRAIN_NOTSOLID ? SOLID_NOT : SOLID_BSP;
|
2019-03-19 19:01:24 +00:00
|
|
|
movetype = MOVETYPE_PUSH;
|
2019-09-09 16:55:58 +00:00
|
|
|
blocked = Blocked;
|
2019-03-19 19:01:24 +00:00
|
|
|
setmodel(this, m_oldModel);
|
|
|
|
setorigin(this, m_oldOrigin);
|
|
|
|
|
2019-09-09 16:55:58 +00:00
|
|
|
/* let's wait 1/4 a second to give the path_corner entities a chance to
|
|
|
|
* spawn in case they're after us in the ent lump */
|
2020-03-03 21:45:30 +00:00
|
|
|
m_strTarget = m_strOldTarget;
|
2019-09-09 16:55:58 +00:00
|
|
|
think = NextPath;
|
|
|
|
nextthink = ltime + 0.25f;
|
2018-12-31 01:00:38 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 16:55:58 +00:00
|
|
|
void
|
|
|
|
func_train::func_train(void)
|
2018-12-31 01:00:38 +00:00
|
|
|
{
|
2019-09-09 16:55:58 +00:00
|
|
|
int a;
|
2019-03-21 19:32:45 +00:00
|
|
|
for (int i = 1; i < (tokenize(__fullspawndata) - 1); i += 2) {
|
|
|
|
switch (argv(i)) {
|
2020-03-03 21:45:30 +00:00
|
|
|
case "target":
|
|
|
|
m_strOldTarget = argv(i+1);
|
|
|
|
break;
|
2019-09-09 16:55:58 +00:00
|
|
|
case "dmg":
|
|
|
|
m_flDamage = stof(argv(i+1));
|
|
|
|
break;
|
|
|
|
case "movesnd":
|
|
|
|
a = bound(0, stof(argv(i+1)), g_strTrainMoveSnd.length);
|
|
|
|
m_strMoveSnd = g_strTrainMoveSnd[a];
|
|
|
|
break;
|
|
|
|
case "stopsnd":
|
|
|
|
a = bound(0, stof(argv(i+1)), g_strTrainStopSnd.length);
|
|
|
|
m_strStopSnd = g_strTrainStopSnd[a];
|
|
|
|
break;
|
|
|
|
case "snd_move":
|
|
|
|
m_strMoveSnd = argv(i+1);
|
|
|
|
break;
|
|
|
|
case "snd_stop":
|
|
|
|
m_strStopSnd = argv(i+1);
|
2019-01-14 15:13:20 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-12-31 01:00:38 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 16:55:58 +00:00
|
|
|
if (m_strMoveSnd) {
|
|
|
|
precache_sound(m_strMoveSnd);
|
|
|
|
}
|
|
|
|
if (m_strStopSnd) {
|
|
|
|
precache_sound(m_strStopSnd);
|
|
|
|
}
|
|
|
|
|
2019-03-19 19:01:24 +00:00
|
|
|
if (!m_flSpeed) {
|
|
|
|
m_flSpeed = 100;
|
|
|
|
}
|
2018-12-31 01:00:38 +00:00
|
|
|
|
2019-03-19 19:01:24 +00:00
|
|
|
CBaseTrigger::CBaseTrigger();
|
2018-12-31 01:00:38 +00:00
|
|
|
}
|