How to prevent AI from moving?

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
PhantomJedi
Posts: 22
Joined: October 25th, 2013, 1:44 am

How to prevent AI from moving?

Post by PhantomJedi »

How would I go about preventing the AI from moving whatsoever? I have figured out how to do this with the AI leader, but not with the AI units.
Velensk
Multiplayer Contributor
Posts: 4002
Joined: January 24th, 2007, 12:56 am

Re: How to prevent AI from moving?

Post by Velensk »

One way you could do it is by giving all the AI units you don't want to move an [object] which sets their move to 0.
"There are two kinds of old men in the world. The kind who didn't go to war and who say that they should have lived fast died young and left a handsome corpse and the old men who did go to war and who say that there is no such thing as a handsome corpse."
PhantomJedi
Posts: 22
Joined: October 25th, 2013, 1:44 am

Re: How to prevent AI from moving?

Post by PhantomJedi »

Ok, I tried that, and I'm pretty sure my coding isn't correct:

Code: Select all

[modifications]
		[object]
			[effect]
				movement_set=0
			[/effect]
		[/object]		
[/modifications]
Edit:

I changed the code to:

Code: Select all

[modifications]
		[object]
			[effect]
				apply_to=movement
            set=0
			[/effect]
		[/object]		
[/modifications]
It doesn't work either.
User avatar
Crow_T
Posts: 851
Joined: February 24th, 2011, 4:20 am

Re: How to prevent AI from moving?

Post by Crow_T »

Code: Select all

[status]
guardian=yes
[/status]
Try this maybe?
User avatar
8680
Moderator Emeritus
Posts: 742
Joined: March 20th, 2011, 11:45 pm
Location: The past

Re: How to prevent AI from moving?

Post by 8680 »

I disclaim having any major knowledge of AiWML, but, theoretically, including…

Code: Select all

[ai]
    [avoid][/avoid]
[/ai]
…in the relevant [side] tag should forbid that side’s AI from moving any units anywhere, except for its leader, who you say you have already prevented from moving.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: How to prevent AI from moving?

Post by zookeeper »

One simple method:

Code: Select all

[event]
    name=side 2 turn refresh
    first_time_only=no

    {MODIFY_UNIT side=2 moves 0}
[/event]
You can add a [filter_condition] if you don't want it to always be active.
PhantomJedi
Posts: 22
Joined: October 25th, 2013, 1:44 am

Re: How to prevent AI from moving?

Post by PhantomJedi »

Thank you all for your suggestions. I will try those, and see if they work with what I am attempting to do.
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: How to prevent AI from moving?

Post by Anonymissimus »

The easiest method is setting [side]controller= to null. It can be switched back and forth by [modify_side]controller=, and doesn't need a side turn event to run and modify unit movement points on every turn. However, setting controller=null makes the engine ignore any side turn (and similar) events for the particular side, so don't be surprised that they aren't fired if you have any.
[side][ai]ai_algorithm=idle_ai works, but cannot be modified, due to a bug.
A third pseudo-method is to take away all gold an income and/or the recruit list The remaining leader will just sit in his keep and do nothing, with the default ai.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
PhantomJedi
Posts: 22
Joined: October 25th, 2013, 1:44 am

Re: How to prevent AI from moving?

Post by PhantomJedi »

Well, the AI has units, and I have prevented the leader from moving; I just need the units to stand still until an event is fired that will make them aggressive and let them move.
User avatar
Bob_The_Mighty
Posts: 870
Joined: July 13th, 2006, 1:15 pm

Re: How to prevent AI from moving?

Post by Bob_The_Mighty »

I had this same problem once. As it happens, it was my first forum post. I wanted to keep Ivan The Blackheart, a bandit in Fall of Trent, from moving until the players got near. Amusingly, zookeeper offered the same solution as he's done here. However, the method I ended up using was to make Ivan unable to move on any of the surrounding terrain.

Code: Select all

    [object]
		silent=yes
		duration=forever
		[filter]
			name="Ivan The Blackheart"
		[/filter]
		[effect]
			apply_to=movement_costs
			replace=true
			[movement_costs]
				flat={UNREACHABLE}
			[/movement_costs]
		[/effect]
	[/object]
You can then reallow movement with this:

Code: Select all

    [object]
		silent=yes
		duration=forever
		[filter]
			name="Ivan The Blackheart"
		[/filter]
		[effect]
			apply_to=movement_costs
			replace=true
			[movement_costs]
				flat=1
			[/movement_costs]
		[/effect]
	[/object]
You can always put more terrain types inside the [movement_costs] tag. If you don't want to worry about their surrounding terrain, you can prevent them from moving on all possible terrain types.

Code: Select all

   [object]
		silent=yes
		duration=forever
     [filter]
         whatever=whatever
     [/filter]
		[effect]
			apply_to=movement_costs
			replace=true
			[movement_costs]
				deep_water={UNREACHABLE}
				shallow_water={UNREACHABLE}
				reef={UNREACHABLE}
				swamp_water={UNREACHABLE}
				flat={UNREACHABLE}
				castle={UNREACHABLE}
				sand={UNREACHABLE}
				forest={UNREACHABLE}
				hills={UNREACHABLE}
				mountains={UNREACHABLE}
				village={UNREACHABLE}
				cave={UNREACHABLE}
				frozen={UNREACHABLE}
				unwalkable={UNREACHABLE}
				impassable={UNREACHABLE}
				fungus={UNREACHABLE}
			[/movement_costs]
		[/effect]
	[/object]
Hope that helps.
My current projects:
MP pirate campaign: The Altaz Mariners
RPG sequel: Return to Trent
MP stealth campaign: Den of Thieves
PhantomJedi
Posts: 22
Joined: October 25th, 2013, 1:44 am

Re: How to prevent AI from moving?

Post by PhantomJedi »

Ok, the [side] controller=null method will not work. It doesn't spawn the leader, and like was said, none of the events involving the side fire. I'll try the object method again.

Edit:

The object method still didn't work.

Code: Select all

					[unit]
						type=Villager
						id=Eostysu
						name=_"Eostysu"
						x=17
						y=14
						side=2
						random_traits=no
						[modifications]
							[object]
          						silent=yes
          						duration=forever
          						[filter]
          							id=Eostysu
          						[/filter]	
          						[effect]
            						apply_to=movement_costs
             						replace=true
             						[movement_costs]
                						deep_water={UNREACHABLE}
                						shallow_water={UNREACHABLE}
                						reef={UNREACHABLE}
                						swamp_water={UNREACHABLE}
                						flat={UNREACHABLE}
                						castle={UNREACHABLE}
                						sand={UNREACHABLE}
                						forest={UNREACHABLE}
                						hills={UNREACHABLE}
            							mountains={UNREACHABLE}
            							village={UNREACHABLE}
            							cave={UNREACHABLE}
            							frozen={UNREACHABLE}                 							
            							unwalkable={UNREACHABLE}
                						impassable={UNREACHABLE}
                						fungus={UNREACHABLE}
             						[/movement_costs]
          						[/effect]
       						[/object]
							{TRAIT_LOYAL}
						[/modifications]
						{IS_LOYAL}
					[/unit]
User avatar
trewe
Translator
Posts: 122
Joined: December 24th, 2012, 5:37 pm
Location: Portugal
Contact:

Re: How to prevent AI from moving?

Post by trewe »

Yes, with controller=null you have to spam the leader by hand with [unit]canrecruit=yes.

Did setting the moves of all side units to zero in a turn refresh event not work?

Another alternative, you can end the ai turn as soon it starts

Code: Select all

[event]
   name=side 2 turn
   first_time_only=no
   [end_turn][/end_turn]
[/event]
Add an filter_condition if it should not fire all the time.
Post Reply