本文整理汇总了C++中MapComposite::getMap方法的典型用法代码示例。如果您正苦于以下问题:C++ MapComposite::getMap方法的具体用法?C++ MapComposite::getMap怎么用?C++ MapComposite::getMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MapComposite
的用法示例。
在下文中一共展示了MapComposite::getMap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: insert
bool GameState::insert(Entity *ptr)
{
assert(!dbgLockObjects);
MapComposite *map = ptr->getMap();
assert(map && map->isActive());
/* Non-visible objects have neither position nor public ID, so their
insertion cannot fail. Take care of them first. */
if (!ptr->isVisible())
{
map->insert(ptr);
ptr->signal_inserted.emit(ptr);
return true;
}
// Check that coordinates are actually valid.
Actor *obj = static_cast< Actor * >(ptr);
Map *mp = map->getMap();
Point pos = obj->getPosition();
if ((int)pos.x / mp->getTileWidth() >= mp->getWidth() ||
(int)pos.y / mp->getTileHeight() >= mp->getHeight())
{
LOG_ERROR("Tried to insert an actor at position " << pos.x << ','
<< pos.y << " outside map " << map->getID() << '.');
// Set an arbitrary small position.
pos = Point(100, 100);
obj->setPosition(pos);
}
if (!map->insert(obj))
{
// The map is overloaded, no room to add a new actor
LOG_ERROR("Too many actors on map " << map->getID() << '.');
return false;
}
obj->signal_inserted.emit(obj);
// DEBUG INFO
switch (obj->getType())
{
case OBJECT_ITEM:
LOG_DEBUG("Item inserted: "
<< obj->getComponent<ItemComponent>()->getItemClass()->getDatabaseID());
break;
case OBJECT_NPC:
LOG_DEBUG("NPC inserted: " << obj->getComponent<NpcComponent>()->getNpcId());
break;
case OBJECT_CHARACTER:
LOG_DEBUG("Player inserted: "
<< static_cast<Being*>(obj)->getName());
break;
case OBJECT_EFFECT:
LOG_DEBUG("Effect inserted: "
<< obj->getComponent<EffectComponent>()->getEffectId());
break;
case OBJECT_MONSTER:
LOG_DEBUG("Monster inserted: "
<< static_cast<Monster*>(obj)->getSpecy()->getId());
break;
case OBJECT_ACTOR:
case OBJECT_OTHER:
default:
LOG_DEBUG("Entity inserted: " << obj->getType());
break;
}
obj->raiseUpdateFlags(UPDATEFLAG_NEW_ON_MAP);
if (obj->getType() != OBJECT_CHARACTER)
return true;
/* Since the player does not know yet where in the world its character is,
we send a map-change message, even if it is the first time it
connects to this server. */
MessageOut mapChangeMessage(GPMSG_PLAYER_MAP_CHANGE);
mapChangeMessage.writeString(map->getName());
mapChangeMessage.writeInt16(pos.x);
mapChangeMessage.writeInt16(pos.y);
gameHandler->sendTo(static_cast< Character * >(obj), mapChangeMessage);
// update the online state of the character
accountHandler->updateOnlineStatus(
static_cast< Character * >(obj)->getDatabaseID(), true);
return true;
}