[comp.sources.d] NetHack 2.2: objects[] bug

cl@dlhpedg.co.uk (Charles Lambert) (12/16/87)

I have built NetHack 2.2 for HP-UX (Hewlett Packard UNIX-like).  To keep
the game simple, I didn't switch on all the optional stuff: specifically,
I left SAC undefined so there are no soldiers.  When I tried to run the game,
it printed the message

	init-prob error for * (80%)

To cut a long story short:  leaving soldiers out means that there are fewer
objects (to wit, no dead soldier) in objects[] (see objects.h).  As a result,
the defined constant indeces for objects[] were wrong;  the code that sets
initial probabilities for valuable gems was overwriting the probabilities
for "worthless piece[s] of coloured glass";  and the sum of probabilities
for all gems was coming out wrong.

I still haven't worked out the most elegant fix.  I think the whole design
of the objects database and access to it ought to be rehashed, to allow
for dynamic sizing, but that's a big job.

As a quick-fix,  I'll probably replace the defined indeces with variables
calculated early in the initialisation.

--------------------
Charlie

cl@dlhpedg.co.uk (Charles Lambert) (12/16/87)

In article <337@dlhpedg.co.uk> cl@datlog.co.uk (Charles Lambert) writes:
>
>As a quick-fix,  I'll probably replace the defined indeces with variables
>calculated early in the initialisation.
>

Silly me!  The obvious quick-fix is to remove the offending compiler switch
from objects.h;  then I'm left with the right offsets and a redundant entry.

--------------
Charlie

creps@silver.bacs.indiana.edu (Steve Creps) (12/18/87)

In article <337@dlhpedg.co.uk> cl@datlog.co.uk (Charles Lambert) writes:
>I have built NetHack 2.2 for HP-UX (Hewlett Packard UNIX-like).  To keep
>the game simple, I didn't switch on all the optional stuff: specifically,
>I left SAC undefined so there are no soldiers.  When I tried to run the game,
>it printed the message
>
>	init-prob error for * (80%)
>
>To cut a long story short:  leaving soldiers out means that there are fewer
>objects (to wit, no dead soldier) in objects[] (see objects.h).  As a result,
>the defined constant indeces for objects[] were wrong;  the code that sets
>initial probabilities for valuable gems was overwriting the probabilities
>for "worthless piece[s] of coloured glass";  and the sum of probabilities
>for all gems was coming out wrong.

   It's your own fault for #undef'ing my code! :-)

   Actually, I'm the person who wrote the stuff inside the "#ifdef SAC"'s,
and I see that I made a slight mistake. Instead of just putting the dead
soldier declaration in objects.h, I should have also put something into
makedefs.c. That's my conclusion after a quick look at the source.

>I still haven't worked out the most elegant fix.  I think the whole design
>of the objects database and access to it ought to be rehashed, to allow
>for dynamic sizing, but that's a big job.

   I will come up with a fix this weekend, and will send it to mike for the
2.3 patch release. My suggestion is to define SAC; it's really pretty neat
stuff (or will be when 2.3 is released) if I do say so myself. If you refuse
to do that, you can always remove the #ifdef SAC and #endif around the
declaration of dead soldiers. It won't actually add them as a type of
object; it will just allocate the space in the array to satisfy the rest
of the code.

>As a quick-fix,  I'll probably replace the defined indeces with variables
>calculated early in the initialisation.

   I think commenting out the #ifdef #endif pair in objects.h (mentioned above)
so that the array is properly aligned is a better quick fix. Unless you are
going to define SAC (hint hint).

-	-	-	-	-	-	-	-	-
Steve Creps on the VAX 8650 running Ultrix 2.0-1 at Indiana University.
	creps@silver.bacs.indiana.edu
"F-14 Tomcat! There IS no substitute."

creps@silver.bacs.indiana.edu (Steve Creps) (12/20/87)

In article <338@dlhpedg.co.uk> cl@.co.uk (Charles Lambert) writes:
>Silly me!  The obvious quick-fix is to remove the offending compiler switch
>from objects.h;  then I'm left with the right offsets and a redundant entry.

   Yeah, that's what I came up with after examining the code, and the fix
in the new code I'm sending to mike@genat for 2.3 does this.
   So, what everyone should do in the meantime is to remove all the #ifdef SAC
and corresponding #endif lines from objects.h if you aren't #defining SAC
in config.h. If you #define SAC, the error won't make a bit of difference.

-	-	-	-	-	-	-	-	-
Steve Creps on the VAX 8650 running Ultrix 2.0-1 at Indiana University.
	creps@silver.bacs.indiana.edu
"F-14 Tomcat! There IS no substitute."

allbery@ncoast.UUCP (Brandon Allbery) (12/24/87)

As quoted from <543@silver.bacs.indiana.edu> by creps@silver.bacs.indiana.edu (Steve Creps):
+---------------
|    I will come up with a fix this weekend, and will send it to mike for the
| 2.3 patch release. My suggestion is to define SAC; it's really pretty neat
+---------------

If these patches come out as "ed" scripts, there's gonna be a war...!
-- 
	      Brandon S. Allbery, Moderator of comp.sources.misc
 {hoptoad,harvard!necntc,cbosgd,sun!mandrill!hal,uunet!hnsurg3}!ncoast!allbery
     [This space reserved for future quotes and similar brain twisters.]