Results 1 to 7 of 7

Thread: Is it possible to use an "or"/"else if" operator?

  1. #1

    Default Is it possible to use an "or"/"else if" operator?

    Like so-

    Code:
    if SettlementBuildingExists = tradeRoute_Adriatic
    	or if SettlementBuildingExists tradeNexus_Adriatic
    				
    	set_event_counter tradeReCalc_Adriatic 1
    end_if
    If not, and assuming that "else if" or "else_if" doesn't work, then I assume that this is the method:

    Code:
    if SettlementBuildingExists = tradeRoute_Adriatic
    	set_event_counter tradeReCalc_Adriatic 1
    end_if
    
    if SettlementBuildingExists = tradeNexus_Adriatic
    	set_event_counter tradeReCalc_Adriatic 1
    end_if

  2. #2

    Default Re: Is it possible to use an "or"/"else if" operator?

    The only logic operator that works in campaign_script is and. There is no or, there is no elseif. Your approach using counters is, in principle, the correct way to effectively reproduce the behavior of or. However, the SettlementBuildingExists condition is an event condition - it will not work with if. Generally, the only conditions that work with if begin with I_ (a notable exception being the condition RandomPercent). To address this, you would need to use multiple monitors as in:

    Spoiler Alert, click show to read: 

    Code:
    set_event_counter tradeReCalc_Adriatic 0
    
    monitor_event SettlementTurnStart SettlementBuildingExists tradeRoute_Adriatic
     set_event_counter tradeReCalc_Adriatic 1
    end_monitor
    monitor_event SettlementTurnStart SettlementBuildingExists tradeNexus_Adriatic
     set_event_counter tradeReCalc_Adriatic 1
    end_monitor
    I don't believe the = after the SettlementBuildingExists condition is necessary, but it's been a long time since I tested this.


    This is a very simple example, not necessarily what you're trying to do, but at least the syntax is correct.

  3. #3

    Default Re: Is it possible to use an "or"/"else if" operator?

    My intention is to monitor if and when trade route settlements change hands- if a trade route is "unified" either by all Route provinces OR all Nexus provinces owned by a single faction, then all associated buildings (regardless of owner) get a benefit. Note that these are preset/prebuilt with Hinterland buildings (controlled by hidden resources) at game start; so I may not need to evaluate the buildings.....

    Now that I think about it, would it be more efficient scriptwise to simply just re-evaluate all the trade node at the end of the Rebels' turn? I've heard that monitors are the most computationally expensive...

    This is how I have it now. I suppose I could drop the "ReCalc" and just have this evaluate at the end of "slave" turn?

    Spoiler Alert, click show to read: 

    Code:
    monitor_event EventCounter EventCounterType tradeReCalc_Adriatic
                and EventCounter == 1 
    
    
                    ;clear ReCalc
                    set_event_counter tradeReCalc_Adriatic 0
                    
                        ;check if there is now a Trade Hegemon
                        ;compare all trade route settlement owners to owner of triggering settlement
                        ;faction must either own all regular Trade Route provinces OR all Trade Nexus provinces
                        ;if all are owned by the same faction then we have a unified trade route
                        
                        if I_EventCounter tradeMax_Adriatic == 0
                        
                            
                            ;;trade routes
                            if I_SettlementOwner Campobasso = FROM
                                and if I_SettlementOwner Foggia = FROM
                                and if I_SettlementOwner Bari = FROM
                                and if I_SettlementOwner Otranto = FROM
                                and if I_SettlementOwner Ravenna = FROM
                                and if I_SettlementOwner Rimini = FROM
                                and if I_SettlementOwner Pola = FROM
                                and if I_SettlementOwner Trieste = FROM
                                and if I_SettlementOwner Fiume = FROM
                                and if I_SettlementOwner Zara = FROM
                                and if I_SettlementOwner Split = FROM
                                and if I_SettlementOwner Scutari = FROM
                                and if I_SettlementOwner Podgorica = FROM
                                
                                set_event_counter tradeMax_Adriatic 1
                            
                                ;fire event notifying factions that there is a new sheriff in town
                                
                                terminate_monitor
                            end_if
        
                            ;trade Nexuses (Nexi?)
                            if I_SettlementOwner Venice = FROM
                                and if I_SettlementOwner Ancona = FROM
                                and if I_SettlementOwner Ragusa = FROM
                                and if I_SettlementOwner Brindisi = FROM
                                and if I_SettlementOwner Taranto = FROM
                                and if I_SettlementOwner Durazzo = FROM
                                
                                set_event_counter tradeMax_Adriatic 1
                            
                                ;fire event notifying that there is a new sheriff in town
                                
                                terminate_monitor
                            end_if
                        end_if
                        
                        ;determine if trade hegemony has been broken
                        if I_EventCounter tradeMax_Adriatic == 1
                            
                            ;trade Route provinces
                            if not I_SettlementOwner Campobasso = FROM
                                set_event_counter tradeMax_Adriatic 0
                                
                                ;;fire event
                                
                                terminate_monitor
                            end_if
    
    
                            if not I_SettlementOwner Foggia = FROM
                                set_event_counter tradeMax_Adriatic 0
                                
                                ;;fire event
                                
                                terminate_monitor
                            end_if
    
    
                            if not I_SettlementOwner Bari = FROM
                                set_event_counter tradeMax_Adriatic 0
                                
                                ;;fire event
                                
                                terminate_monitor
                            end_if
    
    
                            if not I_SettlementOwner Otranto = FROM
                                set_event_counter tradeMax_Adriatic 0
                                
                                ;;fire event
                                
                                terminate_monitor
                            end_if
    
    
                            if not I_SettlementOwner Ravenna = FROM
                                set_event_counter tradeMax_Adriatic 0
                                
                                ;;fire event
                                
                                terminate_monitor
                            end_if
    
    
                            if not I_SettlementOwner Rimini = FROM
                                set_event_counter tradeMax_Adriatic 0
                                
                                ;;fire event
                                
                                terminate_monitor
                            end_if
    
    
                            if not I_SettlementOwner Pola = FROM
                                set_event_counter tradeMax_Adriatic 0
                                
                                ;;fire event
                                
                                terminate_monitor
                            end_if
    
    
                            if not I_SettlementOwner Trieste = FROM
                                set_event_counter tradeMax_Adriatic 0
                                
                                ;;fire event
                                
                                terminate_monitor
                            end_if
    
    
                            if not I_SettlementOwner Fiume = FROM
                                set_event_counter tradeMax_Adriatic 0
                                
                                ;;fire event
                                
                                terminate_monitor
                            end_if
    
    
                            if not I_SettlementOwner Zara = FROM
                                set_event_counter tradeMax_Adriatic 0
                                
                                ;;fire event
                                
                                terminate_monitor
                            end_if
    
    
                            if not I_SettlementOwner Split = FROM
                                set_event_counter tradeMax_Adriatic 0
                                
                                ;;fire event
                                
                                terminate_monitor
                            end_if
    
    
                            if not I_SettlementOwner Scutari = FROM
                                set_event_counter tradeMax_Adriatic 0
                                
                                ;;fire event
                                
                                terminate_monitor
                            end_if
    
    
                            if not I_SettlementOwner Podgorica = FROM
                                set_event_counter tradeMax_Adriatic 0
                                
                                ;;fire event
                                
                                terminate_monitor
                            end_if
    
    
                            if not I_SettlementOwner Pola = FROM
                                set_event_counter tradeMax_Adriatic 0
                                
                                ;;fire event
                                
                                terminate_monitor
                            end_if
    
    
                            ;Trade Nexus Provinces
                            if not I_SettlementOwner Venice = FROM
                                set_event_counter tradeMax_Adriatic 0
                                
                                ;;fire event
                                
                                terminate_monitor
                            end_if
                            if not I_SettlementOwner Ancona = FROM
                                set_event_counter tradeMax_Adriatic 0
                                
                                ;;fire event
                                
                                terminate_monitor
                            end_if
                            
                            if not I_SettlementOwner Ragusa = FROM
                                set_event_counter tradeMax_Adriatic 0
                                
                                ;;fire event
                                
                                terminate_monitor
                            end_if
                            
                            if not I_SettlementOwner Brindisi = FROM
                                set_event_counter tradeMax_Adriatic 0
                                
                                ;;fire event
                                
                                terminate_monitor
                            end_if
                            
                            if not I_SettlementOwner Taranto = FROM
                                set_event_counter tradeMax_Adriatic 0
                                
                                ;;fire event
                                
                                terminate_monitor
                            end_if
    
    
                            if not I_SettlementOwner Durazzo = FROM
                                set_event_counter tradeMax_Adriatic 0
                                
                                ;;fire event
                                
                                terminate_monitor
                            end_if
                        
                        end_if
                    end_if
                end_if
                
            end_monitor

  4. #4

    Default Re: Is it possible to use an "or"/"else if" operator?

    Without knowing how these event counters interact with EDB or how the initial event counter being monitored is changed, it's hard to comment on your script. But I'll give you some general advice.

    AI turn times are primarily a function of the number of monitors in your campaign_script. What you are doing by monitoring EventCounter is essentially a function call. It can be done more efficiently by using only one such monitor, as in:

    Code:
    monitor_event EventCounter TrueCondition
    
     if I_EventCounter tradeReCalc_Adriatic > 0
      set_event_counter tradeReCalc_Adriatic 0
      ;... do stuff...
     end_if
    
     if I_EventCounter someothercounter > 0
      ;...etc.
     end_if
    
    end_monitor
    Elsewhere in script, you can use inc_event_counter to call the if-blocks in this monitor, which are essentially functions. Obviously, you should never terminate this monitor. In fact, I encourage you not terminate any monitors unless absolutely necessary (which would be unusual). The design paradigm is to have as few monitors as possible, ideally no more than one for each event type, that handle everything related to their event for the whole campaign without terminating. In other words, it is better to have fewer non-terminating monitors than a greater number of terminating monitors because it takes time for monitors to terminate if they ever do so at all. Most mods make this mistake - they pack their campaign_script with thousands of monitors which are meant to eventually terminate when they could actually get away with ~50 non-terminating monitors and have AI turn times comparable to vanilla.

    The counterpoint to this design principle is my previous comment in this thread where the event condition SettlementBuildingExists requires multiple monitors for the same event; SettlementTurnStart. Event conditions like this which have no I_ version are the only reason to ever have more than one monitor for the same event.

    At any rate, it doesn't seem to make sense for your script to terminate this monitor as soon as the first set of conditions are met, because then the bonus will be active for the rest of the campaign even if one faction no longer controls the required regions.
    Last edited by Callistonian; December 07, 2022 at 06:43 PM.

  5. #5

    Default Re: Is it possible to use an "or"/"else if" operator?

    Thr EDV will have event counter triggered trade/growth bonuses. I may also add in a penalty/negative triggered by trade disruption due to sieges or blockades.

    Is there any real benefit to using a function call rather than simply having the code within a GeneralCapturesSettlement monitor? I would evaluate against the specific provinces rather than the buildings.

  6. #6

    Default Re: Is it possible to use an "or"/"else if" operator?

    In general, it's good practice to use function calls instead of duplicating commands in multiple places. That way, if you ever want to edit the function, you only need to edit one bit of code instead of several which you are more likely to forget about. Using function calls also makes for more readable code. In my opinion, it's cleaner to have your event monitors (for FactionTurnStart, etc. etc.) contain as little code as possible and instead make maximal use of calls. Then for example, if you decide you want to use FactionTurnStart instead of GeneralCaptureSettlement, all you have to do is move one inc_event_counter line from one monitor to the other instead of an entire function. But in terms of performance, no, there is no difference between 'localizing' your code to monitors vs. using calls (remembering that calls use only one EventCounter monitor which has a negligible impact on AI turn times).

  7. #7

    Default Re: Is it possible to use an "or"/"else if" operator?

    Alright, so I think I've got it then. Here's the barebones of the script.

    Basically, the gist of it is that "guilds" are trade outposts of certain factions (Venice, Genoa, Ancona, Switzerland, Aragon, and the Hafsids), and controlling/unifying a trade route requires ownership of all provinces in the node OR having your trade outposts there, if you are one of those factions. Unifying a node will give access to recruitment of certain units and also give bonuses to the buildings associated with that node (and possibly to the trade posts), regardless of where they are. Thanks again for your help.

    Code:
    		;Trade ReCalc		
    		monitor_event GeneralCaptureSettlement SettlementBuildingExists tradeRoute_Adriatic
    				set_event_counter tradeReCalc_Adriatic 1
    		end_monitor
    
    
    		monitor_event GeneralCaptureSettlement SettlementBuildingExists tradeNexus_Adriatic
    				set_event_counter tradeReCalc_Adriatic 1
    		end_monitor
    		
    		;;repeat for all trade nodes
    
    
    		monitor_event GuildUpgraded trade_venice
    			and SettlementBuildingExists tradeRoute_Adriatic
    				set_event_counter tradeReCalc_Adriatic 1
    		end_monitor
    
    
    		monitor_event GuildUpgraded trade_venice
    			and SettlementBuildingExists tradeNexus_Adriatic
    				set_event_counter tradeReCalc_Adriatic 1
    		end_monitor
    
    
    		monitor_event GuildDestroyed trade_venice
    			and SettlementBuildingExists tradeRoute_Adriatic
    				set_event_counter tradeReCalc_Adriatic 1
    		end_monitor
    
    
    		monitor_event GuildDestroyed trade_venice
    			and SettlementBuildingExists tradeNexus_Adriatic
    				set_event_counter tradeReCalc_Adriatic 1
    		end_monitor		monitor_event GuildUpgraded trade_venice
    			and SettlementBuildingExists tradeRoute_Adriatic
    				set_event_counter tradeReCalc_Adriatic 1
    		end_monitor
    
    
    	;repeat for all guilds (Venice, Genoa, Ancona, Swiss, Catalans, Hafsids), and all trade nodes
    
    
    		monitor_event EventCounter TrueCondition
    		
    		if I_EventCounter tradeReCalc_Adriatic > 0
    			
    			;recalc Adriatic Trade
    			
    		end_if
    		
    		;repeat for all trade nodes
    		
    		end_monitor

Posting Permissions

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