Issue information

Issue ID
#2901
Status
Fixed
Severity
Medium
Started
Hercules Elf Bot
Mar 26, 2009 2:51
Last Post
Hercules Elf Bot
Mar 26, 2009 2:51
Confirmation
N/A

Hercules Elf Bot - Mar 26, 2009 2:51

Originally posted by [b]Setras[/b]
http://www.eathena.ws/board/index.php?autocom=bugtracker&showbug=2901

First of all, sorry if this was discussed earlier. (new search instrument in forum is a bit strange - finds lots of unneeded topics so i didn't locate anything like my problem)

And sorry for my stupid style of writing(due to fact that my current time is almost 4 AM)
P.S. (yeah P.S. in the beginning) I believe this is a bug, and it is caused by inattentivness (loss of attention).
P.P.S. request to check is in the bottom.

Second: http://svn.eathena.ws/svn/ea/trunk/src/map/battle.c
The code below
CODE
/*==========================================
* Calculates GVG related damage adjustments.
*------------------------------------------*/


Contains next rows:
CODE
if (md && md->guardian_data) {
damage -= damage * (md->guardian_data->castle->defense/100) * battle_config.castle_defense_rate/100;
}


THis means, that all damage to guardian units in WoE & WoE2 (e.g. Emperium, Barricades, Guardians and so on) is reduced by value of
>>WHOOPS<<
Reduced only by battle_config.castle_defense_rate % only when DEF is 100?

Here's the GLOBAL question: Why calculations leading to "if DEF = 100 then reduce damage by battle_config.castle_defense_rate" are so obfuscated? I mean:

IF md->guardian_data->castle->defense Has NO influence untill it is 100, why not make (and i don't mean it's correct, but correct me if i'm wrong)
CODE
-- damage -= damage * (md->guardian_data->castle->defense/100) * battle_config.castle_defense_rate/100;
++ if(md->guardian_data->castle->defense==100) damage -= damage *  battle_config.castle_defense_rate/100;

Otherwise, if, as i believe on official kRO, DEF of Castle HAS influence on damage dealt to guardians(i mean all who (md->guardian_data)) and the influence IS 1% of battle_config.castle_defense_rate per 1 Investment, then this DEFINITLEY should be changed to:
CODE
-- damage -= damage * (md->guardian_data->castle->defense/100) * battle_config.castle_defense_rate/100;
++ damage -= damage * ((float)md->guardian_data->castle->defense/100) * ((float)battle_config.castle_defense_rate/100);

Notice the "(float)" which means that calculations will be float, meaning anything below 100/100 will not be rounded DOWN to ZERO, as it IS currently.

I mean, let's imagine a castle with 95 DEF invest's and battle_config.castle_defense_rate equal to 100 which is default.
damage -= damage * (md->guardian_data->castle->defense/100) * battle_config.castle_defense_rate/100;
Means that damage is reduced by damage * (95/100) * 100/100;
Which is exactly ZERO, because: (95/100)==0, because this is rounded down to integer. Because both values are integer. So because 1 multiplier is zero, whole multiplying results in zero.

While after applying my patch this gets:
damage -= damage * ((float)md->guardian_data->castle->defense/100) * ((float)battle_config.castle_defense_rate/100);
Means that damage is reduced by damage * ((float)95/100) * ((float)100/100);
Which means that damage -= damage * 0.95 * 100.0;
Which means all damage will be reduced to 5%! See the difference? 100% and 5%. Or 0% and 95% (of reduction).

So here what i ask for: check WHETHER investing in DEF of Castle up to 99 results in Reduction of Damage dealt to Targets having attributes (md && md->guardian_data), OR NOT. Because if it results - the formulae is TOTALLY wrong, and if not - sorry for the whole post.