From 5faf0c949468cf72d1dfd0e52369ab2d26760fd7 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Mon, 26 Apr 2021 15:37:02 -0400 Subject: Initial POC of in-game help --- messages.pl | 212 +++++++++--------------------------------------------------- 1 file changed, 29 insertions(+), 183 deletions(-) (limited to 'messages.pl') diff --git a/messages.pl b/messages.pl index 574d439..d00d9d5 100644 --- a/messages.pl +++ b/messages.pl @@ -1,12 +1,23 @@ #!/usr/bin/perl -w # compresses messages for taipan.c. -# messages are listed at the end of this file after __END__ marker. -# Run with no arguments to encode all messages, in which case the -# output of this script should be redirected to messages.c. -# With an argument, encoding is not done: instead, the strings -# to be encoded are dumped to stdout, *after* dictionary -# substitution is done. + +# Reads lines from stdin of the form: +# label "message text" +# writes C code to stdout. +# by default, an asm include file "asm.inc" is created, containing +# definitions of messages which exactly match a dictionary entry. +# with -n, "asm.inc" is not created. +# with -d, dumps messages to be encoded, after dictionary replacement. + +if(@ARGV) { + if($ARGV[0] eq '-n') { + $skip_msg_inc++; + } elsif($ARGV[0] eq '-d') { + $dump++; + $skip_msg_inc++; + } +} # make dictionary from textdecomp.s comments open my $t, "msg.inc" or die $!; -print ASMINC "; do not edit, contents are generated by messages.pl\n\n"; +if(!$skip_msg_inc) { + open ASMINC, ">msg.inc" or die $!; + print ASMINC "; do not edit, contents are generated by messages.pl\n\n"; +} + print "// do not edit, contents are generated by messages.pl\n\n"; -while() { +while() { chomp; $msgcount++; /^(\w+)\s/; @@ -43,7 +57,7 @@ while() { s/^\w+\s+//; my $orig = $_; - print " input: $_\n" if @ARGV; + print " input: $_\n" if $dump; s/"//g; s/\\r//g; s/\\n/\n/g; @@ -59,13 +73,13 @@ while() { # if a string turns out to be exactly a dict entry, no need to include # the compressed version in messages.c. - if(/^Z.$/) { + if(!$skip_msg_inc && /^Z.$/) { print "\nextern const char M_$label\[\]; // dictionary used, $dictlabels{$_}\n\n"; print ASMINC " _M_$label = $dictlabels{$_}\n .export _M_$label\n\n"; next; } - if(@ARGV) { + if($dump) { my $w = $_; $w =~ s/\n/\\n/g; print "output: \"$w\"\n\n"; @@ -84,11 +98,13 @@ while() { print join(", ", @got); $total_out += @got; } + close $result; die "failed to compress $orig\n" unless $readbytes; print "\n};" . ($dict_used ? " // dictionary used" : "") . "\n\n"; } -exit 0 if @ARGV; +close ASMINC unless $skip_msg_inc; +exit 0 if $dump; print "// messages: $msgcount\n"; print "// total input size: $total_in\n"; @@ -103,173 +119,3 @@ fine "fine" run "Run" # too short to be worth compression how_much_spc "How much " =cut - -__END__ -guns "guns" -fight "Fight" -throw "Throw Cargo" -opium "Opium" -silk "Silk" -arms "Arms" -gen_cargo "General Cargo" -ellipsis "..." -at_sea " At sea " -hong_kong "Hong Kong" -shanghai "Shanghai" -nagasaki "Nagasaki" -saigon "Saigon" -manila "Manila" -singapore "Singapore" -batavia "Batavia" -will_you "will you " -bad_joss "Bad Joss!!\r\n" -crlf "\n" -taipan "Taipan" -do_you_wish "do you wish " -elder_brother_wu "Elder Brother Wu " -li_yuen "Li Yuen" -do_you_want "Do you want " -firm_colon "Firm:" -compradors_report "Comprador's Report\r\n\n" -captains_report " Captain's Report\r\n\n" -overloaded "Your ship is overloaded" -wish_to_trade "Do you wish to trade in your " -ship_for_one "\r\nship for one with " -more_capacity " more capacity by\r\npaying an additional " -gun_offer "Do you wish to buy a ship's gun\r\nfor " -space_ship " ship" -space_attacking " attacking" -your_orders_are "Your orders are: " -we_have " We have" -cur_seaworth "Current seaworthiness: " -what_shall_we_do "what shall we do??\r\n(Fight, Run, Throw cargo)" -aye_fight "Aye, we'll fight 'em" -were_firing "We're firing on 'em" -sunk "Sunk " -of_the_buggers " of the buggers" -didnt_sink "Hit 'em, but didn't sink 'em" -ran_away " ran away" -we_have_no_guns "We have no guns" -you_have_on_board "You have the following on board" -what_shall_i_throw "What shall I throw overboard" -how_much "How much" -hope_we_lose_em "Let's hope we lose 'em" -nothing_there "There's nothing there" -aye_run "Aye, we'll run" -we_got_away "We got away from 'em" -couldnt_lose_em "Couldn't lose 'em." -but_we_escaped "But we escaped from " -of_em " of 'em!" -theyre_firing "They're firing on us" -weve_been_hit "We've been hit" -buggers_hit_gun "The buggers hit a gun" -we_got_em_all "We got 'em all" -to_start "to start . . .\r\n\n" -with_cash ") With cash (and a debt)\r\n\n" -with_5_guns ") With five guns and no cash\r\n" -but_no_debt "(But no debt!)" -mchenry_has_arrived "Mc Henry from the Hong Kong\r\nShipyards has arrived!! He says, 'I see\r\nye've a wee bit of damage to yer ship.'\r\nWill ye be wanting repairs? " -tis_a_pity "Och, 'tis a pity to be " -percent_damaged "% damaged.\r\nWe can fix yer whole ship for " -or_partial_repairs "\r\nor make partial repairs if you wish.\r\n" -will_ye_spend "will ye spend? " -illionaire " I L L I O N A I R E !" -youre_a " Y o u ' r e a" -your_final_status "Your final status:\r\n\nNet cash: " -ship_size "\r\nShip size: " -units_with " units with " -you_traded_for " guns\r\n\nYou traded for " -spc_year " year" -spc_and_spc " and " -spc_month " month" -your_score_is "Your score is " -land_based_job "Have you considered a land based job?\r\n\n\n" -stay_on_shore "The crew has requested that you stay on\r\nshore for their safety!!\r\n\n" -3_nls "\n\n\n" -your_rating "Your Rating:\r\n" -ma_tsu "Ma Tsu" -master_taipan "Master Taipan" -compradore "Compradore" -galley_hand "Galley Hand" -play_again "Play again? " -you_have_only "You have only " -you_have_no_cargo "You have no cargo" -move_to_whouse " shall I move\r\nto the warehouse" -whouse_only_hold "Your warehouse will only hold an\r\nadditional " -whouse_full "Your warehouse is full" -move_aboard " shall I move\r\naboard ship" -me_to_go_to "me to go to:\r\n" -already_here "\r\n\nYou're already here" -hostile_ship " hostile ship" -approaching " approaching" -fleet_drove_off "Li Yuen's fleet drove them off!" -s_pirates "Li Yuen's pirates" -they_let_us_be "Good joss!! They let us be!!\r\n" -ships_of_fleet " ships of Li Yuen's pirate\r\nfleet" -captured_some_booty "We captured some booty.\r\nIt's worth " -we_made_it "We made it!" -buggers_got_us "The buggers got us" -all_over_now "!\r\nIt's all over, now!!!" -storm "Storm" -think_going_down " I think we're going down!!\r\n\n" -were_going_down "We're going down" -storm_we_made_it " We made it!!\r\n\n" -blown_off_course "We've been blown off course\r\nto " -arriving_at "Arriving at " -asks "Li Yuen asks " -in_donation " in donation\r\nto the temple of Tin Hau, the Sea\r\nGoddess. Will you pay? " -not_enough_cash "you do not have enough cash!!\r\n\n" -make_up_difference "to make up\r\nthe difference for you? " -given_the_diff "has given Li Yuen the\r\ndifference between what he wanted and\r\nyour cash on hand and added the same\r\namount to your debt.\r\n" -very_well "Very well. " -will_not_pay "will not pay\r\nLi Yuen the difference. I would be very\r\nwary of pirates if I were you." -you_only_have "you only have " -nl_in_spc "\nin " -the_bank "the bank.\n" -cash "cash.\n" -do_you_have_biz_with_wu "Do you have business with Elder Brother\r\nWu, the moneylender? " -aware_of_your_plight "Elder Brother is aware of your plight,\r\nTaipan. He is willing to loan you an\r\nadditional " -if_you_will_pay_back " if you will pay back\r\n" -are_you_willing ". Are you willing" -game_is_over "Very well, Taipan, the game is over!\r\n" -very_well_good_joss "Very well, Taipan. Good joss!!\r\n" -to_repay_him "to repay\r\nhim? " -to_borrow "to \r\nborrow? " -wont_loan "\r\n\nHe won't loan you so much" -bodyguards_killed " of your bodyguards have been killed\r\nby cutthroats and you have been robbed\r\nof all of your cash" -the_price_of "Taipan!! The price of " -nl_has_spc "\n has " -risen "risen" -dropped "dropped" -spc_to_spc " to " -bang_bang_nl "!!\n" -prices_here_are "present prices per unit here are" -general_shortname "General" -shall_i_buy_sell "Shall I Buy, Sell, " -bank_transfer "Visit bank, Transfer\r\ncargo, " -quit_traging "Quit trading" -or_retire ", or Retire" -what_will_you_name_firm " What will you name your" -what "What " -me_to "me to " -spc_you_can_spc " You can " -spc_shall " shall" -spc_afford " afford " -i_buy "I buy, " -shall_i_sell " shall\r\nI sell, " -too_much_cash "\r\nYou cannot carry so much cash" -ship_would_sink "\r\nYour ship would sink under the weight\r\nof your riches.\r\n" -deposit "deposit? " -withdraw "withdraw? " -assassinated_1 "you have been assassinated!" -assassinated_2 "As the masked figure plunges the blade\r\ninto your heart, he says:\r\n" -assassinated_3 "regrets to inform you\r\nthat your account has been terminated\r\nwith extreme prejudice." -has_sent "has sent " -braves_to_escort " braves\r\nto escort you to the Wu mansion" -wu_warn_1 "reminds you of the\r\nConfucian ideal of personal worthiness,\r\nand how this applies to paying one's\r\ndebts.\r\n" -wu_warn_2 "He is reminded of a fabled barbarian\r\nwho came to a bad end, after not caring\r\nfor his obligations.\r\n\nHe hopes no such fate awaits you, his\r\nfriend" -siezed_opium "The local authorities have seized your\r\nOpium cargo and have also fined you\r\n" -whouse_theft "Messenger reports large theft\r\nfrom warehouse" -has_sent_lieutenant "Li Yuen has sent a Lieutenant,\r\nTaipan. He says his admiral wishes\r\nto see you in Hong Kong, posthaste!\r\n" -beaten_robbed "You've been beaten up and\r\nrobbed of " -in_cash " in cash" -- cgit v1.2.3