Need help with unit overrides

Putmalk

Deity
Joined
Sep 26, 2010
Messages
2,652
Location
New York
Hey guys.

I'm trying to make two civ unique units that do not replace other units, but can only be buildable by the right civilization.

Any thoughts on how this can be done? I've tried:

1. Keeping UnitClass blank in the overrides part of the Civilization.xml
2. Keeping Unit blank in the overrides part of the xml

Am I missing something? Does this require LUA? Thanks.
 
Unfortunately, the default for every unit is to be available to all civs. So if you wanted to make a UU that isn't just a variant of an existing unit, you'd need to add a new unit class, and then either:
1> Add a disabling override for every other civ, including the DLC ones. (See the Barbarian civ for plenty of examples of this.) Unfortunately, you'd then be incompatible with any mod that adds a new civilization.
or
2> Give that unit a prerequisite that only the civ in question can fulfill. Custom techs could do this, but those are problematic because of how city-states and barbarians "steal" technologies. The better way would be to create an unbuildable Project (cost = -1), award it to the one civ you want through a simple start-of-game Lua event, and then have the unit require that project (like how nukes require the Manhattan Project).

The unfortunate downside of #2 is that the unit will appear on everyone else's tech trees and such, but that's easy enough to fix if you really worry about that sort of thing.
 
Thanks Spatz. Knew I could count on you. :)

I'll take option 1 because my scenario will be incompatible with any other mod anyways. Thanks!
 
And the easier way to do #1 is with SQL

(something like)

Code:
INSERT INTO Civilization_UnitClassOverrides(CivilizationType, UnitClassType, UnitType)
  SELECT Type, 'UNITCLASS_MYUNITCLASS', NULL FROM Civilizations WHERE Type != 'CIVILIZATION_MYCIV'
 
Thanks guys, I'll keep this is mind for the future.

In the end I decided that there wasn't any need for these units to not replace existing ones, so I simply made one replace the Great Merchant and removed the other, and added a new UB. Thanks anyway, though!
 
but those are problematic because of how city-states and barbarians "steal" technologies.

Spatzimaus, do you know any further details on how barbarians "steal" technology? Also, are there any XML attributes to adjust that?
 
Couldn't you set the cost of a "base" unit to -1 (unbuildable), then have a UU done the usual way (but giving it a cost, so it is buildable)

No. Well, you COULD, but it wouldn't work quite the way you think. You see, -1 doesn't actually mean "unbuildable", it really means "unselectable". In most practical uses the two are equivalent, but there are a few ways that a civ can gain a unit despite a cost of -1; the most common, by far, is as gifts from Militaristic city-states, but it's also possible for city-states and/or Barbarians to gain these units through certain mechanisms. You can also occasionally get -1 units into your build queue, through some sort of cache issue.

CivWarGamer said:
Spatzimaus, do you know any further details on how barbarians "steal" technology? Also, are there any XML attributes to adjust that?

No, there are no XML attributes to adjust that that I've found, and there's no detailed logic involved. The Barbarian civilization just seems to have a chance to steal techs owned by other civs; it can't ever pull AHEAD of the normal civs, but it'll stay fairly close behind the tech leader. And unlike regular civs, it can gain Disabled techs through this mechanism, which can cause all sorts of problems if you're trying to gate content using disabled techs awarded through various events.
 
Could you make it so that the "base" unit upgrades to a unit buildable earlier in the game? Alternatively, how about making it require a resource that will never be revealed?
 
Could you make it so that the "base" unit upgrades to a unit buildable earlier in the game?

It'd still give you the unit, but now you'd have to pay to "downgrade" it. Doesn't really work well.

The better solution would be to change the tech prerequisite of the unit to being something like Future Tech. The game DOES seem to bring era limitations into account, with gifted units and barbarian camps only spawning units appropriate to the era of the players involved. Between the prereq tech, the obsolete tech, and cost, you might be able to create a situation where a unit doesn't get created in 99% of all situations.

Alternatively, how about making it require a resource that will never be revealed?

Wouldn't help. City-states, unfortunately, can gift units that require a resource. Units gifted by Militaristic city-states don't follow any of the usual rules; they're not limited to the units your civ can build, they're not limited by cost, they're not limited by resources, they're not limited by project limitations, and so on. The only thing I've found that MIGHT be linked to the gift status is the <MilitaryUnit> flag. Unfortunately, that flag also seems to be linked to other factors, like the unit's ability to stack with workers, so changing it could have some unfortunate side effects of its own. When I get home I'll play with this a bit more, and let you know what I find.

Now, I'm not saying that what you want can't be done. With Lua, pretty much ANYTHING can be done in one form or another. You can easily trap the creation of the unit with the SerialEventUnitCreated event, and if it's a type you don't want to have created, you can destroy it on the spot and replace it with something else instead. (I'm looking at doing exactly that in my own mod, for both city-state gifts and Barbarian camps.) I believe this same mechanism was being used in the city-state UU mod. It might also be possible to use the CanConstruct GameEvent to do some of this, but I'm not sure if that function applies to gifted units.
 
I appreciate that bit of info. As far as barbarian civs acquiring those disabled techs, seems like using the Civilization_UnitClassOverrides to "Delete" the unit specific for Barbarians would work.


example:

<Row>
<CivilizationType>CIVILIZATION_BARBARIAN</CivilizationType>
<UnitClassType>UNITCLASS_YOUR_UNIT</UnitClassType>
<UnitType />
</Row>
 
As far as barbarian civs acquiring those disabled techs, seems like using the Civilization_UnitClassOverrides to "Delete" the unit specific for Barbarians would work.

Yes, for Barbarians that works. You should also be using that same override for CIVILIZATION_MINOR to prevent city-states from building the unit for themselves. It doesn't help with the city-state gifting problem, though, since those aren't actually built by the city-states directly.

The point I was getting at is that there's no one simple toggle, like the Cost=-1, that works for all situations. From what I can tell, you either need to mix a handful of different overrides together, or you need to use some sort of Lua hack after the fact. The original poster had asked about adding a civ-specific unit that wasn't just a UU variant of a different unit, and what I was trying to say is that there's unfortunately no simple way to do this using the existing XML because of the many varied mechanisms involved; all of the existing project/building/tech prerequisites will work for general production, but not for these other ways of gaining units. It MIGHT be possible to flag a unit to not be giftable by city-states using the MilitaryUnit or MilitaryProduction flags, but those probably have other effects as well.
 
Just asking this out of interest, but do you know what would happen if the base unit was made obsolete by the tech that allowed it in the first place - or even made obsolete by a pre-requisite of the tech?
 
Just asking this out of interest, but do you know what would happen if the base unit was made obsolete by the tech that allowed it in the first place - or even made obsolete by a pre-requisite of the tech?

Probably the same as setting cost = -1. You'd never be able to build it, but it'd probably still get awarded by city-states since I don't think those check the obsolescence limit in the first place. The game has a few mechanisms where it finds the most recent unit in each "chain", like when you're starting a game in a later era and it's deciding which types of combat units, settlers, and workers you begin the game with. I'd guess that doing what you describe would still have the game seeing those units as being the most recent of each chain.
(Although, that late-start bit DOES check to see if the unit in question has a resource requirement, so it's not a perfect match for the C-S logic.)
 
Back
Top Bottom