aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2016-01-26 15:40:50 -0500
committerB. Watson <yalhcru@gmail.com>2016-01-26 15:40:50 -0500
commitee56543e38c10c2391012d9222f78f44552cd77c (patch)
tree08ca0b4b30f41db867d227e809ed8a99e229f87e
parentd1488ab01cf16e0c0417565bbf051688846c752c (diff)
downloadtaipan-ee56543e38c10c2391012d9222f78f44552cd77c.tar.gz
streamline sea_battle(), save 190 bytes
-rw-r--r--taipan.c45
1 files changed, 29 insertions, 16 deletions
diff --git a/taipan.c b/taipan.c
index bb49035..ab94669 100644
--- a/taipan.c
+++ b/taipan.c
@@ -712,6 +712,15 @@ void plus_or_space(unsigned char b) {
hide_cursor();
}
+char set_orders(char orders) {
+ switch((char)timed_getch(TMOUT_3S)) {
+ case 'f': return 1;
+ case 'r': return 2;
+ case 't': return 3;
+ default: return orders;
+ }
+}
+
int sea_battle(int id, int num_ships) {
/* These locals seem to eat too much stack and
cause weird behaviour, so they're static now. */
@@ -749,7 +758,7 @@ int sea_battle(int id, int num_ships) {
clrscr();
cursor(0);
- flushinp();
+ // flushinp();
/* the static part of "we have N guns" display, gets printed
only once per battle. Bloats the code by 30-odd bytes, but
@@ -774,7 +783,7 @@ int sea_battle(int id, int num_ships) {
}
*/
- flushinp();
+ // flushinp();
gotoxy(0, 3);
clrtoeol();
@@ -800,7 +809,7 @@ int sea_battle(int id, int num_ships) {
gotoxy(0, 16);
cputs("\r\n");
- input = timed_getch(TMOUT_3S);
+ // input = timed_getch(TMOUT_3S);
/* using a switch() instead of a chain of if/else
actually increases code size by 16 bytes!
@@ -812,6 +821,8 @@ int sea_battle(int id, int num_ships) {
}
*/
+ orders = set_orders(orders);
+ /*
if(input == 'f') {
orders = 1;
} else if(input == 'r') {
@@ -819,17 +830,13 @@ int sea_battle(int id, int num_ships) {
} else if (input == 't') {
orders = 3;
}
+ */
if(orders == 0) {
- input = timed_getch(TMOUT_3S);
-
- if (input == 'f') {
- orders = 1;
- } else if(input == 'r') {
- orders = 2;
- } else if(input == 't') {
- orders = 3;
- } else {
+ // input = timed_getch(TMOUT_3S);
+
+ orders = set_orders(orders);
+ if(!orders) {
gotoxy(0, 3);
clrtoeol();
cputs("Taipan, what shall we do??\r\n(Fight, Run, Throw cargo)");
@@ -975,8 +982,10 @@ int sea_battle(int id, int num_ships) {
gotoxy(0, 16);
- timed_getch(TMOUT_3S);
+ // input = timed_getch(TMOUT_3S);
+ orders = set_orders(orders);
+ /*
if(input == 'f') {
orders = 1;
} else if(input == 'r') {
@@ -984,6 +993,7 @@ int sea_battle(int id, int num_ships) {
} else if(input == 't') {
orders = 3;
}
+ */
}
} else if ((orders == 1) && (guns == 0)) {
gotoxy(0, 3);
@@ -1083,7 +1093,7 @@ int sea_battle(int id, int num_ships) {
ok += ik++;
if(randi()%ok > randi()%num_ships) {
- flushinp();
+ // flushinp();
gotoxy(0, 3);
clrtoeol();
cputs("We got away from 'em, Taipan!");
@@ -1123,8 +1133,10 @@ int sea_battle(int id, int num_ships) {
gotoxy(0, 16);
- timed_getch(TMOUT_3S);
+ // input = timed_getch(TMOUT_3S);
+ orders = set_orders(orders);
+ /*
if(input == 'f') {
orders = 1;
} else if(input == 'r') {
@@ -1132,6 +1144,7 @@ int sea_battle(int id, int num_ships) {
} else if(input == 't') {
orders = 3;
}
+ */
}
}
}
@@ -1142,7 +1155,7 @@ int sea_battle(int id, int num_ships) {
cputs("They're firing on us, Taipan!");
timed_getch(TMOUT_3S);
- flushinp();
+ // flushinp();
/* screen flash doesn't change the hue bit of
COLOR2 register, since we now support changing