Update mainline content to use the mathx module

This commit is contained in:
Celtic Minstrel 2021-04-27 09:12:14 -04:00
parent 1fc31c23d0
commit 1dccc3ad76
55 changed files with 225 additions and 233 deletions

View File

@ -1840,7 +1840,7 @@ function ai_helper.custom_cost_with_avoid(x, y, prev_cost, unit, avoid_map, ally
-- in most cases this will simply add to the cost, rather than change the path itself.
local defense = unit:defense_on(terrain)
-- We need this to be multiples of 10 for the penalty identification to work
defense = H.round(defense / 10) * 10
defense = mathx.round(defense / 10) * 10
if (defense > 90) then defense = 90 end
if (defense < 10) then defense = 10 end
move_cost_int = move_cost_int + (100 - defense)

View File

@ -143,16 +143,16 @@ function battle_calcs.strike_damage(attacker, defender, att_weapon, def_weapon,
-- Rounding of .5 values is done differently depending on whether the
-- multiplier is greater or smaller than 1
if (att_multiplier > 1) then
att_damage = H.round(att_damage * att_multiplier - 0.001)
att_damage = mathx.round(att_damage * att_multiplier - 0.001)
else
att_damage = H.round(att_damage * att_multiplier + 0.001)
att_damage = mathx.round(att_damage * att_multiplier + 0.001)
end
if (def_weapon ~= 0) then
if (def_multiplier > 1) then
def_damage = H.round(def_damage * def_multiplier - 0.001)
def_damage = mathx.round(def_damage * def_multiplier - 0.001)
else
def_damage = H.round(def_damage * def_multiplier + 0.001)
def_damage = mathx.round(def_damage * def_multiplier + 0.001)
end
end

View File

@ -535,14 +535,14 @@
for i = 1, #units do
-- pick an advancement randomly, and remove others so advance() doesn't show the dialog
if units[i].advances_to[1] ~= nil then
local r = wesnoth.random ( 1, #units[i].advances_to )
local r = mathx.random ( 1, #units[i].advances_to )
local t = { }; t[1] = units[i].advances_to[r]
units[i].advances_to = t
end
-- level the unit and give it a random amount of experience up to half of max
units[i].experience = units[i].max_experience
units[i]:advance( )
units[i].experience = wesnoth.random ( 0, helper.round( units[i].max_experience / 2 ) )
units[i].experience = mathx.random ( 0, helper.round( units[i].max_experience / 2 ) )
end
>>
[/lua]

View File

@ -184,7 +184,7 @@ local convert = {
local loopCounter
for loopCounter = 1, snowNeeded do
local locationsIndex = wesnoth.random(#locations)
local locationsIndex = mathx.random(#locations)
local coordinate = locations[locationsIndex]
local terrainCode = wesnoth.current.map[coordinate]
wesnoth.current.map[coordinate] = (convert[terrainCode] or terrainCode)

View File

@ -25,7 +25,7 @@ function wml_actions.spread_bandit_villages(cfg)
local village_i
for i = 0, (count - 1) do
village_i = helper.rand("1.."..#villages)
village_i = mathx.random_choice("1.."..#villages)
vars[string.format("bandit_villages[%d].x", i)] = villages[village_i][1]
vars[string.format("bandit_villages[%d].y", i)] = villages[village_i][2]
@ -38,8 +38,8 @@ local function bandits_found(x,y)
local bandit_villages = wml.array_variables["bandit_villages"]
local boss_found = vars.boss_found
local visited = vars.villages_visited
local rand1 = helper.rand("3,4")
local rand2 = helper.rand("2.."..rand1)
local rand1 = mathx.random_choice("3,4")
local rand2 = mathx.random_choice("2.."..rand1)
for i=1,rand2 do
local radius = 1
@ -49,8 +49,8 @@ local function bandits_found(x,y)
radius = radius + 1
until locs[1]
local bandit = helper.rand(bandit_types)
local loc_i = helper.rand("1.."..#locs)
local bandit = mathx.random_choice(bandit_types)
local loc_i = mathx.random_choice("1.."..#locs)
wml_actions.move_unit_fake({x = string.format("%d,%d", x, locs[loc_i][1]), y = string.format("%d,%d", y, locs[loc_i][2]), type = bandit, side = "4"})
wesnoth.units.to_map({ type = bandit, side = "4", random_traits = "yes", generate_name = "yes", upkeep = "loyal" }, locs[loc_i][1], locs[loc_i][2])
@ -58,7 +58,7 @@ local function bandits_found(x,y)
if not boss_found and visited > 2 then
local boss_chance = (100 / #bandit_villages)
local rand3 = helper.rand("1..100")
local rand3 = mathx.random_choice("1..100")
if rand3 <= boss_chance or #bandit_villages < 3 then
vars.boss_found = true

View File

@ -204,7 +204,7 @@ local convert = {
local loopCounter
for loopCounter = 1, snowNeeded do
local locationsIndex = wesnoth.random(#locations)
local locationsIndex = mathx.random(#locations)
local coordinate = locations[locationsIndex]
local terrainCode = wesnoth.current.map[coordinate]
wesnoth.current.map[coordinate] = (convert[terrainCode] or terrainCode)

View File

@ -200,8 +200,6 @@
#define ENABLE_AI_COMMAND_CA_TRANSPORT_S6
[lua]
code = <<
local helper = wesnoth.require "helper"
function wesnoth.custom_synced_commands.ship_unload(cfg)
local unit = wesnoth.units.get(cfg.x, cfg.y)
@ -211,12 +209,12 @@ function wesnoth.custom_synced_commands.ship_unload(cfg)
local locs = wml.child_array(cfg, "dst")
local l2_type = helper.rand('Swordsman,Javelineer,Pikeman')
local l2_type = mathx.random_choice('Swordsman,Javelineer,Pikeman')
wesnoth.units.to_map({ side = wesnoth.current.side, type = l2_type, moves = 2 }, locs[1].x, locs[1].y)
wesnoth.add_known_unit(l2_type)
for i = 2, #locs do
local l1_type = helper.rand('Fencer,Mage,Cavalryman,Bowman,Spearman')
local l1_type = mathx.random_choice('Fencer,Mage,Cavalryman,Bowman,Spearman')
wesnoth.units.to_map({ side = wesnoth.current.side, type = l1_type, moves = 2 }, locs[i].x, locs[i].y)
wesnoth.add_known_unit(l1_type)
end

View File

@ -20,8 +20,8 @@ function wml_actions.spawn_units(cfg)
done = done + 1
local unit_type = helper.rand(types)
local loc_i = helper.rand("1.."..#locs)
local unit_type = mathx.random_choice(types)
local loc_i = mathx.random_choice("1.."..#locs)
wml_actions.move_unit_fake({x = string.format("%d,%d", x, locs[loc_i][1]) , y = string.format("%d,%d", y, locs[loc_i][2]) , type = unit_type , side = side})
wesnoth.units.to_map({ type = unit_type , side = side, random_traits = "yes", generate_name = "yes" , upkeep = "loyal" }, locs[loc_i][1], locs[loc_i][2])

View File

@ -401,8 +401,8 @@
radius = radius + 1
until locs[1]
local orc = helper.rand(orc_types)
local loc_i = helper.rand("1.."..#locs)
local orc = mathx.random_choice(orc_types)
local loc_i = mathx.random_choice("1.."..#locs)
wml_actions.move_unit_fake({x = string.format("%d,%d", x, locs[loc_i][1]), y = string.format("%d,%d", y, locs[loc_i][2]), type = orc, side = "4"})
wesnoth.units.to_map({ type = orc, side = "4", random_traits = "yes", generate_name = "yes", upkeep = "loyal" }, locs[loc_i][1], locs[loc_i][2])

View File

@ -1,5 +1,4 @@
local on_event = wesnoth.require("on_event")
local helper = wesnoth.require("helper")
local enemy = {}
@ -38,7 +37,7 @@ function enemy.pick_suitable_enemy_item(unit)
if #possible_artifacts == 0 then
return
end
local i = possible_artifacts[wesnoth.random(#possible_artifacts)]
local i = possible_artifacts[mathx.random(#possible_artifacts)]
local artifact_id = tonumber(enemy_items[i])
table.remove(enemy_items, i)
wml.variables["wc2_enemy_army.artifacts"] = table.concat(enemy_items, ",")
@ -77,7 +76,7 @@ function enemy.do_commander(cfg, group_id, loc)
local scenario = wc2_scenario.scenario_num()
--wesnoth.message("do_commander", wml.variables[("wc2_enemy_army.group[%d].allies_available"):format(group_id)])
local ally_i = wc2_utils.pick_random(("wc2_enemy_army.group[%d].allies_available"):format(group_id)) - 1
local leader_index = wesnoth.random(wml.variables[("wc2_enemy_army.group[%d].leader.length"):format(ally_i)]) - 1
local leader_index = mathx.random(wml.variables[("wc2_enemy_army.group[%d].leader.length"):format(ally_i)]) - 1
local new_recruits = wml.variables[("wc2_enemy_army.group[%d].leader[%d].recruit"):format(ally_i, leader_index)]
wesnoth.wml_actions.allow_recruit {
side = cfg.side,
@ -87,7 +86,7 @@ function enemy.do_commander(cfg, group_id, loc)
wesnoth.wml_actions.unit {
x = loc[1],
y = loc[2],
type = helper.rand(commander_options),
type = mathx.random_choice(commander_options),
side = cfg.side,
generate_name = true,
role = "commander",
@ -144,7 +143,7 @@ on_event("recruit", function(ec)
wml.tag.filter {}
}
}
helper.shuffle(candidates)
mathx.shuffle(candidates)
while #candidates > 0 and #to_recall > 0 do
enemy.fake_recall(side_num, to_recall[1], candidates[1])
table.remove(to_recall, 1)
@ -169,7 +168,7 @@ function enemy.do_recall(cfg, group_id, loc)
get_advanced_units(level, stringx.split(group.recruit or ""), types)
end
for i = 1, amount do
table.insert(to_recall, types[wesnoth.random(#types)])
table.insert(to_recall, types[mathx.random(#types)])
end
end
recall_level(2)
@ -255,7 +254,7 @@ function wesnoth.wml_actions.wc2_enemy(cfg)
--should't happen, added for robustness.
local n_groups = wml.variables["wc2_enemy_army.group.length"]
if n_groups > 0 then
enemy_type_id = wesnoth.random(n_groups) - 1
enemy_type_id = mathx.random(n_groups) - 1
else
error("no enemy groups defined")
end

View File

@ -8,7 +8,7 @@ local strings = {
-- which means in paticular changing the castle of the enemy accorign to the unit type of that
-- enemy, and giving him an extra unit.
local function wct_map_enemy_themed(race, pet, castle, village, chance)
if wesnoth.random(100) > chance then
if mathx.random(100) > chance then
return
end
local boss = wesnoth.units.find_on_map {
@ -56,7 +56,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
if mathx.random(10) <= 4 then
wesnoth.current.map[tile] = "Cv^Fet"
end
end

View File

@ -1,4 +1,3 @@
local helper = wesnoth.require("helper")
local on_event = wesnoth.require("on_event")
local _ = wesnoth.textdomain 'wesnoth-wc'
@ -74,7 +73,7 @@ local function init_side(side_num)
for v in wml.child_range(faction, "pair") do
i = i + 1
local p = stringx.split(v.types or "")
if wesnoth.random(1,2) == 2 then
if mathx.random(1,2) == 2 then
p[1],p[2] = p[2],p[1]
end
wesnoth.wml_actions.allow_recruit {
@ -86,7 +85,7 @@ local function init_side(side_num)
end
if not faction and #wc2_era.factions_wml > 0 then
faction = wc2_era.factions_wml[wesnoth.random(#wc2_era.factions_wml)]
faction = wc2_era.factions_wml[mathx.random(#wc2_era.factions_wml)]
end
if not faction then
@ -97,9 +96,9 @@ local function init_side(side_num)
local deserters = wc2_era.expand_hero_types(faction.deserters)
local commanders = wc2_era.expand_hero_types(faction.commanders)
helper.shuffle(heroes)
helper.shuffle(deserters)
helper.shuffle(commanders)
mathx.shuffle(heroes)
mathx.shuffle(deserters)
mathx.shuffle(commanders)
side.variables["wc2.heroes"] = table.concat(heroes, ",")
side.variables["wc2.deserters"] = table.concat(deserters, ",")
@ -116,13 +115,13 @@ end
local function add_known_spawn_filter(spawn_filter)
local types = stringx.map_split(spawn_filter.types or "")
local filter_location = wml.get_child(spawn_filter, "filter_location") or helper.wml_error("missing [filter_location] in [hero_spawn_filter]")
local filter_location = wml.get_child(spawn_filter, "filter_location") or wml.error("missing [filter_location] in [hero_spawn_filter]")
table.insert(wc2_era.spawn_filters, { types = types, filter_location = filter_location} )
end
local function add_known_trait_extra(trait_extra)
local types = stringx.map_split(trait_extra.types or "")
local trait = wml.get_child(trait_extra, "trait") or helper.wml_error("missing [trait] in [trait_extra]")
local trait = wml.get_child(trait_extra, "trait") or wml.error("missing [trait] in [trait_extra]")
table.insert(wc2_era.hero_traits, { types = types, trait = trait} )
end
-- in case that a [multiplayer_side] has not [world_conquest_data] we generate it randomly.
@ -132,11 +131,11 @@ function wc2_era.create_random_faction(id)
local heroes_set = {}
local commanders_set = {}
local i_deserters1 = wesnoth.random(#wc2_era.standard_factions)
local i_deserters2 = wesnoth.random(#wc2_era.standard_factions)
local i_heroes1 = wesnoth.random(#wc2_era.standard_factions)
local i_heroes2 = wesnoth.random(#wc2_era.standard_factions)
local i_commanders = wesnoth.random(#wc2_era.standard_factions)
local i_deserters1 = mathx.random(#wc2_era.standard_factions)
local i_deserters2 = mathx.random(#wc2_era.standard_factions)
local i_heroes1 = mathx.random(#wc2_era.standard_factions)
local i_heroes2 = mathx.random(#wc2_era.standard_factions)
local i_commanders = mathx.random(#wc2_era.standard_factions)
deserters_set = stringx.map_split(wc2_era.standard_factions[i_deserters1].recruits .. ',' .. wc2_era.standard_factions[i_deserters2].recruits)
heroes_set = stringx.map_split(wc2_era.standard_factions[i_heroes1].recruits .. ',' .. wc2_era.standard_factions[i_heroes2].recruits)

View File

@ -17,12 +17,12 @@ function wesnoth.wml_actions.wc2_place_bonus(cfg)
local image = c_scenery.image or scenery
bonus.place_item(x, y, image)
-- Note: although the numbrs of options passed to helper.rand might depend on the langauge
-- the number of thimes random is called does not (random is called even if there is
-- Note: although the numbers of options passed to mathx.random_choice might depend on the langauge
-- the number of times random is called does not (random is called even if there is
-- only one option), so this doesn't cause OOS.
local name1 = wc2_random_names()
local name_options = c_scenery.names or { _"place" }
local name2 = tostring(name_options[wesnoth.random(#name_options)])
local name2 = tostring(name_options[mathx.random(#name_options)])
local function span_font_family(str, fam)
return string.format("<span font-family='%s'>%s</span>", fam, str)
@ -100,7 +100,7 @@ on_event("wc2_drop_pickup", function(ec)
local training_chance = wml.variables.wc2_config_training_chance or 1
local hero_chance = wml.variables.wc2_config_hero_chance or 1
local item_chance = wml.variables.wc2_config_item_chance or 1
local r = wesnoth.random(training_chance + hero_chance + item_chance)
local r = mathx.random(training_chance + hero_chance + item_chance)
if r <= training_chance then
bonus_type = 1
elseif r <= training_chance + item_chance then
@ -112,7 +112,7 @@ on_event("wc2_drop_pickup", function(ec)
local bonus_subtype = item.wc2_subtype
if bonus_type == 1 then
if not bonus.found_training(wesnoth.current.side, bonus_subtype, ec) then
bonus_type = wesnoth.random(2,3)
bonus_type = mathx.random(2,3)
bonus_subtype = nil
end
end

View File

@ -8,7 +8,7 @@ function wc2_invest.add_items(side_num, num_items)
local items_left = stringx.split(side.variables["wc2.items_left"] or "")
local items_available = stringx.split(side.variables["wc2.items"] or "")
for j = 1, num_items do
local i = wesnoth.random(#items_left)
local i = mathx.random(#items_left)
table.insert(items_available, items_left[i])
table.remove(items_left, i)
end
@ -72,7 +72,7 @@ function wc2_invest.do_hero(t, is_local)
local x,y = leaders[1].x, leaders[1].y
if t == "wc2_commander" then
local commanders = stringx.split(side.variables["wc2.commanders"] or "")
local i = wesnoth.random(#commanders)
local i = mathx.random(#commanders)
t = commanders[i]
table.remove(commanders, i)
side.variables["wc2.commanders"] = table.concat(commanders, ",")
@ -85,7 +85,7 @@ function wc2_invest.do_hero(t, is_local)
wesnoth.sides[side_num].gold = wesnoth.sides[side_num].gold + 15
local deserters = stringx.split(side.variables["wc2.deserters"] or "")
local i = wesnoth.random(#deserters)
local i = mathx.random(#deserters)
t = deserters[i]
table.remove(deserters, i)
side.variables["wc2.deserters"] = table.concat(deserters, ",")
@ -171,7 +171,7 @@ end
function wesnoth.wml_actions.wc2_invest(cfg)
--disallow undoing.
wesnoth.random(100)
mathx.random(100)
wc2_invest.invest()
end

View File

@ -102,7 +102,7 @@ function training.find_available(side_num, among, amount)
if #possible_traintypes == 0 then
return
else
return possible_traintypes[wesnoth.random(#possible_traintypes)]
return possible_traintypes[mathx.random(#possible_traintypes)]
end
end
@ -184,7 +184,7 @@ end
function training.bonus_calculate_amount(side_num)
local amount = 1
local advanced_chance = 4 * training.get_level_sum(side_num)
if wc2_scenario.scenario_num() > 3 or wesnoth.random(100) <= advanced_chance then
if wc2_scenario.scenario_num() > 3 or mathx.random(100) <= advanced_chance then
amount = 2
end
return amount
@ -226,7 +226,7 @@ function training.apply(u)
local vchance = wml.tovconfig(chance)
local filter = wml.get_child(vchance, "filter")
local matches_filter = (not filter) or u:matches(filter)
if wesnoth.random(100) <= vchance.value and matches_filter then
if mathx.random(100) <= vchance.value and matches_filter then
--wesnoth.wml_actions.message { message = "Got it" }
table.insert(descriptions, wc2_utils.get_fstring(chance, "info"))
for effect in wml.child_range(vchance, "effect") do

View File

@ -32,7 +32,7 @@ function wc2_utils.pick_random(str, generator)
if #array == 0 and generator then
array = generator()
end
local index = wesnoth.random(#array)
local index = mathx.random(#array)
local res = array[index]
table.remove(array, index)
wml.variables[str] = table.concat(array, ",")
@ -50,7 +50,7 @@ local function filtered_from_array(array, filter)
if #possible_indicies == 0 then
return nil
end
local index = possible_indicies[wesnoth.random(#possible_indicies)]
local index = possible_indicies[mathx.random(#possible_indicies)]
return index
end
@ -79,7 +79,7 @@ end
function wc2_utils.pick_random_t(str)
local size = wml.variables[str .. ".length"]
if size ~= 0 then
local index = wesnoth.random(size) - 1
local index = mathx.random(size) - 1
local res = wml.variables[str .. "[" .. index .. "]"]
wml.variables[str .. "[" .. index .. "]"] = nil
return res

View File

@ -245,13 +245,13 @@ function default_generate_map(data)
end
for i = 1, 20 do
local status, map = pcall(function()
cfg.seed = wesnoth.random(5000) + 7
cfg.seed = mathx.random(5000) + 7
return wesnoth.map.generate(w, h, cfg)
end)
if status then
return map
end
end
cfg.seed = wesnoth.random(5000) + 7
cfg.seed = mathx.random(5000) + 7
return wesnoth.map.generate(w, h, cfg)
end

View File

@ -28,7 +28,7 @@ local function get_map_generator(scenario_data)
globals.settings.island
)
else
return scenario_data.generators[wesnoth.random(#scenario_data.generators)]
return scenario_data.generators[mathx.random(#scenario_data.generators)]
end
end

View File

@ -48,9 +48,9 @@ function world_conquest_tek_map_decoration_1()
}
-- tweak roads
if wesnoth.random(20) ~= 1 then
local rad = wesnoth.random(5, 9)
local ter = helper.rand("Ch*^*,Kh*^*,Ch*^*,Kh*^*")
if mathx.random(20) ~= 1 then
local rad = mathx.random(5, 9)
local ter = mathx.random_choice("Ch*^*,Kh*^*,Ch*^*,Kh*^*")
set_terrain { "Rb",
f.all(
f.terrain("Re"),
@ -63,13 +63,13 @@ function world_conquest_tek_map_decoration_1()
-- chances of fords
local terrain_to_change = wct_store_possible_encampment_ford();
while #terrain_to_change > 0 and wesnoth.random(2) == 1 do
local i = wesnoth.random(#terrain_to_change)
while #terrain_to_change > 0 and mathx.random(2) == 1 do
local i = mathx.random(#terrain_to_change)
map[terrain_to_change[i]] = "Wwf"
terrain_to_change = wct_store_possible_encampment_ford()
end
if wesnoth.random(20) ~= 1 then
if mathx.random(20) ~= 1 then
wct_change_map_water("g")
end
-- randomize a few forest
@ -87,7 +87,7 @@ function world_conquest_tek_map_decoration_1()
),
}
if wesnoth.random(8) ~= 1 then
if mathx.random(8) ~= 1 then
set_terrain { "Mm^Xm",
f.all(
f.terrain("Xu"),
@ -122,7 +122,7 @@ end
function wct_map_1_post_castle_expansion_fix()
wct_map_reduce_castle_expanding_recruit("Ce", "Wwf")
local r = helper.rand("Ch,Ch,Ch,Chw,Chw,Chs,Ce,Wwf")
local r = mathx.random_choice("Ch,Ch,Ch,Chw,Chw,Chs,Ce,Wwf")
set_terrain { r,
f.all(
f.terrain("Ce"),

View File

@ -19,28 +19,28 @@ function world_conquest_tek_map_decoration_2a()
}
-- chances of tropical palm forest near caves
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
local terrain_to_change = map:find(f.all(
f.terrain("Hh*^F*"),
f.adjacent(f.terrain("Xu,U*^*,Mv,Ql,Qxu"))
))
if #terrain_to_change > 3 then
local r = wesnoth.random(0, #terrain_to_change - 3)
local r = mathx.random(0, #terrain_to_change - 3)
for i = 1, r do
local loc = terrain_to_change[wesnoth.random(#terrain_to_change)]
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
map[loc] = "Hh^Ftp"
end
end
end
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
local terrain_to_change = map:find(f.all(
f.terrain("G*^F*"),
f.adjacent(f.terrain("Xu,U*^*,Mv,Ql,Qxu"))
))
if #terrain_to_change > 3 then
local r = wesnoth.random(0, #terrain_to_change - 3)
local r = mathx.random(0, #terrain_to_change - 3)
for i = 1, r do
local loc = terrain_to_change[wesnoth.random(#terrain_to_change)]
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
map[loc] = "Gs^Ftp"
end
end
@ -139,7 +139,7 @@ function world_conquest_tek_map_decoration_2a()
-- fords
local r = wesnoth.random(0, 4)
local r = mathx.random(0, 4)
for i = 1, r do
set_terrain { "Wwf",
f.all(
@ -152,8 +152,8 @@ function world_conquest_tek_map_decoration_2a()
end
-- chances flowers
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)]
while #terrain_to_change > 0 and mathx.random(10) ~= 1 do
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
map[loc] = "^Efm"
local terrain_to_change = wct_store_possible_flowers("G*^Fet")
end
@ -167,7 +167,7 @@ function world_conquest_tek_map_decoration_2a()
}
wct_map_reduce_castle_expanding_recruit("Ce", "Re")
if wesnoth.random(5) ~= 1 then
if mathx.random(5) ~= 1 then
wct_map_decorative_docks()
end
end

View File

@ -1,21 +1,21 @@
-- Lakes
local function world_conquest_tek_map_repaint_2b()
-- Add snow and ice
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
local terrain_to_change = map:find(f.all(
f.terrain("!,Ss,D*^*,Hd,W*^*,Mm^Xm,Xu,Mv,Q*^*,U*^*"),
f.radius(2, f.terrain("M*^*"))
))
-- base amount in map surface
local r = helper.rand(tostring(total_tiles // 675) .. ".." .. tostring(total_tiles // 330))
local r = mathx.random_choice(tostring(total_tiles // 675) .. ".." .. tostring(total_tiles // 330))
wct_storm(terrain_to_change, r)
end
wct_expand_snow()
set_terrain { "Ai",
f.all(
f.terrain("Wwt,Wot"),
f.adjacent(f.terrain("A*^*,Ms^*,Ha^*,Kha,Cha"), nil, wesnoth.random(3, 5))
f.adjacent(f.terrain("A*^*,Ms^*,Ha^*,Kha,Cha"), nil, mathx.random(3, 5))
),
}
-- randomize snowed forests
@ -58,14 +58,14 @@ local function world_conquest_tek_map_repaint_2b()
fraction = 2,
}
if wesnoth.random(20) ~= 1 then
if mathx.random(20) ~= 1 then
set_terrain { "Gg",
f.terrain("Gs^*"),
layer = "base",
}
end
if wesnoth.random(20) ~= 1 then
if mathx.random(20) ~= 1 then
set_terrain { "Gg^Gvs",
f.all(
f.terrain("Gg"),
@ -88,13 +88,13 @@ local function world_conquest_tek_map_repaint_2b()
}
end
if wesnoth.random(20) == 1 then
if mathx.random(20) == 1 then
wct_map_decorative_docks()
end
wct_dirt_beachs("9..11")
-- chance of different lakes water
-- todo: does this syntax really work?
local terrain_mod = helper.rand("g,,,,,,,,,,,,,,,,,,t")
local terrain_mod = mathx.random_choice("g,,,,,,,,,,,,,,,,,,t")
set_terrain { "Ww" .. terrain_mod,
f.terrain("Wwt^*"),
layer = "base",
@ -104,7 +104,7 @@ local function world_conquest_tek_map_repaint_2b()
}
-- chance of frozen lakes
if wesnoth.random(9) == 1 then
if mathx.random(9) == 1 then
set_terrain { "Ai",
f.all(
f.terrain("Ww,Wwg,Wo,Wog"),
@ -144,7 +144,7 @@ local function world_conquest_tek_map_repaint_2b()
local terrain_to_change = map:find(f.terrain("A*^*,Ha*^*,Ms^*"))
local chance = 2000 * #terrain_to_change // total_tiles
if wesnoth.random(0, 99 ) > chance then
if mathx.random(0, 99 ) > chance then
set_terrain { "*^Ftd",
f.terrain("*^Ft"),
layer = "overlay",
@ -231,7 +231,7 @@ function world_conquest_tek_map_constructor_lakes()
fraction_rand = "11..13",
}
local r = helper.rand(tostring(total_tiles // 675) .. ".." .. tostring(total_tiles // 285))
local r = mathx.random_choice(tostring(total_tiles // 675) .. ".." .. tostring(total_tiles // 285))
set_terrain { "Hh^Uf",
f.all(

View File

@ -141,9 +141,9 @@ function world_conquest_tek_map_decoration_2c()
f.terrain("Wo"),
f.adjacent(f.terrain("!,Wo"), nil, 0)
))
helper.shuffle(terrain_to_change)
mathx.shuffle(terrain_to_change)
-- base amount in map surface
local r = helper.rand(tostring(total_tiles // 285) .. ".." .. tostring(total_tiles // 150))
local r = mathx.random_choice(tostring(total_tiles // 285) .. ".." .. tostring(total_tiles // 150))
for i = 1, math.min(r, #terrain_to_change) do
map[terrain_to_change[i]] = "Ai"
end
@ -152,8 +152,8 @@ function world_conquest_tek_map_decoration_2c()
f.terrain("Wo"),
f.adjacent(f.terrain("!,Wo,Ai"), nil, 0)
))
helper.shuffle(icepack_candiates)
local r = helper.rand(tostring(total_tiles // 250) .. ".." .. tostring(total_tiles // 150))
mathx.shuffle(icepack_candiates)
local r = mathx.random_choice(tostring(total_tiles // 250) .. ".." .. tostring(total_tiles // 150))
for i = 1, math.min(r, #icepack_candiates) do
local loc = icepack_candiates[i]
@ -170,20 +170,20 @@ function world_conquest_tek_map_decoration_2c()
fraction = 15,
}
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
set_terrain { "Wwf",
f.terrain("Gd"),
fraction_rand = "2..6",
}
end
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
set_terrain { "Gs",
f.terrain("Gd"),
fraction_rand = "1..5",
}
end
if wesnoth.random(8) == 1 then
if mathx.random(8) == 1 then
set_terrain { "Aa,Aa,Aa,Ai",
f.terrain("Gd"),
fraction_rand = "1..4",

View File

@ -15,7 +15,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)]
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
map[loc] = terrain
end
end

View File

@ -10,7 +10,7 @@ function wct_map_2e_post_bunus_decoration()
end
function world_conquest_tek_map_repaint_2e()
world_conquest_tek_map_noise_proxy(1, wesnoth.random(1,2), "!,W*^*,Ds*^*,X*,M*^Xm,R*^*,Ch*,K*,U*^*,Ql^B*")
world_conquest_tek_map_noise_proxy(1, mathx.random(1,2), "!,W*^*,Ds*^*,X*,M*^Xm,R*^*,Ch*,K*,U*^*,Ql^B*")
-- create citadel castles
wct_map_reduce_castle_expanding_recruit("Xos", "Rr^Fet")
@ -57,12 +57,12 @@ function world_conquest_tek_map_repaint_2e()
-- create villages in empty citadels
local terrain_to_change = wct_store_empty_citadel()
while #terrain_to_change > 0 do
local loc = terrain_to_change[wesnoth.random(#terrain_to_change)]
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
map[loc] = "Rr^Vhc"
terrain_to_change = wct_store_empty_citadel()
end
-- improve roads quality
local r = wesnoth.random(2,4)
local r = mathx.random(2,4)
set_terrain { "Rr",
f.all(
f.terrain("Re"),
@ -86,11 +86,11 @@ function world_conquest_tek_map_repaint_2e()
}
local max_yards = map.height * map.width // 300
local nyards = tonumber(helper.rand("1,0.." .. max_yards))
local nyards = tonumber(mathx.random_choice("1,0.." .. max_yards))
for i = 1, nyards do
local yard_dir = "n,nw,ne"
local yard_cdir = "s,sw,se"
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
yard_dir, yard_cdir = yard_cdir, yard_dir
end
wct_map_yard(yard_dir, yard_cdir)
@ -98,7 +98,7 @@ function world_conquest_tek_map_repaint_2e()
-- chance of farms replacing yards
if wesnoth.random(20) == 1 then
if mathx.random(20) == 1 then
set_terrain { "Rb^Gvs,Rb^Gvs,Rb^Gvs,Gg",
f.terrain("*^Eff"),
}
@ -136,7 +136,7 @@ function wct_map_yard(directions, counter_directions)
))
if #terrain_to_change > 0 then
local loc = terrain_to_change[wesnoth.random(#terrain_to_change)]
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
map[loc] = "Gg^Eff"
set_terrain { "Gg^Eff",
f.adjacent( f.is_loc(loc), counter_directions, nil)
@ -202,7 +202,7 @@ function wct_map_decoration_3e_leantos()
)
))
for i, v in ipairs(terrain_to_change) do
if wesnoth.random(3) == 1 then
if mathx.random(3) == 1 then
map[v] = "Rrc"
table.insert(prestart_event, wml.tag.item {

View File

@ -9,7 +9,7 @@ end
function world_conquest_tek_map_decoration_3a()
-- chances of some dessert over swamp
if wesnoth.random(4) ~= 1 then
if mathx.random(4) ~= 1 then
set_terrain { "Dd^Edp,Dd^Do,Dd,Dd,Dd,Dd,Dd,Dd",
f.all(
f.terrain("Ss"),
@ -139,7 +139,7 @@ function world_conquest_tek_map_decoration_3a()
f.terrain("Xu"),
}
if wesnoth.random(20) ~= 1 then
if mathx.random(20) ~= 1 then
wct_change_map_water("t")
end
set_terrain { "Gs^Ft",

View File

@ -378,7 +378,7 @@ function world_conquest_tek_map_decoration_3c()
}
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
wct_change_map_water("t")
end
end

View File

@ -10,8 +10,8 @@ function world_conquest_tek_map_repaint_3f()
-- soft rough terrain generated
local terrain_to_change = wct_store_cave_passages_candidates()
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)
-- the original code also did not randomize this.
-- todo: but maybe we should? (use mathx.random(#terrain_to_change) instead of 1 here)
map[terrain_to_change[1]] = "Mm"
terrain_to_change = wct_store_cave_passages_candidates()
end
@ -145,7 +145,7 @@ function wct_map_3f_post_bunus_decoration(bonus_points)
fraction = 4,
}
if wesnoth.random(7) == 1 then
if mathx.random(7) == 1 then
set_terrain { "Wwf",
f.all(
f.terrain("G*"),
@ -160,7 +160,7 @@ function wct_map_3f_post_bunus_decoration(bonus_points)
}
end
if wesnoth.random(7) == 1 then
if mathx.random(7) == 1 then
set_terrain { "Wwf",
f.all(
f.terrain("G*"),

View File

@ -101,7 +101,7 @@ function world_conquest_tek_map_decoration_4a()
}
-- better road near castle
local rad = helper.rand("1,2,3,3,3,3,4,4")
local rad = mathx.random_choice("1,2,3,3,3,3,4,4")
set_terrain { "Rr",
f.all(
f.terrain("Re"),
@ -150,8 +150,8 @@ function world_conquest_tek_map_decoration_4a()
-- chances flowers
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)]
while #terrain_to_change > 0 and mathx.random(10) > 5 do
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
map[loc] = "^Efm"
terrain_to_change = wct_store_possible_flowers("Rr^Vhc")
end
@ -162,30 +162,30 @@ function world_conquest_tek_map_decoration_4a()
layer = "overlay",
}
if wesnoth.random(20) == 1 then
if mathx.random(20) == 1 then
set_terrain { "*^Ftr",
f.terrain("G*^Fds"),
layer = "overlay",
}
end
if wesnoth.random(20) == 1 then
if mathx.random(20) == 1 then
set_terrain { "*^Ftr",
f.terrain("G*^Fms"),
fraction = 3,
layer = "overlay",
}
end
if wesnoth.random(20) == 1 then
if mathx.random(20) == 1 then
set_terrain { "*^Ftr",
f.terrain("G*^Fp"),
fraction = 5,
layer = "overlay",
}
end
if wesnoth.random(20) == 1 then
if mathx.random(20) == 1 then
wct_map_decorative_docks()
end
if wesnoth.random(20) == 1 then
if mathx.random(20) == 1 then
wct_change_map_water("g")
end
end

View File

@ -91,21 +91,21 @@ function world_conquest_tek_map_repaint_4b()
fraction = 3,
}
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
set_terrain { "Ur^Vd",
f.terrain("Ur^Vu"),
fraction_rand = "2..3",
}
end
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
set_terrain { "Rd^Vd",
f.terrain("Rd^Vhh"),
fraction_rand = "2..3",
}
end
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
set_terrain { "Ds^Vd",
f.terrain("D*^V*"),
fraction_rand = "3..4",
@ -193,7 +193,7 @@ function world_conquest_tek_map_repaint_4b()
f.adjacent(f.terrain("K*^*,C*^*,*^V"), "se,s,sw", 0)
))
if #terrain_to_change > 0 then
local loc = terrain_to_change[wesnoth.random(#terrain_to_change)]
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
set_terrain { "Md^Xm",
f.all(
f.none(f.terrain("M*^*")),
@ -277,8 +277,8 @@ function world_conquest_tek_map_repaint_4b()
-- mushrooms, base amount in map surface
local terrain_to_change = map:find(f.terrain("Hhd,Hhd^F^*"))
helper.shuffle(terrain_to_change)
local r = helper.rand(tostring(total_tiles // 600) .. ".." .. tostring(total_tiles // 300))
mathx.shuffle(terrain_to_change)
local r = mathx.random_choice(tostring(total_tiles // 600) .. ".." .. tostring(total_tiles // 300))
for mush_i = 1, math.min(r, #terrain_to_change) do
map[terrain_to_change[mush_i]] = "Hhd^Uf"
@ -321,8 +321,8 @@ function world_conquest_tek_map_repaint_4b()
f.adjacent(f.terrain("Uue"))
))
helper.shuffle(whirlpool_candidats)
for i = 1, #whirlpool_candidats // wesnoth.random(4, 15) do
mathx.shuffle(whirlpool_candidats)
for i = 1, #whirlpool_candidats // mathx.random(4, 15) do
local loc = whirlpool_candidats[i]
table.insert(prestart_event, wml.tag.item {
@ -354,11 +354,11 @@ function world_conquest_tek_map_repaint_4b()
-- very dirt coast
local terrain_to_change = map:find(f.terrain("Ds"))
helper.shuffle(terrain_to_change)
for i = 1, #terrain_to_change // wesnoth.random(3, 4) do
mathx.shuffle(terrain_to_change)
for i = 1, #terrain_to_change // mathx.random(3, 4) do
map[terrain_to_change[i]] = "Ds^Esd"
end
helper.shuffle(terrain_to_change)
mathx.shuffle(terrain_to_change)
for i = 1, #terrain_to_change // 6 do
map[terrain_to_change[i]] = "Ds^Es"
end
@ -401,7 +401,7 @@ function world_conquest_tek_map_repaint_4b()
}
local r = wesnoth.random(20)
local r = mathx.random(20)
if r == 1 then
wct_change_map_water("g")
elseif r == 2 then

View File

@ -230,7 +230,7 @@ function world_conquest_tek_map_decoration_4c()
layer = "overlay",
}
if wesnoth.random(20) == 1 then
if mathx.random(20) == 1 then
wct_change_map_water("t")
end
end
@ -262,7 +262,7 @@ function wct_map_4c_post_bunus_decoration()
))
for forge_i, v in ipairs(terrain_to_change) do
local r = wesnoth.random(6)
local r = mathx.random(6)
if r == 1 then
map[v] = "Cud"
elseif r == 2 then

View File

@ -1,7 +1,7 @@
-- Podzol
local function world_conquest_tek_map_repaint_4d()
local rad = helper.rand("1,2,2")
local rad = mathx.random_choice("1,2,2")
world_conquest_tek_map_noise_proxy(rad, 2 , "!,W*^*,Ai,Ds*^*,Xu,M*^Xm,R*^*,Ch*,Cud,K*,U*^*,Ql^B*")
wct_reduce_wall_clusters("Uu,Uu,Uu,Uu,Uh,Uh,Ai")
@ -102,7 +102,7 @@ local function world_conquest_tek_map_repaint_4d()
f.terrain("Ww"),
}
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
set_terrain { "Ai",
f.all(
f.terrain("Wwg"),

View File

@ -364,7 +364,7 @@ function world_conquest_tek_map_repaint_4e()
}
local r = "Gs^Fp,Gs^Fms,Gs^Fds,Gs^Ft,Gs^Ft,Gs^Ftp,Gs^Ftr,Gs^Ftd,Gs^Fet"
r = helper.rand(r)
r = mathx.random_choice(r)
set_terrain { r,
f.all(
f_west_half,
@ -376,7 +376,7 @@ function world_conquest_tek_map_repaint_4e()
}
local r = "Gs^Fp,Gs^Fms,Gs^Fds,Gs^Ftp,Gs^Ft,Gs^Ftp,Gs^Ftr,Gs^Ftd,Gs^Fet,Gs^Fts,Gs^Fts,Gs^Ft,Gs^Ft,Gs^Ftd,Gs^Fp"
r = helper.rand(r)
r = mathx.random_choice(r)
set_terrain { r,
f.all(
f.terrain("Gs^F*,Hh^F*"),
@ -587,7 +587,7 @@ function wct_map_4e_post_bunus_decoration()
f_north_half
)
),
fraction = wesnoth.random(10,30),
fraction = mathx.random(10,30),
}
-- small mushrooms northeast
@ -601,7 +601,7 @@ function wct_map_4e_post_bunus_decoration()
f_west_half
)
),
fraction = wesnoth.random(2,3),
fraction = mathx.random(2,3),
}
-- slighty soft dessert southwest

View File

@ -70,7 +70,7 @@ function repaint(map_data)
exact = false,
}
if wesnoth.random(4) == 1 then
if mathx.random(4) == 1 then
set_terrain { "Ww",
f.terrain("Wwg^*"),
layer = "base",
@ -238,7 +238,7 @@ function wild_zones_replace(heights)
for i_temp, temp in ipairs(height) do
handle_single_zone(temp.all_locs, temp[1].default)
for zone_i, zone in ipairs(temp.zones) do
local wild_dice = wesnoth.random(100)
local wild_dice = mathx.random(100)
for chance_i, chance in ipairs(temp[1].chances) do
if wild_dice <= chance.value then
handle_single_zone(zone, chance.command)

View File

@ -67,7 +67,7 @@ local function world_conquest_tek_map_decoration_6a()
}
-- stone roads, better ones near castle
local rad = wesnoth.random(4, 6)
local rad = mathx.random(4, 6)
set_terrain { "Rrc",
f.all(
f.terrain("Re"),
@ -175,7 +175,7 @@ local function world_conquest_tek_map_decoration_6a()
))
))
local r = helper.rand(tostring(total_tiles // 930) .. ".." .. tostring(total_tiles // 210))
local r = mathx.random_choice(tostring(total_tiles // 930) .. ".." .. tostring(total_tiles // 210))
wct_storm(terrain_to_change, r + 2)
wct_expand_snow()
@ -269,14 +269,14 @@ local function world_conquest_tek_map_decoration_6a()
-- chances of few dwarven castles
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)]
while #terrain_to_change > 0 and mathx.random(2) == 1 do
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
map[loc] = "Cud"
terrain_to_change = wct_store_possible_dwarven_castle()
end
-- decorative farmlands in base to log villages
local terrain_to_change = map:find(f.terrain("Gs^Vl"))
for i = 1, wesnoth.random(0, 2 * #terrain_to_change) do
for i = 1, mathx.random(0, 2 * #terrain_to_change) do
set_terrain { "Gg^Gvs",
f.all(
f.terrain("Gs,Gg"),
@ -319,7 +319,7 @@ local function world_conquest_tek_map_decoration_6a()
}
-- chance of fences near farmlands
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
local terrain_to_change = map:find(f.all(
f.terrain("Gs,Gg,Gll,Aa,Ai"),
f.adjacent(f.terrain("Gg^Gvs")),
@ -333,7 +333,7 @@ local function world_conquest_tek_map_decoration_6a()
end
end
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
set_terrain { "Gs^Eff",
f.any(
f.all(
@ -350,7 +350,7 @@ local function world_conquest_tek_map_decoration_6a()
end
-- chances of stone walls and dark roads near darven castls
local rad = wesnoth.random(1, 4)
local rad = mathx.random(1, 4)
set_terrain { "Xos",
f.all(
f.terrain("Xu"),
@ -359,7 +359,7 @@ local function world_conquest_tek_map_decoration_6a()
}
wct_map_cave_path_to("Re")
local r = helper.rand("Ur,Urb")
local r = mathx.random_choice("Ur,Urb")
set_terrain { r,
f.all(
f.terrain("Re"),
@ -367,7 +367,7 @@ local function world_conquest_tek_map_decoration_6a()
),
}
if wesnoth.random(3) == 0 then
if mathx.random(3) == 0 then
set_terrain { "Xuc",
f.all(
f.terrain("Xu"),
@ -382,10 +382,10 @@ local function world_conquest_tek_map_decoration_6a()
}
end
if wesnoth.random(20) == 1 then
if mathx.random(20) == 1 then
wct_map_decorative_docks()
end
if wesnoth.random(20) == 1 then
if mathx.random(20) == 1 then
wct_change_map_water("g")
end
wct_noise_snow_to("Wwf")

View File

@ -42,8 +42,8 @@ function wct_maritime_bridges()
local pb = get_possible_maritime_bridge()
while #pb[1].locs > 0 or #pb[2].locs > 0 or #pb[3].locs > 0 do
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)]
local sel = pb[mathx.random(#pb)]
local loc = sel.locs[mathx.random(#sel.locs)]
map[loc] = "Ww^" .. sel.type
pb = get_possible_maritime_bridge()
end
@ -190,7 +190,7 @@ function world_conquest_tek_map_decoration_6b()
f.adjacent(f.terrain("W*^*"), nil, "2-5"),
f.adjacent(f.terrain("Wog,Wwg"))
))
loc = locs[wesnoth.random(#locs)];
loc = locs[mathx.random(#locs)];
map[loc] = "Iwr^Vl"
end
@ -238,7 +238,7 @@ function world_conquest_tek_map_decoration_6b()
}
local locs = map:find(f.terrain("Iwr"))
for ship_i, ship_loc in ipairs(locs) do
if wesnoth.random(2) == 1 then
if mathx.random(2) == 1 then
table.insert(prestart_event, wml.tag.item {
x = ship_loc[1],
y = ship_loc[2],
@ -368,7 +368,7 @@ function world_conquest_tek_map_decoration_6b()
}
-- chance of expand rivers into sea
local r = tonumber(helper.rand("0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,2,2,3"))
local r = tonumber(mathx.random_choice("0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,2,2,3"))
for i = 1 , r do
local terrain_to_change = map:find(f.all(
f.terrain("Wog,Wwg,Wwrg"),

View File

@ -103,8 +103,8 @@ local function wct_dirty_deltas()
local terrain_to_change = wct_store_possible_dirty_delta()
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")
local loc = 1 -- todo: maybe use terrain_to_change[mathx.random(#terrain_to_change)]
local ter = mathx.random_choice("Gs,Hh^Uf,Cud,Gs^Uf,Gs,Hh,Ds^Edt,Ds,Hh^Fmf,Gs,Gs^Fmf")
map[loc] = ter
terrain_to_change = wct_store_possible_dirty_delta()
end
@ -122,8 +122,8 @@ local function wct_ford_deltas()
local terrain_to_change = wct_store_possible_ford_delta()
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")
local loc = terrain_to_change[1]-- todo: maybe use errain_to_change[mathx.random(#terrain_to_change)]
local ter = mathx.random_choice("Gg,Gg^Efm,Mm,Gg^Fet,Gg,Mm,Gg")
map[loc] = ter
terrain_to_change = wct_store_possible_ford_delta()
end
@ -385,7 +385,7 @@ local function world_conquest_tek_map_decoration_6c()
))
for swamp_i, swamp_loc in ipairs(terrain_to_change) do
local r = wesnoth.random(3, map.width // 4)
local r = mathx.random(3, map.width // 4)
set_terrain { "Sm",
f.all(
f.terrain("Ww^*"),
@ -402,7 +402,7 @@ local function world_conquest_tek_map_decoration_6c()
))
for water_i, water_loc in ipairs(terrain_to_change) do
local r = wesnoth.random(4, map.width // 6)
local r = mathx.random(4, map.width // 6)
set_terrain { "Wwg",
f.all(
f.terrain("Ww^*"),
@ -413,7 +413,7 @@ local function world_conquest_tek_map_decoration_6c()
}
end
-- fords
local r = wesnoth.random(4, map.width // 10)
local r = mathx.random(4, map.width // 10)
set_terrain { "Wwf",
f.all(
f.terrain("Ww^*"),

View File

@ -453,7 +453,7 @@ local function world_conquest_tek_map_repaint_6d()
fraction_rand = "24..240",
}
if wesnoth.random(20) == 1 then
if mathx.random(20) == 1 then
wct_map_decorative_docks()
end
-- beachs sand and stones

View File

@ -63,12 +63,12 @@ function set_terrain_impl(data)
if d.exact then
num_tiles = math.ceil(num_tiles * chance / 1000)
chance = 1000
helper.shuffle(locs[i])
mathx.shuffle(locs[i])
end
for j = 1, num_tiles do
local loc = locs[i][j]
if chance >= 1000 or chance >= wesnoth.random(1000) then
map[loc] = wesnoth.map['replace_' .. layer](helper.rand(terrains))
if chance >= 1000 or chance >= mathx.random(1000) then
map[loc] = wesnoth.map['replace_' .. layer](mathx.random_choice(terrains))
nlocs_changed = nlocs_changed + 1
end
end
@ -95,7 +95,7 @@ function set_terrain_simul(cfg)
elseif r.fraction then
r_new.per_thousand = math.ceil(1000 / r.fraction);
elseif r.fraction_rand then
r_new.per_thousand = math.ceil(1000 / helper.rand(r.fraction_rand));
r_new.per_thousand = math.ceil(1000 / mathx.random_choice(r.fraction_rand));
end
table.insert(data, r_new)
end

View File

@ -146,7 +146,7 @@ function wct_castle_expansion_side(side_num)
wesnoth.log("warn", "Too few tiles in castle expansion for side " .. side_num .. ", wanted: " .. n_tiles_wanted .. " but we got only " .. #candidates)
n_tiles_wanted = #candidates
end
helper.shuffle(candidates)
mathx.shuffle(candidates)
for i = 1, n_tiles_wanted do
map[candidates[i]] = "Ch"
end

View File

@ -1,7 +1,7 @@
function world_conquest_tek_map_noise_proxy(radius, fraction, terrain)
local terrain_to_change = map:find(f.terrain(terrain))
local nop_filter = wesnoth.map.filter(f.all())
helper.shuffle(terrain_to_change)
mathx.shuffle(terrain_to_change)
for terrain_i = 1, math.ceil(#terrain_to_change / fraction) do
local loc_a = terrain_to_change[terrain_i]
local terrain_to_swap_b = map:find_in_radius({loc_a}, radius, nop_filter)
@ -12,7 +12,7 @@ function world_conquest_tek_map_noise_proxy(radius, fraction, terrain)
), terrain_to_swap_b)
if #terrain_to_swap_b > 0 then
local loc_b = terrain_to_swap_b[wesnoth.random(#terrain_to_swap_b)]
local loc_b = terrain_to_swap_b[mathx.random(#terrain_to_swap_b)]
local terrain_a, terrain_b = map[loc_a], map[loc_b]
map[loc_a] = terrain_b
map[loc_b] = terrain_a

View File

@ -128,8 +128,8 @@ function wct_expand_snow()
),
}
-- chances of expand ice
if wesnoth.random(20) == 1 then
local r = wesnoth.random(3)
if mathx.random(20) == 1 then
local r = mathx.random(3)
set_terrain { "Ai",
f.all(
f.terrain("Ww,Wo"),
@ -138,8 +138,8 @@ function wct_expand_snow()
}
end
if wesnoth.random(20) == 1 then
local r = wesnoth.random(4, 5)
if mathx.random(20) == 1 then
local r = mathx.random(4, 5)
set_terrain { "Ai",
f.all(
f.terrain("Aa"),
@ -156,7 +156,7 @@ function wct_storm(terrain_to_change, snow)
return
end
for show_i = 1, snow do
local loc = terrain_to_change[wesnoth.random(#terrain_to_change)]
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
set_terrain { "Ai",
f.terrain("Aa"),
locs = { loc },

View File

@ -47,7 +47,7 @@ function world_conquest_tek_map_rebuild(cave, reef)
-- replace hills for mushrooms
-- base amount in map surface
local r = helper.rand(tostring(total_tiles // 500) .. ".." .. tostring(total_tiles // 250))
local r = mathx.random_choice(tostring(total_tiles // 500) .. ".." .. tostring(total_tiles // 250))
-- just to be sure.
r = tonumber(r)
set_terrain { "Hh^Uf",
@ -190,8 +190,8 @@ end
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)]
while #terrain_to_change > 0 and mathx.random(value + 1) == 1 do
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
map[loc] = terrain
terrain_to_change = wct_store_possible_map4_castle(value)
end
@ -220,7 +220,7 @@ function wct_road_to_village(road, village)
-- build roads of 1 hex to conect villages
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)]
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
map[loc] = road
terrain_to_change = wct_store_possible_roads(village)
end
@ -233,7 +233,7 @@ function wct_iterate_roads_to(get_next, radius, terrain)
for r = radius, 1, -1 do
local locs = get_next(r)
while #locs > 0 do
local loc = locs[wesnoth.random(#locs)]
local loc = locs[mathx.random(#locs)]
map[loc] = terrain
locs = get_next(r)
end
@ -287,7 +287,7 @@ function wct_iterate_roads_to_2(f_validpath, f_src, f_dest, terrain_road, radius
goto path_found
end
end
path[#path + 1] = next_locs[wesnoth.random(#next_locs)]
path[#path + 1] = next_locs[mathx.random(#next_locs)]
loc = path[#path]
dist = distmap:get(loc)
end
@ -309,8 +309,8 @@ 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[loc] = helper.rand(terrain)
local loc = terrain_to_change[mathx.random(#terrain_to_change)]
map[loc] = mathx.random_choice(terrain)
terrain_to_change = wct_store_broken_wall_candidates(wall)
end
end

View File

@ -10,7 +10,7 @@ local function wild_volcano_for_lava_zone(terrain_to_change)
), { terrain_to_change = terrain_to_change })
if #possible_volcano > 0 then
local loc = possible_volcano[wesnoth.random(#possible_volcano)]
local loc = possible_volcano[mathx.random(#possible_volcano)]
set_terrain { "Md^Xm",
f.adjacent(f.is_loc(loc), "ne,n,nw")
}

View File

@ -20,7 +20,7 @@ function random_placement(locs, num_items, min_distance, command)
helper.wml_error("[random_placement] failed to place items. only " .. i .. " items were placed")
end
end
local index = wesnoth.random(size)
local index = mathx.random(size)
local point = locs[index]
command(point, i)
@ -391,7 +391,7 @@ function wct_bonus_chose_scenery(loc, theme, filter_extra)
end
::final_pick::
-- pick random scenery value from our list
local res = helper.rand(scenery)
local res = mathx.random_choice(scenery)
wesnoth.log("debug", "scenery:" .. res .. " from " .. scenery)
return res
end

View File

@ -43,7 +43,7 @@ function add_plot(scenario, scenario_num, nplayers)
end_message("1,2,3", true, _ "Victory is ours! Let us set sail in search of new lands to conquer!")
elseif scenario_num == 2 then
local r = wesnoth.random(nplayers)
local r = mathx.random(nplayers)
start_message(r, true, _ "Ahhh. Just look at these fertile lands, ripe for conquest!")
start_message("4", true, _ "Whats this?! Foreign invaders have set foot upon our shores!")
start_message("5", true, _ "Well send them back to where they came from quick enough. All troops, to me!")
@ -57,7 +57,7 @@ function add_plot(scenario, scenario_num, nplayers)
end_message("1,2,3", true, _ "Victory is ours! Let us set sail in search of new lands to conquer!")
elseif scenario_num == 4 then
local r = wesnoth.random(nplayers)
local r = mathx.random(nplayers)
start_message("5", true, _ "Ready yourselves, men! The conquering hordes are upon us!")
start_message("4", true, _ "Word has come to our island of your victories. Your army is impressive, but it will avail you not.")
start_message("6", true, _ "Indeed. You come this far, and no farther!")
@ -69,7 +69,7 @@ function add_plot(scenario, scenario_num, nplayers)
end_message("1,2,3", false, _ "We have travelled great oceans and brought low mighty empires. Should we not wait until our forces regain their strength?")
end_message("1,2,3", true, _ "One last effort! We better finish our campaign when we hold initiative, before Winter arrives.")
else
local r = wesnoth.random(nplayers)
local r = mathx.random(nplayers)
start_message(r, true, _ "Finally we come to the shores of the last continent. Here at the edge of the world our empire shall be made complete.")
start_message("4", true, _ "Never! Your mad quest ends here, tyrant.")

View File

@ -1,6 +1,4 @@
local helper = wesnoth.require("helper")
globals = {}
setmetatable(globals, {
["__index"] = function(t, k)
@ -37,7 +35,7 @@ function shuffle_special_locations(map, loc_ids)
locs[i] = map.special_locations[tostring(v)]
end
assert(#locs == #loc_ids)
helper.shuffle(locs)
mathx.shuffle(locs)
for i , v in ipairs(loc_ids) do
map.special_locations[tostring(v)] = locs[i]
end

View File

@ -76,9 +76,9 @@ on_event("die", function(cx)
map[loc] = "^Fetd"
elseif loc:matches{terrain = "Aa"} then
item(snow[wesnoth.random(#snow)])
item(snow[mathx.random(#snow)])
elseif loc:matches{terrain = "Ai"} then
item(ice[wesnoth.random(#ice)])
item(ice[mathx.random(#ice)])
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")

View File

@ -1,6 +1,6 @@
local MG = wesnoth.require "mapgen_helper"
local LS = wesnoth.require "location_set"
local random = wesnoth.random
local random = mathx.random
local callbacks = {}

View File

@ -53,7 +53,7 @@ function mathx.random_choice(possible_values, random_func)
-- We need to parse ranges separately anyway
for i, val in ipairs(possible_values) do
if type(val) == "table" then
assert(#val == 2 and type(val[1]) == "number" and type(val[2]) == "number", "Malformed range for helper.rand")
assert(#val == 2 and type(val[1]) == "number" and type(val[2]) == "number", "Malformed range for mathx.random_choice")
if val[1] > val[2] then
val = {val[2], val[1]}
end
@ -95,4 +95,4 @@ function mathx.shuffle(t, random_func)
end
end
wesnoth.random = wesnoth.deprecate_api('wesnoth.random', 'mathx.random', 1, nil, mathx.random)
mathx.random = wesnoth.deprecate_api('mathx.random', 'mathx.random', 1, nil, mathx.random)

View File

@ -280,7 +280,7 @@ function methods:random()
-- Select a random hex from the hexes in the location set
-- This seems "inelegant", but I can't come up with another way without creating an extra array
-- Return -1, -1 if empty
local r = wesnoth.random(self:size())
local r = mathx.random(self:size())
local i, xr, yr = 1, -1, -1
self:iter( function(x, y, v)
if (i == r) then xr, yr = x, y end

View File

@ -35,7 +35,7 @@ wesnoth.wml_actions.random_placement = function(cfg)
wml.error("[random_placement] failed to place items. only " .. i .. " items were placed")
end
end
local index = wesnoth.random(size)
local index = mathx.random(size)
local point = locs[index]
wml.variables[variable .. ".x"] = point[1]
wml.variables[variable .. ".y"] = point[2]

View File

@ -1,4 +1,3 @@
local helper = wesnoth.require "helper"
function wesnoth.wml_actions.set_variable(cfg, variables)
local name = cfg.name or wml.error "trying to set a variable with an empty name"
@ -106,7 +105,7 @@ function wesnoth.wml_actions.set_variable(cfg, variables)
else
local decimals = math.modf(tonumber(round_val) or 0)
local value = var * (10 ^ decimals)
value = helper.round(value)
value = mathx.round(value)
value = value * (10 ^ -decimals)
variables[name] = value
end
@ -154,7 +153,7 @@ function wesnoth.wml_actions.set_variable(cfg, variables)
end
if cfg.rand then
variables[name] = helper.rand(tostring(cfg.rand))
variables[name] = mathx.random_choice(tostring(cfg.rand))
end
if cfg.formula then

View File

@ -212,7 +212,7 @@ on_event("moveto", function()
pickadvance.pick_advance(unit)
if #unit.advances_to > 1 then
local len = #unit.advances_to
local rand = wesnoth.random(len)
local rand = mathx.random(len)
unit.advances_to = { unit.advances_to[rand] }
end
else

View File

@ -1,5 +1,4 @@
local helper = wesnoth.require("helper")
local _ = wesnoth.textdomain 'wesnoth-multiplayer'
local T = wml.tag
local on_event = wesnoth.require("on_event")
@ -96,7 +95,7 @@ local function get_spawn_types(num_units, max_gold, unit_pool)
local units_left = num_units
local current_types = {}
while gold_left > 0 and units_left > 0 do
local unit_group = wesnoth.random(#unit_pool)
local unit_group = mathx.random(#unit_pool)
local unit_rank = 1
local unit_type = wesnoth.unit_types[unit_pool[unit_group][unit_rank]]
table.insert(current_types, { group = unit_group, type = unit_type})
@ -143,7 +142,7 @@ local function get_spawn_types(num_units, max_gold, unit_pool)
table.insert(possible_groups, { group = i, type = unit_type})
end
end
local index = wesnoth.random(#possible_groups)
local index = mathx.random(#possible_groups)
table.insert(current_types, possible_groups[index])
gold_left = gold_left - possible_groups[index].type.cost
end
@ -165,22 +164,22 @@ local function create_timed_spawns(interval, num_spawns, base_gold_amount, gold_
for i = 1, #random_spawns do
table.insert(random_spawn_numbers, i)
end
helper.shuffle(random_spawn_numbers)
local final_turn = math.ceil(((num_spawns - 1) * interval + 40 + wesnoth.random(2,4))/2)
mathx.shuffle(random_spawn_numbers)
local final_turn = math.ceil(((num_spawns - 1) * interval + 40 + mathx.random(2,4))/2)
local end_spawns = 0
for spawn_number = 1, num_spawns do
local turn = 3 + (spawn_number - 1) * interval
local gold = base_gold_amount + (turn - 3) * gold_increment
if spawn_number > 1 then
-- foruma taken from original Dark forecast, TODO: find easier formula.
local unit_gold = (turn - 3) * gold_increment + math.min(wesnoth.random(base_gold_amount), wesnoth.random(base_gold_amount))
local unit_gold = (turn - 3) * gold_increment + math.min(mathx.random(base_gold_amount), mathx.random(base_gold_amount))
local gold_per_unit = gold_per_unit_amount + turn / 1.5
local units = unit_gold / gold_per_unit + units_amount + wesnoth.random(-1, 2)
if wesnoth.random(5) == 5 then
local units = unit_gold / gold_per_unit + units_amount + mathx.random(-1, 2)
if mathx.random(5) == 5 then
units = units - 1
end
-- end complicated formula
turn = turn + wesnoth.random(-1, 1)
turn = turn + mathx.random(-1, 1)
-- reduce gold and units for spawns after the final spawn
if turn >= final_turn then
units = units / (end_spawns + 3)
@ -194,7 +193,7 @@ local function create_timed_spawns(interval, num_spawns, base_gold_amount, gold_
wml.variables[string.format("timed_spawn[%d]", spawn_number - 1)] = {
units = math.ceil(units),
turn = turn,
gold = helper.round(gold * configure_gold_factor),
gold = mathx.round(gold * configure_gold_factor),
pool_num = random_spawn_numbers[spawn_number],
}
else
@ -235,7 +234,7 @@ local function final_spawn()
if spawns_left == 0 then
return
end
local spawn_index = wesnoth.random(spawns_left) - 1
local spawn_index = mathx.random(spawns_left) - 1
local spawn = wml.variables[string.format("fixed_spawn[%d]", spawn_index)]
wml.variables[string.format("fixed_spawn[%d]", spawn_index)] = nil
local types = {}
@ -276,9 +275,9 @@ on_event("new turn", function()
wml.variables["timed_spawn[0]"] = nil
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 spawn_area = spawn_areas[mathx.random(#spawn_areas)]
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)]
local chosen_location = locations_in_area[mathx.random(#locations_in_area)]
place_units(unit_types, chosen_location[1], chosen_location[2])
end)
@ -301,7 +300,7 @@ on_event("new turn", function()
message= _ "The last and most powerful of these creatures are almost upon us. I feel that if we can finish them off in time, we shall be victorious.",
}
wml.variables["next_final_spawn"] = wesnoth.current.turn + wesnoth.random(1,2)
wml.variables["next_final_spawn"] = wesnoth.current.turn + mathx.random(1,2)
end)
-- after the first final spawn, spawn a new final spawn every 1 or 2 turns.
@ -310,7 +309,7 @@ on_event("new turn", function()
return
end
final_spawn()
wml.variables["next_final_spawn"] = wesnoth.current.turn + wesnoth.random(1,2)
wml.variables["next_final_spawn"] = wesnoth.current.turn + mathx.random(1,2)
end)
-- The victory condition: win when there are no enemy unit after the first final spawn appeared.
@ -359,15 +358,15 @@ end)
-- The weather evens are complateleey unrelated to the spawn events.
local function get_weather_duration(max_duration)
local res = wesnoth.random(2)
while res < max_duration and wesnoth.random(2) == 2 do
local res = mathx.random(2)
while res < max_duration and mathx.random(2) == 2 do
res = res + 1
end
return res
end
-- initilize the weather_event wml array which defines at which turns the weather changes.
on_event("prestart", function()
local turn = wesnoth.random(4,6)
local turn = mathx.random(4,6)
local event_num = 0
local weather_to_dispense = {
{ turns_left = 10, id = "drought"},
@ -378,7 +377,7 @@ on_event("prestart", function()
local heavy_snowfall_turns_left = 6
while turn < 55 and #weather_to_dispense > 0 do
-- pick a random weather except 'clear' and 'heavy snow'
local index = wesnoth.random(#weather_to_dispense)
local index = mathx.random(#weather_to_dispense)
local num_turns = get_weather_duration(weather_to_dispense[index].turns_left)
local weather_id = weather_to_dispense[index].id
weather_to_dispense[index].turns_left = weather_to_dispense[index].turns_left - num_turns
@ -392,7 +391,7 @@ on_event("prestart", function()
event_num = event_num + 1
turn = turn + num_turns
-- Second snow happens half the time.
if weather_id == "snowfall" and heavy_snowfall_turns_left >= 0 and wesnoth.random(2) == 2 then
if weather_id == "snowfall" and heavy_snowfall_turns_left >= 0 and mathx.random(2) == 2 then
num_turns = get_weather_duration(heavy_snowfall_turns_left)
wml.variables[string.format("weather_event[%d]", event_num)] = {
turn = turn,

View File

@ -13,7 +13,7 @@ local function create_game(context)
context.select_type({type = "scenario"})
local s = info.find_level({id = "test1"})
context.select_level({index = s.index})
context.set_name({name = tostring(wesnoth.random(999999))})
context.set_name({name = tostring(mathx.random(999999))})
context.update_settings({registered_users = false})
events, context, info = coroutine.yield()
@ -52,7 +52,7 @@ return function()
-- Reached the lobby. Random delay before we start actually simulating activity.
-- This is here to avoid a situation where activity arrives in bursts after a script
-- has launched, say, 100 copies of Wesnoth at the same time.
wesnoth.interface.delay(wesnoth.random(15000))
wesnoth.interface.delay(mathx.random(15000))
events, context, info = coroutine.yield()
@ -64,10 +64,10 @@ return function()
exit_game(context)
end
if wesnoth.random() > 0.1 then
if mathx.random() > 0.1 then
-- chat message
local messages = {"asdf", "qwerty", "zxc"}
context.chat({message = messages[wesnoth.random(#messages)]})
context.chat({message = messages[mathx.random(#messages)]})
else
-- toggle between creating a game and leaving it
if not in_staging then