Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Development

Reply
 
Thread Tools Display Modes
Old April 3, 2018, 17:42   #1
Gordon
Scout
 
Join Date: Jan 2010
Posts: 31
Gordon is on a distinguished road
Fix for lack of damage boost from device skill in Angband 4.05

Since I received no response to my query about fixing this, I decided to fix it myself. The fix was easy. Just replace:
Code:
int effect_calculate_value(effect_handler_context_t *context, bool use_boost)
{
	int final = 0;

	if (context->value.base > 0 ||
		(context->value.dice > 0 && context->value.sides > 0))
		final = context->value.base +
			damroll(context->value.dice, context->value.sides);

	if (use_boost)
		final *= (100 + context->boost) / 100;

	return final;
}
with:
Code:
int effect_calculate_value(effect_handler_context_t *context, bool use_boost)
{
	int final = 0;

	if (context->value.base > 0 ||
		(context->value.dice > 0 && context->value.sides > 0))
		final = context->value.base +
			damroll(context->value.dice, context->value.sides);

	if (use_boost)
		final *= (100 + context->boost);
		final /= 100;

	return final;
}
in effects.c
Gordon is offline   Reply With Quote
Old April 3, 2018, 18:23   #2
Derakon
Prophet
 
Derakon's Avatar
 
Join Date: Dec 2009
Posts: 8,449
Derakon is on a distinguished road
Interesting. It looks like the issue is with integer division effectively truncating the multiplier down to 1 unless boost was >= 100. Good catch!

This should be an equivalent single-line fix, right?

Code:
final = (final * (100 + context->boost)) / 100
Derakon is offline   Reply With Quote
Old April 3, 2018, 18:35   #3
Gordon
Scout
 
Join Date: Jan 2010
Posts: 31
Gordon is on a distinguished road
Yeah, that will work also. I usually prefer multiple lines when I'm doing integer math like this since I think it is clearer that way.
Gordon is offline   Reply With Quote
Old April 3, 2018, 18:43   #4
Derakon
Prophet
 
Derakon's Avatar
 
Join Date: Dec 2009
Posts: 8,449
Derakon is on a distinguished road
Yeah, it's mostly just a style thing. I have a mild preference for one-liners when there's a possibility that otherwise the lines could get separated -- a single line has a clear "this is all one action" nature to it. But it really doesn't matter in this case.

In any case, thanks for finding the bug!
Derakon is offline   Reply With Quote
Old April 3, 2018, 18:53   #5
Gordon
Scout
 
Join Date: Jan 2010
Posts: 31
Gordon is on a distinguished road
Now my Wand of Annihilation is much more useful!
Gordon is offline   Reply With Quote
Old April 3, 2018, 20:11   #6
AnonymousHero
Veteran
 
AnonymousHero's Avatar
 
Join Date: Jun 2007
Posts: 1,357
AnonymousHero is on a distinguished road
Quote:
Originally Posted by Gordon View Post
with:
Code:
int effect_calculate_value(effect_handler_context_t *context, bool use_boost)
{
	int final = 0;

	if (context->value.base > 0 ||
		(context->value.dice > 0 && context->value.sides > 0))
		final = context->value.base +
			damroll(context->value.dice, context->value.sides);

	if (use_boost)
		final *= (100 + context->boost);
		final /= 100;

	return final;
}
in effects.c
I'm not sure what you indended with the code code but the indentation in the above lines is extremely misleading either way. The "final /= 100" bit will always apply, not just when "use_boost" is true. I would suggest always using braces.

(I believe recent versions of clang/gcc will even issue a warning for the above code because of the misleading indentation.)
AnonymousHero is offline   Reply With Quote
Old April 3, 2018, 20:36   #7
Gordon
Scout
 
Join Date: Jan 2010
Posts: 31
Gordon is on a distinguished road
Whoops. Correction:
Code:
int effect_calculate_value(effect_handler_context_t *context, bool use_boost)
{
	int final = 0;

	if (context->value.base > 0 ||
		(context->value.dice > 0 && context->value.sides > 0))
		final = context->value.base +
			damroll(context->value.dice, context->value.sides);

	if (use_boost) {
		final *= (100 + context->boost);
		final /= 100;
	}

	return final;
}
Thanks for noticing that!
Gordon is offline   Reply With Quote
Old April 3, 2018, 20:54   #8
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 4,864
Donated: $40
Pete Mack is on a distinguished road
This bug was fixed in 4.1
Pete Mack is offline   Reply With Quote
Old April 3, 2018, 20:59   #9
Gordon
Scout
 
Join Date: Jan 2010
Posts: 31
Gordon is on a distinguished road
Yes, but 4.1 is basically a whole different game. For those who prefer a more traditional game, this should be fixed in 4.05 as well. It's a pretty nasty bug.
Gordon is offline   Reply With Quote
Old April 3, 2018, 22:20   #10
Nick
Vanilla maintainer
 
Nick's Avatar
 
Join Date: Apr 2007
Location: Canberra, Australia
Age: 53
Posts: 7,164
Donated: $60
Nick is on a distinguished road
Quote:
Originally Posted by Gordon View Post
Yes, but 4.1 is basically a whole different game. For those who prefer a more traditional game, this should be fixed in 4.05 as well. It's a pretty nasty bug.
The tradition in Angband is to keep changing, so I regard 4.1 as more traditional than 4.0.5
__________________
One for the Dark Lord on his dark throne
In the Land of Mordor where the Shadows lie.
Nick is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
4.0.5 device skill effect PowerDiver Vanilla 19 January 20, 2017 19:34
Angband variants for android-device Angrist Variants 0 June 26, 2015 17:50
Angband 3.3.2 - anything else to fix? Magnate Vanilla 57 May 27, 2012 23:50
Magic Device Skill Old Coach v4 1 January 23, 2012 22:05
Angband on mobile device Mark Vanilla 7 June 16, 2010 15:37


All times are GMT +1. The time now is 10:22.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.