forked from EasyRPG/Player
-
Notifications
You must be signed in to change notification settings - Fork 1
/
game_interpreter_map.cpp
1950 lines (1702 loc) · 53.3 KB
/
game_interpreter_map.cpp
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
/*
* This file is part of EasyRPG Player.
*
* EasyRPG Player 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.
*
* EasyRPG Player 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 EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
*/
// Headers
#include <boost/bind.hpp>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include "async_handler.h"
#include "audio.h"
#include "game_map.h"
#include "game_battle.h"
#include "game_event.h"
#include "game_player.h"
#include "game_temp.h"
#include "game_switches.h"
#include "game_variables.h"
#include "game_party.h"
#include "game_actors.h"
#include "game_system.h"
#include "game_message.h"
#include "game_picture.h"
#include "game_targets.h"
#include "spriteset_map.h"
#include "sprite_character.h"
#include "scene_map.h"
#include "scene.h"
#include "graphics.h"
#include "input.h"
#include "main_data.h"
#include "output.h"
#include "player.h"
#include "util_macro.h"
#include "game_interpreter_map.h"
#include "reader_util.h"
#include "filefinder.h"
#include "reader_lcf.h"
Game_Interpreter_Map::Game_Interpreter_Map(int depth, bool main_flag) :
Game_Interpreter(depth, main_flag) {
}
bool Game_Interpreter_Map::SetupFromSave(const std::vector<RPG::SaveEventCommands>& save, int _event_id, int _index) {
if (_index < (int)save.size()) {
map_id = Game_Map::GetMapId();
event_id = _event_id;
list = save[_index].commands;
index = save[_index].current_command;
child_interpreter.reset(new Game_Interpreter_Map());
bool result = static_cast<Game_Interpreter_Map*>(child_interpreter.get())->SetupFromSave(save, _event_id, _index + 1);
if (!result) {
child_interpreter.reset();
}
return true;
}
return false;
}
// Taken from readers because a kitten is killed when reader_structs is included
static int GetEventCommandSize(const std::vector<RPG::EventCommand>& commands) {
std::vector<RPG::EventCommand>::const_iterator it;
int result = 0;
for (it = commands.begin(); it != commands.end(); ++it) {
result += LcfReader::IntSize(it->code);
result += LcfReader::IntSize(it->indent);
result += LcfReader::IntSize(it->string.size());
result += ReaderUtil::Recode(it->string, Player::encoding).size();
int count = it->parameters.size();
result += LcfReader::IntSize(count);
for (int i = 0; i < count; i++)
result += LcfReader::IntSize(it->parameters[i]);
}
result += 4; // No idea why but then it fits
return result;
}
std::vector<RPG::SaveEventCommands> Game_Interpreter_Map::GetSaveData() const {
std::vector<RPG::SaveEventCommands> save;
const Game_Interpreter_Map* save_interpreter = this;
int i = 1;
if (save_interpreter->list.empty()) {
return save;
}
while (save_interpreter != NULL) {
RPG::SaveEventCommands save_commands;
save_commands.commands = save_interpreter->list;
save_commands.current_command = save_interpreter->index;
save_commands.commands_size = GetEventCommandSize(save_commands.commands);
save_commands.ID = i++;
save.push_back(save_commands);
save_interpreter = static_cast<Game_Interpreter_Map*>(save_interpreter->child_interpreter.get());
}
save.back().ID = event_id;
save.back().current_command++;
return save;
}
int Game_Interpreter_Map::DecodeInt(std::vector<int>::const_iterator& it) {
int value = 0;
for (;;) {
int x = *it++;
value <<= 7;
value |= x & 0x7F;
if (!(x & 0x80))
break;
}
return value;
}
const std::string Game_Interpreter_Map::DecodeString(std::vector<int>::const_iterator& it)
{
std::ostringstream out;
int len = DecodeInt(it);
for (int i = 0; i < len; i++)
out << (char) *it++;
std::string result = ReaderUtil::Recode(out.str(), Player::encoding);
return result;
}
RPG::MoveCommand Game_Interpreter_Map::DecodeMove(std::vector<int>::const_iterator& it)
{
RPG::MoveCommand cmd;
cmd.command_id = *it++;
switch (cmd.command_id) {
case 32: // Switch ON
case 33: // Switch OFF
cmd.parameter_a = DecodeInt(it);
break;
case 34: // Change Graphic
cmd.parameter_string = DecodeString(it);
cmd.parameter_a = DecodeInt(it);
break;
case 35: // Play Sound Effect
cmd.parameter_string = DecodeString(it);
cmd.parameter_a = DecodeInt(it);
cmd.parameter_b = DecodeInt(it);
cmd.parameter_c = DecodeInt(it);
break;
}
return cmd;
}
/**
* Execute Command.
*/
bool Game_Interpreter_Map::ExecuteCommand() {
if (index >= list.size()) {
return CommandEnd();
}
RPG::EventCommand const& com = list[index];
switch (com.code) {
case Cmd::MessageOptions:
return CommandMessageOptions(com);
case Cmd::ChangeExp:
return CommandChangeExp(com);
case Cmd::ChangeParameters:
return CommandChangeParameters(com);
case Cmd::ChangeHeroName:
return CommandChangeHeroName(com);
case Cmd::ChangeHeroTitle:
return CommandChangeHeroTitle(com);
case Cmd::ChangeSpriteAssociation:
return CommandChangeSpriteAssociation(com);
case Cmd::MemorizeLocation:
return CommandMemorizeLocation(com);
case Cmd::RecallToLocation:
return CommandRecallToLocation(com);
case Cmd::StoreTerrainID:
return CommandStoreTerrainID(com);
case Cmd::StoreEventID:
return CommandStoreEventID(com);
case Cmd::MemorizeBGM:
return CommandMemorizeBGM(com);
case Cmd::PlayMemorizedBGM:
return CommandPlayMemorizedBGM(com);
case Cmd::ChangeSystemBGM:
return CommandChangeSystemBGM(com);
case Cmd::ChangeSystemSFX:
return CommandChangeSystemSFX(com);
case Cmd::ChangeSaveAccess:
return CommandChangeSaveAccess(com);
case Cmd::ChangeTeleportAccess:
return CommandChangeTeleportAccess(com);
case Cmd::ChangeEscapeAccess:
return CommandChangeEscapeAccess(com);
case Cmd::ChangeMainMenuAccess:
return CommandChangeMainMenuAccess(com);
case Cmd::ChangeActorFace:
return CommandChangeActorFace(com);
case Cmd::Teleport:
return CommandTeleport(com);
case Cmd::EraseScreen:
return CommandEraseScreen(com);
case Cmd::ShowScreen:
return CommandShowScreen(com);
case Cmd::ShowPicture:
return CommandShowPicture(com);
case Cmd::MovePicture:
return CommandMovePicture(com);
case Cmd::ErasePicture:
return CommandErasePicture(com);
case Cmd::WeatherEffects:
return CommandWeatherEffects(com);
case Cmd::ChangeSystemGraphics:
return CommandChangeSystemGraphics(com);
case Cmd::ChangeScreenTransitions:
return CommandChangeScreenTransitions(com);
case Cmd::ChangeEventLocation:
return CommandChangeEventLocation(com);
case Cmd::TradeEventLocations:
return CommandTradeEventLocations(com);
case Cmd::TimerOperation:
return CommandTimerOperation(com);
case Cmd::ChangePBG:
return CommandChangePBG(com);
case Cmd::Label:
return true;
case Cmd::JumpToLabel:
return CommandJumpToLabel(com);
case Cmd::Loop:
return true;
case Cmd::BreakLoop:
return CommandBreakLoop(com);
case Cmd::EndLoop:
return CommandEndLoop(com);
case Cmd::MoveEvent:
return CommandMoveEvent(com);
case Cmd::OpenShop:
return CommandOpenShop(com);
case Cmd::Transaction:
case Cmd::NoTransaction:
return SkipTo(Cmd::EndShop);
case Cmd::EndShop:
return true;
case Cmd::ShowInn:
return CommandShowInn(com);
case Cmd::Stay:
case Cmd::NoStay:
return SkipTo(Cmd::EndInn);
case Cmd::EndInn:
return true;
case Cmd::EnterHeroName:
return CommandEnterHeroName(com);
case Cmd::ReturntoTitleScreen:
return CommandReturnToTitleScreen(com);
case Cmd::OpenSaveMenu:
return CommandOpenSaveMenu(com);
case Cmd::OpenMainMenu:
return CommandOpenMainMenu(com);
case Cmd::EnemyEncounter:
return CommandEnemyEncounter(com);
case Cmd::VictoryHandler:
case Cmd::EscapeHandler:
case Cmd::DefeatHandler:
return SkipTo(Cmd::EndBattle);
case Cmd::EndBattle:
return true;
case Cmd::TeleportTargets:
return CommandTeleportTargets(com);
case Cmd::EscapeTarget:
return CommandEscapeTarget(com);
case Cmd::SpriteTransparency:
return CommandSpriteTransparency(com);
case Cmd::FlashSprite:
return CommandFlashSprite(com);
case Cmd::EraseEvent:
return CommandEraseEvent(com);
case Cmd::ChangeMapTileset:
return CommandChangeMapTileset(com);
case Cmd::CallEvent:
return CommandCallEvent(com);
case Cmd::ChangeEncounterRate:
return CommandChangeEncounterRate(com);
case Cmd::ProceedWithMovement:
return CommandProceedWithMovement(com);
case Cmd::PlayMovie:
return CommandPlayMovie(com);
case Cmd::ChangeBattleCommands:
return CommandChangeBattleCommands(com);
case Cmd::KeyInputProc:
return CommandKeyInputProc(com);
case Cmd::ChangeVehicleGraphic:
return CommandChangeVehicleGraphic(com);
case Cmd::EnterExitVehicle:
return CommandEnterExitVehicle(com);
case Cmd::SetVehicleLocation:
return CommandSetVehicleLocation(com);
case Cmd::TileSubstitution:
return CommandTileSubstitution(com);
case Cmd::PanScreen:
return CommandPanScreen(com);
case Cmd::SimulatedAttack:
return CommandSimulatedAttack(com);
case Cmd::ShowBattleAnimation:
return CommandShowBattleAnimation(com);
case Cmd::ChangeClass:
return CommandChangeClass(com);
case Cmd::HaltAllMovement:
return CommandHaltAllMovement(com);
case Cmd::ConditionalBranch:
return CommandConditionalBranch(com);
case Cmd::ElseBranch:
return SkipTo(Cmd::EndBranch);
case Cmd::EndBranch:
return true;
default:
return Game_Interpreter::ExecuteCommand();
}
}
/**
* Commands
*/
bool Game_Interpreter_Map::CommandMessageOptions(RPG::EventCommand const& com) { //code 10120
Game_Message::SetTransparent(com.parameters[0] != 0);
Game_Message::SetPosition(com.parameters[1]);
Game_Message::SetPositionFixed(com.parameters[2] == 0);
Game_Message::SetContinueEvents(com.parameters[3] != 0);
return true;
}
bool Game_Interpreter_Map::CommandChangeExp(RPG::EventCommand const& com) { // Code 10410
int value = OperateValue(
com.parameters[2],
com.parameters[3],
com.parameters[4]
);
for (const auto& actor : GetActors(com.parameters[0], com.parameters[1])) {
actor->ChangeExp(actor->GetExp() + value, com.parameters[5] != 0);
}
return true;
}
bool Game_Interpreter_Map::CommandChangeParameters(RPG::EventCommand const& com) { // Code 10430
int value = OperateValue(
com.parameters[2],
com.parameters[4],
com.parameters[5]
);
for (const auto& actor : GetActors(com.parameters[0], com.parameters[1])) {
switch (com.parameters[3]) {
case 0:
// Max HP
actor->SetBaseMaxHp(actor->GetBaseMaxHp() + value);
break;
case 1:
// Max MP
actor->SetBaseMaxSp(actor->GetBaseMaxSp() + value);
break;
case 2:
// Attack
actor->SetBaseAtk(actor->GetBaseAtk() + value);
break;
case 3:
// Defense
actor->SetBaseDef(actor->GetBaseDef() + value);
break;
case 4:
// Spirit
actor->SetBaseSpi(actor->GetBaseSpi() + value);
break;
case 5:
// Agility
actor->SetBaseAgi(actor->GetBaseAgi() + value);
break;
}
}
return true;
}
bool Game_Interpreter_Map::CommandChangeHeroName(RPG::EventCommand const& com) { // code 10610
Game_Actor* actor = Game_Actors::GetActor(com.parameters[0]);
actor->SetName(com.string);
return true;
}
bool Game_Interpreter_Map::CommandChangeHeroTitle(RPG::EventCommand const& com) { // code 10620
Game_Actor* actor = Game_Actors::GetActor(com.parameters[0]);
actor->SetTitle(com.string);
return true;
}
bool Game_Interpreter_Map::CommandChangeSpriteAssociation(RPG::EventCommand const& com) { // code 10630
Game_Actor* actor = Game_Actors::GetActor(com.parameters[0]);
const std::string &file = com.string;
int idx = com.parameters[1];
bool transparent = com.parameters[2] != 0;
actor->SetSprite(file, idx, transparent);
Main_Data::game_player->Refresh();
return true;
}
bool Game_Interpreter_Map::CommandMemorizeLocation(RPG::EventCommand const& com) { // code 10820
Game_Character *player = Main_Data::game_player.get();
int var_map_id = com.parameters[0];
int var_x = com.parameters[1];
int var_y = com.parameters[2];
Game_Variables[var_map_id] = Game_Map::GetMapId();
Game_Variables[var_x] = player->GetX();
Game_Variables[var_y] = player->GetY();
Game_Map::SetNeedRefresh(true);
return true;
}
bool Game_Interpreter_Map::CommandRecallToLocation(RPG::EventCommand const& com) { // Code 10830
Game_Character *player = Main_Data::game_player.get();
int var_map_id = com.parameters[0];
int var_x = com.parameters[1];
int var_y = com.parameters[2];
int map_id = Game_Variables[var_map_id];
int x = Game_Variables[var_x];
int y = Game_Variables[var_y];
if (map_id == Game_Map::GetMapId()) {
player->MoveTo(x, y);
return true;
};
if (Main_Data::game_player->IsTeleporting() ||
Game_Message::visible) {
return false;
}
Main_Data::game_player->ReserveTeleport(map_id, x, y);
Main_Data::game_player->StartTeleport();
// Parallel events should keep on running in 2k and 2k3, unlike in later versions
if (!main_flag)
return true;
index++;
return false;
}
bool Game_Interpreter_Map::CommandStoreTerrainID(RPG::EventCommand const& com) { // code 10820
int x = ValueOrVariable(com.parameters[0], com.parameters[1]);
int y = ValueOrVariable(com.parameters[0], com.parameters[2]);
int var_id = com.parameters[3];
Game_Variables[var_id] = Game_Map::GetTerrainTag(x, y);
Game_Map::SetNeedRefresh(true);
return true;
}
bool Game_Interpreter_Map::CommandStoreEventID(RPG::EventCommand const& com) { // code 10920
int x = ValueOrVariable(com.parameters[0], com.parameters[1]);
int y = ValueOrVariable(com.parameters[0], com.parameters[2]);
int var_id = com.parameters[3];
std::vector<Game_Event*> events;
Game_Map::GetEventsXY(events, x, y);
Game_Variables[var_id] = events.size() > 0 ? events.back()->GetId() : 0;
Game_Map::SetNeedRefresh(true);
return true;
}
bool Game_Interpreter_Map::CommandMemorizeBGM(RPG::EventCommand const& /* com */) { // code 11530
Game_System::MemorizeBGM();
return true;
}
bool Game_Interpreter_Map::CommandPlayMemorizedBGM(RPG::EventCommand const& /* com */) { // code 11540
Game_System::PlayMemorizedBGM();
return true;
}
bool Game_Interpreter_Map::CommandChangeSystemBGM(RPG::EventCommand const& com) { //code 10660
RPG::Music music;
int context = com.parameters[0];
music.name = com.string;
music.fadein = com.parameters[1];
music.volume = com.parameters[2];
music.tempo = com.parameters[3];
music.balance = com.parameters[4];
Game_System::SetSystemBGM(context, music);
return true;
}
bool Game_Interpreter_Map::CommandChangeSystemSFX(RPG::EventCommand const& com) { //code 10670
RPG::Sound sound;
int context = com.parameters[0];
sound.name = com.string;
sound.volume = com.parameters[1];
sound.tempo = com.parameters[2];
sound.balance = com.parameters[3];
Game_System::SetSystemSE(context, sound);
return true;
}
bool Game_Interpreter_Map::CommandChangeSaveAccess(RPG::EventCommand const& com) { // code 11930
Game_System::SetAllowSave(com.parameters[0] != 0);
return true;
}
bool Game_Interpreter_Map::CommandChangeTeleportAccess(RPG::EventCommand const& com) { // code 11820
Game_System::SetAllowTeleport(com.parameters[0] != 0);
return true;
}
bool Game_Interpreter_Map::CommandChangeEscapeAccess(RPG::EventCommand const& com) { // code 11840
Game_System::SetAllowEscape(com.parameters[0] != 0);
return true;
}
bool Game_Interpreter_Map::CommandChangeMainMenuAccess(RPG::EventCommand const& com) { // code 11960
Game_System::SetAllowMenu(com.parameters[0] != 0);
return true;
}
bool Game_Interpreter_Map::CommandChangeActorFace(RPG::EventCommand const& com) { // code 10640
Game_Actor* actor = Game_Actors::GetActor(com.parameters[0]);
if (actor != NULL) {
actor->SetFace(com.string, com.parameters[1]);
return true;
}
return false;
}
bool Game_Interpreter_Map::CommandTeleport(RPG::EventCommand const& com) { // Code 10810
// TODO: if in battle return true
if (Main_Data::game_player->IsTeleporting() || Game_Temp::transition_processing ||
Game_Message::visible) {
return false;
}
int map_id = com.parameters[0];
int x = com.parameters[1];
int y = com.parameters[2];
// RPG2k3 feature
int direction = com.parameters.size() > 3 ? com.parameters[3] - 1 : -1;
Main_Data::game_player->ReserveTeleport(map_id, x, y, direction);
Main_Data::game_player->StartTeleport();
// Parallel events should keep on running in 2k and 2k3, unlike in later versions
if (!main_flag)
return true;
index++;
return false;
}
bool Game_Interpreter_Map::CommandEraseScreen(RPG::EventCommand const& com) { // code 11010
if (Game_Temp::transition_processing || Game_Message::visible)
return false;
Game_Temp::transition_processing = true;
Game_Temp::transition_erase = true;
switch(com.parameters[0]) {
case -1:
Game_Temp::transition_type = (Graphics::TransitionType)Game_System::GetTransition(
Game_System::Transition_TeleportErase);
return true;
case 0:
Game_Temp::transition_type = Graphics::TransitionFadeOut;
return true;
case 1:
Game_Temp::transition_type = Graphics::TransitionRandomBlocks;
return true;
case 2:
Game_Temp::transition_type = Graphics::TransitionRandomBlocksUp;
return true;
case 3:
Game_Temp::transition_type = Graphics::TransitionRandomBlocksDown;
return true;
case 4:
Game_Temp::transition_type = Graphics::TransitionBlindClose;
return true;
case 5:
Game_Temp::transition_type = Graphics::TransitionVerticalStripesOut;
return true;
case 6:
Game_Temp::transition_type = Graphics::TransitionHorizontalStripesOut;
return true;
case 7:
Game_Temp::transition_type = Graphics::TransitionBorderToCenterOut;
return true;
case 8:
Game_Temp::transition_type = Graphics::TransitionCenterToBorderOut;
return true;
case 9:
Game_Temp::transition_type = Graphics::TransitionScrollUpOut;
return true;
case 10:
Game_Temp::transition_type = Graphics::TransitionScrollDownOut;
return true;
case 11:
Game_Temp::transition_type = Graphics::TransitionScrollLeftOut;
return true;
case 12:
Game_Temp::transition_type = Graphics::TransitionScrollRightOut;
return true;
case 13:
Game_Temp::transition_type = Graphics::TransitionVerticalDivision;
return true;
case 14:
Game_Temp::transition_type = Graphics::TransitionHorizontalDivision;
return true;
case 15:
Game_Temp::transition_type = Graphics::TransitionCrossDivision;
return true;
case 16:
Game_Temp::transition_type = Graphics::TransitionZoomIn;
return true;
case 17:
Game_Temp::transition_type = Graphics::TransitionMosaicOut;
return true;
case 18:
Game_Temp::transition_type = Graphics::TransitionWaveOut;
return true;
case 19:
Game_Temp::transition_type = Graphics::TransitionErase;
return true;
default:
Game_Temp::transition_type = Graphics::TransitionNone;
return true;
}
}
bool Game_Interpreter_Map::CommandShowScreen(RPG::EventCommand const& com) { // code 11020
if (Game_Temp::transition_processing || Game_Message::visible)
return false;
Game_Temp::transition_processing = true;
Game_Temp::transition_erase = false;
switch(com.parameters[0]) {
case -1:
Game_Temp::transition_type = (Graphics::TransitionType)Game_System::GetTransition(
Game_System::Transition_TeleportShow);
return true;
case 0:
Game_Temp::transition_type = Graphics::TransitionFadeIn;
return true;
case 1:
Game_Temp::transition_type = Graphics::TransitionRandomBlocks;
return true;
case 2:
Game_Temp::transition_type = Graphics::TransitionRandomBlocksUp;
return true;
case 3:
Game_Temp::transition_type = Graphics::TransitionRandomBlocksDown;
return true;
case 4:
Game_Temp::transition_type = Graphics::TransitionBlindOpen;
return true;
case 5:
Game_Temp::transition_type = Graphics::TransitionVerticalStripesIn;
return true;
case 6:
Game_Temp::transition_type = Graphics::TransitionHorizontalStripesIn;
return true;
case 7:
Game_Temp::transition_type = Graphics::TransitionBorderToCenterIn;
return true;
case 8:
Game_Temp::transition_type = Graphics::TransitionCenterToBorderIn;
return true;
case 9:
Game_Temp::transition_type = Graphics::TransitionScrollUpIn;
return true;
case 10:
Game_Temp::transition_type = Graphics::TransitionScrollDownIn;
return true;
case 11:
Game_Temp::transition_type = Graphics::TransitionScrollLeftIn;
return true;
case 12:
Game_Temp::transition_type = Graphics::TransitionScrollRightIn;
return true;
case 13:
Game_Temp::transition_type = Graphics::TransitionVerticalCombine;
return true;
case 14:
Game_Temp::transition_type = Graphics::TransitionHorizontalCombine;
return true;
case 15:
Game_Temp::transition_type = Graphics::TransitionCrossCombine;
return true;
case 16:
Game_Temp::transition_type = Graphics::TransitionZoomOut;
return true;
case 17:
Game_Temp::transition_type = Graphics::TransitionMosaicIn;
return true;
case 18:
Game_Temp::transition_type = Graphics::TransitionWaveIn;
return true;
case 19:
Game_Temp::transition_type = Graphics::TransitionErase;
return true;
default:
Game_Temp::transition_type = Graphics::TransitionNone;
return true;
}
}
bool Game_Interpreter_Map::CommandShowPicture(RPG::EventCommand const& com) { // code 11110
int pic_id = com.parameters[0];
Game_Picture* picture = Main_Data::game_screen->GetPicture(pic_id);
std::string const& pic_name = com.string;
int x = ValueOrVariable(com.parameters[1], com.parameters[2]);
int y = ValueOrVariable(com.parameters[1], com.parameters[3]);
bool scrolls = com.parameters[4] > 0;
int magnify = com.parameters[5];
int top_trans = com.parameters[6];
bool use_trans = com.parameters[7] > 0;
int red = com.parameters[8];
int green = com.parameters[9];
int blue = com.parameters[10];
int saturation = com.parameters[11];
int effect = com.parameters[12];
int speed = com.parameters[13];
int bottom_trans;
if (Player::IsRPG2k() || Player::IsRPG2k3E()) {
// RKG2k and RPG2k3 1.10 do not support this option
bottom_trans = top_trans;
} else {
// Corner case when 2k maps are used in 2k3 (pre-1.10) and don't contain this chunk
size_t param_size = com.parameters.size();
bottom_trans = param_size > 14 ? com.parameters[14] : top_trans;
}
picture->Show(pic_name, use_trans);
picture->SetFixedToMap(scrolls);
picture->SetMovementEffect(x, y);
picture->SetColorEffect(red, green, blue, saturation);
picture->SetZoomEffect(magnify);
picture->SetTransparencyEffect(top_trans, bottom_trans);
picture->SetTransition(0);
switch (effect) {
case 0:
picture->StopEffects();
break;
case 1:
picture->SetRotationEffect(speed);
break;
case 2:
picture->SetWaverEffect(speed);
break;
}
picture->SetTransition(0);
return true;
}
bool Game_Interpreter_Map::CommandMovePicture(RPG::EventCommand const& com) { // code 11120
int pic_id = com.parameters[0];
Game_Picture* picture = Main_Data::game_screen->GetPicture(pic_id);
int x = ValueOrVariable(com.parameters[1], com.parameters[2]);
int y = ValueOrVariable(com.parameters[1], com.parameters[3]);
int magnify = com.parameters[5];
int top_trans = com.parameters[6];
int red = com.parameters[8];
int green = com.parameters[9];
int blue = com.parameters[10];
int saturation = com.parameters[11];
int effect = com.parameters[12];
int speed = com.parameters[13];
int tenths = com.parameters[14];
bool wait = com.parameters[15] != 0;
int bottom_trans;
if (Player::IsRPG2k() || Player::IsRPG2k3E()) {
// RPG2k and RPG2k3 1.10 do not support this option
bottom_trans = top_trans;
} else {
// Corner case when 2k maps are used in 2k3 (pre-1.10) and don't contain this chunk
size_t param_size = com.parameters.size();
bottom_trans = param_size > 16 ? com.parameters[16] : top_trans;
}
picture->SetMovementEffect(x, y);
picture->SetColorEffect(red, green, blue, saturation);
picture->SetZoomEffect(magnify);
picture->SetTransparencyEffect(top_trans, bottom_trans);
picture->SetTransition(tenths);
switch (effect) {
case 0:
picture->StopEffects();
break;
case 1:
picture->SetRotationEffect(speed);
break;
case 2:
picture->SetWaverEffect(speed);
break;
}
if (wait)
SetupWait(tenths);
return true;
}
bool Game_Interpreter_Map::CommandErasePicture(RPG::EventCommand const& com) { // code 11130
int pic_id = com.parameters[0];
Game_Picture* picture = Main_Data::game_screen->GetPicture(pic_id);
picture->Erase();
return true;
}
bool Game_Interpreter_Map::CommandWeatherEffects(RPG::EventCommand const& com) { // code 11070
Game_Screen* screen = Main_Data::game_screen.get();
int type = com.parameters[0];
int strength = com.parameters[1];
screen->SetWeatherEffect(type, strength);
return true;
}
void Game_Interpreter_Map::OnChangeSystemGraphicReady(FileRequestResult* result) {
Game_System::SetSystemName(result->file);
Scene_Map* scene = (Scene_Map*)Scene::Find(Scene::Map).get();
if (!scene)
return;
scene->spriteset->SystemGraphicUpdated();
}
bool Game_Interpreter_Map::CommandChangeSystemGraphics(RPG::EventCommand const& com) { // code 10680
FileRequestAsync* request = AsyncHandler::RequestFile("System", com.string);
request->Bind(&Game_Interpreter_Map::OnChangeSystemGraphicReady, this);
request->SetImportantFile(true);
request->Start();
return true;
}
bool Game_Interpreter_Map::CommandChangeScreenTransitions(RPG::EventCommand const& com) { // code 10690
Game_System::SetTransition(com.parameters[0], com.parameters[1]);
return true;
}
bool Game_Interpreter_Map::CommandChangeEventLocation(RPG::EventCommand const& com) { // Code 10860
int event_id = com.parameters[0];
Game_Character *event = GetCharacter(event_id);
if (event != NULL) {
int x = ValueOrVariable(com.parameters[1], com.parameters[2]);
int y = ValueOrVariable(com.parameters[1], com.parameters[3]);
event->MoveTo(x, y);
}
return true;
}
bool Game_Interpreter_Map::CommandTradeEventLocations(RPG::EventCommand const& com) { // Code 10870
int event1_id = com.parameters[0];
int event2_id = com.parameters[1];
Game_Character *event1 = GetCharacter(event1_id);
Game_Character *event2 = GetCharacter(event2_id);
if (event1 != NULL && event2 != NULL) {
int x1 = event1->GetX();
int y1 = event1->GetY();
int x2 = event2->GetX();
int y2 = event2->GetY();
event1->MoveTo(x2, y2);
event2->MoveTo(x1, y1);
}
return true;
}
bool Game_Interpreter_Map::CommandTimerOperation(RPG::EventCommand const& com) { // code 10230
int timer_id = (Player::IsRPG2k()) ? 0 : com.parameters[5];
int seconds;
bool visible, battle;
switch (com.parameters[0]) {
case 0:
seconds = ValueOrVariable(com.parameters[1],
com.parameters[2]);
Main_Data::game_party->SetTimer(timer_id, seconds);
break;
case 1:
visible = com.parameters[3] != 0;
battle = com.parameters[4] != 0;
Main_Data::game_party->StartTimer(timer_id, visible, battle);
break;
case 2:
Main_Data::game_party->StopTimer(timer_id);
break;
default:
return false;
}
return true;
}
bool Game_Interpreter_Map::CommandChangePBG(RPG::EventCommand const& com) { // code 11720
const std::string& name = com.string;
Game_Map::SetParallaxName(name);
bool horz = com.parameters[0] != 0;
bool vert = com.parameters[1] != 0;
bool horz_auto = com.parameters[2] != 0;
int horz_speed = com.parameters[3];
bool vert_auto = com.parameters[4] != 0;
int vert_speed = com.parameters[5];
Game_Map::SetParallaxScroll(horz, vert,
horz_auto, vert_auto,
horz_speed, vert_speed);
return true;
}
bool Game_Interpreter_Map::CommandJumpToLabel(RPG::EventCommand const& com) { // code 12120
int label_id = com.parameters[0];
for (int idx = 0; (size_t) idx < list.size(); idx++) {
if (list[idx].code != Cmd::Label)
continue;
if (list[idx].parameters[0] != label_id)
continue;
index = idx;
break;
}
return true;
}
bool Game_Interpreter_Map::CommandBreakLoop(RPG::EventCommand const& com) { // code 12220
return SkipTo(Cmd::EndLoop, Cmd::EndLoop, 0, com.indent - 1, true);
}
bool Game_Interpreter_Map::CommandEndLoop(RPG::EventCommand const& com) { // code 22210
int indent = com.indent;
for (int idx = index; idx >= 0; idx--) {
if (list[idx].indent > indent)
continue;
if (list[idx].indent < indent)
return false;
if (list[idx].code != Cmd::Loop)
continue;
index = idx;
break;
}
return true;
}
bool Game_Interpreter_Map::CommandMoveEvent(RPG::EventCommand const& com) { // code 11330
int event_id = com.parameters[0];
Game_Character* event = GetCharacter(event_id);
if (event != NULL) {
// If the event is a vehicle in use, push the commands to the player instead
if (event_id >= Game_Character::CharBoat && event_id <= Game_Character::CharAirship)
if (static_cast<Game_Vehicle*>(event)->IsInUse())
event = Main_Data::game_player.get();
RPG::MoveRoute route;
int move_freq = com.parameters[1];
route.repeat = com.parameters[2] != 0;