forked from sdlpal/sdlpal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.c
3609 lines (3145 loc) · 94.5 KB
/
script.c
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
/* -*- mode: c; tab-width: 4; c-basic-offset: 4; c-file-style: "linux" -*- */
//
// Copyright (c) 2009-2011, Wei Mingzhi <[email protected]>.
// Copyright (c) 2011-2020, SDLPAL development team.
// All rights reserved.
//
// This file is part of SDLPAL.
//
// SDLPAL 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 3 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, see <http://www.gnu.org/licenses/>.
//
// Based on PALx Project by palxex.
// Copyright (c) 2006-2008, Pal Lockheart <[email protected]>.
//
#include "main.h"
BOOL g_fScriptSuccess = TRUE;
static int g_iCurEquipPart = -1;
static BOOL
PAL_NPCWalkTo(
WORD wEventObjectID,
INT x,
INT y,
INT h,
INT iSpeed
)
/*++
Purpose:
Make the specified event object walk to the map position specified by (x, y, h)
at the speed of iSpeed.
Parameters:
[IN] wEventObjectID - the event object to move.
[IN] x - Column number of the tile.
[IN] y - Line number in the map.
[IN] h - Each line in the map has two lines of tiles, 0 and 1.
(See map.h for details.)
[IN] iSpeed - the speed to move.
Return value:
TRUE if the event object has successfully moved to the specified position,
FALSE if still need more moving.
--*/
{
LPEVENTOBJECT pEvtObj;
int xOffset, yOffset;
pEvtObj = &(gpGlobals->g.lprgEventObject[wEventObjectID - 1]);
xOffset = (x * 32 + h * 16) - pEvtObj->x;
yOffset = (y * 16 + h * 8) - pEvtObj->y;
if (yOffset < 0)
{
pEvtObj->wDirection = ((xOffset < 0) ? kDirWest : kDirNorth);
}
else
{
pEvtObj->wDirection = ((xOffset < 0) ? kDirSouth: kDirEast);
}
if (abs(xOffset) < iSpeed * 2 || abs(yOffset) < iSpeed * 2)
{
pEvtObj->x = x * 32 + h * 16;
pEvtObj->y = y * 16 + h * 8;
}
else
{
PAL_NPCWalkOneStep(wEventObjectID, iSpeed);
}
if (pEvtObj->x == x * 32 + h * 16 && pEvtObj->y == y * 16 + h * 8)
{
pEvtObj->wCurrentFrameNum = 0;
return TRUE;
}
return FALSE;
}
static VOID
PAL_PartyWalkTo(
INT x,
INT y,
INT h,
INT iSpeed
)
/*++
Purpose:
Make the party walk to the map position specified by (x, y, h)
at the speed of iSpeed.
Parameters:
[IN] x - Column number of the tile.
[IN] y - Line number in the map.
[IN] h - Each line in the map has two lines of tiles, 0 and 1.
(See map.h for details.)
[IN] iSpeed - the speed to move.
Return value:
None.
--*/
{
int xOffset, yOffset, i, dx, dy;
DWORD t;
xOffset = x * 32 + h * 16 - PAL_X(gpGlobals->viewport) - PAL_X(gpGlobals->partyoffset);
yOffset = y * 16 + h * 8 - PAL_Y(gpGlobals->viewport) - PAL_Y(gpGlobals->partyoffset);
t = 0;
while (xOffset != 0 || yOffset != 0)
{
PAL_DelayUntil(t);
t = SDL_GetTicks() + FRAME_TIME;
//
// Store trail
//
for (i = 3; i >= 0; i--)
{
gpGlobals->rgTrail[i + 1] = gpGlobals->rgTrail[i];
}
gpGlobals->rgTrail[0].wDirection = gpGlobals->wPartyDirection;
gpGlobals->rgTrail[0].x = PAL_X(gpGlobals->viewport) + PAL_X(gpGlobals->partyoffset);
gpGlobals->rgTrail[0].y = PAL_Y(gpGlobals->viewport) + PAL_Y(gpGlobals->partyoffset);
if (yOffset < 0)
{
gpGlobals->wPartyDirection = ((xOffset < 0) ? kDirWest : kDirNorth);
}
else
{
gpGlobals->wPartyDirection = ((xOffset < 0) ? kDirSouth: kDirEast);
}
dx = PAL_X(gpGlobals->viewport);
dy = PAL_Y(gpGlobals->viewport);
if (abs(xOffset) <= iSpeed * 2)
{
dx += xOffset;
}
else
{
dx += iSpeed * (xOffset < 0 ? -2 : 2);
}
if (abs(yOffset) <= iSpeed)
{
dy += yOffset;
}
else
{
dy += iSpeed * (yOffset < 0 ? -1 : 1);
}
//
// Move the viewport
//
gpGlobals->viewport = PAL_XY(dx, dy);
PAL_UpdatePartyGestures(TRUE);
PAL_GameUpdate(FALSE);
PAL_MakeScene();
VIDEO_UpdateScreen(NULL);
xOffset = x * 32 + h * 16 - PAL_X(gpGlobals->viewport) - PAL_X(gpGlobals->partyoffset);
yOffset = y * 16 + h * 8 - PAL_Y(gpGlobals->viewport) - PAL_Y(gpGlobals->partyoffset);
}
PAL_UpdatePartyGestures(FALSE);
}
static VOID
PAL_PartyRideEventObject(
WORD wEventObjectID,
INT x,
INT y,
INT h,
INT iSpeed
)
/*++
Purpose:
Move the party to the specified position, riding the specified event object.
Parameters:
[IN] wEventObjectID - the event object to be ridden.
[IN] x - Column number of the tile.
[IN] y - Line number in the map.
[IN] h - Each line in the map has two lines of tiles, 0 and 1.
(See map.h for details.)
[IN] iSpeed - the speed to move.
Return value:
TRUE if the party and event object has successfully moved to the specified
position, FALSE if still need more moving.
--*/
{
int xOffset, yOffset, dx, dy, i;
DWORD t;
LPEVENTOBJECT p;
p = &(gpGlobals->g.lprgEventObject[wEventObjectID - 1]);
xOffset = x * 32 + h * 16 - PAL_X(gpGlobals->viewport) - PAL_X(gpGlobals->partyoffset);
yOffset = y * 16 + h * 8 - PAL_Y(gpGlobals->viewport) - PAL_Y(gpGlobals->partyoffset);
t = 0;
while (xOffset != 0 || yOffset != 0)
{
PAL_DelayUntil(t);
t = SDL_GetTicks() + FRAME_TIME;
if (yOffset < 0)
{
gpGlobals->wPartyDirection = ((xOffset < 0) ? kDirWest : kDirNorth);
}
else
{
gpGlobals->wPartyDirection = ((xOffset < 0) ? kDirSouth: kDirEast);
}
if (abs(xOffset) > iSpeed * 2)
{
dx = iSpeed * (xOffset < 0 ? -2 : 2);
}
else
{
dx = xOffset;
}
if (abs(yOffset) > iSpeed)
{
dy = iSpeed * (yOffset < 0 ? -1 : 1);
}
else
{
dy = yOffset;
}
//
// Store trail
//
for (i = 3; i >= 0; i--)
{
gpGlobals->rgTrail[i + 1] = gpGlobals->rgTrail[i];
}
gpGlobals->rgTrail[0].wDirection = gpGlobals->wPartyDirection;
gpGlobals->rgTrail[0].x = PAL_X(gpGlobals->viewport) + dx + PAL_X(gpGlobals->partyoffset);
gpGlobals->rgTrail[0].y = PAL_Y(gpGlobals->viewport) + dy + PAL_Y(gpGlobals->partyoffset);
//
// Move the viewport
//
gpGlobals->viewport =
PAL_XY(PAL_X(gpGlobals->viewport) + dx, PAL_Y(gpGlobals->viewport) + dy);
p->x += dx;
p->y += dy;
PAL_GameUpdate(FALSE);
PAL_MakeScene();
VIDEO_UpdateScreen(NULL);
xOffset = x * 32 + h * 16 - PAL_X(gpGlobals->viewport) - PAL_X(gpGlobals->partyoffset);
yOffset = y * 16 + h * 8 - PAL_Y(gpGlobals->viewport) - PAL_Y(gpGlobals->partyoffset);
}
}
static VOID
PAL_MonsterChasePlayer(
WORD wEventObjectID,
WORD wSpeed,
WORD wChaseRange,
BOOL fFloating
)
/*++
Purpose:
Make the specified event object chase the players.
Parameters:
[IN] wEventObjectID - the event object ID of the monster.
[IN] wSpeed - the speed of chasing.
[IN] wChaseRange - sensitive range of the monster.
[IN] fFloating - TRUE if monster is floating (i.e., ignore the obstacles)
Return value:
None.
--*/
{
LPEVENTOBJECT pEvtObj = &gpGlobals->g.lprgEventObject[wEventObjectID - 1];
WORD wMonsterSpeed = 0, prevx, prevy;
int x, y, i, j, l;
if (gpGlobals->wChaseRange != 0)
{
x = PAL_X(gpGlobals->viewport) + PAL_X(gpGlobals->partyoffset) - pEvtObj->x;
y = PAL_Y(gpGlobals->viewport) + PAL_Y(gpGlobals->partyoffset) - pEvtObj->y;
if (x == 0)
{
x = RandomLong(0, 1) ? -1 : 1;
}
if (y == 0)
{
y = RandomLong(0, 1) ? -1 : 1;
}
prevx = pEvtObj->x;
prevy = pEvtObj->y;
i = prevx % 32;
j = prevy % 16;
prevx /= 32;
prevy /= 16;
l = 0;
if (i + j * 2 >= 16)
{
if (i + j * 2 >= 48)
{
prevx++;
prevy++;
}
else if (32 - i + j * 2 < 16)
{
prevx++;
}
else if (32 - i + j * 2 < 48)
{
l = 1;
}
else
{
prevy++;
}
}
prevx = prevx * 32 + l * 16;
prevy = prevy * 16 + l * 8;
//
// Is the party near to the event object?
//
if (abs(x) + abs(y) * 2 < wChaseRange * 32 * gpGlobals->wChaseRange)
{
if (x < 0)
{
if (y < 0)
{
pEvtObj->wDirection = kDirWest;
}
else
{
pEvtObj->wDirection = kDirSouth;
}
}
else
{
if (y < 0)
{
pEvtObj->wDirection = kDirNorth;
}
else
{
pEvtObj->wDirection = kDirEast;
}
}
if (x != 0)
{
x = pEvtObj->x + x / abs(x) * 16;
}
else
{
x = pEvtObj->x;
}
if (y != 0)
{
y = pEvtObj->y + y / abs(y) * 8;
}
else
{
y = pEvtObj->y;
}
if (fFloating)
{
wMonsterSpeed = wSpeed;
}
else
{
if (!PAL_CheckObstacle(PAL_XY(x, y), TRUE, wEventObjectID))
{
wMonsterSpeed = wSpeed;
}
else
{
pEvtObj->x = prevx;
pEvtObj->y = prevy;
}
for (l = 0; l < 4; l++)
{
switch (l)
{
case 0:
pEvtObj->x -= 4;
pEvtObj->y += 2;
break;
case 1:
pEvtObj->x -= 4;
pEvtObj->y -= 2;
break;
case 2:
pEvtObj->x += 4;
pEvtObj->y -= 2;
break;
case 3:
pEvtObj->x += 4;
pEvtObj->y += 2;
break;
}
if (PAL_CheckObstacle(PAL_XY(pEvtObj->x, pEvtObj->y), FALSE, 0))
{
pEvtObj->x = prevx;
pEvtObj->y = prevy;
}
}
}
}
}
PAL_NPCWalkOneStep(wEventObjectID, wMonsterSpeed);
}
VOID
PAL_AdditionalCredits(
VOID
)
/*++
Purpose:
Show the additional credits.
Parameters:
None.
Return value:
None.
--*/
{
LPCWSTR rgszcps[][CP_MAX] = {
// Traditional Chinese, Simplified Chinese
{ L"", L"", /*L""*/ },
{ L" 經典特別篇 ",
L" 经典特别篇 ",
//L" \x30AF\x30E9\x30B7\x30C3\x30AF\x7279\x5225\x7DE8 "
},
{ L"", L"", /*L""*/ },
{ L"", L"", /*L""*/ },
{ L"", L"", /*L""*/ },
{ L"", L"", /*L""*/ },
{ L"", L"", /*L""*/ },
{ L"", L"", /*L""*/ },
{ L" 本程式是自由軟體,按照 GNU General",
L" 本程序是自由软件,按照 GNU General",
//L" \x3053\x306E\x30D7\x30ED\x30B0\x30E9\x30E0\x306F\x81EA\x7531\x30BD\x30D5\x30C8\x30A6\x30A7\x30A2\x3067\x3059\x3001"
},
{ L" Public License v3 或更高版本發佈",
L" Public License v3 或更高版本发布",
//L" GNU General Public License v3 \x306E\x4E0B\x3067"
},
{ L"", L"", /*L" \x914D\x5E03\x3055\x308C\x3066\x3044\x307E\x3059\x3002"*/ },
{ L" ...按 Enter 結束",
L" ...按 Enter 结束",
//L" ...Enter\x30AD\x30FC\x3092\x62BC\x3057\x3066\x7D42\x4E86\x3057\x307E\x3059"
},
};
LPCWSTR rgszStrings[] = {
L" SDLPAL (http://sdlpal.github.io/)",
#ifdef PAL_CLASSIC
L"%ls(" WIDETEXT(__DATE__) L")",
#else
L" (" WIDETEXT(__DATE__) L")",
#endif
L" ",
L" (c) 2009-2011, Wei Mingzhi",
L" <[email protected]>.",
L" (c) 2011-2020, SDLPAL Team",
L"%ls", // Porting information line 1
L"%ls", // Porting information line 2
L"%ls", // GNU line 1
L"%ls", // GNU line 2
L"%ls", // GNU line 3
L"%ls", // Press Enter to continue
};
int i = 0;
PAL_DrawOpeningMenuBackground();
for (i = 0; i < 12; i++)
{
WCHAR buffer[48];
PAL_swprintf(buffer, sizeof(buffer) / sizeof(WCHAR), rgszStrings[i], gConfig.pszMsgFile ? g_rcCredits[i] : rgszcps[i][PAL_GetCodePage()]);
PAL_DrawText(buffer, PAL_XY(0, 2 + i * 16), DESCTEXT_COLOR, TRUE, FALSE, FALSE);
}
PAL_SetPalette(0, FALSE);
VIDEO_UpdateScreen(NULL);
PAL_WaitForKey(0);
}
static WORD
PAL_InterpretInstruction(
WORD wScriptEntry,
WORD wEventObjectID
)
/*++
Purpose:
Interpret and execute one instruction in the script.
Parameters:
[IN] wScriptEntry - The script entry to execute.
[IN] wEventObjectID - The event object ID which invoked the script.
Return value:
The address of the next script instruction to execute.
--*/
{
LPEVENTOBJECT pEvtObj, pCurrent;
LPSCRIPTENTRY pScript;
int iPlayerRole, i, j, x, y;
WORD w, wCurEventObjectID;
pScript = &(gpGlobals->g.lprgScriptEntry[wScriptEntry]);
if (wEventObjectID != 0)
{
pEvtObj = &(gpGlobals->g.lprgEventObject[wEventObjectID - 1]);
}
else
{
pEvtObj = NULL;
}
if (pScript->rgwOperand[0] == 0 || pScript->rgwOperand[0] == 0xFFFF)
{
pCurrent = pEvtObj;
wCurEventObjectID = wEventObjectID;
}
else
{
i = pScript->rgwOperand[0] - 1;
if (i > 0x9000)
{
// HACK for Dream 2.11 to avoid crash
i -= 0x9000;
}
pCurrent = &(gpGlobals->g.lprgEventObject[i]);
wCurEventObjectID = pScript->rgwOperand[0];
}
if (pScript->rgwOperand[0] < MAX_PLAYABLE_PLAYER_ROLES)
{
iPlayerRole = gpGlobals->rgParty[pScript->rgwOperand[0]].wPlayerRole;
}
else
{
iPlayerRole = gpGlobals->rgParty[0].wPlayerRole;
}
switch (pScript->wOperation)
{
case 0x000B:
case 0x000C:
case 0x000D:
case 0x000E:
//
// walk one step
//
pEvtObj->wDirection = pScript->wOperation - 0x000B;
PAL_NPCWalkOneStep(wEventObjectID, 2);
break;
case 0x000F:
//
// Set the direction and/or gesture for event object
//
if (pScript->rgwOperand[0] != 0xFFFF)
{
pEvtObj->wDirection = pScript->rgwOperand[0];
}
if (pScript->rgwOperand[1] != 0xFFFF)
{
pEvtObj->wCurrentFrameNum = pScript->rgwOperand[1];
}
break;
case 0x0010:
//
// Walk straight to the specified position
//
if (!PAL_NPCWalkTo(wEventObjectID, pScript->rgwOperand[0], pScript->rgwOperand[1],
pScript->rgwOperand[2], 3))
{
wScriptEntry--;
}
break;
case 0x0011:
//
// Walk straight to the specified position, at a lower speed
//
if ((wEventObjectID & 1) ^ (gpGlobals->dwFrameNum & 1))
{
if (!PAL_NPCWalkTo(wEventObjectID, pScript->rgwOperand[0], pScript->rgwOperand[1],
pScript->rgwOperand[2], 2))
{
wScriptEntry--;
}
}
else
{
wScriptEntry--;
}
break;
case 0x0012:
//
// Set the position of the event object, relative to the party
//
pCurrent->x =
pScript->rgwOperand[1] + PAL_X(gpGlobals->viewport) + PAL_X(gpGlobals->partyoffset);
pCurrent->y =
pScript->rgwOperand[2] + PAL_Y(gpGlobals->viewport) + PAL_Y(gpGlobals->partyoffset);
break;
case 0x0013:
//
// Set the position of the event object
//
pCurrent->x = pScript->rgwOperand[1];
pCurrent->y = pScript->rgwOperand[2];
break;
case 0x0014:
//
// Set the gesture of the event object
//
pEvtObj->wCurrentFrameNum = pScript->rgwOperand[0];
pEvtObj->wDirection = kDirSouth;
break;
case 0x0015:
//
// Set the direction and gesture for a party member
//
gpGlobals->wPartyDirection = pScript->rgwOperand[0];
gpGlobals->rgParty[pScript->rgwOperand[2]].wFrame =
gpGlobals->wPartyDirection * 3 + pScript->rgwOperand[1];
break;
case 0x0016:
//
// Set the direction and gesture for an event object
//
if (pScript->rgwOperand[0] != 0)
{
pCurrent->wDirection = pScript->rgwOperand[1];
pCurrent->wCurrentFrameNum = pScript->rgwOperand[2];
}
break;
case 0x0017:
//
// set the player's extra attribute
//
{
WORD *p;
i = pScript->rgwOperand[0] - 0xB;
p = (WORD *)(&gpGlobals->rgEquipmentEffect[i]); // HACKHACK
p[pScript->rgwOperand[1] * MAX_PLAYER_ROLES + wEventObjectID] =
(SHORT)pScript->rgwOperand[2];
}
break;
case 0x0018:
//
// Equip the selected item
//
i = pScript->rgwOperand[0] - 0x0B;
g_iCurEquipPart = i;
//
// The wEventObjectID parameter here should indicate the player role
//
PAL_RemoveEquipmentEffect(wEventObjectID, i);
if (gpGlobals->g.PlayerRoles.rgwEquipment[i][wEventObjectID] != pScript->rgwOperand[1])
{
w = gpGlobals->g.PlayerRoles.rgwEquipment[i][wEventObjectID];
gpGlobals->g.PlayerRoles.rgwEquipment[i][wEventObjectID] = pScript->rgwOperand[1];
PAL_AddItemToInventory(pScript->rgwOperand[1], -1);
if (w != 0)
{
PAL_AddItemToInventory(w, 1);
}
gpGlobals->wLastUnequippedItem = w;
}
break;
case 0x0019:
//
// Increase/decrease the player's attribute
//
{
WORD *p = (WORD *)(&gpGlobals->g.PlayerRoles); // HACKHACK
if (pScript->rgwOperand[2] == 0)
{
iPlayerRole = wEventObjectID;
}
else
{
iPlayerRole = pScript->rgwOperand[2] - 1;
}
p[pScript->rgwOperand[0] * MAX_PLAYER_ROLES + iPlayerRole] +=
(SHORT)pScript->rgwOperand[1];
}
break;
case 0x001A:
//
// Set player's stat
//
{
WORD *p = (WORD *)(&gpGlobals->g.PlayerRoles); // HACKHACK
if (g_iCurEquipPart != -1)
{
//
// In the progress of equipping items
//
p = (WORD *)&(gpGlobals->rgEquipmentEffect[g_iCurEquipPart]);
}
if (pScript->rgwOperand[2] == 0)
{
//
// Apply to the current player. The wEventObjectID should
// indicate the player role.
//
iPlayerRole = wEventObjectID;
}
else
{
iPlayerRole = pScript->rgwOperand[2] - 1;
}
p[pScript->rgwOperand[0] * MAX_PLAYER_ROLES + iPlayerRole] =
(SHORT)pScript->rgwOperand[1];
}
break;
case 0x001B:
//
// Increase/decrease player's HP
//
if (pScript->rgwOperand[0])
{
g_fScriptSuccess = FALSE;
//
// Apply to everyone
//
for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
{
w = gpGlobals->rgParty[i].wPlayerRole;
if (PAL_IncreaseHPMP(w, (SHORT)(pScript->rgwOperand[1]), 0))
g_fScriptSuccess = TRUE;
}
}
else
{
//
// Apply to one player. The wEventObjectID parameter should indicate the player role.
//
if (!PAL_IncreaseHPMP(wEventObjectID, (SHORT)(pScript->rgwOperand[1]), 0))
{
g_fScriptSuccess = FALSE;
}
}
break;
case 0x001C:
//
// Increase/decrease player's MP
//
if (pScript->rgwOperand[0])
{
//
// Apply to everyone
//
for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
{
w = gpGlobals->rgParty[i].wPlayerRole;
PAL_IncreaseHPMP(w, 0, (SHORT)(pScript->rgwOperand[1]));
}
}
else
{
//
// Apply to one player. The wEventObjectID parameter should indicate the player role.
//
if (!PAL_IncreaseHPMP(wEventObjectID, 0, (SHORT)(pScript->rgwOperand[1])))
{
g_fScriptSuccess = FALSE;
}
}
break;
case 0x001D:
//
// Increase/decrease player's HP and MP
//
if (pScript->rgwOperand[0])
{
//
// Apply to everyone
//
for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
{
w = gpGlobals->rgParty[i].wPlayerRole;
PAL_IncreaseHPMP(w,
(SHORT)(pScript->rgwOperand[1]), (SHORT)(pScript->rgwOperand[1]));
}
}
else
{
//
// Apply to one player. The wEventObjectID parameter should indicate the player role.
//
if (!PAL_IncreaseHPMP(wEventObjectID,
(SHORT)(pScript->rgwOperand[1]), (SHORT)(pScript->rgwOperand[1])))
{
g_fScriptSuccess = FALSE;
}
}
break;
case 0x001E:
//
// Increase or decrease cash by the specified amount
//
if ((SHORT)(pScript->rgwOperand[0]) < 0 &&
gpGlobals->dwCash < (WORD)(-(SHORT)(pScript->rgwOperand[0])))
{
//
// not enough cash
//
wScriptEntry = pScript->rgwOperand[1] - 1;
}
else
{
gpGlobals->dwCash += (SHORT)(pScript->rgwOperand[0]);
}
break;
case 0x001F:
//
// Add item to inventory
//
PAL_AddItemToInventory(pScript->rgwOperand[0], (SHORT)(pScript->rgwOperand[1]));
break;
case 0x0020:
//
// Remove item from inventory
//
x = pScript->rgwOperand[1];
if (x == 0)
{
x = 1;
}
if (x <= PAL_CountItem(pScript->rgwOperand[0]) || pScript->rgwOperand[2] == 0)
{
if (!PAL_AddItemToInventory(pScript->rgwOperand[0], -x))
{
//
// Try removing equipped item
//
for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++)
{
w = gpGlobals->rgParty[i].wPlayerRole;
for (j = 0; j < MAX_PLAYER_EQUIPMENTS; j++)
{
if (gpGlobals->g.PlayerRoles.rgwEquipment[j][w] == pScript->rgwOperand[0])
{
PAL_RemoveEquipmentEffect(w, j);
gpGlobals->g.PlayerRoles.rgwEquipment[j][w] = 0;
if (--x == 0)
{
i = 9999;
break;
}
}
}
}
}
}
else
wScriptEntry = pScript->rgwOperand[2] - 1;
break;
case 0x0021:
//
// Inflict damage to the enemy
//
if (pScript->rgwOperand[0])
{
//
// Inflict damage to all enemies
//
for (i = 0;i <= g_Battle.wMaxEnemyIndex; i++)
{
if (g_Battle.rgEnemy[i].wObjectID != 0)