H2 change level of unit inside event?

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
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

H2 change level of unit inside event?

Post by Wussel »

A unit only getting AMLA should get a higher level than startimg level asigned after a few amlas. I want to do that inside a event which i allready use. Is that possible? I remember Kaleh/under burning sun getting level through amla directly.

I am thinking of giving the unit a higher level at distinct exp values. Can I include that in the post_advance event code?

something like
[unit]
level=2
[/unit]

Nothing else would change. Resilient would get a bonus and the upkeep should rise. More experience when defeated.
Wussel

Posts: 175
Joined: July 28th, 2012, 5:58 am
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: H2 change level of unit inside event?

Post by Dugi »

Kaleh does it via variations, his unit type has a load of variations and AMLA always changes his variation, and some variations have a greater level than others. EffectWML can be used to change variations, so you can use it to switch to some variations that are identical everywhere except level. Kaleh's code is somewhat obfuscated with macros, but it can be deciphered.

Variations have an unpleasant inconvenience that they bloat the save files. At some point, I realised that most of the contents of my campaign's save files were Walking Corpses on recall list (as you probably know, they have a load of variations).

You can alternatively create a post advance event that would check the number of advancements the unit has taken (can be read easily by accessing the $unit.modifications.advance.length field) and set its level appropriately.
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

Re: H2 change level of unit inside event?

Post by Wussel »

I want to do what you described as the last option. I can do all the rest but would like to know:

H2 "set its level appropriately" inside post_advance event.
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: H2 change level of unit inside event?

Post by Dugi »

This should be the simplest way to do it:

Code: Select all

[event]
 name=post advance
 id=increase level  # The id has no actual meaning, unique ids just prevent duplication
 first_time_only=no
 [filter]
  advances_to=null  # Affect only those who can't advance to other units
 [/filter]
 # We need to reset the level first to prevent accidents
 [store_unit_type]
  type=$unit.type
  variable=unit_type
 [/store_unit_type]
 [set_variable]
  name=unit.level
  value=$unit_type.level
 [/set_variable]
 {CLEAR_VARIABLE unit_type}
 # And increase it accordingly to the number of AMLAs taken
 [if]
  [variable]
   name=unit.modifications.advance.length
   greater_than_equal_to=5
  [/variable]  # If the unit advanced already five times, increase the level by one
  [then]
   [set_variable]
    name=unit.level
    add=1
   [/set_variable]
  [/then]
 [/if]
 [if]
  [variable]
   name=unit.modifications.advance.length
   greater_than_equal_to=12
  [/variable] # If the unit advanced 12 times, increase the level once again (ranges like 5-12 could be used, but the code would be longer with irrelevant performance gain)
  [then]
   [set_variable]
    name=unit.level
    add=1
   [/set_variable]
  [/then]
 [/if]
 #....
 [unstore_unit]
  variable=unit
  find_vacant=no
 [/unstore_unit]
[/event]
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

Re: H2 change level of unit inside event?

Post by Wussel »

As I said, i am allready happy with the filter I use. The only thing I need is the level advancement.

I did loose my fear of storing units some time ago. However I would prefer a simple solution of just seting the level if possible. Why are you using the varible unit_type? Does this create a sub type? Just changing a variable inside a specific unit would not be more easy and less consuming?
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: H2 change level of unit inside event?

Post by Dugi »

You'll have to tame the fear of storing units you've unleashed, because it's the only way to get the more advanced stuff done.

There aren't many ways to make it easier. Changes to level aren't based on EffectWML, are unstable and can be involuntarily undone in some cases and there has to be a way to recreate it from AMLA record (that means that increasing the level on fifth advancement and increasing the level on twelfth advancement again isn't stable). This is the simplest way to do it if you want to do it properly.

The variable unit_type is the code is a variable that holds the UnitWML of the unit_type of the unit that is advancing. It contains the basic stats of the unit type like level. By setting the unit's level to the level of unit_type, we reset all previous changes to its level so that we can do it anew without fear that some leftovers will persist and cause the level to increase every time the unit advances.
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

Re: H2 change level of unit inside event?

Post by Wussel »

I have this bunch of ifs in a post advance and added a minium selection of your code after the overlay stuff. I did not find a STORE_UNIT in your code! Is that ok?

Code: Select all

		[if]
			[variable]
				name=unit.max_experience
				numerical_equals=12
			[/variable]
			[then]
				[remove_unit_overlay]
					x,y=$x1,$y1
					image=overlays/ex-1.png
				[/remove_unit_overlay]
				[unit_overlay]
					x,y=$x1,$y1
					image=overlays/ex-2.png
				[/unit_overlay]
				[store_unit_type]
					type=$unit.type
					variable=unit_type
				[/store_unit_type]
				[set_variable]
					name=unit.level
					add=1
				[/set_variable]
				[unstore_unit]
					variable=unit
					find_vacant=no
				[/unstore_unit]
 			[/then]
		[/if]
Right now I do not care about stable. Would be cool if it just worked.
User avatar
James_The_Invisible
Posts: 536
Joined: October 28th, 2012, 1:58 pm
Location: Somewhere in the Northlands, fighting dark forces
Contact:

Re: H2 change level of unit inside event?

Post by James_The_Invisible »

Yes, it is. Units involved in an event are automatically stored to variables unit/second_unit.
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

Re: H2 change level of unit inside event?

Post by Wussel »

Does that mean I do not need the Store_unit_type either?

Obiviously I want the set_variables!

But if the unit is stored automatically, does it get unstored automatically too? Does this mean I do not need the unstore_unit part?
User avatar
Iris
Site Administrator
Posts: 6798
Joined: November 14th, 2006, 5:54 pm
Location: Chile
Contact:

Re: H2 change level of unit inside event?

Post by Iris »

No, they are not automatically unstored.
Author of the unofficial UtBS sequels Invasion from the Unknown and After the Storm.
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

Re: H2 change level of unit inside event?

Post by Wussel »

If the unit gets stored automatically, why do i have to unstore???

Code: Select all

[set_variable]
               name=unit.level
               add=1
            [/set_variable]
Is this the only thing I have to include in my if/then?
Vanagandr
Posts: 36
Joined: May 17th, 2014, 5:48 pm

Re: H2 change level of unit inside event?

Post by Vanagandr »

You have to unstore the variable to make the changes take effect.
I tested the following

Code: Select all

[event]
	name= attack end
	first_time_only= no
	
	[set_variable]
	   name=unit.level
	   add=1
	[/set_variable]
	[unstore_unit]
	   variable=unit
 	   find_vacant=no
	[/unstore_unit]
[/event]
and it works. I don't know what goes wrong if your above code doesn't work. What could be is that other events interfere with it.
If you don't care about stability you don't need store_unit_type, but you need unstore_unit, so the minimum you need is the set_variable and unstore_unit parts.
Wussel
Posts: 624
Joined: July 28th, 2012, 5:58 am

Re: H2 change level of unit inside event?

Post by Wussel »

Seems to be working fine. No stability issues so far. Only problem would be the level of a unit running away anyway? If I encounter issues i will come back. Otherwise solved.
Post Reply