I need to get a list of all sides not allied to the player

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
User avatar
Kapoue_II
Posts: 203
Joined: October 11th, 2010, 9:41 am

I need to get a list of all sides not allied to the player

Post by Kapoue_II »

For my era, I have a bunch of slaves. Like in DiD, I'm going to give each slave a 1-50 chance of rebelling each turn. For this , I need an extra side........... but because its for an entire era, not a scenario, I can't just have a spare side kicking around, because I don't know how many sides the scenario will have. Is there a way around this?
Last edited by Kapoue_II on December 12th, 2010, 5:53 pm, edited 1 time in total.
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: I need to create a ai controlled side..for an era.

Post by Anonymissimus »

At least with lua you can get the number of sides ([lua]code=<<local sides = #wesnoth.sides>>[/lua]). No idea how useful this is for you since I'm a noob concerning eras and multiplayer wml :P. For a normal scenario I know that it's not possible to add sides afterwards (that is, in an event).
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
Kapoue_II
Posts: 203
Joined: October 11th, 2010, 9:41 am

Re: I need to create a ai controlled side..for an era.

Post by Kapoue_II »

Anonymissimus wrote:At least with lua you can get the number of sides ([lua]code=<<local sides = #wesnoth.sides>>[/lua]). No idea how useful this is for you since I'm a noob concerning eras and multiplayer wml :P. For a normal scenario I know that it's not possible to add sides afterwards (that is, in an event).
Thanks. I will take that as meaning it is impossible :(. The next best thing is to make the slaves defect to the enemy team. What code would I need to make them automatically join an enemy team?
Brilliand
Posts: 80
Joined: July 11th, 2009, 12:15 am

Re: I need to create a ai controlled side..for an era.

Post by Brilliand »

Get a list of sides that are not allied with the current side (using a loop that goes through all of the sides), then use that as the input to a random number generator:

Code: Select all

    [set_variable]
        name=unit.side
        rand=$nonally_list
    [/set_variable]
Then unstore the unit to set it to that side. You should probably add a failsafe in case there are no nonallied sides fro some reason... I guess you could just kill the unit if the player is doing some special MP scenario with no enemies.
You are a Dark Adept: you dimmerse yourself in the dark arts...potentially with great rewards....
-JW's personality quiz
User avatar
Kapoue_II
Posts: 203
Joined: October 11th, 2010, 9:41 am

Re: I need to create a ai controlled side..for an era.

Post by Kapoue_II »

How do I get the list? I can handle the rest of the code, but I have no idea how to get the sides, except using Annonysimus's Lua code-and I have no comprehention of lua, (yet) so I hesitate to use it.
User avatar
Pentarctagon
Project Manager
Posts: 5564
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: I need to create a ai controlled side..for an era.

Post by Pentarctagon »

you could use store_unit with canrecruit=yes in the filter to get all the leaders, then use store_side to compare team names to see if they are allied or not.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
User avatar
Kapoue_II
Posts: 203
Joined: October 11th, 2010, 9:41 am

Re: I need to create a ai controlled side..for an era.

Post by Kapoue_II »

That I knew. What I need to know is how to compare the lists. Can I stick a "[not]" tag in the [store_side]? (So that it stores all the sides who are not allied)

EDIT: This is the code I have for storing the sides, after I have stored their leaders:

Code: Select all

 {FOREACH leaders num}
                     [set_variable]
                       name=loop
                       add=1
                     [/set_variable]
                     [store_side]
                      side=$leaders.$loop.side
                      variable=sides
                     [/store_side]
                    {NEXT num}
Am I allowed the line that says $leaders (the variable the side leaders are in) .$loop (num is the variable that keeps track of what number loop I'm on-and subsequently, how many are stored in the variable).side
Brilliand
Posts: 80
Joined: July 11th, 2009, 12:15 am

Re: I need to create a ai controlled side..for an era.

Post by Brilliand »

Kapoue_II wrote:That I knew. What I need to know is how to compare the lists. Can I stick a "[not]" tag in the [store_side]? (So that it stores all the sides who are not allied)

EDIT: This is the code I have for storing the sides, after I have stored their leaders:

Code: Select all

 {FOREACH leaders num}
                     [set_variable]
                       name=loop
                       add=1
                     [/set_variable]
                     [store_side]
                      side=$leaders.$loop.side
                      variable=sides
                     [/store_side]
                    {NEXT num}
Am I allowed the line that says $leaders (the variable the side leaders are in) .$loop (num is the variable that keeps track of what number loop I'm on-and subsequently, how many are stored in the variable).side
I recommend this:

Code: Select all

{FOREACH leaders num}
    [store_side]
        side=leaders[$num].side
        variable=temp_side
    [/store_side]
    [if]
        [variable]
            name=temp_side.team_name
            not_equals=$current_team_name
        [/variable]
        [then]
            [set_variables]
                name=enemy_list
                mode=append
                [value]
                    n=leaders[$num].side
                [/value]
            [/set_variables]
        [/then]
    [/if]
{NEXT num}
[set_variable]
    name=enemy_list
    [join]
        variable=enemy_list
        key=n
        separator=,
    [/join]
[/set_variable]
[set_variable]
    name=unit.side
    rand=$enemy_list
[/set_variable]
You are a Dark Adept: you dimmerse yourself in the dark arts...potentially with great rewards....
-JW's personality quiz
Post Reply