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;
int herbsfound;
const item_type *whichherb;
int effsk = effskill(u, SK_HERBALISM, 0);
int herbs = rherbs(r);
if (effsk == 0) {
cmistake(u, u->thisorder, 59, MSG_PRODUCE);
@ -73,14 +74,13 @@ void herbsearch(unit * u, int max)
return;
}
if (max)
max = MIN(max, rherbs(r));
else
max = rherbs(r);
if (max_take < herbs) {
herbs = max_take;
}
herbsfound = ntimespprob(effsk * u->number,
(double)rherbs(r) / 100.0F, -0.01F);
if (herbsfound > max) herbsfound = max;
if (herbsfound > herbs) herbsfound = herbs;
rsetherbs(r, (short) (rherbs(r) - 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) {
int use = u->number / 10;
if (use < amount) {
if (u->number % 10 > 0) ++use;
amount = use;
int hp = 10 * amount;
if (hp > u->number) {
hp = u->number;
amount = (hp + 9) % 10;
}
/* Verf<72>nffacht die HP von max. 10 Personen in der Einheit */
u->hp += MIN(u->number, 10 * amount) * unit_max_hp(u) * 4;
u->hp += hp * unit_max_hp(u) * 4;
return amount;
}

View File

@ -680,7 +680,7 @@ static int CavalryBonus(const unit * u, troop enemy, int type)
/* only half against trolls */
if (skl > 0) {
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)) {
dmg = dmg / 4;
}
@ -691,7 +691,8 @@ static int CavalryBonus(const unit * u, troop enemy, int type)
}
else {
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;
if (gain > 0) {
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;
int maxk = 4;
kritchance = MAX(kritchance, 0.005);
kritchance = MIN(0.9, kritchance);
kritchance = fmax(kritchance, 0.005);
kritchance = fmin(0.9, kritchance);
while (maxk-- && chance(kritchance)) {
da += dice_rand(damage);
@ -1733,8 +1736,9 @@ void do_combatmagic(battle * b, combatmagic_t was)
}
level = eff_spelllevel(mage, sp, level, 1);
if (sl > 0)
level = MIN(sl, level);
if (sl > 0 && sl < level) {
level = sl;
}
if (level < 0) {
report_failed_spell(b, mage, sp);
free_order(ord);
@ -1814,8 +1818,10 @@ static void do_combatspell(troop at)
}
level = eff_spelllevel(caster, sp, fi->magic, 1);
if ((sl = get_combatspelllevel(caster, 1)) > 0)
level = MIN(level, sl);
sl = get_combatspelllevel(caster, 1);
if (sl > 0 && sl < level) {
level = sl;
}
if (fumble(r, caster, sp, level)) {
report_failed_spell(b, caster, sp);
@ -2333,14 +2339,15 @@ double fleechance(unit * u)
if (u_race(u) == get_race(RC_HALFLING)) {
c += 0.20;
c = MIN(c, 0.90);
c = fmin(c, 0.90);
}
else {
c = MIN(c, 0.75);
c = fmin(c, 0.75);
}
if (a != NULL)
if (a) {
c += a->data.flt;
}
return c;
}
@ -2461,7 +2468,7 @@ static void loot_items(fighter * corpse)
float lootfactor = (float)dead / (float)u->number; /* only loot the dead! */
int maxloot = (int)((float)itm->number * lootfactor);
if (maxloot > 0) {
int i = MIN(10, maxloot);
int i = (maxloot > 10) ? 10 : maxloot;
for (; i != 0; --i) {
int loot = maxloot / i;
@ -2541,12 +2548,18 @@ static double PopulationDamage(void)
static void battle_effects(battle * b, int dead_players)
{
region *r = b->region;
int dead_peasants =
MIN(rpeasants(r), (int)(dead_players * PopulationDamage()));
if (dead_peasants) {
deathcounts(r, dead_peasants + dead_players);
add_chaoscount(r, dead_peasants / 2);
rsetpeasants(r, rpeasants(r) - dead_peasants);
int rp = rpeasants(r);
if (rp > 0) {
int dead_peasants = (int)(dead_players * PopulationDamage());
if (dead_peasants > rp) {
dead_peasants = rp;
}
if (dead_peasants) {
deathcounts(r, dead_peasants + dead_players);
add_chaoscount(r, dead_peasants / 2);
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 */
/* 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 */
for (i = 0; i < fig->alive; i++) {
@ -3946,7 +3960,8 @@ static void battle_flee(battle * b)
troop dt;
int runners = 0;
/* 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)) {
/* 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) {
ispaniced = EFFECT_PANIC_SPELL;
}
if (chance(MIN(fleechance(u) + ispaniced, 0.90))) {
if (chance(fmin(fleechance(u) + ispaniced, 0.90))) {
++runners;
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.
**/
#ifdef _MSC_VER
#include <platform.h>
#include <kernel/config.h>
#endif
#include "build.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/connection.h>
#include <kernel/building.h>
#include <kernel/config.h>
#include <kernel/curse.h>
#include <kernel/faction.h>
#include <kernel/group.h>
@ -121,11 +123,12 @@ static void destroy_road(unit * u, int nmax, struct order *ord)
}
road = rroad(r, d);
n = MIN(n, road);
if (n > road) n = road;
if (n != 0) {
region *r2 = rconnect(r, d);
int willdo = effskill(u, SK_ROAD_BUILDING, 0) * u->number;
willdo = MIN(willdo, n);
if (willdo > n) willdo = n;
if (willdo == 0) {
/* TODO: error message */
}
@ -324,8 +327,9 @@ void build_road(unit * u, int size, direction_t d)
return;
}
if (size > 0)
left = MIN(size, left);
if (size > 0 && left > size) {
left = size;
}
/* baumaximum anhand der rohstoffe */
if (u_race(u) == get_race(RC_STONEGOLEM)) {
n = u->number * GOLEM_STONE;
@ -337,7 +341,7 @@ void build_road(unit * u, int size, direction_t d)
return;
}
}
left = MIN(n, left);
if (n < left) left = n;
/* n = maximum by skill. try to maximize it */
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);
item *itm = ring ? *i_find(&u->items, ring->itype) : 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;
}
}
@ -353,15 +357,15 @@ void build_road(unit * u, int size, direction_t d)
int dm = get_effect(u, oldpotiontype[P_DOMORE]);
if (dm != 0) {
int todo = (left - n + effsk - 1) / effsk;
todo = MIN(todo, u->number);
dm = MIN(dm, todo);
if (todo > u->number) todo = u->number;
if (dm > todo) dm = todo;
change_effect(u, oldpotiontype[P_DOMORE], -dm);
n += dm * effsk;
} /* Auswirkung Schaffenstrunk */
}
/* 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
* 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 {
use_pooled(u, get_resourcetype(R_STONE), GET_DEFAULT, n);
/* 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",
"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) {
/* Auswirkung Schaffenstrunk */
dm = MIN(dm, u->number);
if (dm > u->number) dm = u->number;
change_effect(u, oldpotiontype[P_DOMORE], -dm);
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;
int i = itm ? itm->number : 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;
}
}
@ -600,7 +604,8 @@ int build(unit * u, const construction * ctype, int completed, int want, int ski
if (want < n) n = want;
if (con->maxsize > 0) {
n = MIN(con->maxsize - completed, n);
int req = con->maxsize - completed;
if (req < n) n = req;
if (con->improvement == NULL) {
want = n;
}
@ -623,7 +628,7 @@ int build(unit * u, const construction * ctype, int completed, int want, int ski
completed = completed + n;
}
/* 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;
}
@ -667,8 +672,10 @@ int maxbuild(const unit * u, const construction * cons)
if (have < need) {
return 0;
}
else
maximum = MIN(maximum, have / need);
else {
int b = have / need;
if (maximum > b) maximum = b;
}
}
return maximum;
}
@ -877,7 +884,8 @@ static void build_ship(unit * u, ship * sh, int want)
}
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;
if (repair % DAMAGE_SCALE)
++n;
@ -920,10 +928,9 @@ order * ord)
cmistake(u, ord, 88, MSG_PRODUCE);
return;
}
if (want > 0)
want = MIN(want, msize);
else
if (want <= 0 || want > msize) {
want = msize;
}
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);
return;
}
if (want > 0)
want = MIN(want, msize);
else
if (want <= 0 || want > msize) {
want = msize;
}
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);
if (q >= MIN_QUALITY && nfactions < numfactions && players && *players) {
starting_region(players, r, rn);
minq = MIN(minq, q);
maxq = MAX(maxq, q);
if (minq > q) minq = q;
if (maxq < q) maxq = q;
++nfactions;
}
}
@ -976,8 +976,8 @@ int build_island_e3(int x, int y, int minsize, newfaction ** players, int numfac
q = region_quality(r, rn);
if (q >= MIN_QUALITY * 4 / 3 && nfactions < numfactions && players && *players) {
starting_region(players, r, rn);
minq = MIN(minq, q);
maxq = MAX(maxq, q);
if (minq > q) minq = q;
if (maxq < q) maxq = q;
++nfactions;
}
}

View File

@ -19,11 +19,6 @@
/* @see https://insanecoding.blogspot.no/2007/11/pathmax-simply-isnt.html */
#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
#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.
**/
#define TEACH_ALL 1
#define TEACH_FRIENDS
#ifdef _MSC_VER
#include <platform.h>
#endif
#include <kernel/config.h>
#include "study.h"
#include "laws.h"
@ -65,6 +64,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <string.h>
#include <math.h>
#define TEACH_ALL 1
#define TEACH_FRIENDS
static skill_t getskill(const struct locale *lang)
{
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);
}
#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) {
log_t *lg;
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) {
va_list copy;
va_copy(copy, args);
VA_COPY(copy, args);
lg->log(lg->data, level, NULL, format, copy);
va_end(copy);
}