From 8987d012144c91af8bddc45119b9c706becf27f7 Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Sun, 24 Jun 2012 05:09:13 +0200 Subject: [PATCH 01/24] fix compilation on gcc --- src/bindings/bindings.c | 24 ------------------------ src/gamecode/laws.c | 2 +- src/util/os.c | 22 +++++++++------------- 3 files changed, 10 insertions(+), 38 deletions(-) diff --git a/src/bindings/bindings.c b/src/bindings/bindings.c index 12480b8a5..b452eb366 100755 --- a/src/bindings/bindings.c +++ b/src/bindings/bindings.c @@ -1006,30 +1006,6 @@ typedef struct event_args { const char *sendertype; } event_args; -static void args_free(void *udata) -{ - free(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; - int nargs = 2; - lua_rawgeti(L, LUA_REGISTRYINDEX, args->hfunction); - if (sender && args->sendertype) { - tolua_pushusertype(L, sender, TOLUA_CAST args->sendertype); - } else { - lua_pushnil(L); - } - tolua_pushstring(L, event); - if (args->hargs) { - lua_rawgeti(L, LUA_REGISTRYINDEX, args->hfunction); - ++nargs; - } - lua_pcall(L, nargs, 0, 0); -} - static int tolua_report_unit(lua_State * L) { char buffer[512]; diff --git a/src/gamecode/laws.c b/src/gamecode/laws.c index 82ebc4034..d2485fadc 100755 --- a/src/gamecode/laws.c +++ b/src/gamecode/laws.c @@ -4483,8 +4483,8 @@ void init_processor(void) } p += 10; + add_proc_region(p, do_contact, "Kontaktieren"); add_proc_order(p, K_MAIL, &mail_cmd, 0, "Botschaften"); - add_proc_order(p, K_CONTACT, &contact_cmd, 0, "Kontaktieren"); p += 10; /* all claims must be done before we can USE */ add_proc_region(p, &enter_1, "Betreten (1. Versuch)"); diff --git a/src/util/os.c b/src/util/os.c index 1278e0f7c..c2f947920 100644 --- a/src/util/os.c +++ b/src/util/os.c @@ -2,20 +2,16 @@ #if defined(WIN32) #include <direct.h> -#else /* */ +#else /* WIN32 */ #include <sys/stat.h> -#endif /* */ - int os_mkdir(const char *path, int mode) -{ +#endif /* WIN32 */ +int os_mkdir(const char *path, int mode) +{ #ifdef WIN32 - mode = mode; - return _mkdir(path); - + mode = mode; + return _mkdir(path); #else /* POSIX is our last hope */ - return mkdir(path, (mode_t) mode); - -#endif /* */ -} - - + return mkdir(path, (mode_t) mode); +#endif /* WIN32 */ +} From 413edd9be6b5820c10bbfb06b43775efd495a412 Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Sun, 24 Jun 2012 06:56:42 +0200 Subject: [PATCH 02/24] compilation fix for gcc C99 --- src/util/os.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/os.c b/src/util/os.c index c2f947920..5a7220e7d 100644 --- a/src/util/os.c +++ b/src/util/os.c @@ -3,6 +3,7 @@ #if defined(WIN32) #include <direct.h> #else /* WIN32 */ +#include <sys/types.h> #include <sys/stat.h> #endif /* WIN32 */ int os_mkdir(const char *path, int mode) From 7359eea1846c53aded031e47c3cbfd752dd8104c Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Sun, 24 Jun 2012 07:08:16 +0200 Subject: [PATCH 03/24] use bool type where it's available when using gcc, compile as C99 --- src/CMakeLists.txt | 1 + src/platform.h | 19 +++---------------- src/util/bool.h | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 src/util/bool.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1cc33a9b9..9e9eb8d6c 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,6 +3,7 @@ project (eressea C) IF(CMAKE_COMPILER_IS_GNUCC) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -DHAVE__BOOL") ELSE(CMAKE_COMPILER_IS_GNUCC) MESSAGE(STATUS "Unknown compiler ${CMAKE_C_COMPILER_ID}") ENDIF(CMAKE_COMPILER_IS_GNUCC) diff --git a/src/platform.h b/src/platform.h index d72545cc6..679737ec2 100644 --- a/src/platform.h +++ b/src/platform.h @@ -246,22 +246,9 @@ extern char *strdup(const char *s); # define unused(a) (a) #endif /* ghs || __GNUC__ || ..... */ -/**** **** - ** The Eressea boolean type ** - **** ****/ -#if defined(BOOLEAN) -# define boolean BOOLEAN -#else -typedef int boolean; /* not bool! wrong size. */ -#endif -#ifndef __cplusplus -# define false ((boolean)0) -# define true ((boolean)!false) -#endif -#ifdef __cplusplus -} -#endif - +#include "util/bool.h" +typedef bool boolean; + #ifndef INLINE_FUNCTION # define INLINE_FUNCTION #endif diff --git a/src/util/bool.h b/src/util/bool.h new file mode 100644 index 000000000..0bdebc9ec --- /dev/null +++ b/src/util/bool.h @@ -0,0 +1,15 @@ +#if HAVE_STDBOOL_H +# include <stdbool.h> +#else +# if ! HAVE__BOOL +# ifdef __cplusplus +typedef bool _Bool; +# else +typedef unsigned char _Bool; +# endif +# endif +# define bool _Bool +# define false 0 +# define true 1 +# define __bool_true_false_are_defined 1 +#endif From 186126810993fb01329f8f77fee7c3e0a265181b Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Sat, 23 Jun 2012 22:41:07 -0700 Subject: [PATCH 04/24] remove custom boolean type use bool when we have C99, or our own typedef for bool --- src/attributes/moved.c | 2 +- src/attributes/moved.h | 2 +- src/attributes/movement.c | 2 +- src/attributes/movement.h | 2 +- src/bindings/bind_sqlite.c | 4 +- src/bindings/helpers.c | 4 +- src/gamecode/archetype.h | 2 +- src/gamecode/creport.c | 16 ++++---- src/gamecode/economy.c | 36 ++++++++--------- src/gamecode/economy.h | 2 +- src/gamecode/give.c | 4 +- src/gamecode/laws.c | 42 +++++++++---------- src/gamecode/laws.h | 2 +- src/gamecode/monster.c | 2 +- src/gamecode/monster.h | 2 +- src/gamecode/randenc.c | 8 ++-- src/gamecode/report.c | 34 ++++++++-------- src/gamecode/study.c | 10 ++--- src/gamecode/study.h | 2 +- src/gamecode/summary.c | 2 +- src/gamecode/summary.h | 2 +- src/gamecode/xmlreport.c | 6 +-- src/gmtool.c | 4 +- src/gmtool.h | 2 +- src/gmtool_structs.h | 4 +- src/items/phoenixcompass.c | 2 +- src/items/weapons.c | 4 +- src/kernel/alliance.c | 2 +- src/kernel/battle.c | 82 +++++++++++++++++++------------------- src/kernel/battle.h | 16 ++++---- src/kernel/building.c | 6 +-- src/kernel/config.c | 56 +++++++++++++------------- src/kernel/config.h | 48 +++++++++++----------- src/kernel/connection.c | 32 +++++++-------- src/kernel/connection.h | 34 ++++++++-------- src/kernel/curse.c | 14 +++---- src/kernel/curse.h | 12 +++--- src/kernel/faction.c | 6 +-- src/kernel/faction.h | 8 ++-- src/kernel/group.c | 2 +- src/kernel/group.h | 2 +- src/kernel/item.c | 2 +- src/kernel/item.h | 4 +- src/kernel/magic.c | 32 +++++++-------- src/kernel/magic.h | 16 ++++---- src/kernel/move.c | 60 ++++++++++++++-------------- src/kernel/move.h | 10 ++--- src/kernel/pathfinder.c | 18 ++++----- src/kernel/pathfinder.h | 14 +++---- src/kernel/plane.c | 2 +- src/kernel/plane.h | 2 +- src/kernel/race.c | 4 +- src/kernel/race.h | 8 ++-- src/kernel/region.c | 6 +-- src/kernel/region.h | 8 ++-- src/kernel/reports.c | 28 ++++++------- src/kernel/reports.h | 16 ++++---- src/kernel/resources.c | 2 +- src/kernel/save.c | 4 +- src/kernel/skill.c | 6 +-- src/kernel/skill.h | 4 +- src/kernel/sqlite.c | 10 ++--- src/kernel/teleport.c | 8 ++-- src/kernel/teleport.h | 8 ++-- src/kernel/unit.c | 18 ++++----- src/kernel/unit.h | 14 +++---- src/kernel/xmlreader.c | 16 ++++---- src/modules/autoseed.c | 6 +-- src/modules/autoseed.h | 2 +- src/modules/gmcmd.c | 6 +-- src/modules/wormhole.c | 2 +- src/platform.h | 1 - src/util/attrib.c | 2 +- src/util/attrib.h | 2 +- src/util/filereader.c | 16 ++++---- src/util/listbox.c | 2 +- src/util/parser.c | 6 +-- src/util/parser.h | 2 +- src/util/rand.c | 2 +- src/util/rand.h | 2 +- src/util/translation.c | 8 ++-- src/util/xml.c | 8 ++-- src/util/xml.h | 2 +- 83 files changed, 456 insertions(+), 457 deletions(-) diff --git a/src/attributes/moved.c b/src/attributes/moved.c index d73b3e541..6ddad1b17 100644 --- a/src/attributes/moved.c +++ b/src/attributes/moved.c @@ -48,7 +48,7 @@ attrib_type at_moved = { "moved", NULL, NULL, age_moved, write_moved, read_moved }; -boolean get_moved(attrib ** alist) +bool get_moved(attrib ** alist) { return a_find(*alist, &at_moved) ? true : false; } diff --git a/src/attributes/moved.h b/src/attributes/moved.h index cce9fe941..bad4dcdd5 100644 --- a/src/attributes/moved.h +++ b/src/attributes/moved.h @@ -25,7 +25,7 @@ extern "C" { struct attrib; struct attrib_type; - extern boolean get_moved(struct attrib **alist); + extern bool get_moved(struct attrib **alist); extern void set_moved(struct attrib **alist); extern struct attrib_type at_moved; diff --git a/src/attributes/movement.c b/src/attributes/movement.c index 8e2515854..1f3bf51c0 100644 --- a/src/attributes/movement.c +++ b/src/attributes/movement.c @@ -42,7 +42,7 @@ attrib_type at_movement = { "movement", NULL, NULL, NULL, write_movement, read_movement }; -boolean get_movement(attrib * const *alist, int type) +bool get_movement(attrib * const *alist, int type) { const attrib *a = a_findc(*alist, &at_movement); if (a == NULL) diff --git a/src/attributes/movement.h b/src/attributes/movement.h index b976a67ec..0fe4cfc83 100644 --- a/src/attributes/movement.h +++ b/src/attributes/movement.h @@ -22,7 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif - extern boolean get_movement(struct attrib *const *alist, int type); + extern bool get_movement(struct attrib *const *alist, int type); extern void set_movement(struct attrib **alist, int type); extern struct attrib_type at_movement; diff --git a/src/bindings/bind_sqlite.c b/src/bindings/bind_sqlite.c index be1eacec7..0df9e530f 100644 --- a/src/bindings/bind_sqlite.c +++ b/src/bindings/bind_sqlite.c @@ -21,7 +21,7 @@ without prior permission by the authors of Eressea. #define LTYPE_DB TOLUA_CAST "db" -extern int db_update_factions(sqlite3 * db, boolean force); +extern int db_update_factions(sqlite3 * db, bool force); static int tolua_db_update_factions(lua_State * L) { sqlite3 *db = (sqlite3 *) tolua_tousertype(L, 1, 0); @@ -29,7 +29,7 @@ static int tolua_db_update_factions(lua_State * L) return 0; } -extern int db_update_scores(sqlite3 * db, boolean force); +extern int db_update_scores(sqlite3 * db, bool force); static int tolua_db_update_scores(lua_State * L) { sqlite3 *db = (sqlite3 *) tolua_tousertype(L, 1, 0); diff --git a/src/bindings/helpers.c b/src/bindings/helpers.c index f2fbae090..d6d73d7b2 100644 --- a/src/bindings/helpers.c +++ b/src/bindings/helpers.c @@ -342,10 +342,10 @@ static int lua_getresource(unit * u, const struct resource_type *rtype) return result; } -static boolean lua_canuse_item(const unit * u, const struct item_type *itype) +static bool lua_canuse_item(const unit * u, const struct item_type *itype) { static int function_exists = 1; - boolean result = true; + bool result = true; if (function_exists) { lua_State *L = (lua_State *) global.vm_state; diff --git a/src/gamecode/archetype.h b/src/gamecode/archetype.h index 963acd286..55c6896cc 100644 --- a/src/gamecode/archetype.h +++ b/src/gamecode/archetype.h @@ -18,7 +18,7 @@ extern "C" { #endif typedef struct rule { - boolean allow; + bool allow; char *property; char *value; } rule; diff --git a/src/gamecode/creport.c b/src/gamecode/creport.c index 3f7d4fe1d..0a4768097 100644 --- a/src/gamecode/creport.c +++ b/src/gamecode/creport.c @@ -80,7 +80,7 @@ without prior permission by the authors of Eressea. /* imports */ extern int verbosity; -boolean opt_cr_absolute_coords = false; +bool opt_cr_absolute_coords = false; /* globals */ #define C_REPORT_VERSION 66 @@ -177,7 +177,7 @@ static void print_items(FILE * F, item * items, const struct locale *lang) static void cr_output_curses(FILE * F, const faction * viewer, const void *obj, objtype_t typ) { - boolean header = false; + bool header = false; attrib *a = NULL; int self = 0; region *r; @@ -508,7 +508,7 @@ static void render_messages(FILE * F, faction * f, message_list * msgs) struct mlist *m = msgs->begin; while (m) { char crbuffer[BUFFERSIZE]; /* gross, wegen spionage-messages :-( */ - boolean printed = false; + bool printed = false; const struct message_type *mtype = m->msg->type; unsigned int hash = mtype->key; #ifdef RENDER_CRMESSAGES @@ -637,7 +637,7 @@ cr_output_ship(FILE * F, const ship * sh, const unit * u, int fcaptain, static void fwriteorder(FILE * F, const struct order *ord, const struct locale *lang, - boolean escape) + bool escape) { char ebuf[1024]; char obuf[1024]; @@ -690,9 +690,9 @@ static void cr_output_unit(FILE * F, const region * r, const faction * f, const char *pzTmp; skill *sv; const attrib *a_fshidden = NULL; - boolean itemcloak = false; + bool itemcloak = false; static const curse_type *itemcloak_ct = 0; - static boolean init = false; + static bool init = false; item result[MAX_INVENTORY]; if (fval(u->race, RCF_INVISIBLE)) @@ -1096,7 +1096,7 @@ cr_borders(seen_region ** seen, const region * r, const faction * f, } b = get_borders(r, r2); while (b) { - boolean cs = b->type->fvisible(b, f, r); + bool cs = b->type->fvisible(b, f, r); if (!cs) { cs = b->type->rvisible(b, r); @@ -1352,7 +1352,7 @@ static void cr_output_region(FILE * F, report_context * ctx, seen_region * sr) /* describe both passed and inhabited regions */ show_active_spells(r); if (fval(r, RF_TRAVELUNIT)) { - boolean seeunits = false, seeships = false; + bool seeunits = false, seeships = false; const attrib *ru; /* show units pulled through region */ for (ru = a_find(r->attribs, &at_travelunit); diff --git a/src/gamecode/economy.c b/src/gamecode/economy.c index cd47f880a..6668c3a21 100644 --- a/src/gamecode/economy.c +++ b/src/gamecode/economy.c @@ -89,7 +89,7 @@ typedef struct request { int qty; int no; union { - boolean goblin; /* stealing */ + bool goblin; /* stealing */ const struct luxury_type *ltype; /* trading */ } type; } request; @@ -392,7 +392,7 @@ static void feedback_give_not_allowed(unit * u, order * ord) "")); } -static boolean check_give(unit * u, unit * u2, const item_type * itype, +static bool check_give(unit * u, unit * u2, const item_type * itype, int mask) { if (u2) { @@ -537,7 +537,7 @@ static void recruit(unit * u, struct order *ord, request ** recruitorders) get_gamedate(turn, &date); if (date.season == 0 && r->terrain != newterrain(T_DESERT)) { #ifdef INSECT_POTION - boolean usepotion = false; + bool usepotion = false; unit *u2; for (u2 = r->units; u2; u2 = u2->next) @@ -769,7 +769,7 @@ static void give_cmd(unit * u, order * ord) } else if (p == P_HERBS) { - boolean given = false; + bool given = false; if (!(u->race->ec_flags & GIVEITEM) && u2 != NULL) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_nogive", "race", u->race)); @@ -996,12 +996,12 @@ void add_spende(faction * f1, faction * f2, int amount, region * r) r->donations = sp; } -static boolean maintain(building * b, boolean first) +static bool maintain(building * b, bool first) /* first==false -> take money from wherever you can */ { int c; region *r = b->region; - boolean paid = true, work = first; + bool paid = true, work = first; unit *u; if (fval(b, BLD_MAINTAINED) || b->type == NULL || b->type->maintenance == NULL || is_cursed(b->attribs, C_NOCOST, 0)) { @@ -1111,12 +1111,12 @@ static boolean maintain(building * b, boolean first) return true; } -void maintain_buildings(region * r, boolean crash) +void maintain_buildings(region * r, bool crash) { building **bp = &r->buildings; while (*bp) { building *b = *bp; - boolean maintained = maintain(b, !crash); + bool maintained = maintain(b, !crash); /* the second time, send a message */ if (crash) { @@ -1141,7 +1141,7 @@ void maintain_buildings(region * r, boolean crash) static int recruit_archetype(unit * u, order * ord) { - boolean merge = (u->number > 0); + bool merge = (u->number > 0); int want; const char *s; @@ -1178,7 +1178,7 @@ static int recruit_archetype(unit * u, order * ord) */ int k; for (k = 0; arch->rules[k].property; ++k) { - boolean match = false; + bool match = false; if (arch->rules[k].value[0] == '*') match = true; else if (strcmp(arch->rules[k].property, "race") == 0) { @@ -1296,7 +1296,7 @@ void economics(region * r) for (u = r->units; u; u = u->next) { order *ord; - boolean destroyed = false; + bool destroyed = false; if (u->number > 0) { for (ord = u->orders; ord; ord = ord->next) { keyword_t kwd = get_keyword(ord); @@ -1421,7 +1421,7 @@ typedef struct allocation_list { static allocation_list *allocations; -static boolean can_guard(const unit * guard, const unit * u) +static bool can_guard(const unit * guard, const unit * u) { if (fval(guard, UFL_ISNEW)) return false; @@ -1612,7 +1612,7 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) const item_type *itype = resource2item(rtype); rawmaterial *rm = rm_get(r, rtype); int need; - boolean first = true; + bool first = true; if (rm != NULL) { do { @@ -2373,9 +2373,9 @@ static void expandselling(region * r, request * sellorders, int limit) } } -static boolean sell(unit * u, request ** sellorders, struct order *ord) +static bool sell(unit * u, request ** sellorders, struct order *ord) { - boolean unlimited = true; + bool unlimited = true; const item_type *itype; const luxury_type *ltype = NULL; int n; @@ -2904,7 +2904,7 @@ static int max_skill(region * r, faction * f, skill_t sk) static void steal_cmd(unit * u, struct order *ord, request ** stealorders) { int n, i, id; - boolean goblin = false; + bool goblin = false; request *o; unit *u2 = NULL; region *r = u->region; @@ -3342,7 +3342,7 @@ void produce(struct region *r) unit *u; int todo; static int rule_autowork = -1; - boolean limited = true; + bool limited = true; request *nextworker = workers; assert(r); @@ -3378,7 +3378,7 @@ void produce(struct region *r) for (u = r->units; u; u = u->next) { order *ord; - boolean trader = false; + bool trader = false; if (u->race == new_race[RC_SPELL] || fval(u, UFL_LONGACTION)) continue; diff --git a/src/gamecode/economy.h b/src/gamecode/economy.h index b5ccac86d..8b44df380 100644 --- a/src/gamecode/economy.h +++ b/src/gamecode/economy.h @@ -48,7 +48,7 @@ extern "C" { enum { IC_WORK, IC_ENTERTAIN, IC_TAX, IC_TRADE, IC_TRADETAX, IC_STEAL, IC_MAGIC }; - void maintain_buildings(struct region *r, boolean crash); + void maintain_buildings(struct region *r, bool crash); extern void add_spende(struct faction *f1, struct faction *f2, int betrag, struct region *r); extern int make_cmd(struct unit *u, struct order *ord); diff --git a/src/gamecode/give.c b/src/gamecode/give.c index b9254c7c2..9c259f2cf 100644 --- a/src/gamecode/give.c +++ b/src/gamecode/give.c @@ -87,7 +87,7 @@ add_give(unit * u, unit * u2, int given, int received, } } -static boolean limited_give(const item_type * type) +static bool limited_give(const item_type * type) { /* trade only money 2:1, if at all */ return (type == i_silver); @@ -288,7 +288,7 @@ void give_men(int n, unit * u, unit * u2, struct order *ord) if (u2) { if (u2->number != 0 && recruit_archetypes()) { /* must have same set of skills */ - boolean okay = false; + bool okay = false; if (u->skill_size == u2->skill_size) { int i; for (i = 0; i != u->skill_size; ++i) { diff --git a/src/gamecode/laws.c b/src/gamecode/laws.c index d2485fadc..3b332fec7 100755 --- a/src/gamecode/laws.c +++ b/src/gamecode/laws.c @@ -141,7 +141,7 @@ static void checkorders(void) ADDMSG(&f->msgs, msg_message("turnreminder", "")); } -static boolean help_money(const unit * u) +static bool help_money(const unit * u) { if (u->race->ec_flags & GIVEITEM) return true; @@ -1128,7 +1128,7 @@ int leave_cmd(unit * u, struct order *ord) return 0; } -static boolean EnhancedQuit(void) +static bool EnhancedQuit(void) { static int value = -1; if (value < 0) { @@ -1180,7 +1180,7 @@ int quit_cmd(unit * u, struct order *ord) return 0; } -static boolean mayenter(region * r, unit * u, building * b) +static bool mayenter(region * r, unit * u, building * b) { unit *u2; if (fval(b, BLD_UNGUARDED)) @@ -1201,7 +1201,7 @@ static int mayboard(const unit * u, ship * sh) return (!u2 || ucontact(u2, u) || alliedunit(u2, u->faction, HELP_GUARD)); } -static boolean CheckOverload(void) +static bool CheckOverload(void) { static int value = -1; if (value < 0) { @@ -1655,7 +1655,7 @@ static void init_prefixnames(void) int i; for (i = 0; localenames[i]; ++i) { const struct locale *lang = find_locale(localenames[i]); - boolean exist = false; + bool exist = false; struct local_names *in = pnames; while (in != NULL) { @@ -1839,7 +1839,7 @@ int display_cmd(unit * u, struct order *ord) return 0; } -boolean renamed_building(const building * b) +bool renamed_building(const building * b) { const struct locale *lang = locales; size_t len = strlen(b->name); @@ -1877,7 +1877,7 @@ int rename_building(unit * u, order * ord, building * b, const char *name) { unit *owner = b ? building_owner(b) : 0; - boolean foreign = !(owner && owner->faction == u->faction); + bool foreign = !(owner && owner->faction == u->faction); if (!b) { cmistake(u, ord, u->building ? 6 : 145, MSG_EVENT); @@ -1922,7 +1922,7 @@ int name_cmd(struct unit *u, struct order *ord) region *r = u->region; char **s = NULL; param_t p; - boolean foreign = false; + bool foreign = false; const char *str; init_tokens(ord); @@ -2196,7 +2196,7 @@ static int mail_cmd(unit * u, struct order *ord) case P_FACTION: { - boolean see = false; + bool see = false; n = getfactionid(); @@ -2223,7 +2223,7 @@ static int mail_cmd(unit * u, struct order *ord) case P_UNIT: { - boolean see = false; + bool see = false; n = getid(); for (u2 = r->units; u2; u2 = u2->next) { @@ -2374,7 +2374,7 @@ int password_cmd(unit * u, struct order *ord) char pwbuf[32]; int i; const char *s; - boolean pwok = true; + bool pwok = true; init_tokens(ord); skip_token(); @@ -2440,7 +2440,7 @@ int send_cmd(unit * u, struct order *ord) return 0; } -static boolean display_item(faction * f, unit * u, const item_type * itype) +static bool display_item(faction * f, unit * u, const item_type * itype) { const char *name; const char *key; @@ -2473,7 +2473,7 @@ static boolean display_item(faction * f, unit * u, const item_type * itype) return true; } -static boolean display_potion(faction * f, unit * u, const potion_type * ptype) +static bool display_potion(faction * f, unit * u, const potion_type * ptype) { attrib *a; @@ -2497,7 +2497,7 @@ static boolean display_potion(faction * f, unit * u, const potion_type * ptype) return true; } -static boolean display_race(faction * f, unit * u, const race * rc) +static bool display_race(faction * f, unit * u, const race * rc) { const char *name, *key; const char *info; @@ -3076,7 +3076,7 @@ void restack_units(void) region *r; for (r = regions; r; r = r->next) { unit **up = &r->units; - boolean sorted = false; + bool sorted = false; while (*up) { unit *u = *up; if (!fval(u, UFL_MARK)) { @@ -3271,7 +3271,7 @@ int renumber_cmd(unit * u, order * ord) static building *age_building(building * b) { - static boolean init = false; + static bool init = false; static const building_type *bt_blessed; static const curse_type *ct_astralblock; if (!init) { @@ -3657,8 +3657,8 @@ void check_long_orders(unit * u) void update_long_order(unit * u) { order *ord; - boolean trade = false; - boolean hunger = LongHunger(u); + bool trade = false; + bool hunger = LongHunger(u); freset(u, UFL_MOVED); freset(u, UFL_LONGACTION); @@ -3873,7 +3873,7 @@ static void defaultorders(void) for (r = regions; r; r = r->next) { unit *u; for (u = r->units; u; u = u->next) { - boolean neworders = false; + bool neworders = false; order **ordp = &u->orders; while (*ordp != NULL) { order *ord = *ordp; @@ -4316,7 +4316,7 @@ int siege_cmd(unit * u, order * ord) building *b; int d, pooled; int bewaffnete, katapultiere = 0; - static boolean init = false; + static bool init = false; static const curse_type *magicwalls_ct; static item_type *it_catapultammo = NULL; static item_type *it_catapult = NULL; @@ -4432,7 +4432,7 @@ static int warn_password(void) { faction *f = factions; while (f) { - boolean pwok = true; + bool pwok = true; const char *c = f->passw; while (*c && pwok) { if (!isalnum((unsigned char)*c)) diff --git a/src/gamecode/laws.h b/src/gamecode/laws.h index 0d4cbd614..3cc5882e5 100755 --- a/src/gamecode/laws.h +++ b/src/gamecode/laws.h @@ -34,7 +34,7 @@ extern "C" { const char *s, struct unit *receiver); int init_data(const char *filename, const char *catalog); - boolean renamed_building(const struct building * b); + bool renamed_building(const struct building * b); int rename_building(struct unit * u, struct order * ord, struct building * b, const char *name); void get_food(struct region * r); extern int can_contact(const struct region *r, const struct unit *u, const struct unit *u2); diff --git a/src/gamecode/monster.c b/src/gamecode/monster.c index 1c4911cd1..4fe9d9ec2 100644 --- a/src/gamecode/monster.c +++ b/src/gamecode/monster.c @@ -70,7 +70,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define MAXILLUSION_TEXTS 3 -boolean monster_is_waiting(const unit * u) +bool monster_is_waiting(const unit * u) { if (fval(u, UFL_ISNEW | UFL_MOVED)) return true; diff --git a/src/gamecode/monster.h b/src/gamecode/monster.h index 0ae45a6bf..27a8f23f7 100644 --- a/src/gamecode/monster.h +++ b/src/gamecode/monster.h @@ -23,7 +23,7 @@ extern "C" { #endif void monster_kills_peasants(struct unit *u); - boolean monster_is_waiting(const struct unit *u); + bool monster_is_waiting(const struct unit *u); #ifdef __cplusplus } diff --git a/src/gamecode/randenc.c b/src/gamecode/randenc.c index 43d3370b2..196fdd5a0 100644 --- a/src/gamecode/randenc.c +++ b/src/gamecode/randenc.c @@ -153,7 +153,7 @@ static void dissolve_units(void) static int improve_all(faction * f, skill_t sk, int by_weeks) { unit *u; - boolean ret = by_weeks; + bool ret = by_weeks; for (u = f->units; u; u = u->nextF) { if (has_skill(u, sk)) { @@ -596,7 +596,7 @@ static int nb_armor(const unit * u, int index) } static int -damage_unit(unit * u, const char *dam, boolean physical, boolean magic) +damage_unit(unit * u, const char *dam, bool physical, bool magic) { int *hp = malloc(u->number * sizeof(int)); int h; @@ -980,7 +980,7 @@ void create_icebergs(void) for (r = regions; r; r = r->next) { if (r->terrain == newterrain(T_ICEBERG_SLEEP) && chance(0.05)) { - boolean has_ocean_neighbour = false; + bool has_ocean_neighbour = false; direction_t dir; region *rc; unit *u; @@ -1062,7 +1062,7 @@ static void orc_growth(void) for (r = regions; r; r = r->next) { unit *u; for (u = r->units; u; u = u->next) { - static boolean init = false; + static bool init = false; static const curse_type *ct_orcish = 0; curse *c = 0; if (!init) { diff --git a/src/gamecode/report.c b/src/gamecode/report.c index 2127d2940..c01ea5089 100644 --- a/src/gamecode/report.c +++ b/src/gamecode/report.c @@ -134,7 +134,7 @@ void rnl(FILE * F) fputc('\n', F); } -static void centre(FILE * F, const char *s, boolean breaking) +static void centre(FILE * F, const char *s, bool breaking) { /* Bei Namen die genau 80 Zeichen lang sind, kann es hier Probleme * geben. Seltsamerweise wird i dann auf MAXINT oder aehnlich @@ -698,7 +698,7 @@ nr_unit(FILE * F, const faction * f, const unit * u, int indent, int mode) attrib *a_otherfaction; char marker; int dh; - boolean isbattle = (boolean) (mode == see_battle); + bool isbattle = (bool) (mode == see_battle); char buf[8192]; if (fval(u->race, RCF_INVISIBLE)) @@ -735,7 +735,7 @@ nr_unit(FILE * F, const faction * f, const unit * u, int indent, int mode) static void rp_messages(FILE * F, message_list * msgs, faction * viewer, int indent, - boolean categorized) + bool categorized) { nrsection *section; if (!msgs) @@ -866,9 +866,9 @@ static void prices(FILE * F, const region * r, const faction * f) } -boolean see_border(const connection * b, const faction * f, const region * r) +bool see_border(const connection * b, const faction * f, const region * r) { - boolean cs = b->type->fvisible(b, f, r); + bool cs = b->type->fvisible(b, f, r); if (!cs) { cs = b->type->rvisible(b, r); if (!cs) { @@ -890,7 +890,7 @@ static void describe(FILE * F, const seen_region * sr, faction * f) { const region *r = sr->r; int n; - boolean dh; + bool dh; direction_t d; int trees; int saplings; @@ -899,12 +899,12 @@ static void describe(FILE * F, const seen_region * sr, faction * f) struct edge { struct edge *next; char *name; - boolean transparent; - boolean block; - boolean exist[MAXDIRECTIONS]; + bool transparent; + bool block; + bool exist[MAXDIRECTIONS]; direction_t lastd; } *edges = NULL, *e; - boolean see[MAXDIRECTIONS]; + bool see[MAXDIRECTIONS]; char buf[8192]; char *bufp = buf; size_t size = sizeof(buf); @@ -919,7 +919,7 @@ static void describe(FILE * F, const seen_region * sr, faction * f) continue; for (b = get_borders(r, r2); b;) { struct edge *e = edges; - boolean transparent = b->type->transparent(b, f); + bool transparent = b->type->transparent(b, f); const char *name = b->type->name(b, r, f, GF_DETAILED | GF_ARTICLE); if (!transparent) @@ -1235,7 +1235,7 @@ static void describe(FILE * F, const seen_region * sr, faction * f) if (edges) rnl(F); for (e = edges; e; e = e->next) { - boolean first = true; + bool first = true; bufp = buf; size = sizeof(buf) - 1; for (d = 0; d != MAXDIRECTIONS; ++d) { @@ -1455,7 +1455,7 @@ static int buildingmaintenance(const building * b, const resource_type * rtype) { const building_type *bt = b->type; int c, cost = 0; - static boolean init = false; + static bool init = false; static const curse_type *nocost_ct; if (!init) { init = true; @@ -1775,7 +1775,7 @@ static void guards(FILE * F, const region * r, const faction * see) unit *u; int i; - boolean tarned = false; + bool tarned = false; /* Bewachung */ for (u = r->units; u; u = u->next) { @@ -2579,7 +2579,7 @@ static void add_find(faction * f, unit * u, faction * f2) static void update_find(void) { region *r; - static boolean initial = true; + static bool initial = true; if (initial) for (r = regions; r; r = r->next) { @@ -2601,10 +2601,10 @@ static void update_find(void) initial = false; } -boolean kann_finden(faction * f1, faction * f2) +bool kann_finden(faction * f1, faction * f2) { update_find(); - return (boolean) (can_find(f1, f2) != NULL); + return (bool) (can_find(f1, f2) != NULL); } /******* end summary ******/ diff --git a/src/gamecode/study.c b/src/gamecode/study.c index 2919e8b1f..653ef5bb9 100644 --- a/src/gamecode/study.c +++ b/src/gamecode/study.c @@ -87,7 +87,7 @@ magic_t getmagicskill(const struct locale * lang) /* ------------------------------------------------------------- */ /* Vertraute und Kr�ten sind keine Migranten */ -boolean is_migrant(unit * u) +bool is_migrant(unit * u) { if (u->race == u->faction->race) return false; @@ -103,7 +103,7 @@ boolean is_migrant(unit * u) } /* ------------------------------------------------------------- */ -boolean magic_lowskill(unit * u) +bool magic_lowskill(unit * u) { return (u->race == new_race[RC_TOAD]) ? true : false; } @@ -174,7 +174,7 @@ static int study_days(unit * student, skill_t sk) static int teach_unit(unit * teacher, unit * student, int nteaching, skill_t sk, - boolean report, int *academy) + bool report, int *academy) { teaching_info *teach = NULL; attrib *a; @@ -393,7 +393,7 @@ int teach_cmd(unit * u, struct order *ord) while (!parser_end()) { unit *u2 = getunit(r, u->faction); - boolean feedback; + bool feedback; ++count; /* Falls die Unit nicht gefunden wird, Fehler melden */ @@ -763,7 +763,7 @@ int learn_cmd(unit * u, order * ord) while (teach->teachers[index] && index != MAXTEACHERS) { unit *teacher = teach->teachers[index++]; if (teacher->faction != u->faction) { - boolean feedback = alliedunit(u, teacher->faction, HELP_GUARD); + bool feedback = alliedunit(u, teacher->faction, HELP_GUARD); if (feedback) { ADDMSG(&teacher->faction->msgs, msg_message("teach_teacher", "teacher student skill level", teacher, u, sk, diff --git a/src/gamecode/study.h b/src/gamecode/study.h index 3527e3cec..182e364ee 100644 --- a/src/gamecode/study.h +++ b/src/gamecode/study.h @@ -27,7 +27,7 @@ extern "C" { extern int learn_cmd(struct unit *u, struct order *ord); extern magic_t getmagicskill(const struct locale *lang); - extern boolean is_migrant(struct unit *u); + extern bool is_migrant(struct unit *u); extern int study_cost(struct unit *u, skill_t talent); #define MAXTEACHERS 4 diff --git a/src/gamecode/summary.c b/src/gamecode/summary.c index 03690dee7..1d3c73e2f 100644 --- a/src/gamecode/summary.c +++ b/src/gamecode/summary.c @@ -132,7 +132,7 @@ static void writeturn(void) fclose(f); } -void report_summary(summary * s, summary * o, boolean full) +void report_summary(summary * s, summary * o, bool full) { FILE *F = NULL; int i, newplayers = 0; diff --git a/src/gamecode/summary.h b/src/gamecode/summary.h index 5da62e688..bb2ae04b7 100644 --- a/src/gamecode/summary.h +++ b/src/gamecode/summary.h @@ -17,7 +17,7 @@ extern "C" { struct summary; extern void report_summary(struct summary *n, struct summary *o, - boolean full); + bool full); extern struct summary *make_summary(void); #ifdef __cplusplus diff --git a/src/gamecode/xmlreport.c b/src/gamecode/xmlreport.c index 5b93dc887..9ccf72a31 100644 --- a/src/gamecode/xmlreport.c +++ b/src/gamecode/xmlreport.c @@ -213,10 +213,10 @@ static xmlNodePtr xml_unit(report_context * ctx, unit * u, int mode) xml_context *xct = (xml_context *) ctx->userdata; xmlNodePtr node = xmlNewNode(xct->ns_atl, BAD_CAST "unit"); static const curse_type *itemcloak_ct = 0; - static boolean init = false; + static bool init = false; xmlNodePtr child; const char *str, *rcname, *rcillusion; - boolean disclosure = (ctx->f == u->faction || omniscient(ctx->f)); + bool disclosure = (ctx->f == u->faction || omniscient(ctx->f)); /* TODO: hitpoints, aura, combatspells, curses */ @@ -391,7 +391,7 @@ static xmlNodePtr xml_unit(report_context * ctx, unit * u, int mode) if (disclosure) { show = u->items; } else { - boolean see_items = (mode >= see_unit); + bool see_items = (mode >= see_unit); if (see_items) { if (itemcloak_ct && curse_active(get_curse(u->attribs, itemcloak_ct))) { see_items = false; diff --git a/src/gmtool.c b/src/gmtool.c index 57d715501..83d637d04 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -356,7 +356,7 @@ static void paint_status(window * wnd, const state * st) wclrtoeol(win); } -static boolean handle_info_region(window * wnd, state * st, int c) +static bool handle_info_region(window * wnd, state * st, int c) { return false; } @@ -1281,7 +1281,7 @@ curses_readline(struct lua_State *L, char *buffer, size_t size, return buffer[0] != 0; } -void seed_players(const char *filename, boolean new_island) +void seed_players(const char *filename, bool new_island) { newfaction *players = read_newfactions(filename); if (players != NULL) { diff --git a/src/gmtool.h b/src/gmtool.h index fa2df80e7..0359973b5 100644 --- a/src/gmtool.h +++ b/src/gmtool.h @@ -33,7 +33,7 @@ extern "C" { void state_close(struct state *); void make_block(int x, int y, int radius, const struct terrain_type *terrain); - void seed_players(const char *filename, boolean new_island); + void seed_players(const char *filename, bool new_island); #ifdef __cplusplus } diff --git a/src/gmtool_structs.h b/src/gmtool_structs.h index 49acbf526..1f3e4e9a7 100644 --- a/src/gmtool_structs.h +++ b/src/gmtool_structs.h @@ -70,13 +70,13 @@ extern "C" { } state; typedef struct window { - boolean(*handlekey) (struct window * win, struct state * st, int key); + bool(*handlekey) (struct window * win, struct state * st, int key); void (*paint) (struct window * win, const struct state * st); WINDOW *handle; struct window *next; struct window *prev; - boolean initialized; + bool initialized; int update; } window; diff --git a/src/items/phoenixcompass.c b/src/items/phoenixcompass.c index e26adfa8e..9787d4e9d 100644 --- a/src/items/phoenixcompass.c +++ b/src/items/phoenixcompass.c @@ -45,7 +45,7 @@ use_phoenixcompass(struct unit *u, const struct item_type *itype, region *r; unit *closest_phoenix = NULL; int closest_phoenix_distance = INT_MAX; - boolean confusion = false; + bool confusion = false; direction_t direction; unit *u2; direction_t closest_neighbour_direction = 0; diff --git a/src/items/weapons.c b/src/items/weapons.c index 05fbc31a5..7b817510a 100644 --- a/src/items/weapons.c +++ b/src/items/weapons.c @@ -38,7 +38,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* damage types */ -static boolean +static bool attack_firesword(const troop * at, const struct weapon_type *wtype, int *casualties) { @@ -83,7 +83,7 @@ attack_firesword(const troop * at, const struct weapon_type *wtype, #define CATAPULT_ATTACKS 6 -static boolean +static bool attack_catapult(const troop * at, const struct weapon_type *wtype, int *casualties) { diff --git a/src/kernel/alliance.c b/src/kernel/alliance.c index ede4b0dfd..afd31343d 100644 --- a/src/kernel/alliance.c +++ b/src/kernel/alliance.c @@ -452,7 +452,7 @@ int victorycondition(const alliance * al, const char *name) const struct item_type *itype = it_find(*igem); quicklist *flist = al->members; int qi; - boolean found = false; + bool found = false; assert(itype != NULL); for (qi = 0; flist && !found; ql_advance(&flist, &qi, 1)) { diff --git a/src/kernel/battle.c b/src/kernel/battle.c index 6417c1b91..7a4f1cd12 100644 --- a/src/kernel/battle.c +++ b/src/kernel/battle.c @@ -186,7 +186,7 @@ static char *sidename(side * s) return sidename_buf[bufno++]; } -static const char *sideabkz(side * s, boolean truename) +static const char *sideabkz(side * s, bool truename) { static char sideabkz_buf[8]; /* STATIC_RESULT: used for return, not across calls */ const faction *f = (s->stealthfaction @@ -214,7 +214,7 @@ static void message_faction(battle * b, faction * f, struct message *m) add_message(&f->battles->msgs, m); } -int armedmen(const unit * u, boolean siege_weapons) +int armedmen(const unit * u, bool siege_weapons) { item *itm; int n = 0; @@ -273,7 +273,7 @@ static void fbattlerecord(battle * b, faction * f, const char *s) #define enemy(as, ds) (as->relations[ds->index]&E_ENEMY) #define friendly(as, ds) (as->relations[ds->index]&E_FRIEND) -static boolean set_enemy(side * as, side * ds, boolean attacking) +static bool set_enemy(side * as, side * ds, bool attacking) { int i; for (i = 0; i != MAXSIDES; ++i) { @@ -366,11 +366,11 @@ fighter *select_corpse(battle * b, fighter * af) return NULL; } -boolean helping(const side * as, const side * ds) +bool helping(const side * as, const side * ds) { if (as->faction == ds->faction) return true; - return (boolean) (!enemy(as, ds) && allysf(as, ds->faction)); + return (bool) (!enemy(as, ds) && allysf(as, ds->faction)); } int statusrow(int status) @@ -414,7 +414,7 @@ static double hpflee(int status) static int get_row(const side * s, int row, const side * vs) { - boolean counted[MAXSIDES]; + bool counted[MAXSIDES]; int enemyfront = 0; int line, result; int retreat = 0; @@ -560,7 +560,7 @@ contest(int skdiff, const troop dt, const armor_type * ar, } } -static boolean is_riding(const troop t) +static bool is_riding(const troop t) { if (t.fighter->building != NULL) return false; @@ -569,7 +569,7 @@ static boolean is_riding(const troop t) return false; } -static weapon *preferred_weapon(const troop t, boolean attacking) +static weapon *preferred_weapon(const troop t, bool attacking) { weapon *missile = t.fighter->person[t.index].missile; weapon *melee = t.fighter->person[t.index].melee; @@ -586,8 +586,8 @@ static weapon *preferred_weapon(const troop t, boolean attacking) return melee; } -static weapon *select_weapon(const troop t, boolean attacking, - boolean ismissile) +static weapon *select_weapon(const troop t, bool attacking, + bool ismissile) /* select the primary weapon for this trooper */ { if (attacking) { @@ -604,7 +604,7 @@ static weapon *select_weapon(const troop t, boolean attacking, return preferred_weapon(t, attacking); } -static boolean i_canuse(const unit * u, const item_type * itype) +static bool i_canuse(const unit * u, const item_type * itype) { if (itype->canuse) { return itype->canuse(u, itype); @@ -613,7 +613,7 @@ static boolean i_canuse(const unit * u, const item_type * itype) } static int -weapon_skill(const weapon_type * wtype, const unit * u, boolean attacking) +weapon_skill(const weapon_type * wtype, const unit * u, bool attacking) /* the 'pure' skill when using this weapon to attack or defend. * only undiscriminate modifiers (not affected by troops or enemies) * are taken into account, e.g. no horses, magic, etc. */ @@ -729,8 +729,8 @@ static int CavalryBonus(const unit * u, troop enemy, int type) } static int -weapon_effskill(troop t, troop enemy, const weapon * w, boolean attacking, - boolean missile) +weapon_effskill(troop t, troop enemy, const weapon * w, bool attacking, + bool missile) /* effektiver Waffenskill w�hrend des Kampfes */ { /* In dieser Runde alle die Modifier berechnen, die fig durch die @@ -810,7 +810,7 @@ weapon_effskill(troop t, troop enemy, const weapon * w, boolean attacking, return skill; } -static const armor_type *select_armor(troop t, boolean shield) +static const armor_type *select_armor(troop t, bool shield) { unsigned int type = shield ? ATF_SHIELD : 0; unit *u = t.fighter->unit; @@ -858,7 +858,7 @@ int select_magicarmor(troop t) } /* Sind side ds und Magier des meffect verb�ndet, dann return 1*/ -boolean meffect_protection(battle * b, meffect * s, side * ds) +bool meffect_protection(battle * b, meffect * s, side * ds) { if (!s->magician->alive) return false; @@ -872,7 +872,7 @@ boolean meffect_protection(battle * b, meffect * s, side * ds) } /* Sind side as und Magier des meffect verfeindet, dann return 1*/ -boolean meffect_blocked(battle * b, meffect * s, side * as) +bool meffect_blocked(battle * b, meffect * s, side * as) { if (!s->magician->alive) return false; @@ -1051,8 +1051,8 @@ static int natural_armor(unit * du) return an; } -boolean -terminate(troop dt, troop at, int type, const char *damage, boolean missile) +bool +terminate(troop dt, troop at, int type, const char *damage, bool missile) { item **pitm; fighter *df = dt.fighter; @@ -1076,7 +1076,7 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile) const weapon *weapon; int rda, sk = 0, sd; - boolean magic = false; + bool magic = false; int da = dice_rand(damage); assert(du->number > 0); @@ -1864,7 +1864,7 @@ int skilldiff(troop at, troop dt, int dist) } if (df->building) { - boolean init = false; + bool init = false; static const curse_type *strongwall_ct, *magicwalls_ct; if (!init) { strongwall_ct = ct_find("strongwall"); @@ -1934,7 +1934,7 @@ int getreload(troop at) static void debug_hit(troop at, const weapon * awp, troop dt, const weapon * dwp, - int skdiff, int dist, boolean success) + int skdiff, int dist, bool success) { fprintf(bdebug, "%.4s/%d [%6s/%d] %s %.4s/%d [%6s/%d] with %d, distance %d\n", unitid(at.fighter->unit), at.index, @@ -2112,8 +2112,8 @@ static void attack(battle * b, troop ta, const att * a, int numattack) if (getreload(ta)) { ta.fighter->person[ta.index].reload--; } else { - boolean standard_attack = true; - boolean reload = false; + bool standard_attack = true; + bool reload = false; /* spezialattacken der waffe nur, wenn erste attacke in der runde. * sonst helden mit feuerschwertern zu m�chtig */ if (numattack == 0 && wp && wp->type->attack) { @@ -2127,7 +2127,7 @@ static void attack(battle * b, troop ta, const att * a, int numattack) } } if (standard_attack) { - boolean missile = false; + bool missile = false; if (wp && fval(wp->type, WTF_MISSILE)) missile = true; if (missile) { @@ -2560,7 +2560,7 @@ static void loot_items(fighter * corpse) } } -static boolean seematrix(const faction * f, const side * s) +static bool seematrix(const faction * f, const side * s) { if (f == s->faction) return true; @@ -2626,7 +2626,7 @@ static void aftermath(battle * b) side *s; int dead_players = 0; bfaction *bf; - boolean ships_damaged = (boolean) (b->turn + (b->has_tactics_turn ? 1 : 0) > 2); /* only used for ship damage! */ + bool ships_damaged = (bool) (b->turn + (b->has_tactics_turn ? 1 : 0) > 2); /* only used for ship damage! */ for (s = b->sides; s != b->sides + b->nsides; ++s) { fighter *df; @@ -2672,7 +2672,7 @@ static void aftermath(battle * b) for (s = b->sides; s != b->sides + b->nsides; ++s) { int snumber = 0; fighter *df; - boolean relevant = false; /* Kampf relevant f�r diese Partei? */ + bool relevant = false; /* Kampf relevant f�r diese Partei? */ if (!fval(s, SIDE_HASGUARDS)) { relevant = true; } @@ -2920,7 +2920,7 @@ static void print_fighters(battle * b, const side * s) } } -boolean is_attacker(const fighter * fig) +bool is_attacker(const fighter * fig) { return fval(fig, FIG_ATTACKER) != 0; } @@ -2939,7 +2939,7 @@ static void print_header(battle * b) message *m; faction *f = bf->faction; const char *lastf = NULL; - boolean first = false; + bool first = false; side *s; char *bufp = zText; size_t size = sizeof(zText) - 1; @@ -3129,7 +3129,7 @@ static void print_stats(battle * b) } } -static int weapon_weight(const weapon * w, boolean missile) +static int weapon_weight(const weapon * w, bool missile) { if (missile == i2b(fval(w->type, WTF_MISSILE))) { return w->attackskill + w->defenseskill; @@ -3137,7 +3137,7 @@ static int weapon_weight(const weapon * w, boolean missile) return 0; } -fighter *make_fighter(battle * b, unit * u, side * s1, boolean attack) +fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) { #define WMAX 20 weapon weapons[WMAX]; @@ -3153,7 +3153,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, boolean attack) int berserk; int strongmen; int speeded = 0, speed = 1; - boolean pr_aid = false; + bool pr_aid = false; int rest; const group *g = NULL; const attrib *a = a_find(u->attribs, &at_otherfaction); @@ -3459,7 +3459,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, boolean attack) return fig; } -static int join_battle(battle * b, unit * u, boolean attack, fighter ** cp) +static int join_battle(battle * b, unit * u, bool attack, fighter ** cp) { side *s; fighter *c = NULL; @@ -3650,8 +3650,8 @@ static int *get_alive(side * s) static int battle_report(battle * b) { side *s, *s2; - boolean cont = false; - boolean komma; + bool cont = false; + bool komma; bfaction *bf; for (s = b->sides; s != b->sides + b->nsides; ++s) { @@ -3876,11 +3876,11 @@ static void flee(const troop dt) kill_troop(dt); } -static boolean init_battle(region * r, battle ** bp) +static bool init_battle(region * r, battle ** bp) { battle *b = NULL; unit *u; - boolean fighting = false; + bool fighting = false; /* list_foreach geht nicht, wegen flucht */ for (u = r->units; u != NULL; u = u->next) { @@ -3890,7 +3890,7 @@ static boolean init_battle(region * r, battle ** bp) order *ord; for (ord = u->orders; ord; ord = ord->next) { - static boolean init = false; + static bool init = false; static const curse_type *peace_ct, *slave_ct, *calm_ct; if (!init) { @@ -3989,7 +3989,7 @@ static boolean init_battle(region * r, battle ** bp) if (calm_ct) { attrib *a = a_find(u->attribs, &at_curse); - boolean calm = false; + bool calm = false; while (a && a->type == &at_curse) { curse *c = (curse *) a->data.v; if (c->type == calm_ct @@ -4239,7 +4239,7 @@ static void battle_flee(battle * b) void do_battle(region * r) { battle *b = NULL; - boolean fighting = false; + bool fighting = false; ship *sh; static int init_rules = 0; diff --git a/src/kernel/battle.h b/src/kernel/battle.h index bc8acc66f..c962e32bb 100644 --- a/src/kernel/battle.h +++ b/src/kernel/battle.h @@ -46,7 +46,7 @@ extern "C" { struct bfaction *next; struct side *sides; struct faction *faction; - boolean attacker; + bool attacker; } bfaction; typedef struct tactics { @@ -94,9 +94,9 @@ extern "C" { struct quicklist *meffects; int max_tactics; int turn; - boolean has_tactics_turn; + bool has_tactics_turn; int keeploot; - boolean reelarrow; + bool reelarrow; int alive; struct { const struct side *as; @@ -218,8 +218,8 @@ extern "C" { extern int count_enemies(struct battle *b, const struct fighter *af, int minrow, int maxrow, int select); - extern boolean terminate(troop dt, troop at, int type, const char *damage, - boolean missile); + extern bool terminate(troop dt, troop at, int type, const char *damage, + bool missile); extern void message_all(battle * b, struct message *m); extern int hits(troop at, troop dt, weapon * awp); extern void damage_building(struct battle *b, struct building *bldg, @@ -229,18 +229,18 @@ extern "C" { extern int count_allies(const struct side *as, int minrow, int maxrow, int select, int allytype); extern int get_unitrow(const struct fighter *af, const struct side *vs); - extern boolean helping(const struct side *as, const struct side *ds); + extern bool helping(const struct side *as, const struct side *ds); extern void rmfighter(fighter * df, int i); extern struct fighter *select_corpse(struct battle *b, struct fighter *af); extern int statusrow(int status); extern void drain_exp(struct unit *u, int d); extern void kill_troop(troop dt); extern void remove_troop(troop dt); /* not the same as the badly named rmtroop */ - extern boolean is_attacker(const fighter * fig); + extern bool is_attacker(const fighter * fig); extern struct battle *make_battle(struct region * r); extern fighter *make_fighter(struct battle *b, struct unit *u, side * s, - boolean attack); + bool attack); extern struct side *make_side(struct battle * b, const struct faction * f, const struct group * g, unsigned int flags, const struct faction * stealthfaction); diff --git a/src/kernel/building.c b/src/kernel/building.c index 0b695622d..4ba7cad10 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -180,7 +180,7 @@ const char *buildingtype(const building_type * btype, const building * b, int bsize) { const char *s = NULL; - static boolean init_generic = false; + static bool init_generic = false; static const struct building_type *bt_generic; if (!init_generic) { @@ -451,7 +451,7 @@ building *new_building(const struct building_type * btype, region * r, { building **bptr = &r->buildings; building *b = (building *) calloc(1, sizeof(building)); - static boolean init_lighthouse = false; + static bool init_lighthouse = false; static const struct building_type *bt_lighthouse = 0; const char *bname = 0; char buffer[32]; @@ -501,7 +501,7 @@ void remove_building(building ** blist, building * b) { unit *u; static const struct building_type *bt_caravan, *bt_dam, *bt_tunnel; - static boolean init = false; + static bool init = false; if (!init) { init = true; diff --git a/src/kernel/config.c b/src/kernel/config.c index e66dc0f79..08970f71b 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -95,8 +95,8 @@ struct settings global = { FILE *logfile; FILE *updatelog; const struct race *new_race[MAXRACES]; -boolean sqlpatch = false; -boolean battledebug = false; +bool sqlpatch = false; +bool battledebug = false; int turn = 0; int NewbieImmunity(void) @@ -110,7 +110,7 @@ int NewbieImmunity(void) return value; } -boolean IsImmune(const faction * f) +bool IsImmune(const faction * f) { return !fval(f, FFL_NPC) && f->age < NewbieImmunity(); } @@ -143,7 +143,7 @@ static int ally_flag(const char *s, int help_mask) return 0; } -boolean ExpensiveMigrants(void) +bool ExpensiveMigrants(void) { static int value = -1; static int gamecookie = -1; @@ -617,7 +617,7 @@ int shipspeed(const ship * sh, const unit * u) { double k = sh->type->range; static const curse_type *stormwind_ct, *nodrift_ct; - static boolean init; + static bool init; attrib *a; curse *c; @@ -829,7 +829,7 @@ int eff_stealth(const unit * u, const region * r) return e; } -boolean unit_has_cursed_item(unit * u) +bool unit_has_cursed_item(unit * u) { item *itm = u->items; while (itm) { @@ -855,7 +855,7 @@ static void init_gms(void) static int autoalliance(const plane * pl, const faction * sf, const faction * f2) { - static boolean init = false; + static bool init = false; if (!init) { init_gms(); init = true; @@ -959,7 +959,7 @@ int alliedunit(const unit * u, const faction * f2, int mode) return 0; } -boolean +bool seefaction(const faction * f, const region * r, const unit * u, int modifier) { if (((f == u->faction) || !fval(u, UFL_ANON_FACTION)) @@ -968,7 +968,7 @@ seefaction(const faction * f, const region * r, const unit * u, int modifier) return false; } -boolean +bool cansee(const faction * f, const region * r, const unit * u, int modifier) /* r kann != u->region sein, wenn es um durchreisen geht */ /* und es muss niemand aus f in der region sein, wenn sie vom Turm @@ -977,7 +977,7 @@ cansee(const faction * f, const region * r, const unit * u, int modifier) int stealth, rings; unit *u2 = r->units; static const item_type *itype_grail; - static boolean init; + static bool init; if (!init) { init = true; @@ -1037,7 +1037,7 @@ cansee(const faction * f, const region * r, const unit * u, int modifier) return false; } -boolean cansee_unit(const unit * u, const unit * target, int modifier) +bool cansee_unit(const unit * u, const unit * target, int modifier) /* target->region kann != u->region sein, wenn es um durchreisen geht */ { if (fval(target->race, RCF_INVISIBLE) || target->number == 0) @@ -1073,7 +1073,7 @@ boolean cansee_unit(const unit * u, const unit * target, int modifier) return false; } -boolean +bool cansee_durchgezogen(const faction * f, const region * r, const unit * u, int modifier) /* r kann != u->region sein, wenn es um durchreisen geht */ @@ -1144,7 +1144,7 @@ static attrib_type at_lighthouse = { */ void update_lighthouse(building * lh) { - static boolean init_lighthouse = false; + static bool init_lighthouse = false; static const struct building_type *bt_lighthouse = 0; if (!init_lighthouse) { @@ -1256,7 +1256,7 @@ void init_tokens(const struct order *ord) } void -parse(keyword_t kword, int (*dofun) (unit *, struct order *), boolean thisorder) +parse(keyword_t kword, int (*dofun) (unit *, struct order *), bool thisorder) { region *r; @@ -1502,7 +1502,7 @@ int read_unitid(const faction * f, const region * r) } /* exported symbol */ -boolean getunitpeasants; +bool getunitpeasants; unit *getunitg(const region * r, const faction * f) { int n = read_unitid(f, r); @@ -1565,7 +1565,7 @@ void freestrlist(strlist * s) /* - Meldungen und Fehler ------------------------------------------------- */ -boolean lomem = false; +bool lomem = false; /* - Namen der Strukturen -------------------------------------- */ typedef char name[OBJECTIDSIZE + 1]; @@ -1615,7 +1615,7 @@ char *cstring(const char *s) } building *largestbuilding(const region * r, cmp_building_cb cmp_gt, - boolean imaginary) + bool imaginary) { building *b, *best = NULL; @@ -1720,9 +1720,9 @@ unit *createunit(region * r, faction * f, int number, const struct race * rc) return create_unit(r, f, number, rc, 0, NULL, NULL); } -boolean idle(faction * f) +bool idle(faction * f) { - return (boolean) (f ? false : true); + return (bool) (f ? false : true); } int maxworkingpeasants(const struct region *r) @@ -1765,7 +1765,7 @@ int lighthouse_range(const building * b, const faction * f) return d; } -boolean check_leuchtturm(region * r, faction * f) +bool check_leuchtturm(region * r, faction * f) { attrib *a; @@ -2364,7 +2364,7 @@ void remove_empty_units(void) } } -boolean faction_id_is_unused(int id) +bool faction_id_is_unused(int id) { return findfaction(id) == NULL; } @@ -2461,7 +2461,7 @@ int lifestyle(const unit * u) return need; } -boolean has_horses(const struct unit * u) +bool has_horses(const struct unit * u) { item *itm = u->items; for (; itm; itm = itm->next) { @@ -2471,7 +2471,7 @@ boolean has_horses(const struct unit * u) return false; } -boolean hunger(int number, unit * u) +bool hunger(int number, unit * u) { region *r = u->region; int dead = 0, hpsub = 0; @@ -2520,7 +2520,7 @@ boolean hunger(int number, unit * u) return (dead || hpsub); } -void plagues(region * r, boolean ismagic) +void plagues(region * r, bool ismagic) { int peasants; int i; @@ -2584,7 +2584,7 @@ int cmp_wage(const struct building *b, const building * a) return -1; } -boolean is_owner_building(const struct building * b) +bool is_owner_building(const struct building * b) { region *r = b->region; if (b->type->taxes && r->land && r->land->ownership) { @@ -2754,7 +2754,7 @@ default_wage(const region * r, const faction * f, const race * rc, int in_turn) attrib *a; const building_type *artsculpture_type = bt_find("artsculpture"); static const curse_type *drought_ct, *blessedharvest_ct; - static boolean init; + static bool init; if (!init) { init = true; @@ -2895,7 +2895,7 @@ int movewhere(const unit * u, const char *token, region * r, region ** resultp) return E_MOVE_OK; } -boolean move_blocked(const unit * u, const region * r, const region * r2) +bool move_blocked(const unit * u, const region * r, const region * r2) { connection *b; curse *c; @@ -2944,7 +2944,7 @@ int lovar(double xpct_x2) return (rng_int() % n + rng_int() % n) / 1000; } -boolean has_limited_skills(const struct unit * u) +bool has_limited_skills(const struct unit * u) { if (has_skill(u, SK_MAGIC) || has_skill(u, SK_ALCHEMY) || has_skill(u, SK_TACTICS) || has_skill(u, SK_HERBALISM) || diff --git a/src/kernel/config.h b/src/kernel/config.h index 6e8a1a142..e85325bc1 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -111,7 +111,7 @@ extern "C" { extern int shipspeed(const struct ship *sh, const struct unit *u); -#define i2b(i) ((boolean)((i)?(true):(false))) +#define i2b(i) ((bool)((i)?(true):(false))) typedef struct ally { struct ally *next; @@ -136,10 +136,10 @@ extern "C" { extern int verbosity; /* parteinummern */ - extern boolean faction_id_is_unused(int); + extern bool faction_id_is_unused(int); /* leuchtturm */ - extern boolean check_leuchtturm(struct region *r, struct faction *f); + extern bool check_leuchtturm(struct region *r, struct faction *f); extern void update_lighthouse(struct building *lh); extern int lighthouse_range(const struct building *b, const struct faction *f); @@ -159,7 +159,7 @@ extern "C" { void addstrlist(strlist ** SP, const char *s); - int armedmen(const struct unit *u, boolean siege_weapons); + int armedmen(const struct unit *u, bool siege_weapons); unsigned int atoip(const char *s); unsigned int getuint(void); @@ -188,13 +188,13 @@ extern "C" { #define factionid(x) itoa36((x)->no) #define curseid(x) itoa36((x)->no) - extern boolean cansee(const struct faction *f, const struct region *r, + extern bool cansee(const struct faction *f, const struct region *r, const struct unit *u, int modifier); - boolean cansee_durchgezogen(const struct faction *f, const struct region *r, + bool cansee_durchgezogen(const struct faction *f, const struct region *r, const struct unit *u, int modifier); - extern boolean cansee_unit(const struct unit *u, const struct unit *target, + extern bool cansee_unit(const struct unit *u, const struct unit *target, int modifier); - boolean seefaction(const struct faction *f, const struct region *r, + bool seefaction(const struct faction *f, const struct region *r, const struct unit *u, int modifier); extern int effskill(const struct unit *u, skill_t sk); @@ -210,7 +210,7 @@ extern "C" { extern struct unit *createunit(struct region *r, struct faction *f, int number, const struct race *rc); extern void create_unitid(struct unit *u, int id); - extern boolean getunitpeasants; + extern bool getunitpeasants; extern struct unit *getunitg(const struct region *r, const struct faction *f); extern struct unit *getunit(const struct region *r, const struct faction *f); @@ -242,7 +242,7 @@ extern "C" { typedef int (*cmp_building_cb) (const struct building * b, const struct building * a); struct building *largestbuilding(const struct region *r, cmp_building_cb, - boolean imaginary); + bool imaginary); int cmp_wage(const struct building *b, const struct building *bother); int cmp_taxes(const struct building *b, const struct building *bother); int cmp_current_owner(const struct building *b, @@ -265,7 +265,7 @@ extern "C" { extern int count_migrants(const struct faction *f); extern int count_maxmigrants(const struct faction *f); - extern boolean has_limited_skills(const struct unit *u); + extern bool has_limited_skills(const struct unit *u); extern const struct race *findrace(const char *, const struct locale *); int eff_stealth(const struct unit *u, const struct region *r); @@ -273,7 +273,7 @@ extern "C" { int check_option(struct faction *f, int option); extern void parse(keyword_t kword, int (*dofun) (struct unit *, - struct order *), boolean thisorder); + struct order *), bool thisorder); /* Anzahl Personen in einer Einheit festlegen. NUR (!) mit dieser Routine, * sonst gro�es Ungl�ck. Durch asserts an ein paar Stellen abgesichert. */ @@ -293,8 +293,8 @@ extern "C" { void fhash(struct faction *f); void funhash(struct faction *f); - boolean idle(struct faction *f); - boolean unit_has_cursed_item(struct unit *u); + bool idle(struct faction *f); + bool unit_has_cursed_item(struct unit *u); /* simple garbage collection: */ void *gc_add(void *p); @@ -344,18 +344,18 @@ extern "C" { */ unsigned int guard_flags(const struct unit *u); - extern boolean hunger(int number, struct unit *u); + extern bool hunger(int number, struct unit *u); extern int lifestyle(const struct unit *); extern int besieged(const struct unit *u); extern int maxworkingpeasants(const struct region *r); - extern boolean has_horses(const struct unit *u); + extern bool has_horses(const struct unit *u); extern int markets_module(void); extern int wage(const struct region *r, const struct faction *f, const struct race *rc, int in_turn); extern int maintenance_cost(const struct unit *u); extern struct message *movement_error(struct unit *u, const char *token, struct order *ord, int error_code); - extern boolean move_blocked(const struct unit *u, const struct region *src, + extern bool move_blocked(const struct unit *u, const struct region *src, const struct region *dest); extern void add_income(struct unit *u, int type, int want, int qty); @@ -392,7 +392,7 @@ extern "C" { const char *gamename; struct attrib *attribs; unsigned int data_turn; - boolean disabled[MAXKEYWORDS]; + bool disabled[MAXKEYWORDS]; struct param *parameters; void *vm_state; float producexpchance; @@ -409,9 +409,9 @@ extern "C" { extern int produceexp(struct unit *u, skill_t sk, int n); - extern boolean battledebug; - extern boolean sqlpatch; - extern boolean lomem; /* save memory */ + extern bool battledebug; + extern bool sqlpatch; + extern bool lomem; /* save memory */ extern const char *dbrace(const struct race *rc); @@ -421,19 +421,19 @@ extern "C" { extern float get_param_flt(const struct param *p, const char *name, float def); - extern boolean ExpensiveMigrants(void); + extern bool ExpensiveMigrants(void); extern int NMRTimeout(void); extern int LongHunger(const struct unit *u); extern int SkillCap(skill_t sk); extern int NewbieImmunity(void); - extern boolean IsImmune(const struct faction *f); + extern bool IsImmune(const struct faction *f); extern int AllianceAuto(void); /* flags that allied factions get automatically */ extern int AllianceRestricted(void); /* flags restricted to allied factions */ extern int HelpMask(void); /* flags restricted to allied factions */ extern struct order *default_order(const struct locale *lang); extern int entertainmoney(const struct region *r); - extern void plagues(struct region *r, boolean ismagic); + extern void plagues(struct region *r, bool ismagic); typedef struct helpmode { const char *name; int status; diff --git a/src/kernel/connection.c b/src/kernel/connection.c index 5d4d24d19..7bbb2e75a 100644 --- a/src/kernel/connection.c +++ b/src/kernel/connection.c @@ -224,21 +224,21 @@ void b_write(const connection * b, storage * store) } } -boolean b_transparent(const connection * b, const struct faction *f) +bool b_transparent(const connection * b, const struct faction *f) { unused(b); unused(f); return true; } -boolean b_opaque(const connection * b, const struct faction * f) +bool b_opaque(const connection * b, const struct faction * f) { unused(b); unused(f); return false; } -boolean b_blockall(const connection * b, const unit * u, const region * r) +bool b_blockall(const connection * b, const unit * u, const region * r) { unused(u); unused(r); @@ -246,7 +246,7 @@ boolean b_blockall(const connection * b, const unit * u, const region * r) return true; } -boolean b_blocknone(const connection * b, const unit * u, const region * r) +bool b_blocknone(const connection * b, const unit * u, const region * r) { unused(u); unused(r); @@ -254,12 +254,12 @@ boolean b_blocknone(const connection * b, const unit * u, const region * r) return false; } -boolean b_rvisible(const connection * b, const region * r) +bool b_rvisible(const connection * b, const region * r) { - return (boolean) (b->to == r || b->from == r); + return (bool) (b->to == r || b->from == r); } -boolean b_fvisible(const connection * b, const struct faction * f, +bool b_fvisible(const connection * b, const struct faction * f, const region * r) { unused(r); @@ -268,21 +268,21 @@ boolean b_fvisible(const connection * b, const struct faction * f, return true; } -boolean b_uvisible(const connection * b, const unit * u) +bool b_uvisible(const connection * b, const unit * u) { unused(u); unused(b); return true; } -boolean b_rinvisible(const connection * b, const region * r) +bool b_rinvisible(const connection * b, const region * r) { unused(r); unused(b); return false; } -boolean b_finvisible(const connection * b, const struct faction * f, +bool b_finvisible(const connection * b, const struct faction * f, const region * r) { unused(r); @@ -291,7 +291,7 @@ boolean b_finvisible(const connection * b, const struct faction * f, return false; } -boolean b_uinvisible(const connection * b, const unit * u) +bool b_uinvisible(const connection * b, const unit * u) { unused(u); unused(b); @@ -399,14 +399,14 @@ static const char *b_namefogwall(const connection * b, const region * r, return LOC(f->locale, mkname("border", "fogwall")); } -static boolean +static bool b_blockfogwall(const connection * b, const unit * u, const region * r) { unused(b); unused(r); if (!u) return true; - return (boolean) (effskill(u, SK_PERCEPTION) > 4); /* Das ist die alte Nebelwand */ + return (bool) (effskill(u, SK_PERCEPTION) > 4); /* Das ist die alte Nebelwand */ } /** Legacy type used in old Eressea games, no longer in use. */ @@ -458,7 +458,7 @@ border_type bt_illusionwall = { * special quest door ***/ -boolean b_blockquestportal(const connection * b, const unit * u, +bool b_blockquestportal(const connection * b, const unit * u, const region * r) { if (b->data.i > 0) @@ -558,14 +558,14 @@ static void b_writeroad(const connection * b, storage * store) store->w_int(store, b->data.sa[1]); } -static boolean b_validroad(const connection * b) +static bool b_validroad(const connection * b) { if (b->data.sa[0] == SHRT_MAX) return false; return true; } -static boolean b_rvisibleroad(const connection * b, const region * r) +static bool b_rvisibleroad(const connection * b, const region * r) { int x = b->data.i; x = (r == b->from) ? b->data.sa[0] : b->data.sa[1]; diff --git a/src/kernel/connection.h b/src/kernel/connection.h index 62e09771e..b582377c5 100644 --- a/src/kernel/connection.h +++ b/src/kernel/connection.h @@ -39,7 +39,7 @@ extern "C" { typedef struct border_type { const char *__name; /* internal use only */ variant_type datatype; - boolean(*transparent) (const connection *, const struct faction *); + bool(*transparent) (const connection *, const struct faction *); /* is it possible to see through this? */ void (*init) (connection *); /* constructor: initialize the connection. allocate extra memory if needed */ @@ -47,7 +47,7 @@ extern "C" { /* destructor: remove all extra memory for destruction */ void (*read) (connection *, struct storage *); void (*write) (const connection *, struct storage *); - boolean(*block) (const connection *, const struct unit *, + bool(*block) (const connection *, const struct unit *, const struct region * r); /* return true if it blocks movement of u from * r to the opposite struct region. @@ -59,11 +59,11 @@ extern "C" { * may depend on the struct faction, for example "a wall" may * turn out to be "an illusionary wall" */ - boolean(*rvisible) (const connection *, const struct region *); + bool(*rvisible) (const connection *, const struct region *); /* is it visible to everyone in r ? * if not, it may still be fvisible() for some f. */ - boolean(*fvisible) (const connection *, const struct faction *, + bool(*fvisible) (const connection *, const struct faction *, const struct region *); /* is it visible to units of f in r? * the function shall not check for @@ -73,16 +73,16 @@ extern "C" { * the reporting function will have to assure). * if not true, it may still be uvisible() for some u. */ - boolean(*uvisible) (const connection *, const struct unit *); + bool(*uvisible) (const connection *, const struct unit *); /* is it visible to u ? * a doorway may only be visible to a struct unit with perception > 5 */ - boolean(*valid) (const connection *); + bool(*valid) (const connection *); /* is the connection in a valid state, * or should it be erased at the end of this turn to save space? */ struct region *(*move) (const connection *, struct unit * u, - struct region * from, struct region * to, boolean routing); + struct region * from, struct region * to, bool routing); /* executed when the units traverses this connection */ int (*age) (struct connection *); /* return 0 if connection needs to be removed. >0 if still aging, <0 if not aging */ @@ -112,20 +112,20 @@ extern "C" { /* provide default implementations for some member functions: */ extern void b_read(connection * b, struct storage *store); extern void b_write(const connection * b, struct storage *store); - extern boolean b_blockall(const connection *, const struct unit *, + extern bool b_blockall(const connection *, const struct unit *, const struct region *); - extern boolean b_blocknone(const connection *, const struct unit *, + extern bool b_blocknone(const connection *, const struct unit *, const struct region *); - extern boolean b_rvisible(const connection *, const struct region *r); - extern boolean b_fvisible(const connection *, const struct faction *f, + extern bool b_rvisible(const connection *, const struct region *r); + extern bool b_fvisible(const connection *, const struct faction *f, const struct region *); - extern boolean b_uvisible(const connection *, const struct unit *u); - extern boolean b_rinvisible(const connection *, const struct region *r); - extern boolean b_finvisible(const connection *, const struct faction *f, + extern bool b_uvisible(const connection *, const struct unit *u); + extern bool b_rinvisible(const connection *, const struct region *r); + extern bool b_finvisible(const connection *, const struct faction *f, const struct region *); - extern boolean b_uinvisible(const connection *, const struct unit *u); - extern boolean b_transparent(const connection *, const struct faction *); - extern boolean b_opaque(const connection *, const struct faction *); /* !transparent */ + extern bool b_uinvisible(const connection *, const struct unit *u); + extern bool b_transparent(const connection *, const struct faction *); + extern bool b_opaque(const connection *, const struct faction *); /* !transparent */ extern border_type bt_fogwall; extern border_type bt_noway; diff --git a/src/kernel/curse.c b/src/kernel/curse.c index 4a7403e69..5dfa9c3f1 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -322,7 +322,7 @@ const curse_type *ct_find(const char *c) * einen pointer auf die struct zur�ck. */ -boolean cmp_curse(const attrib * a, const void *data) +bool cmp_curse(const attrib * a, const void *data) { const curse *c = (const curse *)data; if (a->type->flags & ATF_CURSE) { @@ -332,7 +332,7 @@ boolean cmp_curse(const attrib * a, const void *data) return false; } -boolean cmp_cursetype(const attrib * a, const void *data) +bool cmp_cursetype(const attrib * a, const void *data) { const curse_type *ct = (const curse_type *)data; if (a->type->flags & ATF_CURSE) { @@ -343,7 +343,7 @@ boolean cmp_cursetype(const attrib * a, const void *data) } curse *get_cursex(attrib * ap, const curse_type * ctype, variant data, - boolean(*compare) (const curse *, variant)) + bool(*compare) (const curse *, variant)) { attrib *a = a_select(ap, ctype, cmp_cursetype); while (a) { @@ -582,7 +582,7 @@ static void do_transfer_curse(curse * c, unit * u, unit * u2, int n) { int cursedmen = 0; int men = get_cursedmen(u, c); - boolean dogive = false; + bool dogive = false; const curse_type *ct = c->type; switch ((ct->flags | c->flags) & CURSE_SPREADMASK) { @@ -639,7 +639,7 @@ void transfer_curse(unit * u, unit * u2, int n) /* ------------------------------------------------------------- */ -boolean curse_active(const curse * c) +bool curse_active(const curse * c) { if (!c) return false; @@ -651,7 +651,7 @@ boolean curse_active(const curse * c) return true; } -boolean is_cursed_internal(attrib * ap, const curse_type * ct) +bool is_cursed_internal(attrib * ap, const curse_type * ct) { curse *c = get_curse(ap, ct); @@ -661,7 +661,7 @@ boolean is_cursed_internal(attrib * ap, const curse_type * ct) return true; } -boolean is_cursed_with(const attrib * ap, const curse * c) +bool is_cursed_with(const attrib * ap, const curse * c) { const attrib *a = ap; diff --git a/src/kernel/curse.h b/src/kernel/curse.h index ee2f7899e..a4b2f9c80 100644 --- a/src/kernel/curse.h +++ b/src/kernel/curse.h @@ -248,7 +248,7 @@ extern "C" { extern void destroy_curse(curse * c); - boolean is_cursed_internal(struct attrib *ap, const curse_type * ctype); + bool is_cursed_internal(struct attrib *ap, const curse_type * ctype); /* ignoriert CURSE_ISNEW */ extern void remove_curse(struct attrib **ap, const struct curse *c); @@ -281,7 +281,7 @@ extern "C" { * */ extern struct curse *get_cursex(struct attrib *ap, const curse_type * ctype, - variant data, boolean(*compare) (const struct curse *, variant)); + variant data, bool(*compare) (const struct curse *, variant)); /* gibt pointer auf die erste curse-struct zur�ck, deren Typ ctype ist, * und f�r die compare() true liefert, oder einen NULL-pointer. * */ @@ -303,15 +303,15 @@ extern "C" { extern void curse_done(struct attrib *a); extern int curse_age(struct attrib *a); - extern boolean cmp_curse(const struct attrib *a, const void *data); - extern boolean cmp_cursetype(const struct attrib *a, const void *data); + extern bool cmp_curse(const struct attrib *a, const void *data); + extern bool cmp_cursetype(const struct attrib *a, const void *data); extern double destr_curse(struct curse *c, int cast_level, double force); extern int resolve_curse(variant data, void *address); - extern boolean is_cursed_with(const struct attrib *ap, const struct curse *c); + extern bool is_cursed_with(const struct attrib *ap, const struct curse *c); - extern boolean curse_active(const struct curse *c); + extern bool curse_active(const struct curse *c); /* gibt true, wenn der Curse nicht NULL oder inaktiv ist */ /*** COMPATIBILITY MACROS. DO NOT USE FOR NEW CODE, REPLACE IN OLD CODE: */ diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 009922bca..8bf86e30a 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -258,7 +258,7 @@ unit *addplayer(region * r, faction * f) return u; } -boolean checkpasswd(const faction * f, const char *passwd, boolean shortp) +bool checkpasswd(const faction * f, const char *passwd, bool shortp) { if (unicode_utf8_strcasecmp(f->passw, passwd) == 0) return true; @@ -490,14 +490,14 @@ void faction_setpassword(faction * f, const char *passw) f->passw = strdup(itoa36(rng_int())); } -boolean valid_race(const struct faction *f, const struct race *rc) +bool valid_race(const struct faction *f, const struct race *rc) { if (f->race == rc) return true; else { const char *str = get_param(f->race->parameters, "other_race"); if (str) - return (boolean) (rc_find(str) == rc); + return (bool) (rc_find(str) == rc); return false; } } diff --git a/src/kernel/faction.h b/src/kernel/faction.h index a81d0545c..e68cf8bcd 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -87,7 +87,7 @@ extern "C" { int no_units; struct ally *allies; struct group *groups; - boolean alive; /* enno: sollte ein flag werden */ + bool alive; /* enno: sollte ein flag werden */ int nregions; int money; #if SCORE_MODULE @@ -118,8 +118,8 @@ extern "C" { extern struct unit *addplayer(struct region *r, faction * f); extern struct faction *addfaction(const char *email, const char *password, const struct race *frace, const struct locale *loc, int subscription); - extern boolean checkpasswd(const faction * f, const char *passwd, - boolean shortp); + extern bool checkpasswd(const faction * f, const char *passwd, + bool shortp); extern void destroyfaction(faction * f); extern void set_alliance(struct faction *a, struct faction *b, int status); @@ -150,7 +150,7 @@ extern "C" { const char *faction_getpassword(const struct faction *self); void faction_setpassword(struct faction *self, const char *password); - boolean valid_race(const struct faction *f, const struct race *rc); + bool valid_race(const struct faction *f, const struct race *rc); struct spellbook * faction_get_spellbook(struct faction *f); #ifdef __cplusplus diff --git a/src/kernel/group.c b/src/kernel/group.c index a0b5821c5..8b6144d82 100755 --- a/src/kernel/group.c +++ b/src/kernel/group.c @@ -175,7 +175,7 @@ void set_group(struct unit *u, struct group *g) } } -boolean join_group(unit * u, const char *name) +bool join_group(unit * u, const char *name) { group *g = NULL; diff --git a/src/kernel/group.h b/src/kernel/group.h index 14dd119cd..17b44ab3d 100755 --- a/src/kernel/group.h +++ b/src/kernel/group.h @@ -38,7 +38,7 @@ extern "C" { } group; extern struct attrib_type at_group; /* attribute for units assigned to a group */ - extern boolean join_group(struct unit *u, const char *name); + extern bool join_group(struct unit *u, const char *name); extern void set_group(struct unit *u, struct group *g); extern struct group * get_group(const struct unit *u); extern void free_group(struct group *g); diff --git a/src/kernel/item.c b/src/kernel/item.c index c588fbeca..fd35f0776 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -684,7 +684,7 @@ typedef struct t_item { const char *name; /* [0]: Einzahl f�r eigene; [1]: Mehrzahl f�r eigene; * [2]: Einzahl f�r Fremde; [3]: Mehrzahl f�r Fremde */ - boolean is_resource; + bool is_resource; skill_t skill; int minskill; int gewicht; diff --git a/src/kernel/item.h b/src/kernel/item.h index 7ff3b9454..be6d18272 100644 --- a/src/kernel/item.h +++ b/src/kernel/item.h @@ -132,7 +132,7 @@ extern "C" { int capacity; struct construction *construction; /* --- functions --- */ - boolean(*canuse) (const struct unit * user, + bool(*canuse) (const struct unit * user, const struct item_type * itype); int (*use) (struct unit * user, const struct item_type * itype, int amount, struct order * ord); @@ -220,7 +220,7 @@ extern "C" { int reload; /* time to reload this weapon */ weapon_mod *modifiers; /* --- functions --- */ - boolean(*attack) (const struct troop *, const struct weapon_type *, + bool(*attack) (const struct troop *, const struct weapon_type *, int *deaths); } weapon_type; diff --git a/src/kernel/magic.c b/src/kernel/magic.c index e716528ce..3f388450b 100644 --- a/src/kernel/magic.c +++ b/src/kernel/magic.c @@ -345,7 +345,7 @@ attrib_type at_mage = { ATF_UNIQUE }; -boolean is_mage(const unit * u) +bool is_mage(const unit * u) { return i2b(get_mage(u) != NULL); } @@ -407,7 +407,7 @@ attrib_type at_seenspell = { #define MAXSPELLS 256 -static boolean already_seen(const faction * f, const spell * sp) +static bool already_seen(const faction * f, const spell * sp) { attrib *a; @@ -912,7 +912,7 @@ void pay_spell(unit * u, const spell * sp, int cast_level, int range) * aber dann immer noch nicht k�nnen, vieleicht ist seine Stufe derzeit * nicht ausreichend oder die Komponenten fehlen. */ -boolean knowsspell(const region * r, const unit * u, const spell * sp) +bool knowsspell(const region * r, const unit * u, const spell * sp) { /* Ist �berhaupt ein g�ltiger Spruch angegeben? */ if (!sp || sp->id == 0) { @@ -929,7 +929,7 @@ boolean knowsspell(const region * r, const unit * u, const spell * sp) * und sonstige Gegenstaende sein. */ -boolean +bool cancast(unit * u, const spell * sp, int level, int range, struct order * ord) { int k; @@ -1178,7 +1178,7 @@ double magic_resistance(unit * target) * true zur�ck */ -boolean +bool target_resists_magic(unit * magician, void *obj, int objtyp, int t_bonus) { double probability = 0.0; @@ -1244,9 +1244,9 @@ target_resists_magic(unit * magician, void *obj, int objtyp, int t_bonus) /* ------------------------------------------------------------- */ -boolean is_magic_resistant(unit * magician, unit * target, int resist_bonus) +bool is_magic_resistant(unit * magician, unit * target, int resist_bonus) { - return (boolean) target_resists_magic(magician, target, TYP_UNIT, + return (bool) target_resists_magic(magician, target, TYP_UNIT, resist_bonus); } @@ -1261,7 +1261,7 @@ boolean is_magic_resistant(unit * magician, unit * target, int resist_bonus) * eben) bis zu etwa 1% bei doppelt so gut wie notwendig */ -boolean fumble(region * r, unit * u, const spell * sp, int cast_grade) +bool fumble(region * r, unit * u, const spell * sp, int cast_grade) { /* X ergibt Zahl zwischen 1 und 0, je kleiner, desto besser der Magier. * 0,5*40-20=0, dh wenn der Magier doppelt so gut ist, wie der Spruch @@ -1500,7 +1500,7 @@ void regenerate_aura(void) } } -static boolean +static bool verify_ship(region * r, unit * mage, const spell * sp, spllprm * spobj, order * ord) { @@ -1523,7 +1523,7 @@ verify_ship(region * r, unit * mage, const spell * sp, spllprm * spobj, return true; } -static boolean +static bool verify_building(region * r, unit * mage, const spell * sp, spllprm * spobj, order * ord) { @@ -1564,7 +1564,7 @@ message *msg_unitnotfound(const struct unit * mage, struct order * ord, "unit region command id", mage, mage->region, ord, uid); } -static boolean +static bool verify_unit(region * r, unit * mage, const spell * sp, spllprm * spobj, order * ord) { @@ -1907,7 +1907,7 @@ addparam_unit(const char *const param[], spllprm ** spobjp, const unit * u, static spellparameter *add_spellparameter(region * target_r, unit * u, const char *syntax, const char *const param[], int size, struct order *ord) { - boolean fail = false; + bool fail = false; int i = 0; int p = 0; const char *c; @@ -2116,7 +2116,7 @@ typedef struct familiar_data { unit *familiar; } famililar_data; -boolean is_familiar(const unit * u) +bool is_familiar(const unit * u) { attrib *a = a_find(u->attribs, &at_familiarmage); return i2b(a != NULL); @@ -2200,7 +2200,7 @@ void remove_familiar(unit * mage) } } -boolean create_newfamiliar(unit * mage, unit * familiar) +bool create_newfamiliar(unit * mage, unit * familiar) { /* if the skill modifier for the mage does not yet exist, add it */ attrib *a; @@ -2461,7 +2461,7 @@ unit *get_clone_mage(const unit * u) return NULL; } -static boolean is_moving_ship(const region * r, ship * sh) +static bool is_moving_ship(const region * r, ship * sh) { const unit *u = ship_owner(sh); @@ -2767,7 +2767,7 @@ void magic(void) for (co = spellranks[rank].begin; co; co = co->next) { order *ord = co->order; int invalid, resist, success, cast_level = co->level; - boolean fumbled = false; + bool fumbled = false; unit *u = co->magician.u; const spell *sp = co->sp; region *target_r = co_get_region(co); diff --git a/src/kernel/magic.h b/src/kernel/magic.h index 0f5b6b56d..f2dfaa5ba 100644 --- a/src/kernel/magic.h +++ b/src/kernel/magic.h @@ -228,9 +228,9 @@ typedef struct sc_mage { * und initialisiert den Magiertypus mit mtyp. */ sc_mage *get_mage(const struct unit *u); /* gibt u->mage zur�ck, bei nicht-Magiern *NULL */ - boolean is_mage(const struct unit *u); + bool is_mage(const struct unit *u); /* gibt true, wenn u->mage gesetzt. */ - boolean is_familiar(const struct unit *u); + bool is_familiar(const struct unit *u); /* gibt true, wenn eine Familiar-Relation besteht. */ /* Spr�che */ @@ -253,7 +253,7 @@ typedef struct sc_mage { /* f�gt alle Zauber des Magiegebietes der Einheit, deren Stufe kleiner * als das aktuelle Magietalent ist, in die Spruchliste der Einheit * ein */ - boolean knowsspell(const struct region *r, const struct unit *u, + bool knowsspell(const struct region *r, const struct unit *u, const struct spell * sp); /* pr�ft, ob die Einheit diesen Spruch gerade beherrscht, dh * mindestens die erforderliche Stufe hat. Hier k�nnen auch Abfragen @@ -277,7 +277,7 @@ typedef struct sc_mage { extern double spellpower(struct region *r, struct unit *u, const struct spell * sp, int cast_level, struct order *ord); /* ermittelt die St�rke eines Spruchs */ - boolean fumble(struct region *r, struct unit *u, const struct spell * sp, + bool fumble(struct region *r, struct unit *u, const struct spell * sp, int cast_level); /* true, wenn der Zauber misslingt, bei false gelingt der Zauber */ @@ -304,7 +304,7 @@ typedef struct sc_mage { /* gibt die f�r diesen Spruch derzeit notwendigen Magiepunkte auf der * geringstm�glichen Stufe zur�ck, schon um den Faktor der bereits * zuvor gezauberten Spr�che erh�ht */ - boolean cancast(struct unit *u, const struct spell * spruch, int eff_stufe, + bool cancast(struct unit *u, const struct spell * spruch, int eff_stufe, int distance, struct order *ord); /* true, wenn Einheit alle Komponenten des Zaubers (incl. MP) f�r die * geringstm�gliche Stufe hat und den Spruch beherrscht */ @@ -317,13 +317,13 @@ typedef struct sc_mage { /* ermittelt die effektive Stufe des Zaubers. Dabei ist cast_level * die gew�nschte maximale Stufe (im Normalfall Stufe des Magiers, * bei Farcasting Stufe*2^Entfernung) */ - boolean is_magic_resistant(struct unit *magician, struct unit *target, int + bool is_magic_resistant(struct unit *magician, struct unit *target, int resist_bonus); /* Mapperfunktion f�r target_resists_magic() vom Typ struct unit. */ extern double magic_resistance(struct unit *target); /* gibt die Chance an, mit der einem Zauber widerstanden wird. Je * gr��er, desto resistenter ist da Opfer */ - boolean target_resists_magic(struct unit *magician, void *obj, int objtyp, + bool target_resists_magic(struct unit *magician, void *obj, int objtyp, int resist_bonus); /* gibt false zur�ck, wenn der Zauber gelingt, true, wenn das Ziel * widersteht */ @@ -339,7 +339,7 @@ typedef struct sc_mage { extern struct attrib_type at_familiar; extern struct attrib_type at_familiarmage; extern void remove_familiar(struct unit *mage); - extern boolean create_newfamiliar(struct unit *mage, struct unit *familiar); + extern bool create_newfamiliar(struct unit *mage, struct unit *familiar); extern void create_newclone(struct unit *mage, struct unit *familiar); extern struct unit *has_clone(struct unit *mage); diff --git a/src/kernel/move.c b/src/kernel/move.c index 993125b43..7eed52d5f 100644 --- a/src/kernel/move.c +++ b/src/kernel/move.c @@ -187,7 +187,7 @@ static attrib_type at_driveweight = { "driveweight", NULL, NULL, NULL, NULL, NULL }; -static boolean entrance_allowed(const struct unit *u, const struct region *r) +static bool entrance_allowed(const struct unit *u, const struct region *r) { #ifdef REGIONOWNERS faction *owner = region_get_owner(r); @@ -372,7 +372,7 @@ static int canwalk(unit * u) return E_CANWALK_TOOHEAVY; } -boolean canfly(unit * u) +bool canfly(unit * u) { if (get_item(u, I_PEGASUS) >= u->number && effskill(u, SK_RIDING) >= 4) return true; @@ -386,7 +386,7 @@ boolean canfly(unit * u) return false; } -boolean canswim(unit * u) +bool canswim(unit * u) { if (get_item(u, I_DOLPHIN) >= u->number && effskill(u, SK_RIDING) >= 4) return true; @@ -448,7 +448,7 @@ static int canride(unit * u) return 0; } -static boolean cansail(const region * r, ship * sh) +static bool cansail(const region * r, ship * sh) { /* sonst ist construction:: size nicht ship_type::maxsize */ assert(!sh->type->construction @@ -584,7 +584,7 @@ ship *move_ship(ship * sh, region * from, region * to, region_list * route) { unit **iunit = &from->units; unit **ulist = &to->units; - boolean trail = (route == NULL); + bool trail = (route == NULL); if (from != to) { translist(&from->ships, &to->ships, sh); @@ -619,7 +619,7 @@ ship *move_ship(ship * sh, region * from, region * to, region_list * route) return sh; } -static boolean is_freezing(const unit * u) +static bool is_freezing(const unit * u) { if (u->race != new_race[RC_INSECT]) return false; @@ -671,7 +671,7 @@ static int is_ship_allowed(struct ship *sh, const region * r) return SA_NO_COAST; } -static boolean flying_ship(const ship * sh) +static bool flying_ship(const ship * sh) { if (sh->type->flags & SFL_FLY) return true; @@ -804,9 +804,9 @@ static void drifting_ships(region * r) } } -static boolean present(region * r, unit * u) +static bool present(region * r, unit * u) { - return (boolean) (u && u->region == r); + return (bool) (u && u->region == r); } static void caught_target(region * r, unit * u) @@ -837,7 +837,7 @@ static unit *bewegung_blockiert_von(unit * reisender, region * r) { unit *u; int perception = 0; - boolean contact = false; + bool contact = false; unit *guard = NULL; if (fval(reisender->race, RCF_ILLUSIONARY)) @@ -871,7 +871,7 @@ static unit *bewegung_blockiert_von(unit * reisender, region * r) return NULL; } -static boolean is_guardian_u(const unit * guard, unit * u, unsigned int mask) +static bool is_guardian_u(const unit * guard, unit * u, unsigned int mask) { if (guard->faction == u->faction) return false; @@ -887,7 +887,7 @@ static boolean is_guardian_u(const unit * guard, unit * u, unsigned int mask) return true; } -static boolean is_guardian_r(const unit * guard) +static bool is_guardian_r(const unit * guard) { if (guard->number == 0) return false; @@ -912,7 +912,7 @@ static boolean is_guardian_r(const unit * guard) return true; } -boolean is_guard(const struct unit * u, int mask) +bool is_guard(const struct unit * u, int mask) { return is_guardian_r(u) && (getguard(u) & mask) != 0; } @@ -1011,8 +1011,8 @@ static void cycle_route(order * ord, unit * u, int gereist) char neworder[2048]; const char *token; direction_t d = NODIRECTION; - boolean paused = false; - boolean pause; + bool paused = false; + bool pause; order *norder; size_t size = sizeof(tail) - 1; @@ -1086,7 +1086,7 @@ static void cycle_route(order * ord, unit * u, int gereist) free_order(norder); } -static boolean transport(unit * ut, unit * u) +static bool transport(unit * ut, unit * u) { order *ord; @@ -1106,7 +1106,7 @@ static boolean transport(unit * ut, unit * u) return false; } -static boolean can_move(const unit * u) +static bool can_move(const unit * u) { if (u->race->flags & RCF_CANNOTMOVE) return false; @@ -1185,7 +1185,7 @@ static void init_transportation(void) } } -static boolean roadto(const region * r, direction_t dir) +static bool roadto(const region * r, direction_t dir) { /* wenn es hier genug strassen gibt, und verbunden ist, und es dort * genug strassen gibt, dann existiert eine strasse in diese richtung */ @@ -1329,7 +1329,7 @@ static int movement_speed(unit * u) { int mp; static const curse_type *speed_ct; - static boolean init = false; + static bool init = false; double dk = u->race->speed; assert(u->number); @@ -1428,7 +1428,7 @@ static const region_list *travel_route(unit * u, region *current = u->region; const region_list *iroute = route_begin; int steps = 0; - boolean landing = false; /* aquarians have landed */ + bool landing = false; /* aquarians have landed */ while (iroute && iroute != route_end) { region *next = iroute->data; @@ -1586,7 +1586,7 @@ static const region_list *travel_route(unit * u, return iroute; } -static boolean ship_ready(const region * r, unit * u) +static bool ship_ready(const region * r, unit * u) { if (!u->ship || u!=ship_owner(u->ship)) { cmistake(u, u->thisorder, 146, MSG_MOVE); @@ -1633,8 +1633,8 @@ unit *owner_buildingtyp(const region * r, const building_type * bt) return NULL; } -boolean -buildingtype_exists(const region * r, const building_type * bt, boolean working) +bool +buildingtype_exists(const region * r, const building_type * bt, bool working) { building *b; @@ -1648,7 +1648,7 @@ buildingtype_exists(const region * r, const building_type * bt, boolean working) /* Pr�ft, ob Ablegen von einer K�ste in eine der erlaubten Richtungen erfolgt. */ -static boolean check_takeoff(ship * sh, region * from, region * to) +static bool check_takeoff(ship * sh, region * from, region * to) { if (!fval(from->terrain, SEA_REGION) && sh->coast != NODIRECTION) { direction_t coast = sh->coast; @@ -1667,7 +1667,7 @@ static boolean check_takeoff(ship * sh, region * from, region * to) } static void -sail(unit * u, order * ord, boolean move_on_land, region_list ** routep) +sail(unit * u, order * ord, bool move_on_land, region_list ** routep) { region *starting_point = u->region; region *current_point, *last_point; @@ -1747,7 +1747,7 @@ sail(unit * u, order * ord, boolean move_on_land, region_list ** routep) && fval(current_point->terrain, SEA_REGION)) { if (!is_cursed(sh->attribs, C_SHIP_NODRIFT, 0)) { region *rnext = NULL; - boolean storm = true; + bool storm = true; int d_offset = rng_int() % MAXDIRECTIONS; direction_t d; /* Sturm nur, wenn n�chste Region Hochsee ist. */ @@ -2035,7 +2035,7 @@ static const region_list *travel_i(unit * u, const region_list * route_begin, } else if (!can_move(ut)) { cmistake(u, ord, 99, MSG_MOVE); } else { - boolean found = false; + bool found = false; if (!fval(ut, UFL_NOTMOVING) && !LongHunger(ut)) { init_tokens(ut->thisorder); @@ -2150,7 +2150,7 @@ static void travel(unit * u, region_list ** routep) } -static void move(unit * u, boolean move_on_land) +static void move(unit * u, bool move_on_land) { region_list *route = NULL; @@ -2556,7 +2556,7 @@ void movement(void) region *r = regions; while (r != NULL) { unit **up = &r->units; - boolean repeat = false; + bool repeat = false; while (*up) { unit *u = *up; @@ -2676,7 +2676,7 @@ void follow_unit(unit * u) if (a && !fval(u, UFL_MOVED | UFL_NOTMOVING)) { unit *u2 = a->data.v; - boolean follow = false; + bool follow = false; if (!u2 || u2->region != r || !cansee(u->faction, r, u2, 0)) { return; diff --git a/src/kernel/move.h b/src/kernel/move.h index e53764c29..621510d04 100644 --- a/src/kernel/move.h +++ b/src/kernel/move.h @@ -51,18 +51,18 @@ extern "C" { void movement(void); void run_to(struct unit *u, struct region *to); struct unit *is_guarded(struct region *r, struct unit *u, unsigned int mask); - boolean is_guard(const struct unit *u, int mask); + bool is_guard(const struct unit *u, int mask); int enoughsailors(const struct ship *sh, const struct region *r); - boolean canswim(struct unit *u); - boolean canfly(struct unit *u); + bool canswim(struct unit *u); + bool canfly(struct unit *u); struct unit *get_captain(const struct ship *sh); void travelthru(const struct unit *u, struct region *r); struct ship *move_ship(struct ship *sh, struct region *from, struct region *to, struct region_list *route); int walkingcapacity(const struct unit *u); void follow_unit(struct unit *u); - boolean buildingtype_exists(const struct region *r, - const struct building_type *bt, boolean working); + bool buildingtype_exists(const struct region *r, + const struct building_type *bt, bool working); struct unit *owner_buildingtyp(const struct region *r, const struct building_type *bt); diff --git a/src/kernel/pathfinder.c b/src/kernel/pathfinder.c index c9adf3251..875211deb 100644 --- a/src/kernel/pathfinder.c +++ b/src/kernel/pathfinder.c @@ -28,21 +28,21 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include <stdlib.h> #include <assert.h> -boolean allowed_swim(const region * src, const region * r) +bool allowed_swim(const region * src, const region * r) { if (fval(r->terrain, SWIM_INTO)) return true; return false; } -boolean allowed_walk(const region * src, const region * r) +bool allowed_walk(const region * src, const region * r) { if (fval(r->terrain, WALK_INTO)) return true; return false; } -boolean allowed_fly(const region * src, const region * r) +bool allowed_fly(const region * src, const region * r) { if (fval(r->terrain, FLY_INTO)) return true; @@ -100,7 +100,7 @@ static void free_nodes(node * root) } struct quicklist *regions_in_range(struct region *start, int maxdist, - boolean(*allowed) (const struct region *, const struct region *)) + bool(*allowed) (const struct region *, const struct region *)) { quicklist * rlist = NULL; node *root = new_node(start, 0, NULL); @@ -140,14 +140,14 @@ struct quicklist *regions_in_range(struct region *start, int maxdist, } static region **internal_path_find(region * start, const region * target, - int maxlen, boolean(*allowed) (const region *, const region *)) + int maxlen, bool(*allowed) (const region *, const region *)) { static region *path[MAXDEPTH + 2]; /* STATIC_RETURN: used for return, not across calls */ direction_t d; node *root = new_node(start, 0, NULL); node **end = &root->next; node *n = root; - boolean found = false; + bool found = false; assert(maxlen <= MAXDEPTH); fset(start, RF_MARK); @@ -190,9 +190,9 @@ static region **internal_path_find(region * start, const region * target, return NULL; } -boolean +bool path_exists(region * start, const region * target, int maxlen, - boolean(*allowed) (const region *, const region *)) + bool(*allowed) (const region *, const region *)) { assert((!fval(start, RF_MARK) && !fval(target, RF_MARK)) || !"Some Algorithm did not clear its RF_MARKs!"); @@ -204,7 +204,7 @@ path_exists(region * start, const region * target, int maxlen, } region **path_find(region * start, const region * target, int maxlen, - boolean(*allowed) (const region *, const region *)) + bool(*allowed) (const region *, const region *)) { assert((!fval(start, RF_MARK) && !fval(target, RF_MARK)) || !"Did you call path_init()?"); diff --git a/src/kernel/pathfinder.h b/src/kernel/pathfinder.h index ac372dc34..6c9edb94e 100644 --- a/src/kernel/pathfinder.h +++ b/src/kernel/pathfinder.h @@ -29,18 +29,18 @@ extern "C" { extern struct region **path_find(struct region *start, const struct region *target, int maxlen, - boolean(*allowed) (const struct region *, const struct region *)); - extern boolean path_exists(struct region *start, const struct region *target, - int maxlen, boolean(*allowed) (const struct region *, + bool(*allowed) (const struct region *, const struct region *)); + extern bool path_exists(struct region *start, const struct region *target, + int maxlen, bool(*allowed) (const struct region *, const struct region *)); - extern boolean allowed_swim(const struct region *src, + extern bool allowed_swim(const struct region *src, const struct region *target); - extern boolean allowed_fly(const struct region *src, + extern bool allowed_fly(const struct region *src, const struct region *target); - extern boolean allowed_walk(const struct region *src, + extern bool allowed_walk(const struct region *src, const struct region *target); extern struct quicklist *regions_in_range(struct region *src, int maxdist, - boolean(*allowed) (const struct region *, const struct region *)); + bool(*allowed) (const struct region *, const struct region *)); extern void pathfinder_cleanup(void); diff --git a/src/kernel/plane.c b/src/kernel/plane.c index 111ebb675..13ea38ce9 100644 --- a/src/kernel/plane.c +++ b/src/kernel/plane.c @@ -309,7 +309,7 @@ int read_plane_reference(plane ** pp, struct storage *store) return AT_READ_OK; } -boolean is_watcher(const struct plane * p, const struct faction * f) +bool is_watcher(const struct plane * p, const struct faction * f) { struct watcher *w; if (!p) diff --git a/src/kernel/plane.h b/src/kernel/plane.h index 685a36c71..c573c096b 100644 --- a/src/kernel/plane.h +++ b/src/kernel/plane.h @@ -73,7 +73,7 @@ extern "C" { struct plane *get_homeplane(void); extern int rel_to_abs(const struct plane *pl, const struct faction *f, int rel, unsigned char index); - extern boolean is_watcher(const struct plane *p, const struct faction *f); + extern bool is_watcher(const struct plane *p, const struct faction *f); extern int resolve_plane(variant data, void *addr); extern void write_plane_reference(const plane * p, struct storage *store); extern int read_plane_reference(plane ** pp, struct storage *store); diff --git a/src/kernel/race.c b/src/kernel/race.c index 48c8b3a4a..95686c56f 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -153,7 +153,7 @@ race *rc_find(const char *name) } /** dragon movement **/ -boolean allowed_dragon(const region * src, const region * target) +bool allowed_dragon(const region * src, const region * target) { if (fval(src->terrain, ARCTIC_REGION) && fval(target->terrain, SEA_REGION)) return false; @@ -187,7 +187,7 @@ void set_show_item(faction * f, item_t i) a->data.v = (void *)olditemtype[i]; } -boolean r_insectstalled(const region * r) +bool r_insectstalled(const region * r) { return fval(r->terrain, ARCTIC_REGION); } diff --git a/src/kernel/race.h b/src/kernel/race.h index c7c7c43fc..c6f511d44 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -80,7 +80,7 @@ extern "C" { struct att attack[10]; char bonus[MAXSKILLS]; signed char *study_speed; /* study-speed-bonus in points/turn (0=30 Tage) */ - boolean __remove_me_nonplayer; + bool __remove_me_nonplayer; int flags; int battle_flags; int ec_flags; @@ -89,7 +89,7 @@ extern "C" { const char *(*generate_name) (const struct unit *); const char *(*describe) (const struct unit *, const struct locale *); void (*age) (struct unit * u); - boolean(*move_allowed) (const struct region *, const struct region *); + bool(*move_allowed) (const struct region *, const struct region *); struct item *(*itemdrop) (const struct race *, int size); void (*init_familiar) (struct unit *); @@ -176,10 +176,10 @@ extern "C" { #define humanoidrace(rc) (fval((rc), RCF_UNDEAD) || (rc)==new_race[RC_DRACOID] || playerrace(rc)) #define illusionaryrace(rc) (fval(rc, RCF_ILLUSIONARY)) - extern boolean allowed_dragon(const struct region *src, + extern bool allowed_dragon(const struct region *src, const struct region *target); - extern boolean r_insectstalled(const struct region *r); + extern bool r_insectstalled(const struct region *r); extern void add_raceprefix(const char *); extern char **race_prefixes; diff --git a/src/kernel/region.c b/src/kernel/region.c index 6996d959f..bfaaab804 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -431,7 +431,7 @@ static int hash_requests; static int hash_misses; #endif -boolean pnormalize(int *x, int *y, const plane * pl) +bool pnormalize(int *x, int *y, const plane * pl) { if (pl) { if (x) { @@ -806,7 +806,7 @@ short rroad(const region * r, direction_t d) return (r == b->from) ? b->data.sa[0] : b->data.sa[1]; } -boolean r_isforest(const region * r) +bool r_isforest(const region * r) { if (fval(r->terrain, FOREST_REGION)) { /* needs to be covered with at leas 48% trees */ @@ -1607,7 +1607,7 @@ int owner_change(const region * r) return -1; } -boolean is_mourning(const region * r, int in_turn) +bool is_mourning(const region * r, int in_turn) { int change = owner_change(r); return (change == in_turn - 1 diff --git a/src/kernel/region.h b/src/kernel/region.h index 4afbfa2f6..88764586a 100644 --- a/src/kernel/region.h +++ b/src/kernel/region.h @@ -157,7 +157,7 @@ extern "C" { typedef struct spec_direction { int x, y; int duration; - boolean active; + bool active; char *desc; char *keyword; } spec_direction; @@ -236,7 +236,7 @@ extern "C" { #define rherbs(r) ((r)->land?(r)->land->herbs:0) #define rsetherbs(r, value) if ((r)->land) ((r)->land->herbs=(short)(value)) - boolean r_isforest(const struct region *r); + bool r_isforest(const struct region *r); #define rterrain(r) (oldterrain((r)->terrain)) #define rsetterrain(r, t) ((r)->terrain = newterrain(t)) @@ -255,7 +255,7 @@ extern "C" { struct region *new_region(int x, int y, struct plane *pl, unsigned int uid); void remove_region(region ** rlist, region * r); void terraform_region(struct region *r, const struct terrain_type *terrain); - boolean pnormalize(int *x, int *y, const struct plane *pl); + bool pnormalize(int *x, int *y, const struct plane *pl); extern const int delta_x[MAXDIRECTIONS]; extern const int delta_y[MAXDIRECTIONS]; @@ -295,7 +295,7 @@ extern "C" { void region_setresource(struct region *r, const struct resource_type *rtype, int value); int owner_change(const region * r); - boolean is_mourning(const region * r, int in_turn); + bool is_mourning(const region * r, int in_turn); const struct item_type *r_luxury(struct region *r); void get_neighbours(const struct region *r, struct region **list); diff --git a/src/kernel/reports.c b/src/kernel/reports.c index e6ae19581..86995cb2d 100644 --- a/src/kernel/reports.c +++ b/src/kernel/reports.c @@ -69,9 +69,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include <attributes/otherfaction.h> #include <attributes/racename.h> -boolean nocr = false; -boolean nonr = false; -boolean noreports = false; +bool nocr = false; +bool nonr = false; +bool noreports = false; const char *visibility[] = { "none", @@ -141,7 +141,7 @@ const char *hp_status(const unit * u) void report_item(const unit * owner, const item * i, const faction * viewer, - const char **name, const char **basename, int *number, boolean singular) + const char **name, const char **basename, int *number, bool singular) { assert(!owner || owner->number); if (owner && owner->faction == viewer) { @@ -379,7 +379,7 @@ report_resources(const seen_region * sr, resource_report * result, int size, int horses = rhorses(r); int trees = rtrees(r, 2); int saplings = rtrees(r, 1); - boolean mallorn = fval(r, RF_MALLORN) != 0; + bool mallorn = fval(r, RF_MALLORN) != 0; if (money) { if (n >= size) @@ -457,16 +457,16 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf, int getarnt = fval(u, UFL_ANON_FACTION); const char *pzTmp, *str; building *b; - boolean isbattle = (boolean) (mode == see_battle); + bool isbattle = (bool) (mode == see_battle); int telepath_see = 0; attrib *a_fshidden = NULL; item *itm; item *show; faction *fv = visible_faction(f, u); char *bufp = buf; - boolean itemcloak = false; + bool itemcloak = false; static const curse_type *itemcloak_ct = 0; - static boolean init = false; + static bool init = false; int bytes; item result[MAX_INVENTORY]; @@ -774,7 +774,7 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf, } } if (!isbattle) { - boolean printed = 0; + bool printed = 0; order *ord;; for (ord = u->old_orders; ord; ord = ord->next) { if (is_repeated(ord)) { @@ -1095,7 +1095,7 @@ static void get_addresses(report_context * ctx) while (u != NULL) { if (u->faction != ctx->f) { faction *sf = visible_faction(ctx->f, u); - boolean ballied = sf && sf != ctx->f && sf != lastf + bool ballied = sf && sf != ctx->f && sf != lastf && !fval(u, UFL_ANON_FACTION) && cansee(ctx->f, r, u, stealthmod); if (ballied || ALLIED(ctx->f, sf)) { ql_set_insert(&flist, sf); @@ -1208,9 +1208,9 @@ static void get_seen_interval(report_context * ctx) link_seen(ctx->seen, ctx->first, ctx->last); } -boolean +bool add_seen(struct seen_region *seehash[], struct region *r, unsigned char mode, - boolean dis) + bool dis) { seen_region *find = find_seen(seehash, r); if (find == NULL) { @@ -1590,7 +1590,7 @@ static seen_region **prepare_report(faction * f) int write_reports(faction * f, time_t ltime) { int backup = 1, maxbackup = 128; - boolean gotit = false; + bool gotit = false; struct report_context ctx; const char *encoding = "UTF-8"; @@ -2321,7 +2321,7 @@ int report_action(region * r, unit * actor, message * msg, int flags) if (view) { for (u = r->units; u; u = u->next) { if (!fval(u->faction, FFL_SELECT)) { - boolean show = u->faction == actor->faction; + bool show = u->faction == actor->faction; fset(u->faction, FFL_SELECT); if (view == ACTION_CANSEE) { /* Bei Fernzaubern sieht nur die eigene Partei den Magier */ diff --git a/src/kernel/reports.h b/src/kernel/reports.h index e2669de6f..ffd4ee42c 100644 --- a/src/kernel/reports.h +++ b/src/kernel/reports.h @@ -33,12 +33,12 @@ extern "C" { extern const char *directions[]; extern const char *coasts[]; - extern boolean nonr; - extern boolean nocr; - extern boolean noreports; + extern bool nonr; + extern bool nocr; + extern bool noreports; /* kann_finden speedups */ - extern boolean kann_finden(struct faction *f1, struct faction *f2); + extern bool kann_finden(struct faction *f1, struct faction *f2); extern struct unit *can_find(struct faction *, struct faction *); /* funktionen zum schreiben eines reports */ @@ -77,13 +77,13 @@ extern "C" { struct seen_region *next; struct region *r; unsigned char mode; - boolean disbelieves; + bool disbelieves; } seen_region; extern struct seen_region *find_seen(struct seen_region *seehash[], const struct region *r); - extern boolean add_seen(struct seen_region *seehash[], struct region *r, - unsigned char mode, boolean dis); + extern bool add_seen(struct seen_region *seehash[], struct region *r, + unsigned char mode, bool dis); extern struct seen_region **seen_init(void); extern void seen_done(struct seen_region *seehash[]); extern void free_seen(void); @@ -137,7 +137,7 @@ extern "C" { const struct unit *owner, const struct faction *viewer); void report_item(const struct unit *owner, const struct item *i, const struct faction *viewer, const char **name, const char **basename, - int *number, boolean singular); + int *number, bool singular); void report_building(const struct building *b, const char **btype, const char **billusion); void report_race(const struct unit *u, const char **rcname, diff --git a/src/kernel/resources.c b/src/kernel/resources.c index 0cd731869..4a3607d7b 100644 --- a/src/kernel/resources.c +++ b/src/kernel/resources.c @@ -118,7 +118,7 @@ static void terraform_default(struct rawmaterial *res, const region * r) } #ifdef RANDOM_CHANGE -static void resource_random_change(int *pvalue, boolean used) +static void resource_random_change(int *pvalue, bool used) { int split = 5; int rnd = rng_int() % 100; diff --git a/src/kernel/save.c b/src/kernel/save.c index cf7724a96..c8c39b50f 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -132,7 +132,7 @@ FILE *cfopen(const char *filename, const char *mode) int freadstr(FILE * F, int encoding, char *start, size_t size) { char *str = start; - boolean quote = false; + bool quote = false; for (;;) { int c = fgetc(F); @@ -298,7 +298,7 @@ static unit *unitorders(FILE * F, int enc, struct faction *f) stok = parse_token(&stok); if (stok) { - boolean quit = false; + bool quit = false; param_t param = findparam(stok, u->faction->locale); switch (param) { case P_UNIT: diff --git a/src/kernel/skill.c b/src/kernel/skill.c index c25954182..2cdc3d25b 100644 --- a/src/kernel/skill.c +++ b/src/kernel/skill.c @@ -73,7 +73,7 @@ const char *skillnames[MAXSKILLS] = { "unarmed" }; -boolean skill_enabled[MAXSKILLS]; +bool skill_enabled[MAXSKILLS]; const char *skillname(skill_t sk, const struct locale *lang) { @@ -83,7 +83,7 @@ const char *skillname(skill_t sk, const struct locale *lang) return NULL; } -void enable_skill(const char *skname, boolean value) +void enable_skill(const char *skname, bool value) { skill_t sk; for (sk = 0; sk != MAXSKILLS; ++sk) { @@ -260,7 +260,7 @@ int level(int days) { int i; static int ldays[64]; - static boolean init = false; + static bool init = false; if (!init) { init = true; for (i = 0; i != 64; ++i) diff --git a/src/kernel/skill.h b/src/kernel/skill.h index dde1c0721..4db618f5a 100644 --- a/src/kernel/skill.h +++ b/src/kernel/skill.h @@ -48,7 +48,7 @@ extern "C" { extern const char *skillname(skill_t, const struct locale *); extern skill_t sk_find(const char *name); - extern void enable_skill(const char *name, boolean value); + extern void enable_skill(const char *name, bool value); extern int level_days(int level); extern int level(int days); @@ -60,7 +60,7 @@ extern "C" { extern void sk_set(skill * sv, int level); extern const char *skillnames[]; - extern boolean skill_enabled[]; + extern bool skill_enabled[]; #ifdef __cplusplus } diff --git a/src/kernel/sqlite.c b/src/kernel/sqlite.c index 6e6cc5014..b7c9951a3 100644 --- a/src/kernel/sqlite.c +++ b/src/kernel/sqlite.c @@ -73,9 +73,9 @@ typedef struct db_faction { static int db_update_email(sqlite3 * db, const faction * f, const db_faction * dbstate, - boolean force, /* [OUT] */ sqlite3_uint64 * id_email) + bool force, /* [OUT] */ sqlite3_uint64 * id_email) { - boolean update = force; + bool update = force; int res = SQLITE_OK; char email_lc[MAX_EMAIL_LENGTH]; @@ -129,7 +129,7 @@ db_update_email(sqlite3 * db, const faction * f, const db_faction * dbstate, return SQLITE_OK; } -int db_update_factions(sqlite3 * db, boolean force) +int db_update_factions(sqlite3 * db, bool force) { int game_id = 6; const char sql_select[] = @@ -172,7 +172,7 @@ int db_update_factions(sqlite3 * db, boolean force) int i; char passwd_md5[MD5_LENGTH_0]; sqlite3_uint64 id_email; - boolean update = force; + bool update = force; db_faction dbstate; const char *no_b36; @@ -241,7 +241,7 @@ int db_update_factions(sqlite3 * db, boolean force) return SQLITE_OK; } -int db_update_scores(sqlite3 * db, boolean force) +int db_update_scores(sqlite3 * db, bool force) { const char *sql_ins = "INSERT OR FAIL INTO score (value,faction_id,turn) VALUES (?,?,?)"; diff --git a/src/kernel/teleport.c b/src/kernel/teleport.c index 51428f7b8..db5cc646b 100644 --- a/src/kernel/teleport.c +++ b/src/kernel/teleport.c @@ -61,7 +61,7 @@ static region *tpregion(const region * r) return rt; } -region_list *astralregions(const region * r, boolean(*valid) (const region *)) +region_list *astralregions(const region * r, bool(*valid) (const region *)) { region_list *rlist = NULL; int x, y; @@ -116,7 +116,7 @@ region *r_astral_to_standard(const region * r) } region_list *all_in_range(const region * r, int n, - boolean(*valid) (const region *)) + bool(*valid) (const region *)) { int x, y; region_list *rlist = NULL; @@ -171,7 +171,7 @@ plane *get_normalplane(void) return NULL; } -boolean is_astral(const region * r) +bool is_astral(const region * r) { plane *pl = get_astralplane(); return (pl && rplane(r) == pl); @@ -227,7 +227,7 @@ void create_teleport_plane(void) } } -boolean inhabitable(const region * r) +bool inhabitable(const region * r) { return fval(r->terrain, LAND_REGION); } diff --git a/src/kernel/teleport.h b/src/kernel/teleport.h index 2f3a5bcc0..75be6b5d1 100644 --- a/src/kernel/teleport.h +++ b/src/kernel/teleport.h @@ -25,11 +25,11 @@ extern "C" { struct region *r_standard_to_astral(const struct region *r); struct region *r_astral_to_standard(const struct region *); extern struct region_list *astralregions(const struct region *rastral, - boolean(*valid) (const struct region *)); + bool(*valid) (const struct region *)); extern struct region_list *all_in_range(const struct region *r, int n, - boolean(*valid) (const struct region *)); - extern boolean inhabitable(const struct region *r); - extern boolean is_astral(const struct region *r); + bool(*valid) (const struct region *)); + extern bool inhabitable(const struct region *r); + extern bool is_astral(const struct region *r); extern struct plane *get_astralplane(void); extern struct plane *get_normalplane(void); diff --git a/src/kernel/unit.c b/src/kernel/unit.c index c24902076..5aee29ab7 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -612,7 +612,7 @@ void usetcontact(unit * u, const unit * u2) a_add(&u->attribs, a_new(&at_contact))->data.v = (void *)u2; } -boolean ucontact(const unit * u, const unit * u2) +bool ucontact(const unit * u, const unit * u2) /* Pr�ft, ob u den Kontaktiere-Befehl zu u2 gesetzt hat. */ { attrib *ru; @@ -820,7 +820,7 @@ void leave_building(unit * u) } } -boolean can_leave(unit * u) +bool can_leave(unit * u) { static int rule_leave = -1; @@ -836,7 +836,7 @@ boolean can_leave(unit * u) return true; } -boolean leave(unit * u, boolean force) +bool leave(unit * u, bool force) { if (!force) { if (!can_leave(u)) { @@ -856,7 +856,7 @@ const struct race *urace(const struct unit *u) return u->race; } -boolean can_survive(const unit * u, const region * r) +bool can_survive(const unit * u, const region * r) { if ((fval(r->terrain, WALK_INTO) && (u->race->flags & RCF_WALK)) || (fval(r->terrain, SWIM_INTO) && (u->race->flags & RCF_SWIM)) @@ -891,7 +891,7 @@ void move_unit(unit * u, region * r, unit ** ulist) if (u->ship || u->building) { /* can_leave must be checked in travel_i */ #ifndef NDEBUG - boolean result = leave(u, false); + bool result = leave(u, false); assert(result); #else leave(u, false); @@ -1117,7 +1117,7 @@ void set_number(unit * u, int count) u->number = (unsigned short)count; } -boolean learn_skill(unit * u, skill_t sk, double chance) +bool learn_skill(unit * u, skill_t sk, double chance) { skill *sv = u->skills; if (chance < 1.0 && rng_int() % 10000 >= chance * 10000) @@ -1183,7 +1183,7 @@ skill *get_skill(const unit * u, skill_t sk) return NULL; } -boolean has_skill(const unit * u, skill_t sk) +bool has_skill(const unit * u, skill_t sk) { skill *sv = u->skills; while (sv != u->skills + u->skill_size) { @@ -1224,7 +1224,7 @@ static int item_modification(const unit * u, skill_t sk, int val) static int att_modification(const unit * u, skill_t sk) { double result = 0; - static boolean init = false; + static bool init = false; static const curse_type *skillmod_ct, *gbdream_ct, *worse_ct; curse *c; @@ -1283,7 +1283,7 @@ static int att_modification(const unit * u, skill_t sk) int get_modifier(const unit * u, skill_t sk, int level, const region * r, - boolean noitem) + bool noitem) { int bskill = level; int skill = bskill; diff --git a/src/kernel/unit.h b/src/kernel/unit.h index 7c9e3d8d3..292e6a759 100644 --- a/src/kernel/unit.h +++ b/src/kernel/unit.h @@ -145,7 +145,7 @@ extern "C" { const struct potion_type *ugetpotionuse(const struct unit *u); /* benutzt u einein trank? */ void usetpotionuse(struct unit *u, const struct potion_type *p); /* u benutzt trank p (es darf halt nur einer pro runde) */ - boolean ucontact(const struct unit *u, const struct unit *u2); + bool ucontact(const struct unit *u, const struct unit *u2); void usetcontact(struct unit *u, const struct unit *c); struct unit *findnewunit(const struct region *r, const struct faction *f, @@ -155,7 +155,7 @@ extern "C" { extern struct skill *add_skill(struct unit *u, skill_t id); extern void remove_skill(struct unit *u, skill_t sk); extern struct skill *get_skill(const struct unit *u, skill_t id); - extern boolean has_skill(const unit * u, skill_t sk); + extern bool has_skill(const unit * u, skill_t sk); extern void set_level(struct unit *u, skill_t id, int level); extern int get_level(const struct unit *u, skill_t id); @@ -167,7 +167,7 @@ extern "C" { const struct region *r); extern int get_modifier(const struct unit *u, skill_t sk, int lvl, - const struct region *r, boolean noitem); + const struct region *r, bool noitem); extern int remove_unit(struct unit **ulist, struct unit *u); #define GIFT_SELF 1<<0 @@ -181,8 +181,8 @@ extern "C" { extern void write_unit_reference(const struct unit *u, struct storage *store); extern variant read_unit_reference(struct storage *store); - extern boolean leave(struct unit *u, boolean force); - extern boolean can_leave(struct unit *u); + extern bool leave(struct unit *u, bool force); + extern bool can_leave(struct unit *u); extern void u_set_building(struct unit * u, struct building * b); extern void u_set_ship(struct unit * u, struct ship * sh); @@ -191,7 +191,7 @@ extern "C" { extern void set_leftship(struct unit *u, struct ship *sh); extern struct ship *leftship(const struct unit *); - extern boolean can_survive(const struct unit *u, const struct region *r); + extern bool can_survive(const struct unit *u, const struct region *r); extern void move_unit(struct unit *u, struct region *target, struct unit **ulist); @@ -203,7 +203,7 @@ extern "C" { extern void u_setfaction(struct unit *u, struct faction *f); extern void set_number(struct unit *u, int count); - extern boolean learn_skill(struct unit *u, skill_t sk, double chance); + extern bool learn_skill(struct unit *u, skill_t sk, double chance); extern int invisible(const struct unit *target, const struct unit *viewer); extern void free_unit(struct unit *u); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index c87f7449a..70da69915 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -51,7 +51,7 @@ without prior permission by the authors of Eressea. #include <limits.h> #include <string.h> -static boolean gamecode_enabled = false; +static bool gamecode_enabled = false; static building_type *bt_get_or_create(const char *name) { @@ -824,7 +824,7 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype) assert(propValue != NULL); if (strcmp((const char *)propValue, "attack") == 0) { wtype->attack = - (boolean(*)(const struct troop *, const struct weapon_type *, + (bool(*)(const struct troop *, const struct weapon_type *, int *))fun; } else { log_error("unknown function type '%s' for item '%s'\n", (const char *)propValue, itype->rtype->_name[0]); @@ -938,7 +938,7 @@ static item_type *xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype) struct order *))fun; } else if (strcmp((const char *)propValue, "canuse") == 0) { itype->canuse = - (boolean(*)(const struct unit *, const struct item_type *))fun; + (bool(*)(const struct unit *, const struct item_type *))fun; } else if (strcmp((const char *)propValue, "useonother") == 0) { itype->useonother = (int (*)(struct unit *, int, const struct item_type *, int, @@ -1893,7 +1893,7 @@ static int parse_races(xmlDocPtr doc) rc->age = (void (*)(struct unit *))fun; } else if (strcmp((const char *)propValue, "move") == 0) { rc->move_allowed = - (boolean(*)(const struct region *, const struct region *))fun; + (bool(*)(const struct region *, const struct region *))fun; } else if (strcmp((const char *)propValue, "itemdrop") == 0) { rc->itemdrop = (struct item * (*)(const struct race *, int))fun; } else if (strcmp((const char *)propValue, "initfamiliar") == 0) { @@ -2206,7 +2206,7 @@ static int parse_messages(xmlDocPtr doc) static void xml_readstrings(xmlXPathContextPtr xpath, xmlNodePtr * nodeTab, int nodeNr, - boolean names) + bool names) { int i; @@ -2274,7 +2274,7 @@ static int parse_strings(xmlDocPtr doc) static void xml_readprefixes(xmlXPathContextPtr xpath, xmlNodePtr * nodeTab, int nodeNr, - boolean names) + bool names) { int i; @@ -2344,7 +2344,7 @@ static int parse_main(xmlDocPtr doc) for (i = 0; i != nodes->nodeNr; ++i) { xmlNodePtr node = nodes->nodeTab[i]; xmlChar *propName = xmlGetProp(node, BAD_CAST "name"); - boolean disable = xml_bvalue(node, "disable", false); + bool disable = xml_bvalue(node, "disable", false); if (disable) { int k; @@ -2369,7 +2369,7 @@ static int parse_main(xmlDocPtr doc) for (i = 0; i != nodes->nodeNr; ++i) { xmlNodePtr node = nodes->nodeTab[i]; xmlChar *propName = xmlGetProp(node, BAD_CAST "name"); - boolean enable = xml_bvalue(node, "enable", true); + bool enable = xml_bvalue(node, "enable", true); enable_skill((const char *)propName, enable); xmlFree(propName); } diff --git a/src/modules/autoseed.c b/src/modules/autoseed.c index 9a0b5d233..4a004a0ab 100644 --- a/src/modules/autoseed.c +++ b/src/modules/autoseed.c @@ -104,7 +104,7 @@ static int count_demand(const region * r) static int recurse_regions(region * r, region_list ** rlist, - boolean(*fun) (const region * r)) + bool(*fun) (const region * r)) { if (!fun(r)) return 0; @@ -125,7 +125,7 @@ recurse_regions(region * r, region_list ** rlist, } } -static boolean f_nolux(const region * r) +static bool f_nolux(const region * r) { if (r->land && count_demand(r) != get_maxluxuries()) return true; @@ -337,7 +337,7 @@ static const terrain_type *preferred_terrain(const struct race *rc) #define MINFACTIONS 1 #define VOLCANO_CHANCE 100 -static boolean virgin_region(const region * r) +static bool virgin_region(const region * r) { direction_t d; if (r == NULL) diff --git a/src/modules/autoseed.h b/src/modules/autoseed.h index 254608803..923534020 100644 --- a/src/modules/autoseed.h +++ b/src/modules/autoseed.h @@ -26,7 +26,7 @@ extern "C" { const struct race *race; int bonus; int subscription; - boolean oldregions; + bool oldregions; struct alliance *allies; } newfaction; diff --git a/src/modules/gmcmd.c b/src/modules/gmcmd.c index 5f6caeb0c..78c26e235 100644 --- a/src/modules/gmcmd.c +++ b/src/modules/gmcmd.c @@ -157,7 +157,7 @@ static void gm_create(const void *tnext, struct unit *u, struct order *ord) } } -static boolean has_permission(const attrib * permissions, unsigned int key) +static bool has_permission(const attrib * permissions, unsigned int key) { return (find_key((attrib *) permissions->data.v, key) || find_key((attrib *) permissions->data.v, atoi36("master"))); @@ -600,7 +600,7 @@ faction *gm_addquest(const char *email, const char *name, int radius, plane *pl; watcher *w = calloc(sizeof(watcher), 1); region *center; - boolean invalid = false; + bool invalid = false; int minx, miny, maxx, maxy, cx, cy; int x; faction *f; @@ -716,7 +716,7 @@ plane *gm_addplane(int radius, unsigned int flags, const char *name) { region *center; plane *pl; - boolean invalid = false; + bool invalid = false; int minx, miny, maxx, maxy, cx, cy; int x; diff --git a/src/modules/wormhole.c b/src/modules/wormhole.c index d018c358f..4a4730df3 100644 --- a/src/modules/wormhole.c +++ b/src/modules/wormhole.c @@ -37,7 +37,7 @@ #include <assert.h> #include <stdlib.h> -static boolean good_region(const region * r) +static bool good_region(const region * r) { return (!fval(r, RF_CHAOTIC) && r->age > 30 && rplane(r) == NULL && r->units != NULL && r->land != NULL); diff --git a/src/platform.h b/src/platform.h index 679737ec2..7e1fd72b4 100644 --- a/src/platform.h +++ b/src/platform.h @@ -247,7 +247,6 @@ extern char *strdup(const char *s); #endif /* ghs || __GNUC__ || ..... */ #include "util/bool.h" -typedef bool boolean; #ifndef INLINE_FUNCTION # define INLINE_FUNCTION diff --git a/src/util/attrib.c b/src/util/attrib.c index f76b48427..ef7674534 100644 --- a/src/util/attrib.c +++ b/src/util/attrib.c @@ -85,7 +85,7 @@ static attrib_type *at_find(unsigned int hk) } attrib *a_select(attrib * a, const void *data, - boolean(*compare) (const attrib *, const void *)) + bool(*compare) (const attrib *, const void *)) { while (a && !compare(a, data)) a = a->next; diff --git a/src/util/attrib.h b/src/util/attrib.h index 47c0e29fd..6096a4cbe 100644 --- a/src/util/attrib.h +++ b/src/util/attrib.h @@ -64,7 +64,7 @@ extern "C" { extern void at_deprecate(const char * name, int (*reader)(attrib *, void *, struct storage *)); extern attrib *a_select(attrib * a, const void *data, - boolean(*compare) (const attrib *, const void *)); + bool(*compare) (const attrib *, const void *)); extern attrib *a_find(attrib * a, const attrib_type * at); extern const attrib *a_findc(const attrib * a, const attrib_type * at); extern attrib *a_add(attrib ** pa, attrib * at); diff --git a/src/util/filereader.c b/src/util/filereader.c index 1b6f79488..12ef3add4 100644 --- a/src/util/filereader.c +++ b/src/util/filereader.c @@ -42,9 +42,9 @@ INLINE_FUNCTION int eatwhite(const char *ptr, size_t * total_size) static const char *getbuf_latin1(FILE * F) { - boolean cont = false; + bool cont = false; char quote = 0; - boolean comment = false; + bool comment = false; char *cp = fbuf; char *tail = lbuf + MAXLINE - 2; @@ -57,8 +57,8 @@ static const char *getbuf_latin1(FILE * F) while (*bp && isxspace(*(unsigned char *)bp)) ++bp; /* eatwhite */ - comment = (boolean) (comment && cont); - quote = (boolean) (quote && cont); + comment = (bool) (comment && cont); + quote = (bool) (quote && cont); if (tail[1] == 0) { /* we read he maximum number of bytes! */ @@ -178,9 +178,9 @@ static const char *getbuf_latin1(FILE * F) static const char *getbuf_utf8(FILE * F) { - boolean cont = false; + bool cont = false; char quote = 0; - boolean comment = false; + bool comment = false; char *cp = fbuf; char *tail = lbuf + MAXLINE - 2; @@ -195,8 +195,8 @@ static const char *getbuf_utf8(FILE * F) eatwhite(bp, &white); /* decoding errors will get caught later on, don't have to check */ bp += white; - comment = (boolean) (comment && cont); - quote = (boolean) (quote && cont); + comment = (bool) (comment && cont); + quote = (bool) (quote && cont); if (tail[1] == 0) { /* we read the maximum number of bytes! */ diff --git a/src/util/listbox.c b/src/util/listbox.c index 0b7403860..ab3dd9eb9 100644 --- a/src/util/listbox.c +++ b/src/util/listbox.c @@ -75,7 +75,7 @@ list_selection *do_selection(list_selection * sel, const char *title, void (*perform) (list_selection *, void *), void *data) { WINDOW *wn; - boolean update = true; + bool update = true; list_selection *s; list_selection *top = sel; list_selection *current = top; diff --git a/src/util/parser.c b/src/util/parser.c index 46d6ba8a8..3634ba541 100644 --- a/src/util/parser.c +++ b/src/util/parser.c @@ -76,7 +76,7 @@ void parser_popstate(void) state = new_state; } -boolean parser_end(void) +bool parser_end(void) { eatwhitespace_c(&state->current_token); return *state->current_token == 0; @@ -126,7 +126,7 @@ const char *parse_token(const char **str) static char lbuf[MAXTOKENSIZE]; /* STATIC_RESULT: used for return, not across calls */ char *cursor = lbuf; char quotechar = 0; - boolean escape = false; + bool escape = false; const char *ctoken = *str; assert(ctoken); @@ -135,7 +135,7 @@ const char *parse_token(const char **str) while (*ctoken && cursor - lbuf < MAXTOKENSIZE - 1) { ucs4_t ucs; size_t len; - boolean copy = false; + bool copy = false; unsigned char utf8_character = *(unsigned char *)ctoken; if (~utf8_character & 0x80) { diff --git a/src/util/parser.h b/src/util/parser.h index dc1ab3717..521987174 100644 --- a/src/util/parser.h +++ b/src/util/parser.h @@ -19,7 +19,7 @@ extern "C" { extern const char *parse_token(const char **str); extern void parser_pushstate(void); extern void parser_popstate(void); - extern boolean parser_end(void); + extern bool parser_end(void); extern const char *getstrtoken(void); #ifdef __cplusplus diff --git a/src/util/rand.c b/src/util/rand.c index ac02786b7..b26bf0c12 100644 --- a/src/util/rand.c +++ b/src/util/rand.c @@ -61,7 +61,7 @@ int ntimespprob(int n, double p, double mod) return count; } -boolean chance(double x) +bool chance(double x) { if (x >= 1.0) return true; diff --git a/src/util/rand.h b/src/util/rand.h index 2c9d6e96b..9223923b9 100644 --- a/src/util/rand.h +++ b/src/util/rand.h @@ -29,7 +29,7 @@ extern "C" { /* in rand.c: */ extern double normalvariate(double mu, double sigma); extern int ntimespprob(int n, double p, double mod); - extern boolean chance(double x); + extern bool chance(double x); #ifdef __cplusplus } diff --git a/src/util/translation.c b/src/util/translation.c index 411b8aee0..e3493f434 100644 --- a/src/util/translation.c +++ b/src/util/translation.c @@ -186,7 +186,7 @@ static const char *parse_symbol(opstack ** stack, const char *in, * result goes on the stack */ { - boolean braces = false; + bool braces = false; char symbol[32]; char *cp = symbol; /* current position */ @@ -239,8 +239,8 @@ static const char *parse_string(opstack ** stack, const char *in, const char *ic = in; char *oc = buffer; /* mode flags */ - boolean f_escape = false; - boolean bDone = false; + bool f_escape = false; + bool bDone = false; variant var; while (*ic && !bDone) { @@ -310,7 +310,7 @@ static const char *parse_int(opstack ** stack, const char *in) { int k = 0; int vz = 1; - boolean ok = false; + bool ok = false; variant var; do { switch (*in) { diff --git a/src/util/xml.c b/src/util/xml.c index 297d8c89b..31a1bb542 100644 --- a/src/util/xml.c +++ b/src/util/xml.c @@ -43,9 +43,9 @@ int xml_ivalue(xmlNodePtr node, const char *name, int dflt) return i; } -boolean xml_bvalue(xmlNodePtr node, const char *name, boolean dflt) +bool xml_bvalue(xmlNodePtr node, const char *name, bool dflt) { - boolean result = dflt; + bool result = dflt; xmlChar *propValue = xmlGetProp(node, BAD_CAST name); if (propValue != NULL) { if (strcmp((const char *)propValue, "no") == 0) @@ -57,10 +57,10 @@ boolean xml_bvalue(xmlNodePtr node, const char *name, boolean dflt) else if (strcmp((const char *)propValue, "true") == 0) result = true; else if (strcmp((const char *)propValue, "1") == 0) { - log_warning("boolean value is '1': %s::%s\n", node->name, name); + log_warning("bool value is '1': %s::%s\n", node->name, name); result = true; } else if (strcmp((const char *)propValue, "0") == 0) { - log_warning("boolean value is '0': %s::%s\n", node->name, name); + log_warning("bool value is '0': %s::%s\n", node->name, name); result = false; } xmlFree(propValue); diff --git a/src/util/xml.h b/src/util/xml.h index f14cbedeb..42b9178bb 100644 --- a/src/util/xml.h +++ b/src/util/xml.h @@ -25,7 +25,7 @@ extern "C" { extern int read_xml(const char *filename, const char *catalog); extern double xml_fvalue(xmlNodePtr node, const char *name, double dflt); extern int xml_ivalue(xmlNodePtr node, const char *name, int dflt); - extern boolean xml_bvalue(xmlNodePtr node, const char *name, boolean dflt); + extern bool xml_bvalue(xmlNodePtr node, const char *name, bool dflt); const xmlChar *xml_i(double number); From f893ea03b630cebf3e2f272ce5bad91a922ec24a Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Sat, 23 Jun 2012 22:36:17 -0700 Subject: [PATCH 05/24] E4 combat prototype (WIP) --- src/gamecode/spy.c | 1 + src/kernel/battle.c | 50 +++++++++++++++++++++++++--------------- src/kernel/battle.h | 3 +++ src/kernel/battle_test.c | 3 ++- src/kernel/config.c | 11 ++++----- src/kernel/config.h | 3 ++- src/kernel/move.c | 7 ------ src/kernel/move.h | 1 - src/kernel/order.c | 6 +++++ src/kernel/order.h | 1 + src/kernel/region.c | 8 +++---- 11 files changed, 56 insertions(+), 38 deletions(-) diff --git a/src/gamecode/spy.c b/src/gamecode/spy.c index 43eb475cb..476aed8af 100644 --- a/src/gamecode/spy.c +++ b/src/gamecode/spy.c @@ -28,6 +28,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include <kernel/magic.h> #include <kernel/message.h> #include <kernel/move.h> +#include <kernel/order.h> #include <kernel/race.h> #include <kernel/region.h> #include <kernel/ship.h> diff --git a/src/kernel/battle.c b/src/kernel/battle.c index 7a4f1cd12..662c797c7 100644 --- a/src/kernel/battle.c +++ b/src/kernel/battle.c @@ -206,7 +206,7 @@ static void message_faction(battle * b, faction * f, struct message *m) region *r = b->region; if (f->battles == NULL || f->battles->r != r) { - struct bmsg *bm = calloc(1, sizeof(struct bmsg)); + struct bmsg *bm = (struct bmsg *)calloc(1, sizeof(struct bmsg)); bm->next = f->battles; f->battles = bm; bm->r = r; @@ -3203,7 +3203,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) /* Zu diesem Zeitpunkt ist attacked noch 0, da die Einheit f�r noch * keinen Kampf ausgew�hlt wurde (sonst w�rde ein fighter existieren) */ } - fig = calloc(1, sizeof(struct fighter)); + fig = (struct fighter*)calloc(1, sizeof(struct fighter)); fig->next = s1->fighters; s1->fighters = fig; @@ -3228,7 +3228,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) fig->catmsg = -1; /* Freigeben nicht vergessen! */ - fig->person = calloc(fig->alive, sizeof(struct person)); + fig->person = (struct person*)calloc(fig->alive, sizeof(struct person)); h = u->hp / u->number; assert(h); @@ -3542,7 +3542,7 @@ battle *make_battle(region * r) else { const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 }; fwrite(utf8_bom, 1, 3, bdebug); - fprintf(bdebug, "In %s findet ein Kampf stattactics:\n", rname(r, + fprintf(bdebug, "In %s findet ein Kampf statt:\n", rname(r, default_locale)); } obs_count++; @@ -3600,7 +3600,6 @@ static void free_fighter(fighter * fig) static void free_battle(battle * b) { - side *s; int max_fac_no = 0; if (bdebug) { @@ -3615,19 +3614,11 @@ static void free_battle(battle * b) free(bf); } - for (s = b->sides; s != b->sides + b->nsides; ++s) { - fighter *fnext = s->fighters; - while (fnext) { - fighter *fig = fnext; - fnext = fig->next; - free_fighter(fig); - free(fig); - } - free_side(s); - } ql_free(b->leaders); ql_foreach(b->meffects, free); ql_free(b->meffects); + + battle_free(b); } static int *get_alive(side * s) @@ -3876,7 +3867,7 @@ static void flee(const troop dt) kill_troop(dt); } -static bool init_battle(region * r, battle ** bp) +static bool start_battle(region * r, battle ** bp) { battle *b = NULL; unit *u; @@ -4091,7 +4082,7 @@ static void battle_stats(FILE * F, battle * b) } stat = *slist; if (stat == NULL || stat->wtype != wtype || stat->level != level) { - stat = calloc(1, sizeof(stat_info)); + stat = (stat_info*)calloc(1, sizeof(stat_info)); stat->wtype = wtype; stat->level = level; stat->next = *slist; @@ -4251,7 +4242,7 @@ void do_battle(region * r) msg_separator = msg_message("battle::section", ""); } - fighting = init_battle(r, &b); + fighting = start_battle(r, &b); if (b == NULL) return; @@ -4318,3 +4309,26 @@ void do_battle(region * r) free(b); } } + +void battle_init(battle * b) { + assert(b); + memset(b, 0, sizeof(battle)); +} + +void battle_free(battle * b) { + side *s; + + assert(b); + + for (s = b->sides; s != b->sides + b->nsides; ++s) { + fighter *fnext = s->fighters; + while (fnext) { + fighter *fig = fnext; + fnext = fig->next; + free_fighter(fig); + free(fig); + } + free_side(s); + } +} + diff --git a/src/kernel/battle.h b/src/kernel/battle.h index c962e32bb..59ced0967 100644 --- a/src/kernel/battle.h +++ b/src/kernel/battle.h @@ -114,6 +114,9 @@ extern "C" { } fast; } battle; + void battle_init(battle * b); + void battle_free(battle * b); + typedef struct weapon { int count, used; const struct weapon_type *type; diff --git a/src/kernel/battle_test.c b/src/kernel/battle_test.c index c8a558af1..8bdc50822 100644 --- a/src/kernel/battle_test.c +++ b/src/kernel/battle_test.c @@ -8,8 +8,9 @@ #include "region.h" #include "skill.h" #include "unit.h" -#include "tests.h" + #include <CuTest.h> +#include "tests.h" static void test_make_fighter(CuTest * tc) { diff --git a/src/kernel/config.c b/src/kernel/config.c index 08970f71b..92739609c 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -1249,12 +1249,6 @@ int count_maxmigrants(const faction * f) return migrants; } -void init_tokens(const struct order *ord) -{ - char *cmd = getcommand(ord); - init_tokens_str(cmd, cmd); -} - void parse(keyword_t kword, int (*dofun) (unit *, struct order *), bool thisorder) { @@ -1953,6 +1947,11 @@ direction_t finddirection(const char *s, const struct locale *lang) return NODIRECTION; } +direction_t getdirection(const struct locale * lang) +{ + return finddirection(getstrtoken(), lang); +} + static void init_translations(const struct locale *lang, int ut, const char * (*string_cb)(int i), int maxstrings) { char buffer[256]; diff --git a/src/kernel/config.h b/src/kernel/config.h index e85325bc1..559bcae2d 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -165,9 +165,10 @@ extern "C" { unsigned int getuint(void); int getint(void); + direction_t getdirection(const struct locale *); + extern const char *igetstrtoken(const char *s); - extern void init_tokens(const struct order *ord); /* initialize token parsing */ extern skill_t findskill(const char *s, const struct locale *lang); extern keyword_t findkeyword(const char *s, const struct locale *lang); diff --git a/src/kernel/move.c b/src/kernel/move.c index 7eed52d5f..21894c144 100644 --- a/src/kernel/move.c +++ b/src/kernel/move.c @@ -176,13 +176,6 @@ attrib_type at_speedup = { /* ------------------------------------------------------------- */ -direction_t getdirection(const struct locale * lang) -{ - return finddirection(getstrtoken(), lang); -} - -/* ------------------------------------------------------------- */ - static attrib_type at_driveweight = { "driveweight", NULL, NULL, NULL, NULL, NULL }; diff --git a/src/kernel/move.h b/src/kernel/move.h index 621510d04..80744ce9f 100644 --- a/src/kernel/move.h +++ b/src/kernel/move.h @@ -47,7 +47,6 @@ extern "C" { ** pferde, macht nur noch 100, aber samt eigenem gewicht (40) macht also 140. */ int personcapacity(const struct unit *u); - direction_t getdirection(const struct locale *); void movement(void); void run_to(struct unit *u, struct region *to); struct unit *is_guarded(struct region *r, struct unit *u, unsigned int mask); diff --git a/src/kernel/order.c b/src/kernel/order.c index 9004fd4db..9005330e4 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -606,3 +606,9 @@ void push_order(order ** ordp, order * ord) ordp = &(*ordp)->next; *ordp = ord; } + +void init_tokens(const struct order *ord) +{ + char *cmd = getcommand(ord); + init_tokens_str(cmd, cmd); +} diff --git a/src/kernel/order.h b/src/kernel/order.h index 9e0ebeef5..c86b98792 100644 --- a/src/kernel/order.h +++ b/src/kernel/order.h @@ -57,6 +57,7 @@ extern "C" { extern int is_long(const order * ord); extern char *write_order(const order * ord, char *buffer, size_t size); + extern void init_tokens(const struct order *ord); /* initialize token parsing */ #ifdef __cplusplus } diff --git a/src/kernel/region.c b/src/kernel/region.c index bfaaab804..b78bb6d1c 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -628,13 +628,13 @@ int distance(const region * r1, const region * r2) static direction_t koor_reldirection(int ax, int ay, int bx, int by, const struct plane *pl) { - direction_t dir; + int dir; for (dir = 0; dir != MAXDIRECTIONS; ++dir) { int x = ax + delta_x[dir]; int y = ay + delta_y[dir]; pnormalize(&x, &y, pl); if (bx == x && by == y) - return dir; + return (direction_t)dir; } return NODIRECTION; } @@ -1593,9 +1593,9 @@ void region_set_morale(region * r, int morale, int turn) void get_neighbours(const region * r, region ** list) { - direction_t dir; + int dir; for (dir = 0; dir != MAXDIRECTIONS; ++dir) { - list[dir] = rconnect(r, dir); + list[dir] = rconnect(r, (direction_t)dir); } } From a8324f16fd946e11d3417b298a82bbcb04c082df Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Sun, 24 Jun 2012 08:04:12 +0200 Subject: [PATCH 06/24] make some prototypes use bool, not int --- src/gamecode/laws.c | 2 +- src/gamecode/laws.h | 2 +- src/kernel/config.c | 4 ++-- src/kernel/config.h | 2 +- src/kernel/move.c | 2 +- src/kernel/order.c | 12 ++++++------ src/kernel/order.h | 8 ++++---- src/kernel/region.c | 6 +++--- src/kernel/region.h | 2 +- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/gamecode/laws.c b/src/gamecode/laws.c index 3b332fec7..3e7ca3595 100755 --- a/src/gamecode/laws.c +++ b/src/gamecode/laws.c @@ -1327,7 +1327,7 @@ static void do_contact(region * r) } } -void do_enter(struct region *r, int is_final_attempt) +void do_enter(struct region *r, bool is_final_attempt) { unit **uptr; diff --git a/src/gamecode/laws.h b/src/gamecode/laws.h index 3cc5882e5..7f96db564 100755 --- a/src/gamecode/laws.h +++ b/src/gamecode/laws.h @@ -56,7 +56,7 @@ extern "C" { extern void restack_units(void); extern void update_long_order(struct unit *u); extern void sinkships(struct region * r); - extern void do_enter(struct region *r, int is_final_attempt); + extern void do_enter(struct region *r, bool is_final_attempt); extern int password_cmd(struct unit *u, struct order *ord); extern int banner_cmd(struct unit *u, struct order *ord); diff --git a/src/kernel/config.c b/src/kernel/config.c index 08970f71b..a6db38377 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -1403,13 +1403,13 @@ param_t findparam_ex(const char *s, const struct locale * lang) return (result == P_BUILDING) ? P_GEBAEUDE : result; } -int isparam(const char *s, const struct locale * lang, param_t param) +bool isparam(const char *s, const struct locale * lang, param_t param) { if (s[0]>'@') { param_t p = (param==P_GEBAEUDE) ? findparam_ex(s, lang) : findparam(s, lang); return p==param; } - return 0; + return false; } param_t getparam(const struct locale * lang) diff --git a/src/kernel/config.h b/src/kernel/config.h index e85325bc1..75be214e0 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -174,7 +174,7 @@ extern "C" { param_t findparam(const char *s, const struct locale *lang); param_t findparam_ex(const char *s, const struct locale * lang); - int isparam(const char *s, const struct locale * lang, param_t param); + bool isparam(const char *s, const struct locale * lang, param_t param); param_t getparam(const struct locale *lang); extern int getid(void); diff --git a/src/kernel/move.c b/src/kernel/move.c index 7eed52d5f..80bdfbd5a 100644 --- a/src/kernel/move.c +++ b/src/kernel/move.c @@ -633,7 +633,7 @@ static bool is_freezing(const unit * u) #define SA_NO_INSECT -1 #define SA_NO_COAST -2 -static int is_ship_allowed(struct ship *sh, const region * r) +static bool is_ship_allowed(struct ship *sh, const region * r) { int c = 0; static const building_type *bt_harbour = NULL; diff --git a/src/kernel/order.c b/src/kernel/order.c index 9004fd4db..d7105e8eb 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -373,7 +373,7 @@ order *parse_order(const char *s, const struct locale * lang) * \return true if the order is long * \sa is_exclusive(), is_repeated(), is_persistent() */ -int is_repeated(const order * ord) +bool is_repeated(const order * ord) { keyword_t kwd = ORD_KEYWORD(ord); const struct locale *lang = ORD_LOCALE(ord); @@ -439,7 +439,7 @@ int is_repeated(const order * ord) * \return true if the order is long * \sa is_exclusive(), is_repeated(), is_persistent() */ -int is_exclusive(const order * ord) +bool is_exclusive(const order * ord) { keyword_t kwd = ORD_KEYWORD(ord); const struct locale *lang = ORD_LOCALE(ord); @@ -500,11 +500,11 @@ int is_exclusive(const order * ord) * \return true if the order is long * \sa is_exclusive(), is_repeated(), is_persistent() */ -int is_long(const order * ord) +bool is_long(const order * ord) { keyword_t kwd = ORD_KEYWORD(ord); const struct locale *lang = ORD_LOCALE(ord); - int result = 0; + bool result = false; switch (kwd) { case K_CAST: @@ -550,7 +550,7 @@ int is_long(const order * ord) parser_popstate(); break; default: - result = 0; + result = false; } return result; } @@ -564,7 +564,7 @@ int is_long(const order * ord) * \return true if the order is persistent * \sa is_exclusive(), is_repeated(), is_persistent() */ -int is_persistent(const order * ord) +bool is_persistent(const order * ord) { keyword_t kwd = ORD_KEYWORD(ord); int persist = ord->_persistent != 0; diff --git a/src/kernel/order.h b/src/kernel/order.h index 9e0ebeef5..6e2159687 100644 --- a/src/kernel/order.h +++ b/src/kernel/order.h @@ -51,10 +51,10 @@ extern "C" { extern keyword_t get_keyword(const order * ord); extern void set_order(order ** destp, order * src); extern char *getcommand(const order * ord); - extern int is_persistent(const order * ord); - extern int is_exclusive(const order * ord); - extern int is_repeated(const order * ord); - extern int is_long(const order * ord); + extern bool is_persistent(const order * ord); + extern bool is_exclusive(const order * ord); + extern bool is_repeated(const order * ord); + extern bool is_long(const order * ord); extern char *write_order(const order * ord, char *buffer, size_t size); diff --git a/src/kernel/region.c b/src/kernel/region.c index bfaaab804..bdd16de12 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -817,17 +817,17 @@ bool r_isforest(const region * r) return false; } -int is_coastregion(region * r) +bool is_coastregion(region * r) { direction_t i; int res = 0; - for (i = 0; i < MAXDIRECTIONS; i++) { + for (i = 0; !res && i < MAXDIRECTIONS; i++) { region *rn = rconnect(r, i); if (rn && fval(rn->terrain, SEA_REGION)) res++; } - return res; + return res!=0; } int rpeasants(const region * r) diff --git a/src/kernel/region.h b/src/kernel/region.h index 88764586a..2cdd3dd95 100644 --- a/src/kernel/region.h +++ b/src/kernel/region.h @@ -210,7 +210,7 @@ extern "C" { short rroad(const struct region *r, direction_t d); void rsetroad(struct region *r, direction_t d, short value); - int is_coastregion(struct region *r); + bool is_coastregion(struct region *r); int rtrees(const struct region *r, int ageclass); enum { From 3cee3d14158e5a82c4f7e1ac53bd54867cc25587 Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Sun, 1 Jul 2012 19:17:47 +0200 Subject: [PATCH 07/24] lua 5.2 compat changes --- scripts/tests/common.lua | 10 +++---- src/CMakeLists.txt | 2 +- src/bindings/CMakeLists.txt | 2 +- src/bindings/bind_building.c | 1 - src/bindings/bind_faction.c | 1 - src/bindings/bind_gmtool.c | 1 - src/bindings/bind_hashtable.c | 1 - src/bindings/bind_message.c | 1 - src/bindings/bind_region.c | 1 - src/bindings/bind_ship.c | 1 - src/bindings/bind_sqlite.c | 1 - src/bindings/bind_storage.c | 1 - src/bindings/bind_unit.c | 1 - src/bindings/bindings.c | 11 ++++++-- src/bindings/helpers.c | 53 ++++++++++++----------------------- src/util/console.c | 9 +++--- 16 files changed, 37 insertions(+), 60 deletions(-) diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index 3fe4a1ae8..34f46b169 100755 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -594,7 +594,7 @@ function test_guard_resources() end local function is_flag_set(flags, flag) - return math.mod(flags, flag*2) - math.mod(flags, flag) == flag; + return math.fmod(flags, flag*2) - math.fmod(flags, flag) == flag; end function test_hero_hero_transfer() @@ -803,7 +803,7 @@ end local function find_in_report(f, pattern, extension) extension = extension or "nr" local filename = config.reportpath .. "/" .. get_turn() .. "-" .. itoa36(f.id) .. "." .. extension - local report = io.open(filename, 'rt'); + local report = io.open(filename, 'r'); assert_not_nil(report) t = report:read("*all") report:close() @@ -893,7 +893,7 @@ function test_parser() local u = unit.create(f, r, 1) local filename = config.basepath .. "/data/orders.txt" - local file = io.open(filename, "w+") + local file = io.open(filename, "w") assert_not_nil(file) file:write('ERESSEA ' .. itoa36(f.id) .. ' "' .. f.password .. '"\n') file:write('EINHEIT ' .. itoa36(u.id) .. "\n") @@ -956,7 +956,7 @@ function test_bug_1814() local u = unit.create(f, r, 1) local filename = config.basepath .. "/data/1814.txt" - local file = io.open(filename, "w+") + local file = io.open(filename, "w") file:write('ERESSEA ' .. itoa36(f.id) .. ' "' .. f.password .. '"\n') file:write('EINHEIT ' .. itoa36(u.id) .. "\n") file:write("; parse error follows: '\n") @@ -977,7 +977,7 @@ function test_bug_1679() local u = unit.create(f, r, 1) local filename = config.basepath .. "/data/1679.txt" - local file = io.open(filename, "w+") + local file = io.open(filename, "w") file:write('ERESSEA ' .. itoa36(f.id) .. ' "' .. f.password .. '"\n') file:write('EINHEIT ' .. itoa36(u.id) .. "\n") file:write("NACH W\n") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8421e4692..99c318a95 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,7 +13,7 @@ set (ERESSEA_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "Eressea Cor add_subdirectory(bindings) -find_package (Lua51 REQUIRED) +find_package (Lua52 REQUIRED) find_package (ToLua REQUIRED) find_package (LibXml2 REQUIRED) find_package (Curses REQUIRED) diff --git a/src/bindings/CMakeLists.txt b/src/bindings/CMakeLists.txt index 94efddcb2..f3945b4f5 100755 --- a/src/bindings/CMakeLists.txt +++ b/src/bindings/CMakeLists.txt @@ -9,7 +9,7 @@ ENDIF(CMAKE_COMPILER_IS_GNUCC) set (BINDINGS_LIBRARY ${PROJECT_NAME} CACHE INTERNAL "Eressea Lua Bindings") -find_package (Lua51 REQUIRED) +find_package (Lua52 REQUIRED) find_package (ToLua REQUIRED) find_package (LibXml2 REQUIRED) find_package (Curses REQUIRED) diff --git a/src/bindings/bind_building.c b/src/bindings/bind_building.c index 4e51a0a65..230ba5b88 100644 --- a/src/bindings/bind_building.c +++ b/src/bindings/bind_building.c @@ -21,7 +21,6 @@ without prior permission by the authors of Eressea. #include <util/language.h> -#include <lua.h> #include <tolua.h> int tolua_buildinglist_next(lua_State * L) diff --git a/src/bindings/bind_faction.c b/src/bindings/bind_faction.c index 111b49f37..d5efd226c 100644 --- a/src/bindings/bind_faction.c +++ b/src/bindings/bind_faction.c @@ -29,7 +29,6 @@ without prior permission by the authors of Eressea. #include <util/log.h> #include <quicklist.h> -#include <lua.h> #include <tolua.h> int tolua_factionlist_next(lua_State * L) diff --git a/src/bindings/bind_gmtool.c b/src/bindings/bind_gmtool.c index a55cb75b7..654f16f30 100644 --- a/src/bindings/bind_gmtool.c +++ b/src/bindings/bind_gmtool.c @@ -11,7 +11,6 @@ #include <modules/autoseed.h> #include <util/log.h> -#include <lua.h> #include <tolua.h> static int tolua_run_mapper(lua_State * L) diff --git a/src/bindings/bind_hashtable.c b/src/bindings/bind_hashtable.c index 2069e272b..17c6c4975 100644 --- a/src/bindings/bind_hashtable.c +++ b/src/bindings/bind_hashtable.c @@ -23,7 +23,6 @@ without prior permission by the authors of Eressea. #include <util/variant.h> #include <util/attrib.h> -#include <lua.h> #include <tolua.h> #include <assert.h> diff --git a/src/bindings/bind_message.c b/src/bindings/bind_message.c index 6ff30e98a..2959c6c5c 100644 --- a/src/bindings/bind_message.c +++ b/src/bindings/bind_message.c @@ -13,7 +13,6 @@ #include <util/message.h> /* lua includes */ -#include <lua.h> #include <tolua.h> #include <assert.h> diff --git a/src/bindings/bind_region.c b/src/bindings/bind_region.c index 58f64203c..b5fb16108 100644 --- a/src/bindings/bind_region.c +++ b/src/bindings/bind_region.c @@ -37,7 +37,6 @@ without prior permission by the authors of Eressea. #include <util/language.h> #include <util/log.h> -#include <lua.h> #include <tolua.h> #include <assert.h> diff --git a/src/bindings/bind_ship.c b/src/bindings/bind_ship.c index d5319dfe0..ddfa883ad 100644 --- a/src/bindings/bind_ship.c +++ b/src/bindings/bind_ship.c @@ -22,7 +22,6 @@ without prior permission by the authors of Eressea. #include <util/language.h> -#include <lua.h> #include <tolua.h> int tolua_shiplist_next(lua_State * L) diff --git a/src/bindings/bind_sqlite.c b/src/bindings/bind_sqlite.c index 0df9e530f..6f6c5ea29 100644 --- a/src/bindings/bind_sqlite.c +++ b/src/bindings/bind_sqlite.c @@ -16,7 +16,6 @@ without prior permission by the authors of Eressea. #include "bindings.h" #include <sqlite3.h> -#include <lua.h> #include <tolua.h> #define LTYPE_DB TOLUA_CAST "db" diff --git a/src/bindings/bind_storage.c b/src/bindings/bind_storage.c index 5e7768d2d..e2b83b670 100644 --- a/src/bindings/bind_storage.c +++ b/src/bindings/bind_storage.c @@ -22,7 +22,6 @@ without prior permission by the authors of Eressea. #include <math.h> #include <stdio.h> -#include <lua.h> #include <tolua.h> static int tolua_storage_create(lua_State * L) diff --git a/src/bindings/bind_unit.c b/src/bindings/bind_unit.c index 543a9f9d5..5d4dd9b47 100755 --- a/src/bindings/bind_unit.c +++ b/src/bindings/bind_unit.c @@ -51,7 +51,6 @@ without prior permission by the authors of Eressea. #include <util/log.h> #include <quicklist.h> -#include <lua.h> #include <tolua.h> #include <assert.h> diff --git a/src/bindings/bindings.c b/src/bindings/bindings.c index b452eb366..23f90cd8a 100755 --- a/src/bindings/bindings.c +++ b/src/bindings/bindings.c @@ -1182,12 +1182,17 @@ static const struct { static void openlibs(lua_State * L) { - int i; + luaL_openlibs(L); +/* int i, err; for (i = 0; lualibs[i].func; ++i) { lua_pushcfunction(L, lualibs[i].func); lua_pushstring(L, lualibs[i].name); - lua_call(L, 1, 0); + err = lua_pcall(L, 1, 0, 0); + if (err != 0) { + log_lua_error(L); + } } +*/ } void lua_done(lua_State * L) { @@ -1195,7 +1200,7 @@ void lua_done(lua_State * L) { } lua_State *lua_init(void) { - lua_State *L = lua_open(); + lua_State *L = luaL_newstate(); openlibs(L); #ifdef BINDINGS_TOLUA diff --git a/src/bindings/helpers.c b/src/bindings/helpers.c index d6d73d7b2..5658f590c 100644 --- a/src/bindings/helpers.c +++ b/src/bindings/helpers.c @@ -31,8 +31,8 @@ without prior permission by the authors of Eressea. #include <gamecode/archetype.h> -#include <lua.h> #include <tolua.h> +#include <lua.h> #include <assert.h> @@ -48,8 +48,7 @@ lua_giveitem(unit * s, unit * d, const item_type * itype, int n, struct order *o strlcpy(fname, iname, sizeof(fname)); strlcat(fname, "_give", sizeof(fname)); - lua_pushstring(L, fname); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, s, TOLUA_CAST "unit"); tolua_pushusertype(L, d, TOLUA_CAST "unit"); @@ -81,8 +80,7 @@ static int limit_resource(const region * r, const resource_type * rtype) strlcpy(fname, rtype->_name[0], sizeof(fname)); strlcat(fname, "_limit", sizeof(fname)); - lua_pushstring(L, fname); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, (void *)r, TOLUA_CAST "region"); @@ -111,8 +109,7 @@ produce_resource(region * r, const resource_type * rtype, int norders) strlcpy(fname, rtype->_name[0], sizeof(fname)); strlcat(fname, "_produce", sizeof(fname)); - lua_pushstring(L, fname); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, (void *)r, TOLUA_CAST "region"); tolua_pushnumber(L, (lua_Number) norders); @@ -140,8 +137,7 @@ static int lc_age(struct attrib *a) if (fname != NULL) { lua_State *L = (lua_State *) global.vm_state; - lua_pushstring(L, fname); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, (void *)b, TOLUA_CAST "building"); if (fparam) { @@ -201,8 +197,7 @@ static int lua_callspell(castorder * co) fname = fbuf; } - lua_pushstring(L, fname); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { int nparam = 4; tolua_pushusertype(L, r, TOLUA_CAST "region"); @@ -254,8 +249,7 @@ static int lua_initfamiliar(unit * u) strlcpy(fname, "initfamiliar_", sizeof(fname)); strlcat(fname, u->race->_name[0], sizeof(fname)); - lua_pushstring(L, fname); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, u, TOLUA_CAST "unit"); @@ -290,8 +284,7 @@ lua_changeresource(unit * u, const struct resource_type *rtype, int delta) strlcpy(fname, rtype->_name[0], sizeof(fname)); strlcat(fname, "_changeresource", sizeof(fname)); - lua_pushstring(L, fname); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, u, TOLUA_CAST "unit"); tolua_pushnumber(L, (lua_Number) delta); @@ -321,8 +314,7 @@ static int lua_getresource(unit * u, const struct resource_type *rtype) strlcpy(fname, rtype->_name[0], sizeof(fname)); strlcat(fname, "_getresource", sizeof(fname)); - lua_pushstring(L, fname); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, u, TOLUA_CAST "unit"); @@ -351,8 +343,7 @@ static bool lua_canuse_item(const unit * u, const struct item_type *itype) lua_State *L = (lua_State *) global.vm_state; const char *fname = "item_canuse"; - lua_pushstring(L, fname); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); tolua_pushstring(L, itype->rtype->_name[0]); @@ -381,8 +372,7 @@ lua_wage(const region * r, const faction * f, const race * rc, int in_turn) const char *fname = "wage"; int result = -1; - lua_pushstring(L, fname); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, (void *)r, TOLUA_CAST "region"); tolua_pushusertype(L, (void *)f, TOLUA_CAST "faction"); @@ -413,8 +403,7 @@ static void lua_agebuilding(building * b) strlcpy(fname, "age_", sizeof(fname)); strlcat(fname, b->type->_name, sizeof(fname)); - lua_pushstring(L, fname); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, (void *)b, TOLUA_CAST "building"); @@ -435,8 +424,7 @@ static int lua_building_protection(building * b, unit * u) const char *fname = "building_protection"; int result = 0; - lua_pushstring(L, fname); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, (void *)b, TOLUA_CAST "building"); tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); @@ -462,8 +450,7 @@ static double lua_building_taxes(building * b, int level) const char *fname = "building_taxes"; double result = 0.0F; - lua_pushstring(L, fname); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, (void *)b, TOLUA_CAST "building"); tolua_pushnumber(L, level); @@ -489,8 +476,7 @@ static int lua_maintenance(const unit * u) const char *fname = "maintenance"; int result = -1; - lua_pushstring(L, fname); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); @@ -519,8 +505,7 @@ static int lua_equipmentcallback(const struct equipment *eq, unit * u) strlcpy(fname, "equip_", sizeof(fname)); strlcat(fname, eq->name, sizeof(fname)); - lua_pushstring(L, fname); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); @@ -551,8 +536,7 @@ lua_useitem(struct unit *u, const struct item_type *itype, int amount, strlcpy(fname, "use_", sizeof(fname)); strlcat(fname, itype->rtype->_name[0], sizeof(fname)); - lua_pushstring(L, fname); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); tolua_pushnumber(L, (lua_Number) amount); @@ -582,8 +566,7 @@ static int lua_recruit(struct unit *u, const struct archetype *arch, int amount) strlcpy(fname, "recruit_", sizeof(fname)); strlcat(fname, arch->name[0], sizeof(fname)); - lua_pushstring(L, fname); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, fname); if (lua_isfunction(L, -1)) { tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); tolua_pushnumber(L, (lua_Number) amount); diff --git a/src/util/console.c b/src/util/console.c index 28586f704..0ce3704a8 100644 --- a/src/util/console.c +++ b/src/util/console.c @@ -29,7 +29,7 @@ #include <readline/history.h> #define default_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL) #define lua_saveline(L,idx) \ - if (lua_strlen(L,idx) > 0) /* non-empty line? */ \ + if (lua_rawlen(L,idx) > 0) /* non-empty line? */ \ add_history(lua_tostring(L, idx)); /* add it to history */ #define lua_freeline(L,b) ((void)L, free(b)) #else @@ -109,7 +109,7 @@ static int report(lua_State * L, int status) static int traceback(lua_State * L) { - lua_getfield(L, LUA_GLOBALSINDEX, "debug"); + lua_getglobal(L, "debug"); if (!lua_istable(L, -1)) { lua_pop(L, 1); return 1; @@ -149,8 +149,7 @@ static int docall(lua_State * L, int narg, int clear) static const char *get_prompt(lua_State * L, int firstline) { const char *p = NULL; - lua_pushstring(L, firstline ? "_PROMPT" : "_PROMPT2"); - lua_rawget(L, LUA_GLOBALSINDEX); + lua_getglobal(L, firstline ? "_PROMPT" : "_PROMPT2"); p = lua_tostring(L, -1); if (p == NULL) p = (firstline ? PROMPT : PROMPT2); @@ -195,7 +194,7 @@ static int loadline(lua_State * L) if (!pushline(L, 1)) return -1; /* no input */ for (;;) { /* repeat until gets a complete line */ - status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin"); + status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_rawlen(L, 1), "=stdin"); if (!incomplete(L, status)) break; /* cannot try to add lines? */ if (!pushline(L, 0)) /* no more input? */ From cb14492ccde24443b69974b8b2af5221ac934961 Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Sun, 1 Jul 2012 22:31:14 +0200 Subject: [PATCH 08/24] make cmake find the best Lua version that's installed --- src/CMakeLists.txt | 2 +- src/bindings/CMakeLists.txt | 2 +- src/bindings/bindings.c | 30 ------------------------------ 3 files changed, 2 insertions(+), 32 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 99c318a95..633509d2d 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,7 +13,7 @@ set (ERESSEA_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "Eressea Cor add_subdirectory(bindings) -find_package (Lua52 REQUIRED) +find_package (Lua 5 REQUIRED) find_package (ToLua REQUIRED) find_package (LibXml2 REQUIRED) find_package (Curses REQUIRED) diff --git a/src/bindings/CMakeLists.txt b/src/bindings/CMakeLists.txt index f3945b4f5..56310c2d3 100755 --- a/src/bindings/CMakeLists.txt +++ b/src/bindings/CMakeLists.txt @@ -9,7 +9,7 @@ ENDIF(CMAKE_COMPILER_IS_GNUCC) set (BINDINGS_LIBRARY ${PROJECT_NAME} CACHE INTERNAL "Eressea Lua Bindings") -find_package (Lua52 REQUIRED) +find_package (Lua 5 REQUIRED) find_package (ToLua REQUIRED) find_package (LibXml2 REQUIRED) find_package (Curses REQUIRED) diff --git a/src/bindings/bindings.c b/src/bindings/bindings.c index 23f90cd8a..904e3e015 100755 --- a/src/bindings/bindings.c +++ b/src/bindings/bindings.c @@ -1160,39 +1160,9 @@ int tolua_bindings_open(lua_State * L) return 1; } -static const struct { - const char *name; - int (*func) (lua_State *); -} lualibs[] = { - { - "", luaopen_base}, { - LUA_TABLIBNAME, luaopen_table}, { - LUA_IOLIBNAME, luaopen_io}, { - LUA_STRLIBNAME, luaopen_string}, { - LUA_MATHLIBNAME, luaopen_math}, { - LUA_LOADLIBNAME, luaopen_package}, { - LUA_DBLIBNAME, luaopen_debug}, -#if LUA_VERSION_NUM>=501 - { - LUA_OSLIBNAME, luaopen_os}, -#endif - { - NULL, NULL} -}; - static void openlibs(lua_State * L) { luaL_openlibs(L); -/* int i, err; - for (i = 0; lualibs[i].func; ++i) { - lua_pushcfunction(L, lualibs[i].func); - lua_pushstring(L, lualibs[i].name); - err = lua_pcall(L, 1, 0, 0); - if (err != 0) { - log_lua_error(L); - } - } -*/ } void lua_done(lua_State * L) { From bd34cbd350dc1ca0a539b71fd18ed3d8b98152c8 Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Tue, 26 Jun 2012 05:17:11 -0700 Subject: [PATCH 09/24] lua 5.1 and lua 5.2 side-by-side --- src/util/console.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/util/console.c b/src/util/console.c index 0ce3704a8..b850678c5 100644 --- a/src/util/console.c +++ b/src/util/console.c @@ -23,13 +23,17 @@ #define LUA_MAXINPUT 512 #endif +#if LUA_VERSION_NUM >= 502 +#define lua_strlen(L, idx) lua_rawlen(L, idx) +#endif + #if defined(LUA_USE_READLINE) #include <stdio.h> #include <readline/readline.h> #include <readline/history.h> #define default_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL) #define lua_saveline(L,idx) \ - if (lua_rawlen(L,idx) > 0) /* non-empty line? */ \ + if (lua_strlen(L,idx) > 0) /* non-empty line? */ \ add_history(lua_tostring(L, idx)); /* add it to history */ #define lua_freeline(L,b) ((void)L, free(b)) #else @@ -194,7 +198,7 @@ static int loadline(lua_State * L) if (!pushline(L, 1)) return -1; /* no input */ for (;;) { /* repeat until gets a complete line */ - status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_rawlen(L, 1), "=stdin"); + status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin"); if (!incomplete(L, status)) break; /* cannot try to add lines? */ if (!pushline(L, 0)) /* no more input? */ From 5e3ce7ad4d4d844e7f38dff5e832d48c17fae8e7 Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Tue, 26 Jun 2012 20:29:32 -0700 Subject: [PATCH 10/24] export more battle functions for e4 combat alliances have lists of diplomatic relations (enemies) --- src/kernel/alliance.h | 3 ++ src/kernel/battle.c | 81 +++++++++++++++++++++++++++++++------------ src/kernel/battle.h | 11 ++++-- src/kernel/config.h | 2 ++ src/kernel/faction.h | 2 +- src/kernel/types.h | 4 --- 6 files changed, 72 insertions(+), 31 deletions(-) diff --git a/src/kernel/alliance.h b/src/kernel/alliance.h index a97227ab0..04871c50a 100644 --- a/src/kernel/alliance.h +++ b/src/kernel/alliance.h @@ -40,6 +40,8 @@ extern "C" { #define ALF_NON_ALLIED (1<<0) /* this alliance is just a default for a non-allied faction */ +#define ALLY_ENEMY (1<<0) + typedef struct alliance { struct alliance *next; struct faction *_leader; @@ -47,6 +49,7 @@ extern "C" { unsigned int flags; int id; char *name; + struct ally *allies; } alliance; extern alliance *alliances; diff --git a/src/kernel/battle.c b/src/kernel/battle.c index 662c797c7..8dfd2357e 100644 --- a/src/kernel/battle.c +++ b/src/kernel/battle.c @@ -3137,6 +3137,45 @@ static int weapon_weight(const weapon * w, bool missile) return 0; } +side * get_side(battle * b, const const unit * u) +{ + side * s; + for (s = b->sides; s != b->sides + b->nsides; ++s) { + if (s->faction==u->faction) { + fighter * fig; + for (fig=s->fighters;fig;fig=fig->next) { + if (fig->unit==u) { + return s; + } + } + } + } + return 0; +} + +side * find_side(battle * b, const faction * f, const group * g, int flags, const faction * stealthfaction) +{ + side * s; + static int rule_anon_battle = -1; + + if (rule_anon_battle < 0) { + rule_anon_battle = get_param_int(global.parameters, "rules.stealth.anon_battle", 1); + } + for (s = b->sides; s != b->sides + b->nsides; ++s) { + if (s->faction == f && s->group == g) { + int s1flags = flags | SIDE_HASGUARDS; + int s2flags = s->flags | SIDE_HASGUARDS; + if (rule_anon_battle && s->stealthfaction != stealthfaction) { + continue; + } + if (s1flags == s2flags) { + return s; + } + } + } + return 0; +} + fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) { #define WMAX 20 @@ -3147,9 +3186,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) region *r = b->region; item *itm; fighter *fig = NULL; - int i, tactics = eff_skill(u, SK_TACTICS, r); - side *s2; - int h; + int h, i, tactics = eff_skill(u, SK_TACTICS, r); int berserk; int strongmen; int speeded = 0, speed = 1; @@ -3159,14 +3196,8 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) const attrib *a = a_find(u->attribs, &at_otherfaction); const faction *stealthfaction = a ? get_otherfaction(a) : NULL; unsigned int flags = 0; - static int rule_anon_battle = -1; assert(u->number); - - if (rule_anon_battle < 0) { - rule_anon_battle = - get_param_int(global.parameters, "rules.stealth.anon_battle", 1); - } if (fval(u, UFL_ANON_FACTION) != 0) flags |= SIDE_STEALTH; if (!(AllianceAuto() & HELP_FIGHT) && fval(u, UFL_GROUP)) { @@ -3180,20 +3211,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) return NULL; } if (s1 == NULL) { - for (s2 = b->sides; s2 != b->sides + b->nsides; ++s2) { - if (s2->faction == u->faction && s2->group == g) { - int s1flags = flags | SIDE_HASGUARDS; - int s2flags = s2->flags | SIDE_HASGUARDS; - if (rule_anon_battle && s2->stealthfaction != stealthfaction) { - continue; - } - if (s1flags == s2flags) { - s1 = s2; - break; - } - } - } - + s1 = find_side(b, u->faction, g, flags, stealthfaction); /* aliances are moved out of make_fighter and will be handled later */ if (!s1) { s1 = make_side(b, u->faction, g, flags, stealthfaction); @@ -3459,6 +3477,23 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) return fig; } +fighter * get_fighter(battle * b, const struct unit * u) +{ + side * s; + + for (s = b->sides; s != b->sides + b->nsides; ++s) { + fighter *fig; + if (s->faction == u->faction) { + for (fig = s->fighters; fig; fig = fig->next) { + if (fig->unit == u) { + return fig; + } + } + } + } + return 0; +} + static int join_battle(battle * b, unit * u, bool attack, fighter ** cp) { side *s; diff --git a/src/kernel/battle.h b/src/kernel/battle.h index 59ced0967..eb854caeb 100644 --- a/src/kernel/battle.h +++ b/src/kernel/battle.h @@ -114,9 +114,6 @@ extern "C" { } fast; } battle; - void battle_init(battle * b); - void battle_free(battle * b); - typedef struct weapon { int count, used; const struct weapon_type *type; @@ -208,6 +205,14 @@ extern "C" { extern const troop no_troop; + /* BEGIN battle interface */ + void battle_init(battle * b); + void battle_free(battle * b); + side * find_side(battle * b, const struct faction * f, const struct group * g, int flags, const struct faction * stealthfaction); + side * get_side(battle * b, const struct unit * u); + fighter * get_fighter(battle * b, const struct unit * u); + /* END battle interface */ + extern void do_battle(struct region *r); /* for combat spells and special attacks */ diff --git a/src/kernel/config.h b/src/kernel/config.h index 559bcae2d..4a3531444 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -119,6 +119,8 @@ extern "C" { int status; } ally; + ally * ally_find(const ally *al, const struct faction *f); + void remove_empty_units_in_region(struct region *r); void remove_empty_units(void); void remove_empty_factions(void); diff --git a/src/kernel/faction.h b/src/kernel/faction.h index e68cf8bcd..cc7239e82 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -125,7 +125,7 @@ extern "C" { extern void set_alliance(struct faction *a, struct faction *b, int status); extern int get_alliance(const struct faction *a, const struct faction *b); - extern struct alliance *f_get_alliance(const struct faction *a); + extern struct alliance *f_get_alliance(const struct faction *f); extern void write_faction_reference(const struct faction *f, struct storage *store); diff --git a/src/kernel/types.h b/src/kernel/types.h index ed895bfdd..130d576a0 100644 --- a/src/kernel/types.h +++ b/src/kernel/types.h @@ -394,10 +394,6 @@ typedef enum { /* ------------------------------------------------------------- */ /* Prototypen */ -#define ALLIED_TAX 1 -#define ALLIED_NOBLOCK 2 -#define ALLIED_HELP 4 - /* alle vierstelligen zahlen: */ #define MAX_UNIT_NR (36*36*36*36-1) #define MAX_CONTAINER_NR (36*36*36*36-1) From 6911af02b11a782e3ef363c0f341fd983e0b3d45 Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Sat, 30 Jun 2012 11:07:28 -0700 Subject: [PATCH 11/24] moving the ally struct into a separate file, with interface and test coverage. --- src/CMakeLists.txt | 2 ++ src/gamecode/creport.c | 1 + src/gamecode/laws.c | 1 + src/gamecode/report.c | 1 + src/gamecode/xmlreport.c | 1 + src/kernel/ally.c | 39 +++++++++++++++++++++++++++++++++++++++ src/kernel/ally.h | 40 ++++++++++++++++++++++++++++++++++++++++ src/kernel/ally_test.c | 27 +++++++++++++++++++++++++++ src/kernel/config.c | 1 + src/kernel/config.h | 8 -------- src/kernel/faction.c | 1 + src/kernel/group.c | 3 ++- src/kernel/save.c | 1 + src/kernel/types.h | 1 + src/tests.c | 1 + src/tests.h | 1 + 16 files changed, 120 insertions(+), 9 deletions(-) create mode 100644 src/kernel/ally.c create mode 100644 src/kernel/ally.h create mode 100644 src/kernel/ally_test.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9e9eb8d6c..8421e4692 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,6 +50,7 @@ set (TEST_SRC gamecode/economy_test.c gamecode/laws_test.c gamecode/market_test.c + kernel/ally_test.c kernel/battle_test.c kernel/building_test.c kernel/curse_test.c @@ -116,6 +117,7 @@ set (LIB_SRC items/xerewards.c kernel/alchemy.c kernel/alliance.c + kernel/ally.c kernel/battle.c kernel/binarystore.c kernel/build.c diff --git a/src/gamecode/creport.c b/src/gamecode/creport.c index 0a4768097..90374cb4b 100644 --- a/src/gamecode/creport.c +++ b/src/gamecode/creport.c @@ -33,6 +33,7 @@ without prior permission by the authors of Eressea. /* kernel includes */ #include <kernel/alchemy.h> #include <kernel/alliance.h> +#include <kernel/ally.h> #include <kernel/connection.h> #include <kernel/building.h> #include <kernel/curse.h> diff --git a/src/gamecode/laws.c b/src/gamecode/laws.c index 3e7ca3595..80a819f5c 100755 --- a/src/gamecode/laws.c +++ b/src/gamecode/laws.c @@ -37,6 +37,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* kernel includes */ #include <kernel/alchemy.h> #include <kernel/alliance.h> +#include <kernel/ally.h> #include <kernel/battle.h> #include <kernel/connection.h> #include <kernel/curse.h> diff --git a/src/gamecode/report.c b/src/gamecode/report.c index c01ea5089..898b06c20 100644 --- a/src/gamecode/report.c +++ b/src/gamecode/report.c @@ -38,6 +38,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* kernel includes */ #include <kernel/alchemy.h> +#include <kernel/ally.h> #include <kernel/connection.h> #include <kernel/build.h> #include <kernel/building.h> diff --git a/src/gamecode/xmlreport.c b/src/gamecode/xmlreport.c index 9ccf72a31..f4e4f9b6d 100644 --- a/src/gamecode/xmlreport.c +++ b/src/gamecode/xmlreport.c @@ -31,6 +31,7 @@ without prior permission by the authors of Eressea. /* kernel includes */ #include <kernel/alchemy.h> #include <kernel/alliance.h> +#include <kernel/ally.h> #include <kernel/connection.h> #include <kernel/curse.h> #include <kernel/building.h> diff --git a/src/kernel/ally.c b/src/kernel/ally.c new file mode 100644 index 000000000..cf5772fd6 --- /dev/null +++ b/src/kernel/ally.c @@ -0,0 +1,39 @@ +#include "types.h" +#include "ally.h" + +#include <stdlib.h> + +ally * ally_find(ally *al, const struct faction *f) { + for (;al;al=al->next) { + if (al->faction==f) return al; + } + return 0; +} + +ally * ally_add(ally **al_p, struct faction *f) { + ally * al; + while (*al_p) { + al = *al_p; + if (al->faction==f) return al; + al_p = &al->next; + } + al = (ally *)malloc(sizeof(ally)); + al->faction = f; + al->status = 0; + al->next = 0; + *al_p = al; + return al; +} + +void ally_remove(ally **al_p, struct faction *f) { + ally * al; + while (*al_p) { + al = *al_p; + if (al->faction==f) { + *al_p = al->next; + free(al); + break; + } + al_p = &al->next; + } +} diff --git a/src/kernel/ally.h b/src/kernel/ally.h new file mode 100644 index 000000000..5e09b721c --- /dev/null +++ b/src/kernel/ally.h @@ -0,0 +1,40 @@ +/* +Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> + Katja Zedel <katze@felidae.kn-bremen.de + Christian Schlittchen <corwin@amber.kn-bremen.de> + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +**/ + +#ifndef ALLY_H +#define ALLY_H + +#ifdef __cplusplus +extern "C" { +#endif + + typedef struct ally { + struct ally *next; + struct faction *faction; + int status; + } ally; + + ally * ally_find(ally *al, const struct faction *f); + ally * ally_add(ally **al_p, struct faction *f); + void ally_remove(ally **al_p, struct faction *f); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/kernel/ally_test.c b/src/kernel/ally_test.c new file mode 100644 index 000000000..c7b8500ad --- /dev/null +++ b/src/kernel/ally_test.c @@ -0,0 +1,27 @@ +#include <platform.h> +#include "types.h" +#include "ally.h" + +#include <CuTest.h> +#include <tests.h> + +static void test_ally(CuTest * tc) +{ + ally * al = 0; + struct faction * f1 = test_create_faction(0); + + ally_add(&al, f1); + CuAssertPtrNotNull(tc, al); + CuAssertPtrEquals(tc, f1, ally_find(al, f1)->faction); + + ally_remove(&al, f1); + CuAssertPtrEquals(tc, 0, al); + CuAssertPtrEquals(tc, 0, ally_find(al, f1)); +} + +CuSuite *get_ally_suite(void) +{ + CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_ally); + return suite; +} diff --git a/src/kernel/config.c b/src/kernel/config.c index 7d84f396a..224923bf3 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -25,6 +25,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* kernel includes */ #include "alliance.h" +#include "ally.h" #include "alchemy.h" #include "battle.h" #include "connection.h" diff --git a/src/kernel/config.h b/src/kernel/config.h index c9c43f89b..23542caf5 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -113,14 +113,6 @@ extern "C" { #define i2b(i) ((bool)((i)?(true):(false))) - typedef struct ally { - struct ally *next; - struct faction *faction; - int status; - } ally; - - ally * ally_find(const ally *al, const struct faction *f); - void remove_empty_units_in_region(struct region *r); void remove_empty_units(void); void remove_empty_factions(void); diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 8bf86e30a..ea02a62a1 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -21,6 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "faction.h" #include "alliance.h" +#include "ally.h" #include "equipment.h" #include "group.h" #include "item.h" diff --git a/src/kernel/group.c b/src/kernel/group.c index 8b6144d82..0e49fd4aa 100755 --- a/src/kernel/group.c +++ b/src/kernel/group.c @@ -21,9 +21,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "group.h" /* kernel includes */ -#include "unit.h" +#include "ally.h" #include "faction.h" #include "save.h" +#include "unit.h" #include "version.h" /* attrib includes */ diff --git a/src/kernel/save.c b/src/kernel/save.c index c8c39b50f..1ba845cc0 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -22,6 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "alchemy.h" #include "alliance.h" +#include "ally.h" #include "connection.h" #include "building.h" #include "faction.h" diff --git a/src/kernel/types.h b/src/kernel/types.h index 130d576a0..f6f1e4099 100644 --- a/src/kernel/types.h +++ b/src/kernel/types.h @@ -35,6 +35,7 @@ typedef short item_t; struct attrib; struct attrib_type; +struct ally; struct building; struct building_type; struct curse; diff --git a/src/tests.c b/src/tests.c index b269663dc..a0c5dcd94 100644 --- a/src/tests.c +++ b/src/tests.c @@ -51,6 +51,7 @@ int RunAllTests(void) CuSuiteAddSuite(suite, get_building_suite()); CuSuiteAddSuite(suite, get_spell_suite()); CuSuiteAddSuite(suite, get_battle_suite()); + CuSuiteAddSuite(suite, get_ally_suite()); /* gamecode */ CuSuiteAddSuite(suite, get_market_suite()); CuSuiteAddSuite(suite, get_laws_suite()); diff --git a/src/tests.h b/src/tests.h index 2b6b91cce..2ea13633e 100644 --- a/src/tests.h +++ b/src/tests.h @@ -25,6 +25,7 @@ extern "C" { CuSuite *get_bsdstring_suite(void); CuSuite *get_functions_suite(void); CuSuite *get_umlaut_suite(void); + CuSuite *get_ally_suite(void); void test_cleanup(void); From 5f5b4a394767c50a27c2f309f37eed379d12f036 Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Sat, 30 Jun 2012 20:29:04 +0200 Subject: [PATCH 12/24] there is an old version of tolua on gelbbaer that doesn't do comparisons of user types. ugh. --- scripts/tests/orders.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/orders.lua b/scripts/tests/orders.lua index b46e0c1c7..ac98a1d1b 100755 --- a/scripts/tests/orders.lua +++ b/scripts/tests/orders.lua @@ -140,7 +140,7 @@ end function test_process_move() r2 = _G.region.create(1, 0, 'plain') u:add_order('NACH O') - assert_not_equal(r2, u.region) + assert_not_equal(r2.id, u.region.id) eressea.process.update_long_order() eressea.process.movement() assert_equal(r2, u.region) From 9d8e02d094b2392f7e2f3c35efda982df6895839 Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Sun, 1 Jul 2012 18:00:31 -0700 Subject: [PATCH 13/24] test that movement into coastal regions is blocked when no harbor exists, unless ship is allowed in this terrain. --- src/kernel/move.c | 15 +++++--------- src/kernel/move.h | 6 ++++++ src/kernel/move_test.c | 47 ++++++++++++++++++++++++++++++++++++++++++ src/kernel/ship.c | 5 +++-- src/tests.c | 39 +++++++++++++++++++++-------------- src/tests.h | 3 +++ 6 files changed, 88 insertions(+), 27 deletions(-) diff --git a/src/kernel/move.c b/src/kernel/move.c index b7c30a677..8b3572f6d 100644 --- a/src/kernel/move.c +++ b/src/kernel/move.c @@ -621,12 +621,7 @@ static bool is_freezing(const unit * u) return true; } -#define SA_HARBOUR 1 -#define SA_COAST 1 -#define SA_NO_INSECT -1 -#define SA_NO_COAST -2 - -static bool is_ship_allowed(struct ship *sh, const region * r) +int check_ship_allowed(struct ship *sh, const region * r) { int c = 0; static const building_type *bt_harbour = NULL; @@ -634,7 +629,7 @@ static bool is_ship_allowed(struct ship *sh, const region * r) if (bt_harbour == NULL) bt_harbour = bt_find("harbour"); - if (r_insectstalled(r)) { + if (sh->region && r_insectstalled(r)) { /* insekten d�rfen nicht hier rein. haben wir welche? */ unit *u; @@ -654,7 +649,7 @@ static bool is_ship_allowed(struct ship *sh, const region * r) } } - if (buildingtype_exists(r, bt_harbour, true)) + if (bt_harbour && buildingtype_exists(r, bt_harbour, true)) return SA_HARBOUR; for (c = 0; sh->type->coasts[c] != NULL; ++c) { if (sh->type->coasts[c] == r->terrain) @@ -746,7 +741,7 @@ static void drifting_ships(region * r) region *rn; dir = (direction_t) ((d + d_offset) % MAXDIRECTIONS); rn = rconnect(r, dir); - if (rn != NULL && fval(rn->terrain, SAIL_INTO) && is_ship_allowed(sh, rn) > 0) { + if (rn != NULL && fval(rn->terrain, SAIL_INTO) && check_ship_allowed(sh, rn) > 0) { rnext = rn; if (!fval(rnext->terrain, SEA_REGION)) break; @@ -1809,7 +1804,7 @@ sail(unit * u, order * ord, bool move_on_land, region_list ** routep) } } - reason = is_ship_allowed(sh, next_point); + reason = check_ship_allowed(sh, next_point); if (reason<0) { /* for some reason or another, we aren't allowed in there.. */ if (check_leuchtturm(current_point, NULL) || reason == SA_NO_INSECT) { diff --git a/src/kernel/move.h b/src/kernel/move.h index 80744ce9f..c76c362c1 100644 --- a/src/kernel/move.h +++ b/src/kernel/move.h @@ -66,7 +66,13 @@ extern "C" { const struct building_type *bt); extern struct attrib_type at_speedup; + +#define SA_HARBOUR 2 +#define SA_COAST 1 +#define SA_NO_INSECT -1 +#define SA_NO_COAST -2 + extern int check_ship_allowed(struct ship *sh, const struct region * r); #ifdef __cplusplus } #endif diff --git a/src/kernel/move_test.c b/src/kernel/move_test.c index 172012e4d..3183d9a59 100644 --- a/src/kernel/move_test.c +++ b/src/kernel/move_test.c @@ -4,12 +4,57 @@ #include <kernel/building.h> #include <kernel/move.h> #include <kernel/region.h> +#include <kernel/ship.h> +#include <kernel/terrain.h> #include <util/language.h> #include <CuTest.h> #include <tests.h> +static void test_ship_not_allowed_in_coast(CuTest * tc) +{ + region *r; + ship * sh; + terrain_type * ttype; + ship_type * stype; + char * names[] = { "derp", "derp_p" }; + + test_cleanup(); + test_create_world(); + + ttype = test_create_terrain("glacier", LAND_REGION|ARCTIC_REGION|WALK_INTO|SAIL_INTO); + stype = test_create_shiptype(names); + stype->coasts = (const struct terrain_type **)calloc(2, sizeof(const struct terrain_type *)); + + r = test_create_region(0, 0, ttype); + sh = test_create_ship(0, stype); + + CuAssertIntEquals(tc, SA_NO_COAST, check_ship_allowed(sh, r)); + stype->coasts[0] = ttype; + CuAssertIntEquals(tc, SA_COAST, check_ship_allowed(sh, r)); +} + +static void test_ship_allowed_with_harbor(CuTest * tc) +{ + region *r; + ship * sh; + terrain_type * ttype; + building_type * btype; + + test_cleanup(); + test_create_world(); + + ttype = test_create_terrain("glacier", LAND_REGION|ARCTIC_REGION|WALK_INTO|SAIL_INTO); + btype = test_create_buildingtype("harbour"); + + r = test_create_region(0, 0, ttype); + sh = test_create_ship(0, 0); + + test_create_building(r, btype); + CuAssertIntEquals(tc, SA_HARBOUR, check_ship_allowed(sh, r)); +} + static void test_building_type_exists(CuTest * tc) { region *r; @@ -35,5 +80,7 @@ CuSuite *get_move_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_building_type_exists); + SUITE_ADD_TEST(suite, test_ship_not_allowed_in_coast); + SUITE_ADD_TEST(suite, test_ship_allowed_with_harbor); return suite; } diff --git a/src/kernel/ship.c b/src/kernel/ship.c index 141bd4ba9..96745c59e 100644 --- a/src/kernel/ship.c +++ b/src/kernel/ship.c @@ -171,7 +171,6 @@ ship *new_ship(const ship_type * stype, region * r, const struct locale *lang) const char *sname = 0; assert(stype); - assert(r); sh->no = newcontainerid(); sh->coast = NODIRECTION; sh->type = stype; @@ -188,7 +187,9 @@ ship *new_ship(const ship_type * stype, region * r, const struct locale *lang) slprintf(buffer, sizeof(buffer), "%s %s", sname, shipid(sh)); sh->name = strdup(buffer); shash(sh); - addlist(&r->ships, sh); + if (r) { + addlist(&r->ships, sh); + } return sh; } diff --git a/src/tests.c b/src/tests.c index a0c5dcd94..dd05c7d93 100644 --- a/src/tests.c +++ b/src/tests.c @@ -138,6 +138,26 @@ ship * test_create_ship(region * r, const ship_type * stype) return s; } +ship_type * test_create_shiptype(const char ** names) +{ + ship_type * stype = (ship_type*)calloc(sizeof(ship_type), 1); + stype->name[0] = strdup(names[0]); + stype->name[1] = strdup(names[1]); + locale_setstring(default_locale, names[0], names[0]); + st_register(stype); + return stype; +} + +building_type * test_create_buildingtype(const char * name) +{ + building_type * btype = (building_type*)calloc(sizeof(building_type), 1); + btype->flags = BTF_NAMECHANGE; + btype->_name = strdup(name); + locale_setstring(default_locale, name, name); + bt_register(btype); + return btype; +} + item_type * test_create_itemtype(const char ** names) { resource_type * rtype; item_type * itype; @@ -160,16 +180,14 @@ void test_create_world(void) terrain_type *t_plain, *t_ocean; region *island[2]; int i; - building_type *btype; - ship_type *stype; item_type * itype; - const char * horses[2] = { "horse", "horse_p" }; + const char * names[] = { "horse", "horse_p", "boat", "boat_p" }; make_locale("de"); init_resources(); assert(!olditemtype[I_HORSE]); - itype = test_create_itemtype(horses); + itype = test_create_itemtype(names); olditemtype[I_HORSE] = itype; t_plain = test_create_terrain("plain", LAND_REGION | FOREST_REGION | WALK_INTO | CAVALRY_REGION); @@ -192,17 +210,8 @@ void test_create_world(void) test_create_race("human"); - btype = (building_type*)calloc(sizeof(building_type), 1); - btype->flags = BTF_NAMECHANGE; - btype->_name = strdup("castle"); - locale_setstring(default_locale, "castle", "castle"); - bt_register(btype); - - stype = (ship_type*)calloc(sizeof(ship_type), 1); - stype->name[0] = strdup("boat"); - stype->name[1] = strdup("boat_p"); - locale_setstring(default_locale, "boat", "boat"); - st_register(stype); + test_create_buildingtype("castle"); + test_create_shiptype(names+2); } int main(int argc, char ** argv) { diff --git a/src/tests.h b/src/tests.h index 2ea13633e..15aa7a230 100644 --- a/src/tests.h +++ b/src/tests.h @@ -39,6 +39,9 @@ extern "C" { struct building * test_create_building(struct region * r, const struct building_type * btype); struct ship * test_create_ship(struct region * r, const struct ship_type * stype); struct item_type * test_create_itemtype(const char ** names); + struct ship_type *test_create_shiptype(const char **names); + struct building_type *test_create_buildingtype(const char *name); + int RunAllTests(void); #ifdef __cplusplus From f3286cbd0a616817efa288bba72f993bd32e7dd4 Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Mon, 2 Jul 2012 03:36:16 +0200 Subject: [PATCH 14/24] gcc is picky Conflicts: src/kernel/move_test.c --- src/kernel/move_test.c | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/kernel/move_test.c b/src/kernel/move_test.c index 172012e4d..cea15292e 100644 --- a/src/kernel/move_test.c +++ b/src/kernel/move_test.c @@ -10,6 +10,49 @@ #include <CuTest.h> #include <tests.h> +static void test_ship_not_allowed_in_coast(CuTest * tc) +{ + region *r; + ship * sh; + terrain_type * ttype; + ship_type * stype; + const char * names[] = { "derp", "derp_p" }; + + test_cleanup(); + test_create_world(); + + ttype = test_create_terrain("glacier", LAND_REGION|ARCTIC_REGION|WALK_INTO|SAIL_INTO); + stype = test_create_shiptype(names); + stype->coasts = (const struct terrain_type **)calloc(2, sizeof(const struct terrain_type *)); + + r = test_create_region(0, 0, ttype); + sh = test_create_ship(0, stype); + + CuAssertIntEquals(tc, SA_NO_COAST, check_ship_allowed(sh, r)); + stype->coasts[0] = ttype; + CuAssertIntEquals(tc, SA_COAST, check_ship_allowed(sh, r)); +} + +static void test_ship_allowed_with_harbor(CuTest * tc) +{ + region *r; + ship * sh; + terrain_type * ttype; + building_type * btype; + + test_cleanup(); + test_create_world(); + + ttype = test_create_terrain("glacier", LAND_REGION|ARCTIC_REGION|WALK_INTO|SAIL_INTO); + btype = test_create_buildingtype("harbour"); + + r = test_create_region(0, 0, ttype); + sh = test_create_ship(0, 0); + + test_create_building(r, btype); + CuAssertIntEquals(tc, SA_HARBOUR, check_ship_allowed(sh, r)); +} + static void test_building_type_exists(CuTest * tc) { region *r; From d4bd2bc7f7f7e1101dff49a189e822ed1c311851 Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Sun, 8 Jul 2012 11:37:19 -0700 Subject: [PATCH 15/24] remove DELIVER translate hunger in the NR --- res/de/strings.xml | 8 +++++--- src/gamecode/economy.c | 2 +- src/kernel/order.c | 5 ----- src/kernel/reports.c | 10 ++++++---- src/kernel/types.h | 1 - 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/res/de/strings.xml b/res/de/strings.xml index aea55a6a9..d7f7039f6 100644 --- a/res/de/strings.xml +++ b/res/de/strings.xml @@ -2200,9 +2200,6 @@ <string name="LERNEN"> <text locale="de">LERNEN</text> </string> - <string name="LIEFERE"> - <text locale="de">LIEFERE</text> - </string> <string name="MACHEN"> <text locale="de">MACHEN</text> </string> @@ -6980,6 +6977,11 @@ <text locale="en">guards the region</text> </string> + <string name="unit_hungers"> + <text locale="de">hungert</text> + <text locale="en">hungry</text> + </string> + <string name="list_and"> <text locale="de"> und </text> <text locale="en"> and </text> diff --git a/src/gamecode/economy.c b/src/gamecode/economy.c index 6668c3a21..859cdd079 100644 --- a/src/gamecode/economy.c +++ b/src/gamecode/economy.c @@ -1306,7 +1306,7 @@ void economics(region * r) ord = NULL; destroyed = true; } - } else if (kwd == K_GIVE || kwd == K_LIEFERE) { + } else if (kwd == K_GIVE) { give_cmd(u, ord); } else if (kwd == K_FORGET) { forget_cmd(u, ord); diff --git a/src/kernel/order.c b/src/kernel/order.c index 4457a5c6b..13cd7dc6d 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -260,10 +260,6 @@ static order *create_order_i(keyword_t kwd, const char *sptr, int persistent, case K_KOMMENTAR: case NOKEYWORD: return NULL; - case K_LIEFERE: - kwd = K_GIVE; - persistent = 1; - break; default: break; } @@ -575,7 +571,6 @@ bool is_persistent(const order * ord) return false; case K_KOMMENTAR: - case K_LIEFERE: return true; default: diff --git a/src/kernel/reports.c b/src/kernel/reports.c index 86995cb2d..54cdbb011 100644 --- a/src/kernel/reports.c +++ b/src/kernel/reports.c @@ -620,10 +620,12 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf, WARN_STATIC_BUFFER(); } if (fval(u, UFL_HUNGER)) { - if (c) - bytes = (int)strlcpy(bufp, ", hungert", size); - else - bytes = (int)strlcpy(bufp, "hungert", size); + if (c) { + bytes = (int)strlcpy(bufp, ", ", size); + if (wrptr(&bufp, &size, bytes) != 0) + WARN_STATIC_BUFFER(); + } + bytes = (int)strlcpy(bufp, LOC(f->locale, "unit_hungers"), size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } diff --git a/src/kernel/types.h b/src/kernel/types.h index f6f1e4099..f023e435a 100644 --- a/src/kernel/types.h +++ b/src/kernel/types.h @@ -101,7 +101,6 @@ typedef enum { K_CONTACT, K_TEACH, K_STUDY, - K_LIEFERE, K_MAKE, K_MOVE, K_PASSWORD, From 7b0bdd568d6e8c2d915dcaf0139020484cee1fa5 Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Sun, 8 Jul 2012 11:44:57 -0700 Subject: [PATCH 16/24] fix previous commit --- src/kernel/config.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/kernel/config.c b/src/kernel/config.c index 224923bf3..caf72d6cb 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -410,7 +410,6 @@ const char *keywords[MAXKEYWORDS] = { "KONTAKTIEREN", "LEHREN", "LERNEN", - "LIEFERE", "MACHEN", "NACH", "PASSWORT", From 9812a8dc3408db83b5e035fa48722bdc4a356d3d Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Sun, 8 Jul 2012 15:40:37 -0700 Subject: [PATCH 17/24] translate spell modifiers --- res/de/strings.xml | 25 +++++++++++++ src/gamecode/report.c | 81 +++++++++++++++++++------------------------ 2 files changed, 61 insertions(+), 45 deletions(-) diff --git a/res/de/strings.xml b/res/de/strings.xml index d7f7039f6..c0f770f37 100644 --- a/res/de/strings.xml +++ b/res/de/strings.xml @@ -6982,6 +6982,31 @@ <text locale="en">hungry</text> </string> + <string name="smod_far"> + <text locale="de">Fernzauber</text> + <text locale="en">far</text> + </string> + + <string name="smod_sea"> + <text locale="de">Seezauber</text> + <text locale="en">sea</text> + </string> + + <string name="smod_ship"> + <text locale="de">Schiffszauber</text> + <text locale="en">ship</text> + </string> + + <string name="smod_nofamiliar"> + <text locale="de">Magier exklusiv</text> + <text locale="en">magicians only</text> + </string> + + <string name="smod_none"> + <text locale="de">Keine</text> + <text locale="en">none</text> + </string> + <string name="list_and"> <text locale="de"> und </text> <text locale="en"> and </text> diff --git a/src/gamecode/report.c b/src/gamecode/report.c index 898b06c20..ee4f24608 100644 --- a/src/gamecode/report.c +++ b/src/gamecode/report.c @@ -218,12 +218,26 @@ rparagraph(FILE * F, const char *str, ptrdiff_t indent, int hanging_indent, } while (*begin); } +static size_t write_spell_modifier(spell * sp, int flag, const char * str, bool cont, char * bufp, size_t size) { + if (sp->sptyp & flag) { + size_t bytes = 0; + if (cont) { + bytes = strlcpy(bufp, ", ", size); + } else { + bytes = strlcpy(bufp, " ", size); + } + bytes += strlcpy(bufp+bytes, str, size-bytes); + return bytes; + } + return 0; +} + static void nr_spell(FILE * F, spellbook_entry * sbe, const struct locale *lang) { int bytes, k, itemanz, costtyp; int dh = 0; char buf[4096]; - char *bufp = buf; + char *startp, *bufp = buf; size_t size = sizeof(buf) - 1; spell * sp = sbe->sp; const char *params = sp->parameter; @@ -297,52 +311,29 @@ static void nr_spell(FILE * F, spellbook_entry * sbe, const struct locale *lang) bytes = (int)strlcpy(buf, LOC(lang, "nr_spell_modifiers"), size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - if (sp->sptyp & FARCASTING) { - bytes = (int)strlcpy(bufp, " Fernzauber", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - dh = 1; + + startp = bufp; + bytes = (int)write_spell_modifier(sp, FARCASTING, LOC(lang, "smod_far"), startp!=bufp, bufp, size); + if (bytes && wrptr(&bufp, &size, bytes) != 0) { + WARN_STATIC_BUFFER(); } - if (sp->sptyp & OCEANCASTABLE) { - if (dh == 1) { - bytes = (int)strlcpy(bufp, ",", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); + bytes = (int)write_spell_modifier(sp, OCEANCASTABLE, LOC(lang, "smod_sea"), startp!=bufp, bufp, size); + if (bytes && wrptr(&bufp, &size, bytes) != 0) { + WARN_STATIC_BUFFER(); + } + bytes = (int)write_spell_modifier(sp, ONSHIPCAST, LOC(lang, "smod_ship"), startp!=bufp, bufp, size); + if (bytes && wrptr(&bufp, &size, bytes) != 0) { + WARN_STATIC_BUFFER(); + } + bytes = (int)write_spell_modifier(sp, NOTFAMILIARCAST, LOC(lang, "smod_nofamiliar"), startp!=bufp, bufp, size); + if (bytes && wrptr(&bufp, &size, bytes) != 0) { + WARN_STATIC_BUFFER(); + } + if (startp==bufp) { + bytes = (int)write_spell_modifier(sp, NOTFAMILIARCAST, LOC(lang, "smod_none"), startp!=bufp, bufp, size); + if (bytes && wrptr(&bufp, &size, bytes) != 0) { + WARN_STATIC_BUFFER(); } - bytes = (int)strlcpy(bufp, " Seezauber", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - dh = 1; - } - if (sp->sptyp & ONSHIPCAST) { - if (dh == 1) { - bytes = (int)strlcpy(bufp, ",", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - } - bytes = (int)strlcpy(bufp, " Schiffszauber", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - dh = 1; - } - if (sp->sptyp & NOTFAMILIARCAST) { - if (dh == 1) { - bytes = (int)strlcpy(bufp, ", k", size); - } else { - bytes = (int)strlcpy(bufp, " K", size); - } - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - bytes = - (int)strlcpy(bufp, "ann nicht vom Vertrauten gezaubert werden", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); - dh = 1; - } - if (dh == 0) { - bytes = (int)strlcpy(bufp, " Keine", size); - if (wrptr(&bufp, &size, bytes) != 0) - WARN_STATIC_BUFFER(); } *bufp = 0; rparagraph(F, buf, 0, 0, 0); From e7f0650e4caa6e9b0c086b90a4afdb3ac7589ccf Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Sun, 8 Jul 2012 15:59:27 -0700 Subject: [PATCH 18/24] translate diplomatic status in the NR --- res/de/strings.xml | 20 ++++++++++++++++++++ src/gamecode/report.c | 8 ++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/res/de/strings.xml b/res/de/strings.xml index c0f770f37..72292a714 100644 --- a/res/de/strings.xml +++ b/res/de/strings.xml @@ -7007,6 +7007,26 @@ <text locale="en">none</text> </string> + <string name="faction_help_one"> + <text locale="de">Wir helfen der Partei</text> + <text locale="en">We are helping the faction</text> + </string> + + <string name="faction_help_many"> + <text locale="de">Wir helfen den Parteien</text> + <text locale="en">We are helping the factions</text> + </string> + + <string name="group_help_one"> + <text locale="de">hilft der Partei</text> + <text locale="en">is helping the faction</text> + </string> + + <string name="group_help_many"> + <text locale="de">hilft den Parteien</text> + <text locale="en">is helping the factions</text> + </string> + <string name="list_and"> <text locale="de"> und </text> <text locale="en"> and </text> diff --git a/src/gamecode/report.c b/src/gamecode/report.c index ee4f24608..c5a7346eb 100644 --- a/src/gamecode/report.c +++ b/src/gamecode/report.c @@ -1727,9 +1727,9 @@ static void allies(FILE * F, const faction * f) int bytes; size_t size = sizeof(buf); if (!f->allies->next) { - bytes = (int)strlcpy(buf, "Wir helfen der Partei ", size); + bytes = snprintf(buf, size, "%s ", LOC(f->locale, "faction_help_one")); } else { - bytes = (int)strlcpy(buf, "Wir helfen den Parteien ", size); + bytes = snprintf(buf, size, "%s ", LOC(f->locale, "faction_help_many")); } size -= bytes; show_allies(f, f->allies, buf + bytes, size); @@ -1742,9 +1742,9 @@ static void allies(FILE * F, const faction * f) int bytes; size_t size = sizeof(buf); if (!g->allies->next) { - bytes = snprintf(buf, size, "%s hilft der Partei ", g->name); + bytes = snprintf(buf, size, "%s %s ", g->name, LOC(f->locale, "group_help_one")); } else { - bytes = snprintf(buf, size, "%s hilft den Parteien ", g->name); + bytes = snprintf(buf, size, "%s %s ", g->name, LOC(f->locale, "group_help_many")); } size -= bytes; show_allies(f, g->allies, buf + bytes, size); From 9af5f08a8a63e61ea48dd02ab8aff042774a08ca Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Sun, 8 Jul 2012 16:04:45 -0700 Subject: [PATCH 19/24] translate region visibility in NR --- res/de/strings.xml | 15 +++++++++++++++ src/gamecode/report.c | 6 +++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/res/de/strings.xml b/res/de/strings.xml index 72292a714..2feb93f2a 100644 --- a/res/de/strings.xml +++ b/res/de/strings.xml @@ -7027,6 +7027,21 @@ <text locale="en">is helping the factions</text> </string> + <string name="see_travel"> + <text locale="de">durchgereist</text> + <text locale="en">travel</text> + </string> + + <string name="see_neighbour"> + <text locale="de">benachbart</text> + <text locale="en">neighbour</text> + </string> + + <string name="see_lighthouse"> + <text locale="de">vom Turm erblickt</text> + <text locale="en">from lighthouse</text> + </string> + <string name="list_and"> <text locale="de"> und </text> <text locale="en"> and </text> diff --git a/src/gamecode/report.c b/src/gamecode/report.c index c5a7346eb..1570a76b9 100644 --- a/src/gamecode/report.c +++ b/src/gamecode/report.c @@ -940,11 +940,11 @@ static void describe(FILE * F, const seen_region * sr, faction * f) WARN_STATIC_BUFFER(); if (sr->mode == see_travel) { - bytes = (int)strlcpy(bufp, " (durchgereist)", size); + bytes = snprintf(buf, size, " (%s)", LOC(f->locale, "see_travel")); } else if (sr->mode == see_neighbour) { - bytes = (int)strlcpy(bufp, " (benachbart)", size); + bytes = snprintf(buf, size, " (%s)", LOC(f->locale, "see_neighbour")); } else if (sr->mode == see_lighthouse) { - bytes = (int)strlcpy(bufp, " (vom Turm erblickt)", size); + bytes = snprintf(buf, size, " (%s)", LOC(f->locale, "see_lighthouse")); } else { bytes = 0; } From e01a420aa8edb53a72a926d952f7846ad780dfa0 Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Sun, 8 Jul 2012 16:10:48 -0700 Subject: [PATCH 20/24] translate travel-through message --- res/de/strings.xml | 10 ++++++++++ src/gamecode/report.c | 10 +++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/res/de/strings.xml b/res/de/strings.xml index 2feb93f2a..3b7b88f43 100644 --- a/res/de/strings.xml +++ b/res/de/strings.xml @@ -7027,6 +7027,16 @@ <text locale="en">is helping the factions</text> </string> + <string name="has_moved_one"> + <text locale="de">hat die Region durchquert</text> + <text locale="en">has traveled through the region</text> + </string> + + <string name="has_moved_many"> + <text locale="de">haben die Region durchquert</text> + <text locale="en">have traveled through the region</text> + </string> + <string name="see_travel"> <text locale="de">durchgereist</text> <text locale="en">travel</text> diff --git a/src/gamecode/report.c b/src/gamecode/report.c index 1570a76b9..3c773edc6 100644 --- a/src/gamecode/report.c +++ b/src/gamecode/report.c @@ -940,11 +940,11 @@ static void describe(FILE * F, const seen_region * sr, faction * f) WARN_STATIC_BUFFER(); if (sr->mode == see_travel) { - bytes = snprintf(buf, size, " (%s)", LOC(f->locale, "see_travel")); + bytes = snprintf(bufp, size, " (%s)", LOC(f->locale, "see_travel")); } else if (sr->mode == see_neighbour) { - bytes = snprintf(buf, size, " (%s)", LOC(f->locale, "see_neighbour")); + bytes = snprintf(bufp, size, " (%s)", LOC(f->locale, "see_neighbour")); } else if (sr->mode == see_lighthouse) { - bytes = snprintf(buf, size, " (%s)", LOC(f->locale, "see_lighthouse")); + bytes = snprintf(bufp, size, " (%s)", LOC(f->locale, "see_lighthouse")); } else { bytes = 0; } @@ -1432,9 +1432,9 @@ static void durchreisende(FILE * F, const region * r, const faction * f) } /* TODO: finish localization */ if (maxtravel == 1) { - bytes = (int)strlcpy(bufp, " hat die Region durchquert.", size); + bytes = snprintf(bufp, size, " %s", LOC(f->locale, "has_moved_one")); } else { - bytes = (int)strlcpy(bufp, " haben die Region durchquert.", size); + bytes = snprintf(bufp, size, " %s", LOC(f->locale, "has_moved_many")); } if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); From cb56a820b5607906d07f89b72409e79fc60a62ca Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Mon, 9 Jul 2012 01:25:09 +0200 Subject: [PATCH 21/24] fix gcc compilation fix broken test for duplicate orders --- scripts/tests/common.lua | 4 ++-- src/gamecode/report.c | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index 34f46b169..1b21a0390 100755 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -980,8 +980,8 @@ function test_bug_1679() local file = io.open(filename, "w") file:write('ERESSEA ' .. itoa36(f.id) .. ' "' .. f.password .. '"\n') file:write('EINHEIT ' .. itoa36(u.id) .. "\n") - file:write("NACH W\n") file:write("ARBEITEN\n") + file:write("NACH W\n") file:close() eressea.read_orders(filename) @@ -989,7 +989,7 @@ function test_bug_1679() init_reports() write_report(f) assert_true(find_in_report(f, "Die Einheit kann keine weiteren langen Befehle", "cr")) - assert_true(find_in_report(f, "entdeckt, dass es keinen Weg nach Westen gibt")) + assert_false(find_in_report(f, "entdeckt, dass es keinen Weg nach Westen gibt")) end function test_building_unique0() diff --git a/src/gamecode/report.c b/src/gamecode/report.c index 898b06c20..1a253cadb 100644 --- a/src/gamecode/report.c +++ b/src/gamecode/report.c @@ -221,7 +221,6 @@ rparagraph(FILE * F, const char *str, ptrdiff_t indent, int hanging_indent, static void nr_spell(FILE * F, spellbook_entry * sbe, const struct locale *lang) { int bytes, k, itemanz, costtyp; - int dh = 0; char buf[4096]; char *bufp = buf; size_t size = sizeof(buf) - 1; From 366f0feeaa27d48dde66d85854902120f6296326 Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Sun, 8 Jul 2012 19:15:06 -0700 Subject: [PATCH 22/24] need to mark ships for fishing even if not drifting (this code is bad) --- src/kernel/move.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/kernel/move.c b/src/kernel/move.c index 8b3572f6d..3113a1c58 100644 --- a/src/kernel/move.c +++ b/src/kernel/move.c @@ -692,7 +692,7 @@ static float damage_drift(void) static void drifting_ships(region * r) { direction_t d; - if (get_param_int(global.parameters, "rules.ship.drifting", 1)==0) return; + bool drift = get_param_int(global.parameters, "rules.ship.drifting", 1)!=0; if (fval(r->terrain, SEA_REGION)) { ship **shp = &r->ships; @@ -709,7 +709,7 @@ static void drifting_ships(region * r) } /* Schiff schon abgetrieben oder durch Zauber gesch�tzt? */ - if (fval(sh, SF_DRIFTED) || is_cursed(sh->attribs, C_SHIP_NODRIFT, 0)) { + if (!drift || fval(sh, SF_DRIFTED) || is_cursed(sh->attribs, C_SHIP_NODRIFT, 0)) { shp = &sh->next; continue; } From 3fda0ab14461adf6d13fa6727c7bb2b64193069b Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Sun, 8 Jul 2012 23:15:22 -0700 Subject: [PATCH 23/24] added an option to disable storms from configuration files --- src/kernel/move.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/kernel/move.c b/src/kernel/move.c index 3113a1c58..46a1cadfd 100644 --- a/src/kernel/move.c +++ b/src/kernel/move.c @@ -1720,9 +1720,12 @@ sail(unit * u, order * ord, bool move_on_land, region_list ** routep) int reason; if (gamecookie != global.cookie) { - gamedate date; - get_gamedate(turn, &date); - stormyness = storms[date.month] * 5; + bool storms_enabled = get_param_int(global.parameters, "rules.ship.storms", 1)!=0; + if (storms_enabled) { + gamedate date; + get_gamedate(turn, &date); + stormyness = storms[date.month] * 5; + } gamecookie = global.cookie; } From 5abfaad5281c82686ade64dc181a7aade5380de1 Mon Sep 17 00:00:00 2001 From: Enno Rehling <enno.rehling@gmail.com> Date: Mon, 9 Jul 2012 08:27:41 +0200 Subject: [PATCH 24/24] fixing intermittent tests --- scripts/tests/common.lua | 7 +++++++ src/gamecode/laws.c | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index 1b21a0390..3a7193ed0 100755 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -44,6 +44,7 @@ function setup() eressea.settings.set("nmr.timeout", "0") eressea.settings.set("NewbieImmunity", "0") eressea.settings.set("rules.economy.food", "4") + eressea.settings.set("rules.encounters", "0") end function test_fleeing_units_can_be_transported() @@ -885,6 +886,7 @@ function setup() eressea.free_game() eressea.write_game("free.dat") eressea.settings.set("rules.economy.food", "4") -- FOOD_IS_FREE + eressea.settings.set("rules.encounters", "0") end function test_parser() @@ -1132,7 +1134,12 @@ function test_bug_1875_use_help() assert_equal(0, u:get_item("peasantblood")) assert_equal(0, r:get_resource("peasant")) + assert_equal(0, r:get_resource("peasant")) assert_equal(0, u2:get_potion("peasantblood")) -- first unit helps this unit + if 98~=u:get_potion("peasantblood") then + print(get_turn(), f, u) + write_reports() + end assert_equal(98, u:get_potion("peasantblood")) -- unit uses one peasantblood effect end diff --git a/src/gamecode/laws.c b/src/gamecode/laws.c index 80a819f5c..7c0fc460c 100755 --- a/src/gamecode/laws.c +++ b/src/gamecode/laws.c @@ -4562,8 +4562,11 @@ void init_processor(void) p += 10; add_proc_order(p, K_GUARD, &guard_on_cmd, 0, "Bewache (an)"); - p += 10; - add_proc_global(p, &encounters, "Zufallsbegegnungen"); + if (get_param_int(global.parameters, "rules.encounters", 1)) { + p += 10; + add_proc_global(p, &encounters, "Zufallsbegegnungen"); + } + p += 10; add_proc_unit(p, &monster_kills_peasants, "Monster fressen und vertreiben Bauern");