本文整理汇总了C++中MapComposite::getAroundPointIterator方法的典型用法代码示例。如果您正苦于以下问题:C++ MapComposite::getAroundPointIterator方法的具体用法?C++ MapComposite::getAroundPointIterator怎么用?C++ MapComposite::getAroundPointIterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MapComposite
的用法示例。
在下文中一共展示了MapComposite::getAroundPointIterator方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handlePickup
void GameHandler::handlePickup(GameClient &client, MessageIn &message)
{
const int x = message.readInt16();
const int y = message.readInt16();
const Point ppos =
client.character->getComponent<ActorComponent>()->getPosition();
// TODO: use a less arbitrary value.
if (std::abs(x - ppos.x) + std::abs(y - ppos.y) < 48)
{
MapComposite *map = client.character->getMap();
Point ipos(x, y);
for (FixedActorIterator i(map->getAroundPointIterator(ipos, 0)); i; ++i)
{
Entity *o = *i;
Point opos = o->getComponent<ActorComponent>()->getPosition();
if (o->getType() == OBJECT_ITEM && opos.x == x && opos.y == y)
{
ItemComponent *item = o->getComponent<ItemComponent>();
ItemClass *ic = item->getItemClass();
int amount = item->getAmount();
if (!Inventory(client.character).insert(ic->getDatabaseID(),
amount))
{
GameState::remove(o);
// We only do this when items are to be kept in memory
// between two server restart.
if (!Configuration::getValue("game_floorItemDecayTime", 0))
{
// Remove the floor item from map
accountHandler->removeFloorItems(map->getID(),
ic->getDatabaseID(),
amount, x, y);
}
// log transaction
std::stringstream str;
str << "User picked up item " << ic->getDatabaseID()
<< " at " << opos.x << "x" << opos.y;
auto *characterComponent = client.character
->getComponent<CharacterComponent>();
accountHandler->sendTransaction(
characterComponent->getDatabaseID(),
TRANS_ITEM_PICKUP, str.str()
);
}
break;
}
}
}
}
示例2:
static Being *findBeingNear(Actor *p, int id)
{
MapComposite *map = p->getMap();
const Point &ppos = p->getPosition();
// See map.h for tiles constants
const int pixelDist = DEFAULT_TILE_LENGTH * TILES_TO_BE_NEAR;
for (BeingIterator i(map->getAroundPointIterator(ppos, pixelDist)); i; ++i)
{
Being *b = *i;
if (b->getPublicID() != id)
continue;
return ppos.inRangeOf(b->getPosition(), pixelDist) ? b : 0;
}
return 0;
}
示例3:
static Actor *findActorNear(Actor *p, int id)
{
MapComposite *map = p->getMap();
const Point &ppos = p->getPosition();
// See map.hpp for tiles constants
const int pixelDist = DEFAULT_TILE_WIDTH * TILES_TO_BE_NEAR;
for (ActorIterator i(map->getAroundPointIterator(ppos, pixelDist)); i; ++i)
{
Actor *a = *i;
if (a->getPublicID() != id)
continue;
return ppos.inRangeOf(a->getPosition(), pixelDist) ? a : 0;
}
return 0;
}
示例4:
static Entity *findCharacterNear(Entity *p, int id)
{
MapComposite *map = p->getMap();
const Point &ppos = p->getComponent<ActorComponent>()->getPosition();
// See map.h for tiles constants
const int pixelDist = DEFAULT_TILE_LENGTH * TILES_TO_BE_NEAR;
for (CharacterIterator i(map->getAroundPointIterator(ppos,
pixelDist)); i; ++i)
{
Entity *c = *i;
if (c->getComponent<ActorComponent>()->getPublicID() != id)
continue;
if (ppos.inRangeOf(c->getComponent<ActorComponent>()->getPosition(),
pixelDist))
return c;
return 0;
}
return 0;
}
示例5: processMessage
void GameHandler::processMessage(NetComputer *comp, MessageIn &message)
{
GameClient &computer = *static_cast< GameClient * >(comp);
MessageOut result;
if (computer.status == CLIENT_LOGIN)
{
if (message.getId() != PGMSG_CONNECT)
return;
std::string magic_token = message.readString(MAGIC_TOKEN_LENGTH);
computer.status = CLIENT_QUEUED; // Before the addPendingClient
mTokenCollector.addPendingClient(magic_token, &computer);
return;
}
else if (computer.status != CLIENT_CONNECTED)
{
return;
}
switch (message.getId())
{
case PGMSG_SAY:
{
std::string say = message.readString();
if (say.empty()) break;
if (say[0] == '@')
{
CommandHandler::handleCommand(computer.character, say);
break;
}
GameState::sayAround(computer.character, say);
std::string msg = computer.character->getName() + " said " + say;
accountHandler->sendTransaction(computer.character->getDatabaseID(), TRANS_MSG_PUBLIC, msg);
} break;
case PGMSG_NPC_TALK:
case PGMSG_NPC_TALK_NEXT:
case PGMSG_NPC_SELECT:
case PGMSG_NPC_NUMBER:
case PGMSG_NPC_STRING:
{
int id = message.readShort();
Actor *o = findActorNear(computer.character, id);
if (!o || o->getType() != OBJECT_NPC)
{
sendError(comp, id, "Not close enough to NPC\n");
break;
}
NPC *q = static_cast< NPC * >(o);
if (message.getId() == PGMSG_NPC_SELECT)
{
q->select(computer.character, message.readByte());
}
else if (message.getId() == PGMSG_NPC_NUMBER)
{
q->integerReceived(computer.character, message.readLong());
}
else if (message.getId() == PGMSG_NPC_STRING)
{
q->stringReceived(computer.character, message.readString());
}
else
{
q->prompt(computer.character, message.getId() == PGMSG_NPC_TALK);
}
} break;
case PGMSG_PICKUP:
{
int x = message.readShort();
int y = message.readShort();
Point ppos = computer.character->getPosition();
// TODO: use a less arbitrary value.
if (std::abs(x - ppos.x) + std::abs(y - ppos.y) < 48)
{
MapComposite *map = computer.character->getMap();
Point ipos(x, y);
for (FixedActorIterator i(map->getAroundPointIterator(ipos, 0)); i; ++i)
{
Actor *o = *i;
Point opos = o->getPosition();
if (o->getType() == OBJECT_ITEM && opos.x == x && opos.y == y)
{
Item *item = static_cast< Item * >(o);
ItemClass *ic = item->getItemClass();
Inventory(computer.character)
.insert(ic->getDatabaseID(), item->getAmount());
GameState::remove(item);
// log transaction
std::stringstream str;
str << "User picked up item " << ic->getDatabaseID()
<< " at " << opos.x << "x" << opos.y;
accountHandler->sendTransaction(computer.character->getDatabaseID(),
TRANS_ITEM_PICKUP, str.str());
break;
}
//.........这里部分代码省略.........