Thanks again Pip.
Got it. So if I understand the code correctly, BA2 uses
age as a counter (which it stores in
ObjectData for each smoke cloud). It then checks a binary AND so that every other turn it will run the test to randomly remove smoke.
So there's a 25% chance of the smoke disappearing after 2 turns, 50% after 4, 75% after 6, and after 8 turns it's definitely gone...
I assume it runs this test independently for each 'unit' of smoke, so that an artillery barrage of smoke will gradually dissipate at different times, not all en masse?... Elegant guys! Nice
Code: Select all
FUNCTION Smoke_StartTurn(objectid, user)
{
int age ;
int odd ;
age = GetObjectData(objectid, 0) ;
age += 1 ;
SetObjectData(objectid, 0, age) ;
odd = age & 1;
if (odd == 0)
{
// every pair of turns, chance of smoke removal increases by 25%
age /= 2 ;
age *= 25 ;
if (Rand(0, 99) < age)
{
AddVizFunctionCall("DeleteObject", objectid) ;
}
}
}