How to get AI to move to a specific location?

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
cool evil
Posts: 244
Joined: September 13th, 2007, 10:56 pm

How to get AI to move to a specific location?

Post by cool evil »

I had this problem when i was trying out new ways to use WML, in an event, i want the AI's units to move to a specific location, say x,y=20,20, and after it moved there, it would trigger the event which makes defeats the enemy. I know all the events and filter tags, but as far as i searched on the wiki, the closest to this is the [target] WML, but it only allows AI's unit to target it's attack on a certain enemy unit, like the one used in Elves Besieged. Is there anyway i could make the AI unit to move to a certain location?
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Post by zookeeper »

The only way to really force AI movement is to set the goto_x and goto_y keys of a unit by hand in an ai turn event. Like this:

Code: Select all

[event]
    name=ai turn
    first_time_only=no

    [if]
        [variable]
            name=side_number
            equals=3 # assuming the AI unit's side is 3
        [/variable]

        [then]
            [store_unit]
                [filter]
                    description=my_ai_unit
                [/filter]

                kill=no
                variable=stored_my_ai_unit
            [/store_unit]

            {VARIABLE stored_my_ai_unit.goto_x 8}
            {VARIABLE stored_my_ai_unit.goto_y 35}

            [unstore_unit]
                variable=stored_my_ai_unit
                find_vacant=no
            [/unstore_unit]

            {CLEAR_VARIABLE stored_my_ai_unit}
        [/then]
    [/if]
[/event]
The above forces the unit to always try to move towards 8,35. Doesn't prevent it from attacking either I think, if it happens to land next to an enemy.
toms
Posts: 1717
Joined: November 6th, 2005, 2:15 pm

Post by toms »

Out of curiousity: What happens if an enemy is standing on the given coordinates? Does the unit stop before the enemy or what?
First read, then think. Read again, think again. And then post!
User avatar
Iris
Site Administrator
Posts: 6798
Joined: November 14th, 2006, 5:54 pm
Location: Chile
Contact:

Post by Iris »

toms wrote:Out of curiousity: What happens if an enemy is standing on the given coordinates? Does the unit stop before the enemy or what?
If I read correctly (IIRC v2 ;)) it will replace it. As find_vacant=no.
Author of the unofficial UtBS sequels Invasion from the Unknown and After the Storm.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Post by zookeeper »

toms wrote:Out of curiousity: What happens if an enemy is standing on the given coordinates? Does the unit stop before the enemy or what?
Well, it still tries to go there. Obviously it can't though, so I guess it'll settle for one of the adjacent hexes then. It won't replace the other unit or anything like that.
User avatar
thespaceinvader
Retired Art Director
Posts: 8414
Joined: August 25th, 2007, 10:12 am
Location: Oxford, UK
Contact:

Post by thespaceinvader »

WIll it not do its best to clear the hex by attacking the unit occupying it?
http://thespaceinvader.co.uk | http://thespaceinvader.deviantart.com
Back to work. Current projects: Catching up on commits. Picking Meridia back up. Sprite animations, many and varied.
User avatar
cool evil
Posts: 244
Joined: September 13th, 2007, 10:56 pm

Post by cool evil »

I put the codes in like this, trying to get ai side 6,7,8 unit's to move to 6,35, i know i didn't fill in the my_ai_unit one so it didn't work, but i was wondering what do i have to put there to make every ai unit move to the location, if i put down specific units would it orders them to move?

Code: Select all

[event]
    name=ai turn
    first_time_only=no

    [if]
        [variable]
            name=6,7,8
            equals=6,7,8
        [/variable]

        [then]
            [store_unit]
                [filter]
                    description=my_ai_unit
                [/filter]

                kill=no
                variable=stored_my_ai_unit
            [/store_unit]

            {VARIABLE stored_my_ai_unit.goto_x 6}
            {VARIABLE stored_my_ai_unit.goto_y 35}

            [unstore_unit]
                variable=stored_my_ai_unit
                find_vacant=no
            [/unstore_unit]

            {CLEAR_VARIABLE stored_my_ai_unit}
        [/then]
    [/if]
[/event]
Rhuvaen
Inactive Developer
Posts: 1272
Joined: August 27th, 2004, 8:05 am
Location: Berlin, Germany

Post by Rhuvaen »

cool evil wrote:

Code: Select all

    [if]
        [variable]
            name=6,7,8
            equals=6,7,8
        [/variable]

        [then]
Yikes! 6,7,8 is not a variable name. Try side_number instead:

Code: Select all

    [if]
        [variable]
            name=side_number
            greater_than=5
        [/variable]
        [variable]
            name=side_number
            less_than=9
        [/variable]

        [then]
The "less_than=" part can probably be skipped, unless you actually have a side number 9.
User avatar
cool evil
Posts: 244
Joined: September 13th, 2007, 10:56 pm

Post by cool evil »

That didn't really answer my question. I was asking what do i have to put down on the "description=my_ai_unit"

It's still not working :(
Rhuvaen
Inactive Developer
Posts: 1272
Joined: August 27th, 2004, 8:05 am
Location: Berlin, Germany

Post by Rhuvaen »

cool evil wrote:i know i didn't fill in the my_ai_unit one so it didn't work, but i was wondering what do i have to put there to make every ai unit move to the location, if i put down specific units would it orders them to move?
Sorry, I think your phrasing threw me off the question and I went to look for answers in your code. :)

You just put side=$side_number in the filter. That would make every ai unit of that side (and the event fires for each side) move to the location.
Post Reply