Make Simutrans speak your language.

Highlighting / marking trains

Started by hreintke, August 16, 2021, 09:47:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.



I am working on visualizing some statuses of the available cargo for factories.
I know how to highlight factories using the "obj->set_flag( obj_t::highlight );"

Looking now into the marking of running trains.
Think I can use something similar to the way the train blocks are shown (red tracks and unmarking when the train has passed).

Can you point me to the code that handles that ?


This is usually handled by the display function, so there is no dedicated code to handle it. You would need to return a transparten image, if the obj is highlighted, override get_outline_image(); and get_outline_colour()


I understand that the actual highlight is done by the display function, but there is a higher level function that triggers that.

Like the gui_schedule_cc does for halts :

void highlight_schedule(bool marking)
marking &= env_t::visualize_schedule;
FOR(minivec_tpl<schedule_entry_t>, const& i, schedule->entries) {
if (grund_t* const gr = welt->lookup(i.pos)) {
for(  uint idx=0;  idx<gr->get_top();  idx++  ) {
obj_t *obj = gr->obj_bei(idx);
if(  marking  ) {
if(  !obj->is_moving()  ) {
obj->set_flag( obj_t::highlight );
else {
obj->clear_flag( obj_t::highlight );

I am using similar code to highlight suppliers and consumers from factories.

Now looking for that "higher level function" for train block highlight.


There is no higher level function.

schiene_t::show_reservations = true;

That's it. Any track reserved will be displayed red.


What's wrong about using obj->set_flag( obj_t::highlight ) on tracks?
Doesn't it work?
Otherwise, overriding obj_t::get_outline_image() and obj_t::get_outline_colour() seems to be the way to go.

Edit: I am wondering why the highlight flag is not considered in get_outline_colour, but instead handled sperately in the display function. Seems a little confusing to me.


Thx for the replies.
Gives me a good starting point for my investigation.

@Freahk : I don't know it there is specific/other work done in display function but get_outline_colour() is used.

* if a function return here a value with TRANSPARENT_FLAGS set
* then a transparent outline with the color form the lower 8 Bit is drawn
FLAGGED_PIXVAL get_outline_colour() const OVERRIDE { return (show_reservations  &&  reserved.is_bound()) ? TRANSPARENT75_FLAG | OUTLINE_FLAG | color_idx_to_rgb(COL_RED) : 0;}

* to show reservations if needed
image_id get_outline_image() const OVERRIDE { return weg_t::get_image(); }

Edit : It is much easier than I anticipated.
I want to highlight convoys with specific content, I can just highlight the vehicles ("cnv->get_vehikel(i)->set_flag(obj_t::highlight);"