Merge pull request #1926 from myk002/myk_projectile_vomit

Handle projectiles in Items module functions
develop
Alan 2021-08-20 00:21:20 -04:00 committed by GitHub
commit 3ae4dbeb21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 5 deletions

@ -47,6 +47,9 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
- `tiletypes-here`, `tiletypes-here-point`: add --cursor and --quiet options to support non-interactive use cases
- `quickfort`: Dreamfort blueprint set improvements: extensive revision based on playtesting and feedback. includes updated ``onMapLoad.init`` settings file and enhanced automation orders. see full changelog at https://github.com/DFHack/dfhack/pull/1921
## API
- The ``Items`` module ``moveTo*`` and ``remove`` functions now handle projectiles
## Documentation
- `quickfort-library-guide`: updated dreamfort documentation and added screenshots

@ -310,6 +310,27 @@ Link *linked_list_insert_after(Link *pos, Link *link)
return link;
}
/**
* Returns true if the item with id idToRemove was found, deleted, and removed
* from the list. Otherwise returns false.
*/
template<typename Link>
bool linked_list_remove(Link *head, int32_t idToRemove)
{
for (Link *link = head; link; link = link->next)
{
if (!link->item || link->item->id != idToRemove)
continue;
link->prev->next = link->next;
if (link->next)
link->next->prev = link->prev;
delete(link);
return true;
}
return false;
}
template<typename T>
inline typename T::mapped_type map_find(
const T &map, const typename T::key_type &key,

@ -819,7 +819,6 @@ static bool detachItem(MapExtras::MapCache &mc, df::item *item)
switch (ref->getType())
{
case general_ref_type::PROJECTILE:
case general_ref_type::BUILDING_HOLDER:
case general_ref_type::BUILDING_CAGED:
case general_ref_type::BUILDING_TRIGGER:
@ -832,6 +831,15 @@ static bool detachItem(MapExtras::MapCache &mc, df::item *item)
}
}
if (auto *ref =
virtual_cast<df::general_ref_projectile>(
Items::getGeneralRef(item, general_ref_type::PROJECTILE)))
{
return linked_list_remove(&world->proj_list, ref->projectile_id) &&
DFHack::removeRef(item->general_refs,
general_ref_type::PROJECTILE, ref->getID());
}
if (item->flags.bits.on_ground)
{
if (!mc.removeItemOnGround(item))
@ -841,7 +849,8 @@ static bool detachItem(MapExtras::MapCache &mc, df::item *item)
item->flags.bits.on_ground = false;
return true;
}
else if (item->flags.bits.in_inventory)
if (item->flags.bits.in_inventory)
{
bool found = false;
@ -906,7 +915,8 @@ static bool detachItem(MapExtras::MapCache &mc, df::item *item)
item->flags.bits.in_inventory = false;
return true;
}
else if (item->flags.bits.removed)
if (item->flags.bits.removed)
{
item->flags.bits.removed = false;
@ -918,8 +928,8 @@ static bool detachItem(MapExtras::MapCache &mc, df::item *item)
return true;
}
else
return false;
return false;
}
static void putOnGround(MapExtras::MapCache &mc, df::item *item, df::coord pos)