E2150 - Weather

From InsideEARTH
Revision as of 14:05, 3 December 2023 by GvardianDLVII (talk | contribs)

The weather in Earth 2150 is dynamic and can actively influence the gameplay. Various weather effects can happen due to being scripted by gamemode/campaign designers, console commands, or player actions (LC's Weather control Center). The weather effects available in the game are as follows: snow, rain, wind, thunderstorm and meteor rain. Thunderstorm usually happen along with rains (although it is possible to have a thunderstorm without a rain).

Snow

Rain

Wind

Thunderstorm

Thunderstorm spawns lightnings on the area, that damage and destroy units and buildings. The lightnings are more likely to hit targets that are placed higher, what can make it worth to build structures in the vicinity of higher terrain. Unless spawned with console command, thunderstorms always come with rain effect.

Technical data

Parameters

The effect is parameterized in the following way:

  • x,y - epicenter location
  • range - range of the effect, value gets clamped to 1-127 range
  • upTime - time (in ticks) it takes to get the effect to the full intensity, min 1
  • constTime - time (in ticks) in which the effect operates at full intensity, min 1
  • downTime - time (in ticks) it takes for the effect to fade out, min 1
  • intensity - clamped to 1-10 range
  • power - determines the strength of the spawned lightnings, clamped to 1-10 range
  • unknown parameter - it is not possible to set it, so the game always takes the default value, which is not recognized yet

Create conditions

  • with Weather.AddStorm(x, y, range, upTime, constTime, downTime, intensity, power) command - it is the only way to spawn Thunderstorm without the rain
  • with Weather.AddRainStorm(x, y, range, upTime, constTime, downTime, rainIntensity, stormIntensity, stormPower) command, that spawns both Rain and Thunderstorm
  • with Storm(x, y, range, upTime, constTime, downTime, rainIntensity, stormIntensity, stormPower) function call from within EarthC scripts
  • with Weather Control Center. This spawns both rain and thunderstorm effects with the following parameters:
    • x, y - as selected by the player
    • range - 30
    • upTime - 300 ticks = 15 seconds
    • constTime - 1200 ticks = 60 seconds
    • downTime - 300 ticks = 15 seconds
    • intensity - 2
    • power - 5
    • rain intensity is at the maximum value of 10

Single lightning spawn algorithm

  1. Get random location in effect's range
  2. Get random hit offset range (an area to search for lightning interceptors)
  3. Alter hit location to make the lightning hit the highest point in the vicinity
  4. Randomize spawned lightning type, affected by the power parameter
  5. Spawn lightning
Finding the random "initial location"

The game calculates a random distance (r1, within 0-range) and a random angle alpha (0-255, where 256 == 2*PI rad). With the use of sin and cos functions of alpha, multiplied by the r1 value, the game calculates offset (x1, y1) from the epicenter. After applying the offset to the x and y parameters, we will get a point (x2, y2). This point is the initial hit location. If the location is outside of the level, the lightning won't spawn. There is no difference for the lightning to spawn in the accessible or the inaccessible area of the map (the level "margin"), so casting rainstorm near the edge of the level will result with fewer lightnings spawned and/or fewer lightnings hitting relevant area. You may also notice that lightnings are more likely to hit nearby the epicenter, rather than on the further distances.

Altering hit location by nearby high elements

The hit location is altered in the following way: We take a random number r2 within the range of 4-8. The way this number gets randomized isn't that simple - there is a 1/3 chance that the number will be in <4-6> range, and 2/3 chance that the number will be within <6-8> range. This makes value 6 the most probable (33%), followed by 7 and 8 (both 22%), with 4 and 5 being the least probable (both 11%). The game iterates all terrain squares with square area bounded by x2 - r2, y2 - r2, x2 + r2, y2 + r2 and searches for the highest spot. This establishes the final hit location.

Type of spawned lightning

There are multiple kinds of lightnings, that are defined in game parameters, thus their count and properties can be different among game versions and mods. By default there are 5 of them, each subsequent one being stronger than the previous one (this should always be made that way). The way the lightning is being chosen is a little bit complicated. There are 20 "spawn factors" for each of the power parameter levels. Those values (taken randomly 1-20) are in range of 0-10, with 0 pointing to the weakest lightning, and 10 pointing to the strongest. The index of the lightning (0 to numOfLightningTypes - 1) is calculated as follows: spawnFactor * (numOfLightningTypes - 1) / 10. Below is the table of "Spawn factors":

Example: We have 5 lightning types in parameters, a thunderstorm with power = 5 and we randomized (1-20) the 17th factor. From the table above we get value 3. The index of the lightning type is 3 * (5 - 1) / 10 = 12 / 10 = 1. This results in spawning the second (first has index = 0) lightning type from the parameters.

Taking above into account, the default WCC's lightning (5 types in parameters, power = 5) has 5% chance of spawning lightning type 3/5, 15% chance of spawning lightning type 2/5, and 80% chance to spawn the weakest lightning of type 1/5.

Effect intensity

Event intensity scales lineary from 0 to the target intensity (from event's parameter) during up time, and diminishes in the same way during down time. The intensity is equal to the target intensity during ``const time`` phase. The timeout between lightnings is calculated as follows:

 x = 400 / currentIntensity * range
 deltaT = Max(1, Rand(0, x-1) + x / 2)

With default WCC settings, at full intensity, a thunderstorm spawns a lightning every 3-8 ticks (0,15s-0,4s).

Meteor rain

Meteors are another destructive weather effect, which similarly to thunderstorm hits multiple targets at the area it happens. Meteors are stronger however, since they don't get intercepted by higher elements, they deal AOE damage and cannot be canceled with Weather Control Center.

Technical data

Parameters

The effect is parameterized in the following way:

  • x,y - epicenter location
  • range - range of the effect, value gets clamped to 1-127 range
  • upTime - time (in ticks) it takes to get the effect to the full intensity, min 1
  • constTime - time (in ticks) in which the effect operates at full intensity, min 1
  • downTime - time (in ticks) it takes for the effect to fade out, min 1
  • intensity - clamped to 1-10 range
  • power - determines the strength of the spawned lightnings, clamped to 1-10 range
  • alphaAngle - the angle at which the meteors strike (horizontally). Any value above 255 gets reduced to the rest of the division by 256. If "-1" is provided, the value gets picked randomly from the 0-255 range
  • betaAngle - the angle at which the meteors strike (vertically). If value is not "-1", it gets clamped to <48, 64> range. If "-1" is provided, the value gets picked randomly from the 48-64 range

Create conditions

  • with Weather.AddMeteorRain(x, y, range, upTime, constTime, downTime, intensity, power, alphaAngle, betaAngle) command - it is the only way to spawn meteor rain with custom angle values
  • with Shower cheat, that spawns the meteor rain with following parameters:
    • x, y - current camera position
    • range - 12
    • upTime - 100 ticks = 5 seconds
    • constTime - 500 ticks = 25 seconds
    • downTime - 100 ticks = 5 seconds
    • intensity - 10
    • power - 10
    • alpha - 32
    • beta - 53
  • with MeteorRain(x, y, range, upTime, constTime, downTime, intensity, power) function call from within EarthC scripts. The angles are set to -1, thus are always randomized.
  • with Weather Control Center. This spawns the meteor rain with the following parameters:
    • x, y - as selected by the player
    • range - 30
    • upTime - 300 ticks = 15 seconds
    • constTime - 1200 ticks = 60 seconds
    • downTime - 300 ticks = 15 seconds
    • intensity - 2
    • power - 5
    • alpha - (-1) (random)
    • beta - (-1) (random)

Single meteor spawn algorithm

  1. Get random location in effect's range
  2. Calculate spawn location at 4096 height, with an offset that takes into account the angles
  3. Randomize spawned meteor type, affected by the power parameter
  4. Spawn meteor
Finding the random location

The procedure is the same as with lightnings - random angle, random distance, calculate offset using trigonometry.

Calculating the spawn location

The algorithm takes beta angle and calculates the horizontal offset form the hit location to the spawn point at 4096 height (4096 / tan(beta)). Using this distance, the alphaAngle, along with sin(alpha) * dist and cos(alpha) * dist, the algorithm calculates offset from the hit location

Type of spawned meteor

Same as with lightning types.

Effect intensity

Event intensity scales lineary from 0 to the target intensity (from event's parameter) during up time, and diminishes in the same way during down time. The intensity is equal to the target intensity during const time phase. The timeout between meteors is calculated as follows (the only difference to lightning is 400 being replaced by 500, which results in meteors spawning a bit less frequently):

 x = 500 / currentIntensity * range
 deltaT = Max(1, Rand(0, x-1) + x / 2)

With default WCC settings, at full intensity, a meteor rain spawns a meteor every 4-11 ticks (0,2s-0,55s).