side switching

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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
Limabean
Posts: 350
Joined: August 26th, 2008, 2:14 pm
Location: New Hampshire, USA

side switching

Post by Limabean »

I'm having a problem with my campaign. In the first few scenarios the player plays using a particular side and leader. Then, for a few scenarios, the leader switches and the player controls a different leader with different recruits, recalls, etc.
Now, in my next scenario, I want the player to be able to use the original leader again with all the recallable units he/she gained in the scenarios before the first leader switch. I've tried using save_id but it doesn't seem to make a difference. The player just has an un-leveled leader and no units available to recall like it's a brand new side.
I just can't figure it out. Hopefully you guys can help. :)

Here's the [side] code for each of the relevent scenarios:

the first two:

Code: Select all

[side]
    type=Raid Captain
    description=Gashnu
    user_description= _ "Gashnu"
    unrenamable=yes
    profile=portraits/Gashnu.png
    side=1
    canrecruit=yes
    controller=human
    recruit= Wolf Rider
    enemy=2,3
    persistent=1
    save_id=Gashnu
    gold=100
    fog=yes
    facing=ne
[/side]
-----------------------------------------
[side]
    type=Raid Captain
    description=Gashnu
    user_description= _ "Gashnu"
    unrenamable=yes
    profile=portraits/Gashnu.png
    team_name=Orcs
    side=1
    canrecruit=yes
    controller=human
    recruit= Wolf Rider, Goblin Spearman
    enemy=2
    gold=150
    persistent=1
    save_id=Gashnu
    fog=no
    village_gold=1
[/side]
and the one i'm working on:

Code: Select all

[side]
    type=Raid Captain
    description=Gashnu
    user_description= _ "Gashnu"
    unrenamable=yes
    profile=portraits/Gashnu.png
    team_name=Orcs
    side=1
    canrecruit=yes
    controller=human
    persistent=1
    save_id=Gashnu
    recruit=Wolf Rider, Goblin Spearman, Orcish Grunt, Orcish Archer, Orcish Assassin
    gold=150
    fog=no
    shroud=yes
    village_gold=1
[/side]
Thanks
When a scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
-Arthur C. Clarke-
Max
Posts: 1449
Joined: April 13th, 2008, 12:41 am

Re: side switching

Post by Max »

User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: side switching

Post by Sapient »

the words "bug report?" come to mind...
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
Limabean
Posts: 350
Joined: August 26th, 2008, 2:14 pm
Location: New Hampshire, USA

Re: side switching

Post by Limabean »

Max2008 wrote:hope this helps:
http://www.wesnoth.org/wiki/SideSwitchingWML
No, sorry. Thats actually one of the first places I went when I had the problem. I havn't used save_ids before this and added them after reading that.
Sapient wrote:the words "bug report?" come to mind...
So, my code checks out and that should work? I had kind of ruled out the bug possibility because i'm using the stable version.
When a scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
-Arthur C. Clarke-
opensourcejunkie
Posts: 547
Joined: August 11th, 2008, 3:19 pm

Re: side switching

Post by opensourcejunkie »

Limabean wrote:I had kind of ruled out the bug possibility because i'm using the stable version.
Hah! Funny...

I've been messing around with a few persistent sides myself, and I might have a foggy grasp on what's going on.

If you assign a side to a specific save_id, that seems to work. However, if you opt not to use that save_id in a later scenario, the wesnoth engine seems to still tie it to whatever side it was on before. For example, if in scenario 1, side 1 uses the save_id "foo", and in scenario 2, side 1 is just a normal side, all of the units from the previous scenario will still be available for recall. That's been my experience so far.

Now to throw a stab in the dark at your problem, I'm guessing that when you tied a new save_id to side 1 (when you switched to a new leader/army), it overwrote, knocked out, or overshadows the original save_id, Gashnu. Any units you had were removed (you may want to confirm/disprove this with your save file), including the old leader, and your side 1 default leader is used instead.

I have no idea if any of that is accurate, but it's my best appraisal of the situation. If you decide to put in a bug report, let me know so I can follow it.
--OSJ

P.S. I'm working on a macro set to use as a workaround. If you like, I'll post it here when it's finished.
what if the Bible's claims about Christ depicted accurate, verifiable history? given some research, you might be surprised at the evidence...
opensourcejunkie
Posts: 547
Joined: August 11th, 2008, 3:19 pm

Re: side switching

Post by opensourcejunkie »

Here're the two macros I wrote:

Code: Select all

#define SOL_PACKAGE_SIDE SIDE VAR
    ##:: Store Leader
    [store_unit]
        [filter]
            side={SIDE}
            canrecruit=yes
        [/filter]
        kill=yes
        variable={VAR}.leader
    [/store_unit]
    
    ##:: Store Other Units
    [store_unit]
        [filter]
            side={SIDE}
        [/filter]
        kill=yes
        variable={VAR}.units
    [/store_unit]
    
    ##:: Store Side Stats
    [store_side]
        variable={VAR}.stats
    [/store_side]
#enddef

#define SOL_UNPACKAGE_SIDE SIDE VAR
    ##:: Remove Default Leader (if available)
    [if]
        [have_unit]
            side={SIDE}
            canrecruit=yes
        [/have_unit]
        [then]
            ## store/kill default leader
            [store_unit]
                [filter]
                    side={SIDE}
                    canrecruit=yes
                [/filter]
                variable=SOL_UNPACKAGE_SIDE_leader
                kill=yes
            [/store_unit]
            
            ## grab coordinates
            {VARIABLE {VAR}.leader.x $SOL_UNPACKAGE_SIDE_leader.x}
            {VARIABLE {VAR}.leader.y $SOL_UNPACKAGE_SIDE_leader.y}
        [/then]
    [/if]
    
    ##:: Unstore Leader
    {VARIABLE {VAR}.leader.side {SIDE}}
    [unstore_unit]
        variable={VAR}.leader
        find_vacant=yes
    [/unstore_unit]
    
    ##:: Unstore Other Units
    {FOREACH {VAR}.units SOL_UNPACKAGE_SIDE_i}
        {VARIABLE {VAR}.units[$SOL_UNPACKAGE_SIDE_i].side {SIDE}}
        {VARIABLE {VAR}.units[$SOL_UNPACKAGE_SIDE_i].x recall}
        {VARIABLE {VAR}.units[$SOL_UNPACKAGE_SIDE_i].y recall}
        [unstore_unit]
            variable={VAR}.units[$SOL_UNPACKAGE_SIDE_i]
            find_vacant=yes
        [/unstore_unit]
    {NEXT SOL_UNPACKAGE_SIDE_i}
    
    ##:: Set Gold
    [modify_side]
        side={SIDE}
        gold=${VAR}.stats.gold
    [/modify_side]
    
    ##:: Clear Variables
    {CLEAR_VARIABLE SOL_UNPACKAGE_SIDE_leader}
    {CLEAR_VARIABLE SOL_UNPACKAGE_SIDE_i} # just in case NEXT doesn't do it
    {CLEAR_VARIABLE {VAR}}
#enddef
The first macro, SOL_PACKAGE_SIDE, is used to bundle all of a side's data into one variable. It takes two arguments - the side being packaged, and the variable that will hold it.

The second macro, SOL_UNPACKAGE_SIDE replaces the default leader (if there is one) with the stored leader, places the stored units on the recall list, and sets the gold to that in the scenario previous (you may need to add in gold for the scenario bonus; that isn't factored in here)

SOL_UNPACKAGE_SIDE takes two arguments, SIDE and VAR. VAR should be a variable stored via SOL_PACKAGE_SIDE. SIDE refers to the side that the units will be unpacked on, not to the side they come from. This allows a smooth switch from side 1 to side 3, if such a switch is required.

Hope someone can use this :-)
--OSJ
Attachments
utils-side.cfg
(2.04 KiB) Downloaded 248 times
what if the Bible's claims about Christ depicted accurate, verifiable history? given some research, you might be surprised at the evidence...
User avatar
Limabean
Posts: 350
Joined: August 26th, 2008, 2:14 pm
Location: New Hampshire, USA

Re: side switching

Post by Limabean »

lol, I'll certainly be re-reading your posts a few times :lol2:
I'm still a noobish coder and don't even know how to use macros (I know, it's sad :cry:). This does seem like you're on the right track though so I will certainly be trying to figure them out. Thanks for the help. :D
When a scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
-Arthur C. Clarke-
Post Reply