Tuesday, August 17, 2021

Project Zomboid's Least Important Bug! (Infinite Fuel Isn't Infinite)

I am here to declare that *I*, PseudonymousEd, have discovered...


Infinite Fuel Isn't Infinite

(You probably read the title before you read this, so you probably knew I was going to say all that)

As I'm sure you all know, in build 41.51 Project Zomboid switched to having finite fuel in the fuel pumps.  It seemed like pretty big news when they announced it.

But there is a Sandbox setting that allows us to set the amount of initial fuel available, and one of the options is "Infinite".  Unfortunately, it doesn't work.

Here's the 41.53 code, in a decompiled IsoObject.class

    public int getPipedFuelAmount() {
        Object object;
        if (this.sprite == null) {
            return 0;
        }
        double d = 0.0;
        if (this.hasModData() && !this.getModData().isEmpty() && (object = this.getModData().rawget((Object)"fuelAmount")) != null) {
            d = (Double)object;
        }
        if (this.sprite.getProperties().Is("fuelAmount")) {
            if (SandboxOptions.instance.FuelStationGas.getValue() == 7) {
                return 1000;
            }
            if (d == 0.0 && (SandboxOptions.getInstance().AllowExteriorGenerator.getValue() && this.getSquare().haveElectricity() || GameTime.getInstance().getNightsSurvived() < SandboxOptions.instance.getElecShutModifier())) {
                float f = 0.8f;
                float f2 = 1.0f;
                switch (SandboxOptions.getInstance().FuelStationGas.getValue()) {
                    case 1: {
                        f2 = 0.0f;
                        f = 0.0f;
                        break;
                    }
                    case 2: {
                        f = 0.2f;
                        f2 = 0.4f;
                        break;
                    }
                    case 3: {
                        f = 0.3f;
                        f2 = 0.5f;
                        break;
                    }
                    case 4: {
                        f = 0.5f;
                        f2 = 0.7f;
                        break;
                    }
                    case 5: {
                        f = 0.7f;
                        f2 = 0.8f;
                        break;
                    }
                    case 6: {
                        f = 0.8f;
                        f2 = 0.9f;
                        break;
                    }
                    case 7: {
                        f2 = 1.0f;
                        f = 1.0f;
                    }
                }
                d = (int)Rand.Next((float)((float)Integer.parseInt(this.sprite.getProperties().Val("fuelAmount")) * f), (float)((float)Integer.parseInt(this.sprite.getProperties().Val("fuelAmount")) * f2));
                this.getModData().rawset((Object)"fuelAmount", (Object)d);
                this.transmitModData();
                return (int)d;
            }
        }
        return (int)d;
    }

So basically, as long as this item is supposed to have fuel (is a fuel pump)...

If SandboxOptions is set to 7, the fuel is always 1000.  Voila!  Infinite fuel!

Except... There are 8 sandbox options.  Infinite is #8.

And this isn't one of those start counting from 0 situations.

So instead of Infinite fuel giving you 1000 fuel, Full is always returning 1000 fuel.

If you have infinite fuel you are instead getting a random number between 0.8 and 1.0 of the maximum fuel amount.  Because it gets set before the switch and there is no case 8 so it doesn't get reassigned before the actual fuel amount is randomly determined between the given range.

It's pretty easy to figure out why this is such an unimportant bug.

We don't have multiplayer yet.

If anyone has actually selected infinite fuel, they are getting around 14,000 units of fuel.  That's 1750 cans of gas out of one pump.  If you are driving around all day and your base has 2 fridges and 4 freezers, maybe you need 4 cans a day to support that.  That's still more than 400 days of gas if you are using only one pump.  Has anyone even reached 400 days since 41.51 was released?  Twitch streamer RoyaleWithCheeseTV plays PZ on most days and he streams 10+ hours a day and hasn't reached 400 days in 41.51+ (or even 200 days on his current run using 2 hour days).

And how many people even know how much fuel they have in their pumps?  I think my mod, How Much Fuel, is the only way for normal people to know how much fuel is in a pump.  I have 3,671 subscribers.


And as soon as Indie Stone fixes this bug, all saved games with infinite fuel set will immediately actually have infinite fuel in their pumps.

I challenge anyone to find a bug less impactful than this one.  Even a typo in a tooltip is worse than this - a lot of people can see a typo.

(Until multiplayer is released, that is.  But even then it will be a while before people would actually find their infinite pumps aren't infinite)

Yes, I did report the bug.  And while I assert this is the least important bug in the game, it is actually a bug.  I've read through many bug reports that are just user error.  Or misinterpretations of what should be happening.  Or are just opinions.  

**

I'll add one somewhat snarky java note:

This is a textbook case of why you use enums.  I'm not a decompiler expert, it is possible the original java did use enums and the compiler/decompiler process removed them, but that would probably mean someone forgot that there were different FULL and INFINITE options.  Or maybe this was very quickly coded and there was no code review.  But this is the kind of situation enums were designed to prevent (whether or not the original code used them).

5 comments:

  1. What decompiler do you use? I tried JD, and it doesn't open any of the .class files.

    ReplyDelete
  2. Whenever taken in a right measurements, 'recreation' will back out the mounting tensions and pressures which creep into our internal identity due to the cutting edge approach to everyday life.
    https://www.snakeeaterperformance.com/

    ReplyDelete
  3. It ought to be perceived that generally 'wellbeing' is 'riches' and for keeping up with sound wellbeing psyche and body, 'recreation' is an unquestionable necessity.
    aftermarket car parts

    ReplyDelete
  4. Recreation just means utilization of your time either in imaginative, or relaxation or sports exercises, where the soul of cooperation is more than the outcome, so the whole cycle turns out to be great for the psyche and the body.
    Bosch Injectors

    ReplyDelete
  5. Propane-powered vehicles have lower maintenance costs than gasoline vehicles.
    Residential Propane Service

    ReplyDelete

Do Gloves Protect You From Broken Glass?

Yes, gloves protect you from handling broken glass - any pair of gloves.  But gloves are not needed when removing broken glass from a smashe...