Skip to content

Commit

Permalink
use w_items.mdl to save model slots
Browse files Browse the repository at this point in the history
also fix batteries not working at all
  • Loading branch information
wootguy committed Sep 9, 2024
1 parent f0dc072 commit 190b1ea
Show file tree
Hide file tree
Showing 64 changed files with 260 additions and 75 deletions.
12 changes: 12 additions & 0 deletions dlls/CBasePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,8 @@ void CBasePlayer::PackDeadPlayerItems( void )

if (iAmmoRules == GR_PLR_DROP_AMMO_ACTIVE) {
SET_MODEL(pWeaponBox->edict(), rgpPackWeapons[iPW]->GetModelW());
pWeaponBox->pev->body = rgpPackWeapons[iPW]->MergedModelBody() != -1 ? rgpPackWeapons[iPW]->MergedModelBody() : 0;
pWeaponBox->pev->sequence = rgpPackWeapons[iPW]->pev->sequence;

if (!strcmp(STRING(rgpPackWeapons[iPW]->pev->classname), "weapon_tripmine")) {
pWeaponBox->pev->body = 3;
Expand Down Expand Up @@ -4855,6 +4857,9 @@ void CBasePlayer::DropPlayerItem ( char *pszItemName )
CBasePlayerWeapon* wep = pWeapon->GetWeaponPtr();
if (wep) {
SET_MODEL(pWeaponBox->edict(), wep->GetModelW());
pWeaponBox->pev->body = wep->MergedModelBody() != -1 ? wep->MergedModelBody() : 0;
pWeaponBox->pev->sequence = wep->pev->sequence;

if (!strcmp(STRING(pWeapon->pev->classname), "weapon_tripmine")) {
pWeaponBox->pev->body = 3;
pWeaponBox->pev->sequence = TRIPMINE_GROUND;
Expand Down Expand Up @@ -4939,13 +4944,17 @@ void CBasePlayer::DropAmmo(bool secondary) {

// get ammo entity model
string_t model = 0;
int body = 0;
int sequence = 0;
CBaseEntity* ammoEnt = (CBaseEntity*)CBaseEntity::Create(ammoEntName, pev->origin, pev->angles, edict());
if (!ammoEnt) {
ALERT(at_console, "Invalid ent in DropAmmo: %s\n", ammoEntName);
return;
}

model = ammoEnt->pev->model;
body = ammoEnt->pev->body;
sequence = ammoEnt->pev->sequence;

CWeaponBox* pWeaponBox = (CWeaponBox*)CBaseEntity::Create("weaponbox", pev->origin + gpGlobals->v_forward * 10, pev->angles, edict());
pWeaponBox->pev->angles.x = 0;
Expand Down Expand Up @@ -4974,6 +4983,9 @@ void CBasePlayer::DropAmmo(bool secondary) {

if (model) {
SET_MODEL(pWeaponBox->edict(), STRING(model));
pWeaponBox->pev->body = body;
pWeaponBox->pev->sequence = sequence;

if (!strcmp(ammoEntName, "weapon_tripmine")) {
pWeaponBox->pev->body = 3;
pWeaponBox->pev->sequence = TRIPMINE_GROUND;
Expand Down
3 changes: 3 additions & 0 deletions dlls/CWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ void CWorld::Precache(void)

PRECACHE_MODEL(NOT_PRECACHED_MODEL);

if (mp_mergemodels.value)
PRECACHE_MODEL(MERGED_ITEMS_MODEL);

g_Language = (int)CVAR_GET_FLOAT("sv_language");
if (g_Language == LANGUAGE_GERMAN)
{
Expand Down
2 changes: 2 additions & 0 deletions dlls/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ cvar_t mp_bulletspongemax ={"mp_bulletspongemax","4", FCVAR_SERVER, 0, 0 };
cvar_t mp_maxmonsterrespawns ={"mp_maxmonsterrespawns","-1", FCVAR_SERVER, 0, 0 };
cvar_t mp_edictsorting ={"mp_edictsorting","1", FCVAR_SERVER, 0, 0 };
cvar_t mp_shitcode ={"mp_shitcode","0", FCVAR_SERVER, 0, 0 };
cvar_t mp_mergemodels ={"mp_mergemodels","0", FCVAR_SERVER, 0, 0 };

cvar_t soundvariety={"mp_soundvariety","0", FCVAR_SERVER, 0, 0 };

Expand Down Expand Up @@ -196,6 +197,7 @@ void GameDLLInit( void )
CVAR_REGISTER (&mp_maxmonsterrespawns);
CVAR_REGISTER (&mp_edictsorting);
CVAR_REGISTER (&mp_shitcode);
CVAR_REGISTER (&mp_mergemodels);

CVAR_REGISTER (&mp_chattime);

Expand Down
1 change: 1 addition & 0 deletions dlls/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ extern cvar_t mp_shitcode; // conditionally enables shitty code that fixes criti
extern cvar_t mp_survival_supported;
extern cvar_t mp_survival_starton;
extern cvar_t mp_survival_restart;
extern cvar_t mp_mergemodels; // used merged models to save on model slots

// Enables classic func_pushable physics (which is horribly broken, but fun)
// The higher your FPS, the faster you can boost pushables. You also get boosted.
Expand Down
4 changes: 3 additions & 1 deletion dlls/item/CHealthKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ extern int gmsgItemPickup;

class CHealthKit : public CItem
{
virtual int MergedModelBody() { return MERGE_MDL_W_MEDKIT; }

void Spawn( void );
void Precache( void );
void KeyValue(KeyValueData* pkvd);
Expand Down Expand Up @@ -58,7 +60,7 @@ IMPLEMENT_SAVERESTORE( CHealthKit, CItem)
void CHealthKit :: Spawn( void )
{
Precache( );
SET_MODEL(ENT(pev), GetModel());
SetItemModel();

CItem::Spawn();
}
Expand Down
15 changes: 14 additions & 1 deletion dlls/item/CItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ void CItem::SetSize(Vector defaultMins, Vector defaultMaxs) {
UTIL_SetSize(pev, min, max);
}

void CItem::SetItemModel() {
if (pev->model || MergedModelBody() == -1) {
SET_MODEL(ENT(pev), GetModel());
}
else {
SET_MODEL_MERGED(ENT(pev), GetModel(), MergedModelBody());
}
}


extern int gEvilImpulse101;

Expand Down Expand Up @@ -180,5 +189,9 @@ void CItem::Materialize(void)
}

const char* CItem::GetModel() {
return pev->model ? STRING(pev->model) : m_defaultModel;
if (pev->model) {
return STRING(pev->model);
}

return mp_mergemodels.value && MergedModelBody() != -1 ? MERGED_ITEMS_MODEL : m_defaultModel;
}
2 changes: 2 additions & 0 deletions dlls/item/CItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class EXPORT CItem : public CBaseAnimating
virtual BOOL ShouldRespawn();
const char* GetModel();
void SetSize(Vector defaultMins, Vector defaultMaxs);
void SetItemModel();
virtual int MergedModelBody() { return -1; }

const char* m_defaultModel;
string_t m_sequence_name;
Expand Down
10 changes: 7 additions & 3 deletions dlls/item/CItemBattery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ class CItemBattery : public CItem
{
float m_healthcap;

virtual int MergedModelBody() { return MERGE_MDL_W_BATTERY; }

void Spawn(void)
{
Precache();
SET_MODEL(ENT(pev), GetModel());
SetItemModel();
CItem::Spawn();
}

Expand Down Expand Up @@ -52,7 +54,9 @@ class CItemBattery : public CItem
return FALSE;
}

float healthcap = m_healthcap > 0 ? m_healthcap : mp_startarmor.value;
float maxArmor = mp_startarmor.value > 100 ? mp_startarmor.value : 100;

float healthcap = m_healthcap > 0 ? m_healthcap : maxArmor;

if ((pPlayer->pev->armorvalue < healthcap) &&
(pPlayer->pev->weapons & (1 << WEAPON_SUIT)))
Expand All @@ -72,7 +76,7 @@ class CItemBattery : public CItem

// Suit reports new power level
// For some reason this wasn't working in release build -- round it.
pct = (int)((float)(pPlayer->pev->armorvalue * 100.0) * (1.0 / mp_startarmor.value) + 0.5);
pct = (int)((float)(pPlayer->pev->armorvalue * 100.0) * (1.0 / maxArmor) + 0.5);
pct = (pct / 5);
if (pct > 0)
pct--;
Expand Down
4 changes: 3 additions & 1 deletion dlls/item/CItemLongJump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

class CItemLongJump : public CItem
{
virtual int MergedModelBody() { return MERGE_MDL_W_LONGJUMP; }

void Spawn(void)
{
Precache();
SET_MODEL(ENT(pev), GetModel());
SetItemModel();
CItem::Spawn();
}
void Precache(void)
Expand Down
4 changes: 3 additions & 1 deletion dlls/item/CItemSecurity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

class CItemSecurity : public CItem
{
virtual int MergedModelBody() { return MERGE_MDL_W_SECURITY; }

void Spawn(void)
{
Precache();
SET_MODEL(ENT(pev), GetModel());
SetItemModel();
CItem::Spawn();
}
void Precache(void)
Expand Down
4 changes: 3 additions & 1 deletion dlls/item/CItemSuit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

class CItemSuit : public CItem
{
virtual int MergedModelBody() { return MERGE_MDL_W_SUIT; }

void Spawn(void)
{
Precache();
SET_MODEL(ENT(pev), GetModel());
SetItemModel();
CItem::Spawn();
}
void Precache(void)
Expand Down
4 changes: 2 additions & 2 deletions dlls/mod_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ struct HLCOOP_FUNCTIONS {
// return replacement model if one exists, otherwise the given model
const char* (*pfnGetModel)(const char* model);

// same as the engine function, but handles model replacements
void (*pfnSetModel)(edict_t* edict, const char* model);
// same as the engine function, but handles model replacements, returns true if the model was replaced
bool (*pfnSetModel)(edict_t* edict, const char* model);

// same as the engine function, but handles model replacements
int (*pfnModelIndex)(const char* model);
Expand Down
7 changes: 5 additions & 2 deletions dlls/monster/CApache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,8 @@ class CApacheHVR : public CGrenade
int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];

virtual int MergedModelBody() { return MERGE_MDL_HVR; }

int m_iTrail;
Vector m_vecForward;
};
Expand All @@ -1087,7 +1089,7 @@ void CApacheHVR :: Spawn( void )
pev->movetype = MOVETYPE_FLY;
pev->solid = SOLID_BBOX;

SET_MODEL(ENT(pev), "models/HVR.mdl");
SetGrenadeModel();
UTIL_SetSize(pev, Vector( 0, 0, 0), Vector(0, 0, 0));
UTIL_SetOrigin( pev, pev->origin );

Expand All @@ -1106,7 +1108,8 @@ void CApacheHVR :: Spawn( void )

void CApacheHVR :: Precache( void )
{
PRECACHE_MODEL("models/HVR.mdl");
m_defaultModel = "models/HVR.mdl";
PRECACHE_MODEL(GetModel());
m_iTrail = PRECACHE_MODEL("sprites/smoke.spr");
PRECACHE_SOUND ("weapons/rocket1.wav");
}
Expand Down
2 changes: 1 addition & 1 deletion dlls/monster/CShockRoach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ void COFShockRoach :: Precache()
//UTIL_PrecacheOther("weapon_shockrifle");
PRECACHE_MODEL("models/v_shock.mdl");
PRECACHE_MODEL("models/p_shock.mdl");
PRECACHE_MODEL("models/w_shock.mdl");
PRECACHE_MODEL("models/w_shock_rifle.mdl");
PRECACHE_MODEL("sprites/shockwave.spr");
PRECACHE_MODEL("sprites/lgtning.spr");
PRECACHE_SOUND("weapons/shock_fire.wav");
Expand Down
30 changes: 28 additions & 2 deletions dlls/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3270,6 +3270,17 @@ int PRECACHE_MODEL(const char* path) {

}

int PRECACHE_REPLACEMENT_MODEL(const char* path) {
std::string lowerPath = toLowerCase(path);
path = lowerPath.c_str();

if (!mp_mergemodels.value || g_modelReplacements.find(path) != g_modelReplacements.end()) {
return PRECACHE_MODEL(path);
}

return g_engfuncs.pfnPrecacheModel(NOT_PRECACHED_MODEL);
}

int PRECACHE_EVENT(int id, const char* path) {
std::string lowerPath = toLowerCase(path);
path = lowerPath.c_str();
Expand All @@ -3295,25 +3306,40 @@ int PRECACHE_EVENT(int id, const char* path) {
}
}

void SET_MODEL(edict_t* edict, const char* model) {
bool SET_MODEL(edict_t* edict, const char* model) {
if (model && model[0] == '*') {
// BSP model. No special handling.
g_engfuncs.pfnSetModel(edict, model);
return;
return false;
}

std::string lowerPath = toLowerCase(model);
model = lowerPath.c_str();
bool replaced = false;

if (g_modelReplacements.find(model) != g_modelReplacements.end()) {
model = g_modelReplacements[model].c_str();
replaced = true;
}

if (g_precachedModels.find(model) == g_precachedModels.end()) {
model = NOT_PRECACHED_MODEL;
}

g_engfuncs.pfnSetModel(edict, model);

return replaced;
}

bool SET_MODEL_MERGED(edict_t* edict, const char* model, int mergeId) {
if (!SET_MODEL(edict, model) && mp_mergemodels.value) {
// save on model slots by using the merged model that contains many different submodels
SET_MODEL(edict, MERGED_ITEMS_MODEL);
edict->v.body = mergeId;
return false;
}

return true;
}

const char* GET_MODEL(const char* model) {
Expand Down
43 changes: 42 additions & 1 deletion dlls/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,51 @@ extern int g_serveractive; // 1 if ServerActivate was called (no longer safe to
extern int g_edictsinit; // 1 if all edicts were allocated so that relocations can begin

#define NOT_PRECACHED_MODEL "models/" MOD_MODEL_FOLDER "not_precached.mdl"
#define MERGED_ITEMS_MODEL "models/" MOD_MODEL_FOLDER "w_items.mdl"
#define NOT_PRECACHED_SOUND "common/null.wav"
#define MAX_PRECACHE 512
#define MAX_PRECACHE_SOUND 511
#define MAX_PRECACHE_MODEL 510
#define MAX_PRECACHE_EVENT 256

enum merged_item_bodies {
MERGE_MDL_W_9MMAR,
MERGE_MDL_W_9MMARCLIP,
MERGE_MDL_W_9MMCLIP,
MERGE_MDL_W_9MMHANDGUN,
MERGE_MDL_W_357,
MERGE_MDL_W_357AMMOBOX,
MERGE_MDL_W_ARGRENADE,
MERGE_MDL_W_BATTERY,
MERGE_MDL_W_BGRAP,
MERGE_MDL_W_CHAINAMMO,
MERGE_MDL_W_CROSSBOW,
MERGE_MDL_W_CROSSBOW_CLIP,
MERGE_MDL_W_CROWBAR,
MERGE_MDL_W_DISPLACER,
MERGE_MDL_W_EGON,
MERGE_MDL_W_GAUSS,
MERGE_MDL_W_GAUSSAMMO,
MERGE_MDL_W_GRENADE,
MERGE_MDL_W_HGUN,
MERGE_MDL_W_LONGJUMP,
MERGE_MDL_W_MEDKIT,
MERGE_MDL_W_PIPE_WRENCH,
MERGE_MDL_W_RPG,
MERGE_MDL_W_RPGAMMO,
MERGE_MDL_W_SATCHEL,
MERGE_MDL_W_SECURITY,
MERGE_MDL_W_SHOTBOX,
MERGE_MDL_W_SHOTSHELL,
MERGE_MDL_W_SUIT,
MERGE_MDL_W_WEAPONBOX,
MERGE_MDL_GRENADE,
MERGE_MDL_HVR,
MERGE_MDL_RPGROCKET,
MERGE_MDL_SPORE,
MERGE_MDL_SHOCK_EFFECT,
};

extern Bsp g_bsp;

extern std::string g_mp3Command; // current global mp3 command
Expand Down Expand Up @@ -720,8 +759,10 @@ EXPORT int PRECACHE_GENERIC(const char* path);
EXPORT int PRECACHE_SOUND_ENT(CBaseEntity* ent, const char* path);
EXPORT int PRECACHE_SOUND_NULLENT(const char* path);
EXPORT int PRECACHE_MODEL(const char* model);
EXPORT int PRECACHE_REPLACEMENT_MODEL(const char* model); // only precache the model if it will be replaced
EXPORT int PRECACHE_EVENT(int id, const char* path);
EXPORT void SET_MODEL(edict_t* edict, const char* model);
EXPORT bool SET_MODEL(edict_t* edict, const char* model); // returns true if the given model was swapped with something else
EXPORT bool SET_MODEL_MERGED(edict_t* edict, const char* model, int mergeId); // will set the merged model and body if the given model was not replaced
EXPORT const char* GET_MODEL(const char* model); // return replacement model, if one exists, or the given model
EXPORT int MODEL_INDEX(const char* model);
EXPORT void* GET_MODEL_PTR(edict_t* edict);
Expand Down
Loading

0 comments on commit 190b1ea

Please sign in to comment.