Help me make my new variant! (please!)
Collapse
X
-
But if there is an array of curses for each object, surely they all share the same obj pointer? -
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.Leave a comment:
-
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, 09:59.Leave a comment:
-
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).
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; }
Leave a comment:
-
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.Leave a comment:
-
Okay, I see.
Now, I'm wondering why the stealth code uses this weird formula...Leave a comment:
-
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...
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.Leave a comment:
-
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...Leave a comment:
-
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...Leave a comment:
-
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.Leave a comment:
-
-
In this line:
int player_noise = 1 << (30 - stealth);
what does the "<<" mean?Leave a comment:
-
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).
Leave a comment:
-
EDIT: So the curses don't modify the object at all. They just modify the player while the object is being worm/wielded. That's going to make it hard to do a heaviness curse, especially for thrown weapons...
PS: here's the entry for curse.txt:
name:heaviness
combat:-4:4:0:100 (the 4th spot here is for weight, so it adds up to 10lbs)
values: DEX[-2]
type:hafted
type: polearm
type:sword
type:bow
type:throwing weapon
type:boots
type:shield
type:hard armor
type:dragon armor
desc:weighs you down
I also added a lightness ego.Last edited by will_asher; August 21, 2021, 04:52.Leave a comment:
Leave a comment: