aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2016-01-18 00:46:33 -0500
committerB. Watson <yalhcru@gmail.com>2016-01-18 00:46:33 -0500
commit807708211e2206d3b21c9c6353203ee40bdfe30b (patch)
treed1127405831e44923943043d5bdf0b9e40eb3cde
parente033d3cecc1707419525382f4635fcbc54df1e39 (diff)
downloadtaipan-807708211e2206d3b21c9c6353203ee40bdfe30b.tar.gz
fix "65534 ships attacking", stop assuming a bignum can handle a fraction
-rw-r--r--bigfloat.h7
-rw-r--r--taipan.c17
2 files changed, 14 insertions, 10 deletions
diff --git a/bigfloat.h b/bigfloat.h
index bcfcfd1..359438d 100644
--- a/bigfloat.h
+++ b/bigfloat.h
@@ -9,11 +9,8 @@
/* zero */
#define BIG_0 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
-/* TODO: calculate bank interest differently: this bignum
- implementation is floating point, but I might swap it out
- for an int-based one! */
-/* 1.005 (bank interest) */
-#define BIG_1_005 { 0x40, 0x01, 0x00, 0x50, 0x00, 0x00 }
+/* bank interest rate is 0.5%, or .005, or 1/200 */
+#define BIG_200 { 0x41, 0x02, 0x00, 0x00, 0x00, 0x00 }
/* bignum 100, used for score calculations in final_stats() */
#define BIG_100 { 0x41, 0x01, 0x00, 0x00, 0x00, 0x00 }
diff --git a/taipan.c b/taipan.c
index ebd023e..c440625 100644
--- a/taipan.c
+++ b/taipan.c
@@ -263,7 +263,7 @@ char *st[] = { "Critical", " Poor", " Fair",
#ifdef BIGNUM
bignum(bank) = BIG_0;
-bignum(interest_rate) = BIG_1_005;
+bignum(interest_denom) = BIG_200;
bignum(big_max_ulong) = BIG_MAX_ULONG;
#else
unsigned long bank = 0;
@@ -1003,7 +1003,8 @@ int sea_battle(int id, int num_ships) {
// if ((randi()%s0 > (num_ships * .6 / id)) && (num_ships > 2))
if((randi()%s0 > ((num_ships / 2) / id)) && (num_ships > 2)) {
static int ran;
- ran = randi()%(num_ships / 3 / id) + 1;
+ // ran = randi()%(num_ships / 3 / id) + 1;
+ ran = randclamp(num_ships / 3 / id) + 1;
num_ships -= ran;
fight_stats(num_ships, orders);
@@ -1896,9 +1897,7 @@ void transfer(void)
a few bytes of code... but it makes the code a little
bigger instead! */
int i, in_use;
-
long amount = 0;
-
if ((hkw_[0] == 0) && (hold_[0] == 0) &&
(hkw_[1] == 0) && (hold_[1] == 0) &&
(hkw_[2] == 0) && (hold_[2] == 0) &&
@@ -2006,6 +2005,9 @@ void transfer(void)
void quit(void)
{
+#ifdef BIGNUM
+ bignum(banktmp);
+#endif
unsigned char choice, sunk;
int result = 0,
damagepct;
@@ -2236,7 +2238,12 @@ void quit(void)
if(debt >= DEBT_MAX) wu_assassin = 1;
#ifdef BIGNUM
- big_mul(bank, bank, interest_rate);
+ // no good, assumes a bignum can handle a fraction
+ // big_mul(bank, bank, interest_rate);
+
+ // bank = bank + (bank / 200);
+ big_div(banktmp, bank, interest_denom);
+ big_add(bank, bank, banktmp);
#else
/* bank calculation original formula was:
bank = bank + (bank * .005);