[MOD 0.16] Diesel Locomotive

Topics and discussion about specific mods
User avatar
BlueTemplar
Smart Inserter
Smart Inserter
Posts: 2420
Joined: Fri Jun 08, 2018 2:16 pm
Contact:

Re: [MOD 0.16] Diesel Locomotive

Post by BlueTemplar »

It really sounds like these fuel values should be handled by vanilla...
- like they once were ?
(from 0.16.51 fluid.lua, emphasis mine)

Code: Select all

{
    type = "fluid",
    name = "crude-oil",
    default_temperature = 25,
    heat_capacity = "0.1KJ",
    base_color = {r=0, g=0, b=0},
    flow_color = {r=0.5, g=0.5, b=0.5},
    max_temperature = 100,
    icon = "__base__/graphics/icons/fluid/crude-oil.png",
    icon_size = 32,
    pressure_to_speed_ratio = 0.4,
    flow_to_energy_ratio = 0.59,
    -- fuel_value = "8MJ", <=============================
    order = "a[fluid]-b[crude-oil]"
  }
(this might pre-date to fluid scaling, making it equivalent to 0.8 MJ/L in 0.16 or 0.4 MJ/L in 0.17 ?)

Or at least it should be a "community" mod, like https://mods.factorio.com/mod/stdlib

P.S.: See also :
Bob's Mods, 0.16 : "Planned: Fuel values on fluids and Hydrogen balance. Give opinions."
BobDiggity (mod-scenario-pack)

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2530
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: [MOD 0.16] Diesel Locomotive

Post by FuryoftheStars »

Well, the locomotive can’t use the fluids directly. What has to happen is as fluid is added (or removed), it creates an item out of the fluid and puts that into the locomotive, assigning fuel values and the like to the item.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

User avatar
BlueTemplar
Smart Inserter
Smart Inserter
Posts: 2420
Joined: Fri Jun 08, 2018 2:16 pm
Contact:

Re: [MOD 0.16] Diesel Locomotive

Post by BlueTemplar »

Oh. Well, in any case, wouldn't it make sense for that item to have the same chemical energy as the fluids consumed ?
(Have you looked into using thermal energy for potential steam locomotives ?)

P.S.: Reminds me also of : https://mods.factorio.com/mod/BurnBarrels
Now working with:

light-oil.fuel_value = "1.2MJ"
petroleum-gas.fuel_value = "0.6MJ"
heavy-oil.fuel_value = "0.6MJ"
heavy-oil-barrel.fuel_value = "30MJ"
light-oil-barrel.fuel_value = "60MJ"
petroleum-gas-barrel.fuel_value = "30MJ"
BobDiggity (mod-scenario-pack)

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2530
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: [MOD 0.16] Diesel Locomotive

Post by FuryoftheStars »

Yes, that’s what I attempted to do originally, but I made a mistake thinking solid fuel only required 10 units of heavy oil, so I gave its item equivelant for the locomotive the same as light. Just wanted some additional feed back before I slashed the value in half.

I do, though, for this mod, add a little extra to the fluid fuel values to be representative of energy loss in the conversion process (to solid fuel).
BlueTemplar wrote:
Sat Jul 13, 2019 3:39 pm
(Have you looked into using thermal energy for potential steam locomotives ?)
Based on the methods that have to be used in order to get the locomotive to “consume” fuel, something like this would also be hacky and we wouldn’t be able to use the principle of thermal energy directly.

That said, I have had ideas in my head to try and allow this, but I don’t have it worked out yet and would be a separate add-on mod.
Last edited by FuryoftheStars on Sat Jul 13, 2019 5:47 pm, edited 1 time in total.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

User avatar
BlueTemplar
Smart Inserter
Smart Inserter
Posts: 2420
Joined: Fri Jun 08, 2018 2:16 pm
Contact:

Re: [MOD 0.16] Diesel Locomotive

Post by BlueTemplar »

There's been some discussion about them in Bob's Mods :
viewtopic.php?p=439844#p439844
BobDiggity (mod-scenario-pack)

DTSephiroth
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sat Jan 05, 2019 2:28 pm
Contact:

Re: [MOD 0.15] Diesel Locomotive

Post by DTSephiroth »

Optera wrote:
Wed Jun 21, 2017 8:56 am
You have to add a condition for using KS-Power or anyone not having it installed will get an error when your mod tries referencing fluids from that mod.

Code: Select all

if data.raw.fluid["diesel-fuel"] then
  USABLE_FLUID["diesel-fuel"] = {
    fuel_value = "2500KJ",
    fuel_acceleration_multiplier = 1.8,
    fuel_top_speed_multiplier = 1.15
  }
Do you know if this fix works in 0.17 as well? I use KS Power because I love Diesel generators.

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2530
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: [MOD 0.15] Diesel Locomotive

Post by FuryoftheStars »

DTSephiroth wrote:
Thu Jul 18, 2019 3:51 am
Optera wrote:
Wed Jun 21, 2017 8:56 am
You have to add a condition for using KS-Power or anyone not having it installed will get an error when your mod tries referencing fluids from that mod.

Code: Select all

if data.raw.fluid["diesel-fuel"] then
  USABLE_FLUID["diesel-fuel"] = {
    fuel_value = "2500KJ",
    fuel_acceleration_multiplier = 1.8,
    fuel_top_speed_multiplier = 1.15
  }
Do you know if this fix works in 0.17 as well? I use KS Power because I love Diesel generators.
I have the fix in there differently so it should work with any mod adding diesel fuel, not just ks power, but I did test this against ks power and from what I could tell it worked. Please let me know if you run into any issues! :)
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

User avatar
Shenpen
Fast Inserter
Fast Inserter
Posts: 227
Joined: Sat Aug 27, 2016 2:46 pm
Contact:

Re: [MOD 0.16] Diesel Locomotive

Post by Shenpen »

What would I need to change for my diesel to be acceptable as fuel in these locomotives?
(from Factorio Bitumen mod).

Code: Select all

{
type = "fluid",
    name = "diesel",
    icon = "__bitumen__/graphics/icons/diesel64.png",
	icon_size = 64, scale = 1,
	default_temperature = 25,
    heat_capacity = "1KJ",
    base_color = {r = 1, g = 1, b = 0.3},
    flow_color = {r = 1, g = 1, b = 0.3},
    max_temperature = 100,
	pressure_to_speed_ratio = 0.4,
    flow_to_energy_ratio = 0.59,
	
},

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2530
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: [MOD 0.16] Diesel Locomotive

Post by FuryoftheStars »

Shenpen wrote:
Mon Jul 29, 2019 3:41 pm
What would I need to change for my diesel to be acceptable as fuel in these locomotives?
(from Factorio Bitumen mod).

Code: Select all

{
type = "fluid",
    name = "diesel",
    icon = "__bitumen__/graphics/icons/diesel64.png",
	icon_size = 64, scale = 1,
	default_temperature = 25,
    heat_capacity = "1KJ",
    base_color = {r = 1, g = 1, b = 0.3},
    flow_color = {r = 1, g = 1, b = 0.3},
    max_temperature = 100,
	pressure_to_speed_ratio = 0.4,
    flow_to_energy_ratio = 0.59,
	
},
Hopefully nothing. Have you given it a try? It is setup to only work with 1 mod added diesel fuel, so (for example) if someone was to use your mod and ks power, which ever it finds first will win out. I can see about improving this, it would just add more items and complicate the code a little bit more.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

User avatar
Shenpen
Fast Inserter
Fast Inserter
Posts: 227
Joined: Sat Aug 27, 2016 2:46 pm
Contact:

Re: [MOD 0.16] Diesel Locomotive

Post by Shenpen »

Indeed. Works fine with no changes.
diesel-loco.png
diesel-loco.png (1004 KiB) Viewed 3283 times
"It is setup to only work with 1 mod added diesel fuel, so (for example) if someone was to use your mod and ks power, which ever it finds first will win out. "

In case of KSP diesel and FB diesel both having the fluid name "diesel", would they not then actually be the same fluid, but originating from different recipes?
Last edited by Shenpen on Mon Jul 29, 2019 4:17 pm, edited 1 time in total.

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2530
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: [MOD 0.16] Diesel Locomotive

Post by FuryoftheStars »

Shenpen wrote:
Mon Jul 29, 2019 3:59 pm
It is setup to only work with 1 mod added diesel fuel, so (for example) if someone was to use your mod and ks power, which ever it finds first will win out.

In case of KSP diesel and FB diesel both having the fluid name "diesel", would they not then actually be the same fluid, but originating from different recipes?
Yes, that is correct. Sorry, should've defined what it's searching for better. It looks for any fluid with the word "diesel" in the name, so while your fluid "diesel" is obviously an exact match, it will also match on "diesel-fuel" if someone adds it like that.

Also, it currently does not use the fuel values from the mod added fluid and instead uses internal values (it won't affect your fluid directly, though. Only its use in the locomotive). This was because everyone would have their own idea of what fuel value, etc it should have and I wanted to make sure its use in the diesel locomotives was consistent compared to the other acceptable fluids.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

User avatar
Shenpen
Fast Inserter
Fast Inserter
Posts: 227
Joined: Sat Aug 27, 2016 2:46 pm
Contact:

Re: [MOD 0.16] Diesel Locomotive

Post by Shenpen »

So in theory you could make a furnace or a boiler that could run if supplied by a pipeline of fuel-oil or methane?

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2530
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: [MOD 0.16] Diesel Locomotive

Post by FuryoftheStars »

Yes, actually they've already implemented that in vanilla code (with 0.17.0, I think), just not actually used in vanilla. However, as far as I'm aware, they didn't extended this to locomotives or cars, etc, so we still have to use a hacky method to get it to work (the mod essentially copies the solid fuel item and makes changes to create a "fake" fluid item for the locomotive to burn instead of the fluid directly).
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

User avatar
BlueTemplar
Smart Inserter
Smart Inserter
Posts: 2420
Joined: Fri Jun 08, 2018 2:16 pm
Contact:

Re: [MOD 0.16] Diesel Locomotive

Post by BlueTemplar »

More like 0.16.0 ?
Added FluidPrototype::fuel_value and Generator::burns_fluid.
----
Shenpen wrote:
Mon Jul 29, 2019 4:25 pm
So in theory you could make a furnace or a boiler that could run if supplied by a pipeline of fuel-oil or methane?
Yeah, see implementations in :
https://mods.factorio.com/mod/KS_Power
And Bob's mods :
2018-02-12 : Planned: Fuel values on fluids and Hydrogen balance. Give opinions.
BobDiggity (mod-scenario-pack)

User avatar
Shenpen
Fast Inserter
Fast Inserter
Posts: 227
Joined: Sat Aug 27, 2016 2:46 pm
Contact:

Re: [MOD 0.16] Diesel Locomotive

Post by Shenpen »

It will accept Kerosine but not actually run on that.
kerosine-loco.png
kerosine-loco.png (631.35 KiB) Viewed 3271 times

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2530
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: [MOD 0.16] Diesel Locomotive

Post by FuryoftheStars »

BlueTemplar wrote:
Mon Jul 29, 2019 5:05 pm
More like 0.16.0 ?
Added FluidPrototype::fuel_value and Generator::burns_fluid.
----
Shenpen wrote:
Mon Jul 29, 2019 4:25 pm
So in theory you could make a furnace or a boiler that could run if supplied by a pipeline of fuel-oil or methane?
Yeah, see implementations in :
https://mods.factorio.com/mod/KS_Power
And Bob's mods :
2018-02-12 : Planned: Fuel values on fluids and Hydrogen balance. Give opinions.
Actually, check the other thread. I found the 0.17.0 patch notes. Generator is a specific entity type that burns fuel for direct electricity output and is different from boilers.
Shenpen wrote:
Mon Jul 29, 2019 5:16 pm
It will accept Kerosine but not actually run on that.
Correct. I would have to manually add this fuel type into the mod. I suspect evildogbot100 created it that way initially so that the locomotive wouldn't run off from just any fluid type with a fuel_value.

Unfortunately, while fluid boxes have a filter = "" property to allow a specific fluid in, they don't have a fluids = {} to allow a specific set and thus I can't block you from putting water into it unless I made it so you could put only 1 fuel type in.

Edit: and sorry, should probably also say that I'm not sure on the value of further complicating the mod code and settings by adding more fuel types. I removed crude oil from the original version of the mod.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

User avatar
Shenpen
Fast Inserter
Fast Inserter
Posts: 227
Joined: Sat Aug 27, 2016 2:46 pm
Contact:

Re: [MOD 0.16] Diesel Locomotive

Post by Shenpen »

I would have to manually add this fuel type into the mod.
Not necessarily. I was able to get KS Power to accept a range of fuels by adding a *version* of the data-update.lua in the mod:

Code: Select all

local fuel_values = {
  ["crude-oil"] = "1.4MJ",
  ["light-oil"] = "1.5MJ",
  ["heavy-oil"] = "1MJ",
  ["petroleum-gas"] = "1.5MJ",
  ["diesel"] = "2MJ",
  ["liquid-kerosine"] = "2MJ",
  ["fuel-oil"] = "2MJ",
  ["gasoline"] = "2MJ",
  ["methane-gas"] = "2MJ",
  }
  
  local emissions = {
  ["crude-oil"] = 1.4,
  ["light-oil"] = 1.2,
  ["heavy-oil"] = 1.3,
  ["petroleum-gas"] = 1,
  ["diesel-fuel"] = 0.8,
  ["methane-gas"] = 0.8,
  ["liquid-kerosine"] = 0.8,
  ["fuel-oil"] = 0.8,
  ["gasoline"] = 0.8,
}

local parse_energy = function(energy)
  local ending = energy:sub(energy:len())
  if not (ending == "J" or ending == "W") then
    error(ending.. " is not a valid unit of energy")
  end
  local magnitude = energy:sub(energy:len() - 1, energy:len() - 1)
  local multiplier = 1
  if type(magnitude) == "number" then
    return tonumber(energy:sub(1, energy:len()-1))
  end
  local char = {
    k = 1000,
    K = 1000,
    M = 1000000,
    G = 1000000000,
    T = 1000000000000,
    P = 1000000000000000,
    E = 1000000000000000000,
    Z = 1000000000000000000000,
    Y = 1000000000000000000000000
  }
  multiplier = char[magnitude]
  if not multiplier then error(magnitude.. " is not valid magnitude") end
  return tonumber(energy:sub(1, energy:len()-2)) * multiplier
end

local names = {}

for k, fluid in pairs (data.raw.fluid) do
  if not fluid.fuel_value then
    fluid.fuel_value = fuel_values[fluid.name]
  end
  if not fluid.emissions_multiplier then
    fluid.emissions_multiplier = emissions[fluid.name]
  end
end

In effect this file works like an api for the mod,if you fill in the fuel names and values.

User avatar
Shenpen
Fast Inserter
Fast Inserter
Posts: 227
Joined: Sat Aug 27, 2016 2:46 pm
Contact:

Re: [MOD 0.16] Diesel Locomotive

Post by Shenpen »

Edit: and sorry, should probably also say that I'm not sure on the value of further complicating the mod code and settings by adding more fuel types. I removed crude oil from the original version of the mod.
That is totally fair. However I would love to burn a variety of fuels in trains and do see the value of that. :)

User avatar
BlueTemplar
Smart Inserter
Smart Inserter
Posts: 2420
Joined: Fri Jun 08, 2018 2:16 pm
Contact:

Re: [MOD 0.16] Diesel Locomotive

Post by BlueTemplar »

Heh, looks like that this is pretty much what I was asking for !
(Not sure why I missed it before, as it's not the first time that I looks into that file...)
BlueTemplar wrote:
Sat Jul 13, 2019 12:17 pm
It really sounds like these fuel values should be handled by vanilla...
[...]

Or at least it should be a "community" mod, like https://mods.factorio.com/mod/stdlib
BobDiggity (mod-scenario-pack)

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2530
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: [MOD 0.16] Diesel Locomotive

Post by FuryoftheStars »

Shenpen wrote:
Mon Jul 29, 2019 7:23 pm
I would have to manually add this fuel type into the mod.
Not necessarily. I was able to get KS Power to accept a range of fuels by adding a *version* of the data-update.lua in the mod:

In effect this file works like an api for the mod,if you fill in the fuel names and values.
Well, for this mod, the fuel values are kept in config.lua and then the relevant code that uses these is found in data-final-fixes.lua. I think (?) this allows an end user to modify the fuel values if they wanted without it being overridden by updates to the mod, but I think this also prevents you from adding a value into the table it uses from another mod.

If you wanted to add fuels in a "modding of a mod" kind of way rather than my sticking in native support, I think what you'd have to do is modify the item this mod makes (in this case for a fluid called "kerosene", it'd be called "Diesel-Locomotive-kerosene") to simply change the fuel_value, fuel_acceleration_multiplier, and fuel_top_speed_multiplier to your desired values (note that "invalid fuels", which is what this mod would natively treat kerosene as, will assign top speed and accel multipliers of 0, so even if you wanted a value of 1 you need to change them). However, you'd have to do this in data-final-fixes.lua, and then add this mod as an optional dependency of yours to force this one to load first.

Also, if a player selects either the heavy only or light only settings, it will stick a fluid filter onto the locomotive tanks to only allow heavy or light respective of the settings (if the allow diesel option is selected and it detects diesel, it will override this and use diesel only instead of either heavy or light).

I should probably change a few things on how this handles all of that, but that'll probably take me some time to sit down and work it out. For example, I question if the creation of the "fake" fluids needs to happen in data-final-fixes.lua, or if I could do it in data-updates.lua. Typically, mods that would add new fluids should do this in the data.lua cycle, right?
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

Post Reply

Return to “Mods”