Exemple #1
0
void Viewport::_drawDebugPath(Graphics *graphics)
{
    if (mDebugFlags & Map::MAP_MOUSE_PATH)
    {
        // Get the current mouse position
        SDL_GetMouseState(&mMouseX, &mMouseY);

        // Prepare the walkmask corresponding to the protocol
        unsigned char walkMask;
        switch (Net::getNetworkType())
        {
          case ServerInfo::TMWATHENA:
            walkMask = Map::BLOCKMASK_WALL | Map::BLOCKMASK_CHARACTER;
            break;
          case ServerInfo::MANASERV:
          default:
            walkMask = Map::BLOCKMASK_WALL;
            break;
        }

        static Path debugPath;
        static Vector lastMouseDestination = Vector(0.0f, 0.0f);
        Vector mouseDestination(mMouseX + (int) mPixelViewX,
                                mMouseY + (int) mPixelViewY);

        if (mouseDestination.x != lastMouseDestination.x
            || mouseDestination.y != lastMouseDestination.y)
        {
            const Vector &playerPos = player_node->getPosition();

            // Adapt the path finding to the precision requested
            if (Net::getPlayerHandler()->usePixelPrecision())
            {
                debugPath = mMap->findPixelPath((int) playerPos.x,
                                                (int) playerPos.y,
                                                mouseDestination.x,
                                                mouseDestination.y,
                                                player_node->getCollisionRadius(),
                                                walkMask);
            }
            else
            {
                debugPath = mMap->findTilePath((int) playerPos.x,
                                               (int) playerPos.y,
                                               mouseDestination.x,
                                               mouseDestination.y,
                                               walkMask);
            }

            lastMouseDestination = mouseDestination;
        }

        _drawPath(graphics, debugPath, gcn::Color(128, 0, 128, 150));
    }

    // Draw the path debug information for every beings.
    ActorSpritesConstIterator it, it_end;
    const ActorSprites &actors = actorSpriteManager->getAll();
    for (it = actors.begin(), it_end = actors.end() ; it != it_end; it++)
    {
        Being *being = dynamic_cast<Being*>(*it);
        if (!being)
            continue;

        const Vector &beingPos = being->getPosition();
        graphics->setColor(gcn::Color(128, 128, 0, 150));

        if (mDebugFlags & Map::MAP_BEING_COLLISION_RADIUS)
        {
            const int radius = being->getCollisionRadius();
            graphics->fillRectangle(gcn::Rectangle(
                                        (int) beingPos.x
                                        - (int) mPixelViewX - radius,
                                        (int) beingPos.y - (int) mPixelViewY
                                        - radius,
                                        radius * 2, radius * 2));
        }

        if (mDebugFlags & Map::MAP_BEING_PATH)
            _drawPath(graphics, being->getPath(), gcn::Color(0, 0, 255, 150));

        if (mDebugFlags & Map::MAP_BEING_POSITION)
        {
            // Draw the absolute x, y position using a cross.
            graphics->setColor(gcn::Color(0, 0, 255, 255));
            graphics->drawLine((int) beingPos.x - (int) mPixelViewX - 4,
                               (int) beingPos.y - (int) mPixelViewY - 4,
                               (int) beingPos.x - (int) mPixelViewX + 4,
                               (int) beingPos.y - (int) mPixelViewY + 4);
            graphics->drawLine((int) beingPos.x - (int) mPixelViewX + 4,
                               (int) beingPos.y - (int) mPixelViewY - 4,
                               (int) beingPos.x - (int) mPixelViewX - 4,
                               (int) beingPos.y - (int) mPixelViewY + 4);
        }
    }
}