Merge branch 'develop'

This commit is contained in:
Enno Rehling 2018-11-27 18:56:01 +01:00
commit 5873c0252f
291 changed files with 8239 additions and 4913 deletions

View file

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

2
.gitignore vendored
View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

22
process/getemail.py Executable file
View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1437,7 +1437,7 @@ msgstr "Goblins"
msgctxt "spellinfo"
msgid "song_of_slavery"
msgstr "Dieser mächtige Bann raubt dem Opfer seinen freien Willen und unterwirft sie den Befehlen des Barden. Für einige Zeit wird das Opfer sich völlig von seinen eigenen Leuten abwenden und der Partei des Barden zugehörig fühlen."
msgstr "Dieser mächtige Bann raubt dem Opfer seinen freien Willen und unterwirft es den Befehlen des Barden. Für einige Zeit wird das Opfer sich völlig von seinen eigenen Leuten abwenden und der Partei des Barden zugehörig fühlen."
msgctxt "spell"
msgid "healingzone"
@ -2772,10 +2772,6 @@ msgstr "Dieser wunderschoen geschmueckte Baum entfaltet in den Wintermonaten ein
msgid "h10"
msgstr "Kakteenschwitz"
msgctxt "keyword"
msgid "besiege"
msgstr "BELAGERE"
msgid "h11"
msgstr "Sandfäule"

View file

@ -2421,10 +2421,6 @@ msgctxt "iteminfo"
msgid "xmastree"
msgstr "In the winter months, this beautifully decorated tree has a magical effect on the entire forest."
msgctxt "keyword"
msgid "besiege"
msgstr "BESIEGE"
msgid "h10"
msgstr "peyote"

View file

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

View file

@ -22,11 +22,12 @@ exit $2 # otherwise
function build() {
assert_dir $SOURCE
cd $SOURCE
rm -rf crypto tolua
rm -rf tolua
git fetch || abort "failed to update source. do you have local changes?"
[ -z $1 ] || git checkout $1
git pull -q
git submodule update
s/cmake-init
s/build > /dev/null || abort "build failed."
}
@ -54,7 +55,8 @@ cd $TESTROOT
cat >| eressea.ini <<HEREDOC
[lua]
dbname = preview.db
dbname = eressea.db
dbswap = :memory:
install = $SOURCE
paths = $SOURCE/lunit:$SOURCE/git/scripts
rules = e$game
@ -69,7 +71,6 @@ cd $TESTROOT
[ -d data ] || mkdir data
assert_dir data
assert_files $LIVE/orders.$turn $LIVE/data/$turn.dat
cp $LIVE/eressea.db preview.db
ln -f $LIVE/orders.$turn
ln -f $LIVE/data/$turn.dat data/
rm -rf reports

View file

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

View file

@ -132,7 +132,7 @@ function equip_unit(u, name, flags)
end
local spells = set['spells']
if spells then
for name, level in ipairs(spells) do
for name, level in pairs(spells) do
u:add_spell(name, level)
end
end

View file

@ -1,3 +1,4 @@
-- Weltentor portal module
local tunnels = {}
local buildings = {}
@ -24,25 +25,15 @@ local function get_target(param)
end
local function tunnel_action(b, param)
local r = nil
if tonumber(param)~=nil then
r = get_region_by_id(tonumber(param))
end
local units = tunnel_travelers(b)
if units~=nil then
local rto = get_target(param)
if rto and units then
eressea.log.debug("Tunnel from " .. tostring(b) .. " [" .. param .. "]")
for key, u in pairs(units) do
local rto = r
if r==nil then
rto = get_target(param)
end
if rto~=nil then
u.region = rto
eressea.log.debug("teleported " .. tostring(u) .. " to " .. tostring(rto))
end
end
end
return 1 -- return 0 to destroy
end
function tunnels.init()

View file

@ -74,7 +74,7 @@ function use_xmastree(u, amount)
if u.region.herb~=nil then
-- TODO: else?
local trees = u.region:get_resource("tree")
u.region:set_key("xm06", true)
u.region:set_key("xm06", get_turn())
u.region:set_resource("tree", 10+trees)
local msg = usepotion_message(u, "xmastree")
msg:send_region(u.region)
@ -107,7 +107,7 @@ function self.update()
-- we celebrate knut and kick out the trees.
for r in regions() do
if r:get_key("xm06") then
r:set_key("xm06", false)
r:set_key("xm06", 0)
end
end
end

View file

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

View file

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

View file

@ -1150,3 +1150,35 @@ function test_immunity_stops_guard()
assert_equal(f.age, 2)
assert_true(u.guard)
end
function test_region_keys()
local r = region.create(0, 0, 'plain')
assert_nil(r:get_key('test'))
assert_nil(r:get_key('more'))
r:set_key('test', 42)
r:set_key('more') -- default is 1
assert_equal(42, r:get_key('test'))
assert_equal(1, r:get_key('more'))
end
function test_faction_keys()
local f = faction.create('human')
assert_nil(f:get_key('test'))
assert_nil(f:get_key('more'))
f:set_key('test', 42)
f:set_key('more') -- default is 1
assert_equal(42, f:get_key('test'))
assert_equal(1, f:get_key('more'))
end
function test_cartmaking()
local f = faction.create('human')
local r = region.create(0, 0, 'plain')
local u = unit.create(f, r)
u:set_skill('cartmaking', 1)
u:add_item('log', 10)
u:add_order('MACHE Wagen')
process_orders()
assert_equal(1, u:get_item('cart'))
assert_equal(5, u:get_item('log'))
end

View file

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

View file

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

View file

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

View file

@ -9,7 +9,7 @@ function setup()
eressea.settings.set("NewbieImmunity", "0")
end
function test_piracy()
function test_piracy()
local r = region.create(0, 0, "plain")
local r2 = region.create(1, 0, "plain")
local r3 = region.create(-1, 0, "ocean")

View file

@ -10,6 +10,7 @@ function setup()
eressea.settings.set("rules.food.flags", "4")
eressea.settings.set("rules.peasants.growth.factor", "0")
eressea.settings.set("magic.fumble.enable", "0")
eressea.settings.set("magic.regeneration.enable", "0")
end
function test_shapeshift()
@ -104,6 +105,52 @@ function test_earn_silver()
assert_equal(0, r:get_resource("money"))
end
function test_familiar_cast()
local r = region.create(0, 0, "plain")
r:set_resource("money", 350)
r:set_resource("peasant", 0)
local f = faction.create("human")
local u = unit.create(f, r)
u.magic = "gwyrrd"
u:set_skill("magic", 10)
u.aura = 200
u:add_spell("earn_silver#gwyrrd")
u:add_order('ARBEITE')
local uf = unit.create(f, r)
uf.race = "lynx"
uf:set_skill("magic", 5)
uf:add_order('ZAUBER STUFE 1 Viehheilung')
u.familiar = uf
process_orders()
assert_equal(198, u.aura) -- Fremdzauber, Kosten verdoppelt
assert_equal(10, u:get_item('money')) -- von ARBEITE
assert_equal(50, uf:get_item('money')) -- von Zauber
assert_equal(300, uf.region:get_resource("money"))
end
function test_familiar_mage_actions()
local r = region.create(0, 0, "plain")
r:set_resource("money", 350)
r:set_resource("peasant", 0)
local f = faction.create("human")
local u = unit.create(f, r)
u.magic = "gwyrrd"
u:set_skill("magic", 10)
u.aura = 200
u:add_spell("earn_silver#gwyrrd")
u:add_order('ZAUBER STUFE 1 Viehheilung')
local uf = unit.create(f, r)
uf.race = "lynx"
uf:set_skill("magic", 5)
uf:add_order('ZAUBER STUFE 1 Viehheilung')
u.familiar = uf
process_orders()
assert_equal(50, u:get_item('money'))
assert_equal(50, uf:get_item('money'))
assert_equal(250, uf.region:get_resource("money"))
assert_equal(197, u.aura)
end
function test_familiar()
local r = region.create(0, 0, "mountain")
local f = faction.create("human")
@ -136,3 +183,67 @@ function test_familiar_lynx()
assert_equal(1, u:get_skill('magic'))
assert_equal(1, u:get_skill('perception'))
end
function test_bug_2480()
local r = region.create(0, 0, "plain")
local f = faction.create("human", "2480@eressea.de", "de")
local u1 = unit.create(f, r, 1)
local monster = unit.create(get_monsters(), r, 1, "wyrm")
u1.number = 30
u1.hp = u1.hp_max * u1.number
monster:add_order("ATTACK " .. itoa36(u1.id))
process_orders()
assert_equal(0, u1.number);
end
function test_bug_2517()
local r = region.create(0, 0, "plain")
local f = faction.create("elf")
local um = unit.create(f, r, 1)
local uf = nil
eressea.settings.set("magic.familiar.race", "lynx")
f.magic = 'gwyrrd'
um.name = 'Xolgrim'
um.magic = 'gwyrrd'
um.race = 'elf'
um:set_skill('magic', 10)
um:add_spell('summon_familiar')
um:add_spell('earn_silver#gwyrrd')
um:add_order('ZAUBERE Vertrauten~rufen')
um.aura = 200
process_orders()
uf = um.familiar
assert_not_nil(uf)
assert_equal('lynx', uf.race)
assert_equal('gray', uf.magic)
uf:add_order('LERNE Magie')
um:clear_orders()
um:add_order('ARBEITEN')
process_orders()
assert_equal('gray', uf.magic)
uf:add_order('ZAUBERE STUFE 1 Viehheilung')
process_orders()
assert_equal(50, uf:get_item('money'))
end
function test_familiar_school()
local r = region.create(0, 0, "plain")
r:set_resource("money", 350)
r:set_resource("peasant", 0)
local f = faction.create("human")
local u = unit.create(f, r)
u.magic = "draig"
u:set_skill("magic", 10)
u.aura = 200
u:add_spell("fireball")
local uf = unit.create(f, r)
uf.race = "lynx"
u.familiar = uf
assert_nil(uf.magic)
uf:set_skill("magic", 5)
assert_nil(uf.magic)
uf.aura = 10
assert_equal(0, uf.aura)
assert_nil(uf.magic)
end

View file

@ -6,6 +6,33 @@ function setup()
eressea.free_game()
end
function test_undead_reserve_self()
local r1 = region.create(0, 0, "plain")
local f1 = faction.create("human")
local u1 = unit.create(f1, r1, 1)
u1.race = "undead"
u1:clear_orders()
u1:add_item("log", 2)
u1:add_order("RESERVIERE 1 Holz")
u1:add_order("GIB 0 ALLES Holz")
process_orders()
assert_equal(1, u1:get_item("log"))
end
function test_undead_reserve_other()
local r1 = region.create(0, 0, "plain")
local f1 = faction.create("human")
local u1 = unit.create(f1, r1, 1)
local u2 = unit.create(f1, r1, 1)
u2:add_item("log", 2)
u1.race = "undead"
u1:clear_orders()
u1:add_order("RESERVIERE 1 Holz")
process_orders()
assert_equal(0, u1:get_item("log"))
assert_equal(2, u2:get_item("log"))
end
function test_undead_give_item()
local r1 = region.create(0, 0, "plain")
local f1 = faction.create("human", "hodor@eressea.de", "de")

View file

@ -34,22 +34,18 @@ function test_build_watch()
local u = unit.create(f, r, 1)
u.number = 20
u:add_item("log", 20)
u:add_item("log", 30)
u.id = 42
u:set_skill("building", 1)
u:add_order("MACHE Wache")
process_orders()
assert_not_nil(u.building)
if 5 ~= u.building.size then
-- debug logging to find intermittent errors
for k,v in ipairs(f.messages) do
print(v)
end
end
-- stage two needs skill 2, this unit can only build a first stage:
assert_equal(5, u.building.size)
u:set_skill("building", 2)
u:clear_orders()
u:add_order("MACHE Wache " .. itoa36(u.building.id))
process_orders()
assert_not_nil(u.building)

View file

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

View file

@ -75,9 +75,11 @@ end
function test_xmastree()
local r
r = use_tree("ocean")
assert_nil(r:get_key("xm06"))
assert_equal(0, r:get_resource("tree"))
eressea.free_game()
r = use_tree("plain")
assert_equal(get_turn(), r:get_key("xm06"))
assert_equal(10, r:get_resource("tree"))
end

View file

@ -1,52 +0,0 @@
-- create a fixed path to a specific region
local function create_path(from, to)
local param = tostring(to.uid)
local b = building.create(from, "portal")
b.name = "Weltentor"
b.size = 1
b:add_action("tunnel_action", param)
end
-- create a wonky tunnel wth more than one exit
local function create_tunnel(from, param)
local b = building.create(from, "portal")
b.name = "Weltentor"
b.size = 1
b:add_action("tunnel_action", param)
end
-- make a tunnel from the cursor to the first selected region
function mktunnel()
local from = gmtool.get_cursor()
local to = gmtool.get_selection()()
if to~=nil then
region.create(from.x, from.y, "glacier")
create_tunnel(from, to)
gmtool.select(to, 0)
gmtool.highlight(to, 1)
end
end
-- turn all selected regions into targets for a wonky tunnel ("tnnL")
function mkanchors()
for r in gmtool.get_selection() do
if not r:get_key("tnnL") then
r:set_key("tnnL", true)
if r:get_flag(0) then
-- RF_CHAOTIC gets removed
r:set_flag(0, false)
end
r:set_resource("peasant", r:get_resource("peasant") + 1)
end
end
end
-- region.create and prepare all hell-regions to become wonky gates
function mkgates()
for r in regions() do
if r.plane_id==0 and r.terrain=="hell" then
create_tunnel(r, "tnnL")
region.create(r.x, r.y, "glacier")
end
end
end

View file

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

View file

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

View file

@ -33,8 +33,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/unit.h>
/* util includes */
#include <util/attrib.h>
#include <util/gamedata.h>
#include <kernel/attrib.h>
#include <kernel/gamedata.h>
#include <util/base36.h>
#include <util/log.h>
#include <util/macros.h>
@ -66,7 +66,8 @@ void new_potiontype(item_type * itype, int level)
{
potion_type *ptype;
ptype = (potion_type *)calloc(sizeof(potion_type), 1);
ptype = (potion_type *)calloc(1, sizeof(potion_type));
assert(ptype);
itype->flags |= ITF_POTION;
ptype->itype = itype;
ptype->level = level;
@ -181,7 +182,7 @@ int use_potion(unit * u, const item_type * itype, int amount, struct order *ord)
static void a_initeffect(variant *var)
{
var->v = calloc(sizeof(effect_data), 1);
var->v = calloc(1, sizeof(effect_data));
}
static void

View file

@ -44,16 +44,16 @@ static void test_herbsearch(CuTest * tc)
CuAssertPtrEquals(tc, u2, is_guarded(r, u));
herbsearch(u, INT_MAX);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error70"));
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error59"));
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error59"));
test_clear_messages(f);
setguard(u2, false);
CuAssertPtrEquals(tc, 0, is_guarded(r, u));
CuAssertPtrEquals(tc, 0, (void *)rherbtype(r));
CuAssertPtrEquals(tc, NULL, is_guarded(r, u));
CuAssertPtrEquals(tc, NULL, (void *)rherbtype(r));
herbsearch(u, INT_MAX);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error108"));
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error70"));
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error59"));
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error70"));
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error59"));
test_clear_messages(f);
rsetherbtype(r, itype);
@ -61,9 +61,9 @@ static void test_herbsearch(CuTest * tc)
CuAssertIntEquals(tc, 0, rherbs(r));
herbsearch(u, INT_MAX);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "researchherb_none"));
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error108"));
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error70"));
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error59"));
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error108"));
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error70"));
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error59"));
test_clear_messages(f);
rsetherbs(r, 100);
@ -72,10 +72,10 @@ static void test_herbsearch(CuTest * tc)
CuAssertIntEquals(tc, 99, rherbs(r));
CuAssertIntEquals(tc, 1, i_get(u->items, itype));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "herbfound"));
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "researchherb_none"));
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error108"));
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error70"));
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error59"));
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "researchherb_none"));
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error108"));
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error70"));
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error59"));
test_clear_messages(f);
test_teardown();

View file

@ -53,9 +53,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/building.h>
/* util includes */
#include <util/attrib.h>
#include <util/event.h>
#include <util/gamedata.h>
#include <kernel/attrib.h>
#include <kernel/event.h>
#include <kernel/gamedata.h>
#include <util/macros.h>
#include <util/resolve.h>
@ -98,7 +98,7 @@ static int obs_read(variant *var, void *owner, struct gamedata *data)
obs_data *od = (obs_data *)var->v;
UNUSED_ARG(owner);
read_faction_reference(data, &od->f, NULL);
read_faction_reference(data, &od->f);
READ_INT(data->store, &od->skill);
READ_INT(data->store, &od->timer);
return AT_READ_OK;
@ -182,13 +182,13 @@ void register_attributes(void)
at_register(&at_seenspell);
at_register(&at_seenspells);
/* neue REGION-Attribute */
/* REGION Attribute */
at_register(&at_moveblock);
at_register(&at_deathcount);
at_register(&at_woodcount);
at_register(&at_germs);
/* neue UNIT-Attribute */
at_register(&at_siege);
/* UNIT Attribute */
at_register(&at_effect);
at_register(&at_private);
@ -205,8 +205,7 @@ void register_attributes(void)
register_bordertype(&bt_illusionwall);
register_bordertype(&bt_road);
at_register(&at_germs);
at_deprecate("siege", a_readint);
at_deprecate("maxmagicians", a_readint); /* factions with differnt magician limits, probably unused */
at_deprecate("hurting", a_readint); /* an old arena attribute */
at_deprecate("chaoscount", a_readint); /* used to increase the chance of monster spawns */

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -22,8 +22,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include <kernel/region.h>
#include <util/attrib.h>
#include <util/gamedata.h>
#include <kernel/attrib.h>
#include <kernel/gamedata.h>
#include <util/resolve.h>
#include <storage.h>
@ -36,7 +36,7 @@ write_targetregion(const variant *var, const void *owner, struct storage *store)
static int read_targetregion(variant *var, void *owner, gamedata *data)
{
if (read_region_reference(data, (region **)&var->v, NULL) <= 0) {
if (read_region_reference(data, (region **)&var->v) <= 0) {
return AT_READ_FAIL;
}
return AT_READ_OK;

View file

@ -6,10 +6,10 @@
#include "kernel/region.h"
#include "kernel/unit.h"
#include "util/keyword.h"
#include "util/log.h"
#include "automate.h"
#include "keyword.h"
#include "laws.h"
#include "study.h"
@ -55,10 +55,6 @@ int autostudy_init(scholar scholars[], int max_scholars, unit **units)
unext = u;
}
}
else {
ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "error_race_nolearn", "race",
u_race(u)));
}
}
u = u->next;
}

File diff suppressed because it is too large Load diff

View file

@ -173,9 +173,8 @@ extern "C" {
struct person {
int hp; /* Trefferpunkte der Personen */
int attack;
int defence;
int defense;
int damage;
int damage_rear;
int flags;
int speed;
int reload;
@ -233,7 +232,10 @@ 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, union variant *magres);
const struct armor_type *select_armor(struct troop t, bool shield);
struct weapon *select_weapon(const struct troop t, bool attacking, bool ismissile);
int calculate_armor(troop dt, const struct weapon_type *dwtype, const struct weapon_type *awtype, const struct armor_type *armor, const struct armor_type *shield, bool magic);
int apply_resistance(int damage, struct troop dt, const struct weapon_type *dwtype, const struct armor_type *armor, const struct armor_type *shield, bool magic);
bool terminate(troop dt, troop at, int type, const char *damage,
bool missile);
void message_all(battle * b, struct message *m);

View file

@ -2,6 +2,7 @@
#include "battle.h"
#include "guard.h"
#include "reports.h"
#include "skill.h"
@ -10,6 +11,7 @@
#include <kernel/faction.h>
#include <kernel/curse.h>
#include <kernel/item.h>
#include <kernel/order.h>
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/ship.h>
@ -17,7 +19,9 @@
#include <spells/buildingcurse.h>
#include <util/base36.h>
#include <util/functions.h>
#include "util/keyword.h"
#include <util/language.h>
#include <util/message.h>
#include <util/rand.h>
@ -31,6 +35,21 @@
#include "tests.h"
static void setup_messages(void) {
mt_create_va(mt_new("start_battle", NULL), "factions:string", MT_NEW_END);
mt_create_va(mt_new("para_army_index", NULL), "index:int", "name:string", MT_NEW_END);
mt_create_va(mt_new("battle_msg", NULL), "string:string", MT_NEW_END);
mt_create_va(mt_new("battle_row", NULL), "row:int", MT_NEW_END);
mt_create_va(mt_new("para_lineup_battle", NULL), "turn:int", MT_NEW_END);
mt_create_va(mt_new("para_after_battle", NULL), MT_NEW_END);
mt_create_va(mt_new("army_report", NULL),
"index:int", "abbrev:string", "dead:int", "fled:int", "survived:int",
MT_NEW_END);
mt_create_va(mt_new("casualties", NULL),
"unit:unit", "runto:region", "run:int", "alive:int", "fallen:int",
MT_NEW_END);
}
static void test_make_fighter(CuTest * tc)
{
unit *au;
@ -59,7 +78,7 @@ static void test_make_fighter(CuTest * tc)
af = make_fighter(b, au, as, false);
CuAssertIntEquals(tc, 1, b->nfighters);
CuAssertPtrEquals(tc, 0, af->building);
CuAssertPtrEquals(tc, NULL, af->building);
CuAssertPtrEquals(tc, as, af->side);
CuAssertIntEquals(tc, 0, af->run.hp);
CuAssertIntEquals(tc, ST_BEHIND, af->status);
@ -197,7 +216,7 @@ static void test_defenders_get_building_bonus(CuTest * tc)
af = make_fighter(b, au, as, true);
CuAssertPtrEquals(tc, bld, df->building);
CuAssertPtrEquals(tc, 0, af->building);
CuAssertPtrEquals(tc, NULL, af->building);
dt.fighter = df;
dt.index = 0;
@ -242,7 +261,7 @@ static void test_attackers_get_no_building_bonus(CuTest * tc)
as = make_side(b, au->faction, 0, 0, 0);
af = make_fighter(b, au, as, true);
CuAssertPtrEquals(tc, 0, af->building);
CuAssertPtrEquals(tc, NULL, af->building);
free_battle(b);
test_teardown();
}
@ -279,12 +298,12 @@ static void test_building_bonus_respects_size(CuTest * tc)
df = make_fighter(b, du, as, false);
CuAssertPtrEquals(tc, bld, af->building);
CuAssertPtrEquals(tc, 0, df->building);
CuAssertPtrEquals(tc, NULL, df->building);
free_battle(b);
test_teardown();
}
static void test_building_defence_bonus(CuTest * tc)
static void test_building_defense_bonus(CuTest * tc)
{
building_type * btype;
@ -339,6 +358,16 @@ static void test_natural_armor(CuTest * tc)
test_teardown();
}
static int test_armor(troop dt, weapon_type *awtype, bool magic) {
return calculate_armor(dt, 0, awtype, select_armor(dt, false), select_armor(dt, true), magic);
}
static int test_resistance(troop dt) {
return apply_resistance(1000, dt,
select_weapon(dt, false, true) ? select_weapon(dt, false, true)->type : 0,
select_armor(dt, false), select_armor(dt, true), true);
}
static void test_calculate_armor(CuTest * tc)
{
troop dt;
@ -349,7 +378,6 @@ static void test_calculate_armor(CuTest * tc)
armor_type *ashield, *achain;
item_type *ibelt, *ishield, *ichain;
race *rc;
variant magres = frac_zero;
variant v50p = frac_make(1, 2);
test_setup();
@ -365,18 +393,19 @@ static void test_calculate_armor(CuTest * tc)
dt.index = 0;
dt.fighter = setup_fighter(&b, du);
CuAssertIntEquals_Msg(tc, "default ac", 0, calculate_armor(dt, 0, 0, &magres));
CuAssertIntEquals_Msg(tc, "magres unmodified", magres.sa[0], magres.sa[1]);
CuAssertIntEquals_Msg(tc, "default ac", 0, test_armor(dt, 0, false));
CuAssertIntEquals_Msg(tc, "magres unmodified", 1000, test_resistance(dt));
free_battle(b);
b = NULL;
i_change(&du->items, ibelt, 1);
dt.fighter = setup_fighter(&b, du);
CuAssertIntEquals_Msg(tc, "without natural armor", 0, natural_armor(du));
CuAssertIntEquals_Msg(tc, "magical armor", 1, calculate_armor(dt, 0, 0, 0));
CuAssertIntEquals_Msg(tc, "magical armor", 1, test_armor(dt, 0, false));
rc->armor = 2;
CuAssertIntEquals_Msg(tc, "with natural armor", 2, natural_armor(du));
CuAssertIntEquals_Msg(tc, "natural armor", 3, calculate_armor(dt, 0, 0, 0));
CuAssertIntEquals_Msg(tc, "natural armor", 3, test_armor(dt, 0, false));
rc->armor = 0;
free_battle(b);
@ -385,29 +414,30 @@ static void test_calculate_armor(CuTest * tc)
i_change(&du->items, ichain, 1);
dt.fighter = setup_fighter(&b, du);
rc->battle_flags &= ~BF_EQUIPMENT;
CuAssertIntEquals_Msg(tc, "require BF_EQUIPMENT", 1, calculate_armor(dt, 0, 0, 0));
CuAssertIntEquals_Msg(tc, "require BF_EQUIPMENT", 1, test_armor(dt, 0, false));
free_battle(b);
b = NULL;
rc->battle_flags |= BF_EQUIPMENT;
dt.fighter = setup_fighter(&b, du);
CuAssertIntEquals_Msg(tc, "stack equipment rc", 5, calculate_armor(dt, 0, 0, 0));
CuAssertIntEquals_Msg(tc, "stack equipment rc", 5, test_armor(dt, 0, false));
rc->armor = 2;
CuAssertIntEquals_Msg(tc, "natural armor adds 50%", 6, calculate_armor(dt, 0, 0, 0));
CuAssertIntEquals_Msg(tc, "natural armor adds 50%", 6, test_armor(dt, 0, false));
wtype->flags = WTF_NONE;
CuAssertIntEquals_Msg(tc, "regular weapon has no effect", 6, calculate_armor(dt, 0, wtype, 0));
CuAssertIntEquals_Msg(tc, "regular weapon has no effect", 6, test_armor(dt, wtype, false));
wtype->flags = WTF_ARMORPIERCING;
CuAssertIntEquals_Msg(tc, "armor piercing weapon", 3, calculate_armor(dt, 0, wtype, 0));
CuAssertIntEquals_Msg(tc, "armor piercing weapon", 3, test_armor(dt, wtype, false));
wtype->flags = WTF_NONE;
CuAssertIntEquals_Msg(tc, "magical attack", 3, calculate_armor(dt, 0, 0, &magres));
CuAssertIntEquals_Msg(tc, "magres unmodified", magres.sa[1], magres.sa[0]);
CuAssertIntEquals_Msg(tc, "magical attack", 3, test_armor(dt, wtype, true));
CuAssertIntEquals_Msg(tc, "magres unmodified", 1000,
test_resistance(dt));
ashield->flags |= ATF_LAEN;
achain->flags |= ATF_LAEN;
magres = frac_one;
CuAssertIntEquals_Msg(tc, "laen armor", 3, calculate_armor(dt, 0, 0, &magres));
CuAssertIntEquals_Msg(tc, "laen magres bonus", 4, magres.sa[1]);
CuAssertIntEquals_Msg(tc, "laen armor", 3, test_armor(dt, wtype, true));
CuAssertIntEquals_Msg(tc, "laen magres bonus", 250, test_resistance(dt));
free_battle(b);
test_teardown();
}
@ -437,15 +467,17 @@ static void test_magic_resistance(CuTest *tc)
i_change(&du->items, ishield, 1);
dt.fighter = setup_fighter(&b, du);
calculate_armor(dt, 0, 0, &magres);
CuAssertIntEquals_Msg(tc, "no magres reduction", magres.sa[1], magres.sa[0]);
CuAssertIntEquals_Msg(tc, "no magres reduction", 1000, test_resistance(dt));
magres = magic_resistance(du);
CuAssertIntEquals_Msg(tc, "no magres reduction", 0, magres.sa[0]);
ashield->flags |= ATF_LAEN;
ashield->magres = v10p;
calculate_armor(dt, 0, 0, &magres);
CuAssert(tc, "laen reduction => 10%%", frac_equal(frac_make(9, 10), magres));
CuAssertIntEquals_Msg(tc, "laen reduction => 10%%", 900, test_resistance(dt));
CuAssertIntEquals_Msg(tc, "no magic, no resistance", 1000,
apply_resistance(1000, dt,
select_weapon(dt, false, true) ? select_weapon(dt, false, true)->type : 0,
select_armor(dt, false), select_armor(dt, true), false));
free_battle(b);
b = NULL;
@ -455,8 +487,7 @@ static void test_magic_resistance(CuTest *tc)
ashield->flags |= ATF_LAEN;
ashield->magres = v10p;
dt.fighter = setup_fighter(&b, du);
calculate_armor(dt, 0, 0, &magres);
CuAssert(tc, "2x laen reduction => 81%%", frac_equal(frac_make(81, 100), magres));
CuAssertIntEquals_Msg(tc, "2x laen reduction => 81%%", 810, test_resistance(dt));
free_battle(b);
b = NULL;
@ -464,21 +495,18 @@ static void test_magic_resistance(CuTest *tc)
i_change(&du->items, ichain, -1);
set_level(du, SK_MAGIC, 2);
dt.fighter = setup_fighter(&b, du);
calculate_armor(dt, 0, 0, &magres);
CuAssert(tc, "skill reduction => 90%%", frac_equal(magres, frac_make(9, 10)));
CuAssertIntEquals_Msg(tc, "skill reduction => 90%%", 900, test_resistance(dt));
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);
CuAssert(tc, "race reduction => 40%%", frac_equal(magres, frac_make(4, 10)));
CuAssertIntEquals_Msg(tc, "race reduction => 40%%", 400, test_resistance(dt));
magres = magic_resistance(du);
CuAssert(tc, "race bonus => 60%%", frac_equal(magres, frac_make(60, 100)));
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);
CuAssert(tc, "damage reduction is never < 0.1", frac_equal(magres, frac_make(1, 10)));
CuAssertIntEquals_Msg(tc, "damage reduction is never < 0.1", 100, test_resistance(dt));
free_battle(b);
test_teardown();
@ -513,12 +541,12 @@ static void test_projectile_armor(CuTest * tc)
dt.fighter = setup_fighter(&b, du);
wtype->flags = WTF_MISSILE;
achain->projectile = 1.0;
CuAssertIntEquals_Msg(tc, "projectile armor", -1, calculate_armor(dt, 0, wtype, 0));
CuAssertIntEquals_Msg(tc, "projectile armor", -1, test_armor(dt, wtype, false));
achain->projectile = 0.0;
ashield->projectile = 1.0;
CuAssertIntEquals_Msg(tc, "projectile shield", -1, calculate_armor(dt, 0, wtype, 0));
CuAssertIntEquals_Msg(tc, "projectile shield", -1, test_armor(dt, wtype, false));
wtype->flags = WTF_NONE;
CuAssertIntEquals_Msg(tc, "no projectiles", 4, calculate_armor(dt, 0, wtype, 0));
CuAssertIntEquals_Msg(tc, "no projectiles", 4, test_armor(dt, wtype, false));
free_battle(b);
test_teardown();
}
@ -542,7 +570,7 @@ static void test_battle_skilldiff(CuTest *tc)
CuAssertIntEquals(tc, 0, skilldiff(ta, td, 0));
ta.fighter->person[0].attack = 2;
td.fighter->person[0].defence = 1;
td.fighter->person[0].defense = 1;
CuAssertIntEquals(tc, 1, skilldiff(ta, td, 0));
td.fighter->person[0].flags |= FL_SLEEPING;
@ -556,6 +584,38 @@ static void test_battle_skilldiff(CuTest *tc)
test_teardown();
}
static void test_terminate(CuTest * tc)
{
troop at, dt;
battle *b = NULL;
region *r;
unit *au, *du;
race *rc;
test_setup();
r = test_create_region(0, 0, NULL);
rc = test_create_race("human");
au = test_create_unit(test_create_faction(rc), r);
du = test_create_unit(test_create_faction(rc), r);
dt.index = 0;
at.index = 0;
at.fighter = setup_fighter(&b, au);
dt.fighter = setup_fighter(&b, du);
CuAssertIntEquals_Msg(tc, "not killed", 0, terminate(dt, at, AT_STANDARD, "1d1", false));
b = NULL;
at.fighter = setup_fighter(&b, au);
dt.fighter = setup_fighter(&b, du);
CuAssertIntEquals_Msg(tc, "killed", 1, terminate(dt, at, AT_STANDARD, "100d1", false));
CuAssertIntEquals_Msg(tc, "number", 0, dt.fighter->person[0].hp);
free_battle(b);
test_teardown();
}
static void test_battle_report_one(CuTest *tc)
{
battle * b = NULL;
@ -566,7 +626,7 @@ static void test_battle_report_one(CuTest *tc)
fighter *fig;
test_setup();
mt_create_va(mt_new("start_battle", NULL), "factions:string", MT_NEW_END);
setup_messages();
r = test_create_plain(0, 0);
u1 = test_create_unit(test_create_faction(NULL), r);
u2 = test_create_unit(test_create_faction(NULL), r);
@ -597,7 +657,7 @@ static void test_battle_report_two(CuTest *tc)
test_setup();
lang = test_create_locale();
locale_setstring(lang, "and", "and");
mt_create_va(mt_new("start_battle", NULL), "factions:string", MT_NEW_END);
setup_messages();
r = test_create_plain(0, 0);
u1 = test_create_unit(test_create_faction(NULL), r);
u1->faction->locale = lang;
@ -630,7 +690,7 @@ static void test_battle_report_three(CuTest *tc)
test_setup();
lang = test_create_locale();
locale_setstring(lang, "and", "and");
mt_create_va(mt_new("start_battle", NULL), "factions:string", MT_NEW_END);
setup_messages();
r = test_create_plain(0, 0);
u1 = test_create_unit(test_create_faction(NULL), r);
u1->faction->locale = lang;
@ -783,12 +843,43 @@ static void test_tactics_chance(CuTest *tc) {
test_teardown();
}
static void test_battle_fleeing(CuTest *tc) {
region *r;
unit *u1, *u2;
test_setup();
setup_messages();
r = test_create_plain(0, 0);
u1 = test_create_unit(test_create_faction(NULL), r);
u2 = test_create_unit(test_create_faction(NULL), r);
u1->status = ST_FLEE;
u2->status = ST_AGGRO;
#if 0
setguard(u1, true);
CuAssertIntEquals(tc, UFL_GUARD, (u1->flags & UFL_GUARD));
CuAssertIntEquals(tc, RF_GUARDED, (r->flags & RF_GUARDED));
#endif
config_set_int("rules.combat.flee_chance_base", 100);
config_set_int("rules.combat.flee_chance_limit", 100);
unit_addorder(u2, create_order(K_ATTACK, u2->faction->locale, itoa36(u1->no)));
do_battles();
CuAssertIntEquals(tc, 1, u1->number);
CuAssertIntEquals(tc, 1, u2->number);
#if 0
CuAssertIntEquals(tc, 0, (u1->flags & UFL_GUARD));
CuAssertIntEquals(tc, 0, (r->flags & RF_GUARDED));
#endif
CuAssertIntEquals(tc, UFL_LONGACTION, (u1->flags & UFL_LONGACTION));
CuAssertIntEquals(tc, UFL_LONGACTION | UFL_NOTMOVING, (u2->flags & (UFL_LONGACTION | UFL_NOTMOVING)));
test_teardown();
}
CuSuite *get_battle_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_make_fighter);
SUITE_ADD_TEST(suite, test_select_weapon_restricted);
SUITE_ADD_TEST(suite, test_select_armor);
SUITE_ADD_TEST(suite, test_battle_fleeing);
SUITE_ADD_TEST(suite, test_battle_skilldiff);
SUITE_ADD_TEST(suite, test_battle_skilldiff_building);
SUITE_ADD_TEST(suite, test_battle_report_one);
@ -797,12 +888,13 @@ CuSuite *get_battle_suite(void)
SUITE_ADD_TEST(suite, test_defenders_get_building_bonus);
SUITE_ADD_TEST(suite, test_attackers_get_no_building_bonus);
SUITE_ADD_TEST(suite, test_building_bonus_respects_size);
SUITE_ADD_TEST(suite, test_building_defence_bonus);
SUITE_ADD_TEST(suite, test_building_defense_bonus);
SUITE_ADD_TEST(suite, test_calculate_armor);
SUITE_ADD_TEST(suite, test_natural_armor);
SUITE_ADD_TEST(suite, test_magic_resistance);
SUITE_ADD_TEST(suite, test_projectile_armor);
SUITE_ADD_TEST(suite, test_tactics_chance);
SUITE_ADD_TEST(suite, test_terminate);
DISABLE_TEST(suite, test_drain_exp);
return suite;
}

View file

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

View file

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

View file

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

View file

@ -17,47 +17,32 @@ without prior permission by the authors of Eressea.
#include "bind_faction.h"
#include "bind_unit.h"
#include "bindings.h"
#include "helpers.h"
#include "magic.h"
#include <kernel/alliance.h>
#include <kernel/faction.h>
#include <kernel/unit.h>
#include <kernel/item.h>
#include <kernel/faction.h>
#include <kernel/messages.h>
#include <kernel/plane.h>
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/spellbook.h>
#include <attributes/key.h>
#include "kernel/types.h"
#include <util/base36.h>
#include <util/language.h>
#include <util/log.h>
#include <util/macros.h>
#include <util/message.h>
#include <util/password.h>
#include "attributes/key.h"
#include <lua.h>
#include <lauxlib.h>
#include <tolua.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct helpmode {
const char *name;
int status;
} helpmode;
static helpmode helpmodes[] = {
{ "all", HELP_ALL },
{ "money", HELP_MONEY },
{ "fight", HELP_FIGHT },
{ "observe", HELP_OBSERVE },
{ "give", HELP_GIVE },
{ "guard", HELP_GUARD },
{ "stealth", HELP_FSTEALTH },
{ "travel", HELP_TRAVEL },
{ NULL, 0 }
};
int tolua_factionlist_next(lua_State * L)
{
@ -74,7 +59,7 @@ int tolua_factionlist_next(lua_State * L)
static int tolua_faction_get_units(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
unit **unit_ptr = (unit **)lua_newuserdata(L, sizeof(unit *));
luaL_getmetatable(L, TOLUA_CAST "unit");
@ -88,8 +73,8 @@ static int tolua_faction_get_units(lua_State * L)
int tolua_faction_add_item(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
const char *iname = tolua_tostring(L, 2, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
const char *iname = tolua_tostring(L, 2, NULL);
int number = (int)tolua_tonumber(L, 3, 0);
int result = -1;
@ -106,35 +91,35 @@ int tolua_faction_add_item(lua_State * L)
static int tolua_faction_get_maxheroes(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
lua_pushinteger(L, maxheroes(self));
return 1;
}
static int tolua_faction_get_heroes(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
lua_pushinteger(L, countheroes(self));
return 1;
}
static int tolua_faction_get_score(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
lua_pushnumber(L, (lua_Number)self->score);
return 1;
}
static int tolua_faction_get_id(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
lua_pushinteger(L, self->no);
return 1;
}
static int tolua_faction_set_id(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
int id = (int)tolua_tonumber(L, 2, 0);
if (findfaction(id) == NULL) {
renumber_faction(self, id);
@ -148,15 +133,15 @@ static int tolua_faction_set_id(lua_State * L)
static int tolua_faction_get_magic(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
lua_pushstring(L, magic_school[self->magiegebiet]);
return 1;
}
static int tolua_faction_set_magic(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
const char *type = tolua_tostring(L, 2, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
const char *type = tolua_tostring(L, 2, NULL);
int mtype;
for (mtype = 0; mtype != MAXMAGIETYP; ++mtype) {
@ -170,14 +155,14 @@ static int tolua_faction_set_magic(lua_State * L)
static int tolua_faction_get_age(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
lua_pushinteger(L, self->age);
return 1;
}
static int tolua_faction_set_age(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
int age = (int)tolua_tonumber(L, 2, 0);
self->age = age;
return 0;
@ -185,14 +170,14 @@ static int tolua_faction_set_age(lua_State * L)
static int tolua_faction_get_flags(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
lua_pushinteger(L, self->flags);
return 1;
}
static int tolua_faction_set_flags(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
int flags = (int)tolua_tonumber(L, 2, self->flags);
self->flags = flags;
return 1;
@ -200,14 +185,14 @@ static int tolua_faction_set_flags(lua_State * L)
static int tolua_faction_get_options(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
lua_pushinteger(L, self->options);
return 1;
}
static int tolua_faction_set_options(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
int options = (int)tolua_tonumber(L, 2, self->options);
self->options = options;
return 1;
@ -215,14 +200,14 @@ static int tolua_faction_set_options(lua_State * L)
static int tolua_faction_get_lastturn(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
lua_pushinteger(L, self->lastorders);
return 1;
}
static int tolua_faction_set_lastturn(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
if (self) {
self->lastorders = (int)tolua_tonumber(L, 2, self->lastorders);
}
@ -231,7 +216,7 @@ static int tolua_faction_set_lastturn(lua_State * L)
static int tolua_faction_renumber(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
int no = (int)tolua_tonumber(L, 2, 0);
renumber_faction(self, no);
@ -240,8 +225,8 @@ static int tolua_faction_renumber(lua_State * L)
static int tolua_faction_addnotice(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
const char *str = tolua_tostring(L, 2, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
const char *str = tolua_tostring(L, 2, NULL);
addmessage(NULL, self, str, MSG_MESSAGE, ML_IMPORTANT);
return 0;
@ -249,19 +234,22 @@ static int tolua_faction_addnotice(lua_State * L)
static int tolua_faction_getkey(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
const char *name = tolua_tostring(L, 2, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
const char *name = tolua_tostring(L, 2, NULL);
int flag = atoi36(name);
lua_pushinteger(L, key_get(self->attribs, flag));
return 1;
int value = key_get(self->attribs, flag);
if (value != 0) {
lua_pushinteger(L, value);
return 1;
}
return 0;
}
static int tolua_faction_setkey(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
const char *name = tolua_tostring(L, 2, 0);
int value = (int)tolua_tonumber(L, 3, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
const char *name = tolua_tostring(L, 2, NULL);
int value = (int)tolua_tonumber(L, 3, 1);
int flag = atoi36(name);
if (value) {
@ -275,7 +263,7 @@ static int tolua_faction_setkey(lua_State * L)
static int tolua_faction_get_messages(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
int i = 1;
mlist *ml;
if (!self->msgs) {
@ -291,8 +279,8 @@ static int tolua_faction_get_messages(lua_State * L)
}
static int tolua_faction_count_msg_type(lua_State *L) {
faction *self = (faction *)tolua_tousertype(L, 1, 0);
const char *str = tolua_tostring(L, 2, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
const char *str = tolua_tostring(L, 2, NULL);
int n = 0;
if (self->msgs) {
mlist * ml = self->msgs->begin;
@ -307,53 +295,10 @@ static int tolua_faction_count_msg_type(lua_State *L) {
return 1;
}
static int tolua_faction_get_policy(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *other = (faction *)tolua_tousertype(L, 2, 0);
const char *policy = tolua_tostring(L, 3, 0);
int result = 0, mode;
for (mode = 0; helpmodes[mode].name != NULL; ++mode) {
if (strcmp(policy, helpmodes[mode].name) == 0) {
result = get_alliance(self, other) & mode;
break;
}
}
lua_pushinteger(L, result);
return 1;
}
static int tolua_faction_set_policy(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *other = (faction *)tolua_tousertype(L, 2, 0);
const char *policy = tolua_tostring(L, 3, 0);
int value = tolua_toboolean(L, 4, 0);
int mode;
for (mode = 0; helpmodes[mode].name != NULL; ++mode) {
if (strcmp(policy, helpmodes[mode].name) == 0) {
if (value) {
set_alliance(self, other, get_alliance(self,
other) | helpmodes[mode].status);
}
else {
set_alliance(self, other, get_alliance(self,
other) & ~helpmodes[mode].status);
}
break;
}
}
return 0;
}
static int tolua_faction_normalize(lua_State * L)
{
faction *f = (faction *)tolua_tousertype(L, 1, 0);
region *r = (region *)tolua_tousertype(L, 2, 0);
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
region *r = (region *)tolua_tousertype(L, 2, NULL);
if (r) {
plane *pl = rplane(r);
int nx = r->x, ny = r->y;
@ -368,8 +313,8 @@ static int tolua_faction_normalize(lua_State * L)
static int tolua_faction_set_origin(lua_State * L)
{
faction *f = (faction *)tolua_tousertype(L, 1, 0);
region *r = (region *)tolua_tousertype(L, 2, 0);
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
region *r = (region *)tolua_tousertype(L, 2, NULL);
plane *pl = rplane(r);
int id = pl ? pl->id : 0;
@ -379,21 +324,9 @@ static int tolua_faction_set_origin(lua_State * L)
static int tolua_faction_get_origin(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
ursprung *origin = self->ursprung;
int x, y;
while (origin != NULL && origin->id != 0) {
origin = origin->next;
}
if (origin) {
x = origin->x;
y = origin->y;
}
else {
x = 0;
y = 0;
}
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
int x = 0, y = 0;
faction_getorigin(self, 0, &x, &y);
lua_pushinteger(L, x);
lua_pushinteger(L, y);
@ -402,7 +335,7 @@ static int tolua_faction_get_origin(lua_State * L)
static int tolua_faction_destroy(lua_State * L)
{
faction **fp, *f = (faction *)tolua_tousertype(L, 1, 0);
faction **fp, *f = (faction *)tolua_tousertype(L, 1, NULL);
/* TODO: this loop is slow af, but what can we do? */
for (fp = &factions; *fp; fp = &(*fp)->next) {
if (*fp == f) {
@ -423,14 +356,14 @@ static int tolua_faction_get(lua_State * L)
static int tolua_faction_create(lua_State * L)
{
const char *racename = tolua_tostring(L, 1, 0);
const char *email = tolua_tostring(L, 2, 0);
const char *lang = tolua_tostring(L, 3, 0);
const char *racename = tolua_tostring(L, 1, NULL);
const char *email = tolua_tostring(L, 2, NULL);
const char *lang = tolua_tostring(L, 3, NULL);
struct locale *loc = lang ? get_locale(lang) : default_locale;
faction *f = NULL;
const struct race *frace = rc_find(racename ? racename : "human");
if (frace != NULL) {
f = addfaction(email, NULL, frace, loc, 0);
f = addfaction(email, NULL, frace, loc);
}
if (!f) {
log_error("cannot create %s faction for %s, unknown race.", racename, email);
@ -441,44 +374,44 @@ static int tolua_faction_create(lua_State * L)
static int tolua_faction_get_password(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
tolua_pushstring(L, self->_password);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
tolua_pushstring(L, faction_getpassword(self));
return 1;
}
static int tolua_faction_set_password(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
const char * passw = tolua_tostring(L, 2, 0);
faction_setpassword(self, password_encode(passw, PASSWORD_DEFAULT));
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
const char * passw = tolua_tostring(L, 2, NULL);
faction_setpassword(self, password_hash(passw, PASSWORD_DEFAULT));
return 0;
}
static int tolua_faction_get_email(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
tolua_pushstring(L, faction_getemail(self));
return 1;
}
static int tolua_faction_set_email(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction_setemail(self, tolua_tostring(L, 2, 0));
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
faction_setemail(self, tolua_tostring(L, 2, NULL));
return 0;
}
static int tolua_faction_get_locale(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
tolua_pushstring(L, locale_name(self->locale));
return 1;
}
static int tolua_faction_set_locale(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
const char *name = tolua_tostring(L, 2, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
const char *name = tolua_tostring(L, 2, NULL);
const struct locale *loc = get_locale(name);
if (loc) {
self->locale = loc;
@ -492,15 +425,15 @@ static int tolua_faction_set_locale(lua_State * L)
static int tolua_faction_get_race(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
tolua_pushstring(L, self->race->_name);
return 1;
}
static int tolua_faction_set_race(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
const char *name = tolua_tostring(L, 2, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
const char *name = tolua_tostring(L, 2, NULL);
const race *rc = rc_find(name);
if (rc != NULL) {
self->race = rc;
@ -511,57 +444,57 @@ static int tolua_faction_set_race(lua_State * L)
static int tolua_faction_get_name(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
tolua_pushstring(L, faction_getname(self));
return 1;
}
static int tolua_faction_set_name(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction_setname(self, tolua_tostring(L, 2, 0));
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
faction_setname(self, tolua_tostring(L, 2, NULL));
return 0;
}
static int tolua_faction_get_uid(lua_State * L)
{
faction *f = (faction *)tolua_tousertype(L, 1, 0);
lua_pushinteger(L, f->subscription);
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
lua_pushinteger(L, f->uid);
return 1;
}
static int tolua_faction_set_uid(lua_State * L)
{
faction *f = (faction *)tolua_tousertype(L, 1, 0);
f->subscription = (int)tolua_tonumber(L, 2, 0);
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
f->uid = (int)tolua_tonumber(L, 2, 0);
return 0;
}
static int tolua_faction_get_info(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
tolua_pushstring(L, faction_getbanner(self));
return 1;
}
static int tolua_faction_set_info(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction_setbanner(self, tolua_tostring(L, 2, 0));
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
faction_setbanner(self, tolua_tostring(L, 2, NULL));
return 0;
}
static int tolua_faction_get_alliance(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
tolua_pushusertype(L, f_get_alliance(self), TOLUA_CAST "alliance");
return 1;
}
static int tolua_faction_set_alliance(lua_State * L)
{
struct faction *self = (struct faction *)tolua_tousertype(L, 1, 0);
struct alliance *alli = (struct alliance *) tolua_tousertype(L, 2, 0);
struct faction *self = (struct faction *)tolua_tousertype(L, 1, NULL);
struct alliance *alli = (struct alliance *) tolua_tousertype(L, 2, NULL);
setalliance(self, alli);
@ -570,7 +503,7 @@ static int tolua_faction_set_alliance(lua_State * L)
static int tolua_faction_get_items(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
item **item_ptr = (item **)lua_newuserdata(L, sizeof(item *));
luaL_getmetatable(L, TOLUA_CAST "item");
@ -585,7 +518,7 @@ static int tolua_faction_get_items(lua_State * L)
static int tolua_faction_tostring(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
lua_pushstring(L, factionname(self));
return 1;
}
@ -642,8 +575,6 @@ void tolua_faction_open(lua_State * L)
tolua_variable(L, TOLUA_CAST "lastturn", tolua_faction_get_lastturn,
tolua_faction_set_lastturn);
tolua_function(L, TOLUA_CAST "set_policy", tolua_faction_set_policy);
tolua_function(L, TOLUA_CAST "get_policy", tolua_faction_get_policy);
tolua_function(L, TOLUA_CAST "get_origin", tolua_faction_get_origin);
tolua_function(L, TOLUA_CAST "set_origin", tolua_faction_set_origin);
tolua_function(L, TOLUA_CAST "normalize", tolua_faction_normalize);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -8,43 +8,41 @@
#include "bind_building.h"
#include "teleport.h"
#include "direction.h"
#include <kernel/building.h>
#include <kernel/calendar.h>
#include <kernel/config.h>
#include <kernel/curse.h>
#include <kernel/region.h>
#include <kernel/resources.h>
#include <kernel/unit.h>
#include <kernel/region.h>
#include <kernel/item.h>
#include <kernel/build.h>
#include <kernel/building.h>
#include <kernel/ship.h>
#include <kernel/plane.h>
#include <kernel/terrain.h>
#include <kernel/messages.h>
#include <modules/autoseed.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/log.h>
#include <util/macros.h>
#include <util/message.h>
#include <util/strings.h>
#include <attributes/key.h>
#include <attributes/racename.h>
#include <util/attrib.h>
#include <util/base36.h>
#include <util/language.h>
#include <util/log.h>
#include <util/macros.h>
#include <util/strings.h>
#include <critbit.h>
#include <lua.h>
#include <lauxlib.h>
#include <tolua.h>
#include <assert.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
static int tolua_region_count_msg_type(lua_State *L) {
region *self = (region *)tolua_tousertype(L, 1, 0);
const char *str = tolua_tostring(L, 2, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
const char *str = tolua_tostring(L, 2, NULL);
int n = 0;
if (self->msgs) {
mlist * ml = self->msgs->begin;
@ -74,21 +72,21 @@ int tolua_regionlist_next(lua_State * L)
static int tolua_region_get_id(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
lua_pushinteger(L, self->uid);
return 1;
}
static int tolua_region_get_blocked(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
lua_pushboolean(L, (self->flags&RF_BLOCKED) != 0);
return 1;
}
static int tolua_region_set_blocked(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
bool flag = !!tolua_toboolean(L, 2, 1);
if (flag) self->flags |= RF_BLOCKED;
else self->flags &= ~RF_BLOCKED;
@ -97,36 +95,36 @@ static int tolua_region_set_blocked(lua_State * L)
static int tolua_region_get_x(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
lua_pushinteger(L, self->x);
return 1;
}
static int tolua_region_get_y(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
lua_pushinteger(L, self->y);
return 1;
}
static int tolua_region_get_plane(lua_State * L)
{
region *r = (region *)tolua_tousertype(L, 1, 0);
region *r = (region *)tolua_tousertype(L, 1, NULL);
tolua_pushusertype(L, rplane(r), TOLUA_CAST "plane");
return 1;
}
static int tolua_region_get_terrain(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
tolua_pushstring(L, self->terrain->_name);
return 1;
}
static int tolua_region_set_terrain(lua_State * L)
{
region *r = (region *)tolua_tousertype(L, 1, 0);
const char *tname = tolua_tostring(L, 2, 0);
region *r = (region *)tolua_tousertype(L, 1, NULL);
const char *tname = tolua_tostring(L, 2, NULL);
if (tname) {
const terrain_type *terrain = get_terrain(tname);
if (terrain) {
@ -138,7 +136,7 @@ static int tolua_region_set_terrain(lua_State * L)
static int tolua_region_get_terrainname(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
attrib *a = a_find(self->attribs, &at_racename);
if (a) {
tolua_pushstring(L, get_racename(a));
@ -149,8 +147,8 @@ static int tolua_region_get_terrainname(lua_State * L)
static int tolua_region_set_owner(lua_State * L)
{
region *r = (region *)tolua_tousertype(L, 1, 0);
struct faction *f = (struct faction *)tolua_tousertype(L, 2, 0);
region *r = (region *)tolua_tousertype(L, 1, NULL);
struct faction *f = (struct faction *)tolua_tousertype(L, 2, NULL);
if (r) {
region_set_owner(r, f, turn);
}
@ -159,7 +157,7 @@ static int tolua_region_set_owner(lua_State * L)
static int tolua_region_get_owner(lua_State * L)
{
region *r = (region *)tolua_tousertype(L, 1, 0);
region *r = (region *)tolua_tousertype(L, 1, NULL);
if (r) {
struct faction *f = region_get_owner(r);
tolua_pushusertype(L, f, TOLUA_CAST "faction");
@ -170,8 +168,8 @@ static int tolua_region_get_owner(lua_State * L)
static int tolua_region_set_terrainname(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
const char *name = tolua_tostring(L, 2, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
const char *name = tolua_tostring(L, 2, NULL);
if (name == NULL) {
a_removeall(&self->attribs, &at_racename);
}
@ -183,42 +181,42 @@ static int tolua_region_set_terrainname(lua_State * L)
static int tolua_region_get_info(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
tolua_pushstring(L, region_getinfo(self));
return 1;
}
static int tolua_region_set_info(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
region_setinfo(self, tolua_tostring(L, 2, 0));
region *self = (region *)tolua_tousertype(L, 1, NULL);
region_setinfo(self, tolua_tostring(L, 2, NULL));
return 0;
}
static int tolua_region_get_name(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
tolua_pushstring(L, region_getname(self));
return 1;
}
static int tolua_region_set_name(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
region_setname(self, tolua_tostring(L, 2, 0));
region *self = (region *)tolua_tousertype(L, 1, NULL);
region_setname(self, tolua_tostring(L, 2, NULL));
return 0;
}
static int tolua_region_get_morale(lua_State * L)
{
region *r = (region *)tolua_tousertype(L, 1, 0);
region *r = (region *)tolua_tousertype(L, 1, NULL);
lua_pushinteger(L, region_get_morale(r));
return 1;
}
static int tolua_region_set_morale(lua_State * L)
{
region *r = (region *)tolua_tousertype(L, 1, 0);
region *r = (region *)tolua_tousertype(L, 1, NULL);
region_set_morale(r, (int)tolua_tonumber(L, 2, 0), turn);
return 0;
}
@ -226,14 +224,14 @@ static int tolua_region_set_morale(lua_State * L)
/* region mourning this turn */
static int tolua_region_get_is_mourning(lua_State * L)
{
region *r = (region *)tolua_tousertype(L, 1, 0);
region *r = (region *)tolua_tousertype(L, 1, NULL);
lua_pushboolean(L, is_mourning(r, turn+1));
return 1;
}
static int tolua_region_get_adj(lua_State * L)
{
region *r = (region *)tolua_tousertype(L, 1, 0);
region *r = (region *)tolua_tousertype(L, 1, NULL);
region *rn[MAXDIRECTIONS];
int d, idx;
get_neighbours(r, rn);
@ -250,7 +248,7 @@ static int tolua_region_get_adj(lua_State * L)
static int tolua_region_get_luxury(lua_State * L)
{
region *r = (region *)tolua_tousertype(L, 1, 0);
region *r = (region *)tolua_tousertype(L, 1, NULL);
if (r->land) {
const item_type *lux = r_luxury(r);
if (lux) {
@ -264,8 +262,8 @@ static int tolua_region_get_luxury(lua_State * L)
static int tolua_region_set_luxury(lua_State * L)
{
region *r = (region *)tolua_tousertype(L, 1, 0);
const char *name = tolua_tostring(L, 2, 0);
region *r = (region *)tolua_tousertype(L, 1, NULL);
const char *name = tolua_tostring(L, 2, NULL);
if (r->land && name) {
const item_type *lux = r_luxury(r);
const item_type *itype = it_find(name);
@ -279,9 +277,9 @@ static int tolua_region_set_luxury(lua_State * L)
static int tolua_region_set_herb(lua_State * L)
{
region *r = (region *)tolua_tousertype(L, 1, 0);
region *r = (region *)tolua_tousertype(L, 1, NULL);
if (r->land) {
const char *name = tolua_tostring(L, 2, 0);
const char *name = tolua_tostring(L, 2, NULL);
const item_type *itype = it_find(name);
if (itype && (itype->flags & ITF_HERB)) {
r->land->herbtype = itype;
@ -292,7 +290,7 @@ static int tolua_region_set_herb(lua_State * L)
static int tolua_region_get_herb(lua_State * L)
{
region *r = (region *)tolua_tousertype(L, 1, 0);
region *r = (region *)tolua_tousertype(L, 1, NULL);
if (r->land && r->land->herbtype) {
const char *name = r->land->herbtype->rtype->_name;
tolua_pushstring(L, name);
@ -303,7 +301,7 @@ static int tolua_region_get_herb(lua_State * L)
static int tolua_region_get_next(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
direction_t dir = (direction_t)tolua_tonumber(L, 2, 0);
if (dir >= 0 && dir < MAXDIRECTIONS) {
@ -315,7 +313,7 @@ static int tolua_region_get_next(lua_State * L)
static int tolua_region_get_flag(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
int bit = (int)tolua_tonumber(L, 2, 0);
lua_pushboolean(L, (self->flags & (1 << bit)));
@ -324,7 +322,7 @@ static int tolua_region_get_flag(lua_State * L)
static int tolua_region_set_flag(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
int bit = (int)tolua_tonumber(L, 2, 0);
int set = tolua_toboolean(L, 3, 1);
@ -337,8 +335,8 @@ static int tolua_region_set_flag(lua_State * L)
static int tolua_region_get_resourcelevel(lua_State * L)
{
region *r = (region *)tolua_tousertype(L, 1, 0);
const char *type = tolua_tostring(L, 2, 0);
region *r = (region *)tolua_tousertype(L, 1, NULL);
const char *type = tolua_tostring(L, 2, NULL);
const resource_type *rtype = rt_find(type);
if (rtype != NULL) {
const rawmaterial *rm;
@ -373,9 +371,9 @@ static int tolua_region_get_resource(lua_State * L)
const resource_type *rtype;
int result;
r = (region *)tolua_tousertype(L, 1, 0);
r = (region *)tolua_tousertype(L, 1, NULL);
LUA_ASSERT(r != NULL, "invalid parameter");
type = tolua_tostring(L, 2, 0);
type = tolua_tostring(L, 2, NULL);
LUA_ASSERT(type != NULL, "invalid parameter");
result = special_resource(type);
@ -404,8 +402,8 @@ static int tolua_region_get_resource(lua_State * L)
static int tolua_region_set_resource(lua_State * L)
{
region *r = (region *)tolua_tousertype(L, 1, 0);
const char *type = tolua_tostring(L, 2, 0);
region *r = (region *)tolua_tousertype(L, 1, NULL);
const char *type = tolua_tostring(L, 2, NULL);
int result, value = (int)tolua_tonumber(L, 3, 0);
const resource_type *rtype;
@ -430,7 +428,7 @@ static int tolua_region_set_resource(lua_State * L)
static int tolua_region_destroy(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
remove_region(&regions, self);
return 0;
}
@ -439,7 +437,7 @@ static int tolua_region_create(lua_State * L)
{
int x = (int)tolua_tonumber(L, 1, 0);
int y = (int)tolua_tonumber(L, 2, 0);
const char *tname = tolua_tostring(L, 3, 0);
const char *tname = tolua_tostring(L, 3, NULL);
if (tname) {
plane *pl = findplane(x, y);
const terrain_type *terrain = get_terrain(tname);
@ -449,7 +447,7 @@ static int tolua_region_create(lua_State * L)
return 0;
}
assert(!pnormalize(&x, &y, pl));
pnormalize(&x, &y, pl);
r = result = findregion(x, y);
if (r != NULL && r->units != NULL) {
@ -472,7 +470,7 @@ static int tolua_region_create(lua_State * L)
static int tolua_region_get_units(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
unit **unit_ptr = (unit **)lua_newuserdata(L, sizeof(unit *));
luaL_getmetatable(L, "unit");
@ -486,7 +484,7 @@ static int tolua_region_get_units(lua_State * L)
static int tolua_region_get_buildings(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
building **building_ptr =
(building **)lua_newuserdata(L, sizeof(building *));
@ -501,7 +499,7 @@ static int tolua_region_get_buildings(lua_State * L)
static int tolua_region_get_ships(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
ship **ship_ptr = (ship **)lua_newuserdata(L, sizeof(ship *));
luaL_getmetatable(L, "ship");
@ -515,7 +513,7 @@ static int tolua_region_get_ships(lua_State * L)
static int tolua_region_get_age(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
if (self) {
lua_pushinteger(L, self->age);
@ -526,7 +524,7 @@ static int tolua_region_get_age(lua_State * L)
static int tolua_region_get_peasants(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
if (self) {
lua_pushinteger(L, self->land ? self->land->peasants : 0);
@ -537,7 +535,7 @@ static int tolua_region_get_peasants(lua_State * L)
static int tolua_region_set_peasants(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
if (self && self->land) {
self->land->peasants = lua_tointeger(L, 2);
@ -547,37 +545,22 @@ static int tolua_region_set_peasants(lua_State * L)
static int tolua_region_getkey(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
const char *name = tolua_tostring(L, 2, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
const char *name = tolua_tostring(L, 2, NULL);
int flag = atoi36(name);
lua_pushboolean(L, key_get(self->attribs, flag));
return 1;
}
static int tolua_region_getastral(lua_State * L)
{
region *r = (region *)tolua_tousertype(L, 1, 0);
region *rt = r_standard_to_astral(r);
if (!rt) {
const char *tname = tolua_tostring(L, 2, 0);
plane *pl = get_astralplane();
rt = new_region(real2tp(r->x), real2tp(r->y), pl, 0);
if (tname) {
const terrain_type *terrain = get_terrain(tname);
terraform_region(rt, terrain);
}
int value = key_get(self->attribs, flag);
if (value != 0) {
lua_pushinteger(L, value);
return 1;
}
tolua_pushusertype(L, rt, TOLUA_CAST "region");
return 1;
return 0;
}
static int tolua_region_setkey(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
const char *name = tolua_tostring(L, 2, 0);
int value = (int)tolua_tonumber(L, 3, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
const char *name = tolua_tostring(L, 2, NULL);
int value = (int)tolua_tonumber(L, 3, 1);
int flag = atoi36(name);
if (value) {
@ -589,9 +572,27 @@ static int tolua_region_setkey(lua_State * L)
return 0;
}
static int tolua_region_getastral(lua_State * L)
{
region *r = (region *)tolua_tousertype(L, 1, NULL);
region *rt = r_standard_to_astral(r);
if (!rt) {
const char *tname = tolua_tostring(L, 2, NULL);
plane *pl = get_astralplane();
rt = new_region(real2tp(r->x), real2tp(r->y), pl, 0);
if (tname) {
const terrain_type *terrain = get_terrain(tname);
terraform_region(rt, terrain);
}
}
tolua_pushusertype(L, rt, TOLUA_CAST "region");
return 1;
}
static int tolua_region_tostring(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
lua_pushstring(L, regionname(self, NULL));
return 1;
}
@ -607,7 +608,7 @@ static int tolua_plane_get(lua_State * L)
static int tolua_plane_erase(lua_State *L)
{
plane *self = (plane *)tolua_tousertype(L, 1, 0);
plane *self = (plane *)tolua_tousertype(L, 1, NULL);
remove_plane(self);
return 0;
}
@ -619,7 +620,7 @@ static int tolua_plane_create(lua_State * L)
int y = (int)tolua_tonumber(L, 3, 0);
int width = (int)tolua_tonumber(L, 4, 0);
int height = (int)tolua_tonumber(L, 5, 0);
const char *name = tolua_tostring(L, 6, 0);
const char *name = tolua_tostring(L, 6, NULL);
plane *pl;
pl = create_new_plane(id, name, x, x + width - 1, y, y + height - 1, 0);
@ -630,15 +631,15 @@ static int tolua_plane_create(lua_State * L)
static int tolua_plane_get_name(lua_State * L)
{
plane *self = (plane *)tolua_tousertype(L, 1, 0);
plane *self = (plane *)tolua_tousertype(L, 1, NULL);
tolua_pushstring(L, self->name);
return 1;
}
static int tolua_plane_set_name(lua_State * L)
{
plane *self = (plane *)tolua_tousertype(L, 1, 0);
const char *str = tolua_tostring(L, 2, 0);
plane *self = (plane *)tolua_tousertype(L, 1, NULL);
const char *str = tolua_tostring(L, 2, NULL);
free(self->name);
if (str)
self->name = str_strdup(str);
@ -649,14 +650,14 @@ static int tolua_plane_set_name(lua_State * L)
static int tolua_plane_get_id(lua_State * L)
{
plane *self = (plane *)tolua_tousertype(L, 1, 0);
plane *self = (plane *)tolua_tousertype(L, 1, NULL);
lua_pushinteger(L, self->id);
return 1;
}
static int tolua_plane_normalize(lua_State * L)
{
plane *self = (plane *)tolua_tousertype(L, 1, 0);
plane *self = (plane *)tolua_tousertype(L, 1, NULL);
int x = (int)tolua_tonumber(L, 2, 0);
int y = (int)tolua_tonumber(L, 3, 0);
pnormalize(&x, &y, self);
@ -667,14 +668,14 @@ static int tolua_plane_normalize(lua_State * L)
static int tolua_plane_tostring(lua_State * L)
{
plane *self = (plane *)tolua_tousertype(L, 1, 0);
plane *self = (plane *)tolua_tousertype(L, 1, NULL);
lua_pushstring(L, self->name);
return 1;
}
static int tolua_plane_get_size(lua_State * L)
{
plane *pl = (plane *)tolua_tousertype(L, 1, 0);
plane *pl = (plane *)tolua_tousertype(L, 1, NULL);
lua_pushinteger(L, plane_width(pl));
lua_pushinteger(L, plane_height(pl));
return 2;
@ -699,8 +700,8 @@ static int tolua_distance(lua_State * L)
}
static int tolua_region_get_curse(lua_State *L) {
region *self = (region *)tolua_tousertype(L, 1, 0);
const char *name = tolua_tostring(L, 2, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
const char *name = tolua_tostring(L, 2, NULL);
if (self->attribs) {
curse * c = get_curse(self->attribs, ct_find(name));
if (c) {
@ -712,8 +713,8 @@ static int tolua_region_get_curse(lua_State *L) {
}
static int tolua_region_has_attrib(lua_State *L) {
region *self = (region *)tolua_tousertype(L, 1, 0);
const char *name = tolua_tostring(L, 2, 0);
region *self = (region *)tolua_tousertype(L, 1, NULL);
const char *name = tolua_tostring(L, 2, NULL);
attrib * a = a_find(self->attribs, at_find(name));
lua_pushboolean(L, a != NULL);
return 1;

View file

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

View file

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

View file

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

View file

@ -5,15 +5,22 @@
#include "bind_unit.h"
#include "alchemy.h"
#include "bindings.h"
#include "move.h"
#include "reports.h"
#include "guard.h"
#include "magic.h"
#include "skill.h"
/* attributes includes */
#include <attributes/racename.h>
#include <attributes/key.h>
/* util includes */
#include <kernel/attrib.h>
#include <util/base36.h>
#include <kernel/event.h>
#include <util/log.h>
#include <util/macros.h>
#include "util/variant.h"
/* kernel includes */
#include "kernel/skills.h"
#include "kernel/types.h"
#include <kernel/building.h>
#include <kernel/config.h>
#include <kernel/curse.h>
@ -31,21 +38,20 @@
#include <kernel/spell.h>
#include <kernel/unit.h>
/* util includes */
#include <util/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <util/lists.h>
#include <util/log.h>
#include <util/macros.h>
/* attributes includes */
#include <attributes/racename.h>
#include <attributes/key.h>
#include <selist.h>
#include <lauxlib.h>
#include <lua.h>
#include <tolua.h>
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <limits.h>
@ -56,7 +62,7 @@ static int tolua_bufunit(lua_State * L) {
if (f) {
char buf[8192];
int mode = (int)tolua_tonumber(L, 3, (int)seen_unit);
bufunit(f, u, mode, buf, sizeof(buf));
bufunit_depr(f, u, mode, buf, sizeof(buf));
tolua_pushstring(L, buf);
return 1;
}
@ -193,7 +199,7 @@ static int tolua_unit_set_id(lua_State * L)
static int tolua_unit_get_auramax(lua_State * L)
{
unit *self = (unit *)tolua_tousertype(L, 1, 0);
lua_pushinteger(L, max_spellpoints(self->region, self));
lua_pushinteger(L, max_spellpoints_depr(self->region, self));
return 1;
}
@ -270,8 +276,12 @@ static int tolua_unit_set_guard(lua_State * L)
static const char *unit_getmagic(const unit * u)
{
sc_mage *mage = get_mage_depr(u);
return mage ? magic_school[mage->magietyp] : NULL;
struct sc_mage *mage = get_mage(u);
if (mage) {
magic_t mtype = mage_get_type(mage);
return magic_school[mtype];
}
return NULL;
}
static int tolua_unit_get_magic(lua_State * L)
@ -283,16 +293,15 @@ static int tolua_unit_get_magic(lua_State * L)
static void unit_setmagic(unit * u, const char *type)
{
sc_mage *mage = get_mage(u);
int mtype;
for (mtype = 0; mtype != MAXMAGIETYP; ++mtype) {
if (strcmp(magic_school[mtype], type) == 0)
break;
}
if (mtype == MAXMAGIETYP)
return;
struct sc_mage *mage = get_mage(u);
if (mage == NULL) {
mage = create_mage(u, (magic_t)mtype);
int mtype;
for (mtype = 0; mtype != MAXMAGIETYP; ++mtype) {
if (strcmp(magic_school[mtype], type) == 0) {
create_mage(u, (magic_t)mtype);
return;
}
}
}
}
@ -515,7 +524,7 @@ static int tolua_unit_addspell(lua_State * L)
return EINVAL;
}
else {
unit_add_spell(u, 0, sp, level);
unit_add_spell(u, sp, level);
}
lua_pushinteger(L, err);
@ -742,8 +751,8 @@ static int tolua_unit_get_items(lua_State * L)
static int tolua_unit_get_spells(lua_State * L)
{
unit *self = (unit *) tolua_tousertype(L, 1, 0);
sc_mage *mage = self ? get_mage_depr(self) : 0;
spellbook *sb = mage ? mage->spellbook : 0;
struct sc_mage *mage = self ? get_mage(self) : NULL;
spellbook *sb = mage_get_spellbook(mage);
selist *slist = 0;
if (sb) {
selist **slist_ptr = &sb->spells;

View file

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

View file

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

92
src/checker.c Normal file
View file

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

View file

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

136
src/contact.c Normal file
View file

@ -0,0 +1,136 @@
#ifdef _MSC_VER
#include <platform.h>
#endif
#include "contact.h"
#include "kernel/attrib.h"
#include "kernel/faction.h"
#include "kernel/messages.h"
#include "kernel/order.h"
#include "kernel/unit.h"
#include "util/base36.h"
#include "util/param.h"
#include "util/parser.h"
#include <assert.h>
static attrib_type at_contact_unit = {
"contact_unit",
DEFAULT_INIT,
DEFAULT_FINALIZE,
DEFAULT_AGE,
NO_WRITE,
NO_READ
};
void contact_unit(unit * u, const unit * u2)
{
attrib *a = a_find(u->attribs, &at_contact_unit);
while (a && a->type == &at_contact_unit) {
if (a->data.v == u2) {
return;
}
a = a->next;
}
a_add(&u->attribs, a_new(&at_contact_unit))->data.v = (void *)u2;
}
static attrib_type at_contact_faction = {
"contact_faction",
DEFAULT_INIT,
DEFAULT_FINALIZE,
DEFAULT_AGE,
NO_WRITE,
NO_READ
};
void contact_faction(unit * u, const faction * f)
{
attrib *a = a_find(u->attribs, &at_contact_faction);
while (a && a->type == &at_contact_faction) {
if (a->data.v == f) {
return;
}
a = a->next;
}
a_add(&u->attribs, a_new(&at_contact_faction))->data.v = (void *)f;
}
bool ucontact(const unit * u, const unit * u2)
/* Prueft, ob u den Kontaktiere-Befehl zu u2 gesetzt hat. */
{
attrib *a;
if (u->faction == u2->faction) {
return true;
}
/* Explizites KONTAKTIERE */
for (a = u->attribs; a; a = a->next) {
if (a->type == &at_contact_unit) {
if (u2 == a->data.v) {
return true;
}
}
else if (a->type == &at_contact_faction) {
if (u2->faction == a->data.v) {
return true;
}
}
}
return false;
}
int contact_cmd(unit * u, order * ord)
{
char token[16];
const char *str;
param_t p;
init_order(ord, u->faction->locale);
str = gettoken(token, sizeof(token));
p = findparam(str, u->faction->locale);
if (p == P_FACTION) {
/* new-style syntax, KONTAKTIERE PARTEI foo */
faction * f = getfaction();
if (!f) {
cmistake(u, ord, 66, MSG_EVENT);
}
else {
contact_faction(u, f);
return 0;
}
}
else if (p == P_UNIT) {
/* new-style syntax, KONTAKTIERE EINHEIT [TEMP] foo */
unit *u2 = NULL;
if (GET_UNIT == getunit(u->region, u->faction, &u2)) {
assert(u2);
contact_unit(u, u2);
return 0;
}
ADDMSG(&u->faction->msgs, msg_feedback(u, ord,
"feedback_unit_not_found", NULL));
}
else {
/* old-style syntax, KONTAKTIERE foo */
unit *u2;
int n = 0;
if (p == P_TEMP) {
n = getid();
u2 = findnewunit(u->region, u->faction, n);
}
else {
n = atoi36((const char *)str);
u2 = findunit(n);
}
if (u2 != NULL) {
contact_unit(u, u2);
return 0;
}
ADDMSG(&u->faction->msgs, msg_feedback(u, ord,
"feedback_unit_not_found", NULL));
}
return -1;
}

12
src/contact.h Normal file
View file

@ -0,0 +1,12 @@
#pragma once
#include <stdbool.h>
struct faction;
struct order;
struct unit;
bool ucontact(const struct unit *u, const struct unit *u2);
void contact_unit(struct unit *u, const struct unit *c);
void contact_faction(struct unit * u, const struct faction * f);
int contact_cmd(struct unit * u, struct order * ord);

84
src/contact.test.c Normal file
View file

@ -0,0 +1,84 @@
#include "contact.h"
#include "kernel/faction.h"
#include "kernel/order.h"
#include "kernel/unit.h"
#include "util/language.h"
#include "util/param.h"
#include "tests.h"
#include <CuTest.h>
struct region;
static void test_contact(CuTest *tc) {
struct unit *u1, *u2, *u3;
struct region *r;
struct faction *f;
test_setup();
r = test_create_plain(0, 0);
f = test_create_faction(NULL);
u1 = test_create_unit(f, r);
u2 = test_create_unit(f, r);
u3 = test_create_unit(test_create_faction(NULL), r);
CuAssertTrue(tc, ucontact(u1, u1));
CuAssertTrue(tc, ucontact(u1, u2));
CuAssertTrue(tc, !ucontact(u1, u3));
contact_unit(u1, u3);
CuAssertTrue(tc, ucontact(u1, u3));
CuAssertTrue(tc, !ucontact(u2, u3));
test_teardown();
}
static void test_contact_cmd(CuTest *tc) {
struct unit *u, *u2;
struct region *r;
const struct locale *lang;
struct order *ord;
test_setup();
r = test_create_plain(0, 0);
u = test_create_unit(test_create_faction(NULL), r);
lang = u->faction->locale;
u2 = test_create_unit(test_create_faction(NULL), r);
ord = create_order(K_CONTACT, u->faction->locale, "%s %i",
LOC(lang, parameters[P_UNIT]), u2->no);
contact_cmd(u, ord);
CuAssertTrue(tc, ucontact(u, u2));
free_order(ord);
u2 = test_create_unit(test_create_faction(NULL), r);
ord = create_order(K_CONTACT, u->faction->locale, "%s %i",
LOC(lang, parameters[P_FACTION]), u2->faction->no);
contact_cmd(u, ord);
CuAssertTrue(tc, ucontact(u, u2));
free_order(ord);
u2 = test_create_unit(test_create_faction(NULL), r);
ord = create_order(K_CONTACT, u->faction->locale, "%i", u2->no);
contact_cmd(u, ord);
CuAssertTrue(tc, ucontact(u, u2));
free_order(ord);
u2 = test_create_unit(test_create_faction(NULL), r);
usetalias(u2, 42);
ord = create_order(K_CONTACT, u->faction->locale, "%s %i",
LOC(lang, parameters[P_TEMP]), ualias(u2));
contact_cmd(u, ord);
CuAssertTrue(tc, ucontact(u, u2));
free_order(ord);
test_teardown();
}
CuSuite *get_contact_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_contact);
SUITE_ADD_TEST(suite, test_contact_cmd);
return suite;
}

View file

@ -64,7 +64,7 @@ without prior permission by the authors of Eressea.
#include "kernel/unit.h"
/* util includes */
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/base36.h>
#include <util/crmessage.h>
#include <util/strings.h>
@ -673,9 +673,7 @@ static void cr_output_building(struct stream *out, building *b,
if (fno >= 0) {
stream_printf(out, "%d;Partei\n", fno);
}
if (b->besieged) {
stream_printf(out, "%d;Belagerer\n", b->besieged);
}
cr_output_curses(out, f, b, TYP_BUILDING);
}
@ -780,7 +778,6 @@ void cr_output_unit(stream *out, const faction * f,
const item_type *lasttype;
int pr;
item *itm, *show = NULL;
building *b;
const char *pzTmp;
skill *sv;
item result[MAX_INVENTORY];
@ -802,13 +799,11 @@ void cr_output_unit(stream *out, const faction * f,
}
if (u->faction == f) {
const attrib *a = NULL;
unit *mage;
group * g;
if (fval(u, UFL_GROUP))
a = a_find(u->attribs, &at_group);
if (a != NULL) {
const group *g = (const group *)a->data.v;
g = get_group(u);
if (g) {
stream_printf(out, "%d;gruppe\n", g->gid);
}
mage = get_familiar_mage(u);
@ -879,16 +874,13 @@ void cr_output_unit(stream *out, const faction * f,
if (is_guard(u)) {
stream_printf(out, "%d;bewacht\n", 1);
}
if ((b = usiege(u)) != NULL) {
stream_printf(out, "%d;belagert\n", b->no);
}
/* additional information for own units */
if (u->faction == f || omniscient(f)) {
order *ord;
const char *xc;
const char *c;
int i;
sc_mage *mage;
struct sc_mage *mage;
i = ualias(u);
if (i > 0)
@ -925,7 +917,7 @@ void cr_output_unit(stream *out, const faction * f,
}
if (is_mage(u)) {
stream_printf(out, "%d;Aura\n", get_spellpoints(u));
stream_printf(out, "%d;Auramax\n", max_spellpoints(u->region, u));
stream_printf(out, "%d;Auramax\n", max_spellpoints_depr(u->region, u));
}
/* default commands */
stream_printf(out, "COMMANDS\n");
@ -965,19 +957,23 @@ void cr_output_unit(stream *out, const faction * f,
}
/* spells that this unit can cast */
mage = get_mage_depr(u);
mage = get_mage(u);
if (mage) {
int maxlevel = effskill(u, SK_MAGIC, 0);
cr_output_spells(out, u, maxlevel);
for (i = 0; i != MAXCOMBATSPELLS; ++i) {
const spell *sp = mage->combatspells[i].sp;
int level;
const spell *sp = mage_get_combatspell(mage, i, &level);
if (sp) {
const char *name =
translate(mkname("spell", sp->sname), spell_name(sp, lang));
const char *name;
if (level > maxlevel) {
level = maxlevel;
}
stream_printf(out, "KAMPFZAUBER %d\n", i);
name = translate(mkname("spell", sp->sname), spell_name(sp, lang));
stream_printf(out, "\"%s\";name\n", name);
stream_printf(out, "%d;level\n", mage->combatspells[i].level);
stream_printf(out, "%d;level\n", level);
}
}
}
@ -1024,20 +1020,38 @@ static void cr_output_unit_compat(FILE * F, const faction * f,
cr_output_unit(&strm, f, u, mode);
}
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
static void print_ally(const faction *f, faction *af, int status, FILE *F) {
if (af && status > 0) {
fprintf(F, "ALLIANZ %d\n", af->no);
fprintf(F, "\"%s\";Parteiname\n", af->name);
fprintf(F, "%d;Status\n", status & HELP_ALL);
}
}
struct print_ally_s {
const faction *f;
FILE *F;
};
static int print_ally_cb(struct allies *al, faction *af, int status, void *udata) {
struct print_ally_s *data = (struct print_ally_s *)udata;
UNUSED_ARG(al);
if (af && faction_alive(af)) {
int mode = alliance_status(data->f, af, status);
print_ally(data->f, af, mode, data->F);
}
return 0;
}
/* prints allies */
static void show_allies_cr(FILE * F, const faction * f, const ally * sf)
static void show_allies_cr(FILE * F, const faction * f, const group *g)
{
for (; sf; sf = sf->next)
if (sf->faction) {
int mode = alliedgroup(NULL, f, sf->faction, sf, HELP_ALL);
if (mode != 0 && sf->status > 0) {
fprintf(F, "ALLIANZ %d\n", sf->faction->no);
fprintf(F, "\"%s\";Parteiname\n", sf->faction->name);
fprintf(F, "%d;Status\n", sf->status & HELP_ALL);
}
}
struct print_ally_s data;
data.F = F;
data.f = f;
struct allies *sf = g ? g->allies : f->allies;
allies_walk(sf, print_ally_cb, &data);
}
/* prints allies */
@ -1063,12 +1077,15 @@ static void cr_find_address(FILE * F, const faction * uf, selist * addresses)
while (flist) {
const faction *f = (const faction *)selist_get(flist, i);
if (uf != f) {
const char *str;
fprintf(F, "PARTEI %d\n", f->no);
fprintf(F, "\"%s\";Parteiname\n", f->name);
if (strcmp(faction_getemail(f), "") != 0)
fprintf(F, "\"%s\";email\n", faction_getemail(f));
if (f->banner)
fprintf(F, "\"%s\";banner\n", f->banner);
str = faction_getbanner(f);
if (str) {
fprintf(F, "\"%s\";banner\n", str);
}
fprintf(F, "\"%s\";locale\n", locale_name(f->locale));
if (f->alliance && f->alliance == uf->alliance) {
fprintf(F, "%d;alliance\n", f->alliance->id);
@ -1540,7 +1557,7 @@ report_computer(const char *filename, report_context * ctx, const char *bom)
static int era = -1;
int i;
faction *f = ctx->f;
const char *prefix;
const char *prefix, *str;
region *r;
const char *mailto = config_get("game.email");
const attrib *a;
@ -1634,8 +1651,10 @@ report_computer(const char *filename, report_context * ctx, const char *bom)
fprintf(F, "\"%s\";Parteiname\n", f->name);
fprintf(F, "\"%s\";email\n", faction_getemail(f));
if (f->banner)
fprintf(F, "\"%s\";banner\n", f->banner);
str = faction_getbanner(f);
if (str) {
fprintf(F, "\"%s\";banner\n", str);
}
print_items(F, f->items, f->locale);
fputs("OPTIONEN\n", F);
for (i = 0; i != MAXOPTIONS; ++i) {
@ -1647,7 +1666,7 @@ report_computer(const char *filename, report_context * ctx, const char *bom)
f->options &= (~flag);
}
}
show_allies_cr(F, f, f->allies);
show_allies_cr(F, f, NULL);
{
group *g;
for (g = f->groups; g; g = g->next) {
@ -1660,7 +1679,7 @@ report_computer(const char *filename, report_context * ctx, const char *bom)
fprintf(F, "\"%s\";typprefix\n",
translate(prefix, LOC(f->locale, prefix)));
}
show_allies_cr(F, f, g->allies);
show_allies_cr(F, f, g);
}
}

View file

@ -3,7 +3,6 @@
#include "move.h"
#include "spy.h"
#include "travelthru.h"
#include "keyword.h"
#include <kernel/ally.h>
#include <kernel/building.h>
@ -17,6 +16,7 @@
#include <kernel/spell.h>
#include <kernel/spellbook.h>
#include "util/keyword.h"
#include <util/language.h>
#include <util/lists.h>
#include <util/message.h>
@ -227,7 +227,6 @@ static void test_cr_factionstealth(CuTest *tc) {
faction *f1, *f2;
region *r;
unit *u;
ally *al;
test_setup();
f1 = test_create_faction(NULL);
@ -298,8 +297,7 @@ static void test_cr_factionstealth(CuTest *tc) {
mstream_done(&strm);
/* we see the same thing as them when we are an ally */
al = ally_add(&f1->allies, f2);
al->status = HELP_FSTEALTH;
ally_set(&f1->allies, f2, HELP_FSTEALTH);
mstream_init(&strm);
cr_output_unit(&strm, f2, u, seen_unit);
CuAssertIntEquals(tc, f1->no, cr_get_int(&strm, ";Partei", -1));

View file

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

View file

@ -19,7 +19,7 @@
#include <kernel/terrainid.h>
#include <kernel/unit.h>
#include <util/attrib.h>
#include <kernel/attrib.h>
#include <util/language.h>
#include <util/macros.h>
@ -358,7 +358,7 @@ static void test_tax_cmd(CuTest *tc) {
set_level(u, SK_TAXING, 1);
tax_cmd(u, ord, &taxorders);
CuAssertPtrEquals(tc, 0, test_find_messagetype(u->faction->msgs, "error_no_tax_skill"));
CuAssertPtrEquals(tc, NULL, test_find_messagetype(u->faction->msgs, "error_no_tax_skill"));
CuAssertPtrNotNull(tc, taxorders);
rsetmoney(r, 11);
@ -416,8 +416,8 @@ static void test_maintain_buildings(CuTest *tc) {
b->flags = 0;
maintain_buildings(r);
CuAssertIntEquals(tc, BLD_MAINTAINED, fval(b, BLD_MAINTAINED));
CuAssertPtrEquals(tc, 0, f->msgs);
CuAssertPtrEquals(tc, 0, r->msgs);
CuAssertPtrEquals(tc, NULL, f->msgs);
CuAssertPtrEquals(tc, NULL, r->msgs);
req = calloc(2, sizeof(maintenance));
req[0].number = 100;
@ -439,8 +439,8 @@ static void test_maintain_buildings(CuTest *tc) {
maintain_buildings(r);
CuAssertIntEquals(tc, BLD_MAINTAINED, fval(b, BLD_MAINTAINED));
CuAssertIntEquals(tc, 0, i_get(u->items, itype));
CuAssertPtrEquals(tc, 0, r->msgs);
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "maintenance_nowork"));
CuAssertPtrEquals(tc, NULL, r->msgs);
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "maintenance_nowork"));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "maintenance"));
test_clear_messagelist(&f->msgs);
@ -449,7 +449,7 @@ static void test_maintain_buildings(CuTest *tc) {
b->flags = 0;
maintain_buildings(r);
CuAssertIntEquals(tc, 0, fval(b, BLD_MAINTAINED));
CuAssertPtrEquals(tc, 0, f->msgs);
CuAssertPtrEquals(tc, NULL, f->msgs);
CuAssertPtrNotNull(tc, test_find_messagetype(r->msgs, "maintenance_noowner"));
test_clear_messagelist(&r->msgs);
@ -488,6 +488,7 @@ static void test_recruit_insect(CuTest *tc) {
test_setup();
test_create_calendar();
test_create_terrain("desert", -1);
f = test_create_faction(test_create_race("insect"));
u = test_create_unit(f, test_create_region(0, 0, NULL));
u->thisorder = create_order(K_RECRUIT, f->locale, "%d", 1);

View file

@ -1,14 +1,14 @@
#include <platform.h>
#include "eressea.h"
#include "kernel/building.h"
#include "kernel/calendar.h"
#include "kernel/database.h"
#include "kernel/config.h"
#include "kernel/curse.h"
#include "kernel/faction.h"
#include "kernel/building.h"
#include "kernel/equipment.h"
#include "kernel/faction.h"
#include "kernel/item.h"
#include "kernel/database.h"
#include "util/functions.h"
#include "util/language.h"
@ -54,12 +54,12 @@ void game_done(void)
free_locales();
#endif
kernel_done();
dblib_close();
swapdb_close();
}
void game_init(void)
{
dblib_open();
swapdb_open();
errno = 0;
kernel_init();
register_triggers();

33
src/gamedb.c Normal file
View file

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

3
src/gamedb.h Normal file
View file

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

View file

@ -16,6 +16,7 @@
#include <kernel/config.h>
#include "give.h"
#include "contact.h"
#include "economy.h"
#include "laws.h"
@ -25,6 +26,8 @@
#include <attributes/racename.h>
/* kernel includes */
#include <kernel/attrib.h>
#include <kernel/event.h>
#include <kernel/ally.h>
#include <kernel/build.h>
#include <kernel/curse.h>
@ -41,11 +44,10 @@
#include <kernel/unit.h>
/* util includes */
#include <util/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <util/log.h>
#include <util/macros.h>
#include <util/param.h>
#include <util/parser.h>
/* libc includes */
@ -585,14 +587,12 @@ void give_unit(unit * u, unit * u2, order * ord)
}
}
if (has_skill(u, SK_MAGIC)) {
sc_mage *mage;
if (count_skill(u2->faction, SK_MAGIC) + u->number >
skill_limit(u2->faction, SK_MAGIC)) {
cmistake(u, ord, 155, MSG_COMMERCE);
return;
}
mage = get_mage_depr(u);
if (!mage || u2->faction->magiegebiet != mage->magietyp) {
if (u2->faction->magiegebiet != unit_get_magic(u)) {
cmistake(u, ord, 157, MSG_COMMERCE);
return;
}

View file

@ -1,6 +1,8 @@
#include <platform.h>
#include "give.h"
#include "contact.h"
#include "economy.h"
#include <kernel/ally.h>
@ -16,6 +18,7 @@
#include <util/base36.h>
#include <util/language.h>
#include <util/message.h>
#include <util/param.h>
#include <CuTest.h>
#include <tests.h>
@ -43,8 +46,7 @@ static void setup_give(struct give *env) {
env->itype = it_get_or_create(rt_get_or_create("money"));
env->itype->flags |= ITF_HERB;
if (env->f2) {
ally * al = ally_add(&env->f2->allies, env->f1);
al->status = HELP_GIVE;
ally_set(&env->f2->allies, env->f1, HELP_GIVE);
env->dst = test_create_unit(env->f2, env->r);
}
else {
@ -193,7 +195,7 @@ static void test_give_men_limit(CuTest * tc) {
config_set("rules.give.max_men", "1");
/* below the limit, give men, increase newbies counter */
usetcontact(env.dst, env.src);
contact_unit(env.dst, env.src);
msg = give_men(1, env.src, env.dst, NULL);
CuAssertStrEquals(tc, "give_person", test_get_messagetype(msg));
CuAssertIntEquals(tc, 2, env.dst->number);
@ -202,7 +204,7 @@ static void test_give_men_limit(CuTest * tc) {
msg_release(msg);
/* beyond the limit, do nothing */
usetcontact(env.src, env.dst);
contact_unit(env.src, env.dst);
msg = give_men(2, env.dst, env.src, NULL);
CuAssertStrEquals(tc, "error129", test_get_messagetype(msg));
CuAssertIntEquals(tc, 2, env.dst->number);
@ -281,7 +283,7 @@ static void test_give_men_other_faction(CuTest * tc) {
env.f1 = test_create_faction(NULL);
env.f2 = test_create_faction(NULL);
setup_give(&env);
usetcontact(env.dst, env.src);
contact_unit(env.dst, env.src);
msg = give_men(1, env.src, env.dst, NULL);
CuAssertStrEquals(tc, "give_person", test_get_messagetype(msg));
CuAssertIntEquals(tc, 2, env.dst->number);

View file

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

View file

@ -20,6 +20,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <platform.h>
#include <kernel/config.h>
#include "guard.h"
#include "contact.h"
#include "laws.h"
#include "monsters.h"
@ -105,8 +107,6 @@ static bool is_guardian_r(const unit * guard)
{
if (guard->number == 0)
return false;
if (besieged(guard))
return false;
/* if region_owners exist then they may be guardians: */
if (guard->building && rule_region_owners() && guard == building_owner(guard->building)) {

View file

@ -29,7 +29,7 @@ static void test_is_guarded(CuTest *tc) {
r = test_create_region(0, 0, NULL);
u1 = test_create_unit(test_create_faction(NULL), r);
u2 = test_create_unit(test_create_faction(rc), r);
CuAssertPtrEquals(tc, 0, is_guarded(r, u1));
CuAssertPtrEquals(tc, NULL, is_guarded(r, u1));
setguard(u2, true);
CuAssertPtrEquals(tc, u2, is_guarded(r, u1));
test_teardown();

View file

@ -17,26 +17,21 @@ without prior permission by the authors of Eressea.
#include "helpers.h"
#include "vortex.h"
#include "alchemy.h"
#include "magic.h"
#include <util/attrib.h>
#include <util/base36.h>
#include <util/event.h>
#include <kernel/attrib.h>
#include <kernel/event.h>
#include <util/functions.h>
#include <util/gamedata.h>
#include <kernel/gamedata.h>
#include <util/log.h>
#include <util/macros.h>
#include <util/parser.h>
#include <util/resolve.h>
#include <util/variant.h>
#include <kernel/callbacks.h>
#include <kernel/config.h>
#include <kernel/callbacks.h>
#include <kernel/faction.h>
#include <kernel/spell.h>
#include <kernel/race.h>
#include <kernel/resources.h>
#include <kernel/unit.h>
#include <kernel/building.h>
#include <kernel/item.h>
#include <kernel/region.h>
@ -46,8 +41,10 @@ without prior permission by the authors of Eressea.
#include <lua.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
struct order;
static int
lua_giveitem(unit * s, unit * d, const item_type * itype, int n, struct order *ord)
@ -181,7 +178,7 @@ static bool lua_equipunit(unit *u, const char *eqname, int mask) {
lua_pop(L, 1);
}
else {
result = (bool)lua_toboolean(L, -1);
result = lua_toboolean(L, -1) != 0;
lua_pop(L, 1);
}
}

View file

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

View file

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

View file

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

View file

@ -74,7 +74,7 @@ use_manacrystal(struct unit *u, const struct item_type *itype, int amount,
return -1;
}
msp = max_spellpoints(u->region, u) / 2;
msp = max_spellpoints_depr(u->region, u) / 2;
for (i = 0; i != amount; ++i) {
sp += MAX(25, msp);
change_spellpoints(u, sp);

View file

@ -25,7 +25,7 @@ static void test_manacrystal(CuTest *tc) {
CuAssertIntEquals(tc, -1, use_manacrystal(u, itype, 1, NULL));
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error295"));
test_clear_messages(u->faction);
create_mage(u, M_GRAY);
create_mage(u, M_GWYRRD);
set_level(u, SK_MAGIC, 5);
CuAssertIntEquals(tc, 0, get_spellpoints(u));
CuAssertIntEquals(tc, 1, use_manacrystal(u, itype, 1, NULL));

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