goto_x/y doesn't work with ai

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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
opensourcejunkie
Posts: 547
Joined: August 11th, 2008, 3:19 pm

goto_x/y doesn't work with ai

Post by opensourcejunkie » September 9th, 2008, 4:04 pm

I have a scenario in which I'm trying to control the movement of a few ai units. Basically, I use the goto_x and goto_y attributes of each unit to provide a specific location for them to walk toward.

Code: Select all

    ##|| Peasants Retreat To The Citadel
    [event]
        name=turn refresh
        first_time_only=no
        
        {IF_VAR side_number numerical_equals 3 (
            [then]
                {IF_VAR turn_number numerical_equals 1 (
                    [then]
                        {GENERIC_IDENTIFIABLE_UNIT p1 3 Peasant 22 41}
                        {GENERIC_IDENTIFIABLE_UNIT p2 3 Peasant 13 33}
                        {GENERIC_IDENTIFIABLE_UNIT p3 3 Peasant 38 43}
                    [/then]
                )}
                {IF_VAR turn_number numerical_equals 2 (
                    [then]
                        {GENERIC_IDENTIFIABLE_UNIT p4 3 Peasant 24 38}
                        {GENERIC_IDENTIFIABLE_UNIT p5 3 Peasant 36 24}
                        {GENERIC_IDENTIFIABLE_UNIT p6 3 Peasant 34 41}
                    [/then]
                )}
                {IF_VAR turn_number numerical_equals 3 (
                    [then]
                        {GENERIC_IDENTIFIABLE_UNIT p7 3 Peasant 36 32}
                    [/then]
                )}
                {IF_VAR turn_number less_than_equal_to 5 (
                    [then]
                        {MODIFY_UNIT (
                            type=Peasant
                            [not]
                                role=stationary # testing purposes
                            [/not]
                        ) goto_x 24}
                        {MODIFY_UNIT (
                            type=Peasant
                            [not]
                                role=stationary # testing purposes
                            [/not]
                        ) goto_y 30}
                    [/then]
                )}
            [/then]
        )}
    [/event]
Now, there is a point at which the player gains control of the ai side. The above code works perfectly when the controller=human, but while the ai controls, the peasants don't move. I would assume that this means that the ai ignores/overrides goto_x/y, but I remember reading a forum post in which someone accomplished a similar effect to move non-leader units around. (btw., if anyone knows where that post is, could you let me know? I can't seem to find it in the search.)

Any help you can provide is appreciated, thanks!
--OSJ
what if the Bible's claims about Christ depicted accurate, verifiable history? given some research, you might be surprised at the evidence...

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

Re: goto_x/y doesn't work with ai

Post by Rhuvaen » September 9th, 2008, 5:22 pm

This definitely works. I suppose a turn refresh is too late - the AI will already have calculated moves for its units. Use a side turn event or ai turn event instead.

AI
Developer
Posts: 2394
Joined: January 31st, 2008, 8:38 pm

Re: goto_x/y doesn't work with ai

Post by AI » September 10th, 2008, 9:52 am

That's probably it.

You can also merge the MODIFY_UNIT calls into one and give the arguments goto_x,goto_y and 24,30 instead.

opensourcejunkie
Posts: 547
Joined: August 11th, 2008, 3:19 pm

Re: goto_x/y doesn't work with ai

Post by opensourcejunkie » September 10th, 2008, 2:18 pm

ahh, yes; I'll have to try that. thanks!
--OSJ

Edit:
You can also merge the MODIFY_UNIT calls into one and give the arguments goto_x,goto_y and 24,30 instead.
Yeah, that's another trick I thought I remembered seeing somewhere. But when I tried it out, the peasants wouldn't move at all, so I assumed that {MODIFY_UNIT} couldn't work with that. I'll have to try that again, because it'll cut out a large macro's-worth of final code.
what if the Bible's claims about Christ depicted accurate, verifiable history? given some research, you might be surprised at the evidence...

opensourcejunkie
Posts: 547
Joined: August 11th, 2008, 3:19 pm

Re: goto_x/y doesn't work with ai

Post by opensourcejunkie » September 12th, 2008, 4:37 am

well, it turns out that side turn and ai turn disregard the peasant movement as well, sadly. Any other ideas? If not, the functionality isn't completely necessary; it just would be nice.
what if the Bible's claims about Christ depicted accurate, verifiable history? given some research, you might be surprised at the evidence...

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

Re: goto_x/y doesn't work with ai

Post by Rhuvaen » September 13th, 2008, 11:50 am

That's really strange, because the following code works just fine for me in UW (not tested in the new dev branch):

Code: Select all

  [event]
    name=side turn
    first_time_only=no
    [if]
      [variable]
        name=side_number
        numerical_equals=8
      [/variable]
      [then]
        {MODIFY_UNIT side=8 goto_x 31}
        {MODIFY_UNIT side=8 goto_y 35}
      [/then]
    [/if]
  [/event]
Perhaps there's some other problem with setting / unsetting the role in your code?

opensourcejunkie
Posts: 547
Joined: August 11th, 2008, 3:19 pm

Re: goto_x/y doesn't work with ai

Post by opensourcejunkie » September 15th, 2008, 4:14 am

strange...I can't think of what the problem would be. The only way that role would hinder the peasants from moving would be if each peasant's role=stationary. And I know that the code works as soon as the player is controlled by a human instead of ai.

At any rate, I coded a workaround, so it shouldn't be a problem. Thanks for the help!
--OSJ
what if the Bible's claims about Christ depicted accurate, verifiable history? given some research, you might be surprised at the evidence...

Post Reply