Example #1
0
    bool Rook::isMovingPossible(const std::string &strFromAddr,
                                const std::string &strToAddr,
                                std::vector<std::string>& path, bool bFlag) const
    {
        Pos fromPos(strFromAddr);
        Pos toPos(strToAddr);

        if( toPos.getX() == fromPos.getX() )
        {
            for(int y = fromPos.getY() + 1; y < toPos.getY(); y++)
                path.push_back(Pos(toPos.getX(), y));
            for(int y = fromPos.getY() - 1; y > toPos.getY(); y--)
                path.push_back(Pos(toPos.getX(), y));
            return true;
        }

        if( toPos.getY() == fromPos.getY())
        {
            for(int x = fromPos.getX() + 1; x < toPos.getX(); x++)
                path.push_back(Pos(x, toPos.getY()));
            for(int x = fromPos.getX() - 1; x > toPos.getX(); x--)
                path.push_back(Pos(x, toPos.getY()));
            return true;
        }

        return false;
    }
Example #2
0
    bool Knight::isMovingPossible(const std::string &strFromAddr,
                                  const std::string &strToAddr,
                                  std::vector<std::string>& path,
                                  bool bFlag) const
    {
        Pos fromPos(strFromAddr);
        Pos toPos(strToAddr);

        if(abs(toPos.getX() - fromPos.getX()) == 2 && abs(toPos.getY() - fromPos.getY()) == 1 )
            return true;
        if(abs(toPos.getY() - fromPos.getY()) == 2 && abs(toPos.getX() - fromPos.getX()) == 1 )
            return true;

        path.push_back(strToAddr);
        return false;
    }
Example #3
0
uint32_t MoveEvents::onCreatureMove(Creature* creature, const Tile* fromTile, const Tile* toTile, bool isIn)
{
	MoveEvent_t eventType;
	const Tile* tile = NULL;

	if (isIn)
	{
		tile = toTile;
		eventType = MOVE_EVENT_STEP_IN;
	}
	else
	{
		tile = fromTile;
		eventType = MOVE_EVENT_STEP_OUT;
	}

	Position fromPos(0, 0, 0);

	if (fromTile)
	{
		fromPos = fromTile->getPosition();
	}

	Position toPos(0, 0, 0);

	if (toTile)
	{
		toPos = toTile->getPosition();
	}

	uint32_t ret = 1;
	MoveEvent* moveEvent = getEvent(tile, eventType);

	if (moveEvent)
	{
		ret = ret & moveEvent->fireStepEvent(creature, NULL, fromPos, toPos);
	}

	Item* tileItem = NULL;

	if (m_lastCacheTile == tile)
	{
		if (m_lastCacheItemVector.empty())
		{
			return ret;
		}

		//We can not use iterators here since the scripts can invalidate the iterator
		for (uint32_t i = 0; i < m_lastCacheItemVector.size(); ++i)
		{
			tileItem = m_lastCacheItemVector[i];

			if (tileItem)
			{
				moveEvent = getEvent(tileItem, eventType);

				if (moveEvent)
				{
					ret = ret & moveEvent->fireStepEvent(creature, tileItem, fromPos, toPos);
				}
			}
		}

		return ret;
	}

	m_lastCacheTile = tile;
	m_lastCacheItemVector.clear();
	//We can not use iterators here since the scripts can invalidate the iterator
	int32_t j = tile->__getLastIndex();

	for (int32_t i = tile->__getFirstIndex(); i < j; ++i)
	{
		Thing* thing = tile->__getThing(i);

		if (thing && (tileItem = thing->getItem()))
		{
			moveEvent = getEvent(tileItem, eventType);

			if (moveEvent)
			{
				m_lastCacheItemVector.push_back(tileItem);
				ret = ret & moveEvent->fireStepEvent(creature, tileItem, fromPos, toPos);
			}
			else if (hasTileEvent(tileItem))
			{
				m_lastCacheItemVector.push_back(tileItem);
			}
		}
	}

	return ret;
}