eliminate MAX/MIN macros completely

This commit is contained in:
Enno Rehling 2019-01-24 17:50:58 +01:00
parent 9b113c050e
commit 20e0e8400b
12 changed files with 82 additions and 82 deletions

View File

@ -27,7 +27,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "study.h"
void academy_teaching_bonus(struct unit *u, skill_t sk, int students) {
if (students && sk != NOSKILL) {
if (students > 0 && sk != NOSKILL) {
/* actually students * EXPERIENCEDAYS / MAX_STUDENTS */
learn_skill(u, sk, students);
}

View File

@ -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 <platform.h>
#endif
#include <kernel/config.h>
#include "battle.h"
#include "alchemy.h"
@ -436,7 +439,8 @@ static int get_row(const side * s, int row, const side * vs)
/* every entry in the size[] array means someone trying to defend us.
* 'retreat' is the number of rows falling.
*/
result = MAX(FIRST_ROW, row - retreat);
result = row - retreat;
if (result < FIRST_ROW) result = FIRST_ROW;
return result;
}
@ -587,50 +591,27 @@ weapon_skill(const weapon_type * wtype, const unit * u, bool attacking)
* are taken into account, e.g. no horses, magic, etc. */
{
int skill;
const race * rc = u_race(u);
if (wtype == NULL) {
skill = effskill(u, SK_WEAPONLESS, 0);
int def = attacking ? rc->at_default : rc->df_default;
if (skill <= 0) {
/* wenn kein waffenloser kampf, dann den rassen-defaultwert */
if (u_race(u) == get_race(RC_ORC)) {
if (rc == get_race(RC_ORC)) {
int sword = effskill(u, SK_MELEE, 0);
int spear = effskill(u, SK_SPEAR, 0);
skill = MAX(sword, spear) - 3;
skill = ((sword > spear) ? sword : spear) - 3;
}
}
if (def > skill) skill = def;
if (attacking) {
skill = MAX(skill, u_race(u)->at_default);
}
else {
skill = MAX(skill, u_race(u)->df_default);
}
}
else {
if (attacking) {
skill = u_race(u)->at_default;
}
else {
skill = u_race(u)->df_default;
}
}
}
else {
/* der rassen-defaultwert kann h<>her sein als der Talentwert von
* waffenloser kampf */
if (attacking) {
if (skill < u_race(u)->at_default)
skill = u_race(u)->at_default;
}
else {
if (skill < u_race(u)->df_default)
skill = u_race(u)->df_default;
}
}
if (attacking) {
skill += u_race(u)->at_bonus;
skill += rc->at_bonus;
if (fval(u->region->terrain, SEA_REGION) && u->ship)
skill += u->ship->type->at_bonus;
}
else {
skill += u_race(u)->df_bonus;
skill += rc->df_bonus;
if (fval(u->region->terrain, SEA_REGION) && u->ship)
skill += u->ship->type->df_bonus;
}
@ -642,10 +623,10 @@ weapon_skill(const weapon_type * wtype, const unit * u, bool attacking)
skill = effskill(u, wtype->skill, 0);
if (skill > 0) {
if (attacking) {
skill += u_race(u)->at_bonus;
skill += rc->at_bonus;
}
else {
skill += u_race(u)->df_bonus;
skill += rc->df_bonus;
}
}
if (attacking) {
@ -1282,7 +1263,8 @@ static int apply_magicshield(int reduced_damage, fighter *df,
}
/* gibt R<>stung +effect f<>r duration Treffer */
if (me->typ == SHIELD_ARMOR) {
reduced_damage = MAX(reduced_damage - me->effect, 0);
reduced_damage -= me->effect;
if (reduced_damage < 0) reduced_damage = 0;
me->duration--;
}
}
@ -1347,11 +1329,13 @@ terminate(troop dt, troop at, int type, const char *damage_formula, bool missile
/* Skilldifferenzbonus */
if (rule_damage & DAMAGE_SKILL_BONUS) {
damage += MAX(0, (attskill - defskill) / DAMAGE_QUOTIENT);
int b = (attskill - defskill) / DAMAGE_QUOTIENT;
if (b > 0) damage += b;
}
}
reduced_damage = MAX(damage - armor_value, 0);
reduced_damage = damage - armor_value;
if (reduced_damage < 0) reduced_damage = 0;
reduced_damage = apply_race_resistance(reduced_damage, df, awtype, magic);
reduced_damage = apply_magicshield(reduced_damage, df, awtype, b, magic);
@ -1500,7 +1484,8 @@ troop select_enemy(fighter * af, int minrow, int maxrow, int select)
minrow = FIGHT_ROW;
maxrow = BEHIND_ROW;
}
minrow = MAX(minrow, FIGHT_ROW);
if (minrow < FIGHT_ROW) minrow = FIGHT_ROW;
enemies = count_enemies(b, af, minrow, maxrow, select);
@ -1611,7 +1596,7 @@ static troop select_opponent(battle * b, troop at, int mindist, int maxdist)
dt = select_enemy(at.fighter, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE);
}
else {
mindist = MAX(mindist, FIGHT_ROW);
if (mindist < FIGHT_ROW) mindist = FIGHT_ROW;
dt = select_enemy(at.fighter, mindist, maxdist, SELECT_ADVANCE);
}
@ -2078,7 +2063,8 @@ void dazzle(battle * b, troop * td)
void damage_building(battle * b, building * bldg, int damage_abs)
{
assert(bldg);
bldg->size = MAX(1, bldg->size - damage_abs);
bldg->size -= damage_abs;
if (bldg->size < 1) bldg->size = 1;
/* Wenn Burg, dann gucken, ob die Leute alle noch in das Geb<65>ude passen. */
@ -3020,7 +3006,9 @@ static void print_stats(battle * b)
for (s = b->sides; s != b->sides + b->nsides; ++s) {
if (!selist_empty(s->leader.fighters)) {
b->max_tactics = MAX(b->max_tactics, s->leader.value);
if (s->leader.value > b->max_tactics) {
b->max_tactics = s->leader.value;
}
}
}
@ -3371,7 +3359,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
else
p_bonus += 3;
} while (rnd >= 97);
bonus = MAX(p_bonus, bonus);
if (p_bonus > bonus) p_bonus = bonus;
}
tactics += bonus;
}

View File

@ -75,8 +75,9 @@ use_manacrystal(struct unit *u, const struct item_type *itype, int amount,
}
msp = max_spellpoints_depr(u->region, u) / 2;
if (msp < 25) msp = 25;
for (i = 0; i != amount; ++i) {
sp += MAX(25, msp);
sp += msp;
change_spellpoints(u, sp);
}

View File

@ -60,7 +60,7 @@ group *new_group(faction * f, const char *name, int gid)
gp = &(*gp)->next;
*gp = g;
maxgid = MAX(gid, maxgid);
if (gid > maxgid) maxgid = gid;
g->name = str_strdup(name);
g->gid = gid;

View File

@ -10,7 +10,10 @@
without prior permission by the authors of Eressea.
*/
#ifdef _MSC_VER
#include <platform.h>
#endif
#include <kernel/config.h>
#include "order.h"
@ -398,6 +401,7 @@ order *parse_order(const char *s, const struct locale * lang)
}
if (kwd != NOKEYWORD) {
order *ord = (order *)malloc(sizeof(order));
if (ord == NULL) abort();
create_order_i(ord, kwd, sptr, persistent, noerror, lang);
return ord;
}

View File

@ -156,7 +156,7 @@ int set_resvalue(unit * u, const item_type * itype, int value)
}
int
get_pooled(const unit * u, const resource_type * rtype, unsigned int mode,
get_pooled(const unit * u, const resource_type * rtype, int mode,
int count)
{
const faction *f = u->faction;
@ -199,7 +199,7 @@ int count)
}
int
use_pooled(unit * u, const resource_type * rtype, unsigned int mode, int count)
use_pooled(unit * u, const resource_type * rtype, int mode, int count)
{
const faction *f = u->faction;
unit *v;

View File

@ -42,9 +42,9 @@ extern "C" {
#define GET_ALL (GET_SLACK|GET_RESERVE|GET_POOLED_SLACK|GET_POOLED_RESERVE|GET_POOLED_FORCE)
int get_pooled(const struct unit *u, const struct resource_type *res,
unsigned int mode, int count);
int mode, int count);
int use_pooled(struct unit *u, const struct resource_type *res,
unsigned int mode, int count);
int mode, int count);
/** use_pooled
* verbraucht 'count' Objekte der resource 'itm'
* unter zuhilfenahme des Pools der struct region und Aufbrauch des

View File

@ -448,7 +448,7 @@ unit *read_unit(gamedata *data)
set_number(u, number);
READ_INT(data->store, &n);
u->age = (short)n;
u->age = n;
READ_TOK(data->store, rname, sizeof(rname));
rc = rc_find(rname);
@ -775,7 +775,8 @@ static region *readregion(gamedata *data, int x, int y)
}
if (data->version >= REGIONOWNER_VERSION) {
READ_INT(data->store, &n);
region_set_morale(r, MAX(0, (short)n), -1);
if (n < 0) n = 0;
region_set_morale(r, n, -1);
read_owner(data, &r->land->ownership);
}
}

View File

@ -76,7 +76,8 @@ void morale_update(region *r) {
void morale_change(region *r, int value) {
int morale = region_get_morale(r);
if (morale > 0) {
morale = MAX(0, morale - value);
morale = morale - value;
if (morale < 0) morale = 0;
region_set_morale(r, morale, turn);
}
}

View File

@ -14,6 +14,3 @@
#pragma warning(disable: 4224) // formal parameter was previously defined as a type
#pragma warning(disable: 4214) // bit field types other than int
#endif
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) > (b)) ? (a) : (b))

View File

@ -22,7 +22,10 @@
/* util includes */
#include <util/rng.h>
#define age_chance(a,b,p) (MAX(0,a-b)*p)
static int age_chance(int a, int b, int p) {
int r = (a - b) * p;
return (r < 0) ? 0 : r;
}
#define DRAGONAGE 27
#define WYRMAGE 68

View File

@ -31,7 +31,10 @@
#define UNDEAD_BREAKUP 25 /* chance dafuer */
#define UNDEAD_BREAKUP_FRACTION (25+rng_int()%70) /* anteil der weg geht */
#define age_chance(a,b,p) (MAX(0,a-b)*p)
static int age_chance(int a, int b, int p) {
int r = (a - b) * p;
return (r < 0) ? 0 : r;
}
void make_undead_unit(unit * u)
{
@ -43,8 +46,9 @@ void make_undead_unit(unit * u)
void age_skeleton(unit * u)
{
if (is_monsters(u->faction) && rng_int() % 100 < age_chance(u->age, 27, 1)) {
int n = MAX(1, u->number / 2);
int n = u->number / 2;
double q = (double)u->hp / (double)(unit_max_hp(u) * u->number);
if (n < 1) n = 1;
u_setrace(u, get_race(RC_SKELETON_LORD));
u->irace = NULL;
scale_number(u, n);
@ -55,8 +59,9 @@ void age_skeleton(unit * u)
void age_zombie(unit * u)
{
if (is_monsters(u->faction) && rng_int() % 100 < age_chance(u->age, 27, 1)) {
int n = MAX(1, u->number / 2);
int n = u->number / 2;
double q = (double)u->hp / (double)(unit_max_hp(u) * u->number);
if (n < 1) n = 1;
u_setrace(u, get_race(RC_ZOMBIE_LORD));
u->irace = NULL;
scale_number(u, n);
@ -67,11 +72,11 @@ void age_zombie(unit * u)
void age_ghoul(unit * u)
{
if (is_monsters(u->faction) && rng_int() % 100 < age_chance(u->age, 27, 1)) {
int n = MAX(1, u->number / 2);
int n = u->number / 2;
double q = (double)u->hp / (double)(unit_max_hp(u) * u->number);
u_setrace(u, get_race(RC_GHOUL_LORD));
u->irace = NULL;
scale_number(u, n);
scale_number(u, (n > 0) ? n : 1);
u->hp = (int)(unit_max_hp(u) * u->number * q);
}
}