Skip to content

Commit

Permalink
mod: Print a message on character taking a damage
Browse files Browse the repository at this point in the history
This is wanted to suppress clang warning about unused member variable.
  • Loading branch information
Kaffeine committed Dec 20, 2023
1 parent 184300b commit 69a496a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/game/server/gamemodes/mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class CCharacterMod : public CCharacter
public:
CCharacterMod(CGameControllerMod *pGameController, CNetObj_PlayerInput LastInput);

bool TakeDamage(vec2 Force, int Dmg, int From, int Weapon) override;

protected:
CGameControllerMod *m_pGameController = nullptr;
};
Expand All @@ -26,6 +28,12 @@ CCharacterMod::CCharacterMod(CGameControllerMod *pGameController, CNetObj_Player
{
}

bool CCharacterMod::TakeDamage(vec2 Force, int Dmg, int From, int Weapon)
{
m_pGameController->OnCharacterTakeDamage(this, Dmg, From, Weapon);
return CCharacter::TakeDamage(Force, Dmg, From, Weapon);
}

MACRO_ALLOC_POOL_ID_IMPL(CCharacterMod, MAX_CLIENTS)

class CPlayerMod : public CPlayer
Expand Down Expand Up @@ -74,3 +82,10 @@ void CGameControllerMod::Tick()

IGameController::Tick();
}

void CGameControllerMod::OnCharacterTakeDamage(CCharacterMod *pCharacter, int Damage, int From, int Weapon)
{
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "You've received %d damage points from player %d", Damage, From);
GameServer()->SendChatTarget(pCharacter->GetPlayer()->GetCID(), aBuf);
}
2 changes: 2 additions & 0 deletions src/game/server/gamemodes/mod.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class CGameControllerMod : public IGameController

void Tick() override;

void OnCharacterTakeDamage(class CCharacterMod *pCharacter, int Damage, int From, int Weapon);

using IGameController::GameServer;
};
#endif // GAME_SERVER_GAMEMODES_MOD_H

0 comments on commit 69a496a

Please sign in to comment.