how to limit movement upgrade?

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
Swordy
Posts: 110
Joined: June 10th, 2005, 8:38 am

how to limit movement upgrade?

Post by Swordy »

i want to limit movement upgrade to 14.
thanks in advance, sapientx. hahaha
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Post by Sapient »

Well, I'm just going to type something off the top of my head here without testing it:

Code: Select all

[event]
 name=side turn

    [store_unit]
        [filter]
            side=$side_number
            canrecruit=1
        [/filter]
        kill=no
        variable=side_leader_store
    [/store_unit]
    {VARIABLE_OP current_movement format $side_leader_store.moves}
    {CLEAR_VARIABLE side_leader_store}
[/event]
Then whenever you are about to increase movement, first check that current_movement is less than the desired maximum.

Code: Select all

    [if]
        [variable]
            name=current_movement
            less_than=14
        [/variable]

# your code here

    [/if]
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Swordy
Posts: 110
Joined: June 10th, 2005, 8:38 am

Post by Swordy »

yay sapient it works :)
you only missed one thing...

Code: Select all

[object] 
silent=yes 
[effect] 
apply_to=movement 
increase=1 
[/effect] 
[/object] 
# this :)
{VARIABLE_OP current_movement add 1}
at first the codes you provided didn't work and i didn't know that that's what caused the problem. so i tried to use side_leader_store.moves instead of current_movement. i changed your code making it this way ...

Code: Select all

[event] 
name=side turn 
first_time_only=no
    {CLEAR_VARIABLE side_leader_store} 
    [store_unit] 
        [filter] 
            side=$side_number 
            canrecruit=1 
        [/filter] 
        kill=no 
        variable=side_leader_store 
    [/store_unit]  
[/event] 
and then for the movement upgrade option ...

Code: Select all

[if]
[variable] 
name=side_leader_store.moves 
less_than=14 
[/variable] 
# my code
[/if]
it works fine, so i let it be that way haha. thanks again :)
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Post by Sapient »

good point! I forgot to increment the counter.

Since the unit is moving after you stored it into a variable, the stored variable still has the correct # moves. That is an interesting way to do it, too.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Swordy
Posts: 110
Joined: June 10th, 2005, 8:38 am

Post by Swordy »

it actually only worked on the first turn -_-
help ¬¬
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Post by Sapient »

Right. I was afraid that might happen. The problem is that side turn events fire before moves are restored from the last turn. So, to work around this you can store a variable for each side at the beginning of the game, and restore it each turn.

Like so:

Code: Select all

[event] 
 name=side turn 
 first_time_only=no 
 {VARIABLE_OP movement_var format "stored_movement$side_number"}
 [if]
  [variable]
  name=$movement_var
  less_than_equal_to=0
  [/variable]
  [then]
    [store_unit] 
        [filter] 
            side=$side_number 
            canrecruit=1 
        [/filter] 
        kill=no
        variable=side_leader_store 
    [/store_unit]
    {VARIABLE_OP $movement_var format $side_leader_store.moves}
    {CLEAR_VARIABLE side_leader_store}
  [/then]
  [/if]
[/event] 
However, there is still a special case for the very first turn, which is not considered a side turn:

Code: Select all

[event] 
 name=start 
 first_time_only=yes
 {VARIABLE_OP movement_var format "stored_movement1"}
 [store_unit] 
  [filter]
   side=1
   canrecruit=1 
  [/filter] 
  kill=no
  variable=start_leader_store 
 [/store_unit]
 {VARIABLE_OP $movement_var format $start_leader_store.moves}
 {CLEAR_VARIABLE start_leader_store}
[/event]
Then to check and increment:

Code: Select all

[if] 
 [variable] 
  name=$movement_var 
  less_than=14
 [/variable] 

 # additional conditions here

 [then] 
  {VARIABLE_OP $movement_var add 1}

  # your code here

 [/then]
[/if]
I tested it, and it works for me.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Post Reply