Merge pull request #292 from ennorehling/feature/json-config-param

move configuration parameters from XML to JSON
This commit is contained in:
Enno Rehling 2015-09-11 11:10:06 +02:00
commit 47b7b67d20
36 changed files with 320 additions and 276 deletions

2
.gitignore vendored
View File

@ -41,3 +41,5 @@ Thumbs.db
*.cmd
tmp/
tests/config.lua
tests/reports/
tests/data/185.dat

View File

@ -1,5 +1,34 @@
{
"include": [
"keywords.json"
]
],
"settings": {
"game.id": 2,
"game.name": "Eressea",
"NewbieImmunity": 8,
"modules.wormholes": true,
"entertain.base": 0,
"entertain.perlevel": 20,
"nmr.timeout": 5,
"nmr.removenewbie": 0,
"GiveRestriction": 3,
"hunger.long": true,
"init_spells": 0,
"world.era": 2,
"seed.population.min": 8,
"seed.population.max": 8,
"rules.ship.damage_drift": 0.00,
"rules.reserve.twophase": true,
"rules.give.max_men": -1,
"rules.check_overload": false,
"rules.limit.faction": 2500,
"rules.maxskills.magic": 5,
"rules.guard.base_stop_prob": 0.30,
"rules.guard.skill_stop_prob": 0.05,
"rules.guard.amulet_stop_prob": 0.10,
"rules.guard.guard_number_stop_prob": 0.001,
"rules.guard.castle_stop_prob": 0.05,
"rules.guard.region_type_stop_prob": 0.05,
"rules.economy.repopulate_maximum": 500
}
}

View File

@ -90,32 +90,6 @@
<skill name="taxation" enable="true"/>
<skill name="stamina" enable="true"/>
<skill name="unarmed" enable="true"/>
<param name="NewbieImmunity" value="8"/>
<param name="modules.wormholes" value="1"/>
<param name="entertain.base" value="0"/>
<param name="entertain.perlevel" value="20"/>
<param name="nmr.timeout" value="5"/>
<param name="nmr.removenewbie" value="0"/>
<param name="GiveRestriction" value="3"/>
<param name="hunger.long" value="1"/>
<param name="init_spells" value="0"/>
<param name="rules.ship.damage_drift" value="0.00"/> <!-- percent damage from drifting-->
<param name="rules.reserve.twophase" value="1"/>
<param name="rules.give.max_men" value="-1"/>
<param name="rules.check_overload" value="0"/>
<param name="rules.limit.faction" value="2500"/>
<param name="rules.maxskills.magic" value="5"/>
<param name="rules.guard.base_stop_prob" value="0.30"/>
<param name="rules.guard.skill_stop_prob" value="0.05"/>
<param name="rules.guard.amulet_stop_prob" value="0.10"/>
<param name="rules.guard.guard_number_stop_prob" value="0.001"/>
<param name="rules.guard.castle_stop_prob" value="0.05"/>
<param name="rules.guard.region_type_stop_prob" value="0.05"/>
<param name="rules.economy.repopulate_maximum" value="500"/>
<param name="game.id" value="2"/>
<param name="game.name" value="Eressea"/>
<param name="world.era" value="2"/>
</game>
<strings>
<string name="mailto">

View File

@ -1,5 +1,76 @@
{
"include": [
"keywords.json"
]
],
"settings": {
"game.id": 3,
"game.name": "E3",
"database.gameid": 7,
"NewbieImmunity": 4,
"modules.astralspace": false,
"modules.wormholes": false,
"modules.markets": true,
"magic.regeneration": 0.75,
"magic.power": 0.5,
"resource.factor": 0.25,
"skills.cost.tactics": 500,
"entertain.base": 0,
"entertain.perlevel": 20,
"nmr.timeout": 5,
"nmr.removenewbie": 0,
"GiveRestriction": 3,
"hunger.long": false,
"hunger.demon.skill": true,
"hunger.damage": "1d9+9",
"hunger.demons": true,
"init_spells": 0,
"recruit.allow_merge": true,
"study.expensivemigrants": true,
"study.speedup": 2,
"world.era": 3,
"seed.population.min": 8,
"seed.population.max": 8,
"rules.migrants.max": 0,
"rules.reserve.twophase": true,
"rules.owners.force_leave": false,
"rules.monsters.attack_chance": 0.0,
"rules.transfermen": false,
"rules.stealth.faction": true,
"rules.stealth.anon_battle": false,
"rules.check_overload": false,
"rules.combat.goblinbonus": 3,
"rules.ship.damage_drift": 0.00,
"rules.alliances": true,
"rules.combat.herospeed": 3,
"rules.combat.demon_vampire": 5,
"rules.combat.skill_bonus": 0,
"rules.combat.nat_armor": 1,
"rules.items.loot_divisor": 2,
"rules.items.give_divisor": 2,
"rules.move.owner_leave": true,
"rules.region_owners": true,
"rules.cavalry.skill": 2,
"rules.cavalry.mode": 1,
"rules.magic.multipotion": 1,
"rules.magic.wol_effect": 5,
"rules.magic.factionlist": 1,
"rules.magic.wol_type": 2,
"rules.blessed_harvest.flags": 1,
"rules.magic.elfpower": true,
"rules.magic.playerschools": "gwyrrd illaun draig cerddor",
"rules.build.other_buildings": true,
"rules.economy.taxation": 1,
"rules.food.flags": 2,
"rules.economy.roqf": 5,
"rules.economy.herbrot": 0,
"rules.region_owner_pay_building": "market harbour lighthouse",
"rules.dwarf_castles": true,
"rules.limit.faction": 250,
"rules.grow.formula": 1,
"rules.tactics.formula": 1,
"rules.help.mask": "fight guard money give",
"movement.shipspeed.skillbonus": 6,
"alliance.auto": "fight",
"alliance.restricted": "fight"
}
}

View File

@ -46,8 +46,6 @@
<game name="E3">
<!-- Game specific settings -->
<param name="database.gameid" value="7"></param>
<order name="besiege" disable="yes"/>
<order name="steal" disable="yes"/>
<order name="buy" disable="yes"/>
@ -89,82 +87,6 @@
<skill name="stealth" enable="false"/>
<skill name="taxation" enable="false"/>
<skill name="trade" enable="false"/>
<param name="NewbieImmunity" value="4"/>-
<param name="modules.astralspace" value="0"/>
<param name="modules.wormholes" value="0"/>
<param name="modules.markets" value="1"/>
<!-- resource limitations -->
<param name="magic.regeneration" value="0.75"/>
<param name="magic.power" value="0.5"/>
<param name="resource.factor" value="0.25"/>
<param name="skills.cost.tactics" value="500"/>
<param name="entertain.base" value="0"/>
<param name="entertain.perlevel" value="20"/>
<param name="nmr.timeout" value="5"/>
<param name="nmr.removenewbie" value="0"/>
<param name="GiveRestriction" value="3"/>
<param name="hunger.long" value="0"/>
<param name="hunger.demon.skill" value="1"/>
<param name="hunger.damage" value="1d9+9"/>
<param name="hunger.demons" value="1"/>
<param name="init_spells" value="0"/>
<param name="recruit.allow_merge" value="1"/>
<param name="study.expensivemigrants" value="1"/>
<param name="study.speedup" value="2"/>
<param name="world.era" value="3"/>
<param name="seed.population.min" value="8"/>
<param name="seed.population.max" value="8"/>
<param name="rules.migrants" value="0"/>
<param name="rules.reserve.twophase" value="1"/>
<param name="rules.owners.force_leave" value="0"/>
<param name="rules.monsters.attack_chance" value="0.0"/>
<param name="rules.transfermen" value="0"/>
<param name="rules.stealth.faction" value="1"/>
<param name="rules.stealth.anon_battle" value="0"/>
<param name="rules.check_overload" value="0"/>
<param name="rules.combat.goblinbonus" value="3"/>
<param name="rules.ship.damage_drift" value="0.00"/> <!-- percent damage from drifting-->
<param name="rules.alliances" value="1"/>
<param name="rules.combat.herospeed" value="3"/>
<param name="rules.combat.demon_vampire" value="5"/> <!-- regen 1 hp per X points of damage done -->
<param name="rules.combat.skill_bonus" value="0"/>
<param name="rules.combat.nat_armor" value="1"/>
<!--param name="rules.combat.loot" value="5"/--> <!-- only self + others - keeploot -->
<param name="rules.items.loot_divisor" value="2"/> <!-- damage skims off 1/2 of goods transfers -->
<param name="rules.items.give_divisor" value="2"/> <!-- corruption skims off 1/2 of goods transfers -->
<param name="rules.move.owner_leave" value="1"/> <!-- owner must leave before moving -->
<param name="rules.region_owners" value="1"/>
<param name="rules.cavalry.skill" value="2"/>
<param name="rules.cavalry.mode" value="1"/>
<param name="rules.magic.multipotion" value="1"/>
<param name="rules.magic.wol_effect" value="5"/>
<param name="rules.magic.factionlist" value="1"/>
<param name="rules.magic.wol_type" value="2"/>
<param name="rules.magic.blessed_harvest" value="1"/>
<param name="rules.magic.elfpower" value="1"/> <!-- elves get ring-of-power bonus in a forest -->
<param name="rules.magic.playerschools" value="gwyrrd illaun draig cerddor"/>
<param name="rules.build.other_buildings" value="1"/>
<param name="rules.economy.taxation" value="1"/>
<param name="rules.economy.food" value="2"/>
<param name="rules.economy.wages" value="1"/>
<param name="rules.economy.roqf" value="5"/>
<param name="rules.economy.herbrot" value="0"/>
<param name="rules.region_owner_pay_building" value="market harbour lighthouse"/>
<param name="rules.dwarf_castles" value="1"/>
<!-- param name="rules.nmr.destroy" value="1"/ -->
<param name="rules.limit.faction" value="250"/>
<!--param name="rules.give" value="15"/ --> <!-- self + peasants + herbs + lux - goods -->
<param name="rules.economy.grow" value="1"/>
<param name="rules.tactics.formula" value="1"/> <!-- 10% per skilldiff -->
<param name="rules.help.mask" value="fight guard money give"/>
<param name="movement.shipspeed.skillbonus" value="6"/>
<param name="alliance.auto" value="fight"/>
<param name="alliance.restricted" value="fight"/>
<param name="game.id" value="3"/>
<param name="game.name" value="E3"/>
</game>
<rules>
<function name="wage" value="minimum_wage"/>

View File

@ -1,5 +1,73 @@
{
"include": [
"keywords.json"
]
],
"settings": {
"game.id": 4,
"game.name": "Deveron",
"database.gameid": 7,
"NewbieImmunity": 4,
"modules.astralspace": false,
"modules.wormholes": false,
"modules.markets": true,
"magic.regeneration": 0.75,
"magic.power": 0.5,
"resource.factor": 0.25,
"skills.cost.tactics": 500,
"entertain.base": 0,
"entertain.perlevel": 20,
"nmr.timeout": 5,
"nmr.removenewbie": 0,
"GiveRestriction": 3,
"hunger.long": false,
"hunger.demon.skill": true,
"hunger.damage": "1d9+9",
"hunger.demons": true,
"init_spells": 0,
"recruit.allow_merge": true,
"study.expensivemigrants": true,
"study.speedup": 2,
"world.era": 3,
"rules.migrants.max": 0,
"rules.reserve.twophase": true,
"rules.owners.force_leave": false,
"rules.transfermen": false,
"rules.stealth.faction": true,
"rules.stealth.anon_battle": false,
"rules.check_overload": false,
"rules.combat.goblinbonus": 3,
"rules.ship.damage_drift": 0.00,
"rules.alliances": true,
"rules.combat.herospeed": 3,
"rules.combat.demon_vampire": 5,
"rules.combat.skill_bonus": 0,
"rules.combat.nat_armor": true,
"rules.items.loot_divisor": 2,
"rules.items.give_divisor": 2,
"rules.move.owner_leave": true,
"rules.region_owners": true,
"rules.cavalry.skill": 2,
"rules.cavalry.mode": 1,
"rules.magic.multipotion": true,
"rules.magic.wol_effect": 5,
"rules.magic.factionlist": true,
"rules.magic.wol_type": 2,
"rules.blessed_harvest.flags": 1,
"rules.magic.elfpower": true,
"rules.magic.playerschools": "gwyrrd illaun draig cerddor",
"rules.build.other_buildings": 1,
"rules.economy.taxation": 1,
"rules.food.flags": 2,
"rules.economy.roqf": 5,
"rules.economy.herbrot": 0,
"rules.region_owner_pay_building": "market harbour lighthouse",
"rules.dwarf_castles": true,
"rules.limit.faction": 250,
"rules.grow.formula": 1,
"rules.tactics.formula": 1,
"rules.help.mask": "fight guard money give",
"movement.shipspeed.skillbonus": 6,
"alliance.auto": "fight",
"alliance.restricted": "fight"
}
}

View File

@ -45,9 +45,6 @@
<xi:include href="config://default/names-dragons.xml"/>
<game name="Deveron">
<!-- Game specific settings -->
<param name="database.gameid" value="7"></param>
<order name="besiege" disable="yes"/>
<order name="steal" disable="yes"/>
<order name="buy" disable="yes"/>
@ -89,79 +86,6 @@
<skill name="stealth" enable="false"/>
<skill name="taxation" enable="false"/>
<skill name="trade" enable="false"/>
<param name="NewbieImmunity" value="4"/>
<param name="modules.astralspace" value="0"/>
<param name="modules.wormholes" value="0"/>
<param name="modules.markets" value="1"/>
<!-- resource limitations -->
<param name="magic.regeneration" value="0.75"/>
<param name="magic.power" value="0.5"/>
<param name="resource.factor" value="0.25"/>
<param name="skills.cost.tactics" value="500"/>
<param name="entertain.base" value="0"/>
<param name="entertain.perlevel" value="20"/>
<param name="nmr.timeout" value="5"/>
<param name="nmr.removenewbie" value="0"/>
<param name="GiveRestriction" value="3"/>
<param name="hunger.long" value="0"/>
<param name="hunger.demon.skill" value="1"/>
<param name="hunger.damage" value="1d9+9"/>
<param name="hunger.demons" value="1"/>
<param name="init_spells" value="0"/>
<param name="recruit.allow_merge" value="1"/>
<param name="study.expensivemigrants" value="1"/>
<param name="study.speedup" value="2"/>
<param name="world.era" value="3"/>
<param name="rules.migrants" value="0"/>
<param name="rules.reserve.twophase" value="1"/>
<param name="rules.owners.force_leave" value="0"/>
<param name="rules.transfermen" value="0"/>
<param name="rules.stealth.faction" value="1"/>
<param name="rules.stealth.anon_battle" value="0"/>
<param name="rules.check_overload" value="0"/>
<param name="rules.combat.goblinbonus" value="3"/>
<param name="rules.ship.damage_drift" value="0.00"/> <!-- percent damage from drifting-->
<param name="rules.alliances" value="1"/>
<param name="rules.combat.herospeed" value="3"/>
<param name="rules.combat.demon_vampire" value="5"/> <!-- regen 1 hp per X points of damage done -->
<param name="rules.combat.skill_bonus" value="0"/>
<param name="rules.combat.nat_armor" value="1"/>
<!--param name="rules.combat.loot" value="5"/--> <!-- only self + others - keeploot -->
<param name="rules.items.loot_divisor" value="2"/> <!-- damage skims off 1/2 of goods transfers -->
<param name="rules.items.give_divisor" value="2"/> <!-- corruption skims off 1/2 of goods transfers -->
<param name="rules.move.owner_leave" value="1"/> <!-- owner must leave before moving -->
<param name="rules.region_owners" value="1"/>
<param name="rules.cavalry.skill" value="2"/>
<param name="rules.cavalry.mode" value="1"/>
<param name="rules.magic.multipotion" value="1"/>
<param name="rules.magic.wol_effect" value="5"/>
<param name="rules.magic.factionlist" value="1"/>
<param name="rules.magic.wol_type" value="2"/>
<param name="rules.magic.blessed_harvest" value="1"/>
<param name="rules.magic.elfpower" value="1"/> <!-- elves get ring-of-power bonus in a forest -->
<param name="rules.magic.playerschools" value="gwyrrd illaun draig cerddor"/>
<param name="rules.build.other_buildings" value="1"/>
<param name="rules.economy.taxation" value="1"/>
<param name="rules.economy.food" value="2"/>
<param name="rules.economy.wages" value="1"/>
<param name="rules.economy.roqf" value="5"/>
<param name="rules.economy.herbrot" value="0"/>
<param name="rules.region_owner_pay_building" value="market harbour lighthouse"/>
<param name="rules.dwarf_castles" value="1"/>
<!-- param name="rules.nmr.destroy" value="1"/ -->
<param name="rules.limit.faction" value="250"/>
<!--param name="rules.give" value="15"/ --> <!-- self + peasants + herbs + lux - goods -->
<param name="rules.economy.grow" value="1"/>
<param name="rules.tactics.formula" value="1"/> <!-- 10% per skilldiff -->
<param name="rules.help.mask" value="fight guard money give"/>
<param name="movement.shipspeed.skillbonus" value="6"/>
<param name="alliance.auto" value="fight"/>
<param name="alliance.restricted" value="fight"/>
<param name="game.id" value="4"/>
<param name="game.name" value="Deveron"/>
</game>
<rules>
<function name="wage" value="minimum_wage"/>

View File

@ -28,7 +28,7 @@ function setup()
eressea.free_game()
eressea.settings.set("nmr.timeout", "0")
eressea.settings.set("NewbieImmunity", "0")
eressea.settings.set("rules.economy.food", "4")
eressea.settings.set("rules.food.flags", "4")
eressea.settings.set("rules.encounters", "0")
eressea.settings.set("rules.peasants.growth", "1")
eressea.settings.set("study.random_progress", "0")
@ -45,7 +45,7 @@ function test_flags()
eressea.write_game("test.dat")
eressea.free_game()
eressea.read_game("test.dat")
os.remove('test.dat')
os.remove('data/test.dat')
f = get_faction(no)
assert_equal(flags, f.flags)
end
@ -92,7 +92,7 @@ function test_demon_food()
local u = unit.create(f, r, 1)
local p = r:get_resource("peasant")
r:set_resource("peasant", 2000)
eressea.settings.set("rules.economy.food", "0")
eressea.settings.set("rules.food.flags", "0")
eressea.settings.set("rules.peasants.growth", "0")
process_orders()
assert_not_nil(u)
@ -194,6 +194,7 @@ function test_descriptions()
eressea.write_game(filename)
eressea.free_game()
eressea.read_game(filename)
os.remove("data/test.dat")
assert_equal(info, get_ship(sno).info)
assert_equal(info, get_unit(uno).info)
assert_equal(info, get_faction(fno).info)
@ -459,7 +460,7 @@ function test_work()
end
function test_upkeep()
eressea.settings.set("rules.economy.food", "0")
eressea.settings.set("rules.food.flags", "0")
local r = region.create(0, 0, "plain")
local f = faction.create("noreply10@eressea.de", "human", "de")
local u = unit.create(f, r, 5)
@ -781,7 +782,7 @@ function test_food_is_consumed()
u:add_item("money", 100)
u:clear_orders()
u:add_order("LERNEN Reiten") -- don't work
eressea.settings.set("rules.economy.food", "4")
eressea.settings.set("rules.food.flags", "4")
process_orders()
assert_equal(100, u:get_item("money"))
end
@ -793,7 +794,7 @@ function test_food_can_override()
u:add_item("money", 100)
u:clear_orders()
u:add_order("LERNEN Reiten") -- don't work
eressea.settings.set("rules.economy.food", "0")
eressea.settings.set("rules.food.flags", "0")
process_orders()
assert_equal(90, u:get_item("money"))
end
@ -920,7 +921,7 @@ module("tests.recruit", package.seeall, lunit.testcase)
function setup()
eressea.free_game()
eressea.settings.set("rules.economy.food", "4")
eressea.settings.set("rules.food.flags", "4")
eressea.settings.set("rules.peasants.growth", "0")
end
@ -961,7 +962,7 @@ module("tests.report", package.seeall, lunit.testcase)
function setup()
eressea.free_game()
eressea.settings.set("nmr.timeout", "0")
eressea.settings.set("rules.economy.food", "4")
eressea.settings.set("rules.food.flags", "4")
end
local function find_in_report(f, pattern, extension)
@ -1061,7 +1062,7 @@ module("tests.parser", package.seeall, lunit.testcase)
function setup()
eressea.free_game()
eressea.settings.set("rules.economy.food", "4") -- FOOD_IS_FREE
eressea.settings.set("rules.food.flags", "4") -- FOOD_IS_FREE
eressea.settings.set("rules.encounters", "0")
eressea.settings.set("rules.move.owner_leave", "0")
end
@ -1081,5 +1082,6 @@ function test_parser()
eressea.read_orders(filename)
process_orders()
os.remove(filename)
assert_equal("Goldene Herde", u.name)
end

View File

@ -22,7 +22,7 @@ end
function setup()
eressea.free_game()
eressea.settings.set("nmr.timeout", "0")
eressea.settings.set("rules.economy.food", "4")
eressea.settings.set("rules.food.flags", "4")
eressea.settings.set("rules.ship.storms", "0")
end

View File

@ -6,7 +6,7 @@ function setup()
eressea.free_game()
eressea.settings.set("nmr.timeout", "0")
eressea.settings.set("NewbieImmunity", "0")
eressea.settings.set("rules.economy.food", "4")
eressea.settings.set("rules.food.flags", "4")
end
function test_guard_unarmed()

View File

@ -7,7 +7,7 @@ function setup()
eressea.settings.set("nmr.removenewbie", "0")
eressea.settings.set("nmr.timeout", "0")
eressea.settings.set("NewbieImmunity", "0")
eressea.settings.set("rules.economy.food", "4")
eressea.settings.set("rules.food.flags", "4")
end
function test_shapeshift()

View File

@ -18,7 +18,7 @@ end
function setup()
eressea.game.reset()
set_rule('rules.economy.food', '4')
set_rule('rules.food.flags', '4')
set_rule('rules.magic.playerschools', '')
local r = region.create(0,0, "plain")
@ -28,7 +28,7 @@ function setup()
end
function teardown()
set_rule('rules.economy.food')
set_rule('rules.food.flags')
set_rule('rules.magic.playerschools')
set_rule('rules.stealth.faction')
end

View File

@ -17,14 +17,14 @@ function setup()
eressea.game.reset()
settings = {}
set_rule("rules.move.owner_leave", "1")
set_rule("rules.economy.food", "4")
set_rule("rules.food.flags", "4")
set_rule("rules.ship.drifting", "0")
set_rule("rules.ship.storms", "0")
end
function teardown()
set_rule("rules.move.owner_leave")
set_rule("rules.economy.food")
set_rule("rules.food.flags")
set_rule("rules.ship.drifting")
set_rule("rules.ship.storms")
end
@ -146,6 +146,21 @@ function test_no_stealth()
assert_equal(-1, u:get_skill("stealth"))
end
function test_no_teach()
local r = region.create(0,0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de")
local u1 = unit.create(f, r, 1)
local u2 = unit.create(f, r, 1)
u1:clear_orders()
u2:clear_orders()
u1:set_skill("riding", 3)
u2:add_order("LERNE Reiten")
u1:add_order("LEHRE " .. itoa36(u2.id))
process_orders()
-- TODO: assert something (reflecting skills sucks!)
end
function test_seecast()
local r = region.create(0,0, "plain")
for i = 1,10 do
@ -206,7 +221,7 @@ function test_xmastree()
end
function test_fishing()
eressea.settings.set("rules.economy.food", "0")
eressea.settings.set("rules.food.flags", "0")
local r = region.create(0,0, "ocean")
local r2 = region.create(1,0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de")

View File

@ -8,7 +8,7 @@ function setup()
eressea.free_game()
eressea.settings.set("magic.regeneration.enable", "0")
eressea.settings.set("magic.fumble.enable", "0")
eressea.settings.set("rules.economy.food", "4")
eressea.settings.set("rules.food.flags", "4")
r = region.create(0, 0, "plain")
f = faction.create("spell_payment@eressea.de", "elf", "de")

View File

@ -7,7 +7,7 @@ local u
function setup()
eressea.game.reset()
eressea.settings.set("rules.economy.food", "4")
eressea.settings.set("rules.food.flags", "4")
local r = region.create(0,0, "plain")
f = faction.create("stealth1@eressea.de", "human", "de")

View File

@ -15,7 +15,7 @@ function setup()
f = _G.faction.create("noreply@eressea.de", "human", "de")
u = _G.unit.create(f, r, 1)
u:clear_orders()
eressea.settings.set("rules.economy.food", "4")
eressea.settings.set("rules.food.flags", "4")
eressea.settings.set("nmr.timeout", "0")
eressea.settings.set("NewbieImmunity", "0")
end
@ -104,7 +104,7 @@ function test_process_quit()
eressea.write_game('test.dat')
eressea.free_game()
eressea.read_game('test.dat')
os.remove('test.dat')
os.remove('data/test.dat')
assert_equal(nil, _G.get_faction(fno))
end

View File

@ -5,7 +5,7 @@ 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("rules.food.flags", "0")
eressea.settings.set("nmr.timeout", "0")
eressea.settings.set("rules.magic.playerschools", "")
conf = [[{

View File

@ -26,6 +26,7 @@ function test_store_unit()
assert_not_nil(store)
u = store:read_unit()
store:close()
os.remove(filename)
assert_not_nil(u)
assert_equal(u:get_item("money"), u.number * 100)
end

View File

@ -17,7 +17,7 @@ function setup()
eressea.game.reset()
eressea.config.reset();
eressea.settings.set('rules.magic.playerschools', '')
eressea.settings.set("rules.economy.food", "4")
eressea.settings.set("rules.food.flags", "4")
eressea.settings.set('study.random_progress', '0')
eressea.config.parse(conf)
end

View File

@ -3210,7 +3210,7 @@ side * find_side(battle * b, const faction * f, const group * g, unsigned int fl
if (s->faction == f && s->group == g) {
unsigned int s1flags = flags | SIDE_HASGUARDS;
unsigned int s2flags = s->flags | SIDE_HASGUARDS;
if (rule_anon_battle && s->stealthfaction != stealthfaction) {
if (rule_anon_battle!=0 && s->stealthfaction != stealthfaction) {
continue;
}
if (s1flags == s2flags) {

View File

@ -69,7 +69,7 @@ static void report_transfer(faction *f1, faction *f2, region *r, int amount) {
void report_donations(void)
{
ql_iter qli = qli_init(&transfers);;
ql_iter qli = qli_init(&transfers);
while (qli_more(qli)) {
transfer *tf = (transfer *)qli_next(&qli);

View File

@ -611,7 +611,7 @@ int count_maxmigrants(const faction * f)
static int migrants = -1;
if (migrants < 0) {
migrants = get_param_int(global.parameters, "rules.migrants", INT_MAX);
migrants = get_param_int(global.parameters, "rules.migrants.max", INT_MAX);
}
if (migrants == INT_MAX) {
int x = 0;
@ -1404,19 +1404,19 @@ int cmp_current_owner(const building * b, const building * a)
return -1;
}
int rule_stealth_faction(void)
bool rule_stealth_faction(void)
{
static int gamecookie = -1;
static int rule = -1;
if (rule < 0 || gamecookie != global.cookie) {
rule = get_param_int(global.parameters, "rules.stealth.faction", 0xFF);
rule = get_param_int(global.parameters, "rules.stealth.faction", 1);
gamecookie = global.cookie;
assert(rule >= 0);
}
return rule;
return rule!=0;
}
int rule_region_owners(void)
bool rule_region_owners(void)
{
static int gamecookie = -1;
static int rule = -1;
@ -1425,7 +1425,7 @@ int rule_region_owners(void)
gamecookie = global.cookie;
assert(rule >= 0);
}
return rule;
return rule!=0;
}
int rule_auto_taxation(void)
@ -1447,7 +1447,7 @@ int rule_blessed_harvest(void)
static int rule = -1;
if (rule < 0 || gamecookie != global.cookie) {
rule =
get_param_int(global.parameters, "rules.magic.blessed_harvest",
get_param_int(global.parameters, "rules.blessed_harvest.flags",
HARVEST_WORK);
gamecookie = global.cookie;
assert(rule >= 0);
@ -1479,7 +1479,7 @@ int rule_faction_limit(void)
return rule;
}
int rule_transfermen(void)
bool rule_transfermen(void)
{
static int gamecookie = -1;
static int rule = -1;
@ -1488,7 +1488,7 @@ int rule_transfermen(void)
gamecookie = global.cookie;
assert(rule >= 0);
}
return rule;
return rule!=0;
}
static int

View File

@ -151,18 +151,26 @@ extern "C" {
int cmp_current_owner(const struct building *b,
const struct building *bother);
#define TAX_ORDER 0x00
#define TAX_OWNER 0x01
int rule_auto_taxation(void);
int rule_transfermen(void);
int rule_region_owners(void);
int rule_stealth_faction(void);
bool rule_transfermen(void);
bool rule_region_owners(void);
bool rule_stealth_faction(void);
int rule_alliance_limit(void);
int rule_faction_limit(void);
#define HARVEST_WORK 0x00
#define HARVEST_TAXES 0x01
int rule_blessed_harvest(void);
#define TAX_ORDER 0x00
#define TAX_OWNER 0x01
int rule_auto_taxation(void);
#define GIVE_SELF 1
#define GIVE_PEASANTS 2
#define GIVE_LUXURIES 4
#define GIVE_HERBS 8
#define GIVE_GOODS 16
#define GIVE_ONDEATH 32
#define GIVE_ALLITEMS (GIVE_GOODS|GIVE_HERBS|GIVE_LUXURIES)
#define GIVE_DEFAULT (GIVE_SELF|GIVE_PEASANTS|GIVE_LUXURIES|GIVE_HERBS|GIVE_GOODS)
int rule_give(void);
int rule_alliance_limit(void);
int rule_faction_limit(void);
#define COUNT_MONSTERS 0x01
#define COUNT_MIGRANTS 0x02
@ -296,15 +304,6 @@ extern "C" {
void free_gamedata(void);
#define GIVE_SELF 1
#define GIVE_PEASANTS 2
#define GIVE_LUXURIES 4
#define GIVE_HERBS 8
#define GIVE_GOODS 16
#define GIVE_ONDEATH 32
#define GIVE_ALLITEMS (GIVE_GOODS|GIVE_HERBS|GIVE_LUXURIES)
#define GIVE_DEFAULT (GIVE_SELF|GIVE_PEASANTS|GIVE_LUXURIES|GIVE_HERBS|GIVE_GOODS)
extern struct attrib_type at_guard;
extern struct helpmode helpmodes[];
extern const char *parameters[];

View File

@ -638,6 +638,29 @@ static void json_keywords(cJSON *json) {
}
}
static void json_settings(cJSON *json) {
cJSON *child;
if (json->type != cJSON_Object) {
log_error("settings is not a json object: %d", json->type);
return;
}
for (child = json->child; child; child = child->next) {
if (child->valuestring) {
set_param(&global.parameters, child->string, child->valuestring);
}
else {
char value[32];
if (child->type == cJSON_Number && child->valuedouble && child->valueint<child->valuedouble) {
_snprintf(value, sizeof(value), "%lf", child->valuedouble);
}
else {
_snprintf(value, sizeof(value), "%d", child->valueint);
}
set_param(&global.parameters, child->string, value);
}
}
}
static void json_races(cJSON *json) {
cJSON *child;
if (json->type != cJSON_Object) {
@ -714,6 +737,9 @@ void json_config(cJSON *json) {
else if (strcmp(child->string, "keywords") == 0) {
json_keywords(child);
}
else if (strcmp(child->string, "settings") == 0) {
json_settings(child);
}
else if (strcmp(child->string, "skills") == 0) {
json_skills(child);
}

View File

@ -57,6 +57,26 @@ static void test_flags(CuTest *tc) {
test_cleanup();
}
static void test_settings(CuTest * tc)
{
const char * data = "{\"settings\": { "
"\"string\" : \"1d4\","
"\"integer\" : 14,"
"\"true\": true,"
"\"false\": false,"
"\"float\" : 1.5 }}";
cJSON *json = cJSON_Parse(data);
test_cleanup();
json_config(json);
CuAssertStrEquals(tc, "1", get_param(global.parameters, "true"));
CuAssertStrEquals(tc, "0", get_param(global.parameters, "false"));
CuAssertStrEquals(tc, "1d4", get_param(global.parameters, "string"));
CuAssertIntEquals(tc, 14, get_param_int(global.parameters, "integer", 0));
CuAssertDblEquals(tc, 1.5f, get_param_flt(global.parameters, "float", 0), 0.01);
test_cleanup();
}
static void test_races(CuTest * tc)
{
const char * data = "{\"races\": { \"orc\" : { "
@ -510,6 +530,7 @@ CuSuite *get_jsonconf_suite(void)
SUITE_ADD_TEST(suite, test_strings);
SUITE_ADD_TEST(suite, test_spells);
SUITE_ADD_TEST(suite, test_flags);
SUITE_ADD_TEST(suite, test_settings);
SUITE_ADD_TEST(suite, test_infinitive_from_config);
return suite;
}

View File

@ -858,7 +858,7 @@ bool can_leave(unit * u)
rule_leave = get_param_int(global.parameters, "rules.move.owner_leave", 0);
}
if (rule_leave && u->building && u == building_owner(u->building)) {
if (rule_leave!=0 && u->building && u == building_owner(u->building)) {
return false;
}
return true;

View File

@ -2231,17 +2231,7 @@ static int parse_main(xmlDocPtr doc)
xmlXPathFreeObject(result);
/* reading eressea/game/param */
xpath->node = node;
result = xmlXPathEvalExpression(BAD_CAST "param", xpath);
nodes = result->nodesetval;
for (i = 0; i != nodes->nodeNr; ++i) {
xmlNodePtr node = nodes->nodeTab[i];
parse_param(&global.parameters, node);
}
xmlXPathFreeObject(result);
/* reading eressea/game/order */
result = xmlXPathEvalExpression(BAD_CAST "order", xpath);
nodes = result->nodesetval;

View File

@ -793,7 +793,7 @@ void demographics(void)
if (plant_rules < 0) {
plant_rules =
get_param_int(global.parameters, "rules.economy.grow", 0);
get_param_int(global.parameters, "rules.grow.formula", 0);
}
for (dmd = r->land->demands; dmd; dmd = dmd->next) {
if (dmd->value > 0 && dmd->value < MAXDEMAND) {

View File

@ -213,14 +213,14 @@ static void free_mage(attrib * a)
free(mage);
}
int FactionSpells(void)
bool FactionSpells(void)
{
static int rules_factionspells = -1;
if (rules_factionspells < 0) {
rules_factionspells =
get_param_int(global.parameters, "rules.magic.factionlist", 0);
}
return rules_factionspells;
return rules_factionspells!=0;
}
void read_spells(struct quicklist **slistp, magic_t mtype,

View File

@ -346,23 +346,23 @@ extern "C" {
extern void create_newclone(struct unit *mage, struct unit *familiar);
extern struct unit *has_clone(struct unit *mage);
extern const char *spell_info(const struct spell *sp,
const char *spell_info(const struct spell *sp,
const struct locale *lang);
extern const char *spell_name(const struct spell *sp,
const char *spell_name(const struct spell *sp,
const struct locale *lang);
extern const char *curse_name(const struct curse_type *ctype,
const char *curse_name(const struct curse_type *ctype,
const struct locale *lang);
extern struct message *msg_unitnotfound(const struct unit *mage,
struct message *msg_unitnotfound(const struct unit *mage,
struct order *ord, const struct spllprm *spobj);
extern int FactionSpells(void);
bool FactionSpells(void);
extern void write_spells(struct quicklist *slist, struct storage *store);
extern void read_spells(struct quicklist **slistp, magic_t mtype,
struct storage *store);
void write_spells(struct quicklist *slist, struct storage *store);
void read_spells(struct quicklist **slistp, magic_t mtype,
struct storage *store);
extern struct spellbook * get_spellbook(const char * name);
extern void free_spellbooks(void);
struct spellbook * get_spellbook(const char * name);
void free_spellbooks(void);
#ifdef __cplusplus
}
#endif

View File

@ -121,7 +121,7 @@ void get_food(region * r)
if (food_rules < 0 || gamecookie != global.cookie) {
gamecookie = global.cookie;
food_rules = get_param_int(global.parameters, "rules.economy.food", 0);
food_rules = get_param_int(global.parameters, "rules.food.flags", 0);
}
if (food_rules & FOOD_IS_FREE) {

View File

@ -32,7 +32,7 @@ void test_upkeep_default(CuTest * tc)
u2 = test_create_unit(f2, r);
assert(r && u1 && u2);
set_param(&global.parameters, "rules.economy.food", "0");
set_param(&global.parameters, "rules.food.flags", "0");
i_change(&u1->items, i_silver, 20);
get_food(r);
// since u1 and u2 are not allied, u1 should not help u2 with upkeep
@ -60,7 +60,7 @@ void test_upkeep_hunger_damage(CuTest * tc)
u1 = test_create_unit(f1, r);
assert(r && u1);
set_param(&global.parameters, "rules.economy.food", "0");
set_param(&global.parameters, "rules.food.flags", "0");
u1->hp = 100;
get_food(r);
// since u1 and u2 are not allied, u1 should not help u2 with upkeep
@ -86,7 +86,7 @@ void test_upkeep_from_pool(CuTest * tc)
u2 = test_create_unit(u1->faction, r);
assert(r && u1 && u2);
set_param(&global.parameters, "rules.economy.food", "0");
set_param(&global.parameters, "rules.food.flags", "0");
i_change(&u1->items, i_silver, 30);
get_food(r);
CuAssertIntEquals(tc, 10, i_get(u1->items, i_silver));
@ -122,7 +122,7 @@ void test_upkeep_from_friend(CuTest * tc)
u2 = test_create_unit(f2, r);
assert(r && u1 && u2);
set_param(&global.parameters, "rules.economy.food", "0");
set_param(&global.parameters, "rules.food.flags", "0");
i_change(&u1->items, i_silver, 30);
get_food(r);
CuAssertIntEquals(tc, 10, i_get(u1->items, i_silver));
@ -151,7 +151,7 @@ void test_upkeep_free(CuTest * tc)
u = test_create_unit(test_create_faction(test_create_race("human")), r);
assert(r && u);
set_param(&global.parameters, "rules.economy.food", "4"); // FOOD_IS_FREE
set_param(&global.parameters, "rules.food.flags", "4"); // FOOD_IS_FREE
get_food(r);
CuAssertIntEquals(tc, 0, i_get(u->items, i_silver));
CuAssertIntEquals(tc, 0, fval(u, UFL_HUNGER));

View File

@ -270,10 +270,10 @@ void init_translations(const struct locale *lang, int ut, const char * (*string_
for (i = 0; i != maxstrings; ++i) {
// TODO: swap the name of s and key
const char * s = string_cb(i);
const char * key = s ? locale_string(lang, s, false) : 0;
key = key ? key : s;
if (key) {
if (s) {
struct critbit_tree ** cb = (struct critbit_tree **)tokens;
const char * key = locale_string(lang, s, false);
if (!key) key = s;
add_translation(cb, key, i);
}
}

View File

@ -28,13 +28,6 @@
#include <ctype.h>
#ifdef USE_LIBXML2
const xmlChar *xml_i(double number)
{
static char buffer[128]; // FIXME: static return value
_snprintf(buffer, sizeof(buffer), "%.0f", number);
return (const xmlChar *)buffer;
}
int xml_ivalue(xmlNodePtr node, const char *name, int dflt)
{
int i = dflt;

View File

@ -26,8 +26,6 @@ extern "C" {
extern double xml_fvalue(xmlNodePtr node, const char *name, double dflt);
extern int xml_ivalue(xmlNodePtr node, const char *name, int dflt);
extern bool xml_bvalue(xmlNodePtr node, const char *name, bool dflt);
const xmlChar *xml_i(double number);
#endif
extern int read_xml(const char *filename, const char *catalog);

9
tests/runtests.bat Normal file
View File

@ -0,0 +1,9 @@
@ECHO OFF
SET BUILD=..\build-vs12\eressea\Debug\
SET SERVER=%BUILD%\eressea.exe
%BUILD%\test_eressea.exe
%SERVER% ..\scripts\run-tests.lua
%SERVER% ..\scripts\run-tests-e2.lua
%SERVER% ..\scripts\run-tests-e3.lua
PAUSE
RMDIR /s /q reports