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,14 +110,14 @@ 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);
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
lua_pushnumber(L, 0); lua_pushnumber(L, 0);
lua_pushstring(L, elem_type); lua_pushstring(L, elem_type);
lua_pushcclosure(L, tolua_quicklist_iter, 3); /* OBS: this closure has multiple upvalues (list, index, type_name) */ lua_pushcclosure(L, tolua_quicklist_iter, 3); /* OBS: this closure has multiple upvalues (list, index, type_name) */
} else { } else {
lua_pushnil(L); lua_pushnil(L);
} }
@ -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;
} }
@ -336,8 +336,8 @@ static int tolua_create_curse(lua_State * L)
double vigour = tolua_tonumber(L, 4, 0); double vigour = tolua_tonumber(L, 4, 0);
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,10 +473,10 @@ 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);
} }
if (owner) { if (owner) {
fset(r, RF_GUARDED); fset(r, RF_GUARDED);
@ -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);
} }
@ -884,8 +883,8 @@ int tolua_process_produce(lua_State * L)
typedef struct event_args { typedef struct event_args {
int hfunction; int hfunction;
int hargs; int hargs;
const char *sendertype; const char *sendertype;
} event_args; } event_args;
static void args_free(void *udata) static void args_free(void *udata)
@ -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);
@ -991,8 +989,8 @@ parse_inifile(lua_State * L, dictionary * d, const char *section)
} }
} }
/* special case */ /* special case */
lua_pushstring(L, "basepath"); lua_pushstring(L, "basepath");
lua_pushstring(L, basepath()); lua_pushstring(L, basepath());
lua_rawset(L, -3); lua_rawset(L, -3);
} }
@ -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

@ -124,14 +124,15 @@ static void recruit_init(void)
int income(const unit * u) int income(const unit * u)
{ {
switch (old_race(u->race)) { switch (old_race(u->race)) {
case RC_FIREDRAGON: case RC_FIREDRAGON:
return 150 * u->number; return 150 * u->number;
case RC_DRAGON: case RC_DRAGON:
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,
@ -1297,22 +1297,22 @@ static int recruit_archetype(unit * u, order * ord)
return n; return n;
} else } else
switch (n) { switch (n) {
case ENOMATERIALS: case ENOMATERIALS:
ADDMSG(&u->faction->msgs, msg_materials_required(u, ord, arch->ctype, ADDMSG(&u->faction->msgs, msg_materials_required(u, ord, arch->ctype,
want)); want));
break; break;
case ELOWSKILL: case ELOWSKILL:
case ENEEDSKILL: case ENEEDSKILL:
/* no skill, or not enough skill points to build */ /* no skill, or not enough skill points to build */
cmistake(u, ord, 50, MSG_PRODUCE); cmistake(u, ord, 50, MSG_PRODUCE);
break; break;
case EBUILDINGREQ: case EBUILDINGREQ:
ADDMSG(&u->faction->msgs, ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "building_needed", "building", msg_feedback(u, u->thisorder, "building_needed", "building",
arch->ctype->btype->_name)); arch->ctype->btype->_name));
break; break;
default: default:
assert(!"unhandled return value from build() in recruit_archetype"); assert(!"unhandled return value from build() in recruit_archetype");
} }
return 0; return 0;
} }
@ -1340,27 +1340,21 @@ 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) {
give_cmd(u, ord);
case K_GIVE: } else if (kwd == K_FORGET) {
case K_LIEFERE: forget_cmd(u, ord);
give_cmd(u, ord);
break;
case K_FORGET:
forget_cmd(u, ord);
break;
} }
if (u->orders == NULL) if (u->orders == NULL) {
break; break;
}
} }
} }
} }
@ -1418,24 +1412,24 @@ static void manufacture(unit * u, const item_type * itype, int want)
} }
n = build(u, itype->construction, 0, want); n = build(u, itype->construction, 0, want);
switch (n) { switch (n) {
case ENEEDSKILL: case ENEEDSKILL:
ADDMSG(&u->faction->msgs, ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "skill_needed", "skill", sk)); msg_feedback(u, u->thisorder, "skill_needed", "skill", sk));
return; return;
case EBUILDINGREQ: case EBUILDINGREQ:
ADDMSG(&u->faction->msgs, ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "building_needed", "building", msg_feedback(u, u->thisorder, "building_needed", "building",
itype->construction->btype->_name)); itype->construction->btype->_name));
return; return;
case ELOWSKILL: case ELOWSKILL:
ADDMSG(&u->faction->msgs, ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "manufacture_skills", msg_feedback(u, u->thisorder, "manufacture_skills",
"skill minskill product", sk, minskill, itype->rtype, 1)); "skill minskill product", sk, minskill, itype->rtype, 1));
return; return;
case ENOMATERIALS: case ENOMATERIALS:
ADDMSG(&u->faction->msgs, msg_materials_required(u, u->thisorder, ADDMSG(&u->faction->msgs, msg_materials_required(u, u->thisorder,
itype->construction, want)); itype->construction, want));
return; return;
} }
if (n > 0) { if (n > 0) {
i_change(&u->items, itype, n); i_change(&u->items, itype, n);
@ -1829,33 +1823,33 @@ static void create_potion(unit * u, const potion_type * ptype, int want)
} }
built = build(u, ptype->itype->construction, 0, want); built = build(u, ptype->itype->construction, 0, want);
switch (built) { switch (built) {
case ELOWSKILL: case ELOWSKILL:
case ENEEDSKILL: case ENEEDSKILL:
/* no skill, or not enough skill points to build */ /* no skill, or not enough skill points to build */
cmistake(u, u->thisorder, 50, MSG_PRODUCE); cmistake(u, u->thisorder, 50, MSG_PRODUCE);
break; break;
case EBUILDINGREQ: case EBUILDINGREQ:
ADDMSG(&u->faction->msgs, ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "building_needed", "building", msg_feedback(u, u->thisorder, "building_needed", "building",
ptype->itype->construction->btype->_name)); ptype->itype->construction->btype->_name));
break; break;
case ECOMPLETE: case ECOMPLETE:
assert(0); assert(0);
break; break;
case ENOMATERIALS: case ENOMATERIALS:
/* something missing from the list of materials */ /* something missing from the list of materials */
ADDMSG(&u->faction->msgs, msg_materials_required(u, u->thisorder, ADDMSG(&u->faction->msgs, msg_materials_required(u, u->thisorder,
ptype->itype->construction, want)); ptype->itype->construction, want));
return; return;
break; break;
default: default:
i_change(&u->items, ptype->itype, built); i_change(&u->items, ptype->itype, built);
if (want == INT_MAX) if (want == INT_MAX)
want = built; want = built;
ADDMSG(&u->faction->msgs, msg_message("manufacture", ADDMSG(&u->faction->msgs, msg_message("manufacture",
"unit region amount wanted resource", u, u->region, built, want, "unit region amount wanted resource", u, u->region, built, want,
ptype->itype->rtype)); ptype->itype->rtype));
break; break;
} }
} }
@ -2862,26 +2856,25 @@ static void breed_cmd(unit * u, struct order *ord)
} }
switch (p) { switch (p) {
case P_HERBS: case P_HERBS:
plant(r, u, m); plant(r, u, m);
break; break;
case P_TREES: case P_TREES:
breedtrees(r, u, m); breedtrees(r, u, m);
break; break;
default: default:
if (p != P_ANY) { if (p != P_ANY) {
rtype = findresourcetype(s, u->faction->locale); rtype = findresourcetype(s, u->faction->locale);
if (rtype == rt_mallornseed || rtype == rt_seed) { if (rtype == rt_mallornseed || rtype == rt_seed) {
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;
}
} }
breedhorses(r, u); }
break; breedhorses(r, u);
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) {
@ -3479,41 +3470,41 @@ void produce(struct region *r)
switch (todo) { switch (todo) {
case K_ENTERTAIN: case K_ENTERTAIN:
entertain_cmd(u, u->thisorder); entertain_cmd(u, u->thisorder);
break; break;
case K_WORK: case K_WORK:
if (!rule_autowork && do_work(u, u->thisorder, nextworker) == 0) { if (!rule_autowork && do_work(u, u->thisorder, nextworker) == 0) {
assert(nextworker - workers < MAX_WORKERS); assert(nextworker - workers < MAX_WORKERS);
++nextworker; ++nextworker;
} }
break; break;
case K_TAX: case K_TAX:
tax_cmd(u, u->thisorder, &taxorders); tax_cmd(u, u->thisorder, &taxorders);
break; break;
case K_STEAL: case K_STEAL:
steal_cmd(u, u->thisorder, &stealorders); steal_cmd(u, u->thisorder, &stealorders);
break; break;
case K_SPY: case K_SPY:
spy_cmd(u, u->thisorder); spy_cmd(u, u->thisorder);
break; break;
case K_SABOTAGE: case K_SABOTAGE:
sabotage_cmd(u, u->thisorder); sabotage_cmd(u, u->thisorder);
break; break;
case K_PLANT: case K_PLANT:
case K_BREED: case K_BREED:
breed_cmd(u, u->thisorder); breed_cmd(u, u->thisorder);
break; break;
case K_RESEARCH: case K_RESEARCH:
research_cmd(u, u->thisorder); research_cmd(u, u->thisorder);
break; break;
} }
} }

File diff suppressed because it is too large Load diff

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; case SK_MAGIC: /* Die Magiekosten betragen 50+Summe(50*Stufe) */
break; /* 'Stufe' ist dabei die nächste zu erreichende Stufe */
case SK_MAGIC: /* Die Magiekosten betragen 50+Summe(50*Stufe) */ stufe = 1 + get_level(u, SK_MAGIC);
/* 'Stufe' ist dabei die nächste zu erreichende Stufe */ return k * (1 + ((stufe + 1) * stufe / 2));
stufe = 1 + get_level(u, SK_MAGIC); default:
return k * (1 + ((stufe + 1) * stufe / 2)); return 0;
break;
} }
return 0; return 0;
} }

View file

@ -951,19 +951,19 @@ build_building(unit * u, const building_type * btype, int want, order * ord)
built = build(u, btype->construction, built, n); built = build(u, btype->construction, built, n);
switch (built) { switch (built) {
case ECOMPLETE: case ECOMPLETE:
/* the building is already complete */ /* the building is already complete */
cmistake(u, ord, 4, MSG_PRODUCE); cmistake(u, ord, 4, MSG_PRODUCE);
return; return;
case ENOMATERIALS: case ENOMATERIALS:
ADDMSG(&u->faction->msgs, msg_materials_required(u, ord, ADDMSG(&u->faction->msgs, msg_materials_required(u, ord,
btype->construction, want)); btype->construction, want));
return; return;
case ELOWSKILL: case ELOWSKILL:
case ENEEDSKILL: case ENEEDSKILL:
/* no skill, or not enough skill points to build */ /* no skill, or not enough skill points to build */
cmistake(u, ord, 50, MSG_PRODUCE); cmistake(u, ord, 50, MSG_PRODUCE);
return; return;
} }
/* at this point, the building size is increased. */ /* at this point, the building size is increased. */
@ -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;
} }
} }
} }
@ -1349,37 +1348,37 @@ void do_misc(region * r, boolean lasttry)
id = getid(); id = getid();
switch (p) { switch (p) {
case P_BUILDING: case P_BUILDING:
case P_GEBAEUDE: case P_GEBAEUDE:
if (u->building && u->building->no == id) if (u->building && u->building->no == id)
break; break;
if (enter_building(u, ord, id, lasttry)) { if (enter_building(u, ord, id, lasttry)) {
unit *ub; unit *ub;
for (ub = u; ub; ub = ub->next) { for (ub = u; ub; ub = ub->next) {
if (ub->building == u->building) { if (ub->building == u->building) {
ulast = ub; ulast = ub;
}
} }
} }
break; }
break;
case P_SHIP: case P_SHIP:
if (u->ship && u->ship->no == id) if (u->ship && u->ship->no == id)
break; break;
if (enter_ship(u, ord, id, lasttry)) { if (enter_ship(u, ord, id, lasttry)) {
unit *ub; unit *ub;
ulast = u; ulast = u;
for (ub = u; ub; ub = ub->next) { for (ub = u; ub; ub = ub->next) {
if (ub->ship == u->ship) { if (ub->ship == u->ship) {
ulast = ub; ulast = ub;
}
} }
} }
break; }
break;
default: default:
if (lasttry) if (lasttry)
cmistake(u, ord, 79, MSG_MOVE); cmistake(u, ord, 79, MSG_MOVE);
} }
if (ulast != NULL) { if (ulast != NULL) {

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); } else if (sk == SK_ALCHEMY) {
break; m = get_param_int(global.parameters, "rules.maxskills.alchemy",
case SK_ALCHEMY: MAXALCHEMISTS);
m =
get_param_int(global.parameters, "rules.maxskills.alchemy",
MAXALCHEMISTS);
break;
} }
return m; return m;
} }
@ -607,8 +603,9 @@ 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,14 +1582,15 @@ 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)
return -1; return -1;
@ -2492,16 +2490,19 @@ unsigned int guard_flags(const unit * u)
flags |= GUARD_RECRUIT; flags |= GUARD_RECRUIT;
#endif #endif
switch (old_race(u->race)) { switch (old_race(u->race)) {
case RC_ELF: case RC_ELF:
if (u->faction->race != u->race) if (u->faction->race != u->race)
break;
/* else fallthrough */
case RC_TREEMAN:
flags |= GUARD_TREES;
break;
case RC_IRONKEEPER:
flags = GUARD_MINING;
break; break;
/* else fallthrough */
case RC_TREEMAN:
flags |= GUARD_TREES;
break;
case RC_IRONKEEPER:
flags = GUARD_MINING;
break;
default:
/* TODO: This should be configuration variables, all of it */
break;
} }
return flags; return flags;
} }
@ -2932,11 +2933,11 @@ message *movement_error(unit * u, const char *token, order * ord,
{ {
direction_t d; direction_t d;
switch (error_code) { switch (error_code) {
case E_MOVE_BLOCKED: case E_MOVE_BLOCKED:
d = finddirection(token, u->faction->locale); d = finddirection(token, u->faction->locale);
return msg_message("moveblocked", "unit direction", u, d); return msg_message("moveblocked", "unit direction", u, d);
case E_MOVE_NOREGION: case E_MOVE_NOREGION:
return msg_feedback(u, ord, "unknowndirection", "dirname", token); return msg_feedback(u, ord, "unknowndirection", "dirname", token);
} }
return NULL; return NULL;
} }
@ -2953,24 +2954,24 @@ int movewhere(const unit * u, const char *token, region * r, region ** resultp)
d = finddirection(token, u->faction->locale); d = finddirection(token, u->faction->locale);
switch (d) { switch (d) {
case D_PAUSE: case D_PAUSE:
*resultp = r; *resultp = r;
break; break;
case NODIRECTION: case NODIRECTION:
r2 = find_special_direction(r, token, u->faction->locale); r2 = find_special_direction(r, token, u->faction->locale);
if (r2 == NULL) { if (r2 == NULL) {
return E_MOVE_NOREGION; return E_MOVE_NOREGION;
} }
*resultp = r2; *resultp = r2;
break; break;
default: default:
r2 = rconnect(r, d); r2 = rconnect(r, d);
if (r2 == NULL || move_blocked(u, r, r2)) { if (r2 == NULL || move_blocked(u, r, r2)) {
return E_MOVE_BLOCKED; return E_MOVE_BLOCKED;
} }
*resultp = r2; *resultp = r2;
} }
return E_MOVE_OK; return E_MOVE_OK;
} }

View file

@ -985,13 +985,13 @@ cancast(unit * u, const spell * sp, int level, int range, struct order * ord)
/* sind die Kosten stufenabhängig, so muss itemanz noch mit dem /* sind die Kosten stufenabhängig, so muss itemanz noch mit dem
* level multipliziert werden */ * level multipliziert werden */
switch (sp->components[k].cost) { switch (sp->components[k].cost) {
case SPC_LEVEL: case SPC_LEVEL:
case SPC_LINEAR: case SPC_LINEAR:
itemanz *= level; itemanz *= level;
break; break;
case SPC_FIX: case SPC_FIX:
default: default:
break; break;
} }
itemhave = get_pooled(u, rtype, GET_DEFAULT, itemanz); itemhave = get_pooled(u, rtype, GET_DEFAULT, itemanz);
@ -1206,48 +1206,48 @@ target_resists_magic(unit * magician, void *obj, int objtyp, int t_bonus)
return true; return true;
switch (objtyp) { switch (objtyp) {
case TYP_UNIT: case TYP_UNIT:
{ {
int at, pa = 0; int at, pa = 0;
skill *sv; skill *sv;
unit *u = (unit *) obj; unit *u = (unit *) obj;
at = effskill(magician, SK_MAGIC); at = effskill(magician, SK_MAGIC);
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) { for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
int sk = effskill(u, sv->id); int sk = effskill(u, sv->id);
if (pa < sk) if (pa < sk)
pa = sk; pa = sk;
}
/* Contest */
probability = 0.05 * (10 + pa - at);
probability += magic_resistance((unit *) obj);
break;
} }
case TYP_REGION: /* Contest */
/* Bonus durch Zauber */ probability = 0.05 * (10 + pa - at);
probability +=
0.01 * get_curseeffect(((region *) obj)->attribs, C_RESIST_MAGIC, 0);
break;
case TYP_BUILDING: probability += magic_resistance((unit *) obj);
/* Bonus durch Zauber */ break;
probability += }
0.01 * get_curseeffect(((building *) obj)->attribs, C_RESIST_MAGIC, 0);
/* Bonus durch Typ */ case TYP_REGION:
probability += 0.01 * ((building *) obj)->type->magres; /* Bonus durch Zauber */
probability +=
0.01 * get_curseeffect(((region *) obj)->attribs, C_RESIST_MAGIC, 0);
break;
break; case TYP_BUILDING:
/* Bonus durch Zauber */
probability +=
0.01 * get_curseeffect(((building *) obj)->attribs, C_RESIST_MAGIC, 0);
case TYP_SHIP: /* Bonus durch Typ */
/* Bonus durch Zauber */ probability += 0.01 * ((building *) obj)->type->magres;
probability +=
0.01 * get_curseeffect(((ship *) obj)->attribs, C_RESIST_MAGIC, 0); break;
break;
case TYP_SHIP:
/* Bonus durch Zauber */
probability +=
0.01 * get_curseeffect(((ship *) obj)->attribs, C_RESIST_MAGIC, 0);
break;
} }
probability = MAX(0.02, probability + t_bonus * 0.01); probability = MAX(0.02, probability + t_bonus * 0.01);
@ -1348,86 +1348,86 @@ static void do_fumble(castorder * co)
ADDMSG(&u->faction->msgs, msg_message("patzer", "unit region spell", ADDMSG(&u->faction->msgs, msg_message("patzer", "unit region spell",
u, r, sp)); u, r, sp));
switch (rng_int() % 10) { switch (rng_int() % 10) {
case 0: case 0:
/* wenn vorhanden spezieller Patzer, ansonsten nix */ /* wenn vorhanden spezieller Patzer, ansonsten nix */
if (sp->patzer) if (sp->patzer)
sp->patzer(co); sp->patzer(co);
else else
patzer(co); patzer(co);
break; break;
case 1: case 1:
/* Kröte */ /* Kröte */
{ {
/* one or two things will happen: the toad changes her race back, /* one or two things will happen: the toad changes her race back,
* and may or may not get toadslime. * and may or may not get toadslime.
* The list of things to happen are attached to a timeout * The list of things to happen are attached to a timeout
* trigger and that's added to the triggerlit of the mage gone toad. * trigger and that's added to the triggerlit of the mage gone toad.
*/ */
trigger *trestore = trigger_changerace(u, u->race, u->irace); trigger *trestore = trigger_changerace(u, u->race, u->irace);
if (chance(0.7)) { if (chance(0.7)) {
const item_type *it_toadslime = it_find("toadslime"); const item_type *it_toadslime = it_find("toadslime");
if (it_toadslime != NULL) { if (it_toadslime != NULL) {
t_add(&trestore, trigger_giveitem(u, it_toadslime, 1)); t_add(&trestore, trigger_giveitem(u, it_toadslime, 1));
}
} }
duration = rng_int() % level / 2;
if (duration < 2)
duration = 2;
add_trigger(&u->attribs, "timer", trigger_timeout(duration, trestore));
u->race = new_race[RC_TOAD];
u->irace = NULL;
ADDMSG(&r->msgs, msg_message("patzer6", "unit region spell", u, r, sp));
break;
} }
/* fall-through is intentional! */
case 2: duration = rng_int() % level / 2;
/* temporärer Stufenverlust */ if (duration < 2)
duration = MAX(rng_int() % level / 2, 2); duration = 2;
effect = -0.5 * level; add_trigger(&u->attribs, "timer", trigger_timeout(duration, trestore));
c = u->race = new_race[RC_TOAD];
create_curse(u, &u->attribs, ct_find("skillmod"), (float)level, u->irace = NULL;
duration, effect, 1); ADDMSG(&r->msgs, msg_message("patzer6", "unit region spell", u, r, sp));
c->data.i = SK_MAGIC; break;
ADDMSG(&u->faction->msgs, msg_message("patzer2", "unit region", u, r)); }
break; /* fall-through is intentional! */
case 3:
case 4:
/* Spruch schlägt fehl, alle Magiepunkte weg */
set_spellpoints(u, 0);
ADDMSG(&u->faction->msgs, msg_message("patzer3", "unit region spell",
u, r, sp));
break;
case 5: case 2:
case 6: /* temporärer Stufenverlust */
/* Spruch gelingt, aber alle Magiepunkte weg */ duration = MAX(rng_int() % level / 2, 2);
if (sp->sp_function == NULL) { effect = -0.5 * level;
log_error(("spell '%s' has no function.\n", sp->sname)); c =
} else { create_curse(u, &u->attribs, ct_find("skillmod"), (float)level,
((nspell_f) sp->sp_function) (co); duration, effect, 1);
} c->data.i = SK_MAGIC;
set_spellpoints(u, 0); ADDMSG(&u->faction->msgs, msg_message("patzer2", "unit region", u, r));
ADDMSG(&u->faction->msgs, msg_message("patzer4", "unit region spell", break;
u, r, sp)); case 3:
break; case 4:
/* Spruch schlägt fehl, alle Magiepunkte weg */
set_spellpoints(u, 0);
ADDMSG(&u->faction->msgs, msg_message("patzer3", "unit region spell",
u, r, sp));
break;
case 7: case 5:
case 8: case 6:
case 9: /* Spruch gelingt, aber alle Magiepunkte weg */
default: if (sp->sp_function == NULL) {
/* Spruch gelingt, alle nachfolgenden Sprüche werden 2^4 so teuer */ log_error(("spell '%s' has no function.\n", sp->sname));
if (sp->sp_function == NULL) { } else {
log_error(("spell '%s' has no function.\n", sp->sname)); ((nspell_f) sp->sp_function) (co);
} else { }
((nspell_f) sp->sp_function) (co); set_spellpoints(u, 0);
} ADDMSG(&u->faction->msgs, msg_message("patzer4", "unit region spell",
ADDMSG(&u->faction->msgs, msg_message("patzer5", "unit region spell", u, r, sp));
u, r, sp)); break;
countspells(u, 3);
case 7:
case 8:
case 9:
default:
/* Spruch gelingt, alle nachfolgenden Sprüche werden 2^4 so teuer */
if (sp->sp_function == NULL) {
log_error(("spell '%s' has no function.\n", sp->sname));
} else {
((nspell_f) sp->sp_function) (co);
}
ADDMSG(&u->faction->msgs, msg_message("patzer5", "unit region spell",
u, r, sp));
countspells(u, 3);
} }
return; return;
@ -1588,16 +1588,16 @@ verify_unit(region * r, unit * mage, const spell * sp, spllprm * spobj,
{ {
unit *u = NULL; unit *u = NULL;
switch (spobj->typ) { switch (spobj->typ) {
case SPP_UNIT: case SPP_UNIT:
u = findunit(spobj->data.i); u = findunit(spobj->data.i);
break; break;
case SPP_TEMP: case SPP_TEMP:
u = findnewunit(r, mage->faction, spobj->data.i); u = findnewunit(r, mage->faction, spobj->data.i);
if (u == NULL) if (u == NULL)
u = findnewunit(mage->region, mage->faction, spobj->data.i); u = findnewunit(mage->region, mage->faction, spobj->data.i);
break; break;
default: default:
assert(!"shouldn't happen, this"); assert(!"shouldn't happen, this");
} }
if (u != NULL && (sp->sptyp & SEARCHLOCAL)) { if (u != NULL && (sp->sptyp & SEARCHLOCAL)) {
if (u->region != r) if (u->region != r)
@ -1654,21 +1654,21 @@ verify_targets(castorder * co, int *invalid, int *resist, int *success)
spllprm *spobj = sa->param[i]; spllprm *spobj = sa->param[i];
switch (spobj->typ) { switch (spobj->typ) {
case SPP_TEMP: case SPP_TEMP:
case SPP_UNIT: case SPP_UNIT:
if (!verify_unit(target_r, mage, sp, spobj, co->order)) if (!verify_unit(target_r, mage, sp, spobj, co->order))
++ * invalid; ++ * invalid;
break; break;
case SPP_BUILDING: case SPP_BUILDING:
if (!verify_building(target_r, mage, sp, spobj, co->order)) if (!verify_building(target_r, mage, sp, spobj, co->order))
++ * invalid; ++ * invalid;
break; break;
case SPP_SHIP: case SPP_SHIP:
if (!verify_ship(target_r, mage, sp, spobj, co->order)) if (!verify_ship(target_r, mage, sp, spobj, co->order))
++ * invalid; ++ * invalid;
break; break;
default: default:
break; break;
} }
} }
@ -1683,77 +1683,76 @@ verify_targets(castorder * co, int *invalid, int *resist, int *success)
if (spobj->flag == TARGET_NOTFOUND) if (spobj->flag == TARGET_NOTFOUND)
continue; continue;
switch (spobj->typ) { switch (spobj->typ) {
case SPP_TEMP: case SPP_TEMP:
case SPP_UNIT: case SPP_UNIT:
u = spobj->data.u; u = spobj->data.u;
if ((sp->sptyp & TESTRESISTANCE) if ((sp->sptyp & TESTRESISTANCE)
&& target_resists_magic(mage, u, TYP_UNIT, 0)) { && target_resists_magic(mage, u, TYP_UNIT, 0)) {
/* Fehlermeldung */ /* Fehlermeldung */
spobj->data.i = u->no; spobj->data.i = u->no;
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;
}
/* TODO: Test auf Parteieigenschaft Magieresistsenz */
++*success;
break; break;
case SPP_BUILDING: }
b = spobj->data.b;
if ((sp->sptyp & TESTRESISTANCE) /* TODO: Test auf Parteieigenschaft Magieresistsenz */
&& target_resists_magic(mage, b, TYP_BUILDING, 0)) { /* Fehlermeldung */ ++*success;
spobj->data.i = b->no; break;
spobj->flag = TARGET_RESISTS; case SPP_BUILDING:
++*resist; b = spobj->data.b;
ADDMSG(&mage->faction->msgs, msg_message("spellbuildingresists",
"unit region command id",
mage, mage->region, co->order, spobj->data.i));
break;
}
++*success;
break;
case SPP_SHIP:
sh = spobj->data.sh;
if ((sp->sptyp & TESTRESISTANCE) if ((sp->sptyp & TESTRESISTANCE)
&& target_resists_magic(mage, sh, TYP_SHIP, 0)) { /* Fehlermeldung */ && target_resists_magic(mage, b, TYP_BUILDING, 0)) { /* Fehlermeldung */
spobj->data.i = sh->no; spobj->data.i = b->no;
spobj->flag = TARGET_RESISTS; spobj->flag = TARGET_RESISTS;
++*resist; ++*resist;
ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, ADDMSG(&mage->faction->msgs, msg_message("spellbuildingresists",
"spellshipresists", "ship", sh)); "unit region command id",
break; mage, mage->region, co->order, spobj->data.i));
}
++*success;
break; break;
}
++*success;
break;
case SPP_SHIP:
sh = spobj->data.sh;
case SPP_REGION: if ((sp->sptyp & TESTRESISTANCE)
/* haben wir ein Regionsobjekt, dann wird auch dieses und && target_resists_magic(mage, sh, TYP_SHIP, 0)) { /* Fehlermeldung */
nicht target_r überprüft. */ spobj->data.i = sh->no;
tr = spobj->data.r; spobj->flag = TARGET_RESISTS;
++*resist;
ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order,
"spellshipresists", "ship", sh));
break;
}
++*success;
break;
if ((sp->sptyp & TESTRESISTANCE) case SPP_REGION:
&& target_resists_magic(mage, tr, TYP_REGION, 0)) { /* Fehlermeldung */ /* haben wir ein Regionsobjekt, dann wird auch dieses und
spobj->flag = TARGET_RESISTS; nicht target_r überprüft. */
++*resist; tr = spobj->data.r;
ADDMSG(&mage->faction->msgs, msg_message("spellregionresists",
"unit region command", mage, mage->region, co->order));
break;
}
++*success;
break;
case SPP_INT:
case SPP_STRING:
++*success;
break;
default: if ((sp->sptyp & TESTRESISTANCE)
&& target_resists_magic(mage, tr, TYP_REGION, 0)) { /* Fehlermeldung */
spobj->flag = TARGET_RESISTS;
++*resist;
ADDMSG(&mage->faction->msgs, msg_message("spellregionresists",
"unit region command", mage, mage->region, co->order));
break; break;
}
++*success;
break;
case SPP_INT:
case SPP_STRING:
++*success;
break;
default:
break;
} }
} }
} else { } else {
@ -1804,11 +1803,11 @@ static void free_spellparameter(spellparameter * pa)
for (i = 0; i < pa->length; i++) { for (i = 0; i < pa->length; i++) {
switch (pa->param[i]->typ) { switch (pa->param[i]->typ) {
case SPP_STRING: case SPP_STRING:
free(pa->param[i]->data.s); free(pa->param[i]->data.s);
break; break;
default: default:
break; break;
} }
free(pa->param[i]); free(pa->param[i]);
} }
@ -1967,87 +1966,87 @@ static spellparameter *add_spellparameter(region * target_r, unit * u,
param_t pword; param_t pword;
int j = -1; int j = -1;
switch (*c) { switch (*c) {
case '?': case '?':
/* tja. das sollte moeglichst nur am Ende passieren, /* tja. das sollte moeglichst nur am Ende passieren,
* weil sonst die kacke dampft. */ * weil sonst die kacke dampft. */
j = 0;
++c;
assert(*c == 0);
break;
case '+':
/* das vorhergehende Element kommt ein oder mehrmals vor, wir
* springen zum key zurück */
j = 0;
--c;
break;
case 'u':
/* Parameter ist eine Einheit, evtl. TEMP */
j = addparam_unit(param + i, &spobj, u, ord);
++c;
break;
case 'r':
/* Parameter sind zwei Regionskoordinaten */
/* this silly thing only works in the normal plane! */
j = addparam_region(param + i, &spobj, u, ord, get_normalplane());
++c;
break;
case 'b':
/* Parameter ist eine Burgnummer */
j = addparam_building(param + i, &spobj);
++c;
break;
case 's':
j = addparam_ship(param + i, &spobj);
++c;
break;
case 'c':
/* Text, wird im Spruch ausgewertet */
j = addparam_string(param + i, &spobj);
++c;
break;
case 'i': /* Zahl */
j = addparam_int(param + i, &spobj);
++c;
break;
case 'k':
++c;
pword = findparam(param[i++], u->faction->locale);
switch (pword) {
case P_REGION:
spobj = malloc(sizeof(spllprm));
spobj->flag = 0;
spobj->typ = SPP_REGION;
spobj->data.r = u->region;
j = 0; j = 0;
++c; ++c;
assert(*c == 0);
break; break;
case '+': case P_UNIT:
/* das vorhergehende Element kommt ein oder mehrmals vor, wir if (i < size) {
* springen zum key zurück */ j = addparam_unit(param + i, &spobj, u, ord);
j = 0; ++c;
--c; }
break; break;
case 'u': case P_BUILDING:
/* Parameter ist eine Einheit, evtl. TEMP */ case P_GEBAEUDE:
j = addparam_unit(param + i, &spobj, u, ord); if (i < size) {
++c; j = addparam_building(param + i, &spobj);
++c;
}
break; break;
case 'r': case P_SHIP:
/* Parameter sind zwei Regionskoordinaten */ if (i < size) {
/* this silly thing only works in the normal plane! */ j = addparam_ship(param + i, &spobj);
j = addparam_region(param + i, &spobj, u, ord, get_normalplane()); ++c;
++c;
break;
case 'b':
/* Parameter ist eine Burgnummer */
j = addparam_building(param + i, &spobj);
++c;
break;
case 's':
j = addparam_ship(param + i, &spobj);
++c;
break;
case 'c':
/* Text, wird im Spruch ausgewertet */
j = addparam_string(param + i, &spobj);
++c;
break;
case 'i': /* Zahl */
j = addparam_int(param + i, &spobj);
++c;
break;
case 'k':
++c;
pword = findparam(param[i++], u->faction->locale);
switch (pword) {
case P_REGION:
spobj = malloc(sizeof(spllprm));
spobj->flag = 0;
spobj->typ = SPP_REGION;
spobj->data.r = u->region;
j = 0;
++c;
break;
case P_UNIT:
if (i < size) {
j = addparam_unit(param + i, &spobj, u, ord);
++c;
}
break;
case P_BUILDING:
case P_GEBAEUDE:
if (i < size) {
j = addparam_building(param + i, &spobj);
++c;
}
break;
case P_SHIP:
if (i < size) {
j = addparam_ship(param + i, &spobj);
++c;
}
break;
default:
j = -1;
break;
} }
break; break;
default: default:
j = -1; j = -1;
break; break;
}
break;
default:
j = -1;
break;
} }
if (j < 0) if (j < 0)
fail = true; fail = true;
@ -2481,10 +2480,12 @@ static boolean is_moving_ship(const region * r, const ship * sh)
if (u) if (u)
switch (get_keyword(u->thisorder)) { switch (get_keyword(u->thisorder)) {
case K_ROUTE: case K_ROUTE:
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

@ -1328,12 +1328,14 @@ static int movement_speed(unit * u)
assert(u->number); assert(u->number);
/* dragons have a fixed speed, and no other effects work on them: */ /* dragons have a fixed speed, and no other effects work on them: */
switch (old_race(u->race)) { switch (old_race(u->race)) {
case RC_DRAGON: case RC_DRAGON:
case RC_WYRM: case RC_WYRM:
case RC_FIREDRAGON: case RC_FIREDRAGON:
case RC_BIRTHDAYDRAGON: case RC_BIRTHDAYDRAGON:
case RC_SONGDRAGON: case RC_SONGDRAGON:
return BP_DRAGON; return BP_DRAGON;
default:
break;
} }
if (!init) { if (!init) {
@ -1350,38 +1352,38 @@ static int movement_speed(unit * u)
switch (canride(u)) { switch (canride(u)) {
case 1: /* Pferd */ case 1: /* Pferd */
mp = BP_RIDING; mp = BP_RIDING;
break; break;
case 2: /* Einhorn */ case 2: /* Einhorn */
mp = BP_UNICORN; mp = BP_UNICORN;
break; break;
default: default:
mp = BP_WALKING; mp = BP_WALKING;
/* Siebenmeilentee */ /* Siebenmeilentee */
if (get_effect(u, oldpotiontype[P_FAST]) >= u->number) { if (get_effect(u, oldpotiontype[P_FAST]) >= u->number) {
mp *= 2; mp *= 2;
change_effect(u, oldpotiontype[P_FAST], -u->number); change_effect(u, oldpotiontype[P_FAST], -u->number);
} }
/* unicorn in inventory */ /* unicorn in inventory */
if (u->number <= get_item(u, I_FEENSTIEFEL)) { if (u->number <= get_item(u, I_FEENSTIEFEL)) {
mp *= 2;
}
/* Im Astralraum sind Tyb und Ill-Magier doppelt so schnell.
* Nicht kumulativ mit anderen Beschleunigungen! */
if (mp * dk <= BP_WALKING * u->race->speed && is_astral(u->region)
&& is_mage(u)) {
sc_mage *mage = get_mage(u);
if (mage->magietyp == M_TYBIED || mage->magietyp == M_ILLAUN) {
mp *= 2; mp *= 2;
} }
}
/* Im Astralraum sind Tyb und Ill-Magier doppelt so schnell. break;
* Nicht kumulativ mit anderen Beschleunigungen! */
if (mp * dk <= BP_WALKING * u->race->speed && is_astral(u->region)
&& is_mage(u)) {
sc_mage *mage = get_mage(u);
if (mage->magietyp == M_TYBIED || mage->magietyp == M_ILLAUN) {
mp *= 2;
}
}
break;
} }
return (int)(dk * mp); return (int)(dk * mp);
} }
@ -1996,15 +1998,15 @@ static const region_list *travel_i(unit * u, const region_list * route_begin,
return route_begin; return route_begin;
} }
switch (canwalk(u)) { switch (canwalk(u)) {
case E_CANWALK_TOOHEAVY: case E_CANWALK_TOOHEAVY:
cmistake(u, ord, 57, MSG_MOVE); cmistake(u, ord, 57, MSG_MOVE);
return route_begin; return route_begin;
case E_CANWALK_TOOMANYHORSES: case E_CANWALK_TOOMANYHORSES:
cmistake(u, ord, 56, MSG_MOVE); cmistake(u, ord, 56, MSG_MOVE);
return route_begin; return route_begin;
case E_CANWALK_TOOMANYCARTS: case E_CANWALK_TOOMANYCARTS:
cmistake(u, ord, 42, MSG_MOVE); cmistake(u, ord, 42, MSG_MOVE);
return route_begin; return route_begin;
} }
route_end = cap_route(r, route_begin, route_end, movement_speed(u)); route_end = cap_route(r, route_begin, route_end, movement_speed(u));
@ -2565,44 +2567,41 @@ 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: /* after moving, the unit has no thisorder. this prevents
case K_MOVE: * it from moving twice (or getting error messages twice).
/* after moving, the unit has no thisorder. this prevents * UFL_NOTMOVING is set in combat if the unit is not allowed
* it from moving twice (or getting error messages twice). * to move because it was involved in a battle.
* UFL_NOTMOVING is set in combat if the unit is not allowed */
* to move because it was involved in a battle. if (fval(u, UFL_NOTMOVING)) {
*/ if (fval(u, UFL_LONGACTION)) {
if (fval(u, UFL_NOTMOVING)) { cmistake(u, u->thisorder, 52, MSG_MOVE);
if (fval(u, UFL_LONGACTION)) {
cmistake(u, u->thisorder, 52, MSG_MOVE);
set_order(&u->thisorder, NULL);
} else {
cmistake(u, u->thisorder, 319, MSG_MOVE);
set_order(&u->thisorder, NULL);
}
} else if (fval(u, UFL_MOVED)) {
cmistake(u, u->thisorder, 187, MSG_MOVE);
set_order(&u->thisorder, NULL);
} else if (!can_move(u)) {
cmistake(u, u->thisorder, 55, MSG_MOVE);
set_order(&u->thisorder, NULL); set_order(&u->thisorder, NULL);
} else { } else {
if (ships) { cmistake(u, u->thisorder, 319, MSG_MOVE);
if (u->ship && fval(u, UFL_OWNER)) { set_order(&u->thisorder, NULL);
init_tokens(u->thisorder); }
skip_token(); } else if (fval(u, UFL_MOVED)) {
move(u, false); cmistake(u, u->thisorder, 187, MSG_MOVE);
} set_order(&u->thisorder, NULL);
} else { } else if (!can_move(u)) {
if (u->ship == NULL || !fval(u, UFL_OWNER)) { cmistake(u, u->thisorder, 55, MSG_MOVE);
init_tokens(u->thisorder); set_order(&u->thisorder, NULL);
skip_token(); } else {
move(u, false); if (ships) {
} if (u->ship && fval(u, UFL_OWNER)) {
init_tokens(u->thisorder);
skip_token();
move(u, false);
}
} else {
if (u->ship == NULL || !fval(u, UFL_OWNER)) {
init_tokens(u->thisorder);
skip_token();
move(u, false);
} }
} }
break; }
} }
if (u->region == r) { if (u->region == r) {
/* not moved, use next unit */ /* not moved, use next unit */
@ -2683,24 +2682,24 @@ void follow_unit(unit * u)
} }
switch (get_keyword(u2->thisorder)) { switch (get_keyword(u2->thisorder)) {
case K_MOVE: case K_MOVE:
case K_ROUTE: case K_ROUTE:
case K_DRIVE: case K_DRIVE:
follow = true; follow = true;
break; break;
default: default:
for (ord = u2->orders; ord; ord = ord->next) { for (ord = u2->orders; ord; ord = ord->next) {
switch (get_keyword(ord)) { switch (get_keyword(ord)) {
case K_FOLLOW: case K_FOLLOW:
case K_PIRACY: case K_PIRACY:
follow = true; follow = true;
break;
default:
continue;
}
break; break;
default:
continue;
} }
break; break;
}
break;
} }
if (!follow) { if (!follow) {
attrib *a2 = a_find(u2->attribs, &at_follow); attrib *a2 = a_find(u2->attribs, &at_follow);

View file

@ -195,33 +195,33 @@ static order_data *create_data(keyword_t kwd, const char *sptr, int lindex)
if (kwd == K_STUDY) { if (kwd == K_STUDY) {
skill_t sk = findskill(parse_token(&sptr), lang); skill_t sk = findskill(parse_token(&sptr), lang);
switch (sk) { switch (sk) {
case NOSKILL: /* fehler */ case NOSKILL: /* fehler */
break;
case SK_MAGIC: /* kann parameter haben */
if (*sptr != 0)
break; break;
case SK_MAGIC: /* kann parameter haben */ default: /* nur skill als Parameter, keine extras */
if (*sptr != 0) data = locale_array[lindex]->study_orders[sk];
break; if (data == NULL) {
default: /* nur skill als Parameter, keine extras */ const char *skname = skillname(sk, lang);
data = locale_array[lindex]->study_orders[sk]; data = (order_data *) malloc(sizeof(order_data));
if (data == NULL) { locale_array[lindex]->study_orders[sk] = data;
const char *skname = skillname(sk, lang); data->_keyword = kwd;
data = (order_data *) malloc(sizeof(order_data)); data->_lindex = lindex;
locale_array[lindex]->study_orders[sk] = data; if (strchr(skname, ' ') != NULL) {
data->_keyword = kwd; size_t len = strlen(skname);
data->_lindex = lindex; data->_str = malloc(len + 3);
if (strchr(skname, ' ') != NULL) { data->_str[0] = '\"';
size_t len = strlen(skname); memcpy(data->_str + 1, skname, len);
data->_str = malloc(len + 3); data->_str[len + 1] = '\"';
data->_str[0] = '\"'; data->_str[len + 2] = '\0';
memcpy(data->_str + 1, skname, len); } else {
data->_str[len + 1] = '\"'; data->_str = strdup(skname);
data->_str[len + 2] = '\0';
} else {
data->_str = strdup(skname);
}
data->_refcount = 1;
} }
++data->_refcount; data->_refcount = 1;
return data; }
++data->_refcount;
return data;
} }
} }
@ -256,15 +256,15 @@ static order *create_order_i(keyword_t kwd, const char *sptr, int persistent,
/* if this is just nonsense, then we skip it. */ /* if this is just nonsense, then we skip it. */
if (lomem) { if (lomem) {
switch (kwd) { switch (kwd) {
case K_KOMMENTAR: case K_KOMMENTAR:
case NOKEYWORD: case NOKEYWORD:
return NULL; return NULL;
case K_LIEFERE: case K_LIEFERE:
kwd = K_GIVE; kwd = K_GIVE;
persistent = 1; persistent = 1;
break; break;
default: default:
break; break;
} }
} }
@ -304,26 +304,26 @@ order *create_order(keyword_t kwd, const struct locale * lang,
const char *s; const char *s;
++params; ++params;
switch (*params) { switch (*params) {
case 's': case 's':
s = va_arg(marker, const char *); s = va_arg(marker, const char *);
bytes = (int)strlcpy(bufp, s, size); bytes = (int)strlcpy(bufp, s, size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
break; break;
case 'd': case 'd':
i = va_arg(marker, int); i = va_arg(marker, int);
bytes = (int)strlcpy(bufp, itoa10(i), size); bytes = (int)strlcpy(bufp, itoa10(i), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
break; break;
case 'i': case 'i':
i = va_arg(marker, int); i = va_arg(marker, int);
bytes = (int)strlcpy(bufp, itoa36(i), size); bytes = (int)strlcpy(bufp, itoa36(i), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
break; break;
default: default:
assert(!"unknown format-character in create_order"); assert(!"unknown format-character in create_order");
} }
} else if (size > 0) { } else if (size > 0) {
*bufp++ = *params; *bufp++ = *params;
@ -379,55 +379,55 @@ boolean is_repeated(const order * ord)
param_t param; param_t param;
switch (kwd) { switch (kwd) {
case K_CAST: case K_CAST:
case K_BUY: case K_BUY:
case K_SELL: case K_SELL:
case K_ROUTE: case K_ROUTE:
case K_DRIVE: case K_DRIVE:
case K_WORK: case K_WORK:
case K_BESIEGE: case K_BESIEGE:
case K_ENTERTAIN: case K_ENTERTAIN:
case K_TAX: case K_TAX:
case K_RESEARCH: case K_RESEARCH:
case K_SPY: case K_SPY:
case K_STEAL: case K_STEAL:
case K_SABOTAGE: case K_SABOTAGE:
case K_STUDY: case K_STUDY:
case K_TEACH: case K_TEACH:
case K_BREED: case K_BREED:
case K_PIRACY: case K_PIRACY:
case K_PLANT:
return true;
case K_FOLLOW:
/* FOLLOW is only a long order if we are following a ship. */
parser_pushstate();
init_tokens(ord);
skip_token();
param = getparam(lang);
parser_popstate();
if (param == P_SHIP)
return true; return true;
break;
case K_PLANT: case K_MAKE:
/* Falls wir MACHE TEMP haben, ignorieren wir es. Alle anderen
* Arten von MACHE zaehlen aber als neue defaults und werden
* behandelt wie die anderen (deswegen kein break nach case
* K_MAKE) - und in thisorder (der aktuelle 30-Tage Befehl)
* abgespeichert). */
parser_pushstate();
init_tokens(ord); /* initialize token-parser */
skip_token();
param = getparam(lang);
parser_popstate();
if (param != P_TEMP)
return true; return true;
break;
case K_FOLLOW: default:
/* FOLLOW is only a long order if we are following a ship. */ return false;
parser_pushstate();
init_tokens(ord);
skip_token();
param = getparam(lang);
parser_popstate();
if (param == P_SHIP)
return true;
break;
case K_MAKE:
/* Falls wir MACHE TEMP haben, ignorieren wir es. Alle anderen
* Arten von MACHE zaehlen aber als neue defaults und werden
* behandelt wie die anderen (deswegen kein break nach case
* K_MAKE) - und in thisorder (der aktuelle 30-Tage Befehl)
* abgespeichert). */
parser_pushstate();
init_tokens(ord); /* initialize token-parser */
skip_token();
param = getparam(lang);
parser_popstate();
if (param != P_TEMP)
return true;
break;
} }
return false; return false;
} }
@ -447,55 +447,55 @@ boolean is_exclusive(const order * ord)
param_t param; param_t param;
switch (kwd) { switch (kwd) {
case K_MOVE: case K_MOVE:
case K_WEREWOLF: case K_WEREWOLF:
/* these should not become persistent */ /* these should not become persistent */
case K_ROUTE: case K_ROUTE:
case K_DRIVE: case K_DRIVE:
case K_WORK: case K_WORK:
case K_BESIEGE: case K_BESIEGE:
case K_ENTERTAIN: case K_ENTERTAIN:
case K_TAX: case K_TAX:
case K_RESEARCH: case K_RESEARCH:
case K_SPY: case K_SPY:
case K_STEAL: case K_STEAL:
case K_SABOTAGE: case K_SABOTAGE:
case K_STUDY: case K_STUDY:
case K_TEACH: case K_TEACH:
case K_BREED: case K_BREED:
case K_PIRACY: case K_PIRACY:
case K_PLANT:
return true;
case K_FOLLOW:
/* FOLLOW is only a long order if we are following a ship. */
parser_pushstate();
init_tokens(ord);
skip_token();
param = getparam(lang);
parser_popstate();
if (param == P_SHIP)
return true; return true;
break;
case K_PLANT: case K_MAKE:
/* Falls wir MACHE TEMP haben, ignorieren wir es. Alle anderen
* Arten von MACHE zaehlen aber als neue defaults und werden
* behandelt wie die anderen (deswegen kein break nach case
* K_MAKE) - und in thisorder (der aktuelle 30-Tage Befehl)
* abgespeichert). */
parser_pushstate();
init_tokens(ord); /* initialize token-parser */
skip_token();
param = getparam(lang);
parser_popstate();
if (param != P_TEMP)
return true; return true;
break;
case K_FOLLOW: default:
/* FOLLOW is only a long order if we are following a ship. */ return false;
parser_pushstate();
init_tokens(ord);
skip_token();
param = getparam(lang);
parser_popstate();
if (param == P_SHIP)
return true;
break;
case K_MAKE:
/* Falls wir MACHE TEMP haben, ignorieren wir es. Alle anderen
* Arten von MACHE zaehlen aber als neue defaults und werden
* behandelt wie die anderen (deswegen kein break nach case
* K_MAKE) - und in thisorder (der aktuelle 30-Tage Befehl)
* abgespeichert). */
parser_pushstate();
init_tokens(ord); /* initialize token-parser */
skip_token();
param = getparam(lang);
parser_popstate();
if (param != P_TEMP)
return true;
break;
} }
return false; return false;
} }
@ -515,57 +515,57 @@ boolean is_long(const order * ord)
param_t param; param_t param;
switch (kwd) { switch (kwd) {
case K_CAST: case K_CAST:
case K_BUY: case K_BUY:
case K_SELL: case K_SELL:
case K_MOVE: case K_MOVE:
case K_WEREWOLF: case K_WEREWOLF:
case K_ROUTE: case K_ROUTE:
case K_DRIVE: case K_DRIVE:
case K_WORK: case K_WORK:
case K_BESIEGE: case K_BESIEGE:
case K_ENTERTAIN: case K_ENTERTAIN:
case K_TAX: case K_TAX:
case K_RESEARCH: case K_RESEARCH:
case K_SPY: case K_SPY:
case K_STEAL: case K_STEAL:
case K_SABOTAGE: case K_SABOTAGE:
case K_STUDY: case K_STUDY:
case K_TEACH: case K_TEACH:
case K_BREED: case K_BREED:
case K_PIRACY: case K_PIRACY:
case K_PLANT:
return true;
case K_FOLLOW:
/* FOLLOW is only a long order if we are following a ship. */
parser_pushstate();
init_tokens(ord);
skip_token();
param = getparam(lang);
parser_popstate();
if (param == P_SHIP)
return true; return true;
break;
case K_PLANT: case K_MAKE:
/* Falls wir MACHE TEMP haben, ignorieren wir es. Alle anderen
* Arten von MACHE zaehlen aber als neue defaults und werden
* behandelt wie die anderen (deswegen kein break nach case
* K_MAKE) - und in thisorder (der aktuelle 30-Tage Befehl)
* abgespeichert). */
parser_pushstate();
init_tokens(ord); /* initialize token-parser */
skip_token();
param = getparam(lang);
parser_popstate();
if (param != P_TEMP)
return true; return true;
break;
case K_FOLLOW: default:
/* FOLLOW is only a long order if we are following a ship. */ return false;
parser_pushstate();
init_tokens(ord);
skip_token();
param = getparam(lang);
parser_popstate();
if (param == P_SHIP)
return true;
break;
case K_MAKE:
/* Falls wir MACHE TEMP haben, ignorieren wir es. Alle anderen
* Arten von MACHE zaehlen aber als neue defaults und werden
* behandelt wie die anderen (deswegen kein break nach case
* K_MAKE) - und in thisorder (der aktuelle 30-Tage Befehl)
* abgespeichert). */
parser_pushstate();
init_tokens(ord); /* initialize token-parser */
skip_token();
param = getparam(lang);
parser_popstate();
if (param != P_TEMP)
return true;
break;
} }
return false; return false;
} }
@ -584,18 +584,20 @@ boolean is_persistent(const order * ord)
keyword_t kwd = ORD_KEYWORD(ord); keyword_t kwd = ORD_KEYWORD(ord);
boolean persist = ord->_persistent != 0; boolean persist = ord->_persistent != 0;
switch (kwd) { switch (kwd) {
case K_MOVE: case K_MOVE:
case K_WEREWOLF: case K_WEREWOLF:
case NOKEYWORD: case NOKEYWORD:
/* lang, aber niemals persistent! */ /* lang, aber niemals persistent! */
return false; return false;
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

@ -144,51 +144,29 @@ int freadstr(FILE * F, int encoding, char *start, size_t size)
} }
} }
switch (c) { switch (c) {
case EOF:
return EOF;
case '"':
if (!quote && str != start) {
log_error(
("datafile contains a \" that isn't at the start of a string.\n"));
assert
(!"datafile contains a \" that isn't at the start of a string.\n");
}
if (quote) {
*str = 0;
return (int)(str - start);
}
quote = true;
break;
case '\\':
c = fgetc(F);
switch (c) {
case EOF: case EOF:
return EOF; return EOF;
case '"': case 'n':
if (!quote && str != start) { if ((size_t) (str - start + 1) < size) {
log_error( *str++ = '\n';
("datafile contains a \" that isn't at the start of a string.\n"));
assert
(!"datafile contains a \" that isn't at the start of a string.\n");
}
if (quote) {
*str = 0;
return (int)(str - start);
}
quote = true;
break;
case '\\':
c = fgetc(F);
switch (c) {
case EOF:
return EOF;
case 'n':
if ((size_t) (str - start + 1) < size) {
*str++ = '\n';
}
break;
default:
if ((size_t) (str - start + 1) < size) {
if (encoding == XML_CHAR_ENCODING_8859_1 && c & 0x80) {
char inbuf = (char)c;
size_t inbytes = 1;
size_t outbytes = size - (str - start);
int ret =
unicode_latin1_to_utf8(str, &outbytes, &inbuf, &inbytes);
if (ret > 0)
str += ret;
else {
log_error(
("input data was not iso-8859-1! assuming utf-8\n"));
encoding = XML_CHAR_ENCODING_ERROR;
*str++ = (char)c;
}
} else {
*str++ = (char)c;
}
}
} }
break; break;
default: default:
@ -209,6 +187,26 @@ int freadstr(FILE * F, int encoding, char *start, size_t size)
*str++ = (char)c; *str++ = (char)c;
} }
} }
}
break;
default:
if ((size_t) (str - start + 1) < size) {
if (encoding == XML_CHAR_ENCODING_8859_1 && c & 0x80) {
char inbuf = (char)c;
size_t inbytes = 1;
size_t outbytes = size - (str - start);
int ret = unicode_latin1_to_utf8(str, &outbytes, &inbuf, &inbytes);
if (ret > 0)
str += ret;
else {
log_error(("input data was not iso-8859-1! assuming utf-8\n"));
encoding = XML_CHAR_ENCODING_ERROR;
*str++ = (char)c;
}
} else {
*str++ = (char)c;
}
}
} }
} }
} }
@ -224,20 +222,20 @@ int fwritestr(FILE * F, const char *str)
while (*str) { while (*str) {
int c = (int)(unsigned char)*str++; int c = (int)(unsigned char)*str++;
switch (c) { switch (c) {
case '"': case '"':
case '\\': case '\\':
fputc('\\', F); fputc('\\', F);
fputc(c, F); fputc(c, F);
nwrite += 2; nwrite += 2;
break; break;
case '\n': case '\n':
fputc('\\', F); fputc('\\', F);
fputc('n', F); fputc('n', F);
nwrite += 2; nwrite += 2;
break; break;
default: default:
fputc(c, F); fputc(c, F);
++nwrite; ++nwrite;
} }
} }
fputc('\"', F); fputc('\"', F);
@ -300,23 +298,28 @@ static unit *unitorders(FILE * F, int enc, struct faction *f)
boolean quit = false; boolean quit = false;
param_t param = findparam(stok, u->faction->locale); param_t param = findparam(stok, u->faction->locale);
switch (param) { switch (param) {
case P_UNIT: case P_UNIT:
case P_REGION: case P_REGION:
quit = true;
break;
case P_FACTION:
case P_NEXT:
case P_GAMENAME:
/* these terminate the orders, so we apply extra checking */
if (strlen(stok) >= 3) {
quit = true; quit = true;
break; break;
case P_FACTION: } else {
case P_NEXT: quit = false;
case P_GAMENAME: }
/* these terminate the orders, so we apply extra checking */
if (strlen(stok) >= 3) {
quit = true;
break;
} else {
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);
@ -400,58 +403,58 @@ int readorders(const char *filename)
const char *s; const char *s;
switch (igetparam(b, lang)) { switch (igetparam(b, lang)) {
case P_LOCALE: case P_LOCALE:
s = getstrtoken(); s = getstrtoken();
#undef LOCALE_CHANGE #undef LOCALE_CHANGE
#ifdef LOCALE_CHANGE #ifdef LOCALE_CHANGE
if (f && find_locale(s)) { if (f && find_locale(s)) {
f->locale = find_locale(s); f->locale = find_locale(s);
} }
#endif #endif
b = getbuf(F, enc_gamedata); b = getbuf(F, enc_gamedata);
break; break;
case P_GAMENAME: case P_GAMENAME:
case P_FACTION: case P_FACTION:
f = factionorders(); f = factionorders();
if (f) { if (f) {
++nfactions; ++nfactions;
} }
b = getbuf(F, enc_gamedata); b = getbuf(F, enc_gamedata);
break; break;
/* in factionorders wird nur eine zeile gelesen: /* in factionorders wird nur eine zeile gelesen:
* diejenige mit dem passwort. Die befehle der units * diejenige mit dem passwort. Die befehle der units
* werden geloescht, und die Partei wird als aktiv * werden geloescht, und die Partei wird als aktiv
* vermerkt. */ * vermerkt. */
case P_UNIT: case P_UNIT:
if (!f || !unitorders(F, enc_gamedata, f)) if (!f || !unitorders(F, enc_gamedata, f))
do { do {
b = getbuf(F, enc_gamedata); b = getbuf(F, enc_gamedata);
if (!b) if (!b)
break; break;
p = igetparam(b, lang); p = igetparam(b, lang);
} while ((p != P_UNIT || !f) && p != P_FACTION && p != P_NEXT } while ((p != P_UNIT || !f) && p != P_FACTION && p != P_NEXT
&& p != P_GAMENAME); && p != P_GAMENAME);
break; break;
/* Falls in unitorders() abgebrochen wird, steht dort entweder eine neue /* Falls in unitorders() abgebrochen wird, steht dort entweder eine neue
* Partei, eine neue Einheit oder das File-Ende. Das switch() wird erneut * Partei, eine neue Einheit oder das File-Ende. Das switch() wird erneut
* durchlaufen, und die entsprechende Funktion aufgerufen. Man darf buf * durchlaufen, und die entsprechende Funktion aufgerufen. Man darf buf
* auf alle Fälle nicht überschreiben! Bei allen anderen Einträgen hier * auf alle Fälle nicht überschreiben! Bei allen anderen Einträgen hier
* muß buf erneut gefüllt werden, da die betreffende Information in nur * muß buf erneut gefüllt werden, da die betreffende Information in nur
* einer Zeile steht, und nun die nächste gelesen werden muß. */ * einer Zeile steht, und nun die nächste gelesen werden muß. */
case P_NEXT: case P_NEXT:
f = NULL; f = NULL;
b = getbuf(F, enc_gamedata); b = getbuf(F, enc_gamedata);
break; break;
default: default:
b = getbuf(F, enc_gamedata); b = getbuf(F, enc_gamedata);
break; break;
} }
} }

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;
} else if (sk == SK_STEALTH) {
if (r_isforest(r)) {
++mods; ++mods;
break; }
case SK_STEALTH: } else if (sk == SK_TACTICS) {
if (r_isforest(r)) if (r_isforest(r)) {
++mods; mods += 2;
break; }
case SK_TACTICS:
if (r_isforest(r))
mods += 2;
break;
} }
}
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); } else if (param == P_XELAEN) {
break; xe_givelaen(u, ord);
case P_XELAEN:
xe_givelaen(u, ord);
break;
} }
} }
} }