Does [filter_vision] not work for AI sides?

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.
User avatar
Ken_Oh
Moderator Emeritus
Posts: 2178
Joined: February 6th, 2006, 4:03 am
Location: Baltimore, Maryland, USA

Does [filter_vision] not work for AI sides?

Post by Ken_Oh »

I put this into the tutorial.

Code: Select all

[event]
	name=moveto
	first_time_only=no
	[filter]
		side=1
	[/filter]
	[if]
		[have_unit]
			side=1
			[filter_vision]
				viewing_side=2
			[/filter_vision]
		[/have_unit]
		[then]
			[wml_message]
				message="fired for $x1 $y1"
				logger=err
			[/wml_message]
		[/then]
	[/if]
[/event]
[event]
	name=start
	{GENERIC_UNIT 2 "Fencer" 1 3}
[/event]
The event always fired, no matter where I moved, but then I realized a unit is always going to be sighted if there is no fog. So I put fog=yes into side 2 and now it never fires, no matter how close I get to the Fencer.

Is it back to the sighted event?
User avatar
Luke the Flaming
Posts: 215
Joined: October 18th, 2006, 6:25 pm

Re: Does [filter_vision] not work for AI sides?

Post by Luke the Flaming »

I'm not sure if it can be of help, but... I had some issues with [filter_vision] when (in 1.6.4) I tried to replace the (supposedly bugged) name=sighted with it.
In the end, what worked was:

Code: Select all

[event]
    name=moveto
    [filter]
        side=1
        [filter_location]
            radius=12
            [filter]
                side=2
                [filter_vision]
                    viewing_side=1
                    visible=yes
                [/filter_vision]
            [/filter]
        [/filter_location]
    [/filter]
    # what you wish to happen...
[/event]
Maybe you don't get the desired effect because what side 2 can (or cannot) see isn't updated "real time" (similar to [terrain] needing a [redraw] to be displayed immediately).
It's just a wild guess on my part...
O, Wind, if Winter comes, can Spring be far behind?
User avatar
SkyOne
Posts: 1310
Joined: January 3rd, 2009, 7:23 pm

Re: Does [filter_vision] not work for AI sides?

Post by SkyOne »

Ken_Oh wrote:The event always fired, no matter where I moved, but then I realized a unit is always going to be sighted if there is no fog. So I put fog=yes into side 2 and now it never fires, no matter how close I get to the Fencer.

Is it back to the sighted event?
I bring totally a different issue, but possibly related. The event below triggers even the Ghost Ship is not in the sight on my campaign. (by shroud)
It was fine on 1.6. If I recall correctly, it began on 1.7.13 or before. It was not too bad on 1.7.13, but became worser on 1.7.15 and later.

I am guessing that there is a bug on the [filter_vision] tag or something, isn't it? I have not reported Gna Project because not so sure, yet. (I have the save file)
Spoiler:
Fate of a Princess/feedback thread: "What is in own heart that is the most important, not who you are."
Drake Campaign: Brave Wings/feedback thread, Naga Campaign: Return of the Monster, Saurian Campaign: Across the Ocean
Northern Forces - now on 1.12 server
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Does [filter_vision] not work for AI sides?

Post by Sapient »

I looked at Ken's code several times and I still don't see anything wrong with it. While I'm not 100% certain, this should probably be filed as an official bug report on bugs.wesnoth.org

I'm afraid that filter_vision also has known bugs with potential MP OOS and replay corruption which are possible if any player has "delay shroud updates" turned on.

The good news is that both sighted events and filter_vision may get totally fixed this summer by one of the GSoC students when he introduces a route planning system.
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
Ken_Oh
Moderator Emeritus
Posts: 2178
Joined: February 6th, 2006, 4:03 am
Location: Baltimore, Maryland, USA

Re: Does [filter_vision] not work for AI sides?

Post by Ken_Oh »

OK, thanks everyone. I'll do a little more research as to what works, will submit a report to bugs when figure it out, and will be careful when using it in MP.
User avatar
Ken_Oh
Moderator Emeritus
Posts: 2178
Joined: February 6th, 2006, 4:03 am
Location: Baltimore, Maryland, USA

Re: Does [filter_vision] not work for AI sides?

Post by Ken_Oh »

So, as what is become the case more often, Lua has come to the rescue.

Luke the Flaming: What you posted works fine, but it's not for my case. I don't want viewing_side=1, I want viewing_side=2 and for it to fire during side=1's turn.

Anyway, here is what I've come up with in Lua in case anyone is interested (just hacked together at the moment, but it works).
Spoiler:
More importantly, I have a few questions.

Qs:
-Can I write $foo[$i].bar in Lua as foo.bar ? It seems to be working when I do but I want to make sure.
-Any way for Lua to find if a unit is hidden? There looks to be a bug with [status]/hidden. If I go into a fresh game of HttT and save it, every unit in there shows hidden="yes". zookeeper suggested a work-around, but if Lua can somehow access that directly, I'd love to see it.
silene
Posts: 1109
Joined: August 28th, 2004, 10:02 pm

Re: Does [filter_vision] not work for AI sides?

Post by silene »

Ken_Oh wrote:Can I write $foo[$i].bar in Lua as foo.bar ? It seems to be working when I do but I want to make sure.

No. Or yes. Or maybe. It depends on what you actually want to write. Since you are using dollars, I assume foo and i are WML variables and not Lua ones.

You can do

Code: Select all

wesnoth.set_variable(string.format("foo[%d].bar", wesnoth.get_variable "i"), ...)
... wesnoth.get_variable(string.format("foo[%d].bar", wesnoth.get_variable "i"), ...)
If you use the helper library, you can simplify the usage further:

Code: Select all

local V = helper.set_wml_var_metatable {}
V.foo[V.i].bar = ...
... V.foo[V.i].bar
And if you don't mind mixing Lua and WML variables in the same script, you can even write:

Code: Select all

helper.set_wml_var_metatable(_G)
foo[i].bar = ...
... foo[i].bar
I see you are using rouse_enemies.x in your script, so I guess that last thing is exactly what you did.
Ken_Oh wrote:Any way for Lua to find if a unit is hidden? There looks to be a bug with [status]/hidden. If I go into a fresh game of HttT and save it, every unit in there shows hidden="yes". zookeeper suggested a work-around, but if Lua can somehow access that directly, I'd love to see it.

No. Or rather it won't give anything better than [status]. So if there is a bug with [status], Lua will suffer from it too.
User avatar
Ken_Oh
Moderator Emeritus
Posts: 2178
Joined: February 6th, 2006, 4:03 am
Location: Baltimore, Maryland, USA

Re: Does [filter_vision] not work for AI sides?

Post by Ken_Oh »

Right, I should have mentioned that I have what I needed for variables in a prestart event. '

OK, so zookeeper's workaround for hidden units it is. Thanks for the help.
silene
Posts: 1109
Joined: August 28th, 2004, 10:02 pm

Re: Does [filter_vision] not work for AI sides?

Post by silene »

Ken_Oh wrote:There looks to be a bug with [status]/hidden.
After further investigations, your issue is probably not a bug. It's just that "hidden" doesn't mean hidden. (It would be too easy otherwise.) That being said, there are nonetheless a few bugs associated to this status and it is currently useless, so I'm getting rid of it. It will be replaced by a new status called "uncovered". Hopefully this new name will be less misleading; it will mean something akin to "if the unit was not visible, too bad, now it most certainly is".
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Does [filter_vision] not work for AI sides?

Post by Anonymissimus »

Ken Oh wrote:# not exactly why, but that +1 makes it work better
Maybe it's this:
silene in another thread wrote:Note that the cost value [as returned by wesnoth.find_path] takes into account wasted points at end of turns and zones of control. For instance, if, arrived on a given tile, a unit would have only one mp left yet the next tile has a cost of 2, then the actual cost for the next tile will be 3, since the unit will have to wait the next turn to proceed with the move. This may explain the discrepancies you are experiencing.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Exasperation
Posts: 462
Joined: June 8th, 2006, 3:25 am

Re: Does [filter_vision] not work for AI sides?

Post by Exasperation »

Actually, it's because you want to check for cost <= u.max_moves+move_cost, which (with integer costs) is equivalent to cost < u.max_moves+move_cost+1.
User avatar
Ken_Oh
Moderator Emeritus
Posts: 2178
Joined: February 6th, 2006, 4:03 am
Location: Baltimore, Maryland, USA

Re: Does [filter_vision] not work for AI sides?

Post by Ken_Oh »

Hah, indeed. That's what I get for changing paradigms, from using < knowing full well that I would want a +1 there to using that cost+move_cost convention, without rethinking the structure.
silene
Posts: 1109
Joined: August 28th, 2004, 10:02 pm

Re: Does [filter_vision] not work for AI sides?

Post by silene »

Ken_Oh wrote:Right, I should have mentioned that I have what I needed for variables in a prestart event.
Just in case it wasn't a slip of tongue, you should use a "preload" event, not a "prestart" one. Otherwise the change to _G will wear off when you reload the game since it is not saved.

Also, I was a bit too fast when describing access to variables. The low-level version for "$foo[$i].bar" is more complicated:

Code: Select all

wesnoth.set_variable(string.format("foo[%d].bar", wesnoth.get_variable "i"), ...)
-- and similarly for reading a variable
User avatar
homunculus
Posts: 537
Joined: July 21st, 2010, 9:47 pm

Re: Does [filter_vision] not work for AI sides?

Post by homunculus »

i think i got sighting to work (1.8.4).
i think so because i have seen it working perfectly all the time.
and more than that, i think so because the way it works seems logical to me (it took some effort to figure out, though).
the only thing i could not do was to always clearly determine the ai side 2 unit that sighted side 1 (afaik this was also mentioned in wml reference pages).

basically, the setting is as follows:
"At dawn, when fog is going to fall from the mountains, we must ford the river."
and there is a possibility of being sighted.
and in the morning the fog will be cleared and you will be sighted anyway, and the fording chat event will trigger if you are not on your bank of the river.
Spoiler:
campaign ruthless in your nearest 1.11 add-on server
some wesnoth-related drawings
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Does [filter_vision] not work for AI sides?

Post by Elvish_Hunter »

homunculus wrote:the only thing i could not do was to always clearly determine the ai side 2 unit that sighted side 1 (afaik this was also mentioned in wml reference pages).
To do this, I use a NEAREST_UNIT macro (there are two slightly different examples in TSoG and TFoB) to check what is the nearest unit to the moving one. I have to do this because moveto events don't have a second_unit. I call it this way in a sighted spider event:
Spoiler:
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
Post Reply