diff --git a/.gitignore b/.gitignore
index 24219490f..d7c102f5a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,40 +1,44 @@
-.vscode/
-*.orig
-eressea.ini
-Debug
-Release
-
-# SlickEdit
-*.vtg
-*.vpwhistu
-
-# Microsoft Visual Studio build artefacts
-src/Debug/
-src/Release/
-src/*.vcproj.*.user
-Debug/
-Release/
-ipch/
-*.ipch
-*.ncb
-*.opensdf
-*.pdb
-*.sdf
-*.suo
-*.user
-
-*~
-*.bak
-bin/
-build*/
-*.log
-*.log.*
-tags
-Thumbs.db
-.gdb_history
-*.cfg
-*.cmd
-tmp/
-tests/config.lua
-tests/reports/
-tests/data/185.dat
+tolua/
+.vscode/
+*.orig
+eressea.ini
+Debug
+Release
+
+# SlickEdit
+*.vtg
+*.vpwhistu
+
+# Microsoft Visual Studio build artefacts
+src/Debug/
+src/Release/
+src/*.vcproj.*.user
+Debug/
+Release/
+ipch/
+*.ipch
+*.ncb
+*.opensdf
+*.pdb
+*.sdf
+*.suo
+*.user
+
+*~
+*.bak
+bin/
+build*/
+*.log
+*.log.*
+tags
+Thumbs.db
+.gdb_history
+*.cfg
+*.cmd
+tmp/
+tests/config.lua
+tests/reports/
+tests/data/185.dat
+/quicklist/
+/cutest/
+/critbit/
diff --git a/.gitmodules b/.gitmodules
index 2242a8068..7dff5ab6a 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -4,18 +4,9 @@
[submodule "cmake"]
path = cmake
url = https://github.com/ennorehling/cmake.git
-[submodule "quicklist"]
- path = quicklist
- url = https://github.com/ennorehling/quicklist.git
-[submodule "critbit"]
- path = critbit
- url = https://github.com/ennorehling/critbit.git
[submodule "dlmalloc"]
path = dlmalloc
url = https://github.com/ennorehling/dlmalloc.git
-[submodule "cutest"]
- path = cutest
- url = https://github.com/ennorehling/cutest.git
[submodule "iniparser"]
path = iniparser
url = https://github.com/ennorehling/iniparser.git
@@ -26,3 +17,6 @@
path = storage
url = https://github.com/ennorehling/storage.git
branch = master
+[submodule "clibs"]
+ path = clibs
+ url = https://github.com/ennorehling/clibs
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d60d3d721..405b86a03 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,7 +6,6 @@ endif(WIN32)
project (eressea-server C)
-
enable_testing()
find_package (LibXml2)
find_package (SQLite3)
@@ -14,65 +13,14 @@ find_package (Curses)
find_package (Lua REQUIRED)
find_package (ToLua REQUIRED)
-INCLUDE (CheckIncludeFiles)
-INCLUDE (CheckSymbolExists)
-CHECK_INCLUDE_FILES (stdbool.h HAVE_STDBOOL_H)
-CHECK_INCLUDE_FILES (windows.h HAVE_WINDOWS_H)
-CHECK_INCLUDE_FILES (io.h HAVE_IO_H)
-CHECK_INCLUDE_FILES (strings.h HAVE_STRINGS_H)
-CHECK_INCLUDE_FILES (unistd.h HAVE_UNISTD_H)
-IF (HAVE_IO_H)
-CHECK_SYMBOL_EXISTS (_access "io.h" HAVE__ACCESS)
-ENDIF (HAVE_IO_H)
-IF (HAVE_WINDOWS_H)
-CHECK_SYMBOL_EXISTS (_sleep "windows.h" HAVE__SLEEP)
-ENDIF(HAVE_WINDOWS_H)
-IF(HAVE_STDBOOL_H)
-CHECK_SYMBOL_EXISTS (_Bool "stdbool.h" HAVE__BOOL)
-ENDIF(HAVE_STDBOOL_H)
-IF(HAVE_UNISTD_H)
-CHECK_SYMBOL_EXISTS (sleep "unistd.h" HAVE_SLEEP)
-CHECK_SYMBOL_EXISTS (usleep "unistd.h" HAVE_USLEEP)
-CHECK_SYMBOL_EXISTS (access "unistd.h" HAVE_ACCESS)
-ENDIF(HAVE_UNISTD_H)
-CHECK_SYMBOL_EXISTS (strlcpy "string.h" HAVE_STRLCPY)
-CHECK_SYMBOL_EXISTS (strlcat "string.h" HAVE_STRLCAT)
-CHECK_SYMBOL_EXISTS (slprintf "string.h" HAVE_SLPRINTF)
-CHECK_SYMBOL_EXISTS (strcasecmp "string.h" HAVE_STRCASECMP)
-CHECK_SYMBOL_EXISTS (strncasecmp "string.h" HAVE_STRNCASECMP)
-CHECK_SYMBOL_EXISTS (_strlwr "string.h" HAVE__STRLWR)
-CHECK_SYMBOL_EXISTS (_strcmpl "string.h" HAVE__STRCMPL)
-CHECK_SYMBOL_EXISTS (_strdup "string.h" HAVE__STRDUP)
-CHECK_SYMBOL_EXISTS (_stricmp "string.h" HAVE__STRICMP)
-CHECK_SYMBOL_EXISTS (_memicmp "string.h" HAVE__MEMICMP)
-CHECK_SYMBOL_EXISTS (strcmpl "string.h" HAVE_STRCMPL)
-CHECK_SYMBOL_EXISTS (strdup "string.h" HAVE_STRDUP)
-CHECK_SYMBOL_EXISTS (stricmp "string.h" HAVE_STRICMP)
-CHECK_SYMBOL_EXISTS (memicmp "string.h" HAVE_MEMICMP)
-CHECK_SYMBOL_EXISTS (strlwr "string.h" HAVE_STRLWR)
-CHECK_SYMBOL_EXISTS (snprintf "stdio.h" HAVE_SNPRINTF)
-CHECK_SYMBOL_EXISTS (_snprintf "stdio.h" HAVE__SNPRINTF)
-CHECK_SYMBOL_EXISTS (mkdir "sys/stat.h" HAVE_SYS_STAT_MKDIR)
-CHECK_SYMBOL_EXISTS (mkdir "direct.h" HAVE_DIRECT_MKDIR)
-CHECK_SYMBOL_EXISTS (_mkdir "direct.h" HAVE_DIRECT__MKDIR)
-
-CONFIGURE_FILE (
- ${CMAKE_CURRENT_SOURCE_DIR}/autoconf.h.in
- ${CMAKE_BINARY_DIR}/include/autoconf.h)
-INCLUDE_DIRECTORIES (${CMAKE_BINARY_DIR}/include)
-
-## skip compiler/libc detection and force cmake autoconf:
-#add_definitions(-DUSE_AUTOCONF)
-
-add_subdirectory (cutest)
add_subdirectory (cJSON)
add_subdirectory (storage)
add_subdirectory (iniparser)
-add_subdirectory (quicklist)
-add_subdirectory (critbit)
+add_subdirectory (clibs)
add_subdirectory (process)
add_subdirectory (src eressea)
install(DIRECTORY res conf DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*.xml")
install(DIRECTORY res conf DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*.json")
install(DIRECTORY scripts DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*.lua")
+install(DIRECTORY lunit DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*.lua")
install(DIRECTORY share DESTINATION ${CMAKE_INSTALL_PREFIX})
diff --git a/autoconf.h.in b/autoconf.h.in
deleted file mode 100644
index f3f197db1..000000000
--- a/autoconf.h.in
+++ /dev/null
@@ -1,36 +0,0 @@
-#pragma once
-#ifndef CMAKE_AUTOCONF_H
-#define CMAKE_AUTOCONF_H
-#cmakedefine HAVE_STDBOOL_H 1
-#cmakedefine HAVE_STRINGS_H 1
-#cmakedefine HAVE_WINDOWS_H 1
-#cmakedefine HAVE_IO_H 1
-#cmakedefine HAVE_UNISTD_H 1
-#cmakedefine HAVE__BOOL 1
-#cmakedefine HAVE_STRCASECMP 1
-#cmakedefine HAVE_STRNCASECMP 1
-#cmakedefine HAVE__STRICMP 1
-#cmakedefine HAVE_SNPRINTF 1
-#cmakedefine HAVE__SNPRINTF 1
-#cmakedefine HAVE_ACCESS 1
-#cmakedefine HAVE__ACCESS 1
-#cmakedefine HAVE_SLEEP 1
-#cmakedefine HAVE_USLEEP 1
-#cmakedefine HAVE__SLEEP 1
-#cmakedefine HAVE_STRDUP 1
-#cmakedefine HAVE__STRDUP 1
-#cmakedefine HAVE_STRICMP 1
-#cmakedefine HAVE__STRCMPL 1
-#cmakedefine HAVE_STRCMPL 1
-#cmakedefine HAVE__MEMICMP 1
-#cmakedefine HAVE_MEMICMP 1
-#cmakedefine HAVE__STRLWR 1
-#cmakedefine HAVE_STRLWR 1
-#cmakedefine HAVE_STRLCPY 1
-#cmakedefine HAVE_STRLCAT 1
-#cmakedefine HAVE_SLPRINTF 1
-#cmakedefine HAVE_SYS_STAT_MKDIR 1
-#cmakedefine HAVE_DIRECT_MKDIR 1
-#cmakedefine HAVE_DIRECT__MKDIR 1
-
-#endif
diff --git a/clibs b/clibs
new file mode 160000
index 000000000..27c8b3202
--- /dev/null
+++ b/clibs
@@ -0,0 +1 @@
+Subproject commit 27c8b3202b52766465743c3324fc0b52c5ba4b11
diff --git a/conf/e2/config.json b/conf/e2/config.json
index 217cfffe9..f9f9b2df0 100644
--- a/conf/e2/config.json
+++ b/conf/e2/config.json
@@ -5,12 +5,11 @@
"e2/terrains.json"
],
"disabled": [
- "pay",
"jsreport"
],
"settings": {
- "game.id": 2,
- "game.name": "Eressea",
+ "game.name" : "Eressea",
+ "game.id" : 2,
"orders.default": "work",
"NewbieImmunity": 8,
"modules.wormholes": true,
diff --git a/conf/e2/locales.xml b/conf/e2/locales.xml
new file mode 100644
index 000000000..7a31bbc17
--- /dev/null
+++ b/conf/e2/locales.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/conf/e2/config.xml b/conf/e2/rules.xml
similarity index 56%
rename from conf/e2/config.xml
rename to conf/e2/rules.xml
index 0441a46f6..8d0b01b27 100644
--- a/conf/e2/config.xml
+++ b/conf/e2/rules.xml
@@ -1,11 +1,5 @@
-
-
-
-
-
-
@@ -26,10 +20,9 @@
-
-
+
@@ -42,30 +35,8 @@
-
+
-
-
-
-
-
-
-
-
- eressea-server@eressea.kn-bremen.de
- eressea-server@eressea.kn-bremen.de
-
-
- Bitte denke daran, deine Befehle mit dem Betreff
- ERESSEA 2 BEFEHLE an eressea-server@eressea.kn-bremen.de zu senden.
- Remember to send your orders to
- eressea-server@eressea.kn-bremen.de with the subject ERESSEA 2 ORDERS.
-
-
- ERESSEA 2 BEFEHLE
- ERESSEA 2 ORDERS
-
-
diff --git a/conf/e3/config.json b/conf/e3/config.json
index 30bc7e599..1cecc89d2 100644
--- a/conf/e3/config.json
+++ b/conf/e3/config.json
@@ -25,8 +25,8 @@
"jsreport"
],
"settings": {
- "game.id": 3,
- "game.name": "E3",
+ "game.name" : "Eressea",
+ "game.id" : 3,
"orders.default": "work",
"database.gameid": 7,
"NewbieImmunity": 4,
@@ -42,6 +42,7 @@
"nmr.timeout": 5,
"nmr.removenewbie": 0,
"GiveRestriction": 3,
+ "healing.forest": 2.0,
"hunger.long": false,
"hunger.damage": "1d9+9",
"hunger.demons.skill": true,
diff --git a/conf/e3/locales.xml b/conf/e3/locales.xml
new file mode 100644
index 000000000..2d94bf202
--- /dev/null
+++ b/conf/e3/locales.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/conf/e3/config.xml b/conf/e3/rules.xml
similarity index 56%
rename from conf/e3/config.xml
rename to conf/e3/rules.xml
index c8c5dbb06..421b54d7a 100644
--- a/conf/e3/config.xml
+++ b/conf/e3/rules.xml
@@ -1,8 +1,5 @@
-
-
-
@@ -15,8 +12,6 @@
-
-
@@ -28,14 +23,6 @@
-
-
-
-
-
-
-
-
@@ -44,20 +31,4 @@
-
-
- eressea-server@eressea.kn-bremen.de
- eressea-server@eressea.kn-bremen.de
-
-
- Bitte denke daran, deine Befehle mit dem Betreff
- ERESSEA 3 BEFEHLE an eressea-server@eressea.kn-bremen.de zu senden.
- Remember to send your orders to
- eressea-server@eressea.kn-bremen.de with the subject E3 ORDERS.
-
-
- ERESSEA 3 BEFEHLE
- ERESSEA 3 ORDERS
-
-
diff --git a/conf/e4/catalog.xml b/conf/e4/catalog.xml
deleted file mode 100644
index 9987e72c8..000000000
--- a/conf/e4/catalog.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
-
-
-
diff --git a/conf/e4/config.json b/conf/e4/config.json
deleted file mode 100644
index cbe273af6..000000000
--- a/conf/e4/config.json
+++ /dev/null
@@ -1,95 +0,0 @@
-{
- "include": [
- "keywords.json",
- "prefixes.json",
- "e3/terrains.json"
- ],
- "disabled": [
- "herbalism",
- "alchemy",
- "entertainment",
- "espionage",
- "perception",
- "stealth",
- "taxation",
- "trade",
- "besiege",
- "steal",
- "buy",
- "teach",
- "sabotage",
- "spy",
- "tax",
- "entertain",
- "sell",
- "jsreport"
- ],
- "settings": {
- "game.id": 4,
- "game.name": "Deveron",
- "orders.default": "work",
- "database.gameid": 7,
- "NewbieImmunity": 4,
- "modules.astralspace": false,
- "modules.wormholes": false,
- "modules.markets": true,
- "magic.regeneration": 0.75,
- "magic.power": 0.5,
- "resource.factor": 0.25,
- "skills.cost.tactics": 500,
- "entertain.base": 0,
- "entertain.perlevel": 20,
- "nmr.timeout": 5,
- "nmr.removenewbie": 0,
- "GiveRestriction": 3,
- "hunger.long": false,
- "hunger.damage": "1d9+9",
- "hunger.demons.skill": true,
- "hunger.demons.peasant_tolerance": true,
- "init_spells": 0,
- "recruit.allow_merge": true,
- "study.expensivemigrants": true,
- "study.speedup": 2,
- "study.produceexp": 12,
- "world.era": 3,
- "rules.reserve.twophase": true,
- "rules.owners.force_leave": false,
- "rules.transfermen": false,
- "stealth.faction.other": false,
- "rules.stealth.anon_battle": false,
- "rules.check_overload": false,
- "rules.combat.goblinbonus": 3,
- "rules.alliances": true,
- "rules.combat.herospeed": 3,
- "rules.combat.demon_vampire": 5,
- "rules.combat.skill_bonus": 0,
- "rules.combat.nat_armor": 1,
- "rules.items.loot_divisor": 2,
- "rules.items.give_divisor": 2,
- "rules.move.owner_leave": true,
- "rules.region_owners": true,
- "rules.cavalry.skill": 2,
- "rules.cavalry.mode": 1,
- "rules.magic.multipotion": true,
- "rules.magic.wol_effect": 5,
- "rules.magic.factionlist": true,
- "rules.magic.wol_type": 2,
- "rules.blessed_harvest.flags": 1,
- "rules.magic.elfpower": true,
- "rules.magic.playerschools": "gwyrrd illaun draig cerddor",
- "rules.build.other_buildings": true,
- "rules.economy.taxation": 1,
- "rules.food.flags": 2,
- "rules.economy.roqf": 5,
- "rules.economy.herbrot": 0,
- "rules.region_owner_pay_building": "market harbour lighthouse",
- "rules.dwarf_castles": true,
- "rules.limit.faction": 250,
- "rules.grow.formula": 1,
- "rules.tactics.formula": 1,
- "rules.help.mask": "fight guard money give",
- "movement.shipspeed.skillbonus": 6,
- "alliance.auto": "fight",
- "alliance.restricted": "fight"
- }
-}
diff --git a/conf/e4/config.xml b/conf/e4/config.xml
deleted file mode 100644
index b188f7d79..000000000
--- a/conf/e4/config.xml
+++ /dev/null
@@ -1,64 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- eressea-server@eressea.kn-bremen.de
- eressea-server@eressea.kn-bremen.de
-
-
- Bitte denke daran, deine Befehle mit dem Betreff
- ERESSEA 4 BEFEHLE an eressea-server@eressea.kn-bremen.de zu senden.
- Remember to send your orders to
- eressea-server@eressea.kn-bremen.de with the subject ERESSEA 4 ORDERS.
-
-
- ERESSEA 4 BEFEHLE
- ERESSEA 4 ORDERS
-
-
-
diff --git a/conf/eressea.ini b/conf/eressea.ini
index e14d0af50..b6db180ca 100644
--- a/conf/eressea.ini
+++ b/conf/eressea.ini
@@ -1,5 +1,7 @@
-
-[eressea]
+[game]
+email = eressea-server@kn-bremen.de
+sender = Eressea Server
+name = Eressea
base = .
report = reports
verbose = 0
diff --git a/critbit b/critbit
deleted file mode 160000
index 971836241..000000000
--- a/critbit
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 971836241277e37274aa3110344836499816ff21
diff --git a/cutest b/cutest
deleted file mode 160000
index 6e268687d..000000000
--- a/cutest
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 6e268687dbf6ae55afb63210c3753530d216a622
diff --git a/process/compress.sh b/process/compress.sh
index 23b0929dd..116b3d061 100755
--- a/process/compress.sh
+++ b/process/compress.sh
@@ -20,5 +20,5 @@ if [ ! -d $GAME/reports ]; then
fi
cd $GAME/reports
-$HOME/bin/compress.py $TURN "$GAME_NAME"
+$ERESSEA/server/bin/compress.py $TURN "$GAME_NAME"
cd -
diff --git a/process/orders-accept b/process/orders-accept
index 151f0b196..78af0a056 100755
--- a/process/orders-accept
+++ b/process/orders-accept
@@ -3,22 +3,53 @@
from email.Utils import parseaddr
from email.Parser import Parser
-from os import mkdir, rename, stat, utime, unlink, symlink
-from os.path import exists
+import os
+import os.path
+import ConfigParser
from re import compile, IGNORECASE
from stat import ST_MTIME
from string import upper, split, replace
import logging
-from sys import argv, stdin, exit
+import sys
+from sys import stdin
from time import ctime, sleep, time
from socket import gethostname
from rfc822 import parsedate_tz, mktime_tz
-LOG_FILENAME='/home/eressea/log/orders.log'
+if 'ERESSEA' in os.environ:
+ dir = os.environ['ERESSEA']
+elif 'HOME' in os.environ:
+ dir = os.path.join(os.environ['HOME'], '/eressea')
+else: # WTF? No HOME?
+ dir = "/home/eressea/eressea"
+if not os.path.isdir(dir):
+ print "please set the ERESSEA environment variable to the install path"
+ sys.exit(1)
+rootdir = dir
+
+game = int(sys.argv[1])
+gamedir = os.path.join(rootdir, "game-%d" % (game, ))
+frommail = 'eressea-server@kn-bremen.de'
+gamename = 'Eressea'
+sender = '%s Server <%s>' % (gamename, frommail)
+
+inifile = os.path.join(gamedir, 'eressea.ini')
+if not os.path.exists(inifile):
+ print "no such file: " . inifile
+else:
+ config = ConfigParser.ConfigParser()
+ config.read(inifile)
+ if config.has_option('game', 'email'):
+ frommail = config.get('game', 'email')
+ if config.has_option('game', 'name'):
+ gamename = config.get('game', 'name')
+ if config.has_option('game', 'sender'):
+ sender = config.get('game', 'sender')
+ else:
+ sender = "%s Server <%s>" % (gamename, frommail)
+ config = None
prefix = 'turn-'
hostname = gethostname()
-# base directory for all your games:
-rootdir = "/home/eressea"
orderbase = "orders.dir"
sendmail = True
# maximum number of reports per sender:
@@ -28,36 +59,21 @@ writeheaders = True
# reject all html email?
rejecthtml = True
-games = [
- {
- "from" : "Eressea Server ",
- "prefix" : "Eressea"
- },
- {
- "from" : "Eressea Server ",
- "prefix": "E3"
- },
- {
- "from" : "Eressea Server ",
- "prefix": "E4"
- },
-]
-
def unlock_file(filename):
try:
- unlink(filename+".lock")
+ os.unlink(filename+".lock")
except:
print "could not unlock %s.lock, file not found" % filename
def lock_file(filename):
i = 0
wait = 1
- if not exists(filename):
+ if not os.path.exists(filename):
file=open(filename, "w")
file.close()
while True:
try:
- symlink(filename, filename+".lock")
+ os.symlink(filename, filename+".lock")
return
except:
i = i+1
@@ -74,17 +90,17 @@ messages = {
"software and re-send the orders.",
"multipart-de" :
- "FEHLER: Die von dir eingeschickte Mail enthält keinen " \
+ "FEHLER: Die von dir eingeschickte Mail enth�lt keinen " \
"Text. Evtl. hast Du den Zug als HTML oder als anderweitig " \
- "ungültig formatierte Mail ingeschickt. Wir können ihn " \
- "deshalb nicht berücksichtigen. Schicke den Zug nochmals " \
+ "ung�ltig formatierte Mail ingeschickt. Wir k�nnen ihn " \
+ "deshalb nicht ber�cksichtigen. Schicke den Zug nochmals " \
"als reinen Text ohne Formatierungen ein.",
"maildate-de":
- "Es erreichte uns bereits ein Zug mit einem späteren " \
+ "Es erreichte uns bereits ein Zug mit einem sp�teren " \
"Absendedatum (%s > %s). Entweder ist deine " \
"Systemzeit verstellt, oder ein Zug hat einen anderen Zug von " \
- "dir auf dem Transportweg überholt. Entscheidend für die " \
+ "dir auf dem Transportweg �berholt. Entscheidend f�r die " \
"Auswertungsreihenfolge ist das Absendedatum, d.h. der Date:-Header " \
"deiner Mail.",
@@ -173,8 +189,8 @@ def available_file(dirname, basename):
ver = 0
maxdate = 0
filename = "%s/%s,%s,%d" % (dirname, basename, hostname, ver)
- while exists(filename):
- maxdate = max(stat(filename)[ST_MTIME], maxdate)
+ while os.path.exists(filename):
+ maxdate = max(os.stat(filename)[ST_MTIME], maxdate)
ver = ver + 1
filename = "%s/%s,%s,%d" % (dirname, basename, hostname, ver)
if ver >= maxfiles:
@@ -234,7 +250,7 @@ def copy_orders(message, filename, sender):
from os.path import split
dirname, basename = split(filename)
dirname = dirname + '/headers'
- if not exists(dirname): mkdir(dirname)
+ if not os.path.exists(dirname): os.mkdir(dirname)
outfile = open(dirname + '/' + basename, "w")
for name, value in message.items():
outfile.write(name + ": " + value + "\n")
@@ -265,104 +281,94 @@ def copy_orders(message, filename, sender):
# create a file, containing:
# game=0 locale=de file=/path/to/filename email=rcpt@domain.to
def accept(game, locale, stream, extend=None):
- global rootdir, orderbase
+ global rootdir, orderbase, gamedir, gamename, sender
if extend is not None:
orderbase = orderbase + ".pre-" + extend
- gamename = games[game-2]["prefix"]
- gamedir = rootdir+"/eressea/game-%d" % (game, )
- savedir = gamedir+"/"+orderbase
+ savedir = os.path.join(gamedir, orderbase)
# check if it's one of the pre-sent orders.
# create the save-directories if they don't exist
- if not exists(gamedir): mkdir(gamedir)
- if not exists(savedir): mkdir(savedir)
+ if not os.path.exists(gamedir): os.mkdir(gamedir)
+ if not os.path.exists(savedir): os.mkdir(savedir)
# parse message
message = Parser().parse(stream)
- sender = get_sender(message)
- logger = logging.getLogger(sender)
+ email = get_sender(message)
+ logger = logging.getLogger(email)
# write syslog
- if sender is None or valid_email(sender)==0:
- logger.warning("invalid email address: " + str(sender))
+ if email is None or valid_email(email)==0:
+ logger.warning("invalid email address: " + str(email))
return -1
- logger.info("received orders from " + sender)
+ logger.info("received orders from " + email)
# get an available filename
lock_file(gamedir + "/orders.queue")
- maxdate, filename = available_file(savedir, prefix + sender)
+ maxdate, filename = available_file(savedir, prefix + email)
if filename is None:
- logger.warning("more than " + str(maxfiles) + " orders from " + sender)
+ logger.warning("more than " + str(maxfiles) + " orders from " + email)
return -1
# copy the orders to the file
- text_ok = copy_orders(message, filename, sender)
+ text_ok = copy_orders(message, filename, email)
unlock_file(gamedir + "/orders.queue")
warning, msg, fail = None, "", False
maildate = message.get("Date")
if maildate != None:
turndate = mktime_tz(parsedate_tz(maildate))
- utime(filename, (turndate, turndate))
+ os.utime(filename, (turndate, turndate))
logger.debug("mail date is '%s' (%d)" % (maildate, turndate))
if turndate < maxdate:
- logger.warning("inconsistent message date " + sender)
+ logger.warning("inconsistent message date " + email)
warning = " (" + messages["warning-" + locale] + ")"
msg = msg + formatpar(messages["maildate-" + locale] % (ctime(maxdate),ctime(turndate)), 76, 2) + "\n"
else:
- logger.warning("missing message date " + sender)
+ logger.warning("missing message date " + email)
warning = " (" + messages["warning-" + locale] + ")"
msg = msg + formatpar(messages["nodate-" + locale], 76, 2) + "\n"
if not text_ok:
warning = " (" + messages["error-" + locale] + ")"
msg = msg + formatpar(messages["multipart-" + locale], 76, 2) + "\n"
- logger.warning("rejected - no text/plain in orders from " + sender)
- unlink(filename)
+ logger.warning("rejected - no text/plain in orders from " + email)
+ os.unlink(filename)
savedir = savedir + "/rejected"
- if not exists(savedir): mkdir(savedir)
+ if not os.path.exists(savedir): os.mkdir(savedir)
lock_file(gamedir + "/orders.queue")
- maxdate, filename = available_file(savedir, prefix + sender)
+ maxdate, filename = available_file(savedir, prefix + email)
store_message(message, filename)
unlock_file(gamedir + "/orders.queue")
fail = True
if sendmail and warning is not None:
- frommail = games[key]["from"]
subject = gamename + " " + messages["subject-"+locale] + warning
- mail = "Subject: %s\nFrom: %s\nTo: %s\n\n" % (subject, frommail, sender) + msg
+ mail = "Subject: %s\nFrom: %s\nTo: %s\n\n" % (subject, sender, email) + msg
from smtplib import SMTP
server = SMTP("localhost")
- server.sendmail(frommail, sender, mail)
+ server.sendmail(sender, email, mail)
server.close()
if not sendmail:
- print text_ok, fail, sender
+ print text_ok, fail, email
print filename
if not fail:
lock_file(gamedir + "/orders.queue")
queue = open(gamedir + "/orders.queue", "a")
- queue.write("email=%s file=%s locale=%s game=%s\n" % (sender, filename, locale, game))
+ queue.write("email=%s file=%s locale=%s game=%s\n" % (email, filename, locale, game))
queue.close()
unlock_file(gamedir + "/orders.queue")
- logger.info("done - accepted orders from " + sender)
+ logger.info("done - accepted orders from " + email)
return 0
# the main body of the script:
+LOG_FILENAME=os.path.join(rootdir, 'log/orders.log')
logging.basicConfig(level=logging.DEBUG, filename=LOG_FILENAME)
logger = logging
delay=None # TODO: parse the turn delay
-try:
- game = int(argv[1])
-except:
- game = argv[1]
- if game[:3]=='e3a':
- game = 3
- elif game[:7]=='eressea':
- game = 2
-locale = argv[2]
+locale = sys.argv[2]
infile = stdin
-if len(argv)>3:
- infile = open(argv[3], "r")
+if len(sys.argv)>3:
+ infile = open(sys.argv[3], "r")
retval = accept(game, locale, infile, delay)
if infile!=stdin:
infile.close()
-exit(retval)
+sys.exit(retval)
diff --git a/process/orders-process b/process/orders-process
index 753385e2e..b33cc05bf 100755
--- a/process/orders-process
+++ b/process/orders-process
@@ -2,7 +2,9 @@
# -*- coding: iso-8859-1 -*-
from os import unlink, symlink, rename, popen, tmpfile
-from os.path import exists
+import os
+import os.path
+import ConfigParser
from re import compile, IGNORECASE
from string import split, join, upper, strip
from sys import argv, exit
@@ -14,9 +16,8 @@ from epasswd import EPasswd
def pwd_get_email(faction, pwd, pwdfile=None):
return None
-def splitfilename(filename):
- from os.path import split
- return split(filename)
+def split_filename(filename):
+ return os.path.split(filename)
def unlock_file(filename):
try:
@@ -28,7 +29,7 @@ def unlock_file(filename):
def lock_file(filename):
i = 0
wait = 1
- if not exists(filename):
+ if not os.path.exists(filename):
file=open(filename, "w")
file.close()
while True:
@@ -62,17 +63,47 @@ messages = {
"error-en": "Error",
}
+game = int(sys.argv[1])
+echeck_cmd = "/home/eressea/echeck/echeck.sh"
+maxlines = 25
# base directory for all your games:
-rootdir = "/home/eressea/eressea"
-frommail = "Eressea Server "
-orderbase = "orders.dir"
-sendmail = True
-maxlines = 25
-echeck_cmd = "/home/eressea/echeck/echeck.sh"
+install_dir = "/home/eressea/eressea"
+if 'ERESSEA' in os.environ:
+ install_dir = os.environ['ERESSEA']
+elif 'HOME' in os.environ:
+ install_dir = os.path.join(os.environ['HOME'], '/eressea')
+if not os.path.isdir(install_dir):
+ print "please set the ERESSEA environment variable to the install path"
+ sys.exit(1)
+
+game_dir = os.path.join(install_dir, "game-%d" % (game, ))
+frommail = 'eressea-server@kn-bremen.de'
+gamename = 'Eressea'
+sender = '%s Server <%s>' % (gamename, frommail)
+
+inifile = os.path.join(gamedir, 'eressea.ini')
+if not os.path.exists(inifile):
+ print "no such file: " . inifile
+else:
+ config = ConfigParser.ConfigParser()
+ config.read(inifile)
+ if config.has_option('game', 'email'):
+ frommail = config.get('game', 'email')
+ if config.has_option('game', 'name'):
+ gamename = config.get('game', 'name')
+ if config.has_option('game', 'sender'):
+ sender = config.get('game', 'sender')
+ else:
+ sender = "%s Server <%s>" % (gamename, frommail)
+ config = None
+
+queue_file = os.path.join(game_dir, "orders.queue")
+if not os.path.exists(queue_file):
+ exit(0)
# regular expression that finds the start of a faction
-fact_re = compile("^\s*(eressea|vinyambar|partei|faction)\s+([a-zA-Z0-9]+)\s+\"?([^\"]*)\"?", IGNORECASE)
+fact_re = compile("^\s*(eressea|partei|faction)\s+([a-zA-Z0-9]+)\s+\"?([^\"]*)\"?", IGNORECASE)
def check_pwd(filename, email, pw_data):
results = []
@@ -98,7 +129,7 @@ def check_pwd(filename, email, pw_data):
return results
def echeck(filename, locale, rules):
- dirname, filename = splitfilename(filename)
+ dirname, filename = split_filename(filename)
stream = popen("%s %s %s %s %s" % (echeck_cmd, locale, filename, dirname, rules), 'r')
lines = stream.readlines()
if len(lines)==0:
@@ -111,14 +142,6 @@ def echeck(filename, locale, rules):
stream.close()
return mail
-## the main body of the script
-game = int(argv[1])
-
-basedir = rootdir + "/game-%d" % (game, )
-queuename = basedir + "/orders.queue"
-if not exists(queuename):
- exit(0)
-
# parse the queue file -
#print "connecting to SMTP..."
from smtplib import SMTP
@@ -127,16 +150,17 @@ try:
except:
print "could not connect to SMTP server"
exit(0)
+
#print "reading password file..."
-pw_data = EPasswd(basedir + "/passwd")
+pw_data = EPasswd(os.path.join(game_dir,"passwd"))
#print "reading orders.queue..."
# move the queue file to a save space while locking it:
try:
- lock_file(queuename)
+ lock_file(queue_file)
except:
exit(0)
-queuefile = open(queuename, "r")
+queuefile = open(queue_file, "r")
lines = queuefile.readlines()
queuefile.close()
@@ -154,9 +178,9 @@ tmpfile.close()
openlog("orders")
-unlink(queuename)
+unlink(queue_file)
try:
- unlock_file(queuename)
+ unlock_file(queue_file)
except:
pass
@@ -170,15 +194,15 @@ for line in lines:
email = dict["email"]
locale = dict["locale"]
game = int(dict["game"])
- file = dict["file"]
+ infile = dict["file"]
gamename='[E%d]' % game
rules='e%d' % game
warning = ""
failed = True
- results = check_pwd(file, email, pw_data)
- logfile = open(basedir+"/zug.log", "a")
- dirname, filename = splitfilename(file)
- msg = messages["validate-"+locale] + " " + filename + "\n\n"
+ results = check_pwd(infile, email, pw_data)
+ logfile = open(os.path.join(game_dir, "zug.log"), "a")
+ dirname, filename = split_filename(infile)
+ msg = messages["validate-"+locale] + " " + infilename + "\n\n"
for faction, game_email, success, pwd in results:
msg = msg + messages["faction-"+locale] + " " + faction + "\n"
if success: failed = False
@@ -189,25 +213,24 @@ for line in lines:
if failed:
warning = " (" + messages["warning-" + locale] + ")"
- syslog("failed - no valid password in " + file)
+ syslog("failed - no valid password in " + infile)
else:
- result = echeck(file, locale, rules)
- if email=='eressea':
- print result
- continue
- elif result is None:
+ result = None
+ if os.path.exists(echeck_cmd):
+ result = echeck(infile, locale, rules)
+ if result is None:
# echeck did not finish
- msg = msg + "Echeck was killed. Your turn was accepted, but could not be verified.\n"
+ msg = msg + "Echeck is broken. Your turn was accepted, but could not be verified.\n"
warning = " (" + messages["warning-" + locale] + ")"
- syslog("process - echeck got killed, " + file)
+ syslog("process - echeck broken, " + infile)
else:
msg = msg + result
- syslog("process - checked orders in " + file)
+ syslog("process - checked orders in " + infile)
subject = gamename + " " + messages["subject-" + locale] + warning
- msg = "Subject: %s\nFrom: %s\nTo: %s\nContent-Type: text/plain; charset=utf-8\n\n" % (subject, frommail, email) + msg
+ msg = "Subject: %s\nFrom: %s\nTo: %s\nContent-Type: text/plain; charset=utf-8\n\n" % (subject, sender, email) + msg
try:
- server.sendmail(frommail, email, msg)
+ server.sendmail(sender, email, msg)
except:
syslog("failed - cannot send to " + email)
diff --git a/process/send-bz2-report b/process/send-bz2-report
index e9962d539..983564bea 100755
--- a/process/send-bz2-report
+++ b/process/send-bz2-report
@@ -8,7 +8,6 @@ if [ ! -f reports.txt ]; then
exit -2
fi
source $HOME/bin/functions.sh
-source $ERESSEA/etc/eressea.conf
TEMPLATE=report-mail.txt
if [ "$1" == "-Lde" ]
diff --git a/process/sendreport.sh b/process/sendreport.sh
index 1b9af1d35..93d52f0b4 100755
--- a/process/sendreport.sh
+++ b/process/sendreport.sh
@@ -8,7 +8,6 @@ if [ -z $ERESSEA ]; then
exit -2
fi
source $HOME/bin/functions.sh
-source $HOME/etc/eressea.conf
GAME=$1
EMAIL=$2
diff --git a/process/sendreports.sh b/process/sendreports.sh
index fc24200b6..c2bfa741c 100755
--- a/process/sendreports.sh
+++ b/process/sendreports.sh
@@ -8,7 +8,6 @@ if [ -z $ERESSEA ]; then
exit -2
fi
source $HOME/bin/functions.sh
-source $ERESSEA/etc/eressea.conf
if [ ! -z $1 ]; then
GAME=$ERESSEA/game-$1
diff --git a/quicklist b/quicklist
deleted file mode 160000
index f837dd31e..000000000
--- a/quicklist
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit f837dd31e5fcf13c706db1ac2c86b7de3e706578
diff --git a/res/adamantium.xml b/res/adamantium.xml
index cc1cedadc..bb94dfc12 100644
--- a/res/adamantium.xml
+++ b/res/adamantium.xml
@@ -1,13 +1,12 @@
-
+
-
-
diff --git a/res/buildings/castle-2.xml b/res/buildings/castle-2.xml
index 593e9ae5e..7b015d199 100644
--- a/res/buildings/castle-2.xml
+++ b/res/buildings/castle-2.xml
@@ -1,24 +1,23 @@
-
-
+
-
+
-
+
-
+
-
+
-
+
diff --git a/res/buildings/castle.xml b/res/buildings/castle.xml
index 253f49811..6e9140222 100644
--- a/res/buildings/castle.xml
+++ b/res/buildings/castle.xml
@@ -1,26 +1,25 @@
-
-
+
-
+
-
+
-
+
-
+
-
+
-
+
diff --git a/res/core/common/buildings.xml b/res/core/common/buildings.xml
index cf183086b..540e9f085 100644
--- a/res/core/common/buildings.xml
+++ b/res/core/common/buildings.xml
@@ -4,9 +4,7 @@
-
-
-
+
diff --git a/res/core/de/strings.xml b/res/core/de/strings.xml
index b23d44ffb..26e8cc862 100644
--- a/res/core/de/strings.xml
+++ b/res/core/de/strings.xml
@@ -6,6 +6,10 @@
_x: preposition (15 /Schlumpf/schwerter)
_a: including article (ein Schlumpf, a smurf)
-->
+
+ BEFEHLE
+ ORDERS
+
Wirbel
vortex
@@ -908,17 +912,9 @@
Traumschlößchen
-
+
Struktur
-
- Akademie der Künste
- academy of arts
-
-
- Skulptur
- sculpture
-
@@ -2375,19 +2371,19 @@
ghoul
-
+
Juju-Zombie
juju-zombie
-
+
Juju-Zombies
juju-zombies
-
+
Juju-Zombies
juju-zombies
-
+
Juju-Zombie
juju-zombie
@@ -3815,10 +3811,6 @@
Meteorregen
Meteor Shower
-
- Schattenruf
- Shadow Call
-
Erschaffe einen Ring der Regeneration
Create A Ring of Regeneration
@@ -4499,10 +4491,6 @@
Verletzt alle Gegner.
Injures all enemies.
-
- Ruft Schattenwesen.
- Calls beings from shadow.
-
Panik.
Panic.
@@ -6623,53 +6611,17 @@
EINLADEN
INVITE
-
- Steine
- stones
-
-
- Pferde
- horses
-
-
- Bauern
- peasants
-
-
- Silber
- silver
-
-
- Laen
- laen
-
-
-
+
Schößlinge
saplings
-
+
Mallornschößlinge
mallorn saplings
-
- Bäume
- trees
-
-
-
- Mallorn
- mallorn
-
-
-
- Eisen
- iron
-
-
Winter
winter
diff --git a/res/core/en/strings.xml b/res/core/en/strings.xml
index d80c742b9..063194c5d 100644
--- a/res/core/en/strings.xml
+++ b/res/core/en/strings.xml
@@ -310,7 +310,7 @@
dam
-
+
structure
diff --git a/res/core/fr/strings.xml b/res/core/fr/strings.xml
index d1801b338..c69bb5b75 100644
--- a/res/core/fr/strings.xml
+++ b/res/core/fr/strings.xml
@@ -324,7 +324,7 @@
barrage
-
+
bâtiment
@@ -1912,10 +1912,10 @@
zombie
-
+
zombies juju
-
+
zombie juju
diff --git a/res/core/messages.xml b/res/core/messages.xml
index 260f76c70..e312fcc7c 100644
--- a/res/core/messages.xml
+++ b/res/core/messages.xml
@@ -1,5 +1,15 @@
+
+
+
+
+
+ Bitte denke daran, deine Befehle mit dem Betreff
+ $subject an $email zu senden.
+ Remember to send your orders to
+ $email with the subject ${subject}.
+
@@ -1804,7 +1814,7 @@
"$unit($unit) in $region($region): '$order($command)' - Der Magier erschafft ein Traumgebäude."
"$unit($unit) in $region($region): '$order($command)' - The magician creates an illusionary building."
-
+
@@ -1900,10 +1910,9 @@
-
- "$unit($unit) benutzt in $region($region) einen Antimagiekristall."
- "$unit($unit) uses an antimagic crystal in $region($region)."
+ "$unit($unit) benutzt einen Antimagiekristall."
+ "$unit($unit) uses an antimagic crystal."
@@ -2402,7 +2411,7 @@
"Eine Botschaft von $unit.dative($unit) in $region($region): 'Ups! Quack, Quack!'"
"A message from $unit($unit) in $region($region): 'Oops! Croak, Croak!'"
-
+
@@ -2412,7 +2421,7 @@
"$unit($unit) in $region($region): '$order($command)' - $unit($mage) kann Zauber, die durch $unit($unit) gewirkt werden, nicht zusätzlich in die Ferne richten."
"$unit($unit) in $region($region): '$order($command)' - $unit($mage) cannot direct spells that are channeled through $unit($unit) into distant regions."
-
+
@@ -2552,13 +2561,6 @@
"$unit($unit) in $region($region) regeneriert $int($amount) Aura."
"$unit($unit) regenerates $int($amount) aura in $region($region)."
-
-
-
-
- "$string"
- "$string"
-
@@ -2596,13 +2598,6 @@
"$unit($teacher) lehrt $unit($student) $skill($skill)."
"$unit($teacher) teaches $unit($student) $skill($skill)."
-
-
-
-
- "$string"
- "$string"
-
@@ -2834,13 +2829,6 @@
"$unit($unit) baut für $int($size) an $ship($ship) weiter."
"$unit($unit) builds $int($size) more on $ship($ship)."
-
-
-
-
- "$string"
- "$string"
-
@@ -2878,15 +2866,7 @@
"$unit($unit) $if($eq($mode,1),"reitet", "wandert") von $region($start) nach $region($end).$if($isnull($regions),""," Dabei wurde $trail($regions) durchquert.")"
"$unit($unit) $if($eq($mode,1),"rides", "walks") from $region($start) to $region($end)$if($isnull($regions),""," by way of $trail($regions)")."
-
-
-
-
-
- "$unit($unit) entdeckt dass im $direction($direction) $terrain($region) ist."
- "$unit($unit) discovered that $terrain($region) lies in the $direction($direction)."
-
-
+
@@ -2895,7 +2875,7 @@
"$unit($unit) entdeckt, dass $region($region) $localize($terrain) ist."
"$unit($unit) discovered that $region($region) is $localize($terrain)."
-
+
@@ -2903,7 +2883,7 @@
"$unit($unit) ist in dieser Runde gelandet und kann nicht weiter ins Landesinnere nach $region($region) vorstossen."
"$unit($unit) has just landed and cannot continue moving to $region($region)."
-
+
@@ -2911,7 +2891,7 @@
"Die Mannschaft der $ship($ship) kann in letzter Sekunde verhindern, dass das Schiff in $region($region) auf Land aufläuft."
"At the very last moment, the crew of the $ship($ship) saved the ship from running aground in $region($region)."
-
+
@@ -2919,7 +2899,7 @@
"Die $ship($ship) konnte in $region($region) nicht einreisen, die Küste ist zu gefährlich für das Schiff."
"The $ship($ship) could not berth in $region($region). The coast is too dangerous for the vessel."
-
+
@@ -2927,7 +2907,7 @@
"Die Mannschaft der $ship($ship) weigert sich, nach $direction($direction) zu reisen."
"The crew of the $ship($ship) refuses to travel to the $direction($direction)."
-
+
@@ -2935,7 +2915,7 @@
"Die Mannschaft der $ship($ship) weigert sich, nach $region($region) zu reisen."
"The crew of the $ship($ship) refuses to travel to $region($region)."
-
+
@@ -2943,7 +2923,7 @@
"$unit($unit) weigert sich, nach $direction($direction) zu reisen."
"$unit($unit) refuses to travel to the $direction($direction)."
-
+
@@ -2951,7 +2931,7 @@
"$unit($unit) weigert sich, nach $region($region) zu reisen."
"$unit($unit) refuses to travel to $region($region)."
-
+
@@ -2959,7 +2939,7 @@
"Die $ship($ship) konnte $region($region) nicht verlassen."
"The $ship($ship) could not leave $region($region)."
-
+
@@ -2968,35 +2948,7 @@
"$unit($unit) wurde in $region($region) von $unit.dative($guard) aufgehalten."
"$unit($unit) was kept in $region($region) by $unit($guard)."
-
-
-
-
- "Wir haben den Krieg mit $faction($faction) beendet."
- "We declared peace with $faction($faction)."
-
-
-
-
-
- "$faction($faction) hat den Krieg mit uns beendet."
- "$faction($faction) has declared peace with us."
-
-
-
-
-
- "Wir haben $faction($faction) den Krieg erklärt."
- "We declared war on $faction($faction)."
-
-
-
-
-
- "$faction($faction) hat uns den Krieg erklärt."
- "$faction($faction) has declared war on us."
-
-
+
@@ -3005,7 +2957,7 @@
"$unit($unit) konnte nicht von $region($region) nach $region($target) reisen, da der Besitzer der Region es verhinderte."
"$unit($unit) could not travel from $region($region) to $region($target) because the owner denied entrance."
-
+
@@ -3029,7 +2981,7 @@
"$unit($follower) konnte $unit($unit) nicht folgen."
"$unit($follower) could not follow $unit($unit)."
-
+
@@ -3037,7 +2989,7 @@
"$unit($unit) entdeckt, dass es keinen Weg nach $direction($direction) gibt."
"$unit($unit) discovers that there is no route going $direction($direction)."
-
+
@@ -3046,13 +2998,6 @@
"$unit($unit) konnte von $region($region) nicht nach $direction($direction) ausreisen, der Nebel war zu dicht."
"$unit($unit) could not travel $direction($direction) from $region($region), the fog was too dense."
-
-
-
-
- "$string"
- "$string"
-
@@ -3321,20 +3266,6 @@
"$unit($unit) marschiert in eine Antimagiezone und löst sich auf."
"$unit($unit) walks into an antimagical zone and dissolves."
-
-
-
-
- "$unit($unit) hat sich unbemerkt verflüchtigt."
- "$unit($unit) has dissolved without a trace."
-
-
-
-
-
- "$unit($unit) wird sich bald verflüchtigen."
- "$unit($unit) will dissolve soon."
-
@@ -3370,11 +3301,10 @@
-
- "ERESSEA $int36($faction) \"${password}\" - Deine Befehle hatten ein falsches Passwort."
- "ERESSEA $int36($faction) \"${password}\" - Your orders had the wrong password."
+ "Deine Befehle hatten ein falsches Passwort (${password})."
+ "Your orders had the wrong password (${password})."
@@ -6945,13 +6875,6 @@
"$unit($unit) in $region($region): '$order($command)' - Man benötigt mindestens $int($minskill) $skill($skill), um $resource($product,0) zu produzieren."
"$unit($unit) in $region($region): '$order($command)' - You need at least $int($minskill) $skill($skill), to produce $resource($product,0)."
-
-
-
-
- "$string"
- "$string"
-
@@ -6959,13 +6882,6 @@
"$string"
"$string"
-
-
-
-
- "$string"
- "$string"
-
@@ -6997,7 +6913,6 @@
"$unit($target) erhält $int($amount) $resource($resource,$amount) von $unit($unit)."
"$unit($target) receives $int($amount) $resource($resource,$amount) from $unit($unit)."
-
@@ -7200,7 +7115,7 @@
"$unit($unit) in $region($region): '$order($command)' - No pyramids may be build in this region. The closest region to build a pyramid in is between $int($mindist) and $int($maxdist) regions away."
-
+
@@ -7592,16 +7507,6 @@
"$unit($mage) casts $spell($spell). $int($amount) fighters are temporarily losing some of their memories."
-
-
-
-
-
-
- "$unit($mage) ruft $int($amount) $race($race, 0) zu Hilfe."
- "$unit($mage) calls upon the help of $int($amount) $race($race, 0)."
-
-
@@ -7621,7 +7526,7 @@
"Heer $int($index)($abbrev): $int($dead) Tote, $int($fled) Geflohene, $int($survived) Ãœberlebende."
"Army $int($index)($abbrev): $int($dead) dead, $int($fled) fled, $int($survived) survivors."
-
+
diff --git a/res/core/resources/horse.xml b/res/core/resources/horse.xml
index 53699c696..d7f794491 100644
--- a/res/core/resources/horse.xml
+++ b/res/core/resources/horse.xml
@@ -1,5 +1,5 @@
-
+
-
diff --git a/res/core/resources/iron.xml b/res/core/resources/iron.xml
index 3f8897abc..469840669 100644
--- a/res/core/resources/iron.xml
+++ b/res/core/resources/iron.xml
@@ -1,5 +1,5 @@
-
+
-
diff --git a/res/core/resources/laen.xml b/res/core/resources/laen.xml
index 12062bf07..30531c0fe 100644
--- a/res/core/resources/laen.xml
+++ b/res/core/resources/laen.xml
@@ -1,5 +1,5 @@
-
+
-
diff --git a/res/core/resources/log.xml b/res/core/resources/log.xml
index e3a33ef8b..48662878f 100644
--- a/res/core/resources/log.xml
+++ b/res/core/resources/log.xml
@@ -1,5 +1,5 @@
-
+
-
diff --git a/res/core/resources/mallorn.xml b/res/core/resources/mallorn.xml
index 2d301758e..96892b802 100644
--- a/res/core/resources/mallorn.xml
+++ b/res/core/resources/mallorn.xml
@@ -1,12 +1,11 @@
-
+
-
-
diff --git a/res/core/resources/mallornseed.xml b/res/core/resources/mallornseed.xml
index 7a5a0310f..01b8a3416 100644
--- a/res/core/resources/mallornseed.xml
+++ b/res/core/resources/mallornseed.xml
@@ -3,4 +3,8 @@
-
+
+
+
+
diff --git a/res/core/resources/seed.xml b/res/core/resources/seed.xml
index 99f5f5804..2bda26eeb 100644
--- a/res/core/resources/seed.xml
+++ b/res/core/resources/seed.xml
@@ -3,4 +3,8 @@
-
+
+
+
+
diff --git a/res/core/resources/stone.xml b/res/core/resources/stone.xml
index c227dcc5c..91d3aac5d 100644
--- a/res/core/resources/stone.xml
+++ b/res/core/resources/stone.xml
@@ -1,5 +1,5 @@
-
+
-
diff --git a/res/e3a/buildings.xml b/res/e3a/buildings.xml
index c1edbcc0b..9eeca952f 100644
--- a/res/e3a/buildings.xml
+++ b/res/e3a/buildings.xml
@@ -3,17 +3,16 @@
-
+
-
-
+
-
+
-
+
diff --git a/res/e3a/equipment.xml b/res/e3a/equipment.xml
index bbd2ac5b7..9fe133f48 100644
--- a/res/e3a/equipment.xml
+++ b/res/e3a/equipment.xml
@@ -1,78 +1,9 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/res/e3a/races.xml b/res/e3a/races.xml
index 2b0f68b9d..2e5a81aee 100644
--- a/res/e3a/races.xml
+++ b/res/e3a/races.xml
@@ -8,9 +8,8 @@
-
+
-
@@ -32,11 +31,9 @@
-
+
-
-
@@ -47,11 +44,9 @@
-
+
-
-
@@ -76,11 +71,9 @@
-
+
-
-
@@ -104,9 +97,8 @@
-
+
-
@@ -124,10 +116,8 @@
-
+
-
-
@@ -144,9 +134,8 @@
-
+
-
@@ -167,9 +156,8 @@
-
+
-
@@ -192,9 +180,8 @@
-
+
-
@@ -219,9 +206,8 @@
-
+
-
@@ -241,9 +227,8 @@
-
+
-
@@ -263,9 +248,8 @@
-
+
-
@@ -287,9 +271,8 @@
-
+
-
@@ -311,9 +294,8 @@
-
+
-
@@ -334,9 +316,8 @@
-
+
-
@@ -361,9 +342,8 @@
-
+
-
@@ -384,9 +364,8 @@
-
+
-
@@ -409,9 +388,8 @@
-
+
-
@@ -435,10 +413,8 @@
-
+
-
-
@@ -460,9 +436,8 @@
-
+
-
@@ -484,9 +459,8 @@
-
+
-
@@ -507,9 +481,8 @@
-
+
-
@@ -535,9 +508,8 @@
-
+
-
@@ -559,9 +531,8 @@
-
+
-
@@ -582,9 +553,8 @@
-
+
-
@@ -607,24 +577,21 @@
-
-
+
-
+
-
+
-
-
-
+
@@ -672,77 +639,62 @@
-
+
-
-
+
-
-
+
-
-
+
-
+
-
-
+
-
+
-
+
-
-
+
-
-
-
-
-
-
-
-
-
+
-
-
-
+
@@ -768,9 +720,8 @@
-
-
-
+
+
@@ -787,10 +738,8 @@
-
+
-
-
@@ -806,9 +755,8 @@
-
-
-
+
+
@@ -823,10 +771,8 @@
-
+
-
-
@@ -839,9 +785,8 @@
-
-
-
+
+
@@ -855,10 +800,8 @@
-
+
-
-
@@ -871,16 +814,13 @@
-
+
-
-
+
-
-
@@ -889,35 +829,4 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/res/e3a/resources/iron.xml b/res/e3a/resources/iron.xml
index b245da358..7ffe36f1e 100644
--- a/res/e3a/resources/iron.xml
+++ b/res/e3a/resources/iron.xml
@@ -1,11 +1,10 @@
-
+
-
-
diff --git a/res/e3a/resources/mallornseed.xml b/res/e3a/resources/mallornseed.xml
index 4a348c212..576035b34 100644
--- a/res/e3a/resources/mallornseed.xml
+++ b/res/e3a/resources/mallornseed.xml
@@ -1,4 +1,4 @@
-
+
diff --git a/res/e3a/resources/seed.xml b/res/e3a/resources/seed.xml
index 21652f364..62c971540 100644
--- a/res/e3a/resources/seed.xml
+++ b/res/e3a/resources/seed.xml
@@ -1,4 +1,4 @@
-
+
diff --git a/res/e3a/resources/stone.xml b/res/e3a/resources/stone.xml
index 746b79c21..dfb039093 100644
--- a/res/e3a/resources/stone.xml
+++ b/res/e3a/resources/stone.xml
@@ -1,5 +1,5 @@
-
+
-
diff --git a/res/e3a/spellbooks/gray.xml b/res/e3a/spellbooks/gray.xml
index 5967d6265..9c0035e78 100644
--- a/res/e3a/spellbooks/gray.xml
+++ b/res/e3a/spellbooks/gray.xml
@@ -107,7 +107,6 @@
-
diff --git a/res/e3a/spells.xml b/res/e3a/spells.xml
index ec656c18f..74eb89146 100644
--- a/res/e3a/spells.xml
+++ b/res/e3a/spells.xml
@@ -665,9 +665,6 @@
-
-
-
diff --git a/res/eressea/artrewards.xml b/res/eressea/artrewards.xml
index 6cb836c52..2a3c09950 100644
--- a/res/eressea/artrewards.xml
+++ b/res/eressea/artrewards.xml
@@ -1,20 +1,6 @@
-
-
- -
-
-
-
-
-
-
- -
-
-
-
-
-
diff --git a/res/eressea/buildings.xml b/res/eressea/buildings.xml
index 64d65cff0..670ab484e 100644
--- a/res/eressea/buildings.xml
+++ b/res/eressea/buildings.xml
@@ -4,4 +4,5 @@
+
diff --git a/res/eressea/equipment.xml b/res/eressea/equipment.xml
index bf7e38376..efd4f2a3b 100644
--- a/res/eressea/equipment.xml
+++ b/res/eressea/equipment.xml
@@ -2,18 +2,18 @@
-
+
-
+
-
+
@@ -21,30 +21,30 @@
-
+
-
+
-
+
-
+
-
+
-
+
@@ -58,12 +58,12 @@
-
+
-
+
diff --git a/res/eressea/items.xml b/res/eressea/items.xml
index 8b2df7add..69f84c890 100644
--- a/res/eressea/items.xml
+++ b/res/eressea/items.xml
@@ -63,19 +63,6 @@
-
-
- -
-
-
-
-
-
- -
-
-
-
-
diff --git a/res/eressea/races.xml b/res/eressea/races.xml
index 7c3a5ab0c..6deefacc9 100644
--- a/res/eressea/races.xml
+++ b/res/eressea/races.xml
@@ -1,7 +1,7 @@
-
-
+
-
@@ -27,9 +26,8 @@
-
+
-
@@ -61,9 +59,8 @@
-
+
-
@@ -90,9 +87,8 @@
-
+
-
@@ -118,9 +114,8 @@
-
+
-
@@ -148,9 +143,8 @@
-
+
-
@@ -178,9 +172,8 @@
-
+
-
@@ -209,9 +202,8 @@
-
+
-
@@ -244,9 +236,8 @@
-
+
-
@@ -275,9 +266,8 @@
-
+
-
@@ -308,9 +298,8 @@
-
+
-
@@ -339,10 +328,8 @@
-
+
-
-
@@ -370,9 +357,8 @@
-
+
-
@@ -401,9 +387,8 @@
-
+
-
@@ -431,9 +416,8 @@
-
+
-
@@ -463,9 +447,8 @@
-
+
-
@@ -495,9 +478,8 @@
-
+
-
@@ -525,9 +507,8 @@
-
+
-
@@ -558,9 +539,8 @@
-
+
-
@@ -589,25 +569,22 @@
-
-
+
-
+
-
-
-
-
+
@@ -671,69 +648,61 @@
-
+
-
-
+
-
-
+
-
-
+
-
+
-
-
+
-
+
-
+
-
-
+
-
+
-
-
+
-
-
@@ -742,11 +711,8 @@
-
+
-
-
-
@@ -755,11 +721,8 @@
-
+
-
-
-
@@ -769,22 +732,13 @@
-
-
-
-
-
-
-
+
-
-
-
+
-
@@ -801,9 +755,8 @@
-
+
-
@@ -827,9 +780,8 @@
-
+
-
@@ -860,9 +812,8 @@
-
+
-
@@ -889,10 +840,8 @@
-
+
-
-
@@ -921,9 +870,8 @@
-
+
-
@@ -954,8 +902,6 @@
-
-
@@ -978,7 +924,7 @@
-
+
@@ -1011,11 +957,11 @@
-
+
-
+
@@ -1023,7 +969,7 @@
-
+
@@ -1037,9 +983,8 @@
-
-
-
+
+
@@ -1055,10 +1000,8 @@
-
+
-
-
@@ -1073,9 +1016,8 @@
-
-
-
+
+
@@ -1089,10 +1031,8 @@
-
+
-
-
@@ -1104,9 +1044,8 @@
-
-
-
+
+
@@ -1119,10 +1058,8 @@
-
+
-
-
@@ -1134,15 +1071,12 @@
-
+
-
-
+
-
-
@@ -1150,9 +1084,10 @@
-
+
+
-
@@ -1180,10 +1115,8 @@
-
-
+
-
@@ -1208,9 +1141,8 @@
-
+
-
@@ -1240,7 +1172,7 @@
-
+
@@ -1270,10 +1202,8 @@
-
+
-
-
@@ -1282,31 +1212,5 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/res/eressea/spellbooks/gray.xml b/res/eressea/spellbooks/gray.xml
index a7f718f2a..ae7a1f611 100644
--- a/res/eressea/spellbooks/gray.xml
+++ b/res/eressea/spellbooks/gray.xml
@@ -123,7 +123,6 @@
-
diff --git a/res/eressea/spells.xml b/res/eressea/spells.xml
index 5af11913e..1d762f4bd 100644
--- a/res/eressea/spells.xml
+++ b/res/eressea/spells.xml
@@ -471,9 +471,6 @@
-
-
-
diff --git a/res/eressea/strings.xml b/res/eressea/strings.xml
index 61a35ebe5..f7497b810 100644
--- a/res/eressea/strings.xml
+++ b/res/eressea/strings.xml
@@ -352,37 +352,9 @@
-
- Horn des Tanzes
- horn of dancing
-
-
- Hörner des Tanzes
- horns of dancing
-
-
- Miniatur einer Akademie der Künste
- academy of arts in a box
-
-
- Miniaturen einer Akademie der Künste
- academies of arts in a box
-
-
- Miniatur einer Skulptur
- art sculpture in a box
-
-
- Miniaturen einer Skulptur
- art sculptures in a box
-
-
- Gefangener Windgeist
- trapped air elemental
-
-
- Gefangene Windgeister
- trapped air elementals
+
+ Akademie der Künste
+ academy of arts
Auratrank
diff --git a/res/items.xml b/res/items.xml
deleted file mode 100644
index 108e6d398..000000000
--- a/res/items.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-
diff --git a/res/races/aquarian.xml b/res/races/aquarian.xml
index 776f17e93..19fd3aee7 100644
--- a/res/races/aquarian.xml
+++ b/res/races/aquarian.xml
@@ -1,7 +1,6 @@
-
+
-
diff --git a/res/races/cat.xml b/res/races/cat.xml
index 818b24b36..5986c223c 100644
--- a/res/races/cat.xml
+++ b/res/races/cat.xml
@@ -1,7 +1,6 @@
-
+
-
diff --git a/res/races/demon.xml b/res/races/demon.xml
index a350fef4a..69d98145f 100644
--- a/res/races/demon.xml
+++ b/res/races/demon.xml
@@ -1,12 +1,11 @@
-
-
diff --git a/res/races/dragon.xml b/res/races/dragon.xml
index e4a1a7fec..f42037312 100644
--- a/res/races/dragon.xml
+++ b/res/races/dragon.xml
@@ -1,12 +1,10 @@
-
-
-
diff --git a/res/races/dwarf.xml b/res/races/dwarf.xml
index 20fb874c0..043b76aa7 100644
--- a/res/races/dwarf.xml
+++ b/res/races/dwarf.xml
@@ -1,7 +1,6 @@
-
+
-
@@ -30,4 +29,4 @@
-
\ No newline at end of file
+
diff --git a/res/races/elf.xml b/res/races/elf.xml
index dfbd2f2ec..683ee823b 100644
--- a/res/races/elf.xml
+++ b/res/races/elf.xml
@@ -1,7 +1,6 @@
-
+
-
@@ -26,4 +25,4 @@
-
\ No newline at end of file
+
diff --git a/res/races/goblin-2.xml b/res/races/goblin-2.xml
index 9a9c265be..f26fa780e 100644
--- a/res/races/goblin-2.xml
+++ b/res/races/goblin-2.xml
@@ -1,14 +1,12 @@
-
-
-
diff --git a/res/races/goblin-3.xml b/res/races/goblin-3.xml
index e85b0c645..3fd594939 100644
--- a/res/races/goblin-3.xml
+++ b/res/races/goblin-3.xml
@@ -1,14 +1,12 @@
-
-
-
diff --git a/res/races/goblin.xml b/res/races/goblin.xml
index 177c82ffe..a05d127e3 100644
--- a/res/races/goblin.xml
+++ b/res/races/goblin.xml
@@ -1,12 +1,11 @@
-
-
diff --git a/res/races/halfling.xml b/res/races/halfling.xml
index 3875ca414..3628d2b35 100644
--- a/res/races/halfling.xml
+++ b/res/races/halfling.xml
@@ -1,8 +1,7 @@
-
+
-
-
+
diff --git a/res/races/human.xml b/res/races/human.xml
index 2e4b94af2..f91ba7daf 100644
--- a/res/races/human.xml
+++ b/res/races/human.xml
@@ -1,7 +1,6 @@
-
+
-
diff --git a/res/races/insect.xml b/res/races/insect.xml
index cecbf0193..75e16f7af 100644
--- a/res/races/insect.xml
+++ b/res/races/insect.xml
@@ -1,7 +1,6 @@
-
+
-
@@ -27,4 +26,4 @@
-
\ No newline at end of file
+
diff --git a/res/races/orc.xml b/res/races/orc.xml
index d9d26ab25..4f4d96ed5 100644
--- a/res/races/orc.xml
+++ b/res/races/orc.xml
@@ -1,5 +1,5 @@
-
+
diff --git a/res/races/troll.xml b/res/races/troll.xml
index a2341851b..9168a6d0e 100644
--- a/res/races/troll.xml
+++ b/res/races/troll.xml
@@ -1,12 +1,11 @@
-
-
diff --git a/res/races/wyrm.xml b/res/races/wyrm.xml
index b9f95d9ef..dab1a9e1f 100644
--- a/res/races/wyrm.xml
+++ b/res/races/wyrm.xml
@@ -1,11 +1,10 @@
-
-
diff --git a/res/races/youngdragon.xml b/res/races/youngdragon.xml
index 71bc4214b..df10a44e9 100644
--- a/res/races/youngdragon.xml
+++ b/res/races/youngdragon.xml
@@ -1,12 +1,10 @@
-
-
-
diff --git a/res/races/zombie.xml b/res/races/zombie.xml
index 8c23aea83..fdfe97d8e 100644
--- a/res/races/zombie.xml
+++ b/res/races/zombie.xml
@@ -1,5 +1,5 @@
- /dev/null || abort "build failed."
}
function assert_file() {
@@ -79,9 +79,9 @@ SUPP="$SOURCE/share/debian-7_8.supp"
SERVER="$SOURCE/Debug/eressea/eressea"
VALGRIND=$(which valgrind)
if [ ! -z $VALGRIND ]; then
-SERVER="$VALGRIND --suppressions=$SUPP --error-exitcode=1 --leak-check=no $SERVER"
+SERVER="$VALGRIND --quiet --suppressions=$SUPP --error-exitcode=1 --leak-check=no $SERVER"
fi
-$SERVER -v$verbose -t$turn -re$game $SOURCE/scripts/run-turn.lua
+$SERVER -v$verbose -t$turn $SOURCE/scripts/run-turn.lua
let turn=$turn+1
[ -e data/$turn.dat ] || abort "no data file created"
}
@@ -160,7 +160,7 @@ case "$1" in
done
if [ $sent -eq 0 ]; then
if [ -e ../$factions ]; then
- for faction in $(cat ../$factions) ; do
+ for faction in $(grep -v -E '^#' ../$factions) ; do
send $faction
done
fi
diff --git a/s/runtests b/s/runtests
index 58498436f..e42640de1 100755
--- a/s/runtests
+++ b/s/runtests
@@ -15,7 +15,6 @@ cd $ROOT
$ROOT/$BUILD/eressea/eressea -v1 scripts/run-tests.lua
$ROOT/$BUILD/eressea/eressea -v1 scripts/run-tests-e2.lua
$ROOT/$BUILD/eressea/eressea -v1 scripts/run-tests-e3.lua
-$ROOT/$BUILD/eressea/eressea -v1 scripts/run-tests-e4.lua
rm -rf data reports orders.txt score score.alliances datum turn
cd $OLDWPD
diff --git a/s/setup b/s/setup
index 0839d5b8f..e3e8e113d 100755
--- a/s/setup
+++ b/s/setup
@@ -1,5 +1,15 @@
#!/bin/bash
+ROOT=$(pwd)
+while [ ! -d $ROOT/.git ]; do
+ ROOT=$(dirname $ROOT)
+ if [ "/" = "$ROOT" ]; then
+ echo "could not find root, are you in the git repository?"
+ exit
+ fi
+done
+ERESSEA=$(dirname $ROOT)
+
function abort() {
echo $1
[ -z $2 ] && exit -1
@@ -37,7 +47,6 @@ while getopts :d:g:r:s:hfn o; do
done
[ $game -gt 0 ] || abort "must use a positive integer for game id"
-[ -d $ERESSEA ] || abort "invalid or missing env variable ERESSEA ($ERESSEA)"
[ -z $SOURCE ] && SOURCE=$ERESSEA/$src
[ -d $SOURCE ] || abort "invalid source directory $SOURCE"
[ -z $rules ] && rules=e$game
@@ -46,7 +55,8 @@ done
[ -e $TOOLS ] || TOOLS=$SOURCE/bin
[ -z $INIFILE ] && INIFILE=$TOOLS/inifile
[ -e $INIFILE ] || INIFILE=$TOOLS/iniparser/inifile
-#[ -e $INIFILE ] || abort "tool is not installed: $INIFILE"
+
+[ -e $SOURCE/conf/$rules/config.xml ] || abort "cannot find conf/$rules/config.xml"
cd $ERESSEA
if [ -d $dir ] ; then
@@ -84,8 +94,10 @@ touch eressea.ini
}
ini_start
-ini_sec eressea
-ini_add eressea locales de,en
+ini_sec game
+ini_add game locales de,en
+ini_add game id $game
+ini_add game start 1
ini_sec lua
ini_add lua install $SOURCE
ini_add lua paths $SOURCE/scripts:$SOURCE/lunit
diff --git a/s/upgrade b/s/upgrade
new file mode 100755
index 000000000..9d9d5a313
--- /dev/null
+++ b/s/upgrade
@@ -0,0 +1,14 @@
+#!/bin/sh
+set -e
+
+ROOT=`pwd`
+while [ ! -d $ROOT/.git ]; do
+ ROOT=`dirname $ROOT`
+done
+
+cd $ROOT
+git pull
+git submodule update
+s/build
+s/runtests
+s/install
diff --git a/scripts/eressea/autoseed.lua b/scripts/eressea/autoseed.lua
index 562c39361..9e5060f85 100644
--- a/scripts/eressea/autoseed.lua
+++ b/scripts/eressea/autoseed.lua
@@ -1,3 +1,4 @@
+if not config.autoseed then return nil end
local autoseed = {}
-- minimum required resources in the 7-hex neighborhood:
@@ -64,9 +65,9 @@ local function seed(r, email, race, lang)
assert(f)
local u = unit.create(f, r)
assert(u)
- equip_unit(u, "new_faction")
- equip_unit(u, "first_unit")
- equip_unit(u, "first_" .. race, 7) -- disable old callbacks
+ equip_unit(u, "autoseed_faction")
+ equip_unit(u, "autoseed_unit")
+ equip_unit(u, "autoseed_" .. race, 7)
unit.create(f, r, 5):set_skill("mining", 30)
unit.create(f, r, 5):set_skill("quarrying", 30)
f:set_origin(r)
diff --git a/scripts/eressea/e2/init.lua b/scripts/eressea/e2/init.lua
index ed996c395..722078741 100644
--- a/scripts/eressea/e2/init.lua
+++ b/scripts/eressea/e2/init.lua
@@ -11,7 +11,7 @@ return {
require('eressea.tunnels'),
require('eressea.ponnuki'),
require('eressea.astral'),
- require('eressea.locales'),
+-- require('eressea.locales'),
require('eressea.jsreport'),
require('eressea.ents'),
require('eressea.cursed')
diff --git a/scripts/eressea/e4/init.lua b/scripts/eressea/e4/init.lua
deleted file mode 100644
index 32c0b8498..000000000
--- a/scripts/eressea/e4/init.lua
+++ /dev/null
@@ -1,11 +0,0 @@
-require 'eressea.e3.rules'
-require 'eressea.spells'
-
-eressea.log.debug("rules for game E4")
-
-return {
- require('eressea'),
- -- require('eressea.markets'),
- require('eressea.frost'),
- require('eressea.ents')
-}
diff --git a/scripts/eressea/embassy.lua b/scripts/eressea/embassy.lua
index efbe248b7..93ff66d7c 100644
--- a/scripts/eressea/embassy.lua
+++ b/scripts/eressea/embassy.lua
@@ -1,12 +1,14 @@
-- Muschelplateau
+if not config.embassy then return nil end
+
local embassy = {}
local home = nil
-- global exports (use item)
function use_seashell(u, amount)
-- Muschelplateau...
- local visit = u.faction.objects:get("embassy_muschel")
+ local visit = u.faction:get_key('mupL')
if visit and u.region~= home then
local turns = get_turn() - visit
local msg = message.create('msg_event')
@@ -32,10 +34,10 @@ function embassy.update()
eressea.log.debug("updating embassies in " .. tostring(home))
local u
for u in home.units do
- if u.faction.objects:get('embassy_muschel')==nil then
+ if u.faction:get_key('mupL')==0 then
if (u.faction:add_item('seashell', 1)>0) then
eressea.log.debug("new seashell for " .. tostring(u.faction))
- u.faction.objects:set('embassy_muschel', get_turn())
+ u.faction:set_key('mupL', get_turn())
end
end
end
diff --git a/scripts/eressea/eternath.lua b/scripts/eressea/eternath.lua
index 858a8d462..063577b74 100644
--- a/scripts/eressea/eternath.lua
+++ b/scripts/eressea/eternath.lua
@@ -1,5 +1,5 @@
-- DEPRECATED
-
+if not config.eternath then return nil end
-- implements parts of a quest in E2
-- this module is deprecated, because it puts functions in the global environment for at_building_action
diff --git a/scripts/eressea/ponnuki.lua b/scripts/eressea/ponnuki.lua
index 994a16ff0..96bb0b5f1 100644
--- a/scripts/eressea/ponnuki.lua
+++ b/scripts/eressea/ponnuki.lua
@@ -1,3 +1,4 @@
+if not config.ponnuki then return nil end
local ponnuki = {}
local directions = { "NW", "NO", "O", "SO", "SW", "W" }
diff --git a/scripts/eressea/resources.lua b/scripts/eressea/resources.lua
index 94908c1ab..2829d00c7 100644
--- a/scripts/eressea/resources.lua
+++ b/scripts/eressea/resources.lua
@@ -38,8 +38,47 @@ function hp_changeresource(u, delta)
return hp
end
+local function mallorn_region(r)
+ return r:get_flag(1) -- RF_MALLORN
+end
+
+function seed_limit(r)
+ if mallorn_region(r) then
+ return 0
+ end
+ return r:get_resource("seed")
+end
+
+function seed_produce(r, n)
+ if not mallorn_region(r) then
+ local seeds = r:get_resource("seed")
+ if seeds>=n then
+ r:set_resource("seed", seeds-n)
+ else
+ r:set_resource("seed", 0)
+ end
+ end
+end
+
+function mallornseed_limit(r)
+ if mallorn_region(r) then
+ return r:get_resource("seed")
+ end
+ return 0
+end
+
+function mallornseed_produce(r, n)
+ if mallorn_region(r) then
+ local seeds = r:get_resource("seed")
+ if seeds>=n then
+ r:set_resource("seed", seeds-n)
+ else
+ r:set_resource("seed", 0)
+ end
+ end
+end
function horse_limit(r)
- return r:get_resource("horse")
+ return r:get_resource("horse")
end
function horse_produce(r, n)
@@ -52,9 +91,6 @@ function horse_produce(r, n)
end
function log_limit(r)
--- if r:get_flag(1) then -- RF_MALLORN
--- return 0
--- end
return r:get_resource("tree") + r:get_resource("sapling")
end
@@ -75,7 +111,7 @@ function log_produce(r, n)
end
function mallorn_limit(r)
- if not r:get_flag(1) then -- RF_MALLORN
+ if not mallorn_region(r) then
return 0
end
return r:get_resource("tree") + r:get_resource("sapling")
diff --git a/scripts/eressea/wedding.lua b/scripts/eressea/wedding.lua
index 812bd3269..2c06d9891 100644
--- a/scripts/eressea/wedding.lua
+++ b/scripts/eressea/wedding.lua
@@ -1,4 +1,5 @@
-- DEPRECATED
+if not config.wedding then return nil end
-- this script contains the action functions for the two portals
-- used on the jadee/wildente wedding island. the two _action functions
diff --git a/scripts/eressea/xmas.lua b/scripts/eressea/xmas.lua
index 36e755f45..0316e6265 100644
--- a/scripts/eressea/xmas.lua
+++ b/scripts/eressea/xmas.lua
@@ -1,3 +1,5 @@
+if not config.xmas then return nil end
+
local gifts = {
e2 = {
{ year = 2015, turn = 959, item = 'snowglobe', msg='santa_f' },
diff --git a/scripts/eressea/xmlconf.lua b/scripts/eressea/xmlconf.lua
index 9d87f3f3e..84f29eceb 100644
--- a/scripts/eressea/xmlconf.lua
+++ b/scripts/eressea/xmlconf.lua
@@ -4,6 +4,8 @@ if config.install then
end
if config.rules then
local rules = config.rules .. '/'
- assert(0 == read_xml(confdir .. rules .. 'config.xml', confdir .. rules .. 'catalog.xml'), "could not load XML data, did you compile with LIBXML2 ?")
assert(0 == eressea.config.read(rules .. 'config.json', confdir), "could not read JSON data")
+ assert(0 == read_xml(confdir .. rules .. 'rules.xml', confdir .. rules .. 'catalog.xml'), "could not load XML data, did you compile with LIBXML2 ?")
+ assert(0 == read_xml(confdir .. rules .. 'locales.xml', confdir .. rules .. 'catalog.xml'), "could not load XML data, did you compile with LIBXML2 ?")
end
+eressea.game.reset()
diff --git a/scripts/run-tests-e4.lua b/scripts/run-tests-e4.lua
deleted file mode 100644
index f827baec0..000000000
--- a/scripts/run-tests-e4.lua
+++ /dev/null
@@ -1,23 +0,0 @@
--- Tests that work in E3. With game config of E3.
--- Tests are under scripts/test/e3 and all files must be in scripts/test/e3/init.lua
-
-path = 'scripts'
-if config.install then
- path = config.install .. '/' .. path
- package.path = package.path .. ';' .. config.install .. '/lunit/?.lua'
- --needed to find lunit if not run form eressea root. Needs right [lua] install setting in eressea.ini (point to eressea root from the start folder)
-end
-package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua'
-
-config.rules = 'e4'
-
-require 'eressea'
-require 'eressea.path'
-require 'eressea.xmlconf'
-require 'tests.e3'
-require 'lunit'
-
-eressea.settings.set("rules.alliances", "0")
-rules = require('eressea.' .. config.rules)
-result = lunit.main()
-return result.errors + result.failed
diff --git a/scripts/run-turn.lua b/scripts/run-turn.lua
index 7ee9165ca..9118ed8ee 100644
--- a/scripts/run-turn.lua
+++ b/scripts/run-turn.lua
@@ -26,15 +26,17 @@ function callbacks(rules, name, ...)
end
local function dbupdate()
- update_scores()
- dbname = config.dbname or 'eressea.db'
- edb = db.open(config.basepath..'/'..dbname)
- if edb~=nil then
- edb:update_factions()
- edb:update_scores()
- else
- eressea.log.error("could not open "..config.basepath..'/'..dbname)
- end
+ update_scores()
+ if config.dbname then
+ dbname = config.basepath..'/'..config.dbname
+ edb = db.open(dbame)
+ if edb~=nil then
+ edb:update_factions()
+ edb:update_scores()
+ else
+ eressea.log.error("could not open "..dbname)
+ end
+ end
end
local function write_emails(locales)
@@ -144,7 +146,7 @@ function process(rules, orders)
init_summary()
-- run the turn:
- if read_orders(orders) ~= 0 then
+ if eressea.read_orders(orders) ~= 0 then
print("could not read " .. orders)
return -1
end
diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua
index 670060816..03ae5db85 100644
--- a/scripts/tests/common.lua
+++ b/scripts/tests/common.lua
@@ -330,17 +330,6 @@ function test_message()
return msg
end
-function test_hashtable()
- local f = faction.create("noreply1@eressea.de", "human", "de")
- f.objects:set("enno", "smart guy")
- f.objects:set("age", 10)
- assert(f.objects:get("jesus") == nil)
- assert(f.objects:get("enno") == "smart guy")
- assert(f.objects:get("age") == 10)
- f.objects:set("age", nil)
- assert(f.objects:get("age") == nil)
-end
-
function test_events()
local fail = 1
local function msg_handler(u, evt)
@@ -449,10 +438,9 @@ function test_recruit()
u:add_item("money", 110*n+20)
u:add_order("REKRUTIERE " .. n)
process_orders()
- assert(u.number == n+1)
+ assert_equal(n+1, u.number)
local p = r:get_resource("peasant")
- assert(p<200 and p>=200-n)
- -- assert(u:get_item("money")==10)
+ assert_true(p<200 and p>=200-n)
end
function test_produce()
@@ -479,7 +467,7 @@ function test_work()
u:clear_orders()
u:add_order("ARBEITEN")
process_orders()
- assert(u:get_item("money")>=10)
+ assert_equal(20, u:get_item("money"))
end
function test_upkeep()
@@ -491,7 +479,7 @@ function test_upkeep()
u:clear_orders()
u:add_order("LERNE Waffenbau")
process_orders()
- assert(u:get_item("money")==u.number)
+ assert_equal(u:get_item("money"), u.number)
end
function test_id()
@@ -499,50 +487,39 @@ function test_id()
local f = faction.create("noreply11@eressea.de", "human", "de")
f.id = atoi36("42")
- assert(get_faction(42)~=f)
- assert(get_faction("42")==f)
- assert(get_faction(atoi36("42"))==f)
+ assert_not_equal(f, get_faction(42))
+ assert_equal(f, get_faction("42"))
+ assert_equal(f, get_faction(atoi36("42")))
local u = unit.create(f, r, 1)
u.id = atoi36("42")
- assert(get_unit(42)~=u)
- assert(get_unit("42")==u)
- assert(get_unit(atoi36("42"))==u)
+ assert_not_equal(get_unit(42), u)
+ assert_equal(get_unit("42"), u)
+ assert_equal(get_unit(atoi36("42")), u)
local b = building.create(r, "castle")
-- b.id = atoi36("42")
local fortytwo = itoa36(b.id)
- assert(get_building(fortytwo)==b)
- assert(get_building(atoi36(fortytwo))==b)
+ assert_equal(get_building(fortytwo), b)
+ assert_equal(get_building(atoi36(fortytwo)), b)
local s = _test_create_ship(r)
assert_not_nil(s)
-- s.id = atoi36("42")
local fortytwo = itoa36(s.id)
- assert(get_ship(fortytwo)==s)
- assert(get_ship(atoi36(fortytwo))==s)
-end
-
-function test_herbalism()
- local r = region.create(0, 0, "plain")
- local f = faction.create("noreply12@eressea.de", "human", "de")
- local u = unit.create(f, r, 1)
- u:add_item("money", u.number * 100)
- u:set_skill("herbalism", 5)
- u:clear_orders()
- u:add_order("MACHE Samen")
- process_orders()
+ assert_equal(get_ship(fortytwo), s)
+ assert_equal(get_ship(atoi36(fortytwo)), s)
end
function test_mallorn()
local r = region.create(0, 0, "plain")
r:set_flag(1, false) -- not mallorn
r:set_resource("tree", 100)
- assert(r:get_resource("tree")==100)
+ assert_equal(100, r:get_resource("tree"))
local m = region.create(0, 0, "plain")
m:set_flag(1, true) -- mallorn
m:set_resource("tree", 100)
- assert(m:get_resource("tree")==100)
+ assert_equal(100, m:get_resource("tree"))
local f = faction.create("noreply13@eressea.de", "human", "de")
diff --git a/scripts/tests/e2/e2features.lua b/scripts/tests/e2/e2features.lua
index c4a53da76..de94ea34f 100644
--- a/scripts/tests/e2/e2features.lua
+++ b/scripts/tests/e2/e2features.lua
@@ -2,6 +2,38 @@ require "lunit"
module("tests.e2.e2features", package.seeall, lunit.testcase )
+function setup()
+ eressea.free_game()
+ eressea.settings.set("nmr.timeout", "0")
+ eressea.settings.set("rules.food.flags", "4")
+ eressea.settings.set("rules.ship.storms", "0")
+ eressea.settings.set("rules.encounters", "0")
+end
+
+function test_herbalism()
+-- OBS: herbalism is currently an E2-only skill
+ local r = region.create(0, 0, "plain")
+ local f = faction.create("herbalism@eressea.de", "human", "de")
+ local u = unit.create(f, r, 1)
+
+ eressea.settings.set("rules.grow.formula", 0) -- plants do not grow
+ u:add_item("money", u.number * 100)
+ u:set_skill("herbalism", 5)
+ r:set_resource("seed", 100)
+ r:set_flag(1, false) -- regular trees
+ u:clear_orders()
+ u:add_order("MACHE Samen")
+ process_orders()
+ assert_equal(1, u:get_item("seed"))
+ assert_equal(99, r:get_resource("seed"))
+ r:set_flag(1, true) -- mallorn
+ u:clear_orders()
+ u:add_order("MACHE Mallornsamen")
+ process_orders()
+ assert_equal(1, u:get_item("mallornseed"))
+ assert_equal(98, r:get_resource("seed"))
+end
+
function test_build_harbour()
-- try to reproduce mantis bug 2221
local r = region.create(0, 0, "plain")
@@ -42,13 +74,6 @@ local function two_units(r, f1, f2)
return one_unit(r, f1), one_unit(r, f2)
end
-function setup()
- eressea.free_game()
- eressea.settings.set("nmr.timeout", "0")
- eressea.settings.set("rules.food.flags", "4")
- eressea.settings.set("rules.ship.storms", "0")
-end
-
function test_learn()
eressea.settings.set("study.random_progress", "0")
local r = region.create(0, 0, "plain")
diff --git a/scripts/tests/e3/castles.lua b/scripts/tests/e3/castles.lua
index 1fd4e13e9..b16019159 100644
--- a/scripts/tests/e3/castles.lua
+++ b/scripts/tests/e3/castles.lua
@@ -11,30 +11,62 @@ function teardown()
eressea.settings.set("rules.food.flags", "0")
end
+function test_build_watch()
+ local r = region.create(0, 0, "plain")
+ local f = faction.create("e3build@eressea.de", "human", "de")
+ local u = unit.create(f, r, 1)
+
+ u.number = 20
+ u:add_item("log", 20)
+ u.id = 42
+
+ u:set_skill("building", 1)
+ u:add_order("MACHE Wache")
+ process_orders()
+ assert_not_nil(u.building)
+ assert_equal(5, u.building.size)
+
+ u:set_skill("building", 2)
+ u:add_order("MACHE Wache " .. itoa36(u.building.id))
+ process_orders()
+ assert_not_nil(u.building)
+ assert_equal(10, u.building.size)
+end
+
+function test_watch()
+ local r = region.create(0, 0, "plain")
+ local b = building.create(r, "watch")
+
+ assert_equal("scaffolding", b:get_typename(1))
+ assert_equal("scaffolding", b:get_typename(4))
+ assert_equal("guardhouse", b:get_typename(5))
+ assert_equal("guardhouse", b:get_typename(9))
+ assert_equal("guardtower", b:get_typename(10))
+end
+
function test_small_castles()
- local r = region.create(0, 0, "plain")
- local f1 = faction.create("noreply@eressea.de", "human", "de")
- local u1 = unit.create(f1, r, 1)
- local f2 = faction.create("noreply@eressea.de", "halfling", "de")
- local u2 = unit.create(f2, r, 1)
- u1:add_item("money", 10000)
+ local r = region.create(0, 0, "plain")
+ local f1 = faction.create("noreply@eressea.de", "human", "de")
+ local u1 = unit.create(f1, r, 1)
+ local f2 = faction.create("noreply@eressea.de", "halfling", "de")
+ local u2 = unit.create(f2, r, 1)
- local b = building.create(r, "castle")
- u2.building = b
- u1.building = b
+ local b = building.create(r, "castle")
+ u2.building = b
+ u1.building = b
- b.owner = u2
- assert_equal("site", b:get_typename(7))
- assert_equal("fortification", b:get_typename(8))
- b.owner = u1
- assert_equal("site", b:get_typename(9))
- assert_equal("fortification", b:get_typename(10))
+ b.owner = u2
+ assert_equal("site", b:get_typename(7))
+ assert_equal("fortification", b:get_typename(8))
+ b.owner = u1
+ assert_equal("site", b:get_typename(9))
+ assert_equal("fortification", b:get_typename(10))
end
function test_build_normal()
- local r = region.create(0, 0, "plain")
- local f = faction.create("noreply@eressea.de", "human", "de")
- local u = unit.create(f, r, 1)
+ local r = region.create(0, 0, "plain")
+ local f = faction.create("noreply@eressea.de", "human", "de")
+ local u = unit.create(f, r, 1)
u:clear_orders()
u:add_item("stone", 10)
u:set_skill("building", 10)
@@ -45,9 +77,9 @@ function test_build_normal()
end
function test_build_packice()
- local r = region.create(0, 0, "packice")
- local f = faction.create("noreply@eressea.de", "human", "de")
- local u = unit.create(f, r, 1)
+ local r = region.create(0, 0, "packice")
+ local f = faction.create("packice@eressea.de", "human", "de")
+ local u = unit.create(f, r, 1)
u:clear_orders()
u:add_item("stone", 10)
u:set_skill("building", 10)
diff --git a/scripts/tests/faction.lua b/scripts/tests/faction.lua
index 38fdc4eb7..87a6b5100 100644
--- a/scripts/tests/faction.lua
+++ b/scripts/tests/faction.lua
@@ -17,7 +17,7 @@ function setup()
end
function test_faction_flags()
- assert_equal(2, f.flags) -- FFL_ISNEW
+ assert_equal(6, f.flags) -- FFL_ISNEW|FFL_PWMSG
f.flags = 42
assert_equal(42, f.flags)
end
diff --git a/scripts/tests/laws.lua b/scripts/tests/laws.lua
index f0fef15a9..6f41fc54b 100644
--- a/scripts/tests/laws.lua
+++ b/scripts/tests/laws.lua
@@ -95,6 +95,7 @@ function test_force_leave_postcombat()
u1.building = b1
u2.building = b1
eressea.settings.set("rules.owners.force_leave", "1")
+ eressea.settings.set("NewbieImmunity", "0")
u1:clear_orders()
u1:add_order("ATTACKIERE " .. itoa36(u2.id))
u2:clear_orders()
@@ -109,6 +110,7 @@ function test_force_leave_postcombat()
end
end
assert_not_equal(nil, u3)
+ assert_equal(nil, u2.building)
assert_equal(nil, u3.building)
assert_equal(1, u3.number)
end
diff --git a/scripts/tests/xmas.lua b/scripts/tests/xmas.lua
index 7ac4ce731..459984901 100644
--- a/scripts/tests/xmas.lua
+++ b/scripts/tests/xmas.lua
@@ -8,6 +8,8 @@ function setup()
eressea.settings.set("rules.grow.formula", "0")
eressea.settings.set("rules.peasants.growth.factor", "0")
eressea.settings.set("volcano.active.percent", "0")
+ eressea.settings.set("volcano.outbreak.percent", "0")
+ eressea.settings.set("volcano.stop.percent", "0")
end
function test_snowglobe_fail()
@@ -44,23 +46,17 @@ function test_snowglobe()
local r2 = region.create(1, 0, "ocean")
local f = faction.create("snowglobe2@eressea.de", "human", "de")
local u = unit.create(f, r1, 1)
- local have = 6
local fail = 0
u:add_item("snowglobe", have)
- local xform = { ocean = "glacier", glacier = "glacier", firewall = "volcano", volcano = "mountain", desert = "plain", plain = "plain" }
- u:clear_orders()
- u:add_order("BENUTZEN 1 Schneekugel Ost")
+ local xform = { ocean = "glacier", glacier = "glacier", firewall = "volcano", desert = "plain", volcano = "mountain", plain = "plain" }
for k, v in pairs(xform) do
r2.terrain = k
- process_orders()
+ use_snowglobe(u, 1, "Ost", nil)
assert_equal(v, r2.terrain)
- if k~=v then
- have=have - 1
- else
+ if k==v then
fail = fail + 1
assert_equal(fail, f:count_msg_type('target_region_invalid'))
end
- assert_equal(have, u:get_item("snowglobe"))
end
end
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 8a4445b55..43f109fed 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -2,11 +2,9 @@ cmake_minimum_required(VERSION 2.8)
project (server C)
include_directories (${CMAKE_CURRENT_SOURCE_DIR})
-include_directories (${CRITBIT_INCLUDE_DIR})
include_directories (${CJSON_INCLUDE_DIR})
+include_directories (${CLIBS_INCLUDE_DIR})
include_directories (${STORAGE_INCLUDE_DIR})
-include_directories (${QUICKLIST_INCLUDE_DIR})
-include_directories (${CUTEST_INCLUDE_DIR})
include_directories (${LUA_INCLUDE_DIR})
include_directories (${TOLUA_INCLUDE_DIR})
include_directories (${BSON_INCLUDE_DIR})
@@ -17,14 +15,18 @@ set_source_files_properties(kernel/version.c PROPERTIES
COMPILE_DEFINITIONS ERESSEA_VERSION="${ERESSEA_VERSION}")
ENDIF()
+IF(DEFINED ERESSEA_BUILDNO)
+set_source_files_properties(kernel/version.c PROPERTIES
+COMPILE_DEFINITIONS ERESSEA_BUILDNO="${ERESSEA_BUILDNO}")
+ENDIF()
+
IF (CMAKE_COMPILER_IS_GNUCC)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=unused-but-set-variable")
ENDIF()
IF (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
# SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wno-sign-conversion")
- SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -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=c99")
- add_definitions(-DHAVE__BOOL)
+ 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} /Wall /WX /MP")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG
@@ -114,7 +116,6 @@ set (ERESSEA_SRC
magic.c
market.c
morale.c
- monster.c
randenc.c
renumber.c
volcano.c
@@ -146,7 +147,6 @@ set(SERVER_SRC
bind_locale.c
bind_eressea.c
bind_faction.c
- bind_dict.c
bind_order.c
bindings.c
bind_message.c
@@ -181,9 +181,8 @@ target_link_libraries(eressea
game
${TOLUA_LIBRARIES}
${LUA_LIBRARIES}
- ${QUICKLIST_LIBRARIES}
${STORAGE_LIBRARIES}
- ${CRITBIT_LIBRARIES}
+ ${CLIBS_LIBRARIES}
${CJSON_LIBRARIES}
${INIPARSER_LIBRARIES}
)
@@ -237,11 +236,10 @@ set(TESTS_SRC
add_executable(test_eressea ${TESTS_SRC})
target_link_libraries(test_eressea
game
- ${CUTEST_LIBRARIES}
+ cutest
${LUA_LIBRARIES}
- ${QUICKLIST_LIBRARIES}
+ ${CLIBS_LIBRARIES}
${STORAGE_LIBRARIES}
- ${CRITBIT_LIBRARIES}
${CJSON_LIBRARIES}
${INIPARSER_LIBRARIES}
)
diff --git a/src/academy.c b/src/academy.c
index f6b70873e..496c1ef8e 100644
--- a/src/academy.c
+++ b/src/academy.c
@@ -35,7 +35,7 @@ bool academy_can_teach(unit *teacher, unit *student, 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);
- j = _max(50, j * 2);
+ j = MAX(50, j * 2);
/* kann Einheit das zahlen? */
return get_pooled(student, get_resourcetype(R_SILVER), GET_DEFAULT, j) >= j;
/* sonst nehmen sie nicht am Unterricht teil */
diff --git a/src/alchemy.c b/src/alchemy.c
index 9bc180700..aff3485ef 100644
--- a/src/alchemy.c
+++ b/src/alchemy.c
@@ -73,12 +73,12 @@ void herbsearch(unit * u, int max)
}
if (max)
- max = _min(max, rherbs(r));
+ max = MIN(max, rherbs(r));
else
max = rherbs(r);
herbsfound = ntimespprob(effsk * u->number,
(double)rherbs(r) / 100.0F, -0.01F);
- herbsfound = _min(herbsfound, max);
+ herbsfound = MIN(herbsfound, max);
rsetherbs(r, (short) (rherbs(r) - herbsfound));
if (herbsfound) {
@@ -156,12 +156,13 @@ static int potion_water_of_life(unit * u, region *r, int amount) {
}
static int potion_healing(unit * u, int amount) {
- u->hp = _min(unit_max_hp(u) * u->number, u->hp + 400 * amount);
+ u->hp = MIN(unit_max_hp(u) * u->number, u->hp + 400 * amount);
return amount;
}
static int potion_luck(unit *u, region *r, attrib_type *atype, int amount) {
attrib *a = (attrib *)a_find(r->attribs, atype);
+ UNUSED_ARG(u);
if (!a) {
a = a_add(&r->attribs, a_new(atype));
}
@@ -170,8 +171,8 @@ static int potion_luck(unit *u, region *r, attrib_type *atype, int amount) {
}
static int potion_truth(unit *u) {
- // TODO: this potion does nothing!
- // fset(u, UFL_DISBELIEVES);
+ UNUSED_ARG(u);
+ /* TODO: this potion does nothing! */
return 1;
}
@@ -182,7 +183,7 @@ static int potion_power(unit *u, int amount) {
amount = use;
}
/* Verf�nffacht die HP von max. 10 Personen in der Einheit */
- u->hp += _min(u->number, 10 * amount) * unit_max_hp(u) * 4;
+ u->hp += MIN(u->number, 10 * amount) * unit_max_hp(u) * 4;
return amount;
}
@@ -248,7 +249,7 @@ static void free_potiondelay(attrib * a) {
static int age_potiondelay(attrib * a, void *owner)
{
potiondelay *pd = (potiondelay *)a->data.v;
- unused_arg(owner);
+ UNUSED_ARG(owner);
pd->amount = do_potion(pd->u, pd->r, pd->ptype, pd->amount);
return AT_AGE_REMOVE;
}
@@ -295,7 +296,7 @@ static void a_initeffect(attrib * a)
a->data.v = calloc(sizeof(effect_data), 1);
}
-static void a_finalizeeffect(attrib * a) //-V524
+static void a_finalizeeffect(attrib * a) /*-V524 */
{
free(a->data.v);
}
@@ -304,6 +305,7 @@ static void
a_writeeffect(const attrib * a, const void *owner, struct storage *store)
{
effect_data *edata = (effect_data *)a->data.v;
+ UNUSED_ARG(owner);
WRITE_TOK(store, resourcename(edata->type->itype->rtype, 0));
WRITE_INT(store, edata->value);
}
@@ -316,6 +318,7 @@ static int a_readeffect(attrib * a, void *owner, struct gamedata *data)
effect_data *edata = (effect_data *)a->data.v;
char zText[32];
+ UNUSED_ARG(owner);
READ_TOK(store, zText, sizeof(zText));
rtype = rt_find(zText);
@@ -324,7 +327,7 @@ static int a_readeffect(attrib * a, void *owner, struct gamedata *data)
return AT_READ_FAIL;
}
if (rtype->ptype==oldpotiontype[P_HEAL]) {
- // healing potions used to have long-term effects
+ /* healing potions used to have long-term effects */
return AT_READ_FAIL;
}
edata->type = rtype->ptype;
diff --git a/src/attributes/attributes.c b/src/attributes/attributes.c
index 8e9b22139..42f5247fe 100644
--- a/src/attributes/attributes.c
+++ b/src/attributes/attributes.c
@@ -58,10 +58,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include
-attrib_type at_scare = { // monster scares peasants
- "scare", NULL, NULL, NULL, a_writeint, a_readint
-};
-
attrib_type at_unitdissolve = {
"unitdissolve", NULL, NULL, NULL, a_writechars, a_readchars
};
@@ -78,7 +74,6 @@ static int read_ext(attrib * a, void *owner, gamedata *data)
void register_attributes(void)
{
/* Alle speicherbaren Attribute müssen hier registriert werden */
- at_register(&at_scare);
at_register(&at_shiptrail);
at_register(&at_familiar);
at_register(&at_familiarmage);
diff --git a/src/attributes/attributes.h b/src/attributes/attributes.h
index 91184ad98..4ec3150ec 100644
--- a/src/attributes/attributes.h
+++ b/src/attributes/attributes.h
@@ -23,7 +23,6 @@ extern "C" {
#endif
struct attrib_type;
- extern struct attrib_type at_scare;
extern void register_attributes(void);
#ifdef __cplusplus
diff --git a/src/attributes/dict.c b/src/attributes/dict.c
index 2bba9ea7b..f95555734 100644
--- a/src/attributes/dict.c
+++ b/src/attributes/dict.c
@@ -19,6 +19,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include
#include
#include "dict.h"
+#include "key.h"
/* kernel includes */
#include
@@ -29,6 +30,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* util includes */
#include
+#include
+#include
#include
#include
@@ -39,6 +42,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include
#include
+typedef enum {
+ TNONE = 0, TINTEGER = 1, TREAL = 2
+} dict_type;
+
typedef struct dict_data {
dict_type type;
char *name;
@@ -54,230 +61,110 @@ typedef struct dict_data {
} data;
} dict_data;
-static void
-dict_write(const attrib * a, const void *owner, struct storage *store)
-{
- const dict_data *data = (dict_data *)a->data.v;
- int type = (int)data->type;
- WRITE_TOK(store, data->name);
- WRITE_INT(store, type);
- switch (data->type) {
- case TINTEGER:
- WRITE_INT(store, data->data.i);
- break;
- case TREAL:
- WRITE_FLT(store, (float)data->data.real);
- break;
- case TSTRING:
- WRITE_STR(store, data->data.str);
- break;
- case TUNIT:
- write_unit_reference(data->data.u, store);
- break;
- case TFACTION:
- write_faction_reference(data->data.f, store);
- break;
- case TBUILDING:
- write_building_reference(data->data.b, store);
- break;
- case TSHIP:
- /* write_ship_reference(data->data.sh, store); */
- assert(!"not implemented");
- break;
- case TREGION:
- write_region_reference(data->data.r, store);
- break;
- case TNONE:
- break;
- default:
- assert(!"illegal type in object-attribute");
- }
-}
-
static int dict_read(attrib * a, void *owner, gamedata *data)
{
storage *store = data->store;
char name[NAMESIZE];
dict_data *dd = (dict_data *)a->data.v;
- int result, n;
- float flt;
+ int n;
READ_STR(store, name, sizeof(name));
- dd->name = _strdup(name);
+ dd->name = strdup(name);
READ_INT(store, &n);
dd->type = (dict_type)n;
- switch (dd->type) {
- case TINTEGER:
+ if (dd->type == TINTEGER) {
READ_INT(store, &dd->data.i);
- break;
- case TREAL:
+ }
+ else if (dd->type == TREAL) {
+ float flt;
READ_FLT(store, &flt);
- if ((int)flt == flt) {
- dd->type = TINTEGER;
- dd->data.i = (int)flt;
- }
- else {
- dd->data.real = flt;
- }
- break;
- case TSTRING:
- READ_STR(store, name, sizeof(name));
- dd->data.str = _strdup(name);
- break;
- case TBUILDING:
- result =
- read_reference(&dd->data.b, data, read_building_reference,
- resolve_building);
- if (result == 0 && !dd->data.b) {
- return AT_READ_FAIL;
- }
- break;
- case TUNIT:
- result =
- read_reference(&dd->data.u, data, read_unit_reference, resolve_unit);
- if (result == 0 && !dd->data.u) {
- return AT_READ_FAIL;
- }
- break;
- case TFACTION:
- result =
- read_reference(&dd->data.f, data, read_faction_reference,
- resolve_faction);
- if (result == 0 && !dd->data.f) {
- return AT_READ_FAIL;
- }
- break;
- case TREGION:
- result =
- read_reference(&dd->data.r, data, read_region_reference,
- RESOLVE_REGION(data->version));
- if (result == 0 && !dd->data.r) {
- return AT_READ_FAIL;
- }
- break;
- case TSHIP:
- /* return read_ship_reference(&data->data.sh, store); */
- assert(!"not implemented");
- break;
- case TNONE:
- break;
- default:
+ dd->data.real = flt;
+ }
+ else {
+ log_error("read dict, invalid type %d", n);
return AT_READ_FAIL;
}
- return AT_READ_OK;
+ return AT_READ_DEPR;
}
static void dict_init(attrib * a)
{
- dict_data *data;
+ dict_data *dd;
a->data.v = malloc(sizeof(dict_data));
- data = (dict_data *)a->data.v;
- data->type = TNONE;
+ dd = (dict_data *)a->data.v;
+ dd->type = TNONE;
}
static void dict_done(attrib * a)
{
- dict_data *data = (dict_data *)a->data.v;
- if (data->type == TSTRING)
- free(data->data.str);
- free(data->name);
+ dict_data *dd = (dict_data *)a->data.v;
+ free(dd->name);
free(a->data.v);
}
+static void upgrade_keyval(const dict_data *dd, int keyval[], int v) {
+ if (strcmp(dd->name, "embassy_muschel") == 0) {
+ keyval[0] = atoi36("mupL");
+ keyval[1] = v;
+ }
+ else {
+ log_error("dict conversion, bad entry %s", dd->name);
+ }
+}
+
+static void dict_upgrade(attrib **alist, attrib *abegin) {
+ int n = 0, *keys = 0;
+ int i = 0, val[8];
+ attrib *a, *ak = a_find(*alist, &at_keys);
+ if (ak) {
+ keys = (int *)ak->data.v;
+ if (keys) n = keys[0];
+ }
+ for (a = abegin; a && a->type == abegin->type; a = a->next) {
+ dict_data *dd = (dict_data *)a->data.v;
+ if (dd->type == TINTEGER) {
+ upgrade_keyval(dd, val + i * 2, dd->data.i);
+ ++i;
+ }
+ else if (dd->type == TREAL) {
+ upgrade_keyval(dd, val + i * 2, (int)dd->data.real);
+ ++i;
+ }
+ else {
+ log_error("dict conversion, bad type %d for %s", dd->type, dd->name);
+ assert(!"invalid input");
+ }
+ if (i == 4) {
+ keys = realloc(keys, sizeof(int) * (n + i + 1));
+ memcpy(keys + n + 1, val, sizeof(val));
+ n += i;
+ i = 0;
+ }
+ }
+ if (i > 0) {
+ keys = realloc(keys, sizeof(int) * (2 * (n + i) + 1));
+ memcpy(keys + n*2 + 1, val, sizeof(int)*i*2);
+ if (!ak) {
+ ak = a_add(alist, a_new(&at_keys));
+ }
+ }
+ if (ak) {
+ ak->data.v = keys;
+ if (keys) {
+ keys[0] = n + i;
+ }
+ }
+}
+
attrib_type at_dict = {
"object", dict_init, dict_done, NULL,
- dict_write, dict_read
+ NULL, dict_read, dict_upgrade
};
-const char *dict_name(const attrib * a)
+void dict_set(attrib * a, const char * name, int value)
{
- dict_data *data = (dict_data *)a->data.v;
- return data->name;
-}
-
-struct attrib *dict_create(const char *name, dict_type type, variant value)
-{
- attrib *a = a_new(&at_dict);
- dict_data *data = (dict_data *)a->data.v;
- data->name = _strdup(name);
-
- dict_set(a, type, value);
- return a;
-}
-
-void dict_set(attrib * a, dict_type type, variant value)
-{
- dict_data *data = (dict_data *)a->data.v;
-
- if (data->type == TSTRING)
- free(data->data.str);
- data->type = type;
- switch (type) {
- case TSTRING:
- data->data.str = value.v ? _strdup(value.v) : NULL;
- break;
- case TINTEGER:
- data->data.i = value.i;
- break;
- case TREAL:
- data->data.real = value.f;
- break;
- case TREGION:
- data->data.r = (region *)value.v;
- break;
- case TBUILDING:
- data->data.b = (building *)value.v;
- break;
- case TFACTION:
- data->data.f = (faction *)value.v;
- break;
- case TUNIT:
- data->data.u = (unit *)value.v;
- break;
- case TSHIP:
- data->data.sh = (ship *)value.v;
- break;
- case TNONE:
- break;
- default:
- assert(!"invalid object-type");
- break;
- }
-}
-
-void dict_get(const struct attrib *a, dict_type * type, variant * value)
-{
- dict_data *data = (dict_data *)a->data.v;
- *type = data->type;
- switch (data->type) {
- case TSTRING:
- value->v = data->data.str;
- break;
- case TINTEGER:
- value->i = data->data.i;
- break;
- case TREAL:
- value->f = (float)data->data.real;
- break;
- case TREGION:
- value->v = data->data.r;
- break;
- case TBUILDING:
- value->v = data->data.b;
- break;
- case TFACTION:
- value->v = data->data.f;
- break;
- case TUNIT:
- value->v = data->data.u;
- break;
- case TSHIP:
- value->v = data->data.sh;
- break;
- case TNONE:
- break;
- default:
- assert(!"invalid object-type");
- break;
- }
+ dict_data *dd = (dict_data *)a->data.v;
+ dd->name = strdup(name);
+ dd->type = TINTEGER;
+ dd->data.i = value;
}
diff --git a/src/attributes/dict.h b/src/attributes/dict.h
index 5b282779e..aa6b4566a 100644
--- a/src/attributes/dict.h
+++ b/src/attributes/dict.h
@@ -13,25 +13,16 @@
#ifndef H_ATTRIBUTE_OBJECT
#define H_ATTRIBUTE_OBJECT
-#include
+struct attrib_type;
+struct attrib;
#ifdef __cplusplus
extern "C" {
#endif
- typedef enum {
- TNONE = 0, TINTEGER = 1, TREAL = 2, TSTRING = 3,
- TUNIT = 10, TFACTION = 11, TREGION = 12, TBUILDING = 13, TSHIP = 14
- } dict_type;
+ extern struct attrib_type at_dict; /* DEPRECATED: at_dict has been replaced with at_keys */
- extern struct attrib_type at_dict;
-
- struct attrib *dict_create(const char *name, dict_type type,
- variant value);
- void dict_get(const struct attrib *a, dict_type * type,
- variant * value);
- void dict_set(struct attrib *a, dict_type type, variant value);
- const char *dict_name(const struct attrib *a);
+ void dict_set(struct attrib * a, const char * name, int value);
#ifdef __cplusplus
}
diff --git a/src/attributes/hate.c b/src/attributes/hate.c
index 98a36a029..17155fc71 100644
--- a/src/attributes/hate.c
+++ b/src/attributes/hate.c
@@ -30,7 +30,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
static int verify_hate(attrib * a, void *owner)
{
- unused_arg(owner);
+ UNUSED_ARG(owner);
if (a->data.v == NULL) {
return 0;
}
diff --git a/src/attributes/key.c b/src/attributes/key.c
index ae15a38e3..31580bccf 100644
--- a/src/attributes/key.c
+++ b/src/attributes/key.c
@@ -30,8 +30,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
static void a_writekeys(const attrib *a, const void *o, storage *store) {
int i, *keys = (int *)a->data.v;
- for (i = 0; i <= keys[0]; ++i) {
- WRITE_INT(store, keys[i]);
+ WRITE_INT(store, keys[0]);
+ for (i = 0; i < keys[0]; ++i) {
+ WRITE_INT(store, keys[i * 2 + 1]);
+ WRITE_INT(store, keys[i * 2 + 2]);
}
}
@@ -42,10 +44,16 @@ static int a_readkeys(attrib * a, void *owner, gamedata *data) {
if (i == 0) {
return AT_READ_FAIL;
}
- a->data.v = p = malloc(sizeof(int)*(i + 1));
+ a->data.v = p = malloc(sizeof(int)*(i*2 + 1));
*p++ = i;
while (i--) {
READ_INT(data->store, p++);
+ if (data->version >= KEYVAL_VERSION) {
+ READ_INT(data->store, p++);
+ }
+ else {
+ *p++ = 1;
+ }
}
return AT_READ_OK;
}
@@ -69,32 +77,37 @@ attrib_type at_keys = {
NULL
};
-void a_upgradekeys(attrib **alist, attrib *abegin) {
+static void a_upgradekeys(attrib **alist, attrib *abegin) {
int n = 0, *keys = 0;
- int i = 0, val[4];
+ int i = 0, val[8];
attrib *a, *ak = a_find(*alist, &at_keys);
if (ak) {
keys = (int *)ak->data.v;
if (keys) n = keys[0];
}
for (a = abegin; a && a->type == abegin->type; a = a->next) {
- val[i++] = a->data.i;
- if (i == 4) {
- keys = realloc(keys, sizeof(int) * (n + i + 1));
- memcpy(keys + n + 1, val, sizeof(int)*i);
+ val[i * 2] = a->data.i;
+ val[i * 2 + 1] = 1;
+ if (++i == 4) {
+ keys = realloc(keys, sizeof(int) * (2 * (n + i) + 1));
+ memcpy(keys + 2 * n + 1, val, sizeof(val));
n += i;
i = 0;
}
}
if (i > 0) {
- keys = realloc(keys, sizeof(int) * (n + i + 1));
- memcpy(keys + n + 1, val, sizeof(int)*i);
+ keys = realloc(keys, sizeof(int) * (2 * (n + i) + 1));
+ memcpy(keys + 2 * n + 1, val, sizeof(int)*i*2);
if (!ak) {
ak = a_add(alist, a_new(&at_keys));
}
}
- ak->data.v = keys;
- keys[0] = n + i;
+ if (ak) {
+ ak->data.v = keys;
+ if (keys) {
+ keys[0] = n + i;
+ }
+ }
}
attrib_type at_key = {
@@ -107,9 +120,9 @@ attrib_type at_key = {
a_upgradekeys
};
-void key_set(attrib ** alist, int key)
+void key_set(attrib ** alist, int key, int val)
{
- int *keys, n = 1;
+ int *keys, n = 0;
attrib *a;
assert(key != 0);
a = a_find(*alist, &at_keys);
@@ -118,12 +131,13 @@ void key_set(attrib ** alist, int key)
}
keys = (int *)a->data.v;
if (keys) {
- n = keys[0] + 1;
+ n = keys[0];
}
- keys = realloc(keys, sizeof(int) *(n + 1));
- // TODO: does insertion sort pay off here?
- keys[0] = n;
- keys[n] = key;
+ keys = realloc(keys, sizeof(int) *(2 * n + 3));
+ /* TODO: does insertion sort pay off here? prob. not. */
+ keys[0] = n + 1;
+ keys[2 * n + 1] = key;
+ keys[2 * n + 2] = val;
a->data.v = keys;
}
@@ -135,29 +149,31 @@ void key_unset(attrib ** alist, int key)
if (a) {
int i, *keys = (int *)a->data.v;
if (keys) {
- for (i = 1; i <= keys[0]; ++i) {
- if (keys[i] == key) {
- keys[i] = keys[keys[0]];
+ int n = keys[0];
+ for (i = 0; i != n; ++i) {
+ if (keys[2 * i + 1] == key) {
+ memmove(keys + 2 * i + 1, keys + 2 * n - 1, 2 * sizeof(int));
keys[0]--;
+ break;
}
}
}
}
}
-bool key_get(attrib *alist, int key) {
+int key_get(attrib *alist, int key) {
attrib *a;
assert(key != 0);
a = a_find(alist, &at_keys);
if (a) {
int i, *keys = (int *)a->data.v;
if (keys) {
- for (i = 1; i <= keys[0]; ++i) {
- if (keys[i] == key) {
- return true;
+ for (i = 0; i != keys[0]; ++i) {
+ if (keys[i*2+1] == key) {
+ return keys[i * 2 + 2];
}
}
}
}
- return false;
+ return 0;
}
diff --git a/src/attributes/key.h b/src/attributes/key.h
index 89292db1d..0b3ab748f 100644
--- a/src/attributes/key.h
+++ b/src/attributes/key.h
@@ -18,17 +18,20 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifndef H_ATTRIBUTE_KEY
#define H_ATTRIBUTE_KEY
+
+#include
+
#ifdef __cplusplus
extern "C" {
#endif
struct attrib;
struct attrib_type;
- extern struct attrib_type at_key;
+ extern struct attrib_type at_key; /* DEPRECATED: at_key has been replaced with at_keys */
extern struct attrib_type at_keys;
- void key_set(struct attrib **alist, int key);
+ void key_set(struct attrib **alist, int key, int value);
void key_unset(struct attrib **alist, int key);
- bool key_get(struct attrib *alist, int key);
+ int key_get(struct attrib *alist, int key);
#ifdef __cplusplus
}
diff --git a/src/attributes/key.test.c b/src/attributes/key.test.c
index 2b7632917..b816e1d86 100644
--- a/src/attributes/key.test.c
+++ b/src/attributes/key.test.c
@@ -1,22 +1,24 @@
#include
#include "key.h"
+#include "dict.h"
#include
+#include
#include
#include
static void test_get_set_keys(CuTest *tc) {
attrib *a = 0;
- key_set(&a, 42);
- key_set(&a, 43);
- key_set(&a, 44);
- CuAssertTrue(tc, key_get(a, 42));
- CuAssertTrue(tc, key_get(a, 43));
- CuAssertTrue(tc, key_get(a, 44));
+ key_set(&a, 42, 1);
+ key_set(&a, 43, 2);
+ key_set(&a, 44, 3);
+ CuAssertIntEquals(tc, 1, key_get(a, 42));
+ CuAssertIntEquals(tc, 2, key_get(a, 43));
+ CuAssertIntEquals(tc, 3, key_get(a, 44));
key_unset(&a, 42);
- CuAssertTrue(tc, !key_get(a, 42));
- CuAssertTrue(tc, key_get(a, 43));
- CuAssertTrue(tc, key_get(a, 44));
+ CuAssertIntEquals(tc, 0, key_get(a, 42));
+ CuAssertIntEquals(tc, 2, key_get(a, 43));
+ CuAssertIntEquals(tc, 3, key_get(a, 44));
a_removeall(&a, NULL);
}
@@ -26,7 +28,7 @@ static attrib *key_set_orig(attrib **alist, int key) {
return a;
}
-static void test_upgrade(CuTest *tc) {
+static void test_upgrade_key(CuTest *tc) {
attrib *alist = 0;
key_set_orig(&alist, 40);
key_set_orig(&alist, 41);
@@ -35,18 +37,31 @@ static void test_upgrade(CuTest *tc) {
key_set_orig(&alist, 44);
CuAssertPtrNotNull(tc, alist->type->upgrade);
alist->type->upgrade(&alist, alist);
- CuAssertTrue(tc, key_get(alist, 40));
- CuAssertTrue(tc, key_get(alist, 41));
- CuAssertTrue(tc, key_get(alist, 42));
- CuAssertTrue(tc, key_get(alist, 43));
- CuAssertTrue(tc, key_get(alist, 44));
+ CuAssertIntEquals(tc, 1, key_get(alist, 40));
+ CuAssertIntEquals(tc, 1, key_get(alist, 41));
+ CuAssertIntEquals(tc, 1, key_get(alist, 42));
+ CuAssertIntEquals(tc, 1, key_get(alist, 43));
+ CuAssertIntEquals(tc, 1, key_get(alist, 44));
a_removeall(&alist, NULL);
}
+static void test_upgrade_dict(CuTest *tc) {
+ attrib *a;
+
+ a = a_new(&at_dict);
+
+ dict_set(a, "embassy_muschel", 42);
+ CuAssertPtrNotNull(tc, a->type->upgrade);
+ a->type->upgrade(&a, a);
+ CuAssertIntEquals(tc, 42, key_get(a, atoi36("mupL")));
+ a_removeall(&a, NULL);
+}
+
CuSuite *get_key_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_get_set_keys);
- SUITE_ADD_TEST(suite, test_upgrade);
+ SUITE_ADD_TEST(suite, test_upgrade_key);
+ SUITE_ADD_TEST(suite, test_upgrade_dict);
return suite;
}
diff --git a/src/attributes/moved.c b/src/attributes/moved.c
index 3da2a4c3b..c66a5489c 100644
--- a/src/attributes/moved.c
+++ b/src/attributes/moved.c
@@ -27,7 +27,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
static int age_moved(attrib * a, void *owner)
{
- unused_arg(owner);
+ UNUSED_ARG(owner);
--a->data.i;
return a->data.i > 0;
}
diff --git a/src/attributes/movement.c b/src/attributes/movement.c
index 874da5eb3..4d79039ef 100644
--- a/src/attributes/movement.c
+++ b/src/attributes/movement.c
@@ -67,7 +67,7 @@ void set_movement(attrib ** alist, int type)
static int age_speedup(attrib * a, void *owner)
{
- unused_arg(owner);
+ UNUSED_ARG(owner);
if (a->data.sa[0] > 0) {
assert(a->data.sa[0] - a->data.sa[1] >= SHRT_MIN);
assert(a->data.sa[0] - a->data.sa[1] <= SHRT_MAX);
diff --git a/src/attributes/racename.c b/src/attributes/racename.c
index b408cbf6a..c45fa3815 100644
--- a/src/attributes/racename.c
+++ b/src/attributes/racename.c
@@ -43,7 +43,7 @@ void set_racename(attrib ** palist, const char *name)
attrib *a = a_find(*palist, &at_racename);
if (!a && name) {
a = a_add(palist, a_new(&at_racename));
- a->data.v = _strdup(name);
+ a->data.v = strdup(name);
}
else if (a && !name) {
a_remove(palist, a);
@@ -51,7 +51,7 @@ void set_racename(attrib ** palist, const char *name)
else if (a) {
if (strcmp(a->data.v, name) != 0) {
free(a->data.v);
- a->data.v = _strdup(name);
+ a->data.v = strdup(name);
}
}
}
diff --git a/src/attributes/raceprefix.c b/src/attributes/raceprefix.c
index 15f0036c1..a87edfb80 100644
--- a/src/attributes/raceprefix.c
+++ b/src/attributes/raceprefix.c
@@ -41,7 +41,7 @@ void set_prefix(attrib ** ap, const char *str)
free(a->data.v);
}
assert(a->type == &at_raceprefix);
- a->data.v = _strdup(str);
+ a->data.v = strdup(str);
}
const char *get_prefix(attrib * a)
@@ -53,7 +53,7 @@ const char *get_prefix(attrib * a)
str = (char *)a->data.v;
/* conversion of old prefixes */
if (strncmp(str, "prefix_", 7) == 0) {
- ((attrib *)a)->data.v = _strdup(str + 7);
+ ((attrib *)a)->data.v = strdup(str + 7);
free(str);
str = (char *)a->data.v;
}
diff --git a/src/battle.c b/src/battle.c
index 7aa3e4cfa..9864adc41 100644
--- a/src/battle.c
+++ b/src/battle.c
@@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "chaos.h"
#include "guard.h"
#include "laws.h"
-#include "monster.h"
+#include "monsters.h"
#include "move.h"
#include "skill.h"
@@ -64,7 +64,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include
#include
#include
-#include
+#include
#include
#include
@@ -93,12 +93,6 @@ typedef enum combatmagic {
DO_POSTCOMBATSPELL
} combatmagic_t;
-/* globals */
-bool battledebug = false;
-
-static int obs_count = 0;
-static FILE *bdebug;
-
#define MINSPELLRANGE 1
#define MAXSPELLRANGE 7
@@ -440,7 +434,7 @@ static int get_row(const side * s, int row, const side * vs)
/* every entry in the size[] array means someone trying to defend us.
* 'retreat' is the number of rows falling.
*/
- result = _max(FIRST_ROW, row - retreat);
+ result = MAX(FIRST_ROW, row - retreat);
return result;
}
@@ -509,6 +503,9 @@ contest_new(int skilldiff, const troop dt, const armor_type * ar,
const armor_type * sh)
{
double tohit = 0.5 + skilldiff * 0.1;
+
+ UNUSED_ARG(sh);
+ UNUSED_ARG(ar);
if (tohit < 0.5)
tohit = 0.5;
if (chance(tohit)) {
@@ -600,12 +597,12 @@ weapon_skill(const weapon_type * wtype, const unit * u, bool attacking)
if (u_race(u) == get_race(RC_ORC)) {
int sword = effskill(u, SK_MELEE, 0);
int spear = effskill(u, SK_SPEAR, 0);
- skill = _max(sword, spear) - 3;
+ skill = MAX(sword, spear) - 3;
if (attacking) {
- skill = _max(skill, u_race(u)->at_default);
+ skill = MAX(skill, u_race(u)->at_default);
}
else {
- skill = _max(skill, u_race(u)->df_default);
+ skill = MAX(skill, u_race(u)->df_default);
}
}
else {
@@ -685,7 +682,7 @@ static int CavalryBonus(const unit * u, troop enemy, int type)
/* only half against trolls */
if (skl > 0) {
if (type == BONUS_SKILL) {
- int dmg = _min(skl, 8);
+ int dmg = MIN(skl, 8);
if (u_race(enemy.fighter->unit) == get_race(RC_TROLL)) {
dmg = dmg / 4;
}
@@ -696,7 +693,7 @@ static int CavalryBonus(const unit * u, troop enemy, int type)
}
else {
skl = skl / 2;
- return _min(skl, 4);
+ return MIN(skl, 4);
}
}
}
@@ -763,10 +760,6 @@ bool missile)
if (is_riding(t) && (wtype == NULL || (fval(wtype, WTF_HORSEBONUS)
&& !fval(wtype, WTF_MISSILE)))) {
skill += CavalryBonus(tu, enemy, BONUS_SKILL);
- if (wtype)
- skill =
- skillmod(u_race(tu)->attribs, tu, tu->region, wtype->skill, skill,
- SMF_RIDING);
}
if (t.index < tf->elvenhorses) {
@@ -839,6 +832,7 @@ int select_magicarmor(troop t)
/* Sind side ds und Magier des meffect verb�ndet, dann return 1*/
bool meffect_protection(battle * b, meffect * s, side * ds)
{
+ UNUSED_ARG(b);
if (!s->magician->alive)
return false;
if (s->duration <= 0)
@@ -853,6 +847,7 @@ bool meffect_protection(battle * b, meffect * s, side * ds)
/* Sind side as und Magier des meffect verfeindet, dann return 1*/
bool meffect_blocked(battle * b, meffect * s, side * as)
{
+ UNUSED_ARG(b);
if (!s->magician->alive)
return false;
if (s->duration <= 0)
@@ -930,14 +925,12 @@ void kill_troop(troop dt)
if (!df->alive) {
char eqname[64];
const struct equipment *eq;
- if (u_race(du)->itemdrop) {
- item *drops = u_race(du)->itemdrop(u_race(du), du->number - df->run.number);
-
- if (drops != NULL) {
- i_merge(&du->items, &drops);
- }
+ const race *rc = u_race(du);
+ item *drops = item_spoil(rc, du->number - df->run.number);
+ if (drops != NULL) {
+ i_merge(&du->items, &drops);
}
- sprintf(eqname, "%s_spoils", u_race(du)->_name);
+ sprintf(eqname, "%s_spoils", rc->_name);
eq = get_equipment(eqname);
if (eq != NULL) {
equip_items(&du->items, eq);
@@ -1008,24 +1001,20 @@ static void vampirism(troop at, int damage)
if (gain > 0) {
int maxhp = unit_max_hp(at.fighter->unit);
at.fighter->person[at.index].hp =
- _min(gain + at.fighter->person[at.index].hp, maxhp);
+ MIN(gain + at.fighter->person[at.index].hp, maxhp);
}
}
}
#define MAXRACES 128
-static int armor_bonus(const race *rc) {
- return get_param_int(rc->parameters, "armor.stamina", -1);
-}
-
int natural_armor(unit * du)
{
const race *rc = u_race(du);
int an;
assert(rc);
- an = armor_bonus(rc);
+ an = rc_armor_bonus(rc);
if (an > 0) {
int sk = effskill(du, SK_STAMINA, 0);
return rc->armor + sk / an;
@@ -1070,7 +1059,7 @@ static int rc_specialdamage(const unit *au, const unit *du, const struct weapon_
return modifier;
}
-int calculate_armor(troop dt, const weapon_type *dwtype, const weapon_type *awtype, double *magres) {
+int calculate_armor(troop dt, const weapon_type *dwtype, const weapon_type *awtype, variant *magres) {
fighter *df = dt.fighter;
unit *du = df->unit;
int ar = 0, an, am;
@@ -1120,22 +1109,32 @@ int calculate_armor(troop dt, const weapon_type *dwtype, const weapon_type *awty
ar += am;
if (magres) {
- // calculate damage multiplier for magical damage
- double res = 1.0 - magic_resistance(du);
+ /* calculate damage multiplier for magical damage */
+ variant res;
+
+ res = frac_sub(frac_one, magic_resistance(du));
if (u_race(du)->battle_flags & BF_EQUIPMENT) {
/* der Effekt von Laen steigt nicht linear */
- if (armor && fval(armor, ATF_LAEN))
- res *= (1 - armor->magres);
- if (shield && fval(shield, ATF_LAEN))
- res *= (1 - shield->magres);
- if (dwtype)
- res *= (1 - dwtype->magres);
+ if (armor && fval(armor, ATF_LAEN)) {
+ res = frac_mul(res, frac_sub(frac_one, armor->magres));
+ }
+ if (shield && fval(shield, ATF_LAEN)) {
+ res = frac_mul(res, frac_sub(frac_one, shield->magres));
+ }
+ if (dwtype) {
+ res = frac_mul(res, frac_sub(frac_one, dwtype->magres));
+ }
}
- /* gegen Magie wirkt nur nat�rliche und magische R�stung */
+ /* gegen Magie wirkt nur natuerliche und magische Ruestung */
ar = an + am;
- *magres = res > 0 ? res : 0;
+ if (res.sa[0] >= 0) {
+ *magres = res;
+ }
+ else {
+ *magres = frac_make(0, 1);
+ }
}
return ar;
@@ -1158,7 +1157,7 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile)
const weapon_type *dwtype = NULL;
const weapon_type *awtype = NULL;
const weapon *weapon;
- double res = 1.0;
+ variant res = frac_make(1, 1);
int rda, sk = 0, sd;
bool magic = false;
@@ -1201,22 +1200,19 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile)
return false;
}
- /* TODO not sure if res could be > 1 here */
if (magic) {
- da = (int)(_max(da * res, 0));
+ res = frac_mul(frac_make(da, 1), res);
+ da = res.sa[0] / res.sa[1];
}
if (type != AT_COMBATSPELL && type != AT_SPELL) {
if (rule_damage & DAMAGE_CRITICAL) {
double kritchance = (sk * 3 - sd) / 200.0;
- kritchance = _max(kritchance, 0.005);
- kritchance = _min(0.9, kritchance);
+ kritchance = MAX(kritchance, 0.005);
+ kritchance = MIN(0.9, kritchance);
while (chance(kritchance)) {
- if (bdebug) {
- fprintf(bdebug, "%s/%d lands a critical hit\n", itoa36(au->no), at.index);
- }
da += dice_rand(damage);
}
}
@@ -1238,17 +1234,17 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile)
/* Skilldifferenzbonus */
if (rule_damage & DAMAGE_SKILL_BONUS) {
- da += _max(0, (sk - sd) / DAMAGE_QUOTIENT);
+ da += MAX(0, (sk - sd) / DAMAGE_QUOTIENT);
}
}
- rda = _max(da - ar, 0);
+ rda = MAX(da - ar, 0);
if ((u_race(du)->battle_flags & BF_INV_NONMAGIC) && !magic)
rda = 0;
else {
int qi;
- quicklist *ql;
+ selist *ql;
unsigned int i = 0;
if (u_race(du)->battle_flags & BF_RES_PIERCE)
@@ -1262,8 +1258,8 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile)
rda /= 2;
/* Schilde */
- for (qi = 0, ql = b->meffects; ql; ql_advance(&ql, &qi, 1)) {
- meffect *me = (meffect *)ql_get(ql, qi);
+ for (qi = 0, ql = b->meffects; ql; selist_advance(&ql, &qi, 1)) {
+ meffect *me = (meffect *)selist_get(ql, qi);
if (meffect_protection(b, me, ds) != 0) {
assert(0 <= rda); /* rda sollte hier immer mindestens 0 sein */
/* jeder Schaden wird um effect% reduziert bis der Schild duration
@@ -1275,7 +1271,7 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile)
}
/* gibt R�stung +effect f�r duration Treffer */
if (me->typ == SHIELD_ARMOR) {
- rda = _max(rda - me->effect, 0);
+ rda = MAX(rda - me->effect, 0);
me->duration--;
}
}
@@ -1297,10 +1293,6 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile)
}
if (df->person[dt.index].hp > 0) { /* Hat �berlebt */
- if (bdebug) {
- fprintf(bdebug, "Damage %d, armor %d: %d -> %d HP\n",
- da, ar, df->person[dt.index].hp + rda, df->person[dt.index].hp);
- }
if (u_race(au) == get_race(RC_DAEMON)) {
if (!(df->person[dt.index].flags & (FL_COURAGE | FL_DAZZLED))) {
df->person[dt.index].flags |= FL_DAZZLED;
@@ -1318,10 +1310,10 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile)
if (oldpotiontype[P_HEAL] && !fval(&df->person[dt.index], FL_HEALING_USED)) {
if (i_get(du->items, oldpotiontype[P_HEAL]->itype) > 0) {
- i_change(&du->items, oldpotiontype[P_HEAL]->itype, -1);
message *m = msg_message("battle::potionsave", "unit", du);
message_faction(b, du->faction, m);
msg_release(m);
+ i_change(&du->items, oldpotiontype[P_HEAL]->itype, -1);
fset(&df->person[dt.index], FL_HEALING_USED);
df->person[dt.index].hp = u_race(du)->hitpoints * 5; /* give the person a buffer */
return false;
@@ -1329,10 +1321,6 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile)
}
++at.fighter->kills;
- if (bdebug) {
- fprintf(bdebug, "Damage %d, armor %d, type %d: %d -> %d HP, tot.\n",
- da, ar, type, df->person[dt.index].hp + rda, df->person[dt.index].hp);
- }
for (pitm = &du->items; *pitm;) {
item *itm = *pitm;
const item_type *itype = itm->type;
@@ -1474,7 +1462,7 @@ troop select_enemy(fighter * af, int minrow, int maxrow, int select)
minrow = FIGHT_ROW;
maxrow = BEHIND_ROW;
}
- minrow = _max(minrow, FIGHT_ROW);
+ minrow = MAX(minrow, FIGHT_ROW);
enemies = count_enemies(b, af, minrow, maxrow, select);
@@ -1574,7 +1562,7 @@ static troop select_opponent(battle * b, troop at, int mindist, int maxdist)
dt = select_enemy(at.fighter, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE);
}
else {
- mindist = _max(mindist, FIGHT_ROW);
+ mindist = MAX(mindist, FIGHT_ROW);
dt = select_enemy(at.fighter, mindist, maxdist, SELECT_ADVANCE);
}
@@ -1603,11 +1591,11 @@ static troop select_opponent(battle * b, troop at, int mindist, int maxdist)
return dt;
}
-quicklist *fighters(battle * b, const side * vs, int minrow, int maxrow,
+selist *fighters(battle * b, const side * vs, int minrow, int maxrow,
int mask)
{
side *s;
- quicklist *fightervp = 0;
+ selist *fightervp = 0;
assert(vs != NULL);
@@ -1629,7 +1617,7 @@ quicklist *fighters(battle * b, const side * vs, int minrow, int maxrow,
for (fig = s->fighters; fig; fig = fig->next) {
int row = get_unitrow(fig, vs);
if (row >= minrow && row <= maxrow) {
- ql_push(&fightervp, fig);
+ selist_push(&fightervp, fig);
}
}
}
@@ -1735,7 +1723,7 @@ void do_combatmagic(battle * b, combatmagic_t was)
level = eff_spelllevel(mage, sp, level, 1);
if (sl > 0)
- level = _min(sl, level);
+ level = MIN(sl, level);
if (level < 0) {
report_failed_spell(b, mage, sp);
free_order(ord);
@@ -1763,8 +1751,8 @@ void do_combatmagic(battle * b, combatmagic_t was)
for (co = spellranks[rank].begin; co; co = co->next) {
fighter *fig = co->magician.fig;
const spell *sp = co->sp;
- int level = co->level;
+ level = co->level;
if (!sp->cast) {
log_error("spell '%s' has no function.\n", sp->sname);
}
@@ -1801,7 +1789,7 @@ static void do_combatspell(troop at)
unit *caster = fi->unit;
battle *b = fi->side->battle;
region *r = b->region;
- quicklist *ql;
+ selist *ql;
int level, qi;
double power;
int fumblechance = 0;
@@ -1822,7 +1810,7 @@ static void do_combatspell(troop at)
level = eff_spelllevel(caster, sp, fi->magic, 1);
if ((sl = get_combatspelllevel(caster, 1)) > 0)
- level = _min(level, sl);
+ level = MIN(level, sl);
if (fumble(r, caster, sp, level)) {
report_failed_spell(b, caster, sp);
@@ -1830,8 +1818,8 @@ static void do_combatspell(troop at)
return;
}
- for (qi = 0, ql = b->meffects; ql; ql_advance(&ql, &qi, 1)) {
- meffect *mblock = (meffect *)ql_get(ql, qi);
+ for (qi = 0, ql = b->meffects; ql; selist_advance(&ql, &qi, 1)) {
+ meffect *mblock = (meffect *)selist_get(ql, qi);
if (mblock->typ == SHIELD_BLOCK) {
if (meffect_blocked(b, mblock, fi->side) != 0) {
fumblechance += mblock->duration;
@@ -1870,10 +1858,13 @@ static void do_combatspell(troop at)
static void do_extra_spell(troop at, const att * a)
{
- const spell *sp = a->data.sp;
+ const spell *sp = spellref_get(a->data.sp);
- if (sp->cast == NULL) {
- log_error("spell '%s' has no function.\n", sp->sname);
+ if (!sp) {
+ log_error("no such spell: '%s'", a->data.sp->name);
+ }
+ else if (sp->cast == NULL) {
+ log_error("spell '%s' has no function.", sp->sname);
}
else {
assert(a->level > 0);
@@ -1911,10 +1902,11 @@ int skilldiff(troop at, troop dt, int dist)
}
if (df->building) {
- if (df->building->attribs) {
+ building *b = df->building;
+ if (b->attribs) {
const curse_type *strongwall_ct = ct_find("strongwall");
if (strongwall_ct) {
- curse *c = get_curse(df->building->attribs, strongwall_ct);
+ curse *c = get_curse(b->attribs, strongwall_ct);
if (curse_active(c)) {
/* wirkt auf alle Geb�ude */
skdiff -= curse_geteffect_int(c);
@@ -1922,15 +1914,16 @@ int skilldiff(troop at, troop dt, int dist)
}
}
}
- if (df->building->type->protection) {
- int beff = df->building->type->protection(df->building, du, DEFENSE_BONUS);
- if (beff) {
+ if (b->type->flags & BTF_FORTIFICATION) {
+ int stage = buildingeffsize(b, false);
+ int beff = building_protection(b->type, stage);
+ if (beff > 0) {
skdiff -= beff;
is_protected = 2;
- if (df->building->attribs) {
+ if (b->attribs) {
const curse_type *magicwalls_ct = ct_find("magicwalls");
if (magicwalls_ct
- && curse_active(get_curse(df->building->attribs, magicwalls_ct))) {
+ && curse_active(get_curse(b->attribs, magicwalls_ct))) {
/* Verdoppelt Burgenbonus */
skdiff -= beff;
}
@@ -1974,20 +1967,6 @@ int getreload(troop at)
return at.fighter->person[at.index].reload;
}
-static void
-debug_hit(troop at, const weapon * awp, troop dt, const weapon * dwp,
-int skdiff, int dist, bool success)
-{
- fprintf(bdebug, "%.4s/%d [%6s/%d] %s %.4s/%d [%6s/%d] with %d, distance %d\n",
- itoa36(at.fighter->unit->no), at.index,
- LOC(default_locale, awp ? resourcename(awp->type->itype->rtype,
- 0) : "unarmed"), weapon_effskill(at, dt, awp, true, dist > 1),
- success ? "hits" : "misses", itoa36(dt.fighter->unit->no), dt.index,
- LOC(default_locale, dwp ? resourcename(dwp->type->itype->rtype,
- 0) : "unarmed"), weapon_effskill(dt, at, dwp, false, dist > 1), skdiff,
- dist);
-}
-
int hits(troop at, troop dt, weapon * awp)
{
fighter *af = at.fighter, *df = dt.fighter;
@@ -2027,19 +2006,14 @@ int hits(troop at, troop dt, weapon * awp)
shield = select_armor(dt, false);
}
if (contest(skdiff, dt, armor, shield)) {
- if (bdebug) {
- debug_hit(at, awp, dt, dwp, skdiff, dist, true);
- }
return 1;
}
- if (bdebug) {
- debug_hit(at, awp, dt, dwp, skdiff, dist, false);
- }
return 0;
}
void dazzle(battle * b, troop * td)
{
+ UNUSED_ARG(b);
/* Nicht kumulativ ! */
#ifdef TODO_RUNESWORD
if (td->fighter->weapon[WP_RUNESWORD].count > td->index) {
@@ -2056,11 +2030,11 @@ void dazzle(battle * b, troop * td)
void damage_building(battle * b, building * bldg, int damage_abs)
{
- bldg->size = _max(1, bldg->size - damage_abs);
+ bldg->size = MAX(1, bldg->size - damage_abs);
/* Wenn Burg, dann gucken, ob die Leute alle noch in das Geb�ude passen. */
- if (bldg->type->protection) {
+ if (bldg->type->flags & BTF_FORTIFICATION) {
side *s;
bldg->sizeleft = bldg->size;
@@ -2184,11 +2158,7 @@ static void attack(battle * b, troop ta, const att * a, int numattack)
}
}
if (reload && wp && wp->type->reload && !getreload(ta)) {
- int i = setreload(ta);
- if (bdebug) {
- fprintf(bdebug, "%s/%d reloading %d turns\n", itoa36(au->no),
- ta.index, i);
- }
+ setreload(ta);
}
}
}
@@ -2332,7 +2302,7 @@ void do_regenerate(fighter * af)
while (ta.index--) {
struct person *p = af->person + ta.index;
p->hp += effskill(au, SK_STAMINA, 0);
- p->hp = _min(unit_max_hp(au), p->hp);
+ p->hp = MIN(unit_max_hp(au), p->hp);
}
}
@@ -2341,11 +2311,11 @@ static void add_tactics(tactics * ta, fighter * fig, int value)
if (value == 0 || value < ta->value)
return;
if (value > ta->value) {
- ql_free(ta->fighters);
+ selist_free(ta->fighters);
ta->fighters = 0;
}
- ql_push(&ta->fighters, fig);
- ql_push(&fig->side->battle->leaders, fig);
+ selist_push(&ta->fighters, fig);
+ selist_push(&fig->side->battle->leaders, fig);
ta->value = value;
}
@@ -2391,10 +2361,10 @@ double fleechance(unit * u)
if (u_race(u) == get_race(RC_HALFLING)) {
c += 0.20;
- c = _min(c, 0.90);
+ c = MIN(c, 0.90);
}
else {
- c = _min(c, 0.75);
+ c = MIN(c, 0.75);
}
if (a != NULL)
@@ -2487,6 +2457,7 @@ troop select_ally(fighter * af, int minrow, int maxrow, int allytype)
static int loot_quota(const unit * src, const unit * dst,
const item_type * type, int n)
{
+ UNUSED_ARG(type);
if (dst && src && src->faction != dst->faction) {
double divisor = config_get_flt("rules.items.loot_divisor", 1);
assert(divisor <= 0 || divisor >= 1);
@@ -2518,7 +2489,7 @@ static void loot_items(fighter * corpse)
float lootfactor = (float)dead / (float)u->number; /* only loot the dead! */
int maxloot = (int)((float)itm->number * lootfactor);
if (maxloot > 0) {
- int i = _min(10, maxloot);
+ int i = MIN(10, maxloot);
for (; i != 0; --i) {
int loot = maxloot / i;
@@ -2599,7 +2570,7 @@ static void battle_effects(battle * b, int dead_players)
{
region *r = b->region;
int dead_peasants =
- _min(rpeasants(r), (int)(dead_players * PopulationDamage()));
+ MIN(rpeasants(r), (int)(dead_players * PopulationDamage()));
if (dead_peasants) {
deathcounts(r, dead_peasants + dead_players);
add_chaoscount(r, dead_peasants / 2);
@@ -2636,7 +2607,6 @@ static void reorder_fleeing(region * r)
static void aftermath(battle * b)
{
region *r = b->region;
- ship *sh;
side *s;
int dead_players = 0;
bfaction *bf;
@@ -2833,6 +2803,7 @@ static void aftermath(battle * b)
* dieses Schiff besch�digt. Andernfalls ein Schiff, welches
* evt. zuvor verlassen wurde. */
if (ships_damaged) {
+ ship *sh;
if (du->ship)
sh = du->ship;
else
@@ -2867,13 +2838,6 @@ static void aftermath(battle * b)
}
reorder_fleeing(r);
-
- if (bdebug) {
- fprintf(bdebug, "The battle lasted %d turns, %s and %s.\n",
- b->turn,
- b->has_tactics_turn ? "had a tactic turn" : "had no tactic turn",
- ships_damaged ? "was relevant" : "was not relevant.");
- }
}
static void battle_punit(unit * u, battle * b)
@@ -2887,10 +2851,6 @@ static void battle_punit(unit * u, battle * b)
spunit(&S, f, u, 4, seen_battle);
for (x = S; x; x = x->next) {
fbattlerecord(b, f, x->s);
- if (bdebug && u->faction == f) {
- fputs(x->s, bdebug);
- fputc('\n', bdebug);
- }
}
if (S)
freestrlist(S);
@@ -3070,17 +3030,6 @@ static void print_stats(battle * b)
fbattlerecord(b, f, buf);
}
- if (bdebug && s->faction) {
- if (f_get_alliance(s->faction)) {
- fprintf(bdebug, "##### %s (%s/%d)\n", s->faction->name,
- itoa36(s->faction->no),
- s->faction->alliance ? s->faction->alliance->id : 0);
- }
- else {
- fprintf(bdebug, "##### %s (%s)\n", s->faction->name,
- itoa36(s->faction->no));
- }
- }
print_fighters(b, s);
}
@@ -3091,19 +3040,19 @@ static void print_stats(battle * b)
b->max_tactics = 0;
for (s = b->sides; s != b->sides + b->nsides; ++s) {
- if (!ql_empty(s->leader.fighters)) {
- b->max_tactics = _max(b->max_tactics, s->leader.value);
+ if (!selist_empty(s->leader.fighters)) {
+ b->max_tactics = MAX(b->max_tactics, s->leader.value);
}
}
if (b->max_tactics > 0) {
for (s = b->sides; s != b->sides + b->nsides; ++s) {
if (s->leader.value == b->max_tactics) {
- quicklist *ql;
+ selist *ql;
int qi;
- for (qi = 0, ql = s->leader.fighters; ql; ql_advance(&ql, &qi, 1)) {
- fighter *tf = (fighter *)ql_get(ql, qi);
+ for (qi = 0, ql = s->leader.fighters; ql; selist_advance(&ql, &qi, 1)) {
+ fighter *tf = (fighter *)selist_get(ql, qi);
unit *u = tf->unit;
message *m = NULL;
if (!is_attacker(tf)) {
@@ -3258,7 +3207,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
/* change_effect wird in ageing gemacht */
/* Effekte von Artefakten */
- strongmen = _min(fig->unit->number, trollbelts(u));
+ strongmen = MIN(fig->unit->number, trollbelts(u));
/* Hitpoints, Attack- und Defence-Boni f�r alle Personen */
for (i = 0; i < fig->alive; i++) {
@@ -3448,7 +3397,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
else
p_bonus += 3;
} while (rnd >= 97);
- bonus = _max(p_bonus, bonus);
+ bonus = MAX(p_bonus, bonus);
}
tactics += bonus;
}
@@ -3512,28 +3461,6 @@ static int join_battle(battle * b, unit * u, bool attack, fighter ** cp)
return false;
}
-static const char *simplename(region * r)
-{
- int i;
- static char name[17];
- const char *cp = rname(r, default_locale);
- for (i = 0; *cp && i != 16; ++i, ++cp) {
- int c = *(unsigned char *)cp;
- while (c && !isalpha(c) && !isxspace(c)) {
- ++cp;
- c = *(unsigned char *)cp;
- }
- if (isxspace(c))
- name[i] = '_';
- else
- name[i] = *cp;
- if (c == 0)
- break;
- }
- name[i] = 0;
- return name;
-}
-
battle *make_battle(region * r)
{
battle *b = (battle *)calloc(1, sizeof(battle));
@@ -3545,29 +3472,6 @@ battle *make_battle(region * r)
for (bld = r->buildings; bld != NULL; bld = bld->next)
bld->sizeleft = bld->size;
- if (battledebug) {
- char zText[MAX_PATH];
- char zFilename[MAX_PATH];
- join_path(basepath(), "battles", zText, sizeof(zText));
- if (_mkdir(zText) != 0) {
- log_error("could not create subdirectory for battle logs: %s", zText);
- battledebug = false;
- }
- else {
- sprintf(zFilename, "battle-%d-%s.log", obs_count++, simplename(r));
- join_path(zText, zFilename, zText, sizeof(zText));
- bdebug = fopen(zText, "w");
- if (!bdebug)
- log_error("battles cannot be debugged");
- else {
- const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 };
- fwrite(utf8_bom, 1, 3, bdebug);
- fprintf(bdebug, "In %s findet ein Kampf statt:\n", rname(r,
- default_locale));
- }
- }
- }
-
b->region = r;
b->plane = getplane(r);
/* Finde alle Parteien, die den Kampf beobachten k�nnen: */
@@ -3599,7 +3503,7 @@ battle *make_battle(region * r)
static void free_side(side * si)
{
- ql_free(si->leader.fighters);
+ selist_free(si->leader.fighters);
}
static void free_fighter(fighter * fig)
@@ -3637,19 +3541,15 @@ static void battle_free(battle * b) {
void free_battle(battle * b)
{
- if (bdebug) {
- fclose(bdebug);
- }
-
while (b->factions) {
bfaction *bf = b->factions;
b->factions = bf->next;
free(bf);
}
- ql_free(b->leaders);
- ql_foreach(b->meffects, free);
- ql_free(b->meffects);
+ selist_free(b->leaders);
+ selist_foreach(b->meffects, free);
+ selist_free(b->meffects);
battle_free(b);
}
@@ -3805,13 +3705,7 @@ static void join_allies(battle * b)
}
/* keine Einw�nde, also soll er mitmachen: */
if (c == NULL) {
- if (join_battle(b, u, false, &c)) {
- if (battledebug) {
- fprintf(bdebug, "%s joins to help %s against %s.\n",
- unitname(u), factionname(s->faction), factionname(se->faction));
- }
- }
- else if (c == NULL) {
+ if (!join_battle(b, u, false, &c)) {
continue;
}
}
@@ -3819,12 +3713,7 @@ static void join_allies(battle * b)
/* the enemy of my friend is my enemy: */
for (se = b->sides; se != s_end; ++se) {
if (se->faction != u->faction && enemy(s, se)) {
- if (set_enemy(se, c->side, false) && battledebug) {
- fprintf(bdebug,
- "%u/%s hates %u/%s because they are enemies with %u/%s.\n",
- c->side->index, sidename(c->side), se->index, sidename(se),
- s->index, sidename(s));
- }
+ set_enemy(se, c->side, false);
}
}
}
@@ -4005,18 +3894,8 @@ static bool start_battle(region * r, battle ** bp)
}
b = make_battle(r);
}
- if (join_battle(b, u, true, &c1)) {
- if (battledebug) {
- fprintf(bdebug, "%s joins by attacking %s.\n",
- unitname(u), unitname(u2));
- }
- }
- if (join_battle(b, u2, false, &c2)) {
- if (battledebug) {
- fprintf(bdebug, "%s joins because of an attack from %s.\n",
- unitname(u2), unitname(u));
- }
- }
+ join_battle(b, u, true, &c1);
+ join_battle(b, u2, false, &c2);
/* Hat die attackierte Einheit keinen Noaid-Status,
* wird das Flag von der Faction genommen, andere
@@ -4029,11 +3908,7 @@ static bool start_battle(region * r, battle ** bp)
* Pr�combataura bei kurzem Kampf. */
c1->side->bf->attacker = true;
- if (set_enemy(c1->side, c2->side, true) && battledebug) {
- fprintf(bdebug, "%u/%s hates %u/%s because they attacked them.\n",
- c2->side->index, sidename(c2->side),
- c1->side->index, sidename(c1->side));
- }
+ set_enemy(c1->side, c2->side, true);
fighting = true;
}
}
@@ -4104,7 +3979,7 @@ static void battle_flee(battle * b)
troop dt;
int runners = 0;
/* Flucht nicht bei mehr als 600 HP. Damit Wyrme t�tbar bleiben. */
- int runhp = _min(600, (int)(0.9 + unit_max_hp(u) * hpflee(u->status)));
+ int runhp = MIN(600, (int)(0.9 + unit_max_hp(u) * hpflee(u->status)));
if (u->ship && fval(u->region->terrain, SEA_REGION)) {
/* keine Flucht von Schiffen auf hoher See */
@@ -4147,15 +4022,11 @@ static void battle_flee(battle * b)
if (fig->person[dt.index].flags & FL_PANICED) {
ispaniced = EFFECT_PANIC_SPELL;
}
- if (chance(_min(fleechance(u) + ispaniced, 0.90))) {
+ if (chance(MIN(fleechance(u) + ispaniced, 0.90))) {
++runners;
flee(dt);
}
}
- if (bdebug && runners > 0) {
- fprintf(bdebug, "Fleeing: %d from %s\n", runners,
- itoa36(fig->unit->no));
- }
}
}
}
@@ -4242,7 +4113,7 @@ void do_battle(region * r)
freset(sh, SF_DAMAGED);
/* Gibt es eine Taktikrunde ? */
- if (!ql_empty(b->leaders)) {
+ if (!selist_empty(b->leaders)) {
b->turn = 0;
b->has_tactics_turn = true;
}
@@ -4258,9 +4129,6 @@ void do_battle(region * r)
log_debug("battle in %s (%d, %d) : ", regionname(r, 0), r->x, r->y);
for (; battle_report(b) && b->turn <= max_turns; ++b->turn) {
- if (bdebug) {
- fprintf(bdebug, "*** Turn: %d\n", b->turn);
- }
battle_flee(b);
battle_update(b);
battle_attacks(b);
diff --git a/src/battle.h b/src/battle.h
index 007bda008..85e65cf66 100644
--- a/src/battle.h
+++ b/src/battle.h
@@ -20,11 +20,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define H_KRNL_BATTLE
#include
+#include
#ifdef __cplusplus
extern "C" {
#endif
+ struct message;
+ struct selist;
+
/** more defines **/
#define FS_ENEMY 1
#define FS_HELP 2
@@ -43,7 +47,6 @@ extern "C" {
#define LAST_ROW FLEE_ROW
#define MAXSIDES 192 /* if there are ever more than this, we're fucked. */
- struct message;
typedef struct bfaction {
struct bfaction *next;
@@ -53,7 +56,7 @@ extern "C" {
} bfaction;
typedef struct tactics {
- struct quicklist *fighters;
+ struct selist *fighters;
int value;
} tactics;
@@ -86,7 +89,7 @@ extern "C" {
} side;
typedef struct battle {
- struct quicklist *leaders;
+ struct selist *leaders;
struct region *region;
struct plane *plane;
bfaction *factions;
@@ -94,7 +97,7 @@ extern "C" {
int nfighters;
side sides[MAXSIDES];
int nsides;
- struct quicklist *meffects;
+ struct selist *meffects;
int max_tactics;
int turn;
bool has_tactics_turn;
@@ -224,7 +227,6 @@ extern "C" {
} meffect;
extern const troop no_troop;
- extern bool battledebug;
/* BEGIN battle interface */
side * find_side(battle * b, const struct faction * f, const struct group * g, unsigned int flags, const struct faction * stealthfaction);
@@ -246,14 +248,14 @@ extern "C" {
int count_enemies(struct battle *b, const struct fighter *af,
int minrow, int maxrow, int select);
int natural_armor(struct unit * u);
- int calculate_armor(troop dt, const struct weapon_type *dwtype, const struct weapon_type *awtype, double *magres);
+ int calculate_armor(troop dt, const struct weapon_type *dwtype, const struct weapon_type *awtype, union variant *magres);
bool terminate(troop dt, troop at, int type, const char *damage,
bool missile);
extern void message_all(battle * b, struct message *m);
extern int hits(troop at, troop dt, weapon * awp);
extern void damage_building(struct battle *b, struct building *bldg,
int damage_abs);
- struct quicklist *fighters(struct battle *b, const struct side *vs,
+ struct selist *fighters(struct battle *b, const struct side *vs,
int minrow, int maxrow, int mask);
int count_allies(const struct side *as, int minrow, int maxrow,
int select, int allytype);
diff --git a/src/battle.test.c b/src/battle.test.c
index 7228ef90e..b00d06a98 100644
--- a/src/battle.test.c
+++ b/src/battle.test.c
@@ -26,7 +26,7 @@ static void test_make_fighter(CuTest * tc)
faction * f;
const resource_type *rtype;
- test_cleanup();
+ test_setup();
test_create_horse();
r = test_create_region(0, 0, 0);
f = test_create_faction(NULL);
@@ -60,8 +60,17 @@ static void test_make_fighter(CuTest * tc)
test_cleanup();
}
-static int add_two(const building * b, const unit * u, building_bonus bonus) {
- return 2;
+static building_type * setup_castle(void) {
+ building_type * btype;
+ construction *cons;
+
+ btype = bt_get_or_create("castle");
+ btype->flags |= BTF_FORTIFICATION;
+ cons = btype->construction = calloc(1, sizeof(construction));
+ cons->maxsize = 5;
+ cons = cons->improvement = calloc(1, sizeof(construction));
+ cons->maxsize = -1;
+ return btype;
}
static void test_defenders_get_building_bonus(CuTest * tc)
@@ -72,16 +81,13 @@ static void test_defenders_get_building_bonus(CuTest * tc)
fighter *df, *af;
battle *b;
side *ds, *as;
- int diff;
troop dt, at;
building_type * btype;
- test_cleanup();
+ test_setup();
+ btype = setup_castle();
r = test_create_region(0, 0, 0);
- btype = bt_get_or_create("castle");
- btype->protection = &add_two;
bld = test_create_building(r, btype);
- bld->size = 10;
du = test_create_unit(test_create_faction(NULL), r);
au = test_create_unit(test_create_faction(NULL), r);
@@ -101,11 +107,14 @@ static void test_defenders_get_building_bonus(CuTest * tc)
at.fighter = af;
at.index = 0;
- diff = skilldiff(at, dt, 0);
- CuAssertIntEquals(tc, -2, diff);
+ bld->size = 10; /* stage 1 building */
+ CuAssertIntEquals(tc, -1, skilldiff(at, dt, 0));
+ CuAssertIntEquals(tc, 0, skilldiff(dt, at, 0));
+
+ bld->size = 1; /* stage 0 building */
+ CuAssertIntEquals(tc, 0, skilldiff(at, dt, 0));
+ CuAssertIntEquals(tc, 0, skilldiff(dt, at, 0));
- diff = skilldiff(dt, at, 0);
- CuAssertIntEquals(tc, 0, diff);
free_battle(b);
test_cleanup();
}
@@ -120,10 +129,10 @@ static void test_attackers_get_no_building_bonus(CuTest * tc)
side *as;
building_type * btype;
- test_cleanup();
+ test_setup();
r = test_create_region(0, 0, 0);
- btype = bt_get_or_create("castle");
- btype->protection = &add_two;
+ btype = setup_castle();
+ btype->flags |= BTF_FORTIFICATION;
bld = test_create_building(r, btype);
bld->size = 10;
@@ -150,10 +159,10 @@ static void test_building_bonus_respects_size(CuTest * tc)
building_type * btype;
faction * f;
- test_cleanup();
+ test_setup();
+ btype = setup_castle();
r = test_create_region(0, 0, 0);
- btype = bt_get_or_create("castle");
- btype->protection = &add_two;
+ btype->flags |= BTF_FORTIFICATION;
bld = test_create_building(r, btype);
bld->size = 10;
@@ -178,28 +187,25 @@ static void test_building_bonus_respects_size(CuTest * tc)
static void test_building_defence_bonus(CuTest * tc)
{
- unit *au;
- region *r;
- building * bld;
building_type * btype;
- faction * f;
- int def;
- test_cleanup();
- r = test_create_region(0, 0, 0);
- btype = test_create_buildingtype("castle");
- btype->protection = (int(*)(const struct building *, const struct unit *, building_bonus))get_function("building_protection");
- btype->construction->defense_bonus = 3;
- bld = test_create_building(r, btype);
- bld->size = 1;
+ test_setup();
+ btype = setup_castle();
- f = test_create_faction(NULL);
- au = test_create_unit(f, r);
- scale_number(au, 1);
- u_set_building(au, bld);
+ btype->maxsize = -1; /* unlimited buildigs get the castle bonus */
+ CuAssertIntEquals(tc, 0, building_protection(btype, 0));
+ CuAssertIntEquals(tc, 1, building_protection(btype, 1));
+ CuAssertIntEquals(tc, 3, building_protection(btype, 2));
+ CuAssertIntEquals(tc, 5, building_protection(btype, 3));
+ CuAssertIntEquals(tc, 8, building_protection(btype, 4));
+ CuAssertIntEquals(tc, 12, building_protection(btype, 5));
+ CuAssertIntEquals(tc, 12, building_protection(btype, 6));
- def = btype->protection(bld, au, DEFENSE_BONUS);
- CuAssertIntEquals(tc, 3, def);
+ btype->maxsize = 10; /* limited-size buildings are treated like an E3 watchtower */
+ CuAssertIntEquals(tc, 0, building_protection(btype, 0));
+ CuAssertIntEquals(tc, 1, building_protection(btype, 1));
+ CuAssertIntEquals(tc, 2, building_protection(btype, 2));
+ CuAssertIntEquals(tc, 2, building_protection(btype, 3));
test_cleanup();
}
@@ -219,14 +225,17 @@ static void test_natural_armor(CuTest * tc)
race *rc;
unit *u;
- test_cleanup();
+ test_setup();
rc = test_create_race("human");
u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, 0));
set_level(u, SK_STAMINA, 2);
+ CuAssertIntEquals(tc, 0, rc_armor_bonus(rc));
CuAssertIntEquals(tc, 0, natural_armor(u));
- set_param(&rc->parameters, "armor.stamina", "1");
+ rc_set_param(rc, "armor.stamina", "1");
+ CuAssertIntEquals(tc, 1, rc_armor_bonus(rc));
CuAssertIntEquals(tc, 2, natural_armor(u));
- set_param(&rc->parameters, "armor.stamina", "2");
+ rc_set_param(rc, "armor.stamina", "2");
+ CuAssertIntEquals(tc, 2, rc_armor_bonus(rc));
CuAssertIntEquals(tc, 1, natural_armor(u));
test_cleanup();
}
@@ -241,23 +250,24 @@ static void test_calculate_armor(CuTest * tc)
armor_type *ashield, *achain;
item_type *ibelt, *ishield, *ichain;
race *rc;
- double magres = 0.0;
+ variant magres = frac_zero;
+ variant v50p = frac_make(1, 2);
- test_cleanup();
+ test_setup();
r = test_create_region(0, 0, 0);
ibelt = it_get_or_create(rt_get_or_create("trollbelt"));
ishield = it_get_or_create(rt_get_or_create("shield"));
- ashield = new_armortype(ishield, 0.0, 0.5, 1, ATF_SHIELD);
+ ashield = new_armortype(ishield, 0.0, v50p, 1, ATF_SHIELD);
ichain = it_get_or_create(rt_get_or_create("chainmail"));
- achain = new_armortype(ichain, 0.0, 0.5, 3, ATF_NONE);
- wtype = new_weapontype(it_get_or_create(rt_get_or_create("sword")), 0, 0.5, 0, 0, 0, 0, SK_MELEE, 1);
+ achain = new_armortype(ichain, 0.0, v50p, 3, ATF_NONE);
+ wtype = new_weapontype(it_get_or_create(rt_get_or_create("sword")), 0, v50p, 0, 0, 0, 0, SK_MELEE, 1);
rc = test_create_race("human");
du = test_create_unit(test_create_faction(rc), r);
dt.index = 0;
dt.fighter = setup_fighter(&b, du);
CuAssertIntEquals_Msg(tc, "default ac", 0, calculate_armor(dt, 0, 0, &magres));
- CuAssertDblEquals_Msg(tc, "magres unmodified", 1.0, magres, 0.01);
+ CuAssertIntEquals_Msg(tc, "magres unmodified", magres.sa[0], magres.sa[1]);
free_battle(b);
b = NULL;
@@ -290,13 +300,13 @@ static void test_calculate_armor(CuTest * tc)
wtype->flags = WTF_NONE;
CuAssertIntEquals_Msg(tc, "magical attack", 3, calculate_armor(dt, 0, 0, &magres));
- CuAssertDblEquals_Msg(tc, "magres unmodified", 1.0, magres, 0.01);
+ CuAssertIntEquals_Msg(tc, "magres unmodified", magres.sa[1], magres.sa[0]);
ashield->flags |= ATF_LAEN;
achain->flags |= ATF_LAEN;
- magres = 1.0;
+ magres = frac_one;
CuAssertIntEquals_Msg(tc, "laen armor", 3, calculate_armor(dt, 0, 0, &magres));
- CuAssertDblEquals_Msg(tc, "laen magres bonus", 0.25, magres, 0.01);
+ CuAssertIntEquals_Msg(tc, "laen magres bonus", 4, magres.sa[1]);
free_battle(b);
test_cleanup();
}
@@ -310,38 +320,42 @@ static void test_magic_resistance(CuTest *tc)
armor_type *ashield, *achain;
item_type *ishield, *ichain;
race *rc;
- double magres;
+ variant magres;
+ variant v50p = frac_make(1, 2);
+ variant v10p = frac_make(1, 10);
- test_cleanup();
+ test_setup();
r = test_create_region(0, 0, 0);
ishield = it_get_or_create(rt_get_or_create("shield"));
- ashield = new_armortype(ishield, 0.0, 0.5, 1, ATF_SHIELD);
+ ashield = new_armortype(ishield, 0.0, v50p, 1, ATF_SHIELD);
ichain = it_get_or_create(rt_get_or_create("chainmail"));
- achain = new_armortype(ichain, 0.0, 0.5, 3, ATF_NONE);
+ achain = new_armortype(ichain, 0.0, v50p, 3, ATF_NONE);
rc = test_create_race("human");
du = test_create_unit(test_create_faction(rc), r);
dt.index = 0;
+ i_change(&du->items, ishield, 1);
dt.fighter = setup_fighter(&b, du);
calculate_armor(dt, 0, 0, &magres);
- CuAssertDblEquals_Msg(tc, "no magres bonus", 0.0, magic_resistance(du), 0.01);
- CuAssertDblEquals_Msg(tc, "no magres reduction", 1.0, magres, 0.01);
+ CuAssertIntEquals_Msg(tc, "no magres reduction", magres.sa[1], magres.sa[0]);
+ magres = magic_resistance(du);
+ CuAssertIntEquals_Msg(tc, "no magres reduction", 0, magres.sa[0]);
ashield->flags |= ATF_LAEN;
- ashield->magres = 0.1;
+ ashield->magres = v10p;
calculate_armor(dt, 0, 0, &magres);
+ CuAssert(tc, "laen reduction => 10%%", frac_equal(frac_make(9, 10), magres));
free_battle(b);
b = NULL;
- i_change(&du->items, ishield, 1);
i_change(&du->items, ichain, 1);
achain->flags |= ATF_LAEN;
- achain->magres = 0.1;
+ achain->magres = v10p;
ashield->flags |= ATF_LAEN;
- ashield->magres = 0.1;
+ ashield->magres = v10p;
dt.fighter = setup_fighter(&b, du);
calculate_armor(dt, 0, 0, &magres);
- CuAssertDblEquals_Msg(tc, "laen reduction", 0.81, magres, 0.01);
+ CuAssert(tc, "2x laen reduction => 81%%", frac_equal(frac_make(81, 100), magres));
free_battle(b);
b = NULL;
@@ -350,17 +364,20 @@ static void test_magic_resistance(CuTest *tc)
set_level(du, SK_MAGIC, 2);
dt.fighter = setup_fighter(&b, du);
calculate_armor(dt, 0, 0, &magres);
- CuAssertDblEquals_Msg(tc, "skill bonus", 0.1, magic_resistance(du), 0.01);
- CuAssertDblEquals_Msg(tc, "skill reduction", 0.9, magres, 0.01);
- rc->magres = 0.5; /* gets added to skill bonus */
+ CuAssert(tc, "skill reduction => 90%%", frac_equal(magres, frac_make(9, 10)));
+ magres = magic_resistance(du);
+ CuAssert(tc, "skill reduction", frac_equal(magres, v10p));
+ rc->magres = v50p; /* percentage, gets added to skill bonus */
calculate_armor(dt, 0, 0, &magres);
- CuAssertDblEquals_Msg(tc, "race bonus", 0.6, magic_resistance(du), 0.01);
- CuAssertDblEquals_Msg(tc, "race reduction", 0.4, magres, 0.01);
+ CuAssert(tc, "race reduction => 40%%", frac_equal(magres, frac_make(4, 10)));
+ magres = magic_resistance(du);
+ CuAssert(tc, "race bonus => 60%%", frac_equal(magres, frac_make(60, 100)));
- rc->magres = 1.5; /* should not cause negative damage multiplier */
- CuAssertDblEquals_Msg(tc, "magic resistance is never > 0.9", 0.9, magic_resistance(du), 0.01);
+ rc->magres = frac_make(15, 10); /* 150% resistance should not cause negative damage multiplier */
+ magres = magic_resistance(du);
+ CuAssert(tc, "magic resistance is never > 0.9", frac_equal(magres, frac_make(9, 10)));
calculate_armor(dt, 0, 0, &magres);
- CuAssertDblEquals_Msg(tc, "damage reduction is never < 0.1", 0.1, magres, 0.01);
+ CuAssert(tc, "damage reduction is never < 0.1", frac_equal(magres, frac_make(1, 10)));
free_battle(b);
test_cleanup();
@@ -376,14 +393,15 @@ static void test_projectile_armor(CuTest * tc)
armor_type *ashield, *achain;
item_type *ishield, *ichain;
race *rc;
+ variant v50p = frac_make(1, 2);
- test_cleanup();
+ test_setup();
r = test_create_region(0, 0, 0);
ishield = it_get_or_create(rt_get_or_create("shield"));
- ashield = new_armortype(ishield, 0.0, 0.5, 1, ATF_SHIELD);
+ ashield = new_armortype(ishield, 0.0, v50p, 1, ATF_SHIELD);
ichain = it_get_or_create(rt_get_or_create("chainmail"));
- achain = new_armortype(ichain, 0.0, 0.5, 3, ATF_NONE);
- wtype = new_weapontype(it_get_or_create(rt_get_or_create("sword")), 0, 0.5, 0, 0, 0, 0, SK_MELEE, 1);
+ achain = new_armortype(ichain, 0.0, v50p, 3, ATF_NONE);
+ wtype = new_weapontype(it_get_or_create(rt_get_or_create("sword")), 0, v50p, 0, 0, 0, 0, SK_MELEE, 1);
rc = test_create_race("human");
rc->battle_flags |= BF_EQUIPMENT;
du = test_create_unit(test_create_faction(rc), r);
@@ -411,7 +429,7 @@ static void test_battle_skilldiff(CuTest *tc)
unit *ua, *ud;
battle *b = NULL;
- test_cleanup();
+ test_setup();
r = test_create_region(0, 0, 0);
ud = test_create_unit(test_create_faction(0), r);
@@ -430,18 +448,14 @@ static void test_battle_skilldiff(CuTest *tc)
td.fighter->person[0].flags |= FL_SLEEPING;
CuAssertIntEquals(tc, 3, skilldiff(ta, td, 0));
- // TODO: unarmed halfling vs. dragon: +5
- // TODO: rule_goblin_bonus
- // TODO: weapon modifiers, missiles, skill_formula
+ /* TODO: unarmed halfling vs. dragon: +5 */
+ /* TODO: rule_goblin_bonus */
+ /* TODO: weapon modifiers, missiles, skill_formula */
free_battle(b);
test_cleanup();
}
-static int protect(const building *b, const unit *u, building_bonus bonus) {
- return (bonus == DEFENSE_BONUS) ? 4 : 0;
-}
-
static void test_battle_skilldiff_building(CuTest *tc)
{
troop ta, td;
@@ -451,8 +465,8 @@ static void test_battle_skilldiff_building(CuTest *tc)
building_type *btype;
const curse_type *strongwall_ct, *magicwalls_ct;
- test_cleanup();
- btype = test_create_buildingtype("castle");
+ test_setup();
+ btype = setup_castle();
strongwall_ct = ct_find("strongwall");
magicwalls_ct = ct_find("magicwalls");
@@ -467,14 +481,14 @@ static void test_battle_skilldiff_building(CuTest *tc)
ua = test_create_unit(test_create_faction(0), r);
CuAssertIntEquals(tc, 0, skilldiff(ta, td, 0));
- btype->protection = protect;
- CuAssertIntEquals(tc, -4, skilldiff(ta, td, 0));
+ ud->building->size = 10;
+ CuAssertIntEquals(tc, -1, skilldiff(ta, td, 0));
create_curse(NULL, &ud->building->attribs, magicwalls_ct, 1, 1, 1, 1);
- CuAssertIntEquals(tc, -8, skilldiff(ta, td, 0));
+ CuAssertIntEquals(tc, -2, skilldiff(ta, td, 0));
create_curse(NULL, &ud->building->attribs, strongwall_ct, 1, 1, 2, 1);
- CuAssertIntEquals(tc, -10, skilldiff(ta, td, 0));
+ CuAssertIntEquals(tc, -4, skilldiff(ta, td, 0));
free_battle(b);
test_cleanup();
diff --git a/src/bind_building.c b/src/bind_building.c
index 3724d4db5..ea689bfb5 100644
--- a/src/bind_building.c
+++ b/src/bind_building.c
@@ -13,7 +13,6 @@ without prior permission by the authors of Eressea.
#include
#include "bind_building.h"
#include "bind_unit.h"
-#include "bind_dict.h"
#include
#include
@@ -41,13 +40,6 @@ int tolua_buildinglist_next(lua_State * L)
return 0; /* no more values to return */
}
-static int tolua_building_get_objects(lua_State * L)
-{
- building *self = (building *)tolua_tousertype(L, 1, 0);
- tolua_pushusertype(L, (void *)&self->attribs, USERTYPE_DICT);
- return 1;
-}
-
static int tolua_building_set_working(lua_State * L)
{
building *self = (building *)tolua_tousertype(L, 1, 0);
@@ -92,7 +84,7 @@ static int tolua_building_set_info(lua_State * L)
const char *info = tolua_tostring(L, 2, 0);
free(self->display);
if (info)
- self->display = _strdup(info);
+ self->display = strdup(info);
else
self->display = NULL;
return 0;
@@ -258,7 +250,6 @@ void tolua_building_open(lua_State * L)
tolua_variable(L, TOLUA_CAST "size", tolua_building_get_size,
tolua_building_set_size);
tolua_function(L, TOLUA_CAST "get_typename", tolua_building_get_typename);
- tolua_variable(L, TOLUA_CAST "objects", tolua_building_get_objects, 0);
tolua_variable(L, TOLUA_CAST "working", tolua_building_get_working, tolua_building_set_working);
}
diff --git a/src/bind_config.c b/src/bind_config.c
index 3959cc22c..b4aa68d58 100644
--- a/src/bind_config.c
+++ b/src/bind_config.c
@@ -3,6 +3,8 @@
#include
#include
#include
+#include
+#include
#include
#include
#include
@@ -18,8 +20,8 @@
#include "kernel/terrain.h"
void config_reset(void) {
- default_locale = 0;
- free_locales();
+ free_config();
+ free_nrmesssages();
free_spells();
free_buildingtypes();
free_shiptypes();
@@ -33,7 +35,6 @@ int config_parse(const char *json)
if (conf) {
json_config(conf);
cJSON_Delete(conf);
- init_locales();
return 0;
}
else {
@@ -45,7 +46,7 @@ int config_parse(const char *json)
if (xp >= ep) break;
}
xp = (ep > json + 10) ? ep - 10 : json;
- strncpy(buffer, xp, sizeof(buffer));
+ strlcpy(buffer, xp, sizeof(buffer));
buffer[9] = 0;
log_error("json parse error in line %d, position %d, near `%s`\n", line, ep - lp, buffer);
}
diff --git a/src/bind_dict.c b/src/bind_dict.c
deleted file mode 100644
index 32d3c498d..000000000
--- a/src/bind_dict.c
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
-+-------------------+
-| | Enno Rehling
-| Eressea PBEM host | Christian Schlittchen
-| (c) 1998 - 2008 | Katja Zedel
-| | Henning Peters
-+-------------------+
-
-This program may not be used, modified or distributed
-without prior permission by the authors of Eressea.
-*/
-
-#include
-#include "bind_dict.h"
-
-#include
-#include
-#include
-#include
-
-#include
-
-#include
-#include
-
-#include
-#include
-
-#include
-#include
-
-static int tolua_dict_get(lua_State * L)
-{
- dict self = (dict)tolua_tousertype(L, 1, 0);
- const char *name = tolua_tostring(L, 2, 0);
- attrib *a = a_find(*self, &at_dict);
-
- for (; a && a->type == &at_dict; a = a->next) {
- const char *obj_name = dict_name(a);
- if (obj_name && name && strcmp(obj_name, name) == 0) {
- variant val;
- dict_type type;
-
- dict_get(a, &type, &val);
- switch (type) {
- case TNONE:
- lua_pushnil(L);
- break;
- case TINTEGER:
- lua_pushinteger(L, val.i);
- break;
- case TREAL:
- lua_pushnumber(L, (lua_Number)val.f);
- break;
- case TREGION:
- tolua_pushusertype(L, val.v, TOLUA_CAST "region");
- break;
- case TBUILDING:
- tolua_pushusertype(L, val.v, TOLUA_CAST "building");
- break;
- case TUNIT:
- tolua_pushusertype(L, val.v, TOLUA_CAST "unit");
- break;
- case TSHIP:
- tolua_pushusertype(L, val.v, TOLUA_CAST "ship");
- break;
- case TSTRING:
- tolua_pushstring(L, (const char *)val.v);
- break;
- default:
- assert(!"not implemented");
- }
- return 1;
- }
- }
- lua_pushnil(L);
- return 1;
-}
-
-static int tolua_dict_set_number(lua_State * L)
-{
- dict self = (dict)tolua_tousertype(L, 1, 0);
- const char *name = tolua_tostring(L, 2, 0);
- lua_Number value = tolua_tonumber(L, 3, 0);
- attrib *a = a_find(*self, &at_dict);
- variant val;
-
- val.f = (float)value;
-
- for (; a && a->type == &at_dict; a = a->next) {
- if (strcmp(dict_name(a), name) == 0) {
- dict_set(a, TREAL, val);
- return 0;
- }
- }
-
- a = a_add(self, dict_create(name, TREAL, val));
- return 0;
-}
-
-static int tolua_dict_set_string(lua_State * L)
-{
- dict self = (dict)tolua_tousertype(L, 1, 0);
- const char *name = tolua_tostring(L, 2, 0);
- const char *value = tolua_tostring(L, 3, 0);
- attrib *a = a_find(*self, &at_dict);
- variant val;
-
- val.v = _strdup(value);
-
- for (; a && a->type == &at_dict; a = a->next) {
- if (strcmp(dict_name(a), name) == 0) {
- dict_set(a, TSTRING, val);
- return 0;
- }
- }
-
- a = a_add(self, dict_create(name, TSTRING, val));
- return 0;
-}
-
-static int tolua_dict_set_usertype(lua_State * L, int type)
-{
- dict self = (dict)tolua_tousertype(L, 1, 0);
- const char *name = tolua_tostring(L, 2, 0);
- unit *value = tolua_tousertype(L, 3, 0);
- attrib *a = a_find(*self, &at_dict);
- variant val;
-
- val.v = value;
-
- for (; a && a->type == &at_dict; a = a->next) {
- if (strcmp(dict_name(a), name) == 0) {
- dict_set(a, type, val);
- return 0;
- }
- }
-
- a = a_add(self, dict_create(name, type, val));
- return 0;
-}
-
-static int tolua_dict_set(lua_State * L)
-{
- tolua_Error tolua_err;
- if (tolua_isnumber(L, 3, 0, &tolua_err)) {
- return tolua_dict_set_number(L);
- }
- else if (tolua_isusertype(L, 3, TOLUA_CAST "unit", 0, &tolua_err)) {
- return tolua_dict_set_usertype(L, TUNIT);
- }
- else if (tolua_isusertype(L, 3, TOLUA_CAST "faction", 0, &tolua_err)) {
- return tolua_dict_set_usertype(L, TFACTION);
- }
- else if (tolua_isusertype(L, 3, TOLUA_CAST "ship", 0, &tolua_err)) {
- return tolua_dict_set_usertype(L, TSHIP);
- }
- else if (tolua_isusertype(L, 3, TOLUA_CAST "building", 0, &tolua_err)) {
- return tolua_dict_set_usertype(L, TBUILDING);
- }
- else if (tolua_isusertype(L, 3, TOLUA_CAST "region", 0, &tolua_err)) {
- return tolua_dict_set_usertype(L, TREGION);
- }
- return tolua_dict_set_string(L);
-}
-
-void tolua_dict_open(lua_State * L)
-{
- /* register user types */
- tolua_usertype(L, USERTYPE_DICT);
-
- tolua_module(L, NULL, 0);
- tolua_beginmodule(L, NULL);
- {
- tolua_cclass(L, USERTYPE_DICT, USERTYPE_DICT,
- TOLUA_CAST "", NULL);
- tolua_beginmodule(L, USERTYPE_DICT);
- {
- tolua_function(L, TOLUA_CAST "get", tolua_dict_get);
- tolua_function(L, TOLUA_CAST "set", tolua_dict_set);
- }
- tolua_endmodule(L);
- }
- tolua_endmodule(L);
-}
diff --git a/src/bind_dict.h b/src/bind_dict.h
deleted file mode 100644
index 83ca1efbf..000000000
--- a/src/bind_dict.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-+-------------------+
-| | Enno Rehling
-| Eressea PBEM host | Christian Schlittchen
-| (c) 1998 - 2008 | Katja Zedel
-| | Henning Peters
-+-------------------+
-
-This program may not be used, modified or distributed
-without prior permission by the authors of Eressea.
-*/
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define USERTYPE_DICT ((char *)"dict")
-
- struct lua_State;
- void tolua_dict_open(struct lua_State *L);
-
- typedef struct attrib **dict;
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/src/bind_eressea.c b/src/bind_eressea.c
index 279ce8f4e..de8751306 100755
--- a/src/bind_eressea.c
+++ b/src/bind_eressea.c
@@ -9,6 +9,8 @@
#include
#include
+#include
+
#include
#include