The International Simutrans Forum

 

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

0 Members and 1 Guest are viewing this topic.

Offline Yona-TYT ve

  • Devotee
  • *
  • Posts: 1094
    • 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: 1094
    • 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: 1094
    • 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: 1094
    • 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: 1094
    • 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: 1094
    • 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!.

Online prissi

  • Developer
  • Administrator
  • *
  • Posts: 9186
  • 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: 1094
    • 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()"