Merge pull request #1021 from wesnoth/lua_require
Improve the wesnoth.require implementation
This commit is contained in:
commit
787a46820e
111 changed files with 873 additions and 789 deletions
|
@ -40,6 +40,9 @@ Version 1.13.7+dev:
|
|||
* wesnoth.set_music is now deprecated, in favour of the above new API
|
||||
* New wesnoth.sound_volume function gets/sets the current sound volume, as [volume]sound=
|
||||
* New wesnoth.show_story function launches the storyscreen viewer
|
||||
* wesnoth.dofile now forwards any excess arguments to the file in the "..." argument
|
||||
* wesnoth.require can now load all modules in a directory and accepts some shortened paths,
|
||||
for example omitting the ".lua" file extension.
|
||||
* Multiplayer:
|
||||
* Fixed statistics being lost when reloading an MP game.
|
||||
* Performance:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local W = H.set_wml_action_metatable {}
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
|
||||
-- This is a collection of Lua functions used for custom AI development.
|
||||
-- Note that this is still work in progress with significant changes occurring
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
|
||||
-- This is a collection of Lua functions used for custom AI development.
|
||||
-- Note that this is still work in progress with significant changes occurring
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
|
||||
-- Evaluation process:
|
||||
--
|
||||
|
|
|
@ -23,10 +23,10 @@ return {
|
|||
end
|
||||
math.randomseed(os.time())
|
||||
|
||||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local W = H.set_wml_action_metatable {}
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
|
||||
local function print_time(...)
|
||||
if turn_start_time then
|
||||
|
|
|
@ -6,11 +6,11 @@ return {
|
|||
|
||||
-- More generic grunt rush (and can, in fact, be used with other unit types as well)
|
||||
|
||||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local W = H.set_wml_action_metatable {}
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local BC = wesnoth.require "ai/lua/battle_calcs.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
local HS = wesnoth.require "ai/micro_ais/cas/ca_healer_move.lua"
|
||||
local R = wesnoth.require "ai/lua/retreat.lua"
|
||||
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
Functions to support the retreat of injured units
|
||||
]=]
|
||||
|
||||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local BC = wesnoth.require "ai/lua/battle_calcs.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
|
||||
local retreat_functions = {}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
|
||||
local function get_units_target(cfg)
|
||||
local units = AH.get_units_with_moves {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
local MAIUV = wesnoth.require "ai/micro_ais/micro_ai_unit_variables.lua"
|
||||
|
||||
local function get_big_animals(cfg)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
|
||||
local ca_bottleneck_attack = {}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local LS = wesnoth.require "location_set"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local BC = wesnoth.require "ai/lua/battle_calcs.lua"
|
||||
local MAISD = wesnoth.require "ai/micro_ais/micro_ai_self_data.lua"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
|
||||
local function get_coward(cfg)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
local T = H.set_wml_tag_metatable{}
|
||||
|
||||
-- Functions to perform fast evaluation of attacks and attack combinations.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local FAU = wesnoth.require "ai/micro_ais/cas/ca_fast_attack_utils.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
|
||||
local ca_fast_combat = {}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local FAU = wesnoth.require "ai/micro_ais/cas/ca_fast_attack_utils.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
|
||||
local ca_fast_combat_leader = {}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local FAU = wesnoth.require "ai/micro_ais/cas/ca_fast_attack_utils.lua"
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local W = H.set_wml_action_metatable {}
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
|
||||
local function get_forest_animals(cfg)
|
||||
-- We want the deer/rabbits to move first, tuskers afterward
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local W = H.set_wml_action_metatable {}
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
|
||||
local function get_tuskers(cfg)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
|
||||
local function get_tusklets(cfg)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local BC = wesnoth.require "ai/lua/battle_calcs.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
local MAIUV = wesnoth.require "ai/micro_ais/micro_ai_unit_variables.lua"
|
||||
local MAISD = wesnoth.require "ai/micro_ais/micro_ai_self_data.lua"
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
local MAIUV = wesnoth.require "ai/micro_ais/micro_ai_unit_variables.lua"
|
||||
local MAISD = wesnoth.require "ai/micro_ais/micro_ai_self_data.lua"
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
|
||||
local ca_healer_initialize = {}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
|
||||
local ca_healer_may_attack = {}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local LS = wesnoth.require "location_set"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local BC = wesnoth.require "ai/lua/battle_calcs.lua"
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
|
||||
local function get_sheep(cfg)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
|
||||
local function get_dog(cfg)
|
||||
local dogs = AH.get_units_with_moves {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
|
||||
local function get_dog(cfg)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local LS = wesnoth.require "location_set"
|
||||
|
||||
return function(cfg)
|
||||
-- Find the area that the sheep can occupy
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
|
||||
local herding_area = wesnoth.require "ai/micro_ais/cas/ca_herding_f_herding_area.lua"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
|
||||
local herding_area = wesnoth.require "ai/micro_ais/cas/ca_herding_f_herding_area.lua"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
|
||||
local function get_next_sheep(cfg)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
|
||||
local function get_next_sheep_enemies(cfg)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local W = H.set_wml_action_metatable {}
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local MAIUV = wesnoth.require "ai/micro_ais/micro_ai_unit_variables.lua"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
|
||||
local function get_lurker(cfg)
|
||||
-- We simply pick the first of the lurkers, they have no strategy
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
|
||||
local messenger_next_waypoint = wesnoth.require "ai/micro_ais/cas/ca_messenger_f_next_waypoint.lua"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
local MAIUV = wesnoth.require "ai/micro_ais/micro_ai_unit_variables.lua"
|
||||
|
||||
local messenger_next_waypoint = wesnoth.require "ai/micro_ais/cas/ca_messenger_f_next_waypoint.lua"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local MAIUV = wesnoth.require "ai/micro_ais/micro_ai_unit_variables.lua"
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
|
||||
local messenger_next_waypoint = wesnoth.require "ai/micro_ais/cas/ca_messenger_f_next_waypoint.lua"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local MAIUV = wesnoth.require "ai/micro_ais/micro_ai_unit_variables.lua"
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local BC = wesnoth.require "ai/lua/battle_calcs.lua"
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
|
||||
local ca_protect_unit_finish, PU_unit, PU_goal = {}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local LS = wesnoth.require "location_set"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local BC = wesnoth.require "ai/lua/battle_calcs.lua"
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require("ai/lua/ai_helper.lua")
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
|
||||
local recruit_type
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
|
||||
local function get_guardian(cfg)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local BC = wesnoth.require "ai/lua/battle_calcs.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
|
||||
local ca_simple_attack, best_attack = {}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
|
||||
local function get_guardian(cfg)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
|
||||
local ca_swarm_move = {}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
|
||||
local function get_enemies(cfg)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local BC = wesnoth.require "ai/lua/battle_calcs.lua"
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local MAIUV = wesnoth.require "ai/micro_ais/micro_ai_unit_variables.lua"
|
||||
local WMPF = wesnoth.require "ai/micro_ais/cas/ca_wolves_multipacks_functions.lua"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local W = H.set_wml_action_metatable {}
|
||||
local MAIUV = wesnoth.require "ai/micro_ais/micro_ai_unit_variables.lua"
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local MAIUV = wesnoth.require "ai/micro_ais/micro_ai_unit_variables.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
local WMPF = wesnoth.require "ai/micro_ais/cas/ca_wolves_multipacks_functions.lua"
|
||||
|
||||
local ca_wolves_multipacks_wander = {}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local BC = wesnoth.require "ai/lua/battle_calcs.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
|
||||
local function get_wolves(cfg)
|
||||
local wolves = AH.get_units_with_moves {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
|
||||
local function get_guardian(cfg)
|
||||
local filter = H.get_child(cfg, "filter") or { id = cfg.id }
|
||||
|
|
|
@ -2,7 +2,7 @@ return {
|
|||
init = function()
|
||||
local priority_target = {}
|
||||
|
||||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local W = H.set_wml_action_metatable {}
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local MAIH = wesnoth.require("ai/micro_ais/micro_ai_helper.lua")
|
||||
|
||||
function wesnoth.micro_ais.big_animals(cfg)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
|
||||
function wesnoth.micro_ais.messenger_escort(cfg)
|
||||
if (cfg.action ~= 'delete') and (not cfg.id) and (not H.get_child(cfg, "filter")) then
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
|
||||
function wesnoth.micro_ais.fast_ai(cfg)
|
||||
local optional_keys = {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
|
||||
function wesnoth.micro_ais.stationed_guardian(cfg)
|
||||
if (cfg.action ~= 'delete') and (not cfg.id) and (not H.get_child(cfg, "filter")) then
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
|
||||
function wesnoth.micro_ais.patrol(cfg)
|
||||
if (cfg.action ~= 'delete') and (not cfg.id) and (not H.get_child(cfg, "filter")) then
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local MAIH = wesnoth.require("ai/micro_ais/micro_ai_helper.lua")
|
||||
|
||||
function wesnoth.micro_ais.protect_unit(cfg)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
|
||||
local function handle_default_recruitment(cfg)
|
||||
-- Also need to delete/add the default recruitment CA
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local T = H.set_wml_tag_metatable {}
|
||||
local AH = wesnoth.require("ai/lua/ai_helper.lua")
|
||||
local MAIUV = wesnoth.require "ai/micro_ais/micro_ai_unit_variables.lua"
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
-- same side).
|
||||
-- For the time being, we only allow key=value style variables.
|
||||
|
||||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
|
||||
local micro_ai_self_data = {}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
-- with different ai_CA values affecting the same unit)
|
||||
-- For the time being, we only allow key=value style variables.
|
||||
|
||||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
|
||||
local micro_ai_unit_variables = {}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local AH = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local BC = wesnoth.require "ai/lua/battle_calcs.lua"
|
||||
--local LS = wesnoth.require "lua/location_set.lua"
|
||||
--local LS = wesnoth.require "location_set"
|
||||
|
||||
local ca_ogres_flee = {}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
-- Used for the bandit villages in S5. Much more specific than the village spawn implementations elsewhere,
|
||||
-- since there are a lot more specific things needed (mostly the boss mechanics and village spreading)
|
||||
|
||||
local helper = wesnoth.require "lua/helper.lua"
|
||||
local helper = wesnoth.require "helper"
|
||||
local wml_actions = wesnoth.wml_actions
|
||||
local _ = wesnoth.textdomain "wesnoth-ei"
|
||||
local T = helper.set_wml_tag_metatable {}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
[generator]
|
||||
id="cavegen"
|
||||
config_name="Lua Cave Generator"
|
||||
create_map = << return wesnoth.require("lua/cave_map_generator.lua").generate_map(...) >>
|
||||
create_map = << return wesnoth.require("cave_map_generator").generate_map(...) >>
|
||||
|
||||
map_width=50
|
||||
map_height=70
|
||||
|
@ -654,7 +654,7 @@
|
|||
# wmllint: markcheck off
|
||||
code= <<
|
||||
local ai_helper = wesnoth.require "ai/lua/ai_helper.lua"
|
||||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local W = H.set_wml_action_metatable {}
|
||||
local delf = wesnoth.get_units { id = 'Delfador' }[1]
|
||||
local sceptre_loc= wesnoth.special_locations.sceptre
|
||||
|
|
|
@ -4,7 +4,7 @@ local labels = {}
|
|||
local wml_label = wesnoth.wml_actions.label
|
||||
local replace_map = wesnoth.wml_actions.replace_map
|
||||
|
||||
local helper = wesnoth.require "lua/helper.lua"
|
||||
local helper = wesnoth.require "helper"
|
||||
local wml_actions = wesnoth.wml_actions
|
||||
local T = helper.set_wml_tag_metatable {}
|
||||
local V = helper.set_wml_var_metatable {}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local helper = wesnoth.require "lua/helper.lua"
|
||||
local helper = wesnoth.require "helper"
|
||||
local T = helper.set_wml_tag_metatable {}
|
||||
|
||||
function wesnoth.wml_actions.find_respawn_point(cfg)
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
[generator]
|
||||
id="cavegen"
|
||||
config_name="Lua Cave Generator"
|
||||
create_map = << return wesnoth.require("lua/cave_map_generator.lua").generate_map(...) >>
|
||||
create_map = << return wesnoth.require("cave_map_generator").generate_map(...) >>
|
||||
|
||||
map_width=45
|
||||
map_height=45
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local LS = wesnoth.require "location_set"
|
||||
|
||||
local ca_transport = {}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
-- Used for the bandit spawns in scenario 5
|
||||
|
||||
local helper = wesnoth.require "lua/helper.lua"
|
||||
local utils = wesnoth.require "lua/wml-utils.lua"
|
||||
local helper = wesnoth.require "helper"
|
||||
local utils = wesnoth.require "wml-utils"
|
||||
local wml_actions = wesnoth.wml_actions
|
||||
local T = helper.set_wml_tag_metatable {}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
-- Allows the player to choose whether they want to play Konrad or Li’sar
|
||||
-- for the tutorial
|
||||
|
||||
local helper = wesnoth.require "lua/helper.lua"
|
||||
local helper = wesnoth.require "helper"
|
||||
local T = helper.set_wml_tag_metatable {}
|
||||
local wml_actions = wesnoth.wml_actions
|
||||
local _ = wesnoth.textdomain "wesnoth-tutorial"
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
wesnoth.dofile 'lua/backwards-compatibility.lua'
|
||||
wesnoth.dofile 'lua/wml-tags.lua'
|
||||
wesnoth.dofile 'lua/feeding.lua'
|
||||
wesnoth.dofile 'ai/micro_ais/micro_ai_wml_tag.lua'
|
||||
>>
|
||||
[/lua]
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
-- This file may provide an implementation of Lua functions removed from the engine.
|
||||
|
||||
local helper = wesnoth.require "lua/helper.lua"
|
||||
local helper = wesnoth.require "helper"
|
||||
|
||||
function wesnoth.set_music(cfg)
|
||||
wesnoth.wml_actions.music(cfg)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
local helper = wesnoth.require "lua/helper.lua"
|
||||
local MG = wesnoth.require "lua/mapgen_helper.lua"
|
||||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local helper = wesnoth.require "helper"
|
||||
local MG = wesnoth.require "mapgen_helper"
|
||||
local LS = wesnoth.require "location_set"
|
||||
local T = helper.set_wml_tag_metatable {}
|
||||
local random = wesnoth.random
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
local helper = wesnoth.require("lua/helper.lua")
|
||||
local helper = wesnoth.require("helper")
|
||||
local _ = wesnoth.textdomain 'wesnoth-help'
|
||||
local T = helper.set_wml_tag_metatable {}
|
||||
local on_event = wesnoth.require("lua/on_event.lua")
|
||||
local on_event = wesnoth.require("on_event")
|
||||
|
||||
-- The feeding event code
|
||||
on_event("die", function()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local LS = wesnoth.require "lua/location_set.lua"
|
||||
local LS = wesnoth.require "location_set"
|
||||
|
||||
local mapgen_helper, map_mt = {}, {__index = {}}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local utils = wesnoth.require "lua/wml-utils.lua"
|
||||
local utils = wesnoth.require "wml-utils"
|
||||
-- registers an event handler. note that, like all lua variables this is not persitent in savefiles,
|
||||
-- so you have to call this function from a toplevel lua tag or from a preload event.
|
||||
-- It is also not possible to use this for first_time_only=yes events.
|
||||
|
|
51
data/lua/package.lua
Normal file
51
data/lua/package.lua
Normal file
|
@ -0,0 +1,51 @@
|
|||
|
||||
local empty_pkg = {}
|
||||
|
||||
local function resolve_package(pkg_name)
|
||||
if pkg_name[#pkg_name] == '/' then
|
||||
pkg_name = pkg_name:sub(1, -2)
|
||||
end
|
||||
if wesnoth.have_file(pkg_name) then return pkg_name end
|
||||
if pkg_name:sub(-4) ~= ".lua" then
|
||||
if wesnoth.have_file(pkg_name .. ".lua") then
|
||||
return pkg_name .. ".lua"
|
||||
end
|
||||
if pkg_name:sub(1, 4) ~= "lua/" then
|
||||
if wesnoth.have_file("lua/" .. pkg_name .. ".lua") then
|
||||
return "lua/" .. pkg_name .. ".lua"
|
||||
end
|
||||
end
|
||||
end
|
||||
if pkg_name:sub(1, 4) ~= "lua/" then
|
||||
if wesnoth.have_file("lua/" .. pkg_name) then
|
||||
return "lua/" .. pkg_name
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function wesnoth.require(pkg_name)
|
||||
-- First, check if the package is already loaded
|
||||
local loaded_name = resolve_package(pkg_name)
|
||||
if loaded_name and wesnoth.package[loaded_name] then
|
||||
return wesnoth.package[loaded_name]
|
||||
end
|
||||
|
||||
-- Next, if it's a single file, load the package with dofile
|
||||
if wesnoth.have_file(loaded_name, true) then
|
||||
local pkg = wesnoth.dofile(loaded_name)
|
||||
wesnoth.package[loaded_name] = pkg or empty_pkg
|
||||
return pkg
|
||||
else -- If it's a directory, load all the files therein
|
||||
local files = wesnoth.read_file(loaded_name)
|
||||
local pkg = {}
|
||||
for i = files.ndirs + 1, #files do
|
||||
if files[i]:sub(-4) == ".lua" then
|
||||
local subpkg_name = files[i]:sub(1, -5)
|
||||
pkg[subpkg_name] = wesnoth.require(loaded_name .. '/' .. files[i])
|
||||
end
|
||||
end
|
||||
wesnoth.package[loaded_name] = pkg
|
||||
return pkg
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
local helper = wesnoth.require "lua/helper.lua"
|
||||
local utils = wesnoth.require "lua/wml-utils.lua"
|
||||
local helper = wesnoth.require "helper"
|
||||
local utils = wesnoth.require "wml-utils"
|
||||
local wml_actions = wesnoth.wml_actions
|
||||
|
||||
function wml_actions.command(cfg)
|
||||
|
|
|
@ -11,21 +11,15 @@ function wesnoth.game_events.on_save()
|
|||
return {}
|
||||
end
|
||||
|
||||
wesnoth.require "lua/wml-flow.lua"
|
||||
wesnoth.require "lua/wml/objectives.lua"
|
||||
wesnoth.require "lua/wml/animate_unit.lua"
|
||||
wesnoth.require "lua/wml/items.lua"
|
||||
wesnoth.require "lua/wml/message.lua"
|
||||
wesnoth.require "lua/wml/object.lua"
|
||||
wesnoth.require "lua/wml/modify_unit.lua"
|
||||
wesnoth.require "lua/wml/harm_unit.lua"
|
||||
wesnoth.require "lua/wml/find_path.lua"
|
||||
wesnoth.require "lua/wml/endlevel.lua"
|
||||
wesnoth.require "lua/wml/random_placement.lua"
|
||||
wesnoth.require "wml-flow"
|
||||
wesnoth.require "wml"
|
||||
-- Note: When adding new WML tags, unless they're very simple, it's preferred to
|
||||
-- add a new file in the "data/lua/wml" directory. The file will then automatically
|
||||
-- be loaded by the above require statement.
|
||||
|
||||
local helper = wesnoth.require "lua/helper.lua"
|
||||
local location_set = wesnoth.require "lua/location_set.lua"
|
||||
local utils = wesnoth.require "lua/wml-utils.lua"
|
||||
local helper = wesnoth.require "helper"
|
||||
local location_set = wesnoth.require "location_set"
|
||||
local utils = wesnoth.require "wml-utils"
|
||||
local wml_actions = wesnoth.wml_actions
|
||||
local T = helper.set_wml_tag_metatable {}
|
||||
|
||||
|
@ -297,58 +291,6 @@ function wml_actions.volume(cfg)
|
|||
end
|
||||
end
|
||||
|
||||
-- This is mainly for use in unit test macros, but maybe it can be useful elsewhere too
|
||||
function wml_actions.test_condition(cfg)
|
||||
local logger = cfg.logger or "warning"
|
||||
|
||||
-- This function returns true if it managed to explain the failure
|
||||
local function explain(current_cfg, expect)
|
||||
for i,t in ipairs(current_cfg) do
|
||||
local tag, this_cfg = t[1], t[2]
|
||||
-- Some special cases
|
||||
if tag == "or" or tag == "and" then
|
||||
if explain(this_cfg, expect) then
|
||||
return true
|
||||
end
|
||||
elseif tag == "not" then
|
||||
if explain(this_cfg, not expect) then
|
||||
return true
|
||||
end
|
||||
elseif tag == "true" or tag == "false" then
|
||||
-- We don't explain these ones.
|
||||
return true
|
||||
elseif wesnoth.eval_conditional{t} == expect then
|
||||
local explanation = "The following conditional test %s:"
|
||||
if expect then
|
||||
explanation = explanation:format("passed")
|
||||
else
|
||||
explanation = explanation:format("failed")
|
||||
end
|
||||
explanation = string.format("%s\n\t[%s]", explanation, tag)
|
||||
for k,v in pairs(this_cfg) do
|
||||
if type(k) ~= "number" then
|
||||
local format = "%s\n\t\t%s=%s"
|
||||
local literal = tostring(helper.literal(this_cfg)[k])
|
||||
if literal ~= v then
|
||||
format = format .. "=%s"
|
||||
end
|
||||
explanation = string.format(format, explanation, k, literal, tostring(v))
|
||||
end
|
||||
end
|
||||
explanation = string.format("%s\n\t[/%s]", explanation, tag)
|
||||
if tag == "variable" then
|
||||
explanation = string.format("%s\n\tNote: The variable %s currently has the value %q.", explanation, this_cfg.name, tostring(wesnoth.get_variable(this_cfg.name)))
|
||||
end
|
||||
wesnoth.log(logger, explanation, true)
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Use not twice here to convert nil to false
|
||||
explain(cfg, not not cfg.result)
|
||||
end
|
||||
|
||||
function wml_actions.scroll_to(cfg)
|
||||
local loc = wesnoth.get_locations( cfg )[1]
|
||||
if not loc then return end
|
||||
|
@ -529,69 +471,6 @@ function wml_actions.unhide_unit(cfg)
|
|||
wml_actions.redraw {}
|
||||
end
|
||||
|
||||
function wml_actions.move_unit(cfg)
|
||||
local coordinate_error = "invalid coordinate in [move_unit]"
|
||||
local to_x = tostring(cfg.to_x or helper.wml_error(coordinate_error))
|
||||
local to_y = tostring(cfg.to_y or helper.wml_error(coordinate_error))
|
||||
local fire_event = cfg.fire_event
|
||||
local muf_force_scroll = cfg.force_scroll
|
||||
local check_passability = cfg.check_passability
|
||||
if check_passability == nil then check_passability = true end
|
||||
cfg = helper.literal(cfg)
|
||||
cfg.to_x, cfg.to_y, cfg.fire_event = nil, nil, nil
|
||||
local units = wesnoth.get_units(cfg)
|
||||
|
||||
local pattern = "[^%s,]+"
|
||||
for current_unit_index, current_unit in ipairs(units) do
|
||||
if not fire_event or current_unit.valid then
|
||||
local xs, ys = string.gmatch(to_x, pattern), string.gmatch(to_y, pattern)
|
||||
local move_string_x = current_unit.x
|
||||
local move_string_y = current_unit.y
|
||||
local pass_check = nil
|
||||
if check_passability then pass_check = current_unit end
|
||||
|
||||
local x, y = xs(), ys()
|
||||
local prevX, prevY = tonumber(current_unit.x), tonumber(current_unit.y)
|
||||
while true do
|
||||
x = tonumber(x) or helper.wml_error(coordinate_error)
|
||||
y = tonumber(y) or helper.wml_error(coordinate_error)
|
||||
if not (x == prevX and y == prevY) then x, y = wesnoth.find_vacant_tile(x, y, pass_check) end
|
||||
if not x or not y then helper.wml_error("Could not find a suitable hex near to one of the target hexes in [move_unit].") end
|
||||
move_string_x = string.format("%s,%u", move_string_x, x)
|
||||
move_string_y = string.format("%s,%u", move_string_y, y)
|
||||
local next_x, next_y = xs(), ys()
|
||||
if not next_x and not next_y then break end
|
||||
prevX, prevY = x, y
|
||||
x, y = next_x, next_y
|
||||
end
|
||||
|
||||
if current_unit.x < x then current_unit.facing = "se"
|
||||
elseif current_unit.x > x then current_unit.facing = "sw"
|
||||
end
|
||||
|
||||
wesnoth.extract_unit(current_unit)
|
||||
local current_unit_cfg = current_unit.__cfg
|
||||
wml_actions.move_unit_fake {
|
||||
type = current_unit_cfg.type,
|
||||
gender = current_unit_cfg.gender,
|
||||
variation = current_unit_cfg.variation,
|
||||
image_mods = current_unit.image_mods,
|
||||
side = current_unit_cfg.side,
|
||||
x = move_string_x,
|
||||
y = move_string_y,
|
||||
force_scroll = muf_force_scroll
|
||||
}
|
||||
local x2, y2 = current_unit.x, current_unit.y
|
||||
current_unit.x, current_unit.y = x, y
|
||||
wesnoth.put_unit(current_unit)
|
||||
|
||||
if fire_event then
|
||||
wesnoth.fire_event("moveto", x, y, x2, y2)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function wml_actions.capture_village(cfg)
|
||||
local side = cfg.side
|
||||
local filter_side = helper.get_child(cfg, "filter_side")
|
||||
|
@ -660,74 +539,6 @@ function wml_actions.unpetrify(cfg)
|
|||
end
|
||||
end
|
||||
|
||||
function wml_actions.heal_unit(cfg)
|
||||
local healers = helper.get_child(cfg, "filter_second")
|
||||
if healers then
|
||||
healers = wesnoth.get_units{
|
||||
ability_type = "heals",
|
||||
T["and"](healers)
|
||||
}
|
||||
else
|
||||
healers = {}
|
||||
end
|
||||
|
||||
local who = helper.get_child(cfg, "filter")
|
||||
if who then
|
||||
who = wesnoth.get_units(who)
|
||||
else
|
||||
who = wesnoth.get_units{
|
||||
x = wesnoth.current.event_context.x1,
|
||||
y = wesnoth.current.event_context.y1
|
||||
}
|
||||
end
|
||||
|
||||
local heal_full = cfg.amount == "full" or cfg.amount == nil
|
||||
local moves_full = cfg.moves == "full"
|
||||
local heal_amount_set = false
|
||||
for i,u in ipairs(who) do
|
||||
local heal_amount = u.max_hitpoints - u.hitpoints
|
||||
if heal_full then
|
||||
u.hitpoints = u.max_hitpoints
|
||||
else
|
||||
heal_amount = tonumber(cfg.amount) or heal_amount
|
||||
local new_hitpoints = math.max(1, math.min(u.max_hitpoints, u.hitpoints + heal_amount))
|
||||
heal_amount = new_hitpoints - u.hitpoints
|
||||
u.hitpoints = new_hitpoints
|
||||
end
|
||||
|
||||
if moves_full then
|
||||
u.moves = u.max_moves
|
||||
else
|
||||
u.moves = math.min(u.max_moves, u.moves + (cfg.moves or 0))
|
||||
end
|
||||
|
||||
if cfg.restore_attacks then
|
||||
u.attacks_left = u.max_attacks
|
||||
end
|
||||
|
||||
if cfg.restore_statuses == true or cfg.restore_statuses == nil then
|
||||
u.status.poisoned = false
|
||||
u.status.petrified = false
|
||||
u.status.slowed = false
|
||||
u.status.unhealable = false
|
||||
end
|
||||
|
||||
if not heal_amount_set then
|
||||
heal_amount_set = true
|
||||
wesnoth.set_variable("heal_amount", heal_amount)
|
||||
end
|
||||
|
||||
if cfg.animate then
|
||||
local animator = wesnoth.create_animator()
|
||||
animator:add(u, 'healed', 'hits', {value = heal_amount})
|
||||
if #healers > 0 then
|
||||
animator:add(healers[1], 'healing', 'hits', {value = heal_amount})
|
||||
end
|
||||
animator:run()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function wml_actions.transform_unit(cfg)
|
||||
local transform_to = cfg.transform_to
|
||||
|
||||
|
@ -773,39 +584,6 @@ function wml_actions.store_side(cfg)
|
|||
end
|
||||
end
|
||||
|
||||
function wml_actions.modify_ai(cfg)
|
||||
local sides = utils.get_sides(cfg)
|
||||
local component, final
|
||||
if cfg.action == "add" or cfg.action == "change" then
|
||||
local start = string.find(cfg.path, "[a-z_]+%[[a-z0-9_*]*%]$")
|
||||
final = start and (string.find(cfg.path, '[', start, true) - 1) or -1
|
||||
start = start or string.find(cfg.path, "[^.]*$") or 1
|
||||
local comp_type = string.sub(cfg.path, start, final)
|
||||
component = helper.get_child(cfg, comp_type)
|
||||
if component == nil then
|
||||
helper.wml_error("Missing component definition in [modify_ai]")
|
||||
end
|
||||
component = helper.parsed(component)
|
||||
end
|
||||
for i = 1, #sides do
|
||||
if cfg.action == "add" then
|
||||
wesnoth.add_ai_component(sides[i].side, cfg.path, component)
|
||||
elseif cfg.action == "delete" or cfg.action == "try_delete" then
|
||||
wesnoth.delete_ai_component(sides[i].side, cfg.path)
|
||||
elseif cfg.action == "change" then
|
||||
local id_start = final + 2
|
||||
local id_final = string.len(cfg.path) - 1
|
||||
local id = string.sub(cfg.path, id_start, id_final)
|
||||
if id == "*" then
|
||||
helper.wml_error("[modify_ai] can only change one component at a time")
|
||||
elseif not component.id and not id:match("[0-9]+") then
|
||||
component.id = id
|
||||
end
|
||||
wesnoth.change_ai_component(sides[i].side, cfg.path, component)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function wml_actions.add_ai_behavior(cfg)
|
||||
local unit = wesnoth.get_units(helper.get_child(cfg, "filter"))[1] or
|
||||
helper.wml_error("[add_ai_behavior]: no unit specified")
|
||||
|
@ -987,75 +765,6 @@ function wml_actions.inspect(cfg)
|
|||
wesnoth.gamestate_inspector(cfg)
|
||||
end
|
||||
|
||||
local kill_recursion_preventer = wesnoth.require("lua/location_set.lua").create()
|
||||
function wml_actions.kill(cfg)
|
||||
local number_killed = 0
|
||||
local secondary_unit = helper.get_child(cfg, "secondary_unit")
|
||||
local killer_loc = {0, 0}
|
||||
if secondary_unit then
|
||||
secondary_unit = wesnoth.get_units(secondary_unit)[1]
|
||||
if cfg.fire_event then
|
||||
if secondary_unit then
|
||||
killer_loc = {secondary_unit.loc}
|
||||
else
|
||||
wesnoth.log("warn", "failed to match [secondary_unit] in [kill] with a single on-board unit")
|
||||
end
|
||||
end
|
||||
end
|
||||
local dead_men_walking = wesnoth.get_units(cfg)
|
||||
for i,unit in ipairs(dead_men_walking) do
|
||||
local death_loc = {x = tonumber(unit.x) or 0, y = tonumber(unit.y) or 0}
|
||||
if not secondary_unit then killer_loc = death_loc end
|
||||
local can_fire = false
|
||||
|
||||
local recursion = (kill_recursion_preventer:get(death_loc.x, death_loc.y) or 0) + 1
|
||||
if cfg.fire_event then
|
||||
kill_recursion_preventer:insert(death_loc.x, death_loc.y, recursion)
|
||||
can_fire = true
|
||||
if death_loc.x == wesnoth.current.event.x1 and death_loc.y == wesnoth.current.event.y1 then
|
||||
if wesnoth.current.event.name == "die" or wesnoth.current.event.name == "last breath" then
|
||||
if recursion >= 10 then
|
||||
can_fire = false;
|
||||
wesnoth.log("error", "tried to fire 'die' or 'last breath' event on unit from the unit's 'die' or 'last breath' event with first_time_only=no!")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if can_fire then
|
||||
wesnoth.fire_event("last breath", death_loc, killer_loc)
|
||||
end
|
||||
if cfg.animate then
|
||||
wesnoth.scroll_to_tile(death_loc)
|
||||
local anim = wesnoth.create_animator()
|
||||
-- Possible TODO: Add weapon selection? (That's kinda a pain right now; see animate_unit defn)
|
||||
anim:add(unit, "death", "kill")
|
||||
if secondary_unit then
|
||||
anim:add(secondary_unit, "victory", "kill")
|
||||
end
|
||||
anim:run()
|
||||
end
|
||||
wml_actions.redraw{}
|
||||
|
||||
if can_fire then
|
||||
wesnoth.fire_event("die", death_loc, killer_loc)
|
||||
end
|
||||
if cfg.fire_event then
|
||||
if recursion <= 1 then
|
||||
kill_recursion_preventer:remove(death_loc.x, death_loc.y)
|
||||
else
|
||||
kill_recursion_preventer:insert(death_loc.x, death_loc.y, recursion)
|
||||
end
|
||||
end
|
||||
-- Test that it's valid (and still on the map) first, in case the event erased (or extracted) it.
|
||||
if unit.valid == "map" then unit:erase() end
|
||||
|
||||
number_killed = number_killed + 1
|
||||
end
|
||||
|
||||
-- TODO: Do I need to check recall lists or was that covered by the above loop?
|
||||
return number_killed
|
||||
end
|
||||
|
||||
function wml_actions.label( cfg )
|
||||
local new_cfg = helper.parsed( cfg )
|
||||
for index, location in ipairs( wesnoth.get_locations( cfg ) ) do
|
||||
|
@ -1064,111 +773,6 @@ function wml_actions.label( cfg )
|
|||
end
|
||||
end
|
||||
|
||||
local side_changes_needing_redraw = {
|
||||
'shroud', 'fog', 'reset_map', 'reset_view', 'shroud_data',
|
||||
'share_vision', 'share_maps', 'share_view',
|
||||
'color', 'flag',
|
||||
}
|
||||
function wml_actions.modify_side(cfg)
|
||||
local sides = utils.get_sides(cfg)
|
||||
for i,side in ipairs(sides) do
|
||||
if cfg.team_name then
|
||||
side.team_name = cfg.team_name
|
||||
end
|
||||
if cfg.user_team_name then
|
||||
side.user_team_name = cfg.user_team_name
|
||||
end
|
||||
if cfg.controller then
|
||||
side.controller = cfg.controller
|
||||
end
|
||||
if cfg.defeat_condition then
|
||||
side.defeat_condition = cfg.defeat_condition
|
||||
end
|
||||
if cfg.recruit then
|
||||
local recruits = {}
|
||||
for recruit in utils.split(cfg.recruit) do
|
||||
table.insert(recruits, recruit)
|
||||
end
|
||||
side.recruit = recruits
|
||||
end
|
||||
if cfg.village_support then
|
||||
side.village_support = cfg.village_support
|
||||
end
|
||||
if cfg.village_gold then
|
||||
side.village_gold = cfg.village_gold
|
||||
end
|
||||
if cfg.income then
|
||||
side.base_income = cfg.income
|
||||
end
|
||||
if cfg.gold then
|
||||
side.gold = cfg.gold
|
||||
end
|
||||
|
||||
if cfg.hidden ~= nil then
|
||||
side.hidden = cfg.hidden
|
||||
end
|
||||
if cfg.color or cfg.flag then
|
||||
wesnoth.set_side_id(side.side, cfg.flag, cfg.color)
|
||||
end
|
||||
if cfg.flag_icon then
|
||||
side.flag_icon = cfg.flag_icon
|
||||
end
|
||||
if cfg.suppress_end_turn_confirmation ~= nil then
|
||||
side.suppress_end_turn_confirmation = cfg.suppress_end_turn_confirmation
|
||||
end
|
||||
if cfg.scroll_to_leader ~= nil then
|
||||
side.scroll_to_leader = cfg.scroll_to_leader
|
||||
end
|
||||
|
||||
if cfg.shroud ~= nil then
|
||||
side.shroud = cfg.shroud
|
||||
end
|
||||
if cfg.reset_maps then
|
||||
wesnoth.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)
|
||||
end
|
||||
if cfg.shroud_data then
|
||||
wesnoth.remove_shroud(side.side, cfg.shroud_data)
|
||||
end
|
||||
|
||||
if cfg.share_vision then
|
||||
side.share_vision = cfg.share_vision
|
||||
end
|
||||
-- Legacy support
|
||||
if cfg.share_view ~= nil or cfg.share_maps ~= nil then
|
||||
if cfg.share_view then
|
||||
side.share_vision = 'all'
|
||||
elseif cfg.share_maps then
|
||||
side.share_vision = 'shroud'
|
||||
else
|
||||
side.share_vision = 'none'
|
||||
end
|
||||
end
|
||||
|
||||
if cfg.switch_ai then
|
||||
wesnoth.switch_ai(side.side, cfg.switch_ai)
|
||||
end
|
||||
local ai = {}
|
||||
for next_ai in helper.child_range(cfg, "ai") do
|
||||
table.insert(ai, T.ai(next_ai))
|
||||
end
|
||||
if #ai > 0 then
|
||||
wesnoth.append_ai(side.side, ai)
|
||||
end
|
||||
end
|
||||
for i,key in ipairs(side_changes_needing_redraw) do
|
||||
if cfg[key] ~= nil then
|
||||
wml_actions.redraw{}
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function wml_actions.open_help(cfg)
|
||||
wesnoth.open_help(cfg.topic)
|
||||
end
|
||||
|
@ -1188,115 +792,6 @@ function wml_actions.print(cfg)
|
|||
wesnoth.print(cfg)
|
||||
end
|
||||
|
||||
function wml_actions.role(cfg)
|
||||
-- role= and type= are handled differently than in other tags,
|
||||
-- so we need to remove them from the filter
|
||||
local role = cfg.role
|
||||
local filter = helper.shallow_literal(cfg)
|
||||
|
||||
if role == nil then
|
||||
helper.wml_error("missing role= in [role]")
|
||||
end
|
||||
|
||||
local types = {}
|
||||
|
||||
if cfg.type then
|
||||
for value in utils.split(cfg.type) do
|
||||
table.insert(types, utils.trim(value))
|
||||
end
|
||||
end
|
||||
|
||||
filter.role, filter.type = nil, nil
|
||||
local search_map, search_recall, reassign = true, true, true
|
||||
if cfg.search_recall_list == "only" then
|
||||
search_map = false
|
||||
elseif cfg.search_recall_list ~= nil then
|
||||
search_recall = not not cfg.search_recall_list
|
||||
end
|
||||
if cfg.reassign ~= nil then
|
||||
reassign = not not cfg.reassign
|
||||
end
|
||||
|
||||
-- pre-build a new [recall] from the [auto_recall]
|
||||
-- copy only recall-specific attributes, no SUF at all
|
||||
-- the SUF will be id= which we will add in a moment
|
||||
-- keep this in sync with the C++ recall function!!!
|
||||
local recall = nil
|
||||
local child = helper.get_child(cfg, "auto_recall")
|
||||
if child ~= nil then
|
||||
if helper.get_nth_child(cfg, "auto_recall", 2) ~= nil then
|
||||
wesnoth.log("debug", "More than one [auto_recall] found within [role]", true)
|
||||
end
|
||||
local original = helper.shallow_literal(child)
|
||||
recall = {}
|
||||
recall.x = original.x
|
||||
recall.y = original.y
|
||||
recall.show = original.show
|
||||
recall.fire_event = original.fire_event
|
||||
recall.check_passability = original.check_passability
|
||||
end
|
||||
|
||||
if not reassign then
|
||||
if search_map then
|
||||
local unit = wesnoth.get_units{role=role}[1]
|
||||
if unit then
|
||||
return
|
||||
end
|
||||
end
|
||||
if recall and search_recall then
|
||||
local unit = wesnoth.get_recall_units{role=role}[1]
|
||||
if unit then
|
||||
recall.id = unit.id
|
||||
wml_actions.recall(recall)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if search_map then
|
||||
-- first attempt to match units on the map
|
||||
local i = 1
|
||||
repeat
|
||||
-- give precedence based on the order specified in type=
|
||||
if #types > 0 then
|
||||
filter.type = types[i]
|
||||
end
|
||||
local unit = wesnoth.get_units(filter)[1]
|
||||
if unit then
|
||||
unit.role = role
|
||||
return
|
||||
end
|
||||
i = i + 1
|
||||
until #types == 0 or i > #types
|
||||
end
|
||||
|
||||
if search_recall then
|
||||
-- then try to match units on the recall lists
|
||||
i = 1
|
||||
repeat
|
||||
if #types > 0 then
|
||||
filter.type = types[i]
|
||||
end
|
||||
local unit = wesnoth.get_recall_units(filter)[1]
|
||||
if unit then
|
||||
unit.role = role
|
||||
if recall then
|
||||
recall.id = unit.id
|
||||
wml_actions.recall(recall)
|
||||
end
|
||||
return
|
||||
end
|
||||
i = i + 1
|
||||
until #types == 0 or i > #types
|
||||
end
|
||||
|
||||
-- no matching unit found, try the [else] tags
|
||||
for else_child in helper.child_range(cfg, "else") do
|
||||
local action = utils.handle_event_commands(else_child, "conditional")
|
||||
if action ~= "none" then return end
|
||||
end
|
||||
end
|
||||
|
||||
function wml_actions.unsynced(cfg)
|
||||
wesnoth.unsynced(function ()
|
||||
wml_actions.command(cfg)
|
||||
|
@ -1398,123 +893,6 @@ function wml_actions.reset_fog(cfg)
|
|||
end
|
||||
end
|
||||
|
||||
function wml_actions.set_variable(cfg)
|
||||
local name = cfg.name or helper.wml_error "trying to set a variable with an empty name"
|
||||
|
||||
if cfg.value ~= nil then -- check for nil because user may try to set a variable as false
|
||||
wesnoth.set_variable(name, cfg.value)
|
||||
end
|
||||
|
||||
if cfg.literal ~= nil then
|
||||
wesnoth.set_variable(name, helper.shallow_literal(cfg).literal)
|
||||
end
|
||||
|
||||
if cfg.to_variable then
|
||||
wesnoth.set_variable(name, wesnoth.get_variable(cfg.to_variable))
|
||||
end
|
||||
|
||||
if cfg.add then
|
||||
wesnoth.set_variable(name, (tonumber(wesnoth.get_variable(name)) or 0) + (tonumber(cfg.add) or 0))
|
||||
end
|
||||
|
||||
if cfg.sub then
|
||||
wesnoth.set_variable(name, (tonumber(wesnoth.get_variable(name)) or 0) - (tonumber(cfg.sub) or 0))
|
||||
end
|
||||
|
||||
if cfg.multiply then
|
||||
wesnoth.set_variable(name, (tonumber(wesnoth.get_variable(name)) or 0) * (tonumber(cfg.multiply) or 0))
|
||||
end
|
||||
|
||||
if cfg.divide then
|
||||
local divide = tonumber(cfg.divide) or 0
|
||||
if divide == 0 then helper.wml_error("division by zero on variable " .. name) end
|
||||
wesnoth.set_variable(name, (tonumber(wesnoth.get_variable(name)) or 0) / divide)
|
||||
end
|
||||
|
||||
if cfg.modulo then
|
||||
local modulo = tonumber(cfg.modulo) or 0
|
||||
if modulo == 0 then helper.wml_error("division by zero on variable " .. name) end
|
||||
wesnoth.set_variable(name, (tonumber(wesnoth.get_variable(name)) or 0) % modulo)
|
||||
end
|
||||
|
||||
if cfg.abs then
|
||||
wesnoth.set_variable(name, math.abs(tonumber(wesnoth.get_variable(name)) or 0))
|
||||
end
|
||||
|
||||
if cfg.root then
|
||||
if cfg.root == "square" then
|
||||
local radicand = tonumber(wesnoth.get_variable(name)) or 0
|
||||
if radicand < 0 then helper.wml_error("square root of negative number on variable " .. name) end
|
||||
wesnoth.set_variable(name, math.sqrt(radicand))
|
||||
end
|
||||
end
|
||||
|
||||
if cfg.power then
|
||||
wesnoth.set_variable(name, (tonumber(wesnoth.get_variable(name)) or 0) ^ (tonumber(cfg.power) or 0))
|
||||
end
|
||||
|
||||
if cfg.round then
|
||||
local var = tonumber(wesnoth.get_variable(name) or 0)
|
||||
local round_val = cfg.round
|
||||
if round_val == "ceil" then
|
||||
wesnoth.set_variable(name, math.ceil(var))
|
||||
elseif round_val == "floor" then
|
||||
wesnoth.set_variable(name, math.floor(var))
|
||||
else
|
||||
local decimals, discarded = math.modf(tonumber(round_val) or 0)
|
||||
local value = var * (10 ^ decimals)
|
||||
value = helper.round(value)
|
||||
value = value * (10 ^ -decimals)
|
||||
wesnoth.set_variable(name, value)
|
||||
end
|
||||
end
|
||||
|
||||
-- unlike the other math operations, ipart and fpart do not act on
|
||||
-- the value already contained in the variable
|
||||
-- but on the value assigned to the respective key
|
||||
if cfg.ipart then
|
||||
local ivalue, fvalue = math.modf(tonumber(cfg.ipart) or 0)
|
||||
wesnoth.set_variable(name, ivalue)
|
||||
end
|
||||
|
||||
if cfg.fpart then
|
||||
local ivalue, fvalue = math.modf(tonumber(cfg.fpart) or 0)
|
||||
wesnoth.set_variable(name, fvalue)
|
||||
end
|
||||
|
||||
if cfg.string_length ~= nil then
|
||||
wesnoth.set_variable(name, string.len(tostring(cfg.string_length)))
|
||||
end
|
||||
|
||||
if cfg.time then
|
||||
if cfg.time == "stamp" then
|
||||
wesnoth.set_variable(name, wesnoth.get_time_stamp())
|
||||
end
|
||||
end
|
||||
|
||||
if cfg.rand then
|
||||
wesnoth.set_variable(name, helper.rand(tostring(cfg.rand)))
|
||||
end
|
||||
|
||||
local join_child = helper.get_child(cfg, "join")
|
||||
if join_child then
|
||||
local array_name = join_child.variable or helper.wml_error "missing variable= attribute in [join]"
|
||||
local separator = join_child.separator
|
||||
local key_name = join_child.key or "value"
|
||||
local remove_empty = join_child.remove_empty
|
||||
|
||||
local string_to_join = {}
|
||||
|
||||
for i, element in ipairs(helper.get_variable_array(array_name)) do
|
||||
if element[key_name] ~= nil or (not remove_empty) then
|
||||
table.insert(string_to_join, tostring(element[key_name]))
|
||||
end
|
||||
end
|
||||
|
||||
wesnoth.set_variable(name, table.concat(string_to_join, separator))
|
||||
end
|
||||
end
|
||||
|
||||
function wesnoth.wml_actions.change_theme(cfg)
|
||||
wesnoth.game_config.theme = cfg.theme
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
local helper = wesnoth.require "lua/helper.lua"
|
||||
local helper = wesnoth.require "helper"
|
||||
local utils = {vwriter = {}}
|
||||
|
||||
function utils.trim(s)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local helper = wesnoth.require "lua/helper.lua"
|
||||
local helper = wesnoth.require "helper"
|
||||
local T = helper.set_wml_tag_metatable{}
|
||||
|
||||
local function get_fake_attack(unit, cfg)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local helper = wesnoth.require "lua/helper.lua"
|
||||
local helper = wesnoth.require "helper"
|
||||
local already_ended = false
|
||||
|
||||
function wesnoth.wml_actions.endlevel(cfg)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
local helper = wesnoth.require "lua/helper.lua"
|
||||
local utils = wesnoth.require "lua/wml-utils.lua"
|
||||
local helper = wesnoth.require "helper"
|
||||
local utils = wesnoth.require "wml-utils"
|
||||
|
||||
function wesnoth.wml_actions.find_path(cfg)
|
||||
local filter_unit = helper.get_child(cfg, "traveler") or helper.wml_error("[find_path] missing required [traveler] tag")
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
local helper = wesnoth.require "lua/helper.lua"
|
||||
local utils = wesnoth.require "lua/wml-utils.lua"
|
||||
local helper = wesnoth.require "helper"
|
||||
local utils = wesnoth.require "wml-utils"
|
||||
local wml_actions = wesnoth.wml_actions
|
||||
local T = helper.set_wml_tag_metatable {}
|
||||
|
||||
|
|
70
data/lua/wml/heal_unit.lua
Normal file
70
data/lua/wml/heal_unit.lua
Normal file
|
@ -0,0 +1,70 @@
|
|||
local helper = wesnoth.require "helper"
|
||||
local T = helper.set_wml_tag_metatable {}
|
||||
|
||||
function wesnoth.wml_actions.heal_unit(cfg)
|
||||
local healers = helper.get_child(cfg, "filter_second")
|
||||
if healers then
|
||||
healers = wesnoth.get_units{
|
||||
ability_type = "heals",
|
||||
T["and"](healers)
|
||||
}
|
||||
else
|
||||
healers = {}
|
||||
end
|
||||
|
||||
local who = helper.get_child(cfg, "filter")
|
||||
if who then
|
||||
who = wesnoth.get_units(who)
|
||||
else
|
||||
who = wesnoth.get_units{
|
||||
x = wesnoth.current.event_context.x1,
|
||||
y = wesnoth.current.event_context.y1
|
||||
}
|
||||
end
|
||||
|
||||
local heal_full = cfg.amount == "full" or cfg.amount == nil
|
||||
local moves_full = cfg.moves == "full"
|
||||
local heal_amount_set = false
|
||||
for i,u in ipairs(who) do
|
||||
local heal_amount = u.max_hitpoints - u.hitpoints
|
||||
if heal_full then
|
||||
u.hitpoints = u.max_hitpoints
|
||||
else
|
||||
heal_amount = tonumber(cfg.amount) or heal_amount
|
||||
local new_hitpoints = math.max(1, math.min(u.max_hitpoints, u.hitpoints + heal_amount))
|
||||
heal_amount = new_hitpoints - u.hitpoints
|
||||
u.hitpoints = new_hitpoints
|
||||
end
|
||||
|
||||
if moves_full then
|
||||
u.moves = u.max_moves
|
||||
else
|
||||
u.moves = math.min(u.max_moves, u.moves + (cfg.moves or 0))
|
||||
end
|
||||
|
||||
if cfg.restore_attacks then
|
||||
u.attacks_left = u.max_attacks
|
||||
end
|
||||
|
||||
if cfg.restore_statuses == true or cfg.restore_statuses == nil then
|
||||
u.status.poisoned = false
|
||||
u.status.petrified = false
|
||||
u.status.slowed = false
|
||||
u.status.unhealable = false
|
||||
end
|
||||
|
||||
if not heal_amount_set then
|
||||
heal_amount_set = true
|
||||
wesnoth.set_variable("heal_amount", heal_amount)
|
||||
end
|
||||
|
||||
if cfg.animate then
|
||||
local animator = wesnoth.create_animator()
|
||||
animator:add(u, 'healed', 'hits', {value = heal_amount})
|
||||
if #healers > 0 then
|
||||
animator:add(healers[1], 'healing', 'hits', {value = heal_amount})
|
||||
end
|
||||
animator:run()
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
local helper = wesnoth.require "lua/helper.lua"
|
||||
local helper = wesnoth.require "helper"
|
||||
local wml_actions = wesnoth.wml_actions
|
||||
local game_events = wesnoth.game_events
|
||||
|
||||
|
|
72
data/lua/wml/kill.lua
Normal file
72
data/lua/wml/kill.lua
Normal file
|
@ -0,0 +1,72 @@
|
|||
local helper = wesnoth.require "helper"
|
||||
local location_set = wesnoth.require "location_set"
|
||||
|
||||
local kill_recursion_preventer = location_set.create()
|
||||
|
||||
function wesnoth.wml_actions.kill(cfg)
|
||||
local number_killed = 0
|
||||
local secondary_unit = helper.get_child(cfg, "secondary_unit")
|
||||
local killer_loc = {0, 0}
|
||||
if secondary_unit then
|
||||
secondary_unit = wesnoth.get_units(secondary_unit)[1]
|
||||
if cfg.fire_event then
|
||||
if secondary_unit then
|
||||
killer_loc = {secondary_unit.loc}
|
||||
else
|
||||
wesnoth.log("warn", "failed to match [secondary_unit] in [kill] with a single on-board unit")
|
||||
end
|
||||
end
|
||||
end
|
||||
local dead_men_walking = wesnoth.get_units(cfg)
|
||||
for i,unit in ipairs(dead_men_walking) do
|
||||
local death_loc = {x = tonumber(unit.x) or 0, y = tonumber(unit.y) or 0}
|
||||
if not secondary_unit then killer_loc = death_loc end
|
||||
local can_fire = false
|
||||
|
||||
local recursion = (kill_recursion_preventer:get(death_loc.x, death_loc.y) or 0) + 1
|
||||
if cfg.fire_event then
|
||||
kill_recursion_preventer:insert(death_loc.x, death_loc.y, recursion)
|
||||
can_fire = true
|
||||
if death_loc.x == wesnoth.current.event.x1 and death_loc.y == wesnoth.current.event.y1 then
|
||||
if wesnoth.current.event.name == "die" or wesnoth.current.event.name == "last breath" then
|
||||
if recursion >= 10 then
|
||||
can_fire = false;
|
||||
wesnoth.log("error", "tried to fire 'die' or 'last breath' event on unit from the unit's 'die' or 'last breath' event with first_time_only=no!")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if can_fire then
|
||||
wesnoth.fire_event("last breath", death_loc, killer_loc)
|
||||
end
|
||||
if cfg.animate then
|
||||
wesnoth.scroll_to_tile(death_loc)
|
||||
local anim = wesnoth.create_animator()
|
||||
-- Possible TODO: Add weapon selection? (That's kinda a pain right now; see animate_unit defn)
|
||||
anim:add(unit, "death", "kill")
|
||||
if secondary_unit then
|
||||
anim:add(secondary_unit, "victory", "kill")
|
||||
end
|
||||
anim:run()
|
||||
end
|
||||
wesnoth.wml_actions.redraw{}
|
||||
|
||||
if can_fire then
|
||||
wesnoth.fire_event("die", death_loc, killer_loc)
|
||||
end
|
||||
if cfg.fire_event then
|
||||
if recursion <= 1 then
|
||||
kill_recursion_preventer:remove(death_loc.x, death_loc.y)
|
||||
else
|
||||
kill_recursion_preventer:insert(death_loc.x, death_loc.y, recursion)
|
||||
end
|
||||
end
|
||||
-- Test that it's valid (and still on the map) first, in case the event erased (or extracted) it.
|
||||
if unit.valid == "map" then unit:erase() end
|
||||
|
||||
number_killed = number_killed + 1
|
||||
end
|
||||
|
||||
-- TODO: Do I need to check recall lists or was that covered by the above loop?
|
||||
return number_killed
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
local helper = wesnoth.require "lua/helper.lua"
|
||||
local utils = wesnoth.require "lua/wml-utils.lua"
|
||||
local location_set = wesnoth.require "lua/location_set.lua"
|
||||
local helper = wesnoth.require "helper"
|
||||
local utils = wesnoth.require "wml-utils"
|
||||
local location_set = wesnoth.require "location_set"
|
||||
local _ = wesnoth.textdomain "wesnoth"
|
||||
|
||||
local function log(msg, level)
|
||||
|
|
|
@ -1,20 +1,11 @@
|
|||
local H = wesnoth.require "lua/helper.lua"
|
||||
local H = wesnoth.require "helper"
|
||||
local W = H.set_wml_action_metatable {}
|
||||
local MAIH = wesnoth.require("ai/micro_ais/micro_ai_helper.lua")
|
||||
|
||||
wesnoth.micro_ais = {}
|
||||
|
||||
-- Load all default MicroAIs
|
||||
wesnoth.require("ai/micro_ais/mai-defs/animals.lua")
|
||||
wesnoth.require("ai/micro_ais/mai-defs/bottleneck.lua")
|
||||
wesnoth.require("ai/micro_ais/mai-defs/escort.lua")
|
||||
wesnoth.require("ai/micro_ais/mai-defs/fast.lua")
|
||||
wesnoth.require("ai/micro_ais/mai-defs/guardian.lua")
|
||||
wesnoth.require("ai/micro_ais/mai-defs/healers.lua")
|
||||
wesnoth.require("ai/micro_ais/mai-defs/misc.lua")
|
||||
wesnoth.require("ai/micro_ais/mai-defs/patrol.lua")
|
||||
wesnoth.require("ai/micro_ais/mai-defs/protect.lua")
|
||||
wesnoth.require("ai/micro_ais/mai-defs/recruiting.lua")
|
||||
wesnoth.require("ai/micro_ais/mai-defs")
|
||||
|
||||
function wesnoth.wml_actions.micro_ai(cfg)
|
||||
local CA_path = 'ai/micro_ais/cas/'
|
35
data/lua/wml/modify_ai.lua
Normal file
35
data/lua/wml/modify_ai.lua
Normal file
|
@ -0,0 +1,35 @@
|
|||
local helper = wesnoth.require "helper"
|
||||
local utils = wesnoth.require "wml-utils"
|
||||
|
||||
function wesnoth.wml_actions.modify_ai(cfg)
|
||||
local sides = utils.get_sides(cfg)
|
||||
local component, final
|
||||
if cfg.action == "add" or cfg.action == "change" then
|
||||
local start = string.find(cfg.path, "[a-z_]+%[[a-z0-9_*]*%]$")
|
||||
final = start and (string.find(cfg.path, '[', start, true) - 1) or -1
|
||||
start = start or string.find(cfg.path, "[^.]*$") or 1
|
||||
local comp_type = string.sub(cfg.path, start, final)
|
||||
component = helper.get_child(cfg, comp_type)
|
||||
if component == nil then
|
||||
helper.wml_error("Missing component definition in [modify_ai]")
|
||||
end
|
||||
component = helper.parsed(component)
|
||||
end
|
||||
for i = 1, #sides do
|
||||
if cfg.action == "add" then
|
||||
wesnoth.add_ai_component(sides[i].side, cfg.path, component)
|
||||
elseif cfg.action == "delete" or cfg.action == "try_delete" then
|
||||
wesnoth.delete_ai_component(sides[i].side, cfg.path)
|
||||
elseif cfg.action == "change" then
|
||||
local id_start = final + 2
|
||||
local id_final = string.len(cfg.path) - 1
|
||||
local id = string.sub(cfg.path, id_start, id_final)
|
||||
if id == "*" then
|
||||
helper.wml_error("[modify_ai] can only change one component at a time")
|
||||
elseif not component.id and not id:match("[0-9]+") then
|
||||
component.id = id
|
||||
end
|
||||
wesnoth.change_ai_component(sides[i].side, cfg.path, component)
|
||||
end
|
||||
end
|
||||
end
|
109
data/lua/wml/modify_side.lua
Normal file
109
data/lua/wml/modify_side.lua
Normal file
|
@ -0,0 +1,109 @@
|
|||
local helper = wesnoth.require "helper"
|
||||
local utils = wesnoth.require "wml-utils"
|
||||
local T = helper.set_wml_tag_metatable {}
|
||||
|
||||
local side_changes_needing_redraw = {
|
||||
'shroud', 'fog', 'reset_map', 'reset_view', 'shroud_data',
|
||||
'share_vision', 'share_maps', 'share_view',
|
||||
'color', 'flag',
|
||||
}
|
||||
|
||||
function wesnoth.wml_actions.modify_side(cfg)
|
||||
local sides = utils.get_sides(cfg)
|
||||
for i,side in ipairs(sides) do
|
||||
if cfg.team_name then
|
||||
side.team_name = cfg.team_name
|
||||
end
|
||||
if cfg.user_team_name then
|
||||
side.user_team_name = cfg.user_team_name
|
||||
end
|
||||
if cfg.controller then
|
||||
side.controller = cfg.controller
|
||||
end
|
||||
if cfg.defeat_condition then
|
||||
side.defeat_condition = cfg.defeat_condition
|
||||
end
|
||||
if cfg.recruit then
|
||||
local recruits = {}
|
||||
for recruit in utils.split(cfg.recruit) do
|
||||
table.insert(recruits, recruit)
|
||||
end
|
||||
side.recruit = recruits
|
||||
end
|
||||
if cfg.village_support then
|
||||
side.village_support = cfg.village_support
|
||||
end
|
||||
if cfg.village_gold then
|
||||
side.village_gold = cfg.village_gold
|
||||
end
|
||||
if cfg.income then
|
||||
side.base_income = cfg.income
|
||||
end
|
||||
if cfg.gold then
|
||||
side.gold = cfg.gold
|
||||
end
|
||||
|
||||
if cfg.hidden ~= nil then
|
||||
side.hidden = cfg.hidden
|
||||
end
|
||||
if cfg.color or cfg.flag then
|
||||
wesnoth.set_side_id(side.side, cfg.flag, cfg.color)
|
||||
end
|
||||
if cfg.flag_icon then
|
||||
side.flag_icon = cfg.flag_icon
|
||||
end
|
||||
if cfg.suppress_end_turn_confirmation ~= nil then
|
||||
side.suppress_end_turn_confirmation = cfg.suppress_end_turn_confirmation
|
||||
end
|
||||
if cfg.scroll_to_leader ~= nil then
|
||||
side.scroll_to_leader = cfg.scroll_to_leader
|
||||
end
|
||||
|
||||
if cfg.shroud ~= nil then
|
||||
side.shroud = cfg.shroud
|
||||
end
|
||||
if cfg.reset_maps then
|
||||
wesnoth.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)
|
||||
end
|
||||
if cfg.shroud_data then
|
||||
wesnoth.remove_shroud(side.side, cfg.shroud_data)
|
||||
end
|
||||
|
||||
if cfg.share_vision then
|
||||
side.share_vision = cfg.share_vision
|
||||
end
|
||||
-- Legacy support
|
||||
if cfg.share_view ~= nil or cfg.share_maps ~= nil then
|
||||
if cfg.share_view then
|
||||
side.share_vision = 'all'
|
||||
elseif cfg.share_maps then
|
||||
side.share_vision = 'shroud'
|
||||
else
|
||||
side.share_vision = 'none'
|
||||
end
|
||||
end
|
||||
|
||||
if cfg.switch_ai then
|
||||
wesnoth.switch_ai(side.side, cfg.switch_ai)
|
||||
end
|
||||
local ai = {}
|
||||
for next_ai in helper.child_range(cfg, "ai") do
|
||||
table.insert(ai, T.ai(next_ai))
|
||||
end
|
||||
if #ai > 0 then
|
||||
wesnoth.append_ai(side.side, ai)
|
||||
end
|
||||
end
|
||||
for i,key in ipairs(side_changes_needing_redraw) do
|
||||
if cfg[key] ~= nil then
|
||||
wesnoth.wml_actions.redraw{}
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
local helper = wesnoth.require "lua/helper.lua"
|
||||
local utils = wesnoth.require "lua/wml-utils.lua"
|
||||
local helper = wesnoth.require "helper"
|
||||
local utils = wesnoth.require "wml-utils"
|
||||
local wml_actions = wesnoth.wml_actions
|
||||
|
||||
function wml_actions.modify_unit(cfg)
|
||||
|
|
64
data/lua/wml/move_unit.lua
Normal file
64
data/lua/wml/move_unit.lua
Normal file
|
@ -0,0 +1,64 @@
|
|||
local helper = wesnoth.require "helper"
|
||||
|
||||
function wesnoth.wml_actions.move_unit(cfg)
|
||||
local coordinate_error = "invalid coordinate in [move_unit]"
|
||||
local to_x = tostring(cfg.to_x or helper.wml_error(coordinate_error))
|
||||
local to_y = tostring(cfg.to_y or helper.wml_error(coordinate_error))
|
||||
local fire_event = cfg.fire_event
|
||||
local muf_force_scroll = cfg.force_scroll
|
||||
local check_passability = cfg.check_passability
|
||||
if check_passability == nil then check_passability = true end
|
||||
cfg = helper.literal(cfg)
|
||||
cfg.to_x, cfg.to_y, cfg.fire_event = nil, nil, nil
|
||||
local units = wesnoth.get_units(cfg)
|
||||
|
||||
local pattern = "[^%s,]+"
|
||||
for current_unit_index, current_unit in ipairs(units) do
|
||||
if not fire_event or current_unit.valid then
|
||||
local xs, ys = string.gmatch(to_x, pattern), string.gmatch(to_y, pattern)
|
||||
local move_string_x = current_unit.x
|
||||
local move_string_y = current_unit.y
|
||||
local pass_check = nil
|
||||
if check_passability then pass_check = current_unit end
|
||||
|
||||
local x, y = xs(), ys()
|
||||
local prevX, prevY = tonumber(current_unit.x), tonumber(current_unit.y)
|
||||
while true do
|
||||
x = tonumber(x) or helper.wml_error(coordinate_error)
|
||||
y = tonumber(y) or helper.wml_error(coordinate_error)
|
||||
if not (x == prevX and y == prevY) then x, y = wesnoth.find_vacant_tile(x, y, pass_check) end
|
||||
if not x or not y then helper.wml_error("Could not find a suitable hex near to one of the target hexes in [move_unit].") end
|
||||
move_string_x = string.format("%s,%u", move_string_x, x)
|
||||
move_string_y = string.format("%s,%u", move_string_y, y)
|
||||
local next_x, next_y = xs(), ys()
|
||||
if not next_x and not next_y then break end
|
||||
prevX, prevY = x, y
|
||||
x, y = next_x, next_y
|
||||
end
|
||||
|
||||
if current_unit.x < x then current_unit.facing = "se"
|
||||
elseif current_unit.x > x then current_unit.facing = "sw"
|
||||
end
|
||||
|
||||
wesnoth.extract_unit(current_unit)
|
||||
local current_unit_cfg = current_unit.__cfg
|
||||
wesnoth.wml_actions.move_unit_fake {
|
||||
type = current_unit_cfg.type,
|
||||
gender = current_unit_cfg.gender,
|
||||
variation = current_unit_cfg.variation,
|
||||
image_mods = current_unit.image_mods,
|
||||
side = current_unit_cfg.side,
|
||||
x = move_string_x,
|
||||
y = move_string_y,
|
||||
force_scroll = muf_force_scroll
|
||||
}
|
||||
local x2, y2 = current_unit.x, current_unit.y
|
||||
current_unit.x, current_unit.y = x, y
|
||||
wesnoth.put_unit(current_unit)
|
||||
|
||||
if fire_event then
|
||||
wesnoth.fire_event("moveto", x, y, x2, y2)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
local helper = wesnoth.require "lua/helper.lua"
|
||||
local utils = wesnoth.require "lua/wml-utils.lua"
|
||||
local helper = wesnoth.require "helper"
|
||||
local utils = wesnoth.require "wml-utils"
|
||||
local T = helper.set_wml_tag_metatable {}
|
||||
local wml_actions = wesnoth.wml_actions
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
local helper = wesnoth.require "lua/helper.lua"
|
||||
local helper = wesnoth.require "helper"
|
||||
local wml_actions = wesnoth.wml_actions
|
||||
local game_events = wesnoth.game_events
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue