Resources::ActionArray GameInterface::listStockActionsPossibleForObject(Resources::ItemVisual *item) { Resources::ActionArray actions = listActionsPossibleForObject(item); Resources::ActionArray stockActions; for (uint i = 0; i < actions.size(); i++) { if (actions[i] < 4) { stockActions.push_back(actions[i]); } } return stockActions; }
void GameWindow::checkObjectAtPos(const Common::Point &pos, int16 selectedInventoryItem, int16 &singlePossibleAction, bool &isDefaultAction) { _objectUnderCursor = nullptr; singlePossibleAction = -1; isDefaultAction = false; Math::Ray ray = StarkScene->makeRayFromMouse(_cursor->getMousePosition(true)); Common::Rect cursorRect; if (selectedInventoryItem != -1) { cursorRect = _cursor->getHotRectangle(); cursorRect.translate(pos.x, pos.y); } // Render entries are sorted from the farthest to the camera to the nearest // Loop in reverse order for (int i = _renderEntries.size() - 1; i >= 0; i--) { if (_renderEntries[i]->containsPoint(pos, _objectRelativePosition, cursorRect) || _renderEntries[i]->intersectRay(ray)) { _objectUnderCursor = _renderEntries[i]->getOwner(); break; } } if (!_objectUnderCursor || !StarkGameInterface->itemHasActionAt(_objectUnderCursor, _objectRelativePosition, -1)) { // Only consider items with runnable scripts _objectUnderCursor = nullptr; return; } int32 defaultAction = StarkGameInterface->itemGetDefaultActionAt(_objectUnderCursor, _objectRelativePosition); if (defaultAction != -1) { // Use the default action if there is one singlePossibleAction = defaultAction; isDefaultAction = true; } else if (selectedInventoryItem != -1) { // Use the selected inventory item if there is one if (StarkGameInterface->itemHasActionAt(_objectUnderCursor, _objectRelativePosition, selectedInventoryItem)) { singlePossibleAction = selectedInventoryItem; } } else { // Otherwise, use stock actions Resources::ActionArray actionsPossible = StarkGameInterface->listStockActionsPossibleForObjectAt( _objectUnderCursor, _objectRelativePosition); if (actionsPossible.size() == 1) { singlePossibleAction = actionsPossible[0]; } } }