[go: up one dir, main page]

Menu

[fa6046]: / gtycoon.mps  Maximize  Restore  History

Download this file

1362 lines (1234 with data), 33.8 kB

Uses Cfg
Uses User

Include gtdefs.inc
Include gtfiles.inc

Procedure GamePause
Begin
	Write('|CR'+PadCt('|01<|09PAUSE|01>|11',91,' ')+'|[D99')
	ReadKey
End

Function RRandom:Real
Begin
	RRandom:=Random(100)/100
End

Function Sector2XY(S:Integer):String
Var Ret	: String
Var X,Y	: Integer
Begin
	X:=(S%20+1)
	Y:=(S/20+1)
	Ret:='|09'+Chr(X+Ord('A')-1)+Chr(X+Ord('A')-1)+'|14'+PadLt(Int2Str(Y),2,'0')
	Sector2XY:=Ret
End

Function CurrentSector:Integer
Var X,Y,Ret	: Integer=0
Begin
	X:=((Ship.LocX-1)/20)
	Y:=((Ship.LocY-1)/20)
	Ret:=X+(Y*20)
	CurrentSector:=Ret
End

Function EmptyHolds:Integer
Var Ret	: Integer = Ship.Holds
Var I		: Integer = 1
Begin
	For I:=1 To 5 Do 
		Ret:=Ret-Ship.Goods[I]
	EmptyHolds:=Ret
End

Procedure ShowAllAlliances
Var I	: Integer=1
Var P1,P2	: PlanetRec
Begin
	While ReadAlliance(I) Do Begin
		ReadPlan(Alnc.From)
		P1:=Plan
		ReadPlan(Alnc.ToTo)
		P2:=Plan
		Write(PadLt(Int2Str(Alnc.Idx),5,' ')+' '+P1.Name)
		Case Alnc.Alliance Of
			NEUTRAL:	Write(' ? ')
			HOSTILE:	Write(' ! ')
			FRIENDLY:	Write(' = ')
		End
		WriteLn(P2.Name)
		I:=I+1
	End
	Pause	
End

Function WhereAmI:Integer
Var Ret	: Integer
Var I		: Integer
Var Done	: Boolean = False
Begin
	I:=1
	Ship.LastSeen:=0
	While Not Done And ReadPlan(I) Do Begin
		If Plan.LocX = Ship.LocX And Plan.LocY = Ship.LocY And Plan.LocX = Ship.LocX Then Begin
			Ret:=Plan.Idx
			Ship.LastSeen:=Plan.Idx
			Done:=False
		End
		I:=I+1
	End
	SaveShip(Ship.Idx)
	WhereAmI:=Ret
End

Function WriteLOC(X,Y,Z:Integer):String
Var S	: String
Begin
	S:='|09S|11'+PadLt(Int2Str(Z),2,'0')
	S:=S+'|09X|11'+PadLt(Int2Str(X),2,'0')
	S:=S+'|09Y|11'+PadLt(Int2Str(Y),2,'0')
	WriteLOC:=S
End

Procedure PlanInfo(D:Integer)
Var R	: Byte
Var I	: Integer
Var P1,P2	: PlanetRec
Var S	: String
Begin
	If D < 1 Then Begin
		WriteLn('|CR  |12No planets are nearby....|10')
		Exit
	End
	ReadPlan(D)
	ReadCorp(Plan.Govt)
	P1:=Plan
	ClrScr
	WriteLn('')
	WriteLn('|09%%%%% |15'+P1.Name)
	WriteLn('')
	WriteLn('|09%%%%% |14Planetary Info |09%%%%%%')
	WriteLn('  |14Class          |09: |15'+Int2Str(P1.Class))
	WriteLn('  |14Location       |09: |14Sector#|15'+Int2Str(P1.LocZ)+ ' |09(|15'+Int2Str(P1.LocX)+'|09/|15'+Int2Str(P1.LocY)+'|09)')
	If Plan.Govt = 1 Then
	WriteLn('  |05Governed By    : |13Government of '+Plan.Name)
	Else
	WriteLn('  |05Governed By    : |13'+Corp.Name)
	WriteLn('  |02Allied With:')
	For I:=1 To GNumAlncs Do Begin
		ReadAlliance(I)
		If Alnc.From = D And Alnc.Alliance=FRIENDLY Then Begin
			ReadPlan(I)
			S:=WriteLOC(Plan.LocZ,Plan.LocX,Plan.LocY)
			WriteLn('   |10(|11#'+Int2Str(Plan.Idx)+'|10) |11'+Plan.Name+'|12:'+S)
		End
	End
	WriteLn('  |12At War With:')
	For I:=1 To GNumAlncs Do Begin
		ReadAlliance(I)
		If Alnc.From = D And Alnc.Alliance=HOSTILE Then Begin
			ReadPlan(I)
			S:=WriteLOC(Plan.LocZ,Plan.LocX,Plan.LocY)
			WriteLn('   |12(|11#'+Int2Str(Plan.Idx)+'|12) |11'+Plan.Name+'|09:'+S)
		End
	End
	
	WriteLn('  |14Techology Level|09: |15'+Real2Str(P1.TekLev,2))
	WriteLn('  |14Population     |09: |15'+Real2Str(P1.pop,2)+' |14Million')
	WriteLn('  |14Industry Level |09: |15'+Real2Str(P1.IndLev,2))
	WriteLn('')
	WriteLn('|09%%%%% |14Available Goods |09%%%%%')
	For R:=1 To 5 Do Begin
		Write('  |14'+PadRt(GoodsNames[R],20,' ')+' |12: |15$')
		WriteLn(PadLt(StrComma(GoodsBases[R]*Plan.Rates[R]),10,' ')+' |14Credits')
	End
End

Procedure SelectPlanet(D: Byte)
Begin
	Write('|CR  |02Which Planet? [1-'+Int2Str(GNumPlans)+'] : ')	
	D:=Str2Int(Input(3,3,1,''))
	If D>=1 And D<=GNumPlans Then Begin
		PlanInfo(D)
	End
End

Procedure Q2BBS
Begin
	If InputNY('|CR  |10Do you really want to quit? : ') Then Begin
		ClrScr
		Halt
	End 
	WriteLn('')
End


Procedure Intro
Var Done	: Boolean = False
Var Ch1	: Char
Begin
	DispFile('gt-splash')
	While Not Done Do Begin
		ClrScr	
		WriteLn('')
		WriteLn('|13')
		WriteLn(PadCt('Welcome To',79,' '))
		WriteLn('|10')
		WriteLn(PadCt(Program,79,' '))
		WriteLn(PadCt('By Darryl Perry, 2014',79,' '))
		WriteLn('')
		WriteLn(PadCt('There are '+Int2Str(GNumPlans)+' planets',79,' '))
		WriteLn(PadCt('and '+Int2Str(GNumPlyrs)+' Tycoons',79,' '))
		WriteLn('')
		WriteLn(PadCt('|06[|14E|06]|14nter the game      ',91,' '))
		WriteLn(PadCt('|06[|14I|06]|14nstruction         ',91,' '))
		WriteLn(PadCt('|06[|14L|06]|14ist Tycoons        ',91,' '))
		WriteLn(PadCt('|06[|14Q|06]|14uit Galactic Tycoon',91,' '))
		WriteLn('')
		Write  (PadLt('|14Command |11: ',48,' '))
		
		Ch1:=OneKey('EQLI',True)
		Case Ch1 Of 
			'Q': Q2BBS
			'E': Done:=True
		End
	End
End

Procedure GalaxyMap
Var X,Y,I	: Integer
Var GX,GY	: Integer
Var SList	: Array [1..20,1..20] Of Integer
Begin
	For X:=1 To 20 Do Begin
		For Y:=1 To 20 Do Begin
			SList[X,Y]:=0
		End
	End

	GX:=((Ship.LocX-1)/20)+1
	GY:=((Ship.LocY-1)/20)+1

	I:=1
	While ReadPlan(I) Do Begin
		X:=((Plan.LocX-1)/20)+1
		Y:=((Plan.LocY-1)/20)+1

		If X > 0 And X < 21 Then Begin
			If Y > 0 And Y < 21 Then Begin
				SList[X,Y]:=SList[X,Y]+1
			End
		End
		I:=I+1
	End

	ClrScr

	For X:=1 To 20 Do Begin
		WriteXY((X*3)+8,2,09,Chr(X+Ord('A')-1)+Chr(X+Ord('A')-1))
		WriteXY(06,X+3,02,PadLt(Int2Str(X),2,'0'))
		WriteXY(73,X+3,02,PadLt(Int2Str(X),2,'0'))
	End
	
	For X:=1 To 20 Do Begin
		For Y:=1 To 20 Do Begin
			If X=GX and Y=GY Then
				WriteXY((X*3)+8,Y+3,14,PadLt(Int2Str(SList[X,Y]),2,'0'))
			Else
				WriteXY((X*3)+8,Y+3,11,PadLt(Int2Str(SList[X,Y]),2,'0'))
		End
	End
	GamePause
End

Procedure Map
Var SC,PL	: Integer
Var X,X1,Y1	: Integer
Var Y,X2,Y2	: Integer
Var I,A,B	: Integer
Var Done		: Boolean = False
Var Ch		: Char
Var PList	: Array [1..30] of Integer
Begin

	SC:=CurrentSector
	While Not Done Do Begin
		X:=(SC%20)+1
//		If X = 0 Then X:=20

		X1:=((SC%20)*20)+1
		X2:=X1+19

		Y:=(SC/20)+1

		Y1:=SC/20
		Y1:=Y1*20+1
		Y2:=Y1+19

		ClrScr

		For A:=1 To 20 Do Begin
			WriteXY((A*2)+2,1,09,Chr(X+64))
			WriteXY((A*2)+3,1,10,Chr(A+64))
			WriteXY(1,A+1,09,PadLt(Int2Str(Y1+A-1),3,' '))
		End
		A:=1
		For PL:=1 To MaxPlanets Do Begin
			ReadPlan(PL)
			If Plan.LocX >= X1 And Plan.LocX <= X2 Then Begin
				If Plan.LocY >= Y1 And Plan.LocY <= Y2 Then Begin
					WriteXY(48,A+1,Plan.Govt,Chr(A+ord('a')-1)+' '+PadLt(Int2str(Plan.Idx),5,' ')+' '+PadRt(Plan.Name,20,' '))	
					WriteXY(((Plan.LocX-X1)*2)+5,Plan.LocY-Y1+2,Plan.Govt,Chr(A+ord('a')-1))
					PList[A]:=Plan.Idx
					A:=A+1	
				End
			End
		End
		WriteXY(1,24,11,'('+Chr(X+64)+Chr(X+64)+PadLt(Int2Str(Y),2,'0')+') : X['+Int2Str(X1)+'-'+Int2Str(X2)+'];Y['+Int2Str(Y1)+'-'+Int2Str(Y2)+'] : ')
		Ch:=ReadKey
		If IsArrow Then Begin
			Case Ch Of
				#72: SC:=SC-20
				#77: SC:=SC+1
				#75: SC:=SC-1
				#80: SC:=SC+20
			End
			If SC < 1 Then SC:=SC+400
			If SC > 400 Then SC:=SC-400
		End Else Begin
			Ch:=Upper(Ch)
			Case Ch Of
				'Q',#27: Done:=True
			Else
				I:=Ord(Ch)-64
				ClrScr
				PlanInfo(PList[I])
				GamePause
				ClrScr
			End
		End
	End
End


Procedure OldMap 
Var I,X,Z,I1,IX	: Integer
Var F,B,S,SX: String
Var V,C,D	: Byte
Var M			: Char
Var PList	: Array [1..30] of Integer
Begin
	Z:=Ship.LocZ
	ClrScr
	Repeat 
		For X:=1 To 20 Do Begin
			F:=Copy(PadLt(Int2Str(X),2,' '),1,1)
			GoToXy(X*2+4,1)
			Write('|02'+F)
			B:=Copy(PadLt(Int2Str(X),2,' '),2,1)
			GoToXy(X*2+4,2)
			Write('|02'+B)

			GoToXy(X*2+3,3)
			Write('|05--')

			For V:=1 To 20 Do Begin
				WriteXY((X*2)+3,V+3,0,'  ')
			End

			GoToXy(2,X+3)
			Write('|02'+PadLt(Int2Str(X),2,' ')+'|05:')
			GoToXy(45,X+3)
			Write('|05:|02'+PadRt(Int2Str(X),2,' '))
		End

		GoToXy(49,2)
		Write(PadCt('Sector '+Int2Str(Z),30,' '))
		GoToXy(49,3)
		Write('|09'+PadCt('=',30,'='))

		C:=0
		For X:=1 To GNumPlans Do Begin
			If ReadPlan(X) Then Begin
				If Plan.LocX = Z Then Begin
					D:=C+ord('a')
					C:=C+1
					GoToXy(Plan.LocX*2+4,Plan.LocY+3)
					Write('|'+PadLt(Int2Str(Plan.Class+8),2,'0'))
					Write(chr(d))
					GoToXy(49,C+3)
					Write(chr(d)+' '+PadLt(Int2Str(Plan.Idx),3,' ')+' '+PadRt(Copy(Plan.Name,1,25),25,' '))
					PList[C]:=Plan.Idx
				End
			End
			If Ship.LocZ=Z Then Begin
				GoToXy(Ship.LocX*2+3,Ship.LocY+3)
				Write(Chr(223+Plyr.Idx))
			End

		End	
		While C < 20 Do Begin
			C:=C+1
			WriteXY(49,C+3,0,'                               ')
		End
		GoToXy(1,24)
		Write('|05|16')
		Write(PadCt('-',78,'-'))
		GoToXy(1,25)
//          Write(PadLt('|02Which Sector |05[|101|08-|1020|02,|10Q|08=|10Quit|05] |09: ',64,' '))
		SX:='|01'
		For IX:=1 To 20 Do Begin
			If IX = Z Then
				SX:=SX+'|09'
			Else
				SX:=SX+'|01'
			SX:=SX+PadLt(Int2Str(IX),2,'0')+' '
		End
		Write(SX)
		M:=ReadKey
		If IsArrow Then Begin
			If M = #77 Then Begin 
				Z:=Z+1
				If Z > 20 Then
					Z:=1
			End
			If M = #75 Then Begin 
				Z:=Z-1
				If Z < 1 Then
					Z:=20
			End
		End Else Begin
			M:=Upper(M)
			If Ord(M) >= Ord('A') And Ord(M) <= Ord('Z') And M <> 'Q' Then Begin	
				I:=Ord(M)-64
				ClrScr
				PlanInfo(PList[I])
				GamePause
				ClrScr
			End
		End
	Until M = #27 Or M = 'Q'
	ReadShip(Plyr.CurShip) 
End

Function SquareRoot(SRNum : Real): Real
Var X	: Real
Var R	: Real
Begin
	R:=1
	R:=R/100
	X:=1
	X:=X/100
	While X*X < SRNum Do Begin
		X:=X+R
	End
	SquareRoot:=X
End

Function CalcDist(D : Byte; A,B,C,X,Y,Z : Real): Real
Var	L	: Real 
Var	M	: Real 
Var 	N	: Real 
Var	R	: Real 
Var	Q	: Real 
Begin
	If A>X Then
		L:=A-X
	Else
		L:=X-A
	If B>Y Then
		M:=B-Y
	Else
		M:=Y-B
	If C>Z Then
		N:=C-Z
	Else
		N:=Z-C

	L:=L*L
	M:=M*M
	N:=N*N
	Q:=SquareRoot(L+M)
	R:=Q*Q

   CalcDist:=SquareRoot(R+N)
End

Procedure ListPlanets
Var	X	: Integer
Var Done	: Boolean = False
Begin
	WriteLn('|16|11|CL#### Planet                                   XXX YYY Sec Dist (LY)')
	WriteLn('==== ======================================== === === === =====    ')
	X:=1 
	While Not Done And ReadPlan(X) Do Begin
		Write('|09')
		Write(PadLt(Int2Str(Plan.Idx),4,' ')+'|11 ')
		Write(PadRt(Plan.Name,40,' ')+'|12' )
      Write(PadLt(Int2Str(Plan.LocX),4,' ')+'|13')
		Write(PadLt(Int2Str(Plan.LocY),4,' ')+'|14')
		Write(PadLt(Int2Str(Plan.LocZ),4,' ')+'|15')
      Write(' '+PadLt(Real2Str(CalcDist(0,Ship.LocX,Ship.LocY,Ship.LocZ,Plan.LocX,Plan.LocY,Plan.LocZ),2),5,' '))
		WriteLn('')
		If X % 22 = 0 Then Begin
			If Not InputYN('|CR  Continue? : ') Then 
				Done:=True
			Else Begin
				WriteLn('|11|CL#### Planet                                   XXX YYY Sec Dist (LY)')
				WriteLn('==== ======================================== === === === =====    ')
			End
		End
		X:=X+1
	End	
End

Procedure FindDistance(D:Byte):Real
Begin
	FindDistance:=0.00
	If D >= 1 and D <=GNumPlans Then Begin
		If ReadPlan(D) Then Begin
			FindDistance:=CalcDist(0,Ship.LocX,Ship.LocY,Ship.LocZ,Plan.LocX,Plan.LocY,Plan.LocZ)
		End
	End 
End

Function ClosestPlanet:Integer
Var I,Ret		: Integer = 0
Var Y,X			: Real = 10000.00
Begin
	I:=1
	While ReadPlan(I) Do Begin
		X:=FindDistance(I)
		If X <= Y Then Begin 
			Y:=X
			Ret:=I
		End
		I:=I+1
	End	
	ClosestPlanet:=Ret
End

Procedure ListClosestPlanets(MaxNum : Integer)
Type
     Plan2Rec = Record
          Dist:Real
          Idx:Integer
		End
Var  D    : Array [1..201] of Plan2Rec
Var	X	: Integer
Var	Y	: Integer
Var	R	: Integer
Var	C	: Byte
Begin

	WriteLn('')
	For X:=1 To GNumPlans Do Begin
		C:=X%16
		Write('|'+PadLt(Int2Str(C),2,'0')+'  **THINKING**|[D15')
		If ReadPlan(X) Then Begin
			D[X].Dist:=CalcDist(0,Ship.LocX,Ship.LocY,Ship.LocZ,Plan.LocX,Plan.LocY,Plan.LocZ)
			D[X].Idx:=X
		End
	End

	For X:=1 to GNumPlans Do Begin
		For Y:=1 to GNumPlans Do Begin
			If D[Y].Dist>D[X].Dist Then Begin
				D[201]:=D[X]
				D[X]:=D[Y]
				D[Y]:=D[201]
     		End
		End
	End

	WriteLn('|CR|CR|11Closest Planets:')
	WriteLn('|10#### Planet Name                                X   Y  SecNo Distance')
	WriteLn('|09==== ========================================= === === ===== ========')
	For R:=1 To 5 Do Begin
		If ReadPlan(D[R].Idx) Then Begin
			Write('|15'+PadLt(Int2Str(Plan.Idx),4,' ')+' ')
			Write('|14'+PadRt(Plan.Name,40,' ') )
			Write('|08'+PadLt(Int2Str(Plan.LocX),4,' '))
			Write('|07'+PadLt(Int2Str(Plan.LocY),4,' '))
			Write('|03'+PadLt(Int2Str(Plan.LocZ),5,' '))
			WriteLn(' |10'+PadLt(Real2Str(D[R].Dist,2),6,' ')+' LYs')
		End
	End
End

Procedure RenameShip(SI:Integer)
Var S	: String=''
Var Done	: Boolean = False
Begin
	If ReadShip(SI) Then Begin
		If Ship.Plyr=Plyr.IDX Then Begin
			Repeat
				Write('|CR|CR|02  I see you have a nice shiney new ship.  What do you call it?|CR  : ')
				S:=Input(50,50,11,S)
				If InputYN('|CR  |10"'+S+'?"  Is this what you want? |11: ') Then Begin
					Ship.Name:=S
					SaveShip(SI)
					Done:=True
				End
			Until Done
		End
	End Else Begin
		WriteLn('|12  |12Error!  Can''t find ship '+Int2Str(SI)+'!')
	End
End

Procedure NewShip(CL:Integer)
Var I:	 Integer
Begin
	ReadBoat(1)
	Ship:=Boat
	Ship.Idx:=GNumShips+1
	Ship.Plyr:=Plyr.Idx
	Ship.Fuel:=50.00
	Ship.Name:=''

	Ship.Shields:=Ship.ShieldsMax/2
	Ship.Cannon	:=Ship.CannonMax/2
	Ship.Crew	:=Ship.CrewMax/2
	Ship.Missles:=Ship.MisslesMax/2
	Ship.Fighters:=Ship.FightersMax/2
	For I:=1 To 5 Do
		Ship.Goods[I]:=0

	Plyr.CurShip:=Ship.Idx
	SaveShip(Ship.Idx)
	SavePlyr(Plyr.Idx)
	GNumShips:=GNumShips+1
	RenameShip(Ship.Idx)
End

Procedure FindHomePlanet
Var C,I	: Integer
Var Done	: Boolean = False
Begin
	C:=1
	While Not Done And C < 100 Do Begin
		I:=Random(GNumPlans)+1
		If ReadPlan(I) Then Begin
			If Plan.HomeTo = 0 Then Begin
				Plan.HomeTo:=Plyr.Idx
				Plyr.HomePlan:=I
				SavePlyr(Plyr.Idx)
				SavePlan(Plan.Idx)
				Done:=True
			End
		End
		C:=C+1
	End
End

Procedure NewPlyr
Var I	: Integer
Begin
	GetThisUser
	Plyr.Idx:=GNumPlyrs+1	
	Plyr.Name:=UserAlias
	Plyr.Alias:=UserAlias
	Plyr.Bank:=0
	Plyr.Corp:=1
	Plyr.LastOn:=DateTime
	Plyr.Credits:=1000

	WriteLn('|CR|CR|CR  |02Welcome New Tycoon!')
	Repeat
		Write('|CR|02  What do you wish to call yourself?|CR  |10: ')
		Plyr.Alias:=Input(40,40,11,'')	
	Until InputNY('|10  "Captain ' + Plyr.Alias+'|02?  Is that what you want? |10: ')

	SavePlyr(Plyr.Idx)

	NewShip(1)

	FindHomePlanet
	If ReadPlan(Plyr.HomePlan) Then Begin
		If ReadShip(Plyr.CurShip) Then Begin
			Ship.LocX:=Plan.LocX
			Ship.LocY:=Plan.LocY
			Ship.LocZ:=Plan.LocZ
			SaveShip(Ship.Idx)	
		End Else Begin
			WriteLn('|10  |12There was a problem finding a ship for you.|CR|10')
		End
	End 

	WriteLn('  |10You are in orbit above your home planet of '+Plan.Name)

	SavePlyr(Plyr.Idx)
End

Function FindPlayer(PlyrName : String) : Integer
Var	Ret	: Integer = 0
Var	Found	: Boolean = False
Var	X	: Integer = 1
Begin
	While ReadPlyr(X) And Not Found Do Begin
		If upper(Plyr.Name) = Upper(PlyrName) Then Begin
			Ret  :=X
			Found:=True
		End
		X:=X+1
	End
	FindPlayer:=Ret
End

Procedure ListShips
Var	X	: Integer
Begin
	X:=1
	WriteLn('|CR|CR  |02Tycoon Ships')
	WriteLn('|05-------------------------------------------------------------------------------')
	While ReadShip(X) Do Begin
          Write  (' |09'+PadLt(Int2Str(Ship.Idx),3,' '))
		Write  (' |10'+PadRt(Ship.Model,20,' '))
		Write  (' |09'+PadLt(Int2Str(Ship.cost),10,' '))
		WriteLn(' |09'+PadLt(Int2Str(Ship.Holds),10,' '))
		X:=X+1
	End
     GamePause 
End

Procedure ListPlayers
Var	X	: Integer
Var	MyIdx	: Integer
Var 	B1	: Boolean
Begin
	MyIdx:=Plyr.Idx
	X:=1
	WriteLn('|CR|CR  |02Tycoon Rankings')
	WriteLn('|04 Tycoon              Shipname            Ship Type           Rank')
	WriteLn('|06-------------------------------------------------------------------------------')
     While ReadPlyr(X) Do Begin
		Write  (' |10'+PadRt(Plyr.Alias,20,' '))
		Write  (' |08'+PadRt(Ship.Name,20,' ') )
		Write  (' |08'+PadRt(Ship.Model,20,' ') )
		WriteLn(' |09'+PadLt(Int2Str(Plyr.Rank),3,' '))
		X:=X+1
	End
	B1:=ReadPlyr(MyIdx)
	GamePause 
End

Procedure NewDay
Begin
	WriteLn('|CR|02It is a new Day')

	WriteLn('|12Your chrystals have regenerated to 100% capacity')
	Plyr.LastOn:=DateTime
	SavePlyr(Plyr.Idx)
End

Procedure EnterGame
Var Y	: Integer
Begin
	Y:=FindPlayer(UserAlias)
	If Y=0 Then
		NewPlyr
	Else Begin
		ReadPlyr(Y)
		WriteLn('|CL|CR|CR'+PadCt('Welcome Back, '+Plyr.Name,79,' '))
		If DaysAgo(Plyr.LastOn) > 0 Then Begin
			NewDay
		End Else Begin
			Plyr.LastOn:=DateTime
			If Not ReadShip(Plyr.CurShip) Then Begin
				WriteLn('|CR  |10Can''t find your ship!')	
			End Else Begin
				WriteLn('|CR|10'+PadCt('You are aboard your ship, "|15'+Ship.Name+'|10"',85,' ')+'|10|CR')
			End
		End
		GamePause
		WhereAmI
	End
End

Procedure FleetList
Var I	: Integer
Begin
	I:=1
	WriteLn('|11  ### Name                      Class                    Sector:X/Y|10')
	WriteLn('|09  |$D03'+#196+' |$D25'+#196+' |$D24'+#196+' |$D16'+#196+'|10')
	While ReadShip(I) Do Begin
		If Ship.Plyr = Plyr.Idx Then Begin
			Write('|11'+PadLt(Int2Str(Ship.Idx),5,' ')+' |12')
			Write(PadRt(Ship.Name,25,' ')+' |13')
			Write(PadRt(Ship.Model,25,' |10'))
			Write(Int2Str(Ship.LocZ)+':'+Int2Str(Ship.LocX)+'/'+Int2Str(Ship.LocY))
			WriteLn('')
		End
		I:=I+1
	End
	WriteLn('')
End

Procedure ShipInfo(I:Integer)
Var S	: String
Begin
	If ReadShip(I) Then Begin
		WriteLn('')
		Write('  Ship  : '+PadRt(Ship.Name,20,' '))
		Write(' Type: '+PadRt(Ship.Model,20,' '))
		WriteLn(' Fuel: '+Real2Str(Ship.Fuel/100,2)+'/'+Real2Str(Ship.FuelMax/100,2))
		Write('  Holds : '+PadRt(Int2Str(Ship.Holds)+'/'+Int2Str(Ship.HoldsMax),15,' '))
		Write('   Shields: '+PadRt(Int2Str(Ship.Shields)+'/'+Int2Str(Ship.ShieldsMax),15,' '))
		WriteLn('     Crew : '+PadRt(Int2Str(Ship.Crew)+'/'+Int2Str(Ship.CrewMax),15,' '))
		Write('  Cannon: '+PadRt(Int2Str(Ship.Cannon)+'/'+Int2Str(Ship.CannonMax),15,' '))
		Write('   Missles: '+PadRt(Int2Str(Ship.Missles)+'/'+Int2Str(Ship.MisslesMax),15,' '))
		Write('  Fighters: '+Int2Str(Ship.Fighters)+'/'+Int2Str(Ship.FightersMax))
		WriteLn('')
		Write	('  Damage: '+Int2Str(Ship.Damage)+'%            ')
		S:='No'
		If Ship.IsCloaked Then 
			S:='Yes'
		Write  ('    Cloaked: '+PadRt(S,15,' ')) 
		S:=WriteLOC(Ship.LocZ,Ship.LocX,Ship.LocY)
		WriteLn('  Location: '+S)
		TitleBar('Inventory')
		For I:=1 To 5 Do 
			Write  (PadLt(ShortNames[I],12,' '))
		Write(PadLt('Empty',12,' '))
		WriteLn('|07')
		For I:=1 To 5 Do 
			Write  (PadLt(StrComma(Ship.Goods[I]),12,''))
		Write  (PadLt(StrComma(Ship.Holds),12,' '))
	End Else Begin
		WriteLn('|CR  |12Unable to view ship info|CR')
	End
End

Function SelectShip:Integer
Var I	: Integer = 0
Begin
	Write('|CR  View which ship? (Ship ID #) : ')
	I:=Str2Int(Input(3,3,1,''))
	SelectShip:=I
End

Procedure ViewShipInfo
Var I	: Integer=SelectShip
Begin
	If I > 0 Then
		ShipInfo(I)
End

Procedure ShipMenu
Var Ch	: Char
Var Done : Boolean = False
Begin
	While Not Done Do Begin
		TitleBar('Ship Menu')
		ShipInfo(Plyr.CurShip)	
		Write  ('|CR|CR')
		WriteLn('  |06(|14S|06)|11elect Ship')
		WriteLn('  |06(|14R|06)|11ename Ship')
		WriteLn('  |06(|14Q|06)|11uit Ship Menu')
		Write  ('|CR|CR')
		Write('  |10Ship Operations:|CR  Your Command, |11Captain '+Plyr.Alias+' : ')
		Ch:=OneKey('SRQ',True)
		Case Ch Of
			'R': RenameShip(Plyr.CurShip)
			'Q': Done:=True
		End
	End
End

Procedure ListDefShips
Var I	: Integer
Begin
	I:=1 
	While ReadBoat(I) Do Begin
		Write  ('|11'+PadLt(Int2Str(I),5,' ')+' |12'+PadRt(Boat.Model,30,' '))
		Write  ('|09'+PadLt(ShipClass[Boat.Class],20,' '))
		Write  ('|15'+PadLt('$'+StrComma(Boat.Cost),15,' '))
		WriteLn('|13'+PadLt(Int2Str(Boat.HoldsMax),5,' '))
		I:=I+1
	End	
End

Procedure ViewShipType(I:Integer)
Begin
	If I < 1 Then Begin
		Write('|CR  View which ship? [1-'+Int2Str(GNumBoats)+'] : ')	
		I:=Str2Int(Input(5,5,1,''))
	End
	If ReadBoat(I) Then Begin
		TitleBar(Boat.Model+' Info')
		WriteLn('')
		WriteLn('   Model: '+Boat.Model)		
		WriteLn('    Cost:$'+StrComma(Boat.Cost)+' Credits')
		WriteLn('    Crew: '+Strcomma(Boat.Crew)+', with a max of '+StrComma(Boat.CrewMax)+'.')
		WriteLn('   Holds: '+Strcomma(Boat.Holds)+', upgradeable to '+StrComma(Boat.HoldsMax)+'.')
		WriteLn(' Shields: '+Strcomma(Boat.Shields)+', upgradeable to '+StrComma(Boat.ShieldsMax)+'.')
		WriteLn('  Cannon: '+Strcomma(Boat.Cannon)+' installed, upgradeable to '+StrComma(Boat.CannonMax)+' max.')
		WriteLn(' Missles: '+Strcomma(Boat.Missles)+' included, but can hold up to '+StrComma(Boat.MisslesMax)+' max.')
		WriteLn('Fighters: '+Strcomma(Boat.Missles)+' included, but can house '+StrComma(Boat.FightersMax)+' max.')
		WriteLn('   Cloak: '+YorN(Ship.CanCloak))
		WriteLn('')
		GamePause
	End
End

Procedure SellShip
Begin
	ListDefShips
		
End

Procedure BuyShip
Var I	: Integer
Var Done	: Boolean = False
Var S	: String
Begin
	While Not Done Do Begin
		WriteLn('|10')
		ListDefShips
		WriteLn('|CR  |10Which ship were you interested in buying?')
		Write('|CR  Command [|111|10-|114] |11: ')
		I:=Str2Int(Input(3,3,1,''))
		If ReadBoat(I) Then Begin
			S:='|CR  |02"|10You wish to buy the |07'+Boat.Model+' |10for |11$'
			S:=S+StrComma(Boat.Cost)+'|10?|02" : '
			If InputYN(S) Then Begin
				If Plyr.Credits >= Boat.Cost Then Begin 
					WriteLn('|CR  "Sold!  Here are the keys.|CR')
					Plyr.Credits:=Plyr.Credits-Boat.Cost
					SavePlyr(Plyr.Idx)
					NewShip(I)
				End Else Begin
				End
			End
		End Else Begin
			WriteLn('|CR  "Come back when you are ready to buy!|CR')
			Done:=True
		End
	End
End

Procedure BuySellShip
Var Ch	: Char
Var Done	: Boolean = False
Var I		: Integer 
Begin
	While Not Done Do Begin
		TitleBar('Ship Showroom')

		ListDefShips

		WriteLn('|CR  |06(|14B|06)|11uy a ship')
		WriteLn('  |06(|14S|06)|11ell a ship')
		WriteLn('  |06(|14V|06)|11iew a ship')
		Write('|CR  |10Ship Salesroom:|CR  Your Command, |11Captain '+Plyr.Alias+' : ')
		Ch:=OneKey('BSVQ',True)
		Case Ch Of
			'B': BuyShip
			'S': SellShip
			'V': ViewShipType(0) 
			'Q': Done:=True
		End
	End
End

Procedure FleetMenu
Var Ch	: Char
Var Done	: Boolean = False
Var I		: Integer = 0
Begin
	While Not Done Do Begin
		TitleBar('Fleet Menu')
		FleetList
		WriteLn('  |09(|14L|09) |10List Fleet Ships')
		WriteLn('  |09(|14V|09) |10View Ship Info')
		WriteLn('  |09(|14F|09) |10Transfer Flag')
		WriteLn('  |09(|14T|09) |10Transfer Goods')
		Write('|CR  |10Fleet Operations:|CR  Your Command, |11Captian '+Plyr.Alias+' : ')
		Ch:=OneKey('FLQTV',True)
		Case Ch Of
			'L': FleetList
			'Q': Done:=True
			'V': Begin 
				I:=SelectShip
				If I > 0 Then
					ShipMenu
				End
		End	
	End
End

Procedure Status
Var I	: Integer
Var S	: String
Begin
	ReadPlan(Plyr.HomePlan)
	S:=WriteLOC(Plan.LocZ,Plan.LocX,Plan.LocY)
	TitleBar(Plyr.Alias+'''s Status Report')

	Write('|CR  |12Last On  : |11'+PadRt(DateStr(Plyr.LastOn,1),20,' '))
		WriteLn(' |12Home : |09(|11#'+Int2Str(Plan.Idx)+'|09) |11'+Plan.Name)

	Write('  |12Credits  : |11$'+PadRt(StrComma(Plyr.Credits),19,' '))
		WriteLn(' |12Loc  : |11'+S)

	Write('  |12Bank     : |11$'+PadRt(StrComma(Plyr.Bank),19,' '))
		WriteLn(' |12Fuel : |11'+Real2Str(Ship.Fuel/100,2))


	WriteLn('|CR  |11Fleet:')
	If ReadShip(Plyr.CurShip) Then Begin
		S:=WriteLOC(Ship.LocZ,Ship.LocX,Ship.LocY)
		Write  ('|CR  |12Name:|10'+Ship.Name)
		Write  ('   |12Type:|10'+Ship.Model)
		WriteLn('   |12Location:'+S+'|08')
		For I:=1 To 5 Do 
			Write  (PadLt(ShortNames[I],12,' '))
		Write(PadLt('Holds',12,' '))
		WriteLn('|07')
		For I:=1 To 5 Do 
			Write  (PadLt(StrComma(Ship.Goods[I]),12,''))
		Write  (PadLt(StrComma(Ship.Holds),12,' '))
	End

	WriteLn('')

	WriteLn('|CR|CR  |22|14'+PadCT('END REPORT',76,' ')+'|16')
	WriteLn('')
End

Function Orbiting:Integer
Var	X	: Integer
Var	Ret: Integer=0
Begin
	If Ship.LastSeen > 0 Then Begin
		If ReadPlan(Ship.LastSeen) Then Begin
			If Ship.LocX = Plan.LocX And Ship.LocY = Plan.LocY And Ship.LocZ = Plan.LocZ Then Begin
				Write('|CR  |02Location: Orbiting |10'+Plan.Name+' '+Int2Str(Ship.LocX)+'/'+Int2Str(Ship.LocY))
				Ret:=Ship.LastSeen
			End Else
				Write('|CR  |02Drifting: |10'+Int2Str(Ship.LocX)+'/'+Int2Str(Ship.LocY))	
		End
	End
	Orbiting:=Ret
End

Procedure GoToPlanet
Var X	: Integer
Var F,S	: Real
Begin
	Write('|02  Go to which planet? [|101-'+Int2Str(GNumPlans)+'|02]: ')
	X:=Str2Int(Input(3,3,11,''))
	If X >= 1 and X <=GNumPlans Then Begin
               If Not ReadPlan(X) Then 
			WriteLn('|CR  No such planet.|CR')
		Else Begin
			S:=FindDistance(X)			
			F:=S/10
			ReadPlan(X)
			WriteLn('|CR  |09'+Plan.Name+'|02 is |10'+Real2Str(S,2)+ '|02 Lightyears away')
			WriteLn('|02  and will consume |09'+Real2Str(F,2) + '|02 units of fuel')
			If InputYN('  |02Warp to |09'+Plan.Name+'|02?  : ') Then Begin
				If Ship.Fuel >= S Then Begin
					Ship.LocX:=Plan.LocX
					Ship.LocY:=Plan.LocY
					Ship.LocZ:=Plan.LocZ
//					Plyr.GName:=Plan.Name
					Ship.Fuel:=Ship.Fuel-F
					SaveShip(Ship.Idx)
				End Else Begin
					WriteLn('|CR*** You don''t have enough fuel for the trip ***')
					GamePause
				End
			End
		End
	End
End

Procedure MainMenuX
Begin
	WriteLn('|11  '+Program+'|CR')
	If Plyr.Idx = 1 Then 
		WriteLn('  |09(|14M|09) |11Map')
		WriteLn('  |09(|14C|09) |11Closest Planets')
		WriteLn('  |09(|14I|09) |11Planetary Info')
		WriteLn('  |09(|14F|09) |11Find Distance')
		WriteLn('  |09(|14W|09) |11Warp to Planet')
		WriteLn('  |09(|14L|09) |11List Planets')
		WriteLn('  |09(|14P|09) |11List Tycoons')
		WriteLn('  |09(|14S|09) |11Status')
		WriteLn('  |09(|14Q|09) |11Quit to the Real World')
End

Procedure SellIt(I,Pnum:Integer)
Var NewCost, Tot,Amt,Cost	: LongInt
Var OTries, MO	: Integer
VAr MA	: Char
Var MaxTries	: Integer = Random(3)+3
Var Done	: Boolean
Var B,Diff	: Real
Begin
	MO:=Ship.Goods[I]
	If ReadPlan(PNum) Then 
		Cost:=Plan.Rates[I]*GoodsBases[I]
	If Cost > 0 Then Begin 
		Diff:=Cost / 10
		Cost:=Diff * 7 
	End

	If MO < 1 Then Begin
		WriteLn('|CR  |10You consider selling some |13'+GoodsNames[I]+'|10, but remember you have none')
		WriteLn('  in your holds.  Better sell something else.')
		Exit
	End

	WriteLn('|CR  |10The man smiles, but informs you that he buys at 70% of retail.')
	WriteLn('  |10He offers to buy the |13'+GoodsNames[I]+' |10at |11$'+StrComma(Cost)+'|10 credits each.')

	B:=Cost/20
	OTries:=0
	Done:=False
	Repeat	
		Write('|CR  |01"|09Make |06[|11O|06]|09ffer, or |06[|11A|06]|09ccept Deal|01" |06[|11O,A|06] |11: ')
		MA:=OneKey('OAQ',True)
		If MA = 'Q' Then Begin
			WriteLn('|CR  |01"|09Alrighty-Then!|01"')
			Exit
		End

		If MA = 'O' Then Begin
			OTries:=OTries+1
			If OTries < MaxTries Then Begin
				Diff:=OTries*B
				NewCost:=(B*28)-Diff
				Write('|CR  |10You counter the offer with |15$'+Int2Str(NewCost)+' |10 credits each')
				If Random(100) < 85 Then Begin
					Diff:=OTries*B
					NewCost:=(B*20)+Diff
					WriteLn('|CR  |10He counters with $'+Int2Str(NewCost)+' credits each')
				End Else Begin
					WriteLn('|CR  |10He reluctantly accepts your offer.')
					Done:=True
				End
			End Else Begin
				WriteLn('|CR  |01"|09Come back when you really want to sell your wares.|01" |10the man scoffs.')
				WriteLn('  |10You may have over-played your hand.  Maybe you should try agian later.')
				exit
			End
		End 

		If MA = 'A' Then Begin
			If NewCost > 0 Then Cost:=NewCost
			Done:=True
		End
	Until Done

	Write('|CR  |01"|09How many units do you want to sell?|01" |11: ')
	Amt:=Str2Int(Input(10,10,1,Int2Str(MO)))

	If Amt > MO Then Begin
		WriteLn('|CR  |10You can''t sell more then you have!')
		Exit
	End	

	If Amt < 1 Then Begin
		WriteLn('|CR  |01"|09Your''re confusing me!  Come back when you know what you want!|01"')
		Exit
	End

	Tot:=Amt*Cost
	If InputYN('|CR  |02"|10Sell |11'+Int2Str(Amt)+' '+GoodsNames[I]+' |10for |15$'+Int2Str(Tot)+' |10credits?|02" |11: ') Then Begin
		Ship.Holds:=Ship.Holds+Amt
		Plyr.Credits:=Plyr.Credits+Tot
		Ship.Goods[I]:=Ship.Goods[I]-Amt
		SavePlyr(Plyr.Idx)
		SaveShip(Ship.Idx)
		WriteLn('|CR  |01"|09Done!  Have a good day!|01"')
	End Else Begin
		WriteLn('|CR  |01"|09Make up your mind!|01"')
	End
End

Procedure BuyIt(I,Pnum:Integer)
Var NewCost,Tot,Cost	: LongInt = 0
Var MA	: Char
Var OTries, Amt,HO	: Integer 
Var MaxTries	: Integer = Random(3)+3
Var Done	: Boolean
Var B, Diff	: Real
Begin

	If ReadPlan(PNum) Then 
		Cost:=Plan.Rates[I]*GoodsBases[I]

	If Cost < 1 Then Begin
		WriteLn('|CR  |10"|02Something isn''t quite right...|10"')
		Exit
	End

	HO:=EmptyHolds

	If HO < 1 Then Begin
		WriteLn('|CR  |11You consider buying some '+GoodsNames[I]+', but remember you have no')
		WriteLn('  place to put them.  Better sell something first.')
		Exit
	End

	B:=Cost/20

	OTries:=0
	Done:=False
	Repeat	
		Write('|CR  |02"|10Make |06[|11O|06]|10ffer, or |06[|11A|06]|10ccept Deal|02" [O,A] |11: ')
		MA:=OneKey('OAQ',True)
		If MA = 'Q' Then Begin
			WriteLn('|CR  |06"|14Alrighty-Then!|06"')
			Exit
		End

		If MA = 'O' Then Begin
			OTries:=OTries+1
			If Not Done And OTries < MaxTries Then Begin
				Diff:=OTries*B
				NewCost:=(B*15)+Diff
				Write('|CR  |10You counter the offer with |15$'+Int2Str(NewCost)+' |10credits each')
				If Random(100) < 85 Then Begin
					Diff:=OTries*B
					NewCost:=(B*17)+Diff
					WriteLn('|CR  |10He counters with |15$'+Int2Str(NewCost)+'|10 credits each')
				End Else Begin
					WriteLn('|CR  |10He reluctantly accepts your offer.')
					Done:=True
				End
			End Else Begin
				WriteLn('|CR  |02"|10Come back when you really want to buy something.|02" the man sneers at you.')
				WriteLn('  |10You may have over-played your hand.  Maybe you should try agian later.')
				exit
			End
		End 

		If MA = 'A' Then Begin
			If NewCost > 0 Then Cost:=NewCost
			Done:=True
		End
	Until Done

	Write('|CR  |02"|10How many units do you want?|02" |11: ')
	Amt:=Str2Int(Input(10,10,1,Int2Str(HO)))
	
	If Amt > HO Then Begin
		WriteLn('|CR  You''d have to leave '+Int2Str(HO-Amt)+' units on the dock!')
		Exit
	End	

	If Amt < 1 Then Begin
		WriteLn('|CR  |02"|10Your''re confusing me!  Come back when you know what you want!|10"')
		Exit
	End

	Tot:=Amt*Cost
	If InputYN('|CR  |02"|10Buy |11'+Int2Str(Amt)+' '+GoodsNames[I]+' |10for |15$'+Int2Str(Tot)+' |10credits?|02" |11: ') Then Begin
		Ship.Holds:=Ship.Holds-Amt
		Plyr.Credits:=Plyr.Credits-Tot
		Ship.Goods[I]:=Ship.Goods[I]+Amt
		SavePlyr(Plyr.Idx)
		SaveShip(Ship.Idx)
		WriteLn('|CR  |10"|02Done!  Have a good day!|10"')
	End Else Begin
		WriteLn('|CR  |10"|02Make up your mind!|10"')
	End

	 
End

Procedure DoTrade(Pnum:Integer;C:Char)
Var J,I	: Integer
Var BS	: Char
Begin
	ReadPlan(Pnum)
	I:=Ord(C)-64
	J:=GoodsBases[I]*Plan.Rates[I]
	WriteLn('|CR  |10The man behind the counter smiles and welcomes you...')

	WriteLn('|CR  |02"|10We have |13'+GoodsNames[I]+' |10for |11$'+Int2Str(J)+' |10Credits each|02"')
	Write('|CR  |02"|10Are you |14[|06B|14]|10uying or |14[|06S|14]|10elling?|02" |11[|02B,S, Q=Quit|11] : ')

	BS:=OneKey('BSQ',True)
	Case BS Of
		'Q': Begin
				WriteLn('|CR  "Allrighty-Then!"|CR')
			End
		'B': Begin
				BuyIt(I,PNum)
			End
		'S': Begin
				SellIt(I,Pnum)
			End
	End
End

Procedure TradeMenu(Pnum : Integer)
Var Chx	: Char
Var I		: Integer
Var Keys	: String
Begin
	Keys:='1ABCDEQ'
	If Pnum < 1 Then Begin
		WriteLn('|CR  |12You are not orbiting any planet...|CR')
		Exit
	End
	ReadPlan(Pnum)
	WriteLn('|09%%%%% |14Available Goods |09%%%%%|CR')
	WriteLn('  |13Trading at |14'+Plan.Name)
	WriteLn('|CR')
	WriteLn('      Product              :       Cost         Your Inventory|CR')
	For I:=1 To 5 Do Begin
		Write('  |09(|11'+Chr(I+64)+'|09) |14'+PadRt(GoodsNames[I],20,' ')+' |12: |15')
		Write(PadLt('$'+StrComma(GoodsBases[I]*Plan.Rates[I]),10,' '))
		WriteLn(PadLt(StrComma(Ship.Goods[I]),15,' '))
	End

	If Plan.Class = 1 Then Begin
		WriteLn('|CR  |09(|111|09)|11 Buy or Sell a ship')
		Keys:=Keys+'1'
	End

	Write('|CR  |02Your Command, |10'+Plyr.Alias+'|02? (?=Menu) : ')
	Chx:=OneKey(Keys,True)
	Case Chx Of
		'A','B','C','D','E': DoTrade(PNum,Chx)
		'1': BuySellShip
	End
End

Procedure AddCredits
Begin
	If Plyr.Idx = 1 Then Begin
		Plyr.Credits:=Plyr.Credits+1000
		SavePlyr(Plyr.Idx)
	End
End

Include gtcorp.inc

Procedure MainMenu
Var Keys	: String
Var D		: Integer
Var Ch	: Char
Begin
	Keys:='ACDFGHIWLMNOPQSVT?+-'
	While True Do Begin
		If Plyr.Idx = 1 Then Begin
			Keys:=Keys+'#'
		End
		WriteLn('')
		D:=Orbiting
		WriteLn('|CR  |02Current Sector: '+Sector2XY(CurrentSector))
		Write('  |02Your Command, |10'+Plyr.Alias+'|02? (?=Menu) : ')
		Ch:=OneKey(Keys,True)
		Case Ch Of
			'+': AddCredits
			'-': ShowAllAlliances
			'?': MainMenuX
			'O': ListClosestPlanets(5)	
			'C': CorporateMenu
			'F': FleetMenu 
			'G': GalaxyMap
			'H': ShipMenu
			'I': SelectPlanet(D)
			'L': ListPlanets	
			'M': Map	
			'N': PlanInfo(D)
			'P': ListPlayers
			'Q': Q2BBS
			'T': TradeMenu(D)
			'S': Status	
			'W': GoToPlanet
		End
	End
End

Begin
	MenuCmd('NA','Galactic Tycoon')
	GetThisUser
	Init
	LoadFiles
	Intro
	EnterGame
	MainMenu
End