Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - Homez

#1
I know decompiling the source code is common practice in the RW mod community, and it's specifically allowed in the RW EULA. https://rimworldgame.com/eula/

QuoteYou're allowed to 'decompile' our game assets and look through our code, art, sound, and other resources for learning purposes, or to use our resources as a basis or reference for a Mod. However, you're not allowed to rip these resources out and pass them around independently.

My question is this: are we allowed to post decompiled source code on these forums?
#2
Tried to include System.Reactive but discovered it isn't compatible with Mono. Does anyone here use any good Reactive implementations? I've heard of UniRx and will be giving it a shot, but if you have thoughts, suggestions, warnings, threats, or experience I'd love to hear them.
#3
Normally, if all your colonists are downed, the man in black (hereafter MiB) shows up. If your colonists and the MiB all die, the Game Over modal pops up.

However, if your colonists die and the MiB is kidnapped, the Game Over modal does not show and the game does not end.

This happened to me while I was testing a mod (which would have been kinda funny if I wasn't brain dead from staring at C#). I then disabled all mods and reproduced it in the test map by debug downing all my colonists, then after the MiB shows up, debug killing the colonists and debug kidnapping the MiB.

The attached save file is saved after the MiB has been kidnapped. It's a sad, lonely little save.
#4
Batteries self-discharge at 3.66W instead of 5W, but the issue is really much bigger. I believe this is a sort of rounding error due to the limitations of the float datatype that could impact the power system in other places besides just the battery building.

If you have an isolated battery fully charged with 600Wd of energy, it will self-discharge. The stated rate is 5W, meaning if you leave the battery alone, neither supplying energy nor consuming its energy, it will have 595Wd of energy after 1 day (60,000 ticks). This is not the case. In actuality, after 60,000 ticks, it will have about ‭596.34‬Wd of energy. This phenomenon can be trivially replicated by executing the following function anywhere in RimWorld:

private void SimulateBatterySelfDischarge()
        {
            float batteryStartingEnergyFloat = 600f;
            float energyFloat = batteryStartingEnergyFloat;

            decimal batteryStartingEnergyDecimal = 600m;
            decimal energyDecimal = batteryStartingEnergyDecimal;
            const decimal WattsToWattDaysPerTickDecimal = 1.66666669E-05m; // same value as CompPower.WattsToWattDaysPerTick, but as decimal

            int ticksInOneDay = 60000;

            for (var i = 0; i < ticksInOneDay; i++)
            {
                energyFloat -= 5f * CompPower.WattsToWattDaysPerTick;
                energyDecimal -= 5m * WattsToWattDaysPerTickDecimal;
            }

            Log.Message("After one simulated day (60,000 iterations):");
            Log.Message("Self-discharge when using float: " + (batteryStartingEnergyFloat - energyFloat));
            Log.Message("Self-discharge when using decimal: " + (batteryStartingEnergyDecimal - energyDecimal));

            Log.Message("Without the loop, float: " + (5f * CompPower.WattsToWattDaysPerTick * ticksInOneDay));
            Log.Message("Without the loop, decimal: " + (5m * WattsToWattDaysPerTickDecimal * ticksInOneDay));
        }


The energyFloat -= 5f * CompPower.WattsToWattDaysPerTick line is taken, with slight modification, from CompPowerBattery.CompTick(); it's the line responsible for the self-discharge.

After running that code, you'll notice that the decimal values are exactly as you'd expect: 5Wd have been discharged. batteryStartingEnergyDecimal - energyDecimal is 5. But the float value from batteryStartingEnergyFloat - energyFloat is 3.66.

Something about looping and performing that arithmetic on a float is causing a rounding error. Just for fun, I included Log.Message("Without the loop, float: " + (5f * CompPower.WattsToWattDaysPerTick * ticksInOneDay)) to verify it is, in fact, the loop causing the issue. If you do the daily discharge all at one time with 5f * CompPower.WattsToWattDaysPerTick * ticksInOneDay you get 5 right on the money.

If this isn't sufficient proof, I created a MapComponent class that will perform this experiment using real batteries and the real tick loop. See attached for the class. The results are exactly the same.

If you'd like to run it, you'll need a mod to drop the class into, then start the RimWorld testing map, pause immediately, go into god mode, spawn a battery, set it to full, and wait a few days. The log will print out, demonstrating this issue does exist in the game. I included the simple loop test in the file, too, for your amusement edification. Also included a picture of the real battery test in the attachments.

Also, this is my first post and I just started modding. Please be gentle.