Night-transforming unit

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.
ulfgur
Posts: 88
Joined: December 16th, 2008, 1:01 am

Night-transforming unit

Post by ulfgur »

Hello.

I have been trying and failing to create a unit that turns into a werewolf at night. So far, I'm just working on getting the animation to work. Here's what i have put in the unit...

[standing_anim]
start_time=-50
[filter]
time_of_day=chaotic
[/filter]
[frame]
image="units/noble/werewolf.png"
duration=50
[/frame]
[/standing_anim]

[standing_anim]
start_time=-50
[filter]
time_of_day=lawful
[/filter]
[frame]
image="units/noble/nobleman.png"
duration=50
[/frame]
[/standing_anim]
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Night-transforming unit

Post by zookeeper »

User avatar
Kapoue_II
Posts: 203
Joined: October 11th, 2010, 9:41 am

Re: Night-transforming unit

Post by Kapoue_II »

Look at the code in HTTT. There's a scenario in there where all the bad guys become undead at night, and loyalist in the day.
User avatar
Reepurr
Posts: 1088
Joined: August 29th, 2010, 5:38 pm

Re: Night-transforming unit

Post by Reepurr »

Kapoue_II wrote:Look at the code in HTTT. There's a scenario in there where all the bad guys become undead at night, and loyalist in the day.
And Liberty.

Anyway,

Code: Select all

[filter]
    [filter_location]
        time_of_day=lawful
    [/filter_location]
[/filter]
"What do you mean, "a dwarvish dragonguard with marksman is overpowered"?"

Story of a Drake Outcast | The Nonsense Era
Played HttT-Underground Channels? Thought it was rubbish? Help us develop it here!
ulfgur
Posts: 88
Joined: December 16th, 2008, 1:01 am

Re: Night-transforming unit

Post by ulfgur »

Brillliant! filter location tag worked. For anyone who ends up wanting to use the code, here it is:

Code: Select all

    [standing_anim]
[filter]
    [filter_location]
        time_of_day=chaotic
    [/filter_location]
[/filter]
        start_time=-50
        [frame]
            image="units/noble/werewolf.png"
            duration=50
        [/frame]
    [/standing_anim]
    [standing_anim]
[filter]
    [filter_location]
        time_of_day=lawful
    [/filter_location]
[/filter]
        start_time=-50
        [frame]
            image="units/noble/nobleman.png"
            duration=50
        [/frame]
    [/standing_anim]
    [standing_anim]
[filter]
    [filter_location]
        time_of_day=neutral
    [/filter_location]
[/filter]
        start_time=-50
        [frame]
            image="units/noble/nobleman.png"
            duration=50
        [/frame]
    [/standing_anim]
I had to filter time of day neutral, or else the game crashed when I tried to use the unit.
ulfgur
Posts: 88
Joined: December 16th, 2008, 1:01 am

Re: Night-transforming unit

Post by ulfgur »

Here's the next (and final) problem. The werewolf slightly increases speed at night, and gets leadership during the day. Here is what I tried.

Code: Select all

#define ABILITY_WEREWOLF_NIGHT
    # Canned definition of the werewolf ability to be included in an
    # [abilities] clause.
    [werewolf]
        id=werewolf
        name= _ "Werewolf"
        female_name= _ "Werewolf"
        description= _ "Werewolf:
the unit gets increased speed during the night."
        name_inactive= _ "Werewolf"
        female_name_inactive= _ "female^ Werewolf"
        description_inactive= _ "Werewolf:
the unit gets increased speed during the night."
        affect_self=yes
    	movement=7
        [filter_self]
            [filter_location]
                time_of_day=chaotic
            [/filter_location]
        [/filter_self]
    [/werewolf]
#enddef

#define ABILITY_WEREWOLF_DAY
    # Canned definition of the werewolf ability to be included in an
    # [abilities] clause.
    [werewolf]
        id=werewolfday
        name= _ "Werewolf"
        female_name= _ "Werewolf"
        description= _ "Werewolf:
the unit gets leadership during the day."
        name_inactive= _ "Werewolf"
        female_name_inactive= _ "female^ Werewolf"
        description_inactive= _ "Werewolf:
the unit gets leadership during the day."
    	{ABILITY_LEADERSHIP_LEVEL_1}
        affect_self=yes
        [filter_self]
            [filter_location]
                time_of_day=lawful
            [/filter_location]
        [/filter_self]
    [/werewolf]
#enddef

#define ABILITY_WEREWOLF_NEUTRAL
    # Canned definition of the werewolf ability to be included in an
    # [abilities] clause.
    [werewolf]
        id=werewolfneutral
        name= _ "Werewolf"
        female_name= _ "Werewolf"
        description= _ "Werewolf:
the unit gets leadership during the day."
        name_inactive= _ "Werewolf"
        female_name_inactive= _ "female^ Werewolf"
        description_inactive= _ "Werewolf:
the unit gets leadership during the day."
    	{ABILITY_LEADERSHIP_LEVEL_1}
        affect_self=yes
        [filter_self]
            [filter_location]
                time_of_day=neutral
            [/filter_location]
        [/filter_self]
    Proxy-Connection: keep-alive
Cache-Control: max-age=0

werewolf]
#enddef
User avatar
beetlenaut
Developer
Posts: 2825
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Night-transforming unit

Post by beetlenaut »

I'm not sure how you're using these macros, but I can't think of a way you could use them that works. Macros are expanded just once when the scenario or unit_type is loaded, so you can't call them like functions. The best way to do what you want is to make two different unit types and then use the TRANSFORM_UNIT macro in unit-utils.cfg to switch back and forth. (It preserves XP, HP, and status.) This is what is done in Liberty's fourth scenario, "Unlawful Orders", so you could check that out.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
Reepurr
Posts: 1088
Joined: August 29th, 2010, 5:38 pm

Re: Night-transforming unit

Post by Reepurr »

Yeah, and FYI Liberty works pretty bleeping well. However, that might result in you being confused over where your unit is, so perhaps not.

Here's what I'd try.

Code: Select all

#define ABILITY_WEREWOLF_NIGHT
    # Canned definition of the werewolf ability to be included in an
    # [abilities] clause.
    [dummy]
        id=werewolf
        name= _ "Werewolf"
        female_name= _ "Werewolf"
        description= _ "Werewolf:
the unit gets increased speed during the night."
        name_inactive= _ "Werewolf"
        female_name_inactive= _ "female^ Werewolf"
        description_inactive= _ "Werewolf:
the unit gets increased speed during the night."
    [/dummy]
    [/abilities]
# important bit here
[event]
    name=new turn
    first_time_only=no
    {MODIFY_UNIT ( type=Werewolf
            [filter_location]
                time_of_day=chaotic
            [/filter_location] ) movement 7}
[/event]
[+abilities]
#enddef
There's some sort of max_movement you can use I believe, but I forgot exactly what it's called.
Also, there is no such tag as [werewolf] so it won't do anything, it'll just behave like a [dummy] tag, and you can't just insert movement=7 into an ability, there's no such string that the ability will recognise. That's what I understand, anyway, based on what I've read.
"What do you mean, "a dwarvish dragonguard with marksman is overpowered"?"

Story of a Drake Outcast | The Nonsense Era
Played HttT-Underground Channels? Thought it was rubbish? Help us develop it here!
ulfgur
Posts: 88
Joined: December 16th, 2008, 1:01 am

Re: Night-transforming unit

Post by ulfgur »

I would like to note at this point that, being only amateur in coding, we are really getting into code I don't know. That's why I was making it an ability, i kind of know how it works. :P

Okay, I tried copying/pasting Reepur's code into abilities and making a separate werewolf unit, and the game told me I had a missing closing tag for abilities in the nobleman unit. I don't. :hmm: Since I am clueless about the coding, I'm having trouble fixing it.
User avatar
bigkahuna
Posts: 657
Joined: September 11th, 2010, 6:24 pm
Location: In your mind.

Re: Night-transforming unit

Post by bigkahuna »

Code: Select all

    [dummy]
        id=werewolf
        name= _ "Werewolf"
        female_name= _ "Werewolf"
        description= _ "Werewolf:
the unit gets increased speed during the night."
        name_inactive= _ "Werewolf"
        female_name_inactive= _ "female^ Werewolf"
        description_inactive= _ "Werewolf:
the unit gets increased speed during the night."
    [/dummy]
    [/abilities]
Notice the [/abilities] stuck on the end. Take that out.

To use this, place it in the [abilities] tag of the nobleman as so:

Code: Select all

[abilities]
    {ABILITY_WEREWOLF_NIGHT}
[/abilities]
Check out my campaign Sweet Revenge!
Join the new R2D forum!
ulfgur
Posts: 88
Joined: December 16th, 2008, 1:01 am

Re: Night-transforming unit

Post by ulfgur »

Hrmmm. Now it doesn't transform at all.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Night-transforming unit

Post by Sapient »

bigkahuna wrote: Notice the [/abilities] stuck on the end. Take that out.
Wrong, it has to close abilities tag first to define an event. Then it re-opens it with [+abilities].
bigkahuna wrote: To use this, place it in the [abilities] tag of the nobleman
That much is correct.

However, you should really be doing the entire transformation with {TRANSFORM_UNIT} and using a second unit type as multiple people have already suggested. In fact, "werewolf" or night-transforming units were the very reason that macro was written.

Code: Select all

[unit_type]
  id=werewolf_day
  ...
  [event]
    name=new turn,recruit
    first_time_only=no
    [store_time_of_day]
    [/store_time_of_day]
    [if]
      [variable]
        name=time_of_day.lawful_bonus
        less_than=0
      [/variable]
      [then]
        {TRANSFORM_UNIT type=werewolf_day werewolf_night}
      [/then]
    [/if]
  [/event]
[/unit_type]
[unit_type]
  id=werewolf_night
  ...
  [event]
    name=new turn,recruit
    first_time_only=no
    [store_time_of_day]
    [/store_time_of_day]
    [if]
      [variable]
        name=time_of_day.lawful_bonus
        greater_than_equal_to=0
      [/variable]
      [then]
        {TRANSFORM_UNIT type=werewolf_night werewolf_day}
      [/then]
    [/if]
  [/event]
[/unit_type]
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
ulfgur
Posts: 88
Joined: December 16th, 2008, 1:01 am

Re: Night-transforming unit

Post by ulfgur »

Brilliant! Halfway there! That made the day version turn into the night version, but the night won't turn back into the day.

note: I would have used the TRANSFORM_UNIT, but the code in liberty was too complicated. In the act of digging through the code to find what i need, I would have broken something irreparably...
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Night-transforming unit

Post by Sapient »

ulfgur wrote:Brilliant! Halfway there! That made the day version turn into the night version, but the night won't turn back into the day.

note: I would have used the TRANSFORM_UNIT, but the code in liberty was too complicated. In the act of digging through the code to find what i need, I would have broken something irreparably...

I forgot to put first_time_only=no in the event

I fixed it now and made it a little more foolproof.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
ulfgur
Posts: 88
Joined: December 16th, 2008, 1:01 am

Re: Night-transforming unit

Post by ulfgur »

Okay, now it's working the other way. The werewolf will turn to the nobleman @ day, but the nobleman stubbornly refuses to be turned to a werewolf at night.
Post Reply