1. We have added the ability to collapse/expand forum categories and widgets on forum home.
    Dismiss Notice
  2. All Civ avatars are brought back and available for selection in the Avatar Gallery! There are 945 avatars total.
    Dismiss Notice
  3. To make the site more secure, we have installed SSL certificates and enabled HTTPS for both the main site and forums.
    Dismiss Notice
  4. Civ6 is released! Order now! (Amazon US | Amazon UK | Amazon CA | Amazon DE | Amazon FR)
    Dismiss Notice
  5. Dismiss Notice
  6. Forum account upgrades are available for ad-free browsing.
    Dismiss Notice

Getting the ai to not build a unit

Discussion in 'Civ4 - Creation & Customization' started by peter450, May 15, 2009.

  1. peter450

    peter450 Chieftain

    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?
     
  2. The_J

    The_J Say No 2 Net Validations Retired Moderator

    Joined:
    Oct 22, 2008
    Messages:
    29,759
    Location:
    Germany / Netherlands
    Do you want, that nobody can build the unit?
    If yes: Set iCost to -1, this disables a unit.
     
  3. Tholish

    Tholish Chieftain

    Joined:
    Jul 5, 2002
    Messages:
    1,344
    Location:
    Japan
    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.
     
  4. mechaerik

    mechaerik Magician

    Joined:
    Oct 28, 2008
    Messages:
    7,064
    Location:
    Los Angeles
    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/
     
  5. phungus420

    phungus420 Chieftain

    Joined:
    Mar 1, 2003
    Messages:
    6,296
    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.
     
  6. peter450

    peter450 Chieftain

    Joined:
    Sep 24, 2006
    Messages:
    392
    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
     
  7. mechaerik

    mechaerik Magician

    Joined:
    Oct 28, 2008
    Messages:
    7,064
    Location:
    Los Angeles
    Give it a very low iAsset and iPower, then the AI will think it's worthless.
     
  8. Agent327

    Agent327 Observer

    Joined:
    Oct 28, 2006
    Messages:
    16,046
    Location:
    In orbit
    Good to know.;)

    Any suggestions for a unit not to be built by barbs?
     
  9. phungus420

    phungus420 Chieftain

    Joined:
    Mar 1, 2003
    Messages:
    6,296
    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.
     
  10. Agent327

    Agent327 Observer

    Joined:
    Oct 28, 2006
    Messages:
    16,046
    Location:
    In orbit
    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.):)
     
  11. deanej

    deanej Chieftain

    Joined:
    Apr 8, 2006
    Messages:
    4,859
    Location:
    New York State
    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
     
  12. Flintlock1415

    Flintlock1415 Chieftain

    Joined:
    Feb 24, 2008
    Messages:
    1,057
    Location:
    MN
    Actually the XML tags using <Unit>NONE</Unit> works 100% of the time, without the need for Python. ;)
     
  13. deanej

    deanej Chieftain

    Joined:
    Apr 8, 2006
    Messages:
    4,859
    Location:
    New York State
    I think that disallows everyone from building it (I say "I think" because many files have a <Unit> tag and I'm not sure where you're referring to). My stuff was mentioned for preventing the AI from building it while allowing humans to build it.
     
  14. Flintlock1415

    Flintlock1415 Chieftain

    Joined:
    Feb 24, 2008
    Messages:
    1,057
    Location:
    MN
    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. ;)
     
  15. Agent327

    Agent327 Observer

    Joined:
    Oct 28, 2006
    Messages:
    16,046
    Location:
    In orbit
    Ah, thanks! ;) (I checked the barb list phungus mentioned, but it seems to list units the barbs actually do build.)
     
  16. mechaerik

    mechaerik Magician

    Joined:
    Oct 28, 2008
    Messages:
    7,064
    Location:
    Los Angeles
    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).
     
  17. Agent327

    Agent327 Observer

    Joined:
    Oct 28, 2006
    Messages:
    16,046
    Location:
    In orbit
    OK, thanks.;)
     
  18. Agent327

    Agent327 Observer

    Joined:
    Oct 28, 2006
    Messages:
    16,046
    Location:
    In orbit
    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:
     
  19. phungus420

    phungus420 Chieftain

    Joined:
    Mar 1, 2003
    Messages:
    6,296
    Put that in code tags. It's python so whitespace matters.
     
  20. Agent327

    Agent327 Observer

    Joined:
    Oct 28, 2006
    Messages:
    16,046
    Location:
    In orbit
    Do you mean like this:
    Code:
     ... [\CODE]? (Because that still gives me no interface.:()
     

Share This Page