aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2016-01-14 13:39:56 -0500
committerB. Watson <yalhcru@gmail.com>2016-01-14 13:39:56 -0500
commit3da90b381b58b4245d65b144e7af28efd8217830 (patch)
tree1ea14a778c1e45675a04f9bbb80f0a462db5589c
parent67761f7d5710fa93e2cd60726c1b8a02776077b5 (diff)
downloadtaipan-3da90b381b58b4245d65b144e7af28efd8217830.tar.gz
fix cargo throwing
-rw-r--r--taipan.c137
1 files changed, 124 insertions, 13 deletions
diff --git a/taipan.c b/taipan.c
index 0a1b015..3f28a8a 100644
--- a/taipan.c
+++ b/taipan.c
@@ -8,6 +8,10 @@
#include "sounds.h"
+#ifdef BIGNUM
+#include "bignum.h"
+#endif
+
/* define this to use cc65's rand() instead of POKEY's RANDOM
register. No need to disable this now */
#define POKEY_RANDOM
@@ -132,6 +136,69 @@ void atari_text_setup() {
/**** End of atari-specific stuff. Supposed to be, anyway. */
+#ifdef BIGNUM
+bignum(big1M) = BIG_1M;
+bignum(big100M) = BIG_100M;
+bignum(big1B) = BIG_1B;
+
+/*
+Requires a bit of explanation. b's value will always be zero or
+positive, and can range up to 1.0e+14 (aka 100 trillion).
+
+magnitude values:
+0 - result is used as-is (result range 0 - 999999)
+ b range 0 - 999999
+1 - result is in 100000's, print result/10 Million (range 0-9999)
+ b range 1,000,000 - 999,999,999 (999 Million)
+2 - result is in 100 millions, print result/10 Billion (range 0-9999)
+ b range 1,000,000,000 (1 Billion) - 999,999,999,999 (1 trillion - 1)
+
+The calling code decides whether or not to print a decimal point
+and 10ths digit (using integer math only).
+*/
+
+unsigned long cformat_big(char *magnitude, bignump b) {
+ bignum(tmp);
+ unsigned long ret;
+ if(big_cmp(b, big1M) < 0) {
+ *magnitude = 0;
+ big_to_ulong(b, &ret);
+ } else if(big_cmp(b, big1B) < 0) {
+ *magnitude = 1;
+ big_to_ulong(b, &ret);
+ ret /= 100000L;
+ } else {
+ *magnitude = 2;
+ big_div(tmp, b, big100M);
+ big_to_ulong(tmp, &ret);
+ }
+ return ret;
+}
+
+void cprintfancy_big(bignump b) {
+ char m;
+ unsigned long l = cformat_big(&m, b);
+ if(!m) {
+ // cprintf("%lu", l);
+ cprintulong(l);
+ } else {
+ if(l > 100) {
+ // cprintf("%lu ", l / 10L);
+ cprintulong(l / 10L);
+ } else {
+ // cprintf("%lu.%lu ", l / 10L, l % 10L);
+ cprintulong(l / 10L);
+ cputc('.');
+ cprintulong(l % 10L);
+ }
+ cputc(' ');
+ cputc(m == 1 ? 'M' : 'B');
+ cputs("illion");
+ }
+ cputs("\r\n");
+}
+#endif
+
/* old version of this used to just 'return randl()%clamp'.
If clamp were 0, the return value would be the unclamped
result from randl() (x % 0 == x, in cc65). If it were 1,
@@ -255,8 +322,13 @@ char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
char *st[] = { "Critical", " Poor", " Fair",
" Good", " Prime", "Perfect" };
-unsigned long cash = 0,
- bank = 0,
+#ifdef BIGNUM
+bignum(bank) = BIG_0;
+#else
+unsigned long bank = 0;
+#endif
+
+unsigned long cash = 0,
debt = 0,
booty = 0;
// ec = 20,
@@ -269,8 +341,7 @@ int base_price[4][8] = { {1000, 11, 16, 15, 14, 12, 10, 13},
{10, 12, 16, 10, 11, 13, 14, 15},
{1, 10, 11, 12, 13, 14, 15, 16} };
-int hkw_[4],
- hold_[4];
+unsigned long hkw_[4], hold_[4];
/* this really can go negative */
int hold = 0;
@@ -604,6 +675,8 @@ int sea_battle(int id, int num_ships) {
i,
input,
status;
+ char choice;
+ long amount, total;
port_stat_dirty = 1;
@@ -871,8 +944,6 @@ int sea_battle(int id, int num_ships) {
cputs("We have no guns, Taipan!!");
timed_getch(TMOUT_3S);
} else if (orders == 3) {
- static int choice;
- static long amount, total;
choice = 0;
amount = 0;
total = 0;
@@ -941,8 +1012,8 @@ int sea_battle(int id, int num_ships) {
hold += total;
ok += (total / 10);
}
- gotoxy(0, 18);
- clrtobot();
+ // gotoxy(0, 18);
+ // clrtobot();
timed_getch(TMOUT_3S);
} else {
@@ -1109,6 +1180,8 @@ int sea_battle(int id, int num_ships) {
be possible. */
if(damage < 0) damage = capacity; /* band-aid! */
+ if(damage == capacity) return 4;
+
#ifdef DAMAGE_TEST
gotoxy(0, 23);
clrtoeol();
@@ -1208,6 +1281,7 @@ void cash_or_guns(void)
#ifdef TIMEWARP
year = 1869;
cash = 1000000000L;
+ // cash = 3500000L;
bank = 1000000000L;
debt = 0;
capacity = 1000;
@@ -1403,14 +1477,15 @@ void port_stats(void)
gotoxy(6, 14);
cblank(14);
- // fancy_numbers(cash, fancy_num);
- // cputs(fancy_num);
cprintfancy(cash);
gotoxy(26, 14);
cblank(13);
- // fancy_numbers(bank, fancy_num);
- // cputs(fancy_num);
+
+#ifdef BIGNUM
+ cprintfancy_big(bank);
+#else
cprintfancy(bank);
+#endif
}
void mchenry(void)
@@ -1613,7 +1688,11 @@ void final_stats(void)
*/
if(choice == 'y') {
+#ifdef BIGNUM
+ bank = BIG_0;
+#else
bank = 0;
+#endif
hkw_[0] = 0;
hkw_[1] = 0;
hkw_[3] = 0;
@@ -1978,6 +2057,9 @@ void quit(void)
}
if(debt >= DEBT_MAX) wu_assassin = 1;
+#ifdef BIGNUM
+ big_bank_interest();
+#else
/* bank calculation original formula was:
bank = bank + (bank * .005);
int-based formula is the same, except when bank <= 200,
@@ -1989,6 +2071,7 @@ void quit(void)
else
bank++;
}
+#endif
set_prices();
@@ -2094,6 +2177,24 @@ void li_yuen_extortion(void)
return;
}
+#ifdef BIGNUM
+void you_only_have(unsigned char in_bank) {
+ gotoxy(0, 18);
+ clrtobot();
+
+ cputs("Taipan, you only have ");
+ if(in_bank)
+ cprintfancy_big(bank);
+ else
+ cprintfancy(cash);
+ cputs("\r\nin ");
+ cputs(in_bank ? "the bank" : "cash");
+ cputs(".\r\n");
+ good_joss_sound();
+
+ timed_getch(TMOUT_5S);
+}
+#else
void you_only_have(unsigned char in_bank) {
gotoxy(0, 18);
clrtobot();
@@ -2107,6 +2208,7 @@ void you_only_have(unsigned char in_bank) {
timed_getch(TMOUT_5S);
}
+#endif
void elder_brother_wu(void)
{
@@ -2128,7 +2230,13 @@ void elder_brother_wu(void)
{
break;
} else if (choice == 'y') {
- if (((int)cash == 0) && ((int)bank == 0) && (guns == 0) &&
+ if (((int)cash == 0) &&
+#ifdef BIGNUM
+ (bigcmp(bank, B_0) == 0)
+#else
+ ((int)bank == 0)
+#endif
+ && (guns == 0) &&
(hold_[0] == 0) && (hkw_[0] == 0) &&
(hold_[1] == 0) && (hkw_[1] == 0) &&
(hold_[2] == 0) && (hkw_[2] == 0) &&
@@ -2341,7 +2449,10 @@ int port_choices(void) {
clrtobot();
cursor(0);
+#ifdef BIGNUM
+#else
retire_ok = (port == 1 && ((cash + bank) >= 1000000L));
+#endif
cputs("Shall I Buy, Sell, ");
if(port ==1) {
cputs("Visit bank, Transfer\r\ncargo, ");