Results 1 to 13 of 13

Thread: Comparing the values of multiple counters to find the higher value.

Hybrid View

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

    Default Comparing the values of multiple counters to find the higher value.

    I would like to know if it is at all achievable to compare the values of multiple counters to find the higher value.

    This is the visual representation of what i want to get;
    The numbers represent the counter value, then each turn the inc_counter value.

    Turn ___1__2__3__4__5
    counter1 0 +1 +3 +4 +2
    counter2 1 +3 +4 +0 +1
    counter3 0 +6 +0 +1 +0

    Winner
    1 counter2 (1)
    2 counter3 (6)
    3 counter2 (8)
    4 none (equal 8)
    5 counter1 (10)

    I want to find a way to compare the counters to ascertain the highest each turn.

    Can anybody provide a solution? or think of a viable alternative?
    I am unable to imagine this working at all in M2TW...

  2. #2
    konny's Avatar Artifex
    Join Date
    Jul 2007
    Location
    Germania Inferior
    Posts
    3,631

    Default Re: Comparing the values of multiple counters to find the higher value.

    That looks very complicated because you wish to compare counters to each others, not counters to values. The only way I could think of would be to write if-statements for all possible combinations:

    if counter_1 = 0
    --> counter_1 winner

    if counter_1 = 1
    and counter_2 > 1
    and counter_3 > 1
    --> counter_1 winner

    if counter_1 = 2
    and counter_2 > 2
    and counter_3 > 2
    --> counter_1 winner

    if counter_1 = 3
    and counter_2 > 3
    and counter_3 > 3
    --> counter_1 winner

    and so on.

    or think of a viable alternative?
    It would be helpfull to know what you trying to do with this.

    Team member of: Das Heilige Römische Reich, Europa Barbarorum, Europa Barbarorum II, East of Rome
    Modding help by Konny: Excel Traitgenerator, Setting Heirs to your preference
    dHRR 0.8 beta released! get it here
    New: Native America! A mini-mod for Kingdoms America

  3. #3

    Default Re: Comparing the values of multiple counters to find the higher value.

    I am trying to write events that show who has the Naval superiority, points are added for winning battles and building navies, ect.
    So the counter values could be up in the 100's late game.
    Thought about deducting points for loosing and all that to keep the score down, but there aren't many ways to script ways to that..

    I appreciate your idea, but that is the basic idea i was going to do until i realised how many lines of code that would require...

    I was hoping there was a way to do something like this;
    I_CompareCounters counter1 < counter2 true

    or something similar..

    Is there anything other than counters i can use to check who has the most superior naval force?

  4. #4
    konny's Avatar Artifex
    Join Date
    Jul 2007
    Location
    Germania Inferior
    Posts
    3,631

    Default Re: Comparing the values of multiple counters to find the higher value.

    Quote Originally Posted by Archaon View Post
    I am trying to write events that show who has the Naval superiority, points are added for winning battles and building navies, ect.
    So the counter values could be up in the 100's late game.
    Thought about deducting points for loosing and all that to keep the score down, but there aren't many ways to script ways to that..
    No, you would indeed need counters that count ships built, naval battles fought, ships lost (how?).

    May be something with guilds could be possible? But that would be absolut: who ever builts "naval_superiority" (= the HQ) first would keep it until someone conquers this town.
    I was hoping there was a way to do something like this;
    I_CompareCounters counter1 < counter2 true

    or something similar..
    Nope, only I_CompareCounter counter1 < 3 and stuff like that. To compare it to other counters you would need the above "ifs"

    Is there anything other than counters i can use to check who has the most superior naval force?
    Not for naval, only for military like:
    FactionScoreRank military < 3

    (Scores include: overall, military, production, regions, treasury, population)

    Team member of: Das Heilige Römische Reich, Europa Barbarorum, Europa Barbarorum II, East of Rome
    Modding help by Konny: Excel Traitgenerator, Setting Heirs to your preference
    dHRR 0.8 beta released! get it here
    New: Native America! A mini-mod for Kingdoms America

  5. #5

    Default Re: Comparing the values of multiple counters to find the higher value.

    I am pretty certain konny's approach with comparing each combination of counters is the only possible way.

    But what you could do to cut down dramatically on the number of counter combinations required is set 'levels' that a faction would reach (or drop to). Example, every time a faction recruits a naval ship increase that factions naval counter by 1 (and so forth for winning naval battles or whatever and decrease when losing battles etc as u have suggested), and then when you are comparing FactionA with FactionB you compare in quantities of 10 (plus or minus). so if a faction has 27 naval points they would fall into level 3 (between 21-30). Reaching 31 pushes them into the next level... A faction with 22 points and another with 29 would fall in the same level and be considered naval equals.

    If you think a faction might get into the hundreds then change the levels to 20 or 30 points. That would save on comparing every combination as u would only be comparing stages but each faction would still be aquiring these points as you originally intended...

    Below gives u an idea of what i mean, you would ofcourse use proper commands from docudemons...

    Repeat for each faction...

    declare_counter FactionA_Naval_Counter
    declare_counter FactionA_Naval_Rank

    shipConstructed
    inc_counter FactionA_Naval_Counter 1

    monitor_event FactionTurnStart FactionType FactionA
    if I_CompareCounter FactionA_Naval_Counter < 11
    set_counter FactionA_Naval_Rank 0
    end_if

    if I_CompareCounter FactionA_Naval_Counter > 10
    and I_CompareCounter FactionA_Naval_Counter < 21
    set_counter FactionA_Naval_Rank 1
    end_if

    if I_CompareCounter FactionA_Naval_Counter > 20
    and I_CompareCounter FactionA_Naval_Counter < 31
    set_counter FactionA_Naval_Rank 2
    end_if

    etc...
    end_monitor

    then compare naval rank counters to find who has the highest rank...

    In essence, this approach would just be reducing the times you would need to compare...

    The number of factions would determine the length of the script... but possibly some factions will never likely be naval leaders so you could even dismiss them from the script altogether...
    ...longbows, in skilled hands, could reach further than trebuchets...

  6. #6

    Default Re: Comparing the values of multiple counters to find the higher value.

    Thank you both, i think i'll be needing to labor away at this using counters after all.

    Though Tsarsies, i will consider using the 'rank' system in 10's as you suggest, although there are more counters invovled the comparing of two counters will be minimal thus less code overall - thanks!

    If anyone comes accross this and has an idea, please do not hesitate to post!

  7. #7
    GrnEyedDvl's Avatar Liberalism is a Socially Transmitted Disease
    Artifex Technical Staff

    Join Date
    Jan 2007
    Location
    Denver CO
    Posts
    23,851
    Blog Entries
    10

    Default Re: Comparing the values of multiple counters to find the higher value.

    I rarely post here anymore but I will jump in on this one.

    What is the end goal here, ie what are you actually doing with the information once you have established what counter/faction is the highest?

    I imagine you could do this easier with a faction leader trait that moves up and down.

  8. #8

    Default Re: Comparing the values of multiple counters to find the higher value.

    Quote Originally Posted by GrnEyedDvl View Post
    I rarely post here anymore but I will jump in on this one.

    What is the end goal here, ie what are you actually doing with the information once you have established what counter/faction is the highest?

    I imagine you could do this easier with a faction leader trait that moves up and down.
    Since there was no system to score the naval power of a faction, i am trying to create one.

    I will have an event counter for each faction that will be set to 1 for the highest scoring faction and all other factions counters set to 0.
    The event counter will be used in many ways, of which you would be well aware of.

    To keep it simple, my end result is to have one faction at a time with the highest score and if another faction takes the lead the previous factions counter will be set to 0 and the new leading faction factions counter set to 1.

    An event will also be launched to inform the player whenever a new naval leader is set.

    All the coding and scripts are ready, i'm simply needing to explore how to now 'compare' them to ascertain who the leader is each slave turn end.

    I am not looking to have a million range checks that run each turn, that is an infinite amount of if statements in monitors for each game turn..

  9. #9
    GrnEyedDvl's Avatar Liberalism is a Socially Transmitted Disease
    Artifex Technical Staff

    Join Date
    Jan 2007
    Location
    Denver CO
    Posts
    23,851
    Blog Entries
    10

    Default Re: Comparing the values of multiple counters to find the higher value.

    Sorry I havent responded until now. I have been really busy.

    Other than popping an event that declares who the new leader is, what will be the effect in game. Are you looking to give bonuses or money to a faction? I guess I am not understanding the purpose here, which is why I asked:

    What is the end goal here, ie what are you actually doing with the information once you have established what counter/faction is the highest?
    If all you are using this for is eye candy then I guess I dont see the point. If you are trying to do something else then there may be an easier/better way to do it. But I need to know what that "something else" is before I can put any ideas out there.

  10. #10

    Default Re: Comparing the values of multiple counters to find the higher value.

    the leader will have an event exported for use in EDB and descr_merc, as well as scripted trading events (that will be in effect for all already but bonuses adjusted dependant on the leader).

    As i explained.

    I have all the coding done, ready, working, i simply need a way to compare multiple counters values to ascertain the highest value each turn.


    EDIT:

    Sorry for the vaugeness, i am trying not to give away certain details of the features as i've noticed several members stalking my posts whom i'd prefer not to know what im doing for the mod until its done...

    i.e. im not posting the script

  11. #11
    GrnEyedDvl's Avatar Liberalism is a Socially Transmitted Disease
    Artifex Technical Staff

    Join Date
    Jan 2007
    Location
    Denver CO
    Posts
    23,851
    Blog Entries
    10

    Default Re: Comparing the values of multiple counters to find the higher value.

    lol no worries about secrecy, I completely understand. If I need to see the script I will ask you to PM it to me and you could be assured it would go nowhere else.


    Has anyone actually tried testing a counter against another counter? I know I havent. I never had a reason to. I no longer have M2 installed or I would take a look at this.

    declare_counter CounterA
    declare_counter CounterB

    monitor_event FactionTurnEnd FactionIsLocal
    set_counter CounterA 1
    set_counter CounterB 10

    if I_CompareCounter CounterA > CounterB
    pop historical event
    end_monitor

    If that fails to work then you will have to build a fairly long script. The good news is that you can take a look at my banking script for something similar, and you can use my script replicator to build it.

  12. #12

    Default Re: Comparing the values of multiple counters to find the higher value.

    Quote Originally Posted by GrnEyedDvl View Post
    lol no worries about secrecy, I completely understand. If I need to see the script I will ask you to PM it to me and you could be assured it would go nowhere else.


    Has anyone actually tried testing a counter against another counter? I know I havent. I never had a reason to. I no longer have M2 installed or I would take a look at this.

    declare_counter CounterA
    declare_counter CounterB

    monitor_event FactionTurnEnd FactionIsLocal
    set_counter CounterA 1
    set_counter CounterB 10

    if I_CompareCounter CounterA > CounterB
    pop historical event
    end_monitor

    If that fails to work then you will have to build a fairly long script. The good news is that you can take a look at my banking script for something similar, and you can use my script replicator to build it.
    I tried the logic values to no avail, thus the frustration when i failed.

    I think the end result here will be the lengthy script, such as the one discussed earlier in this thread - that script replicator could be very useful.
    Does it work on VB or .net?
    Can you link me?

    Wouldn't have a Debian version would you nevermind.

    I'm too lazy to look for it if you wouldn't mind posting a link to it thanks a lot GeD as usual very helpful.

  13. #13
    GrnEyedDvl's Avatar Liberalism is a Socially Transmitted Disease
    Artifex Technical Staff

    Join Date
    Jan 2007
    Location
    Denver CO
    Posts
    23,851
    Blog Entries
    10

    Default Re: Comparing the values of multiple counters to find the higher value.

    Its a simple VB program.
    http://www.twcenter.net/forums/showthread.php?t=239062

    A Debian version? What the hell would I want to make one of those for? Obviously you have never seen Sim and I debate the value of Linux.

    Pretty much all of my stuff on modding M2 can be found here:
    http://www.twcenter.net/forums/showthread.php?t=176050

Posting Permissions

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