diff --git a/dlls/genericitem.cpp b/dlls/genericitem.cpp new file mode 100644 index 00000000..6613becb --- /dev/null +++ b/dlls/genericitem.cpp @@ -0,0 +1,147 @@ +/*** +* +* Copyright (c) 1996-2001, Valve LLC. All rights reserved. +* +* This product contains software technology licensed from Id +* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. +* All Rights Reserved. +* +* This source code contains proprietary and confidential information of +* Valve LLC and its suppliers. Access to this code is restricted to +* persons who have executed a written SDK license with Valve. Any access, +* use or distribution of this code by or to any unlicensed person is illegal. +* +****/ +#include "extdll.h" +#include "util.h" +#include "cbase.h" + +const auto SF_ITEMGENERIC_DROP_TO_FLOOR = 1 << 0; +const auto SF_ITEMGENERIC_SOLID = 1 << 1; + +class CGenericItem : public CBaseAnimating +{ +public: + void KeyValue(KeyValueData* pkvd) override; + void Precache() override; + void Spawn() override; + + void EXPORT StartItem(); + void EXPORT AnimateThink(); + + void Use(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value) override; + + float m_lastTime; + int m_iSequence; +}; + +LINK_ENTITY_TO_CLASS(item_generic, CGenericItem); + +void CGenericItem::KeyValue(KeyValueData* pkvd) +{ + if (FStrEq("sequencename", pkvd->szKeyName)) + { + m_iSequence = ALLOC_STRING(pkvd->szValue); + pkvd->fHandled = true; + } + else if (FStrEq("skin", pkvd->szKeyName)) + { + pev->skin = static_cast(atof(pkvd->szValue)); + pkvd->fHandled = true; + } + else if (FStrEq("body", pkvd->szKeyName)) + { + pev->body = atoi(pkvd->szValue); + pkvd->fHandled = true; + } + else + { + CBaseDelay::KeyValue(pkvd); + } +} + +void CGenericItem::Precache() +{ + PRECACHE_MODEL(const_cast(STRING(pev->model))); +} + +void CGenericItem::Spawn() +{ + pev->solid = 0; + pev->movetype = 0; + pev->effects = 0; + pev->frame = 0; + + Precache(); + + SET_MODEL(edict(), STRING(pev->model)); + + if (m_iSequence) + { + SetThink(&CGenericItem::StartItem); + pev->nextthink = gpGlobals->time + 0.1; + } + + if (pev->spawnflags & SF_ITEMGENERIC_DROP_TO_FLOOR) + { + if (!g_engfuncs.pfnDropToFloor(pev->pContainingEntity)) + { + ALERT(at_error, "Item %s fell out of level at %f,%f,%f", STRING(pev->classname), pev->origin.x, pev->origin.y, pev->origin.z); + UTIL_Remove(this); + } + } + + if (pev->spawnflags & SF_ITEMGENERIC_SOLID) + { + Vector mins, maxs; + + pev->solid = SOLID_SLIDEBOX; + int sequence = LookupSequence(STRING(m_iSequence)); + + if (sequence == -1) + { + ALERT(at_console, "ERROR! FIX ME: item generic: %s, model: %s, does not have animation: %s\n", STRING(pev->targetname), STRING(pev->model), STRING(m_iSequence)); + + sequence = 0; + } + + ExtractBbox(sequence, mins, maxs); + + UTIL_SetSize(pev, mins, maxs); + UTIL_SetOrigin(pev, pev->origin); + } +} + +void CGenericItem::StartItem() +{ + pev->effects = 0; + + pev->sequence = LookupSequence(STRING(m_iSequence)); + pev->frame = 0; + ResetSequenceInfo(); + + SetThink(&CGenericItem::AnimateThink); + pev->nextthink = gpGlobals->time + 0.1; + pev->frame = 0; +} + +void CGenericItem::AnimateThink() +{ + DispatchAnimEvents(); + StudioFrameAdvance(); + + if (m_fSequenceFinished && !m_fSequenceLoops) + { + pev->frame = 0; + ResetSequenceInfo(); + } + + pev->nextthink = gpGlobals->time + 0.1; + m_lastTime = gpGlobals->time; +} + +void CGenericItem::Use(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value) +{ + SetThink(&CGenericItem::SUB_Remove); + pev->nextthink = gpGlobals->time + 0.1; +} diff --git a/linux/Makefile.agdll b/linux/Makefile.agdll index 6f512140..d241c3c7 100644 --- a/linux/Makefile.agdll +++ b/linux/Makefile.agdll @@ -161,7 +161,8 @@ HLDLL_OBJS = \ $(HLDLL_OBJ_DIR)/agflood.o \ $(HLDLL_OBJ_DIR)/cvar.o \ $(HLDLL_OBJ_DIR)/agrandom.o \ - $(HLDLL_OBJ_DIR)/speedrunstats.o + $(HLDLL_OBJ_DIR)/speedrunstats.o \ + $(HLDLL_OBJ_DIR)/genericitem.o HLWPN_OBJS = \ $(HLWPN_OBJ_DIR)/hl_wpn_glock.o @@ -190,7 +191,7 @@ dirs: $(MODNAME).$(SHLIBEXT): $(HLDLL_OBJS) $(HLWPN_OBJS) $(PM_OBJS) $(GAME_SHARED_OBJS) $(MINISTL_OBJS) $(CC) $(LDFLAGS) $(SHLIBLDFLAGS) -o $(BUILD_DIR)/$@ $(HLDLL_OBJS) $(HLWPN_OBJS) $(PM_OBJS) $(GAME_SHARED_OBJS) ./gendbg.sh $(BUILD_DIR)/$(MODNAME).$(SHLIBEXT) - + $(HLWPN_OBJ_DIR)/%.o : $(HLWPN_SRC_DIR)/%.cpp $(DO_HLWPN_CC) diff --git a/projects/vs2019/agdll.vcxproj b/projects/vs2019/agdll.vcxproj index 714deb66..5ccd2298 100644 --- a/projects/vs2019/agdll.vcxproj +++ b/projects/vs2019/agdll.vcxproj @@ -257,6 +257,7 @@ + diff --git a/projects/vs2019/agdll.vcxproj.filters b/projects/vs2019/agdll.vcxproj.filters index e43c91fd..f4a7f9bc 100644 --- a/projects/vs2019/agdll.vcxproj.filters +++ b/projects/vs2019/agdll.vcxproj.filters @@ -447,6 +447,9 @@ Source Files\dlls + + Source Files\dlls +