1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef WORLD_DAMAGE_INFO_H
24 #define WORLD_DAMAGE_INFO_H
25 
26 #include "ultima/shared/std/string.h"
27 
28 namespace Ultima {
29 namespace Ultima8 {
30 
31 class Item;
32 
33 /**
34  * The damage.dat flex contains data about each shape and how it should be damaged
35  */
36 class DamageInfo {
37 public:
38 	DamageInfo(uint8 data[6]);
~DamageInfo()39 	~DamageInfo() {};
40 
41 	//! apply this damage info to the given item.  Returns true if the item was destroyed in the process.
42 	bool applyToItem(Item *item, uint16 points) const;
43 
frameDataIsAbsolute()44 	bool frameDataIsAbsolute() const {
45 		return (_flags >> 7) & 1;
46 	}
replaceItem()47 	bool replaceItem() const {
48 		return (_flags >> 6) & 1;
49 	}
explodeDestroysItem()50 	bool explodeDestroysItem() const {
51 		return (_flags >> 5) & 1;
52 	}
explodeWithDamage()53 	bool explodeWithDamage() const {
54 		return (_flags >> 3) & 1;
55 	}
takesDamage()56 	bool takesDamage() const {
57 		return _flags & 1;
58 	}
59 
damagePoints()60 	uint8 damagePoints() const {
61 		return _damagePoints;
62 	}
63 
64 protected:
explode()65 	bool explode() const {
66 		return (_flags & 0x06) != 0;
67 	}
explosionType()68 	int explosionType() const {
69 		assert(explode());
70 		return ((_flags & 0x06) >> 1) - 1;
71 	}
72 
getReplacementShape()73 	uint16 getReplacementShape() const {
74 		assert(replaceItem());
75 		return static_cast<uint16>(_data[1]) << 8 | _data[0];
76 	}
77 
getReplacementFrame()78 	uint16 getReplacementFrame() const {
79 		assert(replaceItem());
80 		return static_cast<uint16>(_data[2]);
81 	}
82 
83 
84 	// Flags are ABCxDEEF
85 	// A = frame data is absolute (not relative to current)
86 	// B = item is replaced when destroyed
87 	// C = item destroyed after explosion
88 	// D = explosion damages surrounding items
89 	// EE = 2 bits for explosion type
90 	// F = item takes damage
91 	uint8 _flags;
92 	uint8 _sound;
93 	uint8 _data[3];
94 	uint8 _damagePoints;
95 };
96 
97 } // End of namespace Ultima8
98 } // End of namespace Ultima
99 
100 #endif
101