NSIO: add TransitionComplete() method for easier handling of entities post level-transition.
NSRenderableEntity: Default renderamt to 0. Also use Read*() methods within all of the base classes their SpawnKey() methods.
This commit is contained in:
parent
9110da2cec
commit
19d6f22dc4
10 changed files with 136 additions and 101 deletions
|
@ -529,7 +529,7 @@ void NSEntity::SetNextThink( float fl ) {
|
|||
|
||||
/* HACK: to make sure things happen post-spawn */
|
||||
if ( flTime == 0.0f )
|
||||
flTime = 0.1f;
|
||||
flTime = 0.001f;
|
||||
|
||||
if ( flTime >= 0 )
|
||||
nextthink = flTime;
|
||||
|
@ -797,36 +797,43 @@ void NSEntity::Input( entity eAct, string strInput, string strData ) {
|
|||
#endif
|
||||
|
||||
void NSEntity::SpawnKey( string strKey, string strValue ) {
|
||||
bool tempCheck = false;
|
||||
/* we do re-read a lot of the builtin fields in case we want to set
|
||||
defaults. just in case anybody is wondering. */
|
||||
switch ( strKey ) {
|
||||
case "spawnflags":
|
||||
spawnflags = stof( strValue );
|
||||
spawnflags = ReadFloat( strValue );
|
||||
break;
|
||||
case "origin":
|
||||
origin = stov( strValue );
|
||||
origin = ReadVector( strValue );
|
||||
break;
|
||||
case "model":
|
||||
model = strValue;
|
||||
model = ReadString(strValue);
|
||||
break;
|
||||
case "angles":
|
||||
angles = stov( strValue );
|
||||
angles = ReadVector( strValue );
|
||||
break;
|
||||
case "angle":
|
||||
angles[1] = stof( strValue );
|
||||
angles[1] = ReadFloat( strValue );
|
||||
break;
|
||||
case "solid":
|
||||
solid = stof( strValue );
|
||||
solid = ReadFloat( strValue );
|
||||
break;
|
||||
#ifdef SERVER
|
||||
case "health":
|
||||
health = stof( strValue );
|
||||
health = ReadFloat( strValue );
|
||||
break;
|
||||
case "parentname":
|
||||
SetParent( strValue );
|
||||
SetParent( ReadString(strValue) );
|
||||
break;
|
||||
case "ignorepvs":
|
||||
pvsflags = PVSF_IGNOREPVS;
|
||||
tempCheck = ReadBool(strValue);
|
||||
|
||||
if (tempCheck == true)
|
||||
pvsflags = PVSF_IGNOREPVS;
|
||||
else
|
||||
pvsflags &= ~PVSF_IGNOREPVS;
|
||||
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
|
|
|
@ -72,6 +72,9 @@ public:
|
|||
/** Called when the entity has been successfully restored from a savegame file. */
|
||||
virtual void RestoreComplete(void);
|
||||
|
||||
/** Called when the entity has successfully completed a level transition. */
|
||||
virtual void TransitionComplete(void);
|
||||
|
||||
/** Called when we are being prompted by another object/function with an input message. */
|
||||
virtual void Input(entity,string,string);
|
||||
|
||||
|
@ -109,6 +112,7 @@ public:
|
|||
nonvirtual void SaveBool(float,string,bool);
|
||||
/** Saves an entity id key/value pair to a filehandle. */
|
||||
nonvirtual void SaveEntity(float,string,entity);
|
||||
#endif
|
||||
|
||||
/* load game/spawn helper functions */
|
||||
/** reads a floating point value from a string */
|
||||
|
@ -123,7 +127,6 @@ public:
|
|||
nonvirtual bool ReadBool(string);
|
||||
/** read an entity id, converted to entity, from a string */
|
||||
nonvirtual entity ReadEntity(string);
|
||||
#endif
|
||||
|
||||
/** Get the level time the entity finds itself in.
|
||||
Always use this instead of the `time` global. The `time` global may not
|
||||
|
|
|
@ -96,6 +96,53 @@ NSIO::Spawned(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
NSIO::ReadBool(string strValue)
|
||||
{
|
||||
if (strValue && strValue != "")
|
||||
return stof(Constants_LookUp(strValue, strValue));
|
||||
return __NULL__;
|
||||
}
|
||||
float
|
||||
NSIO::ReadFloat(string strValue)
|
||||
{
|
||||
if (strValue && strValue != "")
|
||||
return stof(Constants_LookUp(strValue, strValue));
|
||||
return __NULL__;
|
||||
}
|
||||
int
|
||||
NSIO::ReadInt(string strValue)
|
||||
{
|
||||
if (strValue && strValue != "")
|
||||
return stoi(Constants_LookUp(strValue, strValue));
|
||||
return __NULL__;
|
||||
}
|
||||
string
|
||||
NSIO::ReadString(string strValue)
|
||||
{
|
||||
if (strValue && strValue != "")
|
||||
return Constants_LookUp(strValue, strValue);
|
||||
return __NULL__;
|
||||
}
|
||||
vector
|
||||
NSIO::ReadVector(string strValue)
|
||||
{
|
||||
if (strValue && strValue != "")
|
||||
return stov(Constants_LookUp(strValue, strValue));
|
||||
return __NULL__;
|
||||
}
|
||||
entity
|
||||
NSIO::ReadEntity(string strValue)
|
||||
{
|
||||
if (strValue && strValue != "") {
|
||||
float num = stof(strValue);
|
||||
|
||||
if (num)
|
||||
return edict_num(num);
|
||||
}
|
||||
return __NULL__;
|
||||
}
|
||||
|
||||
#ifdef SERVER
|
||||
/* Input/Output system */
|
||||
void
|
||||
|
@ -252,53 +299,6 @@ NSIO::SaveEntity(float handle, string key, entity targ)
|
|||
fputs(handle, sprintf("%S \"%f\"\n", key, value));
|
||||
}
|
||||
|
||||
bool
|
||||
NSIO::ReadBool(string strValue)
|
||||
{
|
||||
if (strValue && strValue != "")
|
||||
return stof(Constants_LookUp(strValue, strValue));
|
||||
return __NULL__;
|
||||
}
|
||||
float
|
||||
NSIO::ReadFloat(string strValue)
|
||||
{
|
||||
if (strValue && strValue != "")
|
||||
return stof(Constants_LookUp(strValue, strValue));
|
||||
return __NULL__;
|
||||
}
|
||||
int
|
||||
NSIO::ReadInt(string strValue)
|
||||
{
|
||||
if (strValue && strValue != "")
|
||||
return stoi(Constants_LookUp(strValue, strValue));
|
||||
return __NULL__;
|
||||
}
|
||||
string
|
||||
NSIO::ReadString(string strValue)
|
||||
{
|
||||
if (strValue && strValue != "")
|
||||
return Constants_LookUp(strValue, strValue);
|
||||
return __NULL__;
|
||||
}
|
||||
vector
|
||||
NSIO::ReadVector(string strValue)
|
||||
{
|
||||
if (strValue && strValue != "")
|
||||
return stov(Constants_LookUp(strValue, strValue));
|
||||
return __NULL__;
|
||||
}
|
||||
entity
|
||||
NSIO::ReadEntity(string strValue)
|
||||
{
|
||||
if (strValue && strValue != "") {
|
||||
float num = stof(strValue);
|
||||
|
||||
if (num)
|
||||
return edict_num(num);
|
||||
}
|
||||
return __NULL__;
|
||||
}
|
||||
|
||||
void
|
||||
NSIO::Save(float handle)
|
||||
{
|
||||
|
@ -699,6 +699,11 @@ void
|
|||
NSIO::RestoreComplete( void ) {
|
||||
/* this is where we can handle anything post-loading */
|
||||
}
|
||||
|
||||
void
|
||||
NSIO::TransitionComplete( void ) {
|
||||
/* this is where we can handle anything post-loading */
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
|
|
|
@ -610,29 +610,35 @@ NSPhysicsEntity::Respawn(void)
|
|||
void
|
||||
NSPhysicsEntity::SpawnKey(string strKey, string strValue)
|
||||
{
|
||||
bool tempCheck = false;
|
||||
|
||||
switch (strKey) {
|
||||
case "physmodel":
|
||||
m_iShape = stoi(strValue);
|
||||
m_iShape = ReadInt(strValue);
|
||||
if (m_iShape > PHYSM_CYLINDER)
|
||||
m_iShape = 0;
|
||||
break;
|
||||
case "massscale":
|
||||
mass = stof(strValue);
|
||||
mass = ReadFloat(strValue);
|
||||
break;
|
||||
case "inertiascale":
|
||||
m_flInertiaScale = stof(strValue);
|
||||
m_flInertiaScale = ReadFloat(strValue);
|
||||
break;
|
||||
case "physdamagescale":
|
||||
break;
|
||||
case "material":
|
||||
m_iMaterial = stof(strValue);
|
||||
m_iMaterial = ReadFloat(strValue);
|
||||
break;
|
||||
case "nodamageforces":
|
||||
if (strValue == "1")
|
||||
tempCheck = ReadBool(strValue);
|
||||
|
||||
if (tempCheck == true)
|
||||
m_iFlags |= BPHY_NODMGPUSH;
|
||||
break;
|
||||
case "Damagetype":
|
||||
if (strValue == "1")
|
||||
tempCheck = ReadBool(strValue);
|
||||
|
||||
if (tempCheck == true)
|
||||
m_iFlags |= BPHY_SHARP;
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -24,7 +24,7 @@ NSRenderableEntity::NSRenderableEntity(void)
|
|||
m_vecRenderColor[0] = 1.0f;
|
||||
m_vecRenderColor[1] = 1.0f;
|
||||
m_vecRenderColor[2] = 1.0f;
|
||||
m_flRenderAmt = 1.0f;
|
||||
m_flRenderAmt = 0.0f;
|
||||
m_flBoneControl1 = 0.5f;
|
||||
m_flBoneControl2 = 0.5f;
|
||||
m_flBoneControl3 = 0.5f;
|
||||
|
@ -644,16 +644,13 @@ NSRenderableEntity::postdraw(void)
|
|||
if not (autocvar(r_showRenderInfo, 0))
|
||||
return;
|
||||
|
||||
if not (PointMessage_Visible(origin, g_view.GetCameraOrigin(), g_view.GetCameraAngle()))
|
||||
if not (PointMessage_Visible(WorldSpaceCenter(), g_view.GetCameraOrigin(), g_view.GetCameraAngle()))
|
||||
return;
|
||||
|
||||
string renderMode;
|
||||
string renderFX;
|
||||
string renderMode = "";
|
||||
string renderFX = "";
|
||||
|
||||
switch (GetRenderMode()) {
|
||||
case RM_NORMAL:
|
||||
renderMode = "RM_NORMAL";
|
||||
break;
|
||||
case RM_COLOR:
|
||||
renderMode = "RM_COLOR";
|
||||
break;
|
||||
|
@ -681,12 +678,13 @@ NSRenderableEntity::postdraw(void)
|
|||
case RM_DONTRENDER:
|
||||
renderMode = "RM_DONTRENDER";
|
||||
break;
|
||||
case RM_NORMAL:
|
||||
default:
|
||||
renderMode = "RM_NORMAL";
|
||||
break;
|
||||
}
|
||||
|
||||
switch (GetRenderFX()) {
|
||||
case RFX_NORMAL:
|
||||
renderFX = "RFX_NORMAL";
|
||||
break;
|
||||
case RFX_SLOWPULSE:
|
||||
renderFX = "RFX_SLOWPULSE";
|
||||
break;
|
||||
|
@ -744,6 +742,10 @@ NSRenderableEntity::postdraw(void)
|
|||
case RFX_Q2PULSE:
|
||||
renderFX = "RFX_Q2PULSE";
|
||||
break;
|
||||
case RFX_NORMAL:
|
||||
default:
|
||||
renderFX = "RFX_NORMAL";
|
||||
break;
|
||||
}
|
||||
string renderString = sprintf("RC: %v\nRA: %f\nRM: %s\nRFX: %s",
|
||||
m_vecRenderColor, m_flRenderAmt, renderMode, renderFX);
|
||||
|
@ -1154,30 +1156,30 @@ NSRenderableEntity::SpawnKey(string strKey, string strValue)
|
|||
{
|
||||
switch (strKey) {
|
||||
case "body":
|
||||
m_iBody = stoi(strValue);
|
||||
m_iBody = ReadInt(strValue);
|
||||
break;
|
||||
case "body0":
|
||||
SetBodyInGroup(0, stoi(strValue));
|
||||
SetBodyInGroup(0, ReadInt(strValue));
|
||||
break;
|
||||
case "body1":
|
||||
SetBodyInGroup(1, stoi(strValue));
|
||||
SetBodyInGroup(1, ReadInt(strValue));
|
||||
break;
|
||||
case "body2":
|
||||
SetBodyInGroup(2, stoi(strValue));
|
||||
SetBodyInGroup(2, ReadInt(strValue));
|
||||
break;
|
||||
case "body3":
|
||||
SetBodyInGroup(3, stoi(strValue));
|
||||
SetBodyInGroup(3, ReadInt(strValue));
|
||||
break;
|
||||
case "modelscale":
|
||||
case "scale":
|
||||
scale = stof(strValue);
|
||||
scale = ReadFloat(strValue);
|
||||
break;
|
||||
case "modelstretch":
|
||||
case "axialscale":
|
||||
m_vecAxialScale = stov(strValue);
|
||||
m_vecAxialScale = ReadVector(strValue);
|
||||
break;
|
||||
case "skin":
|
||||
skin = stof(strValue);
|
||||
skin = ReadFloat(strValue);
|
||||
break;
|
||||
case "shadows":
|
||||
if (stof(strValue) == 1) {
|
||||
|
@ -1191,25 +1193,25 @@ NSRenderableEntity::SpawnKey(string strKey, string strValue)
|
|||
}
|
||||
break;
|
||||
case "renderamt":
|
||||
m_flRenderAmt = stof(strValue) / 255;
|
||||
m_flRenderAmt = ReadFloat(strValue) / 255;
|
||||
#ifdef SERVER
|
||||
m_oldflRenderAmt = m_flRenderAmt;
|
||||
#endif
|
||||
break;
|
||||
case "rendercolor":
|
||||
m_vecRenderColor = stov(strValue) / 255;
|
||||
m_vecRenderColor = ReadVector(strValue) / 255;
|
||||
#ifdef SERVER
|
||||
m_oldvecRenderColor = m_vecRenderColor;
|
||||
#endif
|
||||
break;
|
||||
case "rendermode":
|
||||
m_iRenderMode = stof(strValue);
|
||||
m_iRenderMode = ReadFloat(strValue);
|
||||
#ifdef SERVER
|
||||
m_oldiRenderMode = m_iRenderMode;
|
||||
#endif
|
||||
break;
|
||||
case "renderfx":
|
||||
m_iRenderFX = stof(strValue);
|
||||
m_iRenderFX = ReadFloat(strValue);
|
||||
#ifdef SERVER
|
||||
m_oldiRenderFX = m_iRenderFX;
|
||||
#endif
|
||||
|
|
|
@ -619,7 +619,7 @@ NSSurfacePropEntity::SpawnKey(string strKey, string strValue)
|
|||
{
|
||||
switch (strKey) {
|
||||
case "health":
|
||||
max_health = health = stof(strValue);
|
||||
max_health = health = ReadFloat(strValue);
|
||||
m_oldHealth = health;
|
||||
break;
|
||||
case "propdata":
|
||||
|
@ -636,7 +636,7 @@ NSSurfacePropEntity::SpawnKey(string strKey, string strValue)
|
|||
/* Input/Output system */
|
||||
#ifdef SERVER
|
||||
case "OnBreak":
|
||||
m_strOnBreak = PrepareOutput(m_strOnBreak, strValue);
|
||||
m_strOnBreak = PrepareOutput(m_strOnBreak, ReadString(strValue));
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
|
|
|
@ -685,10 +685,10 @@ NSTalkMonster::SpawnKey(string strKey, string strValue)
|
|||
{
|
||||
switch (strKey) {
|
||||
case "UnUseSentence":
|
||||
m_talkUnfollow = strcat("!", strValue);
|
||||
m_talkUnfollow = strcat("!", ReadString(strValue));
|
||||
break;
|
||||
case "UseSentence":
|
||||
m_talkFollow = strcat("!", strValue);
|
||||
m_talkFollow = strcat("!", ReadString(strValue));
|
||||
break;
|
||||
|
||||
/* entityDef */
|
||||
|
|
|
@ -118,6 +118,9 @@ public:
|
|||
/** Returns the name of the entity group it can trigger (legacy style). */
|
||||
nonvirtual string GetTriggerTarget(void);
|
||||
|
||||
/** Returns the first entity named after the target field. */
|
||||
nonvirtual entity GetTargetEntity(void);
|
||||
|
||||
/** Returns TRUE if the entity has a legacy trigger target. */
|
||||
nonvirtual bool HasTriggerTarget(void);
|
||||
|
||||
|
|
|
@ -193,6 +193,15 @@ NSTrigger::GetTriggerTarget(void)
|
|||
return target;
|
||||
}
|
||||
|
||||
entity
|
||||
NSTrigger::GetTargetEntity(void)
|
||||
{
|
||||
if (HasTriggerTarget() == false)
|
||||
return __NULL__;
|
||||
|
||||
return find(world, ::targetname, target);
|
||||
}
|
||||
|
||||
bool
|
||||
NSTrigger::HasTriggerTarget(void)
|
||||
{
|
||||
|
@ -304,25 +313,25 @@ NSTrigger::SpawnKey(string strKey, string strValue)
|
|||
switch (strKey) {
|
||||
#ifdef SERVER
|
||||
case "killtarget":
|
||||
m_strKillTarget = strValue;
|
||||
m_strKillTarget = ReadString(strValue);
|
||||
break;
|
||||
case "message":
|
||||
m_strMessage = strValue;
|
||||
m_strMessage = ReadString(strValue);
|
||||
break;
|
||||
case "master":
|
||||
m_strMaster = strValue;
|
||||
m_strMaster = ReadString(strValue);
|
||||
break;
|
||||
case "team_no":
|
||||
team_no = stof(strValue);
|
||||
team_no = ReadFloat(strValue);
|
||||
break;
|
||||
case "delay":
|
||||
m_flDelay = stof(strValue);
|
||||
m_flDelay = ReadFloat(strValue);
|
||||
break;
|
||||
case "globalstate":
|
||||
m_strGlobalState = strValue;
|
||||
m_strGlobalState = ReadString(strValue);
|
||||
break;
|
||||
case "globalname":
|
||||
m_strGlobalName = strValue;
|
||||
m_strGlobalName = ReadString(strValue);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
|
|
|
@ -34,8 +34,8 @@ NSVehicle::Save(float handle)
|
|||
SaveInt(handle, "m_iVehicleFlags", m_iVehicleFlags);
|
||||
SaveInt(handle, "m_iMoveButtons", m_iMoveButtons);
|
||||
SaveVector(handle, "m_vecMoveValues", m_vecMoveValues);
|
||||
SaveFloat(handle, "m_eDriver", num_for_edict(m_eDriver));
|
||||
SaveFloat(handle, "m_eDriverLast", num_for_edict(m_eDriverLast));
|
||||
SaveEntity(handle, "m_eDriver", m_eDriver);
|
||||
SaveEntity(handle, "m_eDriverLast", m_eDriverLast);
|
||||
SaveVector(handle, "m_vecPlayerPos", m_vecPlayerPos);
|
||||
SaveVector(handle, "m_vecExitPos", m_vecExitPos);
|
||||
}
|
||||
|
@ -54,10 +54,10 @@ NSVehicle::Restore(string strKey, string strValue)
|
|||
m_vecMoveValues = ReadVector(strValue);
|
||||
break;
|
||||
case "m_eDriver":
|
||||
m_eDriver = edict_num(stof(strValue));
|
||||
m_eDriver = ReadEntity(strValue);
|
||||
break;
|
||||
case "m_eDriverLast":
|
||||
m_eDriverLast = edict_num(stof(strValue));
|
||||
m_eDriverLast = ReadEntity(strValue);
|
||||
break;
|
||||
case "m_vecPlayerPos":
|
||||
m_vecPlayerPos = ReadVector(strValue);
|
||||
|
|
Loading…
Reference in a new issue