About exclusives units for civs, but NON replacing disponible units.

Discussion in 'Civ4 - Creation & Customization' started by Alarconte, Sep 29, 2009.

  1. Alarconte

    Alarconte Chieftain

    Joined:
    Aug 29, 2009
    Messages:
    47
    Location:
    Barcelona, Catalonia, Spain
    In the "add units" tutorial, I din't see so much clear one aspect.


    1)I know (i think xD) how to make new units for all civs
    2)I know how to make the new UU for news civs (easy)
    3)I know that a civ can have multiple UUs (I think is simply, but i not tested yet)

    But. What goes when you want to make a new unit, but only for a civ?

    Example.

    One Civ, (Nationalist Spain, in this case) has standard infantery.
    And too, I want that Nationalist Spain have one new unit, a Ligth version of Infantery (Phalanx recruits).

    But I DON'T want to replace standard Infantery with UU: Phalanx Recruits.

    (If I put one UU for this civ, this will not be the Phalanx recruits, cause they are a lesser powerfull version of Infantery, and i want too the normal infantery.

    How I can do it?

    Making a new unit for ALL civs, and making Phalanx Recruits UU for Nationalist Spain, and new different UU for the rest of civs?

    Or I can make a new unit (non UU) only avaible only for one or few civs?

    Thanks ^^
     
  2. NotSoGood

    NotSoGood Emperor

    Joined:
    Jan 25, 2009
    Messages:
    1,077
    Location:
    Finland
    You could make a whole new. And add a tag that disables to train that unit to all other civs than your Nationalist Spain. Its like this:
    Code:
    				<Unit>
    					<UnitClassType>UNITCLASS_SETTLER</UnitClassType>
    					<UnitType>NONE</UnitType>
    				</Unit>
    Take a look barbarian civ in CivilizationInfos.xml if you don't get what I mean. Its almost like the way to define unique units. Just replace UnitType with NONE. It'll need lots of work 'cos you have to define that for every other civ.

    Another way is to use python with this. Like in the begining make a whole new unit. In CvGameUtils, there is function canTrain. The original one:
    Code:
    	def canTrain(self,argsList):
    		pCity = argsList[0]
    		eUnit = argsList[1]
    		bContinue = argsList[2]
    		bTestVisible = argsList[3]
    		bIgnoreCost = argsList[4]
    		bIgnoreUpgrades = argsList[5]
    		return False
    And changed:
    Code:
    	def canTrain(self,argsList):
    		pCity = argsList[0]
    		eUnit = argsList[1]
    		bContinue = argsList[2]
    		bTestVisible = argsList[3]
    		bIgnoreCost = argsList[4]
    		bIgnoreUpgrades = argsList[5]
    		
    #training limit start
    		owner = pCity.getOwner
    		if (owner.getCivilizationType == gc.getInfoTypeForString('CIVILIZATION_NATIONALIST_SPAIN')):
    			return True
    #training limit end		
    		return False
    I don't recomend using the code I showed because most likely it wouldn't work. I'm not so good at python. :D
     
  3. zyphyr

    zyphyr Prince

    Joined:
    Oct 30, 2005
    Messages:
    461
    The easiest way..

    In CIV4UnitClassInfos.xml, set the class for the new unit type like this :
    Code:
    		<UnitClassInfo>
    			<Type>UNITCLASS_PHALANX_RECRUIT</Type>
    			<Description>TXT_KEY_UNIT_PHALANX_RECRUIT</Description>
    			<iMaxGlobalInstances>-1</iMaxGlobalInstances>
    			<iMaxTeamInstances>-1</iMaxTeamInstances>
    			<iMaxPlayerInstances>-1</iMaxPlayerInstances>
    			<iInstanceCostModifier>0</iInstanceCostModifier>
    			<DefaultUnit>NONE</DefaultUnit>
    		</UnitClassInfo>
    
    By setting the DefaultUnit to NONE, nobody gets anything in that class unless it is overridden in the Civ as a UU, which you do just by adding another Unit entry to the civ (inside the Units tags). In this case :
    Code:
    			<Units>
    				<Unit>
    					<UnitClassType>UNITCLASS_CUIRASSIER</UnitClassType>
    					<UnitType>UNIT_SPANISH_CONQUISTADOR</UnitType>
    				</Unit>
    				<Unit>
    					<UnitClassType>UNITCLASS_PHALANX_RECRUIT</UnitClassType>
    					<UnitType>UNIT_PHALANX_RECRUIT</UnitType>
    				</Unit>
    
    			</Units>
    
    The overall effect is the same as NotSoGood's first suggestion, but is much easier/faster to implement and far easier to maintain/extend.

    End result : Spain gets the new unit, everyone else gets nothing.

    Additionally, if you happen to have several civs that you want to provide an extra unit like this you have 2 options :
    1)A new unit class for each as above
    2)One generic unit class to cover them all (UNITCLASS_FREEBIE_UNIT perhaps), then just override for the specific civs as needed.
     
  4. NotSoGood

    NotSoGood Emperor

    Joined:
    Jan 25, 2009
    Messages:
    1,077
    Location:
    Finland
    Wow! :eek: Never knew that. Its a lot easier that way.
    Well, you learn something new every day. :cooool:
     
  5. The_J

    The_J Say No 2 Net Validations Super Moderator Supporter

    Joined:
    Oct 22, 2008
    Messages:
    35,045
    Location:
    DE/NL/FR
    I want to comment some things here:
    It has to be pCity.getOwner(), with the brackets.
    Then you only have the number of the player, so you have to get a player instance, like CurrentPlayer = gc.getPlayer(owner).
    Then you need CurrentPlayer.getCivilizationType () (also with the brackets).
    And you forgot to check the unit ;).
     
  6. Alarconte

    Alarconte Chieftain

    Joined:
    Aug 29, 2009
    Messages:
    47
    Location:
    Barcelona, Catalonia, Spain
    A lot of thanks!

    The zyphir idea is definitely a great way to make unique units for one or more civs.

    The same way, the NotSoGood idea is great too, because my mod only has 6 civs and some units maybe considerable for having some civs and others don't

    Thankyou, boys!
     
  7. NotSoGood

    NotSoGood Emperor

    Joined:
    Jan 25, 2009
    Messages:
    1,077
    Location:
    Finland
    :lol: I'm still trying somehow to learn how to use python. Just wanted to tell that it can be done in python.
    Great that you fixed my post. :)
     

Share This Page