Page 1 of 1

Change color of rails on map

Posted: Thu Jun 06, 2019 2:11 pm
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.

Re: Change color of rails on map

Posted: Thu Jun 06, 2019 4:39 pm
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.

Re: Change color of rails on map

Posted: Thu Jun 06, 2019 4:56 pm
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.

Re: Change color of rails on map

Posted: Thu Jun 06, 2019 5:54 pm
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.

Re: Change color of rails on map

Posted: Fri Jun 07, 2019 7:43 am
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:

Re: Change color of rails on map

Posted: Fri Jun 07, 2019 10:14 am
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...

Re: Change color of rails on map

Posted: Fri Jun 07, 2019 5:15 pm
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?

Re: Change color of rails on map

Posted: Fri Jun 07, 2019 5:50 pm
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.

Re: Change color of rails on map

Posted: Fri Jun 07, 2019 6:50 pm
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.