awlite

POSIX AWK port of Text Elite game
git clone git://git.luxferre.top/awlite.git
Log | Files | Refs | README

commit d3ed7cb832fbe9594568a1c2b072a88640ad0c73
parent d1b2beced56a8386450e3ceaf7163fc4cc1c7c17
Author: Luxferre <lux@ferre>
Date:   Sun, 28 Jan 2024 12:14:19 +0200

v1.8: ship upgrades, better stats display

Diffstat:
MREADME | 28++++++++++++++++++----------
Mawlite.awk | 79++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
2 files changed, 70 insertions(+), 37 deletions(-)

diff --git a/README b/README @@ -28,7 +28,7 @@ basic game launch command. == In-game commands == As you launch a fresh game, you start on the planet Lave of Galaxy 1, -on a ship with 20t of cargo space, with 100 credits of cash. +on a Cobra Mk3 ship with 20t of cargo space, with 100 credits of cash. From now on, the following commands are available (case-insensitive): * buy (product) (amount): buy specified amount of specified product @@ -41,7 +41,7 @@ From now on, the following commands are available (case-insensitive): (the planet must be in the same galaxy as you) * mkt: show local planetary system market prices * local: list planetary systems within 7 lightyears (your max fuel capacity) -* hold: expand your cargo bay to 35t for 400 credits (one-time upgrade only) +* upgrade: expand your cargo bay by upgrading your ship or buying a new one * stat: show player statistics and overall rank * save (name): save the gamestate in the current working directory * load (name): load the gamestate from the current working directory @@ -49,22 +49,22 @@ From now on, the following commands are available (case-insensitive): * rand: toggle between the AWK's native PRNG (default) and a custom one * quit: quit the game -All commands except "hold", "save" and "load" can be abbreviated by their +All commands except "upgrade", "save" and "load" can be abbreviated by their first letter. In addition, trade goods names can be abbreviated too (by several first letters). E.g. "b fo 5" is the same as "buy Food 5", and "q" is "quit". +The "upgrade" command can be abbreviated as "up". Fuel price is fixed at 0.2 CR/LY, you can hold 7LY of fuel at most. == Gameplay differences from the original TE 1.5 C version == -As of the current version, 1.7: +As of the current version, 1.8: * multiple typos corrected in text strings * the "cash" and "sneak" commands were removed since v1.6 * galaxy jumps are no longer free and cost 5000 credits each (like in classic Elite and Oolite) -* cargo hold expansion also is non-free (400 credits) and can only be - done once from 20t to 35t (like in classic Elite) +* cargo hold expansion also is non-free and (since v1.8) multi-tiered * alien items are available by default (can be overridden with -v NO_ALIEN_ITEMS=1) * economy names are no longer shortened @@ -77,6 +77,7 @@ As of the current version, 1.7: * since v1.6.3, galaxy names are also displayed with "local" command (the names were taken from the Archimedes version of Classic Elite) * since v1.7, basic ranking and statistics have been introduced +* since v1.8, "hold" command was replaced with "upgrade" with several ships To be continued. This list is expected to grow in the future. @@ -163,11 +164,18 @@ difficulties such as police and pirate attacks. Highly unlikely. One of the project goals is to keep it simple. -- Are there going to be any further ship upgrades besides the "hold" command? +- Are there ship upgrades available in awlite? -Very likely, closer to version 2.0. Particularly, ability to buy another ship -of a different class (with a much larger cargo bay) is -being designed. +Yes, since v1.8, awlite offers 5 upgrade tiers similar to Oolite trade ships: + +* Cobra Mk3 Extended (35t, 400 CR) - like in the original Elite versions +* Python (100t, 200000 CR) +* Boa (125t, 450000 CR) +* Boa 2 (175t, 495000 CR) +* Anaconda (750t, 650000 CR) + +You can list and select them with the "upgrade" (or "up") command. +Note that once you upgrade to a better ship, previous tiers become unavailable. - How large is awlite? diff --git a/awlite.awk b/awlite.awk @@ -1,5 +1,5 @@ # awlite: POSIX AWK port of Text Elite -# Version 1.7 +# Version 1.8 # Original high-level algorithms from Text Elite 1.5 by Ian Bell, 1999, 2015 # Porting, corrections, improvements and optimizations by Luxferre, 2024 # @@ -10,7 +10,7 @@ # Gameplay differences from the original C version of TE 1.5: # - multiple typos corrected in text strings # - galaxy jumps are no longer free and cost 5000 credits each (like in classic Elite and Oolite) -# - cargo hold expansion also is non-free (400 credits) and can only be done once from 20t to 35t (like in classic Elite) +# - cargo hold expansion also is non-free and (since v1.8) multi-tiered # - alien items are available by default, can be overridden with -v NO_ALIEN_ITEMS=1 # - economy names are no longer shortened # - the "politically correct" goods names are turned on with -v CENSORED=1 @@ -21,6 +21,7 @@ # - since v1.6.1, the game gives you a hint if you might have found Raxxla # - since v1.6.3, galaxy names are actually displayed (taken from ArcElite) # - since v1.7, "stat" command and basic ranking was introduced +# - since v1.8, "hold" command was replaced with "upgrade" with several ships # ... to be continued ... # utility functions @@ -387,26 +388,37 @@ function doinfo(s, dest, si) { prisys(si, 0) # print its info } -# hold command implementation -function dohold(a, t, i) { - if(player["holdspace"] >= game["cargoexpsize"]) { - printf("\nExpansion not possible! The cargo bay already is at maximum capacity") - return 0 - } - if(player["cash"] < game["cargoexpcost"]) { - printf("\nNot enough cash! Need %.1f CR for upgrading the cargo bay", game["cargoexpcost"]/10) - return 0 +# upgrade/up command implementation +function doup(a, t, i, ns) { + ns = 6 # number of upgrades, including the basic version + if(player["upglvl"] == ns - 1) + printf("\nYou already are on the maximum upgrade level, enjoy!") + else if(a == "") { # no parameter, list available ships + printf("\nAvailable upgrades:\n") + for(i=player["upglvl"]+1;i<ns;i++) { + printf("\n%u. %-13s %-5s %-10s", i, shipnames[i], sprintf("%ut", cargoholds[i]), sprintf("%.1f CR",shipprices[i]/10)) + } + printf("\n\nType upgrade [number] to upgrade") + } else { + a = int(a) + if(a >= ns || a <= player["upglvl"]) + printf("\nInvalid upgrade number!") + else if(player["cash"] < shipprices[a]) + printf("\nYou need at least %.1f CR to upgrade to %s!", shipprices[a]/10, shipnames[a]) + else { # perform the upgrade if cash allows + player["upglvl"] = a + a = int(cargoholds[a]) + t = 0 + for(i=0;i<=IDX_ALIEN_ITEMS;i++) + if(goods_units[i] == 0) t += shipshold[i] + if(t > a) {printf("\nHold too full"); return 0} + player["holdspace"] = a - t + player["cash"] -= shipprices[player["upglvl"]] + player["expense"] += shipprices[player["upglvl"]] + printf("\nBought %s", shipnames[player["upglvl"]]) + printf("\nCargo bay expanded to %dt", cargoholds[player["upglvl"]]) + } } - t = 0 - a = int(a) - for(i=0;i<=IDX_ALIEN_ITEMS;i++) - if(goods_units[i] == 0) t += shipshold[i] - if(t > a) {printf("\nHold too full"); return 0} - player["holdspace"] = a - t - player["cash"] -= game["cargoexpcost"] - player["expense"] += game["cargoexpcost"] - printf("\nCargo bay expanded to %dt", game["cargoexpsize"]) - return 1 } # check string s against n options in array a @@ -475,7 +487,7 @@ function dofuel(f) { # show stock market function domkt() { displaymarket() - printf("\n\nFuel: %.1f\nHoldspace: %it", player["fuel"]/10, player["holdspace"]) + printf("\n\nFuel: %.1f\nFree cargo space: %it", player["fuel"]/10, player["holdspace"]) } # display help @@ -489,7 +501,7 @@ function dohelp() { printf("\nInfo planetname (print info on system)") printf("\nMkt (show market prices)") printf("\nLocal (list systems within 7 lightyears)") - printf("\nHold (expand cargo bay to %dt)", game["cargoexpsize"]) + printf("\nUpgrade (upgrade your ship)") printf("\nStat (show player statistics)") printf("\nSave playername (save game into current working directory)") printf("\nLoad playername (load game from current working directory)") @@ -546,8 +558,10 @@ function dostat(profind, rank) { printf("\nExpenses %16s", sprintf("%.1f CR", player["expense"]/10)) printf("\nProfit margin %11s", sprintf("%.2f%%", profind*100)) printf("\n\n======= Ship info =======") + printf("\nName %20s", shipnames[player["upglvl"]]) printf("\nFuel %20s", sprintf("%.1f LY", player["fuel"]/10)) - printf("\nCargo space %13s", sprintf("%ut", player["holdspace"])) + printf("\nCargo space %13s", sprintf("%ut", cargoholds[player["upglvl"]])) + printf("\nFree space %14s", sprintf("%ut", player["holdspace"])) printf("\nJumps %19s", sprintf("%u", player["jumps"])) } @@ -572,7 +586,7 @@ function gameinit() { player["expense"] = 0 # for tracking overall expenses player["jumps"] = 0 # for counting interplanetary jumps player["fuel"] = game["maxfuel"] # current fuel amount - player["holdspace"] = 20 # max cargo hold space + player["upglvl"] = 0 # player's upgrade level split("",shipshold) # (saveable) contents of cargo bay, up to 16 items # constants and tables @@ -592,6 +606,17 @@ function gameinit() { # rank names asplit("Penniless,Mostly Penniless,Peddler,Dealer,Merchant,Broker,Entrepreneur,Tycoon,Elite", ranknames, ",") + # ship names + asplit("Cobra Mk3,Cobra Mk3 Ext,Python,Boa,Boa 2,Anaconda", shipnames, ",") + + # upgrade prices + asplit("0 4000 2000000 4500000 4950000 6500000", shipprices, " ") + + # cargo hold values, t + asplit("20 35 100 125 175 750", cargoholds, " ") + + player["holdspace"] = cargoholds[player["upglvl"]] # max cargo hold space + # Goods # Data for DB's price/availability generation system: @@ -655,7 +680,7 @@ BEGIN { split("", globalseeds) # init galaxy seeds buildgalaxy(player["galaxynum"], globalseeds) # build the current galaxy genmarket(0, economies[player["currentplanet"]]) # build local market - printf("\nWelcome to awlite 1.7\n") + printf("\nWelcome to awlite 1.8\n") dohelp() # start the REPL printf("\n\nCash: %.1f> ", player["cash"]/10) @@ -676,7 +701,7 @@ BEGIN { else if(action == "s" || action == "sell") dosell(paramstr) else if(action == "j" || action == "jump") dojump(paramstr) else if(action == "f" || action == "fuel") dofuel(paramstr) - else if(action == "hold") dohold(game["cargoexpsize"]) + else if(action == "up" || action == "upgrade") doup(paramstr) else if(action == "save") dosave(paramstr) else if(action == "load") doload(paramstr) else printf("Unknown command")