The International Simutrans Forum

Development => Scripting Scenarios and AI => Topic started by: Yona-TYT on June 07, 2018, 03:32:48 AM

Title: Function to Mark the ground
Post by: Yona-TYT on June 07, 2018, 03:32:48 AM
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.
(https://www.mediafire.com/convkey/8c97/dkqzdhvzppa3a366g.jpg)
Title: Re: Function to Mark the ground
Post by: Yona-TYT on June 08, 2018, 05:51:10 PM
Would it be possible to use the pointer (zeiger)?

This helps me to visually indicate where to build a road section.  ;)
(https://www.mediafire.com/convkey/14cd/29mxam37g8dre3g6g.jpg)
Edit
It is to be used in the tutorial, and also to correct an infinite loop error.  :P
Title: Re: Function to Mark the ground
Post by: 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<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()"

(https://www.mediafire.com/convkey/e264/tyqgazlqop8ro8b6g.jpg)
Title: Re: Function to Mark the ground
Post by: Yona-TYT on June 14, 2018, 01:38:25 AM
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.  ;)
Title: Re: Function to Mark the ground
Post by: Yona-TYT on July 01, 2018, 02:44:00 AM
I would like to implement this.  ::'(
Title: Re: Function to Mark the ground
Post by: Yona-TYT on August 27, 2018, 03:01:04 AM
Any idea to mark the ground? .... maybe using bridge pillars ?.
regards!.
Title: Re: Function to Mark the ground
Post by: prissi on August 27, 2018, 01:49:16 PM
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.
Title: Re: Function to Mark the ground
Post by: Yona-TYT on September 02, 2018, 08:27:03 PM
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()" (https://www.mediafire.com/convkey/e264/tyqgazlqop8ro8b6g.jpg)


Title: Re: Function to Mark the ground
Post by: Yona-TYT on September 22, 2018, 10:58:02 PM
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. ;)
Title: Re: Function to Mark the ground
Post by: Dwachs on September 23, 2018, 09:25:47 AM
I do not understand, which cursor box do you mean?
Title: Re: Function to Mark the ground
Post by: Yona-TYT on September 24, 2018, 02:19:25 AM
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  );
         } 
}
Title: Re: Function to Mark the ground
Post by: Dwachs on September 24, 2018, 02:45:56 PM
This can be done.
Title: Re: Function to Mark the ground
Post by: Yona-TYT on September 24, 2018, 09:25:51 PM
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.
Title: Re: Function to Mark the ground
Post by: Dwachs on October 19, 2018, 05:16:13 PM
Functions to mark tiles are now in r8613, see http://dwachs.github.io/simutrans-sqapi-doc/classtile__x.html
Title: Re: Function to Mark the ground
Post by: Yona-TYT on October 19, 2018, 05:36:51 PM
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.
Title: Re: Function to Mark the ground
Post by: Dwachs on October 19, 2018, 06:58:23 PM
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.
Title: Re: Function to Mark the ground
Post by: Yona-TYT on October 21, 2018, 03:53:22 AM
Now if you can try my new invention ... hehehehe. :thumbsup:

Script: http://www.mediafire.com/file/qxco65da76ypen4/Tutorial-ex-tyt.zip/file


Savegame: http://www.mediafire.com/file/iyvrs1l7hy39397/Tutorial3.sve/file

(https://www.mediafire.com/convkey/33c7/9qcpdxfq2oq88qg6g.jpg)