Shields

Discuss Chaos Strikes Back for Windows and Linux, an unofficial port of Chaos Strikes Back to PC by Paul Stevens, as well as CSBuild, an associated dungeon editor.

Moderator: Zyx

Forum rules
Please read the Forum rules and policies before posting.
Post Reply
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Shields

Post by Sophia »

As the conventional wisdom goes, shields are ignored in DM. Some other poking around reminded me of this issue and renewed my curiosity. The source code deepened the mystery a bit, as the CSBwin shield code (near the top of TAG01680a) was enough of a mess of code that it had to be doing something in there other than just ignoring the shields. I couldn't find anything in the code that implied shields were completely thrown out, either. They are multiplied by some values that I don't think are zero, and subjected to some strange formulas, but the trace does clearly show that D6W (the register where shield strength is stored) has a value when it's all said and done.

The formula is strange, though. Their contribution to the overall armor power was partially figured upon the shield's throwing distance (how far can a typical character throw a shield?), multiplied by a value from 1 to 6 depending on where the monster was attacking, and then divided by 32 (usually), though, so we ended up with a rather strange value that might well have been a negligible contribution in normal play. The code is actually rather clever, I think. Using the throwing distance is probably some sort of way to emulate the character actively blocking, and the location takes into account the ability of the character to block some areas better than others. It makes it kind of a shame that when all is said and done, the contribution of the shield ends being so pathetic.

As an example, having the mighty shield of lyte in my hand against a Trolin caused D6W to be around 20, meaning my defensive strength was increased by ~20 points. This is approximately the same increase that you get from upgrading from no shirt to a leather jerkin. An ordinary small shield gave me a D6W of 12, making it about as good as slipping on a pair of blue pants. It gets worse. Trolins tend to aim high, making the shield multiplier typically around 5 or 6. Against a worm, who aims low where shields are not so effective, my D6W dropped even further, to 11 with the shield of lyte and 6 with the small shield. This puts them right up there with ghi trousers. To contrast, when the torso is being attacked, plate mail adds 65 to your defense, and the Armor of Lyte adds 125.

So, in short, shields aren't ignored, their defensive contribution just ends up being roughly equal to some relatively weak pieces of clothing, even for very "impressive" shields.

I just thought someone might find this interesting. :D
User avatar
Rasmus
Ee Master
Posts: 714
Joined: Fri May 08, 2009 1:44 am
Location: Sweden
Contact:

Re: Shields

Post by Rasmus »

I find this very interesting! When I was checking the CSB code I ignored looking for any shieldcode because everybody said that it was ignored in DM/CSB. Instead I did a (chance to block) calculation for every shield. But now I think I will take an extra look into the code. Thanks Sophia :)
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Shields

Post by Sophia »

I've already done a lot of work on trying to figure out CSBwin's formulas, so if you need help, feel free to ask. :) And please share any new insights you gain, too-- I am not at all convinced I've gotten it all right.

My current challenge is figuring out when exactly it decides to "ouch" a body part. There is some formula that is supposed to take vitality into account, but it ends up using the same code that results in broken anti-fire, so I'm still a bit confused.
User avatar
Rasmus
Ee Master
Posts: 714
Joined: Fri May 08, 2009 1:44 am
Location: Sweden
Contact:

Re: Shields

Post by Rasmus »

It was a couple of months since I looked into the burning part, and I think I had some problem figuring this out this too. I can't really remember if I did some kind of a shortcut on this and did some simular homemade code, but I can check it out later this day and give you a post.

It's funny, sometimes I had to much problem cleaning the code so all I did was copying the function it into my game. One value goes in and goes thru some "secret" calculations and comes out another.. Well as long as it worked correctly I had no reason to complain :)
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Shields

Post by Sophia »

Rasmus wrote:I can't really remember if I did some kind of a shortcut on this and did some simular homemade code
This is what DSB does right now, but it didn't "feel" quite right while testing my dungeon so I thought I'd go digging a bit deeper into the code to try to figure out if I can be more correct. :D
User avatar
Bit
Arch Master
Posts: 1064
Joined: Mon Mar 03, 2008 10:53 am
Location: Nuts trees

Re: Shields

Post by Bit »

I will try to solve the problem with the duplicated objects in my clone now.
For that it seems that I finally have to give names to the still just tag-numbered variables now.
Different types and classes, immediate function-replacements for mask-things (a lot is already done in CSBwin, but I bet one can spend another year on this), this all starts now and I hope I can distribute anything then. I'll do my very best.
I also still have all differences of DM and CSB #ifdef'd.

@Sophia:
I was close to point Rasmus to your LUA-code, because this seemed to me easier than to fight through all this bitmask-horror in the CSBwin-source. I wasn't aware that you are still fighting ;)
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Shields

Post by Sophia »

Bit wrote:I was close to point Rasmus to your LUA-code, because this seemed to me easier than to fight through all this bitmask-horror in the CSBwin-source. I wasn't aware that you are still fighting ;)
And, in theory, I think DSB's code could quite useful in that regard... however, that means I have to get it right, first. I'm getting closer, but I'm sure there are still problems here and there. :)
User avatar
ian_scho
High Lord
Posts: 2806
Joined: Fri Apr 07, 2006 8:30 am
Location: Zaragoza, Spain

Re: Shields

Post by ian_scho »

This is what I like about 'reading' the code in DSB. Sophia will add comments where necessary about not only how it works but also what is lifted out of CSB. Example, monster.lua line 299:

Code: Select all

-- These functions are roughly based on CSBwin's calculations for monster
-- damage. The base damage uses its exact formula, and the call to 
-- zone_damage with a specified attack zone tries to preserve the "feel"
-- of what is going on. I've completely estimated the odds of causing an
-- injury because CSBwin's TAG016426 seems to produce nonsense.
-- Piercing attacks are more likely to cause one, and attacks in which
-- armor didn't do a very good job are more likely to as well.
User avatar
Rasmus
Ee Master
Posts: 714
Joined: Fri May 08, 2009 1:44 am
Location: Sweden
Contact:

Re: Shields

Post by Rasmus »

I did something like this..
D7W are the damage..
damageparts shows how much damage that is given to each bodypart..
damageall are typical fireball etc that damages all bodyparts.

Code: Select all

	if (includehurt)
	{
		int damageparts[6]={15, 15, head, torso, legs, feet};
		if (damageall) for (int i=0;i<6;i++) damageparts[i]=0;
		int maxhealth=sHero[herocount].stats[0][1];
		for (int i=0;i<6;i++)
		{
			damage=D7W-int(float(float(D7W)*(float(damageparts[i])/15.0f)));
			damage=int(damage/3);
			int hurtprob=maxhealth-damage;
			if (hurtprob<int(maxhealth-int(maxhealth/10)))
			{
				if ((int(rand() % hurtprob)<=int(maxhealth/10))||(hurtprob<0))
				{
					sHero[herocount].hurt[i]+=20+damage;
				}
			}
		}
	}
The first time the hero gets hurt it dosn't increase the damage. But the next time the damage are calculated on the hurted parts it will calculate without any armourresistance there.
User avatar
Rasmus
Ee Master
Posts: 714
Joined: Fri May 08, 2009 1:44 am
Location: Sweden
Contact:

Re: Shields

Post by Rasmus »

I can honestly say that I am not that good at making notes as Sophia :)
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Shields

Post by Sophia »

Thanks for posting that. I had a similar mechanic, actually-- I think I've finally figured out the way DM does it (it was kind of obfuscated by some calls to the controversial TAG016426) and it's actually pretty simple by comparison.

DM generates a random number between 13 and 181, and if your damage is greater than that value, it generates a random body part. If the body part has been attacked, that part is injured. Then, it doubles its random number and checks again, and keeps doing this until the damage is no longer greater than the random number.

(Amusingly enough, that comment Ian posted is gone, now. I've changed the algorithm around in an attempt to duplicate DM as exactly as possible because I'm no longer satisfied with merely "getting the feel right" ;) )
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Shields

Post by Sophia »

Graphics.dat item 562, at location 0x1A2 (byte1412 in CSBwin), contains 6 multipliers for the strength of the shield to protect various locations: off hand, weapon hand, head, body, legs, and feet. By default, the values are 05 05 04 06 03 01 but increasing them will make shields protect each location better, so custom dungeon designers do have a way to help shields if they want to. These bytes are rather vaguely stated in the current version of the Encyclopedia as "resistances to ouches," so hopefully this description will help shed some light.
User avatar
zoom
Grand Master
Posts: 1819
Joined: Tue Sep 23, 2003 1:27 am
Location: far away but close enough

Re: Shields

Post by zoom »

nice to have some insight on how shields work, sophia.

I would like to know if shield-protection(however low it may be)
does protect after the "ferocity of attack" or "sharpness value" of an attack
has been applied or not.

plate of lyte has an armor value of 125 / 4
http://dmweb.free.fr/?q=node/259#toc3
lyte shield has
85/4
ignored

What I want to know is, do shields help more against sharp attacks than for non sharp attacks?
Is the calculation the same as for armor,
regarding the sharp attacks/ferocity of monster...I just ask because you did not mention the second value
As I see it shields may have an even lower impact on protection for really strong attacking monsters,

with the lowly buckler granting good protection against these adversaries

what I really would like to know is what would be the best armor set for facing (and getting hit by)
low monster category (no ferocity attack/sharpness),
sharp attacking monsters(up to ferocity 4)
sharp attacking monsters(up to ferocity 7)(because best armor resitance is mithril (7)')
sharp attacking monsters(above ferocity7)(are there any monsters ?)
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Shields

Post by Sophia »

I'm not sure what you mean by the "ferocity" of the monster, but it seems like you're under the impression there is some direct correlation between the sharp resistance of a piece of armor and some value in the monsters' stats, which isn't the case. The determination of whether the damage is "blunt" or "sharp" is based solely on the monster's attack method number. Monsters that use attack method 3 do "blunt" damage, and method 4 does "sharp" damage.

The sharp resistance is a multiplier, because sharp attacks use a different formula. The sharp resistance + 4 is multiplied times the armor strength, and then the whole thing is divided by 8. This means a sharp number of 4, like the plate of lyte, has equal strength against blunt and sharp attacks, because it's just (125 * (4 + 4)) / 8 = 125. This also means things like the buckler (as you mentioned) as well as chain armor offer superior protection against sharp attacks than blunt attacks, because their sharp multiplier is greater than 4.

To answer your question, this means is that shields with a sharp number greater than 4 will help you more for sharp attacks than blunt ones, and shields with a number less than 4 will help you for blunt attacks more than sharp ones. This works just like every other piece of armor. :)
User avatar
zoom
Grand Master
Posts: 1819
Joined: Tue Sep 23, 2003 1:27 am
Location: far away but close enough

Re: Shields

Post by zoom »

:shock: ok this is new to me! woohoo. :shock:
just for completion:
I thought you have items with low or high sharp resistance, no blunt resistance at all.
-->each number lower than seven* would be reducing the actual protection of a piece of armor accordingly;
therefore I thought mithril would be as good as plate of darc in some cases
(

So if I get this right :

Mithril will be as good as plate of darc for (method 4) but only in that particular case
there is no further spread of ferocity(all monsters using sharp attacks/method 4 do have the same ferocity)
(Monsters only use sharpness attacks and not a special sharpness=4, sharpness=5 or sharpness=7 )

:arrow: :?: hmm which hand did you refer to?

quote
As an example, having the mighty shield of lyte in my hand against a Trolin caused D6W to be around 20,

quote

monster attacks with high ferocity=sharpness attack;--I referred to some nomenclature ency uses)


the divide by 8 is also a bit confusing; since ency says:(but I believe you ;) )
*
Armor Strength (/200) /
Sharp Resistance (/7)


Armor Strength: The armor value (0..200) associated with the item. Some items (Shields) have the "Ignored" keyword, meaning that the item's Armor Strength will be ignored when calculating armor.

Sharp Resistance: A 0..7 value which is used when monsters have a "sharp" attack. Sharp attacks use the following format to calculate armor: (Sharp Resistance / 7) * Armor Strength, so if the Sharp Resistance value is 0, a creature having a Sharp attack will ignore your armor.

:roll:

all the thinking about how shields should work is a good thing I think
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Shields

Post by Sophia »

zoom wrote:Mithril will be as good as plate of darc for (method 4) but only in that particular case
there is no further spread of ferocity(all monsters using sharp attacks/method 4 do have the same ferocity)
(Monsters only use sharpness attacks and not a special sharpness=4, sharpness=5 or sharpness=7 )
That's right. Their "ferocity" in their attack is based on their attacking power, just like method 3 (blunt attacks)-- it's just that the armor resistance is computed differently so some pieces of armor resist them more effectively and others are not as effective.
zoom wrote:hmm which hand did you refer to?
Either hand. If you have shields in both hands you get protection from both, but then you can't fight.
zoom wrote:I referred to some nomenclature ency uses
I think the information on the encyclopedia is based on very old data, that was guessed before we had figured out the complete formulas.
User avatar
Bit
Arch Master
Posts: 1064
Joined: Mon Mar 03, 2008 10:53 am
Location: Nuts trees

Re: Shields

Post by Bit »

Now with all that knowledge that I gained while building my clone, I started to create one more testclone that is absolutely close to the disassembly, just with the necessary hardware-stuff and CSBwin's routine- and variablenames. I'll do that mostly source-processed and each manually edited line carefully described.
Can't take too long. So far I believe I can trust the last versions of my emu-part so that no new problem is added.
Not that I would distrust CSBwin, but then we got a chance to verify those wrong-byte-picks.
Perhaps we find that compiler-problem-pattern in more places - so far it seems to be lost in both, in CSBwin and my clone too.
User avatar
Adamo
Italodance spammer
Posts: 1534
Joined: Fri Apr 22, 2005 11:59 am
Location: Poland
Contact:

Re: Shields

Post by Adamo »

Awesome work, Sophia!!! So it seems that shields ARE usefull somehow.
By the way, does shield command do anything? When the character has a shield in right hand and he uses the "block" command, does it change anything?
Spoiler
(\__/) (\__/) (\__/) (\__/) (\__/) (\__/) (\__/) (\__/) (\__/) (\__/) (\__/) (\__/)
Spoiler
(@.@) (@.@) (@.@) (@.@) (@.@) (@.@) (@.@) (@.@) (@.@) (@.@) (@.@) (@.@)
Spoiler
(>s<) (>s<) (>s<) (>s<) (>s<) (>s<) (>s<) (>s<) (>s<) (>s<) (>s<) (>s<)
User avatar
Rasmus
Ee Master
Posts: 714
Joined: Fri May 08, 2009 1:44 am
Location: Sweden
Contact:

Re: Shields

Post by Rasmus »

I can answer that one if I remember correctly :) After each attack a champion makes his defense decreses for a amount of time, when using block your overall defense increases for awhile insted.

You can take a look at the actions Defense Modifier at:
http://dmweb.free.fr/?q=node/690

I don't have the csb code availible for the moment so I can't look at it exactly. But this is how it works in general..
User avatar
zoom
Grand Master
Posts: 1819
Joined: Tue Sep 23, 2003 1:27 am
Location: far away but close enough

Re: Shields

Post by zoom »

Adamo, you can read what block command and all other actions do here:
http://dmweb.free.fr/?q=node/690
(defense modifier 34 with block command etc)

nevertheless some description of how valuable a 34 bonus is, would be cool. 17% of 200?
then again, since shields protect all kinds of body parts it is not easy to explain probably..

really not optimal how shields act in dm, you can either use the shield or attack with a weapon..
would be cool to have the first 2 actions of the sword change when you hold a shield in the offhand..
so instead of swing you would get "swing and block" or some such.. anyway
User avatar
Rasmus
Ee Master
Posts: 714
Joined: Fri May 08, 2009 1:44 am
Location: Sweden
Contact:

Re: Shields

Post by Rasmus »

Hello Sophia, I have a misson for you ;)
I have noticed that the stamina and food / water generation are a bit off in my game. Do you have good explanation on how this works? I must have missed something important..
The things that are included is:
- The stamina are ten times higher than what is actually shown in the game.
- The stamina goes down for every square I move too depending on how much I carry.
- The stamina decreases when the mana goes up (mana generation is depending on the wisdom).
- Every 10:th second the mana increases some steps, but goes down some more steps depending on how hungry or thirsty your
character is.

What I would like to know is how much the values on these calculations are. And if I have missed something else here..
I know that it is alot of work checking this out, and I could probably do it myself but I am a bit in a hurry nowdays completing all the other bugs and this would save me some time :)
User avatar
Rasmus
Ee Master
Posts: 714
Joined: Fri May 08, 2009 1:44 am
Location: Sweden
Contact:

Re: Shields

Post by Rasmus »

I found the problem wíth my code. The "lose stamina when walking" was calculated twice, and therefore the stamina went down at double speed :S Also, the stamina is supposed to go up when your water are "blue", in my the value that was going to increase the stamina was instead used to lower water :S

So the stamina was drained as they was have zero water, and also at double speed when moveing.

Thanks for sharing the DSB code, it made it a whole lot easyer to locate my misstakes :)
User avatar
sucinum
Pal Master
Posts: 872
Joined: Wed Apr 18, 2001 1:00 am
Location: Karlsruhe, Germany
Contact:

Re: Shields

Post by sucinum »

It feels good reading this because i always believed in shields. You have the power, offhand-friends! *ahem*
Post Reply

Return to “Chaos Strikes Back for Windows & Linux (CSBWin) / CSBuild”