Skip to content

Commit

Permalink
Minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
astog committed Jul 31, 2017
1 parent a43f497 commit e78d21d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
17 changes: 11 additions & 6 deletions UI/TradeOverview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2061,24 +2061,29 @@ function OnUnitOperationStarted( ownerID:number, unitID:number, operationID:numb
if m_HasBuiltTradeRouteTable then
-- Remove unit from available traders
RemoveTrader(unitID)
local foundRoute:boolean = false

if ownerID == Game.GetLocalPlayer() and operationID == UnitOperationTypes.MAKE_TRADE_ROUTE then
if operationID == UnitOperationTypes.MAKE_TRADE_ROUTE then
-- Unit was just started a trade route. Find the route, and update the tables
local localPlayerCities:table = Players[ownerID]:GetCities();
for _, city in localPlayerCities:Members() do
local outgoingRoutes = city:GetTrade():GetOutgoingRoutes();
for _, route in ipairs(outgoingRoutes) do
if route.TraderUnitID == unitID then
print("Found route...")
-- Remove it from the available routes
if m_groupByList[m_groupBySelected].groupByID ~= GROUP_BY_SETTINGS.NONE then
RemoveRouteFromTable(route, m_AvailableGroupedRoutes, true);
else
RemoveRouteFromTable(route, m_AvailableTradeRoutes, false);
end
RemoveRouteFromTable(route, m_AvailableGroupedRoutes, not GroupSettingIsNone(m_groupBySelected));
foundRoute = true
break
end
end
end

if not foundRoute then
print("Route not found!!")
return
end

-- Dont refresh, if the window is hidden
if not ContextPtr:IsHidden() then
Refresh();
Expand Down
22 changes: 12 additions & 10 deletions UI/TradeSupport.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1215,9 +1215,10 @@ function FormatYieldText(yieldIndex, yieldAmount)
end

-- Finds and removes routeToDelete from routeTable
function RemoveRouteFromTable( routeToDelete:table , routeTable:table, groupedRoutes:boolean )
function RemoveRouteFromTable( routeToDelete:table , routeTable:table, isGrouped:boolean )
-- If grouping by something, go one level deeper
if groupedRoutes then
if isGrouped then
print("Routes grouped")
local targetIndex:number = -1;
local targetGroupIndex:number = -1;

Expand All @@ -1233,25 +1234,26 @@ function RemoveRouteFromTable( routeToDelete:table , routeTable:table, groupedRo

-- Remove route
if targetIndex ~= -1 and targetGroupIndex ~= -1 then
print("REMOVING ROUTE")
table.remove(routeTable[targetGroupIndex], targetIndex);

-- If that group is empty, remove that group
if table.count(routeTable[targetGroupIndex]) <= 0 then
table.remove(routeTable, targetGroupIndex);
end
else
print("COULD NOT FIND ROUTE")
end
else
local targetIndex:number = -1;
print("Routes not grouped")

for i, route in ipairs(routeTable) do
if CheckRouteEquality( route, routeToDelete ) then
targetIndex = i;
end
end

-- Remove route
-- Find and remove route
local targetIndex:number = findIndex(routeTable, routeToDelete, CheckRouteEquality)
if targetIndex ~= -1 then
print("REMOVING ROUTE")
table.remove(routeTable, targetIndex);
else
print("COULD NOT FIND ROUTE")
end
end
end
Expand Down

0 comments on commit e78d21d

Please sign in to comment.