Unit era with two prerequisites?

CivilizationAce

Warlord
Joined
Jan 17, 2017
Messages
236
If a unit has only a single civic or tech requirement then obviously it's era is the same as that, but what if it has two. In my new Jedi mod (link in sig) I've created a unit that requires Theology (Classical era civic) and Astrology (Ancient era tech).

Meanwhile some effects only work if a unit is of a certain era, so does anyone know which era the unit adopts?
 
If a unit has only a single civic or tech requirement then obviously it's era is the same as that, but what if it has two. In my new Jedi mod (link in sig) I've created a unit that requires Theology (Classical era civic) and Astrology (Ancient era tech).

Meanwhile some effects only work if a unit is of a certain era, so does anyone know which era the unit adopts?


I don't know, but a possible workaround for this is to set the prereq to just one civic or tech, then set a Resource requirement for the unit for a resource that can't be found on the map ("Jedi Energy" or something). Then automatically award 1 copy of the resource with a Modifier when the player completes the second tech/civic. It would make me nervous to have units running around with both Tech and Civic prereqs set, since no existing units have that set.
 
It would make me nervous to have units running around with both Tech and Civic prereqs set, since no existing units have that set.
Fair point, but in the absence of an official guide we have to experiment and see what works. Happily nobody has reported any issues with it yet :)
 
But how does it work? As AND or as OR, I.e. do you need both tech and civic or just any of them will do?


I think it works as an "and," but all of the UI and AI is coded and tested on the assumption that only or the other is set, not both, so its one of those things that even if it appears to work I would be very wary of.

I did once accidentally set Stonehenge to require a both a civic and a tech, and there was nothing obviously amiss in the game (I believe it required you to unlock both settings), but it still made me nervous. In terms of the UI, it just showed Stonehenge on both trees. If I remember right it also caused some minor display issues with the Civilopedia and preview text.
 
I can confirm this.

However, be warned, building requirements act as OR, as in Apostle requires Temple OR Stave Church.


Yes, this is as designed. It's that way because otherwise a civ's unique buildings would block the building prerequisite chain. That part is well tested and very stable, since all the civ unique buildings are coded that way.
 
BTW this may be worth mentioning since we just talked about Buildings and prereqs.

An oddity of Buildings and prerequisites is that a Trait must point to a civ or the game will crash when the city is captured by another player. Like for example if you create a Trait like this:

TRAIT_NO_ONE_CAN_BUILD

...and set that as the Building's prereq, it will correctly stop all players from constructing the building. You can still manually add the Building with Lua code.

However, when someone captures a city containing such a building, the game crashes to desktop, because the person who owned the city doesn't have the Trait (I assume this happens during the check to see whether to delete or replace various buildings for the new owner). It's an example of the "unsupported" kind of thing I was mentioning earlier. I'm now super cautious about implementing stuff that sits outside the tested parameters, because although it often seems to work in most situations, one odd situation could crash the game.
 
super cautious about implementing stuff that sits outside the tested parameters
Where's the fun in that? Let's push the edge of the envelope and do amazing things. If we hit an issue or two along the way it'll still be worth it, and we'll find those issues for other modders to be wary of, and it'll challenge us to find ways to work around the problems. :)
 
Where's the fun in that? Let's push the edge of the envelope and do amazing things. If we hit an issue or two along the way it'll still be worth it, and we'll find those issues for other modders to be wary of, and it'll challenge us to find ways to work around the problems. :)

I suppose so. The main problem with it is when players start stacking mods. It can lead to some very unsafe operations. If we had tools for stack tracing crashes to desktop it wouldn't worry me. But the environment we have to build in is more limited. You certainly can push the envelope in some ways, but there are some sorts of operations I personally consider too risky. This is one of them mainly because checking civ/tech prereqs is such a frequent operation, and anyone coding UI or AI is likely to make the assumption that only one or the other is set, not both.

Other stuff in this general category for me includes:
- Districts with no prereqs (technically works with the game as far as I can tell, but produces screamers or crashes in some UI add- ons since in the unmodded game all districts have prereqs)
- Buildings with dummy traits that are not attached to a leader (see crash description above)


That's why my suggested workaround is to set a Tech or Civic requirement, then set a Resource requirement. Unlock the Resource with the tech/civic. Plenty of units have both a Tech/Civic requirement and also a Resource one, and you'll never have to worry about which era is getting picked up (which IMO is likely a different answer depending on the function, I'd be surprised if there was consistency since its not a condition that exists in the Vanilla game).
 
Last edited:
Top Bottom