Ordinarily, I would cover this process by providing code; however, I am going to go over the vehicle data script in this blog. In addition, I will cover a portion of a dummy load script, at least, the portion on how to access the player data (from a previous blog) and the vehicle data scripts.
The vehicle data script is very similar in design to the player data script. Its purpose is to store the vehicle's (usually a fighter) capabilities for other scripts. This script is very important to the flight control, fire control and countermeasure scripts. It also provides "benchmark" (the fighter's capabilites when it is undamaged) to the damage calculation routines. This allows for incremental deterioration of the ship's combat capabities.
Like the player data script, it consists of local variables, a load and find function, and a bunch of methods to access the local variables. So, we need to populate the player data and vehicle data scripts. I did this through a dummy load script. This script is a temporary script designed to load a player controlled viper with some default values. In the future, its functions will be handled by a resource manager. Here’s the script:
This script loads the player, vehicle, flight control, fire control, faction control and dradis control scripts; however, we’ll just look at the player and vehicle data. The actual viper has a player and vehicle script attached to it, along with the dummy load script. In order for a script to access another script, you have to create a reference to it. The statement “PlayerData vPlayerData = PlayerData.Find(vShip)” and the similar statement for VehicleData create that reference. (The variable “vShip” represents the viper model and was defined by the statement “Transform vShip = transform”.)
With the reference, the vVehicleDAta variable has direct access to the “VehicleData” script attached to the viper. Any changes made within the vVehicleData variable automatically update the script attached to the ship. The first manipulation of the vVehicleData is done in the statement “vVehicle.Load(…)”. If you look at the vehicle data script, the Load statement takes a bunch of strings and float values and places them into variables such as the main thrust and fuel capacity variables. The statement before the vehicle load statement loads player data values into the PlayerData script.
Other scripts are loaded in this dummy load script. For example, the statement following the vehicle data load handles the loading of data into the flight control script. The flight control script, unlike our two data scripts, actually manipulates the data. We’ll look at that script in a future blog...