forked from github/server
Merge branch 'master' of github.com:eressea/server
Conflicts: scripts/eressea/init.lua
This commit is contained in:
commit
b839fcc5c9
|
@ -1,9 +1,4 @@
|
|||
if config.paths ~= nil then
|
||||
for path in string.gmatch(config.paths, "([^:]+)") do
|
||||
package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua'
|
||||
end
|
||||
end
|
||||
|
||||
require 'eressea.path'
|
||||
require 'eressea.resources'
|
||||
require 'eressea.spells'
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
if config.paths ~= nil then
|
||||
for path in string.gmatch(config.paths, "([^:]+)") do
|
||||
package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua'
|
||||
end
|
||||
end
|
||||
print(package.path)
|
|
@ -7,7 +7,7 @@ end
|
|||
package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua'
|
||||
|
||||
require 'eressea'
|
||||
require 'eressea.tests'
|
||||
require 'eressea.path'
|
||||
require 'tests'
|
||||
require 'lunit'
|
||||
read_xml()
|
||||
lunit.main()
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
module ('tests.eressea.faction', package.seeall, lunit.testcase)
|
||||
|
||||
local f
|
||||
|
||||
function setup()
|
||||
conf = [[{
|
||||
"races": {
|
||||
"human" : {}
|
||||
}
|
||||
}]]
|
||||
eressea.config.reset()
|
||||
assert(eressea.config.parse(conf)==0)
|
||||
f = faction.create("faction@eressea.de", "human", "de")
|
||||
end
|
||||
|
||||
function test_faction_flags()
|
||||
assert_equal(0, f.flags)
|
||||
f.flags = 42
|
||||
assert_equal(42, f.flags)
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
-- new tests 2014-06-11
|
||||
require 'tests.pool'
|
||||
require 'tests.settings'
|
||||
require 'tests.config'
|
||||
require 'tests.faction'
|
||||
require 'tests.locale'
|
||||
require 'tests.regions'
|
||||
require 'tests.study'
|
||||
require 'tests.movement'
|
||||
|
||||
-- require 'tests.bugs'
|
||||
-- require 'tests.building'
|
||||
-- require 'tests.castles'
|
||||
-- require 'tests.spells'
|
||||
-- require 'tests.ships'
|
|
@ -0,0 +1,17 @@
|
|||
require "lunit"
|
||||
|
||||
module("tests.eressea.locale", package.seeall, lunit.testcase )
|
||||
|
||||
function setup()
|
||||
eressea.free_game()
|
||||
end
|
||||
|
||||
function test_get_set()
|
||||
local loc = "en"
|
||||
assert_not_nil(eressea.locale)
|
||||
eressea.locale.create(loc)
|
||||
assert_equal(nil, eressea.locale.get(loc, "move"))
|
||||
eressea.locale.set(loc, "move", "MOVE")
|
||||
assert_equal("MOVE", eressea.locale.get(loc, "move"))
|
||||
end
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
require "lunit"
|
||||
|
||||
module("tests.movement", package.seeall, lunit.testcase)
|
||||
|
||||
function setup()
|
||||
eressea.free_game()
|
||||
eressea.settings.set("nmr.removenewbie", "0")
|
||||
eressea.settings.set("nmr.timeout", "0")
|
||||
eressea.settings.set("rules.ships.storms", "0")
|
||||
conf = [[{
|
||||
"races": {
|
||||
"human" : {
|
||||
"speed" : 1,
|
||||
"weight" : 1000,
|
||||
"capacity" : 1500,
|
||||
"flags" : [ "walk" ]
|
||||
},
|
||||
"troll" : {}
|
||||
},
|
||||
"items" : {
|
||||
"horse" : {
|
||||
"capacity" : 7000,
|
||||
"weight" : 5000,
|
||||
"flags" : [ "big", "animal" ]
|
||||
}
|
||||
},
|
||||
"terrains" : {
|
||||
"ocean": { "flags" : [ "sea", "sail" ] },
|
||||
"plain": { "flags" : [ "land", "walk", "sail" ] },
|
||||
"glacier": { "flags" : [ "land", "walk" ] }
|
||||
},
|
||||
"directions" : {
|
||||
"de" : {
|
||||
"east" : "OSTEN",
|
||||
"west" : "WESTEN"
|
||||
}
|
||||
},
|
||||
"keywords" : {
|
||||
"de" : {
|
||||
"move" : "NACH"
|
||||
}
|
||||
}
|
||||
}]]
|
||||
|
||||
eressea.config.reset()
|
||||
eressea.config.parse(conf)
|
||||
end
|
||||
|
||||
function test_walk_to_land()
|
||||
local r1 = region.create(0, 0, "plain")
|
||||
local r2 = region.create(1, 0, "plain")
|
||||
local f = faction.create("walk@example.com", "human", "de")
|
||||
local u = unit.create(f, r1, 1)
|
||||
u:add_order("NACH O")
|
||||
process_orders()
|
||||
assert_equal(r2, u.region)
|
||||
end
|
||||
|
||||
function test_walk_into_ocean_fails()
|
||||
local r1 = region.create(0, 0, "plain")
|
||||
local r2 = region.create(1, 0, "ocean")
|
||||
local f = faction.create("test@example.com", "human", "de")
|
||||
local u = unit.create(f, r1, 1)
|
||||
u:add_order("NACH O")
|
||||
process_orders()
|
||||
assert_equal(r1, u.region)
|
||||
end
|
||||
|
||||
function test_walk_distance()
|
||||
local r1 = region.create(0, 0, "plain")
|
||||
local r2 = region.create(1, 0, "plain")
|
||||
region.create(2, 0, "plain")
|
||||
local f = faction.create("test@example.com", "human", "de")
|
||||
local u = unit.create(f, r1, 1)
|
||||
u:add_order("NACH O O")
|
||||
process_orders()
|
||||
assert_equal(r2, u.region)
|
||||
end
|
||||
|
||||
function test_ride_max_distance()
|
||||
local r1 = region.create(0, 0, "plain")
|
||||
local r2 = region.create(2, 0, "plain")
|
||||
region.create(1, 0, "plain")
|
||||
region.create(3, 0, "plain")
|
||||
local f = faction.create("test@example.com", "human", "de")
|
||||
local u = unit.create(f, r1, 1)
|
||||
u:add_item("horse", 1)
|
||||
u:set_skill("riding", 2)
|
||||
u:add_order("NACH O O O")
|
||||
process_orders()
|
||||
assert_equal(r2, u.region, "should ride exactly two hexes")
|
||||
end
|
||||
|
||||
function test_ride_over_capacity_leads_horse()
|
||||
local r1 = region.create(0, 0, "plain")
|
||||
local r2 = region.create(1, 0, "plain")
|
||||
region.create(2, 0, "plain")
|
||||
local f = faction.create("test@example.com", "human", "de")
|
||||
local u = unit.create(f, r1, 3)
|
||||
u:add_item("horse", 1)
|
||||
u:set_skill("riding", 2)
|
||||
u:add_order("NACH O O")
|
||||
process_orders()
|
||||
assert_equal(r2, u.region)
|
||||
end
|
||||
|
||||
function test_ride_no_skill_leads_horse()
|
||||
local r1 = region.create(0, 0, "plain")
|
||||
local r2 = region.create(1, 0, "plain")
|
||||
region.create(2, 0, "plain")
|
||||
local f = faction.create("test@example.com", "human", "de")
|
||||
local u = unit.create(f, r1, 1)
|
||||
u:add_item("horse", 1)
|
||||
u:add_order("NACH O O")
|
||||
process_orders()
|
||||
assert_equal(r2, u.region)
|
||||
end
|
|
@ -0,0 +1,75 @@
|
|||
require "lunit"
|
||||
|
||||
module("tests.eressea.pool", package.seeall, lunit.testcase )
|
||||
|
||||
function setup()
|
||||
eressea.game.reset()
|
||||
eressea.config.reset();
|
||||
eressea.settings.set("rules.economy.food", "0")
|
||||
eressea.settings.set("nmr.removenewbie", "0")
|
||||
eressea.settings.set("nmr.timeout", "0")
|
||||
eressea.settings.set("rules.magic.playerschools", "")
|
||||
conf = [[{
|
||||
"races": {
|
||||
"human" : { "flags" : [ "giveitem", "getitem" ] }
|
||||
},
|
||||
"terrains" : {
|
||||
"plain": { "flags" : [ "land" ] }
|
||||
},
|
||||
"keywords" : {
|
||||
"de" : {
|
||||
"give" : "GIB",
|
||||
"contact" : "KONTAKTIERE"
|
||||
}
|
||||
},
|
||||
"strings" : {
|
||||
"de" : {
|
||||
"money" : "Silber"
|
||||
}
|
||||
}
|
||||
}]]
|
||||
|
||||
assert(eressea.config.parse(conf)==0)
|
||||
end
|
||||
|
||||
function test_give_nopool()
|
||||
local r = region.create(1, 1, "plain")
|
||||
local f = faction.create("test@example.com", "human", "de")
|
||||
local u1 = unit.create(f, r, 1)
|
||||
local u2 = unit.create(f, r, 1)
|
||||
u1:add_item("money", 100)
|
||||
u1:add_order("GIB " .. itoa36(u2.id) .. " 50 SILBER")
|
||||
process_orders()
|
||||
assert_equal(50, u1:get_item("money"))
|
||||
assert_equal(50, u2:get_item("money"))
|
||||
end
|
||||
|
||||
function test_give_from_faction()
|
||||
local r = region.create(1, 1, "plain")
|
||||
local f = faction.create("test@example.com", "human", "de")
|
||||
local u1 = unit.create(f, r, 1)
|
||||
local u2 = unit.create(f, r, 1)
|
||||
local u3 = unit.create(f, r, 1)
|
||||
u1:add_item("money", 50)
|
||||
u2:add_item("money", 50)
|
||||
u1:add_order("GIB " .. itoa36(u3.id) .. " 100 SILBER")
|
||||
process_orders()
|
||||
assert_equal(0, u1:get_item("money"))
|
||||
assert_equal(0, u2:get_item("money"))
|
||||
assert_equal(100, u3:get_item("money"))
|
||||
end
|
||||
|
||||
function test_give_divisor()
|
||||
eressea.settings.set("rules.items.give_divisor", 2)
|
||||
local r = region.create(1, 1, "plain")
|
||||
local f1 = faction.create("test@example.com", "human", "de")
|
||||
local f2 = faction.create("test@example.com", "human", "de")
|
||||
local u1 = unit.create(f1, r, 1)
|
||||
local u2 = unit.create(f2, r, 1)
|
||||
u2:add_order("KONTAKTIERE " .. itoa36(u1.id))
|
||||
u1:add_item("money", 100)
|
||||
u1:add_order("GIB " .. itoa36(u2.id) .. " 100 SILBER")
|
||||
process_orders()
|
||||
assert_equal(0, u1:get_item("money"))
|
||||
assert_equal(50, u2:get_item("money"))
|
||||
end
|
|
@ -0,0 +1,22 @@
|
|||
require "lunit"
|
||||
|
||||
module("tests.regions", package.seeall, lunit.testcase)
|
||||
|
||||
function setup()
|
||||
eressea.game.reset()
|
||||
conf = [[{
|
||||
"terrains" : {
|
||||
"ocean": {},
|
||||
"plain": {}
|
||||
}
|
||||
}]]
|
||||
eressea.config.reset()
|
||||
eressea.settings.set('rules.magic.playerschools', '')
|
||||
eressea.config.parse(conf)
|
||||
end
|
||||
|
||||
function test_create()
|
||||
local r
|
||||
r = region.create(0, 0, "ocean")
|
||||
assert_not_nil(r)
|
||||
end
|
|
@ -1,13 +1,13 @@
|
|||
require "lunit"
|
||||
require 'lunit'
|
||||
|
||||
module("tests.eressea.settings", package.seeall, lunit.testcase )
|
||||
module('tests.eressea.settings', package.seeall, lunit.testcase )
|
||||
|
||||
function setup()
|
||||
eressea.free_game()
|
||||
end
|
||||
|
||||
function test_settings()
|
||||
assert_equal(nil, eressea.settings.get("foo"))
|
||||
eressea.settings.set("foo", "bar")
|
||||
assert_equal("bar", eressea.settings.get("foo"))
|
||||
assert_equal(nil, eressea.settings.get('foo'))
|
||||
eressea.settings.set('foo', 'bar')
|
||||
assert_equal('bar', eressea.settings.get('foo'))
|
||||
end
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
require "lunit"
|
||||
|
||||
module("tests.eressea.study", package.seeall, lunit.testcase)
|
||||
|
||||
function setup()
|
||||
conf = [[{
|
||||
"races" : { "human" : {} },
|
||||
"terrains" : { "plain" : { "flags" : [ "land" ] } },
|
||||
"keywords" : { "de" : { "study": "LERNEN" } },
|
||||
"skills" : { "de": { "alchemy" : "Alchemie", "crossbow" : "Armbrust" } }
|
||||
}]]
|
||||
eressea.game.reset()
|
||||
eressea.config.reset();
|
||||
eressea.settings.set('rules.magic.playerschools', '')
|
||||
eressea.config.parse(conf)
|
||||
end
|
||||
|
||||
function test_study()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f = faction.create("test@example.com", "human", "de")
|
||||
local u = unit.create(f, r, 1)
|
||||
u:add_order("LERNEN Armbrust")
|
||||
process_orders()
|
||||
assert_equal(1, u:get_skill("crossbow"))
|
||||
end
|
||||
|
||||
function test_study_expensive()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f = faction.create("test@example.com", "human", "de")
|
||||
local u = unit.create(f, r, 1)
|
||||
eressea.settings.set("skills.cost.alchemy", "50")
|
||||
eressea.settings.set("rules.encounters", "0")
|
||||
u:add_order("LERNEN Alchemie")
|
||||
u:add_item("money", 50)
|
||||
process_orders()
|
||||
assert_equal(1, u:get_skill("alchemy"))
|
||||
assert_equal(0, u:get_item("money"))
|
||||
end
|
|
@ -146,26 +146,14 @@ void free_races(void) {
|
|||
}
|
||||
}
|
||||
|
||||
static const char *racealias[][2] = {
|
||||
{"uruk", "orc"}, /* there was a time when the orc race was called uruk (and there were other orcs). That was really confusing */
|
||||
{"skeletton lord", "skeleton lord"}, /* we once had a typo here. it is fixed */
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
static race *rc_find_i(const char *name)
|
||||
{
|
||||
const char *rname = name;
|
||||
race *rc = races;
|
||||
int i;
|
||||
|
||||
for (i = 0; racealias[i][0]; ++i) {
|
||||
if (strcmp(racealias[i][0], name) == 0) {
|
||||
rname = racealias[i][1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (rc && !strcmp(rname, rc->_name[0]) == 0)
|
||||
while (rc && !strcmp(rname, rc->_name[0]) == 0) {
|
||||
rc = rc->next;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue