Results 1 to 13 of 13

Thread: CS Is Processed Differently for Player and AI (solved)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default CS Is Processed Differently for Player and AI (solved)

    I have recently discovered quite a problem. I designed a routine in CS which works flawlessly for the player but for AI it does not work because (according to log and testing) the CS is processed differently for AI factions.

    Simplified version of what I am doing:


    ;;;;This is done for all factions and IDs range from 0 to 30. When settlement is captured the counter is set to the ID of faction that captured it.

    monitor_event GeneralCaptureSettlement FactionType {faction}
    set_counter settlement_taken {ID}
    end_monitor

    ;;;;This monitors the change of the above counter and then it does stuff.

    monitor_conditions I_CompareCounter settlement_taken < 31

    ;;;;Series of if checking what faction triggered the change and then do stuff to it.

    if I_CompareCounter settlement_taken = {ID}

    ;;;;I know there is no counter = counter, this is just simplification of lengthy procedure of translating one counter into another. It works, that is not the problem.

    (set_counter {settlement_ownership_counter} = settlement_taken)

    end_if

    end_monitor



    Now this works nicely for the player but for the AI the monitor_conditions is NOT triggered right after the change of the counter for some reason.

    Instead AI turn processes all GeneralCaptureSettlement events and assign correct values based on the factions but it does not trigger the monitor_conditions as well. That is wrong because I need to translate each change into another counter (for which I assumed one monitor_conditions should work). In practice when there are more than one settlement take per turn it takes the value of the last faction which took a settlement and applies it to all such events (ownership is wrong).


    Example:

    Faction 'england' (7) takes settlement A and the 'settlement_taken' counter is then changed to 7. It does not trigger the monitor_conditions however so the counter 'A_ownership' is not set to anything yet. In the same turn faction 'france' (8) takes settlement B and the 'settlement_taken' counter is overwritten and set to 8. Then, by the end of the turn, monitor_conditions finally triggers and set the ownership of both A and B to 8 (france) instead.


    I have no idea why it is happening like this but log says it does exactly happen like this. It shows several counter changes right after each other according to settlements being sieged out in that turn but only the last one actually triggers the monitor_conditions.

    Again, for player this works fine and monitor_conditions fires right after the counter changes after the settlement fell. But why it does not work the same for the AI??

    My question thus is how to possibly solve this? Employ campaign_wait or something? Am I missing something? This behaviour is completely idiotic and would not make sense in any programming language I know!

    Thanks in advance, this is a really hard nut to crack for me.


    Addendum, here is the excerpt from the log which clearly shows that the counter did change correctly but it did not trigger the monitor_conditions:

    Code:
    08:52:42.576 [game.script.trigger] [trace] Trigger <0052_T_Invaded_Settlement> fired
    08:52:42.576 [data.transgression] [info] Applied transgression TC_INVADED_SETTLEMENT from transgressor faction 1056D1E4 against faction 1056E5F2
    08:52:42.588 [game.script.exec] [trace] exec <set_counter> at line 3960 in mods/DotS/data/world/maps/campaign/imperial_campaign/campaign_script.txt
    08:52:42.588 [game.script.counter] [trace] counter <settlement_taken> = 8
    08:52:42.600 [game.script.trigger] [trace] Trigger <0052_T_Invaded_Settlement> fired
    08:52:42.600 [data.transgression] [info] Applied transgression TC_INVADED_SETTLEMENT from transgressor faction 10549DEC against faction 1056E5F2
    08:52:42.608 [game.script.exec] [trace] exec <set_counter> at line 3956 in mods/DotS/data/world/maps/campaign/imperial_campaign/campaign_script.txt
    08:52:42.608 [game.script.counter] [trace] counter <settlement_taken> = 7
    08:52:42.609 [game.script.trigger] [trace] Trigger <0052_T_Invaded_Settlement> fired
    08:52:42.609 [data.transgression] [info] Applied transgression TC_INVADED_SETTLEMENT from transgressor faction 1056D0CE against faction 1056E5F2
    08:52:42.646 [game.script.exec] [trace] exec <set_counter> at line 4000 in mods/DotS/data/world/maps/campaign/imperial_campaign/campaign_script.txt
    08:52:42.647 [game.script.counter] [trace] counter <settlement_taken> = 18
    Last edited by Resurrection; March 02, 2012 at 02:52 AM.

    Mod Leader, Mapper & Bohemian Researcher

  2. #2
    /|\/|\/|\/|\/|\/|\/
    Join Date
    Jun 2005
    Posts
    10,770

    Default Re: CS Is Processes Differently for Player and AI

    Can you explain what you are trying to achieve? If you want help scripting it then a description of what you want is going to be very useful.
    Last edited by Taiji; March 02, 2012 at 02:53 AM.

  3. #3

    Default Re: CS Is Processes Differently for Player and AI

    Quote Originally Posted by Taiji View Post
    I can see what you are doing but I can't work out what you want. Can you explain what you are trying to achieve?
    Basically I set up one counter per settlement:

    settlement_A
    settlement_B

    and give them at the start the values equalling the owners. So there are 31 factions and they have IDs from 0 to 30. If settlement A is rebels at the start it's 30 for example.

    When faction conquers a settlement I wish to change this ownership counter (so I can use it elsewhere). Say faction england (ID 7) conquers settlement A which was originally rebels (ID 30). When that happens I want the counter settlement_A to change to 7. But 30*199 combinations is way too many monitors so I am doing it via two variables (counters). Counter settlement_taken is by default 32 (= disabled). If a faction conquers a settlement it gets changed to that faction's ID. Then there is a monitor_conditions for this counter (settlement_taken) checking if it has changed and if it does it has routine to change the correct ownership counter to the correct value of settlement_taken counter.

    Problem is that while for player sieges this monitor_conditions fires properly and does what it is supposed to do (change ownership counter), for AI this does not happen at all. I don't know why but according to log it seems like all sieges being processes simultaneously meaning all 'monitor_event GeneralCaptureSettlement' fire at once and overwrites the settlement_taken counter in close succession without monitor_conditions being ever fired despite the counter change. It is proven by the excerpt from the log. For player there follows the monitor_conditions routine but for AI it does not.

    I have no idea why it behaves like this.

    Mod Leader, Mapper & Bohemian Researcher

  4. #4
    /|\/|\/|\/|\/|\/|\/
    Join Date
    Jun 2005
    Posts
    10,770

    Default Re: CS Is Processes Differently for Player and AI

    I'm hungover and that's too wordy

    So, did it say this "I want a script counter system that tracks which faction owns which settlement."?

  5. #5

    Default Re: CS Is Processes Differently for Player and AI

    Pretty much.

    Mod Leader, Mapper & Bohemian Researcher

  6. #6
    /|\/|\/|\/|\/|\/|\/
    Join Date
    Jun 2005
    Posts
    10,770

    Default Re: CS Is Processes Differently for Player and AI

    monitor_event SettlementTurnStart SettlementName blah
    and FactionType bleh
    set_counter blahbleh
    end_monitor

    5820 of those would cover 30 factions and 194 provinces (GED's script replicator FTW).

    Or is there some reason that this way of doing it is undesirable? (want it to change in real time during player turn?)

  7. #7

    Default Re: CS Is Processes Differently for Player and AI

    Quote Originally Posted by Taiji View Post
    Or is there some reason that this way of doing it is undesirable?
    Yes.

    This:

    (want it to change in real time during player turn?)
    :-) Also it has to be dynamic during AI turns as well.

    Mod Leader, Mapper & Bohemian Researcher

  8. #8
    /|\/|\/|\/|\/|\/|\/
    Join Date
    Jun 2005
    Posts
    10,770

    Default Re: CS Is Processes Differently for Player and AI

    OK, how about this one:

    monitor_conditions I_SettlementOwner blah = bleh
    and I_CompareCounter blahbleh == 0
    set_counter blahbleh 1
    end_monitor

    Check and see what 5820 of those does to turn time, especially when a load of settlements change hands.

    Might be OK though.
    Last edited by Taiji; March 02, 2012 at 03:18 AM.

  9. #9

    Default Re: CS Is Processes Differently for Player and AI

    Quote Originally Posted by Taiji View Post
    OK, how about this one:

    monitor_conditions I_SettlementOwner blah = bleh
    and I_CompareCounter blahbleh == 0
    set_counter blahbleh 1
    end_monitor

    Check and see what 5820 of those does to turn time, especially when a load of settlements change hands.

    Might be OK though.
    I tried this some time ago. Turn times are not a problem but actual running of the game is. 20 monitor_conditions produce noticeable lag. 70 makes the game run at 1-2 FPS. 5820 would likely create a black hole in place of CPU.

    I tried to squeeze the original GeneralCaptureSettlement events into one:

    monitor_event GeneralCaptureSettlement
    if FactionType england
    set_counter settlement_taken 8
    end_if
    if FactionType france
    set_counter settlement_taken 7
    end_if
    (...)
    end_monitor


    This does not work. The log says the 'faction' is not available which is very odd because the event does export it. I am trying to figure out alternatives to the construction so it would bypass this idiotic CS behaviour of processing all monitor_events of the same kind at once... Any ideas in that regard?

    Mod Leader, Mapper & Bohemian Researcher

  10. #10
    /|\/|\/|\/|\/|\/|\/
    Join Date
    Jun 2005
    Posts
    10,770

    Default Re: CS Is Processes Differently for Player and AI

    Yeah, always use an I_ condition in an if statement - Other conditions require exports from the event that will not be carried past 'if'.

    So I'd use I_SettlementOwner in the if, and FactionType or SettlementName as the event's condition:

    monitor_event GeneralCaptureSettlement SettlementName blah
    if I_SettlementOwner blah bleh
    set_counter blahbleh 1
    end_if
    (...)
    end_monitor

    194 of those, with 30 ifs each.

    And then the other events which track settlement owner changes...

    edit:

    CityRebels is all I can think of for now... 194 of those with no if statement.

    edit:

    I think maybe I prefer this approach:

    monitor_event GeneralCaptureSettlement SettlementName blah
    and FactionType bleh
    set_counter blahbleh 1
    set_counter blah<otherfactions> 0
    etc.
    end_monitor

    So 5820 of those...

    It seems that way the app does as little as possible each time it has to do something.
    Last edited by Taiji; March 02, 2012 at 04:36 AM.

  11. #11

    Default Re: CS Is Processed Differently for Player and AI

    Solved by the counter system and the use of I_FactionNearTile condition. Too long to show the full solution, PM me if interested.

    Thanks for help Taiji!

    Mod Leader, Mapper & Bohemian Researcher

  12. #12

    Default Re: CS Is Processed Differently for Player and AI (solved)

    just a late question about the condition you used ( because it could prove very efficient indeed for some scripts I am working on ) are you sure it doesn't activate with a spy ?

  13. #13

    Default Re: CS Is Processed Differently for Player and AI (solved)

    Quote Originally Posted by ilmrik View Post
    just a late question about the condition you used ( because it could prove very efficient indeed for some scripts I am working on ) are you sure it doesn't activate with a spy ?
    It does but:

    if I_FactionNearTile faction 0 x, y
    if I_CharacterTypeNearTile faction named_character, 0 x, y
    do same stuff
    end_if
    if I_CharacterTypeNearTile faction general, 0 x, y
    do same stuff
    end_if
    end_if


    It might be doubling the code some but it's efficient as the script size is irrelevant to actual performance. Number of checks is what matters and this would be just 199 base checks plust 2 sub-checks if parent check is true.

    I briefly considered:

    if I_FactionNearTile faction 0 x, y
    and not I_CharacterTypeNearTile faction named_character, 0 x, y
    do stuff
    end_if


    But this will not trigger if spy is present even if other character types are present because the secondary condition checks presence of the spy and not his presence if there are no other characters. Same goes for variant:

    if I_FactionNearTile faction 0 x, y
    if not I_CharacterTypeNearTile faction named_character, 0 x, y
    do stuff
    end_if
    end_if


    Even though the checks proceed inside the if it skips the internal if when spy is present.

    So I believe the original formula is the minimalist working one to check if there is garrison of given faction. Naturally you may switch the 'do same stuff' to counters and check change of that counter and then executes the commands there but unless you use just one particular command for all of them it wouldn't save much space and could possibly introduce other problems (timing of script execution is tricky because it is non-linear...).

    Mod Leader, Mapper & Bohemian Researcher

Posting Permissions

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