void GameInterface::walkTo(const Common::Point &mouse) { Resources::Floor *floor = StarkGlobal->getCurrent()->getFloor(); Resources::ModelItem *april = StarkGlobal->getCurrent()->getInteractive(); if (!floor || !april) { return; } Math::Ray mouseRay = StarkScene->makeRayFromMouse(mouse); // First look for a direct intersection with the floor Math::Vector3d destinationPosition; int32 destinationFloorFaceIndex = floor->findFaceHitByRay(mouseRay, destinationPosition); // Otherwise fall back to the floor face center closest to the ray if (destinationFloorFaceIndex < 0) { destinationFloorFaceIndex = floor->findFaceClosestToRay(mouseRay, destinationPosition); } if (destinationFloorFaceIndex < 0) { // No destination was found return; } Walk *walk = new Walk(april); walk->setDestination(destinationPosition); walk->start(); april->setMovement(walk); }
Command *Command::opWalkTo(Script *script, const ResourceReference &objectRef, int32 suspend) { Resources::ModelItem *april = StarkGlobal->getCurrent()->getInteractive(); Math::Vector3d destinationPosition = getObjectPosition(objectRef); Math::Vector3d currentPosition = april->getPosition3D(); if (destinationPosition == currentPosition) { return nextCommand(); } Walk *walk = new Walk(april); walk->setDestination(destinationPosition); walk->start(); april->setMovement(walk); if (suspend) { script->suspend(april); april->setMovementSuspendedScript(script); return this; // Stay on the same command while suspended } else { return nextCommand(); } }