Skip to content

Commit

Permalink
misc map features + fixes
Browse files Browse the repository at this point in the history
- add nomaptrans cfg setting
- inventory item uses dropped model properties when viewed (carried settings often use a special sequence where it hovers above the player, which makes it go crazy when rotated in view mode)
- fix inventory weapon not removed when last item is kill targeted
- fix kingpin beams not working if custom model has no attachments
- fix weapon drop command working when undroppable items are held
- fix custom sentence parsing
  • Loading branch information
wootguy committed Dec 5, 2024
1 parent f241ea1 commit 3ddfaae
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 15 deletions.
2 changes: 2 additions & 0 deletions dlls/game/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ EXPORT extern std::unordered_set<std::string> g_shuffledMonsterSounds; // classe

EXPORT extern bool g_cfgsExecuted; // set to true after server and map cfgs are executed

EXPORT extern std::unordered_set<std::string> g_nomaptrans; // trigger_changelevel disabled for these maps

// mark a palyer weapon for precaching (alias names are ok)
EXPORT void AddPrecacheWeapon(std::string wepName);

Expand Down
8 changes: 8 additions & 0 deletions dlls/game/gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ extern DLL_GLOBAL BOOL g_fGameOver;
extern int gmsgDeathMsg; // client dll messages
extern int gmsgMOTD;

std::unordered_set<std::string> g_nomaptrans;

int g_teamplay = 0;

//=========================================================
Expand Down Expand Up @@ -163,6 +165,7 @@ void execMapCfg() {
"map_plugin",
"nosuit",
"nomedkit",
"nomaptrans",
};

static unordered_set<string> itemNames = {
Expand Down Expand Up @@ -264,6 +267,11 @@ void execMapCfg() {
continue;
}

if (name == "nomaptrans") {
g_nomaptrans.insert(value);
continue;
}

if (parts.size() > 1 && whitelistCommands.find(name) != whitelistCommands.end()) {
if (mp_prefer_server_maxspeed.value == 1 && name == "sv_maxspeed") {
int maxspeed = atoi(value.c_str());
Expand Down
8 changes: 6 additions & 2 deletions dlls/hooks/hlds_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ void ServerDeactivate( void )
g_mapWeapons.clear();
g_wavInfos.clear();
g_weaponClassnames.clear();
g_nomaptrans.clear();
clearNetworkMessageHistory();
g_mp3Command = "";
g_monstersNerfed = false;
Expand Down Expand Up @@ -1199,9 +1200,12 @@ int AddToFullPack( struct entity_state_s *state, int e, edict_t *ent, edict_t *h
(!ent->v.modelindex || !STRING(ent->v.model)) ||
((ent->v.flags & FL_SPECTATOR) && (ent != host));

// solid entities should always be sent to clients for collision prediction
bool solid = ent->v.solid >= SOLID_BBOX && ent->v.modelindex;

bool forceVisChecks = baseent->ForceVisChecks();

if (invisible && !forceVisChecks) {
if (invisible && !forceVisChecks && !solid) {
return 0; // exit now unless a vis check was requested for this ent
}

Expand All @@ -1222,7 +1226,7 @@ int AddToFullPack( struct entity_state_s *state, int e, edict_t *ent, edict_t *h
return 0;
}

if (invisible || forceVisChecks || (baseent->m_hidePlayers & plrbit)) {
if ((invisible && !solid) || forceVisChecks || (baseent->m_hidePlayers & plrbit)) {
return 0;
}

Expand Down
9 changes: 9 additions & 0 deletions dlls/item/CItemInventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,14 @@ void CItemInventory::ItemThink() {
pev->aiment = NULL;
pev->movetype = MOVETYPE_NOCLIP;

if (m_is_viewing != m_was_viewing) {
// show dropped model properties in case it has an animation for hovering above the player
// (will look very wrong if rotated)
ApplyModelProperties(!m_is_viewing);
}

m_was_viewing = m_is_viewing;

if (m_is_viewing) {
Vector angles = carrier->pev->v_angle;
angles.x += sinf(g_engfuncs.pfnTime() * 0.1f); // keep it moving so avelocity is smoothed
Expand Down Expand Up @@ -962,6 +970,7 @@ void CItemInventory::FireInvTargets(CBaseEntity* activator, InvTriggerTargets ta
}

void CItemInventory::UpdateOnRemove(void) {
Detach(false);
FireInvTargets(this, m_target_on_destroy);
}

Expand Down
1 change: 1 addition & 0 deletions dlls/item/CItemInventory.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class EXPORT CItemInventory : public CItem
// runtime state
bool m_is_moved; // true if the item was picked up or dropped (unset after returning)
bool m_is_viewing; // true if player is viewing the item on their "HUD"
bool m_was_viewing; // true if player was viewing the item last think
EHANDLE m_hHolder; // monster holding this item
EHANDLE m_pNext; // next item in the monster's inventory
int m_activation_count;
Expand Down
16 changes: 13 additions & 3 deletions dlls/monster/CKingpin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ class CKingpin : public CBaseMonster
float m_lastBeam;

int m_iSpitSprite;
int m_numAttachments;

static const char* pAttackHitSounds[];
static const char* pAttackMissSounds[];
Expand Down Expand Up @@ -453,6 +454,8 @@ void CKingpin::Spawn()
m_eyes[1].angle = 180; // back
m_eyes[2].angle = -90; // right
m_eyes[3].angle = 90; //left

m_numAttachments = GetAttachmentCount();
}

void CKingpin::Precache()
Expand Down Expand Up @@ -659,7 +662,14 @@ void CKingpin::LaserEyesThink() {
kingpin_eye_t& eye = m_eyes[i];

Vector attachOri, attachAngles;
GetAttachment(eye.iAttachment, attachOri, attachAngles);

if (eye.iAttachment < m_numAttachments) {
GetAttachment(eye.iAttachment, attachOri, attachAngles);
}
else {
attachOri = Center();
}

MAKE_VECTORS(Vector(0, pev->angles.y + eye.angle, 0));
Vector eyeDir = gpGlobals->v_forward;

Expand Down Expand Up @@ -701,8 +711,8 @@ void CKingpin::LaserEyesThink() {
CSoundEnt::InsertSound(bits_SOUND_COMBAT, pev->origin, NORMAL_GUN_VOLUME, 0.3);

RGBA color = RGBA(m_beamColor.x, m_beamColor.y, m_beamColor.z, 150);
UTIL_BeamEntPoint(entindex(), eye.iAttachment+1, target->Center(), kingBeamSpriteIdx, 0, 0, 2, 50, 32,
color, 0, MSG_PVS, pev->origin);
UTIL_BeamEntPoint(entindex(), eye.iAttachment + 1, target->Center(), kingBeamSpriteIdx,
0, 0, 2, 50, 32, color, 0, MSG_PVS, pev->origin);

CSprite* flr = CSprite::SpriteCreate(KINGPIN_FLARE_SPRITE, pev->origin, FALSE);
flr->SetAttachment(edict(), eye.iAttachment + 1);
Expand Down
18 changes: 9 additions & 9 deletions dlls/player/CBasePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5054,6 +5054,11 @@ void CBasePlayer::DropPlayerItem ( char *pszItemName )
// item we want to drop and hit a BREAK; pWeapon is the item.
if ( pWeapon )
{
if (!strcmp(STRING(pWeapon->pev->classname), "weapon_inventory")) {
DropAllInventoryItems();
return;
}

if ( !g_pGameRules->GetNextBestWeapon( this, pWeapon ) && !pWeapon->CanHolster())
return; // can't drop the item they asked for, may be something we can't holster

Expand All @@ -5065,13 +5070,6 @@ void CBasePlayer::DropPlayerItem ( char *pszItemName )

SetAnimation(PLAYER_DROP_ITEM);

if (!strcmp(STRING(pWeapon->pev->classname), "weapon_inventory")) {
if (RemovePlayerItem(pWeapon) && m_inventory) {
DropAllInventoryItems();
}
return;
}

if (!strcmp(STRING(pWeapon->pev->classname), "weapon_shockrifle")) {
// fixme: logic duplicated in kill code
if (RemovePlayerItem(pWeapon)) {
Expand Down Expand Up @@ -5844,9 +5842,9 @@ void CBasePlayer::ShowInteractMessage(const char* msg) {
}
}

void CBasePlayer::DropAllInventoryItems(bool deathDrop, bool respawnDrop) {
bool CBasePlayer::DropAllInventoryItems(bool deathDrop, bool respawnDrop) {
if (!m_inventory) {
return;
return true;
}

int itemCount = CountInventoryItems();
Expand Down Expand Up @@ -5887,6 +5885,8 @@ void CBasePlayer::DropAllInventoryItems(bool deathDrop, bool respawnDrop) {
}

pev->v_angle = old_vangle;

return !m_inventory;
}

void CBasePlayer::Revive() {
Expand Down
3 changes: 2 additions & 1 deletion dlls/player/CBasePlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,8 @@ class EXPORT CBasePlayer : public CBaseMonster

// if death=true, only drop items that are not marked to keep on death
// if respawn=true, only drop items that are not marked to keep on respawn
void DropAllInventoryItems(bool deathDrop = false, bool respawnDrop = false);
// returns false if not all inventory items were dropped due to restrictions
bool DropAllInventoryItems(bool deathDrop = false, bool respawnDrop = false);

virtual void Revive();

Expand Down
16 changes: 16 additions & 0 deletions dlls/triggers/CChangeLevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class CChangeLevel : public CBaseTrigger
void EXPORT ExecuteChangeLevel(void);
void EXPORT TouchChangeLevel(CBaseEntity* pOther);
void ChangeLevelNow(CBaseEntity* pActivator);
int GetEntindexPriority() { return ENTIDX_PRIORITY_NORMAL; } // in case it's made solid


static edict_t* FindLandmark(const char* pLandmarkName);
static int ChangeList(LEVELLIST* pLevelList, int maxList);
Expand Down Expand Up @@ -109,6 +111,20 @@ void CChangeLevel::Spawn(void)
if (!(pev->spawnflags & SF_CHANGELEVEL_USEONLY))
SetTouch(&CChangeLevel::TouchChangeLevel);
// ALERT( at_console, "TRANSITION: %s (%s)\n", m_szMapName, m_szLandmarkName );

if (g_nomaptrans.count(toLowerCase(m_szMapName))) {

pev->movetype = MOVETYPE_PUSH;
pev->solid = SOLID_BSP;

// rehlds won't call AddToFullPack if EF_NODRAW is used
pev->effects = 0;
pev->renderamt = 0;
pev->rendermode = kRenderTransTexture;

SetTouch(NULL);
UTIL_SetOrigin(pev, pev->origin);
}
}


Expand Down
14 changes: 14 additions & 0 deletions dlls/util/sentences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,20 @@ CustomSentence ParseSentence(std::string sentenceLine) {
parts[1] = parts[1].substr(slashIdx + 1);
}

// merge space-separated parts that are enclosed in parentheses
for (int i = 0; i < (int)parts.size(); i++) {
if (parts[i].find("(") != -1 && parts[i].find(")") == -1) {
while (i+1 < parts.size()) {
int k = i + 1;
parts[i] = parts[i] + " " + parts[k];
parts.erase(parts.begin() + k);
if (parts[i].find(")") != -1) {
break;
}
}
}
}

CustomSentence sent;
sent.name = sentName;

Expand Down

0 comments on commit 3ddfaae

Please sign in to comment.