diff --git a/binaries/data/mods/public/simulation/components/GuiInterface.js b/binaries/data/mods/public/simulation/components/GuiInterface.js
index 4ce8c71..0129529 100644
a
|
b
|
GuiInterface.prototype.GetSimulationState = function(player)
|
65 | 65 | // store player ally/enemy data as arrays |
66 | 66 | var allies = []; |
67 | 67 | var enemies = []; |
68 | | for (var j = 0; j <= n; ++j) |
| 68 | for (var j = 0; j < n; ++j) |
69 | 69 | { |
70 | 70 | allies[j] = cmpPlayer.IsAlly(j); |
71 | 71 | enemies[j] = cmpPlayer.IsEnemy(j); |
72 | 72 | } |
| 73 | |
| 74 | var diplomacy = []; |
| 75 | for (var k = 0; k < allies.length; ++k) |
| 76 | { |
| 77 | if (allies[k]) |
| 78 | diplomacy.push(k); |
| 79 | } |
| 80 | cmpPlayer.SetAllies(diplomacy); |
| 81 | |
73 | 82 | var playerData = { |
74 | 83 | "name": cmpPlayer.GetName(), |
75 | 84 | "civ": cmpPlayer.GetCiv(), |
diff --git a/binaries/data/mods/public/simulation/components/Player.js b/binaries/data/mods/public/simulation/components/Player.js
index cb73201..bbb5a12 100644
a
|
b
|
Player.prototype.Init = function()
|
23 | 23 | this.team = -1; // team number of the player, players on the same team will always have ally diplomatic status - also this is useful for team emblems, scoring, etc. |
24 | 24 | this.state = "active"; // game state - one of "active", "defeated", "won" |
25 | 25 | this.diplomacy = []; // array of diplomatic stances for this player with respect to other players (including gaia and self) |
| 26 | this.allies = []; // non-sparse array of a player's allies (including self) |
26 | 27 | this.conquestCriticalEntitiesCount = 0; // number of owned units with ConquestCritical class |
27 | 28 | this.phase = "village"; |
28 | 29 | this.formations = []; |
… |
… |
Player.prototype.SetTeam = function(team)
|
213 | 214 | this.team = team; |
214 | 215 | }; |
215 | 216 | |
| 217 | Player.prototype.GetAllies = function() |
| 218 | { |
| 219 | return this.allies; |
| 220 | }; |
| 221 | |
| 222 | Player.prototype.SetAllies = function(allies) |
| 223 | { |
| 224 | this.allies = allies; |
| 225 | }; |
| 226 | |
216 | 227 | Player.prototype.GetDiplomacy = function() |
217 | 228 | { |
218 | 229 | return this.diplomacy; |
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..d882dfd 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 | m_PlayerTeamMasks[i] = cmpRangeManager->GetLosVisibilityMask( cmpPlayer->GetAllies() ); |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | |
| 383 | u32 CGame::GetPlayerTeamMask(int player) const |
| 384 | { |
| 385 | if (player < 0 || player >= (int)m_PlayerTeamMasks.size()) |
| 386 | return 0; |
| 387 | |
| 388 | return m_PlayerTeamMasks[player]; |
| 389 | } |
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..8658ecd 100644
a
|
b
|
public:
|
43 | 43 | return m_Script.Call<std::wstring>("GetCiv"); |
44 | 44 | } |
45 | 45 | |
| 46 | virtual std::vector<int> GetAllies() |
| 47 | { |
| 48 | return m_Script.Call<std::vector<int> >("GetAllies"); |
| 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..fe1b95a 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> GetAllies() = 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. |