|
|
@ -60,7 +60,7 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
|
|
|
|
if (enable_teledwarf) do
|
|
|
|
if (enable_teledwarf) do
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// don't do anything if the dwarf isn't going anywhere
|
|
|
|
// don't do anything if the dwarf isn't going anywhere
|
|
|
|
if (unit->path.dest.x == -30000)
|
|
|
|
if (!unit->path.dest.isValid())
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
// skip dwarves that are dragging creatures or being dragged
|
|
|
|
// skip dwarves that are dragging creatures or being dragged
|
|
|
@ -71,33 +71,36 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
|
|
|
|
if (unit->relations.following != 0)
|
|
|
|
if (unit->relations.following != 0)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
old_block = Maps::getTileBlock(unit->pos.x, unit->pos.y, unit->pos.z);
|
|
|
|
// skip unconscious units
|
|
|
|
new_block = Maps::getTileBlock(unit->path.dest.x, unit->path.dest.y, unit->path.dest.z);
|
|
|
|
if (unit->counters.unconscious > 0)
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
// make sure source and dest map blocks are valid
|
|
|
|
// make sure source and dest map blocks are valid
|
|
|
|
if (!old_block || !new_block)
|
|
|
|
auto old_occ = Maps::getTileOccupancy(unit->pos);
|
|
|
|
|
|
|
|
auto new_occ = Maps::getTileOccupancy(unit->path.dest);
|
|
|
|
|
|
|
|
if (!old_occ || !new_occ)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
// clear appropriate occupancy flags at old tile
|
|
|
|
// clear appropriate occupancy flags at old tile
|
|
|
|
if (unit->flags1.bits.on_ground)
|
|
|
|
if (unit->flags1.bits.on_ground)
|
|
|
|
// this is technically wrong, but the game will recompute this as needed
|
|
|
|
// this is technically wrong, but the game will recompute this as needed
|
|
|
|
old_block->occupancy[unit->pos.x & 0xF][unit->pos.y & 0xF].bits.unit_grounded = 0;
|
|
|
|
old_occ->bits.unit_grounded = 0;
|
|
|
|
else
|
|
|
|
else
|
|
|
|
old_block->occupancy[unit->pos.x & 0xF][unit->pos.y & 0xF].bits.unit = 0;
|
|
|
|
old_occ->bits.unit = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// if there's already somebody standing at the destination, then force the unit to lay down
|
|
|
|
// if there's already somebody standing at the destination, then force the unit to lay down
|
|
|
|
if (new_block->occupancy[unit->path.dest.x & 0xF][unit->path.dest.y & 0xF].bits.unit)
|
|
|
|
if (new_occ->bits.unit)
|
|
|
|
unit->flags1.bits.on_ground = 1;
|
|
|
|
unit->flags1.bits.on_ground = 1;
|
|
|
|
|
|
|
|
|
|
|
|
// set appropriate occupancy flags at new tile
|
|
|
|
// set appropriate occupancy flags at new tile
|
|
|
|
if (unit->flags1.bits.on_ground)
|
|
|
|
if (unit->flags1.bits.on_ground)
|
|
|
|
new_block->occupancy[unit->path.dest.x & 0xF][unit->path.dest.y & 0xF].bits.unit_grounded = 1;
|
|
|
|
new_occ->bits.unit_grounded = 1;
|
|
|
|
else
|
|
|
|
else
|
|
|
|
new_block->occupancy[unit->path.dest.x & 0xF][unit->path.dest.y & 0xF].bits.unit = 1;
|
|
|
|
new_occ->bits.unit = 1;
|
|
|
|
|
|
|
|
|
|
|
|
// move unit to destination
|
|
|
|
// move unit to destination
|
|
|
|
unit->pos.x = unit->path.dest.x;
|
|
|
|
unit->pos = unit->path.dest;
|
|
|
|
unit->pos.y = unit->path.dest.y;
|
|
|
|
unit->path.path.clear();
|
|
|
|
unit->pos.z = unit->path.dest.z;
|
|
|
|
|
|
|
|
} while (0);
|
|
|
|
} while (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
return CR_OK;
|
|
|
|