continued work for MSVC compilation

This commit is contained in:
Enno Rehling 2017-01-10 18:07:36 +01:00 committed by Enno Rehling
parent 5ddd511aa8
commit 774fa12a5a
11 changed files with 84 additions and 36 deletions

View File

@ -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) { static int potion_luck(unit *u, region *r, attrib_type *atype, int amount) {
attrib *a = (attrib *)a_find(r->attribs, atype); attrib *a = (attrib *)a_find(r->attribs, atype);
UNUSED_ARG(u);
if (!a) { if (!a) {
a = a_add(&r->attribs, a_new(atype)); 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) { static int potion_truth(unit *u) {
UNUSED_ARG(u);
// TODO: this potion does nothing! // TODO: this potion does nothing!
// fset(u, UFL_DISBELIEVES); // fset(u, UFL_DISBELIEVES);
return 1; return 1;
@ -304,6 +306,7 @@ static void
a_writeeffect(const attrib * a, const void *owner, struct storage *store) a_writeeffect(const attrib * a, const void *owner, struct storage *store)
{ {
effect_data *edata = (effect_data *)a->data.v; effect_data *edata = (effect_data *)a->data.v;
UNUSED_ARG(owner);
WRITE_TOK(store, resourcename(edata->type->itype->rtype, 0)); WRITE_TOK(store, resourcename(edata->type->itype->rtype, 0));
WRITE_INT(store, edata->value); 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; effect_data *edata = (effect_data *)a->data.v;
char zText[32]; char zText[32];
UNUSED_ARG(owner);
READ_TOK(store, zText, sizeof(zText)); READ_TOK(store, zText, sizeof(zText));
rtype = rt_find(zText); rtype = rt_find(zText);

View File

@ -509,6 +509,9 @@ contest_new(int skilldiff, const troop dt, const armor_type * ar,
const armor_type * sh) const armor_type * sh)
{ {
double tohit = 0.5 + skilldiff * 0.1; double tohit = 0.5 + skilldiff * 0.1;
UNUSED_ARG(sh);
UNUSED_ARG(ar);
if (tohit < 0.5) if (tohit < 0.5)
tohit = 0.5; tohit = 0.5;
if (chance(tohit)) { if (chance(tohit)) {
@ -839,6 +842,7 @@ int select_magicarmor(troop t)
/* Sind side ds und Magier des meffect verb<72>ndet, dann return 1*/ /* Sind side ds und Magier des meffect verb<72>ndet, dann return 1*/
bool meffect_protection(battle * b, meffect * s, side * ds) bool meffect_protection(battle * b, meffect * s, side * ds)
{ {
UNUSED_ARG(b);
if (!s->magician->alive) if (!s->magician->alive)
return false; return false;
if (s->duration <= 0) 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*/ /* Sind side as und Magier des meffect verfeindet, dann return 1*/
bool meffect_blocked(battle * b, meffect * s, side * as) bool meffect_blocked(battle * b, meffect * s, side * as)
{ {
UNUSED_ARG(b);
if (!s->magician->alive) if (!s->magician->alive)
return false; return false;
if (s->duration <= 0) 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) { for (co = spellranks[rank].begin; co; co = co->next) {
fighter *fig = co->magician.fig; fighter *fig = co->magician.fig;
const spell *sp = co->sp; const spell *sp = co->sp;
int level = co->level;
level = co->level;
if (!sp->cast) { if (!sp->cast) {
log_error("spell '%s' has no function.\n", sp->sname); 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) void dazzle(battle * b, troop * td)
{ {
UNUSED_ARG(b);
/* Nicht kumulativ ! */ /* Nicht kumulativ ! */
#ifdef TODO_RUNESWORD #ifdef TODO_RUNESWORD
if (td->fighter->weapon[WP_RUNESWORD].count > td->index) { 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, static int loot_quota(const unit * src, const unit * dst,
const item_type * type, int n) const item_type * type, int n)
{ {
UNUSED_ARG(type);
if (dst && src && src->faction != dst->faction) { if (dst && src && src->faction != dst->faction) {
double divisor = config_get_flt("rules.items.loot_divisor", 1); double divisor = config_get_flt("rules.items.loot_divisor", 1);
assert(divisor <= 0 || divisor >= 1); assert(divisor <= 0 || divisor >= 1);
@ -2636,7 +2643,6 @@ static void reorder_fleeing(region * r)
static void aftermath(battle * b) static void aftermath(battle * b)
{ {
region *r = b->region; region *r = b->region;
ship *sh;
side *s; side *s;
int dead_players = 0; int dead_players = 0;
bfaction *bf; bfaction *bf;
@ -2833,6 +2839,7 @@ static void aftermath(battle * b)
* dieses Schiff besch<EFBFBD>digt. Andernfalls ein Schiff, welches * dieses Schiff besch<EFBFBD>digt. Andernfalls ein Schiff, welches
* evt. zuvor verlassen wurde. */ * evt. zuvor verlassen wurde. */
if (ships_damaged) { if (ships_damaged) {
ship *sh;
if (du->ship) if (du->ship)
sh = du->ship; sh = du->ship;
else else

View File

@ -1,3 +1,4 @@
#include <platform.h>
#include <kernel/types.h> #include <kernel/types.h>
#include "donations.h" #include "donations.h"

View File

@ -1041,10 +1041,10 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want)
static int required(int want, double save) static int required(int want, double save)
{ {
int norders = (int)(want * save); int req = (int)(want * save);
if (norders < want * save) if (req < want * save)
++norders; ++req;
return norders; return req;
} }
static void static void
@ -1058,7 +1058,7 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist)
if (rm != NULL) { if (rm != NULL) {
do { do {
int avail = rm->amount; int avail = rm->amount;
int norders = 0; int nreq = 0;
allocation *al; allocation *al;
if (avail <= 0) { 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) if (effskill(al->unit, itype->construction->skill, 0)
>= rm->level + itype->construction->minskill - 1) { >= rm->level + itype->construction->minskill - 1) {
if (req) { if (req) {
norders += req; nreq += req;
} }
else { else {
fset(al, AFL_DONE); fset(al, AFL_DONE);
@ -1089,22 +1089,22 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist)
fset(al, AFL_LOWSKILL); fset(al, AFL_LOWSKILL);
} }
} }
need = norders; need = nreq;
avail = MIN(avail, norders); avail = MIN(avail, nreq);
if (need > 0) { if (need > 0) {
int use = 0; int use = 0;
for (al = alist; al; al = al->next) for (al = alist; al; al = al->next)
if (!fval(al, AFL_DONE)) { if (!fval(al, AFL_DONE)) {
if (avail > 0) { if (avail > 0) {
int want = required(al->want - al->get, al->save); 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: */ /* Wenn Rest, dann würfeln, ob ich was bekomme: */
if (rng_int() % norders < (avail * want) % norders) if (rng_int() % nreq < (avail * want) % nreq)
++x; ++x;
avail -= x; avail -= x;
use += x; use += x;
norders -= want; nreq -= want;
need -= x; need -= x;
al->get = MIN(al->want, al->get + (int)(x / al->save)); 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); assert(use <= rm->amount);
rm->type->use(rm, r, use); rm->type->use(rm, r, use);
} }
assert(avail == 0 || norders == 0); assert(avail == 0 || nreq == 0);
} }
first = false; first = false;
} while (need > 0); } while (need > 0);
@ -1124,13 +1124,13 @@ static void
attrib_allocation(const resource_type * rtype, region * r, allocation * alist) attrib_allocation(const resource_type * rtype, region * r, allocation * alist)
{ {
allocation *al; allocation *al;
int norders = 0; int nreq = 0;
attrib *a = a_find(rtype->attribs, &at_resourcelimit); attrib *a = a_find(rtype->attribs, &at_resourcelimit);
resource_limit *rdata = (resource_limit *)a->data.v; resource_limit *rdata = (resource_limit *)a->data.v;
int avail = rdata->value; int avail = rdata->value;
for (al = alist; al; al = al->next) { for (al = alist; al; al = al->next) {
norders += required(al->want, al->save); nreq += required(al->want, al->save);
} }
if (rdata->limit) { if (rdata->limit) {
@ -1139,16 +1139,16 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist)
avail = 0; avail = 0;
} }
avail = MIN(avail, norders); avail = MIN(avail, nreq);
for (al = alist; al; al = al->next) { for (al = alist; al; al = al->next) {
if (avail > 0) { if (avail > 0) {
int want = required(al->want, al->save); 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: */ /* Wenn Rest, dann würfeln, ob ich was bekomme: */
if (rng_int() % norders < (avail * want) % norders) if (rng_int() % nreq < (avail * want) % nreq)
++x; ++x;
avail -= x; avail -= x;
norders -= want; nreq -= want;
al->get = MIN(al->want, (int)(x / al->save)); al->get = MIN(al->want, (int)(x / al->save));
if (rdata->produce) { if (rdata->produce) {
int use = required(al->get, al->save); 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 *, typedef void(*allocate_function) (const resource_type *, struct region *,

View File

@ -57,7 +57,7 @@ extern "C" {
struct mlist ** merge_messages(message_list *mlist, message_list *append); struct mlist ** merge_messages(message_list *mlist, message_list *append);
void split_messages(message_list *mlist, struct mlist **split); 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); void syntax_error(const struct unit *u, struct order *ord);
struct message * cmistake(const struct unit *u, struct order *ord, int mno, int mtype); struct message * cmistake(const struct unit *u, struct order *ord, int mno, int mtype);

View File

@ -163,6 +163,7 @@ static int shiptrail_read(attrib * a, void *owner, struct gamedata *data)
int n; int n;
traveldir *t = (traveldir *)(a->data.v); traveldir *t = (traveldir *)(a->data.v);
UNUSED_ARG(owner);
READ_INT(store, &t->no); READ_INT(store, &t->no);
READ_INT(store, &n); READ_INT(store, &n);
t->dir = (direction_t)n; t->dir = (direction_t)n;
@ -174,6 +175,8 @@ static void
shiptrail_write(const attrib * a, const void *owner, struct storage *store) shiptrail_write(const attrib * a, const void *owner, struct storage *store)
{ {
traveldir *t = (traveldir *)(a->data.v); traveldir *t = (traveldir *)(a->data.v);
UNUSED_ARG(owner);
WRITE_INT(store, t->no); WRITE_INT(store, t->no);
WRITE_INT(store, t->dir); WRITE_INT(store, t->dir);
WRITE_INT(store, t->age); WRITE_INT(store, t->age);
@ -204,6 +207,8 @@ static bool entrance_allowed(const struct unit *u, const struct region *r)
return true; return true;
return false; return false;
#else #else
UNUSED_ARG(u);
UNUSED_ARG(r);
return true; return true;
#endif #endif
} }
@ -466,6 +471,8 @@ static int canride(unit * u)
static bool cansail(const region * r, ship * sh) static bool cansail(const region * r, ship * sh)
{ {
UNUSED_ARG(r);
/* sonst ist construction:: size nicht ship_type::maxsize */ /* sonst ist construction:: size nicht ship_type::maxsize */
assert(!sh->type->construction assert(!sh->type->construction
|| sh->type->construction->improvement == NULL); || 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) static double overload(const region * r, ship * sh)
{ {
UNUSED_ARG(r);
/* sonst ist construction:: size nicht ship_type::maxsize */ /* sonst ist construction:: size nicht ship_type::maxsize */
assert(!sh->type->construction assert(!sh->type->construction
|| sh->type->construction->improvement == NULL); || sh->type->construction->improvement == NULL);
@ -1761,8 +1770,6 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting)
* befahrene Region. */ * befahrene Region. */
while (next_point && current_point != next_point && step < k) { while (next_point && current_point != next_point && step < k) {
const char *token;
int error;
const terrain_type *tthis = current_point->terrain; const terrain_type *tthis = current_point->terrain;
/* these values need to be updated if next_point changes (due to storms): */ /* these values need to be updated if next_point changes (due to storms): */
const terrain_type *tnext = next_point->terrain; const terrain_type *tnext = next_point->terrain;

View File

@ -394,8 +394,8 @@ const char *abkz(const char *s, char *buf, size_t buflen, size_t maxchars)
size_t size; size_t size;
int result; int result;
UNUSED_ARG(buflen);
/* Prüfen, ob Kurz genug */ /* Prüfen, ob Kurz genug */
if (strlen(s) <= maxchars) { if (strlen(s) <= maxchars) {
return s; return s;
} }

View File

@ -4,6 +4,20 @@
#define UNILIB_H #define UNILIB_H
#define _POSIX_C_SOURCE 200809L #define _POSIX_C_SOURCE 200809L
#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 #ifndef MAX_PATH
# define MAX_PATH 4096 # define MAX_PATH 4096
@ -15,4 +29,13 @@
#define MAX(a, b) (((a) > (b)) ? (a) : (b)) #define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define TOLUA_CAST (char*) #define TOLUA_CAST (char*)
#ifdef NO_STRDUP
char * strdup(const char *s);
#endif
#ifdef NO_MKDIR
int mkdir(const char *pathname, int mode);
#endif
#endif #endif

View File

@ -1906,23 +1906,23 @@ static void eval_regions(struct opstack **stack, const void *userdata)
const faction *report = (const faction *)userdata; const faction *report = (const faction *)userdata;
int i = opop(stack).i; int i = opop(stack).i;
int end, begin = 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]; char buf[256];
size_t size = sizeof(buf) - 1; size_t size = sizeof(buf) - 1;
variant var; variant var;
char *bufp = buf; char *bufp = buf;
if (regions == NULL) { if (aregs == NULL) {
end = begin; end = begin;
} }
else { else {
if (i >= 0) if (i >= 0)
end = begin + i; end = begin + i;
else else
end = regions->nregions + i; end = aregs->nregions + i;
} }
for (i = begin; i < end; ++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); bufp = STRLCPY(bufp, rname, size);
if (i + 1 < end && size > 2) { if (i + 1 < end && size > 2) {
@ -1941,7 +1941,7 @@ static void eval_trail(struct opstack **stack, const void *userdata)
const faction *report = (const faction *)userdata; const faction *report = (const faction *)userdata;
const struct locale *lang = report ? report->locale : default_locale; const struct locale *lang = report ? report->locale : default_locale;
int i, end = 0, begin = 0; 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]; char buf[512];
size_t size = sizeof(buf) - 1; size_t size = sizeof(buf) - 1;
variant var; variant var;
@ -1951,10 +1951,10 @@ static void eval_trail(struct opstack **stack, const void *userdata)
int eold = errno; int eold = errno;
#endif #endif
if (regions != NULL) { if (aregs != NULL) {
end = regions->nregions; end = aregs->nregions;
for (i = begin; i < end; ++i) { for (i = begin; i < end; ++i) {
region *r = regions->regions[i]; region *r = aregs->regions[i];
const char *trail = trailinto(r, lang); const char *trail = trailinto(r, lang);
const char *rn = f_regionid_s(r, report); const char *rn = f_regionid_s(r, report);

View File

@ -398,6 +398,7 @@ static void
report_effect(region * r, unit * mage, message * seen, message * unseen) report_effect(region * r, unit * mage, message * seen, message * unseen)
{ {
int err = report_action(r, mage, seen, ACTION_RESET | ACTION_CANSEE); int err = report_action(r, mage, seen, ACTION_RESET | ACTION_CANSEE);
UNUSED_ARG(unseen);
if (err) { if (err) {
report_action(r, mage, seen, ACTION_CANNOTSEE); 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; float strength;
int rx, ry; int rx, ry;
UNUSED_ARG(a);
UNUSED_ARG(target);
READ_INT(store, &duration); READ_INT(store, &duration);
READ_FLT(store, &strength); READ_FLT(store, &strength);
READ_INT(store, &var.i); READ_INT(store, &var.i);
@ -3121,6 +3124,8 @@ static bool chaosgate_valid(const connection * b)
static struct region *chaosgate_move(const connection * b, struct unit *u, 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) { if (!routing) {
int maxhp = u->hp / 4; int maxhp = u->hp / 4;
if (maxhp < u->number) if (maxhp < u->number)
@ -6438,6 +6443,7 @@ int sp_break_curse(castorder * co)
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
int sp_becomewyrm(castorder * co) int sp_becomewyrm(castorder * co)
{ {
UNUSED_ARG(co);
return 0; return 0;
} }

View File

@ -826,8 +826,8 @@ int sp_shadowcall(struct castorder * co)
attrib *a; attrib *a;
int force = (int)(get_force(power, 3) / 2); int force = (int)(get_force(power, 3) / 2);
unit *u; unit *u;
const char *races[3] = { "shadowbat", "nightmare", "vampunicorn" }; const char *rcnames[3] = { "shadowbat", "nightmare", "vampunicorn" };
const race *rc = rc_find(races[rng_int() % 3]); const race *rc = rc_find(rcnames[rng_int() % 3]);
message *msg; message *msg;
u = create_unit(r, mage->faction, force, rc, 0, NULL, mage); u = create_unit(r, mage->faction, force, rc, 0, NULL, mage);