forked from CaravelGames/drod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacter.cpp
More file actions
7356 lines (6583 loc) · 228 KB
/
Copy pathCharacter.cpp
File metadata and controls
7356 lines (6583 loc) · 228 KB
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
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// $Id: Character.cpp 10219 2012-05-21 13:18:56Z mrimer $
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Deadly Rooms of Death.
*
* The Initial Developer of the Original Code is
* Caravel Software.
* Portions created by the Initial Developer are Copyright (C) 1995, 1996,
* 1997, 2000, 2001, 2002, 2005 Caravel Software. All Rights Reserved.
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** */
#ifdef WIN32
#pragma warning(disable:4786)
#endif
#include "Character.h"
#include "BuildUtil.h"
#include "Combat.h"
#include "Db.h"
#include "DbHolds.h"
#include "EvilEye.h"
#include "Phoenix.h"
#include "Swordsman.h"
#include "../Texts/MIDs.h"
#include <BackEndLib/Base64.h>
#include <BackEndLib/Ports.h>
#include <BackEndLib/Files.h>
//*****************************************************************************
#define NO_LABEL (-1)
#define NO_OVERRIDE (UINT(-9999))
const UINT MAX_ANSWERS = 9;
const UINT MAX_HUE = 6000;
const UINT MAX_SATURATION = 1000;
//Literals used to query and store values for the NPC in the packed vars object.
//DO NOT CHANGE
#define commandStr "Commands"
#define idStr "id"
#define initialIdStr "initialId"
#define numCommandsStr "NumCommands"
#define scriptIDstr "ScriptID"
#define startLineStr "StartLine"
#define scriptDoneStr "ScriptDone"
#define visibleStr "visible"
#define equipTypeStr "equipType"
#define jumpStackStr "jumpStack"
#define EachAttackStr "EachAttack"
#define EachDefendStr "EachDefend"
#define EachUseStr "EachUse"
#define EachVictoryStr "EachVictory"
#define CustomNameStr "Name"
#define ParamXStr "XParam"
#define ParamYStr "YParam"
#define ParamWStr "WParam"
#define ParamHStr "HParam"
#define ParamFStr "FParam"
#define MonsterHPMultStr "MonsterHPMultiplier"
#define MonsterATKMultStr "MonsterATKMultiplier"
#define MonsterDEFMultStr "MonsterDEFMultiplier"
#define MonsterGRMultStr "MonsterGRMultiplier"
#define MonsterXPMultStr "MonsterXPMultiplier"
#define ItemMultStr "ItemMultiplier"
#define ItemHPMultStr "ItemHPMultiplier"
#define ItemATKMultStr "ItemATKMultiplier"
#define ItemDEFMultStr "ItemDEFMultiplier"
#define ItemGRMultStr "ItemGRMultiplier"
#define ItemShovelMultStr "ItemShovelMultiplier"
#define SpawnTypeStr "SpawnType"
#define WeaknessStr "Weakness"
#define TooltipStr "Tooltip"
#define TurnDelayStr "TurnDelay"
#define XRelStr "XRel"
#define YRelStr "YRel"
#define MovingRelativeStr "MovingRel"
#define ExitRoomOStr "ExitO"
#define VulnerableStr "Vulnerable"
#define MissionCriticalStr "MissCrit"
#define SafeToPlayerStr "SafeToPlayer"
#define SwordSafeToPlayerStr "SwSafeToPlayer"
#define DefeatedStr "Defeated"
#define ShowStatChangesStr "SStatChanges"
#define InvisibleInspectableStr "InvisibleInspectable"
#define SwordStr "Sword"
#define RestartScriptOnEntranceStr "RestartOnEntrance"
#define GlobalStr "Global"
#define ExecuteScriptOnCombatStr "ESOC"
#define AttackAdjacentStr "AttackAdj"
#define AttackInFrontStr "AttackInFront"
#define AttackInFrontWhenBackIsTurnedStr "AttackInFrontWhenBackIsTurned"
#define FaceTargetStr "FaceTarget"
#define RayGunStr "RayGun"
#define RayBlockingStr "RayBlocking"
#define SurprisedFromBehindStr "SurprisedFromBehind"
#define FaceAwayFromTargetStr "FaceAwayFromTarget"
#define GoblinWeaknessStr "GoblinWeakness"
#define SerpentWeaknessStr "SerpentWeakness"
#define MetalStr "Metal"
#define LuckyGRStr "Lucky"
#define LuckyXPStr "LuckyXP"
#define BriarStr "Briar"
#define NoEnemyDefenseStr "NoEnemyDEF"
#define AttackFirstStr "AttackFirst"
#define AttackLastStr "AttackLast"
#define MovementIQStr "MoveIQ"
#define DropTrapdoorsStr "DropTrapdoors"
#define MoveIntoSwordsStr "MoveIntoSwords"
#define PushObjectsStr "PushObjects"
#define SpawnEggsStr "SpawnEggs"
#define RemovesSwordStr "RemovesSword"
#define ExplosiveKegSafeStr "ExplosiveSafe"
#define CutTarAnywhereStr "CutTarAnywhere"
#define MovementTypeStr "MovementType"
#define WallMirrorSafeStr "WallMirrorSafe"
#define HotTileImmuneStr "HotTileImmune"
#define FiretrapImmuneStr "FiretrapImmune"
#define MistImmuneStr "MistImmune"
#define WallDwellingStr "WallDwelling"
#define SKIP_WHITESPACE(str, index) while (iswspace(str[index])) ++index
//*****************************************************************************
inline bool isVarCharValid(WCHAR wc)
{
return iswalnum(wc) || wc == W_t('_');
}
void LogParseError(const WCHAR* pwStr, const char* message)
{
CFiles f;
string str = UnicodeToUTF8(pwStr);
str += ": ";
str += message;
f.AppendErrorLog(str.c_str());
}
//*****************************************************************************
inline bool multWithClamp(int& val, const int operand)
//Multiplies two integers, ensuring the product doesn't overflow.
//
//Returns: false if actual result can't be given (i.e. value overflowed), otherwise true
{
const double newVal = (double)val * operand;
if (newVal > INT_MAX)
{
val = INT_MAX;
return false;
}
if (newVal < INT_MIN)
{
val = INT_MIN;
return false;
}
val *= operand;
return true;
}
//*****************************************************************************
inline bool bCommandHasData(const UINT eCommand)
//Returns: whether this script command has a data record attached to it
{
switch (eCommand)
{
case CCharacterCommand::CC_AmbientSound:
case CCharacterCommand::CC_AmbientSoundAt:
case CCharacterCommand::CC_PlayVideo:
case CCharacterCommand::CC_SetMusic:
case CCharacterCommand::CC_ImageOverlay:
case CCharacterCommand::CC_WorldMapMusic:
case CCharacterCommand::CC_WorldMapImage:
return true;
default:
return false;
}
}
std::function<bool(int, int)> getComparator(ScriptVars::Comp comparison) {
switch (comparison) {
case ScriptVars::Equals:
default:
return [](int lhs, int rhs) { return lhs == rhs; };
case ScriptVars::Greater:
return [](int lhs, int rhs) { return lhs > rhs; };
case ScriptVars::Less:
return [](int lhs, int rhs) { return lhs < rhs; };
case ScriptVars::GreaterThanOrEqual:
return [](int lhs, int rhs) { return lhs >= rhs; };
case ScriptVars::LessThanOrEqual:
return [](int lhs, int rhs) { return lhs <= rhs; };
case ScriptVars::Inequal:
return [](int lhs, int rhs) { return lhs != rhs; };
}
}
//
//Public methods.
//
//*****************************************************************************
CCharacter::CCharacter(
//Constructor.
//
//Params:
CCurrentGame *pSetCurrentGame) //(in) If NULL (default) then
// class can only be used for
// accessing data, and not
// for game processing.
: CPlayerDouble(M_CHARACTER, pSetCurrentGame,
9999) //put last in process sequence so all cue events will have
//occurred and can be detected by the time Process() is called
, pCustomChar(NULL)
, dwScriptID(0)
, wIdentity(M_NONE)
, wInitialIdentity(M_NONE)
, wLogicalIdentity(M_NONE)
, bVisible(false)
, bInvisibleInspectable(false)
, bScriptDone(false), bReplaced(false), bGlobal(false)
, bYesNoQuestion(false)
, bPlayerTouchedMe(false)
, bAttacked(false)
, equipType(ScriptFlag::NotEquipment)
, movementIQ(SmartDiagonalOnly)
, bMovementChanged(false)
, worldMapID(0)
, wCurrentCommandIndex(0)
, wTurnDelay(0)
, wLastSO(NO_ORIENTATION), wSO(NO_ORIENTATION)
, wXRel(0), wYRel(0)
, bMovingRelative(false)
, wExitingRoomO(NO_ORIENTATION)
, bVulnerable(true)
, bMissionCritical(false)
, bSafeToPlayer(false)
, bSwordSafeToPlayer(false)
, bDefeated(false)
, bShowStatChanges(true)
, bGhostImage(false)
, bRestartScriptOnRoomEntrance(false)
, bExecuteScriptOnCombat(true)
, bAttackAdjacent(false)
, bAttackInFront(false)
, bAttackInFrontWhenBackIsTurned(false)
, bFaceAwayFromTarget(false)
, bFaceTarget(false)
, bHasRayGun(false)
, bHasRayBlocking(false)
, bSurprisedFromBehind(false)
, bGoblinWeakness(false)
, bSerpentWeakness(false)
, bMetal(false), bLuckyGR(false), bLuckyXP(false), bBriar(false), bNoEnemyDEF(false)
, bAttackFirst(false), bAttackLast(false)
, bDropTrapdoors(false), bMoveIntoSwords(false), bPushObjects(false), bSpawnEggs(false)
, bRemovesSword(false) , bExplosiveSafe(false), bMinimapTreasure(false), bCutTarAnywhere(false)
, bWallMirrorSafe(false), bHotTileImmune(false), bFiretrapImmune(false), bMistImmune(false)
, bWallDwelling(false)
, wJumpLabel(0)
, bWaitingForCueEvent(false)
, bIfBlock(false)
, eachAttackLabelIndex(NO_LABEL), eachDefendLabelIndex(NO_LABEL), eachUseLabelIndex(NO_LABEL)
, eachVictoryLabelIndex(NO_LABEL)
, bIsDefaultScript(false)
, customSpeechColor(0)
, wLastSpeechLineNumber(0)
, color(0), hue(0), saturation(0), sword(NPC_DEFAULT_SWORD)
, paramX(NO_OVERRIDE), paramY(NO_OVERRIDE), paramW(NO_OVERRIDE), paramH(NO_OVERRIDE), paramF(NO_OVERRIDE)
, monsterHPmult(100), monsterATKmult(100), monsterDEFmult(100), monsterGRmult(100), monsterXPmult(100)
, itemMult(100), itemHPmult(100), itemATKmult(100), itemDEFmult(100), itemGRmult(100), itemShovelMult(100)
, wSpawnType(-1)
{
}
//*****************************************************************************
void CCharacter::ChangeHold(
//Call this when a character is being moved from an old hold to a new hold.
const CDbHold* pSrcHold, //may be NULL. This indicates character is copied within the same hold.
CDbHold* pDestHold,
CImportInfo& info, //(in/out) media copy info
const bool bGetNewScriptID) //[default=true]
{
ASSERT(pDestHold);
if (bGetNewScriptID)
this->dwScriptID = pDestHold->GetNewScriptID();
ChangeHoldForCommands(this->commands, pSrcHold, pDestHold, info, true);
SyncCustomCharacterData(pSrcHold, pDestHold, info);
}
//*****************************************************************************
void CCharacter::SyncCustomCharacterData(
const CDbHold* pSrcHold,
CDbHold* pDestHold,
CImportInfo& info)
{
SyncCustomCharacterData(this->wLogicalIdentity, pSrcHold, pDestHold, info);
this->wInitialIdentity = this->wLogicalIdentity;
}
//Returns: whether something was changed
void CCharacter::SyncCustomCharacterData(
UINT& wLogicalIdentity,
const CDbHold* pSrcHold,
CDbHold* pDestHold,
CImportInfo& info)
{
if (pSrcHold)
{
const HoldCharacter *pCustomChar = pSrcHold->GetCharacterConst(wLogicalIdentity);
if (pCustomChar)
{
//Match on character name.
UINT charID = pDestHold->GetCharacterID(pCustomChar->charNameText.c_str());
if (!charID)
{
//Copy custom character data to new hold.
charID = pDestHold->AddCharacter(pCustomChar->charNameText.c_str());
ASSERT(charID);
HoldCharacter *pDestCustomChar = pDestHold->GetCharacter(charID);
ASSERT(pDestCustomChar);
pDestCustomChar->animationSpeed = pCustomChar->animationSpeed;
pDestCustomChar->wType = pCustomChar->wType;
pDestCustomChar->dwDataID_Avatar = pCustomChar->dwDataID_Avatar;
pDestCustomChar->dwDataID_Tiles = pCustomChar->dwDataID_Tiles;
pDestCustomChar->ExtraVars = pCustomChar->ExtraVars;
pDestCustomChar->ExtraVars.SetVar(initialIdStr, charID);
pSrcHold->CopyCustomCharacterData(*pDestCustomChar, pDestHold, info);
}
wLogicalIdentity = charID;
}
}
}
void SyncEntranceID(CImportInfo& info, UINT& entranceID)
{
if (entranceID && entranceID != (UINT)EXIT_PRIOR_LOCATION) {
PrimaryKeyMap::const_iterator newID = info.EntranceIDMap.find(entranceID);
if (newID != info.EntranceIDMap.end()) {
entranceID = newID->second;
} else {
entranceID = 0; //end hold
}
}
}
void CCharacter::ChangeHoldForCommands(
COMMAND_VECTOR& commands,
const CDbHold* pOldHold, CDbHold* pNewHold,
CImportInfo& info,
bool bUpdateSpeech)
{
const bool bDifferentHold = pOldHold && pOldHold->dwHoldID != pNewHold->dwHoldID;
for (UINT wIndex=0; wIndex<commands.size(); ++wIndex)
{
CCharacterCommand& c = commands[wIndex];
if (bDifferentHold)
{
//Merge script vars and IDs from a different source hold.
switch (c.command)
{
case CCharacterCommand::CC_WaitForVar:
case CCharacterCommand::CC_VarSet:
case CCharacterCommand::CC_VarSetAt:
case CCharacterCommand::CC_ArrayVarSet:
case CCharacterCommand::CC_ArrayVarSetAt:
case CCharacterCommand::CC_ClearArrayVar:
case CCharacterCommand::CC_WaitForArrayEntry:
case CCharacterCommand::CC_CountArrayEntries:
{
//Update var refs.
UINT wRef = c.getVarID();
if (wRef >= (UINT)ScriptVars::FirstPredefinedVar)
break; //predefined var IDs remain the same
const WCHAR *pVarName = pOldHold->GetVarName(wRef);
UINT uVarID = pNewHold->GetVarID(pVarName);
if (!uVarID && pVarName)
{
//A var with this (valid) name doesn't exist in the
//destination hold -- add one.
uVarID = pNewHold->AddVar(pVarName);
}
//Update the var ID to match the ID of the var with this
//name in the destination hold.
c.setVarID(uVarID);
}
break;
case CCharacterCommand::CC_AmbientSound:
case CCharacterCommand::CC_AmbientSoundAt:
case CCharacterCommand::CC_PlayVideo:
case CCharacterCommand::CC_ImageOverlay:
//Make a copy of the media object in the new hold.
CDbData::CopyObject(info, c.w, pNewHold->dwHoldID);
break;
case CCharacterCommand::CC_SetMusic:
CDbData::CopyObject(info, c.w, pNewHold->dwHoldID);
break;
case CCharacterCommand::CC_SetNPCAppearance:
case CCharacterCommand::CC_SetPlayerAppearance:
SyncCustomCharacterData(c.x, pOldHold, pNewHold, info);
break;
case CCharacterCommand::CC_GenerateEntity:
SyncCustomCharacterData(c.h, pOldHold, pNewHold, info);
break;
case CCharacterCommand::CC_Equipment:
{
//Sync character data if the command is using reference equipment
ScriptFlag::TransactionType trans = (ScriptFlag::TransactionType)c.w;
if (trans == ScriptFlag::Trade || trans == ScriptFlag::QueryStatus ||
trans == ScriptFlag::Generate) {
SyncCustomCharacterData(c.y, pOldHold, pNewHold, info);
}
}
break;
case CCharacterCommand::CC_LevelEntrance:
SyncEntranceID(info, c.x);
break;
case CCharacterCommand::CC_Speech:
if (c.pSpeech)
SyncCustomCharacterData(c.pSpeech->wCharacter, pOldHold, pNewHold, info);
break;
case CCharacterCommand::CC_WorldMapMusic:
CDbData::CopyObject(info, c.y, pNewHold->dwHoldID);
break;
case CCharacterCommand::CC_WorldMapIcon:
SyncCustomCharacterData(c.h, pOldHold, pNewHold, info);
SyncEntranceID(info, c.w);
break;
case CCharacterCommand::CC_WorldMapImage:
CDbData::CopyObject(info, c.h, pNewHold->dwHoldID);
SyncEntranceID(info, c.w);
break;
default: break;
}
}
//Point all data objects to the destination hold.
if (c.pSpeech && bUpdateSpeech)
{
CDbDatum *pSound = (CDbDatum*)c.pSpeech->GetSound();
if (pSound)
{
pSound->dwHoldID = pNewHold->dwHoldID;
pSound->Update();
}
}
}
}
//*****************************************************************************
WSTRING CCharacter::getPredefinedVar(const UINT varIndex) const
{
WSTRING wstr;
if (ScriptVars::IsStringVar(ScriptVars::Predefined(varIndex))) {
wstr = getPredefinedVarString(varIndex);
}
else {
WCHAR wIntText[20];
const UINT val = getPredefinedVarInt(varIndex);
wstr = _itoW(int(val), wIntText, 10);
}
return wstr;
}
//*****************************************************************************
UINT CCharacter::getPredefinedVarInt(const UINT varIndex) const
//Returns: the value of the predefined var with this relative index
{
ASSERT(this->pCurrentGame);
ASSERT(varIndex >= (UINT)ScriptVars::FirstPredefinedVar);
switch (varIndex)
{
case (UINT)ScriptVars::P_MONSTER_HP:
return this->HP;
case (UINT)ScriptVars::P_MONSTER_ATK:
return this->ATK;
case (UINT)ScriptVars::P_MONSTER_DEF:
return this->DEF;
case (UINT)ScriptVars::P_MONSTER_GOLD:
return this->GOLD;
case (UINT)ScriptVars::P_MONSTER_XP:
return this->XP;
case (UINT)ScriptVars::P_MONSTER_COLOR:
return this->color;
case (UINT)ScriptVars::P_MONSTER_SWORD:
return this->sword;
case (UINT)ScriptVars::P_MONSTER_HUE:
return this->hue;
case (UINT)ScriptVars::P_MONSTER_SATURATION:
return this->saturation;
//Room position.
case (UINT)ScriptVars::P_MONSTER_X:
return this->wX;
case (UINT)ScriptVars::P_MONSTER_Y:
return this->wY;
case (UINT)ScriptVars::P_MONSTER_O:
return this->wO;
//Script parameter overrides.
case (UINT)ScriptVars::P_SCRIPT_X:
return this->paramX;
case (UINT)ScriptVars::P_SCRIPT_Y:
return this->paramY;
case (UINT)ScriptVars::P_SCRIPT_W:
return this->paramW;
case (UINT)ScriptVars::P_SCRIPT_H:
return this->paramH;
case (UINT)ScriptVars::P_SCRIPT_F:
return this->paramF;
//Local statistic modifiers
case (UINT)ScriptVars::P_SCRIPT_MONSTER_HP_MULT:
return this->monsterHPmult;
case (UINT)ScriptVars::P_SCRIPT_MONSTER_ATK_MULT:
return this->monsterATKmult;
case (UINT)ScriptVars::P_SCRIPT_MONSTER_DEF_MULT:
return this->monsterDEFmult;
case (UINT)ScriptVars::P_SCRIPT_MONSTER_GOLD_MULT:
return this->monsterGRmult;
case (UINT)ScriptVars::P_SCRIPT_MONSTER_XP_MULT:
return this->monsterXPmult;
case (UINT)ScriptVars::P_SCRIPT_ITEM_MULT:
return this->itemMult;
case (UINT)ScriptVars::P_SCRIPT_ITEM_HP_MULT:
return this->itemHPmult;
case (UINT)ScriptVars::P_SCRIPT_ITEM_ATK_MULT:
return this->itemATKmult;
case (UINT)ScriptVars::P_SCRIPT_ITEM_DEF_MULT:
return this->itemDEFmult;
case (UINT)ScriptVars::P_SCRIPT_ITEM_GR_MULT:
return this->itemGRmult;
case (UINT)ScriptVars::P_SCRIPT_ITEM_SHOVEL_MULT:
return this->itemShovelMult;
//Spawn type
case (UINT)ScriptVars::P_SCRIPT_MONSTER_SPAWN:
return this->wSpawnType;
//Hidden global values
case (UINT)ScriptVars::P_TOTALTIME:
return 0;
default:
return this->pCurrentGame->getVar(ScriptVars::Predefined(varIndex));
}
}
//*****************************************************************************
WSTRING CCharacter::getPredefinedVarString(const UINT varIndex) const
//Returns: the value of the predefined var with this relative index
{
ASSERT(this->pCurrentGame);
ASSERT(varIndex >= (UINT)ScriptVars::FirstPredefinedVar);
switch (varIndex)
{
case (UINT)ScriptVars::P_MONSTER_NAME:
return this->customName;
case (UINT)ScriptVars::P_MONSTER_CUSTOM_WEAKNESS:
return this->customWeakness;
case (UINT)ScriptVars::P_MONSTER_CUSTOM_DESCRIPTION:
return this->customDescription;
default:
ASSERT(!"getPredefinedStringVar val not supported");
return WSTRING();
}
}
//*****************************************************************************
int CCharacter::getArrayValue(
const ScriptArrayMap& scriptArrays, //[in] map of variable ids to script arrays
const UINT& varId, //[in] id of script array to read
const int arrayIndex //[in] index of value to get
)
//Returns: the value at the given index in the specified script array.
//If the value has not been set, a default value of 0 is returned.
{
if (!ScriptVars::IsIndexInArrayRange(arrayIndex)) {
return 0; //Out of range value is always 0
}
ScriptArrayMap::const_iterator array = scriptArrays.find(varId);
if (array == scriptArrays.end()) {
return 0; //Array hasn't been initialized yet, so return 0 as default.
}
map<int, int>::const_iterator value = array->second.find(arrayIndex);
if (value == array->second.end()) {
return 0; //Value hasn't been set yet, so return 0 as default.
}
return value->second;
}
//*****************************************************************************
bool CCharacter::setPredefinedVarInt(const UINT varIndex, const UINT val, CCueEvents& CueEvents)
//Sets the value of the predefined var with this relative index to the specified value
//Returns: false if command cannot be allowed to execute (e.g., killing player on turn 0), otherwise true
{
ASSERT(varIndex >= (UINT)ScriptVars::FirstPredefinedVar);
switch (varIndex)
{
case (UINT)ScriptVars::P_MONSTER_HP:
if ((int)val > 0) //guard against negative HP (only allow up to max int)
this->HP = val;
else
this->HP = 0;
//When HP is set to a positive value, the defeated flag is reset so the NPC-monster can fight again.
if (this->HP > 0)
this->bDefeated = false;
break;
case (UINT)ScriptVars::P_MONSTER_ATK:
this->ATK = val;
break;
case (UINT)ScriptVars::P_MONSTER_DEF:
this->DEF = val;
break;
case (UINT)ScriptVars::P_MONSTER_GOLD:
this->GOLD = val;
break;
case (UINT)ScriptVars::P_MONSTER_XP:
this->XP = val;
break;
case (UINT)ScriptVars::P_MONSTER_COLOR:
this->color = val;
break;
case (UINT)ScriptVars::P_MONSTER_SWORD:
this->sword = val;
break;
case (UINT)ScriptVars::P_MONSTER_HUE:
this->SetHue(val);
break;
case (UINT)ScriptVars::P_MONSTER_SATURATION:
this->SetSaturation(val);
break;
//Room position.
case (UINT)ScriptVars::P_PLAYER_X:
const_cast<CCurrentGame*>(this->pCurrentGame)->TeleportPlayer(val, this->pCurrentGame->pPlayer->wY, CueEvents);
break;
case (UINT)ScriptVars::P_PLAYER_Y:
const_cast<CCurrentGame*>(this->pCurrentGame)->TeleportPlayer(this->pCurrentGame->pPlayer->wX, val, CueEvents);
break;
case (UINT)ScriptVars::P_PLAYER_O:
if (IsValidOrientation(val) && val != NO_ORIENTATION)
this->pCurrentGame->pPlayer->wO = val;
break;
case (UINT)ScriptVars::P_MONSTER_X:
{
//Ensure square is valid and available.
const CDbRoom& room = *(this->pCurrentGame->pRoom);
if (room.IsValidColRow(val, this->wY) &&
(!IsVisible() || (!room.GetMonsterAtSquare(val, this->wY) &&
!this->pCurrentGame->IsPlayerAt(val, this->wY))))
{
this->wPrevX = this->wX;
TeleportCharacter(val, this->wY, CueEvents);
}
}
break;
case (UINT)ScriptVars::P_MONSTER_Y:
{
//Ensure square is valid and available.
const CDbRoom& room = *(this->pCurrentGame->pRoom);
if (room.IsValidColRow(this->wX, val) &&
(!IsVisible() || (!room.GetMonsterAtSquare(this->wX, val) &&
!this->pCurrentGame->IsPlayerAt(this->wX, val))))
{
this->wPrevY = this->wY;
TeleportCharacter(this->wX, val, CueEvents);
}
}
break;
case (UINT)ScriptVars::P_MONSTER_O:
if (IsValidOrientation(val) && val != NO_ORIENTATION)
this->wO = val;
break;
//Script parameter overrides.
case (UINT)ScriptVars::P_SCRIPT_X:
this->paramX = val;
break;
case (UINT)ScriptVars::P_SCRIPT_Y:
this->paramY = val;
break;
case (UINT)ScriptVars::P_SCRIPT_W:
this->paramW = val;
break;
case (UINT)ScriptVars::P_SCRIPT_H:
this->paramH = val;
break;
case (UINT)ScriptVars::P_SCRIPT_F:
this->paramF = val;
break;
//Local statistic modifiers
case (UINT)ScriptVars::P_SCRIPT_MONSTER_HP_MULT:
this->monsterHPmult = val;
break;
case (UINT)ScriptVars::P_SCRIPT_MONSTER_ATK_MULT:
this->monsterATKmult = val;
break;
case (UINT)ScriptVars::P_SCRIPT_MONSTER_DEF_MULT:
this->monsterDEFmult = val;
break;
case (UINT)ScriptVars::P_SCRIPT_MONSTER_GOLD_MULT:
this->monsterGRmult = val;
break;
case (UINT)ScriptVars::P_SCRIPT_MONSTER_XP_MULT:
this->monsterXPmult = val;
break;
case (UINT)ScriptVars::P_SCRIPT_ITEM_MULT:
this->itemMult = val;
break;
case (UINT)ScriptVars::P_SCRIPT_ITEM_HP_MULT:
this->itemHPmult = val;
break;
case (UINT)ScriptVars::P_SCRIPT_ITEM_ATK_MULT:
this->itemATKmult = val;
break;
case (UINT)ScriptVars::P_SCRIPT_ITEM_DEF_MULT:
this->itemDEFmult = val;
break;
case (UINT)ScriptVars::P_SCRIPT_ITEM_GR_MULT:
this->itemGRmult = val;
break;
case (UINT)ScriptVars::P_SCRIPT_ITEM_SHOVEL_MULT:
this->itemShovelMult = val;
break;
//Spawn type
case (UINT)ScriptVars::P_SCRIPT_MONSTER_SPAWN:
this->wSpawnType = val;
break;
//Combat enemy stats.
case (UINT)ScriptVars::P_ENEMY_HP:
case (UINT)ScriptVars::P_ENEMY_ATK:
case (UINT)ScriptVars::P_ENEMY_DEF:
case (UINT)ScriptVars::P_ENEMY_GOLD:
case (UINT)ScriptVars::P_ENEMY_XP:
{
//Do nothing if there is no current combat enemy.
if (!this->pCurrentGame->InCombat())
break;
CCombat *pCombat = this->pCurrentGame->pCombat;
ASSERT(pCombat);
CMonster *pMonster = pCombat->pMonster;
ASSERT(pMonster);
bool bRefreshCombat = false;
switch (varIndex)
{
case (UINT)ScriptVars::P_ENEMY_HP: pMonster->HP = (int)val > 0 ? val : 0; break;
case (UINT)ScriptVars::P_ENEMY_ATK:
pMonster->ATK = val;
bRefreshCombat = true;
break;
case (UINT)ScriptVars::P_ENEMY_DEF:
pMonster->DEF = val;
bRefreshCombat = true;
break;
case (UINT)ScriptVars::P_ENEMY_GOLD: pMonster->GOLD = val; break;
case (UINT)ScriptVars::P_ENEMY_XP: pMonster->XP = val; break;
}
if (bRefreshCombat)
pCombat->InitMonsterStats(false);
}
break;
//Player equipment values.
case (UINT)ScriptVars::P_WEAPON_ATK:
case (UINT)ScriptVars::P_WEAPON_DEF:
case (UINT)ScriptVars::P_WEAPON_GR:
case (UINT)ScriptVars::P_ARMOR_ATK:
case (UINT)ScriptVars::P_ARMOR_DEF:
case (UINT)ScriptVars::P_ARMOR_GR:
case (UINT)ScriptVars::P_ACCESSORY_ATK:
case (UINT)ScriptVars::P_ACCESSORY_DEF:
case (UINT)ScriptVars::P_ACCESSORY_GR:
{
UINT type = 0;
switch (varIndex)
{
case (UINT)ScriptVars::P_WEAPON_ATK: case (UINT)ScriptVars::P_WEAPON_DEF:
case (UINT)ScriptVars::P_WEAPON_GR: type = ScriptFlag::Weapon; break;
case (UINT)ScriptVars::P_ARMOR_ATK: case (UINT)ScriptVars::P_ARMOR_DEF:
case (UINT)ScriptVars::P_ARMOR_GR: type = ScriptFlag::Armor; break;
case (UINT)ScriptVars::P_ACCESSORY_ATK: case (UINT)ScriptVars::P_ACCESSORY_DEF:
case (UINT)ScriptVars::P_ACCESSORY_GR: type = ScriptFlag::Accessory; break;
}
CCharacter* pCharacter = this->pCurrentGame->getCustomEquipment(type);
if (!pCharacter)
break; //only custom equipment may have its values modified
switch (varIndex)
{
case (UINT)ScriptVars::P_WEAPON_ATK: case (UINT)ScriptVars::P_ARMOR_ATK:
case (UINT)ScriptVars::P_ACCESSORY_ATK: pCharacter->ATK = val; break;
case (UINT)ScriptVars::P_WEAPON_DEF: case (UINT)ScriptVars::P_ARMOR_DEF:
case (UINT)ScriptVars::P_ACCESSORY_DEF: pCharacter->DEF = val; break;
case (UINT)ScriptVars::P_WEAPON_GR: case (UINT)ScriptVars::P_ARMOR_GR:
case (UINT)ScriptVars::P_ACCESSORY_GR: pCharacter->GOLD = val; break;
}
}
break;
case (UINT)ScriptVars::P_MONSTER_NAME:
case (UINT)ScriptVars::P_MONSTER_CUSTOM_WEAKNESS:
case (UINT)ScriptVars::P_MONSTER_CUSTOM_DESCRIPTION:
//string vars
break;
//Stat modifications that may display the change as a special effect.
default:
{
CSwordsman &p = *(const_cast<CCurrentGame*>(this->pCurrentGame)->pPlayer);
PlayerStats& st = p.st;
//Bounds checks
UINT newVal = val;
switch (varIndex)
{
case (UINT)ScriptVars::P_YKEY:
case (UINT)ScriptVars::P_GKEY:
case (UINT)ScriptVars::P_BKEY:
case (UINT)ScriptVars::P_SKEY:
case (UINT)ScriptVars::P_SHOVEL:
if (int(val) < 0)
newVal = 0;
break;
default: break;
}
if (this->bShowStatChanges)
{
const UINT oldVal = st.getVar(ScriptVars::Predefined(varIndex));
int delta = int(newVal) - int(oldVal);
CombatEffectType type = CET_NODAMAGE;
switch (varIndex)
{
case (UINT)ScriptVars::P_HP:
if (int(newVal) <= 0 && this->pCurrentGame->wTurnNo == 0) //forbid killing player on turn 0 (avoids respawn loop)
return false;
type = delta < 0 ? CET_HARM : CET_HEAL;
if (delta < 0)
delta = -delta;
break;
case (UINT)ScriptVars::P_ATK:
type = CET_ATK;
break;
case (UINT)ScriptVars::P_DEF:
type = CET_DEF;
break;
case (UINT)ScriptVars::P_GOLD:
type = CET_GOLD;
break;
case (UINT)ScriptVars::P_XP:
type = CET_XP;
break;
case (UINT)ScriptVars::P_YKEY:
type = CET_YKEY;
break;
case (UINT)ScriptVars::P_GKEY:
type = CET_GKEY;
break;
case (UINT)ScriptVars::P_BKEY:
type = CET_BKEY;
break;
case (UINT)ScriptVars::P_SKEY:
type = CET_SKEY;
break;
case (UINT)ScriptVars::P_SHOVEL:
type = CET_SHOVEL;
break;
case (UINT)ScriptVars::P_MONSTER_ATK_MULT:
case (UINT)ScriptVars::P_MONSTER_DEF_MULT:
case (UINT)ScriptVars::P_MONSTER_HP_MULT:
case (UINT)ScriptVars::P_MONSTER_GOLD_MULT:
case (UINT)ScriptVars::P_MONSTER_XP_MULT:
case (UINT)ScriptVars::P_ITEM_MULT:
case (UINT)ScriptVars::P_ITEM_HP_MULT:
case (UINT)ScriptVars::P_ITEM_ATK_MULT:
case (UINT)ScriptVars::P_ITEM_DEF_MULT:
case (UINT)ScriptVars::P_ITEM_GR_MULT:
case (UINT)ScriptVars::P_ITEM_SHOVEL_MULT:
case (UINT)ScriptVars::P_HOTTILE:
case (UINT)ScriptVars::P_EXPLOSION:
case (UINT)ScriptVars::P_BEAM:
case (UINT)ScriptVars::P_FIRETRAP:
case (UINT)ScriptVars::P_MUD_SPAWN:
case (UINT)ScriptVars::P_TAR_SPAWN:
case (UINT)ScriptVars::P_GEL_SPAWN:
case (UINT)ScriptVars::P_QUEEN_SPAWN:
case (UINT)ScriptVars::P_SCORE_HP:
case (UINT)ScriptVars::P_SCORE_ATK:
case (UINT)ScriptVars::P_SCORE_DEF:
case (UINT)ScriptVars::P_SCORE_YKEY:
case (UINT)ScriptVars::P_SCORE_GKEY:
case (UINT)ScriptVars::P_SCORE_BKEY:
case (UINT)ScriptVars::P_SCORE_SKEY:
case (UINT)ScriptVars::P_SCORE_GOLD:
case (UINT)ScriptVars::P_SCORE_XP:
case (UINT)ScriptVars::P_SCORE_SHOVEL:
case (UINT)ScriptVars::P_MUD_SWAP:
case (UINT)ScriptVars::P_TAR_SWAP:
case (UINT)ScriptVars::P_GEL_SWAP:
case (UINT)ScriptVars::P_RETURN_X:
//display nothing
break;
case (UINT)ScriptVars::P_SWORD:
if (!const_cast<CCurrentGame*>(this->pCurrentGame)->IsEquipmentValid(newVal, ScriptFlag::Weapon))
return true;
break;
case (UINT)ScriptVars::P_SHIELD:
if (!const_cast<CCurrentGame*>(this->pCurrentGame)->IsEquipmentValid(newVal, ScriptFlag::Armor))
return true;
break;
case (UINT)ScriptVars::P_ACCESSORY:
if (!const_cast<CCurrentGame*>(this->pCurrentGame)->IsEquipmentValid(newVal, ScriptFlag::Accessory))
return true;
break;
case (UINT)ScriptVars::P_SPEED:
case (UINT)ScriptVars::P_TOTALMOVES:
case (UINT)ScriptVars::P_TOTALTIME:
case (UINT)ScriptVars::P_LEVEL_MULT:
case (UINT)ScriptVars::P_ROOM_X:
case (UINT)ScriptVars::P_ROOM_Y:
case (UINT)ScriptVars::P_TOTAL_ATK:
case (UINT)ScriptVars::P_TOTAL_DEF:
//cannot alter
break;
default:
ASSERT(!"Unsupported var display");
break;
}
if (type != CET_NODAMAGE && delta != 0)
{
//If player is in room, show stat changes where player is.
//Otherwise, show them where this NPC is.
CEntity *pEntity;
if (p.IsInRoom())
pEntity = &p;
else pEntity = this;
CueEvents.Add(CID_EntityAffected, new CCombatEffect(pEntity, type, delta), true);
}
}
//Check for special things that need to happen as a result of altering
//these vars.
CCurrentGame *pGame = const_cast<CCurrentGame*>(this->pCurrentGame);