Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Development

Reply
 
Thread Tools Display Modes
Old August 27, 2021, 04:28   #161
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 6,589
Donated: $40
Pete Mack is on a distinguished road
Note that STL 30 (legendary) gives perfect stealth where you can stroll past Huan without risk. I once walked between him and Tarrasque, at about 3 squares away for each.
Pete Mack is online now   Reply With Quote
Old August 27, 2021, 05:23   #162
will_asher
DaJAngband Maintainer
 
will_asher's Avatar
 
Join Date: Apr 2007
Location: San Antonio, TX
Posts: 1,123
Donated: $10
will_asher is on a distinguished road
Quote:
Originally Posted by Nick View Post
It's the left shift operator - it shifts all the bits to the left, which is effectively multiplying by a power of 2. So 1 << 1 is 2, 1 << 2 is 4, 1 << 3 is 8, etc.
Sorry, it's been a long time since I had any math(s) class. "by a power of 2" sounds to me like "squared" but 1 squared is still 1 so how does 1 << 1 = 2?, and I don't know what you mean by "shifting bits to the left" (unless it's multiplying by 10 which it obviously isn't). I still don't get it...
__________________
Will_Asher
aka LibraryAdventurer

My old variant DaJAngband:
http://sites.google.com/site/dajangbandwebsite/home (defunct and so old it's forked from Angband 3.1.0 -I think- but it's probably playable...)
will_asher is offline   Reply With Quote
Old August 27, 2021, 05:38   #163
Nick
Vanilla maintainer
 
Nick's Avatar
 
Join Date: Apr 2007
Location: Canberra, Australia
Age: 56
Posts: 9,167
Donated: $60
Nick will become famous soon enoughNick will become famous soon enough
Quote:
Originally Posted by will_asher View Post
Sorry, it's been a long time since I had any math(s) class. "by a power of 2" sounds to me like "squared" but 1 squared is still 1 so how does 1 << 1 = 2?, and I don't know what you mean by "shifting bits to the left" (unless it's multiplying by 10 which it obviously isn't). I still don't get it...
Power of 2 means 2 multiplied by itself a number of times. Computer arithmetic is base 2 or binary (bit = binary digit), so shifting to the left multiplies by 2 (in normal base 10, shifting to the left would indeed multiply by 10). I can go on about this stuff forever, but I won't
__________________
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 August 27, 2021, 05:46   #164
backwardsEric
Adept
 
Join Date: Aug 2019
Posts: 217
backwardsEric is on a distinguished road
Quote:
Originally Posted by will_asher View Post
Sorry, it's been a long time since I had any math(s) class. "by a power of 2" sounds to me like "squared" but 1 squared is still 1 so how does 1 << 1 = 2?, and I don't know what you mean by "shifting bits to the left" (unless it's multiplying by 10 which it obviously isn't). I still don't get it...
1 << n is equivalent to multiplying by 2, n times in a row. So, for n = 1, it multiplies by 2; for n = 2, it multiplies by 4.

An example with 8 bits (most significant (biggest) first):

00000101 = 1 * 2^2 + 1 * 2^0 = 4 + 1 = 5

Shifted by 1 bit to the left:

00001010 = 1 * 2^3 + 1 * 2^1 = 8 + 2 = 10 = 5 * 2

Shifted by 2 bits to the left:

00010100 = 1 * 2^4 + 1 * 2^2 = 16 + 4 = 20 = 5 * 4

This is analogous to multiplying by 10 when a number is written in decimal notation. However, for binary each digit represents a power of 2 rather than a power of 10, so shifting multiplies (or divides) by 2 rather than by 10.
backwardsEric is offline   Reply With Quote
Old August 27, 2021, 09:26   #165
will_asher
DaJAngband Maintainer
 
will_asher's Avatar
 
Join Date: Apr 2007
Location: San Antonio, TX
Posts: 1,123
Donated: $10
will_asher is on a distinguished road
Okay, I see.
Now, I'm wondering why the stealth code uses this weird formula...
__________________
Will_Asher
aka LibraryAdventurer

My old variant DaJAngband:
http://sites.google.com/site/dajangbandwebsite/home (defunct and so old it's forked from Angband 3.1.0 -I think- but it's probably playable...)
will_asher is offline   Reply With Quote
Old August 27, 2021, 10:06   #166
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 6,589
Donated: $40
Pete Mack is on a distinguished road
Stealth is exponential--an increase of +3 cuts the chance of waking (per game turn) by a factor of two. At stealth 30, the chance of detection is cut by 1/1000 (compares to a H-T warrior). Monsters can still wake up, but it is highly unlikely in the time it takes to cross a room, especially at speed +10 or higher.
Pete Mack is online now   Reply With Quote
Old August 29, 2021, 08:50   #167
will_asher
DaJAngband Maintainer
 
will_asher's Avatar
 
Join Date: Apr 2007
Location: San Antonio, TX
Posts: 1,123
Donated: $10
will_asher is on a distinguished road
Quote:
Originally Posted by Nick View Post
It looks like this is actually a bit of work. The way I would do it is:
  1. Add a function (probably in obj-util.c) called something like object_weight(). This should take a struct object * argument, and should take the object's actual weight and then run through all the curses on the object add weight whenever a curse has weight, and return the total.
  2. Then search though for all uses of object weight in calculations or display, and replace obj->weight with object_weight(obj).
Alternatively, you could file it as an issue for Vanilla and hope someone else does it...
Done.
Now vanilla can copy me.
Code:
/* Modifiers to object weight */
int object_weight(const struct object* obj)
{
	int weight = obj->weight;
	int index = 0;

	/* Check for curses */
	struct curse_data* curse = obj ? obj->curses : NULL;

	/* (copied from calc_bonuses()) */
	while (obj) {
		/* Curses may affect weight (index zero is original object) */
		if ((obj->weight) && (index)) weight += obj->weight;

		/* next curse if any */
		if (curse) {
			index++;
			obj = NULL;
			while (index < z_info->curse_max) {
				if (curse[index].power) {
					obj = curses[index].obj;
					break;
				}
				else {
					index++;
				}
			}
		}
		else {
			obj = NULL;
		}
	}

	return weight;
}
__________________
Will_Asher
aka LibraryAdventurer

My old variant DaJAngband:
http://sites.google.com/site/dajangbandwebsite/home (defunct and so old it's forked from Angband 3.1.0 -I think- but it's probably playable...)
will_asher is offline   Reply With Quote
Old August 29, 2021, 10:27   #168
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 6,589
Donated: $40
Pete Mack is on a distinguished road
Why do you add obj->weight to itself?
Pete Mack is online now   Reply With Quote
Old August 29, 2021, 10:50   #169
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 6,589
Donated: $40
Pete Mack is on a distinguished road
Here's the usual idiom.
Check preconditions. If not met, return early
Think what your iterator is. If it is over an array, usually use a for loop. Figure your termination condition.

You will see this idiom all through the code base. It s standard for a reason. (In this case it's a relational aggregator.)

Code:
/* Modifiers to object weight */
int object_weight(const struct object* obj)
{
    int weight = obj->weight;   
    const struct curse* curses = obj-> curses;
    if (!curses) return weight;
    for (int i=0; i < z_info->curse_max && curses[i].power; i++) {
        if ( [[[ curses[i] type is cumbersome ]]])
             weight += [[[ cumbersome curse  constant ]]];
    }
    return weight;
}

Last edited by Pete Mack; August 29, 2021 at 10:59.
Pete Mack is online now   Reply With Quote
Old August 29, 2021, 12:09   #170
Nick
Vanilla maintainer
 
Nick's Avatar
 
Join Date: Apr 2007
Location: Canberra, Australia
Age: 56
Posts: 9,167
Donated: $60
Nick will become famous soon enoughNick will become famous soon enough
Pete, I think you're missing that there is a struct object associated with each curse for easy storage of object properties, so the loop need to run across all the curse objects and add their weight.

So I think the original code is correct.
__________________
One for the Dark Lord on his dark throne
In the Land of Mordor where the Shadows lie.
Nick 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
can we make identify more common ? Sky Vanilla 16 September 10, 2017 11:20
Make Artistry automatic bagori nd Sil 4 September 26, 2016 19:22
How many variant developers/maintainers have beaten their own variant? Delver Variants 12 June 5, 2009 10:08
Variant writing.. quickstart guide? Also, Hengband variant suggestions? dzhang Variants 34 April 1, 2009 01:45
Trying to make my own variant bpleshek Variants 8 September 15, 2008 21:42


All times are GMT +1. The time now is 19:58.


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