aboutsummaryrefslogtreecommitdiff
path: root/engines/parallaction/parallaction.cpp
blob: 0dcefc241c78c20fadf074a6eb6fda5a6160c493 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2006 The ScummVM project
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * $URL$
 * $Id$
 *
 */

#include "parallaction/parallaction.h"
#include "parallaction/menu.h"
#include "parallaction/disk.h"
#include "parallaction/music.h"
#include "parallaction/inventory.h"
#include "parallaction/graphics.h"
#include "parallaction/zone.h"

#include "common/util.h"
#include "common/file.h"


namespace Parallaction {

// FIXME: remove this
Parallaction *_vm = NULL;

// public stuff
Point	_mousePos = { 0, 0 };
uint16	_mouseButtons = 0;


char		_saveData1[30] = { '\0' };
uint16		_language = 0;
char		_location[100] = "fogne";
uint32		_engineFlags = 0;
char	   *_objectsNames[100];
Zone	   *_activeZone = NULL;
Animation	_yourself;
uint16		_score = 1;
Command    *_locationACommands = NULL;
Command    *_locationCommands = NULL;
char	   *_locationComment = NULL;
char	   *_locationEndComment = NULL;
uint32		_localFlags[120] = { 0 };

static char tmp_visited_str[] = "visited";

char *_localFlagNames[32] = {
	tmp_visited_str, // "visited",
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0
};

Command *	_forwardedCommands[20] = {
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL
};

char		_forwardedAnimationNames[20][20];
uint16		_numForwards = 0;
char		_soundFile[20];
char		_slideText[2][40];
Point		_firstPosition = { -1000, -1000 };
char		_newLocation[100];
char	   *_globalTable[32];
uint16		_firstFrame = 0;
Cnv 		_characterFace;
byte		_mouseHidden = 0;
Node		_locationWalkNodes = { 0, 0 };
uint32		_commandFlags = 0;
Cnv 		_tempFrames;
uint16		_introSarcData3 = 200;
uint16		_introSarcData2 = 1;

// private stuff




static Job	   *_jDrawInventory = NULL;
static Job	   *_jDrawLabel = NULL;
static Job	   *_jEraseLabel = NULL;
static Zone    *_hoverZone = NULL;
static Job	   *_jRunScripts = NULL;

static Cnv		_miniCharacterFrames;

static Job		_jobs = { { NULL, NULL }, 0, 0, 0, NULL, 0 };




Parallaction::Parallaction(OSystem *syst) :
	Engine(syst) {

	// FIXME
	_vm = this;

	_skipMenu = false;

	_transCurrentHoverItem = 0;
	_actionAfterWalk = false;  // actived when the character needs to move before taking an action
	_activeItem._index = 0;
	_activeItem._id = 0;
	_procCurrentHoverItem = -1;

	_musicData1 = 0;
	strcpy(_characterName1, "null");


	_baseTime = 0;

	Common::File::addDefaultDirectory( _gameDataPath );

/*    Common::addSpecialDebugLevel(kDebugAnimation, "Animation", "Animations debug level");
    Common::addSpecialDebugLevel(kDebugZone, "Zone", "Zones debug level");
    Common::addSpecialDebugLevel(kDebugCommand, "Command", "Commands debug level");
    Common::addSpecialDebugLevel(kDebugDialogue, "Dialogue", "Dialogues debug level");
    Common::addSpecialDebugLevel(kDebugIntro, "Intro", "Intro debug level");
    Common::addSpecialDebugLevel(kDebugInventory, "Inventory", "Inventory debug level");
    Common::addSpecialDebugLevel(kDebugLocation, "Location", "Locations debug level");
*/
    Common::addSpecialDebugLevel(kDebugDisk, "Disk", "Disk debug level");
    Common::addSpecialDebugLevel(kDebugWalk, "Walk", "Walk debug level");
}


Parallaction::~Parallaction() {

}


int Parallaction::init() {

	// Detect game
	if (!detectGame()) {
		GUIErrorMessage("No valid games were found in the specified directory.");
		return -1;
	}

//	strcpy(_location, "night");
//	strcpy(_characterName, "drki");
//	strcpy(_languageDir, "it/");
//	_skipMenu = true;

	_engineFlags = 0;

	strcpy(_characterName, "dough");
	memset(_locationNames, 0, 120*32);
	_numLocations = 0;




	_yourself._zone.pos._position._x = 150;
	_yourself._zone.pos._position._y = 100;
	initInventory();
	_yourself._z = 10;

	_yourself._zone.pos._oldposition._x = -1000;
	_yourself._zone.pos._oldposition._y = -1000;
	_yourself._frame = 0;

	_yourself._zone._flags = kFlagsActive | kFlagsNoName;
	_yourself._zone._type = kZoneYou;

	_yourself._zone._label._data0 = NULL;
	_yourself._zone._name = strdup("yourself");

	addNode(&_animations, &_yourself._zone._node);
	_graphics = new Graphics(this);


	return 0;
}





int Parallaction::go() {

	initGame();
	runGame();

	return 0;
}

void Parallaction::initGame() {

	_menu = new Menu(this);

	initGlobals();
	if (_skipMenu == false) {
		_menu->start();
	}

	char *v4 = strchr(_location, '.');
	if (v4) {
		*v4 = '\0';
	}

	_engineFlags &= ~kEngineChangeLocation;
	changeCharacter(_characterName);

	strcpy(_saveData1, _location);
	parseLocation(_location);

	if (_firstPosition._x != -1000) {
		_yourself._zone.pos._position._x = _firstPosition._x;
		_yourself._zone.pos._position._y = _firstPosition._y;
		_yourself._frame = _firstFrame;
		_firstPosition._y = -1000;
		_firstPosition._x = -1000;
	}

	return;
}

void Parallaction::initGlobals() {

	initTable("global.tab", _globalTable);
}

//
//	broken input management
//
uint16 Parallaction::updateInput() {

	OSystem::Event e;
	uint16 KeyDown = 0;

	_mouseButtons = kMouseNone;

	while (g_system->pollEvent(e)) {

		switch (e.type) {
		case OSystem::EVENT_KEYDOWN:
			if (e.kbd.ascii == ' ') KeyDown = kEvQuitGame;
			if (e.kbd.ascii == 'l') KeyDown = kEvLoadGame;
			if (e.kbd.ascii == 's') KeyDown = kEvSaveGame;
			break;

		case OSystem::EVENT_LBUTTONDOWN:
			_mouseButtons = kMouseLeftDown;
			break;

		case OSystem::EVENT_LBUTTONUP:
			_mouseButtons = kMouseLeftUp;
			break;

		case OSystem::EVENT_RBUTTONDOWN:
			_mouseButtons = kMouseRightDown;
			break;

		case OSystem::EVENT_RBUTTONUP:
			_mouseButtons = kMouseRightUp;
			break;

		case OSystem::EVENT_MOUSEMOVE:
			_mousePos._x = e.mouse.x;
			_mousePos._y = e.mouse.y;
			break;

		case OSystem::EVENT_QUIT:
			_engineFlags |= kEngineQuit;
			break;

		default:
			break;

		}

	}

	return KeyDown;

}


void waitUntilLeftClick() {

	OSystem::Event e;

	for (;;) {
		g_system->pollEvent(e);
		g_system->delayMillis(10);
		if (e.type == OSystem::EVENT_LBUTTONUP)
			break;

		if (e.type == OSystem::EVENT_QUIT) {
			_engineFlags |= kEngineQuit;
			break;
		}
	}


	return;
}


void Parallaction::runGame() {
//	printf("runGame()\n");

	addJob(jobEraseAnimations, (void*)1, JOBPRIORITY_RUNSTUFF);
	_jRunScripts = addJob(jobRunScripts, 0, JOBPRIORITY_RUNSTUFF);
	addJob(jobDisplayAnimations, 0, JOBPRIORITY_DRAWANIMATIONS);

	_graphics->copyScreen(Graphics::kBitBack, Graphics::kBit2);

	if (_locationCommands)
		runCommands(_locationCommands);

	runJobs();

	_graphics->copyScreen(Graphics::kBitBack, Graphics::kBitFront);

	if (_locationComment)
		doLocationEnterTransition();

	changeCursor(kCursorArrow);

	if (_locationACommands)
		runCommands(_locationACommands);

//	printf("entering game loop...\n");

	while ((_engineFlags & kEngineQuit) == 0) {
		_keyDown = updateInput();

		if ((_mouseHidden == 0) && ((_engineFlags & kEngineMouse) == 0) && ((_engineFlags & kEngineWalking) == 0)) {
			InputData *v8 = translateInput();
			if (v8) processInput(v8);
		}

		if (_activeZone) {
			Zone *z = _activeZone;	// speak Zone or sound
			_activeZone = NULL;
			if (runZone( z ) == 0)
				runCommands( z->_commands, z );
		}

		if (_engineFlags & kEngineChangeLocation) {
			_engineFlags &= ~kEngineChangeLocation;
			changeLocation(_location);
			continue;
		}

		g_system->delayMillis(30);

//		printflags();
		runJobs();

		if ((_engineFlags & kEnginePauseJobs) == 0 || (_engineFlags & kEngineInventory)) {
			_graphics->swapBuffers();
			byte palette[PALETTE_SIZE];
			memcpy(palette, _palette, sizeof(palette));
			_graphics->animatePalette(palette);
			_graphics->setPalette(palette);
		}

	}

//	printf("exiting game loop...\n");

	delete _menu;

	return;
}


void Parallaction::processInput(InputData *data) {
//	printf("processInput()\n");
	Zone *z;
	WalkNode *v4;

	switch (data->_event) {
	case kEvEnterZone:
		_graphics->_labelPosition[1]._x = -1000;
		_graphics->_labelPosition[1]._y = -1000;
		_graphics->_labelPosition[0]._x = -1000;
		_graphics->_labelPosition[0]._y = -1000;
		_jDrawLabel = addJob(&jobDisplayLabel, (void*)data->_cnv, JOBPRIORITY_DRAWLABEL);
		_jEraseLabel = addJob(&jobEraseLabel, (void*)data->_cnv, JOBPRIORITY_HIDEINVENTORY);
		break;

	case kEvExitZone:
		removeJob(_jDrawLabel);
		addJob(&jobWaitRemoveJob, _jEraseLabel, JOBPRIORITY_RUNSTUFF);
		_jDrawLabel = NULL;
		break;

	case kEvAction:
		_procCurrentHoverItem = -1;
		_hoverZone = NULL;
		pauseJobs();
		z = data->_zone;
		if (runZone(z) == 0) {
			runCommands( z->_commands, z );
		}
		resumeJobs();
		break;

	case kEvOpenInventory:
		_procCurrentHoverItem = -1;
		_hoverZone = 0;
		if (_jDrawLabel != 0) {
			removeJob(_jDrawLabel);
			_jDrawLabel = NULL;
			addJob(&jobWaitRemoveJob, _jEraseLabel, JOBPRIORITY_SHOWINVENTORY);
		}
		if (hitZone(kZoneYou, _mousePos._x, _mousePos._y) == 0)
		changeCursor(kCursorArrow);
		removeJob(_jRunScripts);
		_jDrawInventory = addJob(&jobShowInventory, 0, JOBPRIORITY_SHOWINVENTORY);
		openInventory();
		break;

	case kEvCloseInventory: // closes inventory and possibly select item
		closeInventory();
		if ((data->_inventoryIndex != -1) && (_inventory[data->_inventoryIndex]._id != 0)) {
			// activates item
			changeCursor(data->_inventoryIndex);
		}
		_jRunScripts = addJob(&jobRunScripts, 0, JOBPRIORITY_RUNSTUFF);
		addJob(&jobHideInventory, 0, JOBPRIORITY_HIDEINVENTORY);
		removeJob(_jDrawInventory);
		break;

	case kEvHoverInventory:
		highlightInventoryItem(_procCurrentHoverItem, 12);	// disable
		highlightInventoryItem(data->_inventoryIndex, 19);						// enable
		_procCurrentHoverItem = data->_inventoryIndex;
		break;

	case kEvWalk:
		_hoverZone = 0;
		changeCursor(kCursorArrow);
		if (_yourself._zone._flags & kFlagsRemove) break;
		if ((_yourself._zone._flags & kFlagsActive) == 0) break;
		v4 = buildWalkPath(data->_mousePos._x, data->_mousePos._y);
		addJob(jobWalk, v4, JOBPRIORITY_WALK);
		_engineFlags |= kEngineWalking; 								   // inhibits processing of input until walking is over
		break;

	case kEvQuitGame:
		_engineFlags |= kEngineQuit;
		break;

	case kEvSaveGame:
		_hoverZone = NULL;
		changeCursor(kCursorArrow);
		saveGame();
		break;

	case kEvLoadGame:
		_hoverZone = NULL;
		changeCursor(kCursorArrow);
		loadGame();
		break;

	}

	return;
}



Parallaction::InputData *Parallaction::translateInput() {
//	printf("translateInput(%c)\n", _keyDown);

	if (_keyDown == kEvQuitGame) {
		_input._event = kEvQuitGame;
		return &_input;
	}

	if (_keyDown == kEvSaveGame) {
		_input._event = kEvSaveGame;
		return &_input;
	}

	if (_keyDown == kEvLoadGame) {
		_input._event = kEvLoadGame;
		return &_input;
	}

	_input._mousePos._x = _mousePos._x;
	_input._mousePos._y = _mousePos._y;

	if (((_engineFlags & kEnginePauseJobs) == 0) && ((_engineFlags & kEngineInventory) == 0)) {

		if (_actionAfterWalk == true) {
//			printf("1\n");

			// if walking is over, then take programmed action

			_input._event = kEvAction;
			_actionAfterWalk = false;
			return &_input;
		}

		Zone *z = hitZone(_activeItem._id, _mousePos._x, _mousePos._y);

		if (_mouseButtons == kMouseRightDown) {
//			printf("2\n");

			// right button down shows inventory

			if (hitZone(kZoneYou, _mousePos._x, _mousePos._y) && (_activeItem._id != 0)) {
//				printf("2.1\n");

				_activeItem._index = (_activeItem._id >> 16) & 0xFFFF;
				_engineFlags |= kEngineDragging;
			}


			_input._event = kEvOpenInventory;
			_transCurrentHoverItem = -1;
			return &_input;
		}

		if (((_mouseButtons == kMouseLeftUp) && (_activeItem._id == 0) && ((_engineFlags & kEngineWalking) == 0)) && ((z == NULL) || ((z->_type & 0xFFFF) != kZoneCommand))) {
//			printf("3\n");

			_input._event = kEvWalk;
			return &_input;
		}

		if ((z != _hoverZone) && (_hoverZone != NULL)) {
//			printf("4\n");

			_hoverZone = NULL;
			_input._event = kEvExitZone;
//			_input._data= &z->_name;
			return &_input;
		}

		if (z == NULL) {
//			printf("5\n");

			return NULL;
		}

		if ((_hoverZone == NULL) && ((z->_flags & kFlagsNoName) == 0)) {
//			printf("6\n");

			_hoverZone = z;
			_input._event = kEvEnterZone;
			_input._cnv = &z->_label;
			return &_input;
		}

		if ((_mouseButtons == kMouseLeftUp) && ((_activeItem._id != 0) || ((z->_type & 0xFFFF) == kZoneCommand))) {

			_input._zone = z;
			if (z->_flags & kFlagsNoWalk) {
//				printf("7.1\n");

				// character doesn't need to walk to take specified action
				_input._event = kEvAction;

			} else {
//				  printf("7.2\n");

				// action delayed: if Zone defined a moveto position the character is programmed to move there,
				// else it will move to the mouse position

				_input._event = kEvWalk;
				_actionAfterWalk = true;
				if (z->_moveTo._y != 0) {
	//				printf("3.2.2\n");
					_input._mousePos._x = z->_moveTo._x;
					_input._mousePos._y = z->_moveTo._y;
				}

			}

			beep();
			changeCursor(kCursorArrow);
			return &_input;
		}

	}

	if ((_engineFlags & kEngineInventory) == 0) return NULL;

//	printf("8\n");


	// in inventory

	int16 _si = getHoverInventoryItem(_mousePos._x, _mousePos._y);

	if (_mouseButtons == kMouseRightUp) {
		// right up hides inventory

		_input._event = kEvCloseInventory;
		_input._inventoryIndex = getHoverInventoryItem(_mousePos._x, _mousePos._y);
		highlightInventoryItem(_transCurrentHoverItem, 12); 		// disable

		if ((_engineFlags & kEngineDragging) == 0) return &_input;

		_engineFlags &= ~kEngineDragging;
		Zone *z = hitZone(kZoneMerge, _activeItem._index, _inventory[_input._inventoryIndex]._index);

		if (z != NULL) {
			dropItem(z->u.merge->_obj1 - 4);
			dropItem(z->u.merge->_obj2 - 4);
			addInventoryItem(z->u.merge->_obj3);
			runCommands(z->_commands);
		}

		return &_input;
	}

	if (_si == _transCurrentHoverItem) return NULL;

	_transCurrentHoverItem = _si;
	_input._event = kEvHoverInventory;
	_input._inventoryIndex = _si;
	return &_input;

}

uint32 Parallaction::getElapsedTime() {
	return g_system->getMillis() - _baseTime;
}

void Parallaction::resetTimer() {
	_baseTime = g_system->getMillis();
	return;
}


void Parallaction::waitTime(uint32 t) {
//	printf("waitTime(%i)\n", t);

	uint32 v4 = 0;

	while (v4 < t * (1000 / 18.2)) {
		v4 = getElapsedTime();
	}

	resetTimer();

	return;
}




//	changes the mouse pointer
//	index 0 means standard pointer (from pointer.cnv)
//	index > 0 means inventory item
//
void Parallaction::changeCursor(int32 index) {
//	printf("changeCursor(%i)\n", index);

	if (index == kCursorArrow) {		// standard mouse pointer

		if (_jDrawLabel != NULL) {
			removeJob(_jDrawLabel);
			addJob(&jobWaitRemoveJob, _jEraseLabel, JOBPRIORITY_RUNSTUFF);
			_jDrawLabel = NULL;
		}

		_activeItem._id = 0;

	} else {
		_activeItem._id = _inventory[index]._id;
	}

	_graphics->setMousePointer(index);

	return;
}



void freeCharacterFrames() {

	_vm->_graphics->freeCnv(&_tempFrames);

	if (_vm->_characterName[0] != 'D') {
		_vm->_graphics->freeCnv(&_miniCharacterFrames);
		_vm->freeTable(_objectsNames);
	}

	return;
}



void Parallaction::changeCharacter(const char *name) {
//	printf("changeCharacter(%s)\n", name);

	uint16 _si = 0;

	if (!scumm_strnicmp(name, "mini", 4)) {
		name+=4;
		_si = 1;
	}

	char v32[20];
	strcpy(v32, name);



	if (_engineFlags & kEngineMiniDonna) {
		strcat(v32, "tras");
	}

	if (scumm_stricmp(v32, _characterName1)) {

		if (scumm_stricmp(_characterName1, "null")) {
			freeCharacterFrames();
		}

		closeArchive();

		strcpy(_disk, "disk1");
		openArchive("disk1");

		char path[PATH_LEN];
		strcpy(path, v32);
		_graphics->loadCnv(path, &_tempFrames);

		if (name[0] != 'D') {
			sprintf(path, "mini%s", v32);
			_graphics->loadCnv(path, &_miniCharacterFrames);

			sprintf(path, "%s.tab", name);
			initTable(path, _objectsNames);

			refreshInventory(name);

			stopMusic();

			if (scumm_stricmp(name, "night") && scumm_stricmp(name, "intsushi")) {
				if (!scumm_stricmp(name, "dino") || !scumm_stricmp(name, "minidino")) {
					loadMusic("dino");
				} else
				if (!scumm_stricmp(name, "donna") || !scumm_stricmp(name, "minidonna")) {
					loadMusic("donna");
				} else {
					loadMusic("nuts");
				}

				playMusic();
			}

		}

	}

	if (_si == 1) {
		memcpy(&_yourself._cnv, &_miniCharacterFrames, sizeof(Cnv));
	} else {
		memcpy(&_yourself._cnv, &_tempFrames, sizeof(Cnv));
	}

	strcpy(_characterName1, v32);

	return;
}

void freeNodeList(Node *list) {

	while (list) {
		Node *v4 = list->_next;
		memFree(list);
		list = v4;
	}

	return;
}


void addNode(Node *list, Node *n) {

	Node *v4 = list->_next;

	if (v4 != NULL) {
		v4->_prev = n;
	}

	n->_next = v4;
	list->_next = n;
	n->_prev = list;

	return;
}

void removeNode(Node *n) {

	Node *v4 = n->_next;
	if (v4 != NULL) {
		v4->_prev = n->_prev;
	}

	n->_prev->_next = n->_next;

	return;
}


Job *addJob(JobFn fn, void *parm, uint16 tag) {
//	printf("addJob(%i)\n", tag);

	Job *v8 = (Job*)memAlloc(sizeof(Job));

	v8->_parm = parm;
	v8->_fn = fn;
	v8->_tag = tag;
	v8->_finished = 0;
	v8->_count = 0;

	Job *v4 = &_jobs;

	while (v4->_node._next && ((Job*)(v4->_node._next))->_tag > tag) {
		v4 = (Job*)v4->_node._next;
	}

	addNode(&v4->_node, &v8->_node);
	return v8;
}

void removeJob(Job *j) {
//	printf("removeJob(%x, %i)\n", j, j->_tag);

	removeNode(&j->_node);
	memFree(j);
	return;
}

void pauseJobs() {
	_engineFlags |= kEnginePauseJobs;
	return;
}

void resumeJobs() {
	_engineFlags &= ~kEnginePauseJobs;
	return;
}

void runJobs() {
//	printf("runJobs...START\n");

	if (_engineFlags & kEnginePauseJobs) return;

	Job *j = (Job*)_jobs._node._next;
	while (j) {
//		printf("Job run %s\n", _jobDescriptions[j->_tag]);

		(*j->_fn)(j->_parm, j);
		Job *v4 = (Job*)j->_node._next;

		if (j->_finished == 1) removeJob(j);

		j = v4;
	}

//	printf("runJobs...DONE\n");

	return;}

// this Job uses a static counter to delay removal
// and is in fact only used to remove jEraseLabel jobs
//
void jobWaitRemoveJob(void *parm, Job *j) {
//	printf("jobWaitRemoveJob(%x)\n", parm);

	Job *arg = (Job*)parm;

	static uint16 count = 0;

	_engineFlags |= kEngineMouse;

	count++;
	if (count == 2) {
		count = 0;
		removeJob(arg);
		_engineFlags &= ~kEngineMouse;
		j->_finished = 1;
	}

	return;
}


} // namespace Parallaction