As discussed in the introduction (Chapter 1), most approaches to modelling real-world phenomena in virtual worlds aim to develop accurate, error-free models. These models are usually developed for the purposes of simulating natural disasters (e.g.
forest fires) or visually realistic effects (e.g. smoke or fluid flow), using complex equations. However, these computationally-expensive, complex methods are not needed in game worlds, where the emphasis is on credible and acceptable behaviour, rather than accurate and error-free simulation. Games worlds only need to approximately model reality for the purposes of entertainment. Forsyth (2002) has identified ways in which environmental processes can be simplified for games using cellular automata and has formulated some example equations for these processes in human-sized (e.g. first-person shooter) games. In this section, Forsyth’s equations for heat, pressure, fluid flow and fire are summarised.
4.2.1 Heat
Forsyth (2002) discusses three different mechanisms for transmitting heat through the environment: conduction, convection and radiation. In conduction, neighbouring cells pass heat to each other until they reach the same temperature (see Figure 4.1). Forsyth also describes mechanisms for convection (heat rises) and radiation (hot objects emit light).
// Find current heat capacities
float HCCell = cell->material->SHC * cell->Mass;
float HCNeigh = neigh->material->SHC * neigh->Mass;
float EnergyFlow = neigh->Temp – cell->Temp;
// Convert from heat to energy if (EnergyFlow > 0.0f)
EnergyFlow *= HCNeigh;
else
EnergyFlow *= HCCell;
// A constant according to cell update speed.
// Usually found by trial and error.
EnergyFlow *= ConstantEnergyFlowFactor;
Neigh->Temp -= EnergyFlow / HCNeigh;
Cell->Temp += EnergyFlow / HCCell;
// Detect and kill oscillations.
if (((EnergyFlow>0.0f)&&(neigh->Temp<cell->Temp)) ||
((EnergyFlow<=0.0f)&&(neigh->Temp>cell->Temp))) {
float TotalEnergy = HCCell * cell->Temp + HCNeigh * neigh->Temp;
float AverageTemp = TotalEnergy / (HCCell + HCNeigh);
cell->Temp = AverageTemp;
neigh->Temp = AverageTemp;
}
Figure 4.1. Equations for heat. Neighbouring cells pass heat to each other until they reach the same temperature (reproduced from Forsyth, 2002, p. 209)
4.2.2 Pressure
Forsyth (2002) provides a general algorithm for diffusion, which calculates the difference in pressure between a cell and its neighbour and divides that amount by the number of neighbours (see Figure 4.2).
for (neigh = each neighbour cell) {
if (neigh->Material->IsInert( ) ) continue;
float DPress = cell->Pressure – neigh->Pressure;
float Flow = cell->Material->Flow * DPress;
Flow = clamp (Flow, Cell->Pressure / 6.0f, -neigh->Pressure / 6.0f );
cell->NewPressure -= Flow;
neigh->NewPressure += Flow;
}
Figure 4.2. Equations for pressure diffusion. Pressure is divided equally between a cell and its neighbours (reproduced from Forsyth, 2002, p. 205)
4.2.3 Fluid Flow
The equations for fluid flow suggested by Forsyth (2002) are based on his general equations for pressure diffusion (see Figure 4.2). However, fluid is made compressible, so that fluid at greater depth seems to have greater pressure (more fluid stored in the same space). The compression property allows water to behave realistically in three dimensions (see Figure 4.3).
if (neighbour cell is above this one) {
if ( ( cell->Mass < material->MaxMass ) ||
(neigh->MaxMass < material->MaxMass ) ) {
Flow = cell->Mass – material->MaxMass;
}else{
Flow = cell->Mass – neigh->Mass - material->MaxCompress;
Flow *= 0.5f;
}
else if ( neighbour cell is below this one ) {
if ( ( cell->Mass < material->MaxMass ) ||
(neigh->Mass < material->MaxMass ) ) {
Flow = material->MaxMass – neigh->Mass;
} else {
Flow = cell->Mass – neigh->Mass + material->MaxCompress;
Flow *= 0.5f;
} }
else // neighbour is on same level {
Flow = (cell->Mass – neigh->Mass ) * 0.5f;
}
Figure 4.3. Equations for fluid flow. Fluid is made compressible so that water at greater depths has more pressure (reproduced from Forsyth, 2002, p. 207)
4.2.4 Fire
Forsyth (2002) notes that the process of burning materials is extremely complex and identifies that the best results are given by using a function that shows the amount of heat energy that is released per unit of time when a material burns at a certain temperature. In order to model burning in real-time the materials need to be reduced to their main characteristics. With Forsyth’s approach, the two variables maximum
burning rate and burning temperature can be tweaked to allow the burning of any material to be simulated.
float Temp = cell->Temp – material->Flashpoint;
// Damage the cell
CellDamage = Temp * material->BurnRate;
float Burn;
// Convert to actual burning value.
if (Temp > material->MaxBurn * 2 ) Burn = material->MaxBurn;
else
Burn = ( 1.0f – ( 0.25f * Temp / material->MaxBurn ) ) * Temp;
ASSERT ( Burn <= material->MaxBurn );
ASSERT ( Burn >= 0.0f );
// And heat the cell up from the burning.
Cell->Temp += Burn * material->BurnTemp;
Figure 4.4. Equations for burning. Burning can be reduced to the amount of heat energy that is released per unit of time when a material burns at a certain temperature (reproduced from Forsyth, 2002, p. 211)
4.2.5 Limitations
The equations discussed by Forsyth (2002) provide a foundation for developing a game world based on cellular automata. However, there is a need to develop these equations into a full world model that includes structure, as well as means for integrating the individual components and updating the game world. Also, the equations need to be developed into complete algorithms and adapted to strategy games, as opposed to human-sized games. Finally, extensive tuning is required to ensure the behaviour of the system meets requirements. Consequently, the aim of this study was to develop and tune such a system, which is discussed in the following sections.