2019-08-31 19:18:15 -07:00
|
|
|
/*
|
2020-04-07 05:46:23 -07:00
|
|
|
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
|
2019-08-31 19:18:15 -07:00
|
|
|
*
|
|
|
|
* 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-30 17:00:38 -08:00
|
|
|
|
2019-09-10 00:53:36 -07:00
|
|
|
/*QUAKED func_train (0 .5 .8) ? TRAIN_WAIT x x TRAIN_NOTSOLID
|
2019-09-06 20:37:06 -07:00
|
|
|
"targetname" Name
|
2019-09-09 09:55:58 -07:00
|
|
|
"target" First node.
|
2019-09-06 20:37:06 -07:00
|
|
|
"killtarget" Target to kill when triggered.
|
2019-09-10 00:53:36 -07: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-06 20:37:06 -07:00
|
|
|
|
2019-09-09 09:55:58 -07: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 10:12:18 -07: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-06 20:37:06 -07:00
|
|
|
*/
|
|
|
|
|
2020-04-12 06:50:42 -07:00
|
|
|
enumflags
|
|
|
|
{
|
2019-09-10 00:53:36 -07:00
|
|
|
TRAIN_WAIT,
|
|
|
|
TRAIN_UNUSED1,
|
|
|
|
TRAIN_UNUSED2,
|
|
|
|
TRAIN_NOTSOLID
|
|
|
|
};
|
2019-09-09 09:55:58 -07: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 07:13:20 -08:00
|
|
|
class func_train:CBaseTrigger
|
2018-12-30 17:00:38 -08:00
|
|
|
{
|
2019-09-09 09:55:58 -07:00
|
|
|
float m_flWait;
|
2018-12-30 17:00:38 -08:00
|
|
|
float m_flSpeed;
|
2019-09-09 09:55:58 -07:00
|
|
|
float m_flDamage;
|
|
|
|
string m_strMoveSnd;
|
|
|
|
string m_strStopSnd;
|
2020-03-03 13:45:30 -08:00
|
|
|
string m_strOldTarget; /* specific to trains? */
|
2018-12-30 17:00:38 -08:00
|
|
|
|
2020-04-12 06:50:42 -07:00
|
|
|
void(void) func_train;
|
|
|
|
virtual void(void) NextPath;
|
|
|
|
virtual void(void) GoToTarget;
|
2020-08-10 03:32:18 -07:00
|
|
|
virtual void(entity, int) Trigger;
|
2020-04-12 06:50:42 -07:00
|
|
|
virtual void(void) Respawn;
|
|
|
|
virtual void(void) Blocked;
|
2020-09-08 16:56:46 -07:00
|
|
|
virtual void(string, string) SpawnKey;
|
2018-12-30 17:00:38 -08:00
|
|
|
};
|
|
|
|
|
2019-09-09 09:55:58 -07:00
|
|
|
void
|
|
|
|
func_train::Blocked(void)
|
|
|
|
{
|
2019-11-08 17:09:17 -08:00
|
|
|
/* HACK: Make corpses gib instantly */
|
2020-03-29 12:40:51 -07:00
|
|
|
if (other.solid == SOLID_CORPSE) {
|
2019-11-08 17:09:17 -08: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 09:55:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
func_train::GoToTarget(void)
|
2018-12-30 17:00:38 -08:00
|
|
|
{
|
2019-09-09 09:55:58 -07:00
|
|
|
entity eNode;
|
2019-03-19 12:01:24 -07:00
|
|
|
float flTravelTime;
|
2019-09-09 09:55:58 -07:00
|
|
|
vector vecVelocity;
|
|
|
|
vector vecWorldPos;
|
2019-03-19 12:01:24 -07:00
|
|
|
|
2020-09-08 13:49:35 -07:00
|
|
|
eNode = find(world, ::targetname, target);
|
2018-12-30 17:00:38 -08:00
|
|
|
|
2019-09-09 09:55:58 -07:00
|
|
|
if (!eNode) {
|
2018-12-30 17:00:38 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-03 13:45:30 -08:00
|
|
|
vecWorldPos[0] = absmin[0] + (0.5 * (absmax[0] - absmin[0]));
|
|
|
|
vecWorldPos[1] = absmin[1] + (0.5 * (absmax[1] - absmin[1]));
|
2019-03-21 12:32:45 -07:00
|
|
|
vecWorldPos[2] = absmin[2] + (0.5 * (absmax[2] - absmin[2]));
|
|
|
|
|
2019-09-09 09:55:58 -07:00
|
|
|
vecVelocity = (eNode.origin - vecWorldPos);
|
|
|
|
flTravelTime = (vlen(vecVelocity) / m_flSpeed);
|
2019-01-14 07:13:20 -08:00
|
|
|
|
2019-03-19 12:01:24 -07:00
|
|
|
if (!flTravelTime) {
|
2020-03-31 00:04:05 -07:00
|
|
|
print("^1func_train::^3GoToTarget^7: Distance short, going next\n");
|
2020-03-29 12:40:51 -07:00
|
|
|
think = NextPath;
|
|
|
|
nextthink = ltime;
|
2019-03-19 12:01:24 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-09 09:55:58 -07: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 12:01:24 -07:00
|
|
|
think = NextPath;
|
2019-09-01 13:39:56 -07:00
|
|
|
nextthink = (ltime + flTravelTime);
|
2018-12-30 17:00:38 -08:00
|
|
|
}
|
|
|
|
|
2019-09-09 09:55:58 -07:00
|
|
|
void
|
|
|
|
func_train::NextPath(void)
|
2018-12-30 17:00:38 -08:00
|
|
|
{
|
2019-09-09 09:55:58 -07:00
|
|
|
path_corner eNode;
|
2020-09-08 13:49:35 -07:00
|
|
|
eNode = (path_corner)find(world, ::targetname, target);
|
2019-03-19 12:01:24 -07:00
|
|
|
|
2019-09-09 09:55:58 -07:00
|
|
|
if (!eNode) {
|
|
|
|
return;
|
2019-03-19 12:01:24 -07:00
|
|
|
}
|
|
|
|
|
2019-09-09 09:55:58 -07:00
|
|
|
/* fire the path_corners' target */
|
|
|
|
if (eNode.m_strMessage) {
|
2020-08-10 03:32:18 -07:00
|
|
|
eNode.Trigger(this, TRIG_TOGGLE);
|
2019-09-09 09:55:58 -07:00
|
|
|
}
|
2019-03-21 12:32:45 -07:00
|
|
|
|
2019-09-09 09:55:58 -07: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 09:25:03 -07:00
|
|
|
sound(this, CHAN_VOICE, "common/null.wav", 1.0, ATTN_NORM);
|
2019-03-19 12:01:24 -07:00
|
|
|
}
|
2018-12-30 17:00:38 -08:00
|
|
|
|
2020-04-22 14:33:18 -07:00
|
|
|
SetOrigin(eNode.origin - (mins + maxs) * 0.5);
|
2019-09-09 09:55:58 -07:00
|
|
|
m_flSpeed = eNode.m_flSpeed;
|
|
|
|
m_flWait = eNode.m_flWait;
|
2020-09-08 13:49:35 -07:00
|
|
|
target = eNode.target;
|
2019-09-09 09:55:58 -07:00
|
|
|
velocity = [0,0,0];
|
2019-03-19 12:01:24 -07:00
|
|
|
|
2020-03-29 12:40:51 -07:00
|
|
|
/* warp next frame */
|
2019-09-09 09:55:58 -07:00
|
|
|
if (eNode.spawnflags & PC_TELEPORT) {
|
2020-09-08 13:49:35 -07:00
|
|
|
print(sprintf("^1func_train::^3NextPath^7: Node %s wants %s to teleport\n", eNode.targetname, targetname));
|
2020-03-29 12:40:51 -07:00
|
|
|
think = NextPath;
|
|
|
|
nextthink = ltime;
|
2019-09-09 09:55:58 -07:00
|
|
|
return;
|
|
|
|
}
|
2019-01-18 12:06:23 -08:00
|
|
|
|
2019-09-09 09:55:58 -07:00
|
|
|
/* stop until triggered again */
|
2019-09-10 00:53:36 -07:00
|
|
|
if (eNode.spawnflags & PC_WAIT || spawnflags & TRAIN_WAIT) {
|
2019-01-18 12:06:23 -08:00
|
|
|
return;
|
|
|
|
}
|
2019-03-19 12:01:24 -07:00
|
|
|
|
2019-09-09 09:55:58 -07:00
|
|
|
if (m_flWait > 0) {
|
|
|
|
think = GoToTarget;
|
|
|
|
nextthink = ltime + m_flWait;
|
|
|
|
} else {
|
|
|
|
GoToTarget();
|
|
|
|
}
|
|
|
|
}
|
2018-12-30 17:00:38 -08:00
|
|
|
|
2020-08-07 05:07:38 -07:00
|
|
|
/* TODO: Handle state? */
|
2019-09-09 09:55:58 -07:00
|
|
|
void
|
2020-08-10 03:32:18 -07:00
|
|
|
func_train::Trigger(entity act, int state)
|
2019-09-09 09:55:58 -07:00
|
|
|
{
|
|
|
|
GoToTarget();
|
2019-03-19 12:01:24 -07:00
|
|
|
}
|
2019-01-18 12:06:23 -08:00
|
|
|
|
2019-09-09 09:55:58 -07:00
|
|
|
void
|
|
|
|
func_train::Respawn(void)
|
2019-03-19 12:01:24 -07:00
|
|
|
{
|
2019-09-09 09:55:58 -07:00
|
|
|
solid = spawnflags & TRAIN_NOTSOLID ? SOLID_NOT : SOLID_BSP;
|
2019-03-19 12:01:24 -07:00
|
|
|
movetype = MOVETYPE_PUSH;
|
2019-09-09 09:55:58 -07:00
|
|
|
blocked = Blocked;
|
2020-04-22 14:33:18 -07:00
|
|
|
SetModel(m_oldModel);
|
|
|
|
SetOrigin(m_oldOrigin);
|
2019-03-19 12:01:24 -07:00
|
|
|
|
2019-09-09 09:55:58 -07: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-09-08 13:49:35 -07:00
|
|
|
target = m_strOldTarget;
|
2019-09-09 09:55:58 -07:00
|
|
|
think = NextPath;
|
|
|
|
nextthink = ltime + 0.25f;
|
2018-12-30 17:00:38 -08:00
|
|
|
}
|
|
|
|
|
2019-09-09 09:55:58 -07:00
|
|
|
void
|
2020-09-08 16:56:46 -07:00
|
|
|
func_train::SpawnKey(string strKey, string strValue)
|
2018-12-30 17:00:38 -08:00
|
|
|
{
|
2019-09-09 09:55:58 -07:00
|
|
|
int a;
|
2018-12-30 17:00:38 -08:00
|
|
|
|
2020-09-08 16:56:46 -07:00
|
|
|
switch (strKey) {
|
|
|
|
case "target":
|
|
|
|
m_strOldTarget = strValue;
|
|
|
|
break;
|
|
|
|
case "dmg":
|
|
|
|
m_flDamage = stof(strValue);
|
|
|
|
break;
|
|
|
|
case "movesnd":
|
|
|
|
a = bound(0, stof(strValue), g_strTrainMoveSnd.length);
|
|
|
|
m_strMoveSnd = g_strTrainMoveSnd[a];
|
2019-09-09 09:55:58 -07:00
|
|
|
precache_sound(m_strMoveSnd);
|
2020-09-08 16:56:46 -07:00
|
|
|
break;
|
|
|
|
case "stopsnd":
|
|
|
|
a = bound(0, stof(strValue), g_strTrainStopSnd.length);
|
|
|
|
m_strStopSnd = g_strTrainStopSnd[a];
|
2019-09-09 09:55:58 -07:00
|
|
|
precache_sound(m_strStopSnd);
|
2020-09-08 16:56:46 -07:00
|
|
|
break;
|
|
|
|
case "snd_move":
|
|
|
|
m_strMoveSnd = strValue;
|
|
|
|
break;
|
|
|
|
case "snd_stop":
|
|
|
|
m_strStopSnd = strValue;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
CBaseTrigger::SpawnKey(strKey, strValue);
|
2019-09-09 09:55:58 -07:00
|
|
|
}
|
2020-09-08 16:56:46 -07:00
|
|
|
}
|
2019-09-09 09:55:58 -07:00
|
|
|
|
2020-09-08 16:56:46 -07:00
|
|
|
void
|
|
|
|
func_train::func_train(void)
|
|
|
|
{
|
|
|
|
/* FIXME: This is all decided by the first path_corner pretty much */
|
|
|
|
m_flSpeed = 100;
|
2019-03-19 12:01:24 -07:00
|
|
|
CBaseTrigger::CBaseTrigger();
|
2018-12-30 17:00:38 -08:00
|
|
|
}
|