How to make unit class unique to a civilization? (not a unique unit)

dirtgon

Chieftain
Joined
Dec 9, 2024
Messages
10
Hello! I've been making a fantasy mod, and the idea is that one of the civilizations can create buildings allowing them to build special undead units. I want each undead unit to have its own unit class so it doesn't have to replace anything and mess with the other units.
However, the way unique units work, it seems like they HAVE to replace something. A whole, unit class can't be unique to a single civilization, only a unique unit. Even though the units I made require a specific unique building in order to be produced, they still appear to other civilizations (which I don't want as it's confusing, you should only be able to see them if you're playing as the civilization that can make them), and even worse, they appear all over the map as barbarian units. While having undead units roaming the world is a nice idea (and if I can figure this out I might even make some barbarian specific units), it doesn't fit the lore for these units and they're a bit too powerful for that, and I'd much rather have them be completely unique to a single civilization.

Does anyone know how to get this to work? I know the animals aren't able to be built and are unique to the barbarians, but that might be different than what I'm trying to do and I still want these units to be buildable, but only by one civilization (without replacing any other unit). The mod Fall From Heaven did this but it's been a very long time since I've played it and I'm not sure how they managed to do it.
 
Give your civ a unique tech (TECH_UNDEAD) that is a prerequisite for all undead unit.
Set the tech to bTrade 0 as that tag allows the player to trade this technology in particular in diplomacy.
iCost -1 so it's not researchable by others.
 
The other way to do it is go into CIV4CivilizationInfos.xml and, for every civ you don't want to have zombies, insert lines
<UnitClassType>UNITCLASS_ZOMBIES<UnitClassType>
<UnitType>NONE<UnitType>
 
Give your civ a unique tech (TECH_UNDEAD) that is a prerequisite for all undead unit.
Set the tech to bTrade 0 as that tag allows the player to trade this technology in particular in diplomacy.
iCost -1 so it's not researchable by others.
I didn't think of doing that! You can make unique techs???
I got it to work the other way but I might try this too, thank you!
 
The other way to do it is go into CIV4CivilizationInfos.xml and, for every civ you don't want to have zombies, insert lines
<UnitClassType>UNITCLASS_ZOMBIES<UnitClassType>
<UnitType>NONE<UnitType>
Thank you! I did this but then for some reason it started crashing every time I ended the turn when one of the units was present. No XML error, just a crash. Do you know why it might be doing this? (I also gave them their own unit type which I could probably get rid of as it's not necessary.)
 
I Assumed you knew you needed to define a unit class (whatever you named it) before you mark it NONE. But if you xml-code something enough to make a crash, it probably won't load the game.
 
Make the unitclass default unit unbuildable by everyone (cost -1, or only built in a city with a Barbarian unique building) and the CIVILIZATION_x gets a unique version of that class.
- the issue with setting dummy techs is ... don't vassals get all your techs and vanilla PROJECT_THE_INTERNET or whatever style things still act on these techs, dirtgon?
- going down a whole list and going NONE NONE NONE is soul-destroying, you are stronger than I, mardonius
- cheating and using python, followed by a serious reassessment of your life choices (works on the unit, not the whole class, but if the set of units in that class = 1 unit only, this works):

Code:
CvGameUtils.py:


def cannotTrain(argsList):
    pCity = argsList[0]
    eUnit = argsList[1]
    bContinue = argsList[2]
    bTestVisible = argsList[3]
    ePlayer = pCity.getOwner()
    pPlayer = gc.getPlayer(ePlayer)

    if eUnit == gc.getInfoTypeForString('UNIT_WOZZIZNAME'):
        if (player.getCivilizationType() == gc.getInfoTypeForString("CIVILIZATION_THINGY")):
            return True

    return False
 
- going down a whole list and going NONE NONE NONE is soul-destroying, you are stronger than I, mardonius
Text editors can reduce that to just a few clicks ;)
 
I would recommend Notepad++, it is a text editor and not an XML editor, but it has convenient search and replace functionality that should help solve this kind of task.
 
My personal favorite is Foxe:
 
Foxe runs on winxp 32bit, which civ4 was made for, though it does not say so on download website.
So does Notepad++.
 
Ah another way to have a civilization-unique unit:

ok Civ4UnitInfos.xml has the tag <PrereqBuilding>NONE</PrereqBuilding>

add to this a unique building for the civ you want sole use of the unit for ... if you need the unit available quickly, set up an early, national-wonder style unique building ... doesn't really matter what it does, so long as the other civs can't build it, and if you want it in place quickly, make it low-cost, low-tech, and cheap; add an AI weight if you think the AI might otherwise not bother creating it,or add flavours ('flavors') that make it attractive. Then setup an (otherwise unbuildable) buildingclass that delivers free buildings (like the Eiffel Tower and free broadcast towers) to all cities, the name tag of which is used as part of the unit requirements: you could even have a civic that ignores this tag (like missionaries).

I use the OG Warlords light-at-the-top obelisks as default buildings for those moments when you really need a Welsh Daffodill Garden or whatever but lack the energy to make one, if you need some quick building art.

I'm hoping mardonius will make one for me.

Code:
        <BuildingArtInfo>
            <Type>ART_DEF_BUILDING_OBELISK_MARKER_BLUE</Type>
            <LSystem>LSYSTEM_1x1</LSystem>
            <bAnimated>0</bAnimated>
            <fScale>0.45</fScale>
            <fInterfaceScale>1.6</fInterfaceScale>
            <NIF>Art/Structures/Buildings/Obelisk Marker/Obelisk_marker_blue.nif</NIF>
            <KFM/>
            <Button>,Art/Interface/Buttons/WorldBuilder/Music.dds,Art/Interface/Buttons/Warlords_Atlas_1.dds,2,13</Button>
        </BuildingArtInfo>
        <BuildingArtInfo>
            <Type>ART_DEF_BUILDING_OBELISK_MARKER_GREEN</Type>
            <LSystem>LSYSTEM_1x1</LSystem>
            <bAnimated>0</bAnimated>
            <fScale>0.45</fScale>
            <fInterfaceScale>1.6</fInterfaceScale>
            <NIF>Art/Structures/Buildings/Obelisk Marker/Obelisk_marker_green.nif</NIF>
            <KFM/>
            <Button>,Art/Interface/Buttons/WorldBuilder/Music.dds,Art/Interface/Buttons/Warlords_Atlas_1.dds,6,13</Button>
        </BuildingArtInfo>
        <BuildingArtInfo>
            <Type>ART_DEF_BUILDING_OBELISK_MARKER_ORANGE</Type>
            <LSystem>LSYSTEM_1x1</LSystem>
            <bAnimated>0</bAnimated>
            <fScale>0.45</fScale>
            <fInterfaceScale>1.6</fInterfaceScale>
            <NIF>Art/Structures/Buildings/Obelisk Marker/Obelisk_marker_orange.nif</NIF>
            <KFM/>
            <Button>Art/Interface/Buttons/Buildings/button_building_obelisk_marker_orange.dds</Button>
        </BuildingArtInfo>
        <BuildingArtInfo>
            <Type>ART_DEF_BUILDING_OBELISK_MARKER_PURPLE</Type>
            <LSystem>LSYSTEM_1x1</LSystem>
            <bAnimated>1</bAnimated>
            <fScale>0.45</fScale>
            <fInterfaceScale>1.6</fInterfaceScale>
            <NIF>Art/Structures/Buildings/Obelisk Marker/Obelisk_marker_purple.nif</NIF>
            <KFM/>
            <Button>,Art/Interface/Buttons/WorldBuilder/Music.dds,Art/Interface/Buttons/Warlords_Atlas_1.dds,3,13</Button>
        </BuildingArtInfo>
        <BuildingArtInfo>
            <Type>ART_DEF_BUILDING_OBELISK_MARKER_RED</Type>
            <LSystem>LSYSTEM_1x1</LSystem>
            <bAnimated>0</bAnimated>
            <fScale>0.45</fScale>
            <fInterfaceScale>1.6</fInterfaceScale>
            <NIF>Art/Structures/Buildings/Obelisk Marker/Obelisk_marker_red.nif</NIF>
            <KFM/>
            <Button>,Art/Interface/Buttons/WorldBuilder/Music.dds,Art/Interface/Buttons/Warlords_Atlas_1.dds,4,13</Button>
        </BuildingArtInfo>
        <BuildingArtInfo>
            <Type>ART_DEF_BUILDING_OBELISK_MARKER_YELLOW</Type>
            <LSystem>LSYSTEM_1x1</LSystem>
            <bAnimated>0</bAnimated>
            <fScale>0.45</fScale>
            <fInterfaceScale>1.6</fInterfaceScale>
            <NIF>Art/Structures/Buildings/Obelisk Marker/Obelisk_marker_yellow.nif</NIF>
            <KFM/>
            <Button>,Art/Interface/Buttons/WorldBuilder/Music.dds,Art/Interface/Buttons/Warlords_Atlas_1.dds,5,13</Button>
        </BuildingArtInfo>

Note the orange one ... needs the attached button.

[cough] that code i stuck up for CannotTrain is missing a 'not' .. I'm afraid. I was distracted by one of my many lovers, or the gleam on one of my Bentleys, or something
 

Attachments

Last edited:
oh no now i have to make a welsh civ ... llewellyn the frog prince ... brian the boring bland and blessed ... but thanks! i was joking ... but i could work it into some kind of ub ... intolerant Methodism?
 
Back
Top Bottom