[LUA] Connect Unit with TradeRoute Data

LastSword

Prince
Joined
Feb 24, 2013
Messages
1,129
Shortly: I have a Trade Unit (caravan) and I would like to know CityTo from TradeRoute data (Trade Route destination).



//I am 100% sure that my Trade Unit is currently making a Trade Route.
//The best I have thought is detect the UnitID, look how many units with lower ID is creating TradeRoute and then pick equivalent Trade Route. Quite silly, but would work if Trade Routes are sorted that way.
 
but would work if Trade Routes are sorted that way.

Pretty sure they aren't as unit IDs get reused as units die.

Annoyingly the unit id is part of the C++ data structure about trade routes, it's just that Firaxis didn't bother to copy it into the Lua table in the API code.

That data (and a few other useful API methods, like pUnit:GetTradeRouteIndex() and Game.GetTradeRoute(iRouteIndex)) are already in my DLL
 
Thanks for clarification. Unfortunately, I want this for civ mod, which I would prefer not be DLL dependent.

By UnitID, I meant Units() iterator, but for anyone curious It didn't seem too promising after first test.
 
By UnitID, I meant Units() iterator, but for anyone curious It didn't seem too promising after first test.

That's even less likely to be a predictable order as you're totally dependant on how the C++ standard library handles insertions/deletions into the collection
 
Back
Top Bottom