From f98eab56c49d0217dc31c63417d2871d83c27453 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 29 Dec 2017 06:13:28 +0100 Subject: [PATCH] platform.h is only for WIN32 now. replace MIN and MAX macros, they are BAD. --- scripts/tests/e2/e2features.lua | 4 +- scripts/tests/e2/init.lua | 2 +- scripts/tests/e2/movement.lua | 1 + scripts/tests/e2/ships.lua | 1 - src/CMakeLists.txt | 2 +- src/alchemy.c | 1 + src/attributes/attributes.c | 1 + src/attributes/hate.c | 1 + src/attributes/moved.c | 1 + src/attributes/movement.c | 1 + src/battle.c | 4 +- src/bind_building.c | 14 +-- src/bind_config.c | 5 +- src/bind_eressea.c | 3 + src/bind_faction.c | 4 + src/bind_gmtool.c | 4 + src/bind_locale.c | 4 + src/bind_message.c | 4 + src/bind_monsters.c | 4 + src/bind_order.c | 4 + src/bind_process.c | 5 +- src/bind_region.c | 14 +-- src/bind_ship.c | 14 +-- src/bind_sqlite.c | 14 +-- src/bind_storage.c | 14 +-- src/bind_tolua.c | 2 + src/bind_unit.c | 14 +-- src/bindings.c | 14 +-- src/calendar.c | 8 +- src/console.c | 2 + src/creport.c | 53 ++++++----- src/economy.c | 151 +++++++++++++++-------------- src/economy.test.c | 3 + src/give.c | 164 +++++++++++++++++--------------- src/give.test.c | 16 ++++ src/gmtool.c | 12 ++- src/gmtool.h | 3 + src/helpers.c | 4 + src/items.c | 1 + src/items/speedsail.c | 1 + src/kernel/config.c | 29 ++++-- src/kernel/connection.c | 1 + src/kernel/curse.c | 1 + src/kernel/item.c | 1 + src/kernel/messages.c | 1 + src/kernel/messages.h | 4 +- src/kernel/render.h | 4 +- src/kernel/resources.c | 1 + src/kernel/ship.h | 4 +- src/kernel/spell.c | 3 +- src/kernel/spell.test.c | 1 + src/kernel/spellbook.c | 4 +- src/kernel/unit.c | 1 + src/kernel/unit.test.c | 3 +- src/kernel/version.c | 2 + src/laws.c | 13 +-- src/listbox.c | 4 +- src/magic.c | 5 +- src/main.c | 3 + src/modules/museum.c | 1 + src/monsters.c | 2 +- src/move.c | 39 +++++--- src/move.h | 2 +- src/names.c | 3 +- src/piracy.c | 1 + src/platform.h | 18 +--- src/prefix.test.c | 4 + src/randenc.c | 9 +- src/report.c | 56 ++++++----- src/reports.c | 45 +++++---- src/spells.c | 2 +- src/spells/borders.c | 6 +- src/spells/buildingcurse.c | 1 + src/spells/combatspells.c | 1 + src/spells/regioncurse.c | 1 + src/spells/shipcurse.c | 1 + src/spells/unitcurse.c | 1 + src/spy.c | 3 +- src/sqlite.c | 2 + src/study.c | 2 +- src/travelthru.test.c | 1 + src/triggers/changefaction.c | 3 +- src/triggers/changerace.c | 3 +- src/triggers/clonedied.c | 3 +- src/triggers/createcurse.c | 3 +- src/triggers/createunit.c | 1 + src/triggers/gate.c | 1 + src/triggers/giveitem.c | 1 + src/triggers/killunit.c | 1 + src/triggers/shock.c | 1 + src/triggers/timeout.c | 1 + src/util/base36.test.c | 4 + src/util/bsdstring.c | 2 + src/util/bsdstring.test.c | 3 + src/util/crmessage.c | 1 + src/util/functions.test.c | 3 + src/util/language.c | 4 + src/util/lists.c | 5 +- src/util/log.test.c | 3 + src/util/macros.h | 2 +- src/util/mt19937ar.c | 2 - src/util/rand.c | 5 + src/util/rng.test.c | 3 + src/util/strings.c | 3 + src/util/strings.test.c | 3 + src/util/translation.c | 11 ++- src/util/umlaut.test.c | 3 + src/wormhole.c | 3 +- 108 files changed, 540 insertions(+), 398 deletions(-) diff --git a/scripts/tests/e2/e2features.lua b/scripts/tests/e2/e2features.lua index 20b21ce75..ca3f68ebe 100644 --- a/scripts/tests/e2/e2features.lua +++ b/scripts/tests/e2/e2features.lua @@ -214,8 +214,8 @@ end function test_can_give_person() local r = region.create(0, 0, "plain") - local f1 = faction.create("human", "noreply@eressea.de", "de") - local f2 = faction.create("human", "noreply@eressea.de", "de") + local f1 = faction.create("human") + local f2 = faction.create("human") local u1 = unit.create(f1, r, 10) local u2 = unit.create(f2, r, 10) u1.faction.age = 10 diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index fed038628..9dd507671 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -1,3 +1,4 @@ +require 'tests.e2.e2features' require 'tests.e2.insects' require 'tests.e2.spells' require 'tests.e2.buildings' @@ -5,7 +6,6 @@ require 'tests.e2.production' require 'tests.e2.adamantium' require 'tests.e2.undead' require 'tests.e2.shiplanding' -require 'tests.e2.e2features' require 'tests.e2.movement' require 'tests.e2.destroy' require 'tests.e2.guard' diff --git a/scripts/tests/e2/movement.lua b/scripts/tests/e2/movement.lua index 232782e8e..fb82567af 100644 --- a/scripts/tests/e2/movement.lua +++ b/scripts/tests/e2/movement.lua @@ -165,6 +165,7 @@ function test_troll_example() u1:clear_orders() -- 3 trolls - 1 cart = 320, but not allowed? + u1.name='XXX' assert_nomove("3 trolls", u1) u1.number = 4 diff --git a/scripts/tests/e2/ships.lua b/scripts/tests/e2/ships.lua index ba410a56b..973d70f8e 100644 --- a/scripts/tests/e2/ships.lua +++ b/scripts/tests/e2/ships.lua @@ -56,7 +56,6 @@ function test_speedy_ship_slow() u2.ship = u1.ship u1:set_skill("sailing", 2) -- cptskill = 2^1 u2:set_skill("sailing", 24) -- sumskill = 50 - u1.name = "XXX" u1:add_order("NACH O O O O O O O O O O") process_orders() assert_equal(5, u1.region.x) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0f8c97109..b3b842a3a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,7 +28,7 @@ IF (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wsign-compare -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long") # SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c89") ELSEIF(MSVC) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4 /WX /MP /D_CRT_SECURE_NO_WARNINGS /D_USE_MATH_DEFINES") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4 /WX /MP /Za /D_CRT_SECURE_NO_WARNINGS /D_USE_MATH_DEFINES") set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libc.lib /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcd.lib /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:msvcrt.lib") set(CMAKE_EXE_LINKER_FLAGS_RELEASE diff --git a/src/alchemy.c b/src/alchemy.c index c933d3fa3..fbf1dfa07 100644 --- a/src/alchemy.c +++ b/src/alchemy.c @@ -37,6 +37,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include diff --git a/src/attributes/attributes.c b/src/attributes/attributes.c index 95d4f41fc..8ea24dddd 100644 --- a/src/attributes/attributes.c +++ b/src/attributes/attributes.c @@ -56,6 +56,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include diff --git a/src/attributes/hate.c b/src/attributes/hate.c index 7cba12514..e6751bdfb 100644 --- a/src/attributes/hate.c +++ b/src/attributes/hate.c @@ -24,6 +24,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#include #include #include diff --git a/src/attributes/moved.c b/src/attributes/moved.c index c66a5489c..e34b9c5e8 100644 --- a/src/attributes/moved.c +++ b/src/attributes/moved.c @@ -22,6 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#include #include diff --git a/src/attributes/movement.c b/src/attributes/movement.c index 4d79039ef..1b5ba3f94 100644 --- a/src/attributes/movement.c +++ b/src/attributes/movement.c @@ -22,6 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#include #include diff --git a/src/battle.c b/src/battle.c index bb269d119..3e0cd2931 100644 --- a/src/battle.c +++ b/src/battle.c @@ -68,12 +68,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include -#include #include #include +#include + /* libc includes */ #include #include diff --git a/src/bind_building.c b/src/bind_building.c index 42b92fc07..9e39a54a5 100644 --- a/src/bind_building.c +++ b/src/bind_building.c @@ -1,14 +1,6 @@ -/* -+-------------------+ -| | Enno Rehling -| Eressea PBEM host | Christian Schlittchen -| (c) 1998 - 2008 | Katja Zedel -| | Henning Peters -+-------------------+ - -This program may not be used, modified or distributed -without prior permission by the authors of Eressea. -*/ +#ifdef _MSC_VER +#include +#endif #include "bind_building.h" #include "bind_unit.h" diff --git a/src/bind_config.c b/src/bind_config.c index b4aa68d58..be9eb15db 100644 --- a/src/bind_config.c +++ b/src/bind_config.c @@ -1,6 +1,9 @@ +#ifdef _MSC_VER +#include +#endif + #include "bind_config.h" -#include #include #include #include diff --git a/src/bind_eressea.c b/src/bind_eressea.c index ffc23fbfc..11c03898d 100755 --- a/src/bind_eressea.c +++ b/src/bind_eressea.c @@ -1,3 +1,6 @@ +#ifdef _MSC_VER +#include +#endif #include "bind_eressea.h" #include diff --git a/src/bind_faction.c b/src/bind_faction.c index 6b02f13b9..c0875aae2 100644 --- a/src/bind_faction.c +++ b/src/bind_faction.c @@ -10,6 +10,10 @@ This program may not be used, modified or distributed without prior permission by the authors of Eressea. */ +#ifdef _MSC_VER +#include +#endif + #include "bind_faction.h" #include "bind_unit.h" #include "bindings.h" diff --git a/src/bind_gmtool.c b/src/bind_gmtool.c index 43f4138fa..5c08f6e2c 100644 --- a/src/bind_gmtool.c +++ b/src/bind_gmtool.c @@ -1,3 +1,7 @@ +#ifdef _MSC_VER +#include +#endif + #include #include "bind_gmtool.h" diff --git a/src/bind_locale.c b/src/bind_locale.c index 992f140b7..ce46792d2 100644 --- a/src/bind_locale.c +++ b/src/bind_locale.c @@ -1,3 +1,7 @@ +#ifdef _MSC_VER +#include +#endif + #include "bind_locale.h" #include "util/language.h" #include "direction.h" diff --git a/src/bind_message.c b/src/bind_message.c index c553d3e67..8eee85bc1 100644 --- a/src/bind_message.c +++ b/src/bind_message.c @@ -1,3 +1,7 @@ +#ifdef _MSC_VER +#include +#endif + #include "spells.h" /* kernel includes */ diff --git a/src/bind_monsters.c b/src/bind_monsters.c index 7c7a50940..76afffc15 100644 --- a/src/bind_monsters.c +++ b/src/bind_monsters.c @@ -1,3 +1,7 @@ +#ifdef _MSC_VER +#include +#endif + #include "spells/shipcurse.h" #include "monsters.h" diff --git a/src/bind_order.c b/src/bind_order.c index 624e4f92e..407e29037 100644 --- a/src/bind_order.c +++ b/src/bind_order.c @@ -1,3 +1,7 @@ +#ifdef _MSC_VER +#include +#endif + /* kernel includes */ #include #include diff --git a/src/bind_process.c b/src/bind_process.c index 2b44eb19d..947458ce5 100755 --- a/src/bind_process.c +++ b/src/bind_process.c @@ -1,6 +1,9 @@ +#ifdef _MSC_VER +#include +#endif + #include "bind_process.h" -#include #include #include #include diff --git a/src/bind_region.c b/src/bind_region.c index 41cff035f..8514bf639 100644 --- a/src/bind_region.c +++ b/src/bind_region.c @@ -1,14 +1,6 @@ -/* -+-------------------+ -| | Enno Rehling -| Eressea PBEM host | Christian Schlittchen -| (c) 1998 - 2008 | Katja Zedel -| | Henning Peters -+-------------------+ - -This program may not be used, modified or distributed -without prior permission by the authors of Eressea. -*/ +#ifdef _MSC_VER +#include +#endif #include "bind_region.h" #include "bind_unit.h" diff --git a/src/bind_ship.c b/src/bind_ship.c index ae53ef913..2a1d75271 100644 --- a/src/bind_ship.c +++ b/src/bind_ship.c @@ -1,14 +1,6 @@ -/* -+-------------------+ -| | Enno Rehling -| Eressea PBEM host | Christian Schlittchen -| (c) 1998 - 2008 | Katja Zedel -| | Henning Peters -+-------------------+ - -This program may not be used, modified or distributed -without prior permission by the authors of Eressea. -*/ +#ifdef _MSC_VER +#include +#endif #include "bind_ship.h" #include "bind_unit.h" diff --git a/src/bind_sqlite.c b/src/bind_sqlite.c index ee2d58666..3af4843ea 100644 --- a/src/bind_sqlite.c +++ b/src/bind_sqlite.c @@ -1,14 +1,6 @@ -/* -+-------------------+ -| | Enno Rehling -| Eressea PBEM host | Christian Schlittchen -| (c) 1998 - 2008 | Katja Zedel -| | Henning Peters -+-------------------+ - -This program may not be used, modified or distributed -without prior permission by the authors of Eressea. -*/ +#ifdef _MSC_VER +#include +#endif #include "bind_unit.h" #include "bindings.h" diff --git a/src/bind_storage.c b/src/bind_storage.c index ce35ad2f0..e1339312c 100644 --- a/src/bind_storage.c +++ b/src/bind_storage.c @@ -1,14 +1,6 @@ -/* -+-------------------+ -| | Enno Rehling -| Eressea PBEM host | Christian Schlittchen -| (c) 1998 - 2008 | Katja Zedel -| | Henning Peters -+-------------------+ - -This program may not be used, modified or distributed -without prior permission by the authors of Eressea. -*/ +#ifdef _MSC_VER +#include +#endif #include "bind_storage.h" diff --git a/src/bind_tolua.c b/src/bind_tolua.c index 9a5b8e184..669d5848b 100644 --- a/src/bind_tolua.c +++ b/src/bind_tolua.c @@ -1,4 +1,6 @@ +#ifdef _MSC_VER #include +#endif #pragma warning(push) #pragma warning(disable: 4100) #include "config.pkg.c" diff --git a/src/bind_unit.c b/src/bind_unit.c index 3d455f3a9..cdfeec39d 100644 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -1,14 +1,6 @@ -/* -+-------------------+ -| | Enno Rehling -| Eressea PBEM host | Christian Schlittchen -| (c) 1998 - 2008 | Katja Zedel -| | Henning Peters -+-------------------+ - -This program may not be used, modified or distributed -without prior permission by the authors of Eressea. -*/ +#ifdef _MSC_VER +#include +#endif #include "bind_unit.h" #include "alchemy.h" diff --git a/src/bindings.c b/src/bindings.c index f5acdb1e9..c5494e64b 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -1,14 +1,6 @@ -/* -+-------------------+ -| | Enno Rehling -| Eressea PBEM host | Christian Schlittchen -| (c) 1998 - 2008 | Katja Zedel -| | Henning Peters -+-------------------+ - -This program may not be used, modified or distributed -without prior permission by the authors of Eressea. -*/ +#ifdef _MSC_VER +#include +#endif #include "bindings.h" #include "bind_unit.h" diff --git a/src/calendar.c b/src/calendar.c index c93e5bcf8..23562daa6 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -1,4 +1,6 @@ +#ifdef _MSC_VER #include +#endif #include "calendar.h" #include "move.h" /* storms */ @@ -36,15 +38,15 @@ int first_turn(void) return config_get_int("game.start", 0); } -const gamedate *get_gamedate(int turn, gamedate * gd) +const gamedate *get_gamedate(int turn_now, gamedate * gd) { int weeks_per_year = months_per_year * weeks_per_month; - int t = turn - first_turn(); + int t = turn_now - first_turn(); assert(gd); assert(t>=0); - gd->turn = turn; + gd->turn = turn_now; gd->week = t % weeks_per_month; /* 0 - weeks_per_month-1 */ gd->month = (t / weeks_per_month + first_month) % months_per_year; /* 0 - months_per_year-1 */ gd->year = 1 + t / weeks_per_year; diff --git a/src/console.c b/src/console.c index 034dd9994..c20c0d8b9 100644 --- a/src/console.c +++ b/src/console.c @@ -1,4 +1,6 @@ +#ifdef _MSC_VER #include +#endif #include "console.h" /* lua includes */ diff --git a/src/creport.c b/src/creport.c index 96264f555..e5732036a 100644 --- a/src/creport.c +++ b/src/creport.c @@ -68,6 +68,7 @@ without prior permission by the authors of Eressea. #include #include #include +#include #include #include #include @@ -620,6 +621,26 @@ static void cr_output_messages(FILE * F, message_list * msgs, faction * f) render_messages(F, f, msgs); } +static void cr_output_battles(FILE * F, faction * f) +{ + struct bmsg *bm; + for (bm = f->battles; bm; bm = bm->next) { + region *rb = bm->r; + plane *pl = rplane(rb); + int plid = plane_id(pl); + int nx = rb->x, ny = rb->y; + + pnormalize(&nx, &ny, pl); + adjust_coordinates(f, &nx, &ny, pl); + if (!plid) + fprintf(F, "BATTLE %d %d\n", nx, ny); + else { + fprintf(F, "BATTLE %d %d %d\n", nx, ny, plid); + } + cr_output_messages(F, bm->msgs, f); + } +} + /* prints a building */ static void cr_output_building(struct stream *out, building *b, const unit *owner, int fno, faction *f) @@ -947,7 +968,7 @@ void cr_output_unit(stream *out, const faction * f, /* spells that this unit can cast */ mage = get_mage_depr(u); if (mage) { - int i, maxlevel = effskill(u, SK_MAGIC, 0); + int maxlevel = effskill(u, SK_MAGIC, 0); cr_output_spells(out, u, maxlevel); for (i = 0; i != MAXCOMBATSPELLS; ++i) { @@ -1100,7 +1121,7 @@ static void cr_reportspell(FILE * F, spell * sp, int level, const struct locale int itemanz = sp->components[k].amount; int costtyp = sp->components[k].cost; if (itemanz > 0) { - const char *name = resourcename(rtype, 0); + name = resourcename(rtype, 0); fprintf(F, "%d %d;%s\n", itemanz, costtyp == SPC_LEVEL || costtyp == SPC_LINEAR, translate(name, LOC(lang, name))); } @@ -1432,14 +1453,15 @@ static void cr_output_region(FILE * F, report_context * ctx, region * r) if (rl) { region_list *rl2 = rl; while (rl2) { - region *r = rl2->data; - int nx = r->x, ny = r->y; - plane *plx = rplane(r); + region *r2 = rl2->data; + plane *plx = rplane(r2); + nx = r2->x; + ny = r2->y; pnormalize(&nx, &ny, plx); adjust_coordinates(f, &nx, &ny, plx); fprintf(F, "SCHEMEN %d %d\n", nx, ny); - fprintf(F, "\"%s\";Name\n", rname(r, f->locale)); + fprintf(F, "\"%s\";Name\n", rname(r2, f->locale)); rl2 = rl2->next; } free_regionlist(rl); @@ -1619,24 +1641,7 @@ report_computer(const char *filename, report_context * ctx, const char *bom) } cr_output_messages(F, f->msgs, f); - { - struct bmsg *bm; - for (bm = f->battles; bm; bm = bm->next) { - plane *pl = rplane(bm->r); - int plid = plane_id(pl); - region *r = bm->r; - int nx = r->x, ny = r->y; - - pnormalize(&nx, &ny, pl); - adjust_coordinates(f, &nx, &ny, pl); - if (!plid) - fprintf(F, "BATTLE %d %d\n", nx, ny); - else { - fprintf(F, "BATTLE %d %d %d\n", nx, ny, plid); - } - cr_output_messages(F, bm->msgs, f); - } - } + cr_output_battles(F, f); cr_find_address(F, f, ctx->addresses); a = a_find(f->attribs, &at_reportspell); diff --git a/src/economy.c b/src/economy.c index c7ab2247d..479edda9a 100644 --- a/src/economy.c +++ b/src/economy.c @@ -86,7 +86,6 @@ static econ_request entertainers[1024]; static econ_request *nextentertainer; static int entertaining; -static unsigned int norders; static econ_request *g_requests; #define RECRUIT_MERGE 1 @@ -179,16 +178,16 @@ unsigned int expand_production(region * r, econ_request * requests, econ_request *results = NULL; } while (requests) { - econ_request *o = requests->next; + econ_request *req = requests->next; free_order(requests->ord); free(requests); - requests = o; + requests = req; } return norders; } -static void expandorders(region * r, econ_request * requests) { - norders = expand_production(r, requests, &g_requests); +static unsigned int expandorders(region * r, econ_request * requests) { + return expand_production(r, requests, &g_requests); } /* ------------------------------------------------------------- */ @@ -802,12 +801,12 @@ void economics(region * r) } -static void mod_skill(const resource_mod *mod, skill_t sk, int *skill) { +static void mod_skill(const resource_mod *mod, skill_t sk, int *value) { skill_t msk; assert(mod->type == RMT_PROD_SKILL); msk = (skill_t)mod->value.sa[0]; if (msk == NOSKILL || msk == sk) { - *skill += mod->value.sa[1]; + *value += mod->value.sa[1]; } } @@ -1023,8 +1022,9 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) /* mit Flinkfingerring verzehnfacht sich die Produktion */ rring = get_resourcetype(R_RING_OF_NIMBLEFINGER); if (rring) { - int dm = i_get(u->items, rring->itype); - amount += skill * MIN(u->number, dm) * (roqf_factor() - 1); + int more = i_get(u->items, rring->itype); + if (more > u->number) more = u->number; + amount += skill * more * (roqf_factor() - 1); } /* Schaffenstrunk: */ @@ -1117,9 +1117,9 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) if (avail > 0) { int want = required(al->want - al->get, al->save); int x = avail * want / nreq; - int r = (avail * want) % nreq; + int req = (avail * want) % nreq; /* Wenn Rest, dann wuerfeln, ob ich etwas bekomme: */ - if (r > 0 && rng_int() % nreq < r) ++x; + if (req > 0 && rng_int() % nreq < req) ++x; avail -= x; use += x; nreq -= want; @@ -1285,7 +1285,7 @@ void make_item(unit * u, const item_type * itype, int want) int make_cmd(unit * u, struct order *ord) { - char token[128]; + char token[32]; region *r = u->region; const building_type *btype = 0; const ship_type *stype = 0; @@ -1322,7 +1322,7 @@ int make_cmd(unit * u, struct order *ord) cmistake(u, ord, 275, MSG_PRODUCE); } else { - const char * s = gettoken(token, sizeof(token)); + s = gettoken(token, sizeof(token)); direction_t d = s ? get_direction(s, u->faction->locale) : NODIRECTION; if (d != NODIRECTION) { build_road(u, m, d); @@ -1471,7 +1471,7 @@ static void expandbuying(region * r, econ_request * buyorders) * gehandelten Produktes. */ if (max_products > 0) { unsigned int j; - expandorders(r, buyorders); + unsigned int norders = expandorders(r, buyorders); if (!norders) return; @@ -1486,18 +1486,20 @@ static void expandbuying(region * r, econ_request * buyorders) if (get_pooled(g_requests[j].unit, rsilver, GET_DEFAULT, price) >= price) { - unit *u = g_requests[j].unit; item *items; - /* litems z�hlt die G�ter, die verkauft wurden, u->n das Geld, das * verdient wurde. Dies mu� gemacht werden, weil der Preis st�ndig sinkt, * man sich also das verdiente Geld und die verkauften Produkte separat * merken mu�. */ - attrib *a = a_find(u->attribs, &at_luxuries); - if (a == NULL) - a = a_add(&u->attribs, a_new(&at_luxuries)); + attrib *a; + u = g_requests[j].unit; + a = a_find(u->attribs, &at_luxuries); + if (a == NULL) { + a = a_add(&u->attribs, a_new(&at_luxuries)); + } items = a->data.v; + i_change(&items, ltype->itype, 1); a->data.v = items; i_change(&g_requests[j].unit->items, ltype->itype, 1); @@ -1667,7 +1669,7 @@ static int tax_per_size[7] = { 0, 6, 12, 18, 24, 30, 36 }; static void expandselling(region * r, econ_request * sellorders, int limit) { int money, price, max_products; - unsigned int j; + unsigned int j, norders; /* int m, n = 0; */ int maxsize = 0, maxeffsize = 0; int taxcollected = 0; @@ -1742,9 +1744,10 @@ static void expandselling(region * r, econ_request * sellorders, int limit) /* Verkauf: so programmiert, dass er leicht auf mehrere Gueter pro * Runde erweitert werden kann. */ - expandorders(r, sellorders); - if (!norders) + norders = expandorders(r, sellorders); + if (norders == 0) { return; + } for (j = 0; j != norders; j++) { const luxury_type *search = NULL; @@ -1763,19 +1766,22 @@ static void expandselling(region * r, econ_request * sellorders, int limit) price = ltype->price * multi; if (money >= price) { - unit *u = g_requests[j].unit; item *itm; - attrib *a = a_find(u->attribs, &at_luxuries); - if (a == NULL) + attrib *a; + u = g_requests[j].unit; + a = a_find(u->attribs, &at_luxuries); + if (!a) { a = a_add(&u->attribs, a_new(&at_luxuries)); + } itm = (item *)a->data.v; i_change(&itm, ltype->itype, 1); a->data.v = itm; ++use; - if (u->n < 0) + if (u->n < 0) { u->n = 0; + } - if (hafenowner != NULL) { + if (hafenowner) { if (hafenowner->faction != u->faction) { int abgezogenhafen = price / 10; hafencollected += abgezogenhafen; @@ -1783,7 +1789,7 @@ static void expandselling(region * r, econ_request * sellorders, int limit) money -= abgezogenhafen; } } - if (maxb != NULL) { + if (maxb) { if (maxowner->faction != u->faction) { int abgezogensteuer = price * tax_per_size[maxeffsize] / 100; taxcollected += abgezogensteuer; @@ -2423,9 +2429,9 @@ expandwork(region * r, econ_request * work_begin, econ_request * work_end, int m if (jobs >= working) workers = u->number; else { - int r = (u->number * jobs) % working; + int req = (u->number * jobs) % working; workers = u->number * jobs / working; - if (r > 0 && rng_int() % working < r) + if (req > 0 && rng_int() % working < req) workers++; } @@ -2491,37 +2497,38 @@ static int do_work(unit * u, order * ord, econ_request * o) static void expandloot(region * r, econ_request * lootorders) { - unit *u; - unsigned int i; - int m, looted = 0; - int startmoney = rmoney(r); + unsigned int norders; - expandorders(r, lootorders); - if (!norders) - return; + norders = expandorders(r, lootorders); + if (norders > 0) { + unit *u; + unsigned int i; + int m, looted = 0; + int startmoney = rmoney(r); - for (i = 0; i != norders && startmoney > looted + TAXFRACTION * 2; i++) { - change_money(g_requests[i].unit, TAXFRACTION); - g_requests[i].unit->n += TAXFRACTION; - /*Looting destroys double the money*/ - looted += TAXFRACTION * 2; - } - rsetmoney(r, startmoney - looted); - free(g_requests); - - /* Lowering morale by 1 depending on the looted money (+20%) */ - m = region_get_morale(r); - if (m && startmoney > 0) { - if (rng_int() % 100 < 20 + (looted * 80) / startmoney) { - /*Nur Moral -1, turns is not changed, so the first time nothing happens if the morale is good*/ - region_set_morale(r, m - 1, -1); + for (i = 0; i != norders && startmoney > looted + TAXFRACTION * 2; i++) { + change_money(g_requests[i].unit, TAXFRACTION); + g_requests[i].unit->n += TAXFRACTION; + /*Looting destroys double the money*/ + looted += TAXFRACTION * 2; } - } + rsetmoney(r, startmoney - looted); + free(g_requests); - for (u = r->units; u; u = u->next) { - if (u->n >= 0) { - add_income(u, IC_LOOT, u->wants, u->n); - fset(u, UFL_LONGACTION | UFL_NOTMOVING); + /* Lowering morale by 1 depending on the looted money (+20%) */ + m = region_get_morale(r); + if (m && startmoney > 0) { + if (rng_int() % 100 < 20 + (looted * 80) / startmoney) { + /*Nur Moral -1, turns is not changed, so the first time nothing happens if the morale is good*/ + region_set_morale(r, m - 1, -1); + } + } + + for (u = r->units; u; u = u->next) { + if (u->n >= 0) { + add_income(u, IC_LOOT, u->wants, u->n); + fset(u, UFL_LONGACTION | UFL_NOTMOVING); + } } } } @@ -2529,23 +2536,23 @@ static void expandloot(region * r, econ_request * lootorders) void expandtax(region * r, econ_request * taxorders) { unit *u; - unsigned int i; + unsigned int norders; - expandorders(r, taxorders); - if (!norders) - return; + norders = expandorders(r, taxorders); + if (norders > 0) { + unsigned int i; + for (i = 0; i != norders && rmoney(r) > TAXFRACTION; i++) { + change_money(g_requests[i].unit, TAXFRACTION); + g_requests[i].unit->n += TAXFRACTION; + rsetmoney(r, rmoney(r) - TAXFRACTION); + } + free(g_requests); - for (i = 0; i != norders && rmoney(r) > TAXFRACTION; i++) { - change_money(g_requests[i].unit, TAXFRACTION); - g_requests[i].unit->n += TAXFRACTION; - rsetmoney(r, rmoney(r) - TAXFRACTION); - } - free(g_requests); - - for (u = r->units; u; u = u->next) { - if (u->n >= 0) { - add_income(u, IC_TAX, u->wants, u->n); - fset(u, UFL_LONGACTION | UFL_NOTMOVING); + for (u = r->units; u; u = u->next) { + if (u->n >= 0) { + add_income(u, IC_TAX, u->wants, u->n); + fset(u, UFL_LONGACTION | UFL_NOTMOVING); + } } } } diff --git a/src/economy.test.c b/src/economy.test.c index 19425ba6f..bd5858c7f 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -1,4 +1,6 @@ +#ifdef _MSC_VER #include +#endif #include #include "economy.h" @@ -19,6 +21,7 @@ #include #include +#include #include #include diff --git a/src/give.c b/src/give.c index 5f7945887..5d5673bd2 100644 --- a/src/give.c +++ b/src/give.c @@ -10,7 +10,9 @@ without prior permission by the authors of Eressea. */ +#ifdef _MSC_VER #include +#endif #include #include "give.h" @@ -43,6 +45,7 @@ #include #include #include +#include #include /* libc includes */ @@ -176,6 +179,7 @@ static void give_horses(unit * s, const item_type * itype, int n) { region *r = s->region; + UNUSED_ARG(itype); if (r->land) { rsethorses(r, rhorses(r) + n); } @@ -185,6 +189,7 @@ static void give_money(unit * s, const item_type * itype, int n) { region *r = s->region; + UNUSED_ARG(itype); if (r->land) { rsetmoney(r, rmoney(r) + n); } @@ -192,14 +197,14 @@ give_money(unit * s, const item_type * itype, int n) int give_item(int want, const item_type * itype, unit * src, unit * dest, -struct order *ord) + struct order *ord) { short error = 0; int n, delta; assert(itype != NULL); n = get_pooled(src, item2resource(itype), GET_SLACK | GET_POOLED_SLACK, want); - n = MIN(want, n); + if (n > want) n = want; delta = n; if (dest && src->faction != dest->faction && src->faction->age < GiveRestriction()) { @@ -271,6 +276,7 @@ static bool unit_has_cursed_item(const unit * u) } static bool can_give_men(const unit *u, const unit *dst, order *ord, message **msg) { + UNUSED_ARG(dst); if (unit_has_cursed_item(u)) { if (msg) *msg = msg_error(u, ord, 78); } @@ -435,9 +441,8 @@ message * give_men(int n, unit * u, unit * u2, struct order *ord) return msg_error(u, ord, error); } else if (u2->faction != u->faction) { - message *msg = msg_message("give_person", "unit target amount", u, u2, n); - add_message(&u2->faction->msgs, msg); - return msg; + return add_message(&u2->faction->msgs, + msg_message("give_person", "unit target amount", u, u2, n)); } return NULL; } @@ -615,6 +620,79 @@ bool can_give_to(unit *u, unit *u2) { return true; } +static void give_all_items(unit *u, unit *u2, order *ord) { + char token[128]; + const char *s; + + if (!can_give(u, u2, NULL, GIVE_ALLITEMS)) { + feedback_give_not_allowed(u, ord); + return; + } + s = gettoken(token, sizeof(token)); + if (!s || *s == 0) { /* GIVE ALL items that you have */ + + /* do these checks once, not for each item we have: */ + if (u2 && !(u_race(u2)->ec_flags & ECF_GETITEM)) { + ADDMSG(&u->faction->msgs, + msg_feedback(u, ord, "race_notake", "race", u_race(u2))); + return; + } + + /* für alle items einmal prüfen, ob wir mehr als von diesem Typ + * reserviert ist besitzen und diesen Teil dann übergeben */ + if (u->items) { + item **itmp = &u->items; + while (*itmp) { + item *itm = *itmp; + const item_type *itype = itm->type; + if (itm->number > 0 + && itm->number - get_reservation(u, itype) > 0) { + int n = itm->number - get_reservation(u, itype); + if (give_item(n, itype, u, u2, ord) == 0) { + if (*itmp != itm) + continue; + } + } + itmp = &itm->next; + } + } + } + else { + if (isparam(s, u->faction->locale, P_PERSON)) { + if (!(u_race(u)->ec_flags & ECF_GIVEPERSON)) { + ADDMSG(&u->faction->msgs, + msg_feedback(u, ord, "race_noregroup", "race", u_race(u))); + } + else { + message * msg; + msg = u2 ? give_men(u->number, u, u2, ord) : disband_men(u->number, u, ord); + if (msg) { + ADDMSG(&u->faction->msgs, msg); + } + } + } + else if (u2 && !(u_race(u2)->ec_flags & ECF_GETITEM)) { + ADDMSG(&u->faction->msgs, + msg_feedback(u, ord, "race_notake", "race", u_race(u2))); + } + else { + const item_type *itype = finditemtype(s, u->faction->locale); + if (itype != NULL) { + item *i = *i_find(&u->items, itype); + if (i != NULL) { + if (can_give(u, u2, itype, 0)) { + int n = i->number - get_reservation(u, itype); + give_item(n, itype, u, u2, ord); + } + else { + feedback_give_not_allowed(u, ord); + } + } + } + } + } +} + void give_cmd(unit * u, order * ord) { char token[128]; @@ -689,8 +767,7 @@ void give_cmd(unit * u, order * ord) item **itmp = &u->items; while (*itmp) { item *itm = *itmp; - const item_type *itype = itm->type; - if (fval(itype, ITF_HERB) && itm->number > 0) { + if (fval(itm->type, ITF_HERB) && itm->number > 0) { /* give_item ändert im fall,das man alles übergibt, die * item-liste der unit, darum continue vor pointerumsetzten */ if (give_item(itm->number, itm->type, u, u2, ord) == 0) { @@ -724,75 +801,7 @@ void give_cmd(unit * u, order * ord) } else if (p == P_ANY) { - const char *s; - - if (!can_give(u, u2, NULL, GIVE_ALLITEMS)) { - feedback_give_not_allowed(u, ord); - return; - } - s = gettoken(token, sizeof(token)); - if (!s || *s == 0) { /* GIVE ALL items that you have */ - - /* do these checks once, not for each item we have: */ - if (u2 && !(u_race(u2)->ec_flags & ECF_GETITEM)) { - ADDMSG(&u->faction->msgs, - msg_feedback(u, ord, "race_notake", "race", u_race(u2))); - return; - } - - /* für alle items einmal prüfen, ob wir mehr als von diesem Typ - * reserviert ist besitzen und diesen Teil dann übergeben */ - if (u->items) { - item **itmp = &u->items; - while (*itmp) { - item *itm = *itmp; - const item_type *itype = itm->type; - if (itm->number > 0 - && itm->number - get_reservation(u, itype) > 0) { - n = itm->number - get_reservation(u, itype); - if (give_item(n, itype, u, u2, ord) == 0) { - if (*itmp != itm) - continue; - } - } - itmp = &itm->next; - } - } - } - else { - if (isparam(s, u->faction->locale, P_PERSON)) { - if (!(u_race(u)->ec_flags & ECF_GIVEPERSON)) { - ADDMSG(&u->faction->msgs, - msg_feedback(u, ord, "race_noregroup", "race", u_race(u))); - } - else { - message * msg; - msg = u2 ? give_men(u->number, u, u2, ord) : disband_men(u->number, u, ord); - if (msg) { - ADDMSG(&u->faction->msgs, msg); - } - } - } - else if (u2 && !(u_race(u2)->ec_flags & ECF_GETITEM)) { - ADDMSG(&u->faction->msgs, - msg_feedback(u, ord, "race_notake", "race", u_race(u2))); - } - else { - itype = finditemtype(s, u->faction->locale); - if (itype != NULL) { - item *i = *i_find(&u->items, itype); - if (i != NULL) { - if (can_give(u, u2, itype, 0)) { - n = i->number - get_reservation(u, itype); - give_item(n, itype, u, u2, ord); - } - else { - feedback_give_not_allowed(u, ord); - } - } - } - } - } + give_all_items(u, u2, ord); return; } else if (p == P_EACH) { @@ -813,13 +822,12 @@ void give_cmd(unit * u, order * ord) } if (isparam(s, u->faction->locale, P_PERSON)) { - message * msg; if (!(u_race(u)->ec_flags & ECF_GIVEPERSON)) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_noregroup", "race", u_race(u))); return; } - n = MIN(u->number, n); + if (n > u->number) n = u->number; msg = u2 ? give_men(n, u, u2, ord) : disband_men(n, u, ord); if (msg) { ADDMSG(&u->faction->msgs, msg); diff --git a/src/give.test.c b/src/give.test.c index 48be9cbc5..5afdc3842 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -210,6 +210,21 @@ static void test_give_men_too_many(CuTest * tc) { test_teardown(); } +static void test_give_cmd_limit(CuTest * tc) { + struct give env = { 0 }; + unit *u; + test_setup_ex(tc); + env.f2 = env.f1 = test_create_faction(0); + setup_give(&env); + u = env.src; + scale_number(u, 2); + u->thisorder = create_order(K_GIVE, u->faction->locale, "%s 1 PERSON", itoa36(env.dst->no)); + give_cmd(u, u->thisorder); + CuAssertIntEquals(tc, 2, env.dst->number); + CuAssertIntEquals(tc, 1, env.src->number); + test_teardown(); +} + static void test_give_men_none(CuTest * tc) { struct give env = { 0 }; message * msg; @@ -436,6 +451,7 @@ CuSuite *get_give_suite(void) CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_give); SUITE_ADD_TEST(suite, test_give_cmd); + SUITE_ADD_TEST(suite, test_give_cmd_limit); SUITE_ADD_TEST(suite, test_give_men); SUITE_ADD_TEST(suite, test_give_men_magicians); SUITE_ADD_TEST(suite, test_give_men_limit); diff --git a/src/gmtool.c b/src/gmtool.c index bfe7cbe25..ad723ddc7 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -8,7 +8,10 @@ * */ +#ifdef _MSC_VER #include +#endif + #include #include @@ -45,11 +48,12 @@ #include #include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include #include #include diff --git a/src/gmtool.h b/src/gmtool.h index 04f062f4b..5a2449c9a 100644 --- a/src/gmtool.h +++ b/src/gmtool.h @@ -11,6 +11,9 @@ #ifndef H_GMTOOL #define H_GMTOOL +#include +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/helpers.c b/src/helpers.c index 983750173..5015fe401 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -10,6 +10,10 @@ This program may not be used, modified or distributed without prior permission by the authors of Eressea. */ +#ifdef _MSC_VER +#include +#endif + #include "helpers.h" #include "vortex.h" #include "alchemy.h" diff --git a/src/items.c b/src/items.c index fe59ffa15..a51c83326 100644 --- a/src/items.c +++ b/src/items.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include diff --git a/src/items/speedsail.c b/src/items/speedsail.c index cb40e9a8c..b224d6d6d 100644 --- a/src/items/speedsail.c +++ b/src/items/speedsail.c @@ -33,6 +33,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* util includes */ #include #include +#include /* libc includes */ #include diff --git a/src/kernel/config.c b/src/kernel/config.c index 3a1aab3a5..bb682b63b 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -16,8 +16,11 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ +#ifdef _MSC_VER #include -#include +#endif + +#include "config.h" /* kernel includes */ #include "alliance.h" @@ -48,10 +51,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "types.h" #include "unit.h" - -#include -#include - /* util includes */ #include #include @@ -62,6 +61,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include #include @@ -90,8 +90,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include +#ifdef WIN32 +#include +#else +#include +#endif struct settings global; int turn = 0; @@ -576,14 +580,23 @@ void set_reportpath(const char *path) g_reportdir = path; } +static int sys_mkdir(const char *path, int mode) { +#ifdef WIN32 + UNUSED_ARG(mode); + return _mkdir(path); +#else + return mkdir(path, mode); +#endif +} + int create_directories(void) { int err; - err = mkdir(datapath(), 0777); + err = sys_mkdir(datapath(), 0777); if (err) { if (errno == EEXIST) errno = 0; else return err; } - err = mkdir(reportpath(), 0777); + err = sys_mkdir(reportpath(), 0777); if (err && errno == EEXIST) { errno = 0; } diff --git a/src/kernel/connection.c b/src/kernel/connection.c index 2cae4ec8f..9bcd6095a 100644 --- a/src/kernel/connection.c +++ b/src/kernel/connection.c @@ -29,6 +29,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include diff --git a/src/kernel/curse.c b/src/kernel/curse.c index 499db9e93..e83323ab5 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -38,6 +38,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include #include diff --git a/src/kernel/item.c b/src/kernel/item.c index 2b3ba1e2e..2eabd4aa5 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -41,6 +41,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include #include diff --git a/src/kernel/messages.c b/src/kernel/messages.c index ebcce80f2..0aa19a79c 100644 --- a/src/kernel/messages.c +++ b/src/kernel/messages.c @@ -32,6 +32,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include #include diff --git a/src/kernel/messages.h b/src/kernel/messages.h index 58558072d..59bac9af2 100644 --- a/src/kernel/messages.h +++ b/src/kernel/messages.h @@ -54,8 +54,8 @@ extern "C" { void addmessage(struct region *r, struct faction *f, const char *s, msg_t mtype, int level); - struct mlist ** merge_messages(message_list *mlist, message_list *append); - void split_messages(message_list *mlist, struct mlist **split); + struct mlist ** merge_messages(message_list *ml, message_list *append); + void split_messages(message_list *ml, struct mlist **split); #define ADDMSG(msgs, mcreate) { message * mx = mcreate; if (mx) { assert(mx->refcount>=1); add_message(msgs, mx); msg_release(mx); } } diff --git a/src/kernel/render.h b/src/kernel/render.h index 688c07f2b..f12d55b9b 100644 --- a/src/kernel/render.h +++ b/src/kernel/render.h @@ -24,5 +24,5 @@ struct message; /* TODO: this could be nicer and faster * call with MSG(("msg_name", "param", p), buf, faction). */ -#define MSG(makemsg, buf, size, loc, ud) { struct message * m = msg_message makemsg; nr_render(m, loc, buf, size, ud); msg_release(m); } -#define RENDER(f, buf, size, mcreate) { struct message * m = msg_message mcreate; nr_render(m, f->locale, buf, size, f); msg_release(m); } +#define MSG(makemsg, buf, size, loc, ud) { struct message * mm = msg_message makemsg; nr_render(mm, loc, buf, size, ud); msg_release(mm); } +#define RENDER(f, buf, size, mcreate) { struct message * mr = msg_message mcreate; nr_render(mr, f->locale, buf, size, f); msg_release(mr); } diff --git a/src/kernel/resources.c b/src/kernel/resources.c index 2f99315e3..bcf26efb3 100644 --- a/src/kernel/resources.c +++ b/src/kernel/resources.c @@ -21,6 +21,7 @@ #include "region.h" #include "terrain.h" +#include #include #include diff --git a/src/kernel/ship.h b/src/kernel/ship.h index 4b46f02b4..2ee1a6d3b 100644 --- a/src/kernel/ship.h +++ b/src/kernel/ship.h @@ -126,12 +126,12 @@ extern "C" { extern void free_ship(struct ship *s); extern void free_ships(void); - const char *ship_getname(const struct ship *self); + const char *ship_getname(const struct ship *sh); void ship_setname(struct ship *self, const char *name); int shipspeed(const struct ship *sh, const struct unit *u); int crew_skill(const struct ship *sh); - int ship_damage_percent(const struct ship *ship); + int ship_damage_percent(const struct ship *sh); #ifdef __cplusplus } #endif diff --git a/src/kernel/spell.c b/src/kernel/spell.c index ccdf4e29b..ca97bf1f0 100644 --- a/src/kernel/spell.c +++ b/src/kernel/spell.c @@ -16,8 +16,9 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ +#ifdef _MSC_VER #include -#include +#endif #include "spell.h" /* util includes */ diff --git a/src/kernel/spell.test.c b/src/kernel/spell.test.c index 18300b48b..7307e22a1 100644 --- a/src/kernel/spell.test.c +++ b/src/kernel/spell.test.c @@ -5,6 +5,7 @@ #include #include +#include #include #include diff --git a/src/kernel/spellbook.c b/src/kernel/spellbook.c index 037bb0bed..ae5387f11 100644 --- a/src/kernel/spellbook.c +++ b/src/kernel/spellbook.c @@ -1,4 +1,6 @@ -#include +#ifdef _MSC_VER +#include +#endif #include #include diff --git a/src/kernel/unit.c b/src/kernel/unit.c index fd9a15515..28f227ff5 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -57,6 +57,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include #include diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index fc3cdda3d..5694fb79d 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -12,8 +12,9 @@ #include #include #include -#include +#include #include +#include #include #include #include diff --git a/src/kernel/version.c b/src/kernel/version.c index c0dc8d2bc..7c5c2435f 100644 --- a/src/kernel/version.c +++ b/src/kernel/version.c @@ -1,4 +1,6 @@ +#ifdef _MSC_VER #include +#endif #include "version.h" #include diff --git a/src/laws.c b/src/laws.c index ede465f7e..587f3002b 100644 --- a/src/laws.c +++ b/src/laws.c @@ -85,6 +85,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include #include @@ -1586,17 +1587,17 @@ int display_cmd(unit * u, struct order *ord) free(*s); if (s2) { - char * str = str_strdup(s2); - if (unicode_utf8_trim(str) != 0) { + char * sdup = str_strdup(s2); + if (unicode_utf8_trim(sdup) != 0) { log_info("trimming info: %s", s2); } - if (strlen(str) >= DISPLAYSIZE) { - str[DISPLAYSIZE-1] = 0; + if (strlen(sdup) >= DISPLAYSIZE) { + sdup[DISPLAYSIZE-1] = 0; } - *s = str; + *s = sdup; } else { - *s = 0; + *s = NULL; } } diff --git a/src/listbox.c b/src/listbox.c index 6a8556b6c..afc04b232 100644 --- a/src/listbox.c +++ b/src/listbox.c @@ -8,8 +8,10 @@ * */ -/* wenn platform.h nicht vor curses included wird, kompiliert es unter windows nicht */ +#ifdef _MSC_VER #include +#endif + #include #include diff --git a/src/magic.c b/src/magic.c index 3b4a8d331..6855c307f 100644 --- a/src/magic.c +++ b/src/magic.c @@ -17,7 +17,9 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ -#include +#ifdef _MSC_VER +#include +#endif #include "magic.h" #include "skill.h" @@ -40,6 +42,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include #include diff --git a/src/main.c b/src/main.c index 9d76967b2..ca2950746 100644 --- a/src/main.c +++ b/src/main.c @@ -16,7 +16,10 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ +#ifdef _MSC_VER #include +#endif + #include #include diff --git a/src/modules/museum.c b/src/modules/museum.c index 572a8c41a..4420603ad 100644 --- a/src/modules/museum.c +++ b/src/modules/museum.c @@ -44,6 +44,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include diff --git a/src/monsters.c b/src/monsters.c index ade13af48..0b1bb7902 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -786,7 +786,7 @@ void plan_monsters(faction * f) /* Einheiten mit Bewegungsplan kriegen ein NACH: */ if (long_order == NULL) { - attrib *ta = a_find(u->attribs, &at_targetregion); + ta = a_find(u->attribs, &at_targetregion); if (ta) { if (u->region == (region *)ta->data.v) { a_remove(&u->attribs, ta); diff --git a/src/move.c b/src/move.c index 8791b7f3c..0932c7d4f 100644 --- a/src/move.c +++ b/src/move.c @@ -17,7 +17,9 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ +#ifdef _MSC_VER #include +#endif #include #include "move.h" #include "guard.h" @@ -75,6 +77,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include #include @@ -262,6 +265,7 @@ static int ridingcapacity(const unit * u) { int vehicles = 0, vcap = 0; int animals = 0, acap = 0; + int horses; get_transporters(u->items, &animals, &acap, &vehicles, &vcap); @@ -269,19 +273,22 @@ static int ridingcapacity(const unit * u) ** tragen nichts (siehe walkingcapacity). Ein Wagen zählt nur, wenn er ** von zwei Pferden gezogen wird */ - animals = MIN(animals, effskill(u, SK_RIDING, 0) * u->number * 2); + horses = effskill(u, SK_RIDING, 0) * u->number * 2; + if (animals > horses) animals = horses; + if (fval(u_race(u), RCF_HORSE)) animals += u->number; /* maximal diese Pferde können zum Ziehen benutzt werden */ - vehicles = MIN(animals / HORSESNEEDED, vehicles); + horses = animals / HORSES_PER_CART; + if (horses < vehicles) vehicles = horses; return vehicles * vcap + animals * acap; } int walkingcapacity(const struct unit *u) { - int n, people, pferde_fuer_wagen; + int n, people, pferde_fuer_wagen, horses; int wagen_ohne_pferde, wagen_mit_pferden, wagen_mit_trollen; int vehicles = 0, vcap = 0; int animals = 0, acap = 0; @@ -293,7 +300,8 @@ int walkingcapacity(const struct unit *u) /* Das Gewicht, welches die Pferde tragen, plus das Gewicht, welches * die Leute tragen */ - pferde_fuer_wagen = MIN(animals, effskill(u, SK_RIDING, 0) * u->number * 4); + horses = effskill(u, SK_RIDING, 0) * u->number * 4; + pferde_fuer_wagen = (animals < horses) ? animals : horses; if (fval(u_race(u), RCF_HORSE)) { animals += u->number; people = 0; @@ -303,7 +311,8 @@ int walkingcapacity(const struct unit *u) } /* maximal diese Pferde können zum Ziehen benutzt werden */ - wagen_mit_pferden = MIN(vehicles, pferde_fuer_wagen / HORSESNEEDED); + horses = pferde_fuer_wagen / HORSES_PER_CART; + wagen_mit_pferden = (vehicles < horses) ? vehicles : horses; n = wagen_mit_pferden * vcap; @@ -313,7 +322,8 @@ int walkingcapacity(const struct unit *u) wagen_ohne_pferde = vehicles - wagen_mit_pferden; /* Genug Trolle, um die Restwagen zu ziehen? */ - wagen_mit_trollen = MIN(u->number / 4, wagen_ohne_pferde); + wagen_mit_trollen = u->number / 4; + if (wagen_mit_trollen > wagen_ohne_pferde) wagen_mit_trollen = wagen_ohne_pferde; /* Wagenkapazität hinzuzählen */ n += wagen_mit_trollen * vcap; @@ -337,7 +347,8 @@ int walkingcapacity(const struct unit *u) int belts = i_get(u->items, rbelt->itype); if (belts) { int multi = config_get_int("rules.trollbelt.multiplier", STRENGTHMULTIPLIER); - n += MIN(people, belts) * (multi - 1) * u_race(u)->capacity; + if (belts > people) belts = people; + n += belts * (multi - 1) * u_race(u)->capacity; } } @@ -368,7 +379,8 @@ static int canwalk(unit * u) effsk = effskill(u, SK_RIDING, 0); maxwagen = effsk * u->number * 2; if (u_race(u) == get_race(RC_TROLL)) { - maxwagen = MAX(maxwagen, u->number / 4); + int trolls = u->number / 4; + if (maxwagen > trolls) maxwagen = trolls; } maxpferde = effsk * u->number * 4 + u->number; @@ -510,8 +522,9 @@ static double overload(const region * r, ship * sh) getshipweight(sh, &n, &p); ovl = n / (double)sh->type->cargo; - if (mcabins) - ovl = MAX(ovl, p / (double)mcabins); + if (mcabins) { + ovl = fmax(ovl, p / (double)mcabins); + } return ovl; } } @@ -752,7 +765,7 @@ double damage_overload(double overload) badness = overload - overload_worse(); if (badness >= 0) { assert(overload_worst() > overload_worse() || !"overload.worst must be > overload.worse"); - damage += MIN(badness, overload_worst() - overload_worse()) * + damage += fmin(badness, overload_worst() - overload_worse()) * (overload_max_damage() - damage) / (overload_worst() - overload_worse()); } @@ -952,7 +965,7 @@ static unit *bewegung_blockiert_von(unit * reisender, region * r) double prob_u = (sk - stealth) * skill_prob; guard_count += u->number; /* amulet counts at most once */ - prob_u += MIN(1, MIN(u->number, i_get(u->items, ramulet->itype))) * amulet_prob; + prob_u += fmin(1, fmin(u->number, i_get(u->items, ramulet->itype))) * amulet_prob; if (u->building && (u->building->type == castle_bt) && u == building_owner(u->building)) prob_u += castle_prob*buildingeffsize(u->building, 0); if (prob_u >= prob) { @@ -1967,8 +1980,8 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting) const luxury_type *ltype = resource2luxury(itm->type->rtype); if (ltype != NULL && itm->number > 0) { int st = itm->number * effskill(harbourmaster, SK_TRADE, 0) / 50; - st = MIN(itm->number, st); + if (st > itm->number) st = itm->number; if (st > 0) { i_change(&u2->items, itm->type, -st); i_change(&harbourmaster->items, itm->type, st); diff --git a/src/move.h b/src/move.h index 535c76bb2..84a4cdb4f 100644 --- a/src/move.h +++ b/src/move.h @@ -50,7 +50,7 @@ extern "C" { #define MV_SWIM (1<<8) /* kann schwimmen */ #define MV_WALK (1<<9) /* kann über Land gehen */ -#define HORSESNEEDED 2 +#define HORSES_PER_CART 2 /* number of horses for a cart */ #define STRENGTHMULTIPLIER 50 /* multiplier for trollbelt */ /* ein mensch wiegt 10, traegt also 5, ein pferd wiegt 50, traegt also 20. ein diff --git a/src/names.c b/src/names.c index d67f441a1..e58feceec 100644 --- a/src/names.c +++ b/src/names.c @@ -32,8 +32,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* util includes */ #include #include -#include #include +#include +#include #include #include diff --git a/src/piracy.c b/src/piracy.c index 389e92021..888a7e53a 100644 --- a/src/piracy.c +++ b/src/piracy.c @@ -1,3 +1,4 @@ +#include #include "piracy.h" #include "direction.h" diff --git a/src/platform.h b/src/platform.h index d892df8c3..1dcf224a9 100644 --- a/src/platform.h +++ b/src/platform.h @@ -5,16 +5,13 @@ #endif #ifdef _MSC_VER -#ifndef __STDC__ -#define __STDC__ 1 // equivalent to /Za -#endif -#define NO_MKDIR #if _MSC_VER >= 1900 -#pragma warning(disable: 4710 4820) +#pragma warning(disable: 4710 4820 4001) #pragma warning(disable: 4100) // unreferenced formal parameter #pragma warning(disable: 4456) // declaration hides previous #pragma warning(disable: 4457) // declaration hides function parameter #pragma warning(disable: 4459) // declaration hides global +#pragma warning(disable: 4224) // formal parameter was previously defined as a type #endif #else /* assume gcc */ #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L @@ -29,18 +26,7 @@ # define MAX_PATH 4096 #endif -#define UNUSED_ARG(a) (void)(a) - #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MAX(a, b) (((a) > (b)) ? (a) : (b)) #define TOLUA_CAST (char*) - -#ifdef NO_MKDIR -int mkdir(const char *pathname, int mode); -#endif - -/* do not use M_PI, use one of these instead: */ -#define PI_F 3.1415926535897932384626433832795F -#define PI_D 3.1415926535897932384626433832795 -#define PI_L 3.1415926535897932384626433832795L diff --git a/src/prefix.test.c b/src/prefix.test.c index e3f1e7dfb..f131813d7 100644 --- a/src/prefix.test.c +++ b/src/prefix.test.c @@ -1,3 +1,7 @@ +#ifdef _MSC_VER +#include +#endif + #include "prefix.h" #include diff --git a/src/randenc.c b/src/randenc.c index 3e1ac3554..499591294 100644 --- a/src/randenc.c +++ b/src/randenc.c @@ -675,10 +675,11 @@ static void godcurse(void) double dmg = config_get_flt("rules.ship.damage.godcurse", 0.1); damage_ship(sh, dmg); if (sh->damage >= sh->size * DAMAGE_SCALE) { - unit *u = ship_owner(sh); - if (u) - ADDMSG(&u->faction->msgs, - msg_message("godcurse_destroy_ship", "ship", sh)); + unit *uo = ship_owner(sh); + if (uo) { + ADDMSG(&uo->faction->msgs, + msg_message("godcurse_destroy_ship", "ship", sh)); + } remove_ship(&sh->region->ships, sh); } sh = shn; diff --git a/src/report.c b/src/report.c index dc7b8a1e2..12506f2be 100644 --- a/src/report.c +++ b/src/report.c @@ -16,9 +16,9 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ -#define ECHECK_VERSION "4.01" - +#ifdef _MSC_VER #include +#endif #include #include "report.h" @@ -104,9 +104,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#if defined(_MSC_VER) && _MSC_VER >= 1900 -# pragma warning(disable: 4774) /* TODO: remove this */ -#endif +#define ECHECK_VERSION "4.01" extern int *storms; extern int weeks_per_month; @@ -922,7 +920,7 @@ void report_region(struct stream *out, const region * r, faction * f) if (!r2) continue; for (b = get_borders(r, r2); b;) { - struct edge *e = edges; + struct edge *edg = edges; bool transparent = b->type->transparent(b, f); const char *name = border_name(b, r, f, GF_DETAILED | GF_ARTICLE); @@ -933,18 +931,18 @@ void report_region(struct stream *out, const region * r, faction * f) b = b->next; continue; } - while (e && (e->transparent != transparent || strcmp(name, e->name)!=0)) { - e = e->next; + while (edg && (edg->transparent != transparent || strcmp(name, edg->name)!=0)) { + edg = edg->next; } - if (!e) { - e = calloc(sizeof(struct edge), 1); - e->name = str_strdup(name); - e->transparent = transparent; - e->next = edges; - edges = e; + if (!edg) { + edg = calloc(sizeof(struct edge), 1); + edg->name = str_strdup(name); + edg->transparent = transparent; + edg->next = edges; + edges = edg; } - e->lastd = d; - e->exist[d] = true; + edg->lastd = d; + edg->exist[d] = true; b = b->next; } } @@ -1009,7 +1007,7 @@ void report_region(struct stream *out, const region * r, faction * f) /* iron & stone */ if (r->seen.mode >= seen_unit) { resource_report result[MAX_RAWMATERIALS]; - int n, numresults = report_resources(r, result, MAX_RAWMATERIALS, f, true); + int numresults = report_resources(r, result, MAX_RAWMATERIALS, f, true); for (n = 0; n < numresults; ++n) { if (result[n].number >= 0 && result[n].level >= 0) { @@ -1024,8 +1022,8 @@ void report_region(struct stream *out, const region * r, faction * f) /* peasants & silver */ if (rpeasants(r)) { - int n = rpeasants(r); - bytes = snprintf(bufp, size, ", %d", n); + int p = rpeasants(r); + bytes = snprintf(bufp, size, ", %d", p); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -1040,7 +1038,7 @@ void report_region(struct stream *out, const region * r, faction * f) if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); bytes = - (int)strlcpy(bufp, LOC(f->locale, n == 1 ? "peasant" : "peasant_p"), + (int)strlcpy(bufp, LOC(f->locale, p == 1 ? "peasant" : "peasant_p"), size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -1172,17 +1170,17 @@ void report_region(struct stream *out, const region * r, faction * f) /* Spezielle Richtungen */ for (a = a_find(r->attribs, &at_direction); a && a->type == &at_direction; a = a->next) { - spec_direction *d = (spec_direction *)(a->data.v); + spec_direction *spd = (spec_direction *)(a->data.v); bytes = (int)strlcpy(bufp, " ", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - bytes = (int)strlcpy(bufp, LOC(f->locale, d->desc), size); + bytes = (int)strlcpy(bufp, LOC(f->locale, spd->desc), size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); bytes = (int)strlcpy(bufp, " (\"", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - bytes = (int)strlcpy(bufp, LOC(f->locale, d->keyword), size); + bytes = (int)strlcpy(bufp, LOC(f->locale, spd->keyword), size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); bytes = (int)strlcpy(bufp, "\")", size); @@ -2226,14 +2224,14 @@ report_plaintext(const char *filename, report_context * ctx, WARN_STATIC_BUFFER(); if (ptype->itype->construction) { - requirement *m = ptype->itype->construction->materials; - while (m->number) { + requirement *rm = ptype->itype->construction->materials; + while (rm->number) { bytes = - (int)strlcpy(bufp, LOC(f->locale, resourcename(m->rtype, 0)), size); + (int)strlcpy(bufp, LOC(f->locale, resourcename(rm->rtype, 0)), size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); ++m; - if (m->number) + if (rm->number) bytes = (int)strlcpy(bufp, ", ", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -2275,7 +2273,8 @@ report_plaintext(const char *filename, report_context * ctx, if (markets_module() && r->land) { const item_type *lux = r_luxury(r); const item_type *herb = r->land->herbtype; - message *m = 0; + + m = NULL; if (herb && lux) { m = msg_message("nr_market_info_p", "p1 p2", lux->rtype, herb->rtype); @@ -2288,7 +2287,6 @@ report_plaintext(const char *filename, report_context * ctx, newline(out); nr_paragraph(out, m, f); } - /* */ } else { if (!fval(r->terrain, SEA_REGION) && rpeasants(r) / TRADE_FRACTION > 0) { diff --git a/src/reports.c b/src/reports.c index c822afe25..03eb24e47 100644 --- a/src/reports.c +++ b/src/reports.c @@ -67,6 +67,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include #include @@ -537,10 +538,9 @@ bufunit(const faction * f, const unit * u, unsigned int indent, seen_mode mode, if (u->attribs && alliedunit(u, f, HELP_FSTEALTH)) { faction *otherf = get_otherfaction(u); if (otherf) { - int result = - snprintf(bufp, size, ", %s (%s)", factionname(otherf), - factionname(u->faction)); - if (wrptr(&bufp, &size, result) != 0) + int n = snprintf(bufp, size, ", %s (%s)", + factionname(otherf), factionname(u->faction)); + if (wrptr(&bufp, &size, n) != 0) WARN_STATIC_BUFFER(); } else { @@ -675,23 +675,22 @@ bufunit(const faction * f, const unit * u, unsigned int indent, seen_mode mode, if (book) { selist *ql = book->spells; int qi, header, maxlevel = effskill(u, SK_MAGIC, 0); - int result = snprintf(bufp, size, ". Aura %d/%d", get_spellpoints(u), max_spellpoints(u->region, u)); - if (wrptr(&bufp, &size, result) != 0) { + int n = snprintf(bufp, size, ". Aura %d/%d", get_spellpoints(u), max_spellpoints(u->region, u)); + if (wrptr(&bufp, &size, n) != 0) { WARN_STATIC_BUFFER(); } for (header = 0, qi = 0; ql; selist_advance(&ql, &qi, 1)) { spellbook_entry * sbe = (spellbook_entry *)selist_get(ql, qi); if (sbe->level <= maxlevel) { - int result = 0; if (!header) { - result = snprintf(bufp, size, ", %s: ", LOC(lang, "nr_spells")); + n = snprintf(bufp, size, ", %s: ", LOC(lang, "nr_spells")); header = 1; } else { - result = (int)strlcpy(bufp, ", ", size); + n = (int)strlcpy(bufp, ", ", size); } - if (wrptr(&bufp, &size, result) != 0) { + if (wrptr(&bufp, &size, n) != 0) { WARN_STATIC_BUFFER(); } /* TODO: no need to deref the spellref here (spref->name is good) */ @@ -704,9 +703,8 @@ bufunit(const faction * f, const unit * u, unsigned int indent, seen_mode mode, break; } if (i != MAXCOMBATSPELLS) { - int result = - snprintf(bufp, size, ", %s: ", LOC(lang, "nr_combatspells")); - if (wrptr(&bufp, &size, result) != 0) + n = snprintf(bufp, size, ", %s: ", LOC(lang, "nr_combatspells")); + if (wrptr(&bufp, &size, n) != 0) WARN_STATIC_BUFFER(); dh = 0; @@ -723,8 +721,8 @@ bufunit(const faction * f, const unit * u, unsigned int indent, seen_mode mode, int sl = get_combatspelllevel(u, i); bufp = STRLCPY(bufp, spell_name(sp, lang), size); if (sl > 0) { - result = snprintf(bufp, size, " (%d)", sl); - if (wrptr(&bufp, &size, result) != 0) + n = snprintf(bufp, size, " (%d)", sl); + if (wrptr(&bufp, &size, n) != 0) WARN_STATIC_BUFFER(); } } @@ -741,8 +739,8 @@ bufunit(const faction * f, const unit * u, unsigned int indent, seen_mode mode, keyword_t kwd = getkeyword(ord); if (is_repeated(kwd)) { if (printed < ORDERS_IN_NR) { - int result = (int)buforder(bufp, size, ord, u->faction->locale, printed++); - if (wrptr(&bufp, &size, result) != 0) + int n = (int)buforder(bufp, size, ord, u->faction->locale, printed++); + if (wrptr(&bufp, &size, n) != 0) WARN_STATIC_BUFFER(); } else @@ -754,12 +752,13 @@ bufunit(const faction * f, const unit * u, unsigned int indent, seen_mode mode, keyword_t kwd = getkeyword(ord); if (is_repeated(kwd)) { if (printed < ORDERS_IN_NR) { - int result = (int)buforder(bufp, size, ord, lang, printed++); - if (wrptr(&bufp, &size, result) != 0) + int n = (int)buforder(bufp, size, ord, lang, printed++); + if (wrptr(&bufp, &size, n) != 0) WARN_STATIC_BUFFER(); } - else + else { break; + } } } } @@ -1339,8 +1338,8 @@ void reorder_units(region * r) while (*unext && sh) { unit **ufirst = unext; /* where the first unit in the building should go */ - unit **umove = unext; /* a unit we consider moving */ unit *owner = ship_owner(sh); + umove = unext; while (owner && *umove) { unit *u = *umove; if (u->number && u->ship == sh) { @@ -1478,8 +1477,8 @@ void prepare_report(report_context *ctx, faction *f) for (b = rbuildings(r); b; b = b->next) { if (b && b->type == bt_lighthouse) { /* region owners get maximm range */ - int br = lighthouse_range(b, NULL, NULL); - if (br > range) range = br; + int lhr = lighthouse_range(b, NULL, NULL); + if (lhr > range) range = lhr; } } } diff --git a/src/spells.c b/src/spells.c index a9fa12127..68553efaf 100644 --- a/src/spells.c +++ b/src/spells.c @@ -11,7 +11,6 @@ * This program may not be used, modified or distributed without * prior permission by the authors of Eressea. */ - #include #include @@ -64,6 +63,7 @@ #include #include #include +#include #include #include #include diff --git a/src/spells/borders.c b/src/spells/borders.c index d19470230..9ded973c8 100644 --- a/src/spells/borders.c +++ b/src/spells/borders.c @@ -1,5 +1,6 @@ +#ifdef _MSC_VER #include - +#endif #include "borders.h" #include "vortex.h" @@ -15,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -119,7 +121,7 @@ struct region *from, struct region *to, bool routing) wall_data *fd = (wall_data *)b->data.v; if (!routing && fd->active) { int hp = dice(3, fd->force) * u->number; - hp = MIN(u->hp, hp); + if (u->hp < hp) hp = u->hp; u->hp -= hp; if (u->hp) { ADDMSG(&u->faction->msgs, msg_message("firewall_damage", diff --git a/src/spells/buildingcurse.c b/src/spells/buildingcurse.c index 06c62e1c4..e1eff8988 100644 --- a/src/spells/buildingcurse.c +++ b/src/spells/buildingcurse.c @@ -26,6 +26,7 @@ #include #include #include +#include /* libc includes */ #include diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index 688a389cb..ce737f570 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include diff --git a/src/spells/regioncurse.c b/src/spells/regioncurse.c index 8ac3eea8c..7622b536f 100644 --- a/src/spells/regioncurse.c +++ b/src/spells/regioncurse.c @@ -25,6 +25,7 @@ /* util includes */ #include +#include #include #include #include diff --git a/src/spells/shipcurse.c b/src/spells/shipcurse.c index 180c84eea..4d62d1968 100644 --- a/src/spells/shipcurse.c +++ b/src/spells/shipcurse.c @@ -26,6 +26,7 @@ #include #include #include +#include #include diff --git a/src/spells/unitcurse.c b/src/spells/unitcurse.c index 4f8d69f64..6fc979e38 100644 --- a/src/spells/unitcurse.c +++ b/src/spells/unitcurse.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include diff --git a/src/spy.c b/src/spy.c index ff1f6da4e..de25f46e2 100644 --- a/src/spy.c +++ b/src/spy.c @@ -425,9 +425,8 @@ static void sink_ship(region * r, ship * sh, unit * saboteur) } } for (ui = &r->units; *ui;) { - unit *u = *ui; - /* inform this faction about the sinking ship: */ + u = *ui; if (!(u->faction->flags & FFL_SELECT)) { fset(u->faction, FFL_SELECT); if (sink_msg == NULL) { diff --git a/src/sqlite.c b/src/sqlite.c index ad74379d8..e25d105d2 100644 --- a/src/sqlite.c +++ b/src/sqlite.c @@ -1,4 +1,6 @@ +#ifdef _MSC_VER #include +#endif #include #include #include diff --git a/src/study.c b/src/study.c index 3e932df84..bcb83a723 100644 --- a/src/study.c +++ b/src/study.c @@ -768,7 +768,7 @@ int study_cmd(unit * u, order * ord) if (skill > maxalchemy) { for (ptype = potiontypes; ptype; ptype = ptype->next) { if (skill == ptype->level * 2) { - attrib *a = a_find(f->attribs, &at_showitem); + a = a_find(f->attribs, &at_showitem); while (a && a->type == &at_showitem && a->data.v != ptype) a = a->next; if (a == NULL || a->type != &at_showitem) { diff --git a/src/travelthru.test.c b/src/travelthru.test.c index 7dbd150be..1a8871a74 100644 --- a/src/travelthru.test.c +++ b/src/travelthru.test.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "travelthru.h" #include "reports.h" diff --git a/src/triggers/changefaction.c b/src/triggers/changefaction.c index 6a2700afa..f34cb98bd 100644 --- a/src/triggers/changefaction.c +++ b/src/triggers/changefaction.c @@ -25,11 +25,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* util includes */ #include +#include #include #include #include +#include #include -#include #include diff --git a/src/triggers/changerace.c b/src/triggers/changerace.c index 1a065fce2..5ab56b346 100644 --- a/src/triggers/changerace.c +++ b/src/triggers/changerace.c @@ -25,11 +25,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* util includes */ #include +#include #include #include #include +#include #include -#include #include diff --git a/src/triggers/clonedied.c b/src/triggers/clonedied.c index edcf756f9..62c4c3343 100644 --- a/src/triggers/clonedied.c +++ b/src/triggers/clonedied.c @@ -27,11 +27,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* util includes */ #include +#include #include #include #include +#include #include -#include #include diff --git a/src/triggers/createcurse.c b/src/triggers/createcurse.c index 2551f7fb5..bd7422587 100644 --- a/src/triggers/createcurse.c +++ b/src/triggers/createcurse.c @@ -25,11 +25,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* util includes */ #include +#include #include #include #include +#include #include -#include #include diff --git a/src/triggers/createunit.c b/src/triggers/createunit.c index 951887860..f152d3766 100644 --- a/src/triggers/createunit.c +++ b/src/triggers/createunit.c @@ -31,6 +31,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include diff --git a/src/triggers/gate.c b/src/triggers/gate.c index a66e0365e..d3fa1a1a8 100644 --- a/src/triggers/gate.c +++ b/src/triggers/gate.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include diff --git a/src/triggers/giveitem.c b/src/triggers/giveitem.c index 0442d9295..08e4f0147 100644 --- a/src/triggers/giveitem.c +++ b/src/triggers/giveitem.c @@ -29,6 +29,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include diff --git a/src/triggers/killunit.c b/src/triggers/killunit.c index 230efa7dc..bca630177 100644 --- a/src/triggers/killunit.c +++ b/src/triggers/killunit.c @@ -28,6 +28,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include diff --git a/src/triggers/shock.c b/src/triggers/shock.c index 690a115df..7eae6f31a 100644 --- a/src/triggers/shock.c +++ b/src/triggers/shock.c @@ -34,6 +34,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include #include diff --git a/src/triggers/timeout.c b/src/triggers/timeout.c index 43bb061c8..5179bd832 100644 --- a/src/triggers/timeout.c +++ b/src/triggers/timeout.c @@ -24,6 +24,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include #include diff --git a/src/util/base36.test.c b/src/util/base36.test.c index b2e6fcbac..226fd86ab 100644 --- a/src/util/base36.test.c +++ b/src/util/base36.test.c @@ -1,3 +1,7 @@ +#ifdef _MSC_VER +#include +#endif + #include #include "base36.h" #include diff --git a/src/util/bsdstring.c b/src/util/bsdstring.c index d9d974dcd..36377713f 100644 --- a/src/util/bsdstring.c +++ b/src/util/bsdstring.c @@ -1,4 +1,6 @@ +#ifdef _MSC_VER #include +#endif #include #include #include diff --git a/src/util/bsdstring.test.c b/src/util/bsdstring.test.c index 61453f893..70e8aa8b8 100644 --- a/src/util/bsdstring.test.c +++ b/src/util/bsdstring.test.c @@ -1,3 +1,6 @@ +#ifdef _MSC_VER +#include +#endif #include #include "bsdstring.h" #include diff --git a/src/util/crmessage.c b/src/util/crmessage.c index dd400bf3d..3e3b05177 100644 --- a/src/util/crmessage.c +++ b/src/util/crmessage.c @@ -14,6 +14,7 @@ #include #include "crmessage.h" +#include "macros.h" #include "message.h" #include "strings.h" #include "log.h" diff --git a/src/util/functions.test.c b/src/util/functions.test.c index ddd882821..32606b98f 100644 --- a/src/util/functions.test.c +++ b/src/util/functions.test.c @@ -1,3 +1,6 @@ +#ifdef _MSC_VER +#include +#endif #include #include #include diff --git a/src/util/language.c b/src/util/language.c index 565cf25a1..689ccfcd7 100644 --- a/src/util/language.c +++ b/src/util/language.c @@ -16,6 +16,10 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ +#ifdef _MSC_VER +#include +#endif + #include "language.h" #include "log.h" diff --git a/src/util/lists.c b/src/util/lists.c index 9b4233c0a..9e4b3a493 100644 --- a/src/util/lists.c +++ b/src/util/lists.c @@ -16,8 +16,11 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ -#include "lists.h" +#ifdef _MSC_VER +#include +#endif +#include "lists.h" #include "strings.h" #include diff --git a/src/util/log.test.c b/src/util/log.test.c index 1558ee3e3..86f13ea9c 100644 --- a/src/util/log.test.c +++ b/src/util/log.test.c @@ -1,7 +1,10 @@ +#ifdef _MSC_VER #include +#endif #include #include "log.h" +#include "macros.h" #include #include diff --git a/src/util/macros.h b/src/util/macros.h index bf60b9f40..6bca93465 100644 --- a/src/util/macros.h +++ b/src/util/macros.h @@ -1,3 +1,3 @@ -#define UNUSED_ARG(x) (void)x +#define UNUSED_ARG(x) (void)(x) #define TOLUA_CAST (char*) diff --git a/src/util/mt19937ar.c b/src/util/mt19937ar.c index 4fbd3f70d..0dda925ca 100644 --- a/src/util/mt19937ar.c +++ b/src/util/mt19937ar.c @@ -41,8 +41,6 @@ email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space) */ -#include - /* Period parameters */ #define N 624 #define M 397 diff --git a/src/util/rand.c b/src/util/rand.c index 441461068..f409cd0bb 100644 --- a/src/util/rand.c +++ b/src/util/rand.c @@ -28,6 +28,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +/* do not use M_PI, use one of these instead: */ +#define PI_F 3.1415926535897932384626433832795F +#define PI_D 3.1415926535897932384626433832795 +#define PI_L 3.1415926535897932384626433832795L + int lovar(double xpct_x2) { int n = (int)(xpct_x2 * 500) + 1; diff --git a/src/util/rng.test.c b/src/util/rng.test.c index e5bedde81..34e530c5e 100644 --- a/src/util/rng.test.c +++ b/src/util/rng.test.c @@ -1,3 +1,6 @@ +#ifdef _MSC_VER +#include +#endif #include #include diff --git a/src/util/strings.c b/src/util/strings.c index 3a69b92e9..0c3908397 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -16,6 +16,9 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ +#ifdef _MSC_VER +#include +#endif #include "strings.h" #include "assert.h" diff --git a/src/util/strings.test.c b/src/util/strings.test.c index 14d62200a..cff6a5168 100644 --- a/src/util/strings.test.c +++ b/src/util/strings.test.c @@ -1,3 +1,6 @@ +#ifdef _MSC_VER +#include +#endif #include #include #include diff --git a/src/util/translation.c b/src/util/translation.c index 290e28c16..b15a79fe2 100644 --- a/src/util/translation.c +++ b/src/util/translation.c @@ -9,13 +9,16 @@ This program may not be used, modified or distributed without prior permission by the authors of Eressea. */ +#ifdef _MSC_VER #include +#endif #include "translation.h" #include "bsdstring.h" #include "critbit.h" #include "log.h" +#include "macros.h" #include "assert.h" /* libc includes */ @@ -161,12 +164,12 @@ static void free_functions(void) void add_function(const char *symbol, evalfun parse) { - char buffer[64]; + char token[64]; size_t len = strlen(symbol); - assert(len + 1 + sizeof(parse) <= sizeof(buffer)); - len = cb_new_kv(symbol, len, &parse, sizeof(parse), buffer); - cb_insert(&functions, buffer, len); + assert(len + 1 + sizeof(parse) <= sizeof(token)); + len = cb_new_kv(symbol, len, &parse, sizeof(parse), token); + cb_insert(&functions, token, len); } static evalfun find_function(const char *symbol) diff --git a/src/util/umlaut.test.c b/src/util/umlaut.test.c index 959960509..0c94ea87a 100644 --- a/src/util/umlaut.test.c +++ b/src/util/umlaut.test.c @@ -1,3 +1,6 @@ +#ifdef _MSC_VER +#include +#endif #include #include #include diff --git a/src/wormhole.c b/src/wormhole.c index b4dfa7068..2366a7e9c 100644 --- a/src/wormhole.c +++ b/src/wormhole.c @@ -28,10 +28,11 @@ #include #include #include +#include #include #include -#include +#include #include /* libc includes */