Extract SnapPickup() to CGameContext helpers

This commit is contained in:
Alexander Akulich 2023-02-10 23:09:27 +03:00
parent 2ad5c020e0
commit 3a9e4ee067
3 changed files with 46 additions and 26 deletions

View file

@ -173,6 +173,7 @@ void CPickup::Snap(int SnappingClient)
pChar = GameServer()->GetPlayerChar(GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID); pChar = GameServer()->GetPlayerChar(GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID);
int SnappingClientVersion = GameServer()->GetClientVersion(SnappingClient); int SnappingClientVersion = GameServer()->GetClientVersion(SnappingClient);
bool Sixup = SnappingClientVersion == VERSION_NONE ? Server()->IsSixup(SnappingClient) : false;
CNetObj_EntityEx *pEntData = 0; CNetObj_EntityEx *pEntData = 0;
if(SnappingClientVersion >= VERSION_DDNET_SWITCH && (m_Layer == LAYER_SWITCH || length(m_Core) > 0)) if(SnappingClientVersion >= VERSION_DDNET_SWITCH && (m_Layer == LAYER_SWITCH || length(m_Core) > 0))
@ -191,30 +192,7 @@ void CPickup::Snap(int SnappingClient)
return; return;
} }
int Size = Server()->IsSixup(SnappingClient) ? sizeof(protocol7::CNetObj_Pickup) : sizeof(CNetObj_Pickup); GameServer()->SnapPickup(CSnapContext(SnappingClientVersion, Sixup), GetID(), m_Pos, m_Type, m_Subtype);
CNetObj_Pickup *pPickup = static_cast<CNetObj_Pickup *>(Server()->SnapNewItem(NETOBJTYPE_PICKUP, GetID(), Size));
if(!pPickup)
return;
pPickup->m_X = (int)m_Pos.x;
pPickup->m_Y = (int)m_Pos.y;
pPickup->m_Type = m_Type;
if(SnappingClientVersion < VERSION_DDNET_WEAPON_SHIELDS)
{
if(m_Type >= POWERUP_ARMOR_SHOTGUN && m_Type <= POWERUP_ARMOR_LASER)
{
pPickup->m_Type = POWERUP_ARMOR;
}
}
if(Server()->IsSixup(SnappingClient))
{
if(m_Type == POWERUP_WEAPON)
pPickup->m_Type = m_Subtype == WEAPON_SHOTGUN ? protocol7::PICKUP_SHOTGUN : m_Subtype == WEAPON_GRENADE ? protocol7::PICKUP_GRENADE : protocol7::PICKUP_LASER;
else if(m_Type == POWERUP_NINJA)
pPickup->m_Type = protocol7::PICKUP_NINJA;
}
else
pPickup->m_Subtype = m_Subtype;
} }
void CPickup::Move() void CPickup::Move()

View file

@ -404,6 +404,45 @@ bool CGameContext::SnapLaserObject(const CSnapContext &Context, int SnapID, cons
return true; return true;
} }
bool CGameContext::SnapPickup(const CSnapContext &Context, int SnapID, const vec2 &Pos, int Type, int SubType)
{
if(Context.IsSixup())
{
protocol7::CNetObj_Pickup *pPickup = Server()->SnapNewItem<protocol7::CNetObj_Pickup>(SnapID);
if(!pPickup)
return false;
pPickup->m_X = (int)Pos.x;
pPickup->m_Y = (int)Pos.y;
if(Type == POWERUP_WEAPON)
pPickup->m_Type = SubType == WEAPON_SHOTGUN ? protocol7::PICKUP_SHOTGUN : SubType == WEAPON_GRENADE ? protocol7::PICKUP_GRENADE : protocol7::PICKUP_LASER;
else if(Type == POWERUP_NINJA)
pPickup->m_Type = protocol7::PICKUP_NINJA;
}
else
{
CNetObj_Pickup *pPickup = Server()->SnapNewItem<CNetObj_Pickup>(SnapID);
if(!pPickup)
return false;
pPickup->m_X = (int)Pos.x;
pPickup->m_Y = (int)Pos.y;
pPickup->m_Type = Type;
if(Context.GetClientVersion() < VERSION_DDNET_WEAPON_SHIELDS)
{
if(Type >= POWERUP_ARMOR_SHOTGUN && Type <= POWERUP_ARMOR_LASER)
{
pPickup->m_Type = POWERUP_ARMOR;
}
}
pPickup->m_Subtype = SubType;
}
return true;
}
void CGameContext::CallVote(int ClientID, const char *pDesc, const char *pCmd, const char *pReason, const char *pChatmsg, const char *pSixupDesc) void CGameContext::CallVote(int ClientID, const char *pDesc, const char *pCmd, const char *pReason, const char *pChatmsg, const char *pSixupDesc)
{ {
// check if a vote is already running // check if a vote is already running

View file

@ -61,15 +61,17 @@ struct CScoreRandomMapResult;
struct CSnapContext struct CSnapContext
{ {
CSnapContext(int Version) : CSnapContext(int Version, bool Sixup = false) :
m_ClientVersion(Version) m_ClientVersion(Version), m_Sixup(Sixup)
{ {
} }
int GetClientVersion() const { return m_ClientVersion; } int GetClientVersion() const { return m_ClientVersion; }
bool IsSixup() const { return m_Sixup; }
private: private:
int m_ClientVersion; int m_ClientVersion;
bool m_Sixup;
}; };
class CGameContext : public IGameServer class CGameContext : public IGameServer
@ -227,6 +229,7 @@ public:
void CreateSoundGlobal(int Sound, int Target = -1); void CreateSoundGlobal(int Sound, int Target = -1);
bool SnapLaserObject(const CSnapContext &Context, int SnapID, const vec2 &To, const vec2 &From, int StartTick, int Owner = -1, int LaserType = -1); bool SnapLaserObject(const CSnapContext &Context, int SnapID, const vec2 &To, const vec2 &From, int StartTick, int Owner = -1, int LaserType = -1);
bool SnapPickup(const CSnapContext &Context, int SnapID, const vec2 &Pos, int Type, int SubType);
enum enum
{ {