New micro_ai: attack_enemy_leader
Moderator: Forum Moderators
Forum rules
Before posting a new idea, you must read the following:
Before posting a new idea, you must read the following:
New micro_ai: attack_enemy_leader
Hi, Game Designers.
As a scenario designer, I would be grateful if the following
A key that assigns a percentage for this behavior would also be useful. Otherwise, the default percentage is 100%.
For example,
I have tried various other methods of encouraging the ai to prefer attacking an enemy Leader rather than other units, and they do not work. At best, they encourage the ai's units to move toward an enemy leader. However, once the enemy leader is within attack range, it remain highly likely that the ai's unit will attack a nearby 0-level unit or a badly injured unit instead.
I think
Thanks. The Battle for Wesnoth is an awesome game. Keep up the good work!
As a scenario designer, I would be grateful if the following
micro_ai
was added to the game:ai_type=attack_enemy_leader
: Any unit qualified by the filter will attack an enemy leader if they are within range. Nearby enemy units will not distract them, and the unit's own damage will not be a consideration.A key that assigns a percentage for this behavior would also be useful. Otherwise, the default percentage is 100%.
For example,
frequency=70
would indicate that an ai-controlled unit would have a 70% probability of replacing its default behavior with an attack on an enemy leader whenever an enemy leader is within range.I have tried various other methods of encouraging the ai to prefer attacking an enemy Leader rather than other units, and they do not work. At best, they encourage the ai's units to move toward an enemy leader. However, once the enemy leader is within attack range, it remain highly likely that the ai's unit will attack a nearby 0-level unit or a badly injured unit instead.
I think
ai_type=attack_enemy_leader
would make the ai seem more human-like, as most players are ever-watchful for an opportunity to attack an enemy leader.Thanks. The Battle for Wesnoth is an awesome game. Keep up the good work!
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
- Lord-Knightmare
- Discord Moderator
- Posts: 2354
- Joined: May 24th, 2010, 5:26 pm
- Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
- Contact:
Re: New micro_ai: attack_enemy_leader
Simple Attack MAI with a lua function to target enemy leader would be sufficient for this actually. No new MAI is needed.
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
Re: New micro_ai: attack_enemy_leader
Well, people who can code lua may not need it, but only a small percentage of scenario-makers would qualify. I certainly couldn't do it.Lord-Knightmare wrote: ↑November 9th, 2022, 11:20 pm Simple Attack MAI with a lua function to target enemy leader would be sufficient for this actually. No new MAI is needed.
With all due respect, if writing the code is so easy, would you mind contributing the code within this thread so people like me can copy/paste it into their scenarios?
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
- Lord-Knightmare
- Discord Moderator
- Posts: 2354
- Joined: May 24th, 2010, 5:26 pm
- Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
- Contact:
Re: New micro_ai: attack_enemy_leader
Of course. Instructing people on making better UMC is what I do these days.Helmet wrote: ↑November 10th, 2022, 2:22 amWell, people who can code lua may not need it, but only a small percentage of scenario-makers would qualify. I certainly couldn't do it.Lord-Knightmare wrote: ↑November 9th, 2022, 11:20 pm Simple Attack MAI with a lua function to target enemy leader would be sufficient for this actually. No new MAI is needed.
With all due respect, if writing the code is so easy, would you mind contributing the code within this thread so people like me can copy/paste it into their scenarios?
So, we start with defining Lua functions.
Code: Select all
# preload for Lua events
[event]
name=preload
first_time_only=no
# focus me
# since I am the main
[lua]
code=<<
function prioritise_player_leader(unit)
if (unit.id == "Jahin") then
return true
else
return false
end
end
>>
[/lua]
# Lua function to priortise
# higher level units
[lua]
code=<<
function high_level_unit(unit)
if (unit.level >= 2) then
return true
else
return false
end
end
>>
[/lua]
[/event]
Code: Select all
[micro_ai]
side=6
ai_type=simple_attack
action=add
ca_score=110002
# focuses on me cause I am canrecruit=yes
[filter_second]
lua_function = "prioritise_player_leader"
[/filter_second]
[/micro_ai]
# focus on my high level units
[micro_ai]
side=3
ai_type=simple_attack
action=add
ca_score=110001
[filter_second]
lua_function = "high_level_unit"
[/filter_second]
[/micro_ai]
For further inquiries, feel free to reach out to me here or in the the Wesnoth UMC discord (invite link on request).
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
Re: New micro_ai: attack_enemy_leader
Thanks!
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
- Celtic_Minstrel
- Developer
- Posts: 2194
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: New micro_ai: attack_enemy_leader
Or you could do it without any Lua coding at all.
Code: Select all
[micro_ai]
side=6
ai_type=simple_attack
action=add
ca_score=110002
# focuses on me cause I am canrecruit=yes
[filter_second]
formula="id = 'Jahin' "
[/filter_second]
[/micro_ai]
# focus on my high level units
[micro_ai]
side=3
ai_type=simple_attack
action=add
ca_score=110001
[filter_second]
formula="level >= 2"
[/filter_second]
[/micro_ai]
Re: New micro_ai: attack_enemy_leader
Wow, I just tried this code in a new scenario. It works great.Celtic_Minstrel wrote: ↑November 21st, 2022, 2:54 pm Or you could do it without any Lua coding at all...
I was under the impression that it had to be encased within an
[ai]
tag within a [side]
tag, but that is not accurate. I tossed it into a start
event all by itself and it worked like a charm, just like the Wiki indicated.Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.