Merge branch 'develop' into bug2480

This commit is contained in:
Enno Rehling 2018-10-13 20:25:13 +02:00 committed by GitHub
commit 92c6fb9bac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
257 changed files with 5060 additions and 2094 deletions

View file

@ -24,3 +24,8 @@ indent_style = tab
[.travis.yml]
indent_style = space
indent_size = 2
# Matches exact files
[CMakeLists.txt]
indent_style = space
indent_size = 2

2
.gitignore vendored
View file

@ -25,6 +25,7 @@ ipch/
*.user
*~
*.pyc
*.bak
bin/
build*/
@ -36,6 +37,7 @@ Thumbs.db
*.cfg
*.cmd
tmp/
tests/orders.txt
tests/config.lua
tests/reports/
tests/data/185.dat

View file

@ -8,6 +8,7 @@ addons:
apt:
packages:
- libbsd-dev
- libdb-dev
- liblua5.1-dev
- libtolua-dev
- libncurses5-dev

2
clibs

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

View file

@ -28,7 +28,6 @@
"stealth",
"taxation",
"trade",
"besiege",
"steal",
"buy",
"teach",

View file

@ -12,7 +12,6 @@
"work": [ "ARBEITE", "ARBEITEN" ],
"attack": ["ATTACKIERE", "ATTACKIEREN"],
"steal": [ "BEKLAUE", "BEKLAUEN" ],
"besiege": ["BELAGERE", "BELAGERN" ],
"name": [ "BENENNE", "BENENNEN" ],
"use": [ "BENUTZE", "BENUTZEN" ],
"describe": [ "BESCHREIBE", "BESCHREIBEN" ],

View file

@ -1,7 +1,7 @@
install(PROGRAMS create-orders backup-eressea run-turn send-zip-report
send-bz2-report compress.py compress.sh epasswd.py orders-process
process-orders.py accept-orders.py
checkpasswd.py sendreport.sh sendreports.sh orders-accept DESTINATION bin)
process-orders.py accept-orders.py getemail.py checkpasswd.py
sendreport.sh sendreports.sh orders-accept DESTINATION bin)
install(DIRECTORY cron/ DESTINATION bin USE_SOURCE_PERMISSIONS
FILES_MATCHING PATTERN "*.cron")

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

@ -6,14 +6,19 @@ from epasswd import EPasswd
if len(sys.argv)<4:
sys.exit(-2)
passfile=sys.argv[1]
filename=sys.argv[1]
myfaction=sys.argv[2]
mypasswd=sys.argv[3]
if mypasswd[0]=='"':
mypasswd=mypasswd[1:len(mypasswd)-1]
if mypasswd[0] == '"':
mypasswd = mypasswd.strip('"')
pw_data = EPasswd()
try:
pw_data.load_database(filename)
except:
pw_data.load_file(filename)
pw_data=EPasswd(passfile)
if pw_data.fac_exists(myfaction):
if pw_data.check(myfaction, mypasswd):
sys.exit(0)

View file

@ -16,6 +16,7 @@ else
mv orders.dir "orders.dir.$TURN"
mkdir -p orders.dir
fi
rm -f "orders.$TURN"
find "orders.dir.$TURN" -maxdepth 1 -type f -printf "%T+\t%p\n" | sort | cut -f2 | while read -r
do
cat "$REPLY" >> "orders.$TURN"
@ -23,7 +24,7 @@ done
lockfile -r3 -l120 orders.queue.lock
if [ -e orders.queue ] ; then
mv orders.queue "orders.dir.$TURN/orders.queue"
mv orders.queue "orders.queue.bak.$TURN"
fi
rm -f orders.queue.lock

View file

@ -4,47 +4,82 @@ from string import split
from string import strip
from string import lower
import subprocess
import bcrypt
import sqlite3
def baseconvert(n, base):
"""convert positive decimal integer n to equivalent in another base (2-36)"""
digits = "0123456789abcdefghijkLmnopqrstuvwxyz"
try:
n = int(n)
base = int(base)
except:
return ""
if n < 0 or base < 2 or base > 36:
return ""
s = ""
while True:
r = n % base
s = digits[r] + s
n = n / base
if n == 0:
break
return s
class EPasswd:
def _check_apr1(self, pwhash, pw):
spl = split(pwhash, '$')
salt = spl[2]
hash = subprocess.check_output(['openssl', 'passwd', '-apr1', '-salt', salt, pw]).decode('utf-8').strip()
return hash==pwhash
def __init__(self):
self.data = {}
def __init__(self, file):
self.data = {}
try:
fp = open(file,"r")
except:
fp = None
if fp != None:
while True:
line = fp.readline()
if not line: break
line = strip(line)
[id, email, passwd] = split(line, ":")[0:3]
lc_id = lower(id)
self.data[lc_id] = {}
self.data[lc_id]["id"] = id
self.data[lc_id]["email"] = email
self.data[lc_id]["passwd"] = passwd
fp.close()
def set_data(self, no, email, passwd):
lc_id = lower(no)
self.data[lc_id] = {}
self.data[lc_id]["id"] = no
self.data[lc_id]["email"] = email
self.data[lc_id]["passwd"] = passwd
def check(self, id, passwd):
pw = self.get_passwd(id)
if pw[0:6]=='$apr1$':
return self._check_apr1(pw, passwd)
return pw == passwd
def load_database(self, file):
conn = sqlite3.connect(file)
c = conn.cursor()
c.execute('SELECT MAX(turn) FROM factions')
args = c.fetchone()
for row in c.execute('SELECT no, email, password FROM factions WHERE turn=?', args):
(no, email, passwd) = row
self.set_data(baseconvert(no, 36), email, passwd)
conn.close()
def get_passwd(self, id):
return self.data[lower(id)]["passwd"]
def load_file(self, file):
try:
fp = open(file,"r")
except:
fp = None
if fp != None:
while True:
line = fp.readline()
if not line: break
line = strip(line)
[id, email, passwd] = split(line, ":")[0:3]
self.set_data(id, email, passwd)
fp.close()
def get_email(self, id):
return self.data[lower(id)]["email"]
def check(self, id, passwd):
pw = self.get_passwd(id)
if pw[0:4]=='$2a$' or pw[0:4]=='$2y$':
return bcrypt.checkpw(passwd, pw)
return pw == passwd
def get_canon_id(self, id):
return self.data[lower(id)]["id"]
def get_passwd(self, id):
return self.data[lower(id)]["passwd"]
def fac_exists(self, id):
return self.data.has_key(lower(id))
def get_email(self, id):
return self.data[lower(id)]["email"]
def get_canon_id(self, id):
return self.data[lower(id)]["id"]
def fac_exists(self, id):
return self.data.has_key(lower(id))

22
process/getemail.py Executable file
View file

@ -0,0 +1,22 @@
#!/usr/bin/env python
import sys, re
from epasswd import EPasswd
if len(sys.argv)<3:
sys.exit(-2)
filename=sys.argv[1]
myfaction=sys.argv[2]
pw_data = EPasswd()
try:
pw_data.load_database(filename)
except:
pw_data.load_file(filename)
if pw_data.fac_exists(myfaction):
email = pw_data.get_email(myfaction)
print(email)
sys.exit(0)
sys.exit(-1)

View file

@ -128,7 +128,11 @@ def echeck(filename, locale, rules):
return mail
#print "reading password file..."
pw_data = EPasswd(os.path.join(game_dir,"passwd"))
pw_data = EPasswd()
try:
pw_data.load_database(os.path.join(game_dir,"eressea.db"))
except:
pw_data.load_file(os.path.join(game_dir,"passwd"))
#print "reading orders.queue..."
# move the queue file to a save space while locking it:

View file

@ -2,26 +2,6 @@
## Eressea Reportversand
##
:0:server.lock
* ^Subject:.*ERE.*2.*PASSWOR.*
| sendpassword.py $HOME/eressea/game-2/passwd
:0:server.lock
* ^Subject:.*ERE.*3.*PASSWOR.*
| sendpassword.py $HOME/eressea/game-3/passwd
:0:server.lock
* ^Subject:.*ERE.*4.*PASSWOR.*
| sendpassword.py $HOME/eressea/game-4/passwd
:0:server.lock
* ^Subject:.*ERE.*PASSWOR.*
| sendpassword.py $HOME/eressea/game-2/passwd
:0:server.lock
* ^Subject:.*E3.*PASSWOR.*
| sendpassword.py $HOME/eressea/game-3/passwd
:0:server.lock
* ^Subject:.*ERE.*2.*REPORT \/.*
* !From: .*eressea.*@eressea.de

View file

@ -30,7 +30,11 @@ LOCKFILE="$ERESSEA/.report.lock"
echo "$(date):report:$GAME:$EMAIL:$FACTION:$PASSWD" >> "$ERESSEA/request.log"
cd "$ERESSEA" || exit
checkpasswd.py "game-$GAME/passwd" "$FACTION" "$PASSWD" || reply "Das Passwort fuer die Partei $FACTION ist ungueltig"
PWFILE="game-$GAME/eressea.db"
if [ ! -e "$PWFILE" ]; then
PWFILE="game-$GAME/passwd"
fi
checkpasswd.py "$PWFILE" "$FACTION" "$PASSWD" || reply "Das Passwort fuer die Partei $FACTION ist ungueltig"
cd "$ERESSEA/game-$GAME/reports" || exit
if [ ! -e "${FACTION}.sh" ]; then
@ -41,12 +45,8 @@ fi
bash "${FACTION}.sh" "$EMAIL" || reply "Unbekannte Partei $FACTION"
if [ -e "$ERESSEA/game-$GAME/eressea.db" ]; then
SQL="select email from faction f left join faction_data fd on fd.faction_id=f.id where f.game_id=$GAME AND fd.code='$FACTION' and fd.turn=(select max(turn) from faction_data fx where fx.faction_id=f.id)"
OWNER=$(sqlite3 "$ERESSEA/game-$GAME/eressea.db" "$SQL")
if [ ! -z "$OWNER" ]; then
echo "Der Report Deiner Partei wurde an ${EMAIL} gesandt." \
| mutt -s "Reportnachforderung Partei ${FACTION}" "$OWNER"
fi
OWNER=$(getfaction.py "$PWFILE" "$FACTION")
if [ ! -z "$OWNER" ]; then
echo "Der Report Deiner Partei wurde an ${EMAIL} gesandt." \
| mutt -s "Reportnachforderung Partei ${FACTION}" "$OWNER"
fi

View file

@ -30,7 +30,7 @@
</type>
</message>
<message name="target_region_invalid">
<message name="target_region_invalid" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
@ -38,7 +38,7 @@
</type>
</message>
<message name="missing_direction">
<message name="missing_direction" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
@ -46,7 +46,7 @@
</type>
</message>
<message name="target_region_not_empty">
<message name="target_region_not_empty" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
@ -710,12 +710,6 @@
<arg name="dir" type="direction"/>
</type>
</message>
<message name="nr_building_besieged" section="nr">
<type>
<arg name="soldiers" type="int"/>
<arg name="diff" type="int"/>
</type>
</message>
<message name="newbie_password" section="events">
<type>
@ -2684,19 +2678,6 @@
<arg name="want" type="int"/>
</type>
</message>
<message name="siege_catapults" section="events">
<type>
<arg name="unit" type="unit"/>
<arg name="building" type="building"/>
<arg name="destruction" type="int"/>
</type>
</message>
<message name="siege" section="events">
<type>
<arg name="unit" type="unit"/>
<arg name="building" type="building"/>
</type>
</message>
<message name="drown_on_ship" section="events">
<type>
<arg name="unit" type="unit"/>
@ -3351,14 +3332,6 @@
<arg name="command" type="order"/>
</type>
</message>
<message name="entrance_besieged" section="events">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
<arg name="building" type="building"/>
</type>
</message>
<message name="entrance_denied" section="events">
<type>
<arg name="unit" type="unit"/>
@ -3890,13 +3863,6 @@
<arg name="command" type="order"/>
</type>
</message>
<message name="error166" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
</type>
</message>
<message name="error165" section="errors">
<type>
<arg name="unit" type="unit"/>
@ -4002,13 +3968,6 @@
<arg name="command" type="order"/>
</type>
</message>
<message name="error60" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
</type>
</message>
<message name="error151" section="errors">
<type>
<arg name="unit" type="unit"/>
@ -4993,20 +4952,6 @@
<arg name="command" type="order"/>
</type>
</message>
<message name="error24" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
</type>
</message>
<message name="error23" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
</type>
</message>
<message name="error22" section="errors">
<type>
<arg name="unit" type="unit"/>

View file

@ -257,9 +257,6 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - Hier kann man k
msgid "error165"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Der Trank bekommt der Einheit nicht.\""
msgid "siege_catapults"
msgstr "\"$unit($unit) belagert $building($building). Dabei richten die Katapulte Zerstörungen von $int($destruction) Größenpunkten an.\""
msgid "curseinfo::magicstreet"
msgstr "\"Die Straßen sind erstaunlich trocken und gut begehbar. ($int36($id))\""
@ -638,9 +635,6 @@ msgstr "\"$unit($unit) erscheint plötzlich.\""
msgid "magicresistance_effect"
msgstr "\"$unit($unit) wird kurz von einem magischen Licht umhüllt.\""
msgid "siege"
msgstr "\"$unit($unit) belagert $building($building).\""
msgid "missing_force"
msgstr "\"$unit($unit) schafft es nicht, genug Kraft aufzubringen, um $spell($spell) auf Stufe $int($level) zu zaubern.\""
@ -977,9 +971,6 @@ msgstr "\"$unit($mage) kümmert sich um die Verletzten und benutzt ein $resource
msgid "error276"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Hier kann man keine Schiffe bauen.\""
msgid "error166"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Diese Rasse kann eine Burg nicht belagern.\""
msgid "chaosgate_effect_2"
msgstr "\"Ein Wirbel aus blendendem Licht erscheint.\""
@ -998,9 +989,6 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - Die Einheit ist
msgid "error82"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Es gibt keine Abstimmung mit dieser Nummer.\""
msgid "error60"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Die Einheit wird belagert.\""
msgid "error162"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Der Heiltrank wird automatisch bei Bedarf benutzt.\""
@ -1457,9 +1445,6 @@ msgstr "\"$unit($unit) öffnet eines der Schlösser in $region($region) mit $if(
msgid "error255"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - So etwas kann man nicht opfern.\""
msgid "entrance_besieged"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - $building($building) wird belagert.\""
msgid "error260"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Der Besitzer eines Schiffes oder Gebäudes kann nicht neu sortiert werden.\""
@ -1550,9 +1535,6 @@ msgstr "\"In $region($region) findet ein Kampf statt.\""
msgid "wormhole_dissolve"
msgstr "\"Das Wurmloch in $region($region) schließt sich.\""
msgid "error23"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Der Belagerungszustand macht die Kontaktaufnahme unmöglich.\""
msgid "error12"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Das Schiff gehört uns nicht.\""
@ -2135,9 +2117,6 @@ msgstr "\"Seit $int($age) Wochen Mitglied der Allianz '$name ($int36($id))', ang
msgid "deathcloud_effect"
msgstr "\"$unit($mage) beschwört einen Giftelementar in $region($region).\""
msgid "nr_building_besieged"
msgstr "\", belagert von $int($soldiers) Personen$if($lt($diff,0),\"\",\" (abgeschnitten)\")\""
msgid "nr_population"
msgstr "\"Deine Partei hat $int($population) Personen in $int($units) von maximal $int($limit) Einheiten.\""
@ -2414,9 +2393,6 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - Das Schiff hat
msgid "aborted_battle"
msgstr "\"Der Kampf wurde abgebrochen, da alle Verteidiger flohen.\""
msgid "error24"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Der Belagerungszustand macht Spionage unmöglich.\""
msgid "usecatapult"
msgstr "\"$int($amount) Krieger von $unit($unit) feuern ihre Katapulte ab.\""

View file

@ -257,9 +257,6 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - Buildings canno
msgid "error165"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - The potion does not agree with the unit.\""
msgid "siege_catapults"
msgstr "\"$building($building) is under siege by $unit($unit). During siege, catapults caused $int($destruction) points destruction.\""
msgid "curseinfo::magicstreet"
msgstr "\"The roads are extremely dry and well-kept. ($int36($id))\""
@ -638,9 +635,6 @@ msgstr "\"$unit($unit) appears.\""
msgid "magicresistance_effect"
msgstr "\"$unit($unit) is briefly surrounded by a magical light.\""
msgid "siege"
msgstr "\"$building($building) is under siege by $unit($unit).\""
msgid "missing_force"
msgstr "\"$unit($unit) cannot muster enough energy to cast $spell($spell) on level $int($level).\""
@ -977,9 +971,6 @@ msgstr "\"$unit($mage) sees after the wounded and heals $int($amount). A $resour
msgid "error276"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Ships cannot be built here.\""
msgid "error166"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - This race cannot besiege a castle.\""
msgid "chaosgate_effect_2"
msgstr "\"A vortex of blinding light appears.\""
@ -998,9 +989,6 @@ msgstr "\"'$order($command)' - $unit($unit) marched into $region($region) during
msgid "error82"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - There is no agreement with this number.\""
msgid "error60"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - The unit is under siege.\""
msgid "error162"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - This healing potion will be automatically used when needed.\""
@ -1457,9 +1445,6 @@ msgstr "\"$unit($unit) unlocks one of the locks in $region($region) with $if($eq
msgid "error255"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - You cannot sacrifice this.\""
msgid "entrance_besieged"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - $building($building) is under siege.\""
msgid "error260"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - The owner of a ship or a building cannot be sorted.\""
@ -1550,9 +1535,6 @@ msgstr "\"There is a battle in $region($region).\""
msgid "wormhole_dissolve"
msgstr "\"The wormhole in $region($region) disappears.\""
msgid "error23"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Contact was not possible due to siege.\""
msgid "error12"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - The ship is not ours.\""
@ -2135,9 +2117,6 @@ msgstr "\"Member of '$name ($int36($id))' for $int($age) weeks, led by $faction(
msgid "deathcloud_effect"
msgstr "\"$unit($mage) summons a poison elemental in $region($region).\""
msgid "nr_building_besieged"
msgstr "\", besieged by $int($soldiers) soldiers$if($lt($diff,0),\"\",\" (cut off)\")\""
msgid "nr_population"
msgstr "\"Your faction has $int($population) people in $int($units) of $int($limit) possible units.\""
@ -2414,9 +2393,6 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - The ship has mo
msgid "aborted_battle"
msgstr "\"The battle was aborted because all enemies escaped.\""
msgid "error24"
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Espionage was not possible due to siege.\""
msgid "usecatapult"
msgstr "\"$int($amount) fighters of $unit($unit) launch their catapults.\""

View file

@ -2772,10 +2772,6 @@ msgstr "Dieser wunderschoen geschmueckte Baum entfaltet in den Wintermonaten ein
msgid "h10"
msgstr "Kakteenschwitz"
msgctxt "keyword"
msgid "besiege"
msgstr "BELAGERE"
msgid "h11"
msgstr "Sandfäule"
@ -2864,6 +2860,9 @@ msgstr "der Schatten"
msgid "ALLES"
msgstr "ALLES"
msgid "AUTO"
msgstr "AUTO"
msgid "undead_postfix_2"
msgstr "der Finsternis"
@ -5958,6 +5957,10 @@ msgctxt "keyword"
msgid "maketemp"
msgstr "MACHE TEMP"
msgctxt "keyword"
msgid "autostudy"
msgstr "LERNE AUTO"
msgctxt "spell"
msgid "reanimate"
msgstr "Wiederbelebung"

View file

@ -2421,10 +2421,6 @@ msgctxt "iteminfo"
msgid "xmastree"
msgstr "In the winter months, this beautifully decorated tree has a magical effect on the entire forest."
msgctxt "keyword"
msgid "besiege"
msgstr "BESIEGE"
msgid "h10"
msgstr "peyote"
@ -2510,6 +2506,9 @@ msgstr "halfling foot"
msgid "ALLES"
msgstr "ALL"
msgid "AUTO"
msgstr "AUTO"
msgctxt "race"
msgid "songdragon_d"
msgstr "song dragons"
@ -5268,7 +5267,11 @@ msgstr "berserkers blood potions"
msgctxt "keyword"
msgid "maketemp"
msgstr "MAKETEMP"
msgstr "MAKE TEMP"
msgctxt "keyword"
msgid "autostudy"
msgstr "LEARN AUTO"
msgctxt "spell"
msgid "reanimate"

View file

@ -1,16 +1,46 @@
#!/bin/sh
ERESSEA_DB=db
if [ -e /usr/include/sqlite3.h ] ; then
ERESSEA_DB=sqlite
ERESSEA_DB=memory
pkg-config --exists sqlite3 && ERESSEA_DB=sqlite
GETOPT=getopt
GETOPT_LONG=1
if [ "Darwin" = "$(uname)" ] ; then
if [ -x "/usr/local/opt/gnu-getopt/bin/getopt" ] ; then
GETOPT="/usr/local/opt/gnu-getopt/bin/getopt"
else
GETOPT_LONG=0
fi
fi
if [ $GETOPT_LONG -eq 1 ]; then
options=$(${GETOPT} -o d: -l db: -- "$@")
else # assume GNU getopt (long arguments)
options=$(${GETOPT} d: "$@")
fi
# Parse command line arguments
eval set -- "$options"
until [ -z "$1" ] ; do
case $1 in
-d|--db)
ERESSEA_DB=$2
shift
;;
--) shift; break;;
(-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;;
(*) break;;
esac
shift
done
while [ ! -z "$1" ] ; do
if [ "$1" = "--with-db" ] ; then
ERESSEA_DB=db
elif [ "$1" = "--with-sqlite" ] ; then
ERESSEA_DB=sqlite
elif [ "$1" = "--with-memory" ] ; then
ERESSEA_DB=memory
fi
shift 1
done

View file

@ -22,11 +22,12 @@ exit $2 # otherwise
function build() {
assert_dir $SOURCE
cd $SOURCE
rm -rf crypto tolua
rm -rf tolua
git fetch || abort "failed to update source. do you have local changes?"
[ -z $1 ] || git checkout $1
git pull -q
git submodule update
s/cmake-init
s/build > /dev/null || abort "build failed."
}

View file

@ -5,6 +5,6 @@ import sys
def new_version(ver):
os.system("git tag -f v%s" % ver)
os.system("git push --tags")
os.system("git push --tags -f")
new_version(sys.argv[1])

View file

@ -31,8 +31,8 @@ cppcheck_tests() {
set -e
[ -z $BUILD ] && BUILD=Debug ; export BUILD
s/cmake-init
# cppcheck_tests
s/cmake-init --db=sqlite
s/build
cd process
make

View file

@ -95,6 +95,7 @@ local function write_htpasswd()
end
local function write_files(locales)
write_database()
write_passwords()
write_htpasswd()
write_reports()

View file

@ -31,7 +31,6 @@ function test_process()
assert_equal("function", _G.type(eressea.process.movement))
assert_equal("function", _G.type(eressea.process.use))
assert_equal("function", _G.type(eressea.process.battle))
assert_equal("function", _G.type(eressea.process.siege))
assert_equal("function", _G.type(eressea.process.leave))
assert_equal("function", _G.type(eressea.process.promote))
assert_equal("function", _G.type(eressea.process.restack))

View file

@ -13,12 +13,6 @@ function setup()
eressea.settings.set("magic.regeneration.enable", "0")
end
local function dump_messages(f)
for k, v in ipairs(f.messages) do
print(v)
end
end
function test_fetch_astral()
local r = region.create(0, 0, "plain")
local f = faction.create("human")

View file

@ -12,6 +12,30 @@ function setup()
eressea.settings.set("rules.peasants.growth.factor", "0")
end
function test_study_auto()
local r = region.create(0, 0, "plain")
local f = faction.create("human")
local u = unit.create(f, r, 1)
u:add_order("LERN AUT Waffenbau")
assert_equal("LERNE AUTO Waffenbau", u:get_order(0))
process_orders()
assert_equal(1, u:get_skill("weaponsmithing"))
end
function test_study_auto_expensive()
local r = region.create(0, 0, "plain")
local f = faction.create("human")
local u = unit.create(f, r, 1)
u:add_order("LERNE AUTO Magie")
assert_equal("LERNE Magie", u:get_order(0))
u:clear_orders()
u:add_order("LERN AUT Taktik")
assert_equal("LERNE Taktik", u:get_order(0))
u:clear_orders()
u:add_order("LERN AUT Waffenbau")
assert_equal("LERNE AUTO Waffenbau", u:get_order(0))
end
function test_calendar()
assert_equal("winter", get_season(1011))
assert_equal("spring", get_season(1012))
@ -517,17 +541,3 @@ function test_buy_sell()
assert_equal(4, u:get_item(item))
assert_not_equal(0, u:get_item('money'))
end
function test_seaserpent_attack()
-- FIXME what does this test do?
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

@ -1,3 +1,10 @@
function dump_messages(f)
for k, v in ipairs(f.messages) do
print(v)
end
end
require 'tests.e2.movement'
require 'tests.e2.astral'
require 'tests.e2.spells'
require 'tests.e2.e2features'
@ -7,7 +14,6 @@ require 'tests.e2.production'
require 'tests.e2.adamantium'
require 'tests.e2.undead'
require 'tests.e2.shiplanding'
require 'tests.e2.movement'
require 'tests.e2.destroy'
require 'tests.e2.guard'
require 'tests.e2.stealth'

View file

@ -9,7 +9,7 @@ function setup()
eressea.settings.set("NewbieImmunity", "0")
end
function test_piracy()
function test_piracy()
local r = region.create(0, 0, "plain")
local r2 = region.create(1, 0, "plain")
local r3 = region.create(-1, 0, "ocean")
@ -96,6 +96,7 @@ function test_follow_ship()
local f = faction.create("human", "test@example.com", "de")
local u1 = unit.create(f, r1, 1)
local u2 = unit.create(f, r1, 1)
u2.name = 'Xolgrim'
u1:add_item("money", 100)
u2:add_item("money", 100)
u1.ship = ship.create(r1, "boat")

View file

@ -42,7 +42,8 @@ function test_build_watch()
process_orders()
assert_not_nil(u.building)
if 5 ~= u.building.size then
for k,v in f.messages do
-- debug logging to find intermittent errors
for k,v in ipairs(f.messages) do
print(v)
end
end

View file

@ -953,12 +953,11 @@ function test_bug2083()
-- this is a bit weird, but the bug was caused by market code
-- being called in two places. We want to make sure this doesn't happen
for k, v in pairs(rules) do
set_key("xm09", true)
if 'table' == type(v) then
if 'table' == type(v) then
cb = v['update']
if 'function' == type(cb) then
if 'function' == type(cb) then
cb()
end
end
end
end

View file

@ -24,7 +24,7 @@ end
function test_study()
local r = region.create(0, 0, "plain")
local f = faction.create("human", "test@example.com", "de")
local f = faction.create("human")
local u = unit.create(f, r, 1)
u:add_order("LERNEN Armbrust")
process_orders()
@ -33,7 +33,7 @@ end
function test_study_expensive()
local r = region.create(0, 0, "plain")
local f = faction.create("human", "test@example.com", "de")
local f = faction.create("human")
local u = unit.create(f, r, 1)
eressea.settings.set("skills.cost.alchemy", "50")
u:add_order("LERNEN Alchemie")
@ -45,7 +45,7 @@ end
function test_unit_spells()
local r = region.create(0, 0, "plain")
local f = faction.create("human", "test@example.com", "de")
local f = faction.create("human")
local u = unit.create(f, r, 1)
u.magic = "gray"
u:set_skill("magic", 1)
@ -75,7 +75,7 @@ end
function test_study_no_teacher()
local r = region.create(0, 0, "plain")
local f = faction.create("human", "test@example.com", "de")
local f = faction.create("human")
local u1 = make_student(f, r, 1)
u1:set_skill("crossbow", 1)
process_orders()
@ -84,7 +84,7 @@ end
function test_study_with_teacher()
local r = region.create(0, 0, "plain")
local f = faction.create("human", "test@example.com", "de")
local f = faction.create("human")
local u1 = make_student(f, r, 1)
make_teacher(u1)
@ -95,7 +95,7 @@ end
function test_study_too_many_students()
local r = region.create(0, 0, "plain")
local f = faction.create("human", "test@example.com", "de")
local f = faction.create("human")
local u1 = make_student(f, r, 20, "Taktik")
u1.name = "Student"
u1:add_item("money", 201*u1.number)
@ -106,7 +106,7 @@ end
function test_study_multiple_teachers()
local r = region.create(0, 0, "plain")
local f = faction.create("human", "test@example.com", "de")
local f = faction.create("human")
local u1 = make_student(f, r, 20, "Taktik")
u1.name = "Student"
u1:add_item("money", 201*u1.number)

View file

@ -3,6 +3,7 @@ project (server C)
include_directories (${CMAKE_CURRENT_SOURCE_DIR})
include_directories (${CJSON_INCLUDE_DIR})
include_directories (${CRYPTO_INCLUDE_DIR})
include_directories (${CLIBS_INCLUDE_DIR})
include_directories (${STORAGE_INCLUDE_DIR})
include_directories (${TOLUA_INCLUDE_DIR})
@ -27,7 +28,7 @@ IF (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wsign-compare -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long")
# SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c89")
ELSEIF(MSVC)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4 /WX /MP /Za /D_CRT_SECURE_NO_WARNINGS /D_USE_MATH_DEFINES")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4 /WX /MP /D_CRT_SECURE_NO_WARNINGS /D_USE_MATH_DEFINES")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG
"${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libc.lib /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcd.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrt.lib")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE
@ -84,50 +85,56 @@ TOLUA_BINDING(eressea.pkg bind_eressea.h)
TOLUA_BINDING(settings.pkg kenel/config.h)
ENDIF()
set (PARSER_SRC
${DB_SRC}
${UTIL_SRC}
)
set (ERESSEA_SRC
vortex.c
automate.c
move.c
piracy.c
spells.c
battle.c
alchemy.c
academy.c
alchemy.c
automate.c
battle.c
chaos.c
upkeep.c
names.c
lighthouse.c
reports.c
teleport.c
guard.c
jsonconf.c
prefix.c
donations.c
eressea.c
direction.c
keyword.c
skill.c
json.c
creport.c
report.c
steal.c
direction.c
donations.c
economy.c
eressea.c
exparse.c
gamedb.c
give.c
guard.c
items.c
json.c
jsonconf.c
laws.c
lighthouse.c
magic.c
market.c
monsters.c
morale.c
move.c
names.c
orderdb.c
orderfile.c
piracy.c
prefix.c
randenc.c
renumber.c
volcano.c
report.c
reports.c
skill.c
spells.c
spy.c
steal.c
study.c
summary.c
travelthru.c
monsters.c
teleport.c
upkeep.c
volcano.c
wormhole.c
${SPELLS_SRC}
${RACES_SRC}
@ -136,56 +143,74 @@ set (ERESSEA_SRC
${TRIGGERS_SRC}
${ATTRIBUTES_SRC}
${KERNEL_SRC}
${DB_SRC}
${UTIL_SRC}
)
)
set(CHECK_SRC
checker.c
)
set(SERVER_SRC
main.c
console.c
helpers.c
bind_tolua.c
bind_building.c
bind_config.c
bind_locale.c
bind_eressea.c
bind_faction.c
bind_order.c
bindings.c
bind_locale.c
bind_message.c
bind_monsters.c
bind_order.c
bind_process.c
bind_region.c
bind_ship.c
bind_storage.c
bind_tolua.c
bind_unit.c
)
bindings.c
console.c
helpers.c
main.c
)
if (CURSES_FOUND)
set (SERVER_SRC ${SERVER_SRC}
bind_gmtool.c
gmtool.c
listbox.c
bind_gmtool.c
)
endif(CURSES_FOUND)
find_program(IWYU_PATH NAMES include-what-you-use iwyu)
if(NOT IWYU_PATH)
message(STATUS "Could not find the program include-what-you-use")
endif()
add_library(version STATIC ${VERSION_SRC})
add_library(parser ${PARSER_SRC})
target_link_libraries(parser
${CLIBS_LIBRARIES}
${CRYPTO_LIBRARIES}
)
add_executable(checker ${CHECK_SRC})
target_link_libraries(checker parser)
add_library(game ${ERESSEA_SRC})
target_link_libraries(game parser version)
add_executable(eressea ${SERVER_SRC})
target_link_libraries(game version)
if (IWYU_PATH)
set_property(TARGET eressea PROPERTY C_INCLUDE_WHAT_YOU_USE ${IWYU_PATH})
endif(IWYU_PATH)
target_link_libraries(eressea
game
${TOLUA_LIBRARIES}
${LUA_LIBRARIES}
${STORAGE_LIBRARIES}
${CLIBS_LIBRARIES}
${CJSON_LIBRARIES}
${INIPARSER_LIBRARIES}
)
set(TESTS_SRC
test_eressea.c
tests.c
academy.test.c
alchemy.test.c
automate.test.c
@ -198,7 +223,6 @@ set(TESTS_SRC
guard.test.c
json.test.c
jsonconf.test.c
keyword.test.c
laws.test.c
lighthouse.test.c
magic.test.c
@ -206,17 +230,20 @@ set(TESTS_SRC
monsters.test.c
move.test.c
names.test.c
orderdb.test.c
orderfile.test.c
piracy.test.c
prefix.test.c
renumber.test.c
reports.test.c
report.test.c
summary.test.c
reports.test.c
skill.test.c
spells.test.c
spy.test.c
study.test.c
summary.test.c
test_eressea.c
tests.c
tests.test.c
travelthru.test.c
upkeep.test.c
@ -270,8 +297,7 @@ if (HAVE_STRDUP)
endif(HAVE_STRDUP)
if (HAVE_LIBBSD)
target_link_libraries(test_eressea bsd)
target_link_libraries(eressea bsd)
target_link_libraries(parser bsd)
endif (HAVE_LIBBSD)
if (SQLITE3_FOUND)

View file

@ -16,8 +16,8 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/
#include <platform.h>
#include <kernel/config.h>
#include "platform.h"
#include "kernel/config.h"
#include <kernel/unit.h>
#include <kernel/building.h>
#include <kernel/item.h>

View file

@ -33,8 +33,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/unit.h>
/* util includes */
#include <util/attrib.h>
#include <util/gamedata.h>
#include <kernel/attrib.h>
#include <kernel/gamedata.h>
#include <util/base36.h>
#include <util/log.h>
#include <util/macros.h>

View file

@ -53,9 +53,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/building.h>
/* util includes */
#include <util/attrib.h>
#include <util/event.h>
#include <util/gamedata.h>
#include <kernel/attrib.h>
#include <kernel/event.h>
#include <kernel/gamedata.h>
#include <util/macros.h>
#include <util/resolve.h>
@ -182,13 +182,13 @@ void register_attributes(void)
at_register(&at_seenspell);
at_register(&at_seenspells);
/* neue REGION-Attribute */
/* REGION Attribute */
at_register(&at_moveblock);
at_register(&at_deathcount);
at_register(&at_woodcount);
at_register(&at_germs);
/* neue UNIT-Attribute */
at_register(&at_siege);
/* UNIT Attribute */
at_register(&at_effect);
at_register(&at_private);
@ -205,8 +205,7 @@ void register_attributes(void)
register_bordertype(&bt_illusionwall);
register_bordertype(&bt_road);
at_register(&at_germs);
at_deprecate("siege", a_readint);
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 */

View file

@ -29,10 +29,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/unit.h>
/* util includes */
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/log.h>
#include <util/gamedata.h>
#include <kernel/gamedata.h>
#include <util/resolve.h>
#include <util/strings.h>

View file

@ -22,8 +22,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include <kernel/unit.h>
#include <util/attrib.h>
#include <util/gamedata.h>
#include <kernel/attrib.h>
#include <kernel/gamedata.h>
#include <util/variant.h>
#include <storage.h>

View file

@ -22,8 +22,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/unit.h>
#include <util/attrib.h>
#include <util/gamedata.h>
#include <kernel/attrib.h>
#include <kernel/gamedata.h>
#include <util/macros.h>
#include <util/resolve.h>

View file

@ -20,7 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include "iceberg.h"
#include <util/attrib.h>
#include <kernel/attrib.h>
attrib_type at_iceberg = {
"iceberg_drift",

View file

@ -20,11 +20,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include "key.h"
#include <util/attrib.h>
#include <util/gamedata.h>
#include <kernel/attrib.h>
#include <kernel/gamedata.h>
#include <util/log.h>
#include <storage.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
@ -76,25 +77,83 @@ static int keys_size(int n) {
return 4096;
}
static int read_flags(gamedata *data, int *keys, int n) {
int i;
for (i = 0; i != n; ++i) {
int key;
READ_INT(data->store, &key);
keys[i * 2] = key;
keys[i * 2 + 1] = 1;
}
return n;
}
#ifdef KEYVAL_VERSION
static int read_keyval(gamedata *data, int *keys, int n) {
int i;
for (i = 0; i != n; ++i) {
int key, val;
READ_INT(data->store, &key);
READ_INT(data->store, &val);
keys[i * 2] = key;
keys[i * 2 + 1] = val;
}
return n;
}
#endif
#ifdef FIXATKEYS_VERSION
static int read_keyval_orig(gamedata *data, int *keys, int n) {
int i, j = 0, dk = -1;
for (i = 0; i != n; ++i) {
int key, val;
READ_INT(data->store, &key);
READ_INT(data->store, &val);
if (key > dk) {
keys[j * 2] = key;
keys[j * 2 + 1] = val;
dk = key;
++j;
}
}
return j;
}
#endif
static int a_readkeys(variant *var, void *owner, gamedata *data) {
int i, n, *keys;
int i, n, ksn, *keys;
READ_INT(data->store, &n);
assert(n < 4096 && n >= 0);
if (n == 0) {
return AT_READ_FAIL;
}
keys = malloc(sizeof(int)*(keys_size(n) * 2 + 1));
*keys = n;
for (i = 0; i != n; ++i) {
READ_INT(data->store, keys + i * 2 + 1);
if (data->version >= KEYVAL_VERSION) {
READ_INT(data->store, keys + i * 2 + 2);
}
else {
keys[i * 2 + 2] = 1;
ksn = keys_size(n);
keys = malloc((ksn * 2 + 1) * sizeof(int));
if (data->version >= FIXATKEYS_VERSION) {
n = read_keyval(data, keys + 1, n);
}
else if (data->version >= KEYVAL_VERSION) {
int m = read_keyval_orig(data, keys + 1, n);
if (n != m) {
int ksm = keys_size(m);
if (ksm != ksn) {
int *nkeys = (int *)realloc(keys, (ksm * 2 + 1) * sizeof(int));
if (nkeys != NULL) {
keys = nkeys;
}
else {
log_error("a_readkeys allocation failed: %s", strerror(errno));
return AT_READ_FAIL;
}
}
n = m;
}
}
else {
n = read_flags(data, keys + 1, n);
}
keys[0] = n;
if (data->version < SORTKEYS_VERSION) {
int e = 1;
for (i = 1; i != n; ++i) {

View file

@ -2,7 +2,7 @@
#include "key.h"
#include "dict.h"
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <CuTest.h>
#include <stdlib.h>

View file

@ -20,8 +20,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include "movement.h"
#include <util/attrib.h>
#include <util/gamedata.h>
#include <kernel/attrib.h>
#include <kernel/gamedata.h>
#include <util/macros.h>
#include <storage.h>

View file

@ -23,8 +23,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/ally.h>
#include <kernel/faction.h>
#include <kernel/unit.h>
#include <util/attrib.h>
#include <util/gamedata.h>
#include <kernel/attrib.h>
#include <kernel/gamedata.h>
#include <storage.h>
#include <assert.h>

View file

@ -7,7 +7,7 @@
#include <kernel/region.h>
#include <kernel/faction.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <CuTest.h>
#include <tests.h>

View file

@ -20,7 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include "overrideroads.h"
#include <util/attrib.h>
#include <kernel/attrib.h>
attrib_type at_overrideroads = {
"roads_override", NULL, NULL, NULL, a_writestring, a_readstring

View file

@ -20,7 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include "racename.h"
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/strings.h>
/* libc includes */

View file

@ -20,7 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include "raceprefix.h"
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/strings.h>
#include <assert.h>

View file

@ -22,7 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/region.h>
#include <kernel/messages.h>
#include <util/message.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <assert.h>
static int age_reduceproduction(attrib * a, void *owner)

View file

@ -23,8 +23,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/faction.h>
#include <kernel/spell.h>
#include <kernel/spellbook.h>
#include <util/attrib.h>
#include <util/gamedata.h>
#include <kernel/attrib.h>
#include <kernel/gamedata.h>
#include <util/log.h>
#include <util/macros.h>

View file

@ -1,7 +1,7 @@
#include <platform.h>
#include <kernel/unit.h>
#include <kernel/region.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <attributes/stealth.h>
#include <stdlib.h>

View file

@ -22,8 +22,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include <kernel/region.h>
#include <util/attrib.h>
#include <util/gamedata.h>
#include <kernel/attrib.h>
#include <kernel/gamedata.h>
#include <util/resolve.h>
#include <storage.h>

View file

@ -6,10 +6,10 @@
#include "kernel/region.h"
#include "kernel/unit.h"
#include "util/keyword.h"
#include "util/log.h"
#include "automate.h"
#include "keyword.h"
#include "laws.h"
#include "study.h"
@ -38,14 +38,14 @@ int autostudy_init(scholar scholars[], int max_scholars, region *r)
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;
st->u = u;
if (++nscholars == max_scholars) {
log_fatal("you must increase MAXSCHOLARS");
}
}
else {
ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "error_race_nolearn", "race",
@ -81,13 +81,13 @@ void autostudy_run(scholar scholars[], int nscholars)
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) {
for (; mint > tt && si != nscholars && scholars[si].sk == sk; ++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) {
for (; si != se && scholars[ti].level - TEACHDIFFERENCE > scholars[si].level && scholars[si].sk == sk; ++si) {
tt += scholars[si].u->number;
}
if (si == se) {
@ -134,7 +134,7 @@ void autostudy_run(scholar scholars[], int nscholars)
learning(scholars + s, (n - i));
i = 0;
if (++s == se) {
continue;
break;
}
n = scholars[s].u->number;
} while (scholars[t].level - TEACHDIFFERENCE < scholars[s].level);

View file

@ -60,7 +60,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* util includes */
#include <util/assert.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/language.h>
#include <util/lists.h>
@ -100,10 +100,8 @@ typedef enum combatmagic {
#define MINSPELLRANGE 1
#define MAXSPELLRANGE 7
#ifndef ROW_FACTOR
# define ROW_FACTOR 10
#endif
#define EFFECT_PANIC_SPELL 0.25
#define ROW_FACTOR 3 /* factor for combat row advancement rule */
#define EFFECT_PANIC_SPELL 25
#define TROLL_REGENERATION 0.10
/* Nach dem alten System: */
@ -128,6 +126,9 @@ const troop no_troop = { 0, 0 };
static int max_turns;
static int rule_damage;
static int rule_loot;
static int flee_chance_max_percent;
static int flee_chance_base;
static int flee_chance_skill_bonus;
static int skill_formula;
static int rule_cavalry_skill;
static int rule_population_damage;
@ -146,6 +147,9 @@ static void init_rules(void)
{
it_mistletoe = it_find("mistletoe");
flee_chance_skill_bonus = config_get_int("rules.combat.flee_chance_bonus", 5);
flee_chance_base = config_get_int("rules.combat.flee_chance_base", 20);
flee_chance_max_percent = config_get_int("rules.combat.flee_chance_limit", 90);
rule_nat_armor = config_get_int("rules.combat.nat_armor", 0);
rule_tactics_formula = config_get_int("rules.tactics.formula", 0);
rule_goblin_bonus = config_get_int("rules.combat.goblinbonus", 10);
@ -161,7 +165,7 @@ static void init_rules(void)
skill_formula = config_get_int("rules.combat.skill_formula",
FORMULA_ORIG);
/* maximum number of combat turns */
max_turns = config_get_int("rules.combat.turns", COMBAT_TURNS);
max_turns = config_get_int("rules.combat.turns", 5);
/* damage calculation */
if (config_get_int("rules.combat.critical", 1)) {
rule_damage |= DAMAGE_CRITICAL;
@ -2350,7 +2354,7 @@ static void add_tactics(tactics * ta, fighter * fig, int value)
ta->value = value;
}
static double horse_fleeing_bonus(const unit * u)
static int horse_fleeing_bonus(const unit * u)
{
const item_type *it_horse, *it_elvenhorse, *it_charger;
int n1 = 0, n2 = 0, n3 = 0;
@ -2373,26 +2377,26 @@ static double horse_fleeing_bonus(const unit * u)
}
}
if (skl >= 5 && n3 >= u->number)
return 0.30;
return 30;
if (skl >= 2 && n2 + n3 >= u->number)
return 0.20;
return 20;
if (n1 + n2 + n3 >= u->number)
return 0.10;
return 0.0F;
return 10;
return 0;
}
double fleechance(unit * u)
static int fleechance(unit * u)
{
double p = 0.20; /* Fluchtwahrscheinlichkeit in % */
int p = flee_chance_base; /* Fluchtwahrscheinlichkeit in % */
/* Einheit u versucht, dem Get<65>mmel zu entkommen */
p += (effskill(u, SK_STEALTH, 0) * 0.05);
p += (effskill(u, SK_STEALTH, 0) * flee_chance_skill_bonus);
p += horse_fleeing_bonus(u);
if (u_race(u) == get_race(RC_HALFLING)) {
p += 0.20;
if (p > 0.9) {
p = 0.9;
p += flee_chance_base;
if (p > flee_chance_max_percent) {
p = flee_chance_max_percent;
}
}
return p;
@ -2691,7 +2695,7 @@ static void aftermath(battle * b)
}
}
snumber += du->number;
if (df->alive == 0) {
if (dead == df->unit->number) {
flags = UFL_DEAD;
}
else if (relevant) {
@ -3651,17 +3655,6 @@ static void join_allies(battle * b)
}
if (se == s_end)
continue;
/* Wenn die Einheit belagert ist, mu<6D> auch einer der Alliierten belagert sein: */
if (besieged(u)) {
fighter *ally;
for (ally = s->fighters; ally; ally = ally->next) {
if (besieged(ally->unit)) {
break;
}
}
if (ally == NULL)
continue;
}
/* keine Einw<6E>nde, also soll er mitmachen: */
if (c == NULL) {
if (!join_battle(b, u, false, &c)) {
@ -3716,13 +3709,21 @@ static void flee(const troop dt)
{
fighter *fig = dt.fighter;
unit *u = fig->unit;
int fchance = fleechance(u);
fig->run.hp += fig->person[dt.index].hp;
++fig->run.number;
if (fig->person[dt.index].flags & FL_PANICED) {
fchance += EFFECT_PANIC_SPELL;
}
if (fchance > flee_chance_max_percent) {
fchance = flee_chance_max_percent;
}
if (rng_int() % 100 < fchance) {
fig->run.hp += fig->person[dt.index].hp;
++fig->run.number;
setguard(u, false);
kill_troop(dt);
setguard(u, false);
kill_troop(dt);
}
}
static bool is_calmed(const unit *u, const faction *f) {
@ -3730,7 +3731,7 @@ static bool is_calmed(const unit *u, const faction *f) {
while (a && a->type == &at_curse) {
curse *c = (curse *)a->data.v;
if (c->type == &ct_calmmonster && curse_geteffect_int(c) == f->subscription) {
if (c->type == &ct_calmmonster && curse_geteffect_int(c) == f->uid) {
if (curse_active(c)) {
return true;
}
@ -3950,7 +3951,6 @@ static void battle_flee(battle * b)
for (fig = s->fighters; fig; fig = fig->next) {
unit *u = fig->unit;
troop dt;
int runners = 0;
/* Flucht nicht bei mehr als 600 HP. Damit Wyrme t<>tbar bleiben. */
int runhp = (int)(0.9 + unit_max_hp(u) * hpflee(u->status));
if (runhp > 600) runhp = 600;
@ -3967,7 +3967,6 @@ static void battle_flee(battle * b)
dt.fighter = fig;
dt.index = fig->alive - fig->removed;
while (s->size[SUM_ROW] && dt.index != 0) {
double ispaniced = 0.0;
--dt.index;
assert(dt.index >= 0 && dt.index < fig->unit->number);
assert(fig->person[dt.index].hp > 0);
@ -3992,14 +3991,7 @@ static void battle_flee(battle * b)
}
continue;
}
if (fig->person[dt.index].flags & FL_PANICED) {
ispaniced = EFFECT_PANIC_SPELL;
}
if (chance(fmin(fleechance(u) + ispaniced, 0.90))) {
++runners;
flee(dt);
}
flee(dt);
}
}
}
@ -4053,8 +4045,7 @@ void force_leave(region *r, battle *b) {
}
void do_battle(region * r)
{
static void do_battle(region * r) {
battle *b = NULL;
bool fighting;
ship *sh;

View file

@ -2,6 +2,7 @@
#include "battle.h"
#include "guard.h"
#include "reports.h"
#include "skill.h"
@ -10,6 +11,7 @@
#include <kernel/faction.h>
#include <kernel/curse.h>
#include <kernel/item.h>
#include <kernel/order.h>
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/ship.h>
@ -17,7 +19,9 @@
#include <spells/buildingcurse.h>
#include <util/base36.h>
#include <util/functions.h>
#include "util/keyword.h"
#include <util/language.h>
#include <util/message.h>
#include <util/rand.h>
@ -31,6 +35,21 @@
#include "tests.h"
static void setup_messages(void) {
mt_create_va(mt_new("start_battle", NULL), "factions:string", MT_NEW_END);
mt_create_va(mt_new("para_army_index", NULL), "index:int", "name:string", MT_NEW_END);
mt_create_va(mt_new("battle_msg", NULL), "string:string", MT_NEW_END);
mt_create_va(mt_new("battle_row", NULL), "row:int", MT_NEW_END);
mt_create_va(mt_new("para_lineup_battle", NULL), "turn:int", MT_NEW_END);
mt_create_va(mt_new("para_after_battle", NULL), MT_NEW_END);
mt_create_va(mt_new("army_report", NULL),
"index:int", "abbrev:string", "dead:int", "fled:int", "survived:int",
MT_NEW_END);
mt_create_va(mt_new("casualties", NULL),
"unit:unit", "runto:region", "run:int", "alive:int", "fallen:int",
MT_NEW_END);
}
static void test_make_fighter(CuTest * tc)
{
unit *au;
@ -607,7 +626,7 @@ static void test_battle_report_one(CuTest *tc)
fighter *fig;
test_setup();
mt_create_va(mt_new("start_battle", NULL), "factions:string", MT_NEW_END);
setup_messages();
r = test_create_plain(0, 0);
u1 = test_create_unit(test_create_faction(NULL), r);
u2 = test_create_unit(test_create_faction(NULL), r);
@ -638,7 +657,7 @@ static void test_battle_report_two(CuTest *tc)
test_setup();
lang = test_create_locale();
locale_setstring(lang, "and", "and");
mt_create_va(mt_new("start_battle", NULL), "factions:string", MT_NEW_END);
setup_messages();
r = test_create_plain(0, 0);
u1 = test_create_unit(test_create_faction(NULL), r);
u1->faction->locale = lang;
@ -671,7 +690,7 @@ static void test_battle_report_three(CuTest *tc)
test_setup();
lang = test_create_locale();
locale_setstring(lang, "and", "and");
mt_create_va(mt_new("start_battle", NULL), "factions:string", MT_NEW_END);
setup_messages();
r = test_create_plain(0, 0);
u1 = test_create_unit(test_create_faction(NULL), r);
u1->faction->locale = lang;
@ -824,12 +843,43 @@ static void test_tactics_chance(CuTest *tc) {
test_teardown();
}
static void test_battle_fleeing(CuTest *tc) {
region *r;
unit *u1, *u2;
test_setup();
setup_messages();
r = test_create_plain(0, 0);
u1 = test_create_unit(test_create_faction(NULL), r);
u2 = test_create_unit(test_create_faction(NULL), r);
u1->status = ST_FLEE;
u2->status = ST_AGGRO;
#if 0
setguard(u1, true);
CuAssertIntEquals(tc, UFL_GUARD, (u1->flags & UFL_GUARD));
CuAssertIntEquals(tc, RF_GUARDED, (r->flags & RF_GUARDED));
#endif
config_set_int("rules.combat.flee_chance_base", 100);
config_set_int("rules.combat.flee_chance_limit", 100);
unit_addorder(u2, create_order(K_ATTACK, u2->faction->locale, itoa36(u1->no)));
do_battles();
CuAssertIntEquals(tc, 1, u1->number);
CuAssertIntEquals(tc, 1, u2->number);
#if 0
CuAssertIntEquals(tc, 0, (u1->flags & UFL_GUARD));
CuAssertIntEquals(tc, 0, (r->flags & RF_GUARDED));
#endif
CuAssertIntEquals(tc, UFL_LONGACTION, (u1->flags & UFL_LONGACTION));
CuAssertIntEquals(tc, UFL_LONGACTION | UFL_NOTMOVING, (u2->flags & (UFL_LONGACTION | UFL_NOTMOVING)));
test_teardown();
}
CuSuite *get_battle_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_make_fighter);
SUITE_ADD_TEST(suite, test_select_weapon_restricted);
SUITE_ADD_TEST(suite, test_select_armor);
SUITE_ADD_TEST(suite, test_battle_fleeing);
SUITE_ADD_TEST(suite, test_battle_skilldiff);
SUITE_ADD_TEST(suite, test_battle_skilldiff_building);
SUITE_ADD_TEST(suite, test_battle_report_one);

View file

@ -5,7 +5,6 @@
#include "bind_building.h"
#include "bind_unit.h"
#include <kernel/config.h>
#include <kernel/unit.h>
#include <kernel/building.h>
#include <kernel/region.h>
@ -15,9 +14,12 @@
#include <util/macros.h>
#include <util/strings.h>
#include <lua.h>
#include <lauxlib.h>
#include <tolua.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
int tolua_buildinglist_next(lua_State * L)
{

View file

@ -5,17 +5,15 @@
#include "bind_config.h"
#include "jsonconf.h"
#include "magic.h"
#include <kernel/config.h>
#include <kernel/building.h>
#include <kernel/race.h>
#include <kernel/ship.h>
#include <kernel/spell.h>
#include <kernel/spellbook.h>
#include <kernel/terrain.h>
#include <util/log.h>
#include <util/language.h>
#include <util/nrmessage.h>
#include <util/path.h>
#include <util/strings.h>

View file

@ -3,8 +3,6 @@
#endif
#include "bind_eressea.h"
#include <platform.h>
#include "json.h"
#include "orderfile.h"
@ -14,15 +12,17 @@
#include <kernel/save.h>
#include <util/language.h>
#include <util/log.h>
#include <stream.h>
#include <stdio.h>
#include <filestream.h>
void eressea_free_game(void) {
free_gamedata();
init_resources();
init_locales();
init_locales(init_locale);
}
int eressea_read_game(const char * filename) {
@ -35,7 +35,13 @@ int eressea_write_game(const char * filename) {
}
int eressea_read_orders(const char * filename) {
return readorders(filename);
FILE * F = fopen(filename, "r");
if (!F) {
perror(filename);
return -1;
}
log_info("reading orders from %s", filename);
return parseorders(F);
}
int eressea_export_json(const char * filename, int flags) {

View file

@ -17,30 +17,32 @@ without prior permission by the authors of Eressea.
#include "bind_faction.h"
#include "bind_unit.h"
#include "bindings.h"
#include "helpers.h"
#include "magic.h"
#include <kernel/alliance.h>
#include <kernel/faction.h>
#include <kernel/unit.h>
#include <kernel/item.h>
#include <kernel/faction.h>
#include <kernel/messages.h>
#include <kernel/plane.h>
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/spellbook.h>
#include <attributes/key.h>
#include "kernel/types.h"
#include <util/base36.h>
#include <util/language.h>
#include <util/log.h>
#include <util/macros.h>
#include <util/message.h>
#include <util/password.h>
#include "attributes/key.h"
#include <lua.h>
#include <lauxlib.h>
#include <tolua.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct helpmode {
const char *name;
@ -430,7 +432,7 @@ static int tolua_faction_create(lua_State * L)
faction *f = NULL;
const struct race *frace = rc_find(racename ? racename : "human");
if (frace != NULL) {
f = addfaction(email, NULL, frace, loc, 0);
f = addfaction(email, NULL, frace, loc);
}
if (!f) {
log_error("cannot create %s faction for %s, unknown race.", racename, email);
@ -450,7 +452,7 @@ static int tolua_faction_set_password(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
const char * passw = tolua_tostring(L, 2, 0);
faction_setpassword(self, password_encode(passw, PASSWORD_DEFAULT));
faction_setpassword(self, password_hash(passw, PASSWORD_DEFAULT));
return 0;
}
@ -526,14 +528,14 @@ static int tolua_faction_set_name(lua_State * L)
static int tolua_faction_get_uid(lua_State * L)
{
faction *f = (faction *)tolua_tousertype(L, 1, 0);
lua_pushinteger(L, f->subscription);
lua_pushinteger(L, f->uid);
return 1;
}
static int tolua_faction_set_uid(lua_State * L)
{
faction *f = (faction *)tolua_tousertype(L, 1, 0);
f->subscription = (int)tolua_tonumber(L, 2, 0);
f->uid = (int)tolua_tonumber(L, 2, 0);
return 0;
}

View file

@ -14,6 +14,8 @@
#include <util/log.h>
#include <util/macros.h>
#include <lua.h>
#include <lauxlib.h>
#include <tolua.h>
#include <string.h>

View file

@ -16,14 +16,18 @@
#include <util/macros.h>
#include <util/message.h>
#include <util/nrmessage.h>
#include <util/variant.h>
/* lua includes */
#include <lua.h>
#include <tolua.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
struct order;
#define E_OK 0
#define E_INVALID_MESSAGE 1
#define E_INVALID_PARAMETER_NAME 2

View file

@ -2,20 +2,19 @@
#include <platform.h>
#endif
#include "spells/shipcurse.h"
#include "monsters.h"
#include <spells/flyingship.h>
#include <kernel/faction.h>
#include <kernel/race.h>
#include <kernel/ship.h>
#include <kernel/spellbook.h>
#include <kernel/unit.h>
#include <util/macros.h>
#include <lua.h>
#include <tolua.h>
#include <stdlib.h>
static int tolua_levitate_ship(lua_State * L)
@ -62,7 +61,7 @@ static int tolua_spawn_undead(lua_State * L)
return 0;
}
void bind_monsters(struct lua_State *L)
void bind_monsters(lua_State *L)
{
tolua_module(L, NULL, 0);
tolua_beginmodule(L, NULL);

View file

@ -8,6 +8,7 @@
#include <util/macros.h>
/* lua includes */
#include <lua.h>
#include <tolua.h>
#include <stdlib.h>

View file

@ -4,20 +4,22 @@
#include "bind_process.h"
#include "battle.h"
#include "economy.h"
#include "laws.h"
#include "magic.h"
#include "market.h"
#include "move.h"
#include "study.h"
#include <kernel/alliance.h>
#include <kernel/config.h>
#include <kernel/order.h>
#include <kernel/region.h>
#include <kernel/terrain.h>
#include <kernel/unit.h>
#include "battle.h"
#include "economy.h"
#include "keyword.h"
#include "laws.h"
#include "magic.h"
#include "market.h"
#include "move.h"
#include "study.h"
#include "util/keyword.h"
#define PROC_LAND_REGION 0x0001
#define PROC_LONG_ORDER 0x0002
@ -76,10 +78,6 @@ void process_battle(void) {
do_battles();
}
void process_siege(void) {
process_cmd(K_BESIEGE, siege_cmd, PROC_LAND_REGION);
}
void process_update_long_order(void) {
region * r;
for (r = regions; r; r = r->next) {

View file

@ -8,38 +8,37 @@
#include "bind_building.h"
#include "teleport.h"
#include "direction.h"
#include <kernel/building.h>
#include <kernel/calendar.h>
#include <kernel/config.h>
#include <kernel/curse.h>
#include <kernel/region.h>
#include <kernel/resources.h>
#include <kernel/unit.h>
#include <kernel/region.h>
#include <kernel/item.h>
#include <kernel/build.h>
#include <kernel/building.h>
#include <kernel/ship.h>
#include <kernel/plane.h>
#include <kernel/terrain.h>
#include <kernel/messages.h>
#include <modules/autoseed.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/log.h>
#include <util/macros.h>
#include <util/message.h>
#include <util/strings.h>
#include <attributes/key.h>
#include <attributes/racename.h>
#include <util/attrib.h>
#include <util/base36.h>
#include <util/language.h>
#include <util/log.h>
#include <util/macros.h>
#include <util/strings.h>
#include <critbit.h>
#include <lua.h>
#include <lauxlib.h>
#include <tolua.h>
#include <assert.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
static int tolua_region_count_msg_type(lua_State *L) {

View file

@ -14,7 +14,7 @@
#include <kernel/ship.h>
#include <kernel/build.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/language.h>
#include <util/log.h>
#include <util/macros.h>

View file

@ -6,21 +6,18 @@
#include <kernel/save.h>
#include <util/gamedata.h>
#include <kernel/gamedata.h>
#include <util/log.h>
#include <util/macros.h>
#include <storage.h>
#include <stream.h>
#include <filestream.h>
#include <binarystore.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <lua.h>
#include <tolua.h>
static int tolua_storage_create(lua_State * L)

View file

@ -12,6 +12,8 @@
#include "settings.pkg.c"
#pragma warning(pop)
#include <lua.h>
void tolua_bind_open(lua_State * L) {
tolua_eressea_open(L);
tolua_process_open(L);

View file

@ -5,15 +5,22 @@
#include "bind_unit.h"
#include "alchemy.h"
#include "bindings.h"
#include "move.h"
#include "reports.h"
#include "guard.h"
#include "magic.h"
#include "skill.h"
/* attributes includes */
#include <attributes/racename.h>
#include <attributes/key.h>
/* util includes */
#include <kernel/attrib.h>
#include <util/base36.h>
#include <kernel/event.h>
#include <util/log.h>
#include <util/macros.h>
#include "util/variant.h"
/* kernel includes */
#include "kernel/skills.h"
#include "kernel/types.h"
#include <kernel/building.h>
#include <kernel/config.h>
#include <kernel/curse.h>
@ -31,21 +38,20 @@
#include <kernel/spell.h>
#include <kernel/unit.h>
/* util includes */
#include <util/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <util/lists.h>
#include <util/log.h>
#include <util/macros.h>
/* attributes includes */
#include <attributes/racename.h>
#include <attributes/key.h>
#include <selist.h>
#include <lauxlib.h>
#include <lua.h>
#include <tolua.h>
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <limits.h>

View file

@ -4,30 +4,39 @@
#include "bindings.h"
#include "console.h"
#include "gamedb.h"
#include "helpers.h"
#include "laws.h"
#include "magic.h"
#include "reports.h"
#include "skill.h"
#include "study.h"
#include "summary.h"
#include "teleport.h"
#include "kernel/calendar.h"
#include "kernel/config.h"
#include "kernel/alliance.h"
#include "kernel/building.h"
#include "kernel/build.h"
#include "kernel/curse.h"
#include "kernel/unit.h"
#include "kernel/terrain.h"
#include "kernel/messages.h"
#include "kernel/region.h"
#include "kernel/building.h"
#include "kernel/plane.h"
#include "kernel/race.h"
#include "kernel/item.h"
#include "kernel/order.h"
#include "kernel/ship.h"
#include "kernel/faction.h"
#include "kernel/region.h"
#include "kernel/save.h"
#include "kernel/ship.h"
#include "kernel/spell.h"
#include "kernel/types.h"
#include "kernel/item.h"
#include "kernel/faction.h"
#include "kernel/spellbook.h"
#include "races/races.h"
#include "bind_unit.h"
#include "bind_storage.h"
#include "bind_building.h"
#include "bind_message.h"
#include "bind_building.h"
#include "bind_faction.h"
@ -36,42 +45,31 @@
#include "bind_gmtool.h"
#include "bind_region.h"
#include "helpers.h"
#include "console.h"
#include "reports.h"
#include "study.h"
#include "economy.h"
#include "summary.h"
#include "teleport.h"
#include "laws.h"
#include "monsters.h"
#include "market.h"
#include <modules/score.h>
#include <attributes/key.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/language.h>
#include <util/lists.h>
#include <util/log.h>
#include <util/macros.h>
#include <util/nrmessage.h>
#include <util/message.h>
#include <util/rand.h>
#include <util/rng.h>
#include <selist.h>
#include <storage.h>
#include <iniparser.h>
#include <dictionary.h>
#include <tolua.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <time.h>
#include <errno.h>
#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TOLUA_PKG(NAME) void tolua_##NAME##_open(lua_State * L)
@ -153,15 +151,6 @@ int tolua_itemlist_next(lua_State * L)
return 0;
}
static int tolua_getkey(lua_State * L)
{
const char *name = tolua_tostring(L, 1, 0);
int flag = atoi36(name);
lua_pushboolean(L, key_get(global.attribs, flag));
return 1;
}
static int tolua_translate(lua_State * L)
{
const char *str = tolua_tostring(L, 1, 0);
@ -175,20 +164,6 @@ static int tolua_translate(lua_State * L)
return 0;
}
static int tolua_setkey(lua_State * L)
{
const char *name = tolua_tostring(L, 1, 0);
int value = (int)tolua_tonumber(L, 3, 0);
int flag = atoi36(name);
if (value) {
key_set(&global.attribs, flag, value);
}
else {
key_unset(&global.attribs, flag);
}
return 0;
}
static int tolua_random(lua_State * L)
{
lua_pushinteger(L, rng_int());
@ -365,13 +340,6 @@ static int tolua_update_owners(lua_State * L)
return 0;
}
static int tolua_update_subscriptions(lua_State * L)
{
UNUSED_ARG(L);
update_subscriptions();
return 0;
}
static int tolua_remove_empty_units(lua_State * L)
{
UNUSED_ARG(L);
@ -470,7 +438,14 @@ static int tolua_write_passwords(lua_State * L)
{
int result = writepasswd();
lua_pushinteger(L, result);
return 0;
return 1;
}
static int tolua_write_database(lua_State * L)
{
int result = gamedb_update();
lua_pushinteger(L, result);
return 1;
}
static int tolua_write_summary(lua_State * L)
@ -982,6 +957,7 @@ int tolua_bindings_open(lua_State * L, const dictionary *inifile)
tolua_function(L, TOLUA_CAST "write_report", tolua_write_report);
tolua_function(L, TOLUA_CAST "write_summary", tolua_write_summary);
tolua_function(L, TOLUA_CAST "write_passwords", tolua_write_passwords);
tolua_function(L, TOLUA_CAST "write_database", tolua_write_database);
tolua_function(L, TOLUA_CAST "message_unit", tolua_message_unit);
tolua_function(L, TOLUA_CAST "message_faction", tolua_message_faction);
tolua_function(L, TOLUA_CAST "message_region", tolua_message_region);
@ -998,13 +974,10 @@ int tolua_bindings_open(lua_State * L, const dictionary *inifile)
tolua_function(L, TOLUA_CAST "dice_roll", tolua_dice_rand);
tolua_function(L, TOLUA_CAST "get_nmrs", tolua_get_nmrs);
tolua_function(L, TOLUA_CAST "remove_empty_units", tolua_remove_empty_units);
tolua_function(L, TOLUA_CAST "update_subscriptions", tolua_update_subscriptions);
tolua_function(L, TOLUA_CAST "update_scores", tolua_update_scores);
tolua_function(L, TOLUA_CAST "update_owners", tolua_update_owners);
tolua_function(L, TOLUA_CAST "learn_skill", tolua_learn_skill);
tolua_function(L, TOLUA_CAST "create_curse", tolua_create_curse);
tolua_function(L, TOLUA_CAST "get_key", tolua_getkey);
tolua_function(L, TOLUA_CAST "set_key", tolua_setkey);
tolua_function(L, TOLUA_CAST "translate", &tolua_translate);
tolua_function(L, TOLUA_CAST "spells", tolua_get_spells);
tolua_function(L, TOLUA_CAST "equip_newunits", tolua_equip_newunits);

View file

@ -34,7 +34,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/terrainid.h>
#include <kernel/unit.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/rng.h>
#include <stdlib.h>

92
src/checker.c Normal file
View file

@ -0,0 +1,92 @@
#ifdef _MSV_VER
#include <platform.h>
#endif
#include "util/order_parser.h"
#include "util/keyword.h"
#include "util/language.h"
#include "util/path.h"
#include "util/pofile.h"
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
typedef struct parser_state {
FILE * F;
} parser_state;
static void handle_order(void *userData, const char *str) {
parser_state * state = (parser_state*)userData;
fputs(str, state->F);
fputc('\n', state->F);
}
int parsefile(FILE *F) {
OP_Parser parser;
char buf[1024];
int done = 0, err = 0;
parser_state state = { NULL };
state.F = stdout;
parser = OP_ParserCreate();
OP_SetOrderHandler(parser, handle_order);
OP_SetUserData(parser, &state);
while (!done) {
size_t len = (int)fread(buf, 1, sizeof(buf), F);
if (ferror(F)) {
/* TODO: error message */
err = errno;
break;
}
done = feof(F);
if (OP_Parse(parser, buf, len, done) == OP_STATUS_ERROR) {
/* TODO: error message */
err = (int)OP_GetErrorCode(parser);
break;
}
}
OP_ParserFree(parser);
return err;
}
static int handle_po(const char *msgid, const char *msgstr, const char *msgctxt, void *data) {
struct locale *lang = (struct locale *)data;
if (msgctxt) {
if (strcmp(msgctxt, "keyword") == 0) {
keyword_t kwd = findkeyword(msgid);
init_keyword(lang, kwd, msgstr);
locale_setstring(lang, mkname("keyword", keywords[kwd]), msgstr);
}
}
return 0;
}
static void read_config(const char *respath) {
char path[PATH_MAX];
struct locale *lang;
lang = get_or_create_locale("de");
path_join(respath, "translations/strings.de.po", path, sizeof(path));
pofile_read(path, handle_po, lang);
}
int main(int argc, char **argv) {
FILE * F = stdin;
if (argc > 1) {
const char *filename = argv[1];
F = fopen(filename, "r");
if (!F) {
perror(filename);
return -1;
}
}
read_config("../git");
parsefile(F);
if (F != stdin) {
fclose(F);
}
return 0;
}

View file

@ -5,13 +5,12 @@
/* lua includes */
#include <lua.h>
#include <luaconf.h>
#include <lauxlib.h>
#include <lualib.h>
/* libc includes */
#include <assert.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

View file

@ -64,7 +64,7 @@ without prior permission by the authors of Eressea.
#include "kernel/unit.h"
/* util includes */
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/crmessage.h>
#include <util/strings.h>
@ -673,9 +673,7 @@ static void cr_output_building(struct stream *out, building *b,
if (fno >= 0) {
stream_printf(out, "%d;Partei\n", fno);
}
if (b->besieged) {
stream_printf(out, "%d;Belagerer\n", b->besieged);
}
cr_output_curses(out, f, b, TYP_BUILDING);
}
@ -780,7 +778,6 @@ void cr_output_unit(stream *out, const faction * f,
const item_type *lasttype;
int pr;
item *itm, *show = NULL;
building *b;
const char *pzTmp;
skill *sv;
item result[MAX_INVENTORY];
@ -879,9 +876,6 @@ void cr_output_unit(stream *out, const faction * f,
if (is_guard(u)) {
stream_printf(out, "%d;bewacht\n", 1);
}
if ((b = usiege(u)) != NULL) {
stream_printf(out, "%d;belagert\n", b->no);
}
/* additional information for own units */
if (u->faction == f || omniscient(f)) {
order *ord;

View file

@ -3,7 +3,6 @@
#include "move.h"
#include "spy.h"
#include "travelthru.h"
#include "keyword.h"
#include <kernel/ally.h>
#include <kernel/building.h>
@ -17,6 +16,7 @@
#include <kernel/spell.h>
#include <kernel/spellbook.h>
#include "util/keyword.h"
#include <util/language.h>
#include <util/lists.h>
#include <util/message.h>

View file

@ -20,7 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifdef _MSC_VER
#include <platform.h>
#endif
#include <kernel/config.h>
#include "economy.h"
#include "alchemy.h"
@ -45,10 +45,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* kernel includes */
#include "kernel/ally.h"
#include "kernel/attrib.h"
#include "kernel/building.h"
#include "kernel/calendar.h"
#include "kernel/config.h"
#include "kernel/curse.h"
#include "kernel/equipment.h"
#include "kernel/event.h"
#include "kernel/faction.h"
#include "kernel/item.h"
#include "kernel/messages.h"
@ -64,13 +67,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "kernel/unit.h"
/* util includes */
#include <util/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <util/goodies.h>
#include <util/language.h>
#include <util/lists.h>
#include <util/log.h>
#include "util/param.h"
#include <util/parser.h>
#include <util/rng.h>
@ -103,6 +105,8 @@ static void recruit_init(void)
}
}
#define ENTERTAINFRACTION 20
int entertainmoney(const region * r)
{
double n;
@ -978,11 +982,6 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want)
}
}
if (besieged(u)) {
cmistake(u, u->thisorder, 60, MSG_PRODUCE);
return;
}
if (rtype->modifiers) {
message *msg = get_modifiers(u, sk, rtype, &save_mod, &skill_mod);
if (msg) {
@ -1604,11 +1603,6 @@ static void buy(unit * u, econ_request ** buyorders, struct order *ord)
cmistake(u, ord, 26, MSG_COMMERCE);
return;
}
if (besieged(u)) {
/* Belagerte Einheiten k<>nnen nichts kaufen. */
cmistake(u, ord, 60, MSG_COMMERCE);
return;
}
/* Entweder man ist Insekt in Sumpf/Wueste, oder es muss
* einen Handelsposten in der Region geben: */
@ -1666,7 +1660,7 @@ static void buy(unit * u, econ_request ** buyorders, struct order *ord)
return;
}
}
if (r_demand(r, ltype)) {
if (!r->land || r_demand(r, ltype)) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "luxury_notsold", ""));
return;
}
@ -1708,6 +1702,7 @@ static void expandselling(region * r, econ_request * sellorders, int limit)
static int bt_cache;
static const struct building_type *castle_bt, *harbour_bt, *caravan_bt;
assert(r->land);
if (bt_changed(&bt_cache)) {
castle_bt = bt_find("castle");
harbour_bt = bt_find("harbour");
@ -1927,12 +1922,6 @@ static bool sell(unit * u, econ_request ** sellorders, struct order *ord)
return false;
}
}
/* Belagerte Einheiten k<>nnen nichts verkaufen. */
if (besieged(u)) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error60", ""));
return false;
}
/* In der Region mu<6D> es eine Burg geben. */
if (u_race(u) == get_race(RC_INSECT)) {
@ -1977,7 +1966,7 @@ static bool sell(unit * u, econ_request ** sellorders, struct order *ord)
econ_request *o;
int k, available;
if (!r_demand(r, ltype)) {
if (!r->land || !r_demand(r, ltype)) {
cmistake(u, ord, 263, MSG_COMMERCE);
return false;
}
@ -2406,10 +2395,6 @@ void entertain_cmd(unit * u, struct order *ord)
cmistake(u, ord, 58, MSG_INCOME);
return;
}
if (besieged(u)) {
cmistake(u, ord, 60, MSG_INCOME);
return;
}
if (u->ship && is_guarded(r, u)) {
cmistake(u, ord, 69, MSG_INCOME);
return;
@ -2498,11 +2483,6 @@ static int do_work(unit * u, order * ord, econ_request * o)
cmistake(u, ord, 313, MSG_INCOME);
return -1;
}
if (besieged(u)) {
if (ord)
cmistake(u, ord, 60, MSG_INCOME);
return -1;
}
if (u->ship && is_guarded(r, u)) {
if (ord)
cmistake(u, ord, 69, MSG_INCOME);
@ -2611,10 +2591,6 @@ void tax_cmd(unit * u, struct order *ord, econ_request ** taxorders)
return;
}
if (besieged(u)) {
cmistake(u, ord, 60, MSG_INCOME);
return;
}
n = armedmen(u, false);
if (!n) {
@ -2685,10 +2661,6 @@ void loot_cmd(unit * u, struct order *ord, econ_request ** lootorders)
return;
}
if (besieged(u)) {
cmistake(u, ord, 60, MSG_INCOME);
return;
}
n = armedmen(u, false);
if (!n) {

View file

@ -19,7 +19,7 @@
#include <kernel/terrainid.h>
#include <kernel/unit.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/language.h>
#include <util/macros.h>
@ -487,6 +487,7 @@ static void test_recruit_insect(CuTest *tc) {
test_setup();
test_create_calendar();
test_create_terrain("desert", -1);
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);

View file

@ -1,14 +1,13 @@
#include <platform.h>
#include "eressea.h"
#include "kernel/building.h"
#include "kernel/calendar.h"
#include "kernel/config.h"
#include "kernel/curse.h"
#include "kernel/faction.h"
#include "kernel/building.h"
#include "kernel/equipment.h"
#include "kernel/faction.h"
#include "kernel/item.h"
#include "kernel/database.h"
#include "util/functions.h"
#include "util/language.h"
@ -28,6 +27,7 @@
#include "creport.h"
#include "report.h"
#include "names.h"
#include "orderdb.h"
#include "reports.h"
#include "spells.h"
#include "vortex.h"
@ -54,12 +54,12 @@ void game_done(void)
free_locales();
#endif
kernel_done();
dblib_close();
orderdb_close();
}
void game_init(void)
{
dblib_open();
orderdb_open();
errno = 0;
kernel_init();
register_triggers();

31
src/gamedb.c Normal file
View file

@ -0,0 +1,31 @@
#ifdef _MSC_VER
#include <platform.h>
#endif
#include "gamedb.h"
#include "kernel/config.h"
#include "kernel/calendar.h"
#include "kernel/faction.h"
#include "kernel/db/driver.h"
int gamedb_update(void)
{
faction *f;
int err;
const char *dbname;
dbname = config_get("game.dbname");
err = db_driver_open(DB_GAME, dbname);
if (err == 0) {
for (f = factions; f; f = f->next) {
int uid = db_driver_faction_save(f->uid, f->no, turn, f->email, f->_password);
if (uid > 0) {
f->uid = uid;
}
}
db_driver_close(DB_GAME);
}
return err;
}

3
src/gamedb.h Normal file
View file

@ -0,0 +1,3 @@
#pragma once
int gamedb_update(void);

View file

@ -25,6 +25,8 @@
#include <attributes/racename.h>
/* kernel includes */
#include <kernel/attrib.h>
#include <kernel/event.h>
#include <kernel/ally.h>
#include <kernel/build.h>
#include <kernel/curse.h>
@ -41,11 +43,10 @@
#include <kernel/unit.h>
/* util includes */
#include <util/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <util/log.h>
#include <util/macros.h>
#include <util/param.h>
#include <util/parser.h>
/* libc includes */

View file

@ -16,6 +16,7 @@
#include <util/base36.h>
#include <util/language.h>
#include <util/message.h>
#include <util/param.h>
#include <CuTest.h>
#include <tests.h>

View file

@ -18,49 +18,35 @@
#include "gmtool.h"
#include <modules/xmas.h>
#include <modules/gmcmd.h>
#include <modules/museum.h>
#include <modules/autoseed.h>
#include "kernel/building.h"
#include "kernel/calendar.h"
#include "kernel/faction.h"
#include "kernel/item.h"
#include "kernel/plane.h"
#include "kernel/race.h"
#include "kernel/region.h"
#include "kernel/terrainid.h"
#include "kernel/unit.h"
#include "kernel/resources.h"
#include "kernel/save.h"
#include "kernel/ship.h"
#include "kernel/terrain.h"
#include <attributes/attributes.h>
#include <triggers/triggers.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/lists.h>
#include <util/log.h>
#include <util/macros.h>
#include <util/path.h>
#include <util/rng.h>
#include <util/unicode.h>
#include "util/path.h"
#include "util/rng.h"
#include "util/unicode.h"
#include "gmtool_structs.h"
#include "console.h"
#include "listbox.h"
#include "wormhole.h"
#include "teleport.h"
#include <storage.h>
#include <lua.h>
#include <assert.h>
#include <locale.h>
#include <limits.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
@ -932,20 +918,10 @@ static void seed_player(state *st, const newfaction *player) {
pnormalize(&nx, &ny, st->cursor.pl);
r = findregion(nx, ny);
if (r) {
const char *at = strchr(player->email, '@');
faction *f;
addplayer(r, f = addfaction(player->email, player->password,
player->race, player->lang,
player->subscription));
if (at) {
char fname[64];
size_t len = at - player->email;
if (len>4 && len<sizeof(fname)) {
memcpy(fname, player->email, len);
fname[len]=0;
faction_setname(f, fname);
}
}
const char *password = player->password ? player->password : itoa36(rng_int());
addplayer(r, f = addfaction(player->email, password,
player->race, player->lang));
}
}
}

View file

@ -105,8 +105,6 @@ static bool is_guardian_r(const unit * guard)
{
if (guard->number == 0)
return false;
if (besieged(guard))
return false;
/* if region_owners exist then they may be guardians: */
if (guard->building && rule_region_owners() && guard == building_owner(guard->building)) {

View file

@ -17,26 +17,21 @@ without prior permission by the authors of Eressea.
#include "helpers.h"
#include "vortex.h"
#include "alchemy.h"
#include "magic.h"
#include <util/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <kernel/attrib.h>
#include <kernel/event.h>
#include <util/functions.h>
#include <util/gamedata.h>
#include <kernel/gamedata.h>
#include <util/log.h>
#include <util/macros.h>
#include <util/parser.h>
#include <util/resolve.h>
#include <util/variant.h>
#include <kernel/callbacks.h>
#include <kernel/config.h>
#include <kernel/callbacks.h>
#include <kernel/faction.h>
#include <kernel/spell.h>
#include <kernel/race.h>
#include <kernel/resources.h>
#include <kernel/unit.h>
#include <kernel/building.h>
#include <kernel/item.h>
#include <kernel/region.h>
@ -46,8 +41,10 @@ without prior permission by the authors of Eressea.
#include <lua.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
struct order;
static int
lua_giveitem(unit * s, unit * d, const item_type * itype, int n, struct order *ord)

View file

@ -14,8 +14,6 @@ without prior permission by the authors of Eressea.
extern "C" {
#endif
struct lua_State;
void register_tolua_helpers(void);
#ifdef __cplusplus

View file

@ -5,7 +5,6 @@
#include "alchemy.h"
#include "skill.h"
#include "keyword.h"
#include "direction.h"
#include "study.h"
#include "economy.h"
@ -33,8 +32,9 @@
#include <triggers/changerace.h>
#include <triggers/timeout.h>
#include <util/attrib.h>
#include <util/event.h>
#include <kernel/attrib.h>
#include <kernel/event.h>
#include <util/keyword.h>
#include <util/macros.h>
#include <util/parser.h>
#include <util/rand.h>

View file

@ -31,7 +31,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <attributes/movement.h>
/* util includes */
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/log.h>
#include <util/macros.h>

View file

@ -29,9 +29,10 @@ without prior permission by the authors of Eressea.
#include "kernel/spellbook.h"
/* util includes */
#include "util/attrib.h"
#include "kernel/attrib.h"
#include "util/crmessage.h"
#include "util/functions.h"
#include "util/keyword.h"
#include "util/language.h"
#include "util/log.h"
#include "util/message.h"
@ -42,7 +43,6 @@ without prior permission by the authors of Eressea.
/* game modules */
#include "direction.h"
#include "keyword.h"
#include "move.h"
#include "prefix.h"
#include "skill.h"
@ -846,7 +846,7 @@ static void json_keyword(cJSON *json, struct locale *lang) {
}
for (child = json->child; child; child = child->next) {
keyword_t kwd = findkeyword(child->string);
if (kwd != NOKEYWORD) {
if (kwd != NOKEYWORD && keywords[kwd]) {
if (child->type == cJSON_String) {
init_keyword(lang, kwd, child->valuestring);
locale_setstring(lang, mkname("keyword", keywords[kwd]), child->valuestring);

View file

@ -15,11 +15,11 @@
#include "kernel/order.h"
#include "kernel/terrain.h"
#include "util/keyword.h"
#include "util/language.h"
#include "kernel/calendar.h"
#include "direction.h"
#include "keyword.h"
#include "move.h"
#include "prefix.h"
@ -120,7 +120,7 @@ static void test_disable(CuTest * tc)
const char * data = "{\"disabled\": [ "
"\"alchemy\","
"\"pay\","
"\"besiege\","
"\"attack\","
"\"module\""
"]}";
cJSON *json = cJSON_Parse(data);
@ -129,13 +129,13 @@ static void test_disable(CuTest * tc)
CuAssertTrue(tc, skill_enabled(SK_ALCHEMY));
CuAssertTrue(tc, !keyword_disabled(K_BANNER));
CuAssertTrue(tc, !keyword_disabled(K_PAY));
CuAssertTrue(tc, !keyword_disabled(K_BESIEGE));
CuAssertTrue(tc, !keyword_disabled(K_ATTACK));
CuAssertIntEquals(tc, 1, config_get_int("module.enabled", 1));
json_config(json);
CuAssertTrue(tc, !skill_enabled(SK_ALCHEMY));
CuAssertTrue(tc, !keyword_disabled(K_BANNER));
CuAssertTrue(tc, keyword_disabled(K_PAY));
CuAssertTrue(tc, keyword_disabled(K_BESIEGE));
CuAssertTrue(tc, keyword_disabled(K_ATTACK));
CuAssertIntEquals(tc, 0, config_get_int("module.enabled", 1));
cJSON_Delete(json);
test_teardown();

View file

@ -1,9 +1,18 @@
cmake_minimum_required(VERSION 2.6)
project(kernel C)
SET(_DBFILES db/memory.c)
IF(SQLITE3_FOUND)
SET(_DBFILES db/sqlite.c)
ELSEIF(DB_FOUND)
SET(_DBFILES db/berkeley.c)
ENDIF(SQLITE3_FOUND)
SET(_TEST_FILES
alliance.test.c
ally.test.c
attrib.test.c
build.test.c
building.test.c
# callbacks.test.c
@ -14,12 +23,13 @@ config.test.c
curse.test.c
database.test.c
equipment.test.c
# event.test.c
faction.test.c
gamedata.test.c
group.test.c
item.test.c
messages.test.c
order.test.c
orderdb.test.c
# pathfinder.test.c
plane.test.c
pool.test.c
@ -35,18 +45,11 @@ spell.test.c
unit.test.c
)
SET(_DBFILES db/critbit.c)
IF(SQLITE3_FOUND)
SET(_DBFILES db/sqlite.c)
ELSEIF(DB_FOUND)
SET(_DBFILES db/berkeley.c)
ENDIF(SQLITE3_FOUND)
SET(_FILES
${_DBFILES}
alliance.c
ally.c
attrib.c
build.c
building.c
callbacks.c
@ -55,14 +58,14 @@ command.c
config.c
connection.c
curse.c
database.c
equipment.c
event.c
faction.c
gamedata.c
group.c
item.c
messages.c
order.c
orderdb.c
pathfinder.c
plane.c
pool.c

View file

@ -27,7 +27,7 @@ without prior permission by the authors of Eressea.
#include <attributes/key.h>
/* util includes */
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/language.h>
#include <util/parser.h>

View file

@ -10,9 +10,9 @@
#include "objtypes.h"
#include "plane.h"
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/strings.h>
#include <util/gamedata.h>
#include <kernel/gamedata.h>
#include <storage.h>

View file

@ -19,12 +19,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <platform.h>
#include "attrib.h"
#include "gamedata.h"
#include "log.h"
#include "variant.h"
#include "storage.h"
#include "strings.h"
#include <util/log.h>
#include <util/strings.h>
#include <util/variant.h>
#include <kernel/gamedata.h>
#include <storage.h>
#include <critbit.h>
#include <assert.h>

View file

@ -20,7 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define ATTRIB_H
#include <stdbool.h>
#include "variant.h"
#include <util/variant.h>
#ifdef __cplusplus
extern "C" {
#endif

View file

@ -1,7 +1,7 @@
#include <platform.h>
#include "attrib.h"
#include <util/gamedata.h>
#include <kernel/gamedata.h>
#include <util/strings.h>
#include <storage.h>

View file

@ -33,10 +33,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* kernel includes */
#include <kernel/ally.h>
#include <kernel/alliance.h>
#include <kernel/connection.h>
#include <kernel/attrib.h>
#include <kernel/building.h>
#include <kernel/config.h>
#include <kernel/connection.h>
#include <kernel/curse.h>
#include <kernel/event.h>
#include <kernel/faction.h>
#include <kernel/group.h>
#include <kernel/item.h>
@ -52,12 +54,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/unit.h>
/* from libutil */
#include <util/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <util/goodies.h>
#include <util/language.h>
#include <util/log.h>
#include <util/param.h>
#include <util/parser.h>
#include <util/resolve.h>
@ -79,7 +80,7 @@ struct building *getbuilding(const struct region *r)
ship *getship(const struct region * r)
{
ship *sh, *sx = findship(getshipid());
ship *sh, *sx = findship(getid());
for (sh = r->ships; sh; sh = sh->next) {
if (sh == sx)
return sh;
@ -279,10 +280,6 @@ void build_road(unit * u, int size, direction_t d)
cmistake(u, u->thisorder, 103, MSG_PRODUCE);
return;
}
if (besieged(u)) {
cmistake(u, u->thisorder, 60, MSG_PRODUCE);
return;
}
if (rn == NULL || rn->terrain->max_road < 0) {
cmistake(u, u->thisorder, 94, MSG_PRODUCE);
@ -780,11 +777,6 @@ build_building(unit * u, const building_type * btype, int id, int want, order *
cmistake(u, ord, 93, MSG_PRODUCE);
return 0;
}
if (besieged(u)) {
/* units under siege can not build */
cmistake(u, ord, 60, MSG_PRODUCE);
return 0;
}
if (btype->flags & BTF_NOBUILD) {
/* special building, cannot be built */
cmistake(u, ord, 221, MSG_PRODUCE);
@ -949,10 +941,6 @@ create_ship(unit * u, const struct ship_type *newtype, int want,
cmistake(u, ord, 100, MSG_PRODUCE);
return;
}
if (besieged(u)) {
cmistake(u, ord, 60, MSG_PRODUCE);
return;
}
/* check if skill and material for 1 size is available */
if (effskill(u, cons->skill, 0) < cons->minskill) {

View file

@ -1,19 +1,24 @@
#ifdef _MSC_VER
#include <platform.h>
#include <kernel/config.h>
#endif
#include <kernel/messages.h>
#include "alchemy.h"
#include "types.h"
#include "build.h"
#include "guard.h"
#include "order.h"
#include "unit.h"
#include "building.h"
#include "config.h"
#include "faction.h"
#include "region.h"
#include "race.h"
#include "guard.h"
#include "item.h"
#include <util/language.h>
#include "messages.h"
#include "order.h"
#include "race.h"
#include "region.h"
#include "types.h"
#include "unit.h"
#include "util/language.h"
#include "util/param.h"
#include <CuTest.h>
#include <tests.h>

View file

@ -38,13 +38,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "lighthouse.h"
/* util includes */
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <kernel/event.h>
#include <util/functions.h>
#include <util/gamedata.h>
#include <kernel/gamedata.h>
#include <util/language.h>
#include <util/log.h>
#include <util/param.h>
#include <util/resolve.h>
#include <util/strings.h>
#include <util/umlaut.h>
@ -128,14 +129,6 @@ static void free_buildingtype(void *ptr) {
free(btype);
}
void free_buildingtypes(void) {
cb_clear(&cb_bldgtypes);
selist_foreach(buildingtypes, free_buildingtype);
selist_free(buildingtypes);
buildingtypes = 0;
++bt_changes;
}
building_type *bt_get_or_create(const char *name)
{
assert(name && name[0]);
@ -264,17 +257,28 @@ building *findbuilding(int i)
static local_names *bnames;
/* Find the building type for a given localized name (as seen by the user). Useful for parsing
* orders. The inverse of locale_string(lang, btype->_name), sort of. */
const building_type *findbuildingtype(const char *name,
const struct locale *lang)
{
variant type;
local_names *bn = bnames;
static void free_bnames(void) {
while (bnames) {
local_names *bn = bnames;
bnames = bnames->next;
freetokens(bn->names);
free(bn);
}
}
static local_names *get_bnames(const struct locale *lang)
{
static int config;
local_names *bn;
if (bt_changed(&config)) {
free_bnames();
}
bn = bnames;
while (bn) {
if (bn->lang == lang)
if (bn->lang == lang) {
break;
}
bn = bn->next;
}
if (!bn) {
@ -291,14 +295,26 @@ const building_type *findbuildingtype(const char *name,
const char *n = LOC(lang, btype->_name);
if (!n) {
log_error("building type %s has no translation in %s",
btype->_name, locale_name(lang));
} else {
btype->_name, locale_name(lang));
}
else {
variant type;
type.v = (void *)btype;
addtoken((struct tnode **)&bn->names, n, type);
}
}
bnames = bn;
}
return bn;
}
/* Find the building type for a given localized name (as seen by the user). Useful for parsing
* orders. The inverse of locale_string(lang, btype->_name), sort of. */
const building_type *findbuildingtype(const char *name,
const struct locale *lang)
{
variant type;
local_names *bn = get_bnames(lang);
if (findtoken(bn->names, name, &type) == E_TOK_NOMATCH)
return NULL;
return (const building_type *)type.v;
@ -870,3 +886,12 @@ int cmp_current_owner(const building * b, const building * a)
}
return 0;
}
void free_buildingtypes(void) {
free_bnames();
cb_clear(&cb_bldgtypes);
selist_foreach(buildingtypes, free_buildingtype);
selist_free(buildingtypes);
buildingtypes = 0;
++bt_changes;
}

Some files were not shown because too many files have changed in this diff Show more