v1.8: ship upgrades, better stats display

This commit is contained in:
Luxferre
2024-01-28 12:14:19 +02:00
parent d1b2beced5
commit d3ed7cb832
2 changed files with 70 additions and 37 deletions
+52 -27
View File
@@ -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
# 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"]])
}
}
if(player["cash"] < game["cargoexpcost"]) {
printf("\nNot enough cash! Need %.1f CR for upgrading the cargo bay", game["cargoexpcost"]/10)
return 0
}
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")