Results 1 to 12 of 12

Thread: Forcing AI to besiege settlement.

  1. #1

    Default Forcing AI to besiege settlement.

    am attempting to get the ai to invade a settlement that it's not adjacent to

    have had it working for one faction (but that one was based on an island not connected to the invasion area, but near that coast)

    this one has another faction between it and the invasion area, and whatever I do it seems to insist on walking home instead of continuing the siege - I didn't really want to do 'assault' as if the defending faction is human player I'd like them to have a chance to make a defense.

    Code so far;
    Code:
    monitor_event FactionTurnStart FactionType france
    	and I_EventCounter france_is_the_ai = 1	
    	if I_NumberOfSettlements hre > 5 
    		and I_TurnNumber > 1
    		and RandomPercent <= 90
    		log always too many naugiri
    		console_command diplomatic_stance france hre War
    		set_event_counter ildiriToMolehale 1
    		set_event_counter ildiriToDiluvia 1
    		set_event_counter ildiriToGoryanger 1
    	end_if
    	if I_EventCounter ildiriToMolehale = 1
    		and I_SettlementOwner Molehale = hre
    		and not I_CharacterExists Invade_Molehale
    		and RandomPercent <= 50
    		spawn_army 
    		faction france
    		character Incsiri, named character, age 38, x 313, y 192, direction S, label Invade_Molehale
    		unit	Swan Knights		exp 5 armour 0 weapon_lvl 0
    		unit	swan_knightsft 		exp 2 armour 0 weapon_lvl 0
    		unit	swan_knightsft 		exp 2 armour 0 weapon_lvl 0
    		unit	swan_knightsft		exp 3 armour 0 weapon_lvl 0
    		unit	Falconskts 		exp 4 armour 0 weapon_lvl 0
    		unit	swansbow 		exp 3 armour 0 weapon_lvl 0
    		unit	swansbow 		exp 3 armour 0 weapon_lvl 0
    		unit	Tears of Ithil 		exp 2 armour 0 weapon_lvl 0
    		unit	Tears of Ithil 		exp 3 armour 0 weapon_lvl 0
    		end
    		set_event_counter ildiriToMolehale 0
    	end_if
    	if I_SettlementOwner Molehale = hre
    		and I_CharacterExists Invade_Molehale
    		siege_settlement Invade_Molehale, Molehale, maintain
    		log always ildiri in molehale
    	end_if
    	if I_EventCounter ildiriToDiluvia = 1
    		and I_SettlementOwner Diluvia = hre
    		and not I_CharacterExists Invade_Diluvia
    		and RandomPercent <= 50
    		spawn_army 
    		faction france
    		character Incsiri, named character, age 38, x 286, y 181, direction S, label Invade_Diluvia
    		unit	Swan Knights		exp 5 armour 0 weapon_lvl 0
    		unit	swan_knightsft 		exp 2 armour 0 weapon_lvl 0
    		unit	swan_knightsft 		exp 2 armour 0 weapon_lvl 0
    		unit	swan_knightsft		exp 3 armour 0 weapon_lvl 0
    		unit	Falconskts 		exp 4 armour 0 weapon_lvl 0
    		unit	swansbow 		exp 3 armour 0 weapon_lvl 0
    		unit	swansbow 		exp 3 armour 0 weapon_lvl 0
    		unit	swansbow 		exp 3 armour 0 weapon_lvl 0
    		unit	Tears of Ithil 		exp 2 armour 0 weapon_lvl 0
    		unit	Tears of Ithil 		exp 2 armour 0 weapon_lvl 0
    		unit	Tears of Ithil 		exp 3 armour 0 weapon_lvl 0
    		end
    		siege_settlement Invade_Diluvia, Diluvia, maintain
    		log always ildiri in Diluvia
    		set_event_counter ildiriToDiluvia 0
    	end_if
    	if I_EventCounter ildiriToGoryanger = 1
    		and I_SettlementOwner Goryanger = hre
    		and not I_CharacterExists Invade_Goryanger
    		and RandomPercent <= 50
    		spawn_army 
    		faction france
    		character Incsiri, named character, age 38, x 317, y 166, direction S, label Invade_Goryanger
    		unit	Swan Knights		exp 5 armour 0 weapon_lvl 0
    		unit	swan_knightsft 		exp 2 armour 0 weapon_lvl 0
    		unit	swan_knightsft 		exp 2 armour 0 weapon_lvl 0
    		unit	swan_knightsft		exp 3 armour 0 weapon_lvl 0
    		unit	swan_knightsft		exp 3 armour 0 weapon_lvl 0
    		unit	Falconskts 		exp 4 armour 0 weapon_lvl 0
    		unit	Falconskts 		exp 4 armour 0 weapon_lvl 0
    		unit	swansbow 		exp 3 armour 0 weapon_lvl 0
    		unit	swansbow 		exp 3 armour 0 weapon_lvl 0
    		unit	Tears of Ithil 		exp 2 armour 0 weapon_lvl 0
    		unit	Tears of Ithil 		exp 3 armour 0 weapon_lvl 0
    		end
    		siege_settlement Invade_Goryanger, Goryanger, maintain
    		log always ildiri in Goryanger
    		set_event_counter ildiriToGoryanger 0
    	end_if
    	if I_NumberOfSettlements hre < 4 
    		log always less naug
    		set_event_counter ildiriToMolehale 0
    		set_event_counter ildiriToDiluvia 0
    		set_event_counter ildiriToGoryanger 0
    	end_if
    end_monitor
    separating out the
    if I_SettlementOwner Molehale = hre
    and I_CharacterExists Invade_Molehale
    siege_settlement Invade_Molehale, Molehale, maintain
    end_if
    bit makes the character come back and re-start the siege every alternate turn, but then next turn he walks off again

    the other ones just walk off completely


    is this at all possible?

  2. #2
    Gigantus's Avatar I am not special - I am a limited edition.
    Patrician took an arrow to the knee spy of the council

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    53,132
    Blog Entries
    35

    Default Re: Forcing AI to besiege settlement.

    You need to wrap your additional if sequence into a FactionTurnEnd monitor. And find a suitable condition to later terminate that monitor. Please note that this will most likely result in a siege that gets only terminated by the settlement surrendering or the attacker being killed. Here is the script I used in Last Kingdom, but it has the character spawned right next to the settlement, so the I_SettlementUnderSiege condition will not work properly for you. But you get drift about the FactionTurnEnd importance.

    Code:
    declare_counter siege_Fareyar
    ; --- the spawn ---
    monitor_event FactionTurnStart FactionIsLocal
        and I_TurnNumber = 1
        and not I_SettlementOwner Fareyar = norway
        and not I_SettlementOwner Fareyar = horda
        and not I_SettlementOwner Fareyar = denmark
        and not I_SettlementOwner Fareyar = spain
    
        spawn_army
            faction spain
            character    Bjalfi, general, age 29, x 89, y 193, label v00, direction W
            unit    Huskarl Swordsmen        exp 4 armour 0 weapon_lvl 0
            unit    Leidgangr Spearmen        exp 3 armour 0 weapon_lvl 0
            unit    Leidgangr Spearmen        exp 3 armour 0 weapon_lvl 0
            unit    Herkledi Spearmen        exp 3 armour 0 weapon_lvl 0
            unit    Vikingr Axemen            exp 3 armour 0 weapon_lvl 0
            unit    Vikingr Axemen            exp 3 armour 0 weapon_lvl 0
            unit    Leidgangr Archers        exp 3 armour 0 weapon_lvl 0
        sieging
            siege_settlement v00, Fareyar, maintain
        terminate_monitor
    end_monitor
    
    ;--- the siege ---
    monitor_event FactionTurnEnd FactionType spain
        and I_CharacterExists v00
        and not I_SettlementOwner Fareyar = norway
        and not I_SettlementOwner Fareyar = horda
        and not I_SettlementOwner Fareyar = denmark
        and not I_SettlementOwner Fareyar = spain
        and I_SettlementUnderSiege Fareyar
    
        if I_CompareCounter siege_Fareyar < 2
                siege_settlement v00, Fareyar, maintain
        end_if
        if I_CompareCounter siege_Fareyar = 2
            siege_settlement v00, Fareyar, attack
        terminate_monitor
        end_if
    
        inc_counter siege_Fareyar 1
    end_monitor










  3. #3
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: Forcing AI to besiege settlement.

    Quote Originally Posted by makanyane View Post
    this one has another faction between it and the invasion area
    I can't tell from your script where they spawn in relation to the cities. If they're not adjacent then siege_settlement won't work. It would be handy if that command meant "walk to the settlement and lay siege" but it doesn't do the walk part so a "move" command is also needed.

    Does the spawned army need to walk some distance to reach the settlement? Possibly a journey that takes multiple turns?

    Even if it's a short journey that will never take more than one turn it's still tricky because script needs to know for certain that they reached an adjacent tile before calling siege_settlement. The tile he was scripted to walk to might be occupied so he will stop short.

    Even spawning him adjacent isn't guaranteed. If you spawn him on the settlement tile itself then he will land on the first free adjacent tile: that's handy. But if the settlement happens to have no free tiles around it - unlikely but possible - then he'll land on a tile one step further out --> no longer adjacent. Spawning him onto an adjacent tile might not work either because if the tile is occupied then he'll land somewhere adjacent to that tile, which may or may not be adjacent to the settlement tile.

    Making it foolproof takes some hoop jumping. I do it this way...

    Spawn an agent into a faction that doesn't normally have them (e.g. england inquisitor) onto some out of the way tile.
    For each tile around the settlement (that can be reached by foot):
    - reposition_character him onto that tile
    - use I_CharacterTypeNearTile to test that he's on that tile - if not then it must be already occupied
    Move him out of the way and kill him.

    If I_CharacterTypeNearTile is true then it must mean that the tile is free: use that as the spawn location (after removing the agent).

    Unfortunately you'll need to know the agent's name and it must be unique, therefore Unique Name method. Or you could use a spawned named character or general with a label but for named characters you can only use that label once and you can't kill generals: you must destroy his unit type.

    None of that solves the walking to the settlement of course. For that you'd need to use something like the above to find which tile is his destination and use that with "move". Then have a way to know for certain that he actually ended up there before calling siege_settlement. The tile's free but we don't know that he can reach it (enemy ZOC, etc.). Personally I don't even attempt to manage this for a multi-turn journey.

    This may be of help for the "ended up there" bit: http://www.twcenter.net/forums/showt...1#post12608031

  4. #4

    Default Re: Forcing AI to besiege settlement.

    Thanks Gigantus I'll try that - had tried all the 'starts' but not 'end'...

    Quote Originally Posted by Withwnar View Post
    I can't tell from your script where they spawn in relation to the cities. If they're not adjacent then siege_settlement won't work. It would be handy if that command meant "walk to the settlement and lay siege" but it doesn't do the walk part so a "move" command is also needed.
    I'm spawning about 4 tiles away, the targets are settlements at far top right of map and I want it to look like the attackers are appearing from 'off map'. They seem to be doing the walk to the settlement bit fine... haven't tested it with enemy ZOC in the way though, that might break it. But the comedy version where they lay siege for a turn, go away and come back next turn seems to have them reaching the settlement OK.

    Will test with obstacles...

  5. #5
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: Forcing AI to besiege settlement.

    Quote Originally Posted by Withwnar View Post
    If they're not adjacent then siege_settlement won't work. It would be handy if that command meant "walk to the settlement and lay siege" but it doesn't do the walk part so a "move" command is also needed.
    Holy cow. siege_settlement does walk them to the settlement first! I never knew that. engage_armies doesn't behave that way.

    It seems that it doesn't matter if they are allies either. I expected that to fail. It didn't show a "War" message, or any message for that matter, but maybe that's because it was my faction that did the attacking and during my own turn.

    Well that simplifies things a lot. Although it would still need to test that an adjacent tile is available and reachable.

  6. #6

    Default Re: Forcing AI to besiege settlement.

    Bad news is that FactionTurnEnd (combined with FactionTurnStart as well) isn't fixing my walking off every alternate turn problem...

  7. #7
    Gigantus's Avatar I am not special - I am a limited edition.
    Patrician took an arrow to the knee spy of the council

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    53,132
    Blog Entries
    35

    Default Re: Forcing AI to besiege settlement.

    Just did this test with my Bare Geomod:

    1. Give Rufus (england) the label Rufus1
    2. Add this script to the campaign script
    3. Play as england, remove FoW
    4. Rufus will move to (and take) York in the second round, York has no wall.

    Code:
    declare_counter siege_York
    ; --- the spawn ---
    monitor_event FactionTurnStart FactionIsLocal
            siege_settlement Rufus1, York, maintain
        terminate_monitor
    end_monitor
    
    ;--- the siege ---
    monitor_event FactionTurnEnd FactionType england
        and I_CharacterExists Rufus1
        and not I_SettlementOwner York = england
        and I_SettlementUnderSiege York
    
        if I_CompareCounter siege_York < 2
                siege_settlement Rufus1, York, maintain
        end_if
        if I_CompareCounter siege_York = 2
            siege_settlement Rufus1, York, attack
        terminate_monitor
        end_if
    
        inc_counter siege_York 1
    end_monitor
    Second try:
    1. as above but turned York into a motte & bailey
    Code:
    settlement castle
    {
        level village
        region York_Province
    
        year_founded 0
        population 800
        plan_set default_set
        faction_creator england
            building
        {
            type core_castle_building motte_and_bailey
        }
    }
    Result: Rufus sieges motte in second turn, get's killed (army is repelled) in attack in the third round

    Note: moving Rufus beyond one turn reach of York initiates a move of Rufus towards York but the AI will take over the next turn. I have tried several initial scripts (sample below) using siege_settlement but have failed to get him to execute an attack\siege on York.
    Code:
    monitor_event FactionTurnStart FactionIsLocal
        and not I_SettlementOwner York = england
        and not I_SettlementUnderSiege York
        siege_settlement Rufus1, York, maintain
        if I_SettlementUnderSiege York
               terminate_monitor
        end_if
    end_monitor
    I am assuming that moving him into the vicinity of York (less then one turn range) and then calling the above script (IsPositionInRect) will work for multiple turns.
    Last edited by Gigantus; July 06, 2014 at 03:26 AM.










  8. #8

    Default Re: Forcing AI to besiege settlement.

    Yeah but, England AI is probably quite happy to attack York

    and my other version of this which has an island nation attacking a mainland area it can't walk home from works fine... with just the code in FactionTurnStart

    to try something closer to what I need it would be more like France attacking Poland (Krakow/Halych)

    I've just tried it now with the siege/maintain bit all the available Start/End monitors
    Spoiler Alert, click show to read: 
    Code:
    monitor_event FactionTurnEnd TrueCondition
    	if I_SettlementOwner Molehale = hre
    		and I_CharacterExists Invade_Molehale
    		siege_settlement Invade_Molehale, Molehale, maintain
    		log always ildiri in molehale FTend
    	end_if
    	if I_SettlementOwner Diluvia = hre
    		and I_CharacterExists Invade_Diluvia
    		siege_settlement Invade_Diluvia, Diluvia, maintain
    		log always ildiri in Diluvia FTend
    	end_if
    	if I_SettlementOwner Goryanger = hre
    		and I_CharacterExists Invade_Goryanger
    		siege_settlement Invade_Goryanger, Goryanger, maintain
    		log always ildiri in Goryanger FTend
    	end_if
    end_monitor
    
    monitor_event FactionTurnStart TrueCondition
    	if I_SettlementOwner Molehale = hre
    		and I_CharacterExists Invade_Molehale
    		siege_settlement Invade_Molehale, Molehale, maintain
    		log always ildiri in molehale FTend
    	end_if
    	if I_SettlementOwner Diluvia = hre
    		and I_CharacterExists Invade_Diluvia
    		siege_settlement Invade_Diluvia, Diluvia, maintain
    		log always ildiri in Diluvia FTend
    	end_if
    	if I_SettlementOwner Goryanger = hre
    		and I_CharacterExists Invade_Goryanger
    		siege_settlement Invade_Goryanger, Goryanger, maintain
    		log always ildiri in Goryanger FTend
    	end_if
    end_monitor
    
    monitor_event PreFactionTurnStart TrueCondition
    	if I_SettlementOwner Molehale = hre
    		and I_CharacterExists Invade_Molehale
    		siege_settlement Invade_Molehale, Molehale, maintain
    		log always ildiri in molehale prestart
    	end_if
    	if I_SettlementOwner Diluvia = hre
    		and I_CharacterExists Invade_Diluvia
    		siege_settlement Invade_Diluvia, Diluvia, maintain
    		log always ildiri in Diluvia prestart
    	end_if
    	if I_SettlementOwner Goryanger = hre
    		and I_CharacterExists Invade_Goryanger
    		siege_settlement Invade_Goryanger, Goryanger, maintain
    		log always ildiri in Goryanger prestart
    	end_if
    end_monitor
    
    monitor_event CharacterTurnEnd TrueCondition
    	if I_SettlementOwner Molehale = hre
    		and I_CharacterExists Invade_Molehale
    		siege_settlement Invade_Molehale, Molehale, maintain
    		log always ildiri in molehale charend
    	end_if
    	if I_SettlementOwner Diluvia = hre
    		and I_CharacterExists Invade_Diluvia
    		siege_settlement Invade_Diluvia, Diluvia, maintain
    		log always ildiri in Diluvia charend
    	end_if
    	if I_SettlementOwner Goryanger = hre
    		and I_CharacterExists Invade_Goryanger
    		siege_settlement Invade_Goryanger, Goryanger, maintain
    		log always ildiri in Goryanger charend
    	end_if
    end_monitor
    
    monitor_event CharacterTurnStart TrueCondition
    	if I_SettlementOwner Molehale = hre
    		and I_CharacterExists Invade_Molehale
    		siege_settlement Invade_Molehale, Molehale, maintain
    		log always ildiri in molehale charstart
    	end_if
    	if I_SettlementOwner Diluvia = hre
    		and I_CharacterExists Invade_Diluvia
    		siege_settlement Invade_Diluvia, Diluvia, maintain
    		log always ildiri in Diluvia charstart
    	end_if
    	if I_SettlementOwner Goryanger = hre
    		and I_CharacterExists Invade_Goryanger
    		siege_settlement Invade_Goryanger, Goryanger, maintain
    		log always ildiri in Goryanger charstart
    	end_if
    end_monitor
    
    monitor_event SettlementTurnStart TrueCondition
    	if I_SettlementOwner Molehale = hre
    		and I_CharacterExists Invade_Molehale
    		siege_settlement Invade_Molehale, Molehale, maintain
    		log always ildiri in molehale settle
    	end_if
    	if I_SettlementOwner Diluvia = hre
    		and I_CharacterExists Invade_Diluvia
    		siege_settlement Invade_Diluvia, Diluvia, maintain
    		log always ildiri in Diluvia settle
    	end_if
    	if I_SettlementOwner Goryanger = hre
    		and I_CharacterExists Invade_Goryanger
    		siege_settlement Invade_Goryanger, Goryanger, maintain
    		log always ildiri in Goryanger settle
    	end_if
    end_monitor
    
    monitor_event SettlementTurnEnd TrueCondition
    	if I_SettlementOwner Molehale = hre
    		and I_CharacterExists Invade_Molehale
    		siege_settlement Invade_Molehale, Molehale, maintain
    		log always ildiri in molehale settleend
    	end_if
    	if I_SettlementOwner Diluvia = hre
    		and I_CharacterExists Invade_Diluvia
    		siege_settlement Invade_Diluvia, Diluvia, maintain
    		log always ildiri in Diluvia settleend
    	end_if
    	if I_SettlementOwner Goryanger = hre
    		and I_CharacterExists Invade_Goryanger
    		siege_settlement Invade_Goryanger, Goryanger, maintain
    		log always ildiri in Goryanger settleend
    	end_if
    end_monitor

    they still bog off every other turn

  9. #9
    Gigantus's Avatar I am not special - I am a limited edition.
    Patrician took an arrow to the knee spy of the council

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    53,132
    Blog Entries
    35

    Default Re: Forcing AI to besiege settlement.

    Read my edit, re moving and then initiating the siege










  10. #10

    Default Re: Forcing AI to besiege settlement.

    Even if that does work, you're playing as England - and you're presumeably not giving him a command to lift the siege and walk home - which is what the AI is doing to my attacking faction.

    So siege_settlement is working, he gets there and lays siege, but at some point AI is deciding to lift siege and walk off, then he gets the script command again and goes back restarts siege etc etc etc

    think I'll try removing his movement points when he gets there and see if that helps.

  11. #11
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    6,329

    Default Re: Forcing AI to besiege settlement.

    Mak, try doing siege_settlement in (only) france's turn end and lock him via a "MovementPoints -100" trait. You can give him that trait during the spawn - it won't kick in until next turn.

    That should hold him in place (though not necessarily his units) every turn and the siege_settlement (every turn end) should re-engage the siege in case he broke it during his turn.

    Changing your OP's script to FactionTurnEnd - and adding the trait - should do it.

    EDIT: ninjad.

  12. #12

    Default Re: Forcing AI to besiege settlement.

    Quote Originally Posted by Withwnar View Post
    Changing your OP's script to FactionTurnEnd - and adding the trait - should do it.
    that does seem to work, Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •