Modifying Core Units

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
User avatar
s1m0n
Posts: 53
Joined: May 7th, 2020, 1:55 pm
Location: Irdya

Modifying Core Units

Post by s1m0n »

Is there a pre-wesnoth 1.15 possibility to modify the units from the core game within a UMC?
I found this

Code: Select all

[modify_unit_type]
	type=Woodsman
	remove_advancement=Bowman
[/modify_unit_type]
working to force the Woodsman leveling up to a Hunter working in 1.15.2 and later

But my add-on is for 1.14 and I am not planning on changing its version until the next stable version is out (1.16)

I found a workaround by putting a slightly modified unit into the unit folder of the campaign, but I found that to be impractical every time I want to make a small change to a unit :mrgreen:
eh, what comes here again?
Pilauli
Posts: 115
Joined: August 18th, 2020, 12:56 pm

Re: Modifying Core Units

Post by Pilauli »

EDIT: There's a really simple way to do this. When you create the unit on the map (using the [unit] tag), include a line which says "advances_to=Poacher".
To quote the wiki...
advances_to: comma-separated list of unit types to which this unit can advance. Will override the default provided by the [unit_type]. This is generally not set manually.
(Source: https://wiki.wesnoth.org/SingleUnitWML)

I wrote some other stuff before, and I'll leave it here under a spoiler for reference.
Spoiler:
User avatar
WhiteWolf
Forum Moderator
Posts: 769
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: Modifying Core Units

Post by WhiteWolf »

Just as the wiki says: this is generally not set manually. Some unit properties are reset at times, for example when the unit is rebuilt for some reason, that's why it's generally not recommended to set it this way. It's a much better and safer approach to use an [object] with the appropriate [effect]'s to do this (in your example, it would be remove_advancement). If you want to apply it to every unit that appears, just have a unit_placed [event] apply the object to every instance of the unit.
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Pilauli
Posts: 115
Joined: August 18th, 2020, 12:56 pm

Re: Modifying Core Units

Post by Pilauli »

So the really-simple-looking method was too good to be true. Darn.

Objects (which I have no experience with) are probably the best way to do it, then.

I see that remove_advancement is marked "Version 1.13.2 and later only", which shouldn't be a problem for 1.14.
User avatar
s1m0n
Posts: 53
Joined: May 7th, 2020, 1:55 pm
Location: Irdya

Re: Modifying Core Units

Post by s1m0n »

Pilauli wrote: August 29th, 2020, 9:11 pm EDIT: There's a really simple way to do this. When you create the unit on the map (using the [unit] tag), include a line which says "advances_to=Poacher".
To quote the wiki...
advances_to: comma-separated list of unit types to which this unit can advance. Will override the default provided by the [unit_type]. This is generally not set manually.
(Source: https://wiki.wesnoth.org/SingleUnitWML)
eh.. That works, but only for single units and with the problems WhiteWolf described.

I'm gonna play around with EffectWML and the [resources] tag (ModificationWML), that might just do it
Pilauli wrote: August 29th, 2020, 11:57 pm I see that remove_advancement is marked "Version 1.13.2 and later only", which shouldn't be a problem for 1.14.
I think that's what you meant here :D
eh, what comes here again?
Pilauli
Posts: 115
Joined: August 18th, 2020, 12:56 pm

Re: Modifying Core Units

Post by Pilauli »

I meant that it has scary blue text but the scary blue text doesn't say anything important in this case.

Good luck with your add-on! :)
User avatar
s1m0n
Posts: 53
Joined: May 7th, 2020, 1:55 pm
Location: Irdya

Re: Modifying Core Units

Post by s1m0n »

Pilauli wrote: August 29th, 2020, 9:11 pm I wrote some other stuff before, and I'll leave it here under a spoiler for reference.
Spoiler:
After looking into the mainlines as you suggested, I found a similar thing to what you described in Liberty, and modified that to my fittings. There is now a unit called Forester that is a Woodsman that only levels up to a Poacher, and that is fine. I think if 1.16 comes out I will try the modifications thingy again, but for now that works and is uncomplicated.

Anyways, thank you both for your help :) , here's my code:

Code: Select all

[unit_type]
    [base_unit]
        id=Woodsman
    [/base_unit]
    id=forester
    name= _ "Forester"
    advances_to=Poacher
    description= _ "Foresters are hunters, woodcutters, charcoal-burners, and others who eke out a living where the human world verges on the wilderness. Wits and woodcraft often support them where weapons will not."
[/unit_type]
eh, what comes here again?
User avatar
s1m0n
Posts: 53
Joined: May 7th, 2020, 1:55 pm
Location: Irdya

Re: Modifying Core Units

Post by s1m0n »

What's important not to forget: you have to describe the path for units in the main.cfg, that was one of my mistakes :mrgreen: :doh:
eh, what comes here again?
Pilauli
Posts: 115
Joined: August 18th, 2020, 12:56 pm

Re: Modifying Core Units

Post by Pilauli »

Unit path: yep, argh. (I once had units that would not appear, because I'd put them in a subfolder of units, but hadn't explicitly listed the subfolder in main.cfg.)

---

Okay, take the rest of this with a grain of "I'm not a lawyer or professional campaign designer", but...

You'll want to make sure your unit type doesn't accidentally share an id with any other active unit types (so "forester" could theoretically be problematic), because if the game tried to load two unit types with the same id, you could end up with the wrong one in a scenario... and it might not fit in the scenario. (Too powerful, not strong enough, levels to the wrong thing, is actually an elf, etc.)

I believe there are two options:
1) Put your unit file paths inside an "#ifdef YOUR_CAMPAIGN'S_TAG" section in main.cfg (which should mean that it works when playing your campaign and doesn't affect anything the rest of the time.)
2) Prefix your unit types' IDs with your campaign's initials so that their ids won't match anything else.

I believe both of these are generally considered good practice, and in fact, there's no reason you couldn't do both. I also believe they're pretty easy to do.

---

If you already put the file paths inside the ifdef, you're probably good and I'm sorry for sounding like a worrywart.
User avatar
s1m0n
Posts: 53
Joined: May 7th, 2020, 1:55 pm
Location: Irdya

Re: Modifying Core Units

Post by s1m0n »

You'll want to make sure your unit type doesn't accidentally share an id with any other active unit types (so "forester" could theoretically be problematic), because if the game tried to load two unit types with the same id, you could end up with the wrong one in a scenario... and it might not fit in the scenario. (Too powerful, not strong enough, levels to the wrong thing, is actually an elf, etc.)

I believe there are two options:
1) Put your unit file paths inside an "#ifdef YOUR_CAMPAIGN'S_TAG" section in main.cfg (which should mean that it works when playing your campaign and doesn't affect anything the rest of the time.)
2) Prefix your unit types' IDs with your campaign's initials so that their ids won't match anything else.

I believe both of these are generally considered good practice, and in fact, there's no reason you couldn't do both. I also believe they're pretty easy to do.
yep. checked the id's to not use one already used, but i sure will try your solutions
eh, what comes here again?
Pilauli
Posts: 115
Joined: August 18th, 2020, 12:56 pm

Re: Modifying Core Units

Post by Pilauli »

Well, the thing is that someone else might make an add-on with a forester unit...

Edit in response to following:
Okay, then. Good luck!
Last edited by Pilauli on September 9th, 2020, 9:36 pm, edited 1 time in total.
User avatar
s1m0n
Posts: 53
Joined: May 7th, 2020, 1:55 pm
Location: Irdya

Re: Modifying Core Units

Post by s1m0n »

That's not my problem at the moment. I can always fix this in the beta, but for now I only want all my features working
eh, what comes here again?
Post Reply