Castle control

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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
Neuromancer
Posts: 204
Joined: September 10th, 2010, 9:49 pm

Castle control

Post by Neuromancer » December 10th, 2011, 11:01 am

Dark elves and humans are fighting over control of a city. In the city, there are several castles which can be controlled by each one of the belligerents. Each castle has its own recruit list, leader (these two variables change according to the ownership of the castle) and income. For example, one castle is controlled by elves. Elvish captain spawns at the keep, and each turn recruits some fighters and archers. Later the captain is killed. Human sergeant spawns at the keep and starts recruiting spearmen and archers.
Is there some way to achieve this besides of assigning different side to each of the castles?
Last edited by Neuromancer on January 5th, 2012, 8:55 pm, edited 2 times in total.

User avatar
Crendgrim
Moderator Emeritus
Posts: 1328
Joined: October 15th, 2010, 10:39 am
Location: Germany

Re: Castle control

Post by Crendgrim » December 10th, 2011, 12:44 pm

You could disallow the leaders on the castles to recruit, and manually select a random unit which spawns on the castle hexes. Of course, this approach is quite complicated to implement, but it may work.
UMC Story Images — Story images for your campaign!

User avatar
Xudo
Posts: 561
Joined: April 3rd, 2009, 5:26 pm

Re: Castle control

Post by Xudo » December 10th, 2011, 1:45 pm

You can try to handle "attack end" event.
Check hp of leader, if it < 0, teleport him to the next castle, change unit type, heal and recruitment pattern.

User avatar
Bonteaux
Posts: 22
Joined: November 10th, 2011, 6:49 pm

Re: Castle control

Post by Bonteaux » December 10th, 2011, 7:50 pm

Here's an idea:

1.) Give the leader units that spawn on the castles defined ids according to which castle they occupy, such as leader_castle_1, leader_castle_2 and so on
2.) Then make a "die" event (inside $unit is the one doing the dying, $second_unit is the killer):
- filter for id= leader_castle_1, leader_castle_2, ....
- store the $unit in a variable, then [kill] it , removing it from the game (and recall lists) so you can then
- spawn a leader [unit] from $second_unit.side and give it the $unit.id (it shouldn't give any id collusions, since the other unit with this id is already gone)

something like this (untested):

Code: Select all

[event]
    name=die
    first_time_only=no
    [filter]
        id=leader_castle_1,leader_castle_2
    [/filter]
    [store_unit]
        [filter]
            id=$unit.id
        [/filter]
        variable=prev_leader
    [/store_unit]
    [kill] # so it doesn't appear on the recall list
        [filter]
            id=$prev_leader.id
        [/filter]
    [/kill]
    [switch] # with a switch, you can easily extend this to more sides. Maybe the dwarves want the city as well later on :)
        # assumes side=1 => dark elves, side=2 => humans
        variable=prev_leader.side
        [case]
            value=2
            [unit]
                id=$prev_leader.id
                x,y=$prev_leader.x,$prev_leader.y
                type=Elvish Captain
                canrecruit=yes
                side=$second_unit.side
            [/unit]
        [/case]
        [case]
            value=1
            [unit]
                id=$prev_leader.id
                x,y=$prev_leader.x,$prev_leader.y
                type=Sergeant
                canrecruit=yes
                side=$second_unit.side
            [/unit]
        [/case]
    [/switch]
[/event]
"UM BROK HIT YOU!" -- Um Brok, Swamplings

User avatar
Neuromancer
Posts: 204
Joined: September 10th, 2010, 9:49 pm

Re: Castle control

Post by Neuromancer » January 4th, 2012, 7:47 pm

It works, but right after creating new leader, the game ends: "You have been defeated", the newly created leader the only unit on the map. I killed the previous leader with both human and AI-controlled sides and nothing changes.

User avatar
Bonteaux
Posts: 22
Joined: November 10th, 2011, 6:49 pm

Re: Castle control

Post by Bonteaux » January 5th, 2012, 3:33 pm

Hm, I think the problem is that [kill] doesn't need/understand [filter], so if you used the code as it was posted, the [kill] probably kills all everybody (ignoring the [filter]) and then the new leader is created, is of course the only unit that remains after the event, and thus wins the game. (I did write it was untested code though :) )

So, just get rid of the [filter] tags surrounding the id=$prev_leader.id in the [kill] tag, or I think you can get rid of the [kill] tag entirely and replace it with a kill=yes in the [store_unit].

OTOH, since this is the event where $prev_leader is dying, maybe you don't even need to kill it, since the whole point is just to keep it of the recall lists, where dead units usually don't end up anyway...
"UM BROK HIT YOU!" -- Um Brok, Swamplings

User avatar
artisticdude
Moderator Emeritus
Posts: 2424
Joined: December 15th, 2009, 12:37 pm
Location: Somewhere in the middle of everything

Re: Castle control

Post by artisticdude » January 5th, 2012, 3:46 pm

The [kill] tagset takes a SUF, but you cannot use the [filter] tagset.

Also remember that in the [store_unit] block you can make use of the kill= key (which takes a boolean value) to automatically kill the stored unit without having to add the [kill] tagset in order to kill the unit that was previously stored. So instead of this:

Code: Select all

[store_unit]
        [filter]
            id=$unit.id
        [/filter]
        variable=prev_leader
    [/store_unit]
    [kill] # so it doesn't appear on the recall list
        [filter]
            id=$prev_leader.id
        [/filter]
    [/kill]
you would write this:

Code: Select all

[store_unit]
        [filter]
            id=$unit.id
        [/filter]
        variable=prev_leader
#just add this key to kill the stored unit
        kill=yes
    [/store_unit]
"I'm never wrong. One time I thought I was wrong, but I was mistaken."

User avatar
Neuromancer
Posts: 204
Joined: September 10th, 2010, 9:49 pm

Re: Castle control

Post by Neuromancer » January 5th, 2012, 8:55 pm

Thank you guys.

Post Reply