unit ends a move on a specific terrain type?

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
Ditto
Posts: 35
Joined: June 27th, 2009, 3:25 pm

unit ends a move on a specific terrain type?

Post by Ditto »

Basically, I'm creating a new unit (not important at this time), and I want something to happen if this unit is left on a specific terrain type.

Specifically: it is allowed to move across Deep Water (Wo), but if it ends it's move there, it drowns .. (ie kill it). (for now, we'll just use a Gryphon, as it can move across Deep Water ..)

I used this code to find the condition:

[filter]
type=Gryphon
[filter_location]
terrain=Wo
[/filter_location]
[/filter]

I know about the [kill] tag, but not sure how to use it, or if it uses filters "properly" ..

I tried the [select] event, but it seemed to only detect the unit if it started on Deep Water .. it didn't fire when it ended it's move on Deep Water ..

So, I tried event "side turn" .. figured at the start of anyone's turn .. I'll just look for ANY gryphon on Deep water .. and kill it ..

Wow .. bad idea .. it nuked ALL creatures, (gryphon or not .. Deep water or not), and threw the game into a loop .. screen flashing, round counter climbed to about 200 before I managed to kill the process.
yikes.

Anyway, I know of the tag: "fire_event=no" in the [kill] tag .. but that didn't seem to stop the getaway loop ..

any ideas?
User avatar
Huston
Posts: 1070
Joined: April 29th, 2009, 8:26 pm
Location: Somewhere in this World(I Think)

Re: unit ends a move on a specific terrain type?

Post by Huston »

try something like this:

Code: Select all

[event]
    name=moveto
    first_time_only=no
    [filter]
        type=Gryphon
        [filter_location]
            terrain=Wo
        [/filter_location]
    [/filter]
    [kill]
        type=gryphon
        animate=no
    [/kill]
[/event]
this should work. only thing is... the way i wrote it, it will kill all the gryphons.
so you'll need to modify it a little
coded Rebellion During the Dark Age
Currently working on:
Era of the Future
User avatar
TofuOgre
Posts: 23
Joined: April 25th, 2009, 12:25 am

Re: unit ends a move on a specific terrain type?

Post by TofuOgre »

It would kill them all wouldn't it. That could be useful. It would need a few if-then's to not do that.

The best example I found was UTBS 02_Across_the_Harsh_Sands.cfg

There's a macro called {FILTER}. Find #define APPLY_DEHYDRATION_EFFECT FILTER on line 364. It uses the [have_unit] tag to cause damage to a unit on sand during the daytime.
User avatar
melinath
Posts: 1298
Joined: May 20th, 2009, 7:42 am

Re: unit ends a move on a specific terrain type?

Post by melinath »

The Dehydration effect is much more complicated. This is very simple.
Here's how to kill the Gryphon that just moved onto deep water:
Spoiler:
Here's how to kill all of a player's units in deep water at the beginning of their turn:
Spoiler:
Ditto
Posts: 35
Joined: June 27th, 2009, 3:25 pm

Re: unit ends a move on a specific terrain type?

Post by Ditto »

Got it!!

Code: Select all

[multiplayer]
   id=test_water
   name= _"test_water"
   description= _"test_water"
   victory_when_enemies_defeated=no
   map_data="{/multiplayer/maps/tester.map}"

   {DEFAULT_SCHEDULE}

   [side]
      side=1
      id=Spider
      name=Spider
      type=Giant Spider
      canrecruit=yes
      fog=no
      shroud=no
      
      [unit]
         type=Gryphon
         id=Gryp1
         name=Gryp2
         x,y=5,5
      [/unit]
   [/side]

   [side]
      side=2
      type=Giant Scorpion
      id=Scorpion
      name=Scorpion
      canrecruit=yes
      fog=no
      shroud=no
      
      [unit]
         type=Gryphon
         id=Gryp2
         name=Gryp2
         x,y=5,15
      [/unit]
   [/side]

   [event]
      name=side turn
      first_time_only=no
      
      [store_unit]
         [filter]
            type=Gryphon
            [filter_location]
               terrain=Wo
            [/filter_location]
         [/filter]
         variable=MODIFY_UNIT_store
         kill=yes
      [/store_unit]
      
      {FOREACH MODIFY_UNIT_store MODIFY_UNIT_i}
         {DEBUG_MSG "$MODIFY_UNIT_store[$MODIFY_UNIT_i].name has drowned!"}

      {NEXT MODIFY_UNIT_i}
      
      {CLEAR_VARIABLE MODIFY_UNIT_store}
   [/event]
   
[/multiplayer]
This seems to work well enough ..

Thanks!
Last edited by Ditto on July 2nd, 2009, 12:27 am, edited 1 time in total.
User avatar
melinath
Posts: 1298
Joined: May 20th, 2009, 7:42 am

Re: unit ends a move on a specific terrain type?

Post by melinath »

Hmm... that is a nice solution. Incidentally, putting code in a

Code: Select all

[code] tag makes it much easier to read
.
Ditto
Posts: 35
Joined: June 27th, 2009, 3:25 pm

Re: unit ends a move on a specific terrain type?

Post by Ditto »

melinath wrote:Hmm... that is a nice solution. Incidentally, putting code in a

Code: Select all

[code] tag makes it much easier to read
.
Right .. forgot ... fixed!
:D

Ok, now the next question to this is .. how do I "imbed" this into a new unit_type?

ie I create a new unit type, create the file and drop it in ./units.
Can I imbed this event somehow so that it gets included anywhere a unit of that type gets used?

Or do I have to use macros and rely on the tag being added "manually" with the scenario?
User avatar
melinath
Posts: 1298
Joined: May 20th, 2009, 7:42 am

Re: unit ends a move on a specific terrain type?

Post by melinath »

UnitTypeWML - look under "other tags"
Ditto
Posts: 35
Joined: June 27th, 2009, 3:25 pm

Re: unit ends a move on a specific terrain type?

Post by Ditto »

melinath wrote:UnitTypeWML - look under "other tags"
Of course!!
:oops:

Thanks!!
I'll try that when I get a chance ..
User avatar
A Guy
Posts: 793
Joined: May 24th, 2008, 1:55 am

Re: unit ends a move on a specific terrain type?

Post by A Guy »

Alternatively, you could've done the following:

Code: Select all

    [kill]
        type=Gryphon
        side=$side_number
        fire_event=yes
        [filter_location]
            terrain=Wo
        [/filter_location]
    [/kill][event]
    name=new turn
    first_time_only=no
    [if]
        [have_unit]
            type=Gryphon
            side=$side_number
            [filter_location]
                terrain=Wo
            [/filter_location]
        [/have_unit]
        [then]
            [message]
                speaker=narrator
                side_for=$side_number
                message= _  "Gryphons that you had over deep water have drowned!"
            [/message]
        [/then]
    [/if]
[/event]
Note: fire_event=yes is important in a [kill] tag if you want any events that would happen upon the death of the units to occur. Otherwise, if a player should lose if a mission-critical gryphon dies, the player doesn't lose if it gets killed by the [kill] tag.
I'm just... a guy...
I'm back for now, I might get started on some work again.
Ditto
Posts: 35
Joined: June 27th, 2009, 3:25 pm

Re: unit ends a move on a specific terrain type?

Post by Ditto »

A Guy wrote:Alternatively, you could've done the following:

Code: Select all

    [kill]
        type=Gryphon
        side=$side_number
        fire_event=yes
        [filter_location]
            terrain=Wo
        [/filter_location]
    [/kill][event]
    name=new turn
    first_time_only=no
    [if]
        [have_unit]
            type=Gryphon
            side=$side_number
            [filter_location]
                terrain=Wo
            [/filter_location]
        [/have_unit]
        [then]
            [message]
                speaker=narrator
                side_for=$side_number
                message= _  "Gryphons that you had over deep water have drowned!"
            [/message]
        [/then]
    [/if]
[/event]
Note: fire_event=yes is important in a [kill] tag if you want any events that would happen upon the death of the units to occur. Otherwise, if a player should lose if a mission-critical gryphon dies, the player doesn't lose if it gets killed by the [kill] tag.
I did try this, couldn't get it to work .. so I'll stick with the other logic .. :) Thanks anywhom.
User avatar
A Guy
Posts: 793
Joined: May 24th, 2008, 1:55 am

Re: unit ends a move on a specific terrain type?

Post by A Guy »

Oh, I forgot the closing tag for the previous event you put the [kill] tag in. It works for me, anyways.
I'm just... a guy...
I'm back for now, I might get started on some work again.
Post Reply