[engine] change management random

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

Moderator: Forum Moderators

Forum rules
Before posting a new idea, you must read the following:
Post Reply
Bernard_Juan
Posts: 3
Joined: June 26th, 2015, 7:33 pm

[engine] change management random

Post by Bernard_Juan »

Hi, I'm french living in ORLEANS.
I would like to share with you an idea about the random drawing during the fighting in Wesnoth. I just changed the source code of the game as follows:
In the 1.10.7 release, go to the ./src directory and open the file action.cpp
In the 1.12.2 release go the ./src/actions directory and open the file attack.cpp
Search the string "bool hits =" and you will find this part of the source code that handles the fight. Here is the excerpt of the original code:

bool hits = (ran_num % 100) < attacker.cth_;
int damage = 0;
if (hits) {
damage = attacker.damage_;
...

Edit the source code as follows:

// bool hits = (ran_num % 100) < attacker.cth_;
int damage = 0;
//-----------------------------------------------------------------------------------------
damage = attacker.damage_ * ((attacker.cth_ - 15) + (ran_num % 30));
damage = (damage / 10 + 5) / 10; // gestion de l'arrondi à 0,5 ex: 1,5 <= [2] < 2,5
bool hits = (damage != 0);
//-----------------------------------------------------------------------------------------
if (hits) {
// damage = attacker.damage_;
...

Let me explain:
In the original release, we draw a random number between 0 and 99 then compares this number with the attack potientel. If this number is less then the attack is completed with its maximum value. Otherwise, the attack is 0, it is the method of all or nothing that frustrates many players.

In the modified version (and recompiled course, see about how to recompile the source code on this forum), it does not work at all or nothing. In fact, I consider the potential of the attacker and I initially applies a change of plus or minus 15%
Then I multiply this number with the value of the damage and I divide by 100. Finer, I divide by 10, I add 5 and I re-divide by 10 which manages the rounded value of [0.5- 1.5]. I give you some examples to illustrate all this:

An attacker has a potential attack 9-2
The defender is parked in the forest with a defense bonus of 70%
The attacker will get twice 30% to 9, with a variability of more or less 15% This gives a minimum 15% and maximum 45% of 9. With the new calculation, we get a value between 1 and 4. The attacker inflict minimum 2 points and maximum 8 points major damage.
Other examples :

Attacker 12-4
Defender bonus defense 40% so 60% for attacker
Result : (minimum 5 , maximum 9) X 4 [20 - 36] damage

Attacker 2-10
Defender bonus defense 20% so 80% for attacker
Result : (minimum 1 , maximum 2) X 10

attacker 40-1
Defender bonus defense 60 % so 40% for attacker
Result : (minimum 10 , maximum 22) X 1


With this new process, the attacker is almost certain to hit the target every time. Nevertheless, the major damage points are proportional to the opponent's defense bonus. The variability of plus or minus 15% provides a good variability in the calculation of points of damage. It is possible to vary up to plus or minus 30%, which provides a range of 60% of variabilté. Just modify the source code line as follows:

damage = attacker.damage_ * ((attacker.cth_ - 30) + (ran_num % 60));

I tried several variations:
+/- 0%: no change, it gives a deterministic approach but in the end it becomes annoying
+/- 30%: the luck factor is close to the original playing conditions
+/- 15%: This is my favorite configuration.

And you, what do you think?

Suggestion: why not add this option getting to play with such a variabilté slider between 1 and 30.

Since I modifies the source code in this way, I rediscovered the pleasure of playing against the artificial intelligence.
"IA experimental" is particularly effective on large playgrounds with many villages.

Goodbye

ps: excuse my broken English, I did as I was able;-)
User avatar
Crow_T
Posts: 851
Joined: February 24th, 2011, 4:20 am

Re: [engine] change management random

Post by Crow_T »

This sounds interesting, and in a way is similar to my random damage mod, but with less randomness- or I should say a smaller damage range. I tried to keep the high and low range, even misses, as still a possibility, but a less common occurrence. You may want to see my add-on code and/or the PRNG add-on code (both written by Dugi) to make your system more accessible to less tech saavy players by creating an in-game menu option as opposed to modifying the source (next time I build I will try this out though :geek: )

Some potential flaws in your system that I had to think through when designing my mod were things like poison and slow- it is too powerful to have them as guarantees IMO so their effects are handled by the stock RNG system.
Bernard_Juan
Posts: 3
Joined: June 26th, 2015, 7:33 pm

Re: [engine] change management random

Post by Bernard_Juan »

Crow_T wrote:This sounds interesting, and in a way...
I ignored that one could make add-on that.
I am trying to study the link.
Indeed, with my system, the units that poison or slow are favored.
However, the way I calculate is simple, it is easy to mentally calculate the damage during a game.

Thank you for the link.
see you
Bernard_Juan
Posts: 3
Joined: June 26th, 2015, 7:33 pm

Re: [engine] change management random

Post by Bernard_Juan »

[quote="Crow_T"]This sounds interesting,

I put a little time to understand the wml system.

The act of playing separately the damage and special effects seemed weird but ultimately, why not.
This is questionable because the units that slow or poison, do little damage. Their main functions are to slow or poison ...

I kept my version of Wesnoth modified thus:
//-----------------------------------------------------------------------------------------
int more_or_less = 30; // value between 0 and 30
damage = attacker.damage_ * ((attacker.cth_ - more_or_less) + (ran_num % (more_or_less * 2)));
damage = (damage + 50) / 100; // rounded management to 0,5 ex: 1,4 -> 1 ; 1,9 -> 2
// damage = damage / 100; // no rounded management ex: 1,4 -> 1 ; 1,9 -> 1
bool hits = (damage != 0);
//-----------------------------------------------------------------------------------------

And I've incorporated the "Damage_Distribution_Mod" modified thus:

local steepness = 8
...
result_damage = result_damage - defender_code.level + attacker_code.level
-- to prevent negative result with (result_damage - 1)
if result_damage < 1 then
result_damage = 1
end
...

I played alternately with both versions, they seem very similar.
I must admit that the way of "Damage_Distribution_Mod" is more in the spirit of the game to keep a maximum of possibilities for damage.
My version is a little more deterministic and easier to calculate. This corresponds more to my chess player style.
Again, congratulations to you and Dugy for your contribution (your code in wml is remarkable, it gives me ideas ...)
And thanks for google translate too ;-)

bye

Bernard
Post Reply