Merge branch 'master' of github.com:eressea/core

Conflicts:
	src/kernel/move_test.c
This commit is contained in:
Enno Rehling 2012-07-02 03:38:51 +02:00
commit 0a756efba9
22 changed files with 78 additions and 109 deletions

View File

@ -594,7 +594,7 @@ function test_guard_resources()
end end
local function is_flag_set(flags, flag) local function is_flag_set(flags, flag)
return math.mod(flags, flag*2) - math.mod(flags, flag) == flag; return math.fmod(flags, flag*2) - math.fmod(flags, flag) == flag;
end end
function test_hero_hero_transfer() function test_hero_hero_transfer()
@ -803,7 +803,7 @@ end
local function find_in_report(f, pattern, extension) local function find_in_report(f, pattern, extension)
extension = extension or "nr" extension = extension or "nr"
local filename = config.reportpath .. "/" .. get_turn() .. "-" .. itoa36(f.id) .. "." .. extension local filename = config.reportpath .. "/" .. get_turn() .. "-" .. itoa36(f.id) .. "." .. extension
local report = io.open(filename, 'rt'); local report = io.open(filename, 'r');
assert_not_nil(report) assert_not_nil(report)
t = report:read("*all") t = report:read("*all")
report:close() report:close()
@ -893,7 +893,7 @@ function test_parser()
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
local filename = config.basepath .. "/data/orders.txt" local filename = config.basepath .. "/data/orders.txt"
local file = io.open(filename, "w+") local file = io.open(filename, "w")
assert_not_nil(file) assert_not_nil(file)
file:write('ERESSEA ' .. itoa36(f.id) .. ' "' .. f.password .. '"\n') file:write('ERESSEA ' .. itoa36(f.id) .. ' "' .. f.password .. '"\n')
file:write('EINHEIT ' .. itoa36(u.id) .. "\n") file:write('EINHEIT ' .. itoa36(u.id) .. "\n")
@ -956,7 +956,7 @@ function test_bug_1814()
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
local filename = config.basepath .. "/data/1814.txt" local filename = config.basepath .. "/data/1814.txt"
local file = io.open(filename, "w+") local file = io.open(filename, "w")
file:write('ERESSEA ' .. itoa36(f.id) .. ' "' .. f.password .. '"\n') file:write('ERESSEA ' .. itoa36(f.id) .. ' "' .. f.password .. '"\n')
file:write('EINHEIT ' .. itoa36(u.id) .. "\n") file:write('EINHEIT ' .. itoa36(u.id) .. "\n")
file:write("; parse error follows: '\n") file:write("; parse error follows: '\n")
@ -977,7 +977,7 @@ function test_bug_1679()
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
local filename = config.basepath .. "/data/1679.txt" local filename = config.basepath .. "/data/1679.txt"
local file = io.open(filename, "w+") local file = io.open(filename, "w")
file:write('ERESSEA ' .. itoa36(f.id) .. ' "' .. f.password .. '"\n') file:write('ERESSEA ' .. itoa36(f.id) .. ' "' .. f.password .. '"\n')
file:write('EINHEIT ' .. itoa36(u.id) .. "\n") file:write('EINHEIT ' .. itoa36(u.id) .. "\n")
file:write("NACH W\n") file:write("NACH W\n")

View File

@ -13,7 +13,7 @@ set (ERESSEA_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "Eressea Cor
add_subdirectory(bindings) add_subdirectory(bindings)
find_package (Lua51 REQUIRED) find_package (Lua 5 REQUIRED)
find_package (ToLua REQUIRED) find_package (ToLua REQUIRED)
find_package (LibXml2 REQUIRED) find_package (LibXml2 REQUIRED)
find_package (Curses REQUIRED) find_package (Curses REQUIRED)

View File

@ -9,7 +9,7 @@ ENDIF(CMAKE_COMPILER_IS_GNUCC)
set (BINDINGS_LIBRARY ${PROJECT_NAME} CACHE INTERNAL "Eressea Lua Bindings") set (BINDINGS_LIBRARY ${PROJECT_NAME} CACHE INTERNAL "Eressea Lua Bindings")
find_package (Lua51 REQUIRED) find_package (Lua 5 REQUIRED)
find_package (ToLua REQUIRED) find_package (ToLua REQUIRED)
find_package (LibXml2 REQUIRED) find_package (LibXml2 REQUIRED)
find_package (Curses REQUIRED) find_package (Curses REQUIRED)

View File

@ -21,7 +21,6 @@ without prior permission by the authors of Eressea.
#include <util/language.h> #include <util/language.h>
#include <lua.h>
#include <tolua.h> #include <tolua.h>
int tolua_buildinglist_next(lua_State * L) int tolua_buildinglist_next(lua_State * L)

View File

@ -29,7 +29,6 @@ without prior permission by the authors of Eressea.
#include <util/log.h> #include <util/log.h>
#include <quicklist.h> #include <quicklist.h>
#include <lua.h>
#include <tolua.h> #include <tolua.h>
int tolua_factionlist_next(lua_State * L) int tolua_factionlist_next(lua_State * L)

View File

@ -11,7 +11,6 @@
#include <modules/autoseed.h> #include <modules/autoseed.h>
#include <util/log.h> #include <util/log.h>
#include <lua.h>
#include <tolua.h> #include <tolua.h>
static int tolua_run_mapper(lua_State * L) static int tolua_run_mapper(lua_State * L)

View File

@ -23,7 +23,6 @@ without prior permission by the authors of Eressea.
#include <util/variant.h> #include <util/variant.h>
#include <util/attrib.h> #include <util/attrib.h>
#include <lua.h>
#include <tolua.h> #include <tolua.h>
#include <assert.h> #include <assert.h>

View File

@ -13,7 +13,6 @@
#include <util/message.h> #include <util/message.h>
/* lua includes */ /* lua includes */
#include <lua.h>
#include <tolua.h> #include <tolua.h>
#include <assert.h> #include <assert.h>

View File

@ -37,7 +37,6 @@ without prior permission by the authors of Eressea.
#include <util/language.h> #include <util/language.h>
#include <util/log.h> #include <util/log.h>
#include <lua.h>
#include <tolua.h> #include <tolua.h>
#include <assert.h> #include <assert.h>

View File

@ -22,7 +22,6 @@ without prior permission by the authors of Eressea.
#include <util/language.h> #include <util/language.h>
#include <lua.h>
#include <tolua.h> #include <tolua.h>
int tolua_shiplist_next(lua_State * L) int tolua_shiplist_next(lua_State * L)

View File

@ -16,7 +16,6 @@ without prior permission by the authors of Eressea.
#include "bindings.h" #include "bindings.h"
#include <sqlite3.h> #include <sqlite3.h>
#include <lua.h>
#include <tolua.h> #include <tolua.h>
#define LTYPE_DB TOLUA_CAST "db" #define LTYPE_DB TOLUA_CAST "db"

View File

@ -22,7 +22,6 @@ without prior permission by the authors of Eressea.
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#include <lua.h>
#include <tolua.h> #include <tolua.h>
static int tolua_storage_create(lua_State * L) static int tolua_storage_create(lua_State * L)

View File

@ -51,7 +51,6 @@ without prior permission by the authors of Eressea.
#include <util/log.h> #include <util/log.h>
#include <quicklist.h> #include <quicklist.h>
#include <lua.h>
#include <tolua.h> #include <tolua.h>
#include <assert.h> #include <assert.h>

View File

@ -1160,34 +1160,9 @@ int tolua_bindings_open(lua_State * L)
return 1; return 1;
} }
static const struct {
const char *name;
int (*func) (lua_State *);
} lualibs[] = {
{
"", luaopen_base}, {
LUA_TABLIBNAME, luaopen_table}, {
LUA_IOLIBNAME, luaopen_io}, {
LUA_STRLIBNAME, luaopen_string}, {
LUA_MATHLIBNAME, luaopen_math}, {
LUA_LOADLIBNAME, luaopen_package}, {
LUA_DBLIBNAME, luaopen_debug},
#if LUA_VERSION_NUM>=501
{
LUA_OSLIBNAME, luaopen_os},
#endif
{
NULL, NULL}
};
static void openlibs(lua_State * L) static void openlibs(lua_State * L)
{ {
int i; luaL_openlibs(L);
for (i = 0; lualibs[i].func; ++i) {
lua_pushcfunction(L, lualibs[i].func);
lua_pushstring(L, lualibs[i].name);
lua_call(L, 1, 0);
}
} }
void lua_done(lua_State * L) { void lua_done(lua_State * L) {
@ -1195,7 +1170,7 @@ void lua_done(lua_State * L) {
} }
lua_State *lua_init(void) { lua_State *lua_init(void) {
lua_State *L = lua_open(); lua_State *L = luaL_newstate();
openlibs(L); openlibs(L);
#ifdef BINDINGS_TOLUA #ifdef BINDINGS_TOLUA

View File

@ -31,8 +31,8 @@ without prior permission by the authors of Eressea.
#include <gamecode/archetype.h> #include <gamecode/archetype.h>
#include <lua.h>
#include <tolua.h> #include <tolua.h>
#include <lua.h>
#include <assert.h> #include <assert.h>
@ -48,8 +48,7 @@ lua_giveitem(unit * s, unit * d, const item_type * itype, int n, struct order *o
strlcpy(fname, iname, sizeof(fname)); strlcpy(fname, iname, sizeof(fname));
strlcat(fname, "_give", sizeof(fname)); strlcat(fname, "_give", sizeof(fname));
lua_pushstring(L, fname); lua_getglobal(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, s, TOLUA_CAST "unit"); tolua_pushusertype(L, s, TOLUA_CAST "unit");
tolua_pushusertype(L, d, TOLUA_CAST "unit"); tolua_pushusertype(L, d, TOLUA_CAST "unit");
@ -81,8 +80,7 @@ static int limit_resource(const region * r, const resource_type * rtype)
strlcpy(fname, rtype->_name[0], sizeof(fname)); strlcpy(fname, rtype->_name[0], sizeof(fname));
strlcat(fname, "_limit", sizeof(fname)); strlcat(fname, "_limit", sizeof(fname));
lua_pushstring(L, fname); lua_getglobal(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region"); tolua_pushusertype(L, (void *)r, TOLUA_CAST "region");
@ -111,8 +109,7 @@ produce_resource(region * r, const resource_type * rtype, int norders)
strlcpy(fname, rtype->_name[0], sizeof(fname)); strlcpy(fname, rtype->_name[0], sizeof(fname));
strlcat(fname, "_produce", sizeof(fname)); strlcat(fname, "_produce", sizeof(fname));
lua_pushstring(L, fname); lua_getglobal(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region"); tolua_pushusertype(L, (void *)r, TOLUA_CAST "region");
tolua_pushnumber(L, (lua_Number) norders); tolua_pushnumber(L, (lua_Number) norders);
@ -140,8 +137,7 @@ static int lc_age(struct attrib *a)
if (fname != NULL) { if (fname != NULL) {
lua_State *L = (lua_State *) global.vm_state; lua_State *L = (lua_State *) global.vm_state;
lua_pushstring(L, fname); lua_getglobal(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building"); tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
if (fparam) { if (fparam) {
@ -201,8 +197,7 @@ static int lua_callspell(castorder * co)
fname = fbuf; fname = fbuf;
} }
lua_pushstring(L, fname); lua_getglobal(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
int nparam = 4; int nparam = 4;
tolua_pushusertype(L, r, TOLUA_CAST "region"); tolua_pushusertype(L, r, TOLUA_CAST "region");
@ -254,8 +249,7 @@ static int lua_initfamiliar(unit * u)
strlcpy(fname, "initfamiliar_", sizeof(fname)); strlcpy(fname, "initfamiliar_", sizeof(fname));
strlcat(fname, u->race->_name[0], sizeof(fname)); strlcat(fname, u->race->_name[0], sizeof(fname));
lua_pushstring(L, fname); lua_getglobal(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, u, TOLUA_CAST "unit"); tolua_pushusertype(L, u, TOLUA_CAST "unit");
@ -290,8 +284,7 @@ lua_changeresource(unit * u, const struct resource_type *rtype, int delta)
strlcpy(fname, rtype->_name[0], sizeof(fname)); strlcpy(fname, rtype->_name[0], sizeof(fname));
strlcat(fname, "_changeresource", sizeof(fname)); strlcat(fname, "_changeresource", sizeof(fname));
lua_pushstring(L, fname); lua_getglobal(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, u, TOLUA_CAST "unit"); tolua_pushusertype(L, u, TOLUA_CAST "unit");
tolua_pushnumber(L, (lua_Number) delta); tolua_pushnumber(L, (lua_Number) delta);
@ -321,8 +314,7 @@ static int lua_getresource(unit * u, const struct resource_type *rtype)
strlcpy(fname, rtype->_name[0], sizeof(fname)); strlcpy(fname, rtype->_name[0], sizeof(fname));
strlcat(fname, "_getresource", sizeof(fname)); strlcat(fname, "_getresource", sizeof(fname));
lua_pushstring(L, fname); lua_getglobal(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, u, TOLUA_CAST "unit"); tolua_pushusertype(L, u, TOLUA_CAST "unit");
@ -351,8 +343,7 @@ static bool lua_canuse_item(const unit * u, const struct item_type *itype)
lua_State *L = (lua_State *) global.vm_state; lua_State *L = (lua_State *) global.vm_state;
const char *fname = "item_canuse"; const char *fname = "item_canuse";
lua_pushstring(L, fname); lua_getglobal(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
tolua_pushstring(L, itype->rtype->_name[0]); tolua_pushstring(L, itype->rtype->_name[0]);
@ -381,8 +372,7 @@ lua_wage(const region * r, const faction * f, const race * rc, int in_turn)
const char *fname = "wage"; const char *fname = "wage";
int result = -1; int result = -1;
lua_pushstring(L, fname); lua_getglobal(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region"); tolua_pushusertype(L, (void *)r, TOLUA_CAST "region");
tolua_pushusertype(L, (void *)f, TOLUA_CAST "faction"); tolua_pushusertype(L, (void *)f, TOLUA_CAST "faction");
@ -413,8 +403,7 @@ static void lua_agebuilding(building * b)
strlcpy(fname, "age_", sizeof(fname)); strlcpy(fname, "age_", sizeof(fname));
strlcat(fname, b->type->_name, sizeof(fname)); strlcat(fname, b->type->_name, sizeof(fname));
lua_pushstring(L, fname); lua_getglobal(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building"); tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
@ -435,8 +424,7 @@ static int lua_building_protection(building * b, unit * u)
const char *fname = "building_protection"; const char *fname = "building_protection";
int result = 0; int result = 0;
lua_pushstring(L, fname); lua_getglobal(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building"); tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
@ -462,8 +450,7 @@ static double lua_building_taxes(building * b, int level)
const char *fname = "building_taxes"; const char *fname = "building_taxes";
double result = 0.0F; double result = 0.0F;
lua_pushstring(L, fname); lua_getglobal(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building"); tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
tolua_pushnumber(L, level); tolua_pushnumber(L, level);
@ -489,8 +476,7 @@ static int lua_maintenance(const unit * u)
const char *fname = "maintenance"; const char *fname = "maintenance";
int result = -1; int result = -1;
lua_pushstring(L, fname); lua_getglobal(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
@ -519,8 +505,7 @@ static int lua_equipmentcallback(const struct equipment *eq, unit * u)
strlcpy(fname, "equip_", sizeof(fname)); strlcpy(fname, "equip_", sizeof(fname));
strlcat(fname, eq->name, sizeof(fname)); strlcat(fname, eq->name, sizeof(fname));
lua_pushstring(L, fname); lua_getglobal(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
@ -551,8 +536,7 @@ lua_useitem(struct unit *u, const struct item_type *itype, int amount,
strlcpy(fname, "use_", sizeof(fname)); strlcpy(fname, "use_", sizeof(fname));
strlcat(fname, itype->rtype->_name[0], sizeof(fname)); strlcat(fname, itype->rtype->_name[0], sizeof(fname));
lua_pushstring(L, fname); lua_getglobal(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
tolua_pushnumber(L, (lua_Number) amount); tolua_pushnumber(L, (lua_Number) amount);
@ -582,8 +566,7 @@ static int lua_recruit(struct unit *u, const struct archetype *arch, int amount)
strlcpy(fname, "recruit_", sizeof(fname)); strlcpy(fname, "recruit_", sizeof(fname));
strlcat(fname, arch->name[0], sizeof(fname)); strlcat(fname, arch->name[0], sizeof(fname));
lua_pushstring(L, fname); lua_getglobal(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
tolua_pushnumber(L, (lua_Number) amount); tolua_pushnumber(L, (lua_Number) amount);

View File

@ -621,12 +621,7 @@ static bool is_freezing(const unit * u)
return true; return true;
} }
#define SA_HARBOUR 1 int check_ship_allowed(struct ship *sh, const region * r)
#define SA_COAST 1
#define SA_NO_INSECT -1
#define SA_NO_COAST -2
static bool is_ship_allowed(struct ship *sh, const region * r)
{ {
int c = 0; int c = 0;
static const building_type *bt_harbour = NULL; static const building_type *bt_harbour = NULL;
@ -634,7 +629,7 @@ static bool is_ship_allowed(struct ship *sh, const region * r)
if (bt_harbour == NULL) if (bt_harbour == NULL)
bt_harbour = bt_find("harbour"); bt_harbour = bt_find("harbour");
if (r_insectstalled(r)) { if (sh->region && r_insectstalled(r)) {
/* insekten dürfen nicht hier rein. haben wir welche? */ /* insekten dürfen nicht hier rein. haben wir welche? */
unit *u; unit *u;
@ -654,7 +649,7 @@ static bool is_ship_allowed(struct ship *sh, const region * r)
} }
} }
if (buildingtype_exists(r, bt_harbour, true)) if (bt_harbour && buildingtype_exists(r, bt_harbour, true))
return SA_HARBOUR; return SA_HARBOUR;
for (c = 0; sh->type->coasts[c] != NULL; ++c) { for (c = 0; sh->type->coasts[c] != NULL; ++c) {
if (sh->type->coasts[c] == r->terrain) if (sh->type->coasts[c] == r->terrain)
@ -746,7 +741,7 @@ static void drifting_ships(region * r)
region *rn; region *rn;
dir = (direction_t) ((d + d_offset) % MAXDIRECTIONS); dir = (direction_t) ((d + d_offset) % MAXDIRECTIONS);
rn = rconnect(r, dir); rn = rconnect(r, dir);
if (rn != NULL && fval(rn->terrain, SAIL_INTO) && is_ship_allowed(sh, rn) > 0) { if (rn != NULL && fval(rn->terrain, SAIL_INTO) && check_ship_allowed(sh, rn) > 0) {
rnext = rn; rnext = rn;
if (!fval(rnext->terrain, SEA_REGION)) if (!fval(rnext->terrain, SEA_REGION))
break; break;
@ -1809,7 +1804,7 @@ sail(unit * u, order * ord, bool move_on_land, region_list ** routep)
} }
} }
reason = is_ship_allowed(sh, next_point); reason = check_ship_allowed(sh, next_point);
if (reason<0) { if (reason<0) {
/* for some reason or another, we aren't allowed in there.. */ /* for some reason or another, we aren't allowed in there.. */
if (check_leuchtturm(current_point, NULL) || reason == SA_NO_INSECT) { if (check_leuchtturm(current_point, NULL) || reason == SA_NO_INSECT) {

View File

@ -67,6 +67,12 @@ extern "C" {
extern struct attrib_type at_speedup; 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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -4,6 +4,8 @@
#include <kernel/building.h> #include <kernel/building.h>
#include <kernel/move.h> #include <kernel/move.h>
#include <kernel/region.h> #include <kernel/region.h>
#include <kernel/ship.h>
#include <kernel/terrain.h>
#include <util/language.h> #include <util/language.h>
@ -78,5 +80,7 @@ CuSuite *get_move_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_building_type_exists); SUITE_ADD_TEST(suite, test_building_type_exists);
SUITE_ADD_TEST(suite, test_ship_not_allowed_in_coast);
SUITE_ADD_TEST(suite, test_ship_allowed_with_harbor);
return suite; return suite;
} }

View File

@ -171,7 +171,6 @@ ship *new_ship(const ship_type * stype, region * r, const struct locale *lang)
const char *sname = 0; const char *sname = 0;
assert(stype); assert(stype);
assert(r);
sh->no = newcontainerid(); sh->no = newcontainerid();
sh->coast = NODIRECTION; sh->coast = NODIRECTION;
sh->type = stype; sh->type = stype;
@ -188,7 +187,9 @@ ship *new_ship(const ship_type * stype, region * r, const struct locale *lang)
slprintf(buffer, sizeof(buffer), "%s %s", sname, shipid(sh)); slprintf(buffer, sizeof(buffer), "%s %s", sname, shipid(sh));
sh->name = strdup(buffer); sh->name = strdup(buffer);
shash(sh); shash(sh);
if (r) {
addlist(&r->ships, sh); addlist(&r->ships, sh);
}
return sh; return sh;
} }

View File

@ -138,6 +138,26 @@ ship * test_create_ship(region * r, const ship_type * stype)
return s; return s;
} }
ship_type * test_create_shiptype(const char ** names)
{
ship_type * stype = (ship_type*)calloc(sizeof(ship_type), 1);
stype->name[0] = strdup(names[0]);
stype->name[1] = strdup(names[1]);
locale_setstring(default_locale, names[0], names[0]);
st_register(stype);
return stype;
}
building_type * test_create_buildingtype(const char * name)
{
building_type * btype = (building_type*)calloc(sizeof(building_type), 1);
btype->flags = BTF_NAMECHANGE;
btype->_name = strdup(name);
locale_setstring(default_locale, name, name);
bt_register(btype);
return btype;
}
item_type * test_create_itemtype(const char ** names) { item_type * test_create_itemtype(const char ** names) {
resource_type * rtype; resource_type * rtype;
item_type * itype; item_type * itype;
@ -160,16 +180,14 @@ void test_create_world(void)
terrain_type *t_plain, *t_ocean; terrain_type *t_plain, *t_ocean;
region *island[2]; region *island[2];
int i; int i;
building_type *btype;
ship_type *stype;
item_type * itype; item_type * itype;
const char * horses[2] = { "horse", "horse_p" }; const char * names[] = { "horse", "horse_p", "boat", "boat_p" };
make_locale("de"); make_locale("de");
init_resources(); init_resources();
assert(!olditemtype[I_HORSE]); assert(!olditemtype[I_HORSE]);
itype = test_create_itemtype(horses); itype = test_create_itemtype(names);
olditemtype[I_HORSE] = itype; olditemtype[I_HORSE] = itype;
t_plain = test_create_terrain("plain", LAND_REGION | FOREST_REGION | WALK_INTO | CAVALRY_REGION); t_plain = test_create_terrain("plain", LAND_REGION | FOREST_REGION | WALK_INTO | CAVALRY_REGION);
@ -192,17 +210,8 @@ void test_create_world(void)
test_create_race("human"); test_create_race("human");
btype = (building_type*)calloc(sizeof(building_type), 1); test_create_buildingtype("castle");
btype->flags = BTF_NAMECHANGE; test_create_shiptype(names+2);
btype->_name = strdup("castle");
locale_setstring(default_locale, "castle", "castle");
bt_register(btype);
stype = (ship_type*)calloc(sizeof(ship_type), 1);
stype->name[0] = strdup("boat");
stype->name[1] = strdup("boat_p");
locale_setstring(default_locale, "boat", "boat");
st_register(stype);
} }
int main(int argc, char ** argv) { int main(int argc, char ** argv) {

View File

@ -39,6 +39,9 @@ extern "C" {
struct building * test_create_building(struct region * r, const struct building_type * btype); struct building * test_create_building(struct region * r, const struct building_type * btype);
struct ship * test_create_ship(struct region * r, const struct ship_type * stype); struct ship * test_create_ship(struct region * r, const struct ship_type * stype);
struct item_type * test_create_itemtype(const char ** names); struct item_type * test_create_itemtype(const char ** names);
struct ship_type *test_create_shiptype(const char **names);
struct building_type *test_create_buildingtype(const char *name);
int RunAllTests(void); int RunAllTests(void);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -23,6 +23,10 @@
#define LUA_MAXINPUT 512 #define LUA_MAXINPUT 512
#endif #endif
#if LUA_VERSION_NUM >= 502
#define lua_strlen(L, idx) lua_rawlen(L, idx)
#endif
#if defined(LUA_USE_READLINE) #if defined(LUA_USE_READLINE)
#include <stdio.h> #include <stdio.h>
#include <readline/readline.h> #include <readline/readline.h>
@ -109,7 +113,7 @@ static int report(lua_State * L, int status)
static int traceback(lua_State * L) static int traceback(lua_State * L)
{ {
lua_getfield(L, LUA_GLOBALSINDEX, "debug"); lua_getglobal(L, "debug");
if (!lua_istable(L, -1)) { if (!lua_istable(L, -1)) {
lua_pop(L, 1); lua_pop(L, 1);
return 1; return 1;
@ -149,8 +153,7 @@ static int docall(lua_State * L, int narg, int clear)
static const char *get_prompt(lua_State * L, int firstline) static const char *get_prompt(lua_State * L, int firstline)
{ {
const char *p = NULL; const char *p = NULL;
lua_pushstring(L, firstline ? "_PROMPT" : "_PROMPT2"); lua_getglobal(L, firstline ? "_PROMPT" : "_PROMPT2");
lua_rawget(L, LUA_GLOBALSINDEX);
p = lua_tostring(L, -1); p = lua_tostring(L, -1);
if (p == NULL) if (p == NULL)
p = (firstline ? PROMPT : PROMPT2); p = (firstline ? PROMPT : PROMPT2);