From d3395e701c2a14d30508a7f36c84be620ff2261a Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Fri, 1 Jan 2016 19:26:06 -0500 Subject: fix calculation for storm sinking the ship --- README.txt | 18 +++++++++++++----- taipan.c | 33 ++++++++++++++++++++++++++------- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/README.txt b/README.txt index f793dfa..c0e1c1e 100644 --- a/README.txt +++ b/README.txt @@ -36,8 +36,8 @@ What's missing: Build Requirements: -- GNU make. I use version 3.82, but I don't use any of its special - features, so any version should do. +- make. I use GNU make 3.82, and occasionally test with an old + version of BSD make (which works). - cc65. Originally I used version 2.13.3, and part way through I upgraded to a git snapshot dated December 29, 2015. cc65-2.3.13 @@ -117,9 +117,10 @@ monitor with S-Video (separate chroma/luma) inputs. If all else fails, try turning the color knob all the way down (and the contrast as high as you can stand it). In emulators, you can just disable artifacting. -On PAL systems, the ship explosions and sinking animations will be a bit -slower, and the prompt timeouts will be a bit longer. I don't think this -is a real issue (it's not like Taipan is a fast-paced arcade game). +On PAL systems, the ship explosions and sinking animations will be 20% +slower, and the prompt timeouts will be 20% longer (1 sec => 1.2 sec). I +don't think this is a real issue (it's not like Taipan is a fast-paced +arcade game). Bugs! At least these: @@ -164,6 +165,13 @@ Bugs! At least these: If you have e.g. 1,190,000, that should show as 1.2 million, not 1.1... or maybe not (need to double-check against the Apple version). +- One of my playtesters reported that, when running away from combat, it + said 4 billion ships were attacking (number of ships must have gone + negative). + +- After a fight, "Arriving at Manila" or such appears on the fight screen + without clearing it first (if you ran away, you can still see ships). + Differences between the Apple II original and Linux port: 1. Linux has an 80-column screen layout, Apple is 40. diff --git a/taipan.c b/taipan.c index 27f2adb..8080d13 100644 --- a/taipan.c +++ b/taipan.c @@ -74,8 +74,15 @@ extern void clrtoeol(); /**** End of atari-specific stuff */ +/* 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, + the return value would always be 1 (no randomness there). */ unsigned long randclamp(unsigned long clamp) { - return randl() % clamp; + unsigned long r = randl(); + if(clamp == 0) return clamp; + if(clamp == 1) return r & 0x01; + return r % clamp; } /* wrapper for cgetc() that returns letters as lowercase only @@ -893,7 +900,7 @@ int sea_battle(int id, int num_ships) { // cc65 runtime can't detect it... // If ((ed * i * id)/2)) works out to 1, anything%1 is 0. // damage = damage + (randi() % ((ed * i * id)/2)) + (i / 2); - // The is to avoid to % operator if the 2nd arg would be + // The answer is to avoid to % operator if the 2nd arg would be // 0 or 1: the intended result would just be 0 or 1 anyway. newdamage = ((ed * i * id)/2) + (i / 2); @@ -1608,7 +1615,8 @@ void transfer(void) void quit(void) { int choice = 0, - result = 0; + result = 0, + damagepct, sunk; compradores_report(); cputs("Taipan, do you wish me to go to:\r\n"); @@ -1688,7 +1696,7 @@ void quit(void) num_ships = randi()%((capacity / 5) + guns) + 5; cprintulong(num_ships); - cputs("ships of Li Yuen's pirate\r\n"); + cputs(" ships of Li Yuen's pirate\r\n"); cputs("fleet, Taipan!!\r\n"); timed_getch(TMOUT_3S); @@ -1739,10 +1747,21 @@ void quit(void) cputs(" I think we're going down!!\r\n\n"); timed_getch(TMOUT_3S); - // FIXME: the randclamp() version of this is broken badly! // if (((damage / capacity * 3) * ((float) randi() / RAND_MAX)) >= 1) - if(randclamp(damage / capacity * 3) >= 1) - { + // in the float version, damage/capacity*3 is your damage percentage, + // scaled 0 (0%) to 3 (100%). So if you're less than 34% damaged, + // you have no chance of sinking. If you're 34%-66% damaged, you + // have a 1 in 3 chance. If you're over 66%, you have a 2 in + // 3 chance. + damagepct = damage * 100 / capacity; + if(damagepct < 34) + sunk = 0; + else if(damagepct < 67) + sunk = randclamp(3) == 0; + else + sunk = randclamp(3) != 0; + + if(sunk) { cputs("We're going down, Taipan!!\r\n"); timed_getch(TMOUT_5S); -- cgit v1.2.3