RELEASED Happy Animals 1.0

Discussion in 'Livestock' started by StarPeanut, Nov 5, 2016.

  1. StarPeanut

    StarPeanut 2.7182818284590...

    I hacked together a small mod to try to work around some bugs that several of us have recently identified with the animal happiness mechanic. This mod does two things:

    1. Some animals don't have a "deluxe produce" item, like Sheep (there's no "large wool"). For those animals, this mod sets the "deluxe produce" to be the same as the "normal produce" so that if the game rolls deluxe produce those animals will still produce their usual thing.

    2. Happiness is totally broken. This mod sets happiness overnight to almost maximum (technically, 255 - 2 * happinessDrain). As long as you pet and feed your animals, this will result in their happiness ending up at the max value when the code runs that decides what produce you get. If you fail to pet or feed your animals, their happiness will be lower, and you'll take a penalty to production.

    I've literally spent less than half an hour working on this and have only tested it a bit with one save, so there may be issues. Please let me know if you find anything not behaving as expected and I'll be happy to take a look! :)

    Installation Instructions: Unzip to your Stardew Valley mods folder.
     

      Attached Files:

      Last edited: Nov 6, 2016
      Ceter, Charza, chenjohn0329 and 14 others like this.
    • StarPeanut

      StarPeanut 2.7182818284590...

      Hmm. Oops, looks like this only works for animals that are outside, not ones that are inside. Fixing...
       
      • StarPeanut

        StarPeanut 2.7182818284590...

        Alright, I've updated the OP with version 1.0.1, which should fix all animals, not just the ones you leave outside overnight. Oops. Sorry!
         
        • StarPeanut

          StarPeanut 2.7182818284590...

          One more tiny update: OP now has version 1.0.2. In 1.0.1 I was incorrectly docking happiness after the daily produce roll (in addition to before the roll), so if you checked your animals' happiness right after you woke up you'd see them at ~95% rather than 100%. This wasn't affecting the produce rolls, but it looked silly, and now it's fixed. You should now see them at 100% happiness each morning as long as they were fed and petted the previous day.
           
          • nevyn21

            nevyn21 Cosmic Narwhal

            Does this fix sheep, pig, and dinosaur production at high happiness with the deluxe produce bug?
             
            • StarPeanut

              StarPeanut 2.7182818284590...

              Yes, that should be fixed too!
               
                nevyn21 likes this.
              • SunTide

                SunTide Scruffy Nerf-Herder

                I was wondering how you were going to deal with the issue of detecting when animals go to sleep. This is a good workaround.

                We may want to discuss future design, if you want to further refine this mod. AS you know the formula for happiness bonus is:
                1) happiness*(-2) if happiness is 200 or less
                2) happiness*2 is happiness is greater than 200

                Which is a non-sensiscal formula, as we have discussed to death in the animal mechanics thread.

                This mod (more of a patch, really) works around this bizarre formula by always keeping the score on the 200+ side, but we will probably want to eventually move to a more complete solution. Assuming that's a thing that happens, what is a good replacement formula? bonus = (happiness -200) is a start, in that it retains 200 as the tipping point, but it reduces the impact of very happy animals. This might even be a good thing, I'm not sure.

                Other ideas?
                 
                • StarPeanut

                  StarPeanut 2.7182818284590...

                  Unfortunately, I don't think SMAPI lets you modify game code, it just lets you add your own code that runs when certain events occur. That's why I "fixed" this the way I did, by adding some code that triggers before CA's code for updating animal happiness and producing goods at the start of a new day. SMAPI doesn't provide a way to change the happiness bonus code that CA wrote, or to change the buggy code that causes happiness to roll over from the max value to zero, or anything like that. If it did, I'd happily rip out the entire implementation of farm animals and replace it with a new one that makes more sense. :)
                   
                  • StarPeanut

                    StarPeanut 2.7182818284590...

                    Hmm. Actually, thinking out loud a bit more: I suppose it might be possible to write a mod that just completely replaces the logic for generating animal produce with some new logic of our own. I bet I could, in a mod, change some properties of the animal such that the built-in logic would *never* produce anything, and then the mod could generate its own produce.

                    This still wouldn't be able to fix the happiness rollover bug, though, so if you pet your animals in the wrong order (i.e., before they ate grass) you'd still end up with low happiness and any new formula we could come up with that's based on happiness would be affected.

                    You could then imagine a mod that has its own happiness system... yeah, maybe that could work. That's starting to sound like a lot of effort, though. Personally, I think I'll stick with this simple approach for now. :)
                     
                    • nevyn21

                      nevyn21 Cosmic Narwhal

                      I tried you mod and got gold and iridium products out of all my cows, chickens and goats but not one of my 60 sheep produced anything.
                       
                      • StarPeanut

                        StarPeanut 2.7182818284590...

                        Ah, I see the problem. My fix for the bug where animals like sheep produce nothing when happy will only affect animals born after the mod is installed. I'm working on a fix for that now to cover the existing animals -- stay tuned!
                         
                          foghorn and nevyn21 like this.
                        • nevyn21

                          nevyn21 Cosmic Narwhal

                          I'm curious how that even works but after seeing some of the other bugs I'm sure it would just make me headdesk again.
                           
                          • StarPeanut

                            StarPeanut 2.7182818284590...

                            Alright, OP updated with mod version 1.0.3, which should fix the bug where overly happy animals never produce anything, and should fix it for all your existing animals this time, not just new ones. I was able to get my sheep to all produce after three days (sheep produce at most every 3 days unless you go down the animal skill tree, which I didn't, in which case it's at most once every 2 days) -- please try it out and let me know if it works! :)
                             
                            • StarPeanut

                              StarPeanut 2.7182818284590...

                              Ah, this one isn't so headdesky, actually. The problem is that I was trying to fix the bug by modifying FarmAnimals.xnb to set the deluxe produce index for sheep etc. to a sane value, but the problem is that the configuration values from that file are only read when an animal is born. For animals that were already born before you installed my mod, they already have the wrong values from the config file that ships with the game, and no amount of editing that file will help. I fixed this by putting some code in the mod that modifies the value overnight for all animals instead, which will catch ones that were born earlier too.

                              As a nice side effect, the mod no longer needs to modify FarmAnimals.xnb. It's now just a plain old mod that goes in your Mods directory, like everyone else's mods. I've updated the instructions in the OP to reflect that.
                               
                                nevyn21 likes this.
                              • StarPeanut

                                StarPeanut 2.7182818284590...

                                Oops, the last zip file I uploaded was missing a critical file that's part of the mod (the manifest file). Fixed!
                                 
                                • nevyn21

                                  nevyn21 Cosmic Narwhal

                                  Yes! It works perfectly now. Every one of my 60 sheep produced the morning after I installed it. Thank you!

                                  [​IMG]
                                   
                                    ZephyrWindSpirit and StarPeanut like this.
                                  • nevyn21

                                    nevyn21 Cosmic Narwhal

                                    In case you miss it in the other thread, here's a day of production pre-mod and post-mod:

                                    Pre-mod 29/60 Sheep

                                    Typical Daily Production Pre-mod.jpg

                                    Post mod 60/60 Sheep

                                    Daily Production Post-Mod.jpg
                                     
                                    • StarPeanut

                                      StarPeanut 2.7182818284590...

                                      Yay! Glad it's working for you now. :) Thanks for helping me test and for finding the bug with animals that had already been born.
                                       
                                        nevyn21 likes this.
                                      • cidrei

                                        cidrei Void-Bound Voyager

                                        I don't know which events you can catch with SMAPI, but it at least appears to be possible to set values like animal happiness. Would it be possible to catch the events (animal fed, animal pet, etc) and keep track of what happiness should be, prevent it from rolling over if need be and set it each night accordingly?
                                         
                                        • StarPeanut

                                          StarPeanut 2.7182818284590...

                                          The list of available events is here:
                                          http://canimod.com/guides/creating-a-smapi-mod#available-events

                                          There's no event for being fed or petted, but you could approximate this by listening to something like the OneSecondTick and checking each animal's values to watch for changes over time.

                                          So, yes, I believe it should be possible to create a fancier version of this mod that implements a more nuanced approach to happiness.
                                           

                                          Share This Page