excluding terrain (villages) in [terrain] when changing terrain

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
Gwledig
Posts: 569
Joined: March 30th, 2009, 5:10 pm
Location: UK

excluding terrain (villages) in [terrain] when changing terrain

Post by Gwledig »

hi I have some WML where an 'engineer' type unit can be used to transform terrain using [terrain] e.g. to create a cobbled area, or build a bridge, i have only just noticed that this also changes villages into the desired terrain.... so I need to exclude village tiles so they remain as villages (and owned by the player owning them), this is what I am trying, bear in mind this is a macro, re-used by a menu list where the player can choose from different terrains to 'engineer', I've tried lots of combinations...

any ideas appreciated...

Code: Select all

#add terrain change code here
[terrain]
[and]
[filter]
x,y=$x1,$y1
side=$side_number
role=Worker
[/filter]
terrain=*^*  # here is the filter criterion
[/and]
terrain={TERRAIN_CODE} # and the new terrain

#ATTEMPT TO EXCLUDE VILLAGES FROM TRANSFORMATION
[not]
terrain=*^V*
[/not]
#ATTEMPT TO EXCLUDE VILLAGES FROM TRANSFORMATION

radius={RADIUS}
[/terrain]
...I also have similar WML like a gooey blob spell in another mod which will need similar exclusion, so thanks for any thoughts.....
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)
User avatar
Ravana
Forum Moderator
Posts: 3002
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: excluding terrain (villages) in [terrain] when changing terrain

Post by Ravana »

Debug your filter. Split different parts into separate [store_locations] and inspect and if they work as expected, combine them in [terrain] with find_in.
User avatar
Gwledig
Posts: 569
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: excluding terrain (villages) in [terrain] when changing terrain

Post by Gwledig »

cant it just be excluded?

https://wiki.wesnoth.org/StandardLocati ... g_Terrains

Code: Select all

#add terrain change code here
[terrain]
[and]
[filter]
x,y=$x1,$y1
side=$side_number
role=Worker
[/filter]
terrain=!,*^V*  # here is the filter criterion
[/and]

terrain={TERRAIN_CODE} # and the new terrain
radius={RADIUS}

[/terrain]
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)
User avatar
beetlenaut
Developer
Posts: 2825
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: excluding terrain (villages) in [terrain] when changing terrain

Post by beetlenaut »

I'm sure it can be excluded, but it's not obvious to me what the problem is just by looking at the code. However, to figure it out, I would do exactly what Ravana suggested. I think you could solve many of your problems yourself if you used debugging tricks like that, but sometimes it seems like you are reluctant to try them. (And indent your code. It helps you and us read it.)
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
sergey
Posts: 475
Joined: January 9th, 2015, 9:25 pm

Re: excluding terrain (villages) in [terrain] when changing terrain

Post by sergey »

Radius may cause problems. https://wiki.wesnoth.org/StandardLocati ... dius_Usage

Radius is applied after all other criteria matches. If worker stands on a non-village terrain, but there is a village within the radius - it will match your filter.
Author of SP scenario Dragon Fight and SP campaign Captured by a Nightmare.
Created The Rise of Wesnoth (alternative mechanics) version of the mainline campaign.
User avatar
Gwledig
Posts: 569
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: excluding terrain (villages) in [terrain] when changing terrain

Post by Gwledig »

This does the job it looks like layer=base is needed, because presumably villages are overlays and still sit on the proper terrain, the terrain filter in [and] doesn't seem to be needed.

Code: Select all

#add terrain change code here
[terrain]

[and]
[filter]
x,y=$x1,$y1
side=$side_number
role=Worker
[/filter]

# unused.....   terrain=!,*^V*  # here is the filter criterion
[/and]
layer=base

terrain={TERRAIN_CODE} # and the new terrain
radius={RADIUS}

[/terrain]
I'm afraid I have very little time which is probably why my mods use macros to automate a lot of stuff, to be honest I've never been a fan of indenting, unless decrypting vast lists of almost identical nested stuff. I do use exclusion a lot to debug and have used the debug switch on startup, inspect etc. and the log, but the biggest thing for Wesnoth is just getting the basic syntax, the wiki often provides a kind of narrative which can be open to interpretation, you then need to track down examples, which can sometimes be hard to find.
Last edited by Gwledig on August 31st, 2019, 5:26 pm, edited 1 time in total.
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)
User avatar
Gwledig
Posts: 569
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: excluding terrain (villages) in [terrain] when changing terrain

Post by Gwledig »

Yep I do want to apply radius because it's a kind of land engineering ability to convert terrain.
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)
Post Reply