Constant Mutation

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
Ghite
Posts: 23
Joined: July 7th, 2013, 11:28 pm

Constant Mutation

Post by Ghite »

I am trying to have an ability, gainable by amla, in which every side turn the unit gains a new random trait, but keeps its old ones.

I included these macros in the era, but nothing happens.

Code: Select all

#define AMLA_MUTATE
    [advancement]
	id=mutate
	always_display=true
	image="units/mutant.png"
	description="mutate"
	max_times=1
	[effect]
		apply_to=new_ability
		times=1
		[abilities]
			[dummy]
				id=unstability
				name="unstability"
				description="This unit will continuously mutate, changing it's attributes."
			[/dummy]
		[/abilities]
	[/effect]
    [/advancement]
#enddef

#define CHANGE_MUTATION
    [event]
        name=moveto
        first_time_only=no
	[allow_undo]
	[/allow_undo]
        [filter]
        [/filter]
        [set_variable]
		name=mutation
		rand=1-9
        [/set_variable]
    [/event]
#enddef

#define MUTATE
    [event]
        name=side turn
        first_time_only=no
	[if]
		[variable]
			name=mutation
			numerical_equals=1
		[/variable]
		[then]
			[modify_unit]
				[filter]
					ability=unstability
				[/filter]
				[modifications]
					{TRAIT_STRONG}
				[/modifications]
   			[/modify_unit]
		[/then]
	[/if]
	[if]
		[variable]
			name=mutation
			numerical_equals=2
		[/variable]
		[then]
			[modify_unit]
				[filter]
					ability=unstability
				[/filter]
				[modifications]
					{TRAIT_DEXTROUS}
				[/modifications]
   			[/modify_unit]
		[/then]
	[/if]
	[if]
		[variable]
			name=mutation
			numerical_equals=3
		[/variable]
		[then]
			[modify_unit]
				[filter]
					ability=unstability
				[/filter]
				[modifications]
					{TRAIT_RESILIENT}
				[/modifications]
   			[/modify_unit]
		[/then]
	[/if]
	[if]
		[variable]
			name=mutation
			numerical_equals=4
		[/variable]
		[then]
			[modify_unit]
				[filter]
					ability=unstability
				[/filter]
				[modifications]
					{TRAIT_INTELLIGENT}
				[/modifications]
   			[/modify_unit]
		[/then]
	[/if]
	[if]
		[variable]
			name=mutation
			numerical_equals=5
		[/variable]
		[then]
			[modify_unit]
				[filter]
					ability=unstability
				[/filter]
				[modifications]
					{TRAIT_QUICK}
				[/modifications]
   			[/modify_unit]
		[/then]
	[/if]
	[if]
		[variable]
			name=mutation
			numerical_equals=6
		[/variable]
		[then]
			[modify_unit]
				[filter]
					ability=unstability
				[/filter]
				[modifications]
					{TRAIT_WEAK}
				[/modifications]
   			[/modify_unit]
		[/then]
	[/if]
	[if]
		[variable]
			name=mutation
			numerical_equals=7
		[/variable]
		[then]
			[modify_unit]
				[filter]
					ability=unstability
				[/filter]
				[modifications]
					{TRAIT_AGED}
				[/modifications]
   			[/modify_unit]
		[/then]
	[/if]
	[if]
		[variable]
			name=mutation
			numerical_equals=8
		[/variable]
		[then]
			[modify_unit]
				[filter]
					ability=unstability
				[/filter]
				[modifications]
					{TRAIT_DIM}
				[/modifications]
   			[/modify_unit]
		[/then]
	[/if]
	[if]
		[variable]
			name=mutation
			numerical_equals=9
		[/variable]
		[then]
			[modify_unit]
				[filter]
					ability=unstability
				[/filter]
				[modifications]
					{TRAIT_SLOW}
				[/modifications]
   			[/modify_unit]
		[/then]
	[/if]
    [/event]
#enddef
Last edited by Ghite on August 7th, 2013, 10:42 pm, edited 1 time in total.
Ghite
Posts: 23
Joined: July 7th, 2013, 11:28 pm

Re: Constant Mutation

Post by Ghite »

Does anyone have an idea to fix this?
User avatar
Ravana
Forum Moderator
Posts: 3002
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Constant Mutation

Post by Ravana »

This moveto event looks like something that can cause oos.
As I hate using traits/[modification]/[modify_unit] I cant tell if that part is correct, I would use [object] to edit unit, or store/variables/unstore way.
Instead of that many [if] it is better to use [switch]
Where problem happens, you said nothing happens yet you have no debug messages in this code.
User avatar
A Guy
Posts: 793
Joined: May 24th, 2008, 1:55 am

Re: Constant Mutation

Post by A Guy »

Code: Select all

[event]
    name=new turn
    first_time_only=no
    [store_unit]
        [filter]
            # filter stuff here
        [/filter]
        variable=evolving
    [/store_unit]
    [set_variables]
        name=evolving.modifications.trait
        mode=append
        [value]
             #trait stuff here, without [trait] tag
        [/value]
    [/set_variables]
    [unstore_unit]
        variable=evolving
    [/unstore_unit]
[/event]
Try this out. I think it'll work if you put in the random factor. I typed this on my phone, so can't help you test it, sorry.
I'm just... a guy...
I'm back for now, I might get started on some work again.
User avatar
Heindal
Posts: 1355
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Re: Constant Mutation

Post by Heindal »

I for one don't like the manipulation of traits. You might want to use random abilities instead, as this is far easier to code.
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
User avatar
A Guy
Posts: 793
Joined: May 24th, 2008, 1:55 am

Re: Constant Mutation

Post by A Guy »

Heindal wrote:I for one don't like the manipulation of traits. You might want to use random abilities instead, as this is far easier to code.
Oh, yeah - that reminds me that changing traits directly hasn't worked for some time now.
I'm just... a guy...
I'm back for now, I might get started on some work again.
User avatar
trewe
Translator
Posts: 122
Joined: December 24th, 2012, 5:37 pm
Location: Portugal
Contact:

Re: Constant Mutation

Post by trewe »

Look at the mainline QUICK_4MP_LEADERS macro on how to manipulate traits.

Code: Select all

[event]
    name=recruit
    first_time_only=no

    [filter]
        ability=trait_mutation
    [/filter]

    # build an array of all available traits
    [set_variables]
        name=random_traits_$unit.id
        [literal]
            [trait]
                # first trait
            [/trait]
            [trait]
                # second trait
            [/trait]
            [trait]
                # another trait
            [/trait]
            [trait]
                # repeat at will
            [/trait]
        [/literal]
    [/set_variables]
[/event]

[event]
    name=side turn # this could cause OOS
    first_time_only=no

    [store_unit]
        [filter]
            ability=trait_mutation
            # side=$side_number ?
        [/filter]
        variable=unit
    [/store_unit]

    {FOREACH unit i_temp}
        # pick up one trait at random
        {RANDOM 1..$random_traits_$unit[$i_temp].id|.trait.length}
        {VARIABLE_OP random sub 1}

        # add it to the unit
        [set_variables]
            name=unit[$i_temp].modifications.trait
            mode=append # replace ?
            [insert_tag]
                name=literal
                variable=random_traits_$unit[$i_temp].id|.trait[$random]
            [/insert_tag]
        [/set_variables]

        # you may delete it to prevent it to be picked up twice
        {CLEAR_VARIABLE random_traits_$unit[$i_temp].id|.trait[$random]}

        # apply the changes
        [unstore_unit]
            variable=unit[$i_temp]
        [/unstore_unit]
    {NEXT i_temp}

    {CLEAR_VARIABLE unit,random}
[/event]
Something like the the above should work, change at will to fit your needs. btw, it is rand=1..9 instead 1-9 (two dots not an hyphen)
Post Reply