1. We have added the ability to collapse/expand forum categories and widgets on forum home.
    Dismiss Notice
  2. Photobucket has changed its policy concerning hotlinking images and now requires an account with a $399.00 annual fee to allow hotlink. More information is available at: this link.
    Dismiss Notice
  3. All Civ avatars are brought back and available for selection in the Avatar Gallery! There are 945 avatars total.
    Dismiss Notice
  4. To make the site more secure, we have installed SSL certificates and enabled HTTPS for both the main site and forums.
    Dismiss Notice
  5. Civ6 is released! Order now! (Amazon US | Amazon UK | Amazon CA | Amazon DE | Amazon FR)
    Dismiss Notice
  6. Dismiss Notice
  7. Forum account upgrades are available for ad-free browsing.
    Dismiss Notice

Way to make one building prevent another from being built?

Discussion in 'Civ5 - Creation & Customization' started by chrome-rome, Jan 10, 2012.

  1. chrome-rome

    chrome-rome Chieftain

    Joined:
    Jan 7, 2009
    Messages:
    620
    Hi all,

    Is there a way to set up an "x or y" type deal, where a city can either build building x or building y, but can't have both in the same city?
     
  2. Spatzimaus

    Spatzimaus Mad Scientist

    Joined:
    Sep 21, 2005
    Messages:
    3,063
    Location:
    Los Angeles, CA
    Yes, that's what the Mutually Exclusive Groups are for. In the vanilla game, the Solar Plant and Nuclear Plant work exactly that way. So all you need to do is set <MutuallyExclusiveGroup>2</MutuallyExclusiveGroup> (I think that's the name, it shouldn't be hard to find) for both buildings, and the game will automatically lock all buildings in the group out once one of them has been built. I use this in my own mods as well.

    The problem is the number (the "2" I used above). The Nuclear/Solar Plants are group 1, so you just need to pick a number other than 1. The problem is that if some other mod with mutually exclusive buildings just happened to pick the same number as you, you'll lock each other out. So you should generally skip the most commonly selected numbers for nerds (42, 69, 314...). I have no idea whether there's a maximum value for this, but you should try to keep it below 999.
     
  3. Rob (R8XFT)

    Rob (R8XFT) Ancient Briton Super Moderator

    Joined:
    Aug 11, 2002
    Messages:
    10,188
    Location:
    Leeds (UK)
  4. chrome-rome

    chrome-rome Chieftain

    Joined:
    Jan 7, 2009
    Messages:
    620
    Oh great thanks Spatz. :)

    Btw, I took your advice on the lua stuff. It still doesn't look like much fun but at least I have a heading. :lol:
     
  5. Spatzimaus

    Spatzimaus Mad Scientist

    Joined:
    Sep 21, 2005
    Messages:
    3,063
    Location:
    Los Angeles, CA
    I should also point out that these mutual exclusions only apply within a single city. So you can make it so that two National Wonders within a group are mutually exclusive, but you can't make it to that you can't build Wonder X if you already have Wonder Y somewhere else in your empire.
    It still has some very nice uses for National Wonders; in my own mods (specifically the Empires mod), I created four National Wonders in a mutual exclusion group: Wall Street, Hollywood, the Red Cross, and the Three Gorges Dam. So four of your cities will end up with these, which basically causes the cities to specialize a bit (Wall Street making one city your financial center, Hollywood making a cultural center, and so on) and each also has empire-wide effects. It's really a very under-utilized bit of functionality, and could have made the vanilla game much more interesting.

    Now, if you DO want something more complex, like having a Wonder lock out a different Wonder from every city, you can use the CanConstruct function in Lua to override the process. In theory there's no limitation to how complex the triggers can be, since Lua can cover a lot of different algorithms. But don't use these Lua overrides too much, or it'll slow things down.
     
  6. chrome-rome

    chrome-rome Chieftain

    Joined:
    Jan 7, 2009
    Messages:
    620
    One more question: Let's say I have a group of 10 different buildings. I want a player to be able to build up to three of them in a city, but once they build that third building, the others get blocked out. Is that possible?
     
  7. PawelS

    PawelS Ancient Druid

    Joined:
    Dec 11, 2003
    Messages:
    2,803
    Location:
    Poland
    Why do you think these numbers are the most commonly selected?
     
  8. Eiken

    Eiken Chieftain

    Joined:
    Apr 7, 2011
    Messages:
    7
    42 is ultimate answer, 69 you can do with GF and 314 is Pi(at least i see it there)?
     
  9. Spatzimaus

    Spatzimaus Mad Scientist

    Joined:
    Sep 21, 2005
    Messages:
    3,063
    Location:
    Los Angeles, CA
    You could use the CityCanConstruct Lua gameevent to cap this without many problems. I'm not sure how much overhead there'd be on each check, but the logic would at least be pretty straightforward. You'd just use City:GetNumRealBuildings, something like
    Code:
    cityLevel = pCity:GetNumRealBuildings(bID1) + pCity:GetNumRealBuildings(bID2) + ...
    although if you're intending to have any of these buildings to not be limited to one-per-city then you'd need to do that element as
    (pCity:GetNumRealBuildings(bID1) > 0) and 1 or 0)

    Depending on exactly what you want to do with this, there's another option: give all ten buildings the same building class, and then cap things like number-per-player for that class. This wouldn't limit it to three in a given city, just N in your entire empire. This sort of method is good for buildings awarded through Lua functions, not so much for ones the player builds as normal. I've actually used this method for the Hero units in my own Mythology mod, because it's much easier to check for a single unit class than it is to check dozens of different unit types.

    The other option is to construct a progressive exclusion tree. That is, you start with building A. Then there are buildings B and C, each of which requires A and which are mutually exclusive. Then you have D and E, which require B and are exclusive, and F and G, which require C and are exclusive. So everyone gets a total of three buildings (one of which is A) out of the seven, with four unique combinations. You can even take this another level by adding a second tree of 7 whose root is exclusive with A. It gets even more interesting when you try adding OR logic in on prerequisites... you can create all sorts of interesting progressions this way.
     
  10. PawelS

    PawelS Ancient Druid

    Joined:
    Dec 11, 2003
    Messages:
    2,803
    Location:
    Poland
    As for the original question about "MutuallyExclusiveGroup": Wouldn't it be possible to create SQL code that checks which numbers are already used, and assigns unused ones to building groups in your mod? This would be useful for mods that are often used together with other mods...
     
  11. Spatzimaus

    Spatzimaus Mad Scientist

    Joined:
    Sep 21, 2005
    Messages:
    3,063
    Location:
    Los Angeles, CA
    Probably, but the logic for this could be pretty horrendous depending on the load orders. You'd have to use explicit checks for a lot of things, because how else would you distinguish the conflicting buildings you've added with the ones that came from some other source?

    Honestly, I think they should have just done it the same way they did invisibility, where the invisibility type is basically identified by a string like "Submarine". So if you made a "Power Plant" group for the vanilla game, a "Spatz's Industrial National Wonders" group, and so on, there'd be no possibility of conflict. Instead, we're left picking a random number and hoping no one else chose the same one.
     
  12. PawelS

    PawelS Ancient Druid

    Joined:
    Dec 11, 2003
    Messages:
    2,803
    Location:
    Poland
    I think it can be done by adding the string as a new field in the Buildings table, and using some SQL code to assign an unique number to every unique string... But of course there will be problems when using mods that don't use this convention...
     

Share This Page