aboutsummaryrefslogtreecommitdiff
path: root/taipan.c
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2016-01-30 20:29:59 -0500
committerB. Watson <yalhcru@gmail.com>2016-01-30 20:29:59 -0500
commit09b25847717073929eb0548ac41d23b6cc224f32 (patch)
treee8f5b5c33d9c355af495372df692c0dd2e223b21 /taipan.c
parentfee72cdb3651d2e5bfd5fe525c6498dc01fbbe01 (diff)
downloadtaipan-09b25847717073929eb0548ac41d23b6cc224f32.tar.gz
much code-crunching. almost 4K free now.
Diffstat (limited to 'taipan.c')
-rw-r--r--taipan.c798
1 files changed, 434 insertions, 364 deletions
diff --git a/taipan.c b/taipan.c
index d734362..b3577ff 100644
--- a/taipan.c
+++ b/taipan.c
@@ -30,7 +30,7 @@
/* define this to start the game in the year 1869, with
1000 capacity, 20 guns, and 1 billion cash and bank. */
-// #define TIMEWARP
+#define TIMEWARP
/* define this to start the game in a 99% damaged ship */
// #define ALMOST_DEAD
@@ -148,6 +148,10 @@ unsigned long randclamp(unsigned long clamp) {
return r % clamp;
}
+unsigned char chance_1_in(unsigned char odds) {
+ return ( (randi() % odds) == 0);
+}
+
/* print 'count' spaces, but leave the cursor where it was.
TODO: rewrite in asm. */
void cblank(unsigned char count) {
@@ -240,6 +244,10 @@ void cprintfancy_centered(unsigned long num);
void too_much_cash(void);
char would_overflow(unsigned long a, unsigned long b);
int get_time(void);
+void cprint_taipan_comma(void);
+void cprint_taipan_bang(void);
+void cprint_taipan_bangbang(void);
+void cprint_taipan_period(void);
unsigned char firmpos;
@@ -286,9 +294,11 @@ int base_price[4][8] = { {1000, 11, 16, 15, 14, 12, 10, 13},
32768 of some item later in the game. You won't be able to
leave port, so you'll have to get rid of it on the same turn,
but we still have to stop it overflowing a 16-bit int.
- I'm not convinced hkw_ needs to be long, since it's
- limited to 10000 of each item. */
-unsigned long hkw_[4], hold_[4];
+
+ hkw_ doesn't need to be long, since you can never have more
+ than 10,000 of any one item. */
+unsigned int hkw_[4];
+unsigned long hold_[4];
/* this really can go negative (meaning, your ship is
overloaded). It needs to be a long though. At some
@@ -321,6 +331,44 @@ unsigned char port = 1,
// displaying ship status.
long damage = 0, capacity = 60, newdamage;
+void cprint_bad_joss() {
+ cputs("Bad Joss!!\r\n");
+}
+
+void crlf(void) {
+ cputs("\r\n");
+}
+
+void cprint_taipan(void) {
+ cputs("Taipan");
+}
+
+void comma_space(void) {
+ cputs(", ");
+}
+
+void cprint_taipan_comma(void) {
+ cprint_taipan();
+ comma_space();
+}
+
+void cprint_taipan_bang(void) {
+ comma_space();
+ cprint_taipan();
+ cputc('!');
+}
+
+void cprint_taipan_bangbang(void) {
+ cprint_taipan_bang();
+ cputc('!');
+}
+
+void cprint_taipan_period(void) {
+ comma_space();
+ cprint_taipan();
+ cputc('.');
+}
+
#ifdef BIGNUM
bignum(big1T) = BIG_1T;
bignum(big1B) = BIG_1B;
@@ -448,7 +496,8 @@ void clear_msg_window(void) {
void overload(void) {
compradores_report();
- cputs("Your ship is overloaded, Taipan!!");
+ cputs("Your ship is overloaded");
+ cprint_taipan_bangbang();
good_joss_sound();
timed_getch();
return;
@@ -489,7 +538,7 @@ void new_ship(void) {
damage = 0;
}
- if ((randi()%2 == 0) && (guns < 1000))
+ if (chance_1_in(2) && (guns < 1000))
{
port_stats();
new_gun();
@@ -728,7 +777,7 @@ int sea_battle(int id, int num_ships) {
ok,
ik,
i,
- input,
+ // input,
status;
char choice, flashctr;
unsigned long amount, total;
@@ -803,7 +852,8 @@ int sea_battle(int id, int num_ships) {
plus_or_space(num_ships > num_on_screen);
gotoxy(0, 16);
- cputs("\r\n");
+ // cputs("\r\n");
+ crlf();
orders = set_orders(orders);
@@ -812,8 +862,19 @@ int sea_battle(int id, int num_ships) {
if(!orders) {
gotoxy(0, 3);
clrtoeol();
- cputs("Taipan, what shall we do??\r\n(Fight, Run, Throw cargo)");
+ cprint_taipan_comma();
+ cputs("what shall we do??\r\n(Fight, Run, Throw cargo)");
under_attack_sound();
+
+ while(! (orders = set_orders(orders)) )
+ ;
+
+ gotoxy(0, 3);
+ clrtoeol();
+ gotoxy(0, 4);
+ clrtoeol();
+
+ /*
while ((input != 'f') &&
(input != 'r') &&
(input != 't'))
@@ -831,6 +892,7 @@ int sea_battle(int id, int num_ships) {
} else {
orders = 3;
}
+ */
}
}
@@ -843,12 +905,14 @@ int sea_battle(int id, int num_ships) {
ik = 1;
gotoxy(0, 3);
clrtoeol();
- cputs("Aye, we'll fight 'em, Taipan.");
+ cputs("Aye, we'll fight 'em");
+ cprint_taipan_period();
timed_getch();
gotoxy(0, 3);
clrtoeol();
- cputs("We're firing on 'em, Taipan!");
+ cputs("We're firing on 'em");
+ cprint_taipan_bang();
timed_getch();
for(i = 1; i <= guns; i++) {
@@ -874,7 +938,8 @@ int sea_battle(int id, int num_ships) {
plus_or_space(num_ships > num_on_screen);
gotoxy(0, 16);
- cputs("\r\n");
+ // cputs("\r\n");
+ crlf();
do {
targeted = randi()%10;
@@ -916,10 +981,12 @@ int sea_battle(int id, int num_ships) {
if(sk > 0) {
cputs("Sunk ");
cprintulong(sk);
- cputs(" of the buggers, Taipan!");
+ cputs(" of the buggers");
+ cprint_taipan_bang();
bad_joss_sound();
} else {
- cputs("Hit 'em, but didn't sink 'em, Taipan!");
+ cputs("Hit 'em, but didn't sink 'em");
+ cprint_taipan_bang();
}
timed_getch();
@@ -934,7 +1001,8 @@ int sea_battle(int id, int num_ships) {
gotoxy(0, 3);
clrtoeol();
cprintulong(ran);
- cputs(" ran away, Taipan!");
+ cputs(" ran away");
+ cprint_taipan_bang();
bad_joss_sound();
if(num_ships <= 10) {
@@ -959,7 +1027,8 @@ int sea_battle(int id, int num_ships) {
} else if ((orders == 1) && (guns == 0)) {
gotoxy(0, 3);
clrtoeol();
- cputs("We have no guns, Taipan!!");
+ cputs("We have no guns");
+ cprint_taipan_bangbang();
timed_getch();
} else if (orders == 3) {
choice = 0;
@@ -1016,7 +1085,8 @@ int sea_battle(int id, int num_ships) {
if(total > 0) {
gotoxy(0, 3);
clrtoeol();
- cputs("Let's hope we lose 'em, Taipan!");
+ cputs("Let's hope we lose 'em");
+ cprint_taipan_bang();
bad_joss_sound();
if (choice < 4) {
hold_[choice] -= amount;
@@ -1030,14 +1100,13 @@ int sea_battle(int id, int num_ships) {
hold += total;
ok += (total / 10);
}
- // gotoxy(0, 18);
- // clrtobot();
timed_getch();
} else {
gotoxy(0, 3);
clrtoeol();
- cputs("There's nothing there, Taipan!");
+ cputs("There's nothing there");
+ cprint_taipan_bang();
good_joss_sound();
timed_getch();
@@ -1048,7 +1117,8 @@ int sea_battle(int id, int num_ships) {
if(orders == 2) {
gotoxy(0, 3);
clrtoeol();
- cputs("Aye, we'll run, Taipan.");
+ cputs("Aye, we'll run");
+ cprint_taipan_period();
timed_getch();
}
@@ -1057,7 +1127,8 @@ int sea_battle(int id, int num_ships) {
// flushinp();
gotoxy(0, 3);
clrtoeol();
- cputs("We got away from 'em, Taipan!");
+ cputs("We got away from 'em");
+ cprint_taipan_bang();
good_joss_sound();
timed_getch();
num_ships = 0;
@@ -1067,7 +1138,7 @@ int sea_battle(int id, int num_ships) {
cputs("Couldn't lose 'em.");
timed_getch();
- if((num_ships > 2) && (randi()%5 == 0)) {
+ if((num_ships > 2) && (chance_1_in(5))) {
static int lost;
lost = (randi()%num_ships / 2) + 1;
@@ -1102,7 +1173,8 @@ int sea_battle(int id, int num_ships) {
if(num_ships > 0) {
gotoxy(0, 3);
clrtoeol();
- cputs("They're firing on us, Taipan!");
+ cputs("They're firing on us");
+ cprint_taipan_bang();
timed_getch();
hide_cursor();
@@ -1113,7 +1185,8 @@ int sea_battle(int id, int num_ships) {
gotoxy(0, 3);
clrtoeol();
- cputs("We've been hit, Taipan!!");
+ cputs("We've been hit");
+ cprint_taipan_bangbang();
under_attack_sound();
timed_getch();
@@ -1133,7 +1206,8 @@ int sea_battle(int id, int num_ships) {
fight_stats(num_ships, orders);
gotoxy(0, 3);
clrtoeol();
- cputs("The buggers hit a gun, Taipan!!");
+ cputs("The buggers hit a gun");
+ cprint_taipan_bangbang();
under_attack_sound();
fight_stats(num_ships, orders);
update_guns();
@@ -1186,7 +1260,7 @@ int sea_battle(int id, int num_ships) {
cgetc();
#endif
- if((id == GENERIC) && (randi()%20 == 0)) {
+ if((id == GENERIC) && (chance_1_in(20))) {
return 2;
}
}
@@ -1197,7 +1271,8 @@ int sea_battle(int id, int num_ships) {
fight_stats(num_ships, orders);
gotoxy(0, 3);
clrtoeol();
- cputs("We got 'em all, Taipan!");
+ cputs("We got 'em all");
+ cprint_taipan_bang();
bad_joss_sound();
timed_getch();
@@ -1322,16 +1397,11 @@ void set_prices(void) {
char i;
for(i = 0; i < 4; ++i)
price[i] = base_price[i][port] / 2 * (randi()%3 + 1) * base_price[i][0];
-
- /*
- // using above for loop instead of the below, saves 142 bytes!
- price[0] = base_price[0][port] / 2 * (randi()%3 + 1) * base_price[0][0];
- price[1] = base_price[1][port] / 2 * (randi()%3 + 1) * base_price[1][0];
- price[2] = base_price[2][port] / 2 * (randi()%3 + 1) * base_price[2][0];
- price[3] = base_price[3][port] / 2 * (randi()%3 + 1) * base_price[3][0];
- */
}
+unsigned int warehouse_in_use() {
+ return hkw_[0] + hkw_[1] + hkw_[2] + hkw_[3];
+}
void port_stats(void)
{
@@ -1399,7 +1469,8 @@ void port_stats(void)
cputs(", Hong Kong");
gotoxy(21, 4);
- in_use = hkw_[0] + hkw_[1] + hkw_[2] + hkw_[3];
+ // in_use = hkw_[0] + hkw_[1] + hkw_[2] + hkw_[3];
+ in_use = warehouse_in_use();
cblank(5);
cprintulong(in_use);
@@ -1468,20 +1539,13 @@ void port_stats(void)
revers(0);
gotoxy(28, 9);
- // fancy_numbers(debt, fancy_num);
- // gotox(34 - strlen(fancy_num) / 2);
clrtoeol();
- // revers(1);
cprintfancy_centered(debt);
- // cputs(fancy_num);
- // revers(0);
gotoxy(29, 12);
clrtoeol();
i = status / 20;
- if (i < 2) {
- revers(1);
- }
+ if(i < 2) revers(1);
cputs(st[i]);
cputc(':');
cprintulong(status);
@@ -1490,9 +1554,9 @@ void port_stats(void)
gotoxy(6, 14);
cblank(14);
cprintfancy(cash);
+
gotoxy(26, 14);
cblank(13);
-
#ifdef BIGNUM
cprintfancy_big(bank);
#else
@@ -1505,7 +1569,8 @@ void mchenry(void)
static int choice;
compradores_report();
- cputs("Taipan, Mc Henry from the Hong Kong\r\n");
+ cprint_taipan_comma();
+ cputs("Mc Henry from the Hong Kong\r\n");
cputs("Shipyards has arrived!! He says, 'I see\r\n");
cputs("ye've a wee bit of damage to yer ship.'\r\n");
cputs("Will ye be wanting repairs? ");
@@ -1564,7 +1629,12 @@ void mchenry(void)
}
void retire_blanks(void) {
- cputs(" \r\n");
+ char i;
+ for(i = 0; i < 29; ++i) cputc(' ');
+ crlf();
+
+ // above loop saves a measly 6 bytes over this:
+ // cputs(" \r\n");
}
#ifdef BIGNUM
@@ -1586,7 +1656,6 @@ void aire(void) {
#endif
void retire(void) {
- // cursor(0);
compradores_report();
revers(1);
retire_blanks();
@@ -1644,8 +1713,8 @@ void final_stats(void)
port_stat_dirty = 1;
clrscr();
- cputs("Your final status:\r\n\r\n");
- cputs("Net cash: ");
+ cputs("Your final status:\r\n\r\n"
+ "Net cash: ");
#ifdef BIGNUM
cprintfancy_big(finalcash);
#else
@@ -1655,8 +1724,8 @@ void final_stats(void)
cprintulong(capacity);
cputs(" units with ");
cprintulong(guns);
- cputs(" guns\r\n\r\n");
- cputs("You traded for ");
+ cputs(" guns\r\n\r\n"
+ "You traded for ");
cprintulong(years);
cputs(" year");
if (years != 1)
@@ -1684,8 +1753,8 @@ void final_stats(void)
{
cputs("Have you considered a land based job?\r\n\r\n\r\n");
} else if (score < 0) {
- cputs("The crew has requested that you stay on\r\n");
- cputs("shore for their safety!!\r\n\r\n");
+ cputs("The crew has requested that you stay on\r\n"
+ "shore for their safety!!\r\n\r\n");
} else {
cputs("\r\n\r\n\r\n");
}
@@ -1693,7 +1762,8 @@ void final_stats(void)
cputc(17); // upper left corner
chline(31);
cputc(5); // upper right corner
- cputs("\r\n");
+ // cputs("\r\n");
+ crlf();
cputc('|');
if (score > 49999L)
@@ -1793,21 +1863,24 @@ void final_stats(void)
exit(0);
}
+char have_no_cargo(void) {
+ char i;
+ for(i = 0; i < 4; ++i)
+ if(hkw_[i] || hold_[i]) return 0;
+ return 1;
+}
+
void transfer(void)
{
- /* you might think making i an unsigned char would save
- a few bytes of code... but it makes the code a little
- bigger instead! */
int i, in_use;
unsigned long amount = 0;
- if ((hkw_[0] == 0) && (hold_[0] == 0) &&
- (hkw_[1] == 0) && (hold_[1] == 0) &&
- (hkw_[2] == 0) && (hold_[2] == 0) &&
- (hkw_[3] == 0) && (hold_[3] == 0))
- {
+
+ if(have_no_cargo()) {
gotoxy(0, 22);
clrtobot();
- cputs("You have no cargo, Taipan.\r\n");
+ cputs("You have no cargo");
+ cprint_taipan_period();
+ crlf();
good_joss_sound();
timed_getch();
@@ -1832,7 +1905,8 @@ void transfer(void)
}
if (amount <= hold_[i])
{
- in_use = hkw_[0] + hkw_[1] + hkw_[2] + hkw_[3];
+ // in_use = hkw_[0] + hkw_[1] + hkw_[2] + hkw_[3];
+ in_use = warehouse_in_use();
if ((in_use + amount) <= 10000)
{
hold_[i] -= amount;
@@ -1841,13 +1915,14 @@ void transfer(void)
break;
} else if (in_use == 10000) {
gotoxy(0, 21);
- cputs("Your warehouse is full, Taipan!");
+ cputs("Your warehouse is full");
+ cprint_taipan_bang();
good_joss_sound();
} else {
gotoxy(0, 21);
cputs("Your warehouse will only hold an\r\nadditional ");
cprintulong(10000 - in_use);
- cputs(", Taipan!");
+ cprint_taipan_bang();
good_joss_sound();
timed_getch();
@@ -1858,7 +1933,8 @@ void transfer(void)
// clrtobot();
cputs("You have only ");
cprintulong(hold_[i]);
- cputs(", Taipan.\r\n");
+ // cputs(", Taipan.\r\n");
+ cprint_taipan_period();
good_joss_sound();
timed_getch();
@@ -1893,7 +1969,9 @@ void transfer(void)
// clrtobot();
cputs("You have only ");
cprintulong(hkw_[i]);
- cputs(", Taipan.\r\n");
+ cprint_taipan_period();
+ // cputs("\r\n");
+ crlf();
timed_getch();
}
@@ -1915,10 +1993,23 @@ void quit(void)
damagepct;
compradores_report();
- cputs("Taipan, do you wish me to go to:\r\n");
+ cprint_taipan_comma();
+ cputs("do you wish me to go to:\r\n");
+
+ for(choice = 1; choice < 8; ++choice) {
+ if(choice == 7) crlf();
+ cputc(choice + '0');
+ cputs(") ");
+ cputs(location[choice]);
+ if(choice != 7) comma_space();
+ }
+ cputs(" ? ");
+
+ /*
cputs("1) Hong Kong, 2) Shanghai, 3) Nagasaki,\r\n");
cputs("4) Saigon, 5) Manila, 6) Singapore, or\r\n");
cputs("7) Batavia ? ");
+ */
for (;;)
{
@@ -1929,7 +2020,8 @@ void quit(void)
if (choice == port)
{
- cputs("\r\n\nYou're already here, Taipan.");
+ cputs("\r\n\nYou're already here");
+ cprint_taipan_period();
good_joss_sound();
timed_getch();
} else if ((choice >= 1) && (choice <= 7)) {
@@ -1956,7 +2048,10 @@ void quit(void)
cprintulong(num_ships);
cputs(" hostile ship");
if(num_ships != 1) cputc('s');
- cputs(" approaching, Taipan!\r\n");
+ // cputs(" approaching, Taipan!\r\n");
+ cputs(" approaching");
+ cprint_taipan_bang();
+ crlf();
under_attack_sound();
timed_getch();
@@ -1979,9 +2074,12 @@ void quit(void)
if (((result == 0) && (randi()%(4 + (8 * li))) == 0) || (result == 2))
{
clear_msg_window();
- // gotoxy(0, 18);
- // clrtobot();
- cputs("Li Yuen's pirates, Taipan!!\r\n\n");
+ // cputs("Li Yuen's pirates, Taipan!!\r\n");
+ cputs("Li Yuen's pirates");
+ cprint_taipan_bangbang();
+ // cputs("\r\n");
+ crlf();
+ crlf();
bad_joss_sound();
timed_getch();
@@ -2000,8 +2098,10 @@ void quit(void)
num_ships = randi()%((capacity / 5) + guns) + 5;
cprintulong(num_ships);
- cputs(" ships of Li Yuen's pirate\r\n");
- cputs("fleet, Taipan!!\r\n");
+ cputs(" ships of Li Yuen's pirate\r\nfleet");
+ cprint_taipan_bangbang();
+ // cputs(" ships of Li Yuen's pirate\r\n");
+ // cputs("fleet, Taipan!!\r\n");
under_attack_sound();
timed_getch();
@@ -2024,8 +2124,8 @@ void quit(void)
if (result == 1)
{
// fancy_numbers(booty, fancy_num);
- cputs("We captured some booty.\r\n");
- cputs("It's worth ");
+ cputs("We captured some booty.\r\n"
+ "It's worth ");
// cputs(fancy_num);
cprintfancy(booty);
cputc('!');
@@ -2035,8 +2135,9 @@ void quit(void)
cputs("We made it!");
good_joss_sound();
} else {
- cputs("The buggers got us, Taipan!!!\r\n");
- cputs("It's all over, now!!!");
+ cputs("The buggers got us");
+ cprint_taipan_bangbang();
+ cputs("!\r\nIt's all over, now!!!");
timed_getch();
@@ -2047,17 +2148,19 @@ void quit(void)
timed_getch();
}
- if (randi()%10 == 0)
- {
+ if(chance_1_in(10)) {
clear_msg_window();
// gotoxy(0, 18);
// clrtobot();
- cputs("Storm, Taipan!!\r\n\n");
+ cputs("Storm");
+ cprint_taipan_bangbang();
+ // cputs("\r\n");
+ crlf();
+ crlf();
bad_joss_sound();
timed_getch();
- if (randi()%30 == 0)
- {
+ if(chance_1_in(30)) {
cputs(" I think we're going down!!\r\n\n");
timed_getch();
@@ -2076,7 +2179,10 @@ void quit(void)
sunk = randclamp(3) != 0;
if(sunk) {
- cputs("We're going down, Taipan!!\r\n");
+ cputs("We're going down");
+ cprint_taipan_bangbang();
+ // cputs("\r\n");
+ crlf();
under_attack_sound();
timed_getch();
@@ -2088,18 +2194,13 @@ void quit(void)
bad_joss_sound();
timed_getch();
- if (randi()%3 == 0)
- {
+ if(chance_1_in(3)) {
int orig = port;
- while (port == orig)
- {
- port = randi()%7 + 1;
- }
+ while(port == orig)
+ port = randi()%7 + 1;
clear_msg_window();
- // gotoxy(0, 18);
- // clrtobot();
cputs("We've been blown off course\r\nto ");
cputs(location[port]);
timed_getch();
@@ -2107,8 +2208,7 @@ void quit(void)
}
month++;
- if (month == 13)
- {
+ if(month == 13) {
month = 1;
year++;
ec += 10;
@@ -2214,8 +2314,7 @@ void li_yuen_extortion(void) {
compradores_report();
cputs("Li Yuen asks ");
cprintfancy(amount);
- cputs(" in donation\r\nto the temple of Tin Hau, the Sea\r\n");
- cputs("Goddess. Will you pay? ");
+ cputs(" in donation\r\nto the temple of Tin Hau, the Sea\r\nGoddess. Will you pay? ");
choice = yngetc(0);
if(choice == 'y') {
@@ -2226,12 +2325,12 @@ void li_yuen_extortion(void) {
clear_msg_window();
// gotoxy(0, 18);
// clrtobot();
- cputs("Taipan, you do not have enough cash!!\r\n\r\n");
+ cprint_taipan_comma();
+ cputs("you do not have enough cash!!\r\n\r\n");
timed_getch();
- cputs("Do you want Elder Brother Wu to make up\r\n");
- cputs("the difference for you? ");
+ cputs("Do you want Elder Brother Wu to make up\r\nthe difference for you? ");
choice = yngetc(0);;
clear_msg_window();
@@ -2243,16 +2342,19 @@ void li_yuen_extortion(void) {
cash = 0;
li = 1;
- cputs("Elder Brother has given Li Yuen the\r\n");
- cputs("difference between what he wanted and\r\n");
- cputs("your cash on hand and added the same\r\n");
- cputs("amount to your debt.\r\n");
+ cputs("Elder Brother has given Li Yuen the\r\n"
+ "difference between what he wanted and\r\n"
+ "your cash on hand and added the same\r\n"
+ "amount to your debt.\r\n");
} else {
cash = 0;
- cputs("Very well. Elder Brother Wu will not pay\r\n");
- cputs("Li Yuen the difference. I would be very\r\n");
- cputs("wary of pirates if I were you, Taipan.\r\n");
+ cputs("Very well. Elder Brother Wu will not pay\r\n"
+ "Li Yuen the difference. I would be very\r\n"
+ "wary of pirates if I were you");
+ cprint_taipan_period();
+ // cputs("\r\n");
+ crlf();
}
timed_getch();
}
@@ -2267,7 +2369,8 @@ void you_only_have(unsigned char in_bank) {
// gotoxy(0, 18);
// clrtobot();
- cputs("Taipan, you only have ");
+ cprint_taipan_comma();
+ cputs("you only have ");
if(in_bank)
cprintfancy_big(bank);
else
@@ -2285,7 +2388,8 @@ void you_only_have(unsigned char in_bank) {
// gotoxy(0, 18);
// clrtobot();
- cputs("Taipan, you only have ");
+ cprint_taipan_comma();
+ cputs("you only have ");
cprintfancy(in_bank ? bank : cash);
cputs("\r\nin ");
cputs(in_bank ? "the bank" : "cash");
@@ -2303,8 +2407,7 @@ void elder_brother_wu(void)
unsigned long wu = 0;
compradores_report();
- cputs("Do you have business with Elder Brother\r\n");
- cputs("Wu, the moneylender? ");
+ cputs("Do you have business with Elder Brother\r\nWu, the moneylender? ");
for (;;)
{
@@ -2313,141 +2416,136 @@ void elder_brother_wu(void)
// choice = get_one();
choice = yngetc('n');
if ((choice == 'n') || choice == 0)
- {
break;
- } else if (choice == 'y') {
- if (((int)cash == 0) &&
+
+ if ((cash == 0) &&
#ifdef BIGNUM
- (bank[0] == '\0')
+ (big_cmp(bank, big0) == 0)
#else
- ((int)bank == 0)
+ (bank == 0)
#endif
- && (guns == 0) &&
- (hold_[0] == 0) && (hkw_[0] == 0) &&
- (hold_[1] == 0) && (hkw_[1] == 0) &&
- (hold_[2] == 0) && (hkw_[2] == 0) &&
- (hold_[3] == 0) && (hkw_[3] == 0))
- {
- int i = randi()%1500 + 500,
- j;
+ && (guns == 0) &&
+ have_no_cargo())
+ {
+ int i = randi()%1500 + 500,
+ j;
- wu_bailout++;
- j = randi()%2000 * wu_bailout + 1500;
+ wu_bailout++;
+ j = randi()%2000 * wu_bailout + 1500;
- for (;;)
- {
+ for (;;)
+ {
+ compradores_report();
+ cputs("Elder Brother is aware of your plight,\r\n"
+ "Taipan. He is willing to loan you an\r\n"
+ "additional ");
+ cprintulong(i);
+ cputs(" if you will pay back\r\n");
+ cprintulong(j);
+ cputs(". Are you willing, Taipan? ");
+
+ choice = get_one();
+ if(choice != 'y') {
compradores_report();
- cputs("Elder Brother is aware of your plight,\r\n");
- cputs("Taipan. He is willing to loan you an\r\n");
- cputs("additional ");
- cprintulong(i);
- cputs(" if you will pay back\r\n");
- cprintulong(j);
- cputs(". Are you willing, Taipan? ");
-
- choice = get_one();
- if (choice == 'n')
- {
- compradores_report();
- cputs("Very well, Taipan, the game is over!\r\n");
- under_attack_sound();
-
- timed_getch();
-
- final_stats();
- } else if (choice == 'y') {
- cash += i;
- debt += j;
- port_stats();
+ cputs("Very well, Taipan, the game is over!\r\n");
+ under_attack_sound();
- compradores_report();
- cputs("Very well, Taipan. Good joss!!\r\n");
- bad_joss_sound();
+ timed_getch();
- timed_getch();
+ final_stats();
+ } else {
+ cash += i;
+ debt += j;
+ port_stats();
- return;
- }
- }
- } else if ((cash > 0) && (debt != 0)) {
- for (;;)
- {
compradores_report();
- cputs("How much do you wish to repay\r\n");
- cputs("him? ");
+ cputs("Very well, Taipan. Good joss!!\r\n");
+ bad_joss_sound();
- wu = get_num();
- if (wu == UINT32_MAX)
- {
- wu = cash;
- }
- if (wu <= cash)
- {
- if(wu > debt) wu = debt;
- cash -= wu;
- debt -= wu;
- /* // currently debt is unsigned so the negative debt
- // bug (or feature) is unimplemented.
- if ((wu > debt) && (debt > 0))
- {
- debt -= (wu + 1);
- } else {
- debt -= wu;
- }
- */
- break;
- } else {
- you_only_have(0);
- }
- }
- }
- port_stats();
+ timed_getch();
- for (;;)
- {
+ return;
+ }
+ }
+ } else if ((cash > 0) && (debt != 0)) {
+ for (;;)
+ {
compradores_report();
- cputs("How much do you wish to\r\n");
- cputs("borrow? ");
+ cputs("How much do you wish to repay\r\nhim? ");
+
+ wu = get_num();
+ if(wu == UINT32_MAX)
+ wu = cash;
+
+ if(wu <= cash) {
+ if(wu > debt) wu = debt;
+ cash -= wu;
+ debt -= wu;
+
+ /*
+ // currently debt is unsigned so the negative debt
+ // bug (or feature) is unimplemented.
+ if ((wu > debt) && (debt > 0))
+ debt -= (wu + 1);
+ else
+ debt -= wu;
+ */
- wu = get_num();
- if(wu == UINT32_MAX)
- {
- wu = (cash * 2);
- }
- if((wu <= (cash * 2)) && !would_overflow(cash, wu))
- {
- cash += wu;
- debt += wu;
- break;
- } else {
- cputs("\r\n\r\nHe won't loan you so much, Taipan!");
- good_joss_sound();
- timed_getch();
- }
- }
- port_stats();
+ break;
+ } else {
+ you_only_have(0);
+ }
+ }
+ }
+ port_stats();
- // break;
+ for (;;)
+ {
+ compradores_report();
+ cputs("How much do you wish to\r\nborrow? ");
- /* do NOT let him steal the money back on the SAME TURN
- he loans it to you! */
- return;
- }
+ wu = get_num();
+
+ // TODO: handle case where (cash * 2) would overflow!
+ if(wu == UINT32_MAX)
+ {
+ wu = (cash * 2);
+ }
+ if((wu <= (cash * 2)) && !would_overflow(cash, wu))
+ {
+ cash += wu;
+ debt += wu;
+ break;
+ } else {
+ cputs("\r\n\nHe won't loan you so much");
+ cprint_taipan_bang();
+ good_joss_sound();
+ timed_getch();
+ }
+ }
+ port_stats();
+
+ // break;
+
+ /* do NOT let him steal the money back on the SAME TURN
+ he loans it to you! */
+ return;
}
- if ((debt > 20000) && (cash > 0) && (randi()%5 == 0))
- {
+ if((debt > 20000) && (cash > 0) && (chance_1_in(5))) {
int num = randi()%3 + 1;
cash = 0;
port_stats();
compradores_report();
- cputs("Bad joss!!\r\n");
+ cprint_bad_joss();
cprintulong(num);
- cputs(" of your bodyguards have been killed\r\n");
- cputs("by cutthroats and you have been robbed\r\n");
- cputs("of all of your cash, Taipan!!\r\n");
+ cputs(" of your bodyguards have been killed\r\n"
+ "by cutthroats and you have been robbed\r\n"
+ "of all of your cash");
+ cprint_taipan_bangbang();
+ crlf();
under_attack_sound();
timed_getch();
@@ -2456,34 +2554,15 @@ void elder_brother_wu(void)
return;
}
-void good_prices(void)
-{
- // static char item[14];
-
+void good_prices(void) {
unsigned char i = randi()%4;
- /*
- int i = randi()%4,
- j = randi()%2;
- */
-
- /*
- if (i == 0)
- {
- strcpy(item, "Opium");
- } else if (i == 1) {
- strcpy(item, "Silk");
- } else if (i == 2) {
- strcpy(item, "Arms");
- } else {
- strcpy(item, "General Cargo");
- }
- */
compradores_report();
- cputs("Taipan!! The price of ");
- // cputs(item);
+ cprint_taipan();
+ cputs("!! The price of ");
cputs(item[i]);
cputs("\r\n has ");
+
if(randi()&1) {
price[i] *= (randi()%5 + 5);
cputs("risen");
@@ -2495,18 +2574,6 @@ void good_prices(void)
}
cputs(" to ");
- /*
- if (j == 0)
- {
- price[i] = price[i] / 5;
- cputs("dropped");
- } else {
- price[i] = price[i] * (randi()%5 + 5);
- cputs("risen");
- }
- cputs(" to ");
- */
-
cprintulong(price[i]);
cputs("!!\r\n");
good_joss_sound();
@@ -2515,12 +2582,31 @@ void good_prices(void)
}
int port_choices(void) {
- int choice = 0;
+ char choice;
char retire_ok = 0;
compradores_report();
- cputs("Taipan, present prices per unit here are"); /* NB: exactly 40 cols */
+ cprint_taipan_comma();
+ cputs("present prices per unit here are"); /* NB: exactly 40 cols */
+
+ // ===> free code space $0f7b (3936, 3.9K)
+ // saves 46 bytes:
+ for(choice = 0; choice < 4; ++choice) {
+ gotox(3 + ((choice & 1) * 16));
+ if(choice == 3)
+ cputs("General");
+ else
+ cputs(item[choice]);
+ cputc(':');
+ gotox(11 + ((choice & 1) * 18));
+ cprintulong(price[choice]);
+ if(choice == 1) crlf();
+ }
+
+ /*
+ // original version:
+ // ===> free code space $0f32 (3890, 3.8K)
cputs(" Opium: Silk:\r\n");
cputs(" Arms: General:\r\n");
gotoxy(11, 19);
@@ -2531,37 +2617,48 @@ int port_choices(void) {
cprintulong(price[2]);
gotoxy(29, 20);
cprintulong(price[3]);
+ */
gotoxy(0, 22);
clrtobot();
- // cursor(0);
#ifdef BIGNUM
- // TODO: make this smaller!
if(port == 1) {
+ /*
+ // this speeds things up ever so slightly when cash is
+ // low, but costs 68 bytes of code. Leave out for now.
if(cash > 1000000L) {
retire_ok = 1;
} else if(big_cmp(bank, big1M) >= 0) {
retire_ok = 1;
} else {
+ */
bignum(tmp);
ulong_to_big(cash, tmp);
big_add(tmp, tmp, bank);
- if(big_cmp(tmp, big1M) >= 0)
- retire_ok = 1;
+ retire_ok = (big_cmp(tmp, big1M) >= 0);
+
+ // if(big_cmp(tmp, big1M) >= 0)
+ // retire_ok = 1;
+
+ /*
}
+ */
}
#else
retire_ok = (port == 1 && ((cash + bank) >= 1000000L));
#endif
+
cputs("Shall I Buy, Sell, ");
- if(port ==1) {
+
+ if(port == 1)
cputs("Visit bank, Transfer\r\ncargo, ");
- }
+
if(!retire_ok) cputs("or ");
+
cputs("Quit trading");
+
if(retire_ok) cputs(", or Retire");
- // cursor(1);
cputs("? ");
for(;;) {
@@ -2575,7 +2672,7 @@ int port_choices(void) {
break;
}
}
- // cursor(0);
+
return choice;
}
@@ -2751,8 +2848,7 @@ void sell(void) {
cputs("How much ");
cputs(item[choice]);
- cputs(" shall\r\n");
- cputs("I sell, Taipan: ");
+ cputs(" shall\r\nI sell, Taipan: ");
amount = get_num();
@@ -2785,9 +2881,9 @@ char would_overflow(unsigned long a, unsigned long b) {
void too_much_cash(void) {
clear_msg_window();
- cputs("\r\nYou cannot carry so much cash, Taipan!");
- cputs("\r\nYour ship would sink under the weight");
- cputs("\r\nof your riches.\r\n");
+ cputs("\r\nYou cannot carry so much cash");
+ cprint_taipan_bang();
+ cputs("\r\nYour ship would sink under the weight\r\nof your riches.\r\n");
bad_joss_sound();
timed_getch();
}
@@ -2903,7 +2999,8 @@ void bignum_test(void) {
cputc(' ');
big_negate(n);
cprintfancy_big(n);
- cputs("\r\n");
+ // cputs("\r\n");
+ crlf();
big_mul(n, n, o);
}
agetc();
@@ -2929,7 +3026,8 @@ int main(void) {
clrscr();
cputs("dmg? ");
damage = get_num();
- cputs("\r\n");
+ // cputs("\r\n");
+ crlf();
cputs("cap? ");
capacity = get_num();
mchenry();
@@ -2949,46 +3047,35 @@ int main(void) {
cash_or_guns();
set_prices();
- for (;;)
- {
+ for (;;) {
choice = 0;
port_stats();
- /*
- clear_msg_window();
- cputs("li ");
- cprintulong(li);
- agetc();
- */
-
if(wu_assassin) {
wu_assassin = 0;
compradores_report();
- cputs("Taipan, you have been assassinated!");
+ cprint_taipan_comma();
+ cputs("you have been assassinated!");
under_attack_sound();
timed_getch();
compradores_report();
- cputs("As the masked figure plunges the blade\r\n");
- cputs("into your heart, he says:\r\n");
+ cputs("As the masked figure plunges the blade\r\n"
+ "into your heart, he says:\r\n");
timed_getch();
compradores_report();
- cputs("Elder Brother Wu regrets to inform you\r\n");
- cputs("that your account has been terminated\r\n");
- cputs("with extreme prejudice.");
+ cputs("Elder Brother Wu regrets to inform you\r\n"
+ "that your account has been terminated\r\n"
+ "with extreme prejudice.");
timed_getch();
final_stats();
}
- if ((port == 1) && (li == 0) && (cash > 0))
- {
- li_yuen_extortion();
- }
+ if ((port == 1) && (li == 0) && (cash > 0))
+ li_yuen_extortion();
- if ((port == 1) && (damage > 0))
- {
- mchenry();
- }
+ if ((port == 1) && (damage > 0))
+ mchenry();
if ((port == 1) && (debt >= 10000) && (wu_warn == 0))
{
@@ -2997,48 +3084,43 @@ int main(void) {
compradores_report();
cputs("Elder Brother Wu has sent ");
cprintulong(braves);
- cputs(" braves\r\n");
- cputs("to escort you to the Wu mansion, Taipan.\r\n");
+ cputs(" braves\r\nto escort you to the Wu mansion");
+ cprint_taipan_period();
+ crlf();
timed_getch();
clear_msg_window();
- cputs("Elder Brother Wu reminds you of the\r\n");
- cputs("Confucian ideal of personal worthiness,\r\n");
- cputs("and how this applies to paying one's\r\n");
- cputs("debts.\r\n");
+ cputs("Elder Brother Wu reminds you of the\r\n"
+ "Confucian ideal of personal worthiness,\r\n"
+ "and how this applies to paying one's\r\ndebts.\r\n");
timed_getch();
clear_msg_window();
- cputs("He is reminded of a fabled barbarian\r\n");
- cputs("who came to a bad end, after not caring\r\n");
- cputs("for his obligations.\r\n\r\n");
- cputs("He hopes no such fate awaits you, his\r\n");
- cputs("friend, Taipan.\r\n");
+ cputs("He is reminded of a fabled barbarian\r\n"
+ "who came to a bad end, after not caring\r\n"
+ "for his obligations.\r\n\n"
+ "He hopes no such fate awaits you, his\r\nfriend");
+ cprint_taipan_period();
+ crlf();
timed_getch();
wu_warn = 1;
}
- if (port == 1)
- {
- elder_brother_wu();
- }
+ if(port == 1)
+ elder_brother_wu();
- if (randi()%4 == 0)
- {
- if (randi()%2 == 0)
- {
- new_ship();
- } else if (guns < 1000) {
- new_gun();
- }
- }
+ if(chance_1_in(4)) {
+ if(chance_1_in(2))
+ new_ship();
+ else if (guns < 1000)
+ new_gun();
+ }
- if ((port != 1) && (randi()%18 == 0) && (hold_[0] > 0))
- {
+ if((port != 1) && (chance_1_in(18)) && (hold_[0] > 0)) {
// float fine = ((cash / 1.8) * ((float) randi() / RAND_MAX)) + 1;
// the 1.8 is now a 2
unsigned long fine = 0;
@@ -3053,17 +3135,20 @@ int main(void) {
// fancy_numbers(fine, fancy_num);
compradores_report();
- cputs("Bad Joss!!\r\n");
- cputs("The local authorities have seized your\r\n");
- cputs("Opium cargo and have also fined you\r\n");
+ // cputs("Bad Joss!!\r\n");
+ cprint_bad_joss();
+ cputs("The local authorities have seized your\r\n"
+ "Opium cargo and have also fined you\r\n");
// cputs(fancy_num);
cprintfancy(fine);
- cputs(", Taipan!\r\n");
+ cprint_taipan_bang();
+ // cputs("\r\n");
+ crlf();
timed_getch();
}
- if ((randi()%50 == 0) &&
+ if ((chance_1_in(50)) &&
((hkw_[0] + hkw_[1] + hkw_[2] + hkw_[3]) > 0))
{
int i;
@@ -3078,35 +3163,32 @@ int main(void) {
port_stats();
compradores_report();
- cputs("Messenger reports large theft\r\n");
- cputs("from warehouse, Taipan.\r\n");
+ cputs("Messenger reports large theft\r\nfrom warehouse");
+ cprint_taipan_period();
+ // cputs("\r\n");
+ crlf();
timed_getch();
}
- if (randi()%20 == 0)
- {
- if (li > 0) { li++; }
- if (li == 4) { li = 0; }
+ if(chance_1_in(20)) {
+ if (li > 0) li++;
+ if (li == 4) li = 0;
}
- if ((port != 1) && (li == 0) && (randi()%4 != 0))
- {
+ if((port != 1) && (li == 0) && (!chance_1_in(4))) {
compradores_report();
- cputs("Li Yuen has sent a Lieutenant,\r\n");
- cputs("Taipan. He says his admiral wishes\r\n");
- cputs("to see you in Hong Kong, posthaste!\r\n");
+ cputs("Li Yuen has sent a Lieutenant,\r\n"
+ "Taipan. He says his admiral wishes\r\n"
+ "to see you in Hong Kong, posthaste!\r\n");
bad_joss_sound();
timed_getch();
}
- if (randi()%9 == 0)
- {
+ if(chance_1_in(9))
good_prices();
- }
- if ((cash > 25000) && (randi()%20 == 0))
- {
+ if((cash > 25000) && (chance_1_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));
@@ -3114,14 +3196,13 @@ int main(void) {
cash -= robbed;
port_stats();
- // fancy_numbers(robbed, fancy_num);
compradores_report();
- cputs("Bad Joss!!\r\n");
- cputs("You've been beaten up and\r\n");
- cputs("robbed of ");
- // cputs(fancy_num);
+ cprint_bad_joss();
+ cputs("You've been beaten up and\r\nrobbed of ");
cprintfancy(robbed);
- cputs(" in cash, Taipan!!\r\n");
+ cputs(" in cash");
+ cprint_taipan_bangbang();
+ crlf();
under_attack_sound();
timed_getch();
@@ -3129,31 +3210,24 @@ int main(void) {
for (;;)
{
- while ((choice != 'Q') && (choice != 'q'))
- {
- switch (choice = port_choices())
- {
- case 'B':
+ while (choice != 'q') {
+ switch (choice = port_choices()) {
case 'b':
buy();
break;
- case 'S':
case 's':
sell();
break;
- case 'V':
case 'v':
visit_bank();
break;
- case 'T':
case 't':
transfer();
break;
- case 'R':
case 'r':
retire();
}
@@ -3172,9 +3246,5 @@ int main(void) {
}
}
- cgetc();
- POKE(709, 0);
-hangmain:
- goto hangmain;
return 0;
}