Custom attack outcome calculation

Brainstorm ideas of possible additions to the game. Read this before posting!

Moderators: Forum Moderators, Developers

Forum rules
Before posting a new idea, you must read the following:
Post Reply
User avatar
Xudo
Posts: 561
Joined: April 3rd, 2009, 5:26 pm

Custom attack outcome calculation

Post by Xudo »

In this theme I want to discuss feature, which will make wesnot more customizable.
Feature will affect the way of calculation of default unit attack.
Mainline gameplay should not be changed.
I'm going to implement this feature by myself, if I will get enough feedback from developers.
Thats why I ask everyone, who is exeprienced in wesnoth to comment.

Attack outcome is amount of damage and its description: "miss", "hit" and so on.

To calculate attack outcome now wesnoth uses following data:
* to calculate success of attack:
- element of [defense] array
- property "value" of weapon special [chance_to_hit] if present
- random number.
* to calculate damage:
- element of [resistance] array
- property "damage" of attacker's weapon
This rule is hardcoded and there is not trivial way to change it.

My proposal is:
Define special variable "attack_outcome_calculator" somewhere in context of campaign or era. (Where should I do it, exactly?)
This variable should contain function, which will accept arguments:
* attacker - properties of attacker unit
* defender - properties of defender unit
* attacker_weapon - properties of attacker weapon
This function is expected to return:
* damage - amount of damage dealt by attack
* description - translatable description of attack

In game when unit A will attack unit B, this function will be called.
Its result will determine damage dealt and floating text.
Floating text will be displayed according to rules:
* "damage (description)" if damage != 0 and description is not empty
* "damage" if damage != 0 and description is empty
* "description" if damage == 0 and description is not empty
* "" if damage == 0 and description is empty
For example "5" or "miss" or "промах" for localized client

With this feature it will be possible to introduce custom unit properties.
For example [absorption] described in previous theme http://forums.wesnoth.org/viewtopic.php?f=12&t=37583
Or implement "block" mechanic and chance to block for units.
On block, in some cases, dmage will be divided by 2 and floating text will be "5 (blocked)".

Post Reply