1 /* ResidualVM - A 3D game interpreter
2  *
3  * ResidualVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the AUTHORS
5  * file distributed with this source distribution.
6  *
7  * Additional copyright for this file:
8  * Copyright (C) 1999-2000 Revolution Software Ltd.
9  * This code is based on source code created by Revolution Software,
10  * used with permission.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25  *
26  */
27 
28 #ifndef ICB_ICON_LIST_H_INCLUDED
29 #define ICB_ICON_LIST_H_INCLUDED
30 
31 // Include headers needed by this class.
32 #include "engines/icb/common/px_string.h"
33 #include "engines/icb/common/px_clu_api.h"
34 #include "engines/icb/p4.h"
35 #include "engines/icb/debug.h"
36 #include "engines/icb/string_vest.h"
37 
38 namespace ICB {
39 
40 extern const char *global_deleted_list;
41 
42 // This is used as a placeholder for deleted lists to save reallocating.
43 #define ICON_LIST_DELETED_PLACEHOLDER global_deleted_list
44 
45 // This defines the available values for the scope of these lists.
46 enum IconListScope { CURRENT_LOGIC = 0, SESSION_WIDE, MISSION_WIDE, GAME_WIDE };
47 
48 // This defines the maximum number of icons that can be in the menu.
49 #define ICON_LIST_MAX_ICONS 16 // This defines an array size, so must be a multiple of 4!
50 
51 // And this defines the maximum number that can be displayed at one time.
52 #define ICON_LIST_MAX_DISPLAYED 10
53 
54 // This defines how many of each icon are allowed (only meaningful when the list is handling duplicates).
55 #define ICON_MAX_DUPLICATE_COUNT 99
56 
57 // This means there is no current selection.
58 #define ICON_LIST_NO_SELECTION (-1)
59 
60 // This defines the name of the 'empty' icon.
61 
62 extern const char *iconListEmptyIcon;
63 #define ICON_LIST_EMPTY_ICON iconListEmptyIcon
64 
65 // Class to manage the lists of icons used in the game.  the inventory, Remora and speech system all use these lists.
66 class _icon_list {
67 public:
68 	// Default constructor and destructor.
69 	_icon_list();
~_icon_list()70 	~_icon_list() {}
71 
72 	// Alternative constructor, which takes the list name.
73 	inline _icon_list(const char *pcListName);
74 
75 	// Copy constructor and assignment operator.
76 	inline _icon_list(const _icon_list &oX);
77 	inline const _icon_list &operator=(const _icon_list &oOpB);
78 
79 	// This resets the list to its newly-created state.
80 	void Reset();
81 
82 	// Gets and sets.
GetListName()83 	const char *GetListName() const { return (m_pcListName); }
SetListName(const char * pcListName)84 	void SetListName(const char *pcListName) { m_pcListName = pcListName; }
85 
GetIconCount()86 	uint8 GetIconCount() const { return (m_nItemCount); }
87 
GetScope()88 	IconListScope GetScope() const { return (m_eScope); }
SetScope(IconListScope eScope)89 	void SetScope(IconListScope eScope) { m_eScope = eScope; }
90 
91 	inline const char *GetIcon(uint32 nIndex) const;
92 	inline uint32 GetIconHash(uint32 nIndex) const;
93 	uint8 GetDuplicateCount(const char *pcIconName) const;
94 	uint8 GetDuplicateCount(uint32 nIndex) const;
95 
96 	void SetAbsoluteIconCount(const char *pcIconName, uint32 nCount);
97 
98 	// This returns the index position of an icon in the list.
99 	int32 GetIconPosition(const char *pcIconName) const;
100 
101 	// These add and remove items from the list.
102 	void AddIcon(const char *pcIconName, const uint32 nIconNameHash);
103 	void RemoveIcon(const char *pcIconName, bool8 bForceRemove);
104 
105 private:
106 	const char *m_pcListName;                                  // The name of the list.
107 	IconListScope m_eScope;                                    // Scope of the list (determines when it is allowed to be destroyed).
108 	uint32 m_pnIconListHash[ICON_LIST_MAX_ICONS];              // The hash number of items currently in the inventory.
109 	uint8 m_pnDuplicateCount[ICON_LIST_MAX_ICONS];             // The list of items currently in the inventory.
110 	char m_ppcIconList[ICON_LIST_MAX_ICONS][MAXLEN_ICON_NAME]; // The list of items currently in the inventory.
111 	uint8 m_nItemCount;                                        // My own count of the number of items currently in the inventory.
112 	bool8 m_bAllowDuplicates;                                  // If true, a count is incremented when a duplicate is added.
113 	uint8 m_nPad1;
114 	uint8 m_nPad2;
115 
116 	// Private functions used only in this class.
117 	void Clone(const _icon_list &oSource);
118 };
119 
_icon_list(const _icon_list & oX)120 inline _icon_list::_icon_list(const _icon_list &oX) { Clone(oX); }
121 
122 inline const _icon_list &_icon_list::operator=(const _icon_list &oOpB) {
123 	Clone(oOpB);
124 
125 	return (*this);
126 }
127 
Reset()128 inline void _icon_list::Reset() {
129 	memset((uint8 *)m_pnIconListHash, 0, ICON_LIST_MAX_ICONS * sizeof(uint32));
130 	memset((uint8 *)m_pnDuplicateCount, 0, ICON_LIST_MAX_ICONS * sizeof(uint8));
131 	memset((uint8 *)m_ppcIconList, 0, ICON_LIST_MAX_ICONS * MAXLEN_ICON_NAME * sizeof(char));
132 	m_nItemCount = 0;
133 }
134 
GetIcon(uint32 nIndex)135 inline const char *_icon_list::GetIcon(uint32 nIndex) const { return (m_ppcIconList[nIndex]); }
136 
GetIconHash(uint32 nIndex)137 inline uint32 _icon_list::GetIconHash(uint32 nIndex) const {
138 	if (nIndex >= m_nItemCount) {
139 		Fatal_error("_icon_list::GetIconHash( %d ) called - list has %d items", nIndex, m_nItemCount);
140 	}
141 
142 	return (m_pnIconListHash[nIndex]);
143 }
144 
145 } // End of namespace ICB
146 
147 #endif // #if !defined( ICON_LIST_H_INCLUDED )
148