A few questions (change sides mid-scenaro, unit duplication)

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

A few questions (change sides mid-scenaro, unit duplication)

Post by Ken_Oh »

These are for an Undead campaign that I'm working on. I'm also quite the newbie so mass excuses for my ignorance and inability.

#1. Is it possible to change combat sides mid scenario? I'd like to give the option to turn against your master. Would I be able to do that mid-scenario or should I just give that option pre-scenario?

#2. Can you change the sides of specific units mid-scenario? Think of 2 Liches fighting for the control of the minds of undead units.

#3. I want to change the Walking Corpse line to have the ability to replicate itself when on a village. Think of it as an ability to harvest townsfolk unto Walking Corpses.

I'm a beginner with WML so I'm ripping the Mermen cages from the HttT Bay of Pearls campaign.

Here's what I've got: a small bit of code (which may very well be broken) that would be specific to each map in the campaign. Consider there is a village at coords 4,5.

Code: Select all

[event]
	name=new turn

		[filter]
		side=1
		x=4
		y=5
		type=Walking Corpse
		[/filter]

		[unit]
		side=1
		x=4
		y=6
		type=Walking Corpse
		[/unit]
	[/event]
The next questions:

4. Did I do anything glaringly stupid? Is this just not going to work?
5. Can those filters be used for "new turn"?
6. The "new turn" event means right before your own turn starts, right?
7. I didn't see any syntax for stuff I was looking for, like "or." I'd want to filter for WCs or Soullesses. How can I do that and is there a doc that I obviously missed?
8. How can I make it choose to place the WC somewhere else if coords 4,6 are already occupied?


I'd like to think that I'm not biting off more than I can chew for my first campaign. There are just a few options I'd like to work with to make it unique. The most desired of all is to make Walking Corpses more useful.

Any help is much appreciated.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: A few questions (change sides mid-scenaro, unit duplicat

Post by zookeeper »

All of those things (#1, #2, #3) can be done, even relatively easily. I'll write more about the details in a minute, stay tuned...
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: A few questions (change sides mid-scenaro, unit duplicat

Post by zookeeper »

Ken Oh wrote:#1. Is it possible to change combat sides mid scenario? I'd like to give the option to turn against your master. Would I be able to do that mid-scenario or should I just give that option pre-scenario?
Yes, that can be done. Use [modify_side] to set a different team_name for one of the allied sides. Since their team_names are no longer identical, they'll become enemies.
Ken Oh wrote:#2. Can you change the sides of specific units mid-scenario? Think of 2 Liches fighting for the control of the minds of undead units.
Grab the MODIFY_UNIT macro from the WML Utilities 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: Select all

{MODIFY_UNIT (type=Vampire Bat) side 3}
You should be able to see how to use macros and where to put them by looking at pretty much any user-made campaign.
Ken Oh wrote:#3. I want to change the Walking Corpse line to have the ability to replicate itself when on a village. Think of it as an ability to harvest townsfolk unto Walking Corpses.
The following would duplicate all side 2 walking corpses that are in a village at the start of side 2's turn (which I think is the most logical time). Note that you need the macros IF and IF_TERRAIN from the aforementioned page for this.

Code: Select all

[event]
    name=side turn
    first_time_only=no

    {IF side_number equals 2 (
        [then]
            [store_unit]
                [filter]
                    side=2
                    type=Walking Corpse
                [/filter]

                variable=temp
                kill=no
            [/store_unit]

            {FOREACH temp i}
                {VARIABLE_OP spawn_x format "$temp[$i].x"}
                {VARIABLE_OP spawn_y format "$temp[$i].y"}

                {IF_TERRAIN $spawn_x $spawn_y AaBbDeLptUVvYZ (
                    [then]
                        [unit]
                            type=Walking Corpse
                            side=1
                            x=$spawn_x
                            y=$spawn_y
                        [/unit]
                    [/then]
                )}
            {NEXT i}

            {CLEAR_VARIABLE temp}
        [/then]
    )}
[/event]
You might want to change the upkeep cost of the spawned unit to upkeep=full. While walking corpses are level 0 units and don't cost upkeep, they may level into soulless, which do cost. So I suggest adding that line to the [unit] tag, unless you want to give the player the ability to get lots of zero upkeep units.

That example, obviously, only makes the spawning work for side 2. So you might want to make it a macro, which takes the side as an argument, like this:

Code: Select all

#define VILLAGES_DUPLICATE_CORPSES SIDE
    # copypaste here all the above code, just replace occurrences of [i]side=2[/i] with [i]side={SIDE}[/i]
#enddef
And then you'd just put a {VILLAGES_DUPLICATE_CORPSES 1} in inside your [scenario], one per each side that should get the ability (that one gives it for side 1). With a little more tweaking you could make the macro to allow duplicating what ever unit types you want (and into what ever unit types you want), but we'll leave that as an exercise. :wink:
Ken Oh wrote:4. Did I do anything glaringly stupid? Is this just not going to work?
5. Can those filters be used for "new turn"?
No, new turn does not take any filters. Like the EventWML page says, new turn events always trigger when the last player finishes their turn.
Ken Oh wrote:6. The "new turn" event means right before your own turn starts, right?
In campaigns, the player practically always controls side 1, so yes.
Ken Oh wrote:7. I didn't see any syntax for stuff I was looking for, like "or." I'd want to filter for WCs or Soullesses. How can I do that and is there a doc that I obviously missed?
There isn't a direct "or", but you can use a [not] in [filter]s. Take a closer look at the FilterWML page, there are even a few good examples (rare!) of it's use there.
Ken Oh wrote:8. How can I make it choose to place the WC somewhere else if coords 4,6 are already occupied?
If you try to create a unit on top of another, the new unit will go to the nearest free hex instead, so you can just place it on top of the other one, like I did in the above example.
User avatar
Ken_Oh
Moderator Emeritus
Posts: 2178
Joined: February 6th, 2006, 4:03 am
Location: Baltimore, Maryland, USA

Post by Ken_Oh »

You are awesome.

I admit I haven't even looked at macroing at all, since I'm just getting into this stuff now. But, I'll take what you've given me and work from there. I hope to make something interesting with it.

Thanks a million!
User avatar
Ken_Oh
Moderator Emeritus
Posts: 2178
Joined: February 6th, 2006, 4:03 am
Location: Baltimore, Maryland, USA

Post by Ken_Oh »

OK, I spent a lot of today trying to work this out and haven't been able to make WCs duplicate themselves. I tried to build the macro like you suggested and put it into the scenario as such:

Code: Select all


#define VILLAGES_DUPLICATE_CORPSES SIDE    
	[event]
		name=side turn
		first_time_only=no

		{IF side_number equals {SIDE} (
			[then]
				[store_unit]
					[filter]
						side={SIDE}
						type=Walking Corpse
					[/filter]

					variable=temp
					kill=no
				[/store_unit]

				{FOREACH temp i}
					{VARIABLE_OP spawn_x format "$temp[$i].x"}
					{VARIABLE_OP spawn_y format "$temp[$i].y"}

					{IF_TERRAIN $spawn_x $spawn_y AaBbDeLptUVvYZ (
						[then]
							[unit]
								type=Walking Corpse
								upkeep=full
								side={SIDE}
								x=$spawn_x
								y=$spawn_y
							[/unit]
						[/then]
					)}
				{NEXT i}

				{CLEAR_VARIABLE temp}
			[/then]
		)}
	[/event]
#enddef

{VILLAGES_DUPLICATE_CORPSES 1}

I'm just too newbie to have built something like that myself. I think I see what you did, but it's just not working for me yet. I even put down a line of AaBbDeLptUVvYZ in a map to see if it would work.

I'll keep cracking with this but I'm afraid it's a little too over my head for me to see anything obvious.

FYI, I am using v1.1.1, if that makes a difference.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Post by zookeeper »

I tested the code in 1.1.1 myself and it seemed to work ok. Have you included the IF and IF_TERRAIN macros in your code somewhere? If not, just copypaste them (from the WML Utilities page) somewhere above your #define VILLAGES_DUPLICATE_CORPSES so they are actually available.
User avatar
Ken_Oh
Moderator Emeritus
Posts: 2178
Joined: February 6th, 2006, 4:03 am
Location: Baltimore, Maryland, USA

Post by Ken_Oh »

That was it!

Thanks. I guess that shows I didn't really know what's going on. It's much better now. It works perfectly.

Thanks again!
Post Reply