1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Code for unhappiness?

Discussion in 'Civ5 - Creation & Customization' started by Alexander666, Dec 2, 2012.

  1. Alexander666

    Alexander666 Chieftain

    Joined:
    Nov 29, 2012
    Messages:
    24
    Hi guys,
    what is the code for having a building yield unhappiness?

    Tried this but doesn't work - can't seem to find the right yield type anywhere:
    <BuildingType>BUILDING_WHATEVER</BuildingType>
    <YieldType>YIELD_UNHAPPINESS</YieldType>
    <Yield>3</Yield>

    And I can't find any reference to the icon code for the unhappy smiley either.

    Thanks


    EDIT: Here is the solution from the posts below if someone needs it later on:
    "The specific code to use if you want a building/wonder to produce unhappiness is "<UnhappinessModifier>10</UnhappinessModifier>" - it won't show directly with its own entry in the happiness dropdown, but it does modify your civ's overall unhappiness. "
     
  2. kaspergm

    kaspergm Deity

    Joined:
    Aug 19, 2012
    Messages:
    4,828
    Have you tried simply to give it a negative happiness yield? You can have negative yields of other stuff, so how about simply trying to set yield to -3? That being said, is YIELD_HAPPINESS even a valid tag, or do you need something else? Compare to other buildings that give happiness for reference.
     
  3. snarko

    snarko DLLer

    Joined:
    Dec 9, 2003
    Messages:
    1,512
    Location:
    Sweden
    Happiness is not a yield. What you want to do is set <Happiness>-3</Happiness> for the building.

    (I haven't tested it, but if it does work that's the way to do it.)
     
  4. Alexander666

    Alexander666 Chieftain

    Joined:
    Nov 29, 2012
    Messages:
    24
    Aha, ok cool, gonna try out <Happiness>-3</Happiness>.

    Edit: Ok that code provides this result: "+-3 :) Happiness"
    My guess it that there is an Unhappiness "resource" like the one for Happiness. Just don't know where to find the reference for it. I tried <Unhappiness>3</Unhappiness> just to try and guess it, but it is not a valid code.
     
  5. whoward69

    whoward69 DLL Minion

    Joined:
    May 30, 2011
    Messages:
    8,417
    Location:
    Near Portsmouth, UK
  6. Alexander666

    Alexander666 Chieftain

    Joined:
    Nov 29, 2012
    Messages:
    24
    Sweet, thanks for the icon references!

    Now I just need to find the unhappiness "resource" code.
     
  7. kaspergm

    kaspergm Deity

    Joined:
    Aug 19, 2012
    Messages:
    4,828
    Is there any feature in the game that adds unhappiness that you can think of, which you might look up for reference?
     
  8. Alexander666

    Alexander666 Chieftain

    Joined:
    Nov 29, 2012
    Messages:
    24
    Yeah, that's what's cooking my noodle.

    Only thing I can think of is actually when not building a courthouse after annexing a city... but where to find this, I don't know.

    Unhappiness might not even exist as a modifiable stat like Happiness.
     
  9. Horem

    Horem Emperor

    Joined:
    Apr 1, 2010
    Messages:
    1,720
    Location:
    Wales, UK
    For buildings there is a UnhappinessModifier(Int) never used it so do not know if it works or its left over from Civ IV. Use it same way as happiness at a guess, 3 been 3 unhappiness ect.

    Edit: Scratch that the only building I see that uses it is Forbidden Palace and that is set at -10? No idea what this wonder does tbh.

    Edit:2 Courthouse uses a different function, NoOccupiedUnhappiness.
     
  10. Drawmeus

    Drawmeus Emperor

    Joined:
    Jul 25, 2007
    Messages:
    1,213
    Unhappiness Modifier is apparently percent reduction in global unhappiness from population. The name is rather unhelpful, like quite a few other fields.
     
  11. Alexander666

    Alexander666 Chieftain

    Joined:
    Nov 29, 2012
    Messages:
    24
    I have implemented the code from the Forbidden Palace: <UnhappinessModifier>-10</UnhappinessModifier>.

    It does not make any errors, so that's a good thing - but it also does not show up as a modifier on the Happiness drop down in game. So I am not sure it actually works.
     
  12. kaspergm

    kaspergm Deity

    Joined:
    Aug 19, 2012
    Messages:
    4,828
    Forbidden Palace decreases unhappiness by 10 percent. So if you implemented that effect, it would have the opposite effect of what you wanted. Don't know if you could potentially set it to a positive number in order to make it increase unhappiness, but since FP affects total kingdom happiness it would probably be hard to balance.

    On a sidenote and out of curiosity, what is the building you are making which will actually increase unhappiness?
     
  13. rf900

    rf900 Warlord

    Joined:
    Jan 31, 2006
    Messages:
    194
    I faced the same problem when working on a medieval lab that gaved science and unhappiness on the city. Are you sure that even in the interface it shows as +-3 it is not giving the -3 unhappiness?

    I answer my own question, there is check for positive values in the code... I could make a DLL that accepts negative values, not sure if it can cause other problems elsewhere.

    Spoiler :
    CvCity.cpp under processBuilding

    if(pBuildingInfo->GetHappiness() > 0)
    {
    ChangeBaseHappinessFromBuildings(pBuildingInfo->GetHappiness() * iChange);
    }

    if(pBuildingInfo->GetUnmoddedHappiness() > 0)
    {
    ChangeUnmoddedHappinessFromBuildings(pBuildingInfo->GetUnmoddedHappiness() * iChange);
    }
     
  14. Alexander666

    Alexander666 Chieftain

    Joined:
    Nov 29, 2012
    Messages:
    24
    I am working on a Spartan civilization mod. The building I want to increase unhappiness is actually the wonder associated with that civ.



    The Apothetai:
    +15% [ICON_STRENGTH] Combat strength for units fighting on Spartan soil.
    +5 [ICON_CULTURE] Culture. +3 [ICON_PRODUCTION] Production.
    Some [ICON_HAPPINESS_3] Unhappiness from lamenting women.

    Here is the Civilopedia entry:
    Spoiler :
    "The Apothetai was the name of a great gorge near a hill side close to the city of Sparta. When a Spartan baby was born, soldiers came to the house and examined it carefully to determine its strength. The baby was bathed in wine rather than water, to see its reaction. If a baby was weak or disfigured, the Spartans either took it to be grown in to a Helot (slave worker) or, if the council deemed it so, threw it from a hillside into the gorge - the site known as The Apothetai.

    Spartan children were taught stories of courage and fortitude. One favorite story was about a boy who followed the Spartan code. He captured a live fox and intended to eat it. Although boys were encouraged to scrounge for food, they were punished if caught. The boy noticed some Spartan soldiers coming, and hid the fox beneath his shirt. When the soldiers confronted him, he allowed the fox to chew into his stomach rather than confess, and showed no sign of pain in his body or face. This was the Spartan way.

    At the age of 20 or so, they had to pass a rigorous test to graduate and become full citizens. Only the soldiers were received the aristocratic citizenship. If they failed their tests they never became citizens, but became perioeci, the middle class. So to some extent class was based on merit rather than birth.

    The many bones and skulls in The Apothetai functioned as a harsh reminder and inspiration to the young Spartans through their rigorous testing and endeavors."


    Here is the splash image:
    Spoiler :


    The idea is that this is kind of the essence of Spartan philosophy and a very cultural thing for the Spartans (hence the culture bonus) - the men would be "inspired" to work hard or face dire consequences if deemed weak (hence the production bonus), and the women would mourn their losses, so I just think it would be a nice tweak with lamenting women (Unhappiness) since this "wonder" is quite morbid :king:

    Download and (WinRAR file) from this link:
    http://speedy.sh/uCKZZ/King-Leonidas-This-is-Sparta-v-1beta.rar

    Unpack the directory in your "C:\Users\[your username]\Documents\My Games\Sid Meier's Civilization 5\MODS" folder.


    Feel free to download it and give it a whirl - see if you get a feel of being able to withstand Persia with a few good men while focusing on raising some culture :king: (feedback is always welcome - especially the kind of feedback containig code ;)).

    PS. Since this wonder is replacing The Oracle (which gives a free social policy) I was thinking of implementing a free policy when completing the Honor policy tree. But really I have no clue how to make that work, so that's off the shelf for now.
     
  15. Alexander666

    Alexander666 Chieftain

    Joined:
    Nov 29, 2012
    Messages:
    24
    This works! I can't see it specifically on the happiness drop down, but on the turn before the wonder is built I had x unhappiness, and after it was buit the unhappiness increased! :) good times!

    See above post :)

    -

    So... to recap for anyone needing this at some point:
    The specific code to use if you want a building/wonder to produce unhappiness is "<UnhappinessModifier>10</UnhappinessModifier>" - it won't show directly with its own entry in the happiness dropdown, but it does modify your civ's overall unhappiness.
     
  16. Spatzimaus

    Spatzimaus Mad Scientist

    Joined:
    Sep 21, 2005
    Messages:
    3,063
    Location:
    Los Angeles, CA
    Sorry I'm late to the discussion, but let me give you some answers.

    No, you can't implement a straight -X happiness for a building, regardless of whether you make it unmodded or not, because the XML in the Buildings table simply isn't capable of recognizing negative numbers. You can take the Wonder path to increase overall unhappiness by a certain percentage, but a straight one-shot happiness penalty can't be done through the Buildings declaration.

    However, it CAN be done through Policies. Unlike the building happiness declarations, which have to be positive, the "+1 happiness per University" sort of policy CAN be inverted, to where all buildings of a specific type can add Unhappiness instead of Happiness. My own mods have done exactly this; all players are given a certain hidden Policy that adds Unhappiness for a half-dozen or so buildings. So, each Genejack Factory might give -2 Happiness when built (to offset its huge production boost); the Building declaration doesn't do that, but the hidden Policy does, and the end result is a nicely balanced building that you can choose not to build if you're short on Happiness.

    This has a few issues to keep track of, though:
    1> The UI isn't really built for it, but that's an easy change. The first thing I did in my mods was change the various UI elements to allow for the possibility of negative happiness. So, instead of saying "(smiley) +-1" it'll say "(frown) -1". This sort of change is useful even if you're not going to bother with the rest, though.

    2> Adding a hidden policy adds a number of new problems. First, that policy needs to be placed in a Branch. If you place it into one of the ten existing branches, then the player will be just fine, but the AI will prioritize that now-opened branch over all others. If you place it into a new eleventh branch, then the UI logic will break. And, that new eleventh branch will also have AI issues, although that's avoidable if you make multiple exclusive policies within that branch and then increase the AI branch cap from 2 to 3. Plus, you need to add Lua logic to give that policy to the players on the first turn, and ensure the AI doesn't lock up in indecision (and yes, that can happen).

    3> The AI can handle it in most cases, as Flavor values can be negative, but an AI at zero Happiness will still build the thing, even if the unhappiness penalty would be far more crippling than the benefits of the building. Normally the AI has strong overrides to prevent itself from going negative on Happiness, but this mechanism avoids those checks. It's made worse since a smart human player will simply avoid building the buildings until he has a nice buffer to work with, whereas AI Flavor ratings are an always-on thing. (That is, a building that's good to build now will pretty much always be seen as good to build.)
    In other words, you shouldn't put negative-happiness buildings in the part of the tech tree where the players are always low on Happiness and trying to settle new cities before unlocking new Happiness-producing structures (i.e., the Classical Era). They work just fine in later eras, where adding new Happiness is easy.

    However, this sort of hidden policy mechanism is useful for all sorts of other stuff. For instance, in my Mythology mod I actually had five hidden policies, depending on which Era you were in. That way, certain buildings automatically get stronger as the game goes on, while others get weaker over time. So you can add all sorts of other benefits to these hidden policies, to do things not possible through the simple Building XML tables.

    At the moment my mods aren't available, due to some coding issues, but I'm hoping to have them back online within the next week or two. Then, you'd be able to see what I'm suggesting. (I've also adding things like Happiness-producing Specialists, so what I've got is a lot more complex than the core game allows.)
     
  17. kaspergm

    kaspergm Deity

    Joined:
    Aug 19, 2012
    Messages:
    4,828
    Fascinating read. Sounds like the all-round unhappiness is the way to go for the OP, though.
     
  18. Horem

    Horem Emperor

    Joined:
    Apr 1, 2010
    Messages:
    1,720
    Location:
    Wales, UK
    Take a look at CCTP's Policy lua, allows 30 branches or more, I didnt make it so I am not sure on the limitations.
     
  19. Spatzimaus

    Spatzimaus Mad Scientist

    Joined:
    Sep 21, 2005
    Messages:
    3,063
    Location:
    Los Angeles, CA
    I should have been more clear: the UI logic AS WRITTEN will break. Obviously, if you mod the UI then this issue goes away. My own mod simply placed the 11th branch into a special horizontal box that could be opened and closed as needed by clicking a button.

    The point was that it's not like many other UI elements, where it'll either fail gracefully (just not showing whatever new thing you added) or adapt dynamically. An eleventh branch just causes it a crash.
     

Share This Page