stop using MIN and MAX macros

This commit is contained in:
Enno Rehling 2018-02-07 18:39:20 +01:00
parent 0884fb1f1b
commit 9ee84445eb
2 changed files with 56 additions and 36 deletions

View file

@ -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. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/ **/
#ifdef _MSC_VER
#include <platform.h> #include <platform.h>
#endif
#include <kernel/config.h> #include <kernel/config.h>
#include "building.h" #include "building.h"
@ -150,10 +152,11 @@ building_type *bt_get_or_create(const char *name)
int buildingcapacity(const building * b) int buildingcapacity(const building * b)
{ {
if (b->type->capacity >= 0) { if (b->type->capacity >= 0) {
if (b->type->maxcapacity >= 0) { int cap = b->size * b->type->capacity;
return MIN(b->type->maxcapacity, b->size * b->type->capacity); if (b->type->maxcapacity > 0 && b->type->maxcapacity < cap) {
cap = b->type->maxcapacity;
} }
return b->size * b->type->capacity; return cap;
} }
if (building_finished(b)) { if (building_finished(b)) {
if (b->type->maxcapacity >= 0) { if (b->type->maxcapacity >= 0) {
@ -313,9 +316,15 @@ int building_protection(const building_type * btype, int stage)
{ {
assert(btype->flags & BTF_FORTIFICATION); assert(btype->flags & BTF_FORTIFICATION);
if (btype->maxsize < 0) { if (btype->maxsize < 0) {
return castle_bonus[MIN(stage, 5)]; if (stage > 5) {
stage = 5;
}
return castle_bonus[stage];
} }
return watch_bonus[MIN(stage, 2)]; if (stage > 2) {
stage = 2;
}
return watch_bonus[stage];
} }
void write_building_reference(const struct building *b, struct storage *store) void write_building_reference(const struct building *b, struct storage *store)
@ -682,7 +691,7 @@ default_wage(const region * r, const faction * f, const race * rc, int in_turn)
{ {
building *b = largestbuilding(r, cmp_wage, false); building *b = largestbuilding(r, cmp_wage, false);
int esize = 0; int esize = 0;
double wage; int wage;
if (b != NULL) { if (b != NULL) {
/* TODO: this reveals imaginary castles */ /* TODO: this reveals imaginary castles */
@ -715,25 +724,27 @@ default_wage(const region * r, const faction * f, const race * rc, int in_turn)
if (r->attribs) { if (r->attribs) {
attrib *a; attrib *a;
curse *c; curse *c;
variant vm = frac_make(wage, 1);
/* Godcurse: Income -10 */ /* Godcurse: Income -10 */
c = get_curse(r->attribs, &ct_godcursezone); c = get_curse(r->attribs, &ct_godcursezone);
if (c && curse_active(c)) { if (c && curse_active(c)) {
wage = MAX(0, wage - 10); wage = (wage < 10) ? 0 : (wage - 10);
} }
/* Bei einer D<>rre verdient man nur noch ein Viertel */ /* Bei einer D<>rre verdient man nur noch ein Viertel */
c = get_curse(r->attribs, &ct_drought); c = get_curse(r->attribs, &ct_drought);
if (c && curse_active(c)) { if (c && curse_active(c)) {
wage /= curse_geteffect(c); vm = frac_mul(vm, frac_make(1, curse_geteffect_int(c)));
} }
a = a_find(r->attribs, &at_reduceproduction); a = a_find(r->attribs, &at_reduceproduction);
if (a) { if (a) {
wage = (wage * a->data.sa[0]) / 100; vm = frac_mul(vm, frac_make(a->data.sa[0], 100));
} }
wage = vm.sa[0] / vm.sa[1];
} }
return (int)wage; return wage;
} }
static int static int

View file

@ -9,7 +9,9 @@
This program may not be used, modified or distributed This program may not be used, modified or distributed
without prior permission by the authors of Eressea. without prior permission by the authors of Eressea.
*/ */
#ifdef _MSC_VER
#include <platform.h> #include <platform.h>
#endif
#include "combatspells.h" #include "combatspells.h"
#include <spells/buildingcurse.h> #include <spells/buildingcurse.h>
@ -45,6 +47,7 @@
/* libc includes */ /* libc includes */
#include <assert.h> #include <assert.h>
#include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -131,8 +134,7 @@ int damage_spell(struct castorder * co, int dmg, int strength)
enemies = count_enemies(b, fi, FIGHT_ROW, BEHIND_ROW - 1, SELECT_ADVANCE); enemies = count_enemies(b, fi, FIGHT_ROW, BEHIND_ROW - 1, SELECT_ADVANCE);
if (enemies == 0) { if (enemies == 0) {
message *m = m = msg_message("spell_out_of_range", "mage spell", fi->unit, sp);
msg_message("spell_out_of_range", "mage spell", fi->unit, sp);
message_all(b, m); message_all(b, m);
msg_release(m); msg_release(m);
return 0; return 0;
@ -171,8 +173,7 @@ int sp_petrify(struct castorder * co)
enemies = count_enemies(b, fi, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE); enemies = count_enemies(b, fi, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE);
if (!enemies) { if (!enemies) {
message *m = m = msg_message("spell_out_of_range", "mage spell", fi->unit, sp);
msg_message("spell_out_of_range", "mage spell", fi->unit, sp);
message_all(b, m); message_all(b, m);
msg_release(m); msg_release(m);
return 0; return 0;
@ -218,8 +219,7 @@ int sp_stun(struct castorder * co)
enemies = count_enemies(b, fi, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE); enemies = count_enemies(b, fi, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE);
if (!enemies) { if (!enemies) {
message *m = m = msg_message("spell_out_of_range", "mage spell", fi->unit, sp);
msg_message("spell_out_of_range", "mage spell", fi->unit, sp);
message_all(b, m); message_all(b, m);
msg_release(m); msg_release(m);
return 0; return 0;
@ -298,7 +298,8 @@ int sp_combatrosthauch(struct castorder * co)
for (w = 0; df->weapons[w].type != NULL; ++w) { for (w = 0; df->weapons[w].type != NULL; ++w) {
weapon *wp = df->weapons; weapon *wp = df->weapons;
int n = MIN(force, wp->used); int n = force;
if (n < wp->used) n = wp->used;
if (n) { if (n) {
requirement *mat = wp->type->itype->construction->materials; requirement *mat = wp->type->itype->construction->materials;
bool iron = false; bool iron = false;
@ -682,8 +683,7 @@ int sp_immolation(struct castorder * co)
force = 99999; force = 99999;
if (!count_enemies(b, fi, FIGHT_ROW, AVOID_ROW, SELECT_ADVANCE | SELECT_FIND)) { if (!count_enemies(b, fi, FIGHT_ROW, AVOID_ROW, SELECT_ADVANCE | SELECT_FIND)) {
message *m = m = msg_message("spell_out_of_range", "mage spell", fi->unit, sp);
msg_message("spell_out_of_range", "mage spell", fi->unit, sp);
message_all(b, m); message_all(b, m);
msg_release(m); msg_release(m);
return 0; return 0;
@ -791,7 +791,7 @@ int sp_shadowknights(struct castorder * co)
region *r = b->region; region *r = b->region;
unit *mage = fi->unit; unit *mage = fi->unit;
attrib *a; attrib *a;
int force = MAX(1, (int)get_force(power, 3)); int force = (int)fmax(1, get_force(power, 3));
message *msg; message *msg;
u = u =
@ -890,7 +890,6 @@ int sp_chaosrow(struct castorder * co)
continue; continue;
if (power <= 0.0) if (power <= 0.0)
break; break;
/* force sollte wegen des MAX(0,x) nicht unter 0 fallen k<>nnen */
if (is_magic_resistant(mage, df->unit, 0)) if (is_magic_resistant(mage, df->unit, 0))
continue; continue;
@ -925,7 +924,7 @@ int sp_chaosrow(struct castorder * co)
} }
k += df->alive; k += df->alive;
} }
power = MAX(0, power - n); power = fmax(0, power - n);
} }
selist_free(fgs); selist_free(fgs);
@ -1020,7 +1019,8 @@ int sp_hero(struct castorder * co)
message *m; message *m;
df_bonus = (int)(power / 5); df_bonus = (int)(power / 5);
force = MAX(1, lovar(get_force(power, 4))); force = lovar(get_force(power, 4));
if (force < 1) force = 1;
allies = allies =
count_allies(fi->side, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE, ALLY_ANY); count_allies(fi->side, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE, ALLY_ANY);
@ -1065,7 +1065,8 @@ int sp_berserk(struct castorder * co)
int targets = 0; int targets = 0;
message *m; message *m;
at_bonus = MAX(1, level / 3); at_bonus = level / 3;
if (at_bonus < 1) at_bonus = 1;
df_malus = 2; df_malus = 2;
force = (int)get_force(power, 2); force = (int)get_force(power, 2);
@ -1114,14 +1115,14 @@ int sp_frighten(struct castorder * co)
int targets = 0; int targets = 0;
message *m; message *m;
at_malus = MAX(1, level - 4); at_malus = level - 4;
if (at_malus < 1) at_malus = 1;
df_malus = 2; df_malus = 2;
force = (int)get_force(power, 2); force = (int)get_force(power, 2);
enemies = count_enemies(b, fi, FIGHT_ROW, BEHIND_ROW - 1, SELECT_ADVANCE); enemies = count_enemies(b, fi, FIGHT_ROW, BEHIND_ROW - 1, SELECT_ADVANCE);
if (!enemies) { if (!enemies) {
message *m = m = msg_message("spell_out_of_range", "mage spell", fi->unit, sp);
msg_message("spell_out_of_range", "mage spell", fi->unit, sp);
message_all(b, m); message_all(b, m);
msg_release(m); msg_release(m);
return 0; return 0;
@ -1170,8 +1171,7 @@ int sp_tiredsoldiers(struct castorder * co)
if (!count_enemies(b, fi, FIGHT_ROW, BEHIND_ROW, if (!count_enemies(b, fi, FIGHT_ROW, BEHIND_ROW,
SELECT_ADVANCE | SELECT_FIND)) { SELECT_ADVANCE | SELECT_FIND)) {
message *m = m = msg_message("spell_out_of_range", "mage spell", fi->unit, sp);
msg_message("spell_out_of_range", "mage spell", fi->unit, sp);
message_all(b, m); message_all(b, m);
msg_release(m); msg_release(m);
return 0; return 0;
@ -1367,7 +1367,8 @@ int sp_fumbleshield(struct castorder * co)
/* der erste Zauber schl<68>gt mit 100% fehl */ /* der erste Zauber schl<68>gt mit 100% fehl */
duration = 100; duration = 100;
effect = MAX(1, 25 - level); effect = 25 - level;
if (effect < 1) effect = 1;
do_meffect(fi, SHIELD_BLOCK, effect, duration); do_meffect(fi, SHIELD_BLOCK, effect, duration);
return level; return level;
@ -1403,7 +1404,7 @@ int sp_reanimate(struct castorder * co)
unit *mage = fi->unit; unit *mage = fi->unit;
int healable, j = 0; int healable, j = 0;
double c = 0.50 + 0.02 * power; double c = 0.50 + 0.02 * power;
double k = EFFECT_HEALING_SPELL * power; int k = (int)(EFFECT_HEALING_SPELL * power);
bool use_item = has_ao_healing(mage); bool use_item = has_ao_healing(mage);
message *msg; message *msg;
@ -1413,7 +1414,9 @@ int sp_reanimate(struct castorder * co)
} }
healable = count_healable(b, fi); healable = count_healable(b, fi);
healable = (int)MIN(k, healable); if (healable > k) {
healable = k;
}
while (healable--) { while (healable--) {
fighter *tf = select_corpse(b, fi); fighter *tf = select_corpse(b, fi);
if (tf != NULL && tf->side->casualties > 0 if (tf != NULL && tf->side->casualties > 0
@ -1466,7 +1469,7 @@ int sp_keeploot(struct castorder * co)
message_all(b, m); message_all(b, m);
msg_release(m); msg_release(m);
b->keeploot = (int)MAX(25, b->keeploot + 5 * power); b->keeploot = (int)fmax(25, b->keeploot + 5 * power);
return level; return level;
} }
@ -1497,10 +1500,14 @@ static int heal_fighters(selist * fgs, int *power, bool heal_monsters)
++wound; ++wound;
if (wound > 0 && wound < hp) { if (wound > 0 && wound < hp) {
int heal = MIN(healhp, wound); int heal = healhp;
if (heal > wound) {
heal = wound;
}
assert(heal >= 0); assert(heal >= 0);
df->person[n].hp += heal; df->person[n].hp += heal;
healhp = MAX(0, healhp - heal); healhp -= heal;
if (healhp < 0) healhp = 0;
++healed; ++healed;
if (healhp <= 0) if (healhp <= 0)
break; break;
@ -1653,7 +1660,9 @@ int sp_undeadhero(struct castorder * co)
} }
selist_free(fgs); selist_free(fgs);
level = MIN(level, undead); if (level > undead) {
level = undead;
}
if (undead == 0) { if (undead == 0) {
msg = msg =
msg_message("summonundead_effect_0", "mage region", mage, mage->region); msg_message("summonundead_effect_0", "mage region", mage, mage->region);