Hi I have a tank with 5 turrets and instead of writing out the info for all turrets within the type Id like to do an array of turret types within the tank type.
How would I do this?
How would I do this?
Type turretType Field rotation# Field elevation# End Type Type tankType Field turrets.turretType[4] End Type tank.tanktype = New tanktype For n = 0 To 4 this.turretType = New turretType this\rotation = 45 this\elevation = 10 tank\turrets[n] = this Next
tank\turrets[3]\rotation = 90 tank\turrets[3]\elevation = 45
Type tankType tankName$ turret1_rot# turret1_ele# turret2_rot# turret2_ele# turret3_rot# turret3_ele# turret4_rot# turret4_ele# turret5_rot# turret5_ele# End Type
const MAX_TURRETS=5 type tank field tank_name$ field tank_x# field tank_y# field tank_z# field tank_rotation# field tank_number_of_turrets field turret_elevation#[MAX_TURRETS-1] field turret_rotation#[MAX_TURRETS-1] end type
Type turretType Field rotation# Field elevation# Field nextLink.turretType End Type Type tankType Field tankName$ Field totalTurrets% Field turretList.turretType End Type ; Create a tank. tank.tankType = New tankType tank\tankName$ = "Mega Crusher" ; Add 5 turrets with random rotation and elevation. For n = 1 To 5 add_turret(tank, Rand(360), Rand(45)) Next ; Display current tank settings. print_tank(tank) Print Print "Press a key to change rotation & elevation" Print "of turret 3 ..." Print WaitKey() ; Now change the rotation and elevation of turret 3. this.turretType = get_turret(tank, 3) this\rotation = 123 this\elevation = 456 ; Display new tank settings. print_tank(tank) WaitKey() ; Kill the tank. free_tank(tank) End ; ; Add a new turret to the specified tank. ; Function add_turret%(tank.tankType, rotation#=0, elevation#=0) ; Create a new turret type. newTurret.turretType = New turretType ; Set initial turret settings. newTurret\rotation = rotation newTurret\elevation = elevation ; Add turret to tank's linked list. newTurret\nextLink = tank\turretList tank\turretList = newTurret ; Increment the total count of turrets belonging to this tank. tank\totalTurrets = tank\totalTurrets + 1 Return tank\totalTurrets End Function ; ; Return a pointer to the specified tank turret. ; Function get_turret.turretType(tank.tankType, turretNo%) ; Return NULL pointer if turretNo is invalid. If (turretNo < 1) Or (turretNo > tank\totalTurrets) Then Return Null ; Walk along turret linked list until we reach the requested turret. this.turretType = tank\turretList For n = tank\totalTurrets-1 To turretNo Step -1 this = this\nextLink Next ; Return pointer to the requested turret type. Return this End Function ; ; free all memory used by a tank type. ; Function free_tank(tank.tankType) ; Free all the turrets. this.turretType = tank\turretList While this <> Null nextTurret.turretType = this\nextLink Delete this this = nextTurret Wend ; Free actual tank. Delete tank End Function ; ; Display settings of specified tank. ; Function print_tank(tank.tankType) Print "Tank Name : " + tank\tankName$ For n = 1 To tank\totalTurrets this.turretType = get_turret(tank, n) Print "Turret " + n + " : rotation=" + this\rotation + " elevation=" + this\elevation Next End Function
; ; Delete a turret from the specified tank. ; Function delete_turret%(tank.tankType, turretNo%) ; Return -1 if turretNo is invalid. If (turretNo < 1) Or (turretNo > tank\totalTurrets) Then Return -1 ; Walk along turret linked list until we reach the requested turret. this.turretType = tank\turretList prev.turretType = Null For n = tank\totalTurrets-1 To turretNo Step -1 prev = this this = this\nextLink Next ; Remove turret from linked list. If prev <> Null prev\nextLink = this\nextLink Else tank\turretList = this\nextLink EndIf ; Free the turret type. Delete this ; Decrease the total count of turrets belonging to this tank. tank\totalTurrets = tank\totalTurrets - 1 Return tank\totalTurrets End Function