ai avoid terrain type - possible?

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
flava_clown
Posts: 79
Joined: September 24th, 2005, 10:46 am
Location: Spain
Contact:

ai avoid terrain type - possible?

Post by flava_clown »

hi

is there an "easy" way to make sure that the ai avoid some terrain types?
like the ai stays out of water.
i think that i can't filter the terrain type in the avoid tag.

my idea was to use "store_locations" and use then the variable.x and variable.y for the avoid tag. i know it won't work that way. first i'll need to format it, to make sure that not only variable[0].x and variable[0].y is used.
the question is now how? the foreach macro won't help with that right?

i guess it must look like this |$var[0]|,|$var[1]|,... and so on...

regards
Imagine there's no countries
It isn't hard to do
Nothing to kill or die for
And no religion too
Imagine all the people
Living life in peace
toms
Posts: 1717
Joined: November 6th, 2005, 2:15 pm

Post by toms »

Listing the whole array would work, AFAIK. But I think terrain=c in also does. Check the wiki and/or try it at yourself.
First read, then think. Read again, think again. And then post!
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Post by zookeeper »

Tricky one. [avoid], according to the wiki at least, accepts only one coordinate to avoid, not a list or a range. If it accepted a list, or the standard location filter was extended to include the terrain= option as well, this would be doable.

Unfortunately, I don't think you can currently do what you want to. Unless the wiki documentation hasn't been updated to reflect some odd change that enables this, which I seriously doubt.
toms
Posts: 1717
Joined: November 6th, 2005, 2:15 pm

Post by toms »

Then it definitely should be made possible, IMO. It would offer lots of new possibilities to make the ai smart and other things.
First read, then think. Read again, think again. And then post!
Rhuvaen
Inactive Developer
Posts: 1272
Joined: August 27th, 2004, 8:05 am
Location: Berlin, Germany

Post by Rhuvaen »

Much simpler than that. Don't try to appeal to the AI's intelligence. Use brute force on its units by applying an object like this to their units:

Code: Select all

      [object]
        [effect]
          apply_to=movement_costs
          replace=true
          [movement_costs]
            shallow_water=99
            deep_water=99
          [/movement_costs]
        [/effect]
      [/object]
They'll never be able to enter water, then ;).

There's different ways you could apply the object, the simplest being directly in the recruit event. I've never used one of those though.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Post by zookeeper »

Rhuvaen wrote:Much simpler than that. Don't try to appeal to the AI's intelligence. Use brute force on its units by applying an object like this to their units:
Yeah, that should work. :) Damn, that was pretty clever.
flava_clown
Posts: 79
Joined: September 24th, 2005, 10:46 am
Location: Spain
Contact:

Post by flava_clown »

damn... that's what i call an idea... i've use such a "hack" to make sure that the guard units stay in the tower (i set moves to 0 every turn)
but to change the whole movement cost thing is quite good... but i guess i'll try avoid terrain before ;)

thanx to all for the help
and yes the possibility to let the ai avoid terrain types would help a lot with ai things

anyway one question stays ... is there a way to format an array?
Imagine there's no countries
It isn't hard to do
Nothing to kill or die for
And no religion too
Imagine all the people
Living life in peace
toms
Posts: 1717
Joined: November 6th, 2005, 2:15 pm

Post by toms »

If you know the length, it's easy:

Code: Select all

[set_variable]
temp_list
format=temp[0],temp[1],temp[2],...
[/set_variable]
but this will produce a list again, so you can't let the ai avoid it (if the wiki says the truth)

If you do not know the length, it is a lot tricky, I tell you if you need it.
First read, then think. Read again, think again. And then post!
flava_clown
Posts: 79
Joined: September 24th, 2005, 10:46 am
Location: Spain
Contact:

Post by flava_clown »

thanx, but what i wanted to know is how to do this in an automatic way, if you understand what i mean... to format it like this is a lot of work, even with copy/paste... and it seems that the wiki is not correct, you can use a list for x,y in the avoid tag... just have a look in the mainline campaigns. they use it like

Code: Select all

[avoid]
x=1-20
y=1-11
[/avoid]
i´ve tried to use terrain=c but it didn't work (as expected)

but thanx to the idea from Rhuvaen, the ai stays now out of the water ;)
i did it a bit different but the main idea is the same.

Code: Select all

{MODIFY_UNIT_DAD side=1 movement_costs.deep_water 99 movement_costs.shallow_water 99}
all in an "ai turn" event, which i had for the tower guard units anyway...

the whole event:

Code: Select all

# makes sure that the guards stay in the tower, at least for the first 5 turns
# higher the 'less_than' number to let them stay longer or lower the number to let them go earlier
[event]
	name=ai turn
	first_time_only=no
	[if]
		[and]
			[variable]
				name=turn_number
				greater_than=1
			[/variable]
		[/and]
		[and]
			[variable]
				name=turn_number
				less_than=6
			[/variable]
		[/and]
		[then]
			{MODIFY_UNIT description=Ven moves 0}
			{MODIFY_UNIT description=Carercyn moves 0}
			{MODIFY_UNIT description=Yreddyn moves 0}
			{MODIFY_UNIT description=Suc moves 0}
			{MODIFY_UNIT description=Gudd moves 0}
			{MODIFY_UNIT description=Ceoryn moves 0}
			{MODIFY_UNIT description=Lonnyn moves 0}
			{MODIFY_UNIT description=Taemyr moves 0}
			{MODIFY_UNIT description=Owidry moves 0}
			{MODIFY_UNIT description=Aethunry moves 0}
		[/then]
	[/if]
# this makes sure that the humans doesn't enter the water
# thanx to Rhuvaen for the Idea, how to do this!
	{MODIFY_UNIT_DAD side=1 movement_costs.deep_water 99 movement_costs.shallow_water 99}

[/event]
regards
Imagine there's no countries
It isn't hard to do
Nothing to kill or die for
And no religion too
Imagine all the people
Living life in peace
Post Reply