The International Simutrans Forum

 

Author Topic: Function to Mark the ground  (Read 1222 times)

0 Members and 1 Guest are viewing this topic.

Offline Yona-TYT ve

  • Devotee
  • *
  • Posts: 1148
    • Simutrans-BLOG
  • Languages: ES
Function to Mark the ground
« 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.

Offline Yona-TYT ve

  • Devotee
  • *
  • Posts: 1148
    • Simutrans-BLOG
  • Languages: ES
Re: Function to Mark the ground
« Reply #1 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.  ;)

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

Offline Yona-TYT ve

  • Devotee
  • *
  • Posts: 1148
    • Simutrans-BLOG
  • Languages: ES
Re: Function to Mark the ground
« Reply #2 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?

Code: [Select]
//====================================== /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()"

Offline Yona-TYT ve

  • Devotee
  • *
  • Posts: 1148
    • Simutrans-BLOG
  • Languages: ES
Re: Function to Mark the ground
« Reply #3 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:
Code: [Select]
tile.mark_grund(tool_remover)
That would be great.  ;)

Offline Yona-TYT ve

  • Devotee
  • *
  • Posts: 1148
    • Simutrans-BLOG
  • Languages: ES
Re: Function to Mark the ground
« Reply #4 on: July 01, 2018, 02:44:00 AM »
I would like to implement this.  ::'(

Offline Yona-TYT ve

  • Devotee
  • *
  • Posts: 1148
    • Simutrans-BLOG
  • Languages: ES
Re: Function to Mark the ground
« Reply #5 on: August 27, 2018, 03:01:04 AM »
Any idea to mark the ground? .... maybe using bridge pillars ?.
 regards!.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 9309
  • Languages: De,EN,JP
Re: Function to Mark the ground
« Reply #6 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.

Offline Yona-TYT ve

  • Devotee
  • *
  • Posts: 1148
    • Simutrans-BLOG
  • Languages: ES
Re: Function to Mark the ground
« Reply #7 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.
@Dwachs I have created a function to mark the terrain, but only works with [TOOL_SCHEDULE_ADD], what do you think of this?
Code: [Select]
//====================================== /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()"



Offline Yona-TYT ve

  • Devotee
  • *
  • Posts: 1148
    • Simutrans-BLOG
  • Languages: ES
Re: Function to Mark the ground
« Reply #8 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. ;)

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4493
  • Languages: EN, DE, AT
Re: Function to Mark the ground
« Reply #9 on: September 23, 2018, 09:25:47 AM »
I do not understand, which cursor box do you mean?

Offline Yona-TYT ve

  • Devotee
  • *
  • Posts: 1148
    • Simutrans-BLOG
  • Languages: ES
Re: Function to Mark the ground
« Reply #10 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  );
         } 
}
« Last Edit: September 24, 2018, 02:39:11 AM by Yona-TYT »

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4493
  • Languages: EN, DE, AT
Re: Function to Mark the ground
« Reply #11 on: September 24, 2018, 02:45:56 PM »
This can be done.

Offline Yona-TYT ve

  • Devotee
  • *
  • Posts: 1148
    • Simutrans-BLOG
  • Languages: ES
Re: Function to Mark the ground
« Reply #12 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.
« Last Edit: September 24, 2018, 09:41:18 PM by Yona-TYT »

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4493
  • Languages: EN, DE, AT
Re: Function to Mark the ground
« Reply #13 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

Offline Yona-TYT ve

  • Devotee
  • *
  • Posts: 1148
    • Simutrans-BLOG
  • Languages: ES
Re: Function to Mark the ground
« Reply #14 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.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4493
  • Languages: EN, DE, AT
Re: Function to Mark the ground
« Reply #15 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.

Offline Yona-TYT ve

  • Devotee
  • *
  • Posts: 1148
    • Simutrans-BLOG
  • Languages: ES
Re: Function to Mark the ground
« Reply #16 on: October 21, 2018, 03:53:22 AM »