News:

SimuTranslator
Make Simutrans speak your language.

Function to Mark the ground

Started by Yona-TYT, June 07, 2018, 03:32:48 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Yona-TYT

I would like to mark and unmark the terrain with "gr-> set_flag (grund_t :: marked);"


The problem is that the cursor always eliminates the marked box.

Yona-TYT

Would it be possible to use the pointer (zeiger)?

This helps me to visually indicate where to build a road section.  ;)

Edit
It is to be used in the tutorial, and also to correct an infinite loop error.  :P

Yona-TYT

@Dwachs
I have created a function to mark the terrain, but only works with [TOOL_SCHEDULE_ADD], what do you think of this?

//====================================== /script/api/api_tiles.cc

#include "../../obj/zeiger.h"


void_t mark_grund(grund_t *gr)
{
    koord3d pos = koord3d(gr->get_pos().get_2d(),0);
    zeiger_t *cursor = new zeiger_t(pos, NULL );
    cursor->set_image( tool_t::general_tool[TOOL_SCHEDULE_ADD]->cursor );
    cursor->set_pos( pos );
    gr->obj_add( cursor );
    cursor->set_flag( obj_t::dirty );
    gr->set_flag( grund_t::dirty );
   
    return void_t();
}

void_t unmark_grund(grund_t *gr)
{   
    zeiger_t *cursor = gr->find<zeiger_t>();
    if (cursor){
        cursor->mark_image_dirty( cursor->get_image(), 0 );
        gr->obj_remove( cursor );
        cursor->set_pos( koord3d::invalid );
        gr->set_flag( grund_t::dirty );
        cursor->clear_flag( obj_t::highlight );
   
    }
    return void_t();
}

bool grund_object_is_marked(grund_t *gr)
{
    zeiger_t *cursor = gr->find<zeiger_t>();
    if ((cursor) && (cursor->get_image()) == tool_t::general_tool[TOOL_SCHEDULE_ADD]->cursor){
        return true;
    }
    return false;
}

//========================================== /script/api/squirrel_types_scenario.awk

    export_types["tile_x::mark_grund"] = "void()"
    export_types["tile_x::unmark_grund"] = "void()"
    export_types["tile_x::is_grund_marked"] = "bool()"


Yona-TYT

I would like to use "tool_id" to choose the cursor image to use, but I do not know how to make that work.  :-[
Example: tile.mark_grund(tool_remover)

That would be great.  ;)

Yona-TYT

I would like to implement this.  ::'(

Yona-TYT

Any idea to mark the ground? .... maybe using bridge pillars ?.
regards!.

prissi

In principle you need the imageid of a skin object, which is rather trivial in the main code. But unfourtunately I cannot help you, because my knowledge of adding new functions is zero.

Yona-TYT

I did a small script function that allows to use a cursor image, I like it because it can be used even in underground mode.
Quote from: Yona-TYT on June 11, 2018, 04:47:21 PM@Dwachs I have created a function to mark the terrain, but only works with [TOOL_SCHEDULE_ADD], what do you think of this? //====================================== /script/api/api_tiles.cc #include "../../obj/zeiger.h" void_t mark_grund(grund_t *gr) { koord3d pos = koord3d(gr->get_pos().get_2d(),0); zeiger_t *cursor = new zeiger_t(pos, NULL ); cursor->set_image( tool_t::general_tool[TOOL_SCHEDULE_ADD]->cursor ); cursor->set_pos( pos ); gr->obj_add( cursor ); cursor->set_flag( obj_t::dirty ); gr->set_flag( grund_t::dirty ); return void_t(); } void_t unmark_grund(grund_t *gr) { zeiger_t *cursor = gr->find(); if (cursor){ cursor->mark_image_dirty( cursor->get_image(), 0 ); gr->obj_remove( cursor ); cursor->set_pos( koord3d::invalid ); gr->set_flag( grund_t::dirty ); cursor->clear_flag( obj_t::highlight ); } return void_t(); } bool grund_object_is_marked(grund_t *gr) { zeiger_t *cursor = gr->find(); if ((cursor) && (cursor->get_image()) == tool_t::general_tool[TOOL_SCHEDULE_ADD]->cursor){ return true; } return false; } //========================================== /script/api/squirrel_types_scenario.awk export_types["tile_x::mark_grund"] = "void()" export_types["tile_x::unmark_grund"] = "void()" export_types["tile_x::is_grund_marked"] = "bool()"



Yona-TYT

I think it would be nice to use the cursor box, like the one used by ships when they are routed '' schedule list '' ... it can be an elegant solution for this. ;)

Dwachs

I do not understand, which cursor box do you mean?
Parsley, sage, rosemary, and maggikraut.

Yona-TYT

#10
I refer to the box that marks the water when a ship / ship is routed ... look at this code block
{
gr-> set_flag (  grund_t :: dirty  );
//    here on water
if (  gr-> is_water ( )     ||    gr-> ist_natur ( )   ) {
         if(     marking    )   {
                    gr-> set_flag (  grund_t :: marked  );
         }
        else  {
                  gr-> clear_flag (    grund_t :: marked  );
         } 
}

Dwachs

Parsley, sage, rosemary, and maggikraut.

Yona-TYT

#12
I would like to enter two coordinates (a and b) to form grids / grids, as seen in the forest creation tool or the climate edition tool.

Dwachs

Parsley, sage, rosemary, and maggikraut.

Yona-TYT

Thank you very much, very happy about that.

Another detail:
Is it possible to do an "unmark_all" to unmark all the tiles at the same time? ... that would be very practical.

Dwachs

Such a method would have to iterate through all tiles of the map, which might be a very time consuming method. Please implement this somehow in your script.
Parsley, sage, rosemary, and maggikraut.