Finding/manipulating units on sight and events as functions?
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.
Finding/manipulating units on sight and events as functions?
Two issues, one needed, one mainly performance based but still nice to know =)
Basically what I want to do, is detect units on one team moving into sight of another, and vice versa. However, I'm not sure how to do this, except to create two events which is going to be messy, especially as I will need to use variables to ensure that both do not trigger by accident.
So, when a unit of side 1 moves into sight of a unit of side 2, it should be detected, similarly when a unit on side 2 moves into sight of a unit on side 1 then it should do the same.
Further to this, I then want to be able to manipulate the unit from side 2, either switching its side directly, or killing it and replacing it with an identical unit on side 1. ie the units on side 2 should be controller by side 2 until such a time as it gets in range of a unit on side 1, at which point the player can now control it.
If someone could give me an example of this, or even the exact code I'd need the that would be awesome! I'm finding myself blind on many issues due to a lack of useful examples in the wiki, if I'm sure I've got something right then I may go back and contribute where I am finding myself struggling.
The second issue is in code re-use. Basically, I have tons of code-duplication in my files. One map uses custom villages which had to be defined, thus for twenty villages I have twenty fairly large events, which I'd rather I didn't.
So what I'm wondering is, is there an easy way to re-use code, perhaps by definding a custom event and then triggering it when I need to use that code?
I understand that we can define macros, but I'm of the impression they work much like standard defines and thus are basically copy/pasted into position so are just the same as having a ton of copy/pasted segments (but a lot neater!).
Basically what I want to do, is detect units on one team moving into sight of another, and vice versa. However, I'm not sure how to do this, except to create two events which is going to be messy, especially as I will need to use variables to ensure that both do not trigger by accident.
So, when a unit of side 1 moves into sight of a unit of side 2, it should be detected, similarly when a unit on side 2 moves into sight of a unit on side 1 then it should do the same.
Further to this, I then want to be able to manipulate the unit from side 2, either switching its side directly, or killing it and replacing it with an identical unit on side 1. ie the units on side 2 should be controller by side 2 until such a time as it gets in range of a unit on side 1, at which point the player can now control it.
If someone could give me an example of this, or even the exact code I'd need the that would be awesome! I'm finding myself blind on many issues due to a lack of useful examples in the wiki, if I'm sure I've got something right then I may go back and contribute where I am finding myself struggling.
The second issue is in code re-use. Basically, I have tons of code-duplication in my files. One map uses custom villages which had to be defined, thus for twenty villages I have twenty fairly large events, which I'd rather I didn't.
So what I'm wondering is, is there an easy way to re-use code, perhaps by definding a custom event and then triggering it when I need to use that code?
I understand that we can define macros, but I'm of the impression they work much like standard defines and thus are basically copy/pasted into position so are just the same as having a ton of copy/pasted segments (but a lot neater!).
Being Haravikk gets you girls like these:
image removed
image removed
Hrm, I can't seem to get an [event]name=sighted[/event] to work at all, is it a correctly working event? It won't seem to trigger even if I have two of them with correctly made filters.
Being Haravikk gets you girls like these:
image removed
image removed
- Ken_Oh
- Moderator Emeritus
- Posts: 2178
- Joined: February 6th, 2006, 4:03 am
- Location: Baltimore, Maryland, USA
For code re-use, you want something we call macros. Look for {MACRO_NAME} tags in other campaigns and you'll see their usage. Read all about them here: http://www.wesnoth.org/wiki/PreprocessorRef
For the sighted event, it's best that you post your code and the users can pick it apart and correct it. To change sides, I'll quote zookeeper from another thread:
For the sighted event, it's best that you post your code and the users can pick it apart and correct it. To change sides, I'll quote zookeeper from another thread:
Good luck, that is unless you're planning to make a furry campaign.zookeeper wrote:Grab the MODIFY_UNIT macro from the WML Utilities page page, and use that in an event to change a unit or a group of units to a different side. For example to flip all vampire bats to side 3, use:
Code:Code: Select all
{MODIFY_UNIT (type=Vampire Bat) side 3}
Last edited by Ken_Oh on May 16th, 2006, 3:56 pm, edited 1 time in total.
Macros are the way to go. Yes, they do expand into the full code when parsed, but they make the WML so much more readable.
Sighted events only work properly in fog, and even then there are some limitations. They can be made to work with shroud, but not when side 1 is being sighted by side n+1.
Sighted events only work properly in fog, and even then there are some limitations. They can be made to work with shroud, but not when side 1 is being sighted by side n+1.
Hope springs eternal.
Wesnoth acronym guide.
Wesnoth acronym guide.
Ah, shroud/fog weren't on
The map is designed with them in mind, but I had them switched off so I could see just how much of a fool the lich lord of doom is making of himself (how he can manage to die when he outnumbers the other teams by about five to one I don't know, time to make him invincible perhaps).
Thanks for that again!
Anyway, that now works just fine. The unit modify macro works great too!
However, what I'm trying to work out now, how do I place a unit into the macro from the event filter?
ie, my events look like this:
So, the first filter should pick up a unit from side 2 when it moves into sight of side 1 (there is a similar action for if it happens the other way around).
What I want to do is pass in a unique identifier for the unit conversion so that only the unit triggering my event (caught either by [filter] or [filter_second] in my case) is passed in? Now I know that you can use speaker=unit to make a triggering unit of a moveto event say something, but it doesn't appear to be working as expected when I pass in description=unit to the {MODIFY_UNIT} macro it doesn't behave as expected.
Basically what I would like to do is take the unit found in either [filter] or [filter_second] as a part of the [event] tag, and pass it into the MODIFY_UNIT macro (or a similar piece of code to do the conversion).
How would I go about that? I have the events triggering quite happily though
It's mostly your bog-standard humans vs undead storyline, though I'm doing what I can to concentrate on interesting settings/terrains and focusing on what Wesnoth's gameplay strengths are to make fun scenarios from it; ie I've found a number of scenarios that I plain didn't like in the bundled campaigns because they tried to do something I'm not sure that BfW is really suited for, so I'm going for stuff that can be done well with it
The map is designed with them in mind, but I had them switched off so I could see just how much of a fool the lich lord of doom is making of himself (how he can manage to die when he outnumbers the other teams by about five to one I don't know, time to make him invincible perhaps).
Thanks for that again!
Anyway, that now works just fine. The unit modify macro works great too!
However, what I'm trying to work out now, how do I place a unit into the macro from the event filter?
ie, my events look like this:
Code: Select all
[event]
name=sighted
first_time_only=no
[filter]
side=2
[/filter]
[filter_second]
side=1
[/filter_second]
#Unit conversion goes here
[/event]
[event]
name=sighted
first_time_only=no
[filter]
side=1
[/filter]
[filter_second]
side=2
[/filter_second]
#Unit conversion for the other way round goes here
[/event]
What I want to do is pass in a unique identifier for the unit conversion so that only the unit triggering my event (caught either by [filter] or [filter_second] in my case) is passed in? Now I know that you can use speaker=unit to make a triggering unit of a moveto event say something, but it doesn't appear to be working as expected when I pass in description=unit to the {MODIFY_UNIT} macro it doesn't behave as expected.
Basically what I would like to do is take the unit found in either [filter] or [filter_second] as a part of the [event] tag, and pass it into the MODIFY_UNIT macro (or a similar piece of code to do the conversion).
How would I go about that? I have the events triggering quite happily though
What makes you think I'd do that? I'm a horse owner but that's about itKen Oh wrote:Good luck, that is unless you're planning to make a furry campaign.
It's mostly your bog-standard humans vs undead storyline, though I'm doing what I can to concentrate on interesting settings/terrains and focusing on what Wesnoth's gameplay strengths are to make fun scenarios from it; ie I've found a number of scenarios that I plain didn't like in the bundled campaigns because they tried to do something I'm not sure that BfW is really suited for, so I'm going for stuff that can be done well with it
Being Haravikk gets you girls like these:
image removed
image removed