Hermios trains

Topics and discussion about specific mods
Hermios
Long Handed Inserter
Long Handed Inserter
Posts: 77
Joined: Sat Aug 13, 2016 2:57 pm
Contact:

Hermios trains

Post by Hermios »

Well, I don't want to be obsessed with trains, but... I am!
So this thread for all those who want to talk/complain/congratulate (yes, you can!) me about my train mods : Railpowersystem, TrainCaller, TrainSignalSender
I'll try to answer as soon as I can, and the best I can do.
Thanks

Hermios

d3x0r
Filter Inserter
Filter Inserter
Posts: 316
Joined: Sun Jun 04, 2017 8:56 am
Contact:

Re: Hermios trains

Post by d3x0r »

Any chance you'd put your sources on github? On edit there's a option at the bottom to edit metadata and provide user/repository information that then shows when clicking on source tab of mod. could then just make a PR(pull request) for the minor modifications suggested below.

Would like to extend/modify RailPowerSystem from another mod (Train Speed Limiter), which changes speeds of trains based on track type. But also if Bio Industries is installed then there are rails the can bridge water, and cement rails (speed bonus); So was adding addtional electrified versions of these, but I cannot get the power pole to connect to these new types. They do connect to existing powered-rails (I guess I can add a note that a section of standard rail has to be used to connect power to the other tracks) but basicaly because the original power-pole entity that gets created is destroyed, no further events are generated for it (I never hear that). Instead of just calling OnGlobalEvent you could use script.raise_event() to raise the event for other created items; but that requires saving the original event type, and event data and is kinda a mess to update.

And internally on the hybrid train you have a max power transfer that's hard coded instead of coming from the train power requirements... this is pretty easy to fix.

Also update the electrified rail icon so they are more visibily electric based on an icon I found in bio Inudstries with a electric bolt on the rails.

d3x0r
Filter Inserter
Filter Inserter
Posts: 316
Joined: Sun Jun 04, 2017 8:56 am
Contact:

Re: Hermios trains

Post by d3x0r »

Blueprinting a section of track with a rail power pole doesn't work. It shows in the blueprint but since the blueprint is saved as ghost-electric-pole it doesn't rebuild. Added this event code and that works.

Also realized that building powered rail next to a rail power pole doesn't connect the pole.

Code: Select all

script.on_event(defines.events.on_player_configured_blueprint, function(event)
     --log( "surface create?" );
	local player = game.players[event.player_index]
	local stack = player.cursor_stack
	log( "blueprint seetup." );
	if not stack.valid then 
		log( "stack not valid" );
		return
	end
	if not stack.valid_for_read then
		log( "stack not valid for read" );
		return
	end
	if stack.name ~= "blueprint" then
		log( "stack is not a blueprint" );
		return
	end	

	local entities = stack.get_blueprint_entities()
	log( "blueprint has entities:".. #entities );
	for k, entity in pairs (entities) do
		if entity.name == ghostElectricPole then
			entity.name = railPole;
			items_changed = true;
		end
	end

  local blueprint_icons = player.cursor_stack.blueprint_icons
  for k=1,4 do
    if( blueprint_icons[k] ) then
        if blueprint_icons[k].signal.name == ghostElectricPole then
          blueprint_icons[k].signal.name = railPole
          break
        end
    end
  end
  player.cursor_stack.blueprint_icons = blueprint_icons  
  stack.set_blueprint_entities(entities)

	--local stack = player.cursor_stack.  event.player_index
end)


---
To support other mods also making poweered rails

modified libs/eventsHandler.lua

Code: Select all

local lastEvent = nil;
local lastEventType = 0;

function reRaiseEvent( entity ) 
	lastEvent.created_entity = entity;
	script.raise_event( lastEventType, lastEvent );
end

function OnBuildEntity(eventType,event)
-- remove automatic connected cables
	lastEventType = eventType;
	lastEvent = event;
	local entity = event.created_entity;

-- .... the remaining code in onBuildEntity
had to change the call to OnBuildEntity to include the original event type (whether robot or player for accuracy), and pass the event so tick could be saved; and then in the above code, reRaiseEvent() just changes the event.created_entity and raises the event.

Code: Select all

	OnBuildEntity(defines.events.on_robot_built_entity,event)

and then in addGhostEntity replaced...

Code: Select all

	reRaiseEvent( ghostCreated );
	--onGlobalBuilt(ghostCreated)
--------------

and then in controls/train.lua to support modified train powers...

Code: Select all

local init = false;
trains.onTick=function (entity)
	if not init then
		-- only need a little more than the max of the entity so energy doesn't hit 0 and flash the fuel symbol...
		-- couldn't find an actual reference for how big the actual buffer is in the train... seems to be just +1333.33 or something
		basePowerMax = game.entity_prototypes["hybrid-train"].max_energy_usage + 10;
		init = true;
	end

-- the remaining code in trains.onTick
and I'm pretty sure that
ghostAccu.electric_drain = requiredPower/60
doesn't need the /60. requiredPower is already an amount that is per-tick...

Hermios
Long Handed Inserter
Long Handed Inserter
Posts: 77
Joined: Sat Aug 13, 2016 2:57 pm
Contact:

Re: Hermios trains

Post by Hermios »

Well, well, well!
Ok, first of all, many thanks for all your tips, I really appreciate.
1- Github : Created long tiöe ago, but since you talked about it, I improved my process. I'll update my mods with it.

2- Code : I definitely agree, that hardcoded data are not the best, and I am glad if I can improve it. I will check your suggestions and probably implement it quickly.

3- Improvement related to other mods: Less priority. The point is, there are a lot of mods, I won't be able to comply with all of them. It doesn#t mean that I won't do it, but it comes after the 2 first points (and the fact that I want to update my own mods based on issues that I found while playing)
I let you know then

Hermios

d3x0r
Filter Inserter
Filter Inserter
Posts: 316
Joined: Sun Jun 04, 2017 8:56 am
Contact:

Re: Hermios trains

Post by d3x0r »

Hermios wrote: 3- Improvement related to other mods: Less priority. The point is, there are a lot of mods, I won't be able to comply with all of them. It doesn#t mean that I won't do it, but it comes after the 2 first points (and the fact that I want to update my own mods based on issues that I found while playing)
I let you know then

Hermios
I concur; in fact it's my mod that has conformed to you :) Everywhere that I can. When the rail-pole gets created you get the event first and then create two ghosts for it instead and then destroy it, which gives noone else any idea anything happened, and there's no events on the ghosts. I could clone the item and make it a special case 'power pole that works with all electric tracks' ... and then hide the broken one I suppose. could have handled the hybrid train extra energy in my on-tick too I guess... and the blueprint update I already had in my code not yours so..

None of the startup events will work for the max train energy code; I had looked into that. But, on_init only gets called once, on_load doesn't get game to be able to look at the entity prototype, and on_configuration only gets called if something changed.. so reloading a game without any changes would leave the max unset... only option is really to do a one time test in on_tick.

Anyway :) have a great day :)

d3x0r
Filter Inserter
Filter Inserter
Posts: 316
Joined: Sun Jun 04, 2017 8:56 am
Contact:

Re: Hermios trains

Post by d3x0r »

:) I can't fill the train in on-tick because you'll unfill the train because of that constant.
could at least check if( locomotive.energy < basePowerMax )


(your original 0.1.4 code; just added comments to the side with the numbers)

Code: Select all

	local requiredPower=basePowerMax-entity.energy   --  (10666-25010) = -14343.3333
	local ghostAccu=ghostRailAccu(rail)              -- 
	ghostAccu.electric_drain = requiredPower/60      --    neg electric_drain ; doesn't set to < 0 in accum
	local max_power = ghostAccu.energy               --   25000
	local power_transfer = 0                         --    0
	if (max_power < requiredPower) then              --  25000 < -14333.33 (false)
		power_transfer = max_power                    --  
	else                                             --
		power_transfer = requiredPower                --   -14343.333
	end
	  
	--  Transfer energy that will be drained over the next second into some entity
	entity.energy = entity.energy + power_transfer     --  entity.energy = 10666.666 (removed 14343 energy from train)
	ghostAccu.energy=ghostAccu.energy-power_transfer --  accum = 25000 + 14343.333 (capacity is 25k so no change)
power drain 860kW idle.

-----

Another bug I realized - if you put more than one hybrid loco on a train, it tries to fill all of them from the same accumulator at front_rail; and fails.
for each mover...

Code: Select all

-- this is a constant
local backwardRail = {rail_direction=defines.rail_direction.back, rail_connection_direction=defines.rail_connection_direction.straight};

rail = rail.get_connected_rail(backwardRail)
But that still fails going around corners... I think because the rail position is 3 or 4 times the same spot so it keeps getting the same accumulator.


it also appears you don't have to set electric_drain (or keep the previous accumulator table to reset drain). in my tick I didn't set it; and right now your tick is trying to set it to a negative number which leaves it at 0.

d3x0r
Filter Inserter
Filter Inserter
Posts: 316
Joined: Sun Jun 04, 2017 8:56 am
Contact:

Re: Hermios trains

Post by d3x0r »

:) Figured out how to increase power without requiring dynamic internal updates; can set the burner.effectivity so it still thinks the draw is 600kW.

Hermios
Long Handed Inserter
Long Handed Inserter
Posts: 77
Joined: Sat Aug 13, 2016 2:57 pm
Contact:

Re: Hermios trains

Post by Hermios »

Sorry, I don't get your last point.
I am not sure for the drain. The point is, that I am totally confused : Yesterday, I removed the drain for a test, it worked the same way.
Then, I changed the config of my entities, it doesn't work. I reload the old version, and it doesn't work either. Totally confused!
You know how to ensure that entities are updated?

d3x0r
Filter Inserter
Filter Inserter
Posts: 316
Joined: Sun Jun 04, 2017 8:56 am
Contact:

Re: Hermios trains

Post by d3x0r »

you'll have to rebuild the track if you change accumulators... they don't get their properties updated...
or add a migration https://github.com/d3x0r/train-speed-li ... /accum.lua

d3x0r
Filter Inserter
Filter Inserter
Posts: 316
Joined: Sun Jun 04, 2017 8:56 am
Contact:

Re: Hermios trains

Post by d3x0r »

The new method with remote interface doesn't entirely help; for bridge rails I had to have a different rail-accum that had a different collision mask.
also don't see a fix to allow blueprinting rails that have power poles attached... well it works anyway so I guess maybe you changed having an extra ghost pole?

But, multiple engines starve; I'm guessing they still pull from just the front rail instead of stepping back each rail to get the next available accumulator.
https://youtu.be/j9mRl0Bk5eA

jdogg
Burner Inserter
Burner Inserter
Posts: 7
Joined: Mon Oct 08, 2018 9:41 pm
Contact:

Re: Hermios trains

Post by jdogg »

I was able to update the electric pole sprite sheet and adjusted the info.json file to work with factorio v0.16.x. However I'm not a developer and don't really understand what makes the mod work haha. It does seam to be working but anything i do to the rail graphic has no effect and they're just auto connected with a random color wire. I don't know if you're still interested in developing this mod but i'd love to learn what makes it tick and make the rails look better (i.e. just add a third rail in the middle and color it red).

Hermios
Long Handed Inserter
Long Handed Inserter
Posts: 77
Joined: Sat Aug 13, 2016 2:57 pm
Contact:

Re: Hermios trains

Post by Hermios »

Hey jdogg
For info, I updated the mod for 0.16.51. It works! (Well, it should). Feel free to add any comment!

gmyx
Inserter
Inserter
Posts: 25
Joined: Sun Jul 13, 2014 1:39 pm
Contact:

Re: Hermios trains

Post by gmyx »

I have a strange bug for you. When I load a game, all circuit connections to the rail pole are lost. I don't know if there is a mod conflict, I use 20+ mods. this brakes all functionality for me.

Save game attached.
final2018.zip
(7.17 MiB) Downloaded 139 times
Dropbox version: https://www.dropbox.com/s/6v7gpvlnwkge7 ... 8.zip?dl=0

Hermios
Long Handed Inserter
Long Handed Inserter
Posts: 77
Joined: Sat Aug 13, 2016 2:57 pm
Contact:

Re: Hermios trains

Post by Hermios »

Hi gmxy
Well, I have a good news: I can reproduce it (So it does come from my mod).
I have a bad news too: I have no idea why! I think this is a problem with the game itself. I will send a notice to the developers. Until then, I can do nothing, sorry!

Niko

gmyx
Inserter
Inserter
Posts: 25
Joined: Sun Jul 13, 2014 1:39 pm
Contact:

Re: Hermios trains

Post by gmyx »

Hermios wrote:
Sun Dec 09, 2018 7:39 pm
Hi gmxy
Well, I have a good news: I can reproduce it (So it does come from my mod).
I have a bad news too: I have no idea why! I think this is a problem with the game itself. I will send a notice to the developers. Until then, I can do nothing, sorry!

Niko
Well, it's a start! Looking forward to seeing it fixed and I can drop the poles again.

gmyx
Inserter
Inserter
Posts: 25
Joined: Sun Jul 13, 2014 1:39 pm
Contact:

Re: Hermios trains

Post by gmyx »

Hermios wrote:
Sun Dec 09, 2018 7:39 pm
Hi gmxy
Well, I have a good news: I can reproduce it (So it does come from my mod).
I have a bad news too: I have no idea why! I think this is a problem with the game itself. I will send a notice to the developers. Until then, I can do nothing, sorry!

Niko
Have you heard back from the Devs? I noticed another issue. I am using a bridges mod, which naturally disconnects the rail power segments. Using the rail power pole to bridge the water, the far end does not get power. I am assuming it's the same problem.

thanks again!

Hermios
Long Handed Inserter
Long Handed Inserter
Posts: 77
Joined: Sat Aug 13, 2016 2:57 pm
Contact:

Re: Hermios trains

Post by Hermios »

Hi
I am so sorry, I forgot to ask them. Quite busy. The problem may be more complex than what I thought, that is why I didn't contact them about it immeditaly
For the bridges, you can ask the developer of the mod to include a remote call to my mod in his. Thus, his bridges shall be consirered as electric as well.
For more information, just look in the description of my mod!
I'll try to look at the other issue later, not sure when. Sorry again for the delay!
Niko

Horatio
Inserter
Inserter
Posts: 20
Joined: Mon Mar 12, 2018 10:57 pm
Contact:

Re: Hermios trains

Post by Horatio »

Mod doesnt work

coolfarmer
Burner Inserter
Burner Inserter
Posts: 5
Joined: Mon Jun 10, 2019 10:16 pm
Contact:

Re: Hermios trains

Post by coolfarmer »

Can't understand why your mod "Trains Caller" doesn't work for me.
This error occure and crash my game every time I put the "train caller equipment" into the equipment grid of my locomotive.

Code: Select all

The mod TrainsCaller caused a non-recoverable error.
Please report this error to the mod author.

Error while running event TrainsCaller::on_player_placed_equipment (ID 38)
LuaTrain doesn't contain key train.
stack traceback:
	__HermiosLibs__/dataLibs.lua:64: in function 'getUnitId'
	__TrainsCaller__/methods/trainFunctions.lua:17: in function 'new'
	__TrainsCaller__/methods/trainFunctions.lua:29: in function 'setListTrains'
	__TrainsCaller__/methods/globalEvents.lua:62: in function 'OnEquipmentPlaced'
	__HermiosLibs__/controlLib.lua:93: in function <__HermiosLibs__/controlLib.lua:87>
stack traceback:
	[C]: in function '__index'
	__HermiosLibs__/dataLibs.lua:64: in function 'getUnitId'
	__TrainsCaller__/methods/trainFunctions.lua:17: in function 'new'
	__TrainsCaller__/methods/trainFunctions.lua:29: in function 'setListTrains'
	__TrainsCaller__/methods/globalEvents.lua:62: in function 'OnEquipmentPlaced'
	__HermiosLibs__/controlLib.lua:93: in function <__HermiosLibs__/controlLib.lua:87>

Hermios
Long Handed Inserter
Long Handed Inserter
Posts: 77
Joined: Sat Aug 13, 2016 2:57 pm
Contact:

Re: Hermios trains

Post by Hermios »

Hi
Which version do you use? Please ensure you use the 0.1.2 of HermiosLibs
Besides, there may be some problems of migration. I recommand to remove your locomotive and to put it back on the rails.
If not, please rather send a message on the portal for mods (I created this blog when the portal was not good, but it is ok now, so I prefer to deal with it).
Cheers
Niko

Post Reply

Return to “Mods”