Results 1 to 11 of 11

Thread: Spawning into a full settlement

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 Spawning into a full settlement

    Ultimately what I'm trying to do is use create_unit to spawn a single unit into a settlement. This is working fine but if the settlement is full then nothing happens.

    So, two questions...

    1) Is there any way to test whether the settlement is full, or at least how many units it contains?

    I_NumberUnitsInSettlement looked promising but as far as I can see it only counts a particular (specified) unit type.

    There's also IsSettlementGarrisoned but it only indicates whether any troops are there, not how many.


    2) Is there any way to test whether a given tile is unoccupied?

    If the settlement is full then I was hoping to spawn the unit directly outside instead, in a an empty location.


    I have been looking into this for a while now and found a few good examples (including spawn_army) but they all seem to say something like "so long as the settlement/location is not full/occupied".

    Any help here would be much appreciated...

  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: Spawning into a full settlement

    Best would be to use a work around: spawn the unit next to settlement and then order it move to the tile co-ordinates of the settlement. Obviously doesn't work if the city is under siege.

    Or experiment with these two:

    Identifier: PercentageOfPopulationInGarrison
    Trigger requirements: settlement
    Parameters:
    Sample use: PercentageOfPopulationInGarrison > 35
    Description: Check the percentage of population that is currently in the garrison
    Battle or Strat: Strat
    Class: PERCENTAGE_OF_POPULATION_IN_GARRISON

    Identifier: GarrisonToPopulationRatio
    Trigger requirements: settlement Parameters:
    Sample use: GarrisonSettlementRatio > 0.35
    Description: Calculate the ratio of soldiers to civilians
    Battle or Strat: Strat
    Class: GARRISON_TO_POPULATION_RATIO










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

    Default Re: Spawning into a full settlement

    Good onya Gigantus, thanks for that.

    I gather then that the answer to both of my questions is "no". This seems a little odd to me given the number and nature of things that can be tested, but that's life. I did consider the Population options but I think that it could only truly work if all units had the same number of soldiers.

    I will try your workaround to see what happens when the city is already full.

    In the meantime I have been experimenting with spawn_army and think that I have stumbled across a solution...

    Code:
    spawn_army
    	faction turks
    	character	{captain name}, general, age 40, x 140, y 252
    	unit		{the unit I want} exp 0 armour 0 weapon_lvl 0
    end
    If the x/y is the city location then this spawns the unit outside on an empty tile, even if there is room in the city. Not quite what I was originally after - spawning in the city - but good enough.

    EDIT: the spawn-and-move doesn't work if the city is full. The unit just ends up standing on top of the city.

    On reflection, having the unit located outside of the city is actually better for what I need, so problem solved.
    Last edited by Withwnar; August 13, 2010 at 02:53 AM.

  4. #4

    Default Re: Spawning into a full settlement

    How likely is that that the settlement is going to be full? I just wonder if you're making things more difficult for yourself when most of the time a settlement won't have all its 20 slots taken up with units.
    Currently following these promising mods - Imperia Antiquitatis by Splenyi
    Traits, Talents, and Toadies
    by Hellbent
    Real Roman Reforms
    by Aodh Mor
    Unit Icons project
    by Bullgod
    Also recommended:
    City Sack, Liberation and Diplomatic Options
    by Dresden

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

    Default Re: Spawning into a full settlement

    Not very, I suppose, but possible. I wouldn't want to rely on hope or assumptions.

  6. #6

    Default Re: Spawning into a full settlement

    Quote Originally Posted by Withwnar View Post
    The unit just ends up standing on top of the city.

    On reflection, having the unit located outside of the city is actually better for what I need, so problem solved.
    Does this happens with a garrison script as well?
    I thought that when using a garrison script extra units will automatically be placed on the next pixel beside the city?
    Last edited by Ishan; August 13, 2010 at 06:17 AM.

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

    Default Re: Spawning into a full settlement

    I'm not sure exactly how the garrison script behaves but I was under the impression that they don't spill out of the city; it only 'adds enough' to fill the slots. Could be wrong of course.

  8. #8

    Default Re: Spawning into a full settlement

    @Withwnar
    Yes u are right it doesn't spills out the extra units out of the city it only fills the 20 units.

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

    Default Re: Spawning into a full settlement

    I just had a look at the script and it uses create_unit. Calling create_unit on a city that has 20 slots filled does nothing.

  10. #10
    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: Spawning into a full settlement

    Forgot to mention: you cannot spawn into a settlement, hence the appearance next to it when you use the spawn command in a script.

    And you obviously have to have a slot open in that settlement if you want to move a character into it or create units.










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

    Default Re: Spawning into a full settlement

    I was looking through my threads trying to find something else. I forgot about this one and I have a solution so I may as well mention it while I'm here...

    Code:
    if I_EventCounter test_free_slots == 1
    
      console_command create_unit Helms-Deep test_unit 1 0 0
      campaign_wait 0.1
      if I_NumberUnitsInSettlement Helms-Deep test_unit == 0
        set_event_counter test_free_slots_ok 0
      end_if
      if I_NumberUnitsInSettlement Helms-Deep test_unit == 1
        destroy_units milan test_unit
        campaign_wait 0.1
        set_event_counter test_free_slots_ok 1
      end_if
    end_if
    
    if I_EventCounter test_free_slots == 2
    
      console_command create_unit Helms-Deep test_unit 2 0 0
      campaign_wait 0.1
      if I_NumberUnitsInSettlement Helms-Deep test_unit == 0
        set_event_counter test_free_slots_ok 0
      end_if
      if I_NumberUnitsInSettlement Helms-Deep test_unit == 1
        destroy_units milan test_unit
        campaign_wait 0.1
        set_event_counter test_free_slots_ok 0
      end_if
      if I_NumberUnitsInSettlement Helms-Deep test_unit == 2
        destroy_units milan test_unit
        campaign_wait 0.1
        set_event_counter test_free_slots_ok 1
      end_if
    end_if
    This will test whether the "Helms-Deep" settlement has either one or two slots free: test_free_slots indicates whether to test for 1 or 2.

    The first section spawns 1 unit of test_unit into the settlement, tests that there is indeed 1 unit in there and then removes it. If the "has 1 unit" test failed then there must have been no room for it: a full garrison already.

    The second test is the same, spawning and testing for 2 units, but also handles the case where there was room for only 1 (removes that 1 unit).

    Obviously the unit used for the testing should not be one that can be in the campaign for this faction, because destroy_units will wipe them all out. And it can't have spaces in the Type name as I_NumberUnitsInSettlement doesn't work with those.

    I don't know if the campaign_waits are necessary. They are left over from something I was trying out when it wasn't working. The very next thing I was doing after this was spawning units into the settlement - that wasn't working and I thought that maybe the engine saw these test units as still there due to destroy_units not completed yet. So the waits gave it some breathing space between the destroys and the next spawns.

    test_free_slots_ok is set to be 1 for yes and 0 for no which can then be used as a condition for whatever.

    e.g.

    Code:
    if I_EventCounter test_free_slots == 2
      and I_EventCounter test_free_slots_ok == 1
    
      ;there are two slots free: do what you have to do
    end_if
    Why bother? If you only need to spawn some units into there and don't really care whether there was room for them (and therefore were indeed spawned) then this script is unnecessary.

    But if you need to know before you spawn anything 'real' into a settlement then this is one way to do it. And also for testing before trying to move a general into a settlement.

    ~~~~~~~~~~~~~~

    I also found that create_unit can cause problems. If it is used on a settlement that is already full then subsequent create_unit calls on that same settlement can fail, even if, later, the settlement is no longer fully garrisoned. As though it has left the "garrison full" test logic in a broken state for the rest of the campaign.

    However, "console_command create_unit" did not suffer from this problem. So I would suggest always using this one for spawning units into settlements.
    Last edited by Withwnar; February 11, 2012 at 02:45 AM.

Posting Permissions

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