From b27e1a01aab35c0c1c185cafae488e3312ea3018 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 10 Jan 2017 18:07:36 +0100 Subject: [PATCH] continued work for MSVC compilation --- src/alchemy.c | 4 ++++ src/battle.c | 11 +++++++++-- src/donations.c | 1 + src/economy.c | 38 +++++++++++++++++++------------------- src/kernel/messages.h | 2 +- src/move.c | 11 +++++++++-- src/names.c | 2 +- src/platform.h | 23 +++++++++++++++++++++++ src/reports.c | 16 ++++++++-------- src/spells.c | 8 +++++++- src/spells/combatspells.c | 4 ++-- src/util/rand.h | 3 +++ 12 files changed, 87 insertions(+), 36 deletions(-) diff --git a/src/alchemy.c b/src/alchemy.c index ddbe46b8e..81244eba1 100644 --- a/src/alchemy.c +++ b/src/alchemy.c @@ -162,6 +162,7 @@ static int potion_healing(unit * u, int amount) { static int potion_luck(unit *u, region *r, attrib_type *atype, int amount) { attrib *a = (attrib *)a_find(r->attribs, atype); + UNUSED_ARG(u); if (!a) { a = a_add(&r->attribs, a_new(atype)); } @@ -170,6 +171,7 @@ static int potion_luck(unit *u, region *r, attrib_type *atype, int amount) { } static int potion_truth(unit *u) { + UNUSED_ARG(u); // TODO: this potion does nothing! // fset(u, UFL_DISBELIEVES); return 1; @@ -304,6 +306,7 @@ static void a_writeeffect(const attrib * a, const void *owner, struct storage *store) { effect_data *edata = (effect_data *)a->data.v; + UNUSED_ARG(owner); WRITE_TOK(store, resourcename(edata->type->itype->rtype, 0)); WRITE_INT(store, edata->value); } @@ -316,6 +319,7 @@ static int a_readeffect(attrib * a, void *owner, struct gamedata *data) effect_data *edata = (effect_data *)a->data.v; char zText[32]; + UNUSED_ARG(owner); READ_TOK(store, zText, sizeof(zText)); rtype = rt_find(zText); diff --git a/src/battle.c b/src/battle.c index 3b34cd162..7e5c4b9d8 100644 --- a/src/battle.c +++ b/src/battle.c @@ -509,6 +509,9 @@ contest_new(int skilldiff, const troop dt, const armor_type * ar, const armor_type * sh) { double tohit = 0.5 + skilldiff * 0.1; + + UNUSED_ARG(sh); + UNUSED_ARG(ar); if (tohit < 0.5) tohit = 0.5; if (chance(tohit)) { @@ -839,6 +842,7 @@ int select_magicarmor(troop t) /* Sind side ds und Magier des meffect verb�ndet, dann return 1*/ bool meffect_protection(battle * b, meffect * s, side * ds) { + UNUSED_ARG(b); if (!s->magician->alive) return false; if (s->duration <= 0) @@ -853,6 +857,7 @@ bool meffect_protection(battle * b, meffect * s, side * ds) /* Sind side as und Magier des meffect verfeindet, dann return 1*/ bool meffect_blocked(battle * b, meffect * s, side * as) { + UNUSED_ARG(b); if (!s->magician->alive) return false; if (s->duration <= 0) @@ -1763,8 +1768,8 @@ void do_combatmagic(battle * b, combatmagic_t was) for (co = spellranks[rank].begin; co; co = co->next) { fighter *fig = co->magician.fig; const spell *sp = co->sp; - int level = co->level; + level = co->level; if (!sp->cast) { log_error("spell '%s' has no function.\n", sp->sname); } @@ -2040,6 +2045,7 @@ int hits(troop at, troop dt, weapon * awp) void dazzle(battle * b, troop * td) { + UNUSED_ARG(b); /* Nicht kumulativ ! */ #ifdef TODO_RUNESWORD if (td->fighter->weapon[WP_RUNESWORD].count > td->index) { @@ -2487,6 +2493,7 @@ troop select_ally(fighter * af, int minrow, int maxrow, int allytype) static int loot_quota(const unit * src, const unit * dst, const item_type * type, int n) { + UNUSED_ARG(type); if (dst && src && src->faction != dst->faction) { double divisor = config_get_flt("rules.items.loot_divisor", 1); assert(divisor <= 0 || divisor >= 1); @@ -2636,7 +2643,6 @@ static void reorder_fleeing(region * r) static void aftermath(battle * b) { region *r = b->region; - ship *sh; side *s; int dead_players = 0; bfaction *bf; @@ -2833,6 +2839,7 @@ static void aftermath(battle * b) * dieses Schiff besch�digt. Andernfalls ein Schiff, welches * evt. zuvor verlassen wurde. */ if (ships_damaged) { + ship *sh; if (du->ship) sh = du->ship; else diff --git a/src/donations.c b/src/donations.c index 8f820df2b..7d2f15816 100644 --- a/src/donations.c +++ b/src/donations.c @@ -1,3 +1,4 @@ +#include #include #include "donations.h" diff --git a/src/economy.c b/src/economy.c index 7edbbcb12..16b201555 100644 --- a/src/economy.c +++ b/src/economy.c @@ -1041,10 +1041,10 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) static int required(int want, double save) { - int norders = (int)(want * save); - if (norders < want * save) - ++norders; - return norders; + int req = (int)(want * save); + if (req < want * save) + ++req; + return req; } static void @@ -1058,7 +1058,7 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) if (rm != NULL) { do { int avail = rm->amount; - int norders = 0; + int nreq = 0; allocation *al; if (avail <= 0) { @@ -1077,7 +1077,7 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) if (effskill(al->unit, itype->construction->skill, 0) >= rm->level + itype->construction->minskill - 1) { if (req) { - norders += req; + nreq += req; } else { fset(al, AFL_DONE); @@ -1089,22 +1089,22 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) fset(al, AFL_LOWSKILL); } } - need = norders; + need = nreq; - avail = MIN(avail, norders); + avail = MIN(avail, nreq); if (need > 0) { int use = 0; for (al = alist; al; al = al->next) if (!fval(al, AFL_DONE)) { if (avail > 0) { int want = required(al->want - al->get, al->save); - int x = avail * want / norders; + int x = avail * want / nreq; /* Wenn Rest, dann würfeln, ob ich was bekomme: */ - if (rng_int() % norders < (avail * want) % norders) + if (rng_int() % nreq < (avail * want) % nreq) ++x; avail -= x; use += x; - norders -= want; + nreq -= want; need -= x; al->get = MIN(al->want, al->get + (int)(x / al->save)); } @@ -1113,7 +1113,7 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) assert(use <= rm->amount); rm->type->use(rm, r, use); } - assert(avail == 0 || norders == 0); + assert(avail == 0 || nreq == 0); } first = false; } while (need > 0); @@ -1124,13 +1124,13 @@ static void attrib_allocation(const resource_type * rtype, region * r, allocation * alist) { allocation *al; - int norders = 0; + int nreq = 0; attrib *a = a_find(rtype->attribs, &at_resourcelimit); resource_limit *rdata = (resource_limit *)a->data.v; int avail = rdata->value; for (al = alist; al; al = al->next) { - norders += required(al->want, al->save); + nreq += required(al->want, al->save); } if (rdata->limit) { @@ -1139,16 +1139,16 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist) avail = 0; } - avail = MIN(avail, norders); + avail = MIN(avail, nreq); for (al = alist; al; al = al->next) { if (avail > 0) { int want = required(al->want, al->save); - int x = avail * want / norders; + int x = avail * want / nreq; /* Wenn Rest, dann würfeln, ob ich was bekomme: */ - if (rng_int() % norders < (avail * want) % norders) + if (rng_int() % nreq < (avail * want) % nreq) ++x; avail -= x; - norders -= want; + nreq -= want; al->get = MIN(al->want, (int)(x / al->save)); if (rdata->produce) { int use = required(al->get, al->save); @@ -1157,7 +1157,7 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist) } } } - assert(avail == 0 || norders == 0); + assert(avail == 0 || nreq == 0); } typedef void(*allocate_function) (const resource_type *, struct region *, diff --git a/src/kernel/messages.h b/src/kernel/messages.h index 866eecba7..a42342153 100644 --- a/src/kernel/messages.h +++ b/src/kernel/messages.h @@ -57,7 +57,7 @@ extern "C" { struct mlist ** merge_messages(message_list *mlist, message_list *append); void split_messages(message_list *mlist, struct mlist **split); -#define ADDMSG(msgs, mcreate) { message * m = mcreate; if (m) { assert(m->refcount>=1); add_message(msgs, m); msg_release(m); } } +#define ADDMSG(msgs, mcreate) { message * mx = mcreate; if (mx) { assert(mx->refcount>=1); add_message(msgs, mx); msg_release(mx); } } void syntax_error(const struct unit *u, struct order *ord); struct message * cmistake(const struct unit *u, struct order *ord, int mno, int mtype); diff --git a/src/move.c b/src/move.c index 62300beb1..0184d22ca 100644 --- a/src/move.c +++ b/src/move.c @@ -163,6 +163,7 @@ static int shiptrail_read(attrib * a, void *owner, struct gamedata *data) int n; traveldir *t = (traveldir *)(a->data.v); + UNUSED_ARG(owner); READ_INT(store, &t->no); READ_INT(store, &n); t->dir = (direction_t)n; @@ -174,6 +175,8 @@ static void shiptrail_write(const attrib * a, const void *owner, struct storage *store) { traveldir *t = (traveldir *)(a->data.v); + + UNUSED_ARG(owner); WRITE_INT(store, t->no); WRITE_INT(store, t->dir); WRITE_INT(store, t->age); @@ -204,6 +207,8 @@ static bool entrance_allowed(const struct unit *u, const struct region *r) return true; return false; #else + UNUSED_ARG(u); + UNUSED_ARG(r); return true; #endif } @@ -466,6 +471,8 @@ static int canride(unit * u) static bool cansail(const region * r, ship * sh) { + UNUSED_ARG(r); + /* sonst ist construction:: size nicht ship_type::maxsize */ assert(!sh->type->construction || sh->type->construction->improvement == NULL); @@ -490,6 +497,8 @@ static bool cansail(const region * r, ship * sh) static double overload(const region * r, ship * sh) { + UNUSED_ARG(r); + /* sonst ist construction:: size nicht ship_type::maxsize */ assert(!sh->type->construction || sh->type->construction->improvement == NULL); @@ -1761,8 +1770,6 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting) * befahrene Region. */ while (next_point && current_point != next_point && step < k) { - const char *token; - int error; const terrain_type *tthis = current_point->terrain; /* these values need to be updated if next_point changes (due to storms): */ const terrain_type *tnext = next_point->terrain; diff --git a/src/names.c b/src/names.c index 248084828..969e278d8 100644 --- a/src/names.c +++ b/src/names.c @@ -394,8 +394,8 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars) size_t size; int result; + UNUSED_ARG(buflen); /* Prüfen, ob Kurz genug */ - if (strlen(s) <= maxchars) { return s; } diff --git a/src/platform.h b/src/platform.h index 2f114cec5..57f4cd720 100644 --- a/src/platform.h +++ b/src/platform.h @@ -3,6 +3,21 @@ #ifndef UNILIB_H #define UNILIB_H +#ifdef _MSC_VER +#ifndef __STDC__ +#define __STDC__ 1 // equivalent to /Za +#endif +#define NO_STRDUP +#define NO_MKDIR +#define mkdir(d, a) _mkdir(d) +#define _CRT_SECURE_NO_WARNINGS +#pragma warning(disable: 4710 4820) +#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 +#endif + #ifndef MAX_PATH # define MAX_PATH 4096 #endif @@ -12,4 +27,12 @@ #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#ifdef NO_STRDUP +char * strdup(const char *s); +#endif + +#ifdef NO_MKDIR +int mkdir(const char *pathname, int mode); +#endif + #endif diff --git a/src/reports.c b/src/reports.c index b31ecac19..6d0aaba37 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1907,23 +1907,23 @@ static void eval_regions(struct opstack **stack, const void *userdata) const faction *report = (const faction *)userdata; int i = opop(stack).i; int end, begin = opop(stack).i; - const arg_regions *regions = (const arg_regions *)opop(stack).v; + const arg_regions *aregs = (const arg_regions *)opop(stack).v; char buf[256]; size_t size = sizeof(buf) - 1; variant var; char *bufp = buf; - if (regions == NULL) { + if (aregs == NULL) { end = begin; } else { if (i >= 0) end = begin + i; else - end = regions->nregions + i; + end = aregs->nregions + i; } for (i = begin; i < end; ++i) { - const char *rname = (const char *)regionname(regions->regions[i], report); + const char *rname = (const char *)regionname(aregs->regions[i], report); bufp = STRLCPY(bufp, rname, size); if (i + 1 < end && size > 2) { @@ -1942,7 +1942,7 @@ static void eval_trail(struct opstack **stack, const void *userdata) const faction *report = (const faction *)userdata; const struct locale *lang = report ? report->locale : default_locale; int i, end = 0, begin = 0; - const arg_regions *regions = (const arg_regions *)opop(stack).v; + const arg_regions *aregs = (const arg_regions *)opop(stack).v; char buf[512]; size_t size = sizeof(buf) - 1; variant var; @@ -1952,10 +1952,10 @@ static void eval_trail(struct opstack **stack, const void *userdata) int eold = errno; #endif - if (regions != NULL) { - end = regions->nregions; + if (aregs != NULL) { + end = aregs->nregions; for (i = begin; i < end; ++i) { - region *r = regions->regions[i]; + region *r = aregs->regions[i]; const char *trail = trailinto(r, lang); const char *rn = f_regionid_s(r, report); diff --git a/src/spells.c b/src/spells.c index 6ed38d022..0bb6df5af 100644 --- a/src/spells.c +++ b/src/spells.c @@ -398,6 +398,7 @@ static void report_effect(region * r, unit * mage, message * seen, message * unseen) { int err = report_action(r, mage, seen, ACTION_RESET | ACTION_CANSEE); + UNUSED_ARG(unseen); if (err) { report_action(r, mage, seen, ACTION_CANNOTSEE); } @@ -2895,6 +2896,8 @@ static int dc_read_compat(struct attrib *a, void *target, gamedata *data) float strength; int rx, ry; + UNUSED_ARG(a); + UNUSED_ARG(target); READ_INT(store, &duration); READ_FLT(store, &strength); READ_INT(store, &var.i); @@ -3119,8 +3122,10 @@ static bool chaosgate_valid(const connection * b) } static struct region *chaosgate_move(const connection * b, struct unit *u, -struct region *from, struct region *to, bool routing) + struct region *from, struct region *to, bool routing) { + UNUSED_ARG(from); + UNUSED_ARG(b); if (!routing) { int maxhp = u->hp / 4; if (maxhp < u->number) @@ -6438,6 +6443,7 @@ int sp_break_curse(castorder * co) /* ------------------------------------------------------------- */ int sp_becomewyrm(castorder * co) { + UNUSED_ARG(co); return 0; } diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index 0e1a27e75..227d94858 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -826,8 +826,8 @@ int sp_shadowcall(struct castorder * co) attrib *a; int force = (int)(get_force(power, 3) / 2); unit *u; - const char *races[3] = { "shadowbat", "nightmare", "vampunicorn" }; - const race *rc = rc_find(races[rng_int() % 3]); + const char *rcnames[3] = { "shadowbat", "nightmare", "vampunicorn" }; + const race *rc = rc_find(rcnames[rng_int() % 3]); message *msg; u = create_unit(r, mage->faction, force, rc, 0, NULL, mage); diff --git a/src/util/rand.h b/src/util/rand.h index 9fb3f2f69..2aabb8571 100644 --- a/src/util/rand.h +++ b/src/util/rand.h @@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef RAND_H #define RAND_H + +#include + #ifdef __cplusplus extern "C" { #endif