windows/linux merge

This commit is contained in:
Enno Rehling 2020-05-02 11:18:49 +02:00
commit 62531107ae
64 changed files with 759 additions and 677 deletions

15
doc/befehle.txt Normal file
View File

@ -0,0 +1,15 @@
# Befehlsverarbeitung in Eressea
Einheiten haben zwei Listen von Befehlen: orders und old_orders.
1. `read_unit`: Aus dem Datenfile gelesene (Default-)Befehl der Vorwoche werden in u->orders gespeichert.
2. `begin_orders`: Wenn die Einheit neue Befehle erhält, werden "wiederholbare" Befehle (Handel, lange Befehle ausser NACH) aus u->orders nach u->old_orders kopiert.
3. `unitorders`: Die neuen Befehle werden in u->orders gelesen.
4. `update_long_order`: u->thisorder wird auf den ersten "langen" Befehl in u->orders gesetzt.
5. Auswertung: Für lange Befehle wird in u->thisorder geschaut, für kurze und andere (inkl. KAUFE/ATTACKIERE) in u->orders.
6. `movement`: NACH löscht u->thisorder, damit es nicht bei Auswertung der Zielregion ein zweites Mal ausgeführt werden kann. Das hat allerdings keine Auswirkung auf die beiden Listen.
7. `build_building`: Wenn ein MACHE GEBAEUDE Befehl "fertig" ist, wird der Befehl in u->orders durch ein ARBEITE ersetzt (aber u->thisorder nicht geändert, das sollte also nichts tun).
8. `defaultorders`: Nach allen langen Befehlen wird der DEFAULT Befehl gesetzt. Dieser löscht zuerst alle nicht-kurzen Befehle aus u->orders und u->old_orders, und hängt dann den neuen Befehl in u->old_orders an.
9.1: `cr_output_unit`: In den CR werden alle "dauerhaften" Befehle aus u->old_orders geschrieben, d.h. kurze Befehle mit @ Prefix, Kommentare mit // und lange Befehle ausser NACH.
9.2: `cr_output_unit`: In den CR werden alle "dauerhaften" Befehle aus u->orders geschrieben, d.h. kurze Befehle mit @ Prefix, Kommentare mit // und lange Befehle ausser NACH. Wenn u->old_orders nicht leer ist, werden "wiederholbare" Befehle dabei ignoriert.

View File

@ -3,6 +3,7 @@
[ "$PREVIEW" != "yes" ] && exit
[ -z "${ERESSEA}" ] && ERESSEA="$HOME/eressea"
eval $(luarocks path)
branch="develop"
if [ -e "${ERESSEA}/build/.preview" ]; then
branch=$(cat "${ERESSEA}/build/.preview")

View File

@ -1,4 +1,6 @@
#!/bin/bash
eval $(luarocks path)
GAME=$1
(
[ "$ENABLED" != "yes" ] && exit

View File

@ -17,8 +17,6 @@ fi
cd "$GAME/reports" || exit
for REPORT in *.sh
do
echo -n "Sending "
basename "$REPORT" .sh
bash "$REPORT"
done
cd - || exit

View File

@ -391,16 +391,6 @@
<arg name="id" type="int"/>
</type>
</message>
<message name="curseinfo::godcurseocean" section="events">
<type>
<arg name="id" type="int"/>
</type>
</message>
<message name="curseinfo::godcurse" section="events">
<type>
<arg name="id" type="int"/>
</type>
</message>
<message name="curseinfo::disorientationzone" section="events">
<type>
<arg name="id" type="int"/>
@ -712,11 +702,6 @@
<arg name="password" type="string"/>
</type>
</message>
<message name="godcurse_destroy_ship" section="events">
<type>
<arg name="ship" type="ship"/>
</type>
</message>
<message name="skillpotion_use" section="events">
<type>
<arg name="unit" type="unit"/>
@ -2690,6 +2675,70 @@
</type>
</message>
<message name="error321" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
</type>
</message>
<message name="error322" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
</type>
</message>
<message name="error323" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
</type>
</message>
<message name="error324" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
</type>
</message>
<message name="error325" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
</type>
</message>
<message name="error326" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
</type>
</message>
<message name="error327" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
</type>
</message>
<message name="error328" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
</type>
</message>
<message name="error319" section="errors">
<type>
<arg name="unit" type="unit"/>
@ -3740,6 +3789,62 @@
<arg name="command" type="order"/>
</type>
</message>
<message name="error321" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
</type>
</message>
<message name="error322" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
</type>
</message>
<message name="error323" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
</type>
</message>
<message name="error324" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
</type>
</message>
<message name="error325" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
</type>
</message>
<message name="error326" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
</type>
</message>
<message name="error327" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
</type>
</message>
<message name="error328" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
</type>
</message>
<message name="error181" section="errors">
<type>
<arg name="unit" type="unit"/>

View File

@ -721,7 +721,7 @@
<attack type="4" damage="3d30"/>
<attack type="6" spell="icy_dragonbreath" level="6" />
</race>
<race name="youngdragon" magres="50" maxaura="1.000000" regaura="1.000000" weight="20000" capacity="10000" speed="1.000000" hp="300" ac="4" damage="2d15" unarmedattack="0" unarmeddefense="0" attackmodifier="4" defensemodifier="4" fly="yes" walk="yes" teach="no" getitem="yes" resistbash="yes" unarmedguard="yes">
<race name="youngdragon" magres="50" maxaura="1.000000" regaura="1.000000" weight="20000" capacity="10000" speed="1.000000" hp="300" ac="4" damage="2d15" unarmedattack="0" unarmeddefense="0" attackmodifier="4" defensemodifier="4" fly="yes" walk="yes" teach="no" getitem="yes" resistbash="yes" unarmedguard="yes" dragon="yes">
<ai splitsize="6" killpeasants="yes" learn="yes" scarepeasants="yes"/>
<skill name="magic" modifier="4"/>
<skill name="tactics" modifier="4"/>

View File

@ -437,9 +437,6 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - Pferde kann man
msgid "error307"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Snotlinge sind zu dumm, um auf den Feldern zu arbeiten.\""
msgid "godcurse_destroy_ship"
msgstr "\"Die Mannschaft krank vom vergifteten Wasser, Planken, Ruder und Segel zerfressen von den Wassern des verfluchten Meeres, ergibt sich die $ship($ship) in ihr Schicksal und sinkt.\""
msgid "too_many_units_in_faction"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Eine Partei darf nicht aus mehr als $int($allowed) Einheiten bestehen.\""
@ -1034,9 +1031,6 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - Auf dem Schiff
msgid "sp_icastle_effect"
msgstr "\"Verwundert blicken die Bauern von $region($region) auf ein neues Gebäude.\""
msgid "curseinfo::godcurse"
msgstr "\"Diese Region wurde von den Göttern verflucht. Stinkende Nebel ziehen über die tote Erde und furchtbare Kreaturen ziehen über das Land. Die Brunnen sind vergiftet, und die wenigen essbaren Früchte sind von einem rosa Pilz überzogen. Niemand kann hier lange überleben. ($int36($id))\""
msgid "recruit_archetype"
msgstr "\"$unit($unit) rekrutiert $int($amount) $localize($archetype).\""
@ -2555,9 +2549,6 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - Man benötigt m
msgid "error177"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Diesen Spruch kann der Vertraute nicht zaubern.\""
msgid "curseinfo::godcurseocean"
msgstr "\"Diese Region wurde von den Göttern verflucht. Das Meer ist eine ekelige Brühe, braunschwarze, stinkende Gase steigen aus den unergründlichen Tiefen hervor, und untote Seeungeheuer, Schiffe zerfressend und giftige grüne Galle geifernd, sind der Schrecken aller Seeleute, die diese Gewässer durchqueren. Niemand kann hier lange überleben. ($int36($id))\""
msgid "curseinfo::sparkle_4"
msgstr "\"Ein schimmernder Lichterkranz umgibt $unit($unit). ($int36($id))\""
@ -2775,7 +2766,7 @@ msgid "error324"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Die Einheit gehört nicht zu unserer Partei.\""
msgid "error322"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Die Einheit ist bereits auf einem Schiff.\""
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Nur Schiffe gleicher Bauart können einen Konvoi bilden.\""
msgid "error323"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Das Schiff ist verzaubert.\""
@ -2783,6 +2774,9 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - Das Schiff ist
msgid "error327"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - So viele Schiffe kann die Einheit nicht übergeben.\""
msgid "error328"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Dafür müssen die Schiffe an derselben Küste liegen.\""
msgid "error326"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Diese Schiffe können keinen Konvoi bilden.\""

View File

@ -437,9 +437,6 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - You can only br
msgid "error307"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - We snotlings is too stupid fer dat!\""
msgid "godcurse_destroy_ship"
msgstr "\"Her sailors sick from the poisened ocean, planks, rudder und sails corroded by the waters of the cursed ocean, the $ship($ship) finally succumbs to her destiny and sinks.\""
msgid "too_many_units_in_faction"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - A faction may not consist of more than $int($allowed) units.\""
@ -1034,9 +1031,6 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - There are not e
msgid "sp_icastle_effect"
msgstr "\"Flabbergasted, the peasants of $region($region) behold a new building.\""
msgid "curseinfo::godcurse"
msgstr "\"This region was cursed by the gods. Stinking vapors billow over the dead ground and hideous creatures move about the country. The wells are poisened and the edible plants are covered by a pink fungus. Noone can live here for long. ($int36($id))\""
msgid "recruit_archetype"
msgstr "\"$unit($unit) recruits $int($amount) $localize($archetype).\""
@ -1251,7 +1245,7 @@ msgid "error184"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - The unit does not move.\""
msgid "income_entertainment"
msgstr "\"$unit($unit) earns $int($amount) in $region($region) with entertainment.\""
msgstr "\"$unit($unit) earns $int($amount) in $region($region) from entertainment.\""
msgid "error180"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - The spell fails.\""
@ -1620,7 +1614,7 @@ msgid "curseinfo::deathcloud"
msgstr "\"A poison elemental is spreading pestilence and death. ($int36($id))\""
msgid "income"
msgstr "\"$unit($unit) earns $int($amount)$if($eq($wanted,$amount),\"\",\" of $int($wanted)\") in $region($region) $if($eq($mode,1),\" by entertainment\",$if($eq($mode,2),\" by taxes\",$if($eq($mode,3),\" by trade\",$if($eq($mode,5),\" by stealing\",$if($eq($mode,6),\" by magic\",$if($eq($mode,7),\" by pillaging\",\"\")))))).\""
msgstr "\"$unit($unit) in $region($region) earns $int($amount)$if($eq($wanted,$amount),\"\",\" of $int($wanted)\") silver.\""
msgid "researchherb"
msgstr "\"$unit($unit) discovers that $localize($amount) $resource($herb,0) grow in $region($region).\""
@ -2115,7 +2109,7 @@ msgid "deathcloud_effect"
msgstr "\"$unit($mage) summons a poison elemental in $region($region).\""
msgid "nr_population"
msgstr "\"Your faction has $int($population) people in $int($units) of $int($limit) possible units.\""
msgstr "\"Your faction has $int($population) $if($eq($population,1), \"person\", \"persons\") in $int($units) of $int($limit) possible units.\""
msgid "curseinfo::shipdisorientation"
msgstr "This ship has lost its path. ($int36($id))"
@ -2223,7 +2217,7 @@ msgid "curseinfo::healingzone"
msgstr "Healing in this region is affected by magic. ($int36($id))"
msgid "income_entertainment_reduced"
msgstr "\"In $region($region), $unit($unit) earns only $int($amount) instead of$if($eq($wanted,$amount),\"\",\" of$if($eq($wanted,$amount),\"\",\" of $int($wanted)\") \") with entertainment.\""
msgstr "\"In $region($region), $unit($unit) earns only $int($amount) instead of$if($eq($wanted,$amount),\"\",\" of$if($eq($wanted,$amount),\"\",\" of $int($wanted)\") \") from entertainment.\""
msgid "errusingpotion"
msgstr "\"$unit($unit): '$order($command)' - The unit already uses $resource($using,0).\""
@ -2555,9 +2549,6 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - You need at lea
msgid "error177"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - The familiar cannot cast this spell.\""
msgid "curseinfo::godcurseocean"
msgstr "\"This region was cursed by the gods. The sea is a foul cesspool, noxious gases rise from the deep, undead seamonsters attack all ships. Noone can live here for long. ($int36($id))\""
msgid "curseinfo::sparkle_4"
msgstr "\"A circle of shimmering lights surrounds $unit($unit). ($int36($id))\""
@ -2781,11 +2772,14 @@ msgid "error324"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - The unit is not one of ours.\""
msgid "error322"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - The unit is already on a ship.\""
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Only ships of the same type can form a convoy.\""
msgid "error323"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - The ship is under a spell.\""
msgid "error328"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - All ships of a convoy must be on the same coast.\""
msgid "dissolve_units_2"
msgstr "\"$unit($unit) in $region($region): $int($number) $race($race,$number) turned into $if($eq($number,1),\"a tree\", \"trees\").\""

View File

@ -2331,10 +2331,6 @@ msgstr "Seelenfrieden"
msgid "list_and"
msgstr " und "
msgctxt "spell"
msgid "godcursezone"
msgstr "Fluch der Götter"
msgid "sptype_postcombat"
msgstr "Postkampfzauber"

View File

@ -1976,10 +1976,6 @@ msgstr " and "
msgid "h18_p"
msgstr "ice begonias"
msgctxt "spell"
msgid "godcursezone"
msgstr "Curse of the Gods"
msgid "sptype_postcombat"
msgstr "post-combat spell"

View File

@ -128,6 +128,7 @@ TOLUA
else
echo "tolua is $path"
fi
luarocks --local install lunitx
unset path
set -e

View File

@ -3,4 +3,3 @@ if config.paths ~= nil then
package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua'
end
end
-- print(package.path)

View File

@ -6,7 +6,6 @@ module = lunit.module
path = 'scripts'
if config.install then
path = config.install .. '/' .. path
--needed to find lunit if not run from eressea root. Needs right [lua] install setting in eressea.ini (point to eressea root from the start folder)
end
package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua'

View File

@ -7,12 +7,12 @@ module = lunit.module
path = 'scripts'
if config.install then
path = config.install .. '/' .. path
--needed to find lunit if not run form eressea root. Needs right [lua] install setting in eressea.ini (point to eressea root from the start folder)
end
package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua'
config.rules = 'e3'
lunit = require 'lunit'
require 'eressea'
require 'eressea.path'
require 'eressea.xmlconf'

View File

@ -4,14 +4,12 @@
path = 'scripts'
if config.install then
path = config.install .. '/' .. path
--needed to find lunit if not run form eressea root. Needs right [lua] install setting in eressea.ini (point to eressea root from the start folder)
end
package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua'
lunit = require 'lunit'
require 'eressea'
require 'eressea.path'
lunit = require('lunit')
module = lunit.module
require 'tests'
result = lunit.main()

View File

@ -130,8 +130,9 @@ function process(rules, orders)
end
turn_begin()
-- run the turn:
-- create orders for monsters:
plan_monsters()
-- read orders for players:
if eressea.read_orders(orders) ~= 0 then
print("could not read " .. orders)
return -1
@ -140,8 +141,9 @@ function process(rules, orders)
if nmr_check(config.maxnmrs or 80)~=0 then
return -1
end
plan_monsters()
callbacks(rules, 'init')
-- run the turn:
turn_process()
callbacks(rules, 'update')
turn_end() -- ageing, etc.

View File

@ -898,4 +898,3 @@ function test_walk_and_carry_the_cart()
process_orders()
assert_equal(1, u.region.x)
end

View File

@ -6,18 +6,6 @@ else
module(tcname, 'seeall')
end
function skip_test_get_set_ally()
local f1 = faction.create("human")
local f2 = faction.create("human")
assert_equal(false, f1:get_ally(f2, "guard"))
f1:set_ally(f2, "guard", true)
assert_equal(true, f1:get_ally(f2, "guard"))
assert_equal(false, f1:get_ally(f2, "give"))
f1:set_ally(f2, "give", true)
assert_equal(true, f1:get_ally(f2, "give"))
end
function test_get_allies()
local f1 = faction.create("human")
local f2 = faction.create("human")
@ -32,3 +20,16 @@ function test_get_allies()
assert_equal(1, #allies[f2.id])
assert_equal("give", allies[f2.id][1])
end
function test_get_set_ally()
local f1 = faction.create("human")
local f2 = faction.create("human")
assert_equal(false, f1:get_ally(f2, "guard"))
f1:set_ally(f2, "guard", true)
assert_equal(true, f1:get_ally(f2, "guard"))
assert_equal(false, f1:get_ally(f2, "give"))
f1:set_ally(f2, "give", true)
assert_equal(true, f1:get_ally(f2, "give"))
end

View File

@ -45,7 +45,6 @@ function test_build_tunnel_limited()
u:add_item('iron', 2)
u:add_item('money', 700)
u.building = b
u.name = 'Xolgrim'
u:add_order('MACHE 2 BURG ' .. itoa36(b.id))
b.size = 99
process_orders()

View File

@ -45,8 +45,8 @@ function test_destroy_is_long()
local u = unit.create(faction.create("human", "one@example.com", "de"), r1, 10)
u.building = building.create(u.region, "castle")
u:clear_orders()
u:add_order("LERNE Unterhaltung")
u:add_order("ZERSTOERE " .. itoa36(u.building.id))
u:add_order("LERNE Unterhaltung")
process_orders()
assert_equal(0, u:get_skill("entertainment"))
assert_equal(nil, u.building)

View File

@ -16,6 +16,26 @@ function setup()
eressea.settings.set("rules.peasants.growth.factor", "0")
end
function disabled_double_default()
local r = region.create(0, 0, "plain")
local f = faction.create("human")
local u = unit.create(f, r, 1)
region.create(1, 0, "plain")
region.create(2, 0, "plain")
region.create(3, 0, "plain")
u:add_order('NACH O')
u:add_order('DEFAULT "NACH O"')
u:add_order('DEFAULT "DEFAULT ARBEITE"')
process_orders()
assert_equal(1, u.region.x)
process_orders()
assert_equal(2, u.region.x)
process_orders()
assert_equal(2, u.region.x)
assert_equal("ARBEITE", u:get_order())
end
function test_give_unit()
local r = region.create(0, 0, "plain")
local f1 = faction.create('elf')

View File

@ -1,6 +1,6 @@
require 'tests.e2.trolls'
require 'tests.e2.trees'
require 'tests.e2.buildings'
require 'tests.e2.allies'
require 'tests.e2.quit'
require 'tests.e2.movement'
require 'tests.e2.carts'
require 'tests.e2.astral'
@ -8,6 +8,7 @@ require 'tests.e2.spells'
require 'tests.e2.e2features'
require 'tests.e2.insects'
require 'tests.e2.production'
require 'tests.e2.allies'
require 'tests.e2.adamantium'
require 'tests.e2.undead'
require 'tests.e2.shiplanding'
@ -31,3 +32,4 @@ require 'tests.xmas'
require 'tests.production'
require 'tests.spells'
require 'tests.undead'

View File

@ -7,7 +7,7 @@ else
end
function setup()
eressea.free_game()
eressea.game.reset()
eressea.settings.set("nmr.removenewbie", "0")
eressea.settings.set("nmr.timeout", "0")
eressea.settings.set("NewbieImmunity", "0")
@ -18,6 +18,26 @@ function setup()
eressea.settings.set("magic.regeneration.enable", "0")
end
function test_undead_cannot_enter_holyground()
local r1 = region.create(0, 0, 'plain')
local r2 = region.create(1, 0, 'plain')
local f = faction.create('human')
local u1 = unit.create(f, r1, 1)
local u2 = unit.create(f, r2, 1)
u2.magic = 'gwyrrd'
u2:set_skill('magic', 100)
u2.aura = 200
u2:add_spell('holyground')
u2:add_order('ZAUBERE STUFE 10 "Heiliger Boden"')
u1.race = "skeleton"
u1:add_order("NACH Osten")
process_orders()
assert_not_nil(r2:get_curse('holyground'))
assert_equal(r1, u1.region)
end
function test_shapeshift()
local r = region.create(42, 0, "plain")
local f = faction.create("demon", "noreply@eressea.de", "de")
@ -208,7 +228,6 @@ function test_bug_2517()
local uf = nil
eressea.settings.set("magic.familiar.race", "lynx")
f.magic = 'gwyrrd'
um.name = 'Xolgrim'
um.magic = 'gwyrrd'
um.race = 'elf'
um:set_skill('magic', 10)

144
scripts/tests/e2/trees.lua Normal file
View File

@ -0,0 +1,144 @@
local tcname = 'tests.e2.trees'
local lunit = require("lunit")
if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, 'seeall')
end
function setup()
eressea.game.reset()
eressea.settings.set("rules.food.flags", "4") -- food is free
eressea.settings.set("rules.treeseeds.chance", "0.0") -- trees make no seeds
eressea.settings.set("rules.grow.formula", "0") -- no tree or seed growth
eressea.settings.set("NewbieImmunity", "0")
end
function test_no_growth()
eressea.settings.set("rules.grow.formula", "2") -- E2 growth rules
set_turn(204)
assert_equal('spring', get_season())
local r = region.create(0, 0, 'plain')
r:set_flag(1, false) -- no mallorn
r:set_resource('seed', 0)
r:set_resource('sapling', 0)
r:set_resource('tree', 0)
process_orders()
assert_equal(0, r:get_resource('seed'))
assert_equal(0, r:get_resource('sapling'))
assert_equal(0, r:get_resource('tree'))
end
function test_spring_growth()
eressea.settings.set("rules.grow.formula", "2") -- E2 growth rules
set_turn(204)
assert_equal('spring', get_season())
local r = region.create(0, 0, 'plain')
r:set_flag(1, false) -- no mallorn
r:set_resource('seed', 6)
r:set_resource('sapling', 17)
r:set_resource('tree', 0)
process_orders()
assert_equal(5, r:get_resource('seed'))
assert_equal(16, r:get_resource('sapling'))
assert_equal(2, r:get_resource('tree'))
end
-- hebalism < T6 cannot plant
function test_plant_fail()
set_turn(184)
assert_equal('summer', get_season())
local f = faction.create('goblin')
local r = region.create(0, 0, 'plain')
r:set_flag(1, false) -- no mallorn
r:set_resource('seed', 0)
r:set_resource('sapling', 0)
r:set_resource('tree', 0)
local u = unit.create(f, r)
u:set_skill('herbalism', 5)
u:add_item('seed', 40)
u:add_order("PFLANZE 20 Samen")
process_orders()
assert_equal(0, r:get_resource('seed'))
assert_equal(0, r:get_resource('sapling'))
assert_equal(0, r:get_resource('tree'))
assert_equal(40, u:get_item('seed'))
end
-- T6+ herbalism allows planting seeds at 1:1 rates
function test_plant_summer()
set_turn(184)
assert_equal('summer', get_season())
local f = faction.create('goblin')
local r = region.create(0, 0, 'plain')
r:set_flag(1, false) -- no mallorn
r:set_resource('seed', 0)
r:set_resource('sapling', 0)
r:set_resource('tree', 0)
local u = unit.create(f, r)
u:set_skill('herbalism', 20)
u:add_item('seed', 40)
u:add_order("PFLANZE 20 Samen")
process_orders()
assert_equal(20, r:get_resource('seed'))
assert_equal(0, r:get_resource('sapling'))
assert_equal(0, r:get_resource('tree'))
assert_equal(20, u:get_item('seed'))
end
-- in spring, herbalism >= T12 plants saplings at 10:1 rate
function test_plant_spring_saplings()
set_turn(203)
assert_equal('spring', get_season())
local f = faction.create('goblin')
local r = region.create(0, 0, 'plain')
local u = unit.create(f, r)
r:set_flag(1, false) -- no mallorn
r:set_resource('seed', 0)
r:set_resource('sapling', 0)
r:set_resource('tree', 0)
assert_equal('spring', get_season())
process_orders() -- to initialize at_germs
assert_equal(0, r:get_resource('sapling'))
assert_equal(0, r:get_resource('seed'))
assert_equal(0, r:get_resource('tree'))
assert_equal('spring', get_season())
u:set_skill('herbalism', 12)
u:add_item('seed', 20)
u:add_order("PFLANZE 20 Samen") -- limited by herbalism
process_orders()
assert_equal(1, r:get_resource('sapling'))
assert_equal(2, r:get_resource('seed'))
assert_equal(0, r:get_resource('tree'))
assert_equal(8, u:get_item('seed'))
end
-- herbalism < T12 means we are still planting seeds at 1:1
function test_plant_spring_seeds()
set_turn(204)
local f = faction.create('goblin')
local r = region.create(0, 0, 'plain')
local u = unit.create(f, r)
r:set_flag(1, false) -- no mallorn
r:set_resource('seed', 0)
r:set_resource('sapling', 0)
r:set_resource('tree', 0)
assert_equal('spring', get_season())
process_orders() -- to initialize at_germs
assert_equal(0, r:get_resource('sapling'))
assert_equal(0, r:get_resource('seed'))
assert_equal(0, r:get_resource('tree'))
assert_equal('spring', get_season())
u:set_skill('herbalism', 10)
u:add_item('seed', 40)
u:add_order("PFLANZE 10 Samen")
process_orders()
assert_equal(0, r:get_resource('sapling'))
assert_equal(10, r:get_resource('seed'))
assert_equal(0, r:get_resource('tree'))
assert_equal(30, u:get_item('seed'))
end

View File

@ -0,0 +1,54 @@
local tcname = 'tests.e2.trolls'
local lunit = require("lunit")
if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
else
module(tcname, 'seeall')
end
function setup()
eressea.free_game()
end
function test_trolls_with_horses()
local r0 = region.create(0, 0, 'plain')
local r1 = region.create(1, 0, 'plain')
local r2 = region.create(2, 0, 'plain')
local r3 = region.create(3, 0, 'plain')
local r4 = region.create(4, 0, 'plain')
local r5 = region.create(5, 0, 'plain')
local f = faction.create('troll')
-- 1. 20 trolls can pull 5 loaded carts:
assert_not_nil(r0)
local u1 = unit.create(f, r0, 20)
u1:add_item('cart', 5)
-- trolls carry 10.8 GE, carts carry 100 GE:
u1:add_item('money', 100 * (5 * 100 + 2 * 108))
u1:add_order('NACH O O O')
process_orders()
assert_equal(r1, u1.region)
-- 20 trolls can also lead 20 horses
u1:add_item('horse', 20)
u1:add_item('money', 100 * 20 * 20)
process_orders()
assert_equal(r2, u1.region)
-- test if trolls are still "lazy". If yes they should still manage 10 full carts behind the 20 horses (5 more)
u1:add_item('cart', 5)
u1:add_item('money', 100 * 5 * 100)
process_orders()
assert_equal(r3, u1.region)
-- test if trolls are still "lazy". If not they should manage 15 full carts, 5 behind trolls and 10 behind 20 horses (again 5 more)
u1:add_item('cart', 5)
u1:add_item('money', 100 * 5 * 100)
process_orders()
assert_equal(r4, u1.region)
end

View File

@ -32,7 +32,6 @@ function test_undead_reserve_other()
u1.race = "undead"
u1:clear_orders()
u1:add_order("RESERVIERE 1 Holz")
u1.name = 'Xolgrim'
process_orders()
if 0 ~= u1:get_item("log") then

View File

@ -37,10 +37,15 @@ int u_geteffstealth(const unit *u)
if (skill_enabled(SK_STEALTH)) {
if (u->flags & UFL_STEALTH) {
attrib *a = a_find(u->attribs, &at_stealth);
if (a != NULL)
if (a != NULL) {
int eff = effskill(u, SK_STEALTH, u->region);
if (eff < a->data.i) {
return eff;
}
return a->data.i;
}
}
}
return -1;
}

View File

@ -20,7 +20,7 @@ static void test_stealth(CuTest *tc) {
CuAssertIntEquals(tc, -1, u_geteffstealth(u));
CuAssertIntEquals(tc, 2, eff_stealth(u, u->region));
u_seteffstealth(u, 3);
CuAssertIntEquals(tc, 3, u_geteffstealth(u));
CuAssertIntEquals(tc, 2, u_geteffstealth(u));
CuAssertIntEquals(tc, 2, eff_stealth(u, u->region));
u_seteffstealth(u, 1);
CuAssertIntEquals(tc, 1, u_geteffstealth(u));

View File

@ -20,7 +20,8 @@
static int cmp_scholars(const void *lhs, const void *rhs) {
const scholar *a = (const scholar *)lhs;
const scholar *b = (const scholar *)rhs;
return b->level - a->level;
int diff = b->level - a->level;
return (diff != 0) ? diff : b->u->number - a->u->number;
}
int autostudy_init(scholar scholars[], int max_scholars, unit **units, skill_t *o_skill)
@ -77,6 +78,7 @@ int autostudy_init(scholar scholars[], int max_scholars, unit **units, skill_t *
static void teaching(scholar *s, int n) {
assert(n <= s->u->number);
// doppelter Effekt mit Lehrer:
s->learn += n;
s->u->flags |= UFL_LONGACTION;
}
@ -91,27 +93,31 @@ void autostudy_run(scholar scholars[], int nscholars)
{
int ti = 0;
while (ti != nscholars) {
int t, se, ts = 0, tt = 0, si = ti;
for (se = ti; se != nscholars; ++se) {
int mint;
ts += scholars[se].u->number; /* count total scholars */
int t, ts = 0, tt = 0, si = ti, mint = 0, ns = 0;
for (t = ti; t != nscholars; ++t) {
ts += scholars[t].u->number; /* count total scholars */
mint = (ts + 10) / 11; /* need a minimum of ceil(ts/11) teachers */
for (; mint > tt && si != nscholars; ++si) {
tt += scholars[si].u->number;
}
}
if (mint < tt) {
/* die Einheit si-1 hat einen Mix aus Lehrer und Schüler */
--si;
ns = tt - mint;
}
/* now si splits the teachers and students 1:10 */
/* first student must be 2 levels below first teacher: */
for (; si != se; ++si) {
for (; si != nscholars; ++si) {
if (scholars[si].level + TEACHDIFFERENCE <= scholars[ti].level) {
break;
}
tt += scholars[si].u->number;
ns = 0;
}
/* now si is the first unit we can teach, if we can teach any */
if (si == se) {
if (si == nscholars) {
/* there are no students, so standard learning for everyone */
for (t = ti; t != se; ++t) {
for (t = ti; t != nscholars; ++t) {
learning(scholars + t, scholars[t].u->number);
}
}
@ -119,16 +125,17 @@ void autostudy_run(scholar scholars[], int nscholars)
/* invariant: unit ti can still teach i students */
int i = scholars[ti].u->number * STUDENTS_PER_TEACHER;
/* invariant: unit si has n students that can still be taught */
int s, n = scholars[si].u->number;
for (t = ti, s = si; t != si && s != se; ) {
int s, n = (ns > 0) ? ns : scholars[si].u->number;
for (t = ti, s = si; t != si && s != nscholars; ) {
if (i >= n) {
/* t has more than enough teaching capacity for s */
i -= n;
teaching(scholars + s, n);
learning(scholars + s, scholars[s].u->number);
/* next student, please: */
if (++s == se) {
continue;
if (++s == nscholars) {
/* no more students */
break;
}
n = scholars[s].u->number;
}
@ -147,7 +154,7 @@ void autostudy_run(scholar scholars[], int nscholars)
do {
/* remaining students learn without a teacher: */
learning(scholars + s, n);
if (++s == se) {
if (++s == nscholars) {
break;
}
n = scholars[s].u->number;
@ -163,10 +170,15 @@ void autostudy_run(scholar scholars[], int nscholars)
}
++t;
for (; t < si; ++t) {
/* teachers that did not teach */
learning(scholars + t, scholars[t].u->number);
}
for (; s < nscholars; ++s) {
/* students that were not taught */
learning(scholars + s, scholars[s].u->number);
}
ti = se;
}
ti = nscholars;
}
}

View File

@ -110,6 +110,111 @@ static void test_autostudy_run_twoteachers(CuTest *tc) {
test_teardown();
}
/**
* Reproduce Bug 2640
*/
static void test_autostudy_run_bigunit(CuTest *tc) {
scholar scholars[4];
int nscholars;
unit *u1, *u2, *ulist;
faction *f;
region *r;
skill_t skill;
test_setup();
r = test_create_plain(0, 0);
f = test_create_faction(NULL);
u1 = test_create_unit(f, r);
set_number(u1, 20);
set_level(u1, SK_ENTERTAINMENT, 16);
u1->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
u2 = test_create_unit(f, r);
set_number(u2, 1000);
set_level(u2, SK_ENTERTAINMENT, 10);
u2->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
ulist = r->units;
CuAssertIntEquals(tc, 2, nscholars = autostudy_init(scholars, 4, &ulist, &skill));
CuAssertPtrEquals(tc, NULL, ulist);
autostudy_run(scholars, nscholars);
CuAssertIntEquals(tc, SK_ENTERTAINMENT, skill);
CuAssertIntEquals(tc, 0, scholars[0].learn);
CuAssertIntEquals(tc, 1200, scholars[1].learn);
test_teardown();
}
static void test_autostudy_run_few_teachers(CuTest *tc) {
scholar scholars[4];
int nscholars;
unit *u1, *u2, *u3, *ulist;
faction *f;
region *r;
skill_t skill;
test_setup();
r = test_create_plain(0, 0);
f = test_create_faction(NULL);
u1 = test_create_unit(f, r);
set_number(u1, 20);
set_level(u1, SK_ENTERTAINMENT, 16);
u1->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
u2 = test_create_unit(f, r);
set_number(u2, 500);
set_level(u2, SK_ENTERTAINMENT, 10);
u2->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
u3 = test_create_unit(f, r);
set_number(u3, 100);
set_level(u3, SK_ENTERTAINMENT, 9);
u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
ulist = r->units;
CuAssertIntEquals(tc, 3, nscholars = autostudy_init(scholars, 4, &ulist, &skill));
CuAssertPtrEquals(tc, NULL, ulist);
autostudy_run(scholars, nscholars);
CuAssertIntEquals(tc, SK_ENTERTAINMENT, skill);
CuAssertIntEquals(tc, 0, scholars[0].learn);
CuAssertIntEquals(tc, 700, scholars[1].learn);
CuAssertIntEquals(tc, 100, scholars[2].learn);
test_teardown();
}
static void test_autostudy_run_few_teachers_reverse(CuTest *tc) {
scholar scholars[4];
int nscholars;
unit *u1, *u2, *u3, *ulist;
faction *f;
region *r;
skill_t skill;
test_setup();
r = test_create_plain(0, 0);
f = test_create_faction(NULL);
u1 = test_create_unit(f, r);
set_number(u1, 20);
set_level(u1, SK_ENTERTAINMENT, 16);
u1->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
u2 = test_create_unit(f, r);
set_number(u2, 100);
set_level(u2, SK_ENTERTAINMENT, 10);
u2->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
u3 = test_create_unit(f, r);
set_number(u3, 500);
set_level(u3, SK_ENTERTAINMENT, 9);
u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
ulist = r->units;
CuAssertIntEquals(tc, 3, nscholars = autostudy_init(scholars, 4, &ulist, &skill));
CuAssertPtrEquals(tc, NULL, ulist);
autostudy_run(scholars, nscholars);
CuAssertIntEquals(tc, SK_ENTERTAINMENT, skill);
CuAssertIntEquals(tc, 0, scholars[0].learn);
CuAssertIntEquals(tc, 800, scholars[1].learn + scholars[2].learn);
test_teardown();
}
static void test_autostudy_run(CuTest *tc) {
scholar scholars[4];
int nscholars;
@ -325,6 +430,9 @@ CuSuite *get_automate_suite(void)
SUITE_ADD_TEST(suite, test_autostudy_run_noteachers);
SUITE_ADD_TEST(suite, test_autostudy_run_teachers_learn);
SUITE_ADD_TEST(suite, test_autostudy_run_twoteachers);
SUITE_ADD_TEST(suite, test_autostudy_run_bigunit);
SUITE_ADD_TEST(suite, test_autostudy_run_few_teachers);
SUITE_ADD_TEST(suite, test_autostudy_run_few_teachers_reverse);
SUITE_ADD_TEST(suite, test_autostudy_run_skilldiff);
return suite;
}

View File

@ -2933,7 +2933,7 @@ static void print_stats(battle * b)
header = LOC(f->locale, "battle_helpers");
for (s2 = b->sides; s2 != b->sides + b->nsides; ++s2) {
if (friendly(s2, s)) {
if (s2 != s && friendly(s2, s)) {
const char *abbrev = seematrix(f, s2) ? sideabkz(s2, false) : "-?-";
rsize = slprintf(bufp, size, "%s %s %d(%s)",
komma++ ? "," : (const char *)header, loc_army, army_index(s2),

View File

@ -28,9 +28,6 @@ static int tolua_levitate_ship(lua_State * L)
return 1;
}
extern void spawn_undead(void);
extern void plan_monsters(struct faction *f);
static int tolua_planmonsters(lua_State * L)
{
faction *f = (faction *)tolua_tousertype(L, 1, get_monsters());

View File

@ -14,7 +14,8 @@
#include <lua.h>
void tolua_bind_open(lua_State * L) {
void tolua_bind_open(lua_State * L)
{
tolua_eressea_open(L);
tolua_process_open(L);
tolua_settings_open(L);

View File

@ -3,6 +3,7 @@
#endif
#include "bindings.h"
#include "bind_tolua.h"
#include "console.h"
#include "gamedb.h"
@ -259,7 +260,7 @@ static int tolua_dice_rand(lua_State * L)
static int tolua_get_season(lua_State * L)
{
int turn_no = (int)tolua_tonumber(L, 1, 0);
int turn_no = (int)tolua_tonumber(L, 1, turn);
season_t season = calendar_season(turn_no);
tolua_pushstring(L, seasonnames[season]);
return 1;
@ -865,8 +866,6 @@ static int lua_rng_default(lua_State *L) {
return 0;
}
void tolua_bind_open(lua_State * L);
int tolua_bindings_open(lua_State * L, const dictionary *inifile)
{
tolua_open(L);

View File

@ -12,6 +12,8 @@ extern "C" {
int tolua_selist_push(struct lua_State *L, const char *list_type,
const char *elem_type, struct selist *list);
void bind_monsters(struct lua_State *L);
int log_lua_error(struct lua_State *L);
void lua_done(struct lua_State *L);

View File

@ -84,7 +84,7 @@ static char g_bigbuf[BUFFERSIZE];
bool opt_cr_absolute_coords = false;
/* globals */
#define C_REPORT_VERSION 67
#define C_REPORT_VERSION 68
struct locale *crtag_locale(void) {
static struct locale * lang;
@ -495,38 +495,6 @@ static int cr_curse(variant var, char *buffer, const void *userdata)
/*static int msgno; */
#define MTMAXHASH 1021
static struct known_mtype {
const struct message_type *mtype;
struct known_mtype *nexthash;
} *mtypehash[MTMAXHASH];
static void report_crtypes(FILE * F, const struct locale *lang)
{
int i;
for (i = 0; i != MTMAXHASH; ++i) {
struct known_mtype *kmt;
for (kmt = mtypehash[i]; kmt; kmt = kmt->nexthash) {
char buffer[DISPLAYSIZE];
int hash = (int)kmt->mtype->key;
assert(hash > 0);
fprintf(F, "MESSAGETYPE %d\n", hash);
fputc('\"', F);
fputs(crescape(nrt_string(kmt->mtype, lang), buffer, sizeof(buffer)), F);
fputs("\";text\n", F);
if (kmt->mtype->section) {
fprintf(F, "\"%s\";section\n", kmt->mtype->section);
}
}
while (mtypehash[i]) {
kmt = mtypehash[i];
mtypehash[i] = mtypehash[i]->nexthash;
free(kmt);
}
}
}
static int message_id(const struct message *msg)
{
variant var;
@ -594,19 +562,6 @@ static void render_messages(FILE * F, faction * f, message_list * msgs)
else {
log_error("could not render cr-message %p: %s\n", m->msg, m->msg->type->name);
}
if (printed) {
unsigned int ihash = hash % MTMAXHASH;
struct known_mtype *kmt = mtypehash[ihash];
while (kmt && kmt->mtype != mtype)
kmt = kmt->nexthash;
if (kmt == NULL) {
kmt = (struct known_mtype *)malloc(sizeof(struct known_mtype));
if (!kmt) abort();
kmt->nexthash = mtypehash[ihash];
kmt->mtype = mtype;
mtypehash[ihash] = kmt;
}
}
m = m->next;
}
}
@ -1714,7 +1669,6 @@ report_computer(const char *filename, report_context * ctx, const char *bom)
cr_output_region(F, ctx, r);
}
}
report_crtypes(F, f->locale);
if (f->locale != crtag_locale()) {
report_translations(F);
}

View File

@ -1680,84 +1680,41 @@ static void plant(unit * u, int raw)
u, r, planted, itype->rtype));
}
static void planttrees(unit * u, int raw)
static void planttrees(region * r, int type, int n)
{
int n, i, skill, planted = 0;
const resource_type *rtype;
region * r = u->region;
if (!fval(r->terrain, LAND_REGION)) {
return;
if (n > 0) {
rsettrees(r, type, rtrees(r, type) + n);
}
/* Mallornbaeume kann man nur in Mallornregionen zuechten */
rtype = get_resourcetype(fval(r, RF_MALLORN) ? R_MALLORN_SEED : R_SEED);
/* Skill pruefen */
skill = effskill(u, SK_HERBALISM, NULL);
if (skill < 6) {
ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "plant_skills",
"skill minskill product", SK_HERBALISM, 6, rtype, 1));
return;
}
if (fval(r, RF_MALLORN) && skill < 7) {
ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "plant_skills",
"skill minskill product", SK_HERBALISM, 7, rtype, 1));
return;
}
/* wenn eine Anzahl angegeben wurde, nur soviel verbrauchen */
if (raw > skill * u->number) raw = skill * u->number;
n = get_pooled(u, rtype, GET_DEFAULT, raw);
if (n == 0) {
ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "resource_missing", "missing", rtype));
return;
}
if (n > raw) n = raw;
/* Fuer jeden Samen Talent*10% Erfolgschance. */
for (i = n; i > 0; i--) {
if (rng_int() % 10 < skill)
planted++;
}
rsettrees(r, 0, rtrees(r, 0) + planted);
/* Alles ok. Abziehen. */
produceexp(u, SK_HERBALISM, u->number);
use_pooled(u, rtype, GET_DEFAULT, n);
ADDMSG(&u->faction->msgs, msg_message("plant",
"unit region amount herb", u, r, planted, rtype));
}
/* zuechte baeume */
static void breedtrees(unit * u, int raw)
{
int n, i, skill, planted = 0;
int n, i, skill;
const resource_type *rtype;
season_t current_season = calendar_season(turn);
region *r = u->region;
/* Baeume zuechten geht nur im Fruehling */
if (current_season != SEASON_SPRING) {
planttrees(u, raw);
return;
}
int minskill = 6;
if (!fval(r->terrain, LAND_REGION)) {
return;
}
/* Mallornbaeume kann man nur in Mallornregionen zuechten */
rtype = get_resourcetype(fval(r, RF_MALLORN) ? R_MALLORN_SEED : R_SEED);
if (fval(r, RF_MALLORN)) {
++minskill;
rtype = get_resourcetype(R_MALLORN_SEED);
}
else {
rtype = get_resourcetype(R_SEED);
}
/* Skill pruefen */
skill = effskill(u, SK_HERBALISM, NULL);
if (skill < 12) {
planttrees(u, raw);
if (skill < minskill) {
ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "plant_skills",
"skill minskill product", SK_HERBALISM, 6, rtype, 1));
return;
}
@ -1773,19 +1730,21 @@ static void breedtrees(unit * u, int raw)
}
if (n > raw) n = raw;
/* Fuer jeden Samen Talent*5% Erfolgschance. */
for (i = n; i > 0; i--) {
if (rng_int() % 100 < skill * 5)
planted++;
if (skill >= 12 && current_season == SEASON_SPRING) {
// Plant saplings for every 10 seeds
planttrees(r, 0, n % 10);
planttrees(r, 1, n / 10);
}
else {
planttrees(r, 0, n);
}
rsettrees(r, 1, rtrees(r, 1) + planted);
/* Alles ok. Abziehen. */
/* Alles ok. Samen abziehen. */
produceexp(u, SK_HERBALISM, u->number);
use_pooled(u, rtype, GET_DEFAULT, n);
ADDMSG(&u->faction->msgs, msg_message("plant",
"unit region amount herb", u, r, planted, rtype));
"unit region amount herb", u, r, n, rtype));
}
/* zuechte pferde */

View File

@ -371,7 +371,7 @@ message * give_ship(unit *u1, unit *u2, int n, order *ord)
u2->ship->coast = u1->ship->coast;
}
else {
return msg_error(u1, ord, 182);
return msg_error(u1, ord, 328);
}
}
}
@ -796,6 +796,9 @@ static void give_all_items(unit *u, unit *u2, order *ord) {
}
}
}
else {
cmistake(u, ord, 123, MSG_COMMERCE);
}
}
}
}

View File

@ -47,7 +47,7 @@
static int g_quit;
int force_color = 0;
newfaction * new_players = 0;
newfaction * new_players = NULL;
state *current_state = NULL;

View File

@ -746,10 +746,6 @@ default_wage(const region * r, const faction * f, const race * rc, int in_turn)
variant vm;
/* Godcurse: Income -10 */
c = get_curse(r->attribs, &ct_godcursezone);
if (c && curse_active(c)) {
wage = (wage < 10) ? 0 : (wage - 10);
}
vm = frac_make(wage, 1);
/* Bei einer Duerre verdient man nur noch ein Viertel */

View File

@ -129,6 +129,7 @@ static int read_ccompat(const char *cursename, struct storage *store)
} *seek, old_curses[] = {
{ "disorientationzone", "" },
{ "shipdisorientation", "" },
{ "godcursezone", "" },
{ NULL, NULL }
};
for (seek = old_curses; seek->name; ++seek) {

View File

@ -62,6 +62,7 @@ static message *missing_feedback(const char *name, const struct unit *u,
log_error("trying to create undefined feedback of type \"%s\"\n", name);
}
else if (missing_message_mode == MESSAGE_MISSING_REPLACE) {
log_warning("trying to create undefined message of type \"%s\"\n", name);
if (strcmp(name, "missing_feedback") != 0) {
if (!mt_find("missing_feedback")) {
mt_create_va(mt_new("missing_feedback", NULL), "unit:unit",

View File

@ -294,7 +294,7 @@ static race *rc_find_i(const char *name)
return rc;
}
const race * rc_find(const char *name) {
race * rc_find(const char *name) {
return rc_find_i(name);
}

View File

@ -155,7 +155,7 @@ extern "C" {
race *rc_create(const char *zName);
race *rc_get_or_create(const char *name);
bool rc_changed(int *cache);
const race *rc_find(const char *);
race *rc_find(const char *);
void free_races(void);
bool rc_can_use(const struct race *rc, const struct item_type *itype);

View File

@ -647,7 +647,7 @@ void leave_building(unit * u)
{
building * b = u->building;
u->building = 0;
u->building = NULL;
if (b->_owner == u) {
building_update_owner(b);
assert(b->_owner != u);

View File

@ -8,7 +8,7 @@
#ifndef ERESSEA_VERSION
/* the version number, if it was not passed to make with -D */
#define ERESSEA_VERSION "3.22.0"
#define ERESSEA_VERSION "3.24.0"
#endif
const char *eressea_version(void) {

View File

@ -463,10 +463,7 @@ static void horses(region * r)
maxhorses = region_maxworkers(r) / 10;
horses = rhorses(r);
if (horses > 0) {
if (is_cursed(r->attribs, &ct_godcursezone)) {
rsethorses(r, (int)(horses * 0.9));
}
else if (maxhorses > 0) {
if (maxhorses > 0) {
double growth =
(RESOURCE_QUANTITY * (HORSEGROWTH * 200.0 * ((double)maxhorses -
horses))) / (double)maxhorses;
@ -594,14 +591,21 @@ growing_trees_e3(region * r, const int current_season,
}
}
static int cap_int(int i, int imin, int imax) {
if (i > imin) {
return ((i < imax) ? i : imax);
}
return imin;
}
static void
growing_trees(region * r, const season_t current_season, const season_t last_weeks_season)
{
int grownup_trees, i, seeds, sprout;
attrib *a;
double seedchance = config_get_flt("rules.treeseeds.chance", 0.01F) * RESOURCE_QUANTITY;
if (current_season == SEASON_SUMMER || current_season == SEASON_AUTUMN) {
double seedchance = 0.01F * RESOURCE_QUANTITY;
int mp, elves = count_race(r, get_race(RC_ELF));
direction_t d;
@ -618,12 +622,6 @@ growing_trees(region * r, const season_t current_season, const season_t last_wee
a_removeall(&r->attribs, &at_germs);
}
if (is_cursed(r->attribs, &ct_godcursezone)) {
rsettrees(r, 1, (int)(rtrees(r, 1) * 0.9));
rsettrees(r, 2, (int)(rtrees(r, 2) * 0.9));
return;
}
mp = max_production(r);
if (mp <= 0)
return;
@ -655,6 +653,7 @@ growing_trees(region * r, const season_t current_season, const season_t last_wee
/* Gesamtzahl der Samen:
* bis zu 6% (FORESTGROWTH*3) der Baeume samen in die Nachbarregionen */
if (seedchance > 0) {
seeds = (rtrees(r, 2) * FORESTGROWTH * 3) / 1000000;
for (d = 0; d != MAXDIRECTIONS; ++d) {
region *r2 = rconnect(r, d);
@ -673,66 +672,44 @@ growing_trees(region * r, const season_t current_season, const season_t last_wee
rsettrees(r2, 0, rtrees(r2, 0) + sprout);
}
}
}
}
else if (current_season == SEASON_SPRING) {
int growth;
if (is_cursed(r->attribs, &ct_godcursezone))
return;
/* in at_germs merken uns die Zahl der Samen und Sproesslinge, die
* dieses Jahr aelter werden duerfen, damit nicht ein Same im selben
* Zyklus zum Baum werden kann */
a = a_find(r->attribs, &at_germs);
if (!a) {
a = a_add(&r->attribs, a_new(&at_germs));
a->data.sa[0] = (short)rtrees(r, 0);
a->data.sa[1] = (short)rtrees(r, 1);
a->data.sa[0] = (short)cap_int(rtrees(r, 0), 0, SHRT_MAX);
a->data.sa[1] = (short)cap_int(rtrees(r, 1), 0, SHRT_MAX);
}
/* wir haben 6 Wochen zum wachsen, jeder Same/Spross hat 18% Chance
* zu wachsen, damit sollten nach 5-6 Wochen alle gewachsen sein */
growth = 1800;
/* Samenwachstum */
/* Raubbau abfangen, es duerfen nie mehr Samen wachsen, als aktuell
* in der Region sind */
seeds = rtrees(r, 0);
if (seeds > a->data.sa[0]) seeds = a->data.sa[0];
sprout = 0;
for (i = 0; i < seeds; i++) {
if (rng_int() % 10000 < growth)
sprout++;
else if (a->data.sa[0] < 0 || a->data.sa[1] << 0) {
a->data.sa[0] = (short)cap_int(a->data.sa[0], 0, SHRT_MAX);
a->data.sa[1] = (short)cap_int(a->data.sa[1], 0, SHRT_MAX);
}
/* aus dem Samenpool dieses Jahres abziehen */
a->data.sa[0] = (short)(seeds - sprout);
/* aus dem gesamt Samenpool abziehen */
rsettrees(r, 0, rtrees(r, 0) - sprout);
/* zu den Sproesslinge hinzufuegen */
rsettrees(r, 1, rtrees(r, 1) + sprout);
/* Baumwachstum */
/* hier gehen wir davon aus, das Jungbaeume nicht ohne weiteres aus
* der Region entfernt werden koennen, da Jungbaeume in der gleichen
* Runde nachwachsen, wir also nicht mehr zwischen diesjaehrigen und
* 'alten' Jungbaeumen unterscheiden koennten */
sprout = rtrees(r, 1);
if (sprout > a->data.sa[1]) sprout = a->data.sa[1];
grownup_trees = 0;
for (i = 0; i < sprout; i++) {
if (rng_int() % 10000 < growth)
grownup_trees++;
}
grownup_trees = sprout / 6;
/* aus dem Sproesslingepool dieses Jahres abziehen */
a->data.sa[1] = (short)(sprout - grownup_trees);
/* aus dem gesamt Sproesslingepool abziehen */
rsettrees(r, 1, rtrees(r, 1) - grownup_trees);
/* zu den Baeumen hinzufuegen */
rsettrees(r, 2, rtrees(r, 2) + grownup_trees);
/* Samenwachstum */
seeds = rtrees(r, 0);
if (seeds > a->data.sa[0]) seeds = a->data.sa[0];
sprout = seeds / 6;
/* aus dem Samenpool dieses Jahres abziehen */
a->data.sa[0] = (short)(seeds - sprout);
/* aus dem gesamt Samenpool abziehen */
rsettrees(r, 0, rtrees(r, 0) - sprout);
/* zu den Sproesslinge hinzufuegen */
rsettrees(r, 1, rtrees(r, 1) + sprout);
}
}
@ -1003,7 +980,7 @@ int quit_cmd(unit * u, struct order *ord)
if (p == P_FACTION) {
#ifdef QUIT_WITH_TRANSFER
faction *f2 = getfaction();
if (f2 == NULL) {
if (f2 == NULL || f2 == u->faction) {
cmistake(u, ord, 66, MSG_EVENT);
flags = 0;
}
@ -1249,13 +1226,6 @@ void do_enter(struct region *r, bool is_final_attempt)
}
}
if (ulast != NULL) {
/* Wenn wir hier angekommen sind, war der Befehl
* erfolgreich und wir loeschen ihn, damit er im
* zweiten Versuch nicht nochmal ausgefuehrt wird. */
*ordp = ord->next;
ord->next = NULL;
free_order(ord);
if (ulast != u) {
/* put u behind ulast so it's the last unit in the building */
*uptr = u->next;
@ -3121,14 +3091,7 @@ void update_long_order(unit * u)
}
break;
default:
if (kwd > thiskwd) {
/* swap out thisorder for the new one */
cmistake(u, u->thisorder, 52, MSG_EVENT);
set_order(&u->thisorder, copy_order(ord));
}
else {
cmistake(u, ord, 52, MSG_EVENT);
}
break;
}
}
@ -3712,8 +3675,9 @@ void process(void)
log_debug("- Step %u", prio);
while (proc && proc->priority == prio) {
if (proc->name)
if (proc->name) {
log_debug(" - %s", proc->name);
}
proc = proc->next;
}
@ -3721,8 +3685,9 @@ void process(void)
pglobal->data.global.process();
pglobal = pglobal->next;
}
if (pglobal == NULL || pglobal->priority != prio)
if (pglobal == NULL || pglobal->priority != prio) {
continue;
}
for (r = regions; r; r = r->next) {
unit *u;
@ -3733,8 +3698,9 @@ void process(void)
pregion->data.per_region.process(r);
pregion = pregion->next;
}
if (pregion == NULL || pregion->priority != prio)
if (pregion == NULL || pregion->priority != prio) {
continue;
}
if (r->units) {
for (u = r->units; u; u = u->next) {
@ -3744,14 +3710,16 @@ void process(void)
punit->data.per_unit.process(u);
punit = punit->next;
}
if (punit == NULL || punit->priority != prio)
if (punit == NULL || punit->priority != prio) {
continue;
}
porder = punit;
while (porder && porder->priority == prio && porder->type == PR_ORDER) {
order **ordp = &u->orders;
if (porder->flags & PROC_THISORDER)
if (porder->flags & PROC_THISORDER) {
ordp = &u->thisorder;
}
while (*ordp) {
order *ord = *ordp;
if (getkeyword(ord) == porder->data.per_order.kword) {
@ -3780,9 +3748,10 @@ void process(void)
}
}
}
if (!ord || *ordp == ord)
if (!ord || *ordp == ord) {
ordp = &(*ordp)->next;
}
}
porder = porder->next;
}
}
@ -3798,9 +3767,9 @@ void process(void)
pregion->data.per_region.process(r);
pregion = pregion->next;
}
if (pregion == NULL || pregion->priority != prio)
if (pregion == NULL || pregion->priority != prio) {
continue;
}
}
}

View File

@ -290,8 +290,6 @@ void locale_init(void)
}
}
extern void bind_monsters(lua_State *L);
int main(int argc, char **argv)
{
int err = 0;

View File

@ -87,6 +87,9 @@ newfaction *read_newfactions(const char *filename)
if (fgets(buf, sizeof(buf), F) == NULL)
break;
if (buf[0] == '#') {
continue;
}
email[0] = '\0';
password[0] = '\0';
@ -95,9 +98,6 @@ newfaction *read_newfactions(const char *filename)
password, &alliance) < 3) {
break;
}
if (email[0] == '#') {
continue;
}
if (email[0] == '\0') {
break;
}

View File

@ -44,6 +44,7 @@
/* attributes includes */
#include <attributes/targetregion.h>
#include <attributes/otherfaction.h>
#include <attributes/hate.h>
#include <spells/regioncurse.h>
@ -142,18 +143,39 @@ static void reduce_weight(unit * u)
}
}
static bool monster_is_waiting(const unit * u)
{
int test = fval(u_race(u), RCF_ATTACK_MOVED) ? UFL_ISNEW : UFL_ISNEW | UFL_MOVED;
if (fval(u, test))
return true;
return false;
}
static bool monster_can_attack(const unit * u)
{
if (u->status >= ST_AVOID) {
return false;
}
if (u->region->land) {
return is_guard(u);
}
else if (fval(u->region->terrain, SEA_REGION)) {
return fval(u_race(u), RCF_SWIM);
}
return fval(u_race(u), RCF_FLY);
}
static order *monster_attack(unit * u, const unit * target)
{
assert(u->region == target->region);
assert(u->faction != target->faction);
if (!cansee(u->faction, u->region, target, 0))
return NULL;
if (monster_is_waiting(u))
return NULL;
if (u->region->land && (u->region->flags & RF_GUARDED) == 0) {
if (!cansee(u->faction, u->region, target, 0)) {
return NULL;
}
if (monster_is_waiting(u)) {
return NULL;
}
return create_order(K_ATTACK, u->faction->locale, "%i", target->no);
}
@ -185,7 +207,8 @@ int monster_attacks(unit * monster, bool rich_only)
{
const race *rc_serpent = get_race(RC_SEASERPENT);
int result = -1;
if (monster->status < ST_AVOID) {
if (monster_can_attack(monster)) {
region *r = monster->region;
unit *u2;
int money = 0;
@ -214,10 +237,10 @@ int monster_attacks(unit * monster, bool rich_only)
return result;
}
static order *get_money_for_dragon(region * r, unit * udragon, int wanted)
static order *get_money_for_dragon(region * r, unit * u, int wanted)
{
int money;
bool attacks = attack_chance > 0.0;
bool attacks = (attack_chance > 0.0) && armedmen(u, false);
/* falls genug geld in der region ist, treiben wir steuern ein. */
if (rmoney(r) >= wanted) {
@ -231,8 +254,8 @@ static order *get_money_for_dragon(region * r, unit * udragon, int wanted)
/* falls der drache launisch ist, oder das regionssilber knapp, greift er alle an
* und holt sich Silber von Einheiten, vorausgesetzt er bewacht bereits */
money = 0;
if (attacks && is_guard(udragon)) {
int m = monster_attacks(udragon, true);
if (attacks && monster_can_attack(u)) {
int m = monster_attacks(u, true);
if (m > 0) money += m;
}
@ -623,11 +646,11 @@ static order *plan_dragon(unit * u)
rc_wyrm = get_race(RC_WYRM);
}
if (ta == NULL) {
move |= (rpeasants(r) == 0); /* when no peasants, move */
move |= (rmoney(r) == 0); /* when no money, move */
if (!move && ta == NULL) {
move = (rpeasants(r) == 0); /* when no peasants, move */
move = move || (rmoney(r) == 0); /* when no money, move */
}
move |= chance(0.04); /* 4% chance to change your mind */
move = move || chance(0.04); /* 4% chance to change your mind */
if (rc == rc_wyrm && !move) {
unit *u2;
@ -739,6 +762,7 @@ void plan_monsters(faction * f)
attrib *ta;
order *long_order = NULL;
bool can_move = true;
bool guarding;
/* Ab hier nur noch Befehle fuer NPC-Einheiten. */
if (u->faction != f || u->number <= 0) {
@ -749,6 +773,7 @@ void plan_monsters(faction * f)
if (fval(u, UFL_ANON_FACTION)) {
u->flags &= ~UFL_ANON_FACTION;
}
a_removeall(&u->attribs, &at_otherfaction);
if (rc->splitsize < 10) {
/* hermit-type monsters eat each other */
@ -763,8 +788,9 @@ void plan_monsters(faction * f)
/* Befehle muessen jede Runde neu gegeben werden: */
free_orders(&u->orders);
/* All monsters guard the region: */
if (u->status < ST_FLEE && !monster_is_waiting(u) && r->land) {
guarding = is_guard(u);
/* All monsters want to guard the region: */
if (!guarding && u->status < ST_FLEE && !monster_is_waiting(u) && r->land) {
unit_addorder(u, create_order(K_GUARD, u->faction->locale, NULL));
}
@ -772,7 +798,7 @@ void plan_monsters(faction * f)
ta = a_find(u->attribs, &at_hate);
if (ta && !monster_is_waiting(u)) {
unit *tu = (unit *)ta->data.v;
if (tu && tu->region == r) {
if (tu && tu->region == r && monster_can_attack(u)) {
order * ord = monster_attack(u, tu);
if (ord) {
unit_addorder(u, ord);
@ -790,7 +816,7 @@ void plan_monsters(faction * f)
else
a_remove(&u->attribs, ta);
}
else if (!r->land || is_guard(u)) {
else if (monster_can_attack(u)) {
if (chance(attack_chance)) {
int m = monster_attacks(u, false);
if (m >= 0) {
@ -1011,14 +1037,6 @@ void spawn_undead(void)
}
}
bool monster_is_waiting(const unit * u)
{
int test = fval(u_race(u), RCF_ATTACK_MOVED) ? UFL_ISNEW : UFL_ISNEW | UFL_MOVED;
if (fval(u, test))
return true;
return false;
}
static void eaten_by_monster(unit * u)
{
/* adjustment for smaller worlds */

View File

@ -18,9 +18,12 @@ extern "C" {
void monsters_desert(struct faction *monsters);
void monster_kills_peasants(struct unit *u);
bool monster_is_waiting(const struct unit *u);
void make_zombie(struct unit * u);
void spawn_undead(void);
void plan_monsters(struct faction *f);
#ifdef __cplusplus
}
#endif

View File

@ -97,6 +97,7 @@ static void test_monsters_attack_ocean(CuTest * tc)
{
region *r;
unit *u, *m;
race *rc;
test_setup();
create_monsters(&u, &m);
@ -107,10 +108,16 @@ static void test_monsters_attack_ocean(CuTest * tc)
assert(!m->region->land);
config_set("rules.monsters.attack_chance", "1");
rc = rc_find(m->_race->_name);
freset(rc, RCF_SWIM);
plan_monsters(m->faction);
CuAssertPtrEquals(tc, NULL, find_order("attack 2", m));
fset(rc, RCF_SWIM);
plan_monsters(m->faction);
CuAssertPtrNotNull(tc, find_order("attack 2", m));
test_teardown();
}
@ -145,7 +152,7 @@ static void test_seaserpent_piracy(CuTest * tc)
u_setrace(m, rc = test_create_race("seaserpent"));
assert(!m->region->land);
fset(m, UFL_MOVED);
fset(rc, RCF_ATTACK_MOVED);
fset(rc, RCF_ATTACK_MOVED|RCF_SWIM);
config_set("rules.monsters.attack_chance", "1");

View File

@ -974,10 +974,17 @@ bool move_blocked(const unit * u, const region * r, const region * r2)
}
if (r->attribs) {
const curse_type *fogtrap_ct = &ct_fogtrap;
curse *c = get_curse(r->attribs, fogtrap_ct);
curse *c = get_curse(r->attribs, &ct_fogtrap);
if (curse_active(c)) {
return true;
}
}
if (r2->attribs && fval(u_race(u), RCF_UNDEAD)) {
curse *c = get_curse(r2->attribs, &ct_holyground);
return curse_active(c);
}
return false;
}

View File

@ -48,182 +48,6 @@ static void begin_orders(unit *u) {
u->orders = NULL;
}
static void unitorders(input *in, faction *f)
{
int i;
unit *u;
assert(f);
i = getid();
u = findunit(i);
if (u && u->faction == f) {
order **ordp;
begin_orders(u);
ordp = &u->orders;
for (;;) {
const char *s;
/* Erst wenn wir sicher sind, dass kein Befehl
* eingegeben wurde, checken wir, ob nun eine neue
* Einheit oder ein neuer Spieler drankommt */
s = in->getbuf(in->data);
if (s == NULL)
break;
if (s[0]) {
if (s[0] != '@') {
char token[64];
const char *stok = s;
stok = parse_token(&stok, token, sizeof(token));
if (stok) {
bool quit = false;
param_t param = findparam(stok, u->faction->locale);
switch (param) {
case P_UNIT:
case P_REGION:
quit = true;
break;
case P_FACTION:
case P_NEXT:
case P_GAMENAME:
/* these terminate the orders, so we apply extra checking */
if (strlen(stok) >= 3) {
quit = true;
break;
}
else {
quit = false;
}
break;
default:
break;
}
if (quit) {
break;
}
}
}
/* Nun wird der Befehl erzeut und eingehaengt */
*ordp = parse_order(s, u->faction->locale);
if (*ordp) {
ordp = &(*ordp)->next;
}
else {
ADDMSG(&f->msgs, msg_message("parse_error", "unit command", u, s));
}
}
}
}
}
static faction *factionorders(void)
{
int fid = getid();
faction *f = findfaction(fid);
if (f != NULL && (f->flags & FFL_NPC) == 0) {
char token[PASSWORD_MAXSIZE];
const char *pass = gettoken(token, sizeof(token));
if (!checkpasswd(f, (const char *)pass)) {
log_debug("Invalid password for faction %s", itoa36(fid));
ADDMSG(&f->msgs, msg_message("wrongpasswd", "password", pass));
return 0;
}
/* Die Partei hat sich zumindest gemeldet, so dass sie noch
* nicht als untaetig gilt */
f->lastorders = turn;
}
else {
log_debug("orders for invalid faction %s", itoa36(fid));
}
return f;
}
int read_orders(input *in)
{
const char *b;
int nfactions = 0;
struct faction *f = NULL;
const struct locale *lang = default_locale;
/* TODO: recognize UTF8 BOM */
b = in->getbuf(in->data);
/* Auffinden der ersten Partei, und danach abarbeiten bis zur letzten
* Partei */
while (b) {
char token[128];
param_t p;
const char *s;
init_tokens_str(b);
s = gettoken(token, sizeof(token));
p = findparam_block(s, lang, true);
switch (p) {
case P_GAMENAME:
case P_FACTION:
f = factionorders();
if (f) {
lang = f->locale;
++nfactions;
}
b = in->getbuf(in->data);
break;
/* in factionorders wird nur eine zeile gelesen:
* diejenige mit dem passwort. Die befehle der units
* werden geloescht, und die Partei wird als aktiv
* vermerkt. */
case P_UNIT:
if (f) {
unitorders(in, f);
do {
b = in->getbuf(in->data);
if (!b) {
break;
}
init_tokens_str(b);
s = gettoken(token, sizeof(token));
p = (s && s[0] != '@') ? findparam(s, lang) : NOPARAM;
} while ((p != P_UNIT || !f) && p != P_FACTION && p != P_NEXT
&& p != P_GAMENAME);
}
break;
/* Falls in unitorders() abgebrochen wird, steht dort entweder eine neue
* Partei, eine neue Einheit oder das File-Ende. Das switch() wird erneut
* durchlaufen, und die entsprechende Funktion aufgerufen. Man darf buf
* auf alle Faelle nicht ueberschreiben! Bei allen anderen Eintraegen hier
* muss buf erneut gefaellt werden, da die betreffende Information in nur
* einer Zeile steht, und nun die naechste gelesen werden muss.
*/
case P_NEXT:
f = NULL;
lang = default_locale;
b = in->getbuf(in->data);
break;
default:
b = in->getbuf(in->data);
break;
}
}
log_info("done reading orders for %d factions", nfactions);
return 0;
}
typedef struct parser_state {
unit *u;
faction *f;

View File

@ -12,7 +12,6 @@ extern "C" {
void *data;
} input;
int read_orders(struct input *in);
int parseorders(FILE *F);
#ifdef __cplusplus

View File

@ -21,82 +21,36 @@
#include <CuTest.h>
#include <tests.h>
static const char *getbuf_null(void *data)
{
return NULL;
}
static void test_read_orders(CuTest *tc) {
input in;
test_setup();
in.getbuf = getbuf_null;
in.data = NULL;
CuAssertIntEquals(tc, 0, read_orders(&in));
test_teardown();
}
static const char *getbuf_strings(void *data)
{
strlist **listp = (strlist **)data;
if (listp && *listp) {
strlist *list = *listp;
*listp = list->next;
return list->s;
}
return NULL;
}
static void test_unit_orders(CuTest *tc) {
input in;
unit *u;
faction *f;
strlist *orders = NULL, *backup;
char buf[64];
FILE *F = tmpfile();
test_setup();
u = test_create_unit(f = test_create_faction(NULL), test_create_plain(0, 0));
f->locale = test_create_locale();
u->orders = create_order(K_ENTERTAIN, f->locale, NULL);
faction_setpassword(f, password_hash("password", PASSWORD_DEFAULT));
snprintf(buf, sizeof(buf), "%s %s %s",
fprintf(F, "%s %s %s\n",
LOC(f->locale, parameters[P_FACTION]), itoa36(f->no), "password");
addstrlist(&orders, buf);
snprintf(buf, sizeof(buf), "%s %s",
fprintf(F, "%s %s\n",
LOC(f->locale, parameters[P_UNIT]), itoa36(u->no));
addstrlist(&orders, buf);
snprintf(buf, sizeof(buf), "%s %s", keyword_name(K_MOVE, f->locale),
fprintf(F, "%s %s\n", keyword_name(K_MOVE, f->locale),
LOC(f->locale, shortdirections[D_WEST]));
backup = orders;
addstrlist(&orders, buf);
in.data = &orders;
in.getbuf = getbuf_strings;
CuAssertIntEquals(tc, 0, read_orders(&in));
rewind(F);
CuAssertIntEquals(tc, 0, parseorders(F));
CuAssertPtrNotNull(tc, u->old_orders);
CuAssertPtrNotNull(tc, u->orders);
CuAssertPtrEquals(tc, NULL, orders);
CuAssertIntEquals(tc, K_MOVE, getkeyword(u->orders));
CuAssertIntEquals(tc, K_ENTERTAIN, getkeyword(u->old_orders));
CuAssertIntEquals(tc, UFL_ORDERS, u->flags & UFL_ORDERS);
freestrlist(backup);
fclose(F);
test_teardown();
}
typedef struct order_list {
const char **orders;
int next;
} order_list;
static const char *getbuf_list(void *data)
{
order_list * olist = (order_list *)data;
return olist->orders[olist->next++];
}
static void test_faction_password_okay(CuTest *tc) {
input in;
faction *f;
order_list olist;
const char *orders[] = { "ERESSEA 1 password", NULL };
FILE *F;
test_setup();
f = test_create_faction(NULL);
@ -104,21 +58,18 @@ static void test_faction_password_okay(CuTest *tc) {
CuAssertIntEquals(tc, 1, f->no);
faction_setpassword(f, "password");
f->lastorders = turn - 1;
olist.orders = orders;
olist.next = 0;
in.getbuf = getbuf_list;
in.data = &olist;
CuAssertIntEquals(tc, 0, read_orders(&in));
CuAssertIntEquals(tc, 2, olist.next);
F = tmpfile();
fprintf(F, "ERESSEA 1 password\n");
rewind(F);
CuAssertIntEquals(tc, 0, parseorders(F));
CuAssertIntEquals(tc, turn, f->lastorders);
fclose(F);
test_teardown();
}
static void test_faction_password_bad(CuTest *tc) {
input in;
faction *f;
order_list olist;
const char *orders[] = { "ERESSEA 1 password", NULL };
FILE *F;
test_setup();
mt_create_va(mt_new("wrongpasswd", NULL), "password:string", MT_NEW_END);
@ -128,20 +79,18 @@ static void test_faction_password_bad(CuTest *tc) {
CuAssertIntEquals(tc, 1, f->no);
faction_setpassword(f, "patzword");
f->lastorders = turn - 1;
olist.orders = orders;
olist.next = 0;
in.getbuf = getbuf_list;
in.data = &olist;
CuAssertIntEquals(tc, 0, read_orders(&in));
CuAssertIntEquals(tc, 2, olist.next);
F = tmpfile();
fprintf(F, "ERESSEA 1 password\n");
rewind(F);
CuAssertIntEquals(tc, 0, parseorders(F));
CuAssertIntEquals(tc, turn - 1, f->lastorders);
fclose(F);
test_teardown();
}
CuSuite *get_orderfile_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_read_orders);
SUITE_ADD_TEST(suite, test_unit_orders);
SUITE_ADD_TEST(suite, test_faction_password_okay);
SUITE_ADD_TEST(suite, test_faction_password_bad);

View File

@ -380,44 +380,6 @@ static void create_icebergs(void)
}
}
static void godcurse(void)
{
region *r;
for (r = regions; r; r = r->next) {
if (is_cursed(r->attribs, &ct_godcursezone)) {
unit *u;
for (u = r->units; u; u = u->next) {
skill *sv = u->skills;
while (sv != u->skills + u->skill_size) {
int weeks = 1 + rng_int() % 3;
reduce_skill(u, sv, weeks);
++sv;
}
}
if (fval(r->terrain, SEA_REGION)) {
ship *sh;
for (sh = r->ships; sh;) {
ship *shn = sh->next;
double dmg = config_get_flt("rules.ship.damage.godcurse", 0.1);
damage_ship(sh, dmg);
if (sh->damage >= sh->size * DAMAGE_SCALE) {
unit *uo = ship_owner(sh);
if (uo) {
ADDMSG(&uo->faction->msgs,
msg_message("godcurse_destroy_ship", "ship", sh));
}
sink_ship(sh);
remove_ship(&sh->region->ships, sh);
}
sh = shn;
}
}
}
}
}
/** handles the "orcish" curse that makes units grow like old orks
* TODO: This would probably be better handled in an age-function for the curse,
* but it's now being called by randomevents()
@ -535,7 +497,6 @@ void randomevents(void)
for (r = regions; r; r = r->next) {
drown(r);
}
godcurse();
orc_growth();
demon_skillchanges();
if (volcano_module()) {

View File

@ -1718,23 +1718,23 @@ nr_ship(struct stream *out, const region *r, const ship * sh, const faction * f,
char buffer[1024];
char ch;
sbstring sbs;
const char *stname;
sbs_init(&sbs, buffer, sizeof(buffer));
newline(out);
stname = locale_plural(f->locale, sh->type->_name, sh->number, true);
if (captain && captain->faction == f) {
int n = 0, p = 0;
const char *stname;
getshipweight(sh, &n, &p);
n = (n + 99) / 100; /* 1 Silber = 1 GE */
stname = locale_plural(f->locale, sh->type->_name, sh->number, true);
sbs_printf(&sbs, "%s, %d %s, (%d/%d)", shipname(sh), sh->number,
stname, n, ship_capacity(sh) / 100);
}
else {
sbs_printf(&sbs, "%s, %s", shipname(sh), LOC(f->locale, sh->type->_name));
sbs_printf(&sbs, "%s, %d %s", shipname(sh), sh->number, stname);
}
if (!ship_finished(sh)) {

View File

@ -2358,9 +2358,8 @@ static void patzer_peasantmob(const castorder * co)
rsetpeasants(r, rpeasants(r) - n);
assert(rpeasants(r) >= 0);
u =
create_unit(r, f, n, get_race(RC_PEASANT), 0, LOC(f->locale, "angry_mob"),
NULL);
u = create_unit(r, f, n, get_race(RC_PEASANT), 0,
LOC(f->locale, "angry_mob"), NULL);
fset(u, UFL_ISNEW);
unit_addorder(u, create_order(K_GUARD, lang, NULL));
set_order(&u->thisorder, default_order(lang));

View File

@ -56,7 +56,7 @@ int sp_flying_ship(castorder * co)
if (pa->param[0]->flag == TARGET_NOTFOUND)
return 0;
sh = pa->param[0]->data.sh;
if (sh->type->construction->maxsize > 50) {
if (sh->number > 1 || sh->type->construction->maxsize > 50) {
ADDMSG(&caster->faction->msgs, msg_feedback(caster, co->order,
"error_flying_ship_too_big", "ship", sh));
return 0;

View File

@ -22,30 +22,6 @@
#include <stdlib.h>
#include <assert.h>
/*
* godcursezone
*/
static message *cinfo_cursed_by_the_gods(const void *obj, objtype_t typ,
const curse * c, int self)
{
region *r = (region *)obj;
UNUSED_ARG(typ);
UNUSED_ARG(self);
assert(typ == TYP_REGION);
if (r->terrain->flags & SEA_REGION) {
return msg_message("curseinfo::godcurseocean", "id", c->no);
}
return msg_message("curseinfo::godcurse", "id", c->no);
}
const struct curse_type ct_godcursezone = {
"godcursezone",
CURSETYP_NORM, CURSE_IMMUNE, (NO_MERGE),
cinfo_cursed_by_the_gods,
};
/* --------------------------------------------------------------------- */
/*
* C_GBDREAM
@ -299,7 +275,6 @@ void register_regioncurse(void)
ct_register(&ct_badmagicresistancezone);
ct_register(&ct_goodmagicresistancezone);
ct_register(&ct_riotzone);
ct_register(&ct_godcursezone);
ct_register(&ct_holyground);
ct_register(&ct_healing);
}

View File

@ -10,7 +10,6 @@ extern "C" {
extern const struct curse_type ct_peacezone;
extern const struct curse_type ct_drought;
extern const struct curse_type ct_blessedharvest;
extern const struct curse_type ct_godcursezone;
extern const struct curse_type ct_gbdream;
extern const struct curse_type ct_healing;
extern const struct curse_type ct_antimagiczone;

View File

@ -277,7 +277,7 @@ const message_type *mt_find(const char *name)
return data;
}
}
return 0;
return NULL;
}
void msg_free(message * msg)

View File

@ -106,10 +106,9 @@ param_t findparam_block(const char *s, const struct locale *lang, bool any_local
bool isparam(const char *s, const struct locale * lang, param_t param)
{
assert(s);
assert(param != P_GEBAEUDE);
assert(param != P_BUILDING);
if (s[0] > '@') {
if (s && s[0] > '@') {
param_t p = findparam(s, lang);
return p == param;
}