Saisons effects on maps

Brainstorm ideas of possible additions to the game. Read this before posting!

Moderator: Forum Moderators

Forum rules
Before posting a new idea, you must read the following:
User avatar
hermestrismi
Posts: 626
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: Saisons effects on maps

Post by hermestrismi »

beetlenaut wrote: March 8th, 2023, 12:20 am
hermestrismi wrote: March 8th, 2023, 12:00 am I think it loop only one variables instead of the whole lengths
Oh, I see. That variable will only contain one element. Your [store_locations] has an x and y, so that is the only location stored, which is not what you want I guess. Also, you can't use [filter_location] inside [store_locations], so that part is being ignored. With :inspect, you would have been able to see that loc_rand_for_sound_and_emb had only one element.

I suppose it's not obvious what an array would look like in :inspect if you've never seen one, but you could look at some simpler arrays to see the difference.
So, I will try to remove the filter location. But, I don't understand still why it worked at the first place if it is the case
User avatar
beetlenaut
Developer
Posts: 2827
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Saisons effects on maps

Post by beetlenaut »

hermestrismi wrote: March 8th, 2023, 12:26 am Inside the inspect, I saw all the arrays (with index from 0 to 4 as intended)
Oh, no, storing one location is what you want. I was misunderstanding what you were trying to do there. I didn't look through it carefully enough.
hermestrismi wrote: March 8th, 2023, 12:27 am I don't understand still why it worked at the first place if it is the case
It's because [random_placement] has its own location filter. I don't know if you can clear the variable [random_placement] is using inside its command block. That seems suspicious, but isn't the cause of all your problems.
hermestrismi wrote: March 8th, 2023, 12:26 am With every turn, a new label was added with a precise ID but no event except the first
If I understand you correctly, I see why that is now. You are using loc_rand_for_sound_and_emb like it's a regular variable in the [foreach] loop, so you are always getting only its first element in the [terrain] block. Actually, you should not be using the array inside the [foreach] in the first place. You should be referring to its elements with $this_item or whatever name you set with variable=.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
hermestrismi
Posts: 626
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: Saisons effects on maps

Post by hermestrismi »

beetlenaut wrote: March 8th, 2023, 12:57 am
hermestrismi wrote: March 8th, 2023, 12:26 am Inside the inspect, I saw all the arrays (with index from 0 to 4 as intended)
Oh, no, storing one location is what you want. I was misunderstanding what you were trying to do there. I didn't look through it carefully enough.
hermestrismi wrote: March 8th, 2023, 12:27 am I don't understand still why it worked at the first place if it is the case
It's because [random_placement] has its own location filter. I don't know if you can clear the variable [random_placement] is using inside its command block. That seems suspicious, but isn't the cause of all your problems.
hermestrismi wrote: March 8th, 2023, 12:26 am With every turn, a new label was added with a precise ID but no event except the first
If I understand you correctly, I see why that is now. You are using loc_rand_for_sound_and_emb like it's a regular variable in the [foreach] loop, so you are always getting only its first element in the [terrain] block. Actually, you should not be using the array inside the [foreach] in the first place. You should be referring to its elements with $this_item or whatever name you set with variable=.
I see.
Many things to consider and to understand.
So, basically, I need to extract the informations from the array of the random placement to another variable then extract the information and loop with the foreach. Am I correct?
That or I have to create a variable to assign a unique ID to the sound source and the terrain (for example, {VARIABLE_OP name_a rand "1..100}, {VARIABLE_OP name_b rand "100..500}, {VARIABLE_OP name_a_b "$name_a + $name_b"} . Then the ID of the sound became id=birds_$name_a_b ) and... well a long process.
Is there an expression for the [foreach] to make it loop through all the variables index of the loc_rand_for_sound_and_emb?
Edit: I saw only now that I cleared the variable of random_placement inside the command. Lool how did I missed that :augh: :augh:
User avatar
hermestrismi
Posts: 626
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: Saisons effects on maps

Post by hermestrismi »

I may learned one thing or two about WFL and Lua but still I always have problems with variables...
I have to ask myself if age made learning more and more hard but thank you wesnothian and thank you wesnoth. I am really happy that every time I check or ask or read, I learn something new. If I am a minister, I would make it a part of educational system for children
User avatar
beetlenaut
Developer
Posts: 2827
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Saisons effects on maps

Post by beetlenaut »

hermestrismi wrote: March 8th, 2023, 1:10 am Is there an expression for the [foreach] to make it loop through all the variables index of the loc_rand_for_sound_and_emb?
This is exactly what [foreach] does! I will try to explain it better than the wiki. Each time through the loop, [foreach] names the index it is using "this_item". The first time through the loop, $this_item will equal $loc_rand_for_sound_and_emb[0]. The second time, $this_item will equal $loc_rand_for_sound_and_emb[1], and so on. (You can change the name of "this_item" with variable= as I mentioned before.) You should not use the name "loc_rand_for_sound_and_emb" in the [foreach] loop. It is possible, but it won't always work the way you expect.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
hermestrismi
Posts: 626
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: Saisons effects on maps

Post by hermestrismi »

I gave up. It is a mind blowing . I don't even remember why I used this thing or what value for that thing. I will return later may be.
For now, this is a test scenario for anyone to test it for bugs or ameliorating. For now, it contains the terrain modifications cycle over seasons (turn 1 to turn 34)
Attachments
test2.rar
(168.77 KiB) Downloaded 19 times
User avatar
hermestrismi
Posts: 626
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: Saisons effects on maps

Post by hermestrismi »

Eureka
as a revelation, I find out what was my fault.
I was complicated things trying to work with {FOREACH} as it is just the same as [foreach] (the wiki was clear but I didnt pay attention.
And, voilà!

Code: Select all

	[event]
		name=side 1 turn refresh
		first_time_only=no
			[store_time_of_day]
			[/store_time_of_day]
					[random_placement]
						num_items=1
						variable=loc_rand_for_sound
						allow_less=no
						min_distance=3
						[filter_location]
							terrain="*^Fet*,*^Ft*,*^Fp*"
						[/filter_location]
						[command]
							[store_locations]
								x,y=$loc_rand_for_sound.x,$loc_rand_for_sound.y
								variable=loc_rand_for_sound_and_emb
								mode=append
							[/store_locations]
						[/command]
					[/random_placement]
					{CLEAR_VARIABLE loc_rand_for_sound}
					
		{FOREACH loc_rand_for_sound_and_emb i}
			{SET_LABEL "$loc_rand_for_sound_and_emb[$i].x" "$loc_rand_for_sound_and_emb[$i].y" ( _ "step twoa")}
			[switch]
				variable=time_of_day.id
				[case]
					value="dawn,morning,midday,afternoon"
							[terrain]
								x,y=$loc_rand_for_sound_and_emb[$i].x,$loc_rand_for_sound_and_emb[$i].y
								terrain=*^Iig
								layer=overlay
							[/terrain]
				[/case]
				[else]
					[terrain]
						x,y=$loc_rand_for_sound_and_emb[$i].x,$loc_rand_for_sound_and_emb[$i].y
						terrain=Gs^
						layer=overlay
					[/terrain]
				[/else]
			[/switch]

		{NEXT i}
	[/event]
Thank you very much beetlenaut. You just directed me to the problem in my procedure and my logic
User avatar
hermestrismi
Posts: 626
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: Saisons effects on maps

Post by hermestrismi »

It was very simple that I feel I was ridicule
User avatar
beetlenaut
Developer
Posts: 2827
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Saisons effects on maps

Post by beetlenaut »

You should change it to use [foreach] and $this_item instead of {FOREACH} and $loc_rand_for_sound_and_emb[]. That is because {FOREACH} is in deprecated-utils.cfg, so it could be removed at any moment. I don't expect it to exist in BfW 1.18.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
hermestrismi
Posts: 626
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: Saisons effects on maps

Post by hermestrismi »

like that:

Code: Select all

[indent][foreach]
        array=loc_rand_for_sound_and_emb
        variable=this_item
        [do]
....
        [/do]
    [/foreach][/indent]
    
User avatar
beetlenaut
Developer
Posts: 2827
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Saisons effects on maps

Post by beetlenaut »

Yes, but you don't need to put "this_item" in a variable= line because this_item is the default. Use $this_item in place of $loc_rand_for_sound_and_emb[$i] in the rest of the code.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
hermestrismi
Posts: 626
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: Saisons effects on maps

Post by hermestrismi »

beetlenaut wrote: March 8th, 2023, 7:38 pm Yes, but you don't need to put "this_item" in a variable= line because this_item is the default. Use $this_item in place of $loc_rand_for_sound_and_emb[$i] in the rest of the code.

Code: Select all

#define SPRING_EMBELL_AND_SOUNDS
			[store_time_of_day]
			[/store_time_of_day]
			[if]
				[variable]
					name=counter_sound_of_season
					less_than_equal_to=3
				[/variable]
				[then]
					[random_placement]
						num_items=1
						variable=loc_rand_for_sound
						allow_less=no
						min_distance=3
						[filter_location]
							terrain="*^Fet*,*^Ft*,*^Fp*"
						[/filter_location]
						[command]
							[store_locations]
								x,y=$loc_rand_for_sound.x,$loc_rand_for_sound.y
								variable=loc_rand_for_sound_and_emb
								mode=append
							[/store_locations]
					[set_variable]
						name=counter_sound_of_season
						add=1
					[/set_variable]
						[/command]
					[/random_placement]
					{CLEAR_VARIABLE loc_rand_for_sound}
				[/then]
			[/if]
			[foreach]
				array=loc_rand_for_sound_and_emb
				[do]		
				###	{SET_LABEL "$loc_rand_for_sound_and_emb[$i].x" "$loc_rand_for_sound_and_emb[$i].y" ( _ "step twoa")}
					[switch]
						variable=time_of_day.id
						[case]
							value="dawn_spring,morning_spring,midday_spring,afternoon_spring"
									[terrain]
										x,y=$this_item.x,$this_item.y
										terrain=*^Iig
										layer=overlay
									[/terrain]
							[sound_source]
								id=birds_$this_item.x|_$this_item.y
								x,y=$this_item.x,$this_item.y
								check_fogged=no
								check_shrouded=no
								sounds=ambient/birds1.ogg,ambient/birds2.ogg,ambient/birds3.ogg
								delay=6000
								chance=100
								full_range=11
								fade_range=2
								loop=-1
							[/sound_source]
						[/case]
						[else]
							[terrain]
								x,y=$this_item.x,$this_item.y
								terrain=Gs^
								layer=overlay
							[/terrain]
							[remove_sound_source]
								id=birds_$this_item.x|_$this_item.y
							[/remove_sound_source]
						[/else]
					[/switch]
				[/do]
			[/foreach]
#enddef
User avatar
beetlenaut
Developer
Posts: 2827
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Saisons effects on maps

Post by beetlenaut »

I don't see any obvious problems with this. Does it work the way you want now?
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
hermestrismi
Posts: 626
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: Saisons effects on maps

Post by hermestrismi »

beetlenaut wrote: March 10th, 2023, 9:14 pm I don't see any obvious problems with this. Does it work the way you want now?
yes. I am improving some details but it is not flawless. For example, when we have a {TWO_SUNS_SCHEDULES}, the player will not see that and there is no way to know if the scenario original set was about default or two suns schedules.
also, if the scenario is underground, D-underground or indoor, there is no elegant way to stop the loop since capturing time_of_day in prestart event is meaningless and the loop must begin before start (otherwise, the player will see the change of the schedules icon and the DBG msg about the first season cycle will not show. The only way to undo that is to not implies the code in scenarios other than DEFAULT_SCHEDULES
Those are the most updated version (in fact, they can be briefed into one file with one event "side x turn refresh" but I was lazy bit

And, I was trying to made a WFL to look for the muultiple of a number but I forget it

This is event trigger of the loop

Code: Select all

#define WEATHER_ROUNDS
			{WINTER_ACTIONS}
			{SPRING_ACTIONS}
			{SUMMER_ACTIONS}
[event]
	name=prestart
	[store_time_of_day]
	[/store_time_of_day]
	[if]
		[variable]
			name=weather_effects_sys
			equals=yes
		[/variable]
		[variable]
			name=time_of_day.id
			not_equals=indoors,underground,deep_underground
		[/variable]
		# no effect actually
		[then]
			[set_variable]
				name=rand_season_to_begin
				rand="winter,summer,spring"
			[/set_variable]
			[switch]
				variable=rand_season_to_begin
				[case]
					value=winter
					{VARIABLE seasons option_1}
						{VARIABLE round_1 1}
						{VARIABLE round_2 13}
						{VARIABLE round_3 26}
				[/case]
				[case]
					value=spring
					{VARIABLE seasons option_2}
						{VARIABLE round_2 1}
						{VARIABLE round_3 13}
						{VARIABLE round_1 26}
				[/case]
				[case]
					value=summer
					{VARIABLE seasons option_3}
						{VARIABLE round_3 1}
						{VARIABLE round_1 13}
						{VARIABLE round_2 26}
				[/case]
			[/switch]
			{CLEAR_VARIABLE rand_season_to_begin}
		[/then]
	[/if]
[/event]
[event]
	name=turn $round_1
		[set_variable]
			name=what_season_is_it
			value=season_is_winter
		[/set_variable]
[/event]
[event]
	name=turn $round_2
		[set_variable]
			name=what_season_is_it
			value=season_is_spring
		[/set_variable]
[/event]
[event]
	name=turn $round_3
		[set_variable]
			name=what_season_is_it
			value=season_is_summer
		[/set_variable]
[/event]
[event]
	name=victory
	{CLEAR_VARIABLE counter_sound_of_season,round_1,round_2,round_3,season_couldown,what_season_is_it,seasons,loc_rand_for_sound_and_emb,time_of_day}
[/event]
#enddef
Attachments
winter_mode.cfg
(9.06 KiB) Downloaded 21 times
summer_mode.cfg
(6.69 KiB) Downloaded 25 times
spring_mode.cfg
(8.24 KiB) Downloaded 19 times
general_weather_utils.cfg
(13.77 KiB) Downloaded 32 times
User avatar
hermestrismi
Posts: 626
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: Saisons effects on maps

Post by hermestrismi »

It is weird that the fourth file was downloaded 6 times while it contains only the general macros not those of the effects during such season
Post Reply