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 #include "ultima/ultima8/misc/pent_include.h"
24
25 #include "ultima/ultima8/graphics/wpn_ovlay_dat.h"
26
27 #include "ultima/ultima8/world/actors/weapon_overlay.h"
28 #include "ultima/ultima8/filesys/raw_archive.h"
29 #include "ultima/ultima8/games/game_data.h"
30 #include "ultima/ultima8/graphics/main_shape_archive.h"
31 #include "ultima/ultima8/world/actors/anim_action.h"
32
33 namespace Ultima {
34 namespace Ultima8 {
35
WpnOvlayDat()36 WpnOvlayDat::WpnOvlayDat() {
37 }
38
~WpnOvlayDat()39 WpnOvlayDat::~WpnOvlayDat() {
40 for (unsigned int i = 0; i < _overlay.size(); i++)
41 delete _overlay[i];
42 }
43
getOverlayFrame(uint32 action,int type,Direction direction,int frame) const44 const WeaponOverlayFrame *WpnOvlayDat::getOverlayFrame(uint32 action, int type,
45 Direction direction,
46 int frame) const {
47 if (action >= _overlay.size())
48 return nullptr;
49 if (!_overlay[action])
50 return nullptr;
51 return _overlay[action]->getFrame(type, direction, frame);
52 }
53
54
load(RawArchive * overlaydat)55 void WpnOvlayDat::load(RawArchive *overlaydat) {
56 MainShapeArchive *msf = GameData::get_instance()->getMainShapes();
57 assert(msf);
58
59 _overlay.resize(overlaydat->getCount());
60
61 for (unsigned int action = 0; action < _overlay.size(); action++) {
62 Common::SeekableReadStream *rs = overlaydat->get_datasource(action);
63 _overlay[action] = nullptr;
64
65 if (rs && rs->size()) {
66 // get Avatar's animation
67 const AnimAction *anim = msf->getAnim(1, action);
68 if (!anim) {
69 perr << "Skipping wpnovlay action " << action << " because avatar animation doesn't exist." << Std::endl;
70 continue;
71 }
72
73 AnimWeaponOverlay *awo = new AnimWeaponOverlay;
74 _overlay[action] = awo;
75
76 unsigned int animlength = anim->getSize();
77 unsigned int dircount = anim->getDirCount();
78
79 unsigned int typecount = rs->size() / (4 * dircount * animlength);
80 awo->_overlay.resize(typecount);
81
82 for (unsigned int type = 0; type < typecount; type++) {
83 awo->_overlay[type]._dirCount = dircount;
84 awo->_overlay[type]._frames =
85 new Std::vector<WeaponOverlayFrame>[dircount];
86 for (unsigned int dir = 0; dir < dircount; dir++) {
87 awo->_overlay[type]._frames[dir].resize(animlength);
88 for (unsigned int frame = 0; frame < animlength; frame++) {
89 WeaponOverlayFrame f;
90 f._xOff = rs->readSByte();
91 f._yOff = rs->readSByte();
92 f._frame = rs->readUint16LE();
93
94 awo->_overlay[type]._frames[dir][frame] = f;
95 }
96 }
97 }
98 }
99
100 delete rs;
101 }
102 }
103
104 } // End of namespace Ultima8
105 } // End of namespace Ultima
106