How to insert moveto events into randomly generated cave maps

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

How to insert moveto events into randomly generated cave maps

Post by LordAwsomeness »

Hi! I have been fiddling around with random cave map generation and am currently trying to find out how to make make moveto events work on them. there used to be some form of implementation for it in wml https://wiki.wesnoth.org/MapGeneratorWM ... _Generator however it seems like that no longer works as you can no longer insert events into the generator itself. How could i currently create moveto events tied directly to chambers? Even further: my goal is to create randomly generated cave maps with chance to spawn chambers and passageways that can be affected by events depending on if that particular chamber spawns or not.

here is some of the code i was trying. i dont honestly know how to use the same_location_as_previous=yes function.

Code: Select all

        [chamber]
            id=minichamber1
            x=2-8
            y=95-105
            size=5
            jagged=5
			chance=100
            {PASSAGE_NORMAL players 2 10 5}
			[event]
			name=moveto
			first_time_only=yes
			#same_location_as_previous=yes
			[filter]
				side=1,2,3,4,5,6
			[/filter]
			[narrate]
			message="Events in chambers are working!"
			[/narrate]
			[/event]
        [/chamber]
Included in the section is a comment about using [item_location] however there doesn't seem to be any documentation on how to use this.

EDIT: after poking around just a bit further, I have learned why using

Code: Select all

        [chamber]
            id=players
            x=35-45
            y=105
            size=8
            jagged=50
            [item_location]
                id = 1
            [/item_location]
            [item_location]
                id = 2
            [/item_location]
            [item_location]
                id = 3
            [/item_location]
            [item_location]
                id = 4
            [/item_location]
            [item_location]
                id = 5
            [/item_location]
            [item_location]
                id = 6
            [/item_location]
        [/chamber]
is able to place units in the proper chamber: it uses their underlying id. how do i use this for other things however? what are my limitations? can this be used for some sort of event?
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
Pilauli
Posts: 110
Joined: August 18th, 2020, 12:56 pm

Re: How to insert moveto events into randomly generated cave maps

Post by Pilauli »

I went and looked in the scenario file for the HttT scenario "The Sceptre of Fire"... it looks like the important parts MAY just go like this:

Code: Select all

        [chamber]
            # various stuff
            
            [item_location]
                id = sceptre
            [/item_location]
        [/chamber]

Code: Select all

    [event]
        name=moveto
        [filter]
            # Filter the unit that steps on the sceptre here
            [filter_location]
                location_id="sceptre"
            [/filter_location]
        [/filter]
        
       	# various stuff
    [/event]
It seems like it couldn't possibly be that simple, but I can't find any sort of location-id-setting, so I think that [item_location] may really be all you need to set it up properly.

Other snippets (hoisted out of the files and plunked here):
Spoiler:
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Re: How to insert moveto events into randomly generated cave maps

Post by LordAwsomeness »

Pilauli wrote: September 14th, 2020, 1:30 am I went and looked in the scenario file for the HttT scenario "The Sceptre of Fire"... it looks like the important parts MAY just go like this:

Code: Select all

        [chamber]
            # various stuff
            
            [item_location]
                id = sceptre
            [/item_location]
        [/chamber]

Code: Select all

    [event]
        name=moveto
        [filter]
            # Filter the unit that steps on the sceptre here
            [filter_location]
                location_id="sceptre"
            [/filter_location]
        [/filter]
        
       	# various stuff
    [/event]
It seems like it couldn't possibly be that simple, but I can't find any sort of location-id-setting, so I think that [item_location] may really be all you need to set it up properly.

Other snippets (hoisted out of the files and plunked here):
Spoiler:
thats so funny that you used that scenario cause thats actually how i figured out how to create the cave random generator!
Im dumb, i should have put that together that i could affect the items from that same code
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
User avatar
octalot
Developer
Posts: 521
Joined: July 17th, 2010, 7:40 pm
Location: Austria

Re: How to insert moveto events into randomly generated cave maps

Post by octalot »

LordAwsomeness wrote: September 13th, 2020, 9:26 pm How could i currently create moveto events tied directly to chambers?

Even further: my goal is to create randomly generated cave maps with chance to spawn chambers and passageways that can be affected by events depending on if that particular chamber spawns or not.
@gfgtdf, @CelticMinstrel, would it make sense for the mainline Lua cave map generator to create named areas corresponding to the generated chambers and passageways?

@LordAwsomeness I checked the code and confirm that [item_location]id= is added to the list for Standard Location Filter's location_id. If we added named areas to the map generation, then you could check if a chamber has spawned like this:

Code: Select all

[if]
    [has_location]
        # Note: this does not work with any of the mainline map generators (yet)
        area=chamber_name
    [/has_location]
    [then]
        ...
I'm not familiar with the map generation, but AFAICS it would be fairly easy for a 1.14 UMC to include a local backport of a 1.15.x version of the cave generator.
User avatar
Celtic_Minstrel
Developer
Posts: 1737
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: How to insert moveto events into randomly generated cave maps

Post by Celtic_Minstrel »

octalot wrote: September 14th, 2020, 8:58 am @LordAwsomeness I checked the code and confirm that [item_location]id= is added to the list for Standard Location Filter's location_id. If we added named areas to the map generation, then you could check if a chamber has spawned like this:
If this is the case, couldn't you also check like this?

Code: Select all

[if]
    [has_location]
        location_id=chamber_id
    [/has_location]
    [then]
        ...
[/quote]
octalot wrote: September 14th, 2020, 8:58 am @gfgtdf, @CelticMinstrel, would it make sense for the mainline Lua cave map generator to create named areas corresponding to the generated chambers and passageways?
It's an interesting idea. I think it should be an optional feature, though. I do have quite a bit of work in progress on the cave map generator so perhaps I'll think about adding this.

If the goal is to detect when someone enters a particular chamber, I think you could get an approximation even now by using location_id with a radius filter.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Re: How to insert moveto events into randomly generated cave maps

Post by LordAwsomeness »

octalot wrote: September 14th, 2020, 8:58 am @LordAwsomeness I checked the code and confirm that [item_location]id= is added to the list for Standard Location Filter's location_id. If we added named areas to the map generation, then you could check if a chamber has spawned like this:

Code: Select all

[if]
    [has_location]
        # Note: this does not work with any of the mainline map generators (yet)
        area=chamber_name
    [/has_location]
    [then]
        ...
I'm not familiar with the map generation, but AFAICS it would be fairly easy for a 1.14 UMC to include a local backport of a 1.15.x version of the cave generator.
THIS IS PERFECT! Thank you so much! you may have just saved me a whole bunch of time trying to figure this out!
Another thing im curious about, but dont believe is implemented: is there a way to have some chambers have a priority to spawn over others (not chance=100), I'm talking in the sense of if one chamber does not spawn from the generator, can i make a different chamber spawn somewhere else as a result of that (or just have a higher chance to spawn)?
Celtic_Minstrel wrote: September 14th, 2020, 1:17 pm If this is the case, couldn't you also check like this?

Code: Select all

[if]
    [has_location]
        location_id=chamber_id
    [/has_location]
    [then]
        ...
If the goal is to detect when someone enters a particular chamber, I think you could get an approximation even now by using location_id with a radius filter.
ill probably try both ways and see which works more conveniently. The approximation idea would probably work. Another idea i just came up with is maybe during the prestart use these methods to check and see if the areas have spawned. if yes, then in that area with a radius and filtering for walkable terrain it would place an item (such as a treasure chest) with a specific x-y coordinate. that way its less sloppy in the terms of the moveto event being used in a radius fashion.
Yet another idea i want to know if it is possible, is there a way to create gates that block doors? One of my ideas that ive used on non generated maps is blocking off certain entrances with gates that could only be opened if you A) had the generic key that would work on generic doors, or B) the door had to be opened by a very specific key that is assigned to that specific door. This function brings so much more depth to dungeon crawling and i feel that wesband really suffered in its linear playstyle from not having functions like this.

EDIT: also are future cave generations going to have procedurally generated terrains? Right now the lua cave generator from the scepter of fire that i pillaged only spawns cave floors, cave walls, and villages. It's kind of bland and lacks an actual living environment in my opinion. This isnt an issue for me as im quite well versed in most wml functions at this point. My solution was to simply create my own macro and change the SCATTER_EMBELLISHMENTS macro from being overlays only to replacing the entire terrain. It adds a lot more aesthetic appeal (once again, in my opinion) to cave maps.
Here is the base generator not adding any 'enviroment'
Here is the base generator not adding any 'enviroment'

Here is the code i used to create the more aesthetic environment in the prestart event:

Code: Select all

#rockbound caves spawning off of the cave floor, dirt, and dark dirt.
#same with sconces and mushrooms
{LA_SCATTER_EMBELLISHMENTS_ADJACENT Uu, Uh 1 Xu "n,ne,se,s,sw,nw" 25}
#sconces
{LA_SCATTER_EMBELLISHMENTS_ADJACENT2 Xu ^Efs 1 Uu "n,ne,se,s,sw,nw" 100}
#mushrooms
{LA_SCATTER_EMBELLISHMENTS_ADJACENT Xu ^Uf 1 Uu "n,ne,se,s,sw,nw" 10}
#dark dirt
{LA_SCATTER_EMBELLISHMENTS Uu Rb 28}
#regular dirt
{LA_SCATTER_EMBELLISHMENTS Uu Re 22}
#cave path
{LA_SCATTER_EMBELLISHMENTS Uu Ur 5}

#rockbound cave (not tied to the walls)
{LA_SCATTER_EMBELLISHMENTS Uu Uh 10}
#mushrooms (not tied to the walls and placed on dirt as well)
{SCATTER_EMBELLISHMENTS Uu,Rb,Re ^Uf 5}
#swamp
{LA_SCATTER_EMBELLISHMENTS Uu Ss 15}
#quagmire
#we only want this terrain to spawn next to swamps.
{LA_SCATTER_EMBELLISHMENTS_ADJACENT Uu Sm 1 Ss "n,ne,se,s,sw,nw" 50}
#swamp
{LA_SCATTER_EMBELLISHMENTS Uu Ss 15}
#dead forests
#we only want these to spawn next to swamps in the quagmire tiles
{LA_SCATTER_EMBELLISHMENTS_ADJACENT Uu,Ss,Sm ^Fdw 1 Sm "n,ne,se,s,sw,nw" 50}
#turn dead tree terrain into quagmire dead tree terrain
{LA_SCATTER_EMBELLISHMENTS Gll^Fdw Sm^Fdw 100}
#trash
#make it look like its been lived in
{SCATTER_EMBELLISHMENTS Uu,Rb,Re,Ss,Sm ^Edt 5}
#remains
#gives the aura of decay. perhaps in the future spawn even more next to mushrooms as to make the mushrooms look like theyre feeding off of the decay?
{SCATTER_EMBELLISHMENTS Uu,Rb,Re,Ss,Sm ^Edb 10}
Here is after my 'environment' has been added
Here is after my 'environment' has been added
Finally one last thing before i just overwhelm you guys with stuff: I am also curious if i could create lakes and rivers for underground maps with the cave generator. I tried using the default lakes and rivers commands with the defaut generator on it but it doesnt spawn any water as expected. Right now i am considering building a lake and water macro that would be based upon only spawning more water from the initial water spots. water can then only be spawned even further by limited it to only touching 2 or 3 other water tiles but also being required to touch more water so that it all stays connected. Im fairly confident that i can get it to work, but im slightly hesitant at the moment to do this because i wanted to ask before i dedicated the time to doing it myself. Plus i would probably end up using a [while] {VARIABLE_CONDITIONAL rand greater_than (number)} to make sure the lakes and rivers dont end up being the same exact amount of tiles each time.
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
gfgtdf
General Code Maintainer
Posts: 1344
Joined: February 10th, 2013, 2:25 pm

Re: How to insert moveto events into randomly generated cave maps

Post by gfgtdf »

octalot wrote: September 14th, 2020, 8:58 am @gfgtdf, @CelticMinstrel, would it make sense for the mainline Lua cave map generator to create named areas corresponding to the generated chambers and passageways?
While this does somewhat make sense, i personally i won't have the time to do it, also since [time_area] are not part of the raw 'map_data' you need to (at least in 1.14) use scenario_generation= instead of map_generation= then.

But since this is just a lua file any addon can just copy the cave map generatore lua file to their addon and make any modification to it that they want.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
Celtic_Minstrel
Developer
Posts: 1737
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: How to insert moveto events into randomly generated cave maps

Post by Celtic_Minstrel »

LordAwsomeness wrote: September 14th, 2020, 4:11 pm EDIT: also are future cave generations going to have procedurally generated terrains? Right now the lua cave generator from the scepter of fire that i pillaged only spawns cave floors, cave walls, and villages. It's kind of bland and lacks an actual living environment in my opinion. This isnt an issue for me as im quite well versed in most wml functions at this point. My solution was to simply create my own macro and change the SCATTER_EMBELLISHMENTS macro from being overlays only to replacing the entire terrain. It adds a lot more aesthetic appeal (once again, in my opinion) to cave maps.

[...snip...]

Finally one last thing before i just overwhelm you guys with stuff: I am also curious if i could create lakes and rivers for underground maps with the cave generator. I tried using the default lakes and rivers commands with the defaut generator on it but it doesnt spawn any water as expected. Right now i am considering building a lake and water macro that would be based upon only spawning more water from the initial water spots. water can then only be spawned even further by limited it to only touching 2 or 3 other water tiles but also being required to touch more water so that it all stays connected. Im fairly confident that i can get it to work, but im slightly hesitant at the moment to do this because i wanted to ask before i dedicated the time to doing it myself. Plus i would probably end up using a [while] {VARIABLE_CONDITIONAL rand greater_than (number)} to make sure the lakes and rivers dont end up being the same exact amount of tiles each time.
I have some work-in-progress on expanding the options in the cave generator, which makes more diverse terrain possible, including lakes, rivers, and roads. It probably won't be backported to 1.14, though.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Re: How to insert moveto events into randomly generated cave maps

Post by LordAwsomeness »

Celtic_Minstrel wrote: September 15th, 2020, 1:33 pm I have some work-in-progress on expanding the options in the cave generator, which makes more diverse terrain possible, including lakes, rivers, and roads. It probably won't be backported to 1.14, though.
Not that big of a deal. Ive been able to manage with my own adaptations as is so while more tools right now would be nice, I probably have enough stuff to keep me busy for quite a while anyways while that stuff gets developed. Thank you all for the kind and relatively quick responses!
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
Post Reply