Merge remote-tracking branch 'upstream/master'

This commit is contained in:
CTD 2014-09-01 15:27:42 +02:00
commit 37c459cebe
82 changed files with 13254 additions and 12791 deletions

View File

@ -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)

View File

@ -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"/>

View File

@ -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"/>

View File

@ -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"/>

View File

@ -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"/>

View File

@ -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"/>

View File

@ -1,4 +0,0 @@
<?xml version="1.0"?>
<directions>
<dir name="vortex" desc="vortex_desc"/>
</directions>

View File

@ -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

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -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"

View File

@ -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>

View File

@ -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"

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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) {

View File

@ -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>

View File

@ -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)
{

View File

@ -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>

View File

@ -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>

View File

@ -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>
@ -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,

View File

@ -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>

View File

@ -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>

View File

@ -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 */

View File

@ -4,31 +4,27 @@ 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
race.test.c
reports.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
@ -42,15 +38,12 @@ group.c
item.c
magic.c
messages.c
move.c
names.c
order.c
pathfinder.c
plane.c
pool.c
race.c
region.c
reports.c
resources.c
save.c
ship.c

File diff suppressed because it is too large Load Diff

View File

@ -521,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);

View File

@ -1,5 +1,6 @@
#include <platform.h>
#include <kernel/config.h>
#include "alchemy.h"
#include "types.h"
#include "build.h"
#include "order.h"
@ -21,6 +22,7 @@ typedef struct build_fixture {
unit *u;
region *r;
race *rc;
construction cons;
} build_fixture;
static unit * setup_build(build_fixture *bf) {
@ -32,37 +34,159 @@ static unit * setup_build(build_fixture *bf) {
assert(bf->rc && bf->f && bf->r);
bf->u = test_create_unit(bf->f, bf->r);
assert(bf->u);
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(CuTest *tc) {
build_fixture bf;
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;
construction cons = { 0 };
const struct resource_type *rtype;
u = setup_build(&bf);
rtype = get_resourcetype(R_SILVER);
assert(rtype);
cons.materials = calloc(2, sizeof(requirement));
cons.materials[0].number = 1;
cons.materials[0].rtype = rtype;
cons.skill = SK_ARMORER;
cons.minskill = 2;
cons.reqsize = 1;
CuAssertIntEquals(tc, ENEEDSKILL, build(u, &cons, 1, 1));
set_level(u, SK_ARMORER, 1);
CuAssertIntEquals(tc, ELOWSKILL, build(u, &cons, 1, 1));
set_level(u, SK_ARMORER, 2);
CuAssertIntEquals(tc, ENOMATERIALS, build(u, &cons, 1, 1));
rtype = bf.cons.materials[0].rtype;
i_change(&u->items, rtype->itype, 1);
CuAssertIntEquals(tc, 1, build(u, &cons, 1, 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, &cons, 2, 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();
}
@ -82,7 +206,7 @@ static void test_build_building_no_materials(CuTest *tc) {
static void test_build_building_with_golem(CuTest *tc) {
unit *u;
build_fixture bf;
build_fixture bf = { 0 };
const building_type *btype;
u = setup_build(&bf);
@ -92,7 +216,7 @@ static void test_build_building_with_golem(CuTest *tc) {
assert(btype->construction);
set_level(bf.u, SK_BUILDING, 1);
CuAssertIntEquals(tc, 1, build_building(u, btype, 0, 4, 0));
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);
@ -124,7 +248,14 @@ static void test_build_building_success(CuTest *tc) {
CuSuite *get_build_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_build);
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);

View File

@ -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>
@ -669,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;
@ -2684,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 || *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;
@ -2796,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);

View File

@ -251,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);
@ -340,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);

View File

@ -838,7 +838,7 @@ static int
use_bloodpotion(struct unit *u, const struct item_type *itype, int amount,
struct order *ord)
{
if (u_race(u) == get_race(RC_DAEMON)) {
if (u->number == 0 || u_race(u) == get_race(RC_DAEMON)) {
change_effect(u, itype->rtype->ptype, 100 * amount);
}
else {

View File

@ -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

View File

@ -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. */
@ -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) {

View File

@ -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(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);

View File

@ -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
@ -56,6 +56,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/rng.h>
#include <util/variant.h>
#include <stealth.h>
#include <storage.h>
/* libc includes */
@ -74,7 +76,7 @@ attrib_type at_creator = {
#define UMAXHASH MAXUNITS
static unit *unithash[UMAXHASH];
static unit *delmarker = (unit *) unithash; /* a funny hack */
static unit *delmarker = (unit *)unithash; /* a funny hack */
#define HASH_STATISTICS 1
#if HASH_STATISTICS
@ -134,7 +136,7 @@ static dead *deadhash[DMAXHASH];
static void dhash(int no, faction * f)
{
dead *hash = (dead *) calloc(1, sizeof(dead));
dead *hash = (dead *)calloc(1, sizeof(dead));
dead *old = deadhash[no % DMAXHASH];
hash->no = no;
hash->f = f;
@ -177,7 +179,8 @@ static buddy *get_friends(const unit * u, int *numfriends)
int allied = 0;
if (get_param_int(global.parameters, "rules.alliances", 0) != 0) {
allied = (f->alliance && f->alliance == u2->faction->alliance);
} else if (alliedunit(u, u2->faction, HELP_MONEY)
}
else if (alliedunit(u, u2->faction, HELP_MONEY)
&& alliedunit(u2, f, HELP_GIVE)) {
allied = 1;
}
@ -196,7 +199,8 @@ static buddy *get_friends(const unit * u, int *numfriends)
nf->unit = u2;
nf->number = 0;
*fr = nf;
} else if (nf->faction == u2->faction
}
else if (nf->faction == u2->faction
&& (u_race(u2)->ec_flags & GIVEITEM)) {
/* we don't like to gift it to units that won't give it back */
if ((u_race(nf->unit)->ec_flags & GIVEITEM) == 0) {
@ -256,7 +260,8 @@ int gift_items(unit * u, int flags)
i_merge(&u2->items, &u->items);
u->items = NULL;
break;
} else {
}
else {
u3 = u2;
}
}
@ -318,7 +323,8 @@ int gift_items(unit * u, int flags)
if (itm->number > 0 && (itm->type->flags & ITF_NOTLOST)) {
itm_p = &itm->next;
retval = -1;
} else {
}
else {
i_remove(itm_p, itm);
i_free(itm);
}
@ -444,7 +450,8 @@ const char *u_description(const unit * u, const struct locale *lang)
{
if (u->display && u->display[0]) {
return u->display;
} else if (u_race(u)->describe) {
}
else if (u_race(u)->describe) {
return u_race(u)->describe(u, lang);
}
return NULL;
@ -522,7 +529,7 @@ unit *utarget(const unit * u)
return NULL;
a = a_find(u->attribs, &at_target);
assert(a || !"flag set, but no target found");
return (unit *) a->data.v;
return (unit *)a->data.v;
}
void usettarget(unit * u, const unit * t)
@ -534,7 +541,8 @@ void usettarget(unit * u, const unit * t)
if (!t) {
a_remove(&u->attribs, a);
freset(u, UFL_TARGET);
} else {
}
else {
a->data.v = (void *)t;
fset(u, UFL_TARGET);
}
@ -589,7 +597,8 @@ void usetsiege(unit * u, const struct building *t)
if (!t) {
a_remove(&u->attribs, a);
freset(u, UFL_SIEGE);
} else {
}
else {
a->data.v = (void *)t;
fset(u, UFL_SIEGE);
}
@ -628,7 +637,7 @@ bool ucontact(const unit * u, const unit * u2)
/* Explizites KONTAKTIERE */
for (ru = a_find(u->attribs, &at_contact); ru && ru->type == &at_contact;
ru = ru->next) {
if (((unit *) ru->data.v) == u2) {
if (((unit *)ru->data.v) == u2) {
return true;
}
}
@ -661,11 +670,11 @@ int resolve_unit(variant id, void *address)
if (id.i != 0) {
u = findunit(id.i);
if (u == NULL) {
*(unit **) address = NULL;
*(unit **)address = NULL;
return -1;
}
}
*(unit **) address = u;
*(unit **)address = u;
return 0;
}
@ -676,44 +685,6 @@ variant read_unit_reference(struct storage * store)
return var;
}
attrib_type at_stealth = {
"stealth", NULL, NULL, NULL, a_writeint, a_readint
};
void u_seteffstealth(unit * u, int value)
{
if (skill_enabled(SK_STEALTH)) {
attrib *a = NULL;
if (fval(u, UFL_STEALTH)) {
a = a_find(u->attribs, &at_stealth);
}
if (value < 0) {
if (a != NULL) {
freset(u, UFL_STEALTH);
a_remove(&u->attribs, a);
}
return;
}
if (a == NULL) {
a = a_add(&u->attribs, a_new(&at_stealth));
fset(u, UFL_STEALTH);
}
a->data.i = value;
}
}
int u_geteffstealth(const struct unit *u)
{
if (skill_enabled(SK_STEALTH)) {
if (fval(u, UFL_STEALTH)) {
attrib *a = a_find(u->attribs, &at_stealth);
if (a != NULL)
return a->data.i;
}
}
return -1;
}
int get_level(const unit * u, skill_t id)
{
if (skill_enabled(id)) {
@ -780,7 +751,7 @@ ship *leftship(const unit * u)
* Zeitpunkt noch auf ein existierendes Schiff zeigt! */
if (a)
return (ship *) (a->data.v);
return (ship *)(a->data.v);
return NULL;
}
@ -808,7 +779,7 @@ void leave_ship(unit * u)
struct ship *sh = u->ship;
u->ship = 0;
if (sh->_owner==u) {
if (sh->_owner == u) {
ship_update_owner(sh);
sh->_owner = ship_owner(sh);
}
@ -820,9 +791,9 @@ void leave_building(unit * u)
building * b = u->building;
u->building = 0;
if (b->_owner==u) {
if (b->_owner == u) {
building_update_owner(b);
assert(b->_owner!=u);
assert(b->_owner != u);
}
}
@ -855,7 +826,8 @@ bool leave(unit * u, bool force)
}
if (u->building) {
leave_building(u);
} else if (u->ship) {
}
else if (u->ship) {
leave_ship(u);
}
return true;
@ -908,7 +880,8 @@ void move_unit(unit * u, region * r, unit ** ulist)
#endif
}
translist(&u->region->units, ulist, u);
} else {
}
else {
addlist(ulist, u);
}
@ -951,7 +924,8 @@ void transfermen(unit * u, unit * u2, int n)
/* new unit, easy to solve */
level = sv->level;
weeks = sv->weeks;
} else {
}
else {
double dlevel = 0.0;
if (sv && sv->level) {
@ -972,7 +946,8 @@ void transfermen(unit * u, unit * u2, int n)
* next level */
level = (int)dlevel;
weeks = (level + 1) - (int)((dlevel - level) * (level + 1));
} else {
}
else {
/* make it harder to reach the next level.
* weeks+level is the max difficulty, 1 - the fraction between
* level and dlevel applied to the number of weeks between this
@ -989,14 +964,15 @@ void transfermen(unit * u, unit * u2, int n)
assert(sn->weeks > 0 && sn->weeks <= sn->level * 2 + 1);
assert(u2->number != 0 || (sn->level == sv->level
&& sn->weeks == sv->weeks));
} else if (sn) {
}
else if (sn) {
remove_skill(u2, sk);
sn = NULL;
}
}
a = a_find(u->attribs, &at_effect);
while (a && a->type == &at_effect) {
effect_data *olde = (effect_data *) a->data.v;
effect_data *olde = (effect_data *)a->data.v;
if (olde->value)
change_effect(u2, olde->type, olde->value);
a = a->next;
@ -1020,19 +996,21 @@ void transfermen(unit * u, unit * u2, int n)
a = a_find(u2->attribs, &at_effect);
while (a && a->type == &at_effect) {
attrib *an = a->next;
effect_data *olde = (effect_data *) a->data.v;
effect_data *olde = (effect_data *)a->data.v;
int e = get_effect(u, olde->type);
if (e != 0)
change_effect(u2, olde->type, -e);
a = an;
}
} else if (r->land) {
}
else if (r->land) {
if ((u_race(u)->ec_flags & ECF_REC_ETHEREAL) == 0) {
const race *rc = u_race(u);
if (rc->ec_flags & ECF_REC_HORSES) { /* Zentauren an die Pferde */
int h = rhorses(r) + n;
rsethorses(r, h);
} else {
}
else {
int p = rpeasants(r);
p += (int)(n * rc->recruit_multi);
rsetpeasants(r, p);
@ -1049,10 +1027,12 @@ struct building *inside_building(const struct unit *u)
if (!fval(u->building, BLD_WORKING)) {
/* Unterhalt nicht bezahlt */
return NULL;
} else if (u->building->size < u->building->type->maxsize) {
}
else if (u->building->size < u->building->type->maxsize) {
/* Gebaeude noch nicht fertig */
return NULL;
} else {
}
else {
int p = 0, cap = buildingcapacity(u->building);
const unit *u2;
for (u2 = u->region->units; u2; u2 = u2->next) {
@ -1143,7 +1123,8 @@ bool learn_skill(unit * u, skill_t sk, double chance)
if (sv->id == sk) {
if (sv->weeks <= 1) {
sk_set(sv, sv->level + 1);
} else {
}
else {
sv->weeks--;
}
return true;
@ -1258,7 +1239,7 @@ static int att_modification(const unit * u, skill_t sk)
if (skillmod_ct) {
attrib *a = a_find(u->attribs, &at_curse);
while (a && a->type == &at_curse) {
curse *c = (curse *) a->data.v;
curse *c = (curse *)a->data.v;
if (c->type == skillmod_ct && c->data.i == sk) {
result += curse_geteffect(c);
break;
@ -1274,7 +1255,7 @@ static int att_modification(const unit * u, skill_t sk)
double bonus = 0, malus = 0;
attrib *a = a_find(u->region->attribs, &at_curse);
while (a && a->type == &at_curse) {
curse *c = (curse *) a->data.v;
curse *c = (curse *)a->data.v;
if (curse_active(c) && c->type == gbdream_ct) {
double mod = curse_geteffect(c);
unit *mage = c->magician;
@ -1284,7 +1265,8 @@ static int att_modification(const unit * u, skill_t sk)
|| alliedunit(mage, u->faction, HELP_GUARD)) {
bonus = mod;
}
} else if (mod < malus) {
}
else if (mod < malus) {
if (mage == NULL || !alliedunit(mage, u->faction, HELP_GUARD)) {
malus = mod;
}
@ -1300,7 +1282,7 @@ static int att_modification(const unit * u, skill_t sk)
int
get_modifier(const unit * u, skill_t sk, int level, const region * r,
bool noitem)
bool noitem)
{
int bskill = level;
int skill = bskill;
@ -1424,10 +1406,12 @@ void name_unit(unit * u)
const char *gen_name = u_race(u)->generate_name(u);
if (gen_name) {
unit_setname(u, gen_name);
} else {
}
else {
unit_setname(u, racename(u->faction->locale, u, u_race(u)));
}
} else {
}
else {
char name[32];
const char * result;
const struct locale * lang = u->faction ? u->faction->locale : default_locale;
@ -1441,7 +1425,8 @@ void name_unit(unit * u)
}
}
result = prefix[i];
} else {
}
else {
result = parameters[P_UNIT];
}
strlcpy(name, result, sizeof(name));
@ -1474,7 +1459,6 @@ unit *create_unit(region * r, faction * f, int number, const struct race *urace,
}
}
}
u_seteffstealth(u, -1);
u_setrace(u, urace);
u->irace = NULL;
@ -1495,7 +1479,8 @@ unit *create_unit(region * r, faction * f, int number, const struct race *urace,
if (!dname) {
name_unit(u);
} else {
}
else {
u->name = _strdup(dname);
}
@ -1539,7 +1524,7 @@ unit *create_unit(region * r, faction * f, int number, const struct race *urace,
if (creator->faction == f && fval(creator, UFL_GROUP)) {
a = a_find(creator->attribs, &at_group);
if (a) {
group *g = (group *) a->data.v;
group *g = (group *)a->data.v;
set_group(u, g);
}
}
@ -1699,7 +1684,6 @@ int unit_max_hp(const unit * u)
void scale_number(unit * u, int n)
{
skill_t sk;
const attrib *a;
int remain;
@ -1714,14 +1698,15 @@ void scale_number(unit * u, int n)
assert(u->hp >= 0);
if ((rng_int() % u->number) < remain)
++u->hp; /* Nachkommastellen */
} else {
}
else {
remain = 0;
u->hp = 0;
}
if (u->number > 0) {
for (a = a_find(u->attribs, &at_effect); a && a->type == &at_effect;
a = a->next) {
effect_data *data = (effect_data *) a->data.v;
effect_data *data = (effect_data *)a->data.v;
int snew = data->value / u->number * n;
if (n) {
remain = data->value - snew / n * u->number;
@ -1734,6 +1719,7 @@ void scale_number(unit * u, int n)
}
}
if (u->number == 0 || n == 0) {
skill_t sk;
for (sk = 0; sk < MAXSKILLS; sk++) {
remove_skill(u, sk);
}
@ -1767,7 +1753,7 @@ void unit_add_spell(unit * u, sc_mage * m, struct spell * sp, int level)
if (!mage) {
log_debug("adding new spell %s to a previously non-mage unit %s\n", sp->sname, unitname(u));
mage = create_mage(u, u->faction?u->faction->magiegebiet:M_GRAY);
mage = create_mage(u, u->faction ? u->faction->magiegebiet : M_GRAY);
}
if (!mage->spellbook) {
mage->spellbook = create_spellbook(0);
@ -1782,7 +1768,7 @@ struct spellbook * unit_get_spellbook(const struct unit * u)
if (mage->spellbook) {
return mage->spellbook;
}
if (mage->magietyp!=M_GRAY) {
if (mage->magietyp != M_GRAY) {
return faction_get_spellbook(u->faction);
}
}

View File

@ -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
View 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;
}

View File

@ -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);
@ -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

View File

@ -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>

View File

@ -31,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>
@ -266,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);

View File

@ -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>

View File

@ -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();

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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",

92
src/move.h Normal file
View 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

View File

@ -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>

View File

@ -21,13 +21,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#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"
#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>

View File

@ -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>

View File

@ -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>
@ -1127,7 +1128,7 @@ 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)
@ -1167,6 +1168,7 @@ static void describe(FILE * F, const seen_region * sr, faction * f)
dh = true;
}
}
}
/* Spezielle Richtungen */
for (a = a_find(r->attribs, &at_direction); a && a->type == &at_direction;
a = a->next) {

View File

@ -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;
@ -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)
{
@ -2379,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 */

View File

@ -20,7 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define H_KRNL_REPORTS
#include <time.h>
#include "objtypes.h"
#include <kernel/objtypes.h>
#ifdef __cplusplus
extern "C" {
@ -112,9 +112,6 @@ extern "C" {
void register_reports(void);
int update_nmrs(void);
int *nmrs;
struct message *msg_curse(const struct curse *c, const void *obj,
objtype_t typ, int slef);
@ -141,12 +138,6 @@ extern "C" {
const char **rcillusion);
void add_seen_faction(struct faction *self, struct faction *seen);
#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 */
int report_action(struct region *r, struct unit *actor,
struct message *msg, int flags);
size_t f_regionid(const struct region *r, const struct faction *f,
char *buffer, size_t size);

View File

@ -1,9 +1,10 @@
#include <platform.h>
#include <config.h>
#include <kernel/types.h>
#include "reports.h"
#include <kernel/building.h>
#include <kernel/faction.h>
#include <kernel/race.h>
#include <kernel/reports.h>
#include <kernel/region.h>
#include <kernel/ship.h>
#include <kernel/unit.h>

6877
src/spells.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -21,11 +21,16 @@ extern "C" {
struct ship;
struct curse;
struct unit;
struct message;
extern void register_spells(void);
void register_spells(void);
void set_spelldata(struct spell *sp);
#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 */
int report_action(struct region *r, struct unit *actor, struct message *msg, int flags);
#ifdef __cplusplus
}
#endif

View File

@ -6,7 +6,6 @@ buildingcurse.c
combatspells.c
regioncurse.c
shipcurse.c
spells.c
unitcurse.c
)
FOREACH(_FILE ${_FILES})

View File

@ -15,7 +15,6 @@
#include "combatspells.h"
/* kernel includes */
#include <kernel/battle.h>
#include <kernel/build.h>
#include <kernel/building.h>
#include <kernel/curse.h>
@ -27,12 +26,14 @@
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/unit.h>
#include <kernel/move.h>
#include <kernel/spell.h>
#include <kernel/spellid.h>
#include <kernel/race.h>
#include <kernel/terrain.h>
#include <battle.h>
#include <move.h>
/* util includes */
#include <util/attrib.h>
#include <util/base36.h>

File diff suppressed because it is too large Load Diff

View File

@ -20,14 +20,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include "spy.h"
#include "laws.h"
#include "stealth.h"
#include "move.h"
#include "reports.h"
/* kernel includes */
#include <kernel/reports.h>
#include <kernel/item.h>
#include <kernel/faction.h>
#include <kernel/magic.h>
#include <kernel/messages.h>
#include <kernel/move.h>
#include <kernel/order.h>
#include <kernel/race.h>
#include <kernel/region.h>

64
src/stealth.c Normal file
View File

@ -0,0 +1,64 @@
#include <config.h>
#include <platform.h>
#include "stealth.h"
#include <kernel/unit.h>
#include <kernel/region.h>
#include <kernel/save.h>
#include <util/attrib.h>
#include <stdlib.h>
attrib_type at_stealth = {
"stealth", NULL, NULL, NULL, a_writeint, a_readint
};
void u_seteffstealth(unit * u, int value)
{
if (skill_enabled(SK_STEALTH)) {
attrib *a = NULL;
if (u->flags & UFL_STEALTH) {
a = a_find(u->attribs, &at_stealth);
}
if (value < 0) {
if (a != NULL) {
u->flags &= ~UFL_STEALTH;
a_remove(&u->attribs, a);
}
return;
}
if (a == NULL) {
a = a_add(&u->attribs, a_new(&at_stealth));
u->flags |= UFL_STEALTH;
}
a->data.i = value;
}
}
int u_geteffstealth(const unit *u)
{
if (skill_enabled(SK_STEALTH)) {
if (u->flags & UFL_STEALTH) {
attrib *a = a_find(u->attribs, &at_stealth);
if (a != NULL)
return a->data.i;
}
}
return -1;
}
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 (u->flags & UFL_STEALTH) {
int es = u_geteffstealth(u);
if (es >= 0 && es < e)
return es;
}
}
return e;
}

19
src/stealth.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef STEALTH_H
#define STEALTH_H
#ifdef __cplusplus
extern "C" {
#endif
struct unit;
struct region;
extern struct attrib_type at_stealth;
int eff_stealth(const struct unit *u, const struct region *r);
void u_seteffstealth(struct unit *u, int value);
int u_geteffstealth(const struct unit *u);
#ifdef __cplusplus
}
#endif
#endif

40
src/stealth.test.c Normal file
View File

@ -0,0 +1,40 @@
#include <platform.h>
#include "stealth.h"
#include <kernel/unit.h>
#include <kernel/region.h>
#include <CuTest.h>
#include <tests.h>
#include <stdlib.h>
#include <assert.h>
void test_stealth(CuTest *tc) {
unit *u;
test_cleanup();
test_create_world();
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
set_level(u, SK_STEALTH, 2);
CuAssertIntEquals(tc, -1, u_geteffstealth(u));
CuAssertIntEquals(tc, 2, eff_stealth(u, u->region));
u_seteffstealth(u, 3);
CuAssertIntEquals(tc, 3, u_geteffstealth(u));
CuAssertIntEquals(tc, 2, eff_stealth(u, u->region));
u_seteffstealth(u, 1);
CuAssertIntEquals(tc, 1, u_geteffstealth(u));
CuAssertIntEquals(tc, 1, eff_stealth(u, u->region));
u_seteffstealth(u, -1);
CuAssertIntEquals(tc, -1, u_geteffstealth(u));
CuAssertIntEquals(tc, 2, eff_stealth(u, u->region));
test_cleanup();
}
CuSuite *get_stealth_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_stealth);
return suite;
}

View File

@ -22,15 +22,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <platform.h>
#include <kernel/config.h>
#include "study.h"
#include "move.h"
#include "alchemy.h"
#include <kernel/alchemy.h>
#include <kernel/building.h>
#include <kernel/curse.h>
#include <kernel/faction.h>
#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>

View File

@ -13,7 +13,6 @@
#include <kernel/config.h>
#include "summary.h"
#include "laws.h"
#include <kernel/alliance.h>
@ -22,7 +21,6 @@
#include <kernel/item.h>
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/reports.h>
#include <kernel/save.h>
#include <kernel/terrain.h>
#include <kernel/terrainid.h>
@ -71,6 +69,38 @@ typedef struct summary {
} *languages;
} summary;
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;
}
static char *pcomp(double i, double j)
{
static char buf[32];

View File

@ -16,9 +16,13 @@ extern "C" {
#endif
struct summary;
extern void report_summary(struct summary *n, struct summary *o,
bool full);
extern struct summary *make_summary(void);
void report_summary(struct summary *n, struct summary *o, bool full);
struct summary *make_summary(void);
int update_nmrs(void);
extern int* nmrs;
#ifdef __cplusplus
}

View File

@ -36,6 +36,7 @@ int RunAllTests(void)
ADD_TESTS(suite, umlaut);
ADD_TESTS(suite, strings);
/* kernel */
ADD_TESTS(suite, unit);
ADD_TESTS(suite, faction);
ADD_TESTS(suite, build);
ADD_TESTS(suite, pool);
@ -43,19 +44,21 @@ int RunAllTests(void)
ADD_TESTS(suite, equipment);
ADD_TESTS(suite, item);
ADD_TESTS(suite, magic);
ADD_TESTS(suite, move);
ADD_TESTS(suite, reports);
ADD_TESTS(suite, save);
ADD_TESTS(suite, ship);
ADD_TESTS(suite, spellbook);
ADD_TESTS(suite, building);
ADD_TESTS(suite, spell);
ADD_TESTS(suite, battle);
ADD_TESTS(suite, ally);
/* gamecode */
ADD_TESTS(suite, market);
ADD_TESTS(suite, laws);
ADD_TESTS(suite, battle);
ADD_TESTS(suite, economy);
ADD_TESTS(suite, laws);
ADD_TESTS(suite, market);
ADD_TESTS(suite, move);
ADD_TESTS(suite, stealth);
ADD_TESTS(suite, vortex);
CuSuiteRun(suite);
CuSuiteSummary(suite, output);

View File

@ -234,6 +234,15 @@ void ** get_translations(const struct locale *lang, int index)
return lstrs[0].tokens + index;
}
void *get_translation(const struct locale *lang, const char *str, int index) {
void **tokens = get_translations(lang, index);
variant var;
if (findtoken(*tokens, str, &var) == E_TOK_SUCCESS) {
return var.v;
}
return NULL;
}
void free_locales(void)
{
while (locales) {

View File

@ -65,7 +65,8 @@ extern "C" {
UT_MAX
};
void ** get_translations(const struct locale *lang, int index);
void ** get_translations(const struct locale *lang, int type);
void * get_translation(const struct locale *lang, const char *str, int type);
#ifdef __cplusplus
}

View File

@ -48,7 +48,7 @@ void opstack_push(opstack ** stackp, variant data)
opstack *stack = *stackp;
if (stack == NULL) {
stack = (opstack *) malloc(sizeof(opstack));
stack->size = 1;
stack->size = 2;
stack->begin = malloc(sizeof(variant) * stack->size);
stack->top = stack->begin;
*stackp = stack;

185
src/vortex.c Normal file
View File

@ -0,0 +1,185 @@
#include <config.h>
#include <platform.h>
#include "vortex.h"
#include <kernel/config.h>
#include <kernel/version.h>
#include <kernel/region.h>
#include <util/attrib.h>
#include <util/language.h>
#include <util/log.h>
#include <util/umlaut.h>
#include <util/variant.h>
#include <storage.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
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 == locales) {
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));
}
}
}
/********************/
/* 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;
}
static int a_readdirection(attrib * a, void *owner, struct storage *store)
{
spec_direction *d = (spec_direction *)(a->data.v);
(void) owner;
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);
_snprintf(lbuf, sizeof(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);
(void)owner;
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)
{
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 && strcmp(token, 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, bool active)
{
attrib *a = a_add(&r->attribs, a_new(&at_direction));
spec_direction *d = (spec_direction *)(a->data.v);
d->active = active;
d->x = rt->x;
d->y = rt->y;
d->duration = duration;
d->desc = _strdup(desc);
d->keyword = _strdup(keyword);
return a;
}
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;
}

31
src/vortex.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef H_VORTEX
#define H_VORTEX
#ifdef __cplusplus
extern "C" {
#endif
struct region;
struct attrib;
typedef struct spec_direction {
int x, y;
int duration;
bool active;
char *desc;
char *keyword;
} spec_direction;
extern struct attrib_type at_direction;
struct region *find_special_direction(const struct region *r,
const char *token);
void register_special_direction(const char *name);
struct spec_direction *special_direction(const struct region * from,
const struct region * to);
struct attrib *create_special_direction(struct region *r, struct region *rt,
int duration, const char *desc, const char *keyword, bool active);
#ifdef __cplusplus
}
#endif
#endif

48
src/vortex.test.c Normal file
View File

@ -0,0 +1,48 @@
#include <platform.h>
#include <kernel/types.h>
#include "vortex.h"
#include "move.h"
#include "tests.h"
#include <kernel/config.h>
#include <kernel/region.h>
#include <kernel/terrain.h>
#include <kernel/unit.h>
#include <kernel/race.h>
#include <util/language.h>
#include <CuTest.h>
static void test_move_to_vortex(CuTest *tc) {
region *r1, *r2, *r = 0;
terrain_type *t_plain;
unit *u;
struct locale *lang;
test_cleanup();
lang = get_or_create_locale("en");
locale_setstring(lang, "vortex", "wirbel");
init_locale(lang);
register_special_direction("vortex");
t_plain = test_create_terrain("plain", LAND_REGION | FOREST_REGION | WALK_INTO | CAVALRY_REGION);
r1 = test_create_region(0, 0, t_plain);
r2 = test_create_region(5, 0, t_plain);
CuAssertPtrNotNull(tc, create_special_direction(r1, r2, 10, "", "vortex", true));
u = test_create_unit(test_create_faction(rc_get_or_create("hodor")), r1);
CuAssertIntEquals(tc, E_MOVE_NOREGION, movewhere(u, "barf", r1, &r));
CuAssertIntEquals(tc, E_MOVE_OK, movewhere(u, "wirbel", r1, &r));
CuAssertPtrEquals(tc, r2, r);
}
static void test_vortex(CuTest *tc) {
}
CuSuite *get_vortex_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_vortex);
SUITE_ADD_TEST(suite, test_move_to_vortex);
return suite;
}

View File

@ -27,6 +27,7 @@ without prior permission by the authors of Eressea.
/* gamecode includes */
#include "laws.h"
#include "economy.h"
#include "move.h"
/* kernel includes */
#include <kernel/alchemy.h>
@ -40,7 +41,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/plane.h>
#include <kernel/race.h>