forked from github/server
building naming function configured from JSON (this needs work).
started writing tests for castles.
This commit is contained in:
parent
ba53c90b9c
commit
a48cca5db8
|
@ -133,6 +133,14 @@ void json_building(cJSON *json, building_type *bt) {
|
|||
json_construction(child, &bt->construction);
|
||||
}
|
||||
break;
|
||||
case cJSON_String:
|
||||
if (strcmp(child->string, "name")==0) {
|
||||
bt->name = (const char *(*)(const struct building_type *,
|
||||
const struct building *, int))get_function(child->valuestring);
|
||||
break;
|
||||
}
|
||||
log_error_n("building %s contains unknown attribute %s", json->string, child->string);
|
||||
break;
|
||||
default:
|
||||
log_error_n("building %s contains unknown attribute %s", json->string, child->string);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
require "lunit"
|
||||
|
||||
module("tests.castles", package.seeall, lunit.testcase )
|
||||
|
||||
function setup()
|
||||
eressea.game.reset()
|
||||
eressea.config.reset()
|
||||
eressea.settings.set("nmr.removenewbie", "0")
|
||||
eressea.settings.set("nmr.timeout", "0")
|
||||
eressea.settings.set("rules.ships.storms", "0")
|
||||
conf = [[{
|
||||
"races": {
|
||||
"human" : {},
|
||||
"halfling" : {}
|
||||
},
|
||||
"buildings" : {
|
||||
"castle" : {
|
||||
"name" : "castle_name",
|
||||
"construction" : [
|
||||
{ "maxsize" : 2 },
|
||||
{ "maxsize" : 10 },
|
||||
{ "maxsize" : 50 },
|
||||
{ "maxsize" : 250 }
|
||||
]
|
||||
}
|
||||
},
|
||||
"terrains" : {
|
||||
"plain": { "flags" : [ "land" ] }
|
||||
},
|
||||
"keywords" : {
|
||||
"de" : {
|
||||
"make" : "MACHEN"
|
||||
}
|
||||
}
|
||||
}]]
|
||||
assert(eressea.config.parse(conf)==0)
|
||||
end
|
||||
|
||||
function disable_test_small_castles()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f1 = faction.create("test@eressea.de", "human", "de")
|
||||
local u1 = unit.create(f1, r, 1)
|
||||
local f2 = faction.create("test@eressea.de", "halfling", "de")
|
||||
local u2 = unit.create(f2, r, 1)
|
||||
u1:add_item("money", 10000)
|
||||
|
||||
local b = building.create(r, "castle")
|
||||
u2.building = b
|
||||
u1.building = b
|
||||
|
||||
b.owner = u2
|
||||
assert_equal("site", b:get_typename(7))
|
||||
assert_equal("fortification", b:get_typename(8))
|
||||
b.owner = u1
|
||||
assert_equal("site", b:get_typename(9))
|
||||
assert_equal("fortification", b:get_typename(10))
|
||||
end
|
|
@ -3,6 +3,7 @@ require "tests.settings"
|
|||
require "tests.config"
|
||||
require "tests.locale"
|
||||
require "tests.regions"
|
||||
require "tests.castles"
|
||||
require "tests.ships"
|
||||
require "tests.study"
|
||||
require "tests.movement"
|
||||
|
|
Loading…
Reference in New Issue