This is a heavily modified version of Frits Daalmans' Parsival borg,
incorporating many bug fixes, features of my previous borg, and some new stuff 
too.  The root borg for all these modifications was the stock 2.7.7v3
borg-ben.c.  2.7.7v4 will compile this borg just fine also.  Be sure to use
the -DFRITS flag in the makefile, define all the stuff needed in config.h,
and define AUTO_PLAY also.

I've been awhile releasing this due to constant changes, bug fixes, etc.  I
have hopefully ironed out most of the bugs by now.  Those still known are
mentioned further down.  Since so much of the code has been changed, it will
be quite a long time before I even think of modifying the 2.7.8 borg, or
whatever version is out by then, since it would take SO much cutting and
pasting, not to mention changes to make some of the patches still work.
I hope I've listed all the changes I've made, but I could have forgotten a
few.

I also patched in the borg_think() function from 2.7.7v4 so the borg would
work right under 2.7.7v4.  It still works properly under 2.7.7v3.  The
problem was that any staff, wand, or light source would not register as
identified, and all scrolls would be used up and all mana used up identifying
them over and over.  The problem lay in the "cheat inventory" option.  If the 
"cheat" was turned off, everything worked fine, but that kind of speed is
unacceptable.  Since borg_think() handles parsing the inventory, it was the
obvious function to patch in from 2.7.7v4.

I now take the time to fully acknowledge the great works of Ben and Frits.
There would be no borg without Ben, and I still can't comprehend all the stuff
about mapping out the dungeon, goals, building 'rooms', etc.  Frits did a
GREAT job with the spellcasting, which was a very large undertaking.  Asside
from several bugs, problems with forgotten spells, and a few other things, the
main part of his code didn't need any alteration and is a good foundation for
future spell programming.

Thanks also go to Matt Craighead for many improvements and suggestions, plus
playtesting on a computer much faster than mine.

For those unfamiliar with the borg, here are a few commands and some initial
strategy.  To initialize him, hit ^w for wizard mode, then ^a for the wizard
command prompt, then $ to initialize him.  From then on out, ^z gives you a
borg command prompt.  The r command restarts him from where he was stopped,
and the z command resets his current goal and restarts him.  Hitting ^w is the
best way to stop the borg.  For other commands, look in the code.  It is best
to roll up a borg with high dex and con, and wis/int 18 for spell casters.
Choose races with the most hit dice for the class you want to play.  A half-
troll priest is really good.  Beginning non-warrior borgs often suffer infant
death.  Either walk them trough it for the first few player levels, or be
prepared to save and reload a bunch.  Once he gets a few levels though, he
does fairly well.

Changes over borg-ben.c, non-casting related:

Modified Frits' item_power, which was in turn modifed from my older version,
   replacing Ben's new one altogether.  Frits added in # blows, weight
   considerations for weapons, hafted penalty for priests, and a few other
   things.
Since # blows was giving me some infinite loop problems, BLOWS must be
   defined to compile in support for factoring it in.  I've defined it since I
   think I've taken care of the problems, so undefine it if he gets into
   trouble and tell me what happened so I can fix it.
Subtracts out the pval of current weapon from # blows if current weapon is
   EGO_ATTACKS and weapon analyzed is in the inventory.  This was royaly
   messing things up before.
Turned off # blows factoring for item in inventory if current weapon wielded
   is artifact, Westerness, or Holy Avenger.  DEX or STR bonuses will
   sometimes lead to nasty wielding loops.
Values Calris, Thorin, and Celeborn very highly.
Values gloves of agility, slaying, power better.     
Values rings of accuracy, damage, slaying higher than all else but speed.
Values res life levels over all others (non forced_potions) if needed.
Values fix stat potions over all others except res life levels if needed. 
Devalues amulets of chr and stealth since they suck.
Devalues rings of speed <= +2 since slay/dam/hit are better at that point.
Fixed problem of wearing 0 value stuff if slot was empty. 
Won't wear weapon if he thinks it is to heavy.  If really good, save it at
   home for later.
Doesn't count # serious wounds potions as important for leaving level.
Recognizes when he enters a room, activates the current lite artifact, or
   casts a light spell if artifact not recharged yet.  Due to artifact
   recharging, borgs which can't cast light won't always light up a room.  If
   a light spell fails then the room won't be lit either.  Rooms are defined
   as >=6 non_walls surrounding him.  >=5 will cover almost all the rooms, but also
   gets lots of hallways :(  >=6 is a decent compromise.  He will light up
   again once he has reset the room_was_lit flag by passing through a hallway
   (non_walls == 2).
WoR in town based on certain conditions (see code).
Doesn't panic and go back to town if exp drained but player level not drained.
Took out conditions in borg_leave_level_aux() dealing with boredom, except for
   critical wounds.  They kept him from diving by limiting him too much.
   Since he needs 10 critical wounds to WoR down, this condition is still
   needed, otherwise he dives down through levels in the 30's, using up
   critical wounds, and is almost never able to buy enough at once to WoR down, 
   making for a slow diving borg.  This is good if he is having trouble, but
   bad if he is powerful, since it takes lots of time.
Doesn't read WoR unless > depth 5, not 4, so critical wound potion
   accumulation won't waste WoR scrolls.
Will dive down to level 5 even if level drained.  It took a LONG time to build
   up enough money for a res life level potion just going to level 1.
Tries to take item stat bonuses into account when deciding whether or not to
   buy stat potions.
Awareness and use of right hand ring correctly.   
Buys rings/amulets.
Buys and quaffs star-healing, life, and star-enlightenment potions. 
Stocks up on speed potions and uses them if hp < 3/4.       
Stocks up on healing potions and uses them if hp < 1/3 and old one worn off. 
Buys fewer critical wounds if enough healing potions.
Factors in # healing potions when escaping.
Tries to cope with "Almost dead" 'intelligently'.  You may want to comment
   this out but it works pretty well :).
Ranged attack handling is MUCH better.  Before he would only have a 1 in 5
   chance of firing anything, and wouldn't cast a spell if he was out of ammo.
   Now he will always fire if there is not a monster next to him, and has a 1
   in 5 chance of firing even then.  It also targets the 'highest' monster
   rather than the farthest away.
Won't go below a certain depth based on his max hp.  maxhp * 3 / 40.
Goes back to town if his level was drained while he was on the current level
   even if he has restored it, since he ran into some big trouble and should
   rest himself in town.
Changed # monsters which disturb him in borg_caution() from > 1 to > 2.
Doesn't identify crap (broken daggers, filthy rags, etc.).
Identifies {terrible}.
Identifies {uncursed}.
Handles Calris correctly.
Realizes when he is junking a {cursed} artifact and id's it instead.
Cursed aftifacts saved in home.
Identifies equipment. 
Will junk ammo if he hasn't got anything else to junk.
Won't junk artifacts, {terrible}, {excellent}, {special}, cost >= 100000 
WoR once very desperate junking starts and can't identify.
Only counts sellable items as items which are actually going to be sold, not
   just non-junk.  The # of sellable items of required worth to leave level
   back to town now factors in amount of slots available for sellable items.  
   # books, scrolls of teleport, etc. factored in.
Changed "sufficient" gold from 2 * price to just price of item.
Changed borg.c to not care about (Multiple Players!) and added some handling 
   for hallucination (kinda sucks though).  You may want to comment out the
   code in borg_think_dungeon() dealing with "seeing himself" since it may
   or may not guard against crashes and may lead to him dying easier when
   hallucinating.
Turned off interception of beep signals when a wrong key is input.  This was
   causing some of my hacks to stop the borg by making it beep.



Casting related changes over Frits' Parsival borg:

If non-warrior, won't use certain armors unless ego or artifact to save weight.
Doesn't care as much about food if he can cast food.
Casts food before eating it.  With high speed and enchanting > +10 he can
   go through rations pretty quickly.
If magic user then wear only gloves of Free Action, Agility, or artifact
   gloves with one of these qualities (cost > 30000).
Decent penalty for non-hafted non-blessed and HA weapons if priest.
Won't devalue identify scrolls if able to cast identify.  
Tries to cast stone to mud when tunneling.
Notices when player level has changed and learns spells, checks for forgotten
   ones, etc.  This also initializes the casting stuff upon reloading a game.
Recognizes and correctly handles forgotten and illegible spells.
Checks for forgotten spells and learns new one when spell stat changes.  
Browses book when he changes depth, lets him know when he has picked up a book
   which was missing and enable the spells.
Will learn new spells if leaving town and "Study" is at bottom of screen.   
Recharges mana by resting.
Only 2 of each lower book are kept, 1 of each higher.  Higher level books now
   correctly stored in home.
If depth >= 20 and bored and missing a lower book, go back to town.
Won't WoR down if isn't maxed out on lower books. 
Casts untried spells to gain experience.
Won't enchant unidentified items.
Casts enchant spells if needed, enchants inventory when in town, enchants
   if +10 up to +15 around every 100 turns if mana is green.
Tries to cast identify before rods/staves/scrolls instead of after.
Tries to cast teleport if < 1/3 hp after trying scrolls, not before.
Tries to cast teleport/portal if < 1/2 hp.
Tries to cast priest healing spell if < 1/2 hp or down by 300.
Always casts aggressive spell over missile weapon if possible instead of just
   a 1 in 10 chance.  Rangers get to blow the shit out of monsters!
Won't cast Annihilation at all now, not worth it.
Added in borg_keypress(ESCAPE) after gaining first spell/prayer.  Many
   problems arose if this wasn't there, like aiming wands or hanging when
   asked for which spell to gain next.
Cleaned up (somewhat) Frits' code for buying and selling books.
No longer uses maxknownspells AT ALL.  It would sometimes make massively
   incorrect guesses as to the correct value, causing the borg to keep trying 
   to gain new spells when he couldn't, making an infinite loop if spells had
   been forgotten.  Replaced by checking for Study at bottom of screen.
Moved all spell casting out of borg_think_dungeon(), where it was causing
   some minor problems, and put it in borg_use_other().



Changes made to my stuff by Matt Craighead (may have missed a few):

Changed buy stat potion logic to accomodate maximize mode.
Buys enchant scrolls to enchant to +10 if gold > 1000000.
Stocks up on and uses potions of restore mana, *healing*, and life.
Support for using mushrooms of restoring and restore constitution.
Won't go past depth 40 if doesn't have resist disenchantment.
Saves game after each staircase use and WoR.
Improved item_power() some.  I'm still thinking what's the best way to value
   some of the stuff :)
Avoided an infinite loop problem I had never seen with buying/selling forced
   potions/scrolls.
Will use scrolls of satisfy hunger.
Won't quaff enlightment more than once per level.
Won't use/cast certains stuff in town.



Obvious areas in need of improvement:

Casting strategy needs to be improved, which ones to cast when.
Item_power can always be improved.
Add in more 'preventitive spells' which he will recast once the time has
   expired for the effect, like speed, berzerk strength, heroism, etc.

Why does he sometimes stay on a level FOREVER until flags are reset, like
   by saving and reloading?  Often this won't even stop it.  It usually
   happens on levels which are heavily earthquaked.  Could it be that he
   hasn't explored evey little square in the rubble and is incorrectly
   plotting a course to get to it, since I'm sure that that much debris could
   screw up a course plotting algorithm?
Why does he sometimes stop lighting rooms for the rest of the game until
   a reload?  I think I fixed the problem, but it may reappear...
When level or spell stat is drained very quickly, sometimes he will press 'a'
   when he shouldn't.  Blindness/confusion can also do this.  Hopefully I've
   fixed all these problems, but if you find one let me know.  He will beep
   infinitely and prompt for which wand to aim.  It was caused mainly before
   by him trying to browse books while blind/confused to check for forgotten
   spells.  There's a similar problem with 'r' which I think was in a faulty
   bit of code I wrote to handle almost dead which I believe I have fixed.
My paranoia handling really sucks.  I tried everything I could to keep the
   darn thing from crashing the program.  If the borg sits there for a little
   while, give him about a minute before restarting him.
Clean up the code.

I need all the suggestions I can get, since it's getting harder to think of
ways to improve him.  Please contact me with any problems or suggestions you
may have at:

ewelsh@grove.ufl.edu



-Eric
