here is my source... it is slightly more complex than this, because it is not just one type... but here is the source... i really wanted to do it the way that i placed as my example because it is a far more elegant solution... anyway here it is
Type WeaponList
Field WeaponName$
Field WeaponType$
Field Damage
Field Speed
Field AirDamage
Field NextWeapon.WeaponList
End Type
Type UnitData
Field Speed
Field Armor$
Field UnitType$
Field Health
Field Transport
Field TransportSpace
Field Space
Field Detector
End Type
Type Unit
Field Name$
Field NumWeapons
Field ImgSm,ImgLg
Field Weapons.WeaponList
Field UnitData.UnitData
End Type
Function LoadUnit.Unit(FileName$)
state = 0
file = False
this.Unit = Null
in = ReadFile(FileName$)
ln$ = ""
While Not ln$ = "#END"
ln$ = EatWhite$(ReadLine$(in))
If Left$(ln$,2) <> "//"
Select(state)
Case 0:
If Instr(ln$,"#HEADER") And file = False Then state = 1
If Instr(ln$,"#CORE") Then state = 2
If Instr(ln$,"#UNITWEAPONS") Then state = 3
If Instr(ln$,"#UNITDATA") Then state = 4
Case 1:
If Instr(ln$,"FILETYPE") And file = False
If Right$(ln$,Instr(ln$,"=")-2) = "UNITFILE"
file = True
this = New Unit
this\UnitData = New UnitData
EndIf
EndIf
If Instr(ln$,"VERSION")
If Not Right$(ln$,Instr(ln$,"=")-5) = VS_UNITFILE Then RuntimeError("Fileversion was not current " + Right$(ln$,Instr(ln$,"=")-5))
EndIf
If Instr(ln$,"#ENDHEADER") Then state = 0
Case 2:
If Instr(ln$,"UNITNAME") And file = True
this\Name$ = Right$(ln$,Instr(ln$,"=")-5)
EndIf
If Instr(ln$,"NUMWEAPONS") And file = True
this\NumWeapons = Right$(ln$,Instr(ln$,"=")-5)
this\Weapons = New WeaponList
w.WeaponList = this\Weapons
For i = 1 To NumWeapons-1
w\NextWeapon = New WeaponList
w = w\NextWeapon
Next
EndIf
If Instr(ln$,"IMGSM") And file = True
this\ImgSm = LoadImage(Right$(ln$,Instr(ln$,"=")-5))
EndIf
If Instr(ln$,"IMGLG") And file = True
this\ImgLg = LoadImage(Right$(ln$,Instr(ln$,"=")-5))
EndIf
If Instr(ln$,"#ENDCORE") Then state = 0
Case 3:
w.WeaponList = this\Weapons
If Instr(ln$,"WEAPON")
w\WeaponName$ = Right$(ln$,Instr(ln$,":")-2)
EndIf
If Instr(ln$,"TYPE")
w\WeaponType$ = Right$(ln$,Instr(ln$,"=")-5)
EndIf
If Instr(ln$,"DAMAGE")
w\Damage = Right$(ln$,Instr(ln$,"=")-5)
EndIf
If Instr(ln$,"SPEED")
w\Speed = Right$(ln$,Instr(ln$,"=")-5)
EndIf
If Instr(ln$,"AIRDAMAGE")
w\AirDamage = Right$(ln$,Instr(ln$,"=")-5)
EndIf
If Instr(ln$,"]") And w\NextWeapon <> Null Then w = w\NextWeapon
If Instr(ln$,"#ENDUNITWEAPONS") Then state = 0
Case 4:
If Instr(ln$,"SPEED")
this\UnitData\Speed = Right$(ln$,Instr(ln$,"=")-5)
EndIf
If Instr(ln$,"ARMOR")
this\UnitData\Armor$ = Right$(ln$,Instr(ln$,"=")-5)
EndIf
If Instr(ln$,"HEALTH")
this\UnitData\Health = Right$(ln$,Instr(ln$,"=")-5)
EndIf
If Instr(ln$,"TYPE")
this\UnitData\UnitType$ = Right$(ln$,Instr(ln$,"=")-5)
EndIf
If Instr(ln$,"TRANSPORT")
this\UnitData\Transport = Right$(ln$,Instr(ln$,"=")-5)
EndIf
If Instr(ln$,"CARGOSPACE")
this\UnitData\TransportSpace = Right$(ln$,Instr(ln$,"=")-5)
EndIf
If Instr(ln$,"SPACE")
this\UnitData\Space = Right$(ln$,Instr(ln$,"=")-5)
EndIf
If Instr(ln$,"DETECTOR")
this\UnitData\Detector = Right$(ln$,Instr(ln$,"=")-5)
EndIf
If Instr(ln$,"#ENDUNITDATA") Then state = 0
Default:
End Select
EndIf
Wend
Return this
End Function
if you see anything that iv done that is wrong... please feel free to comment but what im really after is suggestions on how to do the WeaponList, as i would like a solution that is very friendly(lol) thanks
|