Railcraft

Railcraft

34M Downloads

NeedsRefuel doesn't make sense

mcclurej06 opened this issue ยท 2 comments

commented

Routing tables evaluate "NeedsRefuel" to true too often. From the code posted in issue #151, a locomotive will need fuel if any of its stacks are below 25% of their max stack size. For instance, if I fill a locomotive with 4 stacks of charcoal, then it will need to refuel after 48 pieces of charcoal have been used, and still has 208 pieces (~81%). Half of the water tank also seems a little high. Not sure what a good value would be, but it would be nice if it was user controlled in some way.

commented

Unfortunately there is no good way to determine what refueling really means from the routing script side. Every locomotive must make that decision for themselves, and each type of locomotive will have different rules (when they get added).

But you're right about the stack size thing. I should probably add the max stack sizes up then compare that against the current number of total items.

commented

New Code

    public boolean needsRefuel() {
        FluidStack water = tankWater.getFluid();
        if (water == null || water.amount < tankWater.getCapacity() / 3)
            return true;
        int numItems = InvTools.countItems(invFuel);
        if (numItems == 0)
            return true;
        int maxItems = InvTools.countMaxItemStackSize(invFuel);
        return (double) numItems / (double) maxItems < 0.25;
    }