Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Enno Rehling 2018-09-09 12:11:24 +02:00
commit fe58b624b1
88 changed files with 1655 additions and 1205 deletions

2
clibs

@ -1 +1 @@
Subproject commit d86c8525489d7f11b7ba13e101bb59ecf160b871
Subproject commit 66a891b383f1a51bb0d4e5cf002530f7f70bf7f4

View file

@ -39,7 +39,7 @@
"entertain.perlevel": 20,
"taxing.perlevel": 20,
"nmr.timeout": 5,
"nmr.removenewbie": 0,
"nmr.removenewbie": false,
"GiveRestriction": 3,
"hunger.long": true,
"init_spells": 0,

View file

@ -1,7 +1,9 @@
{
"include": [
"config://res/translations/strings.de.po",
"config://res/translations/strings-e2.de.po",
"config://res/translations/strings.en.po",
"config://res/translations/strings-e2.en.po",
"config://res/translations/messages.de.po",
"config://res/translations/messages.en.po",
"config://res/core/messages.xml"

View file

@ -58,7 +58,7 @@
"entertain.base": 0,
"entertain.perlevel": 20,
"nmr.timeout": 5,
"nmr.removenewbie": 0,
"nmr.removenewbie": false,
"GiveRestriction": 3,
"healing.forest": 2.0,
"hunger.long": false,

View file

@ -28,6 +28,9 @@ if [ -e orders.$TURN ]; then
files="$files orders.$TURN"
fi
echo "backup turn $TURN, game $GAME, files: $files"
if [ -d reports ] ; then
tar cjf backup/$TURN-reports.tar.bz2 reports
fi
tar cjf backup/$TURN.tar.bz2 $files
echo "uploading game-$GAME/$TURN.tar.bz2"
curl -s -n -T backup/$TURN.tar.bz2 https://dav.box.com/dav/Eressea/game-$GAME/$TURN.tar.bz2

View file

@ -25,6 +25,6 @@ addr=$1
subj=$2
shift 2
mutt -F "$ERESSEA/etc/muttrc" -s "$subj" -a "$@" -- "$addr" \
mutt -s "$subj" -a "$@" -- "$addr" \
< "$ERESSEA/server/etc/$TEMPLATE"

View file

@ -44,6 +44,6 @@ addr=$1
subject=$2
shift 2
mutt -F "$ERESSEA/etc/muttrc" -s "$subject" -a "$@" -- "$addr" \
mutt -s "$subject" -a "$@" -- "$addr" \
< "$TEMPLATE" || echo "Sending failed for email/report: $2/$3"

View file

@ -868,21 +868,6 @@
</type>
</message>
<message name="sink_lost_msg" section="events">
<type>
<arg name="dead" type="int"/>
<arg name="region" type="region"/>
<arg name="unit" type="unit"/>
</type>
</message>
<message name="sink_saved_msg" section="events">
<type>
<arg name="region" type="region"/>
<arg name="unit" type="unit"/>
</type>
</message>
<message name="sink_msg" section="events">
<type>
<arg name="ship" type="ship"/>

View file

@ -1773,7 +1773,7 @@ msgid "storm"
msgstr "\"Die $ship($ship) wird in $region($region) von Stürmen abgetrieben$if($sink,\" und sinkt\",\"\").\""
msgid "nr_insectwinter"
msgstr "Es ist Winter, und Insekten können nur in Wüsten oder mit Hilfe des Nestwärme-Tranks Personen rekrutieren."
msgstr "Insekten können wegen des Winterwetters in der kommenden Woche nur in Wüsten oder mit Hilfe des Nestwärme-Tranks Personen rekrutieren."
msgid "spellfail_nomonsters"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Dieser Zauber kann nicht auf Monster gezaubert werden.\""
@ -2121,7 +2121,7 @@ msgid "missing_components"
msgstr "\"$unit($unit) hat nicht genügend Komponenten um $spell($spell) auf Stufe $int($level) zu zaubern.\""
msgid "seduce_effect_1"
msgstr "\"$unit($unit) verfiel dem Glücksspiel und hat fast sein ganzes Hab und gut verspielt.\""
msgstr "\"$unit($unit) verfiel dem Glücksspiel und hat fast sein ganzes Hab und Gut verspielt.\""
msgid "xmastree_effect"
msgstr "\"In der Region erstrahlen des Nachts bunte Lichter, Gloeckchen klingeln und frohes Kindergelaechter klingt durch den Wald.\""
@ -2303,9 +2303,6 @@ msgstr "\"$unit($mage) erleidet durch den Tod seines Vertrauten einen Schock.\""
msgid "error269"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Hier kann man nicht zaubern.\""
msgid "sink_saved_msg"
msgstr "\"$unit($unit) überlebt unbeschadet und rettet sich nach $region($region).\""
msgid "race_noregroup"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - $race($race,0) können nicht neu gruppiert werden.\""
@ -2654,9 +2651,6 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - Die Einheit kan
msgid "analyse_building_noage"
msgstr "\"$unit($mage) fand heraus, dass auf $building($building) der Zauber '$curse($curse)' liegt, dessen Kraft ausreicht, um noch Jahrhunderte bestehen zu bleiben.\""
msgid "sink_lost_msg"
msgstr "\"$int($amount) Personen von $unit($unit) ertrinken.$if($isnull($region),\"\",\" Die Einheit rettet sich nach $region($region).\")\""
msgid "error130"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Syntax: MAGIEGEBIET [1-5].\""
@ -2733,7 +2727,7 @@ msgid "volcanostartsmoke"
msgstr "\"Aus dem Vulkankrater von $region($region) steigt plötzlich Rauch.\""
msgid "nr_insectfall"
msgstr "Es ist Spätherbst, und diese Woche ist die letzte vor dem Winter, in der Insekten rekrutieren können."
msgstr "Es ist Spätherbst, und die kommende Woche ist die letzte vor dem Winter, in der Insekten rekrutieren können."
msgid "error296"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Hier werden niemals Bäume wachsen.\""

View file

@ -2303,9 +2303,6 @@ msgstr "\"$unit($mage) receives a shock when his familiar dies.\""
msgid "error269"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - You cannot cast spells here.\""
msgid "sink_saved_msg"
msgstr "\"$unit($unit) survives unscathed and makes it to $region($region).\""
msgid "race_noregroup"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - $race($race,0) cannot be regrouped.\""
@ -2654,9 +2651,6 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - The unit cannot
msgid "analyse_building_noage"
msgstr "\"$unit($mage) discovers that $building($building) is charmed with '$curse($curse)', which will last for centuries.\""
msgid "sink_lost_msg"
msgstr "\"$int($amount) people of $unit($unit) drown.$if($isnull($region),\"\",\" The unit makes it to $region($region).\")\""
msgid "error130"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Syntax: MAGIC SPHERE [1-5].\""

View file

@ -0,0 +1,49 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: de\n"
"X-Generator: Poedit 2.0.7\n"
msgctxt "spellinfo"
msgid "concealing_aura"
msgstr "Dieser Zauber wird die gesamte Ausrüstung der Zieleinheit für einige Zeit vor den Blicken anderer verschleiern."
msgctxt "spellinfo"
msgid "raindance"
msgstr "Dieses uralte Tanzritual ruft die Kräfte des Lebens und der Fruchtbarkeit. Die Erträge der Bauern werden für einige Wochen deutlich besser ausfallen."
msgctxt "spellinfo"
msgid "earn_silver#gwyrrd"
msgstr "Die Fähigkeiten der Gwyrrd-Magier in der Viehzucht und Heilung sind bei den Bauern sehr begehrt. Gerade auf Märkten sind ihre Dienste häufig sehr gefragt. Manch einer mag auch sein Talent dazu nutzen, ein Tier für einen besseren Preis zu verkaufen. Pro Stufe kann der Magier so 50 Silber verdienen."
msgctxt "spellinfo"
msgid "earn_silver#draig"
msgstr "In den dunkleren Gassen gibt es sie, die Flüche und Verhexungen auf Bestellung. Aber auch Gegenzauber hat der Jünger des Draigs natürlich im Angebot. Ob nun der Sohn des Nachbarn in einen Liebesbann gezogen werden soll oder die Nebenbuhlerin Pickel und Warzen bekommen soll, niemand gibt gerne zu, zu solchen Mitteln gegriffen zu haben. Für diese Dienstleistung streicht der Magier 50 Silber pro Stufe ein."
msgctxt "spellinfo"
msgid "earn_silver#cerddor"
msgstr "Cerddormagier sind die führenden Gaukler unter den Magiern, sie lieben es das Volk zu unterhalten und im Mittelpunkt zu stehen. Schon Anfänger lernen die kleinen Kunststücke und magischen Tricks, mit denen man das Volk locken und verführen kann, den Geldbeutel ganz weit zu öffnen, und am Ende der Woche wird der Gaukler 50 Silber pro Stufe verdient haben."
msgctxt "spellinfo"
msgid "earn_silver#tybied"
msgstr "Wenn einem der Alchemist nicht weiterhelfen kann, geht man zu dem gelehrten Tybiedmagier. Seine Tränke und Tinkturen helfen gegen alles, was man sonst nicht bekommen kann. Ob nun die kryptische Formel unter dem Holzschuh des untreuen Ehemannes wirklich geholfen hat - nun, der des Lesens nicht mächtige Bauer wird es nie wissen. Dem Magier hilft es auf jeden Fall... beim Füllen seines Geldbeutels. 50 Silber pro Stufe lassen sich so in einer Woche verdienen."
msgctxt "spellinfo"
msgid "earn_silver#illaun"
msgstr "Niemand kann so gut die Träume deuten wie ein Magier des Illaun. Auch die Kunst der Wahrsagerei, des Kartenlegens und des Handlesens sind ihm geläufig. Dafür zahlen ihm die Bauern 50 Silber pro Stufe."
msgctxt "describe"
msgid "lifepotion"
msgstr "Das 'Wasser des Lebens' ist in der Lage, aus gefällten Baumstämmen wieder lebende Bäume zu machen. Dazu wird ein knotiger Saugwurz zusammen mit einem Elfenlieb erwärmt, so dass man gerade noch den Finger reinhalten kann. Dies gieße man in ein Gefäß und lasse es langsam abkühlen. Der Extrakt reicht für 10 Holzstämme."
msgctxt "spellinfo"
msgid "blessedharvest"
msgstr "Dieses Ernteritual verbessert die Erträge der arbeitenden Bauern in der Region um ein Silberstück. Je mehr Kraft der Druide investiert, desto länger wirkt der Zauber."

View file

@ -0,0 +1,49 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: en\n"
"X-Generator: Poedit 2.0.7\n"
msgctxt "spellinfo"
msgid "earn_silver#gwyrrd"
msgstr "The abilities of the mages of Gwyrrd concerning the breeding and healing of cattle are highly appreciated among the peasants. Especially at the markets, their services are demanded frequently. Some of them also use their talents to sell an animal at a higher price. A magician can earn 50 silver pieces per level in this way."
msgctxt "spellinfo"
msgid "earn_silver#draig"
msgstr "In the dark alleys you can find those who sell curses and hexes on demand - but you can buy the apropriate counterspells from the followers of Draig as well. May it be a love spell for the son of a neighbour or a wart in the face of a rival. For offering these services, the sorcerer charges 50 silver pieces per level."
msgctxt "spellinfo"
msgid "earn_silver#cerddor"
msgstr "The mages of Cerddor truly are the bards of the wizards; they love to use their sorcery to entertain the crowds and to be the center of attention. Even the apprentices study those little magic tricks, which attract and fascinate the people and thus ensnare them into leaving a few coins or more for the artist. By the end of the week, the bard will have earned 50 silver per level."
msgctxt "spellinfo"
msgid "earn_silver#illaun"
msgstr "No one can read dreams as well as the mages of Illaun. Furthermore, they are also familiar with all other common means of foretelling the future like crystal balls, tarot cards or palms. A mentalist can earn 50 silver pieces per level and week for offering these services to peasants."
msgctxt "spellinfo"
msgid "earn_silver#tybied"
msgstr "If the local alchemist could not help you, you should visit a scholar of Tybied. His potions and tinctures may help when nothing else does. If the cryptic formula under the wooden shoes of the unfaithful husband really helped? - well, the peasant, who isn't capable of reading, will never know. At least it helped the magician... to fill his purse. In one week he can earn 50 silver per level that way."
msgctxt "spellinfo"
msgid "blessedharvest"
msgstr "This ritual increases the output of the local farms. Peasants in the region produce an extra silverpiece. The stronger the druid's spell is, the longer the effect will last."
msgctxt "spellinfo"
msgid "raindance"
msgstr "This ancient rite calls upon the forces of life and fertility. For the next few weeks, the peasant's harvest will be extraordinary good."
msgctxt "spellinfo"
msgid "concealing_aura"
msgstr "This spell will hide the whole equipment of a target unit from the looks of others."
msgctxt "describe"
msgid "lifepotion"
msgstr "The \"Water of Life\" allows living trees to be created from logs. A Knotroot and Elvendear are heated until one can just still keep one's finger in. This is then poured into a jar and allowed to cool slowly. The extract is sufficient for 10 pieces of wood."

View file

@ -327,10 +327,6 @@ msgctxt "spell"
msgid "clone"
msgstr "Seelenkopie"
msgctxt "spellinfo"
msgid "concealing_aura"
msgstr "Dieser Zauber wird die gesamte Ausrüstung der Zieleinheit für einige Zeit vor den Blicken anderer verschleiern."
msgctxt "shipinfo"
msgid "balloon"
msgstr "Der Sumpfgasballon besteht aus einem großen Weidenkorb, welcher Platz für maximal 5 Personen oder 500 Gewichtseinheiten bietet, und einer großen, mit Sumpfgas gefüllten Wyrmblase. Bei guten Winden kann sich der Ballon zwei Regionen pro Woche fortbewegen. Das Führen eines Ballons ist nicht einfach, und der Kapitän muss mindestens ein Segeltalent von 6 besitzen. Diese neue Entwicklung auf Eressea wird ausschließlich für den Xontormia-Expreß hergestellt und die Baupläne sind streng geheim. So ist es auch bisher noch niemandem gelungen, ein Exemplar nachzubauen."
@ -908,10 +904,6 @@ msgctxt "spellinfo"
msgid "disturbingdreams"
msgstr "Dieser Zauber führt in der betroffenen Region für einige Wochen zu Schlaflosigkeit und Unruhe. Den Betroffenen fällt das Lernen deutlich schwerer."
msgctxt "spellinfo"
msgid "raindance"
msgstr "Dieses uralte Tanzritual ruft die Kräfte des Lebens und der Fruchtbarkeit. Die Erträge der Bauern werden für einige Wochen deutlich besser ausfallen."
msgid "wdw_pyramid"
msgstr "Pyramide"
@ -1459,10 +1451,6 @@ msgctxt "race"
msgid "goblin_x"
msgstr "Goblin"
msgctxt "spellinfo"
msgid "earn_silver#gwyrrd"
msgstr "Die Fähigkeiten der Gwyrrd-Magier in der Viehzucht und Heilung sind bei den Bauern sehr begehrt. Gerade auf Märkten sind ihre Dienste häufig sehr gefragt. Manch einer mag auch sein Talent dazu nutzen, ein Tier für einen besseren Preis zu verkaufen. Pro Stufe kann der Magier so 50 Silber verdienen."
msgctxt "spell"
msgid "raindance"
msgstr "Regentanz"
@ -1494,10 +1482,6 @@ msgstr "Mallorn"
msgid "mallorn_p"
msgstr "Mallorn"
msgctxt "describe"
msgid "lifepotion"
msgstr "Das 'Wasser des Lebens' ist in der Lage, aus gefällten Baumstämmen wieder lebende Bäume zu machen. Dazu wird ein knotiger Saugwurz zusammen mit einem Elfenlieb erwärmt, so dass man gerade noch den Finger reinhalten kann. Dies gieße man in ein Gefäß und lasse es langsam abkühlen. Der Extrakt reicht für 10 Holzstämme."
msgctxt "spell"
msgid "homestone"
msgstr "Heimstein"
@ -1740,10 +1724,6 @@ msgstr "Beschwörung eines Wasserelementares"
msgid "GEBAEUDE"
msgstr "GEBÄUDE"
msgctxt "spellinfo"
msgid "blessedharvest"
msgstr "Dieses Ernteritual verbessert die Erträge der arbeitenden Bauern in der Region um ein Silberstück. Je mehr Kraft der Druide investiert, desto länger wirkt der Zauber."
msgid "KRAEUTER"
msgstr "KRÄUTER"
@ -3147,10 +3127,6 @@ msgctxt "spellinfo"
msgid "create_focus"
msgstr "Erzeugt einen Aurafokus."
msgctxt "spellinfo"
msgid "earn_silver#draig"
msgstr "In den dunkleren Gassen gibt es sie, die Flüche und Verhexungen auf Bestellung. Aber auch Gegenzauber hat der Jünger des Draigs natürlich im Angebot. Ob nun der Sohn des Nachbarn in einen Liebesbann gezogen werden soll oder die Nebenbuhlerin Pickel und Warzen bekommen soll, niemand gibt gerne zu, zu solchen Mitteln gegriffen zu haben. Für diese Dienstleistung streicht der Magier 50 Silber pro Stufe ein."
msgctxt "spell"
msgid "song_of_slavery"
msgstr "Gesang der Versklavung"
@ -4910,10 +4886,6 @@ msgstr "Elixier der Macht"
msgid "wand_p"
msgstr "Zauberstäbe"
msgctxt "spellinfo"
msgid "earn_silver#cerddor"
msgstr "Cerddormagier sind _die_ Gaukler unter den Magiern, sie lieben es das Volk zu unterhalten und im Mittelpunkt zu stehen. Schon Anfänger lernen die kleinen Kunststücke und magischen Tricks, mit denen man das Volk locken und verführen kann, den Geldbeutel ganz weit zu öffnen, und am Ende der Woche wird der Gaukler 50 Silber pro Stufe verdient haben."
msgctxt "spell"
msgid "strength"
msgstr "Unbekannter Effekt"
@ -4996,10 +4968,6 @@ msgstr "Myrrhe"
msgid "skeleton_prefix_9"
msgstr "Dunkle"
msgctxt "spellinfo"
msgid "earn_silver#illaun"
msgstr "Niemand kann so gut die Träume deuten wie ein Magier des Illaun. Auch die Kunst der Wahrsagerei, des Kartenlegens und des Handlesens sind ihm geläufig. Dafür zahlen ihm die Bauern 50 Silber pro Stufe."
msgctxt "spell"
msgid "big_recruit"
msgstr "Hohe Kunst der Überzeugung"
@ -5913,10 +5881,6 @@ msgctxt "spell"
msgid "cerddorfumbleshield"
msgstr "Bannlied"
msgctxt "spellinfo"
msgid "earn_silver#tybied"
msgstr "Wenn einem der Alchemist nicht weiterhelfen kann, geht man zu dem gelehrten Tybiedmagier. Seine Tränke und Tinkturen helfen gegen alles, was man sonst nicht bekommen kann. Ob nun die kryptische Formel unter dem Holzschuh des untreuen Ehemannes wirklich geholfen hat - nun, der des Lesens nicht mächtige Bauer wird es nie wissen. Dem Magier hilft es auf jeden Fall... beim Füllen seines Geldbeutels. 50 Silber pro Stufe lassen sich so in einer Woche verdienen."
msgid "ANZAHL"
msgstr "ANZAHL"

View file

@ -273,10 +273,6 @@ msgctxt "spell"
msgid "clone"
msgstr "Doppelganger"
msgctxt "spellinfo"
msgid "concealing_aura"
msgstr "This spell will hide the whole equipment of a target unit from the looks of others."
msgctxt "spell"
msgid "bloodsacrifice"
msgstr "Lesser Sacrifice"
@ -695,10 +691,6 @@ msgctxt "spellinfo"
msgid "disturbingdreams"
msgstr "This spell causes insomnia and restlessness in a whole region for several weeks. All affected persons will learn much slower than normal."
msgctxt "spellinfo"
msgid "raindance"
msgstr "This ancient rite calls upon the forces of life and fertility. For the next few weeks, the peasant's harvest will be extraordinary good."
msgid "wdw_pyramid"
msgstr "pyramid"
@ -1221,10 +1213,6 @@ msgctxt "race"
msgid "goblin_x"
msgstr "goblin"
msgctxt "spellinfo"
msgid "earn_silver#gwyrrd"
msgstr "The abilities of the mages of Gwyrrd concerning the breeding and healing of cattle are highly appreciated among the peasants. Especially at the markets, their services are demanded frequently. Some of them also use their talents to sell an animal at a higher price. A magician can earn 50 silver pieces per level in this way."
msgctxt "spell"
msgid "raindance"
msgstr "Rain Dance"
@ -1252,10 +1240,6 @@ msgstr "mallorn"
msgid "mallorn_p"
msgstr "mallorn"
msgctxt "describe"
msgid "lifepotion"
msgstr "The \"Water of Life\" allows living trees to be created from logs. A Knotroot and Elvendear are heated until one can just still keep one's finger in. This is then poured into a jar and allowed to cool slowly. The extract is sufficient for 10 pieces of wood."
msgid "thickfog_trail"
msgstr "%s"
@ -1490,10 +1474,6 @@ msgctxt "spell"
msgid "goodwinds"
msgstr "Summon Water Elemental"
msgctxt "spellinfo"
msgid "blessedharvest"
msgstr "This ritual increases the output of the local farms. Peasants in the region produce an extra silverpiece. The stronger the druid's spell is, the longer the effect will last."
msgid "KRAEUTER"
msgstr "HERBS"
@ -2732,10 +2712,6 @@ msgctxt "spellinfo"
msgid "create_focus"
msgstr "Creates an aurafocus crystal."
msgctxt "spellinfo"
msgid "earn_silver#draig"
msgstr "In the dark alleys you can find those who sell curses and hexes on demand - but you can buy the apropriate counterspells from the followers of Draig as well. May it be a love spell for the son of a neighbour or a wart in the face of a rival. For offering these services, the sorcerer charges 50 silver pieces per level."
msgctxt "spell"
msgid "song_of_slavery"
msgstr "Song of Slavery"
@ -4370,10 +4346,6 @@ msgstr "elixir of power"
msgid "wand_p"
msgstr "wands"
msgctxt "spellinfo"
msgid "earn_silver#cerddor"
msgstr "The mages of Cerddor truly are the bards of the wizards; they love to use their sorcery to entertain the crowds and to be the center of attention. Even the apprentices study those little magic tricks, which attract and fascinate the people and thus ensnare them into leaving a few coins or more for the artist. By the end of the week, the bard will have earned 50 silver per level."
msgctxt "spell"
msgid "strength"
msgstr "Unknown Effect"
@ -4426,10 +4398,6 @@ msgstr "trees"
msgid "myrrh_p"
msgstr "myrrh"
msgctxt "spellinfo"
msgid "earn_silver#illaun"
msgstr "No one can read dreams as well as the mages of Illaun. Furthermore, they are also familiar with all other common means of foretelling the future like crystal balls, tarot cards or palms. A mentalist can earn 50 silver pieces per level and week for offering these services to peasants."
msgctxt "spell"
msgid "big_recruit"
msgstr "High art of persuasion"
@ -5222,10 +5190,6 @@ msgctxt "spell"
msgid "cerddorfumbleshield"
msgstr "Countersong"
msgctxt "spellinfo"
msgid "earn_silver#tybied"
msgstr "If the local alchemist could not help you, you should visit a scholar of Tybied. His potions and tinctures may help when nothing else does. If the cryptic formula under the wooden shoes of the unfaithful husband really helped? - well, the peasant, who isn't capable of reading, will never know. At least it helped the magician... to fill his purse. In one week he can earn 50 silver per level that way."
msgctxt "keyword"
msgid "teach"
msgstr "TEACH"

View file

@ -93,7 +93,7 @@ email=$(grep "faction=$1:" reports.txt | cut -d: -f2 | sed 's/email=//')
echo "sending reports to $1 / $email"
info=/dev/null
[ -e ../email.txt ] && info=../email.txt
cat $info | mutt -F $ERESSEA/etc/muttrc -s "Testauswertung Spiel $game Partei $1" -a $zip -- $email
cat $info | mutt -s "Testauswertung Spiel $game Partei $1" -a $zip -- $email
}
game=0

View file

@ -2,7 +2,6 @@
local self = {}
local function equip_first(u)
equip_newunits(u)
name = 'seed_' .. u.race
equip_unit(u, name, 255)
end

View file

@ -99,8 +99,6 @@ function self.update()
r:set_resource("tree", trees * 1.1)
msg:send_region(r)
end
if clear then
end
end
end
else

View file

@ -338,45 +338,6 @@ function test_message()
return msg
end
function test_events()
local fail = 1
local function msg_handler(u, evt)
str = evt:get(0)
u2 = evt:get(1)
assert(u2~=nil)
assert(str=="Du Elf stinken")
message_unit(u, u2, "thanks unit, i got your message: " .. str)
message_faction(u, u2.faction, "thanks faction, i got your message: " .. str)
message_region(u, "thanks region, i got your message: " .. str)
fail = 0
end
plain = region.create(0, 0, "plain")
skill = 8
f = create_faction('elf')
f.age = 20
u = unit.create(f, plain)
u.number = 1
u:add_item("money", u.number*100)
u:clear_orders()
u:add_order("NUMMER PARTEI test")
u:add_handler("message", msg_handler)
msg = "BOTSCHAFT EINHEIT " .. itoa36(u.id) .. " Du~Elf~stinken"
f = create_faction('elf')
f.age = 20
u = unit.create(f, plain)
u.number = 1
u:add_item("money", u.number*100)
u:clear_orders()
u:add_order("NUMMER PARTEI eviL")
u:add_order(msg)
process_orders()
assert(fail==0)
end
function test_renumber_ship()
local r = region.create(0, 0, "plain")
local f = create_faction('human')

View file

@ -30,6 +30,26 @@ function test_first_troll()
assert_equal(2, u:eff_skill('perception'))
end
function test_first_human()
local f = faction.create('human')
local r = region.create(0, 0, "plain")
local u = unit.create(f, r, 1)
u:equip('first_unit')
assert_not_nil(u.building)
assert_equal('castle', u.building.type)
assert_equal(10, u.building.size)
end
function test_first_aquarian()
local f = faction.create('aquarian')
local r = region.create(0, 0, "plain")
local u = unit.create(f, r, 1)
u:equip('first_unit')
assert_not_nil(u.ship)
assert_equal('boat', u.ship.type)
assert_equal(1, u:get_skill('sailing'))
end
function test_seed_unit()
local r = region.create(0, 0, "plain")
local f = faction.create('human')
@ -53,3 +73,4 @@ function test_seed_elf()
assert_equal('castle', u.building.type)
assert_equal(10, u.building.size)
end

View file

@ -517,3 +517,16 @@ function test_buy_sell()
assert_equal(4, u:get_item(item))
assert_not_equal(0, u:get_item('money'))
end
function test_seaserpent_attack()
local r = region.create(0, 0, 'ocean')
local sh = ship.create(r, 'boat')
local us = unit.create(get_monsters(), r, 1, 'seaserpent')
local u = unit.create(faction.create('human', 'enno@example.com'), r, 20, 'human')
u.ship = sh
us:clear_orders()
us:add_order('ATTACKIERE ' .. itoa36(u.id))
us:set_skill('unarmed', 10)
process_orders()
write_reports()
end

View file

@ -93,11 +93,11 @@ end
function test_lighthouse()
eressea.free_game()
local r = region.create(0, 0, "mountain")
local f = faction.create("human", "noreply@eressea.de", "de")
local f = faction.create("human", "human@example.com")
region.create(1, 0, "mountain")
region.create(2, 0, "ocean")
region.create(0, 1, "firewall")
region.create(3, 0, "mountain")
region.create(3, 0, "ocean")
region.create(4, 0, "plain")
local u = unit.create(f, r, 1)
local b = building.create(r, "lighthouse")
@ -110,7 +110,7 @@ function test_lighthouse()
init_reports()
write_report(f)
assert_true(find_in_report(f, " %(1,0%) %(vom Turm erblickt%)"))
assert_false(find_in_report(f, " %(1,0%) %(vom Turm erblickt%)"))
assert_true(find_in_report(f, " %(2,0%) %(vom Turm erblickt%)"))
assert_true(find_in_report(f, " %(3,0%) %(vom Turm erblickt%)"))

BIN
src/.DS_Store vendored Normal file

Binary file not shown.

View file

@ -86,6 +86,7 @@ ENDIF()
set (ERESSEA_SRC
vortex.c
automate.c
move.c
piracy.c
spells.c
@ -187,6 +188,7 @@ set(TESTS_SRC
tests.c
academy.test.c
alchemy.test.c
automate.test.c
battle.test.c
creport.test.c
direction.test.c

View file

@ -33,13 +33,13 @@ void academy_teaching_bonus(struct unit *u, skill_t sk, int students) {
}
}
bool academy_can_teach(unit *teacher, unit *student, skill_t sk) {
bool academy_can_teach(unit *teacher, unit *scholar, skill_t sk) {
const struct building_type *btype = bt_find("academy");
if (active_building(teacher, btype) && active_building(student, btype)) {
int j = study_cost(student, sk) * 2;
if (active_building(teacher, btype) && active_building(scholar, btype)) {
int j = study_cost(scholar, sk) * 2;
if (j < 50) j = 50;
/* kann Einheit das zahlen? */
return get_pooled(student, get_resourcetype(R_SILVER), GET_DEFAULT, j) >= j;
return get_pooled(scholar, get_resourcetype(R_SILVER), GET_DEFAULT, j) >= j;
/* sonst nehmen sie nicht am Unterricht teil */
}
return false;

View file

@ -9,7 +9,7 @@ extern "C" {
struct unit;
void academy_teaching_bonus(struct unit *u, skill_t sk, int academy);
bool academy_can_teach(struct unit *teacher, struct unit *student, skill_t sk);
bool academy_can_teach(struct unit *teacher, struct unit *scholar, skill_t sk);
#ifdef __cplusplus
}
#endif

View file

@ -209,6 +209,7 @@ void register_attributes(void)
at_deprecate("maxmagicians", a_readint); /* factions with differnt magician limits, probably unused */
at_deprecate("hurting", a_readint); /* an old arena attribute */
at_deprecate("chaoscount", a_readint); /* used to increase the chance of monster spawns */
at_deprecate("xontormiaexpress", a_readint); /* required for old datafiles */
at_deprecate("orcification", a_readint); /* required for old datafiles */
at_deprecate("lua", read_ext); /* required for old datafiles */

161
src/automate.c Normal file
View file

@ -0,0 +1,161 @@
#include <platform.h>
#include "kernel/faction.h"
#include "kernel/messages.h"
#include "kernel/order.h"
#include "kernel/region.h"
#include "kernel/unit.h"
#include "util/log.h"
#include "automate.h"
#include "keyword.h"
#include "laws.h"
#include "study.h"
#include <stdlib.h>
#include <assert.h>
static int cmp_scholars(const void *lhs, const void *rhs)
{
const scholar *a = (const scholar *)lhs;
const scholar *b = (const scholar *)rhs;
if (a->sk == b->sk) {
/* sort by level, descending: */
return b->level - a->level;
}
/* order by skill */
return (int)a->sk - (int)b->sk;
}
int autostudy_init(scholar scholars[], int max_scholars, region *r)
{
unit *u;
int nscholars = 0;
for (u = r->units; u; u = u->next) {
keyword_t kwd = getkeyword(u->thisorder);
if (kwd == K_AUTOSTUDY) {
if (long_order_allowed(u) && unit_can_study(u)) {
scholar * st = scholars + nscholars;
if (++nscholars == max_scholars) {
log_fatal("you must increase MAXSCHOLARS");
}
st->u = u;
init_order(u->thisorder, u->faction->locale);
st->sk = getskill(u->faction->locale);
st->level = effskill_study(u, st->sk);
st->learn = 0;
}
else {
ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "error_race_nolearn", "race",
u_race(u)));
}
}
}
if (nscholars > 0) {
qsort(scholars, nscholars, sizeof(scholar), cmp_scholars);
}
return nscholars;
}
static void teaching(scholar *s, int n) {
assert(n <= s->u->number);
s->learn += n;
s->u->flags |= UFL_LONGACTION;
}
static void learning(scholar *s, int n) {
assert(n <= s->u->number);
s->learn += n;
s->u->flags |= UFL_LONGACTION;
}
void autostudy_run(scholar scholars[], int nscholars)
{
int ti = 0;
while (ti != nscholars) {
skill_t sk = scholars[ti].sk;
int t, s, se, ts = 0, tt = 0, si = ti;
for (se = ti; se != nscholars && scholars[se].sk == sk; ++se) {
int mint;
ts += scholars[se].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;
}
}
/* now si splits the teachers and students 1:10 */
/* first student must be 2 levels below first teacher: */
for (; si != se && scholars[ti].level - TEACHDIFFERENCE > scholars[si].level; ++si) {
tt += scholars[si].u->number;
}
if (si == se) {
/* there are no students, so standard learning only */
for (t = ti; t != se; ++t) {
learning(scholars + t, scholars[t].u->number);
}
}
else {
/* 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 n = scholars[si].u->number;
for (t = ti, s = si; t != si && s != se; ) {
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;
}
n = scholars[s].u->number;
}
else {
/* s gets partial credit and we need a new teacher */
teaching(scholars + s, i);
/* we are done with this teacher. any remaining people are regular learners: */
if (scholars[t].u->number > 1) {
/* remain = number - ceil(taught/10); */
int remain = (STUDENTS_PER_TEACHER * scholars[t].u->number - i + STUDENTS_PER_TEACHER - 1) / STUDENTS_PER_TEACHER;
learning(scholars + t, remain);
}
/* we want a new teacher for s. if any exists, it's next in the sequence. */
if (++t == si) {
continue;
}
if (scholars[t].level - TEACHDIFFERENCE < scholars[s].level) {
/* next teacher cannot teach, we must skip students. */
do {
learning(scholars + s, (n - i));
i = 0;
if (++s == se) {
continue;
}
n = scholars[s].u->number;
} while (scholars[t].level - TEACHDIFFERENCE < scholars[s].level);
}
i = scholars[t].u->number * STUDENTS_PER_TEACHER;
}
}
}
ti = se;
}
}
#define MAXSCHOLARS 128
void do_autostudy(region *r)
{
scholar scholars[MAXSCHOLARS];
int i, nscholars = autostudy_init(scholars, MAXSCHOLARS, r);
autostudy_run(scholars, nscholars);
for (i = 0; i != nscholars; ++i) {
int days = STUDYDAYS * scholars[i].learn;
learn_skill(scholars[i].u, scholars[i].sk, days);
}
}

43
src/automate.h Normal file
View file

@ -0,0 +1,43 @@
/*
Copyright (c) 1998-2018, Enno Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/
#pragma once
#ifndef H_GC_AUTOMATE
#define H_GC_AUTOMATE
#include "skill.h"
struct region;
struct unit;
typedef struct scholar {
struct unit *u;
skill_t sk;
int level;
int learn;
} scholar;
#define STUDENTS_PER_TEACHER 10
void do_autostudy(struct region *r);
int autostudy_init(scholar scholars[], int max_scholars, struct region *r);
void autostudy_run(scholar scholars[], int nscholars);
#endif

114
src/automate.test.c Normal file
View file

@ -0,0 +1,114 @@
#ifdef _MSC_VER
#include <platform.h>
#endif
#include "automate.h"
#include "kernel/faction.h"
#include "kernel/order.h"
#include "kernel/region.h"
#include "kernel/unit.h"
#include "tests.h"
#include <CuTest.h>
static void test_autostudy_init(CuTest *tc) {
scholar scholars[4];
unit *u1, *u2, *u3;
faction *f;
region *r;
test_setup();
r = test_create_plain(0, 0);
f = test_create_faction(NULL);
u1 = test_create_unit(f, r);
u1->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
test_create_unit(f, r);
u2 = test_create_unit(f, r);
u2->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
set_level(u2, SK_ENTERTAINMENT, 2);
u3 = test_create_unit(f, r);
u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
scholars[3].u = NULL;
CuAssertIntEquals(tc, 3, autostudy_init(scholars, 4, r));
CuAssertPtrEquals(tc, u2, scholars[0].u);
CuAssertIntEquals(tc, 2, scholars[0].level);
CuAssertIntEquals(tc, 0, scholars[0].learn);
CuAssertIntEquals(tc, SK_ENTERTAINMENT, scholars[0].sk);
CuAssertPtrEquals(tc, u1, scholars[1].u);
CuAssertIntEquals(tc, 0, scholars[1].level);
CuAssertIntEquals(tc, 0, scholars[1].learn);
CuAssertIntEquals(tc, SK_ENTERTAINMENT, scholars[1].sk);
CuAssertPtrEquals(tc, u3, scholars[2].u);
CuAssertIntEquals(tc, 0, scholars[2].level);
CuAssertIntEquals(tc, 0, scholars[2].learn);
CuAssertIntEquals(tc, SK_PERCEPTION, scholars[2].sk);
CuAssertPtrEquals(tc, NULL, scholars[3].u);
test_teardown();
}
static void test_autostudy_run(CuTest *tc) {
scholar scholars[4];
unit *u1, *u2, *u3;
faction *f;
region *r;
test_setup();
r = test_create_plain(0, 0);
f = test_create_faction(NULL);
u1 = test_create_unit(f, r);
u1->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
set_number(u1, 2);
set_level(u1, SK_ENTERTAINMENT, 2);
u2 = test_create_unit(f, r);
u2->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
set_number(u2, 10);
u3 = test_create_unit(f, r);
u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
set_number(u3, 15);
scholars[3].u = NULL;
CuAssertIntEquals(tc, 3, autostudy_init(scholars, 4, r));
autostudy_run(scholars, 3);
CuAssertIntEquals(tc, 0, scholars[0].learn);
CuAssertIntEquals(tc, 20, scholars[1].learn);
CuAssertIntEquals(tc, 15, scholars[2].learn);
test_teardown();
}
static void test_autostudy_run_noteachers(CuTest *tc) {
scholar scholars[4];
unit *u1, *u2, *u3;
faction *f;
region *r;
test_setup();
r = test_create_plain(0, 0);
f = test_create_faction(NULL);
u1 = test_create_unit(f, r);
u1->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_LUMBERJACK]);
set_number(u1, 2);
set_level(u1, SK_ENTERTAINMENT, 2);
u2 = test_create_unit(f, r);
u2->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
set_number(u2, 10);
u3 = test_create_unit(f, r);
u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
set_number(u3, 15);
scholars[3].u = NULL;
CuAssertIntEquals(tc, 3, autostudy_init(scholars, 4, r));
autostudy_run(scholars, 3);
CuAssertIntEquals(tc, 2, scholars[0].learn);
CuAssertIntEquals(tc, 10, scholars[1].learn);
CuAssertIntEquals(tc, 15, scholars[2].learn);
test_teardown();
}
CuSuite *get_automate_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_autostudy_init);
SUITE_ADD_TEST(suite, test_autostudy_run);
SUITE_ADD_TEST(suite, test_autostudy_run_noteachers);
return suite;
}

View file

@ -20,13 +20,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include "battle.h"
#include "alchemy.h"
#include "chaos.h"
#include "guard.h"
#include "laws.h"
#include "monsters.h"
#include "move.h"
#include "skill.h"
#include "study.h"
#include "spy.h"
#include <spells/buildingcurse.h>
#include <spells/regioncurse.h>
@ -2531,7 +2531,6 @@ static void battle_effects(battle * b, int dead_players)
}
if (dead_peasants) {
deathcounts(r, dead_peasants + dead_players);
add_chaoscount(r, dead_peasants / 2);
rsetpeasants(r, rp - dead_peasants);
}
}
@ -2789,10 +2788,12 @@ static void aftermath(battle * b)
ship *sh = *sp;
freset(sh, SF_DAMAGED);
if (sh->damage >= sh->size * DAMAGE_SCALE) {
sink_ship(sh);
remove_ship(sp, sh);
}
if (*sp == sh)
else {
sp = &sh->next;
}
}
}
@ -3325,7 +3326,7 @@ fighter * get_fighter(battle * b, const struct unit * u)
return 0;
}
static int join_battle(battle * b, unit * u, bool attack, fighter ** cp)
int join_battle(battle * b, unit * u, bool attack, fighter ** cp)
{
side *s;
fighter *fc = NULL;

View file

@ -261,6 +261,7 @@ extern "C" {
void free_battle(struct battle * b);
struct fighter *make_fighter(struct battle *b, struct unit *u,
struct side * s, bool attack);
int join_battle(struct battle * b, struct unit * u, bool attack, struct fighter ** cp);
struct side *make_side(struct battle * b, const struct faction * f,
const struct group * g, unsigned int flags,
const struct faction * stealthfaction);

View file

@ -1,6 +1,8 @@
#include <platform.h>
#include "battle.h"
#include "reports.h"
#include "skill.h"
#include <kernel/config.h>
@ -16,6 +18,8 @@
#include <spells/buildingcurse.h>
#include <util/functions.h>
#include <util/language.h>
#include <util/message.h>
#include <util/rand.h>
#include <util/rng.h>
#include <util/strings.h>
@ -552,6 +556,103 @@ static void test_battle_skilldiff(CuTest *tc)
test_teardown();
}
static void test_battle_report_one(CuTest *tc)
{
battle * b = NULL;
region *r;
unit *u1, *u2;
message *m;
const char *expect;
fighter *fig;
test_setup();
mt_create_va(mt_new("start_battle", NULL), "factions:string", MT_NEW_END);
r = test_create_plain(0, 0);
u1 = test_create_unit(test_create_faction(NULL), r);
u2 = test_create_unit(test_create_faction(NULL), r);
b = make_battle(r);
join_battle(b, u1, true, &fig);
join_battle(b, u2, false, &fig);
faction_setname(u1->faction, "Monster");
expect = factionname(u1->faction);
report_battle_start(b);
CuAssertPtrNotNull(tc, m = test_find_messagetype(u1->faction->battles->msgs, "start_battle"));
CuAssertStrEquals(tc, expect, (const char *)m->parameters[0].v);
free_battle(b);
test_teardown();
}
static void test_battle_report_two(CuTest *tc)
{
battle * b = NULL;
region *r;
unit *u1, *u2;
message *m;
char expect[64];
fighter *fig;
struct locale *lang;
test_setup();
lang = test_create_locale();
locale_setstring(lang, "and", "and");
mt_create_va(mt_new("start_battle", NULL), "factions:string", MT_NEW_END);
r = test_create_plain(0, 0);
u1 = test_create_unit(test_create_faction(NULL), r);
u1->faction->locale = lang;
u2 = test_create_unit(test_create_faction(NULL), r);
u2->faction->locale = lang;
str_slprintf(expect, sizeof(expect), "%s and %s", factionname(u1->faction), factionname(u2->faction));
b = make_battle(r);
join_battle(b, u1, true, &fig);
join_battle(b, u2, true, &fig);
report_battle_start(b);
CuAssertPtrNotNull(tc, m = test_find_messagetype(u1->faction->battles->msgs, "start_battle"));
CuAssertStrEquals(tc, expect, (const char *)m->parameters[0].v);
free_battle(b);
test_teardown();
}
static void test_battle_report_three(CuTest *tc)
{
battle * b = NULL;
region *r;
unit *u1, *u2, *u3;
message *m;
char expect[64];
fighter *fig;
struct locale *lang;
test_setup();
lang = test_create_locale();
locale_setstring(lang, "and", "and");
mt_create_va(mt_new("start_battle", NULL), "factions:string", MT_NEW_END);
r = test_create_plain(0, 0);
u1 = test_create_unit(test_create_faction(NULL), r);
u1->faction->locale = lang;
u2 = test_create_unit(test_create_faction(NULL), r);
u2->faction->locale = lang;
u3 = test_create_unit(test_create_faction(NULL), r);
u3->faction->locale = lang;
str_slprintf(expect, sizeof(expect), "%s, %s and %s", factionname(u1->faction), factionname(u2->faction), factionname(u3->faction));
b = make_battle(r);
join_battle(b, u1, true, &fig);
join_battle(b, u2, true, &fig);
join_battle(b, u3, true, &fig);
report_battle_start(b);
CuAssertPtrNotNull(tc, m = test_find_messagetype(u1->faction->battles->msgs, "start_battle"));
CuAssertStrEquals(tc, expect, (const char *)m->parameters[0].v);
free_battle(b);
test_teardown();
}
static void test_battle_skilldiff_building(CuTest *tc)
{
troop ta, td;
@ -690,6 +791,9 @@ CuSuite *get_battle_suite(void)
SUITE_ADD_TEST(suite, test_select_armor);
SUITE_ADD_TEST(suite, test_battle_skilldiff);
SUITE_ADD_TEST(suite, test_battle_skilldiff_building);
SUITE_ADD_TEST(suite, test_battle_report_one);
SUITE_ADD_TEST(suite, test_battle_report_two);
SUITE_ADD_TEST(suite, test_battle_report_three);
SUITE_ADD_TEST(suite, test_defenders_get_building_bonus);
SUITE_ADD_TEST(suite, test_attackers_get_no_building_bonus);
SUITE_ADD_TEST(suite, test_building_bonus_respects_size);

View file

@ -7,7 +7,6 @@
#include "bind_ship.h"
#include "bind_building.h"
#include "chaos.h"
#include "teleport.h"
#include <kernel/calendar.h>
@ -356,7 +355,7 @@ static int tolua_region_get_resourcelevel(lua_State * L)
#define LUA_ASSERT(c, s) if (!(c)) { log_error("%s(%d): %s\n", __FILE__, __LINE__, (s)); return 0; }
static int special_resource(const char *type) {
const char * special[] = { "seed", "sapling", "tree", "grave", "chaos", 0 };
const char * special[] = { "seed", "sapling", "tree", "grave", NULL };
int i;
for (i = 0; special[i]; ++i) {
@ -389,9 +388,6 @@ static int tolua_region_get_resource(lua_State * L)
case 3:
result = deathcount(r);
break;
case 4:
result = get_chaoscount(r);
break;
default:
rtype = rt_find(type);
if (rtype) {
@ -423,9 +419,6 @@ static int tolua_region_set_resource(lua_State * L)
case 3:
deathcounts(r, value - deathcount(r));
break;
case 4:
add_chaoscount(r, value - get_chaoscount(r));
break;
default:
rtype = rt_find(type);
if (rtype != NULL) {

View file

@ -455,48 +455,6 @@ int fctr_handle(struct trigger *tp, void *data)
return 0;
}
static void fctr_init(trigger * t)
{
t->data.v = calloc(sizeof(fctr_data), 1);
}
static void fctr_done(trigger * t)
{
fctr_data *fd = (fctr_data *)t->data.v;
lua_State *L = (lua_State *)global.vm_state;
luaL_unref(L, LUA_REGISTRYINDEX, fd->fhandle);
free(fd);
}
static struct trigger_type tt_lua = {
"lua_event",
fctr_init,
fctr_done,
fctr_handle
};
static trigger *trigger_lua(struct unit *u, int handle)
{
trigger *t = t_new(&tt_lua);
fctr_data *td = (fctr_data *)t->data.v;
td->target = u;
td->fhandle = handle;
return t;
}
static int tolua_unit_addhandler(lua_State * L)
{
unit *self = (unit *)tolua_tousertype(L, 1, 0);
const char *ename = tolua_tostring(L, 2, 0);
int handle;
lua_pushvalue(L, 3);
handle = luaL_ref(L, LUA_REGISTRYINDEX);
add_trigger(&self->attribs, ename, trigger_lua(self, handle));
return 0;
}
static int tolua_unit_addnotice(lua_State * L)
{
unit *self = (unit *)tolua_tousertype(L, 1, 0);
@ -909,8 +867,8 @@ static int tolua_unit_create(lua_State * L)
faction *f = (faction *)tolua_tousertype(L, 1, 0);
region *r = (region *)tolua_tousertype(L, 2, 0);
unit *u;
const char *rcname = tolua_tostring(L, 4, NULL);
int num = (int)tolua_tonumber(L, 3, 1);
const char *rcname = tolua_tostring(L, 4, NULL);
const race *rc;
assert(f && r);
@ -1046,9 +1004,6 @@ void tolua_unit_open(lua_State * L)
tolua_function(L, TOLUA_CAST "add_notice", tolua_unit_addnotice);
/* npc logic: */
tolua_function(L, TOLUA_CAST "add_handler", tolua_unit_addhandler);
tolua_variable(L, TOLUA_CAST "race_name", tolua_unit_get_racename,
tolua_unit_set_racename);
tolua_function(L, TOLUA_CAST "add_spell", tolua_unit_addspell);

View file

@ -21,6 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "chaos.h"
#include "monsters.h"
#include "move.h"
#include "spy.h"
#include <kernel/building.h>
#include <kernel/faction.h>
@ -39,57 +40,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <stdlib.h>
#include <assert.h>
/*********************/
/* at_chaoscount */
/*********************/
attrib_type at_chaoscount = {
"chaoscount",
DEFAULT_INIT,
DEFAULT_FINALIZE,
DEFAULT_AGE,
a_writeint,
a_readint,
NULL,
ATF_UNIQUE
};
void set_chaoscount(struct region *r, int deaths)
{
if (deaths==0) {
a_removeall(&r->attribs, &at_chaoscount);
} else {
attrib *a = a_find(r->attribs, &at_chaoscount);
if (!a) {
a = a_add(&r->attribs, a_new(&at_chaoscount));
}
a->data.i = deaths;
}
}
int get_chaoscount(const region * r)
{
attrib *a = a_find(r->attribs, &at_chaoscount);
if (!a)
return 0;
return a->data.i;
}
void add_chaoscount(region * r, int fallen)
{
attrib *a;
if (fallen == 0)
return;
a = a_find(r->attribs, &at_chaoscount);
if (!a)
a = a_add(&r->attribs, a_new(&at_chaoscount));
a->data.i += fallen;
if (a->data.i <= 0)
a_remove(&r->attribs, a);
}
static const terrain_type *chaosterrain(void)
{
static const terrain_type **types;
@ -195,19 +145,20 @@ static void chaos(region * r)
break;
}
if (dir != MAXDIRECTIONS) {
ship *sh = r->ships;
ship **slist = &r->ships;
unit **up;
while (sh) {
ship *nsh = sh->next;
double dmg =
config_get_flt("rules.ship.damage.atlantis",
0.50);
damage_ship(sh, dmg);
while (*slist) {
ship *sh = *slist;
damage_ship(sh, 0.5);
if (sh->damage >= sh->size * DAMAGE_SCALE) {
remove_ship(&sh->region->ships, sh);
sink_ship(sh);
remove_ship(slist, sh);
}
else {
slist = &sh->next;
}
sh = nsh;
}
for (up = &r->units; *up;) {
@ -248,18 +199,8 @@ void chaos_update(void) {
region *r;
/* Chaos */
for (r = regions; r; r = r->next) {
int i;
if ((r->flags & RF_CHAOTIC)) {
chaos(r);
}
i = get_chaoscount(r);
if (i) {
add_chaoscount(r, -(int)(i * ((double)(rng_int() % 10)) / 100.0));
}
}
}
void chaos_register(void) {
at_register(&at_chaoscount);
}

View file

@ -22,17 +22,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" {
#endif
struct region;
extern struct attrib_type at_chaoscount;
void chaos_register(void);
void chaos_update(void);
void set_chaoscount(struct region *r, int deaths);
int get_chaoscount(const struct region * r);
void add_chaoscount(struct region * r, int deaths);
#ifdef __cplusplus
}
#endif

View file

@ -426,6 +426,59 @@ static int recruit_cost(const faction * f, const race * rc)
return -1;
}
message *can_recruit(unit *u, const race *rc, order *ord, int now)
{
region *r = u->region;
/* this is a very special case because the recruiting unit may be empty
* at this point and we have to look at the creating unit instead. This
* is done in cansee, which is called indirectly by is_guarded(). */
if (is_guarded(r, u)) {
return msg_error(u, ord, 70);
}
if (rc == get_race(RC_INSECT)) {
gamedate date;
get_gamedate(now, &date);
if (date.season == SEASON_WINTER && r->terrain != newterrain(T_DESERT)) {
bool usepotion = false;
unit *u2;
for (u2 = r->units; u2; u2 = u2->next) {
if (fval(u2, UFL_WARMTH)) {
usepotion = true;
break;
}
}
if (!usepotion) {
return msg_error(u, ord, 98);
}
}
/* in Gletschern, Eisbergen gar nicht rekrutieren */
if (r_insectstalled(r)) {
return msg_error(u, ord, 97);
}
}
if (is_cursed(r->attribs, &ct_riotzone)) {
/* Die Region befindet sich in Aufruhr */
return msg_error(u, ord, 237);
}
if (rc && !playerrace(rc)) {
return msg_error(u, ord, 139);
}
if (fval(u, UFL_HERO)) {
return msg_feedback(u, ord, "error_herorecruit", "");
}
if (has_skill(u, SK_MAGIC)) {
/* error158;de;{unit} in {region}: '{command}' - Magier arbeiten
* grunds<EFBFBD>tzlich nur alleine! */
return msg_error(u, ord, 158);
}
return NULL;
}
static void recruit(unit * u, struct order *ord, econ_request ** recruitorders)
{
region *r = u->region;
@ -434,6 +487,7 @@ static void recruit(unit * u, struct order *ord, econ_request ** recruitorders)
const faction *f = u->faction;
const struct race *rc = u_race(u);
int n;
message *msg;
init_order_depr(ord);
n = getint();
@ -456,6 +510,7 @@ static void recruit(unit * u, struct order *ord, econ_request ** recruitorders)
}
}
}
if (recruitcost < 0) {
rc = u_race(u);
recruitcost = recruit_cost(f, rc);
@ -463,95 +518,46 @@ static void recruit(unit * u, struct order *ord, econ_request ** recruitorders)
recruitcost = INT_MAX;
}
}
assert(rc);
u_setrace(u, rc);
/* this is a very special case because the recruiting unit may be empty
* at this point and we have to look at the creating unit instead. This
* is done in cansee, which is called indirectly by is_guarded(). */
if (is_guarded(r, u)) {
cmistake(u, ord, 70, MSG_EVENT);
return;
}
if (rc == get_race(RC_INSECT)) {
gamedate date;
get_gamedate(turn, &date);
if (date.season == 0 && r->terrain != newterrain(T_DESERT)) {
bool usepotion = false;
unit *u2;
for (u2 = r->units; u2; u2 = u2->next)
if (fval(u2, UFL_WARMTH)) {
usepotion = true;
break;
}
if (!usepotion)
{
cmistake(u, ord, 98, MSG_EVENT);
return;
}
}
/* in Gletschern, Eisbergen gar nicht rekrutieren */
if (r_insectstalled(r)) {
cmistake(u, ord, 97, MSG_EVENT);
return;
}
}
if (is_cursed(r->attribs, &ct_riotzone)) {
/* Die Region befindet sich in Aufruhr */
cmistake(u, ord, 237, MSG_EVENT);
return;
}
if (recruitcost) {
if (recruitcost > 0) {
int pool;
plane *pl = getplane(r);
if (pl && fval(pl, PFL_NORECRUITS)) {
if (pl && (pl->flags & PFL_NORECRUITS)) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_pflnorecruit", ""));
return;
}
if (get_pooled(u, get_resourcetype(R_SILVER), GET_DEFAULT,
recruitcost) < recruitcost) {
pool = get_pooled(u, get_resourcetype(R_SILVER), GET_DEFAULT, recruitcost * n);
if (pool < recruitcost) {
cmistake(u, ord, 142, MSG_EVENT);
return;
}
pool /= recruitcost;
if (n > pool) n = pool;
}
if (!playerrace(rc)) {
cmistake(u, ord, 139, MSG_EVENT);
return;
}
if (fval(u, UFL_HERO)) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_herorecruit", ""));
return;
}
if (has_skill(u, SK_MAGIC)) {
/* error158;de;{unit} in {region}: '{command}' - Magier arbeiten
* grunds<EFBFBD>tzlich nur alleine! */
cmistake(u, ord, 158, MSG_EVENT);
return;
}
if (has_skill(u, SK_ALCHEMY)
&& count_skill(u->faction, SK_ALCHEMY) + n >
skill_limit(u->faction, SK_ALCHEMY)) {
cmistake(u, ord, 156, MSG_EVENT);
return;
}
if (recruitcost > 0) {
int pooled =
get_pooled(u, get_resourcetype(R_SILVER), GET_DEFAULT, recruitcost * n);
int pr = pooled / recruitcost;
if (n > pr) n = pr;
}
u->wants = n;
if (!n) {
cmistake(u, ord, 142, MSG_EVENT);
return;
}
if (has_skill(u, SK_ALCHEMY)) {
if (count_skill(u->faction, SK_ALCHEMY) + n > skill_limit(u->faction, SK_ALCHEMY)) {
cmistake(u, ord, 156, MSG_EVENT);
return;
}
}
assert(rc);
msg = can_recruit(u, rc, ord, turn);
if (msg) {
add_message(&u->faction->msgs, msg);
msg_release(msg);
return;
}
u_setrace(u, rc);
u->wants = n;
o = (econ_request *)calloc(1, sizeof(econ_request));
o->qty = n;
o->unit = u;

View file

@ -44,6 +44,7 @@ extern "C" {
#define MAXNEWBIES 5
struct unit;
struct race;
struct region;
struct faction;
struct order;
@ -94,6 +95,7 @@ extern "C" {
void steal_cmd(struct unit * u, struct order *ord, struct econ_request ** stealorders);
void expandstealing(struct region * r, struct econ_request * stealorders);
struct message *can_recruit(struct unit *u, const struct race *rc, struct order *ord, int now);
void add_recruits(struct unit * u, int number, int wanted);
#ifdef __cplusplus

View file

@ -480,6 +480,35 @@ static void test_recruit(CuTest *tc) {
test_teardown();
}
static void test_recruit_insect(CuTest *tc) {
unit *u;
faction *f;
message * msg;
test_setup();
test_create_calendar();
f = test_create_faction(test_create_race("insect"));
u = test_create_unit(f, test_create_region(0, 0, NULL));
u->thisorder = create_order(K_RECRUIT, f->locale, "%d", 1);
msg = can_recruit(u, f->race, u->thisorder, 1083); /* Autumn */
CuAssertPtrEquals(tc, NULL, msg);
msg = can_recruit(u, f->race, u->thisorder, 1084); /* Insects, Winter */
CuAssertPtrNotNull(tc, msg);
msg_release(msg);
u->flags |= UFL_WARMTH;
msg = can_recruit(u, f->race, u->thisorder, 1084); /* Insects, potion, Winter */
CuAssertPtrEquals(tc, NULL, msg);
u->flags = 0;
msg = can_recruit(u, NULL, u->thisorder, 1084); /* Other races, Winter */
CuAssertPtrEquals(tc, NULL, msg);
test_teardown();
}
static void test_income(CuTest *tc)
{
race *rc;
@ -764,6 +793,7 @@ CuSuite *get_economy_suite(void)
SUITE_ADD_TEST(suite, test_trade_insect);
SUITE_ADD_TEST(suite, test_maintain_buildings);
SUITE_ADD_TEST(suite, test_recruit);
SUITE_ADD_TEST(suite, test_recruit_insect);
SUITE_ADD_TEST(suite, test_loot);
SUITE_ADD_TEST(suite, test_expand_production);
return suite;

View file

@ -24,7 +24,6 @@
#include "attributes/attributes.h"
#include "races/races.h"
#include "chaos.h"
#include "items.h"
#include "creport.h"
#include "report.h"
@ -82,5 +81,4 @@ void game_init(void)
register_attributes();
register_gmcmd();
chaos_register();
}

File diff suppressed because it is too large Load diff

View file

@ -50,7 +50,6 @@
#include <util/unicode.h>
#include "gmtool_structs.h"
#include "chaos.h"
#include "console.h"
#include "listbox.h"
#include "wormhole.h"
@ -534,7 +533,6 @@ static void reset_region(region *r) {
unit **up = &r->units;
bool players = false;
set_chaoscount(r, 0);
r->flags = 0;
a_removeall(&r->attribs, NULL);
while (*up) {

View file

@ -895,7 +895,9 @@ build_building(unit * u, const building_type * btype, int id, int want, order *
}
fset(b, BLD_EXPANDED);
update_lighthouse(b);
if (is_lighthouse(btype)) {
update_lighthouse(b);
}
return built;
}

View file

@ -377,7 +377,9 @@ building *new_building(const struct building_type * btype, region * r,
bptr = &(*bptr)->next;
*bptr = b;
update_lighthouse(b);
if (is_lighthouse(b->type)) {
update_lighthouse(b);
}
bname = LOC(lang, btype->_name);
if (!bname) {
bname = LOC(lang, parameters[P_GEBAEUDE]);
@ -399,6 +401,7 @@ static building *deleted_buildings;
void remove_building(building ** blist, building * b)
{
unit *u;
region *r = b->region;
static const struct building_type *bt_caravan, *bt_dam, *bt_tunnel;
static int btypes;
@ -410,18 +413,19 @@ void remove_building(building ** blist, building * b)
bt_tunnel = bt_find("tunnel");
}
handle_event(b->attribs, "destroy", b);
for (u = b->region->units; u; u = u->next) {
for (u = r->units; u; u = u->next) {
if (u->building == b) leave(u, true);
}
if (is_lighthouse(b->type)) {
remove_lighthouse(b);
}
b->size = 0;
update_lighthouse(b);
bunhash(b);
/* Falls Karawanserei, Damm oder Tunnel einst<73>rzen, wird die schon
* gebaute Strasse zur Haelfte vernichtet */
if (b->type == bt_caravan || b->type == bt_dam || b->type == bt_tunnel) {
region *r = b->region;
int d;
for (d = 0; d != MAXDIRECTIONS; ++d) {
direction_t dir = (direction_t)d;

View file

@ -135,7 +135,8 @@ const char *parameters[MAXPARAMS] = {
"GRUPPE",
"PARTEITARNUNG",
"BAEUME",
"ALLIANZ"
"ALLIANZ",
"AUTO"
};
int findoption(const char *s, const struct locale *lang)

View file

@ -492,36 +492,6 @@ void destroyfaction(faction ** fp)
}
handle_event(f->attribs, "destroy", f);
#if 0
faction *ff;
for (ff = factions; ff; ff = ff->next) {
group *g;
ally *sf, **sfp;
for (sfp = &ff->allies; *sfp;) {
sf = *sfp;
if (sf->faction == f || sf->faction == NULL) {
*sfp = sf->next;
free(sf);
}
else
sfp = &(*sfp)->next;
}
for (g = ff->groups; g; g = g->next) {
for (sfp = &g->allies; *sfp; ) {
sf = *sfp;
if (sf->faction == f || sf->faction == NULL) {
*sfp = sf->next;
free(sf);
}
else {
sfp = &(*sfp)->next;
}
}
}
}
#endif
if (f->alliance) {
setalliance(f, 0);
}

View file

@ -84,7 +84,7 @@ char* get_command(const order *ord, const struct locale *lang, char *sbuffer, si
sbs_strcat(&sbs, str);
if (ord->id < 0) {
skill_t sk = (skill_t)(100+ord->id);
assert(kwd == K_STUDY && sk != SK_MAGIC && sk < MAXSKILLS);
assert((kwd == K_STUDY || kwd == K_AUTOSTUDY) && sk != SK_MAGIC && sk < MAXSKILLS);
str = skillname(sk, lang);
if (str) {
if (strchr(str, ' ') == NULL) {
@ -214,12 +214,12 @@ static int create_data(keyword_t kwd, const char *s,
order_data *data;
int id;
assert(kwd!=NOKEYWORD);
assert(kwd != NOKEYWORD);
if (!s || *s == 0) {
return 0;
}
if (kwd==K_STUDY) {
if (kwd == K_STUDY || kwd == K_AUTOSTUDY) {
const char * sptr = s;
skill_t sk = get_skill(parse_token_depr(&sptr), lang);
if (sk != SK_MAGIC && sk != NOSKILL) {
@ -332,6 +332,14 @@ order *parse_order(const char *s, const struct locale * lang)
sptr = sp;
}
}
else if (kwd == K_STUDY) {
const char *sp = sptr;
p = parse_token_depr(&sp);
if (p && isparam(p, lang, P_AUTO)) {
kwd = K_AUTOSTUDY;
sptr = sp;
}
}
if (kwd != NOKEYWORD) {
order *ord = (order *)malloc(sizeof(order));
create_order_i(ord, kwd, sptr, persistent, noerror, lang);
@ -366,6 +374,7 @@ bool is_repeated(keyword_t kwd)
case K_STEAL:
case K_SABOTAGE:
case K_STUDY:
case K_AUTOSTUDY:
case K_TEACH:
case K_GROW:
case K_PLANT:
@ -406,6 +415,7 @@ bool is_exclusive(const order * ord)
case K_STEAL:
case K_SABOTAGE:
case K_STUDY:
case K_AUTOSTUDY:
case K_TEACH:
case K_GROW:
case K_PLANT:
@ -447,6 +457,7 @@ bool is_long(keyword_t kwd)
case K_STEAL:
case K_SABOTAGE:
case K_STUDY:
case K_AUTOSTUDY:
case K_TEACH:
case K_GROW:
case K_PLANT:
@ -541,7 +552,7 @@ keyword_t init_order(const struct order *ord, const struct locale *lang)
assert(sk < MAXSKILLS);
assert(lang);
assert(kwd == K_STUDY);
assert(kwd == K_STUDY || kwd == K_AUTOSTUDY);
str = skillname(sk, lang);
if (strchr(str, ' ') == NULL) {
init_tokens_str(str);
@ -575,7 +586,7 @@ keyword_t init_order_depr(const struct order *ord)
{
if (ord) {
keyword_t kwd = ORD_KEYWORD(ord);
assert(kwd != K_STUDY);
assert(kwd != K_STUDY && kwd != K_AUTOSTUDY);
}
return init_order(ord, NULL);
}

View file

@ -113,6 +113,30 @@ static void test_parse_make(CuTest *tc) {
test_teardown();
}
static void test_parse_autostudy(CuTest *tc) {
char cmd[32];
order *ord;
struct locale * lang;
test_setup();
lang = get_or_create_locale("en");
locale_setstring(lang, mkname("skill", skillnames[SK_ENTERTAINMENT]), "Entertainment");
locale_setstring(lang, keyword(K_STUDY), "STUDY");
locale_setstring(lang, keyword(K_AUTOSTUDY), "AUTOSTUDY");
locale_setstring(lang, parameters[P_AUTO], "AUTO");
init_locale(lang);
ord = parse_order("STUDY AUTO Entertainment", lang);
CuAssertPtrNotNull(tc, ord);
CuAssertIntEquals(tc, K_AUTOSTUDY, getkeyword(ord));
CuAssertStrEquals(tc, "AUTOSTUDY Entertainment", get_command(ord, lang, cmd, sizeof(cmd)));
CuAssertIntEquals(tc, K_AUTOSTUDY, init_order(ord, lang));
CuAssertStrEquals(tc, "Entertainment", getstrtoken());
free_order(ord);
test_teardown();
}
static void test_parse_make_temp(CuTest *tc) {
char cmd[32];
order *ord;
@ -130,7 +154,7 @@ static void test_parse_make_temp(CuTest *tc) {
CuAssertIntEquals(tc, K_MAKETEMP, getkeyword(ord));
CuAssertStrEquals(tc, "MAKETEMP herp", get_command(ord, lang, cmd, sizeof(cmd)));
CuAssertIntEquals(tc, K_MAKETEMP, init_order_depr(ord));
CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord, lang));
CuAssertStrEquals(tc, "herp", getstrtoken());
free_order(ord);
test_teardown();
@ -153,7 +177,7 @@ static void test_parse_maketemp(CuTest *tc) {
CuAssertPtrNotNull(tc, ord);
CuAssertStrEquals(tc, "MAKETEMP herp", get_command(ord, lang, cmd, sizeof(cmd)));
CuAssertIntEquals(tc, K_MAKETEMP, getkeyword(ord));
CuAssertIntEquals(tc, K_MAKETEMP, init_order_depr(ord));
CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord, lang));
CuAssertStrEquals(tc, "herp", getstrtoken());
free_order(ord);
test_teardown();
@ -167,7 +191,7 @@ static void test_init_order(CuTest *tc) {
lang = get_or_create_locale("en");
ord = create_order(K_MAKETEMP, lang, "hurr durr");
CuAssertIntEquals(tc, K_MAKETEMP, init_order_depr(ord));
CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord, lang));
CuAssertStrEquals(tc, "hurr", getstrtoken());
CuAssertStrEquals(tc, "durr", getstrtoken());
free_order(ord);
@ -512,6 +536,7 @@ static void test_create_order_long(CuTest *tc) {
stream_order(&out, ord, lang, true);
out.api->rewind(out.handle);
out.api->readln(out.handle, buffer, sizeof(buffer));
CuAssertIntEquals(tc, 1026, strlen(buffer));
mstream_done(&out);
free_order(ord);
test_teardown();
@ -547,6 +572,7 @@ CuSuite *get_order_suite(void)
SUITE_ADD_TEST(suite, test_study_order_quoted);
SUITE_ADD_TEST(suite, test_parse_order);
SUITE_ADD_TEST(suite, test_parse_make);
SUITE_ADD_TEST(suite, test_parse_autostudy);
SUITE_ADD_TEST(suite, test_parse_make_temp);
SUITE_ADD_TEST(suite, test_parse_maketemp);
SUITE_ADD_TEST(suite, test_init_order);

View file

@ -1493,7 +1493,9 @@ int read_game(gamedata *data)
if (r->flags & RF_LIGHTHOUSE) {
building *b;
for (b = r->buildings; b; b = b->next) {
update_lighthouse(b);
if (is_lighthouse(b->type)) {
update_lighthouse(b);
}
}
}
}

View file

@ -124,9 +124,9 @@ extern "C" {
extern void write_ship_reference(const struct ship *sh,
struct storage *store);
extern void remove_ship(struct ship **slist, struct ship *s);
extern void free_ship(struct ship *s);
extern void free_ships(void);
void remove_ship(struct ship **slist, struct ship *s);
void free_ship(struct ship *s);
void free_ships(void);
const char *ship_getname(const struct ship *sh);
void ship_setname(struct ship *self, const char *name);

View file

@ -130,6 +130,7 @@ typedef enum {
P_FACTIONSTEALTH,
P_TREES,
P_ALLIANCE,
P_AUTO,
MAXPARAMS,
NOPARAM
} param_t;

View file

@ -1310,13 +1310,12 @@ int eff_skill(const unit * u, const skill *sv, const region *r)
return 0;
}
int effskill_study(const unit * u, skill_t sk, const region * r)
int effskill_study(const unit * u, skill_t sk)
{
skill *sv = unit_skill(u, sk);
if (sv && sv->level > 0) {
int mlevel = sv->level;
if (!r) r = u->region;
mlevel += get_modifier(u, sv->id, sv->level, r, true);
mlevel += get_modifier(u, sv->id, sv->level, u->region, true);
if (mlevel > 0)
return mlevel;
}

View file

@ -163,7 +163,7 @@ extern "C" {
void clone_men(const struct unit *src, struct unit *dst, int n); /* like transfer, but do not subtract from src */
int eff_skill(const struct unit *u, const struct skill *sv, const struct region *r);
int effskill_study(const struct unit *u, skill_t sk, const struct region *r);
int effskill_study(const struct unit *u, skill_t sk);
int get_modifier(const struct unit *u, skill_t sk, int level,
const struct region *r, bool noitem);

View file

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

View file

@ -149,5 +149,6 @@ const char *keywords[MAXKEYWORDS] = {
"promote",
"pay",
"loot",
"autostudy",
};

View file

@ -72,6 +72,7 @@ extern "C"
K_PROMOTION,
K_PAY,
K_LOOT,
K_AUTOSTUDY,
MAXKEYWORDS,
NOKEYWORD
} keyword_t;

View file

@ -26,6 +26,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <modules/gmcmd.h>
#include "alchemy.h"
#include "automate.h"
#include "battle.h"
#include "economy.h"
#include "keyword.h"
@ -2058,17 +2059,6 @@ int mail_cmd(unit * u, struct order *ord)
break;
}
else {
attrib *a = a_find(u2->attribs, &at_eventhandler);
if (a != NULL) {
event_arg args[3];
args[0].data.v = (void *)s;
args[0].type = "string";
args[1].data.v = (void *)u;
args[1].type = "unit";
args[2].type = NULL;
handle_event(a, "message", args);
}
mailunit(r, u, n, ord, s);
}
return 0;
@ -2590,6 +2580,7 @@ void sinkships(struct region * r)
}
}
if (sh->damage >= sh->size * DAMAGE_SCALE) {
sink_ship(sh);
remove_ship(shp, sh);
}
if (*shp == sh)
@ -3646,6 +3637,24 @@ void add_proc_unit(int priority, void(*process) (unit *), const char *name)
}
}
bool long_order_allowed(const unit *u)
{
const region *r = u->region;
if (fval(u, UFL_LONGACTION)) {
/* this message was already given in laws.update_long_order
cmistake(u, ord, 52, MSG_PRODUCE);
*/
return false;
}
else if (fval(r->terrain, SEA_REGION)
&& u_race(u) != get_race(RC_AQUARIAN)
&& !(u_race(u)->flags & RCF_SWIM)) {
/* error message disabled by popular demand */
return false;
}
return true;
}
/* per priority, execute processors in order from PR_GLOBAL down to PR_ORDER */
void process(void)
{
@ -3715,16 +3724,7 @@ void process(void)
cmistake(u, ord, 224, MSG_MAGIC);
ord = NULL;
}
else if (fval(u, UFL_LONGACTION)) {
/* this message was already given in laws.update_long_order
cmistake(u, ord, 52, MSG_PRODUCE);
*/
ord = NULL;
}
else if (fval(r->terrain, SEA_REGION)
&& u_race(u) != get_race(RC_AQUARIAN)
&& !(u_race(u)->flags & RCF_SWIM)) {
/* error message disabled by popular demand */
else if (!long_order_allowed(u)) {
ord = NULL;
}
}
@ -4011,6 +4011,7 @@ void init_processor(void)
}
p += 10;
add_proc_region(p, do_autostudy, "study automation");
add_proc_order(p, K_TEACH, teach_cmd, PROC_THISORDER | PROC_LONGORDER,
"Lehren");
p += 10;
@ -4165,7 +4166,7 @@ void update_subscriptions(void)
/** determine if unit can be seen by faction
* @param f -- the observiong faction
* @param u -- the unit that is observed
* @param r -- the region that u is obesrved in (see below)
* @param r -- the region that u is obesrved from (see below)
* @param m -- terrain modifier to stealth
*
* r kann != u->region sein, wenn es um Durchreisen geht,

View file

@ -66,6 +66,7 @@ extern "C" {
void update_long_order(struct unit *u);
void sinkships(struct region * r);
void do_enter(struct region *r, bool is_final_attempt);
bool long_order_allowed(const struct unit *u);
int password_cmd(struct unit *u, struct order *ord);
int banner_cmd(struct unit *u, struct order *ord);

View file

@ -1759,6 +1759,34 @@ static void test_nmr_timeout(CuTest *tc) {
test_teardown();
}
static void test_long_orders(CuTest *tc) {
unit *u;
test_setup();
u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0));
CuAssertTrue(tc, long_order_allowed(u));
u->flags |= UFL_LONGACTION;
CuAssertTrue(tc, !long_order_allowed(u));
test_teardown();
}
static void test_long_order_on_ocean(CuTest *tc) {
unit *u;
race * rc;
test_setup();
rc = test_create_race("pikachu");
u = test_create_unit(test_create_faction(rc), test_create_ocean(0, 0));
CuAssertTrue(tc, !long_order_allowed(u));
rc->flags |= RCF_SWIM;
CuAssertTrue(tc, long_order_allowed(u));
rc = test_create_race("aquarian");
u = test_create_unit(test_create_faction(rc), u->region);
CuAssertTrue(tc, long_order_allowed(u));
test_teardown();
}
CuSuite *get_laws_suite(void)
{
CuSuite *suite = CuSuiteNew();
@ -1831,6 +1859,8 @@ CuSuite *get_laws_suite(void)
SUITE_ADD_TEST(suite, test_cansee_ring);
SUITE_ADD_TEST(suite, test_cansee_sphere);
SUITE_ADD_TEST(suite, test_nmr_timeout);
SUITE_ADD_TEST(suite, test_long_orders);
SUITE_ADD_TEST(suite, test_long_order_on_ocean);
return suite;
}

View file

@ -19,72 +19,94 @@ attrib_type at_lighthouse = {
/* Rest ist NULL; tempor<6F>res, nicht alterndes Attribut */
};
bool is_lighthouse(const building_type *btype)
{
return is_building_type(btype, "lighthouse");
}
/* update_lighthouse: call this function whenever the size of a lighthouse changes
* it adds temporary markers to the surrounding regions.
* The existence of markers says nothing about the quality of the observer in
* the lighthouse, for this may change more frequently.
*/
* it adds temporary markers to the surrounding regions.
* The existence of markers says nothing about the quality of the observer in
* the lighthouse, since this may change more frequently.
*/
void update_lighthouse(building * lh)
{
if (is_building_type(lh->type, "lighthouse")) {
region *r = lh->region;
region *r = lh->region;
assert(is_lighthouse(lh->type));
r->flags |= RF_LIGHTHOUSE;
if (lh->size > 0) {
int d = (int)log10(lh->size) + 1;
int x;
for (x = -d; x <= d; ++x) {
int y;
for (y = -d; y <= d; ++y) {
attrib *a;
region *r2;
int px = r->x + x, py = r->y + y;
r->flags |= RF_LIGHTHOUSE;
if (lh->size >= 10) {
int d = lighthouse_range(lh);
int x;
for (x = -d; x <= d; ++x) {
int y;
for (y = -d; y <= d; ++y) {
attrib *a;
region *r2;
int px = r->x + x, py = r->y + y;
pnormalize(&px, &py, rplane(r));
r2 = findregion(px, py);
if (!r2 || !fval(r2->terrain, SEA_REGION))
continue;
if (distance(r, r2) > d)
continue;
a = a_find(r2->attribs, &at_lighthouse);
while (a && a->type == &at_lighthouse) {
building *b = (building *)a->data.v;
if (b == lh)
break;
a = a->next;
}
if (!a) {
a = a_add(&r2->attribs, a_new(&at_lighthouse));
a->data.v = (void *)lh;
}
pnormalize(&px, &py, rplane(r));
r2 = findregion(px, py);
if (!r2 || !fval(r2->terrain, SEA_REGION))
continue;
if (distance(r, r2) > d)
continue;
a = a_find(r2->attribs, &at_lighthouse);
while (a && a->type == &at_lighthouse) {
building *b = (building *)a->data.v;
if (b == lh)
break;
a = a->next;
}
if (!a) {
a = a_add(&r2->attribs, a_new(&at_lighthouse));
a->data.v = (void *)lh;
}
}
}
}
}
int lighthouse_range(const building * b, const faction * f, const unit *u)
{
if (fval(b, BLD_MAINTAINED) && b->size >= 10) {
int maxd = (int)log10(b->size) + 1;
void remove_lighthouse(const building *lh) {
building *b;
region * r = lh->region;
if (u && skill_enabled(SK_PERCEPTION)) {
r->flags &= ~RF_LIGHTHOUSE;
for (b = r->buildings; b; b = b->next) {
if (b != lh && is_lighthouse(b->type)) {
update_lighthouse(b);
}
}
}
int lighthouse_range(const building * b)
{
if (b->size >= 10 && (b->flags & BLD_MAINTAINED)) {
return (int)log10(b->size) + 1;
}
return 0;
}
int lighthouse_view_distance(const building * b, const unit *u)
{
if (b->size >= 10 && (b->flags & BLD_MAINTAINED)) {
int maxd = lighthouse_range(b);
if (maxd > 0 && u && skill_enabled(SK_PERCEPTION)) {
int sk = effskill(u, SK_PERCEPTION, 0) / 3;
assert(u->building == b);
assert(u->faction == f);
if (maxd > sk) maxd = sk;
}
/* E3A rule: no perception req'd */
return maxd;
}
return 0;
}
bool check_leuchtturm(region * r, faction * f)
bool lighthouse_guarded(const region * r)
{
attrib *a;
if (!fval(r->terrain, SEA_REGION)) {
if (!r->attribs || !(r->terrain->flags & SEA_REGION)) {
return false;
}
for (a = a_find(r->attribs, &at_lighthouse); a && a->type == &at_lighthouse;
@ -92,37 +114,11 @@ bool check_leuchtturm(region * r, faction * f)
building *b = (building *)a->data.v;
assert(is_building_type(b->type, "lighthouse"));
if (fval(b, BLD_MAINTAINED) && b->size >= 10) {
if ((b->flags & BLD_MAINTAINED) && b->size >= 10) {
int maxd = (int)log10(b->size) + 1;
if (skill_enabled(SK_PERCEPTION) && f) {
region *r2 = b->region;
unit *u;
int c = 0;
int d = 0;
for (u = r2->units; u; u = u->next) {
if (u->building == b) {
c += u->number;
if (c > buildingcapacity(b))
break;
if (u->faction == f) {
if (!d)
d = distance(r, r2);
if (maxd < d)
break;
if (effskill(u, SK_PERCEPTION, 0) >= d * 3)
return true;
}
}
else if (c)
break; /* first unit that's no longer in the house ends the search */
}
}
else {
/* E3A rule: no perception req'd */
return true;
}
int d = distance(r, b->region);
assert(maxd >= d);
return true;
}
}

View file

@ -29,15 +29,18 @@ extern "C" {
struct faction;
struct region;
struct building;
struct building_type;
struct unit;
struct attrib;
extern struct attrib_type at_lighthouse;
/* leuchtturm */
bool check_leuchtturm(struct region *r, struct faction *f);
bool is_lighthouse(const struct building_type *btype);
bool lighthouse_guarded(const struct region *r);
void update_lighthouse(struct building *b);
int lighthouse_range(const struct building *b, const struct faction *f,
const struct unit *u);
void remove_lighthouse(const struct building *lh);
int lighthouse_range(const struct building *b);
int lighthouse_view_distance(const struct building *b, const struct unit *u);
#ifdef __cplusplus

View file

@ -26,35 +26,39 @@ static void test_lighthouse_range(CuTest * tc)
u1 = test_create_unit(test_create_faction(NULL), r);
u2 = test_create_unit(test_create_faction(NULL), r);
b = test_create_building(r, test_create_buildingtype("lighthouse"));
CuAssertIntEquals(tc, 0, lighthouse_range(b, NULL, NULL));
CuAssertIntEquals(tc, 0, lighthouse_range(b, u1->faction, NULL));
CuAssertIntEquals(tc, 0, lighthouse_range(b));
b->size = 9;
CuAssertIntEquals(tc, 0, lighthouse_range(b));
b->size = 10;
CuAssertIntEquals(tc, 0, lighthouse_range(b, NULL, NULL));
CuAssertIntEquals(tc, 0, lighthouse_range(b));
b->flags |= BLD_MAINTAINED;
CuAssertIntEquals(tc, 2, lighthouse_range(b));
u1->building = b;
u2->building = b;
u1->number = 10;
set_level(u1, SK_PERCEPTION, 3);
set_level(u2, SK_PERCEPTION, 3);
CuAssertIntEquals(tc, 0, lighthouse_range(b, NULL, NULL));
b->flags |= BLD_MAINTAINED;
CuAssertIntEquals(tc, 1, lighthouse_range(b, u1->faction, u1));
CuAssertIntEquals(tc, 1, lighthouse_view_distance(b, u1));
set_level(u1, SK_PERCEPTION, 6);
CuAssertIntEquals(tc, 2, lighthouse_range(b, u1->faction, u1));
/* lighthouse_range does not check inside_building */
CuAssertIntEquals(tc, 1, lighthouse_range(b, u2->faction, u2));
CuAssertIntEquals(tc, 1, lighthouse_view_distance(b, u2));
CuAssertIntEquals(tc, 2, lighthouse_view_distance(b, u1));
b->size = 100;
update_lighthouse(b);
CuAssertIntEquals(tc, 3, lighthouse_range(b, NULL, NULL));
CuAssertIntEquals(tc, 2, lighthouse_range(b, u1->faction, u1));
CuAssertIntEquals(tc, 3, lighthouse_range(b));
CuAssertIntEquals(tc, 2, lighthouse_view_distance(b, u1));
set_level(u1, SK_PERCEPTION, 9);
CuAssertIntEquals(tc, 3, lighthouse_range(b, u1->faction, u1));
CuAssertIntEquals(tc, 1, lighthouse_range(b, u2->faction, u2));
CuAssertIntEquals(tc, 3, lighthouse_view_distance(b, u1));
CuAssertIntEquals(tc, 1, lighthouse_view_distance(b, u2));
b->size = 99;
CuAssertIntEquals(tc, 2, lighthouse_view_distance(b, u1));
test_teardown();
}
static void test_lighthouse_update(CuTest * tc)
{
region *r1, *r2, *r3;
region *r1, *r2, *r3, *r4;
building *b;
const struct terrain_type *t_ocean, *t_plain;
@ -64,20 +68,23 @@ static void test_lighthouse_update(CuTest * tc)
r1 = test_create_region(0, 0, t_plain);
r2 = test_create_region(1, 0, t_ocean);
r3 = test_create_region(2, 0, t_ocean);
r4 = test_create_region(0, 1, t_plain);
b = test_create_building(r1, test_create_buildingtype("lighthouse"));
b->flags |= BLD_MAINTAINED;
CuAssertIntEquals(tc, RF_LIGHTHOUSE, r1->flags&RF_LIGHTHOUSE);
CuAssertPtrEquals(tc, NULL, r1->attribs);
CuAssertPtrEquals(tc, NULL, r2->attribs);
CuAssertPtrEquals(tc, NULL, r3->attribs);
CuAssertPtrEquals(tc, NULL, r4->attribs);
r1->flags = 0;
b->size = 1;
b->size = 9; /* minimum size for any effect is 10 */
update_lighthouse(b);
CuAssertIntEquals(tc, RF_LIGHTHOUSE, r1->flags&RF_LIGHTHOUSE);
CuAssertPtrNotNull(tc, r2->attribs);
CuAssertPtrEquals(tc, (void *)&at_lighthouse, (void *)r2->attribs->type);
CuAssertPtrEquals(tc, NULL, r1->attribs);
CuAssertPtrEquals(tc, NULL, r2->attribs);
CuAssertPtrEquals(tc, NULL, r3->attribs);
CuAssertPtrEquals(tc, NULL, r4->attribs);
a_removeall(&r2->attribs, NULL);
r1->flags = 0;
@ -88,6 +95,39 @@ static void test_lighthouse_update(CuTest * tc)
CuAssertPtrEquals(tc, (void *)&at_lighthouse, (void *)r2->attribs->type);
CuAssertPtrNotNull(tc, r3->attribs);
CuAssertPtrEquals(tc, (void *)&at_lighthouse, (void *)r3->attribs->type);
CuAssertPtrEquals(tc, NULL, r4->attribs);
test_teardown();
}
static void test_lighthouse_guard(CuTest * tc) {
region *r1, *r2, *r3, *r4;
building *b;
const struct terrain_type *t_ocean, *t_plain;
test_setup();
t_ocean = test_create_terrain("ocean", SEA_REGION);
t_plain = test_create_terrain("plain", LAND_REGION);
r1 = test_create_region(0, 0, t_plain);
r2 = test_create_region(1, 0, t_ocean);
r3 = test_create_region(2, 0, t_ocean);
r4 = test_create_region(0, 1, t_plain);
b = test_create_building(r1, test_create_buildingtype("lighthouse"));
b->flags |= BLD_MAINTAINED;
b->size = 10;
CuAssertIntEquals(tc, 2, lighthouse_range(b));
update_lighthouse(b);
CuAssertIntEquals(tc, RF_LIGHTHOUSE, r1->flags&RF_LIGHTHOUSE);
CuAssertPtrEquals(tc, NULL, r1->attribs);
CuAssertPtrEquals(tc, (void *)&at_lighthouse, (void *)r2->attribs->type);
CuAssertPtrEquals(tc, (void *)&at_lighthouse, (void *)r3->attribs->type);
CuAssertPtrEquals(tc, NULL, r4->attribs);
CuAssertIntEquals(tc, false, lighthouse_guarded(r1));
CuAssertIntEquals(tc, true, lighthouse_guarded(r2));
CuAssertIntEquals(tc, true, lighthouse_guarded(r3));
CuAssertIntEquals(tc, false, lighthouse_guarded(r4));
b->size = 1; /* size can go down in destroy_cmd */
CuAssertIntEquals(tc, false, lighthouse_guarded(r2));
CuAssertIntEquals(tc, false, lighthouse_guarded(r3));
test_teardown();
}
@ -96,5 +136,6 @@ CuSuite *get_lighthouse_suite(void)
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_lighthouse_range);
SUITE_ADD_TEST(suite, test_lighthouse_update);
SUITE_ADD_TEST(suite, test_lighthouse_guard);
return suite;
}

View file

@ -24,7 +24,6 @@
#include "monsters.h"
#include "economy.h"
#include "chaos.h"
#include "give.h"
#include "guard.h"
#include "laws.h"
@ -756,6 +755,11 @@ void plan_monsters(faction * f)
if (u->faction!=f)
continue;
/* Parteitarnung von Monstern ist doof: */
if (fval(u, UFL_ANON_FACTION)) {
u->flags &= ~UFL_ANON_FACTION;
}
/* Befehle m<>ssen jede Runde neu gegeben werden: */
free_orders(&u->orders);
if (skill_enabled(SK_PERCEPTION)) {
@ -843,18 +847,14 @@ void plan_monsters(faction * f)
pathfinder_cleanup();
}
static double chaosfactor(region * r)
{
return fval(r, RF_CHAOTIC) ? ((double)(1 + get_chaoscount(r)) / 1000.0) : 0.0;
}
static int nrand(int handle_start, int sub)
{
int res = 0;
do {
if (rng_int() % 100 < handle_start)
if (rng_int() % 100 < handle_start) {
res++;
}
handle_start -= sub;
} while (handle_start > 0);
@ -876,7 +876,7 @@ void spawn_dragons(void)
region *r;
faction *monsters = get_or_create_monsters();
int minage = config_get_int("monsters.spawn.min_age", 100);
int spawn_chance = 100 * config_get_int("monsters.spawn.chance", 100);
int spawn_chance = config_get_int("monsters.spawn.chance", 100);
if (spawn_chance <= 0) {
/* monster spawning disabled */
@ -895,7 +895,8 @@ void spawn_dragons(void)
else if ((r->terrain == newterrain(T_GLACIER)
|| r->terrain == newterrain(T_SWAMP)
|| r->terrain == newterrain(T_DESERT))
&& rng_int() % spawn_chance < (5 + 100 * chaosfactor(r))) {
&& rng_int() % spawn_chance < 6)
{
if (chance(0.80)) {
u = create_unit(r, monsters, nrand(60, 20) + 1, get_race(RC_FIREDRAGON), 0, NULL, NULL);
}
@ -907,7 +908,7 @@ void spawn_dragons(void)
log_debug("spawning %d %s in %s.\n", u->number,
LOC(default_locale,
rc_name_s(u_race(u), (u->number == 1) ? NAME_SINGULAR : NAME_PLURAL)), regionname(r, NULL));
rc_name_s(u_race(u), (u->number == 1) ? NAME_SINGULAR : NAME_PLURAL)), regionname(r, NULL));
name_unit(u);
@ -932,9 +933,9 @@ void spawn_undead(void)
continue;
}
}
/* Chance 0.1% * chaosfactor */
if (r->land && unburied > rpeasants(r) / 20
&& rng_int() % 10000 < (100 + 100 * chaosfactor(r))) {
&& rng_int() % 10000 < 200) {
message *msg;
unit *u;
/* es ist sinnfrei, wenn irgendwo im Wald 3er-Einheiten Untote entstehen.
@ -1015,37 +1016,42 @@ static void eaten_by_monster(unit * u)
{
/* adjustment for smaller worlds */
double multi = RESOURCE_QUANTITY * newterrain(T_PLAIN)->size / 10000.0;
int n = 0;
int horse = -1;
const resource_type *rhorse = get_resourcetype(R_HORSE);
const race *rc = u_race(u);
int scare;
int p = rpeasants(u->region);
scare = rc_scare(rc);
if (scare>0) {
n = rng_int() % scare * u->number;
} else {
n = rng_int() % (u->number / 20 + 1);
horse = 0;
}
horse = horse ? i_get(u->items, rhorse->itype) : 0;
if (p > 0) {
int horse = -1;
int scare = rc_scare(rc);
int n = 0;
n = (int)(n * multi);
if (n > 0) {
n = lovar(n);
if (n > 0) {
int p = rpeasants(u->region);
if (p < n) n = p;
deathcounts(u->region, n);
rsetpeasants(u->region, rpeasants(u->region) - n);
ADDMSG(&u->region->msgs, msg_message("eatpeasants", "unit amount", u, n));
if (scare > 0) {
n = rng_int() % scare * u->number;
}
else {
n = rng_int() % (u->number / 20 + 1);
horse = 0;
}
horse = horse ? i_get(u->items, rhorse->itype) : 0;
if (horse > 0) {
i_change(&u->items, rhorse->itype, -horse);
ADDMSG(&u->region->msgs, msg_message("eathorse", "unit amount", u, horse));
}
n = (int)(n * multi);
if (n > 0) {
n = lovar(n);
if (p < n) n = p;
if (n > 0) {
if (n > 0) {
deathcounts(u->region, n);
rsetpeasants(u->region, rpeasants(u->region) - n);
ADDMSG(&u->region->msgs, msg_message("eatpeasants", "unit amount", u, n));
}
}
}
}
if (horse > 0) {
i_change(&u->items, rhorse->itype, -horse);
ADDMSG(&u->region->msgs, msg_message("eathorse", "unit amount", u, horse));
}
}
@ -1058,10 +1064,12 @@ static void absorbed_by_monster(unit * u)
if (n > 0) {
int p = rpeasants(u->region);
if (p < n) n = p;
rsetpeasants(u->region, rpeasants(u->region) - n);
scale_number(u, u->number + n);
ADDMSG(&u->region->msgs, msg_message("absorbpeasants",
"unit race amount", u, u_race(u), n));
if (n > 0) {
rsetpeasants(u->region, rpeasants(u->region) - n);
scale_number(u, u->number + n);
ADDMSG(&u->region->msgs, msg_message("absorbpeasants",
"unit race amount", u, u_race(u), n));
}
}
}
}

View file

@ -47,6 +47,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "laws.h"
#include "reports.h"
#include "study.h"
#include "spy.h"
#include "alchemy.h"
#include "travelthru.h"
#include "vortex.h"
@ -73,7 +74,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/assert.h>
#include <util/attrib.h>
#include <util/base36.h>
#include <util/bsdstring.h>
#include <util/gamedata.h>
#include <util/language.h>
#include <util/lists.h>
@ -542,6 +542,7 @@ static ship *do_maelstrom(region * r, unit * u)
if (sh->damage >= sh->size * DAMAGE_SCALE) {
ADDMSG(&u->faction->msgs, msg_message("entermaelstrom",
"region ship damage sink", r, sh, damage, 1));
sink_ship(sh);
remove_ship(&sh->region->ships, sh);
return NULL;
}
@ -883,12 +884,14 @@ static void drifting_ships(region * r)
}
if (sh->damage >= sh->size * DAMAGE_SCALE) {
msg_to_ship_inmates(sh, &firstu, &lastu, msg_message("shipsink", "ship", sh));
remove_ship(&sh->region->ships, sh);
sink_ship(sh);
remove_ship(shp, sh);
}
}
if (*shp == sh)
if (*shp == sh) {
shp = &sh->next;
}
}
}
}
@ -1047,15 +1050,17 @@ int movewhere(const unit * u, const char *token, region * r, region ** resultp)
order * cycle_route(order * ord, const struct locale *lang, int gereist)
{
int cm = 0;
char tail[1024], *bufp = tail;
char neworder[2048], *obuf = neworder;
char tail[1024];
char neworder[2048];
char token[128];
direction_t d = NODIRECTION;
bool paused = false;
bool pause;
order *norder;
size_t size = sizeof(tail) - 1;
sbstring sbtail;
sbstring sborder;
sbs_init(&sbtail, tail, sizeof(tail));
sbs_init(&sborder, neworder, sizeof(neworder));
assert(getkeyword(ord) == K_ROUTE);
tail[0] = '\0';
neworder[0] = '\0';
@ -1063,14 +1068,10 @@ order * cycle_route(order * ord, const struct locale *lang, int gereist)
for (cm = 0;; ++cm) {
const char *s;
pause = false;
s = gettoken(token, sizeof(token));
if (s && *s) {
d = get_direction(s, lang);
if (d == D_PAUSE) {
pause = true;
}
else if (d == NODIRECTION) {
if (d == NODIRECTION) {
break;
}
}
@ -1079,38 +1080,37 @@ order * cycle_route(order * ord, const struct locale *lang, int gereist)
}
if (cm < gereist) {
/* TODO: hier sollte keine PAUSE auftreten */
assert(!pause);
if (!pause) {
assert (d != D_PAUSE);
if (d != D_PAUSE) {
const char *loc = LOC(lang, shortdirections[d]);
assert(loc);
if (bufp != tail) {
bufp = STRLCPY_EX(bufp, " ", &size, "cycle_route");
if (sbs_length(&sbtail) > 0) {
sbs_strcat(&sbtail, " ");
}
bufp = STRLCPY_EX(bufp, loc, &size, "cycle_route");
sbs_strcat(&sbtail, loc);
}
}
else if (strlen(neworder) > sizeof(neworder) / 2)
break;
else if (cm == gereist && !paused && pause) {
else if (cm == gereist && !paused && (d == D_PAUSE)) {
const char *loc = LOC(lang, parameters[P_PAUSE]);
bufp = STRLCPY_EX(bufp, " ", &size, "cycle_route");
bufp = STRLCPY_EX(bufp, loc, &size, "cycle_route");
sbs_strcat(&sbtail, " ");
sbs_strcat(&sbtail, loc);
paused = true;
}
else if (pause) {
/* da PAUSE nicht in ein shortdirections[d] umgesetzt wird (ist
* hier keine normale direction), muss jede PAUSE einzeln
* herausgefiltert und explizit gesetzt werden */
if (neworder != obuf) {
obuf += str_strlcat(obuf, " ", sizeof(neworder) - (obuf - neworder));
}
obuf += str_strlcat(obuf, LOC(lang, parameters[P_PAUSE]), sizeof(neworder) - (obuf - neworder));
}
else {
if (neworder != obuf) {
obuf += str_strlcat(obuf, " ", sizeof(neworder) - (obuf - neworder));
if (sbs_length(&sbtail) > 0) {
sbs_strcat(&sborder, " ");
}
if (d == D_PAUSE) {
/* da PAUSE nicht in ein shortdirections[d] umgesetzt wird (ist
* hier keine normale direction), muss jede PAUSE einzeln
* herausgefiltert und explizit gesetzt werden */
sbs_strcat(&sborder, LOC(lang, parameters[P_PAUSE]));
}
else {
sbs_strcat(&sborder, LOC(lang, shortdirections[d]));
}
obuf += str_strlcat(obuf, LOC(lang, shortdirections[d]), sizeof(neworder) - (obuf - neworder));
}
}
@ -1783,7 +1783,7 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting)
/* storms should be the first thing we do. */
stormchance = stormyness / shipspeed(sh, u);
if (check_leuchtturm(next_point, NULL)) {
if (lighthouse_guarded(next_point)) {
if (lighthouse_div > 0) {
stormchance /= lighthouse_div;
}
@ -1871,7 +1871,7 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting)
if (reason == SA_NO_INSECT) {
ADDMSG(&f->msgs, msg_message("detectforbidden", "unit region", u, sh->region));
}
else if (check_leuchtturm(current_point, NULL)) {
else if (lighthouse_guarded(current_point)) {
ADDMSG(&f->msgs, msg_message("sailnolandingstorm", "ship region", sh, next_point));
}
else {
@ -1930,6 +1930,7 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting)
if (sh->damage >= sh->size * DAMAGE_SCALE) {
if (sh->region) {
ADDMSG(&f->msgs, msg_message("shipsink", "ship", sh));
sink_ship(sh);
remove_ship(&sh->region->ships, sh);
}
sh = NULL;
@ -2250,10 +2251,9 @@ static direction_t hunted_dir(attrib * at, int id)
int follow_ship(unit * u, order * ord)
{
region *rc = u->region;
size_t bytes;
sbstring sbcmd;
int moves, id, speed;
char command[256], *bufp = command;
size_t size = sizeof(command);
char command[256];
direction_t dir;
if (fval(u, UFL_NOTMOVING)) {
@ -2289,11 +2289,10 @@ int follow_ship(unit * u, order * ord)
return 0;
}
bufp = command;
bytes = slprintf(bufp, size, "%s %s", LOC(u->faction->locale, keyword(K_MOVE)), LOC(u->faction->locale, directions[dir]));
assert(bytes <= INT_MAX);
if (wrptr(&bufp, &size, (int)bytes) != 0)
WARN_STATIC_BUFFER();
sbs_init(&sbcmd, command, sizeof(command));
sbs_strcpy(&sbcmd, LOC(u->faction->locale, keyword(K_MOVE)));
sbs_strcat(&sbcmd, " ");
sbs_strcat(&sbcmd, LOC(u->faction->locale, directions[dir]));
moves = 1;
@ -2309,8 +2308,8 @@ int follow_ship(unit * u, order * ord)
rc = rconnect(rc, dir);
while (rc && moves < speed && (dir = hunted_dir(rc->attribs, id)) != NODIRECTION) {
const char *loc = LOC(u->faction->locale, directions[dir]);
bufp = STRLCPY_EX(bufp, " ", &size, "hunt");
bufp = STRLCPY_EX(bufp, loc, &size, "hunt");
sbs_strcat(&sbcmd, " ");
sbs_strcat(&sbcmd, loc);
moves++;
rc = rconnect(rc, dir);
}

View file

@ -287,6 +287,9 @@ void setup_drift (struct drift_fixture *fix) {
u_set_ship(fix->u, fix->sh = test_create_ship(fix->u->region, fix->st_boat));
assert(fix->sh);
mt_create_va(mt_new("sink_msg", NULL),
"ship:ship", "region:region", MT_NEW_END);
mt_create_va(mt_new("ship_drift", NULL),
"ship:ship", "dir:int", MT_NEW_END);
mt_create_va(mt_new("shipsink", NULL),
@ -495,6 +498,7 @@ static void test_follow_ship_msg(CuTest * tc) {
follow_ship(u, ord);
CuAssertPtrEquals(tc, r, u->region);
CuAssertPtrNotNull(tc, msg = test_find_messagetype(u->faction->msgs, "error18"));
p = msg->parameters[2].v;
CuAssertPtrNotNull(tc, p);

View file

@ -26,6 +26,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "economy.h"
#include "monsters.h"
#include "move.h"
#include "spy.h"
#include "study.h"
#include "volcano.h"
@ -295,6 +296,7 @@ static void move_iceberg(region * r)
ADDMSG(&u->faction->msgs, msg_message("overrun_by_iceberg_des",
"ship", sh));
}
sink_ship(sh);
remove_ship(&sh->region->ships, sh);
}
else if (u != NULL) {
@ -421,6 +423,7 @@ static void godcurse(void)
ADDMSG(&uo->faction->msgs,
msg_message("godcurse_destroy_ship", "ship", sh));
}
sink_ship(sh);
remove_ship(&sh->region->ships, sh);
}
sh = shn;

View file

@ -79,7 +79,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* util includes */
#include <util/attrib.h>
#include <util/base36.h>
#include <util/bsdstring.h>
#include "util/bsdstring.h"
#include <util/goodies.h>
#include <util/language.h>
#include <util/lists.h>
@ -243,39 +243,44 @@ static size_t write_spell_modifier(const spell * sp, int flag, const char * str,
return 0;
}
void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct locale *lang)
void nr_spell_syntax(char *buf, size_t size, spellbook_entry * sbe, const struct locale *lang)
{
int bytes;
char buf[4096];
char *bufp = buf;
size_t size = sizeof(buf) - 1;
const spell *sp = spellref_get(&sbe->spref);
const char *params = sp->parameter;
const char *spname;
sbstring sbs;
sbs_init(&sbs, buf, size);
if (sp->sptyp & ISCOMBATSPELL) {
bytes = (int)str_strlcpy(bufp, LOC(lang, keyword(K_COMBATSPELL)), size);
sbs_strcpy(&sbs, LOC(lang, keyword(K_COMBATSPELL)));
}
else {
bytes = (int)str_strlcpy(bufp, LOC(lang, keyword(K_CAST)), size);
sbs_strcpy(&sbs, LOC(lang, keyword(K_CAST)));
}
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
/* Reihenfolge beachten: Erst REGION, dann STUFE! */
if (sp->sptyp & FARCASTING) {
bytes = snprintf(bufp, size, " [%s x y]", LOC(lang, parameters[P_REGION]));
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
sbs_strcat(&sbs, " [");
sbs_strcat(&sbs, LOC(lang, parameters[P_REGION]));
sbs_strcat(&sbs, " x y]");
}
if (sp->sptyp & SPELLLEVEL) {
bytes = snprintf(bufp, size, " [%s n]", LOC(lang, parameters[P_LEVEL]));
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
sbs_strcat(&sbs, " [");
sbs_strcat(&sbs, LOC(lang, parameters[P_LEVEL]));
sbs_strcat(&sbs, " n]");
}
bytes = (int)snprintf(bufp, size, " \"%s\"", spell_name(sp, lang));
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
spname = spell_name(sp, lang);
if (strchr(spname, ' ') != NULL) {
/* contains spaces, needs quotes */
sbs_strcat(&sbs, " '");
sbs_strcat(&sbs, spname);
sbs_strcat(&sbs, "'");
}
else {
sbs_strcat(&sbs, " ");
sbs_strcat(&sbs, spname);
}
while (params && *params) {
typedef struct starget {
@ -298,52 +303,48 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc
if (cp == 'u') {
targetp = targets + 1;
locp = LOC(lang, targetp->vars);
bytes = (int)snprintf(bufp, size, " <%s>", locp);
sbs_strcat(&sbs, " <");
sbs_strcat(&sbs, locp);
sbs_strcat(&sbs, ">");
if (*params == '+') {
++params;
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)snprintf(bufp, size, " [<%s> ...]", locp);
sbs_strcat(&sbs, " [<");
sbs_strcat(&sbs, locp);
sbs_strcat(&sbs, "> ...]");
}
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
else if (cp == 's') {
targetp = targets + 2;
locp = LOC(lang, targetp->vars);
bytes = (int)snprintf(bufp, size, " <%s>", locp);
sbs_strcat(&sbs, " <");
sbs_strcat(&sbs, locp);
sbs_strcat(&sbs, ">");
if (*params == '+') {
++params;
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)snprintf(bufp, size, " [<%s> ...]", locp);
sbs_strcat(&sbs, " [<");
sbs_strcat(&sbs, locp);
sbs_strcat(&sbs, "> ...]");
}
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
else if (cp == 'r') {
bytes = (int)str_strlcpy(bufp, " <x> <y>", size);
sbs_strcat(&sbs, " <x> <y>");
if (*params == '+') {
++params;
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)str_strlcpy(bufp, " [<x> <y> ...]", size);
sbs_strcat(&sbs, " [<x> <y> ...]");
}
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
else if (cp == 'b') {
targetp = targets + 3;
locp = LOC(lang, targetp->vars);
bytes = (int)snprintf(bufp, size, " <%s>", locp);
sbs_strcat(&sbs, " <");
sbs_strcat(&sbs, locp);
sbs_strcat(&sbs, ">");
if (*params == '+') {
++params;
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)snprintf(bufp, size, " [<%s> ...]", locp);
sbs_strcat(&sbs, " [<");
sbs_strcat(&sbs, locp);
sbs_strcat(&sbs, "> ...]");
}
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
else if (cp == 'k') {
int i, maxparam = 0;
@ -361,41 +362,35 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc
++maxparam;
}
if (!maxparam || maxparam > 1) {
bytes = (int)str_strlcpy(bufp, " (", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
sbs_strcat(&sbs, " (");
}
i = 0;
for (targetp = targets; targetp->flag; ++targetp) {
if (!maxparam || sp->sptyp & targetp->flag) {
if (i++ != 0) {
bytes = (int)str_strlcpy(bufp, " |", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
sbs_strcat(&sbs, " |");
}
if (targetp->param && targetp->vars) {
locp = LOC(lang, targetp->vars);
bytes =
(int)snprintf(bufp, size, " %s <%s>", parameters[targetp->param],
locp);
sbs_strcat(&sbs, " ");
sbs_strcat(&sbs, parameters[targetp->param]);
sbs_strcat(&sbs, " <");
sbs_strcat(&sbs, locp);
sbs_strcat(&sbs, ">");
if (multi) {
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)snprintf(bufp, size, " [<%s> ...]", locp);
sbs_strcat(&sbs, " [<");
sbs_strcat(&sbs, locp);
sbs_strcat(&sbs, "> ...]");
}
}
else {
bytes =
(int)snprintf(bufp, size, " %s", parameters[targetp->param]);
sbs_strcat(&sbs, " ");
sbs_strcat(&sbs, parameters[targetp->param]);
}
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
}
if (!maxparam || maxparam > 1) {
bytes = (int)str_strlcpy(bufp, " )", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
sbs_strcat(&sbs, " )");
}
}
else if (cp == 'i' || cp == 'c') {
@ -416,21 +411,20 @@ void nr_spell_syntax(struct stream *out, spellbook_entry * sbe, const struct loc
}
if (*params == '?') {
++params;
bytes = (int)snprintf(bufp, size, " [<%s>]", locp);
sbs_strcat(&sbs, " [<");
sbs_strcat(&sbs, locp);
sbs_strcat(&sbs, ">]");
}
else {
bytes = (int)snprintf(bufp, size, " <%s>", locp);
sbs_strcat(&sbs, " <");
sbs_strcat(&sbs, locp);
sbs_strcat(&sbs, ">");
}
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
else {
log_error("unknown spell parameter %c for spell %s", cp, sp->sname);
}
}
*bufp = 0;
paragraph(out, buf, 2, 0, 0);
}
void nr_spell(struct stream *out, spellbook_entry * sbe, const struct locale *lang)
@ -542,10 +536,8 @@ void nr_spell(struct stream *out, spellbook_entry * sbe, const struct locale *la
paragraph(out, buf, 0, 0, 0);
paragraph(out, LOC(lang, "nr_spell_syntax"), 0, 0, 0);
bufp = buf;
size = sizeof(buf) - 1;
nr_spell_syntax(out, sbe, lang);
nr_spell_syntax(buf, sizeof(buf), sbe, lang);
paragraph(out, buf, 2, 0, 0);
newline(out);
}
@ -1825,72 +1817,61 @@ nr_ship(struct stream *out, const region *r, const ship * sh, const faction * f,
static void
nr_building(struct stream *out, const region *r, const building *b, const faction *f)
{
int i, bytes;
int i;
const char *name, *bname, *billusion = NULL;
const struct locale *lang;
char buffer[8192], *bufp = buffer;
char buffer[8192];
message *msg;
size_t size = sizeof(buffer) - 1;
size_t size;
sbstring sbs;
assert(f);
lang = f->locale;
newline(out);
bytes =
snprintf(bufp, size, "%s, %s %d, ", buildingname(b), LOC(lang,
"nr_size"), b->size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
sbs_init(&sbs, buffer, sizeof(buffer));
report_building(b, &bname, &billusion);
size = str_slprintf(buffer, sizeof(buffer), "%s, %s %d, ", buildingname(b),
LOC(lang, "nr_size"), b->size);
sbs.end += size;
name = LOC(lang, billusion ? billusion : bname);
bytes = (int)str_strlcpy(bufp, name, size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
sbs_strcat(&sbs, name);
if (billusion) {
unit *owner = building_owner(b);
if (owner && owner->faction == f) {
/* illusion. report real type */
name = LOC(lang, bname);
bytes = snprintf(bufp, size, " (%s)", name);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
sbs_strcat(&sbs, " (");
sbs_strcat(&sbs, LOC(lang, bname));
sbs_strcat(&sbs, ")");
}
}
if (!building_finished(b)) {
bytes = (int)str_strlcpy(bufp, " ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)str_strlcpy(bufp, LOC(lang, "nr_building_inprogress"), size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
sbs_strcat(&sbs, " ");
sbs_strcat(&sbs, LOC(lang, "nr_building_inprogress"));
}
if (b->besieged > 0 && r->seen.mode >= seen_lighthouse) {
msg = msg_message("nr_building_besieged", "soldiers diff", b->besieged,
b->besieged - b->size * SIEGEFACTOR);
bytes = (int)nr_render(msg, lang, bufp, size, f);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
size = nr_render(msg, lang, sbs.end, sbs.size - (sbs.end - sbs.begin), f);
sbs.end += size;
msg_release(msg);
}
i = 0;
if (b->display && b->display[0]) {
bytes = (int)str_strlcpy(bufp, "; ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
bytes = (int)str_strlcpy(bufp, b->display, size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
sbs_strcat(&sbs, "; ");
sbs_strcat(&sbs, b->display);
i = b->display[strlen(b->display) - 1];
}
if (i != '!' && i != '?' && i != '.') {
bytes = (int)str_strlcpy(bufp, ".", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
sbs_strcat(&sbs, ".");
}
*bufp = 0;
paragraph(out, buffer, 2, 0, 0);
if (r->seen.mode >= seen_lighthouse) {
@ -1900,14 +1881,10 @@ nr_building(struct stream *out, const region *r, const building *b, const factio
static void nr_paragraph(struct stream *out, message * m, faction * f)
{
int bytes;
char buf[4096], *bufp = buf;
size_t size = sizeof(buf) - 1;
char buf[4096];
assert(f);
bytes = (int)nr_render(m, f->locale, bufp, size, f);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
nr_render(m, f->locale, buf, sizeof(buf), f);
msg_release(m);
paragraph(out, buf, 0, 0, 0);
@ -2011,6 +1988,8 @@ void report_travelthru(struct stream *out, region *r, const faction *f)
}
}
#include "util/bsdstring.h"
int
report_plaintext(const char *filename, report_context * ctx,
const char *bom)

View file

@ -30,7 +30,7 @@ extern "C" {
void report_travelthru(struct stream *out, struct region * r, const struct faction * f);
void report_region(struct stream *out, const struct region * r, struct faction * f);
void nr_spell_syntax(struct stream *out, struct spellbook_entry * sbe, const struct locale *lang);
void nr_spell_syntax(char *buf, size_t size, struct spellbook_entry * sbe, const struct locale *lang);
void nr_spell(struct stream *out, struct spellbook_entry * sbe, const struct locale *lang);
#ifdef __cplusplus

View file

@ -228,32 +228,11 @@ static void set_parameter(spell_fixture spell, char *value) {
}
static void check_spell_syntax(CuTest *tc, char *msg, spell_fixture *spell, char *syntax) {
stream strm;
char buf[1024];
char *linestart, *newline;
size_t len;
mstream_init(&strm);
nr_spell_syntax(&strm, spell->sbe, spell->lang);
strm.api->rewind(strm.handle);
len = strm.api->read(strm.handle, buf, sizeof(buf));
buf[len] = '\0';
nr_spell_syntax(buf, sizeof(buf), spell->sbe, spell->lang);
linestart = strtok(buf, "\n");
while (linestart && !strstr(linestart, "ZAUBERE"))
linestart = strtok(NULL, "\n");
CuAssertPtrNotNull(tc, linestart);
newline = strtok(NULL, "\n");
while (newline) {
*(newline - 1) = '\n';
newline = strtok(NULL, "\n");
}
CuAssertStrEquals_Msg(tc, msg, syntax, linestart);
mstream_done(&strm);
CuAssertStrEquals_Msg(tc, msg, syntax, buf);
}
static void test_write_spell_syntax(CuTest *tc) {
@ -262,54 +241,54 @@ static void test_write_spell_syntax(CuTest *tc) {
test_setup();
setup_spell_fixture(&spell);
check_spell_syntax(tc, "vanilla", &spell, " ZAUBERE \"Testzauber\"");
check_spell_syntax(tc, "vanilla", &spell, "ZAUBERE Testzauber");
spell.sp->sptyp |= FARCASTING;
check_spell_syntax(tc, "far", &spell, " ZAUBERE [REGION x y] \"Testzauber\"");
check_spell_syntax(tc, "far", &spell, "ZAUBERE [REGION x y] Testzauber");
spell.sp->sptyp |= SPELLLEVEL;
check_spell_syntax(tc, "farlevel", &spell, " ZAUBERE [REGION x y] [STUFE n] \"Testzauber\"");
check_spell_syntax(tc, "farlevel", &spell, "ZAUBERE [REGION x y] [STUFE n] Testzauber");
spell.sp->sptyp = 0;
set_parameter(spell, "kc");
check_spell_syntax(tc, "kc", &spell, " ZAUBERE \"Testzauber\" ( REGION | EINHEIT <enr> | SCHIFF <snr> | BURG <bnr> )");
check_spell_syntax(tc, "kc", &spell, "ZAUBERE Testzauber ( REGION | EINHEIT <enr> | SCHIFF <snr> | BURG <bnr> )");
spell.sp->sptyp |= BUILDINGSPELL;
check_spell_syntax(tc, "kc typed", &spell, " ZAUBERE \"Testzauber\" BURG <bnr>");
check_spell_syntax(tc, "kc typed", &spell, "ZAUBERE Testzauber BURG <bnr>");
spell.sp->sptyp = 0;
set_parameter(spell, "b");
check_spell_syntax(tc, "b", &spell, " ZAUBERE \"Testzauber\" <bnr>");
check_spell_syntax(tc, "b", &spell, "ZAUBERE Testzauber <bnr>");
set_parameter(spell, "s");
check_spell_syntax(tc, "s", &spell, " ZAUBERE \"Testzauber\" <snr>");
check_spell_syntax(tc, "s", &spell, "ZAUBERE Testzauber <snr>");
set_parameter(spell, "s+");
check_spell_syntax(tc, "s+", &spell, " ZAUBERE \"Testzauber\" <snr> [<snr> ...]");
check_spell_syntax(tc, "s+", &spell, "ZAUBERE Testzauber <snr> [<snr> ...]");
set_parameter(spell, "u");
check_spell_syntax(tc, "u", &spell, " ZAUBERE \"Testzauber\" <enr>");
check_spell_syntax(tc, "u", &spell, "ZAUBERE Testzauber <enr>");
set_parameter(spell, "r");
check_spell_syntax(tc, "r", &spell, " ZAUBERE \"Testzauber\" <x> <y>");
check_spell_syntax(tc, "r", &spell, "ZAUBERE Testzauber <x> <y>");
set_parameter(spell, "bc");
free(spell.sp->syntax);
spell.sp->syntax = str_strdup("hodor");
check_spell_syntax(tc, "bc hodor", &spell, " ZAUBERE \"Testzauber\" <bnr> <Hodor>");
check_spell_syntax(tc, "bc hodor", &spell, "ZAUBERE Testzauber <bnr> <Hodor>");
free(spell.sp->syntax);
spell.sp->syntax = 0;
set_parameter(spell, "c?");
free(spell.sp->syntax);
spell.sp->syntax = str_strdup("hodor");
check_spell_syntax(tc, "c?", &spell, " ZAUBERE \"Testzauber\" [<Hodor>]");
check_spell_syntax(tc, "c?", &spell, "ZAUBERE Testzauber [<Hodor>]");
free(spell.sp->syntax);
spell.sp->syntax = 0;
set_parameter(spell, "kc+");
check_spell_syntax(tc, "kc+", &spell,
" ZAUBERE \"Testzauber\" ( REGION | EINHEIT <enr> [<enr> ...] | SCHIFF <snr>\n [<snr> ...] | BURG <bnr> [<bnr> ...] )");
"ZAUBERE Testzauber ( REGION | EINHEIT <enr> [<enr> ...] | SCHIFF <snr> [<snr> ...] | BURG <bnr> [<bnr> ...] )");
cleanup_spell_fixture(&spell);
test_teardown();

View file

@ -1353,6 +1353,13 @@ static void add_seen_nb(faction *f, region *r, seen_mode mode) {
update_interval(f, last);
}
static void add_seen_lighthouse(region *r, faction *f)
{
if (r->terrain->flags & SEA_REGION) {
add_seen_nb(f, r, seen_lighthouse);
}
}
/** mark all regions seen by the lighthouse.
*/
static void prepare_lighthouse_ql(faction *f, selist *rlist) {
@ -1361,9 +1368,7 @@ static void prepare_lighthouse_ql(faction *f, selist *rlist) {
for (ql = rlist, qi = 0; ql; selist_advance(&ql, &qi, 1)) {
region *rl = (region *)selist_get(ql, qi);
if (!fval(rl->terrain, FORBIDDEN_REGION)) {
add_seen_nb(f, rl, seen_lighthouse);
}
add_seen_lighthouse(rl, f);
}
}
@ -1382,9 +1387,7 @@ static void prepare_lighthouse(faction *f, region *r, int range)
assert(n > 0 && n <= 64);
for (i = 0; i != n; ++i) {
region *rl = result[i];
if (!fval(rl->terrain, FORBIDDEN_REGION)) {
add_seen_nb(f, rl, seen_lighthouse);
}
add_seen_lighthouse(rl, f);
}
}
}
@ -1514,24 +1517,23 @@ static void cb_add_seen(region *r, unit *u, void *cbdata) {
}
}
void report_warnings(faction *f, const gamedate *date)
void report_warnings(faction *f, int now)
{
if (f->age < NewbieImmunity()) {
ADDMSG(&f->msgs, msg_message("newbieimmunity", "turns",
NewbieImmunity() - f->age));
}
if (date) {
if (f->race == get_race(RC_INSECT)) {
if (date->season == 0) {
ADDMSG(&f->msgs, msg_message("nr_insectwinter", ""));
}
else {
gamedate next;
get_gamedate(date->turn + 1, &next);
if (next.season == 0) {
ADDMSG(&f->msgs, msg_message("nr_insectfall", ""));
}
if (f->race == get_race(RC_INSECT)) {
gamedate date;
get_gamedate(now + 1, &date);
if (date.season == SEASON_WINTER) {
ADDMSG(&f->msgs, msg_message("nr_insectwinter", ""));
}
else if (date.season == SEASON_AUTUMN) {
if (get_gamedate(now + 2 + 2, &date)->season == SEASON_WINTER) {
ADDMSG(&f->msgs, msg_message("nr_insectfall", ""));
}
}
}
@ -1549,11 +1551,9 @@ void prepare_report(report_context *ctx, faction *f)
static bool rule_region_owners;
static bool rule_lighthouse_units;
const struct building_type *bt_lighthouse = bt_find("lighthouse");
gamedate now;
/* Insekten-Winter-Warnung */
get_gamedate(turn, &now);
report_warnings(f, &now);
report_warnings(f, turn);
if (bt_lighthouse && config_changed(&config)) {
rule_region_owners = config_token("rules.region_owner_pay_building", bt_lighthouse->_name);
@ -1592,8 +1592,8 @@ void prepare_report(report_context *ctx, faction *f)
if (rule_region_owners && f == region_get_owner(r)) {
for (b = rbuildings(r); b; b = b->next) {
if (b && b->type == bt_lighthouse) {
/* region owners get maximm range */
int lhr = lighthouse_range(b, NULL, NULL);
/* region owners get maximum range */
int lhr = lighthouse_view_distance(b, NULL);
if (lhr > range) range = lhr;
}
}
@ -1610,7 +1610,7 @@ void prepare_report(report_context *ctx, faction *f)
*/
if (!fval(r, RF_LIGHTHOUSE)) {
/* it's enough to add the region once, and if there are
* no lighthouses, there is no need to look at more units */
* no lighthouses here, there is no need to look at more units */
break;
}
}
@ -1630,10 +1630,10 @@ void prepare_report(report_context *ctx, faction *f)
/* unit is one of ours, and inside the current lighthouse */
if (br == 0) {
/* lazy-calculate the range */
br = lighthouse_range(u->building, f, u);
}
if (br > range) {
range = br;
br = lighthouse_view_distance(b, u);
if (br > range) {
range = br;
}
}
}
}
@ -2179,10 +2179,10 @@ void report_battle_start(battle * b)
for (df = s->fighters; df; df = df->next) {
if (is_attacker(df)) {
if (first) {
sbs_strcpy(&sbs, ", ");
sbs_strcat(&sbs, ", ");
}
if (lastf) {
sbs_strcpy(&sbs, lastf);
sbs_strcat(&sbs, lastf);
first = true;
}
if (seematrix(f, s))
@ -2193,12 +2193,12 @@ void report_battle_start(battle * b)
}
}
}
if (first) {
sbs_strcat(&sbs, " ");
sbs_strcat(&sbs, LOC(f->locale, "and"));
sbs_strcat(&sbs, " ");
}
if (lastf) {
if (first) {
sbs_strcat(&sbs, " ");
sbs_strcat(&sbs, LOC(f->locale, "and"));
sbs_strcat(&sbs, " ");
}
sbs_strcat(&sbs, lastf);
}

View file

@ -115,7 +115,7 @@ extern "C" {
int size, const struct faction *viewer, bool see_unit);
int report_items(const struct unit *u, struct item *result, int size,
const struct unit *owner, const struct faction *viewer);
void report_warnings(struct faction *f, const struct gamedate *date);
void report_warnings(struct faction *f, int now);
void report_raceinfo(const struct race *rc, const struct locale *lang, char *buf, size_t length);
void report_race_skills(const struct race *rc, char *zText, size_t length, const struct locale *lang);
void report_item(const struct unit *owner, const struct item *i,

View file

@ -496,7 +496,7 @@ void test_prepare_lighthouse_capacity(CuTest *tc) {
u1->number = 4;
u1->building = b;
set_level(u1, SK_PERCEPTION, 3);
CuAssertIntEquals(tc, 1, lighthouse_range(b, u1->faction, u1));
CuAssertIntEquals(tc, 1, lighthouse_view_distance(b, u1));
CuAssertPtrEquals(tc, b, inside_building(u1));
u2 = test_create_unit(f, r1);
u2->building = b;
@ -531,7 +531,7 @@ void test_prepare_lighthouse_capacity(CuTest *tc) {
static void test_prepare_lighthouse(CuTest *tc) {
report_context ctx;
faction *f;
region *r1, *r2, *r3;
region *r1, *r2, *r3, *r4;
unit *u;
building *b;
building_type *btype;
@ -544,6 +544,7 @@ static void test_prepare_lighthouse(CuTest *tc) {
r1 = test_create_region(0, 0, t_plain);
r2 = test_create_region(1, 0, t_ocean);
r3 = test_create_region(2, 0, t_ocean);
r4 = test_create_region(0, 1, t_plain);
btype = test_create_buildingtype("lighthouse");
b = test_create_building(r1, btype);
b->flags |= BLD_MAINTAINED;
@ -558,6 +559,7 @@ static void test_prepare_lighthouse(CuTest *tc) {
CuAssertIntEquals(tc, seen_unit, r1->seen.mode);
CuAssertIntEquals(tc, seen_lighthouse, r2->seen.mode);
CuAssertIntEquals(tc, seen_neighbour, r3->seen.mode);
CuAssertIntEquals(tc, seen_neighbour, r4->seen.mode);
finish_reports(&ctx);
test_teardown();
}
@ -596,7 +598,7 @@ static void test_prepare_lighthouse_owners(CuTest *tc)
u = test_create_unit(test_create_faction(NULL), r1);
u->building = b;
region_set_owner(b->region, f, 0);
CuAssertIntEquals(tc, 2, lighthouse_range(b, NULL, NULL));
CuAssertIntEquals(tc, 2, lighthouse_view_distance(b, NULL));
prepare_report(&ctx, f);
CuAssertPtrEquals(tc, r1, ctx.first);
CuAssertPtrEquals(tc, NULL, ctx.last);
@ -787,19 +789,29 @@ static void test_insect_warnings(CuTest *tc) {
faction *f;
gamedate gd;
/* OBS: in unit tests, get_gamedate always returns season = 0 */
test_setup();
test_create_calendar();
test_inject_messagetypes();
f = test_create_faction(test_create_race("insect"));
gd.turn = 0;
gd.season = 3;
report_warnings(f, &gd);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "nr_insectfall"));
gd.season = 0;
report_warnings(f, &gd);
CuAssertIntEquals(tc, SEASON_AUTUMN, get_gamedate(1083, &gd)->season);
report_warnings(f, gd.turn);
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "nr_insectfall"));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "nr_insectwinter"));
test_clear_messages(f);
CuAssertIntEquals(tc, SEASON_AUTUMN, get_gamedate(1082, &gd)->season);
report_warnings(f, gd.turn);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "nr_insectfall"));
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "nr_insectwinter"));
test_clear_messages(f);
CuAssertIntEquals(tc, SEASON_WINTER, get_gamedate(1084, &gd)->season);
report_warnings(f, gd.turn);
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "nr_insectfall"));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "nr_insectwinter"));
test_clear_messages(f);
test_teardown();
}
@ -808,16 +820,16 @@ static void test_newbie_warning(CuTest *tc) {
test_setup();
test_inject_messagetypes();
f = test_create_faction(test_create_race("insect"));
f = test_create_faction(NULL);
config_set_int("NewbieImmunity", 3);
f->age = 2;
report_warnings(f, NULL);
report_warnings(f, 0);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "newbieimmunity"));
test_clear_messages(f);
f->age = 3;
report_warnings(f, NULL);
report_warnings(f, 0);
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "newbieimmunity"));
test_clear_messages(f);

View file

@ -4072,7 +4072,7 @@ static int sp_pump(castorder * co)
* Betoert eine Einheit, so das sie ihm den groe<EFBFBD>ten Teil ihres Bargelds
* und 50% ihres Besitzes schenkt. Sie behaelt jedoch immer soviel, wie
* sie zum ueberleben braucht. Wirkt gegen Magieresistenz.
* MIN(Stufe*1000$, u->money - maintenace)
* MIN(Stufe*1000$, u->money - maintenance)
* Von jedem Item wird 50% abgerundet ermittelt und uebergeben. Dazu
* kommt Itemzahl%2 mit 50% chance
*
@ -4083,15 +4083,16 @@ static int sp_seduce(castorder * co)
{
const resource_type *rsilver = get_resourcetype(R_SILVER);
unit *target;
item **itmp, *items = 0;
unit *mage = co->magician.u;
item **itmp, *items = NULL;
unit *u, *mage = co->magician.u;
spellparameter *pa = co->par;
int cast_level = co->level;
double force = co->force;
/* wenn kein Ziel gefunden, Zauber abbrechen */
if (pa->param[0]->flag == TARGET_NOTFOUND)
if (pa->param[0]->flag == TARGET_NOTFOUND) {
return 0;
}
target = pa->param[0]->data.u; /* Zieleinheit */
@ -4101,6 +4102,15 @@ static int sp_seduce(castorder * co)
return 0;
}
u = mage;
if (mage->region != target->region) {
for (u = target->region->units; u; u = u->next) {
if (u->faction == mage->faction) {
break;
}
}
}
/* Erfolgsmeldung */
itmp = &target->items;
@ -4113,28 +4123,30 @@ static int sp_seduce(castorder * co)
if (loot < 0) loot = 0;
}
else {
loot = itm->number / 2;
if (itm->number % 2) {
loot += rng_int() % 2;
}
loot = (itm->number + 1) / 2;
if (loot > 0) {
int floot = (int)(5 * force);
if (loot > floot) loot = floot;
}
}
if (loot > 0) {
i_change(&mage->items, itm->type, loot);
i_change(&items, itm->type, loot);
if (u) {
i_change(&u->items, itm->type, loot);
i_change(&items, itm->type, loot);
}
i_change(itmp, itm->type, -loot);
}
if (*itmp == itm)
if (*itmp == itm) {
itmp = &itm->next;
}
}
if (items) {
ADDMSG(&mage->faction->msgs, msg_message("seduce_effect_0", "mage unit items",
mage, target, items));
i_freeall(&items);
if (u) {
ADDMSG(&mage->faction->msgs, msg_message("seduce_effect_0", "mage unit items",
u, target, items));
i_freeall(&items);
}
ADDMSG(&target->faction->msgs, msg_message("seduce_effect_1", "unit",
target));
}

View file

@ -392,19 +392,16 @@ static int try_destruction(unit * u, unit * u2, const ship * sh, int skilldiff)
return 1; /* success */
}
static void sink_ship(region * r, ship * sh, unit * saboteur)
void sink_ship(ship * sh)
{
unit **ui, *u;
region *safety = r;
int i;
direction_t d;
double probability = 0.0;
unit *u;
region *r;
message *sink_msg = NULL;
faction *f;
assert(r);
assert(sh);
assert(saboteur);
assert(sh && sh->region);
r = sh->region;
for (f = NULL, u = r->units; u; u = u->next) {
/* slight optimization to avoid dereferencing u->faction each time */
if (f != u->faction) {
@ -413,76 +410,27 @@ static void sink_ship(region * r, ship * sh, unit * saboteur)
}
}
/* figure out what a unit's chances of survival are: */
if (!(r->terrain->flags & SEA_REGION)) {
probability = CANAL_SWIMMER_CHANCE;
}
else {
for (d = 0; d != MAXDIRECTIONS; ++d) {
region *rn = rconnect(r, d);
if (rn && !(rn->terrain->flags & SEA_REGION) && !move_blocked(NULL, r, rn)) {
safety = rn;
probability = OCEAN_SWIMMER_CHANCE;
break;
}
}
}
for (ui = &r->units; *ui;) {
for (f = NULL, u = r->units; u; u = u->next) {
/* inform this faction about the sinking ship: */
u = *ui;
if (!(u->faction->flags & FFL_SELECT)) {
fset(u->faction, FFL_SELECT);
if (sink_msg == NULL) {
sink_msg = msg_message("sink_msg", "ship region", sh, r);
}
add_message(&f->msgs, sink_msg);
}
if (u->ship == sh) {
int dead = 0;
message *msg;
/* if this fails, I misunderstood something: */
for (i = 0; i != u->number; ++i)
if (chance(probability))
++dead;
if (dead != u->number) {
/* she will live. but her items get stripped */
if (dead > 0) {
msg =
msg_message("sink_lost_msg", "dead region unit", dead, safety, u);
}
else {
msg = msg_message("sink_saved_msg", "region unit", safety, u);
}
leave_ship(u);
if (r != safety) {
setguard(u, false);
}
while (u->items) {
i_remove(&u->items, u->items);
}
move_unit(u, safety, NULL);
}
else {
msg = msg_message("sink_lost_msg", "dead region unit", dead, (region *)NULL, u);
}
add_message(&u->faction->msgs, msg);
msg_release(msg);
if (dead == u->number) {
if (remove_unit(ui, u) == 0) {
/* ui is already pointing at u->next */
continue;
if (f != u->faction) {
f = u->faction;
if (!(f->flags & FFL_SELECT)) {
f->flags |= FFL_SELECT;
if (sink_msg == NULL) {
sink_msg = msg_message("sink_msg", "ship region", sh, r);
}
add_message(&f->msgs, sink_msg);
}
}
}
ui = &u->next;
else if (f != NULL) {
break;
}
}
if (sink_msg)
if (sink_msg) {
msg_release(sink_msg);
/* finally, get rid of the ship */
remove_ship(&sh->region->ships, sh);
}
}
int sabotage_cmd(unit * u, struct order *ord)
@ -514,7 +462,9 @@ int sabotage_cmd(unit * u, struct order *ord)
effskill(u, SK_SPY, 0) - top_skill(u->region, u2->faction, sh, SK_PERCEPTION);
}
if (try_destruction(u, u2, sh, skdiff)) {
sink_ship(u->region, sh, u);
sink_ship(sh);
/* finally, get rid of the ship */
remove_ship(&sh->region->ships, sh);
}
break;
default:

View file

@ -27,6 +27,7 @@ extern "C" {
struct strlist;
struct order;
struct faction;
struct ship;
int setstealth_cmd(struct unit *u, struct order *ord);
int spy_cmd(struct unit *u, struct order *ord);
@ -34,10 +35,7 @@ extern "C" {
void spy_message(int spy, const struct unit *u,
const struct unit *target);
void set_factionstealth(struct unit * u, struct faction * f);
#define OCEAN_SWIMMER_CHANCE 0.1
#define CANAL_SWIMMER_CHANCE 0.9
void sink_ship(struct ship * sh);
#ifdef __cplusplus
}

View file

@ -55,10 +55,6 @@ static void setup_spy(spy_fixture *fix) {
"ship:ship", MT_NEW_END);
mt_create_va(mt_new("sink_msg", NULL),
"ship:ship", "region:region", MT_NEW_END);
mt_create_va(mt_new("sink_lost_msg", NULL),
"unit:unit", "region:region", "dead:int", MT_NEW_END);
mt_create_va(mt_new("sink_saved_msg", NULL),
"unit:unit", "region:region", MT_NEW_END);
if (fix) {
fix->r = test_create_region(0, 0, NULL);
@ -112,6 +108,7 @@ static void test_sabotage_self(CuTest *tc) {
unit *u;
region *r;
order *ord;
message *msg;
test_setup();
setup_spy(NULL);
@ -119,17 +116,49 @@ static void test_sabotage_self(CuTest *tc) {
assert(r);
u = test_create_unit(test_create_faction(NULL), r);
assert(u && u->faction && u->region == r);
u->ship = test_create_ship(r, test_create_shiptype("boat"));
u->ship = test_create_ship(r, NULL);
assert(u->ship);
ord = create_order(K_SABOTAGE, u->faction->locale, "SCHIFF");
assert(ord);
CuAssertIntEquals(tc, 0, sabotage_cmd(u, ord));
CuAssertPtrEquals(tc, 0, r->ships);
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "sink_msg"));
CuAssertPtrEquals(tc, NULL, r->ships);
CuAssertPtrNotNull(tc, msg = test_find_messagetype(u->faction->msgs, "sink_msg"));
CuAssertPtrEquals(tc, NULL, test_find_messagetype_ex(u->faction->msgs, "sink_msg", msg));
free_order(ord);
test_teardown();
}
static void test_sink_ship(CuTest *tc) {
ship *sh;
unit *u1, *u2, *u3;
region *r;
message *msg;
test_setup();
setup_spy(NULL);
r = test_create_ocean(0, 0);
u1 = test_create_unit(test_create_faction(NULL), r);
u2 = test_create_unit(u1->faction, r);
u3 = test_create_unit(test_create_faction(NULL), r);
u1->ship = u2->ship = u3->ship = sh = test_create_ship(r, NULL);
sink_ship(sh);
CuAssertPtrEquals(tc, r, sh->region);
CuAssertPtrEquals(tc, sh, r->ships);
CuAssertPtrNotNull(tc, msg = test_find_messagetype(u1->faction->msgs, "sink_msg"));
CuAssertPtrEquals(tc, NULL, test_find_messagetype_ex(u1->faction->msgs, "sink_msg", msg));
CuAssertPtrNotNull(tc, msg = test_find_messagetype(u3->faction->msgs, "sink_msg"));
CuAssertPtrEquals(tc, NULL, test_find_messagetype_ex(u3->faction->msgs, "sink_msg", msg));
remove_ship(&r->ships, sh);
CuAssertPtrEquals(tc, NULL, sh->region);
CuAssertPtrEquals(tc, NULL, r->ships);
CuAssertPtrEquals(tc, NULL, u1->ship);
CuAssertPtrEquals(tc, NULL, u2->ship);
CuAssertPtrEquals(tc, NULL, u3->ship);
test_teardown();
}
static void test_sabotage_other_fail(CuTest *tc) {
unit *u, *u2;
@ -145,7 +174,7 @@ static void test_sabotage_other_fail(CuTest *tc) {
u = test_create_unit(test_create_faction(NULL), r);
u2 = test_create_unit(test_create_faction(NULL), r);
assert(u && u2);
u2->ship = test_create_ship(r, test_create_shiptype("boat"));
u2->ship = test_create_ship(r, NULL);
assert(u2->ship);
u->ship = u2->ship;
ship_update_owner(u->ship);
@ -167,7 +196,7 @@ static void test_setstealth_cmd(CuTest *tc) {
const struct locale *lang;
test_setup();
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0));
lang = u->faction->locale;
u->flags = UFL_ANON_FACTION | UFL_SIEGE;
u->thisorder = create_order(K_SETSTEALTH, lang, "%s %s",
@ -191,7 +220,7 @@ static void test_setstealth_demon(CuTest *tc) {
test_setup();
lang = test_create_locale();
rc = test_create_race("demon");
u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, NULL));
u = test_create_unit(test_create_faction(rc), test_create_plain(0, 0));
rc = test_create_race("dwarf");
init_races(lang);
u->thisorder = create_order(K_SETSTEALTH, lang, racename(lang, u, rc));
@ -208,7 +237,7 @@ static void test_setstealth_demon_bad(CuTest *tc) {
test_setup();
lang = test_create_locale();
rc = test_create_race("demon");
u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, NULL));
u = test_create_unit(test_create_faction(rc), test_create_plain(0, 0));
rc = test_create_race("smurf");
rc->flags &= ~RCF_PLAYABLE;
@ -232,7 +261,7 @@ static void test_sabotage_other_success(CuTest *tc) {
u = test_create_unit(test_create_faction(NULL), r);
u2 = test_create_unit(test_create_faction(NULL), r);
assert(u && u2);
u2->ship = test_create_ship(r, test_create_shiptype("boat"));
u2->ship = test_create_ship(r, NULL);
assert(u2->ship);
u->ship = u2->ship;
ship_update_owner(u->ship);
@ -251,6 +280,7 @@ CuSuite *get_spy_suite(void)
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_simple_spy_message);
SUITE_ADD_TEST(suite, test_all_spy_message);
SUITE_ADD_TEST(suite, test_sink_ship);
SUITE_ADD_TEST(suite, test_sabotage_self);
SUITE_ADD_TEST(suite, test_setstealth_cmd);
SUITE_ADD_TEST(suite, test_setstealth_demon);

View file

@ -69,7 +69,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define TEACH_ALL 1
#define TEACH_FRIENDS
static skill_t getskill(const struct locale *lang)
skill_t getskill(const struct locale *lang)
{
char token[128];
const char * s = gettoken(token, sizeof(token));
@ -195,37 +195,37 @@ const attrib_type at_learning = {
#define EXPERIENCEDAYS 10
static int study_days(unit * student, skill_t sk)
static int study_days(unit * scholar, skill_t sk)
{
int speed = STUDYDAYS;
if (u_race(student)->study_speed) {
speed += u_race(student)->study_speed[sk];
if (u_race(scholar)->study_speed) {
speed += u_race(scholar)->study_speed[sk];
if (speed < STUDYDAYS) {
skill *sv = unit_skill(student, sk);
skill *sv = unit_skill(scholar, sk);
if (sv == 0) {
speed = STUDYDAYS;
}
}
}
return student->number * speed;
return scholar->number * speed;
}
static int
teach_unit(unit * teacher, unit * student, int nteaching, skill_t sk,
teach_unit(unit * teacher, unit * scholar, int nteaching, skill_t sk,
bool report, int *academy_students)
{
teaching_info *teach = NULL;
attrib *a;
int students;
if (magic_lowskill(student)) {
if (magic_lowskill(scholar)) {
cmistake(teacher, teacher->thisorder, 292, MSG_EVENT);
return 0;
}
students = student->number;
students = scholar->number;
/* subtract already taught students */
a = a_find(student->attribs, &at_learning);
a = a_find(scholar->attribs, &at_learning);
if (a != NULL) {
teach = (teaching_info *)a->data.v;
students -= teach->students;
@ -235,18 +235,18 @@ teach_unit(unit * teacher, unit * student, int nteaching, skill_t sk,
if (students > 0) {
if (teach == NULL) {
a = a_add(&student->attribs, a_new(&at_learning));
a = a_add(&scholar->attribs, a_new(&at_learning));
teach = (teaching_info *)a->data.v;
}
selist_push(&teach->teachers, teacher);
teach->days += students * STUDYDAYS;
teach->students += students;
if (student->building && teacher->building == student->building) {
if (scholar->building && teacher->building == scholar->building) {
/* Solange Akademien groessenbeschraenkt sind, sollte Lehrer und
* Student auch in unterschiedlichen Gebaeuden stehen duerfen */
/* FIXME comment contradicts implementation */
if (academy_can_teach(teacher, student, sk)) {
if (academy_can_teach(teacher, scholar, sk)) {
/* Jeder Schueler zusaetzlich +10 Tage wenn in Uni. */
teach->days += students * EXPERIENCEDAYS; /* learning erhoehen */
/* Lehrer zusaetzlich +1 Tag pro Schueler. */
@ -304,7 +304,7 @@ int teach_cmd(unit * teacher, struct order *ord)
#if TEACH_ALL
if (getparam(teacher->faction->locale) == P_ANY) {
skill_t sk;
unit *student;
unit *scholar;
skill_t teachskill[MAXSKILLS];
int t = 0;
@ -313,15 +313,15 @@ int teach_cmd(unit * teacher, struct order *ord)
teachskill[t] = getskill(teacher->faction->locale);
} while (sk != NOSKILL);
for (student = r->units; teaching > 0 && student; student = student->next) {
if (LongHunger(student)) {
for (scholar = r->units; teaching > 0 && scholar; scholar = scholar->next) {
if (LongHunger(scholar)) {
continue;
}
else if (student->faction == teacher->faction) {
if (getkeyword(student->thisorder) == K_STUDY) {
else if (scholar->faction == teacher->faction) {
if (getkeyword(scholar->thisorder) == K_STUDY) {
/* Input ist nun von student->thisorder !! */
init_order(student->thisorder, student->faction->locale);
sk = getskill(student->faction->locale);
init_order(scholar->thisorder, scholar->faction->locale);
sk = getskill(scholar->faction->locale);
if (sk != NOSKILL && teachskill[0] != NOSKILL) {
for (t = 0; teachskill[t] != NOSKILL; ++t) {
if (sk == teachskill[t]) {
@ -331,20 +331,20 @@ int teach_cmd(unit * teacher, struct order *ord)
sk = teachskill[t];
}
if (sk != NOSKILL
&& effskill_study(teacher, sk, 0) - TEACHDIFFERENCE > effskill_study(student, sk, 0)) {
teaching -= teach_unit(teacher, student, teaching, sk, true, &academy_students);
&& effskill_study(teacher, sk) - TEACHDIFFERENCE > effskill_study(scholar, sk)) {
teaching -= teach_unit(teacher, scholar, teaching, sk, true, &academy_students);
}
}
}
#ifdef TEACH_FRIENDS
else if (alliedunit(teacher, student->faction, HELP_GUARD)) {
if (getkeyword(student->thisorder) == K_STUDY) {
else if (alliedunit(teacher, scholar->faction, HELP_GUARD)) {
if (getkeyword(scholar->thisorder) == K_STUDY) {
/* Input ist nun von student->thisorder !! */
init_order(student->thisorder, student->faction->locale);
sk = getskill(student->faction->locale);
init_order(scholar->thisorder, scholar->faction->locale);
sk = getskill(scholar->faction->locale);
if (sk != NOSKILL
&& effskill_study(teacher, sk, 0) - TEACHDIFFERENCE >= effskill(student, sk, 0)) {
teaching -= teach_unit(teacher, student, teaching, sk, true, &academy_students);
&& effskill_study(teacher, sk) - TEACHDIFFERENCE >= effskill(scholar, sk, NULL)) {
teaching -= teach_unit(teacher, scholar, teaching, sk, true, &academy_students);
}
}
}
@ -363,15 +363,15 @@ int teach_cmd(unit * teacher, struct order *ord)
while (!parser_end()) {
skill_t sk;
unit *student;
unit *scholar;
bool feedback;
getunit(r, teacher->faction, &student);
getunit(r, teacher->faction, &scholar);
++count;
/* Falls die Unit nicht gefunden wird, Fehler melden */
if (!student) {
if (!scholar) {
char tbuf[20];
const char *uid;
const char *token;
@ -403,8 +403,8 @@ int teach_cmd(unit * teacher, struct order *ord)
continue;
}
feedback = teacher->faction == student->faction
|| alliedunit(student, teacher->faction, HELP_GUARD);
feedback = teacher->faction == scholar->faction
|| alliedunit(scholar, teacher->faction, HELP_GUARD);
/* Neuen Befehl zusammenbauen. TEMP-Einheiten werden automatisch in
* ihre neuen Nummern uebersetzt. */
@ -412,31 +412,31 @@ int teach_cmd(unit * teacher, struct order *ord)
strncat(zOrder, " ", sz - 1);
--sz;
}
sz -= str_strlcpy(zOrder + 4096 - sz, itoa36(student->no), sz);
sz -= str_strlcpy(zOrder + 4096 - sz, itoa36(scholar->no), sz);
if (getkeyword(student->thisorder) != K_STUDY) {
if (getkeyword(scholar->thisorder) != K_STUDY) {
ADDMSG(&teacher->faction->msgs,
msg_feedback(teacher, ord, "teach_nolearn", "student", student));
msg_feedback(teacher, ord, "teach_nolearn", "student", scholar));
continue;
}
/* Input ist nun von student->thisorder !! */
parser_pushstate();
init_order(student->thisorder, student->faction->locale);
sk = getskill(student->faction->locale);
init_order(scholar->thisorder, scholar->faction->locale);
sk = getskill(scholar->faction->locale);
parser_popstate();
if (sk == NOSKILL) {
ADDMSG(&teacher->faction->msgs,
msg_feedback(teacher, ord, "teach_nolearn", "student", student));
msg_feedback(teacher, ord, "teach_nolearn", "student", scholar));
continue;
}
if (effskill_study(student, sk, 0) > effskill_study(teacher, sk, 0)
if (effskill_study(scholar, sk) > effskill_study(teacher, sk)
- TEACHDIFFERENCE) {
if (feedback) {
ADDMSG(&teacher->faction->msgs, msg_feedback(teacher, ord, "teach_asgood",
"student", student));
"student", scholar));
}
continue;
}
@ -444,18 +444,18 @@ int teach_cmd(unit * teacher, struct order *ord)
/* ist der Magier schon spezialisiert, so versteht er nur noch
* Lehrer seines Gebietes */
sc_mage *mage1 = get_mage_depr(teacher);
sc_mage *mage2 = get_mage_depr(student);
sc_mage *mage2 = get_mage_depr(scholar);
if (mage2 && mage1 && mage2->magietyp != M_GRAY
&& mage1->magietyp != mage2->magietyp) {
if (feedback) {
ADDMSG(&teacher->faction->msgs, msg_feedback(teacher, ord,
"error_different_magic", "target", student));
"error_different_magic", "target", scholar));
}
continue;
}
}
sk_academy = sk;
teaching -= teach_unit(teacher, student, teaching, sk, false, &academy_students);
teaching -= teach_unit(teacher, scholar, teaching, sk, false, &academy_students);
}
new_order = create_order(K_TEACH, teacher->faction->locale, "%s", zOrder);
replace_order(&teacher->orders, ord, new_order);
@ -766,9 +766,6 @@ int study_cmd(unit * u, order * ord)
days *= 2;
}
if (fval(u, UFL_HUNGER))
days /= 2;
learn_skill(u, sk, days);
if (a != NULL) {
if (teach->teachers) {
@ -832,6 +829,9 @@ void learn_skill(unit *u, skill_t sk, int days) {
int leveldays = STUDYDAYS * u->number;
int weeks = 0;
if (fval(u, UFL_HUNGER)) {
days /= 2;
}
assert(sk >= 0 && sk < MAXSKILLS);
if (inject_learn_fun) {
inject_learn_fun(u, sk, days);

View file

@ -33,6 +33,7 @@ extern "C" {
int study_cmd(struct unit *u, struct order *ord);
magic_t getmagicskill(const struct locale *lang);
skill_t getskill(const struct locale *lang);
bool is_migrant(struct unit *u);
int study_cost(struct unit *u, skill_t talent);

View file

@ -89,15 +89,15 @@ static void setup_teacher(study_fixture *fix, skill_t sk) {
setup_locale(lang);
fix->u = test_create_unit(f, r);
assert(fix->u);
fix->u->thisorder = create_order(K_STUDY, f->locale, "%s", skillnames[sk]);
fix->u->thisorder = create_order(K_STUDY, f->locale, skillnames[sk]);
fix->teachers[0] = test_create_unit(f, r);
assert(fix->teachers[0]);
fix->teachers[0]->thisorder = create_order(K_TEACH, f->locale, "%s", itoa36(fix->u->no));
fix->teachers[0]->thisorder = create_order(K_TEACH, f->locale, itoa36(fix->u->no));
fix->teachers[1] = test_create_unit(f, r);
assert(fix->teachers[1]);
fix->teachers[1]->thisorder = create_order(K_TEACH, f->locale, "%s", itoa36(fix->u->no));
fix->teachers[1]->thisorder = create_order(K_TEACH, f->locale, itoa36(fix->u->no));
test_clear_messages(f);
}
@ -110,7 +110,7 @@ static void test_study_no_teacher(CuTest *tc) {
CuAssertPtrNotNull(tc, sv = unit_skill(fix.u, SK_CROSSBOW));
CuAssertIntEquals(tc, 1, sv->level);
CuAssertIntEquals(tc, 2, sv->weeks);
CuAssertPtrEquals(tc, 0, test_get_last_message(fix.u->faction->msgs));
CuAssertPtrEquals(tc, NULL, test_get_last_message(fix.u->faction->msgs));
test_teardown();
}
@ -121,7 +121,7 @@ static void test_study_with_teacher(CuTest *tc) {
setup_teacher(&fix, SK_CROSSBOW);
set_level(fix.teachers[0], SK_CROSSBOW, TEACHDIFFERENCE);
teach_cmd(fix.teachers[0], fix.teachers[0]->thisorder);
CuAssertPtrEquals(tc, 0, test_get_last_message(fix.u->faction->msgs));
CuAssertPtrEquals(tc, NULL, test_get_last_message(fix.u->faction->msgs));
study_cmd(fix.u, fix.u->thisorder);
CuAssertPtrNotNull(tc, sv = unit_skill(fix.u, SK_CROSSBOW));
CuAssertIntEquals(tc, 1, sv->level);
@ -288,7 +288,7 @@ static void test_academy_bonus(CuTest *tc) {
u1 = test_create_unit(u->faction, u->region);
u3 = test_create_unit(u->faction, u->region);
u0->thisorder = create_order(K_TEACH, loc, "%s %s", itoa36(u3->no), itoa36(u1->no));
u->thisorder = create_order(K_TEACH, loc, "%s", itoa36(u1->no));
u->thisorder = create_order(K_TEACH, loc, itoa36(u1->no));
u1->thisorder = create_order(K_STUDY, loc, skillnames[SK_CROSSBOW]);
u3->thisorder = create_order(K_STUDY, loc, skillnames[SK_CROSSBOW]);
@ -405,7 +405,7 @@ static void test_study_magic(CuTest *tc) {
f = test_create_faction(NULL);
lang = f->locale;
u = test_create_unit(f, test_create_region(0, 0, NULL));
u->thisorder = create_order(K_STUDY, lang, "%s", skillnames[SK_MAGIC]);
u->thisorder = create_order(K_STUDY, lang, skillnames[SK_MAGIC]);
itype = test_create_silver();
CuAssertIntEquals(tc, -1, study_cmd(u, u->thisorder));
@ -423,7 +423,7 @@ static void test_study_magic(CuTest *tc) {
CuAssertIntEquals(tc, M_GWYRRD, f->magiegebiet);
CuAssertIntEquals(tc, 0, i_get(u->items, itype));
CuAssertPtrNotNull(tc, get_mage_depr(u));
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error65"));
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error65"));
CuAssertIntEquals(tc, M_GWYRRD, get_mage_depr(u)->magietyp);
test_teardown();
@ -491,12 +491,12 @@ static void test_teach_magic(CuTest *tc) {
f = test_create_faction(NULL);
f->magiegebiet = M_GWYRRD;
u = test_create_unit(f, test_create_region(0, 0, NULL));
u->thisorder = create_order(K_STUDY, f->locale, "%s", skillnames[SK_MAGIC]);
u->thisorder = create_order(K_STUDY, f->locale, skillnames[SK_MAGIC]);
i_change(&u->items, itype, study_cost(u, SK_MAGIC));
ut = test_create_unit(f, u->region);
set_level(ut, SK_MAGIC, TEACHDIFFERENCE);
create_mage(ut, M_GWYRRD);
ut->thisorder = create_order(K_TEACH, f->locale, "%s", itoa36(u->no));
ut->thisorder = create_order(K_TEACH, f->locale, itoa36(u->no));
learn_inject();
teach_cmd(ut, ut->thisorder);
study_cmd(u, u->thisorder);

View file

@ -93,7 +93,6 @@ int RunAllTests(int argc, char *argv[])
ADD_SUITE(xerewards);
/* kernel */
ADD_SUITE(academy);
ADD_SUITE(alchemy);
ADD_SUITE(alliance);
ADD_SUITE(ally);
ADD_SUITE(building);
@ -121,6 +120,8 @@ int RunAllTests(int argc, char *argv[])
ADD_SUITE(spells);
ADD_SUITE(unit);
/* gamecode */
ADD_SUITE(alchemy);
ADD_SUITE(automate);
ADD_SUITE(battle);
ADD_SUITE(calendar);
ADD_SUITE(creport);

View file

@ -260,6 +260,21 @@ static void test_reset(void) {
}
}
void test_create_calendar(void) {
config_set_int("game.start", 184);
months_per_year = 9;
month_season = malloc(sizeof(int) * months_per_year);
month_season[0] = SEASON_SUMMER;
month_season[1] = SEASON_AUTUMN;
month_season[2] = SEASON_AUTUMN;
month_season[3] = SEASON_WINTER;
month_season[4] = SEASON_WINTER;
month_season[5] = SEASON_WINTER;
month_season[6] = SEASON_SPRING;
month_season[7] = SEASON_SPRING;
month_season[8] = SEASON_SUMMER;
}
void test_inject_messagetypes(void)
{
message_handle_missing(MESSAGE_MISSING_REPLACE);

View file

@ -40,6 +40,7 @@ extern "C" {
struct log_t * test_log_start(int flags, struct strlist **slist);
void test_log_stop(struct log_t *log, struct strlist *slist);
void test_create_calendar(void);
struct locale * test_create_locale(void);
struct terrain_type * test_create_terrain(const char * name, int flags);
struct race *test_create_race(const char *name);

BIN
src/util/.DS_Store vendored Normal file

Binary file not shown.

View file

@ -66,6 +66,7 @@ int pofile_read(const char *filename, int (*callback)(const char *msgid, const c
if (!F) {
log_error("could not open %s", filename);
return -1;
}
msgctxt[0] = 0;
@ -106,10 +107,10 @@ int pofile_read(const char *filename, int (*callback)(const char *msgid, const c
line = read_line(F);
}
}
if (ferror(F)) {
log_error("read error in %s:%d.", filename, po_lineno);
return -1;
}
err = ferror(F);
fclose(F);
if (err) {
log_error("read error %d in %s:%d.", err, filename, po_lineno);
}
return err;
}

View file

@ -275,6 +275,11 @@ void sbs_strcpy(struct sbstring *sbs, const char *str)
sbs->end = sbs->begin + len;
}
size_t sbs_length(const struct sbstring *sbs)
{
return sbs->end - sbs->begin;
}
char *str_unescape(char *str) {
char *read = str, *write = str;
while (*read) {

View file

@ -50,6 +50,7 @@ extern "C" {
void sbs_strcat(struct sbstring *sbs, const char *str);
void sbs_strncat(struct sbstring *sbs, const char *str, size_t size);
void sbs_strcpy(struct sbstring *sbs, const char *str);
size_t sbs_length(const struct sbstring *sbs);
/* benchmark for units:
* JENKINS_HASH: 5.25 misses/hit (with good cache behavior)

View file

@ -54,11 +54,11 @@ assert_grep_count reports/$CRFILE '^EINHEIT' 2
assert_grep_count reports/$CRFILE '^GEGENSTAENDE' 2
assert_grep_count reports/185-heg.cr '185;Runde' 1
assert_grep_count reports/185-heg.cr ';Baeume' 4
assert_grep_count reports/185-heg.cr '"B.ume";type' 4
assert_grep_count reports/185-heg.cr '"Pferde";type' 6
assert_grep_count reports/185-heg.nr 'erblickt' 6
assert_grep_count reports/185-heg.cr '"lighthouse";visibility' 6
assert_grep_count reports/185-heg.cr ';Baeume' 2
assert_grep_count reports/185-heg.cr '"B.ume";type' 2
assert_grep_count reports/185-heg.cr '"Pferde";type' 2
assert_grep_count reports/185-heg.nr 'erblickt' 2
assert_grep_count reports/185-heg.cr '"lighthouse";visibility' 2
assert_grep_count reports/185-heg.cr '"neighbour";visibility' 11
assert_grep_count reports/185-6rLo.cr '^EINHEIT' 2
assert_grep_count reports/185-6rLo.cr '^REGION' 13

View file

@ -19,7 +19,7 @@ done
#set -e
cd $ROOT/tests
setup
#cleanup
cleanup
VALGRIND=`which valgrind`
TESTS=../Debug/eressea/test_eressea
SERVER=../Debug/eressea/eressea