Events that trigger if an enemy is a certain distance away

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
TheBladeRoden
Posts: 168
Joined: July 16th, 2007, 8:01 am

Events that trigger if an enemy is a certain distance away

Post by TheBladeRoden »

I have a cannon unit that switches between deployment modes via right click menu. But since such things are beyond the AI I decided to create a macro to help it out a little. The idea is, if there is an enemy in 3 hexes radius, the unit changes into a cannon_deployed. And if there aren't any enemies in 3 hexes radius, then it changes into a cannon_in_tow. But sadly it is not working, and I still need to figure out how to filter if a unit is ai-controlled.

Code: Select all

[event]
	name=turn_refresh
	first_time_only=no
	[filter]
		side=$side_number
		x,y=$x1,$y1
		type=Cannon in tow
	[/filter]
	[filter_second]
		[not]
			side=$side_number
		[/not]
		[filter_location]
		x,y=$x1,$y1
		radius=3
		[/filter_location]
	[/filter_second]
	{CANNON_DEPLOY}	
[/event]

[event]
	name=turn_refresh
	first_time_only=no
	[filter]
		side=$side_number
		x,y=$x1,$y1
		type=Cannon deployed
	[/filter]
	[filter_second]
		[not]
			side=$side_number
			[filter_location]
				x,y=$x1,$y1
				radius=3
			[/filter_location]
		[/not]
	[/filter_second]
	{CANNON_TOW}	
[/event]	
Founding Father of Columbia
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Events that trigger if an enemy is a certain distance aw

Post by zookeeper »

There's no primary unit associated with turn refresh events, so there's nothing to filter for.
User avatar
TheBladeRoden
Posts: 168
Joined: July 16th, 2007, 8:01 am

Re: Events that trigger if an enemy is a certain distance aw

Post by TheBladeRoden »

Well at least something is happening now. Now problem is that every unit on the battlefield changes into a cannon

Code: Select all

[event]
	name=ai_turn
	first_time_only=no
	[store_unit]
		kill=no
		variable=cannon_deploying_ai
		[filter]
			side=$side_number
			x,y=$x1,$y1
			type=Cannon in tow
		[/filter]
		[filter_second]
			[not]
				side=$side_number
			[/not]
			[filter_location]
			x,y=$x1,$y1
			radius=3
			[/filter_location]
		[/filter_second]
	[/store_unit]
	{CANNON_DEPLOY}
	[unstore_unit]
		variable=cannon_deploying_ai
	[/unstore_unit]
[/event]

[event]
	name=ai_turn
	first_time_only=no
	[store_unit]
		kill=no
		variable=cannon_towing_ai
		[filter]
			side=$side_number
			x,y=$x1,$y1
			type=Cannon deployed
		[/filter]
		[filter_second]
			[not]
				side=$side_number
				[filter_location]
					x,y=$x1,$y1
					radius=3
				[/filter_location]
			[/not]
		[/filter_second]
	[/store_unit]
	{CANNON_TOW}
	[unstore_unit]
		variable=cannon_deploying_ai
	[/unstore_unit]	
[/event]
Founding Father of Columbia
User avatar
Luke the Flaming
Posts: 215
Joined: October 18th, 2006, 6:25 pm

Re: Events that trigger if an enemy is a certain distance aw

Post by Luke the Flaming »

There's no [filter_second] available in [store_unit].
Note that I haven't been using WML lately, so I may remember details wrong, but...

Code: Select all

   [store_unit]
      kill=no
      variable=cannon_deploying_ai
      [filter]
         side=$side_number
         type=Cannon in tow
         [filter_location]
             [filter]
                 [not]
                    side=$side_number
                 [/not]
             [/filter]
             radius=3
         [/filter_location]
      [/filter]
   [/store_unit]
(and similarly for the other [event] switching back cannons).
O, Wind, if Winter comes, can Spring be far behind?
User avatar
TheBladeRoden
Posts: 168
Joined: July 16th, 2007, 8:01 am

Re: Events that trigger if an enemy is a certain distance aw

Post by TheBladeRoden »

well I gave up on the 3 hexes away bit and just settled on adjecenct enemies after moving. Good enough for government work

Code: Select all

[event]
	name=ai turn
	first_time_only=no
	[event]
		name=moveto
		first_time_only=no
		[filter]
			type=Cannon in tow
			[filter_adjacent]
				count=1-6
				is_enemy=true
			[/filter_adjacent]
		[/filter]
		[store_unit]
			kill=no
			variable=cannon_deploying_ai
			[filter]
				x,y=$x1,$y1
			[/filter]
		[/store_unit]
		[if]
			[have_unit]
				x,y=$x1,$y1
				[filter_wml]
					[modifications]
						{TRAIT_QUICK}
					[/modifications]
				[/filter_wml]
			[/have_unit]
			[and]
				[variable]
					name=cannon_deploying_ai.moves
					greater_than=3
				[/variable]
			[/and]
			[then]
				[set_variable]
					name=cannon_deploying_ai.moves
					value=3
				[/set_variable]	
			[/then]
			[else]
				[if]
					[variable]
						name=cannon_deploying_ai.moves
						greater_than=2
					[/variable]
					[then]
						[set_variable]
							name=cannon_deploying_ai.moves
							value=2
						[/set_variable]	
					[/then]
					[else]
						[set_variable]
							name=cannon_deploying_ai.moves
							add=-1
						[/set_variable]						
					[/else]
				[/if]
			[/else]
		[/if]
		[unstore_unit]
			variable=cannon_deploying_ai
			find_vacant=no
		[/unstore_unit]
		{TRANSFORM_UNIT (
		side=$side_number
		x,y=$x1,$y1
		type=Cannon in tow
		) (Cannon deployed)}
		{CLEAR_VARIABLE cannon_deploying_ai}
	[/event]
[/event]

[event]
	name=ai turn
	first_time_only=no
	[event]
		name=moveto
		first_time_only=no
		[store_unit]
			kill=no
			variable=cannon_towing_ai
			[filter]
				x,y=$x1,$y1
			[/filter]
		[/store_unit]	
		[set_variable]
			name=cannon_towing_ai.moves
			add=1
		[/set_variable]
		[unstore_unit]
			variable=cannon_towing_ai
			find_vacant=no
		[/unstore_unit]  
		{TRANSFORM_UNIT (
		side=$side_number
		x,y=$x1,$y1
		type=Cannon deployed
		[filter_adjacent]
				count=0
				is_enemy=true
		[/filter_adjacent]
		) (Cannon in tow)}
		{CLEAR_VARIABLE cannon_towing_ai}
	[/event]	
[/event]
Founding Father of Columbia
Post Reply