Added CHANCE macro to replace difficult-to-read special rand() uses.
I found myself confused by the interception chances, because it looked like the chance of interceptions was decreasing slowly over time. Turns out, it was the denominator in a fraction; a "chance" of 300 meant that there was a 1 / 300 chance.
This commit is contained in:
parent
97f1f441c2
commit
6189a66866
|
@ -20,6 +20,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#ifndef DEFS_H
|
#ifndef DEFS_H
|
||||||
#define DEFS_H
|
#define DEFS_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
// Macros
|
||||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||||
#define LIMIT(x, a, b) x = ((x) < (b) ? ((x) > (a) ? (x) : (a)) : (b))
|
#define LIMIT(x, a, b) x = ((x) < (b) ? ((x) > (a) ? (x) : (a)) : (b))
|
||||||
|
@ -29,6 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define WRAP_ADD(x, y, a, b) x = (((x) + (y)) + \
|
#define WRAP_ADD(x, y, a, b) x = (((x) + (y)) + \
|
||||||
((x) + (y) < (a) ? ((b) - (a)) : 0) + \
|
((x) + (y) < (a) ? ((b) - (a)) : 0) + \
|
||||||
((x) + (y) > (b) ? ((a) - (b)) : 0))
|
((x) + (y) > (b) ? ((a) - (b)) : 0))
|
||||||
|
#define CHANCE(x) ((rand() % RAND_MAX) < ((x) * RAND_MAX))
|
||||||
#define RANDRANGE(x, y) (((x) < (y)) ? ((x) + (rand() % (1 + (y) - (x)))) : (x))
|
#define RANDRANGE(x, y) (((x) < (y)) ? ((x) + (rand() % (1 + (y) - (x)))) : (x))
|
||||||
|
|
||||||
// ALL
|
// ALL
|
||||||
|
|
|
@ -632,7 +632,7 @@ int intermission()
|
||||||
SDL_Rect r;
|
SDL_Rect r;
|
||||||
SDL_Rect destRect;
|
SDL_Rect destRect;
|
||||||
int distance = 0;
|
int distance = 0;
|
||||||
int interceptionChance;
|
double interceptionChance;
|
||||||
|
|
||||||
intermission_setStatusLines();
|
intermission_setStatusLines();
|
||||||
initShop();
|
initShop();
|
||||||
|
@ -670,17 +670,17 @@ int intermission()
|
||||||
switch (game.system)
|
switch (game.system)
|
||||||
{
|
{
|
||||||
case SYSTEM_EYANANTH:
|
case SYSTEM_EYANANTH:
|
||||||
interceptionChance = 300;
|
interceptionChance = 1. / 300.;
|
||||||
break;
|
break;
|
||||||
case SYSTEM_MORDOR:
|
case SYSTEM_MORDOR:
|
||||||
interceptionChance = 150;
|
interceptionChance = 1. / 150.;
|
||||||
break;
|
break;
|
||||||
case SYSTEM_SOL:
|
case SYSTEM_SOL:
|
||||||
// There is no chance of being interceptted after the final attack on Earth
|
// There is no chance of being interceptted after the final attack on Earth
|
||||||
if ((game.system == SYSTEM_SOL) && (systemPlanet[2].missionCompleted))
|
if ((game.system == SYSTEM_SOL) && (systemPlanet[2].missionCompleted))
|
||||||
interceptionChance = 0;
|
interceptionChance = 0;
|
||||||
else
|
else
|
||||||
interceptionChance = 100;
|
interceptionChance = 1. / 100.;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
interceptionChance = 0;
|
interceptionChance = 0;
|
||||||
|
@ -894,7 +894,7 @@ int intermission()
|
||||||
}
|
}
|
||||||
else if (interceptionChance > 0)
|
else if (interceptionChance > 0)
|
||||||
{
|
{
|
||||||
if ((rand() % interceptionChance) == 0)
|
if (CHANCE(interceptionChance))
|
||||||
{
|
{
|
||||||
game.area = MISN_INTERCEPTION;
|
game.area = MISN_INTERCEPTION;
|
||||||
rtn = 2;
|
rtn = 2;
|
||||||
|
|
Loading…
Reference in New Issue