aboutsummaryrefslogtreecommitdiff
path: root/engines/wintermute/base/base_frame.cpp
blob: eaad024120fbdc9ae9a91599fa370b766685ae75 (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
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * 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.
 *
 */

/*
 * This file is based on WME Lite.
 * http://dead-code.org/redir.php?target=wmelite
 * Copyright (c) 2011 Jan Nedoma
 */

#include "engines/wintermute/base/base_parser.h"
#include "engines/wintermute/base/base_engine.h"
#include "engines/wintermute/base/base_frame.h"
#include "engines/wintermute/base/base_object.h"
#include "engines/wintermute/base/base_dynamic_buffer.h"
#include "engines/wintermute/base/sound/base_sound_manager.h"
#include "engines/wintermute/base/sound/base_sound.h"
#include "engines/wintermute/base/base_sub_frame.h"
#include "engines/wintermute/platform_osystem.h"
#include "engines/wintermute/base/scriptables/script_value.h"
#include "engines/wintermute/base/scriptables/script.h"
#include "engines/wintermute/base/scriptables/script_stack.h"
#include "common/str.h"

namespace Wintermute {

IMPLEMENT_PERSISTENT(BaseFrame, false)

//////////////////////////////////////////////////////////////////////
BaseFrame::BaseFrame(BaseGame *inGame) : BaseScriptable(inGame, true) {
	_delay = 0;
	_moveX = _moveY = 0;

	_sound = nullptr;
	_killSound = false;

	_editorExpanded = false;
	_keyframe = false;
}


//////////////////////////////////////////////////////////////////////
BaseFrame::~BaseFrame() {
	delete _sound;
	_sound = nullptr;

	for (uint32 i = 0; i < _subframes.size(); i++) {
		delete _subframes[i];
	}
	_subframes.clear();

	for (uint32 i = 0; i < _applyEvent.size(); i++) {
		delete[] _applyEvent[i];
		_applyEvent[i] = nullptr;
	}
	_applyEvent.clear();
}


//////////////////////////////////////////////////////////////////////
bool BaseFrame::draw(int x, int y, BaseObject *registerOwner, float zoomX, float zoomY, bool precise, uint32 alpha, bool allFrames, float rotate, TSpriteBlendMode blendMode) {
	bool res;

	for (uint32 i = 0; i < _subframes.size(); i++) {
		res = _subframes[i]->draw(x, y, registerOwner, zoomX, zoomY, precise, alpha, rotate, blendMode);
		if (DID_FAIL(res)) {
			return res;
		}
	}
	return STATUS_OK;
}

void BaseFrame::stopSound() {
	if (_sound) {
		_sound->stop();
	}
}


//////////////////////////////////////////////////////////////////////////
bool BaseFrame::oneTimeDisplay(BaseObject *owner, bool muted) {
	if (_sound && !muted) {
		if (owner) {
			owner->updateOneSound(_sound);
		}
		_sound->play();
		/*
		if (_gameRef->_state == GAME_FROZEN) {
		    _sound->Pause(true);
		}
		*/
	}
	if (owner) {
		for (uint32 i = 0; i < _applyEvent.size(); i++) {
			owner->applyEvent(_applyEvent[i]);
		}
	}
	return STATUS_OK;
}



TOKEN_DEF_START
TOKEN_DEF(DELAY)
TOKEN_DEF(IMAGE)
TOKEN_DEF(TRANSPARENT)
TOKEN_DEF(RECT)
TOKEN_DEF(HOTSPOT)
TOKEN_DEF(2D_ONLY)
TOKEN_DEF(3D_ONLY)
TOKEN_DEF(MIRROR_X)
TOKEN_DEF(MIRROR_Y)
TOKEN_DEF(MOVE)
TOKEN_DEF(ALPHA_COLOR)
TOKEN_DEF(ALPHA)
TOKEN_DEF(SUBFRAME)
TOKEN_DEF(SOUND)
TOKEN_DEF(KEYFRAME)
TOKEN_DEF(DECORATION)
TOKEN_DEF(APPLY_EVENT)
TOKEN_DEF(EDITOR_SELECTED)
TOKEN_DEF(EDITOR_EXPANDED)
TOKEN_DEF(EDITOR_PROPERTY)
TOKEN_DEF(KILL_SOUND)
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////
bool BaseFrame::loadBuffer(byte *buffer, int lifeTime, bool keepLoaded) {
	TOKEN_TABLE_START(commands)
	TOKEN_TABLE(DELAY)
	TOKEN_TABLE(IMAGE)
	TOKEN_TABLE(TRANSPARENT)
	TOKEN_TABLE(RECT)
	TOKEN_TABLE(HOTSPOT)
	TOKEN_TABLE(2D_ONLY)
	TOKEN_TABLE(3D_ONLY)
	TOKEN_TABLE(MIRROR_X)
	TOKEN_TABLE(MIRROR_Y)
	TOKEN_TABLE(MOVE)
	TOKEN_TABLE(ALPHA_COLOR)
	TOKEN_TABLE(ALPHA)
	TOKEN_TABLE(SUBFRAME)
	TOKEN_TABLE(SOUND)
	TOKEN_TABLE(KEYFRAME)
	TOKEN_TABLE(DECORATION)
	TOKEN_TABLE(APPLY_EVENT)
	TOKEN_TABLE(EDITOR_SELECTED)
	TOKEN_TABLE(EDITOR_EXPANDED)
	TOKEN_TABLE(EDITOR_PROPERTY)
	TOKEN_TABLE(KILL_SOUND)
	TOKEN_TABLE_END

	char *params;
	int cmd;
	BaseParser parser;
	Rect32 rect;
	int r = 255, g = 255, b = 255;
	int ar = 255, ag = 255, ab = 255, alpha = 255;
	int hotspotX = 0, hotspotY = 0;
	bool custoTrans = false;
	bool editorSelected = false;
	bool is2DOnly = false;
	bool is3DOnly = false;
	bool decoration = false;
	bool mirrorX = false;
	bool mirrorY = false;
	BasePlatform::setRectEmpty(&rect);
	char *surface_file = nullptr;

	while ((cmd = parser.getCommand((char **)&buffer, commands, &params)) > 0) {
		switch (cmd) {
		case TOKEN_DELAY:
			parser.scanStr(params, "%d", &_delay);
			break;

		case TOKEN_IMAGE:
			surface_file = params;
			break;

		case TOKEN_TRANSPARENT:
			parser.scanStr(params, "%d,%d,%d", &r, &g, &b);
			custoTrans = true;
			break;

		case TOKEN_RECT:
			parser.scanStr(params, "%d,%d,%d,%d", &rect.left, &rect.top, &rect.right, &rect.bottom);
			break;

		case TOKEN_HOTSPOT:
			parser.scanStr(params, "%d,%d", &hotspotX, &hotspotY);
			break;

		case TOKEN_MOVE:
			parser.scanStr(params, "%d,%d", &_moveX, &_moveY);
			break;

		case TOKEN_2D_ONLY:
			parser.scanStr(params, "%b", &is2DOnly);
			break;

		case TOKEN_3D_ONLY:
			parser.scanStr(params, "%b", &is3DOnly);
			break;

		case TOKEN_MIRROR_X:
			parser.scanStr(params, "%b", &mirrorX);
			break;

		case TOKEN_MIRROR_Y:
			parser.scanStr(params, "%b", &mirrorY);
			break;

		case TOKEN_ALPHA_COLOR:
			parser.scanStr(params, "%d,%d,%d", &ar, &ag, &ab);
			break;

		case TOKEN_ALPHA:
			parser.scanStr(params, "%d", &alpha);
			break;

		case TOKEN_EDITOR_SELECTED:
			parser.scanStr(params, "%b", &editorSelected);
			break;

		case TOKEN_EDITOR_EXPANDED:
			parser.scanStr(params, "%b", &_editorExpanded);
			break;

		case TOKEN_KILL_SOUND:
			parser.scanStr(params, "%b", &_killSound);
			break;

		case TOKEN_SUBFRAME: {
			BaseSubFrame *subframe = new BaseSubFrame(_gameRef);
			if (!subframe || DID_FAIL(subframe->loadBuffer((byte *)params, lifeTime, keepLoaded))) {
				delete subframe;
				cmd = PARSERR_GENERIC;
			} else {
				_subframes.add(subframe);
			}
		}
		break;

		case TOKEN_SOUND: {
			if (_sound) {
				delete _sound;
				_sound = nullptr;
			}
			_sound = new BaseSound(_gameRef);
			if (!_sound || DID_FAIL(_sound->setSound(params, Audio::Mixer::kSFXSoundType, false))) {
				if (BaseEngine::instance().getSoundMgr()->_soundAvailable) {
					BaseEngine::LOG(0, "Error loading sound '%s'.", params);
				}
				delete _sound;
				_sound = nullptr;
			}
		}
		break;

		case TOKEN_APPLY_EVENT: {
			char *event = new char[strlen(params) + 1];
			strcpy(event, params);
			_applyEvent.add(event);
		}
		break;

		case TOKEN_KEYFRAME:
			parser.scanStr(params, "%b", &_keyframe);
			break;

		case TOKEN_DECORATION:
			parser.scanStr(params, "%b", &decoration);
			break;

		case TOKEN_EDITOR_PROPERTY:
			parseEditorProperty((byte *)params, false);
			break;
		}
	}
	if (cmd == PARSERR_TOKENNOTFOUND) {
		BaseEngine::LOG(0, "Syntax error in FRAME definition");
		return STATUS_FAILED;
	}

	if (cmd == PARSERR_GENERIC) {
		BaseEngine::LOG(0, "Error loading FRAME definition");
		return STATUS_FAILED;
	}


	BaseSubFrame *sub = new BaseSubFrame(_gameRef);
	if (surface_file != nullptr) {
		if (custoTrans) {
			sub->setSurface(surface_file, false, r, g, b, lifeTime, keepLoaded);
		} else {
			sub->setSurface(surface_file, true, 0, 0, 0, lifeTime, keepLoaded);
		}

		if (!sub->_surface) {
			delete sub;
			BaseEngine::LOG(0, "Error loading SUBFRAME");
			return STATUS_FAILED;
		}

		sub->_alpha = BYTETORGBA(ar, ag, ab, alpha);
		if (custoTrans) {
			sub->_transparent = BYTETORGBA(r, g, b, 0xFF);
		}
	}

	if (BasePlatform::isRectEmpty(&rect)) {
		sub->setDefaultRect();
	} else {
		sub->setRect(rect);
	}

	sub->_hotspotX = hotspotX;
	sub->_hotspotY = hotspotY;
	sub->_2DOnly = is2DOnly;
	sub->_3DOnly = is3DOnly;
	sub->_decoration = decoration;
	sub->_mirrorX = mirrorX;
	sub->_mirrorY = mirrorY;


	sub->_editorSelected = editorSelected;
	_subframes.insert_at(0, sub);

	return STATUS_OK;
}


//////////////////////////////////////////////////////////////////////////
bool BaseFrame::getBoundingRect(Rect32 *rect, int x, int y, float scaleX, float scaleY) {
	if (!rect) {
		return false;
	}
	BasePlatform::setRectEmpty(rect);

	Rect32 subRect;

	for (uint32 i = 0; i < _subframes.size(); i++) {
		_subframes[i]->getBoundingRect(&subRect, x, y, scaleX, scaleY);
		BasePlatform::unionRect(rect, rect, &subRect);
	}
	return true;
}



//////////////////////////////////////////////////////////////////////////
bool BaseFrame::saveAsText(BaseDynamicBuffer *buffer, int indent) {
	buffer->putTextIndent(indent, "FRAME {\n");
	buffer->putTextIndent(indent + 2, "DELAY = %d\n", _delay);

	if (_moveX != 0 || _moveY != 0) {
		buffer->putTextIndent(indent + 2, "MOVE {%d, %d}\n", _moveX, _moveY);
	}

	if (_sound && _sound->getFilename()) {
		buffer->putTextIndent(indent + 2, "SOUND=\"%s\"\n", _sound->getFilename());
	}

	buffer->putTextIndent(indent + 2, "KEYFRAME=%s\n", _keyframe ? "TRUE" : "FALSE");

	if (_killSound) {
		buffer->putTextIndent(indent + 2, "KILL_SOUND=%s\n", _killSound ? "TRUE" : "FALSE");
	}

	if (_editorExpanded) {
		buffer->putTextIndent(indent + 2, "EDITOR_EXPANDED=%s\n", _editorExpanded ? "TRUE" : "FALSE");
	}

	if (_subframes.size() > 0) {
		_subframes[0]->saveAsText(buffer, indent, false);
	}

	for (uint32 i = 1; i < _subframes.size(); i++) {
		_subframes[i]->saveAsText(buffer, indent + 2);
	}

	for (uint32 i = 0; i < _applyEvent.size(); i++) {
		buffer->putTextIndent(indent + 2, "APPLY_EVENT=\"%s\"\n", _applyEvent[i]);
	}

	BaseClass::saveAsText(buffer, indent + 2);


	buffer->putTextIndent(indent, "}\n\n");

	return STATUS_OK;
}


//////////////////////////////////////////////////////////////////////////
bool BaseFrame::persist(BasePersistenceManager *persistMgr) {
	BaseScriptable::persist(persistMgr);

	_applyEvent.persist(persistMgr);
	persistMgr->transfer(TMEMBER(_delay));
	persistMgr->transfer(TMEMBER(_editorExpanded));
	persistMgr->transfer(TMEMBER(_keyframe));
	persistMgr->transfer(TMEMBER(_killSound));
	persistMgr->transfer(TMEMBER(_moveX));
	persistMgr->transfer(TMEMBER(_moveY));
	persistMgr->transferPtr(TMEMBER_PTR(_sound));
	_subframes.persist(persistMgr);

	return STATUS_OK;
}


//////////////////////////////////////////////////////////////////////////
// high level scripting interface
//////////////////////////////////////////////////////////////////////////
bool BaseFrame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) {

	//////////////////////////////////////////////////////////////////////////
	// GetSound
	//////////////////////////////////////////////////////////////////////////
	if (strcmp(name, "GetSound") == 0) {
		stack->correctParams(0);

		if (_sound && _sound->getFilename()) {
			stack->pushString(_sound->getFilename());
		} else {
			stack->pushNULL();
		}
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// SetSound
	//////////////////////////////////////////////////////////////////////////
	if (strcmp(name, "SetSound") == 0) {
		stack->correctParams(1);
		ScValue *val = stack->pop();
		delete _sound;
		_sound = nullptr;

		if (!val->isNULL()) {
			_sound = new BaseSound(_gameRef);
			if (!_sound || DID_FAIL(_sound->setSound(val->getString(), Audio::Mixer::kSFXSoundType, false))) {
				stack->pushBool(false);
				delete _sound;
				_sound = nullptr;
			} else {
				stack->pushBool(true);
			}
		} else {
			stack->pushBool(true);
		}
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// GetSubframe
	//////////////////////////////////////////////////////////////////////////
	if (strcmp(name, "GetSubframe") == 0) {
		stack->correctParams(1);
		int index = stack->pop()->getInt(-1);
		if (index < 0 || index >= (int32)_subframes.size()) {
			script->runtimeError("Frame.GetSubframe: Subframe index %d is out of range.", index);
			stack->pushNULL();
		} else {
			stack->pushNative(_subframes[index], true);
		}

		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// DeleteSubframe
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "DeleteSubframe") == 0) {
		stack->correctParams(1);
		ScValue *val = stack->pop();
		if (val->isInt()) {
			int index = val->getInt(-1);
			if (index < 0 || index >= (int32)_subframes.size()) {
				script->runtimeError("Frame.DeleteSubframe: Subframe index %d is out of range.", index);
			}
		} else {
			BaseSubFrame *sub = (BaseSubFrame *)val->getNative();
			for (uint32 i = 0; i < _subframes.size(); i++) {
				if (_subframes[i] == sub) {
					delete _subframes[i];
					_subframes.remove_at(i);
					break;
				}
			}
		}
		stack->pushNULL();
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// AddSubframe
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "AddSubframe") == 0) {
		stack->correctParams(1);
		ScValue *val = stack->pop();
		const char *filename = nullptr;
		if (!val->isNULL()) {
			filename = val->getString();
		}

		BaseSubFrame *sub = new BaseSubFrame(_gameRef);
		if (filename != nullptr) {
			sub->setSurface(filename);
			sub->setDefaultRect();
		}
		_subframes.add(sub);

		stack->pushNative(sub, true);
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// InsertSubframe
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "InsertSubframe") == 0) {
		stack->correctParams(2);
		int index = stack->pop()->getInt();
		if (index < 0) {
			index = 0;
		}

		ScValue *val = stack->pop();
		const char *filename = nullptr;
		if (!val->isNULL()) {
			filename = val->getString();
		}

		BaseSubFrame *sub = new BaseSubFrame(_gameRef);
		if (filename != nullptr) {
			sub->setSurface(filename);
		}

		if (index >= (int32)_subframes.size()) {
			_subframes.add(sub);
		} else {
			_subframes.insert_at(index, sub);
		}

		stack->pushNative(sub, true);
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// GetEvent
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "GetSubframe") == 0) {
		stack->correctParams(1);
		int index = stack->pop()->getInt(-1);
		if (index < 0 || index >= (int32)_applyEvent.size()) {
			script->runtimeError("Frame.GetEvent: Event index %d is out of range.", index);
			stack->pushNULL();
		} else {
			stack->pushString(_applyEvent[index]);
		}
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// AddEvent
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "AddEvent") == 0) {
		stack->correctParams(1);
		const char *event = stack->pop()->getString();
		for (uint32 i = 0; i < _applyEvent.size(); i++) {
			if (scumm_stricmp(_applyEvent[i], event) == 0) {
				stack->pushNULL();
				return STATUS_OK;
			}
		}
		_applyEvent.add(event);
		stack->pushNULL();
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// DeleteEvent
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "DeleteEvent") == 0) {
		stack->correctParams(1);
		const char *event = stack->pop()->getString();
		for (uint32 i = 0; i < _applyEvent.size(); i++) {
			if (scumm_stricmp(_applyEvent[i], event) == 0) {
				delete[] _applyEvent[i];
				_applyEvent.remove_at(i);
				break;
			}
		}
		stack->pushNULL();
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	else {
		if (_subframes.size() == 1) {
			return _subframes[0]->scCallMethod(script, stack, thisStack, name);
		} else {
			return BaseScriptable::scCallMethod(script, stack, thisStack, name);
		}
	}
}


//////////////////////////////////////////////////////////////////////////
ScValue *BaseFrame::scGetProperty(const Common::String &name) {
	if (!_scValue) {
		_scValue = new ScValue(_gameRef);
	}
	_scValue->setNULL();

	//////////////////////////////////////////////////////////////////////////
	// Type (RO)
	//////////////////////////////////////////////////////////////////////////
	if (name == "Type") {
		_scValue->setString("frame");
		return _scValue;
	}

	//////////////////////////////////////////////////////////////////////////
	// Delay
	//////////////////////////////////////////////////////////////////////////
	else if (name == "Delay") {
		_scValue->setInt(_delay);
		return _scValue;
	}

	//////////////////////////////////////////////////////////////////////////
	// Keyframe
	//////////////////////////////////////////////////////////////////////////
	else if (name == "Keyframe") {
		_scValue->setBool(_keyframe);
		return _scValue;
	}

	//////////////////////////////////////////////////////////////////////////
	// KillSounds
	//////////////////////////////////////////////////////////////////////////
	else if (name == "KillSounds") {
		_scValue->setBool(_killSound);
		return _scValue;
	}

	//////////////////////////////////////////////////////////////////////////
	// MoveX
	//////////////////////////////////////////////////////////////////////////
	else if (name == "MoveX") {
		_scValue->setInt(_moveX);
		return _scValue;
	}

	//////////////////////////////////////////////////////////////////////////
	// MoveY
	//////////////////////////////////////////////////////////////////////////
	else if (name == "MoveY") {
		_scValue->setInt(_moveY);
		return _scValue;
	}

	//////////////////////////////////////////////////////////////////////////
	// NumSubframes (RO)
	//////////////////////////////////////////////////////////////////////////
	else if (name == "NumSubframes") {
		_scValue->setInt(_subframes.size());
		return _scValue;
	}

	//////////////////////////////////////////////////////////////////////////
	// NumEvents (RO)
	//////////////////////////////////////////////////////////////////////////
	else if (name == "NumEvents") {
		_scValue->setInt(_applyEvent.size());
		return _scValue;
	}

	//////////////////////////////////////////////////////////////////////////
	else {
		if (_subframes.size() == 1) {
			return _subframes[0]->scGetProperty(name);
		} else {
			return BaseScriptable::scGetProperty(name);
		}
	}
}


//////////////////////////////////////////////////////////////////////////
bool BaseFrame::scSetProperty(const char *name, ScValue *value) {
	//////////////////////////////////////////////////////////////////////////
	// Delay
	//////////////////////////////////////////////////////////////////////////
	if (strcmp(name, "Delay") == 0) {
		_delay = MAX(0, value->getInt());
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// Keyframe
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "Keyframe") == 0) {
		_keyframe = value->getBool();
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// KillSounds
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "KillSounds") == 0) {
		_killSound = value->getBool();
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// MoveX
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "MoveX") == 0) {
		_moveX = value->getInt();
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	// MoveY
	//////////////////////////////////////////////////////////////////////////
	else if (strcmp(name, "MoveY") == 0) {
		_moveY = value->getInt();
		return STATUS_OK;
	}

	//////////////////////////////////////////////////////////////////////////
	else {
		if (_subframes.size() == 1) {
			return _subframes[0]->scSetProperty(name, value);
		} else {
			return BaseScriptable::scSetProperty(name, value);
		}
	}
}


//////////////////////////////////////////////////////////////////////////
const char *BaseFrame::scToString() {
	return "[frame]";
}

} // End of namespace Wintermute