11/* *
2+ * @file astar.nut
23 * Classes to help with route-searching.
34 * Based on the A* algorithm.
45 */
@@ -284,77 +285,6 @@ class astar_route_finder extends astar
284285 }
285286}
286287
287- /* *
288- * Class to search a route along existing ways.
289- */
290- class astar_route_finder extends astar
291- {
292- wt = wt_all
293-
294- constructor (wt_)
295- {
296- base . constructor ()
297- wt = wt_
298- if ( [wt_all, wt_invalid, wt_water, wt_air]. find (wt) ) {
299- throw (" Using this waytype is going to be inefficient. Use at own risk." )
300- }
301- cost_curve = cost_straight
302- }
303-
304- function process_node (cnode)
305- {
306- local from = tile_x (cnode. x, cnode. y, cnode. z)
307- local back = dir. backward (cnode. dir )
308- // allowed directions
309- local dirs = from. get_way_dirs_masked (wt)
310-
311- for (local d = 1 ; d< 16 ; d*= 2 ) {
312- // do not go backwards, only along existing ways
313- if ( d == back || ( (dirs & d) == 0 ) ) {
314- continue
315- }
316-
317- local to = from. get_neighbour (wt, d)
318- if (to) {
319- if (! is_closed (to)) {
320- // estimate moving cost
321- local move = cnode. is_straight_move (d) ? cost_straight : cost_curve
322- local dist = estimate_distance (to)
323- local cost = cnode. cost + move
324- local weight = cost // + dist
325- local node = ab_node (to, cnode, cost, dist, d)
326-
327- add_to_open (node, weight)
328- }
329- }
330- }
331- }
332-
333- // start and end have to be arrays of objects with 3d-coordinates
334- function search_route (start, end)
335- {
336- prepare_search ()
337- foreach (e in end) {
338- targets. append (e);
339- }
340- compute_bounding_box ()
341-
342- foreach (s in start)
343- {
344- local dist = estimate_distance (s)
345- add_to_open (ab_node (s, null , 1 , dist+ 1 , 0 , 0 ), dist+ 1 )
346- }
347-
348- search ()
349-
350- if (route. len () > 0 ) {
351- return { start = route. top (), end = route[0 ], routes = route }
352- }
353- print (" No route found" )
354- return { err = " No route" }
355- }
356- }
357-
358288class ab_node extends ::astar_node
359289{
360290 dir = 0 // direction to reach this node
@@ -1118,13 +1048,14 @@ function check_ground(pos_s, pos_e, way) {
11181048}
11191049
11201050/* *
1051+ * @fn check_tile_end_of_station(direction, count, s_tile)
11211052 * check tile end of station
11221053 *
1123- * direction = 1, 2, 4, 8
1124- * count
1125- * s_tile = station tile : tile_x
1054+ * @param direction = 1, 2, 4, 8
1055+ * @param count
1056+ * @param s_tile = station tile : tile_x
11261057 *
1127- * return tile_x or null
1058+ * @ return tile_x or null
11281059 */
11291060function check_tile_end_of_station (direction, count, s_tile) {
11301061
@@ -1543,13 +1474,13 @@ function remove_tile_to_empty(tiles, wt, t_array = 1) {
15431474/* *
15441475 * function for check station lenght
15451476 *
1546- * pl = player
1547- * starts_field = tile station from plan_simple_connection
1548- * st_lenght = stations fields count
1549- * wt = waytype
1550- * select_station = station object
1551- * build = 0 -> test ; 1 -> build
1552- * combined_halt = true -> yes ; false -> no
1477+ * @param pl = player
1478+ * @param starts_field = tile station from plan_simple_connection
1479+ * @param st_lenght = stations fields count
1480+ * @param wt = waytype
1481+ * @param select_station = station object
1482+ * @param build = 0 -> test ; 1 -> build
1483+ * @param combined_halt = true -> yes ; false -> no
15531484 *
15541485 * returns false (something failed) or array of station tiles (success)
15551486 * in case of success, the value of starts_field maybe changed
@@ -1808,12 +1739,12 @@ function test_tile_is_empty(t_tile) {
18081739/* *
18091740 * function expand station()
18101741 *
1811- * pl = player
1812- * fields = array fields
1813- * wt = waytype
1814- * select_station = station object
1815- * start_fld = c_start or c_end
1816- * combined_halt = true -> yes ; false -> no
1742+ * @param pl = player_x
1743+ * @param fields = array fields
1744+ * @param wt = waytype
1745+ * @param select_station = station object
1746+ * @param start_fld = c_start or c_end
1747+ * @param combined_halt = true -> yes ; false -> no
18171748 */
18181749function expand_station (pl, fields, wt, select_station, start_fld, combined_halt) {
18191750
@@ -2255,16 +2186,16 @@ function expand_station(pl, fields, wt, select_station, start_fld, combined_halt
22552186 }
22562187}
22572188
2258- /*
2189+ /* *
22592190 * function build_extensions_connect_factory()
22602191 *
2261- * pl = player
2262- * st_field = start field
2263- * hlt_field = halt field
2264- * tiles[] = test tiles for extensions to connect factory
2265- * extension = extensions object
2192+ * @param pl = player
2193+ * @param st_field = start field
2194+ * @param hlt_field = halt field
2195+ * @param tiles[] = test tiles for extensions to connect factory
2196+ * @param extension = extensions object
22662197 *
2267- * return
2198+ * @ return
22682199 * 1 = connect factory
22692200 * 0 = not connect factory
22702201 */
@@ -2368,8 +2299,8 @@ function build_station(tiles, station_obj) {
23682299/* *
23692300 * find signal tool
23702301 *
2371- * sig_type = signal type (is_signal, is_presignal ... )
2372- * wt = waytype
2302+ * @param sig_type = signal type (is_signal, is_presignal ... )
2303+ * @param wt = waytype
23732304 */
23742305function find_signal (sig_type, wt) {
23752306
@@ -2621,9 +2552,9 @@ function find_extension(wt, tile_size = 1) {
26212552/* *
26222553 * search existing depot on range to station
26232554 *
2624- * field_pos = start field
2625- * wt = waytype
2626- * range = search range
2555+ * @param field_pos = start field
2556+ * @param wt = waytype
2557+ * @param range = search range
26272558 *
26282559 */
26292560function search_depot (field_pos, wt, range = 10 ) {
@@ -2649,9 +2580,9 @@ function search_depot(field_pos, wt, range = 10) {
26492580/* *
26502581 * search existing station on range to field
26512582 *
2652- * field_pos = start field
2653- * wt = waytype
2654- * range = search range
2583+ * @param field_pos = start field
2584+ * @param wt = waytype
2585+ * @param range = search range
26552586 *
26562587 */
26572588function search_station (field_pos, wt, range) {
@@ -3550,13 +3481,19 @@ function build_double_track(start_field, wt, station_len) {
35503481 }
35513482}
35523483
3553- /*
3554- * start = start field line
3555- * end = end field line
3556- * wt = waytype
3557- * l = stations distance
3558- * c = count of double ways
3559- * c=0 -> no build double ways - return route array
3484+ // / @publicsection
3485+ /* *
3486+ *
3487+ * check the route for build double ways
3488+ *
3489+ * @param start = start field line
3490+ * @param end = end field line
3491+ * @param wt = waytype
3492+ * @param l = stations distance
3493+ * @param c = count of double ways
3494+ * @param c=0 -> no build double ways - return route array
3495+ *
3496+ * @retur tile_x array start tiles for double ways
35603497 */
35613498function check_way_line (start, end, wt, l, c, r_line) {
35623499 /*
@@ -4314,6 +4251,15 @@ function check_way_line(start, end, wt, l, c, r_line) {
43144251
43154252}
43164253
4254+ /* *
4255+ * check the route and optimized this
4256+ *
4257+ * @param route tiles array from route
4258+ * @param wt waytype from route
4259+ * @param int_run count the run this function for selcted line
4260+ * @param o_line line_x object
4261+ *
4262+ */
43174263function optimize_way_line (route, wt, int_run, o_line) {
43184264
43194265 // 0 = off
@@ -4983,10 +4929,10 @@ function optimize_way_line(route, wt, int_run, o_line) {
49834929
49844930}
49854931
4986- /*
4932+ /* *
49874933 * check tiles free for terraform
49884934 *
4989- * tiles = array tiles for check tiles left and right is free
4935+ * @param tiles array tiles for check tiles left and right is free
49904936 */
49914937function check_tiles_for_terraform (tiles) {
49924938 local tiles_free = true
@@ -5008,11 +4954,12 @@ function check_tiles_for_terraform(tiles) {
50084954 return tiles_free
50094955}
50104956
5011- /*
4957+ /* *
50124958 * check double ways in new line
50134959 * waytype: wt_rail
50144960 *
5015- *
4961+ * @param route tiles array from route
4962+ * @param wt waytype from route
50164963 */
50174964function check_doubleway_in_line (route, wt) {
50184965 // gui.add_message_at(our_player, " check_doubleway_in_line(route, wt) ", world.get_time())
@@ -5721,6 +5668,7 @@ function destroy_line(line_obj, good, link_obj) {
57215668 return true
57225669}
57235670
5671+ // / @publicsection
57245672/*
57255673 * check waytypes from halt
57265674 * tile = one tile from halt
@@ -5762,6 +5710,7 @@ function test_halt_waytypes(tile) {
57625710 return test_way
57635711}
57645712
5713+ // / @publicsection
57655714/*
57665715 * check depot as home for other vehicles
57675716 * tile = depot coord
0 commit comments