本文整理汇总了C++中ThingPtr::isCreature方法的典型用法代码示例。如果您正苦于以下问题:C++ ThingPtr::isCreature方法的具体用法?C++ ThingPtr::isCreature怎么用?C++ ThingPtr::isCreature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ThingPtr
的用法示例。
在下文中一共展示了ThingPtr::isCreature方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getTopCreature
CreaturePtr Tile::getTopCreature()
{
CreaturePtr creature;
for(uint i = 0; i < m_things.size(); ++i) {
ThingPtr thing = m_things[i];
if(thing->isLocalPlayer()) // return local player if there is no other creature
creature = thing->static_self_cast<Creature>();
else if(thing->isCreature() && !thing->isLocalPlayer())
return thing->static_self_cast<Creature>();
}
if(!creature && !m_walkingCreatures.empty())
creature = m_walkingCreatures.back();
// check for walking creatures in tiles around
if(!creature) {
for(int xi=-1;xi<=1;++xi) {
for(int yi=-1;yi<=1;++yi) {
Position pos = m_position.translated(xi, yi);
if(pos == m_position)
continue;
const TilePtr& tile = g_map.getTile(pos);
if(tile) {
for(const CreaturePtr& c : tile->getCreatures()) {
if(c->isWalking() && c->getLastStepFromPosition() == m_position && c->getStepProgress() < 0.75f) {
creature = c;
}
}
}
}
}
}
return creature;
}
示例2: look
void Game::look(const ThingPtr& thing)
{
if(!canPerformGameAction() || !thing)
return;
if(thing->isCreature() && m_protocolVersion >= 961)
m_protocolGame->sendLookCreature(thing->getId());
else
m_protocolGame->sendLook(thing->getPosition(), thing->getId(), thing->getStackPos());
}
示例3: useInventoryItemWith
void Game::useInventoryItemWith(int itemId, const ThingPtr& toThing)
{
if(!canPerformGameAction() || !toThing)
return;
Position pos = Position(0xFFFF, 0, 0); // means that is a item in inventory
if(toThing->isCreature())
m_protocolGame->sendUseOnCreature(pos, itemId, 0, toThing->getId());
else
m_protocolGame->sendUseItemWith(pos, itemId, 0, toThing->getPosition(), toThing->getId(), toThing->getStackpos());
}
示例4: useWith
void Game::useWith(const ItemPtr& item, const ThingPtr& toThing)
{
if(!canPerformGameAction() || !item || !toThing)
return;
Position pos = item->getPosition();
if(!pos.isValid()) // virtual item
pos = Position(0xFFFF, 0, 0); // means that is a item in inventory
if(toThing->isCreature())
m_protocolGame->sendUseOnCreature(pos, item->getId(), item->getStackpos(), toThing->getId());
else
m_protocolGame->sendUseItemWith(pos, item->getId(), item->getStackpos(), toThing->getPosition(), toThing->getId(), toThing->getStackpos());
}
示例5: move
void Game::move(const ThingPtr& thing, const Position& toPos, int count)
{
if(count <= 0)
count = 1;
if(!canPerformGameAction() || !thing || thing->getPosition() == toPos)
return;
uint id = thing->getId();
if(thing->isCreature()) {
CreaturePtr creature = thing->static_self_cast<Creature>();
id = Proto::Creature;
}
m_protocolGame->sendMove(thing->getPosition(), id, thing->getStackpos(), toPos, count);
}
示例6: removeThingColor
void Map::removeThingColor(const ThingPtr& thing)
{
if(!thing)
return;
if(thing->isItem())
thing->static_self_cast<Item>()->setColor(Color::alpha);
else if(thing->isCreature()) {
const TilePtr& tile = thing->getTile();
assert(tile);
const ThingPtr& topThing = tile->getTopThing();
assert(topThing);
topThing->static_self_cast<Item>()->setColor(Color::alpha);
}
}
示例7: colorizeThing
void Map::colorizeThing(const ThingPtr& thing, const Color& color)
{
if(!thing)
return;
if(thing->isItem())
thing->static_self_cast<Item>()->setColor(color);
else if(thing->isCreature()) {
const TilePtr& tile = thing->getTile();
assert(tile);
const ThingPtr& topThing = tile->getTopThing();
assert(topThing);
topThing->static_self_cast<Item>()->setColor(color);
}
}
示例8: getTopUseThing
ThingPtr Tile::getTopUseThing()
{
if(isEmpty())
return nullptr;
for(uint i = 0; i < m_things.size(); ++i) {
ThingPtr thing = m_things[i];
if(thing->isForceUse() || (!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop() && !thing->isCreature()))
return thing;
}
for(uint i = 0; i < m_things.size(); ++i) {
ThingPtr thing = m_things[i];
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isCreature())
return thing;
}
return m_things[0];
}
示例9: addThing
void Map::addThing(const ThingPtr& thing, const Position& pos, int stackPos)
{
if(!thing)
return;
if(thing->isItem() || thing->isCreature() || thing->isEffect()) {
const TilePtr& tile = getOrCreateTile(pos);
if(tile)
tile->addThing(thing, stackPos);
} else {
if(thing->isMissile()) {
m_floorMissiles[pos.z].push_back(thing->static_self_cast<Missile>());
thing->onAppear();
} else if(thing->isAnimatedText()) {
// this code will stack animated texts of the same color
AnimatedTextPtr animatedText = thing->static_self_cast<AnimatedText>();
AnimatedTextPtr prevAnimatedText;
bool merged = false;
for(auto other : m_animatedTexts) {
if(other->getPosition() == pos) {
prevAnimatedText = other;
if(other->merge(animatedText)) {
merged = true;
break;
}
}
}
if(!merged) {
if(prevAnimatedText) {
Point offset = prevAnimatedText->getOffset();
float t = prevAnimatedText->getTimer().ticksElapsed();
if(t < Otc::ANIMATED_TEXT_DURATION / 4.0) { // didnt move 12 pixels
int y = 12 - 48 * t / (float)Otc::ANIMATED_TEXT_DURATION;
offset += Point(0, y);
}
offset.y = std::min<int>(offset.y, 12);
animatedText->setOffset(offset);
}
m_animatedTexts.push_back(animatedText);
}
} else if(thing->isStaticText()) {
StaticTextPtr staticText = thing->static_self_cast<StaticText>();
bool mustAdd = true;
for(auto other : m_staticTexts) {
// try to combine messages
if(other->getPosition() == pos && other->addMessage(staticText->getName(), staticText->getMessageMode(), staticText->getFirstMessage())) {
mustAdd = false;
break;
}
}
if(mustAdd)
m_staticTexts.push_back(staticText);
else
return;
}
thing->setPosition(pos);
thing->onAppear();
}
notificateTileUpdate(pos);
}
示例10: getTopMoveThing
ThingPtr Tile::getTopMoveThing()
{
if(isEmpty())
return nullptr;
for(uint i = 0; i < m_things.size(); ++i) {
ThingPtr thing = m_things[i];
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop() && !thing->isCreature()) {
if(i > 0 && thing->isNotMoveable())
return m_things[i-1];
return thing;
}
}
for(const ThingPtr& thing : m_things) {
if(thing->isCreature())
return thing;
}
return m_things[0];
}