diff --git a/src/common/attributes/aggressive.h b/src/common/attributes/aggressive.h index 46a056ede..077ab6a0d 100644 --- a/src/common/attributes/aggressive.h +++ b/src/common/attributes/aggressive.h @@ -19,7 +19,7 @@ extern "C" { #endif extern struct attrib_type at_aggressive; -extern struct attrib * make_aggressive(int chance); +extern struct attrib * make_aggressive(double probability); extern void init_aggressive(void); #ifdef __cplusplus diff --git a/src/common/gamecode/monster.c b/src/common/gamecode/monster.c index a91668fdf..816fd78bb 100644 --- a/src/common/gamecode/monster.c +++ b/src/common/gamecode/monster.c @@ -1004,16 +1004,16 @@ plan_monsters(void) boolean done = false; if((u->race->flags & RCF_ATTACKRANDOM) && is_moving == false) { - int chance; + double probability; attrib *a = a_find(u->attribs, &at_aggressive); - if(a) { - chance = a->data.i; + if (a) { + probability = a->data.flt; } else { - chance = MONSTERATTACK; + probability = MONSTERATTACK; } - if(rand()%100 < chance) { + if(chance(probability)) { done = random_attack_by_monster(r, u); } } diff --git a/src/common/gamecode/randenc.c b/src/common/gamecode/randenc.c index d4c5b233e..a02b886a9 100644 --- a/src/common/gamecode/randenc.c +++ b/src/common/gamecode/randenc.c @@ -1213,22 +1213,22 @@ randomevents(void) for (r = regions; r; r = r->next) { if (fval(r, RF_ORCIFIED)) { direction_t dir; - int chance = 0; + double probability = 0.0; for (dir = 0; dir < MAXDIRECTIONS; dir++) { region *rc = rconnect(r, dir); - if (rc && rpeasants(rc) > 0 && !fval(rc, RF_ORCIFIED)) chance += 2; + if (rc && rpeasants(rc) > 0 && !fval(rc, RF_ORCIFIED)) probability += 0.02; } - if (rand()%100 < chance) { + if (chance(probability)) { ADDMSG(&r->msgs, msg_message("deorcified", "region", r)); freset(r, RF_ORCIFIED); } } else { attrib *a = a_find(r->attribs, &at_orcification); if (a!=NULL) { - int chance = 0; + double probability = 0.0; if (rpeasants(r) <= 0) continue; - chance = (a->data.i*100)/rpeasants(r); - if (rand()%100 < chance) { + probability = a->data.i/(double)rpeasants(r); + if (chance(probability)) { fset(r, RF_ORCIFIED); a_remove(&r->attribs, a); ADDMSG(&r->msgs, msg_message("orcified", "region", r)); diff --git a/src/common/gamecode/spy.c b/src/common/gamecode/spy.c index 3c0b3792e..43a9217f5 100644 --- a/src/common/gamecode/spy.c +++ b/src/common/gamecode/spy.c @@ -42,7 +42,8 @@ #include /* util includes */ -#include "vset.h" +#include +#include /* libc includes */ #include @@ -57,7 +58,8 @@ void spy(region * r, unit * u) { unit *target; - int spy, spychance, observe, observechance; + int spy, observe; + double spychance, observechance; target = getunit(r, u->faction); @@ -77,9 +79,9 @@ spy(region * r, unit * u) * Für jeden Talentpunkt, den das Spionagetalent das Tarnungstalent * des Opfers übersteigt, erhöht sich dieses um 5%*/ spy = eff_skill(u, SK_SPY, r) - eff_skill(target, SK_STEALTH, r); - spychance = 10 + max(spy*5, 0); + spychance = 0.1 + max(spy*0.05, 0.0); - if (rand()%100 < spychance){ + if (chance(spychance)) { spy_message(spy, u, target); } else { add_message(&u->faction->msgs, new_message(u->faction, @@ -101,10 +103,10 @@ spy(region * r, unit * u) /* Anschließend wird - unabhängig vom Erfolg - gewürfelt, ob der * Spionageversuch bemerkt wurde. Die Wahrscheinlich dafür ist (100 - * SpionageSpion*5 + WahrnehmungOpfer*2)%. */ - observechance = 100 - (eff_skill(u, SK_SPY, r) * 5) - + (eff_skill(target, SK_OBSERVATION, r) * 2); + observechance = 1.0 - (eff_skill(u, SK_SPY, r) * 0.05) + + (eff_skill(target, SK_OBSERVATION, r) * 0.02); - if (rand()%100 < observechance){ + if (chance(observechance)){ add_message(&target->faction->msgs, new_message(target->faction, "spydetect%u:spy%u:target", observe>0?u:NULL, target)); } @@ -375,7 +377,7 @@ sink_ship(region * r, ship * sh, const char *name, char spy, unit * saboteur) int i; direction_t d; unsigned int index; - int chance; + double probability = 0.0; int money, count; char buffer[DISPLAYSIZE + 1]; vset informed; @@ -385,14 +387,13 @@ sink_ship(region * r, ship * sh, const char *name, char spy, unit * saboteur) vset_init(&survivors); /* figure out what a unit's chances of survival are: */ - chance = 0; if (rterrain(r) != T_OCEAN) - chance = CANAL_SWIMMER_CHANCE; + probability = CANAL_SWIMMER_CHANCE; else for (d = 0; d != MAXDIRECTIONS; ++d) if (rterrain(rconnect(r, d)) != T_OCEAN && !move_blocked(NULL, r, d)) { safety = rconnect(r, d); - chance = OCEAN_SWIMMER_CHANCE; + probability = OCEAN_SWIMMER_CHANCE; break; } for (ui = &r->units; *ui; ui = &(*ui)->next) { @@ -405,7 +406,7 @@ sink_ship(region * r, ship * sh, const char *name, char spy, unit * saboteur) /* if this fails, I misunderstood something: */ for (i = 0; i != u->number; ++i) - if (rand() % 100 >= chance) + if (chance(probability)) ++dead; if (dead != u->number) diff --git a/src/common/kernel/battle.c b/src/common/kernel/battle.c index 3eb194aeb..b0604bc9c 100644 --- a/src/common/kernel/battle.c +++ b/src/common/kernel/battle.c @@ -1152,7 +1152,7 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile) double res = 1.0; /* magic_resistance gib x% Resistenzbonus zurück */ - res -= (double)((double)magic_resistance(du)/100.0)*3.0; + res -= magic_resistance(du)*3.0; if (du->race->battle_flags & BF_EQUIPMENT) { #ifdef TODO_RUNESWORD @@ -1433,7 +1433,6 @@ do_combatmagic(battle *b, combatmagic_t was) { void **fi; spell *sp; - fighter *fig; region *r = b->region; castorder *co; castorder *cll[MAX_SPELLRANK]; @@ -3838,7 +3837,7 @@ damage_unit(unit *u, const char *dam, boolean armor, boolean magic) /* Schaden */ for (i=0; inumber; i++) { int damage = dice_rand(dam); - if (magic) damage = (int)(damage * (100.0 - magic_resistance(u))/100.0); + if (magic) damage = (int)(damage * (1.0 - magic_resistance(u))); if (armor) damage -= nb_armor(u, i); hp[i] -= damage; } diff --git a/src/common/kernel/combatspells.c b/src/common/kernel/combatspells.c index 523a31bf9..7aae2ab53 100644 --- a/src/common/kernel/combatspells.c +++ b/src/common/kernel/combatspells.c @@ -68,8 +68,8 @@ spell_damage(int sp) } } -static int -get_force(int power, int formel) +static double +get_force(double power, int formel) { switch (formel) { case 0: @@ -100,7 +100,7 @@ get_force(int power, int formel) /* Generischer Kampfzauber */ int -sp_kampfzauber(fighter * fi, int level, int power, spell * sp) +sp_kampfzauber(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; troop dt; @@ -165,7 +165,7 @@ sp_kampfzauber(fighter * fi, int level, int power, spell * sp) /* Versteinern */ int -sp_versteinern(fighter * fi, int level, int power, spell * sp) +sp_versteinern(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; unit *mage = fi->unit; @@ -214,7 +214,7 @@ sp_versteinern(fighter * fi, int level, int power, spell * sp) /* Benommenheit: eine Runde kein Angriff */ int -sp_stun(fighter * fi, int level, int power, spell * sp) +sp_stun(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; unit *mage = fi->unit; @@ -277,7 +277,7 @@ sp_stun(fighter * fi, int level, int power, spell * sp) /* Rosthauch */ int -sp_combatrosthauch(fighter * fi, int level, int power, spell * sp) +sp_combatrosthauch(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; cvector *fgs; @@ -367,7 +367,7 @@ sp_combatrosthauch(fighter * fi, int level, int power, spell * sp) } int -sp_sleep(fighter * fi, int level, int power, spell * sp) +sp_sleep(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; unit *mage = fi->unit; @@ -444,7 +444,7 @@ select_ally_in_row(fighter * af, int minrow, int maxrow) } int -sp_speed(fighter * fi, int level, int power, spell * sp) +sp_speed(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; int force; @@ -513,7 +513,7 @@ random_skill(unit *u) } int -sp_mindblast(fighter * fi, int level, int power, spell * sp) +sp_mindblast(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; unit *mage = fi->unit; @@ -596,7 +596,7 @@ sp_mindblast(fighter * fi, int level, int power, spell * sp) } int -sp_dragonodem(fighter * fi, int level, int power, spell * sp) +sp_dragonodem(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; troop dt; @@ -647,7 +647,7 @@ sp_dragonodem(fighter * fi, int level, int power, spell * sp) /* Feuersturm: Betrifft sehr viele Gegner (in der Regel alle), * macht nur vergleichsweise geringen Schaden */ int -sp_immolation(fighter * fi, int level, int power, spell * sp) +sp_immolation(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; troop dt; @@ -695,7 +695,7 @@ sp_immolation(fighter * fi, int level, int power, spell * sp) } int -sp_drainodem(fighter * fi, int level, int power, spell * sp) +sp_drainodem(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; troop dt; @@ -752,13 +752,13 @@ sp_drainodem(fighter * fi, int level, int power, spell * sp) /* PRECOMBAT */ int -sp_shadowcall(fighter * fi, int level, int power, spell * sp) +sp_shadowcall(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; region *r = b->region; unit *mage = fi->unit; attrib *a; - int force = get_force(power, 3)/2; + double force = get_force(power, 3)/2; const race *rc = NULL; int num; unit *u; @@ -780,12 +780,12 @@ sp_shadowcall(fighter * fi, int level, int power, spell * sp) break; } - u = createunit(r, mage->faction, force, rc); + u = createunit(r, mage->faction, (int)force, rc); u->status = ST_FIGHT; set_string(&u->name, racename(mage->faction->locale, u, u->race)); - set_level(u, SK_WEAPONLESS, power/2); - set_level(u, SK_AUSDAUER, power/2); + set_level(u, SK_WEAPONLESS, (int)(power/2)); + set_level(u, SK_AUSDAUER, (int)(power/2)); u->hp = u->number * unit_max_hp(u); if (fval(mage, UFL_PARTEITARNUNG)) @@ -804,21 +804,21 @@ sp_shadowcall(fighter * fi, int level, int power, spell * sp) } int -sp_wolfhowl(fighter * fi, int level, int power, spell * sp) +sp_wolfhowl(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; region *r = b->region; unit *mage = fi->unit; attrib *a; - int force = get_force(power, 3)/2; - unit *u = createunit(r, mage->faction, force, new_race[RC_WOLF]); + double force = get_force(power, 3)/2; + unit *u = createunit(r, mage->faction, (int)force, new_race[RC_WOLF]); unused(sp); u->status = ST_FIGHT; set_string(&u->name, racename(mage->faction->locale, u, u->race)); - set_level(u, SK_WEAPONLESS, power/3); - set_level(u, SK_AUSDAUER, power/3); + set_level(u, SK_WEAPONLESS, (int)(power/3)); + set_level(u, SK_AUSDAUER, (int)(power/3)); u->hp = u->number * unit_max_hp(u); if (fval(mage, UFL_PARTEITARNUNG)) @@ -837,19 +837,18 @@ sp_wolfhowl(fighter * fi, int level, int power, spell * sp) } int -sp_shadowknights(fighter * fi, int level, int power, spell * sp) +sp_shadowknights(fighter * fi, int level, double power, spell * sp) { unit *u; battle *b = fi->side->battle; region *r = b->region; unit *mage = fi->unit; attrib *a; - int force; - unused(sp); + double force = get_force(power, 3); - force = get_force(power, 3); + unused(sp); - u = createunit(r, mage->faction, force, new_race[RC_SHADOWKNIGHT]); + u = createunit(r, mage->faction, (int)force, new_race[RC_SHADOWKNIGHT]); u->status = ST_FIGHT; set_string(&u->name, "Schattenritter"); @@ -871,12 +870,12 @@ sp_shadowknights(fighter * fi, int level, int power, spell * sp) } int -sp_strong_wall(fighter * fi, int level, int force, spell * sp) +sp_strong_wall(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; unit *mage = fi->unit; building *burg; - int effect; + int effect = (int)(power/4); static boolean init = false; static const curse_type * strongwall_ct; if (!init) { init = true; strongwall_ct = ct_find("strongwall"); } @@ -891,11 +890,9 @@ sp_strong_wall(fighter * fi, int level, int force, spell * sp) } burg = mage->building; - effect = force/4; - if (rand()%4 < force%4) - effect++; + if (chance(power-effect)) ++effect; - create_curse(mage, &burg->attribs, strongwall_ct, force, 1, effect, 0); + create_curse(mage, &burg->attribs, strongwall_ct, power, 1, effect, 0); sprintf(buf, "%s Mauern erglühen in einem unheimlichen magischen Licht.", buildingname(burg)); @@ -904,14 +901,13 @@ sp_strong_wall(fighter * fi, int level, int force, spell * sp) } int -sp_chaosrow(fighter * fi, int level, int force, spell * sp) +sp_chaosrow(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; unit *mage = fi->unit; cvector *fgs; void **fig; int n, enemies, row; - int chance; int k = 0; int minrow = FIGHT_ROW; int maxrow = NUMROWS; @@ -919,12 +915,12 @@ sp_chaosrow(fighter * fi, int level, int force, spell * sp) switch (sp->id) { case SPL_CHAOSROW: sprintf(buf, "%s murmelt eine düster klingende Formel", unitname(mage)); - force *= 40; + power *= 40; break; case SPL_SONG_OF_CONFUSION: sprintf(buf, "%s stimmt einen seltsamen Gesang an", unitname(mage)); - force = get_force(force,5); + power = get_force(power, 5); break; } @@ -942,18 +938,14 @@ sp_chaosrow(fighter * fi, int level, int force, spell * sp) for (fig = fgs->begin; fig != fgs->end; ++fig) { fighter *df = *fig; - if (!force) - break; + if (power<=0.0) break; /* force sollte wegen des max(0,x) nicht unter 0 fallen können */ - assert(force >= 0); - if (is_magic_resistant(mage, df->unit, 0)) - continue; + if (is_magic_resistant(mage, df->unit, 0)) continue; n = df->unit->number; - chance = 100 * force/n; - if (chance < 1 + rand()%100) { + if (chance(power/n)) { row = statusrow(df->status)+FIRST_ROW; df->side->size[row] -= df->alive; if (df->unit->race->battle_flags & BF_NOBLOCK) { @@ -982,14 +974,14 @@ sp_chaosrow(fighter * fi, int level, int force, spell * sp) } k++; } - force = max(0, force-n); + power = max(0, power-n); } cv_kill(fgs); scat("Ein plötzlicher Tumult entsteht"); if (k > 0) { scat(" und bringt die Kampfaufstellung durcheinander."); - }else{ + } else { scat(", der sich jedoch schnell wieder legt."); } battlerecord(b, buf); @@ -1000,7 +992,7 @@ sp_chaosrow(fighter * fi, int level, int force, spell * sp) /* Panik (Präkampfzauber) */ int -sp_flee(fighter * fi, int level, int power, spell * sp) +sp_flee(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; unit *mage = fi->unit; @@ -1015,18 +1007,18 @@ sp_flee(fighter * fi, int level, int power, spell * sp) case SPL_FLEE: sprintf(buf, "%s zaubert %s", unitname(mage), spell_name(sp, default_locale)); - force = get_force(power,4); + force = (int)get_force(power,4); break; case SPL_SONG_OF_FEAR: sprintf(buf, "%s stimmt einen düsteren Gesang an", unitname(mage)); - force = get_force(power,3); + force = (int)get_force(power,3); break; case SPL_AURA_OF_FEAR: sprintf(buf, "%s ist von dunklen Schatten umgeben", unitname(mage)); - force = get_force(power,5); + force = (int)get_force(power,5); break; default: - force = get_force(power,10); + force = (int)get_force(power,10); } if (!count_enemies(b, fi->side, FS_ENEMY, minrow, maxrow)) { @@ -1072,7 +1064,7 @@ sp_flee(fighter * fi, int level, int power, spell * sp) /* Heldenmut */ int -sp_hero(fighter * fi, int level, int power, spell * sp) +sp_hero(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; unit *mage = fi->unit; @@ -1088,13 +1080,13 @@ sp_hero(fighter * fi, int level, int power, spell * sp) spell_name(sp, default_locale)); switch(sp->id) { case SPL_HERO: - df_bonus = power/5; - force = lovar(get_force(power,4)); + df_bonus = (int)(power/5); + force = lovar(get_force(power, 4)); break; default: df_bonus = 1; - force = power; + force = (int)power; } scat(":"); battlerecord(b, buf); @@ -1128,7 +1120,7 @@ sp_hero(fighter * fi, int level, int power, spell * sp) } int -sp_berserk(fighter * fi, int level, int power, spell * sp) +sp_berserk(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; unit *mage = fi->unit; @@ -1148,13 +1140,13 @@ sp_berserk(fighter * fi, int level, int power, spell * sp) case SPL_BLOODTHIRST: at_bonus = max(1,level/3); df_malus = 2; - force = get_force(power,2); + force = (int)get_force(power,2); break; default: at_bonus = 1; df_malus = 0; - force = power; + force = (int)power; } scat(":"); battlerecord(b, buf); @@ -1189,7 +1181,7 @@ sp_berserk(fighter * fi, int level, int power, spell * sp) } int -sp_frighten(fighter * fi, int level, int power, spell * sp) +sp_frighten(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; unit *mage = fi->unit; @@ -1204,7 +1196,7 @@ sp_frighten(fighter * fi, int level, int power, spell * sp) at_malus = max(1,level - 4); df_malus = 2; - force = get_force(power, 2); + force = (int)get_force(power, 2); sprintf(buf, "%s zaubert %s", unitname(mage), spell_name(sp, default_locale)); @@ -1249,13 +1241,12 @@ sp_frighten(fighter * fi, int level, int power, spell * sp) int -sp_tiredsoldiers(fighter * fi, int level, int force, spell * sp) +sp_tiredsoldiers(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; unit *mage = fi->unit; int n = 0; - - force = force * force * 4; + int force = (int)(power * power * 4); sprintf(buf, "%s zaubert %s", unitname(mage), spell_name(sp, default_locale)); @@ -1298,7 +1289,7 @@ sp_tiredsoldiers(fighter * fi, int level, int force, spell * sp) } int -sp_windshield(fighter * fi, int level, int power, spell * sp) +sp_windshield(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; unit *mage = fi->unit; @@ -1312,12 +1303,12 @@ sp_windshield(fighter * fi, int level, int power, spell * sp) spell_name(sp, default_locale)); switch(sp->id) { case SPL_WINDSHIELD: - force = get_force(power,4); + force = (int)get_force(power,4); at_malus = level/4; break; default: - force = power; + force = (int)power; at_malus = 2; } enemies = count_enemies(b, fi->side, FS_ENEMY, @@ -1351,11 +1342,12 @@ sp_windshield(fighter * fi, int level, int power, spell * sp) } int -sp_reeling_arrows(fighter * fi, int level, int force, spell * sp) +sp_reeling_arrows(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; unit *mage = fi->unit; - unused(force); + + unused(power); b->reelarrow = true; sprintf(buf, "%s zaubert %s", unitname(mage), @@ -1367,7 +1359,7 @@ sp_reeling_arrows(fighter * fi, int level, int force, spell * sp) } int -sp_denyattack(fighter * fi, int level, int power, spell * sp) +sp_denyattack(fighter * fi, int level, double power, spell * sp) { /* Magier weicht dem Kampf aus. Wenn er sich bewegen kann, zieht er in * eine Nachbarregion, wobei ein NACH berücksichtigt wird. Ansonsten @@ -1430,7 +1422,7 @@ do_meffect(fighter * af, int typ, int effect, int duration) } int -sp_armorshield(fighter * fi, int level, int power, spell * sp) +sp_armorshield(fighter * fi, int level, double power, spell * sp) { int effect; int duration; @@ -1446,19 +1438,19 @@ sp_armorshield(fighter * fi, int level, int power, spell * sp) switch(sp->id) { case SPL_ARMORSHIELD: effect = level/3; - duration = 20*power*power; + duration = (int)(20*power*power); break; default: effect = level/4; - duration = power*power; + duration = (int)(power*power); } do_meffect(fi, SHIELD_ARMOR, effect, duration); return level; } int -sp_reduceshield(fighter * fi, int level, int power, spell * sp) +sp_reduceshield(fighter * fi, int level, double power, spell * sp) { int effect; int duration; @@ -1475,19 +1467,19 @@ sp_reduceshield(fighter * fi, int level, int power, spell * sp) switch(sp->id) { case SPL_REDUCESHIELD: effect = 50; - duration = 50*power*power; + duration = (int)(50*power*power); break; default: effect = level*3; - duration = get_force(power,5); + duration = (int)get_force(power,5); } do_meffect(fi, SHIELD_REDUCE, effect, duration); return level; } int -sp_fumbleshield(fighter * fi, int level, int power, spell * sp) +sp_fumbleshield(fighter * fi, int level, double power, spell * sp) { int effect; int duration; @@ -1536,27 +1528,25 @@ count_healable(battle *b, fighter *df) /* wiederbeleben */ int -sp_reanimate(fighter * fi, int level, int force, spell * sp) +sp_reanimate(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; unit *mage = fi->unit; - int healable, k, j=0; - double c; + int healable, j=0; + double c = 0.50; + double k = EFFECT_HEALING_SPELL * power; switch(sp->id) { case SPL_REANIMATE: sprintf(buf, "%s beginnt ein Ritual der Wiederbelebung", unitname(mage)); - k = EFFECT_HEALING_SPELL*force; - c = 0.50 + 0.02 * force; + c += 0.02 * power; break; default: sprintf(buf, "%s zaubert %s", unitname(mage), spell_name(sp, default_locale)); - k = EFFECT_HEALING_SPELL*force; - c = 0.50; } if (get_item(mage, I_AMULET_OF_HEALING) > 0) { scat(" und benutzt das "); @@ -1567,8 +1557,8 @@ sp_reanimate(fighter * fi, int level, int force, spell * sp) } healable = count_healable(b, fi); - k = min(k, healable); - while (k--) { + healable = (int)min(k, healable); + while (healable--) { troop t = select_corpse(b, fi); if (t.fighter && t.fighter->side->casualties > 0 @@ -1587,7 +1577,6 @@ sp_reanimate(fighter * fi, int level, int force, spell * sp) ++t.fighter->side->size[t.fighter->unit->status + 1]; ++t.fighter->side->healed; --t.fighter->side->casualties; - --healable; ++j; } } @@ -1608,7 +1597,7 @@ sp_reanimate(fighter * fi, int level, int force, spell * sp) } int -sp_keeploot(fighter * fi, int level, int force, spell * sp) +sp_keeploot(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; @@ -1616,13 +1605,13 @@ sp_keeploot(fighter * fi, int level, int force, spell * sp) spell_name(sp, default_locale)); battlerecord(b, buf); - b->keeploot = max(50, b->keeploot + 5*force); + b->keeploot = (int)max(50, b->keeploot + 5*power); return level; } int -sp_healing(fighter * fi, int level, int force, spell * sp) +sp_healing(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; unit *mage = fi->unit; @@ -1638,13 +1627,13 @@ sp_healing(fighter * fi, int level, int force, spell * sp) /* bis zu 11 Personen pro Stufe (einen HP müssen sie ja noch * haben, sonst wären sie tot) können geheilt werden */ - healhp = force * 200; + power *= 200; if (get_item(mage, I_AMULET_OF_HEALING) > 0) { scat(" und benutzt das "); scat(locale_string(default_locale, resourcename(oldresourcetype[R_AMULET_OF_HEALING], 0))); scat(", um die Heilzauber zu verstärken"); - healhp *= 2; + power *= 2; } /* gehe alle denen wir helfen der reihe nach durch, heile verwundete, @@ -1653,11 +1642,11 @@ sp_healing(fighter * fi, int level, int force, spell * sp) fgs = fighters(b, fi, minrow, maxrow, FS_HELP); v_scramble(fgs->begin, fgs->end); + healhp = (int)power; for (fig = fgs->begin; fig != fgs->end; ++fig) { fighter *df = *fig; - if (!healhp) - break; + if (healhp<=0) break; /* wir heilen erstmal keine Monster */ if (!playerrace(df->unit->race)) @@ -1722,7 +1711,7 @@ sp_healing(fighter * fi, int level, int force, spell * sp) } int -sp_undeadhero(fighter * fi, int level, int force, spell * sp) +sp_undeadhero(fighter * fi, int level, double power, spell * sp) { battle *b = fi->side->battle; unit *mage = fi->unit; @@ -1731,13 +1720,9 @@ sp_undeadhero(fighter * fi, int level, int force, spell * sp) int maxrow = AVOID_ROW; cvector *fgs; void **fig; - int k, n, j; - int undead = 0; - double c; - - /* maximal Stufe*4 Personen*/ - k = get_force(force,0); - c = 0.50 + 0.02 * force; + int n, j, undead = 0; + int k = (int)get_force(power,0); + double c = 0.50 + 0.02 * power; /* Liste aus allen Kämpfern */ fgs = fighters(b, fi, minrow, maxrow, FS_ENEMY | FS_HELP ); diff --git a/src/common/kernel/curse.c b/src/common/kernel/curse.c index 21ea768ed..0ca00a7b1 100644 --- a/src/common/kernel/curse.c +++ b/src/common/kernel/curse.c @@ -37,6 +37,7 @@ /* util includes */ #include #include +#include #include /* libc includes */ @@ -590,14 +591,11 @@ do_transfer_curse(curse *c, unit * u, unit * u2, int n) break; } case CURSE_SPREADCHANCE: - { - int chance = u2->number * 100 / (u2->number + n); - if (rand()%100 > chance ){ + if (chance(u2->number/(double)(u2->number + n))) { men = u2->number + n; dogive = true; } break; - } case CURSE_SPREADNEVER: break; } diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index 1ee08a391..4cfc8bbbf 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -297,7 +297,7 @@ extern void plagues(struct region * r, boolean ismagic); /** Monster */ /* Chance für Monsterangriff */ -#define MONSTERATTACK 40 +#define MONSTERATTACK 0.4 /** Gebäude */ /* Chance für Einsturz bei unversorgtem Gebaeude */ diff --git a/src/common/kernel/item.c b/src/common/kernel/item.c index abf81d716..63d678d92 100644 --- a/src/common/kernel/item.c +++ b/src/common/kernel/item.c @@ -777,10 +777,9 @@ destroy_curse_crystal(attrib **alist, int cast_level, int force) if (c->flag & CURSE_IMMUN); if (cast_level < c->vigour) { /* Zauber ist nicht stark genug */ - int chance; - /* pro Stufe Unterschied -20% */ - chance = (10 + (cast_level - c->vigour)*2); - if(rand()%10 >= chance){ + /* pro Stufe Unterschied -20% */ + double probability = 1 + (cast_level - c->vigour) * 0.2; + if (chance(probability)) { if (c->type->change_vigour) c->type->change_vigour(c, -2); force -= c->vigour; diff --git a/src/common/kernel/magic.c b/src/common/kernel/magic.c index 7b1f6ad95..345d80344 100644 --- a/src/common/kernel/magic.c +++ b/src/common/kernel/magic.c @@ -40,10 +40,6 @@ #include "pathfinder.h" #include "karma.h" -/* util includes */ -#include -#include -#include #include #include #include @@ -51,6 +47,12 @@ #include #include +/* util includes */ +#include +#include +#include +#include + /* libc includes */ #include #include @@ -1179,29 +1181,28 @@ farcasting(unit *magician, region *r) /* allgemeine Magieresistenz einer Einheit, * reduziert magischen Schaden */ -int +double magic_resistance(unit *target) { attrib * a; curse *c; - int chance; int n; - /* Bonus durch Rassenmagieresistenz */ - chance = (int)(target->race->magres * 100); + /* Bonus durch Rassenmagieresistenz */ + double probability = target->race->magres; /* Magier haben einen Resistenzbonus vom Magietalent * 5%*/ - chance += effskill(target, SK_MAGIC)*5; + probability += effskill(target, SK_MAGIC)*0.5; /* Auswirkungen von Zaubern auf der Einheit */ c = get_curse(target->attribs, ct_find("magicresistance")); if (c) { - chance += curse_geteffect(c) * get_cursedmen(target, c); + probability += 0.01 * curse_geteffect(c) * get_cursedmen(target, c); } /* Unicorn +10 */ n = get_item(target, I_UNICORN); - if (n) chance += (10*n)/target->number; + if (n) probability += n*0.1/target->number; /* Auswirkungen von Zaubern auf der Region */ a = a_find(target->region->attribs, &at_curse); @@ -1212,7 +1213,7 @@ magic_resistance(unit *target) if (mage!=NULL) { if (c->type == ct_find("goodmagicresistancezone")) { if (alliedunit(mage, target->faction, HELP_GUARD)) { - chance += curse_geteffect(c); + probability += curse_geteffect(c)*0.01; break; } } @@ -1234,9 +1235,9 @@ magic_resistance(unit *target) const struct building_type * btype = b?b->type:NULL; /* gesegneter Steinkreis gibt 30% dazu */ - if (btype) chance += btype->magresbonus; + if (btype) probability += btype->magresbonus * 0.01; } - return chance; + return (int)(probability*100); } /* ------------------------------------------------------------- */ @@ -1253,7 +1254,7 @@ magic_resistance(unit *target) boolean target_resists_magic(unit *magician, void *obj, int objtyp, int t_bonus) { - int chance = 0; + double probability = 0.0; if (magician == NULL) return true; if (obj == NULL) return true; @@ -1274,47 +1275,39 @@ target_resists_magic(unit *magician, void *obj, int objtyp, int t_bonus) } /* Contest */ - chance = 5*(pa+10 - at); + probability = 0.05 * (10 + pa - at); - chance += magic_resistance((unit *)obj); + probability += magic_resistance((unit *)obj); break; } case TYP_REGION: /* Bonus durch Zauber */ - chance += get_curseeffect(((region *)obj)->attribs, C_RESIST_MAGIC, 0); + probability += 0.01 * get_curseeffect(((region *)obj)->attribs, C_RESIST_MAGIC, 0); break; case TYP_BUILDING: /* Bonus durch Zauber */ - chance += get_curseeffect(((building *)obj)->attribs, C_RESIST_MAGIC, 0); + probability += 0.01 * get_curseeffect(((building *)obj)->attribs, C_RESIST_MAGIC, 0); /* Bonus durch Typ */ - chance += ((building *)obj)->type->magres; - + probability += 0.01 * ((building *)obj)->type->magres; break; case TYP_SHIP: /* Bonus durch Zauber */ - chance += get_curseeffect(((ship *)obj)->attribs, C_RESIST_MAGIC, 0); + probability += 0.01 * get_curseeffect(((ship *)obj)->attribs, C_RESIST_MAGIC, 0); break; - - case TYP_FACTION: - default: - chance = 0; } - chance = max(2, chance + t_bonus); - chance = min(98, chance); + probability = max(0.02, probability + t_bonus*0.01); + probability = min(0.98, probability); /* gibt true, wenn die Zufallszahl kleiner als die chance ist und * false, wenn sie gleich oder größer ist, dh je größer die * Magieresistenz (chance) desto eher gibt die Funktion true zurück */ - if (rand()%100 < chance) { - return true; - } - return false; + return chance(probability); } /* ------------------------------------------------------------- */ @@ -3180,4 +3173,3 @@ spell_name(const struct spell * sp, const struct locale * lang) } return sp->sname; } - diff --git a/src/common/kernel/magic.h b/src/common/kernel/magic.h index c7f61b21b..9d398b05d 100644 --- a/src/common/kernel/magic.h +++ b/src/common/kernel/magic.h @@ -146,6 +146,15 @@ struct spell_ptr { /* typedef struct fighter fighter; */ +/* irgendwelche zauber: */ +typedef void (*spell_f) (void*); +/* normale zauber: */ +typedef int (*nspell_f)(castorder*); +/* kampfzauber: */ +typedef int (*cspell_f) (struct fighter*, int, double, struct spell * sp); +/* zauber-patzer: */ +typedef void (*pspell_f) (castorder *); + typedef struct spell { spellid_t id; const char *sname; @@ -157,7 +166,7 @@ typedef struct spell { char rank; /* Reihenfolge der Zauber */ int level; /* Stufe des Zaubers */ resource_t komponenten[MAXINGREDIENT][3]; - void (*sp_function) (void*); + spell_f sp_function; void (*patzer) (castorder*); } spell; @@ -182,15 +191,6 @@ struct castorder { /* ------------------------------------------------------------- */ -/* irgendwelche zauber: */ -typedef void (*spell_f) (void*); -/* normale zauber: */ -typedef int (*nspell_f)(castorder*); -/* kampfzauber: */ -typedef int (*cspell_f) (struct fighter*, int, double, struct spell * sp); -/* zauber-patzer: */ -typedef void (*pspell_f) (castorder *); - /* besondere Spruchtypen */ #define FARCASTING (1<<0) /* ZAUBER [struct region x y] */ #define SPELLLEVEL (1<<1) /* ZAUBER [STUFE x] */ @@ -364,7 +364,7 @@ int eff_spelllevel(struct unit *u, spell * sp, int cast_level, int distance); boolean is_magic_resistant(struct unit *magician, struct unit *target, int resist_bonus); /* Mapperfunktion für target_resists_magic() vom Typ struct unit. */ -int magic_resistance(struct unit *target); +extern double magic_resistance(struct unit *target); /* gibt die Chance an, mit der einem Zauber widerstanden wird. Je * größer, desto resistenter ist da Opfer */ boolean target_resists_magic(struct unit *magician, void *obj, int objtyp, diff --git a/src/common/kernel/movement.c b/src/common/kernel/movement.c index 617f9e716..85b1f9e27 100644 --- a/src/common/kernel/movement.c +++ b/src/common/kernel/movement.c @@ -44,7 +44,8 @@ #include "unit.h" /* util includes */ -#include +#include +#include /* libc includes */ #include @@ -700,11 +701,11 @@ bewegung_blockiert_von(unit * reisender, region * r) } } if (!contact && guard) { - int chance = 30; /* 30% base chance */ - chance += 10 * (perception - eff_stealth(reisender, r)); - chance += 10 * max(guard->number, get_item(guard, I_AMULET_OF_TRUE_SEEING)); + double prob = 0.3; /* 30% base chance */ + prob += 0.1 * (perception - eff_stealth(reisender, r)); + prob += 0.1 * max(guard->number, get_item(guard, I_AMULET_OF_TRUE_SEEING)); - if (rand() % 100 < chance) { + if (chance(prob)) { return guard; } } diff --git a/src/common/kernel/spell.c b/src/common/kernel/spell.c index b44e6b2e1..1868dcdcb 100644 --- a/src/common/kernel/spell.c +++ b/src/common/kernel/spell.c @@ -3321,7 +3321,7 @@ sp_deathcloud(castorder *co) /* Jede Person verliert 18 HP */ damage = 18 * u->number; /* Reduziert durch Magieresistenz */ - damage *= (100.0 - magic_resistance(u))/100.0; + damage *= (1.0 - magic_resistance(u)); change_hitpoints(u, -(int)damage); } diff --git a/src/common/kernel/spell.h b/src/common/kernel/spell.h index c0335a564..80f929c86 100644 --- a/src/common/kernel/spell.h +++ b/src/common/kernel/spell.h @@ -228,35 +228,35 @@ extern double destr_curse(struct curse* c, int cast_level, double force); /* Kampfzauber */ -extern int sp_fumbleshield(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_shadowknights(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_combatrosthauch(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_kampfzauber(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_healing(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_keeploot(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_reanimate(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_chaosrow(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_flee(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_berserk(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_tiredsoldiers(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_reeling_arrows(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_denyattack(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_sleep(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_windshield(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_strong_wall(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_versteinern(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_hero(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_frighten(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_mindblast(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_speed(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_wolfhowl(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_dragonodem(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_reduceshield(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_armorshield(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_stun(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_undeadhero(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_shadowcall(struct fighter * fi, int level, int power, struct spell * sp); -extern int sp_immolation(struct fighter * fi, int level, int power, struct spell * sp); +extern int sp_fumbleshield(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_shadowknights(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_combatrosthauch(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_kampfzauber(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_healing(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_keeploot(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_reanimate(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_chaosrow(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_flee(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_berserk(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_tiredsoldiers(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_reeling_arrows(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_denyattack(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_sleep(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_windshield(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_strong_wall(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_versteinern(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_hero(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_frighten(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_mindblast(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_speed(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_wolfhowl(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_dragonodem(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_reduceshield(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_armorshield(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_stun(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_undeadhero(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_shadowcall(struct fighter * fi, int level, double power, struct spell * sp); +extern int sp_immolation(struct fighter * fi, int level, double power, struct spell * sp); /* ------------------------------------------------------------- */ diff --git a/src/common/kernel/spy.h b/src/common/kernel/spy.h index 5030a5f46..bb1c50770 100644 --- a/src/common/kernel/spy.h +++ b/src/common/kernel/spy.h @@ -35,8 +35,8 @@ void spy(struct region * r, struct unit * u); void sabotage(struct region * r, struct unit * u); void spy_message(int spy, struct unit *u, struct unit *target); -#define OCEAN_SWIMMER_CHANCE 10 -#define CANAL_SWIMMER_CHANCE 90 +#define OCEAN_SWIMMER_CHANCE 0.1 +#define CANAL_SWIMMER_CHANCE 0.9 #ifdef __cplusplus } diff --git a/src/common/util/rand.c b/src/common/util/rand.c index db6c0c6f1..0da9e5e6b 100644 --- a/src/common/util/rand.c +++ b/src/common/util/rand.c @@ -95,6 +95,7 @@ ntimespprob(int n, double p, double mod) boolean chance(double x) { + if (x>=1.0) return true; return (boolean) (rand() % RAND_MAX < RAND_MAX * x); } diff --git a/src/eressea/server.cpp b/src/eressea/server.cpp index 43978c260..593574037 100644 --- a/src/eressea/server.cpp +++ b/src/eressea/server.cpp @@ -234,34 +234,6 @@ getgarbage(void) #endif } -#if 0 -static void -writefactiondata(void) -{ - FILE *F; - char zText[128]; - - sprintf(zText, "%s/faction-data.xml", basepath()); - F = cfopen(zText, "w"); - if(F) { - faction *f; - for(f = factions; f; f=f->next) { - fprintf(F,"\n"); - fprintf(F,"\t%s\n",itoa36(f->no)); - fprintf(F,"\t%s\n",f->name); - fprintf(F,"\t%s\n",f->email); - fprintf(F,"\t%s\n",f->passw); - fprintf(F,"\t%s\n",rc_name(f->race,1)); - fprintf(F,"\t%s\n",neue_gebiete[f->magiegebiet]); - fprintf(F,"\t%d\n",turn-f->lastorders); - fprintf(F,"\t%d\n",f->score); - fprintf(F,"\n"); - } - } - fclose(F); -} -#endif - #ifdef SHORTPWDS static void readshortpwds() @@ -473,56 +445,6 @@ init_malloc_debug(void) } #endif -#if 0 -static void -write_stats(void) -{ - FILE * F; - char zText[MAX_PATH]; - strcat(strcpy(zText, resourcepath()), "/spells"); - F = fopen(zText, "wt"); - if (F) { - int i, m = -1; - for (i=0;spelldaten[i].id;++i) { - if (spelldaten[i].magietyp!=m) { - m=spelldaten[i].magietyp; - fprintf(F, "\n%s\n", magietypen[m]); - } - fprintf(F, "%d\t%s\n", spelldaten[i].level, spelldaten[i].name); - } - fclose(F); - } else { - sprintf(buf, "fopen(%s): ", zText); - perror(buf); - } - strcat(strcpy(zText, resourcepath()), "/bonus"); - F = fopen(buf, "wt"); - if (F) { - race_t r; - for (r=0;r!=MAXRACES;++r) { - skill_t sk; - int i = 0; - fprintf(F, "const bonus %s_bonus = {\n\t", race[r].name[0]); - for (sk=0;sk!=MAXSKILLS;sk++) { - if (race[r].bonus[sk]) { - if (i==8) { - i = 0; - fputs("\n\t", F); - } - fprintf(F, "{ SK_%s, %d }, ", skillname(sk, NULL), race[r].bonus[sk]); - ++i; - } - } - fputs("{ SK_NONE, 0 }\n};\n", F); - } - fclose(F); - } else { - sprintf(buf, "fopen(%s): ", zText); - perror(zText); - } -} -#endif - static int usage(const char * prog, const char * arg) {