CBaseTrigger: Add support for Source Engine's FireUser/OnUser 1-4 trigger

inputs/outputs.
This commit is contained in:
Marco Cawthorne 2021-05-29 10:52:47 +02:00
parent a4a40be8ae
commit 243c875a3f
6 changed files with 56 additions and 13 deletions

View file

@ -23,7 +23,7 @@ enum
};
int
w_baseauto_fire(int w, .int mag, int d)
w_baseauto_fire(int w, .int mag, int d, vector bs)
{
player pl = (player)self;
@ -41,7 +41,7 @@ w_baseauto_fire(int w, .int mag, int d)
pl.(mag)--;
#ifdef SERVER
TraceAttack_FireBullets(1, pl.origin + pl.view_ofs, d, [0.1,0.1], w);
TraceAttack_FireBullets(1, pl.origin + pl.view_ofs, d, bs, w);
#endif
if (pl.(mag) == 0)

View file

@ -23,7 +23,7 @@ enum
};
int
w_basesemi_fire(int w, .int mag, int d)
w_basesemi_fire(int w, .int mag, int d, vector bs)
{
player pl = (player)self;
@ -41,7 +41,7 @@ w_basesemi_fire(int w, .int mag, int d)
pl.(mag)--;
#ifdef SERVER
TraceAttack_FireBullets(1, pl.origin + pl.view_ofs, d, [0,0,0], w);
TraceAttack_FireBullets(1, pl.origin + pl.view_ofs, d, bs, w);
#endif
pl.gflags |= GF_SEMI_TOGGLED;

View file

@ -44,8 +44,6 @@ w_baseshotgun_fire(int w, .int mag, int c, int d, vector bs)
TraceAttack_FireBullets(c, pl.origin + pl.view_ofs, d, bs, w);
#endif
pl.gflags |= GF_SEMI_TOGGLED;
if (pl.(mag) == 0)
return (SHOTGUN_LAST);
else

View file

@ -1040,6 +1040,10 @@ receive entity updates.
void
CSQC_Ent_Remove(void)
{
/* avoid spawning dupes */
if (self.classname == "CCSAmbientSound")
sound(self, CHAN_VOICE, "", 0.0f, ATTN_NONE);
ClientGame_EntityRemove();
remove(self);
}

View file

@ -41,6 +41,11 @@ class CBaseTrigger:CBaseEntity
/* modern trigger architecture */
string m_strOnTrigger;
string m_strOnUser1;
string m_strOnUser2;
string m_strOnUser3;
string m_strOnUser4;
virtual void(entity, string) UseOutput;
virtual string(string) CreateOutput;
virtual void(entity, string, string) Input;

View file

@ -85,16 +85,32 @@ CBaseTrigger::CreateOutput(string outmsg)
/* entities receive the inputs here and need to act on intype and data
accordingly. this is just a stub for unknown event troubleshooting */
void
CBaseTrigger::Input(entity act, string intype, string data)
CBaseTrigger::Input(entity eAct, string strInput, string strData)
{
if (data != "")
dprint(sprintf("^2%s::^3Input^7: Receives input %s from %s with data %s\n",
this.classname, intype, act.classname, data));
else
dprint(sprintf("^2%s::^3Input^7: Receives input %s from %s\n",
this.classname, intype, act.classname));
switch (strInput) {
case "FireUser1":
UseOutput(eAct, m_strOnUser1);
break;
case "FireUser2":
UseOutput(eAct, m_strOnUser2);
break;
case "FireUser3":
UseOutput(eAct, m_strOnUser3);
break;
case "FireUser4":
UseOutput(eAct, m_strOnUser4);
break;
default:
if (strData != "")
print(sprintf("^2%s::^3Input^7: Receives input %s from %s with data %s\n",
this.classname, strInput, eAct.classname, strData));
else
print(sprintf("^2%s::^3Input^7: Receives input %s from %s\n",
this.classname, strInput, eAct.classname));
}
}
/* legacy trigger architecture */
void
CBaseTrigger::Trigger(entity act, int state)
@ -223,6 +239,22 @@ CBaseTrigger::SpawnKey(string strKey, string strValue)
strValue = strreplace(",", ",_", strValue);
m_strOnTrigger = strcat(m_strOnTrigger, ",_", strValue);
break;
case "OnUser1":
strValue = strreplace(",", ",_", strValue);
m_strOnUser1 = strcat(m_strOnUser1, ",_", strValue);
break;
case "OnUser2":
strValue = strreplace(",", ",_", strValue);
m_strOnUser2 = strcat(m_strOnUser2, ",_", strValue);
break;
case "OnUser3":
strValue = strreplace(",", ",_", strValue);
m_strOnUser3 = strcat(m_strOnUser3, ",_", strValue);
break;
case "OnUser4":
strValue = strreplace(",", ",_", strValue);
m_strOnUser4 = strcat(m_strOnUser4, ",_", strValue);
break;
default:
CBaseEntity::SpawnKey(strKey, strValue);
break;
@ -235,4 +267,8 @@ CBaseTrigger::CBaseTrigger(void)
CBaseEntity::CBaseEntity();
m_strOnTrigger = CreateOutput(m_strOnTrigger);
m_strOnUser1 = CreateOutput(m_strOnUser1);
m_strOnUser2 = CreateOutput(m_strOnUser2);
m_strOnUser3 = CreateOutput(m_strOnUser3);
m_strOnUser4 = CreateOutput(m_strOnUser4);
}