ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

gameinterface.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "engines/stark/services/gameinterface.h"
00024 
00025 #include "engines/stark/movement/walk.h"
00026 
00027 #include "engines/stark/resources/knowledgeset.h"
00028 #include "engines/stark/resources/level.h"
00029 #include "engines/stark/resources/location.h"
00030 #include "engines/stark/resources/speech.h"
00031 
00032 #include "engines/stark/resources/floor.h"
00033 #include "engines/stark/resources/floorface.h"
00034 #include "engines/stark/resources/script.h"
00035 #include "engines/stark/resources/item.h"
00036 
00037 #include "engines/stark/services/global.h"
00038 #include "engines/stark/services/services.h"
00039 
00040 #include "engines/stark/visual/image.h"
00041 
00042 #include "engines/stark/scene.h"
00043 #include "engines/stark/services/userinterface.h"
00044 
00045 namespace Stark {
00046 
00047 GameInterface::GameInterface() {
00048 }
00049 
00050 GameInterface::~GameInterface() {
00051 }
00052 
00053 bool GameInterface::skipCurrentSpeeches() {
00054     Current *current = StarkGlobal->getCurrent();
00055 
00056     if (!current) {
00057         return false; // No current location, nothing to do
00058     }
00059 
00060     // Get all speeches
00061     Common::Array<Resources::Speech *> speeches;
00062     speeches.push_back(StarkGlobal->getLevel()->listChildrenRecursive<Resources::Speech>());
00063     speeches.push_back(current->getLevel()->listChildrenRecursive<Resources::Speech>());
00064     speeches.push_back(current->getLocation()->listChildrenRecursive<Resources::Speech>());
00065 
00066     // Stop them
00067     bool skippedSpeeches = false;
00068     for (uint i = 0; i < speeches.size(); i++) {
00069         Resources::Speech *speech = speeches[i];
00070         if (speech->isPlaying()) {
00071             speech->stop();
00072             skippedSpeeches = true;
00073         }
00074     }
00075 
00076     return skippedSpeeches;
00077 }
00078 
00079 void GameInterface::walkTo(const Common::Point &mouse) {
00080     Resources::Floor *floor = StarkGlobal->getCurrent()->getFloor();
00081     Resources::ModelItem *april = StarkGlobal->getCurrent()->getInteractive();
00082     if (!floor || !april) {
00083         return;
00084     }
00085 
00086     Math::Ray mouseRay = StarkScene->makeRayFromMouse(mouse);
00087 
00088     // First look for a direct intersection with the floor
00089     Math::Vector3d destinationPosition;
00090     int32 destinationFloorFaceIndex = floor->findFaceHitByRay(mouseRay, destinationPosition);
00091 
00092     // Otherwise fall back to the floor face center closest to the ray
00093     if (destinationFloorFaceIndex < 0) {
00094         destinationFloorFaceIndex = floor->findFaceClosestToRay(mouseRay, destinationPosition);
00095     }
00096 
00097     if (destinationFloorFaceIndex < 0) {
00098         // No destination was found
00099         return;
00100     }
00101 
00102     Walk *walk = new Walk(april);
00103     walk->setDestination(destinationPosition);
00104     walk->start();
00105 
00106     april->setMovement(walk);
00107 }
00108 
00109 VisualImageXMG *GameInterface::getActionImage(uint32 itemIndex, bool active) {
00110     // Lookup the action's item in the inventory
00111     Resources::KnowledgeSet *inventory = StarkGlobal->getLevel()->findChildWithSubtype<Resources::KnowledgeSet>(Resources::KnowledgeSet::kInventory, true);
00112 
00113     // Get the visual for the action
00114     Resources::InventoryItem *action = inventory->findChildWithIndex<Resources::InventoryItem>(itemIndex);
00115     Visual *visual = action->getActionVisual(active);
00116 
00117     return visual->get<VisualImageXMG>();
00118 }
00119 
00120 VisualImageXMG *GameInterface::getCursorImage(uint32 itemIndex) {
00121     // Lookup the item's item in the inventory
00122     Resources::KnowledgeSet *inventory = StarkGlobal->getLevel()->findChildWithSubtype<Resources::KnowledgeSet>(Resources::KnowledgeSet::kInventory, true);
00123 
00124     // Get the visual for the item
00125     Resources::InventoryItem *item = inventory->findChildWithIndex<Resources::InventoryItem>(itemIndex);
00126     Visual *visual = item->getCursorVisual();
00127 
00128     return visual->get<VisualImageXMG>();
00129 }
00130 
00131 bool GameInterface::itemHasAction(Resources::ItemVisual *item, int32 action) {
00132     if (action != -1) {
00133         return item->canPerformAction(action, 0);
00134     } else {
00135         Resources::ActionArray actions = listActionsPossibleForObject(item);
00136         return !actions.empty();
00137     }
00138 }
00139 
00140 bool GameInterface::itemHasActionAt(Resources::ItemVisual *item, const Common::Point &position, int32 action) {
00141     int32 hotspotIndex = item->getHotspotIndexForPoint(position);
00142     if (action != -1) {
00143         return item->canPerformAction(action, hotspotIndex);
00144     } else {
00145         Resources::ActionArray actions = listActionsPossibleForObjectAt(item, position);
00146         return !actions.empty();
00147     }
00148 }
00149 
00150 int32 GameInterface::itemGetDefaultActionAt(Resources::ItemVisual *item, const Common::Point &position) {
00151     int32 hotspotIndex = item->getHotspotIndexForPoint(position);
00152     Resources::PATTable *table = item->findChildWithOrder<Resources::PATTable>(hotspotIndex);
00153     if (table) {
00154         return table->getDefaultAction();
00155     } else {
00156         return -1;
00157     }
00158 }
00159 
00160 void GameInterface::itemDoAction(Resources::ItemVisual *item, uint32 action) {
00161     item->doAction(action, 0);
00162 }
00163 
00164 void GameInterface::itemDoActionAt(Resources::ItemVisual *item, uint32 action, const Common::Point &position) {
00165     int32 hotspotIndex = item->getHotspotIndexForPoint(position);
00166     item->doAction(action, hotspotIndex);
00167 }
00168 
00169 Common::String GameInterface::getItemTitle(Resources::ItemVisual *item) {
00170     return item->getHotspotTitle(0);
00171 }
00172 
00173 Common::String GameInterface::getItemTitleAt(Resources::ItemVisual *item, const Common::Point &pos) {
00174     int32 hotspotIndex = item->getHotspotIndexForPoint(pos);
00175     return item->getHotspotTitle(hotspotIndex);
00176 }
00177 
00178 Resources::ActionArray GameInterface::listActionsPossibleForObject(Resources::ItemVisual *item) {
00179     if (item == nullptr) {
00180         return Resources::ActionArray();
00181     }
00182 
00183     Resources::PATTable *table = item->findChildWithOrder<Resources::PATTable>(0);
00184     if (table) {
00185         return table->listPossibleActions();
00186     } else {
00187         return Resources::ActionArray();
00188     }
00189 }
00190 
00191 Resources::ActionArray GameInterface::listActionsPossibleForObjectAt(Resources::ItemVisual *item,
00192                                                                      const Common::Point &pos) {
00193     if (item == nullptr) {
00194         return Resources::ActionArray();
00195     }
00196 
00197     int index = item->getHotspotIndexForPoint(pos);
00198     if (index < 0) {
00199         return Resources::ActionArray();
00200     }
00201 
00202     Resources::PATTable *table = item->findChildWithOrder<Resources::PATTable>(index);
00203     if (table) {
00204         return table->listPossibleActions();
00205     } else {
00206         return Resources::ActionArray();
00207     }
00208 }
00209 
00210 Resources::ActionArray GameInterface::listStockActionsPossibleForObject(Resources::ItemVisual *item) {
00211     Resources::ActionArray actions = listActionsPossibleForObject(item);
00212 
00213     Resources::ActionArray stockActions;
00214     for (uint i = 0; i < actions.size(); i++) {
00215         if (actions[i] < 4) {
00216             stockActions.push_back(actions[i]);
00217         }
00218     }
00219 
00220     return stockActions;
00221 }
00222 
00223 Resources::ActionArray GameInterface::listStockActionsPossibleForObjectAt(Resources::ItemVisual *item,
00224                                                                           const Common::Point &pos) {
00225     Resources::ActionArray actions = listActionsPossibleForObjectAt(item, pos);
00226 
00227     Resources::ActionArray stockActions;
00228     for (uint i = 0; i < actions.size(); i++) {
00229         if (actions[i] < 4) {
00230             stockActions.push_back(actions[i]);
00231         }
00232     }
00233 
00234     return stockActions;
00235 }
00236 
00237 
00238 bool GameInterface::isAprilWalking() const {
00239     Current *current = StarkGlobal->getCurrent();
00240     if (!current) {
00241         return false;
00242     }
00243 
00244     Resources::ModelItem *april = current->getInteractive();
00245     if (!april) {
00246         return false;
00247     }
00248 
00249     Movement *movement = april->getMovement();
00250     if (!movement) {
00251         return false;
00252     }
00253 
00254     Walk *walk = dynamic_cast<Walk *>(movement);
00255     if (!walk) {
00256         return false;
00257     }
00258 
00259     return !walk->hasEnded();
00260 }
00261 
00262 void GameInterface::setAprilRunning() {
00263     Current *current = StarkGlobal->getCurrent();
00264     Resources::ModelItem *april = current->getInteractive();
00265     Movement *movement = april->getMovement();
00266     Walk *walk = dynamic_cast<Walk *>(movement);
00267 
00268     assert(walk);
00269     walk->setRunning();
00270 }
00271 
00272 Common::Array<Common::Point> GameInterface::listExitPositions() {
00273     return StarkGlobal->getCurrent()->getLocation()->listExitPositions();
00274 }
00275 
00276 } // End of namespace Stark


Generated on Sat Mar 23 2019 05:01:39 for ResidualVM by doxygen 1.7.1
curved edge   curved edge