dabber's questions: vision to location
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.
- beetlenaut
- Developer
- Posts: 2827
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: dabber's questions: unique object ids
You can replace substrings in WFL.
https://wiki.wesnoth.org/Wesnoth_Formul ... ge#replace
https://wiki.wesnoth.org/Wesnoth_Formul ... ge#replace
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Re: dabber's questions: unique object ids
It seems I don't understand properly. I thought the below did that in compliance with the wiki, but the object does not get removed from anyone. Can you explain what's wrong?
Code: Select all
#define RESTRICT_TO_KEEP_MODIFY_OBJECT_REMOVE UNIT_ID
[modify_unit]
[filter]
id={UNIT_ID}
[/filter]
[remove_object]
id={UNIT_ID}
object_id=restrict_to_keep
[/remove_object]
[/modify_unit]
#enddef
#define RESTRICT_TO_KEEP_MODIFY_OBJECT UNIT_ID
[modify_unit]
[filter]
id={UNIT_ID}
[/filter]
[object]
id=restrict_to_keep
[effect]
apply_to=movement_costs
replace="yes"
[movement_costs]
flat={UNREACHABLE}
[/movement_costs]
[/effect]
[/object]
[/modify_unit]
#enddef
Thank you. I had not found that page on my own.beetlenaut wrote: ↑September 19th, 2023, 7:11 pmYou can replace substrings in WFL.
https://wiki.wesnoth.org/Wesnoth_Formul ... ge#replace
But it also means there isn't a "single function" to replace spaces with underscores - I have to while loop, find, replace.
- beetlenaut
- Developer
- Posts: 2827
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: dabber's questions: unique object ids
It's shorter than that. It's a while loop that creates objects with IDs made using a formula with concatenate() and replace(). That should be just a few lines.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Re: dabber's questions: unique object ids
That doesn't look right - isdabber wrote: ↑September 20th, 2023, 6:26 amCode: Select all
#define RESTRICT_TO_KEEP_MODIFY_OBJECT_REMOVE UNIT_ID [modify_unit] [filter] id={UNIT_ID} [/filter] [remove_object] id={UNIT_ID} object_id=restrict_to_keep [/remove_object] [/modify_unit] #enddef
[remove_object]
allowed inside [modify_unit]
?Re: dabber's questions: unique object ids
thedabber wrote: ↑September 20th, 2023, 6:26 amIt seems I don't understand properly. I thought the below did that in compliance with the wiki, but the object does not get removed from anyone. Can you explain what's wrong?Code: Select all
#define RESTRICT_TO_KEEP_MODIFY_OBJECT_REMOVE UNIT_ID [modify_unit] [filter] id={UNIT_ID} [/filter] [remove_object] id={UNIT_ID} object_id=restrict_to_keep [/remove_object] [/modify_unit] #enddef #define RESTRICT_TO_KEEP_MODIFY_OBJECT UNIT_ID [modify_unit] [filter] id={UNIT_ID} [/filter] [object] id=restrict_to_keep [effect] apply_to=movement_costs replace="yes" [movement_costs] flat={UNREACHABLE} [/movement_costs] [/effect] [/object] [/modify_unit] #enddef
[remove_object]
goes outside of [modify_unit]
(like before) only the [object]
goes into [modify_unit]
While this is certainly possible, it's not that trivial to do, since replace() (according to the linked page at least) only works by offset which need to be calculated first, and cannot directly replace occurances of a string with something else.beetlenaut wrote: ↑September 20th, 2023, 9:05 am It's shorter than that. It's a while loop that creates objects with IDs made using a formula with concatenate() and replace(). That should be just a few lines.
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.
Re: dabber's questions: store reachable location
How do I determine if a location is empty? This seems like it should be simple, but I'm not finding it.
I can pre-populate a castle so it is full at the start of the game. But if some random other unit is in the castle, I want to not drop a new unit on top of it, because the new unit then bounces out of the castle. I thought checking vs movement would remove those spots, because you cannot move on top of another unit, but it doesn't. I thought I could add a [filter_location][filter] layer, but that didn't work.
This is the core of what I'm using to find locations. How do I exclude locations with a unit?
In case you are curious, this is the whole macro:
I can pre-populate a castle so it is full at the start of the game. But if some random other unit is in the castle, I want to not drop a new unit on top of it, because the new unit then bounces out of the castle. I thought checking vs movement would remove those spots, because you cannot move on top of another unit, but it doesn't. I thought I could add a [filter_location][filter] layer, but that didn't work.
This is the core of what I'm using to find locations. How do I exclude locations with a unit?
Code: Select all
## lock leader into castle, then find where he can move
{RESTRICT_TO_KEEP_OBJECT $populate_recruiter.id}
## give leader enough movement to get anywhere in castle
{MODIFY_UNIT id=$populate_recruiter.id moves 20}
[store_reachable_locations]
[filter]
id=$populate_recruiter.id
[/filter]
moves=current
variable=populate_castle
viewing_side={SIDE}
[/store_reachable_locations]
In case you are curious, this is the whole macro:
Spoiler:
Re: dabber's questions: store reachable location
[filter_location][not][filter]
Re: dabber's questions: store reachable location
Thanks. I'm sure I'm missing something, but this seems to accomplish the goal.
I thought I could use an empty inner filter to mean all units, but that gave an error. Adding the [not] side=1 [/not] fixed it, although I don't like it. Isn't a standard unit filter that returns all units just [filter] [/filter] with nothing inside?
I was wrong. I must have messed up in another way. That does work.
Code: Select all
[store_reachable_locations]
[filter]
id=$populate_recruiter.id
[/filter]
[filter_location]
[not]
[filter]
[not]
side=1
[/not]
[/filter]
[/not]
[/filter_location]
moves=current
variable=populate_castle
viewing_side={SIDE}
[/store_reachable_locations]
I was wrong. I must have messed up in another way. That does work.
Last edited by dabber on September 27th, 2023, 6:29 pm, edited 1 time in total.
Re: dabber's questions: store reachable location
I thought so too, not sure why it didnt work here.
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.
Re: dabber's questions: store reachable location
I apologize for wasting your time. Apparently [filter] [/filter] does work. I thought I tried that yesterday and it didn't work. I definitely tried it today after Ravana's post and it didn't work. But I try it now and it does work.
Big code:
Big code:
Code: Select all
#define PRE_POPULATE_KEEP_REACHABLE SIDE
[event]
name=side 1 turn 1
## find a leader (only supports one leader)
[store_unit]
[filter]
canrecruit=true
side={SIDE}
[filter_location]
terrain=K*
[/filter_location]
[/filter]
variable=populate_recruiter
[/store_unit]
[if]
[variable]
name=populate_recruiter.length
greater_than=0
[/variable]
[then]
## lock leader into castle, then find where he can move
{RESTRICT_TO_KEEP_OBJECT $populate_recruiter.id}
## give leader enough movement to get anywhere in castle
{MODIFY_UNIT id=$populate_recruiter.id moves 20}
[store_reachable_locations]
[filter]
id=$populate_recruiter.id
[/filter]
## filter out locations with any unit
[filter_location]
[not]
[filter]
[/filter]
[/not]
[/filter_location]
moves=current
variable=populate_castle
viewing_side={SIDE}
[/store_reachable_locations]
## return leader to normal movement
{RESTRICT_TO_KEEP_OBJECT_REMOVE $populate_recruiter.id}
## no need to change movement back because that will naturally reset on turn
## grab side in order to get recruit list
[store_side]
side={SIDE}
variable=this_side
[/store_side]
## put recruits into those locations, subtracting gold along the way
[foreach]
array=populate_castle
[do]
[if]
[variable]
name=this_item.x
not_equals=$populate_recruiter.x
[/variable]
[or]
[variable]
name=this_item.y
not_equals=$populate_recruiter.y
[/variable]
[/or]
[then]
{VARIABLE_OP recruit_string rand $this_side.recruit}
[unit]
type=$recruit_string
x,y=$this_item.x,$this_item.y
random_traits=yes
side={SIDE}
[/unit]
[store_unit_type]
type=$recruit_string
variable=recruited_type
[/store_unit_type]
{VARIABLE gold_spent $recruited_type.cost}
{VARIABLE_OP gold_spent multiply -1}
[gold]
side={SIDE}
amount=$gold_spent
[/gold]
[/then]
[/if]
[/do]
[/foreach]
[/then]
[/if]
{CLEAR_VARIABLE populate_recruiter,populate_castle,this_side,recruit_string,recruited_type,gold_spent}
[/event]
#enddef
Re: dabber's questions: losing leader but keeping villages
When I remove the canrecruit ability from the one unit that can recruit (in an event), that side instantly loses all its villages. Is there a way to prevent that? The side is going to regain a leader later.
Re: dabber's questions: store reachable location
Not really. You can have fake/unreachable leader. Or you can store the villages and recapture them later.
Re: dabber's questions: vision to location
Is there a way to trigger an event based on visibility? Specifically, I want to trigger when a unit moves and is now able to see a specific location or a specific second unit. I don't see anything remotely close.
Last edited by dabber on January 23rd, 2024, 1:53 pm, edited 1 time in total.