trigger_changetarget: implemented. needs testing, also any entity's get their target value reset during Respawn() properly if it's been changed by one of those.

This commit is contained in:
Marco Cawthorne 2020-08-28 21:35:18 +02:00
parent 67930b7dde
commit 5526b3524c
6 changed files with 73 additions and 0 deletions

View file

@ -59,6 +59,7 @@ server/trigger_cdaudio.cpp
server/trigger_camera.cpp
server/trigger_hurt.cpp
server/trigger_changelevel.cpp
server/trigger_changetarget.cpp
server/trigger_look.cpp
server/trigger_once.cpp
server/trigger_multiple.cpp

View file

@ -351,6 +351,7 @@ CBaseEntity::CBaseEntity(void)
m_oldflRenderAmt = m_flRenderAmt;
m_oldvecRenderColor = m_vecRenderColor;
m_oldflRenderAmt = m_flRenderAmt;
m_oldstrTarget = m_strTarget;
if (m_oldModel != "") {
precache_model(m_oldModel);
@ -365,6 +366,7 @@ CBaseEntity::Respawn(void)
SetSolid(m_oldSolid);
SetAngles(m_oldAngle);
SetOrigin(m_oldOrigin);
m_strTarget = m_oldstrTarget;
#ifdef GS_RENDERFX
SetRenderFX(m_oldiRenderFX);

View file

@ -17,6 +17,7 @@
class CBaseEntity
{
string m_strTarget;
string m_oldstrTarget; /* needed due to trigger_changetarget */
string m_strTargetName;
int m_iBody;

View file

@ -144,6 +144,7 @@ multi_manager::multi_manager(void)
// HACK: Avoid infinite loops
if (m_strTargetName != argv(i)) {
m_eTriggers[b].m_strTarget = argv(i);
m_eTriggers[b].m_oldstrTarget = argv(i);
b++;
}
}

View file

@ -246,6 +246,7 @@ void
scripted_sequence::Respawn(void)
{
m_iEnabled = TRUE;
m_strTarget = m_oldstrTarget;
if (m_strIdleAnim) {
think = InitIdle;
@ -283,6 +284,7 @@ scripted_sequence::scripted_sequence(void)
break;
}
}
m_oldstrTarget = m_strTarget;
}
CLASSEXPORT(aiscripted_sequence, scripted_sequence)

View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2016-2020 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.
*/
/*QUAKED trigger_changetarget (1 0 0) (-8 -8 -8) (8 8 8)
"targetname" Name
"target" Target when triggered
"m_iszNewTarget" Name of the new 'target' value for the targeted entity
When triggered, trigger_changetarget changes the 'target' value of any entity
to something else.
*/
class trigger_changetarget:CBaseTrigger
{
string m_strNewTarget;
void(void) trigger_changetarget;
virtual void(entity,int) Trigger;
};
void
trigger_changetarget::Trigger(entity act, int state)
{
CBaseEntity f;
f = (CBaseEntity)find(world, CBaseEntity::m_strTargetName, m_strTarget);
if (f) {
dprint("^2trigger_changetarget::^3Trigger^7: " \
"Changing %s (%s) target from '%s' to '%s'\n", \
m_strTarget, f.classname, f.m_strTarget, m_strTarget);
/* now change the target */
f.m_strTarget = m_strNewTarget;
}
}
void
trigger_changetarget::trigger_changetarget(void)
{
for (int i = 1; i < (tokenize(__fullspawndata) - 1); i += 2) {
switch (argv(i)) {
case "m_iszNewTarget":
m_strNewTarget = argv(i+1);
break;
default:
break;
}
}
CBaseTrigger::CBaseTrigger();
}