Help with WML for a particular scenario

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
beetlenaut
Developer
Posts: 2814
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Help with WML for a particular scenario

Post by beetlenaut »

We can't be sure to give you useful code without knowing more. It depends on what you mean by "available". Also note that you have to choose the unit. A computer can't understand "any unit--it doesn't matter".

See if this helps: The [role] tag is for choosing a single unit for some task. (It can be selected later in a unit [filter].) To make a unit walk to a hex, you can use [move_unit]. If it helps, you can also use [store_reachable_locations] to find out if a unit could reach a hex in the current turn.

Why don't you give it a try and post your code if you run into trouble.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
Glen
Posts: 76
Joined: August 20th, 2011, 10:59 pm

Re: Help with WML for a particular scenario

Post by Glen »

To make AI side go to a particular location, I think you should use the [goal] tag for target_location in the [side] tag for that AI side. Here is an example from one of my lava duel scenarios where I want the AI side 1 to capture or move wards the tile 20,27

Code: Select all

[side]
side = 1
gold = 75
village_gold = 1
	[ai]
	passive_leader=yes
	leader_ignores_keep = yes
				village_value=0
				grouping = defensive
				aggression=.2
				caution = .65	
			[avoid]
			x = 15, 5, 12, 10, 10, 21, 19, 22, 24, 22, 29, 29, 31, 36, 39, 36, 41, 46, 39, 42, 36, 44, 49, 44, 32, 30, 33, 32, 35, 25, 23, 18, 18, 15, 8, 13
			y = 21, 21, 22, 20, 13, 12, 6, 9, 13, 17, 15, 6, 17, 13, 13, 16, 9, 16, 27, 25, 23, 27, 27, 34, 30, 34, 36, 38, 42, 42, 31, 31, 34, 35, 31, 39
			[/avoid]
				
			[goal]
			name=target_location
			[criteria] 
				x,y=20,27
			[/criteria]
			value=30
			[/goal]		
    [/ai]
[/side]
If you want AI side to only capture this tile at a specific turn modify the side's AI in the an event for that turn.
Lets say you wanted the AI to target the tile (25,25) on turn 3, it could be done like this.

Code: Select all

[event]
name = turn 3
first_time_only=no

[modify_side]
    side=1
    [ai]
			[goal]
				name=target_location
				[criteria] 
					x,y=25,25
				[/criteria]
				value=100
			[/goal]
			caution = .65
			aggression = .1
			grouping = defensive
			leader_ignores_keep = yes
			
    [/ai]
[/modify_side]
Last edited by Glen on May 4th, 2020, 3:00 am, edited 1 time in total.
User avatar
beetlenaut
Developer
Posts: 2814
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Help with WML for a particular scenario

Post by beetlenaut »

Glen wrote: May 4th, 2020, 2:31 am you should use the [goal] tag for target_location in the [side] tag for that AI side
Not in this case. A [goal] only takes effect if the AI has nothing else useful to do during it's turn. It will ignore the goal if it has attacks it can do, villages it can grab, or a leader that is in danger.

(To show code on the forum, use [code] instead of [c]. You can use the button marked </>).
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
Glen
Posts: 76
Joined: August 20th, 2011, 10:59 pm

Re: Help with WML for a particular scenario

Post by Glen »

I assumed he wanted the AI to move in that direction and capture the Tile if it can. You are implying that the AI should capture the tile and ignore nearby enemies and villages to do so. You're right that Combat and Village CA's take precedence over the Move-To-Targets CA that [goal] is under, but I'm not sure if removing that is what he really needs. I think he would need to use [modify_ai] and delete the offending village and combat CA's if he wanted to do that.

By the way does ai really care if its own leader is in danger? In my own experience in game, I've never found an AI leader to move its units back when its leader is in danger.
User avatar
beetlenaut
Developer
Posts: 2814
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Help with WML for a particular scenario

Post by beetlenaut »

Glen wrote: May 4th, 2020, 3:55 am Combat and Village CA's take precedence over the Move-To-Targets CA that [goal] is under
You probably should have mentioned this, that's all. I replied to your post because I wanted it to be clear to the OP that it wouldn't necessarily do what he wanted. I was assuming he wanted the capture to be a direct action, though I suppose what you thought might be right too. Like I said earlier, it wasn't quite clear.
Glen wrote: May 4th, 2020, 3:55 am By the way does ai really care if its own leader is in danger?
It's supposed to, but it might be that in practice it almost always has higher priority actions.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
chak_abhi
Posts: 347
Joined: June 24th, 2010, 3:37 pm

Re: Help with WML for a particular scenario

Post by chak_abhi »

Glen wrote: May 4th, 2020, 3:55 am I assumed he wanted the AI to move in that direction and capture the Tile if it can. You are implying that the AI should capture the tile and ignore nearby enemies and villages to do so.
Yes, thats the thing I want the AI to do, try to capture a particular tile ignoring the enemies and villages.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Help with WML for a particular scenario

Post by mattsc »

You still haven't given quite enough information for us to know exactly how best to advice you. However, the Goto Micro AI is quite versatile and can probably be set up for this purpose. You might want to check that out.
chak_abhi
Posts: 347
Joined: June 24th, 2010, 3:37 pm

Re: Help with WML for a particular scenario

Post by chak_abhi »

mattsc wrote: May 4th, 2020, 4:36 pm You still haven't given quite enough information for us to know exactly how best to advice you. However, the Goto Micro AI is quite versatile and can probably be set up for this purpose. You might want to check that out.
Ok, take for example the player has to protect an artifact located on a specific tile from the enemies. The enemies (AI controlled) will try to capture the artifact instead of moving into villages or attacking the player's units. What will be the most useful code that can guide the AI?
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Help with WML for a particular scenario

Post by mattsc »

Well, that's very much a non-trivial problem (and not exactly what I imagined you were trying to do). If you think about how you would play the AI side as a human player, it involves decisions which units should attack in order to open a gap vs. which should press forward toward the goal vs. potentially other tasks. There is no code for that decision process, and the reason why it does not exist is that it is very difficult for an AI to do that sort of reasoning. Unless you (the scenario designer) can assign units for either task up front. In either case, the Goto MAI is still your best bet in my opinion, maybe in combination with the Simple Attack MAI - or even the Messenger Escort might work, depending on your map/units. You'll just have to experiment with them a bit.
chak_abhi
Posts: 347
Joined: June 24th, 2010, 3:37 pm

Re: Help with WML for a particular scenario

Post by chak_abhi »

mattsc wrote: May 4th, 2020, 6:24 pm Well, that's very much a non-trivial problem (and not exactly what I imagined you were trying to do). If you think about how you would play the AI side as a human player, it involves decisions which units should attack in order to open a gap vs. which should press forward toward the goal vs. potentially other tasks. There is no code for that decision process, and the reason why it does not exist is that it is very difficult for an AI to do that sort of reasoning. Unless you (the scenario designer) can assign units for either task up front. In either case, the Goto MAI is still your best bet in my opinion, maybe in combination with the Simple Attack MAI - or even the Messenger Escort might work, depending on your map/units. You'll just have to experiment with them a bit.
Well, thanks. I will try something more simple.
chak_abhi
Posts: 347
Joined: June 24th, 2010, 3:37 pm

Re: Help with WML for a particular scenario

Post by chak_abhi »

There is yet another problem with which I need help.
Suppose in a scenario the player needs to capture villages in a particular area (say x=1-20, y=15-25) to get some supporting units (say 1 peasant from each of the captured villages joining the player's side). But if any of these villages are wrested by the opponent and recaptured by the player he won't get any supporting unit. What should be the appropriate code for this? Thanks in advance.
User avatar
beetlenaut
Developer
Posts: 2814
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Help with WML for a particular scenario

Post by beetlenaut »

There is more than one way to do this, but all of them involve making an array. This is what I would do: Each variable in the array is a container variable that matches one village. Each variable contains the x and y, and a variable called previously_captured (or something similar). That variable starts out as "no". When a village is captured by side 1, you search in the array for its x and y, and check to see if its previously_captured variable is still set to "no". If it is, spawn the peasants and then set it to "yes".

To start with, you could use [store_villages] to generate the array, then use [foreach] to add the previously_captured variable to each container in the array. Do a little of the code at a time and use :inspect to make sure the array and its values are changing the way you want.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Post Reply