Results 1 to 10 of 10

Thread: Setting FACTION limits for agents

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default Setting FACTION limits for agents

    I got a bit tired of AI spamming spies and assassins, never mind the killer merchants. Feeling that increasing the cost is counterproductive I tried limiting the number of agents per faction. Using the faction_capability in the EDB didn't work out as it either adds or reduces the agent_limit per building.
    So I turned to the scripting way and would like some input if there is a better way as the current method requires one monitor per faction and per agent type:

    Code:
    declare_counter england_spy_counter
    monitor_event CharacterTurnEnd FactionType england
        and AgentType spy
        inc_counter england_spy_counter 1
        if I_CompareCounter england_spy_counter > 1   ; corresponding to desired max number
            set_event_counter england_spy_limit 1
        end_if
            if I_CompareCounter england_spy_counter < 2   ; corresponding to desired max number
            set_event_counter england_spy_limit 0
        end_if
    end_monitor
    EDB entry
    Code:
                capability
                {
                    agent spy  0  requires factions { england, } and not event_counter england_spy_limt 1
                    agent_limit spy 1    ; still needs to be set to restrict at lower levels of building count
                }
    Last edited by Gigantus; March 07, 2014 at 02:46 AM.










  2. #2
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default Re: Setting FACTION limits for agents

    I just realized I had not made a provision to reset the event_counter, plus a discussion in another thread (thanks withnwar) made me rediscover the TrueCondition entry. Please note that this will not work for regular recruiting as the pool will be reset to zero every round.

    Code:
    declare_counter spy_counter
    
    monitor_event PreFactionTurnStart TrueCondition
            set_event_counter spy_limit 0     ; resetting the counter for the coming faction
    end_monitor
    
    monitor_event CharacterTurnEnd TrueCondition
        and AgentType = spy
        inc_counter spy_counter 1
        if I_CompareCounter spy_counter > 1   ; corresponding to desired max number
            set_event_counter spy_limit 1
        end_if
            if I_CompareCounter spy_counter < 2   ; corresponding to desired max number
            set_event_counter spy_limit 0
        end_if
    end_monitor
    Code:
                capability
                {
                    agent spy  0  requires factions { all, } and not event_counter spy_limt 1
                    agent_limit spy 1    ; still needs to be set to restrict at lower levels of building count
                }
    Last edited by Gigantus; March 07, 2014 at 03:38 AM.










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

    Default Re: Setting FACTION limits for agents

    If it is to be the same max for all factions then you could use just the one counter and monitor (per agent type).

    Code:
    declare_counter spy_count
    declare_counter assassin_count
    
    monitor_event PreFactionTurnStart TrueCondition
      set_counter spy_count 0
      set_event_counter spy_limit_reached 0
      set_counter assassin_count 0
      set_event_counter assassin_limit_reached 0
    end_monitor
    
    monitor_event CharacterTurnStart AgentType spy
      inc_counter spy_count 1
      if I_CompareCounter spy_count >= 1   ; corresponding to desired max number of spies
        set_event_counter spy_limit_reached 1
      end_if
    end_monitor
    
    monitor_event CharacterTurnStart AgentType assassin
      inc_counter assassin_count 1
      if I_CompareCounter assassin_count >= 1   ; corresponding to desired max number of assassins
        set_event_counter assassin_limit_reached 1
      end_if
    end_monitor
    EDB:
    Code:
    capability
    {
      agent spy 0 requires factions { england, ...other factions..., } and not event_counter spy_limit_reached 1
      agent_limit spy 1
    }
    Recruitment queuing happens before CharacterTurnEnd so by the time that event happens it would be too late to impose the EDB restrictions. In the above script it would be setting restrictions for the next faction based on agent numbers of the current faction. CharacterTurnStart avoids those problems.

    If you want different max's for different factions then I would do it like this...

    Code:
    ;faction_id: whose turn is it?
    ; 1 = england (spy = 2, assassin = 4)
    ; 2 = france  (spy = 3, assassin = 3)
    ; 3 = hre     (spy = 4, assassin = 1)
    declare_counter faction_id
    
    declare_counter spy_count
    declare_counter assassin_count
    
    monitor_event PreFactionTurnStart FactionType england
      set_counter faction_id 1
    end_monitor
    
    monitor_event PreFactionTurnStart FactionType france
      set_counter faction_id 2
    end_monitor
    
    monitor_event PreFactionTurnStart FactionType hre
      set_counter faction_id 3
    end_monitor
    
    monitor_event PreFactionTurnStart TrueCondition
      set_counter spy_count 0
      set_event_counter spy_limit_reached 0
      set_counter assassin_count 0
      set_event_counter assassin_limit_reached 0
    end_monitor
    
    monitor_event CharacterTurnStart AgentType spy
      inc_counter spy_count 1
      
      if I_CompareCounter faction_id == 1  ;england
        and I_CompareCounter spy_count >= 2
        set_event_counter spy_limit_reached 1
      end_if
      if I_CompareCounter faction_id == 2  ;france
        and I_CompareCounter spy_count >= 3
        set_event_counter spy_limit_reached 1
      end_if
      if I_CompareCounter faction_id == 3  ;hre
        and I_CompareCounter spy_count >= 4
        set_event_counter spy_limit_reached 1
      end_if
      
    end_monitor
    
    monitor_event CharacterTurnStart AgentType assassin
      inc_counter assassin_count 1
      
      if I_CompareCounter faction_id == 1  ;england
        and I_CompareCounter assassin_count >= 4
        set_event_counter assassin_limit_reached 1
      end_if
      if I_CompareCounter faction_id == 2  ;france
        and I_CompareCounter assassin_count >= 3
        set_event_counter assassin_limit_reached 1
      end_if
      if I_CompareCounter faction_id == 3  ;hre
        and I_CompareCounter assassin_count >= 1
        set_event_counter assassin_limit_reached 1
      end_if
      
    end_monitor
    Still not pretty but at least it's only 1 + faction_count + agent_count monitors instead of 1 + (faction_count x agent_count) monitors.

    EDIT: Are changes in event counter values during xxxStart events reflected in recruitment conditions that use them for that turn? I half remember a problem related to that way of doing it.

    EDIT2: ah, I didn't see post 2 in time.
    Last edited by Withwnar; March 07, 2014 at 03:34 AM.

  4. #4
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default Re: Setting FACTION limits for agents

    I was battling for a while and then realized that 'AgentType' comes with an equal sign

    Still testing if it actually works...


    Edit: my scripts usually have 'faction counters' to create the equivalent of faction IDs:

    Code:
        declare_counter england_turn
        monitor_event PreFactionTurnStart FactionType england
            set_counter england_turn 1
            set_counter reichs_fraktion 0     ; additional counters for 1648
            set_counter katholisch 0      ; additional counters for 1648
        end_monitor
        monitor_event FactionTurnEnd FactionType england
            set_counter england_turn 0
        end_monitor
        declare_counter england_dead
        monitor_event LeaderDestroyedFaction FactionType england
            set_counter england_dead 1
            terminate_monitor
        end_monitor
    Edit2: just realized the typo in the EDB entry (limt instead of limit)
    Last edited by Gigantus; March 07, 2014 at 03:57 AM.










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

    Default Re: Setting FACTION limits for agents

    Quote Originally Posted by Withwnar
    Are changes in event counter values during xxxStart events reflected in recruitment conditions that use them for that turn? I half remember a problem related to that way of doing it.
    Maybe it was this that I was thinking of...
    Quote Originally Posted by Gigantus
    Please note that this will not work for regular recruiting as the pool will be reset to zero every round.
    ...because I just tested mine and it works.

    I was battling for a while and then realized that 'AgentType' comes with an equal sign
    It must be optional. Mine doesn't use one either and it wouldn't have worked properly if a missing = is incorrect syntax.

  6. #6
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default Re: Setting FACTION limits for agents

    Heureka! Confirmed working by
    a) recruiting max number (2) of spys --> recruiting disabled\not available in the next round (when spies are available)
    b) suiciding a spy --> recruiting enabled\available in the next round

    Resetting the spy_limit event_counter somehow didn't work with the IF condition, probably because of the sequence of CTS and FTS.

    Thanks for the help, here the complete working script - time for another 'resource' me thinks.

    Code:
    declare_counter spy_counter
    
    monitor_event PreFactionTurnStart TrueCondition
            set_event_counter spy_limit 0
            set_counter spy_counter 0
    end_monitor
    
    monitor_event CharacterTurnStart TrueCondition
        and AgentType = spy
        inc_counter spy_counter 1
            if I_CompareCounter spy_counter > 1   ; corresponding to desired max number
                set_event_counter spy_limit 1
            end_if
    end_monitor
    Code:
                capability
                {
                    agent spy  0  requires factions { all, } and not event_counter spy_limt 1
                    agent_limit spy 1    ; still needs to be set to restrict at lower levels of building count
                }
    Last edited by Gigantus; March 07, 2014 at 04:19 AM.










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

    Default Re: Setting FACTION limits for agents

    Yay! Happy to help.

    Resetting the spy_limit event_counter somehow didn't work with the IF condition, probably because of the sequence of CTS and FTS.
    In your earlier scripts you were using CharacterTurnEnd; the event counter would have always been 0 during any faction's "perform actions" time, including the player's...

    player actions: recruitment etc.
    hit turn end button
    player faction's CharacterTurnEnd: event counter = 1 (maybe)
    other faction turns
    player faction's PreFactionTurnStart: event counter = 0
    player actions: recruitment etc.

    BTW, adding a "not FactionIsLocal" condition to the CTS monitor will impose these limits on the AI only.

    These are the same thing...
    Code:
    monitor_event CharacterTurnStart TrueCondition
        and AgentType = spy
    Code:
    monitor_event CharacterTurnStart AgentType = spy
    TrueCondition is only needed when there are no other conditions.

  8. #8
    irishron's Avatar Cura Palatii
    Moderator Emeritus

    Join Date
    Feb 2005
    Location
    Cirith Ungol
    Posts
    47,023

    Default Re: Setting FACTION limits for agents

    A couple of dumb questions since it's not even 3AM here yet, (1)can this be used to slow down ai assassin recruitment, and (2)will this slow down ai's ability to spam thieves guilds?

  9. #9
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default Re: Setting FACTION limits for agents

    It will slow the recruitment as the limit is not the old 'number of recruiting buildings multiplied by agent_limit' principle but a straight number limit of your choice.
    Generating action points for the guilds is linked to recruitment of their agents among other things, so it should slow down that as well.

    The tutorial










  10. #10
    irishron's Avatar Cura Palatii
    Moderator Emeritus

    Join Date
    Feb 2005
    Location
    Cirith Ungol
    Posts
    47,023

    Default Re: Setting FACTION limits for agents

    Very good, then. Another one of my pet peeves.

Posting Permissions

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