modifying AI in mid-scenario
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.
modifying AI in mid-scenario
Hello guys, I have an issue with modifying AI behavior in the middle of scenario.
To illustrate the situation: I'm making scenario, where dwarves fight vs. trolls and the player have to go around. But at one certain moment, dwarves change their mind and they start to go after player.
My problem is, that they won't. At least not the way how I imagine. Down below I show part of the code.
If I set value of [goal] id=new_goal to 5, then it doesn't work. It works only if I use bigger value against [goal] id=test... at least 15.
It leads me to think, that I actually didn't remove [goal] id=test.
I also know, that there is possible of using action=change, but I'm not 100% sure how to write it. It would be much more elegant - just change [criteria] of [goal] id=test.
All help I'll appreciate it! Thanks.
To illustrate the situation: I'm making scenario, where dwarves fight vs. trolls and the player have to go around. But at one certain moment, dwarves change their mind and they start to go after player.
My problem is, that they won't. At least not the way how I imagine. Down below I show part of the code.
Code: Select all
#side 1 = player
#side 2 = dwarves
#side 3 = trolls
[side]
side=2
#other standard keys
[ai]
[goal]
id=test
name=target_unit
[criteria]
side=3
[/criteria]
value=5
[/goal]
[/ai]
[/side]
[event]
name=turn 10
[modify_ai]
side=2
action=delete
path=goal[test]
[/modify_ai]
#now I want to force side 2 to attack side 1 (player):
[modify_ai]
side=2
action=add
path=goal[]
[goal]
id=new_goal
[criteria]
side=1
[/criteria]
value=15 #the only way how can I convince AI to move towards side 1 is to set up bigger value here
[/goal]
[/modify_ai]
[/event]
If I set value of [goal] id=new_goal to 5, then it doesn't work. It works only if I use bigger value against [goal] id=test... at least 15.
It leads me to think, that I actually didn't remove [goal] id=test.
I also know, that there is possible of using action=change, but I'm not 100% sure how to write it. It would be much more elegant - just change [criteria] of [goal] id=test.
All help I'll appreciate it! Thanks.
Re: modifying AI in mid-scenario
I assume that the behavior you observe is due to the fact that the goal you define is not the only goal the AI uses. There are also some automatically selected goals; and other considerations, such as distance to the goals, matter as well (see the first paragraphs here and here for more details). Most likely the dwarves are too close to the troll leader by Turn 10 that you need a large goal value to override them going for that leader. That's only a guess, of course, since I have not seen the situation, but given that it works with a large value, it is almost certainly something like that. And in that case, there is nothing wrong with using 15, or even more, for the goal value.
Bottom line is that you can never be sure that _all_ units will follow the directive, no matter how high you set the value. In fact, the move-to-targets CA specifically sends units toward different targets, weighted by the targets' values. Maybe that's okay for what you want. If not, you could use something like the Goto Micro AI which will guarantee that all units it applies to move toward the specified locations/units.
As for whether the change works, you can check that by bringing up the inspector, and clicking on the side -> ai -> goals. I copied your code into my test scenario and the removal works just fine for me. If you want to use the 'change' action, the syntax is the same as for 'add', except that you need to add the id of the goal you want to change (same as for the 'delete' action):
I tested that too and it works.
Bottom line is that you can never be sure that _all_ units will follow the directive, no matter how high you set the value. In fact, the move-to-targets CA specifically sends units toward different targets, weighted by the targets' values. Maybe that's okay for what you want. If not, you could use something like the Goto Micro AI which will guarantee that all units it applies to move toward the specified locations/units.
As for whether the change works, you can check that by bringing up the inspector, and clicking on the side -> ai -> goals. I copied your code into my test scenario and the removal works just fine for me. If you want to use the 'change' action, the syntax is the same as for 'add', except that you need to add the id of the goal you want to change (same as for the 'delete' action):
Code: Select all
[modify_ai]
side=1
action=change
path=goal[test]
[goal]
id=new_goal
[criteria]
side=1
[/criteria]
value=15 #the only way how can I convince AI to move towards side 1 is to set up bigger value here
[/goal]
[/modify_ai]
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: modifying AI in mid-scenario
mattsc: Thank you for your very deep answer. It helps me to understand things! But... I tried syntax with 'change' and it didn't work The game displays this: "<Invalid WML found> Missing component definition in [modify_ai]
Any ideas?
Any ideas?
Re: modifying AI in mid-scenario
Are you sure you are using the tag as in my post? That error happens when you try to change (or add) an AI component without giving it new content to change to (or add); the
[ Also note that my example above changes the goal for side 1 in the second line (which is what I used in my test), you want to change that back to side 2. You probably noticed that, just mentioning it for completeness. And that would not produce this error, it would simply not have any effect. ]
[goal]
tag in this case. Maybe you also changed the [modify_ai]action=delete
instructions to action=change
? That would produce this error. You only need one [modify_ai]
tag when you use 'change', that's the main reason why it exists.[ Also note that my example above changes the goal for side 1 in the second line (which is what I used in my test), you want to change that back to side 2. You probably noticed that, just mentioning it for completeness. And that would not produce this error, it would simply not have any effect. ]
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: modifying AI in mid-scenario
Well, your code was correct. I made mistake using this: id=dwarves A and changed it to id=dwarves B. Somehow problem was a gap. Now I'm using id=dwarves_go_after_trolls into id=dwarves_go_after_player and it's totally ok.
So thank you! I appreciate your game understanding - it really helped. May I ask for one (or two) more things?
1) If I use more than one [ai] or [ai_modify] for just one side, could it possibly do it mess? Something like weird behavior, lags during gameplay, etc.. I'm asking, because I am thinking about to set up aggression for dwarves and also for their leader (because otherwise he is pretty lazy to attack from his castle). Which leads me to my second question...
2) Is it true, that basic configuration for aggression is 0,4 for side's units and -4,0 for their leader?
3) Due to the discussed dwarves, can i write it all down something like this?
So thank you! I appreciate your game understanding - it really helped. May I ask for one (or two) more things?
1) If I use more than one [ai] or [ai_modify] for just one side, could it possibly do it mess? Something like weird behavior, lags during gameplay, etc.. I'm asking, because I am thinking about to set up aggression for dwarves and also for their leader (because otherwise he is pretty lazy to attack from his castle). Which leads me to my second question...
2) Is it true, that basic configuration for aggression is 0,4 for side's units and -4,0 for their leader?
3) Due to the discussed dwarves, can i write it all down something like this?
Code: Select all
[side]
side=2
#other standard keys
[ai]
aggression=0,7
leader_aggression=0,7
[goal]
id=dwarves_go_after_trolls
[criteria]
side=3
[/criteria]
value=5
[/goal]
[/ai]
[/side]
[event]
name=turn 10
[modify_ai]
side=2
action=change
path=goal[dwarves_go_after_trolls]
[goal]
id=dwarves_go_after_player
[criteria]
side=1
[/criteria]
value=15
[/goal]
[/modify_ai]
[/event]
Re: modifying AI in mid-scenario
Glad it helped. And don't worry about having more questions. As for those:
1) That should not be a problem.
2) Yes. The AI is set to be more careful with its leader, but you can change that if you want.
3) I haven't checked it carefully for typos, but it looks like that should work. Only thing I saw is that "0,7" should maybe be changed to "0.7". I know the comma is used as decimal point in some locales, but does that work in WML code also? The comma is usually used for lists of variables in Wesnoth.
Just as an additional comment, I would strongly suggest that you use the gamestate inspector (type
1) That should not be a problem.
2) Yes. The AI is set to be more careful with its leader, but you can change that if you want.
3) I haven't checked it carefully for typos, but it looks like that should work. Only thing I saw is that "0,7" should maybe be changed to "0.7". I know the comma is used as decimal point in some locales, but does that work in WML code also? The comma is usually used for lists of variables in Wesnoth.
Just as an additional comment, I would strongly suggest that you use the gamestate inspector (type
:inspect
in game; possibly after typing :debug
first to enable debug mode) to check whether any of the AI modifications you made actually took effect. I always do that for my own code as typos do happen and changes to AI behavior are often quite subtle and/or difficult to disentangle from other effects.SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: modifying AI in mid-scenario
Yep, you are right
Thanks again.
Thanks again.