Saturday, March 2, 2013

more on #twoweapon

I've been thinking more about the topic of two-weapon combat in slashem, specifically, trying to figure out the reasoning behind the scheme in which certain starting races are not allowed to #twoweapon.  This pulled me into the nethack code, which also has some quirks regarding two-weaponing.  

I use nethackwiki.com all the time (much of it based on the ol' statslab txt spoilers: http://www.statslab.cam.ac.uk/~eva/nethack/spoilerlist.html).  Needless to say, it's generally the the best place to go for your spoiler needs.  It tells you the 'what', and though it doesn't always tell you the 'why' upfront, it does openly reference the source code for those who want to dig further, which y'all gotta admit, is pretty awesome.  This post will go past the level of 'spoiler' down to the inner workings of the code.  This post will delve deeply into the 'why'... or rather, try to figure out why the why is why it is.

To start, I have to explain a little bit about the monst struct and attacks.  monst.c contains stats (number of attacks, special attacks, resistances, intrinsics, etc) for all of the monsters in the game.  Say for example, you are playing as an orcish rogue.  In monst.c, we can see that orcs only have one "weapon type" attack:




To briefly describe the structure, every
monst has 6 possible attacks, so in the above picture, you can see that the remaining 5 attacks are NO_ATTK, meaning they just don't have any extra attacks.  A mind flayer, on the other hand, has 4 tentacle attacks.  The first attack is of type AT_WEAP, so the mind flayer can wield a weapon, but the remaining 3 attacks are tentacle attacks, i.e., of type AT_TENT, so the struct looks like:


Nethack has a C pre-processor macro that checks for whether a monster can, or rather, could two-weapon:


In other words, if the monst has a second "weapon type" attack, it may #twoweapon, as seen here:



So why can your orcish rogue wield two weapons at once?  Because the game uses the rogue monst struct when doing the two weapon check, and the rogue monst has a second weapon attack, as can be seen on line 3002:



Now, we've all had the awesome idea of playing nethack as a monk and fighting with both hands, and we were all deeply saddened when slapped in the face with a message like this:



Yet, I could've sworn that, when watching Ong-bak, Tony Jaa hit someone with his left fist.  So why, in Nethack, are monks restricted?  Turns out, the monk monst in monst.c has a second attack, but it's of type AT_KICK:



This will cause two-weapon combat to fail when that could_twoweapon macro above evaluates to 0 since the second attack is not a weapon attack.  Furthermore, the monk does not get the kick attack as an encountered monster monk does, because a monster only gets that extra kick in the hitmas function (short for, "hit monster as" a different type of monsters), which is only called if you are polymorphed.  So, the only way to play as a monk and have two attacks, though the second one would be a kick, would be to play as a non-monk, then polymorph yourself into a monk.  (Actually, now I kind of really want to do this).

I want to make something clear.  I do not want this blog to be about bashing the nethack code.  I think nethack is the best computer game ever made.  Part of the reason I am starting with the slashem code base is because I'd prefer to leave the nethack code as it is, untouched, in it's full glory.  I admit, I use the hpmon and menucolors patch, but the game engine itself is untouched.

I do, however, wonder if this behavior, of disallowing two-weaponing for monks, was intentional or a side-effect of the way the game was coded.  Obviously, the dev team would've noticed such behavior in testing, so it's possible that this was intentional, though it's also possible that a developer noticed it, checked the code, and said, "meh, that seems fair, I'll leave it that way."

Slashem seems to handle the monst struct differently, and it's the reason that elves can't two weapon, yet drow can, but I'll leave slashem's two-weaponing for another post.

Anyway, to conclude, my proposal is that anything with two arms should be able to #twoweapon.  This will involve fundamentally changing the way attacking is handled and monsters are defined, so that will have to wait for a future post as well.

No comments:

Post a Comment