Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Variants

Reply
 
Thread Tools Display Modes
Old August 29, 2008, 05:58   #1
will_asher
DaJAngband Maintainer
 
will_asher's Avatar
 
Join Date: Apr 2007
Location: San Antonio, TX
Posts: 927
Donated: $10
will_asher is on a distinguished road
Angband coding question

I'm back after being mostly AWOL for the last couple months, but I'm back and DaJAngband is not dead (but it'll still be pretty slow moving). On that note, I have a question for people who know the code.

In monster.txt, the third entry in the W: line is unused and always set at zero. I would like to use this spot for something, but in the code it seems to assign it to r_ptr->power and actually do something with it. Does it actually do anything? Would it have any unwanted effects if I assigned the unused spot to something besides r_ptr->power and used it for something?

In the meantime, I'm going to make yet another copy of everything as a backup and go ahead and try it.


PS After being gone for awhile, I thought the official vanilla 3.1.0 would be out when I came back. oh well.
__________________
Will_Asher

Play DaJAngband:
http://sites.google.com/site/dajangbandwebsite/home
will_asher is offline   Reply With Quote
Old August 29, 2008, 06:24   #2
andrewdoull
Unangband maintainer
 
andrewdoull's Avatar
 
Join Date: Apr 2007
Location: Sydney, Australia
Age: 44
Posts: 872
andrewdoull is on a distinguished road
Quote:
Originally Posted by will_asher View Post
I'm back after being mostly AWOL for the last couple months, but I'm back and DaJAngband is not dead (but it'll still be pretty slow moving). On that note, I have a question for people who know the code.

In monster.txt, the third entry in the W: line is unused and always set at zero. I would like to use this spot for something, but in the code it seems to assign it to r_ptr->power and actually do something with it. Does it actually do anything? Would it have any unwanted effects if I assigned the unused spot to something besides r_ptr->power and used it for something?
Its currently used in commented out code in init1.c. However, that is generated, and not read in from the file - so you could safely read that particular string into another value e.g. r_ptr->not_power instead.
__________________
The Roflwtfzomgbbq Quylthulg summons L33t Paladins -more-
In UnAngband, the level dives you.
ASCII Dreams: http://roguelikedeveloper.blogspot.com
Unangband: http://unangband.blogspot.com
andrewdoull is offline   Reply With Quote
Old August 30, 2008, 01:52   #3
will_asher
DaJAngband Maintainer
 
will_asher's Avatar
 
Join Date: Apr 2007
Location: San Antonio, TX
Posts: 927
Donated: $10
will_asher is on a distinguished road
thanks, that's what I needed to know
__________________
Will_Asher

Play DaJAngband:
http://sites.google.com/site/dajangbandwebsite/home
will_asher is offline   Reply With Quote
Old August 31, 2008, 06:51   #4
will_asher
DaJAngband Maintainer
 
will_asher's Avatar
 
Join Date: Apr 2007
Location: San Antonio, TX
Posts: 927
Donated: $10
will_asher is on a distinguished road
Another question:

I compiled and tested my latest change beginning to implement monster stealth. The game crashed so I tried playing the game on the debug mode in the compiler. When the game crashes, the compiler brings me to the following place in z-rand.c which I never touched. Could anyone help figure out what's wrong?

<code>
/* Hack -- extract a 28-bit "random" number */
r = ((r >> 4) & 0x0FFFFFFF) / n;
</code>


thanks ahead of time
__________________
Will_Asher

Play DaJAngband:
http://sites.google.com/site/dajangbandwebsite/home
will_asher is offline   Reply With Quote
Old August 31, 2008, 07:00   #5
Mangojuice
Z+Angband Maintainer
 
Join Date: Jun 2008
Posts: 318
Mangojuice is on a distinguished road
Quote:
Originally Posted by will_asher View Post
Another question:

I compiled and tested my latest change beginning to implement monster stealth. The game crashed so I tried playing the game on the debug mode in the compiler. When the game crashes, the compiler brings me to the following place in z-rand.c which I never touched. Could anyone help figure out what's wrong?

<code>
/* Hack -- extract a 28-bit "random" number */
r = ((r >> 4) & 0x0FFFFFFF) / n;
</code>


thanks ahead of time
I think I know! This is a division by 0 error, so n would have to be 0 for this to cause a crash. If I'm looking at the right function, n is set to be 0x10000000 / m where m is the input. But m is a u32b value! So if m is larger than 0x10000000, n ends up being 0 and you get a crash. So I bet you are calling for a random number with an extremely large range somewhere.

This is, in fact, a "bug" in the random number generator code, but it's one that's avoided by an unwritten coding practice you must have violated.
__________________
-----------------------------------------
Z+Angband: A Zangband evolution
http://tinyurl.com/5pq2bd
Mangojuice is offline   Reply With Quote
Old August 31, 2008, 07:49   #6
roustk
Adept
 
Join Date: Dec 2007
Posts: 167
roustk is on a distinguished road
Quote:
Originally Posted by Mangojuice View Post
This is, in fact, a "bug" in the random number generator code, but it's one that's avoided by an unwritten coding practice you must have violated.
It is a *documented* feature. The comments before the Rand_div() function include, at about line 117 (in 3.0.9b):
Code:
 * Note that "m" must not be greater than 0x1000000, or division
 * by zero will result.
It would probably behoove Will to check why his code is asking for a uniform draw from more than a quarter-billion values (28 bits)...
roustk is offline   Reply With Quote
Old August 31, 2008, 14:06   #7
Mangojuice
Z+Angband Maintainer
 
Join Date: Jun 2008
Posts: 318
Mangojuice is on a distinguished road
Quote:
Originally Posted by roustk View Post
It is a *documented* feature. The comments before the Rand_div() function include, at about line 117 (in 3.0.9b):
Ok, that's true. Of course, though, the code never calls Rand_div directly. The calls are all through calls to randint0 or rand_range, and their documentation doesn't mention this, or take steps to avoid the problem.
__________________
-----------------------------------------
Z+Angband: A Zangband evolution
http://tinyurl.com/5pq2bd
Mangojuice is offline   Reply With Quote
Old September 2, 2008, 06:27   #8
will_asher
DaJAngband Maintainer
 
will_asher's Avatar
 
Join Date: Apr 2007
Location: San Antonio, TX
Posts: 927
Donated: $10
will_asher is on a distinguished road
Quote:
Originally Posted by roustk View Post
It is a *documented* feature. The comments before the Rand_div() function include, at about line 117 (in 3.0.9b):
Code:
 * Note that "m" must not be greater than 0x1000000, or division
 * by zero will result.
It would probably behoove Will to check why his code is asking for a uniform draw from more than a quarter-billion values (28 bits)...
how would this happen? I certainly didn't put any randint(100000000) in there anywhere.
__________________
Will_Asher

Play DaJAngband:
http://sites.google.com/site/dajangbandwebsite/home
will_asher is offline   Reply With Quote
Old September 2, 2008, 06:35   #9
Nick
Vanilla maintainer
 
Nick's Avatar
 
Join Date: Apr 2007
Location: Canberra, Australia
Age: 54
Posts: 7,849
Donated: $60
Nick will become famous soon enough
Quote:
Originally Posted by will_asher View Post
how would this happen? I certainly didn't put any randint(100000000) in there anywhere.
You should be able to do a backtrace in your debugger to find where the to the RNG is coming from.
__________________
One for the Dark Lord on his dark throne
In the Land of Mordor where the Shadows lie.
Nick is offline   Reply With Quote
Old September 2, 2008, 07:06   #10
Mangojuice
Z+Angband Maintainer
 
Join Date: Jun 2008
Posts: 318
Mangojuice is on a distinguished road
Quote:
Originally Posted by will_asher View Post
how would this happen? I certainly didn't put any randint(100000000) in there anywhere.
My guess is that either you used an uninitialized variable, or somehow you called the RNG with a negative value that wrapped around.
__________________
-----------------------------------------
Z+Angband: A Zangband evolution
http://tinyurl.com/5pq2bd
Mangojuice is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Coding standard? Indentation? Bandobras Vanilla 10 May 24, 2008 20:46
Making DaJAngband: a couple non-coding related questions will_asher Variants 2 April 2, 2008 17:25
Question regarding weapons in Angband. Berserker Vanilla 6 March 11, 2008 16:40


All times are GMT +1. The time now is 13:55.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.