diff --git a/src/bindings/bind_storage.c b/src/bindings/bind_storage.c index f96367ddc..5e7768d2d 100644 --- a/src/bindings/bind_storage.c +++ b/src/bindings/bind_storage.c @@ -20,6 +20,7 @@ without prior permission by the authors of Eressea. #include #include +#include #include #include diff --git a/src/bindings/bindings.c b/src/bindings/bindings.c index 94cdf3b8a..30a058467 100644 --- a/src/bindings/bindings.c +++ b/src/bindings/bindings.c @@ -8,17 +8,17 @@ This program may not be used, modified or distributed without prior permission by the authors of Eressea. -*/ - +*/ + #include #include "bindings.h" #include "bind_unit.h" #include "bind_faction.h" #include "bind_region.h" #include "helpers.h" - + #include - + #include #include #include @@ -37,18 +37,18 @@ without prior permission by the authors of Eressea. #include #include #include - + #include #include #include #include #include #include - + #include #include #include - + #include #include #include @@ -59,15 +59,15 @@ without prior permission by the authors of Eressea. #include #include #include - + #include #include #include - + #include #include -int log_lua_error(lua_State * L) +int log_lua_error(lua_State * L) { const char *error = lua_tostring(L, -1); log_error(("LUA call failed.\n%s\n", error)); @@ -75,10 +75,10 @@ int log_lua_error(lua_State * L) return 1; } -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 * ord = *order_ptr; + order **order_ptr = (order **) lua_touserdata(L, lua_upvalueindex(1)); + order *ord = *order_ptr; if (ord != NULL) { char cmd[8192]; write_order(ord, cmd, sizeof(cmd)); @@ -89,10 +89,10 @@ int tolua_orderlist_next(lua_State * L) return 0; } -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 * ql = *qlp; + quicklist **qlp = (quicklist **) lua_touserdata(L, lua_upvalueindex(1)); + quicklist *ql = *qlp; if (ql != NULL) { int index = lua_tointeger(L, lua_upvalueindex(2)); const char *type = lua_tostring(L, lua_upvalueindex(3)); @@ -107,27 +107,27 @@ static int tolua_quicklist_iter(lua_State * L) } 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) { - quicklist ** qlist_ptr = + quicklist **qlist_ptr = (quicklist **) lua_newuserdata(L, sizeof(quicklist *)); *qlist_ptr = list; luaL_getmetatable(L, list_type); lua_setmetatable(L, -2); lua_pushnumber(L, 0); 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 { lua_pushnil(L); } return 1; } -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 * itm = *item_ptr; + item **item_ptr = (item **) lua_touserdata(L, lua_upvalueindex(1)); + item *itm = *item_ptr; if (itm != NULL) { tolua_pushstring(L, itm->type->rtype->_name[0]); *item_ptr = itm->next; @@ -136,11 +136,11 @@ int tolua_itemlist_next(lua_State * L) return 0; } -static int tolua_autoseed(lua_State * L) +static int tolua_autoseed(lua_State * L) { const char *filename = tolua_tostring(L, 1, 0); int new_island = tolua_toboolean(L, 2, 0); - newfaction * players = read_newfactions(filename); + newfaction *players = read_newfactions(filename); if (players != NULL) { while (players) { int n = listlen(players); @@ -155,16 +155,16 @@ static int tolua_autoseed(lua_State * L) return 0; } -static int tolua_getkey(lua_State * L) +static int tolua_getkey(lua_State * L) { const char *name = tolua_tostring(L, 1, 0); int flag = atoi36(name); - attrib * a = find_key(global.attribs, flag); + attrib *a = find_key(global.attribs, flag); lua_pushboolean(L, a != NULL); return 1; } -static int tolua_translate(lua_State * L) +static int tolua_translate(lua_State * L) { const char *str = tolua_tostring(L, 1, 0); const char *lang = tolua_tostring(L, 2, 0); @@ -177,12 +177,12 @@ static int tolua_translate(lua_State * L) return 0; } -static int tolua_setkey(lua_State * L) +static int tolua_setkey(lua_State * L) { const char *name = tolua_tostring(L, 1, 0); int value = tolua_toboolean(L, 2, 0); int flag = atoi36(name); - attrib * a = find_key(global.attribs, flag); + attrib *a = find_key(global.attribs, flag); if (a == NULL && value) { add_key(&global.attribs, flag); } else if (a != NULL && !value) { @@ -191,13 +191,13 @@ static int tolua_setkey(lua_State * L) return 0; } -static int tolua_rng_int(lua_State * L) +static int tolua_rng_int(lua_State * L) { lua_pushnumber(L, (lua_Number) rng_int()); return 1; } -static int tolua_read_orders(lua_State * L) +static int tolua_read_orders(lua_State * L) { const char *filename = tolua_tostring(L, 1, 0); int result = readorders(filename); @@ -205,10 +205,10 @@ static int tolua_read_orders(lua_State * L) return 1; } -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 * target = (unit *) tolua_tousertype(L, 2, 0); + unit *sender = (unit *) tolua_tousertype(L, 1, 0); + unit *target = (unit *) tolua_tousertype(L, 2, 0); const char *str = tolua_tostring(L, 3, 0); if (!target) tolua_error(L, TOLUA_CAST "target is nil", NULL); @@ -218,10 +218,10 @@ static int tolua_message_unit(lua_State * L) return 0; } -static int tolua_message_faction(lua_State * L) +static int tolua_message_faction(lua_State * L) { - unit * sender = (unit *) tolua_tousertype(L, 1, 0); - faction * target = (faction *) tolua_tousertype(L, 2, 0); + unit *sender = (unit *) tolua_tousertype(L, 1, 0); + faction *target = (faction *) tolua_tousertype(L, 2, 0); const char *str = tolua_tostring(L, 3, 0); if (!target) tolua_error(L, TOLUA_CAST "target is nil", NULL); @@ -231,9 +231,9 @@ static int tolua_message_faction(lua_State * L) return 0; } -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); if (!sender) tolua_error(L, TOLUA_CAST "sender is nil", NULL); @@ -242,46 +242,46 @@ static int tolua_message_region(lua_State * L) return 0; } -static int tolua_update_guards(lua_State * L) +static int tolua_update_guards(lua_State * L) { update_guards(); return 0; } -static int tolua_set_turn(lua_State * L) +static int tolua_set_turn(lua_State * L) { turn = (int)tolua_tonumber(L, 1, 0); return 0; } -static int tolua_get_turn(lua_State * L) +static int tolua_get_turn(lua_State * L) { tolua_pushnumber(L, (lua_Number) turn); return 1; } -static int tolua_atoi36(lua_State * L) +static int tolua_atoi36(lua_State * L) { const char *s = tolua_tostring(L, 1, 0); tolua_pushnumber(L, (lua_Number) atoi36(s)); return 1; } -static int tolua_itoa36(lua_State * L) +static int tolua_itoa36(lua_State * L) { int i = (int)tolua_tonumber(L, 1, 0); tolua_pushstring(L, itoa36(i)); return 1; } -static int tolua_dice_rand(lua_State * L) +static int tolua_dice_rand(lua_State * L) { const char *s = tolua_tostring(L, 1, 0); tolua_pushnumber(L, dice_rand(s)); return 1; } -static int tolua_addequipment(lua_State * L) +static int tolua_addequipment(lua_State * L) { const char *eqname = tolua_tostring(L, 1, 0); const char *iname = tolua_tostring(L, 2, 0); @@ -298,7 +298,7 @@ static int tolua_addequipment(lua_State * L) return 1; } -static int tolua_get_season(lua_State * L) +static int tolua_get_season(lua_State * L) { int turnno = (int)tolua_tonumber(L, 1, 0); gamedate gd; @@ -307,25 +307,25 @@ static int tolua_get_season(lua_State * L) return 1; } -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; - attrib ** ap = NULL; + attrib **ap = NULL; 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) ap = &target->attribs; } 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) ap = &target->attribs; } 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) ap = &target->attribs; } 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) ap = &target->attribs; } @@ -336,8 +336,8 @@ static int tolua_create_curse(lua_State * L) double vigour = tolua_tonumber(L, 4, 0); int duration = (int)tolua_tonumber(L, 5, 0); double effect = tolua_tonumber(L, 6, 0); - int men = (int)tolua_tonumber(L, 7, 0); /* optional */ - curse * c = create_curse(u, ap, ctype, vigour, duration, effect, men); + int men = (int)tolua_tonumber(L, 7, 0); /* optional */ + curse *c = create_curse(u, ap, ctype, vigour, duration, effect, men); if (c) { tolua_pushboolean(L, true); return 1; @@ -348,9 +348,9 @@ static int tolua_create_curse(lua_State * L) return 1; } -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); float chances = (float)tolua_tonumber(L, 3, 0); skill_t sk = sk_find(skname); @@ -360,34 +360,34 @@ static int tolua_learn_skill(lua_State * L) return 0; } -static int tolua_update_scores(lua_State * L) +static int tolua_update_scores(lua_State * L) { score(); return 0; } -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) { update_owners(r); } return 0; } -static int tolua_update_subscriptions(lua_State * L) +static int tolua_update_subscriptions(lua_State * L) { update_subscriptions(); return 0; } -static int tolua_remove_empty_units(lua_State * L) +static int tolua_remove_empty_units(lua_State * L) { remove_empty_units(); return 0; } -static int tolua_get_nmrs(lua_State * L) +static int tolua_get_nmrs(lua_State * L) { int result = -1; int n = (int)tolua_tonumber(L, 1, 0); @@ -401,15 +401,15 @@ static int tolua_get_nmrs(lua_State * L) return 1; } -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); equip_unit(u, get_equipment(eqname)); return 0; } -static int tolua_equipment_setitem(lua_State * L) +static int tolua_equipment_setitem(lua_State * L) { int result = -1; const char *eqname = tolua_tostring(L, 1, 0); @@ -426,30 +426,30 @@ static int tolua_equipment_setitem(lua_State * L) return 1; } -static int tolua_spawn_braineaters(lua_State * L) +static int tolua_spawn_braineaters(lua_State * L) { float chance = (float)tolua_tonumber(L, 1, 0); spawn_braineaters(chance); return 0; } -static int tolua_init_reports(lua_State * L) +static int tolua_init_reports(lua_State * L) { int result = init_reports(); tolua_pushnumber(L, (lua_Number) result); return 1; } -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); int result = write_reports(f, ltime); tolua_pushnumber(L, (lua_Number) result); return 1; } -static int tolua_write_reports(lua_State * L) +static int tolua_write_reports(lua_State * L) { int result; init_reports(); @@ -458,13 +458,13 @@ static int tolua_write_reports(lua_State * L) return 1; } -static void reset_game(void) +static void reset_game(void) { - region * r; - faction * f; + region *r; + faction *f; for (r = regions; r; r = r->next) { - unit * u; - building * b; + unit *u; + building *b; r->flags &= RF_SAVEMASK; for (u = r->units; u; u = u->next) { u->flags &= UFL_SAVEMASK; @@ -473,10 +473,10 @@ static void reset_game(void) b->flags &= BLD_SAVEMASK; } 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()) { - /* some compat-fix, i believe. */ - owner = update_owners(r); + /* some compat-fix, i believe. */ + owner = update_owners(r); } if (owner) { fset(r, RF_GUARDED); @@ -488,7 +488,7 @@ static void reset_game(void) } } -static int tolua_process_orders(lua_State * L) +static int tolua_process_orders(lua_State * L) { ++turn; reset_game(); @@ -496,7 +496,7 @@ static int tolua_process_orders(lua_State * L) return 0; } -static int tolua_write_passwords(lua_State * L) +static int tolua_write_passwords(lua_State * L) { int result = writepasswd(); lua_pushnumber(L, (lua_Number) result); @@ -504,13 +504,13 @@ static int tolua_write_passwords(lua_State * L) } static struct summary *sum_begin = 0; -static int tolua_init_summary(lua_State * L) +static int tolua_init_summary(lua_State * L) { sum_begin = make_summary(); return 0; } -static int tolua_write_summary(lua_State * L) +static int tolua_write_summary(lua_State * L) { if (sum_begin) { struct summary *sum_end = make_summary(); @@ -521,13 +521,13 @@ static int tolua_write_summary(lua_State * L) return 0; } -static int tolua_free_game(lua_State * L) +static int tolua_free_game(lua_State * L) { free_gamedata(); return 0; } -static int tolua_write_map(lua_State * L) +static int tolua_write_map(lua_State * L) { const char *filename = tolua_tostring(L, 1, 0); if (filename) { @@ -536,7 +536,7 @@ static int tolua_write_map(lua_State * L) return 0; } -static int tolua_write_game(lua_State * L) +static int tolua_write_game(lua_State * L) { const char *filename = tolua_tostring(L, 1, 0); const char *mode = tolua_tostring(L, 2, 0); @@ -549,7 +549,7 @@ static int tolua_write_game(lua_State * L) return 1; } -static int tolua_read_game(lua_State * L) +static int tolua_read_game(lua_State * L) { const char *filename = tolua_tostring(L, 1, 0); const char *mode = tolua_tostring(L, 2, 0); @@ -561,84 +561,84 @@ static int tolua_read_game(lua_State * L) return 1; } -static int tolua_read_turn(lua_State * L) +static int tolua_read_turn(lua_State * L) { int cturn = current_turn(); tolua_pushnumber(L, (lua_Number) cturn); return 1; } -static int tolua_get_faction(lua_State * L) +static int tolua_get_faction(lua_State * L) { int no = tolua_toid(L, 1, 0); - faction * f = findfaction(no); + faction *f = findfaction(no); tolua_pushusertype(L, f, TOLUA_CAST "faction"); return 1; } -static int tolua_get_region(lua_State * L) +static int tolua_get_region(lua_State * L) { int x = (int)tolua_tonumber(L, 1, 0); int y = (int)tolua_tonumber(L, 2, 0); - region * r; + region *r; assert(!pnormalize(&x, &y, findplane(x, y))); r = findregion(x, y); tolua_pushusertype(L, r, TOLUA_CAST "region"); return 1; } -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); - region * r = findregionbyid(uid); + region *r = findregionbyid(uid); tolua_pushusertype(L, r, TOLUA_CAST "region"); return 1; } -static int tolua_get_building(lua_State * L) +static int tolua_get_building(lua_State * L) { int no = tolua_toid(L, 1, 0); - building * b = findbuilding(no); + building *b = findbuilding(no); tolua_pushusertype(L, b, TOLUA_CAST "building"); return 1; } -static int tolua_get_ship(lua_State * L) +static int tolua_get_ship(lua_State * L) { int no = tolua_toid(L, 1, 0); - ship * sh = findship(no); + ship *sh = findship(no); tolua_pushusertype(L, sh, TOLUA_CAST "ship"); return 1; } -static int tolua_get_alliance(lua_State * L) +static int tolua_get_alliance(lua_State * L) { int no = tolua_toid(L, 1, 0); - alliance * f = findalliance(no); + alliance *f = findalliance(no); tolua_pushusertype(L, f, TOLUA_CAST "alliance"); return 1; } -static int tolua_get_unit(lua_State * L) +static int tolua_get_unit(lua_State * L) { int no = tolua_toid(L, 1, 0); - unit * u = findunit(no); + unit *u = findunit(no); tolua_pushusertype(L, u, TOLUA_CAST "unit"); return 1; } -static int tolua_alliance_create(lua_State * L) +static int tolua_alliance_create(lua_State * L) { int id = (int)tolua_tonumber(L, 1, 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"); 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"); lua_setmetatable(L, -2); *region_ptr = regions; @@ -646,9 +646,9 @@ static int tolua_get_regions(lua_State * L) return 1; } -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"); lua_setmetatable(L, -2); *faction_ptr = factions; @@ -656,48 +656,47 @@ static int tolua_get_factions(lua_State * L) return 1; } -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); } -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); 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); 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)); return 0; } - #include #include #include #include -static int tolua_write_spells(lua_State * L) +static int tolua_write_spells(lua_State * L) { spell_f fun = (spell_f) get_function("lua_castspell"); const char *filename = "magic.xml"; xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); xmlNodePtr root = xmlNewNode(NULL, BAD_CAST "spells"); - quicklist * ql; + quicklist *ql; int qi; 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) { int combat = 0; xmlNodePtr node = xmlNewNode(NULL, BAD_CAST "spell"); @@ -711,7 +710,7 @@ static int tolua_write_spells(lua_State * L) if (sp->parameter) xmlNewProp(node, BAD_CAST "parameters", BAD_CAST sp->parameter); if (sp->components) { - spell_component * comp = sp->components; + spell_component *comp = sp->components; for (; comp->type != 0; ++comp) { static const char *costs[] = { "fixed", "level", "linear" }; xmlNodePtr cnode = xmlNewNode(NULL, BAD_CAST "resource"); @@ -737,10 +736,10 @@ static int tolua_write_spells(lua_State * L) } if (sp->sptyp & POSTCOMBATSPELL) combat = 3; - + else if (sp->sptyp & COMBATSPELL) combat = 2; - + else if (sp->sptyp & PRECOMBATSPELL) combat = 1; if (combat) { @@ -756,20 +755,20 @@ static int tolua_write_spells(lua_State * L) return 0; } -static int config_get_ships(lua_State * L) +static int config_get_ships(lua_State * L) { - quicklist * ql; + quicklist *ql; int qi, i = 0; lua_createtable(L, ql_length(shiptypes), 0); 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]); lua_rawseti(L, -2, ++i); } return 1; } -static int config_get_locales(lua_State * L) +static int config_get_locales(lua_State * L) { const struct locale *lang; int i = 0, n = 0; @@ -783,7 +782,7 @@ static int config_get_locales(lua_State * L) return 1; } -static int config_get_resource(lua_State * L) +static int config_get_resource(lua_State * L) { const char *name = tolua_tostring(L, 1, 0); if (name) { @@ -824,42 +823,42 @@ static int config_get_resource(lua_State * L) return 0; } -static int tolua_get_spell_text(lua_State * L) +static int tolua_get_spell_text(lua_State * L) { 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)); 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]); 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); return 1; } -static int tolua_get_spell_name(lua_State * L) +static int tolua_get_spell_name(lua_State * L) { 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)); return 1; } -static int tolua_get_spells(lua_State * L) +static int tolua_get_spells(lua_State * L) { return tolua_quicklist_push(L, "spell_list", "spell", spells); } -int tolua_read_xml(lua_State * L) +int tolua_read_xml(lua_State * L) { const char *filename = tolua_tostring(L, 1, 0); const char *catalog = tolua_tostring(L, 2, 0); @@ -867,15 +866,15 @@ int tolua_read_xml(lua_State * L) return 0; } -int tolua_process_markets(lua_State * L) +int tolua_process_markets(lua_State * L) { do_markets(); return 0; } -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) { produce(r); } @@ -884,19 +883,19 @@ int tolua_process_produce(lua_State * L) typedef struct event_args { int hfunction; - int hargs; - const char *sendertype; + int hargs; + const char *sendertype; } event_args; -static void args_free(void *udata) +static void args_free(void *udata) { free(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; - event_args * args = (event_args *) udata; + lua_State *L = (lua_State *) global.vm_state; + event_args *args = (event_args *) udata; int nargs = 2; lua_rawgeti(L, LUA_REGISTRYINDEX, args->hfunction); if (sender && args->sendertype) { @@ -917,12 +916,12 @@ static void event_cb(void *sender, const char *event, void *udata) * 2: event (string) * 3: handler (function) * 4: arguments (any, *optional*) -**/ -static int tolua_eventbus_register(lua_State * L) +**/ +static int tolua_eventbus_register(lua_State * L) { void *sender = tolua_tousertype(L, 1, 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; lua_pushvalue(L, 3); args->hfunction = luaL_ref(L, LUA_REGISTRYINDEX); @@ -936,7 +935,7 @@ static int tolua_eventbus_register(lua_State * L) return 0; } -static int tolua_eventbus_fire(lua_State * L) +static int tolua_eventbus_fire(lua_State * L) { void *sender = tolua_tousertype(L, 1, 0); const char *event = tolua_tostring(L, 2, 0); @@ -945,24 +944,24 @@ static int tolua_eventbus_fire(lua_State * L) return 0; } -static int tolua_report_unit(lua_State * L) +static int tolua_report_unit(lua_State * L) { char buffer[512]; - unit * u = (unit *) tolua_tousertype(L, 1, 0); - faction * f = (faction *) tolua_tousertype(L, 2, 0); + unit *u = (unit *) tolua_tousertype(L, 1, 0); + faction *f = (faction *) tolua_tousertype(L, 2, 0); bufunit(f, u, 0, see_unit, buffer, sizeof(buffer)); tolua_pushstring(L, buffer); return 1; } -static int tolua_settings_get(lua_State * L) +static int tolua_settings_get(lua_State * L) { const char *name = tolua_tostring(L, 1, 0); tolua_pushstring(L, get_param(global.parameters, name)); return 1; } -static int tolua_settings_set(lua_State * L) +static int tolua_settings_set(lua_State * L) { const char *name = tolua_tostring(L, 1, 0); const char *value = tolua_tostring(L, 2, 0); @@ -970,8 +969,7 @@ static int tolua_settings_set(lua_State * L) return 0; } -static void -parse_inifile(lua_State * L, dictionary * d, const char *section) +static void parse_inifile(lua_State * L, dictionary * d, const char *section) { int i; size_t len = strlen(section); @@ -990,18 +988,18 @@ parse_inifile(lua_State * L, dictionary * d, const char *section) lua_rawset(L, -3); } } - - /* special case */ - lua_pushstring(L, "basepath"); + + /* special case */ + lua_pushstring(L, "basepath"); lua_pushstring(L, basepath()); lua_rawset(L, -3); } -int tolua_eressea_open(lua_State * L) +int tolua_eressea_open(lua_State * L) { tolua_open(L); - - /* register user types */ + + /* register user types */ tolua_usertype(L, TOLUA_CAST "spell"); tolua_usertype(L, TOLUA_CAST "spell_list"); tolua_usertype(L, TOLUA_CAST "order"); @@ -1029,7 +1027,8 @@ int tolua_eressea_open(lua_State * L) NULL); tolua_function(L, TOLUA_CAST "create", tolua_alliance_create); } 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_function(L, TOLUA_CAST "__tostring", tolua_get_spell_name); @@ -1088,11 +1087,10 @@ int tolua_eressea_open(lua_State * L) tolua_function(L, TOLUA_CAST "message_unit", tolua_message_unit); tolua_function(L, TOLUA_CAST "message_faction", tolua_message_faction); tolua_function(L, TOLUA_CAST "message_region", tolua_message_region); - - /* scripted monsters */ - tolua_function(L, TOLUA_CAST "spawn_braineaters", - tolua_spawn_braineaters); - + + /* scripted monsters */ + tolua_function(L, TOLUA_CAST "spawn_braineaters", tolua_spawn_braineaters); + 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 "get_turn", &tolua_get_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 "dice_roll", tolua_dice_rand); 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 "update_subscriptions", tolua_update_subscriptions); + tolua_function(L, TOLUA_CAST "remove_empty_units", + 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_owners", tolua_update_owners); tolua_function(L, TOLUA_CAST "learn_skill", tolua_learn_skill); diff --git a/src/gamecode/economy.c b/src/gamecode/economy.c index dd97be767..4097b055f 100644 --- a/src/gamecode/economy.c +++ b/src/gamecode/economy.c @@ -124,14 +124,15 @@ static void recruit_init(void) int income(const unit * u) { switch (old_race(u->race)) { - case RC_FIREDRAGON: - return 150 * u->number; - case RC_DRAGON: - return 1000 * u->number; - case RC_WYRM: - return 5000 * u->number; + case RC_FIREDRAGON: + return 150 * u->number; + case RC_DRAGON: + return 1000 * u->number; + case RC_WYRM: + return 5000 * u->number; + default: + return 20 * u->number; } - return 20 * u->number; } 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)); if (rc->recruitcost) { - int afford = - get_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT, + int afford = get_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT, number * rc->recruitcost) / rc->recruitcost; number = MIN(number, afford); use_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT, @@ -1297,22 +1297,22 @@ static int recruit_archetype(unit * u, order * ord) return n; } else switch (n) { - case ENOMATERIALS: - ADDMSG(&u->faction->msgs, msg_materials_required(u, ord, arch->ctype, - want)); - break; - case ELOWSKILL: - case ENEEDSKILL: - /* no skill, or not enough skill points to build */ - cmistake(u, ord, 50, MSG_PRODUCE); - break; - case EBUILDINGREQ: - ADDMSG(&u->faction->msgs, - msg_feedback(u, u->thisorder, "building_needed", "building", - arch->ctype->btype->_name)); - break; - default: - assert(!"unhandled return value from build() in recruit_archetype"); + case ENOMATERIALS: + ADDMSG(&u->faction->msgs, msg_materials_required(u, ord, arch->ctype, + want)); + break; + case ELOWSKILL: + case ENEEDSKILL: + /* no skill, or not enough skill points to build */ + cmistake(u, ord, 50, MSG_PRODUCE); + break; + case EBUILDINGREQ: + ADDMSG(&u->faction->msgs, + msg_feedback(u, u->thisorder, "building_needed", "building", + arch->ctype->btype->_name)); + break; + default: + assert(!"unhandled return value from build() in recruit_archetype"); } return 0; } @@ -1340,27 +1340,21 @@ void economics(region * r) boolean destroyed = false; if (u->number > 0) { for (ord = u->orders; ord; ord = ord->next) { - switch (get_keyword(ord)) { - case K_DESTROY: - if (!destroyed) { - if (destroy_cmd(u, ord) != 0) - ord = NULL; - destroyed = true; - } - break; - - case K_GIVE: - case K_LIEFERE: - give_cmd(u, ord); - break; - - case K_FORGET: - forget_cmd(u, ord); - break; - + keyword_t kwd = get_keyword(ord); + if (kwd == K_DESTROY) { + if (!destroyed) { + if (destroy_cmd(u, ord) != 0) + ord = NULL; + destroyed = true; + } + } else if (kwd == K_GIVE || kwd == K_LIEFERE) { + give_cmd(u, ord); + } else if (kwd == K_FORGET) { + forget_cmd(u, ord); } - if (u->orders == NULL) + if (u->orders == NULL) { break; + } } } } @@ -1418,24 +1412,24 @@ static void manufacture(unit * u, const item_type * itype, int want) } n = build(u, itype->construction, 0, want); switch (n) { - case ENEEDSKILL: - ADDMSG(&u->faction->msgs, - msg_feedback(u, u->thisorder, "skill_needed", "skill", sk)); - return; - case EBUILDINGREQ: - ADDMSG(&u->faction->msgs, - msg_feedback(u, u->thisorder, "building_needed", "building", - itype->construction->btype->_name)); - return; - case ELOWSKILL: - ADDMSG(&u->faction->msgs, - msg_feedback(u, u->thisorder, "manufacture_skills", - "skill minskill product", sk, minskill, itype->rtype, 1)); - return; - case ENOMATERIALS: - ADDMSG(&u->faction->msgs, msg_materials_required(u, u->thisorder, - itype->construction, want)); - return; + case ENEEDSKILL: + ADDMSG(&u->faction->msgs, + msg_feedback(u, u->thisorder, "skill_needed", "skill", sk)); + return; + case EBUILDINGREQ: + ADDMSG(&u->faction->msgs, + msg_feedback(u, u->thisorder, "building_needed", "building", + itype->construction->btype->_name)); + return; + case ELOWSKILL: + ADDMSG(&u->faction->msgs, + msg_feedback(u, u->thisorder, "manufacture_skills", + "skill minskill product", sk, minskill, itype->rtype, 1)); + return; + case ENOMATERIALS: + ADDMSG(&u->faction->msgs, msg_materials_required(u, u->thisorder, + itype->construction, want)); + return; } if (n > 0) { 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); switch (built) { - case ELOWSKILL: - case ENEEDSKILL: - /* no skill, or not enough skill points to build */ - cmistake(u, u->thisorder, 50, MSG_PRODUCE); - break; - case EBUILDINGREQ: - ADDMSG(&u->faction->msgs, - msg_feedback(u, u->thisorder, "building_needed", "building", - ptype->itype->construction->btype->_name)); - break; - case ECOMPLETE: - assert(0); - break; - case ENOMATERIALS: - /* something missing from the list of materials */ - ADDMSG(&u->faction->msgs, msg_materials_required(u, u->thisorder, - ptype->itype->construction, want)); - return; - break; - default: - i_change(&u->items, ptype->itype, built); - if (want == INT_MAX) - want = built; - ADDMSG(&u->faction->msgs, msg_message("manufacture", - "unit region amount wanted resource", u, u->region, built, want, - ptype->itype->rtype)); - break; + case ELOWSKILL: + case ENEEDSKILL: + /* no skill, or not enough skill points to build */ + cmistake(u, u->thisorder, 50, MSG_PRODUCE); + break; + case EBUILDINGREQ: + ADDMSG(&u->faction->msgs, + msg_feedback(u, u->thisorder, "building_needed", "building", + ptype->itype->construction->btype->_name)); + break; + case ECOMPLETE: + assert(0); + break; + case ENOMATERIALS: + /* something missing from the list of materials */ + ADDMSG(&u->faction->msgs, msg_materials_required(u, u->thisorder, + ptype->itype->construction, want)); + return; + break; + default: + i_change(&u->items, ptype->itype, built); + if (want == INT_MAX) + want = built; + ADDMSG(&u->faction->msgs, msg_message("manufacture", + "unit region amount wanted resource", u, u->region, built, want, + ptype->itype->rtype)); + break; } } @@ -2862,26 +2856,25 @@ static void breed_cmd(unit * u, struct order *ord) } switch (p) { - case P_HERBS: - plant(r, u, m); - break; - case P_TREES: - breedtrees(r, u, m); - break; - default: - if (p != P_ANY) { - rtype = findresourcetype(s, u->faction->locale); - if (rtype == rt_mallornseed || rtype == rt_seed) { - breedtrees(r, u, m); - break; - } else if (rtype != oldresourcetype[R_HORSE]) { - ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_cannotmake", - "")); - break; - } + case P_HERBS: + plant(r, u, m); + break; + case P_TREES: + breedtrees(r, u, m); + break; + default: + if (p != P_ANY) { + rtype = findresourcetype(s, u->faction->locale); + if (rtype == rt_mallornseed || rtype == rt_seed) { + breedtrees(r, u, m); + break; + } else if (rtype != oldresourcetype[R_HORSE]) { + ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_cannotmake", "")); + 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) { - switch (get_keyword(ord)) { - case K_BUY: - buy(u, &buyorders, ord); - trader = true; - break; - case K_SELL: - /* sell returns true if the sale is not limited - * by the region limit */ - limited &= !sell(u, &sellorders, ord); - trader = true; - break; + keyword_t kwd = get_keyword(ord); + if (kwd == K_BUY) { + buy(u, &buyorders, ord); + trader = true; + } else if (kwd == K_SELL) { + /* sell returns true if the sale is not limited + * by the region limit */ + limited &= !sell(u, &sellorders, ord); + trader = true; } } if (trader) { @@ -3479,41 +3470,41 @@ void produce(struct region *r) switch (todo) { - case K_ENTERTAIN: - entertain_cmd(u, u->thisorder); - break; + case K_ENTERTAIN: + entertain_cmd(u, u->thisorder); + break; - case K_WORK: - if (!rule_autowork && do_work(u, u->thisorder, nextworker) == 0) { - assert(nextworker - workers < MAX_WORKERS); - ++nextworker; - } - break; + case K_WORK: + if (!rule_autowork && do_work(u, u->thisorder, nextworker) == 0) { + assert(nextworker - workers < MAX_WORKERS); + ++nextworker; + } + break; - case K_TAX: - tax_cmd(u, u->thisorder, &taxorders); - break; + case K_TAX: + tax_cmd(u, u->thisorder, &taxorders); + break; - case K_STEAL: - steal_cmd(u, u->thisorder, &stealorders); - break; + case K_STEAL: + steal_cmd(u, u->thisorder, &stealorders); + break; - case K_SPY: - spy_cmd(u, u->thisorder); - break; + case K_SPY: + spy_cmd(u, u->thisorder); + break; - case K_SABOTAGE: - sabotage_cmd(u, u->thisorder); - break; + case K_SABOTAGE: + sabotage_cmd(u, u->thisorder); + break; - case K_PLANT: - case K_BREED: - breed_cmd(u, u->thisorder); - break; + case K_PLANT: + case K_BREED: + breed_cmd(u, u->thisorder); + break; - case K_RESEARCH: - research_cmd(u, u->thisorder); - break; + case K_RESEARCH: + research_cmd(u, u->thisorder); + break; } } diff --git a/src/gamecode/laws.c b/src/gamecode/laws.c index 19dd3dbd6..a0c16ada4 100644 --- a/src/gamecode/laws.c +++ b/src/gamecode/laws.c @@ -135,8 +135,8 @@ static int RemoveNMRNewbie(void) static void restart_race(unit * u, const race * rc) { faction *oldf = u->faction; - faction *f = - addfaction(oldf->email, oldf->passw, rc, oldf->locale, oldf->subscription); + faction *f = addfaction(oldf->email, oldf->passw, rc, oldf->locale, + oldf->subscription); unit *nu = addplayer(u->region, f); order **ordp = &u->orders; f->subscription = u->faction->subscription; @@ -306,7 +306,8 @@ static void get_food(region * r) } } 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); } } @@ -419,8 +420,8 @@ static void age_unit(region * r, unit * u) if ((itm->type->flags & ITF_NOTLOST) == 0) { if (itm->type->flags & (ITF_BIG | ITF_ANIMAL | ITF_CURSED)) { ADDMSG(&u->faction->msgs, msg_message("itemcrumble", - "unit region item amount", u, u->region, itm->type->rtype, - itm->number)); + "unit region item amount", + u, u->region, itm->type->rtype, itm->number)); i_free(i_remove(itemp, itm)); continue; } @@ -1056,8 +1057,7 @@ static void transfer_faction(faction * f, faction * f2) for (u = f->units; u;) { un = u->nextF; if (!unit_has_cursed_item(u) - && !has_skill(u, SK_MAGIC) - && !has_skill(u, SK_ALCHEMY)) { + && !has_skill(u, SK_MAGIC) && !has_skill(u, SK_ALCHEMY)) { u_setfaction(u, f2); } u = un; @@ -1358,62 +1358,62 @@ static int ally_cmd(unit * u, struct order *ord) } } switch (keyword) { - case P_NOT: + case P_NOT: + sf->status = 0; + break; + + case NOPARAM: + cmistake(u, ord, 137, MSG_EVENT); + return 0; + + case P_ANY: + if (not_kw == P_NOT) sf->status = 0; - break; + else + sf->status = HELP_ALL; + break; - case NOPARAM: - cmistake(u, ord, 137, MSG_EVENT); - return 0; + case P_TRAVEL: + if (not_kw == P_NOT) + sf->status = sf->status & (HELP_ALL - HELP_TRAVEL); + else + sf->status = sf->status | HELP_TRAVEL; + break; - case P_ANY: - if (not_kw == P_NOT) - sf->status = 0; - else - sf->status = HELP_ALL; - break; + case P_GIVE: + if (not_kw == P_NOT) + sf->status = sf->status & (HELP_ALL - HELP_GIVE); + else + sf->status = sf->status | HELP_GIVE; + break; - case P_TRAVEL: - if (not_kw == P_NOT) - sf->status = sf->status & (HELP_ALL - HELP_TRAVEL); - else - sf->status = sf->status | HELP_TRAVEL; - break; + case P_MONEY: + if (not_kw == P_NOT) + sf->status = sf->status & (HELP_ALL - HELP_MONEY); + else + sf->status = sf->status | HELP_MONEY; + break; - case P_GIVE: - if (not_kw == P_NOT) - sf->status = sf->status & (HELP_ALL - HELP_GIVE); - else - sf->status = sf->status | HELP_GIVE; - break; + case P_FIGHT: + if (not_kw == P_NOT) + sf->status = sf->status & (HELP_ALL - HELP_FIGHT); + else + sf->status = sf->status | HELP_FIGHT; + break; - case P_MONEY: - if (not_kw == P_NOT) - sf->status = sf->status & (HELP_ALL - HELP_MONEY); - else - sf->status = sf->status | HELP_MONEY; - break; + case P_FACTIONSTEALTH: + if (not_kw == P_NOT) + sf->status = sf->status & (HELP_ALL - HELP_FSTEALTH); + else + sf->status = sf->status | HELP_FSTEALTH; + break; - case P_FIGHT: - if (not_kw == P_NOT) - sf->status = sf->status & (HELP_ALL - HELP_FIGHT); - else - sf->status = sf->status | HELP_FIGHT; - break; - - case P_FACTIONSTEALTH: - if (not_kw == P_NOT) - sf->status = sf->status & (HELP_ALL - HELP_FSTEALTH); - else - sf->status = sf->status | HELP_FSTEALTH; - break; - - case P_GUARD: - if (not_kw == P_NOT) - sf->status = sf->status & (HELP_ALL - HELP_GUARD); - else - sf->status = sf->status | HELP_GUARD; - break; + case P_GUARD: + if (not_kw == P_NOT) + sf->status = sf->status & (HELP_ALL - HELP_GUARD); + else + sf->status = sf->status | HELP_GUARD; + break; } sf->status &= HelpMask(); @@ -1536,69 +1536,69 @@ static int display_cmd(unit * u, struct order *ord) skip_token(); switch (getparam(u->faction->locale)) { - case P_BUILDING: - case P_GEBAEUDE: - if (!b) { - cmistake(u, ord, 145, MSG_PRODUCE); - break; - } - if (!fval(u, UFL_OWNER)) { - cmistake(u, ord, 5, MSG_PRODUCE); - break; - } - if (!fval(b->type, BTF_NAMECHANGE) && b->display && b->display[0] != 0) { - cmistake(u, ord, 278, MSG_EVENT); - break; - } - s = &b->display; + case P_BUILDING: + case P_GEBAEUDE: + if (!b) { + cmistake(u, ord, 145, MSG_PRODUCE); break; - - case P_SHIP: - if (!u->ship) { - cmistake(u, ord, 144, MSG_PRODUCE); - break; - } - if (!fval(u, UFL_OWNER)) { - cmistake(u, ord, 12, MSG_PRODUCE); - break; - } - s = &u->ship->display; - break; - - case P_UNIT: - s = &u->display; - break; - - case P_PRIVAT: - { - const char *d = getstrtoken(); - if (d == NULL || *d == 0) { - usetprivate(u, NULL); - } else { - usetprivate(u, d); - } } + if (!fval(u, UFL_OWNER)) { + cmistake(u, ord, 5, MSG_PRODUCE); break; + } + if (!fval(b->type, BTF_NAMECHANGE) && b->display && b->display[0] != 0) { + cmistake(u, ord, 278, MSG_EVENT); + break; + } + s = &b->display; + break; - case P_REGION: - if (!b) { - cmistake(u, ord, 145, MSG_EVENT); - break; - } - if (!fval(u, UFL_OWNER)) { - cmistake(u, ord, 148, MSG_EVENT); - break; - } - if (b != largestbuilding(r, get_cmp_region_owner(), false)) { - cmistake(u, ord, 147, MSG_EVENT); - break; - } - s = &r->display; + case P_SHIP: + if (!u->ship) { + cmistake(u, ord, 144, MSG_PRODUCE); break; + } + if (!fval(u, UFL_OWNER)) { + cmistake(u, ord, 12, MSG_PRODUCE); + break; + } + s = &u->ship->display; + break; - default: - cmistake(u, ord, 110, MSG_EVENT); + case P_UNIT: + s = &u->display; + break; + + case P_PRIVAT: + { + const char *d = getstrtoken(); + if (d == NULL || *d == 0) { + usetprivate(u, NULL); + } else { + usetprivate(u, d); + } + } + break; + + case P_REGION: + if (!b) { + cmistake(u, ord, 145, MSG_EVENT); break; + } + if (!fval(u, UFL_OWNER)) { + cmistake(u, ord, 148, MSG_EVENT); + break; + } + if (b != largestbuilding(r, get_cmp_region_owner(), false)) { + cmistake(u, ord, 147, MSG_EVENT); + break; + } + s = &r->display; + break; + + default: + cmistake(u, ord, 110, MSG_EVENT); + break; } if (s != NULL) { @@ -1669,10 +1669,12 @@ rename_building(unit * u, order * ord, building * b, const char *name) if (owner) { 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)); } else { - ADDMSG(&owner->faction->msgs, msg_message("renamed_building_notseen", + ADDMSG(&owner->faction->msgs, + msg_message("renamed_building_notseen", "building region", b, u->region)); } } @@ -1704,182 +1706,181 @@ static int name_cmd(unit * u, struct order *ord) } switch (p) { - case P_ALLIANCE: - if (foreign == false && f_get_alliance(u->faction)) { - alliance *al = u->faction->alliance; - faction *lead = alliance_get_leader(al); - if (lead == u->faction) { - s = &al->name; - } + case P_ALLIANCE: + if (foreign == false && f_get_alliance(u->faction)) { + alliance *al = u->faction->alliance; + faction *lead = alliance_get_leader(al); + if (lead == u->faction) { + s = &al->name; } - break; - case P_BUILDING: - case P_GEBAEUDE: - if (foreign) { - b = getbuilding(u->region); + } + break; + case P_BUILDING: + case P_GEBAEUDE: + if (foreign) { + b = getbuilding(u->region); + } + + return rename_building(u, ord, b, getstrtoken()); + + case P_FACTION: + if (foreign == true) { + faction *f; + + f = getfaction(); + if (!f) { + cmistake(u, ord, 66, MSG_EVENT); + break; } - - return rename_building(u, ord, b, getstrtoken()); - - case P_FACTION: - if (foreign == true) { - faction *f; - - f = getfaction(); - if (!f) { - cmistake(u, ord, 66, MSG_EVENT); - break; - } - if (f->age < 10) { - cmistake(u, ord, 248, MSG_EVENT); - break; - } else { - const struct locale *lang = locales; - for (; lang; lang = nextlocale(lang)) { - const char *fdname = LOC(lang, "factiondefault"); - size_t fdlen = strlen(fdname); - if (strlen(f->name) >= fdlen - && strncmp(f->name, fdname, fdlen) == 0) { - break; - } - } - if (lang == NULL) { - cmistake(u, ord, 247, MSG_EVENT); + if (f->age < 10) { + cmistake(u, ord, 248, MSG_EVENT); + break; + } else { + const struct locale *lang = locales; + for (; lang; lang = nextlocale(lang)) { + const char *fdname = LOC(lang, "factiondefault"); + size_t fdlen = strlen(fdname); + if (strlen(f->name) >= fdlen && strncmp(f->name, fdname, fdlen) == 0) { break; } } - if (cansee(f, r, u, 0)) { - ADDMSG(&f->msgs, msg_message("renamed_faction_seen", "unit region", u, - r)); - } else { - ADDMSG(&f->msgs, msg_message("renamed_faction_notseen", "", r)); - } - s = &f->name; - } else { - s = &u->faction->name; - } - break; - - case P_SHIP: - if (foreign == true) { - ship *sh = getship(r); - unit *uo; - - if (!sh) { - cmistake(u, ord, 20, MSG_EVENT); + if (lang == NULL) { + cmistake(u, ord, 247, MSG_EVENT); break; - } else { - const struct locale *lang = locales; - for (; lang; lang = nextlocale(lang)) { - const char *sdname = LOC(lang, sh->type->name[0]); - size_t sdlen = strlen(sdname); - if (strlen(sh->name) >= sdlen - && strncmp(sh->name, sdname, sdlen) == 0) { - break; - } + } + } + if (cansee(f, r, u, 0)) { + ADDMSG(&f->msgs, + msg_message("renamed_faction_seen", "unit region", u, r)); + } else { + ADDMSG(&f->msgs, msg_message("renamed_faction_notseen", "", r)); + } + s = &f->name; + } else { + s = &u->faction->name; + } + break; - sdname = LOC(lang, parameters[P_SHIP]); - sdlen = strlen(sdname); - if (strlen(sh->name) >= sdlen - && strncmp(sh->name, sdname, sdlen) == 0) { - break; - } + case P_SHIP: + if (foreign == true) { + ship *sh = getship(r); + unit *uo; - } - if (lang == NULL) { - cmistake(u, ord, 245, MSG_EVENT); + if (!sh) { + cmistake(u, ord, 20, MSG_EVENT); + break; + } else { + const struct locale *lang = locales; + for (; lang; lang = nextlocale(lang)) { + const char *sdname = LOC(lang, sh->type->name[0]); + size_t sdlen = strlen(sdname); + if (strlen(sh->name) >= sdlen + && strncmp(sh->name, sdname, sdlen) == 0) { break; } - } - uo = shipowner(sh); - if (uo) { - if (cansee(uo->faction, r, u, 0)) { - ADDMSG(&uo->faction->msgs, msg_message("renamed_ship_seen", - "ship renamer region", sh, u, r)); - } else { - ADDMSG(&uo->faction->msgs, msg_message("renamed_ship_notseen", - "ship region", sh, r)); - } - } - s = &sh->name; - } else { - if (!u->ship) { - cmistake(u, ord, 144, MSG_PRODUCE); - break; - } - if (!fval(u, UFL_OWNER)) { - cmistake(u, ord, 12, MSG_PRODUCE); - break; - } - s = &u->ship->name; - } - break; - case P_UNIT: - if (foreign == true) { - unit *u2 = getunit(r, u->faction); - - if (!u2 || !cansee(u->faction, r, u2, 0)) { - ADDMSG(&u->faction->msgs, msg_feedback(u, ord, - "feedback_unit_not_found", "")); - break; - } else { - const char *udefault = LOC(u2->faction->locale, "unitdefault"); - size_t udlen = strlen(udefault); - size_t unlen = strlen(u2->name); - if (unlen >= udlen && strncmp(u2->name, udefault, udlen) != 0) { - cmistake(u2, ord, 244, MSG_EVENT); + sdname = LOC(lang, parameters[P_SHIP]); + sdlen = strlen(sdname); + if (strlen(sh->name) >= sdlen + && strncmp(sh->name, sdname, sdlen) == 0) { break; } - } - if (cansee(u2->faction, r, u, 0)) { - ADDMSG(&u2->faction->msgs, msg_message("renamed_seen", - "renamer renamed region", u, u2, r)); - } else { - ADDMSG(&u2->faction->msgs, msg_message("renamed_notseen", - "renamed region", u2, r)); - } - s = &u2->name; - } else { - s = &u->name; - } - break; - case P_REGION: - if (!b) { - cmistake(u, ord, 145, MSG_EVENT); + } + if (lang == NULL) { + cmistake(u, ord, 245, MSG_EVENT); + break; + } + } + uo = shipowner(sh); + if (uo) { + if (cansee(uo->faction, r, u, 0)) { + ADDMSG(&uo->faction->msgs, + msg_message("renamed_ship_seen", "ship renamer region", sh, u, r)); + } else { + ADDMSG(&uo->faction->msgs, + msg_message("renamed_ship_notseen", "ship region", sh, r)); + } + } + s = &sh->name; + } else { + if (!u->ship) { + cmistake(u, ord, 144, MSG_PRODUCE); break; } if (!fval(u, UFL_OWNER)) { - cmistake(u, ord, 148, MSG_EVENT); + cmistake(u, ord, 12, MSG_PRODUCE); break; } + s = &u->ship->name; + } + break; - if (b != largestbuilding(r, get_cmp_region_owner(), false)) { - cmistake(u, ord, 147, MSG_EVENT); - break; - } - s = &r->land->name; - break; + case P_UNIT: + if (foreign == true) { + unit *u2 = getunit(r, u->faction); - case P_GROUP: - { - attrib *a = NULL; - if (fval(u, UFL_GROUP)) - a = a_find(u->attribs, &at_group); - if (a) { - group *g = (group *) a->data.v; - s = &g->name; + if (!u2 || !cansee(u->faction, r, u2, 0)) { + ADDMSG(&u->faction->msgs, msg_feedback(u, ord, + "feedback_unit_not_found", "")); break; } else { - cmistake(u, ord, 109, MSG_EVENT); - break; + const char *udefault = LOC(u2->faction->locale, "unitdefault"); + size_t udlen = strlen(udefault); + size_t unlen = strlen(u2->name); + if (unlen >= udlen && strncmp(u2->name, udefault, udlen) != 0) { + cmistake(u2, ord, 244, MSG_EVENT); + break; + } } + if (cansee(u2->faction, r, u, 0)) { + ADDMSG(&u2->faction->msgs, msg_message("renamed_seen", + "renamer renamed region", u, u2, r)); + } else { + ADDMSG(&u2->faction->msgs, msg_message("renamed_notseen", + "renamed region", u2, r)); + } + s = &u2->name; + } else { + s = &u->name; } + break; + + case P_REGION: + if (!b) { + cmistake(u, ord, 145, MSG_EVENT); break; - default: + } + if (!fval(u, UFL_OWNER)) { + cmistake(u, ord, 148, MSG_EVENT); + break; + } + + if (b != largestbuilding(r, get_cmp_region_owner(), false)) { + cmistake(u, ord, 147, MSG_EVENT); + break; + } + s = &r->land->name; + break; + + case P_GROUP: + { + attrib *a = NULL; + if (fval(u, UFL_GROUP)) + a = a_find(u->attribs, &at_group); + if (a) { + group *g = (group *) a->data.v; + s = &g->name; + break; + } else { cmistake(u, ord, 109, MSG_EVENT); break; + } + } + break; + default: + cmistake(u, ord, 109, MSG_EVENT); + break; } if (s != NULL) { @@ -1898,10 +1899,11 @@ deliverMail(faction * f, region * r, unit * u, const char *s, unit * receiver) u = NULL; } if (!receiver) { /* BOTSCHAFT an PARTEI */ - ADDMSG(&f->msgs, msg_message("regionmessage", "region sender string", r, u, - s)); + ADDMSG(&f->msgs, + msg_message("regionmessage", "region sender string", r, u, s)); } 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)); } } @@ -1917,8 +1919,8 @@ mailunit(region * r, unit * u, int n, struct order *ord, const char *s) } else { /* Immer eine Meldung - sonst könnte man so getarnte EHs enttarnen: * 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", "")); } } @@ -1950,150 +1952,151 @@ static int mail_cmd(unit * u, struct order *ord) do { cont = 0; switch (findparam(s, u->faction->locale)) { - case P_REGION: - /* können alle Einheiten in der Region sehen */ - s = getstrtoken(); - if (!s[0]) { - cmistake(u, ord, 30, MSG_MESSAGE); - break; - } else { - ADDMSG(&r->msgs, msg_message("mail_result", "unit message", u, s)); - return 0; - } - - case P_FACTION: - { - boolean see = false; - - n = getfactionid(); - - for (u2 = r->units; u2; u2 = u2->next) { - if (u2->faction->no == n && seefaction(u->faction, r, u2, 0)) { - see = true; - break; - } - } - - if (see == false) { - cmistake(u, ord, 66, MSG_MESSAGE); - break; - } - - s = getstrtoken(); - if (!s[0]) { - cmistake(u, ord, 30, MSG_MESSAGE); - break; - } - mailfaction(u, n, ord, s); - return 0; - } - - case P_UNIT: - { - boolean see = false; - n = getid(); - - for (u2 = r->units; u2; u2 = u2->next) { - if (u2->no == n && cansee(u->faction, r, u2, 0)) { - see = true; - break; - } - } - - if (see == false) { - ADDMSG(&u->faction->msgs, msg_feedback(u, ord, - "feedback_unit_not_found", "")); - return 0; - } - - s = getstrtoken(); - if (!s[0]) { - cmistake(u, ord, 30, MSG_MESSAGE); - break; - } else { - attrib *a = a_find(u2->attribs, &at_eventhandler); - if (a != NULL) { - event_arg args[3]; - args[0].data.v = (void *)s; - args[0].type = "string"; - args[1].data.v = (void *)u; - args[1].type = "unit"; - args[2].type = NULL; - handle_event(a, "message", args); - } - - mailunit(r, u, n, ord, s); - } - return 0; - } - - case P_BUILDING: - case P_GEBAEUDE: - { - building *b = getbuilding(r); - - if (!b) { - cmistake(u, ord, 6, MSG_MESSAGE); - break; - } - - s = getstrtoken(); - - if (!s[0]) { - cmistake(u, ord, 30, MSG_MESSAGE); - break; - } - - for (u2 = r->units; u2; u2 = u2->next) - freset(u2->faction, FFL_SELECT); - - for (u2 = r->units; u2; u2 = u2->next) { - if (u2->building == b && !fval(u2->faction, FFL_SELECT) - && cansee(u->faction, r, u2, 0)) { - mailunit(r, u, u2->no, ord, s); - fset(u2->faction, FFL_SELECT); - } - } - return 0; - } - - case P_SHIP: - { - ship *sh = getship(r); - - if (!sh) { - cmistake(u, ord, 20, MSG_MESSAGE); - break; - } - - s = getstrtoken(); - - if (!s[0]) { - cmistake(u, ord, 30, MSG_MESSAGE); - break; - } - - for (u2 = r->units; u2; u2 = u2->next) - freset(u2->faction, FFL_SELECT); - - for (u2 = r->units; u2; u2 = u2->next) { - if (u2->ship == sh && !fval(u2->faction, FFL_SELECT) - && cansee(u->faction, r, u2, 0)) { - mailunit(r, u, u2->no, ord, s); - fset(u2->faction, FFL_SELECT); - } - } - return 0; - } - - default: - /* possibly filler token? */ - s = getstrtoken(); - if (s && *s) - cont = 1; + case P_REGION: + /* können alle Einheiten in der Region sehen */ + s = getstrtoken(); + if (!s[0]) { + cmistake(u, ord, 30, MSG_MESSAGE); break; + } else { + ADDMSG(&r->msgs, msg_message("mail_result", "unit message", u, s)); + return 0; + } + + case P_FACTION: + { + boolean see = false; + + n = getfactionid(); + + for (u2 = r->units; u2; u2 = u2->next) { + if (u2->faction->no == n && seefaction(u->faction, r, u2, 0)) { + see = true; + break; + } + } + + if (see == false) { + cmistake(u, ord, 66, MSG_MESSAGE); + break; + } + + s = getstrtoken(); + if (!s[0]) { + cmistake(u, ord, 30, MSG_MESSAGE); + break; + } + mailfaction(u, n, ord, s); + return 0; } - } while (cont); + + case P_UNIT: + { + boolean see = false; + n = getid(); + + for (u2 = r->units; u2; u2 = u2->next) { + if (u2->no == n && cansee(u->faction, r, u2, 0)) { + see = true; + break; + } + } + + if (see == false) { + ADDMSG(&u->faction->msgs, msg_feedback(u, ord, + "feedback_unit_not_found", "")); + return 0; + } + + s = getstrtoken(); + if (!s[0]) { + cmistake(u, ord, 30, MSG_MESSAGE); + break; + } else { + attrib *a = a_find(u2->attribs, &at_eventhandler); + if (a != NULL) { + event_arg args[3]; + args[0].data.v = (void *)s; + args[0].type = "string"; + args[1].data.v = (void *)u; + args[1].type = "unit"; + args[2].type = NULL; + handle_event(a, "message", args); + } + + mailunit(r, u, n, ord, s); + } + return 0; + } + + case P_BUILDING: + case P_GEBAEUDE: + { + building *b = getbuilding(r); + + if (!b) { + cmistake(u, ord, 6, MSG_MESSAGE); + break; + } + + s = getstrtoken(); + + if (!s[0]) { + cmistake(u, ord, 30, MSG_MESSAGE); + break; + } + + for (u2 = r->units; u2; u2 = u2->next) + freset(u2->faction, FFL_SELECT); + + for (u2 = r->units; u2; u2 = u2->next) { + if (u2->building == b && !fval(u2->faction, FFL_SELECT) + && cansee(u->faction, r, u2, 0)) { + mailunit(r, u, u2->no, ord, s); + fset(u2->faction, FFL_SELECT); + } + } + return 0; + } + + case P_SHIP: + { + ship *sh = getship(r); + + if (!sh) { + cmistake(u, ord, 20, MSG_MESSAGE); + break; + } + + s = getstrtoken(); + + if (!s[0]) { + cmistake(u, ord, 30, MSG_MESSAGE); + break; + } + + for (u2 = r->units; u2; u2 = u2->next) + freset(u2->faction, FFL_SELECT); + + for (u2 = r->units; u2; u2 = u2->next) { + if (u2->ship == sh && !fval(u2->faction, FFL_SELECT) + && cansee(u->faction, r, u2, 0)) { + mailunit(r, u, u2->no, ord, s); + fset(u2->faction, FFL_SELECT); + } + } + return 0; + } + + default: + /* possibly filler token? */ + s = getstrtoken(); + if (s && *s) + cont = 1; + break; + } + } + while (cont); cmistake(u, ord, 149, MSG_MESSAGE); return 0; } @@ -2126,8 +2129,8 @@ static int email_cmd(unit * u, struct order *ord) } else { faction *f = u->faction; if (set_email(&f->email, (const char *)s) != 0) { - log_error(("Invalid email address for faction %s: %s\n", itoa36(f->no), - s)); + log_error(("Invalid email address for faction %s: %s\n", + itoa36(f->no), s)); ADDMSG(&f->msgs, msg_message("changemail_invalid", "value", s)); } else { ADDMSG(&f->msgs, msg_message("changemail", "value", f->email)); @@ -2370,29 +2373,29 @@ static boolean display_race(faction * f, unit * u, const race * rc) WARN_STATIC_BUFFER(); switch (rc->attack[a].type) { - case AT_STANDARD: - bytes = - snprintf(bufp, size, "%s (%s)", LOC(f->locale, "attack_standard"), - rc->def_damage); - break; - case AT_NATURAL: - bytes = - snprintf(bufp, size, "%s (%s)", LOC(f->locale, "attack_natural"), - rc->attack[a].data.dice); - break; - case AT_SPELL: - case AT_COMBATSPELL: - case AT_DRAIN_ST: - case AT_DAZZLE: - bytes = snprintf(bufp, size, "%s", LOC(f->locale, "attack_magical")); - break; - case AT_STRUCTURAL: - bytes = - snprintf(bufp, size, "%s (%s)", LOC(f->locale, "attack_structural"), - rc->attack[a].data.dice); - break; - default: - bytes = 0; + case AT_STANDARD: + bytes = + snprintf(bufp, size, "%s (%s)", + LOC(f->locale, "attack_standard"), rc->def_damage); + break; + case AT_NATURAL: + bytes = + snprintf(bufp, size, "%s (%s)", + LOC(f->locale, "attack_natural"), rc->attack[a].data.dice); + break; + case AT_SPELL: + case AT_COMBATSPELL: + case AT_DRAIN_ST: + case AT_DAZZLE: + bytes = snprintf(bufp, size, "%s", LOC(f->locale, "attack_magical")); + break; + case AT_STRUCTURAL: + bytes = + snprintf(bufp, size, "%s (%s)", + LOC(f->locale, "attack_structural"), rc->attack[a].data.dice); + break; + default: + bytes = 0; } if (bytes && wrptr(&bufp, &size, bytes) != 0) @@ -2421,54 +2424,54 @@ static void reshow(unit * u, struct order *ord, const char *s, param_t p) const race *rc; switch (p) { - case P_ZAUBER: - a_removeall(&u->faction->attribs, &at_seenspell); - break; - case P_POTIONS: - skill = effskill(u, SK_ALCHEMY); - c = 0; - for (ptype = potiontypes; ptype != NULL; ptype = ptype->next) { - if (ptype->level * 2 <= skill) { - c += display_potion(u->faction, u, ptype); - } + case P_ZAUBER: + a_removeall(&u->faction->attribs, &at_seenspell); + break; + case P_POTIONS: + skill = effskill(u, SK_ALCHEMY); + c = 0; + for (ptype = potiontypes; ptype != NULL; ptype = ptype->next) { + if (ptype->level * 2 <= skill) { + c += display_potion(u->faction, u, ptype); } - if (c == 0) - cmistake(u, ord, 285, MSG_EVENT); - break; - case NOPARAM: - /* check if it's an item */ - itype = finditemtype(s, u->faction->locale); - if (itype != NULL) { - ptype = resource2potion(item2resource(itype)); - if (ptype != NULL) { - if (display_potion(u->faction, u, ptype)) - break; - } else { - if (display_item(u->faction, u, itype)) - break; - } - } - /* try for a spell */ - sp = get_spellfromtoken(u, s, u->faction->locale); - if (sp != NULL && u_hasspell(u, sp)) { - attrib *a = a_find(u->faction->attribs, &at_seenspell); - while (a != NULL && a->type == &at_seenspell && a->data.v != sp) - a = a->next; - if (a != NULL) - a_remove(&u->faction->attribs, a); - break; - } - /* last, check if it's a race. */ - rc = findrace(s, u->faction->locale); - if (rc != NULL) { - if (display_race(u->faction, u, rc)) + } + if (c == 0) + cmistake(u, ord, 285, MSG_EVENT); + break; + case NOPARAM: + /* check if it's an item */ + itype = finditemtype(s, u->faction->locale); + if (itype != NULL) { + ptype = resource2potion(item2resource(itype)); + if (ptype != NULL) { + if (display_potion(u->faction, u, ptype)) + break; + } else { + if (display_item(u->faction, u, itype)) break; } - cmistake(u, ord, 21, MSG_EVENT); - break; - default: - cmistake(u, ord, 222, MSG_EVENT); + } + /* try for a spell */ + sp = get_spellfromtoken(u, s, u->faction->locale); + if (sp != NULL && u_hasspell(u, sp)) { + attrib *a = a_find(u->faction->attribs, &at_seenspell); + while (a != NULL && a->type == &at_seenspell && a->data.v != sp) + a = a->next; + if (a != NULL) + a_remove(&u->faction->attribs, a); break; + } + /* last, check if it's a race. */ + rc = findrace(s, u->faction->locale); + if (rc != NULL) { + if (display_race(u->faction, u, rc)) + break; + } + cmistake(u, ord, 21, MSG_EVENT); + break; + default: + cmistake(u, ord, 222, MSG_EVENT); + break; } } @@ -2482,7 +2485,8 @@ static int promotion_cmd(unit * u, struct order *ord) } 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))); 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); if (people > money) { - ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "heroes_cost", "cost have", - people, money)); + ADDMSG(&u->faction->msgs, + msg_feedback(u, ord, "heroes_cost", "cost have", people, money)); return 0; } use_pooled(u, i_silver->rtype, GET_ALL, people); @@ -2571,38 +2575,38 @@ static int status_cmd(unit * u, struct order *ord) param = getstrtoken(); switch (findparam(param, u->faction->locale)) { - case P_NOT: - setstatus(u, ST_AVOID); - break; - case P_BEHIND: - setstatus(u, ST_BEHIND); - break; - case P_FLEE: - setstatus(u, ST_FLEE); - break; - case P_CHICKEN: - setstatus(u, ST_CHICKEN); - break; - case P_AGGRO: - setstatus(u, ST_AGGRO); - break; - case P_VORNE: + case P_NOT: + setstatus(u, ST_AVOID); + break; + case P_BEHIND: + setstatus(u, ST_BEHIND); + break; + case P_FLEE: + setstatus(u, ST_FLEE); + break; + case P_CHICKEN: + setstatus(u, ST_CHICKEN); + break; + case P_AGGRO: + setstatus(u, ST_AGGRO); + break; + case P_VORNE: + setstatus(u, ST_FIGHT); + break; + case P_HELP: + if (getparam(u->faction->locale) == P_NOT) { + fset(u, UFL_NOAID); + } else { + freset(u, UFL_NOAID); + } + break; + default: + if (param[0]) { + add_message(&u->faction->msgs, + msg_feedback(u, ord, "unknown_status", "")); + } else { setstatus(u, ST_FIGHT); - break; - case P_HELP: - if (getparam(u->faction->locale) == P_NOT) { - fset(u, UFL_NOAID); - } else { - freset(u, UFL_NOAID); - } - break; - default: - if (param[0]) { - add_message(&u->faction->msgs, - msg_feedback(u, ord, "unknown_status", "")); - } else { - setstatus(u, ST_FIGHT); - } + } } return 0; } @@ -2710,7 +2714,8 @@ static int guard_on_cmd(unit * u, struct order *ord) } else { if (fval(u, UFL_MOVED)) { 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); } else { /* 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) || get_captain(sh) == NULL)) { /* Schiff nicht seetüchtig */ - float dmg = - get_param_flt(global.parameters, "rules.ship.damage.nocrewocean", + float dmg = get_param_flt(global.parameters, + "rules.ship.damage.nocrewocean", 0.30F); damage_ship(sh, dmg); } if (shipowner(sh) == NULL) { - float dmg = - get_param_flt(global.parameters, "rules.ship.damage.nocrew", 0.05F); + float dmg = get_param_flt(global.parameters, "rules.ship.damage.nocrew", + 0.05F); damage_ship(sh, dmg); } } @@ -2868,26 +2873,31 @@ static void reorder(void) cmistake(u, ord, 10, MSG_EVENT); } else { switch (p) { - case P_AFTER: + case P_AFTER: + *up = u->next; + u->next = v->next; + v->next = u; + fset(u, UFL_MARK); + sorted = true; + break; + case P_BEFORE: + if (fval(v, UFL_OWNER)) { + cmistake(v, ord, 261, MSG_EVENT); + } else { + unit **vp = &r->units; + while (*vp != v) + vp = &(*vp)->next; + *vp = u; *up = u->next; - u->next = v->next; - v->next = u; - break; - case P_BEFORE: - if (fval(v, UFL_OWNER)) { - cmistake(v, ord, 261, MSG_EVENT); - } else { - unit **vp = &r->units; - while (*vp != v) - vp = &(*vp)->next; - *vp = u; - *up = u->next; - u->next = v; - } - break; + u->next = v; + } + fset(u, UFL_MARK); + sorted = true; + break; + default: + /* TODO: syntax error message? */ + break; } - fset(u, UFL_MARK); - sorted = true; } break; } @@ -2898,8 +2908,9 @@ static void reorder(void) } if (sorted) { unit *u; - for (u = r->units; u; u = u->next) + for (u = r->units; u; u = u->next) { freset(u, UFL_MARK); + } } } } @@ -2973,109 +2984,109 @@ static int renumber_cmd(unit * u, order * ord) s = getstrtoken(); switch (findparam(s, u->faction->locale)) { - case P_FACTION: - s = getstrtoken(); - if (s && *s) { - int id = atoi36((const char *)s); - attrib *a = a_find(f->attribs, &at_number); - if (!a) - a = a_add(&f->attribs, a_new(&at_number)); - a->data.i = id; - } - break; + case P_FACTION: + s = getstrtoken(); + if (s && *s) { + int id = atoi36((const char *)s); + attrib *a = a_find(f->attribs, &at_number); + if (!a) + a = a_add(&f->attribs, a_new(&at_number)); + a->data.i = id; + } + break; - case P_UNIT: - s = getstrtoken(); - if (s == NULL || *s == 0) { - i = newunitid(); - } else { - i = atoi36((const char *)s); - if (i <= 0 || i > MAX_UNIT_NR) { - cmistake(u, ord, 114, MSG_EVENT); - break; - } - - if (forbiddenid(i)) { - cmistake(u, ord, 116, MSG_EVENT); - break; - } - - if (findunitg(i, u->region)) { - cmistake(u, ord, 115, MSG_EVENT); - break; - } - } - uunhash(u); - if (!ualias(u)) { - attrib *a = a_add(&u->attribs, a_new(&at_alias)); - a->data.i = -u->no; - } - u->no = i; - uhash(u); - break; - - case P_SHIP: - if (!u->ship) { - cmistake(u, ord, 144, MSG_EVENT); + case P_UNIT: + s = getstrtoken(); + if (s == NULL || *s == 0) { + i = newunitid(); + } else { + i = atoi36((const char *)s); + if (i <= 0 || i > MAX_UNIT_NR) { + cmistake(u, ord, 114, MSG_EVENT); break; } - if (u->ship->coast != NODIRECTION) { + + if (forbiddenid(i)) { cmistake(u, ord, 116, MSG_EVENT); break; } - if (!fval(u, UFL_OWNER)) { - cmistake(u, ord, 146, MSG_EVENT); - break; - } - s = getstrtoken(); - if (s == NULL || *s == 0) { - i = newcontainerid(); - } else { - i = atoi36((const char *)s); - if (i <= 0 || i > MAX_CONTAINER_NR) { - cmistake(u, ord, 114, MSG_EVENT); - break; - } - if (findship(i) || findbuilding(i)) { - cmistake(u, ord, 115, MSG_EVENT); - break; - } - } - sunhash(u->ship); - u->ship->no = i; - shash(u->ship); - break; - case P_BUILDING: - case P_GEBAEUDE: - if (!u->building) { - cmistake(u, ord, 145, MSG_EVENT); - break; - } - if (!fval(u, UFL_OWNER)) { - cmistake(u, ord, 148, MSG_EVENT); - break; - } - s = getstrtoken(); - if (*s == 0) { - i = newcontainerid(); - } else { - i = atoi36((const char *)s); - if (i <= 0 || i > MAX_CONTAINER_NR) { - cmistake(u, ord, 114, MSG_EVENT); - break; - } - if (findship(i) || findbuilding(i)) { - cmistake(u, ord, 115, MSG_EVENT); - break; - } - } - bunhash(u->building); - u->building->no = i; - bhash(u->building); - break; - default: - cmistake(u, ord, 239, MSG_EVENT); + if (findunitg(i, u->region)) { + cmistake(u, ord, 115, MSG_EVENT); + break; + } + } + uunhash(u); + if (!ualias(u)) { + attrib *a = a_add(&u->attribs, a_new(&at_alias)); + a->data.i = -u->no; + } + u->no = i; + uhash(u); + break; + + case P_SHIP: + if (!u->ship) { + cmistake(u, ord, 144, MSG_EVENT); + break; + } + if (u->ship->coast != NODIRECTION) { + cmistake(u, ord, 116, MSG_EVENT); + break; + } + if (!fval(u, UFL_OWNER)) { + cmistake(u, ord, 146, MSG_EVENT); + break; + } + s = getstrtoken(); + if (s == NULL || *s == 0) { + i = newcontainerid(); + } else { + i = atoi36((const char *)s); + if (i <= 0 || i > MAX_CONTAINER_NR) { + cmistake(u, ord, 114, MSG_EVENT); + break; + } + if (findship(i) || findbuilding(i)) { + cmistake(u, ord, 115, MSG_EVENT); + break; + } + } + sunhash(u->ship); + u->ship->no = i; + shash(u->ship); + break; + case P_BUILDING: + case P_GEBAEUDE: + if (!u->building) { + cmistake(u, ord, 145, MSG_EVENT); + break; + } + if (!fval(u, UFL_OWNER)) { + cmistake(u, ord, 148, MSG_EVENT); + break; + } + s = getstrtoken(); + if (*s == 0) { + i = newcontainerid(); + } else { + i = atoi36((const char *)s); + if (i <= 0 || i > MAX_CONTAINER_NR) { + cmistake(u, ord, 114, MSG_EVENT); + break; + } + if (findship(i) || findbuilding(i)) { + cmistake(u, ord, 115, MSG_EVENT); + break; + } + } + bunhash(u->building); + u->building->no = i; + bhash(u->building); + break; + + default: + cmistake(u, ord, 239, MSG_EVENT); } return 0; } @@ -3118,8 +3129,8 @@ static building *age_building(building * b) } if (unicorns) { ADDMSG(&u->faction->msgs, msg_message("scunicorn", - "unit amount rtype", u, unicorns, - olditemtype[I_ELVENHORSE]->rtype)); + "unit amount rtype", + u, unicorns, olditemtype[I_ELVENHORSE]->rtype)); } } } @@ -3141,8 +3152,8 @@ static building *age_building(building * b) /* the mage reactivates the circle */ c = create_curse(mage, &rt->attribs, ct_astralblock, (float)MAX(1, sk), MAX(1, sk / 2), effect, 0); - ADDMSG(&r->msgs, msg_message("astralshield_activate", - "region unit", r, mage)); + ADDMSG(&r->msgs, + msg_message("astralshield_activate", "region unit", r, mage)); } } else if (mage != NULL) { int sk = effskill(mage, SK_MAGIC); @@ -3364,13 +3375,15 @@ static void new_units(void) if (err) { if (err == 1) { - ADDMSG(&u->faction->msgs, msg_feedback(u, makeord, - "too_many_units_in_alliance", "allowed", - maxunits(u->faction))); + ADDMSG(&u->faction->msgs, + msg_feedback(u, makeord, + "too_many_units_in_alliance", + "allowed", maxunits(u->faction))); } else { - ADDMSG(&u->faction->msgs, msg_feedback(u, makeord, - "too_many_units_in_faction", "allowed", - maxunits(u->faction))); + ADDMSG(&u->faction->msgs, + msg_feedback(u, makeord, + "too_many_units_in_faction", + "allowed", maxunits(u->faction))); } ordp = &makeord->next; @@ -3436,27 +3449,27 @@ void check_long_orders(unit * u) keyword_t longorder = get_keyword(ord); if (otherorder != MAXKEYWORDS) { switch (longorder) { - case K_CAST: - if (otherorder != longorder) { - cmistake(u, ord, 52, MSG_EVENT); - } - break; - case K_BUY: - if (otherorder == K_SELL) { - otherorder = K_BUY; - } else { - cmistake(u, ord, 52, MSG_EVENT); - } - break; - case K_SELL: - if (otherorder != K_SELL && otherorder != K_BUY) { - cmistake(u, ord, 52, MSG_EVENT); - } - break; - case K_WEREWOLF: - /* don't know what WEREWOLF does... */ - default: + case K_CAST: + if (otherorder != longorder) { cmistake(u, ord, 52, MSG_EVENT); + } + break; + case K_BUY: + if (otherorder == K_SELL) { + otherorder = K_BUY; + } else { + cmistake(u, ord, 52, MSG_EVENT); + } + break; + case K_SELL: + if (otherorder != K_SELL && otherorder != K_BUY) { + cmistake(u, ord, 52, MSG_EVENT); + } + break; + case K_WEREWOLF: + /* don't know what WEREWOLF does... */ + default: + cmistake(u, ord, 52, MSG_EVENT); } } else { otherorder = longorder; @@ -3503,37 +3516,39 @@ static void setdefaults(unit * u) } else { keyword_t keyword = get_keyword(ord); switch (keyword) { - /* Wenn gehandelt wird, darf kein langer Befehl ausgeführt - * werden. Da Handel erst nach anderen langen Befehlen kommt, - * muß das vorher abgefangen werden. Wir merken uns also - * hier, ob die Einheit handelt. */ - case K_BUY: - case K_SELL: - /* Wenn die Einheit handelt, muß der Default-Befehl gelöscht - * werden. */ - trade = true; - break; + /* Wenn gehandelt wird, darf kein langer Befehl ausgeführt + * werden. Da Handel erst nach anderen langen Befehlen kommt, + * muß das vorher abgefangen werden. Wir merken uns also + * hier, ob die Einheit handelt. */ + case K_BUY: + case K_SELL: + /* Wenn die Einheit handelt, muß der Default-Befehl gelöscht + * werden. */ + trade = true; + break; - case K_CAST: - /* dient dazu, das neben Zaubern kein weiterer Befehl - * ausgeführt werden kann, Zaubern ist ein kurzer Befehl */ - set_order(&u->thisorder, NULL); - break; + case K_CAST: + /* dient dazu, das neben Zaubern kein weiterer Befehl + * ausgeführt werden kann, Zaubern ist ein kurzer Befehl */ + set_order(&u->thisorder, NULL); + break; - case K_WEREWOLF: - set_order(&u->thisorder, copy_order(ord)); - break; + case K_WEREWOLF: + set_order(&u->thisorder, copy_order(ord)); + break; - /* Wird je diese Ausschliesslichkeit aufgehoben, muss man aufpassen - * mit der Reihenfolge von Kaufen, Verkaufen etc., damit es Spielern - * nicht moeglich ist, Schulden zu machen. */ + /* Wird je diese Ausschliesslichkeit aufgehoben, muss man aufpassen + * mit der Reihenfolge von Kaufen, Verkaufen etc., damit es Spielern + * nicht moeglich ist, Schulden zu machen. */ + default: + break; } } } - if (hunger) + if (hunger) { return; - + } /* Wenn die Einheit handelt, muß der Default-Befehl gelöscht * werden. */ @@ -3578,18 +3593,20 @@ static double heal_factor(const unit * u) { static float elf_regen = -1; switch (old_race(u->race)) { - case RC_TROLL: - case RC_DAEMON: - return 1.5; - case RC_GOBLIN: - return 2.0; - case RC_ELF: - if (elf_regen < 0) - elf_regen = get_param_flt(u->race->parameters, "regen.forest", 1.0F); - if (elf_regen != 1.0 && r_isforest(u->region)) { - return elf_regen; - } - return 1.0; + case RC_TROLL: + case RC_DAEMON: + return 1.5; + case RC_GOBLIN: + return 2.0; + case RC_ELF: + if (elf_regen < 0) + elf_regen = get_param_flt(u->race->parameters, "regen.forest", 1.0F); + if (elf_regen != 1.0 && r_isforest(u->region)) { + return elf_regen; + } + return 1.0; + default: + return 1.0; } return 1.0; } @@ -3630,8 +3647,8 @@ static void monthly_healing(void) if (fval(u, UFL_HUNGER)) continue; - if (fval(r->terrain, SEA_REGION) && u->ship == NULL && !(canswim(u) - || canfly(u))) { + if (fval(r->terrain, SEA_REGION) && u->ship == NULL + && !(canswim(u) || canfly(u))) { continue; } diff --git a/src/gamecode/study.c b/src/gamecode/study.c index 48ac70971..7138a81b7 100644 --- a/src/gamecode/study.c +++ b/src/gamecode/study.c @@ -104,9 +104,7 @@ boolean is_migrant(unit * u) /* ------------------------------------------------------------- */ boolean magic_lowskill(unit * u) { - if (u->race == new_race[RC_TOAD]) - return true; - return false; + return (u->race == new_race[RC_TOAD]) ? true : false; } /* ------------------------------------------------------------- */ @@ -121,23 +119,22 @@ int study_cost(unit * u, skill_t sk) sprintf(buffer, "skills.cost.%s", skillnames[sk]); cost[sk] = get_param_int(global.parameters, buffer, -1); } - if (cost[sk] >= 0) + if (cost[sk] >= 0) { return cost[sk]; - + } switch (sk) { - case SK_SPY: - return 100; - break; - case SK_TACTICS: - case SK_HERBALISM: - case SK_ALCHEMY: - return 200; - break; - case SK_MAGIC: /* Die Magiekosten betragen 50+Summe(50*Stufe) */ - /* 'Stufe' ist dabei die nächste zu erreichende Stufe */ - stufe = 1 + get_level(u, SK_MAGIC); - return k * (1 + ((stufe + 1) * stufe / 2)); - break; + case SK_SPY: + return 100; + case SK_TACTICS: + case SK_HERBALISM: + case SK_ALCHEMY: + return 200; + case SK_MAGIC: /* Die Magiekosten betragen 50+Summe(50*Stufe) */ + /* 'Stufe' ist dabei die nächste zu erreichende Stufe */ + stufe = 1 + get_level(u, SK_MAGIC); + return k * (1 + ((stufe + 1) * stufe / 2)); + default: + return 0; } return 0; } diff --git a/src/kernel/build.c b/src/kernel/build.c index 7ae38fe48..e75883d8d 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -951,19 +951,19 @@ build_building(unit * u, const building_type * btype, int want, order * ord) built = build(u, btype->construction, built, n); switch (built) { - case ECOMPLETE: - /* the building is already complete */ - cmistake(u, ord, 4, MSG_PRODUCE); - return; - case ENOMATERIALS: - ADDMSG(&u->faction->msgs, msg_materials_required(u, ord, - btype->construction, want)); - return; - case ELOWSKILL: - case ENEEDSKILL: - /* no skill, or not enough skill points to build */ - cmistake(u, ord, 50, MSG_PRODUCE); - return; + case ECOMPLETE: + /* the building is already complete */ + cmistake(u, ord, 4, MSG_PRODUCE); + return; + case ENOMATERIALS: + ADDMSG(&u->faction->msgs, msg_materials_required(u, ord, + btype->construction, want)); + return; + case ELOWSKILL: + case ENEEDSKILL: + /* no skill, or not enough skill points to build */ + cmistake(u, ord, 50, MSG_PRODUCE); + return; } /* 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) { order *ord; for (ord = uc->orders; ord; ord = ord->next) { - switch (get_keyword(ord)) { - case K_CONTACT: - contact_cmd(uc, ord, lasttry); - break; + keyword_t kwd = get_keyword(ord); + if (kwd == K_CONTACT) { + contact_cmd(uc, ord, lasttry); } } } @@ -1349,37 +1348,37 @@ void do_misc(region * r, boolean lasttry) id = getid(); switch (p) { - case P_BUILDING: - case P_GEBAEUDE: - if (u->building && u->building->no == id) - break; - if (enter_building(u, ord, id, lasttry)) { - unit *ub; - for (ub = u; ub; ub = ub->next) { - if (ub->building == u->building) { - ulast = ub; - } + case P_BUILDING: + case P_GEBAEUDE: + if (u->building && u->building->no == id) + break; + if (enter_building(u, ord, id, lasttry)) { + unit *ub; + for (ub = u; ub; ub = ub->next) { + if (ub->building == u->building) { + ulast = ub; } } - break; + } + break; - case P_SHIP: - if (u->ship && u->ship->no == id) - break; - if (enter_ship(u, ord, id, lasttry)) { - unit *ub; - ulast = u; - for (ub = u; ub; ub = ub->next) { - if (ub->ship == u->ship) { - ulast = ub; - } + case P_SHIP: + if (u->ship && u->ship->no == id) + break; + if (enter_ship(u, ord, id, lasttry)) { + unit *ub; + ulast = u; + for (ub = u; ub; ub = ub->next) { + if (ub->ship == u->ship) { + ulast = ub; } } - break; + } + break; - default: - if (lasttry) - cmistake(u, ord, 79, MSG_MOVE); + default: + if (lasttry) + cmistake(u, ord, 79, MSG_MOVE); } if (ulast != NULL) { diff --git a/src/kernel/config.c b/src/kernel/config.c index 2962b9a7f..adaba27db 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -587,15 +587,11 @@ int skill_limit(faction * f, skill_t sk) return fl; } } - switch (sk) { - case SK_MAGIC: - m = max_magicians(f); - break; - case SK_ALCHEMY: - m = - get_param_int(global.parameters, "rules.maxskills.alchemy", - MAXALCHEMISTS); - break; + if (sk == SK_MAGIC) { + m = max_magicians(f); + } else if (sk == SK_ALCHEMY) { + m = get_param_int(global.parameters, "rules.maxskills.alchemy", + MAXALCHEMISTS); } return m; } @@ -607,8 +603,9 @@ int count_skill(faction * f, skill_t sk) for (u = f->units; u; u = u->nextF) { if (has_skill(u, sk)) { - if (!is_familiar(u)) + if (!is_familiar(u)) { n += u->number; + } } } 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) { const char *s = getstrtoken(); + param_t param; /* 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 * nummer suchen, doch dort steht bei temp-units nur "temp" drinnen! */ - switch (findparam(s, f->locale)) { - case P_TEMP: - return read_newunitid(f, r); + param = findparam(s, f->locale); + if (param == P_TEMP) { + return read_newunitid(f, r); } if (!s || *s == 0) return -1; @@ -2492,16 +2490,19 @@ unsigned int guard_flags(const unit * u) flags |= GUARD_RECRUIT; #endif switch (old_race(u->race)) { - case RC_ELF: - if (u->faction->race != u->race) - break; - /* else fallthrough */ - case RC_TREEMAN: - flags |= GUARD_TREES; - break; - case RC_IRONKEEPER: - flags = GUARD_MINING; + case RC_ELF: + if (u->faction->race != u->race) 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; } @@ -2932,11 +2933,11 @@ message *movement_error(unit * u, const char *token, order * ord, { direction_t d; switch (error_code) { - case E_MOVE_BLOCKED: - d = finddirection(token, u->faction->locale); - return msg_message("moveblocked", "unit direction", u, d); - case E_MOVE_NOREGION: - return msg_feedback(u, ord, "unknowndirection", "dirname", token); + case E_MOVE_BLOCKED: + d = finddirection(token, u->faction->locale); + return msg_message("moveblocked", "unit direction", u, d); + case E_MOVE_NOREGION: + return msg_feedback(u, ord, "unknowndirection", "dirname", token); } return NULL; } @@ -2953,24 +2954,24 @@ int movewhere(const unit * u, const char *token, region * r, region ** resultp) d = finddirection(token, u->faction->locale); switch (d) { - case D_PAUSE: - *resultp = r; - break; + case D_PAUSE: + *resultp = r; + break; - case NODIRECTION: - r2 = find_special_direction(r, token, u->faction->locale); - if (r2 == NULL) { - return E_MOVE_NOREGION; - } - *resultp = r2; - break; + case NODIRECTION: + r2 = find_special_direction(r, token, u->faction->locale); + if (r2 == NULL) { + return E_MOVE_NOREGION; + } + *resultp = r2; + break; - default: - r2 = rconnect(r, d); - if (r2 == NULL || move_blocked(u, r, r2)) { - return E_MOVE_BLOCKED; - } - *resultp = r2; + default: + r2 = rconnect(r, d); + if (r2 == NULL || move_blocked(u, r, r2)) { + return E_MOVE_BLOCKED; + } + *resultp = r2; } return E_MOVE_OK; } diff --git a/src/kernel/magic.c b/src/kernel/magic.c index 8bfdd4760..fdc206731 100644 --- a/src/kernel/magic.c +++ b/src/kernel/magic.c @@ -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 * level multipliziert werden */ switch (sp->components[k].cost) { - case SPC_LEVEL: - case SPC_LINEAR: - itemanz *= level; - break; - case SPC_FIX: - default: - break; + case SPC_LEVEL: + case SPC_LINEAR: + itemanz *= level; + break; + case SPC_FIX: + default: + break; } 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; switch (objtyp) { - case TYP_UNIT: - { - int at, pa = 0; - skill *sv; - unit *u = (unit *) obj; + case TYP_UNIT: + { + int at, pa = 0; + skill *sv; + 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) { - int sk = effskill(u, sv->id); - if (pa < sk) - pa = sk; - } - - /* Contest */ - probability = 0.05 * (10 + pa - at); - - probability += magic_resistance((unit *) obj); - break; + for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) { + int sk = effskill(u, sv->id); + if (pa < sk) + pa = sk; } - case TYP_REGION: - /* Bonus durch Zauber */ - probability += - 0.01 * get_curseeffect(((region *) obj)->attribs, C_RESIST_MAGIC, 0); - break; + /* Contest */ + probability = 0.05 * (10 + pa - at); - case TYP_BUILDING: - /* Bonus durch Zauber */ - probability += - 0.01 * get_curseeffect(((building *) obj)->attribs, C_RESIST_MAGIC, 0); + probability += magic_resistance((unit *) obj); + break; + } - /* Bonus durch Typ */ - probability += 0.01 * ((building *) obj)->type->magres; + case TYP_REGION: + /* 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 Zauber */ - probability += - 0.01 * get_curseeffect(((ship *) obj)->attribs, C_RESIST_MAGIC, 0); - break; + /* Bonus durch Typ */ + probability += 0.01 * ((building *) obj)->type->magres; + + 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); @@ -1348,86 +1348,86 @@ static void do_fumble(castorder * co) ADDMSG(&u->faction->msgs, msg_message("patzer", "unit region spell", u, r, sp)); switch (rng_int() % 10) { - case 0: - /* wenn vorhanden spezieller Patzer, ansonsten nix */ - if (sp->patzer) - sp->patzer(co); - else - patzer(co); - break; + case 0: + /* wenn vorhanden spezieller Patzer, ansonsten nix */ + if (sp->patzer) + sp->patzer(co); + else + patzer(co); + break; - case 1: - /* Kröte */ - { - /* one or two things will happen: the toad changes her race back, - * and may or may not get toadslime. - * 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 *trestore = trigger_changerace(u, u->race, u->irace); + case 1: + /* Kröte */ + { + /* one or two things will happen: the toad changes her race back, + * and may or may not get toadslime. + * 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 *trestore = trigger_changerace(u, u->race, u->irace); - if (chance(0.7)) { - const item_type *it_toadslime = it_find("toadslime"); - if (it_toadslime != NULL) { - t_add(&trestore, trigger_giveitem(u, it_toadslime, 1)); - } + if (chance(0.7)) { + const item_type *it_toadslime = it_find("toadslime"); + if (it_toadslime != NULL) { + 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: - /* temporärer Stufenverlust */ - duration = MAX(rng_int() % level / 2, 2); - effect = -0.5 * level; - c = - create_curse(u, &u->attribs, ct_find("skillmod"), (float)level, - duration, effect, 1); - c->data.i = SK_MAGIC; - ADDMSG(&u->faction->msgs, msg_message("patzer2", "unit region", u, r)); - break; - 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; + 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 5: - case 6: - /* Spruch gelingt, aber alle Magiepunkte weg */ - if (sp->sp_function == NULL) { - log_error(("spell '%s' has no function.\n", sp->sname)); - } else { - ((nspell_f) sp->sp_function) (co); - } - set_spellpoints(u, 0); - ADDMSG(&u->faction->msgs, msg_message("patzer4", "unit region spell", - u, r, sp)); - break; + case 2: + /* temporärer Stufenverlust */ + duration = MAX(rng_int() % level / 2, 2); + effect = -0.5 * level; + c = + create_curse(u, &u->attribs, ct_find("skillmod"), (float)level, + duration, effect, 1); + c->data.i = SK_MAGIC; + ADDMSG(&u->faction->msgs, msg_message("patzer2", "unit region", u, r)); + break; + 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 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); + case 5: + case 6: + /* Spruch gelingt, aber alle Magiepunkte weg */ + if (sp->sp_function == NULL) { + log_error(("spell '%s' has no function.\n", sp->sname)); + } else { + ((nspell_f) sp->sp_function) (co); + } + set_spellpoints(u, 0); + ADDMSG(&u->faction->msgs, msg_message("patzer4", "unit region spell", + u, r, sp)); + break; + + 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; @@ -1588,16 +1588,16 @@ verify_unit(region * r, unit * mage, const spell * sp, spllprm * spobj, { unit *u = NULL; switch (spobj->typ) { - case SPP_UNIT: - u = findunit(spobj->data.i); - break; - case SPP_TEMP: - u = findnewunit(r, mage->faction, spobj->data.i); - if (u == NULL) - u = findnewunit(mage->region, mage->faction, spobj->data.i); - break; - default: - assert(!"shouldn't happen, this"); + case SPP_UNIT: + u = findunit(spobj->data.i); + break; + case SPP_TEMP: + u = findnewunit(r, mage->faction, spobj->data.i); + if (u == NULL) + u = findnewunit(mage->region, mage->faction, spobj->data.i); + break; + default: + assert(!"shouldn't happen, this"); } if (u != NULL && (sp->sptyp & SEARCHLOCAL)) { if (u->region != r) @@ -1654,21 +1654,21 @@ verify_targets(castorder * co, int *invalid, int *resist, int *success) spllprm *spobj = sa->param[i]; switch (spobj->typ) { - case SPP_TEMP: - case SPP_UNIT: - if (!verify_unit(target_r, mage, sp, spobj, co->order)) - ++ * invalid; - break; - case SPP_BUILDING: - if (!verify_building(target_r, mage, sp, spobj, co->order)) - ++ * invalid; - break; - case SPP_SHIP: - if (!verify_ship(target_r, mage, sp, spobj, co->order)) - ++ * invalid; - break; - default: - break; + case SPP_TEMP: + case SPP_UNIT: + if (!verify_unit(target_r, mage, sp, spobj, co->order)) + ++ * invalid; + break; + case SPP_BUILDING: + if (!verify_building(target_r, mage, sp, spobj, co->order)) + ++ * invalid; + break; + case SPP_SHIP: + if (!verify_ship(target_r, mage, sp, spobj, co->order)) + ++ * invalid; + break; + default: + break; } } @@ -1683,77 +1683,76 @@ verify_targets(castorder * co, int *invalid, int *resist, int *success) if (spobj->flag == TARGET_NOTFOUND) continue; switch (spobj->typ) { - case SPP_TEMP: - case SPP_UNIT: - u = spobj->data.u; + case SPP_TEMP: + case SPP_UNIT: + u = spobj->data.u; - if ((sp->sptyp & TESTRESISTANCE) - && target_resists_magic(mage, u, TYP_UNIT, 0)) { - /* Fehlermeldung */ - spobj->data.i = u->no; - spobj->flag = TARGET_RESISTS; - ++*resist; - ADDMSG(&mage->faction->msgs, msg_message("spellunitresists", - "unit region command target", - mage, mage->region, co->order, u)); - break; - } - - /* TODO: Test auf Parteieigenschaft Magieresistsenz */ - ++*success; + if ((sp->sptyp & TESTRESISTANCE) + && target_resists_magic(mage, u, TYP_UNIT, 0)) { + /* Fehlermeldung */ + spobj->data.i = u->no; + spobj->flag = TARGET_RESISTS; + ++*resist; + ADDMSG(&mage->faction->msgs, msg_message("spellunitresists", + "unit region command target", mage, mage->region, co->order, u)); break; - case SPP_BUILDING: - b = spobj->data.b; + } - if ((sp->sptyp & TESTRESISTANCE) - && target_resists_magic(mage, b, TYP_BUILDING, 0)) { /* Fehlermeldung */ - spobj->data.i = b->no; - spobj->flag = TARGET_RESISTS; - ++*resist; - 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; + /* TODO: Test auf Parteieigenschaft Magieresistsenz */ + ++*success; + break; + case SPP_BUILDING: + b = spobj->data.b; - if ((sp->sptyp & TESTRESISTANCE) - && target_resists_magic(mage, sh, TYP_SHIP, 0)) { /* Fehlermeldung */ - spobj->data.i = sh->no; - spobj->flag = TARGET_RESISTS; - ++*resist; - ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, - "spellshipresists", "ship", sh)); - break; - } - ++*success; + if ((sp->sptyp & TESTRESISTANCE) + && target_resists_magic(mage, b, TYP_BUILDING, 0)) { /* Fehlermeldung */ + spobj->data.i = b->no; + spobj->flag = TARGET_RESISTS; + ++*resist; + 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; - case SPP_REGION: - /* haben wir ein Regionsobjekt, dann wird auch dieses und - nicht target_r überprüft. */ - tr = spobj->data.r; + if ((sp->sptyp & TESTRESISTANCE) + && target_resists_magic(mage, sh, TYP_SHIP, 0)) { /* Fehlermeldung */ + spobj->data.i = sh->no; + spobj->flag = TARGET_RESISTS; + ++*resist; + ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, + "spellshipresists", "ship", sh)); + break; + } + ++*success; + break; - 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; - } - ++*success; - break; - case SPP_INT: - case SPP_STRING: - ++*success; - break; + case SPP_REGION: + /* haben wir ein Regionsobjekt, dann wird auch dieses und + nicht target_r überprüft. */ + tr = spobj->data.r; - 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; + } + ++*success; + break; + case SPP_INT: + case SPP_STRING: + ++*success; + break; + + default: + break; } } } else { @@ -1804,11 +1803,11 @@ static void free_spellparameter(spellparameter * pa) for (i = 0; i < pa->length; i++) { switch (pa->param[i]->typ) { - case SPP_STRING: - free(pa->param[i]->data.s); - break; - default: - break; + case SPP_STRING: + free(pa->param[i]->data.s); + break; + default: + break; } free(pa->param[i]); } @@ -1967,87 +1966,87 @@ static spellparameter *add_spellparameter(region * target_r, unit * u, param_t pword; int j = -1; switch (*c) { - case '?': - /* tja. das sollte moeglichst nur am Ende passieren, - * weil sonst die kacke dampft. */ + case '?': + /* tja. das sollte moeglichst nur am Ende passieren, + * 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; ++c; - assert(*c == 0); break; - case '+': - /* das vorhergehende Element kommt ein oder mehrmals vor, wir - * springen zum key zurück */ - j = 0; - --c; + case P_UNIT: + if (i < size) { + j = addparam_unit(param + i, &spobj, u, ord); + ++c; + } break; - case 'u': - /* Parameter ist eine Einheit, evtl. TEMP */ - j = addparam_unit(param + i, &spobj, u, ord); - ++c; + case P_BUILDING: + case P_GEBAEUDE: + if (i < size) { + j = addparam_building(param + i, &spobj); + ++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; - ++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; + case P_SHIP: + if (i < size) { + j = addparam_ship(param + i, &spobj); + ++c; } break; default: j = -1; break; + } + break; + default: + j = -1; + break; } if (j < 0) fail = true; @@ -2481,10 +2480,12 @@ static boolean is_moving_ship(const region * r, const ship * sh) if (u) switch (get_keyword(u->thisorder)) { - case K_ROUTE: - case K_MOVE: - case K_FOLLOW: - return true; + case K_ROUTE: + case K_MOVE: + case K_FOLLOW: + return true; + default: + return false; } return false; } diff --git a/src/kernel/move.c b/src/kernel/move.c index 094fdf97d..82a2a51cc 100644 --- a/src/kernel/move.c +++ b/src/kernel/move.c @@ -1328,12 +1328,14 @@ static int movement_speed(unit * u) assert(u->number); /* dragons have a fixed speed, and no other effects work on them: */ switch (old_race(u->race)) { - case RC_DRAGON: - case RC_WYRM: - case RC_FIREDRAGON: - case RC_BIRTHDAYDRAGON: - case RC_SONGDRAGON: - return BP_DRAGON; + case RC_DRAGON: + case RC_WYRM: + case RC_FIREDRAGON: + case RC_BIRTHDAYDRAGON: + case RC_SONGDRAGON: + return BP_DRAGON; + default: + break; } if (!init) { @@ -1350,38 +1352,38 @@ static int movement_speed(unit * u) switch (canride(u)) { - case 1: /* Pferd */ - mp = BP_RIDING; - break; + case 1: /* Pferd */ + mp = BP_RIDING; + break; - case 2: /* Einhorn */ - mp = BP_UNICORN; - break; + case 2: /* Einhorn */ + mp = BP_UNICORN; + break; - default: - mp = BP_WALKING; + default: + mp = BP_WALKING; - /* Siebenmeilentee */ - if (get_effect(u, oldpotiontype[P_FAST]) >= u->number) { - mp *= 2; - change_effect(u, oldpotiontype[P_FAST], -u->number); - } + /* Siebenmeilentee */ + if (get_effect(u, oldpotiontype[P_FAST]) >= u->number) { + mp *= 2; + change_effect(u, oldpotiontype[P_FAST], -u->number); + } - /* unicorn in inventory */ - if (u->number <= get_item(u, I_FEENSTIEFEL)) { + /* unicorn in inventory */ + 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; } - - /* 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; - } - } - break; + } + break; } return (int)(dk * mp); } @@ -1996,15 +1998,15 @@ static const region_list *travel_i(unit * u, const region_list * route_begin, return route_begin; } switch (canwalk(u)) { - case E_CANWALK_TOOHEAVY: - cmistake(u, ord, 57, MSG_MOVE); - return route_begin; - case E_CANWALK_TOOMANYHORSES: - cmistake(u, ord, 56, MSG_MOVE); - return route_begin; - case E_CANWALK_TOOMANYCARTS: - cmistake(u, ord, 42, MSG_MOVE); - return route_begin; + case E_CANWALK_TOOHEAVY: + cmistake(u, ord, 57, MSG_MOVE); + return route_begin; + case E_CANWALK_TOOMANYHORSES: + cmistake(u, ord, 56, MSG_MOVE); + return route_begin; + case E_CANWALK_TOOMANYCARTS: + cmistake(u, ord, 42, MSG_MOVE); + return route_begin; } route_end = cap_route(r, route_begin, route_end, movement_speed(u)); @@ -2565,44 +2567,41 @@ void movement(void) } kword = get_keyword(u->thisorder); - switch (kword) { - case K_ROUTE: - case K_MOVE: - /* after moving, the unit has no thisorder. this prevents - * it from moving twice (or getting error messages twice). - * 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)) { - 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); + if (kword == K_ROUTE || kword == K_MOVE) { + /* after moving, the unit has no thisorder. this prevents + * it from moving twice (or getting error messages twice). + * 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)) { + cmistake(u, u->thisorder, 52, MSG_MOVE); set_order(&u->thisorder, NULL); } else { - 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); - } + 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); + } else { + 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) { /* not moved, use next unit */ @@ -2683,24 +2682,24 @@ void follow_unit(unit * u) } switch (get_keyword(u2->thisorder)) { - case K_MOVE: - case K_ROUTE: - case K_DRIVE: - follow = true; - break; - default: - for (ord = u2->orders; ord; ord = ord->next) { - switch (get_keyword(ord)) { - case K_FOLLOW: - case K_PIRACY: - follow = true; - break; - default: - continue; - } + case K_MOVE: + case K_ROUTE: + case K_DRIVE: + follow = true; + break; + default: + for (ord = u2->orders; ord; ord = ord->next) { + switch (get_keyword(ord)) { + case K_FOLLOW: + case K_PIRACY: + follow = true; break; + default: + continue; } break; + } + break; } if (!follow) { attrib *a2 = a_find(u2->attribs, &at_follow); diff --git a/src/kernel/order.c b/src/kernel/order.c index ffb955e9f..5ce1f5ffd 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -195,33 +195,33 @@ static order_data *create_data(keyword_t kwd, const char *sptr, int lindex) if (kwd == K_STUDY) { skill_t sk = findskill(parse_token(&sptr), lang); switch (sk) { - case NOSKILL: /* fehler */ + case NOSKILL: /* fehler */ + break; + case SK_MAGIC: /* kann parameter haben */ + if (*sptr != 0) break; - case SK_MAGIC: /* kann parameter haben */ - if (*sptr != 0) - break; - default: /* nur skill als Parameter, keine extras */ - data = locale_array[lindex]->study_orders[sk]; - if (data == NULL) { - const char *skname = skillname(sk, lang); - data = (order_data *) malloc(sizeof(order_data)); - locale_array[lindex]->study_orders[sk] = data; - data->_keyword = kwd; - data->_lindex = lindex; - if (strchr(skname, ' ') != NULL) { - size_t len = strlen(skname); - data->_str = malloc(len + 3); - data->_str[0] = '\"'; - memcpy(data->_str + 1, skname, len); - data->_str[len + 1] = '\"'; - data->_str[len + 2] = '\0'; - } else { - data->_str = strdup(skname); - } - data->_refcount = 1; + default: /* nur skill als Parameter, keine extras */ + data = locale_array[lindex]->study_orders[sk]; + if (data == NULL) { + const char *skname = skillname(sk, lang); + data = (order_data *) malloc(sizeof(order_data)); + locale_array[lindex]->study_orders[sk] = data; + data->_keyword = kwd; + data->_lindex = lindex; + if (strchr(skname, ' ') != NULL) { + size_t len = strlen(skname); + data->_str = malloc(len + 3); + data->_str[0] = '\"'; + memcpy(data->_str + 1, skname, len); + data->_str[len + 1] = '\"'; + data->_str[len + 2] = '\0'; + } else { + data->_str = strdup(skname); } - ++data->_refcount; - return data; + data->_refcount = 1; + } + ++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 (lomem) { switch (kwd) { - case K_KOMMENTAR: - case NOKEYWORD: - return NULL; - case K_LIEFERE: - kwd = K_GIVE; - persistent = 1; - break; - default: - break; + case K_KOMMENTAR: + case NOKEYWORD: + return NULL; + case K_LIEFERE: + kwd = K_GIVE; + persistent = 1; + break; + default: + break; } } @@ -304,26 +304,26 @@ order *create_order(keyword_t kwd, const struct locale * lang, const char *s; ++params; switch (*params) { - case 's': - s = va_arg(marker, const char *); - bytes = (int)strlcpy(bufp, s, size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - break; - case 'd': - i = va_arg(marker, int); - bytes = (int)strlcpy(bufp, itoa10(i), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - break; - case 'i': - i = va_arg(marker, int); - bytes = (int)strlcpy(bufp, itoa36(i), size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - break; - default: - assert(!"unknown format-character in create_order"); + case 's': + s = va_arg(marker, const char *); + bytes = (int)strlcpy(bufp, s, size); + if (wrptr(&bufp, &size, bytes) != 0) + WARN_STATIC_BUFFER(); + break; + case 'd': + i = va_arg(marker, int); + bytes = (int)strlcpy(bufp, itoa10(i), size); + if (wrptr(&bufp, &size, bytes) != 0) + WARN_STATIC_BUFFER(); + break; + case 'i': + i = va_arg(marker, int); + bytes = (int)strlcpy(bufp, itoa36(i), size); + if (wrptr(&bufp, &size, bytes) != 0) + WARN_STATIC_BUFFER(); + break; + default: + assert(!"unknown format-character in create_order"); } } else if (size > 0) { *bufp++ = *params; @@ -379,55 +379,55 @@ boolean is_repeated(const order * ord) param_t param; switch (kwd) { - case K_CAST: - case K_BUY: - case K_SELL: - case K_ROUTE: - case K_DRIVE: - case K_WORK: - case K_BESIEGE: - case K_ENTERTAIN: - case K_TAX: - case K_RESEARCH: - case K_SPY: - case K_STEAL: - case K_SABOTAGE: - case K_STUDY: - case K_TEACH: - case K_BREED: - case K_PIRACY: + case K_CAST: + case K_BUY: + case K_SELL: + case K_ROUTE: + case K_DRIVE: + case K_WORK: + case K_BESIEGE: + case K_ENTERTAIN: + case K_TAX: + case K_RESEARCH: + case K_SPY: + case K_STEAL: + case K_SABOTAGE: + case K_STUDY: + case K_TEACH: + case K_BREED: + 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; + 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; - - 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; - 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; + break; + default: + return false; } return false; } @@ -447,55 +447,55 @@ boolean is_exclusive(const order * ord) param_t param; switch (kwd) { - case K_MOVE: - case K_WEREWOLF: - /* these should not become persistent */ - case K_ROUTE: - case K_DRIVE: - case K_WORK: - case K_BESIEGE: - case K_ENTERTAIN: - case K_TAX: - case K_RESEARCH: - case K_SPY: - case K_STEAL: - case K_SABOTAGE: - case K_STUDY: - case K_TEACH: - case K_BREED: - case K_PIRACY: + case K_MOVE: + case K_WEREWOLF: + /* these should not become persistent */ + case K_ROUTE: + case K_DRIVE: + case K_WORK: + case K_BESIEGE: + case K_ENTERTAIN: + case K_TAX: + case K_RESEARCH: + case K_SPY: + case K_STEAL: + case K_SABOTAGE: + case K_STUDY: + case K_TEACH: + case K_BREED: + 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; + 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; - - 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; - 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; + break; + default: + return false; } return false; } @@ -515,57 +515,57 @@ boolean is_long(const order * ord) param_t param; switch (kwd) { - case K_CAST: - case K_BUY: - case K_SELL: - case K_MOVE: - case K_WEREWOLF: - case K_ROUTE: - case K_DRIVE: - case K_WORK: - case K_BESIEGE: - case K_ENTERTAIN: - case K_TAX: - case K_RESEARCH: - case K_SPY: - case K_STEAL: - case K_SABOTAGE: - case K_STUDY: - case K_TEACH: - case K_BREED: - case K_PIRACY: + case K_CAST: + case K_BUY: + case K_SELL: + case K_MOVE: + case K_WEREWOLF: + case K_ROUTE: + case K_DRIVE: + case K_WORK: + case K_BESIEGE: + case K_ENTERTAIN: + case K_TAX: + case K_RESEARCH: + case K_SPY: + case K_STEAL: + case K_SABOTAGE: + case K_STUDY: + case K_TEACH: + case K_BREED: + 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; + 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; - - 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; - 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; + break; + default: + return false; } return false; } @@ -584,18 +584,20 @@ boolean is_persistent(const order * ord) keyword_t kwd = ORD_KEYWORD(ord); boolean persist = ord->_persistent != 0; switch (kwd) { - case K_MOVE: - case K_WEREWOLF: - case NOKEYWORD: - /* lang, aber niemals persistent! */ - return false; + case K_MOVE: + case K_WEREWOLF: + case NOKEYWORD: + /* lang, aber niemals persistent! */ + return false; - case K_KOMMENTAR: - case K_LIEFERE: - return true; + case K_KOMMENTAR: + case K_LIEFERE: + return true; + + default: + return persist || is_repeated(ord); } - return persist || is_repeated(ord); } char *write_order(const order * ord, char *buffer, size_t size) diff --git a/src/kernel/reports.h b/src/kernel/reports.h index 5a643cc01..632c3df86 100644 --- a/src/kernel/reports.h +++ b/src/kernel/reports.h @@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_KRNL_REPORTS #define H_KRNL_REPORTS + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/kernel/save.c b/src/kernel/save.c index 194598b1a..0d7c534cd 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -144,51 +144,29 @@ int freadstr(FILE * F, int encoding, char *start, size_t size) } } 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: 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: - 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; - } - } + case 'n': + if ((size_t) (str - start + 1) < size) { + *str++ = '\n'; } break; default: @@ -209,6 +187,26 @@ int freadstr(FILE * F, int encoding, char *start, size_t size) *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) { int c = (int)(unsigned char)*str++; switch (c) { - case '"': - case '\\': - fputc('\\', F); - fputc(c, F); - nwrite += 2; - break; - case '\n': - fputc('\\', F); - fputc('n', F); - nwrite += 2; - break; - default: - fputc(c, F); - ++nwrite; + case '"': + case '\\': + fputc('\\', F); + fputc(c, F); + nwrite += 2; + break; + case '\n': + fputc('\\', F); + fputc('n', F); + nwrite += 2; + break; + default: + fputc(c, F); + ++nwrite; } } fputc('\"', F); @@ -300,23 +298,28 @@ static unit *unitorders(FILE * F, int enc, struct faction *f) boolean quit = false; param_t param = findparam(stok, u->faction->locale); switch (param) { - case P_UNIT: - case P_REGION: + case P_UNIT: + 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; 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; - break; - } else { - quit = false; - } - } - if (quit) + } else { + quit = false; + } break; + default: + /* TODO: syntax error message */ + break; + } + if (quit) { + break; + } } /* Nun wird der Befehl erzeut und eingehängt */ *ordp = parse_order(s, u->faction->locale); @@ -400,58 +403,58 @@ int readorders(const char *filename) const char *s; switch (igetparam(b, lang)) { - case P_LOCALE: - s = getstrtoken(); + case P_LOCALE: + s = getstrtoken(); #undef LOCALE_CHANGE #ifdef LOCALE_CHANGE - if (f && find_locale(s)) { - f->locale = find_locale(s); - } + if (f && find_locale(s)) { + f->locale = find_locale(s); + } #endif - b = getbuf(F, enc_gamedata); - break; - case P_GAMENAME: - case P_FACTION: - f = factionorders(); - if (f) { - ++nfactions; - } + b = getbuf(F, enc_gamedata); + break; + case P_GAMENAME: + case P_FACTION: + f = factionorders(); + if (f) { + ++nfactions; + } - b = getbuf(F, enc_gamedata); - break; + b = getbuf(F, enc_gamedata); + break; - /* in factionorders wird nur eine zeile gelesen: - * diejenige mit dem passwort. Die befehle der units - * werden geloescht, und die Partei wird als aktiv - * vermerkt. */ + /* in factionorders wird nur eine zeile gelesen: + * diejenige mit dem passwort. Die befehle der units + * werden geloescht, und die Partei wird als aktiv + * vermerkt. */ - case P_UNIT: - if (!f || !unitorders(F, enc_gamedata, f)) - do { - b = getbuf(F, enc_gamedata); - if (!b) - break; - p = igetparam(b, lang); - } while ((p != P_UNIT || !f) && p != P_FACTION && p != P_NEXT - && p != P_GAMENAME); - break; + case P_UNIT: + if (!f || !unitorders(F, enc_gamedata, f)) + do { + b = getbuf(F, enc_gamedata); + if (!b) + break; + p = igetparam(b, lang); + } while ((p != P_UNIT || !f) && p != P_FACTION && p != P_NEXT + && p != P_GAMENAME); + break; - /* Falls in unitorders() abgebrochen wird, steht dort entweder eine neue - * Partei, eine neue Einheit oder das File-Ende. Das switch() wird erneut - * durchlaufen, und die entsprechende Funktion aufgerufen. Man darf buf - * auf alle Fälle nicht überschreiben! Bei allen anderen Einträgen hier - * muß buf erneut gefüllt werden, da die betreffende Information in nur - * einer Zeile steht, und nun die nächste gelesen werden muß. */ + /* Falls in unitorders() abgebrochen wird, steht dort entweder eine neue + * Partei, eine neue Einheit oder das File-Ende. Das switch() wird erneut + * durchlaufen, und die entsprechende Funktion aufgerufen. Man darf buf + * auf alle Fälle nicht überschreiben! Bei allen anderen Einträgen hier + * muß buf erneut gefüllt werden, da die betreffende Information in nur + * einer Zeile steht, und nun die nächste gelesen werden muß. */ - case P_NEXT: - f = NULL; - b = getbuf(F, enc_gamedata); - break; + case P_NEXT: + f = NULL; + b = getbuf(F, enc_gamedata); + break; - default: - b = getbuf(F, enc_gamedata); - break; + default: + b = getbuf(F, enc_gamedata); + break; } } diff --git a/src/kernel/skill.c b/src/kernel/skill.c index 89431ad81..7a41b8b33 100644 --- a/src/kernel/skill.c +++ b/src/kernel/skill.c @@ -223,13 +223,15 @@ int rc_skillmod(const struct race *rc, const region * r, skill_t sk) { int mods; - if (!skill_enabled[sk]) + if (!skill_enabled[sk]) { return 0; + } #ifdef FASTER_SKILLMOD unsigned int index = hashstring(rc->_name[0]) % RCMODMAXHASH; struct skillmods **imods = &modhash[index]; - while (*imods && (*imods)->race != rc) + while (*imods && (*imods)->race != rc) { imods = &(*imods)->next; + } if (*imods == NULL) { *imods = init_skills(rc); } @@ -237,21 +239,19 @@ int rc_skillmod(const struct race *rc, const region * r, skill_t sk) #else mods = skill_mod(rc, sk, r->terrain); #endif - if (rc == new_race[RC_ELF] && r_isforest(r)) - switch (sk) { - case SK_PERCEPTION: + if (rc == new_race[RC_ELF] && r_isforest(r)) { + if (sk == SK_PERCEPTION) { + ++mods; + } else if (sk == SK_STEALTH) { + if (r_isforest(r)) { ++mods; - break; - case SK_STEALTH: - if (r_isforest(r)) - ++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; } diff --git a/src/kernel/spellid.h b/src/kernel/spellid.h index 71f13dcda..8b0e7c668 100644 --- a/src/kernel/spellid.h +++ b/src/kernel/spellid.h @@ -170,7 +170,7 @@ enum { XMLSPL_WDWPYRAMID_ASTRAL = 185, XMLSPL_WDWPYRAMID_DRUIDE = 186, XMLSPL_WDWPYRAMID_BARDE = 187, - XMLSPL_WDWPYRAMID_CHAOS = 188, + XMLSPL_WDWPYRAMID_CHAOS = 188 }; #endif diff --git a/src/kernel/textstore.c b/src/kernel/textstore.c index 9fc80f01e..4c812158b 100644 --- a/src/kernel/textstore.c +++ b/src/kernel/textstore.c @@ -60,7 +60,7 @@ static int txt_w_flt(struct storage *store, float arg) static float txt_r_flt(struct storage *store) { double result; - fscanf((FILE *) store->userdata, "%f", &result); + fscanf((FILE *) store->userdata, "%lf", &result); return (float)result; } @@ -154,7 +154,7 @@ static int txt_open(struct storage *store, const char *filename, int mode) store->version = atoi(token); } } 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); } } diff --git a/src/modules/xecmd.c b/src/modules/xecmd.c index 939b882a5..67ebeb094 100644 --- a/src/modules/xecmd.c +++ b/src/modules/xecmd.c @@ -89,18 +89,17 @@ int xecmd(unit * u, order * ord) if (a_find(f->attribs, &at_xontormiaexpress)) { if (get_keyword(ord) == K_XE) { + param_t param; + init_tokens(ord); skip_token(); - switch (findparam(getstrtoken(), f->locale)) { - case P_XEPOTION: - xe_givepotion(u, ord); - break; - case P_XEBALLOON: - xe_giveballon(u, ord); - break; - case P_XELAEN: - xe_givelaen(u, ord); - break; + param = findparam(getstrtoken(), f->locale); + if (param == P_XEPOTION) { + xe_givepotion(u, ord); + } else if (param == P_XEBALLOON) { + xe_giveballon(u, ord); + } else if (param == P_XELAEN) { + xe_givelaen(u, ord); } } }