Wednesday, February 20, 2013

"You got me blacklisted from Hop Sing's?"

"She named name!"

Before I go into naming monsters using the call command, I'd like to see descriptions of items remain in the inventory even after the item is identified.  "Snow boots of speed" is more informative than "boots of speed", and "silver ring of teleportation" is more informative than "ring of teleportation".  You can get the descriptions of identified items in-game anyway, so why not just stick that info in the inventory so we don't always have to look things up?

Moving on, I'd like to be able to name minions that your God grants you when you are sacrificing for an artifact.  I'm not sure why the decision was made to disallow naming of certain monsters.  Try naming that deva of whatziquotal to see what I'm talking about.  The inability to name names shopkeepers makes sense to some degree.  I'm sure there are people out there who thing that even attempting to name Izchak should result in instadeath (now that I think of it, this is not a bad idea).

As it turns out, you can indeed name minions (and priests for that matter) with the call command.  However, line 632 makes a call to the priestname function which will generate the minion's name based on alignment, etc, regardless of what you've called it.  So the name you call your minion exists in the computer's memory in the minion's permonst struct, but is ignored by the game.  I think simply replacing line 623 with if(mtmp->ispriest) { should do the trick, but I haven't yet tried it out.


Here's my proposal.  You can name any monster.  If you attempt to name an otherwise unnameable (i.e., unique) monster, it appends your name to their name.  Say, for example, you steal a magic lamp from Izchak and anger him.  You may end up back in Minetown much later in the game, so you might want to name Izchak "mad".  His name would then show up as Izchak mad or something along those lines, so you know to be careful on that level.  I suppose one could engrave on the staircases to a level where a shopkeeper is mad at you, so I may just end up restricting this to minions only.

Whatever I decide upon (reader suggestions encouraged!), there would be one exception, however.  Under no circumstances will you be able to name One-eyed Sam.   The reason is that when a shop is created, the shopkeeper will be given a name chosen randomly from a list of strings depending on the type of shop (lighting, books, general, etc).  I haven't quite figured out why, but someone decided that the game should randomly choose one shopkeeper name out of thirty-three for Sam, where all thirty-three names are One-eyed Sam, and in honor of whatever drug(s) that dev was taking at the time, I will keep it that way:



Even better, when the time comes to "randomly" select One-eyed Sam's name, the list is completely ignored, and his name is hard-coded instead:



Brilliant!

Monday, February 18, 2013

Psionics

As I mentioned in a previous post, the Psion has been a driving force in developing my own nethack variant.  Here are some of my thoughts:

They would somewhat resemble monks, i.e., can't wear armor, martial artists, etc.  Instead of getting intrinsic resistances as they progress in experience, psions would gain pychic powers, such as see invisible, telepathy, clairvoyance, and maybe eventually detect monsters (as an intrinsic), and flying.

They'd also need some psionic powers, like a telekinesis technique.  The slashem Jedi patch has a pretty good implementation for a telekinesis technique, bud I'd also like to add my own psychokinesis technique.

Psychokinesis: the player selects a physically visible target (as opposed to seen by telepathy), then selects a visible location to which to move the object.  The object can be a monster, an item, a pet, even the psion himself.  Damage would be dealt to monsters that are thrown into other monsters based on the affected monsters' sizes.  Damage would be dealt if an object (weapon, item, boulder, etc) was moved to a monster's location (i.e., hurled at a monster), potions would shatter.  The psion must not be blind, stunned, or confused.  Hallucination is okay, since it really opens up your mind, man.  There would  have to be a chance of failure if used to hurl a hostile monster.  Notes: (1) I need to fix the uppercase The in the below screenshots and (2) the rock-mole in the lower right shows up because I was toying with detect monsters as an intrinsic.





Anyway, this thought led me down the path to adding a new feature to the overall game play: the ability to pick-up and throw monsters.  Obviously, the held monster will have to be smaller than the player.  The held monster will try to escape each turn it is held.  It will also attack each turn it can, and will escape if the attack succeeds.  This can be useful for carrying pets across traps, or over water, lava, etc.  On the other hand, giants become more dangerous because they might choose to pick the player up and throw him into a trap, water, or lava.

Finally, the coup de grace of my Psion brainstorming: spellbook of dominate.  Here's the gist: when you cast dominate, you select a visible monster (I'm up in the air about whether visibility through telepathy should work in this case).  If you succeed in a check against the monster's magic resistance, you gain control of that monster for a short duration (50 turns? 100 turns? I'm leaning shorter rather than longer).

Implementing this will probably require some major restructuring of the code.  Currently, the game assumes that you can only control one character.  I would need to change things so that the player could control multiple monsters (himself included as a monster).

The interface should be such that it is clear to the player when he is moving the dominated monster(s) or moving himself.  This should be straight forward, just highlight the player under control, change the bottom line to show the stats of the dominated monster, and add a message like:
pline( "You control the %s with your mind!", Monnam(mtmp));

I can probably use some of the youpoly code as a hack to fake the game out into thinking you are polymorphed into the dominated monster at the location of that monster, with that monster's inventory, but I think a cleaner solution would be to abstract the movement interface/bottom line interface so that it's not geared towards a game where the player can only control a single monster.  (This could help pave the way to multiplayer nethack...but I'm not touching that one right now).

Monday, February 11, 2013

#two-handing artifacts

Slashem, to the joy of many players, allows you to wield two artifact weapons at once.  There's a catch, though.  You only gain "wield" effects from the primary weapon.  This was a simple implementation, since it only requires commenting out a few lines of code:


For the non-programmers out there, the "..." can be used for functions with variable-length argument lists, but in this case, it is instead most likely used as a place holder--a "fill this part in later", if you will (note the TODO).

The rest of the code, that deals with effects gained from wielding artifacts, is not changed.  Since nethack assumes you can only wield an artifact as a primary weapon, it only checks your primary weapon when it handles dealing out wielding effects.  I'd like to fix this to check both weapons when #twoweaponing.  In fact, there are other areas I'd like to have code for this, so I'm considering a CPP macro or an inline function.  Just to be clear, when I say CPP I am, and always will be, referring to the C pre-processor, not C++.  I know C++ in the sense that I can just write regular C code, but otherwise, C++ makes no sense to me (check out the C++ frequently questioned answers to get my gist: http://yosefk.com/c++fqa/).

In other news, for the first time in _ages_, I finally have a decent tourist game going. This one is very much ascendable.  I've only ascended a tourist once, so it'll be nice to double up.  I found an altar very early, dungeon level 2 or so, and sacrificed like a madman until I got Fire Brand, Frost Brand, Mjollnir, and Cleaver.  It was around then that I realized Grayswandir was a lawful, not neutral, weapon.  Fortunately, with all those other artifacts in existence, I managed to get Grayswandir out of a wish from a magic lamp found in the tourist quest.




Friday, February 8, 2013

coding_style

A brief history of my coding style.

The first language I learned was Java, so my style was, more or less, K&R with camelCase.  Overtime, I gotSickOfCamelCase in_favor_ of_underscores.  (Pro-tip: check out xmodmap for Linux and BSD machines.  I've mapped Shift+Spacebar to underscore, which makes my life, and my carpel tunnels, so much happier).


Most people consider this the holy grail of coding styles, and for good reason.  The nethack and slashem source is written in the K&R style, though the indentation is poor:



I don't have OCD.  My room's a mess, I have a few weeks worth of scruff grown on my face, but poor and/or inconsistent indentation and coding style drives me fucking crazy.  It's a trait my parents wish I had in every other aspect of my life, but only made it to programming and guitar playing.  I NEED it to be perfect, and though it never is (including my own code), I try to get it as close as possible.

Recently, I've changed my coding style a bit.  I've strayed from K&R in favor of an unnamed style. Below is an example of my new coding style, taken from a memory manager I wrote for a kernel driver.  On one hand, it wastes vertical space (an aspect K&R handles very well) but it's much easier for me to read.  Maybe you younguns out there disagree, but I've found that, as I've gotten older, I prefer a style that's easier on my 27 year-old eyes.  Note the extra space within parentheses.  Check out line 146 for my favorite pointer trick.



Complicated conditionals are


Are we having fun yet?

Thursday, February 7, 2013

Jedi patch v0.5 for slashem

I'll start today by looking at the Jedi patch.  I'd prefer a Star Fleet Officer role over Jedi, but Jedi fit much better into the slashem environment.  Until I can come up with a system for inter-specie diplomacy, the addition of a Star Fleet Officer role will have to wait.

Ever since slashem (http://slashem.sourceforge.net/) introduced me to lightsabers, I knew it was only a matter of time before someone made a Jedi starting role (http://www.crash-override.net/patchesslashem.html).  I am planning on making a grand variant that will incorporate code from a variety of patches and variants, so I started by checking out the Jedi patch.  I recommend following the previous link and reading the description.

Dodgy Code: 

There's the old saying about the NetHack Dev Team: "the dev team thinks of everything."  Lets run this dodgy code through the gauntlet.

"Also, a skilled Jedi with an activated lightsaber can dodge missiles fired at him (though not reflect them)."  Basically, if wielding a lit lightsaber, 

The first thing that popped out to me: what if the Jedi is wielding a lit lightsaber in her off-hand?  I soon realized that I was asking the wrong question, because the  followup question covered that: why does the Jedi's lightsaber need to be lit in order to dodge rocks thrown at her?  Furthermore, there's some inconsistency here.  A Jedi wearing armor gets -20 to hit, similar to Monk's wielding weapons.  But a Jedi wearing a brand spankin' new bronze plate mail is nimble as a fox.

So here's my proposal:
A Jedi can dodge missiles with a probability based on her proficiency in the lightsaber skill (must have at least "basic" proficiency).  The lightsaber shouldn't have to be lit, or even wielded, in order to dodge, but I figure I can use the lightsaber skill to gauge how "learned" the player is in the Jedi ways.  The Jedi should not be able to dodge while wearing armor, and Jedi should not be able to dodge if wielding a non-lightsaber object.  Yes, scalpels are indeed a clumsy weapon, as are tin openers and meat sticks.  The Jedi must be able to concentrate on the force, so they can't dodge if stunned or confused.  A blind Jedi can still dodge, but it's slightly more difficult.  This blog believes that hallucination should not restrict dodging.  I hear it really opens your mind to the force, man.

I also thought that an 80% dodge rate was a little high, so here's what I came up with.  The probability of a successful dodge is as follows:
$(r/6)$ where $r=Prof_{LS} - (1 * Blind)$.   skills.h #defines expert level as 4, skilled as 3, and basic as 2.  If a Jedi is blind, $1$ is subtracted from $r$.  Blind is just a macro that evaluates to a boolean, which on most flavors of unix, is 1 if TRUE, and 0 if FALSE.  Quiz: why is TRUE almost always defined as 1 instead of (-1)?  A: I have no idea, (-1) makes more sense to me. Anyway, a blind Jedi with expert proficiency in the lightsaber skill will dodge 50% of the objects thrown at him, so long as he's not wielding a non-lightsaber weapon. not wearing armor, not stunned, and not confused.

My favorite part of the Jedi patch description is, without a doubt: "The Jedi must then fight along some of his fellow Jedi against the stormtroopers and Lord Sidious himself to gain possession of this powerful artifact which can even reflect beam attacks!"  Holy shit!  A weapon that reflects beam attacks!  Oh wait, the Longbow of Diana does that too...

So, for fun, I added a system of lightsaber deflection.  First, the Jedi must be wielding at least one lit lightsaber, and no armor.  The probability of deflecting a beam is as follows:
$(r/10)$ where $r=(Prof_{LS}) - (1 * Blind) + (bonus_{LS})$.  "bonus" does not refer to enchantment bonus, rather, +1 per lit lightsaber wielded (+2 if double lightsaber).  If two-weaponing, the Jedi must be at least "basic" in two-weapon combat to get the bonus.  If the Jedi succeeds in the deflection check, then there's an additional check, with the same probability.  If the additional check succeeds, the Jedi may choose the direction in which to deflect the beam, otherwise, it is reflected in a random direction.  So, if somehow two lit double lightsabers (both beams lit) are two-weaponed, that's a +4 bonus.  A non-blind Jedi, expert in lightsaber, skilled in two-weapon combat, wielding two lit lightsabers will have a 60% of deflecting the beam, and if she succeeds, another 60% of choosing the direction in which to deflect the beam, otherwise, it is deflected in a random direction.

There's some balance to this.  Yes, it's nice for a starting Jedi to have a 20% chance of deflecting beams, however, due to the nature of random deflection, the Jedi may deflect the beam into a pet, a shopkeeper, watchman, some other peaceful monster, or even herself.  The lightsaber deflecting code comes before testing for reflection (from amulet of reflecting, silver dragon scale mail, etc) so even with reflection, a Jedi still runs the risk of randomly deflecting the beam at a peaceful.  If the Jedi has reflection and randomly deflects at herself, then it will reflect as normal.  The series of screen shots below show an example of lightsaber deflection when the Jedi may choose the deflection direction.  I chose down and to the left to show that deflected beams bounce off walls and otherwise behave like ordinary beams.






Jedi Alignment:

In the original Jedi patch, Jedi must be lawful, and must follow a strict moral code, similar to a knight.  But what about Dark (chaotic) Jedi?  I wanted to make chaotic Jedi a valid starting role, but it doesn't make sense for a chaotic Jedi to follow a strict moral code.  I couldn't just get rid of the moral code checks for a chaotic Jedi, because that would be unfair to the lawful Jedi.  So, here's the deal for chaotic Jedi: any wielded lit lightsaber functions as if bloodthirsty (like Stormbringer), so you will automatically attack pets and peacefuls.  I figured this makes sense as the dark side like to kill things.  If the lightsaber is not lit, then it is not bloodthirsty.

Also, I thought that the two different alignments of Jedi should receive different first sacrifice gifts.  Regardless of alignment, all artifact lightsabers do not need to be recharged, and all lightsabers emit a light with a radius of 2.

The first sacrifice gift for lawful Jedi is The Windu Blade, in honor of my man Samuel L. Jackson.  It is a violet lightsaber, which which deal slightly more damage than green lightsaber: 9+d5 vs. small, 12 + d7 vs. large.  It also has +5 to-hit and +10 damage against cross-aligned monsters.  This might be a little too powerful, so I'm considering changing it to +5 to-hit and +10 damage against undead.

The first sacrifice gift for chaotic Jedi is The Darth Maul Blade.  It's basically Stormbringer in the form of a double red lightsaber: +d5 to-hit and +d2 damage to non level-drain resistant monsters, plus an additional d8 of damage is dealt to current and maximum hit points, half of which goes to heal the wielder.  This might also be a bit overpowered as weapons go,  One thing I am considering is removing  the drain resistance it grants to its wielder.

For both artifact lightsabers, I'm open to suggestions.

Wednesday, February 6, 2013

time to make a nethack variant

As an avid fan and player of nethack and its variants, I've always been struck with ideas for additions/changes to the game while playing.  As a C programmer, it only made sense to make my own nethack variant.

My posts will contain my thoughts about game play as well as my thoughts about the code.  Some posts will be geared more towards general game play concepts and brainstorming, such as thoughts for new roles or races.  Some posts will be geared more towards game specifics, such as racial stats, role abilities, probabilities of succeeding at various tasks.  Finally, some posts _may_ end up being geared towards coding, such as monster struct consolidation, the use of function pointer lists for special attacks, and the beauties of C type declarations.  Even if you don't care about the code stuff, all posts will be geared towards nethack, so feel free to comment on, question about, or suggest anything.

I'll be using the slashem source code as a base for my project, however, I plan on adding features from several different variants (such as sporkhack and unnethack), other patches (color alchemy, hpmon) and new features of my own.  At the end of all this, and potentially throughout development, I will, of course, make the source code available for y'all to test.  In addition, I will also make pkg.tar.gz and .tgz files available for easy installation on Arch Linux and FreeBSD, respectively.  Most of my testing will be done on Arch Linux (if you think ascending a Tourist is hard, try building nethack from source on an Ubuntu or Mint box).  I will also be compiling with gcc, and _maybe_ LLVM on BSD, so hopefully using the two different compilers will catch any mistakes I make relating to compiler specific extensions, like branch prediction (which is fun but generally not needed for a turn-based, user-land game) or other code that doesn't fit the old C89 standard.



As this is the first blog entry, I will lay out my big-picture plans and *try* to leave the details for future posts.  Keep in mind, a lot of this is still in the brainstorming phase.

1) Re-write/re-structure large parts of the game engine.

First, I will split the code into two modules.  The first module will handle game play.  I will replace all closures with their equivalent trigraphs, then implement the entire game in a single function using only pre-processor macros.  All control flow will be handled with goto's.  The second module will parse the data files, and will be written entirely in perl keywords.

All kidding aside, the slashem code is pretty kludgy.  Then again, I'm used to kernel programming, where we like to keep things robust and concise instead of adding lots of complicated conditionals for specific situations, of which there are many in slashem.  That said, I do not see any reason why the 'hit monster' function has to be 1000 lines of nested if and switch blocks.

Basically, I want to make the code more generic.

For example, there are three different source files for hitting things: monsters hitting you (mhitu.c), you hitting monsters (uhitm.c), and monsters hitting monsters (mhitm.c).  There is also a file for monsters throwing items at you (mthrowu.c), and you throwing items at monsters (dothrow.c).  (Can you guess which file contains the code for monsters throwing at monsters?)


2) Religion.

Alignment will play a bigger role in things, from first sacrifice artifacts to different codes of conduct.  Similar to sporkhack, sacrifice gifts are not guaranteed to be artifacts, and the probability with which you receive an artifact gift from a sacrifice will be based on xp level.


3) Add new stuff (below are just some examples).

3a) New Races.

Kobold strikes me as a reasonable starting race.  They would have a racial technique at first level, "Poison", that poisons inventory objects such as darts or other projectiles.

Mindflayer is another race I'm considering.  They would probably resemble Vampires in slashem, i.e., start with a penalty (either slow, or negative luck) and they would have a bite attack, but they wouldn't fly and would have better Int and Wis stats.

3b) New Roles.

Soldier: the game has guns, why not have a soldier role?  They would be able to attain "expert" in firearm proficiency, among other weapons.  The quest artifact, of course, would be The Holy Hand Grenade.  More details on this in a future post.

Jedi: slashem has lightsabers, so of course, someone already made a Jedi patch.  I had some issues with it, so I improved (according to me, at least) on the Jedi role substantially.  I'll have a more detailed post about this in the future, and I'll make the patch available when I'm happy with it.

Psion: this one is my real brain child.  I'm saving the details for a future post(s), but let's just say that brainstorming for the Psion role has been a driving force behind other changes I want to make to the game that will affect all roles (quick teaser: a system for throwing, and being thrown by, monsters).


3c) New Monsters.

Probably some monsters from the biodiversity patch and Gold Dragons from sporkhack, to name a few.


3d) New Items.

Definitely going to include the "bag of poo" from sporkhack.  I also like sporkhack's magic staff system.  Also, why not add things like Gauntlets of Offense, spellbooks of probing, and wands of wonder?  Nethack and its variants make references to various parts of geek culture, but they all left out one of the greatest roguelikes of all time: Toe Jame & Earl.  Rocket Skates anyone?  I envision them as being generated cursed most of the time, providing a faster movement rate than boots of speed, while forcing you to run (as if holding down the shift key when moving).


4) Interface.

No real changes here.  I've seen screenshots of the inventory window patch, and other similar layout patches, but I've never tried them.  Honestly, I think they are a great idea, but I'm not going to include them because I feel that the game should be able to fit in a standard 80x24 console.