diff options
| -rw-r--r-- | taipan.c | 574 | 
1 files changed, 276 insertions, 298 deletions
| @@ -262,7 +262,7 @@ void visit_bank(void);  void transfer(void);  void quit(void);  void overload(void); -int sea_battle(int id, int num_ships); +char sea_battle(char id, int num_ships);  void fight_stats(int ships, int orders);  void mchenry(void);  void retire(void); @@ -844,29 +844,30 @@ void plus_or_space(unsigned char b) {  	// hide_cursor();  } -char set_orders(char orders) { -	switch((char)timed_getch()) { -		case 'f': return 1; -		case 'r': return 2; -		case 't': return 3; -		default: return orders; +char orders = 0; +void set_orders(void) { +	switch(timed_getch()) { +		case 'f': orders = 1; break; +		case 'r': orders = 2; break; +		case 't': orders = 3; break; +		default: break;  	}  } -int sea_battle(int id, int num_ships) { +/* sea_battle only ever returns 1 to 4. making the +	return type a char saved 61 bytes! */ +char sea_battle(char id, int num_ships) {  	/* These locals seem to eat too much stack and  		cause weird behaviour, so they're static now. */ - 	static int ships_on_screen[10]; -   static int orders, -       num_on_screen, -       time, -       s0, -       ok, -       ik, -       i, -       // input, -       status; -	char choice, flashctr; +	static int ships_on_screen[10]; +	static int time, +				  s0, +				  ok, +				  ik, +				  i, +				  // input, +				  status; +	char choice, flashctr, num_on_screen;  	unsigned long amount, total;  	port_stat_dirty = 1; @@ -879,21 +880,20 @@ int sea_battle(int id, int num_ships) {  	ok = 0;  	ik = 1; -   booty = (time / 4 * 1000 * num_ships) + randi()%1000 + 250; +	booty = (time / 4 * 1000 * num_ships) + randi()%1000 + 250;  	if(would_overflow(cash, booty)) {  		booty = 0L;  	} -   for(i = 0; i <= 9; i++) { -      ships_on_screen[i] = 0; -   } +	for(i = 0; i <= 9; i++) { +		ships_on_screen[i] = 0; +	} -   clr_screen(); -	// cursor(0); +	clr_screen(); -/* the static part of "we have N guns" display, gets printed -	only once per battle. Bloats the code by 30-odd bytes, but -	updates are smoother-looking. Maybe. */ +	/* the static part of "we have N guns" display, gets printed +		only once per battle. Bloats the code by 30-odd bytes, but +		updates are smoother-looking. Maybe. */  	rvs_on();  	gotoxy(30, 0);  	cputs("   We have"); @@ -903,130 +903,109 @@ int sea_battle(int id, int num_ships) {  	rvs_off();  	update_guns(); -   fight_stats(num_ships, orders); +	fight_stats(num_ships, orders); -   while(num_ships > 0) { +	while(num_ships > 0) {  		if(damage >= capacity) return 4;  		// status = 100L - ((damage * 100L / capacity));  		status = get_ship_status();  		/* // I think this is a problem: -      if(status <= 0) { -         return 4; -      } -		*/ +			if(status <= 0) { +			return 4; +			} +		 */ -      // flushinp(); -      gotoxy(0, 3); -      clrtoeol(); +		// flushinp(); +		gotoxy(0, 3); +		clrtoeol(); -      cputs("Current seaworthiness: "); +		cputs("Current seaworthiness: ");  		cputs(st[status / 20]);  		cputs(" (");  		cprintulong(status);  		cputs("%)");  		gotoxy(0, 4); -      for(i = 0; i <= 9; i++) { -         if (num_ships > num_on_screen) { -            if (ships_on_screen[i] == 0) { +		for(i = 0; i <= 9; i++) { +			if (num_ships > num_on_screen) { +				if (ships_on_screen[i] == 0) {  					jsleep(5); -               ships_on_screen[i] = (randi() % ec) + 20; -               draw_lorcha(i); -               num_on_screen++; -            } -         } -      } +					ships_on_screen[i] = (randi() % ec) + 20; +					draw_lorcha(i); +					num_on_screen++; +				} +			} +		} -      plus_or_space(num_ships > num_on_screen); +		plus_or_space(num_ships > num_on_screen); -      gotoxy(0, 16); +		gotoxy(0, 16);  		// cputs("\r\n");  		crlf(); -		orders = set_orders(orders); +		set_orders(); -      if(orders == 0) { -			orders = set_orders(orders); -         if(!orders) { -            gotoxy(0, 3); -            clrtoeol(); +		if(orders == 0) { +			set_orders(); +			if(!orders) { +				gotoxy(0, 3); +				clrtoeol();  				cprint_taipan_comma(); -            cputs("what shall we do??\r\n(Fight, Run, Throw cargo)"); +				cputs("what shall we do??\r\n(Fight, Run, Throw cargo)");  				under_attack_sound(); -				while(! (orders = set_orders(orders)) ) -					; +				while(!orders) set_orders(); -            gotoxy(0, 3); +				gotoxy(0, 3);  				clrtoeol(); -            gotoxy(0, 4); +				gotoxy(0, 4);  				clrtoeol(); +			} +		} -				/* -            while ((input != 'f') && -                   (input != 'r') && -                   (input != 't')) -            { -               input = lcgetc(); -            } -            gotoxy(0, 3); -				clrtoeol(); -            gotoxy(0, 4); -				clrtoeol(); -            if(input == 'f') { -               orders = 1; -            } else if(input == 'r') { -               orders = 2; -            } else { -               orders = 3; -            } -				*/ -         } -      } - -      fight_stats(num_ships, orders); -      if((orders == 1) && (guns > 0)) { -         static int targeted, sk; +		fight_stats(num_ships, orders); +		if((orders == 1) && (guns > 0)) { +			static int targeted, sk;  			sk = 0; -         ok = 3; -         ik = 1; -         gotoxy(0, 3); -         clrtoeol(); -         cputs("Aye, we'll fight 'em"); +			ok = 3; +			ik = 1; +			gotoxy(0, 3); +			clrtoeol(); +			cputs("Aye, we'll fight 'em");  			cprint_taipan_period(); -         timed_getch(); +			set_orders(); -         gotoxy(0, 3); -         clrtoeol(); -         cputs("We're firing on 'em"); +			gotoxy(0, 3); +			clrtoeol(); +			cputs("We're firing on 'em");  			cprint_taipan_bang(); -         timed_getch(); - -         for(i = 1; i <= guns; i++) { -            if ((ships_on_screen[0] == 0) && (ships_on_screen[1] == 0) && -                (ships_on_screen[2] == 0) && (ships_on_screen[3] == 0) && -                (ships_on_screen[4] == 0) && (ships_on_screen[5] == 0) && -                (ships_on_screen[6] == 0) && (ships_on_screen[7] == 0) && -                (ships_on_screen[8] == 0) && (ships_on_screen[9] == 0)) -            { -               static int j; - -               for (j = 0; j <= 9; j++) { -                  if (num_ships > num_on_screen) { -                     if(ships_on_screen[j] == 0) { +			set_orders(); + +			for(i = 1; i <= guns; i++) { +				if ((ships_on_screen[0] == 0) && (ships_on_screen[1] == 0) && +						(ships_on_screen[2] == 0) && (ships_on_screen[3] == 0) && +						(ships_on_screen[4] == 0) && (ships_on_screen[5] == 0) && +						(ships_on_screen[6] == 0) && (ships_on_screen[7] == 0) && +						(ships_on_screen[8] == 0) && (ships_on_screen[9] == 0)) +				{ +					static int j; + +					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; -                        draw_lorcha(j); -                        num_on_screen++; -                     } -                  } -               } -            } +								draw_lorcha(j); +								num_on_screen++; +							} +						} +					} +				}  				plus_or_space(num_ships > num_on_screen); -            gotoxy(0, 16); +				gotoxy(0, 16);  				crlf();  				do { @@ -1042,129 +1021,129 @@ int sea_battle(int id, int num_ships) {  				damage_lorcha(targeted); -            ships_on_screen[targeted] -= randi()%30 + 10; +				ships_on_screen[targeted] -= randi()%30 + 10; -            if(ships_on_screen[targeted] <= 0) { -               num_on_screen--; -               num_ships--; -               sk++; -               ships_on_screen[targeted] = 0; +				if(ships_on_screen[targeted] <= 0) { +					num_on_screen--; +					num_ships--; +					sk++; +					ships_on_screen[targeted] = 0;  					bad_joss_sound(); /* not sure this should be here */ -               sink_lorcha(targeted); +					sink_lorcha(targeted);  					plus_or_space(num_ships > num_on_screen); -               fight_stats(num_ships, orders); -            } +					fight_stats(num_ships, orders); +				} -            if(num_ships == 0) { -               i += guns; -            } else { +				if(num_ships == 0) { +					i += guns; +				} else {  					jsleep(10); -            } -         } -         gotoxy(0, 3); -         clrtoeol(); -         if(sk > 0) { +				} +			} +			gotoxy(0, 3); +			clrtoeol(); +			if(sk > 0) {  				cputs("Sunk ");  				cprintulong(sk);  				cputs(" of the buggers");  				cprint_taipan_bang();  				bad_joss_sound(); -         } else { -            cputs("Hit 'em, but didn't sink 'em"); +			} else { +				cputs("Hit 'em, but didn't sink 'em");  				cprint_taipan_bang(); -         } -         timed_getch(); +			} +			set_orders(); -         // 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 = randclamp(num_ships / 3 / id) + 1; +			// 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 = randclamp(num_ships / 3 / id) + 1; -            num_ships -= ran; -            fight_stats(num_ships, orders); -            gotoxy(0, 3); -            clrtoeol(); +				num_ships -= ran; +				fight_stats(num_ships, orders); +				gotoxy(0, 3); +				clrtoeol();  				cprintulong(ran); -            cputs(" ran away"); +				cputs(" ran away");  				cprint_taipan_bang();  				bad_joss_sound(); -            if(num_ships <= 10) { -               for(i = 9; i >= 0; i--) { -                  if ((num_on_screen > num_ships) && (ships_on_screen[i] > 0)) { -                     ships_on_screen[i] = 0; -                     num_on_screen--; +				if(num_ships <= 10) { +					for(i = 9; i >= 0; i--) { +						if ((num_on_screen > num_ships) && (ships_on_screen[i] > 0)) { +							ships_on_screen[i] = 0; +							num_on_screen--;  							clear_lorcha(i);  							jsleep(5); -                  } -               } -               if(num_ships == num_on_screen) { +						} +					} +					if(num_ships == num_on_screen) {  						plus_or_space(0); -               } -            } +					} +				} -            gotoxy(0, 16); +				gotoxy(0, 16); -				orders = set_orders(orders); -         } -      } else if ((orders == 1) && (guns == 0)) { -         gotoxy(0, 3); -         clrtoeol(); -         cputs("We have no guns"); +				set_orders(); +			} +		} else if ((orders == 1) && (guns == 0)) { +			gotoxy(0, 3); +			clrtoeol(); +			cputs("We have no guns");  			cprint_taipan_bangbang(); -         timed_getch(); -      } else if (orders == 3) { -         choice = 0; -         amount = 0; +			set_orders(); +		} else if (orders == 3) { +			choice = 0; +			amount = 0;  			total = 0; -         gotoxy(0, 3); -         cputs("You have the following on board"); +			gotoxy(0, 3); +			cputs("You have the following on board");  			cprint_taipan_colon(); -         gotoxy(4, 4); +			gotoxy(4, 4);  			cputs(item[0]);  			cputs(": ");  			cprintulong(hold_[0]); -         gotoxy(24, 4); +			gotoxy(24, 4);  			cputs(item[1]);  			cputs(": ");  			cprintulong(hold_[1]); -         gotoxy(5, 5); +			gotoxy(5, 5);  			cputs(item[2]);  			cputs(": ");  			cprintulong(hold_[2]); -         gotoxy(21, 5); +			gotoxy(21, 5);  			cputs(item[3]);  			cputs(": ");  			cprintulong(hold_[3]); -         gotoxy(0, 6); -         clrtoeol(); -         cputs("What shall I throw overboard"); +			gotoxy(0, 6); +			clrtoeol(); +			cputs("What shall I throw overboard");  			cprint_taipan_prompt();  			choice = get_item(1); -         if(choice < 4) { -            gotoxy(0, 6); -            clrtoeol(); -            cputs("How much"); +			if(choice < 4) { +				gotoxy(0, 6); +				clrtoeol(); +				cputs("How much");  				cprint_taipan_prompt(); -            amount = get_num(); -            if((hold_[choice] > 0) && ((amount == UINT32_MAX) || (amount > hold_[choice]))) -            { -               amount = hold_[choice]; -            } -            total = hold_[choice]; -         } else { -            total = hold_[0] + hold_[1] + hold_[2] + hold_[3]; -         } +				amount = get_num(); +				if((hold_[choice] > 0) && ((amount == UINT32_MAX) || (amount > hold_[choice]))) +				{ +					amount = hold_[choice]; +				} +				total = hold_[choice]; +			} else { +				total = hold_[0] + hold_[1] + hold_[2] + hold_[3]; +			}  			gotoxy(0, 4);  			clrtoeol(); @@ -1173,139 +1152,139 @@ int sea_battle(int id, int num_ships) {  			gotoxy(0, 6);  			clrtoeol(); -         if(total > 0) { -            gotoxy(0, 3); -            clrtoeol(); -            cputs("Let's hope we lose 'em"); +			if(total > 0) { +				gotoxy(0, 3); +				clrtoeol(); +				cputs("Let's hope we lose 'em");  				cprint_taipan_bang();  				bad_joss_sound(); -            if (choice < 4) { -               hold_[choice] -= amount; -               hold += amount; -               ok += (amount / 10); -            } else { -               hold_[0] = 0; -               hold_[1] = 0; -               hold_[2] = 0; -               hold_[3] = 0; -               hold += total; -               ok += (total / 10); -            } +				if (choice < 4) { +					hold_[choice] -= amount; +					hold += amount; +					ok += (amount / 10); +				} else { +					hold_[0] = 0; +					hold_[1] = 0; +					hold_[2] = 0; +					hold_[3] = 0; +					hold += total; +					ok += (total / 10); +				} -            timed_getch(); -         } else { -            gotoxy(0, 3); -            clrtoeol(); -            cputs("There's nothing there"); +				set_orders(); +			} else { +				gotoxy(0, 3); +				clrtoeol(); +				cputs("There's nothing there");  				cprint_taipan_bang();  				good_joss_sound(); -            timed_getch(); -         } -      } +				set_orders(); +			} +		} -      if((orders == 2) || (orders == 3)) { -         if(orders == 2) { -            gotoxy(0, 3); -            clrtoeol(); -            cputs("Aye, we'll run"); +		if((orders == 2) || (orders == 3)) { +			if(orders == 2) { +				gotoxy(0, 3); +				clrtoeol(); +				cputs("Aye, we'll run");  				cprint_taipan_period(); -            timed_getch(); -         } +				set_orders(); +			} -         ok += ik++; -         if(randi()%ok > randi()%num_ships) { -            gotoxy(0, 3); -            clrtoeol(); -            cputs("We got away from 'em"); +			ok += ik++; +			if(randi()%ok > randi()%num_ships) { +				gotoxy(0, 3); +				clrtoeol(); +				cputs("We got away from 'em");  				cprint_taipan_bang();  				good_joss_sound(); -            timed_getch(); -            num_ships = 0; -         } else { -            gotoxy(0, 3); -            clrtoeol(); -            cputs("Couldn't lose 'em."); -            timed_getch(); +				set_orders(); +				num_ships = 0; +			} else { +				gotoxy(0, 3); +				clrtoeol(); +				cputs("Couldn't lose 'em."); +				set_orders(); -            if((num_ships > 2) && (one_chance_in(5))) { -               static int lost; -               lost = (randi()%num_ships / 2) + 1; +				if((num_ships > 2) && (one_chance_in(5))) { +					static int lost; +					lost = (randi()%num_ships / 2) + 1; -               num_ships -= lost; -               fight_stats(num_ships, orders); -               gotoxy(0, 3); -               clrtoeol(); +					num_ships -= lost; +					fight_stats(num_ships, orders); +					gotoxy(0, 3); +					clrtoeol();  					cputs("But we escaped from ");  					cprintulong(lost);  					cputs(" of 'em!"); -               if(num_ships <= 10) { -                  for(i = 9; i >= 0; i--) { -                     if((num_on_screen > num_ships) && (ships_on_screen[i] > 0)) { -                        ships_on_screen[i] = 0; -                        num_on_screen--; +					if(num_ships <= 10) { +						for(i = 9; i >= 0; i--) { +							if((num_on_screen > num_ships) && (ships_on_screen[i] > 0)) { +								ships_on_screen[i] = 0; +								num_on_screen--;  								clear_lorcha(i);  								jsleep(5); -                     } -                  } +							} +						}  						plus_or_space(num_ships > num_on_screen); -               } +					} -               gotoxy(0, 16); +					gotoxy(0, 16); -					orders = set_orders(orders); -            } -         } -      } +					set_orders(); +				} +			} +		} -      if(num_ships > 0) { -         gotoxy(0, 3); -         clrtoeol(); -         cputs("They're firing on us"); +		if(num_ships > 0) { +			gotoxy(0, 3); +			clrtoeol(); +			cputs("They're firing on us");  			cprint_taipan_bang(); -         timed_getch(); +			set_orders();  			// hide_cursor();  			explosion(); -         fight_stats(num_ships, orders); +			fight_stats(num_ships, orders);  			plus_or_space(num_ships > num_on_screen); -         gotoxy(0, 3); -         clrtoeol(); -         cputs("We've been hit"); +			gotoxy(0, 3); +			clrtoeol(); +			cputs("We've been hit");  			cprint_taipan_bangbang();  			under_attack_sound(); -         timed_getch(); +			set_orders(); -         i = (num_ships > 15) ? 15 : num_ships; +			i = (num_ships > 15) ? 15 : num_ships;  			// is this really correct? -         // if ((guns > 0) && ((randi()%100 < (((float) damage / capacity) * 100)) || -             // ((((float) damage / capacity) * 100) > 80))) +			// if ((guns > 0) && ((randi()%100 < (((float) damage / capacity) * 100)) || +			// ((((float) damage / capacity) * 100) > 80))) -         if((guns > 0) && ((randi()%100 < ((damage * 100L) / capacity)) || -             (((damage * 100L) / capacity)) > 80)) -         { -            i = 1; -            guns--; -            hold += 10; -            fight_stats(num_ships, orders); -            gotoxy(0, 3); -            clrtoeol(); -            cputs("The buggers hit a gun"); +			if((guns > 0) && ((randi()%100 < ((damage * 100L) / capacity)) || +						(((damage * 100L) / capacity)) > 80)) +			{ +				i = 1; +				guns--; +				hold += 10; +				fight_stats(num_ships, orders); +				gotoxy(0, 3); +				clrtoeol(); +				cputs("The buggers hit a gun");  				cprint_taipan_bangbang();  				under_attack_sound(); -            fight_stats(num_ships, orders); +				fight_stats(num_ships, orders);  				update_guns(); -            timed_getch(); -         } +				set_orders(); +			} -         // damage = damage + ((ed * i * id) * ((float) randi() / RAND_MAX)) + (i / 2); +			// damage = damage + ((ed * i * id) * ((float) randi() / RAND_MAX)) + (i / 2);  			// remember, ed is now scaled by 2 (used to be 0.5, now 1)  			// broken because sometimes works out to 0 or 1. If it's 0, @@ -1350,26 +1329,26 @@ int sea_battle(int id, int num_ships) {  			cgetc();  #endif -         if((id == GENERIC) && (one_chance_in(20))) { -            return 2; -         } -      } -   } +			if((id == GENERIC) && (one_chance_in(20))) { +				return 2; +			} +		} +	} -   if(orders == 1) { -      // clr_screen(); -      fight_stats(num_ships, orders); -      gotoxy(0, 3); -      clrtoeol(); -      cputs("We got 'em all"); +	if(orders == 1) { +		// clr_screen(); +		fight_stats(num_ships, orders); +		gotoxy(0, 3); +		clrtoeol(); +		cputs("We got 'em all");  		cprint_taipan_bang();  		bad_joss_sound(); -      timed_getch(); +		timed_getch(); -      return 1; -   } else { -      return 3; -   } +		return 1; +	} else { +		return 3; +	}  }  /* TODO: rewrite in asm. Maybe. */ @@ -2121,9 +2100,8 @@ void quit(void)  #ifdef BIGNUM  	bignum(banktmp);  #endif -	unsigned char choice, sunk; -   int result = 0, -		 damagepct; +	unsigned char choice, sunk, result; +   int damagepct;  	compradores_report();  	cprint_taipan_comma(); | 
