Change color of rails on map

Place to get help with not working mods / modding interface.
Post Reply
eduran
Filter Inserter
Filter Inserter
Posts: 344
Joined: Fri May 09, 2014 2:52 pm
Contact:

Change color of rails on map

Post by eduran »

I'd like to change the color of rails on the map during the control stage. I know that map_color is set at the data stage, so my plan was to define one prototype for each color and switch them out as needed. However, rail entities ignore map_color properties and use the utility-constant chart.rail_color instead.

My next best idea is to create an invisible entity with no collision box and the map_colors I need. That entity would than be placed on top of rails that should be recolored. Before I get into that, two questions: Can an invisible entity without collision be visible on the map? And if so, which map color would be shown if two entities overlap?

I've not done much at all with entity prototypes so far, so maybe there is even a better solution I don't know about. Any help is appreciated.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Change color of rails on map

Post by eradicator »

eduran wrote:
Thu Jun 06, 2019 2:11 pm
I'd like to change the color of rails on the map during the control stage.
[...]
That entity would than be placed on top of rails that should be recolored.
That sounds like you only want to recolor *some* rails? Because recoloring them all individually dynamically would clearly be unreasonable :p.

As for a solution i have no clue. Mass-replacing stuff would be ugly even if it worked. And i bet replacing rails makes the pathfinder grumpy. Depending on what exactly you need it might be realistic to request map support for LuaRendering.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

eduran
Filter Inserter
Filter Inserter
Posts: 344
Joined: Fri May 09, 2014 2:52 pm
Contact:

Re: Change color of rails on map

Post by eduran »

eradicator wrote:
Thu Jun 06, 2019 4:39 pm
That sounds like you only want to recolor *some* rails? Because recoloring them all individually dynamically would clearly be unreasonable :p.
Yes, just some and in 3-4 different colors. I am aware that any attempt to recolor large numbers of rails dynamically would be a performance hog.
eradicator wrote:
Thu Jun 06, 2019 4:39 pm
Depending on what exactly you need it might be realistic to request map support for LuaRendering.
I am looking for a way to visualize train throughput on the map. Rendering on the map would probably work pretty well. But it seems like a big ask.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Change color of rails on map

Post by eradicator »

eduran wrote:
Thu Jun 06, 2019 4:56 pm
I am looking for a way to visualize train throughput on the map. Rendering on the map would probably work pretty well. But it seems like a big ask.
You won't know if you don't ask. It does already work in zoom-to-world view just fine.

Ofc trying yourself how placing invisible entities works won't hurt either. The game doesn't know if anything is "invisible" so that shouldn't affect map color. Collosion_box size most certainly will though. You could try setting an empty collosion_mask so it doesn't actually collide with anything even if it has a box.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

eduran
Filter Inserter
Filter Inserter
Posts: 344
Joined: Fri May 09, 2014 2:52 pm
Contact:

Re: Change color of rails on map

Post by eduran »

eradicator wrote:
Thu Jun 06, 2019 5:54 pm
You could try setting an empty collosion_mask so it doesn't actually collide with anything even if it has a box.
Thanks, that works. Weirdly, my test entity can cover curved rails on the map, but not straight rails. No matter what I use as entity type, straight rails beat all of them. The only exception are vehicles, but they use a sprite instead of map_color :roll:

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Change color of rails on map

Post by eradicator »

eduran wrote:
Fri Jun 07, 2019 7:43 am
eradicator wrote:
Thu Jun 06, 2019 5:54 pm
You could try setting an empty collosion_mask so it doesn't actually collide with anything even if it has a box.
Thanks, that works. Weirdly, my test entity can cover curved rails on the map, but not straight rails. No matter what I use as entity type, straight rails beat all of them. The only exception are vehicles, but they use a sprite instead of map_color :roll:
Try shifting the center of your entity 1/256'th of a tile southwards. Not sure how "off grid" entities behave with map colors...
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

eduran
Filter Inserter
Filter Inserter
Posts: 344
Joined: Fri May 09, 2014 2:52 pm
Contact:

Re: Change color of rails on map

Post by eduran »

eradicator wrote:
Fri Jun 07, 2019 10:14 am
Try shifting the center of your entity 1/256'th of a tile southwards. Not sure how "off grid" entities behave with map colors...
Tried that, but to no effect. Now I am curious: why 1/256th of a tile?

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Change color of rails on map

Post by eradicator »

eduran wrote:
Fri Jun 07, 2019 5:15 pm
eradicator wrote:
Fri Jun 07, 2019 10:14 am
Try shifting the center of your entity 1/256'th of a tile southwards. Not sure how "off grid" entities behave with map colors...
Tried that, but to no effect. Now I am curious: why 1/256th of a tile?
Because as far as i know that's the resolution of "position" (I'm probably wrong about that :P). And stuff further south should draw over stuff north of it. I.e. Doesn't really matter how much. I just thought 1/256 would be the minimum that sohuld work. Try something larger like 1/4th or so. If that doesn't work either than map-draw-order is just different.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Change color of rails on map

Post by DaveMcW »

eradicator wrote:
Fri Jun 07, 2019 5:50 pm
that's the resolution of "position" (I'm probably wrong about that :P).
You are correct, everything except trains uses position at 1/256 resolution. Trains are weird, they have an internal 32-bit 1-dimensional position, but display as a 1/256 2-dimensional position.

Post Reply

Return to “Modding help”