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
|
/* 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/dcgf.h"
#include "engines/wintermute/AdItem.h"
#include "engines/wintermute/AdGame.h"
#include "engines/wintermute/AdSentence.h"
#include "engines/wintermute/BFontStorage.h"
#include "engines/wintermute/BFont.h"
#include "engines/wintermute/BFileManager.h"
#include "engines/wintermute/BGame.h"
#include "engines/wintermute/BParser.h"
#include "engines/wintermute/BSound.h"
#include "engines/wintermute/BSprite.h"
#include "engines/wintermute/utils.h"
#include "engines/wintermute/PlatformSDL.h"
#include "engines/wintermute/scriptables/ScScript.h"
#include "engines/wintermute/scriptables/ScStack.h"
#include "engines/wintermute/scriptables/ScValue.h"
#include "common/str.h"
namespace WinterMute {
IMPLEMENT_PERSISTENT(CAdItem, false)
//////////////////////////////////////////////////////////////////////////
CAdItem::CAdItem(CBGame *inGame): CAdTalkHolder(inGame) {
_spriteHover = NULL;
_cursorNormal = _cursorHover = NULL;
_cursorCombined = true;
_inInventory = false;
_displayAmount = false;
_amount = 0;
_amountOffsetX = 0;
_amountOffsetY = 0;
_amountAlign = TAL_RIGHT;
_amountString = NULL;
_state = STATE_READY;
_movable = false;
}
//////////////////////////////////////////////////////////////////////////
CAdItem::~CAdItem() {
delete _spriteHover;
delete _cursorNormal;
delete _cursorHover;
_spriteHover = NULL;
_cursorNormal = NULL;
_cursorHover = NULL;
delete[] _amountString;
_amountString = NULL;
}
//////////////////////////////////////////////////////////////////////////
HRESULT CAdItem::LoadFile(const char *Filename) {
byte *Buffer = Game->_fileManager->ReadWholeFile(Filename);
if (Buffer == NULL) {
Game->LOG(0, "CAdItem::LoadFile failed for file '%s'", Filename);
return E_FAIL;
}
HRESULT ret;
_filename = new char [strlen(Filename) + 1];
strcpy(_filename, Filename);
if (FAILED(ret = LoadBuffer(Buffer, true))) Game->LOG(0, "Error parsing ITEM file '%s'", Filename);
delete [] Buffer;
return ret;
}
TOKEN_DEF_START
TOKEN_DEF(ITEM)
TOKEN_DEF(TEMPLATE)
TOKEN_DEF(CURSOR_HOVER)
TOKEN_DEF(CURSOR_COMBINED)
TOKEN_DEF(CURSOR)
TOKEN_DEF(NAME)
TOKEN_DEF(IMAGE_HOVER)
TOKEN_DEF(IMAGE)
TOKEN_DEF(EVENTS)
TOKEN_DEF(SCRIPT)
TOKEN_DEF(CAPTION)
TOKEN_DEF(PROPERTY)
TOKEN_DEF(EDITOR_PROPERTY)
TOKEN_DEF(FONT)
TOKEN_DEF(ALPHA_COLOR)
TOKEN_DEF(ALPHA)
TOKEN_DEF(TALK_SPECIAL)
TOKEN_DEF(TALK)
TOKEN_DEF(SPRITE_HOVER)
TOKEN_DEF(SPRITE)
TOKEN_DEF(DISPLAY_AMOUNT)
TOKEN_DEF(AMOUNT_OFFSET_X)
TOKEN_DEF(AMOUNT_OFFSET_Y)
TOKEN_DEF(AMOUNT_ALIGN)
TOKEN_DEF(AMOUNT_STRING)
TOKEN_DEF(AMOUNT)
TOKEN_DEF_END
//////////////////////////////////////////////////////////////////////////
HRESULT CAdItem::LoadBuffer(byte *Buffer, bool Complete) {
TOKEN_TABLE_START(commands)
TOKEN_TABLE(ITEM)
TOKEN_TABLE(TEMPLATE)
TOKEN_TABLE(CURSOR_HOVER)
TOKEN_TABLE(CURSOR_COMBINED)
TOKEN_TABLE(CURSOR)
TOKEN_TABLE(NAME)
TOKEN_TABLE(IMAGE_HOVER)
TOKEN_TABLE(IMAGE)
TOKEN_TABLE(EVENTS)
TOKEN_TABLE(SCRIPT)
TOKEN_TABLE(CAPTION)
TOKEN_TABLE(PROPERTY)
TOKEN_TABLE(EDITOR_PROPERTY)
TOKEN_TABLE(FONT)
TOKEN_TABLE(ALPHA_COLOR)
TOKEN_TABLE(ALPHA)
TOKEN_TABLE(TALK_SPECIAL)
TOKEN_TABLE(TALK)
TOKEN_TABLE(SPRITE_HOVER)
TOKEN_TABLE(SPRITE)
TOKEN_TABLE(DISPLAY_AMOUNT)
TOKEN_TABLE(AMOUNT_OFFSET_X)
TOKEN_TABLE(AMOUNT_OFFSET_Y)
TOKEN_TABLE(AMOUNT_ALIGN)
TOKEN_TABLE(AMOUNT_STRING)
TOKEN_TABLE(AMOUNT)
TOKEN_TABLE_END
byte *params;
int cmd = 2;
CBParser parser(Game);
if (Complete) {
if (parser.GetCommand((char **)&Buffer, commands, (char **)¶ms) != TOKEN_ITEM) {
Game->LOG(0, "'ITEM' keyword expected.");
return E_FAIL;
}
Buffer = params;
}
int ar = 0, ag = 0, ab = 0, alpha = 255;
while (cmd > 0 && (cmd = parser.GetCommand((char **)&Buffer, commands, (char **)¶ms)) > 0) {
switch (cmd) {
case TOKEN_TEMPLATE:
if (FAILED(LoadFile((char *)params))) cmd = PARSERR_GENERIC;
break;
case TOKEN_NAME:
SetName((char *)params);
break;
case TOKEN_FONT:
SetFont((char *)params);
break;
case TOKEN_CAPTION:
SetCaption((char *)params);
break;
case TOKEN_IMAGE:
case TOKEN_SPRITE:
delete _sprite;
_sprite = new CBSprite(Game, this);
if (!_sprite || FAILED(_sprite->LoadFile((char *)params, ((CAdGame *)Game)->_texItemLifeTime))) {
delete _sprite;
cmd = PARSERR_GENERIC;
}
break;
case TOKEN_IMAGE_HOVER:
case TOKEN_SPRITE_HOVER:
delete _spriteHover;
_spriteHover = new CBSprite(Game, this);
if (!_spriteHover || FAILED(_spriteHover->LoadFile((char *)params, ((CAdGame *)Game)->_texItemLifeTime))) {
delete _spriteHover;
cmd = PARSERR_GENERIC;
}
break;
case TOKEN_AMOUNT:
parser.ScanStr((char *)params, "%d", &_amount);
break;
case TOKEN_DISPLAY_AMOUNT:
parser.ScanStr((char *)params, "%b", &_displayAmount);
break;
case TOKEN_AMOUNT_OFFSET_X:
parser.ScanStr((char *)params, "%d", &_amountOffsetX);
break;
case TOKEN_AMOUNT_OFFSET_Y:
parser.ScanStr((char *)params, "%d", &_amountOffsetY);
break;
case TOKEN_AMOUNT_ALIGN:
if (scumm_stricmp((char *)params, "left") == 0) _amountAlign = TAL_LEFT;
else if (scumm_stricmp((char *)params, "right") == 0) _amountAlign = TAL_RIGHT;
else _amountAlign = TAL_CENTER;
break;
case TOKEN_AMOUNT_STRING:
CBUtils::SetString(&_amountString, (char *)params);
break;
case TOKEN_TALK: {
CBSprite *spr = new CBSprite(Game, this);
if (!spr || FAILED(spr->LoadFile((char *)params, ((CAdGame *)Game)->_texTalkLifeTime))) cmd = PARSERR_GENERIC;
else _talkSprites.Add(spr);
}
break;
case TOKEN_TALK_SPECIAL: {
CBSprite *spr = new CBSprite(Game, this);
if (!spr || FAILED(spr->LoadFile((char *)params, ((CAdGame *)Game)->_texTalkLifeTime))) cmd = PARSERR_GENERIC;
else _talkSpritesEx.Add(spr);
}
break;
case TOKEN_CURSOR:
delete _cursorNormal;
_cursorNormal = new CBSprite(Game);
if (!_cursorNormal || FAILED(_cursorNormal->LoadFile((char *)params, ((CAdGame *)Game)->_texItemLifeTime))) {
delete _cursorNormal;
_cursorNormal = NULL;
cmd = PARSERR_GENERIC;
}
break;
case TOKEN_CURSOR_HOVER:
delete _cursorHover;
_cursorHover = new CBSprite(Game);
if (!_cursorHover || FAILED(_cursorHover->LoadFile((char *)params, ((CAdGame *)Game)->_texItemLifeTime))) {
delete _cursorHover;
_cursorHover = NULL;
cmd = PARSERR_GENERIC;
}
break;
case TOKEN_CURSOR_COMBINED:
parser.ScanStr((char *)params, "%b", &_cursorCombined);
break;
case TOKEN_SCRIPT:
AddScript((char *)params);
break;
case TOKEN_PROPERTY:
ParseProperty(params, false);
break;
case TOKEN_ALPHA_COLOR:
parser.ScanStr((char *)params, "%d,%d,%d", &ar, &ag, &ab);
break;
case TOKEN_ALPHA:
parser.ScanStr((char *)params, "%d", &alpha);
break;
case TOKEN_EDITOR_PROPERTY:
ParseEditorProperty(params, false);
break;
}
}
if (cmd == PARSERR_TOKENNOTFOUND) {
Game->LOG(0, "Syntax error in ITEM definition");
return E_FAIL;
}
if (cmd == PARSERR_GENERIC) {
Game->LOG(0, "Error loading ITEM definition");
return E_FAIL;
}
if (alpha != 0 && ar == 0 && ag == 0 && ab == 0) {
ar = ag = ab = 255;
}
_alphaColor = DRGBA(ar, ag, ab, alpha);
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
HRESULT CAdItem::Update() {
_currentSprite = NULL;
if (_state == STATE_READY && _animSprite) {
delete _animSprite;
_animSprite = NULL;
}
// finished playing animation?
if (_state == STATE_PLAYING_ANIM && _animSprite != NULL && _animSprite->_finished) {
_state = STATE_READY;
_currentSprite = _animSprite;
}
if (_sentence && _state != STATE_TALKING) _sentence->Finish();
// default: stand animation
if (!_currentSprite) _currentSprite = _sprite;
switch (_state) {
//////////////////////////////////////////////////////////////////////////
case STATE_PLAYING_ANIM:
_currentSprite = _animSprite;
break;
//////////////////////////////////////////////////////////////////////////
case STATE_READY:
if (!_animSprite) {
if (Game->_activeObject == this && _spriteHover) _currentSprite = _spriteHover;
else _currentSprite = _sprite;
}
break;
//////////////////////////////////////////////////////////////////////////
case STATE_TALKING: {
_sentence->Update();
if (_sentence->_currentSprite) _tempSprite2 = _sentence->_currentSprite;
bool TimeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->IsPlaying() && !_sentence->_sound->IsPaused())) || (!_sentence->_sound && _sentence->_duration <= Game->_timer - _sentence->_startTime);
if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ TimeIsUp)) {
if (TimeIsUp) {
_sentence->Finish();
_tempSprite2 = NULL;
_state = STATE_READY;
} else {
_tempSprite2 = GetTalkStance(_sentence->GetNextStance());
if (_tempSprite2) {
_tempSprite2->Reset();
_currentSprite = _tempSprite2;
}
((CAdGame *)Game)->AddSentence(_sentence);
}
} else {
_currentSprite = _tempSprite2;
((CAdGame *)Game)->AddSentence(_sentence);
}
}
break;
}
_ready = (_state == STATE_READY);
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
HRESULT CAdItem::Display(int X, int Y) {
int Width = 0;
if (_currentSprite) {
RECT rc;
_currentSprite->GetBoundingRect(&rc, 0, 0);
Width = rc.right - rc.left;
}
_posX = X + Width / 2;
_posY = Y;
HRESULT ret;
if (_currentSprite) ret = _currentSprite->Draw(X, Y, this, 100, 100, _alphaColor);
else ret = S_OK;
if (_displayAmount) {
int AmountX = X;
int AmountY = Y + _amountOffsetY;
if (_amountAlign == TAL_RIGHT) {
Width -= _amountOffsetX;
AmountX -= _amountOffsetX;
}
AmountX += _amountOffsetX;
CBFont *Font = _font ? _font : Game->_systemFont;
if (Font) {
if (_amountString) Font->DrawText((byte *)_amountString, AmountX, AmountY, Width, _amountAlign);
else {
char Str[256];
sprintf(Str, "%d", _amount);
Font->DrawText((byte *)Str, AmountX, AmountY, Width, _amountAlign);
}
}
}
return ret;
}
//////////////////////////////////////////////////////////////////////////
// high level scripting interface
//////////////////////////////////////////////////////////////////////////
HRESULT CAdItem::ScCallMethod(CScScript *Script, CScStack *Stack, CScStack *ThisStack, const char *Name) {
//////////////////////////////////////////////////////////////////////////
// SetHoverSprite
//////////////////////////////////////////////////////////////////////////
if (strcmp(Name, "SetHoverSprite") == 0) {
Stack->CorrectParams(1);
bool SetCurrent = false;
if (_currentSprite && _currentSprite == _spriteHover) SetCurrent = true;
const char *Filename = Stack->Pop()->GetString();
delete _spriteHover;
_spriteHover = NULL;
CBSprite *spr = new CBSprite(Game, this);
if (!spr || FAILED(spr->LoadFile(Filename))) {
Stack->PushBool(false);
Script->RuntimeError("Item.SetHoverSprite failed for file '%s'", Filename);
} else {
_spriteHover = spr;
if (SetCurrent) _currentSprite = _spriteHover;
Stack->PushBool(true);
}
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
// GetHoverSprite
//////////////////////////////////////////////////////////////////////////
else if (strcmp(Name, "GetHoverSprite") == 0) {
Stack->CorrectParams(0);
if (!_spriteHover || !_spriteHover->_filename) Stack->PushNULL();
else Stack->PushString(_spriteHover->_filename);
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
// GetHoverSpriteObject
//////////////////////////////////////////////////////////////////////////
else if (strcmp(Name, "GetHoverSpriteObject") == 0) {
Stack->CorrectParams(0);
if (!_spriteHover) Stack->PushNULL();
else Stack->PushNative(_spriteHover, true);
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
// SetNormalCursor
//////////////////////////////////////////////////////////////////////////
if (strcmp(Name, "SetNormalCursor") == 0) {
Stack->CorrectParams(1);
const char *Filename = Stack->Pop()->GetString();
delete _cursorNormal;
_cursorNormal = NULL;
CBSprite *spr = new CBSprite(Game);
if (!spr || FAILED(spr->LoadFile(Filename))) {
Stack->PushBool(false);
Script->RuntimeError("Item.SetNormalCursor failed for file '%s'", Filename);
} else {
_cursorNormal = spr;
Stack->PushBool(true);
}
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
// GetNormalCursor
//////////////////////////////////////////////////////////////////////////
else if (strcmp(Name, "GetNormalCursor") == 0) {
Stack->CorrectParams(0);
if (!_cursorNormal || !_cursorNormal->_filename) Stack->PushNULL();
else Stack->PushString(_cursorNormal->_filename);
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
// GetNormalCursorObject
//////////////////////////////////////////////////////////////////////////
else if (strcmp(Name, "GetNormalCursorObject") == 0) {
Stack->CorrectParams(0);
if (!_cursorNormal) Stack->PushNULL();
else Stack->PushNative(_cursorNormal, true);
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
// SetHoverCursor
//////////////////////////////////////////////////////////////////////////
if (strcmp(Name, "SetHoverCursor") == 0) {
Stack->CorrectParams(1);
const char *Filename = Stack->Pop()->GetString();
delete _cursorHover;
_cursorHover = NULL;
CBSprite *spr = new CBSprite(Game);
if (!spr || FAILED(spr->LoadFile(Filename))) {
Stack->PushBool(false);
Script->RuntimeError("Item.SetHoverCursor failed for file '%s'", Filename);
} else {
_cursorHover = spr;
Stack->PushBool(true);
}
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
// GetHoverCursor
//////////////////////////////////////////////////////////////////////////
else if (strcmp(Name, "GetHoverCursor") == 0) {
Stack->CorrectParams(0);
if (!_cursorHover || !_cursorHover->_filename) Stack->PushNULL();
else Stack->PushString(_cursorHover->_filename);
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
// GetHoverCursorObject
//////////////////////////////////////////////////////////////////////////
else if (strcmp(Name, "GetHoverCursorObject") == 0) {
Stack->CorrectParams(0);
if (!_cursorHover) Stack->PushNULL();
else Stack->PushNative(_cursorHover, true);
return S_OK;
}
else return CAdTalkHolder::ScCallMethod(Script, Stack, ThisStack, Name);
}
//////////////////////////////////////////////////////////////////////////
CScValue *CAdItem::ScGetProperty(const char *Name) {
_scValue->SetNULL();
//////////////////////////////////////////////////////////////////////////
// Type
//////////////////////////////////////////////////////////////////////////
if (strcmp(Name, "Type") == 0) {
_scValue->SetString("item");
return _scValue;
}
//////////////////////////////////////////////////////////////////////////
// Name
//////////////////////////////////////////////////////////////////////////
else if (strcmp(Name, "Name") == 0) {
_scValue->SetString(_name);
return _scValue;
}
//////////////////////////////////////////////////////////////////////////
// DisplayAmount
//////////////////////////////////////////////////////////////////////////
else if (strcmp(Name, "DisplayAmount") == 0) {
_scValue->SetBool(_displayAmount);
return _scValue;
}
//////////////////////////////////////////////////////////////////////////
// Amount
//////////////////////////////////////////////////////////////////////////
else if (strcmp(Name, "Amount") == 0) {
_scValue->SetInt(_amount);
return _scValue;
}
//////////////////////////////////////////////////////////////////////////
// AmountOffsetX
//////////////////////////////////////////////////////////////////////////
else if (strcmp(Name, "AmountOffsetX") == 0) {
_scValue->SetInt(_amountOffsetX);
return _scValue;
}
//////////////////////////////////////////////////////////////////////////
// AmountOffsetY
//////////////////////////////////////////////////////////////////////////
else if (strcmp(Name, "AmountOffsetY") == 0) {
_scValue->SetInt(_amountOffsetY);
return _scValue;
}
//////////////////////////////////////////////////////////////////////////
// AmountAlign
//////////////////////////////////////////////////////////////////////////
else if (strcmp(Name, "AmountAlign") == 0) {
_scValue->SetInt(_amountAlign);
return _scValue;
}
//////////////////////////////////////////////////////////////////////////
// AmountString
//////////////////////////////////////////////////////////////////////////
else if (strcmp(Name, "AmountString") == 0) {
if (!_amountString) _scValue->SetNULL();
else _scValue->SetString(_amountString);
return _scValue;
}
//////////////////////////////////////////////////////////////////////////
// CursorCombined
//////////////////////////////////////////////////////////////////////////
else if (strcmp(Name, "CursorCombined") == 0) {
_scValue->SetBool(_cursorCombined);
return _scValue;
}
else return CAdTalkHolder::ScGetProperty(Name);
}
//////////////////////////////////////////////////////////////////////////
HRESULT CAdItem::ScSetProperty(const char *Name, CScValue *Value) {
//////////////////////////////////////////////////////////////////////////
// Name
//////////////////////////////////////////////////////////////////////////
if (strcmp(Name, "Name") == 0) {
SetName(Value->GetString());
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
// DisplayAmount
//////////////////////////////////////////////////////////////////////////
else if (strcmp(Name, "DisplayAmount") == 0) {
_displayAmount = Value->GetBool();
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
// Amount
//////////////////////////////////////////////////////////////////////////
else if (strcmp(Name, "Amount") == 0) {
_amount = Value->GetInt();
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
// AmountOffsetX
//////////////////////////////////////////////////////////////////////////
else if (strcmp(Name, "AmountOffsetX") == 0) {
_amountOffsetX = Value->GetInt();
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
// AmountOffsetY
//////////////////////////////////////////////////////////////////////////
else if (strcmp(Name, "AmountOffsetY") == 0) {
_amountOffsetY = Value->GetInt();
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
// AmountAlign
//////////////////////////////////////////////////////////////////////////
else if (strcmp(Name, "AmountAlign") == 0) {
_amountAlign = (TTextAlign)Value->GetInt();
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
// AmountString
//////////////////////////////////////////////////////////////////////////
else if (strcmp(Name, "AmountString") == 0) {
if (Value->IsNULL()) SAFE_DELETE_ARRAY(_amountString);
else CBUtils::SetString(&_amountString, Value->GetString());
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
// CursorCombined
//////////////////////////////////////////////////////////////////////////
else if (strcmp(Name, "CursorCombined") == 0) {
_cursorCombined = Value->GetBool();
return S_OK;
}
else return CAdTalkHolder::ScSetProperty(Name, Value);
}
//////////////////////////////////////////////////////////////////////////
char *CAdItem::ScToString() {
return "[item]";
}
//////////////////////////////////////////////////////////////////////////
HRESULT CAdItem::Persist(CBPersistMgr *PersistMgr) {
CAdTalkHolder::Persist(PersistMgr);
PersistMgr->Transfer(TMEMBER(_cursorCombined));
PersistMgr->Transfer(TMEMBER(_cursorHover));
PersistMgr->Transfer(TMEMBER(_cursorNormal));
PersistMgr->Transfer(TMEMBER(_spriteHover));
PersistMgr->Transfer(TMEMBER(_inInventory));
PersistMgr->Transfer(TMEMBER(_displayAmount));
PersistMgr->Transfer(TMEMBER(_amount));
PersistMgr->Transfer(TMEMBER(_amountOffsetX));
PersistMgr->Transfer(TMEMBER(_amountOffsetY));
PersistMgr->Transfer(TMEMBER_INT(_amountAlign));
PersistMgr->Transfer(TMEMBER(_amountString));
return S_OK;
}
//////////////////////////////////////////////////////////////////////////
bool CAdItem::GetExtendedFlag(const char *FlagName) {
if (!FlagName) return false;
else if (strcmp(FlagName, "usable") == 0) return true;
else return CAdObject::GetExtendedFlag(FlagName);
}
} // end of namespace WinterMute
|