Skip to content

Commit

Permalink
Update ModLens_Scout.lua
Browse files Browse the repository at this point in the history
Flattened if-checks
  • Loading branch information
astog committed Mar 18, 2023
1 parent 5797c69 commit c49081f
Showing 1 changed file with 87 additions and 67 deletions.
154 changes: 87 additions & 67 deletions Lenses/Scout/ModLens_Scout.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,92 +62,112 @@ local function RefreshScoutLens()
end

local function OnUnitSelectionChanged( playerID:number, unitID:number, hexI:number, hexJ:number, hexK:number, bSelected:boolean, bEditable:boolean )
if playerID == Game.GetLocalPlayer() and (AUTO_APPLY_SCOUT_LENS or AUTO_APPLY_SCOUT_LENS_EXTRA) then
local pPlayer = Players[playerID]
if pPlayer == nil then
return
end
if not (AUTO_APPLY_SCOUT_LENS or AUTO_APPLY_SCOUT_LENS_EXTRA) then
return
end
if playerID ~= Game.GetLocalPlayer() then
return
end

local pUnit = pPlayer:GetUnits():FindID(unitID)
if pUnit == nil then
return
end
local pPlayer = Players[playerID]
if pPlayer == nil then
return
end

local unitType = pUnit:GetUnitType()
if unitType == -1 or GameInfo.Units[unitType] == nil then
return
end
local pUnit = pPlayer:GetUnits():FindID(unitID)
if pUnit == nil then
return
end

local promotionClass = GameInfo.Units[unitType].PromotionClass
local unitDomain = GameInfo.Units[unitType].Domain
local militaryUnit = (pUnit:GetCombat() > 0 or pUnit:GetRangedCombat() > 0) and (unitDomain == "DOMAIN_LAND")
if bSelected then
if militaryUnit and AUTO_APPLY_SCOUT_LENS_EXTRA then
ShowScoutLens()
elseif promotionClass == "PROMOTION_CLASS_RECON" then
ShowScoutLens()
end
-- Deselection
else
if militaryUnit and AUTO_APPLY_SCOUT_LENS_EXTRA then
ClearScoutLens()
elseif promotionClass == "PROMOTION_CLASS_RECON" then
ClearScoutLens()
end
local unitType = pUnit:GetUnitType()
if unitType == -1 or GameInfo.Units[unitType] == nil then
return
end

local promotionClass = GameInfo.Units[unitType].PromotionClass
local unitDomain = GameInfo.Units[unitType].Domain
local militaryUnit = (pUnit:GetCombat() > 0 or pUnit:GetRangedCombat() > 0) and (unitDomain == "DOMAIN_LAND")
if bSelected then
if militaryUnit and AUTO_APPLY_SCOUT_LENS_EXTRA then
ShowScoutLens()
elseif promotionClass == "PROMOTION_CLASS_RECON" then
ShowScoutLens()
end
-- Deselection
else
if militaryUnit and AUTO_APPLY_SCOUT_LENS_EXTRA then
ClearScoutLens()
elseif promotionClass == "PROMOTION_CLASS_RECON" then
ClearScoutLens()
end
end
end

local function OnUnitRemovedFromMap( playerID: number, unitID : number )
if playerID == Game.GetLocalPlayer() and (AUTO_APPLY_SCOUT_LENS or AUTO_APPLY_SCOUT_LENS_EXTRA) then
local lens = {}
LuaEvents.MinimapPanel_GetActiveModLens(lens)
if lens[1] == LENS_NAME then
ClearScoutLens()
end
if not (AUTO_APPLY_SCOUT_LENS or AUTO_APPLY_SCOUT_LENS_EXTRA) then
return
end
if playerID ~= Game.GetLocalPlayer() then
return
end

local lens = {}
LuaEvents.MinimapPanel_GetActiveModLens(lens)
if lens[1] == LENS_NAME then
ClearScoutLens()
end
end

local function OnUnitMoveComplete( playerID:number, unitID:number )
if playerID == Game.GetLocalPlayer() and (AUTO_APPLY_SCOUT_LENS or AUTO_APPLY_SCOUT_LENS_EXTRA) then
local pPlayer = Players[playerID]
if pPlayer == nil then
return
end
if not (AUTO_APPLY_SCOUT_LENS or AUTO_APPLY_SCOUT_LENS_EXTRA) then
return
end
if playerID ~= Game.GetLocalPlayer() then
return
end

local pUnit = pPlayer:GetUnits():FindID(unitID)
if pUnit == nil then
return
end
local pPlayer = Players[playerID]
if pPlayer == nil then
return
end

-- Ensure the unit is selected. Scout could be exploring automated
if not UI.IsUnitSelected(pUnit) then
return
end
local pUnit = pPlayer:GetUnits():FindID(unitID)
if pUnit == nil then
return
end

local unitType = pUnit:GetUnitType()
if unitType == -1 or GameInfo.Units[unitType] == nil then
return
end

local promotionClass = GameInfo.Units[unitType].PromotionClass
local unitDomain = GameInfo.Units[unitType].Domain
local militaryUnit = (pUnit:GetCombat() > 0 or pUnit:GetRangedCombat() > 0) and (unitDomain == "DOMAIN_LAND")
if militaryUnit and AUTO_APPLY_SCOUT_LENS_EXTRA then
RefreshScoutLens()
elseif promotionClass == "PROMOTION_CLASS_RECON" then
RefreshScoutLens()
end
-- Ensure the unit is selected. Scout could be exploring automated
if not UI.IsUnitSelected(pUnit) then
return
end

local unitType = pUnit:GetUnitType()
if unitType == -1 or GameInfo.Units[unitType] == nil then
return
end

local promotionClass = GameInfo.Units[unitType].PromotionClass
local unitDomain = GameInfo.Units[unitType].Domain
local militaryUnit = (pUnit:GetCombat() > 0 or pUnit:GetRangedCombat() > 0) and (unitDomain == "DOMAIN_LAND")
if militaryUnit and AUTO_APPLY_SCOUT_LENS_EXTRA then
RefreshScoutLens()
elseif promotionClass == "PROMOTION_CLASS_RECON" then
RefreshScoutLens()
end
end

local function OnGoodyHutReward( playerID:number )
if playerID == Game.GetLocalPlayer() and (AUTO_APPLY_SCOUT_LENS or AUTO_APPLY_SCOUT_LENS_EXTRA) then
local lens = {}
LuaEvents.MinimapPanel_GetActiveModLens(lens)
if lens[1] == LENS_NAME then
RefreshScoutLens()
end
if not (AUTO_APPLY_SCOUT_LENS or AUTO_APPLY_SCOUT_LENS_EXTRA) then
return
end
if playerID ~= Game.GetLocalPlayer() then
return
end

local lens = {}
LuaEvents.MinimapPanel_GetActiveModLens(lens)
if lens[1] == LENS_NAME then
RefreshScoutLens()
end
end

Expand Down

0 comments on commit c49081f

Please sign in to comment.