-
Notifications
You must be signed in to change notification settings - Fork 1
/
IGE_Controller_Fog.lua
136 lines (114 loc) · 3.81 KB
/
IGE_Controller_Fog.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
-- Released under GPL v3
-- Yes, this file is a mess. So is the fog in Civ5, full of naughty tricks. Good luck!
------------------------------------------------------------------------------------------
local IGE = nil;
local revealMap = false;
local opened = false;
-------------------------------------------------------------------------------------------------
local function RestoreFog()
if not revealMap then return end
print("RestoreFog")
FOW_SetAll(1);
-- Restore
for i = 0, Map.GetNumPlots()-1, 1 do
local plot = Map.GetPlotByIndex(i);
plot:UpdateFog();
end
Game.UpdateFOW(true);
UI.RequestMinimapBroadcast();
revealMap = false
end
-------------------------------------------------------------------------------------------------
local function HideFog()
if revealMap then return end
print("HideFog")
FOW_SetAll(0);
Game.UpdateFOW(true);
UI.RequestMinimapBroadcast();
revealMap = true
end
-------------------------------------------------------------------------------------------------
local function Update()
if not opened then return end
if IGE.revealMap == revealMap then return end
print("UpdateFog")
if IGE.revealMap then
HideFog()
else
RestoreFog()
end
end
LuaEvents.IGE_ToggleRevealMap.Add(Update);
-------------------------------------------------------------------------------------------------
local function OnSelectingPlayer(playerID, takeSeat)
if takeSeat then
RestoreFog()
end
end
LuaEvents.IGE_SelectingPlayer.Add(OnSelectingPlayer);
-------------------------------------------------------------------------------------------------
local function OnSelectedPlayer(playerID, takeSeat)
if takeSeat then
Update()
end
local pPlayer = Players[playerID];
local plot = pPlayer:GetStartingPlot()
if plot then UI.LookAt(plot, 0) end
end
LuaEvents.IGE_SelectedPlayer.Add(OnSelectedPlayer);
-------------------------------------------------------------------------------------------------
local function OnClosing(takingSeat)
RestoreFog()
opened = false
end
LuaEvents.IGE_Show_Fail.Add(OnClosing);
LuaEvents.IGE_Closing.Add(OnClosing);
-------------------------------------------------------------------------------------------------
local function OnShowing()
opened = true
Update();
end
LuaEvents.IGE_Showing.Add(OnShowing);
-------------------------------------------------------------------------------------------------
local function OnSharingGlobalAndOptions(_IGE)
IGE = _IGE;
end
LuaEvents.IGE_SharingGlobalAndOptions.Add(OnSharingGlobalAndOptions);
-------------------------------------------------------------------------------------------------
local function ShouldBeRevealed(plot, recursivity)
local playerID = IGE.currentPlayerID;
if plot:GetOwner() == playerID then return true end
local numUnits = plot:GetNumUnits();
for i = 0, numUnits do
local unit = plot:GetUnit(i);
if unit and unit:GetOwner() == playerID then
return true
end
end
if recursivity > 0 then
for neighbor in Neighbors(plot) do
if ShouldBeRevealed(neighbor, recursivity - 1) then return true end
end
end
return false;
end
-------------------------------------------------------------------------------------------------
local function OnForceRevealMap(revealing, disableFoW)
local currentTeamID = IGE.currentTeamID
for i = 0, Map.GetNumPlots()-1, 1 do
local plot = Map.GetPlotByIndex(i);
local oldVisibility = plot:GetVisibilityCount(currentTeamID)
local visible = ShouldBeRevealed(plot, 1)
if oldVisibility > 0 then
plot:ChangeVisibilityCount(currentTeamID, -oldVisibility, -1, true, true);
end
if visible or disableFoW then
plot:ChangeVisibilityCount(currentTeamID, 1, -1, true, true);
end
plot:SetRevealed(currentTeamID, visible or revealing);
plot:UpdateFog();
end
Game.UpdateFOW(true);
UI.RequestMinimapBroadcast();
end
LuaEvents.IGE_ForceRevealMap.Add(OnForceRevealMap);