Howto: Complex zone based weather system (Full Version)

All Forums >> [New Releases from Matrix Games] >> Advanced Tactics Series >> Mods and Scenarios



Message


bwheatley -> Howto: Complex zone based weather system (9/15/2012 2:39:18 PM)

Duplicated the post here for posterity if someone or me ever needs some reminder of the power of strings ;)

The is the module that i am using to build the weather zone list per zone it checks a pre-existing set of stringlists which are the weather tables you can see here

Table 1 - 12 are weather tables for january to december and the columns go from

quote:

zone 1 - UK
zone 2 - Northern Europe
zone 3 - Norway/Finland/etc
zone 4 - Southern Europe
zone 5 - Spain/Italy/Balkans
zone 6 - Northern USSR
zone 7 - Southern USSR
zone 8 - Africa


then there are 10 rows each row representing 10% chance of certain weather.

quote:

Weather Types
0 - Clear
1 - Mud
2 - Snow
3 - Blizzard


So we started with

Tempvar900 - is 1-12 (the month) it's passed in from the originating function
StringList 0 - is the stringlist i'm calling 'Weather ForeCast' it holds the same style 8 columns to represent the forecast of the zones for turns ahead. It will allow us to have "Weather Forecasts" so commanders can have some foresight on how to position their forces. There will be a 35-40% chance that the weather on the turn itself is different then the forecast.

We're starting with 0 since vb.net uses 0 based numbering. Just something for non-developer types to take note of.
Then we're using CheckRandomRowStringList to pick a random # row from the strings just a row # not the contents of the number.
Then we have to set the same variable to the actual contents of that row.

quote:

0) ' This function opens the appriopriate weather list
1) SETVAR: TempVar901 = CheckRandomRowStringList(TempVar900, 0)
2) SETVAR: TempVar901 = CheckStringList(TempVar900, TempVar901, 1)
3) ' Weather For Zone 2
4) SETVAR: TempVar902 = CheckRandomRowStringList(TempVar900, 1)
5) SETVAR: TempVar902 = CheckStringList(TempVar900, TempVar902, 2)
6) ' Weather For Zone 2
7) SETVAR: TempVar903 = CheckRandomRowStringList(TempVar900, 2)
8) SETVAR: TempVar903 = CheckStringList(TempVar900, TempVar903, 3)
9) ' Weather For Zone 2
10) SETVAR: TempVar904 = CheckRandomRowStringList(TempVar900, 3)
11) SETVAR: TempVar904 = CheckStringList(TempVar900, TempVar904, 4)
12) ' Weather For Zone 2
13) SETVAR: TempVar905 = CheckRandomRowStringList(TempVar900, 4)
14) SETVAR: TempVar905 = CheckStringList(TempVar900, TempVar905, 5)
15) ' Weather For Zone 2
16) SETVAR: TempVar906 = CheckRandomRowStringList(TempVar900, 5)
17) SETVAR: TempVar906 = CheckStringList(TempVar900, TempVar906, 6)
18) ' Weather For Zone 2
19) SETVAR: TempVar907 = CheckRandomRowStringList(TempVar900, 6)
20) SETVAR: TempVar907 = CheckStringList(TempVar900, TempVar907, 7)
21) ' Weather For Zone 2
22) SETVAR: TempVar908 = CheckRandomRowStringList(TempVar900, 7)
23) SETVAR: TempVar908 = CheckStringList(TempVar900, TempVar908, 8)
24) EXECUTE: ExecMessage(999, 999, '0', '-1')
25) ' Add the row onto the end of the WeatherList
26) EXECUTE: ExecAddStringListCells(0, 1, 0)
27) LOOPER: TempVar0 FROM 1 TO 8
28) EXECUTE: ExecSetStringList(2, 2, 2, 2)
29) END LOOPER


Then with a little thinking that i could probably iterate over this more quickly and talking to
ernie I end up with a much smaller function.


quote:

0) ' This function opens the appriopriate weather list
1) ' it finds a random row then that row gets dumped into stringlist 0 which is weatherforcecast
2) ' Add the row onto the end of the WeatherList
3) EXECUTE: ExecAddStringListCells(0, 1, 0)
4) SETVAR: TempVar902 = CheckStringListRows(0)
5) ' Loop and generate the weather forecast
6) LOOPER: TempVar1 FROM 0 TO 7
7) SETVAR: TempVar901 = CheckRandomRowStringList(TempVar900, TempVar1)
8) SETVAR: TempVar901 = CheckStringList(TempVar900, TempVar901, TempVar1)
9) ' Add the results to the last row in the weatherforecast string
10) EXECUTE: ExecSetStringList(0, TempVar902, TempVar1, TempVar901)
11) END LOOPER





bwheatley -> RE: The power of Strings..thanks vic! (9/15/2012 2:51:39 PM)

Actually i might eventually make this thread into a more complex overview of the weather system i'm designing for War In Europe instead. Or maybe i'll keep it all in the War in Europe thread.

What do you guys think? I think if it's a standalone thread it will be easier and more useful to people so they won't have to search through a long drawn out thread to find this. I know i at least will come back and reference this stuff eventually. :)




Josh -> RE: The power of Strings..thanks vic! (9/15/2012 3:58:54 PM)

Yeah I think it's better to give it a separate thread, like you say it won't be swamped in a long thread.




bwheatley -> RE: The power of Strings..thanks vic! (9/15/2012 8:11:58 PM)

[image]http://wac.3aff.edgecastcdn.net/803AFF/witewiki/billfiles/games/atg/images/WiE/workingishweather1.png[/image]




bwheatley -> RE: The power of Strings..thanks vic! (9/15/2012 9:12:09 PM)

There is a 35% change that weather can change for the current turn and you will get alerted of such and see the new forecast.
[image]http://wac.3aff.edgecastcdn.net/803AFF/witewiki/billfiles/games/atg/images/WiE/weatherchange.png[/image]




bwheatley -> RE: The power of Strings..thanks vic! (9/15/2012 11:49:12 PM)

One request vic...when you export events please export them as their NAMES w/ their event # so we can reimport them properly. :(




bwheatley -> RE: The power of Strings..thanks vic! (9/15/2012 11:51:03 PM)

I made an event that could be executed when seasons change as well as executed inside the game editor so you could make sure things looked right.

quote:


NAME: Change All To Weather
0) LOOPER: TempVar960 FROM 0 TO CheckMapWidth
1) LOOPER: TempVar961 FROM 0 TO CheckMapHeight
2) ' 0-clear 1-mud 2-snow 3-blizzard
3) SETVAR: TempVar962 = 2
4) EXECUTE: CallFunction('Change Landscape')
5) END LOOPER
6) END LOOPER




bwheatley -> RE: The power of Strings..thanks vic! (9/15/2012 11:51:44 PM)

Then this event actually does the lookups based on the strings.
quote:

NAME: Change Landscape
0) ' Change landscape takes 960 & 961 for hex and 962 for col to set to
1) SETVAR: TempVar10 = CheckLandscapeType(TempVar960, TempVar961)
2) SETVAR: TempVar11 = CheckStringList(20, TempVar10, TempVar962)
3) EXECUTE: ExecSetLandscape(TempVar960, TempVar961, TempVar11)




bwheatley -> RE: The power of Strings..thanks vic! (9/15/2012 11:52:24 PM)

Using this stringlist labeled 'Land Weather Trans'

0,18,12,12,0
1,1,1,1,1
2,19,13,13,2
3,20,14,14,3
4,4,15,15,4
5,21,16,16,5
6,22,17,17,6
7,7,7,7,7
8,8,8,8,8
9,9,9,9,9
10,10,10,10,10
11,11,11,11,11
0,18,12,12,12
2,19,13,13,13
3,20,14,14,14
4,4,15,15,15
5,21,16,16,16
6,22,17,17,17
0,18,12,12,18
2,19,13,13,19
3,20,14,14,20
5,21,16,16,21
6,22,17,17,22




bwheatley -> RE: The power of Strings..thanks vic! (9/15/2012 11:54:26 PM)

Column 0 = LandScape# Clear
Column 1 = LandScape# Mud
Column 2 = LandScape# Snow
Column 3 = LandScape# Blizzard (same as snow for now)
Column 4 = Row count for making sure i built the table properly.

basically the lookup will say we're going to weather type 2 - SNOW then look and say we're a plain hex LandScape#0 it will become LandScape#12




bwheatley -> RE: The power of Strings..thanks vic! (9/19/2012 5:18:20 AM)

Event2:
Name: Weather Zone Checker
0)    ' What month is it
1)    SETVAR: TempVar900 = CheckMonth
2)    ' Tempvar952 0 = No Weather Change 1 = Weather Change
3)    SETVAR: TempVar952 = 0
4)    EXECUTE: CallFunction('Open Weather List')
5)    ' Check to see if todays weather gets changed
6)    EXECUTE: CallFunction('Check for Weather Change')
7)    ' Show the Weather Forecast Now
8)    EXECUTE: CallFunction('Show Weather Forecast')
9)    ' Draw hexes
10)   EXECUTE: CallFunction('Draw Weather on Map')
11)   ' There are only 2 rows 0 - current turn, 1 next turn..we need to move it up
12)   EXECUTE: CallFunction('move weather up to row 0')
13)   ' Do the readiness loss based on weather
14)   EXECUTE: CallFunction('Apply Weather Readiness Loss')
15)   EMPTY




bwheatley -> RE: The power of Strings..thanks vic! (9/19/2012 5:18:39 AM)

Event 3
Name:Draw Weather on Map
0)    LOOPER: TempVar960 FROM 0 TO CheckMapWidth
1)      LOOPER: TempVar961 FROM 0 TO CheckMapHeight
2)        ' Find out what slot we're in so we can set the right weather for this turn
3)        SETVAR: TempVar1 = CheckSlot(TempVar960, TempVar961, 9)
4)        ' We have to remove 1 because slot # does not correspond to stringlist#
5)        SETVAR: TempVar1 - 1
6)        ' 0-clear 1-mud 2-snow 3-blizzard
7)        SETVAR: TempVar962 = CheckStringList(0, 0, TempVar1)
8)        EXECUTE: CallFunction('Change Landscape')
9)      END LOOPER
10)   END LOOPER




bwheatley -> RE: The power of Strings..thanks vic! (9/19/2012 5:18:52 AM)

Event 4:
Name: Change Landscape
0)    ' Change landscape takes 960 & 961 for hex and 962 for col to set to
1)    SETVAR: TempVar10 = CheckLandscapeType(TempVar960, TempVar961)
2)    SETVAR: TempVar11 = CheckStringList(20, TempVar10, TempVar962)
3)    EXECUTE: ExecSetLandscape(TempVar960, TempVar961, TempVar11)
4)    ' Also set the OffensivePenalty for Blizzard
5)    SETVAR: TempVar1 = CheckStringList(21, 0, TempVar962)
6)    EXECUTE: ExecOffensiveModByPeople(TempVar960, TempVar961, -1, TempVar1)




bwheatley -> RE: The power of Strings..thanks vic! (9/19/2012 5:19:02 AM)

Event 5:
Name: Open Weather List
0)    ' This function opens the appriopriate weather list
1)    ' it finds a random row then that row gets dumped into stringlist 0 which is weatherforcecast
2)    SETVAR: TempVar902 = 1
3)    ' Loop and generate the weather forecast
4)    LOOPER: TempVar903 FROM 0 TO 7
5)      EXECUTE: CallFunction('Get Random Weather')
6)    END LOOPER




bwheatley -> RE: The power of Strings..thanks vic! (9/19/2012 5:19:14 AM)

Event 6:
Name: Get Random Weather
0)    ' This function just generates the random weather for a given cell
1)    ' it finds a random row then that row gets dumped into stringlist 0 which is weatherforcecast
2)    ' Add the row onto the end of the WeatherList
3)    ' Loop and generate the weather forecast
4)    SETVAR: TempVar901 = CheckRandomRowStringList(TempVar900, TempVar903)
5)    SETVAR: TempVar901 = CheckStringList(TempVar900, TempVar901, TempVar903)
6)    ' Add the results to the last row in the weatherforecast string
7)    EXECUTE: ExecSetStringList(0, TempVar902, TempVar903, TempVar901)




bwheatley -> RE: The power of Strings..thanks vic! (9/19/2012 5:19:25 AM)

Event 7:
Name: Check for Weather Change
0)    ' This function will randomly modify weather for the current turn then alert back into tempstring952
1)    CHECK: CheckRandomPercent =< 35
2)      ' We will override tempvar902 to set the row to update to 0
3)      SETVAR: TempVar902 = 0
4)      SETVAR: TempVar952 = 1
5)      LOOPER: TempVar903 FROM 0 TO 7
6)        EXECUTE: CallFunction('Get Random Weather')
7)      END LOOPER
8)    END CHECK




bwheatley -> RE: The power of Strings..thanks vic! (9/19/2012 5:19:35 AM)

Event 8:
Name: Apply Weather Readiness Loss
0)    ' This function applies movement modifiers based on weather - temp960-x 961-y 962-typeweather
1)    LOOPER: TempVar1 FROM 0 TO 7
2)      ' Look up what the current weather is from teh forecast then do readinesslossbyarea
3)      SETVAR: TempVar950 = CheckStringList(0, 0, TempVar1)
4)      ' We have to add one because stringlist starts at 0 slot start at 1
5)      SETVAR: TempVar3 = TempVar1
6)      SETVAR: TempVar3 + 1
7)      EXECUTE: CallFunction('Convert Weather type to name')
8)      EXECUTE: ExecReadinessLossByArea(9, TempVar3, TempVar953, Gameslot_Change of Readiness Loss(#13))
9)    END LOOPER




bwheatley -> RE: The power of Strings..thanks vic! (9/19/2012 5:19:46 AM)

Event 9:
quote:

Show Weather Forecast
0) ' This function should pole stringlist 0 and show what the forecast is coming up
1) SETVAR: TempString1 = 'Weather Report'
2) ' This is the silly way we have to add newlines for now
3) SETVAR: TempString999 = ReturnCRLF
4) ' At any time there should be 2 rows 0 - This turn 1 - Next Turn
5) LOOPER: TempVar0 FROM 0 TO 1
6) SETVAR: TempString1 + TempString999
7) ' Loop through all the zones 1-8 (0-7 for 0 array)
8) CHECK: TempVar0 == 0
9) SETVAR: TempString1 + 'Current Turn - '
10) CHECK: TempVar952 > 0
11) SETVAR: TempString1 + TempString999
12) SETVAR: TempString1 + '**********ALERT WEATHER FORECAST CHANGE**********'
13) SETVAR: TempString1 + TempString999
14) END CHECK
15) END CHECK
16) CHECK: TempVar0 == 1
17) SETVAR: TempString1 + 'Next Turn - '
18) END CHECK
19) SETVAR: TempString1 + TempString999
20) LOOPER: TempVar1 FROM 0 TO 7
21) SETVAR: TempVar951 = TempVar1
22) SETVAR: TempVar951 + 1
23) SETVAR: TempString1 + 'Zone - '
24) ' Convert the weather Zone # to a name
25) EXECUTE: CallFunction('Convert Zone Number to Name')
26) SETVAR: TempString1 + TempString951
27) SETVAR: TempString1 + ' '
28) SETVAR: TempVar950 = CheckStringList(0, TempVar0, TempVar1)
29) ' Convert the weather type # to a name
30) EXECUTE: CallFunction('Convert Weather type to name')
31) SETVAR: TempString1 + TempString950
32) END LOOPER
33) END LOOPER
34) EXECUTE: ExecMessage(-1, -1, 0, -1)





bwheatley -> RE: The power of Strings..thanks vic! (9/19/2012 5:20:44 AM)

Event 10:
Name: Convert Weather Type to name
0)    ' This function takes tempvar950 as 0 & returns tempstring950 as string of weather type
1)    ' Clear = 0
2)    SETVAR: TempString950 = 'Wtf'
3)    CHECK: TempVar950 == 0
4)      SETVAR: TempString950 = 'Clear '
5)      SETVAR: TempVar953 = 0
6)    END CHECK
7)    ' Mud = 1
8)    CHECK: TempVar950 == 1
9)      SETVAR: TempString950 = 'Mud '
10)     SETVAR: TempVar953 = Gameslot_Mud Readiness Reduction(#10)
11)   END CHECK
12)   ' Snow = 2
13)   CHECK: TempVar950 == 2
14)     SETVAR: TempString950 = 'Snow '
15)     SETVAR: TempVar953 = Gameslot_Snow Readiness Reduction(#11)
16)   END CHECK
17)   ' Blizzard = 3
18)   CHECK: TempVar950 == 3
19)     SETVAR: TempString950 = 'Blizzard '
20)     SETVAR: TempVar953 = Gameslot_Blizzard Readiness Reduction(#12)
21)   END CHECK
22)   SETVAR: TempString950 + TempString999




bwheatley -> RE: The power of Strings..thanks vic! (9/19/2012 5:20:57 AM)

Event 11:
quote:

Name: Convert zone number to name
0) ' This function takes tempvar951 as 0 & returns tempstring951 as string of name of the zone
1) CHECK: TempVar951 == 1
2) SETVAR: TempString951 = 'UK '
3) END CHECK
4) CHECK: TempVar951 == 2
5) SETVAR: TempString951 = 'Northern Europe '
6) END CHECK
7) CHECK: TempVar951 == 3
8) SETVAR: TempString951 = 'Norway/Finland/Sweden '
9) END CHECK
10) CHECK: TempVar951 == 4
11) SETVAR: TempString951 = 'Southern Europe '
12) END CHECK
13) CHECK: TempVar951 == 5
14) SETVAR: TempString951 = 'Spain/Italy/Balkans '
15) END CHECK
16) CHECK: TempVar951 == 6
17) SETVAR: TempString951 = 'Northern USSR '
18) END CHECK
19) CHECK: TempVar951 == 7
20) SETVAR: TempString951 = 'Southern USSR '
21) END CHECK
22) CHECK: TempVar951 == 8
23) SETVAR: TempString951 = 'Africa '
24) END CHECK
25) SETVAR: TempString951 + ' - '




bwheatley -> RE: The power of Strings..thanks vic! (9/19/2012 5:21:08 AM)

Event 12:
Name: Move weather upto row 0
0)    ' This function does everything it says basically moving weather from row 1 to row 0
1)    LOOPER: TempVar903 FROM 0 TO 7
2)      SETVAR: TempVar901 = CheckStringList(0, 1, TempVar903)
3)      EXECUTE: ExecSetStringList(0, 0, TempVar903, TempVar901)
4)      ' Lets set row 1 to clear just as an emergency backup
5)      EXECUTE: ExecSetStringList(0, 1, TempVar903, 0)
6)    END LOOPER




bwheatley -> RE: The power of Strings..thanks vic! (9/19/2012 5:33:14 AM)

Weather forecast table

[image]http://wac.3aff.edgecastcdn.net/803AFF/witewiki/billfiles/games/atg/images/WiE/weathersystem/weatherforecast.png[/image]
There are two rows in this table and row 0 = current turn row 1 = next turn.
Then each column represents the 1-8 zones of the map.




bwheatley -> RE: The power of Strings..thanks vic! (9/19/2012 5:33:35 AM)

Monthly Weather table
[image]http://wac.3aff.edgecastcdn.net/803AFF/witewiki/billfiles/games/atg/images/WiE/weathersystem/monthlyweathertable.png[/image]

This table has rows for all 8 zones. then each column is 10% chance of predicting weather for a given zone
0 = clear
1 = mud
2 = snow
3 = blizzard




bwheatley -> RE: The power of Strings..thanks vic! (9/19/2012 5:35:15 AM)

Landscape type translation table
[image]http://wac.3aff.edgecastcdn.net/803AFF/witewiki/billfiles/games/atg/images/WiE/weathersystem/landweathertranslation.png[/image]h

This table translates clear LT's to Mud LT's to Snow LT's to Blizzard LT's.





bwheatley -> RE: The power of Strings..thanks vic! (9/19/2012 5:36:34 AM)

Weather Penalty
This is where we put what the offensive penalty is based on weather.
[image]http://wac.3aff.edgecastcdn.net/803AFF/witewiki/billfiles/games/atg/images/WiE/weathersystem/winteroffensivepenalty.png[/image]




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.0390625