Results 1 to 12 of 12

Thread: Checking whether AI has ships and if not, then spawn them a navy

  1. #1
    Jadli's Avatar The Fallen God
    Gaming Emeritus

    Join Date
    Dec 2013
    Location
    Czech Republic
    Posts
    8,528

    Default Checking whether AI has ships and if not, then spawn them a navy

    I was trying to find a way to be able to check if AI has any ships, and if not, spawn them new ones, which is of course more effective than just giving them ships time from time. As for some factions it may be essential for their AI to have some. And in case they are also bankrupted fir example, they are done for.

    I think, this is the only way? (I tested it, works)

    Code:
    ;------------------------------------------
    Trigger naval_gunner_vnv_trigger2
        WhenToTest AgentCreated
        Condition IsAdmiral
    
    
        AcquireAncillary naval_navigator chance  100 
        
    ;------------------------------------------
    Trigger naval_gunner_vnv_trigger2
        WhenToTest CharacterTurnEnd
        Condition IsAdmiral
    
    
        AcquireAncillary naval_navigator chance  100 
        
    
    
    ;------------------------------------------
    Trigger shipwright_vnv_trigger3
        WhenToTest NewAdmiralCreated
        Condition IsAdmiral
    
    
        AcquireAncillary naval_navigator chance  100
    (one of them may be redundant)



    And script

    Code:
    monitor_event CharacterTurnStart not CharacterIsLocal
            and FactionType england
            and not FactionwideAncillaryExists naval_navigator
            ;and RandomPercent > 75
            
            campaign_wait 0.1
            
            spawn_army
                    faction        england
                    character    random_name, admiral, age 38, x 230, y 142
                    traits Sailor 1
                    unit        galleass            exp 3 armour 0 weapon_lvl 0
                end
                
        end_monitor
    So all admirals receive an ancillary, and if the ancillary doesnt exist, the factions gets new ships.

    ( I havent seen anything similar to this used in any mod, hence Im posting it)



    BTW, while at this, it seems that vanilla anc trigger "naval_gunner_vnv_trigger" is broken (it never comes true) tho "shipwright_vnv_trigger" works fine.
    Last edited by Jadli; March 12, 2021 at 07:33 AM.

  2. #2
    bitterhowl's Avatar Campidoctor
    Join Date
    Feb 2011
    Location
    Russian Feodality
    Posts
    1,695

    Default Re: Checking whether AI has ships and if not, then spawn them a navy

    Good idea!

    For the sake of optimisation CharacterTurnStart event should be changed for something less frequent one. Does FactionTurnStart export FactionwideAncillaryExists condition?

    My sister, do you still recall the blue Hasan and Khalkhin-Gol?
    Russian warship is winning. Proofs needed? Go find yourself!

  3. #3
    z3n's Avatar State of Mind
    took an arrow to the knee

    Join Date
    Aug 2011
    Posts
    4,640

    Default Re: Checking whether AI has ships and if not, then spawn them a navy

    Neat and this should be in the tutorials section if it's a tutorial.
    The AI Workshop Creator
    Europa Barbaroum II AI/Game Mechanics Developer
    The Northern Crusades Lead Developer
    Classical Age Total War Retired Lead Developer
    Rome: Total Realism Animation Developer
    RTW Workshop Assistance MTW2 AI Tutorial & Assistance
    Broken Crescent Submod (M2TW)/IB VGR Submod (BI)/Animation (RTW/BI/ALX)/TATW PCP Submod (M2TW)/TATW DaC Submod (M2TW)/DeI Submod (TWR2)/SS6.4 Northern European UI Mod (M2TW)

  4. #4
    Jadli's Avatar The Fallen God
    Gaming Emeritus

    Join Date
    Dec 2013
    Location
    Czech Republic
    Posts
    8,528

    Default Re: Checking whether AI has ships and if not, then spawn them a navy

    Hm, seems to be kinda short, I will probably include it in some larger thread once I have one

    Quote Originally Posted by bitterhowl View Post
    Good idea!

    For the sake of optimisation CharacterTurnStart event should be changed for something less frequent one. Does FactionTurnStart export FactionwideAncillaryExists condition?
    it wasnt working with FactionTurnStart, it was saying that it couldnt export character_record, so yea...

    (and without the wait, it was crashing)

  5. #5
    Jadli's Avatar The Fallen God
    Gaming Emeritus

    Join Date
    Dec 2013
    Location
    Czech Republic
    Posts
    8,528

    Default Re: Checking whether AI has ships and if not, then spawn them a navy

    alright then

  6. #6
    bitterhowl's Avatar Campidoctor
    Join Date
    Feb 2011
    Location
    Russian Feodality
    Posts
    1,695

    Default Re: Checking whether AI has ships and if not, then spawn them a navy

    Ah, yes, I remembered same script with FactionwideAncillaryExists for BellumCrucis I tried to optimize. I used there IsFactionLeader - if character is not FL monitor ends at first line.

    My sister, do you still recall the blue Hasan and Khalkhin-Gol?
    Russian warship is winning. Proofs needed? Go find yourself!

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

    Default Re: Checking whether AI has ships and if not, then spawn them a navy

    A possible problem there is that every recruited ship becomes a 'true' admiral --> can't merge with any other ships because they're true admirals too --> no fleets, just single ships, reducing their naval battle chances against the player who can merge as normal.

    True admiral being one that has any trait points or ancs.

  8. #8
    Jadli's Avatar The Fallen God
    Gaming Emeritus

    Join Date
    Dec 2013
    Location
    Czech Republic
    Posts
    8,528

    Default Re: Checking whether AI has ships and if not, then spawn them a navy

    Hm, thats true... though I think that the AI doesnt merge/divide ships much anyway... if you give them a half stack, they will likely keep the half stack together, at least in my experience

    But its definitely a downside of this

  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,125
    Blog Entries
    35

    Default Re: Checking whether AI has ships and if not, then spawn them a navy

    You could do a character turn end monitor that checks for agent type and if it's an admiral increases a counter by 1. And then at faction turn end spawn a fleet if the counter is zero, don't forget to put a counter reset IF section below the spawn IF section.










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

    Default Re: Checking whether AI has ships and if not, then spawn them a navy

    Or possibly this...

    Code:
    declare_counter admiral_exists
    
    monitor_event FactionTurnStart FactionType slave
    
      set_counter admiral_exists 0
      if I_CharacterTypeNearTile england admiral 1000 0,0
        set_counter admiral_exists 1
      end_if
      if I_CompareCounter admiral_exists = 0
        ;no england admirals: spawn one
      end_if
    
      set_counter admiral_exists 0
      if I_CharacterTypeNearTile france admiral 1000 0,0
        set_counter admiral_exists 1
      end_if
      if I_CompareCounter admiral_exists = 0
        ;no france admirals: spawn one
      end_if
    
      ;...repeat for other factions...
    
    end_monitor
    Last edited by Withwnar; March 23, 2021 at 04:08 AM. Reason: typo

  11. #11
    Jadli's Avatar The Fallen God
    Gaming Emeritus

    Join Date
    Dec 2013
    Location
    Czech Republic
    Posts
    8,528

    Default Re: Checking whether AI has ships and if not, then spawn them a navy

    Ah, both solutions seems MUCH more reliable than my imperfect one

    Seems Withwnar's solution is more efficient turn times wise, as it doesnt use CharacterTurnEnd, will try if it works


    Talking of this, how would one check how many family members a faction has, and spawn more if needed?

    EDIT Necroquote from Withwnar to me like 3 years ago

    Quote Originally Posted by Withwnar View Post
    That's what I ended up doing via traits given to - and inherited by - anybody in a family tree. Script counts how many characters currently have this trait, then spawns a new one (with the "family" attribute/tag) when that number falls below a certain level.

    There's no way to count living (or dead) family members directly. The only thing that comes close is I_NumberOfHeirs but it counts all generals (named characters) including the leader, whether they're actually family or not, and does not include off map characters. i.e. It's really a I_NumberOfNamedCharactersOnMap condition.
    I assume if you also give the trait to the the adopted/married/manofhour generals via its triggers (LesserGeneralOfferedForAdoption) etc, it covers all the family members, right? Or is there still some hole?
    Last edited by Jadli; March 22, 2021 at 06:37 AM.

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

    Default Re: Checking whether AI has ships and if not, then spawn them a navy

    Quote Originally Posted by Jadli View Post
    I assume if you also give the trait to the the adopted/married/manofhour generals via its triggers (LesserGeneralOfferedForAdoption) etc, it covers all the family members, right? Or is there still some hole?
    And CharacterComesOfAge, yes, and given to all starting family members in descr_strat.

Posting Permissions

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