Balanced Ancient Era Start

Yeah, I know it is done onCityBuilt.
The question is how you determine which is the unit building the city if you are not using CyInterface().getHeadSelectedUnit()

How do you tell whether it is a colonist or pioneer or simply a settler building the city?
 
See if it does.
If it does, it is bound to fail
 
I have not seen it fail in thousands of city builds in RoM RoM:AND and C2C. Yes it uses CyInterface().getHeadSelectedUnit(). Naturally we always check that this returns a valid unit before proceeding, just in case the onCityBuilt call was a fake.

Code:
		pUnit = CyInterface().getHeadSelectedUnit()
		if pUnit:
 
Then I give you a simple scenario why it will fail miserably.

Give the settler/pioneer/colonist queued orders.
Simply use "Shift", order it to move somewhere and build city.
Or even simpler, move the unit to a plot, make sure its unit movement is totally used up, then click build city.

Obviously, in either case, the unit will not build the city in that turn when it is the Selected Unit.
But after you click end turn, the unit will proceed to automatically build the city.

When that happens, CyInterface().getHeadSelectedUnit() is either invalid or refers to another totally different unit.

Now you see why the code is doomed to fail?

2ndly, what happens when A.I. colonist build the city?
CyInterface().getHeadSelectedUnit() is obviously not refering to the colonist since A.I. does not have a interface obviously.
 
Then I give you a simple scenario why it will fail miserably.

Give the settler/pioneer/colonist queued orders.
Simply use "Shift", order it to move somewhere and build city.
Or even simpler, move the unit to a plot, make sure its unit movement is totally used up, then click build city.

Obviously, in either case, the unit will not build the city in that turn when it is the Selected Unit.
But after you click end turn, the unit will proceed to automatically build the city.

When that happens, CyInterface().getHeadSelectedUnit() is either invalid or refers to another totally different unit.

Now you see why the code is doomed to fail?

2ndly, what happens when A.I. colonist build the city?
CyInterface().getHeadSelectedUnit() is obviously not refering to the colonist since A.I. does not have a interface obviously.

This wouldn't help Platyping (since I assume you want I to work with mods other than C2C), but I could add you a new method on CyCity (getFoundingUnitType()) to return you the UnitType of the founding unit (or -1 if created in some other way than unit founding)...
 
Yeah, I know the only real solution is SDK to add a new means to determine the founding unit, although for my settler promotions I used another method which at least gets rid of both problems but is still not 100% fool proof.

I am just curious why is a faulty code present in so many mods and nobody ever challenged and ask why
 
Rule number 1: always test what is given to you no matter who wrote the codes.

Anyway I proposed a simple solution to xyth before.
Just scrape both advanced settler units.
Just check if the team has the pioneer or colonist tech and you are done.
Of course, if you want the settler to move faster or what just give them a promotion to do so if they are built when you have those techs
 
Just thought you might like to know that there are approximately 790 buildings that can be built in a new city. This does not include auto build, diseases, crime, wonders, pollution or religious buildings. Now to figure out when each should be free in new cities and the type so people can choose not to have them.
 
Where do I put the NewCityFree files?
 
Back
Top Bottom