Experimenting with happiness

A place for discussion of making game modifications.
Post Reply
akkamaddi
Posts: 147
Joined: Tue Sep 26, 2017 5:11 am

Experimenting with happiness

Post by akkamaddi »

I'm experimenting with making some minor changes to happiness modifiers, and I was wondering if there would be any interest in this. I've actually started to make some changes.

Currently, Phidi get +5 additional happiness per Market, and Orthin get +5 happiness per

Markets: (And if there is a way to add a pop-up for races, please let me know!)
-> These are modifiers to the base Market happiness mod, not new flat values.
As things are, Phidi get +5 happiness per market. What I am implementing is:
Spice Mongers +3 (Also mercantile.)
Algorian +1 (You can find amazing gifts to gain social clout.)
Scavengers -2 ("Why not just steal it?")
Lummox -2 (Very primitive, can't fully appreciate what is available.)
Gaiad -4 ("This is all crap. We're not trading our forest for a storage crate of beads.")

Farms:
Lummox +1 ("We don't have to compete with predators for food now?")
Gaiad +1 ("Not ideal, but you are trying to enrich the land. Thank you.")

Mines:
Gaiad -4 ("You leave scars to steal metal. This cannot stand.")

Factories:
Gaiad -2 ("You destroy Forest to poison air and water to make garbage. This is not acceptable.")

Labs:
Scavengers -1 ("We are not sure you can control this magic. The ones before could not.")


The modifiers to mines and factories I was originally planning on adding to my Tzidpah, and I will, but I doubled the modifiers for Gaiads. These modifiers make developing Gaia a dangerous. The Gaiads are OK with labs and kind of like farms, but are not easily bought off with trinkets. It also fits with their "eco disaster" racial special. Quickly turning Gaia into a manufacturing center can lead to a dangerous revolt.

I was also considering giving humans +1 happiness for each farm, factory, mine, and lab structure. I see humans has having an innate neurosis that their homeworld is gone, and they are desperate to rebuild. Being part of an established colony would be inspiring for them. While they would not be penalized for being on a new, undeveloped colony, they would become happier as their surroundings matured.

I would be interested if anyone had any thoughts or interest in this.

Also, for those familiar with Lua, would there be an easy way to check against a planet type?
akkamaddi
Posts: 147
Joined: Tue Sep 26, 2017 5:11 am

Re: Experimenting with happiness

Post by akkamaddi »

EDIT: I think I got it, go to the end.

OK, I could use a bit of help, if possible.

I've expanded the planet issues for labs, so that it accounts for both Orthin liking labs, and Scavengers being afraid of them. That works fine.

I've added an event, using copy and paste, so that both Lummox and Gaiad like farms.

Code: Select all

function RacePlanetIssues.labs(empire,race,planet)

  if remove_race_suffix(race)=='orthin' and (planet.labs>0)

    local rep = race_improvement_morale_bonuses.orthin.labs * planet.labs

    if planet.labs>=3

      return {
        ..rep,
         short = 'Labs(<LAB>)',
        desc = [[These research facilities are excellent!]],
      }

    else

      return {
        ..rep,
        short = 'Labs(<LAB>)',
        desc = [[The local research facilities are acceptable.]],
      }

    end

  end

  if remove_race_suffix(race)=='scavenger' and (planet.labs>0)

    local rep = race_improvement_morale_bonuses.scavenger.labs * planet.labs

    if planet.labs>=3

      return {
        ..rep,
         short = 'Labs(<LAB>)',
        desc = [[You, too, will bring death here!]],
      }

    else

      return {
        ..rep,
        short = 'Labs(<LAB>)',
        desc = [[We are not sure you can control this magic. The ones before could not.]],
      }

    end

  end
	
end



function RacePlanetIssues.farms(empire,race,planet)

  if remove_race_suffix(race)=='lummox' and (planet.farms>0)

    local rep = race_improvement_morale_bonuses.lummox.farms * planet.farms

    if planet.farms>=4

      return {
        ..rep,
         short = 'Farms (<FARM>)',
        desc = [[Our children may never know starvation.]],
      }

    else

      return {
        ..rep,
        short = 'Farms (<FARM>)',
        desc = [[We don't have to compete with predators for food now?]],
      }

    end
	
	end
	
 if remove_race_suffix(race)=='gaiad' and (planet.farms>0)

    local rep = race_improvement_morale_bonuses.gaiad.farms * planet.farms

    if planet.farms>=4

      return {
        ..rep,
         short = 'Farms (<FARM>)',
        desc = [[Sustain Forest, and Forest will sustain you.]],
      }

    else

      return {
        ..rep,
        short = 'Farms (<FARM>)',
        desc = [[Not ideal, but you are trying to enrich the land. Thank you.]],
      }

    end
	
	end
end
If I remove the IF clause for the Gaiad, all seems to be well. When the clause is there, going to a planet with Gaiad produces this error:

Code: Select all

Mods\Lua state\Galaxy\RaceIssues.lua:289: attempt to perform arithmetic on field 'farms' (a nil value)
Mods\Lua state\Galaxy\RaceIssues.lua:289:issue_fun:
 Mods\Lua state\Galaxy\pop_morale.lua:136:
  Mods\Lua state\Galaxy\pop_morale.lua:122:calc_morale_issues:
   Mods\Lua state\Galaxy\pop_morale.lua:159:calc_race_morale:
    Lua state\Galaxy\apply_morale_effects.lua:327:calc_rebel_defender_power
Lua state\debuggee\debugtest.lua:70: looks like visual studio isn't setup to receive file open hints.
Lua state\debuggee\debugtest.lua:70:meta_debug_file_and_line:
 Lua state\@@util\~exception_callbacks.lua:31:
  Lua state\GUI\@EventDispatcher.lua:287:~exception_callbacks.lua:43:
   Lua state\GUI\~GalaxyMap\GalaxyMap.lua:707:
    Lua state\GUI\new_screen_layout.lua:94
Now, I've actually done a bit of troubleshooting.

If I remove the if clause for the Gaiad, everything works.

If I take the working file, Lummox and not Gaiad, and change the text "lummox" to "gaiad" so it's using the same IF clause, I get the same crash.

It is not the fact that two races are in the same function. I have Scavengers and Orthin on the same planet getting science lab modifications. (Editing universe for testing, so things are odd.) I also have Humans and Tacheed Tacheed both getting City Planning bonus on the same planet, using the same function.

It is also not the Unruly trait, unless it only affects positive events.

I'm using Pell as a testing ground, and the population is currently:
pell = 8.7795509999999996609,
haduir = 3.3105919999999993131,
phidi = 3.8954380000000004003,
teros = 4.0167309999999973869,
orthin = 2.7801499999999998991,
algorian = 1,
lummox = 1,
gaiad = 1,

None of those are my races, so it should not be an issue with one of mine not being able to fight, but I don't know why there would be conflict. I do have a slightly modded pop_morale.lua file, but that section of the file was not touched. I have only added my races to the section near the top that indicates what races can become "unhappy".

To my technically ignorant view, it really looks as if the Gaiad are not good hippies and cannot be made to like farms. How else would they get their artisanal vegan soy cheese substitute?

Any help, suggestions, or insights would be greatly appreciated. Thank you.

EDIT: It's not the Insurgent trait, I tried commenting it out.
I've also had the same issue with mines. As of now, Tzidpah get annoyed by mines on their planet, with a message that it damages their only breeding pools. I copy the same IF clause and change it to gaiad, and the game crashes as soon as I open a system with Gaiad colonists.

Also, the happiness effect from mines is a negative and farms is a positive, but both fail.


EDIT 2: So, it looks as if you can only assign one suffix in race_improvement_morale_bonuses in RaceIssues.Lua. The last one sticks, if I am reading my successes and failures correctly.

If I am correct, that means the races get one modifier, good or bad.

That's a bit disappointing, but I guess I will have to scale back my plans and be very selective. It can still make things interesting, though.
akkamaddi
Posts: 147
Joined: Tue Sep 26, 2017 5:11 am

Re: Experimenting with happiness

Post by akkamaddi »

So, today has involved learning. :ugeek:

The happiness changes I've made has been this:

City planning gives refugees +20 happiness, but regular human colonists only +10 happiness (with the note "We will build a new homeworld for our children...".)

Spice Mongers get +2 morale modifier from Markets (+2 over base), and I've altered the coin file so they should produce +2 gold, the same way Phidi get (much) better market effects.

Scavengers get a -2 morale modifier from Markets, and they should produce -2 gold. "Why not just steal it?"

The Lummox get +1 morale per farm.

The Gaiad HAAAAATE the damage mining does to their planet, and get -4 morale per mine.



I have not modified Algorians yet. I am debating having markets give them a better morale bonus, but without the economic boost. Being able to buy better gifts for higher social status would make them happy, but it would likely not alter the economy.


Then, from my own races, the Abbizi get +2 morale per farm on the colony, while Tzidpah get -2 morale from mines damaging their spawning pools.


And now for testing.
gaerzi
Posts: 210
Joined: Wed Jul 10, 2019 1:30 pm

Re: Experimenting with happiness

Post by gaerzi »

Suggestions:

Gremak are happy when they have slaves around. Some possibilities, not sure what would work best:
- a flat bonus if there are any slaves at all?
- a flat bonus if there are at least as many slaves as there are Gremak?
- a +1 bonus per full unit of slave population?
- perhaps Enfi are valued over other slaves?

Teros are happy when they have orbital shipyards (+5?), space stations (+2?), and fleet bases (+3?)

Haduir are happy when they have a star gate (+8?)

Yoral are happy when they have strong defenses (planetary defenses +3/+5/+8?)


Also you have Gaiads hate markets as much as they hate mines. I'd have them hate mines the most (-4), and markets a bit less (-2), but I'd have them also hate labs and planetary defenses (perhaps just -1 each). They'd tolerate farms but prefer if the planet wasn't built up at all. However, so that there is something that would make them happy, I could see a +2 bonus for each different alien race present on the planet, as they love biodiversity. Except of course for tinkers and the harmonized, they should hate them as the soulless negations of nature that they are. :P
akkamaddi
Posts: 147
Joined: Tue Sep 26, 2017 5:11 am

Re: Experimenting with happiness

Post by akkamaddi »

Hello,

I actually had the same idea with the Gremak. Unfortunately, I have a little background in Java but am figuring out Lua as I clumsily stop through it. But, yes, I completely agree that Gremak should get a happiness bonus with from having slaves on the planet. There is a little more I want to do, so I will try to figure this out.

With the Gaiad, unfortunately, the situation is that you can only attach one modifier to the race. Basically, when you create the variable gaiad.mine then gaiad.market, the previous gaiad.mine no longer exists and trying to use it crashes the game.

I will see if I can do gaiadMine.mine, gaiadMarket.market, and gaiadFactory.factory, and if those work. It's too early to start coding now (someone woke me up blowing up my phone with room renovation pictures :roll: ), so I'm not sure if the variable gaiadMine.mine will properly apply to the Gaiad.

I have no idea what I'm doing, but it's fun when something works. :D

If that doesn't work, I will also try reducing the gaiad modifier to -2 and applying it to mines, factories, and markets. Basically, the Gaiad get angry when you do anything polluting and are not too keen on being bought off. If the game had a pollution mechanic, the ideal solution would be that their unhappiness would be directly tied to a fraction of pollution.

Also, with the mine vs. market, the market modification is subtracted from the happiness bonus of the market, which improves as you research better tech. With a -4 adjustment, the market bonus that is normally +8/+12/+16 drops to +4/+8/+12. A larger bonus works because you are reducing a large bonus, rather than starting from zero and going down.


With the main races, though, there is a very strong section of players here who want to keep things very balanced. That is why I've largely stuck with modifying the minor races. It gives them a lot more character. (I really want to make the Scavengers both thieves and afraid of science stations.) With modifications to the major races, we have to tread much more carefully.

I did make a change to the humans on my game because I really don't understand why colonial humans refugee humans get the same bonus for City Planing. I did keep a smaller bonus, though.

I also really do like the idea with the Gremak. In Stelaris, this is the population trait "Decadent", the pop is unhappy if there are no slaves on the planet, but happy if there are. I think a good modifier would be (-1) + (#SlavePop). If there are no slaves, the happiness is -1, and the bonus starts when there are two slave pops. The Gremak become more happy as you add more slaves, but there is a built in inhibitor in that too many slaves will revolt.
gaerzi
Posts: 210
Joined: Wed Jul 10, 2019 1:30 pm

Re: Experimenting with happiness

Post by gaerzi »

akkamaddi wrote: I actually had the same idea with the Gremak. Unfortunately, I have a little background in Java but am figuring out Lua as I clumsily stop through it.
Haha, yes, I really wish Lua had some good old C-style curly braces because all those "end" drive me mad. Worse is that the tabulation isn't extremely consistent in the files. If it were like Python then the whitespace could help figure out the logic but it's not and so when things are out of alignment it makes the code hard to read IMO.
akkamaddi wrote:With the Gaiad, unfortunately, the situation is that you can only attach one modifier to the race. Basically, when you create the variable gaiad.mine then gaiad.market, the previous gaiad.mine no longer exists and trying to use it crashes the game.
That's weird. I can't believe there isn't a way to make it work.
akkamaddi
Posts: 147
Joined: Tue Sep 26, 2017 5:11 am

Re: Experimenting with happiness

Post by akkamaddi »

gaerzi wrote: Haha, yes, I really wish Lua had some good old C-style curly braces because all those "end" drive me mad.
I use Notepad++ for my editing, and the nesting only goes so many layers. I've also found that having certain characters immediately after a function/end (specifically following the "end") is apparently a great affront to lua. It's possible it was a matter of the character encoding, but in the event file where, say, you enter the Tyl system and get the text for finding Gaia, I could add "-- #akkamaddi begin" before what I added, but having "-- #akkamaddi end" after that final "end" line would crash the game.
That's weird. I can't believe there isn't a way to make it work.
I think we are online at the same time. camelCase to the rescue!!! :mrgreen: I don't think I can change the market variable because it's used in several places. (I probably could, but I'd have to make lots of changes that would not be worth the effort.) However, scavenger.market and scavengerLabs.Labs gives you two different variables to work with
akkamaddi
Posts: 147
Joined: Tue Sep 26, 2017 5:11 am

Now with a post!

Post by akkamaddi »

This has not been heavily play tested, but everything should work. Sorry it's a MediaFire link.

LINK REMOVED (It now has it's own mod post, with a few updates)

There are only two lua files here, and not graphics.

To install this, while the game is closed, copy the two folders in the ZIP file (each contains one file) into the folder

\Stars in Shadow\Mods\Lua state

in the game folder. Start the game, and it will run using these two files.

It is save game complaint, but keep in mind that some planets may experience sudden unrest. Gaia will be different.

CHANGE LOG

I made a point to only change the minor races to give them flavor. A single change was made to a faction race.

Humans
In the official code, both refugees and humans (currently only humans are refugees) receive a +20 happiness bonus when the planet action is City Planing. In this change, refugees get a +20 happiness bonus, while colonial humans get a +10 happiness bonus (with different text). City Planing can no longer be used to instantly pacify an uprising human colony.

And the minor races:

Lummox
Thresher

Being primitives, they cannot fully benefit from markets. The happiness bonus for markets is reduced by 2 for both races.
Farms make them happy, as they know they will always have food. Each farm gives +1 happiness.

Scavenger
I am not entirely sure if this is done properly, and this is a bit kluegy. Scavengers should have a -4 on the coin value produces for markets, but a -4 then +2 modifier for happiness. This means there should be a difference between the financial and morale benefit of the Market.
Scavengers are also afraid of research structures, as they fear the destruction from the past will be repeated.

Tarib
Tarib get +1 happiness per mine on the planet, because they get yummy munchies.

Spice Monger
Spice mongers get +3 on the effect of Markets, making them a weaker version of Phidi.

Gaiad
So, the planet Gaia becomes much more difficult. The Gaiads do not want you there. For each Market, the base happiness modifiers is reduced by 4. Each Mine on the planet causes -4 happiness, and each factory causes -2 happiness. Each farm, though, increases happiness by +2. Essentially, the Gaiad don't want you there, get unhappy with nearly everything you do, and are difficult to please.



Possible updates:
I may make Algorians give +1 effect for Markets, as their gift giving society adjusts to a culture of plenty.
I may also have the planet action Mining cause a small negative for Gaiad happiness. It would make sense, but I am concerned about adding too many problems with their happiness.


Any thoughts or constructive criticism is very welcome.
Last edited by akkamaddi on Sun Aug 18, 2019 4:13 pm, edited 2 times in total.
User avatar
sven
Site Admin
Posts: 1621
Joined: Sat Jan 31, 2015 10:24 pm
Location: British Columbia, Canada
Contact:

Re: Experimenting with happiness

Post by sven »

akkamaddi wrote: EDIT 2: So, it looks as if you can only assign one suffix in race_improvement_morale_bonuses in RaceIssues.Lua. The last one sticks, if I am reading my successes and failures correctly.
The issue here (if you haven't figured it out already), is that Lua is a bit weirdly permissive about table declarations. If you write code like this:

Code: Select all

t = {a=1, b=2, a=2}
You'll probably get a table {a=2,b=2}, as the first declaration gets overwritten by the second. (In a more conservative language, the above code would throw an error, but the Lua authors decided to just let it pass without so much as a warning for some reason.)

So, expanding that out to the case in RaceIssues.lua, if you write:

Code: Select all

{
	phidi={farms=5},
	phidi={markets=5},
}
You'll end up losing the first "phidi=" section. But you're building a nested set of tables here, so the following should work:

Code: Select all

{
	phidi={farms=5,markets=5}
}
akkamaddi
Posts: 147
Joined: Tue Sep 26, 2017 5:11 am

Re: Experimenting with happiness

Post by akkamaddi »

sven wrote:You'll end up losing the first "phidi=" section. But you're building a nested set of tables here, so the following should work:

Code: Select all

{
	phidi={farms=5,markets=5}
}
So, I did figure it out, but I did not know about that notation.

My solution was:

phidi={market=5},
phidiFarms={farms=5},
phidiMines={mines=5},

While I think my way is a little easier to read, the proper way you show is definitely cleaner and easier to manage.

And, I really appreciate the response. Thank you. :)
Post Reply