Set goal for units

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
Blitzmerker
Posts: 50
Joined: March 20th, 2007, 5:44 pm
Location: Germany

Set goal for units

Post by Blitzmerker »

Hi,

is it possible to set a goal (target location) for a single unit? [goal] in [side] [ai] would be fine if it wouldn't apply to all units.

mfg
Blitzmerker
:(){ :|:& };:
User avatar
Heindal
Posts: 1353
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Re: Set goal for units

Post by Heindal »

As far as I know you can do that, but I never did it. In the wiki http://wiki.wesnoth.org/SingleUnitWML on the very end, the ai tag is mentioned as an option.

I know there is an ai_special to make a single unit behave differently, but I don't know if you can set this behaviour manually. So far I just know of guardian as behaviour - so enemies will just attack any unit inside its range. As a workaround you could create a new side for units with the same team name. But this just would just work for a couple of targets, as each target requires a single side.
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
User avatar
Blitzmerker
Posts: 50
Joined: March 20th, 2007, 5:44 pm
Location: Germany

Re: Set goal for units

Post by Blitzmerker »

Using [ai] [goal] in the unit tag is ignored. [ai_special] [goal] is ignored as well. So I guess I have to use the FormulaAI?!

mfg
Blitzmerker
:(){ :|:& };:
User avatar
Astoria
Inactive Developer
Posts: 1007
Joined: March 20th, 2008, 5:54 pm
Location: Netherlands

Re: Set goal for units

Post by Astoria »

you could use:

Code: Select all

[unit]
    [ai]
        formula="move(me.loc, loc(target_x, target_y))"
    [/ai]
[/unit]
with

Code: Select all

    [ai]
        version=10710
        [stage]
            engine=fai
            name=unit_formulas
        [/stage]
    [/ai]
in the side definition. (untested, just looking at the wiki)
Formerly known as the creator of Era of Chaos and maintainer of The Aragwaithi and the Era of Myths.
User avatar
Paulomat4
Moderator Emeritus
Posts: 730
Joined: October 16th, 2012, 3:32 pm
Location: Wesmere library, probably summoning Zhangor

Re: Set goal for units

Post by Paulomat4 »

if you are on 1.11 you should take a look at the micro Ais http://wiki.wesnoth.org/Micro_AIs
Creator of Dawn of Thunder and Global Unitmarkers

"I thought Naga's used semi-automatic crossbows with incendiary thermite arrows . . . my beliefs that this race is awesome are now shattered." - Evil Earl
User avatar
Blitzmerker
Posts: 50
Joined: March 20th, 2007, 5:44 pm
Location: Germany

Re: Set goal for units

Post by Blitzmerker »

I tested that, it sort of works. The ai now just trys to move the unit to loc_x, loc_y. It does not attack anything (even if an ememy unit is standing in loc_x, loc_y) and somehow the path finding is a bit crappy, the units line up, even if there is plenty of space next to the queue. It also ignores the [avoid]. I guess the attacking (and possibly the avoid) thing could be done with more FormulaAI, but I do not intend to write my own AI, that behaves just like the default ai, except that it should apply different [goal]s for a few special units.

I am not on 1.11 (yet, since 1.10 is stable and the version currently used by most players), but if there is no other way, I will have a look at that.

mfg
Blitzmerker
:(){ :|:& };:
User avatar
SkyOne
Posts: 1310
Joined: January 3rd, 2009, 7:23 pm

Re: Set goal for units

Post by SkyOne »

You can probably do it as "goto_x=" and "goto_y=" in the [unit] tag of the scenario. If the target moves itself, store him/her by using a [store_unit] tag in each turn, then clear the variable at the end of the turn. In this case, you don't have to touch the [ai]. Well, just an idea...
Fate of a Princess/feedback thread: "What is in own heart that is the most important, not who you are."
Drake Campaign: Brave Wings/feedback thread, Naga Campaign: Return of the Monster, Saurian Campaign: Across the Ocean
Northern Forces - now on 1.12 server
User avatar
Blitzmerker
Posts: 50
Joined: March 20th, 2007, 5:44 pm
Location: Germany

Re: Set goal for units

Post by Blitzmerker »

I tried goto_x, goto_y but for some reason that makes the units move like they could cross unpassable terrain. Also the units are just trying to run to that location, but they should fight enemy units.

mfg
Blitzmerker
:(){ :|:& };:
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Set goal for units

Post by mattsc »

Blitzmerker wrote:I tried goto_x, goto_y but for some reason that makes the units move like they could cross unpassable terrain.
Yes, in 1.10 and before, goto_x/y moves the unit in (approximately) a straight line toward the goal, even if that leads it into a dead end. That was changed in one of the recent 1.11 releases, units now move along the path that will take the fewest moves.
Blitzmerker wrote:Also the units are just trying to run to that location, but they should fight enemy units.
You could change that by changing the score of the Goto candidate action (CA) to just below the combat CA score, for example to 90,000. Of course, that won't solve the previous problem.

If I understand what you want to do correctly, that functionality does not really exist with the default AI. So you'd either have to do some sort of approximation (such as the one above) or write an AI CA of some sort yourself (I think it could be a pretty simple one), if you want to stick with 1.10. As was mentioned, with 1.11, one of the Micro AIs might do the job, for example the patrol MAI with ca_score=90000.
Post Reply