home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Game Killer
/
Game_Killer.bin
/
082.PORTDISP.INC
< prev
next >
Wrap
Text File
|
1992-07-27
|
10KB
|
308 lines
{ Trades:
0 1 2 3 4 5 6 7
BBB SBB BSB SSB BBS SBS BSS SSS
BBB x x x x x x x x
SBB x x fo x fe x foe x
BSB x fo x x oe ofe x x
SSB x x x x efo oe fe x
BBS x fe oe efo x x x x
SBS x x ofe oe x x fo x
BSS x foe x fe x fo x x
SSS x x x x x x x x }
function compatible( i1, i2 : stuff; greed : PortTradeType) : boolean;
{ if each sells something the other buys; note greed can limit displays }
begin
if i2 = -1 then { not a port }
compatible := false
else case greed of
allTrades :
case i1 of
Class0, 0, 7 : compatible := false;
1 : compatible := i2 in [2, 4, 6];
2 : compatible := i2 in [1, 4, 5];
3 : compatible := i2 in [4, 5, 6];
4 : compatible := i2 in [1, 2, 3];
5 : compatible := i2 in [2, 3, 6];
6 : compatible := i2 in [1, 3, 5];
end; {all}
EquipOrganic :
case i1 of
Class0, 0, 1, 6, 7 : compatible := false;
2, 3 : compatible := i2 in [4,5];
4, 5 : compatible := i2 in [2,3];
end; {case EquipOrganic}
EquipFuel :
case i1 of
Class0, 0, 2, 5, 7 : compatible := false;
1, 3 : compatible := i2 in [4, 6];
4, 6 : compatible := i2 in [1, 3];
end; {case}
OrganicFuel :
case i1 of
Class0, 0, 3, 4, 7 : compatible := false;
1 : compatible := i2 in [2, 4, 6];
2 : compatible := i2 in [1, 5];
5 : compatible := i2 in [2, 6];
6 : compatible := i2 in [1, 5];
end; {case OrganicFuel}
end; {case greed}
end;
function deal( good1, good2 : stuff ) : string;
{ Port type "good1" selling to port type "good2" }
const
ND = 'no deal';
F = 'Fuel Ore';
O = 'Organics';
Q = 'Equipment';
any = 'anything';
begin
deal := ND;
case good1 of
Class0, 0 : ; {error}
1 : if good2 in [0,2,4,6] then deal := F;
2 : if good2 in [0,1,4,5] then deal := O;
3 : if good2 in [0,4] then deal := O + ' or ' + F
else if good2 in [1,5] then deal := O
else if good2 in [2,6] then deal := F;
4 : if good2 in [0,1,2,3] then deal := Q;
5 : if good2 in [0,2] then deal := Q + ' or ' + F
else if good2 in [1,3] then deal := Q
else if good2 in [4,6] then deal := F;
6 : if good2 in [0,1] then deal := Q + ' or ' + O
else if good2 in [2,3] then deal := Q
else if good2 in [4,5] then deal := O;
7 : case good2 of
Class0,7 : ; {error}
0 : deal := any;
1 : deal := Q + ' or ' + O;
2 : deal := Q + 'or ' + F;
3 : deal := Q;
4 : deal := O + ' or ' + F;
5 : deal := O;
6 : deal := F;
end; {case 7}
end; {case}
end; {deal}
function letterOfGood( g : goods ) : char;
begin
case g of
fuel : LetterOfGood := 'F';
Organics : LetterOfGood := 'O';
Equipment : LetterOfGood := 'E';
end; {case}
end; {letterOfGood}
procedure ComputeStores( psell, pbuy : PortIndex; var f1, f2 : integer;
which : goods; dump : boolean; var into : text);
var
level1, level2 : integer;
mss : string;
begin
level1 := space.ports.data[ psell ].amts[ which ];
level2 := -space.ports.data[ pbuy ].amts[ which ];
f1 := min( min( level1, level2), f1 );
mss := letterOfGood( which ) + ':' + str( level1, 5) + ' to ' +
str( level2, 4) + ' ';
write( mss );
if dump then
write( into, mss );
f2 := -min( -min( space.ports.data[ psell ].usage[ which ],
space.ports.data[ pbuy ].usage[ which ] ), -f2 );
end; {ComputeStores}
procedure DisplayStores( psell, pbuy : PortIndex; s : string;
var f1, f2 : integer;
Trade : portTradeType;
Dump : boolean; var T : text );
{ we are given two ports, and a string s that represents the goods we are
going to be trading there. For each good in s compute the minimum of
the stores we have to sell and amount to purchase, and store the maximum in f,
while also displaying the quantities the port holds. }
begin
if trade in [allTrades, EquipFuel, OrganicFuel] then
if pos( 'Fuel', s ) > 0 then
ComputeStores( psell, pbuy, f1, f2, Fuel, Dump, t );
if trade in [allTrades, EquipOrganic, OrganicFuel] then
if pos( 'Organic', s ) > 0 then
begin
f2 := 0;
ComputeStores( psell, pbuy, f1, f2, Organics, Dump, t );
end;
if trade in [allTrades, EquipOrganic, EquipFuel ] then
if pos( 'Equip', s ) > 0 then
begin
f2 := 0;
ComputeStores( psell, pbuy, f1, f2, Equipment, Dump, t );
end;
end; {DisplayStores}
procedure PortTradeFactor( s1, s2 : sector;
items12, items21 : string;
PortTrade : portTradeType;
FileDump : boolean;
var DumpFile : text );
{ Print port information from these two ports corresponding to trading
items from 1 to 2 and from 2 to 1; compute relative factor. }
var
p1, p2 : PortIndex;
factor1, factor2 : integer;
result : integer;
line : string;
begin
p1 := PortNumber( s1 );
p2 := PortNumber( s2 );
if (p1 = 0) or (p2 = 0) then
begin
if p1 = 0 then
line := 'No info available for ' + str( s1 , 1)
else if p2 = 0 then
line := 'No info available for ' + str( s2, 1 );
writeln( line );
if Filedump then
writeln( Dumpfile, line );
end
else
begin
write( 'Quantities: ' );
if FileDump then
write(DumpFile, 'Quantities: ');
factor1 := maxint; factor2 := 0;
DisplayStores( p1, p2, items12, factor1, factor2, PortTrade, FileDump, DumpFile);
DisplayStores( p2, p1, items21, factor1, factor2, PortTrade, FileDump, DumpFile);
if factor2 = 0 then
writeln(' Factor: ???')
else
writeln(' Factor: ', factor1, ', ', factor2,'%' );
if FileDump then
writeln(DumpFile,' Factor: ', factor1, ', ', factor2,'%');
end; {else}
end; {PortTradeFactor}
procedure AddEtc( s : sector; var line : string );
{ add special information to code Fighters there or SpaceLane there }
var
p : PortIndex;
begin
if space.sectors[s].etc and HasFighters <> nothing then
line := line + 'F';
if space.sectors[s].etc and Busted <> nothing then
line := line + 'X';
if space.sectors[s].etc and SpaceLane <> nothing then
line := line + 'SL';
p := PortNumber( s );
if p <> 0 then
with space.ports do
if (data[ p ].amts[equipment] <> 0) and
(data[p].usage[equipment]=0) then
line := line + 'B';
end; {AddEtc}
procedure DisplayLotsOfPortStuff( s, s1, WhichDistanceIndex : sector;
{logging,}AsciiDump, showLevels: boolean;
portTrade : portTradetype;
var f{, h} : text);
var
g, g1 : stuff;
line : string;
begin
{ if logging then
begin
writeln( h, 'R', s );
writeln( h, 'R', s1);
end; {log}
g := space.sectors[s].portType;
g1 := space.sectors[s1].portType;
line := '(' + str( s, 3);
AddEtc( s, line );
line := line + ' & ' + str(s1,3);
AddEtc( s1, line );
line := line + ' ) at distance ' + str( distances[WhichDistanceIndex].d,3)
+ ' trading ' + deal( g, g1) + ' for ' +
deal( g1, g );
writeln( line );
if AsciiDump then
writeln( f, line );
if ShowLevels then
PortTradeFactor( s, s1, deal( g, g1), deal( g1, g ),
PortTrade, AsciiDump, f );
end; {Display Lots of Port Stuff}
procedure SearchPairs( NumPorts : integer;
{ logging : boolean; var h : text; }
ASCIIDump : boolean; var f : text;
PortTrade : PortTradeType;
ShowLevels : boolean );
var
i : integer;
s, s1 : sector;
g, g1 : stuff;
t : warpIndex;
NumPairs : integer;
PauseAt : integer;
line : string;
begin
NumPairs := 0;
if ShowLevels then
PauseAt := 10
else
PauseAt := 20;
for i := 1 to NumPorts do
begin
s := distances[ i ].s;
g := space.sectors[s].portType;
if space.sectors[s].number <> Unexplored then
for t := 1 to space.sectors[s].number do
begin
s1 := space.sectors[s].data[t];
g1 := space.sectors[s1].porttype;
if (g1<> NotAPort) and (g < g1) and IsWarp( s1, s) then
{ must be a port; print only once; check if can get back }
if compatible( g, g1, PortTrade ) then
begin
DisplayLotsOfPortStuff(s, s1, i, {logging,} ASCIIdump,
showlevels, PortTrade, f{, h});
NumPairs := NumPairs + 1;
if numPairs mod PauseAt = 0 then
if not prompt('more? ') then
exit;
end; {if if}
end; {for t}
end; {for i}
end; {SearchPairs}
procedure pairport;
var
s : sector;
TradeInt : integer;
Greedy : PortTradeType;
NumSectors : sectorIndex;
QuantInfo,
AsciiDump: boolean;
h, fp : text;
begin
SortPorts( NumSectors );
QuantInfo := prompt('Do you want to see port quantity information? ');
repeat
write('Type of trade: 0 = all, 1 = Equip/Organic, 2 = Equip/Fuel, 3 = Organic/Fuel ? ');
tradeInt := readNumberFromTerminal;
until (tradeint >= 0) and (tradeInt <= 3);
Greedy := PortTradeType( tradeInt );
{ loggit := LogToDisk( h,
'Do you want to log the results in a format suitable for upload? ',
BBSname+'.upl' ); }
AsciiDump := LogToDisk( fp,
'Do you want an echo of the results to an ASCII file? ',
BBSName+'.txt');
SearchPairs( NumSectors, {Loggit, h,} AsciiDump, fp, greedy, QuantInfo );
{ if loggit then
close( h ); }
if AsciiDump then
close( fp );
end; {pair ports}