From a6ae5a9e938769b2af2b8de95ff29ce9c36666b9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 30 Dec 2017 00:06:07 +0100 Subject: [PATCH 1/4] no more MINMAX --- src/upkeep.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/upkeep.c b/src/upkeep.c index f94804633..846e2f4f0 100644 --- a/src/upkeep.c +++ b/src/upkeep.c @@ -1,4 +1,6 @@ +#ifdef WIN32 #include +#endif #include "upkeep.h" #include @@ -42,7 +44,7 @@ static void help_feed(unit * donor, unit * u, int *need_p) { int need = *need_p; int give = get_money(donor) - lifestyle(donor); - give = MIN(need, give); + if (give > need) give = need; if (give > 0) { change_money(donor, -give); @@ -167,7 +169,7 @@ void get_food(region * r) * food from the peasants - should not be used with WORK */ if (owner != NULL && (get_alliance(owner, u->faction) & HELP_MONEY)) { int rm = rmoney(r); - int use = MIN(rm, need); + int use = (rm < need) ? rm : need; rsetmoney(r, rm - use); need -= use; } @@ -180,7 +182,7 @@ void get_food(region * r) for (v = r->units; need && v; v = v->next) { if (v->faction == u->faction) { int give = get_money(v) - lifestyle(v); - give = MIN(need, give); + if (give > need) give = need; if (give > 0) { change_money(v, -give); change_money(u, give); @@ -194,11 +196,11 @@ void get_food(region * r) /* 2. Versorgung durch Fremde. Das Silber alliierter Einheiten wird * entsprechend verteilt. */ for (u = r->units; u; u = u->next) { - int need = lifestyle(u); + int need; faction *f = u->faction; assert(u->hp > 0); - need -= MAX(0, get_money(u)); + need = lifestyle(u) - get_money(u); if (need > 0) { unit *v; @@ -253,8 +255,8 @@ void get_food(region * r) unit *donor = u; while (donor != NULL && hungry > 0) { int blut = get_effect(donor, pt_blood); - blut = MIN(blut, hungry); - if (blut) { + if (hungry < blut) blut = hungry; + if (blut > 0) { change_effect(donor, pt_blood, -blut); hungry -= blut; } @@ -306,7 +308,9 @@ void get_food(region * r) /* 3. Von den �berlebenden das Geld abziehen: */ for (u = r->units; u; u = u->next) { - int need = MIN(get_money(u), lifestyle(u)); + int m = get_money(u); + int need = lifestyle(u); + if (need > m) need = m; change_money(u, -need); } } From ea0acc49d9cd366f65fdf402e3b664034b9ea6aa Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 28 Dec 2017 10:50:08 +0100 Subject: [PATCH 2/4] iwyu --- src/monsters.c | 3 ++- src/util/lists.c | 2 +- src/util/lists.h | 2 -- src/util/log.c | 3 --- src/util/message.c | 1 - src/util/variant.c | 2 -- 6 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/monsters.c b/src/monsters.c index 0b1bb7902..01ebbe8cd 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -495,7 +495,7 @@ static order *make_movement_order(unit * u, const region * target, int moves, { region *r = u->region; region **plan; - int bytes, position = 0; + int position = 0; char zOrder[128], *bufp = zOrder; size_t size = sizeof(zOrder) - 1; @@ -507,6 +507,7 @@ static order *make_movement_order(unit * u, const region * target, int moves, return NULL; while (position != moves && plan[position + 1]) { + int bytes; region *prev = plan[position]; region *next = plan[++position]; direction_t dir = reldirection(prev, next); diff --git a/src/util/lists.c b/src/util/lists.c index 9e4b3a493..81f9c9ab2 100644 --- a/src/util/lists.c +++ b/src/util/lists.c @@ -12,7 +12,7 @@ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +ACTION OF CONTRACT, NEGLIGENCE OR OTH19ER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ diff --git a/src/util/lists.h b/src/util/lists.h index 75920c5d4..7fd0ca034 100644 --- a/src/util/lists.h +++ b/src/util/lists.h @@ -22,8 +22,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif -#include - typedef struct strlist { struct strlist *next; char *s; diff --git a/src/util/log.c b/src/util/log.c index a007a3b2b..5d95d0ea7 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -10,10 +10,7 @@ This program may not be used, modified or distributed without prior permission by the authors of Eressea. */ #include - -#include "bsdstring.h" #include "log.h" -#include "path.h" #include "unicode.h" #include diff --git a/src/util/message.c b/src/util/message.c index a502f833f..831ab23f8 100644 --- a/src/util/message.c +++ b/src/util/message.c @@ -11,7 +11,6 @@ */ -#include #include "message.h" #include "strings.h" diff --git a/src/util/variant.c b/src/util/variant.c index af5d690f4..dd8b16151 100644 --- a/src/util/variant.c +++ b/src/util/variant.c @@ -1,7 +1,5 @@ -#include #include "variant.h" -#include #include #include From c8ee0db02dabf8159cd64a9a63164328f37c2d7a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 30 Dec 2017 07:34:17 +0100 Subject: [PATCH 3/4] stop using MIN and MAX --- src/economy.c | 71 ++++++++++++++---------- src/spells.c | 149 +++++++++++++++++++++++++++++--------------------- src/spy.c | 9 ++- src/steal.c | 12 ++-- src/study.c | 11 +++- src/summary.c | 7 ++- src/upkeep.c | 2 +- 7 files changed, 157 insertions(+), 104 deletions(-) diff --git a/src/economy.c b/src/economy.c index 479edda9a..ef38ef8af 100644 --- a/src/economy.c +++ b/src/economy.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 "economy.h" @@ -332,11 +334,12 @@ static int do_recruiting(recruitment * recruits, int available) int number, dec; double multi = 2.0 * rc->recruit_multi; - number = MIN(req->qty, (int)(get / multi)); + number = (int)(get / multi); + if (number > req->qty) number = req->qty; if (rc->recruitcost) { int afford = get_pooled(u, get_resourcetype(R_SILVER), GET_DEFAULT, number * rc->recruitcost) / rc->recruitcost; - number = MIN(number, afford); + if (number > afford) number = afford; } if (u->number + number > UNIT_MAXSIZE) { ADDMSG(&u->faction->msgs, msg_feedback(u, req->ord, "error_unit_size", @@ -538,7 +541,8 @@ static void recruit(unit * u, struct order *ord, econ_request ** recruitorders) if (recruitcost > 0) { int pooled = get_pooled(u, get_resourcetype(R_SILVER), GET_DEFAULT, recruitcost * n); - n = MIN(n, pooled / recruitcost); + int pr = pooled / recruitcost; + if (n > pr) n = pr; } u->wants = n; @@ -1029,7 +1033,7 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) /* Schaffenstrunk: */ if ((dm = get_effect(u, oldpotiontype[P_DOMORE])) != 0) { - dm = MIN(dm, u->number); + if (dm > u->number) dm = u->number; change_effect(u, oldpotiontype[P_DOMORE], -dm); amount += dm * skill; /* dm Personen produzieren doppelt */ } @@ -1109,7 +1113,7 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) } need = nreq; - avail = MIN(avail, nreq); + if (avail > nreq) avail = nreq; if (need > 0) { int use = 0; for (al = alist; al; al = al->next) { @@ -1124,7 +1128,8 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist) use += x; nreq -= want; need -= x; - al->get = MIN(al->want, al->get + x * al->save.sa[1] / al->save.sa[0]); + al->get = al->get + x * al->save.sa[1] / al->save.sa[0]; + if (al->get > al->want) al->get = al->want; } } } @@ -1160,7 +1165,8 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist) } } - avail = MIN(avail, nreq); + if (avail > nreq) avail = nreq; + for (al = alist; al; al = al->next) { if (avail > 0) { int want = required(al->want, al->save); @@ -1171,7 +1177,7 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist) avail -= x; nreq -= want; al->get = x * al->save.sa[1] / al->save.sa[0]; - al->get = MIN(al->want, al->get); + if (al->want < al->get) al->get = al->want; if (!rtype->raw) { int use = required(al->get, al->save); if (use) { @@ -1622,7 +1628,7 @@ static void buy(unit * u, econ_request ** buyorders, struct order *ord) k -= a->data.i; } - n = MIN(n, k); + if (n > k) n = k; if (!n) { cmistake(u, ord, 102, MSG_COMMERCE); @@ -1863,7 +1869,7 @@ static bool sell(unit * u, econ_request ** sellorders, struct order *ord) bool unlimited = true; const item_type *itype; const luxury_type *ltype; - int n; + int n, i; region *r = u->region; const char *s; keyword_t kwd; @@ -1935,7 +1941,8 @@ static bool sell(unit * u, econ_request ** sellorders, struct order *ord) /* Ein H�ndler kann nur 10 G�ter pro Talentpunkt verkaufen. */ - n = MIN(n, u->number * 10 * effskill(u, SK_TRADE, 0)); + i = u->number * 10 * effskill(u, SK_TRADE, 0); + if (n > i) n = i; if (!n) { cmistake(u, ord, 54, MSG_COMMERCE); @@ -1965,11 +1972,12 @@ static bool sell(unit * u, econ_request ** sellorders, struct order *ord) if (o->type.ltype == ltype && o->unit->faction == u->faction) { int fpool = o->qty - get_pooled(o->unit, itype->rtype, GET_RESERVE, INT_MAX); - available -= MAX(0, fpool); + if (fpool < 0) fpool = 0; + available -= fpool; } } - n = MIN(n, available); + if (n > available) n = available; if (n <= 0) { cmistake(u, ord, 264, MSG_COMMERCE); @@ -1994,7 +2002,7 @@ static bool sell(unit * u, econ_request ** sellorders, struct order *ord) k -= a->data.i; } - n = MIN(n, k); + if (n > k) n = k; assert(n >= 0); /* die Menge der verkauften G�ter merken */ a->data.i += n; @@ -2049,8 +2057,9 @@ static void plant(unit * u, int raw) return; } - n = MIN(skill * u->number, n); - n = MIN(raw, n); + i = skill * u->number; + if (i > raw) i = raw; + if (n > i) n = i; /* F�r jedes Kraut Talent*10% Erfolgschance. */ for (i = n; i > 0; i--) { if (rng_int() % 10 < skill) @@ -2095,14 +2104,14 @@ static void planttrees(unit * u, int raw) } /* wenn eine Anzahl angegeben wurde, nur soviel verbrauchen */ - raw = MIN(raw, skill * u->number); + if (raw > skill * u->number) raw = skill * u->number; n = get_pooled(u, rtype, GET_DEFAULT, raw); if (n == 0) { ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "resource_missing", "missing", rtype)); return; } - n = MIN(raw, n); + if (n > raw) n = raw; /* F�r jeden Samen Talent*10% Erfolgschance. */ for (i = n; i > 0; i--) { @@ -2152,7 +2161,8 @@ static void breedtrees(unit * u, int raw) } /* wenn eine Anzahl angegeben wurde, nur soviel verbrauchen */ - raw = MIN(skill * u->number, raw); + i = skill * u->number; + if (raw > i) raw = i; n = get_pooled(u, rtype, GET_DEFAULT, raw); /* Samen pr�fen */ if (n == 0) { @@ -2160,7 +2170,7 @@ static void breedtrees(unit * u, int raw) msg_feedback(u, u->thisorder, "resource_missing", "missing", rtype)); return; } - n = MIN(raw, n); + if (n > raw) n = raw; /* F�r jeden Samen Talent*5% Erfolgschance. */ for (i = n; i > 0; i--) { @@ -2202,7 +2212,7 @@ static void breedhorses(unit * u) } effsk = effskill(u, SK_HORSE_TRAINING, 0); n = u->number * effsk; - n = MIN(n, horses); + if (n > horses) n = horses; for (c = 0; c < n; c++) { if (rng_int() % 100 < effsk) { @@ -2346,7 +2356,7 @@ static void expandentertainment(region * r) entertaining -= o->qty; /* Nur soviel PRODUCEEXP wie auch tats�chlich gemacht wurde */ - produceexp(u, SK_ENTERTAINMENT, MIN(u->n, u->number)); + produceexp(u, SK_ENTERTAINMENT, (u->n < u->number) ? u->n : u->number); add_income(u, IC_ENTERTAIN, o->qty, u->n); fset(u, UFL_LONGACTION | UFL_NOTMOVING); } @@ -2397,7 +2407,7 @@ void entertain_cmd(unit * u, struct order *ord) max_e = getuint(); if (max_e != 0) { - u->wants = MIN(u->wants, max_e); + if (u->wants > max_e) u->wants = max_e; } o = nextentertainer++; o->unit = u; @@ -2608,11 +2618,12 @@ void tax_cmd(unit * u, struct order *ord, econ_request ** taxorders) max = INT_MAX; } if (!playerrace(u_race(u))) { - u->wants = MIN(income(u), max); + u->wants = income(u); } else { - u->wants = MIN(n * effskill(u, SK_TAXING, 0) * taxperlevel, max); + u->wants = n * effskill(u, SK_TAXING, 0) * taxperlevel; } + if (u->wants > max) u->wants = max; u2 = is_guarded(r, u); if (u2) { @@ -2682,12 +2693,16 @@ void loot_cmd(unit * u, struct order *ord, econ_request ** lootorders) max = INT_MAX; } if (!playerrace(u_race(u))) { - u->wants = MIN(income(u), max); + u->wants = income(u); + if (u->wants > max) u->wants = max; } else { /* For player start with 20 Silver +10 every 5 level of close combat skill*/ - int skbonus = (MAX(effskill(u, SK_MELEE, 0), effskill(u, SK_SPEAR, 0)) * 2 / 10) + 2; - u->wants = MIN(n * skbonus * 10, max); + int skm = effskill(u, SK_MELEE, 0); + int sks = effskill(u, SK_SPEAR, 0); + int skbonus = ((skm > sks ? skm : sks) * 2 / 10) + 2; + u->wants = n * skbonus * 10; + if (u->wants > max) u->wants = max; } o = (econ_request *)calloc(1, sizeof(econ_request)); diff --git a/src/spells.c b/src/spells.c index 68553efaf..953b90533 100644 --- a/src/spells.c +++ b/src/spells.c @@ -11,7 +11,9 @@ * This program may not be used, modified or distributed without * prior permission by the authors of Eressea. */ +#ifdef _MSC_VER #include +#endif #include #include "guard.h" @@ -149,7 +151,7 @@ static void magicanalyse_region(region * r, unit * mage, double force) * mehr als 100% probability und damit immer ein Erfolg. */ probability = curse_chance(c, force); mon = c->duration + (rng_int() % 10) - 5; - mon = MAX(1, mon); + if (mon < 1) mon = 1; found = true; if (chance(probability)) { /* Analyse geglueckt */ @@ -190,7 +192,7 @@ static void magicanalyse_unit(unit * u, unit * mage, double force) * mehr als 100% probability und damit immer ein Erfolg. */ probability = curse_chance(c, force); mon = c->duration + (rng_int() % 10) - 5; - mon = MAX(1, mon); + if (mon < 1) mon = 1; if (chance(probability)) { /* Analyse geglueckt */ if (c_flags(c) & CURSE_NOAGE) { @@ -231,7 +233,7 @@ static void magicanalyse_building(building * b, unit * mage, double force) * mehr als 100% probability und damit immer ein Erfolg. */ probability = curse_chance(c, force); mon = c->duration + (rng_int() % 10) - 5; - mon = MAX(1, mon); + if (mon < 1) mon = 1; if (chance(probability)) { /* Analyse geglueckt */ if (c_flags(c) & CURSE_NOAGE) { @@ -272,7 +274,7 @@ static void magicanalyse_ship(ship * sh, unit * mage, double force) * mehr als 100% probability und damit immer ein Erfolg. */ probability = curse_chance(c, force); mon = c->duration + (rng_int() % 10) - 5; - mon = MAX(1, mon); + if (mon < 1) mon = 1; if (chance(probability)) { /* Analyse geglueckt */ if (c_flags(c) & CURSE_NOAGE) { @@ -701,7 +703,8 @@ static int sp_destroy_magic(castorder * co) "unit region command", mage, mage->region, co->order)); } - return MAX(succ, 1); + if (succ < 1) succ = 1; + return succ; } /* ------------------------------------------------------------- */ @@ -770,7 +773,9 @@ static int sp_transferaura(castorder * co) return 0; } - gain = MIN(aura, scm_src->spellpoints) / multi; + gain = scm_src->spellpoints; + if (gain > aura) gain = aura; + gain = gain / multi; scm_src->spellpoints -= gain * multi; scm_dst->spellpoints += gain; @@ -901,7 +906,7 @@ static int sp_summonent(castorder * co) double power = co->force; unit *u; attrib *a; - int ents; + int ents, p2; if (rtrees(r, 2) == 0) { cmistake(mage, co->order, 204, MSG_EVENT); @@ -909,7 +914,9 @@ static int sp_summonent(castorder * co) return 0; } - ents = MIN((int)(power * power), rtrees(r, 2)); + ents = rtrees(r, 2); + p2 = (int)(power * power); + if (ents > p2) ents = p2; u = create_unit(r, mage->faction, ents, get_race(RC_TREEMAN), 0, NULL, mage); @@ -1300,7 +1307,8 @@ static int sp_rosthauch(castorder * co) for (; iweapon != NULL; iweapon = iweapon->next) { item **ip = i_find(&u->items, iweapon->type); if (*ip) { - float chance = (float)MIN((*ip)->number, force); + float chance = (*ip)->number; + if (chance > force) chance = force; if (iweapon->chance < 1.0) { chance *= iweapon->chance; } @@ -1339,7 +1347,7 @@ static int sp_rosthauch(castorder * co) * unguenstigsten Fall kann pro Stufe nur eine Waffe verzaubert werden, * darum wird hier nur fuer alle Faelle in denen noch weniger Waffen * betroffen wurden ein Kostennachlass gegeben */ - return MIN(success, cast_level); + return (success < cast_level) ? success : cast_level; } /* ------------------------------------------------------------- */ @@ -1369,9 +1377,12 @@ static int sp_kaelteschutz(castorder * co) unit *mage = co->magician.u; int cast_level = co->level; double force = co->force; - int duration = MAX(cast_level, (int)force) + 1; - spellparameter *pa = co->par; double effect; + spellparameter *pa = co->par; + int duration = (int)force; + + if (duration < cast_level) duration = cast_level; + ++duration; force *= 10; /* 10 Personen pro Force-Punkt */ @@ -2132,8 +2143,8 @@ static int sp_drought(castorder * co) */ c = get_curse(r->attribs, &ct_drought); if (c) { - c->vigour = MAX(c->vigour, power); - c->duration = MAX(c->duration, (int)power); + c->vigour = fmax(c->vigour, power); + if (c->duration < (int)power) c->duration = (int)power; } else { double effect = 4.0; @@ -2317,7 +2328,6 @@ static int sp_stormwinds(castorder * co) */ static int sp_earthquake(castorder * co) { - int kaputt; region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; @@ -2330,8 +2340,9 @@ static int sp_earthquake(castorder * co) if (burg->size != 0 && !is_cursed(burg->attribs, &ct_magicwalls)) { /* Magieresistenz */ if (!target_resists_magic(mage, burg, TYP_BUILDING, 0)) { - kaputt = MIN(10 * cast_level, burg->size / 4); - kaputt = MAX(kaputt, 1); + int kaputt = burg->size / 4; + if (kaputt > 10 * cast_level) kaputt = 10 * cast_level; + if (kaputt < 1) kaputt = 1; burg->size -= kaputt; if (burg->size == 0) { /* TODO: sollten die Insassen nicht Schaden nehmen? */ @@ -2507,7 +2518,6 @@ static int sp_forest_fire(castorder * co) static int sp_fumblecurse(castorder * co) { unit *target; - int rx, sx; int duration; unit *mage = co->magician.u; int cast_level = co->level; @@ -2522,9 +2532,12 @@ static int sp_fumblecurse(castorder * co) target = pa->param[0]->data.u; - rx = rng_int() % 3; - sx = cast_level - effskill(target, SK_MAGIC, 0); - duration = MAX(sx, rx) + 1; + duration = cast_level - effskill(target, SK_MAGIC, 0); + if (duration < 2) { + int rx = rng_int() % 3; + if (duration < rx) duration = rx; + } + ++duration; effect = force / 2; c = create_curse(mage, &target->attribs, &ct_fumble, @@ -2690,8 +2703,9 @@ static int sp_firewall(castorder * co) } else { fd = (wall_data *)b->data.v; - fd->force = (int)MAX(fd->force, force / 2 + 0.5); - fd->countdown = MAX(fd->countdown, cast_level + 1); + fd->force = (int)fmax(fd->force, force / 2 + 0.5); + if (fd->countdown < cast_level + 1) + fd->countdown = cast_level + 1; } /* melden, 1x pro Partei */ @@ -3271,7 +3285,7 @@ static void skill_summoned(unit * u, int level) */ static int sp_summonundead(castorder * co) { - int undead; + int undead, dc; unit *u; region *r = co_get_region(co); unit *mage = co->magician.u; @@ -3285,7 +3299,9 @@ static int sp_summonundead(castorder * co) return 0; } - undead = MIN(deathcount(r), 2 + lovar(force)); + undead = 2 + lovar(force); + dc = deathcount(r); + if (undead > dc) undead = dc; if (cast_level <= 8) { race = get_race(RC_SKELETON); @@ -3333,7 +3349,7 @@ static int sp_auraleak(castorder * co) int cast_level = co->level; message *msg; - lost = MIN(0.95, cast_level * 0.05); + lost = fmin(0.95, cast_level * 0.05); for (u = r->units; u; u = u->next) { if (is_mage(u)) { @@ -3707,17 +3723,17 @@ static int sp_raisepeasantmob(castorder * co) int anteil; region *r = co_get_region(co); unit *mage = co->magician.u; - int cast_level = co->level; + int rp, cast_level = co->level; double force = co->force; int duration = (int)force + 1; faction *monsters = get_monsters(); message *msg; anteil = 6 + (rng_int() % 4); - - n = rpeasants(r) * anteil / 10; - n = MAX(0, n); - n = MIN(n, rpeasants(r)); + rp = rpeasants(r); + n = rp * anteil / 10; + if (n < 0) n = 0; + if (n > rp) n = rp; if (n <= 0) { report_failure(mage, co->order); @@ -3956,13 +3972,13 @@ static int sp_recruit(castorder * co) n = (pow(force, 1.6) * 100) / f->race->recruitcost; if (rc->recruit_multi > 0) { double multp = (double)maxp / rc->recruit_multi; - n = MIN(multp, n); - n = MAX(n, 1); + n = fmin(multp, n); + n = fmax(n, 1); rsetpeasants(r, maxp - (int)(n * rc->recruit_multi)); } else { - n = MIN(maxp, n); - n = MAX(n, 1); + n = fmin(maxp, n); + n = fmax(n, 1); rsetpeasants(r, maxp - (int)n); } @@ -4007,18 +4023,17 @@ static int sp_bigrecruit(castorder * co) n = (int)force + lovar((force * force * 1000) / (float)f->race->recruitcost); if (f->race == get_race(RC_ORC)) { - n = MIN(2 * maxp, n); - n = MAX(n, 1); + if (n > 2 * maxp) n = 2 * maxp; + if (n < 1) n = 1; rsetpeasants(r, maxp - (n + 1) / 2); } else { - n = MIN(maxp, n); - n = MAX(n, 1); + if (n > maxp) n = maxp; + if (n < 1) n = 1; rsetpeasants(r, maxp - n); } - u = - create_unit(r, f, n, f->race, 0, LOC(f->locale, + u = create_unit(r, f, n, f->race, 0, LOC(f->locale, (n == 1 ? "peasant" : "peasant_p")), mage); set_order(&u->thisorder, default_order(f->locale)); @@ -4133,9 +4148,9 @@ static int sp_seduce(castorder * co) item *itm = *itmp; int loot; if (itm->type->rtype == rsilver) { - loot = - MIN(cast_level * 1000, get_money(target) - (maintenance_cost(target))); - loot = MAX(loot, 0); + loot = get_money(target) - maintenance_cost(target); + if (loot > cast_level * 1000) loot = cast_level * 1000; + if (loot < 0) loot = 0; } else { loot = itm->number / 2; @@ -4143,7 +4158,7 @@ static int sp_seduce(castorder * co) loot += rng_int() % 2; } if (loot > 0) { - loot = MIN(loot, (int)(force * 5)); + if (loot > 5 * force) loot = 5 * force; } } if (loot > 0) { @@ -4260,7 +4275,9 @@ static int sp_headache(castorder * co) } if (smax != NULL) { /* wirkt auf maximal 10 Personen */ - unsigned int change = MIN(10, target->number) * (rng_uint() % 2 + 1) / target->number; + int change = target->number; + if (change > 10) change = 10; + change *= (rng_uint() % 2 + 1) / target->number; reduce_skill(target, smax, change); } set_order(&target->thisorder, NULL); @@ -4295,17 +4312,18 @@ static int sp_raisepeasants(castorder * co) attrib *a; region *r = co_get_region(co); unit *mage = co->magician.u; - int cast_level = co->level; + int rp = rpeasants(r), cast_level = co->level; double power = co->force; message *msg; - if (rpeasants(r) == 0) { + if (rp == 0) { ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, "error_nopeasants", "")); return 0; } - bauern = MIN(rpeasants(r), (int)(power * 250)); - rsetpeasants(r, rpeasants(r) - bauern); + bauern = (int)(power * 250); + if (bauern > rp) bauern = rp; + rsetpeasants(r, rp - bauern); u2 = create_unit(r, mage->faction, bauern, get_race(RC_PEASANT), 0, @@ -4387,7 +4405,7 @@ int sp_puttorest(castorder * co) message *seen = msg_message("puttorest", "mage", mage); message *unseen = msg_message("puttorest", "mage", NULL); - laid_to_rest = MAX(laid_to_rest, dead); + if (laid_to_rest < dead) laid_to_rest = dead; deathcounts(r, -laid_to_rest); @@ -4567,7 +4585,7 @@ static int sp_gbdreams(castorder * co, int effect) /* wirkt erst in der Folgerunde, soll mindestens eine Runde wirken, * also duration+2 */ - duration = (int)MAX(1, power / 2); /* Stufe 1 macht sonst mist */ + duration = (int)fmax(1, power / 2); /* Stufe 1 macht sonst mist */ duration = 2 + rng_int() % duration; /* Nichts machen als ein entsprechendes Attribut in die Region legen. */ @@ -4739,7 +4757,8 @@ int sp_sweetdreams(castorder * co) cmistake(mage, co->order, 40, MSG_EVENT); continue; } - men = MIN(opfer, u->number); + men = u->number; + if (men > opfer) men = opfer; opfer -= men; /* Nichts machen als ein entsprechendes Attribut an die Einheit legen. */ @@ -4852,7 +4871,7 @@ int sp_itemcloak(castorder * co) spellparameter *pa = co->par; int cast_level = co->level; double power = co->force; - int duration = (int)MAX(2.0, power + 1); /* works in the report, and ageing this round would kill it if it's <=1 */ + int duration = (int)fmax(2.0, power + 1); /* works in the report, and ageing this round would kill it if it's <=1 */ /* wenn kein Ziel gefunden, Zauber abbrechen */ if (pa->param[0]->flag == TARGET_NOTFOUND) @@ -4910,7 +4929,8 @@ int sp_resist_magic_bonus(castorder * co) u = pa->param[n]->data.u; - m = MIN(u->number, victims); + m = u->number; + if (m > victims) m = victims; victims -= m; create_curse(mage, &u->attribs, &ct_magicresistance, @@ -4926,8 +4946,10 @@ int sp_resist_magic_bonus(castorder * co) msg_release(msg); } - cast_level = MIN(cast_level, (int)(cast_level * (victims + 4) / maxvictims)); - return MAX(cast_level, 1); + m = (int)(cast_level * (victims + 4) / maxvictims); + if (m > cast_level) m = cast_level; + if (m < 1) m = 1; + return m; } /** spell 'Astraler Weg'. @@ -5754,7 +5776,7 @@ static int sp_eternizewall(castorder * co) */ int sp_permtransfer(castorder * co) { - int aura; + int aura, i; unit *tu; unit *mage = co->magician.u; int cast_level = co->level; @@ -5781,7 +5803,8 @@ int sp_permtransfer(castorder * co) return 0; } - aura = MIN(get_spellpoints(mage) - spellcost(mage, sp), aura); + i = get_spellpoints(mage) - spellcost(mage, sp); + if (aura > i) aura = i; change_maxspellpoints(mage, -aura); change_spellpoints(mage, -aura); @@ -6090,7 +6113,8 @@ int sp_speed2(castorder * co) spellparameter *pa = co->par; maxmen = 2 * cast_level * cast_level; - dur = MAX(1, cast_level / 2); + dur = cast_level / 2; + if (dur < 1) dur = 1; for (n = 0; n < pa->length; n++) { double effect; @@ -6104,7 +6128,7 @@ int sp_speed2(castorder * co) u = pa->param[n]->data.u; - men = MIN(maxmen, u->number); + men = (maxmen <= u->number) ? maxmen : u->number; effect = 2; create_curse(mage, &u->attribs, &ct_speed, force, dur, effect, men); maxmen -= men; @@ -6115,7 +6139,8 @@ int sp_speed2(castorder * co) "unit region amount", mage, mage->region, used)); /* Effektiv benoetigten cast_level (mindestens 1) zurueckgeben */ used = (int)sqrt(used / 2); - return MAX(1, used); + if (used < 1) used = 1; + return used; } /* ------------------------------------------------------------- */ diff --git a/src/spy.c b/src/spy.c index de25f46e2..999be57aa 100644 --- a/src/spy.c +++ b/src/spy.c @@ -16,7 +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 "spy.h" #include "guard.h" #include "laws.h" @@ -52,6 +54,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* libc includes */ #include #include +#include #include #include #include @@ -146,7 +149,7 @@ int spy_cmd(unit * u, struct order *ord) * Fuer jeden Talentpunkt, den das Spionagetalent das Tarnungstalent * des Opfers uebersteigt, erhoeht sich dieses um 5%*/ spy = effskill(u, SK_SPY, 0) - effskill(target, SK_STEALTH, r); - spychance = 0.1 + MAX(spy * 0.05, 0.0); + spychance = 0.1 + fmax(spy * 0.05, 0.0); if (chance(spychance)) { produceexp(u, SK_SPY, u->number); @@ -162,7 +165,7 @@ int spy_cmd(unit * u, struct order *ord) - (effskill(u, SK_STEALTH, 0) + effskill(u, SK_SPY, 0) / 2); if (invisible(u, target) >= u->number) { - observe = MIN(observe, 0); + if (observe > 0) observe = 0; } /* Anschliessend wird - unabhaengig vom Erfolg - gewuerfelt, ob der @@ -344,7 +347,7 @@ static int top_skill(region * r, faction * f, ship * sh, skill_t sk) for (u = r->units; u; u = u->next) { if (u->ship == sh && u->faction == f) { int s = effskill(u, sk, 0); - value = MAX(s, value); + if (value < s) value = s; } } return value; diff --git a/src/steal.c b/src/steal.c index 250681598..cd2aa9c26 100644 --- a/src/steal.c +++ b/src/steal.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 "economy.h" @@ -80,7 +82,8 @@ void expandstealing(region * r, econ_request * stealorders) n = 10; } if (n > 0) { - n = MIN(n, requests[j].unit->wants); + int w = requests[j].unit->wants; + if (n > w) n = w; use_pooled(u, rsilver, GET_ALL, n); requests[j].unit->n = n; change_money(requests[j].unit, n); @@ -217,7 +220,8 @@ void steal_cmd(unit * u, struct order *ord, econ_request ** stealorders) } } - i = MIN(u->number, i_get(u->items, rring->itype)); + i = i_get(u->items, rring->itype); + if (i > u->number) i = u->number; if (i > 0) { n *= STEALINCOME * (u->number + i * (roqf_factor() - 1)); } @@ -239,6 +243,6 @@ void steal_cmd(unit * u, struct order *ord, econ_request ** stealorders) *stealorders = o; /* Nur soviel PRODUCEEXP wie auch tatsaechlich gemacht wurde */ - - produceexp(u, SK_STEALTH, MIN(n, u->number)); + if (n > u->number) n = u->number; + produceexp(u, SK_STEALTH, n); } diff --git a/src/study.c b/src/study.c index cde89dadf..42e602087 100644 --- a/src/study.c +++ b/src/study.c @@ -16,7 +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 #include "study.h" #include "laws.h" @@ -613,7 +615,8 @@ int study_cmd(unit * u, order * ord) } /* Akademie: */ if (active_building(u, bt_find("academy"))) { - studycost = MAX(50, studycost * 2); + studycost = studycost * 2; + if (studycost < 50) studycost = 50; } if (sk == SK_MAGIC) { @@ -721,12 +724,14 @@ int study_cmd(unit * u, order * ord) } if (get_effect(u, oldpotiontype[P_WISE])) { - l = MIN(u->number, get_effect(u, oldpotiontype[P_WISE])); + l = get_effect(u, oldpotiontype[P_WISE]); + if (l > u->number) l = u->number; teach->days += l * EXPERIENCEDAYS; change_effect(u, oldpotiontype[P_WISE], -l); } if (get_effect(u, oldpotiontype[P_FOOL])) { - l = MIN(u->number, get_effect(u, oldpotiontype[P_FOOL])); + l = get_effect(u, oldpotiontype[P_FOOL]); + if (l > u->number) l = u->number; teach->days -= l * STUDYDAYS; change_effect(u, oldpotiontype[P_FOOL], -l); } diff --git a/src/summary.c b/src/summary.c index 001d5ce28..160346ba2 100644 --- a/src/summary.c +++ b/src/summary.c @@ -8,8 +8,9 @@ * */ -/* wenn platform.h nicht vor curses included wird, kompiliert es unter windows nicht */ +#ifdef _MSC_VER #include +#endif #include #include "summary.h" @@ -97,8 +98,8 @@ int update_nmrs(void) if (timeout>0) { if (nmr < 0 || nmr > timeout) { log_error("faction %s has %d NMR", itoa36(f->no), nmr); - nmr = MAX(0, nmr); - nmr = MIN(nmr, timeout); + if (nmr < 0) nmr = 0; + if (nmr > timeout) nmr = timeout; } if (nmr > 0) { log_debug("faction %s has %d NMR", itoa36(f->no), nmr); diff --git a/src/upkeep.c b/src/upkeep.c index 846e2f4f0..3bd77710e 100644 --- a/src/upkeep.c +++ b/src/upkeep.c @@ -1,4 +1,4 @@ -#ifdef WIN32 +#ifdef _MSC_VER #include #endif #include "upkeep.h" From 07b25fbed1e22b1161dcab4437e9d2f1cd01c8c8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 30 Dec 2017 11:09:09 +0100 Subject: [PATCH 4/4] missing include, thanks mac --- src/util/log.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/log.c b/src/util/log.c index 5d95d0ea7..2a7e41831 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -11,6 +11,8 @@ without prior permission by the authors of Eressea. */ #include #include "log.h" + +#include "bsdstring.h" #include "unicode.h" #include