ReGameDLL_CS/regamedll/dlls/pathcorner.cpp

435 lines
8.8 KiB
C++
Raw Normal View History

2015-06-30 12:46:07 +03:00
#include "precompiled.h"
/*
* Globals initialization
*/
#ifndef HOOK_GAMEDLL
TYPEDESCRIPTION CPathCorner::m_SaveData[] =
{
DEFINE_FIELD(CPathCorner, m_flWait, FIELD_FLOAT),
};
TYPEDESCRIPTION CPathTrack::m_SaveData[] =
{
DEFINE_FIELD(CPathTrack, m_length, FIELD_FLOAT),
DEFINE_FIELD(CPathTrack, m_pnext, FIELD_CLASSPTR),
DEFINE_FIELD(CPathTrack, m_paltpath, FIELD_CLASSPTR),
DEFINE_FIELD(CPathTrack, m_pprevious, FIELD_CLASSPTR),
DEFINE_FIELD(CPathTrack, m_altName, FIELD_STRING),
};
2015-09-16 23:19:21 +03:00
#else
TYPEDESCRIPTION IMPLEMENT_ARRAY_CLASS(CPathCorner, m_SaveData)[1];
TYPEDESCRIPTION IMPLEMENT_ARRAY_CLASS(CPathTrack, m_SaveData)[5];
2015-06-30 12:46:07 +03:00
#endif // HOOK_GAMEDLL
/* <122843> ../cstrike/dlls/pathcorner.cpp:41 */
LINK_ENTITY_TO_CLASS(path_corner, CPathCorner);
/* <1225b6> ../cstrike/dlls/pathcorner.cpp:49 */
IMPLEMENT_SAVERESTORE(CPathCorner, CPointEntity);
/* <122697> ../cstrike/dlls/pathcorner.cpp:54 */
2015-09-16 23:19:21 +03:00
void CPathCorner::__MAKE_VHOOK(KeyValue)(KeyValueData *pkvd)
2015-06-30 12:46:07 +03:00
{
2015-09-16 23:19:21 +03:00
if (FStrEq(pkvd->szKeyName, "wait"))
{
m_flWait = Q_atof(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else
CPointEntity::KeyValue(pkvd);
2015-06-30 12:46:07 +03:00
}
/* <122325> ../cstrike/dlls/pathcorner.cpp:66 */
2015-09-16 23:19:21 +03:00
void CPathCorner::__MAKE_VHOOK(Spawn)(void)
2015-06-30 12:46:07 +03:00
{
2015-09-16 23:19:21 +03:00
assert(("path_corner without a targetname", !FStringNull(pev->targetname)));
2015-06-30 12:46:07 +03:00
}
/* <12256a> ../cstrike/dlls/pathcorner.cpp:80 */
IMPLEMENT_SAVERESTORE(CPathTrack, CBaseEntity);
/* <12290d> ../cstrike/dlls/pathcorner.cpp:81 */
LINK_ENTITY_TO_CLASS(path_track, CPathTrack);
/* <122602> ../cstrike/dlls/pathcorner.cpp:86 */
2015-09-16 23:19:21 +03:00
void CPathTrack::__MAKE_VHOOK(KeyValue)(KeyValueData *pkvd)
2015-06-30 12:46:07 +03:00
{
2015-09-16 23:19:21 +03:00
if (FStrEq(pkvd->szKeyName, "altpath"))
{
m_altName = ALLOC_STRING(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else
CPointEntity::KeyValue(pkvd);
2015-06-30 12:46:07 +03:00
}
/* <122433> ../cstrike/dlls/pathcorner.cpp:97 */
2015-09-16 23:19:21 +03:00
void CPathTrack::__MAKE_VHOOK(Use)(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value)
2015-06-30 12:46:07 +03:00
{
2015-09-16 23:19:21 +03:00
int on;
// Use toggles between two paths
if (m_paltpath)
{
on = !(pev->spawnflags & SF_PATH_ALTERNATE);
if (ShouldToggle(useType, on))
{
if (on)
pev->spawnflags |= SF_PATH_ALTERNATE;
else
pev->spawnflags &= ~SF_PATH_ALTERNATE;
}
}
else // Use toggles between enabled/disabled
{
on = !(pev->spawnflags & SF_PATH_DISABLED);
if (ShouldToggle(useType, on))
{
if (on)
pev->spawnflags |= SF_PATH_DISABLED;
else
pev->spawnflags &= ~SF_PATH_DISABLED;
}
}
2015-06-30 12:46:07 +03:00
}
/* <122a12> ../cstrike/dlls/pathcorner.cpp:128 */
2015-09-16 23:19:21 +03:00
void CPathTrack::Link(void)
2015-06-30 12:46:07 +03:00
{
2015-09-16 23:19:21 +03:00
edict_t *pentTarget;
if (!FStringNull(pev->target))
{
pentTarget = FIND_ENTITY_BY_TARGETNAME(NULL, STRING(pev->target));
if (!FNullEnt(pentTarget))
{
m_pnext = CPathTrack::Instance(pentTarget);
// If no next pointer, this is the end of a path
if (m_pnext != NULL)
{
m_pnext->SetPrevious(this);
}
}
else
ALERT(at_console, "Dead end link %s\n", STRING(pev->target));
}
// Find "alternate" path
if (!FStringNull(m_altName))
{
pentTarget = FIND_ENTITY_BY_TARGETNAME(NULL, STRING(m_altName));
if (!FNullEnt(pentTarget))
{
m_paltpath = CPathTrack::Instance(pentTarget);
// If no next pointer, this is the end of a path
if (m_paltpath != NULL)
{
m_paltpath->SetPrevious(this);
}
}
}
2015-06-30 12:46:07 +03:00
}
/* <12239a> ../cstrike/dlls/pathcorner.cpp:165 */
2015-09-16 23:19:21 +03:00
void CPathTrack::__MAKE_VHOOK(Spawn)(void)
2015-06-30 12:46:07 +03:00
{
2015-09-16 23:19:21 +03:00
pev->solid = SOLID_TRIGGER;
UTIL_SetSize(pev, Vector(-8, -8, -8), Vector(8, 8, 8));
m_pnext = NULL;
m_pprevious = NULL;
2015-06-30 12:46:07 +03:00
}
/* <122c76> ../cstrike/dlls/pathcorner.cpp:180 */
2015-09-16 23:19:21 +03:00
void CPathTrack::__MAKE_VHOOK(Activate)(void)
2015-06-30 12:46:07 +03:00
{
2015-09-16 23:19:21 +03:00
// Link to next, and back-link
if (!FStringNull(pev->targetname))
{
Link();
}
2015-06-30 12:46:07 +03:00
}
/* <122c9c> ../cstrike/dlls/pathcorner.cpp:186 */
2015-09-16 23:19:21 +03:00
CPathTrack *CPathTrack::ValidPath(CPathTrack *ppath, int testFlag)
2015-06-30 12:46:07 +03:00
{
2015-09-16 23:19:21 +03:00
if (!ppath)
return NULL;
if (testFlag && (ppath->pev->spawnflags & SF_PATH_DISABLED))
return NULL;
return ppath;
2015-06-30 12:46:07 +03:00
}
/* <122745> ../cstrike/dlls/pathcorner.cpp:198 */
2015-09-16 23:19:21 +03:00
void CPathTrack::Project(CPathTrack *pstart, CPathTrack *pend, Vector *origin, float dist)
2015-06-30 12:46:07 +03:00
{
2015-09-16 23:19:21 +03:00
if (pstart && pend)
{
Vector dir = (pend->pev->origin - pstart->pev->origin);
dir = dir.Normalize();
*origin = pend->pev->origin + dir * dist;
}
2015-06-30 12:46:07 +03:00
}
/* <122d0f> ../cstrike/dlls/pathcorner.cpp:208 */
2015-09-16 23:19:21 +03:00
CPathTrack *CPathTrack::GetNext(void)
2015-06-30 12:46:07 +03:00
{
2015-09-16 23:19:21 +03:00
if (m_paltpath && (pev->spawnflags & SF_PATH_ALTERNATE) && !(pev->spawnflags & SF_PATH_ALTREVERSE))
{
return m_paltpath;
}
return m_pnext;
2015-06-30 12:46:07 +03:00
}
/* <122d30> ../cstrike/dlls/pathcorner.cpp:218 */
2015-09-16 23:19:21 +03:00
CPathTrack *CPathTrack::GetPrevious(void)
2015-06-30 12:46:07 +03:00
{
2015-09-16 23:19:21 +03:00
if (m_paltpath && (pev->spawnflags & SF_PATH_ALTERNATE) && (pev->spawnflags & SF_PATH_ALTREVERSE))
{
return m_paltpath;
}
return m_pprevious;
2015-06-30 12:46:07 +03:00
}
/* <122d51> ../cstrike/dlls/pathcorner.cpp:228 */
2015-09-16 23:19:21 +03:00
void CPathTrack::SetPrevious(CPathTrack *pprev)
2015-06-30 12:46:07 +03:00
{
2015-09-16 23:19:21 +03:00
// Only set previous if this isn't my alternate path
if (pprev && !FStrEq(STRING(pprev->pev->targetname), STRING(m_altName)))
{
m_pprevious = pprev;
}
2015-06-30 12:46:07 +03:00
}
2015-09-16 23:19:21 +03:00
// Assumes this is ALWAYS enabled
2015-06-30 12:46:07 +03:00
/* <122d95> ../cstrike/dlls/pathcorner.cpp:237 */
2015-09-16 23:19:21 +03:00
CPathTrack *CPathTrack::LookAhead(Vector *origin, float dist, int move)
2015-06-30 12:46:07 +03:00
{
2015-09-16 23:19:21 +03:00
CPathTrack *pcurrent;
float originalDist = dist;
pcurrent = this;
Vector currentPos = *origin;
// Travelling backwards through path
if (dist < 0)
{
dist = -dist;
while (dist > 0)
{
Vector dir = pcurrent->pev->origin - currentPos;
float_precision length = dir.Length();
if (!length)
{
// If there is no previous node, or it's disabled, return now.
if (!ValidPath(pcurrent->GetPrevious(), move))
{
if (!move)
{
Project(pcurrent->GetNext(), pcurrent, origin, dist);
}
return NULL;
}
pcurrent = pcurrent->GetPrevious();
}
// enough left in this path to move
else if (length > dist)
{
*origin = currentPos + (dir * ((float)(dist / length)));
return pcurrent;
}
else
{
dist -= length;
currentPos = pcurrent->pev->origin;
*origin = currentPos;
// If there is no previous node, or it's disabled, return now.
if (!ValidPath(pcurrent->GetPrevious(), move))
{
return NULL;
}
pcurrent = pcurrent->GetPrevious();
}
}
*origin = currentPos;
return pcurrent;
}
else
{
// #96 line
while (dist > 0)
{
// If there is no next node, or it's disabled, return now.
if (!ValidPath(pcurrent->GetNext(), move))
{
if (!move)
{
Project(pcurrent->GetPrevious(), pcurrent, origin, dist);
}
return NULL;
}
Vector dir = pcurrent->GetNext()->pev->origin - currentPos;
float_precision length = dir.Length();
if (!length && !ValidPath(pcurrent->GetNext()->GetNext(), move))
{
// HACK -- up against a dead end
if (dist == originalDist)
return NULL;
return pcurrent;
}
// enough left in this path to move
if (length > dist)
{
*origin = currentPos + (dir * ((float)(dist / length)));
return pcurrent;
}
else
{
dist -= length;
currentPos = pcurrent->GetNext()->pev->origin;
pcurrent = pcurrent->GetNext();
*origin = currentPos;
}
}
*origin = currentPos;
}
return pcurrent;
2015-06-30 12:46:07 +03:00
}
2015-09-16 23:19:21 +03:00
// Assumes this is ALWAYS enabled
2015-06-30 12:46:07 +03:00
/* <123220> ../cstrike/dlls/pathcorner.cpp:320 */
2015-09-16 23:19:21 +03:00
CPathTrack *CPathTrack::Nearest(Vector origin)
2015-06-30 12:46:07 +03:00
{
2015-09-16 23:19:21 +03:00
int deadCount;
float minDist, dist;
Vector delta;
CPathTrack *ppath, *pnearest;
delta = origin - pev->origin;
delta.z = 0;
minDist = delta.Length();
pnearest = this;
ppath = GetNext();
// Hey, I could use the old 2 racing pointers solution to this, but I'm lazy :)
deadCount = 0;
while (ppath != NULL && ppath != this)
{
deadCount++;
if (deadCount > 9999)
{
ALERT(at_error, "Bad sequence of path_tracks from %s", STRING(pev->targetname));
return NULL;
}
delta = origin - ppath->pev->origin;
delta.z = 0;
dist = delta.Length();
if (dist < minDist)
{
minDist = dist;
pnearest = ppath;
}
ppath = ppath->GetNext();
}
return pnearest;
2015-06-30 12:46:07 +03:00
}
/* <123375> ../cstrike/dlls/pathcorner.cpp:358 */
2015-09-16 23:19:21 +03:00
CPathTrack *CPathTrack::Instance(edict_t *pent)
2015-06-30 12:46:07 +03:00
{
2015-09-16 23:19:21 +03:00
if (FClassnameIs(pent, "path_track"))
{
return (CPathTrack *)GET_PRIVATE(pent);
}
return NULL;
2015-06-30 12:46:07 +03:00
}
#ifdef HOOK_GAMEDLL
void CPathCorner::Spawn(void)
{
Spawn_();
}
void CPathCorner::KeyValue(KeyValueData *pkvd)
{
KeyValue_(pkvd);
}
int CPathCorner::Save(CSave &save)
{
return Save_(save);
}
int CPathCorner::Restore(CRestore &restore)
{
return Restore_(restore);
}
void CPathTrack::Spawn(void)
{
Spawn_();
}
void CPathTrack::KeyValue(KeyValueData* pkvd)
{
KeyValue_(pkvd);
}
int CPathTrack::Save(CSave &save)
{
return Save_(save);
}
int CPathTrack::Restore(CRestore &restore)
{
return Restore_(restore);
}
void CPathTrack::Activate(void)
{
Activate_();
}
void CPathTrack::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value)
{
Use_(pActivator, pCaller, useType, value);
}
#endif // HOOK_GAMEDLL