return the value of context.ident and then increment it to be ready for its next use; used to be simple += 1 so that every value from 1 to N got used but now has a random increase that skips half of potential values */
| 506 | its next use; used to be simple += 1 so that every value from 1 to N got |
| 507 | used but now has a random increase that skips half of potential values */ |
| 508 | unsigned |
| 509 | next_ident(void) |
| 510 | { |
| 511 | unsigned res = svc.context.ident; |
| 512 | |
| 513 | /* +rnd(2): originally just +1; changed to rnd() to avoid potential |
| 514 | exploit of player using #adjust to split an object stack in a manner |
| 515 | that makes most recent ident%2 known; since #adjust takes no time, |
| 516 | no intervening activity like random creation of a new monster will |
| 517 | take place before next user command; with former +1, o_id%2 of the |
| 518 | next object to be created was knowable and player could make a wish |
| 519 | under controlled circumstances for an item that is affected by the |
| 520 | low bits of its obj->o_id [particularly helm of opposite alignment] */ |
| 521 | svc.context.ident += rnd(2); /* ready for next new object or monster */ |
| 522 | |
| 523 | /* if ident has wrapped to 0, force it to be non-zero; if/when it |
| 524 | ever wraps past 0 (unlikely, but possible on a configuration which |
| 525 | uses 16-bit 'int'), just live with that and hope no o_id conflicts |
| 526 | between objects or m_id conflicts between monsters arise */ |
| 527 | if (!svc.context.ident) |
| 528 | svc.context.ident = rnd(2) + 1; /* id 1 is reserved */ |
| 529 | |
| 530 | return res; |
| 531 | } |
| 532 | |
| 533 | /* when splitting a stack that has o_id-based shop prices, pick an |
| 534 | o_id value for the new stack that will maintain the same price */ |
no test coverage detected