Skip to content

Commit

Permalink
Fixed spells/specials picked up in possession from neutral land (#1544)
Browse files Browse the repository at this point in the history
- Now the possession behavior for spells and specials as it is outside of possession (really this time).
- Rewrote check_place_to_pickup_spell
- Fixes #1543

Co-authored-by: AdamPlenty <[email protected]>
  • Loading branch information
Loobinex and AdamPlenty committed Jun 16, 2022
1 parent 2d9e7d5 commit 436f22a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
43 changes: 40 additions & 3 deletions src/spdigger_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ extern "C" {
DLLIMPORT long _DK_check_out_unreinforced_place(struct Thing *creatng);
DLLIMPORT long _DK_check_out_unreinforced_area(struct Thing *creatng);
DLLIMPORT struct Thing *_DK_check_place_to_pickup_gold(struct Thing *creatng, long stl_x, long stl_y);
DLLIMPORT struct Thing *_DK_check_place_to_pickup_spell(struct Thing *creatng, long slb_x, long slb_y);
DLLIMPORT struct Thing *_DK_check_place_to_pickup_unconscious_body(struct Thing *creatng, long slb_x, long slb_y);
DLLIMPORT long _DK_imp_will_soon_be_converting_at_excluding(struct Thing *creatng, long slb_x, long slb_y);
DLLIMPORT long _DK_imp_already_reinforcing_at_excluding(struct Thing *creatng, long stl_x, long stl_y);
Expand Down Expand Up @@ -2187,9 +2186,47 @@ struct Thing* check_place_to_pickup_gold(struct Thing* thing, MapSubtlCoord stl_
return INVALID_THING;
}

struct Thing *check_place_to_pickup_spell(struct Thing *thing, long a2, long a3)
TbBool creature_can_pickup_library_object_at_subtile(struct Thing* spdigtng, MapSubtlCoord stl_x, MapSubtlCoord stl_y)
{
return _DK_check_place_to_pickup_spell(thing, a2, a3);
struct SlabMap* slb = get_slabmap_for_subtile(stl_x, stl_y);
if (slabmap_owner(slb) != spdigtng->owner)
{
return false;
}
return true;
}

struct Thing *check_place_to_pickup_spell(struct Thing *spdigtng, MapSubtlCoord stl_x, MapSubtlCoord stl_y)
{
struct Thing *rettng;
if (!creature_can_pickup_library_object_at_subtile(spdigtng, stl_x, stl_y))
{
return INVALID_THING;
}
struct Map* mapblk = get_map_block_at(stl_x, stl_y);
rettng = thing_get(get_mapwho_thing_index(mapblk));
if (thing_is_invalid(rettng))
{
return INVALID_THING;
}
unsigned long k = 0;
while (!thing_can_be_picked_to_place_in_player_room(rettng, spdigtng->owner, RoK_LIBRARY, TngFRPickF_Default))
{
rettng = thing_get(rettng->next_on_mapblk);
if (thing_is_invalid(rettng))
{
return INVALID_THING;
}

k++;
if (k > THINGS_COUNT)
{
ERRORLOG("Infinite loop detected when sweeping things list");
break_mapwho_infinite_chain(mapblk);
break;
}
}
return rettng;
}

struct Thing *check_place_to_pickup_unconscious_body(struct Thing *thing, long a2, long a3)
Expand Down
1 change: 1 addition & 0 deletions src/spdigger_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ long imp_already_reinforcing_at_excluding(struct Thing *creatng, MapSubtlCoord s

TbBool thing_can_be_picked_to_place_in_player_room(const struct Thing* thing, PlayerNumber plyr_idx, RoomKind rkind, unsigned short flags);
long get_random_mining_undug_area_position_for_digger_drop(PlayerNumber plyr_idx, MapSubtlCoord *retstl_x, MapSubtlCoord *retstl_y);
TbBool creature_can_pickup_library_object_at_subtile(struct Thing* spdigtng, MapSubtlCoord stl_x, MapSubtlCoord stl_y);

TbBool imp_stack_update(struct Thing *creatng);
TbBool check_out_imp_stack(struct Thing *creatng);
Expand Down
4 changes: 4 additions & 0 deletions src/thing_creature.c
Original file line number Diff line number Diff line change
Expand Up @@ -5994,6 +5994,10 @@ TbBool thing_is_pickable_by_digger(struct Thing *picktng, struct Thing *creatng)
}
else if (thing_can_be_picked_to_place_in_player_room(picktng, creatng->owner, RoK_LIBRARY, TngFRPickF_Default))
{
if(!creature_can_pickup_library_object_at_subtile(creatng, picktng->mappos.x.stl.num, picktng->mappos.y.stl.num))
{
return false;
}
return (get_room_slabs_count(creatng->owner, RoK_LIBRARY) > 0);
}
else if (thing_can_be_picked_to_place_in_player_room(picktng, creatng->owner, RoK_WORKSHOP, TngFRPickF_Default))
Expand Down

0 comments on commit 436f22a

Please sign in to comment.