Skip to content

Commit

Permalink
more monster debug prep for demos
Browse files Browse the repository at this point in the history
rearranged condition and memory bits to save space in demos (most toggled flags come first). Schedules can be converted to/from an integer id. Marked more projectiles as abnormal monsters.
  • Loading branch information
wootguy committed Nov 8, 2024
1 parent 0839324 commit dcd6286
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 42 deletions.
3 changes: 3 additions & 0 deletions cl_dll/hl/hl_baseentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ const char* CBaseMonster::DisplayName() {return "";}
BOOL CBaseMonster::IsMachine() {return 0;}
void CBaseMonster::Precache() {}
void CBaseMonster::GetAllSchedules(std::unordered_set<Schedule_t*>& schedulesOut) {}
Schedule_t* CBaseMonster::ScheduleFromTableIdx(uint32_t idx) { return NULL; }
int CBaseMonster::GetScheduleTableSize() { return 0; }
int CBaseMonster::GetScheduleTableIdx() { return 0; }

int TrainSpeed(int iSpeed, int iMax) { return 0; }
void CBasePlayer :: DeathSound( void ) { }
Expand Down
2 changes: 1 addition & 1 deletion dlls/Scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ScheduledFunction {
ScheduledFunction() {}
ScheduledFunction(int scheduleId) : scheduleId(scheduleId) {}

bool HasBeenRemoved();
EXPORT bool HasBeenRemoved();
};

EXPORT extern unsigned int g_schedule_id; // don't touch this
Expand Down
4 changes: 4 additions & 0 deletions dlls/eng_wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,4 +701,8 @@ void PLAYBACK_EVENT_FULL(int flags, const edict_t* pInvoker, unsigned short even
iparam1, iparam2, bparam1, bparam2);
g_engfuncs.pfnPlaybackEvent(flags, pInvoker, eventindex, delay, origin, angles, fparam1, fparam2,
iparam1, iparam2, bparam1, bparam2);
}

EXPORT string_t ALLOC_STRING(const char* str) {
return g_engfuncs.pfnAllocString(str);
}
2 changes: 2 additions & 0 deletions dlls/eng_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ inline void MESSAGE_BEGIN(int msg_dest, int msg_type, const float* pOrigin = NUL
#define CMD_ARGV (*g_engfuncs.pfnCmd_Argv)
#define CHANGE_LEVEL (*g_engfuncs.pfnChangeLevel)
#define PLAYBACK_EVENT_FULL (*g_engfuncs.pfnPlaybackEvent)
#define ALLOC_STRING (*g_engfuncs.pfnAllocString)
#else
// engine wrappers which handle model/sound replacement logic
EXPORT int PRECACHE_GENERIC(const char* path);
Expand Down Expand Up @@ -91,4 +92,5 @@ EXPORT int CMD_ARGC();
EXPORT const char* CMD_ARGS();
EXPORT void CHANGE_LEVEL(const char* pszLevelName, const char* pszLandmarkName);
EXPORT void PLAYBACK_EVENT_FULL(int flags, const edict_t* pInvoker, unsigned short eventindex, float delay, float* origin, float* angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2);
EXPORT string_t ALLOC_STRING(const char*);
#endif
1 change: 0 additions & 1 deletion dlls/enginecallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ inline void *GET_PRIVATE( const edict_t *pent )

#define FREE_PRIVATE (*g_engfuncs.pfnFreeEntPrivateData)
//#define STRING (*g_engfuncs.pfnSzFromIndex)
#define ALLOC_STRING (*g_engfuncs.pfnAllocString)
#define FIND_ENTITY_BY_STRING (*g_engfuncs.pfnFindEntityByString)
#define GETENTITYILLUM (*g_engfuncs.pfnGetEntityIllum)
#define FIND_ENTITY_IN_SPHERE (*g_engfuncs.pfnFindEntityInSphere)
Expand Down
16 changes: 16 additions & 0 deletions dlls/monster/CBaseMonster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7009,6 +7009,22 @@ Schedule_t* CBaseMonster::ScheduleInList(const char* pName, Schedule_t** pList,
return NULL;
}

Schedule_t* CBaseMonster::ScheduleFromTableIdx(uint32_t idx) {
return idx < ARRAYSIZE(m_scheduleList) ? m_scheduleList[idx] : NULL;
}

int CBaseMonster::GetScheduleTableSize() {
return ARRAYSIZE(m_scheduleList);
}

int CBaseMonster::GetScheduleTableIdx() {
for (int i = 0; i < ARRAYSIZE(m_scheduleList); i++) {
if (m_scheduleList[i] == m_pSchedule) {
return i;
}
}
}

//=========================================================
// GetScheduleOfType - returns a pointer to one of the
// monster's available schedules of the indicated type.
Expand Down
11 changes: 6 additions & 5 deletions dlls/monster/CBaseMonster.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ struct PlayerAttackInfo {
//
class EXPORT CBaseMonster : public CBaseToggle
{
private:
int m_afConditions;

public:
public:
typedef enum
{
SCRIPT_PLAYING = 0, // Playing the sequence
Expand Down Expand Up @@ -90,7 +87,8 @@ class EXPORT CBaseMonster : public CBaseToggle

int m_iHintNode; // this is the hint node that the monster is moving towards or performing active idle on.

int m_afMemory;
int m_afConditions; // don't touch. Use the accessor methods
int m_afMemory; // don't touch. Use the accessor methods

int m_iMaxHealth;// keeps track of monster's maximum health value (for re-healing, etc)

Expand Down Expand Up @@ -241,7 +239,10 @@ class EXPORT CBaseMonster : public CBaseToggle
Schedule_t *ScheduleInList( const char *pName, Schedule_t **pList, int listCount );

virtual void GetAllSchedules(std::unordered_set<Schedule_t*>& schedulesOut);
virtual int GetScheduleTableSize();
virtual int GetScheduleTableIdx(); // index of current schedule in this monster's schedule table (-1 = not found)
virtual Schedule_t *ScheduleFromName( const char *pName );
virtual Schedule_t *ScheduleFromTableIdx( uint32_t idx);
static Schedule_t *m_scheduleList[];

void MaintainSchedule ( void );
Expand Down
2 changes: 2 additions & 0 deletions dlls/monster/CController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,7 @@ class CControllerHeadBall : public CBaseMonster
void MovetoTarget( Vector vecTarget );
void Crawl( void );
const char* GetDeathNoticeWeapon() { return "weapon_crowbar"; }
virtual BOOL IsNormalMonster() { return FALSE; }
int m_iTrail;
int m_flNextAttack;
Vector m_vecIdeal;
Expand Down Expand Up @@ -1323,6 +1324,7 @@ class CControllerZapBall : public CBaseMonster
void Precache( void );
void EXPORT AnimateThink( void );
void EXPORT ExplodeTouch( CBaseEntity *pOther );
virtual BOOL IsNormalMonster() { return FALSE; }

EHANDLE m_hOwner;
};
Expand Down
1 change: 1 addition & 0 deletions dlls/monster/CCycler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class CCycler : public CBaseMonster
// Don't treat as a live target
virtual BOOL IsAlive( void ) { return FALSE; }
virtual BOOL IsAllowedToSpeak() { return TRUE; }
virtual BOOL IsNormalMonster() { return FALSE; }

virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
Expand Down
1 change: 1 addition & 0 deletions dlls/monster/CHornet.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class CHornet : public CBaseMonster
int IRelationship ( CBaseEntity *pTarget );
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
virtual BOOL IsNormalMonster() { return FALSE; }
static TYPEDESCRIPTION m_SaveData[];

void IgniteTrail( void );
Expand Down
33 changes: 27 additions & 6 deletions dlls/monster/monsters.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ EXPORT BOOL IsFacing(entvars_t* pevTest, const Vector& reference);
#define bits_MEMORY_MOVE_FAILED ( 1 << 5 )// Movement has already failed
#define bits_MEMORY_FLINCHED ( 1 << 6 )// Has already flinched
#define bits_MEMORY_KILLED ( 1 << 7 )// HACKHACK -- remember that I've already called my Killed()
#define bits_MEMORY_CUSTOM4 ( 1 << 28 ) // Monster-specific memory
#define bits_MEMORY_CUSTOM3 ( 1 << 29 ) // Monster-specific memory
#define bits_MEMORY_CUSTOM2 ( 1 << 30 ) // Monster-specific memory
#define bits_MEMORY_CUSTOM1 ( 1 << 31 ) // Monster-specific memory
#define bits_MEMORY_CUSTOM4 ( 1 << 12 ) // Monster-specific memory
#define bits_MEMORY_CUSTOM3 ( 1 << 13 ) // Monster-specific memory
#define bits_MEMORY_CUSTOM2 ( 1 << 14 ) // Monster-specific memory
#define bits_MEMORY_CUSTOM1 ( 1 << 15 ) // Monster-specific memory

// trigger conditions for scripted AI
// these MUST match the CHOICES interface in halflife.fgd for the base monster
Expand Down Expand Up @@ -167,7 +167,10 @@ class EXPORT CGib : public CBaseEntity

#define CUSTOM_SCHEDULES\
virtual Schedule_t *ScheduleFromName( const char *pName );\
virtual void GetAllSchedules( std::unordered_set<Schedule_t*>& schedulesOut );\
virtual Schedule_t* ScheduleFromTableIdx(uint32_t idx); \
virtual int GetScheduleTableSize(); \
virtual int GetScheduleTableIdx(); \
virtual void GetAllSchedules( std::unordered_set<Schedule_t*>& schedulesOut ); \
static Schedule_t *m_scheduleList[]

#define DEFINE_CUSTOM_SCHEDULES(derivedClass)\
Expand All @@ -181,12 +184,30 @@ class EXPORT CGib : public CBaseEntity
return baseClass::ScheduleFromName(pName);\
return pSchedule;\
} \
Schedule_t* derivedClass::ScheduleFromTableIdx(uint32_t idx) { \
Schedule_t* baseSched = baseClass::ScheduleFromTableIdx(idx); \
return !baseSched && idx < ARRAYSIZE(m_scheduleList) ? m_scheduleList[idx] : baseSched; \
} \
int derivedClass::GetScheduleTableSize() { \
return baseClass::GetScheduleTableSize() + ARRAYSIZE(m_scheduleList); \
} \
int derivedClass::GetScheduleTableIdx() { \
int baseIdx = baseClass::GetScheduleTableIdx(); \
if (baseIdx != -1) { \
return baseIdx; \
} \
for (int i = 0; i < ARRAYSIZE(m_scheduleList); i++) { \
if (m_scheduleList[i] == m_pSchedule) { \
return baseClass::GetScheduleTableSize() + i; \
} \
} \
} \
void derivedClass::GetAllSchedules(std::unordered_set<Schedule_t*>& schedulesOut) { \
baseClass::GetAllSchedules(schedulesOut); \
for (int i = 0; i < (int)ARRAYSIZE(m_scheduleList); i++) { \
schedulesOut.insert(m_scheduleList[i]); \
} \
}
} \



Expand Down
62 changes: 33 additions & 29 deletions dlls/monster/schedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ enum
// The goal index should indicate which schedule (ordinally) the monster is running.
// That way, when tasks fail, the AI can make decisions based on the context of the
// current goal and sequence rather than just the current schedule.
/*
enum
{
GOAL_ATTACK_ENEMY,
Expand All @@ -206,6 +207,7 @@ enum
GOAL_MOVE_TARGET,
GOAL_EAT,
};
*/

// an array of tasks is a task list
// an array of schedules is a schedule list
Expand Down Expand Up @@ -260,38 +262,40 @@ struct WayPoint_t
#define MOVEGOAL_LOCATION (bits_MF_TO_LOCATION)
#define MOVEGOAL_NODE (bits_MF_TO_NODE)

// these bits represent conditions that may befall the monster, of which some are allowed
// to interrupt certain schedules.
#define bits_COND_NO_AMMO_LOADED ( 1 << 0 ) // weapon needs to be reloaded!
#define bits_COND_SEE_HATE ( 1 << 1 ) // see something that you hate
#define bits_COND_SEE_FEAR ( 1 << 2 ) // see something that you are afraid of
#define bits_COND_SEE_DISLIKE ( 1 << 3 ) // see something that you dislike
#define bits_COND_TASK_FAILED ( 1 << 0 )
#define bits_COND_LIGHT_DAMAGE ( 1 << 1 ) // hurt a little
#define bits_COND_ENEMY_FACING_ME ( 1 << 2 ) // enemy is facing me
#define bits_COND_ENEMY_OCCLUDED ( 1 << 3 ) // target entity occluded by the world
#define bits_COND_SEE_ENEMY ( 1 << 4 ) // target entity is in full view.
#define bits_COND_ENEMY_OCCLUDED ( 1 << 5 ) // target entity occluded by the world
#define bits_COND_SMELL_FOOD ( 1 << 6 )
#define bits_COND_ENEMY_TOOFAR ( 1 << 7 )
#define bits_COND_LIGHT_DAMAGE ( 1 << 8 ) // hurt a little
#define bits_COND_HEAVY_DAMAGE ( 1 << 9 ) // hurt a lot
#define bits_COND_CAN_RANGE_ATTACK1 ( 1 << 10)
#define bits_COND_CAN_MELEE_ATTACK1 ( 1 << 11)
#define bits_COND_CAN_RANGE_ATTACK2 ( 1 << 12)
#define bits_COND_CAN_MELEE_ATTACK2 ( 1 << 13)
// #define bits_COND_CAN_RANGE_ATTACK3 ( 1 << 14)
#define bits_COND_PROVOKED ( 1 << 15)
#define bits_COND_NEW_ENEMY ( 1 << 16)
#define bits_COND_HEAR_SOUND ( 1 << 17) // there is an interesting sound
#define bits_COND_SMELL ( 1 << 18) // there is an interesting scent
#define bits_COND_ENEMY_FACING_ME ( 1 << 19) // enemy is facing me
#define bits_COND_ENEMY_DEAD ( 1 << 20) // enemy was killed. If you get this in combat, try to find another enemy. If you get it in alert, victory dance.
#define bits_COND_SEE_CLIENT ( 1 << 21) // see a client
#define bits_COND_SEE_NEMESIS ( 1 << 22) // see my nemesis

#define bits_COND_SPECIAL1 ( 1 << 28) // Defined by individual monster
#define bits_COND_SPECIAL2 ( 1 << 29) // Defined by individual monster
#define bits_COND_SEE_DISLIKE ( 1 << 5 ) // see something that you dislike
#define bits_COND_SEE_HATE ( 1 << 6 ) // see something that you hate
#define bits_COND_SEE_CLIENT ( 1 << 7 ) // see a client
#define bits_COND_SEE_FEAR ( 1 << 8 ) // see something that you are afraid of
#define bits_COND_SEE_NEMESIS ( 1 << 9 ) // see my nemesis
#define bits_COND_ENEMY_TOOFAR ( 1 << 10 )
#define bits_COND_NO_AMMO_LOADED ( 1 << 11 ) // weapon needs to be reloaded!
#define bits_COND_CAN_RANGE_ATTACK1 ( 1 << 12 )
#define bits_COND_CAN_RANGE_ATTACK2 ( 1 << 13 )
#define bits_COND_CAN_MELEE_ATTACK1 ( 1 << 14 )
#define bits_COND_CAN_MELEE_ATTACK2 ( 1 << 15 )

#define bits_COND_TASK_FAILED ( 1 << 30)
#define bits_COND_SCHEDULE_DONE ( 1 << 31)
#define bits_COND_SCHEDULE_DONE ( 1 << 16 )
#define bits_COND_SMELL_FOOD ( 1 << 17 )
#define bits_COND_HEAVY_DAMAGE ( 1 << 18 ) // hurt a lot
#define bits_COND_PROVOKED ( 1 << 19 )
#define bits_COND_NEW_ENEMY ( 1 << 20 )
#define bits_COND_HEAR_SOUND ( 1 << 21 ) // there is an interesting sound
#define bits_COND_SMELL ( 1 << 22 ) // there is an interesting scent
#define bits_COND_SPECIAL1 ( 1 << 23 ) // Defined by individual monster
#define bits_COND_SPECIAL2 ( 1 << 24 ) // Defined by individual monster
#define bits_COND_ENEMY_DEAD ( 1 << 25 ) // enemy was killed. If you get this in combat, try to find another enemy. If you get it in alert, victory dance.

// #define bits_COND_CAN_RANGE_ATTACK3 ( 1 << 14)
// #define bits_unused ( 1 << 23)
// #define bits_unused ( 1 << 24)
// #define bits_unused ( 1 << 25)
// #define bits_unused ( 1 << 26)
// #define bits_unused ( 1 << 27)

#define bits_COND_ALL_SPECIAL (bits_COND_SPECIAL1 | bits_COND_SPECIAL2)

Expand Down

0 comments on commit dcd6286

Please sign in to comment.