Hello,
As a project I've decided to try and create a new micro_ai.
I did have quite a bit of the logic below working using WML but my implementation was messy and inelegant, hence an attempt at a purely lua implementation.
Below is a breakdown of the proposed logic.
All thoughts and comments (including "don't do this") greatly appreciated.
I already have a version of forest animals that allows units to wander randomly (ignores enemies) and if a child (tusklet) is attacked makes all units hostile (i.e. may attack on their turn). Me being me I decided to push the envelope but thought I'd best check here first to ensure the logic will work as I expect.
Here's an outline of the proposed behaviours:
Initial questions:
cheers!
-- Spannerbag
As a project I've decided to try and create a new micro_ai.
I did have quite a bit of the logic below working using WML but my implementation was messy and inelegant, hence an attempt at a purely lua implementation.
Below is a breakdown of the proposed logic.
All thoughts and comments (including "don't do this") greatly appreciated.
I already have a version of forest animals that allows units to wander randomly (ignores enemies) and if a child (tusklet) is attacked makes all units hostile (i.e. may attack on their turn). Me being me I decided to push the envelope but thought I'd best check here first to ensure the logic will work as I expect.
Here's an outline of the proposed behaviours:
Code:
-- Ugly hack of forest animals mai to create wanderers mai (wmai).---- Ignores enemies, if any, when moving units.-- Units: parents and children.---- Is really 3 micro-ais in one; parents only, children only or both.-- Each have various behaviours as detailed below.-- All subtags and filters detailed below are optional.---- [filter_parent]-- Unit filter for parent units.-- If absent or no match: no parents.-- As with forest animals mai parents will unconditionally attack any enemy adjacent to a child.---- [filter_child]-- Unit filter for child units.-- If absent or no match: no children.-- Child units never attack (so can only die if attacked).---- [filter_location]-- If present restricts units to specified locations.-- If absent or no match: move over whole map.---- Key "parent_attack" defines % chance (default 0%) of parent attacking if:-- a) enemy unit adjacent to parent (but not also to child) at turn start, or-- b) if parent moves adjacent to enemy unit.---- If enemy attacks and hits:-- Parent: attacked unit no longer controlled by mai but by default RCA ai-- (next wmai turn only).-- Child: *all* units controlled by default RCA ai-- (all subsequent turns, i.e. wmai disabled).---- Controlling ai is mediated by unit variable "maiw_status" with values:-- i) =0 unit(s) controlled by mai (default/fallback value).-- ii) =1 unit(s) controlled by RCA ai current/next turn only-- (parents only, maiw_status cleared at turn end).-- iii) =2 unit(s) always controlled by default RCA ai-- (maiw_status not cleared at turn end).---- Events (provisional)-- 1: new side turn-- If any parents begin with 1+ enemie(s) adjacent *and* no enemies adjacent to a child-- then if maiw_status < 1 set maiw_status = 1 for this unit, prior to-- checking which unit(s) should be controlled by wmai on current turn.---- 2: moveto (enter_hex?)-- If any unit moves adjacent to an enemy set moves=0.-- If parent, set maiw_status=1 and attacks_left=1 (might not be necessary?).---- 3: attacker hits-- If second_unit.side = wmai side set maiw_status accordingly (depending on whether parent or child hit).---- Proposed WML structure:---- [micro_ai]-- side=...-- ai_type=wanderers-- action=add / change / delete-- [filter_parent]-- Includes micro_ai side number above-- Standard unit filter sub-tags and keys-- [/filter_parent]-- [filter_child]-- Includes micro_ai side number above-- Standard unit filter sub-tags and keys-- [/filter_child]-- [filter_location]-- Standard location filter sub-tags and keys-- [/filter_location]-- parent_attack=%
- if a unit does blunder into an enemy, if I simply ensure the unit can attack will control automatically pass to the RCA ai when the micro_ai has finished or do I need to explicitly "deregister" it with the micro ai before the RCA ai can subsequently assume control of this unit?
- Is is preferable to implement the events above in lua or WML?
I would prefer lua as I hope to write the entire micro_ai as a single lua file.
However given the need to trap events on other side turns (attacker hits) I'm not certain this is possible? - Is it OK to invent/create arbitrary tags such as
[filter_parent]
or are only recognised WML tags allowed/recognised?
(If not I could fallback to using the existing type specification logic.) - Not sure whether to check that parents and children are distinct (and issue error if not) or trust the campaign designer.
(I.e. would such a sanity check be useful?) - Need to split moveto/enter_hex logic:
- Set moves=0 immediately (all units)
- Parent only: defer attack enemy until all moves completed then only attack adjacent enemy if no enemies adjacent to children within range (and parent_attack chance → attack).
Is this awkward to implement in lua?
- Would "nuisances" (or something else) be a better name than "wanderers"?
- Is my logic sane/optimal or are there better ways of doing this?
cheers!
-- Spannerbag
Statistics: Posted by Spannerbag — Today, 12:23 pm