Coding Unit Movement = 0

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
CraZCanuck
Posts: 9
Joined: November 6th, 2020, 4:45 am

Coding Unit Movement = 0

Post by CraZCanuck »

Hi all,

Looking to make a specific type of unit on the enemy side not be able to move at all from their position throughout the scenario. In a previous scenario I have successfully used the following code to freeze an ai leader, but I would like to rework this code to work on other enemies.

Code: Select all

	[event]
		name=side 1 turn 1
                [store_unit]
                    [filter]
                        side=2
                    [/filter]
                    variable=aileaders
                [/store_unit]
                {FOREACH aileaders i}
                    [object]
                        silent=yes
                        [filter]
                            id=$aileaders[$i].id
                        [/filter]
				[effect]
					apply_to=movement
					set=0
				[/effect]
                    [/object]
                {NEXT i}
                {CLEAR_VARIABLE aileaders}
	[/event] 
	
Alternately, if there is better code that can be used here, please feel free to enlighten me. :) Any help would be greatly appreciated!! Thanks so much in advance.
User avatar
WhiteWolf
Forum Moderator
Posts: 739
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: Coding Unit Movement = 0

Post by WhiteWolf »

The unit storing and the for loop seems kinda redundant to me. You could just copy the contents of the [store_unit]'s filter to the [object]'s filter and then get rid of the [store_unit] and the enclosing for loop.
You then just filter there for the specific type of unit you want to freeze.

Other than that, I don't think there's a much better approach than this (but who knows, maybe someone will tell otherwise). In general, [object]s are very good because they are easy to keep track of - if you give it an id you can remove them whenever you want, and you could also specify duration=scenario, since you said you only want to freeze the units for the scenario. (Not specified duration means 'forever' by default).
Author of the Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now for 1.14, with new bugs!
Shiki
Developer
Posts: 317
Joined: July 13th, 2015, 9:53 pm
Location: Germany

Re: Coding Unit Movement = 0

Post by Shiki »

Hi

There's not much needed to be done differently. First of all, the code above does not change the movement of an ai leader, but of all of side 2's units. Though, as it happens before side 2 recruited, the movement restricting object will only be given to the leader.
You could fire the code at a later point, like turn 2.
Or, always when a unit is placed – and change the [filter].
And I agree with White Wolf, if can be easier:

Code: Select all

[event]
    name=unit placed
    first_time_only=no

    [object]
        duration=scenario
        [filter]
            id=$unit.id # just this one unit which was just placed
        [/filter]
        [effect]
            apply_to=movement
            set=0
        [/effect]
    [/object]
[/event] 
The unit variable is one of a few automatically available variables:
https://wiki.wesnoth.org/SyntaxWML#Auto ... _Variables
Try out the dark board theme.
CraZCanuck
Posts: 9
Joined: November 6th, 2020, 4:45 am

Re: Coding Unit Movement = 0

Post by CraZCanuck »

Thanks guys! Super helpful!
User avatar
lhybrideur
Posts: 174
Joined: July 9th, 2019, 1:46 pm

Re: Coding Unit Movement = 0

Post by lhybrideur »

Shiki wrote: November 17th, 2020, 8:51 pm Hi

There's not much needed to be done differently. First of all, the code above does not change the movement of an ai leader, but of all of side 2's units. Though, as it happens before side 2 recruited, the movement restricting object will only be given to the leader.
You could fire the code at a later point, like turn 2.
Or, always when a unit is placed – and change the [filter].
And I agree with White Wolf, if can be easier:

Code: Select all

[event]
    name=unit placed
    first_time_only=no

    [object]
        duration=scenario
        [filter]
            id=$unit.id # just this one unit which was just placed
        [/filter]
        [effect]
            apply_to=movement
            set=0
        [/effect]
    [/object]
[/event] 
The unit variable is one of a few automatically available variables:
https://wiki.wesnoth.org/SyntaxWML#Auto ... _Variables
Don't you also need a side=2 inside the filter ?
vghetto
Posts: 356
Joined: November 2nd, 2019, 5:12 pm

Re: Coding Unit Movement = 0

Post by vghetto »

You could use a side X turn refresh event with first_time_only=no. Then use modify_unit or MODIFY_UNIT to set the moves and maybe the attacks_left to 0. No object needed that way.
Post Reply