This file contains the functions used for the actual running of a simulation and the functions used to determine outcomes of events based on probabilities.
success
Type: int
Inputs: float percentage, int verbose, FILE * pFile
This function will take a percentage chance of success for an event and return a 1 if the event is successful or a 0 if the event is unsuccessful.
If verbose is 1 then the function will print the random number it generates (between 0 and 100) to the input file.
get_random
Type: float
Inputs: int verbose, FILE * pFile
This function generates a random number between 0 and 100.
If verbose is 1 then the function will print the random number it generates to the input file.
update_position
Type:void
Inputs: testShip * pship, float timestep
This function updates the position of the ship passed to it using the current speed and heading of the ship and the time elapsing.
At the moment ship speed is given in knots and the x-y system for ship positions is in yards so the function converts between the two. In the rendering code one unit of distance is equal to 100 feet so a different conversion factor will be required when this code is integrated with graphics.
ship_can_fire
Type: void
Inputs: Guns * pshipAguns, cartCoords shipAposition, cartCoords shipAheading, float range, cartCoords shipBposition
This function checks whether a battery of guns is able to fire at the current time when passed a target ship. The only information needed about the target is it's location (shipBposition).
To fire, the following conditions must be met:
The function updates the canfire property of the guns to a 1 or a 0 depending on whether the guns can fire or if they cannot. The firingguns property is also updated to give the number of guns that will fire if possible.
salvo_hit_check_and_resolve
Type: void
Inputs: char * shipAname, Guns * pshipAguns, testShip * pshipB, FILE * pFile, float time_now, float timestep
update_sinking
Type: void
Inputs: testShip * pship, float timestep
If the ship is sinking this function decrements the time until it sinks by the elapsed time.
If this time reaches 0 then the ship is destroyed and its current_status property is updated to sunk.
check_damage_counter
Type: void
Inputs: testShip * pship
This checks the cumulative damage done to the ship. If the ship's damage counter ('health') is reduced to 0 then the ship is destroyed and its current_status property is updated to smoking_wreck.
write_update
Type: void
Inputs: FILE * pFile, testShip * pship