Results 1 to 19 of 19

Thread: Script to add a "Capital" building

Hybrid View

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

    Default Script to add a "Capital" building

    [Kingdoms only]

    Here is a tool that will build this script for Kingdoms and any Kingdoms-based mod: TWCapital.

    The attached script auto-builds a new "Faction Capital" building in the settlement that is the faction's capital. When the capital changes then this building is removed from the old capital and built in the new capital, automatically.

    It works for all playable vanilla Kingdoms Grand Campaign factions, for both player and AI. i.e. The AI factions will also have this building, except for: Mongols, Timurids, Papal States, Aztecs and Slaves.

    Why? You could add some capabilities to this new building, things that you wish only the capital to provide:
    • Bonuses
    • Special recruitment options
    • Conditions for other buildings, allowing you to only build certain buildings in capitals
    • Trait/ancillary triggers but if that is all you need then you may as well just use the DistanceCapital = 0 condition
    • Campaign script conditions, e.g. special garrison scripts for capitals

    Demo
    Emperor of Hell has made a video demonstrating the building appearance as the player changes the capital...
    Spoiler Alert, click show to read: 
    It was from an earlier version - before I made the building icon - so the building has the "placeholder" icon here. Thanks EoH.

    Building
    The building is named fcb_capital internally and "Faction Capital" in-game. It is not buildable by the player/AI, only by the script, and it is indestructible.

    Spoiler Alert, click show to read: 

    export_descr_buildings.txt
    Code:
    building hinterland_fcb_capital
    {
        levels fcb_capital
        {
            fcb_capital city requires factions {  } 	;built by script only
            {
                capability
                {
                }
                material wooden
                construction  1 
                cost  0 
                settlement_min village
                upgrades
                {
                }
            }
        }
        plugins
        {
        }
    }


    export_buildings.txt
    Code:
    {fcb_capital}Faction Capital
    {fcb_capital_desc}This settlement is the faction capital.
    {fcb_capital_desc_short}This settlement is the faction capital.
    Attachment 221054 Attachment 221053

    The Script
    The "build script" is the main processing monitor that does pretty much everything. For a given faction it:
    1. Works out which settlements it owns
    2. Works out which one of those is the capital
    3. Destroys all capital buildings for that faction
    4. Builds a capital building in the capital

    The rest of the script is monitoring events, triggering the build script when necessary:
    • FactionNewCapital: If the faction changes its capital then the build script is triggered for that faction.
    • GeneralCaptureSettlement: If faction A captures faction B's capital then the capital building is destroyed in that settlement, avoiding faction A from now having two of these buildings. If faction B still exists then FactionNewCapital will trigger which in turn builds them a new building.
    • CityRebels: If a faction's capital goes rebel then the building is removed from that settlement (preventing slaves from having one). Again, FactionNewCapital would now trigger for the faction, auto-building a capital building in the new capital.
    • FactionTurnStart: At the start of each faction's turn it counts how many capital buildings they own. If the faction should have a building (i.e. a playable faction) and they have 0 or 2+ of them then the build script is triggered for that faction. If the faction should not have the building but they do then the building(s) are destroyed for that faction.

    The last one is a bit of a catch-all, in case a building somehow ends up in a non-capital, or is absent from a capital. Things are put right at the start of the next turn. e.g. Say the Mongols take ownership of the French capital Paris by any means other than attacking: through a faction_emerge or some kind of scripted give_region. The Mongols now have the capital building in Paris even though it might not be their capital. Say it isn't their capital and the player uses diplomacy's "Give Region" to take Paris from them. Now the player has two capital buildings: in Paris and whatever their capital is. This will be fixed at the start of the next turn.

    UPDATE: actually, it seems as though that faction_emerge scenario still works anyway. If a settlement is the victim of a faction_emerge then GeneralCaptureSettlement triggers on that settlement. (News to me!) Which means that this script's GeneralCaptureSettlement monitors will automatically destroy the building in that settlement. This is good news! Not only for emerging faction situations but also for this give-region script which uses faction_emerge; if you give away a capital - which that script lets you do - then the building disappears immediately from that now-ex-capital.

    UPDATE 2: Nope, I was wrong about that. faction_emerge does not trigger GeneralCaptureSettlement, it triggers GiveSettlement. The script does not include any GiveSettlement monitors because capitals can't be given away; obviously faction_emerge (and Region Owner Switch which uses it) is an exception to that so additional monitors are needed. See the script at the end of this post.

    The script is very large due to it needing to handle the case of any settlement being the capital of any faction: settlement_count x faction_count cases = a lot of cases!

    There are quite a few monitors but impact on turn end times should be negligible. And it is all automatic! Your script doesn't need to know how to use this script: just drop it into your script and forget about it.

    Spawned Character
    To determine the capital the script spawns a temporary general for that faction and positions him over each settlement in that faction, testing his DistanceCapital in the process. This all happens very fast but you will see a character over the settlements for an instant. After his job is done the script kills him by destroying his bodyguard unit type.

    In this script the bodyguard is Theigns. They only belong to the Saxons so there is no chance that any of the playable factions could own this unit. This is important: if Theigns can belong to any of these Faction Capital factions then the script will kill them! If you have modded the game so that Theigns can in any way be in the campaign for these factions then you should adjust the script to use a different unit.


    The attached contains only this script, not the vanilla campaign_script. You will need to insert the contents of fcb_campaign_script.txt into your campaign_script.txt. Plus drop the "ui" folder into your "data" folder to add the building images.

    ~~~~

    Download Script

    Attachment 221055

    ~~~~

    Region Owner Switch & emerge_faction

    As mentioned above ("update 2") if a region is given to another faction via faction_emerge and that region was the capital of the from-faction then the to-faction now owns their capital building even though this region might not be the to-faction's capital. The script will handle building the capital building in the from-faction's new capital (via the FactionNewCapital event) and I expect that it would also handle building it in the emerging faction's capital because that too should fire a FactionNewCapital event.

    However, Region Owner Switch is a different story because it emerges a 'hidden' faction - "spawnpool" - to take ownership of the region and then uses give_everything_to_faction to give that region from spawnpool to whichever faction is the intended new owner. So now the new owner owns two capital buildings: one in their capital and one in this region that was just transferred to them (if that region was the original owner's capital).

    There is an easy fix for that:

    Code:
    monitor_event GiveSettlement TargetFactionType spawnpool
      destroy_buildings spawnpool hinterland_fcb_capital false
    end_monitor
    When faction_emerge happens this monitor will fire and destroy all of spawnpool's capital buildings (of which there should only be one). By the time that the region is transferred to the intended owner its capital building no longer exists, so no extra capital building is given to the new owner.

    An [and SettlementBuildingExists = fcb_capital] condition could be added but there's no real benefit in doing so.
    Last edited by Withwnar; April 19, 2014 at 02:47 AM.

  2. #2
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default Re: Script to add a "Capital" building

    "factions { slave, }" prevents building by the player/AI and appearing in the browser. "hidden_resource hr_none" prevents the slaves from building it. "hr_none" must be added to the list at the top of EDB but not assigned to any regions in descr_regions.txt.
    Not entering anything in the faction brackets (leave three spaces) and omitting the hidden_resource entry has the same effect.

    Awesome script - it will indeed be a nightmare to replicate this for another mod, a ton of mod specific variables that would need changing.










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

    Default Re: Script to add a "Capital" building

    Quote Originally Posted by Gigantus View Post
    Not entering anything in the faction brackets (leave three spaces) and omitting the hidden_resource entry has the same effect.
    From memory it shows up in the browser when you switch between the City and Castle tabs.

    Quote Originally Posted by Gigantus View Post
    Awesome script - it will indeed be a nightmare to replicate this for another mod, a ton of mod specific variables that would need changing.
    Thanks. Yep, I wouldn't wish it on my worst enemy. A shame but a tool shouldn't be too hard to make, based on something I've written before.

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

    Default Re: Script to add a "Capital" building

    Quote Originally Posted by Withwnar View Post
    From memory it shows up in the browser when you switch between the City and Castle tabs.
    No it doesn't. I thought I had tried { } in the past and failed, but it works fine for this so I'll change it. Thanks.

    Quote Originally Posted by Emperor of Hell View Post
    Do you have a base script which one can throw into the script generator?
    Sorry, didn't see your post there and still a valid question: no, because the script also needs the location of each settlement and a valid tile adjacent to it.

  5. #5
    Emperor of Hell's Avatar SPA-NED 1-5
    Join Date
    Jul 2011
    Location
    Netherlands
    Posts
    5,747

    Default Re: Script to add a "Capital" building

    Great work With. Will check it out.

    Do you have a base script which one can throw into the script generator? So it can also be compatible with other mods easily

    should have read your whole post before replying

  6. #6

    Default Re: Script to add a "Capital" building

    It looks like it has the desired effects and would work with most mods with some effort. Nice to see you stuck with this! I'm going to stick with traits for now but I could see such a script being very useful for some mods.

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

    Default Re: Script to add a "Capital" building

    I have made a tool to generate the script for this: TWCapital.

    A slight change to the building internal name: fcb_capital instead of fct_capital. Faction Capital Building instead of Faction Capital Test. The OP has been updated and its attachment is a new version, built with the tool.

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

    Default Re: Script to add a "Capital" building

    OP updated with some internal workings explanation. The "next-turn-start cleanup" bit might be important to any trying to use this.

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

    Default Re: Script to add a "Capital" building

    OP updated with this spot of good news, especially when combining this with the give-region script...

    UPDATE: actually, it seems as though that faction_emerge scenario still works anyway. If a settlement is the victim of a faction_emerge then GeneralCaptureSettlement triggers on that settlement. (News to me!) Which means that this script's GeneralCaptureSettlement monitors will automatically destroy the building in that settlement. This is good news! Not only for emerging faction situations but also for this give-region script which uses faction_emerge; if you give away a capital - which that script lets you do - then the building disappears immediately from that now-ex-capital.

  10. #10

    Default Re: Script to add a "Capital" building

    So, this can be used to test whether the capital is a given settlement or not? Say if I want to write a script to tell the player (in TATW) to move the capital of OOG to Carn-Dum upon the Witchking's return. Or is there a way to directly move the capital via script?

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

    Default Re: Script to add a "Capital" building

    The presence of the building - SettlementBuildingExists (?) - would mean "this is the capital", yes. Alternatively, if you don't want the building, you could just use the part of the script that does the "is capital?" test.

    There is no way to script a capital shift, as far as I know. Except - possibly - for player only by simulating mouse clicks on scrolls, as though the player was doing it.

  12. #12

    Default Re: Script to add a "Capital" building

    Ok, thanks. I guess what I was really thinking was a script that tests if the OOG capital is at Carn-Dum, as a condition for the WK to return.

    OT question - Is there a way to change the faction leader via script?
    Last edited by Spice Master; April 09, 2013 at 12:36 AM.

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

    Default Re: Script to add a "Capital" building

    Quote Originally Posted by Spice Master View Post
    I guess what I was really thinking was a script that tests if the OOG capital is at Carn-Dum, as a condition for the WK to return.
    Like I said: the script contains the logic to do just that, to figure out where the capital is so it knows where to build the building.

    This should do it. Significantly helped by TATW already having a 'spawnpool' faction (hungary). You'll need to add CarnDumCapitalTest to Hungary's name list.

    Code:
    declare_counter carn_dum_is_capital
    
    monitor_event PreFactionTurnStart FactionIsLocal
      
      spawn_army 
        faction hungary
        character  CarnDumCapitalTest, named character, age 22, x 390, y 339
        unit  Bandits    exp 0 armour 0 weapon_lvl 0
      end
      
      give_everything_to_faction hungary hre false
      
      ;reposition him on top of Carn Dum
      console_command move_character CarnDumCapitalTest, 151, 307
      
      ;lock him there
      console_command mp CarnDumCapitalTest -1
      
      set_counter carn_dum_is_capital 1
      
      move CarnDumCapitalTest, 151, 308
      
      ;wait for MultiTurnMove events to fire  
      while  I_CompareCounter carn_dum_is_capital == 1
      end_while
      
      ;move him out of visibility range and kill him
      console_command move_character CarnDumCapitalTest, 390, 339
      kill_character CarnDumCapitalTest
      
      if I_CompareCounter carn_dum_is_capital == 0
        ;Carn Dum is not the capital
      end_if
      if I_CompareCounter carn_dum_is_capital == -1
        ;Carn Dum is the capital
      end_if
    
    end_monitor
    
    monitor_event MultiTurnMove I_CompareCounter carn_dum_is_capital == 1
      and DistanceCapital == 0
      ;the test character is standing on the capital
      set_counter carn_dum_is_capital -1
    end_monitor
    
    monitor_event MultiTurnMove I_CompareCounter carn_dum_is_capital == 1
      ;the test character is NOT standing on the capital
      set_counter carn_dum_is_capital 0
    end_monitor
    You can remove the FactionIsLocal if you want this to work on AI factions too. Just replace with TrueCondition or whatever conditions you need. It doesn't need to be PreFactionTurnStart either.
    Last edited by Withwnar; April 14, 2013 at 12:38 AM.

  14. #14
    Gigantus's Avatar I am not special - I am a limited edition.
    Moderator Emeritus Administrator Emeritus

    Join Date
    Aug 2006
    Location
    Goa - India
    Posts
    52,682
    Blog Entries
    35

    Default Re: Script to add a "Capital" building

    You can kill him via script if you know his name - otherwise no.










  15. #15

    Default Re: Script to add a "Capital" building

    Thanks so much. Very helpful as always.

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

    Default Re: Script to add a "Capital" building

    Quote Originally Posted by Spice Master View Post
    Thanks so much. Very helpful as always.

    You're welcome. I didn't test it so I would be interested to know if it works okay.

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

    Default Re: Script to add a "Capital" building

    Did this work Spice Master?

  18. #18

    Default Re: Script to add a "Capital" building

    Honestly haven't tried it yet. Been caught up with revamping the Rhudaur roster (basing them off late Roman era Visigoths). Maybe tomorrow. I'll let you know.

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

    Default Re: Script to add a "Capital" building

    OP updated with some info regarding faction_emerge: see "update 2" and the bottom of the post.

Posting Permissions

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