move va_copy macro closer to where it is used.

This commit is contained in:
Enno Rehling 2017-12-29 17:00:16 +01:00
parent c3a812123f
commit 095148ab50
7 changed files with 100 additions and 73 deletions

View file

@ -50,12 +50,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
void herbsearch(unit * u, int max) void herbsearch(unit * u, int max_take)
{ {
region * r = u->region; region * r = u->region;
int herbsfound; int herbsfound;
const item_type *whichherb; const item_type *whichherb;
int effsk = effskill(u, SK_HERBALISM, 0); int effsk = effskill(u, SK_HERBALISM, 0);
int herbs = rherbs(r);
if (effsk == 0) { if (effsk == 0) {
cmistake(u, u->thisorder, 59, MSG_PRODUCE); cmistake(u, u->thisorder, 59, MSG_PRODUCE);
@ -73,14 +74,13 @@ void herbsearch(unit * u, int max)
return; return;
} }
if (max) if (max_take < herbs) {
max = MIN(max, rherbs(r)); herbs = max_take;
else }
max = rherbs(r);
herbsfound = ntimespprob(effsk * u->number, herbsfound = ntimespprob(effsk * u->number,
(double)rherbs(r) / 100.0F, -0.01F); (double)rherbs(r) / 100.0F, -0.01F);
if (herbsfound > max) herbsfound = max; if (herbsfound > herbs) herbsfound = herbs;
rsetherbs(r, (short) (rherbs(r) - herbsfound)); rsetherbs(r, (short) (rherbs(r) - herbsfound));
if (herbsfound) { if (herbsfound) {
@ -175,13 +175,13 @@ static int potion_luck(unit *u, region *r, attrib_type *atype, int amount) {
} }
static int potion_power(unit *u, int amount) { static int potion_power(unit *u, int amount) {
int use = u->number / 10; int hp = 10 * amount;
if (use < amount) {
if (u->number % 10 > 0) ++use; if (hp > u->number) {
amount = use; hp = u->number;
amount = (hp + 9) % 10;
} }
/* Verf<72>nffacht die HP von max. 10 Personen in der Einheit */ u->hp += hp * unit_max_hp(u) * 4;
u->hp += MIN(u->number, 10 * amount) * unit_max_hp(u) * 4;
return amount; return amount;
} }

View file

@ -680,7 +680,7 @@ static int CavalryBonus(const unit * u, troop enemy, int type)
/* only half against trolls */ /* only half against trolls */
if (skl > 0) { if (skl > 0) {
if (type == BONUS_SKILL) { if (type == BONUS_SKILL) {
int dmg = MIN(skl, 8); int dmg = (skl < 8) ? skl : 8;
if (u_race(enemy.fighter->unit) == get_race(RC_TROLL)) { if (u_race(enemy.fighter->unit) == get_race(RC_TROLL)) {
dmg = dmg / 4; dmg = dmg / 4;
} }
@ -691,7 +691,8 @@ static int CavalryBonus(const unit * u, troop enemy, int type)
} }
else { else {
skl = skl / 2; skl = skl / 2;
return MIN(skl, 4); if (skl > 4) skl = 4;
return skl;
} }
} }
} }
@ -985,8 +986,10 @@ static void vampirism(troop at, int damage)
++gain; ++gain;
if (gain > 0) { if (gain > 0) {
int maxhp = unit_max_hp(at.fighter->unit); int maxhp = unit_max_hp(at.fighter->unit);
at.fighter->person[at.index].hp =
MIN(gain + at.fighter->person[at.index].hp, maxhp); gain += at.fighter->person[at.index].hp;
if (maxhp > gain) maxhp = gain;
at.fighter->person[at.index].hp = maxhp;
} }
} }
} }
@ -1197,8 +1200,8 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile)
double kritchance = (sk * 3 - sd) / 200.0; double kritchance = (sk * 3 - sd) / 200.0;
int maxk = 4; int maxk = 4;
kritchance = MAX(kritchance, 0.005); kritchance = fmax(kritchance, 0.005);
kritchance = MIN(0.9, kritchance); kritchance = fmin(0.9, kritchance);
while (maxk-- && chance(kritchance)) { while (maxk-- && chance(kritchance)) {
da += dice_rand(damage); da += dice_rand(damage);
@ -1733,8 +1736,9 @@ void do_combatmagic(battle * b, combatmagic_t was)
} }
level = eff_spelllevel(mage, sp, level, 1); level = eff_spelllevel(mage, sp, level, 1);
if (sl > 0) if (sl > 0 && sl < level) {
level = MIN(sl, level); level = sl;
}
if (level < 0) { if (level < 0) {
report_failed_spell(b, mage, sp); report_failed_spell(b, mage, sp);
free_order(ord); free_order(ord);
@ -1814,8 +1818,10 @@ static void do_combatspell(troop at)
} }
level = eff_spelllevel(caster, sp, fi->magic, 1); level = eff_spelllevel(caster, sp, fi->magic, 1);
if ((sl = get_combatspelllevel(caster, 1)) > 0) sl = get_combatspelllevel(caster, 1);
level = MIN(level, sl); if (sl > 0 && sl < level) {
level = sl;
}
if (fumble(r, caster, sp, level)) { if (fumble(r, caster, sp, level)) {
report_failed_spell(b, caster, sp); report_failed_spell(b, caster, sp);
@ -2333,14 +2339,15 @@ double fleechance(unit * u)
if (u_race(u) == get_race(RC_HALFLING)) { if (u_race(u) == get_race(RC_HALFLING)) {
c += 0.20; c += 0.20;
c = MIN(c, 0.90); c = fmin(c, 0.90);
} }
else { else {
c = MIN(c, 0.75); c = fmin(c, 0.75);
} }
if (a != NULL) if (a) {
c += a->data.flt; c += a->data.flt;
}
return c; return c;
} }
@ -2461,7 +2468,7 @@ static void loot_items(fighter * corpse)
float lootfactor = (float)dead / (float)u->number; /* only loot the dead! */ float lootfactor = (float)dead / (float)u->number; /* only loot the dead! */
int maxloot = (int)((float)itm->number * lootfactor); int maxloot = (int)((float)itm->number * lootfactor);
if (maxloot > 0) { if (maxloot > 0) {
int i = MIN(10, maxloot); int i = (maxloot > 10) ? 10 : maxloot;
for (; i != 0; --i) { for (; i != 0; --i) {
int loot = maxloot / i; int loot = maxloot / i;
@ -2541,12 +2548,18 @@ static double PopulationDamage(void)
static void battle_effects(battle * b, int dead_players) static void battle_effects(battle * b, int dead_players)
{ {
region *r = b->region; region *r = b->region;
int dead_peasants = int rp = rpeasants(r);
MIN(rpeasants(r), (int)(dead_players * PopulationDamage()));
if (rp > 0) {
int dead_peasants = (int)(dead_players * PopulationDamage());
if (dead_peasants > rp) {
dead_peasants = rp;
}
if (dead_peasants) { if (dead_peasants) {
deathcounts(r, dead_peasants + dead_players); deathcounts(r, dead_peasants + dead_players);
add_chaoscount(r, dead_peasants / 2); add_chaoscount(r, dead_peasants / 2);
rsetpeasants(r, rpeasants(r) - dead_peasants); rsetpeasants(r, rp - dead_peasants);
}
} }
} }
@ -3174,7 +3187,8 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
/* change_effect wird in ageing gemacht */ /* change_effect wird in ageing gemacht */
/* Effekte von Artefakten */ /* Effekte von Artefakten */
strongmen = MIN(fig->unit->number, trollbelts(u)); strongmen = trollbelts(u);
if (strongmen > fig->unit->number) strongmen = fig->unit->number;
/* Hitpoints, Attack- und Defence-Boni f<>r alle Personen */ /* Hitpoints, Attack- und Defence-Boni f<>r alle Personen */
for (i = 0; i < fig->alive; i++) { for (i = 0; i < fig->alive; i++) {
@ -3946,7 +3960,8 @@ static void battle_flee(battle * b)
troop dt; troop dt;
int runners = 0; int runners = 0;
/* Flucht nicht bei mehr als 600 HP. Damit Wyrme t<>tbar bleiben. */ /* Flucht nicht bei mehr als 600 HP. Damit Wyrme t<>tbar bleiben. */
int runhp = MIN(600, (int)(0.9 + unit_max_hp(u) * hpflee(u->status))); int runhp = (int)(0.9 + unit_max_hp(u) * hpflee(u->status));
if (runhp > 600) runhp = 600;
if (u->ship && fval(u->region->terrain, SEA_REGION)) { if (u->ship && fval(u->region->terrain, SEA_REGION)) {
/* keine Flucht von Schiffen auf hoher See */ /* keine Flucht von Schiffen auf hoher See */
@ -3989,7 +4004,7 @@ static void battle_flee(battle * b)
if (fig->person[dt.index].flags & FL_PANICED) { if (fig->person[dt.index].flags & FL_PANICED) {
ispaniced = EFFECT_PANIC_SPELL; ispaniced = EFFECT_PANIC_SPELL;
} }
if (chance(MIN(fleechance(u) + ispaniced, 0.90))) { if (chance(fmin(fleechance(u) + ispaniced, 0.90))) {
++runners; ++runners;
flee(dt); flee(dt);
} }

View file

@ -16,8 +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>
#include <kernel/config.h> #endif
#include "build.h" #include "build.h"
#include "alchemy.h" #include "alchemy.h"
@ -34,6 +35,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/alliance.h> #include <kernel/alliance.h>
#include <kernel/connection.h> #include <kernel/connection.h>
#include <kernel/building.h> #include <kernel/building.h>
#include <kernel/config.h>
#include <kernel/curse.h> #include <kernel/curse.h>
#include <kernel/faction.h> #include <kernel/faction.h>
#include <kernel/group.h> #include <kernel/group.h>
@ -121,11 +123,12 @@ static void destroy_road(unit * u, int nmax, struct order *ord)
} }
road = rroad(r, d); road = rroad(r, d);
n = MIN(n, road); if (n > road) n = road;
if (n != 0) { if (n != 0) {
region *r2 = rconnect(r, d); region *r2 = rconnect(r, d);
int willdo = effskill(u, SK_ROAD_BUILDING, 0) * u->number; int willdo = effskill(u, SK_ROAD_BUILDING, 0) * u->number;
willdo = MIN(willdo, n); if (willdo > n) willdo = n;
if (willdo == 0) { if (willdo == 0) {
/* TODO: error message */ /* TODO: error message */
} }
@ -324,8 +327,9 @@ void build_road(unit * u, int size, direction_t d)
return; return;
} }
if (size > 0) if (size > 0 && left > size) {
left = MIN(size, left); left = size;
}
/* baumaximum anhand der rohstoffe */ /* baumaximum anhand der rohstoffe */
if (u_race(u) == get_race(RC_STONEGOLEM)) { if (u_race(u) == get_race(RC_STONEGOLEM)) {
n = u->number * GOLEM_STONE; n = u->number * GOLEM_STONE;
@ -337,7 +341,7 @@ void build_road(unit * u, int size, direction_t d)
return; return;
} }
} }
left = MIN(n, left); if (n < left) left = n;
/* n = maximum by skill. try to maximize it */ /* n = maximum by skill. try to maximize it */
n = u->number * effsk; n = u->number * effsk;
@ -345,7 +349,7 @@ void build_road(unit * u, int size, direction_t d)
const resource_type *ring = get_resourcetype(R_RING_OF_NIMBLEFINGER); const resource_type *ring = get_resourcetype(R_RING_OF_NIMBLEFINGER);
item *itm = ring ? *i_find(&u->items, ring->itype) : 0; item *itm = ring ? *i_find(&u->items, ring->itype) : 0;
if (itm != NULL && itm->number > 0) { if (itm != NULL && itm->number > 0) {
int rings = MIN(u->number, itm->number); int rings = (u->number < itm->number) ? u->number : itm->number;
n = n * ((roqf_factor() - 1) * rings + u->number) / u->number; n = n * ((roqf_factor() - 1) * rings + u->number) / u->number;
} }
} }
@ -353,15 +357,15 @@ void build_road(unit * u, int size, direction_t d)
int dm = get_effect(u, oldpotiontype[P_DOMORE]); int dm = get_effect(u, oldpotiontype[P_DOMORE]);
if (dm != 0) { if (dm != 0) {
int todo = (left - n + effsk - 1) / effsk; int todo = (left - n + effsk - 1) / effsk;
todo = MIN(todo, u->number); if (todo > u->number) todo = u->number;
dm = MIN(dm, todo); if (dm > todo) dm = todo;
change_effect(u, oldpotiontype[P_DOMORE], -dm); change_effect(u, oldpotiontype[P_DOMORE], -dm);
n += dm * effsk; n += dm * effsk;
} /* Auswirkung Schaffenstrunk */ } /* Auswirkung Schaffenstrunk */
} }
/* make minimum of possible and available: */ /* make minimum of possible and available: */
n = MIN(left, n); if (n > left) n = left;
/* n is now modified by several special effects, so we have to /* n is now modified by several special effects, so we have to
* minimize it again to make sure the road will not grow beyond * minimize it again to make sure the road will not grow beyond
@ -378,7 +382,7 @@ void build_road(unit * u, int size, direction_t d)
else { else {
use_pooled(u, get_resourcetype(R_STONE), GET_DEFAULT, n); use_pooled(u, get_resourcetype(R_STONE), GET_DEFAULT, n);
/* Nur soviel PRODUCEEXP wie auch tatsaechlich gemacht wurde */ /* Nur soviel PRODUCEEXP wie auch tatsaechlich gemacht wurde */
produceexp(u, SK_ROAD_BUILDING, MIN(n, u->number)); produceexp(u, SK_ROAD_BUILDING, (n < u->number) ? n : u->number);
} }
ADDMSG(&u->faction->msgs, msg_message("buildroad", ADDMSG(&u->faction->msgs, msg_message("buildroad",
"region unit size", r, u, n)); "region unit size", r, u, n));
@ -533,7 +537,7 @@ int build(unit * u, const construction * ctype, int completed, int want, int ski
if (dm != 0) { if (dm != 0) {
/* Auswirkung Schaffenstrunk */ /* Auswirkung Schaffenstrunk */
dm = MIN(dm, u->number); if (dm > u->number) dm = u->number;
change_effect(u, oldpotiontype[P_DOMORE], -dm); change_effect(u, oldpotiontype[P_DOMORE], -dm);
skills += dm * effsk; skills += dm * effsk;
} }
@ -592,7 +596,7 @@ int build(unit * u, const construction * ctype, int completed, int want, int ski
item *itm = ring ? *i_find(&u->items, ring->itype) : 0; item *itm = ring ? *i_find(&u->items, ring->itype) : 0;
int i = itm ? itm->number : 0; int i = itm ? itm->number : 0;
if (i > 0) { if (i > 0) {
int rings = MIN(u->number, i); int rings = (u->number < i) ? u->number : i;
n = n * ((roqf_factor() - 1) * rings + u->number) / u->number; n = n * ((roqf_factor() - 1) * rings + u->number) / u->number;
} }
} }
@ -600,7 +604,8 @@ int build(unit * u, const construction * ctype, int completed, int want, int ski
if (want < n) n = want; if (want < n) n = want;
if (con->maxsize > 0) { if (con->maxsize > 0) {
n = MIN(con->maxsize - completed, n); int req = con->maxsize - completed;
if (req < n) n = req;
if (con->improvement == NULL) { if (con->improvement == NULL) {
want = n; want = n;
} }
@ -623,7 +628,7 @@ int build(unit * u, const construction * ctype, int completed, int want, int ski
completed = completed + n; completed = completed + n;
} }
/* Nur soviel PRODUCEEXP wie auch tatsaechlich gemacht wurde */ /* Nur soviel PRODUCEEXP wie auch tatsaechlich gemacht wurde */
produceexp(u, ctype->skill, MIN(made, u->number)); produceexp(u, ctype->skill, (made < u->number) ? made : u->number);
return made; return made;
} }
@ -667,8 +672,10 @@ int maxbuild(const unit * u, const construction * cons)
if (have < need) { if (have < need) {
return 0; return 0;
} }
else else {
maximum = MIN(maximum, have / need); int b = have / need;
if (maximum > b) maximum = b;
}
} }
return maximum; return maximum;
} }
@ -877,7 +884,8 @@ static void build_ship(unit * u, ship * sh, int want)
} }
if (sh->damage && can) { if (sh->damage && can) {
int repair = MIN(sh->damage, can * DAMAGE_SCALE); int repair = can * DAMAGE_SCALE;
if (repair > sh->damage) repair = sh->damage;
n += repair / DAMAGE_SCALE; n += repair / DAMAGE_SCALE;
if (repair % DAMAGE_SCALE) if (repair % DAMAGE_SCALE)
++n; ++n;
@ -920,10 +928,9 @@ order * ord)
cmistake(u, ord, 88, MSG_PRODUCE); cmistake(u, ord, 88, MSG_PRODUCE);
return; return;
} }
if (want > 0) if (want <= 0 || want > msize) {
want = MIN(want, msize);
else
want = msize; want = msize;
}
sh = new_ship(newtype, r, u->faction->locale); sh = new_ship(newtype, r, u->faction->locale);
@ -979,10 +986,9 @@ void continue_ship(unit * u, int want)
cmistake(u, u->thisorder, 88, MSG_PRODUCE); cmistake(u, u->thisorder, 88, MSG_PRODUCE);
return; return;
} }
if (want > 0) if (want <= 0 || want > msize) {
want = MIN(want, msize);
else
want = msize; want = msize;
}
build_ship(u, sh, want); build_ship(u, sh, want);
} }

View file

@ -961,8 +961,8 @@ int build_island_e3(int x, int y, int minsize, newfaction ** players, int numfac
q = region_quality(r, rn); q = region_quality(r, rn);
if (q >= MIN_QUALITY && nfactions < numfactions && players && *players) { if (q >= MIN_QUALITY && nfactions < numfactions && players && *players) {
starting_region(players, r, rn); starting_region(players, r, rn);
minq = MIN(minq, q); if (minq > q) minq = q;
maxq = MAX(maxq, q); if (maxq < q) maxq = q;
++nfactions; ++nfactions;
} }
} }
@ -976,8 +976,8 @@ int build_island_e3(int x, int y, int minsize, newfaction ** players, int numfac
q = region_quality(r, rn); q = region_quality(r, rn);
if (q >= MIN_QUALITY * 4 / 3 && nfactions < numfactions && players && *players) { if (q >= MIN_QUALITY * 4 / 3 && nfactions < numfactions && players && *players) {
starting_region(players, r, rn); starting_region(players, r, rn);
minq = MIN(minq, q); if (minq > q) minq = q;
maxq = MAX(maxq, q); if (maxq < q) maxq = q;
++nfactions; ++nfactions;
} }
} }

View file

@ -19,11 +19,6 @@
/* @see https://insanecoding.blogspot.no/2007/11/pathmax-simply-isnt.html */ /* @see https://insanecoding.blogspot.no/2007/11/pathmax-simply-isnt.html */
#define PATH_MAX 260 #define PATH_MAX 260
#else /* assume gcc */
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
# define va_copy(a,b) __va_copy(a,b)
#endif
#endif #endif
#define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MIN(a, b) (((a) < (b)) ? (a) : (b))

View file

@ -16,10 +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.
**/ **/
#define TEACH_ALL 1 #ifdef _MSC_VER
#define TEACH_FRIENDS
#include <platform.h> #include <platform.h>
#endif
#include <kernel/config.h> #include <kernel/config.h>
#include "study.h" #include "study.h"
#include "laws.h" #include "laws.h"
@ -65,6 +64,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#define TEACH_ALL 1
#define TEACH_FRIENDS
static skill_t getskill(const struct locale *lang) static skill_t getskill(const struct locale *lang)
{ {
char token[128]; char token[128];

View file

@ -194,6 +194,16 @@ log_t *log_to_file(int flags, FILE *out) {
return log_create(flags, out, log_stdio); return log_create(flags, out, log_stdio);
} }
#ifdef _MSC_VER
/* https://social.msdn.microsoft.com/Forums/vstudio/en-US/53a4fd75-9f97-48b2-aa63-2e2e5a15efa3/stdcversion-problem?forum=vclanguage */
#define VA_COPY(c, a) va_copy(c, a)
#elif !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
/* GNU only: https://www.gnu.org/software/libc/manual/html_node/Argument-Macros.html */
#define VA_COPY(c, a) __va_copy(c, a)
#else
#define VA_COPY(c, a) va_copy(c, a)
#endif
static void log_write(int flags, const char *module, const char *format, va_list args) { static void log_write(int flags, const char *module, const char *format, va_list args) {
log_t *lg; log_t *lg;
for (lg = loggers; lg; lg = lg->next) { for (lg = loggers; lg; lg = lg->next) {
@ -205,8 +215,7 @@ static void log_write(int flags, const char *module, const char *format, va_list
} }
if (dupe == 0) { if (dupe == 0) {
va_list copy; va_list copy;
VA_COPY(copy, args);
va_copy(copy, args);
lg->log(lg->data, level, NULL, format, copy); lg->log(lg->data, level, NULL, format, copy);
va_end(copy); va_end(copy);
} }