Wednesday, 14 October 2009

Big code push this week - The TState Class

The bulk of the art assets required for the demo are complete. I'm busy adding code to populate the battlespace with helicopters and tanks. Essentially the Classes (in OOP terms) that upon creation of a new vehicle loads any required models, adds it to the overall TGame class, sets up initial state of the aircraft or vehicle (cold, engine running, where it is etc.).

In code, if a new THelicopter is created, it will magically appear in the 3D world in the state is was created. Now helicopters can be spawned by .SCN scene files, mission files, campaign engine or from the network when the multiplayer code is installed. I'm using a generic fixed sized TState class to record the status of each helicopter, jumping from helo to helo will transfer the state of that helicopter to you, or send it to your co-pilot, the parent Helicopter object contains information on who has authority over the helicopter.

I've fixed it so there are currently light switches and 8 MFD modes and 8 sub modes. Its easy to extend or reduce this as required. For the VCR feature I can store this state every 500 milliseconds in an external track file. Two doors and two it really necessary to send wiper information? Possibly not, these things are always subject to change, for now it stays.

The TState Class...

Type TState

Field Landed:Int = True
Field PowerDown:Int = True
Field CurrentMode:Int = MODE_COLD
Field LastMode:Int = MODE_COLD {Hidden}
Field LastModeChangeTime:Long ' Game time mode was changed
Field CurrentPosition:TVec3
Field CurrentRotation:TVec3
Field CurrentVelocity:TVec3
Field HUDmode:Int = 0
Field NightVision:Int = 0 
Field WeaponMode:Int = 0
Field WeaponSubMode:Int = 0 
Field MFDmode:Int[MAX_MFD_SLOTS]
Field MFDsubmode:Int[MAX_MFD_SLOTS]
Field LightStatus:Int[MAX_LIGHT_SLOTS] ' Up to 8 lights can be toggled
Field Door1Open:Int = False
Field Door2Open:Int = False
Field Wipers1:Int = False
Field Wipers2:Int = False

Method New()
  Self.MFDmode = New Int[MAX_MFD_SLOTS]
  Self.MFDsubmode = New Int[MAX_MFD_SLOTS]
  Self.LightStatus = New Int[MAX_LIGHT_SLOTS]
End Method

End Type

The TVehicle class and TVehicleState class have yet to be written but will be simplified versions of the THelicopter classes as we're not interested in those to any high degree of fidelity. What matters is they move when they are ordered to move and try to keep in a reasonable formation when asked using an A* path-finding function.

No comments:

Post a Comment