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/ultima1/u1gfx/sprites.h"
24 #include "ultima/shared/early/ultima_early.h"
25 #include "ultima/shared/early/game.h"
26 
27 namespace Ultima {
28 namespace Ultima1 {
29 namespace U1Gfx {
30 
BEGIN_MESSAGE_MAP(Sprites,Shared::TreeItem)31 BEGIN_MESSAGE_MAP(Sprites, Shared::TreeItem)
32 	ON_MESSAGE(FrameMsg)
33 END_MESSAGE_MAP()
34 
35 #define ANIMATE_FRAME_DELAY 200
36 
37 void Sprites::load(bool isOverworld) {
38 	_isOverworld = isOverworld;
39 
40 	if (isOverworld)
41 		Shared::Gfx::Sprites::load("t1ktiles.bin", 4);
42 	else
43 		Shared::Gfx::Sprites::load("t1ktown.bin", 4, 8, 8);
44 }
45 
FrameMsg(CFrameMsg * msg)46 bool Sprites::FrameMsg(CFrameMsg *msg) {
47 	if (!empty() && _isOverworld) {
48 		animateWater();
49 	}
50 
51 	++_frameCtr;
52 
53 	return false;
54 }
55 
animateWater()56 void Sprites::animateWater() {
57 	byte lineBuffer[16];
58 	Shared::Gfx::Sprite &sprite = (*this)[0];
59 
60 	Common::copy(sprite.getBasePtr(0, 15), sprite.getBasePtr(0, 16), lineBuffer);
61 	Common::copy_backward(sprite.getBasePtr(0, 0), sprite.getBasePtr(0, 15), sprite.getBasePtr(0, 16));
62 	Common::copy(lineBuffer, lineBuffer + 16, sprite.getBasePtr(0, 0));
63 }
64 
operator [](uint idx)65 Shared::Gfx::Sprite &Sprites::operator[](uint idx) {
66 	int offset = 2;
67 	if ((_frameCtr % 6) == 0)
68 		offset = 0;
69 	else if ((_frameCtr % 3) == 0)
70 		offset = 1;
71 
72 	if (!_isOverworld) {
73 		// Don't do overworld tile animations within the cities and castles
74 		return Shared::Gfx::Sprites::operator[](idx);
75 	} else if (idx == 4 && offset != 2) {
76 		// Castle flag waving
77 		return Shared::Gfx::Sprites::operator[](4 + offset);
78 	} else if (idx == 6) {
79 		// City flag waving
80 		return Shared::Gfx::Sprites::operator[](7 + ((_frameCtr & 3) ? 1 : 0));
81 	} else {
82 		if (idx >= 7 && idx < 50)
83 			idx += 2;
84 
85 		if (idx == 14 || idx == 25) {
86 			// Transports
87 			return Shared::Gfx::Sprites::operator[](idx + (_frameCtr & 1));
88 		} else if (idx >= 19 && idx <= 47) {
89 			// Random monster animation
90 			return Shared::Gfx::Sprites::operator[](idx + (g_vm->getRandomNumber(1, 100) & 1));
91 		} else {
92 			return Shared::Gfx::Sprites::operator[](idx);
93 		}
94 	}
95 }
96 
97 } // End of namespace U1Gfx
98 } // End of namespace Ultima1
99 } // End of namespace Ultima
100