From 9f97aff62f6ba2dd228314df80ff0b8598fe99e4 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Wed, 17 Feb 2021 20:48:16 -0500 Subject: [PATCH] Update everything to use the new wesnoth.map module - get_terrain and set_terrain replaced with direct indexing operations - get_map_size mostly replaced with either the iterator or an on_board call. Only a few cases really needed to know the size of the map for some other purpose. - shroud and fog operations, village owner, time areas, and location filters - get_terrain_info replaced with terrain_types table - Map generation functions create_map and create_filter --- data/ai/lua/ai_helper.lua | 76 +++++++------- data/ai/lua/battle_calcs.lua | 20 ++-- data/ai/lua/ca_castle_switch.lua | 22 +++-- data/ai/lua/ca_grab_villages.lua | 4 +- data/ai/lua/ca_recruit_rushers.lua | 3 +- data/ai/lua/ca_spread_poison.lua | 4 +- data/ai/lua/ca_village_hunt.lua | 6 +- data/ai/lua/generic_recruit_engine.lua | 17 ++-- data/ai/lua/retreat.lua | 6 +- data/ai/micro_ais/cas/ca_assassin_move.lua | 6 +- data/ai/micro_ais/cas/ca_big_animals.lua | 8 +- data/ai/micro_ais/cas/ca_bottleneck_move.lua | 65 ++++++------ .../ai/micro_ais/cas/ca_fast_attack_utils.lua | 6 +- data/ai/micro_ais/cas/ca_fast_move.lua | 6 +- .../cas/ca_forest_animals_new_rabbit.lua | 3 +- data/ai/micro_ais/cas/ca_goto.lua | 2 +- data/ai/micro_ais/cas/ca_healer_move.lua | 6 +- data/ai/micro_ais/cas/ca_herding_dog_move.lua | 2 +- .../cas/ca_herding_f_herding_area.lua | 4 +- .../micro_ais/cas/ca_herding_herd_sheep.lua | 2 +- data/ai/micro_ais/cas/ca_lurkers.lua | 6 +- .../ai/micro_ais/cas/ca_protect_unit_move.lua | 2 +- data/ai/micro_ais/cas/ca_recruit_random.lua | 10 +- .../micro_ais/cas/ca_stationed_guardian.lua | 2 +- data/ai/micro_ais/cas/ca_wolves_move.lua | 8 +- data/ai/micro_ais/cas/ca_zone_guardian.lua | 2 +- .../scenarios/04_Spring_of_Reprisal.cfg | 6 +- .../Eastern_Invasion/ai/ca_ogres_flee.lua | 7 +- .../Eastern_Invasion/lua/bandits.lua | 6 +- .../scenarios/13_The_Dwarven_Doors.cfg | 6 +- .../Northern_Rebirth/lua/respawn_utils.lua | 2 +- .../ai/ca_transport_S6.lua | 8 +- .../The_Hammer_of_Thursagan/lua/spawns.lua | 4 +- .../scenarios/05_Fear.cfg | 2 +- .../Two_Brothers/ai/ca_muff_toras_move.lua | 2 +- .../lua/campaign/autorecall.lua | 2 +- .../World_Conquest/lua/campaign/enemy.lua | 2 +- .../lua/campaign/enemy_themed.lua | 6 +- .../lua/game_mechanics/bonus.lua | 4 +- .../lua/game_mechanics/supply.lua | 4 +- .../lua/map/generator/utilities.lua | 4 +- .../lua/map/postgeneration/1A_Start.lua | 2 +- .../lua/map/postgeneration/2A_Springs.lua | 6 +- .../lua/map/postgeneration/2C_Glaciers.lua | 2 +- .../lua/map/postgeneration/2D_Provinces.lua | 2 +- .../lua/map/postgeneration/2E_Paradise.lua | 6 +- .../lua/map/postgeneration/3C_Delta.lua | 2 +- .../lua/map/postgeneration/3F_Wetland.lua | 2 +- .../lua/map/postgeneration/4A_Thermal.lua | 2 +- .../lua/map/postgeneration/4B_Volcanic.lua | 6 +- .../lua/map/postgeneration/4C_Mines.lua | 6 +- .../lua/map/postgeneration/6A_Rural.lua | 4 +- .../lua/map/postgeneration/6B_Maritime.lua | 4 +- .../lua/map/postgeneration/6C_Industrial.lua | 8 +- .../lua/map/postgeneration/6D_Feudal.lua | 4 +- .../lua/map/postgeneration_utils/engine.lua | 6 +- .../lua/map/postgeneration_utils/events.lua | 8 +- .../lua/map/postgeneration_utils/noise.lua | 8 +- .../map/postgeneration_utils/utilities.lua | 16 +-- .../map/postgeneration_utils/wild_zones.lua | 2 +- .../lua/map/scenario_utils/bonus_points.lua | 6 +- .../lua/map/wct_map_generator.lua | 2 +- .../lua/optional_mechanics/destruction.lua | 98 +++++++++---------- data/lua/helper.lua | 9 +- data/lua/location_set.lua | 5 - data/lua/wml-tags.lua | 90 +++++++++-------- data/lua/wml/animate_unit.lua | 4 +- data/lua/wml/find_path.lua | 18 ++-- data/lua/wml/items.lua | 6 +- data/lua/wml/modify_side.lua | 6 +- data/lua/wml/random_placement.lua | 4 +- data/modifications/pick_advance/main.lua | 13 +-- .../scenarios/2p_Dark_Forecast.lua | 4 +- data/scenario-test.cfg | 2 +- src/scripting/lua_terrainmap.cpp | 2 +- 75 files changed, 340 insertions(+), 388 deletions(-) diff --git a/data/ai/lua/ai_helper.lua b/data/ai/lua/ai_helper.lua index 99aeba86170d6..387a1656ce038 100644 --- a/data/ai/lua/ai_helper.lua +++ b/data/ai/lua/ai_helper.lua @@ -69,11 +69,8 @@ end function ai_helper.clear_labels() -- Clear all labels on a map - local width, height = wesnoth.get_map_size() - for x = 1,width do - for y = 1,height do - wesnoth.label { x = x, y = y, text = "" } - end + for x, y in wesnoth.current.map:iter(true) do + wesnoth.label { x = x, y = y, text = "" } end end @@ -667,8 +664,7 @@ function ai_helper.get_named_loc_xy(param_core, cfg, required_for) if (param_core ~= '') then param_x, param_y = param_core .. '_x', param_core .. '_y' end local x, y = cfg[param_x], cfg[param_y] if x and y then - local width, height = wesnoth.get_map_size() - if (x < 1) or (x > width) or (y < 1) or (y > height) then + if not wesnoth.current.map:on_board(x, y) then wml.error("Location is not on map: " .. param_x .. ',' .. param_y .. ' = ' .. x .. ',' .. y) end @@ -729,7 +725,7 @@ function ai_helper.get_multi_named_locs_xy(param_core, cfg, required_for) end function ai_helper.get_locations_no_borders(location_filter) - -- Returns the same locations array as wesnoth.get_locations(location_filter), + -- Returns the same locations array as wesnoth.map.find(location_filter), -- but excluding hexes on the map border. -- -- This is faster than alternative methods, at least with the current @@ -738,7 +734,7 @@ function ai_helper.get_locations_no_borders(location_filter) local old_include_borders = location_filter.include_borders location_filter.include_borders = false - local locs = wesnoth.get_locations(location_filter) + local locs = wesnoth.map.find(location_filter) location_filter.include_borders = old_include_borders return locs end @@ -752,14 +748,14 @@ function ai_helper.get_closest_location(hex, location_filter, unit) -- Find the maximum distance from 'hex' that's possible on the map local max_distance = 0 - local width, height = wesnoth.get_map_size() - local to_top_left = M.distance_between(hex[1], hex[2], 0, 0) + local map = wesnoth.current.map + local to_top_left = M.distance_between(hex, 0, 0) if (to_top_left > max_distance) then max_distance = to_top_left end - local to_top_right = M.distance_between(hex[1], hex[2], width+1, 0) + local to_top_right = M.distance_between(hex, map.width-1, 0) if (to_top_right > max_distance) then max_distance = to_top_right end - local to_bottom_left = M.distance_between(hex[1], hex[2], 0, height+1) + local to_bottom_left = M.distance_between(hex, 0, map.height-1) if (to_bottom_left > max_distance) then max_distance = to_bottom_left end - local to_bottom_right = M.distance_between(hex[1], hex[2], width+1, height+1) + local to_bottom_right = M.distance_between(hex, map.width-1, map.height-1) if (to_bottom_right > max_distance) then max_distance = to_bottom_right end -- If the hex is supposed to be passable for a unit, it cannot be on the map border @@ -782,11 +778,11 @@ function ai_helper.get_closest_location(hex, location_filter, unit) } end - local locs = wesnoth.get_locations(loc_filter) + local locs = wesnoth.map.find(loc_filter) if unit then for _,loc in ipairs(locs) do - local movecost = unit:movement(wesnoth.get_terrain(loc[1], loc[2])) + local movecost = unit:movement(wesnoth.current.map[loc]) if (movecost <= unit.max_moves) then return loc end end else @@ -812,7 +808,7 @@ function ai_helper.get_passable_locations(location_filter, unit) if unit then local locs = {} for _,loc in ipairs(all_locs) do - local movecost = unit:movement(wesnoth.get_terrain(loc[1], loc[2])) + local movecost = unit:movement(wesnoth.current.map[loc]) if (movecost <= unit.max_moves) then table.insert(locs, loc) end end return locs @@ -828,7 +824,7 @@ function ai_helper.get_healing_locations(location_filter) local locs = {} for _,loc in ipairs(all_locs) do - if wesnoth.get_terrain_info(wesnoth.get_terrain(loc[1],loc[2])).healing > 0 then + if wesnoth.terrain_types[wesnoth.current.map[loc]].healing > 0 then table.insert(locs, loc) end end @@ -847,20 +843,17 @@ function ai_helper.distance_map(units, map) map:iter(function(x, y, data) local dist = 0 for _,unit in ipairs(units) do - dist = dist + M.distance_between(unit.x, unit.y, x, y) + dist = dist + M.distance_between(unit, x, y) end DM:insert(x, y, dist) end) else - local width, height = wesnoth.get_map_size() - for x = 1,width do - for y = 1,height do - local dist = 0 - for _,unit in ipairs(units) do - dist = dist + M.distance_between(unit.x, unit.y, x, y) - end - DM:insert(x, y, dist) + for x, y in wesnoth.current.map:iter() do + local dist = 0 + for _,unit in ipairs(units) do + dist = dist + M.distance_between(unit, x, y) end + DM:insert(x, y, dist) end end @@ -877,20 +870,17 @@ function ai_helper.inverse_distance_map(units, map) map:iter(function(x, y, data) local dist = 0 for _,unit in ipairs(units) do - dist = dist + 1. / (M.distance_between(unit.x, unit.y, x, y) + 1) + dist = dist + 1. / (M.distance_between(unit, x, y) + 1) end IDM:insert(x, y, dist) end) else - local width, height = wesnoth.get_map_size() - for x = 1,width do - for y = 1,height do - local dist = 0 - for _,unit in ipairs(units) do - dist = dist + 1. / (M.distance_between(unit.x, unit.y, x, y) + 1) - end - IDM:insert(x, y, dist) + for x, y in wesnoth.current.map:iter() do + local dist = 0 + for _,unit in ipairs(units) do + dist = dist + 1. / (M.distance_between(unit, x, y) + 1) end + IDM:insert(x, y, dist) end end @@ -998,8 +988,8 @@ function ai_helper.xyoff(x, y, ori, hex) end function ai_helper.split_location_list_to_strings(list) - -- Convert a list of locations @list as returned by wesnoth.get_locations into a pair of strings - -- suitable for passing in as x,y coordinate lists to wesnoth.get_locations. + -- Convert a list of locations @list as returned by wesnoth.map.find into a pair of strings + -- suitable for passing in as x,y coordinate lists to wesnoth.map.find. -- Could alternatively convert to a WML table and use the find_in argument, but this is simpler. local locsx, locsy = {}, {} for i,loc in ipairs(list) do @@ -1022,7 +1012,7 @@ function ai_helper.get_avoid_map(ai, avoid_tag, use_ai_aspect, default_avoid_tag -- @use_ai_aspect == false or the default AI aspect is not set. if avoid_tag then - return LS.of_pairs(wesnoth.get_locations(avoid_tag)) + return LS.of_pairs(wesnoth.map.find(avoid_tag)) end if use_ai_aspect then @@ -1054,7 +1044,7 @@ function ai_helper.get_avoid_map(ai, avoid_tag, use_ai_aspect, default_avoid_tag -- If we got here, that means neither @avoid_tag nor the default AI [avoid] aspect were used if default_avoid_tag then - return LS.of_pairs(wesnoth.get_locations(default_avoid_tag)) + return LS.of_pairs(wesnoth.map.find(default_avoid_tag)) else return LS.create() end @@ -1526,12 +1516,12 @@ function ai_helper.next_hop(unit, x, y, cfg) unit:to_map(old_x, old_y) unit_in_way:to_map() - local terrain = wesnoth.get_terrain(next_hop_ideal[1], next_hop_ideal[2]) + local terrain = wesnoth.current.map[next_hop_ideal] local move_cost_endpoint = unit:movement_on(terrain) local inverse_reach_map = LS.create() for _,r in pairs(inverse_reach) do -- We want the moves left for moving into the opposite direction in which the reach map was calculated - local terrain = wesnoth.get_terrain(r[1], r[2]) + local terrain = wesnoth.current.map[r] local move_cost = unit:movement_on(terrain) local inverse_cost = r[3] + move_cost - move_cost_endpoint inverse_reach_map:insert(r[1], r[2], inverse_cost) @@ -1754,7 +1744,7 @@ function ai_helper.custom_cost_with_avoid(x, y, prev_cost, unit, avoid_map, ally end local max_moves = unit.max_moves - local terrain = wesnoth.get_terrain(x, y) + local terrain = wesnoth.current.map[{x, y}] local move_cost = unit:movement_on(terrain) if (move_cost > max_moves) then diff --git a/data/ai/lua/battle_calcs.lua b/data/ai/lua/battle_calcs.lua index 7c6e3b4820ecc..1d41cb0c85ab3 100644 --- a/data/ai/lua/battle_calcs.lua +++ b/data/ai/lua/battle_calcs.lua @@ -677,8 +677,8 @@ function battle_calcs.battle_outcome(attacker, defender, cfg, cache) if (def_max_hits > att_strikes) then def_max_hits = att_strikes end -- Probability of landing a hit - local att_hit_prob = 1 - defender:defense_on(wesnoth.get_terrain(defender.x, defender.y)) / 100. - local def_hit_prob = 1 - attacker:defense_on(wesnoth.get_terrain(dst[1], dst[2])) / 100. + local att_hit_prob = 1 - defender:defense_on(wesnoth.current.map[defender]) / 100. + local def_hit_prob = 1 - attacker:defense_on(wesnoth.current.map[dst]) / 100. -- Magical: attack and defense, and under all circumstances if att_attack.magical then att_hit_prob = 0.7 end @@ -808,13 +808,15 @@ function battle_calcs.attack_rating(attacker, defender, dst, cfg, cache) if (att_stats.slowed ~= 0) then damage = damage + 6 * (att_stats.slowed - att_stats.hp_chance[0]) end + + local map = wesnoth.map.get -- If attack is from a healing location, count that as slightly more than the healing amount - damage = damage - 1.25 * wesnoth.get_terrain_info(wesnoth.get_terrain(dst[1], dst[2])).healing + damage = damage - 1.25 * wesnoth.terrain_types[map[dst]].healing -- Equivalently, if attack is adjacent to an unoccupied healing location, that's bad for xa,ya in H.adjacent_tiles(dst[1], dst[2]) do - local healing = wesnoth.get_terrain_info(wesnoth.get_terrain(xa, ya)).healing + local healing = wesnoth.terrain_types[map[{xa, ya}]].healing if (healing > 0) and (not wesnoth.units.get(xa, ya)) then damage = damage + 1.25 * healing end @@ -865,7 +867,7 @@ function battle_calcs.attack_rating(attacker, defender, dst, cfg, cache) end -- If defender is on a healing location, count that as slightly more than the healing amount - damage = damage - 1.25 * wesnoth.get_terrain_info(wesnoth.get_terrain(defender.x, defender.y)).healing + damage = damage - 1.25 * wesnoth.terrain_types[map[defender]].healing if (damage < 0) then damage = 0. end @@ -908,7 +910,7 @@ function battle_calcs.attack_rating(attacker, defender, dst, cfg, cache) -- If defender is on a village, add a bonus rating (we want to get rid of those preferentially) -- So yes, this is positive, even though it's a plus for the defender -- Note: defenders on healing locations also got a negative damage rating above (these don't exactly cancel each other though) - if wesnoth.get_terrain_info(wesnoth.get_terrain(defender.x, defender.y)).village then + if wesnoth.terrain_types[map[defender]].village then defender_value = defender_value * (1. + 10. / attacker.max_hitpoints) end @@ -924,7 +926,7 @@ function battle_calcs.attack_rating(attacker, defender, dst, cfg, cache) -- We don't need a bonus for good terrain for the attacker, as that is covered in the damage calculation -- However, we add a small bonus for good terrain defense of the _defender_ on the _attack_ hex -- This is in order to take good terrain away from defender on next move, all else being equal - local defender_defense = - (100 - defender:defense_on(wesnoth.get_terrain(dst[1], dst[2]))) / 100. + local defender_defense = - (100 - defender:defense_on(map[dst])) / 100. defender_value = defender_value + defender_defense * defense_weight -- Get a very small bonus for hexes in between defender and AI leader @@ -1316,7 +1318,7 @@ function battle_calcs.best_defense_map(units, cfg) if max_moves then unit.moves = old_moves end for _,loc in ipairs(reach) do - local defense = unit:defense_on(wesnoth.get_terrain(loc[1], loc[2])) + local defense = unit:defense_on(wesnoth.current.map[loc]) if (defense > (defense_map:get(loc[1], loc[2]) or - math.huge)) then defense_map:insert(loc[1], loc[2], defense) @@ -1524,7 +1526,7 @@ function battle_calcs.get_attack_combos_subset(units, enemy, cfg) -- Store information about it in 'loc' and add this to 'locs' -- Want coordinates (dst) and terrain defense (for sorting) loc.dst = xa * 1000 + ya - loc.hit_prob = 100 - unit:defense_on(wesnoth.get_terrain(xa, ya)) + loc.hit_prob = 100 - unit:defense_on(wesnoth.current.map[{xa, ya}]) table.insert(locs, loc) -- Also mark this hex as usable diff --git a/data/ai/lua/ca_castle_switch.lua b/data/ai/lua/ca_castle_switch.lua index e24ee7fdfa8a6..a20ba4774213c 100644 --- a/data/ai/lua/ca_castle_switch.lua +++ b/data/ai/lua/ca_castle_switch.lua @@ -33,7 +33,7 @@ end local function other_units_on_keep(leader) -- if we're on a keep, wait until there are no movable non-leader units on the castle before moving off local leader_score = high_score - if wesnoth.get_terrain_info(wesnoth.get_terrain(leader.x, leader.y)).keep then + if wesnoth.terrain_types[wesnoth.current.map[leader]].keep then local castle = AH.get_locations_no_borders { { "and", { x = leader.x, y = leader.y, radius = 200, @@ -172,13 +172,14 @@ function ca_castle_switch:evaluation(cfg, data, filter_own, recruiting_leader) -- If we're on a keep, -- don't move to another keep unless it's much better when uncaptured villages are present - if best_score > 0 and wesnoth.get_terrain_info(wesnoth.get_terrain(leader.x, leader.y)).keep then - local close_unowned_village = (wesnoth.get_villages { - { "and", { - x = leader.x, - y = leader.y, - radius = leader.max_moves - }}, + if best_score > 0 and wesnoth.terrain_types[wesnoth.current.map[leader]].keep then + local close_unowned_village = (wesnoth.map.find { + wml.tag['and']{ + x = leader.x, + y = leader.y, + radius = leader.max_moves + }, + gives_income = true, owner_side = 0 })[1] if close_unowned_village then @@ -199,8 +200,9 @@ function ca_castle_switch:evaluation(cfg, data, filter_own, recruiting_leader) if next_hop and ((next_hop[1] ~= leader.x) or (next_hop[2] ~= leader.y)) then -- See if there is a nearby village that can be captured without delaying progress - local close_villages = wesnoth.get_villages( { - { "and", { x = next_hop[1], y = next_hop[2], radius = leader.max_moves }}, + local close_villages = wesnoth.map.find( { + wml.tag["and"]{ x = next_hop[1], y = next_hop[2], radius = leader.max_moves }, + gives_income = true, owner_side = 0 }) local cheapest_unit_cost = AH.get_cheapest_recruit_cost(leader) for i,loc in ipairs(close_villages) do diff --git a/data/ai/lua/ca_grab_villages.lua b/data/ai/lua/ca_grab_villages.lua index 9579f9673b14e..3553c572734fb 100644 --- a/data/ai/lua/ca_grab_villages.lua +++ b/data/ai/lua/ca_grab_villages.lua @@ -28,7 +28,7 @@ function ca_grab_villages:evaluation(cfg, data, filter_own) local avoid_map = LS.of_pairs(ai.aspects.avoid) - local all_villages, villages = wesnoth.get_villages(), {} + local all_villages, villages = wesnoth.map.find{gives_income = true}, {} for _,village in ipairs(all_villages) do if (not avoid_map:get(village[1], village[2])) then table.insert(villages, village) @@ -69,7 +69,7 @@ function ca_grab_villages:evaluation(cfg, data, filter_own) end -- Unowned and enemy-owned villages get a large bonus - local owner = wesnoth.get_village_owner(v[1], v[2]) + local owner = wesnoth.map.get_owner(v) if (not owner) then village_rating = village_rating + 10000 else diff --git a/data/ai/lua/ca_recruit_rushers.lua b/data/ai/lua/ca_recruit_rushers.lua index 9c5feb371103a..07bd5d98c2bdd 100644 --- a/data/ai/lua/ca_recruit_rushers.lua +++ b/data/ai/lua/ca_recruit_rushers.lua @@ -20,7 +20,8 @@ if ca_castle_switch then params.leader_takes_village = (function(leader) local castle_switch_score = ca_castle_switch:evaluation({}, dummy_engine.data, nil, leader) if castle_switch_score > 0 then - local take_village = #(wesnoth.get_villages { + local take_village = #(wesnoth.map.find { + gives_income = true, x = dummy_engine.data.CS_leader_target[1], y = dummy_engine.data.CS_leader_target[2] }) > 0 diff --git a/data/ai/lua/ca_spread_poison.lua b/data/ai/lua/ca_spread_poison.lua index 4a21fc9e49f9a..3a267c2183e6c 100644 --- a/data/ai/lua/ca_spread_poison.lua +++ b/data/ai/lua/ca_spread_poison.lua @@ -54,8 +54,8 @@ function ca_spread_poison:evaluation(cfg, data, filter_own) local cant_poison = defender.status.poisoned or defender.status.unpoisonable -- For now, we also simply don't poison units on healing locations (unless standard combat CA does it) - local defender_terrain = wesnoth.get_terrain(defender.x, defender.y) - local healing = wesnoth.get_terrain_info(defender_terrain).healing + local defender_terrain = wesnoth.current.map[defender] + local healing = wesnoth.terrain_types[defender_terrain].healing -- Also, poisoning units that would level up through the attack or could level on their turn as a result is very bad local about_to_level = defender.max_experience - defender.experience <= (attacker.level * 2 * wesnoth.game_config.combat_experience) diff --git a/data/ai/lua/ca_village_hunt.lua b/data/ai/lua/ca_village_hunt.lua index 64eed19c55be6..a076267aa35d9 100644 --- a/data/ai/lua/ca_village_hunt.lua +++ b/data/ai/lua/ca_village_hunt.lua @@ -16,7 +16,7 @@ function ca_village_hunt:evaluation(cfg, data, filter_own) local avoid_map = LS.of_pairs(ai.aspects.avoid) - local all_villages, villages = wesnoth.get_villages(), {} + local all_villages, villages = wesnoth.map.find{gives_income = true}, {} for _,village in ipairs(all_villages) do if (not avoid_map:get(village[1], village[2])) then table.insert(villages, village) @@ -30,7 +30,7 @@ function ca_village_hunt:evaluation(cfg, data, filter_own) local n_my_villages, n_allied_villages = 0, 0 for _,village in ipairs(villages) do - local owner = wesnoth.get_village_owner(village[1], village[2]) or -1 + local owner = wesnoth.map.get_owner(village) or -1 if (owner == wesnoth.current.side) then n_my_villages = n_my_villages + 1 end @@ -66,7 +66,7 @@ function ca_village_hunt:evaluation(cfg, data, filter_own) for _,unit in ipairs(units) do local best_cost = AH.no_path for i,v in ipairs(villages) do - if not wesnoth.match_location(v[1], v[2], { {"filter_owner", { {"ally_of", { side = wesnoth.current.side }} }} }) then + if not wesnoth.map.matches(v, { {"filter_owner", { {"ally_of", { side = wesnoth.current.side }} }} }) then local path, cost = AH.find_path_with_avoid(unit, v[1], v[2], avoid_map) if (cost < best_cost) then local dst = AH.next_hop(unit, nil, nil, { path = path, avoid_map = avoid_map }) diff --git a/data/ai/lua/generic_recruit_engine.lua b/data/ai/lua/generic_recruit_engine.lua index a7bc1bba90fa3..8bd9fa91ce317 100644 --- a/data/ai/lua/generic_recruit_engine.lua +++ b/data/ai/lua/generic_recruit_engine.lua @@ -343,7 +343,7 @@ return { { "and", params.filter_own } }[1] - if (not leader) or (not wesnoth.get_terrain_info(wesnoth.get_terrain(leader.x, leader.y)).keep) then + if (not leader) or (not wesnoth.terrain_types[wesnoth.current.map[leader]).keep] then return 0 end @@ -694,8 +694,8 @@ return { end end if not enemy_location then - local width, height = wesnoth.get_map_size() - enemy_location = { x = width + 1 - reference_hex[1], y = height + 1 - reference_hex[2] } + local map = wesnoth.current.map + enemy_location = { x = map.playable_width + 1 - reference_hex[1], y = map.playable_height + 1 - reference_hex[2] } end distance_to_enemy = wesnoth.map.distance_between(reference_hex[1], reference_hex[2], enemy_location.x, enemy_location.y) end @@ -906,15 +906,15 @@ return { end end - local all_villages = wesnoth.get_villages() + local all_villages = wesnoth.map.find{gives_income = true} local villages = {} for _,v in ipairs(all_villages) do - local owner = wesnoth.get_village_owner(v[1], v[2]) + local owner = wesnoth.map.get_owner(v) if ((not owner) or wesnoth.sides.is_enemy(owner, wesnoth.current.side)) - and (not exclude_map:get(v[1], v[2])) + and (not exclude_map:get(v)) then for _,loc in ipairs(data.castle.locs) do - local dist = M.distance_between(v[1], v[2], loc[1], loc[2]) + local dist = M.distance_between(v, loc) if (dist <= fastest_unit_speed) then table.insert(villages, v) break @@ -966,7 +966,6 @@ return { end end - local width,height,border = wesnoth.get_map_size() if (not recruit_data.unit_distances) then recruit_data.unit_distances = {} end for i,v in ipairs(villages) do local close_castle_hexes = {} @@ -987,7 +986,7 @@ return { local viable_village = false local village_best_hex, village_shortest_distance = {}, AH.no_path for j,c in ipairs(close_castle_hexes) do - if c[1] > 0 and c[2] > 0 and c[1] <= width and c[2] <= height then + if wesnoth.current.map:on_board(c) then local distance = 0 for x,unit in ipairs(test_units) do local key = unit.type .. '_' .. v[1] .. '-' .. v[2] .. '_' .. c[1] .. '-' .. c[2] diff --git a/data/ai/lua/retreat.lua b/data/ai/lua/retreat.lua index 60e6b27248ec9..bb4bf07079237 100644 --- a/data/ai/lua/retreat.lua +++ b/data/ai/lua/retreat.lua @@ -21,7 +21,7 @@ function retreat_functions.min_hp(unit) if (caution_factor < 0) then caution_factor = 0 end caution_factor = math.sqrt(caution_factor) * 2 - local hp_per_level = (100 - unit:defense_on(wesnoth.get_terrain(unit.x, unit.y)))/15 * caution_factor + local hp_per_level = (100 - unit:defense_on(wesnoth.current.map[unit]))/15 * caution_factor local level = unit.level -- Leaders are considered to be higher level because of their value @@ -150,7 +150,7 @@ function retreat_functions.get_retreat_injured_units(healees, regen_amounts, avo local location_subset = {} for j,loc in ipairs(possible_locations) do if (not avoid_map) or (not avoid_map:get(loc[1], loc[2])) then - local heal_amount = wesnoth.get_terrain_info(wesnoth.get_terrain(loc[1], loc[2])).healing or 0 + local heal_amount = wesnoth.terrain_types[wesnoth.current.map[loc]].healing or 0 if heal_amount == true then -- handle deprecated syntax -- TODO: remove this when removed from game @@ -212,7 +212,7 @@ function retreat_functions.get_retreat_injured_units(healees, regen_amounts, avo rating = rating - enemy_count * 100000 -- Penalty based on terrain defense for unit - rating = rating - (100 - u:defense_on(wesnoth.get_terrain(loc[1], loc[2])))/10 + rating = rating - (100 - u:defense_on(wesnoth.current.map[loc]))/10 if (loc[1] == u.x) and (loc[2] == u.y) and (not u.status.poisoned) then if is_healthy or enemy_count == 0 then diff --git a/data/ai/micro_ais/cas/ca_assassin_move.lua b/data/ai/micro_ais/cas/ca_assassin_move.lua index 4d61d729113dd..c486e3656431f 100644 --- a/data/ai/micro_ais/cas/ca_assassin_move.lua +++ b/data/ai/micro_ais/cas/ca_assassin_move.lua @@ -24,7 +24,7 @@ local function custom_cost(x, y, unit, enemy_rating_map, prefer_map) -- non-preferred hexes rather than a bonus for preferred hexes as the cost function -- must return values >=1 for the a* search to work. - local terrain = wesnoth.get_terrain(x, y) + local terrain = wesnoth.current.map[{x, y}] local move_cost = unit:movement(terrain) move_cost = move_cost + (enemy_rating_map:get(x, y) or 0) @@ -95,7 +95,7 @@ function ca_assassin_move:execution(cfg) -- Penalties for damage by enemies local enemy_rating_map = LS.create() enemy_damage_map:iter(function(x, y, enemy_damage) - local hit_chance = (100 - unit:defense_on(wesnoth.get_terrain(x, y))) / 100. + local hit_chance = (100 - unit:defense_on(wesnoth.current.map[{x, y}])) / 100. local rating = hit_chance * enemy_damage rating = rating / unit.max_hitpoints @@ -131,7 +131,7 @@ function ca_assassin_move:execution(cfg) local prefer_slf = wml.get_child(cfg, "prefer") local prefer_map -- want this to be nil, not empty LS if [prefer] tag not given if prefer_slf then - local preferred_hexes = wesnoth.get_locations(prefer_slf) + local preferred_hexes = wesnoth.map.find(prefer_slf) prefer_map = LS.create() for _,hex in ipairs(preferred_hexes) do prefer_map:insert(hex[1], hex[2], true) diff --git a/data/ai/micro_ais/cas/ca_big_animals.lua b/data/ai/micro_ais/cas/ca_big_animals.lua index fe8a56316b57c..1f1ea8fb370ca 100644 --- a/data/ai/micro_ais/cas/ca_big_animals.lua +++ b/data/ai/micro_ais/cas/ca_big_animals.lua @@ -50,11 +50,9 @@ function ca_big_animals:execution(cfg) local reach_map = AH.get_reachable_unocc(unit) local wander_terrain = wml.get_child(cfg, "filter_location_wander") or {} - reach_map:iter( function(x, y, v) - -- Remove tiles that do not comform to the wander terrain filter - if (not wesnoth.match_location(x, y, wander_terrain)) then - reach_map:remove(x, y) - end + -- Remove tiles that do not comform to the wander terrain filter + reach_map = reach_map:filter(function(x, y, v) + return wesnoth.map.matches(x, y, wander_terrain) end) -- Now find the one of these hexes that is closest to the goal diff --git a/data/ai/micro_ais/cas/ca_bottleneck_move.lua b/data/ai/micro_ais/cas/ca_bottleneck_move.lua index d529f3c01db53..c9cbc4648a3db 100644 --- a/data/ai/micro_ais/cas/ca_bottleneck_move.lua +++ b/data/ai/micro_ais/cas/ca_bottleneck_move.lua @@ -21,41 +21,38 @@ local function bottleneck_is_my_territory(map, enemy_map) local dummy_unit = unit:clone() local territory_map = LS.create() - local width, height = wesnoth.get_map_size() - for x = 1,width do - for y = 1,height do - -- The hex might have been covered already previously - if (not territory_map:get(x,y)) then - dummy_unit.x, dummy_unit.y = x, y - - -- Find lowest movement cost to own front-line hexes - local min_cost, best_path = math.huge - map:iter(function(xm, ym, v) - local path, cost = AH.find_path_with_shroud(dummy_unit, xm, ym, { ignore_units = true }) - if (cost < min_cost) then - min_cost, best_path = cost, path - end - end) - - -- And the same to the enemy front line - local min_cost_enemy, best_path_enemy = math.huge - enemy_map:iter(function(xm, ym, v) - local path, cost = AH.find_path_with_shroud(dummy_unit, xm, ym, { ignore_units = true }) - if (cost < min_cost_enemy) then - min_cost_enemy, best_path_enemy = cost, path - end - end) + for x, y in wesnoth.current.map:iter() do + -- The hex might have been covered already previously + if (not territory_map:get(x,y)) then + dummy_unit.x, dummy_unit.y = x, y + + -- Find lowest movement cost to own front-line hexes + local min_cost, best_path = math.huge + map:iter(function(xm, ym, v) + local path, cost = AH.find_path_with_shroud(dummy_unit, xm, ym, { ignore_units = true }) + if (cost < min_cost) then + min_cost, best_path = cost, path + end + end) + + -- And the same to the enemy front line + local min_cost_enemy, best_path_enemy = math.huge + enemy_map:iter(function(xm, ym, v) + local path, cost = AH.find_path_with_shroud(dummy_unit, xm, ym, { ignore_units = true }) + if (cost < min_cost_enemy) then + min_cost_enemy, best_path_enemy = cost, path + end + end) - -- We can set the flags for the hexes along the entire path - -- for efficiency reasons (this is pretty slow, esp. on large maps) - if (min_cost < min_cost_enemy) then - for _,step in ipairs(best_path) do - territory_map:insert(step[1], step[2], true) - end - else -- We do need to use 0's in this case though, false won't work - for _,step in ipairs(best_path_enemy) do - territory_map:insert(step[1], step[2], 0) - end + -- We can set the flags for the hexes along the entire path + -- for efficiency reasons (this is pretty slow, esp. on large maps) + if (min_cost < min_cost_enemy) then + for _,step in ipairs(best_path) do + territory_map:insert(step[1], step[2], true) + end + else -- We do need to use 0's in this case though, false won't work + for _,step in ipairs(best_path_enemy) do + territory_map:insert(step[1], step[2], 0) end end end diff --git a/data/ai/micro_ais/cas/ca_fast_attack_utils.lua b/data/ai/micro_ais/cas/ca_fast_attack_utils.lua index 77c71fed72270..a2c5ac365baaf 100644 --- a/data/ai/micro_ais/cas/ca_fast_attack_utils.lua +++ b/data/ai/micro_ais/cas/ca_fast_attack_utils.lua @@ -47,7 +47,7 @@ function ca_fast_attack_utils.gamedata_setup() local gamedata = {} local village_map = {} - for _,village in ipairs(wesnoth.get_villages()) do + for _,village in ipairs(wesnoth.map.find{gives_income = true}) do if (not village_map[village[1]]) then village_map[village[1]] = {} end village_map[village[1]][village[2]] = true end @@ -56,7 +56,7 @@ function ca_fast_attack_utils.gamedata_setup() local healing_map = {} for _,loc in ipairs(AH.get_healing_locations {}) do if (not healing_map[loc[1]]) then healing_map[loc[1]] = {} end - healing_map[loc[1]][loc[2]] = wesnoth.get_terrain_info(wesnoth.get_terrain(loc[1], loc[2])).healing + healing_map[loc[1]][loc[2]] = wesnoth.terrain_types[wesnoth.current.map[loc]].healing end gamedata.healing_map = healing_map @@ -157,7 +157,7 @@ function ca_fast_attack_utils.get_unit_defense(unit_copy, x, y, defense_maps) if (not defense_maps[unit_copy.id][x]) then defense_maps[unit_copy.id][x] = {} end if (not defense_maps[unit_copy.id][x][y]) then - local defense = unit_copy:defense_on(wesnoth.get_terrain(x, y)) / 100. + local defense = unit_copy:defense_on(wesnoth.current.map[{x, y}]) / 100. defense_maps[unit_copy.id][x][y] = { defense = defense } end diff --git a/data/ai/micro_ais/cas/ca_fast_move.lua b/data/ai/micro_ais/cas/ca_fast_move.lua index c818b0805756a..c76eeb5542b98 100644 --- a/data/ai/micro_ais/cas/ca_fast_move.lua +++ b/data/ai/micro_ais/cas/ca_fast_move.lua @@ -30,15 +30,15 @@ function ca_fast_move:execution(cfg) -- Villages get added first, so that (hopefully, scouts and faster units will go for them first) local village_value = ai.aspects.village_value if leader and (village_value > 0) then - local villages = wesnoth.get_villages() + local villages = wesnoth.map.find{gives_income = true} -- Eliminate villages in avoid_map and those owned by an allied side -- Also remove unowned villages if the AI has no leader for i = #villages,1,-1 do - if avoid_map:get(villages[i][1], villages[i][2]) then + if avoid_map:get(villages[i]) then table.remove(villages, i) else - local owner = wesnoth.get_village_owner(villages[i][1], villages[i][2]) + local owner = wesnoth.map.get_owner(villages[i]) if owner and (not wesnoth.sides.is_enemy(owner, wesnoth.current.side)) then table.remove(villages, i) elseif (not leader) and (not owner) then diff --git a/data/ai/micro_ais/cas/ca_forest_animals_new_rabbit.lua b/data/ai/micro_ais/cas/ca_forest_animals_new_rabbit.lua index 7b92749d7dc69..73337fb62c084 100644 --- a/data/ai/micro_ais/cas/ca_forest_animals_new_rabbit.lua +++ b/data/ai/micro_ais/cas/ca_forest_animals_new_rabbit.lua @@ -21,10 +21,9 @@ function ca_forest_animals_new_rabbit:execution(cfg) -- Eliminate all holes that have an enemy within 'rabbit_enemy_distance' hexes -- We also add a random number to the ones we keep, for selection of the holes later - local width, height = wesnoth.get_map_size() local holes = {} for _,item in ipairs(all_items) do - if (item.x > 0) and (item.x <= width) and (item.y > 0) and (item.y <= height) then + if wesnoth.current.map:on_board(item) then local enemies = AH.get_attackable_enemies { { "filter_location", { x = item.x, y = item.y, radius = rabbit_enemy_distance } } } diff --git a/data/ai/micro_ais/cas/ca_goto.lua b/data/ai/micro_ais/cas/ca_goto.lua index 74f786cdf0905..a781c0dde1571 100644 --- a/data/ai/micro_ais/cas/ca_goto.lua +++ b/data/ai/micro_ais/cas/ca_goto.lua @@ -7,7 +7,7 @@ local MAISD = wesnoth.require "ai/micro_ais/micro_ai_self_data.lua" local M = wesnoth.map local function custom_cost(x, y, unit, avoid_map, enemy_map, enemy_attack_map, multiplier) - local terrain = wesnoth.get_terrain(x, y) + local terrain = wesnoth.current.map[{x, y}] local move_cost = unit:movement(terrain) if avoid_map and avoid_map:get(x, y) then diff --git a/data/ai/micro_ais/cas/ca_healer_move.lua b/data/ai/micro_ais/cas/ca_healer_move.lua index 945bf87e0471c..0ef2bad56a07e 100644 --- a/data/ai/micro_ais/cas/ca_healer_move.lua +++ b/data/ai/micro_ais/cas/ca_healer_move.lua @@ -41,7 +41,7 @@ function ca_healer_move:evaluation(cfg, data) -- Also, they cannot be on a healing location or regenerate if (healee.moves == 0) then if (not healee:matches { ability = "regenerates" }) then - local healing = wesnoth.get_terrain_info(wesnoth.get_terrain(healee.x, healee.y)).healing + local healing = wesnoth.terrain_types[wesnoth.current.map[healee]].healing if (healing == 0) then local is_healee = true for _,healer in ipairs(healers_noMP) do @@ -100,8 +100,8 @@ function ca_healer_move:evaluation(cfg, data) rating = rating - enemies_in_reach * 1000 -- All else being more or less equal, prefer villages and strong terrain - local terrain = wesnoth.get_terrain(x, y) - local is_village = wesnoth.get_terrain_info(terrain).village + local terrain = wesnoth.current.map[{x, y}] + local is_village = wesnoth.terrain_types[terrain].village if is_village then rating = rating + 2 end local defense = healer:defense_on(terrain) diff --git a/data/ai/micro_ais/cas/ca_herding_dog_move.lua b/data/ai/micro_ais/cas/ca_herding_dog_move.lua index 13d93bec76ba7..3d9c7b91a25b0 100644 --- a/data/ai/micro_ais/cas/ca_herding_dog_move.lua +++ b/data/ai/micro_ais/cas/ca_herding_dog_move.lua @@ -22,7 +22,7 @@ end function ca_herding_dog_move:execution(cfg) -- We simply move the first dog first, order does not matter local dog = get_dog(cfg) - local herding_perimeter = LS.of_pairs(wesnoth.get_locations(wml.get_child(cfg, "filter_location"))) + local herding_perimeter = LS.of_pairs(wesnoth.map.find(wml.get_child(cfg, "filter_location"))) -- Find average distance of herding_perimeter from center local herd_loc = AH.get_named_loc_xy('herd', cfg) diff --git a/data/ai/micro_ais/cas/ca_herding_f_herding_area.lua b/data/ai/micro_ais/cas/ca_herding_f_herding_area.lua index 4a40f1ac35dad..560ac58419bc4 100644 --- a/data/ai/micro_ais/cas/ca_herding_f_herding_area.lua +++ b/data/ai/micro_ais/cas/ca_herding_f_herding_area.lua @@ -7,7 +7,7 @@ return function(cfg) -- First, find all contiguous hexes around center hex that are inside herding_perimeter local location_filter = wml.get_child(cfg, "filter_location") local herd_loc = AH.get_named_loc_xy('herd', cfg) - local herding_area = LS.of_pairs(wesnoth.get_locations { + local herding_area = LS.of_pairs(wesnoth.map.find { x = herd_loc[1], y = herd_loc[2], radius = 999, @@ -17,7 +17,7 @@ return function(cfg) -- Then, also exclude hexes next to herding_perimeter; some of the functions work better like that herding_area:iter( function(x, y, v) for xa, ya in H.adjacent_tiles(x, y) do - if (wesnoth.match_location(xa, ya, location_filter) ) then + if (wesnoth.map.matches(xa, ya, location_filter) ) then herding_area:remove(x, y) end end diff --git a/data/ai/micro_ais/cas/ca_herding_herd_sheep.lua b/data/ai/micro_ais/cas/ca_herding_herd_sheep.lua index fd041cb74f832..5bbdcac4b35d9 100644 --- a/data/ai/micro_ais/cas/ca_herding_herd_sheep.lua +++ b/data/ai/micro_ais/cas/ca_herding_herd_sheep.lua @@ -63,7 +63,7 @@ function ca_herding_herd_sheep:execution(cfg) -- And the closer dog goes first (so that it might be able to chase another sheep afterward) rating = rating - M.distance_between(x, y, dog.x, dog.y) / 100. -- Finally, prefer to stay on path, if possible - if (wesnoth.match_location(x, y, wml.get_child(cfg, "filter_location")) ) then rating = rating + 0.001 end + if (wesnoth.map.matches(x, y, wml.get_child(cfg, "filter_location")) ) then rating = rating + 0.001 end reach_map:insert(x, y, rating) diff --git a/data/ai/micro_ais/cas/ca_lurkers.lua b/data/ai/micro_ais/cas/ca_lurkers.lua index a0ea25cdafcdb..34f972f599846 100644 --- a/data/ai/micro_ais/cas/ca_lurkers.lua +++ b/data/ai/micro_ais/cas/ca_lurkers.lua @@ -27,7 +27,7 @@ function ca_lurkers:execution(cfg) local reach = LS.of_pairs(wesnoth.find_reach(lurker.x, lurker.y)) local lurk_area = wml.get_child(cfg, "filter_location") local reachable_attack_terrain = - LS.of_pairs(wesnoth.get_locations { + LS.of_pairs(wesnoth.map.find { { "and", { x = lurker.x, y = lurker.y, radius = lurker.moves } }, { "and", lurk_area } }) @@ -46,7 +46,7 @@ function ca_lurkers:execution(cfg) for _,target in ipairs(targets) do -- Get reachable attack terrain next to target unit local reachable_attack_terrrain_adj_target = LS.of_pairs( - wesnoth.get_locations { x = target.x, y = target.y, radius = 1 } + wesnoth.map.find { x = target.x, y = target.y, radius = 1 } ) reachable_attack_terrrain_adj_target:inter(reachable_attack_terrain) @@ -63,7 +63,7 @@ function ca_lurkers:execution(cfg) -- If we got here, unit did not attack: go to random wander terrain hex if (lurker.moves > 0) and (not cfg.stationary) then local reachable_wander_terrain = - LS.of_pairs( wesnoth.get_locations { + LS.of_pairs( wesnoth.map.find { { "and", { x = lurker.x, y = lurker.y, radius = lurker.moves } }, { "and", wml.get_child(cfg, "filter_location_wander") or lurk_area } }) diff --git a/data/ai/micro_ais/cas/ca_protect_unit_move.lua b/data/ai/micro_ais/cas/ca_protect_unit_move.lua index 4110daa65aae6..21e77a18b7d57 100644 --- a/data/ai/micro_ais/cas/ca_protect_unit_move.lua +++ b/data/ai/micro_ais/cas/ca_protect_unit_move.lua @@ -47,7 +47,7 @@ function ca_protect_unit_move:execution(cfg, data) local terrain_defense_map = LS.create() reach_map:iter(function(x, y, data) - terrain_defense_map:insert(x, y, unit:defense_on(wesnoth.get_terrain(x, y))) + terrain_defense_map:insert(x, y, unit:defense_on(wesnoth.current.map[{x, y}])) end) local goal_distance_map = LS.create() diff --git a/data/ai/micro_ais/cas/ca_recruit_random.lua b/data/ai/micro_ais/cas/ca_recruit_random.lua index 56346cf0111f8..d6fa085a64e02 100644 --- a/data/ai/micro_ais/cas/ca_recruit_random.lua +++ b/data/ai/micro_ais/cas/ca_recruit_random.lua @@ -11,13 +11,12 @@ function ca_recruit_random:evaluation(cfg) -- Check if leader is on keep local leader = wesnoth.units.find_on_map { side = wesnoth.current.side, canrecruit = 'yes' }[1] - if (not leader) or (not wesnoth.get_terrain_info(wesnoth.get_terrain(leader.x, leader.y)).keep) then + if (not leader) or (not wesnoth.terrain_types[wesnoth.current.map[leader]).keep] then return 0 end -- Find all connected castle hexes local castle_map = LS.of_pairs({ { leader.x, leader.y } }) - local width, height, border = wesnoth.get_map_size() local new_castle_hex_found = true while new_castle_hex_found do @@ -26,11 +25,8 @@ function ca_recruit_random:evaluation(cfg) castle_map:iter(function(x, y) for xa,ya in H.adjacent_tiles(x, y) do - if (not castle_map:get(xa, ya)) - and (xa >= 1) and (xa <= width) - and (ya >= 1) and (ya <= height) - then - local is_castle = wesnoth.get_terrain_info(wesnoth.get_terrain(xa, ya)).castle + if (not castle_map:get(xa, ya)) and wesnoth.current.map:on_board(xa, ya) then + local is_castle = wesnoth.terrain_types[wesnoth.current.map[{xa, ya}]].castle if is_castle then table.insert(new_hexes, { xa, ya }) diff --git a/data/ai/micro_ais/cas/ca_stationed_guardian.lua b/data/ai/micro_ais/cas/ca_stationed_guardian.lua index e23c8987da74e..a10297242ad0a 100644 --- a/data/ai/micro_ais/cas/ca_stationed_guardian.lua +++ b/data/ai/micro_ais/cas/ca_stationed_guardian.lua @@ -61,7 +61,7 @@ function ca_stationed_guardian:execution(cfg) if (not AH.is_visible_unit(wesnoth.current.side, unit_in_way)) or (unit_in_way == guardian) then - local defense = guardian:defense_on(wesnoth.get_terrain(xa, ya)) + local defense = guardian:defense_on(wesnoth.current.map[{xa, ya}]) local nh = AH.next_hop(guardian, xa, ya) if nh then if (nh[1] == xa) and (nh[2] == ya) and (defense > best_defense) then diff --git a/data/ai/micro_ais/cas/ca_wolves_move.lua b/data/ai/micro_ais/cas/ca_wolves_move.lua index bb82f11e093b2..05272cc9b99fa 100644 --- a/data/ai/micro_ais/cas/ca_wolves_move.lua +++ b/data/ai/micro_ais/cas/ca_wolves_move.lua @@ -65,16 +65,16 @@ function ca_wolves_move:execution(cfg) table.sort(wolves, function(a, b) return M.distance_between(a.x, a.y, target.x, target.y) > M.distance_between(b.x, b.y, target.x, target.y) end) - + -- First wolf moves toward target, but tries to stay away from map edges - local width, height = wesnoth.get_map_size() local wolf1 = AH.find_best_move(wolves[1], function(x, y) local dist_1t = M.distance_between(x, y, target.x, target.y) local rating = - dist_1t + local map = wesnoth.current.map if (x <= 5) then rating = rating - (6 - x) / 1.4 end if (y <= 5) then rating = rating - (6 - y) / 1.4 end - if (width - x <= 5) then rating = rating - (6 - (width - x)) / 1.4 end - if (height - y <= 5) then rating = rating - (6 - (height - y)) / 1.4 end + if (map.playable_width - x <= 5) then rating = rating - (6 - (map.playable_width - x)) / 1.4 end + if (map.playable_height - y <= 5) then rating = rating - (6 - (map.playable_height - y)) / 1.4 end -- Hexes that avoid_type units can reach get a massive penalty if avoid_enemies_map:get(x, y) then rating = rating - 1000 end diff --git a/data/ai/micro_ais/cas/ca_zone_guardian.lua b/data/ai/micro_ais/cas/ca_zone_guardian.lua index ae1f78ff772b8..132c97b25967a 100644 --- a/data/ai/micro_ais/cas/ca_zone_guardian.lua +++ b/data/ai/micro_ais/cas/ca_zone_guardian.lua @@ -46,7 +46,7 @@ function ca_zone_guardian:execution(cfg) if (not AH.is_visible_unit(wesnoth.current.side, unit_in_way)) or (unit_in_way == guardian) then - local defense = guardian:defense_on(wesnoth.get_terrain(xa, ya)) + local defense = guardian:defense_on(wesnoth.current.map[{xa, ya}]) local nh = AH.next_hop(guardian, xa, ya) if nh then if (nh[1] == xa) and (nh[2] == ya) and (defense > best_defense) then diff --git a/data/campaigns/Descent_Into_Darkness/scenarios/04_Spring_of_Reprisal.cfg b/data/campaigns/Descent_Into_Darkness/scenarios/04_Spring_of_Reprisal.cfg index c9828fe9e52e1..19afa02e6b2ab 100644 --- a/data/campaigns/Descent_Into_Darkness/scenarios/04_Spring_of_Reprisal.cfg +++ b/data/campaigns/Descent_Into_Darkness/scenarios/04_Spring_of_Reprisal.cfg @@ -160,7 +160,7 @@ -- table needs to be VERY complete. Or, rename this to morph_terrain and -- have the conversion table come in as an argument, too. -local locations = wesnoth.get_locations{terrain = 'Gd,Gd^Es,Gd^Em,Gd^Fmw,Gd^Fdw,Hh,Hh^Fdw,Hh^Fmw,Mm,Mm^Xm'} +local locations = wesnoth.map.find{terrain = 'Gd,Gd^Es,Gd^Em,Gd^Fmw,Gd^Fdw,Hh,Hh^Fdw,Hh^Fmw,Mm,Mm^Xm'} local coverage = 0.25 -- Constant 25% random coverage. @@ -186,8 +186,8 @@ local loopCounter for loopCounter = 1, snowNeeded do local locationsIndex = wesnoth.random(#locations) local coordinate = locations[locationsIndex] - local terrainCode = wesnoth.get_terrain(coordinate[1], coordinate[2]) - wesnoth.set_terrain(coordinate[1], coordinate[2], (convert[terrainCode] or terrainCode)) + local terrainCode = wesnoth.current.map[coordinate] + wesnoth.current.map[coordinate] = (convert[terrainCode] or terrainCode) table.remove(locations, locationsIndex) end >> diff --git a/data/campaigns/Eastern_Invasion/ai/ca_ogres_flee.lua b/data/campaigns/Eastern_Invasion/ai/ca_ogres_flee.lua index d27d830b3b199..519bb7407159d 100644 --- a/data/campaigns/Eastern_Invasion/ai/ca_ogres_flee.lua +++ b/data/campaigns/Eastern_Invasion/ai/ca_ogres_flee.lua @@ -18,8 +18,6 @@ function ca_ogres_flee:execution() formula = 'movement_left = 0' } - local width, height = wesnoth.get_map_size() - -- Need the enemy map and enemy attack map if avoid_enemies is set local enemies = wesnoth.units.find_on_map { { "filter_side", { {"enemy_of", {side = wesnoth.current.side} } } } } local enemy_attack_map = BC.get_attack_map(enemies) @@ -33,11 +31,12 @@ function ca_ogres_flee:execution() if (not unit_in_way) or (unit_in_way == u) then -- First rating is distance from a map edge + local map = wesnoth.current.map local dist_left = r[1] - 1 - local dist_right = width - r[1] + local dist_right = map.playable_width - r[1] local dist_top_left = M.distance_between(r[1], r[2], 4, 1) local dist_top_right = M.distance_between(r[1], r[2], 40, 1) - local dist_bottom = height - r[2] + local dist_bottom = map.playable_height - r[2] local dist = math.min(dist_left, dist_right, dist_top_left, dist_top_right, dist_bottom) local rating = - dist diff --git a/data/campaigns/Eastern_Invasion/lua/bandits.lua b/data/campaigns/Eastern_Invasion/lua/bandits.lua index eceecbb8d1066..3f579e371a6b7 100644 --- a/data/campaigns/Eastern_Invasion/lua/bandits.lua +++ b/data/campaigns/Eastern_Invasion/lua/bandits.lua @@ -17,7 +17,7 @@ function wml_actions.spread_bandit_villages(cfg) vars.boss_found = false vars.bandit_types = types - local villages = wesnoth.get_villages(cfg) + local villages = wesnoth.map.find{gives_income = true, wml.tag['and'](cfg)} -- Shouldn't happen in the scenario, but a failsafe is always nice. if count > #villages then count = #villages end @@ -45,7 +45,7 @@ local function bandits_found(x,y) local radius = 1 local locs repeat - locs = wesnoth.get_locations({T["not"] { T.filter {} } , T["and"] { x = x, y = y, radius = radius } }) + locs = wesnoth.map.find({T["not"] { T.filter {} } , T["and"] { x = x, y = y, radius = radius } }) radius = radius + 1 until locs[1] @@ -62,7 +62,7 @@ local function bandits_found(x,y) if rand3 <= boss_chance or #bandit_villages < 3 then vars.boss_found = true - local loc = wesnoth.get_locations({T["not"] { T.filter {} } , T["and"] { x = x, y = y, radius = 2 } })[1] + local loc = wesnoth.map.find({T["not"] { T.filter {} } , T["and"] { x = x, y = y, radius = 2 } })[1] wesnoth.fire_event("boss_found", x, y, loc[1], loc[2]) end end diff --git a/data/campaigns/Heir_To_The_Throne/scenarios/13_The_Dwarven_Doors.cfg b/data/campaigns/Heir_To_The_Throne/scenarios/13_The_Dwarven_Doors.cfg index 428c7b5d9b6c1..64969ce01b6ed 100644 --- a/data/campaigns/Heir_To_The_Throne/scenarios/13_The_Dwarven_Doors.cfg +++ b/data/campaigns/Heir_To_The_Throne/scenarios/13_The_Dwarven_Doors.cfg @@ -164,7 +164,7 @@ -- table needs to be VERY complete. Or, rename this to morph_terrain and -- have the conversion table come in as an argument, too. -local locations = wesnoth.get_locations{terrain = 'Ce,Ch,Chr,Co,Gd,Gd^Vc,Gd^Vh,Gd^Vo,Gll^Fp,Hhd,Hhd^Fp,Hhd^Vo,Ke,Khr,Ko,Md,Mm,Rd,Re,Re^Vo,Rr,Ww'} +local locations = wesnoth.map.find{terrain = 'Ce,Ch,Chr,Co,Gd,Gd^Vc,Gd^Vh,Gd^Vo,Gll^Fp,Hhd,Hhd^Fp,Hhd^Vo,Ke,Khr,Ko,Md,Mm,Rd,Re,Re^Vo,Rr,Ww'} local coverage = wml.variables.snowCoverage wml.variables.snowCoverage = nil @@ -206,8 +206,8 @@ local loopCounter for loopCounter = 1, snowNeeded do local locationsIndex = wesnoth.random(#locations) local coordinate = locations[locationsIndex] - local terrainCode = wesnoth.get_terrain(coordinate[1], coordinate[2]) - wesnoth.set_terrain(coordinate[1], coordinate[2], (convert[terrainCode] or terrainCode)) + local terrainCode = wesnoth.current.map[coordinate] + wesnoth.current.map[coordinate] = (convert[terrainCode] or terrainCode) table.remove(locations, locationsIndex) end >> diff --git a/data/campaigns/Northern_Rebirth/lua/respawn_utils.lua b/data/campaigns/Northern_Rebirth/lua/respawn_utils.lua index 17b2c89d5136f..33d0b7b98ea1a 100644 --- a/data/campaigns/Northern_Rebirth/lua/respawn_utils.lua +++ b/data/campaigns/Northern_Rebirth/lua/respawn_utils.lua @@ -12,7 +12,7 @@ function wesnoth.wml_actions.find_respawn_point(cfg) end repeat - respawn_point = wesnoth.get_locations({ + respawn_point = wesnoth.map.find({ include_borders = false, T["and"] { T.filter { diff --git a/data/campaigns/Son_Of_The_Black_Eye/ai/ca_transport_S6.lua b/data/campaigns/Son_Of_The_Black_Eye/ai/ca_transport_S6.lua index 10913a5d7bac7..fabc18d68921f 100644 --- a/data/campaigns/Son_Of_The_Black_Eye/ai/ca_transport_S6.lua +++ b/data/campaigns/Son_Of_The_Black_Eye/ai/ca_transport_S6.lua @@ -47,7 +47,7 @@ function ca_transport:execution() -- First see if a transport is within landing distance local landing_site_map = LS.of_pairs( - wesnoth.get_locations { + wesnoth.map.find { terrain = 'W*', { "filter_adjacent_location", { terrain = '!, W*' } } } @@ -74,10 +74,10 @@ function ca_transport:execution() if (rating >= -0.05) then for x,y in H.adjacent_tiles(r[1], r[2]) do if (not unit_map:get(x, y)) then - if wesnoth.match_location(x, y, { terrain = "!, W*" }) then + if wesnoth.map.matches(x, y, { terrain = "!, W*" }) then rating = rating + 1 table.insert(adj_tiles, { x, y, 1. } ) - elseif wesnoth.match_location(x, y, + elseif wesnoth.map.matches(x, y, { terrain = "W*", { "filter_adjacent_location", { terrain = "!, W*" } } @@ -122,7 +122,7 @@ function ca_transport:execution() -- If we got here, no landing site was found. Do a deep-water move instead local deep_water_map = LS.of_pairs( - wesnoth.get_locations { + wesnoth.map.find { terrain = 'Wo', { "not", { { "filter_adjacent_location", { terrain = '!, Wo' } } } } } diff --git a/data/campaigns/The_Hammer_of_Thursagan/lua/spawns.lua b/data/campaigns/The_Hammer_of_Thursagan/lua/spawns.lua index b4d566d893ed8..b9eefac280d4c 100644 --- a/data/campaigns/The_Hammer_of_Thursagan/lua/spawns.lua +++ b/data/campaigns/The_Hammer_of_Thursagan/lua/spawns.lua @@ -14,8 +14,8 @@ function wml_actions.spawn_units(cfg) local done = 0 for i=1,count do - local locs = wesnoth.get_locations({T["not"] { T.filter {} } , T["and"] { x = x, y = y, radius = 1 } }) - if #locs == 0 then locs = wesnoth.get_locations({T["not"] { T.filter {} } , T["and"] { x = x, y = y, radius = 2 } }) end + local locs = wesnoth.map.find({T["not"] { T.filter {} } , T["and"] { x = x, y = y, radius = 1 } }) + if #locs == 0 then locs = wesnoth.map.find({T["not"] { T.filter {} } , T["and"] { x = x, y = y, radius = 2 } }) end if #locs == 0 then break end done = done + 1 diff --git a/data/campaigns/The_Hammer_of_Thursagan/scenarios/05_Fear.cfg b/data/campaigns/The_Hammer_of_Thursagan/scenarios/05_Fear.cfg index b21d4485bff33..8ea1a4072dead 100644 --- a/data/campaigns/The_Hammer_of_Thursagan/scenarios/05_Fear.cfg +++ b/data/campaigns/The_Hammer_of_Thursagan/scenarios/05_Fear.cfg @@ -397,7 +397,7 @@ local radius = 1 local locs repeat - locs = wesnoth.get_locations({T["not"] { T.filter {} } , T["and"] { x = x, y = y, radius = radius } }) + locs = wesnoth.map.find({T["not"] { T.filter {} } , T["and"] { x = x, y = y, radius = radius } }) radius = radius + 1 until locs[1] diff --git a/data/campaigns/Two_Brothers/ai/ca_muff_toras_move.lua b/data/campaigns/Two_Brothers/ai/ca_muff_toras_move.lua index 69c1916d05f5c..79c4e77448a2b 100644 --- a/data/campaigns/Two_Brothers/ai/ca_muff_toras_move.lua +++ b/data/campaigns/Two_Brothers/ai/ca_muff_toras_move.lua @@ -45,7 +45,7 @@ function muff_toras_move:execution() end -- All else being equal, go with good terrain - local hit_chance = muff_toras:defense(wesnoth.get_terrain(x, y)) + local hit_chance = muff_toras:defense(wesnoth.current.map[{x, y}]) rating = rating - hit_chance -- Finally, we want to run away from enemies if there are no other factors. diff --git a/data/campaigns/World_Conquest/lua/campaign/autorecall.lua b/data/campaigns/World_Conquest/lua/campaign/autorecall.lua index 9bbc654bc004a..3e37e7bad4748 100644 --- a/data/campaigns/World_Conquest/lua/campaign/autorecall.lua +++ b/data/campaigns/World_Conquest/lua/campaign/autorecall.lua @@ -2,7 +2,7 @@ local on_event = wesnoth.require("on_event") -- players get recalled by free all heroes up to castle size local function wc2_autorecall() for side_num = 1, wml.variables.wc2_player_count do - local castle_tiles = wesnoth.get_locations { + local castle_tiles = wesnoth.map.find { terrain = "C*", wml.tag["and"] { radius = 3, diff --git a/data/campaigns/World_Conquest/lua/campaign/enemy.lua b/data/campaigns/World_Conquest/lua/campaign/enemy.lua index 4948c4d3e24d0..964e3b7765e2f 100644 --- a/data/campaigns/World_Conquest/lua/campaign/enemy.lua +++ b/data/campaigns/World_Conquest/lua/campaign/enemy.lua @@ -125,7 +125,7 @@ on_event("recruit", function(ec) if #to_recall == 0 then return end - local candidates = wesnoth.get_locations { + local candidates = wesnoth.map.find { terrain = "K*,C*,*^C*,*^K*", wml.tag["and"] { wml.tag.filter { diff --git a/data/campaigns/World_Conquest/lua/campaign/enemy_themed.lua b/data/campaigns/World_Conquest/lua/campaign/enemy_themed.lua index 0269cfdecfe04..210dbf2c74404 100644 --- a/data/campaigns/World_Conquest/lua/campaign/enemy_themed.lua +++ b/data/campaigns/World_Conquest/lua/campaign/enemy_themed.lua @@ -31,7 +31,7 @@ local function wct_map_enemy_themed(race, pet, castle, village, chance) return end --give themed castle - wesnoth.set_terrain(boss.loc, "K" .. castle, "base") + wesnoth.current.map[boss] = wesnoth.map.replace_base("K" .. castle) wesnoth.wml_actions.terrain { terrain="C" .. castle, wml.tag["and"] { @@ -48,7 +48,7 @@ local function wct_map_enemy_themed(race, pet, castle, village, chance) }, }, } - local elvish_castle = wesnoth.get_locations { + local elvish_castle = wesnoth.map.find { terrain="Cv", wml.tag.filter_adjacent_location { terrain="Kv^*" @@ -57,7 +57,7 @@ local function wct_map_enemy_themed(race, pet, castle, village, chance) -- extra tweak with trees to elvish castle for i, tile in ipairs(elvish_castle) do if wesnoth.random(10) <= 4 then - wesnoth.set_terrain(tile, "Cv^Fet") + wesnoth.current.map[tile] = "Cv^Fet" end end -- adjacent themed villages diff --git a/data/campaigns/World_Conquest/lua/game_mechanics/bonus.lua b/data/campaigns/World_Conquest/lua/game_mechanics/bonus.lua index bf04963dc5df2..142a4b33748a1 100644 --- a/data/campaigns/World_Conquest/lua/game_mechanics/bonus.lua +++ b/data/campaigns/World_Conquest/lua/game_mechanics/bonus.lua @@ -37,7 +37,7 @@ end function bonus.place_item(x, y, image) if image == "campfire" then - wesnoth.set_terrain(x, y, "*^Ecf", "overlay") + wesnoth.current.map[{x, y}] = "^Ecf" image = nil else image = image or "scenery/lighthouse.png" @@ -134,7 +134,7 @@ end function bonus.get_random_hero(x, y) return wc2_utils.pick_random_filtered("wc2.random_heroes", wc2_era.generate_bonus_heroes, function(unittypeid) for _, sf in ipairs(wc2_era.spawn_filters) do - if sf.types[unittypeid] and not wesnoth.match_location(x, y, sf.filter_location) then + if sf.types[unittypeid] and not wesnoth.map.matches(x, y, sf.filter_location) then return false end end diff --git a/data/campaigns/World_Conquest/lua/game_mechanics/supply.lua b/data/campaigns/World_Conquest/lua/game_mechanics/supply.lua index ab9448194484a..58d38dac68ff6 100644 --- a/data/campaigns/World_Conquest/lua/game_mechanics/supply.lua +++ b/data/campaigns/World_Conquest/lua/game_mechanics/supply.lua @@ -17,9 +17,9 @@ local supply_images = function wesnoth.wml_actions.wc2_map_supply_village(t) local unit = wesnoth.units.get(t.x, t.y) local loc = unit.loc - wesnoth.set_terrain(loc, "Kh^Vov", "overlay") + wesnoth.current.map[loc] = "^Vov" - wesnoth.set_village_owner(loc, unit.side, false) + wesnoth.map.set_owner(loc, unit.side, false) local supply_image = ((wml.variables.wc2_supply_image_counter or 0) % #supply_images ) + 1 wml.variables.wc2_supply_image_counter = supply_image diff --git a/data/campaigns/World_Conquest/lua/map/generator/utilities.lua b/data/campaigns/World_Conquest/lua/map/generator/utilities.lua index 0a4d7e5001588..8d791d701f526 100644 --- a/data/campaigns/World_Conquest/lua/map/generator/utilities.lua +++ b/data/campaigns/World_Conquest/lua/map/generator/utilities.lua @@ -246,12 +246,12 @@ function default_generate_map(data) for i = 1, 20 do local status, map = pcall(function() cfg.seed = wesnoth.random(5000) + 7 - return wesnoth.generate_default_map(w, h, cfg) + return wesnoth.map.generate(w, h, cfg) end) if status then return map end end cfg.seed = wesnoth.random(5000) + 7 - return wesnoth.generate_default_map(w, h, cfg) + return wesnoth.map.generate(w, h, cfg) end diff --git a/data/campaigns/World_Conquest/lua/map/postgeneration/1A_Start.lua b/data/campaigns/World_Conquest/lua/map/postgeneration/1A_Start.lua index 47399e9f21897..bd3535156ee60 100644 --- a/data/campaigns/World_Conquest/lua/map/postgeneration/1A_Start.lua +++ b/data/campaigns/World_Conquest/lua/map/postgeneration/1A_Start.lua @@ -65,7 +65,7 @@ function world_conquest_tek_map_decoration_1() while #terrain_to_change > 0 and wesnoth.random(2) == 1 do local i = wesnoth.random(#terrain_to_change) - map:set_terrain(terrain_to_change[i], "Wwf") + map[terrain_to_change[i]] = "Wwf" terrain_to_change = wct_store_possible_encampment_ford() end diff --git a/data/campaigns/World_Conquest/lua/map/postgeneration/2A_Springs.lua b/data/campaigns/World_Conquest/lua/map/postgeneration/2A_Springs.lua index 7651e614f4aeb..3708e2bfba8c6 100644 --- a/data/campaigns/World_Conquest/lua/map/postgeneration/2A_Springs.lua +++ b/data/campaigns/World_Conquest/lua/map/postgeneration/2A_Springs.lua @@ -28,7 +28,7 @@ function world_conquest_tek_map_decoration_2a() local r = wesnoth.random(0, #terrain_to_change - 3) for i = 1, r do local loc = terrain_to_change[wesnoth.random(#terrain_to_change)] - map:set_terrain(loc, "Hh^Ftp") + map[loc] = "Hh^Ftp" end end end @@ -41,7 +41,7 @@ function world_conquest_tek_map_decoration_2a() local r = wesnoth.random(0, #terrain_to_change - 3) for i = 1, r do local loc = terrain_to_change[wesnoth.random(#terrain_to_change)] - map:set_terrain(loc, "Gs^Ftp") + map[loc] = "Gs^Ftp" end end end @@ -154,7 +154,7 @@ function world_conquest_tek_map_decoration_2a() local terrain_to_change = wct_store_possible_flowers("G*^Fet") while #terrain_to_change > 0 and wesnoth.random(10) ~= 1 do local loc = terrain_to_change[wesnoth.random(#terrain_to_change)] - map:set_terrain(loc, "Gg^Efm", "overlay") + map[loc] = "^Efm" local terrain_to_change = wct_store_possible_flowers("G*^Fet") end -- extra coast diff --git a/data/campaigns/World_Conquest/lua/map/postgeneration/2C_Glaciers.lua b/data/campaigns/World_Conquest/lua/map/postgeneration/2C_Glaciers.lua index 9c5fe29177c89..2c710f952397a 100644 --- a/data/campaigns/World_Conquest/lua/map/postgeneration/2C_Glaciers.lua +++ b/data/campaigns/World_Conquest/lua/map/postgeneration/2C_Glaciers.lua @@ -145,7 +145,7 @@ function world_conquest_tek_map_decoration_2c() -- base amount in map surface local r = helper.rand(tostring(total_tiles // 285) .. ".." .. tostring(total_tiles // 150)) for i = 1, math.min(r, #terrain_to_change) do - map:set_terrain(terrain_to_change[i], "Ai") + map[terrain_to_change[i]] = "Ai" end local icepack_candiates = map:get_locations(f.all( diff --git a/data/campaigns/World_Conquest/lua/map/postgeneration/2D_Provinces.lua b/data/campaigns/World_Conquest/lua/map/postgeneration/2D_Provinces.lua index eb1f248594b98..d75cc8db4964d 100644 --- a/data/campaigns/World_Conquest/lua/map/postgeneration/2D_Provinces.lua +++ b/data/campaigns/World_Conquest/lua/map/postgeneration/2D_Provinces.lua @@ -16,7 +16,7 @@ end function wct_provinces_castle(terrain_to_change, terrain) if #terrain_to_change > 0 then local loc = terrain_to_change[wesnoth.random(#terrain_to_change)] - map:set_terrain(loc, terrain) + map[loc] = terrain end end diff --git a/data/campaigns/World_Conquest/lua/map/postgeneration/2E_Paradise.lua b/data/campaigns/World_Conquest/lua/map/postgeneration/2E_Paradise.lua index 9734cf108c319..0c297ccee7879 100644 --- a/data/campaigns/World_Conquest/lua/map/postgeneration/2E_Paradise.lua +++ b/data/campaigns/World_Conquest/lua/map/postgeneration/2E_Paradise.lua @@ -58,7 +58,7 @@ function world_conquest_tek_map_repaint_2e() local terrain_to_change = wct_store_empty_citadel() while #terrain_to_change > 0 do local loc = terrain_to_change[wesnoth.random(#terrain_to_change)] - map:set_terrain(loc, "Rr^Vhc") + map[loc] = "Rr^Vhc" terrain_to_change = wct_store_empty_citadel() end -- improve roads quality @@ -137,7 +137,7 @@ function wct_map_yard(directions, counter_directions) if #terrain_to_change > 0 then local loc = terrain_to_change[wesnoth.random(#terrain_to_change)] - map:set_terrain(loc, "Gg^Eff") + map[loc] = "Gg^Eff" set_terrain { "Gg^Eff", f.adjacent( f.is_loc(loc), counter_directions, nil) } @@ -203,7 +203,7 @@ function wct_map_decoration_3e_leantos() )) for i, v in ipairs(terrain_to_change) do if wesnoth.random(3) == 1 then - map:set_terrain(v, "Rrc") + map[v] = "Rrc" table.insert(prestart_event, wml.tag.item { x = v[1], diff --git a/data/campaigns/World_Conquest/lua/map/postgeneration/3C_Delta.lua b/data/campaigns/World_Conquest/lua/map/postgeneration/3C_Delta.lua index bf4ea9a069346..3f9a72e459b0d 100644 --- a/data/campaigns/World_Conquest/lua/map/postgeneration/3C_Delta.lua +++ b/data/campaigns/World_Conquest/lua/map/postgeneration/3C_Delta.lua @@ -58,7 +58,7 @@ function world_conquest_tek_map_constructor_delta() -- note: the reason why i didnt add support for lua functions yet is that i -- might want lua filter objects to be serializable. if is_in_octaegon(loc[1], loc[2]) then - map:set_terrain(loc, "Wwf") + map[loc] = "Wwf" end end end diff --git a/data/campaigns/World_Conquest/lua/map/postgeneration/3F_Wetland.lua b/data/campaigns/World_Conquest/lua/map/postgeneration/3F_Wetland.lua index 8e719fdf0049b..56c08a11cc993 100644 --- a/data/campaigns/World_Conquest/lua/map/postgeneration/3F_Wetland.lua +++ b/data/campaigns/World_Conquest/lua/map/postgeneration/3F_Wetland.lua @@ -12,7 +12,7 @@ function world_conquest_tek_map_repaint_3f() while #terrain_to_change > 0 do -- the oriignal code also did not randomize this. -- todo: but maybe we should? (use wesnoth.random(#terrain_to_change[) instead of 1 here) - map:set_terrain(terrain_to_change[1], "Mm") + map[terrain_to_change[1]] = "Mm" terrain_to_change = wct_store_cave_passages_candidates() end set_terrain { "Gd", diff --git a/data/campaigns/World_Conquest/lua/map/postgeneration/4A_Thermal.lua b/data/campaigns/World_Conquest/lua/map/postgeneration/4A_Thermal.lua index d3df21894138d..4d541ce4fc555 100644 --- a/data/campaigns/World_Conquest/lua/map/postgeneration/4A_Thermal.lua +++ b/data/campaigns/World_Conquest/lua/map/postgeneration/4A_Thermal.lua @@ -152,7 +152,7 @@ function world_conquest_tek_map_decoration_4a() local terrain_to_change = wct_store_possible_flowers("Rr^Vhc") while #terrain_to_change > 0 and wesnoth.random(10) > 5 do local loc = terrain_to_change[wesnoth.random(#terrain_to_change)] - map:set_terrain(loc, "Gg^Efm", "overlay") + map[loc] = "^Efm" terrain_to_change = wct_store_possible_flowers("Rr^Vhc") end -- 1.12 new forest diff --git a/data/campaigns/World_Conquest/lua/map/postgeneration/4B_Volcanic.lua b/data/campaigns/World_Conquest/lua/map/postgeneration/4B_Volcanic.lua index 44e019f2c597e..f978429b017cd 100644 --- a/data/campaigns/World_Conquest/lua/map/postgeneration/4B_Volcanic.lua +++ b/data/campaigns/World_Conquest/lua/map/postgeneration/4B_Volcanic.lua @@ -281,7 +281,7 @@ function world_conquest_tek_map_repaint_4b() local r = helper.rand(tostring(total_tiles // 600) .. ".." .. tostring(total_tiles // 300)) for mush_i = 1, math.min(r, #terrain_to_change) do - map:set_terrain(terrain_to_change[mush_i], "Hhd^Uf") + map[terrain_to_change[mush_i]] = "Hhd^Uf" end -- chances of few orcish castles wct_possible_map4_castle("Co", 2) @@ -356,11 +356,11 @@ function world_conquest_tek_map_repaint_4b() helper.shuffle(terrain_to_change) for i = 1, #terrain_to_change // wesnoth.random(3, 4) do - map:set_terrain(terrain_to_change[i], "Ds^Esd") + map[terrain_to_change[i]] = "Ds^Esd" end helper.shuffle(terrain_to_change) for i = 1, #terrain_to_change // 6 do - map:set_terrain(terrain_to_change[i], "Ds^Es") + map[terrain_to_change[i]] = "Ds^Es" end set_terrain { "Dd^Es", f.terrain("Dd"), diff --git a/data/campaigns/World_Conquest/lua/map/postgeneration/4C_Mines.lua b/data/campaigns/World_Conquest/lua/map/postgeneration/4C_Mines.lua index dd3c3e640fba0..5548e404594f9 100644 --- a/data/campaigns/World_Conquest/lua/map/postgeneration/4C_Mines.lua +++ b/data/campaigns/World_Conquest/lua/map/postgeneration/4C_Mines.lua @@ -264,11 +264,11 @@ function wct_map_4c_post_bunus_decoration() for forge_i, v in ipairs(terrain_to_change) do local r = wesnoth.random(6) if r == 1 then - map:set_terrain(v, "Cud") + map[v] = "Cud" elseif r == 2 then - map:set_terrain(v, "Kud") + map[v] = "Kud" elseif r == 3 then - map:set_terrain(v, "Kv") + map[v] = "Kv" end end diff --git a/data/campaigns/World_Conquest/lua/map/postgeneration/6A_Rural.lua b/data/campaigns/World_Conquest/lua/map/postgeneration/6A_Rural.lua index 269782d043de1..f00034f07aea7 100644 --- a/data/campaigns/World_Conquest/lua/map/postgeneration/6A_Rural.lua +++ b/data/campaigns/World_Conquest/lua/map/postgeneration/6A_Rural.lua @@ -271,7 +271,7 @@ local function world_conquest_tek_map_decoration_6a() local terrain_to_change = wct_store_possible_dwarven_castle() while #terrain_to_change > 0 and wesnoth.random(2) == 1 do local loc = terrain_to_change[wesnoth.random(#terrain_to_change)] - map:set_terrain(loc, "Cud") + map[loc] = "Cud" terrain_to_change = wct_store_possible_dwarven_castle() end -- decorative farmlands in base to log villages @@ -329,7 +329,7 @@ local function world_conquest_tek_map_decoration_6a() ), "ne,se,sw,nw", "1-6") )) for i, loc in ipairs(terrain_to_change) do - map:set_terrain(loc, map:get_terrain(loc) .. "^Eff") + map[loc] = "^Eff" end end diff --git a/data/campaigns/World_Conquest/lua/map/postgeneration/6B_Maritime.lua b/data/campaigns/World_Conquest/lua/map/postgeneration/6B_Maritime.lua index 1e494bdee7aa4..8d02a91448dca 100644 --- a/data/campaigns/World_Conquest/lua/map/postgeneration/6B_Maritime.lua +++ b/data/campaigns/World_Conquest/lua/map/postgeneration/6B_Maritime.lua @@ -44,7 +44,7 @@ function wct_maritime_bridges() pb = functional.filter(pb, function(t) return #t.locs >0 end) local sel = pb[wesnoth.random(#pb)] local loc = sel.locs[wesnoth.random(#sel.locs)] - map:set_terrain(loc, "Ww^" .. sel.type) + map[loc] = "Ww^" .. sel.type pb = get_possible_maritime_bridge() end end @@ -191,7 +191,7 @@ function world_conquest_tek_map_decoration_6b() f.adjacent(f.terrain("Wog,Wwg")) )) loc = locs[wesnoth.random(#locs)]; - map:set_terrain(loc, "Iwr^Vl") + map[loc] = "Iwr^Vl" end set_terrain { "Wwg,Iwr,Wwg^Bw\\,Wwg^Bw\\,Wwg^Bw\\,Wwg^Bw\\", diff --git a/data/campaigns/World_Conquest/lua/map/postgeneration/6C_Industrial.lua b/data/campaigns/World_Conquest/lua/map/postgeneration/6C_Industrial.lua index 72be8e99d666e..ca6bb461b7461 100644 --- a/data/campaigns/World_Conquest/lua/map/postgeneration/6C_Industrial.lua +++ b/data/campaigns/World_Conquest/lua/map/postgeneration/6C_Industrial.lua @@ -5,7 +5,7 @@ local function wct_conect_factory_rails() f.terrain("*^Br*"), f.adjacent(f.terrain("*^Vhh")) )) - while #map:get_locations(wesnoth.create_filter( + while #map:get_locations(wesnoth.map.filter( f.all( f.terrain("*^Br*"), f.adjacent(f.find_in("rails_conected")), @@ -55,7 +55,7 @@ local function wct_conect_factory_rails() filter_extra = { rails_conected = rails_conected }, layer = "overlay", } - rails_conected = map:get_locations(wesnoth.create_filter( + rails_conected = map:get_locations(wesnoth.map.filter( f.all( f.terrain("*^Br*"), f.radius(1, f.find_in("rails_conected")) @@ -105,7 +105,7 @@ local function wct_dirty_deltas() while #terrain_to_change > 0 do local loc = 1 -- todo: maybe use terrain_to_change[wesnoth.random(#terrain_to_change)] local ter = helper.rand("Gs,Hh^Uf,Cud,Gs^Uf,Gs,Hh,Ds^Edt,Ds,Hh^Fmf,Gs,Gs^Fmf") - map:set_terrain(loc, ter) + map[loc] = ter terrain_to_change = wct_store_possible_dirty_delta() end end @@ -124,7 +124,7 @@ local function wct_ford_deltas() while #terrain_to_change > 0 do local loc = terrain_to_change[1]-- todo: maybe use errain_to_change[wesnoth.random(#terrain_to_change)] local ter = helper.rand("Gg,Gg^Efm,Mm,Gg^Fet,Gg,Mm,Gg") - map:set_terrain(loc, ter) + map[loc] = ter terrain_to_change = wct_store_possible_ford_delta() end end diff --git a/data/campaigns/World_Conquest/lua/map/postgeneration/6D_Feudal.lua b/data/campaigns/World_Conquest/lua/map/postgeneration/6D_Feudal.lua index 0f72c4bbcb329..e19a550e42043 100644 --- a/data/campaigns/World_Conquest/lua/map/postgeneration/6D_Feudal.lua +++ b/data/campaigns/World_Conquest/lua/map/postgeneration/6D_Feudal.lua @@ -135,12 +135,12 @@ local function world_conquest_tek_map_repaint_6d() -- this is faster. local r8_Re = map:get_tiles_radius( map:get_locations(f.terrain("Re")), - wesnoth.create_filter(f.all()), + wesnoth.map.filter(f.all()), 8 ) local r6_Khs = map:get_tiles_radius( map:get_locations(f.terrain("Khs")), - wesnoth.create_filter(f.all()), + wesnoth.map.filter(f.all()), 6 ) set_terrain { "Chs", diff --git a/data/campaigns/World_Conquest/lua/map/postgeneration_utils/engine.lua b/data/campaigns/World_Conquest/lua/map/postgeneration_utils/engine.lua index 6bd9c464aabf8..e629c1bfb32c2 100644 --- a/data/campaigns/World_Conquest/lua/map/postgeneration_utils/engine.lua +++ b/data/campaigns/World_Conquest/lua/map/postgeneration_utils/engine.lua @@ -37,7 +37,7 @@ f = { } function get_locations(t) - local filter = wesnoth.create_filter(t.filter, t.filter_extra or {}) + local filter = wesnoth.map.filter(t.filter, t.filter_extra or {}) return map:get_locations(filter, t.locs) end @@ -46,7 +46,7 @@ function set_terrain_impl(data) local nlocs_total = 0 for i = 1, #data do if data[i].filter then - local f = wesnoth.create_filter(data[i].filter, data[i].known or {}) + local f = wesnoth.map.filter(data[i].filter, data[i].known or {}) locs[i] = map:get_locations(f, data[i].locs) else locs[i] = data[i].locs @@ -68,7 +68,7 @@ function set_terrain_impl(data) for j = 1, num_tiles do local loc = locs[i][j] if chance >= 1000 or chance >= wesnoth.random(1000) then - map:set_terrain(loc, helper.rand(terrains), layer) + map[loc] = wesnoth.map['replace_' .. layer](helper.rand(terrains)) nlocs_changed = nlocs_changed + 1 end end diff --git a/data/campaigns/World_Conquest/lua/map/postgeneration_utils/events.lua b/data/campaigns/World_Conquest/lua/map/postgeneration_utils/events.lua index c77db15703ddf..8add37d96678f 100644 --- a/data/campaigns/World_Conquest/lua/map/postgeneration_utils/events.lua +++ b/data/campaigns/World_Conquest/lua/map/postgeneration_utils/events.lua @@ -111,8 +111,8 @@ function wct_castle_expansion_side(side_num) if keep_loc == nil then return end - local castle = map:get_tiles_radius({keep_loc}, wesnoth.create_filter(f.terrain("C*,K*")), 1) - local keep_area = map:get_tiles_radius({keep_loc}, wesnoth.create_filter(f.all()), 2) + local castle = map:get_tiles_radius({keep_loc}, wesnoth.map.filter(f.terrain("C*,K*")), 1) + local keep_area = map:get_tiles_radius({keep_loc}, wesnoth.map.filter(f.all()), 2) local candidates = get_locations { filter = f.all( @@ -148,7 +148,7 @@ function wct_castle_expansion_side(side_num) end helper.shuffle(candidates) for i = 1, n_tiles_wanted do - map:set_terrain(candidates[i], "Ch") + map[candidates[i]] = "Ch" end end @@ -166,7 +166,7 @@ function get_oceanic() f.y("1," .. tostring(map.height - 1)) ) local water_border_tiles = map:get_locations(f.all(f_is_border, f.terrain("Wo*"))) - local filter_radius = wesnoth.create_filter(f.all( + local filter_radius = wesnoth.map.filter(f.all( f.terrain("W*^V*,Wwr*,Ww,Wwg,Wwt,Wo*"), --ignore rivers f.adjacent(f.terrain("!,W*^*,S*^*,D*^*,Ai"), nil, "0-3") diff --git a/data/campaigns/World_Conquest/lua/map/postgeneration_utils/noise.lua b/data/campaigns/World_Conquest/lua/map/postgeneration_utils/noise.lua index 42ba0bcd8da6d..d9237ac12d5ce 100644 --- a/data/campaigns/World_Conquest/lua/map/postgeneration_utils/noise.lua +++ b/data/campaigns/World_Conquest/lua/map/postgeneration_utils/noise.lua @@ -1,6 +1,6 @@ function world_conquest_tek_map_noise_proxy(radius, fraction, terrain) local terrain_to_change = map:get_locations(f.terrain(terrain)) - local nop_filter = wesnoth.create_filter(f.all()) + local nop_filter = wesnoth.map.filter(f.all()) helper.shuffle(terrain_to_change) for terrain_i = 1, math.ceil(#terrain_to_change / fraction) do local loc_a = terrain_to_change[terrain_i] @@ -13,9 +13,9 @@ function world_conquest_tek_map_noise_proxy(radius, fraction, terrain) if #terrain_to_swap_b > 0 then local loc_b = terrain_to_swap_b[wesnoth.random(#terrain_to_swap_b)] - local terrain_a, terrain_b = map:get_terrain(loc_a), map:get_terrain(loc_b) - map:set_terrain(loc_a, terrain_b) - map:set_terrain(loc_b, terrain_a) + local terrain_a, terrain_b = map[loc_a], map[loc_b] + map[loc_a] = terrain_b + map[loc_b] = terrain_a end end end diff --git a/data/campaigns/World_Conquest/lua/map/postgeneration_utils/utilities.lua b/data/campaigns/World_Conquest/lua/map/postgeneration_utils/utilities.lua index 990083779f47a..74c4c05ddc343 100644 --- a/data/campaigns/World_Conquest/lua/map/postgeneration_utils/utilities.lua +++ b/data/campaigns/World_Conquest/lua/map/postgeneration_utils/utilities.lua @@ -76,7 +76,7 @@ function world_conquest_tek_map_dirt(mushrooms) local terrain_to_change = wct_store_possible_muddy_swamps() while #terrain_to_change > 0 do for i, v in ipairs(terrain_to_change) do - map:set_terrain(v, "Sm") + map[v] = "Sm" end terrain_to_change = wct_store_possible_muddy_swamps() end @@ -192,7 +192,7 @@ function wct_possible_map4_castle(terrain, value) local terrain_to_change = wct_store_possible_map4_castle(value) while #terrain_to_change > 0 and wesnoth.random(value + 1) == 1 do local loc = terrain_to_change[wesnoth.random(#terrain_to_change)] - map:set_terrain(loc, terrain) + map[loc] = terrain terrain_to_change = wct_store_possible_map4_castle(value) end end @@ -221,7 +221,7 @@ function wct_road_to_village(road, village) local terrain_to_change = wct_store_possible_roads(village) while #terrain_to_change > 0 do local loc = terrain_to_change[wesnoth.random(#terrain_to_change)] - map:set_terrain(loc, road) + map[loc] = road terrain_to_change = wct_store_possible_roads(village) end end @@ -234,7 +234,7 @@ function wct_iterate_roads_to(get_next, radius, terrain) local locs = get_next(r) while #locs > 0 do local loc = locs[wesnoth.random(#locs)] - map:set_terrain(loc, terrain) + map[loc] = terrain locs = get_next(r) end end @@ -249,7 +249,7 @@ end function wct_iterate_roads_to_2(f_validpath, f_src, f_dest, terrain_road, radius) local src_tiles = map:get_locations(f_src) local dest_tiles = map:get_locations(f_dest) - local filter_path = wesnoth.create_filter(f_validpath) + local filter_path = wesnoth.map.filter(f_validpath) local map = _G.map local function filter_path_function(x, y) @@ -282,7 +282,7 @@ function wct_iterate_roads_to_2(f_validpath, f_src, f_dest, terrain_road, radius if (dist_ad or 999) < dist then next_locs[#next_locs + 1] = loc_ad end - if dist_ad and map:get_terrain(loc_ad) == terrain_road then + if dist_ad and map[loc_ad] == terrain_road then --we merged with another path. goto path_found end @@ -294,7 +294,7 @@ function wct_iterate_roads_to_2(f_validpath, f_src, f_dest, terrain_road, radius ::path_found:: wesnoth.log("debug", "generated path: " .. debug_wml(path)) for i, ploc in ipairs(path) do - map:set_terrain(ploc, terrain_road) + map[ploc] = terrain_road end end end @@ -310,7 +310,7 @@ function wct_break_walls(wall, terrain) local terrain_to_change = wct_store_broken_wall_candidates(wall) while #terrain_to_change > 0 do local loc = terrain_to_change[wesnoth.random(#terrain_to_change)] - map:set_terrain(loc, helper.rand(terrain)) + map[loc] = helper.rand(terrain) terrain_to_change = wct_store_broken_wall_candidates(wall) end end diff --git a/data/campaigns/World_Conquest/lua/map/postgeneration_utils/wild_zones.lua b/data/campaigns/World_Conquest/lua/map/postgeneration_utils/wild_zones.lua index 6022e81e7a677..017ac477820e4 100644 --- a/data/campaigns/World_Conquest/lua/map/postgeneration_utils/wild_zones.lua +++ b/data/campaigns/World_Conquest/lua/map/postgeneration_utils/wild_zones.lua @@ -676,7 +676,7 @@ local function river_to_lava_postfix(terrain_to_change) } wild_volcano_for_lava_zone(terrain_to_change) - local filter_adjacent_grassland = wesnoth.create_filter(f.all( + local filter_adjacent_grassland = wesnoth.map.filter(f.all( f.terrain("G*^*"), f.adjacent(f.find_in("terrain_to_change")) ), { terrain_to_change = terrain_to_change }) diff --git a/data/campaigns/World_Conquest/lua/map/scenario_utils/bonus_points.lua b/data/campaigns/World_Conquest/lua/map/scenario_utils/bonus_points.lua index 3fdab382ca4b4..91ec5cc0b6346 100644 --- a/data/campaigns/World_Conquest/lua/map/scenario_utils/bonus_points.lua +++ b/data/campaigns/World_Conquest/lua/map/scenario_utils/bonus_points.lua @@ -105,7 +105,7 @@ function get_f_wct_bonus_location_filter(map) ) end function wct_bonus_chose_scenery(loc, theme, filter_extra) - local terrain = map:get_terrain(loc) + local terrain = map[loc] -- determine possible scenery values based on terrain local scenery = "well_g,temple,tent2_g,tent1,village,monolith3,burial" local terrain_to_scenery = @@ -162,7 +162,7 @@ function wct_bonus_chose_scenery(loc, theme, filter_extra) ::intial_list_screated:: local function matches_location(f) - local filter_object = wesnoth.create_filter(f, filter_extra) + local filter_object = wesnoth.map.filter(f, filter_extra) return #map:get_locations(filter_object, {loc}) > 0 end @@ -401,7 +401,7 @@ function world_conquest_tek_bonus_points(theme) local res = {} local scenario_num = wesnoth.get_variable("wc2_scenario") or 1 oceanic = get_oceanic() - f_wct_bonus_location_filter = wesnoth.create_filter(get_f_wct_bonus_location_filter(map), { oceanic = oceanic }) + f_wct_bonus_location_filter = wesnoth.map.filter(get_f_wct_bonus_location_filter(map), { oceanic = oceanic }) local possible_locs = map:get_locations(f_wct_bonus_location_filter) function place_item(loc) scenery = wct_bonus_chose_scenery(loc, theme, { oceanic = oceanic }) diff --git a/data/campaigns/World_Conquest/lua/map/wct_map_generator.lua b/data/campaigns/World_Conquest/lua/map/wct_map_generator.lua index b76dcf6347a98..290ea882fca67 100644 --- a/data/campaigns/World_Conquest/lua/map/wct_map_generator.lua +++ b/data/campaigns/World_Conquest/lua/map/wct_map_generator.lua @@ -44,7 +44,7 @@ local function run_postgeneration(map_data, id, scenario_content, nplayers, nhum nhumanplayers = nhumanplayer, scenario = scenario_content, } - _G.map = wesnoth.create_map(map_data) + _G.map = wesnoth.map.create(map_data) _G.total_tiles = _G.map.width * _G.map.height _G.prestart_event = scenario_content.event[1] _G.print_time = function(msg) diff --git a/data/campaigns/World_Conquest/lua/optional_mechanics/destruction.lua b/data/campaigns/World_Conquest/lua/optional_mechanics/destruction.lua index 6d89e60424232..2f5669a754a2b 100644 --- a/data/campaigns/World_Conquest/lua/optional_mechanics/destruction.lua +++ b/data/campaigns/World_Conquest/lua/optional_mechanics/destruction.lua @@ -18,36 +18,26 @@ local ice = { --replaces terrain fo the wct custom terrain mod. local function wct_map_custom_ruin_village(loc) - local function matches_terrain(filter) - filter.x = cx.x1 - filter.y = cx.y1 - return wesnoth.get_locations({ x = loc[1], y = loc[2], terrain = filter}) > 0 - end + local map = wesnoth.current.map + loc = wesnoth.map.get(loc) -- TODO: enable once https://github.com/wesnoth/wesnoth/issues/4894 is fixed. if false then - if matches_terrain("*^Vh,*^Vha") then - wesnoth.set_terrain(loc, "*^Vhr", "overlay") + if loc:matches{terrain = "*^Vh,*^Vha"} then + map[loc] = "^Vhr" end - if matches_terrain("*^Vhc,*^Vhca") then - wesnoth.set_terrain(loc, "*^Vhr", "overlay") + if loc:matches{terrain = "*^Vhc,*^Vhca"} then + map[loc] = "^Vhr" end end end on_event("die", function(cx) - local loc = { cx.x1, cx.y1 } - local function matches(filter) - filter.x = cx.x1 - filter.y = cx.y1 - return #wesnoth.get_locations(filter) > 0 - end - local function matches_terrain(filter) - return #wesnoth.get_locations({ x = cx.x1, y = cx.y1, terrain = filter}) > 0 - end + local map = wesnoth.current.map + local loc = wesnoth.map.get(cx.x1, cx.y1) if wml.variables.wc2_config_enable_terrain_destruction == false then return end - if not matches_terrain("K*^*,C*^*,*^Fet,G*^F*,G*^Uf,A*,*^B*,Rrc,Iwr,*^Vhh,*^Vh*,*^Fda*") then + if not loc:matches{terrain = "K*^*,C*^*,*^Fet,G*^F*,G*^Uf,A*,*^B*,Rrc,Iwr,*^Vhh,*^Vh*,*^Fda*"} then return end local function item(image) @@ -58,43 +48,43 @@ on_event("die", function(cx) z_order = -10, } end - if matches_terrain("Kh,Kha,Kh^Vov,Kha^Vov") then - wesnoth.set_terrain(loc, "Khr", "base") + if loc:matches{terrain = "Kh,Kha,Kh^Vov,Kha^Vov"} then + map[loc] = "Khr^" - elseif matches_terrain("Ch,Cha") then - wesnoth.set_terrain(loc, "Chr^Es") + elseif loc:matches{terrain = "Ch,Cha"} then + map[loc] = "Chr^Es" -- only without custom activated - elseif matches_terrain("Ch^Vh,Ch^Vhc") then - wesnoth.set_terrain(loc, "Chr", "base") + elseif loc:matches{terrain = "Ch^Vh,Ch^Vhc"} then + map[loc] = "Chr^" - elseif matches_terrain("Cd") then - wesnoth.set_terrain(loc, "Cdr^Es") + elseif loc:matches{terrain = "Cd"} then + map[loc] = "Cdr^Es" - elseif matches_terrain("Cd^Vd") then - wesnoth.set_terrain(loc, "Cdr", "base") + elseif loc:matches{terrain = "Cd^Vd"} then + map[loc] = "Cdr^" - elseif matches_terrain("Kd") then - wesnoth.set_terrain(loc, "Kdr^Es") + elseif loc:matches{terrain = "Kd"} then + map[loc] = "Kdr^Es" - elseif matches_terrain("Gg^Fmf,Gg^Fdf,Gg^Fp,Gg^Uf,Gs^Fmf,Gs^Fdf,Gs^Fp,Gs^Uf") then - wesnoth.set_terrain(loc, "Gll", "base") + elseif loc:matches{terrain = "Gg^Fmf,Gg^Fdf,Gg^Fp,Gg^Uf,Gs^Fmf,Gs^Fdf,Gs^Fp,Gs^Uf"} then + map[loc] = "Gll^" - elseif matches_terrain("Cv^Fds") then - wesnoth.set_terrain(loc, "Cv^Fdw") + elseif loc:matches{terrain = "Cv^Fds"} then + map[loc] "Cv^Fdw" - elseif matches_terrain("Rr^Fet,Cv^Fet") then - wesnoth.set_terrain(loc, "Rr^Fetd", "overlay") + elseif loc:matches{terrain = "Rr^Fet,Cv^Fet"} then + map[loc] = "^Fetd" - elseif matches_terrain("Aa") then + elseif loc:matches{terrain = "Aa"} then item(snow[wesnoth.random(#snow)]) - elseif matches_terrain("Ai") then + elseif loc:matches{terrain = "Ai"} then item(ice[wesnoth.random(#ice)]) - elseif matches_terrain("Ww^Bsb|,Ww^Bsb/,Ww^Bsb\\,Wwt^Bsb|,Wwt^Bsb/,Wwt^Bsb\\,Wwg^Bsb|,Wwg^Bsb/,Wwg^Bsb\\") then - wesnoth.set_terrain(loc, "Wwf^Edt") + elseif loc:matches{terrain = "Ww^Bsb|,Ww^Bsb/,Ww^Bsb\\,Wwt^Bsb|,Wwt^Bsb/,Wwt^Bsb\\,Wwg^Bsb|,Wwg^Bsb/,Wwg^Bsb\\"} then + map[loc] = "Wwf^Edt" wesnoth.play_sound("water-blast.wav") item("scenery/castle-ruins.png") - elseif matches_terrain("Rrc") then + elseif loc:matches{terrain = "Rrc"} then if wesnoth.variables["bonus.theme"] == "paradise" then wesnoth.wml_actions.remove_item { x = cx.x1, @@ -102,33 +92,33 @@ on_event("die", function(cx) image = "wc2_citadel_leanto" } item("scenery/trash.png") - wesnoth.set_terrain(loc, "Rrc^Edt") + map[loc] = "Rrc^Edt" end - elseif matches_terrain("Iwr") then + elseif loc:matches{terrain = "Iwr"} then wesnoth.wml_actions.remove_item { x = cx.x1, y = cx.y1, image = "wc2_dock_ship" } item("scenery/trash.png") - wesnoth.set_terrain(loc, "Iwr^Edt") - elseif matches_terrain("*^Vh,**^Vhc,*^Vha,**^Vhca,*^Fda") then + map[loc] = "Iwr^Edt" + elseif loc:matches{terrain = "*^Vh,**^Vhc,*^Vha,**^Vhca,*^Fda"} then wct_map_custom_ruin_village(loc) - if matches_terrain("Ch^V*") then - wesnoth.set_terrain(loc, "Chr", "base") + if loc:matches{terrain = "Ch^V*"} then + map[loc] = "Chr^" end -- TODO: enable once https://github.com/wesnoth/wesnoth/issues/4894 is fixed. if false then - if matches_terrain("*^Fda") then - wesnoth.set_terrain(loc, "*^Fdw", "overlay") + if loc:matches{terrain = "*^Fda"} then + map[loc] = "^Fdw" end end else - if matches_terrain("*^Vhh,*^Vhha") then - wesnoth.set_terrain(loc, "*^Vhhr", "overlay") + if loc:matches{terrain = "*^Vhh,*^Vhha"} then + map[loc] = "^Vhhr" end - if matches_terrain("*^Bw|,*^Bw/,*^Bw\\") then - wesnoth.set_terrain(loc, wesnoth.get_terrain(loc) .. "r") + if loc:matches{terrain = "*^Bw|,*^Bw/,*^Bw\\"} then + map[loc] = map[loc] .. "r" end end end) diff --git a/data/lua/helper.lua b/data/lua/helper.lua index 65ab83a034522..511c67e498499 100644 --- a/data/lua/helper.lua +++ b/data/lua/helper.lua @@ -72,20 +72,13 @@ end -- Not deprecated because, unlike wesnoth.map.get_adjacent_tiles, -- this verifies that the locations are on the map. function helper.adjacent_tiles(x, y, with_borders) - local x1,y1,x2,y2,b = 1,1,wesnoth.get_map_size() - if with_borders then - x1 = x1 - b - y1 = y1 - b - x2 = x2 + b - y2 = y2 + b - end local adj = {wesnoth.map.get_adjacent_tiles(x, y)} local i = 0 return function() while i < #adj do i = i + 1 local u, v = adj[i][1], adj[i][2] - if u >= x1 and u <= x2 and v >= y1 and v <= y2 then + if wesnoth.current.map:on_board(u, v, with_borders) then return u, v end end diff --git a/data/lua/location_set.lua b/data/lua/location_set.lua index 77df9bf115482..eec02261075bd 100644 --- a/data/lua/location_set.lua +++ b/data/lua/location_set.lua @@ -290,11 +290,6 @@ function methods:random() end function location_set.create() - if wesnoth.get_map_size then - -- If called from the mapgen kernel, there's no map - local w,h,b = wesnoth.get_map_size() - assert(h + 2 * b < 9000) - end return setmetatable({ values = {} }, locset_meta) end diff --git a/data/lua/wml-tags.lua b/data/lua/wml-tags.lua index 5c4b471b2af4c..9da68b83b6821 100644 --- a/data/lua/wml-tags.lua +++ b/data/lua/wml-tags.lua @@ -233,10 +233,10 @@ end function wml_actions.store_map_dimensions(cfg) local var = cfg.variable or "map_size" - local w, h, b = wesnoth.get_map_size() - wml.variables[var .. ".width"] = w - wml.variables[var .. ".height"] = h - wml.variables[var .. ".border_size"] = b + local map = wesnoth.current.map + wml.variables[var .. ".width"] = map.playable_width + wml.variables[var .. ".height"] = map.playable_height + wml.variables[var .. ".border_size"] = map.border_size end function wml_actions.unit_worth(cfg) @@ -305,7 +305,7 @@ function wml_actions.volume(cfg) end function wml_actions.scroll_to(cfg) - local loc = wesnoth.get_locations( cfg )[1] + local loc = wesnoth.map.find( cfg )[1] if not loc then return end if not utils.optional_side_filter(cfg) then return end wesnoth.interface.scroll_to_hex(loc[1], loc[2], cfg.check_fogged, cfg.immediate) @@ -417,14 +417,14 @@ end function wml_actions.store_locations(cfg) -- the variable can be mentioned in a [find_in] subtag, so it -- cannot be cleared before the locations are recovered - local locs = wesnoth.get_locations(cfg) + local locs = wesnoth.map.find(cfg) local writer = utils.vwriter.init(cfg, "location") for i, loc in ipairs(locs) do local x, y = loc[1], loc[2] - local t = wesnoth.get_terrain(x, y) + local t = wesnoth.current.map[{x, y}] local res = { x = x, y = y, terrain = t } - if wesnoth.get_terrain_info(t).village then - res.owner_side = wesnoth.get_village_owner(x, y) or 0 + if wesnoth.terrain_types[t].village then + res.owner_side = wesnoth.map.get_owner(x, y) or 0 end utils.vwriter.write(writer, res) end @@ -475,7 +475,7 @@ function wml_actions.store_reachable_locations(cfg) if location_filter then reach = reach:filter(function(x, y) - return wesnoth.match_location(x, y, location_filter) + return wesnoth.map.matches(x, y, location_filter) end) end reach:to_wml_var(variable) @@ -505,19 +505,26 @@ function wml_actions.capture_village(cfg) side = wesnoth.sides.find(filter_side)[1] if side then side = side.side end end - local locs = wesnoth.get_locations(cfg) + local locs = wesnoth.map.find(cfg) for i, loc in ipairs(locs) do - wesnoth.set_village_owner(loc[1], loc[2], side, fire_event) + wesnoth.map.set_owner(loc[1], loc[2], side, fire_event) end end function wml_actions.terrain(cfg) local terrain = cfg.terrain or wml.error("[terrain] missing required terrain= attribute") + local layer = cfg.layer or 'both' + if layer ~= 'both' and layer ~= 'overlay' and layer ~= 'base' then + wml.error('[terrain] invalid layer=') + end cfg = wml.shallow_parsed(cfg) cfg.terrain = nil - for i, loc in ipairs(wesnoth.get_locations(cfg)) do - wesnoth.set_terrain(loc[1], loc[2], terrain, cfg.layer, cfg.replace_if_failed) + for i, loc in ipairs(wesnoth.map.find(cfg)) do + local replacement = cfg.replace_if_failed + and wesnoth.map.replace_if_failed(terrain, layer) + or wesnoth.map['replace_' .. layer](terrain) + wesnoth.current.map[loc] = replacement end end @@ -529,7 +536,7 @@ function wml_actions.delay(cfg) end function wml_actions.floating_text(cfg) - local locs = wesnoth.get_locations(cfg) + local locs = wesnoth.map.find(cfg) local text = cfg.text or wml.error("[floating_text] missing required text= attribute") for i, loc in ipairs(locs) do @@ -654,10 +661,9 @@ function wml_actions.store_starting_location(cfg) for _, side in ipairs(wesnoth.sides.find(cfg)) do local loc = side.starting_location if loc then - local terrain = wesnoth.get_terrain(loc[1], loc[2]) - local result = { x = loc[1], y = loc[2], terrain = terrain } - if wesnoth.get_terrain_info(terrain).village then - result.owner_side = wesnoth.get_village_owner(loc[1], loc[2]) or 0 + local result = { x = loc[1], y = loc[2], terrain = wesnoth.current.map[loc] } + if wesnoth.terrain_types[result.terrain].village then + result.owner_side = wesnoth.map.get_owner(loc) or 0 end utils.vwriter.write(writer, result) end @@ -665,14 +671,14 @@ function wml_actions.store_starting_location(cfg) end function wml_actions.store_villages( cfg ) - local villages = wesnoth.get_villages( cfg ) + local villages = wesnoth.map.find{gives_income = true, wml.tag['and'](cfg)} local writer = utils.vwriter.init(cfg, "location") for index, village in ipairs( villages ) do utils.vwriter.write(writer, { x = village[1], y = village[2], - terrain = wesnoth.get_terrain( village[1], village[2] ), - owner_side = wesnoth.get_village_owner( village[1], village[2] ) or 0 + terrain = wesnoth.current.map[village], + owner_side = wesnoth.map.get_owner(village) or 0 }) end end @@ -714,17 +720,17 @@ end function wml_actions.place_shroud(cfg) local sides = utils.get_sides(cfg) - local tiles = wesnoth.get_locations(cfg) + local tiles = wesnoth.map.find(cfg) for i,side in ipairs(sides) do - wesnoth.place_shroud(side.side, tiles) + wesnoth.map.place_shroud(side.side, tiles) end end function wml_actions.remove_shroud(cfg) local sides = utils.get_sides(cfg) - local tiles = wesnoth.get_locations(cfg) + local tiles = wesnoth.map.find(cfg) for i,side in ipairs(sides) do - wesnoth.remove_shroud(side.side, tiles) + wesnoth.map.remove_shroud(side.side, tiles) end end @@ -732,7 +738,7 @@ function wml_actions.time_area(cfg) if cfg.remove then wml_actions.remove_time_area(cfg) else - wesnoth.add_time_area(cfg) + wesnoth.map.place_area(cfg) end end @@ -740,7 +746,7 @@ function wml_actions.remove_time_area(cfg) local id = cfg.id or wml.error("[remove_time_area] missing required id= key") for _,w in ipairs(id:split()) do - wesnoth.remove_time_area(w) + wesnoth.map.remove_area(w) end end @@ -792,7 +798,7 @@ end function wml_actions.label( cfg ) local new_cfg = wml.parsed( cfg ) - for index, location in ipairs( wesnoth.get_locations( cfg ) ) do + for index, location in ipairs( wesnoth.map.find( cfg ) ) do new_cfg.x, new_cfg.y = location[1], location[2] wesnoth.label( new_cfg ) end @@ -823,14 +829,6 @@ function wml_actions.unsynced(cfg) end) end -local function on_board(x, y) - if type(x) ~= "number" or type(y) ~= "number" then - return false - end - local w, h = wesnoth.get_map_size() - return x >= 1 and y >= 1 and x <= w and y <= h -end - wml_actions.unstore_unit = function(cfg) local variable = cfg.variable or wml.error("[unstore_unit] missing required 'variable' attribute") local unit_cfg = wml.variables[variable] or wml.error("[unstore_unit]: variable '" .. variable .. "' doesn't exist") @@ -847,7 +845,7 @@ wml_actions.unstore_unit = function(cfg) x,y = table.unpack(wesnoth.special_locations[cfg.location_id]) end wesnoth.add_known_unit(unit.type) - if on_board(x, y) then + if wesnoth.current.map:on_board(x, y) then if cfg.find_vacant then x,y = wesnoth.find_vacant_tile(x, y, check_passability and unit) end @@ -916,21 +914,21 @@ local function parse_fog_cfg(cfg) local ssf = wml.get_child(cfg, "filter_side") local sides = wesnoth.sides.find(ssf or {}) -- Location filter - local locs = wesnoth.get_locations(cfg) + local locs = wesnoth.map.find(cfg) return locs, sides end function wml_actions.lift_fog(cfg) local locs, sides = parse_fog_cfg(cfg) for i = 1, #sides do - wesnoth.remove_fog(sides[i].side, locs, not cfg.multiturn) + wesnoth.map.remove_fog(sides[i].side, locs, not cfg.multiturn) end end function wml_actions.reset_fog(cfg) local locs, sides = parse_fog_cfg(cfg) for i = 1, #sides do - wesnoth.add_fog(sides[i].side, locs, cfg.reset_view) + wesnoth.map.place_fog(sides[i].side, locs, cfg.reset_view) end end @@ -967,9 +965,9 @@ function wesnoth.wml_actions.store_unit_defense(cfg) if terrain then defense = unit:chance_to_be_hit(terrain) elseif cfg.loc_x and cfg.loc_y then - defense = unit:chance_to_be_hit(wesnoth.get_terrain(cfg.loc_x, cfg.loc_y)) + defense = unit:chance_to_be_hit(wesnoth.current.map[{cfg.loc_x, cfg.loc_y}]) else - defense = unit:chance_to_be_hit(wesnoth.get_terrain(unit.x, unit.y)) + defense = unit:chance_to_be_hit(wesnoth.current.map[unit]) end wml.variables[cfg.variable or "terrain_defense"] = defense end @@ -982,9 +980,9 @@ function wesnoth.wml_actions.store_unit_defense_on(cfg) if terrain then defense = unit:defense_on(terrain) elseif cfg.loc_x and cfg.loc_y then - defense = unit:defense_on(wesnoth.get_terrain(cfg.loc_x, cfg.loc_y)) + defense = unit:defense_on(wesnoth.current.map[{cfg.loc_x, cfg.loc_y}]) else - defense = unit:defense_on(wesnoth.get_terrain(unit.x, unit.y)) + defense = unit:defense_on(wesnoth.current.map[unit]) end wml.variables[cfg.variable or "terrain_defense"] = defense end @@ -1023,7 +1021,7 @@ function wml_actions.terrain_mask(cfg) if cfg.mask_file then mask = wesnoth.read_file(cfg.mask_file) end - wesnoth.terrain_mask({x, y}, mask, { + wesnoth.current.map:terrain_mask({x, y}, mask, { is_odd = is_odd, rules = rules, ignore_special_locations = cfg.ignore_special_locations, diff --git a/data/lua/wml/animate_unit.lua b/data/lua/wml/animate_unit.lua index f8eb7bc010456..1450e176e74f6 100644 --- a/data/lua/wml/animate_unit.lua +++ b/data/lua/wml/animate_unit.lua @@ -18,7 +18,7 @@ local function add_animation(anim, cfg) ) end - if unit and not wesnoth.is_fogged(wesnoth.current.side, unit.x, unit.y) then + if unit and not wesnoth.map.is_fogged(wesnoth.current.side, unit.x, unit.y) then local primary = wml.get_child(cfg, "primary_attack") local secondary = wml.get_child(cfg, "secondary_attack") -- We don't have access to the secondary unit at this point. @@ -73,7 +73,7 @@ local function add_animation(anim, cfg) local facing = wml.get_child(cfg, "facing") if facing then - local facing_loc = wesnoth.get_locations(facing)[1] + local facing_loc = wesnoth.map.find(facing)[1] if facing_loc then local dir = wesnoth.map.get_relative_dir(unit.x, unit.y, facing_loc[1], facing_loc[2]) unit.facing = dir diff --git a/data/lua/wml/find_path.lua b/data/lua/wml/find_path.lua index fd3d586ba0fca..d895b46060bae 100644 --- a/data/lua/wml/find_path.lua +++ b/data/lua/wml/find_path.lua @@ -39,23 +39,20 @@ function wesnoth.wml_actions.find_path(cfg) end -- only the first location with the lowest distance and lowest movement cost will match. - local locations = wesnoth.get_locations(filter_location) + local locations = wesnoth.map.find(filter_location) local max_cost = nil if not allow_multiple_turns then max_cost = unit.moves end --to avoid wrong calculation on already moved units local current_distance, current_cost, current_steps = math.huge, math.huge, math.huge local current_location = {} - local width,heigth = wesnoth.get_map_size() -- data for test below - for index, location in ipairs(locations) do -- we test if location passed to pathfinder is invalid (border); -- if it is, do not use it, and continue the cycle - if location[1] == 0 or location[1] == ( width + 1 ) or location[2] == 0 or location[2] == ( heigth + 1 ) then - else - local distance = wesnoth.map.distance_between ( unit.x, unit.y, location[1], location[2] ) + if ~wesnoth.current.map:on_border(location) then + local distance = wesnoth.map.distance_between ( unit.x, unit.y, location ) -- if we pass an unreachable location then an empty path and high value cost will be returned - local path, cost = wesnoth.find_path( unit, location[1], location[2], { + local path, cost = wesnoth.find_path( unit, location, { max_cost = max_cost, ignore_units = ignore_units, ignore_teleport = ignore_teleport, @@ -102,7 +99,7 @@ function wesnoth.wml_actions.find_path(cfg) else local path, cost = wesnoth.find_path( unit, - current_location[1], current_location[2], + current_location, { max_cost = max_cost, ignore_units = ignore_units, @@ -139,8 +136,7 @@ function wesnoth.wml_actions.find_path(cfg) for index, path_loc in ipairs(path) do local sub_path, sub_cost = wesnoth.find_path( unit, - path_loc[1], - path_loc[2], + path_loc, { max_cost = max_cost, ignore_units = ignore_units, @@ -158,7 +154,7 @@ function wesnoth.wml_actions.find_path(cfg) wml.variables[string.format( "%s.step[%d]", variable, index - 1 )] = { -- this structure takes less space in the inspection window x = path_loc[1], y = path_loc[2], - terrain = wesnoth.get_terrain( path_loc[1], path_loc[2] ), + terrain = wesnoth.current.map[path_loc], movement_cost = sub_cost, required_turns = sub_turns } diff --git a/data/lua/wml/items.lua b/data/lua/wml/items.lua index edce3957cf531..516ef7f04c0b6 100644 --- a/data/lua/wml/items.lua +++ b/data/lua/wml/items.lua @@ -94,7 +94,7 @@ end -- returns the 'name' of an item, this can be used as an id to remove the iten later. function wml_actions.item(cfg) - local locs = wesnoth.get_locations(cfg) + local locs = wesnoth.map.find(cfg) cfg = wml.parsed(cfg) if not cfg.image and not cfg.halo then wml.error "[item] missing required image= and halo= attributes." @@ -110,7 +110,7 @@ function wml_actions.item(cfg) end function wml_actions.remove_item(cfg) - local locs = wesnoth.get_locations(cfg) + local locs = wesnoth.map.find(cfg) for i, loc in ipairs(locs) do wesnoth.interface.remove_item(loc[1], loc[2], cfg.image) end @@ -122,7 +122,7 @@ function wml_actions.store_items(cfg) variable = tostring(variable or wml.error("invalid variable= in [store_items]")) wml.variables[variable] = nil local index = 0 - for i, loc in ipairs(wesnoth.get_locations(cfg)) do + for i, loc in ipairs(wesnoth.map.find(cfg)) do local items = scenario_items[loc] if items then for j, item in ipairs(items) do diff --git a/data/lua/wml/modify_side.lua b/data/lua/wml/modify_side.lua index fe5b1a5833147..5ca464028bf9c 100644 --- a/data/lua/wml/modify_side.lua +++ b/data/lua/wml/modify_side.lua @@ -61,16 +61,16 @@ function wesnoth.wml_actions.modify_side(cfg) side.shroud = cfg.shroud end if cfg.reset_maps then - wesnoth.remove_shroud(side.side, "all") + wesnoth.map.remove_shroud(side.side, "all") end if cfg.fog ~= nil then side.fog = cfg.fog end if cfg.reset_view then - wesnoth.add_fog(side.side, {}, true) + wesnoth.map.place_fog(side.side, {}, true) end if cfg.shroud_data then - wesnoth.remove_shroud(side.side, cfg.shroud_data) + wesnoth.map.remove_shroud(side.side, cfg.shroud_data) end if cfg.share_vision then diff --git a/data/lua/wml/random_placement.lua b/data/lua/wml/random_placement.lua index df42beea0dc9b..218f62441a880 100644 --- a/data/lua/wml/random_placement.lua +++ b/data/lua/wml/random_placement.lua @@ -11,7 +11,7 @@ wesnoth.wml_actions.random_placement = function(cfg) local allow_less = cfg.allow_less == true local variable_previous = utils.scoped_var(variable) local math_abs = math.abs - local locs = wesnoth.get_locations(filter) + local locs = wesnoth.map.find(filter) if type(num_items) == "string" then if num_items:match('^%s*%(.*%)%s*$') then local params = {size = #locs} @@ -40,7 +40,7 @@ wesnoth.wml_actions.random_placement = function(cfg) wml.variables[variable .. ".x"] = point[1] wml.variables[variable .. ".y"] = point[2] wml.variables[variable .. ".n"] = i - wml.variables[variable .. ".terrain"] = wesnoth.get_terrain(point[1], point[2]) + wml.variables[variable .. ".terrain"] = wesnoth.current.map[point] if distance < 0 then -- optimisation: nothing to do for distance < 0 elseif distance == 0 then diff --git a/data/modifications/pick_advance/main.lua b/data/modifications/pick_advance/main.lua index 0867f9667549e..0f5fd199aa8ec 100644 --- a/data/modifications/pick_advance/main.lua +++ b/data/modifications/pick_advance/main.lua @@ -181,14 +181,11 @@ local function humans_can_recruit() end -- return true if any keeps exist local function map_has_keeps() - local width,height,_ = wesnoth.get_map_size() - for x = 1, width do - for y = 1, height do - local terr = wesnoth.get_terrain(x, y) - local info = wesnoth.get_terrain_info(terr) - if info.keep then - return true - end + for x, y in wesnoth.current.map:iter() do + local terr = wesnoth.current.map[{x, y}] + local info = wesnoth.terrain_types[terr] + if info.keep then + return true end end end diff --git a/data/multiplayer/scenarios/2p_Dark_Forecast.lua b/data/multiplayer/scenarios/2p_Dark_Forecast.lua index 990a2524b5b68..20e83571ead6a 100644 --- a/data/multiplayer/scenarios/2p_Dark_Forecast.lua +++ b/data/multiplayer/scenarios/2p_Dark_Forecast.lua @@ -240,7 +240,7 @@ local function place_units(unittypes, x, y) local dst_x, dst_y = wesnoth.find_vacant_tile(x, y, u) u:to_map(dst_x, dst_y) wesnoth.add_known_unit(v) - wesnoth.set_village_owner(dst_x, dst_y, 1) + wesnoth.map.set_owner(dst_x, dst_y, 1) end end @@ -291,7 +291,7 @@ on_event("new turn", function() local unit_types = get_spawn_types(next_spawn.units, next_spawn.gold, random_spawns[next_spawn.pool_num]) local spawn_areas = {{"3-14", "15"}, {"1", "4-13"}, {"2-13", "1"}, {"1", "2-15"}} local spawn_area = spawn_areas[wesnoth.random(#spawn_areas)] - local locations_in_area = wesnoth.get_locations { x = spawn_area[1], y = spawn_area[2], radius=1, include_borders=false } + local locations_in_area = wesnoth.map.find { x = spawn_area[1], y = spawn_area[2], radius=1, include_borders=false } local chosen_location = locations_in_area[wesnoth.random(#locations_in_area)] place_units(unit_types, chosen_location[1], chosen_location[2]) end) diff --git a/data/scenario-test.cfg b/data/scenario-test.cfg index 4ced9f6def640..d0b4dbdee5adf 100644 --- a/data/scenario-test.cfg +++ b/data/scenario-test.cfg @@ -1729,7 +1729,7 @@ My best advancement costs $next_cost gold and I’m $experience|% there." [lua] code = << - wesnoth.set_village_owner(20, 1, 1) + wesnoth.map.set_owner(20, 1, 1) local u = wesnoth.units.find_on_map({ lua_function = "has_teleport" })[1] local t, c = wesnoth.find_path(u, 23, 7) for i,l in ipairs(t) do diff --git a/src/scripting/lua_terrainmap.cpp b/src/scripting/lua_terrainmap.cpp index 547827b3f4897..e216cf9c927f9 100644 --- a/src/scripting/lua_terrainmap.cpp +++ b/src/scripting/lua_terrainmap.cpp @@ -350,7 +350,7 @@ The map iterator, when called with false as its parameter is roughly equivalent to the following Lua function: function map_iter() - local map, x, y = wesnoth.map.get(), 0, 1 + local map, x, y = wesnoth.current.map, 0, 1 return function() if x == map.playable_width then if y == map.playable_height then