Results 1 to 10 of 10

Thread: Two questions relating to campaign script

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    EarendilElenthol's Avatar Artifex
    Join Date
    Apr 2008
    Location
    The Netherlands
    Posts
    998

    Default Two questions relating to campaign script

    I'm now trying to understand some scripting and two questions came up:

    Firstly:
    What does the FactionIsLocal precisely do? I see it in nearly every script and it is explained a bit in the scripting courses. But it's not yet clear to me. When specific do you use it? I take that FactionIsLocal is something like a check whether it is the player's turn, but why not use StartTurn or EndTurn then?

    Secondly:
    I was thinking of a way to relate the income of a tavern to the trade of a settlement, but I'm a scripting noob. After some evenings thinking and seeking about how scripts work and what the possibilities are in M2TW I compiled this:

    Spoiler Alert, click show to read: 
    Code:
        monitor_event SettlementTurnStart FactionIsLocal
                and SettlementName Smolensk
            declare_counter smo_tra_lvl
        
            if SettlementBuildingExists = market_area
                inc_event_counter smo_tra_lvl 1
            end_if
            if SettlementBuildingExists = fairground
                inc_event_counter smo_tra_lvl 1
            end_if
            if SettlementBuildingExists = dif_markets
                inc_event_counter smo_tra_lvl 1
            end_if
            if SettlementBuildingExists = merchants_guild
                inc_event_counter smo_tra_lvl 1
            end_if
            if SettlementBuildingExists = merchants_hall
                inc_event_counter smo_tra_lvl 1
            end_if
            if SettlementBuildingExists = merchant_bank
                inc_event_counter smo_tra_lvl 1
            end_if
        end_monitor
        
        monitor_event SettlementTurnEnd FactionIsLocal
                and SettlementName Smolensk
        reset_counter smo_tra_lvl or: set_counter smo_tra_lvl 0 ?
        end_monitor


    The idea is that when the turn of a faction starts the script checks for the buildings in the settlements and the value is used in the EDB. After that it resets and the next faction settlements get checked. This way I will need to write an entry for each settlement.
    I know this script won't work, and if anyone would look in it and correct my mistakes, I would be very glad. It's just that I'm trying to learn myself to script so if you explain my mistakes, I would be even happier.
    If this idea is absolutely rubbish and won't be possible in any way, please tell me, and explain why. Perhaps some parts can work even though the full idea cannot.

    Thanks in advance,

    EE
    Last edited by EarendilElenthol; October 12, 2009 at 06:03 PM. Reason: Change of title

  2. #2
    Caesar Clivus's Avatar SS Forum Moderator
    Join Date
    May 2007
    Location
    Australia
    Posts
    12,693

    Default Re: Two questions relating to campaign script

    FactionIsLocal checks to see if the faction in question is being controlled by the player. So the local faction is always the one being played. It's very useful for when you want things to fire in the script that only affects the player and not the AI or visa versa.

    I'm no scripting genius either but I think you can get away with one monitor for this and just use an if statement for all settlements. Something like:

    Code:
    monitor_event SettlementTurnStart FactionIsLocal
            if SettlementName Smolensk
                    if SettlementBuildingExists = market_area
                            inc_event_counter smo_tra_lvl 1
                    end_if
                    if SettlementBuildingExists = fairground
                            inc_event_counter smo_tra_lvl 1
                    end_if
                    if SettlementBuildingExists = dif_markets
                            inc_event_counter smo_tra_lvl 1
                    end_if
                    if SettlementBuildingExists = merchants_guild
                            inc_event_counter smo_tra_lvl 1
                    end_if
                    if SettlementBuildingExists = merchants_hall
                            inc_event_counter smo_tra_lvl 1
                    end_if
                    if SettlementBuildingExists = merchant_bank
                            inc_event_counter smo_tra_lvl 1
                    end_if
              end_if
               if SettlementName Novgorod
                      etc etc etc.
        end_monitor
    I think that would work but you'd want a second opinion on that first

    BftB2 UPDATED 22nd DECEMBER. Member of the Complete Byzantine Unit Roster team

  3. #3
    Augustus Lucifer's Avatar Life = Like a beanstalk
    Patrician Citizen

    Join Date
    Aug 2006
    Location
    Mote of Dust
    Posts
    10,725

    Default Re: Two questions relating to campaign script

    The problem in both of the above scripts is that 'if' statements only accept conditions with I_ in front of them. The reason is that the monitor doesn't send information to contained 'if' or 'while' statements, so this line:
    Code:
    if SettlementBuildingExists = fairground
    Doesn't know which settlement, if any, is being referred to, since it isn't getting the information it needs from the monitor. The conditions which start with I_, the most common of which is I_EventCounter, all specify their own parameters and are this Independent of a monitor(not sure if that's what the I means, but it's a fine way to remember it). This enables them to work within each other and within monitors since they demand that you provide all the information they need to determine if the condition is true or false.

    So for the above you'd need separate monitors for every settlement for every building level, if you wanted to handle it in that way.

    Another problem which is a common misconception is that the EDB, or any file besides scripts for that matter, can read counters or event counters besides 0/1. If an event counter is > 0 as far as the EDB/EDCT/EDA/etc. are concerned it's 1. To remedy this you'd need something along the lines of:
    Code:
    declare_counter smo_tra_lvl
    ; do the above line elsewhere outside a monitor
    
    set_event_counter smo_tra_lvl_1 0
    set_event_counter smo_tra_lvl_2 0
    set_event_counter smo_tra_lvl_3 0
    set_event_counter smo_tra_lvl_4 0
    set_event_counter smo_tra_lvl_5 0
    set_event_counter smo_tra_lvl_6 1
    if I_CompareCounter smo_tra_lvl == 1
        set_event_counter smo_tra_lvl_1 1
    end_if
    if I_CompareCounter smo_tra_lvl == 2
        set_event_counter smo_tra_lvl_2 1
    end_if
    if I_CompareCounter smo_tra_lvl == 3
        set_event_counter smo_tra_lvl_3 1
    end_if
    if I_CompareCounter smo_tra_lvl == 4
        set_event_counter smo_tra_lvl_4 1
    end_if
    if I_CompareCounter smo_tra_lvl == 5
        set_event_counter smo_tra_lvl_5 1
    end_if
    if I_CompareCounter smo_tra_lvl == 6
        set_event_counter smo_tra_lvl_6 1
    end_if
    I recommend using counters for things which don't directly translate to the EDB or other files. It's not necessarily proven but is logically assumable that they take up less memory than event counters. If that were not the case they may as well have been deprecated when event counters got more streamlined. They're also automatically logged in the script log.

    Are those buildings you want to base it off separate trees or buildings within the same tree? If they're separate trees you can do all of that directly in the EDB. If separate buildings in the same tree, then it would be a lot more complex and probably not worth the effect, especially since I'm unsure how it's supposed to act on itself.
    Last edited by Augustus Lucifer; October 12, 2009 at 09:13 PM.

  4. #4
    EarendilElenthol's Avatar Artifex
    Join Date
    Apr 2008
    Location
    The Netherlands
    Posts
    998

    Default Re: Two questions relating to campaign script

    The idea was to combine the effects of all trade buildings in a number that can be used to decide the income of buildings that are dependent on the amount of trade. Thanks for all the help, I'll see what I can do within these constrains.
    I had already put quite a lot buildings in separate trees to facilitate the EDB coding, this was for all the others.

    I recommend using counters for things which don't directly translate to the EDB or other files.
    What do you mean with this? How to script then for things that are used (as event_counter) in the EDB?

    How do I make a script that checks for only the settlements that that faction owns? It doesnt matter whether it is the player or not. I guess you can make one for all the settlements on the end of the players turn, but I think that is not the most efficient way. And what determines the time that the engine takes in processing the other factions while you wait? What is the "normally used" amount of counters in the full script, close to 1000 or more like 5000 or 10000?
    Last edited by EarendilElenthol; October 13, 2009 at 04:47 AM.

  5. #5
    Augustus Lucifer's Avatar Life = Like a beanstalk
    Patrician Citizen

    Join Date
    Aug 2006
    Location
    Mote of Dust
    Posts
    10,725

    Default Re: Two questions relating to campaign script

    Quote Originally Posted by EarendilElenthol View Post
    What do you mean with this? How to script then for things that are used (as event_counter) in the EDB?
    Well 'counters' have to be declared and use 'set_counter', 'inc_counter', 'I_CompareCounter', etc. They are only referenced within the campaign script. Event counters use the other set and can be referenced in other files, except only as a true/false value(boolean). So in the above example counters are used for the main tracking, which in turn sets event counters that are more usable by other files since they are separated in name and not in value.

    Quote Originally Posted by EarendilElenthol View Post
    How do I make a script that checks for only the settlements that that faction owns? It doesnt matter whether it is the player or not. I guess you can make one for all the settlements on the end of the players turn, but I think that is not the most efficient way.
    You can use a script to set counters when each faction's turn starts, that lets it be known which turn it is(near or at the top of the script so it always runs before any scripts that utilize it).
    Code:
    declare_counter france_turn
    
    monitor_event PreFactionTurnStart FactionType france
    
    set_counter france_turn 1
    
    end_monitor
    monitor_event FactionTurnEnd FactionType france
    
    set_counter france_turn 0
    
    end_monitor
    Then reference these counters with I_CompareCounter and combine it with I_SettlementOwner.
    Code:
    monitor_event ... ...
        if I_CompareCounter france_turn == 1
          and I_SettlementOwner paris = france
          ;do something
        end_if
    end_monitor
    Quote Originally Posted by EarendilElenthol View Post
    And what determines the time that the engine takes in processing the other factions while you wait? What is the "normally used" amount of counters in the full script, close to 1000 or more like 5000 or 10000?
    Not sure what you mean by determines the time it takes. There's a command to speed up the processing of the AI turns, but it hinders gameplay since the AI isn't permitted certain things, and probably has no bearing on script. Try not to use monitor_conditions, but aside from that there's no known formula. Most heavily scripted mods probably use over 1,000 counters, over 10,000 seems like a lot but frankly I don't really keep track.

  6. #6
    EarendilElenthol's Avatar Artifex
    Join Date
    Apr 2008
    Location
    The Netherlands
    Posts
    998

    Default Re: Two questions relating to campaign script

    Thanks for your reaction. Still one thing is not yet clear to me. If you want to "deduct" a trade_level for a settlement like I did, you would hope that this script is run only once each turn, otherwise the game needs to check for 199 (regions) times x (factions) and that would severly eat memory or time I would guess.
    Then the most easy way should be to run the script every time after the player's turn has taken place (and thus sets "fixed" counters until the next turn of the player). But then, new relevant buildings built during the turn of a faction, and conquered afterwards by a later faction still keep the lower counter, instead of the right one. So I thought that the most efficient way would be that each faction only processes their own settlements.
    This is of course only a minor issue, and it seems that I will be able to restrict the events to about 500 instead of the 2000 that one would expect with calculations (due to capped settlement levels). When you want to set up a "fixed" set of counters after the players turn, then a simple TurnEnd FactionIsLocal combination will be enough?

  7. #7
    EarendilElenthol's Avatar Artifex
    Join Date
    Apr 2008
    Location
    The Netherlands
    Posts
    998

    Default Re: Two questions relating to campaign script

    Thanks, then I will slowly implement it, and look whether it works as I envisaged, without taking too much time. I have reduced the amount of event_counters to about something like 2000 and the amount of lines in the EDB to about 10k as I started calculating how much it would take... at the start it was over 50k lines and that is impossible of course.

    But when it works as I hoped, then it is the first script that emulates the economy in an historical way. I am eager to start, but first off to bed.

Posting Permissions

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