From 8656b2323b2c139a8a30be28bf55f5090067c71b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 30 May 2008 21:01:25 +0000 Subject: [PATCH] implementation of adamant and tunnels --- src/res/eressea/items.xml | 13 +++++++ src/scripts/adamant.lua | 68 +++++++++++++++++++++++++++++++++ src/scripts/eressea.lua | 1 + src/scripts/eressea/tunnels.lua | 46 ++++++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 src/scripts/adamant.lua create mode 100644 src/scripts/eressea/tunnels.lua diff --git a/src/res/eressea/items.xml b/src/res/eressea/items.xml index 75816f684..e92fdf1c2 100644 --- a/src/res/eressea/items.xml +++ b/src/res/eressea/items.xml @@ -173,6 +173,19 @@ + + + + + + + + + + + + + diff --git a/src/scripts/adamant.lua b/src/scripts/adamant.lua new file mode 100644 index 000000000..06c29718c --- /dev/null +++ b/src/scripts/adamant.lua @@ -0,0 +1,68 @@ +-- adamant gifts and setup for tunnels + +-- use only once to hand out some items to existing factions +function adamant_gifts() + for f in factions() do + local i = math.mod(test.rng_int(), 2) + if i==0 then + f:add_item("diamond", 1) + f:add_item("diamondplate", 1) + else + f:add_item("diamond", 3) + f:add_item("diamondaxe", 1) + end + end +end + +-- create a fixed path to a specific region +local function create_path(from, to) + local param = tostring(to.uid) + local b = add_building(from, "portal") + b.name = "Weltentor" + b.size = 1 + b:add_action("tunnel_action", param) +end + +-- create a wonky tunnel wth more than one exit +local function create_tunnel(from, param) + local b = add_building(from, "portal") + b.name = "Weltentor" + b.size = 1 + b:add_action("tunnel_action", param) +end + +-- make a tunnel from the cursor to the first selected region +function mktunnel() + local from = gmtool.cursor() + local to = gmtool.selection()() + if to~=nil then + terraform(from.x, from.y, "glacier") + create_tunnel(from, to) + gmtool.select(to, 0) + gmtool.highlight(to, 1) + end +end + +-- turn all selected regions into targets for a wonky tunnel ("tnnL") +function mkanchors() + for r in gmtool.selection() do + if not r:get_key("tnnL") then + r:set_key("tnnL", true) + if r:get_flag(0) then + -- RF_CHAOTIC + r:set_flag(0, true) + end + r:set_resource("peasant", r:get_resource("peasant") + 1) + end + end +end + +-- terraform and prepare all hell-regions to become wonky gates +function mkgates() + for r in regions() do + if r.plane_id==0 and r.terrain=="hell" then + create_tunnel(r, "tnnL") + terraform(r.x, r.y, "glacier") + end + end +end diff --git a/src/scripts/eressea.lua b/src/scripts/eressea.lua index e2d3bd782..bf11aeb1c 100644 --- a/src/scripts/eressea.lua +++ b/src/scripts/eressea.lua @@ -40,6 +40,7 @@ function load_scripts() "eressea/xmas2005.lua", "eressea/xmas2006.lua", "eressea/embassy.lua", + "eressea/tunnels.lua", "eressea/ents.lua" } for index, value in pairs(scripts) do diff --git a/src/scripts/eressea/tunnels.lua b/src/scripts/eressea/tunnels.lua new file mode 100644 index 000000000..547f1c47d --- /dev/null +++ b/src/scripts/eressea/tunnels.lua @@ -0,0 +1,46 @@ +local function tunnel_travellers(b) + local units = {} + for u in b.units do + units[u] = u + end + return units +end + +targets = nil +ntargets = 0 + +local function get_target(param) + if targets == nil then + targets = {} + local r + for r in regions() do + if r:get_key(param) then + targets[ntargets] = r + ntargets = ntargets + 1 + end + end + end + if ntargets==0 then + return nil + end + local rn = math.mod(test.rng_int(), ntargets) + return targets[rn] +end + +-- export, will be called from lc_age() +function tunnel_action(b, param) + local r = nil + if tonumber(param)~=nil then + r = get_region_by_id(tonumber(param)) + end + if r~=nil then + local units = tunnel_travelers(b) + for key, u in pairs(units) do + if r==nil then + u.region = get_target(param) + else + u.region = r + end + end + end +end