Move touch handlers into NSTrigger, remove trigger_multiple's own version of the team check.

This commit is contained in:
Marco Cawthorne 2022-08-31 15:18:06 -07:00
parent 31bb9b4042
commit 5a7d082af7
Signed by: eukara
GPG Key ID: CE2032F0A2882A22
9 changed files with 162 additions and 159 deletions

View File

@ -162,12 +162,6 @@ trigger_multiple::Touch(entity eToucher)
if (!HasSpawnFlags(TM_PUSHABLES) && eToucher.classname == "func_pushable")
return;
if (g_grMode.IsTeamplay() == TRUE) {
if (m_iTeam > 0 && eActivator.team != m_iTeam + 1) {
return;
}
}
/* if the target key isn't used, assume we're using the new I/O system */
if (HasTriggerTarget() == false)
UseOutput(eToucher, m_strOnStartTouch);

View File

@ -738,15 +738,7 @@ func_vehicle::Physics(void)
//crossprint(sprintf("Driver: %s\n", GetDriver().classname));
}
#ifdef SERVER
/* support for think/nextthink */
if (think && nextthink > 0.0f) {
if (nextthink < time) {
nextthink = 0.0f;
think();
}
}
#endif
HandleThink();
}
void

View File

@ -153,15 +153,7 @@ prop_vehicle_driveable::Physics(void)
//crossprint(sprintf("Driver: %s\n", GetDriver().classname));
}
#ifdef SERVER
/* support for think/nextthink */
if (think && nextthink > 0.0f) {
if (nextthink < time) {
nextthink = 0.0f;
think();
}
}
#endif
HandleThink();
}
void

View File

@ -72,11 +72,6 @@ class NSEntity:NSTrigger
PREDICTED_VECTOR_N(velocity);
PREDICTED_VECTOR_N(avelocity);
/* not needed to be saved right now */
float m_flTouchTime;
bool m_beingTouched;
entity m_eTouchLast;
virtual void(void) Spawned;
#ifdef CLIENT
@ -203,14 +198,7 @@ class NSEntity:NSTrigger
nonvirtual bool(string, float, float, bool) StartSound;
nonvirtual bool(string, float, bool) StartSoundDef;
nonvirtual void(float, bool) StopSound;
nonvirtual float(void) GetTime;
virtual void(entity) Blocked;
virtual void(entity) StartTouch;
virtual void(entity) Touch;
virtual void(entity) EndTouch;
nonvirtual void(void) _TouchHandler;
nonvirtual void(void) _BlockedHandler;
nonvirtual void(void) HandleThink;
virtual void(void) OnRemoveEntity;

View File

@ -24,9 +24,6 @@ client doesn't have to do a whole lot here
void
NSEntity::NSEntity(void)
{
blocked = _BlockedHandler;
touch = _TouchHandler;
#ifdef SERVER
identity = 1;
#endif
@ -58,7 +55,7 @@ NSEntity::Spawned(void)
float
NSEntity::EntIndex(void)
{
return num_for_edict(this);
return (num_for_edict(this));
}
void
@ -80,21 +77,21 @@ vector
NSEntity::GetForward(void)
{
makevectors(angles);
return v_forward;
return (v_forward);
}
vector
NSEntity::GetRight(void)
{
makevectors(angles);
return v_right;
return (v_right);
}
vector
NSEntity::GetUp(void)
{
makevectors(angles);
return v_up;
return (v_up);
}
/*
@ -108,7 +105,7 @@ Useful on brush entities that have no real 'origin' defined.
vector
NSEntity::WorldSpaceCenter(void)
{
return absmin + (0.5 * (absmax - absmin));
return (absmin + (0.5 * (absmax - absmin)));
}
/*
@ -121,7 +118,7 @@ Returns whether or not the entity is able to see a given position
float
NSEntity::WaterLevel(void)
{
return waterlevel;
return (waterlevel);
}
/*
@ -200,66 +197,16 @@ NSEntity::IsSolid(void)
entity
NSEntity::GetGroundEntity(void)
{
return groundentity;
return (groundentity);
}
bool
NSEntity::CreatedByMap(void)
{
return _mapspawned;
return (_mapspawned);
}
void
NSEntity::Blocked(entity eBlocker)
{
/* To be handled by sub-classes */
}
void
NSEntity::_BlockedHandler(void)
{
Blocked(other);
}
void
NSEntity::Touch(entity eToucher)
{
/* To be handled by sub-classes */
}
void
NSEntity::StartTouch(entity eToucher)
{
/* To be handled by sub-classes */
}
void
NSEntity::EndTouch(entity eToucher)
{
/* To be handled by sub-classes */
}
void
NSEntity::_TouchHandler(void)
{
#ifdef SERVER
if (g_grMode.IsTeamplay())
if (m_iTeam > 0i)
if (m_iTeam != other.team) {
return;
}
#endif
/* start touch in case we haven't */
if (m_beingTouched != true)
StartTouch(other);
Touch(other);
m_flTouchTime = GetTime();
m_beingTouched = true;
m_eTouchLast = other;
}
#ifdef CLIENT
/*
@ -451,7 +398,7 @@ NSEntity::ParentUpdate(void)
entity
NSEntity::GetParent(void)
{
return find(world, ::targetname, m_parent);
return (find(world, ::targetname, m_parent));
}
void
@ -680,11 +627,6 @@ NSEntity::SetThink(void(void) func)
think = func;
}
/* FIXME: Why do we need to declare this?! */
#ifdef CSQC
noref .float ltime;
#endif
void
NSEntity::SetNextThink(float fl)
{
@ -710,151 +652,151 @@ NSEntity::ScheduleThink(void(void) func, float fl)
vector
NSEntity::GetSpawnOrigin(void)
{
return m_oldOrigin;
return (m_oldOrigin);
}
vector
NSEntity::GetSpawnAngles(void)
{
return m_oldAngle;
return (m_oldAngle);
}
string
NSEntity::GetSpawnModel(void)
{
return m_oldModel;
return (m_oldModel);
}
float
NSEntity::GetEffects(void)
{
return effects;
return (effects);
}
float
NSEntity::GetFrame(void)
{
return frame;
return (frame);
}
float
NSEntity::GetSkin(void)
{
return skin;
return (skin);
}
float
NSEntity::GetScale(void)
{
return scale;
return (scale);
}
entity
NSEntity::GetOwner(void)
{
return owner;
return (owner);
}
vector
NSEntity::GetVelocity(void)
{
return velocity;
return (velocity);
}
float
NSEntity::GetSolid(void)
{
return solid;
return (solid);
}
string
NSEntity::GetModel(void)
{
return model;
return (model);
}
float
NSEntity::GetModelindex(void)
{
return modelindex;
return (modelindex);
}
float
NSEntity::GetMovetype(void)
{
return movetype;
return (movetype);
}
float
NSEntity::GetGravity(void)
{
return gravity;
return (gravity);
}
vector
NSEntity::GetAngles(void)
{
return angles;
return (angles);
}
vector
NSEntity::GetAngularVelocity(void)
{
return avelocity;
return (avelocity);
}
vector
NSEntity::GetOrigin(void)
{
return origin;
return (origin);
}
vector
NSEntity::GetMins(void)
{
return mins;
return (mins);
}
vector
NSEntity::GetMaxs(void)
{
return maxs;
return (maxs);
}
vector
NSEntity::GetRealMins(void)
{
return m_vecMins;
return (m_vecMins);
}
vector
NSEntity::GetRealMaxs(void)
{
return m_vecMaxs;
return (m_vecMaxs);
}
vector
NSEntity::GetAbsoluteMins(void)
{
return absmin;
return (absmin);
}
vector
NSEntity::GetAbsoluteMaxs(void)
{
return absmax;
return (absmax);
}
float
NSEntity::GetFlags(void)
{
return flags;
return (flags);
}
float
NSEntity::GetNextThinkTime(void)
{
return nextthink;
return (nextthink);
}
bool
@ -886,7 +828,7 @@ NSEntity::Respawn(void)
SetAngles(GetSpawnAngles());
SetOrigin(GetSpawnOrigin());
SetModel(GetSpawnModel());
target = m_oldstrTarget; /* FIXME: Move into NSTrigger::Respawn */
SetTriggerTarget(m_oldstrTarget); /* FIXME: Move into NSTrigger::Respawn */
}
void
@ -972,8 +914,7 @@ NSEntity::Input(entity eAct, string strInput, string strData)
{
switch (strInput) {
case "Kill":
think = Util_Destroy;
nextthink = GetTime();
Destroy();
break;
case "KillHierarchy":
/* this works because ents are basically just entnums */
@ -1079,16 +1020,8 @@ through your own hoops. This however will be sufficient 99,99% of the time.
void
NSEntity::Destroy(void)
{
float flTime = GetTime();
OnRemoveEntity();
think = Util_Destroy;
if (!flTime)
nextthink = flTime + 0.01;
else
nextthink = flTime;
ScheduleThink(Util_Destroy, 0.0f);
}
void
@ -1126,29 +1059,40 @@ bool
NSEntity::WithinBounds(entity check)
{
if not (check.absmin[0] >= absmin[0] && check.absmax[0] <= absmax[0])
return false;
return (false);
if not (check.absmin[1] >= absmin[1] && check.absmax[1] <= absmax[1])
return false;
return (false);
if not (check.absmin[2] >= absmin[2] && check.absmax[2] <= absmax[2])
return false;
return (false);
return true;
return (true);
}
bool
NSEntity::StartSound(string strSample, float channel, float flags, bool broadcast)
{
if not (whichpack(strcat("sound/", strSample)))
return false;
return (false);
sound(this, channel, strSample, 1.0, ATTN_NORM);
return true;
if (broadcast)
sound(this, channel, strSample, 1.0, ATTN_NORM);
else {
#ifdef SERVER
msg_entity = this;
sound(this, channel, strSample, 1.0, ATTN_NORM, 0, SOUNDFLAG_UNICAST);
msg_entity = __NULL__;
#else
sound(this, channel, strSample, 1.0, ATTN_NORM);
#endif
}
return (true);
}
bool
NSEntity::StartSoundDef(string strSample, float channel, bool broadcast)
{
Sound_Play(this, channel, strSample);
return (true);
}
void
@ -1168,9 +1112,3 @@ NSEntity::HandleThink(void)
}
}
}
float
NSEntity::GetTime(void)
{
return (movetype == MOVETYPE_PUSH) ? ltime : time;
}

View File

@ -34,6 +34,8 @@ class NSIO
/* Handle entity key/value pairs on init */
virtual void(string, string) SpawnKey;
nonvirtual float(void) GetTime;
#ifdef SERVER
/* Input/Output System */
string m_strOnTrigger;

View File

@ -678,3 +678,15 @@ NSIO::SpawnKey(string strKey, string strValue)
break;
}
}
/* FIXME: Why do we need to declare this?! */
#ifdef CSQC
noref .float ltime;
#endif
float
NSIO::GetTime(void)
{
return (movetype == MOVETYPE_PUSH) ? ltime : time;
}

View File

@ -35,6 +35,19 @@ class NSTrigger:NSIO
{
void(void) NSTrigger;
/* not needed to be saved right now */
float m_flTouchTime;
bool m_beingTouched;
entity m_eTouchLast;
/* touch/blocked */
virtual void(entity) Blocked;
virtual void(entity) StartTouch;
virtual void(entity) Touch;
virtual void(entity) EndTouch;
nonvirtual void(void) _TouchHandler;
nonvirtual void(void) _BlockedHandler;
#ifdef SERVER
string m_oldstrTarget; /* needed due to trigger_changetarget */
@ -43,7 +56,6 @@ class NSTrigger:NSIO
string m_strMessage;
string m_strMaster;
int m_iUseType;
int m_iTeam;
int m_iValue;
/* legacy trigger architecture */
@ -60,10 +72,16 @@ class NSTrigger:NSIO
nonvirtual bool(void) HasTriggerTarget;
nonvirtual bool(void) HasTargetname;
/* team */
nonvirtual void(float) SetTeam;
nonvirtual float(void) GetTeam;
/* overrides */
virtual void(float) Save;
virtual void(string,string) Restore;
virtual void(entity, string, string) Input;
#else
float team;
#endif
virtual void(string, string) SpawnKey;
};

View File

@ -17,6 +17,9 @@
void
NSTrigger::NSTrigger(void)
{
blocked = _BlockedHandler;
touch = _TouchHandler;
#ifdef SERVER
m_oldstrTarget = __NULL__;
m_strGlobalState = __NULL__;
@ -24,7 +27,7 @@ NSTrigger::NSTrigger(void)
m_strMessage = __NULL__;
m_strMaster = __NULL__;
m_iUseType = 0i;
m_iTeam = 0i;
team = 0;
m_iValue = 0i;
m_flDelay = 0.0f;
#endif
@ -175,7 +178,7 @@ NSTrigger::Save(float handle)
SaveString(handle, "m_strMessage", m_strMessage);
SaveString(handle, "m_strMaster", m_strMaster);
SaveInt(handle, "m_iUseType", m_iUseType);
SaveInt(handle, "m_iTeam", m_iTeam);
SaveFloat(handle, "team", team);
SaveInt(handle, "m_iValue", m_iValue);
SaveFloat(handle, "m_flDelay", m_flDelay);
}
@ -201,8 +204,8 @@ NSTrigger::Restore(string strKey, string strValue)
case "m_iUseType":
m_iUseType = ReadInt(strValue);
break;
case "m_iTeam":
m_iTeam = ReadInt(strValue);
case "team":
team = ReadFloat(strValue);
break;
case "m_iValue":
m_iValue = ReadInt(strValue);
@ -243,7 +246,7 @@ NSTrigger::SpawnKey(string strKey, string strValue)
m_strMaster = strValue;
break;
case "team_no":
m_iTeam = stoi(strValue);
team = stof(strValue);
break;
case "delay":
m_flDelay = stof(strValue);
@ -257,3 +260,67 @@ NSTrigger::SpawnKey(string strKey, string strValue)
break;
}
}
void
NSTrigger::Blocked(entity eBlocker)
{
/* To be handled by sub-classes */
}
void
NSTrigger::_BlockedHandler(void)
{
Blocked(other);
}
void
NSTrigger::Touch(entity eToucher)
{
/* To be handled by sub-classes */
}
void
NSTrigger::StartTouch(entity eToucher)
{
/* To be handled by sub-classes */
}
void
NSTrigger::EndTouch(entity eToucher)
{
/* To be handled by sub-classes */
}
void
NSTrigger::_TouchHandler(void)
{
#ifdef SERVER
if (g_grMode.IsTeamplay())
if (team > 0i)
if (other.team != team) {
return;
}
#endif
/* start touch in case we haven't */
if (m_beingTouched != true)
StartTouch(other);
Touch(other);
m_flTouchTime = GetTime();
m_beingTouched = true;
m_eTouchLast = other;
}
void
NSTrigger::SetTeam(float new_team)
{
team = new_team;
}
float
NSTrigger::GetTeam(void)
{
return (team);
}