Page 3 of 5 FirstFirst 12345 LastLast
Results 41 to 60 of 92

Thread: Campaign Script Optimizations

  1. #41

    Default Re: Campaign Script Optimizations

    Quote Originally Posted by gsthoed View Post
    Haven't tried, but mongols_invasion and timurids_invasion even_counters don't do the job? For example, as soon as timurids_invasion sets to 1, there is a monitor that starts spawning them in the same manner that inquisition triggers the spawning of teutonic_order; same for mongols.
    Dunno, i think they might but will have to test just to be sure

  2. #42

    Default Re: Campaign Script Optimizations

    Now, something that reduces significantly the turn end times. It is a faction economy script. It is based on MWY G5 faction economy script for SSHIP as it has been implemented by Melooo182 in the bugfix compilation. This new script does exactly the same job, but in 45 monitors instead of 345. For my humble dual core Pentium E2200, this means more than 6 seconds less from LocalFaction's turn_end till its next PreTurnStart.

    Step 1:
    This part is not included in the attached file, as I use the monitors in "is the AI?" section.
    I introduce a new counter, named ai_ec_id, which in each PreFactionTurnStart takes a value depending which faction's turn is "on".

    Spoiler Alert, click show to read: 
    Code:
    ;===================== Is the AI? =======================
    ;----- This is used in Faction Economy Script ---------
    declare_counter ai_ec_id ; 1=rebels, 2=venice etc
    
    ; Is the AI?: declare counters above this line
    
    monitor_event PreFactionTurnStart FactionIsLocal
        set_event_counter is_the_ai 0
        set_event_counter citadel_boost 0
        set_event_counter freeze_recr_pool 0
    
    ; it is not the AI; set counters below this line
        set_counter ai_ec_id 0 ; is used in G5 Faction Economy Script
    ...
    end_monitor
    
    monitor_event PreFactionTurnStart not FactionIsLocal
        set_event_counter is_the_ai 1
        set_event_counter citadel_boost 0
        set_event_counter freeze_recr_pool 0
    
    ; it is the AI; set counters below this line
        set_counter ai_ec_id 1 ; is used in G5 Faction Economy Script
    ...
    end_monitor


    Step 2:
    In the main section of the economy script and after the necessary declaration of the new counters, we have monitors that set the ai_ec_id the value we want.

    Spoiler Alert, click show to read: 
    Code:
    ;============= G5 FACTION ECONOMY SCRIPT (MWY FIX) ================
    ;Part 1 -- Declare_counters and set ai_ec_id
    declare_counter freeze_venice
    declare_counter freeze_sicily
    ...
    
    ; it's venice 's turn
    monitor_event PreFactionTurnStart FactionType venice
        and IsFactionAIControlled
    
        set_counter ai_ec_id 2
    end_monitor
    
    ; it's sicily 's turn
    monitor_event PreFactionTurnStart FactionType sicily
        and IsFactionAIControlled
    
        set_counter ai_ec_id 3
    end_monitor
    
    ...
    monitor_event PreFactionTurnStart FactionType kwarezm
        and IsFactionAIControlled
    
        set_counter ai_ec_id 29
    end_monitor


    Step 3: For each economic level (in the appropriate order, of course), we have one quite large that checks which identifies which faction's turn is on and issues the corresponding commands. For example:
    Spoiler Alert, click show to read: 
    Code:
    monitor_event PreFactionTurnStart I_CompareCounter ai_ec_id > 0
        and Treasury < -15000
        and Treasury > -20001
    
        if I_CompareCounter ai_ec_id = 1
            set_counter ai_ec_id 0
            add_money slave 20100
        end_if
    
        if I_CompareCounter ai_ec_id = 2
            set_counter freeze_venice 0
            add_money venice 17500
            set_event_counter freeze_recr_pool 1
        end_if
        
        if I_CompareCounter ai_ec_id = 3
            set_counter freeze_sicily 0
            add_money sicily 17500
            set_event_counter freeze_recr_pool 1
        end_if
    
    ...
        if I_CompareCounter ai_ec_id = 29
            set_counter freeze_kwarezm 0
            add_money kwarezm 17500
            set_event_counter freeze_recr_pool 1
        end_if
    
     end_monitor

    Of course, there are some special monitors for slave_faction for the debt levels that are different from the "ranked" factions.
    There are some other minor optimiztions too, but the big deal is the reduction of the total number of monitors.

    Some considerations:
    a) Slave_faction is treated always as AIControlled faction. So, if you want to take control of them and remove the bonus that script gives them, you'll have to add into "part 1" a new monitor.
    b) In part 1, I 've commented out the condition "and IsFactionAIControlled" for all other unplayable factions of early campaign (that is, for papal_states, teutonic_order, mongols, timurids). So, if you want to take control of these, search for
    ; and IsFactionAIControlled ;always true, as this faction is unplayable
    and change accordingly.

    EDIT: Script updated, mainly to fix an error
    Spoiler Alert, click show to read: 
    a) Monitor in Part 4a (Debt > 40000): It was
    Code:
    monitor_event PreFactionTurnStart I_CompareCounter ai_ec_id > 1
        and Treasury < -40000
    This didn't allow check for slave_faction's treasury. It has been replaced with:
    Code:
    monitor_event PreFactionTurnStart IsFactionAIControlled
        and Treasury < -40000
    b) Part 4b's first monitor:
    Code:
     ;Part 4b -- Treasury goes positive for slaves.
    monitor_event PreFactionTurnStart I_CompareCounter ai_ec_id > 0
        and Treasury < -20000
        and Treasury > -40001
    There was no use of the added complexity. It has been replaced with:
    Code:
    monitor_event PreFactionTurnStart IsFactionAIControlled
        and Treasury < -20000
         and Treasury > -40001

    EDIT2: This can a better idea.
    Attached Files Attached Files
    Last edited by gsthoed; August 03, 2014 at 04:54 AM. Reason: add comment

  3. #43
    Andytheplatypus's Avatar Domesticus
    Join Date
    Jan 2010
    Location
    . U.S. - MS, Gulf Coast.
    Posts
    2,384

    Default Re: Campaign Script Optimizations

    Wow thats impressive + rep

  4. #44

    Default Re: Campaign Script Optimizations

    A little "break" for an optimisation not related directly to SS6.4's CSs, but about something I see quite often lately .
    I know it has been discussed elsewhere, I' ve tried search for a relevant thread (ok, I didn't search the whole mod workshop) but I couldn't find any.
    It's about scripted renaming of settlements.

    Let's say we want Palanga to be renamed to Konigsberg when TOs take ownership of it.
    One way is this:

    Code:
    monitor_conditions I_SettlementOwner Palanga = teutonic_order
    
        change_settlement_name Palanga Konigsberg
    terminate_monitor
    end_monitor
    There are these two alternative ways to do it without "monitor_conditions". Remove semicolons according to your liking.
    Proposal A: We use the OccupySettlement, SackSettlement and ExterminatePopulation events
    Spoiler Alert, click show to read: 
    Code:
    ; Proposal A 
    ;if not I_HotseatEnabled
    declare_counter palanga_to_konigsberg
    ;end_if
    
    monitor_event OccupySettlement FactionType teutonic_order
    
    ;    if I_HotseatEnabled
    ;    and not I_IsFactionAIControlled teutonic_order
    ;        terminate_monitor
    ;    end_if
        if I_CompareCounter palanga_to_konigsberg = 1
            terminate_monitor
        end_if
    
        if I_SettlementOwner Palanga = teutonic_order
            change_settlement_name Palanga Konigsberg
            set_counter palanga_to_konigsberg 1
            terminate_monitor
        end_if
    
    end_monitor
    
    monitor_event SackSettlement FactionType teutonic_order
    
    ;    if I_HotseatEnabled
    ;    and not I_IsFactionAIControlled teutonic_order
    ;        terminate_monitor
    ;    end_if
        if I_CompareCounter palanga_to_konigsberg = 1
            terminate_monitor
        end_if
    
        if I_SettlementOwner Palanga = teutonic_order
            change_settlement_name Palanga Konigsberg
            set_counter palanga_to_konigsberg 1
            terminate_monitor
        end_if
    
    end_monitor
    
    monitor_event ExterminatePopulation FactionType teutonic_order
    
    ;    if I_HotseatEnabled
    ;    and not I_IsFactionAIControlled teutonic_order
    ;        terminate_monitor
    ;    end_if
        if I_CompareCounter palanga_to_konigsberg = 1
            terminate_monitor
        end_if
    
        if I_SettlementOwner Palanga = teutonic_order
            change_settlement_name Palanga Konigsberg
            set_counter palanga_to_konigsberg 1
            terminate_monitor
        end_if
    
     end_monitor

    It's the "lighter" one, but it doesn't apply renaming if Palanga is gifted to teutonic order.

    Proposal B
    : More resourceful than A and it doesn't apply renaming immediately (usually and if you play with fog_of_war off, you can't see the difference)
    Spoiler Alert, click show to read: 
    Code:
    monitor_event FactionTurnEnd FactionType teutonic_order
    
    ;    if I_HotseatEnabled
    ;    and not I_IsFactionAIControlled teutonic_order
    ;        terminate_monitor
    ;    end_if
    
        if I_SettlementOwner Palanga = teutonic_order
            change_settlement_name Palanga Konigsberg
            terminate_monitor
        end_if
    
    end_monitor
    Last edited by gsthoed; July 20, 2014 at 08:49 PM.

  5. #45

    Default Re: Campaign Script Optimizations

    Genoese Reinforcement and Seljuk Reinforcement need tweaking, they part of the AI reinforcements script section, but instead of having a monitor each, they could be moved to the same monitor of the Startup reinforcements. (early era only has the Seljuk one)

    This is how they are in late era campaign_script
    It also has a wtf script part
    Spoiler Alert, click show to read: 
    Code:
    ;---- Genoese Reinforcement
    monitor_event FactionTurnStart FactionIsLocal
        and IsFactionAIControlled
        and I_TurnNumber = 0
        and I_LocalFaction byzantium
    
    
        spawn_army 
            faction milan
            character    Francesco, general, age 28, x 329, y 170
            unit        Feudal Knights                exp 2 armour 0 weapon_lvl 0
            unit        Armored Sergeants                exp 1 armour 1 weapon_lvl 0
            unit        Armored Sergeants                exp 0 armour 1 weapon_lvl 0
            unit        Urban Crossbow Militia                exp 2 armour 2 weapon_lvl 0
            unit        Urban Crossbow Militia                exp 2 armour 2 weapon_lvl 0
            unit        Urban Crossbow Militia                exp 2 armour 2 weapon_lvl 0
            unit        Urban Crossbow Militia                exp 1 armour 2 weapon_lvl 0
            unit        Feudal Knights                exp 2 armour 0 weapon_lvl 0
            unit        Feudal Knights                exp 2 armour 0 weapon_lvl 0
            unit        Dismounted Feudal Knights                exp 2 armour 0 weapon_lvl 0
        end
    
    
        add_money milan, 18000
        terminate_monitor
    end_monitor
    
    
    ;---- Seljuk Reinforcement
    monitor_event FactionTurnStart FactionIsLocal
        and I_LocalFaction byzantium
        and I_IsFactionAIControlled turks
    
    
        spawn_army 
            faction turks
            character    Kasim, general, age 28, x 293, y 135
            unit        ME Bodyguard                exp 1 armour 0 weapon_lvl 0
            unit        Turkish Archers                exp 0 armour 0 weapon_lvl 0
            unit        ME Spear Militia                exp 0 armour 0 weapon_lvl 0
            unit        ME Spear Militia                exp 0 armour 0 weapon_lvl 0
            unit        ME Spear Militia                exp 0 armour 0 weapon_lvl 0
            unit        Turkomans                exp 1 armour 0 weapon_lvl 0
            unit        Turkish Archers                exp 0 armour 0 weapon_lvl 0
            unit        Turkish Archers                exp 0 armour 0 weapon_lvl 0
            unit        Turkish Archers                exp 0 armour 0 weapon_lvl 0
            unit        ME Spear Militia                exp 0 armour 0 weapon_lvl 0
            unit        ME Spear Militia                exp 0 armour 0 weapon_lvl 0
            unit        ME Spear Militia                exp 0 armour 0 weapon_lvl 0
            unit        Turkomans                exp 1 armour 0 weapon_lvl 0
            unit        Turkomans                exp 1 armour 0 weapon_lvl 0
        end
    
    
        add_money turks, 18000
        terminate_monitor
    end_monitor


    Here bellow we have the optimization with both armies spawn included in the startup reinforcement monitor
    Spoiler Alert, click show to read: 
    Code:
    ;================== AI Reinforcements ===================
    ;--- Startup Reinforcement
    monitor_event PreFactionTurnStart FactionIsLocal
    ...etc other factions
        if I_IsFactionAIControlled milan
            if I_EventCounter DifficultyLevel <= 2
                spawn_army
                    faction milan
                    character    Azolino Buvalelli, named character, age 20, x 137, y 168, family
                    traits LoyaltyStarter 1 , MilitaryInclination 1 , Military_Edu 2 , GoodCommander 2 , ReligionStarter 1 , Royal_Blood_Milanese 1 , BiologicalSon 1
                    unit    SE Bodyguard        exp 2 armour 0 weapon_lvl 0
                end
            end_if
    
    
            if I_EventCounter DifficultyLevel >= 3
                spawn_army
                    faction milan
                    character    Azolino Buvalelli, named character, age 30, x 139, y 168, family
                    traits LoyaltyStarter 1 , MilitaryInclination 1 , Military_Edu 3 , GoodCommander 2 , ReligionStarter 1 , Royal_Blood_Milanese 1 , BiologicalSon 1
                    unit    SE Bodyguard        exp 2 armour 1 weapon_lvl 0
                    unit    Italian Cavalry Militia    exp 1 armour 0 weapon_lvl 0
                    unit    Pavise Spear Militia    exp 1 armour 0 weapon_lvl 0
                    unit    Pavise Spear Militia    exp 0 armour 0 weapon_lvl 0
                    unit    Sergeant Spearmen    exp 2 armour 0 weapon_lvl 0
                    unit    Sergeant Spearmen    exp 1 armour 0 weapon_lvl 0
                    unit    Urban Crossbow Militia    exp 0 armour 2 weapon_lvl 0
                    unit    Urban Crossbow Militia    exp 0 armour 2 weapon_lvl 0
                    unit    Urban Crossbow Militia    exp 0 armour 2 weapon_lvl 0
                end
            end_if
            ;---- Genoese Reinforcement if Player is Byzantium?
            if I_LocalFaction byzantium
                spawn_army 
                    faction milan
                    character    Francesco, general, age 28, x 329, y 170
                    unit        Feudal Knights                exp 2 armour 0 weapon_lvl 0
                    unit        Armored Sergeants                exp 1 armour 1 weapon_lvl 0
                    unit        Armored Sergeants                exp 0 armour 1 weapon_lvl 0
                    unit        Urban Crossbow Militia                exp 2 armour 2 weapon_lvl 0
                    unit        Urban Crossbow Militia                exp 2 armour 2 weapon_lvl 0
                    unit        Urban Crossbow Militia                exp 2 armour 2 weapon_lvl 0
                    unit        Urban Crossbow Militia                exp 1 armour 2 weapon_lvl 0
                    unit        Feudal Knights                exp 2 armour 0 weapon_lvl 0
                    unit        Feudal Knights                exp 2 armour 0 weapon_lvl 0
                    unit        Dismounted Feudal Knights                exp 2 armour 0 weapon_lvl 0
                end
                add_money milan, 18000; is this cash bonus necessary?
            end_if
        end_if
    ...other bunch of factions
        if I_IsFactionAIControlled turks
            if I_EventCounter DifficultyLevel <= 2
                spawn_army
                    faction turks
                    character    Bahadir al-Din, named character, age 20, x 339, y 133, family
                    traits LoyaltyStarter 1 , MilitaryInclination 1 , Military_Edu 2 , GoodCommander 2 , ReligionStarter 1 , Royal_Blood_Turkish 1 , BiologicalSon 1
                    unit    ME Bodyguard        exp 2 armour 0 weapon_lvl 0
                end
            end_if
    
    
            if I_EventCounter DifficultyLevel >= 3
                spawn_army
                    faction turks
                    character    Bahadir al-Din, named character, age 30, x 312, y 119, family
                    traits LoyaltyStarter 1 , MilitaryInclination 1 , Military_Edu 2 , GoodCommander 2 , ReligionStarter 1 , Royal_Blood_Turkish 1 , BiologicalSon 1
                    unit    ME Bodyguard        exp 2 armour 1 weapon_lvl 0
                    unit    Turkomans        exp 1 armour 0 weapon_lvl 0
                    unit    Turkomans        exp 1 armour 0 weapon_lvl 0
                    unit    Saracen Militia        exp 1 armour 0 weapon_lvl 0
                    unit    Saracen Militia        exp 0 armour 0 weapon_lvl 0
                    unit    Ottoman Infantry        exp 1 armour 0 weapon_lvl 0
                    unit    Ottoman Infantry        exp 0 armour 0 weapon_lvl 0
                    unit    Turkish Archers        exp 0 armour 0 weapon_lvl 0
                    unit    Turkish Archers        exp 0 armour 0 weapon_lvl 0
                end
            end_if
            ;---- Seljuk Reinforcement if Player is Byzantium
            if I_LocalFaction byzantium
                spawn_army 
                    faction turks
                    character    Kasim, general, age 28, x 293, y 135
                    unit        ME Bodyguard                exp 1 armour 0 weapon_lvl 0
                    unit        Turkish Archers                exp 0 armour 0 weapon_lvl 0
                    unit        ME Spear Militia                exp 0 armour 0 weapon_lvl 0
                    unit        ME Spear Militia                exp 0 armour 0 weapon_lvl 0
                    unit        ME Spear Militia                exp 0 armour 0 weapon_lvl 0
                    unit        Turkomans                exp 1 armour 0 weapon_lvl 0
                    unit        Turkish Archers                exp 0 armour 0 weapon_lvl 0
                    unit        Turkish Archers                exp 0 armour 0 weapon_lvl 0
                    unit        Turkish Archers                exp 0 armour 0 weapon_lvl 0
                    unit        ME Spear Militia                exp 0 armour 0 weapon_lvl 0
                    unit        ME Spear Militia                exp 0 armour 0 weapon_lvl 0
                    unit        ME Spear Militia                exp 0 armour 0 weapon_lvl 0
                    unit        Turkomans                exp 1 armour 0 weapon_lvl 0
                    unit        Turkomans                exp 1 armour 0 weapon_lvl 0
                end
                add_money turks, 18000
            end_if
        end_if
    ...and other bunch of factions
        terminate_monitor
    end_monitor

  6. #46

    Default Re: Campaign Script Optimizations

    As I am reworking on "AI Reinforcements" part of the CS since yesterday

    A "smart ass" fix that works:
    Code:
    if I_LocalFaction byzantium
    and I_IsFactionAIControlled milan
    
        spawn_army 
            faction milan
            character    Francesco, general, age 28, x 329, y 170
            unit        Feudal Knights                exp 2 armour 0 weapon_lvl 0
            unit        Armored Sergeants                exp 1 armour 1 weapon_lvl 0
            unit        Armored Sergeants                exp 0 armour 1 weapon_lvl 0
            unit        Urban Crossbow Militia                exp 2 armour 2 weapon_lvl 0
            unit        Urban Crossbow Militia                exp 2 armour 2 weapon_lvl 0
            unit        Urban Crossbow Militia                exp 2 armour 2 weapon_lvl 0
            unit        Urban Crossbow Militia                exp 1 armour 2 weapon_lvl 0
            unit        Feudal Knights                exp 2 armour 0 weapon_lvl 0
            unit        Feudal Knights                exp 2 armour 0 weapon_lvl 0
            unit        Dismounted Feudal Knights                exp 2 armour 0 weapon_lvl 0
        end
    
        add_money milan 18000
    end_if
    Yep, no monitor

  7. #47

    Default Re: Campaign Script Optimizations

    A, just for few seconds
    I have something in mind in where the wtf part might work; I 'll check now


    EDIT: Finally, I made it!
    Add in your CS this:
    Code:
    console_command control egypt
    console_command control byzantium
    
    monitor_event FactionTurnStart FactionIsLocal
        and IsFactionAIControlled
        and I_TurnNumber = 0
        and I_LocalFaction byzantium
    
    log wtf
    
    end_monitor
    and then start a hotseat campaign with Fatimids and Byzantium under your control.
    Quit in turn 2 and then check your log output
    Last edited by gsthoed; July 25, 2014 at 03:27 PM. Reason: SUCCESS

  8. #48

    Default Re: Campaign Script Optimizations

    About Genoese Reinforcement and Seljuk Reinforcement and the cash bonus: It seems like it is the support cost of that spawned army (until they get killed outside Constantinople's walls? ). I cannot answer if this cash bonus is necessary, as I don't know if this command works with that syntax; I think it would be ok with the comma if it was a console_command, but now?

    One note, though, that might be useful: I see in my SS 6.1 installation (with BtR submod) that the equivalent script was this:

    Code:
    ;--------------GENOESE REINFORCEMENTS AT CAFFA----------------;
    
        monitor_event FactionTurnStart FactionIsLocal
            ;and IsFactionAIControlled
            and I_TurnNumber = 0
            and I_LocalFaction byzantium
    
            spawn_army 
                faction milan
                character    Francesco, general, age 28, x 329, y 170
            unit        Armored Sergeants                exp 1 armour 0 weapon_lvl 0
            unit        Armored Sergeants                exp 0 armour 0 weapon_lvl 0
            unit        Genoese Crossbowmen                exp 2 armour 0 weapon_lvl 0
            unit        Genoese Crossbowmen                exp 2 armour 0 weapon_lvl 0
            unit        Genoese Crossbowmen                exp 2 armour 0 weapon_lvl 0
            unit        Genoese Crossbowmen                exp 1 armour 0 weapon_lvl 0
            unit        Feudal Knights                exp 2 armour 0 weapon_lvl 0
            unit    Italian MAA                exp 2 armour 0 weapon_lvl 0
            unit    Italian MAA                exp 2 armour 0 weapon_lvl 0
            unit    Famiglia Ducale                exp 2 armour 0 weapon_lvl 0
          end
          add_money milan 10000 ; gsthoed note: without comma 
          terminate_monitor
            
        end_monitor
    The bonus
    Also, the faction's economic system was not so advanced and, if I remember well, Byzantines in late era were not starting at war with the Turks (so Caffa was an interesting target for a human player controlling Byzantines in early turns).

    My opinion on the subject? Genoa starts with 8000 denarii and Turks with 16000. Those bonuses in v6.4 just seem too high. Maybe a bonus of 8000 or no bonus (similar to the bonus AI factions receive from the other spawned armies in the "AI reinforcements" section) should be more proper.
    Last edited by gsthoed; July 24, 2014 at 04:44 PM. Reason: To write something more useful

  9. #49

    Default Re: Campaign Script Optimizations

    Here is a reworked script of "Interactive Events". It is based on the discussion in posts #31-#33. Furthermore, I added the feature described in Withwnar's tutorial "Reload-safe Yes/No Events" in
    http://www.twcenter.net/forums/showt...=Game+Reloaded for all these events, except Pirates.
    Note, in early campaign the monitor about council_of_clermont was removed, as council_of_clermont is no longer an event.

    In the EDCT file, replace from:
    ;============== Interactive Events ======================
    to:
    ;-------- AI Bad Traits Remove ------------
    with this:
    Spoiler Alert, click show to read: 
    Code:
    ;============== Interactive Events ======================
    ;------------ Trade_Fairs ------------------
    Trigger great_fair_accepted
     WhenToTest CharacterTurnEnd
    
     Condition I_EventCounter great_fair_answer = 1
           and DistanceCapital <= 50
    
     Affects GoodTrader 12 Chance 50
     Affects GoodMerchant 1 Chance 50
    
    ;------------------------------------------
    Trigger great_fair_refused
     WhenToTest CharacterTurnEnd
    
     Condition I_EventCounter great_fair_answer = 2
           and DistanceCapital <= 50
    
     Affects BadTrader 1 Chance 75
     Affects ServesSelfMerchant 1 Chance 75
    
    ;------------ Tourneys ------------------
    Trigger great_tourney_accepted_leader
     WhenToTest CharacterTurnEnd
    
     Condition I_EventCounter great_tourney_answer = 1
           and IsFactionLeader
    
     Affects StrategyChivalry 1 Chance 50
     Affects Energetic 1 Chance 50
    
    ;---------------------------------------
    Trigger great_tourney_accepted_general
     WhenToTest CharacterTurnEnd
    
     Condition I_EventCounter great_tourney_answer = 1
           and IsGeneral
           and not IsFactionLeader
           and DistanceCapital <= 50
    
     Affects HaleAndHearty 3 Chance 50
     Affects ContentGeneral 1 Chance 100
     Affects Energetic 1 Chance 50
    
    ;------------------------------------------
    Trigger great_tourney_accepted_princess
     WhenToTest CharacterTurnEnd
    
     Condition I_EventCounter great_tourney_answer = 1
           and AgentType = princess
           and DistanceCapital <= 50
    
     Affects FairWoman 1 Chance 50
    
    ;------------------------------------------
    Trigger great_tourney_refused_leader
     WhenToTest CharacterTurnEnd
    
     Condition I_EventCounter great_tourney_answer = 2
           and IsFactionLeader
    
     Affects Slothful 1 Chance 50
    
    ;------------------------------------------
    Trigger great_tourney_refused_general
     WhenToTest CharacterTurnEnd
    
     Condition I_EventCounter great_tourney_answer = 2
           and IsGeneral
           and not IsFactionLeader
           and Attribute Chivalry > 3
    
     Affects DiscontentGeneral 1 Chance 50
    
    ;------------ Great Councils ------------------
    Trigger great_council_accepted_leader
     WhenToTest CharacterTurnEnd
    
     Condition I_EventCounter great_council_answer = 1
           and IsFactionLeader
    
     Affects ReligiousActivity 1 Chance 50
    
    ;------------------------------------------
    Trigger great_council_accepted_priest
     WhenToTest CharacterTurnEnd
    
     Condition I_EventCounter great_council_answer = 1
           and AgentType = priest
           and DistanceCapital <= 60
    
     Affects Dogmatic 1 Chance 100
     Affects StrongFaith 1 Chance 25
    
    ;------------ Troubadours ------------------
    Trigger troubadours_accepted_leader
     WhenToTest CharacterTurnEnd
    
     Condition I_EventCounter troubadours_event_answer = 1
           and IsFactionLeader
    
     Affects StrategyChivalry 1 Chance 50
     Affects Poet 1 Chance 25
     Affects Cultured 1 Chance 25
    
    ;------------------------------------------
    Trigger troubadours_accepted_princess
     WhenToTest CharacterTurnEnd
    
     Condition I_EventCounter troubadours_event_answer = 1
           and AgentType = princess
           and DistanceCapital <= 50
    
     Affects FairWoman 1 Chance 50
     Affects FaithfulWoman 1 Chance 50
    
    ;------------------------------------------
    Trigger troubadours_refused_leader
     WhenToTest CharacterTurnEnd
    
     Condition I_EventCounter troubadours_event_answer = 2
           and IsFactionLeader
    
     Affects StrategyDread 1 Chance 50
     Affects Miserly 1 Chance 50
    
    ;------------------------------------------
    Trigger troubadours_refused_princess
     WhenToTest CharacterTurnEnd
    
     Condition I_EventCounter troubadours_event_answer = 2
           and AgentType = princess
           and DistanceCapital <= 50
    
     Affects VapidWoman 1 Chance 50
     Affects BadPrincess 1 Chance 50
    
    ;-------- AI Bad Traits Remove ------------


    Campaign_script for early_campaign:
    Spoiler Alert, click show to read: 
    Code:
    ;================= Interactive Events ===================
    ;--- Reset counters
    
    monitor_event FactionTurnEnd FactionIsLocal
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        set_event_counter great_fair_answer 0
        set_event_counter great_tourney_answer 0
        set_event_counter troubadours_event_answer 0
        set_event_counter great_council_answer 0
    
    end_monitor
    
    ;------- Reload-safe Yes/No Events -------
    if not I_HotseatEnabled
        declare_counter awaiting_answer_great_fair ;0 = false, 1 = true
        declare_counter awaiting_answer_great_tourney
        declare_counter awaiting_answer_troubadours
        declare_counter awaiting_answer_great_council
    end_if
    
    monitor_event GameReloaded TrueCondition
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        if I_CompareCounter awaiting_answer_great_fair = 1
            campaign_wait 0.1
            historic_event great_fair true
        end_if
        if I_CompareCounter awaiting_answer_great_tourney = 1
            campaign_wait 0.1
            historic_event great_tourney true
        end_if
        if I_CompareCounter awaiting_answer_troubadours = 1
            campaign_wait 0.1
            historic_event troubadours_event true
        end_if
        if I_CompareCounter awaiting_answer_great_council = 1
            campaign_wait 0.1
            historic_event great_council true
        end_if
    
    end_monitor
    
    ;------------- Great Trade Fair -----------
    monitor_event FactionTurnStart FactionIsLocal
        and FactionBuildingExists > fairground
        and RandomPercent < 10
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        set_counter awaiting_answer_great_fair 1
        historic_event great_fair true
    
    end_monitor
    
    ; answered "yes"
    monitor_event EventCounter EventCounterType great_fair_accepted
        and EventCounter = 1
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        console_command add_money -2500
        set_counter awaiting_answer_great_fair 0
        set_event_counter great_fair_answer 1
        set_event_counter great_fair_accepted 0
    
    end_monitor
    
    ; answered "no"
    monitor_event EventCounter EventCounterType great_fair_declined
        and EventCounter = 1
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        set_counter awaiting_answer_great_fair 0
        set_event_counter great_fair_answer 2
        set_event_counter great_fair_declined 0
    
    end_monitor 
    
    
    ;------------- Great Tourney --------------
    monitor_event FactionTurnStart FactionIsLocal
        and FactionBuildingExists > jousting_lists
        and RandomPercent < 10
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        historic_event great_tourney true
        set_counter awaiting_answer_great_tourney 1
    
    end_monitor
    
    ; answered "yes"
    monitor_event EventCounter EventCounterType great_tourney_accepted
        and EventCounter = 1
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        console_command add_money -2500
        set_counter awaiting_answer_great_tourney 0
        set_event_counter great_tourney_answer 1
        set_event_counter great_tourney_accepted 0
    
    end_monitor
    
    ; answered "no"
    monitor_event EventCounter EventCounterType great_tourney_declined
        and EventCounter = 1
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        set_counter awaiting_answer_great_tourney 0
        set_event_counter great_tourney_answer 2
        set_event_counter great_tourney_declined 0
    
    end_monitor 
    
    
    ;-------------- Troubadours ---------------
    monitor_event FactionTurnStart FactionIsLocal
        and RandomPercent < 5
        and FactionBuildingExists > town_hall
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        if I_TurnNumber > 10
            historic_event troubadours_event true
            set_counter awaiting_answer_troubadours 1
        end_if
    
    end_monitor
    
    ; answered "yes"
    monitor_event EventCounter EventCounterType troubadours_event_accepted
        and EventCounter = 1
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        console_command add_money -1000
        set_event_counter troubadours_event_answer 1
        set_event_counter troubadours_event_accepted 0
        set_counter awaiting_answer_troubadours 0
    
    end_monitor
    
    ; answered "no"
    monitor_event EventCounter EventCounterType troubadours_event_declined
        and EventCounter = 1
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        set_counter awaiting_answer_troubadours 0
        set_event_counter troubadours_event_answer 2
        set_event_counter troubadours_event_declined 0
    
    end_monitor
    
    
    ;------------- Great Councils -------------
    declare_counter had_council
    declare_counter gc_finished
    
    monitor_event EventCounter EventCounterType lateran_council1
        and EventCounter > 0
        set_counter had_council 1
    terminate_monitor
    end_monitor
    
    monitor_event EventCounter EventCounterType lateran_council2
        and EventCounter > 0
        set_counter had_council 1
    terminate_monitor
    end_monitor
    
    monitor_event EventCounter EventCounterType lateran_council3
        and EventCounter > 0
        set_counter had_council 1
    terminate_monitor
    end_monitor
    
    monitor_event EventCounter EventCounterType lateran_council4
        and EventCounter > 0
        set_counter had_council 1
    terminate_monitor
    end_monitor
    
    monitor_event FactionTurnStart FactionIsLocal
        and I_CompareCounter had_council = 1
        and not Religion islam
        and not Religion pagan
    
        ;if I_HotseatEnabled or one turn after lateran_council4
        if I_CompareCounter gc_finished > 0
            set_event_counter great_council_accepted 1
            set_counter gc_finished 2
            terminate_monitor
        end_if
    
        historic_event great_council true
        set_counter awaiting_answer_great_council 1
        set_counter had_council 0
    
        if I_EventCounter lateran_council4 = 1
            set_counter had_council 1
            set_counter gc_finished 1
        end_if
    
    end_monitor
    
    ; answered "yes"
    monitor_event EventCounter EventCounterType great_council_accepted
        and EventCounter = 1
    
        ;if I_HotseatEnabled or one turn after lateran_council4
        if I_CompareCounter gc_finished = 2
            terminate_monitor
        end_if
    
        console_command add_money -1500
    
        set_counter awaiting_answer_great_council 0
        set_event_counter great_council_answer 1
        set_event_counter great_council_accepted 0
    
    end_monitor
    
    ; answered "no" -- nothing to do
    
    
    ;--------------- Pirates -----------------
    monitor_event FactionTurnStart FactionIsLocal
        and Treasury > 75000
        and FactionBuildingExists >= port
        and RandomPercent < 10
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        historic_event pirates true
    
    end_monitor
    
    monitor_event EventCounter EventCounterType pirates_accepted
        and EventCounter = 1
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        console_command add_money -5000
        set_event_counter pirates_accepted 0
    
    end_monitor
    
    monitor_event EventCounter EventCounterType pirates_declined
        and EventCounter = 1
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        if RandomPercent < 51
            console_command add_money -12000
        end_if
    
        set_event_counter pirates_declined 0
    end_monitor
    
    
    ;---No Interactive Events if I_HotseatEnabled
    if I_HotseatEnabled
        ;-- terminate great trade fairs --
        set_event_counter great_fair_accepted 1
        set_event_counter great_fair_declined 1
    
        ; -- terminate great tourney --
        set_event_counter great_tourney_accepted 1
        set_event_counter great_tourney_declined 1
    
        ; -- terminate great tourney --
        set_event_counter troubadours_event_accepted 1
        set_event_counter troubadours_event_declined 1
    
        ; -- terminate great councils --
        set_counter had_council 1
        set_counter gc_finished 2
        set_event_counter great_council_accepted 1
    
        ; -- terminate pirates --
        set_event_counter pirates_accepted 1
        set_event_counter pirates_declined 1
        ; -- end of terminate pirates --
    end_if
    
    ;========================================================
    ;======= EMERGENT FACTIONS/NATIONAL UPRISINGS ===========


    Campaign_script for late_campaign:
    Spoiler Alert, click show to read: 
    Code:
    ;================= Interactive Events ===================
    ;--- Reset counters
    
    monitor_event FactionTurnEnd FactionIsLocal
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        set_event_counter great_fair_answer 0
        set_event_counter great_tourney_answer 0
        set_event_counter troubadours_event_answer 0
        set_event_counter great_council_answer 0
    
    end_monitor
    
    ;------- Reload-safe Yes/No Events -------
    if not I_HotseatEnabled
        declare_counter awaiting_answer_great_fair ;0 = false, 1 = true
        declare_counter awaiting_answer_great_tourney
        declare_counter awaiting_answer_troubadours
        declare_counter awaiting_answer_great_council
    end_if
    
    monitor_event GameReloaded TrueCondition
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        if I_CompareCounter awaiting_answer_great_fair = 1
            campaign_wait 0.1
            historic_event great_fair true
        end_if
        if I_CompareCounter awaiting_answer_great_tourney = 1
            campaign_wait 0.1
            historic_event great_tourney true
        end_if
        if I_CompareCounter awaiting_answer_troubadours = 1
            campaign_wait 0.1
            historic_event troubadours_event true
        end_if
        if I_CompareCounter awaiting_answer_great_council = 1
            campaign_wait 0.1
            historic_event great_council true
        end_if
    
    end_monitor
    
    ;------------- Great Trade Fair -----------
    monitor_event FactionTurnStart FactionIsLocal
        and FactionBuildingExists > fairground
        and RandomPercent < 10
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        set_counter awaiting_answer_great_fair 1
        historic_event great_fair true
    
    end_monitor
    
    ; answered "yes"
    monitor_event EventCounter EventCounterType great_fair_accepted
        and EventCounter = 1
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        console_command add_money -2500
        set_counter awaiting_answer_great_fair 0
        set_event_counter great_fair_answer 1
        set_event_counter great_fair_accepted 0
    
    end_monitor
    
    ; answered "no"
    monitor_event EventCounter EventCounterType great_fair_declined
        and EventCounter = 1
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        set_counter awaiting_answer_great_fair 0
        set_event_counter great_fair_answer 2
        set_event_counter great_fair_declined 0
    
    end_monitor 
    
    
    ;------------- Great Tourney --------------
    monitor_event FactionTurnStart FactionIsLocal
        and FactionBuildingExists > jousting_lists
        and RandomPercent < 10
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        historic_event great_tourney true
        set_counter awaiting_answer_great_tourney 1
    
    end_monitor
    
    ; answered "yes"
    monitor_event EventCounter EventCounterType great_tourney_accepted
        and EventCounter = 1
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        console_command add_money -2500
        set_counter awaiting_answer_great_tourney 0
        set_event_counter great_tourney_answer 1
        set_event_counter great_tourney_accepted 0
    
    end_monitor
    
    ; answered "no"
    monitor_event EventCounter EventCounterType great_tourney_declined
        and EventCounter = 1
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        set_counter awaiting_answer_great_tourney 0
        set_event_counter great_tourney_answer 2
        set_event_counter great_tourney_declined 0
    
    end_monitor 
    
    
    ;-------------- Troubadours ---------------
    monitor_event FactionTurnStart FactionIsLocal
        and RandomPercent < 5
        and FactionBuildingExists > town_hall
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        if I_TurnNumber > 10
            historic_event troubadours_event true
            set_counter awaiting_answer_troubadours 1
        end_if
    
    end_monitor
    
    ; answered "yes"
    monitor_event EventCounter EventCounterType troubadours_event_accepted
        and EventCounter = 1
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        console_command add_money -1000
        set_event_counter troubadours_event_answer 1
        set_event_counter troubadours_event_accepted 0
        set_counter awaiting_answer_troubadours 0
    
    end_monitor
    
    ; answered "no"
    monitor_event EventCounter EventCounterType troubadours_event_declined
        and EventCounter = 1
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        set_counter awaiting_answer_troubadours 0
        set_event_counter troubadours_event_answer 2
        set_event_counter troubadours_event_declined 0
    
    end_monitor
    
    
    ;------------- Great Councils -------------
    monitor_event FactionTurnStart FactionIsLocal
        and I_EventCounter lateran_council4 > 0
        and not Religion islam
        and not Religion pagan
    
        if not I_HotseatEnabled
            historic_event great_council true
            set_counter awaiting_answer_great_council 1
        end_if
    
    terminate_monitor
    end_monitor
    
    ; answered "yes"
    monitor_event EventCounter EventCounterType great_council_accepted
        and EventCounter = 1
    
        if not I_HotseatEnabled
            console_command add_money -1500
            set_counter awaiting_answer_great_council 0
            set_event_counter great_council_answer 1
            set_event_counter great_council_accepted 0
        end_if
    
    terminate_monitor
    end_monitor
    
    ; answered "no" -- nothing to do
    
    
    ;--------------- Pirates -----------------
    monitor_event FactionTurnStart FactionIsLocal
        and Treasury > 75000
        and FactionBuildingExists >= port
        and RandomPercent < 10
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        historic_event pirates true
    
    end_monitor
    
    monitor_event EventCounter EventCounterType pirates_accepted
        and EventCounter = 1
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        console_command add_money -5000
        set_event_counter pirates_accepted 0
    
    end_monitor
    
    monitor_event EventCounter EventCounterType pirates_declined
        and EventCounter = 1
    
        if I_HotseatEnabled
            terminate_monitor
        end_if
    
        if RandomPercent < 51
            console_command add_money -12000
        end_if
    
        set_event_counter pirates_declined 0
    end_monitor
    
    
    ;---No Interactive Events if I_HotseatEnabled
    if I_HotseatEnabled
        ;-- terminate great trade fairs --
        set_event_counter great_fair_accepted 1
        set_event_counter great_fair_declined 1
    
        ; -- terminate great tourney --
        set_event_counter great_tourney_accepted 1
        set_event_counter great_tourney_declined 1
    
        ; -- terminate great tourney --
        set_event_counter troubadours_event_accepted 1
        set_event_counter troubadours_event_declined 1
    
        ; -- terminate great councils --
        set_counter had_council 1
        set_event_counter great_council_accepted 1
    
        ; -- terminate pirates --
        set_event_counter pirates_accepted 1
        set_event_counter pirates_declined 1
        ; -- end of terminate pirates --
    end_if
    
    ;========================================================
    ;======= EMERGENT FACTIONS/NATIONAL UPRISINGS ===========

  10. #50

    Default Re: Campaign Script Optimizations

    About "AI Reinforcement" section: I am thinking of combine the whole section (without the "No Heir Reinforcement") with "Great People Ancillaries" and "Merchant&Priest&Ship Support Spawn".
    I have prepared a script, which I need to test.

    Now, about the "No Heir Reinforcement": In "Bug Fixes for SS6.4" thread, posts #48 and #50, there is a general fix for a bug. There are two alternatives too:
    a) We can use "status_venice" event_counters (post #8 of current thread) instead of the "I_FactionLeaderAttribute venice Command < 1000" conditions.

    b) In post #42 of current thread, I present a faction's economy script. In what I describe as "Step 2", there are some versatile monitors in which we can do the spawning of "heirs" during their faction's turns. I 'll give an example for venice:

    In "No Heir Reinforcement", we have this:
    Spoiler Alert, click show to read: 
    Code:
    monitor_event FactionTurnStart FactionType slave
    
        if I_IsFactionAIControlled venice
        and I_NumberOfHeirs venice < 4
        and I_CompareCounter heir_venice < 3
        and I_FactionLeaderAttribute venice Command < 1000
            spawn_army
                faction venice
                character    random_name, named character, age 20, x 161, y 173, family
                traits MilitaryInclination 2 , Military_Edu 2 , NaturalMilitarySkill 2 , GoodCommander 1 , Loyal 2 , ReligionStarter 1
                unit    SE Bodyguard        exp 2 armour 0 weapon_lvl 0
            end
            inc_counter heir_venice 1
        end_if
    
    end_monitor

    That is, we spawn a venetian family member in slave_faction's turn if certain conditions are true.

    In "Step 2" of the economy script, we have a monitor for AI-controlled venice:
    Code:
    ; it's venice 's turn
    monitor_event PreFactionTurnStart FactionType venice
        and IsFactionAIControlled
    
        set_counter ai_ec_id 2
    end_monitor
    If we say we 'll do the checks and the spawning during venice's turn instead of slave_faction's turn, then we could have:
    Spoiler Alert, click show to read: 
    Code:
    ; it's venice 's turn
    monitor_event PreFactionTurnStart FactionType venice
        and IsFactionAIControlled
    
        set_counter ai_ec_id 2
    
        if I_NumberOfHeirs venice < 4
        and I_CompareCounter heir_venice < 3
     ;    and I_FactionLeaderAttribute venice Command < 1000 ; obsolete, because if venice was dead (or not emerged), then it could not PreFactionTurnStart
            spawn_army
                faction venice
                character    random_name, named character, age 20, x 161, y 173, family
                traits MilitaryInclination 2 , Military_Edu 2 , NaturalMilitarySkill 2 , GoodCommander 1 , Loyal 2 , ReligionStarter 1
                unit    SE Bodyguard        exp 2 armour 0 weapon_lvl 0
            end
            inc_counter heir_venice 1
        end_if
    
    end_monitor


    If applied for every faction with family_tree, we avoid the "No Heir Reinforcement" monitor and we have less conditions to be checked per turn. Also, if "venice" is a destroyed or a not-emerged faction, we avoid running the "NoHeir" part altogether. This approach has the drawback that removing the "No Heir Reinforcement" feature is more difficult.

    EDIT
    About "alternative (b)": There might be a conflict with adopted generals etc that come to life in each faction's turn.
    Last edited by gsthoed; July 25, 2014 at 10:46 AM.

  11. #51

    Default Re: Campaign Script Optimizations

    I like this, i say go for it, the SMM can still manage it, as long as you put some commented out indicators in every "No Heir" part it can be done

    My opinion on the subject? Genoa starts with 8000 denarii and Turks with 16000. Those bonuses in v6.4 just seem too high. Maybe a bonus of 8000 or no bonus (similar to the bonus AI factions receive from the other spawned armies in the "AI reinforcements" section) should be more proper.
    i agree the cash bonus is excessive, also they have the economy script, so 8000 should do.

  12. #52

    Default Re: Campaign Script Optimizations

    Faction's Economy Script in Post #42 has been updated. There was an error which is now fixed. Those that have downloaded previous version are asked to apply the fix manually or download the newer version.
    Fix is not save-game compatible.

    In post #50, about "alternative (b)": There might be a conflict with adopted generals etc that come to life in each faction's turn.

  13. #53

    Default Re: Campaign Script Optimizations

    gsthoed, I have tried implementing your "optimized" economy script through being a submod, but I think it is incompatible with BGR IV-E. I don't know if it is also not compatible with BGR II since I haven't played with it yet. I really, really like to have your economy script because it really improves turn times a lot.

    Can you please make necessary adjustments so that it will be compatible with BGR IV-E?

  14. #54

    Default Re: Campaign Script Optimizations

    I have completed testing a script that combines "AI Reinforcement" with "Great People Ancillaries" and "Merchant&Priest&Ship Support Spawn".
    But it is the "Constantinople JIHAD garrison script" for which I have a dilemma.
    There is this for the early campaign.
    Code:
    monitor_event SettlementTurnStart SettlementName Constantinople
        and not FactionIsLocal
        and I_SettlementUnderSiege Constantinople
        and IsJihadTarget Constantinople
        and I_SettlementOwner Constantinople = byzantium
    
        create_unit Constantinople, Contaratoi, num 3, exp 0, arm 0, wep 0
        create_unit Constantinople, Toxotae, num 2, exp 0, arm 1, wep 0
        create_unit Constantinople, Toxotae, num 2, exp 0, arm 1, wep 0
    end_monitor
    The "create_unit" command has a somehow peculiar function.
    Since this monitor didn't contain a terminate_monitor, I tend to believe that the goal of the script was the continuous reinforcement of Constantinople's garrison if under siege by jihadists; if this is the case, then the "console_command create_unit" should be used. If the goal was to reinforce this garrison up until its garrison reached 20 units end then stop, then I 'm thinking of using the non console version of "create_unit" and terminate this monitor at the end of the jihad. So, what do you think?

  15. #55

    Default Re: Campaign Script Optimizations

    gsthoed, thank you for still making improvements to the game!

    But, can you please make your "optimized" economy script compatible with BGR IV-E? I think it's incompatible because if I use it along with BGR IV-E, BGR IV-E's ability to have popups, like enabling Scutage Tax, is gone. I really, really like to use your economy script because it really improves turn times by a lot.

    I don't know why your script destroys some elements of BGR. I tried looking at the submod files of BGR IV-E, but I didn't see any changes to the economy script. Maybe, BGR is referencing some codes in the economy script. That's why enabling yours generates errors.

  16. #56

    Default Re: Campaign Script Optimizations

    but terminate_monitor wouldnt prevent the monitor to fire again when another jihad is launched upon the same settlement many turns after?
    also how will you count the garrison size?

  17. #57

    Default Re: Campaign Script Optimizations

    Quote Originally Posted by Melooo182 View Post
    but terminate_monitor wouldnt prevent the monitor to fire again when another jihad is launched upon the same settlement many turns after?
    also how will you count the garrison size?
    You are right. I had to be more analytic and more careful

    Before noticing Withwnar's post, I had prepared this script (for late era):
    Spoiler Alert, click show to read: 
    Code:
    ;---- Constantinople JIHAD garrison script
    monitor_event SettlementTurnStart IsJihadTarget
        and SettlementName Constantinople
    
        if I_LocalFaction byzantium
        and not I_HotseatEnabled
            terminate_monitor
        end_if
    
        if I_SettlementUnderSiege Constantinople
        and I_SettlementOwner Constantinople = byzantium
        and I_IsFactionAIControlled byzantium
            create_unit Constantinople, Contaratoi, num 5, exp 0, arm 0, wep 0
            create_unit Constantinople, Toxotae, num 8, exp 0, arm 1, wep 0
        end_if
    end_monitor


    Note that if Constantinople is under siege by jihadists for 2 sequential or almost sequential turns (which is quite possible), this monitor will give all that is has to give and then will run useless. So I came to consider these options:

    a)The "console" version simply does this: As long as the conditions are true and there are free unit slots, it spawns garrison reinforcements. Actually, this was my impression of the "create_units" function, until proved wrong both by Withwnar's post and the results of relevant tests of my own.

    If we want the repletion of the garrison slots take place once at most, the non-console command is to be preferred. But the drawback that after this event no more garrison reinforcements can be spawned -even if in the future there are available one or more free slots- is a significant one; it makes this monitor useless. Therefore, I believe the "non console" version should be used only in these cases:
    b) Byzantine Constantinople starts a turn under siege by jihadists. All the "spawning" is done at once:
    Code:
    create_unit Constantinople, Contaratoi, num 8, exp 0, arm 0, wep 0
    create_unit Constantinople, Toxotae, num 12, exp 0, arm 1, wep 0
    After the first time these commands have been executed, no additional units can be created by this monitor, therefore it can be safely terminated.

    c) We use the "nums" as there are in CSs. We provide the ability for the first Jihad. My personal estimate is that "create_units" commands will reach their "expiration date" during that period and after that the monitor will run useless; it will check at every SttlementTurnStart if SettlementName is Constantinople (or better if IsJihadTarget) without anything to do; thus, we terminate this monitor so as to not run uselessly.

    My personal preference? I believe that giving Constantinople ballistra or cannons towers if they don't have it already, along with 2 militia spearmen and 3 archers for one time, is something that the AI can handle better as a defender and it is more "fair" for the attackers (the jihadists, especially the AIControlled ones). Whar I would do if I had to vote for a, b or c? I 'd ask someone else

  18. #58

    Default Re: Campaign Script Optimizations

    hehe i had a bit of hard time understanding your post, but i think i got it

    what about something like this?
    Code:
    ;---- Constantinople JIHAD garrison script
    declare_counter XXX
    monitor_event SettlementTurnStart IsJihadTarget
    	and SettlementName Constantinople
    	and I_SettlementOwner Constantinople = byzantium
    
    	if I_LocalFaction byzantium
    	and not I_HotseatEnabled
    		terminate_monitor
    	end_if
    	if not I_SettlementUnderSiege Constantinople
    	and I_CompareCounter XXX = 1
    		set_counter XXX 0
    	end_if
    	if I_IsFactionAIControlled byzantium
    	and I_SettlementUnderSiege Constantinople
    	and I_CompareCounter XXX = 0
    		console_command create_unit Constantinople, Contaratoi, num 5, exp 0, arm 0, wep 0
    		console_command create_unit Constantinople, Toxotae, num 8, exp 0, arm 1, wep 0
    		set_counter XXX 1
    	end_if
    end_monitor

  19. #59

    Default Re: Campaign Script Optimizations

    Quote Originally Posted by Melooo182 View Post
    hehe i had a bit of hard time understanding your post, but i think i got it
    Me too . But I couldn't write it better without exhausting myself
    Quote Originally Posted by Melooo182 View Post
    what about something like this?
    Spoiler Alert, click show to read: 
    Code:
    ;---- Constantinople JIHAD garrison script
    declare_counter XXX
    monitor_event SettlementTurnStart IsJihadTarget
        and SettlementName Constantinople
        and I_SettlementOwner Constantinople = byzantium
    
        if I_LocalFaction byzantium
        and not I_HotseatEnabled
            terminate_monitor
        end_if
        if not I_SettlementUnderSiege Constantinople
        and I_CompareCounter XXX = 1
            set_counter XXX 0
        end_if
        if I_IsFactionAIControlled byzantium
        and I_SettlementUnderSiege Constantinople
        and I_CompareCounter XXX = 0
            console_command create_unit Constantinople, Contaratoi, num 5, exp 0, arm 0, wep 0
            console_command create_unit Constantinople, Toxotae, num 8, exp 0, arm 1, wep 0
            set_counter XXX 1
        end_if
    end_monitor
    hehe, giving the reinforcement once per siege was actually my first thought on this script; I didn't suggest it as it is surely a modification of the initial script. The only "bad" thing with this option is this:
    Turn 0: 1st jihadist army starts sieging Constantinople.
    Turn 1: Reinforcement garrison is spawned during byzantine turn. In 1st jihadist army's faction's turn, this army attacks Constantinople and loses. Jihadist army 2 start new siege.
    Turn 2: No garrison reinforcements for Constantinople.

    I see this scenario quite often in crusade targets. However, I don't consider this function of the garrisson script as "unfair". So, how about I start testing this script?
    Spoiler Alert, click show to read: 
    Code:
    ;---- Constantinople JIHAD garrison script
    declare_counter XXX
    monitor_event SettlementTurnStart IsJihadTarget
        and SettlementName Constantinople
    
        if I_LocalFaction byzantium
        and not I_HotseatEnabled
            terminate_monitor
        end_if
    
     if I_IsFactionAIControlled byzantium
     and I_SettlementOwner Constantinople = byzantium
    
        if not I_SettlementUnderSiege Constantinople
            set_counter XXX 0
        end_if
        if I_SettlementUnderSiege Constantinople
        and I_CompareCounter XXX = 0
             console_command create_unit Constantinople "Contaratoi" 5 0 0 0
             console_command create_unit Constantinople "Toxotae" 8 0 1 0
            set_counter XXX 1
        end_if
     end_if
    end_monitor


    EDIT: Since you have more experience than me in this: How about using the "SiegeEquipmentCompleted" event instead of "SettlementTurnStart"?
    Last edited by gsthoed; July 31, 2014 at 02:26 PM.

  20. #60

    Default Re: Campaign Script Optimizations

    the problem about SiegeEquimentCompleted would be that if by chance a jihad army has an artillery/siege unit already they can assault the walls immediately and there wont be time for a garrison to spawn...well this already happened with SettlementTurnStart xD...but if a player controlled jihad army for X reason didnt build siege equipment but rather got reinforced with cannons...the garrison would have spawn in byzantine's turn.

    Well you said in the previous post that by using "console_command create_unit" once the settlement has its garrison full the command will be ignored, right?
    we can simply forget about the counter XXX thing then...its not like it will be robbing much processing power anyway.

    Also why removing and I_SettlementOwner Constantinople = byzantium from the monitor conditions? since this monitor is exclusively for byzantine controlled constantinople...why let it run if another factions holds it?

Page 3 of 5 FirstFirst 12345 LastLast

Posting Permissions

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