Results 1 to 13 of 13

Thread: generate_random_counter

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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 generate_random_counter

    I finally got around to playing with some of the new script commands, I think I am going to like the random counter, real random decision trees are now possible.

    monitor_event FactionTurnEnd FactionIsLocal
    generate_random_counter random_money 1 5
    if I_EventCounter random_money = 1
    add_money england 1000
    end_if

    if I_EventCounter random_money = 2
    add_money england 2000
    end_if

    if I_EventCounter random_money = 3
    add_money england 3000
    end_if

    if I_EventCounter random_money = 4
    add_money england 4000
    end_if

    if I_EventCounter random_money = 5
    add_money england 5000
    end_if
    end_monitor


    The destroy_buildings command is disappointing though, you can only detroy buildings faction wide, you cant select individual settlements.

  2. #2
    alpaca's Avatar Harbinger of saliva
    Join Date
    Sep 2005
    Location
    Germany
    Posts
    4,811

    Default Re: generate_random_counter

    You could simulate the same behavior using RandomPercent and a bit of maths

    And RandomPercent doesn't merely allow you to use a uniform distribution, either which is often definitely not what you want.

    I'd book it under the rubric "nice to have but not juicy enough to switch" like most of the new commands.

    No thing is everything. Every thing is nothing.

  3. #3
    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: generate_random_counter

    The problem with RandomPercent is that once you call it, you cant reference it again.

  4. #4
    alpaca's Avatar Harbinger of saliva
    Join Date
    Sep 2005
    Location
    Germany
    Posts
    4,811

    Default Re: generate_random_counter

    Quote Originally Posted by GrnEyedDvl View Post
    The problem with RandomPercent is that once you call it, you cant reference it again.
    Consider this uniform distribution between three values (which is a custom random counter command):

    Code:
    declare_counter random_counter
    declare_counter fallthrough
    
    if RandomPercent < 33
    set_counter random_counter 1
    set_counter fallthrough 1
    end_if
    
    if RandomPercent < 50
    and I_CompareCounter fallthrough == 0
    set_counter random_counter 2
    set_counter fallthrough 1
    end_if
    
    if I_CompareCounter fallthrough == 0
    set_counter random_counter 3
    end_if
    Of course if you have a large number of possible random values, the random_counter command is much more comfortable.
    Last edited by alpaca; October 07, 2007 at 11:35 AM.

    No thing is everything. Every thing is nothing.

  5. #5
    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: generate_random_counter

    I have done something similar, but thats 14 lines of code and 2 counters just to generate the number, then you have to code all the choices as well. Lets take the add_money example and compare the way you had to do it in vanilla M2 and the way you can do it in Kingdoms. I will use 3 choices, 5, 10, and 20 thousand added to treasury.


    Vanilla example
    Code:
    declare_counter random_counter
    declare_counter fallthrough
    
    monitor_event FactionTurnEnd FactionType england
    if RandomPercent < 33
    set_counter random_counter 1
    set_counter fallthrough 1
    end_if
    
    if RandomPercent < 50
    and I_CompareCounter fallthrough == 0
    set_counter random_counter 2
    set_counter fallthrough 1
    end_if
    
    if I_CompareCounter fallthrough == 0
    set_counter random_counter 3
    end_if
    
    if random_counter = 1
    console_command add_money england, 5000
    end_if
    
    if random_counter = 2
    console_command add_money england, 10000
    end if
    
    if random_counter 3
    console_command add_money england, 20000
    end_if
    end_monitor
    Kingdoms example
    Code:
    monitor_event FactionTurnEnd FactionType england
    
    generate_random_counter random_money 1 3
    
    if I_EventCounter random_money = 1
    add_money england 5000
    end_if
    
    if I_EventCounter random_money = 2
    add_money england 10000
    end_if
    
    if I_EventCounter random_money = 3
    add_money england 20000
    end_if
    end_monitor
    In the vanilla example there are 25 lines of code (not counting empty lines) in the Kingdoms example there are 12. Multiply that by 31 factions.

    25 x 31 = 775 M2TW
    12 x 31 = 372 Kingdoms

    If you are doing something for every settlement instead of every faction it gets worse, consider 199 settlements.

    25 x 199 = 4975 M2TW
    12 x 199 = 2388 Kingdoms

    To add another choice to the M2TW version you have to add 8 lines of code, 3 for the new choice and 5 to generate the new number. To add another line to the Kingdoms version you have to change one number in the generate_random_counter line and add 3 lines of code.

    For all factions
    (25 + 8) x 31 = 1023 M2TW
    (12 + 3) x 31 = 465 Kingdoms

    For 199 settlements
    (25 + 8) x 199 = 6567 M2TW
    (12 + 3) x 199 = 2985 Kingdoms

    For 10 choices it gets absurd.
    (25 + (8 x 7) x 31 = 43000 M2TW
    (25 + (3 x 7) x 31 = 16275 Kingdoms

    (25 + (8 x 7) x 199 = 278600 M2TW
    (25 + (3 x 7) x 199 = 104475 Kingdoms

    Plus the commands are longer in M2
    console_command add_money england, 20000 = M2TW
    add_money england 20000 = Kingdoms

    If you wanted to use an uneven distribution as in in your example above where the botton 50% is split into two options and the top 50% is one block then you just give the same command to two choices.

    if counter = 1 then this
    if counter = 2 then that
    if counter = 3 then other
    if counter = 4 then other
    if counter = 5 then another
    if counter = 6 then another

    I would rather spend time coding the choices than coding both choices and generating the number.

  6. #6
    alpaca's Avatar Harbinger of saliva
    Join Date
    Sep 2005
    Location
    Germany
    Posts
    4,811

    Default Re: generate_random_counter

    Well if you don't need to access it later you can put the effect right into the same if as the random generation.

    Anyways, you're right, the command has its uses. I'm just ranting about how little actual new stuff they gave us in Kingdoms

    No thing is everything. Every thing is nothing.

  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: generate_random_counter

    lol yeah I wish they had more too, the destroy_buildings and units I am really disappointed with

    The increment_kings_purse is useful, as is random_name, the rest I havent tried much. Maybe there are more commands they added that arent in the new campaign_scripts or descr_strats. We need a new official docudemons.

  8. #8
    alpaca's Avatar Harbinger of saliva
    Join Date
    Sep 2005
    Location
    Germany
    Posts
    4,811

    Default Re: generate_random_counter

    Quote Originally Posted by GrnEyedDvl View Post
    lol yeah I wish they had more too, the destroy_buildings and units I am really disappointed with

    The increment_kings_purse is useful, as is random_name, the rest I havent tried much. Maybe there are more commands they added that arent in the new campaign_scripts or descr_strats. We need a new official docudemons.
    Yeah, Caliban told me Scott (the coder who so far provided it for us) is still on leave but he promised to try and put some programmer through the wrangler to execute the docudemon code

    No thing is everything. Every thing is nothing.

  9. #9

    Default Re: generate_random_counter

    Quote Originally Posted by GrnEyedDvl View Post
    lol yeah I wish they had more too, the destroy_buildings and units I am really disappointed with
    are you taking about the fact you have to use a label to dispose of the units?

    edit: actually i have just realized this is an old post thats what you get for following links.
    Last edited by J@mes; September 08, 2008 at 04:30 PM.


  10. #10
    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: generate_random_counter

    Cool, see if you can get a good list of console commands out of him too while you are at it lol

  11. #11
    Opifex
    Join Date
    Feb 2005
    Location
    New York, USA
    Posts
    15,154

    Default Re: generate_random_counter

    You two grumpy grumpers (alpaca and GED). I love the fact that characters can have labels and be referenced that way instead of through names. In fact this allows you to create 'types' of characters so that you can, say, affect only those generals which have a certain label (and with their name being completely irrelevant). This pushes Kingdoms scripting into a whole new field.


    "If ye love wealth greater than liberty,
    the tranquility of servitude greater than
    the animating contest for freedom, go
    home from us in peace. We seek not
    your counsel, nor your arms. Crouch
    down and lick the hand that feeds you,
    and may posterity forget that ye were
    our countrymen."
    -Samuel Adams

  12. #12

    Default Re: generate_random_counter

    Quote Originally Posted by SigniferOne View Post
    You two grumpy grumpers (alpaca and GED). I love the fact that characters can have labels and be referenced that way instead of through names. In fact this allows you to create 'types' of characters so that you can, say, affect only those generals which have a certain label (and with their name being completely irrelevant). This pushes Kingdoms scripting into a whole new field.
    yes its good that we can bump spawned characters right out of the backdoor on the next turn.


  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: generate_random_counter

    Alpaca and I are grumpy?? lol

Posting Permissions

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