diff --git a/conf/e2/config.json b/conf/e2/config.json index b5ed2e68c..ebc385adf 100644 --- a/conf/e2/config.json +++ b/conf/e2/config.json @@ -6,15 +6,12 @@ "config://conf/e2/locales.json", "config://conf/e2/terrains.json", "config://conf/e2/items.json", - "config://conf/e2/rules.xml", "config://res/core/ships.xml", "config://res/core/common/buildings.xml", "config://res/eressea/buildings.xml", "config://res/buildings/castle.xml", "config://res/eressea/races.xml", "config://res/eressea/artrewards.xml", - "config://res/eressea/familiars.xml", - "config://res/eressea/equipment.xml", "config://res/eressea/spells.xml", "config://res/eressea/spellbooks/gray.xml", "config://res/eressea/spellbooks/gwyrrd.xml", diff --git a/conf/e2/rules.xml b/conf/e2/rules.xml deleted file mode 100644 index 002c34960..000000000 --- a/conf/e2/rules.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/conf/e3/config.json b/conf/e3/config.json index ad7a44b2f..c1fa2725c 100644 --- a/conf/e3/config.json +++ b/conf/e3/config.json @@ -7,8 +7,6 @@ "config://conf/e3/terrains.json", "config://conf/e3/items.json", "config://conf/e3/races.json", - "config://res/e3a/familiars.xml", - "config://res/e3a/equipment.xml", "config://res/e3a/ships.xml", "config://res/e3a/buildings.xml", "config://res/e3a/spells.xml", diff --git a/res/core/de/strings.xml b/res/core/de/strings.xml index 8207e0aec..2be2f04e4 100644 --- a/res/core/de/strings.xml +++ b/res/core/de/strings.xml @@ -7100,112 +7100,6 @@ Furious peasants - - Söldner - Mercenaries - - - - Sumpfbewohner - Swamp people - - - - Waldbewohner - Woodsmen - - - - Nomaden - Nomads - - - - Eisleute - Ice people - - - - Bergbewohner - Mountain people - - - - Magie der Elemente - Magic of the Elements - - - - Schwerter, Armbrüste, Langbögen - Swords, Crossbows and Longbows - - - - Gorms Almanach der Rationellen Kriegsführung - Gorm's Almanach of Rational War - - - - Katamarane, Koggen, Karavellen - The dragonship, the caravell and the longboat - - - - Wege der Sterne - Ways of the Start - - - - Nadishahs Kleine Gift- und Kräuterkunde - Nadishah's collected lore on poisonous and beneficial herbs - - - - Mandricks Kompendium der Alchemie - Mandrick's alchemistic compendium - - - - Die Konstruktion der Burgen und Schlösser von Zentralandune - - - - Die Esse - - - - Über die Gewinnung von Erzen - - - - Barinions Lieder, eine Einführung für Unbedarfte - - - - die Ruine eines alten Tempels - the ruins of an ancient temple - - - - eine alte Burgruine - the ruins of a castle - - - - ein zerfallenes Bauernhaus - a dilapitated farm - - - - eine Leiche am Wegesrand - a corpse by the wayside - - - - eine Leiche am Wegesrand - a corpse by the wayside - - Feuerdrache fire dragon diff --git a/res/core/messages.xml b/res/core/messages.xml index b810b8a43..371369dbf 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -7991,23 +7991,6 @@ "A message from $unit($unit): '$message'" - - - - - - "Plötzlich stolpert $unit($unit) über einige $localize($name). Nach kurzem Zögern entschließen die $localize($name), sich Deiner Partei anzuschließen." - "$unit($unit) stumbles upon $localize($name). After short hesitation, $localize($name) agrees to join your faction." - - - - - - - "$unit($unit) entdeckt ein kleines Dorf. Die meisten Häuser wurden durch einen über die Ufer getretenen Fluß zerstört. Eine Gruppe der verzweifelten Menschen schließt sich deiner Partei an." - "$unit($unit) discovers a small village. Most of the houses have been destroyed by flooding, and a group of the distressed villagers join your faction." - - "Ein Bauernmob erhebt sich und macht Jagd auf Schwarzmagier." "An angry mob forms and hunts practitioners of the dark arts." @@ -8188,8 +8171,8 @@ - "$unit($unit) in $region($region): '$order($command)' - In dieser Region gibt es keine Brücken und Straßen mehr zu bauen." - "$unit($unit) in $region($region): '$order($command)' - The roads and bridges in this region are complete." + "$unit($unit) in $region($region): '$order($command)' - In dieser Richtung gibt es keine Brücken und Straßen mehr zu bauen." + "$unit($unit) in $region($region): '$order($command)' - The roads and bridges in that direction are complete." diff --git a/res/e3a/equipment.xml b/res/e3a/equipment.xml deleted file mode 100644 index d8c529d8a..000000000 --- a/res/e3a/equipment.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/res/e3a/familiars.xml b/res/e3a/familiars.xml deleted file mode 100644 index b30c733ed..000000000 --- a/res/e3a/familiars.xml +++ /dev/null @@ -1,105 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/res/eressea/equipment.xml b/res/eressea/equipment.xml deleted file mode 100644 index 94d0deb07..000000000 --- a/res/eressea/equipment.xml +++ /dev/null @@ -1,275 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/res/eressea/familiars.xml b/res/eressea/familiars.xml deleted file mode 100644 index 112a82420..000000000 --- a/res/eressea/familiars.xml +++ /dev/null @@ -1,133 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/scripts/eressea/e2/familiars.lua b/scripts/eressea/e2/familiars.lua new file mode 100644 index 000000000..720cb81eb --- /dev/null +++ b/scripts/eressea/e2/familiars.lua @@ -0,0 +1,153 @@ +local sets = { + ['fam_lynx'] = { + ['skills'] = { + ['espionage'] = 1, + ['magic'] = 1, + ['stealth'] = 1, + ['perception'] = 1, + } + }, + ['fam_tunnelworm'] = { + ['skills'] = { + ['forestry'] = 1, + ['magic'] = 1, + ['mining'] = 1, + ['stamina'] = 1, + } + }, + ['fam_eagle'] = { + ['skills'] = { + ['magic'] = 1, + ['perception'] = 1, + } + }, + ['fam_rat'] = { + ['skills'] = { + ['magic'] = 1, + ['espionage'] = 1, + ['stealth'] = 1, + ['perception'] = 1, + ['stamina'] = 6, + } + }, + ['fam_owl'] = { + ['skills'] = { + ['magic'] = 1, + ['espionage'] = 1, + ['stealth'] = 1, + ['perception'] = 1, + } + }, + ['fam_direwolf'] = { + ['skills'] = { + ['magic'] = 1, + ['perception'] = 1, + } + }, + ['fam_hellcat'] = { + ['skills'] = { + ['magic'] = 1, + ['perception'] = 1, + } + }, + ['fam_tiger'] = { + ['skills'] = { + ['magic'] = 1, + ['perception'] = 1, + } + }, + ['fam_songdragon'] = { + ['skills'] = { + ['magic'] = 1, + }, + ['spells'] = { + ['flee'] = 2, + ['sleep'] = 7, + ['frighten'] = 8, + }, + }, + ['fam_ghost'] = { + ['skills'] = { + ['magic'] = 1, + }, + ['spells'] = { + ['steal_aura'] = 6, + ['summonundead'] = 6, + ['frighten'] = 8, + }, + }, + ['fam_fairy'] = { + ['skills'] = { + ['magic'] = 1, + }, + ['spells'] = { + ['appeasement'] = 1, + ['calm_monster'] = 6, + ['seduction'] = 6, + }, + }, + ['fam_unicorn'] = { + ['skills'] = { + ['magic'] = 1, + ['stealth'] = 1, + ['perception'] = 1, + }, + ['spells'] = { + ['resist_magic'] = 3, + ['song_of_peace'] = 12, + ['calm_monster'] = 6, + ['heroic_song'] = 5, + ['song_of_healing'] = 3, + ['appeasement'] = 2, + }, + }, + ['fam_imp'] = { + ['skills'] = { + ['magic'] = 1, + ['stealth'] = 1, + ['perception'] = 1, + ['espionage'] = 1, + ['taxation'] = 1, + }, + ['spells'] = { + ['steal_aura'] = 6, + ['shapeshift'] = 3, + ['seduction'] = 6, + }, + }, + ['fam_dreamcat'] = { + ['skills'] = { + ['magic'] = 1, + ['stealth'] = 1, + ['perception'] = 1, + ['espionage'] = 1, + ['taxation'] = 1, + }, + ['spells'] = { + ['shapeshift'] = 3, + ['transferauratraum'] = 3, + }, + }, + ['fam_nymph'] = { + ['skills'] = { + ['magic'] = 1, + ['bow'] = 1, + ['herbalism'] = 1, + ['training'] = 1, + ['riding'] = 1, + ['espionage'] = 1, + ['stealth'] = 1, + ['entertainment'] = 1, + ['perception'] = 1, + }, + ['spells'] = { + ['seduction'] = 6, + ['calm_monster'] = 3, + ['song_of_confusion'] = 4, + ['appeasement'] = 1, + }, + }, +} + +local equipment = require('eressea.equipment') +equipment.add_multiple(sets) diff --git a/scripts/eressea/e2/init.lua b/scripts/eressea/e2/init.lua index 722078741..52636d207 100644 --- a/scripts/eressea/e2/init.lua +++ b/scripts/eressea/e2/init.lua @@ -1,5 +1,106 @@ require 'eressea.spells' -eressea.log.debug("rules for game E2") +eressea.log.debug('rules for game E2') + +math.randomseed(rng.random()) + +local equipment = require('eressea.equipment') +local sets = { + ['seed_faction'] = { + ['items'] = { + ['adamantium'] = 1 + } + }, + ['new_orc'] = { + ['skills'] = { + ['polearm'] = 1, + ['melee'] = 1 + } + }, + ['spo_seaserpent'] = { + ['items'] = { + ['dragonblood'] = 6, + ['seaserpenthead'] = 1 + } + }, + ['spo_dragon'] = { + ['items'] = { + ['dragonblood'] = 4, + ['seaserpenthead'] = 1 + } + }, + ['spo_dragon'] = { + ['items'] = { + ['dragonblood'] = 4, + ['dragonhead'] = 1 + } + }, + ['spo_youngdragon'] = { + ['items'] = { + ['dragonblood'] = 1 + } + }, + ['spo_wyrm'] = { + ['items'] = { + ['dragonblood'] = 10, + ['dragonhead'] = 1 + } + }, + ['seed_dragon'] = { + ['skills'] = { + ['magic'] = 4, + ['stealth'] = 1, + ['stamina'] = 1, + }, + ['callback'] = function(u) + u:add_item('money', u.number * (math.random(500)+99)) + u:set_skill('perception', math.random(3)) + end + }, + ['seed_braineater'] = { + ['skills'] = { + ['stealth'] = 1, + ['perception'] = 1, + } + }, + ['seed_seaserpent'] = { + ['skills'] = { + ['magic'] = 4, + ['stealth'] = 2, + ['stamina'] = 1, + ['perception'] = 3, + } + }, + ['rising_undead'] = { + ['items'] = { + ['rustysword'] = 1 + }, + ['callback'] = function(u) + if (math.random(2)==1) then + u:add_item('rustychainmail', u.number) + end + if (math.random(3)==1) then + u:add_item('rustyshield', u.number) + end + end + }, + ['new_dracoid'] = { + ['callback'] = function(u) + local pick = math.random(3) + if pick==1 then + u:set_skill('melee', math.random(4)+2) + u:add_item('sword', u.number) + elseif pick==2 then + u:set_skill('polearm', math.random(4)+2) + u:add_item('spear', u.number) + else + u:set_skill('bow', math.random(3)+1) + u:add_item('bow', u.number) + end + end + } +} + +equipment.add_multiple(sets) return { require('eressea'), @@ -11,8 +112,8 @@ return { require('eressea.tunnels'), require('eressea.ponnuki'), require('eressea.astral'), --- require('eressea.locales'), require('eressea.jsreport'), require('eressea.ents'), - require('eressea.cursed') + require('eressea.cursed'), + require('eressea.e2.familiars') } diff --git a/scripts/eressea/e3/familiars.lua b/scripts/eressea/e3/familiars.lua new file mode 100644 index 000000000..00f3b537d --- /dev/null +++ b/scripts/eressea/e3/familiars.lua @@ -0,0 +1,127 @@ +eressea.log.debug("rules for game E3") + +local equipment = require('eressea.equipment') +local sets = { + ['fam_lynx'] = { + ['skills'] = { + ['magic'] = 1, + } + }, + ['fam_eagle'] = { + ['skills'] = { + ['magic'] = 1, + } + }, + ['fam_direwolf'] = { + ['skills'] = { + ['magic'] = 1, + } + }, + ['fam_owl'] = { + ['skills'] = { + ['magic'] = 1, + } + }, + ['fam_hellcat'] = { + ['skills'] = { + ['magic'] = 1, + } + }, + ['fam_tiger'] = { + ['skills'] = { + ['magic'] = 1, + } + }, + ['fam_rat'] = { + ['skills'] = { + ['magic'] = 1, + ['stamina'] = 6, + } + }, + ['fam_tunnelworm'] = { + ['skills'] = { + ['magic'] = 1, + ['mining'] = 1, + ['forestry'] = 1, + ['stamina'] = 1, + } + }, + ['fam_dreamcat'] = { + ['skills'] = { + ['magic'] = 1, + }, + ['spells'] = { + ['shapeshift'] = 3, + ['transferauratraum'] = 3, + } + }, + ['fam_imp'] = { + ['skills'] = { + ['magic'] = 1, + }, + ['spells'] = { + ['shapeshift'] = 3, + ['seduction'] = 6, + ['steal_aura'] = 6, + } + }, + ['fam_ghost'] = { + ['skills'] = { + ['magic'] = 1, + }, + ['spells'] = { + ['steal_aura'] = 6, + ['summonundead'] = 6, + ['frighten'] = 8, + } + }, + ['fam_fairy'] = { + ['skills'] = { + ['magic'] = 1, + }, + ['spells'] = { + ['appeasement'] = 1, + ['seduction'] = 6, + ['calm_monster'] = 6, + } + }, + ['fam_songdragon'] = { + ['skills'] = { + ['magic'] = 1, + }, + ['spells'] = { + ['flee'] = 2, + ['sleep'] = 7, + ['frighten'] = 8, + } + }, + ['fam_unicorn'] = { + ['skills'] = { + ['magic'] = 1, + }, + ['spells'] = { + ['appeasement'] = 1, + ['song_of_healing'] = 2, + ['resist_magic'] = 3, + ['heroic_song'] = 5, + ['calm_monster'] = 6, + ['song_of_peace'] = 12, + } + }, + ['fam_nymph'] = { + ['skills'] = { + ['magic'] = 1, + ['bow'] = 1, + ['training'] = 1, + ['riding'] = 1, + }, + ['spells'] = { + ['appeasement'] = 1, + ['song_of_confusion'] = 4, + ['calm_monster'] = 6, + ['seduction'] = 6, + } + }, +} + +equipment.add_multiple(sets) diff --git a/scripts/eressea/e3/init.lua b/scripts/eressea/e3/init.lua index f7402268c..b72d569aa 100644 --- a/scripts/eressea/e3/init.lua +++ b/scripts/eressea/e3/init.lua @@ -2,10 +2,21 @@ require 'eressea.spells' eressea.log.debug("rules for game E3") +local equipment = require('eressea.equipment') +local sets = { + ['spo_seaserpent'] = { + ['items'] = { + ['dragonblood'] = 2, + ['seaserpenthead'] = 1 + } + } +} +equipment.add_multiple(sets) + return { require('eressea'), require('eressea.xmasitems'), - -- require('eressea.markets'), require('eressea.frost'), - require('eressea.ents') + require('eressea.ents'), + require('eressea.e3.familiars'), } diff --git a/scripts/eressea/equipment.lua b/scripts/eressea/equipment.lua new file mode 100644 index 000000000..6e4ccfc9b --- /dev/null +++ b/scripts/eressea/equipment.lua @@ -0,0 +1,156 @@ +-- forward declaration required: + +local self = {} +local mysets = { + ['first_unit'] = { + ['items'] = { + ['money'] = 2500, + ['log'] = 10, + ['stone'] = 4 + } + }, + ['seed_unit'] = { + ['items'] = { + ['log'] = 50, + ['stone'] = 50, + ['iron'] = 50, + ['laen'] = 10, + ['sword'] = 1, + ['mallorn'] = 10, + ['skillpotion'] = 5, + ['lifepotion'] = 5, + ['money'] = 20000 + }, + ['skills'] = { + ['perception'] = 30, + ['melee'] = 1 + } + }, + ['seed_dwarf'] = { + ['items'] = { + ['axe'] = 1, + ['chainmail'] = 1, + }, + ['skills'] = { + ['melee'] = 1 + } + }, + ['seed_elf'] = { + ['items'] = { + ['fairyboot'] = 1, + }, + ['callback'] = equip_newunits + }, + ['seed_orc'] = { + ['skills'] = { + ['polearm'] = 4, + ['melee'] = 4, + ['crossbow'] = 4, + ['catapult'] = 4, + ['bow'] = 4, + } + }, + ['seed_goblin'] = { + ['items'] = { + ['roi'] = 1 + }, + ['callback'] = equip_newunits + }, + ['seed_human'] = { + ['callback'] = equip_newunits + }, + ['seed_troll'] = { + ['items'] = { + ['stone'] = 50, + }, + ['skills'] = { + ['building'] = 1, + ['perception'] = 3, + } + }, + ['seed_demon'] = { + ['skills'] = { + ['stamina'] = 15 + } + }, + ['seed_insect'] = { + ['items'] = { + ['nestwarmth'] =9 + } + }, + ['seed_halfling'] = { + ['items'] = { + ['horse'] = 2, + ['cart'] = 1, + ['balm'] = 5, + ['spice'] = 5, + ['myrrh'] = 5, + ['jewel'] = 5, + ['oil'] = 5, + ['silk'] = 5, + ['incense'] = 5 + }, + ['skills'] = { + ['trade'] = 1, + ['riding'] = 2 + } + }, + ['seed_cat'] = { + ['items'] = { + ['roi'] = 1 + }, + ['callback'] = equip_newunits + }, + ['seed_aquarian'] = { + ['skills'] = { + ['sailing'] = 1 + }, + ['callback'] = equip_newunits + }, +} + +function equip_unit(u, name, flags) + local set = mysets[name] + if set then + local items = set['items'] + if items then + for name, count in pairs(items) do + u:add_item(name, count * u.number) + end + end + local skills = set['skills'] + if skills then + for name, level in pairs(skills) do + u:set_skill(name, level) + end + end + local spells = set['spells'] + if spells then + for name, level in ipairs(spells) do + u:add_spell(name, level) + end + end + local callback = set['callback'] + if callback and type(callback) == 'function' then + callback(u, flags) + end + return true + end + return false +end + +self.add = function(name, set) + mysets[name] = set +end + +self.add_multiple = function(sets) + for name, set in pairs(sets) do + mysets[name] = set + end +end + +self.get = function(name) + return mysets[name] +end + +return self diff --git a/scripts/eressea/xmlconf.lua b/scripts/eressea/xmlconf.lua index 756d3c18a..335845177 100644 --- a/scripts/eressea/xmlconf.lua +++ b/scripts/eressea/xmlconf.lua @@ -3,8 +3,6 @@ local rules = 'conf' if config.rules then rules = rules .. '/' .. config.rules assert(0 == eressea.config.read(rules .. '/config.json', config.install), "could not read JSON data") --- assert(0 == read_xml(confdir .. rules .. 'rules.xml', confdir .. rules .. 'catalog.xml'), "could not load XML data, did you compile with LIBXML2 ?") --- assert(0 == read_xml(confdir .. rules .. 'locales.xml', confdir .. rules .. 'catalog.xml'), "could not load XML data, did you compile with LIBXML2 ?") end eressea.game.reset() diff --git a/scripts/run-tests-e2.lua b/scripts/run-tests-e2.lua index 2672b7ef2..b5f18c7f7 100644 --- a/scripts/run-tests-e2.lua +++ b/scripts/run-tests-e2.lua @@ -22,7 +22,6 @@ eressea.settings.set("rules.food.flags", "4") eressea.settings.set("rules.ship.damage.nocrew", "0") eressea.settings.set("rules.ship.drifting", "0") eressea.settings.set("rules.ship.storms", "0") -eressea.settings.set("rules.encounters", "0") eressea.settings.set("nmr.timeout", "0") eressea.settings.set("NewbieImmunity", "0") rules = require('eressea.' .. config.rules) diff --git a/scripts/run-tests-e3.lua b/scripts/run-tests-e3.lua index 9ad78a81f..3332df306 100644 --- a/scripts/run-tests-e3.lua +++ b/scripts/run-tests-e3.lua @@ -23,7 +23,6 @@ eressea.settings.set("rules.food.flags", "4") eressea.settings.set("rules.ship.damage.nocrew", "0") eressea.settings.set("rules.ship.drifting", "0") eressea.settings.set("rules.ship.storms", "0") -eressea.settings.set("rules.encounters", "0") eressea.settings.set("nmr.timeout", "0") eressea.settings.set("NewbieImmunity", "0") rules = require('eressea.' .. config.rules) diff --git a/scripts/run-turn.lua b/scripts/run-turn.lua index 34340d43c..62d48ec51 100644 --- a/scripts/run-turn.lua +++ b/scripts/run-turn.lua @@ -183,6 +183,8 @@ if file_exists('execute.lock') then assert(false) end +math.randomseed(rng.random()) + local path = 'scripts' if config.install then path = config.install .. '/' .. path diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index 511f275db..febcc2a3f 100644 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -33,7 +33,6 @@ function setup() eressea.settings.set("nmr.timeout", "0") eressea.settings.set("NewbieImmunity", "0") 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") end @@ -968,7 +967,6 @@ 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.encounters", "0") eressea.settings.set("rules.move.owner_leave", "0") end diff --git a/scripts/tests/config.lua b/scripts/tests/config.lua index a83b64350..a3104a6b6 100644 --- a/scripts/tests/config.lua +++ b/scripts/tests/config.lua @@ -8,27 +8,32 @@ end function test_read_race() local f - eressea.free_game() assert_not_nil(eressea.config) eressea.config.parse('{ "races": { "orc" : {}}}') f = faction.create("orc", "orc@example.com", "en") assert_not_nil(f) end -function disable_test_read_ship() - local s - eressea.free_game() - assert_not_nil(eressea.config) - conf = [[{ - "ships": { - "boat" : { - "construction" : { - "maxsize" : 20 - } - } - } - }]] - eressea.config.parse(conf); - s = ship.create(nil, "boat") - assert_not_nil(s) +function test_seed_unit() + local r = region.create(0, 0, "plain") + local f = faction.create('human') + local u = unit.create(f, r, 1) + u:equip('seed_unit') + assert_equal(20000, u:get_item('money')) + assert_equal(50, u:get_item('log')) + assert_equal(50, u:get_item('stone')) + assert_equal(1, u:get_skill('melee')) +end + +function test_seed_elf() + local r = region.create(0, 0, "plain") + local f = faction.create('human') + local u = unit.create(f, r, 1) + -- quirk: independent of the race, seed_elf contains a fairyboot + u:equip('seed_elf') + assert_equal(1, u:get_item('fairyboot')) + -- all humans start in a building: + assert_not_nil(u.building) + assert_equal('castle', u.building.type) + assert_equal(10, u.building.size) end diff --git a/scripts/tests/e2/adamantium.lua b/scripts/tests/e2/adamantium.lua index de9a2312f..a893d32d5 100644 --- a/scripts/tests/e2/adamantium.lua +++ b/scripts/tests/e2/adamantium.lua @@ -7,7 +7,6 @@ function setup() eressea.settings.set("nmr.timeout", "0") eressea.settings.set("rules.food.flags", "4") eressea.settings.set("rules.ship.storms", "0") - eressea.settings.set("rules.encounters", "0") end local function create_faction(race) diff --git a/scripts/tests/e2/e2features.lua b/scripts/tests/e2/e2features.lua index 8fea1641a..776537671 100644 --- a/scripts/tests/e2/e2features.lua +++ b/scripts/tests/e2/e2features.lua @@ -444,3 +444,45 @@ function test_faction_anonymous() assert_equal(get_name(u) .. ", 1 Mensch, aggressiv.", u:show(f)) assert_equal(get_name(u) .. ", " .. get_name(f) .. ", 1 Mensch.", u:show(f2)) end + +function test_new_orc_has_skills() + local f = faction.create('orc') + local r = region.create(0, 0, 'plain') + local u = unit.create(f, r) + u:add_item('money', 400) + u.number = 0 + u:add_order("REKRUTIEREN 2") + process_orders() + assert_equal(2, u.number) + assert_equal(1, u:get_skill('polearm')) + assert_equal(1, u:get_skill('melee')) +end + +function test_new_dracoid() + local f = faction.create('human') + local r = region.create(0, 0, 'plain') + local u = unit.create(f, r, 'dracoid') + u.number = 2 + u:equip("new_dracoid") + assert_equal(2, u.number) + item = nil + if u:get_skill('bow') > 1 then + item = 'bow' + elseif u:get_skill('polearm') > 1 then + item = 'spear' + elseif u:get_skill('melee') > 1 then + item = 'sword' + end + assert_not_nil(item) + assert_equal(u.number, u:get_item(item)) +end + +function test_rising_undead() + local f = faction.create('human') + local r = region.create(0, 0, 'plain') + local u = unit.create(f, r, 'undead') + u.number = 2 + u:equip("rising_undead") + assert_equal(2, u.number) + assert_equal(u.number, u:get_item('rustysword')) +end diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index 22195a1f4..5c942fc74 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -13,6 +13,7 @@ require 'tests.e2.guard' require 'tests.e2.stealth' require 'tests.e2.items' require 'tests.e2.ships' +require 'tests.config' require 'tests.items' require 'tests.economy' require 'tests.orders' diff --git a/scripts/tests/e2/items.lua b/scripts/tests/e2/items.lua index d19b3246f..32e8909cf 100644 --- a/scripts/tests/e2/items.lua +++ b/scripts/tests/e2/items.lua @@ -7,7 +7,6 @@ function setup() eressea.settings.set("nmr.timeout", "0") eressea.settings.set("rules.food.flags", "4") eressea.settings.set("rules.ship.storms", "0") - eressea.settings.set("rules.encounters", "0") eressea.settings.set("magic.regeneration.enable", "0") eressea.settings.set("rules.grow.formula", "0") eressea.settings.set("study.random_progress", "0") diff --git a/scripts/tests/e2/spells.lua b/scripts/tests/e2/spells.lua index deeb2798c..a9f49d2b8 100644 --- a/scripts/tests/e2/spells.lua +++ b/scripts/tests/e2/spells.lua @@ -124,3 +124,15 @@ function test_familiar() end end end + +function test_familiar_lynx() + local r = region.create(0, 0, 'plain') + local f = faction.create('human') + local u = unit.create(f, r) + u.race = 'lynx' + u:equip('fam_lynx') + assert_equal(1, u:get_skill('stealth')) + assert_equal(1, u:get_skill('espionage')) + assert_equal(1, u:get_skill('magic')) + assert_equal(1, u:get_skill('perception')) +end diff --git a/scripts/tests/e3/rules.lua b/scripts/tests/e3/rules.lua index 5120fb747..6d3e56d1a 100644 --- a/scripts/tests/e3/rules.lua +++ b/scripts/tests/e3/rules.lua @@ -1026,3 +1026,17 @@ function test_demons_using_mallornlance() end assert_true(u.guard) end + +function test_new_orc_has_no_skills() +-- orcs in E2 get starting skills, but in E3 they do not + local f = faction.create('orc') + local r = region.create(0, 0, 'plain') + local u = unit.create(f, r) + u:add_item('money', 400) + u.number = 0 + u:add_order("REKRUTIEREN 2") + process_orders() + assert_equal(2, u.number) + assert_equal(0, u:get_skill('polearm')) + assert_equal(0, u:get_skill('melee')) +end diff --git a/scripts/tests/init.lua b/scripts/tests/init.lua index c933d4e69..a01e1c75c 100644 --- a/scripts/tests/init.lua +++ b/scripts/tests/init.lua @@ -1,5 +1,4 @@ -- new tests 2014-06-11 -require 'tests.config' require 'tests.faction' require 'tests.locale' require 'tests.movement' diff --git a/scripts/tests/items.lua b/scripts/tests/items.lua index 60bbf100f..f4d8657c6 100644 --- a/scripts/tests/items.lua +++ b/scripts/tests/items.lua @@ -8,7 +8,6 @@ function setup() eressea.settings.set("NewbieImmunity", "0") eressea.settings.set("rules.food.flags", "4") eressea.settings.set("rules.ship.storms", "0") - eressea.settings.set("rules.encounters", "0") eressea.settings.set("magic.regeneration.enable", "0") end diff --git a/scripts/tests/study.lua b/scripts/tests/study.lua index 2a713dd43..14d4ce1d6 100644 --- a/scripts/tests/study.lua +++ b/scripts/tests/study.lua @@ -36,7 +36,6 @@ function test_study_expensive() local f = faction.create("human", "test@example.com", "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() diff --git a/scripts/tests/undead.lua b/scripts/tests/undead.lua index 0c9f609f1..a3c541afa 100644 --- a/scripts/tests/undead.lua +++ b/scripts/tests/undead.lua @@ -7,7 +7,6 @@ function setup() eressea.settings.set("nmr.timeout", "0") eressea.settings.set("NewbieImmunity", "0") 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") eressea.settings.set("GiveRestriction", "0") diff --git a/src/battle.c b/src/battle.c index 1e6692a68..b69bab5d6 100644 --- a/src/battle.c +++ b/src/battle.c @@ -916,17 +916,13 @@ void kill_troop(troop dt) rmtroop(dt); if (!df->alive) { char eqname[64]; - const struct equipment *eq; const race *rc = u_race(du); item *drops = item_spoil(rc, du->number - df->run.number); if (drops != NULL) { i_merge(&du->items, &drops); } sprintf(eqname, "spo_%s", rc->_name); - eq = get_equipment(eqname); - if (eq != NULL) { - equip_items(&du->items, eq); - } + equip_unit_mask(du, eqname, EQUIP_ITEMS); } } diff --git a/src/bind_monsters.c b/src/bind_monsters.c index 76afffc15..af630bb41 100644 --- a/src/bind_monsters.c +++ b/src/bind_monsters.c @@ -7,7 +7,6 @@ #include -#include #include #include #include diff --git a/src/bind_unit.c b/src/bind_unit.c index 2ae39bf20..e0fa9f86b 100644 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -17,6 +17,7 @@ #include #include #include +#include "kernel/equipment.h" #include #include #include @@ -962,6 +963,16 @@ static int tolua_event_get(lua_State * L) return 0; } +static int tolua_equipunit(lua_State * L) +{ + unit *u = (unit *)tolua_tousertype(L, 1, 0); + const char *eqname = tolua_tostring(L, 2, 0); + int mask = (int)tolua_tonumber(L, 3, EQUIP_ALL); + assert(u && mask > 0); + equip_unit_mask(u, eqname, mask); + return 0; +} + void tolua_unit_open(lua_State * L) { /* register user types */ @@ -1062,6 +1073,7 @@ void tolua_unit_open(lua_State * L) tolua_variable(L, TOLUA_CAST "hp_max", tolua_unit_get_hpmax, 0); tolua_variable(L, TOLUA_CAST "aura_max", tolua_unit_get_auramax, 0); + tolua_function(L, TOLUA_CAST "equip", tolua_equipunit); tolua_function(L, TOLUA_CAST "show", tolua_bufunit); } tolua_endmodule(L); diff --git a/src/bindings.c b/src/bindings.c index 3fda9b844..bbea46e60 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -9,7 +9,6 @@ #include "kernel/alliance.h" #include "kernel/building.h" #include "kernel/curse.h" -#include "kernel/equipment.h" #include "kernel/unit.h" #include "kernel/terrain.h" #include "kernel/messages.h" @@ -24,6 +23,7 @@ #include "kernel/save.h" #include "kernel/spell.h" #include "kernel/spellbook.h" +#include "races/races.h" #include "bind_unit.h" #include "bind_storage.h" @@ -47,7 +47,6 @@ #include "monsters.h" #include "market.h" -#include #include #include @@ -154,25 +153,6 @@ int tolua_itemlist_next(lua_State * L) return 0; } -static int tolua_autoseed(lua_State * L) -{ - const char *filename = tolua_tostring(L, 1, 0); - int new_island = tolua_toboolean(L, 2, 0); - newfaction *players = read_newfactions(filename); - if (players != NULL) { - while (players) { - int n = listlen(players); - int k = (n + ISLANDSIZE - 1) / ISLANDSIZE; - k = n / k; - n = autoseed(&players, k, new_island ? 0 : TURNS_PER_ISLAND); - if (n == 0) { - break; - } - } - } - return 0; -} - static int tolua_getkey(lua_State * L) { const char *name = tolua_tostring(L, 1, 0); @@ -413,33 +393,6 @@ static int tolua_get_nmrs(lua_State * L) return 1; } -static int tolua_equipunit(lua_State * L) -{ - unit *u = (unit *)tolua_tousertype(L, 1, 0); - const char *eqname = tolua_tostring(L, 2, 0); - int mask = (int)tolua_tonumber(L, 3, EQUIP_ALL); - assert(u && mask > 0); - equip_unit_mask(u, get_equipment(eqname), mask); - return 0; -} - -static int tolua_equipment_setitem(lua_State * L) -{ - int result = -1; - const char *eqname = tolua_tostring(L, 1, 0); - const char *iname = tolua_tostring(L, 2, 0); - const char *value = tolua_tostring(L, 3, 0); - if (iname != NULL) { - const struct item_type *itype = it_find(iname); - if (itype != NULL) { - equipment_setitem(get_or_create_equipment(eqname), itype, value); - result = 0; - } - } - lua_pushinteger(L, result); - return 1; -} - static int tolua_spawn_braineaters(lua_State * L) { float chance = (float)tolua_tonumber(L, 1, 0); @@ -893,8 +846,13 @@ static int init_data(const char *filename) return 0; } +static int tolua_equip_newunits(lua_State * L) { + unit *u = (unit *)tolua_tousertype(L, 1, 0); + equip_newunits(u); + return 0; +} -int tolua_read_xml(lua_State * L) +static int tolua_read_xml(lua_State * L) { const char *filename = tolua_tostring(L, 1, "config.xml"); lua_pushinteger(L, init_data(filename)); @@ -1056,8 +1014,6 @@ int tolua_bindings_open(lua_State * L, const dictionary *inifile) tolua_function(L, TOLUA_CAST "set_turn", &tolua_set_turn); tolua_function(L, TOLUA_CAST "get_turn", &tolua_get_turn); tolua_function(L, TOLUA_CAST "get_season", tolua_get_season); - tolua_function(L, TOLUA_CAST "equipment_setitem", tolua_equipment_setitem); - tolua_function(L, TOLUA_CAST "equip_unit", tolua_equipunit); tolua_function(L, TOLUA_CAST "atoi36", tolua_atoi36); tolua_function(L, TOLUA_CAST "itoa36", tolua_itoa36); tolua_function(L, TOLUA_CAST "dice_roll", tolua_dice_rand); @@ -1068,12 +1024,12 @@ int tolua_bindings_open(lua_State * L, const dictionary *inifile) tolua_function(L, TOLUA_CAST "update_owners", tolua_update_owners); tolua_function(L, TOLUA_CAST "learn_skill", tolua_learn_skill); tolua_function(L, TOLUA_CAST "create_curse", tolua_create_curse); - tolua_function(L, TOLUA_CAST "autoseed", tolua_autoseed); tolua_function(L, TOLUA_CAST "get_key", tolua_getkey); tolua_function(L, TOLUA_CAST "set_key", tolua_setkey); tolua_function(L, TOLUA_CAST "translate", &tolua_translate); tolua_function(L, TOLUA_CAST "spells", tolua_get_spells); tolua_function(L, TOLUA_CAST "read_xml", tolua_read_xml); + tolua_function(L, TOLUA_CAST "equip_newunits", tolua_equip_newunits); } tolua_endmodule(L); return 1; } diff --git a/src/economy.c b/src/economy.c index a41b4525e..5fbb0111c 100644 --- a/src/economy.c +++ b/src/economy.c @@ -263,7 +263,7 @@ void add_recruits(unit * u, int number, int wanted) len = snprintf(equipment, sizeof(equipment), "new_%s", u_race(u)->_name); if (len > 0 && (size_t)len < sizeof(equipment)) { - equip_unit(unew, get_equipment(equipment)); + equip_unit(unew, equipment); } if (unew != u) { transfermen(unew, u, unew->number); diff --git a/src/helpers.c b/src/helpers.c index 3b966785b..8acabd97c 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -31,7 +31,6 @@ without prior permission by the authors of Eressea. #include #include #include -#include #include #include #include @@ -162,6 +161,36 @@ static void push_param(lua_State * L, char c, spllprm * param) } } +/** callback to use lua functions isntead of equipment */ +static bool lua_equipunit(unit *u, const char *eqname, int mask) { + lua_State *L = (lua_State *)global.vm_state; + bool result = false; + static bool disabled = false; + + if (disabled) { + return false; + } + lua_getglobal(L, "equip_unit"); + if (lua_isfunction(L, -1)) { + tolua_pushusertype(L, u, TOLUA_CAST "unit"); + lua_pushstring(L, eqname); + lua_pushinteger(L, mask); + if (lua_pcall(L, 3, 1, 0) != 0) { + const char *error = lua_tostring(L, -1); + log_error("equip(%s) with '%s/%d': %s.\n", unitname(u), eqname, mask, error); + lua_pop(L, 1); + } + else { + result = (bool)lua_toboolean(L, -1); + lua_pop(L, 1); + } + } + else { + disabled = true; + } + return result; +} + /** callback to use lua for spell functions */ static int lua_callspell(castorder * co, const char *fname) { @@ -346,6 +375,7 @@ void register_tolua_helpers(void) at_register(&at_direction); at_deprecate("lcbuilding", building_action_read); + callbacks.equip_unit = lua_equipunit; callbacks.cast_spell = lua_callspell; callbacks.use_item = use_item_callback; callbacks.produce_resource = produce_resource_lua; diff --git a/src/kernel/calendar.c b/src/kernel/calendar.c index 93722b5bc..e028580ff 100644 --- a/src/kernel/calendar.c +++ b/src/kernel/calendar.c @@ -47,7 +47,8 @@ const gamedate *get_gamedate(int turn_now, gamedate * gd) assert(gd); if (t<0) { - log_fatal("current turn %d is before first %d", + t = 0; + log_error("current turn %d is before first %d", turn_now, first_turn()); } assert(t>=0); diff --git a/src/kernel/callbacks.h b/src/kernel/callbacks.h index dcdf6ac90..1977cd284 100644 --- a/src/kernel/callbacks.h +++ b/src/kernel/callbacks.h @@ -19,6 +19,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_KRNL_CALLBACKS_H #define H_KRNL_CALLBACKS_H +#include + #ifdef __cplusplus extern "C" { #endif @@ -31,6 +33,7 @@ extern "C" { struct resource_type; struct callback_struct { + bool (*equip_unit)(struct unit *u, const char *eqname, int mask); int (*cast_spell)(struct castorder *co, const char *fname); int (*use_item)(struct unit *u, const struct item_type *itype, int amount, struct order *ord); diff --git a/src/kernel/config.c b/src/kernel/config.c index 8c7e64afe..54d030b76 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -30,7 +30,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "connection.h" #include "building.h" #include "direction.h" -#include "equipment.h" #include "faction.h" #include "group.h" #include "item.h" @@ -564,7 +563,6 @@ void kernel_done(void) attrib_done(); item_done(); message_done(); - equipment_done(); reports_done(); curses_done(); crmessage_done(); diff --git a/src/kernel/equipment.c b/src/kernel/equipment.c index 99c0bba7b..39e59bf43 100644 --- a/src/kernel/equipment.c +++ b/src/kernel/equipment.c @@ -21,11 +21,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "equipment.h" /* kernel includes */ -#include "item.h" -#include "unit.h" +#include "callbacks.h" #include "faction.h" +#include "item.h" #include "race.h" #include "spell.h" +#include "unit.h" /* util includes */ #include @@ -40,278 +41,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -void equipment_setskill(equipment * eq, skill_t sk, const char *value) +bool equip_unit(struct unit *u, const char *eqname) { - if (eq != NULL) { - if (value != NULL) { - eq->skills[sk] = str_strdup(value); - } - else if (eq->skills[sk]) { - free(eq->skills[sk]); - } - } + return equip_unit_mask(u, eqname, EQUIP_ALL); } -typedef struct lazy_spell { - struct spellref *spref; - int level; -} lazy_spell; - -void equipment_addspell(equipment * eq, const char * name, int level) +bool equip_unit_mask(struct unit *u, const char *eqname, int mask) { - if (eq) { - lazy_spell *ls = malloc(sizeof(lazy_spell)); - ls->spref = spellref_create(NULL, name); - ls->level = level; - selist_push(&eq->spells, ls); + if (callbacks.equip_unit) { + return callbacks.equip_unit(u, eqname, mask); } -} - -void -equipment_setitem(equipment * eq, const item_type * itype, const char *value) -{ - if (eq != NULL) { - if (itype != NULL) { - itemdata *idata = eq->items; - while (idata && idata->itype != itype) { - idata = idata->next; - } - if (idata == NULL) { - idata = (itemdata *)malloc(sizeof(itemdata)); - idata->itype = itype; - idata->value = str_strdup(value); - idata->next = eq->items; - eq->items = idata; - } - } - } -} - -void -equipment_setcallback(struct equipment *eq, -void(*callback) (const struct equipment *, struct unit *)) -{ - eq->callback = callback; -} - -void equip_unit(struct unit *u, const struct equipment *eq) -{ - equip_unit_mask(u, eq, EQUIP_ALL); -} - -void equip_unit_mask(struct unit *u, const struct equipment *eq, int mask) -{ - if (eq) { - - if (mask & EQUIP_SKILLS) { - int sk; - for (sk = 0; sk != MAXSKILLS; ++sk) { - if (eq->skills[sk] != NULL) { - int i = dice_rand(eq->skills[sk]); - if (i > 0) { - set_level(u, (skill_t)sk, i); - if (sk == SK_STAMINA) { - u->hp = unit_max_hp(u) * u->number; - } - } - } - } - } - - if (mask & EQUIP_SPELLS) { - if (eq->spells) { - selist * ql = eq->spells; - int qi; - sc_mage * mage = get_mage_depr(u); - - for (qi = 0; ql; selist_advance(&ql, &qi, 1)) { - lazy_spell *sbe = (lazy_spell *)selist_get(ql, qi); - spell *sp = spellref_get(sbe->spref); - unit_add_spell(u, mage, sp, sbe->level); - } - } - } - - if (mask & EQUIP_ITEMS) { - itemdata *idata; - for (idata = eq->items; idata != NULL; idata = idata->next) { - int i = u->number * dice_rand(idata->value); - if (i > 0) { - i_add(&u->items, i_new(idata->itype, i)); - } - } - } - - if (eq->subsets) { - int i; - for (i = 0; eq->subsets[i].sets; ++i) { - if (chance(eq->subsets[i].chance)) { - double rnd = (1 + rng_int() % 1000) / 1000.0; - int k; - for (k = 0; eq->subsets[i].sets[k].set; ++k) { - if (rnd <= eq->subsets[i].sets[k].chance) { - equip_unit_mask(u, eq->subsets[i].sets[k].set, mask); - break; - } - rnd -= eq->subsets[i].sets[k].chance; - } - } - } - } - - if (mask & EQUIP_SPECIAL) { - if (eq->callback) - eq->callback(eq, u); - } - } -} - -void equip_items(struct item **items, const struct equipment *eq) -{ - if (eq) { - itemdata *idata; - - for (idata = eq->items; idata != NULL; idata = idata->next) { - int i = dice_rand(idata->value); - if (i > 0) { - i_add(items, i_new(idata->itype, i)); - } - } - if (eq->subsets) { - int i; - for (i = 0; eq->subsets[i].sets; ++i) { - if (chance(eq->subsets[i].chance)) { - double rnd = (1 + rng_int() % 1000) / 1000.0; - int k; - for (k = 0; eq->subsets[i].sets[k].set; ++k) { - if (rnd <= eq->subsets[i].sets[k].chance) { - equip_items(items, eq->subsets[i].sets[k].set); - break; - } - rnd -= eq->subsets[i].sets[k].chance; - } - } - } - } - } -} - -void free_ls(void *arg) { - lazy_spell *ls = (lazy_spell*)arg; - spellref_free(ls->spref); - free(ls); -} - -static critbit_tree cb_equipments = { 0 }; - -#define EQNAMELEN 24 - -typedef struct eq_entry { - char key[EQNAMELEN]; - equipment *value; -} eq_entry; - -typedef struct name_cb_data { - const equipment *find; - const char *result; -} name_cb_data; - - -static int equipment_name_cb(const void * match, const void * key, size_t keylen, void *cbdata) { - const eq_entry *ent = (const eq_entry *)match; - name_cb_data *query = (name_cb_data *)cbdata; - if (ent->value == query->find) { - query->result = ent->key; - return 1; - } - return 0; -} - -const char *equipment_name(const struct equipment *eq) -{ - name_cb_data data; - - data.find = eq; - data.result = NULL; - cb_foreach(&cb_equipments, "", 0, equipment_name_cb, &data); - return data.result; -} - -equipment *get_equipment(const char *eqname) -{ - const void *match; - - if (strlen(eqname) >= EQNAMELEN) { - log_warning("equipment name is longer than %d bytes: %s", EQNAMELEN - 1, eqname); - return NULL; - } - - match = cb_find_str(&cb_equipments, eqname); - if (match) { - const eq_entry *ent = (const eq_entry *)match; - return ent->value; - } - return NULL; -} - -equipment *create_equipment(const char *eqname) -{ - size_t len = strlen(eqname); - eq_entry ent; - - if (len >= EQNAMELEN) { - log_error("equipment name is longer than %d bytes: %s", EQNAMELEN-1, eqname); - len = EQNAMELEN-1; - } - memset(ent.key, 0, EQNAMELEN); - memcpy(ent.key, eqname, len); - - ent.value = (equipment *)calloc(1, sizeof(equipment)); - - cb_insert(&cb_equipments, &ent, sizeof(ent)); - return ent.value; -} - -equipment *get_or_create_equipment(const char *eqname) -{ - equipment *eq = get_equipment(eqname); - if (!eq) { - return create_equipment(eqname); - } - return eq; -} - -static void free_equipment(equipment *eq) { - int i; - if (eq->spells) { - selist_foreach(eq->spells, free_ls); - selist_free(eq->spells); - } - while (eq->items) { - itemdata *next = eq->items->next; - free(eq->items->value); - free(eq->items); - eq->items = next; - } - if (eq->subsets) { - for (i = 0; eq->subsets[i].sets; ++i) { - free(eq->subsets[i].sets); - } - free(eq->subsets); - } - for (i = 0; i != MAXSKILLS; ++i) { - free(eq->skills[i]); - } -} - -static int free_equipment_cb(const void * match, const void * key, size_t keylen, void *cbdata) { - const eq_entry * ent = (const eq_entry *)match; - free_equipment(ent->value); - free(ent->value); - return 0; -} - -void equipment_done(void) { - cb_foreach(&cb_equipments, "", 0, free_equipment_cb, 0); - cb_clear(&cb_equipments); + return false; } diff --git a/src/kernel/equipment.h b/src/kernel/equipment.h index 9fbffe67f..7c95b8f67 100644 --- a/src/kernel/equipment.h +++ b/src/kernel/equipment.h @@ -19,63 +19,20 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_KRNL_EQUIPMENT_H #define H_KRNL_EQUIPMENT_H -#include "skill.h" +#include #ifdef __cplusplus extern "C" { #endif - struct spell; - struct item; struct unit; - typedef struct itemdata { - const struct item_type *itype; - char *value; - struct itemdata *next; - } itemdata; - - typedef struct subsetitem { - struct equipment *set; - float chance; - } subsetitem; - - typedef struct subset { - float chance; - subsetitem *sets; - } subset; - - typedef struct equipment { - struct itemdata *items; - char *skills[MAXSKILLS]; - struct selist *spells; - struct subset *subsets; - void(*callback) (const struct equipment *, struct unit *); - } equipment; - - void equipment_done(void); - - const char *equipment_name(const struct equipment *eq); - struct equipment *get_or_create_equipment(const char *eqname); - struct equipment *get_equipment(const char *eqname); - struct equipment *create_equipment(const char *eqname); - - void equipment_setitem(struct equipment *eq, - const struct item_type *itype, const char *value); - void equipment_setskill(struct equipment *eq, skill_t sk, - const char *value); - void equipment_addspell(struct equipment *eq, const char *name, int level); - void equipment_setcallback(struct equipment *eq, - void(*callback) (const struct equipment *, struct unit *)); - - void equip_unit(struct unit *u, const struct equipment *eq); #define EQUIP_SKILLS (1<<1) #define EQUIP_SPELLS (1<<2) #define EQUIP_ITEMS (1<<3) #define EQUIP_SPECIAL (1<<4) #define EQUIP_ALL (0xFF) - void equip_unit_mask(struct unit *u, const struct equipment *eq, - int mask); - void equip_items(struct item **items, const struct equipment *eq); + bool equip_unit_mask(struct unit *u, const char *eqname, int mask); + bool equip_unit(struct unit *u, const char *eqname); #ifdef __cplusplus } diff --git a/src/kernel/equipment.test.c b/src/kernel/equipment.test.c index 1a1bbfdf1..331625c14 100644 --- a/src/kernel/equipment.test.c +++ b/src/kernel/equipment.test.c @@ -2,6 +2,7 @@ #include "magic.h" +#include #include #include #include @@ -10,62 +11,40 @@ #include #include -static void test_equipment(CuTest * tc) -{ - equipment * eq; - unit * u; - const item_type * it_horses; - spell *sp; - sc_mage * mage; +static unit *eq_unit; +static const char *eq_name; +static int eq_mask; - test_setup(); - test_create_race("human"); - enable_skill(SK_MAGIC, true); - it_horses = test_create_itemtype("horse"); - CuAssertPtrNotNull(tc, it_horses); - sp = create_spell("testspell"); - CuAssertPtrNotNull(tc, sp); - - CuAssertPtrEquals(tc, 0, get_equipment("herpderp")); - eq = get_or_create_equipment("herpderp"); - CuAssertPtrEquals(tc, eq, get_equipment("herpderp")); - - equipment_setitem(eq, it_horses, "1"); - equipment_setskill(eq, SK_MAGIC, "5"); - equipment_addspell(eq, sp->sname, 1); - - u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); - equip_unit_mask(u, eq, EQUIP_ALL); - CuAssertIntEquals(tc, 1, i_get(u->items, it_horses)); - CuAssertIntEquals(tc, 5, get_level(u, SK_MAGIC)); - - mage = get_mage_depr(u); - CuAssertPtrNotNull(tc, mage); - CuAssertPtrNotNull(tc, mage->spellbook); - CuAssertTrue(tc, u_hasspell(u, sp)); - test_teardown(); +static bool equip_callback(unit *u, const char *eqname, int mask) { + eq_unit = u; + eq_name = eqname; + eq_mask = mask; + return true; } -static void test_get_equipment(CuTest * tc) +static void test_equipment(CuTest * tc) { - equipment * eq; + callbacks.equip_unit = equip_callback; + unit * u; test_setup(); - eq = create_equipment("catapultammo123"); - CuAssertPtrNotNull(tc, eq); - CuAssertStrEquals(tc, "catapultammo123", equipment_name(eq)); - eq = get_equipment("catapultammo123"); - CuAssertPtrNotNull(tc, eq); - CuAssertStrEquals(tc, "catapultammo123", equipment_name(eq)); - eq = get_equipment("catapult"); - CuAssertPtrEquals(tc, NULL, eq); - eq = create_equipment("catapult"); - CuAssertPtrNotNull(tc, eq); - CuAssertPtrEquals(tc, eq, get_equipment("catapult")); - CuAssertStrEquals(tc, "catapult", equipment_name(eq)); - eq = get_equipment("catapultammo123"); - CuAssertPtrNotNull(tc, eq); - CuAssertStrEquals(tc, "catapultammo123", equipment_name(eq)); + + u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); + CuAssertIntEquals(tc, true, equip_unit_mask(u, "hodor", EQUIP_ALL)); + CuAssertIntEquals(tc, EQUIP_ALL, eq_mask); + CuAssertPtrEquals(tc, u, eq_unit); + CuAssertStrEquals(tc, "hodor", eq_name); + + CuAssertIntEquals(tc, true, equip_unit_mask(u, "foobar", EQUIP_ITEMS)); + CuAssertIntEquals(tc, EQUIP_ITEMS, eq_mask); + CuAssertPtrEquals(tc, u, eq_unit); + CuAssertStrEquals(tc, "foobar", eq_name); + + CuAssertIntEquals(tc, true, equip_unit(u, "unknown")); + CuAssertIntEquals(tc, EQUIP_ALL, eq_mask); + CuAssertPtrEquals(tc, u, eq_unit); + CuAssertStrEquals(tc, "unknown", eq_name); + test_teardown(); } @@ -73,6 +52,5 @@ CuSuite *get_equipment_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_equipment); - SUITE_ADD_TEST(suite, test_get_equipment); return suite; } diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 43c25d440..bc08ba010 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -285,7 +285,6 @@ unit *addplayer(region * r, faction * f) { unit *u; const char * name; - const struct equipment* eq; assert(r->land); if (rpeasants(r) < PEASANT_MIN) { @@ -296,10 +295,7 @@ unit *addplayer(region * r, faction * f) faction_setorigin(f, 0, r->x, r->y); u = create_unit(r, f, 1, f->race, 0, NULL, NULL); name = config_get("rules.equip_first"); - eq = get_equipment(name ? name : "first_unit"); - if (eq) { - equip_items(&u->items, eq); - } + equip_unit(u, name ? name : "first_unit"); u->hp = unit_max_hp(u) * u->number; fset(u, UFL_ISNEW); if (f->race == get_race(RC_DAEMON)) { diff --git a/src/kernel/region.c b/src/kernel/region.c index 7ceab2f18..68b47d7a2 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -1091,7 +1091,6 @@ void terraform_region(region * r, const terrain_type * terrain) rsethorses(r, 0); rsetpeasants(r, 0); rsetmoney(r, 0); - freset(r, RF_ENCOUNTER); freset(r, RF_MALLORN); return; } @@ -1195,9 +1194,6 @@ void terraform_region(region * r, const terrain_type * terrain) fset(r, RF_MALLORN); else freset(r, RF_MALLORN); - if (rng_int() % 100 < ENCCHANCE) { - fset(r, RF_ENCOUNTER); - } } } diff --git a/src/kernel/region.h b/src/kernel/region.h index d37da2290..9543658d9 100644 --- a/src/kernel/region.h +++ b/src/kernel/region.h @@ -42,7 +42,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define RF_UNUSED_7 (1<<7) #define RF_UNUSED_8 (1<<8) -#define RF_ENCOUNTER (1<<9) /* persistent */ #define RF_MAPPER_HIGHLIGHT (1<<10) #define RF_LIGHTHOUSE (1<<11) /* this region may contain a lighthouse */ #define RF_MIGRATION (1<<13) @@ -58,7 +57,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define RF_ALL 0xFFFFFF -#define RF_SAVEMASK (RF_CHAOTIC|RF_MALLORN|RF_BLOCKED|RF_ENCOUNTER|RF_GUARDED|RF_LIGHTHOUSE) +#define RF_SAVEMASK (RF_CHAOTIC|RF_MALLORN|RF_BLOCKED|RF_GUARDED|RF_LIGHTHOUSE) struct message; struct message_list; struct rawmaterial; diff --git a/src/kernel/save.c b/src/kernel/save.c index 858cd7040..b43d9bd5d 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -27,7 +27,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "building.h" #include "calendar.h" #include "connection.h" -#include "equipment.h" #include "faction.h" #include "group.h" #include "item.h" @@ -1331,29 +1330,7 @@ static void fix_familiars(void) { /* unit is potentially a familiar */ attrib * a = a_find(u->attribs, &at_mage); attrib * am = a_find(u->attribs, &at_familiarmage); - if (am) { - sc_mage *mage = a ? (sc_mage *)a->data.v : NULL; - /* a familiar */ - if (!mage) { - log_error("%s seems to be a familiar with no magic.", - unitname(u)); - mage = create_mage(u, M_GRAY); - } - if (!mage->spellbook) { - char eqname[32]; - equipment *eq; - - snprintf(eqname, sizeof(eqname), "fam_%s", u->_race->_name); - eq = get_equipment(eqname); - if (eq && eq->spells) { - log_error("%s seems to be a familiar with no spells.", - unitname(u)); - /* magical familiar, no spells */ - equip_unit_mask(u, eq, EQUIP_SPELLS); - } - } - } - else if (a) { + if (!am && a) { /* not a familiar, but magical */ attrib * ae = a_find(u->attribs, &at_eventhandler); if (ae) { diff --git a/src/laws.c b/src/laws.c index ea3fdf3c2..aa6e237e2 100644 --- a/src/laws.c +++ b/src/laws.c @@ -4040,11 +4040,6 @@ void init_processor(void) p += 10; add_proc_order(p, K_GUARD, guard_on_cmd, 0, "Bewache (an)"); - if (config_get_int("rules.encounters", 0)) { - p += 10; - add_proc_global(p, encounters, "Zufallsbegegnungen"); - } - p += 10; add_proc_unit(p, monster_kills_peasants, "Monster fressen und vertreiben Bauern"); diff --git a/src/magic.c b/src/magic.c index 1074192a8..7464e286d 100644 --- a/src/magic.c +++ b/src/magic.c @@ -2181,18 +2181,13 @@ void remove_familiar(unit * mage) void create_newfamiliar(unit * mage, unit * fam) { /* skills and spells: */ - const struct equipment *eq; char eqname[64]; const race *rc = u_race(fam); set_familiar(mage, fam); snprintf(eqname, sizeof(eqname), "fam_%s", rc->_name); - eq = get_equipment(eqname); - if (eq != NULL) { - equip_unit(fam, eq); - } - else { + if (!equip_unit(fam, eqname)) { log_info("could not perform initialization for familiar %s.\n", rc->_name); } /* TODO: Diese Attribute beim Tod des Familiars entfernen: */ diff --git a/src/magic.test.c b/src/magic.test.c index 5533d93ec..95c2d250d 100644 --- a/src/magic.test.c +++ b/src/magic.test.c @@ -4,6 +4,7 @@ #include "teleport.h" #include "give.h" +#include #include #include #include @@ -556,39 +557,32 @@ static void test_familiar_age(CuTest *tc) { test_teardown(); } +static unit *eq_unit; +static char *eq_name; +static int eq_mask; + +static bool equip_callback(unit *u, const char *eqname, int mask) { + eq_unit = u; + eq_name = str_strdup(eqname); + eq_mask = mask; + return true; +} + static void test_familiar_equip(CuTest *tc) { unit *mag, *u; - equipment *eq; - const item_type * itype; - spell *sp; - sc_mage * mage; test_setup(); - - itype = test_create_itemtype("horse"); - CuAssertPtrNotNull(tc, itype); - sp = create_spell("testspell"); - CuAssertPtrNotNull(tc, sp); - - eq = get_or_create_equipment("fam_human"); - equipment_setitem(eq, itype, "1"); - equipment_setskill(eq, SK_ENTERTAINMENT, "5"); - equipment_addspell(eq, sp->sname, 1); - + callbacks.equip_unit = equip_callback; mag = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); u = test_create_unit(mag->faction, test_create_region(0, 0, NULL)); + CuAssertStrEquals(tc, "human", u->_race->_name); set_familiar(mag, u); create_newfamiliar(mag, u); - CuAssertIntEquals(tc, 1, i_get(u->items, itype)); - CuAssertIntEquals(tc, 5, get_level(u, SK_ENTERTAINMENT)); - CuAssertIntEquals(tc, 0, get_level(u, SK_MAGIC)); - mage = get_mage(u); - CuAssertPtrNotNull(tc, mage); - CuAssertPtrNotNull(tc, mage->spellbook); - set_level(u, SK_MAGIC, 1); - CuAssertPtrEquals(tc, mage, get_mage_depr(u)); - CuAssertTrue(tc, u_hasspell(u, sp)); + CuAssertIntEquals(tc, EQUIP_ALL, eq_mask); + CuAssertPtrEquals(tc, u, eq_unit); + CuAssertStrEquals(tc, "fam_human", eq_name); + free(eq_name); test_teardown(); } diff --git a/src/monsters.c b/src/monsters.c index 46f63a92d..00a733677 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -612,7 +612,7 @@ static void recruit_dracoids(unit * dragon, int size) name_unit(un); change_money(dragon, -un->number * 50); - equip_unit(un, get_equipment("new_dracoid")); + equip_unit(un, "new_dracoid"); unit_setstatus(un, ST_FIGHT); for (weapon = un->items; weapon; weapon = weapon->next) { @@ -864,7 +864,7 @@ static int nrand(int handle_start, int sub) unit *spawn_seaserpent(region *r, faction *f) { unit *u = create_unit(r, f, 1, get_race(RC_SEASERPENT), 0, NULL, NULL); fset(u, UFL_ISNEW | UFL_MOVED); - equip_unit(u, get_equipment("seed_seaserpent")); + equip_unit(u, "seed_seaserpent"); return u; } @@ -903,7 +903,7 @@ void spawn_dragons(void) u = create_unit(r, monsters, nrand(30, 20) + 1, get_race(RC_DRAGON), 0, NULL, NULL); } fset(u, UFL_ISNEW | UFL_MOVED); - equip_unit(u, get_equipment("seed_dragon")); + equip_unit(u, "seed_dragon"); log_debug("spawning %d %s in %s.\n", u->number, LOC(default_locale, @@ -965,7 +965,7 @@ void spawn_undead(void) fset(u, UFL_ISNEW | UFL_MOVED); if ((rc == get_race(RC_SKELETON) || rc == get_race(RC_ZOMBIE)) && rng_int() % 10 < 4) { - equip_unit(u, get_equipment("rising_undead")); + equip_unit(u, "rising_undead"); } for (i = 0; i < MAXSKILLS; i++) { diff --git a/src/races/races.c b/src/races/races.c index 92a3d3e3d..120a15dd9 100644 --- a/src/races/races.c +++ b/src/races/races.c @@ -12,7 +12,6 @@ #include "races.h" #include -#include #include #include #include @@ -36,7 +35,7 @@ void age_skeleton(struct unit *u); void age_zombie(struct unit *u); void age_ghoul(struct unit *u); -static void equip_newunits(const struct equipment *eq, struct unit *u) +void equip_newunits(struct unit *u) { struct region *r = u->region; const struct resource_type *rtype; @@ -81,8 +80,6 @@ static void equip_newunits(const struct equipment *eq, struct unit *u) * in die jeweilige Rassendefiniton eingebunden */ void register_races(void) { - register_function((pf_generic)equip_newunits, "equip_newunits"); - /* function age for race->age() */ register_function((pf_generic)age_undead, "age_undead"); register_function((pf_generic)age_skeleton, "age_skeleton"); diff --git a/src/races/races.h b/src/races/races.h index ea7be1337..78c8b062f 100644 --- a/src/races/races.h +++ b/src/races/races.h @@ -18,6 +18,7 @@ extern "C" { void register_races(void); void make_undead_unit(struct unit *); + void equip_newunits(struct unit *u); #ifdef __cplusplus } diff --git a/src/randenc.c b/src/randenc.c index 9630d6e85..7de49b9e2 100644 --- a/src/randenc.c +++ b/src/randenc.c @@ -155,267 +155,6 @@ static void dissolve_units(void) remove_empty_units(); } -static bool improve_all(faction * f, skill_t sk, int by_weeks) -{ - unit *u; - bool result = false; - for (u = f->units; u; u = u->nextF) { - if (has_skill(u, sk)) { - increase_skill(u, sk, by_weeks); - result = true; - } - } - return result; -} - -void find_manual(region * r, unit * u) -{ - char zLocation[32]; - char zBook[32]; - skill_t skill = NOSKILL; - message *msg; - - switch (rng_int() % 36) { - case 0: - skill = SK_MAGIC; - break; - case 1: - case 2: - case 3: - case 4: - skill = SK_WEAPONSMITH; - break; - case 5: - case 6: - skill = SK_TACTICS; - break; - case 7: - case 8: - case 9: - case 10: - skill = SK_SHIPBUILDING; - break; - case 11: - case 12: - case 13: - case 14: - skill = SK_SAILING; - break; - case 15: - case 16: - case 17: - skill = SK_HERBALISM; - break; - case 18: - case 19: - skill = SK_ALCHEMY; - break; - case 20: - case 21: - case 22: - case 23: - skill = SK_BUILDING; - break; - case 24: - case 25: - case 26: - case 27: - skill = SK_ARMORER; - break; - case 28: - case 29: - case 30: - case 31: - skill = SK_MINING; - break; - case 32: - case 33: - case 34: - case 35: - skill = SK_ENTERTAINMENT; - break; - } - - snprintf(zLocation, sizeof(zLocation), "manual_location_%d", - (int)(rng_int() % 4)); - snprintf(zBook, sizeof(zLocation), "manual_title_%s", skillnames[skill]); - - msg = msg_message("find_manual", "unit location book", u, zLocation, zBook); - if (msg) { - r_addmessage(r, u->faction, msg); - msg_release(msg); - } - - if (!improve_all(u->faction, skill, 3)) { - increase_skill(u, skill, 9); - } -} - -static void get_villagers(region * r, unit * u) -{ - unit *newunit; - message *msg = msg_message("encounter_villagers", "unit", u); - const char *name = LOC(u->faction->locale, "villagers"); - - r_addmessage(r, u->faction, msg); - msg_release(msg); - - newunit = - create_unit(r, u->faction, rng_int() % 20 + 3, u->faction->race, 0, name, - u); - leave(newunit, true); - fset(newunit, UFL_ISNEW | UFL_MOVED); - equip_unit(newunit, get_equipment("rand_villagers")); -} - -static void get_allies(region * r, unit * u) -{ - unit *newunit = NULL; - const char *name; - const char *equip; - int number; - message *msg; - - assert(u->number); - - switch (rterrain(r)) { - case T_PLAIN: - if (!r_isforest(r)) { - if (get_money(u) / u->number < 100 + rng_int() % 200) - return; - name = "random_plain_men"; - equip = "rand_plain"; - number = rng_int() % 8 + 2; - break; - } - else { - if (effskill(u, SK_LONGBOW, r) < 3 - && effskill(u, SK_HERBALISM, r) < 2 - && effskill(u, SK_MAGIC, r) < 2) { - return; - } - name = "random_forest_men"; - equip = "rand_forest"; - number = rng_int() % 6 + 2; - } - break; - - case T_SWAMP: - if (effskill(u, SK_MELEE, r) <= 1) { - return; - } - name = "random_swamp_men"; - equip = "rand_swamp"; - number = rng_int() % 6 + 2; - break; - - case T_DESERT: - if (effskill(u, SK_RIDING, r) <= 2) { - return; - } - name = "random_desert_men"; - equip = "rand_desert"; - number = rng_int() % 12 + 2; - break; - - case T_HIGHLAND: - if (effskill(u, SK_MELEE, r) <= 1) { - return; - } - name = "random_highland_men"; - equip = "rand_highland"; - number = rng_int() % 8 + 2; - break; - - case T_MOUNTAIN: - if (effskill(u, SK_MELEE, r) <= 1 || effskill(u, SK_TRADE, r) <= 2) { - return; - } - name = "random_mountain_men"; - equip = "rand_mountain"; - number = rng_int() % 6 + 2; - break; - - case T_GLACIER: - if (effskill(u, SK_MELEE, r) <= 1 || effskill(u, SK_TRADE, r) <= 1) { - return; - } - name = "random_glacier_men"; - equip = "rand_glacier"; - number = rng_int() % 4 + 2; - break; - - default: - return; - } - - newunit = - create_unit(r, u->faction, number, u->faction->race, 0, - LOC(u->faction->locale, name), u); - equip_unit(newunit, get_equipment(equip)); - - u_setfaction(newunit, u->faction); - set_racename(&newunit->attribs, get_racename(u->attribs)); - if (u_race(u)->flags & RCF_SHAPESHIFT) { - newunit->irace = u->irace; - } - if (fval(u, UFL_ANON_FACTION)) - fset(newunit, UFL_ANON_FACTION); - fset(newunit, UFL_ISNEW); - - msg = msg_message("encounter_allies", "unit name", u, name); - r_addmessage(r, u->faction, msg); - msg_release(msg); -} - -static void encounter(region * r, unit * u) -{ - if (!fval(r, RF_ENCOUNTER)) - return; - freset(r, RF_ENCOUNTER); - if (rng_int() % 100 >= ENCCHANCE) - return; - switch (rng_int() % 3) { - case 0: - find_manual(r, u); - break; - case 1: - get_villagers(r, u); - break; - case 2: - get_allies(r, u); - break; - } -} - -void encounters(void) -{ - region *r; - - for (r = regions; r; r = r->next) { - if (fval(r->terrain, LAND_REGION) && fval(r, RF_ENCOUNTER)) { - int c = 0; - unit *u; - for (u = r->units; u; u = u->next) { - c += u->number; - } - - if (c > 0) { - int i = 0; - int n = rng_int() % c; - - for (u = r->units; u; u = u->next) { - if (i + u->number > n) - break; - i += u->number; - } - assert(u && u->number); - encounter(r, u); - } - } - } -} - void drown(region * r) { if (fval(r->terrain, SEA_REGION)) { @@ -611,7 +350,7 @@ static void move_icebergs(void) } } -void create_icebergs(void) +static void create_icebergs(void) { region *r; const struct terrain_type *t_iceberg, *t_sleep; @@ -763,9 +502,8 @@ static void icebergs(void) move_icebergs(); } -#define HERBS_ROT /* herbs owned by units have a chance to rot. */ #define HERBROTCHANCE 5 /* Verrottchance f�r Kr�uter (ifdef HERBS_ROT) */ -#ifdef HERBS_ROT + static void rotting_herbs(void) { region *r; @@ -798,7 +536,6 @@ static void rotting_herbs(void) } } } -#endif void randomevents(void) { @@ -842,9 +579,7 @@ void randomevents(void) } chaos_update(); -#ifdef HERBS_ROT rotting_herbs(); -#endif dissolve_units(); } diff --git a/src/randenc.h b/src/randenc.h index cc799db5f..3814a520d 100644 --- a/src/randenc.h +++ b/src/randenc.h @@ -30,7 +30,6 @@ extern "C" { #define PLAGUE_HEALCHANCE 0.25 /* Wahrscheinlichkeit Heilung */ #define PLAGUE_HEALCOST 30 /* Heilkosten */ void plagues(struct region *r); - void encounters(void); void randomevents(void); #ifdef __cplusplus diff --git a/src/settings.h b/src/settings.h index 0a017dd7a..57edb1566 100644 --- a/src/settings.h +++ b/src/settings.h @@ -31,6 +31,5 @@ /* Gebaeudegroesse = Minimalbelagerer */ #define SIEGEFACTOR 2 -#define ENCCHANCE 10 /* %-Chance fuer einmalige Zufallsbegegnung */ #define BAGCAPACITY 20000 /* soviel passt in einen Bag of Holding */ #define PERSON_WEIGHT 1000 /* weight of a "normal" human unit */ diff --git a/src/teleport.c b/src/teleport.c index 439b44955..36634c5cd 100644 --- a/src/teleport.c +++ b/src/teleport.c @@ -181,7 +181,7 @@ void spawn_braineaters(float chance) if (next-- == 0) { u = create_unit(r, f, 1 + rng_int() % 10 + rng_int() % 10, rc_brain, 0, NULL, NULL); - equip_unit(u, get_equipment("seed_braineater")); + equip_unit(u, "seed_braineater"); next = rng_int() % (int)(chance * 100); } diff --git a/src/tests.c b/src/tests.c index ad9f8eddf..3fb7c9395 100644 --- a/src/tests.c +++ b/src/tests.c @@ -212,7 +212,6 @@ static void test_reset(void) { free_config(); default_locale = 0; calendar_cleanup(); - equipment_done(); close_orders(); free_special_directions(); free_locales(); @@ -257,6 +256,7 @@ void test_setup_test(CuTest *tc, const char *file, int line) { else { log_debug("start test in %s:%d", file, line); } + errno = 0; } void test_teardown(void) diff --git a/src/xmlreader.c b/src/xmlreader.c index b0a0aafcc..43823f48a 100644 --- a/src/xmlreader.c +++ b/src/xmlreader.c @@ -16,7 +16,6 @@ without prior permission by the authors of Eressea. #include "xmlreader.h" #include "kernel/building.h" -#include "kernel/equipment.h" #include "kernel/item.h" #include "kernel/messages.h" #include "kernel/race.h" @@ -856,227 +855,6 @@ static int parse_resources(xmlDocPtr doc) return results; } -static void add_items(equipment * eq, xmlNodeSetPtr nsetItems) -{ - if (nsetItems != NULL && nsetItems->nodeNr > 0) { - int i; - for (i = 0; i != nsetItems->nodeNr; ++i) { - xmlNodePtr node = nsetItems->nodeTab[i]; - xmlChar *propValue; - const struct item_type *itype; - struct resource_type *rtype; - - propValue = xmlGetProp(node, BAD_CAST "name"); - assert(propValue != NULL); - rtype = rt_get_or_create((const char *)propValue); - itype = it_get_or_create(rtype); - xmlFree(propValue); - if (itype != NULL) { - propValue = xmlGetProp(node, BAD_CAST "amount"); - if (propValue != NULL) { - equipment_setitem(eq, itype, (const char *)propValue); - xmlFree(propValue); - } - } - } - } -} - -static void add_callbacks(equipment * eq, xmlNodeSetPtr nsetItems) -{ - if (nsetItems != NULL && nsetItems->nodeNr > 0) { - int i; - for (i = 0; i != nsetItems->nodeNr; ++i) { - xmlNodePtr node = nsetItems->nodeTab[i]; - xmlChar *propValue; - pf_generic fun; - - propValue = xmlGetProp(node, BAD_CAST "name"); - if (propValue != NULL) { - fun = get_function((const char *)propValue); - if (fun) { - equipment_setcallback(eq, (void(*)(const struct equipment *, - struct unit *))fun); - } - xmlFree(propValue); - } - } - } -} - -static void add_spells(equipment * eq, xmlNodeSetPtr nsetItems) -{ - if (nsetItems != NULL && nsetItems->nodeNr > 0) { - int i; - for (i = 0; i != nsetItems->nodeNr; ++i) { - xmlNodePtr node = nsetItems->nodeTab[i]; - xmlChar *propValue; - int level; - const char *name; - - propValue = xmlGetProp(node, BAD_CAST "name"); - assert(propValue != NULL); - name = (const char *)propValue; - level = xml_ivalue(node, "level", 0); - if (level > 0) { - equipment_addspell(eq, name, level); - } - else { - log_error("spell '%s' for equipment-set '%s' has no level\n", name, equipment_name(eq)); - } - xmlFree(propValue); - } - } -} - -static void add_skills(equipment * eq, xmlNodeSetPtr nsetSkills) -{ - if (nsetSkills != NULL && nsetSkills->nodeNr > 0) { - int i; - for (i = 0; i != nsetSkills->nodeNr; ++i) { - xmlNodePtr node = nsetSkills->nodeTab[i]; - xmlChar *propValue; - skill_t sk; - - propValue = xmlGetProp(node, BAD_CAST "name"); - assert(propValue != NULL); - sk = findskill((const char *)propValue); - if (sk == NOSKILL) { - log_error("unknown skill '%s' in equipment-set %s\n", (const char *)propValue, equipment_name(eq)); - xmlFree(propValue); - } - else { - xmlFree(propValue); - propValue = xmlGetProp(node, BAD_CAST "level"); - if (propValue != NULL) { - equipment_setskill(eq, sk, (const char *)propValue); - xmlFree(propValue); - } - } - } - } -} - -static void -add_subsets(xmlDocPtr doc, equipment * eq, xmlNodeSetPtr nsetSubsets) -{ - xmlXPathContextPtr xpath = xmlXPathNewContext(doc); - if (nsetSubsets != NULL && nsetSubsets->nodeNr > 0) { - int i; - - eq->subsets = calloc(nsetSubsets->nodeNr + 1, sizeof(subset)); - for (i = 0; i != nsetSubsets->nodeNr; ++i) { - xmlXPathObjectPtr xpathResult; - xmlNodePtr node = nsetSubsets->nodeTab[i]; - xmlChar *propValue; - - eq->subsets[i].chance = 1.0f; - propValue = xmlGetProp(node, BAD_CAST "chance"); - if (propValue != NULL) { - eq->subsets[i].chance = (float)atof((const char *)propValue); - xmlFree(propValue); - } - xpath->node = node; - xpathResult = xmlXPathEvalExpression(BAD_CAST "set", xpath); - if (xpathResult->nodesetval) { - xmlNodeSetPtr nsetSets = xpathResult->nodesetval; - float totalChance = 0.0f; - - if (nsetSets->nodeNr > 0) { - int set; - eq->subsets[i].sets = - calloc(nsetSets->nodeNr + 1, sizeof(subsetitem)); - for (set = 0; set != nsetSets->nodeNr; ++set) { - xmlNodePtr nodeSet = nsetSets->nodeTab[set]; - float chance = 1.0f; - - propValue = xmlGetProp(nodeSet, BAD_CAST "chance"); - if (propValue != NULL) { - chance = (float)atof((const char *)propValue); - xmlFree(propValue); - } - totalChance += chance; - - propValue = xmlGetProp(nodeSet, BAD_CAST "name"); - assert(propValue != NULL); - eq->subsets[i].sets[set].chance = chance; - eq->subsets[i].sets[set].set = - get_or_create_equipment((const char *)propValue); - xmlFree(propValue); - } - } - if (totalChance > 1.0f) { - log_error("total chance exceeds 1.0: %f in equipment set %s.\n", totalChance, equipment_name(eq)); - } - } - xmlXPathFreeObject(xpathResult); - } - } - xmlXPathFreeContext(xpath); -} - -static int parse_equipment(xmlDocPtr doc) -{ - xmlXPathContextPtr xpath = xmlXPathNewContext(doc); - xmlXPathObjectPtr xpathRaces; - int result = 0; - - /* reading eressea/equipment/set */ - xpathRaces = xmlXPathEvalExpression(BAD_CAST "/eressea/equipment/set", xpath); - if (xpathRaces->nodesetval) { - xmlNodeSetPtr nsetRaces = xpathRaces->nodesetval; - int i; - - result += nsetRaces->nodeNr; - for (i = 0; i != nsetRaces->nodeNr; ++i) { - xmlNodePtr node = nsetRaces->nodeTab[i]; - xmlChar *propName = xmlGetProp(node, BAD_CAST "name"); - - if (propName != NULL) { - equipment *eq = get_equipment((const char *)propName); - xmlXPathObjectPtr xpathResult; - - if (!eq) { - eq = create_equipment((const char *)propName); - } - - xpath->node = node; - - xpathResult = xmlXPathEvalExpression(BAD_CAST "callback", xpath); - assert(!eq->callback); - add_callbacks(eq, xpathResult->nodesetval); - xmlXPathFreeObject(xpathResult); - - xpathResult = xmlXPathEvalExpression(BAD_CAST "item", xpath); - assert(!eq->items); - add_items(eq, xpathResult->nodesetval); - xmlXPathFreeObject(xpathResult); - - xpathResult = xmlXPathEvalExpression(BAD_CAST "spell", xpath); - assert(!eq->spells); - add_spells(eq, xpathResult->nodesetval); - xmlXPathFreeObject(xpathResult); - - xpathResult = xmlXPathEvalExpression(BAD_CAST "skill", xpath); - add_skills(eq, xpathResult->nodesetval); - xmlXPathFreeObject(xpathResult); - - xpathResult = xmlXPathEvalExpression(BAD_CAST "subset", xpath); - assert(!eq->subsets); - add_subsets(doc, eq, xpathResult->nodesetval); - xmlXPathFreeObject(xpathResult); - - xmlFree(propName); - } - } - } - - xmlXPathFreeObject(xpathRaces); - xmlXPathFreeContext(xpath); - - return result; -} - static int parse_spellbooks(xmlDocPtr doc) { xmlXPathContextPtr xpath = xmlXPathNewContext(doc); @@ -1697,7 +1475,6 @@ void register_xmlreader(void) xml_register_callback(parse_spells); xml_register_callback(parse_races); #endif - xml_register_callback(parse_equipment); xml_register_callback(parse_strings);