Skip to content

Commit

Permalink
Add a player argument to floor_object_for_use(). Resolves angband/ang…
Browse files Browse the repository at this point in the history
  • Loading branch information
backwardsEric authored and NickMcConnell committed Aug 21, 2021
1 parent d94a8a7 commit 8d9b162
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 29 deletions.
6 changes: 4 additions & 2 deletions src/cmd-obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,8 @@ static void use_aux(struct command *cmd, struct object *obj, enum use use,
false, &none_left);
from_floor = false;
} else {
work_obj = floor_object_for_use(obj, 1, false, &none_left);
work_obj = floor_object_for_use(player, obj, 1,
false, &none_left);
from_floor = true;
}
/* Record number for messages after use */
Expand Down Expand Up @@ -884,7 +885,8 @@ static void refill_lamp(struct object *lamp, struct object *obj)
used = gear_object_for_use(player, obj, 1, true,
&none_left);
} else {
used = floor_object_for_use(obj, 1, true, &none_left);
used = floor_object_for_use(player, obj, 1, true,
&none_left);
}
if (used->known)
object_delete(&used->known);
Expand Down
2 changes: 1 addition & 1 deletion src/cmd-pickup.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ static void player_pickup_aux(struct player *p, struct object *obj,
else
num = get_quantity(NULL, max);
if (!num) return;
picked_up = floor_object_for_use(obj, num, false, &dummy);
picked_up = floor_object_for_use(p, obj, num, false, &dummy);
inven_carry(p, picked_up, true, domsg);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/effect-handler-general.c
Original file line number Diff line number Diff line change
Expand Up @@ -2139,7 +2139,8 @@ bool effect_handler_RECHARGE(effect_handler_context_t *context)
destroyed = gear_object_for_use(player, obj, 1, true,
&none_left);
} else {
destroyed = floor_object_for_use(obj, 1, true, &none_left);
destroyed = floor_object_for_use(player, obj, 1, true,
&none_left);
}
if (destroyed->known)
object_delete(&destroyed->known);
Expand Down Expand Up @@ -3316,7 +3317,7 @@ bool effect_handler_CREATE_ARROWS(effect_handler_context_t *context)
if (object_is_carried(player, obj)) {
staff = gear_object_for_use(player, obj, 1, true, &none_left);
} else {
staff = floor_object_for_use(obj, 1, true, &none_left);
staff = floor_object_for_use(player, obj, 1, true, &none_left);
}

if (staff->known) {
Expand Down
2 changes: 1 addition & 1 deletion src/obj-gear.c
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ void inven_wield(struct object *obj, int slot)
}
} else {
/* Get a floor item and carry it */
wielded = floor_object_for_use(obj, 1, false, &dummy);
wielded = floor_object_for_use(player, obj, 1, false, &dummy);
inven_carry(player, wielded, false, false);
}

Expand Down
21 changes: 11 additions & 10 deletions src/obj-pile.c
Original file line number Diff line number Diff line change
Expand Up @@ -815,12 +815,13 @@ struct object *object_split(struct object *src, int amt)

/**
* Remove an amount of an object from the floor, returning a detached object
* which can be used - it is assumed that the object is on the player grid.
* which can be used - it is assumed that the object is being manipulated by
* given player and is on that player's grid.
*
* Optionally describe what remains.
*/
struct object *floor_object_for_use(struct object *obj, int num, bool message,
bool *none_left)
struct object *floor_object_for_use(struct player *p, struct object *obj,
int num, bool message, bool *none_left)
{
struct object *usable;
char name[80];
Expand All @@ -833,17 +834,17 @@ struct object *floor_object_for_use(struct object *obj, int num, bool message,
usable = object_split(obj, num);
} else {
usable = obj;
square_excise_object(player->cave, usable->grid, usable->known);
delist_object(player->cave, usable->known);
square_excise_object(p->cave, usable->grid, usable->known);
delist_object(p->cave, usable->known);
square_excise_object(cave, usable->grid, usable);
delist_object(cave, usable);
*none_left = true;

/* Stop tracking item */
if (tracked_object_is(player->upkeep, obj))
track_object(player->upkeep, NULL);
if (tracked_object_is(p->upkeep, obj))
track_object(p->upkeep, NULL);

/* Inventory has changed, so disable repeat command */
/* The pile is gone, so disable repeat command */
cmd_disable_repeat();
}

Expand All @@ -857,8 +858,8 @@ struct object *floor_object_for_use(struct object *obj, int num, bool message,
obj->number = 0;

/* Get a description */
object_desc(name, sizeof(name), obj, ODESC_PREFIX | ODESC_FULL,
player);
object_desc(name, sizeof(name), obj,
ODESC_PREFIX | ODESC_FULL, p);

if (usable == obj)
obj->number = num;
Expand Down
4 changes: 2 additions & 2 deletions src/obj-pile.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ void object_wipe(struct object *obj);
void object_copy(struct object *obj1, const struct object *obj2);
void object_copy_amt(struct object *dest, struct object *src, int amt);
struct object *object_split(struct object *src, int amt);
struct object *floor_object_for_use(struct object *obj, int num, bool message,
bool *none_left);
struct object *floor_object_for_use(struct player *p, struct object *obj,
int num, bool message, bool *none_left);
bool floor_carry(struct chunk *c, struct loc grid, struct object *drop,
bool *note);
void drop_near(struct chunk *c, struct object **dropped, int chance,
Expand Down
2 changes: 1 addition & 1 deletion src/player-attack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ static void ranged_helper(struct player *p, struct object *obj, int dir,
if (object_is_carried(p, obj)) {
missile = gear_object_for_use(p, obj, 1, true, &none_left);
} else {
missile = floor_object_for_use(obj, 1, true, &none_left);
missile = floor_object_for_use(p, obj, 1, true, &none_left);
}

/* Terminate piercing */
Expand Down
21 changes: 11 additions & 10 deletions src/tests/player/inven-wield.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,18 @@ static bool empty_gear(struct player *p) {
return true;
}

static bool empty_floor(struct chunk *c, struct loc grid) {
static bool empty_floor(struct chunk *c, struct player *p) {
while (1) {
struct object *obj = square_object(c, grid);
struct object *obj = square_object(c, p->grid);
bool none_left;

if (!obj) {
return true;
}

none_left = false;
obj = floor_object_for_use(obj, obj->number, false, &none_left);
obj = floor_object_for_use(p, obj, obj->number, false,
&none_left);
if (obj->known) {
object_free(obj->known);
}
Expand Down Expand Up @@ -353,7 +354,7 @@ static int test_inven_wield_floor_single_empty(void *state) {
int old_slots;

require(empty_gear(player));
require(empty_floor(cave, player->grid));
require(empty_floor(cave, player));
obj = setup_object(TV_BOOTS, 1, 1);
require(obj != NULL);
note = false;
Expand Down Expand Up @@ -382,7 +383,7 @@ static int test_inven_wield_floor_stack_empty(void *state) {
int old_slots;

require(empty_gear(player));
require(empty_floor(cave, player->grid));
require(empty_floor(cave, player));
obj = setup_object(TV_CROWN, 1, 4);
require(obj != NULL);
note = false;
Expand Down Expand Up @@ -415,7 +416,7 @@ static int test_inven_wield_floor_single_filled(void *state) {
int old_slots;

require(empty_gear(player));
require(empty_floor(cave, player->grid));
require(empty_floor(cave, player));
obj1 = setup_object(TV_AMULET, 1, 1);
require(obj1 != NULL);
gear_insert_end(player, obj1);
Expand Down Expand Up @@ -453,7 +454,7 @@ static int test_inven_wield_floor_stack_filled(void *state) {
int old_slots;

require(empty_gear(player));
require(empty_floor(cave, player->grid));
require(empty_floor(cave, player));
obj1 = setup_object(TV_DIGGING, 1, 1);
require(obj1 != NULL);
gear_insert_end(player, obj1);
Expand Down Expand Up @@ -495,7 +496,7 @@ static int test_inven_wield_pack_full_no_overflow(void *state) {
int old_slots;

require(empty_gear(player));
require(empty_floor(cave, player->grid));
require(empty_floor(cave, player));
obj1 = setup_object(TV_SOFT_ARMOR, 1, 1);
require(obj1 != NULL);
gear_insert_end(player, obj1);
Expand Down Expand Up @@ -535,7 +536,7 @@ static int test_inven_wield_pack_full_overflow(void *state) {
int old_slots;

require(empty_gear(player));
require(empty_floor(cave, player->grid));
require(empty_floor(cave, player));
obj1 = setup_object(TV_HELM, 1, 1);
require(obj1 != NULL);
gear_insert_end(player, obj1);
Expand Down Expand Up @@ -580,7 +581,7 @@ static int test_inven_wield_floor_full_overflow(void *state) {
int old_slots;

require(empty_gear(player));
require(empty_floor(cave, player->grid));
require(empty_floor(cave, player));
obj1 = setup_object(TV_BOW, 1, 1);
require(obj1 != NULL);
gear_insert_end(player, obj1);
Expand Down

0 comments on commit 8d9b162

Please sign in to comment.