Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added item_generic from HL: Opposing Force & CS:CZ Deleted Scenes #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 147 additions & 0 deletions dlls/genericitem.cpp
Original file line number Diff line number Diff line change
@@ -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<int>(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<char*>(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;
}
5 changes: 3 additions & 2 deletions linux/Makefile.agdll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions projects/vs2019/agdll.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
<ClCompile Include="..\..\dlls\agflood.cpp" />
<ClCompile Include="..\..\dlls\cvar.cpp" />
<ClCompile Include="..\..\dlls\agrandom.cpp" />
<ClCompile Include="..\..\dlls\genericitem.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\common\const.h" />
Expand Down
3 changes: 3 additions & 0 deletions projects/vs2019/agdll.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@
<ClCompile Include="..\..\dlls\speedrunstats.cpp">
<Filter>Source Files\dlls</Filter>
</ClCompile>
<ClCompile Include="..\..\dlls\genericitem.cpp">
<Filter>Source Files\dlls</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\dlls\doors.h">
Expand Down