diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d2635f05..0edbe230c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,8 +48,12 @@ endif() find_package(EXPAT REQUIRED) find_package (ToLua REQUIRED) if (TOLUA_FOUND) -if (${TOLUA_VERSION_STRING} VERSION_EQUAL "5.2") +if (${TOLUA_VERSION_STRING} VERSION_EQUAL "5.3") +find_package (Lua 5.3 REQUIRED) +elseif (${TOLUA_VERSION_STRING} VERSION_EQUAL "5.2") find_package (Lua 5.2 REQUIRED) +elseif (${TOLUA_VERSION_STRING} VERSION_EQUAL "5.3") +find_package ( Lua 5.3 REQUIRED) else () find_package (Lua51 REQUIRED) endif() diff --git a/s/build b/s/build index 709c92510..e54f83ace 100755 --- a/s/build +++ b/s/build @@ -1,6 +1,6 @@ #!/bin/sh ROOT=$(git rev-parse --show-toplevel) - +eval $(luarocks path) [ -z "$BUILD" ] && BUILD=Debug if [ -z "$JOBS" ] ; then if [ -e /usr/sbin/sysctl ]; then diff --git a/s/cmake-init b/s/cmake-init index 22d98b42e..00e6d3d06 100755 --- a/s/cmake-init +++ b/s/cmake-init @@ -6,6 +6,7 @@ pkg-config --exists sqlite3 && ERESSEA_DB=sqlite GETOPT=getopt GETOPT_LONG=1 +luarocks install lunitx --local if [ "Darwin" = "$(uname)" ] ; then if [ -x "/usr/local/opt/gnu-getopt/bin/getopt" ] ; then GETOPT="/usr/local/opt/gnu-getopt/bin/getopt" @@ -74,18 +75,19 @@ fi DEST=$(dirname $ROOT)/server -git submodule update --init - LUA_VERSION="5.2" LUA_INCLUDE=/usr/include LUA_DIR=/usr -if [ -d /usr/include/lua5.1 ]; then - LUA_VERSION="5.1" - LUA_INCLUDE=/usr/include/lua5.1 +if [ -d /usr/local/include/lua5.3 ]; then + LUA_VERSION="5.3" + LUA_INCLUDE=/usr/local/include/lua5.3 elif [ -d /usr/include/lua5.2 ]; then export LUA_DIR=/usr LUA_VERSION="5.2" LUA_INCLUDE=/usr/include/lua5.2 +elif [ -d /usr/include/lua5.1 ]; then + LUA_VERSION="5.1" + LUA_INCLUDE=/usr/include/lua5.1 elif [ -d /usr/local/include/lua5.1 ]; then export LUA_DIR=/usr/local LUA_VERSION="5.1" diff --git a/s/runtests b/s/runtests index 429f8ef03..2c8049098 100755 --- a/s/runtests +++ b/s/runtests @@ -1,5 +1,6 @@ #!/bin/bash set -e + eval $(luarocks path) ROOT=$(git rev-parse --show-toplevel) [ -z $BUILD ] && BUILD=Debug ; export BUILD diff --git a/scripts/eressea/equipment.lua b/scripts/eressea/equipment.lua index 7d92d43c9..3163b85d9 100644 --- a/scripts/eressea/equipment.lua +++ b/scripts/eressea/equipment.lua @@ -6,10 +6,6 @@ local function equip_first(u) equip_unit(u, name, 255) end -local function equip_demon(u) - u.race_name = 'human' -end - local mysets = { ['first_unit'] = { ['items'] = { @@ -82,7 +78,6 @@ local mysets = { ['skills'] = { ['stamina'] = 15 }, - ['callback'] = equip_demon }, ['seed_insect'] = { ['items'] = { diff --git a/scripts/run-tests-e2.lua b/scripts/run-tests-e2.lua index 2495b8385..dd0631086 100644 --- a/scripts/run-tests-e2.lua +++ b/scripts/run-tests-e2.lua @@ -1,6 +1,11 @@ -- Tests that work in all games. With game config of E2. -- Tests are under scripts/test/e2 and all files must be in scripts/test/e2/init.lua +lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then +module = lunit.module +end + path = 'scripts' if config.install then path = config.install .. '/' .. path @@ -9,7 +14,6 @@ package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' config.rules = 'e2' -lunit = require 'lunit' require 'eressea' require 'eressea.xmlconf' require 'eressea.path' diff --git a/scripts/run-tests-e3.lua b/scripts/run-tests-e3.lua index e6c8c9186..e2a808147 100644 --- a/scripts/run-tests-e3.lua +++ b/scripts/run-tests-e3.lua @@ -1,6 +1,11 @@ -- Tests that work in E3. With game config of E3. -- Tests are under scripts/test/e3 and all files must be in scripts/test/e3/init.lua +lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then +module = lunit.module +end + path = 'scripts' if config.install then path = config.install .. '/' .. path @@ -9,7 +14,6 @@ package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' config.rules = 'e3' -lunit = require 'lunit' require 'eressea' require 'eressea.path' require 'eressea.xmlconf' diff --git a/scripts/run-tests.lua b/scripts/run-tests.lua index c14e15a3a..e21ac3aa9 100644 --- a/scripts/run-tests.lua +++ b/scripts/run-tests.lua @@ -1,13 +1,17 @@ -- Basic test without loading XML Config. Test care about needed settings. -- Tests are under scripts/test/ and all files must be in scripts/test/init.lua +lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then +module = lunit.module +end + path = 'scripts' if config.install then path = config.install .. '/' .. path end package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' -lunit = require 'lunit' require 'eressea' require 'eressea.path' require 'tests' diff --git a/scripts/tests/bindings.lua b/scripts/tests/bindings.lua index 5820e0a47..bdacf2660 100644 --- a/scripts/tests/bindings.lua +++ b/scripts/tests/bindings.lua @@ -1,10 +1,13 @@ -require "lunit" +local tcname = 'tests.bindings' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end -local eressea = eressea local _G = _G -module("tests.bindings", lunit.testcase) - function test_eressea() assert_equal("function", _G.type(eressea.free_game)) assert_equal("function", _G.type(eressea.read_game)) diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index 70ff2527d..058a53e2f 100644 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -1,4 +1,10 @@ -require "lunit" +local tcname = 'tests.shared.common' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end local function _test_create_ship(r) local s = ship.create(r, config.ships[1]) @@ -26,8 +32,6 @@ local function two_factions() return f1, f2 end -module("tests.common", package.seeall, lunit.testcase) - function setup() eressea.free_game() eressea.settings.set("nmr.timeout", "0") @@ -894,307 +898,3 @@ function test_walk_and_carry_the_cart() process_orders() assert_equal(1, u.region.x) end - -module("tests.recruit", package.seeall, lunit.testcase) - -function setup() - eressea.free_game() - eressea.settings.set("rules.food.flags", "4") - eressea.settings.set("rules.peasants.growth", "0") -end - -function test_bug_1795_limit() - local r = region.create(0, 0, "plain") - local f = create_faction('human') - local u1 = one_unit(r,f) - u1:add_item("money", 100000000) - u1:add_order("REKRUTIEREN 9999") - r:set_resource("peasant", 2000) -- no fractional growth! - local peasants = r:get_resource("peasant") - local limit,frac = math.modf(peasants/40) -- one day this should be a parameter - - process_orders() - assert_equal(limit+1, u1.number, u1.number .. "!=" .. (limit+1)) - assert_equal(peasants-limit, r:get_resource("peasant")) -end - -function test_bug_1795_demons() - local r = region.create(0, 0, "plain") - local f = create_faction('demon') - local u1 = one_unit(r,f) - r:set_resource("peasant", 2000) - local peasants = r:get_resource("peasant") - local limit,frac = math.modf(peasants/40) - - u1:add_item("money", 100000000) - u1:add_order("REKRUTIEREN 9999") - - process_orders() - - assert_equal(limit+1, u1.number, u1.number .. "!=" .. (limit+1)) - assert_equal(peasants, r:get_resource("peasant")) -end - -module("tests.parser", package.seeall, lunit.testcase) - -function setup() - eressea.free_game() - eressea.settings.set("rules.food.flags", "4") -- FOOD_IS_FREE - eressea.settings.set("rules.move.owner_leave", "0") -end - -function test_parser() - local r = region.create(0, 0, "mountain") - local f = create_faction('human') - local u = unit.create(f, r, 1) - local filename = "orders.txt" - - local file = io.open(filename, "w") - assert_not_nil(file) - f.password = 'Hodor' - file:write('ERESSEA ' .. itoa36(f.id) .. ' "Hodor"\n') - file:write('EINHEIT ' .. itoa36(u.id) .. "\n") - file:write("BENENNEN EINHEIT 'Goldene Herde'\n") - file:close() - - eressea.read_orders(filename) - process_orders() - os.remove(filename) - assert_equal("Goldene Herde", u.name) -end - -local function set_order(u, str) - u:clear_orders() - u:add_order(str) -end - -function test_prefix() - local r0 = region.create(0, 0, "plain") - local f1 = create_faction('human') - local u1 = unit.create(f1, r0, 1) - - set_order(u1, "PRAEFIX See") - process_orders() - assert_not_nil(u1:show():find("Seemensch")) - - u1.race = "elf" - assert_not_nil(u1:show():find("Seeelf")) - - set_order(u1, "PRAEFIX Mond") - process_orders() - assert_not_nil(u1:show():find("Mondelf")) - - set_order(u1, "PRAEFIX") - process_orders() - assert_not_nil(u1:show():find("Elf")) - - set_order(u1, "PRAEFIX Erz") - process_orders() - assert_not_nil(u1:show():find("Erzelf")) - u1.faction.locale = "en" - assert_not_nil(u1:show():find("archelf")) -end - -function test_recruit() - local r = region.create(0, 0, "plain") - local f = create_faction('human') - local u = unit.create(f, r, 1) - - u:add_item("money", 1000) - set_order(u, "REKRUTIERE 5") - process_orders() - for u in f.units do - assert_equal(6, u.number) - end -end - -function test_give_horses() - local r = region.create(0, 0, "plain") - local f = faction.create("human", "noreply@eressea.de", "de") - local u = unit.create(f, r, 1) - - r:set_resource("horse", 0) - u:add_item("horse", 21) - u:add_item("dolphin", 10) - u:add_order("GIB 0 7 PFERD") - u:add_order("GIB 0 5 DELPHIN") - process_orders() - assert_equal(7, r:get_resource("horse")) - assert_equal(5, u:get_item("dolphin")) - assert_equal(14, u:get_item("horse")) -end - -function test_give_silver() - local r = region.create(0, 0, "plain") - local f = faction.create("human", "noreply@eressea.de", "de") - local u = unit.create(f, r, 1) - - r:set_resource("peasant", 0) - r:set_resource("money", 11) - u:clear_orders() - u:add_item("money", 20) - u:add_order("GIB 0 10 SILBER") - process_orders() - assert_equal(21, r:get_resource("money")) - assert_equal(10, u:get_item("money")) -end - -function test_give_horses() - local r = region.create(0, 0, "plain") - local f = create_faction('human') - local u = unit.create(f, r, 1) - - r:set_resource("horse", 0) - u:add_item("horse", 21) - u:add_item("dolphin", 10) - u:add_order("GIB 0 7 PFERD") - u:add_order("GIB 0 5 DELPHIN") - process_orders() - assert_equal(7, r:get_resource("horse")) - assert_equal(5, u:get_item("dolphin")) - assert_equal(14, u:get_item("horse")) -end - -function test_give_silver() - local r = region.create(0, 0, "plain") - local f = create_faction('human') - local u = unit.create(f, r, 1) - - r:set_resource("peasant", 0) - r:set_resource("money", 11) - u:clear_orders() - u:add_item("money", 20) - u:add_order("GIB 0 10 SILBER") - process_orders() - assert_equal(21, r:get_resource("money")) - assert_equal(10, u:get_item("money")) -end - -function test_build_castle_one_stage() - local r = region.create(0, 0, 'plain') - local f = faction.create('human') - local u = unit.create(f, r, 2) - - u:add_item('stone', 4) - - u:set_skill('building', 1) - u:add_order('MACHE BURG') - - process_orders() - assert_equal(2, u.building.size) - assert_equal(2, u:get_item('stone')) -end - -function test_build_castle() - local r = region.create(0, 0, "plain") - local f = create_faction('human') - local u = unit.create(f, r, 1) - - u:add_item('stone', 1) - u:set_skill('building', 1) - u:add_order("MACHE BURG") - process_orders() - assert_not_nil(u.building) - assert_equal(1, u.building.size) - assert_equal(u.building.name, "Burg") -end - -function test_route() - local r1 = region.create(0, 0, "plain") - local r2 = region.create(1, 0, "plain") - local f = faction.create("human", "route@example.com") - local u = unit.create(f, r1, 1) - u:add_order("ROUTE O W P") - process_orders() - assert_equal("ROUTE West PAUSE Ost", u:get_order(0)) - assert_equal(r2, u.region) -end - -function test_route_horse() - local r1 = region.create(0, 0, "plain") - local r2 = region.create(1, 0, "plain") - local f = faction.create("human", "route@example.com") - local u = unit.create(f, r1, 1) - u:add_order("ROUTE O P W P") - u:add_item('horse', 1) - u:set_skill('riding', 1) - process_orders() - assert_equal("ROUTE West PAUSE Ost PAUSE", u:get_order(0)) - assert_equal(r2, u.region) -end - -function test_route_pause() - local r1 = region.create(0, 0, "plain") - local r2 = region.create(1, 0, "plain") - local f = faction.create("human", "route@example.com") - local u = unit.create(f, r1, 1) - u:add_order("ROUTE P O W") - process_orders() - assert_equal("ROUTE P O W", u:get_order(0)) - assert_equal(r1, u.region) -end - -function test_immunity_stops_guard() - eressea.settings.set("NewbieImmunity", 2) - local f = faction.create('human') - local r = region.create(0, 0, 'plain') - local u = unit.create(f, r) - u:set_skill('polearm', 2) - u:add_item('lance', 1) - u:add_order('BEWACHE') - process_orders() - assert_equal(f.age, 1) - assert_true(not u.guard) - process_orders() - assert_equal(f.age, 2) - assert_true(u.guard) -end - -function test_region_keys() - local r = region.create(0, 0, 'plain') - assert_nil(r:get_key('test')) - assert_nil(r:get_key('more')) - r:set_key('test', 42) - r:set_key('more') -- default is 1 - assert_equal(42, r:get_key('test')) - assert_equal(1, r:get_key('more')) -end - -function test_faction_keys() - local f = faction.create('human') - assert_nil(f:get_key('test')) - assert_nil(f:get_key('more')) - f:set_key('test', 42) - f:set_key('more') -- default is 1 - assert_equal(42, f:get_key('test')) - assert_equal(1, f:get_key('more')) -end - -function test_cartmaking() - local f = faction.create('human') - local r = region.create(0, 0, 'plain') - local u = unit.create(f, r) - u:set_skill('cartmaking', 1) - u:add_item('log', 10) - u:add_order('MACHE Wagen') - process_orders() - assert_equal(1, u:get_item('cart')) - assert_equal(5, u:get_item('log')) -end - -function test_promote_after_recruit() - local f = faction.create('human') - local r1 = region.create(0, 0, 'plain') - local r2 = region.create(1, 0, 'plain') - local u1 = unit.create(f, r1, 1) - local u2 = unit.create(f, r2, 55) - u2:add_order('REKRUTIERE 1') - u1:add_order('BEFOERDERE') - u1:add_item('money', 57) - u2:add_item('money', 150) - local fl = u1.flags - process_orders() - assert_equal(56, u2.number) - assert_equal(fl + 128, u1.flags) -- UFL_HERO - assert_equal(0, u1:get_item('money')) -end diff --git a/scripts/tests/config.lua b/scripts/tests/config.lua index 733a8ee07..0ea46b133 100644 --- a/scripts/tests/config.lua +++ b/scripts/tests/config.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.eressea.config", package.seeall, lunit.testcase ) +local tcname = 'tests.shared.config' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/adamantium.lua b/scripts/tests/e2/adamantium.lua index a893d32d5..49766cb52 100644 --- a/scripts/tests/e2/adamantium.lua +++ b/scripts/tests/e2/adamantium.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.adamantium", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.adamantium' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/allies.lua b/scripts/tests/e2/allies.lua index 8c0352923..977d75c61 100644 --- a/scripts/tests/e2/allies.lua +++ b/scripts/tests/e2/allies.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.allies", package.seeall, lunit.testcase) +local tcname = 'tests.e2.allies' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/astral.lua b/scripts/tests/e2/astral.lua index 5c4461921..20e53cb73 100644 --- a/scripts/tests/e2/astral.lua +++ b/scripts/tests/e2/astral.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.astral", package.seeall, lunit.testcase) +local tcname = 'tests.e2.astral' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() @@ -17,7 +21,7 @@ function test_fetch_astral() local r = region.create(0, 0, "plain") local ra = r:get_astral('fog') local rb = region.create(ra.x + 1, ra.y, 'fog') - local f = faction.create("human") + local f = faction.create("human"); local u1 = unit.create(f, r, 1) local u2 = unit.create(f, r, 1) local u3 = unit.create(f, rb, 1) diff --git a/scripts/tests/e2/buildings.lua b/scripts/tests/e2/buildings.lua index a2407335b..3ae9c0337 100644 --- a/scripts/tests/e2/buildings.lua +++ b/scripts/tests/e2/buildings.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.buildings", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.buildings' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.game.reset() diff --git a/scripts/tests/e2/carts.lua b/scripts/tests/e2/carts.lua index 025b473df..f96affba7 100644 --- a/scripts/tests/e2/carts.lua +++ b/scripts/tests/e2/carts.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.carts", package.seeall, lunit.testcase) +local tcname = 'tests.e2.carts' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/destroy.lua b/scripts/tests/e2/destroy.lua index db6f09c2a..bbdab2b0d 100644 --- a/scripts/tests/e2/destroy.lua +++ b/scripts/tests/e2/destroy.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.destroy", package.seeall, lunit.testcase) +local tcname = 'tests.e2.destroy' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/e2features.lua b/scripts/tests/e2/e2features.lua index 3175a091e..f0ee62414 100644 --- a/scripts/tests/e2/e2features.lua +++ b/scripts/tests/e2/e2features.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.e2features", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.features' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/guard.lua b/scripts/tests/e2/guard.lua index e3cf8075f..0cc970f8c 100644 --- a/scripts/tests/e2/guard.lua +++ b/scripts/tests/e2/guard.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.guard", package.seeall, lunit.testcase) +local tcname = 'tests.e2.guard' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index 4246fd288..587c295c0 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -3,7 +3,6 @@ require 'tests.e2.trees' require 'tests.e2.buildings' require 'tests.e2.movement' require 'tests.e2.carts' -require 'tests.e2.quit' require 'tests.e2.astral' require 'tests.e2.spells' require 'tests.e2.e2features' @@ -23,6 +22,8 @@ require 'tests.items' require 'tests.economy' require 'tests.orders' require 'tests.common' +require 'tests.recruit' +require 'tests.parser' require 'tests.report' require 'tests.storage' require 'tests.magicbag' @@ -31,3 +32,4 @@ require 'tests.xmas' require 'tests.production' require 'tests.spells' require 'tests.undead' + diff --git a/scripts/tests/e2/insects.lua b/scripts/tests/e2/insects.lua index f5b8a3213..2e7fe5282 100644 --- a/scripts/tests/e2/insects.lua +++ b/scripts/tests/e2/insects.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.insects", package.seeall, lunit.testcase) +local tcname = 'tests.e2.insects' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/items.lua b/scripts/tests/e2/items.lua index 2492a7fdb..ba0d305c8 100644 --- a/scripts/tests/e2/items.lua +++ b/scripts/tests/e2/items.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.items", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.items' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/movement.lua b/scripts/tests/e2/movement.lua index aa42857f3..d5f2f886f 100644 --- a/scripts/tests/e2/movement.lua +++ b/scripts/tests/e2/movement.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.movement", package.seeall, lunit.testcase) +local tcname = 'tests.e2.movement' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/production.lua b/scripts/tests/e2/production.lua index 80d3447d2..092e44dd6 100644 --- a/scripts/tests/e2/production.lua +++ b/scripts/tests/e2/production.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.production", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.production' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.game.reset() diff --git a/scripts/tests/e2/quit.lua b/scripts/tests/e2/quit.lua index 7db59091b..f1a8e6a0c 100644 --- a/scripts/tests/e2/quit.lua +++ b/scripts/tests/e2/quit.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.quit", package.seeall, lunit.testcase) +local tcname = 'tests.e2.quit' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function test_quit_faction() local r = region.create(47, 0, "plain") diff --git a/scripts/tests/e2/shiplanding.lua b/scripts/tests/e2/shiplanding.lua index 2258a1992..f5eb9f400 100644 --- a/scripts/tests/e2/shiplanding.lua +++ b/scripts/tests/e2/shiplanding.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.shiplanding", package.seeall, lunit.testcase) +local tcname = 'tests.e2.shiplanding' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/ships.lua b/scripts/tests/e2/ships.lua index 5b77220ec..db44871b3 100644 --- a/scripts/tests/e2/ships.lua +++ b/scripts/tests/e2/ships.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.ships", package.seeall, lunit.testcase) +local tcname = 'tests.e2.ships' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.game.reset() diff --git a/scripts/tests/e2/spells.lua b/scripts/tests/e2/spells.lua index 8942ee1f5..2a5c50b2c 100644 --- a/scripts/tests/e2/spells.lua +++ b/scripts/tests/e2/spells.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.spells", package.seeall, lunit.testcase) +local tcname = 'tests.e2.spells' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.game.reset() diff --git a/scripts/tests/e2/stealth.lua b/scripts/tests/e2/stealth.lua index 7f531776c..6a8fcd9f9 100644 --- a/scripts/tests/e2/stealth.lua +++ b/scripts/tests/e2/stealth.lua @@ -1,6 +1,10 @@ -require "lunit" - -module('tests.e2.stealth', package.seeall, lunit.testcase) +local tcname = 'tests.e2.stealth' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end local f local u diff --git a/scripts/tests/e2/trees.lua b/scripts/tests/e2/trees.lua index 739d9f1e6..b5bfa1f6b 100644 --- a/scripts/tests/e2/trees.lua +++ b/scripts/tests/e2/trees.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.trees", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.trees' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.game.reset() diff --git a/scripts/tests/e2/trolls.lua b/scripts/tests/e2/trolls.lua index b6d96b015..cc60ade2d 100644 --- a/scripts/tests/e2/trolls.lua +++ b/scripts/tests/e2/trolls.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.trolls", package.seeall, lunit.testcase ) +local tcname = 'tests.e2.trolls' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/scripts/tests/e2/undead.lua b/scripts/tests/e2/undead.lua index b283d1fcc..5b8170ef6 100644 --- a/scripts/tests/e2/undead.lua +++ b/scripts/tests/e2/undead.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e2.undead", package.seeall, lunit.testcase) +local tcname = 'tests.e2.undead' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/scripts/tests/e3/buildings.lua b/scripts/tests/e3/buildings.lua index d5ea4fa51..1258f9824 100644 --- a/scripts/tests/e3/buildings.lua +++ b/scripts/tests/e3/buildings.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.buildings", package.seeall, lunit.testcase ) +local tcname = 'tests.e3.buildings' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.game.reset() diff --git a/scripts/tests/e3/init.lua b/scripts/tests/e3/init.lua index 04b7da4a2..2ccd19139 100644 --- a/scripts/tests/e3/init.lua +++ b/scripts/tests/e3/init.lua @@ -10,6 +10,8 @@ require 'tests.spells' require 'tests.economy' require 'tests.orders' require 'tests.common' +require 'tests.recruit' +require 'tests.parser' require 'tests.items' require 'tests.magicbag' require 'tests.process' diff --git a/scripts/tests/e3/items.lua b/scripts/tests/e3/items.lua index 1df6be85a..60fce6b7a 100644 --- a/scripts/tests/e3/items.lua +++ b/scripts/tests/e3/items.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.items", package.seeall, lunit.testcase ) +local tcname = 'tests.e3.items' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.game.reset() diff --git a/scripts/tests/e3/morale.lua b/scripts/tests/e3/morale.lua index 1dd92a758..60ed55965 100644 --- a/scripts/tests/e3/morale.lua +++ b/scripts/tests/e3/morale.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.morale", package.seeall, lunit.testcase ) +local tcname = 'tests.e3.morale' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.game.reset() @@ -171,7 +175,7 @@ function test_morale_change() run_a_turn() assert_equal(4, r.morale) - -- regel: ohne herrscher fällt die moral jede woche um 1 punkt, bis sie 1 erreicht + -- regel: ohne herrscher fällt die moral jede woche um 1 punkt, bis sie 1 erreicht assert_false(r.is_mourning) u1.building = nil update_owners() @@ -186,7 +190,7 @@ function test_morale_change() run_a_turn() assert_equal(1, r.morale) - -- ohne herrscher ändert sich auch beschissene Moral nicht: + -- ohne herrscher ändert sich auch beschissene Moral nicht: r.morale = 0 run_a_turn() assert_equal(0, r.morale) diff --git a/scripts/tests/e3/parser.lua b/scripts/tests/e3/parser.lua index a56f08f76..862f9d946 100644 --- a/scripts/tests/e3/parser.lua +++ b/scripts/tests/e3/parser.lua @@ -1,6 +1,10 @@ -require 'lunit' - -module('tests.e3.parser', package.seeall, lunit.testcase) +local tcname = 'tests.e3.parser' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.game.reset() diff --git a/scripts/tests/e3/production.lua b/scripts/tests/e3/production.lua index 3469b06c4..9a631c755 100644 --- a/scripts/tests/e3/production.lua +++ b/scripts/tests/e3/production.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.production", package.seeall, lunit.testcase ) +local tcname = 'tests.e3.production' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.game.reset() diff --git a/scripts/tests/e3/rules.lua b/scripts/tests/e3/rules.lua index aae3b3ab1..89a6d822a 100644 --- a/scripts/tests/e3/rules.lua +++ b/scripts/tests/e3/rules.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.e3features", package.seeall, lunit.testcase) +local tcname = 'tests.e3.rules' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end local settings diff --git a/scripts/tests/e3/spells-e2.lua b/scripts/tests/e3/spells-e2.lua index f232b8a1a..0e2ab4e6d 100644 --- a/scripts/tests/e3/spells-e2.lua +++ b/scripts/tests/e3/spells-e2.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.spells-e2", package.seeall, lunit.testcase) +local tcname = 'tests.e3.e2spells' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end local r, f, u diff --git a/scripts/tests/e3/spells.lua b/scripts/tests/e3/spells.lua index 24f97c221..fb68ba3d1 100644 --- a/scripts/tests/e3/spells.lua +++ b/scripts/tests/e3/spells.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.spells", package.seeall, lunit.testcase) +local tcname = 'tests.e3.spells' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.game.reset() diff --git a/scripts/tests/e3/stealth.lua b/scripts/tests/e3/stealth.lua index 866eb4f14..1db6436a1 100644 --- a/scripts/tests/e3/stealth.lua +++ b/scripts/tests/e3/stealth.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.e3.stealth", package.seeall, lunit.testcase) +local tcname = 'tests.e3.stealth' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end local f local u diff --git a/scripts/tests/economy.lua b/scripts/tests/economy.lua index 0c140e418..271d245d6 100644 --- a/scripts/tests/economy.lua +++ b/scripts/tests/economy.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.economy", package.seeall, lunit.testcase) +local tcname = 'tests.shared.economy' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/scripts/tests/faction.lua b/scripts/tests/faction.lua index c264f4596..fe728e9a0 100644 --- a/scripts/tests/faction.lua +++ b/scripts/tests/faction.lua @@ -1,6 +1,10 @@ -require "lunit" - -module ('tests.eressea.faction', package.seeall, lunit.testcase) +local tcname = 'tests.faction' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end local f diff --git a/scripts/tests/hunger.lua b/scripts/tests/hunger.lua index a33c2208b..750d7c74b 100644 --- a/scripts/tests/hunger.lua +++ b/scripts/tests/hunger.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.hunger", package.seeall, lunit.testcase) +local tcname = 'tests.hunger' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/scripts/tests/items.lua b/scripts/tests/items.lua index f4d8657c6..c6252db17 100644 --- a/scripts/tests/items.lua +++ b/scripts/tests/items.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.items", package.seeall, lunit.testcase ) +local tcname = 'tests.shared.items' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/scripts/tests/laws.lua b/scripts/tests/laws.lua index 6dc37daf7..d9a379319 100644 --- a/scripts/tests/laws.lua +++ b/scripts/tests/laws.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.laws", package.seeall, lunit.testcase) +local tcname = 'tests.laws' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() @@ -115,3 +119,4 @@ function test_force_leave_postcombat() assert_equal(nil, u3.building) assert_equal(1, u3.number) end + diff --git a/scripts/tests/locale.lua b/scripts/tests/locale.lua index 2770beb3f..2b4dbea8c 100644 --- a/scripts/tests/locale.lua +++ b/scripts/tests/locale.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.eressea.locale", package.seeall, lunit.testcase ) +local tcname = 'tests.locale' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/scripts/tests/magicbag.lua b/scripts/tests/magicbag.lua index b51925726..e34d5fba5 100644 --- a/scripts/tests/magicbag.lua +++ b/scripts/tests/magicbag.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.magicbag", package.seeall, lunit.testcase) +local tcname = 'tests.shared.magicbag' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end local u diff --git a/scripts/tests/movement.lua b/scripts/tests/movement.lua index 22bd8d30e..16868dfec 100644 --- a/scripts/tests/movement.lua +++ b/scripts/tests/movement.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.movement", package.seeall, lunit.testcase) +local tcname = 'tests.movement' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname , 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/scripts/tests/orders.lua b/scripts/tests/orders.lua index 6dc191d6c..d3ade71d2 100644 --- a/scripts/tests/orders.lua +++ b/scripts/tests/orders.lua @@ -1,12 +1,14 @@ -require "lunit" +local tcname = 'tests.shared.orders' +local lunit = require("lunit") +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname , 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end local _G = _G -local eressea = eressea local default_ship = config.ships[1] local default_building = config.buildings[1] - -module('tests.eressea.orders', package.seeall, lunit.testcase) - local r, f, u function setup() diff --git a/scripts/tests/parser.lua b/scripts/tests/parser.lua new file mode 100644 index 000000000..7cd42b17f --- /dev/null +++ b/scripts/tests/parser.lua @@ -0,0 +1,270 @@ +local tcname = 'tests.shared.parser' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end + +function setup() + eressea.free_game() + eressea.settings.set("rules.food.flags", "4") -- FOOD_IS_FREE + eressea.settings.set("rules.move.owner_leave", "0") +end + +function test_parser() + local r = region.create(0, 0, "mountain") + local f = faction.create('human') + local u = unit.create(f, r, 1) + local filename = "orders.txt" + + local file = io.open(filename, "w") + assert_not_nil(file) + f.password = 'Hodor' + file:write('ERESSEA ' .. itoa36(f.id) .. ' "Hodor"\n') + file:write('EINHEIT ' .. itoa36(u.id) .. "\n") + file:write("BENENNEN EINHEIT 'Goldene Herde'\n") + file:close() + + eressea.read_orders(filename) + process_orders() + os.remove(filename) + assert_equal("Goldene Herde", u.name) +end + +local function set_order(u, str) + u:clear_orders() + u:add_order(str) +end + +function test_prefix() + local r0 = region.create(0, 0, "plain") + local f1 = faction.create('human') + local u1 = unit.create(f1, r0, 1) + + set_order(u1, "PRAEFIX See") + process_orders() + assert_not_nil(u1:show():find("Seemensch")) + + u1.race = "elf" + assert_not_nil(u1:show():find("Seeelf")) + + set_order(u1, "PRAEFIX Mond") + process_orders() + assert_not_nil(u1:show():find("Mondelf")) + + set_order(u1, "PRAEFIX") + process_orders() + assert_not_nil(u1:show():find("Elf")) + + set_order(u1, "PRAEFIX Erz") + process_orders() + assert_not_nil(u1:show():find("Erzelf")) + u1.faction.locale = "en" + assert_not_nil(u1:show():find("archelf")) +end + +function test_recruit() + local r = region.create(0, 0, "plain") + local f = faction.create('human') + local u = unit.create(f, r, 1) + + u:add_item("money", 1000) + set_order(u, "REKRUTIERE 5") + process_orders() + for u in f.units do + assert_equal(6, u.number) + end +end + +function test_give_horses() + local r = region.create(0, 0, "plain") + local f = faction.create("human", "noreply@eressea.de", "de") + local u = unit.create(f, r, 1) + + r:set_resource("horse", 0) + u:add_item("horse", 21) + u:add_item("dolphin", 10) + u:add_order("GIB 0 7 PFERD") + u:add_order("GIB 0 5 DELPHIN") + process_orders() + assert_equal(7, r:get_resource("horse")) + assert_equal(5, u:get_item("dolphin")) + assert_equal(14, u:get_item("horse")) +end + +function test_give_silver() + local r = region.create(0, 0, "plain") + local f = faction.create("human", "noreply@eressea.de", "de") + local u = unit.create(f, r, 1) + + r:set_resource("peasant", 0) + r:set_resource("money", 11) + u:clear_orders() + u:add_item("money", 20) + u:add_order("GIB 0 10 SILBER") + process_orders() + assert_equal(21, r:get_resource("money")) + assert_equal(10, u:get_item("money")) +end + +function test_give_horses() + local r = region.create(0, 0, "plain") + local f = faction.create('human') + local u = unit.create(f, r, 1) + + r:set_resource("horse", 0) + u:add_item("horse", 21) + u:add_item("dolphin", 10) + u:add_order("GIB 0 7 PFERD") + u:add_order("GIB 0 5 DELPHIN") + process_orders() + assert_equal(7, r:get_resource("horse")) + assert_equal(5, u:get_item("dolphin")) + assert_equal(14, u:get_item("horse")) +end + +function test_give_silver() + local r = region.create(0, 0, "plain") + local f = faction.create('human') + local u = unit.create(f, r, 1) + + r:set_resource("peasant", 0) + r:set_resource("money", 11) + u:clear_orders() + u:add_item("money", 20) + u:add_order("GIB 0 10 SILBER") + process_orders() + assert_equal(21, r:get_resource("money")) + assert_equal(10, u:get_item("money")) +end + +function test_build_castle_one_stage() + local r = region.create(0, 0, 'plain') + local f = faction.create('human') + local u = unit.create(f, r, 2) + + u:add_item('stone', 4) + + u:set_skill('building', 1) + u:add_order('MACHE BURG') + + process_orders() + assert_equal(2, u.building.size) + assert_equal(2, u:get_item('stone')) +end + +function test_build_castle() + local r = region.create(0, 0, "plain") + local f = faction.create('human') + local u = unit.create(f, r, 1) + + u:add_item('stone', 1) + u:set_skill('building', 1) + u:add_order("MACHE BURG") + process_orders() + assert_not_nil(u.building) + assert_equal(1, u.building.size) + assert_equal(u.building.name, "Burg") +end + +function test_route() + local r1 = region.create(0, 0, "plain") + local r2 = region.create(1, 0, "plain") + local f = faction.create("human", "route@example.com") + local u = unit.create(f, r1, 1) + u:add_order("ROUTE O W P") + process_orders() + assert_equal("ROUTE West PAUSE Ost", u:get_order(0)) + assert_equal(r2, u.region) +end + +function test_route_horse() + local r1 = region.create(0, 0, "plain") + local r2 = region.create(1, 0, "plain") + local f = faction.create("human", "route@example.com") + local u = unit.create(f, r1, 1) + u:add_order("ROUTE O P W P") + u:add_item('horse', 1) + u:set_skill('riding', 1) + process_orders() + assert_equal("ROUTE West PAUSE Ost PAUSE", u:get_order(0)) + assert_equal(r2, u.region) +end + +function test_route_pause() + local r1 = region.create(0, 0, "plain") + local r2 = region.create(1, 0, "plain") + local f = faction.create("human", "route@example.com") + local u = unit.create(f, r1, 1) + u:add_order("ROUTE P O W") + process_orders() + assert_equal("ROUTE P O W", u:get_order(0)) + assert_equal(r1, u.region) +end + +function test_immunity_stops_guard() + eressea.settings.set("NewbieImmunity", 2) + local f = faction.create('human') + local r = region.create(0, 0, 'plain') + local u = unit.create(f, r) + u:set_skill('polearm', 2) + u:add_item('lance', 1) + u:add_order('BEWACHE') + process_orders() + assert_equal(f.age, 1) + assert_true(not u.guard) + process_orders() + assert_equal(f.age, 2) + assert_true(u.guard) +end + +function test_region_keys() + local r = region.create(0, 0, 'plain') + assert_nil(r:get_key('test')) + assert_nil(r:get_key('more')) + r:set_key('test', 42) + r:set_key('more') -- default is 1 + assert_equal(42, r:get_key('test')) + assert_equal(1, r:get_key('more')) +end + +function test_faction_keys() + local f = faction.create('human') + assert_nil(f:get_key('test')) + assert_nil(f:get_key('more')) + f:set_key('test', 42) + f:set_key('more') -- default is 1 + assert_equal(42, f:get_key('test')) + assert_equal(1, f:get_key('more')) +end + +function test_cartmaking() + local f = faction.create('human') + local r = region.create(0, 0, 'plain') + local u = unit.create(f, r) + u:set_skill('cartmaking', 1) + u:add_item('log', 10) + u:add_order('MACHE Wagen') + process_orders() + assert_equal(1, u:get_item('cart')) + assert_equal(5, u:get_item('log')) +end + +function test_promote_after_recruit() + local f = faction.create('human') + local r1 = region.create(0, 0, 'plain') + local r2 = region.create(1, 0, 'plain') + local u1 = unit.create(f, r1, 1) + u1.name = 'Xolgrim' + local u2 = unit.create(f, r2, 55) + u2:add_order('REKRUTIERE 1') + u1:add_order('BEFOERDERE') + u1:add_item('money', 57) + u2:add_item('money', 150) + local fl = u1.flags + process_orders() + assert_equal(56, u2.number) + assert_equal(fl + 128, u1.flags) -- UFL_HERO + assert_equal(0, u1:get_item('money')) +end diff --git a/scripts/tests/pool.lua b/scripts/tests/pool.lua index 0d24f8129..398ff6fa2 100644 --- a/scripts/tests/pool.lua +++ b/scripts/tests/pool.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.eressea.pool", package.seeall, lunit.testcase ) +local tcname = 'tests.pool' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.game.reset() diff --git a/scripts/tests/process.lua b/scripts/tests/process.lua index 1fc9a64f5..b9fcf5055 100644 --- a/scripts/tests/process.lua +++ b/scripts/tests/process.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.process", package.seeall, lunit.testcase) +local tcname = 'tests.shared.process' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end local u, r, f diff --git a/scripts/tests/production.lua b/scripts/tests/production.lua index c8a299676..bea8fcf33 100644 --- a/scripts/tests/production.lua +++ b/scripts/tests/production.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.production", package.seeall, lunit.testcase ) +local tcname = 'tests.shared.production' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.game.reset() diff --git a/scripts/tests/recruit.lua b/scripts/tests/recruit.lua new file mode 100644 index 000000000..6a0cc5de6 --- /dev/null +++ b/scripts/tests/recruit.lua @@ -0,0 +1,46 @@ +local tcname = 'tests.shared.recruit' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end + +function setup() + eressea.free_game() + eressea.settings.set("rules.food.flags", "4") + eressea.settings.set("rules.peasants.growth", "0") +end + +function test_bug_1795_limit() + local r = region.create(0, 0, "plain") + local f = faction.create('human') + local u1 = unit.create(f, r, 1) + u1:add_item("money", 100000000) + u1:add_order("REKRUTIEREN 9999") + r:set_resource("peasant", 2000) -- no fractional growth! + local peasants = r:get_resource("peasant") + local limit,frac = math.modf(peasants/40) -- one day this should be a parameter + + process_orders() + assert_equal(limit+1, u1.number, u1.number .. "!=" .. (limit+1)) + local np = r:get_resource("peasant") + assert_equal(peasants-limit, np) +end + +function test_bug_1795_demons() + local r = region.create(0, 0, "plain") + local f = faction.create('demon') + local u1 = unit.create(f, r, 1) + r:set_resource("peasant", 2000) + local peasants = r:get_resource("peasant") + local limit,frac = math.modf(peasants/40) + + u1:add_item("money", 100000000) + u1:add_order("REKRUTIEREN 9999") + + process_orders() + + assert_equal(limit+1, u1.number, u1.number .. "!=" .. (limit+1)) + assert_equal(peasants, r:get_resource("peasant")) +end diff --git a/scripts/tests/regions.lua b/scripts/tests/regions.lua index 32197f0fd..881930a40 100644 --- a/scripts/tests/regions.lua +++ b/scripts/tests/regions.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.regions", package.seeall, lunit.testcase) +local tcname = 'tests.regions' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.game.reset() diff --git a/scripts/tests/report.lua b/scripts/tests/report.lua index b02f4a908..466e77e1a 100644 --- a/scripts/tests/report.lua +++ b/scripts/tests/report.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.report", package.seeall, lunit.testcase) +local tcname = 'tests.shared.report' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/scripts/tests/settings.lua b/scripts/tests/settings.lua index 8f2c5e637..ec4cac2d1 100644 --- a/scripts/tests/settings.lua +++ b/scripts/tests/settings.lua @@ -1,6 +1,10 @@ -require 'lunit' - -module('tests.eressea.settings', package.seeall, lunit.testcase ) +local tcname = 'tests.settings' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/scripts/tests/spells.lua b/scripts/tests/spells.lua index 27a5424f7..b0def9560 100644 --- a/scripts/tests/spells.lua +++ b/scripts/tests/spells.lua @@ -1,5 +1,10 @@ -require 'lunit' -module("tests.spells", package.seeall, lunit.testcase) +local tcname = 'tests.shared.spells' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/scripts/tests/storage.lua b/scripts/tests/storage.lua index 32fbe9ef3..d51912694 100644 --- a/scripts/tests/storage.lua +++ b/scripts/tests/storage.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.storage", package.seeall, lunit.testcase) +local tcname = 'tests.shared.storage' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/scripts/tests/study.lua b/scripts/tests/study.lua index 32638ba90..51065b12a 100644 --- a/scripts/tests/study.lua +++ b/scripts/tests/study.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.eressea.study", package.seeall, lunit.testcase) +local tcname = 'tests.study' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() conf = [[{ diff --git a/scripts/tests/undead.lua b/scripts/tests/undead.lua index a3c541afa..43d910c9f 100644 --- a/scripts/tests/undead.lua +++ b/scripts/tests/undead.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.undead", package.seeall, lunit.testcase) +local tcname = 'tests.shared.undead' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/scripts/tests/xmas.lua b/scripts/tests/xmas.lua index 8ae85fc76..58400aa9f 100644 --- a/scripts/tests/xmas.lua +++ b/scripts/tests/xmas.lua @@ -1,6 +1,10 @@ -require "lunit" - -module("tests.xmas", package.seeall, lunit.testcase ) +local tcname = 'tests.shared.xmas' +local lunit = require('lunit') +if _VERSION >= 'Lua 5.2' then + _ENV = module(tcname, 'seeall') +else + module(tcname, lunit.testcase, package.seeall) +end function setup() eressea.free_game() diff --git a/src/battle.c b/src/battle.c index 6a89a7a6e..8c1627d97 100644 --- a/src/battle.c +++ b/src/battle.c @@ -300,15 +300,16 @@ fighter *select_corpse(battle * b, fighter * af) /* Geflohene haben auch 0 hp, duerfen hier aber nicht ausgewaehlt * werden! */ int dead = dead_fighters(df); - if (!playerrace(u_race(df->unit))) - continue; - - if (af && !helping(af->side, df->side)) - continue; - if (di < dead) { - return df; + const race *rc = u_race(df->unit); + /* Untote sinc für immer tot */ + if (!undeadrace(rc)) { + if (af && !helping(af->side, df->side)) + continue; + if (di < dead) { + return df; + } + di -= dead; } - di -= dead; } } } @@ -2076,9 +2077,6 @@ static void make_heroes(battle * b) unit *u = fig->unit; if (fval(u, UFL_HERO)) { int i; - if (!playerrace(u_race(u))) { - log_error("Hero %s is a %s.\n", unitname(u), u_race(u)->_name); - } for (i = 0; i != u->number; ++i) { fig->person[i].speed += (rule_hero_speed - 1); } @@ -2609,11 +2607,12 @@ static void aftermath(battle * b) for (df = s->fighters; df; df = df->next) { unit *du = df->unit; int dead = dead_fighters(df); + const race *rc = u_race(du); /* tote insgesamt: */ s->dead += dead; /* Tote, die wiederbelebt werde koennen: */ - if (playerrace(u_race(df->unit))) { + if (!undeadrace(rc)) { s->casualties += dead; } if (df->hits + df->kills) { @@ -2640,6 +2639,7 @@ static void aftermath(battle * b) for (df = s->fighters; df; df = df->next) { unit *du = df->unit; + const race *rc = u_race(du); int dead = dead_fighters(df); int sum_hp = 0; int n; @@ -2732,7 +2732,7 @@ static void aftermath(battle * b) } s->flee += df->run.number; - if (playerrace(u_race(du))) { + if (!undeadrace(rc)) { /* tote im kampf werden zu regionsuntoten: * for each of them, a peasant will die as well */ dead_players += dead; @@ -3102,7 +3102,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) } else { building *bld = u->building; - if (bld && bld->sizeleft >= u->number && playerrace(u_race(u))) { + if (bld && bld->sizeleft >= u->number && humanoidrace(u_race(u))) { fig->building = bld; fig->building->sizeleft -= u->number; } diff --git a/src/chaos.c b/src/chaos.c index 8b474cb24..d866c626f 100644 --- a/src/chaos.c +++ b/src/chaos.c @@ -83,7 +83,7 @@ static void chaos(region * r) case 0: /* Untote */ if (!(r->terrain->flags & SEA_REGION)) { unit *u = random_unit(r); - if (u && playerrace(u_race(u))) { + if (u && !undeadrace(u_race(u))) { if (join_monsters(u)) { ADDMSG(&u->faction->msgs, msg_message("chaos_disease", "unit", u)); u_setrace(u, get_race(RC_GHOUL)); diff --git a/src/creport.c b/src/creport.c index e49a96448..04a675e9c 100644 --- a/src/creport.c +++ b/src/creport.c @@ -724,6 +724,7 @@ static void cr_output_spells(stream *out, const unit * u, int maxlevel) void cr_output_unit(stream *out, const faction * f, const unit * u, seen_mode mode) { + const struct locale *lang = crtag_locale(); /* Race attributes are always plural and item attributes always * singular */ const char *str; @@ -736,7 +737,6 @@ void cr_output_unit(stream *out, const faction * f, const faction *fother; const char *prefix; bool allied; - const struct locale *lang = f->locale; assert(u && u->number); @@ -796,17 +796,16 @@ void cr_output_unit(stream *out, const faction * f, pzTmp = get_racename(u->attribs); if (pzTmp) { - const char *pzRace = locale_string(lang, mkname("race", pzTmp), false); - if (pzRace) { - pzTmp = pzRace; + const char *pzRace = pzTmp; + const struct race *rc = rc_find(pzTmp); + if (rc) { + pzRace = rc_name_s(rc, NAME_PLURAL); } - pzRace = translate(pzTmp, locale_string(lang, pzTmp, false)); - if (!pzRace) { - pzRace = pzTmp; - } - stream_printf(out, "\"%s\";Typ\n", pzRace); - if (u->faction == f && fval(u_race(u), RCF_SHAPESHIFTANY)) { - pzRace = rc_name_s(u_race(u), NAME_PLURAL); + pzTmp = translate(pzRace, locale_string(lang, pzRace, false)); + stream_printf(out, "\"%s\";Typ\n", pzTmp); + rc = u_race(u); + if (u->faction == f && fval(rc, RCF_SHAPESHIFTANY)) { + pzRace = rc_name_s(rc, NAME_PLURAL); stream_printf(out, "\"%s\";wahrerTyp\n", pzRace); } } @@ -1514,7 +1513,7 @@ static void report_itemtype(FILE *F, faction *f, const item_type *itype) { static int report_computer(const char *filename, report_context * ctx, const char *bom) { - static int era = -1; + const struct locale *lang = crtag_locale(); int i; faction *f = ctx->f; const char *prefix, *str; @@ -1524,6 +1523,7 @@ report_computer(const char *filename, report_context * ctx, const char *bom) FILE *F = fopen(filename, "w"); static const race *rc_human; static int rc_cache; + static int era = -1; if (era < 0) { era = config_get_int("game.era", 1); @@ -1578,13 +1578,13 @@ report_computer(const char *filename, report_context * ctx, const char *bom) } { const char *zRace = rc_name_s(f->race, NAME_PLURAL); - fprintf(F, "\"%s\";Typ\n", translate(zRace, LOC(f->locale, zRace))); + fprintf(F, "\"%s\";Typ\n", translate(zRace, LOC(lang, zRace))); } prefix = get_prefix(f->attribs); if (prefix != NULL) { prefix = mkname("prefix", prefix); fprintf(F, "\"%s\";typprefix\n", - translate(prefix, LOC(f->locale, prefix))); + translate(prefix, LOC(lang, prefix))); } fprintf(F, "%d;Rekrutierungskosten\n", f->race->recruitcost); fprintf(F, "%d;Anzahl Personen\n", f->num_people); @@ -1637,7 +1637,7 @@ report_computer(const char *filename, report_context * ctx, const char *bom) if (prefix != NULL) { prefix = mkname("prefix", prefix); fprintf(F, "\"%s\";typprefix\n", - translate(prefix, LOC(f->locale, prefix))); + translate(prefix, LOC(lang, prefix))); } show_allies_cr(F, f, g); } diff --git a/src/creport.test.c b/src/creport.test.c index b536a7114..53b2e9d93 100644 --- a/src/creport.test.c +++ b/src/creport.test.c @@ -4,6 +4,13 @@ #include "spy.h" #include "travelthru.h" +#include "attributes/racename.h" + +#include "util/keyword.h" +#include +#include +#include + #include #include #include @@ -16,11 +23,6 @@ #include #include -#include "util/keyword.h" -#include -#include -#include - #include #include @@ -222,6 +224,96 @@ static int cr_get_int(stream *strm, const char *match, int def) return def; } +static bool cr_find_string(stream *strm, const char *match, const char *value) +{ + char line[1024]; + size_t len = strlen(match); + + strm->api->rewind(strm->handle); + while (strm->api->readln(strm->handle, line, sizeof(line))==0) { + if (line[0] == '\"') { + const char * pos = strstr(line + 1, match); + if (pos && pos[len] == '\0') { + size_t vlen = strlen(value); + if (value != NULL && strncmp(line + 1, value, vlen) == 0) { + return (line[vlen + 1] == '\"'); + } + return false; + } + } + } + return value == NULL; +} + +static void test_cr_hiderace(CuTest *tc) { + stream strm; + faction *f1, *f2; + region *r; + unit *u; + struct locale * lang; + + test_setup(); + default_locale = test_create_locale(); + locale_setstring(default_locale, "race::elf_p", "Elfen"); + locale_setstring(default_locale, "race::elf", "elf"); + locale_setstring(default_locale, "race::human_p", "Menschen"); + locale_setstring(default_locale, "race::human", "Mensch"); + lang = get_or_create_locale("en"); + locale_setstring(lang, "race::human_p", "humans"); + locale_setstring(lang, "race::human", "human"); + locale_setstring(lang, "race::elf_p", "elves"); + locale_setstring(lang, "race::elf", "elf"); + f1 = test_create_faction(NULL); + f2 = test_create_faction(NULL); + r = test_create_region(0, 0, NULL); + u = test_create_unit(f1, r); + + mstream_init(&strm); + CuAssertPtrEquals(tc, default_locale, (struct locale *)f1->locale); + CuAssertPtrEquals(tc, default_locale, (struct locale *)f2->locale); + cr_output_unit(&strm, f1, u, seen_unit); + CuAssertTrue(tc, cr_find_string(&strm, ";Typ", "Menschen")); + CuAssertTrue(tc, cr_find_string(&strm, ";wahrerTyp", NULL)); + mstream_done(&strm); + mstream_init(&strm); + CuAssertPtrEquals(tc, default_locale, (struct locale *)f1->locale); + CuAssertPtrEquals(tc, default_locale, (struct locale *)f2->locale); + cr_output_unit(&strm, f2, u, seen_unit); + CuAssertTrue(tc, cr_find_string(&strm, ";Typ", "Menschen")); + CuAssertTrue(tc, cr_find_string(&strm, ";wahrerTyp", NULL)); + mstream_done(&strm); + + /* when we use irace, the owner can see the true race */ + f1->locale = lang; + u->irace = test_create_race("elf"); + mstream_init(&strm); + cr_output_unit(&strm, f1, u, seen_unit); + CuAssertTrue(tc, cr_find_string(&strm, ";Typ", "Elfen")); + CuAssertTrue(tc, cr_find_string(&strm, ";wahrerTyp", "Menschen")); + mstream_done(&strm); + mstream_init(&strm); + cr_output_unit(&strm, f2, u, seen_unit); + CuAssertTrue(tc, cr_find_string(&strm, ";Typ", "Elfen")); + CuAssertTrue(tc, cr_find_string(&strm, ";wahrerTyp", NULL)); + mstream_done(&strm); + + /* when we use racename, nobody can tell it's not the real deal */ + u->irace = NULL; + set_racename(&u->attribs, "Zwerge"); + mstream_init(&strm); + cr_output_unit(&strm, f1, u, seen_unit); + CuAssertTrue(tc, cr_find_string(&strm, ";Typ", "Zwerge")); + CuAssertTrue(tc, cr_find_string(&strm, ";wahrerTyp", NULL)); + mstream_done(&strm); + mstream_init(&strm); + cr_output_unit(&strm, f2, u, seen_unit); + CuAssertTrue(tc, cr_find_string(&strm, ";Typ", "Zwerge")); + CuAssertTrue(tc, cr_find_string(&strm, ";wahrerTyp", NULL)); + mstream_done(&strm); + + test_teardown(); +} + static void test_cr_factionstealth(CuTest *tc) { stream strm; faction *f1, *f2; @@ -326,6 +418,7 @@ CuSuite *get_creport_suite(void) SUITE_ADD_TEST(suite, test_cr_unit); SUITE_ADD_TEST(suite, test_cr_resources); SUITE_ADD_TEST(suite, test_cr_mallorn); + SUITE_ADD_TEST(suite, test_cr_hiderace); SUITE_ADD_TEST(suite, test_cr_factionstealth); return suite; } diff --git a/src/give.c b/src/give.c index 8f352ccbb..e1a3cec66 100644 --- a/src/give.c +++ b/src/give.c @@ -385,6 +385,9 @@ message * give_ship(unit *u1, unit *u2, int n, order *ord) } } else { + if (u2->building) { + leave_building(u2); + } if (n < u1->ship->number) { ship * sh = new_ship(u1->ship->type, u1->region, u1->faction->locale); scale_ship(sh, 0); diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 7c46ab798..c17f4662c 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -279,12 +279,10 @@ unit *addplayer(region * r, faction * f) u->hp = unit_max_hp(u) * u->number; fset(u, UFL_ISNEW); if (f->race == get_race(RC_DAEMON)) { - race_t urc; const race *rc; - do { - urc = (race_t)(rng_int() % MAXRACES); - rc = get_race(urc); - } while (rc == NULL || urc == RC_DAEMON || !playerrace(rc)); + int urc = (race_t)(rng_int() % MAX_START_RACE); + if (urc >= RC_DAEMON) ++urc; + rc = get_race(urc); u->irace = rc; } f->lastorders = turn; diff --git a/src/kernel/race.c b/src/kernel/race.c index 23b25c891..66dced6cf 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -48,16 +48,14 @@ int num_races = 0; static int rc_changes = 1; const char *racenames[MAXRACES] = { - "dwarf", "elf", NULL, "goblin", "human", "troll", "demon", "insect", - "halfling", "cat", "aquarian", "orc", "snotling", "undead", NULL, + "dwarf", "elf", "goblin", "human", "troll", "demon", "insect", + "halfling", "cat", "aquarian", "orc", "snotling", "undead", "youngdragon", "dragon", "wyrm", "ent", "catdragon", "dracoid", - NULL, NULL, "irongolem", "stonegolem", "shadowdemon", + "irongolem", "stonegolem", "shadowdemon", "shadowmaster", "mountainguard", "alp", "toad", "braineater", "peasant", - "wolf", NULL, NULL, NULL, NULL, "songdragon", NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, "seaserpent", - "shadowknight", NULL, "skeleton", "skeletonlord", "zombie", - "juju", "ghoul", "ghast", NULL, NULL, "template", + "wolf", "songdragon", "seaserpent", + "shadowknight", "skeleton", "skeletonlord", "zombie", + "juju", "ghoul", "ghast", "template", "clone" }; diff --git a/src/kernel/race.h b/src/kernel/race.h index 4cc07564e..4cd7fd3b7 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -35,7 +35,7 @@ extern "C" { typedef enum { RC_DWARF, /* 0 - Zwerg */ RC_ELF, - RC_GOBLIN = 3, + RC_GOBLIN, RC_HUMAN, RC_TROLL, RC_DAEMON, @@ -44,17 +44,19 @@ extern "C" { RC_CAT, RC_AQUARIAN, RC_ORC, + /* last of the addplayer races */ + RC_SNOTLING, RC_UNDEAD, - RC_FIREDRAGON = 15, + RC_FIREDRAGON, RC_DRAGON, RC_WYRM, RC_TREEMAN, RC_BIRTHDAYDRAGON, RC_DRACOID, - RC_IRONGOLEM = 23, + RC_IRONGOLEM, RC_STONEGOLEM, RC_SHADOW, RC_SHADOWLORD, @@ -63,25 +65,27 @@ extern "C" { RC_TOAD, RC_HIRNTOETER, RC_PEASANT, - RC_WOLF = 32, + RC_WOLF, - RC_SONGDRAGON = 37, + RC_SONGDRAGON, - RC_SEASERPENT = 51, + RC_SEASERPENT, RC_SHADOWKNIGHT, - RC_SKELETON = 54, + RC_SKELETON, RC_SKELETON_LORD, RC_ZOMBIE, RC_ZOMBIE_LORD, RC_GHOUL, RC_GHOUL_LORD, - RC_TEMPLATE = 62, + RC_TEMPLATE, RC_CLONE, MAXRACES, NORACE = -1 } race_t; +#define MAX_START_RACE RC_ORC + extern int num_races; extern const char *racenames[MAXRACES]; @@ -241,6 +245,7 @@ extern "C" { #define playerrace(rc) ((rc)->flags & RCF_PLAYABLE) #define dragonrace(rc) ((rc)->flags & RCF_DRAGON) #define humanoidrace(rc) (((rc)->flags & RCF_UNDEAD) || (rc)==get_race(RC_DRACOID) || playerrace(rc)) +#define undeadrace(rc) (((rc)->flags & RCF_UNDEAD) || (rc)==get_race(RC_DRACOID)) #define illusionaryrace(rc) ((rc)->flags & RCF_ILLUSIONARY) bool allowed_dragon(const struct region *src, diff --git a/src/kernel/save.c b/src/kernel/save.c index a65dda7e1..66eb22471 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -376,7 +376,7 @@ unit *read_unit(gamedata *data) { unit *u; const race *rc; - int number, n, p; + int number, n, p, bn, sn; order **orderp; char obuf[DISPLAYSIZE]; faction *f; @@ -443,9 +443,10 @@ unit *read_unit(gamedata *data) else u->irace = NULL; - READ_INT(data->store, &n); - if (n > 0) { - building * b = findbuilding(n); + READ_INT(data->store, &bn); + READ_INT(data->store, &sn); + if (sn <= 0 && bn > 0) { + building * b = findbuilding(bn); if (b) { u_set_building(u, b); if (fval(u, UFL_OWNER)) { @@ -453,13 +454,12 @@ unit *read_unit(gamedata *data) } } else { - log_error("read_unit: unit in unkown building '%s'", itoa36(n)); + log_error("read_unit: unit in unkown building '%s'", itoa36(bn)); } } - READ_INT(data->store, &n); - if (n > 0) { - ship * sh = findship(n); + if (sn > 0) { + ship * sh = findship(sn); if (sh) { u_set_ship(u, sh); if (fval(u, UFL_OWNER)) { @@ -467,7 +467,7 @@ unit *read_unit(gamedata *data) } } else { - log_error("read_unit: unit in unkown ship '%s'", itoa36(n)); + log_error("read_unit: unit in unkown ship '%s'", itoa36(sn)); } } diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 0e22e8d2d..6b4cbe2b0 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -635,7 +635,7 @@ void leave_ship(unit * u) { struct ship *sh = u->ship; - u->ship = 0; + u->ship = NULL; if (sh->_owner == u) { ship_update_owner(sh); sh->_owner = ship_owner(sh); diff --git a/src/laws.c b/src/laws.c index fc1c8dc88..01aa4be8d 100644 --- a/src/laws.c +++ b/src/laws.c @@ -684,7 +684,7 @@ growing_trees(region * r, const season_t current_season, const season_t last_wee a->data.sa[0] = (short)cap_int(rtrees(r, 0), 0, SHRT_MAX); a->data.sa[1] = (short)cap_int(rtrees(r, 1), 0, SHRT_MAX); } - else if (a->data.sa[0] < 0 || a->data.sa[1] << 0) { + else if (a->data.sa[0] < 0 || a->data.sa[1] < 0) { a->data.sa[0] = (short)cap_int(a->data.sa[0], 0, SHRT_MAX); a->data.sa[1] = (short)cap_int(a->data.sa[1], 0, SHRT_MAX); } diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index dea37345b..2328997c3 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -1399,7 +1399,7 @@ static int heal_fighters(selist * fgs, int *power, bool heal_monsters) continue; /* wir heilen erstmal keine Monster */ - if (heal_monsters || playerrace(u_race(df->unit))) { + if (heal_monsters || !undeadrace(u_race(df->unit))) { int n, hp = df->unit->hp / df->unit->number; int rest = df->unit->hp % df->unit->number;