Help: Unit that makes adjacent units move faster

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
Kharn
Posts: 83
Joined: December 12th, 2005, 7:50 pm
Location: Dallas, Tx

Help: Unit that makes adjacent units move faster

Post by Kharn »

I am looking to code something in the ability of a unit such that at the start of each turn, any units adjacent to it get X movement over their base amount.

Anyone know where to start? Research is turning up nothing.
Creator of 120+ units Lord of the Rings era and campaign now outdated & lost.
Creator of WWII Battleground Europe mod with 120+ units most with custom wml and animations. Every variable is mathematically derived based on WWII stats such as historical cost & mm armour.
User avatar
Ravana
Forum Moderator
Posts: 3002
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Help: Unit that makes adjacent units move faster

Post by Ravana »

Turn refresh event, store_unit with filter filter_adjacent to find which units to change. Then foreach over those stored and with VARIABLE_OP add those moves, then unstore to save changes.
Kharn
Posts: 83
Joined: December 12th, 2005, 7:50 pm
Location: Dallas, Tx

Re: Help: Unit that makes adjacent units move faster

Post by Kharn »

Ravana wrote:Turn refresh event, store_unit with filter filter_adjacent to find which units to change. Then foreach over those stored and with VARIABLE_OP add those moves, then unstore to save changes.

Will this work in multiplayer? Can I place the event into the unit file? If not where?

This also looks like it will use a loop, which I am not too comfortable in WML despite lots of basic and c++ programming. Wouldnt {MODIFY_UNIT x,y=$x2,$y2 moves 0} work?
Creator of 120+ units Lord of the Rings era and campaign now outdated & lost.
Creator of WWII Battleground Europe mod with 120+ units most with custom wml and animations. Every variable is mathematically derived based on WWII stats such as historical cost & mm armour.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Help: Unit that makes adjacent units move faster

Post by Sapient »

Yes

Code: Select all

[modify_unit]
  [filter]
    [filter_adjacent]
      ability=speedboost2
    [/filter_adjacent]
  [/filter]
  moves="$($this_unit.movement + 2)"
[/modify_unit]
Something like the above should work.

But iterating over stored units is really not that hard... :|

Code: Select all

[store_unit]
  [filter]
    [filter_adjacent]
      ability=speedboost2
    [/filter_adjacent]
  [/filter]
  variable=stored_units
[/store_unit]
{FOREACH stored_units i}
[set_variable]
  name=stored_units[$i].moves
  value=$stored_units[$i].movement
[/set_variable]
[set_variable]
  name=stored_units[$i].moves
  add=2
[/set_variable]
[unstore_unit]
  variable=stored_units[$i]
[/unstore_unit]
{NEXT i}
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
ChaosRider
Posts: 846
Joined: April 15th, 2012, 1:15 pm

Re: Help: Unit that makes adjacent units move faster

Post by ChaosRider »

Amazing, after 240 items they are still some abilities which dont required so long wml code... aura of speed (weaker +1 mp, normal +2 mp, greater +3 mp at turn start for adjected not enemies). Thx for idea :P!
Creator of WOTG (+2880 units), MWC (+615 units), SurvivorsArea, RandomColosseum, RC WOTG, RC MWC, ColosseumRandomClonesBattle, BetweenDarknessAndLight, StealingWeapons, MoreUnitsForms, MoreDamageTypes, CanBeOnlyOne, ColosseumOneWinner, BonusSpam, CriticalStrike - available at 1.12 Wesnoth server.
Kharn
Posts: 83
Joined: December 12th, 2005, 7:50 pm
Location: Dallas, Tx

Re: Help: Unit that makes adjacent units move faster

Post by Kharn »

Thank you Sapient! The only issue I found with the code you supplied is that it sets moves to 0 each time instead of +2. I changed the variable from movement to max_moves to resolve.

To share with others, here is the more finished code that is working for me.
The following code can be applied into as many unit files as you want without the effects stacking.

Code: Select all

	[event]
        name=turn refresh
        first_time_only=no
		[modify_unit]
			[filter]
				race=Infantry
				side="$side_number"
				[filter_adjacent]
					type=Supply_Truck, Supply_Truck_Vet, Supply_Truck_Elite, Armoured_Supply_Truck, Armoured_Supply_Truck_Vet
					is_enemy=no
				[/filter_adjacent]
			[/filter]
			moves="$($this_unit.max_moves + 2)"
		[/modify_unit]
	[/event]
Creator of 120+ units Lord of the Rings era and campaign now outdated & lost.
Creator of WWII Battleground Europe mod with 120+ units most with custom wml and animations. Every variable is mathematically derived based on WWII stats such as historical cost & mm armour.
User avatar
Ravana
Forum Moderator
Posts: 3002
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Help: Unit that makes adjacent units move faster

Post by Ravana »

Using ability filter instead of type filter would make the code easier to maintain.
Post Reply