How to edit automated workers?

jpsprack

Chieftain
Joined
Sep 3, 2006
Messages
1
First time poster here....

I have modded a few things with civs and leaders but nothing with units...
specifically automated workers.

Normally to begin a game i like doing the worker functions myself but as the game goes on and my empire grows i like to have my automated workers take over.

Is there a way to modify what they emphasis they should place on improvements in certain terrains?
Ex: for plains place cottage or workshop
Something like that... which files do i need to edit?

Any assistance is appreciated.
 
Everything in the game calls the AI code to do what the AI wants to do with every unit. That includes all human units / cities / etc. The difference is that if the unit / city / whatever is human, then it will just end and not do anything.

Whenever a unit is automated, it makes a special exception to this rule, and the unit falls through and does all the ai functions in the SDK, exactly like any AI-controlled unit would do on an AI player.

Most of the values used for determining what gets special attention is controlled by the values within the terrain / improvement XML files (such as the AI weight values). However, changing these will change all this for the AI players as well.

To get the most control, I would suggest you take a look at the CvUnitAI.cpp, specifically the function AI_workerMove and the functions that are called by that. Note that you don't need to change the SDK, you can change the CvGameUtil.py file:

Code:
def AI_unitUpdate(self,argsList):
	pUnit = argsList[0]

	if (pUnit.getGroup().getAutomateType() == AutomateTypes.AUTOMATE_BUILD): #Or whatever automate type it is.
		if gc.getPlayer(pUnit.getOwner()).isHuman():
			# What the group should do here, such as search out for plots and push missions.

Note that you don't necessarily have to edit the SDK, but because determining how a unit should go about doing things is such a complex process, it's probably better off to go and try changing those values around then try to rewrite how the unit works in this mode.

You can realistically use the above code, however, to do a few things. For example, if you have a surefire plan where you always build a mine on a mountain, or something like that, you can change the function above to search for mines within a certain distance of the plot that the unit is currently on. If it finds one, then you a move mission to that plot, then push a build mission so when it reaches the plot it will begin building.

If you do decide to use this approach and have something like above, you will want to make sure that the function returns True so that the function will use your moves rather than continue through all the AI code and make their own move. Returning False means that you've done nothing, and it's safe for the AI to do what it would like with this unit.

Sounds complex? Well, after all, you are basically creating a unit AI. So, it probably will be... :P
 
Back
Top Bottom