Results 1 to 7 of 7

Thread: Test that a faction is dead/alive including hordes

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

    Default Test that a faction is dead/alive including hordes

    I_NumberOfSettlements is one way to test whether a faction is alive but it doesn't necessarily work for horde factions because they can be alive without owning any settlements.

    An alternative is to use the I_FactionLeaderAttribute condition because it will only work if a faction has a faction leader; if they do not have a faction leader then they must be dead, a rule that also applies to hordes.

    For example, to test that the Mongols are alive:

    Code:
    monitor_event (whatever)
    
      if I_FactionLeaderAttribute mongols Command < 999
        ;yes they are alive: do whatever...
      end_if
    
    end_monitor
    If they have no faction leader (they are dead) then that condition returns false. If they do have a faction leader (they are alive) then it returns true, assuming that he does not have Command >= 999 (which would only be possible if some wild script, trait or ancillary was giving him that much for a special reason).

    Testing that they are dead is a little more complicated. It needs an additional counter...

    Code:
    declare_counter faction_is_dead
    
    monitor_event (whatever)
    
      set_counter faction_is_dead 1  ;default to dead=true
    
      if I_FactionLeaderAttribute mongols Command < 999
        ;they are alive: set dead=false
        set_counter faction_is_dead 0
      end_if
    
      if I_CompareCounter faction_is_dead == 1
        ;yes they are dead: do whatever...
      end_if
    
    end_monitor
    Because I_FactionLeaderAttribute is an independent (I_xxx) condition it can be used anywhere and anytime. e.g. Within the body of monitors.

    There are other ways to test for the alive-ness of factions, such as testing whether any CharacterTurnStart event fires for that faction, but such testing is at the mercy of the timing of events, i.e. end of turn. And if you need to test more than one faction then each faction would need its own monitor(s), whereas this I_FactionLeaderAttribute way can be used multiple times within one monitor.

    e.g. Script to test if more than one faction is dead, all in one monitor...

    Code:
    declare_counter faction_is_dead
    
    monitor_event (whatever)
      ;mongols dead?
      set_counter faction_is_dead 1
      if I_FactionLeaderAttribute mongols Command < 999
        set_counter faction_is_dead 0
      end_if
      if I_CompareCounter faction_is_dead == 1
        ;yes mongols are dead: do whatever...
      end_if
    
      ;england dead?
      set_counter faction_is_dead 1
      if I_FactionLeaderAttribute england Command < 999
        set_counter faction_is_dead 0
      end_if
      if I_CompareCounter faction_is_dead == 1
        ;yes england is dead: do whatever...
      end_if
    
      ;france dead?
      set_counter faction_is_dead 1
      if I_FactionLeaderAttribute france Command < 999
        set_counter faction_is_dead 0
      end_if
      if I_CompareCounter faction_is_dead == 1
        ;yes france is dead: do whatever...
      end_if
    end_monitor

    UPDATE:
    I just discovered that doing this during PostBattle or CeasedFactionLeader won't work. e.g. If the leader has just been killed then CeasedFactionLeader does fire (even if no other characters remain to take his place) but at the time of this event firing the just-killed leader is still the leader, so I_FactionLeaderAttribute is still looking at him which breaks the whole concept. PostBattle has the same problem.

    So while this technique is fine during turn start/end etc. events it falls down when the test needs to be done as soon as the faction is destroyed. This thread has a solution to that: http://www.twcenter.net/forums/showt...3#post13890413

    UPDATE 2:
    If the faction has family_tree = "no" in descr_sm_factions.txt then it is possible for the faction to be alive without a leader. This method won't work in this case; it will report that the faction is dead when it is not. Thanks gsthoed.
    Last edited by Withwnar; November 15, 2014 at 10:31 PM.

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

    Default Re: Test that a faction is dead/alive including hordes

    Update added to the OP.

  3. #3

    Default Re: Test that a faction is dead/alive including hordes

    Quote Originally Posted by Withwnar View Post
    UPDATE:
    I just discovered that doing this during PostBattle or CeasedFactionLeader won't work. e.g. If the leader has just been killed then CeasedFactionLeader does fire (even if no other characters remain to take his place) but at the time of this event firing the just-killed leader is still the leader, so I_FactionLeaderAttribute is still looking at him which breaks the whole concept. PostBattle has the same problem.
    With a little "risk", we can make "CeasedFactionleader" work, by adding a campaign wait. I'll post some other time about this (and I better do it in the faction destroyed thread? ).

    Anyway, I think I have found an exception on the I_FactionLeaderAtrribute rule : A papal_faction+family_tree "no" (+no catholic? priests worldwide for "immortal pope Saurons") can be alive without any faction leader.

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

    Default Re: Test that a faction is dead/alive including hordes

    With a little "risk", we can make "CeasedFactionleader" work, by adding a campaign wait. I'll post some other time about this (and I better do it in the faction destroyed thread? ).
    I don't think that this is any more "riskier" than the current best solution(s) in that other thread because they both yield execution as well (while loop and monitor_conditions). This would be a more efficient way to do it, so yes please: in that other thread would be great.

    I think I have found an exception on the I_FactionLeaderAtrribute rule : A papal_faction+family_tree "no" (+no catholic? priests worldwide for "immortal pope Saurons") can be alive without any faction leader.
    Ah! An early version of TATW had a bug where some factions (e.g. Mordor) could not be destroyed even when they had no family/generals left and this was due to them having family_tree=no.

    I'll update the OP with this.

  5. #5

    Default Re: Test that a faction is dead/alive including hordes

    Quote Originally Posted by Withwnar View Post
    Ah! An early version of TATW had a bug where some factions (e.g. Mordor) could not be destroyed even when they had no family/generals left and this was due to them having family_tree=no.
    I'll update the OP with this.
    EDIT: True, it applies to all factions with family_tree=no
    Spoiler Alert, click show to read: 
    Yesterday and before posting, I destroyed a faction with family_tree=no by only killing its family/generals. It has to be a faction with the special_faction_type papal_faction entry in descr_sm_factions.txt EDIT: I had a false experimental design; this conclusion is not true.
    The "test" I did was this: It was Mordor faction of DaC submod for TATW. It had that special_faction_type but family_tree=teutonic. I killed their faction leader when there was no other catholic priest and faction got destroyed.
    I repeated the test with family_tree=no and I got the same result as the papal_faction of Stainless Steel: faction was alive and no faction leader. It's like "they are waiting the new Pope".

    Nevertheless, it is only a small issue for themethod; since this faction can be destroyed only via command, we know that they are alive until the command is issued.
    Last edited by gsthoed; November 16, 2014 at 07:48 AM.

  6. #6

    Default Re: Test that a faction is dead/alive including hordes

    I was wrong, there is no need for the special_faction_type papal_faction entry. I have updated my previous post

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

    Default Re: Test that a faction is dead/alive including hordes

    Good, thanks for the update.

Posting Permissions

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