Page 1 of 1

Source code is not making sense.

Posted: Fri Jul 17, 2020 1:48 pm
by Automaton
Hi Paul,

Can you help?

Character.cpp, line 2327
D6W = 0;
D5W = weaponDescA2->uByte1;
if (AttackTraceActive)
{
fprintf(GETFILE(TraceFile),"> Weapon class = %d so using skill ",D5W);
};
if ( (D5W == 0) || (D5W == 2) )
{
D6W = (i16)DetermineMastery(chIdx, 4);
if (AttackTraceActive)
{
fprintf(GETFILE(TraceFile),"4 (swing) which is mastery level %d\n",D6W);
};
};
if ( (D5W != 0) && (D5W < 16) )
{
D6W = sw(D6W + DetermineMastery(chIdx, 10));
if (AttackTraceActive)
{
fprintf(GETFILE(TraceFile),"10 (Throw) which is mastery level %d\n",D6W);
};
};
if ( (D5W >= 16) && (D5W < 112) )
{
D6W = sw(D6W + DetermineMastery(chIdx, 11));
if (AttackTraceActive)
{
fprintf(GETFILE(TraceFile),"11 (Shoot) which is mastery level %d\n",D6W);
};
};
D7W = sw(D7W + 2 * D6W);
weaponDescA2->uByte1 is the weapon class
which is 0 for most hand held weapons, but the axe, dagger and hardcleave are all =2

The first "if" is for 0 or 2
The second for !=0 and <16
The third for >=16 and <122

The axe, dagger and hardcleave all pass through this routine true for the first case and the second case (2=0 or 2 ) and (2= !=0 and <16)

I can see in my traces that hits with the axe are trying to use 04 swing (which my char has a mastery level 4) , but its falling through to the 2nd case, picking up mastery skill 10 throw (which my char has a mastery level 8 ) and adding that to the damage roll instead.
Damage calulation - stage 1 - weighting raw damage-----------------

> Str=47
> Raw damage (Str+rand(15))=58
> Weapon weight=5
and remains at 476 because your stamina > half max stamina
> (Maxload/16)=30
> Passed test 1 - Weapon weight (5) was less than maxload/16(30) so raw damage (raw damage + weapon weight -12)=51
> Raw damage + weapon dmg (10) = 61
> Weapon class = 2 so using skill 4 (swing) which is mastery level 4
10 (Throw) which is mastery level 8
> Raw damage + (2*skill mastery (8)) = 77 and remains at 77 because your stamina > half max stamina
> Log hand=1, D0W (ouches)=0, D1W=2
> Apply limits of 0 and 100 to (raw damage/2) = 38
> Raw damage char=2 hand=1 value=38
I would have thought the correct catch should be !=0 and !=2 and <16

Code: Select all

    if ( (D5W != 0) && (D5W != 2) && (D5W < 16) )
The third case catches the Bow, Speedbow, Crossbow and Sling.

Cheers!
Nick K.

Re: Source code is not making sense.

Posted: Fri Jul 17, 2020 5:47 pm
by Paul Stevens
I never really attempted to understand what was intended by this
sort of code. I am not going to start now. Especially since you
seem to be very good at it.

There are a couple things you can do to decide if the code I produced
is faithful to the original.

1) I think I can find the original Atari binary with machine translation
to assembly. If you like, I will dig it out of my pile of old CDs and
post it. (It may already be posted.....I could check.)

2) You can compare my code with Christophe's reverse-engineered
code that produces the identical Atari binary using the original
compiler.

Let me know if you would like help with either of these options.

Re: Source code is not making sense.

Posted: Fri Jul 17, 2020 9:31 pm
by Sophia
The relevant code in Christophe's version (line 2180 of CHAMPION.C) has one key difference:

Code: Select all

A0937_ui_Class = L0940_ps_WeaponInfo->Class;
if ((A0937_ui_Class == C000_CLASS_SWING_WEAPON) || (A0937_ui_Class == C002_CLASS_DAGGER_AND_AXES)) {
   A0936_ui_SkillLevel = F303_AA09_CHAMPION_GetSkillLevel(P650_i_ChampionIndex, C04_SKILL_SWING);
}
if ((A0937_ui_Class != C000_CLASS_SWING_WEAPON) && (A0937_ui_Class < C016_CLASS_FIRST_BOW)) {
   A0936_ui_SkillLevel += F303_AA09_CHAMPION_GetSkillLevel(P650_i_ChampionIndex, C10_SKILL_THROW);
}
if ((A0937_ui_Class >= C016_CLASS_FIRST_BOW) && (A0937_ui_Class < C112_CLASS_FIRST_MAGIC_WEAPON)) {
   A0936_ui_SkillLevel += F303_AA09_CHAMPION_GetSkillLevel(P650_i_ChampionIndex, C11_SKILL_SHOOT);
}
The second and third cases have +=, not simply =. This means that a dagger-and-axe-class weapon benefits from both your swinging and your throwing ability.

So this may be a bug in CSBwin?

Re: Source code is not making sense.

Posted: Fri Jul 17, 2020 9:40 pm
by Paul Stevens
Thank you, Sophia. I'll try to find that original assembly code.
I'd wager that you are right that it is a bug in the CSBwin translation.


****Edit****

That was easy! The code appears correct. The statements:

Code: Select all

      D6W = sw(D6W + DetermineMastery(chIdx, 10));
      D6W = sw(D6W + DetermineMastery(chIdx, 11));
are equivalent to (ignoring the casts)

D6W += DetermineMastery(chIdx, 10);
D6W += DetermineMastery(chIdx, 11);

Re: Source code is not making sense.

Posted: Fri Jul 17, 2020 10:36 pm
by Sophia
Oops, my eyes kind of glazed over at all the D6W's. That makes sense.

Hopefully it helps to explain what the code is doing, too! Now I'll have to double check DSB... :mrgreen:

Re: Source code is not making sense.

Posted: Fri Jul 17, 2020 10:47 pm
by Automaton
Thank you both for your replies!

Interesting!

@Paul - "Especially since you seem to be very good at it." You flatter me Sir!

I do have a knack for logical deduction though, it comes from my 20 years experience of telling my Oracle admins what their 1.9 million lines of DB are actually doing. I am quite sympathetic to your point of view - It's not because you are the data admin of a big DB, that you understand the business logic in the data (This I know from experience), along the lines of;

"Admin: Nick, we are having problems shipping an item because the field TUV_16 is set to 2."

"Me: Ya, you're trying to ship goods X to an address in Germany and the TUV won't let it in certain tunnels or across certain bridges, that's what the 2 means in that field"

"Amin: Oh, OK"

@Sophia - You seem to have an impressive grasp of things, although I guess I should expect nothing less from the creator of DSB :wink:

I wish my c++ was better, but I am learning.

The important thing here is the intent - like the anti-magic / anti-fire bug from the original ST versions. I think Christophe's reasoning was sound, and that sometimes a bit perfect copy may (will) include errors even the original devs never caught (and looking at the bug comments from Paul and Christophe, they seem quite numerous!). I've been sitting here looking at the code for 40 minutes now and trying to work out the original intent.

Did the devs originally mean for an << master skill 4 and skill 10 character to have +40 dmg (2 *(10*2)) going into the next part of the function?

I think not. It makes using the Dagger, Axe and Hardcleave unbalanced compared to the other weapons in game. And I see no logic in adding a bonus based on throw skill to hand held weapons.

I may be wrong, but my take on this is that you got it right, Paul got it right, Christophe got it right but the original Devs got it wrong.

Cheers!
Nick K.

P.S. @Sophia, in the other thread, on the subject of xp, I expect you 100%are correct, I will reply there once I am certain of what is going on.

Re: Source code is not making sense.

Posted: Fri Jul 17, 2020 11:21 pm
by Paul Stevens
And I see no logic in adding a bonus based on throw skill to hand held weapons
"Throw Skill"

Be careful. Any names we give these values is guesswork. The
original code may have used other names that make more sense.
"Arm Speed"? "Elbow Grease"?

Re: Source code is not making sense.

Posted: Sat Jul 18, 2020 1:39 am
by Automaton
Hi Paul,

I try (but sometimes fail) not to make rash assumptions, but in this case, I am making an assumption based on the data .

Image

From the cases mentioned previously and the class column above;

case 1 is the green (0 or 2)
case 2 is the blue (!=0 and <16)
case 3 is the orange (>=16 and <122)
and the red are not captured.

Case 2; all the weapons have throw as the first action, so there is some sense to base extra damage on skill 10.... ...except the Axe and Hardcleave.

Then the dagger - Has throw as first action, followed by stab and slash, so maybe there is a case to have 2 skills assigned to it's bonus.

But if that is the case, then the arrows and darts (which also have stab as a second skill) are missing out.

For the Axe and Hardcleave, I can only speculate that maybe some time during initial development, they also had "throw" as part of their action set but, IMHO, they are mis-classed now.

Note 1: Oh dear! I have just noticed that the Bolt Blade (class 113) is not captured. This is a Dev error IMHO (because if Fury is captured and gets extra damage, why not bolt blade?). Curious, the bolt blade has 66 shoot damage and 1 delta energy (not mentioned on DM encyc). I'd guess, that during development, it did something different.

Image

Cheers,
Nick K.

Re: Source code is not making sense.

Posted: Sat Jul 18, 2020 5:33 am
by Paul Stevens
Another thing that might be of interest to you; just to complicate things.

CSBwin is (as its name implies) a translation of the Atari "Chaos Strikes Back" game.
In retrospect, I discovered that it can also play "Dungeon Master". But many of the
objects and monsters have different names.

For example, you speak of a "Hardcleave". But there is no "Hardcleave" in CSBwin.
Most of the logic is driven by the databases but there are a few special cases
for particular items/monsters in the code. I don't know if any of these special
cases (in either CSB or DM) are important in your investigation. Nor do I know
if DM and CSB have the same special cases.

Re: Source code is not making sense.

Posted: Sat Jul 18, 2020 9:20 am
by Automaton
Sophia wrote: Fri Jul 17, 2020 10:36 pm Oops, my eyes kind of glazed over at all the D6W's. That makes sense.

Hopefully it helps to explain what the code is doing, too! Now I'll have to double check DSB... :mrgreen:
Probably my fault. I posted;
I can see in my traces that hits with the axe are trying to use 04 swing (which my char has a mastery level 4) , but its falling through to the 2nd case, picking up mastery skill 10 throw (which my char has a mastery level 8 ) and adding that to the damage roll instead.
> Weapon class = 2 so using skill 4 (swing) which is mastery level 4
10 (Throw) which is mastery level 8
Which was wrong. It was not 10 throw skill = 8 but rather level 4 swing being added to level 4 throw - my new additions to the attacktrace in CSB were wrong. Now fixed it looks like;
> Weapon class = 2 so using skills 4 (swing) and 10 (Throw) which combined is mastery level 8
for an axe and
> Weapon class = 0 so using skill 4 (swing) which is mastery level 4
for a sword

Cheers,
Nick K

Re: Source code is not making sense.

Posted: Sat Jul 18, 2020 9:48 am
by Automaton
Paul Stevens wrote: Sat Jul 18, 2020 5:33 am Another thing that might be of interest to you; just to complicate things.

CSBwin is (as its name implies) a translation of the Atari "Chaos Strikes Back" game.
In retrospect, I discovered that it can also play "Dungeon Master". But many of the
objects and monsters have different names.

For example, you speak of a "Hardcleave". But there is no "Hardcleave" in CSBwin.
Most of the logic is driven by the databases but there are a few special cases
for particular items/monsters in the code. I don't know if any of these special
cases (in either CSB or DM) are important in your investigation. Nor do I know
if DM and CSB have the same special cases.
Thanks Paul,

Yes, I took a cursory glance at the data back in 2004 and surmised that there was no difference.

I checked all the items again last night on DM encyc and could see nothing different in the stats of the items, apart some of their names and graphics.

Even as far as the Bolt blade, which becomes Storm in CSB keeping it's (to me, erroneous) class of 113 and it's shoot damage;

Image

The big difference in CSB is that quite a few items in your inventory do something to the game, through DSA's I assume?

Cheers,
Nick K.

Re: Source code is not making sense.

Posted: Sat Jul 18, 2020 11:04 am
by ChristopheF
the bolt blade has 66 shoot damage and 1 delta energy (not mentioned on DM encyc)
In ADGE.net, the 'byte1' value is actually what I called the weapon 'Class', with value 113 for Bolt Blade.

'Delta energy', 'fires 0xa', 'fires 0xb' are computed from this 'Class' value by ADGE.net (I checked in the ADGE.net source code).
However, these computed values have no meaning because the game does not use such computed values (I checked in my ReDMCSB source code). There is no such thing as 'Delta energy'.

Re: Source code is not making sense.

Posted: Sat Jul 18, 2020 5:59 pm
by Paul Stevens
The big difference in CSB is that quite a few items in your inventory do something to the game, through DSA's I assume?
Oh, dear, I hope not. There should be no DSAs in Chaos Strikes Back!
I invented them long after Chaos Strikes Back was released.

Can you provide an example of such an effect? I'll try to
explain it.

Re: Source code is not making sense.

Posted: Sun Jul 19, 2020 4:26 pm
by Automaton
Erk! probably my misunderstanding Paul.

I meant (in the original CSB) the;

A Falchion dropped at (03,21,25) will open the door at (03,21,24).
A Cape dropped at (09,30,37) will activate the teleporter at (09,30,37)
Leather Boots in your inventory will hold open the wall at (09,21,29) when walking at (09,21,28)
A Crown Of Nerra in your inventory will prevent Zytaz generation around (00,25,35) when walking at (00,17,30).
Taking the Shield Of Ra at (03,23,30) will launch Fireballs from (03,25,30).
A Dexhelm in your inventory will prevent Demon generation at (00,47,21) when walking at (00,41,18).

Type things.

Cheers,
Nick k.