Counting owned villages in capture event.

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
JetScootr
Posts: 11
Joined: December 5th, 2022, 11:11 pm

Counting owned villages in capture event.

Post by JetScootr »

Each time side 1 captures a village, I want to count how many villages side 1 currently has. I can't keep a running total myself, because I won't get events when side 1's villages are recaptured by other sides. So, the idea is to store locations based on the terrain type "*^V*", count the hexes that are on side 1, and we're done.
Until I try it in a capture event. The capture event only appears to give me access to one village, ie, the village just captured.
Here's the code:

Code: Select all

[event]
	name=capture 
	first_time_only=no
	[filter]
		side=1
	[/filter]
	{DEBUG "T$turn_number| $unit.name| captured a village!"}
	[store_locations]
		variable=villages
		[filter]
			side=1
		[/filter]
		terrain=*^V*
	[/store_locations]
	{VARIABLE ownedvillagecnt $villages.length}
	:
	: 
" ownedvillagecnt " is always returned with the value 1, and sure enough, it's only got the village captured. How do I count owned villages in a capture event? Is this designed behavior or a bug or am I doing it wrong?
User avatar
Straff
Posts: 85
Joined: September 27th, 2020, 2:53 pm

Re: Counting owned villages in capture event.

Post by Straff »

Topic about counting villages:
viewtopic.php?t=56343
IceSandslash
Developer
Posts: 17
Joined: February 12th, 2023, 1:13 pm

Re: Counting owned villages in capture event.

Post by IceSandslash »

[filter] only checks whether a unit is currently there, and has no relationship to the village ownership (in fact, it's possible a unit rests in village without capturing it.) A better alternative with store_locations is mentioned in the thread linked by Straff. And you may also check the Wiki: https://wiki.wesnoth.org/InternalAction ... illages.5D
User avatar
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Counting owned villages in capture event.

Post by Celtic_Minstrel »

Try replacing [filter] with [filter_owner]. The former is asking for villages that have a side 1 unit on them; the latter is asking for villages that belong to side 1. So, your current filter is wrong even outside of a capture event.

Also, there's gives_income=yes which is recommended instead of filtering by terrain type. I can't remember if that's available in 1.16.x, though.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply