Building_FreeUnits unit in city.

Loupgarou

Chieftain
Joined
Sep 7, 2022
Messages
7
Hi, something I have been trying to do is make units spawned in this manner, the <Building_FreeUnits> table, spawn in the city that built the building, not adjacent to it. I suspect it to be a LUA issue but have no experience with LUA or I am unsure. Any help would be appreciated.

Something I would also like to change is make the Collective Rule settler and Citizenship worker spawn in the [Capital] city, same with any other policy spawned Unit.
 

whoward69

DLL Minion
Joined
May 30, 2011
Messages
8,631
Location
Near Portsmouth, UK
Not Lua but C++ in the DLL source code. The issue is that after a unit is spawned for one of the reasons you mention, the DLL does a CvUnit::jumpToNearestValidPlot() call for the new unit, and that method assumes that the hex the unit is on is invalid, so always makes the unit move. To fix this you would need to mod that method to first check if the hex the unit is currently on is valid and if so leave the unit where it is.
 

Loupgarou

Chieftain
Joined
Sep 7, 2022
Messages
7
That is rather convenient as I am already experimenting with the DLL. Thank you for the clarification!
 

Loupgarou

Chieftain
Joined
Sep 7, 2022
Messages
7
Ok, so copying this line:
if ((getDomainType() != DOMAIN_AIR) || pLoopPlot->isFriendlyCity(*this, true))
{
and turning it into this:
if ((getDomainType() != DOMAIN_LAND) || pLoopPlot->isFriendlyCity(*this, true))
{
allowed the unit to spawn in the city, but now it spawns in the capital even if the building was constructed or given in an expansion. I am not sure how to make this go to a local city rather than check all cities globally. and if the capital is full then it goes to the nearest available city rather than though the city founded order. it also seems to give the Collective Rule settler in a random [maybe in the top left] along with the Citizenship worker. hmm.
 

Loupgarou

Chieftain
Joined
Sep 7, 2022
Messages
7
and some of the units, in this case Great Generals, seem to disappear entirely.

the exact situation is that honor, on adoption, gives the capital a General, in the same way as collective rule gives liberty a settle. then subsequent cities are given a free building that gives them a General as well. the first non capital city's general seems to just, vanish. idk
 

whoward69

DLL Minion
Joined
May 30, 2011
Messages
8,631
Location
Near Portsmouth, UK
Going to need more to go on than one out-of-context line of code copied from some unknown source file into another random location.
 

Loupgarou

Chieftain
Joined
Sep 7, 2022
Messages
7
While a small part of me was hoping that one line would do everything I wanted I was fairly sure it wouldn't. I'm mostly concerned with the vanishing units. Once I figure out how to do this properly it probably wont be an issue. Thanks for pointing me to the dll, otherwise I'd have wasted some.much time going though the lua.
 
Top Bottom