2019-09-01 02:18:15 +00:00
|
|
|
/*
|
2020-04-07 12:46:23 +00:00
|
|
|
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
|
2019-09-01 02:18:15 +00: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-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
|
2021-07-14 09:49:30 +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.
|
|
|
|
|
|
|
|
-------- KEYS --------
|
2021-07-17 19:04:34 +00:00
|
|
|
"targetname" : Name
|
|
|
|
"target" : First node.
|
|
|
|
"killtarget" : Target to kill when triggered.
|
|
|
|
"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.
|
|
|
|
|
|
|
|
-------- SPAWNFLAGS --------
|
|
|
|
TRAIN_WAIT : Stop at each path_corner until we're triggered again.
|
|
|
|
TRAIN_NOTSOLID : Don't do collision testing against this entity.
|
2019-09-07 03:37:06 +00:00
|
|
|
|
2021-07-14 09:49:30 +00:00
|
|
|
-------- NOTES --------
|
2019-09-09 16:55:58 +00:00
|
|
|
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
|
|
|
|
2021-01-22 11:07:42 +00:00
|
|
|
If no targetname is specified, the train will move on its own at map-launch.
|
|
|
|
|
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.
|
2020-10-25 11:38:41 +00:00
|
|
|
|
2021-07-14 09:49:30 +00:00
|
|
|
-------- TRIVIA --------
|
2020-10-25 11:38:41 +00:00
|
|
|
This entity was introduced in Quake (1996).
|
2019-09-07 03:37:06 +00:00
|
|
|
*/
|
|
|
|
|
2020-04-12 13:50:42 +00:00
|
|
|
enumflags
|
|
|
|
{
|
2019-09-10 07:53:36 +00:00
|
|
|
TRAIN_WAIT,
|
|
|
|
TRAIN_UNUSED1,
|
|
|
|
TRAIN_UNUSED2,
|
|
|
|
TRAIN_NOTSOLID
|
|
|
|
};
|
2019-09-09 16:55:58 +00:00
|
|
|
|
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;
|
2018-12-31 01:00:38 +00:00
|
|
|
|
2020-04-12 13:50:42 +00:00
|
|
|
void(void) func_train;
|
2021-02-13 23:21:35 +00:00
|
|
|
virtual void(void) SoundMove;
|
|
|
|
virtual void(void) SoundStop;
|
2021-01-22 11:07:42 +00:00
|
|
|
virtual void(void) AfterSpawn;
|
|
|
|
virtual void(void) PathNext;
|
|
|
|
virtual void(void) PathMove;
|
2020-08-10 10:32:18 +00:00
|
|
|
virtual void(entity, int) Trigger;
|
2020-04-12 13:50:42 +00:00
|
|
|
virtual void(void) Respawn;
|
|
|
|
virtual void(void) Blocked;
|
2020-09-08 23:56:46 +00:00
|
|
|
virtual void(string, string) SpawnKey;
|
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
|
|
|
}
|
|
|
|
|
2021-02-13 23:21:35 +00:00
|
|
|
void
|
|
|
|
func_train::SoundMove(void)
|
|
|
|
{
|
|
|
|
if (m_strMoveSnd) {
|
|
|
|
Sound_Play(this, CHAN_VOICE, m_strMoveSnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
func_train::SoundStop(void)
|
|
|
|
{
|
|
|
|
if (m_strStopSnd) {
|
|
|
|
Sound_Play(this, CHAN_BODY, m_strStopSnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_strMoveSnd) {
|
|
|
|
sound(this, CHAN_VOICE, "common/null.wav", 1.0, ATTN_NORM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-09 16:55:58 +00:00
|
|
|
void
|
2021-01-22 11:07:42 +00:00
|
|
|
func_train::PathMove(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
|
|
|
|
2020-09-08 20:49:35 +00:00
|
|
|
eNode = find(world, ::targetname, target);
|
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) {
|
2021-01-22 11:07:42 +00:00
|
|
|
print("^1func_train::^3PathMove^7: Distance short, going next\n");
|
|
|
|
think = PathNext;
|
2020-03-29 19:40:51 +00:00
|
|
|
nextthink = ltime;
|
2019-03-19 19:01:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-13 23:21:35 +00:00
|
|
|
SoundMove();
|
2019-09-09 16:55:58 +00:00
|
|
|
|
|
|
|
velocity = (vecVelocity * (1 / flTravelTime));
|
2021-01-22 11:07:42 +00:00
|
|
|
think = PathNext;
|
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
|
2021-01-22 11:07:42 +00:00
|
|
|
func_train::PathDone(void)
|
2018-12-31 01:00:38 +00:00
|
|
|
{
|
2019-09-09 16:55:58 +00:00
|
|
|
path_corner eNode;
|
2020-09-08 20:49:35 +00:00
|
|
|
eNode = (path_corner)find(world, ::targetname, target);
|
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) {
|
2020-08-10 10:32:18 +00:00
|
|
|
eNode.Trigger(this, TRIG_TOGGLE);
|
2019-09-09 16:55:58 +00:00
|
|
|
}
|
2021-02-13 23:21:35 +00:00
|
|
|
SoundStop();
|
2021-01-22 11:07:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
func_train::PathNext(void)
|
|
|
|
{
|
|
|
|
path_corner eNode;
|
|
|
|
eNode = (path_corner)find(world, ::targetname, target);
|
|
|
|
|
|
|
|
if (!eNode) {
|
|
|
|
return;
|
|
|
|
}
|
2018-12-31 01:00:38 +00:00
|
|
|
|
2020-04-22 21:33:18 +00:00
|
|
|
SetOrigin(eNode.origin - (mins + maxs) * 0.5);
|
2021-03-12 01:48:08 +00:00
|
|
|
PathDone();
|
2020-09-10 05:00:28 +00:00
|
|
|
|
|
|
|
/* if speed is 0, retain current speed */
|
|
|
|
if (eNode.m_flSpeed > 0)
|
|
|
|
m_flSpeed = eNode.m_flSpeed;
|
|
|
|
|
2019-09-09 16:55:58 +00:00
|
|
|
m_flWait = eNode.m_flWait;
|
2020-09-08 20:49:35 +00:00
|
|
|
target = eNode.target;
|
2019-09-09 16:55:58 +00:00
|
|
|
velocity = [0,0,0];
|
2019-03-19 19:01:24 +00:00
|
|
|
|
2021-01-22 11:07:42 +00:00
|
|
|
/* warp */
|
2019-09-09 16:55:58 +00:00
|
|
|
if (eNode.spawnflags & PC_TELEPORT) {
|
2021-01-22 11:07:42 +00:00
|
|
|
SetOrigin(eNode.origin - (mins + maxs) * 0.5);
|
2019-09-09 16:55:58 +00:00
|
|
|
}
|
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) {
|
2021-02-13 23:21:35 +00:00
|
|
|
SoundStop();
|
2019-01-18 20:06:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-03-19 19:01:24 +00:00
|
|
|
|
2021-01-22 11:07:42 +00:00
|
|
|
/* move after delay, or instantly when none is given */
|
2019-09-09 16:55:58 +00:00
|
|
|
if (m_flWait > 0) {
|
2021-01-22 11:07:42 +00:00
|
|
|
think = PathMove;
|
2019-09-09 16:55:58 +00:00
|
|
|
nextthink = ltime + m_flWait;
|
|
|
|
} else {
|
2021-01-22 11:07:42 +00:00
|
|
|
PathMove();
|
2019-09-09 16:55:58 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-31 01:00:38 +00:00
|
|
|
|
2020-08-07 12:07:38 +00:00
|
|
|
/* TODO: Handle state? */
|
2019-09-09 16:55:58 +00:00
|
|
|
void
|
2020-08-10 10:32:18 +00:00
|
|
|
func_train::Trigger(entity act, int state)
|
2019-09-09 16:55:58 +00:00
|
|
|
{
|
2021-01-22 11:07:42 +00:00
|
|
|
PathMove();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
func_train::AfterSpawn(void)
|
|
|
|
{
|
|
|
|
PathNext();
|
|
|
|
|
|
|
|
if (!targetname) {
|
|
|
|
PathMove();
|
|
|
|
}
|
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
|
|
|
{
|
2021-01-22 11:07:42 +00:00
|
|
|
SetSolid(spawnflags & TRAIN_NOTSOLID ? SOLID_NOT : SOLID_BSP);
|
|
|
|
SetMovetype(MOVETYPE_PUSH);
|
2019-09-09 16:55:58 +00:00
|
|
|
blocked = Blocked;
|
2020-04-22 21:33:18 +00:00
|
|
|
SetModel(m_oldModel);
|
|
|
|
SetOrigin(m_oldOrigin);
|
2019-03-19 19:01:24 +00:00
|
|
|
|
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-09-10 05:00:28 +00:00
|
|
|
target = m_oldstrTarget;
|
2021-01-22 11:07:42 +00:00
|
|
|
think = AfterSpawn;
|
2019-09-09 16:55:58 +00:00
|
|
|
nextthink = ltime + 0.25f;
|
2018-12-31 01:00:38 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 16:55:58 +00:00
|
|
|
void
|
2020-09-08 23:56:46 +00:00
|
|
|
func_train::SpawnKey(string strKey, string strValue)
|
2018-12-31 01:00:38 +00:00
|
|
|
{
|
2020-09-08 23:56:46 +00:00
|
|
|
switch (strKey) {
|
|
|
|
case "dmg":
|
|
|
|
m_flDamage = stof(strValue);
|
|
|
|
break;
|
|
|
|
case "snd_move":
|
|
|
|
m_strMoveSnd = strValue;
|
|
|
|
break;
|
|
|
|
case "snd_stop":
|
|
|
|
m_strStopSnd = strValue;
|
|
|
|
break;
|
2020-09-10 05:00:28 +00:00
|
|
|
/* compatibility */
|
|
|
|
case "movesnd":
|
|
|
|
m_strMoveSnd = sprintf("func_train.move_%i", stoi(strValue) + 1i);
|
|
|
|
break;
|
|
|
|
case "stopsnd":
|
|
|
|
m_strStopSnd = sprintf("func_train.stop_%i", stoi(strValue) + 1i);
|
|
|
|
break;
|
2020-09-08 23:56:46 +00:00
|
|
|
default:
|
|
|
|
CBaseTrigger::SpawnKey(strKey, strValue);
|
2019-09-09 16:55:58 +00:00
|
|
|
}
|
2020-09-08 23:56:46 +00:00
|
|
|
}
|
2019-09-09 16:55:58 +00:00
|
|
|
|
2020-09-08 23:56:46 +00: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 19:01:24 +00:00
|
|
|
CBaseTrigger::CBaseTrigger();
|
2020-09-10 05:00:28 +00:00
|
|
|
|
|
|
|
if (m_strMoveSnd)
|
|
|
|
Sound_Precache(m_strMoveSnd);
|
|
|
|
|
|
|
|
if (m_strStopSnd)
|
|
|
|
Sound_Precache(m_strStopSnd);
|
2018-12-31 01:00:38 +00:00
|
|
|
}
|