From 685bf6f4e08d40208bb8c4f4f1dffa4a7dcaf763 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 23 Sep 2009 17:06:58 +0000 Subject: [PATCH] tactics --- src/common/gamecode/creport.c | 2 +- src/common/kernel/battle.c | 35 +++++++++++++++++++++++------------ src/common/util/language.c | 2 +- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index facf61ee5..8ad55d63b 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -1509,7 +1509,7 @@ report_computer(const char * filename, report_context * ctx, const char * charse int crwritemap(const char * filename) { - FILE * F = fopen(filename, "w+"); + FILE * F = fopen(filename, "w"); region * r; fprintf(F, "VERSION %d\n", C_REPORT_VERSION); diff --git a/src/common/kernel/battle.c b/src/common/kernel/battle.c index 744314b6e..540027690 100644 --- a/src/common/kernel/battle.c +++ b/src/common/kernel/battle.c @@ -1565,20 +1565,26 @@ select_enemy(fighter * af, int minrow, int maxrow, int select) } static int -get_tactics(side * s) +get_tactics(const side * as, const side * ds) { - battle * b = s->battle; + battle * b = as->battle; side *stac; int result = 0; + int defense = 0; if (b->max_tactics > 0) { for (stac=b->sides;stac!=b->sides+b->nsides;++stac) { - if (stac->leader.value >result && helping(stac, s)) { + if (stac->leader.value > result && helping(stac, as)) { + assert(ds==NULL || !helping(stac, ds)); result = stac->leader.value; } + if (ds && stac->leader.value > defense && helping(stac, ds)) { + assert(!helping(stac, as)); + defense = stac->leader.value; + } } } - return result; + return result - defense; } static troop @@ -1603,14 +1609,19 @@ select_opponent(battle * b, troop at, int mindist, int maxdist) tactics_formula = get_param_int(global.parameters, "rules.tactics.formula", 0); } if (tactics_formula==1) { - int tactics = get_tactics(dt.fighter->side); + int tactics = get_tactics(at.fighter->side, dt.fighter->side); + /* percentage chance to get this attack */ - double tacch = 0.1 * (b->max_tactics - tactics); - if (fval(b->region->terrain, SEA_REGION)) { - ship * sh = at.fighter->unit->ship; - if (sh) tacch *= sh->type->tac_bonus; - } - if (!chance(tacch)) { + if (tactics>0) { + double tacch = 0.1 * tactics; + if (fval(b->region->terrain, SEA_REGION)) { + ship * sh = at.fighter->unit->ship; + if (sh) tacch *= sh->type->tac_bonus; + } + if (!chance(tacch)) { + dt.fighter = NULL; + } + } else { dt.fighter = NULL; } } @@ -4200,7 +4211,7 @@ battle_attacks(battle * b) /* Taktikrunde: */ if (b->turn == 0) { - int tactics = get_tactics(s); + int tactics = get_tactics(s, NULL); if (b->max_tactics > 0 && tactics == b->max_tactics) { break; } diff --git a/src/common/util/language.c b/src/common/util/language.c index c60552f81..d95cfd595 100644 --- a/src/common/util/language.c +++ b/src/common/util/language.c @@ -152,7 +152,7 @@ locale_string(const locale * lang, const char * key) s = locale_string(default_locale, key); } if (s_logfile) { - s_debug = s_debug?s_debug:fopen(s_logfile, "w+"); + s_debug = s_debug?s_debug:fopen(s_logfile, "w"); if (s_debug) { fprintf(s_debug, "%s;%s;%s\n", key, lang->name, s); fflush(s_debug);