This repository has been archived by the owner on Aug 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopyorn.c
8776 lines (8294 loc) · 262 KB
/
popyorn.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
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* popyorn v1.0 (December 2022)
* Copyright (C) 2018-2022 Norbert de Jonge <[email protected]>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 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 [ www.gnu.org/licenses/ ].
*
* To properly read this code, set your program's tab stop to: 2.
*/
/*========== Includes ==========*/
#include <stdio.h>
#include <math.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
#include <time.h>
#include <fcntl.h>
#include <unistd.h>
#include <limits.h> /*** Maybe remove, and just change CHAR_BIT to 8? ***/
#if defined WIN32 || _WIN32 || WIN64 || _WIN64
#include <windows.h>
#undef PlaySound
#endif
#include <SDL.h>
#include <SDL_audio.h>
#include <SDL_thread.h>
#include <SDL_ttf.h>
#include <SDL_image.h>
/*========== Includes ==========*/
/*========== Defines ==========*/
#if defined WIN32 || _WIN32 || WIN64 || _WIN64
#define SLASH "\\"
#define DEVNULL "NUL"
#define HERE ""
#define BATCH_FILE "playtest.bat"
#else
#define SLASH "/"
#define DEVNULL "/dev/null"
#define HERE "./"
#define BATCH_FILE "playtest.sh"
#endif
#define PNG_VARIOUS "png" SLASH "various" SLASH
#define PNG_BUTTONS "png" SLASH "buttons" SLASH
#define PNG_GAMEPAD "png" SLASH "gamepad" SLASH
#define PNG_DUNGEON "png" SLASH "dungeon" SLASH
#define PNG_PALACE "png" SLASH "palace" SLASH
#define PNG_SELECTED "png" SLASH "selected" SLASH
#define PNG_LIVING "png" SLASH "living" SLASH
#define PNG_SLIVING "png" SLASH "sliving" SLASH
#define PNG_EXTRAS "png" SLASH "extras" SLASH
#define PNG_ROOMS "png" SLASH "rooms" SLASH
#define PNG_MINI "png" SLASH "mini" SLASH
#define EXIT_NORMAL 0
#define EXIT_ERROR 1
#define EDITOR_NAME "popyorn"
#define EDITOR_VERSION "v1.0 (December 2022)"
#define COPYRIGHT "Copyright (C) 2022 Norbert de Jonge"
#define BIN_DIR "bin"
#define BACKUP BIN_DIR SLASH "backup.bak"
#define MAX_PATHFILE 200
#define MAX_OPTION 100
#define MAX_LEVEL 15
#define ROOMS 24
#define TILES 30
#define EVENTS 256
#define WINDOW_WIDTH 690
#define WINDOW_HEIGHT 459
#define MAX_IMG 200
#define MAX_CON 30
#define NUM_SOUNDS 20 /*** Sounds that may play at the same time. ***/
#define BAR_FULL 435
#define MAX_TEXT 100
#define REFRESH 25 /*** That is 40 frames per second, 1000/25. ***/
#define MAX_TOWRITE 720
#define ADJ_BASE_X 419
#define ADJ_BASE_Y 62
#define MAX_STATUS 100 /*** Cannot be more than MAX_TEXT. ***/
#define MAX_DATA 720
#define MAX_WARNING 200
/*** Map window ***/
#define MAP_BIG_AREA_W 1225
#define MAP_BIG_AREA_H 745
#define MAX_ZOOM 7
#define DEFAULT_ZOOM 4
/*** B9 3E 60 1A 3B 7C [00 3C] BA 8C 3B 7C 02 CF ***/
#define OFFSET_STARTMIN 0x9B3C
/*** CF BA 80 3B 7C [00 03] BA 46 42 6D 96 36 ***/
#define OFFSET_STARTHP 0x9B48
/*** 64 B2 6D BA 62 54 8F [66] 0A 3B 7C 00 0F BA 64 4E ***/
#define OFFSET_SKIPPOT 0x4C5A
/*** BA 22 60 0E 0C 2D [00 05] B9 73 66 06 3B 7C ***/
#define OFFSET_WINROOM 0x8B4C
/*** 70 [05] 2B 40 96 4C 70 00 60 1C ***/
#define OFFSET_SPEEDBASE 0x9F07
/*** 0C 2D 00 02 B9 76 66 08 70 [06] 2B 40 96 4C 60 06 ***/
#define OFFSET_SPEEDFIGHT 0x9EFF
/*** 4E BA FF 70 3E 00 5C 8F 60 16 0C 46 00 10 66 [10] ***/
#define OFFSET_TRIGGERING 0x10923
/***/
/*** 4E BA 02 C2 3B 7C [00 01] BA 64 42 2D A1 24 ***/
#define OFFSET_STARTLVL 0x3EDE
#ifndef O_BINARY
#define O_BINARY 0
#endif
/*========== Defines ==========*/
int iDebug;
char sPathFile[MAX_PATHFILE + 2];
int iNoAudio;
int iScale;
int iFullscreen;
int iStartLevel;
int iNoController;
int iBrokenRoomLinks;
int iDone[24 + 2];
int iCurRoom;
SDL_Window *window;
SDL_Window *windowmap;
unsigned int iWindowID;
unsigned int iWindowMapID;
SDL_Renderer *ascreen;
SDL_Renderer *mscreen;
unsigned int iActiveWindowID;
SDL_Cursor *curArrow;
SDL_Cursor *curWait;
SDL_Cursor *curHand;
int iHourglassFrame;
int iSandFrame;
int iPreLoaded;
int iNrToPreLoad;
int iCurrentBarHeight;
TTF_Font *font11;
TTF_Font *font15;
TTF_Font *font20;
int iStatusBarFrame;
int iScreen;
int iXPos, iYPos;
int iOKOn;
int iChanged;
int iCurLevel;
char cCurType;
int iCurGuard;
int iDownAt;
int iSelected;
int iExtras;
int iLastThing;
int iLastModifier;
int iCloseOn;
int iCustomOn;
int iIsCustom;
int iOnTile;
int iOnTileOld;
int iChangeEvent;
int iGuardSkill;
int iNoAnim;
int iFlameFrameDP;
int iChomperFrameDP;
int iSwordFrameDP;
int iMovingRoom;
int iMovingNewBusy;
int iChangingBrokenRoom;
int iChangingBrokenSide;
int iRoomArray[24 + 1 + 2][24 + 2];
int iMapOpen;
int iMovingOldX;
int iMovingOldY;
int iMovingNewX;
int iMovingNewY;
int iZoom; /*** For the big area on the Map window. ***/
int iXPosMapMoveOffset, iYPosMapMoveOffset;
int iMovingMap;
int iMapHoverYes;
int iMapHoverRoom;
int iXPosMap, iYPosMap;
int iMapHoverTile;
int iMapShowNumbers;
int iMapMoved;
int iDownAtMap;
int iXPosMapMoveStart, iYPosMapMoveStart;
int iMouse;
int iEventHover;
int iHelpOK;
int iChangeGroup, iChangeVariant;
int iCustomOK;
int iInfo;
int iThingACopyPaste[30 + 2];
int iModifierACopyPaste[30 + 2];
int iGuardACopyPaste[4 + 2];
int iCopied;
char sStatus[MAX_STATUS + 2], sStatusOld[MAX_STATUS + 2];
unsigned char cStore[1 + 2];
int iModified;
int iPlaytest;
int iYesOn, iNoOn;
int iEXESave;
int iEXEMinutesLeft;
int iEXEHitPoints;
int iEXESkipPotions;
int iEXEWinRoom;
int iEXEStartLevel;
int iEXESpeedBase;
int iEXESpeedFight;
int iEXETriggering;
/*** This is a level. ***/
unsigned char sLevelForeground[(ROOMS * TILES) + 2];
int iThingA[ROOMS + 2][TILES + 2];
unsigned char sLevelModifier[(ROOMS * TILES) + 2];
int iModifierA[ROOMS + 2][TILES + 2];
unsigned char sFirstDoorEvents[EVENTS + 2];
unsigned char sSecondDoorEvents[EVENTS + 2];
unsigned char sRoomLinks[(ROOMS * 4) + 2];
unsigned char sUnknownI[64 + 2];
unsigned char sStartPosition[3 + 2];
unsigned char sUnknownIIandIII[21 + 2];
unsigned char sGuardLocations[ROOMS + 2];
unsigned char sGuardDirections[ROOMS + 2];
unsigned char sUnknownIVaandIVb[48 + 2];
unsigned char sGuardSkills[ROOMS + 2];
unsigned char sUnknownIVc[24 + 2];
unsigned char sGuardColors[ROOMS + 2];
unsigned char sUnknownIVd[4 + 2];
int iRoomConnections[ROOMS + 2][4 + 2];
unsigned long luKidRoom;
unsigned long luKidPos;
unsigned long luKidDir;
int iRoomConnectionsBroken[ROOMS + 2][4 + 2];
int iMinX, iMaxX, iMinY, iMaxY, iStartRoomsX, iStartRoomsY;
unsigned int gamespeed;
Uint32 looptime;
static const int arDefaultEnv[16] =
{ 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0 };
static const int arDefaultGRes[16] =
{ 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 0, 4, 3, 65535, 65535 };
static const int broken_room_x = 435;
static const int broken_room_y = 78;
static const int broken_side_x[5] = { 0, 420, 450, 435, 435 };
static const int broken_side_y[5] = { 0, 78, 78, 63, 93 };
/*** controller ***/
int iController;
SDL_GameController *controller;
char sControllerName[MAX_CON + 2];
SDL_Joystick *joystick;
SDL_Haptic *haptic;
Uint32 joyleft;
Uint32 joyright;
Uint32 joyup;
Uint32 joydown;
Uint32 trigleft;
Uint32 trigright;
/*** for text ***/
SDL_Surface *message;
SDL_Texture *messaget;
SDL_Rect offset;
SDL_Color color_bl = {0x00, 0x00, 0x00, 255};
SDL_Color color_wh = {0xff, 0xff, 0xff, 255};
SDL_Color color_blue = {0x00, 0x00, 0xff, 255};
SDL_Color color_f4 = {0xf4, 0xf4, 0xf4, 255};
SDL_Texture *imgloading;
SDL_Texture *imghourglasssprite;
SDL_Texture *imgsandsprite;
SDL_Texture *imgblack;
SDL_Texture *imgfaded;
SDL_Texture *imgpopup;
SDL_Texture *imgok[2 + 2];
SDL_Texture *imgdungeon[255 + 2][255 + 2];
SDL_Texture *imgpalace[255 + 2][255 + 2];
SDL_Texture *imgselected[255 + 2][255 + 2];
SDL_Texture *imgleft_0, *imgleft_1;
SDL_Texture *imgright_0, *imgright_1;
SDL_Texture *imgup_0, *imgup_1;
SDL_Texture *imgdown_0, *imgdown_1;
SDL_Texture *imglrno, *imgudno, *imgudnonfo;
SDL_Texture *imgroomsoff, *imgroomson_0, *imgroomson_1;
SDL_Texture *imgbroomsoff, *imgbroomson_0, *imgbroomson_1;
SDL_Texture *imgeventsoff, *imgeventson_0, *imgeventson_1;
SDL_Texture *imgsaveoff, *imgsaveon_0, *imgsaveon_1;
SDL_Texture *imgquit_0, *imgquit_1;
SDL_Texture *imgprevoff, *imgprevon_0, *imgprevon_1;
SDL_Texture *imgnextoff, *imgnexton_0, *imgnexton_1;
SDL_Texture *imgkidr[2 + 2], *imgkidl[2 + 2];
SDL_Texture *imgbar;
SDL_Texture *extras[10 + 2];
SDL_Texture *imgdungeont, *imgpalacet;
SDL_Texture *imgclosebig_0, *imgclosebig_1;
SDL_Texture *imgcustoma0, *imgcustomi0, *imgcustoma1, *imgcustomi1;
SDL_Texture *imgborderb, *imgborders, *imgborderbl, *imgbordersl;
SDL_Texture *imgnoliving;
SDL_Texture *imgfadeds;
SDL_Texture *imgsell;
SDL_Texture *imgrl, *imgbrl;
SDL_Texture *imgroom[24 + 2];
SDL_Texture *imgsrc, *imgsrs, *imgsrm, *imgsrp, *imgsrb;
SDL_Texture *imgevents, *imgsele, *imgeventu;
SDL_Texture *imgmouse;
SDL_Texture *imgeventh;
SDL_Texture *imghelp;
SDL_Texture *imgcustom;
SDL_Texture *imgsave[2 + 2];
SDL_Texture *imgunk[2 + 2];
SDL_Texture *imgexe;
SDL_Texture *imgstatusbarsprite;
SDL_Texture *imgplaytest;
SDL_Texture *imgpopup_yn;
SDL_Texture *imgyes[2 + 2], *imgno[2 + 2];
/*** Map window ***/
SDL_Texture *imgmapon_0, *imgmapon_1, *imgmapoff;
SDL_Texture *imggrid;
SDL_Texture *imgmap, *imgmapgrid;
SDL_Texture *imgmini[31 + 2][255 + 2];
SDL_Texture *imgminiguard, *imgminiprince, *imgminihover, *imgminirelated;
SDL_Texture *imgclose[2 + 2];
SDL_Texture *imgzoom1on_0, *imgzoom1on_1, *imgzoom1off;
SDL_Texture *imgzoomfiton_0, *imgzoomfiton_1, *imgzoomfitoff;
SDL_Texture *imgzoominon_0, *imgzoominon_1, *imgzoominoff;
SDL_Texture *imgzoomouton_0, *imgzoomouton_1, *imgzoomoutoff;
SDL_Texture *imgarrowdoff, *imgarrowdon_0, *imgarrowdon_1;
SDL_Texture *imgarrowloff, *imgarrowlon_0, *imgarrowlon_1;
SDL_Texture *imgarrowroff, *imgarrowron_0, *imgarrowron_1;
SDL_Texture *imgarrowuoff, *imgarrowuon_0, *imgarrowuon_1;
SDL_Texture *imgbmrooma, *imgbmroomh;
SDL_Texture *imgsellm;
/*** sprites ***/
SDL_Texture *spriteflamed1;
SDL_Texture *spriteflamed2;
SDL_Texture *spriteflamep1;
SDL_Texture *spriteflamep2;
SDL_Texture *spritechomperd1;
SDL_Texture *spritechomperd2;
SDL_Texture *spritechomperp1;
SDL_Texture *spritechomperp2;
SDL_Texture *spritechompersel2;
SDL_Texture *spritechompersel1;
SDL_Texture *spriteswordd;
SDL_Texture *spriteswordp;
SDL_Texture *spriteswordsel;
/*** guards ***/
SDL_Texture *imggblush[2 + 2];
SDL_Texture *imggyellow[2 + 2];
SDL_Texture *imggrouge[2 + 2];
SDL_Texture *imggrose[2 + 2];
SDL_Texture *imggdgreen[2 + 2];
SDL_Texture *imggblue[2 + 2];
SDL_Texture *imgglgreen[2 + 2];
SDL_Texture *imggunknown[2 + 2];
SDL_Texture *imgskel[2 + 2];
SDL_Texture *imgfat[2 + 2];
SDL_Texture *imgjaffar[2 + 2];
SDL_Texture *imgshadow[2 + 2];
/***/
SDL_Texture *imggsel[2 + 2];
SDL_Texture *imgskelsel[2 + 2];
SDL_Texture *imgfatsel[2 + 2];
SDL_Texture *imgjaffarsel[2 + 2];
SDL_Texture *imgshadowsel[2 + 2];
struct sample {
Uint8 *data;
Uint32 dpos;
Uint32 dlen;
} sounds[NUM_SOUNDS];
void ShowUsage (void);
void PrIfDe (char *sString);
void GetPathFile (void);
void GetOptionValue (char *sArgv, char *sValue);
void LoadLevel (int iLevel);
void SaveLevel (int iLevel);
int ReadFromFile (int iFd, char *sWhat, int iSize, unsigned char *sRetString);
int EventInfo (int iNr, int iType);
void GetAsEightBits (unsigned char cChar, char *sBinary);
int BitsToInt (char *sString);
char cShowDirection (int iDirection);
int BrokenRoomLinks (int iPrint);
void CheckSides (int iRoom, int iX, int iY);
void InitScreenAction (char *sAction);
void InitScreen (void);
void LoadFonts (void);
void MixAudio (void *unused, Uint8 *stream, int iLen);
void PreLoad (char *sPath, char *sPNG, SDL_Texture **imgImage);
void PreLoadMap (char *sPath, char *sPNG, SDL_Texture **imgImage);
void ShowImage (SDL_Texture *img, int iX, int iY, char *sImageInfo,
SDL_Renderer *screen, float fMultiply, int iXYScale);
void LoadingBar (int iBarHeight);
void ShowScreen (int iScreenS);
void InitPopUp (void);
void ShowPopUp (void);
int MapEvents (SDL_Event event);
void Quit (void);
void PlaySound (char *sFile);
int InArea (int iUpperLeftX, int iUpperLeftY,
int iLowerRightX, int iLowerRightY);
int InAreaMap (int iUpperLeftX, int iUpperLeftY,
int iLowerRightX, int iLowerRightY);
void InitPopUpSave (void);
void ShowPopUpSave (void);
void DisplayText (int iStartX, int iStartY, int iFontSize,
char arText[9 + 2][MAX_TEXT + 2], int iLines, TTF_Font *font,
SDL_Color back, SDL_Color fore, int iOnMap);
void CustomRenderCopy (SDL_Texture* src, char *sImageInfo, SDL_Rect* srcrect,
SDL_Renderer* dst, SDL_Rect *dstrect);
void GetForegroundAsName (char *sBinaryFore, char *sName);
void ShowTile (int iThing, int iModifier, int iLocation);
void LSeekLevel (int iFd, int iLevel);
void WriteCharByChar (int iFd, unsigned char *sString, int iLength);
void Prev (void);
void Next (void);
void LocationToXY (int iLocation, int iXY[4]);
void ShowMap (void);
void SetLocation (int iRoom, int iLocation, int iThing, int iModifier);
void ChangePosAction (char *sAction);
void ChangePos (int iLocation);
void ShowChange (int iLocation);
void UseTile (int iTile, int iLocation, int iRoom);
int IsDisabled (int iTile);
int OnTile (void);
void SetGuard (int iLoc, int iDirection, int iSkill, int iColor);
void DisableSome (void);
int OnTileOld (void);
void CenterNumber (SDL_Renderer *screen, int iNumber, int iX, int iY,
SDL_Color fore, int iHex);
void InitRooms (void);
void WhereToStart (void);
void ShowRooms (int iRoom, int iX, int iY, int iNext);
int MouseSelectAdj (void);
void RemoveOldRoom (void);
void AddNewRoom (int iX, int iY, int iRoom);
void MapShow (void);
void LinkPlus (void);
void LinkMinus (void);
void ClearRoom (void);
float ZoomGet (void);
int MapGridStartX (void);
int MapGridStartY (void);
void SetMapHover (int iRoom, int iX, int iY);
void ShowRoomsMap (int iRoom, int iX, int iY);
int RelatedToHover (int iRoom, int iTile);
void MapAction (char *sAction);
void MapControllerDown (SDL_Event event);
void MapControllerUp (SDL_Event event);
void MapControllerMotion (SDL_Event event);
void MapButtonDown (SDL_Event event);
void MapButtonUp (SDL_Event event);
void MapKeyDown (SDL_Event event);
void MapMouseMotion (SDL_Event event);
void MapMouseWheel (SDL_Event event);
void MapHide (void);
void ZoomIncrease (void);
void ZoomDecrease (void);
void ChangeEvent (int iAmount, int iChangePos);
void EventRoom (int iRoom);
void EventDoor (int iTile);
void EventNext (int iNoNext);
void Help (void);
void ShowHelp (void);
void OpenURL (char *sURL);
void ApplySkillIfNecessary (int iLoc);
void ChangePosCustomAction (char *sAction, int iLocation);
int ChangePosCustom (int iLocation);
void ChangeCustom (int iAmount, char cGroupOrVariant);
void ShowChangeCustom (void);
void CopyPaste (int iRoom, int iAction);
void Zoom (int iToggleFull);
void EXE (void);
void ShowEXE (void);
void EXELoad (void);
void EXESave (void);
void UpdateStatusBar (void);
int PlusMinus (int *iWhat, int iX, int iY,
int iMin, int iMax, int iChange, int iAddChanged);
unsigned long BytesAsLU (unsigned char *sData, int iBytes);
void WriteByte (int iFd, int iValue);
void WriteWord (int iFd, int iValue);
void CreateBAK (void);
int OnLevelBar (void);
void RunLevel (int iLevel);
int StartGame (void *unused);
void ModifyForPlaytest (int iLevel);
void ModifyBack (void);
void Sprinkle (void);
void FlipRoom (int iRoom, int iAxis);
void GetModifierAsName (int iFore, int iMod, char *sName);
/*****************************************************************************/
int main (int argc, char *argv[])
/*****************************************************************************/
{
int iLoopArg;
char sStartLevel[MAX_OPTION + 2];
time_t tm;
SDL_version verc, verl;
iDebug = 0;
iNoAudio = 0;
iScale = 1;
iFullscreen = 0;
iStartLevel = 1;
iNoController = 0;
iExtras = 0;
iLastThing = 0;
iLastModifier = 0;
iNoAnim = 0;
iMapOpen = 0;
iZoom = DEFAULT_ZOOM;
iMapHoverRoom = 0;
iMapShowNumbers = 0;
iMouse = 0;
iEventHover = 0;
iInfo = 0;
iCopied = 0;
iModified = 0;
if (argc > 1)
{
for (iLoopArg = 1; iLoopArg <= argc - 1; iLoopArg++)
{
if ((strcmp (argv[iLoopArg], "-h") == 0) ||
(strcmp (argv[iLoopArg], "-?") == 0) ||
(strcmp (argv[iLoopArg], "--help") == 0))
{
ShowUsage();
}
else if ((strcmp (argv[iLoopArg], "-v") == 0) ||
(strcmp (argv[iLoopArg], "--version") == 0))
{
printf ("%s %s\n", EDITOR_NAME, EDITOR_VERSION);
exit (EXIT_NORMAL);
}
else if ((strcmp (argv[iLoopArg], "-d") == 0) ||
(strcmp (argv[iLoopArg], "--debug") == 0))
{
iDebug = 1;
}
else if ((strcmp (argv[iLoopArg], "-n") == 0) ||
(strcmp (argv[iLoopArg], "--noaudio") == 0))
{
iNoAudio = 1;
}
else if ((strcmp (argv[iLoopArg], "-z") == 0) ||
(strcmp (argv[iLoopArg], "--zoom") == 0))
{
iScale = 2;
}
else if ((strcmp (argv[iLoopArg], "-f") == 0) ||
(strcmp (argv[iLoopArg], "--fullscreen") == 0))
{
iFullscreen = SDL_WINDOW_FULLSCREEN_DESKTOP;
}
else if ((strncmp (argv[iLoopArg], "-l=", 3) == 0) ||
(strncmp (argv[iLoopArg], "--level=", 8) == 0))
{
GetOptionValue (argv[iLoopArg], sStartLevel);
iStartLevel = atoi (sStartLevel);
if ((iStartLevel < 0) || (iStartLevel > MAX_LEVEL))
{
iStartLevel = 1;
}
}
else if ((strcmp (argv[iLoopArg], "-s") == 0) ||
(strcmp (argv[iLoopArg], "--static") == 0))
{
iNoAnim = 1;
}
else if ((strcmp (argv[iLoopArg], "-k") == 0) ||
(strcmp (argv[iLoopArg], "--keyboard") == 0))
{
iNoController = 1;
}
else
{
ShowUsage();
}
}
}
GetPathFile();
srand ((unsigned)time(&tm));
LoadLevel (iStartLevel);
/*** Show the SDL version used for compiling and linking. ***/
if (iDebug == 1)
{
SDL_VERSION (&verc);
SDL_GetVersion (&verl);
printf ("[ INFO ] Compiled with SDL %u.%u.%u, linked with SDL %u.%u.%u.\n",
verc.major, verc.minor, verc.patch, verl.major, verl.minor, verl.patch);
}
InitScreen();
Quit();
return 0;
}
/*****************************************************************************/
void ShowUsage (void)
/*****************************************************************************/
{
printf ("%s %s\n%s\n\n", EDITOR_NAME, EDITOR_VERSION, COPYRIGHT);
printf ("Usage:\n");
printf (" %s [OPTIONS]\n\nOptions:\n", EDITOR_NAME);
printf (" -h, -?, --help display this help and exit\n");
printf (" -v, --version output version information and"
" exit\n");
printf (" -d, --debug also show levels on the console\n");
printf (" -n, --noaudio do not play sound effects\n");
printf (" -z, --zoom double the interface size\n");
printf (" -f, --fullscreen start in fullscreen mode\n");
printf (" -l=NR, --level=NR start in level NR\n");
printf (" -s, --static do not display animations\n");
printf (" -k, --keyboard do not use a game controller\n");
printf ("\n");
exit (EXIT_NORMAL);
}
/*****************************************************************************/
void PrIfDe (char *sString)
/*****************************************************************************/
{
if (iDebug == 1) { printf ("%s", sString); }
}
/*****************************************************************************/
void GetPathFile (void)
/*****************************************************************************/
{
int iFound;
DIR *dDir;
struct dirent *stDirent;
char sExtension[100 + 2];
char sWarning[MAX_WARNING + 2];
iFound = 0;
dDir = opendir (BIN_DIR);
if (dDir == NULL)
{
printf ("[FAILED] Cannot open directory \"%s\": %s!\n",
BIN_DIR, strerror (errno));
exit (EXIT_ERROR);
}
while ((stDirent = readdir (dDir)) != NULL)
{
if (iFound == 0)
{
if ((strcmp (stDirent->d_name, ".") != 0) &&
(strcmp (stDirent->d_name, "..") != 0))
{
snprintf (sExtension, 100, "%s", strrchr (stDirent->d_name, '.'));
if ((toupper (sExtension[1]) == 'B') &&
(toupper (sExtension[2]) == 'I') &&
(toupper (sExtension[3]) == 'N'))
{
iFound = 1;
snprintf (sPathFile, MAX_PATHFILE, "%s%s%s", BIN_DIR, SLASH,
stDirent->d_name);
if (iDebug == 1)
{
printf ("[ OK ] Found Macintosh BIN \"%s\".\n", sPathFile);
}
}
}
}
}
closedir (dDir);
if (iFound == 0)
{
snprintf (sWarning, MAX_WARNING, "Cannot find a .bin disk image in"
" directory \"%s\"!", BIN_DIR);
printf ("[ WARN ] %s\n", sWarning);
SDL_ShowSimpleMessageBox (SDL_MESSAGEBOX_ERROR,
"Warning", sWarning, NULL);
exit (EXIT_ERROR);
}
/*** Is the file accessible? ***/
if (access (sPathFile, R_OK|W_OK) == -1)
{
printf ("[ WARN ] Cannot access \"%s\": %s!\n",
sPathFile, strerror (errno));
exit (EXIT_ERROR);
}
}
/*****************************************************************************/
void GetOptionValue (char *sArgv, char *sValue)
/*****************************************************************************/
{
int iTemp;
char sTemp[MAX_OPTION + 2];
iTemp = strlen (sArgv) - 1;
snprintf (sValue, MAX_OPTION, "%s", "");
while (sArgv[iTemp] != '=')
{
snprintf (sTemp, MAX_OPTION, "%c%s", sArgv[iTemp], sValue);
snprintf (sValue, MAX_OPTION, "%s", sTemp);
iTemp--;
}
}
/*****************************************************************************/
void LoadLevel (int iLevel)
/*****************************************************************************/
{
int iFd;
int iPosFore, iPosBack;
char sBinaryFore[9 + 2]; /*** 8 chars, plus \0 ***/
char sName[7 + 2];
char sForegrounds[100 + 2], sForegroundsTemp[100 + 2];
char sModifiers[100 + 2], sModifiersTemp[100 + 2];
int iNameDone;
char sString[MAX_DATA + 2];
char sReferenceNr[7 + 2];
/*** Used for looping. ***/
int iLoopRoom;
int iLoopTile;
int iLoopEvent;
int iLoopLink;
int iLoopMinus;
int iLoopGuard;
iFd = open (sPathFile, O_RDONLY|O_BINARY);
if (iFd == -1)
{
printf ("[FAILED] Could not open \"%s\": %s!\n",
sPathFile, strerror (errno));
exit (EXIT_ERROR);
}
LSeekLevel (iFd, iLevel);
iChanged = 0;
ReadFromFile (iFd, "Level Foreground", ROOMS * TILES, sLevelForeground);
ReadFromFile (iFd, "Level Modifier", ROOMS * TILES, sLevelModifier);
for (iLoopRoom = 1; iLoopRoom <= ROOMS; iLoopRoom++)
{
for (iLoopTile = 1; iLoopTile <= TILES; iLoopTile++)
{
iPosFore = ((iLoopRoom - 1) * TILES) + (iLoopTile - 1);
iPosBack = iPosFore;
iThingA[iLoopRoom][iLoopTile] = sLevelForeground[iPosFore];
iModifierA[iLoopRoom][iLoopTile] = sLevelModifier[iPosBack];
}
}
if (iDebug == 1)
{
snprintf (sForegrounds, 100, "%s", "");
snprintf (sModifiers, 100, "%s", "");
for (iLoopRoom = 1; iLoopRoom <= ROOMS; iLoopRoom++)
{
printf ("\nRoom %i:\n\n", iLoopRoom);
for (iLoopTile = 1; iLoopTile <= TILES; iLoopTile++)
{
iPosFore = ((iLoopRoom - 1) * TILES) + (iLoopTile - 1);
iPosBack = iPosFore;
GetAsEightBits (sLevelForeground[iPosFore], sBinaryFore);
GetForegroundAsName (sBinaryFore, sName);
if (strcmp (sForegrounds, "") == 0)
{
snprintf (sForegrounds, 100, "%s", sName);
} else {
snprintf (sForegroundsTemp, 100, "%s", sForegrounds);
snprintf (sForegrounds, 100, "%s|%s", sForegroundsTemp, sName);
}
iNameDone = 0;
/*** gate or door ***/
if ((iThingA[iLoopRoom][iLoopTile] == 0x04) ||
(iThingA[iLoopRoom][iLoopTile] == (0x04 + 0x20)))
{
switch (sLevelModifier[iPosBack])
{
case 1: snprintf (sName, 9, "%s", "Open "); break;
default: snprintf (sName, 9, "%s", "Closed "); break;
}
iNameDone = 1;
}
/*** drop or raise ***/
if ((iThingA[iLoopRoom][iLoopTile] == 0x06) ||
(iThingA[iLoopRoom][iLoopTile] == 0x0F) ||
(iThingA[iLoopRoom][iLoopTile] == (0x06 + 0x20)) ||
(iThingA[iLoopRoom][iLoopTile] == (0x0F + 0x20)))
{
snprintf (sString, 3 + 6, "%i ",
sLevelModifier[iPosBack] + 1);
strncpy (sReferenceNr, sString, 7);
sReferenceNr[7] = '\0';
snprintf (sName, 9, "%s", sReferenceNr);
iNameDone = 1;
}
/*** the rest ***/
if (iNameDone == 0)
{
GetModifierAsName (sLevelForeground[iPosFore],
sLevelModifier[iPosBack], sName);
}
if (strcmp (sModifiers, "") == 0)
{
snprintf (sModifiers, 100, "%s", sName);
} else {
snprintf (sModifiersTemp, 100, "%s", sModifiers);
snprintf (sModifiers, 100, "%s|%s", sModifiersTemp, sName);
}
if ((iLoopTile == 10) || (iLoopTile == 20) || (iLoopTile == 30))
{
printf ("%s\n", sForegrounds);
printf ("%s\n", sModifiers);
if ((iLoopTile == 10) || (iLoopTile == 20))
{
for (iLoopMinus = 1; iLoopMinus <= 79; iLoopMinus++)
{ printf ("-"); }
printf ("\n");
}
snprintf (sForegrounds, 100, "%s", "");
snprintf (sModifiers, 100, "%s", "");
}
}
PrIfDe ("\n");
}
}
/*** Load first and second door events. ***/
ReadFromFile (iFd, "First Door Events", EVENTS, sFirstDoorEvents);
ReadFromFile (iFd, "Second Door Events", EVENTS, sSecondDoorEvents);
if (iDebug == 1)
{
for (iLoopEvent = 0; iLoopEvent < EVENTS; iLoopEvent++)
{
printf ("[ INFO ] Event %i changes the door in room: %i, location:"
" %i.",
iLoopEvent + 1,
EventInfo (iLoopEvent, 1),
EventInfo (iLoopEvent, 2));
switch (EventInfo (iLoopEvent, 3))
{
case 1: printf (" (next: yes)\n"); break;
case 0: printf (" (next: no)\n"); break;
}
}
}
/*** Load the room links. ***/
ReadFromFile (iFd, "Room Links", (ROOMS * 4), sRoomLinks);
for (iLoopLink = 0; iLoopLink < (ROOMS * 4); iLoopLink+=4)
{
iRoomConnections[(iLoopLink / 4) + 1][1] =
sRoomLinks[iLoopLink]; /*** left ***/
iRoomConnections[(iLoopLink / 4) + 1][2] =
sRoomLinks[iLoopLink + 1]; /*** right ***/
iRoomConnections[(iLoopLink / 4) + 1][3] =
sRoomLinks[iLoopLink + 2]; /*** up ***/
iRoomConnections[(iLoopLink / 4) + 1][4] =
sRoomLinks[iLoopLink + 3]; /*** down ***/
if (iDebug == 1)
{
printf ("[ INFO ] Room %i is connected to room (0 = none): l%i, "
"r%i, u%i, d%i\n",
(iLoopLink / 4) + 1,
sRoomLinks[iLoopLink],
sRoomLinks[iLoopLink + 1],
sRoomLinks[iLoopLink + 2],
sRoomLinks[iLoopLink + 3]);
}
}
/*** Load Unknown I. ***/
ReadFromFile (iFd, "Unknown I", 64, sUnknownI);
/*** We want remapped modifiers in all 24 rooms. ***/
sUnknownI[0] = 0x18;
/*** Load Start Position. ***/
ReadFromFile (iFd, "Start Position", 3, sStartPosition);
luKidRoom = sStartPosition[0];
luKidPos = sStartPosition[1] + 1;
luKidDir = sStartPosition[2];
/*** 1 of 2 ***/
if ((iLevel == 1) || (iLevel == 13))
{
if (luKidDir == 0) { luKidDir = 255; } else { luKidDir = 0; }
}
if (iDebug == 1)
{
printf ("[ INFO ] The kid starts in room: %lu, position: %lu, turned: "
"%c\n",
luKidRoom,
luKidPos,
cShowDirection ((int)luKidDir));
}
PrIfDe ("[ OK ] Checking for broken room links.\n");
iBrokenRoomLinks = BrokenRoomLinks (1);
/*** Load Unknown II-IVd, guard data. ***/
ReadFromFile (iFd, "Unknown II and III", 21, sUnknownIIandIII);
ReadFromFile (iFd, "Guard Locations", ROOMS, sGuardLocations);
ReadFromFile (iFd, "Guard Directions", ROOMS, sGuardDirections);
ReadFromFile (iFd, "Unknown IVa and IVb", 48, sUnknownIVaandIVb);
ReadFromFile (iFd, "Guard Skills", ROOMS, sGuardSkills);
ReadFromFile (iFd, "Unknown IVc", 24, sUnknownIVc);
ReadFromFile (iFd, "Guard Colors", ROOMS, sGuardColors);
ReadFromFile (iFd, "Unknown IVd", 4, sUnknownIVd);
/*** Display guard information. ***/
if (iDebug == 1)
{
for (iLoopGuard = 0; iLoopGuard < ROOMS; iLoopGuard++)
{
if (sGuardLocations[iLoopGuard] < 30)
{
printf ("[ INFO ] A guard in room: %i, location: %i, turned: %c, "
"skill: %i, color: %i\n",
iLoopGuard + 1,
sGuardLocations[iLoopGuard] + 1,
cShowDirection (sGuardDirections[iLoopGuard]),
sGuardSkills[iLoopGuard],
sGuardColors[iLoopGuard]);
}
}
}
switch (arDefaultEnv[iLevel])
{
case 0: cCurType = 'd'; break;
case 1: cCurType = 'p'; break;
}
iCurGuard = arDefaultGRes[iLevel];
/*** Back to a centered map. ***/
iXPosMapMoveOffset = 0;
iYPosMapMoveOffset = 0;
iCurLevel = iLevel;
iCurRoom = (int)luKidRoom;
iOnTile = 1;
iPlaytest = 0;
close (iFd);
}
/*****************************************************************************/
void SaveLevel (int iLevel)
/*****************************************************************************/
{
int iFd;
char sToWrite[MAX_TOWRITE + 2];
/*** Used for looping. ***/
int iLoopRoom;
int iLoopTile;
int iLoopLink;
if (iChanged == 0) { return; }
CreateBAK();
iFd = open (sPathFile, O_WRONLY|O_BINARY, 0600);
if (iFd == -1)
{
printf ("[FAILED] Could not open \"%s\": %s!\n",