Happiness algorithm

Need help or want to discuss strategy? This is the place!
Norm35
Posts: 750
Joined: Wed Jun 17, 2009 2:22 am
Location: U.S.

Happiness algorithm

Postby Norm35 » Fri Mar 12, 2010 12:06 am

Does anyone know anything about the happiness algorithm used in the program? I have noticed some strange behavior that indicates either a completely random effect or some strange cause and effect relationships.

As an experiment, I put together a script that can selectively delete all rogues or rogues and angry sims or all sims in the lowest three categories. I used this to wipe out all the discontented sims whenever they appear. I found that when there are discontented sims they tend to linger for a long time. On the other hand, when I wipe them all out a couple of times they don't come back. In other words, the presence of unhappy sims seems to create more unhappy sims and this condition gets progressively worse; sort of like an unruly mob. Messing around with the venues and other things does no good but the drastic step of simply wiping them all out puts a stop to the discontented sim problem even if conditions in the city are not improved.

This is not to say that poor conditions can't bring on sim problems but when all else fails, this drastic measure seems to work. I wonder why.
Last edited by Norm35 on Fri Mar 12, 2010 12:17 am, edited 3 times in total.

Azeem
Posts: 3678
Joined: Wed May 05, 2004 9:30 pm
Location: Hetepsenusret

Postby Azeem » Fri Mar 12, 2010 5:09 am

This thing I've been puzzling over as well. Sim Specialists and Random Events do have a profound impact on Sim moods, but if neither are in full effect, there's still the question of what makes happiness (or unhappiness) buzz.

According to the HappinessCategories.xml, the highest rating for Happiness is 30 and the lowest is -26:

Here is how it looks in the XML:
<HappinessCategory_Table>
<HappinessCategory category="Ecstatic" offset="34" low_threshold="26" high_threshold="30" mood_group="Ecstatic" red=".06" green=".20" blue=".06" MouseHelpStringID="TT_SIM_CARD_HAPPINESS_ECSTATIC" mood_graph_help="TT_MOOD_STATUS_ECSTATIC" sdm_icon_id="Mood_Ecstatic" />
<HappinessCategory category="Elated" offset="35" low_threshold="16" high_threshold="25" mood_group="Elated" red=".03" green=".22" blue=".1" MouseHelpStringID="TT_SIM_CARD_HAPPINESS_ELATED" mood_graph_help="TT_MOOD_STATUS_ELATED" sdm_icon_id="Mood_Elated" />
<HappinessCategory category="Happy" offset="36" low_threshold="6" high_threshold="15" mood_group="Happy" red=".16" green=".22" blue=".16" MouseHelpStringID="TT_SIM_CARD_HAPPINESS_HAPPY" mood_graph_help="TT_MOOD_STATUS_HAPPY" sdm_icon_id="Mood_Happy" />
<HappinessCategory category="Content" offset="37" low_threshold="-5" high_threshold="5" mood_group="Content" red=".22" green=".23" blue=".22" MouseHelpStringID="TT_SIM_CARD_HAPPINESS_CONTENT" mood_graph_help="TT_MOOD_STATUS_CONTENT" sdm_icon_id="Mood_Content" />
<HappinessCategory category="Sad" offset="38" low_threshold="-15" high_threshold="-6" mood_group="Sad" red=".23" green=".21" blue=".08" MouseHelpStringID="TT_SIM_CARD_HAPPINESS_SAD" mood_graph_help="TT_MOOD_STATUS_SAD" sdm_icon_id="Mood_Sad" />
<HappinessCategory category="Angry" offset="39" low_threshold="-25" high_threshold="-16" mood_group="Angry" red=".23" green=".12" blue=".03" MouseHelpStringID="TT_SIM_CARD_HAPPINESS_ANGRY" mood_graph_help="TT_MOOD_STATUS_ANGRY" sdm_icon_id="Mood_Angry" />
<HappinessCategory category="Furious" offset="40" low_threshold="-30" high_threshold="-26" mood_group="Furious" red=".23" green=".02" blue=".02" MouseHelpStringID="TT_SIM_CARD_HAPPINESS_FURIOUS" mood_graph_help="TT_MOOD_STATUS_FURIOUS" sdm_icon_id="Mood_Furious" />
</HappinessCategory_Table>

Looking in the SCS Strategic Game Modes.xml file, it seems that depending on the set difficulty level, there's either a greater or lower chance that Sims become sick and Rogue sims can spawn criminals. It is not really clear, however, what factors into the increased or decreased unhappiness modifiers.

The SimConditions.xml file has this:

<!-- <SimCondition condition="Ecstatic" priority="20" script="TGoalGoToVenue" offset="0" display_string="CONDITION_ECSTATIC"/>
<SimCondition condition="Happy" priority="30" script="TGoalGoToVenue" offset="0" display_string="CONDITION_HAPPY"/>
<SimCondition condition="Content" priority="40" script="TGoalGoToVenue" offset="1" display_string="CONDITION_CONTENT"/>
<SimCondition condition="Employed" priority="70" script="TGoalGoToVenue" offset="0" display_string="CONDITION_EMPLOYED"/>
<SimCondition condition="Unemployed" priority="80" script="TGoalGoToVenue" offset="2" display_string="CONDITION_UNEMPLOYED"/>
<SimCondition condition="Homeless" priority="110" script="TGoalGoToVenue" offset="0" display_string="CONDITION_HOMELESS"/>

It appears that the attributes listed here determine how much of a priority a sim will place on visiting venues. Again, pretty ambiguous on how happiness rise or drops are calculated here. :confused:

But this is mentioned in the XML Difficulty Levels text file:

General Format:
<DifficulyLevelTable>
<DifficulyLevel ID="Relaxed" index="0" stringID="DIFFICULTY_LEVEL_RELAXED">
<Value ID="GlobalDailyModifier" float="-1"/>
...
</DifficulyLevel>
</DifficulyLevelTable>


Tag definitions:
NOTE THE MISSPELLING OF 'DIFFICULY' IN ALL CASES
<DifficulyLevelTable>: Primary tag, defines all difficulty levels that will show up when
starting a new game.
<DifficulyLevel>: Defines a single difficulty level.
ID: Name of the difficulty level.
index: Should be a unique number.
stringID: String value, this will be referenced in languagetext.xml, where the name of the difficulty level as seen in-game will be defined.
<Value>: Defines a single value that will act in determining the game's difficulty.
ID: Name of the value. Currently, there are two possible values: GlobalDailyModifier: Controls happiness level. 0 = normal, >0 = lower overall happiness, <0 = higher overall happiness.
JobEfficiencyRelaxed: Controls Simolean production from
workplaces. 1 = normal, <1 = less income, >1 = higher
income.
float: Numeric value, as described above.
Ex. <DifficulyLevel ID="Relaxed" index="0" stringID="DIFFICULTY_LEVEL_RELAXED">
<Value ID="GlobalDailyModifier" float="-1"/>
<Value ID="JobEfficiencyRelaxed" float="1.25"/>
</DifficulyLevel>

What it looks like here is that depending on the set difficulty level you have your game, Happiness level can drop as low as 1 to as high as 2. Then we would need to take into account the happiness rating numbers and perhaps as well as the venue priority factors. I don't know if the 1 and 2 in the Difficulty Levels text file refer to 1 or 2 per hour or if there's another unit of game time used here. One way to test this is to do a test game starting with a single residence that has 1 and only 1 worker sim then have absolutely no venues for a full day; sims typically start at the "Content" level, which is a rating of 5.

One thing you can do to avoid using the most drastic measures is what Midrealm did with his game: change the venue visitation durations to "Express" or to change the values listed in the visit times in the Time_Periods.xml.
Last edited by Azeem on Fri Mar 12, 2010 5:19 am, edited 4 times in total.

Norm35
Posts: 750
Joined: Wed Jun 17, 2009 2:22 am
Location: U.S.

Postby Norm35 » Fri Mar 12, 2010 3:31 pm

" ... One way to test this is to do a test game starting with a single residence that has 1 and only 1 worker sim then have absolutely no venues for a full day; sims typically start at the "Content" level, which is a rating of 5. ..."

I tried your idea of testing with one worker a home, a workplace, and no venue and found that he/she cycled through happiness from happy to rogue and back endlessly. I also tried it with a group of 24 sims with the same result.

This is not what I was taking about. I am talking about a case where the angry sims stay angry and you don't know why but wipe them out and they don't come back. I was wondering what is involved in this situation, do they egg each other on? What in the program causes this kind of behavior?

Sandra Linkletter
Posts: 692
Joined: Tue Jul 15, 2008 7:19 pm
Location: Iowa, USA [Catophilopolis, Amundeir 122 S]
Contact:

Postby Sandra Linkletter » Fri Mar 12, 2010 6:42 pm

Are they injured? I have had angry sims who specifically needed medical venues to heal an injury. If that were the case, removing them would not immediately create more, because they were created by something other than immediate conditions.

Norm35
Posts: 750
Joined: Wed Jun 17, 2009 2:22 am
Location: U.S.

Postby Norm35 » Fri Mar 12, 2010 7:09 pm

"Sandra Linkletter" wrote:Are they injured? I have had angry sims who specifically needed medical venues to heal an injury. If that were the case, removing them would not immediately create more, because they were created by something other than immediate conditions.


No, I don't think they were injured.

For the most part, during past periods there were no unhappy sims. Then I went through some experimentation, changing a number of city characteristics and finally returning to pretty much the original (pretest) configuration. At the same time, a Flu Season had occurred. At that point, I had a large number of unhappy sims even though conditions were pretty much back to what they were before when the sims were happy. The sickness rate was back down to what it had been before the Flu Season. Only they weren't happy now. I waiting for awhile for things to settle down but the Sims remained unhappy. It was sort of like they were holding a grudge because of what I had put them through.

Something just occurred to me. Is there any evidence of the sims having memory of past events?
Last edited by Norm35 on Fri Mar 12, 2010 7:25 pm, edited 2 times in total.

Azeem
Posts: 3678
Joined: Wed May 05, 2004 9:30 pm
Location: Hetepsenusret

Postby Azeem » Sat Mar 13, 2010 3:11 am

That's an interesting possibility; citizens in TM's Children of the Nile did hold grudges for not having services. Maybe TM decided to include that with SCS?

Norm35
Posts: 750
Joined: Wed Jun 17, 2009 2:22 am
Location: U.S.

Postby Norm35 » Sat Mar 13, 2010 3:44 am

"Azeem" wrote:That's an interesting possibility; citizens in TM's Children of the Nile did hold grudges for not having services. Maybe TM decided to include that with SCS?


How could that be tested?

Sandra Linkletter
Posts: 692
Joined: Tue Jul 15, 2008 7:19 pm
Location: Iowa, USA [Catophilopolis, Amundeir 122 S]
Contact:

Postby Sandra Linkletter » Sat Mar 13, 2010 4:01 am

I don't know the answer to that right offhand, but I have felt that the disease routine pumped in sickness for the duration of the plague, regardless of whether the conditions in my city were good and the sims had all the medical care they needed. That is, all but maybe one sim would be cured when the venues closed and suddenly there were 45 more sick ones when the day ticked over. This was without any disease clouds around my homes. Maybe that routine pumps in unhappiness also?

Norm35
Posts: 750
Joined: Wed Jun 17, 2009 2:22 am
Location: U.S.

Postby Norm35 » Sat Mar 13, 2010 9:12 am

"Sandra Linkletter" wrote:I don't know the answer to that right offhand, but I have felt that the disease routine pumped in sickness for the duration of the plague, regardless of whether the conditions in my city were good and the sims had all the medical care they needed. That is, all but maybe one sim would be cured when the venues closed and suddenly there were 45 more sick ones when the day ticked over. This was without any disease clouds around my homes. Maybe that routine pumps in unhappiness also?


A scan of the scripts shows a lot of relevant words and phrases that give clues to program functions that are behind some of these actions.

SicknessReduction
Malady
Cures Malady
Condition
Sick
ApplyHappinessModifier
ApplyToOccupants
Contagious
GetEpidemicEnabled
SetEpidemicEnabled
kPlagued
kImmune
kSick
sPlagueChance
ModifyCures
EpidemicWeight
Healthcare
CrisisEpidemic
kDisasterStateOnGoing
sImmunityFlag

Some of these words are actual class names representing groups of functions there for the express purpose of introducing sickness and unhappiness.

It would not be difficult to plant print statements in these scripts to flag when these functions are being activated, to alert the player to what is beginning, as against just random events. These alerts could appear in the news bar at the bottom of the screen or in a debug file.

Someone commented that this kind of thing would be "cheating." Personally, I see it as outwitting the game, or the programmer behind it. Some of the things the game does seem totally unfair and unreasonable. Some are the result of poorly thought out programming or mistakes. I use this perhaps as an excuse to "cheat" at times.

But all this doesn't answer the question, do the Sims remember?

On the other hand, rather than the sim attitude being the result of something acquired it may the result of something lost, trust, confidence, naivete, a feeling of being safe and protected.

Theoretically, allowing a a sim to play hooky gives it a chance to visit venues and build up its store of happiness to a higher level. This doesn't happen during periods of wide-spread anger. I have followed numerous angry sims from venue to venue without seeing their happiness state change at all. All that seems to work is for the the sim to go to rogue state and disable a workplace; then the state of this one sim changes to Happy. The states of all the other angry sims remain unchanged. So for every angry sim, a workplace must be shut down in order to help it. This looks like a program bug to me.
Last edited by Norm35 on Sat Mar 13, 2010 2:45 pm, edited 5 times in total.

Azeem
Posts: 3678
Joined: Wed May 05, 2004 9:30 pm
Location: Hetepsenusret

Postby Azeem » Sat Mar 13, 2010 2:54 pm

"Norm35" wrote:Theoretically, allowing a a sim to play hooky gives it a chance to visit venues and build up its store of happiness to a higher level. This doesn't happen during periods of wide-spread anger. I have followed numerous angry sims from venue to venue without seeing their happiness state change at all. All that seems to work is for the the sim to go to rogue state and disable a workplace; then the state of this one sim changes to Happy. The states of all the other angry sims remain unchanged. So for every angry sim, a workplace must be shut down in order to help it. This looks like a program bug to me.


Not necessarily. Recall that the happiness factor ranges from 30 to -26, which is a pretty big gap. Venues typically only produce as much as 10 happiness or as little as 3; add on to -1 or -2 happiness per unit of time (as shown in the Difficulty Levels XML) as well as sickness or Sim Specialist modifiers, then it becomes a lose-lose situation for you. Basically if we theoretically say that a Sim's happiness is at 0, he/she goes to a +3 venue for 2 hours, which is the normal required time for most venue as shown in the Time Periods XML file, then he/she would have gained 3 happiness but at the same time lost happiness. It is my hypothesis that Sims lose happiness even as they are inside a venue. It's possible that it is a bug, but on the other hand it could be a "feature" intended to be there to appease those that kept whining about how "easy" the game was (although incidentally those same complainers did not appear really play the game at all at the hardest levels). I know that in earlier versions of SCS, it seemed to be much easier to maintain happiness stability.

Perhaps in this case, one can re-define the visitation times of each venue to be much lower to avoid the unhappiness trap.

Norm35
Posts: 750
Joined: Wed Jun 17, 2009 2:22 am
Location: U.S.

Postby Norm35 » Sat Mar 13, 2010 3:10 pm

"Azeem" wrote:Not necessarily. Recall that the happiness factor ranges from 30 to -26, which is a pretty big gap. Venues typically only produce as much as 10 happiness or as little as 3; add on to -1 or -2 happiness per unit of time (as shown in the Difficulty Levels XML) as well as sickness or Sim Specialist modifiers, then it becomes a lose-lose situation for you. Basically if we theoretically say that a Sim's happiness is at 0, he/she goes to a +3 venue for 2 hours, which is the normal required time for most venue as shown in the Time Periods XML file, then he/she would have gained 3 happiness but at the same time lost happiness. It is my hypothesis that Sims lose happiness even as they are inside a venue. It's possible that it is a bug, but on the other hand it could be a "feature" intended to be there to appease those that kept whining about how "easy" the game was (although incidentally those same complainers did not appear really play the game at all at the hardest levels). I know that in earlier versions of SCS, it seemed to be much easier to maintain happiness stability.

Perhaps in this case, one can re-define the visitation times of each venue to be much lower to avoid the unhappiness trap.


Maybe.

I have raised the happiness effects of venues as high as 20 without relieving the situation.

I am considering programming a script to follow an angry sim and report on its Happiness State to see exactly how it varies under various circumstances. I'm not sure I am up to the task though.

Sandra Linkletter
Posts: 692
Joined: Tue Jul 15, 2008 7:19 pm
Location: Iowa, USA [Catophilopolis, Amundeir 122 S]
Contact:

Postby Sandra Linkletter » Sat Mar 13, 2010 6:50 pm

Nothing is cheating unless you are in a competition against other players, and then cheating is defined by the rules of the competition. :)

A lone person can feel they are cheating by their own rules, but that doesn't apply to anyone else in the universe. :p

I share the impression that angry sims often seem to only be satisfied by going rogue and shutting down a workplace, but I have not played with the system enough to say definitively that this is the case.

I didn't realize that those scripts were active ones. That is, I thought perhaps they were annotations on the program. Can we actually write scripts and have the program execute them?

Norm35
Posts: 750
Joined: Wed Jun 17, 2009 2:22 am
Location: U.S.

Postby Norm35 » Sat Mar 13, 2010 10:15 pm

"Sandra Linkletter" wrote:I share the impression that angry sims often seem to only be satisfied by going rogue and shutting down a workplace, but I have not played with the system enough to say definitively that this is the case.

I didn't realize that those scripts were active ones. That is, I thought perhaps they were annotations on the program. Can we actually write scripts and have the program execute them?


Absolutely. The use of scripting is a very powerful tool. Of course it helps if you know how to program.

Norm35
Posts: 750
Joined: Wed Jun 17, 2009 2:22 am
Location: U.S.

Postby Norm35 » Sat Mar 13, 2010 11:06 pm

Azeem,

I think I have found out why Angry Sims stay angry.

I can hardly believe the reason but have confirmed it by removing the the symptom and they recover almost immediately.

It is either an oversight by the programmer that did it or it was done as a joke, I am not sure which.

Take a look at line 660 of TGoalGoToVenue.cs and at line 48 of Crisis_OzoneHole.cs. The flag was being set but not later cleared.

I cleared the flags and everyone recovered quickly.

Sandra Linkletter
Posts: 692
Joined: Tue Jul 15, 2008 7:19 pm
Location: Iowa, USA [Catophilopolis, Amundeir 122 S]
Contact:

Postby Sandra Linkletter » Sun Mar 14, 2010 4:07 am

I do know how to program, but slogging through someone else's C code isn't my idea of a fun time. :p It's possible, though.

My version of SCS seems to be different from yours. I don't have an Ozone Hole crisis file, and line 660 of TGoalGoToVenue is "}". What's the name of the routine?

Azeem
Posts: 3678
Joined: Wed May 05, 2004 9:30 pm
Location: Hetepsenusret

Postby Azeem » Sun Mar 14, 2010 5:02 am

That's odd. I don't have the cs file either.

Norm35
Posts: 750
Joined: Wed Jun 17, 2009 2:22 am
Location: U.S.

Postby Norm35 » Sun Mar 14, 2010 7:07 am

Both files are in the
C:\Program Files\Electronic Arts\SimCity™ Societies\DataXP1\scripts folder.

You may have been looking in the
C:\Program Files\Electronic Arts\SimCity™ Societies\Data\Scripts folder.

I believe the files in the first folder listed above override those in the second when working with Destinations.
Last edited by Norm35 on Sun Mar 14, 2010 7:10 am, edited 1 time in total.

Norm35
Posts: 750
Joined: Wed Jun 17, 2009 2:22 am
Location: U.S.

Postby Norm35 » Sun Mar 14, 2010 7:21 am

"Sandra Linkletter" wrote:I do know how to program, but slogging through someone else's C code isn't my idea of a fun time. :p It's possible, though.

My version of SCS seems to be different from yours. I don't have an Ozone Hole crisis file, and line 660 of TGoalGoToVenue is "}". What's the name of the routine?


I'm sorry I wasn't more specific. I am working with the Destinations expansion package. It sounds like you may be working with the basic SCS.

I know how you feel about reading someone else's code. It is particularly difficult when the source of the code is uncooperative about releasing information on what is in the parts of the system that are in exe form. I have spent a lot of time poring over these scripts and it is beginning to get easier to find my way. This game does provide more script in source form than any other commercial game I have seen and it is relatively clean. However, some things are done in such a convoluted manner that it is virtually impossible to figure out what they are doing behind the scenes, I don't think this is accidental. It would help a lot to know what is in the exe, particularly class and member names and arguments, so you could make calls to those too rather than constantly reinventing the wheel. I have to do a lot of trial and error guessing about what is in the base classes referenced by the scripts. I had to work from scratch to create my own classes to do simple I/O even though I am sure the system already has a powerful I/O structure. If the company had been more cooperative, the gamer/programmers might have stuck around and the system might have survived with a minimum of company support.
Last edited by Norm35 on Sun Mar 14, 2010 8:30 am, edited 6 times in total.

Sandra Linkletter
Posts: 692
Joined: Tue Jul 15, 2008 7:19 pm
Location: Iowa, USA [Catophilopolis, Amundeir 122 S]
Contact:

Postby Sandra Linkletter » Sun Mar 14, 2010 3:02 pm

Yes, I am playing with the unexpanded SCS. I didn't see enough benefits to the expansion to be worth paying EA more money, not even boxed with SimCity 4. ;)

I was reading over the script for epidemics last night, just before bedtime. I did not chase down the routines called, but I did see more or less what I suspected. It appears that even if the total capacity of your healthcare facilities is several times your total population, the epidemic will continue along some predetermined curve in terms of number of ill Sims.

Norm35
Posts: 750
Joined: Wed Jun 17, 2009 2:22 am
Location: U.S.

Postby Norm35 » Sun Mar 14, 2010 3:31 pm

[QUOTE=Sandra Linkletter;275463]Yes, I am playing with the unexpanded SCS. I didn't see enough benefits to the expansion to be worth paying EA more money, not even boxed with SimCity 4. ;)

If you are not using Destinations, don't worry about the problem I was discussiing; that is only associated with the Destinations version.


Return to “Game Help &amp; Strategy”

Who is online

Users browsing this forum: No registered users and 2 guests