Help me make my new variant! (please!)

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • Pete Mack
    replied
    But if there is an array of curses for each object, surely they all share the same obj pointer?

    Leave a comment:


  • Nick
    replied
    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:


  • Pete Mack
    replied
    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:


  • Pete Mack
    replied
    Why do you add obj->weight to itself?

    Leave a comment:


  • will_asher
    replied
    Originally posted by Nick
    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;
    }

    Leave a comment:


  • Pete Mack
    replied
    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:


  • will_asher
    replied
    Okay, I see.
    Now, I'm wondering why the stealth code uses this weird formula...

    Leave a comment:


  • backwardsEric
    replied
    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.

    Leave a comment:


  • Nick
    replied
    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

    Leave a comment:


  • will_asher
    replied
    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...

    Leave a comment:


  • Pete Mack
    replied
    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:


  • Nick
    replied
    Originally posted by will_asher
    In this line:
    int player_noise = 1 << (30 - stealth);
    what does the "<<" mean?
    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.

    Leave a comment:


  • will_asher
    replied
    In this line:
    int player_noise = 1 << (30 - stealth);
    what does the "<<" mean?

    Leave a comment:


  • Nick
    replied
    Originally posted by will_asher
    Thanks, but I can't tell how I would add object weight in calc_bonuses(). I guess I would I need to add a weight field in the player_state struct?
    You're correct, putting it in calc_bonuses() was bad advice

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

    Leave a comment:


  • will_asher
    replied
    Originally posted by Nick
    So in addition to your change in obj-init.c, you need to handle weight in that combat bonuses section.

    Heaviness curse is a nice idea, BTW, I will probably steal it back from you
    Thanks, but I can't tell how I would add object weight in calc_bonuses(). I guess I would I need to add a weight field in the player_state struct?

    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:

Working...
😀
😂
🥰
😘
🤢
😎
😞
😡
👍
👎