T5 has an algorithm, descended from Merchant Prince, for calculating the sale values of goods produced at a world, based on its trade codes. I've translated this into BASIC to keep my brain from rotting.
COMPRESS THE UWP
First, I compressed the UWP a bit and divide it into fields for storing on a SEQ file on tiny Commodore disk images. This results in data that looks like this:
...and so on...
In the middle of all that mess are the Remarks codes for the UWP, compressed into five characters -- one per remark, so max five remarks -- and stored in a string. For example, the Remarks for Whenge are "AJ[[[", and Zeycude's are "DJNP[".
TL is the number right before the world name, at the end of each line.
COMPRESSED REMARK CODES
A Ag
B Ba
C Cp/Cs/Cx
D De
E He
F Fl
G Ga
H Hi
I In
J Ni
K Di
L Lo
M ??
N Na
O As
P Po
Q ??
R Ri
S RsX
T ??
U ??
V Va
W Wa/Oc
X Ax
Y ??
Z ??
[ NO CODE
CALCULATING SALE VALUE
When calculating sale value, I use these data plus an array that maps letters to +1, 0, or -1 when figuring prices. Pseudocode follows:
DIM V(27) = (1, -1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, 1, -1, 1, -1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0)
The algorithm, then, is:
REM R$ has the remarks
REM TL% is TL
TO% = 3 ; total starts at 3
FOR N = 0 TO 4 ; we've got five characters to check
C$ = MID$(R$,N,1) ; check the N-th remark character
V1% = ASC(C$) - 65 ; get it's ASCII value and subtract 65 ("A"). Result is 0-26.
V2% = V(V1%) ; so "A" -> V(0) = 1, "Z" -> V(25) = 0, and "[" -> V(26) = 0.
TO% = TO% + V2% ; add to total
NEXT N
TO% = TO% * 10 ; prepare to receive TL
TO% = TO% + TL% ; add in TL
TO% = TO% * 100 ; now convert to credits
COMPRESS THE UWP
First, I compressed the UWP a bit and divide it into fields for storing on a SEQ file on tiny Commodore disk images. This results in data that looks like this:
Code:
DATA "0101", "C-", 3, "DJNP[/-83/ZH/K5 ", "-", 9, "ZEYCUDE"
DATA "0102", "C-", 5, "DENP[/-C2/ZH/G5M5 ", "A", 10, "RENO"
DATA "0103", "BA", 7, "JR[[[/-91/ZH/M5M5 ", "-", 11, "ERRERE"
DATA "0104", "C-", 3, "L[[[[/-C1/ZH/F5 ", "-", 9, "CANTREL"
DATA "0108", "C-", 3, "EF[[[/-E3/NA/A5 ", "-", 8, "GYOMAR"
DATA "0202", "C-", 3, "AJ[[[/-C2/ZH/G5M5 ", "-", 5, "THENGO"
DATA "0301", "C-", 4, "AGJR[/-82/NA/M5M5 ", "-", 8, "RIO"
DATA "0303", "BA", 6, "JN[[[/-C2/ZH/M5M5 ", "A", 12, "GESENTOWN"
DATA "0304", "AA", 8, "CH[[[/-51/ZH/F5 ", "-", 13, "CHRONOR"
DATA "0307", "BA", 7, "NP[[[/-81/ZH/F5M5 ", "A", 10, "ATSA"
DATA "0503", "D-", 2, "AJ[[[/-D1/NA/F5 ", "-", 8, "WHENGE"
DATA "0601", "E-", 3, "A[[[[/-E3/NA/F5 ", "-", 6, "ENLAS-DU"
DATA "0605", "C-", 5, "AGJR[/-A1/NA/M5M5 ", "-", 9, "ALGEBASTER"
DATA "0607", "E-", 1, "J[[[[/-61/NA/F5 ", "-", 7, "RASATT"
DATA "0608", "AA", 6, "JN[[[/-61/ZH/A5 ", "-", 12, "NINJAR"
In the middle of all that mess are the Remarks codes for the UWP, compressed into five characters -- one per remark, so max five remarks -- and stored in a string. For example, the Remarks for Whenge are "AJ[[[", and Zeycude's are "DJNP[".
TL is the number right before the world name, at the end of each line.
COMPRESSED REMARK CODES
A Ag
B Ba
C Cp/Cs/Cx
D De
E He
F Fl
G Ga
H Hi
I In
J Ni
K Di
L Lo
M ??
N Na
O As
P Po
Q ??
R Ri
S RsX
T ??
U ??
V Va
W Wa/Oc
X Ax
Y ??
Z ??
[ NO CODE
CALCULATING SALE VALUE
When calculating sale value, I use these data plus an array that maps letters to +1, 0, or -1 when figuring prices. Pseudocode follows:
DIM V(27) = (1, -1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, 1, -1, 1, -1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0)
The algorithm, then, is:
REM R$ has the remarks
REM TL% is TL
TO% = 3 ; total starts at 3
FOR N = 0 TO 4 ; we've got five characters to check
C$ = MID$(R$,N,1) ; check the N-th remark character
V1% = ASC(C$) - 65 ; get it's ASCII value and subtract 65 ("A"). Result is 0-26.
V2% = V(V1%) ; so "A" -> V(0) = 1, "Z" -> V(25) = 0, and "[" -> V(26) = 0.
TO% = TO% + V2% ; add to total
NEXT N
TO% = TO% * 10 ; prepare to receive TL
TO% = TO% + TL% ; add in TL
TO% = TO% * 100 ; now convert to credits