/*    STAR EMPIRE by  GameMaster  Version 1.0  (20-Oct-1994) */

options results; signal on syntax; signal on halt; signal on error
bufferflush

path = 'pfiles:Uni/'
path1 = 'pfiles:Uni/Players/'
path2 = 'pfiles:Uni/Sectors/'
path3 = 'pfiles:Uni/Planets/'
path4 = 'pfiles:Uni/Systems/'
path5 = 'pfiles:UNI/Mail/'
path6 = 'pfiles:UNI/NPC/'
path7 = 'pfiles:UNI/RADIO/'
getuser 1; handle = result
getuser 12; date = result
getuser 15; ac = result
date = left(date,16)
t = transmit
s = sendstring
filename = handle
scan = 0; nft = 0; nya = 0; ncr = 0; nfi = 0

/*NEW USER SIGNUP*/
if ~exists(path1||filename) then do
	call NEWUSER
t "stops here"
end

/*LOAD IN USER*/
signal off error
call open(userfile,path1||filename,'R')
gamer = readln(userfile)
money = readln(userfile)
bank = readln(userfile)
ship = readln(userfile)
swp = readln(userfile)
shld = readln(userfile)
tech = readln(userfile)
agri = readln(userfile)
eqip = readln(userfile)
guns = readln(userfile)
slave = readln(userfile)
torp = readln(userfile)
fght = readln(userfile)
crus = readln(userfile)
tran = readln(userfile)
area = readln(userfile)
col = readln(userfile)
gate = readln(userfile)
trp = readln(userfile)
ltime = readln(userfile)
end = readln(userfile)
wpn = readln(userfile)
call close(userfile)
call START

NEWUSER:
t "Ah ha - a new user for the Imperial fodder beds!"
gamer = handle
money = 10000
bank = 0
area = MoonBase
ship = 1
swp = 1
shld = 1
Tech = 0
Agri = 0
Eqip = 0
Guns = 0
Slave = 0
torp = 0
fght = 0
crus = 0
Tran = 0
col = 0
gate = 0
trp = 0
wpn = 1
end = 25
call open(file,(path1''filename) ,'W')
call writeln(file,gamer)
call writeln(file,money)
call writeln(file,bank)
call writeln(file,ship)
call writeln(file,swp)
call writeln(file,shld)
call writeln(file,tech)
call writeln(file,agri)
call writeln(file,eqip)
call writeln(file,guns)
call writeln(file,slave)
call writeln(file,torp)
call writeln(file,fght)
call writeln(file,crus)
call writeln(file,tran)
call writeln(file,area)
call writeln(file,col)
call writeln(file,gate)
call writeln(file,trp)
call writeln(file,date)
call writeln(file,end)
call writeln(file,wpn)
call close(file)
t 'n2}Writing Characterw1}'
call open(file,(path''gamers), 'A')
	call writeln(file,handle)
	call close file
msg = 0
call open(file,(path5''handle),'W')
call writeln(file,msg)
call close(file)
gal = gamer' has lifted off from Earth!'
nm = 0
t 'n1}Writing to Userlist ...w1}'
call open(file,(path5''handle), 'W')
call writeln(file,nm)
 call close file
t 'n1}Updating Galactic News Service ...w1}'
call open(file,(path''news), 'A')
call writeln(file,gal)
call close file
loc = 0
sendfile 'pfiles:UNI/DOX/START'
call WHERE1

START:
sendfile 'pfiles:UNI/DOX/INTRO'
call open(msgfile,path5||handle, 'R')
mc = readln(msgfile)
call close(msgfile)
area = upper(area)
if area = 'BASE0' then do; call WHERE1; end
if area = 'MOONBASE' then do; call WHERE1; end
if area = 'ALPHA1' then do; call WHERE1; end
if area = 'DELTA1' then do; call WHERE1; end
if area = 'GAMMA1' then do; call WHERE1; end
if area = 'OMEGA1' then do; call WHERE1; end
call WHERE

BASE1:
t 'f1} You have entered 'bnam
t 'n1}c1} MARKETPLACE ------------- STATION ADMIN --------------- OTHER STUFF'    
t 'n1}c3}z4} B z0} Stellar Stores	z4} P z0} Stellar Postal Service	z4} Q z0} Quit Game'
t 'z4} S z0} Trading Post	z4} I z0} Data Terminal		z4} X z0} Leave Station'
s 'n2}c6}Option: '; getchar; ans = upper(result)
if ans = 'Q' then do; call BYE; end
if ans = 'X' then do; call SHIP; end
if ans = 'B' then do; call STORE; end
if ans = 'S' then do; call MARKET; end
if ans = 'I' then do; call DATA; end
if ans = 'P' then do; call COMM; end
t 'That command is not currently active!w1}'
call BASE1
end

COMM:
call open(msgfile,path5||handle, 'R')
mr= readln(msgfile)
call close(msgfile)
t 'f1}c3}STELLAR POSTAL SERVICE                   Active Messages: c7}'mr
t 'n1}c2}     The friendly Stellar Postal Droid approaches, n1}        c7}> What can I do for you today, sir? <'
t 'n1}c6} z1}<A>z0}  Send Mail   z1}<B>z0} Read Your Mail   z1}<Q>z0} Return to Corridor'
query 'n1}c1}Option: c7}'; ans = upper(result)
if ans = 'A' then do; call COMM1; end
if ans = 'Q' then do; call BASE1; end
if ans = 'B' then do; call COMA; end
t 'Not yet active!w1}'
call COMM
end

COMA:
if ~exists(path5||handle) then do
	 t 'n2}c2}No messages waiting!w1}'; call COMM; end
call open(msgfile,path5||handle, 'R')
mss = readln(msgfile)
call close(msgfile)
if mss = 0 then do;  t 'n2}c2}No messages waiting!w1}'; call COMM; end
t 'n1}c5}You have c7}'mss'c5} messages waiting!w1}'
s 'n1}c6}Do you wish to read your messages now? '; getchar; ans = upper(result)
if ans = 'N' then do; call COMM; end
mg = 1
yml = handle'.msg'mg
call READ

READ:
t 'f1}n1}c6}z1} Stellar Postal Service z0}c6}n2}Message #'mg' (c7}of 'mr'c6})'
t 'c7}-----------------------------------------------------------------------------c2}'
sendfile 'pfiles:UNI/Mail/'yml
t 'c7}-----------------------------------------------------------------------------c2}'
query '  c5}z7}<A>z0} Answer   z7}<B>z0} ReRead   z7}<N>z0} Next (Deletes Message)   z7}<Q>z0} Exit Comm Menu  n2}Option: '; ans = upper(result)
	if ans = 'A' then do; call COMM1; end
	if ans = 'B' then do; call READ; end
	if ans = '' then do; call READ; end
	if ans = 'Q' then do; call COMM; end
	if ans = 'N' then do; its = 'pfiles:UNI/Mail/'yml
		s 'Clearing Message c0}#4c:delete 'its'}c6}'
			if mr > mg then do; mg = mg + 1; yml = handle'.msg'mg; call read; end 
		mss = 0; mc = 0; mr = 0
		call open(file,(path5''handle) ,'W')
		call writeln(file,mss)
		call close(file)
		call COMM; end
call COMM

COMM1:
query 'n1}   Enter Player Name: '; nam = upper(result)
if nam = upper(gamer) then do; t 'n1}   You may not mail yourself!w1}'; call COMM; end
if nam = '' then call base1
if ~exists(path5||nam) then do; call NEWCOMM1; end
call open(msgfile,path5||nam,'R')
mss = readln(msgfile)
call close(msgfile)
call COMM2

COMM2:
mg = mss + 1
filename = nam'.msg'mg
CLEAREDITOR
LOADEDITOR 'pfiles:UNI/Mail/'filename
CALLEDITOR 25
SAVEEDITOR 'pfiles:UNI/Mail/'filename
add = 'n1}                                              c3}'handle
dt = '                                              c6}'date
call open(file,(path5||filename),'A')
call writeln(file,add)
call writeln(file,dt)
call close(file)
call open(msgfile,path5||nam,'W')
call writeln(msgfile,mg)
call close(msgfile)
call COMM
end

NEWCOMM1:
mss = 0
call open(file,(path7''nam) ,'W')
call writeln(file,mss)
call close(file)
call COMM1
end

MARKET:
t 'f1} z2}c4} TRADE MARKET z0}'
t 'n1}z5}c7}[B]z0}  cc}Bulletin Boards c7}:  c6}Odd Jobs and Products'
t 'z5}c7}[A]z0}  cc}Available Cargo c7}:  c6}Current Prices and Availability'
t 'z5}c7}[Q]z0}  cc}Exit to Foyer   c7}:  c6}Back to the Passageways'
s 'n1}c2}Select (Q-Exit): '; getchar; ans = upper(result)
if ans = 'A' then do; call CARGO; end
if ans = 'B' then do; t 'Not currently Active!w1}'; call MARKET; end
if ans = 'Q' then do; call BASE1; end
call BASE1

CARGO:
hlds = ship * 10
t 'f1}c5}CARGO DEALERS:c7}   Price                     Ship     Holds     In Use'
t 'n1}c6}A -  Agricultural: 'cagr'                  c1}Agriculture:  c7}'hlds'         'agri  
t 'c6}B -  Technical:    'ctch'                  c1}Technical:    c7}'hlds'         'tech
t 'c6}C -  Equipment:    'cequ'                  c1}Equipment:    c7}'hlds'         'eqip
t '                                       c3}Credits:       c7}'money
s 'n1}c2}Which (Q=Exit): '; getchar; ans = upper(result)
if ans = 'Q' then do; call MARKET; end
if ans = 'A' then do; call BUYA; end
if ans = 'B' then do; call BUYB; end
if ans = 'C' then do; call BUYC; end
call CARGO

BUYA:
s 'n1}(B)uy or (S}ell Agricultural Products? '; getchar; ans = upper(result)
max = ship * 10
if ans = 'S' then do; call SELA; end
if agri > max - 1 then do; t 'No Space in Holds!w2}'; call CARGO; end
if agri < max then mxm = max - agri; t' You may purchase 'mxm
query 'How Many: '; ans = upper(result)
if ans > mxm then do; t 'Too many!w2}'; call CARGO; end
cst = ans * cagr
if money > cst then do; money = money - cst; agri = agri + ans; call CARGO; end
if money < cst then do; t 'Not enough credit!w2}'; end
call CARGO

SELA:
t 'n1}You have 'agri' agricultural products available for sale.'
query 'n1}Sell how many: '; ans = upper(result)
if ans = 0 then do; call CARGO; end
if ans > agri then do; 'You do not have that many!w1}'; call CARGO; end
cst = ans * cagr;
if cst > money then do; t 'n1}Not enough credits ...w1}'; call CARGO; end
money = money + cst; agri = agri - ans
t 'n1}That sale made 'cst'cr. for youw2}'
call CARGO
end

BUYB:
s 'n1}(B)uy or (S}ell Technical Products? '; getchar; ans = upper(result)
max = ship * 10
if ans = 'S' then do; call SELB; end
if tech = max then do; t 'No Room in Holds!w2}'; call CARGO; end
if tech < max then mxm = max - tech; t ' You may purchase 'mxm
query 'How Many: '; ans = upper(result)
if ans > mxm then do; t 'n1}Not enough space in holds!w1}'; call CARGO; end
cst = ans * ctch
if money > cst then do; money = money - cst; tech = tech + ans; call CARGO; end
if money < cst then do; t 'Not enough credit!w2}'; call CARGO; end
call CARGO

SELB:
t 'n1}You have 'tech' technical products available for sale.'
query 'n1}Sell how many: '; ans = upper(result)
if ans = 0 then do; call CARGO; end
if ans > tech then do; 'You do not have that many!w1}'; call CARGO; end
cst = ans * ctch
if cst > money then do; t 'n1}Not enough credits ...w1}'; call CARGO; end
money = money + cst; tech = tech - ans
t 'n1}That sale made 'cst'cr. for youw2}'
call CARGO
end

BUYC:
s 'n1}(B)uy or (S}ell Equipment Products? '; getchar; ans = upper(result)
max = ship * 10
if ans = 'S' then do; call SELC; end
if eqip = max then do; t 'No Space in Hold!w2}'; call CARGO; end
if eqip < max then mxm = max - eqip; t' You may purchase 'mxm3
query 'How Many: '; ans = upper(result)
if ans > mxm then do; t 'n1}Not enough space in holds!w1}'; call CARGO; end
cst = ans * cequ
if money > cst then do; money = money - cst; eqip = eqip + ans; call CARGO; end
if money < cst then do; t 'Not enough credit!w2}'; call CARGO; end
call CARGO

SELC:
t 'n1}You have 'eqip' raw products available for sale.'
query 'n1}Sell how many: '; ans = upper(result)
if ans = 0 then do; call CARGO; end
if ans > eqip then do; 'You do not have that many!w1}'; call CARGO; end
cst = ans * cequ
if cst > money then do; t 'n1}Not enough credits ...w1}'; call CARGO; end
money = money + cst; eqip = eqip - ans
t 'n1}That sale made 'cst'cr. for youw2}'
call CARGO
end

DATA:
t 'f1}z7} c4}INFORMATION TERMINAL z0}n1}'
t 'z2}<Y>z0}  Your Statistics'
t 'z2}<Q>z0}  Quit to Main'
t 'z2}<L>z0}  Current Roster'
t 'z2}<N>z0}  Galactic News Service'
s 'n1}Select: '; getchar; ans = upper(result)
if ans = 'Y' then do; call STATS; end
if ans = 'L' then do; call LIST; end
if ans = 'Q' then do; call BASE1; end
if ans = 'N' then do; call NEWS; end
if ans = 'M' then do; call MAIL; end
call data

MAIL:

NEWS:
t 'f1}G A L A C T I C   N E W S   S E R V I C E'
sendfile 'pfiles:Uni/news'
s 'n1}Press A Key ...g1}'
call DATA
end

LIST:
t 'n2}'
call open(file,(path'gamers'), 'R')
i = 0
do until EOF (file) = 1
	i = i + 1
	player = readln(file)
	if player = '' then do
	s 'n2}c1}Press A Key ...g1}'
	call close(file)
	call DATA
	end
t 'c7}'i'. c3}'player
end
s 'n2}c2}Press A Key ...g1}'
call close file
call DATA

STATS:
t 'f1}c4}Statistics for c3}'gamer
t 'n1}c1}Cash: c7}'money
t 'c1}Ship:'
t '    c6}Level:  c7}'ship
t '    c6}Weapon: c7}'swp
t '    c6}Shield: c7}'shld
t '    c6}Torps:  c7}'torp
t 'c1}Holds:'
t '    c6}Tech: c7}'tech
t '    c6}Agri: c7}'agri
t '    c6}Eqip: c7}'eqip
if guns > 0 then t '    c6}Guns: c7}'guns
if slave > 0 then t '    c6}Slav: c7}'slave
t 'c1}Colonists: c7}'col
t 'c1}StarGates: c7}'gate
s 'n1}Press A Key g1}'
call DATA

STORE:
t 'f1}z4}c3} STELLAR STORES z0}'
t 'n1}z7}c4}<A>z0}  c5}Svengali Starships c7}  :c3}  Need a new starship?  Fighters available!'
t 'z7}c4}<B>z0}  c5}Quadaffi Outfittersc7}  :  c3}For all your weaponry & combat needs.'
t 'z7}c4}<C>z0}  c5}Colonial Warehouse c7}  :  c3}Need colonists? How about some infantry?'
t 'z7}c4}<Q>z0}  c5}Enter Main Concoursec7} :  c3}Return to the crowded passageways.'
s 'n1}Enter a Shop? '; getchar; ans = upper(result)
if ans = 'Q' then do; call BASE1; end
if ans = 'B' then do; call QUAD; end
if ans = 'A' then do; call VESSEL; end
if ans = 'C' then do; call SCUM; end
call store
end

QUAD:
if swp = 1 then wpn = '1mw Mining Lazer'
if swp = 2 then wpn = '10mw Pulse Lazer'
if swp = 3 then wpn = '50mw Beam Lazer'
if swp = 4 then wpn = 'Plasma Gun'
t 'f1}c1}Q U A D A F F I   O U T F I T T E R S'
t 'n1}z7}c5} A z0}  Ship Weaponry            c3}Current: c7}'wpn
t 'z7}c5} B z0}  Ship Shields             c3}Current: c7}'shld' shields'
t 'n1}z7}c5} Q z0}  Quit to Mall'
query 'n1}z3}c4} cash: 'money'c7}cr.c6}z0} Select: c7}'; ans = upper(result)
if ans = 'Q' then do; call STORE; end
if ans = 'A' then do; call WEAPONS; end
if ans = 'B' then do; call SHLDS; end
call QUAD

SHLDS:
t 'n3}Shields cost 100cr each.'
query 'Purchase how many: '; ans = upper(result)
if ans = 0 then do; call QUAD; end
if ans < 1 then do; t 'n1}You may not sell shields!w1}'; call QUAD; end
cst = ans * 100
if cst > money then do; t 'Not enough credit!'; call QUAD; end
money = money - cst; shld = shld + ans
t 'n1}Your Ship is now equipped with 'shld' shields.w2}'
call QUAD

WEAPONS:
t 'f1}c7}z4}Currently Available:cc}'
t 'n1}z7} A z0}  10mw Pulse Lazer	c3}250crcc}'
t 'z7} B z0}  50mw Beam Lazer	c3}600crcc}'
t 'z7} C z0}  Plasma Gun		c3}1500crcc}'
t 'z7} D z0}  Photon Torps	c3}150crcc}'
t 'z7} E z0}  Quark Torps	c3}2000crcc}'
s 'n1}z4}cb} Cash: 'money'cr. c1}--> c2}Selection:z0} c7}'; getchar; ans = upper(result)
if ans = 'Q' then call QUAD
if ans = 'A' then do; wpn = '10mw Pulse Lazer'; cst = 250; sp = 2; call AWEP; end
if ans = 'B' then do; wpn = '50mw Beam Lazer'; cst = 600; sp = 3; call AWEP; end
if ans = 'C' then do; wpn = 'Plasma Gun'; cst = 1500; sp = 4; call AWEP; end
t 'n2}This Option has not yet been activated!'
t 'Press A Key to continue ...g1}'
call WEAPONS

AWEP:
query 'You wish to purchase a 'wpn' (Y/N)? '; ans = upper(result)
if ans = 'N' then do; call WEAPONS; end
if cst > money then do; t 'Not enough credits!'; call QUAD; end
money = money - cst; swp = sp; t 'Sold!	w2}'; call QUAD
call quad

BWEP:
cst = 150
if cst > money then do; t 'Not enough credits!'; call QUAD; end
money = money - cst; torp = 5; trp = trp + 1; t 'Sold!	w2}'; call QUAD
call quad

EWEP:
cst = 2000
if cst > money then do; t 'Not enough credits!'; call QUAD; end
money = money - cst; torp = 6; trp = trp + 1; t 'Sold!	w2}'; call QUAD
call quad

VESSEL:
t 'f1} z3}c0} SVENGALI STARSHIPS z0}n1}'
t 'z7}c4}[A]z0} c6}Private Starcraft c7}: c2}Upgrade your starcraft with quality used ships!'
t 'z7}c4}[B]z0} c6}Combat Vessels    c7}: c2}Fighters & Cruisers for your protection!'
t 'z7}c4}[Q]z0} c6}Exit This Store   c7}: c2}Return to Concourse Foyer.' 
s 'n1}Select: '; getchar; ans = upper(result)
if ans = 'A' then do; call PRVT; end
if ans = 'B' then do; call WAR; end
if ans = 'Q' then do; call STORE; end
call VESSEL
end

PRVT:
t 'f1}cc}PRIVATE STARSHIPS FOR SALE'
t 'n1} z3}c4} V z0}  View Ships				c5}1: c6}Star Carrier    c7}100,000 cr.'
t ' z3}c4} B z0}  Buy Ship 					c5}2: c6}Galaxy Carrier  c7}200,000 cr.'
t ' z3}c4} C z0}  Check Value of Current Ship'
t ' z3}c4} Q z0}  Exit to Concourse'
s 'n1}Select: '; getchar; ans = upper(result)
if ans = 'V' then call VIEW
if ans = 'B' then call PBUY
if ans = 'Q' then call VESSEL
call PRVT

PBUY:
s 'Which Ship do You Wish to Purchase; '; getchar; ans = upper(result)
if ans > 2 then do; t 'Nice try ...w1}'; call PRVT; end
if ans < 1 then do; t 'No Way ...w1}'; call PRVT; end  
cost = 100000 * ans
if cost > money then do; t 'n2}Not enough funds!w1}'; call PRVT; end
money = money - cost; ship = ans
t 'You now own a new starship!w2}'
call PRVT
end

VIEW:
s 'n1}Enter Ship Number: '; getchar; ans = upper(result)
if ans < 3 then do
	  sendfile 'pfiles:Uni/dox/ship.'ans; s 'n2} Press a Key g1}'; Call PRVT; end
s 'n1}There is no ship listed for that number.' 
call PRVT

WAR:
t 'f1}Currently Available Warshipsn1}'
t 'z6}c1} A z0}  Fighter:	c7}200cr'
t 'z6}c1} B z0}  Cruiser:	c7}800cr'
t 'z6}c1} C z0}  Transport:	c7}100cr'
t 'n1}z6}c1} Q z0}  Exit Store'
s 'n1}z3}c4} Cash: 'money'cr z0}cb} Purchase: '; getchar; ans = upper(result)
if ans = 'A' then do; call FIGHT; end
if ans = 'B' then do; call CRUIS; end
if ans = 'C' then do; call TRANS; end
if ans = 'Q' then do; call VESSEL; end
call WAR
end

TRANS:
query 'n1}Transports cost 100cr. Purchase how many? '; ans = upper(result)
if ans = '' then call WAR
cost = ans * 100
if cost > money then do; t 'n2}Not enough funds!w1}'; call WAR; end
money = money - cost; tran = tran + ans
t 'You now own 'tran 'transports.w2}'
call WAR
end

CRUIS:
query 'n1}Cruisers cost 800cr. Purchase how many? '; ans = upper(result)
if ans = '' then call WAR
cost = ans * 800
if cost > money then do; t 'n2}Not enough funds!w1}'; call WAR; end
money = money - cost; crus = crus + ans
t 'You now own 'crus 'cruisers.w2}'
call WAR
end

FIGHT:
query 'n1}Fighters cost 200cr. Purchase how many? '; ans = upper(result)
if ans = '' then call WAR
cost = ans * 200
if cost > money then do; t 'n2}Not enough funds!w1}'; call WAR; end
money = money - cost; fght = fght + ans
t 'You now own 'fght 'fighters.w2}'
call WAR
end

SCUM:
t 'f1}Colonial Warehouse:n1}'
t 'z1}c6}[A]z0}  Hire Colonists'
if slave > 0 then do; t 'z1}c6}[B]z0}  Sell Slaves'; end 
t 'z1}c6}[Q]z0}  Quit to Mall'
query 'n1}c2}Select: '; ans = upper(result)
if ans = 'Q' then do; call STORE; end
if ans = 'B' then do; t 'n2}Currently not active.w1}'; call Scum; end
if ans = 'A' then do; call SCUM1; end
call scum

SCUM1:
t 'n2}   You may hold up to 1000 colonists in the Stasis Chamber.'
t 'Qn1}   Currently you have 'col' colonists in Stasis.'
s 'n1}Do you wish to hire colonists? (N/Y) '; getchar; ans = upper(result)
if ans = 'N' then call STORE
query 'n1}Add how many at 2cr each: '; ans = upper(result)
cost = ans * 2
if cost > money then do; t 'n2}Not enough funds!w1}'; call SCUM; end
t 'n1}That will cost you 'cost'cr.w1}'; money = money - cost
col = col + ans
call STORE
end 

SHIP:
area = loc
if area = 100 then do; t 'n2}BEACON:  You are entering the Cephalid Empire. Travel at your own risk.'; end 
call WHERE
end

SHIPX:
xr = random(1,15)
if xr = 2 then do
	if nft > 0 then do; xr = 0; return; end
 	xr = 'An unidentified ship has entered Sensor Range.'; nft = nft + 1; return; end
if xr = 3 then do
	if nft = 0 then do; xr = 0; return; end
	 if nft > 0 then xr = 'A ship has left sensor range.'; nft = nft - 1
	 sck = 0; return; end
if xr = 5 then do
	if nft > 0 then do; xr = 0; return; end
	xr = 'An unidentified ship has entered Sensor Range.'; nft = nft + 1; return; end
if xr = 6 then do
	if nft = 0 then do; xr = 0; return; end
	 if nft > 0 then xr = 'A ship has left sensor range.'; nft = nft - 1
	 sck = 0; return; end
if xr = 7 then do
	if nft > 0 then do; xr = 0; return; end
	xr = 'An unidentified ship has entered Sensor Range.'; nft = nft + 1; return; end
if xr = 8 then do
	if nft > 0 then do; xr = 0; return; end
	xr = 'An unidentified ship has entered Sensor Range.'; nft = nft + 1; return; end
if xr = 9 then do
	if nft = 0 then do; xr = 0; return; end
	if nft > 0 then xr = 'A ship has left sensor range.'; nft = nft - 1
	sck = 0; return; end
xr = 0
return

SHIPA:
call SYSTEM

SHIP1:
call open(msgfile,path7||handle, 'R')
mr= readln(msgfile)
call close(msgfile)
if mr > 0 then do; t 'f1}n1}c3}               . . . Incoming Radio Transmission!w1}'
	mg = 1
	yml = handle'.msg'mg
	call RREAD
	end
t 'f1}c1}MAIN BRIDGE                  SECTOR: c7}'area'n1}'
t '  z7}c4} Sector 'area' Star Systems z0}'
t '  --------------------------c6}'
if S1 = 0 then do;
	t 'n1}None on Record'; end
if S1 > 0 then do;
	t '    'S1; end
if S2 > 0 then do;
	t '   'S2; end
if S3 > 0 then do;
	t '   'S3; end
t 'c4}  --------------------------'
t '  z4}c3} M z0}  Gateway Movement'
t '  z4} N z0}  System Movement'
t '  z4} I z0}  Sector Movement'
t '  z4} D z0}  Computer/DataBase'
t '  z4} S z0}  Sensor Scan'
t '  z4} Q z0}  Exit Star Empire'
t '  z4} R z0}  Send Radio Transmissionn1}c6}'
call SHIPX
if xr > 0 then t 'c7}Sensor Alert: c6}'xr
query 'n1}  c4}z2} Linked Sectors: 'next' z0}n1}  c2}Option c7}> '; ans = upper(result)
if ans = 'I' then do; nft = 0; nya = 0; ncr = 0; nfi = 0; call MOVE; end 
if ans = 'Q' then do; call BYE; end
if ans = 'R' then do; call RCOMM1; end
if ans = 'S' then do; call SENS; end
if ans = 'N' then do; call INSYS; end
if ans = 'M' then do; t 'Not Yet Active!w2}'; call SHIP1; end
if ans = 'D' then do; call DBASE; end
if ans = 'C' then do; ftrs = 0; crui = 0; mthr = 0; call ENCNT; end
t 'n1}c3}  That Command is not Active!w1}'
call ship1

SENS:
if nft > 0 then call SENS1
t 'n1}Nothing noted within sensor range.w1}'
call SHIP1

SENS1:
call SENS2
t 'n1}Sensor Report: 'eft' 'eshn'   Wpn Level: 'ewep'   Shields: 'eshd
s 'n1}A - Attack   I - Ignore > '; getchar; ans = upper(result)
if ans = 'I' then call SHIP1
if ans = 'A' then call BOUNTY1
call ship1

SENS2:
if sck = 1 then return
getuser 7; ans = result
x = right(ans,1)
if nft = 1 then rnd = random(1,9,x)
if rnd = 1 then do; eft = 'Corellian';eshn = 'Freighter'; eshp = 0; eshd = 1; ewep = 1; eagr = 10; eraw = 5; etch = 5; scn = 1
gsh = shld * 10; bsh = eshd * 10; rwd = 0; enemy = 'The 'eshn; sck = 1; end
if rnd = 2 then do; eft = 'Yneshan';eshn = 'Freighter'; eshp = 1; eshd = 3; ewep = 2; eagr = 15; eraw = 0; etch = 10; scn = 1
gsh = shld * 10; bsh = eshd * 10; rwd = 0; enemy = 'The 'eshn; sch = 1; end
if rnd = 3 then do; eft = 'Ferrengi';eshn = 'Freighter'; eshp = 1; eshd = 20; ewep = 3; eagr = 50; eraw = 10; etch = 100; scn = 1
gsh = shld * 10; bsh = eshd * 10; rwd = 500; enemy = 'The 'eshn; sck = 1; end
if rnd = 4 then do; eft = 'Private';eshn = 'Yacht'; eshp = 1; eshd = 20; ewep = 3; eagr = 50; eraw = 10; etch = 100; scn = 1
gsh = shld * 10; bsh = eshd * 10; rwd = 0; enemy = 'The 'eshn; sck = 1; end
if rnd = 5 then do; eft = 'Borellian';eshn = 'Cruiser'; eshp = 6; eshd = 500; ewep = 5; eagr = 25; eraw = 10; etch = 10; scn = 1
gsh = shld * 10; bsh = eshd * 10; rwd = 0; enemy = 'The 'eshn; sck = 1; end
if rnd = 6 then do; eft = 'Rigellan';eshn = 'StarCruiser'; eshp = 3; eshd = 20; ewep = 3; eagr = 50; eraw = 10; etch = 10; scn = 1
gsh = shld * 10; bsh = eshd * 10; rwd = 0; enemy = 'The 'eshn; sck = 1; end
if rnd = 7 then do; eft = 'Unknown';eshn = 'Freighter'; eshp = 3; eshd = 200; ewep = 2; eagr = 5; eraw = 10; etch = 100; scn = 1
gsh = shld * 10; bsh = eshd * 10; rwd = 1000; enemy = 'The 'eshn; sck = 1; end
if rnd = 8 then do; eft = 'Cardasian';eshn = 'Vulture'; eshp = 2; eshd = 100; ewep = 3; eagr = 50; eraw = 10; etch = 100; scn = 1
gsh = shld * 10; bsh = eshd * 10; rwd = 0; enemy = 'The 'eshn; sck = 1; end
if rnd = 9 then do; eft = 'Terran';eshn = 'Pleasure Ship'; eshp = 5; eshd = 1000; ewep = 1; eagr = 0; eraw = 0; etch = 0; scn = 1
gsh = shld * 10; bsh = eshd * 10; rwd = 0; enemy = 'The 'eshn; sck = 1; end
return

RREAD:
t 'f1}Radio Message:'
sendfile 'pfiles:UNI/Radio/'yml
query 'n1}c5} A  Answer n1} B  ReRead n1} Q  Exit (Deletes all Msgs)  n2}Option: '; ans = upper(result)
	if ans = 'A' then do; call RCOMM1; end
	if ans = 'B' then do; call RREAD; end
	if ans = '' then do; call RREAD; end
	if ans = 'Q' then do; its = 'pfiles:UNI/Radio/'yml
		t 'Transmission complete ... w1}'
		s 'Clearing Transmission c0}#4c:delete 'its'}c6}'
		mss = 0; mc = 0; mr =s 0
		call open(file,(path7''handle) ,'W')
		call writeln(file,mss)
		call close(file)
		call SHIP1; end
call SHIP1

RCOMM1:
query 'n1}   Enter Player Name: '; nam = upper(result)
if nam = '' then call ship1
if ~exists(path7||nam) then do; call NEWCOMM; end
call open(msgfile,path7||nam,'R')
mss = readln(msgfile)
call close(msgfile)
call RCOMM2

RCOMM2:
mg = mss + 1
filename = nam'.msg'mg
CLEAREDITOR
LOADEDITOR 'pfiles:UNI/Radio/'filename
CALLEDITOR 25
SAVEEDITOR 'pfiles:UNI/Radio/'filename
add = 'n1}                        'handle
call open(file,(path7||filename),'A')
call writeln(file,add)
call close(file)
call open(msgfile,path7||nam,'W')
call writeln(msgfile,mg)
call close(msgfile)
call SHIP1
end

NEWCOMM:
mss = 0
call open(file,(path7''nam) ,'W')
call writeln(file,mss)
call close(file)
call RCOMM1
end

DBASE:
t 'f1}c5}SHIP DATABASE:'
t 'n1}c1}<c7}Yc1}> c6}Your Statistics           c1}<c7}Qc1}> c6}Exit Program'
t 'c1}<c7}Lc1}> c6}Current Roster            c1}<c7}Ic1}> c6}FSP InfoBase'
t 'c1}<c7}Gc1}> c6}Galactic News Service'
query 'n1}c3}Option: '; ans = upper(result)
if ans = 'Y' then do; call DATA1; end
if ans = 'L' then do; call LIST1; end
if ans = 'Q' then do; call SHIP1; end
if ans = 'I' then do; call IBS; end
if ans = 'G' then do; call DNEWS; end
call DBASE

DNEWS:
t 'f1}G A L A C T I C   N E W S   S E R V I C E'
sendfile 'pfiles:Uni/news'
s 'n1}Press A Key ...g1}'
call DBASE
end

IBS:
t 'f1}INFORMATION DATABASE'
t 'n1}z7}c4} [P] FSP (NPC) Profiles z0}   z7} [S] FSP Star Systems z0}'
query 'n1}Option: '; ans = upper(result)
if ans = 'P' then do; call IBS1; end
if ans = 'S' then do; call IBS2; end
if ans = 'Q' then do; call DBASE; end
call IBS

IBS1:
query 'n2}Data Request > '; ans = upper(result)
flname = ans
if flname = '' then signal IBS1:
if ~exists(path6||flname) then do; t 'n2}No data file on 'ans' exists.w1}'; call IBS; end
	call open(file,path6||flname, 'R')
	aa = readln(file)
	ab = readln(file)
	ac = readln(file)
	ad = readln(file)
	ae = readln(file)
	af = readln(file)
	call close(file)
	call SBS1

IBS2:
query 'n2}Data Request > '; ans = upper(result)
flname = ans
if ~exists(path4||flname) then do; t 'n2}No data file on 'ans' exists.w1}'; call IBS; end
call open(file,path4||flname, 'R')
aa = readln(file)
ab = readln(file)
ac = readln(file)
ad = readln(file)
ae = readln(file)
af = readln(file)
call close(file)
call SBS2

SBS2:
t 'f1}c1}CURRENT DATA ON c7}'ans'		c1}Star Type: c7}'ad
t 'n1}c6}Number of Planets: c7}'aa'		c6}Hospitable   : c7}'ab
t 'c6}Planet Name      : c7}'ae' 	c6}Asteroid Belt: c7}'ac
t 'c6}Trading Post     : c7}'af
t 'cc}_________________________________________________________________________'
s 'n2}c5}Press A Key to Continue g1}'
call DBASE

SBS1:
t 'f1}c1}CURRENT DATA ON c7}'aa
t 'n1}c6}RACE: c7}'ab'     c6}AGE: c7}'ac'c6}     HOMEWORLD: c7}'ae
t 'n1}c6}CURRENT OCCUPATION: c7}'ad
t 'cc}_________________________________________________________________________'
t 'n1}c3}'af
s 'n2}c5}Press A Key to Continue g1}'
call DBASE

LIST1:
t 'n2}'
call open(file,(path'gamers'), 'R')
i = 0
do until EOF (file) = 1
	i = i + 1
	player = readln(file)
	if player = '' then do
	s 'n2}c1}Press A Key ...g1}'
	call close(file)
	call DBASE
	end
t 'c7}'i'. c3}'player
end
s 'n2}c2}Press A Key ...g1}'
call close file
call DBASE

DATA1:
t 'f1}c4}Statistics for c3}'gamer
t 'n1}c1}Cash: c7}'money
t 'c1}Ship:'
t '    c6}Level:  c7}'ship
t '    c6}Weapon: c7}'swp
t '    c6}Shield: c7}'shld
t '    c6}Torps:  c7}'torp
t 'c1}Holds:'
t '    c6}Tech: c7}'tech
t '    c6}Agri: c7}'agri
t '    c6}Eqip: c7}'eqip
if guns > 0 then t '    c6}Guns: c7}'guns
if slave > 0 then t '    c6}Slav: c7}'slave
t 'c1}Colonists: c7}'col
t 'c1}StarGates: c7}'gate
s 'n1}c5}Press A Key g1}'
call DBASE

INSYS:
t 'n1}'
if s1 > 0 then do; t '   c3}A - System: c7}'S1; end
if s2 > 0 then do; t '   c3}B - System: c7}'S2; end
if S3 > 0 then do; t '   c3}C - System: c7}'S3; end
s 'n1}Select System to Enter (Q-Exits): '; getchar; ans = upper(result)
if ans = 'A' then do; pnam = S1; system = S1
	call open(file,path4||system,'R')
	nplan = readln(file)
	nhosp = readln(file)
	ast = readln(file)
	type = readln(file)
	plnt = readln(file)
	post = readln(file)
	call close(file)
	call INSYS1; end
if ans = 'B' then do; pnam = S2; system = S2
	call open(file,path4||system,'R')
	nplan = readln(file)
	nhosp = readln(file)
	ast = readln(file)
	type = readln(file)
	plnt = readln(file)
	post = readln(file)
	call close(file)
	call INSYS1; end
if ans = 'C' then do; pnam = S3; system = S3
	call open(file,path4||system,'R')
	nplan = readln(file)
	nhosp = readln(file)
	ast = readln(file)
	type = readln(file)
	plnt = readln(file)
	post = readln(file)
	call close(file)
	call INSYS1; end
if ans = 'Q' then do; call SHIP1; end
t 'n2}You must select a current system!w1}'
call INSYS

INSYS1:
if pnam = 0 then do; t 'n2}No System Selected!w1}'; call SHIP1; end
t 'f1}Approaching 'pnam' System ...w1}'
getuser 12; tx = result; ta = right(tx,2); tx = left(ta,1)
enc = random(1,10,tx); if enc = 3 then do; call ENCT; end
t 'n2}Entering System ...w1}'
getuser 12; tx = result; ta = right(tx,2); tx = left(ta,1)
enc = random(1,20,tx)
	if enc = 7 then do; enemy = 'Unknown'; eshn = 0; eshp = 0; eshd = 0; ewpe = 0; call BOUNTY; end
	if enc = 13 then do; call FREETRD; end
call INSYS2

INSYS2:
t 'f1}In-System Menu:			c1}System: c7}'pnam
t 'n2}c6} z1}<Q>z0} Leave System'
if plnt > 0 then t ' z1}<O>z0} Orbit c7}'plnt
if ast > 0 then t ' c6}z1}<A>z0} Enter Asteroid Belt'
if base > 0 then do; t ' z1}<B>z0} Dock with c7}'base; end
if post > 0 then do; t ' c6}z1}<D>z0} Dock with c7}'plnt'c6} Trading Station'; end
s 'n1}Select: '; getchar; ans = upper(result)
if ans = 'O' then do; call WHERE5; end
if ans = 'Q' then do; t 'n2}Leaving 'pnam' Systemw1}'; call SHIP1; end 
if ans = 'B' then do; area = base; call WHERE1; end
if ans = 'A' then do; t 'n2}Not available - Currently under construction!w1}'; call INSYS; end
if ans = 'D' then do; call WHERE6; end
if ans = '' then do; call INSYS2; end
call INSYS2

TRAD:
hlds = ship * 10
t 'f1}c5}'plnt' Trading Stationc7}'
t 'n2}Product           Cost/Avail	        Ship          Holds     In Use'
t 'n1}c6}A -  Agricultural: 'cagr'	'prd1'		c1}Agriculture:  c7}'hlds'         'agri  
t 'c6}B -  Technical:    'ctch'	'prd3'		c1}Technical:    c7}'hlds'         'tech
t 'c6}C -  Raw Material  'cequ'	'prd2'		c1}Raw Material: c7}'hlds'         'eqip
t '                                       c3}Credits:       c7}'money
s 'n1}c2}Which (Q=Exit): '; getchar; ans = upper(result)
if ans = 'Q' then do; call ORBIT; end
if ans = 'A' then do; call TBUYA; end
if ans = 'B' then do; call TBUYB; end
if ans = 'C' then do; call TBUYC; end
call TRAD

TBUYA:
if own = gamer then do; t 'n2}You cannot buy or sell to yourself!w1}'; call TRAD; end
s 'n1}(B)uy or (S}ell Agricultural Products? '; getchar; ans = upper(result)
max = ship * 10
if ans = 'S' then do; call TSELA; end
if prd1 < 1 then do; t 'Nothing Available!w1}'; call TRAD; end
if agri > max - 1 then do; t 'No Space in Holds!w2}'; call TRAD; end
if agri < max then mxm = max - agri; t' You may purchase 'mxm
query 'How Many: '; ans = upper(result)
if ans > mxm then do; t 'Too many!w2}'; call TRAD; end
cst = ans * cagr
if money > cst then do; money = money - cst; agri = agri + ans; prd1 = prd1 - ans; call TRAD; end
if money < cst then do; t 'Not enough credit!w2}'; end
call TRAD

TSELA:
t 'n1}You have 'agri' agricultural products available for sale.'
query 'n1}Sell how many: '; ans = upper(result)
if ans = 0 then do; call TRAD; end
if ans > agri then do; 'You do not have that many!w1}'; call TRAD; end
cst = ans * cagr;
if cst > money then do; t 'n1}Not enough credits ...w1}'; call TRAD; end
money = money + cst; agri = agri - ans; prd1 = prd1 + ans
t 'n1}That sale made 'cst'cr. for youw2}'
call TRAD
end

TBUYB:
if own = gamer then do; t 'n2}You cannot buy or sell to yourself!w1}'; call TRAD; end
s 'n1}(B)uy or (S}ell Technical Products? '; getchar; ans = upper(result)
max = ship * 10
if ans = 'S' then do; call TSELB; end
if prd3 < 1 then do; t 'Nothing Available!w1}'; call TRAD; end
if tech = max then do; t 'No Room in Holds!w2}'; call TRAD; end
if tech < max then mxm = max - tech; t ' You may purchase 'mxm
query 'How Many: '; ans = upper(result)
if ans > mxm then do; t 'n1}Not enough space in holds!w1}'; call TRAD; end
cst = ans * ctch
if money > cst then do; money = money - cst; tech = tech + ans; prd3 = prd3 - ans; call TRAD; end
if money < cst then do; t 'Not enough credit!w2}'; call TRAD; end
call TRAD

TSELB:
t 'n1}You have 'tech' technical products available for sale.'
query 'n1}Sell how many: '; ans = upper(result)
if ans = 0 then do; call TRAD; end
if ans > tech then do; 'You do not have that many!w1}'; call TRAD; end
cst = ans * ctch
if cst > money then do; t 'n1}Not enough credits ...w1}'; call TRAD; end
money = money + cst; tech = tech - ans; prd3 = prd3 + ans
t 'n1}That sale made 'cst'cr. for youw2}'
call TRAD
end

TBUYC:
if own = gamer then do; t 'n2}You cannot buy or sell to yourself!w1}'; call TRAD; end
s 'n1}(B)uy or (S}ell Equipment Products? '; getchar; ans = upper(result)
max = ship * 10
if ans = 'S' then do; call TSELC; end
if prd2 < 1 then do; t 'Nothing Available!w1}'; call TRAD; end
if eqip = max then do; t 'No Space in Hold!w2}'; call TRAD; end
if eqip < max then mxm = max - eqip; t' You may purchase 'mxm
query 'How Many: '; ans = upper(result)
if ans > mxm then do; t 'n1}Not enough space in holds!w1}'; call TRAD; end
cst = ans * cequ
if money > cst then do; money = money - cst; eqip = eqip + ans; prd2 = prd2 - ans; call TRAD; end
if money < cst then do; t 'Not enough credit!w2}'; call TRAD; end
call TRAD

TSELC:
t 'n1}You have 'eqip' raw products available for sale.'
query 'n1}Sell how many: '; ans = upper(result)
if ans = 0 then do; call TRAD; end
if ans > eqip then do; 'You do not have that many!w1}'; call TRAD; end
cst = ans * cequ
if cst > money then do; t 'n1}Not enough credits ...w1}'; call TRAD; end
money = money + cst; eqip = eqip - ans; prd2 = prd2 + ans
t 'n1}That sale made 'cst'cr. for youw2}'
call TRAD
end


ENCT:
esh = random(25,100)
t 'n2}c3}Bleeep Bleeep ... Battle Stationsn1}'esh' unidentified ships attacking!w2}'
wch = random(1,2)
if wch = 1 then do; ftrs = esh; crui = 0; mthr = 0; enemy = 'Hoerd'; val = esh * 25; call ENCNT; end
if wch = 2 then do; crui = esh; ftrs = 0; mthr = 0; enemy = 'Hoerd'; val = esh * 50; call ENCNT; end
if wch = 3 then do; mthr = 1; crui = esh; ftrs = esh * 2; enemy = 'Hoerd'; call ENCNT; end
call ENCNT
end

ENCNT:
t 'f1}c1}COMBAT BRIDGE:			'gamer'			'enemy
t 'n1}c3}A - Dispatch Fighters            c5}Fighters: c7}'fght'          c6}Fighters:    c7}'ftrs
t 'c3}B - Dispatch Cruisers            c5}Cruisers: c7}'crus'          c6}Cruisers:    c7}'crui  
t 'c3}C - Fire Weaponry                                     c6}MotherShip:  c7}'mthr
t 'c3}D - InterSector Jump		 c5}Shields:  c7}'shld
t 'c3}Q - Quit to Main Bridge'
s 'n1}c1}Combat Option: '; getchar; ans = upper(result)
if ans = 'A' then do; org = 0; call FCBT1; end
if ans = 'B' then do; org = 0; call CCBT1; end
if ans = 'C' then do; val = 0; call GUN; end
if ans = 'D' then do; call MOVE; end
if ans = 'Q' then do; call SHIP1; end
call ENCNT

GUN:
if ftrs > 0 then do; call GUNA; end
if mthr > 0 then do; call GUNA; end
if crui > 0 then do; call GUNA; end
t 'n2}What are you attacking?w1}'
call ENCNT
end

GUNA:
t 'n2}FIRE CONTROL'
s 'Fire at (A-fighters B-cruisers C-MotherShip): '; getchar; ans = upper(result)
if ans = 'A' then do; fr = ftrs; t 'f1}Firing ...'; call KL1; end
if ans = 'B' then do; fr = crui; t 'f1}Firing ...'; call KL2; end
if ans = 'C' then do; fr = mthr; t 'f1}Firing ...'; call KL3; end
if ans = 'Q' then do; call ENCNT; end
call GUN

KL3:
t 'n2}Currently Not Active ...w1}'
call ENCNT
if fr = 0 then do; sh = shld * 10 * ship; ef = mthr; t 'f1}'; call BKL1; end
ht = random(1,3)
t 'w0}f0}c3}Firing ...n1}c1}Enemy Fighters:    <3}c7}'ftrs
if ht = 1 then do; ftrs = ftrs - 1; val = val + 5; t '    <4}c1}Hit'; fr = fr - 1; call KL1; end
if ht = 2 then do; t 'c6}Miss'; fr = fr - 1; call KL1; end
if ht = 3 then do; t 'c6}Miss'; fr = fr - 1; call KL1; end
call KL3

KL1:
if fr = 0 then do; sh = shld * 10 * ship; ef = ftrs; t 'f1}'; call BKL1; end
ht = random(1,3)
t 'w0}f0}c3}Firing ...n1}c1}Enemy Fighters:    <3}c7}'ftrs
if ht = 1 then do; ftrs = ftrs - 1; val = val + 5; t '    <4}c1}Hit'; fr = fr - 1; call KL1; end
if ht = 2 then do; t 'c6}Miss'; fr = fr - 1; call KL1; end
if ht = 3 then do; t 'c6}Miss'; fr = fr - 1; call KL1; end
call KL1

KL2:
if fr = 0 then do; sh = shld * 10 * ship; ef = crui; t 'f1}'; call BKL2; end
ht = random(1,3)
t 'w0}f0}c3}Firing ...n1}c1}Enemy Cruisers:    <3}c7}'crui
if ht = 1 then do; crui = crui - 1; val = val + 10; t 'c1}Hit!'; fr = fr - 1; call KL2; end
if ht = 2 then do; t 'c6}Miss'; fr = fr - 1; call KL2; end
if ht = 3 then do; t 'c6}Miss'; fr = fr - 1; call KL2; end
call KL2

BKL1:
if ef = 0 then do; money = money + val; t 'n1}You collect 'val' bounty!w1}'; call ENCNT; end
if sh = 0 then do; money = money + val; t 'Shields Destroyed!w2}'; shld = 0; t 'n1}You collect 'val' Bounty!w1}'; call SAVE; end
t 'f0}c3}The Hoerd Attacks: c7}'ftrs'c3}fighters are firing back ...'
t 'n1}c5}Shield Strength (Shields x 10): c7}'sh
ht = random(1,5)
if ht = 1 then do; sh = sh - 1; ef = ef - 1; t 'n1}c3}HIT!w1}'; call BKL1; end
if ht > 1 then do; t 'n1}c2}Miss'; ef = ef -1; call BKL1; end
call ENCNT

BKL2:
if ef = 0 then do; money = money + val; t 'n1}You collect 'val' Bounty!w1}'; call ENCNT; end
if sh = 0 then do; money = money + val; t 'Shields Destroyed!w2}'; shld = 0; t 'n1}You collect 'val' Bounty!w1}'; call SAVE; end
t 'f0}c3}The Hoerd Attacks: c7}'crui'c3} cruisers are firing back ...'
t 'n1}c5}Shield Strength (Shields x 10): w0}c7}'sh
ht = random(1,5)
if ht = 1 then do; sh = sh - 3; ef = ef - 1; t 'n1}c3}HIT!w1}'; call BKL2; end
if ht > 1 then do; t 'n1}c2}Miss'; ef = ef -1; call BKL2; end
call ENCNT

SAVE:
call ENCNT
end

/*  KL3:
if fr = 0 then call ENCNT
ht = random(1,3)
if ht = 1 then do; mthr = mthr - 1; t 'Hit'; fr = fr - 1; call KL3; end
if ht = 2 then t 'Miss'; fr = fr - 1; call KL3; end
if ht = 3 then t 'Miss'; fr = fr - 1; call KL3; end
call KL3  */
 
FCBT1:
if ftrs > 0 then do; call FCBTA; end
if mthr > 0 then do; call FCBTA; end
if crui > 0 then do; call FCBTA; end
t 'n2}What are you attacking?w1}'
call ENCNT
end

FCBTA:
query 'n1}How Many Fighters: '; gft = upper(result)
if gft < 0 then do; t 'Nice Try ...!w1}'; call ENCNT; end
if gft > fght then do; t 'You do not have that many!w1}'; call ENCNT; end
s 'n1}Attack which (A-Fighters B-Cruisers): '; getchar; ans = upper(result)
if ans = 'A' then do; t 'f1}'; call FCBT2; end
if ans = 'B' then do; t 'f1}'; call FCBT3; end
call ENCNT

CCBT1:
if ftrs > 0 then do; call CCBTA; end
if mthr > 0 then do; call CCBTA; end
if crui > 0 then do; call CCBTA; end
t 'n2}What are you attacking?w1}'
call ENCNT
end

CCBTA:
query 'n1}How Many Cruisers: '; gft = upper(result)
if gft < 0 then do; t 'Nice Try ...!w1}'; call ENCNT; end
if gft > crus then do; t 'You do not have that many!w1}'; call ENCNT; end
s 'n1}Attack which (A-Fighters B-Cruisers): '; getchar; ans = upper(result)
if ans = 'A' then do; t 'f1}'; call CCBT2; end
if ans = 'B' then do; t 'f1}'; call CCBT3; end
call ENCNT

CCBT2:
t 'f0}'
t 'cc}YOUR CRUISERS:       <4}c7}'gft
t 'c1}ENEMY FIGHTERS:     <4}c7}'ftrs
t 'w0}'
if org = 10 then do; call CCKA1; end
gguys = gft; bguys = ftrs
x = random(1,6)
kl = random(1,6,x)
if kl = 1 then do; bguys = bguys - 1; ftrs = ftrs - 1; call CCK1; end
if kl = 2 then do; bguys = bguys - 1; ftrs = ftrs - 1; call CCK1; end
if kl = 3 then do; gguys = gguys - 1; gft = gft - 1; org = org + 1; call CCK1; end
if kl = 4 then do; bguys = bguys - 1; ftrs = ftrs - 1; call CCK1; end
if kl = 5 then do; bguys = bguys - 1; ftrs = ftrs - 1; call CCK1; end
if kl = 6 then do; gguys = gguys - 1; gft = gft - 1; org = org + 1; call CCK1; end
call CCBT2

CCK1:
if gguys < 1 then do; gft = 0; crus = gft; call ENCNT; end
if bguys < 1 then do; ftrs  = 0; crus = gft; money = money + val; t 'You have received 'val' in Bounty!';  call ENCNT; end
call CCBT2

CCKA1:
s 'n2}C- Continue  R - Recall Cruisers: '; getchar; ans = upper(result)
if ans = 'C' then do; org = 0; call CCBT2; end
if ans = 'R' then do; crus = gft; org = 0; call ENCNT; end 
call ENCNT

CCBT3:
t 'f0}'
t 'cc}YOUR CRUISERS:       <4}c7}'gft
t 'c1}ENEMY CRUISERS:     <4}c7}'crui
t 'w0}'
if org = 10 then do; call CCKA2; end
gguys = gft; bguys = crui
x = random(1,6)
kl = random(1,6,x)
if kl = 1 then do; gguys = gguys - 1; gft = gft - 1; org = org + 1; call CCK2; end
if kl = 2 then do; bguys = bguys - 1; crui = crui - 1; call CCK2; end
if kl = 3 then do; gguys = gguys - 1; gft = gft - 1; org = org + 1; call CCK2; end
if kl = 4 then do; bguys = bguys - 1; crui = crui - 1; call CCK2; end
if kl = 5 then do; bguys = bguys - 1; crui = crui - 1; call CCK2; end
if kl = 6 then do; gguys = gguys - 1; gft = gft - 1; org = org + 1; call CCK2; end
call CCBT3

CCK2:
if gguys < 1 then do; gft = 0; crus = gft; call ENCNT; end
if bguys < 1 then do; crui = 0; crus = gft; money = money + val; t 'You have received 'val' in Bounty!'; call ENCNT; end
call CCBT3

CCKA2:
s 'n2}C- Continue  R - Recall Cruisers: '; getchar; ans = upper(result)
if ans = 'C' then do; org = 0; call CCBT3; end
if ans = 'R' then do; crus = gft; org = 0; call ENCNT; end 
call ENCNT


FCBT3:
t 'f0}'
t 'cc}YOUR FIGHTERS:       <4}c7}'gft
t 'c1}ENEMY CRUISERS:     <4}c7}'crui
t 'w0}'
if org = 10 then do; call CKA2; end
gguys = gft; bguys = crus
x = random(1,6)
kl = random(1,6,x)
if kl = 1 then do; gguys = gguys - 1; gft = gft - 1; org = org + 1; call CK2; end
if kl = 2 then do; gguys = gguys - 1; gft = gft - 1; org = org + 1; call CK2; end
if kl = 3 then do; gguys = gguys - 1; gft = gft - 1; org = org + 1; call CK2; end
if kl = 4 then do; bguys = bguys - 1; crui = crui - 1; call CK2; end
if kl = 5 then do; bguys = bguys - 1; crui = crui - 1; call CK2; end
if kl = 6 then do; gguys = gguys - 1; gft = gft - 1; org = org + 1; call CK2; end
call FCBT3

CK2:
if gguys < 1 then do; gft = 0; fght = gft; call ENCNT; end
if bguys < 1 then do; crui = 0; fght = gft; money = money + val; t 'You have received 'val' in Bounty!'; call ENCNT; end
call FCBT3

CKA2:
s 'n2}C- Continue  R - Recall Cruisers: '; getchar; ans = upper(result)
if ans = 'C' then do; org = 0; call FCBT3; end
if ans = 'R' then do; fght = gft; org = 0; call ENCNT; end 
call ENCNT

FCBT2:
t 'f0}'
t 'cc}YOUR FIGHTERS:       <4}c7}'gft
t 'c1}ENEMY FIGHTERS:     <4}c7}'ftrs
t 'w0}'
if org = 10 then do; call CKA1; end
gguys = gft; bguys = ftrs
x = random(1,6)
kl = random(1,6,x)
if kl = 1 then do; gguys = gguys - 1; gft = gft - 1; org = org + 1; call CK1; end
if kl = 2 then do; bguys = bguys - 1; ftrs = ftrs - 1; call CK1; end
if kl = 3 then do; gguys = gguys - 1; gft = gft - 1; org = org + 1; call CHK1; end
if kl = 4 then do; bguys = bguys - 1; ftrs = ftrs - 1; call CK1; end
if kl = 5 then do; bguys = bguys - 1; ftrs = ftrs - 1; call CK1; end
if kl = 6 then do; gguys = gguys - 1; gft = gft - 1; org = org + 1; call CHK1; end
call FCBT2

CK1:
if gguys < 1 then do; gft = 0; fght = gft; ftrs = ftrs; call ENCNT; end
if bguys < 1 then do; ftrs = 0; fght = gft; money = money + val; t 'You have received 'val' in Bounty!'; call ENCNT; end
call FCBT2

CKA1:
s 'n2}C- Continue  R - Recall Fighters: '; getchar; ans = upper(result)
if ans = 'C' then do; org = 0; call FCBT2; end
if ans = 'R' then do; fght = gft; org = 0; call ENCNT; end 
call ENCNT

ORBIT:
t 'f1}c1}ORBITAL COMMAND MENU:'
t 'n1}c6}P - Planetary Report for c3}'plnt
t 'c6}L - Land on c3}'plnt
t 'c6}Q - Leave Orbit'
t 'c6}C - Enter Combat Mode'
if post > 0 then t 'c6}D - Dock with 'plnt' Trading Post'
s 'n1}Option: '; getchar; ans = upper(result)
if ans = 'P' then do; call INFO; end
if ans = 'D' then do; call WHERE6; end
if ans = 'Q' then do; t 'n2}Exiting 'plnt 'System ...w1}'; call SHIP1; end
if ans = 'L' then do; call LAND; end
call orbit

LAND:
if own = 0 then do; call LAND1; end
if own = gamer then do; call LAND2; end
t 'You are not the owner - Do you wish to attack the Planet? (y/n) '; getchar; ans = upper(result)
if ans = 'N' then do; call ORBIT; end
if ans = 'Y' then do; call ATK2; end
call LAND

LAND2:
t 'f1}cc}PLANETARY MENU:             c2}Owner: c7}'own'       c2}Planet: c7}'plnt
t 'n1}c3}Q - Return to Ship          c5}Agricultural Stock: c7}'prd1'	c5}Fighters: c7}'fitr
t 'c3}D - Deploy Military         c5}Raw Materials:      c7}'prd2'	c5}Cruisers: c7}'crsr
t 'c3}A - Assign Workforce        c5}Technical Stock:    c7}'prd3'	c5}Infantry: c7}'inf
t 'c3}C - Take/Leave Goods'
t 'c3}S - Planetary Status'
t 'c3}P - Process Products'
t 'c3}B - Build Military'
s 'n1}c2}Option: '; getchar; ans = upper(result)
if ans = 'T' then do; call TRANS; end
if ans = 'C' then do; call TAKE; end
if ans = 'B' then do; call BUILD; end
if ans = 'D' then do; call WHERE4; end
if ans = 'Q' then do; call PLANWRITE3; end
if ans = 'A' then do; call WHERE3; end
if ans = 'S' then do; call INFO2; end
if ans = 'P' then do; call PROC; end
t 'n2}c3}Sorry, Item not yet active!w2}'
call land

TAKE:
t 'f1}c5}PRODUCT CONTROL:      c1}'plnt'	c3}AGRI: c7}'prd1'   c3}RAW: c7}'prd2'   c3}TECH: c7}'prd3
t 'c1}                      Ship	cc}AGRI: c7}'agri'   cc}RAW: c7}'eqip'   cc}TECH: c7}'tech
t 'n1}A - Agricultural     B - Raw Materials     C - Technical'
s 'n1}Which (Q-Quit): '; getchar; ans = upper(result)
if ans = 'A' then do; call TAKE1; end
if ans = 'B' then do; call TAKE2; end
if ans = 'C' then do; call TAKE3; end
if ans = 'Q' then do; call PLANWRITE; end

TAKE1:
s ' <T - Take   L - Leave > '; getchar; ans = upper(result)
if ans = 'L' then do; call LEAVE1; end
query 'n1}How Many do you want: '; tk = upper(result); call TAKE; end
if tk < 1 then do; t 'Give me a break!w1}'; call 
if tk > prd1 then do; t 'You may not take more than you have!w1}'; call TAKE; end
prd1 = prd1 - tk; agri = agri + tk
call TAKE
end

LEAVE1:
query 'n1}How Many to Leave: '; lv = upper(result)
if lv < 0 then do: t 'Give me a break!w1}'; call TAKE; end
if lv > agri then do; t 'n1}You do not have that many!w1}'; call TAKE; end
prd1 = prd1 + lv; agri = agri - lv
call TAKE
end

TAKE2:
s ' <T - Take   L - Leave > '; getchar; ans = upper(result)
if ans = 'L' then do; call LEAVE2; end
query 'n1}How Many do you want: '; tk = upper(result)
if tk < 0 then do; t 'Give me a break!w1}'; call TAKE; end
if tk > prd2 then do; t 'You may not take more than you have!w1}'; call TAKE; end
prd2 = prd2 - tk; eqip = eqip + tk
call TAKE
endl

LEAVE2:
query 'n1}How Many to Leave: '; lv = upper(result)
if lv < 0 then do; t 'Give me a break!w1}'; call TAKE; end
if lv > eqip then do; t 'n1}You do not have that many!w1}'; call TAKE; end
prd2 = prd2 + lv; eqip = eqip - lv
call TAKE
end

TAKE3:
s ' <T - Take   L - Leave > '; getchar; ans = upper(result)
if ans = 'L' then do; call LEAVE3; end
query 'n1}How Many do you want: '; tk = upper(result)
if tk < 0 then do; t 'Give me a break!w1}'; call TAKE; end
if tk > prd3 then do; t 'You may not take more than you have!w1}'; call TAKE; end
prd3 = prd3 - tk; tech = tech + tk
call TAKE
end

LEAVE3:
query 'n1}How Many to Leave: '; lv = upper(result)
if lv < 0 then do; t 'Give me a break!w1}'; call TAKE; end
if lv > tech then do; t 'n1}You do not have that many!w1}'; call TAKE; end
prd3 = prd3 + lv; tech = tech - lv
call TAKE
end

BUILD:
t 'f1}c3}INDUSTRO-MILITARY COMPLEX	c5}Technical Stock: c7}'prd3
t 'n1}cc}A - Construct Fighters   (Requires 10 Tech Stock)'
t 'B - Construct Cruisers   (Requires 25 Tech Stock)'
t 'Q - Quit'
query 'n1}c5}Option: '; ns = upper(result)
if ns = 'Q' then do; call PLANWRITE; end
if ns = 'B' then do; call BLB; end
if ns = 'A' then do; call BLA; end
call BUILD
end

BLA:
if prd3 < 10 then do; t 'n2}c3}Sorry - not enough material!w1}'; call BUILD; end
tch = trunc(prd3 / 10)
t 'n1}c5}You may construct c7}'tch'c5} fighters.'
query 'n1}c3}Build How Many: '; ans = upper(result)
if ans = 0 then do; call BUILD; end
if ans > tch then do; t 'You cannot build that many!w1}'; call BUILD; end
any = ans * 10
prd3 = prd3 - any
fitr = fitr + ans
t 'You now have 'fitr' fighters.g1}'
call BUILD
end

BLB:
if prd3 < 25 then do; t 'n2}c3}Sorry - not enough material!w1}'; call BUILD; end
tch = trunc(prd3 / 25)
t 'n1}c5}You may construct c7}'tch'c5} cruisers.'
query 'n1}Build How Many: '; ans = upper(result)
if ans = 0 then do; call BUILD; end
if ans > tch then do; t 'You cannot build that many!w1}'; call BUILD; end
any = ans * 25
prd3 = prd3 - any
crsr = crsr + ans
t 'You now have 'crsr' cruisers.g1}'
call BUILD
end

PROC:
if ltime = visit then do; t 'n2}You have already processed material on 'plnt'.w2}'; call land2; end
if visit = 0 then do; visit = date; t 'You must wait 24 hours before you can process material.w1}'; call LAND2; end
yt = substr(visit,5,2); dt = substr(date,5,2); td = dt - yt
ag = (td * agcl) /20
t 'n1}You have added 'ag' to your agricultural stockpile.'
prd1 = prd1 + ag
ra = (td * raw) /5
t 'n1}You have added 'ra' to your raw materials.'
prd2 = prd2 + ra
fk = (td * fctr) /100
t 'n1}You have added 'fk' to your technical stockpile.'
prd3 = prd3 + fk
t 'n1}Press A Key g1}'
visit = date
call planwrite
end

NAVY:
t 'f1}DEPLOY MILITARY:                                     Ship    Planet'
t 'n1}c3}A - Transfer Fighters to 'plnt'        c5}   Fighters:    c7}'fght'        'fitr
t 'c3}B - Transfer Cruisers to 'plnt'        c5}   Cruisers:    c7}'crus'        'crsr
t 'c3}C - Convert Idle Pop to Infantry             c5} Idle Pop:             c7}'pop
t 'c3}D - Take Fighters from 'plnt'          c5}   Infantry:             c7}'inf     
t 'c3}E - Take Cruisers from 'plnt
t 'c3}F - Take Troops from 'plnt
s 'n1}c2}Select: '; getchar; ans = upper(result)
if ans = 'A' then do; call NAVY1; end
if ans = 'B' then do; call NAVY2; end
if ans = 'C' then do; call NAVY3; end
if ans = 'D' then do; call NAVY4; end
if ans = 'E' then do; call NAVY5; end
if ans = 'F' then do; call NAVY6; end
if ans = 'Q' then do; call PLANWRITE; end
call NAVY

NAVY4:
query 'n1}How Many: '; ans = upper(result)
if ans > fitr then do; t 'n2}Not enough availablew1}'; call NAVY; end
if ans < 0 then do; t 'Nice Try - No Way!w1}'; call NAVY; end
if ans = 0 then do; call NAVY; end
if ans > 0 then do; fitr = fitr - ans; fght = fght + ans; call NAVY; end
call NAVY

NAVY5:
query 'n1}How Many: '; ans = upper(result)
if ans > crsr then do; t 'n2}Not enough availablew1}'; call NAVY; end
if ans < 0 then do; t 'Nice Try - No Way!w1}'; call NAVY; end
if ans = 0 then do; call NAVY; end
if ans > 0 then do; crsr = crsr - ans; crus = crus + ans; call NAVY; end
call NAVY

NAVY6:
query 'n1}How Many: '; ans = upper(result)
if ans > inf then do; t 'n2}Not enough availablew1}'; call NAVY; end
if ans < 0 then do; t 'Nice Try - No Way!w1}'; call NAVY; end
if ans = 0 then do; call NAVY; end
if ans > 0 then do; inf = inf - ans; col = col + ans; call NAVY; end
call NAVY

NAVY1:
query 'n1}How Many: '; ans = upper(result)
if ans > fght then do; t 'n2}Not enough availablew1}'; call NAVY; end
if ans < 0 then do; t 'Nice Try - No Way!w1}'; call NAVY; end
if ans = 0 then do; call NAVY; end
fitr = fitr + ans; fght = fght - ans; t 'n2}Transfering 'ans' Fightersw1}'; call NAVY; end
call NAVY

NAVY2:
query 'n1}How Many: '; ans = upper(result)
if ans > crus then do; t 'n2}Not enough availablew1}'; call NAVY; end
if ans < 0 then do; t 'Nice Try - No Way!w1}'; call NAVY; end
if ans = 0 then do; call NAVY; end
if ans > 0 then do; crsr = crsr + ans; crus = crus - ans; call NAVY; end
call NAVY

NAVY3:
query 'n1}How Many: '; ans = upper(result)
if ans > pop then do; t 'n2}Not enough availablew1}'; call NAVY; end
if ans < 0 then do; t 'Nice Try - No Way!w1}'; call NAVY; end
if ans = 0 then do; call NAVY; end
if ans > 0 then do; inf  = inf + ans; pop = pop - ans; call NAVY; end
call NAVY

LAND1:
s 'n1}There is no current owner. Do you wish to take over this world? (Y/N)'; getchar; ans = upper(result)
if ans = 'Y' then do; call ATK1; end
if ans = 'N' then do; call ORBIT; end
call ORBIT
 
ATK1:
if pdb = 0 then do; t 'n1}The planet is unpopulated. You may begin adapting it.w2}'; own = gamer; pbd = 1; call PLANWRITE; end
if pdb > 0 then do; call ATK2; end

ATK2:
t 'f1}Your Military				Defender'
t 'n1}Fighters: 'fght'				Fighters: 'fitr
t 'Cruisers: 'crus'				Cruisers: 'crsr
t 'Infantry: 'col'				Infantry: 'inf
t '						PlaDefBa: 'pdb
t '------------------------------------------------------------------------'
t 'A - Attack WarShips      C - Attack Infantry       Q - Quit to Ship'
t 'L - Land on World'
t '------------------------------------------------------------------------'
s 'n1}Your Option: '; getchar; ans = upper(result)
if ans = 'Q' then do; call ORBIT; end
if ans = 'A' then do; t 'f1}'; org = 0; call OPT1; end
if ans = 'C' then do; t 'f1}'; org = 0; call OPT2; end
if ans = 'L' then do; call CHEK; end
call ATK2

CHEK:
if fitr > 0 then do; t 'n1} There are still fighters to defeat!w1}'; call atk2; end
if crsr > 0 then do; t 'Qn1} There are still cruisers to defeat!w1}'; call ATK2; end
if inf > 0 then do; t 'There are still infantry units to defeat!w1}'; call ATK2; end
own = gamer
gal = gamer' has conquered 'plnt
call open(file,(path'news'), 'A')
call writeln(file,gal)
call close file
call PLANWRITE2
end 

OPT2:
if crsr > 0 then do; t 'n2}You cannot attack the surface until all ships are destroyed!'; call ATK2; end
if fitr > 0 then do; t 'n2}You cannot attack the surface until all ships are destroyed!'; call ATK2; end
call ATK3

OPT1:
s 'n1}Use Which WarShips:  A: Fighters   B: Cruisers'; getchar; wh = upper(result)
if wh = 'A' then do; atk = fght; call WCH1; end
if wh = 'B' then do; atk = crus; call WCH2; end
call ATK2

WCH1:
s 'n1}Against Which Enemy Ships: A: Fighters  B: Cruisers'; getchar; ene = upper(result)
if ene = 'A' then do; dfs = fitr; t 'f1}'; call ATK4; end
if ene = 'B' then do; dfs = crsr; t 'f1}'; call ATK5; end
call ATK2

WCH2:
s 'n1}Against Which Enemy Ships: A: Fighters  B: Cruisers'; getchar; ene = upper(result)
if ene = 'A' then do; dfs = fitr; t 'f1}'; call ATK6; end
if ene = 'B' then do; dfs = crsr; t 'f1}'; call ATK7; end
call ATK2

ATK7:
t 'f0}'
t 'YOUR CRUISERS:       <4}'atk
t 'THEIR CRUISERS:     <4}'dfs
t 'w0}'
if org = 10 then do; call CKK4; end
gguys = atk; bguys = dfs
x = random(1,6)
kl = random(1,6,x)
if kl = 1 then do; gguys = gguys - 1; atk = atk - 1; org = org + 1; call CHK4; end
if kl = 2 then do; bguys = bguys - 1; dfs = dfs - 1; call CHK4; end
if kl = 3 then do; gguys = gguys - 1; atk = atk - 1; org = org + 1; call CHK4; end
if kl = 4 then do; bguys = bguys - 1; dfs = dfs - 1; call CHK4; end
if kl = 5 then do; bguys = bguys - 1; dfs = dfs - 1; call CHK4; end
if kl = 6 then do; gguys = gguys - 1; atk = atk - 1; org = org + 1; call CHK4; end
call ATK7

CHK5:
if gguys < 1 then do; atk = 0; crus = atk; crsr = dfs; call ATK2; end
if bguys < 1 then do; dfs = 0; crus = atk; crsr = dfs; call ATK2; end
call ATK7

CKK4:
s 'n2}Continue (y/n): '; getchar; ans = upper(result)
if ans = 'Y' then do; org = 0; call ATK7; end
call ATK2

ATK6:
t 'f0}'
t 'YOUR CRUISERS:       <4}'atk
t 'THEIR FIGHTERS:     <4}'dfs
t 'w0}'
if org = 10 then do; call CKK3; end
gguys = atk; bguys = dfs
x = random(1,6)
kl = random(1,6,x)
if kl = 1 then do; gguys = gguys - 1; atk = atk - 1; org = org + 1; call CHK4; end
if kl = 2 then do; bguys = bguys - 1; dfs = dfs - 1; call CHK4; end
if kl = 3 then do; gguys = gguys - 1; atk = atk - 1; org = org + 1; call CHK4; end
if kl = 4 then do; bguys = bguys - 1; dfs = dfs - 1; call CHK4; end
if kl = 5 then do; bguys = bguys - 1; dfs = dfs - 1; call CHK4; end
if kl = 6 then do; bguys = bguys - 1; dfs = dfs - 1; call CHK4; end
call ATK6

CHK4:
if gguys < 1 then do; atk = 0; crus = atk; fitr = dfs; call ATK2; end
if bguys < 1 then do; dfs = 0; crus = atk; fitr = dfs; call ATK2; end
call ATK6

CKK3:
s 'n2}Continue (y/n): '; getchar; ans = upper(result)
if ans = 'Y' then do; org = 0; call ATK6; end
call ATK2

ATK5:
t 'f0}'
t 'YOUR FIGHTERS:       <4}'atk
t 'THEIR CRUISERS:     <4}'dfs
t 'w0}'
if org = 10 then do; call CKK2; end
gguys = atk; bguys = dfs
x = random(1,6)
kl = random(1,6,x)
if kl = 1 then do; gguys = gguys - 1; atk = atk - 1; org = org + 1; call CHK3; end
if kl = 2 then do; bguys = bguys - 1; dfs = dfs - 1; call CHK3; end
if kl = 3 then do; gguys = gguys - 1; atk = atk - 1; org = org + 1; call CHK3; end
if kl = 4 then do; bguys = bguys - 1; dfs = dfs - 1; call CHK3; end
if kl = 5 then do; gguys = gguys - 1; atk = atk - 1; org = org + 1; call CHK3; end
if kl = 6 then do; gguys = gguys - 1; atk = atk - 1; org = org + 1; call CHK3; end
call ATK5

CHK3:
if gguys < 1 then do; atk = 0; fght = atk; crsr = dfs; call ATK2; end
if bguys < 1 then do; dfs = 0; fght = atk; crsr = dfs; call ATK2; end
call ATK5

CKK2:
s 'n2}Continue (y/n): '; getchar; ans = upper(result)
if ans = 'Y' then do; org = 0; call ATK5; end
call ATK2

ATK4:
t 'f0}'
t 'YOUR FIGHTERS:       <4}'atk
t 'THEIR FIGHTERS:     <4}'dfs
t 'w0}'
if org = 10 then do; call CKK1; end
gguys = atk; bguys = dfs
x = random(1,6)
kl = random(1,6,x)
if kl = 1 then do; gguys = gguys - 1; atk = atk - 1; org = org + 1; call CHK2; end
if kl = 2 then do; bguys = bguys - 1; dfs = dfs - 1; call CHK2; end
if kl = 3 then do; gguys = gguys - 1; atk = atk - 1; org = org + 1; call CHK2; end
if kl = 4 then do; bguys = bguys - 1; dfs = dfs - 1; call CHK2; end
if kl = 5 then do; gguys = gguys - 1; atk = atk - 1; org = org + 1; call CHK2; end
if kl = 6 then do; bguys = bguys - 1; dfs = dfs - 1; call CHK2; end
call ATK4

CHK2:
if gguys < 1 then do; atk = 0; fght = atk; fitr = dfs; call ATK2; end
if bguys < 1 then do; dfs = 0; fght = atk; fitr = dfs; call ATK2; end
call ATK4

CKK1:
s 'n2}Continue (y/n): '; getchar; ans = upper(result)
if ans = 'Y' then do; org = 0; call ATK4; end
call ATK2

ATK3:
t 'f0}'
t 'YOURS:      <4}'col
t 'THEIRS:     <4}'inf
t 'w0}'
if org = 10 then do; call CKK; end
gguys = col; bguys = inf
x = random(1,6)
kl = random(1,6,x)
if kl = 1 then do; gguys = gguys - 1; col = col - 1; org = org + 1; call CHK1; end
if kl = 2 then do; bguys = bguys - 1; inf = inf - 1; call CHK1; end
if kl = 3 then do; gguys = gguys - 1; col = col - 1; org = org + 1; call CHK1; end
if kl = 4 then do; bguys = bguys - 1; inf = inf - 1; call CHK1; end
if kl = 5 then do; gguys = gguys - 1; col = col - 1; org = org + 1; call CHK1; end
call ATK3

CKK:
s 'n2}Continue (y/n): '; getchar; ans = upper(result)
if ans = 'Y' then do; org = 0; call ATK3; end
call ATK2

CHK1:
if gguys < 1 then do; col = 0; call PLANWRITE1; end
if bguys < 1 then do; inf = 0; call PLANWRITE1; end
call ATK3

WORKER:
t 'f1}WORKFORCE DEPLOYMENTn1}'
t 'c5}A - Add to Tech Workforce			c2}Colonists - c7}'col
t 'c5}B - Add to Farmer Workforce			c2}Idle Pop. - c7}'pop
t 'c5}C - Add to Blue Collar Workforce		c2}Technical - c7}'fctr
t 'c5}D - Deploy Colonists to Planet			c2}Agricultr - c7}'agcl
t 'c5}Q - Exit Workforce Menu				c2}Blue Colr - c7}'raw
t 'c5}E - Assign Colonists to Military		c2}Infantry -  c7}'inf
t 'c5}F - Reassign Workforce'

s 'c3}n1}Deploy Workers: '; getchar; ans = upper(result)
if ans = 'Q' then do; call PLANWRITE; end
if ans = 'D' then do; call DCOL; end
if ans = 'A' then do; call TCHG; end
if ans = 'B' then do; call TCHG1; end
if ans = 'C' then do; call TCHG2; end
if ans = 'E' then do; call TCHG3; end
if ans = 'F' then do; call REASSIGN; end
if ans = 'X' then do; exit; end
call WORKER
end

REASSIGN:
s 'A - Tech  B - Farmer  C - Blue Collar  Q - Exitn1}Which Workforce? '; getchar; ans = upper(result)
if ans = 'A' then do; call REAS; end
if ans = 'B' then do; call REAS1; end
if ans = 'C' then do; call REAS2; end
if ans = 'Q' then do; call WORKER; end
if ans = 'E' then do; call REASSIGN; end

REAS:
t 'n1}You wish to place Blue Collar Workers on the Unemployment Rolls?'
query 'n1}How Many: '; nmb = upper(result)
if nmb = '' then do; call REASSIGN; end
if nmb > fctr then do; t 'Not enough workersw2}'; call REASSIGN; end
if fctr < 1 then do; t 'Nice try, but no way!w2}'; call REASSIGN; end
fctr = fctr - nmb; pop = pop + nmb; call WORKER; end

REAS1:
t 'n1}You wish to place Farmers on the Unemployment Rolls?'
query 'n1}How Many: '; nmb = upper(result)
if nmb = 'Q' then do; call REASSIGN; end
if nmb > agcl  then do; t 'Not enough workers!w2}'; call REASSIGN; end
if agcl < 1 then do; t 'Nice try, but no way!w2}'; call REASSIGN; end
agcl = agcl - nmb; pop = pop + nmb; call WORKER; end

REAS2:
t 'n1}You wish to place Miners on the Unemployment Rolls?'
query 'n1}How Many: '; nmb = upper(result)
if nmb = 'Q' then do; call REASSIGN; end
if nmb > raw then do; t 'Not enough populationw2}'; call REASSIGN; end
if raw < 1 then do; t 'Nice try, but no way!w2}'; call REASSIGN; end
raw = raw - nmb; pop = pop + nmb; call WORKER; end

TCHG:
query 'n1}How Many: '; nmb = upper(result)
if nmb > pop then do; t 'Not enough population - transfer colonists to Idle Pop.w2}'; call WORKER; end
if nmb < 0 then do; t 'You cannot take workers at this prompt!w2}'; call WORKER; end
pop = pop - nmb; fctr = fctr + nmb; call WORKER; end

TCHG1:
query 'n1}How Many: '; nmb = upper(result)
if nmb < 0 then do; t 'You cannot take workers at this prompt!w2}'; call WORKER; end
if nmb > pop then do; t 'Not enough population - transfer colonists to Idle Pop.w2}'; call WORKER; end
pop = pop - nmb; agcl = agcl + nmb; call WORKER; end

TCHG2:
query 'n1}How Many: '; nmb = upper(result)
if nmb < 0 then do; t 'You cannot take workers at this prompt!w2}'; call WORKER; end
if nmb > pop then do; t 'Not enough population - transfer colonists to Idle Pop.w2}'; call WORKER; end
pop = pop - nmb; raw = raw + nmb; call WORKER; end

TCHG3:
query 'n1}How Many: '; nmb = upper(result)
if nmb > pop then do; t 'Not enough populationw2}'; call WORKER; end
if nmb < 0 then do; t 'You cannot take workers at this prompt!w2}'; call WORKER; end
pop = pop - nmb; inf = inf + nmb; call WORKER; end

DCOL:
query 'n1}How Many? '; ans = upper(result)
if ans > col then do; t 'You do not have that many!'; call WORKER; end
if ans < col then do; col = col - ans; pop = pop + ans; call WORKER; end
call WORKER
end

INFO:
if planet = 0 then do; t 'n2}There is no planet to scan!w1}'; call ORBIT; end
call WHERE2

INFO1:
t 'f1}Planetary Scan:'
t 'n1}    Planet:   'plnt
t '    Owner:    'own
t '    PDBs:     'pdb
t '    Cruisers: 'crsr
t '    Fighters: 'fitr
t '    Infantry: 'inf
t '    Transprt: 'trns
t '    Agricltr: 'prd1
t '    Raw Matr: 'prd2
t '    Factory:  'prd3
t '    Populous: 'pop
t 'n1}Press A Key g1}'
call ORBIT
end

INFO2:
t 'f1}Planetary Scan:'
t 'n1}    Planet:   'plnt
t '    Owner:    'own
t '    PDBs:     'pdb
t '    Cruisers: 'crsr
t '    Fighters: 'fitr
t '    Infantry: 'inf
t '    Transprt: 'trns
t '    Agricltr: 'prd1
t '    Raw Matr: 'prd2
t '    Factory:  'prd3
t '    Populous: 'pop
t 'n1}Press A Key g1}'
call LAND2
end

SCAN:
bas = base; if base = 0 then bas = 'None'
t 'f1}SCAN REPORT FOR SECTOR 'loc
t 'n1}c5}Star Systems: c7}'num'        c5}Stellar Base: c7}'bas'n1}'
if s1 > 0 then do; t '   c3}System: c7}'S1; end
if s2 > 0 then do; t '   c3}System: c7}'S2; end
if S3 > 0 then do; t '   c3}System: c7}'S3; end
t 'n1}c6}Adjoining Sectors: c7}'next
if S1 = 0 then do; t 'n1}c6}Press A Key g1}'; call SHIP1; end
s 'n2}c6} (S) Scan System   (Q) Exit Scan: '; getchar; ans = upper(result)
	if ans = 'Q' then do; call SHIP1; end
	if ans = 'S' then do; call SCANA; end
	call SCAN
	end

SCANA:
query 'n2}Enter System Name: c7}'; ans = upper(result)
if ans = upper(S1) then do; call SCANC; end
if ans = upper(S2) then do; call SCAND; end
if ans = upper(S3) then do; call SCANE; end
t 'n2}You must Select a Listed System!w1}'
call SCAN
end

SCANC:
scan = 1; scana = 0; scanb = 0
sector = ans
call open(file,path4||sector,'R')
nplan = readln(file)
nhosp = readln(file)
ast = readln(file)
type = readln(file)
plnt = readln(file)
post = readln(file)
call close(file)
t 'f1}System Report:'
t 'n1}Number of Planets: 'nplan
t 'Hospitable Planets: 'nhosp
t 'Asteroid Belt: 'ast
t 'Star Type: 'type
t 'Planet ID: 'plnt
t 'Trading Posts: 'post
t 'n1}Press a Key g1}'
call SHIP1

SCAND:
scana = 1; scan = 0; scanb = 0
sector = ans
call open(file,path4||sector,'R')
nplan = readln(file)
nhosp = readln(file)
ast = readln(file)
type = readln(file)q

plnt = readln(file)
post = readln(file)
call close(file)
t 'f1}System Report:'
t 'n1}Number of Planets: 'nplan
t 'Hospitable Planets: 'nhosp
t 'Asteroid Belt: 'ast
t 'Star Type: 'type
t 'Planet ID: 'plnt
t 'Trading Posts: 'post
t 'n1}Press a Key g1}'
call SHIP1

SCANE:
scanb = 1; scan = 0; scana = 0
sector = ans
call open(file,path4||sector,'R')
nplan = readln(file)
nhosp = readln(file)
ast = readln(file)
type = readln(file)
plnt = readln(file)
post = readln(file)
call close(file)
t 'f1}System Report:'
t 'n1}Number of Planets: 'nplan
t 'Hospitable Planets: 'nhosp
t 'Asteroid Belt: 'ast
t 'Star Type: 'type
t 'Planet ID: 'plnt
t 'Trading Posts: 'post
t 'n1}Press a Key g1}'
call SHIP1

MOVE:
t 'n2}Sectors Available: z7}c4}' next 'z0}c5}'
query'n1}Option: '; ans = upper(result)
if ans = 'Q' then do; call ship1; end
if ans = 0 then do; t 'You cannot access that sector from here!w2}'; call SHIP; end
if ans = seca then do; nplan = 0; nhosp = 0; ast = 0; type = 0; plnt = 0; post = 0; area = seca; loc = ans; sect = ans; scan = 0; scana = 0; scanb = 0; t 'n1}. . . Engaging Main Drive w1}n2}Arriving at Sector 'ans'w1}'; call SHIP; end
if ans = secb then do; nplan = 0; nhosp = 0; ast = 0; type = 0; plnt = 0; post = 0; area = secb; loc = ans; sect = ans; scan = 0; scana = 0; scanb = 0; t 'n1}. . . Engaging Main Drive w1}n2}Arriving at Sector 'ans'w1}'; call SHIP; end
if ans = secc then do; nplan = 0; nhosp = 0; ast = 0; type = 0; plnt = 0; post = 0; area = secc; loc = ans; sect = ans; scan = 0; scana = 0; scanb = 0; t 'n1}. . . Engaging Main Drive w1}n2}Arriving at Sector 'ans'w1}'; call SHIP; end
if ans = secd then do; nplan = 0; nhosp = 0; ast = 0; type = 0; plnt = 0; post = 0; area = secd; loc = ans; sect = ans; scan = 0; scana = 0; scanb = 0; t 'n1}. . . Engaging Main Drive w1}n2}Arriving at Sector 'ans'w1}'; call SHIP; end
t 'n1} You cannot access that sector from here!w2}'
call SHIP1

WHERE:
call open(file,path2||area,'R')
num = readln(file)
S1 = readln(file)
S2 = readln(file)
S3 = readln(file)
Base = readln(file)
next = readln(file)
seca = readln(file)
secb = readln(file)
secc = readln(file)
secd = readln(file)
loc = readln(file)
call close(file)
call SHIP1

WHERE1:
call open(file,path2||area,'R')
bnam = readln(file)
onr = readln(file)
bftr = readln(file)
bshl = readln(file)
bcon = readln(file)
ctch = readln(file)
cagr = readln(file)
cequ = readln(file)
cgun = readln(file)
cslv = readln(file)
loc = readln(file)
call close(file)
call BASE1

WHERE2:
t plnt'w2}'
planet = plnt
call open(file,path3''planet,'R')
plnt = readln(file)
own = readln(file)
pdb = readln(file)
Crsr = readln(file)
fitr = readln(file)
inf = readln(file)
trns = readln(file)
agcl = readln(file)
raw = readln(file)
fctr = readln(file)
pop = readln(file)
area = readln(file)
visit = readln(file)
prd1 = readln(file)
prd2 = readln(file)
prd3 = readln(file)
call close(file)
call INFO1

WHERE3:
planet = plnt
call open(file,path3''planet,'R')
plnt = readln(file)
own = readln(file)
pdb = readln(file)
Crsr = readln(file)
fitr = readln(file)
inf = readln(file)
trns = readln(file)
agcl = readln(file)
raw = readln(file)
fctr = readln(file)
pop = readln(file)
area = readln(file)
visit = readln(file)
prd1 = readln(file)
prd2 = readln(file)
prd3 = readln(file)
call close(file)
call WORKER

WHERE4:
planet = plnt
call open(file,path3''planet,'R')
plnt = readln(file)
own = readln(file)
pdb = readln(file)
Crsr = readln(file)
fitr = readln(file)
inf = readln(file)
trns = readln(file)
agcl = readln(file)
raw = readln(file)
fctr = readln(file)
pop = readln(file)
area = readln(file)
visit = readln(file)
prd1 = readln(file)
prd2 = readln(file)
prd3 = readln(file)
call close(file)
call NAVY

WHERE5:
if plnt = 'None' then do; t 'There is no planet to orbit!'; call INSYS2; end
if plnt = '0' then do; t 'There is no planet to orbit!'; call INSYS2; end
planet = plnt
call open(file,path3''planet,'R')
plnt = readln(file)
own = readln(file)
pdb = readln(file)
Crsr = readln(file)
fitr = readln(file)
inf = readln(file)
trns = readln(file)
agcl = readln(file)
raw = readln(file)
fctr = readln(file)
pop = readln(file)
area = readln(file)
visit = readln(file)
prd1 = readln(file)
prd2 = readln(file)
prd3 = readln(file)
call close(file)
call ORBIT

WHERE6:
planet = plnt
call open(file,path3''planet,'R')
plnt = readln(file)
own = readln(file)
pdb = readln(file)
Crsr = readln(file)
fitr = readln(file)
inf = readln(file)
trns = readln(file)
agcl = readln(file)
raw = readln(file)
fctr = readln(file)
pop = readln(file)
area = readln(file)
visit = readln(file)
prd1 = readln(file)
prd2 = readln(file)
prd3 = readln(file)
call close(file)
cagr = random(1,25)
ctch = random(1,25)
cequ = random(1,25)
call TRAD

PLANWRITE:
call open(file,path3''plnt,'W')
call writeln(file,plnt)
call writeln(file,own)
call writeln(file,pdb)
call writeln(file,crsr)
call writeln(file,fitr)
call writeln(file,inf)
call writeln(file,trns)
call writeln(file,agcl)
call writeln(file,raw)
call writeln(file,fctr)
call writeln(file,pop)
call writeln(file,area)
call writeln(file,visit)
call writeln(file,prd1)
call writeln(file,prd2)
call writeln(file,prd3)
call close(file)
call LAND

PLANWRITE1:
call open(file,path3''plnt,'W')
call writeln(file,plnt)
call writeln(file,own)
call writeln(file,pdb)
call writeln(file,crsr)
call writeln(file,fitr)
call writeln(file,inf)
call writeln(file,trns)
call writeln(file,agcl)
call writeln(file,raw)
call writeln(file,fctr)
call writeln(file,pop)
call writeln(file,area)
call writeln(file,visit)
call writeln(file,prd1)
call writeln(file,prd2)
call writeln(file,prd3)
call close(file)
call ATK2

PLANWRITE2:
call open(file,path3''plnt,'W')
call writeln(file,plnt)
call writeln(file,own)
call writeln(file,pdb)
call writeln(file,crsr)
call writeln(file,fitr)
call writeln(file,inf)
call writeln(file,trns)
call writeln(file,agcl)
call writeln(file,raw)
call writeln(file,fctr)
call writeln(file,pop)
call writeln(file,area)
call writeln(file,visit)
call writeln(file,prd1)
call writeln(file,prd2)
call writeln(file,prd3)
call close(file)
call LAND2

PLANWRITE3:
call open(file,path3''plnt,'W')
call writeln(file,plnt)
call writeln(file,own)
call writeln(file,pdb)
call writeln(file,crsr)
call writeln(file,fitr)
call writeln(file,inf)
call writeln(file,trns)
call writeln(file,agcl)
call writeln(file,raw)
call writeln(file,fctr)
call writeln(file,pop)
call writeln(file,area)
call writeln(file,visit)
call writeln(file,prd1)
call writeln(file,prd2)
call writeln(file,prd3)
call close(file)
call ORBIT

BYE:
query 'n2}Are you sure you want to exit Star Empire I: '; ans = upper(result)
if ans = 'N' then do; call START; end
t 'You have reached the end!'
filename = handle
call open(file,(path1''filename) ,'W')
call writeln(file,gamer)
call writeln(file,money)
call writeln(file,bank)
call writeln(file,ship)
call writeln(file,swp)
call writeln(file,shld)
call writeln(file,tech)
call writeln(file,agri)
call writeln(file,eqip)
call writeln(file,guns)
call writeln(file,slave)
call writeln(file,torp)
call writeln(file,fght)
call writeln(file,crus)
call writeln(file,tran)
call writeln(file,area)
call writeln(file,col)
call writeln(file,gate)
call writeln(file,trp)
call writeln(file,date)
call writeln(file,end)
call writeln(file,wpn)
call close(file)
exit

signal on syntax

SYNTAX:
t 'Syntax Error in Line: ' SIGL
t 'n1}Press A Key g1}'
exit

ERROR:
t 'Error in Line: ' SIGL
t 'n1}Press A Key g1}'
exit

BOUNTY:
scn = 0
t 'f1}b1}c3}WHHHAAAMMMMM!w1}'
t 'f1}c1}YOU ARE UNDER ATTACK BY AN UNIDENTIFIED CRAFT!w1}'
call BOUNTY1

BOUNTY1:
t 'f1}c1}COMBAT BRIDGE:			'gamer'			'enemy
if eshn = 0 then eshn = 'Unknown'
t 'n1}c3}A - Dispatch Fighters            c5}Fighters: c7}'fght'          c6}Craft:    c7}'eshn' ('eshp')'
if eshd = 0 then eshd = 'Unknown'
t 'c3}B - Dispatch Cruisers            c5}Cruisers: c7}'crus'          c6}Shields:    c7}'eshd  
t 'c3}C - Fire Weaponry'                               
t 'c3}D - InterSector Jump		 c5}Shields:  c7}'shld
t 'c3}S - Combat Scan'
t 'c3}Q - Quit to Main Bridge'
query 'n1}c1}Combat Option: '; ans = upper(result)
if ans = 'C' then do; call BTY1; end
if ans = 'D' then do; call MOVE; end
if ans = 'S' then do; call CSCAN; end
if ans = 'Q' then do; call SHIP1; end
if ans = 'B' then do; t 'n2}Cruisers can not be used in Ship-to-Ship Combatw1}'; call FIRE; end
if ans = 'A' then do; t 'n2}Fighters can not be used in Ship-to-Ship Combatw1}'; call FIRE; end
call FIRE

BTY1:
if scn = 0 then do; t 'n2}Do you know who your enemy is?w1}'; call BOUNTY1; end
t 'f1}c1}SHIP-TO-SHIP COMBAT SCREEN'
t 'n1}cc}Your Status:			    Opponent:'
t '   c6}Shields:   c7}'shld'                    c2}Shields:  c7}'eshd
t '   c6}Strength: c7}'gsh'                      c2}Strength: c7}'bsh
query 'n1}(Q-QUIT) ---> Fire Y/N: '; ans = upper(result)
if ans = 'N' then do; call BTY1; end
if ans = 'Q' then do; call BOUNTY1; end
t 'n2}Firing ...w1}'
ht = random(1,10)
hit = ht + ship
if hit > 7 then do; t 'n2}c5}. . . HIT!w1}'; hrt = random(1,10)
	dmg = swp * hrt
	bsh = bsh - dmg
	esh = bsh / 10; eshd = trunc(esh,0)
	if bsh < 1 then do; t 'n2}c6}You have destroyed the 'eshn'!w1}'; call EARN; end
	if bsh > 4  then do; call BTY2;	end
	if bsh = 1 then do; call BOARD; end
	if bsh = 2 then do; call BOARD; end
	if bsh = 3 then do; call BOARD; end
	if bsh = 4 then do; call BOARD; end
call BTY2
end
t 'n2}c3}. . . MISS!w1}'
call BTY2

BOARD:
t 'n2}Your Opponent Surrenders!w1}'
t 'n1}Boarding currently inactivew1}'
call EARN

EARN:
t 'f1}Congratulations ... you have defeated 'enemy'!w1}'
money = money + rwd
t 'n1}You have earned 'rwd' credits for your success!w1}'
call INSYS

BTY2:
t 'n2}c3}'enemy' is returning fire ...w1}'
hts = random(1,10)
htz = hts + eshp
if htz > 7 then do; t 'c1}n2}. . . HIT!w1}'; hur = random(1,10)
	dg = ewep * hur
	gsh = gsh - dg	
	esh = gsh / 10; shld = trunc(esh,0)
	if gsh < 1 then do; t 'n2}c6}Your ship has been destroyed!'; call DEAD; end 
	if gsh > 4  then do; call BTY1; end
	call BTY1
	end
t 'n2}c6}. . . MISS!w1}'
call BTY1

DEAD:
sendfile 'pfiles:UNI/DOX/DEAD'
money = 4000
ship = 1
swp = 1 
shld = 1
tech = 0
agri = 0
eqip = 0
guns = 0
slave = 0
torp = 0
fght = 0
crus = 0
tran = 0
area = 0
col = 0
gate = 0
trp = 0
ltime = date
wpn = 0
end = 25
call BYE

FIRE:
t 'f1}c1}Incoming fire ...w1}'
dam = random(1,10)
if dam = 7 then do; t ' n2}. . . HITw1}'; call BOUNTY1; end
t 'n2}. . . MISSw1}'
call BOUNTY1

CSCAN:
t 'n2} Scanning ...w1}'
if scn > 0 then do; call BOUNTY1; end
eny = random(1,7)
if eny = 1 then do; enemy = 'Argak'; eshp = 3; eshn = 'Cobra'; eshd = random(10,30); ewep = 2; scn = 1; gsh = shld * 10; bsh = eshd * 10; rwd = random(1,100); call BOUNTY1; end
if eny = 2 then do; enemy = 'Tor Amel'; eshp = 5; eshn = 'Viper'; eshd = random(15,40); ewep = 3; scn = 1; gsh = shld * 10; bsh = eshd * 10; rwd = 10000; call BOUNTY1; end
if eny = 3 then do; enemy = 'Doctor Morei'; eshp = 1; eshn = 'Yacht'; eshd = random(1,10); ewep = 1; scn = 1; gsh = shld * 10; bsh = eshd * 10; rwd = 5000; call BOUNTY1; end
if eny = 4 then do; enemy = 'Kerok'; eshp = 1; eshn = 'Rapier'; eshd = random(1,15); ewep = 1; scn = 1; gsh = shld * 10; bsh = eshd * 10; rwd = random(10,150); call BOUNTY1; end
if eny = 5 then do; enemy = 'Syn Ester'; eshp = 1; eshn = 'Sabre'; eshd = random(5,20); ewep = 2; scn = 1; gsh = shld * 10; bsh = eshd * 10; rwd = 7500; call BOUNTY1; end
if eny = 6 then do; enemy = 'The Sliver'; eshp = 2; eshn = 'Razor'; eshd = random(8,22); ewep = 2; scn = 1; gsh = shld * 10; bsh = eshd * 10; rwd = 0; call BOUNTY1; end
if eny = 7 then do; enemy = 'Wilhelm'; eshp = 1; eshn = 'Yacht'; eshd = random(1,10); ewep = 1; scn = 1; gsh = shld * 10; bsh = eshd * 10; rwd = random(1,100); call BOUNTY1; end
call BOUNTY1
end

FREETRD:
getuser 12; tx = result; ta = right(tx,2); tx = left(ta,1)
rnd = random(3,3,(tx))
if rnd = 1 then do; call FT1; end
if rnd = 2 then do; call FT2; end
if rnd = 3 then do; ftr = 'Jonas'; fagr = 20; ftc = 18; fraw = 31; call FT3; end
if rnd = 3 then do; ftr = 'Kronos'; fagr = 20; ftc = 18; fraw = 31; call FT3; end
if rnd = 3 then do; ftr = 'Smiley'; fagr = 20; ftc = 18; fraw = 31; call FT3; end
if rnd = 3 then do; ftr = 'Win Moore'; fagr = 20; ftc = 18; fraw = 31; call FT3; end
call FREETRD

FT3:
chk = random(1,3)
if chk = 2 then do; call FT4; end
if chk = 3 then do; call FT5; end
t ' f1}b1}n2}c3}INCOMING RADIO TRANSMISSION . . .n2}'
t 's1}c5}From: c7}'ftr
t ' n1}c3}I am searching for raw materials. Do you have any you wish to part with?'
query 'n1}c6}s0}(Y/N) Your Response: '; ans = upper(result)
if ans = 'N' then do; t 'n1}s1}Okay ... Thanks anyway!s0}w1}'; call INSYS; end 
if ans = 'Y' then do
	 t 'n1}Great ... How much do you want per item? '
	query 'n1}Your Answer: '; ans = upper(result)
	if ans > fraw then do; t 'n1}c3}s1}Too much for my pocket ... Thanks anyway!n2}... end transs0}w1}'; call INSYS; end
	prc = eqip
	tk = random(1,prc); eqip = eqip - tk; cst = tk * ans; money = money + cst
	t 'n1}Great ... I need 'tk' of them!w1}' 
	t 'n1}c1}Initiating transfer . . .w1}'
	t 'n1}. . . transfer complete!w1}'
	t 'n1}c3}s1}Nice doing business with you!n2}... end trans.w1}s0}'
call INSYS
end
call SHIP1

FT4:
t ' f1}b1}n2}c3}INCOMING RADIO TRANSMISSION . . .n2}'
t 's1}c5}From: c7}'ftr
t ' n1}c3}I am searching for technological goods. Do you have any you wish to part with?'
query 'n1}c6}s0}(Y/N) Your Response: '; ans = upper(result)
if ans = 'N' then do; t 'n1}s1}Okay ... Thanks anyway!s0}w1}'; call INSYS; end 
if ans = 'Y' then do
	 t 'n1}Great ... How much do you want per item? '
	query 'n1}Your Answer: '; ans = upper(result)
	if ans > ftc then do; t 'n1}c3}s1}Too much for my pocket ... Thanks anyway!n2}... end transs0}w1}'; call INSYS; end
	prc = tech
	tk = random(1,prc); tech = tech - tk; cst = tk * ans; money = money + cst
	t 'n1}Great ... I need 'tk' of them!w1}' 
	t 'n1}c1}Initiating transfer . . .w1}'
	t 'n1}. . . transfer complete!w1}'
	t 'n1}c3}s1}Nice doing business with you!n2}... end trans.w1}s0}'
call INSYS
end
call SHIP1

FT5:
t ' f1}b1}n2}c3}INCOMING RADIO TRANSMISSION . . .n2}'
t 's1}c5}From: c7}'ftr
t ' n1}c3}I am searching for farm goods. Do you have any you wish to part with?'
query 'n1}c6}s0}(Y/N) Your Response: '; ans = upper(result)
if ans = 'N' then do; t 'n1}s1}Okay ... Thanks anyway!s0}w1}'; call INSYS; end 
if ans = 'Y' then do
	 t 'n1}Great ... How much do you want per item? '
	query 'n1}Your Answer: '; ans = upper(result)
	if ans > fagr then do; t 'n1}c3}s1}Too much for my pocket ... Thanks anyway!n2}... end transs0}w1}'; call INSYS; end
	prc = agri
	tk = random(1,prc); agri = agri - tk; cst = tk * ans; money = money + cst
	t 'n1}Great ... I need 'tk' of them!w1}' 
	t 'n1}c1}Initiating transfer . . .w1}'
	t 'n1}. . . transfer complete!w1}'
	t 'n1}c3}s1}Nice doing business with you!n2}... end trans.w1}s0}'
call INSYS
end
call SHIP1

FT1:
t 'f1}b1}n2}c3}INCOMING MESSAGE . . .n2}'
t 's1}c5}From: c7}Quarrak'
slv = random(10,200); slc = slv * 5
t 'n1}c3}   I have 'slv' Slaves available for purchase.'
t 'n1}Would you be interested in purchasing them for 'slc'cr.s1}'
query 'n1}c6}Enter Answer: '; ans = upper(result)
if left(ans,1) = 'N' then do; t 'n2}s1}Okay ... Thanks anyway!s0}'; call SHIP1; end
if left(ans,1) = 'Y' then do; call FTA; end
t 'n2}Try Yes or No'
query 'n1}Enter Answer: '; ans = upper(result)
if left(ans,1) = 'N' then do; t 'n2}s1}Okay ... Thanks anyway!s0}'; call SHIP1; end
if left(ans,1) = 'Y' then do; call FTA; end
t 'n2}Forget it!s0}'
call INSYS

FTA:
t 'n2}s1}c1}Initiating transfer . . .w1}'
t 'n1}c2}. . . Transfer completew1}'
slave = slave + slv; money = money - slc
t guns'g1}'
if guns > 0 then do; t 'n2}c3}Do You have any guns for sale?s0}'
	query 'n1}c6}Your Answer: '; ans = upper(result)
	if left(ans,1) = 'N' then do; t 's1}n1}c3}Nice doing business with you ... s0}w1}'; call INSYS; end
	query 'n1}s1}c3}How many are available: '; avl = upper(result)
	query 'n1}s1}c3}How much do you want: '; cst = upper(result)
	oky = cst / avl
	if oky > 7 then do; t 'n2}s1}c3}Too much for me ...s0}'; call INSYS; end
	t 'n2}s1}c3}OK ... I will take them!s0}'
	guns = guns - avl; money = money + cst
	end
t 'n1}c3}Nice doing business with you ... s0}w1}'
call SHIP1 

FT2:
t 'f1}b1}n2}c3}INCOMING MESSAGE . . .n2}'
t 's1}c5}From: c7}Sthiss'
gns = random(25,400); slc = slv * 15
t 'n1}c3}   I have 'gns' weapons available for purchase.'
t 'n1}Would you be interested in purchasing them for 'slc'cr.s1}'
query 'n1}c6}Enter Answer: '; ans = upper(result)
if left(ans,1) = 'N' then do; t 'n2}s1}c3}Okay ... Thanks anyway!s0}'; call SHIP1; end
if left(ans,1) = 'Y' then do; call FTB; end
t 'n2}Try Yes or No'
query 'n1}c6}Enter Answer: '; ans = upper(result)
if left(ans,1) = 'N' then do; t 'n2}s1}c3}Okay ... Thanks anyway!s0}'; call SHIP1; end
if left(ans,1) = 'Y' then do; call FTB; end
t 'n2}c3}Forget it!s0}'
call INSYS

FTB:
t 'n2}s1}c1}Initiating transfer . . .w1}'
t 'n1}c2}. . . Transfer completew1}'
guns = guns + gns; money = money - slc
if slave > 0 then do; t 'n2}c3}Do You have any slaves for sale?s0}'
	query 'n1}c6}Your Answer: '; ans = upper(result)
	if left(ans,1) = 'N' then do; t 's1}n1}c3}Nice doing business with you ... s0}w1}'; call INSYS; end
	query 'n1}s1}c3}How many are available: '; avl = upper(result)
	query 'n1}s1}c3}How much do you want: '; cst = upper(result)
	oky = cst / avl
	if oky > 7 then do; t 'n2}s1}c3}Too much for me ...s0}'; call INSYS; end
	t 'n2}s1}c3}OK ... I will take them!s0}'
	slave = slave - avl; money = money + cst
	end
t 'n1}c3}Nice doing business with you ... s0}w1}'
call SHIP1 
