Checking ownership of village

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
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Checking ownership of village

Post by Helmet »

A victory condition of my scenario-in-progress requires that a unit from side 1 remain in a particular village (deep in enemy territory) for 3 consecutive turns.

I used name=capture to respond to the first time a side=1 unit enters and captures the village, but evidently capture has no further purpose after the village is already captured.

I tried have_unit, but I don't quite understand have_unit and how to filter it, so it didn't work. The examples I found on the internet did not help much (including a macro made for checking village ownership).

What is the code needed for such a task as I described? Thanks for any help you provide.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
User avatar
Pentarctagon
Project Manager
Posts: 5564
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Checking ownership of village

Post by Pentarctagon »

It sounds like [store_villages] would be what you want.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
Pilauli
Posts: 115
Joined: August 18th, 2020, 12:56 pm

Re: Checking ownership of village

Post by Pilauli »

I could see exactly how to do this in my mind's eye, which would be a slightly horrible and inelegant way, but would probably work without too much tinkering. And I decided putting together a working set of code for it would be an interesting activity. Of course, it ended up taking more tinkering than I thought it should, but I think I've got it working now. Here it is, if you want it.

(My code uses a moveto event to set variables, and then each turn, it checks whether the right unit is on the village; if so, it increases the variable which represents the number of turns that he has sat on the village, until it reaches 3.)

Code: Select all

# General outline:
# When a unit moves to the designated village, the variable turns_village_held_for is set to 1.  After that, it is incremented at the start of each turn.
# When turns_village_held_for reaches 4, the player wins.

# There are comments scattered throughout, hopefully documenting everything as needed.
# To change the village coordinates, run a search-and-replace on the phrase "x,y=10,9 # village coordinates" and replace it with the right contents.

# On every new turn, this event considers whether the unit is on the village, and if so, how long it has been there.
# Both of the variables used here, village_holder_id and turns_village_held_for, are defined elsewhere.
[event] 
    name=new_turn
    first_time_only=no

    # If a unit is supposed to be on the village, but isn't, then we need to clear the special variables documenting a unit being on the village.
    # It's probably easiest to say "if someone's been holding the village for 0 or more turns."  (If there is no turns_village_held_for, I assume that its value doesn't equal anything.)
    # We could have separate variable-clearing events for every single way the unit could lose the village, but that would be a lot of work
    #  and this would be a good fallback anyway for in case some unforeseen situation removed the unit from the village without triggering any of those events.
    [if]
        [not]
            [variable]
                name=turns_village_held_for
                # I went looking for a way to test whether a variable was undeclared, and here's what I found.
                equals=$nonexistent_variable
            [/variable]
        [/not]
        [not]
            [have_unit]
                id=$village_holder_id
                x,y=10,9 # village coordinates
            [/have_unit]
        [/not]
        [then]
            [message]
                side=1 # some dude on side 1, don't care who
                message= _ "We've lost that village?  After only $turns_village_held_for| turns, even.  That's not good."
            [/message]
            [clear_variable]
                name=village_holder_id,turns_village_held_for
            [/clear_variable]
            # Clearing the turns_village_held_for variable means it isn't counting up any more, so there's no risk of accidentally winning if we just cleared it.
        [/then]
    [/if]

    # On the other hand, if the right unit is on the village, then we need to tick turns_village_held_for up by one.
    [if]
        [have_unit] # i.e. if a unit exists with these values...
            id=$village_holder_id
            x,y=10,9 # village coordinates
        [/have_unit]
        [then]
            [set_variable]
                name=turns_village_held_for
                value="$($turns_village_held_for|+1)"
            [/set_variable]
            [message]
                speaker=$village_holder_id
                message= _ "I've held this village for $turns_village_held_for| turns now."
            [/message]
        [/then]
    [/if]

    # Now, if we've held it for enough turns, clear the variables (for tidiness) and end the level.
    [if]
        [variable]
            name=turns_village_held_for
            equals=3
        [/variable]
        [then]
            [message]
                speaker=$village_holder_id
                message= _ "I successfully held the village!  We win!"
            [/message]
            [clear_variable]
                name=village_holder_id,turns_village_held_for
            [/clear_variable]
            [endlevel]
                result=victory
                # Include whatever stuff about carryover or whatever you want to.
            [/endlevel]
        [/then]
    [/if]
[/event]

[event] # When the unit moves to the village, sets variables to keep track of him.
    name=moveto
    first_time_only=no # I want this to re-fire every time someone re-claims the village.
    [filter]
        x,y=10,9 # village coordinates
        side=1
    [/filter]

    # This [if] block is because if the same unit moves back on the same turn, I want the countdown to continue where it left off.
    # In other words, if the same guy moves back on the same turn, just provide some flavor text.  Otherwise, do the full claim-village-routine.
    [if]
        [variable]
            name=village_holder_id
            equals=$unit.id
        [/variable]
        [then]
            [message]
                speaker=unit
                message= _ "I won't leave my post again!"
            [/message]
        [/then]

        # This case will probably be more common, though: either this is the first time a unit moved here,
        # or the unit's been away for too long, or a different unit took his place.
        # In any case, if the unit isn't the same one who held the village earlier this very turn, we want to set the variables.
        [else]
            [set_variable] # This one is so we know who's supposed to be on the village.
                name=village_holder_id
                value=$unit.id
            [/set_variable]
            [set_variable] # This one keeps track of how long he's held the village for.
                name=turns_village_held_for
                value=0
            [/set_variable]
            [message]
                speaker=unit
                message= _ "I'm sure I can keep this place safe for three turns!"
            [/message]
        [/else]
    [/if]
[/event]

# The upcoming moveto and last_breath events are optional; they just add a bit of flavor text.
# The [not] tags are to (hopefully) avoid any potential event conflicts, by making sure these events will never be triggered at the same time as other events.
# (I'm not sure whether, if there are multiple events that COULD be triggered at one time, the first one will or won't prevent the others from happening, but I don't want to find out.)

# The moveto event can be read as "if the village holder moves anywhere EXCEPT THE VILLAGE HE SHOULD BE GUARDING, then say oops, I shouldn't have left the village."
# If you have some important moveto event near the village (teleportation rune, ambush, chest full of gold coins),
#  then you should probably add another [not] tag with your special location inside, so that there's no chance of this event overriding that one.

# The last_breath event has a couple of [not] tags so that if the village-holder dies,
#  and he is a unit who already has a special last_breath message, then he won't say the generic failure message.
# Which means that there's no chance the generic failure message will stop him from saying his own personalized death message.
# Again, I'm not quite sure whether one event can block another, but I definitely don't want it to happen, and this should make it safe.
[event]
    name=moveto
    first_time_only=no
    [filter]
        id=$village_holder_id
        [not]
            x,y=10,9 # village coordinates
        [/not]
    [/filter]
    [message]
        speaker=$village_holder_id
        message= _ "Wait a minute!  I've just abandoned my post!?  I've got to get back there!"
    [/message]
    [allow_undo]
    [/allow_undo]
[/event]
[event]
    name=last_breath
    first_time_only=no # keep in mind that several village-holders in a row may die.
    [filter]
        x,y=10,9 # village coordinates
        id=$village_holder_id
        [not]
            id=Tom
        [/not]
        [not]
            id=Buddy
        [/not]
    [/filter]
    [message]
        speaker=unit
        message= _ "I have failed!  Someone else will have to do what I could not!"
    [/message]
[/event]
(The rules here are that a single unit must occupy the village for three turns, but it still counts as "occupying" it if he steps off and back on. This is because it's the easiest way to account for every way he could be removed from the village, and as a bonus, if the player accidentally moves him off the village, they can undo the movement and put everything back the way it was. If you'd prefer to let units trade off village-occupying duty, then it shouldn't be too hard to tweak. Relatively speaking. I won't bother unless you want it to work that way, though.)
User avatar
lhybrideur
Posts: 369
Joined: July 9th, 2019, 1:46 pm

Re: Checking ownership of village

Post by lhybrideur »

If you don't need to have the same unit on the village for the three turns, or want to have one special unit on it, you can go with only two if I think.

variable turns_on_villages is initialized to 0 at the beginning of the scenario
then use an turn end event for side 1 with the following if:
1) if has a side 1 unit or that special unit on the village (use a filter and a filter_location): turns_on_village++
else: turns_on_village=0
2) if turns on village==3, victory

If you want, I can write that in WML but it is pretty straightforward.
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Checking ownership of village

Post by Helmet »

lhybrideur wrote: October 12th, 2020, 11:38 am (use a filter and a filter_location): turns_on_village++
...
If you want, I can write that in WML but it is pretty straightforward.
Pilauli's code worked. But, if you don't mind, I would like to see the code you envisioned -- at least some of it. I had spent a long time trying to get filter and filter_location to work, but couldn't. I would like to know what the correct code looks like. I clearly need a better understanding of those tags. For a while, I got rid of all the other villages on the map except the special village, to make filtering the village easier, but it didn't help.
Pilauli wrote: October 12th, 2020, 5:55 am ...I decided putting together a working set of code for it would be an interesting activity.
Thank you! The code works great. The illuminating comments in the code are greatly appreciated. During playtesting, I liked how a unit kept stating information, so I could follow the changes to the variables.

I have a few questions. My so-so understanding of WML variables is that they must be initiated in prestart before they are employed in the body of the code. But your code worked fine without initiating the variables in prestart. Am I mistaken, or should I add this code to prestart?

Code: Select all

        [set_variable]
        	name=village_holder_id
        	value=0
        [/set_variable]
        
        [set_variable]
        	name=turns_village_held_for 
        	value=0
        [/set_variable]
I'm confused about why this code was used (equals=$nonexistent_variable) instead of (less_than=1) or (equals=0). Do they all do the same thing, so whichever one is used is a personal preference, or would using (less_than=1) or (equals=0) be wrong?

Edited to remove questions about AI. I started a new post for that, for the people who search the forum by topic.
Last edited by Helmet on October 12th, 2020, 6:03 pm, edited 2 times in total.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Pilauli
Posts: 115
Joined: August 18th, 2020, 12:56 pm

Re: Checking ownership of village

Post by Pilauli »

Helmet wrote: October 12th, 2020, 1:40 pm My so-so understanding of WML variables is that they must be initiated in prestart before they are employed in the body of the code. But your code worked fine, yet I didn't initiate the variables in prestart.
They actually don't have to be. I initiated them in the moveto event (where the guy says "I'm sure I can keep this place safe for three turns"). The conditions are set up so that whenever the guy is on the village, those variables have been initiated (since the last time they were cleared), so they have been initiated before they are employed... it's just slightly more immediately before they were employed.
Helmet wrote: October 12th, 2020, 1:40 pm I'm also confused about why this code was used (equals=$nonexistent_variable) instead of (less_than=1) or (equals=0). Do they all do the same thing, so whichever one is used is a personal preference, or would using (less_than=1) or (equals=0) be wrong?
It bothered me that every turn (when a guy was not on the village), people would say "We've lost that village? After only turns, even. That's not good." (The dialogue bugged me, but actually re-setting it every turn it the village isn't occupied wouldn't be a problem, really.) But I decided to only clear it when it was currently available (and had been initiated since the last time it had been cleared.)

That meant I had to check whether it currently existed, and it turns out all nonexistent variables equal each other, so I asked whether the value of turns_village_held_for (the variable where I wanted to check whether it existed) was equal to the value of nonexistent_variable (which has never existed) or not.

If this undefined variable stuff bothers you (or if some later Wesnoth update breaks it), you should be able to set turns_village_held_for to 0 in the prestart event and then re-write the "clear the variable" block to clear it if it's greater than 0. Actually, that would probably make more sense than what I did.

(This should behave exactly the same in all cases except for when a unit gets on the village and is removed the same turn. In that case, nobody will notice, which I think means if the village-holder escapes, he will keep talking about how he abandoned his post, every time he moves, until either he moves back there, he dies, or someone else take the village. But that's actually kind of appropriate, and not a very likely sequence of events, and I can't think of anything else that this would affect.)

Code: Select all

    [if]
        [variable]
            name=turns_village_held_for
            greater_than=0
        [/variable]
        [not]
            [have_unit]
                id=$village_holder_id
                x,y=10,9 # village coordinates
            [/have_unit]
        [/not]
        [then]
            [message]
                side=1 # some dude on side 1, don't care who
                message= _ "We've lost that village?  After only $turns_village_held_for| turns, even.  That's not good."
            [/message]
            [set_variable]
                name=village_holder_id
                value=0
            [/set_variable]
            [set_variable]
                name=turns_village_held_for
                value=0
            [/set_variable]
            # Clearing the turns_village_held_for variable means it isn't counting up any more, so there's no risk of accidentally winning if we just cleared it.
        [/then]
    [/if]
Helmet wrote: October 12th, 2020, 1:40 pm If a side 1 unit standing on the village is killed at some point, the enemy doesn't always bother re-capturing the village, so it remains flagged for side 1.
You're right, it would make more sense if the enemy would always re-capture the village. There's probably a way to make them always try to occupy it (setting a really high village value in their AI might work to make them take all the villages as much as they can including this one?); however, I would probably start by trying to make the attacker move into the village when he kills the current village-holder. Try this. (Either replace the little last_breath event from earlier, or else put this beside it; it should work either way.)

Code: Select all

[event]
    name=die
    first_time_only=no
    [filter]
        x,y=10,9 # village coordinates
        id=$village_holder_id
    [/filter]
    [message]
        speaker=second_unit
        message= _ "Our village again!"
    [/message]
    [kill] # This silly bit is necessary to get the village holder well and truly off the map so the attacker can take his place.
        id=$village_holder_id
    [/kill]
    [move_unit]
        id=$second_unit.id
        to_x,to_y=10,9 # village coordinates
    [/move_unit]
    [capture_village] # move_unit doesn't actually capture villages, so we need to do that manually.
        x,y=10,9 # village coordinates
        side=2
    [/capture_village]
    [message]
        side=1
        message= _ "Nooo!"
    [/message]
    
    # Now, this might have interfered with other death events (not sure), so let's make sure we deal with the important stuff.
    [if]
        [variable]
            name=village_holder_id
            equals=Tom
        [/variable]
        [or]
            [variable]
                name=village_holder_id
                equals=Buddy
            [/variable]
        [/or]
        [then]
            [endlevel]
                result=defeat
            [/endlevel]
        [/then]
    [/if]

    # Manually re-sets these variables, so that the characters will stop having a strange delayed realization that their village-holder died.
    # (Do NOT remove the on-every-turn reset; that's still useful for if the unit moves away from the village or something.)
    # It's like a second line of defense for everything working smoothly.
    [set_variable]
        name=village_holder_id
        value=0
    [/set_variable]
    [set_variable]
        name=turns_village_held_for
        value=0
    [/set_variable]
[/event]
(Oh, and the [move_unit] part has one line which says to_x,to_y=10,9 # village coordinates instead of x,y=10,9 # village coordinates, so you need to make sure that if you run a search-and-replace on your file, you don't miss that. (And after all this, you might want to go through and delete any of the comments that I wrote that have stopped matching what the code actually does, too.)

I don't think the AI is likely to carry over from one scenario to the next? You could just try it and see whether the AI acts weird in the next scenario or not.

I'm pretty sure lhybrideur's idea would look a lot like mine except the only important part is the new_turn event (mine also relies on the first moveto event), and instead of keeping track of village_holder_id, it just filters for whether any acceptable unit (i.e. side=1) is on the village. That would probably be simpler. Slightly less exciting, and slightly harder to add interesting flavor text, but simpler.

If you do go the simplification route, but still want the village-holder to say something if he moves off of the village (which is a cool bit of flavor text), then this seems to work (it goes in the moveto event filter):

Code: Select all

[filter]
    side=1
    x2,y2=10,9 # village coordinates
[/filter]
EDIT (5 seconds after posting): by "simplification", I meant "lhybrideur's idea", but this would ALSO avoid the rare and unlikely complaining (whenever the unit moves at all) that I hypothesized could occur when talking about whether you could change the variables to always be initialized! It's all coming together! (Sorry, this is just slightly exciting. :D )
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Checking ownership of village

Post by Helmet »

Thanks again, Pilauli! Your solution to the enemy not recapturing the village was great. I like having the enemy unit who killed the side 1 unit immediately move into the village and capture it. It's unexpected, and it makes it somewhat more difficult for side 1 to get the village back, which is nice.

Thanks also for more information about variables. I didn't realize that set_variable not only creates variables, but can also manipulate the variables at the time they're created. Until now, I've been using the variable tag exclusively to manipulate variables.
Pilauli wrote: October 12th, 2020, 3:52 pm If this undefined variable stuff bothers you (or if some later Wesnoth update breaks it), you should be able to set turns_village_held_for to 0 in the prestart event and then re-write the "clear the variable" block to clear it if it's greater than 0. Actually, that would probably make more sense than what I did.
I guess the undefined variable stuff does bother me a little. It's a little harder for me to grasp, compared to x=0; it's like an undeclared variable both exists and doesn't exist.

Thanks for the extra code. It is useful. The excellent annotations have answered some other questions I had been wondering about, including some coding questions so basic that I had been too embarrassed to ask.
Pilauli wrote: October 12th, 2020, 3:52 pm(Sorry, this is just slightly exciting. :D )
I totally understand! Coding WML is fun. It expect it will be even more fun when I get better at it. If my WML knowledge was a castle, every third or fourth stone block would be missing. Slowly but surely, though, more stone blocks are being crafted and jammed into the gaps! :D

One more thing. For story purposes, I need to check a specific village to see which side owns it, if any. How can I put the side number into a variable? Here is the code, to show you what I mean. The variable is which_side_owns_the_village. Note: it may be flagged by side 2, but unoccupied.

Code: Select all

	[event]
		name=turn 4
		[message]
			id=MyLeader
			message="Soldier, which side owns the village (hex 13,5)?"
		[/message]
		[message]
			side=1
			canrecruit=no
			message="The village is owned by side $which_side_owns_the_village|."
		[/message]
	[/event]
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Pilauli
Posts: 115
Joined: August 18th, 2020, 12:56 pm

Re: Checking ownership of village

Post by Pilauli »

Okay, first I checked https://wiki.wesnoth.org/StandardLocationFilter, before I remembered that that compares, rather than directly accessing, so it would be really clunky to use.

Then I set out to write a name=capture event which would update the stored variable which represents the owner of the village to the value $unit.side. (That worked pretty well, but it was long and you would need to include the line fire_event=yes in any [capture_village] statement that affected that village, otherwise it wouldn't update it properly.)

And then I scrolled back up and saw Pentarctagon's suggestion of [store_villages]. And that works great! You just need something like this:

Code: Select all

	[event]
		name=turn 4
		[store_villages]
			x,y=13,5
			variable=target_village
		[/store_villages]
		[message]
			id=MyLeader
			message="Soldier, which side owns the village (hex 13,5)?"
		[/message]
		[message]
			side=1
			canrecruit=no
			message="The village is owned by side $target_village[0].owner_side|."
		[/message]
	[/event]
[store_villages] makes a list of the villages which meet the criteria (in this case, just the village at (13,5)), and then the villages are represented as target_village[0], target_village[1], and so on. Obviously, we need the first and only.

Then, to quote the wiki...
https://wiki.wesnoth.org/InternalActionsWML#[store_villages wrote:]
Each member of the result array will have members 'x' and 'y' (the position) and 'terrain' (the terrain type) and 'owner_side'.
So of course it's obvious what we need to do here.

---

Side note: I said this?
Pilauli wrote: October 12th, 2020, 3:52 pm this seems to work (it goes in the moveto event filter):

Code: Select all

[filter]
    side=1
    x2,y2=10,9 # village coordinates
[/filter]
It doesn't seem to work after all. I went and poked the wiki, and I found a way to properly use $x2 and $y2 (which are not, apparently, things you can just stuff in the filter like that).

Code: Select all

[event]
    name=moveto
    first_time_only=no
    [filter]
        side=1
        formula="$( ($x2=10) and ($y2=9) )"
    [/filter]
    [message]
        speaker=$village_holder_id
        message= _ "Wait a minute!  I've just abandoned my post!?  I've got to get back there!"
    [/message]
[/event]
It seems to work! (By which I mean that it only triggers when a unit moves off the village, and not otherwise. Much better than triggering every single time any side 1 unit moves.)
Reference: https://wiki.wesnoth.org/Wesnoth_Formula_Language

---

Writing WML for other people is fun, because I like writing WML, it's not a project I'm already tired of, and I get to feel good about helping people.
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Checking ownership of village

Post by Helmet »

The code works great! I had tried to apply store_villages to the problem following Pentarctagon's remark, but couldn't get it to work. Thanks for explaining what store_villages does and how to use it.

Man, I wish I could add a line of code to make all arrays start with a 1 instead of a 0.
Pilauli wrote: October 12th, 2020, 8:56 pm Side note: I said this?
Pilauli wrote: October 12th, 2020, 3:52 pm this seems to work (it goes in the moveto event filter):

Code: Select all

[filter]
    side=1
    x2,y2=10,9 # village coordinates
[/filter]
It doesn't seem to work after all. I went and poked the wiki, and I found a way to properly use $x2 and $y2 (which are not, apparently, things you can just stuff in the filter like that).
---
I thought it worked. I may've pasted it in the wrong place, though, so it never came into play. Thanks for the revised code.
Pilauli wrote: October 12th, 2020, 8:56 pm Writing WML for other people is fun, because I like writing WML, it's not a project I'm already tired of, and I get to feel good about helping people.
Thanks for your help! You are really good at explaining your code so that it makes sense. I appreciate that. I want to learn so that I don't keep making the same mistakes.

It can be frustrating wanting to accomplish something with WML, but lacking the know-how. The Wiki is a huge help, but is also deficient in examples. Nothing beats an example. Knowing which tag to use is vital, sure, but oftentimes the problem requires more information than that, like knowing which filter to use, or when to not use a filter, and so forth. I often put things in the wrong order. Line 3 should be below line 5, line 6 should be in a separate tag. A good example removes a lot of confusion and guesswork.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
User avatar
lhybrideur
Posts: 369
Joined: July 9th, 2019, 1:46 pm

Re: Checking ownership of village

Post by lhybrideur »

Helmet wrote: October 12th, 2020, 1:40 pm
lhybrideur wrote: October 12th, 2020, 11:38 am (use a filter and a filter_location): turns_on_village++
...
If you want, I can write that in WML but it is pretty straightforward.
Pilauli's code worked. But, if you don't mind, I would like to see the code you envisioned -- at least some of it. I had spent a long time trying to get filter and filter_location to work, but couldn't. I would like to know what the correct code looks like. I clearly need a better understanding of those tags. For a while, I got rid of all the other villages on the map except the special village, to make filtering the village easier, but it didn't help.
Ok I will try. It won't be tested though.

Code: Select all

[event]
	name=prestart

	{VARIABLE turns_on_village 0}
[/event]
[event]
	name=side 1 turn end
	first_time_only=no

	[if]
		[not]
			[have_unit]
				side=1
				[filter_location]
					x=3
					y=9
				[/filter_location]
			[/have_unit]
		[/not]
		[then]
			[message]
				speaker=Leader_name
				message="Oh no! We lost the village after $turns_on_village turns"
			[/message]
			{VARIABLE turns_on_village 0}
		[/then]
		[else]
			{VARIABLE_OP turns_on_village add 1}
		[/else]
	[/if]
	[if]
		[variable]
			name=turns_on_village
			greater_than_equal_to=3
		[/variable]
		[then]
			[message]
				speaker=Leader_name
				message="Hurray! We did it"
			[/message]
			[endlevel]
				bonus=no
				result=victory
			[/endlevel]
		[/then]
	[/if]
[/event]
This should do the job. If you want the unit that was on the village to tell the message or smth fancier, it would be more complicated though.
I assumed here your village is on 3,9 and that any unit could capture it.
If you want a special unit to capture it, add id=id_of_the_special_unit or any relevant filter btw side=1 and [filter_location]

P.S.: don't forget to clear the variable with a {CLEAR_VARIABLE turns_on_village} in a name=victory event.
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Checking ownership of village

Post by Helmet »

Thank you. That's an interesting solution. The basic structure looks like something that I can apply to another situation involving a counter.

Thanks for making it clear which part goes into prestart and reminding me to clear the variable.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Post Reply