Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/components/CCmpMinimap.cpp
/* Copyright (C) 2017 Wildfire Games. | /* Copyright (C) 2018 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | public: | ||||
virtual void Deinit() | virtual void Deinit() | ||||
{ | { | ||||
} | } | ||||
template<typename S> | template<typename S> | ||||
void SerializeCommon(S& serialize) | void SerializeCommon(S& serialize) | ||||
{ | { | ||||
if (m_UsePlayerColor) | |||||
{ | |||||
serialize.NumberU8_Unbounded("r", m_R); | |||||
serialize.NumberU8_Unbounded("g", m_G); | |||||
serialize.NumberU8_Unbounded("b", m_B); | |||||
} | |||||
serialize.Bool("active", m_Active); | serialize.Bool("active", m_Active); | ||||
if (m_Active) | if (m_Active) | ||||
{ | { | ||||
serialize.NumberFixed_Unbounded("x", m_X); | serialize.NumberFixed_Unbounded("x", m_X); | ||||
serialize.NumberFixed_Unbounded("z", m_Z); | serialize.NumberFixed_Unbounded("z", m_Z); | ||||
} | } | ||||
} | } | ||||
Show All 28 Lines | case MT_PositionChanged: | ||||
{ | { | ||||
m_Active = false; | m_Active = false; | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
case MT_OwnershipChanged: | case MT_OwnershipChanged: | ||||
{ | { | ||||
if (!m_UsePlayerColor) | UpdateColor(); | ||||
break; | |||||
const CMessageOwnershipChanged& msgData = static_cast<const CMessageOwnershipChanged&> (msg); | |||||
// If there's no new owner (e.g. the unit is dying) then don't try updating the color | |||||
if (msgData.to == INVALID_PLAYER) | |||||
break; | |||||
// Find the new player's color | |||||
CmpPtr<ICmpPlayerManager> cmpPlayerManager(GetSystemEntity()); | |||||
if (!cmpPlayerManager) | |||||
break; | |||||
CmpPtr<ICmpPlayer> cmpPlayer(GetSimContext(), cmpPlayerManager->GetPlayerByID(msgData.to)); | |||||
if (!cmpPlayer) | |||||
break; | |||||
CColor color = cmpPlayer->GetColor(); | |||||
m_R = (u8)(color.r*255.0); | |||||
m_G = (u8)(color.g*255.0); | |||||
m_B = (u8)(color.b*255.0); | |||||
// TODO: probably should avoid using floating-point here | |||||
break; | break; | ||||
} | } | ||||
case MT_MinimapPing: | case MT_MinimapPing: | ||||
{ | { | ||||
CmpPtr<ICmpOwnership> cmpOwnership(GetSimContext(), GetEntityId()); | CmpPtr<ICmpOwnership> cmpOwnership(GetSimContext(), GetEntityId()); | ||||
if (!cmpOwnership || cmpOwnership->GetOwner() != (player_id_t)GetSimContext().GetCurrentDisplayedPlayer()) | if (!cmpOwnership || cmpOwnership->GetOwner() != (player_id_t)GetSimContext().GetCurrentDisplayedPlayer()) | ||||
break; | break; | ||||
Show All 30 Lines | virtual bool CheckPing(double currentTime, double pingDuration) | ||||
else if (currentTime > m_PingEndTime) | else if (currentTime > m_PingEndTime) | ||||
{ | { | ||||
m_IsPinging = false; | m_IsPinging = false; | ||||
m_PingEndTime = 0; | m_PingEndTime = 0; | ||||
} | } | ||||
return m_IsPinging; | return m_IsPinging; | ||||
} | } | ||||
virtual void UpdateColor() | |||||
{ | |||||
if (!m_UsePlayerColor) | |||||
return; | |||||
CmpPtr<ICmpOwnership> cmpOwnership(GetEntityHandle()); | |||||
if (!cmpOwnership) | |||||
return; | |||||
player_id_t owner = cmpOwnership->GetOwner(); | |||||
if (owner == INVALID_PLAYER) | |||||
return; | |||||
CmpPtr<ICmpPlayerManager> cmpPlayerManager(GetSystemEntity()); | |||||
if (!cmpPlayerManager) | |||||
return; | |||||
CmpPtr<ICmpPlayer> cmpPlayer(GetSimContext(), cmpPlayerManager->GetPlayerByID(owner)); | |||||
if (!cmpPlayer) | |||||
return; | |||||
CColor color = cmpPlayer->GetColor(); | |||||
m_R = (u8) (color.r * 255); | |||||
m_G = (u8) (color.g * 255); | |||||
m_B = (u8) (color.b * 255); | |||||
} | |||||
}; | }; | ||||
REGISTER_COMPONENT_TYPE(Minimap) | REGISTER_COMPONENT_TYPE(Minimap) |
Wildfire Games · Phabricator