I looked over the Command & Control Dynamic Weather object.
Here are the issues I fixed:
-------------------------
- The cloud height was instantiated as int; it must be float due to Mission.createClouds(float clouds, int height).
- The range of permitted cloud height was limited to 200m to 2,000m. The game actually applies limits of 300m to 5,000m; this has been fixed.
- The DWInterval variable, which sets the time interval between weather changes, had it read from the mission file's section [Main]. In this location the variable is not written by the relevant parent class when the file is altered within the game, and so disappears. It should be located in the [Mods] section of the .mis file, along with "BestClouds" and "WorstClouds"; here it survives file re-writing.
- Formerly worstClouds was set to a maximum of 7, but the actual maximum value is 6 (when the minimum is 0); that's been fixed.
I augmented the capabilities as follows:
-------------------------------------
- Formerly cloud height changes were always fixed at 200m. I now set the height change as a varying factor based on the starting cloud height. The higher the starting cloud height the larger the change in cloud height with each change in the weather. Furthermore, for any given starting cloud height the higher each subsequent change in weather the larger is the height change, and vice versa.
- Formerly cloud height changes were random irrespective of whether the weather worsened or improved. I made cloud height increase with better weather and vice versa.
- Formerly the interval between weather changes was fixed to a constant value of 20 minutes (which could not reliably be made to change, as noted above). I now randomize the interval to +/-1/3 of the set duration. For example, if set to 12 minutes the range will be randomly set to between 8 and 16 minutes.
- I added a check to see if the weather has actually changed (as before, 1/3 of the time it will not change, 1/3 of the time it will worsen and 1/3 of the time it will improve). If no change has been made methods Mission.createClouds() and World.land().cubeFullUpdate() are not called; this avoids an unnecessary re-draw. This also ensures that the mission starts with the weather and cloud height as set in the .mis file (and which the player expects.

)
Here's the original java:
package com.maddox.il2.objects.vehicles.stationary;
import com.maddox.il2.ai.World;
import com.maddox.il2.engine.Landscape;
import com.maddox.il2.game.Mission;
import com.maddox.rts.SectFile;
import com.maddox.sas1946.il2.util.TrueRandom;
// Referenced classes of package com.maddox.il2.objects.vehicles.stationary:
// CandCGeneric, CandC
public static class CandC$DynamicWeatherUnit extends CandCGeneric
{
public boolean danger()
{
int i = Mission.cur().sectFile().get("Main", "DWInterval", 20) * 60;
resetTimer(i);
int j = TrueRandom.nextInt(100);
if(j <= 33)
clouds++;
if(j > 33 && j < 66)
clouds--;
if(clouds < bestclouds)
clouds = bestclouds;
if(clouds > worstclouds)
clouds = worstclouds;
j = TrueRandom.nextInt(100);
if(j <= 33)
height += 200;
else
if(j > 33 && j < 66)
height -= 200;
else
if(height < 200)
height = 200;
else
if(height > 2000)
height = 2000;
if(Mission.cur() != null && start)
{
clouds = Mission.cur().sectFile().get("Main", "CloudType", 2);
height = Mission.cur().sectFile().get("Main", "CloudHeight", 1500);
}
if(Mission.cur() != null && start)
{
bestclouds = Mission.cur().sectFile().get("Mods", "BestClouds", 0);
if(bestclouds < 0 || bestclouds > 7)
bestclouds = 0;
}
if(Mission.cur() != null && start)
{
worstclouds = Mission.cur().sectFile().get("Mods", "WorstClouds", 7);
if(worstclouds < 0 || worstclouds > 7)
worstclouds = 7;
}
if(worstclouds <= bestclouds)
{
worstclouds = 7;
bestclouds = 0;
}
start = false;
Mission.createClouds(clouds, height);
World.land().cubeFullUpdate();
return true;
}
private int clouds;
private int height;
private int bestclouds;
private int worstclouds;
private boolean start;
public CandC$DynamicWeatherUnit()
{
clouds = 2;
height = 1500;
bestclouds = 0;
worstclouds = 7;
start = true;
super.Timer1 = super.Timer2 = 1200F;
}
}
Here's my version as of this moment:
// Augmented by WxTech
// Changed cloud height from int to float (IMPORTANT!)
// Made height change a varying factor based on the starting cloud height (formerly was always fixed to a 200m change)
// Made cloud height increase with better weather and vice versa
// Randomize the interval between weather changes to +/-1/3 of set duration, i.e., if set to 6 min the range is 4 to 8 min
package com.maddox.il2.objects.vehicles.stationary;
import com.maddox.il2.ai.World;
import com.maddox.il2.engine.Landscape;
import com.maddox.il2.game.HUD; //when using HUD.training output
import com.maddox.il2.game.Mission;
import com.maddox.rts.SectFile;
import com.maddox.sas1946.il2.util.TrueRandom;
// Referenced classes of package com.maddox.il2.objects.vehicles.stationary:
// CandCGeneric, CandC
//public static class CandC$DynamicWeatherUnit extends CandCGeneric //"static" not allowed by my compiler
public class CandC$DynamicWeatherUnit extends CandCGeneric
{
public boolean danger()
{
int i = Mission.cur().sectFile().get("Mods", "DWInterval", 20) * 60; //20 minutes is the default; originally in "Main", but this is bad!
int i2 = i + (int) (TrueRandom.nextFloat((float) -i / 3F, (float) i / 3F)); //NEW randomizes time interval by up to 1/3
super.Timer1 = super.Timer2 = i2; //NEW experiment!!!
resetTimer(i2);
int j = TrueRandom.nextInt(100);
if(j <= 33 && cloudsAltered < worstClouds) //worsening
{
flag = true;
cloudsAltered++;
heightAltered *= (0.83F + height / 1000F / 40F);
if(heightAltered < 300F)
heightAltered = 300F;
}
if(j > 33 && j < 66 && cloudsAltered > bestClouds) //improving
{
flag = true;
cloudsAltered--;
heightAltered *= (1F / (0.83F + height / 1000F / 40F));
if(heightAltered > 5000F)
heightAltered = 5000F;
}
if(Mission.cur() != null && start)
{
clouds = Mission.cur().sectFile().get("Main", "CloudType", 2); //Hazy if not specified in .mis
cloudsAltered = clouds; //NEW
height = Mission.cur().sectFile().get("Main", "CloudHeight", 1500); //note: originally was int, supposed to be float !!!
heightAltered = height; //NEW
bestClouds = Mission.cur().sectFile().get("Mods", "BestClouds", 0); //clear if not specified in .mis file
if(bestClouds < 0 || bestClouds > 6)
bestClouds = 0;
worstClouds = Mission.cur().sectFile().get("Mods", "WorstClouds", 6); //thunder if not specified in .mis file
if(worstClouds < 0 || worstClouds > 6)
worstClouds = 6;
if(worstClouds <= bestClouds)
{
worstClouds = 6;
bestClouds = 0;
}
}
start = false;
if (flag) //NEW; to NOT execute createClouds() if no change; also doesn't make change at mission start
{
Mission.createClouds(cloudsAltered, heightAltered); //NOTE: createClouds(int, float); (was clouds, height)
World.land().cubeFullUpdate();
flag = false; //NEW
}
return true;
}
private int clouds;
private int cloudsAltered; //NEW
private float height;
private float heightAltered; //NEW; must be float because createClouds() must be sent float
private int bestClouds; //absolute min weather value permitted (0 for clear)
private int worstClouds; //absolute max weather value permitted (6 for thunder)
private boolean start;
private boolean flag; //NEW; to not execute createClouds() if no change to weather
public CandC$DynamicWeatherUnit()
{
clouds = 2; //weather value at mission start
cloudsAltered = clouds; //NEW; altered weather value
height = 1500;
heightAltered = height; //NEW
bestClouds = 0;
worstClouds = 6;
start = true;
flag = false; //NEW
}
}
Here's an example of part of a mission file using this object:
[NStationary]
0_Static vehicles.planes.Plane$A6M2_21 2 111994.84 80720.15 439.10 0.0 null 2 1.0 null 0
.
.
.
22_Static vehicles.stationary.CandC$DynamicWeatherUnit 1 110247.97 77952.62 360.00 0.0
[Buildings]
[Bridge]
[House]
[Mods]
BestClouds 1
WorstClouds 6
DWInterval 12