eliminate MIN and MAX macros

This commit is contained in:
Enno Rehling 2019-01-24 16:34:07 +01:00
parent 5a01ea14b6
commit 9b113c050e
6 changed files with 40 additions and 19 deletions

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.
**/
#include <platform.h>
#ifdef _MSC_VER
# include <platform.h>
#endif
#include "weapons.h"
#include "battle.h"
@ -106,7 +109,7 @@ int *casualties)
}
enemies = count_enemies(b, af, FIGHT_ROW, FIGHT_ROW, SELECT_ADVANCE);
enemies = MIN(enemies, CATAPULT_ATTACKS);
if (enemies > CATAPULT_ATTACKS) enemies = CATAPULT_ATTACKS;
if (enemies == 0) {
return true; /* allow further attacks */
}

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.
**/
#include <platform.h>
#ifdef _MSC_VER
# include <platform.h>
#endif
#include "region.h"
/* kernel includes */
@ -141,8 +144,11 @@ const char *regionname(const region * r, const faction * f)
int region_maxworkers(const region *r)
{
int size = max_production(r);
int treespace = (rtrees(r, 2) + rtrees(r, 1) / 2) * TREESIZE;
return MAX(size - treespace, MIN(size / 10, 200));
int treespace = size - (rtrees(r, 2) + rtrees(r, 1) / 2) * TREESIZE;
size /=10;
if (size > 200) size = 200;
if (treespace < size) treespace = size;
return treespace;
}
int deathcount(const region * r)
@ -400,7 +406,7 @@ koor_distance_wrap_xy(int x1, int y1, int x2, int y2, int width, int height)
int dx = x1 - x2;
int dy = y1 - y2;
int result, dist;
int mindist = MIN(width, height) >> 1;
int mindist = ((width > height) ? height : width) / 2;
/* Bei negativem dy am Ursprung spiegeln, das veraendert
* den Abstand nicht
@ -423,13 +429,15 @@ koor_distance_wrap_xy(int x1, int y1, int x2, int y2, int width, int height)
if (result <= mindist)
return result;
}
dist = MAX(dx, height - dy);
dist = height - dy;
if (dist < dx) dist = dx;
if (dist >= 0 && dist < result) {
result = dist;
if (result <= mindist)
return result;
}
dist = MAX(width - dx, dy);
dist = width - dx;
if (dist < dy) dist = dy;
if (dist >= 0 && dist < result)
result = dist;
return result;
@ -1097,7 +1105,8 @@ void init_region(region *r)
if (!fval(r, RF_CHAOTIC)) {
int peasants;
peasants = (region_maxworkers(r) * (20 + dice(6, 10))) / 100;
rsetpeasants(r, MAX(100, peasants));
if (peasants < 100) peasants = 100;
rsetpeasants(r, peasants);
rsetmoney(r, rpeasants(r) * ((wage(r, NULL, NULL,
INT_MAX) + 1) + rng_int() % 5));
}
@ -1419,7 +1428,8 @@ faction *update_owners(region * r)
else if (f || new_owner->faction != region_get_last_owner(r)) {
alliance *al = region_get_alliance(r);
if (al && new_owner->faction->alliance == al) {
int morale = MAX(0, region_get_morale(r) - MORALE_TRANSFER);
int morale = region_get_morale(r) - MORALE_TRANSFER;
if (morale < 0) morale = 0;
region_set_morale(r, morale, turn);
}
else {

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.
**/
#include <platform.h>
#ifdef _MSC_VER
# include <platform.h>
#endif
#include <kernel/config.h>
#include "ship.h"
@ -359,8 +361,9 @@ int shipspeed(const ship * sh, const unit * u)
int crew = crew_skill(sh);
int crew_bonus = (crew / sh->type->sumskill / 2) - 1;
if (crew_bonus > 0) {
bonus = MIN(bonus, crew_bonus);
bonus = MIN(bonus, sh->type->range_max - sh->type->range);
int sbonus = sh->type->range_max - sh->type->range;
if (bonus > sbonus) bonus = sbonus;
if (bonus > crew_bonus) bonus = crew_bonus;
}
else {
bonus = 0;

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.
**/
#include <platform.h>
#ifdef _MSC_VER
# include <platform.h>
#endif
#include <kernel/config.h>
#include "unit.h"
@ -1229,7 +1231,7 @@ int invisible(const unit * target, const unit * viewer)
else {
int hidden = item_invis(target);
if (hidden) {
hidden = MIN(hidden, target->number);
if (hidden > target->number) hidden = target->number;
if (viewer) {
const resource_type *rtype = get_resourcetype(R_AMULET_OF_TRUE_SEEING);
hidden -= i_get(viewer->items, rtype->itype);

View File

@ -4089,7 +4089,7 @@ static int sp_pump(castorder * co)
* Betoert eine Einheit, so das sie ihm den groe<EFBFBD>ten Teil ihres Bargelds
* und 50% ihres Besitzes schenkt. Sie behaelt jedoch immer soviel, wie
* sie zum ueberleben braucht. Wirkt gegen Magieresistenz.
* MIN(Stufe*1000$, u->money - maintenance)
* min(Stufe*1000$, u->money - maintenance)
* Von jedem Item wird 50% abgerundet ermittelt und uebergeben. Dazu
* kommt Itemzahl%2 mit 50% chance
*

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.
**/
#include <platform.h>
#ifdef _MSC_VER
# include <platform.h>
#endif
#include "shock.h"
#include <magic.h>
@ -61,8 +64,8 @@ static void do_shock(unit * u, const char *reason)
if (u->number > 0) {
/* HP - Verlust */
int hp = (unit_max_hp(u) * u->number) / 10;
hp = MIN(u->hp, hp);
u->hp = MAX(1, hp);
if (hp > u->hp) hp = u->hp;
u->hp = (hp > 1) ? hp : 1;
}
/* Aura - Verlust */