Random movement of units
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.
Random movement of units
I try to make a unit move randomly, so that no player or ai moves the unit but it will move 5 hex on a random path. I tried this:
Defining unit
Making an event when the ship is moved
The Macro
Any ideas, is my macro flowed (i guess but I don't know why/ how to do it better)
Defining unit
Code: Select all
[event]
name=prestart
[unit]
id=fireship
type=boat
x,y= 10,10
[/unit]
[/event]
Code: Select all
#move ship randomly
[event]
name=turn end
[move_unit]
id=fireship
check_passability=yes
force_scroll=yes
dir={MOVEMENT}
[/move_unit]
[/event]
Code: Select all
#define MOVEMENT
[set_variables]
name=dir_fireship
[value]
rand=N,NW,NE,E,W,S,SW,SE
[/value]
[value]
rand=N,NW,NE,E,W,S,SW,SE
[/value]
[value]
rand=N,NW,NE,E,W,S,SW,SE
[/value]
[value]
rand=N,NW,NE,E,W,S,SW,SE
[/value]
[value]
rand=N,NW,NE,E,W,S,SW,SE
[/value]
[/set_variables]
#enddef
Re: Random movement of units
MOVEMENT is called as value of dir key, so it should return some text value. Currently you have
dir=[set_variables] and later on try to close tag [/set_variables] which was never opened, since [set_variables] is value of dir, it is not treated as opening tag.
After solving syntax issues we get to
However there is nothing about randomness so far. You could use [set_variable] with rand to get random data.
dir=[set_variables] and later on try to close tag [/set_variables] which was never opened, since [set_variables] is value of dir, it is not treated as opening tag.
After solving syntax issues we get to
Code: Select all
[set_variables]
name=dir_fireship
[value]
rand=N,NW,NE,E,W,S,SW,SE
[/value]
[value]
rand=N,NW,NE,E,W,S,SW,SE
[/value]
[value]
rand=N,NW,NE,E,W,S,SW,SE
[/value]
[value]
rand=N,NW,NE,E,W,S,SW,SE
[/value]
[value]
rand=N,NW,NE,E,W,S,SW,SE
[/value]
[/set_variables]
[move_unit]
id=fireship
check_passability=yes
force_scroll=yes
dir=$dir_fireship[0].rand
[/move_unit]
Re: Random movement of units
I've made something like that, but without a route. I'm using teleport to teleport the unit and the animate function of teleport that let it appear as if it is moving. Note - the unit I move has the id "Mover".
You can combine it with a while loop to make the boat walk several steps or if the units are called Boat1 Boat2 and so on, you could make a while loop that moves several boats or units one after another.
Code: Select all
[store_unit]
variable=wanderermove
[filter]
id=Mover
[/filter]
[/store_unit]
[set_variable]
name=wandererchangex
rand=-1..1
[/set_variable]
[set_variable]
name=wandererchangey
rand=-1..1
[/set_variable]
[set_variable]
name=wanderx
value=$wanderermove.x
add=$wandererchangex
[/set_variable]
[set_variable]
name=wandery
value=$wanderermove.y
add=$wandererchangey
[/set_variable]
[unstore_unit]
find_vacant=no
variable=wanderermove
[/unstore_unit]
[clear_variable]
name=wanderermove
[/clear_variable]
[teleport]
[filter]
id=Mover
[/filter]
x=$wanderx
y=$wandery
animate=$movementsetting
[/teleport]
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer