Results 1 to 10 of 10

Thread: Single Building Available in Multiple Regions

  1. #1

    Default Single Building Available in Multiple Regions

    I would like for a particular building to be available in multiple settlements but only buildable in one of those settlements. I.e., the building initially shows up for settlements A and B but as soon as the player adds it to the queue in A, it is removed from the list of B and cannot be built there.

    My first attempt at the script was to use the BuildingCompleted condition but of course this allows the player to queue the building in both settlements simultaneously. Even if it is completed in settlement A and the event counter set to 0, the building queued in B will still be completed (assuming the player doesn't cancel it).

    My second attempt was using AddedToBuildingQueue and TrueCondition but this gives a false positive and sets the counter to 0 from turn 1 preventing the building from being built anywhere.

    The final script also needs to account for "switching" between settlements with the building browser open (i.e. without selecting the second settlement). Even if it's possible to test when the building is added to the queue in A, I have found that setting the event counter to 0 will have no effect if the building browser scroll remains open so it's doubtful that my second attempt would have worked anyway. I'm hoping it's possible to automatically remove a building from a particular settlement's queue as this would account for the "switching" problem.

    Any help is greatly appreciated.

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

    Default Re: Single Building Available in Multiple Regions

    I tried the following and it seemed to work as expected: farms no longer buildable once it's added to the queue anywhere...

    EDB:
    Code:
    building hinterland_farms
    {
        convert_to hinterland_farms
        levels farms farms+1 farms+2 farms+3 
        {
            farms  requires factions { northern_european, middle_eastern, eastern_european, greek, southern_european, } and event_counter can_build_farms 1  
    CS:
    Code:
    set_event_counter can_build_farms 1
    
    monitor_event AddedToBuildingQueue BuildingName = farms
      set_event_counter can_build_farms 0
    end_monitor
    However, there's no event for removing a building from the queue, nor a condition for checking that it's currently in a queue anywhere. Therefore, the above works only if the player doesn't remove it from the queue. If they do then can_build_farms will remain at 0 and therefore unbuildable anywhere, because there's no way for script to know that it needs setting back to 1.

    NOTE: in the above script, once they're disabled for the player they're also disabled for all factions. A more complete example would need to deal with that somehow.

  3. #3

    Default Re: Single Building Available in Multiple Regions

    Ah, I was using the wrong exports for AddedToBuildingQueue. Fortunately, this building only needs to be available for a single faction. My attempt at fixing the 'player cancels construction' bug is to simply start a turn timer when the building is added to the queue. Once the timer reaches the construction time specified in EDB (and I use > to make sure it's actually a bit beyond the construction time so there is no overlap i.e. the player can't start simultaneous construction in the other settlement) the event_counter is set back to 1 making the building available again. This does of course mean that if the player cancels the construction they will have to wait the length of the construction time before trying again. Here is the script:

    Spoiler Alert, click show to read: 

    Code:
    set_event_counter building_available 1
    set_event_counter building_completed 0
    declare_counter building_timer
        
        monitor_event AddedToBuildingQueue BuildingName = building_a
            set_event_counter building_available 0
        end_monitor
        
        monitor_event FactionTurnStart FactionType england
            if I_EventCounter building_completed == 1
                terminate_monitor
            end_if
            if I_EventCounter building_available == 0
                inc_counter building_timer 1
            end_if
            if I_CompareCounter building_timer > 10                        ;unlock building again after 10 turns (construction time in EDB)
                set_event_counter building_available 1
            end_if
        end_monitor
        
        monitor_event BuildingCompleted SettlementBuildingFinished = building_a
            set_event_counter building_completed 1
        end_monitor

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

    Default Re: Single Building Available in Multiple Regions

    That's a good solution.

    If it does take longer than 10 turns to build, because it was added on the end of a longish queue, then it's possible that by the time it is built building_available has been set to 1 again in the meantime, so it could be built a second time somewhere. It would pay to set that counter to 0 in the last monitor, and you may as well terminate that monitor too.

    Does this building actually get built? It seems to me that building_available being 0 would disallow any construction progress on it, as described in your other thread.

  5. #5

    Default Re: Single Building Available in Multiple Regions

    I'm still not sure it's logically possible to resolve this, so please check my code. What I've done is use a second event counter to handle the internal state which is paired with the EDB event counter (the 'external state').

    Spoiler Alert, click show to read: 

    Code:
        set_event_counter building_available 1       ;external (EDB) counter
        set_event_counter firstaddtoqueue 0         ;internal counter
        set_event_counter building_completed 0
        declare_counter building_timer
        
        monitor_event AddedToBuildingQueue BuildingName = building_a
            set_event_counter building_available 0
            set_event_counter firstaddtoqueue 1
        end_monitor
        
        monitor_event FactionTurnStart FactionType england
            if I_EventCounter building_completed == 1              ;minimize number of turn start monitors ASAP
                terminate_monitor
            end_if
            if I_EventCounter firstaddtoqueue == 1
                set_event_counter building_available 0               ;return the EDB counter to 0 every turn start
                inc_counter building_timer 1
            end_if
            if I_CompareCounter building_timer > 10                  ;unlock building again after 10 turns (construction time in EDB)
                set_event_counter building_available 1                ;if player adds building to end of long queue, then this will set event_counter to 1 prematurely allowing two to be built
                set_event_counter firstaddtoqueue 0
                set_counter building_timer 0
            end_if
        end_monitor
        
        monitor_event BuildingCompleted SettlementBuildingFinished = building_a
            set_event_counter building_completed 1
            set_event_counter building_available 0                    ;even if two are being built, as soon as first is finished the other will stop progress, hopefully the player will eventually get the idea
            terminate_monitor
        end_monitor


    Then in the same monitors I used for that other script I have...

    Spoiler Alert, click show to read: 

    Code:
         monitor_event SettlementSelected TrueCondition                        ;this is the critical monitor that 'pairs' the two event counters
            if I_EventCounter firstaddtoqueue == 1
                set_event_counter building_available 0
            end_if
        end_monitor
    
         monitor_event ButtonPressed ButtonPressed end_turn                    ;this allows the construction to progress
            set_event_counter building_available 1
        end_monitor
    Last edited by Callistonian; September 16, 2019 at 02:34 PM.

  6. #6

    Default Re: Single Building Available in Multiple Regions


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

    Default Re: Single Building Available in Multiple Regions

    The script of both threads is for the same building? If so then I think that there are holes in the second part but I'd need to see all of it to say for sure.

    The first part looks right but I think that there's a way to do it without that additional counter. Again, I'd need to see the full combined script first.

  8. #8

    Default Re: Single Building Available in Multiple Regions

    The scripts are for different buildings but I'm using those two monitors for both scripts (I cut out the parts for the other building from the other thread). The script in this thread makes a building available in two settlements but only buildable in one of them and will instantly remove the building from the list in the other settlement even with "switched". I've tested and it seems to be working. The script in the other thread allows only certain factions to select only certain settlements to build a building.

    Script in this thread is going to be used for a "capitol" building which can only be built in one place. A nice, but mostly trivial feature.

    Script in the other thread is much more powerful. It can be used to unlock custom settlement upgrades for specific factions for specific settlements selected. Which means all 31 factions can have as many custom "rebuildable" settlements as there are upgrade tiers reserved for the purpose in the mod. In DAC, we have 3 tiers reserved (Fortress, Citadel, Huge City) which means every faction can now have 3 custom upgradable settlements on the map and for the performance price of a single turn end monitor (whereas previously, all three tiers were reserved for only a couple factions and 3 settlements).

  9. #9

    Default Re: Single Building Available in Multiple Regions

    @Gebilde - Gigantus does the same thing with counting turns until the building is supposed to have been completed and then he enables it again. He also came to the same realization about needing an EDB counter and an internal (queue) counter. And his script suffers the same problem with adding the building at the end of the queue or having the settlement sieged which will allow multiple buildings to be started but the second one will never be finished. The scripts are almost identical except that the one in this thread uses only 1 turn start and 1 turn end monitor whereas his uses 2 turn start and 2 turn end monitors so the performance here is theoretically a bit better assuming everything works.

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

    Default Re: Single Building Available in Multiple Regions

    So this one...

    Code:
        monitor_event SettlementSelected TrueCondition                        ;this is the critical monitor that 'pairs' the two event counters
            if I_EventCounter firstaddtoqueue == 1
                set_event_counter building_available 0
            end_if
        end_monitor
    ...is for the situation where you add the building to the queue in settlement A and then select settlement B without closing the construction scroll in between. The 'switch' as you put it. Forcing the scroll to show the change in construction rules.

    By the sounds of things this works. But does it still work without this monitor? Seems to me it would make no difference because building_available is already 0 at the switch time, so all you're doing is setting it to the value that it already is. Might it be the case that it is not this monitor that is solving the switch problem, rather it's the re-select settlement script from the other thread? If so then this monitor is superfluous. On the other hand, if that re-select settlement script is definitely not the solver here, and it definitely is this monitor, then it would appear that solving the switch problem could be achieved with script that is a lot simpler than that settlement re-select trick.

Posting Permissions

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