Dynamically remove default amla from some unit_type

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
hyper_cubed
Posts: 28
Joined: March 31st, 2018, 7:52 pm

Dynamically remove default amla from some unit_type

Post by hyper_cubed » April 6th, 2018, 3:10 am

I have some great codebase that I have successfully tested.

I am currently building a dynamic amla framework that adds amlas based on conditionals.

I am having a problem removing the default amla however. The code I wrote seems valid, but upon inspecting it in the state inspector I see that I wasn't successful in removing the default amla.

Has anyone on this forum been successful in removing default amlas?

Code: Select all

#textdomain wesnoth-WRPG_DynAmla

#define remove_default_amla
[store_unit]
	variable=unit_remove_amla
	kill=no
	[filter]
		x,y=$x1,$y1
		[filter_wml]
			id=$unit.id
		[/filter_wml]
	[/filter]
[/store_unit]
{VARIABLE p 0}
[while]
	[variable]
		name="p"
		less_than=$advancements_array.length
	[/variable]
	[do]
		[if]
			[variable]
				name=advancements_array[$p].id
				equals="amla_default"
			[/variable]
			[then]
				{VARIABLE check_advancement $advancements_array[$p].id}
			[/then]
		[/if]
	{VARIABLE_OP p add 1}
	[/do]
[/while]
{CLEAR_VARIABLE p}
[if]
	[variable]
		name=check_advancement
		equals="amla_default"
	[/variable]
	[then]
		[unit]
			advances_to=$unit_remove_amla[0].advances_to
			alignment=$unit_remove_amla[0].alignment
			attacks_left=$unit_remove_amla[0].attacks_left
			canrecruit=$unit_remove_amla[0].canrecruit
			cost=$unit_remove_amla[0].cost
			experience=$unit_remove_amla[0].experience
			extra_recruit=$unit_remove_amla[0].extra_recruit
			facing=$unit_remove_amla[0].facing
			flag_rgb=$unit_remove_amla[0].flag_rgb
			gender=$unit_remove_amla[0].gender
			generate_name=$unit_remove_amla[0].generate_name
			goto_x=$unit_remove_amla[0].goto_x
			goto_y=$unit_remove_amla[0].goto_y
			halo=$unit_remove_amla[0].halo
			hidden=$unit_remove_amla[0].hidden
			hitpoints=$unit_remove_amla[0].hitpoints
			id=$unit_remove_amla[0].id
			image=$unit_remove_amla[0].image
			image_icon=$unit_remove_amla[0].image_icon
			jamming=$unit_remove_amla[0].jamming
			#textdomain wesnoth-units
			language_name=$unit_remove_amla[0].language_name
			level=$unit_remove_amla[0].level
			max_attacks=$unit_remove_amla[0].max_attacks
			max_experience=$unit_remove_amla[0].max_experience
			max_hitpoints=$unit_remove_amla[0].max_hitpoints
			max_moves=$unit_remove_amla[0].max_moves
			moves=$unit_remove_amla[0].moves
			name=$unit_remove_amla[0].name
			overlays=$unit_remove_amla[0].overlays
			profile=$unit_remove_amla[0].profile
			race=$unit_remove_amla[0].race
			random_traits=$unit_remove_amla[0].random_traits
			recall_cost=$unit_remove_amla[0].recall_cost
			resting=$unit_remove_amla[0].resting
			role=$unit_remove_amla[0].role
			side=$unit_remove_amla[0].side
			small_profile=$unit_remove_amla[0].small_profile
			type=$unit_remove_amla[0].type
			undead_variation=$unit_remove_amla[0].undead_variation
			underlying_id=$unit_remove_amla[0].underlying_id
			unrenamable=$unit_remove_amla[0].unrenamable
			upkeep=$unit_remove_amla[0].upkeep
			usage=$unit_remove_amla[0].usage
			variation=$unit_remove_amla[0].variation
			vision=$unit_remove_amla[0].vision
			x=$unit_remove_amla[0].x
			y=$unit_remove_amla[0].y
			zoc=$unit_remove_amla[0].zoc
			[insert_tag]
				name=movement_costs
				variable=$unit_remove_amla[0].movement_costs
			[/insert_tag]
			[insert_tag]
				name=defense
				variable=$unit_remove_amla[0].defense
			[/insert_tag]
			[insert_tag]
				name=resistance
				variable=$unit_remove_amla[0].resistance
			[/insert_tag]
			[insert_tag]
				name=modifications
				variable=$unit_remove_amla[0].modifications
			[/insert_tag]
			[insert_tag]
				name=variables
				variable=$unit_remove_amla[0].variables
			[/insert_tag]
			[insert_tag]
				name=filter_recall
				variable=$unit_remove_amla[0].filter_recall
			[/insert_tag]
			[insert_tag]
				name=status
				variable=$unit_remove_amla[0].status
			[/insert_tag]
			[insert_tag]
				name=abilities
				variable=$unit_remove_amla[0].abilities
			[/insert_tag]
			to_variable=kill_default_amla
		[/unit]
		[unstore_unit]
			variable=kill_default_amla
			find_vacant=no
		[/unstore_unit]
		{CLEAR_VARIABLE kill_default_amla}
	[/then]
[/if]
{CLEAR_VARIABLE unit_remove_amla}
#enddef

User avatar
Ravana
Moderator
Posts: 1816
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Dynamically remove default amla from some unit_type

Post by Ravana » April 6th, 2018, 10:36 am

advancements_array is not assigned.

hyper_cubed
Posts: 28
Joined: March 31st, 2018, 7:52 pm

Re: Dynamically remove default amla from some unit_type

Post by hyper_cubed » April 6th, 2018, 2:10 pm

Ravana wrote:
April 6th, 2018, 10:36 am
advancements_array is not assigned.
Hey Ravanna,
The advancements_array is assigned in other parts of the code (grabbed all advancement ids prior to this macro). I didn't want to post the whole thing as it is fairly large. I have my code broken out into files and macros. Thought it would be easier to post the code that I am trying to work on.

The code below attempts to unstore a unit that just post advanced (post_advance event is in another part of the code) after max level and leaves out the advancement tag (my hope was to create a unit that existed without the default amla). I am wondering if the wesnoth engine injects the default amla into advancing units every time a unit post advances.

The code that I am specifically interested in is the unit creation and unstore by virtue of omission of the advancement tag.

Code: Select all

		[unit]
			advances_to=$unit_remove_amla[0].advances_to
			alignment=$unit_remove_amla[0].alignment
			attacks_left=$unit_remove_amla[0].attacks_left
			canrecruit=$unit_remove_amla[0].canrecruit
			cost=$unit_remove_amla[0].cost
			experience=$unit_remove_amla[0].experience
			extra_recruit=$unit_remove_amla[0].extra_recruit
			facing=$unit_remove_amla[0].facing
			flag_rgb=$unit_remove_amla[0].flag_rgb
			gender=$unit_remove_amla[0].gender
			generate_name=$unit_remove_amla[0].generate_name
			goto_x=$unit_remove_amla[0].goto_x
			goto_y=$unit_remove_amla[0].goto_y
			halo=$unit_remove_amla[0].halo
			hidden=$unit_remove_amla[0].hidden
			hitpoints=$unit_remove_amla[0].hitpoints
			id=$unit_remove_amla[0].id
			image=$unit_remove_amla[0].image
			image_icon=$unit_remove_amla[0].image_icon
			jamming=$unit_remove_amla[0].jamming
			#textdomain wesnoth-units
			language_name=$unit_remove_amla[0].language_name
			level=$unit_remove_amla[0].level
			max_attacks=$unit_remove_amla[0].max_attacks
			max_experience=$unit_remove_amla[0].max_experience
			max_hitpoints=$unit_remove_amla[0].max_hitpoints
			max_moves=$unit_remove_amla[0].max_moves
			moves=$unit_remove_amla[0].moves
			name=$unit_remove_amla[0].name
			overlays=$unit_remove_amla[0].overlays
			profile=$unit_remove_amla[0].profile
			race=$unit_remove_amla[0].race
			random_traits=$unit_remove_amla[0].random_traits
			recall_cost=$unit_remove_amla[0].recall_cost
			resting=$unit_remove_amla[0].resting
			role=$unit_remove_amla[0].role
			side=$unit_remove_amla[0].side
			small_profile=$unit_remove_amla[0].small_profile
			type=$unit_remove_amla[0].type
			undead_variation=$unit_remove_amla[0].undead_variation
			underlying_id=$unit_remove_amla[0].underlying_id
			unrenamable=$unit_remove_amla[0].unrenamable
			upkeep=$unit_remove_amla[0].upkeep
			usage=$unit_remove_amla[0].usage
			variation=$unit_remove_amla[0].variation
			vision=$unit_remove_amla[0].vision
			x=$unit_remove_amla[0].x
			y=$unit_remove_amla[0].y
			zoc=$unit_remove_amla[0].zoc
			[insert_tag]
				name=movement_costs
				variable=$unit_remove_amla[0].movement_costs
			[/insert_tag]
			[insert_tag]
				name=defense
				variable=$unit_remove_amla[0].defense
			[/insert_tag]
			[insert_tag]
				name=resistance
				variable=$unit_remove_amla[0].resistance
			[/insert_tag]
			[insert_tag]
				name=modifications
				variable=$unit_remove_amla[0].modifications
			[/insert_tag]
			[insert_tag]
				name=variables
				variable=$unit_remove_amla[0].variables
			[/insert_tag]
			[insert_tag]
				name=filter_recall
				variable=$unit_remove_amla[0].filter_recall
			[/insert_tag]
			[insert_tag]
				name=status
				variable=$unit_remove_amla[0].status
			[/insert_tag]
			[insert_tag]
				name=abilities
				variable=$unit_remove_amla[0].abilities
			[/insert_tag]
			to_variable=kill_default_amla
		[/unit]
		[unstore_unit]
			variable=kill_default_amla
			find_vacant=no
		[/unstore_unit]

User avatar
Celtic_Minstrel
Developer
Posts: 1189
Joined: August 3rd, 2012, 11:26 pm
Contact:

Re: Dynamically remove default amla from some unit_type

Post by Celtic_Minstrel » April 9th, 2018, 2:19 am

In 1.13.x, it's a lot easier to manage advancements in this kind of way. For example, if you're working entirely in WML, you can use an [object] to add and remove advancements (though that won't be optimal if you're doing a lot of adding and removing and re-adding and stuff on particular units). If you're open to using Lua, you can also remove the default AML with a call such as unit:remove_modifications({id = 'amla_default'}, "advancement").
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.

hyper_cubed
Posts: 28
Joined: March 31st, 2018, 7:52 pm

Re: Dynamically remove default amla from some unit_type

Post by hyper_cubed » April 9th, 2018, 12:52 pm

Celtic_Minstrel wrote:
April 9th, 2018, 2:19 am
In 1.13.x, it's a lot easier to manage advancements in this kind of way. For example, if you're working entirely in WML, you can use an [object] to add and remove advancements (though that won't be optimal if you're doing a lot of adding and removing and re-adding and stuff on particular units). If you're open to using Lua, you can also remove the default AML with a call such as unit:remove_modifications({id = 'amla_default'}, "advancement").
Hey Celtic_Minstrel,

It may help to describe what I am doing with my mod.
stage 1: unit advances to max level.
stage 2: my mod uses a small set of conditionals to decide what amla to "inject" into the unit that becomes an option to advances into.
stage 3: unit AMLAs and see the options that it qualified for.

@ stage 2 I am achieving this by using unit definition to create a "class" to "spec" into:
for example:
My first AMLA I created was an AMLA called "Heavy_Warrior". A unit must have no more than 5 movement points, and an impact and blade resistance of at least 20 to qualify for the injection (dynamically meaning any unit regardless of [advancement] defined in the [unit_type].

I was successful in injecting an amla, but couldn't remove the default (I don't want that as an option when a player AMLAs). Will that lua snippet allow me to remove the defaul amla at the [advancement] tag, or will it just remove it at the [modifications].[advancement/advane] tag? I attached a picture of what I am attempting to address.
Attachments
Default_Amla_Issue.PNG

User avatar
Celtic_Minstrel
Developer
Posts: 1189
Joined: August 3rd, 2012, 11:26 pm
Contact:

Re: Dynamically remove default amla from some unit_type

Post by Celtic_Minstrel » April 10th, 2018, 2:46 am

The Lua snippet I posted would be for removing (ie, undoing) an AMLA that has already been selected. For removing the default AMLA as an option, I'd suggest adopting the other approach I mentioned, which is to use an object something like this:

Code: Select all

    [object]
        [effect]
            apply_to=remove_advancement
            amlas=aml_default
        [/effect]
    [/object]
If you're using that in an event you'll also need a [filter] tag in [object] specifying who to apply it to (most likely the unit just created in a "unit placed" event).
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.

hyper_cubed
Posts: 28
Joined: March 31st, 2018, 7:52 pm

Re: Dynamically remove default amla from some unit_type

Post by hyper_cubed » April 18th, 2018, 4:50 pm

Celtic_Minstrel wrote:
April 10th, 2018, 2:46 am
The Lua snippet I posted would be for removing (ie, undoing) an AMLA that has already been selected. For removing the default AMLA as an option, I'd suggest adopting the other approach I mentioned, which is to use an object something like this:

Code: Select all

    [object]
        [effect]
            apply_to=remove_advancement
            amlas=aml_default
        [/effect]
    [/object]
If you're using that in an event you'll also need a [filter] tag in [object] specifying who to apply it to (most likely the unit just created in a "unit placed" event).
Thank you again guys for your direction. I ended up modifying the existing default amla and that solved my problem (it was the solution that I didn't know that I wanted).

I am trying to make this as 1.12 friendly as possible as I am sure some would want to try this modification out on eras that are not yet migrated.

User avatar
Celtic_Minstrel
Developer
Posts: 1189
Joined: August 3rd, 2012, 11:26 pm
Contact:

Re: Dynamically remove default amla from some unit_type

Post by Celtic_Minstrel » April 19th, 2018, 2:38 am

A 1.12-friendly method to remove the default AMLA as an option would probably be something like the following (untested):

Code: Select all

[store_unit]
    # Whatever filter you want; should match only one unit, use a loop if you need more
    variable=my_unit
[/store_unit]
[clear_variable]
    variable=my_unit.advancement[0] # Might need to be my_unit.advance[0], I forget which is correct
[/clear_variable]
That also assumes the unit does have the default AMLA; if you wanted to make sure they do, it would be a little more involved (you'd need {VARIABLE_CONDITIONAL my_unit.advance[$i].id equals amla_default} or some such in a loop).
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.

hyper_cubed
Posts: 28
Joined: March 31st, 2018, 7:52 pm

Re: Dynamically remove default amla from some unit_type

Post by hyper_cubed » April 22nd, 2018, 7:40 pm

Celtic_Minstrel wrote:
April 19th, 2018, 2:38 am
A 1.12-friendly method to remove the default AMLA as an option would probably be something like the following (untested):

Code: Select all

[store_unit]
    # Whatever filter you want; should match only one unit, use a loop if you need more
    variable=my_unit
[/store_unit]
[clear_variable]
    variable=my_unit.advancement[0] # Might need to be my_unit.advance[0], I forget which is correct
[/clear_variable]
That also assumes the unit does have the default AMLA; if you wanted to make sure they do, it would be a little more involved (you'd need {VARIABLE_CONDITIONAL my_unit.advance[$i].id equals amla_default} or some such in a loop).

Hey, I thought that at first as well, until the game just keep auto generating the default amla (I did extended variable testing to verify that (I could still be wrong). I know others have done it but I think maybe it is the way that I have things set up. Definitely not my biggest fish to fry, and I ended up favoring keeping the default (just repurposed it). It allows players to not be forced into choosing amlas they don't want to if my dynamic amlas ever run out.

Thank you for your attention guys.

User avatar
Celtic_Minstrel
Developer
Posts: 1189
Joined: August 3rd, 2012, 11:26 pm
Contact:

Re: Dynamically remove default amla from some unit_type

Post by Celtic_Minstrel » April 22nd, 2018, 11:04 pm

The 1.12-friendly way is indeed not entirely persistent. Any changes you make using [store_unit], [modify_unit], etc will only persist until the unit is "rebuilt", which can happen in a number of ways, most notably when they advance to a different unit type. So you'd need to somehow have events set up to watch for when the unit is "rebuilt" and remove the AMLA every time that happens.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.

Post Reply