~ubuntu-branches/debian/jessie/scummvm/jessie

« back to all changes in this revision

Viewing changes to engines/kyra/kyra_hof.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Moritz Muehlenhoff
  • Date: 2011-05-25 19:02:23 UTC
  • mto: This revision was merged to the branch mainline in revision 23.
  • Revision ID: james.westby@ubuntu.com-20110525190223-fiqm0oaec714xk31
Tags: upstream-1.3.0
ImportĀ upstreamĀ versionĀ 1.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 * along with this program; if not, write to the Free Software
19
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
20
 *
21
 
 * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/tags/release-1-2-1/engines/kyra/kyra_hof.cpp $
22
 
 * $Id: kyra_hof.cpp 51757 2010-08-05 14:41:00Z lordhoto $
 
21
 * $URL$
 
22
 * $Id$
23
23
 *
24
24
 */
25
25
 
26
 
#include "kyra/kyra_v1.h"
27
26
#include "kyra/kyra_hof.h"
28
 
#include "kyra/screen.h"
29
27
#include "kyra/resource.h"
30
 
#include "kyra/wsamovie.h"
31
 
#include "kyra/sound.h"
32
 
#include "kyra/script.h"
33
 
#include "kyra/script_tim.h"
34
28
#include "kyra/text_hof.h"
35
29
#include "kyra/timer.h"
36
30
#include "kyra/debugger.h"
37
31
#include "kyra/util.h"
 
32
#include "kyra/sound.h"
38
33
 
39
34
#include "common/system.h"
40
35
#include "common/config-manager.h"
74
69
        _mainCharX = _mainCharY = -1;
75
70
        _drawNoShapeFlag = false;
76
71
        _charPalEntry = 0;
77
 
        _itemInHand = -1;
 
72
        _itemInHand = kItemNone;
78
73
        _unkSceneScreenFlag1 = false;
79
74
        _noScriptEnter = true;
80
75
        _currentChapter = 0;
87
82
        _pathfinderFlag = 0;
88
83
        _mouseX = _mouseY = 0;
89
84
 
 
85
        _nextIdleAnim = 0;
90
86
        _lastIdleScript = -1;
 
87
        _useSceneIdleAnim = false;
91
88
 
92
89
        _currentTalkSections.STATim = 0;
93
90
        _currentTalkSections.TLKTim = 0;
145
142
        _menu = 0;
146
143
        _chatIsNote = false;
147
144
        memset(&_npcScriptData, 0, sizeof(_npcScriptData));
 
145
 
 
146
        _setCharPalFinal = false;
 
147
        _useCharPal = false;
 
148
 
 
149
        memset(_characterFacingCountTable, 0, sizeof(_characterFacingCountTable));
148
150
}
149
151
 
150
152
KyraEngine_HoF::~KyraEngine_HoF() {
441
443
        if (_gameToLoad == -1) {
442
444
                snd_playWanderScoreViaMap(52, 1);
443
445
                enterNewScene(_mainCharacter.sceneId, _mainCharacter.facing, 0, 0, 1);
444
 
                saveGameState(0, "New Game", 0);
 
446
                saveGameStateIntern(0, "New Game", 0);
445
447
        } else {
446
448
                loadGameStateCheck(_gameToLoad);
447
449
        }
504
506
                int inputFlag = checkInput(_buttonList, true);
505
507
                removeInputTop();
506
508
 
 
509
                if (_updateHandItemCursor) {
 
510
                        // This works around an issue which would occur when setHandItem(_itemInHand)
 
511
                        // was called from inside loadGameState(). When loading via GMM the
 
512
                        // mouse cursor would not be set correctly.
 
513
                        _updateHandItemCursor = false;
 
514
                        setHandItem(_itemInHand);
 
515
                }
 
516
 
507
517
                update();
508
518
 
509
519
                if (inputFlag == 198 || inputFlag == 199) {
510
 
                        _unk3 = _mouseState;
 
520
                        _savedMouseState = _mouseState;
511
521
                        handleInput(_mouseX, _mouseY);
512
522
                }
513
523
 
528
538
        if (!_screen->isMouseVisible())
529
539
                return;
530
540
 
531
 
        if (_unk3 == -2) {
 
541
        if (_savedMouseState == -2) {
532
542
                snd_playSoundEffect(13);
533
543
                return;
534
544
        }
537
547
 
538
548
        if (x <= 6 || x >= 312 || y <= 6 || y >= 135) {
539
549
                bool exitOk = false;
540
 
                assert(_unk3 + 6 >= 0);
541
 
                switch (_unk3 + 6) {
 
550
                assert(_savedMouseState + 6 >= 0);
 
551
                switch (_savedMouseState + 6) {
542
552
                case 0:
543
553
                        if (_sceneExit1 != 0xFFFF)
544
554
                                exitOk = true;
569
579
                }
570
580
        }
571
581
 
572
 
        if (checkCharCollision(x, y) && _unk3 >= -1) {
 
582
        if (checkCharCollision(x, y) && _savedMouseState >= -1) {
573
583
                runSceneScript2();
574
584
                return;
575
585
        } else if (pickUpItem(x, y)) {
609
619
 
610
620
                        dropItem(0, _itemInHand, x, y, 1);
611
621
                } else {
612
 
                        if (_unk3 == -2 || y > 135)
 
622
                        if (_savedMouseState == -2 || y > 135)
613
623
                                return;
614
624
 
615
625
                        if (!_unk5) {
790
800
                if ((mouse.y > 145) || (mouse.x > 6 && mouse.x < 312 && mouse.y > 6 && mouse.y < 135)) {
791
801
                        _mouseState = _itemInHand;
792
802
                        _screen->hideMouse();
793
 
                        if (_itemInHand == -1)
 
803
                        if (_itemInHand == kItemNone)
794
804
                                _screen->setMouseCursor(0, 0, getShapePtr(0));
795
805
                        else
796
806
                                _screen->setMouseCursor(8, 15, getShapePtr(_itemInHand+64));
1127
1137
}
1128
1138
 
1129
1139
void KyraEngine_HoF::updateCharPal(int unk1) {
1130
 
        static bool unkVar1 = false;
1131
 
 
1132
1140
        if (!_useCharPal)
1133
1141
                return;
1134
1142
 
1144
1152
                        ++src;
1145
1153
                }
1146
1154
                _screen->setScreenPalette(_screen->getPalette(0));
1147
 
                unkVar1 = true;
 
1155
                _setCharPalFinal = true;
1148
1156
                _charPalEntry = palEntry;
1149
 
        } else if (unkVar1 || !unk1) {
 
1157
        } else if (_setCharPalFinal || !unk1) {
1150
1158
                _screen->getPalette(0).copy(_scenePal, palEntry << 4, 16, 112);
1151
1159
                _screen->setScreenPalette(_screen->getPalette(0));
1152
 
                unkVar1 = false;
 
1160
                _setCharPalFinal = false;
1153
1161
        }
1154
1162
}
1155
1163
 
1169
1177
        _pathfinderFlag = 15;
1170
1178
 
1171
1179
        if (!_unkHandleSceneChangeFlag) {
1172
 
                if (_unk3 == -3) {
 
1180
                if (_savedMouseState == -3) {
1173
1181
                        if (_sceneList[curScene].exit4 != 0xFFFF) {
1174
1182
                                x = 4;
1175
1183
                                y = _sceneEnterY4;
1176
1184
                                _pathfinderFlag = 7;
1177
1185
                        }
1178
 
                } else if (_unk3 == -5) {
 
1186
                } else if (_savedMouseState == -5) {
1179
1187
                        if (_sceneList[curScene].exit2 != 0xFFFF) {
1180
1188
                                x = 316;
1181
1189
                                y = _sceneEnterY2;
1182
1190
                                _pathfinderFlag = 7;
1183
1191
                        }
1184
 
                } else if (_unk3 == -6) {
 
1192
                } else if (_savedMouseState == -6) {
1185
1193
                        if (_sceneList[curScene].exit1 != 0xFFFF) {
1186
1194
                                x = _sceneEnterX1;
1187
1195
                                y = _sceneEnterY1 - 2;
1188
1196
                                _pathfinderFlag = 14;
1189
1197
                        }
1190
 
                } else if (_unk3 == -4) {
 
1198
                } else if (_savedMouseState == -4) {
1191
1199
                        if (_sceneList[curScene].exit3 != 0xFFFF) {
1192
1200
                                x = _sceneEnterX3;
1193
1201
                                y = 147;
1200
1208
        int vocH = _flags.isTalkie ? 131 : -1;
1201
1209
 
1202
1210
        if (_pathfinderFlag) {
1203
 
                if (findItem(curScene, 13) >= 0 && _unk3 <= -3) {
 
1211
                if (findItem(curScene, 13) >= 0 && _savedMouseState <= -3) {
1204
1212
                        strId = 252;
1205
1213
                } else if (_itemInHand == 72) {
1206
1214
                        strId = 257;
1207
 
                } else if (findItem(curScene, 72) >= 0 && _unk3 <= -3) {
 
1215
                } else if (findItem(curScene, 72) >= 0 && _savedMouseState <= -3) {
1208
1216
                        strId = 256;
1209
 
                } else if (getInventoryItemSlot(72) != -1 && _unk3 <= -3) {
 
1217
                } else if (getInventoryItemSlot(72) != -1 && _savedMouseState <= -3) {
1210
1218
                        strId = 257;
1211
1219
                }
1212
1220
        }
1266
1274
        return _timer->getDelay(0);
1267
1275
}
1268
1276
 
1269
 
void KyraEngine_HoF::updateCharAnimFrame(int charId, int *table) {
1270
 
        static int unkTable1[] = { 0, 0 };
1271
 
        static const int unkTable2[] = { 17, 0 };
1272
 
        static const int unkTable3[] = { 10, 0 };
1273
 
        static const int unkTable4[] = { 24, 0 };
1274
 
        static const int unkTable5[] = { 19, 0 };
1275
 
        static const int unkTable6[] = { 21, 0 };
1276
 
        static const int unkTable7[] = { 31, 0 };
1277
 
        static const int unkTable8[] = { 26, 0 };
 
1277
void KyraEngine_HoF::updateCharAnimFrame(int *table) {
 
1278
        static const int unkFrame1 = 17;
 
1279
        static const int unkFrame2 = 10;
 
1280
        static const int unkFrame3 = 24;
 
1281
        static const int unkFrame4 = 19;
 
1282
        static const int unkFrame5 = 21;
 
1283
        static const int unkFrame6 = 31;
 
1284
        static const int unkFrame7 = 26;
1278
1285
 
1279
1286
        Character *character = &_mainCharacter;
1280
1287
        ++character->animFrame;
1289
1296
        }
1290
1297
 
1291
1298
        if (!facing) {
1292
 
                ++unkTable1[charId];
 
1299
                ++_characterFacingCountTable[0];
1293
1300
        } else if (facing == 4) {
1294
 
                ++unkTable1[charId+1];
 
1301
                ++_characterFacingCountTable[1];
1295
1302
        } else if (facing == 7 || facing == 1 || facing == 5 || facing == 3) {
1296
1303
                if (facing == 7 || facing == 1) {
1297
 
                        if (unkTable1[charId] > 2)
 
1304
                        if (_characterFacingCountTable[0] > 2)
1298
1305
                                facing = 0;
1299
1306
                } else {
1300
 
                        if (unkTable1[charId+1] > 2)
 
1307
                        if (_characterFacingCountTable[1] > 2)
1301
1308
                                facing = 4;
1302
1309
                }
1303
1310
 
1304
 
                unkTable1[charId] = 0;
1305
 
                unkTable1[charId+1] = 0;
 
1311
                _characterFacingCountTable[0] = 0;
 
1312
                _characterFacingCountTable[1] = 0;
1306
1313
        }
1307
1314
 
1308
1315
        if (facing == 0) {
1309
 
                if (character->animFrame < unkTable8[charId])
1310
 
                        character->animFrame = unkTable8[charId];
 
1316
                if (character->animFrame < unkFrame7)
 
1317
                        character->animFrame = unkFrame7;
1311
1318
 
1312
 
                if (character->animFrame > unkTable7[charId])
1313
 
                        character->animFrame = unkTable8[charId];
 
1319
                if (character->animFrame > unkFrame6)
 
1320
                        character->animFrame = unkFrame7;
1314
1321
        } else if (facing == 4) {
1315
 
                if (character->animFrame < unkTable5[charId])
1316
 
                        character->animFrame = unkTable5[charId];
 
1322
                if (character->animFrame < unkFrame4)
 
1323
                        character->animFrame = unkFrame4;
1317
1324
 
1318
 
                if (character->animFrame > unkTable4[charId])
1319
 
                        character->animFrame = unkTable5[charId];
 
1325
                if (character->animFrame > unkFrame3)
 
1326
                        character->animFrame = unkFrame4;
1320
1327
        } else {
1321
 
                if (character->animFrame > unkTable5[charId])
1322
 
                        character->animFrame = unkTable6[charId];
1323
 
 
1324
 
                if (character->animFrame == unkTable2[charId])
1325
 
                        character->animFrame = unkTable3[charId];
1326
 
 
1327
 
                if (character->animFrame > unkTable2[charId])
1328
 
                        character->animFrame = unkTable3[charId] + 2;
 
1328
                if (character->animFrame > unkFrame4)
 
1329
                        character->animFrame = unkFrame5;
 
1330
 
 
1331
                if (character->animFrame == unkFrame1)
 
1332
                        character->animFrame = unkFrame2;
 
1333
 
 
1334
                if (character->animFrame > unkFrame1)
 
1335
                        character->animFrame = unkFrame2 + 2;
1329
1336
        }
1330
1337
 
1331
 
        updateCharacterAnim(charId);
 
1338
        updateCharacterAnim(0);
1332
1339
}
1333
1340
 
1334
1341
bool KyraEngine_HoF::checkCharCollision(int x, int y) {
1385
1392
        if (queryGameFlag(0x159) && _flags.isTalkie)
1386
1393
                return;
1387
1394
 
1388
 
        static bool scriptAnimation = false;
1389
 
        if (!scriptAnimation && _flags.isTalkie) {
1390
 
                scriptAnimation = true;
 
1395
        if (!_useSceneIdleAnim && _flags.isTalkie) {
 
1396
                _useSceneIdleAnim = true;
1391
1397
                randomSceneChat();
1392
1398
        } else {
1393
 
                scriptAnimation = false;
 
1399
                _useSceneIdleAnim = false;
1394
1400
                if (_characterShapeFile > 8)
1395
1401
                        return;
1396
1402