aboutsummaryrefslogtreecommitdiff
path: root/engines/illusions/dictionary.h
diff options
context:
space:
mode:
authorjohndoe1232014-03-30 09:31:53 +0200
committerEugene Sandulenko2018-07-20 06:43:33 +0000
commitbabe997295dbadd95ab497bc6b88e7a0021567e5 (patch)
treee61eb739a3d3f92f8d7e731d3684757932f70652 /engines/illusions/dictionary.h
parent3b3f84c764f8cab8f54b06bbafc607cfb6899fdd (diff)
downloadscummvm-rg350-babe997295dbadd95ab497bc6b88e7a0021567e5.tar.gz
scummvm-rg350-babe997295dbadd95ab497bc6b88e7a0021567e5.tar.bz2
scummvm-rg350-babe997295dbadd95ab497bc6b88e7a0021567e5.zip
ILLUSIONS: Add more script opcodes
- Add support for duplicate keys to the dictionary - Add trigger functions support - Improve inventory, now items can be clicked
Diffstat (limited to 'engines/illusions/dictionary.h')
-rw-r--r--engines/illusions/dictionary.h36
1 files changed, 30 insertions, 6 deletions
diff --git a/engines/illusions/dictionary.h b/engines/illusions/dictionary.h
index 6bdc539725..11b05a6348 100644
--- a/engines/illusions/dictionary.h
+++ b/engines/illusions/dictionary.h
@@ -34,25 +34,49 @@ class TalkEntry;
template<class T>
class DictionaryHashMap {
+protected:
+ typedef Common::List<T*> List;
+ typedef typename List::iterator ListIterator;
+ typedef Common::HashMap<uint32, List*> Map;
+ typedef typename Map::iterator MapIterator;
+ Map _map;
public:
+ ~DictionaryHashMap() {
+ for (MapIterator it = _map.begin(); it != _map.end(); ++it)
+ delete it->_value;
+ }
+
void add(uint32 id, T *value) {
- _map[id] = value;
+ MapIterator it = _map.find(id);
+ List *list;
+ if (it != _map.end())
+ list = it->_value;
+ else {
+ list = new List();
+ _map[id] = list;
+ }
+ list->push_back(value);
}
void remove(uint32 id) {
- _map.erase(id);
+ MapIterator it = _map.find(id);
+ List *list;
+ if (it != _map.end()) {
+ list = it->_value;
+ list->pop_back();
+ if (list->empty())
+ _map.erase(id);
+ }
}
T *find(uint32 id) {
- typename Common::HashMap<uint32, T*>::iterator it = _map.find(id);
+ MapIterator it = _map.find(id);
if (it != _map.end())
- return it->_value;
+ return it->_value->back();
return 0;
}
-protected:
- Common::HashMap<uint32, T*> _map;
};
class Dictionary {