Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
r9112 - Script-KI find_object(mo_way)
#3
Ja das Tile gibt es und es ist auch ein Gleis drauf.

Es ist direkt angegeben zum testen des Baus einer Ausweichstelle. Der Bau funktioniert auch.
Allerdings nutze ich aktuell das erste gefundene Gleis. Ich möchte aber das Gleis verwenden, was bereits gebaut ist.

Unter Umständen hängt es mit den Spielern zusammen. Das Script läuft ja für alle Script-KIs. Das Gleis/Feld gehört aber nur einem Spieler.

Ich hab aber noch nicht gefunden, wie man den Besitzer des Feldes abrufen kann.

Ich kann es noch nicht ins Git einstellen, da das Feld für genau diese Karte vorgegeben ist. Der Code also noch nicht fertig ist für das ermitteln des Startfeldes für die Ausweichstelle. Ich weis auch noch nicht, wie ich das auf eben den Streckenbesitzer einschränke. Aktuell würde jeder aktive Script-KI-Spieler den Bauvorgang auslösen. Das führt dann zu unvollständigen Bau der Ausweichstelle, weil ja die Gleise nicht verbunden werden von verschiedenen Spielern.

Die Funktion selber sieht so aus. Die rote Zeile ist der beabsichtigte Aufruf.

Zitat:function build_double_track(start_field, wt) {

  gui.add_message_at(our_player, "  build_double_track " + coord3d_to_string(start_field), start_field)

  local d = start_field.get_way_dirs(wt)
  local tiles = []
  local tiles_build_l = []
  local tiles_build_r = []
  local t = 0
  local way_len = 8
  local signal = []

  // check way - 8 fields straight
  for ( local i = 0; i < way_len; i++ ) {
    if ( d == 5 ) {
      // ns
      if ( tile_x(start_field.x + 1, start_field.y + i, start_field.z).is_empty() && square_x(start_field.x, start_field.y + i).get_ground_tile().z == start_field.z ) {
        tiles_build_r.append(tile_x(start_field.x + 1, start_field.y + i, start_field.z))
      }
      if ( tile_x(start_field.x - 1, start_field.y + i, start_field.z).is_empty() && square_x(start_field.x, start_field.y + i).get_ground_tile().z == start_field.z ) {
        tiles_build_l.append(tile_x(start_field.x - 1, start_field.y + i, start_field.z))
      }
      tiles.append(tile_x(start_field.x + i, start_field.y, start_field.z))
    } else if ( d == 10 ) {
      // ew
      //gui.add_message_at(our_player, "tile r " + coord3d_to_string(tile_x(start_field.x + i, start_field.y + 1, start_field.z)) + " empty " + tile_x(start_field.x + i, start_field.y + 1, start_field.z).is_empty(), start_field)
      //gui.add_message_at(our_player, " -- tile l " + coord3d_to_string(tile_x(start_field.x + i, start_field.y - 1, start_field.z)) + " to empty " + tile_x(start_field.x - i, start_field.y + 1, start_field.z).is_empty(), start_field)

      if ( tile_x(start_field.x + i, start_field.y + 1, start_field.z).is_empty() && square_x(start_field.x + i, start_field.y).get_ground_tile().z == start_field.z ) {
        tiles_build_r.append(tile_x(start_field.x + i, start_field.y + 1, start_field.z))
      }
      if ( tile_x(start_field.x + i, start_field.y - 1, start_field.z).is_empty() && square_x(start_field.x + i, start_field.y).get_ground_tile().z == start_field.z ) {
        tiles_build_l.append(tile_x(start_field.x + i, start_field.y - 1, start_field.z))
      }
      tiles.append(tile_x(start_field.x + i, start_field.y, start_field.z))
    }
  }

  //gui.add_message_at(our_player, "  tiles_build_r " + tiles_build_r.len(), start_field)
  //gui.add_message_at(our_player, "  tiles_build_l " + tiles_build_l.len(), start_field)

  // 8 field free
  local tl = 0
  local tr = 0
  if ( tiles_build_r.len() == 8 || tiles_build_l.len == 8 ) {
    if ( tiles_build_r.len() == 8 ) {
      for ( local i = 0; i < way_len; i++ ) {
        if ( tiles_build_r[i].get_slope() == 0 ) {
          tr++
        }
      }
    }
    if ( tiles_build_l.len() == 8 ) {
      for ( local i = 0; i < way_len; i++ ) {
        if ( tiles_build_l[i].get_slope() == 0 ) {
          tl++
        }
      }
    }
    //gui.add_message_at(our_player, "  tiles r get_slope() = 0 " + tr, start_field)
    //gui.add_message_at(our_player, "  tiles l get_slope() = 0 " + tl, start_field)
    local tiles_build = null
    if ( tr == 8 ) {
        tiles_build = tiles_build_r
        if ( settings.get_drive_on_left() ) {
          signal = [{coor=coord3d(tiles_build[6].x, tiles_build[6].y, tiles_build[6].z), ribi=8}, {coor=coord3d(tiles[1].x, tiles[1].y, tiles[1].z), ribi=2}]
        } else {
          signal = [{coor=coord3d(tiles[1].x, tiles[1].y, tiles[1].z), ribi=8}, {coor=coord3d(tiles_build[6].x, tiles_build[6].y, tiles_build[6].z), ribi=2}]
        }
    } else if ( tl == 8 ) {
        tiles_build = tiles_build_l
        if ( settings.get_drive_on_left() ) {
          signal = [{coor=coord3d(tiles_build[6].x, tiles_build[6].y, tiles_build[6].z), ribi=4}, {coor=coord3d(tiles[1].x, tiles[1].y, tiles[1].z), ribi=1}]
        } else {
          signal = [{coor=coord3d(tiles[1].x, tiles[1].y, tiles[1].z), ribi=4}, {coor=coord3d(tiles_build[6].x, tiles_build[6].y, tiles_build[6].z), ribi=1}]
        }
    } else {

      tiles_build = tiles_build_r
      if ( settings.get_drive_on_left() ) {
        signal = [{coor=coord3d(tiles_build[6].x, tiles_build[6].y, tiles_build[6].z), ribi=8}, {coor=coord3d(tiles[1].x, tiles[1].y, tiles[1].z), ribi=2}]
      } else {
        signal = [{coor=coord3d(tiles[1].x,tiles[1].y,tiles[1].z), ribi=8}, {coor=coord3d(tiles_build[6].x, tiles_build[6].y, tiles_build[6].z), ribi=2}]
      }

      // check terrafom
      for ( local i = 0; i < way_len; i++ ) {
        local r = square_x(tiles_build[i].x, tiles_build[i].y)
        local z = r.get_ground_tile()
        local f = tile_x(tiles_build[i].x, tiles_build[i].y, z.z)
        local ref_hight = start_field.z

        if ( f.is_empty() && ( f.get_slope() > 0 || ref_hight != z.z ) ) {

          if ( print_message_box == 2 ) {
            gui.add_message_at(pl, " ---=> terraform", world.get_time())
            gui.add_message_at(pl, " ---=> tile z " + z.z + " start tile z " + ref_hight, world.get_time())
          }

          if ( z.z < ref_hight && z.z >= (ref_hight - 2) ) {
          // terraform up
            if ( print_message_box == 2 ) {
              gui.add_message_at(pl, " ---=> tile up to flat ", world.get_time())
            }
            do {
              err = command_x.set_slope(pl, tile_x(f.x, f.y, z.z), 82 )
              if ( err != null ) { break }
              z = r.get_ground_tile()
            } while(z.z < ref_hight )

          } else if ( z.z >= ref_hight || z.z <= (ref_hight + 1) ) {
            // terraform down
            if ( print_message_box == 2 ) {
              gui.add_message_at(pl, " ---=> tile down to flat ", world.get_time())
            }
            do {
              err = command_x.set_slope(pl, tile_x(f.x, f.y, z.z), 83 )
              if ( err != null ) { break }
              z = r.get_ground_tile()
            } while(z.z > ref_hight )
          }
          if ( err ) {
            return false
          }
        }
      }
    }

    // build way
    local way_list = way_desc_x.get_available_ways(wt, st_flat)
  local way_obj = way_list[0] //tiles[0].find_object(mo_way)

    gui.add_message_at(our_player, "build tiles[0] " + coord3d_to_string(tiles[0]) + " to tiles_build[0] " + coord3d_to_string(tiles_build[0]), start_field)

    command_x.build_way(our_player, tiles[0], tiles_build[0], way_obj, true)
    command_x.build_way(our_player, tiles_build[0], tiles_build[way_len - 1], way_obj, true)
    command_x.build_way(our_player, tiles_build[way_len - 1], tiles[way_len - 1], way_obj, true)

    // build signals
    local list = sign_desc_x.get_available_signs(wt)
    local obj_sign = null
    foreach(o in list) {
      gui.add_message_at(our_player, "signals " + o.get_name(), start_field)
        if (o.is_signal()) {
          obj_sign = o
          break
        }
    }

    for(local j=0; j < signal.len(); j++ ){

      gui.add_message_at(our_player, "signal to tile " + coord3d_to_string(tile_x(signal[j].coor.x, signal[j].coor.y, signal[j].coor.z)), start_field)

      while(true){
        local err = command_x.build_sign_at(our_player, tile_x(signal[j].coor.x, signal[j].coor.y, signal[j].coor.z), obj_sign)
        local ribi = tile_x(signal[j].coor.x, signal[j].coor.y, signal[j].coor.z).get_way_dirs_masked(wt)
        if (ribi == signal[j].ribi)
          break
      }

    }
  }
}

Der Aufruf steht in industrie_manager.nut Zeile 321

Code:
      // no signals and double tracks - limit 1 convoy for rail
      if (cnv.get_waytype() == wt_rail && cnv_count == 1) {
          local s_field = tile_x(115, 180, 2)
          build_double_track(s_field, wt_rail)
        //gui.add_message_at(our_player, "####### cnv_count " + cnv_count, world.get_time())
        //gui.add_message_at(our_player, "Line: " + line.get_name() + " ==> no add convoy by rail", world.get_time())
        return
      }
Script-KI für Simutrans r10894+ / Simutrans Nightly Builds
Zitieren


Nachrichten in diesem Thema
r9112 - Script-KI find_object(mo_way) - von Andarix - 28-05-2020, Thursday-21:42:00
RE: r9112 - Script-KI find_object(mo_way) - von prissi - 30-05-2020, Saturday-15:49:27
RE: r9112 - Script-KI find_object(mo_way) - von Andarix - 30-05-2020, Saturday-17:47:26
RE: r9112 - Script-KI find_object(mo_way) - von prissi - 31-05-2020, Sunday-15:28:07
RE: r9112 - Script-KI find_object(mo_way) - von Andarix - 31-05-2020, Sunday-15:44:59
RE: r9112 - Script-KI find_object(mo_way) - von prissi - 01-06-2020, Monday-14:51:26
RE: r9112 - Script-KI find_object(mo_way) - von Andarix - 02-06-2020, Tuesday-09:42:19
RE: r9112 - Script-KI find_object(mo_way) - von Dwachs2 - 08-06-2020, Monday-15:39:14
RE: r9112 - Script-KI find_object(mo_way) - von Dwachs2 - 08-06-2020, Monday-16:03:16
RE: r9112 - Script-KI find_object(mo_way) - von Dwachs2 - 08-06-2020, Monday-16:12:53
RE: r9112 - Script-KI find_object(mo_way) - von Dwachs2 - 08-06-2020, Monday-16:19:44
RE: r9112 - Script-KI find_object(mo_way) - von Andarix - 08-06-2020, Monday-16:48:00
RE: r9112 - Script-KI find_object(mo_way) - von Dwachs2 - 08-06-2020, Monday-19:09:46
RE: r9112 - Script-KI find_object(mo_way) - von Andarix - 15-06-2020, Monday-16:21:30
RE: r9112 - Script-KI find_object(mo_way) - von Andarix - 08-06-2020, Monday-20:07:45
RE: r9112 - Script-KI find_object(mo_way) - von Dwachs2 - 08-06-2020, Monday-20:19:13
RE: r9112 - Script-KI find_object(mo_way) - von Andarix - 02-08-2020, Sunday-13:32:41

Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste