Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added movement costs lens #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions Lenses/MovementCosts/ModLens_MovementCosts.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
local LENS_NAME = "ML_MovementCosts"
local ML_LENS_LAYER = UILens.CreateLensLayerHash("Hex_Coloring_Appeal_Level")

-- ===========================================================================
-- Movement Costs Lens Support
-- ===========================================================================

local function IsPortal(plot)
local improvementType = plot:GetImprovementType()
if improvementType == nil then
return false
end

local improvement = GameInfo.Improvements[improvementType]
if improvement == nil then
return false
end

local type = improvement.ImprovementType
if type == nil then
return false
end

--IMPROVEMENT_MOUNTAIN_ROAD is Qhapaq Ñan improvement
return type == "IMPROVEMENT_MOUNTAIN_ROAD" or type == "IMPROVEMENT_MOUNTAIN_TUNNEL"
end

local function GetMovementCosts(plot)
if plot:IsImpassable() then
return -1
end

if plot:IsCity() and plot:GetOwner() ~= Game.GetLocalPlayer() then
return -1
end

if plot:IsRoute() then
local routeInfo = GameInfo.Routes[plot:GetRouteType()];
if (routeInfo ~= nil and routeInfo.MovementCost ~= nil) then
return routeInfo.MovementCost
end
end

return plot:GetMovementCost()
end

-- ===========================================================================
-- Exported functions
-- ===========================================================================

local function OnGetColorPlotTable()
local mapWidth, mapHeight = Map.GetGridSize()
local localPlayer: number = Game.GetLocalPlayer()
local localPlayerVis:table = PlayersVisibility[localPlayer]

local colorLookup = {
[0.25] = "COLOR_RAILROAD",
[0.5] = "COLOR_MODERN_ROAD",
[0.75] = "COLOR_INDUSTRIAL_ROAD",
[1] = "COLOR_MOVEMENT_COSTS_ONE",
[2] = "COLOR_MOVEMENT_COSTS_TWO",
[3] = "COLOR_MOVEMENT_COSTS_THREE",
[-1] = "COLOR_IMPASSABLE",
}

local colorPlot = {}
local colorString: string

for i = 0, (mapWidth * mapHeight) - 1, 1 do
local pPlot: table = Map.GetPlotByIndex(i)
if localPlayerVis:IsRevealed(pPlot:GetX(), pPlot:GetY()) and not pPlot:IsWater() then
colorString = nil
if IsPortal(pPlot) then
colorString = "COLOR_PORTAL"
else
local movementCosts = GetMovementCosts(pPlot)
if colorLookup[movementCosts] ~= nil then
colorString = colorLookup[movementCosts]
end
end

local colorValue = UI.GetColorValue(colorString)
if colorString ~= nil and colorValue then
if colorPlot[colorValue] == nil then
colorPlot[colorValue] = {}
end

table.insert(colorPlot[colorValue], i)
end
end
end

return colorPlot
end

local MovementCostsLensEntry = {
LensButtonText = "LOC_HUD_MOVEMENTCOSTS_LENS",
LensButtonTooltip = "LOC_HUD_MOVEMENTCOSTS_LENS_TOOLTIP",
Initialize = nil,
GetColorPlotTable = OnGetColorPlotTable
}

-- minimappanel.lua
if g_ModLenses ~= nil then
g_ModLenses[LENS_NAME] = MovementCostsLensEntry
end

-- modallenspanel.lua
if g_ModLensModalPanel ~= nil then
g_ModLensModalPanel[LENS_NAME] = {}
g_ModLensModalPanel[LENS_NAME].LensTextKey = "LOC_HUD_MOVEMENTCOSTS_LENS"
g_ModLensModalPanel[LENS_NAME].Legend = {
{"LOC_TOOLTIP_MOVEMENTCOSTS_LENS_RAILROAD", UI.GetColorValue("COLOR_RAILROAD")},
{"LOC_TOOLTIP_MOVEMENTCOSTS_LENS_MODERN_ROAD", UI.GetColorValue("COLOR_MODERN_ROAD")},
{"LOC_TOOLTIP_MOVEMENTCOSTS_LENS_INDUSTRIAL_ROAD", UI.GetColorValue("COLOR_INDUSTRIAL_ROAD")},
{"LOC_TOOLTIP_MOVEMENTCOSTS_LENS_COSTS_ONE", UI.GetColorValue("COLOR_MOVEMENT_COSTS_ONE")},
{"LOC_TOOLTIP_MOVEMENTCOSTS_LENS_COSTS_TWO", UI.GetColorValue("COLOR_MOVEMENT_COSTS_TWO")},
{"LOC_TOOLTIP_MOVEMENTCOSTS_LENS_COSTS_THREE", UI.GetColorValue("COLOR_MOVEMENT_COSTS_THREE")},
{"LOC_TOOLTIP_MOVEMENTCOSTS_LENS_PORTAL", UI.GetColorValue("COLOR_PORTAL")},
{"LOC_TOOLTIP_MOVEMENTCOSTS_LENS_IMPASSABLE", UI.GetColorValue("COLOR_IMPASSABLE")}
}
end
2 changes: 2 additions & 0 deletions MoreLenses.modinfo
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<File>Lenses/Barbarian/ModLens_Barbarian.lua</File>
<File>Lenses/Naturalist/ModLens_Naturalist.lua</File>
<File>Lenses/Wonder/ModLens_Wonder.lua</File>
<File>Lenses/MovementCosts/ModLens_MovementCosts.lua</File>
</Items>
</ImportFiles>

Expand Down Expand Up @@ -194,6 +195,7 @@
<File>Lenses/CityOverlap/ModLens_CityOverlap.lua</File>
<File>Lenses/Resource/ModLens_Resource.xml</File>
<File>Lenses/Resource/ModLens_Resource.lua</File>
<File>Lenses/MovementCosts/ModLens_MovementCosts.lua</File>

<!-- Settings -->
<File>Settings/ml_settingspanel.xml</File>
Expand Down
18 changes: 18 additions & 0 deletions MoreLenses_Colors.sql
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@ VALUES ( 'COLOR_ALT_SETTLER_HILL', '0', '1',
INSERT INTO Colors ( Type, Red, Green, Blue, Alpha)
VALUES ( 'COLOR_ALT_SETTLER_REGULAR', '0.75', '0.75', '0.75', '0.5');

-- Movement Costs Colors
INSERT INTO Colors ( Type, Red, Green, Blue, Alpha)
VALUES ( 'COLOR_RAILROAD', '0', '1', '0', '0.5');
INSERT INTO Colors ( Type, Red, Green, Blue, Alpha)
VALUES ( 'COLOR_MODERN_ROAD', '0', '0.8', '0', '0.5');
INSERT INTO Colors ( Type, Red, Green, Blue, Alpha)
VALUES ( 'COLOR_INDUSTRIAL_ROAD', '0', '0.6', '0', '0.5');
INSERT INTO Colors ( Type, Red, Green, Blue, Alpha)
VALUES ( 'COLOR_MOVEMENT_COSTS_ONE', '0.68', '0.68', '0.68', '0.5');
INSERT INTO Colors ( Type, Red, Green, Blue, Alpha)
VALUES ( 'COLOR_MOVEMENT_COSTS_TWO', '1', '0.70', '0.35', '0.5');
INSERT INTO Colors ( Type, Red, Green, Blue, Alpha)
VALUES ( 'COLOR_MOVEMENT_COSTS_THREE', '1', '0.47', '0', '0.5');
INSERT INTO Colors ( Type, Red, Green, Blue, Alpha)
VALUES ( 'COLOR_PORTAL', '0.2', '0.2', '1', '0.5');
INSERT INTO Colors ( Type, Red, Green, Blue, Alpha)
VALUES ( 'COLOR_IMPASSABLE', '1', '0', '0', '0.5');

-- Test Colors
INSERT INTO Colors ( Type, Red, Green, Blue, Alpha)
VALUES ( 'COLOR_MORELENSES_BLACK', '0', '0', '0', '0.5');
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ Highlights goody huts on the map. Automatically applies when a scout / ranger is

![Imgur](http://i.imgur.com/TnnErfb.jpg)
___
___
#### Movement Costs Lens:
Visualizes movement costs.

![Imgur](https://i.imgur.com/bQrw8Vv.jpg)
___

## Installation
If you are using [Chao's QUI](https://github.com/chaorace/cqui) follow these steps:
Expand Down
32 changes: 32 additions & 0 deletions Text/MoreLenses_Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,38 @@
<Text>Needs fixing to be used for a park</Text>
</Row>

<!-- Movement Costs Lens -->
<Row Tag="LOC_HUD_MOVEMENTCOSTS_LENS">
<Text>Movement Costs</Text>
</Row>
<Row Tag="LOC_HUD_MOVEMENTCOSTS_LENS_TOOLTIP">
<Text>Visualizes the movement costs</Text>
</Row>
<Row Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_RAILROAD">
<Text>0.25</Text>
</Row>
<Row Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_MODERN_ROAD">
<Text>0.5</Text>
</Row>
<Row Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_INDUSTRIAL_ROAD">
<Text>0.75</Text>
</Row>
<Row Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_COSTS_ONE">
<Text>1</Text>
</Row>
<Row Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_COSTS_TWO">
<Text>2</Text>
</Row>
<Row Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_COSTS_THREE">
<Text>3</Text>
</Row>
<Row Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_PORTAL">
<Text>Portal</Text>
</Row>
<Row Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_IMPASSABLE">
<Text>Impassable</Text>
</Row>

<!-- Settings Panel -->
<Row Tag="LOC_HUD_ML_SETTINGS_PANEL_TITLE">
<Text>More Lenses - Settings Panel</Text>
Expand Down
32 changes: 32 additions & 0 deletions Text/MoreLenses_Text_de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,37 @@
<Text>Benötigt Verbesserung um zum Nationalpark zu werden</Text>
</Replace>

<!-- Movement Costs Lens -->
<Replace Tag="LOC_HUD_MOVEMENTCOSTS_LENS" Language="de_DE">
<Text>Fortbewegungskosten</Text>
</Replace>
<Replace Tag="LOC_HUD_NATURALIST_LENS_TOOLTIP" Language="de_DE">
<Text>Visualisiert die Fortbewegungskosten</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_RAILROAD" Language="de_DE">
<Text>0.25</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_MODERN_ROAD" Language="de_DE">
<Text>0.5</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_INDUSTRIAL_ROAD" Language="de_DE">
<Text>0.75</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_COSTS_ONE" Language="de_DE">
<Text>1</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_COSTS_TWO" Language="de_DE">
<Text>2</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_COSTS_THREE" Language="de_DE">
<Text>3</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_PORTAL" Language="de_DE">
<Text>Portal</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_IMPASSABLE" Language="de_DE">
<Text>Unpassierbar</Text>
</Replace>

</LocalizedText>
</GameData>
32 changes: 32 additions & 0 deletions Text/MoreLenses_Text_es.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,37 @@
<Text>Aldea Tribal</Text>
</Replace>

<!-- Movement Costs Lens -->
<Replace Tag="LOC_HUD_MOVEMENTCOSTS_LENS" Language="es_ES">
<Text>Gastos de transporte</Text>
</Replace>
<Replace Tag="LOC_HUD_NATURALIST_LENS_TOOLTIP" Language="es_ES">
<Text>Visualiza los costes de movimiento</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_RAILROAD" Language="es_ES">
<Text>0.25</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_MODERN_ROAD" Language="es_ES">
<Text>0.5</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_INDUSTRIAL_ROAD" Language="es_ES">
<Text>0.75</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_COSTS_ONE" Language="es_ES">
<Text>1</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_COSTS_TWO" Language="es_ES">
<Text>2</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_COSTS_THREE" Language="es_ES">
<Text>3</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_PORTAL" Language="es_ES">
<Text>Portal</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_IMPASSABLE" Language="es_ES">
<Text>Intransitable</Text>
</Replace>

</LocalizedText>
</GameData>
32 changes: 32 additions & 0 deletions Text/MoreLenses_Text_fr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,37 @@
<Text>Village Tribal</Text>
</Replace>

<!-- Movement Costs Lens -->
<Replace Tag="LOC_HUD_MOVEMENTCOSTS_LENS" Language="fr_FR">
<Text>coûts des mouvements</Text>
</Replace>
<Replace Tag="LOC_HUD_NATURALIST_LENS_TOOLTIP" Language="fr_FR">
<Text>Visualise les coûts de déplacement</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_RAILROAD" Language="fr_FR">
<Text>0.25</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_MODERN_ROAD" Language="fr_FR">
<Text>0.5</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_INDUSTRIAL_ROAD" Language="fr_FR">
<Text>0.75</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_COSTS_ONE" Language="fr_FR">
<Text>1</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_COSTS_TWO" Language="fr_FR">
<Text>2</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_COSTS_THREE" Language="fr_FR">
<Text>3</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_PORTAL" Language="fr_FR">
<Text>Portail</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_IMPASSABLE" Language="fr_FR">
<Text>Impraticable</Text>
</Replace>

</LocalizedText>
</GameData>
32 changes: 32 additions & 0 deletions Text/MoreLenses_Text_it.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,37 @@
<Text>Necessita una lavorazione per poterci costruire il Parco Nazionale</Text>
</Replace>

<!-- Movement Costs Lens -->
<Replace Tag="LOC_HUD_MOVEMENTCOSTS_LENS" Language="it_IT">
<Text>Costi di movimento</Text>
</Replace>
<Replace Tag="LOC_HUD_NATURALIST_LENS_TOOLTIP" Language="it_IT">
<Text>Visualizza i costi di movimento</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_RAILROAD" Language="it_IT">
<Text>0.25</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_MODERN_ROAD" Language="it_IT">
<Text>0.5</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_INDUSTRIAL_ROAD" Language="it_IT">
<Text>0.75</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_COSTS_ONE" Language="it_IT">
<Text>1</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_COSTS_TWO" Language="it_IT">
<Text>2</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_COSTS_THREE" Language="it_IT">
<Text>3</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_PORTAL" Language="it_IT">
<Text>Portale</Text>
</Replace>
<Replace Tag="LOC_TOOLTIP_MOVEMENTCOSTS_LENS_IMPASSABLE" Language="it_IT">
<Text>Impraticabile</Text>
</Replace>

</LocalizedText>
</GameData>
Loading