diff --git a/source/graphics/GameView.cpp b/source/graphics/GameView.cpp
index 86e7c26..ca12aaf 100644
a
|
b
|
void CGameView::BeginFrame()
|
487 | 487 | CheckLightEnv(); |
488 | 488 | |
489 | 489 | m->Game->CachePlayerColours(); |
| 490 | m->Game->CachePlayerTeamMasks(); |
490 | 491 | } |
491 | 492 | |
492 | 493 | void CGameView::Render() |
diff --git a/source/graphics/LOSTexture.cpp b/source/graphics/LOSTexture.cpp
index e89c7d7..cb252cf 100644
a
|
b
|
void CLOSTexture::RecomputeTexture(int unit)
|
178 | 178 | if (!cmpRangeManager) |
179 | 179 | return; |
180 | 180 | |
181 | | ICmpRangeManager::CLosQuerier los (cmpRangeManager->GetLosQuerier(g_Game->GetPlayerID())); |
| 181 | u32 playerMask = g_Game->GetPlayerTeamMask(g_Game->GetPlayerID()); |
| 182 | ICmpRangeManager::CLosQuerier los (cmpRangeManager->GetLosQuerier(g_Game->GetPlayerID(), playerMask)); |
182 | 183 | |
183 | 184 | GenerateBitmap(los, &losData[0], m_MapSize, m_MapSize); |
184 | 185 | |
diff --git a/source/ps/Game.cpp b/source/ps/Game.cpp
index 83ec259..0bb4955 100644
a
|
b
|
CColor CGame::GetPlayerColour(int player) const
|
352 | 352 | |
353 | 353 | return m_PlayerColours[player]; |
354 | 354 | } |
| 355 | |
| 356 | |
| 357 | void CGame::CachePlayerTeamMasks() |
| 358 | { |
| 359 | m_PlayerTeamMasks.clear(); |
| 360 | |
| 361 | CmpPtr<ICmpPlayerManager> cmpPlayerManager(*m_Simulation2, SYSTEM_ENTITY); |
| 362 | if (!cmpPlayerManager) |
| 363 | return; |
| 364 | |
| 365 | CmpPtr<ICmpRangeManager> cmpRangeManager(*m_Simulation2, SYSTEM_ENTITY); |
| 366 | if (!cmpRangeManager) |
| 367 | return; |
| 368 | |
| 369 | int numPlayers = cmpPlayerManager->GetNumPlayers(); |
| 370 | m_PlayerTeamMasks.resize(numPlayers); |
| 371 | |
| 372 | for (int i = 0; i < numPlayers; ++i) |
| 373 | { |
| 374 | CmpPtr<ICmpPlayer> cmpPlayer(*m_Simulation2, cmpPlayerManager->GetPlayerByID(i)); |
| 375 | if (!cmpPlayer) |
| 376 | m_PlayerTeamMasks[i] = 0; |
| 377 | else |
| 378 | { |
| 379 | std::vector<int> diplomacy = cmpPlayer->GetDiplomacy(); |
| 380 | std::vector<int> allies; |
| 381 | for (size_t j = 0; j < diplomacy.size(); ++j) |
| 382 | if (diplomacy[j] == 1) |
| 383 | allies.push_back(j); |
| 384 | |
| 385 | m_PlayerTeamMasks[i] = cmpRangeManager->GetLosVisibilityMask( allies ); |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | |
| 391 | u32 CGame::GetPlayerTeamMask(int player) const |
| 392 | { |
| 393 | if (player < 0 || player >= (int)m_PlayerTeamMasks.size()) |
| 394 | return 0; |
| 395 | |
| 396 | return m_PlayerTeamMasks[player]; |
| 397 | } |
diff --git a/source/ps/Game.h b/source/ps/Game.h
index d6a1d18..70aedb6 100644
a
|
b
|
public:
|
97 | 97 | CColor GetPlayerColour(int player) const; |
98 | 98 | |
99 | 99 | /** |
| 100 | * Retrieves each player's list of allies and generates a mask that |
| 101 | * allows line-of-sight visibility to be checked against a player and |
| 102 | * all allies with one comparison. |
| 103 | */ |
| 104 | void CachePlayerTeamMasks(); |
| 105 | |
| 106 | u32 GetPlayerTeamMask(int player) const; |
| 107 | |
| 108 | /** |
100 | 109 | * Get m_GameStarted. |
101 | 110 | * |
102 | 111 | * @return bool the value of m_GameStarted. |
… |
… |
private:
|
158 | 167 | IReplayLogger* m_ReplayLogger; |
159 | 168 | |
160 | 169 | std::vector<CColor> m_PlayerColours; |
| 170 | std::vector<u32> m_PlayerTeamMasks; |
161 | 171 | |
162 | 172 | int LoadInitialState(); |
163 | 173 | std::string m_InitialSavedState; // valid between RegisterInit and LoadInitialState |
diff --git a/source/simulation2/components/CCmpRangeManager.cpp b/source/simulation2/components/CCmpRangeManager.cpp
index 44a098d..d7b8e4a 100644
a
|
b
|
|
32 | 32 | #include "lib/timer.h" |
33 | 33 | #include "maths/FixedVector2D.h" |
34 | 34 | #include "ps/CLogger.h" |
| 35 | #include "ps/Game.h" |
35 | 36 | #include "ps/Overlay.h" |
36 | 37 | #include "ps/Profile.h" |
37 | 38 | #include "renderer/Scene.h" |
… |
… |
public:
|
915 | 916 | return CLosQuerier(player, m_LosState, m_TerrainVerticesPerSide); |
916 | 917 | } |
917 | 918 | |
| 919 | virtual CLosQuerier GetLosQuerier(player_id_t player, u32 playerMask) |
| 920 | { |
| 921 | if (GetLosRevealAll(player)) |
| 922 | return CLosQuerier(playerMask, m_LosStateRevealed, m_TerrainVerticesPerSide); |
| 923 | else |
| 924 | return CLosQuerier(playerMask, m_LosState, m_TerrainVerticesPerSide); |
| 925 | } |
| 926 | |
918 | 927 | virtual ELosVisibility GetLosVisibility(entity_id_t ent, player_id_t player, bool forceRetainInFog) |
919 | 928 | { |
| 929 | return GetLosVisibility(ent, player, 0, forceRetainInFog); |
| 930 | } |
| 931 | |
| 932 | virtual ELosVisibility GetLosVisibility(entity_id_t ent, player_id_t player, u32 playerMask, bool forceRetainInFog) |
| 933 | { |
920 | 934 | // (We can't use m_EntityData since this needs to handle LOCAL entities too) |
921 | 935 | |
922 | 936 | // Entities not with positions in the world are never visible |
… |
… |
public:
|
939 | 953 | } |
940 | 954 | |
941 | 955 | // Visible if within a visible region |
| 956 | if (!playerMask) |
| 957 | playerMask = g_Game->GetPlayerTeamMask(player); |
942 | 958 | |
943 | | CLosQuerier los(player, m_LosState, m_TerrainVerticesPerSide); |
| 959 | CLosQuerier los(playerMask, m_LosState, m_TerrainVerticesPerSide); |
944 | 960 | |
945 | 961 | if (los.IsVisible(i, j)) |
946 | 962 | return VIS_VISIBLE; |
… |
… |
public:
|
957 | 973 | return VIS_HIDDEN; |
958 | 974 | } |
959 | 975 | |
| 976 | virtual u32 GetLosVisibilityMask(std::vector<player_id_t> players) |
| 977 | { |
| 978 | u32 playerMask = 0; |
| 979 | player_id_t player; |
| 980 | |
| 981 | for (size_t i = 0; i < players.size(); i++) |
| 982 | { |
| 983 | player = players[i]; |
| 984 | if (player > 0 && player <= 16) |
| 985 | playerMask |= LOS_MASK << (2*(player-1)); |
| 986 | else |
| 987 | continue; |
| 988 | } |
| 989 | |
| 990 | return playerMask; |
| 991 | } |
| 992 | |
960 | 993 | virtual void SetLosRevealAll(player_id_t player, bool enabled) |
961 | 994 | { |
962 | 995 | m_LosRevealAll[player] = enabled; |
diff --git a/source/simulation2/components/ICmpPlayer.cpp b/source/simulation2/components/ICmpPlayer.cpp
index 14b308d..19bb65e 100644
a
|
b
|
public:
|
43 | 43 | return m_Script.Call<std::wstring>("GetCiv"); |
44 | 44 | } |
45 | 45 | |
| 46 | virtual std::vector<int> GetDiplomacy() |
| 47 | { |
| 48 | return m_Script.Call<std::vector<int> >("GetDiplomacy"); |
| 49 | } |
| 50 | |
46 | 51 | virtual CFixedVector3D GetStartingCameraPos() |
47 | 52 | { |
48 | 53 | return m_Script.Call<CFixedVector3D>("GetStartingCameraPos"); |
diff --git a/source/simulation2/components/ICmpPlayer.h b/source/simulation2/components/ICmpPlayer.h
index fa30df5..bf62e5b 100644
a
|
b
|
class ICmpPlayer : public IComponent
|
33 | 33 | public: |
34 | 34 | virtual CColor GetColour() = 0; |
35 | 35 | virtual std::wstring GetCiv() = 0; |
| 36 | virtual std::vector<int> GetDiplomacy() = 0; |
36 | 37 | virtual CFixedVector3D GetStartingCameraPos() = 0; |
37 | 38 | virtual CFixedVector3D GetStartingCameraRot() = 0; |
38 | 39 | |
diff --git a/source/simulation2/components/ICmpRangeManager.h b/source/simulation2/components/ICmpRangeManager.h
index 142936e..2a61d77 100644
a
|
b
|
public:
|
194 | 194 | m_PlayerMask = 0; |
195 | 195 | } |
196 | 196 | |
| 197 | CLosQuerier(u32 playerMask, const std::vector<u32>& data, ssize_t verticesPerSide) : |
| 198 | m_Data(&data[0]), m_VerticesPerSide(verticesPerSide) |
| 199 | { |
| 200 | m_PlayerMask = playerMask; |
| 201 | } |
| 202 | |
197 | 203 | const CLosQuerier& operator=(const CLosQuerier&); // not implemented |
198 | 204 | |
199 | 205 | public: |
… |
… |
public:
|
269 | 275 | * Returns a CLosQuerier for checking whether vertex positions are visible to the given player. |
270 | 276 | */ |
271 | 277 | virtual CLosQuerier GetLosQuerier(player_id_t player) = 0; |
| 278 | virtual CLosQuerier GetLosQuerier(player_id_t player, u32 playerMask) = 0; |
272 | 279 | |
273 | 280 | /** |
274 | 281 | * Returns the visibility status of the given entity, with respect to the given player. |
… |
… |
public:
|
279 | 286 | * see http://trac.wildfiregames.com/ticket/958 |
280 | 287 | */ |
281 | 288 | virtual ELosVisibility GetLosVisibility(entity_id_t ent, player_id_t player, bool forceRetainInFog = false) = 0; |
| 289 | virtual u32 GetLosVisibilityMask(std::vector<player_id_t> players) = 0; |
282 | 290 | |
283 | 291 | /** |
284 | 292 | * GetLosVisibility wrapped for script calls. |