Loading [MathJax]/extensions/Safe.js

Special Aircraft Service

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2   Go Down

Author Topic: Fixing and augmenting the C&C Dynamic Weather object (and StormFront too)  (Read 876 times)

0 Members and 1 Guest are viewing this topic.

WxTech

  • Modder
  • member
  • Offline Offline
  • Posts: 6205

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:
Code: [Select]
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:
Code: [Select]
// 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:
Code: [Select]
[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
Logged
Great minds discuss ideas. Average minds discuss events. Small minds discuss people. - Hyman Rickover (but probably predating his use.)

Whiskey_Sierra_972

  • Modder
  • member
  • Offline Offline
  • Posts: 6772
  • In memory of my beloved hero: Saburo SAKAI!
Re: Fixing and augmenting the C&C Dynamic Weather object
« Reply #1 on: December 11, 2024, 10:12:27 PM »

Really cool!

Dynamic weather is an option really useful for every missions but for long missions is a real addition....have you thought about to include into or take a look at the 'storm front' too?
Logged

WxTech

  • Modder
  • member
  • Offline Offline
  • Posts: 6205
Re: Fixing and augmenting the C&C Dynamic Weather object
« Reply #2 on: December 12, 2024, 01:41:45 AM »

Working on the StormFront object for the past hour or so...  ;)

Have added the option to set the distance interval between weather changes from 5 to 100km, as the fixed 50km interval is too limiting.

And as the weather worsens the cloud height decreases, instead of remaining at the formerly fixed height of 1000m; here's the code snippet showing the original line and my new line using a power function.

Code: [Select]
//    Mission.createClouds(front, 1000F);  //original
    Mission.createClouds(front, height * (float) Math.pow(0.85F, (float) (front - clouds)));


Here's a little table to illustrate the resulting heights. The leftmost column is the cloud height as set in the .mis file (entries for heights of 2000m, 1000m and 500m). Each next entry to the right is the height for each step in the worsening weather. For instance, suppose the cloud height is 1000m, the worstCloud = 6 (thunder) and the cloud type in the .mis file is 2 (haze). 6 - 2 = 4. Stepping 4 values to the right of 1000 = a height of 522m (when within the innermost radius for the StormFront object.)

Code: [Select]
0 1 2 3 4 5 6

2000 1700 1445 1228 1044 887 754
1000 850 723 614 522 444 377
500 425 361 307 261 222 189
Logged
Great minds discuss ideas. Average minds discuss events. Small minds discuss people. - Hyman Rickover (but probably predating his use.)

vonofterdingen

  • Missioneer
  • member
  • Offline Offline
  • Posts: 1366
Re: Fixing and augmenting the C&C Dynamic Weather object (and StormFront too)
« Reply #3 on: December 12, 2024, 10:17:19 AM »

What happens to legacy missions that use the C&C Dynamic Weather object but have nothing in the Mods section of the mission file?
Logged

WxTech

  • Modder
  • member
  • Offline Offline
  • Posts: 6205
Re: Fixing and augmenting the C&C Dynamic Weather object (and StormFront too)
« Reply #4 on: December 12, 2024, 11:20:09 AM »

Those missions having no specified parameters in the .mis file will still use the defaults as established in code. However, my treatment of cloud height is different to the old scheme, and so legacy missions carefully constructed around the old scheme will have differences in that respect.

With StormFront, the clouds it had generated were at a constant 1,000m height. Now the height is based on the CloudHeight value in the .mis file's [MAIN] section, getting progressively lower from there as the new weather encountered is incremented. And of course that sequence reverses as distance from the StormFront object increases.

I tested a case where the annuli surrounding the object had a 10km separation versus the old 50km value, and it worked well. Like flying into a more localized thunderstorm supercell.  😉  I had to reduce the value of the timer from 300 (5 minutes) to 30 (30 seconds) in order to get a crisper response for that tighter interval of 10km. Otherwise one could traverse two or more annuli with nothing happening, then suddenly the weather would take a more dramatic turn. While potentially attractive to have this big change in some circumstances, on balance I think it's better to have the weather change in steps of 1 and not 2 or 3. Of course, one could add some randomness to the process, as is done for the Dynamic Weather object...
Logged
Great minds discuss ideas. Average minds discuss events. Small minds discuss people. - Hyman Rickover (but probably predating his use.)

shardana

  • member
  • Offline Offline
  • Posts: 880
Re: Fixing and augmenting the C&C Dynamic Weather object (and StormFront too)
« Reply #5 on: December 12, 2024, 11:33:03 AM »

How would all these great stuff be available?
Logged

Vampire_pilot

  • member
  • Offline Offline
  • Posts: 8630
Re: Fixing and augmenting the C&C Dynamic Weather object (and StormFront too)
« Reply #6 on: December 12, 2024, 11:37:13 AM »

I do suppose as add-on improvements to an existing C&C mod on your game. Or to BAT, which contains C&C.
Logged

WxTech

  • Modder
  • member
  • Offline Offline
  • Posts: 6205
Re: Fixing and augmenting the C&C Dynamic Weather object (and StormFront too)
« Reply #7 on: December 12, 2024, 12:16:58 PM »

I already have a mod released for several other C&C objects. When I'm happy with these two I'll update that mod by adding these.

Note that I supply the classfile names for each of these objects, and so one can choose which to retain or reject.
Logged
Great minds discuss ideas. Average minds discuss events. Small minds discuss people. - Hyman Rickover (but probably predating his use.)

shardana

  • member
  • Offline Offline
  • Posts: 880
Re: Fixing and augmenting the C&C Dynamic Weather object (and StormFront too)
« Reply #8 on: December 12, 2024, 12:32:52 PM »

Great thanks!
Logged

genXgamer

  • Modder
  • member
  • Offline Offline
  • Posts: 1453
Re: Fixing and augmenting the C&C Dynamic Weather object (and StormFront too)
« Reply #9 on: December 12, 2024, 02:04:07 PM »

I trialled C&C Storm Front in one of my campaigns and wasn't that impressed, although it probably wasn't the effect I was really after.
I will be interested to see how it now looks.

If you ever get a chance can you take a look at the code for the ground attack function?
See if you can get it working, meaning aircraft drop bombs then proceed to next waypoint.
Having to do a work around by limiting fuel is time consuming.
Maybe drop the jettison droptanks code as well, as this affects all aircraft even escorts.
Logged
Go in quickly - Punch hard - Get out!

WxTech

  • Modder
  • member
  • Offline Offline
  • Posts: 6205
Re: Fixing and augmenting the C&C Dynamic Weather object (and StormFront too)
« Reply #10 on: December 12, 2024, 02:47:56 PM »

I'm just starting to try adding functionaility to StormFront to increase turbulence and gusts as weather worsens...
Logged
Great minds discuss ideas. Average minds discuss events. Small minds discuss people. - Hyman Rickover (but probably predating his use.)

Whiskey_Sierra_972

  • Modder
  • member
  • Offline Offline
  • Posts: 6772
  • In memory of my beloved hero: Saburo SAKAI!
Re: Fixing and augmenting the C&C Dynamic Weather object (and StormFront too)
« Reply #11 on: December 12, 2024, 02:51:31 PM »

As it should be the case in RL....
Logged
Pages: [1] 2   Go Up
 

Page created in 0.039 seconds with 20 queries.