Sunday, July 21, 2013

GAHHH_NEW_POST!

Now that I'm sure everyone has stopped visiting this blog, I am back!  I was very busy for a while at work as we had a very important deadline approaching for a couple of months.  But that deadline was reached, and good news abounds!  My tiny little start-up was very recently acquired by the best possible company that could've acquired us.  Everybody's happy.

Now, back to nethack.  I haven't played in so long that I've forgotten a lot of the little nitty-gritty spoilers I used to know.  I once again have to look up specific prices of scrolls, potions, rings, etc.  Of course, I'll never forget that my three favorite rings, slow digestion, free action, and levitation (in that order), are all 200 Zk.  Regardless, I'll probably need a little ramp-up time to refamiliarize myself with the little details of the game, as well as the intricacies of the gameplay, before I can jump back into the code.

What's important to take away though, is that this blog is not dead.  It was just wearing an amulet of live saving (ugh, I know, awful joke.  I'm here all week).

Secondly, what's important to take away is that I finally finished my tourist game.  Tourist is one of the best roles in the game.  The early game is very difficult, but the quest artifact is arguably the best in the game, and the quest itself yields tons of loot.

One fun little stupid thing I like to do is chat with Death.  The background is that there are four Riders of the Apocalypse, explained in great depth in The Book of Revelation.  It's a great read, and if you haven't read it, it's probably one of those things you should read aloud to your children at bedtime.  In the words of my boy TJ (Thomas Jefferson), it is "merely the ravings of a maniac, no more worthy nor capable of explanation than the incoherences of our own nightly dreams."

On the Astral Plane, in nethack, you will find three of these Riders: Famine, Pestilence (also know as Conquest in the BoR), and Death.  If I am able, I always make a point to chat with Death, because he gives some insight into who the fourth Rider is:



This actually makes a lot of sense.  You spend the game going through a dungeon killing thousands of creatures.  I can't really think of a better definition of "war" than that.










Monday, April 22, 2013

Ugh.. more off topic

Oy, time has been short.  Exciting things are going on at the start-up I work for, so most of my efforts have been focused there.  I was able to do some brainstorming today about nethack stuff, so I'm excited to get back into nethack coding.

A quick rant, very off-topic:

I run Arch Linux on my home laptop.  It's an absolutely brilliant distribution.  Forever, I've loved everything about Linux.  When I gave FreeBSD a try, I was introduced to the ports tree, and quite frankly, it's the greatest thing existing in the field of operating systems.  On top of that, the rolling release model just made so much more sense than, for example, Ubuntu's "every six months whether it's broken or not" release model.

Anyway, a few months back, I discovered Arch Linux.  It had everything I could ever ask for in this world.  It ran a Linux kernel, but also had a ports tree, called the Arch Build System (ABS), as well as a rolling release model.  Fucking brilliant.

Gnome.  Underrated race in nethack, and also a perfect desktop environment for Linux/BSD.  I'd go as far as saying that Gnome2 is the Holy Arc of the Covenant of desktop environments.  Unfortunately, Gnome3 is the Treblinka of desktop environments.

No problem, though, because some clever folks forked Gnome2 and made MATE.  I've been running with MATE on Linux for a while now, and am lucky enough that Gnome2 is still supported in FreeBSD.

Things changed recently when I did a full system upgrade on my Arch box and installed MATE 1.6.  They got rid of the weather applet!!!  Granted, this could be Arch Linux specific (please comment and let me know if it is), or maybe I'm doing something wrong, but damn!  I loved that panel applet.

These days, UI innovation seems to revolve around "what can we remove?" rather than "what can we add?"  It's a fucking awful approach, because you lose users each time beloved features are removed, and with Linux, you rarely gain new users because people are somehow afraid of the best operating system currently in existence, thanks to FUD campaigns by various entities that view Linux as a rival... as they should, because technology that existed in the Linux kernel (and BSD kernel) 10 years ago is finally gracing OS's like Windows and OSX today (Hell, OSX took their kernel from BSD and Mach, because Apple realized they could not produce anything better).  10 years is a very long time when it comes to computer technology.

So, I've switched to Xfce 4.10 for the time being.  So far, I'm very happy with it.  The Xfce4 weather applet even has wind speed!  6mph in Allston, MA right now.

In other news, my (as my co-worker puts it) +1 Gauntlets of Coding arrived.  They're just wrist braces to combat carpal tunnel syndrome, but with my ergonomic keyboard and vertical mouse, carpal tunnel doesn't stand a chance.  The wrist braces were supposed to arrive last Friday, but when I saw the tracking info, they were listed as being in Watertown, MA, in the heat of the lockdown... no way in hell they would be delivered to me then.  I'm glad we got the younger brother/bomber alive.

Monday, April 15, 2013

Something else to remember on Patriots' Day

Patriots' Day is a holiday celebrated in Massachusetts to commemorate the anniversary of the Battles of Lexingon and Concord, to which my home town of Sudbury, MA, sent the most militia men out of any other city or town in the colonies.

Earlier today, multiple bombs went off in my city, near the finish line of the Boston Marathon.  I've been in touch with a couple of my friends and am trying to find out if the rest are okay.  

I was lucky enough to not have the day off from work, as most people did, so I was safe at work during the time of the explosions.  My thoughts go out to any and all affected by this horrific tragedy.


Wednesday, April 10, 2013

busy busy busy

Sorry, updates are going to be slow for a little while.  My company is in crunch mode for our next release, so I'm just writing to let y'all know, I haven't abandoned the blog, or my variant.  I haven't abandoned nethack either, even though I haven't played my awesome tourist game in ages.  The PYEC is such a good artifact.

In the meantime, my mouse's wheel click has started pasting text when it opens links in new windows, as opposed to before when it would open links in new tabs without pasting.  All my searching so far has told me that is default functionality in X, and unless I want to hack X (a possibility...), I'm going to have to deal with it.

I wonder why it didn't paste before?  It doesn't on my Arch Linux system, which is running X, just on my Linux Mint system.  Maybe some update got me.  The nice thing about minimalist distributions is that they don't get cluttered with unwanted stuff.

Wednesday, March 27, 2013

Next Steps

I've been slow to update recently, since my company is releasing a new version of its software at the end of the week...

But!  My next step is to merge struct you with struct monst, or rather, take out redundant data, like location, alignment, intrinsics, etc, etc, etc, etc, etc.  I want to treat monsters and the player more equally, though I realize there will be some things that are specific to struct you.  the game has a global struct you u, and a global struct monst youmonst, and in some cases, it seems arbitrary which one is used.


On an completely unrelated note, I stumbled across this gem the other day on one of those 'horrors of coding' sites:


    static boolean isTrue(boolean b) { 
        HashMap map = new HashMap();
        b = ! !b;
        if (!(!(b == !b)) == false) {
            map.put(false, !(!(b != !b)));
        }    
        return !map.containsKey(b) & (!true | !false);
    }

I believe this is Java code.  It may also work in JavaScript but, fortunately, I'm not familiar with JS.  It may be the most amazing piece of code I've ever seen, maybe even better than x[strlen(x)] = '\0';.


Friday, March 22, 2013

sporkhack

I was inspired by the subject line of a co-worker's email: "+1 Gauntlets of Coding".  It was just an email with a link to wrist braces for carpal tunnel syndrome, but I really like the sound of Gauntlets of Coding.  I_have a couple ideas: when wearing Gauntlets of Coding, you movement speed will increase only when using the travel command.  Or, it gives you jumping.  Both are pretty big stretches at puns about using goto statements to either travel faster, or jump through code...  yeah...  I'll probably make Gauntlets of Coding a compile-time option, defaulting to not include them.

Moving on...

Sporkhack!  I've been spending more time playing sporkhack, and I have to say, what a fucking brilliant game.  So many changes.  From partial resistances, to sacrifice gifts based on XP level, to chaotic Knights, to variable telepathy range, to new items like gold dragon armor, shield of light, Dirge, etc... fucking brilliant.

Where some variants put a lot of effort into nice ncurses interfaces, sporkhack is all about gameplay. I'm seriously considering ditching the slashem source as my code base for my variant and starting with sporkhack instead, since there are just too many features from sporkhack that I like, and most of them are the bag of poo:



I do have two gripes about sporkhack, and they are very, very minor.  One, I don't like the new character creation screen.  When I start a new nethack game, I know what I want to play as, so I just run: $ nethack -u greg-rog-hum-fem for example, and the game starts.  Even if you do that in sporkhack, you still get taken to this screen:


So you have to press "." to start playing.  I realize how this starting screen can be helpful to new players, since it lets you know what combinations of role, race, and alignment are allowed, but I guess I'm just old and stubborn and like the vanilla nethack character creation system better.  Also, I sometimes run into a bug where, when starting a new game, I get stuck in a corner with no map.  I even tried starting as an archaeologist to see if I could dig my way out, but no dice:




Has anyone else run into this?  I'm using the sporkhack-svn package from the Arch User Repository, so it's possible that this bug is specific to that code.

...

When it comes to debugging, my strategy revolves entirely around printk (printf if I'm in userland).  I don't use gdb because I don't know how.  I've always wanted to learn... but it just seems too daunting of an exercise.  Sometimes I'll resort to objdump or readelf in a bind, but mostly, I just print out whatever things I'm curious about.

Is there a good way to dump debugging messages in nethack, other than using the pline function?  If not, I'll write a patch that will log debug messages to a log file.  Then anyone could just call something like nh_trace( LOG_WARNING, "blah blah blah %s, blah %d", ... ) instead of using pline, which interferes with gameplay.

Tuesday, March 19, 2013

Girl Power!

Who doesn't love numbers?  Well, sadly most people, and yet they still remain the best way of measuring things.  Go figure.

Special thanks to NetHack 4's maintainer, ais523, for the data.

These numbers do not include games that were started but never finished.  The player either had to die, ascend, die, quit, die, escape, die, or be killed.  There were 2788 games in total.

First, let's look at starting role vs. max xp level:


Okay, nothing too surprising here.  Valkyrie remains a solid choice.  Wizard has a tough early game but can become very powerful in the mid and endgame.  Tourist did remarkably well, meaning there are quite a few badass NH4 players out there.

One thing I'd really like to point out is that the Monk dominates the early game.  Lots of people dump on the monk, I don't know why, because they're not bad.  Only drawback, of course, is that they can't wear Gray or Silver Dragon Scale Mail unless at a high enough level to get over the big to-hit penalty.

Role vs. points is pretty similar, no surprise there, so I won't bother with the graph. How about ascensions by role?


Once again Valkyrie, Wizard, and Tourist take the lead!  More importantly, I'd like to see role popularity, because that will clearly affect the number of per-role ascensions.  (Thanks to the HockeyblogAdventure for pointing out the typo in the below graph title.  I'll maybe fix it when I get home from work).

This confirms one of my theories about Barbarians: they're boring to play.  Wizards are always interesting, though it's sad to see a lack of love for my favorite role, the Rogue.  It also confirms that Valkyries are strong role.  They are relatively unpopular (perhaps because they are so strong) yet have the most ascensions.

Also interestingly, people prefer to play Male characters, but Females have more wins.  Only ~24% of the players used female characters, but they accounted for ~64% of the ascensions:


I usually play female characters because I figure that if I polymorph into an egg-laying monster, like a dragon or cockatrice, I can make myself lots of awesome pets.  On the other hand, if an egg hatches in a male character's inventory, there's a 50% chance of it being tame.  On one hand, I don't use the egg-laying trick in most games, but on the other hand, when I do use the trick, I get lots and lots of pets out of it.  I'm curious what other peoples' preferences are.

Anyway, this post was just about some fun with numbers.  Let me know if there are any other interesting or more complicated stats you want to see.  I use the R project for a stats program, and it is superb.  Here are the fields with which I have to work:


"points"    "deathdnum" "deathlev"  "maxlev"    "hp"
"maxhp"     "deaths"    "deathdate" "birthdate" "uid"
"role"      "race"      "gender"    "align"     "name"
"charname"  "death"     "conduct"   "turns"     "event"
"carried"   "starttime" "endtime"   "gender0"   "align0"
"xplevel"   "exp"       "mode"


Also let me know if there are questions about what the fields mean.  I think the most confusing one might be align0 and gender0 which refer to starting alignment and gender, where as align and gender refer to alignment and gender at the game's end.  I don't know what the event field is.

Thursday, March 14, 2013

code restructuring, again

I applied the CK patch my kernel last night to give the Brain Fuck Scheduler and Budget Sector Queue I/O scheduler a try.  I'm more interested in the I/O scheduler since disk access is much slower than context switching, though in theory, BFS should give me ~2% better performance... 2%... yay!  Also, I know more about storage than CPU architecture, so I have a better idea about what's going on.  I gotta say though, I'm impressed with how quickly BFQ hits my external drive.

Moving on...

It's a sad day in Boston.  The Pats traded Wes Welker.  Everyone's pissed.

Moving on...

I came up with a better way to do code restructuring.  First, techniques can stay in their crazy switch block.  You can only do one technique at a time anyway, so there's no point in using function pointer madness.  However, none should return inside their case, rather, they should just break out instead and a single return will be placed at the end of the function.  Each should also specify their own timeouts.  Some do, some use the timeout at the end, some don't even have timeouts:



This is true of techniques and magical effects in general.  Being effects, all they do is modify data, so they can return void.  If it matters whether you succeeded or not, you can always check the condition after it returns.  Instead of linked lists for weapon effects, it will just be a dynamically sized array of effects, and I can loop over the switch blocks and apply each effect in turn.

Tuesday, March 12, 2013

random thoughts

I haven't had much time lately between a Bruins double header that started last night and heading up to VT to ski last weekend.  By the way, don't get stuck in chest deep powder, it fucking sucks.

Anyway, some ideas:
 - Weapons dipped in potions of sleep have a chance of putting a non-sleep resistant monster to sleep on a hit.
 - Weapons dipped in potions of acid do some acid damage on a hit.
 - Weapons dipped in potions of paralyze have a chance of paralyzing a monster for a random, short duration on a hit.
 - I'm sure there are some other cases.

 - Lenses of Infravision
 - Sunglasses (Lenses of Shade?) that would protect against blinding light-based attacks, and maybe give you +1 charisma when worn because they are so cool.
 - Artifact lenses that give you some sort of gaze attack when invoked at the cost of some magic power.

 - Shields of fire, ice, acid, whatever, from sporkhack, have a chance of doing passive damage to a monster if the monster does not hit you and you get the message that you deflected the attack with your shield.

Soldier role:

Soldiers can reach expert in firearms, saber, and maybe skilled in long sword and a few other weapons.  They would start with a pistol, as well as typical soldier gear: low boots, leather gloves, saber, dented pot, leather armor, tin whistle, and a few K or C rations.

I can't think of a good first sacrifice gift.  I don't just want to make it a gun because you'll have plenty of opportunities to pick up a gun later.  Maybe a magic magazine, base item bag, that generates a random number of bullets when invoked... but then again, you also have plenty of opportunities to pick up bullets throughout the game.  Maybe a special gun, a Magnum, base item pistol, that does more damage than a pistol and has a chance of stunning and/or knocking back an opponent like a monk's stunning strike.

The quest artifact would be The Holy Hand Grenade, generated blessed (since it's Holy), and the base item is a stick of dynamite (it's already in the code, not randomly generated though, so you'd need to wish for one).  Instead of the long fuse sticks of dynamite have, an armed Holy Hand Grenade would detonate in 3 turns, "One... Two... Three..." or sometimes 5 turns, "One...Two... Five!  I mean Three!"  Detonation would not destroy the Holy Hand Grenade, i.e., it can be reused, however, monsters can throw it back at you, of course.

The Holy Hand Grenade would grant some intrinsics when carried, but I've yet to figure them out.  I thought maybe fire resistance, but then you could just arm it in your inventory and become a suicide bomber...so you'll have to find another source of fire resistance if you want to do that.  Maybe extrinsic telepathy and half physical damage, or drain resistance (since it's Holy?), or something along those lines.  I'm open to suggestions.

The quest nemesis would be The Killer Rabbit of Caerbanno, base monster would be a rabbit.  It would be fast, or maybe very fast.  Would have stoning resistance and maybe some other resistances, but not fire.  Maybe I'll give him an extra bite attack or two, or a slim chance (5%) of his attack causing instadeath.

Thursday, March 7, 2013

code restructuring: technique

Before I talk about the restructuring of the technique code, I want to extend a big thank you to Finland, which is the source of the majority of my blog views, per capita (USA wins out in overall quantity).  In honor of your Finnish dedication, I will add a new comestible to my variant: lutefisk (please let me know if this is the wrong term in Finland).

My current thought is that it will behave similarly to royal jelly, but when eaten, will give the message: "This tastes like the worst thing you've ever tasted!"  I may change the message for the case when confused by a potion of booze, as I once read a guide to eating lutefisk online, and the first step was "get so drunk that you can't taste it."

...

Moving on, I'm almost done with restructuring the technique code.  Instead of a long switch statement, I'm using a function pointer for each technique.  This will allow for the potential of techniques having more than one effect, as the new tech struct can have a linked list of function pointers, where each function is called in serial.

For example, say we want a technique that deals cold damage and stuns the target monster, and a technique that deals fire damage and stuns the target monster.  The two techniques can share the stun code, so the first would have a linked list containing two function pointers, one to fire damage technique code, and one to stun technique code, whereas the second would have a pointer to cold damage technique code and a function pointer to the same stun code as 'fire-stun'.

Why restructure?  Part of the reason is because of shit like this:


A closer look:



This unreachable break statement appears all over tech.c.  My guess is that someone made the mistake early, when writing tech.c, then copy and pasted the mistake in several more places.  It doesn't make the game not function, but it's ugly.

With the new system I'm implementing, there could also be hybrid/random techniques that randomly select from a couple of the technique function pointers (they'd have to be compatible... combining bless and raise zombies doesn't make any sense).  These random/hybrid techniques could potentially be granted as sacrifice gifts, which would add an interesting dynamic to sacrificing.

As a next step, I'm going to take on the scroll/potions/spell effects... i.e., the type of stuff that can be broken up pretty easily.  Once again, the new structuring will allow for craziness like scrolls/potions/spells with multiple effects, etc, if I, or someone else, decides to add that in the future.

The point of all this is to make the code much more loosely coupled to make expanding and modifying the game easier.

Monday, March 4, 2013

"oh the beauties of C type declarations"

If you can figure out what I'm referencing in the title, you win a FREE download of the original nethack-3.4.3 source code from www.nethack.org!

...

As I mentioned in a previous post, the psion role is one of the motivations for making a nethack/slashem variant in the first place; the other being, why not?  Basically, the dominate ability will allow a player (or a psion) to willfully control another monster.

When you dominate a monster, you get to control it's moves and actions for, say, 25 turns, plus or minus some random amount.  I realize this can be too powerful in many ways, like walking a tough monster into lava to get rid of it, causing a nymph to drop your precious magicbane, or potentially, having a dominated monster on the astral plane zap a wand of teleport at pestilence to get him away from you.

Anyway, I've had some page views since I shamelessly (shamefully really) plugged my blog on the nethackwiki, so I'm hoping you guys can give me some suggestions.  For example, I can't decide whether to make it a technique or a HIGH level enchant spell.  On one hand, a technique makes sense if I want to restrict it to psions.  On the other hand, do I want to restrict it to psions?  And on the third hand, in implementing the dominate power, I will allow for the possibility of dominating more than one monster at a time.  There is a problem with the third hand though; it will slow down game play... no travel, no run, etc, because you have to control each dominate monster (plus yourself) individually, each step of the way, one step at a time...

Monsters would have a chance to resist, and there'd probably have to be monsters on the no-dominate list--shopkeepers and temple priests, special quest folk--but you'd definitely get a bonus against foocubi.

I've been hacking around the already hacked to death slashem code (I'm very guilty of returning early in functions as a shortcut, but does a function really need 30 return statements?).  I'm pretty close to a functional dominate within the current slashem code, but after going through monmove.c, I decided I need to re-prioritize.

The current game engine cannot support the dominate ability (as I envision it) without gross hacks and workarounds.  Originally I figured I could steal some of the polyself.c code and use gotos in the moveloop in allmain.c; in other words, gross, gross, despicable hacks.

This is about the state it was in when I decided to re-prioritize (the cursor to the northwest is just to show that it's a selection thing.  Nothing new there.  Eventually I'm going to move the cursor over to the kitten):




And then I moved him to the left... or tried.  The kitten is actually one place to the left, but I didn't get the screen drawing/updating working before I temporarily pushed the dominate implementation to the back burner.


Since I plan on restructuring parts of the code anyway, I'm going to do restructuring in parallel with hacking around with new ideas because the current code is too rigid at present for what I want to do with it.

I plan on breaking apart some of the monolithic functions into several more modular functions. The overall goal of the restructuring is to separate the game engine from, well, everything else (items, monsters, roles, races, etc).  I want to keep the interfaces to the game engine as uniform as possible for player and monster alike.  The hope is to make it easier to add new items, monsters, roles, races, and entire systems (bards, music, anyone?) to the game.

Also, a robust interface to monster strategy could pave the way for experimenting with alternative strategies, like monster AI-based strategies, or evolving/adapting strategies.  I will make this a future blog post, because I also have ideas for in-game evolution of both monster strategy and, well, monster creation.  What do you get when you cross a yellow dragon with a silver dragon?  A gold dragon egg.

Anyway, I'm going to start with techniques because that's already a pretty self contained system. Instead of the nearly 1000 line-long switch statement, I'm going to remake the tech struct to contain a function pointer to a function that handles that particular technique's effects.  I figure function-call overhead vs. switch statement efficiency isn't going to make a difference in a turn-based, user-land game.

Besides, who doesn't like to bask in the beauties of C type declarations.

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.

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.