forked from github/server
Merge branch 'master' of github.com:eressea/server
This commit is contained in:
commit
baffbbf154
135 changed files with 16117 additions and 15448 deletions
CMakeLists.txt
conf
game-e2
game-e3
iniparserres
s
src
CMakeLists.txtalchemy.calchemy.hbattle.cbattle.hbattle.test.cbind_faction.cbind_message.cbind_monsters.cbind_process.cbind_region.cbind_ship.cbind_unit.cbindings.cbuild.hcreation.ccreport.cdirection.test.ceconomy.ceressea.cgive.cgmtool.chelpers.citems.c
items
kernel
CMakeLists.txtalliance.cbattle.cbuild.cbuild.hbuild.test.ccommand.cconfig.cconfig.hfaction.cfaction.hfaction.test.citem.citem.hitem.test.cjsonconf.test.cmagic.cmove.hnames.corder.corder.horder.test.cplayer.cplayer.hpool.crace.crace.hrace.test.cregion.cregion.hreports.hsave.cskills.cunit.cunit.hunit.test.cxmlreader.c
keyword.claws.claws.test.cmain.cmodules
monster.cmonsters.cmove.cmove.hmove.test.cnames.cnames.hraces
randenc.creport.creports.c
|
@ -54,16 +54,6 @@ CONFIGURE_FILE (
|
|||
INCLUDE_DIRECTORIES (${CMAKE_BINARY_DIR}/include)
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_AUTOCONF")
|
||||
|
||||
IF(CMAKE_COMPILER_IS_GNUCC)
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -DHAVE__BOOL")
|
||||
elseif(MSVC)
|
||||
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
|
||||
"${CMAKE_EXE_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libc.lib /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcd.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrtd.lib")
|
||||
ELSE(CMAKE_COMPILER_IS_GNUCC)
|
||||
MESSAGE(STATUS "Unknown compiler ${CMAKE_C_COMPILER_ID}")
|
||||
ENDIF(CMAKE_COMPILER_IS_GNUCC)
|
||||
|
||||
find_package (LibXml2)
|
||||
find_package (SQLite3)
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
<xi:include href="config:///game/familiars.xml"/>
|
||||
<xi:include href="config:///core/terrains.xml"/>
|
||||
<xi:include href="config:///game/terrains.xml"/>
|
||||
<xi:include href="config:///default/directions.xml"/>
|
||||
<xi:include href="config:///game/artrewards.xml"/>
|
||||
<xi:include href="config:///game/buildings.xml"/>
|
||||
<xi:include href="config:///core/calendar.xml"/>
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
<xi:include href="config:///core/common/buildings.xml"/>
|
||||
<xi:include href="config:///game/familiars.xml"/>
|
||||
|
||||
<xi:include href="config:///default/directions.xml"/>
|
||||
<xi:include href="config:///default/adamantium.xml" />
|
||||
|
||||
<xi:include href="config:///game/ships.xml"/>
|
||||
|
@ -118,6 +117,7 @@
|
|||
<param name="study.speedup" value="0"/>
|
||||
<param name="world.era" value="3"/>
|
||||
<param name="rules.migrants" value="0"/>
|
||||
<param name="rules.monsters.attack_chance" value="0.0"/>
|
||||
<param name="rules.transfermen" value="0"/>
|
||||
<param name="rules.stealth.faction" value="1"/>
|
||||
<param name="rules.stealth.anon_battle" value="0"/>
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
<xi:include href="config:///core/common/buildings.xml"/>
|
||||
<xi:include href="config:///game/familiars.xml"/>
|
||||
|
||||
<xi:include href="config:///default/directions.xml"/>
|
||||
<xi:include href="config:///default/adamantium.xml" />
|
||||
|
||||
<xi:include href="config:///game/ships.xml"/>
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
<xi:include href="config:///game/familiars.xml"/>
|
||||
<xi:include href="config:///core/terrains.xml"/>
|
||||
<xi:include href="config:///game/terrains.xml"/>
|
||||
<xi:include href="config:///default/directions.xml"/>
|
||||
<xi:include href="config:///game/artrewards.xml"/>
|
||||
<xi:include href="config:///game/buildings.xml"/>
|
||||
<xi:include href="config:///core/calendar.xml"/>
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?xml version="1.0"?>
|
||||
<eressea xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
<xi:include href="config:///default/directions.xml"/>
|
||||
|
||||
<xi:include href="config:///core/messages.xml"/>
|
||||
|
||||
<xi:include href="config:///core/de/strings.xml"/>
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit a636c47ebdaf602de6a5db81b5cb1b0309dfdae0
|
||||
Subproject commit f84066fb7d3254bdd9e89694acc4c1c20d001eed
|
|
@ -1,10 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<resources>
|
||||
|
||||
<resource name="money">
|
||||
<item weight="1"/>
|
||||
</resource>
|
||||
|
||||
<resource name="ao_healing" appearance="amulet">
|
||||
<item weight="0" score="6000"/>
|
||||
</resource>
|
||||
|
|
|
@ -1989,8 +1989,8 @@
|
|||
<string name="STUFE">
|
||||
<text locale="de">STUFE</text>
|
||||
</string>
|
||||
<string name="TEMPORAERE">
|
||||
<text locale="de">TEMPORÄRE</text>
|
||||
<string name="TEMP">
|
||||
<text locale="de">TEMP</text>
|
||||
</string>
|
||||
<string name="TRAENKE">
|
||||
<text locale="de">TRÄNKE</text>
|
||||
|
@ -2198,7 +2198,7 @@
|
|||
<text locale="de">MACHEN</text>
|
||||
</string>
|
||||
<string name="maketemp">
|
||||
<text locale="de">MACHE TEMP</text>
|
||||
<text locale="de">MACHETEMP</text>
|
||||
</string>
|
||||
<string name="move">
|
||||
<text locale="de">NACH</text>
|
||||
|
|
|
@ -176,6 +176,9 @@
|
|||
<string name="wall1">
|
||||
<text locale="en">Wall</text>
|
||||
</string>
|
||||
<string name="wall1_trail">
|
||||
<text locale="de">a solid wall</text>
|
||||
</string>
|
||||
<string name="hall1_trail">
|
||||
<text locale="en">the %s</text>
|
||||
</string>
|
||||
|
@ -1274,7 +1277,7 @@
|
|||
<string name="STUFE">
|
||||
<text locale="en">LEVEL</text>
|
||||
</string>
|
||||
<string name="TEMPORAERE">
|
||||
<string name="TEMP">
|
||||
<text locale="en">TEMPORARY</text>
|
||||
</string>
|
||||
<string name="TRAENKE">
|
||||
|
@ -1476,7 +1479,7 @@
|
|||
<text locale="en">MAKE</text>
|
||||
</string>
|
||||
<string name="maketemp">
|
||||
<text locale="de">MAKE TEMP</text>
|
||||
<text locale="en">MAKETEMP</text>
|
||||
</string>
|
||||
<string name="move">
|
||||
<text locale="en">MOVE</text>
|
||||
|
|
|
@ -854,7 +854,7 @@
|
|||
<arg name="average" type="int"/>
|
||||
</type>
|
||||
<text locale="de">"Deine Partei hat $int($score) Punkte. Der Durchschnitt für Parteien ähnlichen Alters ist $int($average) Punkte."</text>
|
||||
<text locale="fr">"Your faction has a score of $int($score). The average score for similar factions is $int($average)."</text>
|
||||
<text locale="en">"Your faction has a score of $int($score). The average score for similar factions is $int($average)."</text>
|
||||
</message>
|
||||
<message name="nr_header_date" section="nr">
|
||||
<type>
|
||||
|
@ -862,7 +862,6 @@
|
|||
<arg name="date" type="string"/>
|
||||
</type>
|
||||
<text locale="de">"Report für $game, $date"</text>
|
||||
<text locale="fr">"Report for $game, $date"</text>
|
||||
<text locale="en">"Report for $game, $date"</text>
|
||||
</message>
|
||||
<message name="nr_vicinitystart" section="nr">
|
||||
|
@ -3606,7 +3605,7 @@
|
|||
<arg name="weeks" type="int"/>
|
||||
<arg name="skill" type="skill"/>
|
||||
</type>
|
||||
<text locale="de">"$unit($unit) vergißt durch Dumpfbackenbrot $int($weeks) Wochen des Talentes $skill($skill)."</text>
|
||||
<text locale="de">"$unit($unit) vergisst durch Dumpfbackenbrot $int($weeks) Wochen des Talentes $skill($skill)."</text>
|
||||
<text locale="fr">"$unit($unit) eats a Dumpfbackenbrot and forgets $int($weeks) weeks worth of $skill($skill)."</text>
|
||||
<text locale="en">"$unit($unit) eats a Dumpfbackenbrot and forgets $int($weeks) weeks worth of $skill($skill)."</text>
|
||||
</message>
|
||||
|
@ -3699,7 +3698,7 @@
|
|||
<arg name="unit" type="unit"/>
|
||||
<arg name="skill" type="skill"/>
|
||||
</type>
|
||||
<text locale="de">"$unit($unit) vergißt $skill($skill)."</text>
|
||||
<text locale="de">"$unit($unit) vergisst $skill($skill)."</text>
|
||||
<text locale="fr">"$unit($unit) forgets $skill($skill)."</text>
|
||||
<text locale="en">"$unit($unit) forgets $skill($skill)."</text>
|
||||
</message>
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<directions>
|
||||
<dir name="vortex" desc="vortex_desc"/>
|
||||
</directions>
|
|
@ -223,7 +223,7 @@
|
|||
</string>
|
||||
<string name="seashell">
|
||||
<text locale="en">This badge pronounces its wearer an official visitor to the
|
||||
region of Muschelplateau.</text>
|
||||
embassies of Muschelplateau.</text>
|
||||
<text locale="de">Dieses Abzeichen identifiziert die Partei seines Trägers offiziell
|
||||
als einen Besucher der Botschafterregion 'Muschelplateau'.</text>
|
||||
</string>
|
||||
|
|
3
res/items.xml
Normal file
3
res/items.xml
Normal file
|
@ -0,0 +1,3 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1" ?>
|
||||
<items>
|
||||
</items>
|
11
s/cron/previews.sh
Normal file → Executable file
11
s/cron/previews.sh
Normal file → Executable file
|
@ -1,8 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
s/preview build
|
||||
s/preview version
|
||||
[ -z $ERESSEA ] && ERESSEA=$HOME/eressea
|
||||
SRC=$ERESSEA/git
|
||||
$SRC/s/preview build master
|
||||
$SRC/s/preview version
|
||||
for game in 2 3 4 ; do
|
||||
s/preview -g $game run && \
|
||||
s/preview -g $game send
|
||||
$SRC/s/preview -g $game run && \
|
||||
$SRC/s/preview -g $game send
|
||||
done
|
||||
|
|
14
s/preview
14
s/preview
|
@ -23,6 +23,7 @@ function build() {
|
|||
assert_dir $SOURCE
|
||||
cd $SOURCE
|
||||
git pull || abort "failed to update source. do you have local changes?"
|
||||
[ -z $1 ] || git checkout $1
|
||||
s/build || abort "build failed."
|
||||
}
|
||||
|
||||
|
@ -83,11 +84,13 @@ let turn=$turn+1
|
|||
}
|
||||
|
||||
function send() {
|
||||
echo "sending reports to $1"
|
||||
zip="$turn-$1.zip"
|
||||
zip -q -u $zip $turn-$1.?r
|
||||
email=$(grep "faction=$1:" reports.txt | cut -d: -f2 | sed 's/email=//')
|
||||
cat /dev/null | mutt -F $ERESSEA/etc/muttrc -s "Testauswertung Spiel $GAME Partei $1" -a $zip -- $email
|
||||
echo "sending reports to $1 / $email"
|
||||
info=/dev/null
|
||||
[ -e ../email.txt ] && info=../email.txt
|
||||
cat $info | mutt -F $ERESSEA/etc/muttrc -s "Testauswertung Spiel $game Partei $1" -a $zip -- $email
|
||||
}
|
||||
|
||||
game=0
|
||||
|
@ -128,7 +131,8 @@ case "$1" in
|
|||
version
|
||||
;;
|
||||
"build")
|
||||
build
|
||||
shift
|
||||
build $*
|
||||
;;
|
||||
"setup")
|
||||
setup
|
||||
|
@ -153,8 +157,8 @@ case "$1" in
|
|||
sent=1
|
||||
done
|
||||
if [ $sent -eq 0 ]; then
|
||||
if [ -e $factions ]; then
|
||||
for faction in $(cat $factions) ; do
|
||||
if [ -e ../$factions ]; then
|
||||
for faction in $(cat ../$factions) ; do
|
||||
send $faction
|
||||
done
|
||||
fi
|
||||
|
|
|
@ -1,14 +1,6 @@
|
|||
cmake_minimum_required(VERSION 2.6)
|
||||
project (server C)
|
||||
|
||||
IF(CMAKE_COMPILER_IS_GNUCC)
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long")
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -DHAVE__BOOL")
|
||||
ELSEIF(MSVC)
|
||||
ELSE(CMAKE_COMPILER_IS_GNUCC)
|
||||
MESSAGE(STATUS "Unknown compiler ${CMAKE_C_COMPILER_ID}")
|
||||
ENDIF(CMAKE_COMPILER_IS_GNUCC)
|
||||
|
||||
include_directories (${CMAKE_CURRENT_SOURCE_DIR})
|
||||
include_directories (${CRITBIT_INCLUDE_DIR})
|
||||
include_directories (${CJSON_INCLUDE_DIR})
|
||||
|
@ -20,6 +12,19 @@ include_directories (${LUA_INCLUDE_DIR})
|
|||
include_directories (${BSON_INCLUDE_DIR})
|
||||
include_directories (${INIPARSER_INCLUDE_DIR})
|
||||
|
||||
IF(CMAKE_COMPILER_IS_GNUCC)
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long")
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -DHAVE__BOOL")
|
||||
elseif(MSVC)
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4 /WX /MP")
|
||||
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
|
||||
"${CMAKE_EXE_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libc.lib /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcd.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrtd.lib")
|
||||
ELSE(CMAKE_COMPILER_IS_GNUCC)
|
||||
MESSAGE(STATUS "Unknown compiler ${CMAKE_C_COMPILER_ID}")
|
||||
ENDIF(CMAKE_COMPILER_IS_GNUCC)
|
||||
|
||||
add_subdirectory(util)
|
||||
add_subdirectory(kernel)
|
||||
add_subdirectory(items)
|
||||
|
@ -58,6 +63,14 @@ TOLUA_BINDING(settings.pkg bind_settings.h)
|
|||
ENDIF()
|
||||
|
||||
set (ERESSEA_SRC
|
||||
move.c
|
||||
spells.c
|
||||
battle.c
|
||||
alchemy.c
|
||||
stealth.c
|
||||
vortex.c
|
||||
names.c
|
||||
reports.c
|
||||
eressea.c
|
||||
callback.c
|
||||
direction.c
|
||||
|
@ -141,7 +154,12 @@ target_link_libraries(eressea
|
|||
set(TESTS_SRC
|
||||
test_eressea.c
|
||||
tests.c
|
||||
battle.test.c
|
||||
vortex.test.c
|
||||
tests.test.c
|
||||
reports.test.c
|
||||
stealth.test.c
|
||||
move.test.c
|
||||
callback.test.c
|
||||
direction.test.c
|
||||
keyword.test.c
|
||||
|
|
|
@ -19,18 +19,18 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include "alchemy.h"
|
||||
|
||||
#include "item.h"
|
||||
#include "faction.h"
|
||||
#include "messages.h"
|
||||
#include "build.h"
|
||||
#include "magic.h"
|
||||
#include "region.h"
|
||||
#include "pool.h"
|
||||
#include "race.h"
|
||||
#include "unit.h"
|
||||
#include "skill.h"
|
||||
#include "move.h"
|
||||
#include "skill.h"
|
||||
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/messages.h>
|
||||
#include <kernel/build.h>
|
||||
#include <kernel/magic.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/pool.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
/* util includes */
|
||||
#include <util/attrib.h>
|
4342
src/battle.c
Normal file
4342
src/battle.c
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,13 +1,15 @@
|
|||
#include <kernel/types.h>
|
||||
#include <platform.h>
|
||||
|
||||
#include "battle.h"
|
||||
#include "building.h"
|
||||
#include "faction.h"
|
||||
#include "item.h"
|
||||
#include "race.h"
|
||||
#include "region.h"
|
||||
#include "skill.h"
|
||||
#include "unit.h"
|
||||
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
#include <CuTest.h>
|
||||
#include "tests.h"
|
|
@ -385,7 +385,7 @@ 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);
|
||||
tolua_pushstring(L, self->race->_name[0]);
|
||||
tolua_pushstring(L, self->race->_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
|
||||
#include "spells.h"
|
||||
|
||||
/* kernel includes */
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/messages.h>
|
||||
#include <kernel/reports.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ static int fix_familiars(struct lua_State *L)
|
|||
free(mage->spellbook);
|
||||
mage->spellbook = 0;
|
||||
|
||||
_snprintf(buffer, sizeof(buffer), "%s_familiar", u_race(u)->_name[0]);
|
||||
_snprintf(buffer, sizeof(buffer), "%s_familiar", u_race(u)->_name);
|
||||
eq = get_equipment(buffer);
|
||||
if (eq) {
|
||||
equip_unit_mask(u, eq, EQUIP_SPELLS);
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
#include <kernel/config.h>
|
||||
#include <kernel/magic.h>
|
||||
#include <kernel/order.h>
|
||||
#include <kernel/battle.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/terrain.h>
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/move.h>
|
||||
#include "battle.h"
|
||||
#include "move.h"
|
||||
#include "economy.h"
|
||||
#include "laws.h"
|
||||
#include "market.h"
|
||||
|
|
|
@ -228,7 +228,7 @@ static int tolua_region_get_luxury(lua_State * L)
|
|||
if (r->land) {
|
||||
const item_type *lux = r_luxury(r);
|
||||
if (lux) {
|
||||
const char *name = lux->rtype->_name[0];
|
||||
const char *name = lux->rtype->_name;
|
||||
tolua_pushstring(L, name);
|
||||
return 1;
|
||||
}
|
||||
|
@ -268,7 +268,7 @@ static int tolua_region_get_herb(lua_State * L)
|
|||
{
|
||||
region *r = (region *) tolua_tousertype(L, 1, 0);
|
||||
if (r->land && r->land->herbtype) {
|
||||
const char *name = r->land->herbtype->rtype->_name[0];
|
||||
const char *name = r->land->herbtype->rtype->_name;
|
||||
tolua_pushstring(L, name);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -11,12 +11,14 @@ without prior permission by the authors of Eressea.
|
|||
*/
|
||||
|
||||
#include <platform.h>
|
||||
#include <kernel/types.h>
|
||||
#include "bind_ship.h"
|
||||
#include "bind_unit.h"
|
||||
|
||||
#include "move.h"
|
||||
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/move.h>
|
||||
#include <kernel/ship.h>
|
||||
#include <kernel/build.h>
|
||||
|
||||
|
|
|
@ -17,14 +17,15 @@ without prior permission by the authors of Eressea.
|
|||
#ifdef BSON_ATTRIB
|
||||
# include "bind_attrib.h"
|
||||
#endif
|
||||
#include "alchemy.h"
|
||||
#include "bindings.h"
|
||||
#include "move.h"
|
||||
|
||||
/* attributes includes */
|
||||
#include <attributes/racename.h>
|
||||
#include <attributes/key.h>
|
||||
|
||||
/* kernel includes */
|
||||
#include <kernel/alchemy.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/config.h>
|
||||
#include <kernel/faction.h>
|
||||
|
@ -32,7 +33,6 @@ without prior permission by the authors of Eressea.
|
|||
#include <kernel/item.h>
|
||||
#include <kernel/magic.h>
|
||||
#include <kernel/messages.h>
|
||||
#include <kernel/move.h>
|
||||
#include <kernel/order.h>
|
||||
#include <kernel/pool.h>
|
||||
#include <kernel/race.h>
|
||||
|
@ -840,7 +840,7 @@ static int tolua_unit_set_faction(lua_State * L)
|
|||
static int tolua_unit_get_race(lua_State * L)
|
||||
{
|
||||
unit *self = (unit *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, u_race(self)->_name[0]);
|
||||
tolua_pushstring(L, u_race(self)->_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ without prior permission by the authors of Eressea.
|
|||
*/
|
||||
|
||||
#include <platform.h>
|
||||
#include <kernel/types.h>
|
||||
#include "bindings.h"
|
||||
#include "bind_unit.h"
|
||||
#include "bind_storage.h"
|
||||
|
@ -24,6 +25,7 @@ without prior permission by the authors of Eressea.
|
|||
#include "bind_region.h"
|
||||
#include "helpers.h"
|
||||
#include "console.h"
|
||||
#include "reports.h"
|
||||
|
||||
#include <kernel/config.h>
|
||||
|
||||
|
@ -36,7 +38,6 @@ without prior permission by the authors of Eressea.
|
|||
#include <kernel/terrain.h>
|
||||
#include <kernel/messages.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/reports.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/plane.h>
|
||||
#include <kernel/race.h>
|
||||
|
@ -151,7 +152,7 @@ int tolua_itemlist_next(lua_State * L)
|
|||
item **item_ptr = (item **) lua_touserdata(L, lua_upvalueindex(1));
|
||||
item *itm = *item_ptr;
|
||||
if (itm != NULL) {
|
||||
tolua_pushstring(L, itm->type->rtype->_name[0]);
|
||||
tolua_pushstring(L, itm->type->rtype->_name);
|
||||
*item_ptr = itm->next;
|
||||
return 1;
|
||||
}
|
||||
|
@ -711,7 +712,7 @@ static int tolua_write_spells(lua_State * L)
|
|||
for (; comp->type != 0; ++comp) {
|
||||
static const char *costs[] = { "fixed", "level", "linear" };
|
||||
xmlNodePtr cnode = xmlNewNode(NULL, BAD_CAST "resource");
|
||||
xmlNewProp(cnode, BAD_CAST "name", BAD_CAST comp->type->_name[0]);
|
||||
xmlNewProp(cnode, BAD_CAST "name", BAD_CAST comp->type->_name);
|
||||
xmlNewProp(cnode, BAD_CAST "amount", xml_i(comp->amount));
|
||||
xmlNewProp(cnode, BAD_CAST "cost", BAD_CAST costs[comp->cost]);
|
||||
xmlAddChild(node, cnode);
|
||||
|
@ -820,7 +821,7 @@ static int config_get_resource(lua_State * L)
|
|||
lua_newtable(L);
|
||||
for (i = 0; itype->construction->materials[i].number; ++i) {
|
||||
lua_pushstring(L,
|
||||
itype->construction->materials[i].rtype->_name[0]);
|
||||
itype->construction->materials[i].rtype->_name);
|
||||
lua_pushinteger(L, itype->construction->materials[i].number);
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
|
@ -865,7 +866,7 @@ static int config_get_btype(lua_State * L)
|
|||
lua_newtable(L);
|
||||
for (i = 0; btype->maintenance[i].number; ++i) {
|
||||
lua_pushstring(L,
|
||||
btype->maintenance[i].rtype->_name[0]);
|
||||
btype->maintenance[i].rtype->_name);
|
||||
lua_pushinteger(L, btype->maintenance[i].number);
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
|
@ -884,7 +885,7 @@ static int config_get_btype(lua_State * L)
|
|||
lua_newtable(L);
|
||||
for (i = 0; btype->construction->materials[i].number; ++i) {
|
||||
lua_pushstring(L,
|
||||
btype->construction->materials[i].rtype->_name[0]);
|
||||
btype->construction->materials[i].rtype->_name);
|
||||
lua_pushinteger(L, btype->construction->materials[i].number);
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
|
@ -950,7 +951,7 @@ static int config_get_stype(lua_State * L)
|
|||
lua_newtable(L);
|
||||
for (i = 0; stype->construction->materials[i].number; ++i) {
|
||||
lua_pushstring(L,
|
||||
stype->construction->materials[i].rtype->_name[0]);
|
||||
stype->construction->materials[i].rtype->_name);
|
||||
lua_pushinteger(L, stype->construction->materials[i].number);
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
#define VERSION_MAJOR 3
|
||||
#define VERSION_MINOR 0
|
||||
#define VERSION_BUILD 682
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_BUILD 684
|
||||
|
|
|
@ -20,9 +20,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/config.h>
|
||||
#include "creation.h"
|
||||
#include "monster.h"
|
||||
#include "alchemy.h"
|
||||
|
||||
/* kernel includes */
|
||||
#include <kernel/alchemy.h>
|
||||
#include <kernel/build.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
|
|
|
@ -30,9 +30,12 @@ without prior permission by the authors of Eressea.
|
|||
/* gamecode includes */
|
||||
#include "laws.h"
|
||||
#include "economy.h"
|
||||
#include "stealth.h"
|
||||
#include "move.h"
|
||||
#include "reports.h"
|
||||
#include "alchemy.h"
|
||||
|
||||
/* kernel includes */
|
||||
#include <kernel/alchemy.h>
|
||||
#include <kernel/alliance.h>
|
||||
#include <kernel/ally.h>
|
||||
#include <kernel/connection.h>
|
||||
|
@ -42,12 +45,10 @@ without prior permission by the authors of Eressea.
|
|||
#include <kernel/group.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/messages.h>
|
||||
#include <kernel/move.h>
|
||||
#include <kernel/order.h>
|
||||
#include <kernel/plane.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/reports.h>
|
||||
#include <kernel/resources.h>
|
||||
#include <kernel/ship.h>
|
||||
#include <kernel/spell.h>
|
||||
|
@ -340,7 +341,7 @@ static int cr_race(variant var, char *buffer, const void *userdata)
|
|||
{
|
||||
const faction *report = (const faction *)userdata;
|
||||
const struct race *rc = (const race *)var.v;
|
||||
const char *key = rc_name(rc, 0);
|
||||
const char *key = rc_name(rc, NAME_SINGULAR);
|
||||
sprintf(buffer, "\"%s\"",
|
||||
translate(key, locale_string(report->locale, key)));
|
||||
return 0;
|
||||
|
@ -490,11 +491,12 @@ static void report_crtypes(FILE * F, const struct locale *lang)
|
|||
for (kmt = mtypehash[i]; kmt; kmt = kmt->nexthash) {
|
||||
const struct nrmessage_type *nrt = nrt_find(lang, kmt->mtype);
|
||||
if (nrt) {
|
||||
char buffer[DISPLAYSIZE];
|
||||
unsigned int hash = kmt->mtype->key;
|
||||
assert(hash > 0);
|
||||
fprintf(F, "MESSAGETYPE %u\n", hash);
|
||||
fputc('\"', F);
|
||||
fputs(escape_string(nrt_string(nrt), NULL, 0), F);
|
||||
fputs(escape_string(nrt_string(nrt), buffer, sizeof(buffer)), F);
|
||||
fputs("\";text\n", F);
|
||||
fprintf(F, "\"%s\";section\n", nrt_section(nrt));
|
||||
}
|
||||
|
@ -832,20 +834,20 @@ static void cr_output_unit(FILE * F, const region * r, const faction * f,
|
|||
if (pzTmp) {
|
||||
fprintf(F, "\"%s\";Typ\n", pzTmp);
|
||||
if (u->faction == f && fval(u_race(u), RCF_SHAPESHIFTANY)) {
|
||||
const char *zRace = rc_name(u_race(u), 1);
|
||||
const char *zRace = rc_name(u_race(u), NAME_PLURAL);
|
||||
fprintf(F, "\"%s\";wahrerTyp\n",
|
||||
translate(zRace, locale_string(f->locale, zRace)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
const race *irace = u_irace(u);
|
||||
const char *zRace = rc_name(irace, 1);
|
||||
const char *zRace = rc_name(irace, NAME_PLURAL);
|
||||
fprintf(F, "\"%s\";Typ\n",
|
||||
translate(zRace, locale_string(f->locale, zRace)));
|
||||
if (u->faction == f && irace != u_race(u)) {
|
||||
assert(skill_enabled(SK_STEALTH)
|
||||
|| !"we're resetting this on load, so.. ircase should never be used");
|
||||
zRace = rc_name(u_race(u), 1);
|
||||
zRace = rc_name(u_race(u), NAME_PLURAL);
|
||||
fprintf(F, "\"%s\";wahrerTyp\n",
|
||||
translate(zRace, locale_string(f->locale, zRace)));
|
||||
}
|
||||
|
@ -1546,7 +1548,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset)
|
|||
fprintf(F, "%d;Punktedurchschnitt\n", avgscore);
|
||||
#endif
|
||||
{
|
||||
const char *zRace = rc_name(f->race, 1);
|
||||
const char *zRace = rc_name(f->race, NAME_PLURAL);
|
||||
fprintf(F, "\"%s\";Typ\n", translate(zRace, LOC(f->locale, zRace)));
|
||||
}
|
||||
prefix = get_prefix(f->attribs);
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#include <platform.h>
|
||||
#include "kernel/types.h"
|
||||
#include <kernel/types.h>
|
||||
|
||||
#include "direction.h"
|
||||
#include "util/language.h"
|
||||
#include "tests.h"
|
||||
|
||||
#include <util/language.h>
|
||||
|
||||
#include <CuTest.h>
|
||||
|
||||
static void test_init_directions(CuTest *tc) {
|
||||
|
|
|
@ -22,14 +22,16 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/types.h>
|
||||
#include "economy.h"
|
||||
|
||||
#include "alchemy.h"
|
||||
#include "direction.h"
|
||||
#include "give.h"
|
||||
#include "laws.h"
|
||||
#include "randenc.h"
|
||||
#include "spy.h"
|
||||
#include "move.h"
|
||||
#include "reports.h"
|
||||
|
||||
/* kernel includes */
|
||||
#include <kernel/alchemy.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/calendar.h>
|
||||
#include <kernel/curse.h>
|
||||
|
@ -38,13 +40,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/item.h>
|
||||
#include <kernel/magic.h>
|
||||
#include <kernel/messages.h>
|
||||
#include <kernel/move.h>
|
||||
#include <kernel/order.h>
|
||||
#include <kernel/plane.h>
|
||||
#include <kernel/pool.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/reports.h>
|
||||
#include <kernel/resources.h>
|
||||
#include <kernel/ship.h>
|
||||
#include <kernel/terrain.h>
|
||||
|
@ -259,7 +259,7 @@ static void add_recruits(unit * u, int number, int wanted)
|
|||
}
|
||||
|
||||
strlcpy(equipment, "new_", sizeof(equipment));
|
||||
strlcat(equipment, u_race(u)->_name[0], sizeof(equipment));
|
||||
strlcat(equipment, u_race(u)->_name, sizeof(equipment));
|
||||
strlcat(equipment, "_unit", sizeof(equipment));
|
||||
equip_unit(unew, get_equipment(equipment));
|
||||
|
||||
|
@ -502,8 +502,7 @@ static void recruit(unit * u, struct order *ord, request ** recruitorders)
|
|||
const struct race *rc = u_race(u);
|
||||
const char *str;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
n = getuint();
|
||||
|
||||
if (u->number == 0) {
|
||||
|
@ -666,8 +665,7 @@ int give_control_cmd(unit * u, order * ord)
|
|||
const char *s;
|
||||
param_t p;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
u2 = getunit(r, u->faction);
|
||||
s = getstrtoken();
|
||||
p = findparam(s, u->faction->locale);
|
||||
|
@ -730,11 +728,10 @@ static void give_cmd(unit * u, order * ord)
|
|||
plane *pl;
|
||||
message *msg;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
u2 = getunit(r, u->faction);
|
||||
s = getstrtoken();
|
||||
n = atoip(s);
|
||||
n = s ? atoip(s) : 0;
|
||||
p = (n > 0) ? NOPARAM : findparam(s, u->faction->locale);
|
||||
|
||||
/* first, do all the ones that do not require HELP_GIVE or CONTACT */
|
||||
|
@ -857,7 +854,7 @@ static void give_cmd(unit * u, order * ord)
|
|||
return;
|
||||
}
|
||||
s = getstrtoken();
|
||||
if (*s == 0) { /* GIVE ALL items that you have */
|
||||
if (!s || *s == 0) { /* GIVE ALL items that you have */
|
||||
|
||||
/* do these checks once, not for each item we have: */
|
||||
if (!(u_race(u)->ec_flags & GIVEITEM) && u2 != NULL) {
|
||||
|
@ -990,8 +987,7 @@ static int forget_cmd(unit * u, order * ord)
|
|||
return 0;
|
||||
}
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
|
||||
if ((sk = get_skill(s, u->faction->locale)) != NOSKILL) {
|
||||
|
@ -1800,9 +1796,10 @@ int make_cmd(unit * u, struct order *ord)
|
|||
const char *s;
|
||||
const struct locale *lang = u->faction->locale;
|
||||
char ibuf[16];
|
||||
keyword_t kwd;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
kwd = init_order(ord);
|
||||
assert(kwd == K_MAKE);
|
||||
s = getstrtoken();
|
||||
|
||||
m = atoi((const char *)s);
|
||||
|
@ -2060,6 +2057,8 @@ static void buy(unit * u, request ** buyorders, struct order *ord)
|
|||
attrib *a;
|
||||
const item_type *itype = NULL;
|
||||
const luxury_type *ltype = NULL;
|
||||
keyword_t kwd;
|
||||
|
||||
if (u->ship && is_guarded(r, u, GUARD_CREWS)) {
|
||||
cmistake(u, ord, 69, MSG_INCOME);
|
||||
return;
|
||||
|
@ -2071,8 +2070,8 @@ static void buy(unit * u, request ** buyorders, struct order *ord)
|
|||
/* Im Augenblick kann man nur 1 Produkt kaufen. expandbuying ist aber
|
||||
* schon dafür ausgerüstet, mehrere Produkte zu kaufen. */
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
kwd = init_order(ord);
|
||||
assert(kwd == K_BUY);
|
||||
n = getuint();
|
||||
if (!n) {
|
||||
cmistake(u, ord, 26, MSG_COMMERCE);
|
||||
|
@ -2351,10 +2350,11 @@ static bool sell(unit * u, request ** sellorders, struct order *ord)
|
|||
{
|
||||
bool unlimited = true;
|
||||
const item_type *itype;
|
||||
const luxury_type *ltype = NULL;
|
||||
const luxury_type *ltype;
|
||||
int n;
|
||||
region *r = u->region;
|
||||
const char *s;
|
||||
keyword_t kwd;
|
||||
|
||||
if (u->ship && is_guarded(r, u, GUARD_CREWS)) {
|
||||
cmistake(u, ord, 69, MSG_INCOME);
|
||||
|
@ -2363,8 +2363,8 @@ static bool sell(unit * u, request ** sellorders, struct order *ord)
|
|||
/* sellorders sind KEIN array, weil für alle items DIE SELBE resource
|
||||
* (das geld der region) aufgebraucht wird. */
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
kwd = init_order(ord);
|
||||
assert(kwd == K_SELL);
|
||||
s = getstrtoken();
|
||||
|
||||
if (findparam(s, u->faction->locale) == P_ANY) {
|
||||
|
@ -2424,9 +2424,8 @@ static bool sell(unit * u, request ** sellorders, struct order *ord)
|
|||
return false;
|
||||
}
|
||||
s = getstrtoken();
|
||||
itype = finditemtype(s, u->faction->locale);
|
||||
if (itype != NULL)
|
||||
ltype = resource2luxury(itype->rtype);
|
||||
itype = s ? finditemtype(s, u->faction->locale) : 0;
|
||||
ltype = itype ? resource2luxury(itype->rtype) : 0;
|
||||
if (ltype == NULL) {
|
||||
cmistake(u, ord, 126, MSG_COMMERCE);
|
||||
return false;
|
||||
|
@ -2764,11 +2763,10 @@ static void breed_cmd(unit * u, struct order *ord)
|
|||
}
|
||||
|
||||
/* züchte [<anzahl>] <parameter> */
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
(void)init_order(ord);
|
||||
s = getstrtoken();
|
||||
|
||||
m = atoi((const char *)s);
|
||||
m = s ? atoi((const char *)s) : 0;
|
||||
if (m != 0) {
|
||||
/* first came a want-paramter */
|
||||
s = getstrtoken();
|
||||
|
@ -2777,7 +2775,7 @@ static void breed_cmd(unit * u, struct order *ord)
|
|||
m = INT_MAX;
|
||||
}
|
||||
|
||||
if (!s[0]) {
|
||||
if (!s || !s[0]) {
|
||||
p = P_ANY;
|
||||
}
|
||||
else {
|
||||
|
@ -2830,9 +2828,10 @@ static const char *rough_amount(int a, int m)
|
|||
static void research_cmd(unit * u, struct order *ord)
|
||||
{
|
||||
region *r = u->region;
|
||||
keyword_t kwd;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
kwd = init_order(ord);
|
||||
assert(kwd == K_RESEARCH);
|
||||
/*
|
||||
const char *s = getstrtoken();
|
||||
|
||||
|
@ -2908,6 +2907,10 @@ static void steal_cmd(unit * u, struct order *ord, request ** stealorders)
|
|||
region *r = u->region;
|
||||
faction *f = NULL;
|
||||
message * msg;
|
||||
keyword_t kwd;
|
||||
|
||||
kwd = init_order(ord);
|
||||
assert(kwd == K_STEAL);
|
||||
|
||||
assert(skill_enabled(SK_PERCEPTION) && skill_enabled(SK_STEALTH));
|
||||
|
||||
|
@ -2916,8 +2919,6 @@ static void steal_cmd(unit * u, struct order *ord, request ** stealorders)
|
|||
ADDMSG(&u->faction->msgs, msg);
|
||||
return;
|
||||
}
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
id = read_unitid(u->faction, r);
|
||||
u2 = findunitr(r, id);
|
||||
|
||||
|
@ -3040,7 +3041,10 @@ void entertain_cmd(unit * u, struct order *ord)
|
|||
request *o;
|
||||
static int entertainbase = 0;
|
||||
static int entertainperlevel = 0;
|
||||
keyword_t kwd;
|
||||
|
||||
kwd = init_order(ord);
|
||||
assert(kwd == K_ENTERTAIN);
|
||||
if (!entertainbase) {
|
||||
const char *str = get_param(global.parameters, "entertain.base");
|
||||
entertainbase = str ? atoi(str) : 0;
|
||||
|
@ -3073,8 +3077,6 @@ void entertain_cmd(unit * u, struct order *ord)
|
|||
u->wants = u->number * (entertainbase + effskill(u, SK_ENTERTAINMENT)
|
||||
* entertainperlevel);
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
max_e = getuint();
|
||||
if (max_e != 0) {
|
||||
u->wants = _min(u->wants, max_e);
|
||||
|
@ -3214,6 +3216,10 @@ void tax_cmd(unit * u, struct order *ord, request ** taxorders)
|
|||
int n;
|
||||
request *o;
|
||||
int max;
|
||||
keyword_t kwd;
|
||||
|
||||
kwd = init_order(ord);
|
||||
assert(kwd == K_TAX);
|
||||
|
||||
if (!humanoidrace(u_race(u)) && !is_monsters(u->faction)) {
|
||||
cmistake(u, ord, 228, MSG_INCOME);
|
||||
|
@ -3236,8 +3242,6 @@ void tax_cmd(unit * u, struct order *ord, request ** taxorders)
|
|||
return;
|
||||
}
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
max = getuint();
|
||||
|
||||
if (max == 0)
|
||||
|
|
|
@ -14,10 +14,7 @@
|
|||
#include <triggers/triggers.h>
|
||||
#include <util/language.h>
|
||||
#include <kernel/xmlreader.h>
|
||||
#include <kernel/reports.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/names.h>
|
||||
#include <kernel/reports.h>
|
||||
#include <kernel/building.h>
|
||||
#include <modules/wormhole.h>
|
||||
#include <modules/gmcmd.h>
|
||||
|
@ -27,6 +24,7 @@
|
|||
#include "report.h"
|
||||
#include "items.h"
|
||||
#include "creport.h"
|
||||
#include "names.h"
|
||||
|
||||
void game_done(void)
|
||||
{
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include <kernel/pool.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/reports.h>
|
||||
#include <kernel/ship.h>
|
||||
#include <kernel/terrain.h>
|
||||
#include <kernel/unit.h>
|
||||
|
@ -228,7 +227,7 @@ void give_men(int n, unit * u, unit * u2, struct order *ord)
|
|||
error = 312;
|
||||
}
|
||||
else if (u2 && u2->number != 0 && u_race(u2) != u_race(u)) {
|
||||
log_debug("faction %s attempts to give %s to %s.\n", itoa36(u->faction->no), u_race(u)->_name[0], u_race(u2)->_name[0]);
|
||||
log_debug("faction %s attempts to give %s to %s.\n", itoa36(u->faction->no), u_race(u)->_name, u_race(u2)->_name);
|
||||
error = 139;
|
||||
}
|
||||
else if (u2 != NULL && (get_racename(u2->attribs)
|
||||
|
|
|
@ -39,7 +39,6 @@
|
|||
#include <kernel/plane.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/names.h>
|
||||
#include <kernel/teleport.h>
|
||||
#include <kernel/terrainid.h>
|
||||
#include <kernel/unit.h>
|
||||
|
|
|
@ -10,8 +10,9 @@ This program may not be used, modified or distributed
|
|||
without prior permission by the authors of Eressea.
|
||||
*/
|
||||
|
||||
#include "helpers.h"
|
||||
#include <platform.h>
|
||||
#include "helpers.h"
|
||||
#include "vortex.h"
|
||||
|
||||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
|
@ -46,7 +47,7 @@ lua_giveitem(unit * s, unit * d, const item_type * itype, int n, struct order *o
|
|||
lua_State *L = (lua_State *) global.vm_state;
|
||||
char fname[64];
|
||||
int result = -1;
|
||||
const char *iname = itype->rtype->_name[0];
|
||||
const char *iname = itype->rtype->_name;
|
||||
|
||||
assert(s != NULL);
|
||||
strlcpy(fname, iname, sizeof(fname));
|
||||
|
@ -81,7 +82,7 @@ static int limit_resource(const region * r, const resource_type * rtype)
|
|||
int result = -1;
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
|
||||
strlcpy(fname, rtype->_name[0], sizeof(fname));
|
||||
strlcpy(fname, rtype->_name, sizeof(fname));
|
||||
strlcat(fname, "_limit", sizeof(fname));
|
||||
|
||||
lua_getglobal(L, fname);
|
||||
|
@ -110,7 +111,7 @@ produce_resource(region * r, const resource_type * rtype, int norders)
|
|||
lua_State *L = (lua_State *) global.vm_state;
|
||||
char fname[64];
|
||||
|
||||
strlcpy(fname, rtype->_name[0], sizeof(fname));
|
||||
strlcpy(fname, rtype->_name, sizeof(fname));
|
||||
strlcat(fname, "_produce", sizeof(fname));
|
||||
|
||||
lua_getglobal(L, fname);
|
||||
|
@ -216,7 +217,7 @@ static int lua_initfamiliar(unit * u)
|
|||
int result = -1;
|
||||
|
||||
strlcpy(fname, "initfamiliar_", sizeof(fname));
|
||||
strlcat(fname, u_race(u)->_name[0], sizeof(fname));
|
||||
strlcat(fname, u_race(u)->_name, sizeof(fname));
|
||||
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
|
@ -237,7 +238,7 @@ static int lua_initfamiliar(unit * u)
|
|||
|
||||
create_mage(u, M_GRAY);
|
||||
|
||||
strlcpy(fname, u_race(u)->_name[0], sizeof(fname));
|
||||
strlcpy(fname, u_race(u)->_name, sizeof(fname));
|
||||
strlcat(fname, "_familiar", sizeof(fname));
|
||||
equip_unit(u, get_equipment(fname));
|
||||
return result;
|
||||
|
@ -250,7 +251,7 @@ lua_changeresource(unit * u, const struct resource_type *rtype, int delta)
|
|||
int result = -1;
|
||||
char fname[64];
|
||||
|
||||
strlcpy(fname, rtype->_name[0], sizeof(fname));
|
||||
strlcpy(fname, rtype->_name, sizeof(fname));
|
||||
strlcat(fname, "_changeresource", sizeof(fname));
|
||||
|
||||
lua_getglobal(L, fname);
|
||||
|
@ -280,7 +281,7 @@ static int lua_getresource(unit * u, const struct resource_type *rtype)
|
|||
int result = -1;
|
||||
char fname[64];
|
||||
|
||||
strlcpy(fname, rtype->_name[0], sizeof(fname));
|
||||
strlcpy(fname, rtype->_name, sizeof(fname));
|
||||
strlcat(fname, "_getresource", sizeof(fname));
|
||||
|
||||
lua_getglobal(L, fname);
|
||||
|
@ -315,7 +316,7 @@ static bool lua_canuse_item(const unit * u, const struct item_type *itype)
|
|||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
|
||||
tolua_pushstring(L, itype->rtype->_name[0]);
|
||||
tolua_pushstring(L, itype->rtype->_name);
|
||||
|
||||
if (lua_pcall(L, 2, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
|
@ -345,7 +346,7 @@ lua_wage(const region * r, const faction * f, const race * rc, int in_turn)
|
|||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region");
|
||||
tolua_pushusertype(L, (void *)f, TOLUA_CAST "faction");
|
||||
tolua_pushstring(L, rc ? rc->_name[0] : 0);
|
||||
tolua_pushstring(L, rc ? rc->_name : 0);
|
||||
tolua_pushnumber(L, (lua_Number) in_turn);
|
||||
|
||||
if (lua_pcall(L, 3, 1, 0) != 0) {
|
||||
|
@ -503,7 +504,7 @@ lua_useitem(struct unit *u, const struct item_type *itype, int amount,
|
|||
char fname[64];
|
||||
|
||||
strlcpy(fname, "use_", sizeof(fname));
|
||||
strlcat(fname, itype->rtype->_name[0], sizeof(fname));
|
||||
strlcat(fname, itype->rtype->_name, sizeof(fname));
|
||||
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
|
@ -541,6 +542,7 @@ int tolua_toid(lua_State * L, int idx, int def)
|
|||
|
||||
void register_tolua_helpers(void)
|
||||
{
|
||||
at_register(&at_direction);
|
||||
at_register(&at_building_action);
|
||||
|
||||
register_function((pf_generic) & lua_building_protection,
|
||||
|
|
326
src/items.c
326
src/items.c
|
@ -3,6 +3,7 @@
|
|||
#include "items.h"
|
||||
|
||||
#include "study.h"
|
||||
#include "move.h"
|
||||
|
||||
#include <kernel/curse.h>
|
||||
#include <kernel/building.h>
|
||||
|
@ -10,7 +11,6 @@
|
|||
#include <kernel/item.h>
|
||||
#include <kernel/magic.h>
|
||||
#include <kernel/messages.h>
|
||||
#include <kernel/move.h>
|
||||
#include <kernel/order.h>
|
||||
#include <kernel/plane.h>
|
||||
#include <kernel/pool.h>
|
||||
|
@ -32,39 +32,39 @@
|
|||
#define MAXGAIN 15
|
||||
static int
|
||||
use_studypotion(struct unit *u, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
struct order *ord)
|
||||
{
|
||||
if (getkeyword(u->thisorder) == K_STUDY) {
|
||||
skill_t sk;
|
||||
skill *sv;
|
||||
if (init_order(u->thisorder) == K_STUDY) {
|
||||
skill_t sk;
|
||||
skill *sv;
|
||||
|
||||
init_tokens(u->thisorder);
|
||||
skip_token();
|
||||
sk = get_skill(getstrtoken(), u->faction->locale);
|
||||
sv = unit_skill(u, sk);
|
||||
sk = get_skill(getstrtoken(), u->faction->locale);
|
||||
sv = unit_skill(u, sk);
|
||||
|
||||
if (sv && sv->level > 2) {
|
||||
/* TODO: message */
|
||||
} else if (study_cost(u, sk) > 0) {
|
||||
/* TODO: message */
|
||||
} else {
|
||||
attrib *a = a_find(u->attribs, &at_learning);
|
||||
teaching_info *teach;
|
||||
if (a == NULL) {
|
||||
a = a_add(&u->attribs, a_new(&at_learning));
|
||||
}
|
||||
teach = (teaching_info *) a->data.v;
|
||||
if (amount > MAXGAIN)
|
||||
amount = MAXGAIN;
|
||||
teach->value += amount * 30;
|
||||
if (teach->value > MAXGAIN * 30) {
|
||||
teach->value = MAXGAIN * 30;
|
||||
}
|
||||
i_change(&u->items, itype, -amount);
|
||||
return 0;
|
||||
if (sv && sv->level > 2) {
|
||||
/* TODO: message */
|
||||
}
|
||||
else if (study_cost(u, sk) > 0) {
|
||||
/* TODO: message */
|
||||
}
|
||||
else {
|
||||
attrib *a = a_find(u->attribs, &at_learning);
|
||||
teaching_info *teach;
|
||||
if (a == NULL) {
|
||||
a = a_add(&u->attribs, a_new(&at_learning));
|
||||
}
|
||||
teach = (teaching_info *)a->data.v;
|
||||
if (amount > MAXGAIN)
|
||||
amount = MAXGAIN;
|
||||
teach->value += amount * 30;
|
||||
if (teach->value > MAXGAIN * 30) {
|
||||
teach->value = MAXGAIN * 30;
|
||||
}
|
||||
i_change(&u->items, itype, -amount);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return EUNUSABLE;
|
||||
return EUNUSABLE;
|
||||
}
|
||||
|
||||
/* END studypotion */
|
||||
|
@ -73,27 +73,27 @@ use_studypotion(struct unit *u, const struct item_type *itype, int amount,
|
|||
#define SPEEDSAIL_EFFECT 1
|
||||
static int
|
||||
use_speedsail(struct unit *u, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
struct order *ord)
|
||||
{
|
||||
curse *c;
|
||||
float effect;
|
||||
ship *sh = u->ship;
|
||||
if (!sh) {
|
||||
cmistake(u, ord, 20, MSG_MOVE);
|
||||
return -1;
|
||||
}
|
||||
curse *c;
|
||||
float effect;
|
||||
ship *sh = u->ship;
|
||||
if (!sh) {
|
||||
cmistake(u, ord, 20, MSG_MOVE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
effect = SPEEDSAIL_EFFECT;
|
||||
c =
|
||||
create_curse(u, &sh->attribs, ct_find("shipspeedup"), 20, INT_MAX, effect,
|
||||
0);
|
||||
c_setflag(c, CURSE_NOAGE);
|
||||
effect = SPEEDSAIL_EFFECT;
|
||||
c =
|
||||
create_curse(u, &sh->attribs, ct_find("shipspeedup"), 20, INT_MAX, effect,
|
||||
0);
|
||||
c_setflag(c, CURSE_NOAGE);
|
||||
|
||||
ADDMSG(&u->faction->msgs, msg_message("use_speedsail", "unit speed", u,
|
||||
SPEEDSAIL_EFFECT));
|
||||
use_pooled(u, itype->rtype, GET_DEFAULT, 1);
|
||||
ADDMSG(&u->faction->msgs, msg_message("use_speedsail", "unit speed", u,
|
||||
SPEEDSAIL_EFFECT));
|
||||
use_pooled(u, itype->rtype, GET_DEFAULT, 1);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* END speedsail */
|
||||
|
@ -103,113 +103,113 @@ use_speedsail(struct unit *u, const struct item_type *itype, int amount,
|
|||
* Antimagiezone, die zwei Runden bestehen bleibt */
|
||||
static int
|
||||
use_antimagiccrystal(unit * u, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
struct order *ord)
|
||||
{
|
||||
region *r = u->region;
|
||||
const resource_type *rt_crystal = NULL;
|
||||
int i;
|
||||
region *r = u->region;
|
||||
const resource_type *rt_crystal = NULL;
|
||||
int i;
|
||||
|
||||
if (rt_crystal == NULL) {
|
||||
rt_crystal = rt_find("antimagic");
|
||||
assert(rt_crystal != NULL);
|
||||
}
|
||||
for (i = 0; i != amount; ++i) {
|
||||
int effect, duration = 2;
|
||||
float force;
|
||||
spell *sp = find_spell("antimagiczone");
|
||||
attrib **ap = &r->attribs;
|
||||
unused_arg(ord);
|
||||
assert(sp);
|
||||
|
||||
/* Reduziert die Stärke jedes Spruchs um effect */
|
||||
effect = 5;
|
||||
|
||||
/* Hält Sprüche bis zu einem summierten Gesamtlevel von power aus.
|
||||
* Jeder Zauber reduziert die 'Lebenskraft' (vigour) der Antimagiezone
|
||||
* um seine Stufe */
|
||||
force = (float)effect * 20; /* Stufe 5 =~ 100 */
|
||||
|
||||
/* Regionszauber auflösen */
|
||||
while (*ap && force > 0) {
|
||||
curse *c;
|
||||
attrib *a = *ap;
|
||||
if (!fval(a->type, ATF_CURSE)) {
|
||||
do {
|
||||
ap = &(*ap)->next;
|
||||
} while (*ap && a->type == (*ap)->type);
|
||||
continue;
|
||||
}
|
||||
c = (curse *) a->data.v;
|
||||
|
||||
/* Immunität prüfen */
|
||||
if (c_flags(c) & CURSE_IMMUNE) {
|
||||
do {
|
||||
ap = &(*ap)->next;
|
||||
} while (*ap && a->type == (*ap)->type);
|
||||
continue;
|
||||
}
|
||||
|
||||
force = destr_curse(c, effect, force);
|
||||
if (c->vigour <= 0) {
|
||||
a_remove(&r->attribs, a);
|
||||
}
|
||||
if (*ap)
|
||||
ap = &(*ap)->next;
|
||||
if (rt_crystal == NULL) {
|
||||
rt_crystal = rt_find("antimagic");
|
||||
assert(rt_crystal != NULL);
|
||||
}
|
||||
for (i = 0; i != amount; ++i) {
|
||||
int effect, duration = 2;
|
||||
float force;
|
||||
spell *sp = find_spell("antimagiczone");
|
||||
attrib **ap = &r->attribs;
|
||||
unused_arg(ord);
|
||||
assert(sp);
|
||||
|
||||
if (force > 0) {
|
||||
create_curse(u, &r->attribs, ct_find("antimagiczone"), (float)force, duration,
|
||||
(float)effect, 0);
|
||||
/* Reduziert die Stärke jedes Spruchs um effect */
|
||||
effect = 5;
|
||||
|
||||
/* Hält Sprüche bis zu einem summierten Gesamtlevel von power aus.
|
||||
* Jeder Zauber reduziert die 'Lebenskraft' (vigour) der Antimagiezone
|
||||
* um seine Stufe */
|
||||
force = (float)effect * 20; /* Stufe 5 =~ 100 */
|
||||
|
||||
/* Regionszauber auflösen */
|
||||
while (*ap && force > 0) {
|
||||
curse *c;
|
||||
attrib *a = *ap;
|
||||
if (!fval(a->type, ATF_CURSE)) {
|
||||
do {
|
||||
ap = &(*ap)->next;
|
||||
} while (*ap && a->type == (*ap)->type);
|
||||
continue;
|
||||
}
|
||||
c = (curse *)a->data.v;
|
||||
|
||||
/* Immunität prüfen */
|
||||
if (c_flags(c) & CURSE_IMMUNE) {
|
||||
do {
|
||||
ap = &(*ap)->next;
|
||||
} while (*ap && a->type == (*ap)->type);
|
||||
continue;
|
||||
}
|
||||
|
||||
force = destr_curse(c, effect, force);
|
||||
if (c->vigour <= 0) {
|
||||
a_remove(&r->attribs, a);
|
||||
}
|
||||
if (*ap)
|
||||
ap = &(*ap)->next;
|
||||
}
|
||||
|
||||
if (force > 0) {
|
||||
create_curse(u, &r->attribs, ct_find("antimagiczone"), (float)force, duration,
|
||||
(float)effect, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
use_pooled(u, rt_crystal, GET_DEFAULT, amount);
|
||||
ADDMSG(&u->faction->msgs, msg_message("use_antimagiccrystal",
|
||||
"unit region", u, r));
|
||||
return 0;
|
||||
use_pooled(u, rt_crystal, GET_DEFAULT, amount);
|
||||
ADDMSG(&u->faction->msgs, msg_message("use_antimagiccrystal",
|
||||
"unit region", u, r));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
use_instantartsculpture(struct unit *u, const struct item_type *itype,
|
||||
int amount, struct order *ord)
|
||||
int amount, struct order *ord)
|
||||
{
|
||||
building *b;
|
||||
building *b;
|
||||
|
||||
if (u->region->land == NULL) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_onlandonly", ""));
|
||||
return -1;
|
||||
}
|
||||
if (u->region->land == NULL) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_onlandonly", ""));
|
||||
return -1;
|
||||
}
|
||||
|
||||
b = new_building(bt_find("artsculpture"), u->region, u->faction->locale);
|
||||
b->size = 100;
|
||||
b = new_building(bt_find("artsculpture"), u->region, u->faction->locale);
|
||||
b->size = 100;
|
||||
|
||||
ADDMSG(&u->region->msgs, msg_message("artsculpture_create", "unit region",
|
||||
u, u->region));
|
||||
ADDMSG(&u->region->msgs, msg_message("artsculpture_create", "unit region",
|
||||
u, u->region));
|
||||
|
||||
use_pooled(u, itype->rtype, GET_DEFAULT, 1);
|
||||
use_pooled(u, itype->rtype, GET_DEFAULT, 1);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
use_instantartacademy(struct unit *u, const struct item_type *itype,
|
||||
int amount, struct order *ord)
|
||||
int amount, struct order *ord)
|
||||
{
|
||||
building *b;
|
||||
building *b;
|
||||
|
||||
if (u->region->land == NULL) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_onlandonly", ""));
|
||||
return -1;
|
||||
}
|
||||
if (u->region->land == NULL) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_onlandonly", ""));
|
||||
return -1;
|
||||
}
|
||||
|
||||
b = new_building(bt_find("artacademy"), u->region, u->faction->locale);
|
||||
b->size = 100;
|
||||
b = new_building(bt_find("artacademy"), u->region, u->faction->locale);
|
||||
b->size = 100;
|
||||
|
||||
ADDMSG(&u->region->msgs, msg_message("artacademy_create", "unit region", u,
|
||||
u->region));
|
||||
ADDMSG(&u->region->msgs, msg_message("artacademy_create", "unit region", u,
|
||||
u->region));
|
||||
|
||||
use_pooled(u, itype->rtype, GET_DEFAULT, 1);
|
||||
use_pooled(u, itype->rtype, GET_DEFAULT, 1);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define BAGPIPEFRACTION dice_rand("2d4+2")
|
||||
|
@ -217,58 +217,58 @@ use_instantartacademy(struct unit *u, const struct item_type *itype,
|
|||
|
||||
static int
|
||||
use_bagpipeoffear(struct unit *u, const struct item_type *itype,
|
||||
int amount, struct order *ord)
|
||||
int amount, struct order *ord)
|
||||
{
|
||||
int money;
|
||||
int money;
|
||||
|
||||
if (get_curse(u->region->attribs, ct_find("depression"))) {
|
||||
cmistake(u, ord, 58, MSG_MAGIC);
|
||||
return -1;
|
||||
}
|
||||
if (get_curse(u->region->attribs, ct_find("depression"))) {
|
||||
cmistake(u, ord, 58, MSG_MAGIC);
|
||||
return -1;
|
||||
}
|
||||
|
||||
money = entertainmoney(u->region) / BAGPIPEFRACTION;
|
||||
change_money(u, money);
|
||||
rsetmoney(u->region, rmoney(u->region) - money);
|
||||
money = entertainmoney(u->region) / BAGPIPEFRACTION;
|
||||
change_money(u, money);
|
||||
rsetmoney(u->region, rmoney(u->region) - money);
|
||||
|
||||
create_curse(u, &u->region->attribs, ct_find("depression"),
|
||||
20, BAGPIPEDURATION, 0.0, 0);
|
||||
create_curse(u, &u->region->attribs, ct_find("depression"),
|
||||
20, BAGPIPEDURATION, 0.0, 0);
|
||||
|
||||
ADDMSG(&u->faction->msgs, msg_message("bagpipeoffear_faction",
|
||||
"unit region command money", u, u->region, ord, money));
|
||||
ADDMSG(&u->faction->msgs, msg_message("bagpipeoffear_faction",
|
||||
"unit region command money", u, u->region, ord, money));
|
||||
|
||||
ADDMSG(&u->region->msgs, msg_message("bagpipeoffear_region",
|
||||
"unit money", u, money));
|
||||
ADDMSG(&u->region->msgs, msg_message("bagpipeoffear_region",
|
||||
"unit money", u, money));
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
use_aurapotion50(struct unit *u, const struct item_type *itype,
|
||||
int amount, struct order *ord)
|
||||
int amount, struct order *ord)
|
||||
{
|
||||
if (!is_mage(u)) {
|
||||
cmistake(u, ord, 214, MSG_MAGIC);
|
||||
return -1;
|
||||
}
|
||||
if (!is_mage(u)) {
|
||||
cmistake(u, ord, 214, MSG_MAGIC);
|
||||
return -1;
|
||||
}
|
||||
|
||||
change_spellpoints(u, 50);
|
||||
change_spellpoints(u, 50);
|
||||
|
||||
ADDMSG(&u->faction->msgs, msg_message("aurapotion50",
|
||||
"unit region command", u, u->region, ord));
|
||||
ADDMSG(&u->faction->msgs, msg_message("aurapotion50",
|
||||
"unit region command", u, u->region, ord));
|
||||
|
||||
use_pooled(u, itype->rtype, GET_DEFAULT, 1);
|
||||
use_pooled(u, itype->rtype, GET_DEFAULT, 1);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void register_itemfunctions(void)
|
||||
{
|
||||
register_demonseye();
|
||||
register_item_use(use_antimagiccrystal, "use_antimagiccrystal");
|
||||
register_item_use(use_instantartsculpture, "use_instantartsculpture");
|
||||
register_item_use(use_studypotion, "use_studypotion");
|
||||
register_item_use(use_speedsail, "use_speedsail");
|
||||
register_item_use(use_instantartacademy, "use_instantartacademy");
|
||||
register_item_use(use_bagpipeoffear, "use_bagpipeoffear");
|
||||
register_item_use(use_aurapotion50, "use_aurapotion50");
|
||||
register_demonseye();
|
||||
register_item_use(use_antimagiccrystal, "use_antimagiccrystal");
|
||||
register_item_use(use_instantartsculpture, "use_instantartsculpture");
|
||||
register_item_use(use_studypotion, "use_studypotion");
|
||||
register_item_use(use_speedsail, "use_speedsail");
|
||||
register_item_use(use_instantartacademy, "use_instantartacademy");
|
||||
register_item_use(use_bagpipeoffear, "use_bagpipeoffear");
|
||||
register_item_use(use_aurapotion50, "use_aurapotion50");
|
||||
}
|
||||
|
|
|
@ -24,12 +24,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/messages.h>
|
||||
#include <kernel/move.h>
|
||||
#include <kernel/plane.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/ship.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
#include <move.h>
|
||||
|
||||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <util/log.h>
|
||||
|
|
|
@ -19,13 +19,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include "weapons.h"
|
||||
#include "battle.h"
|
||||
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/build.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/messages.h>
|
||||
#include <kernel/battle.h>
|
||||
#include <kernel/pool.h>
|
||||
|
||||
/* util includes */
|
||||
|
|
|
@ -3,30 +3,28 @@ project(kernel C)
|
|||
SET(_TEST_FILES
|
||||
build.test.c
|
||||
config.test.c
|
||||
faction.test.c
|
||||
unit.test.c
|
||||
save.test.c
|
||||
ship.test.c
|
||||
spell.test.c
|
||||
ally.test.c
|
||||
battle.test.c
|
||||
building.test.c
|
||||
magic.test.c
|
||||
equipment.test.c
|
||||
curse.test.c
|
||||
item.test.c
|
||||
move.test.c
|
||||
order.test.c
|
||||
pool.test.c
|
||||
reports.test.c
|
||||
race.test.c
|
||||
spellbook.test.c
|
||||
curse.test.c
|
||||
jsonconf.test.c
|
||||
)
|
||||
|
||||
SET(_FILES
|
||||
alchemy.c
|
||||
alliance.c
|
||||
ally.c
|
||||
battle.c
|
||||
build.c
|
||||
building.c
|
||||
calendar.c
|
||||
|
@ -40,16 +38,12 @@ group.c
|
|||
item.c
|
||||
magic.c
|
||||
messages.c
|
||||
move.c
|
||||
names.c
|
||||
order.c
|
||||
pathfinder.c
|
||||
plane.c
|
||||
player.c
|
||||
pool.c
|
||||
race.c
|
||||
region.c
|
||||
reports.c
|
||||
resources.c
|
||||
save.c
|
||||
ship.c
|
||||
|
|
|
@ -158,8 +158,7 @@ static void perform_kick(void)
|
|||
|
||||
if (al && alliance_get_leader(al) == ta->u->faction) {
|
||||
faction *f;
|
||||
init_tokens(ta->ord);
|
||||
skip_token();
|
||||
init_order(ta->ord);
|
||||
skip_token();
|
||||
f = getfaction();
|
||||
if (f && f_get_alliance(f) == al) {
|
||||
|
@ -180,8 +179,7 @@ static void perform_new(void)
|
|||
int id;
|
||||
faction *f = ta->u->faction;
|
||||
|
||||
init_tokens(ta->ord);
|
||||
skip_token();
|
||||
init_order(ta->ord);
|
||||
skip_token();
|
||||
id = getid();
|
||||
|
||||
|
@ -216,8 +214,7 @@ static void perform_transfer(void)
|
|||
|
||||
if (al && alliance_get_leader(al) == ta->u->faction) {
|
||||
faction *f;
|
||||
init_tokens(ta->ord);
|
||||
skip_token();
|
||||
init_order(ta->ord);
|
||||
skip_token();
|
||||
f = getfaction();
|
||||
if (f && f_get_alliance(f) == al) {
|
||||
|
@ -237,8 +234,7 @@ static void perform_join(void)
|
|||
faction *fj = ta->u->faction;
|
||||
int aid;
|
||||
|
||||
init_tokens(ta->ord);
|
||||
skip_token();
|
||||
init_order(ta->ord);
|
||||
skip_token();
|
||||
aid = getid();
|
||||
if (aid) {
|
||||
|
@ -250,8 +246,7 @@ static void perform_join(void)
|
|||
faction *fi = ti->u->faction;
|
||||
if (fi && f_get_alliance(fi) == al) {
|
||||
int fid;
|
||||
init_tokens(ti->ord);
|
||||
skip_token();
|
||||
init_order(ti->ord);
|
||||
skip_token();
|
||||
fid = getid();
|
||||
if (fid == fj->no) {
|
||||
|
|
4281
src/kernel/battle.c
4281
src/kernel/battle.c
File diff suppressed because it is too large
Load diff
|
@ -146,8 +146,7 @@ int destroy_cmd(unit * u, struct order *ord)
|
|||
if (u->number < 1)
|
||||
return 0;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
|
||||
if (findparam(s, u->faction->locale) == P_ROAD) {
|
||||
|
@ -522,9 +521,7 @@ int build(unit * u, const construction * ctype, int completed, int want)
|
|||
}
|
||||
}
|
||||
|
||||
if (want > 0) {
|
||||
n = _min(want, n);
|
||||
}
|
||||
if (want < n) n = want;
|
||||
|
||||
if (type->maxsize > 0) {
|
||||
n = _min(type->maxsize - completed, n);
|
||||
|
|
|
@ -79,8 +79,7 @@ extern "C" {
|
|||
void sunhash(struct ship *sh);
|
||||
extern int roqf_factor(void);
|
||||
|
||||
extern int build(struct unit *u, const construction * ctype, int completed,
|
||||
int want);
|
||||
int build(struct unit *u, const construction * ctype, int completed, int want);
|
||||
extern int maxbuild(const struct unit *u, const construction * cons);
|
||||
extern struct message *msg_materials_required(struct unit *u,
|
||||
struct order *ord, const struct construction *ctype, int multi);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include "alchemy.h"
|
||||
#include "types.h"
|
||||
#include "build.h"
|
||||
#include "order.h"
|
||||
|
@ -13,86 +14,233 @@
|
|||
#include <CuTest.h>
|
||||
#include <tests.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
static void test_build_building_no_materials(CuTest *tc) {
|
||||
typedef struct build_fixture {
|
||||
faction *f;
|
||||
unit *u;
|
||||
region *r;
|
||||
faction *f;
|
||||
race *rc;
|
||||
const building_type *btype;
|
||||
construction cons;
|
||||
} build_fixture;
|
||||
|
||||
static unit * setup_build(build_fixture *bf) {
|
||||
test_cleanup();
|
||||
test_create_world();
|
||||
bf->rc = test_create_race("human");
|
||||
bf->r = findregion(0, 0);
|
||||
bf->f = test_create_faction(bf->rc);
|
||||
assert(bf->rc && bf->f && bf->r);
|
||||
bf->u = test_create_unit(bf->f, bf->r);
|
||||
assert(bf->u);
|
||||
|
||||
rc = test_create_race("human");
|
||||
r = findregion(0, 0);
|
||||
f = test_create_faction(rc);
|
||||
assert(rc && f && r);
|
||||
u = test_create_unit(f, r);
|
||||
bf->cons.materials = calloc(2, sizeof(requirement));
|
||||
bf->cons.materials[0].number = 1;
|
||||
bf->cons.materials[0].rtype = get_resourcetype(R_SILVER);
|
||||
bf->cons.skill = SK_ARMORER;
|
||||
bf->cons.minskill = 2;
|
||||
bf->cons.maxsize = -1;
|
||||
bf->cons.reqsize = 1;
|
||||
return bf->u;
|
||||
}
|
||||
|
||||
static void test_build_requires_materials(CuTest *tc) {
|
||||
build_fixture bf = { 0 };
|
||||
unit *u;
|
||||
const struct item_type *itype;
|
||||
|
||||
u = setup_build(&bf);
|
||||
set_level(u, SK_ARMORER, 2);
|
||||
CuAssertIntEquals(tc, ENOMATERIALS, build(u, &bf.cons, 0, 1));
|
||||
itype = bf.cons.materials[0].rtype->itype;
|
||||
i_change(&u->items, itype, 2);
|
||||
CuAssertIntEquals(tc, 1, build(u, &bf.cons, 0, 1));
|
||||
CuAssertIntEquals(tc, 1, i_get(u->items, itype));
|
||||
}
|
||||
|
||||
static void test_build_requires_building(CuTest *tc) {
|
||||
build_fixture bf = { 0 };
|
||||
unit *u;
|
||||
const struct resource_type *rtype;
|
||||
building_type *btype;
|
||||
|
||||
u = setup_build(&bf);
|
||||
rtype = bf.cons.materials[0].rtype;
|
||||
i_change(&u->items, rtype->itype, 1);
|
||||
set_level(u, SK_ARMORER, 2);
|
||||
bf.cons.btype = btype = bt_get_or_create("hodor");
|
||||
btype->maxcapacity = 1;
|
||||
btype->capacity = 1;
|
||||
CuAssertIntEquals_Msg(tc, "must be inside a production building", EBUILDINGREQ, build(u, &bf.cons, 0, 1));
|
||||
u->building = test_create_building(u->region, btype);
|
||||
fset(u->building, BLD_WORKING);
|
||||
CuAssertIntEquals(tc, 1, build(u, &bf.cons, 0, 1));
|
||||
btype->maxcapacity = 0;
|
||||
CuAssertIntEquals_Msg(tc, "cannot build when production building capacity exceeded", EBUILDINGREQ, build(u, &bf.cons, 0, 1));
|
||||
}
|
||||
|
||||
static void test_build_failure_missing_skill(CuTest *tc) {
|
||||
build_fixture bf = { 0 };
|
||||
unit *u;
|
||||
const struct resource_type *rtype;
|
||||
|
||||
u = setup_build(&bf);
|
||||
rtype = bf.cons.materials[0].rtype;
|
||||
i_change(&u->items, rtype->itype, 1);
|
||||
CuAssertIntEquals(tc, ENEEDSKILL, build(u, &bf.cons, 1, 1));
|
||||
}
|
||||
|
||||
static void test_build_failure_low_skill(CuTest *tc) {
|
||||
build_fixture bf = { 0 };
|
||||
unit *u;
|
||||
const struct resource_type *rtype;
|
||||
|
||||
u = setup_build(&bf);
|
||||
rtype = bf.cons.materials[0].rtype;
|
||||
i_change(&u->items, rtype->itype, 1);
|
||||
set_level(u, SK_ARMORER, bf.cons.minskill-1);
|
||||
CuAssertIntEquals(tc, ELOWSKILL, build(u, &bf.cons, 0, 10));
|
||||
}
|
||||
|
||||
static void test_build_failure_completed(CuTest *tc) {
|
||||
build_fixture bf = { 0 };
|
||||
unit *u;
|
||||
const struct resource_type *rtype;
|
||||
|
||||
u = setup_build(&bf);
|
||||
rtype = bf.cons.materials[0].rtype;
|
||||
i_change(&u->items, rtype->itype, 1);
|
||||
set_level(u, SK_ARMORER, bf.cons.minskill);
|
||||
bf.cons.maxsize = 1;
|
||||
CuAssertIntEquals(tc, ECOMPLETE, build(u, &bf.cons, bf.cons.maxsize, 10));
|
||||
CuAssertIntEquals(tc, 1, i_get(u->items, rtype->itype));
|
||||
}
|
||||
|
||||
static void test_build_limits(CuTest *tc) {
|
||||
build_fixture bf = { 0 };
|
||||
unit *u;
|
||||
const struct resource_type *rtype;
|
||||
|
||||
u = setup_build(&bf);
|
||||
rtype = bf.cons.materials[0].rtype;
|
||||
i_change(&u->items, rtype->itype, 1);
|
||||
set_level(u, SK_ARMORER, bf.cons.minskill);
|
||||
CuAssertIntEquals(tc, 1, build(u, &bf.cons, 0, 10));
|
||||
CuAssertIntEquals(tc, 0, i_get(u->items, rtype->itype));
|
||||
|
||||
scale_number(u, 2);
|
||||
set_level(u, SK_ARMORER, bf.cons.minskill);
|
||||
i_change(&u->items, rtype->itype, 2);
|
||||
CuAssertIntEquals(tc, 2, build(u, &bf.cons, 0, 10));
|
||||
CuAssertIntEquals(tc, 0, i_get(u->items, rtype->itype));
|
||||
|
||||
scale_number(u, 2);
|
||||
set_level(u, SK_ARMORER, bf.cons.minskill * 2);
|
||||
i_change(&u->items, rtype->itype, 4);
|
||||
CuAssertIntEquals(tc, 4, build(u, &bf.cons, 0, 10));
|
||||
CuAssertIntEquals(tc, 0, i_get(u->items, rtype->itype));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_build_with_ring(CuTest *tc) {
|
||||
build_fixture bf = { 0 };
|
||||
unit *u;
|
||||
item_type *ring;
|
||||
const struct resource_type *rtype;
|
||||
|
||||
u = setup_build(&bf);
|
||||
rtype = bf.cons.materials[0].rtype;
|
||||
ring = it_get_or_create(rt_get_or_create("roqf"));
|
||||
assert(rtype && ring);
|
||||
|
||||
set_level(u, SK_ARMORER, bf.cons.minskill);
|
||||
i_change(&u->items, rtype->itype, 20);
|
||||
i_change(&u->items, ring, 1);
|
||||
CuAssertIntEquals(tc, 10, build(u, &bf.cons, 0, 20));
|
||||
CuAssertIntEquals(tc, 10, i_get(u->items, rtype->itype));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_build_with_potion(CuTest *tc) {
|
||||
build_fixture bf = { 0 };
|
||||
unit *u;
|
||||
const potion_type *ptype;
|
||||
const struct resource_type *rtype;
|
||||
|
||||
u = setup_build(&bf);
|
||||
rtype = bf.cons.materials[0].rtype;
|
||||
oldpotiontype[P_DOMORE] = ptype = new_potiontype(it_get_or_create(rt_get_or_create("hodor")), 1);
|
||||
assert(rtype && ptype);
|
||||
|
||||
i_change(&u->items, rtype->itype, 20);
|
||||
change_effect(u, ptype, 4);
|
||||
set_level(u, SK_ARMORER, bf.cons.minskill);
|
||||
CuAssertIntEquals(tc, 2, build(u, &bf.cons, 0, 20));
|
||||
CuAssertIntEquals(tc, 18, i_get(u->items, rtype->itype));
|
||||
CuAssertIntEquals(tc, 3, get_effect(u, ptype));
|
||||
set_level(u, SK_ARMORER, bf.cons.minskill*2);
|
||||
CuAssertIntEquals(tc, 4, build(u, &bf.cons, 0, 20));
|
||||
CuAssertIntEquals(tc, 2, get_effect(u, ptype));
|
||||
set_level(u, SK_ARMORER, bf.cons.minskill);
|
||||
scale_number(u, 2); // OBS: this scales the effects, too:
|
||||
CuAssertIntEquals(tc, 4, get_effect(u, ptype));
|
||||
CuAssertIntEquals(tc, 4, build(u, &bf.cons, 0, 20));
|
||||
CuAssertIntEquals(tc, 2, get_effect(u, ptype));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_build_building_no_materials(CuTest *tc) {
|
||||
const building_type *btype;
|
||||
build_fixture bf = { 0 };
|
||||
unit *u;
|
||||
|
||||
u = setup_build(&bf);
|
||||
btype = bt_find("castle");
|
||||
assert(u && btype);
|
||||
assert(btype);
|
||||
set_level(u, SK_BUILDING, 1);
|
||||
CuAssertIntEquals(tc, ENOMATERIALS, build_building(u, btype, 0, 4, 0));
|
||||
CuAssertPtrEquals(tc, 0, r->buildings);
|
||||
CuAssertPtrEquals(tc, 0, u->region->buildings);
|
||||
CuAssertPtrEquals(tc, 0, u->building);
|
||||
}
|
||||
|
||||
static void test_build_building_with_golem(CuTest *tc) {
|
||||
unit *u;
|
||||
region *r;
|
||||
faction *f;
|
||||
race *rc;
|
||||
build_fixture bf = { 0 };
|
||||
const building_type *btype;
|
||||
|
||||
test_cleanup();
|
||||
test_create_world();
|
||||
|
||||
rc = test_create_race("stonegolem");
|
||||
rc->flags |= RCF_STONEGOLEM;
|
||||
u = setup_build(&bf);
|
||||
bf.rc->flags |= RCF_STONEGOLEM;
|
||||
btype = bt_find("castle");
|
||||
assert(btype && rc);
|
||||
assert(btype);
|
||||
assert(btype->construction);
|
||||
r = findregion(0, 0);
|
||||
assert(!r->buildings);
|
||||
f = test_create_faction(rc);
|
||||
assert(r && f);
|
||||
u = test_create_unit(f, r);
|
||||
assert(u);
|
||||
set_level(u, SK_BUILDING, 1);
|
||||
CuAssertIntEquals(tc, 1, build_building(u, btype, 0, 4, 0));
|
||||
CuAssertPtrNotNull(tc, r->buildings);
|
||||
CuAssertIntEquals(tc, 1, r->buildings->size);
|
||||
|
||||
set_level(bf.u, SK_BUILDING, 1);
|
||||
CuAssertIntEquals(tc, 1, build_building(u, btype, 0, 1, 0));
|
||||
CuAssertPtrNotNull(tc, u->region->buildings);
|
||||
CuAssertIntEquals(tc, 1, u->region->buildings->size);
|
||||
CuAssertIntEquals(tc, 0, u->number);
|
||||
}
|
||||
|
||||
static void test_build_building_success(CuTest *tc) {
|
||||
unit *u;
|
||||
region *r;
|
||||
faction *f;
|
||||
race *rc;
|
||||
build_fixture bf = { 0 };
|
||||
const building_type *btype;
|
||||
const resource_type *rtype;
|
||||
|
||||
test_cleanup();
|
||||
test_create_world();
|
||||
u = setup_build(&bf);
|
||||
|
||||
rc = test_create_race("human");
|
||||
rtype = get_resourcetype(R_STONE);
|
||||
btype = bt_find("castle");
|
||||
assert(btype && rc && rtype && rtype->itype);
|
||||
assert(btype && rtype && rtype->itype);
|
||||
assert(btype->construction);
|
||||
r = findregion(0, 0);
|
||||
assert(!r->buildings);
|
||||
f = test_create_faction(rc);
|
||||
assert(r && f);
|
||||
u = test_create_unit(f, r);
|
||||
assert(u);
|
||||
i_change(&u->items, rtype->itype, 1);
|
||||
assert(!u->region->buildings);
|
||||
|
||||
i_change(&bf.u->items, rtype->itype, 1);
|
||||
set_level(u, SK_BUILDING, 1);
|
||||
CuAssertIntEquals(tc, 1, build_building(u, btype, 0, 4, 0));
|
||||
CuAssertPtrNotNull(tc, r->buildings);
|
||||
CuAssertPtrEquals(tc, r->buildings, u->building);
|
||||
CuAssertPtrNotNull(tc, u->region->buildings);
|
||||
CuAssertPtrEquals(tc, u->region->buildings, u->building);
|
||||
CuAssertIntEquals(tc, 1, u->building->size);
|
||||
CuAssertIntEquals(tc, 0, i_get(u->items, rtype->itype));
|
||||
}
|
||||
|
@ -100,6 +248,14 @@ static void test_build_building_success(CuTest *tc) {
|
|||
CuSuite *get_build_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_build_limits);
|
||||
SUITE_ADD_TEST(suite, test_build_failure_low_skill);
|
||||
SUITE_ADD_TEST(suite, test_build_failure_missing_skill);
|
||||
SUITE_ADD_TEST(suite, test_build_requires_materials);
|
||||
SUITE_ADD_TEST(suite, test_build_requires_building);
|
||||
SUITE_ADD_TEST(suite, test_build_failure_completed);
|
||||
SUITE_ADD_TEST(suite, test_build_with_ring);
|
||||
SUITE_ADD_TEST(suite, test_build_with_potion);
|
||||
SUITE_ADD_TEST(suite, test_build_building_success);
|
||||
SUITE_ADD_TEST(suite, test_build_building_with_golem);
|
||||
SUITE_ADD_TEST(suite, test_build_building_no_materials);
|
||||
|
|
|
@ -92,8 +92,7 @@ static int do_command_i(const void *keys, struct unit *u, struct order *ord)
|
|||
|
||||
void do_command(const void *keys, struct unit *u, struct order *ord)
|
||||
{
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
if (do_command_i(keys, u, ord) != E_TOK_SUCCESS) {
|
||||
char cmd[ORDERSIZE];
|
||||
get_command(ord, cmd, sizeof(cmd));
|
||||
|
|
|
@ -27,7 +27,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include "alliance.h"
|
||||
#include "ally.h"
|
||||
#include "alchemy.h"
|
||||
#include "battle.h"
|
||||
#include "connection.h"
|
||||
#include "building.h"
|
||||
#include "calendar.h"
|
||||
|
@ -40,7 +39,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include "magic.h"
|
||||
#include "messages.h"
|
||||
#include "move.h"
|
||||
#include "names.h"
|
||||
#include "objtypes.h"
|
||||
#include "order.h"
|
||||
#include "plane.h"
|
||||
|
@ -76,6 +74,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/umlaut.h>
|
||||
#include <util/xml.h>
|
||||
|
||||
#include <stealth.h>
|
||||
|
||||
#ifdef USE_LIBXML2
|
||||
/* libxml includes */
|
||||
#include <libxml/tree.h>
|
||||
|
@ -314,11 +314,11 @@ helpmode helpmodes[] = {
|
|||
*/
|
||||
const char *dbrace(const struct race *rc)
|
||||
{
|
||||
static char zText[32];
|
||||
static char zText[32]; // FIXME: static return value
|
||||
char *zPtr = zText;
|
||||
|
||||
/* the english names are all in ASCII, so we don't need to worry about UTF8 */
|
||||
strcpy(zText, (const char *)LOC(get_locale("en"), rc_name(rc, 0)));
|
||||
strcpy(zText, (const char *)LOC(get_locale("en"), rc_name(rc, NAME_SINGULAR)));
|
||||
while (*zPtr) {
|
||||
*zPtr = (char)(toupper(*zPtr));
|
||||
++zPtr;
|
||||
|
@ -346,7 +346,7 @@ const char *parameters[MAXPARAMS] = {
|
|||
"SCHIFF",
|
||||
"SILBER",
|
||||
"STRASSEN",
|
||||
"TEMPORAERE",
|
||||
"TEMP",
|
||||
"FLIEHE",
|
||||
"GEBAEUDE",
|
||||
"GIB", /* Für HELFE */
|
||||
|
@ -637,6 +637,7 @@ unsigned int atoip(const char *s)
|
|||
{
|
||||
int n;
|
||||
|
||||
assert(s);
|
||||
n = atoi(s);
|
||||
|
||||
if (n < 0)
|
||||
|
@ -668,23 +669,6 @@ region *findunitregion(const unit * su)
|
|||
#endif
|
||||
}
|
||||
|
||||
int eff_stealth(const unit * u, const region * r)
|
||||
{
|
||||
int e = 0;
|
||||
|
||||
/* Auf Schiffen keine Tarnung! */
|
||||
if (!u->ship && skill_enabled(SK_STEALTH)) {
|
||||
e = eff_skill(u, SK_STEALTH, r);
|
||||
|
||||
if (fval(u, UFL_STEALTH)) {
|
||||
int es = u_geteffstealth(u);
|
||||
if (es >= 0 && es < e)
|
||||
return es;
|
||||
}
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
bool unit_has_cursed_item(unit * u)
|
||||
{
|
||||
item *itm = u->items;
|
||||
|
@ -973,7 +957,7 @@ int modifier)
|
|||
#ifndef NDEBUG
|
||||
const char *strcheck(const char *s, size_t maxlen)
|
||||
{
|
||||
static char buffer[16 * 1024];
|
||||
static char buffer[16 * 1024]; // FIXME: static return value
|
||||
if (strlen(s) > maxlen) {
|
||||
assert(maxlen < 16 * 1024);
|
||||
log_warning("[strcheck] String wurde auf %d Zeichen verkürzt:\n%s\n", (int)maxlen, s);
|
||||
|
@ -1137,12 +1121,13 @@ const char *igetstrtoken(const char *initstr)
|
|||
|
||||
unsigned int getuint(void)
|
||||
{
|
||||
return atoip((const char *)getstrtoken());
|
||||
const char *s = getstrtoken();
|
||||
return s ? atoip(s) : 0;
|
||||
}
|
||||
|
||||
int getint(void)
|
||||
{
|
||||
return atoi((const char *)getstrtoken());
|
||||
return atoi(getstrtoken());
|
||||
}
|
||||
|
||||
const struct race *findrace(const char *s, const struct locale *lang)
|
||||
|
@ -1172,7 +1157,7 @@ param_t findparam(const char *s, const struct locale * lang)
|
|||
{
|
||||
param_t result = NOPARAM;
|
||||
char buffer[64];
|
||||
char * str = transliterate(buffer, sizeof(buffer) - sizeof(int), s);
|
||||
char * str = s ? transliterate(buffer, sizeof(buffer) - sizeof(int), s) : 0;
|
||||
|
||||
if (str && *str) {
|
||||
int i;
|
||||
|
@ -1204,6 +1189,7 @@ param_t findparam_ex(const char *s, const struct locale * lang)
|
|||
|
||||
bool isparam(const char *s, const struct locale * lang, param_t param)
|
||||
{
|
||||
assert(s);
|
||||
if (s[0] > '@') {
|
||||
param_t p = (param == P_GEBAEUDE) ? findparam_ex(s, lang) : findparam(s, lang);
|
||||
return p == param;
|
||||
|
@ -1791,7 +1777,7 @@ void init_options_translation(const struct locale * lang) {
|
|||
}
|
||||
}
|
||||
|
||||
static void init_locale(const struct locale *lang)
|
||||
void init_locale(const struct locale *lang)
|
||||
{
|
||||
variant var;
|
||||
int i;
|
||||
|
@ -1835,9 +1821,9 @@ static void init_locale(const struct locale *lang)
|
|||
for (rc = races; rc; rc = rc->next) {
|
||||
const char *name;
|
||||
var.v = (void *)rc;
|
||||
name = LOC(lang, rc_name(rc, 1));
|
||||
name = LOC(lang, rc_name(rc, NAME_PLURAL));
|
||||
if (name) addtoken(tokens, name, var);
|
||||
name = LOC(lang, rc_name(rc, 0));
|
||||
name = LOC(lang, rc_name(rc, NAME_SINGULAR));
|
||||
if (name) addtoken(tokens, name, var);
|
||||
}
|
||||
|
||||
|
@ -1855,8 +1841,8 @@ typedef struct param {
|
|||
|
||||
int getid(void)
|
||||
{
|
||||
const char *str = (const char *)getstrtoken();
|
||||
int i = atoi36(str);
|
||||
const char *str = getstrtoken();
|
||||
int i = str ? atoi36(str) : 0;
|
||||
if (i < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -1908,7 +1894,7 @@ int check_param(const struct param *p, const char *key, const char *searchvalue)
|
|||
static const char *g_datadir;
|
||||
const char *datapath(void)
|
||||
{
|
||||
static char zText[MAX_PATH];
|
||||
static char zText[MAX_PATH]; // FIXME: static return value
|
||||
if (g_datadir)
|
||||
return g_datadir;
|
||||
return strcat(strcpy(zText, basepath()), "/data");
|
||||
|
@ -1922,7 +1908,7 @@ void set_datapath(const char *path)
|
|||
static const char *g_reportdir;
|
||||
const char *reportpath(void)
|
||||
{
|
||||
static char zText[MAX_PATH];
|
||||
static char zText[MAX_PATH]; // FIXME: static return value
|
||||
if (g_reportdir)
|
||||
return g_reportdir;
|
||||
return strcat(strcpy(zText, basepath()), "/reports");
|
||||
|
@ -2681,40 +2667,6 @@ message *movement_error(unit * u, const char *token, order * ord,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int movewhere(const unit * u, const char *token, region * r, region ** resultp)
|
||||
{
|
||||
region *r2;
|
||||
direction_t d;
|
||||
|
||||
if (*token == '\0') {
|
||||
*resultp = NULL;
|
||||
return E_MOVE_OK;
|
||||
}
|
||||
|
||||
d = get_direction(token, u->faction->locale);
|
||||
switch (d) {
|
||||
case D_PAUSE:
|
||||
*resultp = r;
|
||||
break;
|
||||
|
||||
case NODIRECTION:
|
||||
r2 = find_special_direction(r, token, u->faction->locale);
|
||||
if (r2 == NULL) {
|
||||
return E_MOVE_NOREGION;
|
||||
}
|
||||
*resultp = r2;
|
||||
break;
|
||||
|
||||
default:
|
||||
r2 = rconnect(r, d);
|
||||
if (r2 == NULL || move_blocked(u, r, r2)) {
|
||||
return E_MOVE_BLOCKED;
|
||||
}
|
||||
*resultp = r2;
|
||||
}
|
||||
return E_MOVE_OK;
|
||||
}
|
||||
|
||||
bool move_blocked(const unit * u, const region * r, const region * r2)
|
||||
{
|
||||
connection *b;
|
||||
|
@ -2793,7 +2745,6 @@ void attrib_init(void)
|
|||
at_register(&at_seenspell);
|
||||
|
||||
/* neue REGION-Attribute */
|
||||
at_register(&at_direction);
|
||||
at_register(&at_moveblock);
|
||||
at_register(&at_deathcount);
|
||||
at_register(&at_chaoscount);
|
||||
|
|
|
@ -65,9 +65,6 @@ extern "C" {
|
|||
#define PLAGUE_HEALCHANCE 0.25F /* Wahrscheinlichkeit Heilung */
|
||||
#define PLAGUE_HEALCOST 30 /* Heilkosten */
|
||||
|
||||
/* Chance of a monster attack */
|
||||
#define MONSTERATTACK 0.4F
|
||||
|
||||
/* Bewegungsweiten: */
|
||||
#define BP_WALKING 4
|
||||
#define BP_RIDING 6
|
||||
|
@ -180,6 +177,7 @@ extern "C" {
|
|||
|
||||
int distribute(int old, int new_value, int n);
|
||||
void init_locales(void);
|
||||
void init_locale(const struct locale *lang);
|
||||
|
||||
int newunitid(void);
|
||||
int forbiddenid(int id);
|
||||
|
@ -253,7 +251,6 @@ extern "C" {
|
|||
bool has_limited_skills(const struct unit *u);
|
||||
const struct race *findrace(const char *, const struct locale *);
|
||||
|
||||
int eff_stealth(const struct unit *u, const struct region *r);
|
||||
int ispresent(const struct faction *f, const struct region *r);
|
||||
|
||||
int check_option(struct faction *f, int option);
|
||||
|
@ -342,15 +339,6 @@ extern "C" {
|
|||
const struct region *dest);
|
||||
void add_income(struct unit *u, int type, int want, int qty);
|
||||
|
||||
/* movewhere error codes */
|
||||
enum {
|
||||
E_MOVE_OK = 0, /* possible to move */
|
||||
E_MOVE_NOREGION, /* no region exists in this direction */
|
||||
E_MOVE_BLOCKED /* cannot see this region, there is a blocking connection. */
|
||||
};
|
||||
int movewhere(const struct unit *u, const char *token,
|
||||
struct region *r, struct region **resultp);
|
||||
|
||||
const char *datapath(void);
|
||||
void set_datapath(const char *path);
|
||||
|
||||
|
|
|
@ -255,7 +255,7 @@ unit *addplayer(region * r, faction * f)
|
|||
u = createunit(r, f, 1, f->race);
|
||||
equip_items(&u->faction->items, get_equipment("new_faction"));
|
||||
equip_unit(u, get_equipment("first_unit"));
|
||||
sprintf(buffer, "first_%s", u_race(u)->_name[0]);
|
||||
sprintf(buffer, "first_%s", u_race(u)->_name);
|
||||
equip_unit(u, get_equipment(buffer));
|
||||
u->hp = unit_max_hp(u) * u->number;
|
||||
fset(u, UFL_ISNEW);
|
||||
|
|
|
@ -25,7 +25,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct player;
|
||||
struct alliance;
|
||||
struct item;
|
||||
struct seen_region;
|
||||
|
@ -60,7 +59,6 @@ typedef struct faction {
|
|||
struct faction *next;
|
||||
struct faction *nexthash;
|
||||
|
||||
struct player *owner;
|
||||
#ifdef SMART_INTERVALS
|
||||
struct region *first;
|
||||
struct region *last;
|
||||
|
|
56
src/kernel/faction.test.c
Normal file
56
src/kernel/faction.test.c
Normal file
|
@ -0,0 +1,56 @@
|
|||
#include <platform.h>
|
||||
#include <kernel/types.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/config.h>
|
||||
#include <util/language.h>
|
||||
#include "faction.h"
|
||||
#include <CuTest.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static void test_addfaction(CuTest *tc) {
|
||||
faction *f = 0;
|
||||
const struct race *rc = rc_get_or_create("human");
|
||||
const struct locale *lang = get_or_create_locale("en");
|
||||
|
||||
f = addfaction("test@eressea.de", "hurrdurr", rc, lang, 1234);
|
||||
CuAssertPtrNotNull(tc, f);
|
||||
CuAssertPtrNotNull(tc, f->name);
|
||||
CuAssertPtrEquals(tc, NULL, (void *)f->units);
|
||||
CuAssertPtrEquals(tc, NULL, (void *)f->next);
|
||||
CuAssertPtrEquals(tc, NULL, (void *)f->banner);
|
||||
CuAssertPtrEquals(tc, NULL, (void *)f->spellbook);
|
||||
CuAssertPtrEquals(tc, NULL, (void *)f->ursprung);
|
||||
CuAssertPtrEquals(tc, (void *)factions, (void *)f);
|
||||
CuAssertStrEquals(tc, "test@eressea.de", f->email);
|
||||
CuAssertStrEquals(tc, "hurrdurr", f->passw);
|
||||
CuAssertPtrEquals(tc, (void *)lang, (void *)f->locale);
|
||||
CuAssertIntEquals(tc, 1234, f->subscription);
|
||||
CuAssertIntEquals(tc, 0, f->flags);
|
||||
CuAssertIntEquals(tc, 0, f->age);
|
||||
CuAssertIntEquals(tc, 1, f->alive);
|
||||
CuAssertIntEquals(tc, M_GRAY, f->magiegebiet);
|
||||
CuAssertIntEquals(tc, turn, f->lastorders);
|
||||
CuAssertPtrEquals(tc, f, findfaction(f->no));
|
||||
}
|
||||
|
||||
static void test_get_monsters(CuTest *tc) {
|
||||
faction *f;
|
||||
CuAssertPtrEquals(tc, NULL, get_monsters());
|
||||
f = get_or_create_monsters();
|
||||
CuAssertPtrEquals(tc, f, get_monsters());
|
||||
CuAssertIntEquals(tc, 666, f->no);
|
||||
CuAssertStrEquals(tc, "Monster", f->name);
|
||||
free_gamedata();
|
||||
CuAssertPtrEquals(tc, NULL, get_monsters());
|
||||
f = get_or_create_monsters();
|
||||
CuAssertPtrEquals(tc, f, get_monsters());
|
||||
CuAssertIntEquals(tc, 666, f->no);
|
||||
}
|
||||
|
||||
CuSuite *get_faction_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_addfaction);
|
||||
SUITE_ADD_TEST(suite, test_get_monsters);
|
||||
return suite;
|
||||
}
|
1229
src/kernel/item.c
1229
src/kernel/item.c
File diff suppressed because it is too large
Load diff
|
@ -64,7 +64,7 @@ extern "C" {
|
|||
typedef char *(*rtype_name) (const struct resource_type * rtype, int flags);
|
||||
typedef struct resource_type {
|
||||
/* --- constants --- */
|
||||
char *_name[2]; /* wie es heißt */
|
||||
char *_name; /* wie es heißt */
|
||||
unsigned int flags;
|
||||
/* --- functions --- */
|
||||
rtype_uchange uchange;
|
||||
|
@ -254,7 +254,6 @@ extern "C" {
|
|||
|
||||
/* creation */
|
||||
resource_type *rt_get_or_create(const char *name);
|
||||
// resource_type *new_resourcetype(const char **names, const char **appearances, int flags);
|
||||
item_type *it_get_or_create(resource_type *rtype);
|
||||
extern item_type *new_itemtype(resource_type * rtype, int iflags, int weight,
|
||||
int capacity);
|
||||
|
|
|
@ -10,6 +10,38 @@
|
|||
#include <CuTest.h>
|
||||
#include <tests.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
static void test_resourcename_no_appearance(CuTest *tc) {
|
||||
const resource_type *rtype;
|
||||
|
||||
test_cleanup();
|
||||
init_resources(); // creates R_SILVER
|
||||
rtype = get_resourcetype(R_SILVER);
|
||||
assert(rtype && rtype->itype);
|
||||
assert(rtype->itype->_appearance[0] == 0);
|
||||
assert(rtype->itype->_appearance[1] == 0);
|
||||
CuAssertStrEquals(tc, "money", resourcename(rtype, 0));
|
||||
CuAssertStrEquals(tc, "money_p", resourcename(rtype, NMF_PLURAL));
|
||||
CuAssertStrEquals(tc, "money", resourcename(rtype, NMF_APPEARANCE));
|
||||
CuAssertStrEquals(tc, "money_p", resourcename(rtype, NMF_APPEARANCE|NMF_PLURAL));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_resourcename_with_appearance(CuTest *tc) {
|
||||
item_type *itype;
|
||||
|
||||
test_cleanup();
|
||||
itype = it_get_or_create(rt_get_or_create("foo"));
|
||||
assert(itype && itype->rtype);
|
||||
it_set_appearance(itype, "bar");
|
||||
CuAssertStrEquals(tc, "foo", resourcename(itype->rtype, 0));
|
||||
CuAssertStrEquals(tc, "foo_p", resourcename(itype->rtype, NMF_PLURAL));
|
||||
CuAssertStrEquals(tc, "bar", resourcename(itype->rtype, NMF_APPEARANCE));
|
||||
CuAssertStrEquals(tc, "bar_p", resourcename(itype->rtype, NMF_APPEARANCE | NMF_PLURAL));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_uchange(CuTest * tc, unit * u, const resource_type * rtype) {
|
||||
int n;
|
||||
change_resource(u, rtype, 4);
|
||||
|
@ -26,7 +58,6 @@ void test_change_item(CuTest * tc)
|
|||
unit * u;
|
||||
|
||||
test_cleanup();
|
||||
register_resources();
|
||||
init_resources();
|
||||
test_create_world();
|
||||
|
||||
|
@ -103,6 +134,8 @@ void test_findresourcetype(CuTest * tc)
|
|||
CuSuite *get_item_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_resourcename_no_appearance);
|
||||
SUITE_ADD_TEST(suite, test_resourcename_with_appearance);
|
||||
SUITE_ADD_TEST(suite, test_change_item);
|
||||
SUITE_ADD_TEST(suite, test_change_person);
|
||||
SUITE_ADD_TEST(suite, test_resource_type);
|
||||
|
|
|
@ -112,7 +112,7 @@ static void test_findrace(CuTest *tc) {
|
|||
json_config(json);
|
||||
rc = findrace("Zwerg", lang);
|
||||
CuAssertPtrNotNull(tc, rc);
|
||||
CuAssertStrEquals(tc, "dwarf", rc->_name[0]);
|
||||
CuAssertStrEquals(tc, "dwarf", rc->_name);
|
||||
}
|
||||
|
||||
static void test_items(CuTest * tc)
|
||||
|
|
|
@ -2535,8 +2535,7 @@ static castorder *cast_cmd(unit * u, order * ord)
|
|||
}
|
||||
level = eff_skill(u, SK_MAGIC, r);
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
param = findparam(s, u->faction->locale);
|
||||
/* für Syntax ' STUFE x REGION y z ' */
|
||||
|
@ -2712,7 +2711,7 @@ static castorder *cast_cmd(unit * u, order * ord)
|
|||
int p = 0, size = 2;
|
||||
for (;;) {
|
||||
s = getstrtoken();
|
||||
if (*s == 0)
|
||||
if (!s || *s == 0)
|
||||
break;
|
||||
if (p + 1 >= size) {
|
||||
size *= 2;
|
||||
|
|
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
**/
|
||||
|
||||
#ifndef H_KRNL_MOVEMENT
|
||||
#define H_KRNL_MOVEMENT
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct unit;
|
||||
struct ship;
|
||||
struct building_type;
|
||||
|
||||
/* die Zahlen sind genau äquivalent zu den race Flags */
|
||||
#define MV_CANNOTMOVE (1<<5)
|
||||
#define MV_FLY (1<<7) /* kann fliegen */
|
||||
#define MV_SWIM (1<<8) /* kann schwimmen */
|
||||
#define MV_WALK (1<<9) /* kann über Land gehen */
|
||||
|
||||
/* Die tragekapaz. ist hardcodiert mit defines, da es bis jetzt sowieso nur 2
|
||||
** objekte gibt, die etwas tragen. */
|
||||
#define SILVERWEIGHT 1
|
||||
#define SCALEWEIGHT 100 /* Faktor, um den die Anzeige von gewichten
|
||||
* * skaliert wird */
|
||||
#define HORSECAPACITY 7000
|
||||
#define WAGONCAPACITY 14000
|
||||
|
||||
#define HORSESNEEDED 2
|
||||
|
||||
/* ein mensch wiegt 10, traegt also 5, ein pferd wiegt 50, traegt also 20. ein
|
||||
** wagen wird von zwei pferden gezogen und traegt total 140, davon 40 die
|
||||
** pferde, macht nur noch 100, aber samt eigenem gewicht (40) macht also 140. */
|
||||
|
||||
int personcapacity(const struct unit *u);
|
||||
void movement(void);
|
||||
void run_to(struct unit *u, struct region *to);
|
||||
struct unit *is_guarded(struct region *r, struct unit *u, unsigned int mask);
|
||||
bool is_guard(const struct unit *u, int mask);
|
||||
int enoughsailors(const struct ship *sh, const struct region *r);
|
||||
bool canswim(struct unit *u);
|
||||
bool canfly(struct unit *u);
|
||||
struct unit *get_captain(const struct ship *sh);
|
||||
void travelthru(const struct unit *u, struct region *r);
|
||||
struct ship *move_ship(struct ship *sh, struct region *from,
|
||||
struct region *to, struct region_list *route);
|
||||
int walkingcapacity(const struct unit *u);
|
||||
void follow_unit(struct unit *u);
|
||||
bool buildingtype_exists(const struct region *r,
|
||||
const struct building_type *bt, bool working);
|
||||
struct unit *owner_buildingtyp(const struct region *r,
|
||||
const struct building_type *bt);
|
||||
|
||||
extern struct attrib_type at_speedup;
|
||||
|
||||
#define SA_HARBOUR 2
|
||||
#define SA_COAST 1
|
||||
#define SA_NO_INSECT -1
|
||||
#define SA_NO_COAST -2
|
||||
|
||||
extern int check_ship_allowed(struct ship *sh, const struct region * r);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,481 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
**/
|
||||
|
||||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include "names.h"
|
||||
|
||||
/* kernel includes */
|
||||
#include "unit.h"
|
||||
#include "region.h"
|
||||
#include "faction.h"
|
||||
#include "magic.h"
|
||||
#include "race.h"
|
||||
#include "terrain.h"
|
||||
#include "terrainid.h"
|
||||
|
||||
/* util includes */
|
||||
#include <util/base36.h>
|
||||
#include <util/bsdstring.h>
|
||||
#include <util/functions.h>
|
||||
#include <util/language.h>
|
||||
#include <util/rng.h>
|
||||
#include <util/unicode.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <wctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
const char *describe_braineater(unit * u, const struct locale *lang)
|
||||
{
|
||||
return LOC(lang, "describe_braineater");
|
||||
}
|
||||
|
||||
static const char *make_names(const char *monster, int *num_postfix,
|
||||
int pprefix, int *num_name, int *num_prefix, int ppostfix)
|
||||
{
|
||||
int uv, uu, un;
|
||||
static char name[NAMESIZE + 1];
|
||||
char zText[32];
|
||||
const char *str;
|
||||
|
||||
if (*num_prefix == 0) {
|
||||
|
||||
for (*num_prefix = 0;; ++*num_prefix) {
|
||||
sprintf(zText, "%s_prefix_%d", monster, *num_prefix);
|
||||
str = locale_getstring(default_locale, zText);
|
||||
if (str == NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
for (*num_name = 0;; ++*num_name) {
|
||||
sprintf(zText, "%s_name_%d", monster, *num_name);
|
||||
str = locale_getstring(default_locale, zText);
|
||||
if (str == NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
for (*num_postfix = 0;; ++*num_postfix) {
|
||||
sprintf(zText, "%s_postfix_%d", monster, *num_postfix);
|
||||
str = locale_getstring(default_locale, zText);
|
||||
if (str == NULL)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (*num_name == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* nur 50% aller Namen haben "Vor-Teil" */
|
||||
uv = rng_int() % (*num_prefix * pprefix);
|
||||
|
||||
uu = rng_int() % *num_name;
|
||||
|
||||
/* nur 50% aller Namen haben "Nach-Teil", wenn kein Vor-Teil */
|
||||
if (uv >= *num_prefix) {
|
||||
un = rng_int() % *num_postfix;
|
||||
} else {
|
||||
un = rng_int() % (*num_postfix * ppostfix);
|
||||
}
|
||||
|
||||
name[0] = 0;
|
||||
if (uv < *num_prefix) {
|
||||
sprintf(zText, "%s_prefix_%d", monster, uv);
|
||||
str = locale_getstring(default_locale, zText);
|
||||
if (str) {
|
||||
strcat(name, (const char *)str);
|
||||
strcat(name, " ");
|
||||
}
|
||||
}
|
||||
|
||||
sprintf(zText, "%s_name_%d", monster, uu);
|
||||
str = locale_getstring(default_locale, zText);
|
||||
if (str)
|
||||
strcat(name, (const char *)str);
|
||||
|
||||
if (un < *num_postfix) {
|
||||
sprintf(zText, "%s_postfix_%d", monster, un);
|
||||
str = locale_getstring(default_locale, zText);
|
||||
if (str) {
|
||||
strcat(name, " ");
|
||||
strcat(name, (const char *)str);
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
const char *undead_name(const unit * u)
|
||||
{
|
||||
static int num_postfix, num_name, num_prefix;
|
||||
return make_names("undead", &num_postfix, 2, &num_name, &num_prefix, 2);
|
||||
}
|
||||
|
||||
const char *skeleton_name(const unit * u)
|
||||
{
|
||||
static int num_postfix, num_name, num_prefix;
|
||||
return make_names("skeleton", &num_postfix, 5, &num_name, &num_prefix, 2);
|
||||
}
|
||||
|
||||
const char *zombie_name(const unit * u)
|
||||
{
|
||||
static int num_postfix, num_name, num_prefix;
|
||||
return make_names("zombie", &num_postfix, 5, &num_name, &num_prefix, 2);
|
||||
}
|
||||
|
||||
const char *ghoul_name(const unit * u)
|
||||
{
|
||||
static int num_postfix, num_name, num_prefix;
|
||||
return make_names("ghoul", &num_postfix, 5, &num_name, &num_prefix, 4);
|
||||
}
|
||||
|
||||
/* Drachen */
|
||||
|
||||
#define SIL1 15
|
||||
|
||||
const char *silbe1[SIL1] = {
|
||||
"Tar",
|
||||
"Ter",
|
||||
"Tor",
|
||||
"Pan",
|
||||
"Par",
|
||||
"Per",
|
||||
"Nim",
|
||||
"Nan",
|
||||
"Nun",
|
||||
"Gor",
|
||||
"For",
|
||||
"Fer",
|
||||
"Kar",
|
||||
"Kur",
|
||||
"Pen",
|
||||
};
|
||||
|
||||
#define SIL2 19
|
||||
|
||||
const char *silbe2[SIL2] = {
|
||||
"da",
|
||||
"do",
|
||||
"dil",
|
||||
"di",
|
||||
"dor",
|
||||
"dar",
|
||||
"ra",
|
||||
"ran",
|
||||
"ras",
|
||||
"ro",
|
||||
"rum",
|
||||
"rin",
|
||||
"ten",
|
||||
"tan",
|
||||
"ta",
|
||||
"tor",
|
||||
"gur",
|
||||
"ga",
|
||||
"gas",
|
||||
};
|
||||
|
||||
#define SIL3 14
|
||||
|
||||
const char *silbe3[SIL3] = {
|
||||
"gul",
|
||||
"gol",
|
||||
"dol",
|
||||
"tan",
|
||||
"tar",
|
||||
"tur",
|
||||
"sur",
|
||||
"sin",
|
||||
"kur",
|
||||
"kor",
|
||||
"kar",
|
||||
"dul",
|
||||
"dol",
|
||||
"bus",
|
||||
};
|
||||
|
||||
const char *generic_name(const unit * u)
|
||||
{
|
||||
if (u->no == 1) {
|
||||
return LOC(u->faction->locale, mkname("race", u_race(u)->_name[0]));
|
||||
}
|
||||
return LOC(u->faction->locale, mkname("race", u_race(u)->_name[1]));
|
||||
}
|
||||
|
||||
const char *dragon_name(const unit * u)
|
||||
{
|
||||
static char name[NAMESIZE + 1];
|
||||
int rnd, ter = 0;
|
||||
int anzahl = 1;
|
||||
static int num_postfix;
|
||||
char zText[32];
|
||||
const char *str;
|
||||
|
||||
if (num_postfix == 0) {
|
||||
for (num_postfix = 0;; ++num_postfix) {
|
||||
sprintf(zText, "dragon_postfix_%d", num_postfix);
|
||||
str = locale_getstring(default_locale, zText);
|
||||
if (str == NULL)
|
||||
break;
|
||||
}
|
||||
if (num_postfix == 0)
|
||||
num_postfix = -1;
|
||||
}
|
||||
if (num_postfix <= 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (u) {
|
||||
region *r = u->region;
|
||||
anzahl = u->number;
|
||||
switch (rterrain(r)) {
|
||||
case T_PLAIN:
|
||||
ter = 1;
|
||||
break;
|
||||
case T_MOUNTAIN:
|
||||
ter = 2;
|
||||
break;
|
||||
case T_DESERT:
|
||||
ter = 3;
|
||||
break;
|
||||
case T_SWAMP:
|
||||
ter = 4;
|
||||
break;
|
||||
case T_GLACIER:
|
||||
ter = 5;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
rnd = num_postfix / 6;
|
||||
rnd = (rng_int() % rnd) + ter * rnd;
|
||||
|
||||
sprintf(zText, "dragon_postfix_%d", rnd);
|
||||
|
||||
str = locale_getstring(default_locale, zText);
|
||||
assert(str != NULL);
|
||||
|
||||
if (anzahl > 1) {
|
||||
const char *no_article = strchr((const char *)str, ' ');
|
||||
assert(no_article);
|
||||
/* TODO: GERMAN */
|
||||
sprintf(name, "Die %sn von %s", no_article+1, rname(u->region,
|
||||
default_locale));
|
||||
} else {
|
||||
char n[32];
|
||||
|
||||
strcpy(n, silbe1[rng_int() % SIL1]);
|
||||
strcat(n, silbe2[rng_int() % SIL2]);
|
||||
strcat(n, silbe3[rng_int() % SIL3]);
|
||||
if (rng_int() % 5 > 2) {
|
||||
sprintf(name, "%s, %s", n, str); /* "Name, der Titel" */
|
||||
} else {
|
||||
strcpy(name, (const char *)str); /* "Der Titel Name" */
|
||||
name[0] = (char)toupper(name[0]); /* TODO: UNICODE - should use towupper() */
|
||||
strcat(name, " ");
|
||||
strcat(name, n);
|
||||
}
|
||||
if (u && (rng_int() % 3 == 0)) {
|
||||
strcat(name, " von ");
|
||||
strcat(name, (const char *)rname(u->region, default_locale));
|
||||
}
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
/* Dracoide */
|
||||
|
||||
#define DRAC_PRE 13
|
||||
static const char *drac_pre[DRAC_PRE] = {
|
||||
"Siss",
|
||||
"Xxaa",
|
||||
"Shht",
|
||||
"X'xixi",
|
||||
"Xar",
|
||||
"X'zish",
|
||||
"X",
|
||||
"Sh",
|
||||
"R",
|
||||
"Z",
|
||||
"Y",
|
||||
"L",
|
||||
"Ck",
|
||||
};
|
||||
|
||||
#define DRAC_MID 12
|
||||
static const char *drac_mid[DRAC_MID] = {
|
||||
"siss",
|
||||
"xxaa",
|
||||
"shht",
|
||||
"xxi",
|
||||
"xar",
|
||||
"x'zish",
|
||||
"x",
|
||||
"sh",
|
||||
"r",
|
||||
"z'ck",
|
||||
"y",
|
||||
"rl"
|
||||
};
|
||||
|
||||
#define DRAC_SUF 10
|
||||
static const char *drac_suf[DRAC_SUF] = {
|
||||
"xil",
|
||||
"shh",
|
||||
"s",
|
||||
"x",
|
||||
"arr",
|
||||
"lll",
|
||||
"lll",
|
||||
"shack",
|
||||
"ck",
|
||||
"k"
|
||||
};
|
||||
|
||||
const char *dracoid_name(const unit * u)
|
||||
{
|
||||
static char name[NAMESIZE + 1];
|
||||
int mid_syllabels;
|
||||
|
||||
u = u;
|
||||
/* Wieviele Mittelteile? */
|
||||
|
||||
mid_syllabels = rng_int() % 4;
|
||||
|
||||
strcpy(name, drac_pre[rng_int() % DRAC_PRE]);
|
||||
while (mid_syllabels > 0) {
|
||||
mid_syllabels--;
|
||||
if (rng_int() % 10 < 4)
|
||||
strcat(name, "'");
|
||||
strcat(name, drac_mid[rng_int() % DRAC_MID]);
|
||||
}
|
||||
strcat(name, drac_suf[rng_int() % DRAC_SUF]);
|
||||
return name;
|
||||
}
|
||||
|
||||
/** returns an abbreviation of a string.
|
||||
* TODO: buflen is being ignored */
|
||||
|
||||
const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars)
|
||||
{
|
||||
const char *p = s;
|
||||
char *bufp;
|
||||
unsigned int c = 0;
|
||||
size_t bpt, i;
|
||||
ucs4_t ucs;
|
||||
size_t size;
|
||||
int result;
|
||||
|
||||
/* Prüfen, ob Kurz genug */
|
||||
|
||||
if (strlen(s) <= maxchars) {
|
||||
return s;
|
||||
}
|
||||
/* Anzahl der Wörter feststellen */
|
||||
|
||||
while (*p != 0) {
|
||||
|
||||
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
||||
|
||||
/* Leerzeichen überspringen */
|
||||
while (*p != 0 && !iswalnum((wint_t) ucs)) {
|
||||
p += size;
|
||||
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
||||
}
|
||||
|
||||
/* Counter erhöhen */
|
||||
if (*p != 0)
|
||||
++c;
|
||||
|
||||
/* alnums überspringen */
|
||||
while (*p != 0 && iswalnum((wint_t) ucs)) {
|
||||
p += size;
|
||||
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
||||
}
|
||||
}
|
||||
|
||||
/* Buchstaben pro Teilkürzel = _max(1,max/AnzWort) */
|
||||
|
||||
bpt = _max(1, maxchars / c);
|
||||
|
||||
/* Einzelne Wörter anspringen und jeweils die ersten BpT kopieren */
|
||||
|
||||
p = s;
|
||||
c = 0;
|
||||
bufp = buf;
|
||||
|
||||
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
||||
|
||||
while (*p != 0 && c < maxchars) {
|
||||
/* Leerzeichen überspringen */
|
||||
|
||||
while (*p != 0 && !iswalnum((wint_t) ucs)) {
|
||||
p += size;
|
||||
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
||||
}
|
||||
|
||||
/* alnums übertragen */
|
||||
|
||||
for (i = 0; i < bpt && *p != 0 && iswalnum((wint_t) ucs); ++i) {
|
||||
memcpy(bufp, p, size);
|
||||
p += size;
|
||||
bufp += size;
|
||||
++c;
|
||||
|
||||
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
||||
}
|
||||
|
||||
/* Bis zum nächsten Leerzeichen */
|
||||
|
||||
while (c < maxchars && *p != 0 && iswalnum((wint_t) ucs)) {
|
||||
p += size;
|
||||
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
||||
}
|
||||
}
|
||||
|
||||
*bufp = 0;
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
void register_names(void)
|
||||
{
|
||||
register_function((pf_generic) describe_braineater, "describe_braineater");
|
||||
/* function name
|
||||
* generate a name for a nonplayerunit
|
||||
* race->generate_name() */
|
||||
register_function((pf_generic) undead_name, "nameundead");
|
||||
register_function((pf_generic) skeleton_name, "nameskeleton");
|
||||
register_function((pf_generic) zombie_name, "namezombie");
|
||||
register_function((pf_generic) ghoul_name, "nameghoul");
|
||||
register_function((pf_generic) dragon_name, "namedragon");
|
||||
register_function((pf_generic) dracoid_name, "namedracoid");
|
||||
register_function((pf_generic) generic_name, "namegeneric");
|
||||
}
|
|
@ -256,6 +256,11 @@ static order *create_order_i(keyword_t kwd, const char *sptr, int persistent,
|
|||
order *ord = NULL;
|
||||
int lindex;
|
||||
|
||||
if ((int)kwd>0 && keyword_disabled(kwd)) {
|
||||
log_error("trying to create an order for disabled keyword %s.", keyword(kwd));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* if this is just nonsense, then we skip it. */
|
||||
if (lomem) {
|
||||
switch (kwd) {
|
||||
|
@ -290,6 +295,7 @@ order *create_order(keyword_t kwd, const struct locale * lang,
|
|||
const char *params, ...)
|
||||
{
|
||||
char zBuffer[DISPLAYSIZE];
|
||||
assert(lang);
|
||||
if (params) {
|
||||
char *bufp = zBuffer;
|
||||
int bytes;
|
||||
|
@ -351,17 +357,21 @@ order *parse_order(const char *s, const struct locale * lang)
|
|||
keyword_t kwd;
|
||||
const char *sptr;
|
||||
int persistent = 0;
|
||||
const char * p;
|
||||
|
||||
while (*s == '@') {
|
||||
persistent = 1;
|
||||
++s;
|
||||
}
|
||||
sptr = s;
|
||||
kwd = get_keyword(parse_token(&sptr), lang);
|
||||
p = *sptr ? parse_token(&sptr) : 0;
|
||||
kwd = p ? get_keyword(p, lang) : NOKEYWORD;
|
||||
if (kwd == K_MAKE) {
|
||||
const char *s = parse_token(&sptr);
|
||||
if (isparam(s, lang, P_TEMP)) {
|
||||
const char *s, *sp = sptr;
|
||||
s = parse_token(&sp);
|
||||
if (s && isparam(s, lang, P_TEMP)) {
|
||||
kwd = K_MAKETEMP;
|
||||
sptr = sp;
|
||||
}
|
||||
}
|
||||
if (kwd != NOKEYWORD) {
|
||||
|
@ -534,7 +544,8 @@ char *write_order(const order * ord, char *buffer, size_t size)
|
|||
keyword_t kwd = ORD_KEYWORD(ord);
|
||||
if (kwd == NOKEYWORD) {
|
||||
const char *text = ORD_STRING(ord);
|
||||
strlcpy(buffer, (const char *)text, size);
|
||||
if (text) strlcpy(buffer, (const char *)text, size);
|
||||
else buffer[0] = 0;
|
||||
}
|
||||
else {
|
||||
get_command(ord, buffer, size);
|
||||
|
@ -550,14 +561,11 @@ void push_order(order ** ordp, order * ord)
|
|||
*ordp = ord;
|
||||
}
|
||||
|
||||
static char *getcommand(const order * ord)
|
||||
keyword_t init_order(const struct order *ord)
|
||||
{
|
||||
char cmd[ORDERSIZE];
|
||||
return _strdup(get_command(ord, cmd, sizeof(cmd)));
|
||||
}
|
||||
char *cmd = 0;
|
||||
|
||||
void init_tokens(const struct order *ord)
|
||||
{
|
||||
char *cmd = getcommand(ord);
|
||||
if (ord->data->_str) cmd = _strdup(ord->data->_str);
|
||||
init_tokens_str(cmd, cmd);
|
||||
return ord->data->_keyword;
|
||||
}
|
||||
|
|
|
@ -58,8 +58,8 @@ extern "C" {
|
|||
bool is_repeated(const order * ord);
|
||||
bool is_long(const order * ord);
|
||||
|
||||
extern char *write_order(const order * ord, char *buffer, size_t size);
|
||||
extern void init_tokens(const struct order *ord); /* initialize token parsing */
|
||||
char *write_order(const order * ord, char *buffer, size_t size);
|
||||
keyword_t init_order(const struct order *ord);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#include <platform.h>
|
||||
#include <config.h>
|
||||
#include <kernel/config.h>
|
||||
#include "order.h"
|
||||
|
||||
#include <util/parser.h>
|
||||
|
@ -6,6 +8,7 @@
|
|||
|
||||
#include <CuTest.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static void test_create_order(CuTest *tc) {
|
||||
char cmd[32];
|
||||
|
@ -16,9 +19,9 @@ static void test_create_order(CuTest *tc) {
|
|||
ord = create_order(K_MOVE, lang, "NORTH");
|
||||
CuAssertPtrNotNull(tc, ord);
|
||||
CuAssertIntEquals(tc, K_MOVE, getkeyword(ord));
|
||||
init_tokens(ord);
|
||||
CuAssertStrEquals(tc, "MOVE NORTH", get_command(ord, cmd, sizeof(cmd)));
|
||||
CuAssertStrEquals(tc, "MOVE", getstrtoken());
|
||||
|
||||
CuAssertIntEquals(tc, K_MOVE, init_order(ord));
|
||||
CuAssertStrEquals(tc, "NORTH", getstrtoken());
|
||||
free_order(ord);
|
||||
}
|
||||
|
@ -32,17 +35,110 @@ static void test_parse_order(CuTest *tc) {
|
|||
ord = parse_order("MOVE NORTH", lang);
|
||||
CuAssertPtrNotNull(tc, ord);
|
||||
CuAssertIntEquals(tc, K_MOVE, getkeyword(ord));
|
||||
init_tokens(ord);
|
||||
CuAssertStrEquals(tc, "MOVE NORTH", get_command(ord, cmd, sizeof(cmd)));
|
||||
CuAssertStrEquals(tc, "MOVE", getstrtoken());
|
||||
|
||||
CuAssertIntEquals(tc, K_MOVE, init_order(ord));
|
||||
CuAssertStrEquals(tc, "NORTH", getstrtoken());
|
||||
free_order(ord);
|
||||
}
|
||||
|
||||
static void test_parse_make(CuTest *tc) {
|
||||
char cmd[32];
|
||||
order *ord;
|
||||
struct locale * lang = get_or_create_locale("en");
|
||||
|
||||
locale_setstring(lang, keyword(K_MAKE), "MAKE");
|
||||
locale_setstring(lang, keyword(K_MAKETEMP), "MAKETEMP");
|
||||
init_locale(lang);
|
||||
ord = parse_order("M hurrdurr", lang);
|
||||
CuAssertPtrNotNull(tc, ord);
|
||||
CuAssertIntEquals(tc, K_MAKE, getkeyword(ord));
|
||||
CuAssertStrEquals(tc, "MAKE hurrdurr", get_command(ord, cmd, sizeof(cmd)));
|
||||
|
||||
CuAssertIntEquals(tc, K_MAKE, init_order(ord));
|
||||
CuAssertStrEquals(tc, "hurrdurr", getstrtoken());
|
||||
free_order(ord);
|
||||
}
|
||||
|
||||
static void test_parse_make_temp(CuTest *tc) {
|
||||
char cmd[32];
|
||||
order *ord;
|
||||
struct locale * lang = get_or_create_locale("en");
|
||||
|
||||
locale_setstring(lang, keyword(K_MAKE), "MAKE");
|
||||
locale_setstring(lang, keyword(K_MAKETEMP), "MAKETEMP");
|
||||
locale_setstring(lang, "TEMP", "TEMP");
|
||||
init_locale(lang);
|
||||
|
||||
ord = parse_order("M T herp", lang);
|
||||
CuAssertPtrNotNull(tc, ord);
|
||||
CuAssertIntEquals(tc, K_MAKETEMP, getkeyword(ord));
|
||||
CuAssertStrEquals(tc, "MAKETEMP herp", get_command(ord, cmd, sizeof(cmd)));
|
||||
|
||||
CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord));
|
||||
CuAssertStrEquals(tc, "herp", getstrtoken());
|
||||
free_order(ord);
|
||||
}
|
||||
|
||||
static void test_parse_maketemp(CuTest *tc) {
|
||||
char cmd[32];
|
||||
order *ord;
|
||||
struct locale * lang = get_or_create_locale("en");
|
||||
|
||||
locale_setstring(lang, keyword(K_MAKE), "MAKE");
|
||||
locale_setstring(lang, keyword(K_MAKETEMP), "MAKETEMP");
|
||||
locale_setstring(lang, "TEMP", "TEMP");
|
||||
init_locale(lang);
|
||||
|
||||
ord = parse_order("MAKET herp", lang);
|
||||
CuAssertPtrNotNull(tc, ord);
|
||||
CuAssertStrEquals(tc, "MAKETEMP herp", get_command(ord, cmd, sizeof(cmd)));
|
||||
CuAssertIntEquals(tc, K_MAKETEMP, getkeyword(ord));
|
||||
CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord));
|
||||
CuAssertStrEquals(tc, "herp", getstrtoken());
|
||||
free_order(ord);
|
||||
}
|
||||
|
||||
static void test_init_order(CuTest *tc) {
|
||||
order *ord;
|
||||
struct locale * lang = get_or_create_locale("en");
|
||||
|
||||
ord = create_order(K_MAKETEMP, lang, "hurr durr");
|
||||
CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord));
|
||||
CuAssertStrEquals(tc, "hurr", getstrtoken());
|
||||
CuAssertStrEquals(tc, "durr", getstrtoken());
|
||||
}
|
||||
|
||||
static void test_getstrtoken(CuTest *tc) {
|
||||
char *cmd = _strdup("hurr \"durr\" \"\" \'\'");
|
||||
init_tokens_str(cmd, cmd);
|
||||
CuAssertStrEquals(tc, "hurr", getstrtoken());
|
||||
CuAssertStrEquals(tc, "durr", getstrtoken());
|
||||
CuAssertStrEquals(tc, "", getstrtoken());
|
||||
CuAssertStrEquals(tc, "", getstrtoken());
|
||||
CuAssertStrEquals(tc, 0, getstrtoken());
|
||||
init_tokens_str(0, 0);
|
||||
CuAssertStrEquals(tc, 0, getstrtoken());
|
||||
}
|
||||
|
||||
static void test_skip_token(CuTest *tc) {
|
||||
char *cmd = _strdup("hurr \"durr\"");
|
||||
init_tokens_str(cmd, cmd);
|
||||
skip_token();
|
||||
CuAssertStrEquals(tc, "durr", getstrtoken());
|
||||
CuAssertStrEquals(tc, 0, getstrtoken());
|
||||
}
|
||||
|
||||
CuSuite *get_order_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_create_order);
|
||||
SUITE_ADD_TEST(suite, test_parse_order);
|
||||
SUITE_ADD_TEST(suite, test_parse_make);
|
||||
SUITE_ADD_TEST(suite, test_parse_make_temp);
|
||||
SUITE_ADD_TEST(suite, test_parse_maketemp);
|
||||
SUITE_ADD_TEST(suite, test_init_order);
|
||||
SUITE_ADD_TEST(suite, test_skip_token);
|
||||
SUITE_ADD_TEST(suite, test_getstrtoken);
|
||||
return suite;
|
||||
}
|
||||
|
|
|
@ -1,103 +0,0 @@
|
|||
/* vi: set ts=2:
|
||||
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
|
||||
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
|
||||
+-------------------+ Stefan Reich <reich@halbling.de>
|
||||
|
||||
This program may not be used, modified or distributed
|
||||
without prior permission by the authors of Eressea.
|
||||
|
||||
*/
|
||||
#include <platform.h>
|
||||
#include "player.h"
|
||||
|
||||
#include <util/goodies.h>
|
||||
#include <util/rng.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
#define PMAXHASH 1021
|
||||
|
||||
typedef struct player_hash {
|
||||
struct player *entries;
|
||||
} player_hash;
|
||||
|
||||
static player_hash *players[PMAXHASH];
|
||||
|
||||
player *make_player(const struct faction *f)
|
||||
{
|
||||
player *p = calloc(sizeof(player), 1);
|
||||
unsigned int hash;
|
||||
|
||||
for (p->id = rng_int();; p->id++) {
|
||||
/* if there is a hashing conflict, resolve it */
|
||||
player *pi = get_player(p->id);
|
||||
if (pi)
|
||||
p->id++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
hash = p->id % PMAXHASH;
|
||||
p->faction = f;
|
||||
p->nexthash = players[hash]->entries;
|
||||
players[hash]->entries = p;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
player *next_player(player * p)
|
||||
{
|
||||
if (p->nexthash)
|
||||
return p->nexthash;
|
||||
else {
|
||||
unsigned int hash = p->id % PMAXHASH;
|
||||
p = NULL;
|
||||
while (++hash != PMAXHASH) {
|
||||
if (players[hash]->entries != NULL) {
|
||||
p = players[hash]->entries;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
player *get_player(unsigned int id)
|
||||
{
|
||||
unsigned int hash = id % PMAXHASH;
|
||||
struct player *p = players[hash]->entries;
|
||||
|
||||
while (p && p->id != id)
|
||||
p = p->nexthash;
|
||||
return p;
|
||||
}
|
||||
|
||||
player *get_players(void)
|
||||
{
|
||||
struct player *p = NULL;
|
||||
unsigned int hash = 0;
|
||||
|
||||
while (p != NULL && hash != PMAXHASH) {
|
||||
p = players[hash++]->entries;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
void players_done(void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i != PMAXHASH; ++i) {
|
||||
player *p = players[i]->entries;
|
||||
players[i]->entries = p->nexthash;
|
||||
free(p->name);
|
||||
if (p->email)
|
||||
free(p->email);
|
||||
if (p->name)
|
||||
free(p->name);
|
||||
free(p);
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
/* vi: set ts=2:
|
||||
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
|
||||
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
|
||||
+-------------------+ Stefan Reich <reich@halbling.de>
|
||||
|
||||
This program may not be used, modified or distributed
|
||||
without prior permission by the authors of Eressea.
|
||||
|
||||
*/
|
||||
#ifndef H_KRNL_PLAYER
|
||||
#define H_KRNL_PLAYER
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct faction;
|
||||
|
||||
typedef struct player {
|
||||
unsigned int id;
|
||||
char *name;
|
||||
char *email;
|
||||
char *address;
|
||||
struct vacation {
|
||||
int weeks;
|
||||
char *email;
|
||||
} *vacation;
|
||||
const struct faction *faction;
|
||||
|
||||
struct player *nexthash; /* don't use! */
|
||||
} player;
|
||||
|
||||
extern struct player *get_players(void);
|
||||
extern struct player *get_player(unsigned int id);
|
||||
extern struct player *make_player(const struct faction *f);
|
||||
extern struct player *next_player(struct player *p);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
|
@ -39,212 +39,216 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
int get_resource(const unit * u, const resource_type * rtype)
|
||||
{
|
||||
assert(rtype);
|
||||
if (rtype->uget) {
|
||||
/* this resource is probably special */
|
||||
int i = rtype->uget(u, rtype);
|
||||
if (i >= 0)
|
||||
return i;
|
||||
}
|
||||
else if (rtype->uchange) {
|
||||
/* this resource is probably special */
|
||||
int i = rtype->uchange((unit *)u, rtype, 0);
|
||||
if (i >= 0)
|
||||
return i;
|
||||
}
|
||||
if (rtype->itype) {
|
||||
if (rtype == get_resourcetype(R_STONE) && (u_race(u)->flags & RCF_STONEGOLEM)) {
|
||||
return u->number * GOLEM_STONE;
|
||||
} else if (rtype == get_resourcetype(R_IRON) && (u_race(u)->flags & RCF_IRONGOLEM)) {
|
||||
return u->number * GOLEM_IRON;
|
||||
} else {
|
||||
return i_get(u->items, rtype->itype);
|
||||
assert(rtype);
|
||||
if (rtype->uget) {
|
||||
/* this resource is probably special */
|
||||
int i = rtype->uget(u, rtype);
|
||||
if (i >= 0)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
if (rtype == get_resourcetype(R_AURA))
|
||||
return get_spellpoints(u);
|
||||
if (rtype == get_resourcetype(R_PERMAURA))
|
||||
return max_spellpoints(u->region, u);
|
||||
log_error("trying to get unknown resource '%s'.\n", rtype->_name[0]);
|
||||
return 0;
|
||||
else if (rtype->uchange) {
|
||||
/* this resource is probably special */
|
||||
int i = rtype->uchange((unit *)u, rtype, 0);
|
||||
if (i >= 0)
|
||||
return i;
|
||||
}
|
||||
if (rtype->itype) {
|
||||
return i_get(u->items, rtype->itype);
|
||||
}
|
||||
if (rtype == get_resourcetype(R_AURA)) {
|
||||
return get_spellpoints(u);
|
||||
}
|
||||
if (rtype == get_resourcetype(R_PERMAURA)) {
|
||||
return max_spellpoints(u->region, u);
|
||||
}
|
||||
log_error("trying to get unknown resource '%s'.\n", rtype->_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int change_resource(unit * u, const resource_type * rtype, int change)
|
||||
{
|
||||
int i = 0;
|
||||
int i = 0;
|
||||
|
||||
if (rtype->uchange)
|
||||
i = rtype->uchange(u, rtype, change);
|
||||
else if (rtype == get_resourcetype(R_AURA))
|
||||
i = change_spellpoints(u, change);
|
||||
else if (rtype == get_resourcetype(R_PERMAURA))
|
||||
i = change_maxspellpoints(u, change);
|
||||
else
|
||||
assert(!"undefined resource detected. rtype->uchange not initialized.");
|
||||
assert(i==get_resource(u, rtype));
|
||||
assert(i >= 0);
|
||||
if (i >= 100000000) {
|
||||
log_warning("%s has %d %s\n", unitname(u), i, rtype->_name[0]);
|
||||
}
|
||||
return i;
|
||||
if (rtype->uchange)
|
||||
i = rtype->uchange(u, rtype, change);
|
||||
else if (rtype == get_resourcetype(R_AURA))
|
||||
i = change_spellpoints(u, change);
|
||||
else if (rtype == get_resourcetype(R_PERMAURA))
|
||||
i = change_maxspellpoints(u, change);
|
||||
else
|
||||
assert(!"undefined resource detected. rtype->uchange not initialized.");
|
||||
assert(i == get_resource(u, rtype));
|
||||
assert(i >= 0);
|
||||
if (i >= 100000000) {
|
||||
log_warning("%s has %d %s\n", unitname(u), i, rtype->_name);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
int get_reservation(const unit * u, const resource_type * rtype)
|
||||
{
|
||||
reservation *res = u->reservations;
|
||||
reservation *res = u->reservations;
|
||||
|
||||
if (rtype == get_resourcetype(R_STONE) && (u_race(u)->flags & RCF_STONEGOLEM))
|
||||
return (u->number * GOLEM_STONE);
|
||||
if (rtype == get_resourcetype(R_IRON) && (u_race(u)->flags & RCF_IRONGOLEM))
|
||||
return (u->number * GOLEM_IRON);
|
||||
while (res && res->type != rtype)
|
||||
res = res->next;
|
||||
if (res)
|
||||
return res->value;
|
||||
return 0;
|
||||
if (rtype == get_resourcetype(R_STONE) && (u_race(u)->flags & RCF_STONEGOLEM))
|
||||
return (u->number * GOLEM_STONE);
|
||||
if (rtype == get_resourcetype(R_IRON) && (u_race(u)->flags & RCF_IRONGOLEM))
|
||||
return (u->number * GOLEM_IRON);
|
||||
while (res && res->type != rtype)
|
||||
res = res->next;
|
||||
if (res)
|
||||
return res->value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int change_reservation(unit * u, const resource_type * rtype, int value)
|
||||
{
|
||||
reservation *res, **rp = &u->reservations;
|
||||
reservation *res, **rp = &u->reservations;
|
||||
|
||||
if (!value)
|
||||
return 0;
|
||||
if (!value)
|
||||
return 0;
|
||||
|
||||
while (*rp && (*rp)->type != rtype)
|
||||
rp = &(*rp)->next;
|
||||
res = *rp;
|
||||
if (!res) {
|
||||
*rp = res = calloc(sizeof(reservation), 1);
|
||||
res->type = rtype;
|
||||
res->value = value;
|
||||
} else if (res && res->value + value <= 0) {
|
||||
*rp = res->next;
|
||||
free(res);
|
||||
return 0;
|
||||
} else {
|
||||
res->value += value;
|
||||
}
|
||||
return res->value;
|
||||
while (*rp && (*rp)->type != rtype)
|
||||
rp = &(*rp)->next;
|
||||
res = *rp;
|
||||
if (!res) {
|
||||
*rp = res = calloc(sizeof(reservation), 1);
|
||||
res->type = rtype;
|
||||
res->value = value;
|
||||
}
|
||||
else if (res && res->value + value <= 0) {
|
||||
*rp = res->next;
|
||||
free(res);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
res->value += value;
|
||||
}
|
||||
return res->value;
|
||||
}
|
||||
|
||||
int set_resvalue(unit * u, const resource_type * rtype, int value)
|
||||
{
|
||||
reservation *res, **rp = &u->reservations;
|
||||
reservation *res, **rp = &u->reservations;
|
||||
|
||||
while (*rp && (*rp)->type != rtype)
|
||||
rp = &(*rp)->next;
|
||||
res = *rp;
|
||||
if (!res) {
|
||||
if (!value)
|
||||
return 0;
|
||||
*rp = res = calloc(sizeof(reservation), 1);
|
||||
res->type = rtype;
|
||||
res->value = value;
|
||||
} else if (res && value <= 0) {
|
||||
*rp = res->next;
|
||||
free(res);
|
||||
return 0;
|
||||
} else {
|
||||
res->value = value;
|
||||
}
|
||||
return res->value;
|
||||
while (*rp && (*rp)->type != rtype)
|
||||
rp = &(*rp)->next;
|
||||
res = *rp;
|
||||
if (!res) {
|
||||
if (!value)
|
||||
return 0;
|
||||
*rp = res = calloc(sizeof(reservation), 1);
|
||||
res->type = rtype;
|
||||
res->value = value;
|
||||
}
|
||||
else if (res && value <= 0) {
|
||||
*rp = res->next;
|
||||
free(res);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
res->value = value;
|
||||
}
|
||||
return res->value;
|
||||
}
|
||||
|
||||
int
|
||||
get_pooled(const unit * u, const resource_type * rtype, unsigned int mode,
|
||||
int count)
|
||||
int count)
|
||||
{
|
||||
const faction *f = u->faction;
|
||||
unit *v;
|
||||
int use = 0;
|
||||
region *r = u->region;
|
||||
int have = get_resource(u, rtype);
|
||||
const faction *f = u->faction;
|
||||
unit *v;
|
||||
int use = 0;
|
||||
region *r = u->region;
|
||||
int have = get_resource(u, rtype);
|
||||
|
||||
if ((u_race(u)->ec_flags & GETITEM) == 0) {
|
||||
mode &= (GET_SLACK | GET_RESERVE);
|
||||
}
|
||||
if ((u_race(u)->ec_flags & GETITEM) == 0) {
|
||||
mode &= (GET_SLACK | GET_RESERVE);
|
||||
}
|
||||
|
||||
if ((mode & GET_SLACK) && (mode & GET_RESERVE))
|
||||
use = have;
|
||||
else {
|
||||
int reserve = get_reservation(u, rtype);
|
||||
int slack = _max(0, have - reserve);
|
||||
if (mode & GET_RESERVE)
|
||||
use = have - slack;
|
||||
else if (mode & GET_SLACK)
|
||||
use = slack;
|
||||
}
|
||||
if (rtype->flags & RTF_POOLED && mode & ~(GET_SLACK | GET_RESERVE)) {
|
||||
for (v = r->units; v && use < count; v = v->next)
|
||||
if (u != v) {
|
||||
int mask;
|
||||
if ((mode & GET_SLACK) && (mode & GET_RESERVE))
|
||||
use = have;
|
||||
else {
|
||||
int reserve = get_reservation(u, rtype);
|
||||
int slack = _max(0, have - reserve);
|
||||
if (mode & GET_RESERVE)
|
||||
use = have - slack;
|
||||
else if (mode & GET_SLACK)
|
||||
use = slack;
|
||||
}
|
||||
if (rtype->flags & RTF_POOLED && mode & ~(GET_SLACK | GET_RESERVE)) {
|
||||
for (v = r->units; v && use < count; v = v->next)
|
||||
if (u != v) {
|
||||
int mask;
|
||||
|
||||
if (v->items == NULL && rtype->uget == NULL)
|
||||
continue;
|
||||
if ((urace(v)->ec_flags & GIVEITEM) == 0)
|
||||
continue;
|
||||
if (v->items == NULL && rtype->uget == NULL)
|
||||
continue;
|
||||
if ((urace(v)->ec_flags & GIVEITEM) == 0)
|
||||
continue;
|
||||
|
||||
if (v->faction == f) {
|
||||
mask = (mode >> 3) & (GET_SLACK | GET_RESERVE);
|
||||
} else if (alliedunit(v, f, HELP_MONEY))
|
||||
mask = (mode >> 6) & (GET_SLACK | GET_RESERVE);
|
||||
else
|
||||
continue;
|
||||
use += get_pooled(v, rtype, mask, count - use);
|
||||
}
|
||||
}
|
||||
return use;
|
||||
if (v->faction == f) {
|
||||
mask = (mode >> 3) & (GET_SLACK | GET_RESERVE);
|
||||
}
|
||||
else if (alliedunit(v, f, HELP_MONEY))
|
||||
mask = (mode >> 6) & (GET_SLACK | GET_RESERVE);
|
||||
else
|
||||
continue;
|
||||
use += get_pooled(v, rtype, mask, count - use);
|
||||
}
|
||||
}
|
||||
return use;
|
||||
}
|
||||
|
||||
int
|
||||
use_pooled(unit * u, const resource_type * rtype, unsigned int mode, int count)
|
||||
{
|
||||
const faction *f = u->faction;
|
||||
unit *v;
|
||||
int use = count;
|
||||
region *r = u->region;
|
||||
int n = 0, have = get_resource(u, rtype);
|
||||
const faction *f = u->faction;
|
||||
unit *v;
|
||||
int use = count;
|
||||
region *r = u->region;
|
||||
int n = 0, have = get_resource(u, rtype);
|
||||
|
||||
if ((u_race(u)->ec_flags & GETITEM) == 0) {
|
||||
mode &= (GET_SLACK | GET_RESERVE);
|
||||
}
|
||||
|
||||
if ((mode & GET_SLACK) && (mode & GET_RESERVE)) {
|
||||
n = _min(use, have);
|
||||
} else {
|
||||
int reserve = get_reservation(u, rtype);
|
||||
int slack = _max(0, have - reserve);
|
||||
if (mode & GET_RESERVE) {
|
||||
n = have - slack;
|
||||
n = _min(use, n);
|
||||
change_reservation(u, rtype, -n);
|
||||
} else if (mode & GET_SLACK) {
|
||||
n = _min(use, slack);
|
||||
if ((u_race(u)->ec_flags & GETITEM) == 0) {
|
||||
mode &= (GET_SLACK | GET_RESERVE);
|
||||
}
|
||||
}
|
||||
if (n > 0) {
|
||||
change_resource(u, rtype, -n);
|
||||
use -= n;
|
||||
}
|
||||
|
||||
if (rtype->flags & RTF_POOLED && mode & ~(GET_SLACK | GET_RESERVE)) {
|
||||
for (v = r->units; use > 0 && v != NULL; v = v->next)
|
||||
if (u != v) {
|
||||
int mask;
|
||||
if ((urace(v)->ec_flags & GIVEITEM) == 0)
|
||||
continue;
|
||||
if (v->items == NULL && rtype->uget == NULL)
|
||||
continue;
|
||||
if ((mode & GET_SLACK) && (mode & GET_RESERVE)) {
|
||||
n = _min(use, have);
|
||||
}
|
||||
else {
|
||||
int reserve = get_reservation(u, rtype);
|
||||
int slack = _max(0, have - reserve);
|
||||
if (mode & GET_RESERVE) {
|
||||
n = have - slack;
|
||||
n = _min(use, n);
|
||||
change_reservation(u, rtype, -n);
|
||||
}
|
||||
else if (mode & GET_SLACK) {
|
||||
n = _min(use, slack);
|
||||
}
|
||||
}
|
||||
if (n > 0) {
|
||||
change_resource(u, rtype, -n);
|
||||
use -= n;
|
||||
}
|
||||
|
||||
if (v->faction == f) {
|
||||
mask = (mode >> 3) & (GET_SLACK | GET_RESERVE);
|
||||
} else if (alliedunit(v, f, HELP_MONEY))
|
||||
mask = (mode >> 6) & (GET_SLACK | GET_RESERVE);
|
||||
else
|
||||
continue;
|
||||
use -= use_pooled(v, rtype, mask, use);
|
||||
}
|
||||
}
|
||||
return count - use;
|
||||
if (rtype->flags & RTF_POOLED && mode & ~(GET_SLACK | GET_RESERVE)) {
|
||||
for (v = r->units; use > 0 && v != NULL; v = v->next)
|
||||
if (u != v) {
|
||||
int mask;
|
||||
if ((urace(v)->ec_flags & GIVEITEM) == 0)
|
||||
continue;
|
||||
if (v->items == NULL && rtype->uget == NULL)
|
||||
continue;
|
||||
|
||||
if (v->faction == f) {
|
||||
mask = (mode >> 3) & (GET_SLACK | GET_RESERVE);
|
||||
}
|
||||
else if (alliedunit(v, f, HELP_MONEY))
|
||||
mask = (mode >> 6) & (GET_SLACK | GET_RESERVE);
|
||||
else
|
||||
continue;
|
||||
use -= use_pooled(v, rtype, mask, use);
|
||||
}
|
||||
}
|
||||
return count - use;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
|
@ -82,7 +82,8 @@ static race * race_cache[MAXRACES];
|
|||
struct race *get_race(race_t rt) {
|
||||
static int cache = -1;
|
||||
const char * name;
|
||||
|
||||
race * result = 0;
|
||||
|
||||
assert(rt < MAXRACES);
|
||||
name = racenames[rt];
|
||||
if (!name) {
|
||||
|
@ -92,69 +93,69 @@ struct race *get_race(race_t rt) {
|
|||
cache = cache_breaker;
|
||||
memset(race_cache, 0, sizeof(race_cache));
|
||||
return race_cache[rt] = rc_get_or_create(name);
|
||||
} else {
|
||||
race * result = race_cache[rt];
|
||||
}
|
||||
else {
|
||||
result = race_cache[rt];
|
||||
if (!result) {
|
||||
result = race_cache[rt] = rc_get_or_create(name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
race_list *get_familiarraces(void)
|
||||
{
|
||||
static int init = 0;
|
||||
static race_list *familiarraces;
|
||||
static int init = 0;
|
||||
static race_list *familiarraces;
|
||||
|
||||
if (!init) {
|
||||
race *rc = races;
|
||||
for (; rc != NULL; rc = rc->next) {
|
||||
if (rc->init_familiar != NULL) {
|
||||
racelist_insert(&familiarraces, rc);
|
||||
}
|
||||
if (!init) {
|
||||
race *rc = races;
|
||||
for (; rc != NULL; rc = rc->next) {
|
||||
if (rc->init_familiar != NULL) {
|
||||
racelist_insert(&familiarraces, rc);
|
||||
}
|
||||
}
|
||||
init = false;
|
||||
}
|
||||
init = false;
|
||||
}
|
||||
return familiarraces;
|
||||
return familiarraces;
|
||||
}
|
||||
|
||||
void racelist_clear(struct race_list **rl)
|
||||
{
|
||||
while (*rl) {
|
||||
race_list *rl2 = (*rl)->next;
|
||||
free(*rl);
|
||||
*rl = rl2;
|
||||
}
|
||||
while (*rl) {
|
||||
race_list *rl2 = (*rl)->next;
|
||||
free(*rl);
|
||||
*rl = rl2;
|
||||
}
|
||||
}
|
||||
|
||||
void racelist_insert(struct race_list **rl, const struct race *r)
|
||||
{
|
||||
race_list *rl2 = (race_list *) malloc(sizeof(race_list));
|
||||
race_list *rl2 = (race_list *)malloc(sizeof(race_list));
|
||||
|
||||
rl2->data = r;
|
||||
rl2->next = *rl;
|
||||
rl2->data = r;
|
||||
rl2->next = *rl;
|
||||
|
||||
*rl = rl2;
|
||||
*rl = rl2;
|
||||
}
|
||||
|
||||
void free_races(void) {
|
||||
while (races) {
|
||||
race * rc = races->next;
|
||||
free(races);
|
||||
races =rc;
|
||||
races = rc;
|
||||
}
|
||||
}
|
||||
|
||||
static race *rc_find_i(const char *name)
|
||||
{
|
||||
const char *rname = name;
|
||||
race *rc = races;
|
||||
const char *rname = name;
|
||||
race *rc = races;
|
||||
|
||||
while (rc && !strcmp(rname, rc->_name[0]) == 0) {
|
||||
rc = rc->next;
|
||||
}
|
||||
return rc;
|
||||
while (rc && !strcmp(rname, rc->_name) == 0) {
|
||||
rc = rc->next;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
const race * rc_find(const char *name) {
|
||||
|
@ -168,7 +169,7 @@ race *rc_get_or_create(const char *zName)
|
|||
assert(zName);
|
||||
rc = rc_find_i(zName);
|
||||
if (!rc) {
|
||||
char zBuffer[80];
|
||||
char zBuffer[80];
|
||||
|
||||
rc = (race *)calloc(sizeof(race), 1);
|
||||
rc->hitpoints = 1;
|
||||
|
@ -177,13 +178,7 @@ race *rc_get_or_create(const char *zName)
|
|||
assert(strchr(zName, ' ') == NULL);
|
||||
}
|
||||
strcpy(zBuffer, zName);
|
||||
rc->_name[0] = _strdup(zBuffer);
|
||||
sprintf(zBuffer, "%s_p", zName);
|
||||
rc->_name[1] = _strdup(zBuffer);
|
||||
sprintf(zBuffer, "%s_d", zName);
|
||||
rc->_name[2] = _strdup(zBuffer);
|
||||
sprintf(zBuffer, "%s_x", zName);
|
||||
rc->_name[3] = _strdup(zBuffer);
|
||||
rc->_name = _strdup(zBuffer);
|
||||
rc->precombatspell = NULL;
|
||||
|
||||
rc->attack[0].type = AT_COMBATSPELL;
|
||||
|
@ -199,135 +194,147 @@ race *rc_get_or_create(const char *zName)
|
|||
/** dragon movement **/
|
||||
bool allowed_dragon(const region * src, const region * target)
|
||||
{
|
||||
if (fval(src->terrain, ARCTIC_REGION) && fval(target->terrain, SEA_REGION))
|
||||
return false;
|
||||
return allowed_fly(src, target);
|
||||
if (fval(src->terrain, ARCTIC_REGION) && fval(target->terrain, SEA_REGION))
|
||||
return false;
|
||||
return allowed_fly(src, target);
|
||||
}
|
||||
|
||||
char **race_prefixes = NULL;
|
||||
|
||||
extern void add_raceprefix(const char *prefix)
|
||||
{
|
||||
static size_t size = 4;
|
||||
static unsigned int next = 0;
|
||||
if (race_prefixes == NULL)
|
||||
race_prefixes = malloc(size * sizeof(char *));
|
||||
if (next + 1 == size) {
|
||||
size *= 2;
|
||||
race_prefixes = realloc(race_prefixes, size * sizeof(char *));
|
||||
}
|
||||
race_prefixes[next++] = _strdup(prefix);
|
||||
race_prefixes[next] = NULL;
|
||||
static size_t size = 4;
|
||||
static unsigned int next = 0;
|
||||
if (race_prefixes == NULL)
|
||||
race_prefixes = malloc(size * sizeof(char *));
|
||||
if (next + 1 == size) {
|
||||
size *= 2;
|
||||
race_prefixes = realloc(race_prefixes, size * sizeof(char *));
|
||||
}
|
||||
race_prefixes[next++] = _strdup(prefix);
|
||||
race_prefixes[next] = NULL;
|
||||
}
|
||||
|
||||
/* Die Bezeichnungen dürfen wegen der Art des Speicherns keine
|
||||
* Leerzeichen enthalten! */
|
||||
|
||||
/* "den Zwergen", "Halblingsparteien" */
|
||||
|
||||
bool r_insectstalled(const region * r)
|
||||
{
|
||||
return fval(r->terrain, ARCTIC_REGION);
|
||||
return fval(r->terrain, ARCTIC_REGION);
|
||||
}
|
||||
|
||||
const char *rc_name(const race * rc, int n)
|
||||
const char *rc_name(const race * rc, name_t n)
|
||||
{
|
||||
return rc ? mkname("race", rc->_name[n]) : NULL;
|
||||
const char * postfix = 0;
|
||||
if (!rc) {
|
||||
return NULL;
|
||||
}
|
||||
switch (n) {
|
||||
case NAME_SINGULAR: postfix = ""; break;
|
||||
case NAME_PLURAL: postfix = "_p"; break;
|
||||
case NAME_DEFINITIVE: postfix = "_d"; break;
|
||||
case NAME_CATEGORY: postfix = "_x"; break;
|
||||
default: assert(!"invalid name_t enum in rc_name");
|
||||
}
|
||||
if (postfix) {
|
||||
static char name[64]; // FIXME: static return value
|
||||
sprintf(name, "race::%s%s", rc->_name, postfix);
|
||||
return name;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *raceprefix(const unit * u)
|
||||
{
|
||||
const attrib *asource = u->faction->attribs;
|
||||
const attrib *asource = u->faction->attribs;
|
||||
|
||||
if (fval(u, UFL_GROUP)) {
|
||||
const attrib *agroup = agroup = a_findc(u->attribs, &at_group);
|
||||
if (agroup != NULL)
|
||||
asource = ((const group *)(agroup->data.v))->attribs;
|
||||
}
|
||||
return get_prefix(asource);
|
||||
if (fval(u, UFL_GROUP)) {
|
||||
const attrib *agroup = agroup = a_findc(u->attribs, &at_group);
|
||||
if (agroup != NULL)
|
||||
asource = ((const group *)(agroup->data.v))->attribs;
|
||||
}
|
||||
return get_prefix(asource);
|
||||
}
|
||||
|
||||
const char *racename(const struct locale *loc, const unit * u, const race * rc)
|
||||
{
|
||||
const char *str, *prefix = raceprefix(u);
|
||||
const char *str, *prefix = raceprefix(u);
|
||||
|
||||
if (prefix != NULL) {
|
||||
static char lbuf[80];
|
||||
char *bufp = lbuf;
|
||||
size_t size = sizeof(lbuf) - 1;
|
||||
int ch, bytes;
|
||||
if (prefix != NULL) {
|
||||
static char lbuf[80]; // FIXME: static return value
|
||||
char *bufp = lbuf;
|
||||
size_t size = sizeof(lbuf) - 1;
|
||||
int ch, bytes;
|
||||
|
||||
bytes = (int)strlcpy(bufp, LOC(loc, mkname("prefix", prefix)), size);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
bytes = (int)strlcpy(bufp, LOC(loc, mkname("prefix", prefix)), size);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
|
||||
bytes = (int)strlcpy(bufp, LOC(loc, rc_name(rc, u->number != 1)), size);
|
||||
assert(~bufp[0] & 0x80 || !"unicode/not implemented");
|
||||
ch = tolower(*(unsigned char *)bufp);
|
||||
bufp[0] = (char)ch;
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
*bufp = 0;
|
||||
bytes = (int)strlcpy(bufp, LOC(loc, rc_name(rc, u->number != 1)), size);
|
||||
assert(~bufp[0] & 0x80 || !"unicode/not implemented");
|
||||
ch = tolower(*(unsigned char *)bufp);
|
||||
bufp[0] = (char)ch;
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
*bufp = 0;
|
||||
|
||||
return lbuf;
|
||||
}
|
||||
str = LOC(loc, rc_name(rc, u->number != 1));
|
||||
return str ? str : rc->_name[0];
|
||||
return lbuf;
|
||||
}
|
||||
str = LOC(loc, rc_name(rc, (u->number == 1) ? NAME_SINGULAR : NAME_PLURAL));
|
||||
return str ? str : rc->_name;
|
||||
}
|
||||
|
||||
int
|
||||
rc_specialdamage(const race * ar, const race * dr,
|
||||
const struct weapon_type *wtype)
|
||||
const struct weapon_type *wtype)
|
||||
{
|
||||
race_t art = old_race(ar);
|
||||
int m, modifier = 0;
|
||||
race_t art = old_race(ar);
|
||||
int m, modifier = 0;
|
||||
|
||||
if (wtype != NULL && wtype->modifiers != NULL)
|
||||
for (m = 0; wtype->modifiers[m].value; ++m) {
|
||||
/* weapon damage for this weapon, possibly by race */
|
||||
if (wtype->modifiers[m].flags & WMF_DAMAGE) {
|
||||
race_list *rlist = wtype->modifiers[m].races;
|
||||
if (rlist != NULL) {
|
||||
while (rlist) {
|
||||
if (rlist->data == ar)
|
||||
break;
|
||||
rlist = rlist->next;
|
||||
}
|
||||
if (rlist == NULL)
|
||||
continue;
|
||||
if (wtype != NULL && wtype->modifiers != NULL)
|
||||
for (m = 0; wtype->modifiers[m].value; ++m) {
|
||||
/* weapon damage for this weapon, possibly by race */
|
||||
if (wtype->modifiers[m].flags & WMF_DAMAGE) {
|
||||
race_list *rlist = wtype->modifiers[m].races;
|
||||
if (rlist != NULL) {
|
||||
while (rlist) {
|
||||
if (rlist->data == ar)
|
||||
break;
|
||||
rlist = rlist->next;
|
||||
}
|
||||
if (rlist == NULL)
|
||||
continue;
|
||||
}
|
||||
modifier += wtype->modifiers[m].value;
|
||||
}
|
||||
modifier += wtype->modifiers[m].value;
|
||||
}
|
||||
}
|
||||
switch (art) {
|
||||
}
|
||||
switch (art) {
|
||||
case RC_HALFLING:
|
||||
if (wtype != NULL && dragonrace(dr)) {
|
||||
modifier += 5;
|
||||
}
|
||||
break;
|
||||
if (wtype != NULL && dragonrace(dr)) {
|
||||
modifier += 5;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return modifier;
|
||||
break;
|
||||
}
|
||||
return modifier;
|
||||
}
|
||||
|
||||
void write_race_reference(const race * rc, struct storage *store)
|
||||
{
|
||||
WRITE_TOK(store, rc ? rc->_name[0] : "none");
|
||||
WRITE_TOK(store, rc ? rc->_name : "none");
|
||||
}
|
||||
|
||||
variant read_race_reference(struct storage *store)
|
||||
{
|
||||
variant result;
|
||||
char zName[20];
|
||||
READ_TOK(store, zName, sizeof(zName));
|
||||
variant result;
|
||||
char zName[20];
|
||||
READ_TOK(store, zName, sizeof(zName));
|
||||
|
||||
if (strcmp(zName, "none") == 0) {
|
||||
result.v = NULL;
|
||||
if (strcmp(zName, "none") == 0) {
|
||||
result.v = NULL;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result.v = rc_find_i(zName);
|
||||
}
|
||||
assert(result.v != NULL);
|
||||
return result;
|
||||
} else {
|
||||
result.v = rc_find_i(zName);
|
||||
}
|
||||
assert(result.v != NULL);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ extern "C" {
|
|||
|
||||
typedef struct race {
|
||||
struct param *parameters;
|
||||
const char *_name[4]; /* neu: name[4]völker */
|
||||
const char *_name; /* neu: name[4]völker */
|
||||
float magres;
|
||||
float maxaura; /* Faktor auf Maximale Aura */
|
||||
float regaura; /* Faktor auf Regeneration */
|
||||
|
@ -134,7 +134,7 @@ extern "C" {
|
|||
float aggression; /* chance that a monster will attack */
|
||||
int hitpoints;
|
||||
const char *def_damage;
|
||||
char armor;
|
||||
int armor;
|
||||
int at_default; /* Angriffsskill Unbewaffnet (default: -2) */
|
||||
int df_default; /* Verteidigungsskill Unbewaffnet (default: -2) */
|
||||
int at_bonus; /* Verändert den Angriffsskill (default: 0) */
|
||||
|
@ -178,11 +178,13 @@ extern "C" {
|
|||
|
||||
extern race *rc_get_or_create(const char *name);
|
||||
extern const race *rc_find(const char *);
|
||||
extern const char *rc_name(const race *, int);
|
||||
extern int rc_specialdamage(const race *, const race *,
|
||||
const struct weapon_type *);
|
||||
void free_races(void);
|
||||
|
||||
typedef enum name_t { NAME_SINGULAR, NAME_PLURAL, NAME_DEFINITIVE, NAME_CATEGORY } name_t;
|
||||
const char *rc_name(const race *, name_t);
|
||||
|
||||
/* Flags. Do not reorder these without changing json_race() in jsonconf.c */
|
||||
#define RCF_NPC (1<<0) /* cannot be the race for a player faction (and other limits?) */
|
||||
#define RCF_KILLPEASANTS (1<<1) /* a monster that eats peasants */
|
||||
|
|
24
src/kernel/race.test.c
Normal file
24
src/kernel/race.test.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include "race.h"
|
||||
#include <CuTest.h>
|
||||
#include <tests.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
static void test_rc_name(CuTest *tc) {
|
||||
struct race *rc = test_create_race("human");
|
||||
CuAssertStrEquals(tc, "race::human", rc_name(rc, NAME_SINGULAR));
|
||||
CuAssertStrEquals(tc, "race::human_p", rc_name(rc, NAME_PLURAL));
|
||||
CuAssertStrEquals(tc, "race::human_d", rc_name(rc, NAME_DEFINITIVE));
|
||||
CuAssertStrEquals(tc, "race::human_x", rc_name(rc, NAME_CATEGORY));
|
||||
}
|
||||
|
||||
CuSuite *get_race_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_rc_name);
|
||||
return suite;
|
||||
}
|
||||
|
|
@ -189,163 +189,6 @@ void chaoscounts(region * r, int fallen)
|
|||
a_remove(&r->attribs, a);
|
||||
}
|
||||
|
||||
/********************/
|
||||
/* at_direction */
|
||||
/********************/
|
||||
static void a_initdirection(attrib * a)
|
||||
{
|
||||
a->data.v = calloc(1, sizeof(spec_direction));
|
||||
}
|
||||
|
||||
static void a_freedirection(attrib * a)
|
||||
{
|
||||
free(a->data.v);
|
||||
}
|
||||
|
||||
static int a_agedirection(attrib * a)
|
||||
{
|
||||
spec_direction *d = (spec_direction *) (a->data.v);
|
||||
--d->duration;
|
||||
return (d->duration > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
||||
}
|
||||
|
||||
typedef struct dir_lookup {
|
||||
char *name;
|
||||
const char *oldname;
|
||||
struct dir_lookup *next;
|
||||
} dir_lookup;
|
||||
|
||||
static dir_lookup *dir_name_lookup;
|
||||
|
||||
void register_special_direction(const char *name)
|
||||
{
|
||||
struct locale *lang;
|
||||
char *str = _strdup(name);
|
||||
|
||||
for (lang = locales; lang; lang = nextlocale(lang)) {
|
||||
void **tokens = get_translations(lang, UT_SPECDIR);
|
||||
const char *token = LOC(lang, name);
|
||||
|
||||
if (token) {
|
||||
variant var;
|
||||
|
||||
var.v = str;
|
||||
addtoken(tokens, token, var);
|
||||
|
||||
if (lang == default_locale) {
|
||||
dir_lookup *dl = malloc(sizeof(dir_lookup));
|
||||
dl->name = str;
|
||||
dl->oldname = token;
|
||||
dl->next = dir_name_lookup;
|
||||
dir_name_lookup = dl;
|
||||
}
|
||||
} else {
|
||||
log_error("no translation for spec_direction '%s' in locale '%s'\n", name, locale_name(lang));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int a_readdirection(attrib * a, void *owner, struct storage *store)
|
||||
{
|
||||
spec_direction *d = (spec_direction *) (a->data.v);
|
||||
|
||||
READ_INT(store, &d->x);
|
||||
READ_INT(store, &d->y);
|
||||
READ_INT(store, &d->duration);
|
||||
if (global.data_version < UNICODE_VERSION) {
|
||||
char lbuf[16];
|
||||
dir_lookup *dl = dir_name_lookup;
|
||||
|
||||
READ_TOK(store, NULL, 0);
|
||||
READ_TOK(store, lbuf, sizeof(lbuf));
|
||||
|
||||
cstring_i(lbuf);
|
||||
for (; dl; dl = dl->next) {
|
||||
if (strcmp(lbuf, dl->oldname) == 0) {
|
||||
d->keyword = _strdup(dl->name);
|
||||
sprintf(lbuf, "%s_desc", d->keyword);
|
||||
d->desc = _strdup(dl->name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (dl == NULL) {
|
||||
log_error("unknown spec_direction '%s'\n", lbuf);
|
||||
assert(!"not implemented");
|
||||
}
|
||||
} else {
|
||||
char lbuf[32];
|
||||
READ_TOK(store, lbuf, sizeof(lbuf));
|
||||
d->desc = _strdup(lbuf);
|
||||
READ_TOK(store, lbuf, sizeof(lbuf));
|
||||
d->keyword = _strdup(lbuf);
|
||||
}
|
||||
d->active = true;
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
||||
static void
|
||||
a_writedirection(const attrib * a, const void *owner, struct storage *store)
|
||||
{
|
||||
spec_direction *d = (spec_direction *) (a->data.v);
|
||||
|
||||
WRITE_INT(store, d->x);
|
||||
WRITE_INT(store, d->y);
|
||||
WRITE_INT(store, d->duration);
|
||||
WRITE_TOK(store, d->desc);
|
||||
WRITE_TOK(store, d->keyword);
|
||||
}
|
||||
|
||||
attrib_type at_direction = {
|
||||
"direction",
|
||||
a_initdirection,
|
||||
a_freedirection,
|
||||
a_agedirection,
|
||||
a_writedirection,
|
||||
a_readdirection
|
||||
};
|
||||
|
||||
region *find_special_direction(const region * r, const char *token,
|
||||
const struct locale *lang)
|
||||
{
|
||||
attrib *a;
|
||||
spec_direction *d;
|
||||
|
||||
if (strlen(token) == 0)
|
||||
return NULL;
|
||||
for (a = a_find(r->attribs, &at_direction); a && a->type == &at_direction;
|
||||
a = a->next) {
|
||||
d = (spec_direction *) (a->data.v);
|
||||
|
||||
if (d->active) {
|
||||
void **tokens = get_translations(lang, UT_SPECDIR);
|
||||
variant var;
|
||||
if (findtoken(*tokens, token, &var) == E_TOK_SUCCESS) {
|
||||
if (strcmp((const char *)var.v, d->keyword) == 0) {
|
||||
return findregion(d->x, d->y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
attrib *create_special_direction(region * r, region * rt, int duration,
|
||||
const char *desc, const char *keyword)
|
||||
{
|
||||
attrib *a = a_add(&r->attribs, a_new(&at_direction));
|
||||
spec_direction *d = (spec_direction *) (a->data.v);
|
||||
|
||||
d->active = false;
|
||||
d->x = rt->x;
|
||||
d->y = rt->y;
|
||||
d->duration = duration;
|
||||
d->desc = _strdup(desc);
|
||||
d->keyword = _strdup(keyword);
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
/* Moveblock wird zur Zeit nicht über Attribute, sondern ein Bitfeld
|
||||
r->moveblock gemacht. Sollte umgestellt werden, wenn kompliziertere
|
||||
Dinge gefragt werden. */
|
||||
|
@ -386,12 +229,12 @@ static int dummy_data;
|
|||
static region *dummy_ptr = (region *) & dummy_data; /* a funny hack */
|
||||
|
||||
typedef struct uidhashentry {
|
||||
unsigned int uid;
|
||||
int uid;
|
||||
region *r;
|
||||
} uidhashentry;
|
||||
static uidhashentry uidhash[MAXREGIONS];
|
||||
|
||||
struct region *findregionbyid(unsigned int uid)
|
||||
struct region *findregionbyid(int uid)
|
||||
{
|
||||
int key = uid % MAXREGIONS;
|
||||
while (uidhash[key].uid != 0 && uidhash[key].uid != uid)
|
||||
|
@ -413,7 +256,7 @@ static void unhash_uid(region * r)
|
|||
|
||||
static void hash_uid(region * r)
|
||||
{
|
||||
unsigned int uid = r->uid;
|
||||
int uid = r->uid;
|
||||
for (;;) {
|
||||
if (uid != 0) {
|
||||
int key = uid % MAXREGIONS;
|
||||
|
@ -630,49 +473,6 @@ int distance(const region * r1, const region * r2)
|
|||
return koor_distance(r1->x, r1->y, r2->x, r2->y);
|
||||
}
|
||||
|
||||
static direction_t
|
||||
koor_reldirection(int ax, int ay, int bx, int by, const struct plane *pl)
|
||||
{
|
||||
int dir;
|
||||
for (dir = 0; dir != MAXDIRECTIONS; ++dir) {
|
||||
int x = ax + delta_x[dir];
|
||||
int y = ay + delta_y[dir];
|
||||
pnormalize(&x, &y, pl);
|
||||
if (bx == x && by == y)
|
||||
return (direction_t)dir;
|
||||
}
|
||||
return NODIRECTION;
|
||||
}
|
||||
|
||||
spec_direction *special_direction(const region * from, const region * to)
|
||||
{
|
||||
const attrib *a = a_findc(from->attribs, &at_direction);
|
||||
|
||||
while (a != NULL && a->type == &at_direction) {
|
||||
spec_direction *sd = (spec_direction *) a->data.v;
|
||||
if (sd->x == to->x && sd->y == to->y)
|
||||
return sd;
|
||||
a = a->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
direction_t reldirection(const region * from, const region * to)
|
||||
{
|
||||
plane *pl = rplane(from);
|
||||
if (pl == rplane(to)) {
|
||||
direction_t dir = koor_reldirection(from->x, from->y, to->x, to->y, pl);
|
||||
|
||||
if (dir == NODIRECTION) {
|
||||
spec_direction *sd = special_direction(from, to);
|
||||
if (sd != NULL && sd->active)
|
||||
return D_SPECIAL;
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
return NODIRECTION;
|
||||
}
|
||||
|
||||
void free_regionlist(region_list * rl)
|
||||
{
|
||||
while (rl) {
|
||||
|
@ -940,7 +740,7 @@ static region *last;
|
|||
|
||||
static unsigned int max_index = 0;
|
||||
|
||||
region *new_region(int x, int y, struct plane *pl, unsigned int uid)
|
||||
region *new_region(int x, int y, struct plane *pl, int uid)
|
||||
{
|
||||
region *r;
|
||||
|
||||
|
@ -1409,7 +1209,7 @@ int resolve_region_id(variant id, void *address)
|
|||
{
|
||||
region *r = NULL;
|
||||
if (id.i != 0) {
|
||||
r = findregionbyid((unsigned int)id.i);
|
||||
r = findregionbyid(id.i);
|
||||
if (r == NULL) {
|
||||
*(region **) address = NULL;
|
||||
return -1;
|
||||
|
|
|
@ -120,7 +120,7 @@ extern "C" {
|
|||
/* an ascending number, to improve the speed of determining the interval in
|
||||
which a faction has its units. See the implementations of firstregion
|
||||
and lastregion */
|
||||
unsigned int uid; /* a unique id */
|
||||
int uid; /* a unique id */
|
||||
int x, y;
|
||||
struct plane *_plane; /* to access, use rplane(r) */
|
||||
char *display;
|
||||
|
@ -153,14 +153,6 @@ extern "C" {
|
|||
struct message *r_addmessage(struct region *r, const struct faction *viewer,
|
||||
struct message *msg);
|
||||
|
||||
typedef struct spec_direction {
|
||||
int x, y;
|
||||
int duration;
|
||||
bool active;
|
||||
char *desc;
|
||||
char *keyword;
|
||||
} spec_direction;
|
||||
|
||||
typedef struct {
|
||||
direction_t dir;
|
||||
} moveblock;
|
||||
|
@ -169,11 +161,9 @@ extern "C" {
|
|||
|
||||
int distance(const struct region *, const struct region *);
|
||||
int koor_distance(int ax, int ay, int bx, int by);
|
||||
direction_t reldirection(const struct region *from, const struct region *to);
|
||||
struct region *findregion(int x, int y);
|
||||
struct region *findregionbyid(unsigned int uid);
|
||||
struct region *findregionbyid(int uid);
|
||||
|
||||
extern struct attrib_type at_direction;
|
||||
extern struct attrib_type at_moveblock;
|
||||
extern struct attrib_type at_peasantluck;
|
||||
extern struct attrib_type at_horseluck;
|
||||
|
@ -189,14 +179,6 @@ extern "C" {
|
|||
void free_regionlist(region_list * rl);
|
||||
void add_regionlist(region_list ** rl, struct region *r);
|
||||
|
||||
struct region *find_special_direction(const struct region *r,
|
||||
const char *token, const struct locale *lang);
|
||||
void register_special_direction(const char *name);
|
||||
struct spec_direction *special_direction(const region * from,
|
||||
const region * to);
|
||||
struct attrib *create_special_direction(struct region *r, struct region *rt,
|
||||
int duration, const char *desc, const char *keyword);
|
||||
|
||||
int deathcount(const struct region *r);
|
||||
int chaoscount(const struct region *r);
|
||||
|
||||
|
@ -251,7 +233,7 @@ extern "C" {
|
|||
const char *write_regionname(const struct region *r, const struct faction *f,
|
||||
char *buffer, size_t size);
|
||||
|
||||
struct region *new_region(int x, int y, struct plane *pl, unsigned int uid);
|
||||
struct region *new_region(int x, int y, struct plane *pl, int uid);
|
||||
void remove_region(region ** rlist, region * r);
|
||||
void terraform_region(struct region *r, const struct terrain_type *terrain);
|
||||
bool pnormalize(int *x, int *y, const struct plane *pl);
|
||||
|
|
|
@ -1,159 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
**/
|
||||
|
||||
#ifndef H_KRNL_REPORTS
|
||||
#define H_KRNL_REPORTS
|
||||
|
||||
#include <time.h>
|
||||
#include "objtypes.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Alter, ab dem der Score angezeigt werden soll: */
|
||||
#define DISPLAYSCORE 12
|
||||
/* Breite einer Reportzeile: */
|
||||
#define REPORTWIDTH 78
|
||||
|
||||
extern const char *directions[];
|
||||
extern const char *coasts[];
|
||||
extern bool nonr;
|
||||
extern bool nocr;
|
||||
extern bool noreports;
|
||||
|
||||
/* kann_finden speedups */
|
||||
extern bool kann_finden(struct faction *f1, struct faction *f2);
|
||||
extern struct unit *can_find(struct faction *, struct faction *);
|
||||
|
||||
/* funktionen zum schreiben eines reports */
|
||||
void sparagraph(struct strlist **SP, const char *s, int indent, char mark);
|
||||
void lparagraph(struct strlist **SP, char *s, int indent, char mark);
|
||||
const char *hp_status(const struct unit *u);
|
||||
extern size_t spskill(char *pbuf, size_t siz, const struct locale *lang, const struct unit *u, struct skill *sv, int *dh, int days); /* mapper */
|
||||
extern void spunit(struct strlist **SP, const struct faction *f,
|
||||
const struct unit *u, int indent, int mode);
|
||||
|
||||
extern int reports(void);
|
||||
extern int write_reports(struct faction *f, time_t ltime);
|
||||
extern int init_reports(void);
|
||||
extern void reorder_units(struct region * r);
|
||||
|
||||
extern const struct unit *ucansee(const struct faction *f,
|
||||
const struct unit *u, const struct unit *x);
|
||||
|
||||
enum {
|
||||
see_none,
|
||||
see_neighbour,
|
||||
see_lighthouse,
|
||||
see_travel,
|
||||
see_far,
|
||||
see_unit,
|
||||
see_battle
|
||||
};
|
||||
extern int stealth_modifier(int seen_mode);
|
||||
|
||||
typedef struct seen_region {
|
||||
struct seen_region *nextHash;
|
||||
struct seen_region *next;
|
||||
struct region *r;
|
||||
unsigned char mode;
|
||||
bool disbelieves;
|
||||
} seen_region;
|
||||
|
||||
extern struct seen_region *find_seen(struct seen_region *seehash[],
|
||||
const struct region *r);
|
||||
extern bool add_seen(struct seen_region *seehash[], struct region *r,
|
||||
unsigned char mode, bool dis);
|
||||
extern struct seen_region **seen_init(void);
|
||||
extern void seen_done(struct seen_region *seehash[]);
|
||||
extern void free_seen(void);
|
||||
extern void link_seen(seen_region * seehash[], const struct region *first,
|
||||
const struct region *last);
|
||||
extern const char *visibility[];
|
||||
|
||||
typedef struct report_context {
|
||||
struct faction *f;
|
||||
struct quicklist *addresses;
|
||||
struct seen_region **seen;
|
||||
struct region *first, *last;
|
||||
void *userdata;
|
||||
time_t report_time;
|
||||
} report_context;
|
||||
|
||||
typedef int (*report_fun) (const char *filename, report_context * ctx,
|
||||
const char *charset);
|
||||
extern void register_reporttype(const char *extension, report_fun write,
|
||||
int flag);
|
||||
|
||||
extern int bufunit(const struct faction *f, const struct unit *u, int indent,
|
||||
int mode, char *buf, size_t size);
|
||||
|
||||
extern const char *trailinto(const struct region *r,
|
||||
const struct locale *lang);
|
||||
extern const char *report_kampfstatus(const struct unit *u,
|
||||
const struct locale *lang);
|
||||
|
||||
extern void register_reports(void);
|
||||
|
||||
extern int update_nmrs(void);
|
||||
extern int *nmrs;
|
||||
|
||||
extern struct message *msg_curse(const struct curse *c, const void *obj,
|
||||
objtype_t typ, int slef);
|
||||
|
||||
typedef struct arg_regions {
|
||||
int nregions;
|
||||
struct region **regions;
|
||||
} arg_regions;
|
||||
|
||||
typedef struct resource_report {
|
||||
const char *name;
|
||||
int number;
|
||||
int level;
|
||||
} resource_report;
|
||||
int report_resources(const struct seen_region *sr,
|
||||
struct resource_report *result, int size, const struct faction *viewer);
|
||||
int report_items(const struct item *items, struct item *result, int size,
|
||||
const struct unit *owner, const struct faction *viewer);
|
||||
void report_item(const struct unit *owner, const struct item *i,
|
||||
const struct faction *viewer, const char **name, const char **basename,
|
||||
int *number, bool singular);
|
||||
void report_building(const struct building *b, const char **btype,
|
||||
const char **billusion);
|
||||
void report_race(const struct unit *u, const char **rcname,
|
||||
const char **rcillusion);
|
||||
|
||||
#define ACTION_RESET 0x01 /* reset the one-time-flag FFL_SELECT (on first pass) */
|
||||
#define ACTION_CANSEE 0x02 /* to people who can see the actor */
|
||||
#define ACTION_CANNOTSEE 0x04 /* to people who can not see the actor */
|
||||
extern int report_action(struct region *r, struct unit *actor,
|
||||
struct message *msg, int flags);
|
||||
|
||||
extern size_t f_regionid(const struct region *r, const struct faction *f,
|
||||
char *buffer, size_t size);
|
||||
|
||||
extern const char *combatstatus[];
|
||||
#define GR_PLURAL 0x01 /* grammar: plural */
|
||||
#define MAX_INVENTORY 128 /* maimum number of different items in an inventory */
|
||||
#define MAX_RAWMATERIALS 8 /* maximum kinds of raw materials in a regions */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -241,7 +241,7 @@ static faction *factionorders(void)
|
|||
|
||||
}
|
||||
else {
|
||||
log_warning("orders for invalid faction %s\n", itoa36(fid));
|
||||
log_debug("orders for invalid faction %s\n", itoa36(fid));
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
@ -411,7 +411,7 @@ void read_items(struct storage *store, item ** ilist)
|
|||
rtype = rt_find(ibuf);
|
||||
READ_INT(store, &i);
|
||||
if (i <= 0) {
|
||||
log_error("data contains an entry with %d %s\n", i, rtype->_name[1]);
|
||||
log_error("data contains an entry with %d %s\n", i, resourcename(rtype, NMF_PLURAL));
|
||||
}
|
||||
else {
|
||||
if (rtype && rtype->itype) {
|
||||
|
@ -810,8 +810,8 @@ void write_unit(struct gamedata *data, const unit * u)
|
|||
WRITE_STR(data->store, u->display ? (const char *)u->display : "");
|
||||
WRITE_INT(data->store, u->number);
|
||||
WRITE_INT(data->store, u->age);
|
||||
WRITE_TOK(data->store, u_race(u)->_name[0]);
|
||||
WRITE_TOK(data->store, (irace && irace != u_race(u)) ? irace->_name[0] : "");
|
||||
WRITE_TOK(data->store, u_race(u)->_name);
|
||||
WRITE_TOK(data->store, (irace && irace != u_race(u)) ? irace->_name : "");
|
||||
write_building_reference(u->building, data->store);
|
||||
write_ship_reference(u->ship, data->store);
|
||||
WRITE_INT(data->store, u->status);
|
||||
|
@ -1412,7 +1412,7 @@ void writefaction(struct gamedata *data, const faction * f)
|
|||
WRITE_TOK(data->store, locale_name(f->locale));
|
||||
WRITE_INT(data->store, f->lastorders);
|
||||
WRITE_INT(data->store, f->age);
|
||||
WRITE_TOK(data->store, f->race->_name[0]);
|
||||
WRITE_TOK(data->store, f->race->_name);
|
||||
WRITE_SECTION(data->store);
|
||||
WRITE_INT(data->store, f->magiegebiet);
|
||||
|
||||
|
@ -1571,7 +1571,9 @@ int readgame(const char *filename, int backup)
|
|||
}
|
||||
}
|
||||
a_read(&store, &pl->attribs, pl);
|
||||
addlist(&planes, pl);
|
||||
if (pl->id != 1094969858) { // Regatta
|
||||
addlist(&planes, pl);
|
||||
}
|
||||
}
|
||||
|
||||
/* Read factions */
|
||||
|
|
|
@ -158,7 +158,7 @@ int rc_skillmod(const struct race *rc, const region * r, skill_t sk)
|
|||
return 0;
|
||||
}
|
||||
#ifdef FASTER_SKILLMOD
|
||||
unsigned int index = hashstring(rc->_name[0]) % RCMODMAXHASH;
|
||||
unsigned int index = hashstring(rc->_name) % RCMODMAXHASH;
|
||||
struct skillmods **imods = &modhash[index];
|
||||
while (*imods && (*imods)->race != rc) {
|
||||
imods = &(*imods)->next;
|
||||
|
|
2096
src/kernel/unit.c
2096
src/kernel/unit.c
File diff suppressed because it is too large
Load diff
|
@ -125,10 +125,6 @@ extern "C" {
|
|||
|
||||
int ualias(const struct unit *u);
|
||||
|
||||
extern struct attrib_type at_stealth;
|
||||
|
||||
void u_seteffstealth(struct unit *u, int value);
|
||||
int u_geteffstealth(const struct unit *u);
|
||||
const struct race *u_irace(const struct unit *u);
|
||||
const struct race *u_race(const struct unit *u);
|
||||
void u_setrace(struct unit *u, const struct race *);
|
||||
|
|
41
src/kernel/unit.test.c
Normal file
41
src/kernel/unit.test.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include "alchemy.h"
|
||||
#include "unit.h"
|
||||
#include "item.h"
|
||||
#include "region.h"
|
||||
|
||||
#include <CuTest.h>
|
||||
#include <tests.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
static void test_scale_number(CuTest *tc) {
|
||||
unit *u;
|
||||
const struct potion_type *ptype;
|
||||
|
||||
test_cleanup();
|
||||
test_create_world();
|
||||
ptype = new_potiontype(it_get_or_create(rt_get_or_create("hodor")), 1);
|
||||
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
|
||||
change_effect(u, ptype, 1);
|
||||
CuAssertIntEquals(tc, 1, u->number);
|
||||
CuAssertIntEquals(tc, 1, u->hp);
|
||||
CuAssertIntEquals(tc, 1, get_effect(u, ptype));
|
||||
scale_number(u, 2);
|
||||
CuAssertIntEquals(tc, 2, u->number);
|
||||
CuAssertIntEquals(tc, 2, u->hp);
|
||||
CuAssertIntEquals(tc, 2, get_effect(u, ptype));
|
||||
set_level(u, SK_ALCHEMY, 1);
|
||||
scale_number(u, 0);
|
||||
CuAssertIntEquals(tc, 0, get_level(u, SK_ALCHEMY));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
CuSuite *get_unit_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_scale_number);
|
||||
return suite;
|
||||
}
|
|
@ -29,6 +29,8 @@ without prior permission by the authors of Eressea.
|
|||
#include "spellbook.h"
|
||||
#include "calendar.h"
|
||||
|
||||
#include "vortex.h"
|
||||
|
||||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <util/bsdstring.h>
|
||||
|
@ -459,33 +461,6 @@ static int parse_calendar(xmlDocPtr doc)
|
|||
return rv;
|
||||
}
|
||||
|
||||
static int parse_directions(xmlDocPtr doc)
|
||||
{
|
||||
xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
|
||||
xmlXPathObjectPtr xpathDirections;
|
||||
xmlNodeSetPtr nsetDirections;
|
||||
int rv = 0;
|
||||
|
||||
/* reading eressea/directions/dir */
|
||||
xpathDirections =
|
||||
xmlXPathEvalExpression(BAD_CAST "/eressea/directions/dir", xpath);
|
||||
nsetDirections = xpathDirections->nodesetval;
|
||||
if (nsetDirections != NULL) {
|
||||
int k;
|
||||
for (k = 0; k != nsetDirections->nodeNr; ++k) {
|
||||
xmlNodePtr dir = nsetDirections->nodeTab[k];
|
||||
xmlChar *propValue = xmlGetProp(dir, BAD_CAST "name");
|
||||
|
||||
register_special_direction((const char *)propValue);
|
||||
xmlFree(propValue);
|
||||
}
|
||||
}
|
||||
xmlXPathFreeObject(xpathDirections);
|
||||
xmlXPathFreeContext(xpath);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static int parse_ships(xmlDocPtr doc)
|
||||
{
|
||||
xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
|
||||
|
@ -776,7 +751,7 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype)
|
|||
|
||||
parse_function(node, &fun, &propValue);
|
||||
if (fun == NULL) {
|
||||
log_error("unknown function name '%s' for item '%s'\n", (const char *)propValue, itype->rtype->_name[0]);
|
||||
log_error("unknown function name '%s' for item '%s'\n", (const char *)propValue, itype->rtype->_name);
|
||||
xmlFree(propValue);
|
||||
continue;
|
||||
}
|
||||
|
@ -786,7 +761,7 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype)
|
|||
(bool(*)(const struct troop *, const struct weapon_type *,
|
||||
int *))fun;
|
||||
} else {
|
||||
log_error("unknown function type '%s' for item '%s'\n", (const char *)propValue, itype->rtype->_name[0]);
|
||||
log_error("unknown function type '%s' for item '%s'\n", (const char *)propValue, itype->rtype->_name);
|
||||
}
|
||||
xmlFree(propValue);
|
||||
}
|
||||
|
@ -880,7 +855,7 @@ static item_type *xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
|
|||
|
||||
parse_function(node, &fun, &propValue);
|
||||
if (fun == NULL) {
|
||||
log_error("unknown function name '%s' for item '%s'\n", (const char *)propValue, rtype->_name[0]);
|
||||
log_error("unknown function name '%s' for item '%s'\n", (const char *)propValue, rtype->_name);
|
||||
xmlFree(propValue);
|
||||
continue;
|
||||
}
|
||||
|
@ -901,7 +876,7 @@ static item_type *xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
|
|||
(int (*)(struct unit *, int, const struct item_type *, int,
|
||||
struct order *))fun;
|
||||
} else {
|
||||
log_error("unknown function type '%s' for item '%s'\n", (const char *)propValue, rtype->_name[0]);
|
||||
log_error("unknown function type '%s' for item '%s'\n", (const char *)propValue, rtype->_name);
|
||||
}
|
||||
xmlFree(propValue);
|
||||
}
|
||||
|
@ -997,7 +972,7 @@ static int parse_resources(xmlDocPtr doc)
|
|||
|
||||
parse_function(node, &fun, &propValue);
|
||||
if (fun == NULL) {
|
||||
log_error("unknown function name '%s' for resource %s\n", (const char *)propValue, rtype->_name[0]);
|
||||
log_error("unknown function name '%s' for resource %s\n", (const char *)propValue, rtype->_name);
|
||||
xmlFree(propValue);
|
||||
continue;
|
||||
}
|
||||
|
@ -1010,7 +985,7 @@ static int parse_resources(xmlDocPtr doc)
|
|||
} else if (strcmp((const char *)propValue, "name") == 0) {
|
||||
rtype->name = (rtype_name) fun;
|
||||
} else {
|
||||
log_error("unknown function type '%s' for resource %s\n", (const char *)propValue, rtype->_name[0]);
|
||||
log_error("unknown function type '%s' for resource %s\n", (const char *)propValue, rtype->_name);
|
||||
}
|
||||
xmlFree(propValue);
|
||||
}
|
||||
|
@ -1077,7 +1052,7 @@ static int parse_resources(xmlDocPtr doc)
|
|||
xmlFree(propBldg);
|
||||
}
|
||||
} else {
|
||||
log_error("unknown type '%s' for resourcelimit-modifier '%s'\n", (const char *)propValue, rtype->_name[0]);
|
||||
log_error("unknown type '%s' for resourcelimit-modifier '%s'\n", (const char *)propValue, rtype->_name);
|
||||
}
|
||||
xmlFree(propValue);
|
||||
}
|
||||
|
@ -1112,7 +1087,7 @@ static int parse_resources(xmlDocPtr doc)
|
|||
assert(propValue != NULL);
|
||||
fun = get_function((const char *)propValue);
|
||||
if (fun == NULL) {
|
||||
log_error("unknown limit '%s' for resource %s\n", (const char *)propValue, rtype->_name[0]);
|
||||
log_error("unknown limit '%s' for resource %s\n", (const char *)propValue, rtype->_name);
|
||||
xmlFree(propValue);
|
||||
continue;
|
||||
}
|
||||
|
@ -1125,7 +1100,7 @@ static int parse_resources(xmlDocPtr doc)
|
|||
} else if (strcmp((const char *)propValue, "limit") == 0) {
|
||||
rdata->limit = (rlimit_limit) fun;
|
||||
} else {
|
||||
log_error("unknown limit '%s' for resource %s\n", (const char *)propValue, rtype->_name[0]);
|
||||
log_error("unknown limit '%s' for resource %s\n", (const char *)propValue, rtype->_name);
|
||||
}
|
||||
xmlFree(propValue);
|
||||
}
|
||||
|
@ -1781,7 +1756,7 @@ static int parse_races(xmlDocPtr doc)
|
|||
rc->study_speed[sk] = (char)speed;
|
||||
}
|
||||
} else {
|
||||
log_error("unknown skill '%s' in race '%s'\n", (const char *)propValue, rc->_name[0]);
|
||||
log_error("unknown skill '%s' in race '%s'\n", (const char *)propValue, rc->_name);
|
||||
}
|
||||
xmlFree(propValue);
|
||||
}
|
||||
|
@ -1796,7 +1771,7 @@ static int parse_races(xmlDocPtr doc)
|
|||
|
||||
parse_function(node, &fun, &propValue);
|
||||
if (fun == NULL) {
|
||||
log_error("unknown function name '%s' for race %s\n", (const char *)propValue, rc->_name[0]);
|
||||
log_error("unknown function name '%s' for race %s\n", (const char *)propValue, rc->_name);
|
||||
xmlFree(propValue);
|
||||
continue;
|
||||
}
|
||||
|
@ -1816,7 +1791,7 @@ static int parse_races(xmlDocPtr doc)
|
|||
} else if (strcmp((const char *)propValue, "initfamiliar") == 0) {
|
||||
rc->init_familiar = (void (*)(struct unit *))fun;
|
||||
} else {
|
||||
log_error("unknown function type '%s' for race %s\n", (const char *)propValue, rc->_name[0]);
|
||||
log_error("unknown function type '%s' for race %s\n", (const char *)propValue, rc->_name);
|
||||
}
|
||||
xmlFree(propValue);
|
||||
}
|
||||
|
@ -1871,7 +1846,7 @@ static int parse_races(xmlDocPtr doc)
|
|||
if (attack->data.sp) {
|
||||
attack->level = xml_ivalue(node, "level", 0);
|
||||
if (attack->level <= 0) {
|
||||
log_error("magical attack '%s' for race '%s' needs a level: %d\n", attack->data.sp->sname, rc->_name[0], attack->level);
|
||||
log_error("magical attack '%s' for race '%s' needs a level: %d\n", attack->data.sp->sname, rc->_name, attack->level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2307,6 +2282,5 @@ void register_xmlreader(void)
|
|||
xml_register_callback(parse_equipment); /* requires spells */
|
||||
xml_register_callback(parse_races); /* requires spells */
|
||||
xml_register_callback(parse_calendar);
|
||||
xml_register_callback(parse_directions);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -12,11 +12,11 @@
|
|||
|
||||
const char * keyword(keyword_t kwd)
|
||||
{
|
||||
static char result[KEYWORDSIZE];
|
||||
static char result[KEYWORDSIZE]; // FIXME: static return value
|
||||
if (!result[0]) {
|
||||
strcpy(result, "keyword::");
|
||||
}
|
||||
strcpy(result+9, keywords[kwd]);
|
||||
strcpy(result + 9, keywords[kwd]);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
123
src/laws.c
123
src/laws.c
|
@ -31,12 +31,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include "study.h"
|
||||
#include "market.h"
|
||||
#include "keyword.h"
|
||||
#include "move.h"
|
||||
#include "battle.h"
|
||||
#include "alchemy.h"
|
||||
|
||||
/* kernel includes */
|
||||
#include <kernel/alchemy.h>
|
||||
#include <kernel/alliance.h>
|
||||
#include <kernel/ally.h>
|
||||
#include <kernel/battle.h>
|
||||
#include <kernel/connection.h>
|
||||
#include <kernel/curse.h>
|
||||
#include <kernel/building.h>
|
||||
|
@ -46,7 +47,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/item.h>
|
||||
#include <kernel/magic.h>
|
||||
#include <kernel/messages.h>
|
||||
#include <kernel/move.h>
|
||||
#include <kernel/order.h>
|
||||
#include <kernel/plane.h>
|
||||
#include <kernel/pool.h>
|
||||
|
@ -1006,7 +1006,7 @@ static void inactivefaction(faction * f)
|
|||
if (inactiveFILE) {
|
||||
fprintf(inactiveFILE, "%s:%s:%d:%d\n",
|
||||
factionid(f),
|
||||
LOC(default_locale, rc_name(f->race, 1)),
|
||||
LOC(default_locale, rc_name(f->race, NAME_PLURAL)),
|
||||
modify(count_all(f)), turn - f->lastorders);
|
||||
|
||||
fclose(inactiveFILE);
|
||||
|
@ -1090,8 +1090,7 @@ int contact_cmd(unit * u, order * ord)
|
|||
unit *u2;
|
||||
region *r = u->region;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
u2 = getunitg(r, u->faction);
|
||||
|
||||
if (u2 != NULL) {
|
||||
|
@ -1147,10 +1146,10 @@ int quit_cmd(unit * u, struct order *ord)
|
|||
{
|
||||
faction *f = u->faction;
|
||||
const char *passwd;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token(); /* skip keyword */
|
||||
|
||||
keyword_t kwd;
|
||||
|
||||
kwd = init_order(ord);
|
||||
assert(kwd == K_PASSWORD);
|
||||
passwd = getstrtoken();
|
||||
if (checkpasswd(f, (const char *)passwd, false)) {
|
||||
if (EnhancedQuit()) {
|
||||
|
@ -1359,8 +1358,7 @@ void do_enter(struct region *r, bool is_final_attempt)
|
|||
unit *ulast = NULL;
|
||||
const char * s;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
p = findparam_ex(s, u->faction->locale);
|
||||
id = getid();
|
||||
|
@ -1540,8 +1538,7 @@ int ally_cmd(unit * u, struct order *ord)
|
|||
int keyword, not_kw;
|
||||
const char *s;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
f = getfaction();
|
||||
|
||||
if (f == NULL || is_monsters(f)) {
|
||||
|
@ -1707,11 +1704,10 @@ int prefix_cmd(unit * u, struct order *ord)
|
|||
for (in = pnames; in->lang != lang; in = in->next);
|
||||
}
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
|
||||
if (!*s) {
|
||||
if (!s || !*s) {
|
||||
attrib *a = NULL;
|
||||
if (fval(u, UFL_GROUP)) {
|
||||
a = a_find(u->attribs, &at_group);
|
||||
|
@ -1725,8 +1721,7 @@ int prefix_cmd(unit * u, struct order *ord)
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (findtoken(in->names, s, &var) == E_TOK_NOMATCH) {
|
||||
else if (findtoken(in->names, s, &var) == E_TOK_NOMATCH) {
|
||||
return 0;
|
||||
}
|
||||
else if (race_prefixes[var.i] == NULL) {
|
||||
|
@ -1761,8 +1756,7 @@ int display_cmd(unit * u, struct order *ord)
|
|||
const char *str;
|
||||
region *r = u->region;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
|
||||
str = getstrtoken();
|
||||
switch (findparam_ex(str, u->faction->locale)) {
|
||||
|
@ -1933,8 +1927,7 @@ int name_cmd(struct unit *u, struct order *ord)
|
|||
bool foreign = false;
|
||||
const char *str;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
str = getstrtoken();
|
||||
p = findparam_ex(str, u->faction->locale);
|
||||
|
||||
|
@ -2193,8 +2186,7 @@ int mail_cmd(unit * u, struct order *ord)
|
|||
const char *s;
|
||||
int n, cont;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token(); /* skip the keyword */
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
|
||||
/* Falls kein Parameter, ist das eine Einheitsnummer;
|
||||
|
@ -2357,8 +2349,7 @@ int mail_cmd(unit * u, struct order *ord)
|
|||
|
||||
int banner_cmd(unit * u, struct order *ord)
|
||||
{
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
|
||||
free(u->faction->banner);
|
||||
u->faction->banner = _strdup(getstrtoken());
|
||||
|
@ -2372,8 +2363,7 @@ int email_cmd(unit * u, struct order *ord)
|
|||
{
|
||||
const char *s;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
|
||||
if (!s[0]) {
|
||||
|
@ -2399,8 +2389,7 @@ int password_cmd(unit * u, struct order *ord)
|
|||
const char *s;
|
||||
bool pwok = true;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
|
||||
if (!s || !*s) {
|
||||
|
@ -2438,8 +2427,7 @@ int send_cmd(unit * u, struct order *ord)
|
|||
const char *s;
|
||||
int option;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
|
||||
option = findoption(s, u->faction->locale);
|
||||
|
@ -2535,13 +2523,13 @@ static bool display_race(faction * f, unit * u, const race * rc)
|
|||
|
||||
if (u && u_race(u) != rc)
|
||||
return false;
|
||||
name = rc_name(rc, 0);
|
||||
name = rc_name(rc, NAME_SINGULAR);
|
||||
|
||||
bytes = slprintf(bufp, size, "%s: ", LOC(f->locale, name));
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
|
||||
key = mkname("raceinfo", rc->_name[0]);
|
||||
key = mkname("raceinfo", rc->_name);
|
||||
info = locale_getstring(f->locale, key);
|
||||
if (info == NULL) {
|
||||
info = locale_string(f->locale, mkname("raceinfo", "no_info"));
|
||||
|
@ -2778,9 +2766,10 @@ int promotion_cmd(unit * u, struct order *ord)
|
|||
int group_cmd(unit * u, struct order *ord)
|
||||
{
|
||||
const char *s;
|
||||
keyword_t kwd;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
kwd = init_order(ord);
|
||||
assert(kwd == K_GROUP);
|
||||
s = getstrtoken();
|
||||
|
||||
join_group(u, s);
|
||||
|
@ -2791,8 +2780,7 @@ int origin_cmd(unit * u, struct order *ord)
|
|||
{
|
||||
short px, py;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
|
||||
px = (short)getint();
|
||||
py = (short)getint();
|
||||
|
@ -2804,8 +2792,7 @@ int origin_cmd(unit * u, struct order *ord)
|
|||
int guard_off_cmd(unit * u, struct order *ord)
|
||||
{
|
||||
assert(getkeyword(ord) == K_GUARD);
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
|
||||
if (getparam(u->faction->locale) == P_NOT) {
|
||||
setguard(u, GUARD_NONE);
|
||||
|
@ -2818,8 +2805,7 @@ int reshow_cmd(unit * u, struct order *ord)
|
|||
const char *s;
|
||||
param_t p = NOPARAM;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
|
||||
if (isparam(s, u->faction->locale, P_ANY)) {
|
||||
|
@ -2835,8 +2821,7 @@ int status_cmd(unit * u, struct order *ord)
|
|||
{
|
||||
const char *param;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
|
||||
param = getstrtoken();
|
||||
switch (findparam(param, u->faction->locale)) {
|
||||
|
@ -2867,7 +2852,7 @@ int status_cmd(unit * u, struct order *ord)
|
|||
}
|
||||
break;
|
||||
default:
|
||||
if (param[0]) {
|
||||
if (param && param[0]) {
|
||||
add_message(&u->faction->msgs,
|
||||
msg_feedback(u, ord, "unknown_status", ""));
|
||||
}
|
||||
|
@ -2884,8 +2869,7 @@ int combatspell_cmd(unit * u, struct order *ord)
|
|||
int level = 0;
|
||||
spell *sp = 0;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
|
||||
/* KAMPFZAUBER [NICHT] löscht alle gesetzten Kampfzauber */
|
||||
|
@ -2970,8 +2954,7 @@ int guard_on_cmd(unit * u, struct order *ord)
|
|||
{
|
||||
assert(getkeyword(ord) == K_GUARD);
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
|
||||
/* GUARD NOT is handled in goard_off_cmd earlier in the turn */
|
||||
if (getparam(u->faction->locale) == P_NOT)
|
||||
|
@ -3132,8 +3115,7 @@ void restack_units(void)
|
|||
int id;
|
||||
unit *v;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
p = findparam(s, u->faction->locale);
|
||||
id = getid();
|
||||
|
@ -3208,8 +3190,7 @@ int renumber_cmd(unit * u, order * ord)
|
|||
int i;
|
||||
faction *f = u->faction;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
switch (findparam_ex(s, u->faction->locale)) {
|
||||
|
||||
|
@ -3627,6 +3608,7 @@ void new_units(void)
|
|||
}
|
||||
continue;
|
||||
}
|
||||
init_order(makeord);
|
||||
alias = getid();
|
||||
|
||||
token = getstrtoken();
|
||||
|
@ -3940,11 +3922,14 @@ void defaultorders(void)
|
|||
order *ord = *ordp;
|
||||
if (getkeyword(ord) == K_DEFAULT) {
|
||||
char lbuf[8192];
|
||||
order *new_order;
|
||||
init_tokens(ord);
|
||||
skip_token(); /* skip the keyword */
|
||||
strcpy(lbuf, getstrtoken());
|
||||
new_order = parse_order(lbuf, u->faction->locale);
|
||||
order *new_order = 0;
|
||||
const char *s;
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
if (s) {
|
||||
strcpy(lbuf, s);
|
||||
new_order = parse_order(lbuf, u->faction->locale);
|
||||
}
|
||||
*ordp = ord->next;
|
||||
ord->next = NULL;
|
||||
free_order(ord);
|
||||
|
@ -4054,8 +4039,7 @@ int use_cmd(unit * u, struct order *ord)
|
|||
int n, err = ENOITEM;
|
||||
const item_type *itype;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
|
||||
t = getstrtoken();
|
||||
n = atoi((const char *)t);
|
||||
|
@ -4104,8 +4088,7 @@ int pay_cmd(unit * u, struct order *ord)
|
|||
}
|
||||
else {
|
||||
param_t p;
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
p = getparam(u->faction->locale);
|
||||
if (p == P_NOT) {
|
||||
unit *owner = building_owner(u->building);
|
||||
|
@ -4127,16 +4110,16 @@ static int reserve_i(unit * u, struct order *ord, int flags)
|
|||
const resource_type *rtype;
|
||||
const char *s;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
count = atoip((const char *)s);
|
||||
count = s ? atoip(s) : 0;
|
||||
para = findparam(s, u->faction->locale);
|
||||
|
||||
if (count == 0 && para == P_EACH) {
|
||||
count = getint() * u->number;
|
||||
}
|
||||
rtype = findresourcetype(getstrtoken(), u->faction->locale);
|
||||
s = getstrtoken();
|
||||
rtype = s ? findresourcetype(s, u->faction->locale) : 0;
|
||||
if (rtype == NULL)
|
||||
return 0;
|
||||
|
||||
|
@ -4169,8 +4152,7 @@ int claim_cmd(unit * u, struct order *ord)
|
|||
int n;
|
||||
const item_type *itype;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
|
||||
t = getstrtoken();
|
||||
n = atoi((const char *)t);
|
||||
|
@ -4436,8 +4418,7 @@ int siege_cmd(unit * u, order * ord)
|
|||
resource_type *rt_catapultammo = NULL;
|
||||
resource_type *rt_catapult = NULL;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
b = getbuilding(r);
|
||||
|
||||
if (!b) {
|
||||
|
|
|
@ -243,6 +243,29 @@ static void test_reserve_cmd(CuTest *tc) {
|
|||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_new_units(CuTest *tc) {
|
||||
unit *u;
|
||||
faction *f;
|
||||
region *r;
|
||||
order *ord;
|
||||
const struct locale *loc;
|
||||
test_cleanup();
|
||||
test_create_world();
|
||||
f = test_create_faction(rc_find("human"));
|
||||
r = findregion(0, 0);
|
||||
assert(r && f);
|
||||
u = test_create_unit(f, r);
|
||||
assert(u && !u->next);
|
||||
loc = get_locale("de");
|
||||
assert(loc);
|
||||
ord = create_order(K_MAKETEMP, loc, "hurr");
|
||||
assert(ord);
|
||||
u->orders = ord;
|
||||
new_units();
|
||||
CuAssertPtrNotNull(tc, u->next);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_reserve_self(CuTest *tc) {
|
||||
unit *u1, *u2;
|
||||
faction *f;
|
||||
|
@ -286,6 +309,7 @@ CuSuite *get_laws_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_unit_limit);
|
||||
SUITE_ADD_TEST(suite, test_reserve_self);
|
||||
SUITE_ADD_TEST(suite, test_reserve_cmd);
|
||||
SUITE_ADD_TEST(suite, test_new_units);
|
||||
SUITE_ADD_TEST(suite, test_cannot_create_unit_above_limit);
|
||||
return suite;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
**/
|
||||
|
||||
#include <autoconf.h>
|
||||
#include <platform.h>
|
||||
#include <util/log.h>
|
||||
|
||||
|
@ -32,8 +31,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include "build.h"
|
||||
#include "bindings.h"
|
||||
#include "races/races.h"
|
||||
#include "spells/spells.h"
|
||||
#include "spells/borders.h"
|
||||
#include "spells.h"
|
||||
|
||||
#include <lua.h>
|
||||
#include <assert.h>
|
||||
|
@ -267,7 +265,6 @@ int main(int argc, char **argv)
|
|||
L = lua_init();
|
||||
game_init();
|
||||
register_races();
|
||||
register_borders();
|
||||
register_spells();
|
||||
bind_monsters(L);
|
||||
err = eressea_run(L, luafile);
|
||||
|
|
|
@ -34,17 +34,17 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/item.h>
|
||||
#include <kernel/magic.h>
|
||||
#include <kernel/messages.h>
|
||||
#include <kernel/move.h>
|
||||
#include <kernel/order.h>
|
||||
#include <kernel/plane.h>
|
||||
#include <kernel/pool.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/reports.h>
|
||||
#include <kernel/terrain.h>
|
||||
#include <kernel/terrainid.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
#include <move.h>
|
||||
|
||||
/* util include */
|
||||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
|
|
|
@ -515,6 +515,7 @@ int autoseed(newfaction ** players, int nsize, int max_agediff)
|
|||
static const terrain_type **terrainarr = 0;
|
||||
static int *distribution;
|
||||
|
||||
assert(players);
|
||||
if (nterrains < 0) {
|
||||
int n = 0;
|
||||
const terrain_type *terrain = terrains();
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
/* kernel includes */
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/reports.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/messages.h>
|
||||
|
|
|
@ -28,7 +28,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/connection.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/move.h>
|
||||
#include <kernel/messages.h>
|
||||
#include <kernel/order.h>
|
||||
#include <kernel/plane.h>
|
||||
|
@ -38,6 +37,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/unit.h>
|
||||
#include <kernel/faction.h>
|
||||
|
||||
#include <move.h>
|
||||
|
||||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
|
|
|
@ -164,7 +164,7 @@ void score(void)
|
|||
f->score, f->score - average_score_of_age(f->age, f->age / 24 + 1),
|
||||
((float)f->score / (float)allscores) * 100.0,
|
||||
(float)f->score / f->num_total,
|
||||
f->name, LOC(default_locale, rc_name(f->race, 0)), factionid(f),
|
||||
f->name, LOC(default_locale, rc_name(f->race, NAME_SINGULAR)), factionid(f),
|
||||
f->age);
|
||||
}
|
||||
fclose(scoreFP);
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
#include <kernel/building.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/move.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
#include <move.h>
|
||||
|
||||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
|
|
|
@ -23,6 +23,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
/* gamecode includes */
|
||||
#include "economy.h"
|
||||
#include "give.h"
|
||||
#include "move.h"
|
||||
|
||||
/* triggers includes */
|
||||
#include <triggers/removecurse.h>
|
||||
|
@ -37,14 +38,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/messages.h>
|
||||
#include <kernel/move.h>
|
||||
#include <kernel/names.h>
|
||||
#include <kernel/order.h>
|
||||
#include <kernel/pathfinder.h>
|
||||
#include <kernel/pool.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/reports.h>
|
||||
#include <kernel/terrain.h>
|
||||
#include <kernel/terrainid.h>
|
||||
#include <kernel/unit.h>
|
||||
|
|
|
@ -40,18 +40,17 @@
|
|||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/messages.h>
|
||||
#include <kernel/move.h>
|
||||
#include <kernel/names.h>
|
||||
#include <kernel/order.h>
|
||||
#include <kernel/pathfinder.h>
|
||||
#include <kernel/pool.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/reports.h>
|
||||
#include <kernel/terrain.h>
|
||||
#include <kernel/terrainid.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
#include <move.h>
|
||||
|
||||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
|
@ -132,6 +131,10 @@ static void reduce_weight(unit * u)
|
|||
}
|
||||
}
|
||||
|
||||
static float monster_attack_chance(void) {
|
||||
return get_param_flt(global.parameters, "rules.monsters.attack_chance", 0.4f);
|
||||
}
|
||||
|
||||
static order *monster_attack(unit * u, const unit * target)
|
||||
{
|
||||
if (u->region != target->region)
|
||||
|
@ -171,7 +174,7 @@ static order *get_money_for_dragon(region * r, unit * u, int wanted)
|
|||
/* falls der drache launisch ist, oder das regionssilber knapp, greift er alle an */
|
||||
n = 0;
|
||||
for (u2 = r->units; u2; u2 = u2->next) {
|
||||
if (u2->faction != u->faction && cansee(u->faction, r, u2, 0)) {
|
||||
if (inside_building(u2)!=u->building && u2->faction != u->faction && cansee(u->faction, r, u2, 0)) {
|
||||
int m = get_money(u2);
|
||||
if (m == 0 || is_guard(u2, GUARD_TAX))
|
||||
continue;
|
||||
|
@ -533,7 +536,7 @@ static void monster_attacks(unit * u)
|
|||
unit *u2;
|
||||
|
||||
for (u2 = r->units; u2; u2 = u2->next) {
|
||||
if (cansee(u->faction, r, u2, 0) && u2->faction != u->faction
|
||||
if (cansee(u->faction, r, u2, 0) && u2->faction != u->faction && inside_building(u2)!=u->building
|
||||
&& chance(0.75)) {
|
||||
order *ord = monster_attack(u, u2);
|
||||
if (ord)
|
||||
|
@ -747,7 +750,7 @@ void plan_monsters(faction * f)
|
|||
|
||||
for (r = regions; r; r = r->next) {
|
||||
unit *u;
|
||||
double attack_chance = MONSTERATTACK;
|
||||
double attack_chance = monster_attack_chance();
|
||||
bool attacking = false;
|
||||
|
||||
for (u = r->units; u; u = u->next) {
|
||||
|
@ -915,7 +918,7 @@ void spawn_dragons(void)
|
|||
if (verbosity >= 2) {
|
||||
log_printf(stdout, "%d %s in %s.\n", u->number,
|
||||
LOC(default_locale,
|
||||
rc_name(u_race(u), u->number != 1)), regionname(r, NULL));
|
||||
rc_name(u_race(u), (u->number==1) ? NAME_SINGULAR:NAME_PLURAL)), regionname(r, NULL));
|
||||
}
|
||||
|
||||
name_unit(u);
|
||||
|
@ -990,7 +993,7 @@ void spawn_undead(void)
|
|||
if (verbosity >= 2) {
|
||||
log_printf(stdout, "%d %s in %s.\n", u->number,
|
||||
LOC(default_locale,
|
||||
rc_name(u_race(u), u->number != 1)), regionname(r, NULL));
|
||||
rc_name(u_race(u), (u->number == 1) ? NAME_SINGULAR : NAME_PLURAL)), regionname(r, NULL));
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
@ -20,31 +20,33 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include "move.h"
|
||||
|
||||
#include "alchemy.h"
|
||||
#include "connection.h"
|
||||
#include "build.h"
|
||||
#include "building.h"
|
||||
#include "calendar.h"
|
||||
#include "curse.h"
|
||||
#include "direction.h"
|
||||
#include "faction.h"
|
||||
#include "item.h"
|
||||
#include "magic.h"
|
||||
#include "messages.h"
|
||||
#include "order.h"
|
||||
#include "plane.h"
|
||||
#include "race.h"
|
||||
#include "region.h"
|
||||
#include "render.h"
|
||||
#include "reports.h"
|
||||
#include "save.h"
|
||||
#include "ship.h"
|
||||
#include "alchemy.h"
|
||||
#include "vortex.h"
|
||||
|
||||
#include <kernel/build.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/calendar.h>
|
||||
#include <kernel/connection.h>
|
||||
#include <kernel/curse.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/magic.h>
|
||||
#include <kernel/messages.h>
|
||||
#include <kernel/order.h>
|
||||
#include <kernel/plane.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/render.h>
|
||||
#include <kernel/save.h>
|
||||
#include <kernel/ship.h>
|
||||
#include <kernel/teleport.h>
|
||||
#include <kernel/terrain.h>
|
||||
#include <kernel/terrainid.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
#include "direction.h"
|
||||
#include "skill.h"
|
||||
#include "terrain.h"
|
||||
#include "terrainid.h"
|
||||
#include "teleport.h"
|
||||
#include "unit.h"
|
||||
|
||||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
|
@ -58,6 +60,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/rand.h>
|
||||
#include <util/rng.h>
|
||||
|
||||
#include <stealth.h>
|
||||
|
||||
#include <storage.h>
|
||||
|
||||
/* attributes includes */
|
||||
|
@ -540,6 +544,36 @@ void travelthru(const unit * u, region * r)
|
|||
#endif
|
||||
}
|
||||
|
||||
static direction_t
|
||||
koor_reldirection(int ax, int ay, int bx, int by, const struct plane *pl)
|
||||
{
|
||||
int dir;
|
||||
for (dir = 0; dir != MAXDIRECTIONS; ++dir) {
|
||||
int x = ax + delta_x[dir];
|
||||
int y = ay + delta_y[dir];
|
||||
pnormalize(&x, &y, pl);
|
||||
if (bx == x && by == y)
|
||||
return (direction_t)dir;
|
||||
}
|
||||
return NODIRECTION;
|
||||
}
|
||||
|
||||
direction_t reldirection(const region * from, const region * to)
|
||||
{
|
||||
plane *pl = rplane(from);
|
||||
if (pl == rplane(to)) {
|
||||
direction_t dir = koor_reldirection(from->x, from->y, to->x, to->y, pl);
|
||||
|
||||
if (dir == NODIRECTION) {
|
||||
spec_direction *sd = special_direction(from, to);
|
||||
if (sd != NULL && sd->active)
|
||||
return D_SPECIAL;
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
return NODIRECTION;
|
||||
}
|
||||
|
||||
static void leave_trail(ship * sh, region * from, region_list * route)
|
||||
{
|
||||
region *r = from;
|
||||
|
@ -1035,6 +1069,44 @@ unit *is_guarded(region * r, unit * u, unsigned int mask)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int movewhere(const unit * u, const char *token, region * r, region ** resultp)
|
||||
{
|
||||
region *r2;
|
||||
direction_t d;
|
||||
|
||||
if (!token || *token == '\0') {
|
||||
*resultp = NULL;
|
||||
return E_MOVE_OK;
|
||||
}
|
||||
|
||||
d = get_direction(token, u->faction->locale);
|
||||
switch (d) {
|
||||
case D_PAUSE:
|
||||
*resultp = r;
|
||||
break;
|
||||
|
||||
case NODIRECTION:
|
||||
token = (const char *)get_translation(u->faction->locale, token, UT_SPECDIR);
|
||||
if (!token) {
|
||||
return E_MOVE_NOREGION;
|
||||
}
|
||||
r2 = find_special_direction(r, token);
|
||||
if (r2 == NULL) {
|
||||
return E_MOVE_NOREGION;
|
||||
}
|
||||
*resultp = r2;
|
||||
break;
|
||||
|
||||
default:
|
||||
r2 = rconnect(r, d);
|
||||
if (r2 == NULL || move_blocked(u, r, r2)) {
|
||||
return E_MOVE_BLOCKED;
|
||||
}
|
||||
*resultp = r2;
|
||||
}
|
||||
return E_MOVE_OK;
|
||||
}
|
||||
|
||||
static const char *shortdirections[MAXDIRECTIONS] = {
|
||||
"dir_nw",
|
||||
"dir_ne",
|
||||
|
@ -1060,8 +1132,7 @@ static void cycle_route(order * ord, unit * u, int gereist)
|
|||
return;
|
||||
tail[0] = '\0';
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
|
||||
neworder[0] = 0;
|
||||
for (cm = 0;; ++cm) {
|
||||
|
@ -1142,8 +1213,7 @@ static bool transport(unit * ut, unit * u)
|
|||
|
||||
for (ord = ut->orders; ord; ord = ord->next) {
|
||||
if (getkeyword(ord) == K_TRANSPORT) {
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
if (getunit(ut->region, ut->faction) == u) {
|
||||
return true;
|
||||
}
|
||||
|
@ -1176,8 +1246,7 @@ static void init_transportation(void)
|
|||
&& !fval(u, UFL_NOTMOVING) && !LongHunger(u)) {
|
||||
unit *ut;
|
||||
|
||||
init_tokens(u->thisorder);
|
||||
skip_token();
|
||||
init_order(u->thisorder);
|
||||
ut = getunit(r, u->faction);
|
||||
if (ut == NULL) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder,
|
||||
|
@ -1207,8 +1276,7 @@ static void init_transportation(void)
|
|||
|
||||
for (ord = u->orders; ord; ord = ord->next) {
|
||||
if (getkeyword(ord) == K_TRANSPORT) {
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
for (;;) {
|
||||
unit *ut = getunit(r, u->faction);
|
||||
|
||||
|
@ -1216,8 +1284,7 @@ static void init_transportation(void)
|
|||
break;
|
||||
if (getkeyword(ut->thisorder) == K_DRIVE && can_move(ut)
|
||||
&& !fval(ut, UFL_NOTMOVING) && !LongHunger(ut)) {
|
||||
init_tokens(ut->thisorder);
|
||||
skip_token();
|
||||
init_order(ut->thisorder);
|
||||
if (getunit(r, ut->faction) == u) {
|
||||
w += weight(ut);
|
||||
}
|
||||
|
@ -2088,8 +2155,7 @@ static const region_list *travel_i(unit * u, const region_list * route_begin,
|
|||
if (getkeyword(ord) != K_TRANSPORT)
|
||||
continue;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
ut = getunit(r, u->faction);
|
||||
if (ut != NULL) {
|
||||
if (getkeyword(ut->thisorder) == K_DRIVE) {
|
||||
|
@ -2104,8 +2170,7 @@ static const region_list *travel_i(unit * u, const region_list * route_begin,
|
|||
bool found = false;
|
||||
|
||||
if (!fval(ut, UFL_NOTMOVING) && !LongHunger(ut)) {
|
||||
init_tokens(ut->thisorder);
|
||||
skip_token();
|
||||
init_order(ut->thisorder);
|
||||
if (getunit(u->region, ut->faction) == u) {
|
||||
const region_list *route_to =
|
||||
travel_route(ut, route_begin, route_end, ord,
|
||||
|
@ -2301,8 +2366,7 @@ static void piracy_cmd(unit * u, struct order *ord)
|
|||
/* Feststellen, ob schon ein anderer alliierter Pirat ein
|
||||
* Ziel gefunden hat. */
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
if (s != NULL && *s) {
|
||||
il = intlist_init();
|
||||
|
@ -2389,8 +2453,7 @@ static void piracy_cmd(unit * u, struct order *ord)
|
|||
LOC(u->faction->locale, directions[target_dir])));
|
||||
|
||||
/* Bewegung ausführen */
|
||||
init_tokens(u->thisorder);
|
||||
skip_token();
|
||||
init_order(u->thisorder);
|
||||
move(u, true);
|
||||
}
|
||||
|
||||
|
@ -2543,8 +2606,7 @@ static void move_hunters(void)
|
|||
if (getkeyword(ord) == K_FOLLOW) {
|
||||
param_t p;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
p = getparam(u->faction->locale);
|
||||
if (p != P_SHIP) {
|
||||
if (p != P_UNIT) {
|
||||
|
@ -2666,15 +2728,13 @@ void movement(void)
|
|||
else {
|
||||
if (ships) {
|
||||
if (u->ship && ship_owner(u->ship) == u) {
|
||||
init_tokens(u->thisorder);
|
||||
skip_token();
|
||||
init_order(u->thisorder);
|
||||
move(u, false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!u->ship || ship_owner(u->ship) != u) {
|
||||
init_tokens(u->thisorder);
|
||||
skip_token();
|
||||
init_order(u->thisorder);
|
||||
move(u, false);
|
||||
}
|
||||
}
|
||||
|
@ -2729,10 +2789,10 @@ void follow_unit(unit * u)
|
|||
const struct locale *lang = u->faction->locale;
|
||||
|
||||
if (getkeyword(ord) == K_FOLLOW) {
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
int id;
|
||||
param_t p = getparam(lang);
|
||||
param_t p;
|
||||
init_order(ord);
|
||||
p = getparam(lang);
|
||||
if (p == P_UNIT) {
|
||||
id = read_unitid(u->faction, r);
|
||||
if (a != NULL) {
|
||||
|
@ -2753,7 +2813,7 @@ void follow_unit(unit * u)
|
|||
a = NULL;
|
||||
}
|
||||
}
|
||||
if (p == P_SHIP) {
|
||||
else if (p == P_SHIP) {
|
||||
id = getshipid();
|
||||
if (id <= 0) {
|
||||
/* cmistake(u, ord, 20, MSG_MOVE); */
|
92
src/move.h
Normal file
92
src/move.h
Normal file
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
**/
|
||||
|
||||
#ifndef H_KRNL_MOVEMENT
|
||||
#define H_KRNL_MOVEMENT
|
||||
|
||||
#include "direction.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct unit;
|
||||
struct ship;
|
||||
struct building_type;
|
||||
|
||||
extern struct attrib_type at_speedup;
|
||||
|
||||
/* die Zahlen sind genau äquivalent zu den race Flags */
|
||||
#define MV_CANNOTMOVE (1<<5)
|
||||
#define MV_FLY (1<<7) /* kann fliegen */
|
||||
#define MV_SWIM (1<<8) /* kann schwimmen */
|
||||
#define MV_WALK (1<<9) /* kann über Land gehen */
|
||||
|
||||
/* Die tragekapaz. ist hardcodiert mit defines, da es bis jetzt sowieso nur 2
|
||||
** objekte gibt, die etwas tragen. */
|
||||
#define SILVERWEIGHT 1
|
||||
#define SCALEWEIGHT 100 /* Faktor, um den die Anzeige von gewichten
|
||||
* * skaliert wird */
|
||||
#define HORSECAPACITY 7000
|
||||
#define WAGONCAPACITY 14000
|
||||
|
||||
#define HORSESNEEDED 2
|
||||
|
||||
/* ein mensch wiegt 10, traegt also 5, ein pferd wiegt 50, traegt also 20. ein
|
||||
** wagen wird von zwei pferden gezogen und traegt total 140, davon 40 die
|
||||
** pferde, macht nur noch 100, aber samt eigenem gewicht (40) macht also 140. */
|
||||
|
||||
/* movewhere error codes */
|
||||
enum {
|
||||
E_MOVE_OK = 0, /* possible to move */
|
||||
E_MOVE_NOREGION, /* no region exists in this direction */
|
||||
E_MOVE_BLOCKED /* cannot see this region, there is a blocking connection. */
|
||||
};
|
||||
int movewhere(const struct unit *u, const char *token,
|
||||
struct region *r, struct region **resultp);
|
||||
direction_t reldirection(const struct region *from, const struct region *to);
|
||||
|
||||
int personcapacity(const struct unit *u);
|
||||
void movement(void);
|
||||
void run_to(struct unit *u, struct region *to);
|
||||
struct unit *is_guarded(struct region *r, struct unit *u, unsigned int mask);
|
||||
bool is_guard(const struct unit *u, int mask);
|
||||
int enoughsailors(const struct ship *sh, const struct region *r);
|
||||
bool canswim(struct unit *u);
|
||||
bool canfly(struct unit *u);
|
||||
struct unit *get_captain(const struct ship *sh);
|
||||
void travelthru(const struct unit *u, struct region *r);
|
||||
struct ship *move_ship(struct ship *sh, struct region *from,
|
||||
struct region *to, struct region_list *route);
|
||||
int walkingcapacity(const struct unit *u);
|
||||
void follow_unit(struct unit *u);
|
||||
bool buildingtype_exists(const struct region *r,
|
||||
const struct building_type *bt, bool working);
|
||||
struct unit *owner_buildingtyp(const struct region *r,
|
||||
const struct building_type *bt);
|
||||
|
||||
#define SA_HARBOUR 2
|
||||
#define SA_COAST 1
|
||||
#define SA_NO_INSECT -1
|
||||
#define SA_NO_COAST -2
|
||||
|
||||
int check_ship_allowed(struct ship *sh, const struct region * r);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,8 +1,9 @@
|
|||
#include <kernel/types.h>
|
||||
#include <platform.h>
|
||||
#include <stdlib.h>
|
||||
#include "move.h"
|
||||
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/move.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/ship.h>
|
||||
#include <kernel/terrain.h>
|
482
src/names.c
Normal file
482
src/names.c
Normal file
|
@ -0,0 +1,482 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
**/
|
||||
|
||||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include "names.h"
|
||||
|
||||
/* kernel includes */
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/magic.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/terrain.h>
|
||||
#include <kernel/terrainid.h>
|
||||
|
||||
/* util includes */
|
||||
#include <util/base36.h>
|
||||
#include <util/bsdstring.h>
|
||||
#include <util/functions.h>
|
||||
#include <util/language.h>
|
||||
#include <util/rng.h>
|
||||
#include <util/unicode.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <wctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static const char *describe_braineater(unit * u, const struct locale *lang)
|
||||
{
|
||||
return LOC(lang, "describe_braineater");
|
||||
}
|
||||
|
||||
static const char *make_names(const char *monster, int *num_postfix,
|
||||
int pprefix, int *num_name, int *num_prefix, int ppostfix)
|
||||
{
|
||||
int uv, uu, un;
|
||||
static char name[NAMESIZE + 1]; // FIXME: static return value
|
||||
char zText[32];
|
||||
const char *str;
|
||||
|
||||
if (*num_prefix == 0) {
|
||||
|
||||
for (*num_prefix = 0;; ++*num_prefix) {
|
||||
sprintf(zText, "%s_prefix_%d", monster, *num_prefix);
|
||||
str = locale_getstring(default_locale, zText);
|
||||
if (str == NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
for (*num_name = 0;; ++*num_name) {
|
||||
sprintf(zText, "%s_name_%d", monster, *num_name);
|
||||
str = locale_getstring(default_locale, zText);
|
||||
if (str == NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
for (*num_postfix = 0;; ++*num_postfix) {
|
||||
sprintf(zText, "%s_postfix_%d", monster, *num_postfix);
|
||||
str = locale_getstring(default_locale, zText);
|
||||
if (str == NULL)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (*num_name == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* nur 50% aller Namen haben "Vor-Teil" */
|
||||
uv = rng_int() % (*num_prefix * pprefix);
|
||||
|
||||
uu = rng_int() % *num_name;
|
||||
|
||||
/* nur 50% aller Namen haben "Nach-Teil", wenn kein Vor-Teil */
|
||||
if (uv >= *num_prefix) {
|
||||
un = rng_int() % *num_postfix;
|
||||
}
|
||||
else {
|
||||
un = rng_int() % (*num_postfix * ppostfix);
|
||||
}
|
||||
|
||||
name[0] = 0;
|
||||
if (uv < *num_prefix) {
|
||||
sprintf(zText, "%s_prefix_%d", monster, uv);
|
||||
str = locale_getstring(default_locale, zText);
|
||||
if (str) {
|
||||
strcat(name, (const char *)str);
|
||||
strcat(name, " ");
|
||||
}
|
||||
}
|
||||
|
||||
sprintf(zText, "%s_name_%d", monster, uu);
|
||||
str = locale_getstring(default_locale, zText);
|
||||
if (str)
|
||||
strcat(name, (const char *)str);
|
||||
|
||||
if (un < *num_postfix) {
|
||||
sprintf(zText, "%s_postfix_%d", monster, un);
|
||||
str = locale_getstring(default_locale, zText);
|
||||
if (str) {
|
||||
strcat(name, " ");
|
||||
strcat(name, (const char *)str);
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
static const char *undead_name(const unit * u)
|
||||
{
|
||||
static int num_postfix, num_name, num_prefix;
|
||||
return make_names("undead", &num_postfix, 2, &num_name, &num_prefix, 2);
|
||||
}
|
||||
|
||||
static const char *skeleton_name(const unit * u)
|
||||
{
|
||||
static int num_postfix, num_name, num_prefix;
|
||||
return make_names("skeleton", &num_postfix, 5, &num_name, &num_prefix, 2);
|
||||
}
|
||||
|
||||
static const char *zombie_name(const unit * u)
|
||||
{
|
||||
static int num_postfix, num_name, num_prefix;
|
||||
return make_names("zombie", &num_postfix, 5, &num_name, &num_prefix, 2);
|
||||
}
|
||||
|
||||
static const char *ghoul_name(const unit * u)
|
||||
{
|
||||
static int num_postfix, num_name, num_prefix;
|
||||
return make_names("ghoul", &num_postfix, 5, &num_name, &num_prefix, 4);
|
||||
}
|
||||
|
||||
/* Drachen */
|
||||
|
||||
#define SIL1 15
|
||||
|
||||
const char *silbe1[SIL1] = {
|
||||
"Tar",
|
||||
"Ter",
|
||||
"Tor",
|
||||
"Pan",
|
||||
"Par",
|
||||
"Per",
|
||||
"Nim",
|
||||
"Nan",
|
||||
"Nun",
|
||||
"Gor",
|
||||
"For",
|
||||
"Fer",
|
||||
"Kar",
|
||||
"Kur",
|
||||
"Pen",
|
||||
};
|
||||
|
||||
#define SIL2 19
|
||||
|
||||
const char *silbe2[SIL2] = {
|
||||
"da",
|
||||
"do",
|
||||
"dil",
|
||||
"di",
|
||||
"dor",
|
||||
"dar",
|
||||
"ra",
|
||||
"ran",
|
||||
"ras",
|
||||
"ro",
|
||||
"rum",
|
||||
"rin",
|
||||
"ten",
|
||||
"tan",
|
||||
"ta",
|
||||
"tor",
|
||||
"gur",
|
||||
"ga",
|
||||
"gas",
|
||||
};
|
||||
|
||||
#define SIL3 14
|
||||
|
||||
const char *silbe3[SIL3] = {
|
||||
"gul",
|
||||
"gol",
|
||||
"dol",
|
||||
"tan",
|
||||
"tar",
|
||||
"tur",
|
||||
"sur",
|
||||
"sin",
|
||||
"kur",
|
||||
"kor",
|
||||
"kar",
|
||||
"dul",
|
||||
"dol",
|
||||
"bus",
|
||||
};
|
||||
|
||||
static const char *generic_name(const unit * u)
|
||||
{
|
||||
const char * name = rc_name(u_race(u), (u->no == 1) ? NAME_SINGULAR : NAME_PLURAL);
|
||||
return LOC(u->faction->locale, name);
|
||||
}
|
||||
|
||||
static const char *dragon_name(const unit * u)
|
||||
{
|
||||
static char name[NAMESIZE + 1]; // FIXME: static return value
|
||||
int rnd, ter = 0;
|
||||
int anzahl = 1;
|
||||
static int num_postfix;
|
||||
char zText[32];
|
||||
const char *str;
|
||||
|
||||
if (num_postfix == 0) {
|
||||
for (num_postfix = 0;; ++num_postfix) {
|
||||
sprintf(zText, "dragon_postfix_%d", num_postfix);
|
||||
str = locale_getstring(default_locale, zText);
|
||||
if (str == NULL)
|
||||
break;
|
||||
}
|
||||
if (num_postfix == 0)
|
||||
num_postfix = -1;
|
||||
}
|
||||
if (num_postfix <= 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (u) {
|
||||
region *r = u->region;
|
||||
anzahl = u->number;
|
||||
switch (rterrain(r)) {
|
||||
case T_PLAIN:
|
||||
ter = 1;
|
||||
break;
|
||||
case T_MOUNTAIN:
|
||||
ter = 2;
|
||||
break;
|
||||
case T_DESERT:
|
||||
ter = 3;
|
||||
break;
|
||||
case T_SWAMP:
|
||||
ter = 4;
|
||||
break;
|
||||
case T_GLACIER:
|
||||
ter = 5;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
rnd = num_postfix / 6;
|
||||
rnd = (rng_int() % rnd) + ter * rnd;
|
||||
|
||||
sprintf(zText, "dragon_postfix_%d", rnd);
|
||||
|
||||
str = locale_getstring(default_locale, zText);
|
||||
assert(str != NULL);
|
||||
|
||||
if (anzahl > 1) {
|
||||
const char *no_article = strchr((const char *)str, ' ');
|
||||
assert(no_article);
|
||||
/* TODO: GERMAN */
|
||||
sprintf(name, "Die %sn von %s", no_article + 1, rname(u->region,
|
||||
default_locale));
|
||||
}
|
||||
else {
|
||||
char n[32];
|
||||
|
||||
strcpy(n, silbe1[rng_int() % SIL1]);
|
||||
strcat(n, silbe2[rng_int() % SIL2]);
|
||||
strcat(n, silbe3[rng_int() % SIL3]);
|
||||
if (rng_int() % 5 > 2) {
|
||||
sprintf(name, "%s, %s", n, str); /* "Name, der Titel" */
|
||||
}
|
||||
else {
|
||||
strcpy(name, (const char *)str); /* "Der Titel Name" */
|
||||
name[0] = (char)toupper(name[0]); /* TODO: UNICODE - should use towupper() */
|
||||
strcat(name, " ");
|
||||
strcat(name, n);
|
||||
}
|
||||
if (u && (rng_int() % 3 == 0)) {
|
||||
strcat(name, " von ");
|
||||
strcat(name, (const char *)rname(u->region, default_locale));
|
||||
}
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
/* Dracoide */
|
||||
|
||||
#define DRAC_PRE 13
|
||||
static const char *drac_pre[DRAC_PRE] = {
|
||||
"Siss",
|
||||
"Xxaa",
|
||||
"Shht",
|
||||
"X'xixi",
|
||||
"Xar",
|
||||
"X'zish",
|
||||
"X",
|
||||
"Sh",
|
||||
"R",
|
||||
"Z",
|
||||
"Y",
|
||||
"L",
|
||||
"Ck",
|
||||
};
|
||||
|
||||
#define DRAC_MID 12
|
||||
static const char *drac_mid[DRAC_MID] = {
|
||||
"siss",
|
||||
"xxaa",
|
||||
"shht",
|
||||
"xxi",
|
||||
"xar",
|
||||
"x'zish",
|
||||
"x",
|
||||
"sh",
|
||||
"r",
|
||||
"z'ck",
|
||||
"y",
|
||||
"rl"
|
||||
};
|
||||
|
||||
#define DRAC_SUF 10
|
||||
static const char *drac_suf[DRAC_SUF] = {
|
||||
"xil",
|
||||
"shh",
|
||||
"s",
|
||||
"x",
|
||||
"arr",
|
||||
"lll",
|
||||
"lll",
|
||||
"shack",
|
||||
"ck",
|
||||
"k"
|
||||
};
|
||||
|
||||
static const char *dracoid_name(const unit * u)
|
||||
{
|
||||
static char name[NAMESIZE + 1]; // FIXME: static return value
|
||||
int mid_syllabels;
|
||||
|
||||
u = u;
|
||||
/* Wieviele Mittelteile? */
|
||||
|
||||
mid_syllabels = rng_int() % 4;
|
||||
|
||||
strcpy(name, drac_pre[rng_int() % DRAC_PRE]);
|
||||
while (mid_syllabels > 0) {
|
||||
mid_syllabels--;
|
||||
if (rng_int() % 10 < 4)
|
||||
strcat(name, "'");
|
||||
strcat(name, drac_mid[rng_int() % DRAC_MID]);
|
||||
}
|
||||
strcat(name, drac_suf[rng_int() % DRAC_SUF]);
|
||||
return name;
|
||||
}
|
||||
|
||||
/** returns an abbreviation of a string.
|
||||
* TODO: buflen is being ignored */
|
||||
|
||||
const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars)
|
||||
{
|
||||
const char *p = s;
|
||||
char *bufp;
|
||||
unsigned int c = 0;
|
||||
size_t bpt, i;
|
||||
ucs4_t ucs;
|
||||
size_t size;
|
||||
int result;
|
||||
|
||||
/* Prüfen, ob Kurz genug */
|
||||
|
||||
if (strlen(s) <= maxchars) {
|
||||
return s;
|
||||
}
|
||||
/* Anzahl der Wörter feststellen */
|
||||
|
||||
while (*p != 0) {
|
||||
|
||||
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
||||
|
||||
/* Leerzeichen überspringen */
|
||||
while (*p != 0 && !iswalnum((wint_t)ucs)) {
|
||||
p += size;
|
||||
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
||||
}
|
||||
|
||||
/* Counter erhöhen */
|
||||
if (*p != 0)
|
||||
++c;
|
||||
|
||||
/* alnums überspringen */
|
||||
while (*p != 0 && iswalnum((wint_t)ucs)) {
|
||||
p += size;
|
||||
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
||||
}
|
||||
}
|
||||
|
||||
/* Buchstaben pro Teilkürzel = _max(1,max/AnzWort) */
|
||||
|
||||
bpt = _max(1, maxchars / c);
|
||||
|
||||
/* Einzelne Wörter anspringen und jeweils die ersten BpT kopieren */
|
||||
|
||||
p = s;
|
||||
c = 0;
|
||||
bufp = buf;
|
||||
|
||||
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
||||
|
||||
while (*p != 0 && c < maxchars) {
|
||||
/* Leerzeichen überspringen */
|
||||
|
||||
while (*p != 0 && !iswalnum((wint_t)ucs)) {
|
||||
p += size;
|
||||
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
||||
}
|
||||
|
||||
/* alnums übertragen */
|
||||
|
||||
for (i = 0; i < bpt && *p != 0 && iswalnum((wint_t)ucs); ++i) {
|
||||
memcpy(bufp, p, size);
|
||||
p += size;
|
||||
bufp += size;
|
||||
++c;
|
||||
|
||||
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
||||
}
|
||||
|
||||
/* Bis zum nächsten Leerzeichen */
|
||||
|
||||
while (c < maxchars && *p != 0 && iswalnum((wint_t)ucs)) {
|
||||
p += size;
|
||||
result = unicode_utf8_to_ucs4(&ucs, p, &size);
|
||||
assert(result == 0 || "damnit, we're not handling invalid input here!");
|
||||
}
|
||||
}
|
||||
|
||||
*bufp = 0;
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
void register_names(void)
|
||||
{
|
||||
register_function((pf_generic)describe_braineater, "describe_braineater");
|
||||
/* function name
|
||||
* generate a name for a nonplayerunit
|
||||
* race->generate_name() */
|
||||
register_function((pf_generic)undead_name, "nameundead");
|
||||
register_function((pf_generic)skeleton_name, "nameskeleton");
|
||||
register_function((pf_generic)zombie_name, "namezombie");
|
||||
register_function((pf_generic)ghoul_name, "nameghoul");
|
||||
register_function((pf_generic)dragon_name, "namedragon");
|
||||
register_function((pf_generic)dracoid_name, "namedracoid");
|
||||
register_function((pf_generic)generic_name, "namegeneric");
|
||||
}
|
|
@ -22,13 +22,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
extern void register_names(void);
|
||||
const char *undead_name(const struct unit *u);
|
||||
const char *skeleton_name(const struct unit *u);
|
||||
const char *zombie_name(const struct unit *u);
|
||||
const char *ghoul_name(const struct unit *u);
|
||||
const char *dragon_name(const struct unit *u);
|
||||
const char *dracoid_name(const struct unit *u);
|
||||
const char *generic_name(const struct unit *u);
|
||||
const char *abkz(const char *s, char *buf, size_t size, size_t maxchars);
|
||||
|
||||
#ifdef __cplusplus
|
|
@ -43,7 +43,7 @@ static void oldfamiliars(unit * u)
|
|||
char fname[64];
|
||||
/* these familiars have no special skills.
|
||||
*/
|
||||
_snprintf(fname, sizeof(fname), "%s_familiar", u_race(u)->_name[0]);
|
||||
_snprintf(fname, sizeof(fname), "%s_familiar", u_race(u)->_name);
|
||||
create_mage(u, M_GRAY);
|
||||
equip_unit(u, get_equipment(fname));
|
||||
}
|
||||
|
|
|
@ -22,10 +22,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
#include "economy.h"
|
||||
#include "monster.h"
|
||||
#include "move.h"
|
||||
#include "alchemy.h"
|
||||
|
||||
/* kernel includes */
|
||||
#include <kernel/alchemy.h>
|
||||
#include <kernel/battle.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/curse.h>
|
||||
#include <kernel/equipment.h>
|
||||
|
@ -33,8 +33,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/item.h>
|
||||
#include <kernel/magic.h>
|
||||
#include <kernel/messages.h>
|
||||
#include <kernel/move.h>
|
||||
#include <kernel/names.h>
|
||||
#include <kernel/order.h>
|
||||
#include <kernel/plane.h>
|
||||
#include <kernel/pool.h>
|
||||
|
|
80
src/report.c
80
src/report.c
|
@ -21,6 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
|
||||
#include "reports.h"
|
||||
/* modules includes */
|
||||
#include <modules/score.h>
|
||||
|
||||
|
@ -35,9 +36,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include "economy.h"
|
||||
#include "monster.h"
|
||||
#include "laws.h"
|
||||
#include "move.h"
|
||||
#include "alchemy.h"
|
||||
#include "vortex.h"
|
||||
|
||||
/* kernel includes */
|
||||
#include <kernel/alchemy.h>
|
||||
#include <kernel/ally.h>
|
||||
#include <kernel/connection.h>
|
||||
#include <kernel/build.h>
|
||||
|
@ -48,7 +51,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/group.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/messages.h>
|
||||
#include <kernel/move.h>
|
||||
#include <kernel/objtypes.h>
|
||||
#include <kernel/order.h>
|
||||
#include <kernel/plane.h>
|
||||
|
@ -56,7 +58,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/race.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/render.h>
|
||||
#include <kernel/reports.h>
|
||||
#include <kernel/resources.h>
|
||||
#include <kernel/save.h>
|
||||
#include <kernel/ship.h>
|
||||
|
@ -100,7 +101,7 @@ extern int months_per_year;
|
|||
|
||||
static char *gamedate_season(const struct locale *lang)
|
||||
{
|
||||
static char buf[256];
|
||||
static char buf[256]; // FIXME: static return value
|
||||
gamedate gd;
|
||||
|
||||
get_gamedate(turn, &gd);
|
||||
|
@ -517,7 +518,7 @@ void sparagraph(strlist ** SP, const char *s, int indent, char mark)
|
|||
|
||||
int i, j, width;
|
||||
int firstline;
|
||||
static char buf[REPORTWIDTH + 1];
|
||||
static char buf[REPORTWIDTH + 1]; // FIXME: static return value
|
||||
|
||||
width = REPORTWIDTH - indent;
|
||||
firstline = 1;
|
||||
|
@ -1127,46 +1128,47 @@ static void describe(FILE * F, const seen_region * sr, faction * f)
|
|||
/* list directions */
|
||||
|
||||
dh = false;
|
||||
for (d = 0; d != MAXDIRECTIONS; d++)
|
||||
for (d = 0; d != MAXDIRECTIONS; d++) {
|
||||
if (see[d]) {
|
||||
region *r2 = rconnect(r, d);
|
||||
if (!r2)
|
||||
continue;
|
||||
nrd--;
|
||||
if (dh) {
|
||||
char regname[4096];
|
||||
if (nrd == 0) {
|
||||
region *r2 = rconnect(r, d);
|
||||
if (!r2)
|
||||
continue;
|
||||
nrd--;
|
||||
if (dh) {
|
||||
char regname[4096];
|
||||
if (nrd == 0) {
|
||||
bytes = (int)strlcpy(bufp, " ", size);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_nb_final"), size);
|
||||
}
|
||||
else {
|
||||
bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_nb_next"), size);
|
||||
}
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
bytes = (int)strlcpy(bufp, LOC(f->locale, directions[d]), size);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
bytes = (int)strlcpy(bufp, " ", size);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_nb_final"), size);
|
||||
f_regionid(r2, f, regname, sizeof(regname));
|
||||
bytes = _snprintf(bufp, size, trailinto(r2, f->locale), regname);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
}
|
||||
else {
|
||||
bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_nb_next"), size);
|
||||
bytes = (int)strlcpy(bufp, " ", size);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
MSG(("nr_vicinitystart", "dir region", d, r2), bufp, size, f->locale,
|
||||
f);
|
||||
bufp += strlen(bufp);
|
||||
dh = true;
|
||||
}
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
bytes = (int)strlcpy(bufp, LOC(f->locale, directions[d]), size);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
bytes = (int)strlcpy(bufp, " ", size);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
f_regionid(r2, f, regname, sizeof(regname));
|
||||
bytes = _snprintf(bufp, size, trailinto(r2, f->locale), regname);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
}
|
||||
else {
|
||||
bytes = (int)strlcpy(bufp, " ", size);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
MSG(("nr_vicinitystart", "dir region", d, r2), bufp, size, f->locale,
|
||||
f);
|
||||
bufp += strlen(bufp);
|
||||
dh = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Spezielle Richtungen */
|
||||
for (a = a_find(r->attribs, &at_direction); a && a->type == &at_direction;
|
||||
a = a->next) {
|
||||
|
@ -1417,6 +1419,7 @@ static void durchreisende(FILE * F, const region * r, const faction * f)
|
|||
if (cansee_durchgezogen(f, r, u, 0)) {
|
||||
++counter;
|
||||
if (u->ship != NULL) {
|
||||
#ifdef GERMAN_FLUFF_DISABLED
|
||||
if (counter == 1) {
|
||||
bytes = (int)strlcpy(bufp, "Die ", size);
|
||||
}
|
||||
|
@ -1427,6 +1430,7 @@ static void durchreisende(FILE * F, const region * r, const faction * f)
|
|||
WARN_STATIC_BUFFER();
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
bytes = (int)strlcpy(bufp, shipname(u->ship), size);
|
||||
}
|
||||
else {
|
||||
|
@ -2174,7 +2178,7 @@ const char *charset)
|
|||
centre(F, gamedate_season(f->locale), true);
|
||||
rnl(F);
|
||||
sprintf(buf, "%s, %s/%s (%s)", factionname(f),
|
||||
LOC(f->locale, rc_name(f->race, 1)),
|
||||
LOC(f->locale, rc_name(f->race, NAME_PLURAL)),
|
||||
LOC(f->locale, mkname("school", magic_school[f->magiegebiet])), f->email);
|
||||
centre(F, buf, true);
|
||||
if (f_get_alliance(f)) {
|
||||
|
|
|
@ -29,7 +29,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/group.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/messages.h>
|
||||
#include <kernel/move.h>
|
||||
#include <kernel/order.h>
|
||||
#include <kernel/plane.h>
|
||||
#include <kernel/race.h>
|
||||
|
@ -66,6 +65,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <attributes/otherfaction.h>
|
||||
#include <attributes/racename.h>
|
||||
|
||||
#include "move.h"
|
||||
#include "stealth.h"
|
||||
|
||||
bool nocr = false;
|
||||
bool nonr = false;
|
||||
bool noreports = false;
|
||||
|
@ -107,7 +109,7 @@ const char *combatstatus[] = {
|
|||
|
||||
const char *report_kampfstatus(const unit * u, const struct locale *lang)
|
||||
{
|
||||
static char fsbuf[64];
|
||||
static char fsbuf[64]; // FIXME: static return value
|
||||
|
||||
strlcpy(fsbuf, LOC(lang, combatstatus[u->status]), sizeof(fsbuf));
|
||||
if (fval(u, UFL_NOAID)) {
|
||||
|
@ -200,37 +202,6 @@ const char **name, const char **basename, int *number, bool singular)
|
|||
}
|
||||
}
|
||||
|
||||
int *nmrs = NULL;
|
||||
|
||||
int update_nmrs(void)
|
||||
{
|
||||
int i, newplayers = 0;
|
||||
faction *f;
|
||||
int turn = global.data_turn;
|
||||
|
||||
if (nmrs == NULL)
|
||||
nmrs = malloc(sizeof(int) * (NMRTimeout() + 1));
|
||||
for (i = 0; i <= NMRTimeout(); ++i) {
|
||||
nmrs[i] = 0;
|
||||
}
|
||||
|
||||
for (f = factions; f; f = f->next) {
|
||||
if (fval(f, FFL_ISNEW)) {
|
||||
++newplayers;
|
||||
}
|
||||
else if (!is_monsters(f) && f->alive) {
|
||||
int nmr = turn - f->lastorders + 1;
|
||||
if (nmr < 0 || nmr > NMRTimeout()) {
|
||||
log_error("faction %s has %d NMRS\n", factionid(f), nmr);
|
||||
nmr = _max(0, nmr);
|
||||
nmr = _min(nmr, NMRTimeout());
|
||||
}
|
||||
++nmrs[nmr];
|
||||
}
|
||||
}
|
||||
return newplayers;
|
||||
}
|
||||
|
||||
#define ORDERS_IN_NR 1
|
||||
static size_t buforder(char *bufp, size_t size, const order * ord, int mode)
|
||||
{
|
||||
|
@ -331,14 +302,14 @@ void report_race(const struct unit *u, const char **name, const char **illusion)
|
|||
if (illusion) {
|
||||
const race *irace = u_irace(u);
|
||||
if (irace && irace != u_race(u)) {
|
||||
*illusion = irace->_name[0];
|
||||
*illusion = irace->_name;
|
||||
}
|
||||
else {
|
||||
*illusion = NULL;
|
||||
}
|
||||
}
|
||||
if (name) {
|
||||
*name = u_race(u)->_name[0];
|
||||
*name = u_race(u)->_name;
|
||||
if (fval(u_race(u), RCF_SHAPESHIFTANY)) {
|
||||
const char *str = get_racename(u->attribs);
|
||||
if (str)
|
||||
|
@ -1048,6 +1019,23 @@ void transfer_seen(quicklist ** dst, quicklist ** src)
|
|||
*src = NULL;
|
||||
}
|
||||
|
||||
int cmp_faction(const void *lhs, const void *rhs) {
|
||||
const faction *lhf = (const faction *)lhs;
|
||||
const faction *rhf = (const faction *)rhs;
|
||||
if (lhf->no == rhf->no) return 0;
|
||||
if (lhf->no > rhf->no) return 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void add_seen_faction_i(struct quicklist **flist, faction *f) {
|
||||
ql_set_insert_ex(flist, f, cmp_faction);
|
||||
}
|
||||
|
||||
void add_seen_faction(faction *self, faction *seen) {
|
||||
add_seen_faction_i(&self->seen_factions, seen);
|
||||
}
|
||||
|
||||
|
||||
static void get_addresses(report_context * ctx)
|
||||
{
|
||||
/* "TODO: travelthru" */
|
||||
|
@ -1065,7 +1053,7 @@ static void get_addresses(report_context * ctx)
|
|||
quicklist *ql = ctx->f->alliance->members;
|
||||
int qi;
|
||||
for (qi = 0; ql; ql_advance(&ql, &qi, 1)) {
|
||||
ql_set_insert(&flist, ql_get(ql, qi));
|
||||
add_seen_faction_i(&flist, (faction *)ql_get(ql, qi));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1084,7 +1072,7 @@ static void get_addresses(report_context * ctx)
|
|||
if (lastf != sf) {
|
||||
if (u->building || u->ship || (stealthmod > INT_MIN
|
||||
&& cansee(ctx->f, r, u, stealthmod))) {
|
||||
ql_set_insert(&flist, sf);
|
||||
add_seen_faction_i(&flist, sf);
|
||||
lastf = sf;
|
||||
}
|
||||
}
|
||||
|
@ -1101,7 +1089,7 @@ static void get_addresses(report_context * ctx)
|
|||
unit *u2 = (unit *)a->data.v;
|
||||
if (u2->faction == ctx->f) {
|
||||
if (cansee_unit(u2, u, stealthmod)) {
|
||||
ql_set_insert(&flist, sf);
|
||||
add_seen_faction_i(&flist, sf);
|
||||
lastf = sf;
|
||||
break;
|
||||
}
|
||||
|
@ -1120,7 +1108,7 @@ static void get_addresses(report_context * ctx)
|
|||
bool ballied = sf && sf != ctx->f && sf != lastf
|
||||
&& !fval(u, UFL_ANON_FACTION) && cansee(ctx->f, r, u, stealthmod);
|
||||
if (ballied || ALLIED(ctx->f, sf)) {
|
||||
ql_set_insert(&flist, sf);
|
||||
add_seen_faction_i(&flist, sf);
|
||||
lastf = sf;
|
||||
}
|
||||
}
|
||||
|
@ -1133,7 +1121,7 @@ static void get_addresses(report_context * ctx)
|
|||
faction *f2;
|
||||
for (f2 = factions; f2; f2 = f2->next) {
|
||||
if (f2->alliance == ctx->f->alliance) {
|
||||
ql_set_insert(&flist, f2);
|
||||
add_seen_faction_i(&flist, f2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1928,7 +1916,7 @@ f_regionid(const region * r, const faction * f, char *buffer, size_t size)
|
|||
static char *f_regionid_s(const region * r, const faction * f)
|
||||
{
|
||||
static int i = 0;
|
||||
static char bufs[4][NAMESIZE + 20];
|
||||
static char bufs[4][NAMESIZE + 20]; // FIXME: static return value
|
||||
char *buf = bufs[(++i) % 4];
|
||||
|
||||
f_regionid(r, f, buf, NAMESIZE + 20);
|
||||
|
@ -2166,7 +2154,7 @@ static void eval_race(struct opstack **stack, const void *userdata)
|
|||
const struct locale *lang = report ? report->locale : default_locale;
|
||||
int j = opop(stack).i;
|
||||
const race *r = (const race *)opop(stack).v;
|
||||
const char *c = LOC(lang, rc_name(r, j != 1));
|
||||
const char *c = LOC(lang, rc_name(r, (j == 1) ? NAME_SINGULAR : NAME_PLURAL));
|
||||
size_t len = strlen(c);
|
||||
variant var;
|
||||
|
||||
|
@ -2177,7 +2165,7 @@ static void eval_race(struct opstack **stack, const void *userdata)
|
|||
static void eval_order(struct opstack **stack, const void *userdata)
|
||||
{ /* order -> string */
|
||||
const struct order *ord = (const struct order *)opop(stack).v;
|
||||
static char buf[512];
|
||||
char buf[512];
|
||||
size_t len;
|
||||
variant var;
|
||||
|
||||
|
@ -2193,7 +2181,7 @@ static void eval_resources(struct opstack **stack, const void *userdata)
|
|||
const faction *report = (const faction *)userdata;
|
||||
const struct locale *lang = report ? report->locale : default_locale;
|
||||
const struct resource *res = (const struct resource *)opop(stack).v;
|
||||
static char buf[1024]; /* but we only use about half of this */
|
||||
char buf[1024]; /* but we only use about half of this */
|
||||
size_t size = sizeof(buf) - 1;
|
||||
variant var;
|
||||
|
||||
|
@ -2225,7 +2213,7 @@ static void eval_regions(struct opstack **stack, const void *userdata)
|
|||
int i = opop(stack).i;
|
||||
int end, begin = opop(stack).i;
|
||||
const arg_regions *regions = (const arg_regions *)opop(stack).v;
|
||||
static char buf[256];
|
||||
char buf[256];
|
||||
size_t size = sizeof(buf) - 1;
|
||||
variant var;
|
||||
char *bufp = buf;
|
||||
|
@ -2262,7 +2250,7 @@ static void eval_trail(struct opstack **stack, const void *userdata)
|
|||
const struct locale *lang = report ? report->locale : default_locale;
|
||||
int i, end = 0, begin = 0;
|
||||
const arg_regions *regions = (const arg_regions *)opop(stack).v;
|
||||
static char buf[512];
|
||||
char buf[512];
|
||||
size_t size = sizeof(buf) - 1;
|
||||
variant var;
|
||||
char *bufp = buf;
|
||||
|
@ -2362,54 +2350,6 @@ static void log_orders(const struct message *msg)
|
|||
}
|
||||
}
|
||||
|
||||
int report_action(region * r, unit * actor, message * msg, int flags)
|
||||
{
|
||||
int result = 0;
|
||||
unit *u;
|
||||
int view = flags & (ACTION_CANSEE | ACTION_CANNOTSEE);
|
||||
|
||||
/* melden, 1x pro Partei */
|
||||
if (flags & ACTION_RESET) {
|
||||
freset(actor->faction, FFL_SELECT);
|
||||
for (u = r->units; u; u = u->next)
|
||||
freset(u->faction, FFL_SELECT);
|
||||
}
|
||||
if (view) {
|
||||
for (u = r->units; u; u = u->next) {
|
||||
if (!fval(u->faction, FFL_SELECT)) {
|
||||
bool show = u->faction == actor->faction;
|
||||
fset(u->faction, FFL_SELECT);
|
||||
if (view == ACTION_CANSEE) {
|
||||
/* Bei Fernzaubern sieht nur die eigene Partei den Magier */
|
||||
show = show || (r == actor->region
|
||||
&& cansee(u->faction, r, actor, 0));
|
||||
}
|
||||
else if (view == ACTION_CANNOTSEE) {
|
||||
show = !show && !(r == actor->region
|
||||
&& cansee(u->faction, r, actor, 0));
|
||||
}
|
||||
else {
|
||||
/* the unliely (or lazy) case */
|
||||
show = true;
|
||||
}
|
||||
|
||||
if (show) {
|
||||
r_addmessage(r, u->faction, msg);
|
||||
}
|
||||
else { /* Partei des Magiers, sieht diesen immer */
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Ist niemand von der Partei des Magiers in der Region, dem Magier
|
||||
* nochmal gesondert melden */
|
||||
if ((flags & ACTION_CANSEE) && !fval(actor->faction, FFL_SELECT)) {
|
||||
add_message(&actor->faction->msgs, msg);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void register_reports(void)
|
||||
{
|
||||
/* register datatypes for the different message objects */
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue