diff --git a/conf/e2/catalog.xml b/conf/e2/catalog.xml
index a66bf0428..d0c7333aa 100644
--- a/conf/e2/catalog.xml
+++ b/conf/e2/catalog.xml
@@ -5,12 +5,12 @@
diff --git a/conf/e2/config.xml b/conf/e2/config.xml
index 92b09b86c..6cb50a1be 100644
--- a/conf/e2/config.xml
+++ b/conf/e2/config.xml
@@ -1,36 +1,36 @@
-
+
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
@@ -43,11 +43,11 @@
-
-
-
-
-
+
+
+
+
+
@@ -93,6 +93,9 @@
+
+
+
diff --git a/conf/e3/catalog.xml b/conf/e3/catalog.xml
index beb8b55c9..9987e72c8 100644
--- a/conf/e3/catalog.xml
+++ b/conf/e3/catalog.xml
@@ -5,12 +5,12 @@
diff --git a/conf/e3/config.xml b/conf/e3/config.xml
index c17cec6f8..89eccdea9 100644
--- a/conf/e3/config.xml
+++ b/conf/e3/config.xml
@@ -1,32 +1,32 @@
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -39,11 +39,11 @@
-
-
-
-
-
+
+
+
+
+
@@ -116,6 +116,8 @@
+
+
diff --git a/conf/e4/catalog.xml b/conf/e4/catalog.xml
index beb8b55c9..9987e72c8 100644
--- a/conf/e4/catalog.xml
+++ b/conf/e4/catalog.xml
@@ -5,12 +5,12 @@
diff --git a/conf/e4/config.xml b/conf/e4/config.xml
index 641bfb25b..197dc4b69 100644
--- a/conf/e4/config.xml
+++ b/conf/e4/config.xml
@@ -1,32 +1,32 @@
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -39,11 +39,11 @@
-
-
-
-
-
+
+
+
+
+
diff --git a/res/armor.xml b/res/armor.xml
index f24ddcd35..f26848da2 100644
--- a/res/armor.xml
+++ b/res/armor.xml
@@ -2,12 +2,12 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
diff --git a/res/core/de/strings.xml b/res/core/de/strings.xml
index 51a24c4d4..351a7e376 100644
--- a/res/core/de/strings.xml
+++ b/res/core/de/strings.xml
@@ -275,11 +275,6 @@
-
- Tresen
- counter
-
-
wenige
few
diff --git a/res/e3a/buildings.xml b/res/e3a/buildings.xml
index 227a2e47a..d95f5ce86 100644
--- a/res/e3a/buildings.xml
+++ b/res/e3a/buildings.xml
@@ -1,7 +1,7 @@
-
+
diff --git a/res/e3a/races.xml b/res/e3a/races.xml
index d5e3831c4..46427ba92 100644
--- a/res/e3a/races.xml
+++ b/res/e3a/races.xml
@@ -3,10 +3,10 @@
-
-
-
-
+
+
+
+
diff --git a/res/e3a/resources.xml b/res/e3a/resources.xml
index 4ab29a5b6..32a79d52e 100644
--- a/res/e3a/resources.xml
+++ b/res/e3a/resources.xml
@@ -2,13 +2,13 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
diff --git a/res/e3a/weapons.xml b/res/e3a/weapons.xml
index 91748d64e..052266a02 100644
--- a/res/e3a/weapons.xml
+++ b/res/e3a/weapons.xml
@@ -1,25 +1,25 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/res/weapons.xml b/res/weapons.xml
index 0cab11ad0..d0b508012 100644
--- a/res/weapons.xml
+++ b/res/weapons.xml
@@ -1,25 +1,25 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 70182005d..71651c1a0 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -12,26 +12,31 @@ include_directories (${LUA_INCLUDE_DIR})
include_directories (${BSON_INCLUDE_DIR})
include_directories (${INIPARSER_INCLUDE_DIR})
-IF(CMAKE_COMPILER_IS_GNUCC)
- execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
- OUTPUT_VARIABLE GCC_VERSION)
- if (GCC_VERSION VERSION_GREATER 4.9)
- SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wfloat-conversion")
- endif()
+IF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wno-sign-conversion")
-
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wsign-compare -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=unused-but-set-variable")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -DHAVE__BOOL")
-elseif(MSVC)
+ELSEIF(MSVC)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Wall /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)
+ELSE()
+ MESSAGE(STATUS "unknown compiler ${CMAKE_C_COMPILER_ID}")
+ENDIF()
+
+IF(CMAKE_COMPILER_IS_CLANG)
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wtautological-compare -Weverything")
+ MESSAGE(STATUS "compiler is clang: ${CMAKE_C_COMPILER_ID}")
+ELSEIF(CMAKE_COMPILER_IS_GCC)
+ EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} -dumpversion
+ OUTPUT_VARIABLE GCC_VERSION)
+ IF (GCC_VERSION VERSION_GREATER 4.9)
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wfloat-conversion")
+ ENDIF()
+ENDIF(CMAKE_COMPILER_IS_CLANG)
add_subdirectory(util)
add_subdirectory(kernel)
diff --git a/src/battle.c b/src/battle.c
index ee9465602..db2dbc3ca 100644
--- a/src/battle.c
+++ b/src/battle.c
@@ -431,7 +431,7 @@ static int get_row(const side * s, int row, const side * vs)
return result;
}
-int get_unitrow(const fighter * af, const side * vs)
+static int get_unitrow(const fighter * af, const side * vs)
{
int row = statusrow(af->status);
if (vs == NULL) {
@@ -3661,6 +3661,24 @@ static void free_fighter(fighter * fig)
}
+static void battle_free(battle * b) {
+ side *s;
+
+ assert(b);
+
+ for (s = b->sides; s != b->sides + b->nsides; ++s) {
+ fighter *fnext = s->fighters;
+ while (fnext) {
+ fighter *fig = fnext;
+ fnext = fig->next;
+ free_fighter(fig);
+ free(fig);
+ }
+ free_side(s);
+ }
+ free(b);
+}
+
void free_battle(battle * b)
{
int max_fac_no = 0;
@@ -3740,7 +3758,7 @@ static int battle_report(battle * b)
char buffer[32];
if (komma) {
- bytes = strlcpy(bufp, ", ", size);
+ strlcpy(bufp, ", ", size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
@@ -4295,21 +4313,3 @@ void do_battle(region * r)
}
}
-void battle_free(battle * b) {
- side *s;
-
- assert(b);
-
- for (s = b->sides; s != b->sides + b->nsides; ++s) {
- fighter *fnext = s->fighters;
- while (fnext) {
- fighter *fig = fnext;
- fnext = fig->next;
- free_fighter(fig);
- free(fig);
- }
- free_side(s);
- }
- free(b);
-}
-
diff --git a/src/battle.h b/src/battle.h
index 9bf500ed9..075edf496 100644
--- a/src/battle.h
+++ b/src/battle.h
@@ -225,8 +225,6 @@ extern "C" {
extern const troop no_troop;
/* BEGIN battle interface */
- void battle_init(battle * b);
- void battle_free(battle * b);
side * find_side(battle * b, const struct faction * f, const struct group * g, unsigned int flags, const struct faction * stealthfaction);
side * get_side(battle * b, const struct unit * u);
fighter * get_fighter(battle * b, const struct unit * u);
@@ -251,11 +249,10 @@ extern "C" {
extern int hits(troop at, troop dt, weapon * awp);
extern void damage_building(struct battle *b, struct building *bldg,
int damage_abs);
- extern struct quicklist *fighters(struct battle *b, const struct side *vs,
+ struct quicklist *fighters(struct battle *b, const struct side *vs,
int minrow, int maxrow, int mask);
- extern int count_allies(const struct side *as, int minrow, int maxrow,
+ int count_allies(const struct side *as, int minrow, int maxrow,
int select, int allytype);
- extern int get_unitrow(const struct fighter *af, const struct side *vs);
extern bool helping(const struct side *as, const struct side *ds);
extern void rmfighter(fighter * df, int i);
extern struct fighter *select_corpse(struct battle *b, struct fighter *af);
diff --git a/src/bind_building.c b/src/bind_building.c
index 8b89d2618..f52789700 100644
--- a/src/bind_building.c
+++ b/src/bind_building.c
@@ -114,7 +114,7 @@ static int tolua_building_set_name(lua_State * L)
static int tolua_building_get_size(lua_State * L)
{
building *self = (building *)tolua_tousertype(L, 1, 0);
- tolua_pushnumber(L, self->size);
+ lua_pushinteger(L, self->size);
return 1;
}
@@ -145,7 +145,7 @@ static int tolua_building_get_units(lua_State * L)
static int tolua_building_get_id(lua_State * L)
{
building *self = (building *)tolua_tousertype(L, 1, 0);
- tolua_pushnumber(L, (lua_Number)self->no);
+ lua_pushinteger(L, self->no);
return 1;
}
diff --git a/src/bind_dict.c b/src/bind_dict.c
index 28bcc5d81..32d3c498d 100644
--- a/src/bind_dict.c
+++ b/src/bind_dict.c
@@ -47,7 +47,7 @@ static int tolua_dict_get(lua_State * L)
lua_pushnil(L);
break;
case TINTEGER:
- lua_pushnumber(L, (lua_Number)val.i);
+ lua_pushinteger(L, val.i);
break;
case TREAL:
lua_pushnumber(L, (lua_Number)val.f);
diff --git a/src/bind_faction.c b/src/bind_faction.c
index 1846ea957..585cdcf35 100644
--- a/src/bind_faction.c
+++ b/src/bind_faction.c
@@ -77,35 +77,35 @@ int tolua_faction_add_item(lua_State * L)
result = i ? i->number : 0;
} /* if (itype!=NULL) */
}
- lua_pushnumber(L, result);
+ lua_pushinteger(L, result);
return 1;
}
static int tolua_faction_get_maxheroes(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
- tolua_pushnumber(L, (lua_Number)maxheroes(self));
+ lua_pushinteger(L, maxheroes(self));
return 1;
}
static int tolua_faction_get_heroes(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
- tolua_pushnumber(L, (lua_Number)countheroes(self));
+ lua_pushinteger(L, countheroes(self));
return 1;
}
static int tolua_faction_get_score(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
- tolua_pushnumber(L, (lua_Number)self->score);
+ lua_pushinteger(L, self->score);
return 1;
}
static int tolua_faction_get_id(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
- tolua_pushnumber(L, (lua_Number)self->no);
+ lua_pushinteger(L, self->no);
return 1;
}
@@ -148,7 +148,7 @@ static int tolua_faction_set_magic(lua_State * L)
static int tolua_faction_get_age(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
- tolua_pushnumber(L, (lua_Number)self->age);
+ lua_pushinteger(L, self->age);
return 1;
}
@@ -163,7 +163,7 @@ static int tolua_faction_set_age(lua_State * L)
static int tolua_faction_get_flags(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
- tolua_pushnumber(L, (lua_Number)self->flags);
+ lua_pushinteger(L, self->flags);
return 1;
}
@@ -178,7 +178,7 @@ static int tolua_faction_set_flags(lua_State * L)
static int tolua_faction_get_options(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
- tolua_pushnumber(L, (lua_Number)self->options);
+ lua_pushinteger(L, self->options);
return 1;
}
@@ -193,7 +193,7 @@ static int tolua_faction_set_options(lua_State * L)
static int tolua_faction_get_lastturn(lua_State * L)
{
faction *self = (faction *)tolua_tousertype(L, 1, 0);
- tolua_pushnumber(L, (lua_Number)self->lastorders);
+ lua_pushinteger(L, self->lastorders);
return 1;
}
@@ -245,7 +245,7 @@ static int tolua_faction_get_policy(lua_State * L)
}
}
- tolua_pushnumber(L, (lua_Number)result);
+ lua_pushinteger(L, result);
return 1;
}
@@ -283,8 +283,8 @@ static int tolua_faction_normalize(lua_State * L)
int nx = r->x, ny = r->y;
pnormalize(&nx, &ny, pl);
adjust_coordinates(f, &nx, &ny, pl);
- tolua_pushnumber(L, (lua_Number)nx);
- tolua_pushnumber(L, (lua_Number)ny);
+ lua_pushinteger(L, nx);
+ lua_pushinteger(L, ny);
return 2;
}
return 0;
@@ -319,8 +319,8 @@ static int tolua_faction_get_origin(lua_State * L)
y = 0;
}
- tolua_pushnumber(L, (lua_Number)x);
- tolua_pushnumber(L, (lua_Number)y);
+ lua_pushinteger(L, x);
+ lua_pushinteger(L, y);
return 2;
}
@@ -443,7 +443,7 @@ static int tolua_faction_set_name(lua_State * L)
static int tolua_faction_get_uid(lua_State * L)
{
faction *f = (faction *)tolua_tousertype(L, 1, 0);
- tolua_pushnumber(L, f->subscription);
+ lua_pushinteger(L, f->subscription);
return 1;
}
diff --git a/src/bind_gmtool.c b/src/bind_gmtool.c
index 3a07cfc6b..3c07bb3b7 100644
--- a/src/bind_gmtool.c
+++ b/src/bind_gmtool.c
@@ -152,8 +152,8 @@ static int tolua_make_island(lua_State * L)
int s = (int)tolua_tonumber(L, 3, 0);
int n = (int)tolua_tonumber(L, 4, s / 3);
- n = build_island_e3(x, y, n, s);
- tolua_pushnumber(L, n);
+ n = build_island_e3(NULL, x, y, n, s);
+ lua_pushinteger(L, n);
return 1;
}
@@ -166,8 +166,8 @@ static void lua_paint_info(struct window *wnd, const struct state *st)
int nx = st->cursor.x, ny = st->cursor.y;
pnormalize(&nx, &ny, st->cursor.pl);
lua_rawgeti(L, LUA_REGISTRYINDEX, paint_handle);
- tolua_pushnumber(L, nx);
- tolua_pushnumber(L, ny);
+ lua_pushinteger(L, nx);
+ lua_pushinteger(L, ny);
if (lua_pcall(L, 2, 1, 0) != 0) {
const char *error = lua_tostring(L, -1);
log_error("paint function failed: %s\n", error);
diff --git a/src/bind_message.c b/src/bind_message.c
index 75ff5821b..bbbd2bc0b 100644
--- a/src/bind_message.c
+++ b/src/bind_message.c
@@ -214,7 +214,7 @@ static int tolua_msg_set_string(lua_State * L)
const char *param = tolua_tostring(L, 2, 0);
const char *value = tolua_tostring(L, 3, 0);
int result = msg_set_string(lmsg, param, value);
- tolua_pushnumber(L, (lua_Number)result);
+ lua_pushinteger(L, result);
return 1;
}
@@ -224,7 +224,7 @@ static int tolua_msg_set_int(lua_State * L)
const char *param = tolua_tostring(L, 2, 0);
int value = (int)tolua_tonumber(L, 3, 0);
int result = msg_set_int(lmsg, param, value);
- tolua_pushnumber(L, (lua_Number)result);
+ lua_pushinteger(L, result);
return 1;
}
@@ -234,7 +234,7 @@ static int tolua_msg_set_resource(lua_State * L)
const char *param = tolua_tostring(L, 2, 0);
const char *value = tolua_tostring(L, 3, 0);
int result = msg_set_resource(lmsg, param, value);
- tolua_pushnumber(L, (lua_Number)result);
+ lua_pushinteger(L, result);
return 1;
}
@@ -244,7 +244,7 @@ static int tolua_msg_set_unit(lua_State * L)
const char *param = tolua_tostring(L, 2, 0);
unit *value = (unit *)tolua_tousertype(L, 3, 0);
int result = msg_set_unit(lmsg, param, value);
- tolua_pushnumber(L, (lua_Number)result);
+ lua_pushinteger(L, result);
return 1;
}
@@ -254,7 +254,7 @@ static int tolua_msg_set_region(lua_State * L)
const char *param = tolua_tostring(L, 2, 0);
region *value = (region *)tolua_tousertype(L, 3, 0);
int result = msg_set_region(lmsg, param, value);
- tolua_pushnumber(L, (lua_Number)result);
+ lua_pushinteger(L, result);
return 1;
}
@@ -270,7 +270,7 @@ static int tolua_msg_set(lua_State * L)
else if (tolua_isusertype(L, 3, TOLUA_CAST "unit", 0, &err)) {
return tolua_msg_set_unit(L);
}
- tolua_pushnumber(L, (lua_Number)-1);
+ lua_pushinteger(L, -1);
return 1;
}
@@ -279,7 +279,7 @@ static int tolua_msg_send_region(lua_State * L)
lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
region *r = (region *)tolua_tousertype(L, 2, 0);
int result = msg_send_region(lmsg, r);
- tolua_pushnumber(L, (lua_Number)result);
+ lua_pushinteger(L, result);
return 1;
}
@@ -293,7 +293,7 @@ static int tolua_msg_report_action(lua_State * L)
lmsg->msg = msg_create(lmsg->mtype, lmsg->args);
}
result = report_action(r, u, lmsg->msg, flags);
- tolua_pushnumber(L, (lua_Number)result);
+ lua_pushinteger(L, result);
return 1;
}
@@ -303,7 +303,7 @@ static int tolua_msg_send_faction(lua_State * L)
faction *f = (faction *)tolua_tousertype(L, 2, 0);
if (f && lmsg) {
int result = msg_send_faction(lmsg, f);
- tolua_pushnumber(L, (lua_Number)result);
+ lua_pushinteger(L, result);
return 1;
}
return 0;
diff --git a/src/bind_monsters.c b/src/bind_monsters.c
index 8897da0d1..a106ec638 100644
--- a/src/bind_monsters.c
+++ b/src/bind_monsters.c
@@ -21,7 +21,7 @@ static int tolua_levitate_ship(lua_State * L)
float power = (float)tolua_tonumber(L, 3, 0);
int duration = (int)tolua_tonumber(L, 4, 0);
int cno = levitate_ship(sh, mage, power, duration);
- tolua_pushnumber(L, (lua_Number)cno);
+ lua_pushinteger(L, cno);
return 1;
}
diff --git a/src/bind_region.c b/src/bind_region.c
index 792f15ac0..f726bc8a6 100644
--- a/src/bind_region.c
+++ b/src/bind_region.c
@@ -62,7 +62,7 @@ int tolua_regionlist_next(lua_State * L)
static int tolua_region_get_id(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
- tolua_pushnumber(L, (lua_Number)self->uid);
+ lua_pushinteger(L, self->uid);
return 1;
}
@@ -85,14 +85,14 @@ static int tolua_region_set_blocked(lua_State * L)
static int tolua_region_get_x(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
- tolua_pushnumber(L, (lua_Number)self->x);
+ lua_pushinteger(L, self->x);
return 1;
}
static int tolua_region_get_y(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
- tolua_pushnumber(L, (lua_Number)self->y);
+ lua_pushinteger(L, self->y);
return 1;
}
@@ -199,7 +199,7 @@ static int tolua_region_set_name(lua_State * L)
static int tolua_region_get_morale(lua_State * L)
{
region *r = (region *)tolua_tousertype(L, 1, 0);
- tolua_pushnumber(L, region_get_morale(r));
+ lua_pushinteger(L, region_get_morale(r));
return 1;
}
@@ -323,7 +323,7 @@ static int tolua_region_get_resourcelevel(lua_State * L)
const rawmaterial *rm;
for (rm = r->resources; rm; rm = rm->next) {
if (rm->type->rtype == rtype) {
- tolua_pushnumber(L, (lua_Number)rm->level);
+ lua_pushinteger(L, rm->level);
return 1;
}
}
@@ -389,7 +389,7 @@ static int tolua_region_get_resource(lua_State * L)
}
}
- tolua_pushnumber(L, (lua_Number)result);
+ lua_pushinteger(L, result);
return 1;
}
@@ -524,7 +524,7 @@ static int tolua_region_get_age(lua_State * L)
region *self = (region *)tolua_tousertype(L, 1, 0);
if (self) {
- lua_pushnumber(L, self->age);
+ lua_pushinteger(L, self->age);
return 1;
}
return 0;
@@ -613,7 +613,7 @@ static int tolua_plane_set_name(lua_State * L)
static int tolua_plane_get_id(lua_State * L)
{
plane *self = (plane *)tolua_tousertype(L, 1, 0);
- tolua_pushnumber(L, (lua_Number)self->id);
+ lua_pushinteger(L, self->id);
return 1;
}
@@ -623,8 +623,8 @@ static int tolua_plane_normalize(lua_State * L)
int x = (int)tolua_tonumber(L, 2, 0);
int y = (int)tolua_tonumber(L, 3, 0);
pnormalize(&x, &y, self);
- tolua_pushnumber(L, (lua_Number)x);
- tolua_pushnumber(L, (lua_Number)y);
+ lua_pushinteger(L, x);
+ lua_pushinteger(L, y);
return 2;
}
@@ -638,8 +638,8 @@ static int tolua_plane_tostring(lua_State * L)
static int tolua_plane_get_size(lua_State * L)
{
plane *pl = (plane *)tolua_tousertype(L, 1, 0);
- lua_pushnumber(L, plane_width(pl));
- lua_pushnumber(L, plane_height(pl));
+ lua_pushinteger(L, plane_width(pl));
+ lua_pushinteger(L, plane_height(pl));
return 2;
}
@@ -657,7 +657,7 @@ static int tolua_distance(lua_State * L)
pnormalize(&x1, &y1, pl);
pnormalize(&x2, &y2, pl);
result = koor_distance(x1, y1, x2, y2);
- lua_pushnumber(L, result);
+ lua_pushinteger(L, result);
return 1;
}
diff --git a/src/bind_ship.c b/src/bind_ship.c
index 7dd1b02f6..595be35dd 100644
--- a/src/bind_ship.c
+++ b/src/bind_ship.c
@@ -45,7 +45,7 @@ int tolua_shiplist_next(lua_State * L)
static int tolua_ship_get_id(lua_State * L)
{
ship *self = (ship *)tolua_tousertype(L, 1, 0);
- tolua_pushnumber(L, (lua_Number)self->no);
+ lua_pushinteger(L, self->no);
return 1;
}
@@ -152,7 +152,7 @@ tolua_ship_tostring(lua_State * L)
static int tolua_ship_get_flags(lua_State * L)
{
ship *self = (ship *)tolua_tousertype(L, 1, 0);
- tolua_pushnumber(L, (lua_Number)self->flags);
+ lua_pushinteger(L, self->flags);
return 1;
}
@@ -179,7 +179,7 @@ static int tolua_ship_get_coast(lua_State * L)
{
ship *self = (ship *)tolua_tousertype(L, 1, 0);
if (self->coast) {
- tolua_pushnumber(L, self->coast);
+ lua_pushinteger(L, self->coast);
return 1;
}
return 0;
diff --git a/src/bind_sqlite.c b/src/bind_sqlite.c
index e2c0e69e3..e8c9b7565 100644
--- a/src/bind_sqlite.c
+++ b/src/bind_sqlite.c
@@ -44,7 +44,7 @@ static int tolua_db_execute(lua_State * L)
int res = sqlite3_exec(db, sql, 0, 0, 0);
- tolua_pushnumber(L, (LUA_NUMBER)res);
+ lua_pushinteger(L, res);
return 1;
}
diff --git a/src/bind_storage.c b/src/bind_storage.c
index d0fea8244..acdf1e046 100644
--- a/src/bind_storage.c
+++ b/src/bind_storage.c
@@ -77,7 +77,7 @@ static int tolua_storage_read_float(lua_State * L)
gamedata *data = (gamedata *)tolua_tousertype(L, 1, 0);
float num;
READ_FLT(data->store, &num);
- tolua_pushnumber(L, (lua_Number)num);
+ lua_pushnumber(L, num);
return 1;
}
@@ -86,7 +86,7 @@ static int tolua_storage_read_int(lua_State * L)
gamedata *data = (gamedata *)tolua_tousertype(L, 1, 0);
int num;
READ_INT(data->store, &num);
- tolua_pushnumber(L, (lua_Number)num);
+ lua_pushinteger(L, num);
return 1;
}
diff --git a/src/bind_unit.c b/src/bind_unit.c
index 4f262114c..200c53b9b 100755
--- a/src/bind_unit.c
+++ b/src/bind_unit.c
@@ -160,7 +160,7 @@ static int tolua_unit_set_group(lua_State * L)
{
unit *self = (unit *)tolua_tousertype(L, 1, 0);
int result = join_group(self, tolua_tostring(L, 2, 0));
- tolua_pushnumber(L, result);
+ lua_pushinteger(L, result);
return 1;
}
diff --git a/src/bindings.c b/src/bindings.c
index 098499a23..6e61dc186 100755
--- a/src/bindings.c
+++ b/src/bindings.c
@@ -123,7 +123,7 @@ static int tolua_quicklist_iter(lua_State * L)
void *data = ql_get(ql, index);
tolua_pushusertype(L, data, TOLUA_CAST type);
ql_advance(qlp, &index, 1);
- tolua_pushnumber(L, index);
+ lua_pushinteger(L, index);
lua_replace(L, lua_upvalueindex(2));
return 1;
}
@@ -139,7 +139,7 @@ int tolua_quicklist_push(struct lua_State *L, const char *list_type,
*qlist_ptr = list;
luaL_getmetatable(L, list_type);
lua_setmetatable(L, -2);
- lua_pushnumber(L, 0);
+ lua_pushinteger(L, 0);
lua_pushstring(L, elem_type);
lua_pushcclosure(L, tolua_quicklist_iter, 3); /* OBS: this closure has multiple upvalues (list, index, type_name) */
}
@@ -219,7 +219,7 @@ static int tolua_setkey(lua_State * L)
static int tolua_rng_int(lua_State * L)
{
- lua_pushnumber(L, (lua_Number)rng_int());
+ lua_pushinteger(L, rng_int());
return 1;
}
@@ -227,7 +227,7 @@ static int tolua_read_orders(lua_State * L)
{
const char *filename = tolua_tostring(L, 1, 0);
int result = readorders(filename);
- lua_pushnumber(L, (lua_Number)result);
+ lua_pushinteger(L, result);
return 1;
}
@@ -282,14 +282,14 @@ static int tolua_set_turn(lua_State * L)
static int tolua_get_turn(lua_State * L)
{
- tolua_pushnumber(L, (lua_Number)turn);
+ lua_pushinteger(L, turn);
return 1;
}
static int tolua_atoi36(lua_State * L)
{
const char *s = tolua_tostring(L, 1, 0);
- tolua_pushnumber(L, (lua_Number)atoi36(s));
+ lua_pushinteger(L, atoi36(s));
return 1;
}
@@ -303,7 +303,7 @@ static int tolua_itoa36(lua_State * L)
static int tolua_dice_rand(lua_State * L)
{
const char *s = tolua_tostring(L, 1, 0);
- tolua_pushnumber(L, dice_rand(s));
+ lua_pushinteger(L, dice_rand(s));
return 1;
}
@@ -320,7 +320,7 @@ static int tolua_addequipment(lua_State * L)
result = 0;
}
}
- lua_pushnumber(L, (lua_Number)result);
+ lua_pushinteger(L, result);
return 1;
}
@@ -426,7 +426,7 @@ static int tolua_get_nmrs(lua_State * L)
}
result = nmrs[n];
}
- tolua_pushnumber(L, (lua_Number)result);
+ lua_pushinteger(L, result);
return 1;
}
@@ -451,7 +451,7 @@ static int tolua_equipment_setitem(lua_State * L)
result = 0;
}
}
- tolua_pushnumber(L, (lua_Number)result);
+ lua_pushinteger(L, result);
return 1;
}
@@ -465,7 +465,7 @@ static int tolua_spawn_braineaters(lua_State * L)
static int tolua_init_reports(lua_State * L)
{
int result = init_reports();
- tolua_pushnumber(L, (lua_Number)result);
+ lua_pushinteger(L, result);
return 1;
}
@@ -475,7 +475,7 @@ static int tolua_write_report(lua_State * L)
if (f) {
time_t ltime = time(0);
int result = write_reports(f, ltime);
- tolua_pushnumber(L, (lua_Number)result);
+ lua_pushinteger(L, result);
}
else {
tolua_pushstring(L, "function expects a faction, got nil");
@@ -488,7 +488,7 @@ static int tolua_write_reports(lua_State * L)
int result;
init_reports();
result = reports();
- tolua_pushnumber(L, (lua_Number)result);
+ lua_pushinteger(L, result);
return 1;
}
@@ -534,7 +534,7 @@ static int tolua_process_orders(lua_State * L)
static int tolua_write_passwords(lua_State * L)
{
int result = writepasswd();
- lua_pushnumber(L, (lua_Number)result);
+ lua_pushinteger(L, result);
return 0;
}
@@ -568,7 +568,7 @@ static int tolua_write_map(lua_State * L)
static int tolua_read_turn(lua_State * L)
{
int cturn = current_turn();
- tolua_pushnumber(L, (lua_Number)cturn);
+ lua_pushinteger(L, cturn);
return 1;
}
@@ -661,7 +661,7 @@ static int tolua_get_alliance_factions(lua_State * L)
static int tolua_get_alliance_id(lua_State * L)
{
alliance *self = (alliance *)tolua_tousertype(L, 1, 0);
- tolua_pushnumber(L, (lua_Number)self->id);
+ lua_pushinteger(L, self->id);
return 1;
}
@@ -982,7 +982,7 @@ static int tolua_get_spell_school(lua_State * L)
static int tolua_get_spell_level(lua_State * L)
{
spell *self = (spell *) tolua_tousertype(L, 1, 0);
- lua_pushnumber(L, self->level);
+ lua_pushinteger(L, self->level);
return 1;
}
#endif
@@ -1069,7 +1069,7 @@ static void parse_inifile(lua_State * L, dictionary * d, const char *section)
tolua_pushstring(L, str_value);
}
else {
- tolua_pushnumber(L, num_value);
+ lua_pushnumber(L, num_value);
}
lua_rawset(L, -3);
}
diff --git a/src/creport.c b/src/creport.c
index 890513c8a..f33d29c1c 100644
--- a/src/creport.c
+++ b/src/creport.c
@@ -1500,7 +1500,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset)
FILE *F = fopen(filename, "wt");
if (era < 0) {
- era = get_param_int(global.parameters, "world.era", 2);
+ era = get_param_int(global.parameters, "world.era", 1);
}
if (F == NULL) {
perror(filename);
diff --git a/src/give.c b/src/give.c
index 646770074..c4fb2ceb4 100644
--- a/src/give.c
+++ b/src/give.c
@@ -401,7 +401,7 @@ message * disband_men(int n, unit * u, struct order *ord) {
void give_unit(unit * u, unit * u2, order * ord)
{
region *r = u->region;
- int n = u->number;
+ int maxt = max_transfers();
if (!rule_transfermen() && u->faction != u2->faction) {
cmistake(u, ord, 74, MSG_COMMERCE);
@@ -472,9 +472,11 @@ void give_unit(unit * u, unit * u2, order * ord)
cmistake(u, ord, 105, MSG_COMMERCE);
return;
}
- if (u2->faction->newbies + n > max_transfers()) {
- cmistake(u, ord, 129, MSG_COMMERCE);
- return;
+ if (maxt >= 0 && u->faction != u2->faction) {
+ if (u2->faction->newbies + u->number > maxt) {
+ cmistake(u, ord, 129, MSG_COMMERCE);
+ return;
+ }
}
if (u_race(u) != u2->faction->race) {
if (u2->faction->race != get_race(RC_HUMAN)) {
@@ -510,9 +512,9 @@ void give_unit(unit * u, unit * u2, order * ord)
cmistake(u, ord, 156, MSG_COMMERCE);
return;
}
- add_give(u, u2, n, n, get_resourcetype(R_PERSON), ord, 0);
+ add_give(u, u2, u->number, u->number, get_resourcetype(R_PERSON), ord, 0);
u_setfaction(u, u2->faction);
- u2->faction->newbies += n;
+ u2->faction->newbies += u->number;
}
bool can_give_to(unit *u, unit *u2) {
diff --git a/src/give.test.c b/src/give.test.c
index f1b13011d..a5714f445 100644
--- a/src/give.test.c
+++ b/src/give.test.c
@@ -3,6 +3,7 @@
#include "give.h"
#include "economy.h"
+#include
#include
#include
#include
@@ -34,6 +35,10 @@ static void setup_give(struct give *env) {
env->dst = env->f2 ? test_create_unit(env->f2, env->r) : 0;
env->itype = it_get_or_create(rt_get_or_create("money"));
env->itype->flags |= ITF_HERB;
+ if (env->f1 && env->f2) {
+ ally * al = ally_add(&env->f2->allies, env->f1);
+ al->status = HELP_GIVE;
+ }
}
static void test_give_unit_to_peasants(CuTest * tc) {
@@ -49,6 +54,25 @@ static void test_give_unit_to_peasants(CuTest * tc) {
test_cleanup();
}
+static void test_give_unit(CuTest * tc) {
+ struct give env;
+ test_cleanup();
+ env.f1 = test_create_faction(0);
+ env.f2 = test_create_faction(0);
+ setup_give(&env);
+ env.r->terrain = test_create_terrain("ocean", SEA_REGION);
+ set_param(&global.parameters, "rules.give.max_men", "0");
+ give_unit(env.src, env.dst, NULL);
+ CuAssertPtrEquals(tc, env.f1, env.src->faction);
+ CuAssertIntEquals(tc, 0, env.f2->newbies);
+ set_param(&global.parameters, "rules.give.max_men", "-1");
+ give_unit(env.src, env.dst, NULL);
+ CuAssertPtrEquals(tc, env.f2, env.src->faction);
+ CuAssertIntEquals(tc, 1, env.f2->newbies);
+ CuAssertPtrEquals(tc, 0, env.f1->units);
+ test_cleanup();
+}
+
static void test_give_unit_in_ocean(CuTest * tc) {
struct give env;
test_cleanup();
@@ -284,6 +308,7 @@ CuSuite *get_give_suite(void)
SUITE_ADD_TEST(suite, test_give_men_other_faction);
SUITE_ADD_TEST(suite, test_give_men_requires_contact);
SUITE_ADD_TEST(suite, test_give_men_not_to_self);
+ SUITE_ADD_TEST(suite, test_give_unit);
SUITE_ADD_TEST(suite, test_give_unit_in_ocean);
SUITE_ADD_TEST(suite, test_give_unit_to_peasants);
SUITE_ADD_TEST(suite, test_give_peasants);
diff --git a/src/gmtool.c b/src/gmtool.c
index 920d02a30..f009f6dbf 100644
--- a/src/gmtool.c
+++ b/src/gmtool.c
@@ -65,6 +65,7 @@
static int g_quit;
int force_color = 0;
+newfaction * new_players = 0;
state *current_state = NULL;
@@ -793,7 +794,7 @@ static void handlekey(state * st, int c)
region *r;
char sbuffer[80];
static char kbuffer[80];
- int n, nx, ny;
+ int n, nx, ny, minpop, maxpop;
switch (c) {
case FAST_RIGHT:
@@ -846,12 +847,20 @@ static void handlekey(state * st, int c)
loaddata(st);
break;
case 'B':
- /*
- make_block(st->cursor.x, st->cursor.y, 6, select_terrain(st, NULL));
- */
+ if (!new_players) {
+ sprintf(sbuffer, "%s/newfactions", basepath());
+ new_players = read_newfactions(sbuffer);
+ }
cnormalize(&st->cursor, &nx, &ny);
- n = rng_int() % 8 + 8;
- build_island_e3(nx, ny, n, n * 3);
+ minpop = get_param_int(global.parameters, "seed.population.min", 8);
+ maxpop = get_param_int(global.parameters, "seed.population.max", minpop);
+ if (maxpop > minpop) {
+ n = rng_int() % (maxpop - minpop) + minpop;
+ }
+ else {
+ n = minpop;
+ }
+ build_island_e3(&new_players, nx, ny, n, n * 3);
st->modified = 1;
st->wnd_info->update |= 1;
st->wnd_status->update |= 1;
@@ -1052,8 +1061,11 @@ static void handlekey(state * st, int c)
tag_region(st->selected, nx, ny);
break;
case 'A':
- sprintf(sbuffer, "%s/newfactions", basepath());
- seed_players(sbuffer, false);
+ if (!new_players) {
+ sprintf(sbuffer, "%s/newfactions", basepath());
+ new_players = read_newfactions(sbuffer);
+ }
+ seed_players(&new_players, false);
st->wnd_map->update |= 1;
break;
case '/':
@@ -1332,15 +1344,14 @@ const char *prompt)
return buffer[0] != 0;
}
-void seed_players(const char *filename, bool new_island)
+void seed_players(newfaction **players, bool new_island)
{
- newfaction *players = read_newfactions(filename);
- if (players != NULL) {
- while (players) {
- int n = listlen(players);
+ if (players) {
+ while (*players) {
+ int n = listlen(*players);
int k = (n + ISLANDSIZE - 1) / ISLANDSIZE;
k = n / k;
- n = autoseed(&players, k, new_island ? 0 : TURNS_PER_ISLAND);
+ n = autoseed(players, k, new_island ? 0 : TURNS_PER_ISLAND);
if (n == 0) {
break;
}
diff --git a/src/gmtool.h b/src/gmtool.h
index ae2cea39a..d5396a615 100644
--- a/src/gmtool.h
+++ b/src/gmtool.h
@@ -20,6 +20,7 @@ extern "C" {
struct state;
struct region;
struct terrain_type;
+ struct newfaction;
int gmmain(int argc, char *argv[]);
int curses_readline(struct lua_State *L, char *buffer, size_t size,
@@ -35,7 +36,7 @@ extern "C" {
void state_close(struct state *);
void make_block(int x, int y, int radius, const struct terrain_type *terrain);
- void seed_players(const char *filename, bool new_island);
+ void seed_players(struct newfaction **players, bool new_island);
#ifdef __cplusplus
}
diff --git a/src/helpers.c b/src/helpers.c
index 4690023e9..29038afb3 100644
--- a/src/helpers.c
+++ b/src/helpers.c
@@ -58,7 +58,7 @@ lua_giveitem(unit * s, unit * d, const item_type * itype, int n, struct order *o
tolua_pushusertype(L, s, TOLUA_CAST "unit");
tolua_pushusertype(L, d, TOLUA_CAST "unit");
tolua_pushstring(L, iname);
- tolua_pushnumber(L, (lua_Number)n);
+ lua_pushinteger(L, n);
if (lua_pcall(L, 4, 1, 0) != 0) {
const char *error = lua_tostring(L, -1);
@@ -121,7 +121,7 @@ produce_resource(region * r, const resource_type * rtype, int norders)
lua_getglobal(L, fname);
if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region");
- tolua_pushnumber(L, (lua_Number)norders);
+ lua_pushinteger(L, norders);
if (lua_pcall(L, 2, 0, 0) != 0) {
const char *error = lua_tostring(L, -1);
@@ -177,8 +177,8 @@ static int lua_callspell(castorder * co)
int nparam = 4;
tolua_pushusertype(L, r, TOLUA_CAST "region");
tolua_pushusertype(L, caster, TOLUA_CAST "unit");
- tolua_pushnumber(L, (lua_Number)co->level);
- tolua_pushnumber(L, (lua_Number)co->force);
+ lua_pushinteger(L, co->level);
+ lua_pushnumber(L, co->force);
if (co->sp->parameter && co->par->length) {
const char *synp = co->sp->parameter;
int i = 0;
@@ -267,7 +267,7 @@ lua_changeresource(unit * u, const struct resource_type *rtype, int delta)
lua_getglobal(L, fname);
if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, u, TOLUA_CAST "unit");
- tolua_pushnumber(L, (lua_Number)delta);
+ lua_pushinteger(L, delta);
if (lua_pcall(L, 2, 1, 0) != 0) {
const char *error = lua_tostring(L, -1);
@@ -363,7 +363,7 @@ lua_wage(const region * r, const faction * f, const race * rc, int in_turn)
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region");
tolua_pushusertype(L, (void *)f, TOLUA_CAST "faction");
tolua_pushstring(L, rc ? rc->_name : 0);
- tolua_pushnumber(L, (lua_Number)in_turn);
+ lua_pushinteger(L, in_turn);
if (lua_pcall(L, 3, 1, 0) != 0) {
const char *error = lua_tostring(L, -1);
@@ -416,7 +416,7 @@ static double lua_building_taxes(building * b, int level)
lua_getglobal(L, fname);
if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
- tolua_pushnumber(L, level);
+ lua_pushinteger(L, level);
if (lua_pcall(L, 2, 1, 0) != 0) {
const char *error = lua_tostring(L, -1);
@@ -508,7 +508,7 @@ struct order *ord)
lua_getglobal(L, fname);
if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
- tolua_pushnumber(L, (lua_Number)amount);
+ lua_pushinteger(L, amount);
if (lua_pcall(L, 2, 1, 0) != 0) {
const char *error = lua_tostring(L, -1);
diff --git a/src/kernel/curse.test.c b/src/kernel/curse.test.c
index 577d6551a..7f8bb4db2 100644
--- a/src/kernel/curse.test.c
+++ b/src/kernel/curse.test.c
@@ -1,15 +1,27 @@
#include
-#include "types.h"
-#include "curse.h"
+#include
#include
#include
+#include
#include
#include
+#include
+#include
+#include
+#include
+#include
#include
+#include "curse.h"
+
+#include
+#include
+#include
+
#include
+
static void test_curse(CuTest * tc)
{
attrib *attrs = NULL;
@@ -83,6 +95,58 @@ static void test_bad_dreams(CuTest *tc) {
test_cleanup();
}
+static void test_memstream(CuTest *tc) {
+ storage store;
+ stream out = { 0 };
+ char buf[1024];
+ int val=0;
+
+ mstream_init(&out);
+ binstore_init(&store, &out);
+ store.handle.data = &out;
+
+ WRITE_INT(&store, 999999);
+ WRITE_TOK(&store, "fortytwo");
+ WRITE_INT(&store, 42);
+
+ out.api->rewind(out.handle);
+ READ_INT(&store, &val);
+ READ_TOK(&store, buf, 1024);
+ CuAssertIntEquals(tc, 999999, val);
+ CuAssertStrEquals(tc, "fortytwo", buf);
+ READ_INT(&store, &val);
+ CuAssertIntEquals(tc, 42, val);
+ mstream_done(&out);
+}
+
+static void test_write_flag(CuTest *tc) {
+ curse_fixture fix;
+ storage store;
+ char buf[1024];
+ stream out = { 0 };
+ size_t len;
+
+ mstream_init(&out);
+ binstore_init(&store, &out);
+ store.handle.data = &out;
+
+ setup_curse(&fix, "gbdream");
+ fix.c->flags = 42 | CURSE_ISNEW;
+ curse_write(fix.r->attribs, fix.r, &store);
+ out.api->rewind(out.handle);
+ len = out.api->read(out.handle, buf, sizeof(buf));
+ buf[len] = '\0';
+ out.api->rewind(out.handle);
+ curse_read(fix.r->attribs, fix.r, &store);
+ CuAssertIntEquals(tc, 42 | CURSE_ISNEW, ((curse *) fix.r->attribs->data.v)->flags);
+ global.data_version = RELEASE_VERSION;
+ CuAssertIntEquals(tc, RELEASE_VERSION, global.data_version);
+
+ mstream_done(&out);
+ binstore_done(&store);
+ test_cleanup();
+}
+
CuSuite *get_curse_suite(void)
{
CuSuite *suite = CuSuiteNew();
@@ -91,5 +155,7 @@ CuSuite *get_curse_suite(void)
SUITE_ADD_TEST(suite, test_magicstreet_warning);
SUITE_ADD_TEST(suite, test_good_dreams);
SUITE_ADD_TEST(suite, test_bad_dreams);
+ SUITE_ADD_TEST(suite, test_memstream);
+ SUITE_ADD_TEST(suite, test_write_flag);
return suite;
}
diff --git a/src/kernel/region.c b/src/kernel/region.c
index 3656c8ef1..24c11a0dd 100644
--- a/src/kernel/region.c
+++ b/src/kernel/region.c
@@ -956,8 +956,10 @@ void setluxuries(region * r, const luxury_type * sale)
assert(r->land);
- if (r->land->demands)
+ if (r->land->demands) {
freelist(r->land->demands);
+ r->land->demands = 0;
+ }
for (ltype = luxurytypes; ltype; ltype = ltype->next) {
struct demand *dmd = malloc(sizeof(struct demand));
diff --git a/src/kernel/save.c b/src/kernel/save.c
index 2aaf4f3b9..25169d4af 100644
--- a/src/kernel/save.c
+++ b/src/kernel/save.c
@@ -1724,6 +1724,7 @@ int writegame(const char *filename)
gdata.store = &store;
gdata.encoding = enc_gamedata;
gdata.version = RELEASE_VERSION;
+ global.data_version = RELEASE_VERSION;
n = STREAM_VERSION;
fwrite(&gdata.version, sizeof(int), 1, F);
fwrite(&n, sizeof(int), 1, F);
diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c
index 7179238ab..b4b1da708 100644
--- a/src/kernel/xmlreader.c
+++ b/src/kernel/xmlreader.c
@@ -31,6 +31,10 @@ without prior permission by the authors of Eressea.
#include "vortex.h"
+#if SCORE_MODULE
+#include
+#endif
+
/* util includes */
#include
#include
@@ -766,9 +770,6 @@ static item_type *xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
itype->weight = xml_ivalue(node, "weight", 0);
itype->capacity = xml_ivalue(node, "capacity", 0);
itype->flags |= flags;
-#if SCORE_MODULE
- itype->score = xml_ivalue(node, "score", 0);
-#endif
/* reading item/construction */
xpath->node = node;
@@ -855,6 +856,10 @@ static item_type *xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
}
xmlFree(propValue);
}
+#if SCORE_MODULE
+ itype->score = xml_ivalue(node, "score", 0);
+ if (!itype->score) itype->score = default_score(itype);
+#endif
xmlXPathFreeObject(result);
return itype;
diff --git a/src/laws.test.c b/src/laws.test.c
index 58cba3942..609b93d03 100644
--- a/src/laws.test.c
+++ b/src/laws.test.c
@@ -696,12 +696,11 @@ static void test_reserve_self(CuTest *tc) {
static void statistic_test(CuTest *tc, int peasants, int luck, int maxp,
double variance, int min_value, int max_value) {
- int effect, i;
- for (i = 0; i < 1000; ++i) {
- effect = peasant_luck_effect(peasants, luck, maxp, variance);
- CuAssertTrue(tc, min_value <= effect);
- CuAssertTrue(tc, max_value >= effect);
- }
+ int effect;
+
+ effect = peasant_luck_effect(peasants, luck, maxp, variance);
+ CuAssertTrue(tc, min_value <= effect);
+ CuAssertTrue(tc, max_value >= effect);
}
static void test_peasant_luck_effect(CuTest *tc) {
@@ -713,6 +712,10 @@ static void test_peasant_luck_effect(CuTest *tc) {
statistic_test(tc, 100, 0, 1000, 0, 0, 0);
statistic_test(tc, 100, 2, 1000, 0, 1, 1);
+/*
+ statistic_test(tc, 1000, 400, 1000, 0, (int)(400 * 10 * 0.001 * .75),
+ (int)(400 * 10 * 0.001 * .75));
+ */
statistic_test(tc, 1000, 400, 1000, 0, 3, 3);
statistic_test(tc, 1000, 1000, 2000, .5, 1, 501);
diff --git a/src/main.c b/src/main.c
index 8b1c8d984..d6267e4ba 100644
--- a/src/main.c
+++ b/src/main.c
@@ -282,7 +282,6 @@ int main(int argc, char **argv)
int err = 0;
lua_State *L;
setup_signal_handler();
-
/* parse args once to read config file location */
if (parse_args(argc, argv, &err) != 0) {
return err;
diff --git a/src/modules/autoseed.c b/src/modules/autoseed.c
index eac860185..dd73943f2 100644
--- a/src/modules/autoseed.c
+++ b/src/modules/autoseed.c
@@ -904,10 +904,9 @@ static void smooth_island(region_list * island)
}
}
-static void starting_region(region * r, region * rn[])
+static void starting_region(newfaction ** players, region * r, region * rn[])
{
int n;
-
oceans_around(r, rn);
freset(r, RF_MARK);
for (n = 0; n != MAXDIRECTIONS; ++n) {
@@ -915,11 +914,19 @@ static void starting_region(region * r, region * rn[])
}
terraform_region(r, newterrain(T_PLAIN));
prepare_starting_region(r);
- addplayer(r, addfaction("enno@eressea.de", itoa36(rng_int()), races, default_locale, 0));
+ if (players && *players) {
+ newfaction *nf = *players;
+ const struct race *rc = nf->race ? nf->race : races;
+ const struct locale *lang = nf->lang ? nf->lang : default_locale;
+ const char * passwd = nf->password ? nf->password : itoa36(rng_int());
+ addplayer(r, addfaction(nf->email, passwd, rc, lang, 0));
+ *players = nf->next;
+ free_newfaction(nf);
+ }
}
/* E3A island generation */
-int build_island_e3(int x, int y, int numfactions, int minsize)
+int build_island_e3(newfaction ** players, int x, int y, int numfactions, int minsize)
{
#define MIN_QUALITY 1000
int nfactions = 0;
@@ -961,8 +968,8 @@ int build_island_e3(int x, int y, int numfactions, int minsize)
get_neighbours(r, rn);
q = region_quality(r, rn);
- if (q >= MIN_QUALITY && nfactions < numfactions) {
- starting_region(r, rn);
+ if (q >= MIN_QUALITY && nfactions < numfactions && *players) {
+ starting_region(players, r, rn);
minq = _min(minq, q);
maxq = _max(maxq, q);
++nfactions;
@@ -976,8 +983,8 @@ int build_island_e3(int x, int y, int numfactions, int minsize)
region *rn[MAXDIRECTIONS];
get_neighbours(r, rn);
q = region_quality(r, rn);
- if (q >= MIN_QUALITY * 4 / 3 && nfactions < numfactions) {
- starting_region(r, rn);
+ if (q >= MIN_QUALITY * 4 / 3 && nfactions < numfactions && *players) {
+ starting_region(players, r, rn);
minq = _min(minq, q);
maxq = _max(maxq, q);
++nfactions;
diff --git a/src/modules/autoseed.h b/src/modules/autoseed.h
index 9844d017c..3cfe6225c 100644
--- a/src/modules/autoseed.h
+++ b/src/modules/autoseed.h
@@ -40,7 +40,7 @@ extern "C" {
*terrains[], int distribution[], int size);
extern int seed_adamantium(struct region *r, int base);
- extern int build_island_e3(int x, int y, int numfactions, int minsize);
+ extern int build_island_e3(newfaction **players, int x, int y, int numfactions, int minsize);
#ifdef __cplusplus
}
diff --git a/src/modules/score.c b/src/modules/score.c
index bf3e472e1..26788199c 100644
--- a/src/modules/score.c
+++ b/src/modules/score.c
@@ -24,6 +24,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* kernel includes */
#include
#include
+#include
#include
#include
#include
@@ -214,4 +215,20 @@ void score(void)
}
}
+int default_score(const item_type *itype) {
+ int result = 0;
+ if (itype->construction) {
+ requirement *req = itype->construction->materials;
+ while (req->number) {
+ int score = req->rtype->itype ? req->rtype->itype->score : 10;
+ result += score * req->number * 2;
+ ++req;
+ }
+ }
+ else {
+ result = 10;
+ }
+ return result;
+}
+
#endif
diff --git a/src/modules/score.h b/src/modules/score.h
index 0cbe6b749..7ffdf64e5 100644
--- a/src/modules/score.h
+++ b/src/modules/score.h
@@ -26,8 +26,11 @@ extern "C" {
#error "must define SCORE_MODULE to use this module"
#endif
- extern void score(void);
- extern int average_score_of_age(int age, int a);
+ struct item_type;
+
+ void score(void);
+ int average_score_of_age(int age, int a);
+ int default_score(const struct item_type *itype);
#ifdef __cplusplus
}
diff --git a/src/names.c b/src/names.c
index 6681877fd..df2e5e0a6 100644
--- a/src/names.c
+++ b/src/names.c
@@ -357,7 +357,8 @@ static const char *dracoid_name(const unit * u)
static char name[NAMESIZE + 1]; // FIXME: static return value
int mid_syllabels;
- u = u;
+ /* ignore u */
+ u = 0;
/* Wieviele Mittelteile? */
mid_syllabels = rng_int() % 4;
diff --git a/src/util/bsdstring.c b/src/util/bsdstring.c
index c43847da1..4205b9480 100644
--- a/src/util/bsdstring.c
+++ b/src/util/bsdstring.c
@@ -12,10 +12,6 @@ int wrptr(char **ptr, size_t * size, size_t bytes)
if (bytes == 0) {
return 0;
}
- if (bytes < 0) {
- *size = 0;
- return EINVAL;
- }
if (bytes <= *size) {
*ptr += bytes;
*size -= bytes;
@@ -24,7 +20,7 @@ int wrptr(char **ptr, size_t * size, size_t bytes)
*ptr += *size;
*size = 0;
- return ENAMETOOLONG;
+ return ERANGE;
}
#ifndef HAVE_STRLCPY
diff --git a/storage b/storage
index 48768e4be..2bcd3b1e6 160000
--- a/storage
+++ b/storage
@@ -1 +1 @@
-Subproject commit 48768e4bef7ff28365487e047d3b910127c716d0
+Subproject commit 2bcd3b1e64764321773672333bd133a61b35b840