-
Notifications
You must be signed in to change notification settings - Fork 36
/
kys_main.pas
6236 lines (5749 loc) · 182 KB
/
kys_main.pas
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
unit kys_main;
{$IFDEF fpc}
//{$MODE Delphi}
{$ELSE}
{$ENDIF}
{
All Heros in Kam Yung's Stories - The Replicated Edition
Created by S.weyl in 2008 May.
No Copyright (C) reserved.
You can build it by Delphi with JEDI-SDL support.
This resouce code file which is not perfect so far,
can be modified and rebuilt freely,
or translate it to another programming language.
But please keep this section when you want to spread a new vision. Thanks.
Note: it must not be a good idea to use this as a pascal paradigm.
}
{
任何人获得这份代码之后, 均可以自由增删功能, 重新
编译, 或译为其他语言. 但请保留本段文字.
}
interface
uses
{$IFDEF fpc}
LConvEncoding,
LCLType,
LCLIntf,
{$ELSE}
Windows,
{$ENDIF}
{$IFDEF ANDROID}
jni,
{$ENDIF}
kys_type,
SysUtils,
Dialogs,
Math,
SDL2_TTF,
SDL2,
SDL2_image,
iniFiles,
bass;
//程序重要子程
procedure Run; stdcall; export;
procedure Quit;
procedure SetMODVersion;
procedure ReadFiles;
//游戏开始画面, 行走等
procedure Start;
procedure StartAmi;
function InitialRole: boolean;
procedure LoadR(num: integer);
procedure SaveR(num: integer);
function WaitAnyKey: integer;
procedure Walk;
function CanWalk(x, y: integer): boolean;
function CheckEntrance: boolean;
function UpdateScenceAmi(interval: uint32; param: pointer): uint32; cdecl;
function WalkInScence(Open: integer): integer;
procedure FindWay(x1, y1: integer);
procedure Moveman(x1, y1, x2, y2: integer);
procedure ShowScenceName(snum: integer);
function CanWalkInScence(x, y: integer): boolean; overload;
function CanWalkInScence(x1, y1, x, y: integer): boolean; overload;
function CheckEvent1: boolean;
procedure CheckEvent3;
//选单子程
function CommonMenu(x, y, w, max: integer; menuString: array of WideString): integer; overload;
function CommonMenu(x, y, w, max, default: integer; menuString: array of WideString): integer; overload;
function CommonMenu(x, y, w, max: integer; menuString, menuEngString: array of WideString): integer; overload;
function CommonMenu(x, y, w, max, default: integer; menuString, menuEngString: array of WideString): integer; overload;
function CommonMenu(x, y, w, max, default: integer; menuString, menuEngString: array of WideString;
fn: TPInt1): integer; overload;
procedure ShowCommonMenu(x, y, w, max, menu: integer; menuString: array of WideString); overload;
procedure ShowCommonMenu(x, y, w, max, menu: integer; menuString, menuEngString: array of WideString); overload;
function CommonScrollMenu(x, y, w, max, maxshow: integer; menuString: array of WideString): integer; overload;
function CommonScrollMenu(x, y, w, max, maxshow: integer; menuString, menuEngString: array of WideString): integer;
overload;
procedure ShowCommonScrollMenu(x, y, w, max, maxshow, menu, menutop: integer;
menuString, menuEngString: array of WideString);
function CommonMenu2(x, y, w: integer; menuString: array of WideString): integer;
procedure ShowCommonMenu2(x, y, w, menu: integer; menuString: array of WideString);
function SelectOneTeamMember(x, y: integer; str: AnsiString; list1, list2: integer): integer;
procedure MenuEsc;
procedure ShowMenu(menu: integer);
procedure MenuMedcine;
procedure MenuMedPoison;
function MenuItem: boolean;
function ReadItemList(ItemType: integer): integer;
procedure ShowMenuItem(row, col, x, y, atlu: integer);
procedure DrawItemFrame(x, y: integer);
procedure UseItem(inum: integer);
function CanEquip(rnum, inum: integer): boolean;
procedure MenuStatus;
procedure ShowStatusByTeam(tnum: integer);
procedure ShowStatus(rnum: integer); overload;
procedure ShowStatus(rnum, x, y: integer); overload;
procedure ShowSimpleStatus(rnum, x, y: integer);
procedure MenuLeave;
procedure MenuSystem;
procedure ShowMenuSystem(menu: integer);
procedure MenuLoad;
function MenuLoadAtBeginning: integer;
procedure MenuSave;
procedure MenuQuit;
//医疗, 解毒, 使用物品的效果等
function EffectMedcine(role1, role2: integer): integer;
function EffectMedPoison(role1, role2: integer): integer;
function EatOneItem(rnum, inum: integer; times: integer = 1; display: integer = 1): integer;
//事件系统
procedure CallEvent(num: integer);
//云的初始化和再次出现
procedure CloudCreate(num: integer);
procedure CloudCreateOnSide(num: integer);
function IsCave(snum: integer): boolean;
implementation
uses
kys_script,
kys_event,
kys_engine,
kys_battle,
kys_draw;
//初始化字体, 音效, 视频, 启动游戏
procedure Run;
var
Text: PSDL_Surface;
word: array[0..1] of uint16;// = (32, 0);
tempcolor: TSDL_Color;
str: AnsiString;
begin
word[0]:=32;
{$IFDEF UNIX}
AppPath := ExtractFilePath(ParamStr(0));
{$ELSE}
AppPath := '';
{$ENDIF}
{$IFDEF android}
AppPath := SDL_AndroidGetExternalStoragePath() + '/game/';
//for i := 1 to 4 do
//AppPath:= ExtractFileDir(AppPath);
str := SDL_AndroidGetExternalStoragePath() + '/place_game_here';
//if not fileexists(str) then
FileClose(filecreate(str));
CellPhone := 1;
{$ENDIF}
ReadFiles;
SetMODVersion;
TTF_Init();
font := TTF_OpenFont(PAnsiChar(AppPath + CHINESE_FONT), CHINESE_FONT_SIZE);
engfont := TTF_OpenFont(PAnsiChar(AppPath + ENGLISH_FONT), ENGLISH_FONT_SIZE);
//此处测试中文字体的空格宽度
Text := TTF_RenderUNICODE_solid(font, @word[0], tempcolor);
//writeln(SDL_geterror());
//writeln(text.w);
CHNFONT_SPACEWIDTH := Text.w;
//CHNFONT_SPACEWIDTH := 10;
SDL_FreeSurface(Text);
//初始化音频系统
//SDL_Init(SDL_INIT_AUDIO);
//Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 16384);
SoundFlag := 0;
if SOUND3D = 1 then
SoundFlag := BASS_DEVICE_3D or SoundFlag;
BASS_Init(-1, 22050, SoundFlag, 0, nil);
//初始化视频系统
Randomize;
//SDL_Init(SDL_INIT_VIDEO);
if (SDL_Init(SDL_INIT_VIDEO) < 0) then
begin
// MessageBox(0, PAnsiChar(Format('Couldn''t initialize SDL : %s', [SDL_GetError])), 'Error', MB_OK or MB_ICONHAND);
SDL_Quit;
exit;
end;
//SDL_WM_SetIcon(IMG_Load(PAnsiChar(AppPath + 'resource/icon.png')), 0);
ScreenFlag := SDL_WINDOW_RESIZABLE;
{SDL_HWSURFACE or SDL_HWACCEL or SDL_ANYFORMAT or SDL_ASYNCBLIT or SDL_FULLSCREEN};
{if GLHR = 1 then
begin
ScreenFlag := SDL_OPENGL or SDL_RESIZABLE;
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
end
else
begin
HARDWARE_BLIT := 0;
end;
if HARDWARE_BLIT = 1 then
ScreenFlag := ScreenFlag or SDL_HWSURFACE or SDL_HWACCEL;}
window := SDL_CreateWindow(PAnsiChar(TitleString), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
RESOLUTIONX, RESOLUTIONY, ScreenFlag);
SDL_GetWindowSize(window, @RESOLUTIONX, @RESOLUTIONY);
if (CellPhone = 1) then
begin
if (RESOLUTIONY > RESOLUTIONX) then
ScreenRotate := 0;
//SDL_WarpMouseInWindow(window, RESOLUTIONX, RESOLUTIONY);
end;
//SDL_WM_SetCaption(PAnsiChar(TitleString), 's.weyl');
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, '1');
render := SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED or SDL_RENDERER_TARGETTEXTURE);
screen := SDL_CreateRGBSurface(ScreenFlag, CENTER_X * 2, CENTER_Y * 2, 32, RMask, GMask, BMask, 0);
screenTex := SDL_CreateTexture(render, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING,
CENTER_X * 2, CENTER_Y * 2);
//prescreen := SDL_CreateRGBSurface(ScreenFlag, CENTER_X * 2, CENTER_Y * 2, 32, RMask, GMask, BMask, 0);
//prescreen := SDL_DisplayFormat(screen);
freshscreen := SDL_CreateRGBSurface(ScreenFlag, CENTER_X * 2, CENTER_Y * 2, 32, RMask, GMask, BMask, 0);
ImageWidth := (36 * 32 + CENTER_X) * 2;
ImageHeight := (18 * 32 + CENTER_Y) * 2;
ImgScence := SDL_CreateRGBSurface(screen.flags, ImageWidth, ImageHeight, 32, RMask, GMask, BMask, 0);
//ImgScence := SDL_DisplayFormat(ImgScence);
ImgScenceBack := SDL_CreateRGBSurface(screen.flags, ImageWidth, ImageHeight, 32, RMask, GMask, BMask, 0);
ImgBField := SDL_CreateRGBSurface(screen.flags, ImageWidth, ImageHeight, 32, RMask, GMask, BMask, 0);
ImgBBuild := SDL_CreateRGBSurface(screen.flags, ImageWidth, ImageHeight, 32, RMask, GMask, BMask, 0);
SDL_SetColorKey(ImgScenceBack, 1, 1);
SDL_SetColorKey(ImgBBuild, 1, 1);
setlength(BlockImg, ImageWidth * ImageHeight);
setlength(BlockImg2, ImageWidth * ImageHeight);
{if GLHR = 1 then
begin
glBindTexture(GL_TEXTURE_2D, TextureID);
glGenTextures(1, @TextureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, screen.w, screen.h, 0, GL_BGRA, GL_UNSIGNED_BYTE, prescreen.pixels);
end;}
if (window = nil) then
begin
SDL_Quit;
halt(1);
end;
InitialScript;
InitialMusic;
SDL_SetEventFilter(@EventFilter, nil);
mutex := SDL_CreateMutex();
SDL_AddTimer(200, UpdateScenceAmi, nil);
Start;
Quit;
end;
//关闭所有已打开的资源, 退出
procedure Quit;
begin
FreeAllSurface;
DestroyScript;
TTF_CloseFont(font);
TTF_CloseFont(engfont);
TTF_Quit;
SDL_DestroyMutex(mutex);
SDL_Quit;
BASS_Free;
halt(1);
exit;
end;
procedure SetMODVersion;
var
filename: AnsiString;
Kys_ini: TIniFile;
begin
Setlength(Music, 24);
Setlength(Esound, 53);
Setlength(Asound, 25);
StartMusic := 16;
TitleString := 'All Heros in Kam Yung''s Stories - Replicated Edition';
OpenPicPosition.x := CENTER_X - 320;
OpenPicPosition.y := CENTER_Y - 220;
TitlePosition.x := OpenPicPosition.x + 275;
TitlePosition.y := OpenPicPosition.y + 125;
//0-原版,
//11-小猪闯江湖, 12-苍龙逐日, 13-金庸水浒传(未包含)
//21-天书奇侠, 22-菠萝三国(含资料片), 23-笑梦游记, 24-前传(未包含)
//31-再战江湖,
//41-PTT
//51-魏征
//62-红颜录解密
//71-天书劫
//81-自然与祥和
case MODVersion of
0:
begin
end;
11:
begin
TitleString := 'All Heros in Kam Yung''s Stories - A Pig';
TitlePosition.y := 270;
OpenPicPosition.y := OpenPicPosition.y + 20;
CENTER_Y := 240;
end;
12:
begin
TitleString := 'All Heros in Kam Yung''s Stories - We Are Dragons';
Setlength(Asound, 37);
TitlePosition.x := 100;
TitlePosition.y := 270;
end;
21:
begin
TitleString := 'All Heros in Kam Yung''s Stories - Books';
TitlePosition.x := 275;
TitlePosition.y := 285;
Setlength(Esound, 59);
end;
22:
begin
TitleString := 'Why I have to go after a pineapple in the period of Three Kingdoms??';
MAX_ITEM_AMOUNT := 456;
Setlength(Music, 38);
StartMusic := 37;
CENTER_Y := 240;
end;
23:
begin
TitleString := 'All Heros in Kam Yung''s Stories - Four Dreams';
//TitlePosition.x := 275;
TitlePosition.y := 165;
Setlength(Music, 25);
Setlength(Esound, 84);
StartMusic := 24;
CENTER_Y := 240;
end;
31:
begin
TitleString := 'All Heros in Kam Yung''s Stories - Wider Rivers and Deeper Lakes';
Setlength(Esound, 99);
Setlength(Asound, 71);
end;
41:
begin
TitleString := 'All Heros in Kam Yung''s Stories - Here is PTT';
TitlePosition.y := 255;
OpenPicPosition.y := OpenPicPosition.y + 20;
CENTER_Y := 240;
end;
51:
begin
TitleString := 'All Heros in Kam Yung''s Stories - An Prime Minister of Tang';
//CHINESE_FONT_SIZE:= 16;
//ENGLISH_FONT_SIZE:= 15;
end;
62:
begin
TitleString := 'All Heros in Kam Yung''s Stories - All for You';
MAX_ITEM_AMOUNT := 968;
CENTER_Y := 240;
Setlength(Music, 195);
BEGIN_WALKPIC := 5697;
end;
71:
begin
TitleString := 'All Heros in Kam Yung''s Stories - Books from Heaven';
TitlePosition.x := 60;
TitlePosition.y := 270;
OpenPicPosition.y := OpenPicPosition.y + 20;
MAX_ITEM_AMOUNT := 400;
Setlength(Esound, 207);
Setlength(Asound, 37);
end;
81:
begin
TitleString := 'All Heros in Kam Yung''s Stories - Awaking of Dragons';
Setlength(Music, 999);
TitlePosition.x := 100;
TitlePosition.y := 270;
end;
end;
{$IFDEF fpc}
Filename := AppPath + 'kysmod.ini';
{$ELSE}
Filename := ExtractFilePath(ParamStr(0)) + 'kysmod.ini';
{$ENDIF}
Kys_ini := TIniFile.Create(filename);
try
//RESOLUTIONX := Kys_ini.ReadInteger('system', 'RESOLUTIONX', CENTER_X * 2);
//RESOLUTIONY := Kys_ini.ReadInteger('system', 'RESOLUTIONY', CENTER_Y * 2);
finally
Kys_ini.Free;
end;
end;
//读取必须的文件
procedure ReadFiles;
var
grp, idx, tnum, len, col, i, k: integer;
filename: AnsiString;
Kys_ini: TIniFile;
LoadPNGTilesThread: PSDL_Thread;
begin
{$IFDEF fpc}
Filename := AppPath + 'kysmod.ini';
{$ELSE}
Filename := ExtractFilePath(ParamStr(0)) + 'kysmod.ini';
{$ENDIF}
Kys_ini := TIniFile.Create(filename);
try
ITEM_BEGIN_PIC := Kys_ini.ReadInteger('constant', 'ITEM_BEGIN_PIC', 3501);
MAX_HEAD_NUM := Kys_ini.ReadInteger('constant', 'MAX_HEAD_NUM', 189);
BEGIN_EVENT := Kys_ini.ReadInteger('constant', 'BEGIN_EVENT', 691);
BEGIN_SCENCE := Kys_ini.ReadInteger('constant', 'BEGIN_SCENCE', 70);
BEGIN_Sx := Kys_ini.ReadInteger('constant', 'BEGIN_Sx', 20);
BEGIN_Sy := Kys_ini.ReadInteger('constant', 'BEGIN_Sy', 19);
SOFTSTAR_BEGIN_TALK := Kys_ini.ReadInteger('constant', 'SOFTSTAR_BEGIN_TALK', 2547);
SOFTSTAR_NUM_TALK := Kys_ini.ReadInteger('constant', 'SOFTSTAR_NUM_TALK', 18);
MAX_PHYSICAL_POWER := Kys_ini.ReadInteger('constant', 'MAX_PHYSICAL_POWER', 100);
BEGIN_WALKPIC := Kys_ini.ReadInteger('constant', 'BEGIN_WALKPIC', 2501);
MONEY_ID := Kys_ini.ReadInteger('constant', 'MONEY_ID', 174);
COMPASS_ID := Kys_ini.ReadInteger('constant', 'COMPASS_ID', 182);
BEGIN_LEAVE_EVENT := Kys_ini.ReadInteger('constant', 'BEGIN_LEAVE_EVENT', 950);
BEGIN_BATTLE_ROLE_PIC := Kys_ini.ReadInteger('constant', 'BEGIN_BATTLE_ROLE_PIC', 2553);
MAX_LEVEL := Kys_ini.ReadInteger('constant', 'MAX_LEVEL', 30);
MAX_WEAPON_MATCH := Kys_ini.ReadInteger('constant', 'MAX_WEAPON_MATCH', 7);
MIN_KNOWLEDGE := Kys_ini.ReadInteger('constant', 'MIN_KNOWLEDGE', 80);
MAX_HP := Kys_ini.ReadInteger('constant', 'MAX_HP', 999);
MAX_MP := Kys_ini.ReadInteger('constant', 'MAX_MP', 999);
LIFE_HURT := Kys_ini.ReadInteger('constant', 'LIFE_HURT', 10);
POISON_HURT := Kys_ini.ReadInteger('constant', 'POISON_HURT', 10);
MED_LIFE := Kys_ini.ReadInteger('constant', 'MED_LIFE', 4);
NOVEL_BOOK := Kys_ini.ReadInteger('constant', 'NOVEL_BOOK', 144);
MAX_ADD_PRO := Kys_ini.ReadInteger('constant', 'MAX_ADD_PRO', 0);
BATTLE_SPEED := Kys_ini.ReadInteger('system', 'BATTLE_SPEED', 10);
WALK_SPEED := Kys_ini.ReadInteger('system', 'WALK_SPEED', 10);
WALK_SPEED2 := Kys_ini.ReadInteger('system', 'WALK_SPEED2', WALK_SPEED);
HARDWARE_BLIT := Kys_ini.ReadInteger('system', 'HARDWARE_BLIT', 1);
SMOOTH := Kys_ini.ReadInteger('system', 'SMOOTH', 1);
GLHR := Kys_ini.ReadInteger('system', 'GLHR', 1);
//CENTER_X := Kys_ini.ReadInteger('system', 'CENTER_X', 320);
//CENTER_Y := Kys_ini.ReadInteger('system', 'CENTER_Y', 220);
//RESOLUTIONX := Kys_ini.ReadInteger('system', 'RESOLUTIONX', CENTER_X * 2);
//RESOLUTIONY := Kys_ini.ReadInteger('system', 'RESOLUTIONY', CENTER_Y * 2);
VOLUME := Kys_ini.ReadInteger('music', 'VOLUME', 30);
VOLUMEWAV := Kys_ini.ReadInteger('music', 'VOLUMEWAV', 30);
SOUND3D := Kys_ini.ReadInteger('music', 'SOUND3D', 1);
MMAPAMI := Kys_ini.ReadInteger('system', 'MMAPAMI', 1);
SCENCEAMI := Kys_ini.ReadInteger('system', 'SCENCEAMI', 2);
SEMIREAL := Kys_ini.ReadInteger('system', 'SEMIREAL', 0);
MODVersion := Kys_ini.ReadInteger('system', 'MODVersion', 0);
CHINESE_FONT_SIZE := Kys_ini.ReadInteger('system', 'CHINESE_FONT_SIZE', 20);
ENGLISH_FONT_SIZE := Kys_ini.ReadInteger('system', 'ENGLISH_FONT_SIZE', 19);
KDEF_SCRIPT := Kys_ini.ReadInteger('system', 'KDEF_SCRIPT', 0);
NIGHT_EFFECT := Kys_ini.ReadInteger('system', 'NIGHT_EFFECT', 0);
EXIT_GAME := Kys_ini.ReadInteger('system', 'EXIT_GAME', 0);
PNG_TILE := Kys_ini.ReadInteger('system', 'PNG_TILE', 0);
TRY_FIND_GRP := Kys_ini.ReadInteger('system', 'TRY_FIND_GRP', 0);
EXPAND_GROUND := Kys_ini.ReadInteger('system', 'EXPAND_GROUND', 1);
if CellPhone <> 0 then
begin
ShowVirtualKey := Kys_ini.ReadInteger('system', 'Virtual_Key', 1);
VirtualKeyX := Kys_ini.ReadInteger('system', 'Virtual_Key_X', 150);
VirtualKeyY := Kys_ini.ReadInteger('system', 'Virtual_Key_Y', 250);
if FileExists(AppPath + 'resource/u.png') then
begin
VirtualKeyU := IMG_Load(PAnsiChar(AppPath + 'resource/u.png'));
VirtualKeyD := IMG_Load(PAnsiChar(AppPath + 'resource/d.png'));
VirtualKeyL := IMG_Load(PAnsiChar(AppPath + 'resource/l.png'));
VirtualKeyR := IMG_Load(PAnsiChar(AppPath + 'resource/r.png'));
end
else
ShowVirtualKey := 0;
end
else
ShowVirtualKey := 0;
if (not FileExists(AppPath + 'resource/mmap/index.ka')) and
(not FileExists(AppPath + 'resource/mmap.imz')) then
PNG_TILE := 0;
for i := 43 to 58 do
begin
MaxProList[i] := Kys_ini.ReadInteger('constant', 'MaxProList' + IntToStr(i), 100);
end;
if LIFE_HURT = 0 then
LIFE_HURT := 1;
if POISON_HURT = 0 then
POISON_HURT := 1;
finally
Kys_ini.Free;
end;
ReadFileToBuffer(@ACol[0], AppPath + 'resource/mmap.col', 768, 0);
move(ACol[0], ACol1[0], 768);
move(ACol[0], ACol2[0], 768);
ReadFileToBuffer(@Earth[0, 0], AppPath + 'resource/earth.002', 480 * 480 * 2, 0);
ReadFileToBuffer(@surface[0, 0], AppPath + 'resource/surface.002', 480 * 480 * 2, 0);
ReadFileToBuffer(@Building[0, 0], AppPath + 'resource/building.002', 480 * 480 * 2, 0);
ReadFileToBuffer(@Buildx[0, 0], AppPath + 'resource/buildy.002', 480 * 480 * 2, 0);
ReadFileToBuffer(@Buildy[0, 0], AppPath + 'resource/buildx.002', 480 * 480 * 2, 0);
ReadFileToBuffer(@leavelist[0], AppPath + 'list/leave.bin', 200, 0);
ReadFileToBuffer(@effectlist[0], AppPath + 'list/effect.bin', 400, 0);
ReadFileToBuffer(@leveluplist[0], AppPath + 'list/levelup.bin', 200, 0);
ReadFileToBuffer(@matchlist[0], AppPath + 'list/match.bin', MAX_WEAPON_MATCH * 3 * 2, 0);
LoadIdxGrp('resource/kdef.idx', 'resource/kdef.grp', KIdx, KDef);
LoadIdxGrp('resource/talk.idx', 'resource/talk.grp', TIdx, TDef);
end;
//Main game.
//显示开头画面
procedure Start;
var
menu, menup, i, col, i1, i2, x, y, k: integer;
Selected: boolean;
begin
PlayMP3(StartMusic, -1);
where := 3;
Redraw;
if PNG_TILE > 0 then
begin
LoadPNGTiles('resource/title', TitlePNGIndex, TitlePNGTile, 1);
DrawTitlePic(8, TitlePosition.x, TitlePosition.y + 20);
end;
SDL_UpdateRect2(screen, 0, 0, screen.w, screen.h);
ReadTiles;
begin_time := random(1440);
now_time := begin_time;
for i1 := 0 to 479 do
for i2 := 0 to 479 do
Entrance[i1, i2] := -1;
//SDL_EnableKeyRepeat(0, 10);
MStep := 0;
FULLSCREEN := 0;
menu := 0;
SetLength(Cloud, CLOUD_AMOUNT);
for i := 0 to CLOUD_AMOUNT - 1 do
begin
CloudCreate(i);
end;
x := TitlePosition.x;
y := TitlePosition.y;
Redraw;
DrawTitlePic(0, x, y);
DrawTitlePic(menu + 1, x, y + menu * 20);
SDL_UpdateRect2(screen, 0, 0, screen.w, screen.h);
//事件等待
Selected := False;
while (SDL_WaitEvent(@event) >= 0) do
begin
CheckBasicEvent;
case event.type_ of //键盘事件
SDL_KEYUP:
begin
if ((event.key.keysym.sym = SDLK_RETURN) or (event.key.keysym.sym = SDLK_SPACE)) then
begin
Selected := True;
end;
//按下方向键上
if event.key.keysym.sym = SDLK_UP then
begin
menu := menu - 1;
if menu < 0 then
menu := 2;
DrawTitlePic(0, x, y);
DrawTitlePic(menu + 1, x, y + menu * 20);
SDL_UpdateRect2(screen, 0, 0, screen.w, screen.h);
end;
//按下方向键下
if event.key.keysym.sym = SDLK_DOWN then
begin
menu := menu + 1;
if menu > 2 then
menu := 0;
DrawTitlePic(0, x, y);
DrawTitlePic(menu + 1, x, y + menu * 20);
SDL_UpdateRect2(screen, 0, 0, screen.w, screen.h);
end;
end;
//按下鼠标(UP表示抬起按键才执行)
SDL_MOUSEBUTTONUP:
begin
if (event.button.button = SDL_BUTTON_LEFT) and (round(event.button.x / (RESOLUTIONX / screen.w)) > x) and
(round(event.button.x / (RESOLUTIONX / screen.w)) < x + 80) and
(round(event.button.y / (RESOLUTIONY / screen.h)) > y) and
(round(event.button.y / (RESOLUTIONY / screen.h)) < y + 60) then
begin
Selected := True;
end;
end;
//鼠标移动
SDL_MOUSEMOTION:
begin
if (round(event.button.x / (RESOLUTIONX / screen.w)) > x) and
(round(event.button.x / (RESOLUTIONX / screen.w)) < x + 80) and
(round(event.button.y / (RESOLUTIONY / screen.h)) > y) and
(round(event.button.y / (RESOLUTIONY / screen.h)) < y + 60) then
begin
menup := menu;
menu := (round(event.button.y / (RESOLUTIONY / screen.h)) - y) div 20;
if menu <> menup then
begin
DrawTitlePic(0, x, y);
DrawTitlePic(menu + 1, x, y + menu * 20);
SDL_UpdateRect2(screen, 0, 0, screen.w, screen.h);
end;
end;
end;
end;
if Selected then
begin
case menu of
2:
break;
1:
begin
if MenuLoadAtBeginning >= 0 then
begin
//redraw;
//SDL_UpdateRect2(screen, 0, 0, screen.w, screen.h);
CurEvent := -1; //when CurEvent=-1, Draw scence by Sx, Sy. Or by Cx, Cy.
if where = 1 then
begin
WalkInScence(0);
end;
Walk;
//menu := -1;
end;
end;
0:
begin
Selected := InitialRole;
if Selected then
begin
CurScence := BEGIN_SCENCE;
CurEvent := -1;
WalkInScence(1);
Walk;
//menu := -1;
end;
end;
end;
Redraw;
DrawTitlePic(0, x, y);
DrawTitlePic(menu + 1, x, y + menu * 20);
SDL_UpdateRect2(screen, 0, 0, screen.w, screen.h);
Selected := False;
end;
end;
end;
//开头字幕
procedure StartAmi;
var
x, y, i, len: integer;
str: WideString;
p: integer;
begin
instruct_14;
Redraw;
i := FileOpen(PAnsiChar(AppPath + 'list/start.txt'), fmOpenRead);
len := FileSeek(i, 0, 2);
FileSeek(i, 0, 0);
setlength(str, len + 1);
FileRead(i, str[1], len);
FileClose(i);
p := 1;
x := 30;
y := 80;
DrawRectangleWithoutFrame(screen, 0, 0, CENTER_X * 2, CENTER_Y * 2, 0, 60);
for i := 1 to len + 1 do
begin
if str[i] = widechar(10) then
str[i] := ' ';
if str[i] = widechar(13) then
begin
str[i] := widechar(0);
DrawShadowText(screen, @str[p], x, y, ColColor($FF), ColColor($FF));
p := i + 1;
y := y + 25;
SDL_UpdateRect2(screen, 0, 0, screen.w, screen.h);
end;
if str[i] = widechar($2A) then
begin
str[i] := ' ';
y := 80;
Redraw;
WaitAnyKey;
DrawRectangleWithoutFrame(screen, 0, 50, CENTER_X * 2, CENTER_Y * 2 - 100, 0, 60);
end;
end;
WaitAnyKey;
instruct_14;
//instruct_13;
end;
//初始化主角属性
function InitialRole: boolean;
var
i: integer;
p: array[0..14] of integer;
str, str0: WideString;
str1, str2, tempname: AnsiString;
{$IFDEF fpc}
Name, homename: AnsiString;
{$ELSE}
Name, homename: WideString;
{$ENDIF}
p0, p1: PAnsiChar;
named: boolean;
{$ifdef android}
env: PJNIEnv;
jstr: jstring;
cstr: PAnsiChar;
activity: jobject;
clazz: jclass;
method_id: jmethodID;
e: TSDL_event;
{$endif}
begin
LoadR(0);
//显示输入姓名的对话框
//form1.ShowModal;
//str := form1.edit1.text;
str1 := '請以繁體中文輸入主角之姓名,選定屬性後按Enter, Esc或滑鼠按鍵 ';
//name := InputBox('Enter name', str1, '我是主角');
where := 3;
Redraw;
tempname := '我是主角';
homename := '主角的家';
{$ifdef android}
{ShowStatus(0);
UpdateAllScreen;
str0 := '點擊一下開始選屬性!';
DrawTextWithRect(@str0[1], 175, CENTER_Y + 171, 10, ColColor($64), ColColor($66));
env := SDL_AndroidGetJNIEnv();
activity := SDL_AndroidGetActivity();
clazz := env^.GetObjectClass(env, activity);
method_id := env^.GetMethodID(env, clazz, 'mythSetName', '()Ljava/lang/String;');
jstr := jstring(env^.CallObjectMethod(env, activity, method_id));
cstr := env^.GetStringUTFChars(env, jstr, 0);
Name := strpas(cstr);
env^.ReleaseStringUTFChars(env, jstr, cstr);}
Name := tempname;
named := True;
{$else}
{$ifndef linux}
named := InputQuery('Enter name', str1, ansistring(tempname));
{$endif}
Name := tempname;
{$endif}
if named then
begin
if Name = '' then
begin
Name := ' ';
end;
{$IFDEF fpc}
str1 := UTF8ToCP950(Name);
if (length(str1) in [1..7]) and (Name <> ' ') then
homename := Name + '居';
str2 := UTF8ToCP950(homename);
{$ELSE}
str1 := UnicodeToBig5(@Name[1]);
if (length(str1[1]) in [1..7]) and (Name <> ' ') then
homename := Name + '居';
str2 := UnicodeToBig5(@homename[1]);
{$ENDIF}
p0 := @Rrole[0].Name;
p1 := @str1[1];
for i := 0 to 4 do
Rrole[0].Data[4 + i] := 0;
for i := 0 to 7 do
begin
(p0 + i)^ := (p1 + i)^;
end;
if (MODVersion <> 22) and (MODVersion <> 11) and (MODVersion <> 12) then
begin
p0 := @Rscence[BEGIN_SCENCE].Name;
p1 := @str2[1];
for i := 0 to 4 do
Rscence[BEGIN_SCENCE].Data[1 + i] := 0;
for i := 0 to 8 do
begin
(p0 + i)^ := (p1 + i)^;
end;
end;
Redraw;
str := ('資質');
repeat
if MODVersion <> 21 then
begin
Rrole[0].MaxHP := 25 + random(26);
Rrole[0].CurrentHP := Rrole[0].MaxHP;
Rrole[0].MaxMP := 25 + random(26);
Rrole[0].CurrentMP := Rrole[0].MaxMP;
Rrole[0].MPType := random(2);
Rrole[0].IncLife := 1 + random(10);
Rrole[0].Attack := 25 + random(6);
Rrole[0].Speed := 25 + random(6);
Rrole[0].Defence := 25 + random(6);
Rrole[0].Medcine := 25 + random(6);
Rrole[0].UsePoi := 25 + random(6);
Rrole[0].MedPoi := 25 + random(6);
Rrole[0].Fist := 25 + random(6);
Rrole[0].Sword := 25 + random(6);
Rrole[0].Knife := 25 + random(6);
Rrole[0].Unusual := 25 + random(6);
Rrole[0].HidWeapon := 25 + random(6);
end;
Rrole[0].Aptitude := 1 + random(100);
if MODVersion = 0 then
begin
Rrole[0].Magic[0] := 1;
if random(100) < 70 then
Rrole[0].Magic[0] := random(93);
end;
if MODVersion = 31 then
Rrole[0].Ethics := random(50) + random(50);
if MODVersion = 41 then
begin
Rrole[0].Magic[0] := 0;
end;
Redraw;
ShowStatus(0);
DrawShadowText(screen, @str[1], CENTER_X - 273 + 10, CENTER_Y + 111, ColColor($21), ColColor($23));
str0 := format('%4d', [Rrole[0].Aptitude]);
DrawEngShadowText(screen, @str0[1], CENTER_X - 273 + 110, CENTER_Y + 111, ColColor($64), ColColor($66));
SDL_UpdateRect2(screen, 0, 0, screen.w, screen.h);
i := WaitAnyKey;
until (i = SDLK_ESCAPE) or (i = SDLK_RETURN);
if MODVersion = 0 then
begin
if Name = 'TXDX尊使' then
begin
Rrole[0].MaxHP := 50;
Rrole[0].CurrentHP := 50;
Rrole[0].MaxMP := 50;
Rrole[0].CurrentMP := 50;
Rrole[0].MPType := 2;
Rrole[0].IncLife := 10;
Rrole[0].Attack := 30;
Rrole[0].Speed := 30;
Rrole[0].Defence := 30;
Rrole[0].Medcine := 30;
Rrole[0].UsePoi := 30;
Rrole[0].MedPoi := 30;
Rrole[0].Fist := 30;
Rrole[0].Sword := 30;
Rrole[0].Knife := 30;
Rrole[0].Unusual := 30;
Rrole[0].HidWeapon := 30;
Rrole[0].Aptitude := 100;
Rrole[0].Magic[0] := 62;
Rrole[0].MagLevel[0] := 800;
Rmagic[62].Attack[9] := 2000;
Ritem[93].Magic := 26;
Ritem[66].OnlyPracRole := -1;
Ritem[79].OnlyPracRole := -1;
instruct_32(82, 1);
instruct_32(74, 1);
end;
Rrole[13].Magic[1] := 91;
end;
if MODVersion = 22 then
begin
if Name = 'k小邪' then
begin
Rrole[0].MaxHP := 50;
Rrole[0].CurrentHP := 50;
Rrole[0].MaxMP := 50;
Rrole[0].CurrentMP := 50;
Rrole[0].MPType := 2;
Rrole[0].IncLife := 10;
Rrole[0].Attack := 150;
Rrole[0].Speed := 150;
Rrole[0].Defence := 130;
Rrole[0].Medcine := 130;
Rrole[0].UsePoi := 130;
Rrole[0].MedPoi := 130;
Rrole[0].Fist := 130;
Rrole[0].Sword := 130;
Rrole[0].Knife := 130;
Rrole[0].Unusual := 130;
Rrole[0].HidWeapon := 130;
Rrole[0].Aptitude := 100;
Rrole[0].Knowledge := 85;
Rrole[0].Magic[0] := 94;
Rrole[0].MagLevel[0] := 850;
Rrole[0].Magic[1] := 93;
Rrole[0].AttPoi := 0;
end;
if Name = '龍吟星落' then
begin
Rrole[0].MaxHP := 150;
Rrole[0].CurrentHP := 120;
Rrole[0].MaxMP := 150;
Rrole[0].CurrentMP := 220;
Rrole[0].MPType := 2;
Rrole[0].IncLife := 10;
Rrole[0].Attack := 130;
Rrole[0].Speed := 130;
Rrole[0].Defence := 130;
Rrole[0].Medcine := 130;
Rrole[0].UsePoi := 130;
Rrole[0].MedPoi := 130;
Rrole[0].Fist := 130;