v1.7: stats command, basic ranking
This commit is contained in:
+42
-6
@@ -1,5 +1,5 @@
|
||||
# awlite: POSIX AWK port of Text Elite
|
||||
# Version 1.6.3
|
||||
# Version 1.7
|
||||
# Original high-level algorithms from Text Elite 1.5 by Ian Bell, 1999, 2015
|
||||
# Porting, corrections, improvements and optimizations by Luxferre, 2024
|
||||
#
|
||||
@@ -20,6 +20,7 @@
|
||||
# - state saving functionality since v1.6 with "save" and "load" commands
|
||||
# - 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
|
||||
# ... to be continued ...
|
||||
|
||||
# utility functions
|
||||
@@ -249,6 +250,7 @@ function gamebuy(i, a, t) {
|
||||
shipshold[i] = int(shipshold[i]) + t
|
||||
localmarket_quantity[i] -= t
|
||||
player["cash"] -= t * localmarket_price[i]
|
||||
player["expense"] += t * localmarket_price[i]
|
||||
if(goods_units[i] == 0) player["holdspace"] -= t
|
||||
return t
|
||||
}
|
||||
@@ -292,6 +294,7 @@ function displaymarket(i) {
|
||||
# move to system i
|
||||
function gamejump(i, si) {
|
||||
player["currentplanet"] = i
|
||||
player["jumps"]++
|
||||
assocdes(galaxy[i], si, "|")
|
||||
genmarket(randbyte(), int(si["economy"]))
|
||||
}
|
||||
@@ -368,7 +371,9 @@ function dojump(s, dest, d, p, si) {
|
||||
function dogalhyp() {
|
||||
if(player["cash"] > game["galhypcost"]) {
|
||||
player["cash"] -= game["galhypcost"]
|
||||
player["expense"] += game["galhypcost"]
|
||||
player["galaxynum"]++
|
||||
player["jumps"]++
|
||||
if(player["galaxynum"] == 9) player["galaxynum"] = 1
|
||||
buildgalaxy(player["galaxynum"], globalseeds) # build a new galaxy
|
||||
}
|
||||
@@ -399,6 +404,7 @@ function dohold(a, t, 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
|
||||
}
|
||||
@@ -454,6 +460,7 @@ function gamefuel(f) {
|
||||
f = int(player["cash"] / game["fuelcost"])
|
||||
player["fuel"] += f
|
||||
player["cash"] -= f * game["fuelcost"]
|
||||
player["expense"] += f * game["fuelcost"]
|
||||
return f
|
||||
}
|
||||
|
||||
@@ -478,11 +485,12 @@ function dohelp() {
|
||||
printf("\nSell product amount")
|
||||
printf("\nFuel amount (buy amount LY of fuel)")
|
||||
printf("\nJump planetname (limited by fuel)")
|
||||
printf("\nGalhyp (jumps to next galaxy)")
|
||||
printf("\nInfo planetname (prints info on system)")
|
||||
printf("\nMkt (shows market prices)")
|
||||
printf("\nLocal (lists systems within 7 lightyears)")
|
||||
printf("\nGalhyp (jump to next galaxy)")
|
||||
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("\nStat (show player statistics)")
|
||||
printf("\nSave playername (save game into current working directory)")
|
||||
printf("\nLoad playername (load game from current working directory)")
|
||||
printf("\nQuit or ^D (exit)")
|
||||
@@ -521,6 +529,28 @@ function doload(savename, fn, fs) {
|
||||
close(fn)
|
||||
}
|
||||
|
||||
# player statistics and ranking display
|
||||
# ranking formula might be subject to change in future versions
|
||||
function dostat(profind, rank) {
|
||||
profind = 0 # profit margin index
|
||||
rank = 0
|
||||
if(player["expense"] > 0) {
|
||||
profind = (player["cash"]-1000) / player["expense"]
|
||||
rank = int(log(1 + profind) / log(2)) # log base 2
|
||||
if(rank < 0) rank = 0
|
||||
if(rank > 8) rank = 8
|
||||
}
|
||||
printf("\nRank: %s", ranknames[rank])
|
||||
printf("\n\n========= Money =========")
|
||||
printf("\nBalance %17s", sprintf("%.1f CR",player["cash"]/10))
|
||||
printf("\nExpenses %16s", sprintf("%.1f CR", player["expense"]/10))
|
||||
printf("\nProfit margin %11s", sprintf("%.2f%%", profind*100))
|
||||
printf("\n\n======= Ship info =======")
|
||||
printf("\nFuel %20s", sprintf("%.1f LY", player["fuel"]/10))
|
||||
printf("\nCargo space %13s", sprintf("%ut", player["holdspace"]))
|
||||
printf("\nJumps %19s", sprintf("%u", player["jumps"]))
|
||||
}
|
||||
|
||||
# Game init procedure: first thing to call in the BEGIN block
|
||||
function gameinit() {
|
||||
rng_lastrand = 0 # state for custom PRNG
|
||||
@@ -539,6 +569,8 @@ function gameinit() {
|
||||
player["currentplanet"] = numForLave # current planet (1 to 256)
|
||||
player["galaxynum"] = 1 # current galaxy (1 to 8)
|
||||
player["cash"] = 1000 # current cash (100 CR)
|
||||
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
|
||||
split("",shipshold) # (saveable) contents of cargo bay, up to 16 items
|
||||
@@ -557,6 +589,9 @@ function gameinit() {
|
||||
# economy names
|
||||
asplit("Rich Industrial,Average Industrial,Poor Industrial,Mainly Industrial,Mainly Agricultural,Rich Agricultural,Average Agricultural,Poor Agricultural", econnames, ",")
|
||||
|
||||
# rank names
|
||||
asplit("Penniless,Mostly Penniless,Peddler,Dealer,Merchant,Broker,Entrepreneur,Tycoon,Elite", ranknames, ",")
|
||||
|
||||
# Goods
|
||||
|
||||
# Data for DB's price/availability generation system:
|
||||
@@ -620,7 +655,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.6.3\n")
|
||||
printf("\nWelcome to awlite 1.7\n")
|
||||
dohelp()
|
||||
# start the REPL
|
||||
printf("\n\nCash: %.1f> ", player["cash"]/10)
|
||||
@@ -635,6 +670,7 @@ BEGIN {
|
||||
else if(cmd == "m" || cmd == "mkt") domkt()
|
||||
else if(cmd == "l" || cmd == "local") dolocal()
|
||||
else if(cmd == "g" || cmd == "galhyp") dogalhyp()
|
||||
else if(cmd == "st" || cmd == "stat") dostat()
|
||||
else if(action == "i" || action == "info") doinfo(paramstr)
|
||||
else if(action == "b" || action == "buy") dobuy(paramstr)
|
||||
else if(action == "s" || action == "sell") dosell(paramstr)
|
||||
|
||||
Reference in New Issue
Block a user