Getting the ai to not build a unit

peter450

Prince
Joined
Sep 24, 2006
Messages
392
Does anyone know what, i need to put in the unitinfos.xml to have the ai not build a unit type, i'm sure this is the file i need to edit as it has all the unit attributes and unit AI types but i don't know what to put in place of the default unit AI

On a side note, does anyone know if the pirate AI also works for a land unit, with the hidden nationality, always hostile atrributes?
 
On a side note, does anyone know if the pirate AI also works for a land unit, with the hidden nationality, always hostile atrributes?

Definitely. It works real good.

The method to use to make the AI not build a unit depends on what kind of unit and why you want to discourage it. If you want to play as a human with a unit that the AI cannot use, why not just make a Human civilization in CivilizationInfos and give it this as a UU? If you simply want to discourage the building of a unit, you could make another unit similiar to it that is better. For example, if you have Swordsman and Legion, and you don't want the AI to build Swordsman, give Legion an icombat of 8 and Swordsman an icombat of 6, but make them otherwise identical.
 
But then nobody would build swordsmen at all (8:strength: vs 6:strength: at an identical cost), you want to set the iPower or iAsset (preferabley the latter) higher, because then the AI will think its better, but they'll be the same/
 
Give it no UnitAIs, and fill up the NotUnitAI field with all UnitAI types for that domain, AI will never see it as a valid unit to build, as it is invalid for all roles it is looking to fill if that's the case.
iPower and iAsset will have an effect, but the AI will ignore it if it wants to fill a role and sees the unit is available and has the best stats for the job.
 
Thanks for all the replies, basically i made a assasin unit, that becomes available with guilds (at least thats my current thinking)

The unit is going to be a national unit limited to 3, with a very good withdrawl change and attack bonus into difficult terain

It's also going to be hidden nationality and always hostile

I was told in the better AI forum that pirate AI does not work for land units, i don't want the AI to build this unit, as defensively it's not all that great, same str as a maceman and does not get terrain def bonus's, it relies on speed and making hit and run strikes using it high withdrawl and terrain attack bonus to ambush units before pulling back

The AI is just going to build it like a normal unit, as it's a hostile unit (anyone can attack it with declaring war, like a privateer)it will likely get killed the second they leave there teritory with it, so i don't want the AI wasting money on a quite expensive unit, that it won't use effectively, thats why i was wondering if there is somthing you can put in the unit AI field that basically says don't build this
 
Give it a very low iAsset and iPower, then the AI will think it's worthless.
 
civilizationsinfos file. At the bottom of it is a list of all the units barbs and minor civs can't build/spawn as. Just add the unit there, and barbs/minors can't build or spawn as them.
 
Cool! I'll add it to my TO DO list for MOO2Civ's next patch. (Don't want Space Pirates to spawn Planetary Defense ships.):)
 
If you want to guarantee that an AI won't build a unit you can disallow it in python. In CvGameUtils.py in the cannotTrain method just add something like this:
Code:
		iKlingonUU = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_KLINGON_CHANG')
		iKlingonUUClass = gc.getUnitInfo(iKlingonUU).getUnitClassType()

                if (eUnit == iKlingonUU):
                    if (not gc.getPlayer(ePlayer).isHuman()):
                        return True
 
I think I now understand your method. My way, when used in CivilizationInfos.xml disallows any chosen Civ to not build a unit, human or not. Your way appears to only allow the human to build a unit, which was the whole point of this thread. :crazyeye:

Thanks for the clarification. ;)
 
If you want to guarantee that an AI won't build a unit you can disallow it in python. In CvGameUtils.py in the cannotTrain method just add something like this:
Code:
        iKlingonUU = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_KLINGON_CHANG')
        iKlingonUUClass = gc.getUnitInfo(iKlingonUU).getUnitClassType()

                if (eUnit == iKlingonUU):
                    if (not gc.getPlayer(ePlayer).isHuman()):
                        return True

Ah, thanks! ;) (I checked the barb list phungus mentioned, but it seems to list units the barbs actually do build.)
 
(I checked the barb list phungus mentioned, but it seems to list units the barbs actually do build.)

Actually, it uses the UU system to place NONE as a unit for that particular UnitClass. That's why you will never see barb missionaries, even if they captured a city with a religion. Below that is also the buildings they cannot build (all the wonders).
 
If you want to guarantee that an AI won't build a unit you can disallow it in python. In CvGameUtils.py in the cannotTrain method just add something like this:
Code:
        iKlingonUU = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_KLINGON_CHANG')
        iKlingonUUClass = gc.getUnitInfo(iKlingonUU).getUnitClassType()

                if (eUnit == iKlingonUU):
                    if (not gc.getPlayer(ePlayer).isHuman()):
                        return True

Hm. I changed the CvGameUtils.py like this:


def cannotTrain(self,argsList):
pCity = argsList[0]
eUnit = argsList[1]
bContinue = argsList[2]
bTestVisible = argsList[3]

# Block out the rest
return False

iStarbaseI = CvUtil.findInfoTypeNum(gc.getUnitInfo, gc.getNumUnitInfos(), "UNIT_STARBASE_I")
iStarbaseII = CvUtil.findInfoTypeNum(gc.getUnitInfo, gc.getNumUnitInfos(), "UNIT_STARBASE_II")
iStarbaseIII = CvUtil.findInfoTypeNum(gc.getUnitInfo, gc.getNumUnitInfos(), "UNIT_STARBASE_III")

if (eUnit == iStarbaseI or eUnit == iStarbaseII or eUnit == iStarbaseIII):
return True

iRobo-Warriors = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_ROBO_WARRIORS')
iRobo-Armor = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_ARMOR')
iRobo-Battleloid = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_BATTLELOID')

if (eUnit == iRobo-Warriors or eUnit == iArmor or eUnit == iBattleloid):
return True

return False


copying the Starbase example, but after reloading I have no interface. What's wrong?:confused:
 
Put that in code tags. It's python so whitespace matters.
 
Top Bottom