compiling with -pedantic on linux

This commit is contained in:
Enno Rehling 2011-03-08 08:44:20 +01:00
parent 04b3d7ff45
commit b4c5607747
16 changed files with 1850 additions and 1837 deletions

View file

@ -20,6 +20,7 @@ without prior permission by the authors of Eressea.
#include <kernel/binarystore.h> #include <kernel/binarystore.h>
#include <math.h> #include <math.h>
#include <stdio.h>
#include <lua.h> #include <lua.h>
#include <tolua.h> #include <tolua.h>

View file

@ -77,8 +77,8 @@ int log_lua_error(lua_State * L)
int tolua_orderlist_next(lua_State * L) int tolua_orderlist_next(lua_State * L)
{ {
order ** order_ptr = (order **) lua_touserdata(L, lua_upvalueindex(1)); order **order_ptr = (order **) lua_touserdata(L, lua_upvalueindex(1));
order * ord = *order_ptr; order *ord = *order_ptr;
if (ord != NULL) { if (ord != NULL) {
char cmd[8192]; char cmd[8192];
write_order(ord, cmd, sizeof(cmd)); write_order(ord, cmd, sizeof(cmd));
@ -91,8 +91,8 @@ int tolua_orderlist_next(lua_State * L)
static int tolua_quicklist_iter(lua_State * L) static int tolua_quicklist_iter(lua_State * L)
{ {
quicklist ** qlp = (quicklist **) lua_touserdata(L, lua_upvalueindex(1)); quicklist **qlp = (quicklist **) lua_touserdata(L, lua_upvalueindex(1));
quicklist * ql = *qlp; quicklist *ql = *qlp;
if (ql != NULL) { if (ql != NULL) {
int index = lua_tointeger(L, lua_upvalueindex(2)); int index = lua_tointeger(L, lua_upvalueindex(2));
const char *type = lua_tostring(L, lua_upvalueindex(3)); const char *type = lua_tostring(L, lua_upvalueindex(3));
@ -110,7 +110,7 @@ int tolua_quicklist_push(struct lua_State *L, const char *list_type,
const char *elem_type, struct quicklist *list) const char *elem_type, struct quicklist *list)
{ {
if (list) { if (list) {
quicklist ** qlist_ptr = quicklist **qlist_ptr =
(quicklist **) lua_newuserdata(L, sizeof(quicklist *)); (quicklist **) lua_newuserdata(L, sizeof(quicklist *));
*qlist_ptr = list; *qlist_ptr = list;
luaL_getmetatable(L, list_type); luaL_getmetatable(L, list_type);
@ -126,8 +126,8 @@ int tolua_quicklist_push(struct lua_State *L, const char *list_type,
int tolua_itemlist_next(lua_State * L) int tolua_itemlist_next(lua_State * L)
{ {
item ** item_ptr = (item **) lua_touserdata(L, lua_upvalueindex(1)); item **item_ptr = (item **) lua_touserdata(L, lua_upvalueindex(1));
item * itm = *item_ptr; item *itm = *item_ptr;
if (itm != NULL) { if (itm != NULL) {
tolua_pushstring(L, itm->type->rtype->_name[0]); tolua_pushstring(L, itm->type->rtype->_name[0]);
*item_ptr = itm->next; *item_ptr = itm->next;
@ -140,7 +140,7 @@ static int tolua_autoseed(lua_State * L)
{ {
const char *filename = tolua_tostring(L, 1, 0); const char *filename = tolua_tostring(L, 1, 0);
int new_island = tolua_toboolean(L, 2, 0); int new_island = tolua_toboolean(L, 2, 0);
newfaction * players = read_newfactions(filename); newfaction *players = read_newfactions(filename);
if (players != NULL) { if (players != NULL) {
while (players) { while (players) {
int n = listlen(players); int n = listlen(players);
@ -159,7 +159,7 @@ static int tolua_getkey(lua_State * L)
{ {
const char *name = tolua_tostring(L, 1, 0); const char *name = tolua_tostring(L, 1, 0);
int flag = atoi36(name); int flag = atoi36(name);
attrib * a = find_key(global.attribs, flag); attrib *a = find_key(global.attribs, flag);
lua_pushboolean(L, a != NULL); lua_pushboolean(L, a != NULL);
return 1; return 1;
} }
@ -182,7 +182,7 @@ static int tolua_setkey(lua_State * L)
const char *name = tolua_tostring(L, 1, 0); const char *name = tolua_tostring(L, 1, 0);
int value = tolua_toboolean(L, 2, 0); int value = tolua_toboolean(L, 2, 0);
int flag = atoi36(name); int flag = atoi36(name);
attrib * a = find_key(global.attribs, flag); attrib *a = find_key(global.attribs, flag);
if (a == NULL && value) { if (a == NULL && value) {
add_key(&global.attribs, flag); add_key(&global.attribs, flag);
} else if (a != NULL && !value) { } else if (a != NULL && !value) {
@ -207,8 +207,8 @@ static int tolua_read_orders(lua_State * L)
static int tolua_message_unit(lua_State * L) static int tolua_message_unit(lua_State * L)
{ {
unit * sender = (unit *) tolua_tousertype(L, 1, 0); unit *sender = (unit *) tolua_tousertype(L, 1, 0);
unit * target = (unit *) tolua_tousertype(L, 2, 0); unit *target = (unit *) tolua_tousertype(L, 2, 0);
const char *str = tolua_tostring(L, 3, 0); const char *str = tolua_tostring(L, 3, 0);
if (!target) if (!target)
tolua_error(L, TOLUA_CAST "target is nil", NULL); tolua_error(L, TOLUA_CAST "target is nil", NULL);
@ -220,8 +220,8 @@ static int tolua_message_unit(lua_State * L)
static int tolua_message_faction(lua_State * L) static int tolua_message_faction(lua_State * L)
{ {
unit * sender = (unit *) tolua_tousertype(L, 1, 0); unit *sender = (unit *) tolua_tousertype(L, 1, 0);
faction * target = (faction *) tolua_tousertype(L, 2, 0); faction *target = (faction *) tolua_tousertype(L, 2, 0);
const char *str = tolua_tostring(L, 3, 0); const char *str = tolua_tostring(L, 3, 0);
if (!target) if (!target)
tolua_error(L, TOLUA_CAST "target is nil", NULL); tolua_error(L, TOLUA_CAST "target is nil", NULL);
@ -233,7 +233,7 @@ static int tolua_message_faction(lua_State * L)
static int tolua_message_region(lua_State * L) static int tolua_message_region(lua_State * L)
{ {
unit * sender = (unit *) tolua_tousertype(L, 1, 0); unit *sender = (unit *) tolua_tousertype(L, 1, 0);
const char *str = tolua_tostring(L, 2, 0); const char *str = tolua_tostring(L, 2, 0);
if (!sender) if (!sender)
tolua_error(L, TOLUA_CAST "sender is nil", NULL); tolua_error(L, TOLUA_CAST "sender is nil", NULL);
@ -309,23 +309,23 @@ static int tolua_get_season(lua_State * L)
static int tolua_create_curse(lua_State * L) static int tolua_create_curse(lua_State * L)
{ {
unit * u = (unit *) tolua_tousertype(L, 1, 0); unit *u = (unit *) tolua_tousertype(L, 1, 0);
tolua_Error tolua_err; tolua_Error tolua_err;
attrib ** ap = NULL; attrib **ap = NULL;
if (tolua_isusertype(L, 2, TOLUA_CAST "unit", 0, &tolua_err)) { if (tolua_isusertype(L, 2, TOLUA_CAST "unit", 0, &tolua_err)) {
unit * target = (unit *) tolua_tousertype(L, 2, 0); unit *target = (unit *) tolua_tousertype(L, 2, 0);
if (target) if (target)
ap = &target->attribs; ap = &target->attribs;
} else if (tolua_isusertype(L, 2, TOLUA_CAST "region", 0, &tolua_err)) { } else if (tolua_isusertype(L, 2, TOLUA_CAST "region", 0, &tolua_err)) {
region * target = (region *) tolua_tousertype(L, 2, 0); region *target = (region *) tolua_tousertype(L, 2, 0);
if (target) if (target)
ap = &target->attribs; ap = &target->attribs;
} else if (tolua_isusertype(L, 2, TOLUA_CAST "ship", 0, &tolua_err)) { } else if (tolua_isusertype(L, 2, TOLUA_CAST "ship", 0, &tolua_err)) {
ship * target = (ship *) tolua_tousertype(L, 2, 0); ship *target = (ship *) tolua_tousertype(L, 2, 0);
if (target) if (target)
ap = &target->attribs; ap = &target->attribs;
} else if (tolua_isusertype(L, 2, TOLUA_CAST "building", 0, &tolua_err)) { } else if (tolua_isusertype(L, 2, TOLUA_CAST "building", 0, &tolua_err)) {
building * target = (building *) tolua_tousertype(L, 2, 0); building *target = (building *) tolua_tousertype(L, 2, 0);
if (target) if (target)
ap = &target->attribs; ap = &target->attribs;
} }
@ -337,7 +337,7 @@ static int tolua_create_curse(lua_State * L)
int duration = (int)tolua_tonumber(L, 5, 0); int duration = (int)tolua_tonumber(L, 5, 0);
double effect = tolua_tonumber(L, 6, 0); double effect = tolua_tonumber(L, 6, 0);
int men = (int)tolua_tonumber(L, 7, 0); /* optional */ int men = (int)tolua_tonumber(L, 7, 0); /* optional */
curse * c = create_curse(u, ap, ctype, vigour, duration, effect, men); curse *c = create_curse(u, ap, ctype, vigour, duration, effect, men);
if (c) { if (c) {
tolua_pushboolean(L, true); tolua_pushboolean(L, true);
return 1; return 1;
@ -350,7 +350,7 @@ static int tolua_create_curse(lua_State * L)
static int tolua_learn_skill(lua_State * L) static int tolua_learn_skill(lua_State * L)
{ {
unit * u = (unit *) tolua_tousertype(L, 1, 0); unit *u = (unit *) tolua_tousertype(L, 1, 0);
const char *skname = tolua_tostring(L, 2, 0); const char *skname = tolua_tostring(L, 2, 0);
float chances = (float)tolua_tonumber(L, 3, 0); float chances = (float)tolua_tonumber(L, 3, 0);
skill_t sk = sk_find(skname); skill_t sk = sk_find(skname);
@ -368,7 +368,7 @@ static int tolua_update_scores(lua_State * L)
static int tolua_update_owners(lua_State * L) static int tolua_update_owners(lua_State * L)
{ {
region * r; region *r;
for (r = regions; r; r = r->next) { for (r = regions; r; r = r->next) {
update_owners(r); update_owners(r);
} }
@ -403,7 +403,7 @@ static int tolua_get_nmrs(lua_State * L)
static int tolua_equipunit(lua_State * L) static int tolua_equipunit(lua_State * L)
{ {
unit * u = (unit *) tolua_tousertype(L, 1, 0); unit *u = (unit *) tolua_tousertype(L, 1, 0);
const char *eqname = tolua_tostring(L, 2, 0); const char *eqname = tolua_tostring(L, 2, 0);
equip_unit(u, get_equipment(eqname)); equip_unit(u, get_equipment(eqname));
return 0; return 0;
@ -442,7 +442,7 @@ static int tolua_init_reports(lua_State * L)
static int tolua_write_report(lua_State * L) static int tolua_write_report(lua_State * L)
{ {
faction * f = (faction *) tolua_tousertype(L, 1, 0); faction *f = (faction *) tolua_tousertype(L, 1, 0);
time_t ltime = time(0); time_t ltime = time(0);
int result = write_reports(f, ltime); int result = write_reports(f, ltime);
tolua_pushnumber(L, (lua_Number) result); tolua_pushnumber(L, (lua_Number) result);
@ -460,11 +460,11 @@ static int tolua_write_reports(lua_State * L)
static void reset_game(void) static void reset_game(void)
{ {
region * r; region *r;
faction * f; faction *f;
for (r = regions; r; r = r->next) { for (r = regions; r; r = r->next) {
unit * u; unit *u;
building * b; building *b;
r->flags &= RF_SAVEMASK; r->flags &= RF_SAVEMASK;
for (u = r->units; u; u = u->next) { for (u = r->units; u; u = u->next) {
u->flags &= UFL_SAVEMASK; u->flags &= UFL_SAVEMASK;
@ -473,7 +473,7 @@ static void reset_game(void)
b->flags &= BLD_SAVEMASK; b->flags &= BLD_SAVEMASK;
} }
if (r->land && r->land->ownership && r->land->ownership->owner) { if (r->land && r->land->ownership && r->land->ownership->owner) {
faction * owner = r->land->ownership->owner; faction *owner = r->land->ownership->owner;
if (owner == get_monsters()) { if (owner == get_monsters()) {
/* some compat-fix, i believe. */ /* some compat-fix, i believe. */
owner = update_owners(r); owner = update_owners(r);
@ -571,7 +571,7 @@ static int tolua_read_turn(lua_State * L)
static int tolua_get_faction(lua_State * L) static int tolua_get_faction(lua_State * L)
{ {
int no = tolua_toid(L, 1, 0); int no = tolua_toid(L, 1, 0);
faction * f = findfaction(no); faction *f = findfaction(no);
tolua_pushusertype(L, f, TOLUA_CAST "faction"); tolua_pushusertype(L, f, TOLUA_CAST "faction");
return 1; return 1;
} }
@ -580,7 +580,7 @@ static int tolua_get_region(lua_State * L)
{ {
int x = (int)tolua_tonumber(L, 1, 0); int x = (int)tolua_tonumber(L, 1, 0);
int y = (int)tolua_tonumber(L, 2, 0); int y = (int)tolua_tonumber(L, 2, 0);
region * r; region *r;
assert(!pnormalize(&x, &y, findplane(x, y))); assert(!pnormalize(&x, &y, findplane(x, y)));
r = findregion(x, y); r = findregion(x, y);
tolua_pushusertype(L, r, TOLUA_CAST "region"); tolua_pushusertype(L, r, TOLUA_CAST "region");
@ -590,7 +590,7 @@ static int tolua_get_region(lua_State * L)
static int tolua_get_region_byid(lua_State * L) static int tolua_get_region_byid(lua_State * L)
{ {
int uid = (int)tolua_tonumber(L, 1, 0); int uid = (int)tolua_tonumber(L, 1, 0);
region * r = findregionbyid(uid); region *r = findregionbyid(uid);
tolua_pushusertype(L, r, TOLUA_CAST "region"); tolua_pushusertype(L, r, TOLUA_CAST "region");
return 1; return 1;
} }
@ -598,7 +598,7 @@ static int tolua_get_region_byid(lua_State * L)
static int tolua_get_building(lua_State * L) static int tolua_get_building(lua_State * L)
{ {
int no = tolua_toid(L, 1, 0); int no = tolua_toid(L, 1, 0);
building * b = findbuilding(no); building *b = findbuilding(no);
tolua_pushusertype(L, b, TOLUA_CAST "building"); tolua_pushusertype(L, b, TOLUA_CAST "building");
return 1; return 1;
} }
@ -606,7 +606,7 @@ static int tolua_get_building(lua_State * L)
static int tolua_get_ship(lua_State * L) static int tolua_get_ship(lua_State * L)
{ {
int no = tolua_toid(L, 1, 0); int no = tolua_toid(L, 1, 0);
ship * sh = findship(no); ship *sh = findship(no);
tolua_pushusertype(L, sh, TOLUA_CAST "ship"); tolua_pushusertype(L, sh, TOLUA_CAST "ship");
return 1; return 1;
} }
@ -614,7 +614,7 @@ static int tolua_get_ship(lua_State * L)
static int tolua_get_alliance(lua_State * L) static int tolua_get_alliance(lua_State * L)
{ {
int no = tolua_toid(L, 1, 0); int no = tolua_toid(L, 1, 0);
alliance * f = findalliance(no); alliance *f = findalliance(no);
tolua_pushusertype(L, f, TOLUA_CAST "alliance"); tolua_pushusertype(L, f, TOLUA_CAST "alliance");
return 1; return 1;
} }
@ -622,7 +622,7 @@ static int tolua_get_alliance(lua_State * L)
static int tolua_get_unit(lua_State * L) static int tolua_get_unit(lua_State * L)
{ {
int no = tolua_toid(L, 1, 0); int no = tolua_toid(L, 1, 0);
unit * u = findunit(no); unit *u = findunit(no);
tolua_pushusertype(L, u, TOLUA_CAST "unit"); tolua_pushusertype(L, u, TOLUA_CAST "unit");
return 1; return 1;
} }
@ -631,14 +631,14 @@ static int tolua_alliance_create(lua_State * L)
{ {
int id = (int)tolua_tonumber(L, 1, 0); int id = (int)tolua_tonumber(L, 1, 0);
const char *name = tolua_tostring(L, 2, 0); const char *name = tolua_tostring(L, 2, 0);
alliance * alli = makealliance(id, name); alliance *alli = makealliance(id, name);
tolua_pushusertype(L, alli, TOLUA_CAST "alliance"); tolua_pushusertype(L, alli, TOLUA_CAST "alliance");
return 1; return 1;
} }
static int tolua_get_regions(lua_State * L) static int tolua_get_regions(lua_State * L)
{ {
region ** region_ptr = (region **) lua_newuserdata(L, sizeof(region *)); region **region_ptr = (region **) lua_newuserdata(L, sizeof(region *));
luaL_getmetatable(L, "region"); luaL_getmetatable(L, "region");
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
*region_ptr = regions; *region_ptr = regions;
@ -648,7 +648,7 @@ static int tolua_get_regions(lua_State * L)
static int tolua_get_factions(lua_State * L) static int tolua_get_factions(lua_State * L)
{ {
faction ** faction_ptr = (faction **) lua_newuserdata(L, sizeof(faction *)); faction **faction_ptr = (faction **) lua_newuserdata(L, sizeof(faction *));
luaL_getmetatable(L, "faction"); luaL_getmetatable(L, "faction");
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
*faction_ptr = factions; *faction_ptr = factions;
@ -658,32 +658,31 @@ static int tolua_get_factions(lua_State * L)
static int tolua_get_alliance_factions(lua_State * L) static int tolua_get_alliance_factions(lua_State * L)
{ {
alliance * self = (alliance *) tolua_tousertype(L, 1, 0); alliance *self = (alliance *) tolua_tousertype(L, 1, 0);
return tolua_quicklist_push(L, "faction_list", "faction", self->members); return tolua_quicklist_push(L, "faction_list", "faction", self->members);
} }
static int tolua_get_alliance_id(lua_State * L) static int tolua_get_alliance_id(lua_State * L)
{ {
alliance * self = (alliance *) tolua_tousertype(L, 1, 0); alliance *self = (alliance *) tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number) self->id); tolua_pushnumber(L, (lua_Number) self->id);
return 1; return 1;
} }
static int tolua_get_alliance_name(lua_State * L) static int tolua_get_alliance_name(lua_State * L)
{ {
alliance * self = (alliance *) tolua_tousertype(L, 1, 0); alliance *self = (alliance *) tolua_tousertype(L, 1, 0);
tolua_pushstring(L, self->name); tolua_pushstring(L, self->name);
return 1; return 1;
} }
static int tolua_set_alliance_name(lua_State * L) static int tolua_set_alliance_name(lua_State * L)
{ {
alliance * self = (alliance *) tolua_tousertype(L, 1, 0); alliance *self = (alliance *) tolua_tousertype(L, 1, 0);
alliance_setname(self, tolua_tostring(L, 2, 0)); alliance_setname(self, tolua_tostring(L, 2, 0));
return 0; return 0;
} }
#include <libxml/tree.h> #include <libxml/tree.h>
#include <util/functions.h> #include <util/functions.h>
#include <util/xml.h> #include <util/xml.h>
@ -694,10 +693,10 @@ static int tolua_write_spells(lua_State * L)
const char *filename = "magic.xml"; const char *filename = "magic.xml";
xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
xmlNodePtr root = xmlNewNode(NULL, BAD_CAST "spells"); xmlNodePtr root = xmlNewNode(NULL, BAD_CAST "spells");
quicklist * ql; quicklist *ql;
int qi; int qi;
for (ql = spells, qi = 0; ql; ql_advance(&ql, &qi, 1)) { for (ql = spells, qi = 0; ql; ql_advance(&ql, &qi, 1)) {
spell * sp = (spell *) ql_get(ql, qi); spell *sp = (spell *) ql_get(ql, qi);
if (sp->sp_function != fun) { if (sp->sp_function != fun) {
int combat = 0; int combat = 0;
xmlNodePtr node = xmlNewNode(NULL, BAD_CAST "spell"); xmlNodePtr node = xmlNewNode(NULL, BAD_CAST "spell");
@ -711,7 +710,7 @@ static int tolua_write_spells(lua_State * L)
if (sp->parameter) if (sp->parameter)
xmlNewProp(node, BAD_CAST "parameters", BAD_CAST sp->parameter); xmlNewProp(node, BAD_CAST "parameters", BAD_CAST sp->parameter);
if (sp->components) { if (sp->components) {
spell_component * comp = sp->components; spell_component *comp = sp->components;
for (; comp->type != 0; ++comp) { for (; comp->type != 0; ++comp) {
static const char *costs[] = { "fixed", "level", "linear" }; static const char *costs[] = { "fixed", "level", "linear" };
xmlNodePtr cnode = xmlNewNode(NULL, BAD_CAST "resource"); xmlNodePtr cnode = xmlNewNode(NULL, BAD_CAST "resource");
@ -758,11 +757,11 @@ static int tolua_write_spells(lua_State * L)
static int config_get_ships(lua_State * L) static int config_get_ships(lua_State * L)
{ {
quicklist * ql; quicklist *ql;
int qi, i = 0; int qi, i = 0;
lua_createtable(L, ql_length(shiptypes), 0); lua_createtable(L, ql_length(shiptypes), 0);
for (qi = 0, ql = shiptypes; ql; ql_advance(&ql, &qi, 1)) { for (qi = 0, ql = shiptypes; ql; ql_advance(&ql, &qi, 1)) {
ship_type * stype = (ship_type *) ql_get(ql, qi); ship_type *stype = (ship_type *) ql_get(ql, qi);
tolua_pushstring(L, TOLUA_CAST stype->name[0]); tolua_pushstring(L, TOLUA_CAST stype->name[0]);
lua_rawseti(L, -2, ++i); lua_rawseti(L, -2, ++i);
} }
@ -827,21 +826,21 @@ static int config_get_resource(lua_State * L)
static int tolua_get_spell_text(lua_State * L) static int tolua_get_spell_text(lua_State * L)
{ {
const struct locale *loc = default_locale; const struct locale *loc = default_locale;
spell * self = (spell *) tolua_tousertype(L, 1, 0); spell *self = (spell *) tolua_tousertype(L, 1, 0);
lua_pushstring(L, spell_info(self, loc)); lua_pushstring(L, spell_info(self, loc));
return 1; return 1;
} }
static int tolua_get_spell_school(lua_State * L) static int tolua_get_spell_school(lua_State * L)
{ {
spell * self = (spell *) tolua_tousertype(L, 1, 0); spell *self = (spell *) tolua_tousertype(L, 1, 0);
lua_pushstring(L, magic_school[self->magietyp]); lua_pushstring(L, magic_school[self->magietyp]);
return 1; return 1;
} }
static int tolua_get_spell_level(lua_State * L) static int tolua_get_spell_level(lua_State * L)
{ {
spell * self = (spell *) tolua_tousertype(L, 1, 0); spell *self = (spell *) tolua_tousertype(L, 1, 0);
lua_pushnumber(L, self->level); lua_pushnumber(L, self->level);
return 1; return 1;
} }
@ -849,7 +848,7 @@ static int tolua_get_spell_level(lua_State * L)
static int tolua_get_spell_name(lua_State * L) static int tolua_get_spell_name(lua_State * L)
{ {
const struct locale *lang = default_locale; const struct locale *lang = default_locale;
spell * self = (spell *) tolua_tousertype(L, 1, 0); spell *self = (spell *) tolua_tousertype(L, 1, 0);
lua_pushstring(L, spell_name(self, lang)); lua_pushstring(L, spell_name(self, lang));
return 1; return 1;
} }
@ -875,7 +874,7 @@ int tolua_process_markets(lua_State * L)
int tolua_process_produce(lua_State * L) int tolua_process_produce(lua_State * L)
{ {
region * r; region *r;
for (r = regions; r; r = r->next) { for (r = regions; r; r = r->next) {
produce(r); produce(r);
} }
@ -895,8 +894,8 @@ static void args_free(void *udata)
static void event_cb(void *sender, const char *event, void *udata) static void event_cb(void *sender, const char *event, void *udata)
{ {
lua_State * L = (lua_State *) global.vm_state; lua_State *L = (lua_State *) global.vm_state;
event_args * args = (event_args *) udata; event_args *args = (event_args *) udata;
int nargs = 2; int nargs = 2;
lua_rawgeti(L, LUA_REGISTRYINDEX, args->hfunction); lua_rawgeti(L, LUA_REGISTRYINDEX, args->hfunction);
if (sender && args->sendertype) { if (sender && args->sendertype) {
@ -922,7 +921,7 @@ static int tolua_eventbus_register(lua_State * L)
{ {
void *sender = tolua_tousertype(L, 1, 0); void *sender = tolua_tousertype(L, 1, 0);
const char *event = tolua_tostring(L, 2, 0); const char *event = tolua_tostring(L, 2, 0);
event_args * args = malloc(sizeof(event_args)); event_args *args = malloc(sizeof(event_args));
args->sendertype = sender ? tolua_typename(L, 1) : NULL; args->sendertype = sender ? tolua_typename(L, 1) : NULL;
lua_pushvalue(L, 3); lua_pushvalue(L, 3);
args->hfunction = luaL_ref(L, LUA_REGISTRYINDEX); args->hfunction = luaL_ref(L, LUA_REGISTRYINDEX);
@ -948,8 +947,8 @@ static int tolua_eventbus_fire(lua_State * L)
static int tolua_report_unit(lua_State * L) static int tolua_report_unit(lua_State * L)
{ {
char buffer[512]; char buffer[512];
unit * u = (unit *) tolua_tousertype(L, 1, 0); unit *u = (unit *) tolua_tousertype(L, 1, 0);
faction * f = (faction *) tolua_tousertype(L, 2, 0); faction *f = (faction *) tolua_tousertype(L, 2, 0);
bufunit(f, u, 0, see_unit, buffer, sizeof(buffer)); bufunit(f, u, 0, see_unit, buffer, sizeof(buffer));
tolua_pushstring(L, buffer); tolua_pushstring(L, buffer);
return 1; return 1;
@ -970,8 +969,7 @@ static int tolua_settings_set(lua_State * L)
return 0; return 0;
} }
static void static void parse_inifile(lua_State * L, dictionary * d, const char *section)
parse_inifile(lua_State * L, dictionary * d, const char *section)
{ {
int i; int i;
size_t len = strlen(section); size_t len = strlen(section);
@ -1029,7 +1027,8 @@ int tolua_eressea_open(lua_State * L)
NULL); NULL);
tolua_function(L, TOLUA_CAST "create", tolua_alliance_create); tolua_function(L, TOLUA_CAST "create", tolua_alliance_create);
} tolua_endmodule(L); } tolua_endmodule(L);
tolua_cclass(L, TOLUA_CAST "spell", TOLUA_CAST "spell", TOLUA_CAST "", NULL); tolua_cclass(L, TOLUA_CAST "spell", TOLUA_CAST "spell", TOLUA_CAST "",
NULL);
tolua_beginmodule(L, TOLUA_CAST "spell"); tolua_beginmodule(L, TOLUA_CAST "spell");
{ {
tolua_function(L, TOLUA_CAST "__tostring", tolua_get_spell_name); tolua_function(L, TOLUA_CAST "__tostring", tolua_get_spell_name);
@ -1090,8 +1089,7 @@ int tolua_eressea_open(lua_State * L)
tolua_function(L, TOLUA_CAST "message_region", tolua_message_region); tolua_function(L, TOLUA_CAST "message_region", tolua_message_region);
/* scripted monsters */ /* scripted monsters */
tolua_function(L, TOLUA_CAST "spawn_braineaters", tolua_function(L, TOLUA_CAST "spawn_braineaters", tolua_spawn_braineaters);
tolua_spawn_braineaters);
tolua_function(L, TOLUA_CAST "update_guards", tolua_update_guards); tolua_function(L, TOLUA_CAST "update_guards", tolua_update_guards);
tolua_function(L, TOLUA_CAST "set_turn", &tolua_set_turn); tolua_function(L, TOLUA_CAST "set_turn", &tolua_set_turn);
@ -1104,8 +1102,10 @@ int tolua_eressea_open(lua_State * L)
tolua_function(L, TOLUA_CAST "itoa36", tolua_itoa36); tolua_function(L, TOLUA_CAST "itoa36", tolua_itoa36);
tolua_function(L, TOLUA_CAST "dice_roll", tolua_dice_rand); tolua_function(L, TOLUA_CAST "dice_roll", tolua_dice_rand);
tolua_function(L, TOLUA_CAST "get_nmrs", tolua_get_nmrs); tolua_function(L, TOLUA_CAST "get_nmrs", tolua_get_nmrs);
tolua_function(L, TOLUA_CAST "remove_empty_units", tolua_remove_empty_units); tolua_function(L, TOLUA_CAST "remove_empty_units",
tolua_function(L, TOLUA_CAST "update_subscriptions", tolua_update_subscriptions); tolua_remove_empty_units);
tolua_function(L, TOLUA_CAST "update_subscriptions",
tolua_update_subscriptions);
tolua_function(L, TOLUA_CAST "update_scores", tolua_update_scores); tolua_function(L, TOLUA_CAST "update_scores", tolua_update_scores);
tolua_function(L, TOLUA_CAST "update_owners", tolua_update_owners); tolua_function(L, TOLUA_CAST "update_owners", tolua_update_owners);
tolua_function(L, TOLUA_CAST "learn_skill", tolua_learn_skill); tolua_function(L, TOLUA_CAST "learn_skill", tolua_learn_skill);

View file

@ -130,8 +130,9 @@ int income(const unit * u)
return 1000 * u->number; return 1000 * u->number;
case RC_WYRM: case RC_WYRM:
return 5000 * u->number; return 5000 * u->number;
} default:
return 20 * u->number; return 20 * u->number;
}
} }
static void scramble(void *data, int n, size_t width) static void scramble(void *data, int n, size_t width)
@ -356,8 +357,7 @@ static int do_recruiting(recruitment * recruits, int available)
number = MIN(req->qty, (int)(get / multi)); number = MIN(req->qty, (int)(get / multi));
if (rc->recruitcost) { if (rc->recruitcost) {
int afford = int afford = get_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT,
get_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT,
number * rc->recruitcost) / rc->recruitcost; number * rc->recruitcost) / rc->recruitcost;
number = MIN(number, afford); number = MIN(number, afford);
use_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT, use_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT,
@ -1340,30 +1340,24 @@ void economics(region * r)
boolean destroyed = false; boolean destroyed = false;
if (u->number > 0) { if (u->number > 0) {
for (ord = u->orders; ord; ord = ord->next) { for (ord = u->orders; ord; ord = ord->next) {
switch (get_keyword(ord)) { keyword_t kwd = get_keyword(ord);
case K_DESTROY: if (kwd == K_DESTROY) {
if (!destroyed) { if (!destroyed) {
if (destroy_cmd(u, ord) != 0) if (destroy_cmd(u, ord) != 0)
ord = NULL; ord = NULL;
destroyed = true; destroyed = true;
} }
break; } else if (kwd == K_GIVE || kwd == K_LIEFERE) {
case K_GIVE:
case K_LIEFERE:
give_cmd(u, ord); give_cmd(u, ord);
break; } else if (kwd == K_FORGET) {
case K_FORGET:
forget_cmd(u, ord); forget_cmd(u, ord);
break;
} }
if (u->orders == NULL) if (u->orders == NULL) {
break; break;
} }
} }
} }
}
/* RECRUIT orders */ /* RECRUIT orders */
if (rules_recruit < 0) if (rules_recruit < 0)
@ -2875,8 +2869,7 @@ static void breed_cmd(unit * u, struct order *ord)
breedtrees(r, u, m); breedtrees(r, u, m);
break; break;
} else if (rtype != oldresourcetype[R_HORSE]) { } else if (rtype != oldresourcetype[R_HORSE]) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_cannotmake", ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_cannotmake", ""));
""));
break; break;
} }
} }
@ -3446,17 +3439,15 @@ void produce(struct region *r)
} }
for (ord = u->orders; ord; ord = ord->next) { for (ord = u->orders; ord; ord = ord->next) {
switch (get_keyword(ord)) { keyword_t kwd = get_keyword(ord);
case K_BUY: if (kwd == K_BUY) {
buy(u, &buyorders, ord); buy(u, &buyorders, ord);
trader = true; trader = true;
break; } else if (kwd == K_SELL) {
case K_SELL:
/* sell returns true if the sale is not limited /* sell returns true if the sale is not limited
* by the region limit */ * by the region limit */
limited &= !sell(u, &sellorders, ord); limited &= !sell(u, &sellorders, ord);
trader = true; trader = true;
break;
} }
} }
if (trader) { if (trader) {

View file

@ -135,8 +135,8 @@ static int RemoveNMRNewbie(void)
static void restart_race(unit * u, const race * rc) static void restart_race(unit * u, const race * rc)
{ {
faction *oldf = u->faction; faction *oldf = u->faction;
faction *f = faction *f = addfaction(oldf->email, oldf->passw, rc, oldf->locale,
addfaction(oldf->email, oldf->passw, rc, oldf->locale, oldf->subscription); oldf->subscription);
unit *nu = addplayer(u->region, f); unit *nu = addplayer(u->region, f);
order **ordp = &u->orders; order **ordp = &u->orders;
f->subscription = u->faction->subscription; f->subscription = u->faction->subscription;
@ -306,7 +306,8 @@ static void get_food(region * r)
} }
} }
for (v = r->units; need && v; v = v->next) { for (v = r->units; need && v; v = v->next) {
if (v->faction != f && alliedunit(v, f, HELP_MONEY) && help_money(v)) { if (v->faction != f && alliedunit(v, f, HELP_MONEY)
&& help_money(v)) {
help_feed(v, u, &need); help_feed(v, u, &need);
} }
} }
@ -419,8 +420,8 @@ static void age_unit(region * r, unit * u)
if ((itm->type->flags & ITF_NOTLOST) == 0) { if ((itm->type->flags & ITF_NOTLOST) == 0) {
if (itm->type->flags & (ITF_BIG | ITF_ANIMAL | ITF_CURSED)) { if (itm->type->flags & (ITF_BIG | ITF_ANIMAL | ITF_CURSED)) {
ADDMSG(&u->faction->msgs, msg_message("itemcrumble", ADDMSG(&u->faction->msgs, msg_message("itemcrumble",
"unit region item amount", u, u->region, itm->type->rtype, "unit region item amount",
itm->number)); u, u->region, itm->type->rtype, itm->number));
i_free(i_remove(itemp, itm)); i_free(i_remove(itemp, itm));
continue; continue;
} }
@ -1056,8 +1057,7 @@ static void transfer_faction(faction * f, faction * f2)
for (u = f->units; u;) { for (u = f->units; u;) {
un = u->nextF; un = u->nextF;
if (!unit_has_cursed_item(u) if (!unit_has_cursed_item(u)
&& !has_skill(u, SK_MAGIC) && !has_skill(u, SK_MAGIC) && !has_skill(u, SK_ALCHEMY)) {
&& !has_skill(u, SK_ALCHEMY)) {
u_setfaction(u, f2); u_setfaction(u, f2);
} }
u = un; u = un;
@ -1669,10 +1669,12 @@ rename_building(unit * u, order * ord, building * b, const char *name)
if (owner) { if (owner) {
if (cansee(owner->faction, u->region, u, 0)) { if (cansee(owner->faction, u->region, u, 0)) {
ADDMSG(&owner->faction->msgs, msg_message("renamed_building_seen", ADDMSG(&owner->faction->msgs,
msg_message("renamed_building_seen",
"building renamer region", b, u, u->region)); "building renamer region", b, u, u->region));
} else { } else {
ADDMSG(&owner->faction->msgs, msg_message("renamed_building_notseen", ADDMSG(&owner->faction->msgs,
msg_message("renamed_building_notseen",
"building region", b, u->region)); "building region", b, u->region));
} }
} }
@ -1738,8 +1740,7 @@ static int name_cmd(unit * u, struct order *ord)
for (; lang; lang = nextlocale(lang)) { for (; lang; lang = nextlocale(lang)) {
const char *fdname = LOC(lang, "factiondefault"); const char *fdname = LOC(lang, "factiondefault");
size_t fdlen = strlen(fdname); size_t fdlen = strlen(fdname);
if (strlen(f->name) >= fdlen if (strlen(f->name) >= fdlen && strncmp(f->name, fdname, fdlen) == 0) {
&& strncmp(f->name, fdname, fdlen) == 0) {
break; break;
} }
} }
@ -1749,8 +1750,8 @@ static int name_cmd(unit * u, struct order *ord)
} }
} }
if (cansee(f, r, u, 0)) { if (cansee(f, r, u, 0)) {
ADDMSG(&f->msgs, msg_message("renamed_faction_seen", "unit region", u, ADDMSG(&f->msgs,
r)); msg_message("renamed_faction_seen", "unit region", u, r));
} else { } else {
ADDMSG(&f->msgs, msg_message("renamed_faction_notseen", "", r)); ADDMSG(&f->msgs, msg_message("renamed_faction_notseen", "", r));
} }
@ -1794,11 +1795,11 @@ static int name_cmd(unit * u, struct order *ord)
uo = shipowner(sh); uo = shipowner(sh);
if (uo) { if (uo) {
if (cansee(uo->faction, r, u, 0)) { if (cansee(uo->faction, r, u, 0)) {
ADDMSG(&uo->faction->msgs, msg_message("renamed_ship_seen", ADDMSG(&uo->faction->msgs,
"ship renamer region", sh, u, r)); msg_message("renamed_ship_seen", "ship renamer region", sh, u, r));
} else { } else {
ADDMSG(&uo->faction->msgs, msg_message("renamed_ship_notseen", ADDMSG(&uo->faction->msgs,
"ship region", sh, r)); msg_message("renamed_ship_notseen", "ship region", sh, r));
} }
} }
s = &sh->name; s = &sh->name;
@ -1898,10 +1899,11 @@ deliverMail(faction * f, region * r, unit * u, const char *s, unit * receiver)
u = NULL; u = NULL;
} }
if (!receiver) { /* BOTSCHAFT an PARTEI */ if (!receiver) { /* BOTSCHAFT an PARTEI */
ADDMSG(&f->msgs, msg_message("regionmessage", "region sender string", r, u, ADDMSG(&f->msgs,
s)); msg_message("regionmessage", "region sender string", r, u, s));
} else { /* BOTSCHAFT an EINHEIT */ } else { /* BOTSCHAFT an EINHEIT */
ADDMSG(&f->msgs, msg_message("unitmessage", "region unit sender string", r, ADDMSG(&f->msgs,
msg_message("unitmessage", "region unit sender string", r,
receiver, u, s)); receiver, u, s));
} }
} }
@ -1917,8 +1919,8 @@ mailunit(region * r, unit * u, int n, struct order *ord, const char *s)
} else { } else {
/* Immer eine Meldung - sonst könnte man so getarnte EHs enttarnen: /* Immer eine Meldung - sonst könnte man so getarnte EHs enttarnen:
* keine Meldung -> EH hier. */ * keine Meldung -> EH hier. */
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found", ADDMSG(&u->faction->msgs,
"")); msg_feedback(u, ord, "feedback_unit_not_found", ""));
} }
} }
@ -2093,7 +2095,8 @@ static int mail_cmd(unit * u, struct order *ord)
cont = 1; cont = 1;
break; break;
} }
} while (cont); }
while (cont);
cmistake(u, ord, 149, MSG_MESSAGE); cmistake(u, ord, 149, MSG_MESSAGE);
return 0; return 0;
} }
@ -2126,8 +2129,8 @@ static int email_cmd(unit * u, struct order *ord)
} else { } else {
faction *f = u->faction; faction *f = u->faction;
if (set_email(&f->email, (const char *)s) != 0) { if (set_email(&f->email, (const char *)s) != 0) {
log_error(("Invalid email address for faction %s: %s\n", itoa36(f->no), log_error(("Invalid email address for faction %s: %s\n",
s)); itoa36(f->no), s));
ADDMSG(&f->msgs, msg_message("changemail_invalid", "value", s)); ADDMSG(&f->msgs, msg_message("changemail_invalid", "value", s));
} else { } else {
ADDMSG(&f->msgs, msg_message("changemail", "value", f->email)); ADDMSG(&f->msgs, msg_message("changemail", "value", f->email));
@ -2372,13 +2375,13 @@ static boolean display_race(faction * f, unit * u, const race * rc)
switch (rc->attack[a].type) { switch (rc->attack[a].type) {
case AT_STANDARD: case AT_STANDARD:
bytes = bytes =
snprintf(bufp, size, "%s (%s)", LOC(f->locale, "attack_standard"), snprintf(bufp, size, "%s (%s)",
rc->def_damage); LOC(f->locale, "attack_standard"), rc->def_damage);
break; break;
case AT_NATURAL: case AT_NATURAL:
bytes = bytes =
snprintf(bufp, size, "%s (%s)", LOC(f->locale, "attack_natural"), snprintf(bufp, size, "%s (%s)",
rc->attack[a].data.dice); LOC(f->locale, "attack_natural"), rc->attack[a].data.dice);
break; break;
case AT_SPELL: case AT_SPELL:
case AT_COMBATSPELL: case AT_COMBATSPELL:
@ -2388,8 +2391,8 @@ static boolean display_race(faction * f, unit * u, const race * rc)
break; break;
case AT_STRUCTURAL: case AT_STRUCTURAL:
bytes = bytes =
snprintf(bufp, size, "%s (%s)", LOC(f->locale, "attack_structural"), snprintf(bufp, size, "%s (%s)",
rc->attack[a].data.dice); LOC(f->locale, "attack_structural"), rc->attack[a].data.dice);
break; break;
default: default:
bytes = 0; bytes = 0;
@ -2482,7 +2485,8 @@ static int promotion_cmd(unit * u, struct order *ord)
} }
if (maxheroes(u->faction) < countheroes(u->faction) + u->number) { if (maxheroes(u->faction) < countheroes(u->faction) + u->number) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "heroes_maxed", "max count", ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "heroes_maxed", "max count",
maxheroes(u->faction), countheroes(u->faction))); maxheroes(u->faction), countheroes(u->faction)));
return 0; return 0;
} }
@ -2495,8 +2499,8 @@ static int promotion_cmd(unit * u, struct order *ord)
money = get_pooled(u, i_silver->rtype, GET_ALL, people); money = get_pooled(u, i_silver->rtype, GET_ALL, people);
if (people > money) { if (people > money) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "heroes_cost", "cost have", ADDMSG(&u->faction->msgs,
people, money)); msg_feedback(u, ord, "heroes_cost", "cost have", people, money));
return 0; return 0;
} }
use_pooled(u, i_silver->rtype, GET_ALL, people); use_pooled(u, i_silver->rtype, GET_ALL, people);
@ -2710,7 +2714,8 @@ static int guard_on_cmd(unit * u, struct order *ord)
} else { } else {
if (fval(u, UFL_MOVED)) { if (fval(u, UFL_MOVED)) {
cmistake(u, ord, 187, MSG_EVENT); cmistake(u, ord, 187, MSG_EVENT);
} else if (fval(u->race, RCF_ILLUSIONARY) || u->race == new_race[RC_SPELL]) { } else if (fval(u->race, RCF_ILLUSIONARY)
|| u->race == new_race[RC_SPELL]) {
cmistake(u, ord, 95, MSG_EVENT); cmistake(u, ord, 95, MSG_EVENT);
} else { } else {
/* Monster der Monsterpartei dürfen immer bewachen */ /* Monster der Monsterpartei dürfen immer bewachen */
@ -2744,14 +2749,14 @@ static void sinkships(region * r)
if (fval(r->terrain, SEA_REGION) && (!enoughsailors(sh, r) if (fval(r->terrain, SEA_REGION) && (!enoughsailors(sh, r)
|| get_captain(sh) == NULL)) { || get_captain(sh) == NULL)) {
/* Schiff nicht seetüchtig */ /* Schiff nicht seetüchtig */
float dmg = float dmg = get_param_flt(global.parameters,
get_param_flt(global.parameters, "rules.ship.damage.nocrewocean", "rules.ship.damage.nocrewocean",
0.30F); 0.30F);
damage_ship(sh, dmg); damage_ship(sh, dmg);
} }
if (shipowner(sh) == NULL) { if (shipowner(sh) == NULL) {
float dmg = float dmg = get_param_flt(global.parameters, "rules.ship.damage.nocrew",
get_param_flt(global.parameters, "rules.ship.damage.nocrew", 0.05F); 0.05F);
damage_ship(sh, dmg); damage_ship(sh, dmg);
} }
} }
@ -2872,6 +2877,8 @@ static void reorder(void)
*up = u->next; *up = u->next;
u->next = v->next; u->next = v->next;
v->next = u; v->next = u;
fset(u, UFL_MARK);
sorted = true;
break; break;
case P_BEFORE: case P_BEFORE:
if (fval(v, UFL_OWNER)) { if (fval(v, UFL_OWNER)) {
@ -2884,10 +2891,13 @@ static void reorder(void)
*up = u->next; *up = u->next;
u->next = v; u->next = v;
} }
break;
}
fset(u, UFL_MARK); fset(u, UFL_MARK);
sorted = true; sorted = true;
break;
default:
/* TODO: syntax error message? */
break;
}
} }
break; break;
} }
@ -2898,10 +2908,11 @@ static void reorder(void)
} }
if (sorted) { if (sorted) {
unit *u; unit *u;
for (u = r->units; u; u = u->next) for (u = r->units; u; u = u->next) {
freset(u, UFL_MARK); freset(u, UFL_MARK);
} }
} }
}
} }
#if 0 #if 0
@ -3118,8 +3129,8 @@ static building *age_building(building * b)
} }
if (unicorns) { if (unicorns) {
ADDMSG(&u->faction->msgs, msg_message("scunicorn", ADDMSG(&u->faction->msgs, msg_message("scunicorn",
"unit amount rtype", u, unicorns, "unit amount rtype",
olditemtype[I_ELVENHORSE]->rtype)); u, unicorns, olditemtype[I_ELVENHORSE]->rtype));
} }
} }
} }
@ -3141,8 +3152,8 @@ static building *age_building(building * b)
/* the mage reactivates the circle */ /* the mage reactivates the circle */
c = create_curse(mage, &rt->attribs, ct_astralblock, c = create_curse(mage, &rt->attribs, ct_astralblock,
(float)MAX(1, sk), MAX(1, sk / 2), effect, 0); (float)MAX(1, sk), MAX(1, sk / 2), effect, 0);
ADDMSG(&r->msgs, msg_message("astralshield_activate", ADDMSG(&r->msgs,
"region unit", r, mage)); msg_message("astralshield_activate", "region unit", r, mage));
} }
} else if (mage != NULL) { } else if (mage != NULL) {
int sk = effskill(mage, SK_MAGIC); int sk = effskill(mage, SK_MAGIC);
@ -3364,13 +3375,15 @@ static void new_units(void)
if (err) { if (err) {
if (err == 1) { if (err == 1) {
ADDMSG(&u->faction->msgs, msg_feedback(u, makeord, ADDMSG(&u->faction->msgs,
"too_many_units_in_alliance", "allowed", msg_feedback(u, makeord,
maxunits(u->faction))); "too_many_units_in_alliance",
"allowed", maxunits(u->faction)));
} else { } else {
ADDMSG(&u->faction->msgs, msg_feedback(u, makeord, ADDMSG(&u->faction->msgs,
"too_many_units_in_faction", "allowed", msg_feedback(u, makeord,
maxunits(u->faction))); "too_many_units_in_faction",
"allowed", maxunits(u->faction)));
} }
ordp = &makeord->next; ordp = &makeord->next;
@ -3527,13 +3540,15 @@ static void setdefaults(unit * u)
/* Wird je diese Ausschliesslichkeit aufgehoben, muss man aufpassen /* Wird je diese Ausschliesslichkeit aufgehoben, muss man aufpassen
* mit der Reihenfolge von Kaufen, Verkaufen etc., damit es Spielern * mit der Reihenfolge von Kaufen, Verkaufen etc., damit es Spielern
* nicht moeglich ist, Schulden zu machen. */ * nicht moeglich ist, Schulden zu machen. */
default:
break;
} }
} }
} }
if (hunger) if (hunger) {
return; return;
}
/* Wenn die Einheit handelt, muß der Default-Befehl gelöscht /* Wenn die Einheit handelt, muß der Default-Befehl gelöscht
* werden. */ * werden. */
@ -3590,6 +3605,8 @@ static double heal_factor(const unit * u)
return elf_regen; return elf_regen;
} }
return 1.0; return 1.0;
default:
return 1.0;
} }
return 1.0; return 1.0;
} }
@ -3630,8 +3647,8 @@ static void monthly_healing(void)
if (fval(u, UFL_HUNGER)) if (fval(u, UFL_HUNGER))
continue; continue;
if (fval(r->terrain, SEA_REGION) && u->ship == NULL && !(canswim(u) if (fval(r->terrain, SEA_REGION) && u->ship == NULL
|| canfly(u))) { && !(canswim(u) || canfly(u))) {
continue; continue;
} }

View file

@ -104,9 +104,7 @@ boolean is_migrant(unit * u)
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
boolean magic_lowskill(unit * u) boolean magic_lowskill(unit * u)
{ {
if (u->race == new_race[RC_TOAD]) return (u->race == new_race[RC_TOAD]) ? true : false;
return true;
return false;
} }
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
@ -121,23 +119,22 @@ int study_cost(unit * u, skill_t sk)
sprintf(buffer, "skills.cost.%s", skillnames[sk]); sprintf(buffer, "skills.cost.%s", skillnames[sk]);
cost[sk] = get_param_int(global.parameters, buffer, -1); cost[sk] = get_param_int(global.parameters, buffer, -1);
} }
if (cost[sk] >= 0) if (cost[sk] >= 0) {
return cost[sk]; return cost[sk];
}
switch (sk) { switch (sk) {
case SK_SPY: case SK_SPY:
return 100; return 100;
break;
case SK_TACTICS: case SK_TACTICS:
case SK_HERBALISM: case SK_HERBALISM:
case SK_ALCHEMY: case SK_ALCHEMY:
return 200; return 200;
break;
case SK_MAGIC: /* Die Magiekosten betragen 50+Summe(50*Stufe) */ case SK_MAGIC: /* Die Magiekosten betragen 50+Summe(50*Stufe) */
/* 'Stufe' ist dabei die nächste zu erreichende Stufe */ /* 'Stufe' ist dabei die nächste zu erreichende Stufe */
stufe = 1 + get_level(u, SK_MAGIC); stufe = 1 + get_level(u, SK_MAGIC);
return k * (1 + ((stufe + 1) * stufe / 2)); return k * (1 + ((stufe + 1) * stufe / 2));
break; default:
return 0;
} }
return 0; return 0;
} }

View file

@ -1324,10 +1324,9 @@ void do_misc(region * r, boolean lasttry)
for (uc = r->units; uc; uc = uc->next) { for (uc = r->units; uc; uc = uc->next) {
order *ord; order *ord;
for (ord = uc->orders; ord; ord = ord->next) { for (ord = uc->orders; ord; ord = ord->next) {
switch (get_keyword(ord)) { keyword_t kwd = get_keyword(ord);
case K_CONTACT: if (kwd == K_CONTACT) {
contact_cmd(uc, ord, lasttry); contact_cmd(uc, ord, lasttry);
break;
} }
} }
} }

View file

@ -587,15 +587,11 @@ int skill_limit(faction * f, skill_t sk)
return fl; return fl;
} }
} }
switch (sk) { if (sk == SK_MAGIC) {
case SK_MAGIC:
m = max_magicians(f); m = max_magicians(f);
break; } else if (sk == SK_ALCHEMY) {
case SK_ALCHEMY: m = get_param_int(global.parameters, "rules.maxskills.alchemy",
m =
get_param_int(global.parameters, "rules.maxskills.alchemy",
MAXALCHEMISTS); MAXALCHEMISTS);
break;
} }
return m; return m;
} }
@ -607,10 +603,11 @@ int count_skill(faction * f, skill_t sk)
for (u = f->units; u; u = u->nextF) { for (u = f->units; u; u = u->nextF) {
if (has_skill(u, sk)) { if (has_skill(u, sk)) {
if (!is_familiar(u)) if (!is_familiar(u)) {
n += u->number; n += u->number;
} }
} }
}
return n; return n;
} }
@ -1585,13 +1582,14 @@ static int read_newunitid(const faction * f, const region * r)
int read_unitid(const faction * f, const region * r) int read_unitid(const faction * f, const region * r)
{ {
const char *s = getstrtoken(); const char *s = getstrtoken();
param_t param;
/* Da s nun nur einen string enthaelt, suchen wir ihn direkt in der /* Da s nun nur einen string enthaelt, suchen wir ihn direkt in der
* paramliste. machen wir das nicht, dann wird getnewunit in s nach der * paramliste. machen wir das nicht, dann wird getnewunit in s nach der
* nummer suchen, doch dort steht bei temp-units nur "temp" drinnen! */ * nummer suchen, doch dort steht bei temp-units nur "temp" drinnen! */
switch (findparam(s, f->locale)) { param = findparam(s, f->locale);
case P_TEMP: if (param == P_TEMP) {
return read_newunitid(f, r); return read_newunitid(f, r);
} }
if (!s || *s == 0) if (!s || *s == 0)
@ -2502,6 +2500,9 @@ unsigned int guard_flags(const unit * u)
case RC_IRONKEEPER: case RC_IRONKEEPER:
flags = GUARD_MINING; flags = GUARD_MINING;
break; break;
default:
/* TODO: This should be configuration variables, all of it */
break;
} }
return flags; return flags;
} }

View file

@ -1694,8 +1694,7 @@ verify_targets(castorder * co, int *invalid, int *resist, int *success)
spobj->flag = TARGET_RESISTS; spobj->flag = TARGET_RESISTS;
++*resist; ++*resist;
ADDMSG(&mage->faction->msgs, msg_message("spellunitresists", ADDMSG(&mage->faction->msgs, msg_message("spellunitresists",
"unit region command target", "unit region command target", mage, mage->region, co->order, u));
mage, mage->region, co->order, u));
break; break;
} }
@ -2485,6 +2484,8 @@ static boolean is_moving_ship(const region * r, const ship * sh)
case K_MOVE: case K_MOVE:
case K_FOLLOW: case K_FOLLOW:
return true; return true;
default:
return false;
} }
return false; return false;
} }

View file

@ -1334,6 +1334,8 @@ static int movement_speed(unit * u)
case RC_BIRTHDAYDRAGON: case RC_BIRTHDAYDRAGON:
case RC_SONGDRAGON: case RC_SONGDRAGON:
return BP_DRAGON; return BP_DRAGON;
default:
break;
} }
if (!init) { if (!init) {
@ -2565,9 +2567,7 @@ void movement(void)
} }
kword = get_keyword(u->thisorder); kword = get_keyword(u->thisorder);
switch (kword) { if (kword == K_ROUTE || kword == K_MOVE) {
case K_ROUTE:
case K_MOVE:
/* after moving, the unit has no thisorder. this prevents /* after moving, the unit has no thisorder. this prevents
* it from moving twice (or getting error messages twice). * it from moving twice (or getting error messages twice).
* UFL_NOTMOVING is set in combat if the unit is not allowed * UFL_NOTMOVING is set in combat if the unit is not allowed
@ -2602,7 +2602,6 @@ void movement(void)
} }
} }
} }
break;
} }
if (u->region == r) { if (u->region == r) {
/* not moved, use next unit */ /* not moved, use next unit */

View file

@ -396,8 +396,6 @@ boolean is_repeated(const order * ord)
case K_TEACH: case K_TEACH:
case K_BREED: case K_BREED:
case K_PIRACY: case K_PIRACY:
return true;
case K_PLANT: case K_PLANT:
return true; return true;
@ -428,6 +426,8 @@ boolean is_repeated(const order * ord)
if (param != P_TEMP) if (param != P_TEMP)
return true; return true;
break; break;
default:
return false;
} }
return false; return false;
} }
@ -464,8 +464,6 @@ boolean is_exclusive(const order * ord)
case K_TEACH: case K_TEACH:
case K_BREED: case K_BREED:
case K_PIRACY: case K_PIRACY:
return true;
case K_PLANT: case K_PLANT:
return true; return true;
@ -496,6 +494,8 @@ boolean is_exclusive(const order * ord)
if (param != P_TEMP) if (param != P_TEMP)
return true; return true;
break; break;
default:
return false;
} }
return false; return false;
} }
@ -534,8 +534,6 @@ boolean is_long(const order * ord)
case K_TEACH: case K_TEACH:
case K_BREED: case K_BREED:
case K_PIRACY: case K_PIRACY:
return true;
case K_PLANT: case K_PLANT:
return true; return true;
@ -566,6 +564,8 @@ boolean is_long(const order * ord)
if (param != P_TEMP) if (param != P_TEMP)
return true; return true;
break; break;
default:
return false;
} }
return false; return false;
} }
@ -593,9 +593,11 @@ boolean is_persistent(const order * ord)
case K_KOMMENTAR: case K_KOMMENTAR:
case K_LIEFERE: case K_LIEFERE:
return true; return true;
default:
return persist || is_repeated(ord);
} }
return persist || is_repeated(ord);
} }
char *write_order(const order * ord, char *buffer, size_t size) char *write_order(const order * ord, char *buffer, size_t size)

View file

@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifndef H_KRNL_REPORTS #ifndef H_KRNL_REPORTS
#define H_KRNL_REPORTS #define H_KRNL_REPORTS
#include <time.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

View file

@ -175,13 +175,11 @@ int freadstr(FILE * F, int encoding, char *start, size_t size)
char inbuf = (char)c; char inbuf = (char)c;
size_t inbytes = 1; size_t inbytes = 1;
size_t outbytes = size - (str - start); size_t outbytes = size - (str - start);
int ret = int ret = unicode_latin1_to_utf8(str, &outbytes, &inbuf, &inbytes);
unicode_latin1_to_utf8(str, &outbytes, &inbuf, &inbytes);
if (ret > 0) if (ret > 0)
str += ret; str += ret;
else { else {
log_error( log_error(("input data was not iso-8859-1! assuming utf-8\n"));
("input data was not iso-8859-1! assuming utf-8\n"));
encoding = XML_CHAR_ENCODING_ERROR; encoding = XML_CHAR_ENCODING_ERROR;
*str++ = (char)c; *str++ = (char)c;
} }
@ -314,9 +312,14 @@ static unit *unitorders(FILE * F, int enc, struct faction *f)
} else { } else {
quit = false; quit = false;
} }
}
if (quit)
break; break;
default:
/* TODO: syntax error message */
break;
}
if (quit) {
break;
}
} }
/* Nun wird der Befehl erzeut und eingehängt */ /* Nun wird der Befehl erzeut und eingehängt */
*ordp = parse_order(s, u->faction->locale); *ordp = parse_order(s, u->faction->locale);

View file

@ -223,13 +223,15 @@ int rc_skillmod(const struct race *rc, const region * r, skill_t sk)
{ {
int mods; int mods;
if (!skill_enabled[sk]) if (!skill_enabled[sk]) {
return 0; return 0;
}
#ifdef FASTER_SKILLMOD #ifdef FASTER_SKILLMOD
unsigned int index = hashstring(rc->_name[0]) % RCMODMAXHASH; unsigned int index = hashstring(rc->_name[0]) % RCMODMAXHASH;
struct skillmods **imods = &modhash[index]; struct skillmods **imods = &modhash[index];
while (*imods && (*imods)->race != rc) while (*imods && (*imods)->race != rc) {
imods = &(*imods)->next; imods = &(*imods)->next;
}
if (*imods == NULL) { if (*imods == NULL) {
*imods = init_skills(rc); *imods = init_skills(rc);
} }
@ -237,21 +239,19 @@ int rc_skillmod(const struct race *rc, const region * r, skill_t sk)
#else #else
mods = skill_mod(rc, sk, r->terrain); mods = skill_mod(rc, sk, r->terrain);
#endif #endif
if (rc == new_race[RC_ELF] && r_isforest(r)) if (rc == new_race[RC_ELF] && r_isforest(r)) {
switch (sk) { if (sk == SK_PERCEPTION) {
case SK_PERCEPTION:
++mods; ++mods;
break; } else if (sk == SK_STEALTH) {
case SK_STEALTH: if (r_isforest(r)) {
if (r_isforest(r))
++mods; ++mods;
break;
case SK_TACTICS:
if (r_isforest(r))
mods += 2;
break;
} }
} else if (sk == SK_TACTICS) {
if (r_isforest(r)) {
mods += 2;
}
}
}
return mods; return mods;
} }

View file

@ -170,7 +170,7 @@ enum {
XMLSPL_WDWPYRAMID_ASTRAL = 185, XMLSPL_WDWPYRAMID_ASTRAL = 185,
XMLSPL_WDWPYRAMID_DRUIDE = 186, XMLSPL_WDWPYRAMID_DRUIDE = 186,
XMLSPL_WDWPYRAMID_BARDE = 187, XMLSPL_WDWPYRAMID_BARDE = 187,
XMLSPL_WDWPYRAMID_CHAOS = 188, XMLSPL_WDWPYRAMID_CHAOS = 188
}; };
#endif #endif

View file

@ -60,7 +60,7 @@ static int txt_w_flt(struct storage *store, float arg)
static float txt_r_flt(struct storage *store) static float txt_r_flt(struct storage *store)
{ {
double result; double result;
fscanf((FILE *) store->userdata, "%f", &result); fscanf((FILE *) store->userdata, "%lf", &result);
return (float)result; return (float)result;
} }
@ -154,7 +154,7 @@ static int txt_open(struct storage *store, const char *filename, int mode)
store->version = atoi(token); store->version = atoi(token);
} }
} else if (store->encoding == XML_CHAR_ENCODING_UTF8) { } else if (store->encoding == XML_CHAR_ENCODING_UTF8) {
fputs((const char*)utf8_bom, F); fputs((const char *)utf8_bom, F);
fprintf(F, "%d\n", RELEASE_VERSION); fprintf(F, "%d\n", RELEASE_VERSION);
} }
} }

View file

@ -89,18 +89,17 @@ int xecmd(unit * u, order * ord)
if (a_find(f->attribs, &at_xontormiaexpress)) { if (a_find(f->attribs, &at_xontormiaexpress)) {
if (get_keyword(ord) == K_XE) { if (get_keyword(ord) == K_XE) {
param_t param;
init_tokens(ord); init_tokens(ord);
skip_token(); skip_token();
switch (findparam(getstrtoken(), f->locale)) { param = findparam(getstrtoken(), f->locale);
case P_XEPOTION: if (param == P_XEPOTION) {
xe_givepotion(u, ord); xe_givepotion(u, ord);
break; } else if (param == P_XEBALLOON) {
case P_XEBALLOON:
xe_giveballon(u, ord); xe_giveballon(u, ord);
break; } else if (param == P_XELAEN) {
case P_XELAEN:
xe_givelaen(u, ord); xe_givelaen(u, ord);
break;
} }
} }
} }