aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--taipan.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/taipan.c b/taipan.c
index 884af0e..a7518e6 100644
--- a/taipan.c
+++ b/taipan.c
@@ -204,15 +204,15 @@ extern void redraw_port_stat(void);
extern void __fastcall__ print_msg(const char *msg);
-/* old version of this used to just 'return randl()%clamp'.
- If clamp were 0, the return value would be the unclamped
+/* old version of this used to just 'return randl()%arg'.
+ If arg were 0, the return value would be the unmodified
result from randl() (x % 0 == x, in cc65). If it were 1,
the return value would always be 1 (no randomness there). */
-unsigned long randclamp(unsigned long clamp) {
+unsigned long randlmod(unsigned long arg) {
unsigned long r = randl();
- if(clamp == 0) return clamp;
- if(clamp == 1) return r & 0x01;
- return r % clamp;
+ if(!arg) return 0;
+ if(arg == 1) return r & 0x01;
+ return r % arg;
}
unsigned char one_chance_in(unsigned char odds) {
@@ -1312,7 +1312,7 @@ char sea_battle(char id, int num_ships) {
/* This calculation was different in the Apple and Linux ports. I went
with the Apple version. */
- booty = randclamp((long)(time / 4L * 1000L * num_ships)) + (long)(randi()%1000 + 250);
+ booty = randlmod((long)(time / 4L * 1000L * num_ships)) + (long)(randi()%1000 + 250);
/* Not ideal, but better than 'booty = 0L' I think. */
while(would_overflow(cash, booty)) {
@@ -1403,7 +1403,7 @@ char sea_battle(char id, int num_ships) {
for (j = 0; j <= 9; j++) {
if (num_ships > num_on_screen) {
if(ships_on_screen[j] == 0) {
- ships_on_screen[j] = randclamp(ec) + 20;
+ ships_on_screen[j] = randlmod(ec) + 20;
draw_lorcha(j);
num_on_screen++;
}
@@ -1471,7 +1471,7 @@ char sea_battle(char id, int num_ships) {
if((randi()%s0 > ((num_ships / 2) / id)) && (num_ships > 2)) {
static int ran;
// ran = randi()%(num_ships / 3 / id) + 1;
- ran = randclamp(num_ships / 3 / id) + 1;
+ ran = randlmod(num_ships / 3 / id) + 1;
num_ships -= ran;
fight_stats(num_ships);
@@ -1978,7 +1978,7 @@ void mchenry(void) {
/* the calculations below can & will overflow, but you'd have to
play a *long* time (like, year 2000 or later), and have a ship
capacity over maybe 10,000. */
- br = ((randclamp(60 * (time + 3) / 4) + 25 * (time + 3) / 4) * capacity / 50);
+ br = ((randlmod(60 * (time + 3) / 4) + 25 * (time + 3) / 4) * capacity / 50);
repair_price = (br * damage) + 1;
clear_msg_window();
@@ -2582,9 +2582,9 @@ void quit(void) {
if(damagepct < 34)
sunk = 0;
else if(damagepct < 67)
- sunk = randclamp(3) == 0;
+ sunk = randlmod(3) == 0;
else
- sunk = randclamp(3) != 0;
+ sunk = randlmod(3) != 0;
if(sunk) {
// cputs("We're going down");
@@ -2702,7 +2702,7 @@ void li_yuen_extortion(void) {
}
// amount = ((cash / i) * ((float) randi() / RAND_MAX)) + j;
- amount = randclamp((cash >> (i - 1))) + j;
+ amount = randlmod((cash >> (i - 1))) + j;
if(!amount) return; /* asking for 0 is dumb */
@@ -3527,7 +3527,7 @@ int main(void) {
// the 1.8 is now a 2
unsigned long fine = 0;
if(cash > 0)
- fine = randclamp(cash >> 1) + 1;
+ fine = randlmod(cash >> 1) + 1;
hold += hold_[0];
hold_[0] = 0;
@@ -3561,7 +3561,7 @@ int main(void) {
{
// hkw_[i] = ((hkw_[i] / 1.8) * ((float) randi() / RAND_MAX));
// the 1.8 is now a 2
- hkw_[i] = randclamp(hkw_[i] >> 1);
+ hkw_[i] = randlmod(hkw_[i] >> 1);
}
port_stats();
@@ -3596,7 +3596,7 @@ int main(void) {
if((cash > 25000) && (one_chance_in(20))) {
// float robbed = ((cash / 1.4) * ((float) randi() / RAND_MAX));
// line below changes the 1.4 to 1.5
- unsigned long robbed = randclamp((cash >> 2) + (cash >> 1));
+ unsigned long robbed = randlmod((cash >> 2) + (cash >> 1));
cash -= robbed;
cash_dirty = 1;