ScummVM
animator_mr.cpp
Go to the documentation of this file.
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 "kyra/engine/kyra_mr.h"
24 #include "kyra/resource/resource.h"
25 #include "kyra/graphics/wsamovie.h"
26 
27 #include "common/system.h"
28 
29 namespace Kyra {
30 
32  screen()->copyBlockToPage(2, 0, 0, 320, 200, _gamePlayBuffer);
33 }
34 
36  for (int i = 0; i < 67; ++i)
37  _animObjects[i].enabled = false;
38 
39  _animObjects[0].index = 0;
40  _animObjects[0].type = 0;
41  _animObjects[0].enabled = true;
43  _animObjects[0].flags = 0x800;
44  _animObjects[0].width = 57;
45  _animObjects[0].height = 91;
46  _animObjects[0].width2 = 4;
47  _animObjects[0].height2 = 10;
48 
49  for (int i = 1; i < 17; ++i) {
50  _animObjects[i].index = i;
51  _animObjects[i].type = 2;
52  _animObjects[i].flags = 0;
53  _animObjects[i].enabled = false;
56  }
57 
58  for (int i = 17; i <= 66; ++i) {
59  _animObjects[i].index = i;
60  _animObjects[i].type = 1;
62  _animObjects[i].flags = 0x800;
63  _animObjects[i].width = 24;
64  _animObjects[i].height = 20;
65  _animObjects[i].width2 = 0;
66  _animObjects[i].height2 = 0;
67  }
68 }
69 
71  int layer = _screen->getLayer(anim->xPos1, anim->yPos1) - 1;
72  int16 count = 0;
73  for (int i = 0; i < 3; ++i)
74  count += _sceneDatPalette[layer*3+i];
75  count /= 3;
76  count *= -1;
77  count = MAX<int16>(0, MIN<int16>(count, 10));
78  anim->palette = count / 3;
79 }
80 
82  for (AnimObj *curObject = _animList; curObject; curObject = curObject->nextObject) {
83  if (!curObject->enabled)
84  continue;
85 
86  int x = curObject->xPos2 - (_screen->getScreenDim(2)->sx << 3);
87  int y = curObject->yPos2 - _screen->getScreenDim(2)->sy;
88  int layer = 7;
89 
90  if (curObject->flags & 0x800) {
91  if (!curObject->specialRefresh)
92  layer = 0;
93  else
94  layer = getDrawLayer(curObject->xPos1, curObject->yPos1);
95  }
96 
97  if (curObject->index)
98  drawSceneAnimObject(curObject, x, y, layer);
99  else
100  drawCharacterAnimObject(curObject, x, y, layer);
101  }
102 }
103 
104 void KyraEngine_MR::drawSceneAnimObject(AnimObj *obj, int x, int y, int layer) {
105  if (obj->type == 1) {
106  if (obj->shapeIndex1 == 0xFFFF)
107  return;
108  int scale = getScale(obj->xPos1, obj->yPos1);
109  _screen->drawShape(2, getShapePtr(obj->shapeIndex1), x, y, 2, obj->flags | 0x104, _paletteOverlay, obj->palette, layer, scale, scale);
110  } else {
111  if (obj->shapePtr) {
112  _screen->drawShape(2, obj->shapePtr, x, y, 2, obj->flags, 7);
113  } else {
114  if (obj->shapeIndex3 == 0xFFFF || obj->animNum == 0xFFFF)
115  return;
116  uint16 flags = 0x4000;
117  if (obj->flags & 0x800)
118  flags |= 0x8000;
119  x = obj->xPos2 - _sceneAnimMovie[obj->animNum]->xAdd();
120  y = obj->yPos2 - _sceneAnimMovie[obj->animNum]->yAdd();
121  _sceneAnimMovie[obj->animNum]->displayFrame(obj->shapeIndex3, 2, x, y, flags | layer, 0, 0);
122  }
123  }
124 }
125 
126 void KyraEngine_MR::drawCharacterAnimObject(AnimObj *obj, int x, int y, int layer) {
127  if (_drawNoShapeFlag)
128  return;
129 
130  if (_mainCharacter.animFrame < 9)
132 
133  if (obj->shapeIndex1 == 0xFFFF || _mainCharacter.animFrame == 87)
134  return;
135 
138  if (shape)
139  _screen->drawShape(2, shape, x, y, 2, obj->flags | 4, layer, _charScale, _charScale);
140 }
141 
143  for (AnimObj *curObject = _animList; curObject; curObject = curObject->nextObject) {
144  if (!curObject->enabled)
145  continue;
146  if (!curObject->needRefresh && !force)
147  continue;
148 
149  const int scale = (curObject->index == 0) ? _charScale : 0;
150 
151  int x = curObject->xPos2 - curObject->width2;
152  if (scale)
153  x -= (0x100 - scale) >> 4;
154 
155  if (x < 0)
156  x = 0;
157  if (x >= 320)
158  x = 319;
159 
160  int y = curObject->yPos2 - curObject->height2;
161  if (scale)
162  y -= (0x100 - scale) >> 3;
163  if (y < 0)
164  y = 0;
165  if (y >= 187)
166  y = 186;
167 
168  int width = curObject->width + curObject->width2 + 8;
169  int height = curObject->height + curObject->height2*2;
170  if (width + x > 320)
171  width -= width + x - 322;
172 
173  const int maxY = _inventoryState ? 143 : 187;
174  if (height + y > maxY)
175  height -= height + y - (maxY + 1);
176 
177  if (height > 0) {
178  _screen->copyRegion(x, y, x, y, width, height, 2, 0, Screen::CR_NO_P_CHECK);
179  }
180 
181  curObject->needRefresh = false;
182  }
183 }
184 
186  bool nextFrame = false;
187 
188  if (_itemAnimDefinition[0].itemIndex == -1)
189  return;
190 
193  _nextAnimItem = (_nextAnimItem + 1) % 10;
194 
195  if (_system->getMillis() < a->nextFrameTime)
196  return;
197 
198  uint16 shpIdx = s->frames[a->currentFrame].index + 248;
200  nextFrame = true;
201  _screen->setMouseCursor(12, 19, getShapePtr(shpIdx));
202  }
203 
204  if (_inventoryState) {
205  for (int i = 0; i < 10; i++) {
206  if (s->itemIndex == _mainCharacter.inventory[i]) {
207  nextFrame = true;
208  _screen->drawShape(2, getShapePtr(422 + i), 9, 0, 0, 0);
209  _screen->drawShape(2, getShapePtr(shpIdx), 9, 0, 0, 0);
210  _screen->copyRegion(9, 0, _inventoryX[i], _inventoryY[i], 24, 20, 2, 0, Screen::CR_NO_P_CHECK);
211  }
212  }
213  }
214 
216 
217  for (int i = 17; i < 66; i++) {
218  AnimObj *animObject = &_animObjects[i];
219  if (animObject->shapeIndex2 == s->itemIndex + 248) {
220  animObject->shapePtr = getShapePtr(shpIdx);
221  animObject->shapeIndex1 = shpIdx;
222  animObject->needRefresh = true;
223  nextFrame = true;
224  }
225  }
226 
227  if (nextFrame) {
229  a->currentFrame = (a->currentFrame + 1) % s->numFrames;
230  }
231 }
232 
234  AnimObj *obj = &_animObjects[0];
235  obj->needRefresh = true;
236  obj->flags &= ~1;
237  obj->xPos1 = _mainCharacter.x1;
238  obj->yPos1 = _mainCharacter.y1;
241 
242  int shapeOffsetX = 0, shapeOffsetY = 0;
243  if (_mainCharacter.animFrame >= 50 && _mainCharacter.animFrame <= 87) {
244  shapeOffsetX = _malcolmShapeXOffset;
245  shapeOffsetY = _malcolmShapeYOffset;
246  } else {
247  shapeOffsetX = _animShapeXAdd;
248  shapeOffsetY = _animShapeYAdd;
249  }
250 
251  obj->xPos2 = _mainCharacter.x1;
252  obj->yPos2 = _mainCharacter.y1;
254  obj->xPos2 += (shapeOffsetX * _charScale) >> 8;
255  obj->yPos2 += (shapeOffsetY * _charScale) >> 8;
258  if (_charBackUpWidth2 == -1) {
259  obj->width2 = 4;
260  obj->height2 = 10;
261  }
262 
263  for (int i = 1; i <= 16; ++i) {
264  if (_animObjects[i].enabled && _animObjects[i].specialRefresh)
265  _animObjects[i].needRefresh = true;
266  }
267 
269  if (_animList)
271  else
273 
274  if (!_loadingState)
275  updateCharPal(1);
276 }
277 
279  AnimObj *animObject = &_animObjects[1+anim];
280  if (!animObject->enabled)
281  return;
282 
283  animObject->needRefresh = true;
284 
285  if (_sceneAnims[anim].flags & 2)
286  animObject->flags |= 1;
287  else
288  animObject->flags &= ~1;
289 
290  if (_sceneAnims[anim].flags & 4) {
291  animObject->shapePtr = _sceneShapes[newFrame];
292  animObject->shapeIndex2 = 0xFFFF;
293  animObject->shapeIndex3 = 0xFFFF;
294  animObject->animNum = 0xFFFF;
295  } else {
296  animObject->shapePtr = 0;
297  animObject->shapeIndex3 = newFrame;
298  animObject->animNum = anim;
299  }
300 
301  animObject->xPos1 = _sceneAnims[anim].x;
302  animObject->yPos1 = _sceneAnims[anim].y;
303  animObject->xPos2 = _sceneAnims[anim].x2;
304  animObject->yPos2 = _sceneAnims[anim].y2;
305 
306  if (_sceneAnims[anim].flags & 0x20) {
307  _animList = deleteAnimListEntry(_animList, animObject);
308  if (!_animList)
309  _animList = initAnimList(_animList, animObject);
310  else
311  _animList = addToAnimListSorted(_animList, animObject);
312  }
313 }
314 
315 void KyraEngine_MR::setupSceneAnimObject(int animId, uint16 flags, int x, int y, int x2, int y2, int w,
316  int h, int unk10, int specialSize, int unk14, int shape, const char *filename) {
317  restorePage3();
318  SceneAnim &anim = _sceneAnims[animId];
319  anim.flags = flags;
320  anim.x = x;
321  anim.y = y;
322  anim.x2 = x2;
323  anim.y2 = y2;
324  anim.width = w;
325  anim.height = h;
326  anim.specialSize = specialSize;
327  anim.shapeIndex = shape;
328  if (filename)
329  strcpy(anim.filename, filename);
330 
331  if (flags & 8) {
332  _sceneAnimMovie[animId]->open(filename, 1, 0);
333  if (_sceneAnimMovie[animId]->opened()) {
334  anim.wsaFlag = 1;
335  if (x2 == -1)
336  x2 = _sceneAnimMovie[animId]->xAdd();
337  if (y2 == -1)
338  y2 = _sceneAnimMovie[animId]->yAdd();
339  if (w == -1)
340  w = _sceneAnimMovie[animId]->width();
341  if (h == -1)
342  h = _sceneAnimMovie[animId]->height();
343  if (x == -1)
344  x = (w >> 1) + x2;
345  if (y == -1)
346  y = y2 + h - 1;
347 
348  anim.x = x;
349  anim.y = y;
350  anim.x2 = x2;
351  anim.y2 = y2;
352  anim.width = w;
353  anim.height = h;
354  }
355  }
356 
357  AnimObj *obj = &_animObjects[1+animId];
358  obj->enabled = true;
359  obj->needRefresh = true;
360 
361  obj->specialRefresh = (anim.flags & 0x20) ? 1 : 0;
362  obj->flags = (anim.flags & 0x10) ? 0x800 : 0;
363  if (anim.flags & 2)
364  obj->flags |= 1;
365 
366  obj->xPos1 = anim.x;
367  obj->yPos1 = anim.y;
368 
369  if ((anim.flags & 4) && anim.shapeIndex != -1)
370  obj->shapePtr = _sceneShapes[anim.shapeIndex];
371  else
372  obj->shapePtr = 0;
373 
374  if (anim.flags & 8) {
375  obj->shapeIndex3 = anim.shapeIndex;
376  obj->animNum = animId;
377  } else {
378  obj->shapeIndex3 = 0xFFFF;
379  obj->animNum = 0xFFFF;
380  }
381 
382  obj->xPos3 = obj->xPos2 = anim.x2;
383  obj->yPos3 = obj->yPos2 = anim.y2;
384  obj->width = anim.width;
385  obj->height = anim.height;
386  obj->width2 = obj->height2 = anim.specialSize;
387 
388  if (_animList)
390  else
392 }
393 
394 void KyraEngine_MR::removeSceneAnimObject(int anim, int refresh) {
395  AnimObj *obj = &_animObjects[anim+1];
396  restorePage3();
397  obj->shapeIndex3 = 0xFFFF;
398  obj->animNum = 0xFFFF;
399  obj->needRefresh = true;
400 
401  if (refresh)
403 
404  obj->enabled = false;
406  _sceneAnimMovie[anim]->close();
407 }
408 
410  restorePage3();
415 
416  _animObjects[0].width2 = (w - _charBackUpWidth) / 2;
418  _animObjects[0].width = w;
419  _animObjects[0].height = h;
420 }
421 
423  restorePage3();
430 }
431 
433  if (_mainCharacter.sceneId == 20 || _mainCharacter.sceneId == 21
434  || _mainCharacter.sceneId == 12 || _mainCharacter.sceneId == 11)
435  return;
436 
437  if (_mainCharacter.animFrame == 87)
438  return;
439 
441  randomSceneChat();
442  } else {
443  static const char *const facingTable[] = {
444  "A", "R", "R", "FR", "FX", "FL", "L", "L"
445  };
446 
448 
449  if (_res->exists(filename.c_str()))
450  runAnimationScript(filename.c_str(), 1, 1, 1, 1);
451  }
452 
454 }
455 
456 } // End of namespace Kyra
int _malcolmShapeXOffset
Definition: kyra_mr.h:323
int _malcolmShapeYOffset
Definition: kyra_mr.h:323
Character _mainCharacter
Definition: kyra_v2.h:330
unsigned short uint16
Definition: cdtypes.h:27
uint8 * _gamePlayBuffer
Definition: kyra_mr.h:192
const ScreenDim * getScreenDim(int dim) const
Definition: screen.cpp:515
Simple string class for ScummVM.
Definition: str.h:49
uint8 * _paletteOverlay
Definition: kyra_mr.h:505
int width() const
Definition: wsamovie.h:66
AnimObj * _animList
Definition: kyra_v2.h:131
int count
Definition: voc.cpp:116
void drawCharacterAnimObject(AnimObj *obj, int x, int y, int drawLayer)
Screen * screen()
Definition: kyra_mr.h:55
Screen_MR * _screen
Definition: kyra_mr.h:82
AnimObj * initAnimList(AnimObj *list, AnimObj *entry)
Definition: animator_v2.cpp:39
bool isMouseVisible() const
Definition: screen.cpp:3048
u16 flags
Definition: zipreader.h:215
uint8 * getShapePtr(int index) const
Definition: kyra_v2.cpp:191
virtual void setMouseCursor(int x, int y, const byte *shape)
Definition: screen.cpp:3059
int y
Definition: dialogs.cpp:409
void randomSceneChat()
Definition: text_mr.cpp:830
unsigned char uint8
Definition: cdtypes.h:28
int open(const char *filename, int unk1, Palette *palette)
Definition: wsamovie.cpp:364
void setCharacterAnimDim(int w, int h)
void runAnimationScript(const char *filename, int allowSkip, int resetChar, int newShapes, int shapeUnload)
virtual void displayFrame(int frameNum, int pageNum, int x, int y, uint16 flags, const uint8 *table1, const uint8 *table2)
Definition: wsamovie.h:118
SceneAnim _sceneAnims[16]
Definition: kyra_v2.h:210
AnimObj * _animObjects
Definition: kyra_v2.h:124
AnimObj * deleteAnimListEntry(AnimObj *list, AnimObj *entry)
Definition: animator_v2.cpp:75
bool talkObjectsInCurScene()
Definition: kyra_mr.cpp:1278
uint16 height
Definition: thumbnail.cpp:41
int yAdd() const
Definition: wsamovie.h:123
void animSetupPaletteEntry(AnimObj *anim)
Definition: animator_mr.cpp:70
uint16 currentFrame
Definition: kyra_v2.h:48
Resource * _res
Definition: kyra_v1.h:264
void updateScreen()
Definition: screen.cpp:324
uint32 nextFrameTime
Definition: kyra_v2.h:49
uint16 sy
Definition: screen.h:50
OSystem * _system
Definition: engine.h:59
virtual uint32 getMillis(bool skipRecord=false)=0
Get the number of milliseconds since the program was started.
const char * c_str() const
Definition: str.h:208
bool exists(const char *file, bool errorOutOnFail=false)
Definition: resource.cpp:308
int getLayer(int x, int y)
Definition: screen_mr.cpp:35
int8 _sceneDatPalette[45]
Definition: kyra_mr.h:368
void copyRegion(int x1, int y1, int x2, int y2, int w, int h, int srcPage, int dstPage, int flags=0)
Definition: screen.cpp:1007
const FrameControl * frames
Definition: kyra_v2.h:44
void refreshAnimObjects(int force)
void setupSceneAnimObject(int anim, uint16 flags, int x, int y, int x2, int y2, int w, int h, int unk10, int specialSize, int unk14, int shape, const char *filename)
int getScale(int x, int y)
Definition: kyra_mr.cpp:1218
uint8 * _sceneShapes[20]
Definition: kyra_mr.h:333
Common::String filename
Definition: action.cpp:479
int getDrawLayer(int x, int y)
Definition: kyra_mr.cpp:1212
uint16 width
Definition: thumbnail.cpp:41
This is the namespace of the Kyra engine.
Definition: chargen.cpp:37
void updateSceneAnim(int anim, int newFrame)
uint16 sx
Definition: screen.h:49
uint16 _tickLength
Definition: kyra_v1.h:311
signed short int16
Definition: cdtypes.h:30
WSAMovie_v2 * _sceneAnimMovie[16]
Definition: kyra_v2.h:211
void refreshAnimObjectsIfNeed()
static const uint8 _inventoryY[]
Definition: kyra_mr.h:259
int xAdd() const
Definition: wsamovie.h:122
ActiveItemAnim _activeItemAnim[10]
Definition: kyra_mr.h:223
static const uint8 _inventoryX[]
Definition: kyra_mr.h:258
virtual void drawShape(uint8 pageNum, const uint8 *shapeData, int x, int y, int sd, int flags,...)
Definition: screen.cpp:1542
void drawSceneAnimObject(AnimObj *obj, int x, int y, int drawLayer)
static String format(const char *fmt,...) GCC_PRINTF(1
Print formatted data into a String object.
Definition: str.cpp:634
void newFrame(Stack theStack, Aint noOfLocals)
Definition: stack.cpp:111
const ItemAnimDefinition * _itemAnimDefinition
Definition: kyra_mr.h:222
void copyBlockToPage(int pageNum, int x, int y, int w, int h, const uint8 *src)
Definition: screen.cpp:1104
if(!yymsg) yymsg
virtual void close()
Definition: wsamovie.cpp:126
void removeSceneAnimObject(int anim, int refresh)
int height() const
Definition: wsamovie.h:67
void updateCharacterAnim(int charId)
AnimObj * addToAnimListSorted(AnimObj *list, AnimObj *entry)
Definition: animator_v2.cpp:44
void updateCharPal(int unk1)
Definition: kyra_mr.cpp:834