engine/maps/source/MapUtils.cpp
// Swap two creatures on their tiles.
Swap two creatures on their tiles.
Swap two creatures on their tiles .
void MapUtils::swap_places(MapPtr map, CreaturePtr creature, CreaturePtr adjacent_creature)
{
  if (creature && adjacent_creature)
  {
    ostringstream ss;
    ss << "Swapping " << creature->get_id() << " and " << adjacent_creature->get_id();
    Log::instance().debug(ss.str());
    Coordinate cr_loc = map->get_location(creature->get_id());
    Coordinate adj_loc = map->get_location(adjacent_creature->get_id());
    TilePtr creatures_current_tile = map->at(cr_loc);
    if (creatures_current_tile && !creatures_current_tile->get_dangerous(adjacent_creature))
    {
      MapUtils::remove_creature(map, creature);
      MapUtils::remove_creature(map, adjacent_creature);
      MapUtils::add_or_update_location(map, creature, adj_loc);
      MapUtils::add_or_update_location(map, adjacent_creature, cr_loc);
    }
    else
    {
      IMessageManager& manager = MM::instance(MessageTransmit::SELF, creature, creature && creature->get_is_player());
      manager.add_new_message(StringTable::get(ActionTextKeys::ACTION_SWITCH_REFUSED));
      manager.send();
    }
  }
}
void MapUtils :: swap_places ( MapPtr map , CreaturePtr creature , CreaturePtr adjacent_creature ) { if ( creature && adjacent_creature ) { ostringstream ss ; ss << " " << creature -> get_id ( ) << " " << adjacent_creature -> get_id ( ) ; Log :: instance ( ) . debug ( ss . str ( ) ) ; Coordinate cr_loc = map -> get_location ( creature -> get_id ( ) ) ; Coordinate adj_loc = map -> get_location ( adjacent_creature -> get_id ( ) ) ; TilePtr creatures_current_tile = map -> at ( cr_loc ) ; if ( creatures_current_tile && ! creatures_current_tile -> get_dangerous ( adjacent_creature ) ) { MapUtils :: remove_creature ( map , creature ) ; MapUtils :: remove_creature ( map , adjacent_creature ) ; MapUtils :: add_or_update_location ( map , creature , adj_loc ) ; MapUtils :: add_or_update_location ( map , adjacent_creature , cr_loc ) ; } else { IMessageManager & manager = MM :: instance ( MessageTransmit :: SELF , creature , creature && creature -> get_is_player ( ) ) ; manager . add_new_message ( StringTable :: get ( ActionTextKeys :: ACTION_SWITCH_REFUSED ) ) ; manager . send ( ) ; } } }
Swap two creatures on their tiles.
Swap two creatures on their tiles .
// Get the location info. // Remove the creatures, then add them in the new location.