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

knowledgeset.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/resources/knowledgeset.h"
00024 
00025 #include "engines/stark/formats/xrc.h"
00026 #include "engines/stark/resources/item.h"
00027 #include "engines/stark/services/stateprovider.h"
00028 
00029 namespace Stark {
00030 namespace Resources {
00031 
00032 KnowledgeSet::~KnowledgeSet() {
00033 }
00034 
00035 KnowledgeSet::KnowledgeSet(Object *parent, byte subType, uint16 index, const Common::String &name) :
00036         Object(parent, subType, index, name) {
00037     _type = TYPE;
00038 }
00039 
00040 void KnowledgeSet::printData() {
00041 }
00042 
00043 Gfx::RenderEntryArray KnowledgeSet::getInventoryRenderEntries() const {
00044     Common::Array<Resources::Item *> inventoryItems = listChildren<Resources::Item>(Resources::Item::kItemInventory);
00045 
00046     // First add the inventory items from old saves which don't have an order
00047     Gfx::RenderEntryArray result;
00048     for (uint i = 0; i < inventoryItems.size(); i++) {
00049         // The first 4 elements are UI elements (Eye, Mouth, Hand, ...)
00050         if (i < 4 || !inventoryItems[i]->isEnabled()) continue;
00051 
00052         bool orderFound = false;
00053         for (uint j = 0; j < _inventoryItemOrder.size(); j++) {
00054             if (_inventoryItemOrder[j] == inventoryItems[i]->getIndex()) {
00055                 orderFound = true;
00056                 break;
00057             }
00058         }
00059 
00060         if (!orderFound) {
00061             result.push_back(inventoryItems[i]->getRenderEntry(Common::Point(0, 0)));
00062         }
00063     }
00064 
00065     // Then add the inventory items for which an order has been recorded
00066     for (uint i = 0; i < _inventoryItemOrder.size(); i++) {
00067         for (uint j = 0; j < inventoryItems.size(); j++) {
00068             if (inventoryItems[j]->isEnabled() && inventoryItems[j]->getIndex() == _inventoryItemOrder[i]) {
00069                 result.push_back(inventoryItems[j]->getRenderEntry(Common::Point(0, 0)));
00070             }
00071         }
00072     }
00073 
00074     return result;
00075 }
00076 
00077 void KnowledgeSet::addItem(InventoryItem *item) {
00078     _inventoryItemOrder.push_back(item->getIndex());
00079 }
00080 
00081 void KnowledgeSet::removeItem(InventoryItem *item) {
00082     Common::Array<uint16>::iterator it;
00083     for (it = _inventoryItemOrder.begin(); it != _inventoryItemOrder.end(); it++) {
00084         if (*it == item->getIndex()) {
00085             _inventoryItemOrder.erase(it);
00086             break;
00087         }
00088     }
00089 }
00090 
00091 void KnowledgeSet::saveLoad(ResourceSerializer *serializer) {
00092     if (_subType == kInventory) {
00093         serializer->syncArraySize(_inventoryItemOrder);
00094         for (uint i = 0; i < _inventoryItemOrder.size(); i++) {
00095             serializer->syncAsUint16LE(_inventoryItemOrder[i]);
00096         }
00097     }
00098 }
00099 
00100 Visual *KnowledgeSet::getInventoryItemVisual(uint16 itemIndex) {
00101     InventoryItem *item = findChildWithIndex<InventoryItem>(itemIndex, Item::kItemInventory);
00102     assert(item);
00103 
00104     return item->getCursorVisual();
00105 }
00106 
00107 int16 KnowledgeSet::getNeighborInventoryItem(int16 selectedIndex, bool forward) {
00108     if (selectedIndex < 0 && !_inventoryItemOrder.empty()) {
00109         return forward ? _inventoryItemOrder.front() : _inventoryItemOrder.back();
00110     }
00111 
00112     for (uint i = 0; i < _inventoryItemOrder.size(); ++i) {
00113         if (_inventoryItemOrder[i] == selectedIndex) {
00114             if ((i == 0 && !forward) || (i == _inventoryItemOrder.size() - 1 && forward)) {
00115                 return -1;
00116             } else {
00117                 i += forward ? 1 : -1;
00118                 return _inventoryItemOrder[i];
00119             }
00120         }
00121     }
00122 
00123     return -1;
00124 }
00125 
00126 } // End of namespace Resources
00127 } // End of namespace Stark


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