New pct_chance(), for clarity, and symmetry with chance()

This commit is contained in:
Markus Armbruster 2012-08-16 21:05:42 +02:00
parent 1cf6b5e6bb
commit 54ddcd0f5a
10 changed files with 34 additions and 22 deletions

View file

@ -280,7 +280,7 @@ detonate(struct nukstr *np, coord x, coord y, int airburst)
continue;
if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
continue;
if (roll(100) > damage)
if (!pct_chance(damage))
continue;
nuke.nuk_effic = 0;
if (own == player->cnum) {

View file

@ -28,6 +28,7 @@
*
* Known contributors to this file:
* Dave Pare, 1986
* Markus Armbruster, 2003-2012
*/
#include <config.h>
@ -229,8 +230,8 @@ asw_shipsatxy(coord x, coord y, int wantflags, int nowantflags,
continue;
}
if (mp->m_flags & M_SUB) {
if (roll(100) > pln_hitchance(pp,
shp_hardtarget(&ship), EF_SHIP))
if (!pct_chance(pln_hitchance(pp,
shp_hardtarget(&ship), EF_SHIP)))
continue;
}
add_shiplist(ship.shp_uid, head);

View file

@ -212,7 +212,7 @@ lnd_take_casualty(int combat_mode, struct ulist *llp, int cas)
/* Have to make a retreat check */
ret_chance = llp->unit.land.lnd_retreat - llp->unit.land.lnd_effic;
if (roll(100) <= ret_chance) {
if (pct_chance(ret_chance)) {
pr("\n");
lnd_print(llp->unit.land.lnd_own, llp, "fails morale check!");
llp->unit.land.lnd_mission = 0;
@ -1099,7 +1099,7 @@ lnd_support(natid victim, natid attacker, coord x, coord y, int defending)
nreport(land.lnd_own, N_FIRE_BACK, victim, 1);
else
nreport(land.lnd_own, N_FIRE_L_ATTACK, victim, 1);
if (roll(100) < lnd_acc(&land))
if (pct_chance(lnd_acc(&land) - 1))
dam2 /= 2;
dam += dam2;
if (land.lnd_own != attacker)

View file

@ -835,7 +835,7 @@ mission_pln_sel(struct emp_qelem *list, int wantflags, int nowantflags,
}
if (pcp->pl_flags & P_A) {
if (roll(100) > pln_identchance(pp, hardtarget, EF_SHIP)) {
if (!pct_chance(pln_identchance(pp, hardtarget, EF_SHIP))) {
emp_remque(qp);
free(qp);
continue;
@ -1040,7 +1040,7 @@ air_damage(struct emp_qelem *bombers, coord x, coord y, int mission,
continue;
if (plp->pcp->pl_flags & P_A) {
if (roll(100) > pln_identchance(pp, hardtarget, EF_SHIP)) {
if (!pct_chance(pln_identchance(pp, hardtarget, EF_SHIP))) {
wu(0, pp->pln_own,
"\t%s detects sub movement in %s\n",
prplane(pp), xyas(x, y, pp->pln_own));
@ -1065,7 +1065,7 @@ air_damage(struct emp_qelem *bombers, coord x, coord y, int mission,
hitchance = 100;
else if (hardtarget != SECT_HARDTARGET)
wu(0, pp->pln_own, "\t\t%d%% hitchance...", hitchance);
if (roll(100) <= hitchance) {
if (pct_chance(hitchance)) {
newdam = pln_damage(&plp->plane, 'p', 1);
wu(0, pp->pln_own,
"\t\thit %s %s for %d damage\n",

View file

@ -163,7 +163,7 @@ msl_hit(struct plnstr *pp, int hardtarget, int type,
hit = 1;
} else {
hitchance = pln_hitchance(pp, hardtarget, type);
hit = (roll(100) <= hitchance);
hit = pct_chance(hitchance);
mpr(pp->pln_own, "\t%d%% hitchance...%s\n", hitchance,
hit ? "HIT!" : "miss");
}

View file

@ -29,7 +29,7 @@
* Known contributors to this file:
* Ken Stevens, 1995
* Steve McClure, 1996-2000
* Markus Armbruster, 2006-2010
* Markus Armbruster, 2006-2012
*/
#include <config.h>
@ -875,7 +875,7 @@ shp_missile_defense(coord dx, coord dy, natid bombown, int hardtarget)
hitchance = 0;
if (hitchance > 100)
hitchance = 100;
hit = roll(100) <= hitchance;
hit = pct_chance(hitchance);
mpr(bombown, "%s anti-missile system activated...%s\n",
cname(ship.shp_own),