1 #ifndef		_KEYS_H_
2 #define		_KEYS_H_
3 
4 #include "Handle_Items.h"
5 #include "Item_Types.h"
6 #include "Types.h"
7 
8 #include <string_theory/string>
9 
10 #include <vector>
11 
12 
13 struct KEY
14 {
15 	UINT16 usSectorFound; // where and
16 	UINT16 usDateFound; // when the key was found
17 };
18 
19 
20 #define KEY_USED			0x01
21 
22 #define LOCK_UNOPENABLE		255
23 #define NO_KEY				255
24 
25 #define LOCK_REGULAR			1
26 #define LOCK_PADLOCK			2
27 #define LOCK_CARD			3
28 #define LOCK_ELECTRONIC		4
29 #define LOCK_SPECIAL			5
30 
31 #define MAXLOCKDESCLENGTH		40
32 struct LOCK
33 {
34 	CHAR8  ubEditorName[ MAXLOCKDESCLENGTH ]; // name to display in editor
35 	UINT16 usKeyItem; // key for this door uses which graphic (item #)?
36 	UINT8  ubLockType; // regular, padlock, electronic, etc
37 	UINT8  ubPickDifficulty; // difficulty to pick such a lock
38 	UINT8  ubSmashDifficulty; // difficulty to smash such a lock
39 	UINT8  ubFiller; // XXX HACK000B
40 };
41 
42 // Defines below for the perceived value of the door
43 #define DOOR_PERCEIVED_UNKNOWN		0
44 #define DOOR_PERCEIVED_LOCKED		1
45 #define DOOR_PERCEIVED_UNLOCKED	2
46 #define DOOR_PERCEIVED_BROKEN		3
47 
48 #define DOOR_PERCEIVED_TRAPPED		1
49 #define DOOR_PERCEIVED_UNTRAPPED	2
50 
51 struct DOOR
52 {
53 	INT16   sGridNo;
54 	BOOLEAN fLocked; // is the door locked
55 	UINT8   ubTrapLevel; // difficulty of finding the trap, 0-10
56 	UINT8   ubTrapID; // the trap type (0 is no trap)
57 	UINT8   ubLockID; // the lock (0 is no lock)
58 	INT8    bPerceivedLocked;	// The perceived lock value can be different than the fLocked.
59 					// Values for this include the fact that we don't know the status of
60 					// the door, etc
61 	INT8    bPerceivedTrapped; // See above, but with respect to traps rather than locked status
62 	INT8    bLockDamage; // Damage to the lock
63 	INT8    bPadding[4]; // extra bytes // XXX HACK000B
64 };
65 
66 
67 enum DoorTrapTypes
68 {
69 	NO_TRAP = 0,
70 	EXPLOSION,
71 	ELECTRIC,
72 	SIREN,
73 	SILENT_ALARM,
74 	BROTHEL_SIREN,
75 	SUPER_ELECTRIC,
76 	NUM_DOOR_TRAPS
77 };
78 
79 #define DOOR_TRAP_STOPS_ACTION		0x01
80 #define DOOR_TRAP_RECURRING		0x02
81 #define DOOR_TRAP_SILENT		0x04
82 
83 
84 struct DOORTRAP
85 {
86 	UINT8 fFlags; // stops action?  recurring trap?
87 };
88 
89 
90 //The status of the door, either open or closed
91 #define DOOR_OPEN			0x01
92 #define DOOR_PERCEIVED_OPEN		0x02
93 #define DOOR_PERCEIVED_NOTSET		0x04
94 #define DOOR_BUSY			0x08
95 #define DOOR_HAS_TIN_CAN		0x10
96 
97 
98 #define DONTSETDOORSTATUS		2
99 
100 struct DOOR_STATUS
101 {
102 	INT16 sGridNo;
103 	UINT8 ubFlags;
104 
105 };
106 
107 
108 // This is the number of different types of doors we can have
109 // in one map at a time...
110 
111 #define NUM_KEYS			64
112 #define NUM_LOCKS			64
113 #define INVALID_KEY_NUMBER		255
114 
115 #define ANYKEY				252
116 #define AUTOUNLOCK			253
117 #define OPENING_NOT_POSSIBLE		254
118 
119 extern KEY KeyTable[NUM_KEYS];
120 extern LOCK LockTable[NUM_LOCKS];
121 extern DOORTRAP const DoorTrapTable[NUM_DOOR_TRAPS];
122 
123 extern BOOLEAN AddKeysToKeyRing( SOLDIERTYPE *pSoldier, UINT8 ubKeyID, UINT8 ubNumber );
124 extern BOOLEAN RemoveKeyFromKeyRing( SOLDIERTYPE *pSoldier, UINT8 ubPos, OBJECTTYPE * pObj );
125 extern BOOLEAN RemoveAllOfKeyFromKeyRing( SOLDIERTYPE *pSoldier, UINT8 ubPos, OBJECTTYPE * pObj );
126 bool KeyExistsInKeyRing(SOLDIERTYPE const&, UINT8 key_id);
127 bool SoldierHasKey(SOLDIERTYPE const&, UINT8 key_id);
128 
129 //**********************************
130 //* Door utils add by Kris Morness *
131 //**********************************
132 
133 //Dynamic array of Doors.  For general game purposes, the doors that are locked and/or trapped
134 //are permanently saved within the map, and are loaded and allocated when the map is loaded.  Because
135 //the editor allows more doors to be added, or removed, the actual size of the DoorTable may change.
136 extern std::vector<DOOR> DoorTable;
137 
138 //File I/O for loading the door information from the map.  This automatically allocates
139 //the exact number of slots when loading.
140 
141 #define FOR_EACH_DOOR(iter) \
142 	for (DOOR& iter : DoorTable)
143 
144 void LoadDoorTableFromMap(HWFILE);
145 
146 //Saves the existing door information to the map.  Before it actually saves, it'll verify that the
147 //door still exists.  Otherwise, it'll ignore it.  It is possible in the editor to delete doors in
148 //many different ways, so I opted to put it in the saving routine.
149 extern void SaveDoorTableToMap( HWFILE fp );
150 
151 //The editor adds locks to the world.  If the gridno already exists, then the currently existing door
152 //information is overwritten.
153 extern void AddDoorInfoToTable( DOOR *pDoor );
154 //When the editor removes a door from the world, this function looks for and removes accompanying door
155 //information.  If the entry is not the last entry, the last entry is move to it's current slot, to keep
156 //everything contiguous.
157 extern void RemoveDoorInfoFromTable( INT32 iMapIndex );
158 //This is the link to see if a door exists at a gridno.
159 DOOR * FindDoorInfoAtGridNo( INT32 iMapIndex );
160 //Upon world deallocation, the door table needs to be deallocated.
161 void TrashDoorTable(void);
162 
163 ST::string GetTrapName(DOOR const&);
164 
165 BOOLEAN AttemptToUnlockDoor(const SOLDIERTYPE* pSoldier, DOOR* pDoor);
166 BOOLEAN AttemptToLockDoor(const SOLDIERTYPE* pSoldier, DOOR* pDoor);
167 BOOLEAN AttemptToSmashDoor( SOLDIERTYPE * pSoldier, DOOR * pDoor );
168 BOOLEAN AttemptToPickLock( SOLDIERTYPE * pSoldier, DOOR * pDoor );
169 BOOLEAN AttemptToBlowUpLock( SOLDIERTYPE * pSoldier, DOOR * pDoor );
170 BOOLEAN AttemptToUntrapDoor( SOLDIERTYPE * pSoldier, DOOR * pDoor );
171 BOOLEAN ExamineDoorForTraps( SOLDIERTYPE * pSoldier, DOOR * pDoor );
172 BOOLEAN HasDoorTrapGoneOff( SOLDIERTYPE * pSoldier, DOOR * pDoor );
173 void HandleDoorTrap(SOLDIERTYPE&, DOOR const&);
174 
175 
176 // Updates the perceived value to the user of the state of the door
177 void UpdateDoorPerceivedValue( DOOR *pDoor );
178 
179 
180 //Saves the Door Table array to the temp file
181 void SaveDoorTableToDoorTableTempFile(INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ);
182 
183 //Load the door table from the temp file
184 void LoadDoorTableFromDoorTableTempFile(void);
185 
186 
187 // Add a door to the door status array. As the user comes across the door, they
188 // are added. If the door already exists, nothing happens.
189 // is_open is True if the door is to be initially open, false if it is closed
190 // perceived_open is true if the door is to be initially open, else false
191 bool ModifyDoorStatus(GridNo, BOOLEAN is_open, BOOLEAN perceived_open);
192 
193 //Deletes the door status array
194 void TrashDoorStatusArray(void);
195 
196 // Saves the Door Status array to the MapTempfile
197 void SaveDoorStatusArrayToDoorStatusTempFile(INT16 sSectorX, INT16 sSectorY, INT8 bSectorZ);
198 
199 //Load the door status from the door status temp file
200 void LoadDoorStatusArrayFromDoorStatusTempFile();
201 
202 
203 //Save the key table to the saved game file
204 void SaveKeyTableToSaveGameFile(HWFILE);
205 
206 //Load the key table from the saved game file
207 void LoadKeyTableFromSaveedGameFile(HWFILE);
208 
209 // Returns a doors status value, NULL if not found
210 DOOR_STATUS *GetDoorStatus( INT16 sGridNo );
211 
212 bool AllMercsLookForDoor(GridNo);
213 
214 void MercLooksForDoors(SOLDIERTYPE const&);
215 
216 void UpdateDoorGraphicsFromStatus();
217 
218 BOOLEAN AttemptToCrowbarLock( SOLDIERTYPE * pSoldier, DOOR * pDoor );
219 
220 void LoadLockTable(void);
221 
222 void ExamineDoorsOnEnteringSector();
223 
224 void AttachStringToDoor( INT16 sGridNo );
225 
226 void DropKeysInKeyRing(SOLDIERTYPE&, GridNo, INT8 level, Visibility, bool add_to_drop_list, INT32 drop_list_slot, bool use_unloaded);
227 
228 #endif
229