Anyone know how to make an AI unit stand still?

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.
User avatar
Bob_The_Mighty
Posts: 875
Joined: July 13th, 2006, 1:15 pm

Anyone know how to make an AI unit stand still?

Post by Bob_The_Mighty »

I'm making a multiplayer scenario and all i want is a computer-controlled unit to stay where it is when the players approach (thus luring them into a trap).

I've tried using the effect tag to reduce it's movement to zero, but i can't seem to get it right. The unit just keeps running into combat.

Can anyone help? An explantion of the effect tag might be useful even if that is not how to do it.
scott
Posts: 5248
Joined: May 12th, 2004, 12:35 am
Location: San Pedro, CA

Post by scott »

I would have to test it, but you can create the unit, change its movement costs to 99 for all terrains, then change them back to normal when you want it to move.

Code: Select all

[event]
name=start
	[unit]
	type=Orcish Grunt
	x,y=10,10
	side=2
	[/unit]

	[store_unit]
	variable=stationary_store
		[filter]
		x,y=10,10
		[/filter]
	[/store_unit]
	{VARIABLE stationary_store.movement_costs.grassland 99}
	{VARIABLE stationary_store.movement_costs.hills 99}
	{VARIABLE stationary_store.movement_costs.mountains 99}
	...etc... for every terrain around it
	[unstore_unit]
	variable=stationary_store
	[/unstore_unit]
[/event]

[event]
name=moveto
	[filter]
	side=1
	x=5-15
	y=5-15
	[/filter]
	[store_unit]
	variable=stationary_store
		[filter]
		x,y=10,10
		[/filter]
	[/store_unit]
	{VARIABLE stationary_store.movement_costs.grassland 1}
	{VARIABLE stationary_store.movement_costs.hills 1}
	{VARIABLE stationary_store.movement_costs.mountains 2}
	...etc... for every terrain around it
	[unstore_unit]
	variable=stationary_store
	[/unstore_unit]
[/event]
Hope springs eternal.
Wesnoth acronym guide.
User avatar
Bob_The_Mighty
Posts: 875
Joined: July 13th, 2006, 1:15 pm

Post by Bob_The_Mighty »

Thanks for the speedy reply but that doesn't work. At least not for me.

(maybe I've done something wrong elsewhere).

Is it possible to set movement to zero?

Could someone give me an example of an effect tag, with some indication of where it should be placed? (i.e. inside the unit tag or what?)

Thanks.
User avatar
Ken_Oh
Moderator Emeritus
Posts: 2178
Joined: February 6th, 2006, 4:03 am
Location: Baltimore, Maryland, USA

Post by Ken_Oh »

Yeah, setting its movement points to zero is easy. Here's one example:

Code: Select all

[event] 
     name=side turn
     first_time_only=no

     {MODIFY_UNIT x,y=10,10 moves 0}

[/event] 
The above will set a unit at coords 10,10 to 0 movement points at the beginning of each side's turn (you can set it so it's only on the side it needs to be, but I didn't want to complicate the code).

Things can get a little more lengthy if you don't want the unit to move only for a few turns, but don't hesitate to ask if you can't figure it out.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Post by zookeeper »

Ken Oh wrote:

Code: Select all

[event] 
     name=side turn
     first_time_only=no

     {MODIFY_UNIT x,y=10,10 moves 0}

[/event] 
Since it is an AI side unit, you probably need to use name=ai turn instead of name=side turn. Otherwise, this one should work nicely (assuming that you're running a relatively new version, of course).
wulf
Posts: 19
Joined: June 30th, 2005, 12:38 pm

Post by wulf »

try this. the wose will not move untill he can attack a players unit.
really ugly, if standing in a forest!
(side 7 must be ai controlled.)

Code: Select all

[unit]
               type=Wose
               generate_description=yes
               x=12
               y=13
               side=7
               ai_special=guardian
[/unit]
no borders, no nation
User avatar
Bob_The_Mighty
Posts: 875
Joined: July 13th, 2006, 1:15 pm

Post by Bob_The_Mighty »

Ken Oh wrote:

Code: Select all

[event] 
     name=side turn
     first_time_only=no

     {MODIFY_UNIT x,y=10,10 moves 0}

[/event] 
This doesn't work either, for some reason.

I've tried using both 'ai turn' and 'side turn', but the bloody bandit keep charging!

Any ideas?
User avatar
Ken_Oh
Moderator Emeritus
Posts: 2178
Joined: February 6th, 2006, 4:03 am
Location: Baltimore, Maryland, USA

Post by Ken_Oh »

What coordinates is he at? Only units at 10,10 will be effected by that macro.

You might want to post the whole scenario, since we've had this much trouble so far. :)
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Post by zookeeper »

I just heard that ai side turns were somehow broken in MP scenarios, meaning that still in 1.1.7 they won't work (in MP scenarios). This might explain the trouble you're having...have you tested by playing a local or a network game? If for some reason (unlikely, but you never know...) you haven't tried a local one (hotseat or vs ai), then I suggest you do so.

It might indeed be best to post the whole scenario at this point.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Post by Sapient »

zookeeper - true, but that C++ bug only affects the remote players. (by the way, that bug is fixed in svn, as well as in the EXE yogi bear provided in the DotM thread). Anyways, since this task only affects AI behavior, it shouldn't generate OOS.

The WML problem here is that side turn events fire before moves are restored from the last turn. The easiest way to force the unit to stand still is to give the unit a silent object that sets its movement to 0. Depending on what you are trying to acheive, the "ai_guardian" solution may suit your needs as well.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Swordy
Posts: 110
Joined: June 10th, 2005, 8:38 am

Post by Swordy »

this works for me.

Code: Select all

[object]
 silent=yes
 [filter]
  #your filter here
 [filter]
 [effect]
  apply_to=movement_costs
  replace=true
  [movement_costs]
   grassland=99
   shallow_water=99
   #more terrains here
  [/movement_costs]
 [/effect]
[/object]
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Post by Sapient »

Swordy wrote:this works for me.
Oh, yeah, that's the fancy way to do it. The advantage is that he will still show normal movement points in the status window. Thanks, Swordy.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
Bob_The_Mighty
Posts: 875
Joined: July 13th, 2006, 1:15 pm

Post by Bob_The_Mighty »

Thanks again for your help.

I've tried all the suggestions here, and still no joy.

Where should swordy's silent object bit go? On it's own, or in a seperate event? If so, what sort of event?

I have also tried doing the same thing in a test scenario, where there is not much else going on. But none of the suggestions work.

Is it because I'm using the 1.0.2 version?
Or some percularity with multiplayer mode?


Hmmm.
Rhuvaen
Inactive Developer
Posts: 1272
Joined: August 27th, 2004, 8:05 am
Location: Berlin, Germany

Post by Rhuvaen »

Bob_The_Mighty wrote:I've tried all the suggestions here, and still no joy.

Is it because I'm using the 1.0.2 version?
Umm, yes. 1.0.2 has nearly nowhere the same capabilities in terms of altering units than the development (and nearly done stable 1.2) have. Most advice you will get on the forums assume that you are working with the development version. If not, maybe state that fact.
Swordy
Posts: 110
Joined: June 10th, 2005, 8:38 am

Post by Swordy »

Oh sorry, I assumed you were using 1.1.7.

I strongly suggest you get the development version, since you're a campaign/scenario maker. There are lots of WML changes in the development version and we're so close to the release of new stable version (1.2). So you need to keep up! :wink:

And my [object] should go in an [event] tag. For example, if you want the AI unit to stand still from the beginning of the game, you can do it in a start event:

Code: Select all

[event]
name=start

[object]
...
[/object]
[/event]
Post Reply