Skip to content

Instantly share code, notes, and snippets.

@hoehrmann
Created June 5, 2013 12:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hoehrmann/5713444 to your computer and use it in GitHub Desktop.
1997 utility that reads TIE Fighter .tie mission files and prints out the mission's goals, especially the bonus goals and their score which are not available in-game.
uses tierec,strngtol;
type
fgdesk=record
name:string;
typ:string;
end;
var f:file;
header:fheader;
fg:flightgroup;
msg:message;
gblgoals:array[1..3] of globalgoals;
i:integer;
primgoal:array[1..24] of string[80];
secgoal:array[1..24] of string[80];
bonusgoal:array[1..24] of string[80];
pgcount,sgcount,bgcount:integer;
strings:stringz;
fgdesc:array[1..99] of fgdesk;
fgdescnum:integer;
res_x:array[0..974] of byte;
{--------------------------------------------}
procedure setFGStrings;
function cl(s:string):string;
begin
while pos(#0,s)<>0 do delete(s,pos(#0,s),1);
cl:=s;
end;
begin
strings.name:=fg.name;
strings.name:=cl(strings.name);
strings.typ:=ShipDesc(fg.typ);
strings.typ:=cl(strings.typ);
fgdesc[fgdescnum].name:=strings.name;
fgdesc[fgdescnum].typ:=strings.typ;
inc(fgdescnum);
end;
{--------------------------------------------}
function getGenTyp(gen:byte):string;
begin
case gen of
0:getGenTyp:='Unknown 0';
1:getGenTyp:='FlightGroup';
2:getGenTyp:='Unknown 2';
3:getGenTyp:='Unknown 3';
4:getGenTyp:='Unknown 4';
5:getGenTyp:='Unknown 5';
6:getGenTyp:='Unknown 6';
7:getGenTyp:='Unknown 7';
end;
end;
{--------------------------------------------}
function IffCode(iff:byte):string;
var s:string;
begin
case iff of
0:s:='Rebel';
1:s:='Imperial';
2:s:=header.iff1;
3:s:=header.iff2;
4:s:=header.iff3;
5:s:=header.iff4;
end;
while pos(#0,s)<>0 do delete(s,pos(#0,s),1);
if iff=2 then delete(s,1,1);
Iffcode:=s;
end;
{--------------------------------------------}
function getanz(nr:byte):string;
begin
case nr of
0:begin if fg.num=1 then getanz:='' else getanz:='100% of ';end;
1:getanz:='50% of ';
2:getanz:='At least one of ';
3:getanz:='All but one of ';
4:begin
if fg.specrand<>0 then getanz:='?'
else getanz:=st(fg.specraft);
end;
5:getanz:='100% of ';
6:getanz:='75% of ';
7:getanz:='50% of ';
8:getanz:='25% of ';
9:getanz:='At least one of ';
10:getanz:='All but one of ';
end;{case}
end; {-->Getanz}
function getaction(act:byte):string;
begin
case act of
00:getaction:='always';
01:getaction:='must have arrived';
02:getaction:='must be destroyed';
03:getaction:='must be attacked';
04:getaction:='must be captured';
05:getaction:='must be inspected';
06:getaction:='must be boarded';
07:getaction:='must have finished docking';
08:getaction:='must be disabled';
09:getaction:='must have survived';
10:getaction:='not specified';
12:getaction:='must have completed mission';
19:getaction:='must be dropped off';
20:getaction:='must be reinforced';
21:getaction:='must be inspected or captured';
22:getaction:='must been boarded';
else getaction:='**--FUCKED--**';
end;{case}
end;{-->getaction}
function bonuspoints(b:byte):string;
begin
if b<=$7f then bonuspoints:=st(b*50)
else if b>=$88 then bonuspoints:='-'+st((b-$88)*50)
else bonuspoints:='-'+st((b)*50);
end;
{--------------------------------------------}
procedure setgoal;
begin
if fg.difflevel in [1,3] then exit;
if fg.actprimgoal<>10 then begin
if fg.numprimgoal=4 then
primgoal[pgcount]:=strings.typ+' '+strings.name+' '+Getanz(fg.numprimgoal)+' '+Getaction(fg.actprimgoal)+'.'
else primgoal[pgcount]:=Getanz(fg.numprimgoal)+strings.typ+' '+strings.name+' '+Getaction(fg.actprimgoal)+'.';
inc(pgcount);
end;{Primgoals}
if fg.actsecgoal<>10 then begin
if fg.numsecgoal=4 then
secgoal[sgcount]:=strings.typ+' '+strings.name+' '+Getanz(fg.numsecgoal)+' '+Getaction(fg.actsecgoal)+'.'
else secgoal[sgcount]:=Getanz(fg.numsecgoal)+strings.typ+' '+strings.name+' '+Getaction(fg.actsecgoal)+'.';
inc(sgcount);
end;{Secgoals}
if fg.actbonusgoal<>10 then begin
if fg.numprimgoal=4 then
bonusgoal[bgcount]:=strings.typ+' '+strings.name+' '+Getanz(fg.numbonusgoal)+' '+Getaction(fg.actbonusgoal)+'.'
else bonusgoal[bgcount]:=Getanz(fg.numbonusgoal)+strings.typ+' '+strings.name+' '+Getaction(fg.actbonusgoal)+
' ('+bonuspoints(fg.bonuspoints)+')'+'.';
inc(bgcount);
end;{Bonusgoals}
end;
{--------------------------------------------}
function GBGoalBuilt(cond,gen,ext,num:byte):string;
var s:string;
_cond,_gen,_ext,_num:string;
begin
GBGoalBuilt:='';
if (cond=0) or (cond=10) then exit;
_cond:=GetAction(cond);
_num:=GetAnz(num+5);
case gen of
1:begin
_gen:='FlightGroup';
_ext:=fgdesc[ext].name;
end;
2:begin
_gen:='Ship Type';
_ext:=ShipDesc(ext);
end;
5:begin
_gen:='IFF';
_ext:=IffCode(ext)+' Craft';
end;
else begin
_gen:='Unknown';
_ext:='Unknown';
end;
end;
s:=_num+'all '+_ext+' '+_cond;
GBGoalBuilt:=S;
end;
{--------------------------------------------}
procedure setGlobalGoals;
begin
with strings do begin
gblpg1:=GBGoalBuilt(GBLGoals[1].cond1,GBLGoals[1].gentyp1,GBLGoals[1].exttyp1,GBLGoals[1].numtyp1);
gblpg2:=GBGoalBuilt(GBLGoals[1].cond2,GBLGoals[1].gentyp2,GBLGoals[1].exttyp2,GBLGoals[1].numtyp2);
if GBLGoals[1].op=0 then gblpgo:='AND'
else gblpgo:='OR';
gblsg1:=GBGoalBuilt(GBLGoals[2].cond1,GBLGoals[2].gentyp1,GBLGoals[2].exttyp1,GBLGoals[2].numtyp1);
gblsg2:=GBGoalBuilt(GBLGoals[2].cond2,GBLGoals[2].gentyp2,GBLGoals[2].exttyp2,GBLGoals[2].numtyp2);
if GBLGoals[2].op=0 then gblpgo:='AND'
else gblpgo:='OR';
gblbg1:=GBGoalBuilt(GBLGoals[3].cond1,GBLGoals[3].gentyp1,GBLGoals[3].exttyp1,GBLGoals[3].numtyp1);
gblbg2:=GBGoalBuilt(GBLGoals[3].cond2,GBLGoals[3].gentyp2,GBLGoals[3].exttyp2,GBLGoals[3].numtyp2);
if GBLGoals[3].op=0 then gblpgo:='AND'
else gblpgo:='OR';
end;
end;
{--------------------------------------------}
procedure OutPut;
procedure wo(s:string);
begin
if s<>'' then WriteLn(s);
end;
begin
with strings do begin
WriteLn(Paramstr(1));
WriteLn('---> Primary Goals <---');
wo(gblpg1);
if gblpg2<>'' then WriteLn(gblpgo);
wo(gblpg2);
for i:=1 to pgcount do WriteLn(Primgoal[i]);
(***)
if (gblsg1<>'') or (gblsg2<>'') or (sgcount>1) or (secgoal[1]<>'') then begin
WriteLn('---> Secondary Goals <---');
wo(gblsg1);
if gblsg2<>'' then WriteLn(gblsgo);
wo(gblsg2);
for i:=1 to sgcount do WriteLn(secgoal[i]);
end;
(***)
if (gblbg1<>'') or (gblbg2<>'') or (bgcount>1) or (bonusgoal[1]<>'') then begin
WriteLn('---> Bonus Goals <---');
wo(gblbg1);
if gblbg2<>'' then WriteLn(gblbgo);
wo(gblbg2);
for i:=1 to bgcount do WriteLn(bonusgoal[i]);
end;
end;
end;
begin
pgcount:=1;sgcount:=1;bgcount:=1;fgdescnum:=1;
assign(f,ParamStr(1));
reset(f,1);
blockRead(f,header,sizeof(header));
for i:=1 to header.unitcount do begin
{> Single FlightGroup Operations <}
BlockRead(f,fg,sizeof(fg));
setfgstrings;
setgoal;
{> Single FlightGroup Operations end <}
end;
for i:=1 to header.messagecount do begin
BlockRead(f,msg,sizeof(msg));
end;
blockRead(f,gblgoals[1],9);
seek(f,filepos(f)+19);
blockRead(f,gblgoals[2],9);
seek(f,filepos(f)+19);
blockRead(f,gblgoals[3],9);
blockRead(f,res_x,sizeof(res_x));
setGlobalGoals;
output;
(* WriteLn(filepos(f),'/',filesize(f)); *)
close(f);
end.
unit tierec;
interface
type
stringz=record
Name:string;
Typ:String;
iffid:String;
difflevel:String;
gblpg1:string;
gblpg2:string;
gblpgo:string;
gblsg1:string;
gblsg2:string;
gblsgo:string;
gblbg1:string;
gblbg2:string;
gblbgo:string;
end;
Fheader=record
ident:word;
unitcount:byte;
res1:byte;
messagecount:byte;
res2:array[0..4] of byte;
BriefPers:byte;
res3:array[0..12] of byte;
pgcompmsg1:array[0..62] of char;
res4:byte;
pgcompmsg2:array[0..62] of char;
res5:byte;
sgcompmsg1:array[0..62] of char;
res6:byte;
sgcompmsg2:array[0..62] of char;
res7:byte;
pgfailmsg1:array[0..62] of char;
res10:byte;
pgfailmsg2:array[0..62] of char;
res11:word;
iff1:array[0..10] of char;
res12:byte;
iff2:array[0..10] of char;
res13:byte;
iff3:array[0..10] of char;
res14:byte;
iff4:array[0..10] of char;
res15:word;
end;
order=record
order:byte;
speed:byte;
repnum:byte;
srepnum:byte;
res1:byte;
res2:byte;
gentyptgt1:byte;
exttyptgt1:byte;
gentyptgt2:byte;
exttyptgt2:byte;
res3:word;
gentyptgt3:byte;
exttyptgt3:byte;
gentyptgt4:byte;
exttyptgt4:byte;
res4:word;
end;
flightgroup=record
Name:array[0..10] of char;
res1:byte;
pilname:array[0..10] of char;
res2:byte;
cargo1:array[0..10] of char;
res3:byte;
cargo2:array[0..10] of char;
res4:byte;
specraft:byte;
specrand:byte;
Typ:byte;
num:byte;
stat:byte;
missle:byte;
beam:byte;
iffid:byte;
ailevel:byte;
color:byte;
radiocnt:byte;
res5:byte;
formation:byte;
res6:byte;
res7:byte;
res8:byte;
waves:byte;
res9:byte;
you:byte;
res10:array[0..5] of byte;
difflevel:byte;
arract1:byte;
gentyp1:byte;
exttyp1:byte;
res11:array[0..7] of char;
actdelay:byte;
res12:array[0..9] of char;
arrfgnum:byte;
arrhyp:byte;
depfgnum:byte;
dephyp:byte;
altarrfgnum:byte;
altarrhyp:byte;
altdepfgnum:byte;
altdephyp:byte;
orders:array[1..3]of order;
actprimgoal:byte;
numprimgoal:byte;
actsecgoal:byte;
numsecgoal:byte;
res13:byte;
res14:byte;
actbonusgoal:byte;
numbonusgoal:byte;
bonuspoints:byte;
res16:array[0..118] of char;
visonbrief:byte;
res17:array[0..4] of char;
end;
message=record
msg:array[0..62] of char;
res1:byte;
act1:byte;
gentyp1:byte;
exttyp1:byte;
op:byte;
act2:byte;
gentyp2:byte;
exttyp2:byte;
res2:byte;
shortid:array[0..14] of char;
res3:byte;
delay:byte;
res4:byte;
end;
globalgoals=record
cond1:byte;
gentyp1:byte;
exttyp1:byte;
numtyp1:byte;
cond2:byte;
gentyp2:byte;
exttyp2:byte;
numtyp2:byte;
op:byte;
end;
globaliffnames=record
iffnr1:array[0..10] of char;
sep1:byte;
iffnr2:array[0..10] of char;
sep2:byte;
iffnr3:array[0..10] of char;
sep3:byte;
iffnr4:array[0..10] of char;
sep4:byte;
end;
radiomessage=record
Message:array[0..62] of char;
res1:byte;
Type1:byte;
which1:byte;
exact1:byte;
op:byte;
Type2:byte;
which2:byte;
exact2:byte;
res2:byte;
msgid:array[0..14] of char;
res3:byte;
delay:byte;
res4:byte;
end;
globalgoal=record
condition1:byte;
crafttype1:byte;
ExactCraft:byte;
craftanz1:byte;
condition2:byte;
crafttype2:byte;
ExactCraf2:byte;
craftanz2:byte;
op:byte;
end;
orderrec=record
Mainorder:byte;
speed:byte;
res1:longint;
typetgt1:byte;
tgt1:byte;
typtgt2:byte;
tgt2:byte;
res2:word;
typtgt3:byte;
tgt3:byte;
typtgt4:byte;
tgt4:byte;
res3:word;
end;
oneship=record
name:array[0..10] of char;
res1:array[0..12] of byte;
cargo1:array[0..10] of char;
res2:byte;
cargo2:array[0..10] of char;
res3:byte;
speccraft:byte;
specraftrandom:byte;
Typ:byte;
anz:byte;
situation:byte;
rockets:byte;
beam:byte;
owner:byte;
rang:byte;
res5:byte;
speech:byte;
res6:byte;
formation:byte;
res7:array[0..2] of byte;
waves:byte;
res8:byte;
playerpos:byte;
res9:array[0..5] of byte;
level:byte;
incomsit:byte;
res10:byte;
fgforsit:byte;
res11:array[0..7] of char;
incomtime:byte;
res12:array[0..9] of char;
arrMother:byte;
arrMethod:byte;
depMother:byte;
depMethod:byte;
res13:longint;
order:array[1..3] of orderrec;
Primgoaltype:byte;
Anzprimgoaltype:byte;
Secgoaltype:byte;
Anzsecgoaltype:byte;
Secretgoaltype:byte;
Anzsecretgoaltype:byte;
BonusGoalType:byte;
AnzBonusGoalType:byte;
bonuspoints:byte;
res15:array[0..124] of byte;
end;
shipstrings=record
name:string[11];
cargo1:string[11];
cargo2:string[11];
speccraft:String[2];
Typ:String;
anz:string[2];
situation:string[32];
rockets:string[32];
beam:string[32];
owner:string[32];
rang:string[32];
speech:string[3];
formation:string[32];
waves:string[2];
playerpos:string[2];
level:String[10];
primgoaltype:string[50];
anzprimgoaltype:string[20];
secgoaltype:string[50];
anzsecgoaltype:string[20];
secretgoaltype:string[50];
anzsecretgoaltype:string[20];
bonusgoaltype:string[50];
anzbonusgoaltype:string[20];
bonuspoints:string[10];
end;
function ShipDesc(b:byte):String;
implementation
function ShipDesc(b:byte):String;
begin
case b of
1 : ShipDesc:='X-Wing';
2 : ShipDesc:='Y-Wing';
3 : ShipDesc:='A-Wing';
4 : ShipDesc:='B-Wing';
5 : ShipDesc:='TIE Fighter';
6 : ShipDesc:='TIE Interceptor';
7 : ShipDesc:='TIE Bomber';
8 : ShipDesc:='TIE Advanced';
9 : ShipDesc:='TIE Defender';
10 : ShipDesc:='TIE New 1';
11 : ShipDesc:='TIE New 2';
12 : ShipDesc:='Missile Boat';
13 : ShipDesc:='TIE New 4';
14 : ShipDesc:='Z-95 Headhunter';
15 : ShipDesc:='Star Fighter 2';
16 : ShipDesc:='Assault Gunboat';
17 : ShipDesc:='Shuttle';
18 : ShipDesc:='Escort Shuttle';
19 : ShipDesc:='Patrol Craft 1';
20 : ShipDesc:='Patrol Craft 2';
21 : ShipDesc:='Transport';
22 : ShipDesc:='Assault Transport';
23 : ShipDesc:='New Transport 2';
24 : ShipDesc:='Tug';
25 : ShipDesc:='New Tug';
26 : ShipDesc:='Container A';
27 : ShipDesc:='Container B';
28 : ShipDesc:='Container C';
29 : ShipDesc:='Container D';
30 : ShipDesc:='Heavy Lifter';
31 : ShipDesc:='Bulk Barge';
32 : ShipDesc:='Freighter';
33 : ShipDesc:='Cargo Ferry';
34 : ShipDesc:='Modular Conveyer';
35 : ShipDesc:='Con Transport';
36 : ShipDesc:='New Freighter 3';
37 : ShipDesc:='New Freighter 4';
38 : ShipDesc:='Corellian Transport';
39 : ShipDesc:='Millenium';
40 : ShipDesc:='Corvette';
41 : ShipDesc:='Modified Corvette';
42 : ShipDesc:='Nebulon-B Frigate';
43 : ShipDesc:='Modified Frigate';
44 : ShipDesc:='Star Galleon';
45 : ShipDesc:='Carrack Cruiser';
46 : ShipDesc:='Strike Cruiser';
47 : ShipDesc:='Escort Carrier';
48 : ShipDesc:='Dreadnaught';
49 : ShipDesc:='Calamari';
50 : ShipDesc:='Light Calamari';
51 : ShipDesc:='Interdictor';
52 : ShipDesc:='V-Class SD';
53 : ShipDesc:='Star Destroyer';
54 : ShipDesc:='Super Destroyer';
55 : ShipDesc:='Container E';
56 : ShipDesc:='Ship 2';
57 : ShipDesc:='Ship 3';
58 : ShipDesc:='Ship 4';
59 : ShipDesc:='Ship 5';
60 : ShipDesc:='Platform A';
61 : ShipDesc:='Platform B';
62 : ShipDesc:='Platform C';
63 : ShipDesc:='Platform D';
64 : ShipDesc:='Platform E';
65 : ShipDesc:='Platform F';
66 : ShipDesc:='Platform 7';
67 : ShipDesc:='Platform 8';
68 : ShipDesc:='Platform 9';
69 : ShipDesc:='Platform 10';
70 : ShipDesc:='Satellite';
71 : ShipDesc:='Satellite 2';
72 : ShipDesc:='Satellite 3';
73 : ShipDesc:='Satellite 4';
74 : ShipDesc:='Satellite 5';
75 : ShipDesc:='Mine Type A';
76 : ShipDesc:='Mine Type B';
77 : ShipDesc:='Mine Type C';
78 : ShipDesc:='Mine 4';
79 : ShipDesc:='Mine 5';
80 : ShipDesc:='Probe Type A';
81 : ShipDesc:='Probe Type B';
82 : ShipDesc:='Probe 3';
83 : ShipDesc:='Buoy 1';
84 : ShipDesc:='Buoy 2';
85 : ShipDesc:='Space Objects';
else ShipDesc:='Unbekannt';
end;
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment