Пример #1
0
bool GameInterface::itemHasAction(Resources::ItemVisual *item, int32 action) {
	if (action != -1) {
		return item->canPerformAction(action, 0);
	} else {
		Resources::ActionArray actions = listActionsPossibleForObject(item);
		return !actions.empty();
	}
}
Пример #2
0
bool GameInterface::itemHasActionAt(Resources::ItemVisual *item, const Common::Point &position, int32 action) {
	int32 hotspotIndex = item->getHotspotIndexForPoint(position);
	if (action != -1) {
		return item->canPerformAction(action, hotspotIndex);
	} else {
		Resources::ActionArray actions = listActionsPossibleForObjectAt(item, position);
		return !actions.empty();
	}
}
Пример #3
0
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;
}
Пример #4
0
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];
		}
	}
}