Question: Where are the 'guts' for abilities/mechanics?

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
vodot
Posts: 97
Joined: October 12th, 2011, 5:32 pm
Location: Camas, WA

Question: Where are the 'guts' for abilities/mechanics?

Post by vodot »

Ok, simple question: where are the 'mechanics' of each ability stored? I can find 'abilities.cfg', but what pulls from 'abilities.cfg' to actually run the ability when triggered? I see the inputs; where are the 'guts'?

example: the "Leadership" ability has a "value" input (20,50,75,etc.), but where is the code that pulls that value and uses it to amplify the attack of adjacent units? Where is the leadership "effect" located?

Am I making sense?

EDIT: I guess a better overall question would be: how do the different WML modules flow into one another, and at what level are each of them 'called' by the next highest/lowest level? Anyone have a [generic] system structure flowchart like that lying around?
User avatar
Alarantalara
Art Contributor
Posts: 784
Joined: April 23rd, 2010, 8:17 pm
Location: Canada

Re: Question: Where are the 'guts' for abilities/mechanics?

Post by Alarantalara »

Most of the default abilities are hiding out in the C++ engine so there is no other WML for you to look at.

e.g. healing is covered in actions.cpp around line 1937ff (calculate healing), while leadership is around line 707 of the same file (under_leadership function).

A lot of the damage modifying weapon specials are handled by unit_abilities.cpp
User avatar
vodot
Posts: 97
Joined: October 12th, 2011, 5:32 pm
Location: Camas, WA

Re: Question: Where are the 'guts' for abilities/mechanics?

Post by vodot »

So if I want to modify the mechanics of a default ability without getting crazy with the engine, do I essentially need to create my own new ability and then remap the default ability to my new one?

Where/At what level would I need to implement new ability code in order to make it global for every campaign/multiplayer matches?

Or: for a global mod that changes default ability behavior, where do I start implementing new code?
User avatar
Alarantalara
Art Contributor
Posts: 784
Joined: April 23rd, 2010, 8:17 pm
Location: Canada

Re: Question: Where are the 'guts' for abilities/mechanics?

Post by Alarantalara »

vodot wrote:So if I want to modify the mechanics of a default ability without getting crazy with the engine, do I essentially need to create my own new ability and then remap the default ability to my new one?

Where/At what level would I need to implement new ability code in order to make it global for every campaign/multiplayer matches?

Or: for a global mod that changes default ability behavior, where do I start implementing new code?
Effectively, you have to redefine all the affected units using your new definition. Any WML you write is processed after the built-in code, so every unit has already received a copy of the built-in version of an ability before you have a chance to change it.

So, you can either make new units that are identical except for your new WML ability, or you can write recruit/recall/create scripts that replace the default ability with your own (remove any ability with the designated id and replace it with a similar ability with a different id).

The status effect abilities like poison are even more of a pain to replace. Take a look at the Nightmares of Meloen add-on if you want an idea of what it takes to do a status effect. You would have to write similar code and make it interact with healing, turn refreshes, etc. manually.

Basically, when you're done all your abilities will look a lot like the feeding ability and the AI may not know how to use them in the same way it would if you do anything beyond just using different numbers for the same ability type.
User avatar
Solikos
Posts: 44
Joined: December 6th, 2011, 5:05 am

Re: Question: Where are the 'guts' for abilities/mechanics?

Post by Solikos »

I have this same question... I understand custom abilities should be created for custom units (I've been planning on doing this anyway)... But where do I define the abilities? In the Campaign.cfg file?
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Question: Where are the 'guts' for abilities/mechanics?

Post by zookeeper »

Solikos wrote:I have this same question... I understand custom abilities should be created for custom units (I've been planning on doing this anyway)... But where do I define the abilities? In the Campaign.cfg file?
Ability tags go inside [abilities] which goes inside [unit_type] which goes inside [units] which doesn't go inside anything as it's a top-level tag. That's all there is to it. Everything else is merely a question of how you want to organize your own code.
User avatar
Solikos
Posts: 44
Joined: December 6th, 2011, 5:05 am

Re: Question: Where are the 'guts' for abilities/mechanics?

Post by Solikos »

Makes sense, thanks!

Last question - where might I find the code of the "Heal" / "Cure" abilities (to copy)? This code doesn't appear to be in any of the core units - just a reference to it (so I assume "core" abilities are not coded in the unit_type, but in another file altogether).
User avatar
Alarantalara
Art Contributor
Posts: 784
Joined: April 23rd, 2010, 8:17 pm
Location: Canada

Re: Question: Where are the 'guts' for abilities/mechanics?

Post by Alarantalara »

The WML is in macros/abilities.cfg as a macro that can be included in any unit to ensure consistency.
Post Reply