Question about defines.entity_status.no_fuel

Place to get help with not working mods / modding interface.
Pi-C
Smart Inserter
Smart Inserter
Posts: 1757
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Question about defines.entity_status.no_fuel

Post by Pi-C »

I've got a tank which has an empty fuel directory and is not burning any fuel. There is a no-fuel icon indicating that the tank, indeed, has no fuel. But when I print the tank's status with

Code: Select all

/c v = game.player.vehicle; states = {}; 
    for name, id in pairs(defines.entity_status) do states[id] = name end
    game.print("Status: "..states[v.status])
I get

Code: Select all

Status: working
no-fuel.png
no-fuel.png (784.43 KiB) Viewed 593 times
Why does that happen? Is defines.entity_status.no_fuel not supposed to work with vehicles? In the API description, most states come with a description like "Used by generators and solar panels", but no such limitation is given for no_fuel, so I'd expected this to work with all entities that could consume fuel -- including car prototypes.

If this is working as intended, how can I determine whether a vehicle (car and spider-vehicle prototypes) has no fuel left? Checking for an empty fuel inventory is trivial, the hard part is the fuel currently burned (shown by the bar next to the fuel inventory slots).

Use case: My mod sends unarmed vehicles into a panic mode when enemies are near, so they speed off into a random direction. But that doesn't make sense for vehicles that are completely out of fuel. Deciding that a vehicle has no fuel based solely on whether its fuel inventory is empty doesn't make sense because some fuel (nuclear, rocket etc.) lasts for an incredibly long time. So, a tank could still cover some considerable distance with 20% of a rocket-fuel cell left for burning -- even if the fuel inventory was empty.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Pi-C
Smart Inserter
Smart Inserter
Posts: 1757
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Question about defines.entity_status.no_fuel

Post by Pi-C »

Something strange is going on! It seems the entity has come into a bad state somehow. I placed down a new car and a new tank and everything worked as expected. Then I removed my mod and put down a crawler. The status change between "no_fuel" and "working" when I inserted or removed fuel from the inventory. Once I was driving it and it ran out of fuel, it remained in the "working" state.

I've attached a saved game where you can see this for yourself: There are four different vehicles lined up in front of you, and you have four pieces of wood in your cursor.
  1. Insert one into each vehicle's fuel inventory (status changes from "No fuel" to "Working).
  2. Remove the wood from a vehicle (status changes from "Working" to "No fuel"), then insert it again. Repeat with all other vehicles.
  3. Get into a vehicle, click on it to open its inventory, then drive straight ahead until the wood has been used up. Keep note of the status message.
  4. Use

    Code: Select all

    /c game.player.teleport{10,0}
    to get back to the other vehicles.
  5. Go back to 3. until you've moved all vehicles.

Could there be something wrong with the prototype definition? There was nothing obvious when I compared the definitions in data.raw.car.car and data.raw.car.crawler. Also, what could have caused the tank I've used with my mod to get into the wrong state, where it would always be "working"?
Attachments
no-fuel-test.zip
(1.42 MiB) Downloaded 42 times
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Post Reply

Return to “Modding help”