No Movement Points

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
Into-Jesus
Posts: 40
Joined: June 17th, 2012, 8:03 pm

No Movement Points

Post by Into-Jesus »

In my campaign I want a unit to stand on a village and not move, but I want him to be able to attack if there is a unit standing next to him. I know how to use the ai_special=guardian, but that's not what I want. Can anyone help?
"The problem with Internet quotes is that you can never tell when they're true." - Ben Franklin

On Wesbreak
Ceres
Forum Regular
Posts: 620
Joined: September 18th, 2010, 7:56 pm
Location: Germany

Re: No Movement Points

Post by Ceres »

You could set the unit's max_moves to 0.
User avatar
junoslord
Posts: 82
Joined: June 11th, 2012, 3:13 pm
Location: Enveloping your left flank.

Re: No Movement Points

Post by junoslord »

I have a similar question to this I was going to post to a new thread... so apologies in advance-- not trying to hijack you. (If this should be it's own thread please let me know and I can start one.)

I want to do something where a unit is "stuck" in a defensive position, has movement (to escape if necessary, but also so it has a field of vision and can spot enemy units), but at the same time will basically fight and die in it's position unless it hits a certain % of it's HP remaining and will then try to flee.

This is sort of like the Heir to the Throne scenario where you are sneaking through the Heavy Infantryman in the forest... except if they see you, or you attack, they stay in their nice cozy turret and receive the defensive bonus.
America-- Land of the Free, home of the Brave! "And now that we've taken care of the Braves we're coming after the Free."

"BANNED!!! What the hell do you mean BANNED? All I did was call one narrow-minded, power-hungry Nazi moderator a narrow-minded, power-hungry Nazi!"
User avatar
Into-Jesus
Posts: 40
Joined: June 17th, 2012, 8:03 pm

Re: No Movement Points

Post by Into-Jesus »

If you use the tag "ai_special=guardian" as shown, that should fix your problem.

Code: Select all

		[unit]
			side=2
			type=Walking Corpse
			id=WC1
			canrecruit=no
			x,y=18,7
			ai_special=guardian
		[/unit]
"The problem with Internet quotes is that you can never tell when they're true." - Ben Franklin

On Wesbreak
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: No Movement Points

Post by mattsc »

Into-Jesus wrote:In my campaign I want a unit to stand on a village and not move, but I want him to be able to attack if there is a unit standing next to him. I know how to use the ai_special=guardian, but that's not what I want. Can anyone help?
If I understand you correctly, I'd set the moves to zero at the beginning of each turn for that. Such as this for the example of a unit on Side 2 with id 'test_unit' (untested, so it might contain typos):

Code: Select all

[event]
    name=side 2 turn refresh
    first_time_only=no
    [modify_unit]
        [filter]
            id=test_unit
        [/filter]
        moves=0
    [/modify_unit]
[/event]
Note that this has to be a variety of a turn refresh event, otherwise it won't work.
junoslord wrote:I want to do something where a unit is "stuck" in a defensive position, has movement (to escape if necessary, but also so it has a field of vision and can spot enemy units), but at the same time will basically fight and die in it's position unless it hits a certain % of it's HP remaining and will then try to flee.
Again, assuming I understand what you want correctly: you could use the same code as above (vision is set according to 'max_moves', not 'moves'), but put the [modify_unit] into an [if] statement that tests for hitpoints being above a certain level. For the fleeing part, you could then add an [else] clause in which you modify the unit to set goto_x, goto_y to the location you want the unit to flee to.

If you want a more complex behavior (e.g. fleeing to a location as far away from enemies as possible), you could either use more complicated WML code, or write a simple AI routine in either Formula AI or Lua AI. As an example, have a look at scenario 'Guardians' in the add-on campaign 'AI Modification Demos' (you can simply choose the scenario you want to look at). None of those guardians behaves exactly as you want it, but it should show you what can be done with simple custom AI code. (And if you can describe to me exactly what you want, I'd be happy to help with the coding.)
User avatar
Into-Jesus
Posts: 40
Joined: June 17th, 2012, 8:03 pm

Re: No Movement Points

Post by Into-Jesus »

I used the max_moves and that worked for what I needed. Thanks!
"The problem with Internet quotes is that you can never tell when they're true." - Ben Franklin

On Wesbreak
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: No Movement Points

Post by Elvish_Hunter »

Into-Jesus wrote:I used the max_moves and that worked for what I needed.
However, the main issue with such approach will be that, if the unit levels up, it will be able to move again. You have two ways to fix it:
1) use a post_advance event to set again max_moves=0 after the unit advances
2) give the unit a [object]:

Code: Select all

[object]
    duration=level
    silent=yes
    [effect]
        apply_to=movement
        set=0
    [/effect]
[/object]
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
User avatar
Into-Jesus
Posts: 40
Joined: June 17th, 2012, 8:03 pm

Re: No Movement Points

Post by Into-Jesus »

Okay, thanks. I'll use that just in case. Thanks for the info!
"The problem with Internet quotes is that you can never tell when they're true." - Ben Franklin

On Wesbreak
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: No Movement Points

Post by Dugi »

Elvish_Hunter wrote:...

Code: Select all

[object]
    duration=level
    silent=yes
    [effect]
        apply_to=movement
        set=0
    [/effect]
[/object]
I read somewhere that 0 movement causes 'strange infinite movement' and that to make all terrains unreachable for the unit instead, somewhere in the game macros, maybe a long time ago. Is 0 movement okay now?
User avatar
Into-Jesus
Posts: 40
Joined: June 17th, 2012, 8:03 pm

Re: No Movement Points

Post by Into-Jesus »

I'm not exactly sure what you mean. Do you know which is better?
"The problem with Internet quotes is that you can never tell when they're true." - Ben Franklin

On Wesbreak
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: No Movement Points

Post by Dugi »

If the movement=0 method works, there is no reason to try to set all terrains to unreachable. I just said that in a mainline scenario, it was written that it causes 'strange, infinite movement', but it might be an old information.
User avatar
Into-Jesus
Posts: 40
Joined: June 17th, 2012, 8:03 pm

Re: No Movement Points

Post by Into-Jesus »

Okay, makes sense. Thanks, everyone!
"The problem with Internet quotes is that you can never tell when they're true." - Ben Franklin

On Wesbreak
Post Reply