Angband Forums Help me make my new variant! (please!)
 Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 August 27, 2021, 04:28 #161 Pete Mack Prophet   Join Date: Apr 2007 Location: Seattle, WA Posts: 6,595 Donated: \$40 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.
August 27, 2021, 05:23   #162
will_asher
DaJAngband Maintainer

Join Date: Apr 2007
Location: San Antonio, TX
Posts: 1,124
Donated: \$10
Quote:
 Originally Posted by Nick 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

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...)

August 27, 2021, 05:38   #163
Nick
Vanilla maintainer

Join Date: Apr 2007
Location: Canberra, Australia
Age: 56
Posts: 9,172
Donated: \$60
Quote:
 Originally Posted by will_asher 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.

August 27, 2021, 05:46   #164
backwardsEric

Join Date: Aug 2019
Posts: 219
Quote:
 Originally Posted by will_asher 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.

 August 27, 2021, 09:26 #165 will_asher DaJAngband Maintainer     Join Date: Apr 2007 Location: San Antonio, TX Posts: 1,124 Donated: \$10 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...)
 August 27, 2021, 10:06 #166 Pete Mack Prophet   Join Date: Apr 2007 Location: Seattle, WA Posts: 6,595 Donated: \$40 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.
August 29, 2021, 08:50   #167
will_asher
DaJAngband Maintainer

Join Date: Apr 2007
Location: San Antonio, TX
Posts: 1,124
Donated: \$10
Quote:
 Originally Posted by Nick It looks like this is actually a bit of work. The way I would do it is: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. 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

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...)

 August 29, 2021, 10:27 #168 Pete Mack Prophet   Join Date: Apr 2007 Location: Seattle, WA Posts: 6,595 Donated: \$40 Why do you add obj->weight to itself?
 August 29, 2021, 10:50 #169 Pete Mack Prophet   Join Date: Apr 2007 Location: Seattle, WA Posts: 6,595 Donated: \$40 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.
 August 29, 2021, 12:09 #170 Nick Vanilla maintainer     Join Date: Apr 2007 Location: Canberra, Australia Age: 56 Posts: 9,172 Donated: \$60 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.

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

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Angband     AAR     Vanilla     Development     ToME     Sil     Variants     Competition The real world     Idle chatter     Oook! Obsolete     v4

 Similar Threads Thread Thread Starter Forum Replies Last Post Sky Vanilla 16 September 10, 2017 11:20 bagori nd Sil 4 September 26, 2016 19:22 Delver Variants 12 June 5, 2009 10:08 dzhang Variants 34 April 1, 2009 01:45 bpleshek Variants 8 September 15, 2008 21:42

All times are GMT +1. The time now is 04:48.