forked from zenorogue/hyperrogue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapeditor.cpp
More file actions
2265 lines (1922 loc) · 67.9 KB
/
Copy pathmapeditor.cpp
File metadata and controls
2265 lines (1922 loc) · 67.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// HyperRogue map editor
// Copyright (C) 2011-2016 Zeno Rogue, see 'hyper.cpp' for details
#include <map>
#include <stdint.h>
#if ISWINDOWS
#include "direntx.h"
#include "direntx.c"
#else
#include <dirent.h>
#endif
namespace mapeditor {
int subcanvas;
int displaycodes;
struct editwhat {
double dist;
int rotid, symid, pointid;
bool side;
cell *c;
} ew, ewsearch;
bool autochoose = ISMOBILE;
#if CAP_EDIT
map<int, cell*> modelcell;
void handleKeyMap(int sym, int uni);
bool handleKeyFile(int sym, int uni);
void applyModelcell(cell *c) {
if(mapeditor::whichPattern == 'H') return;
if(mapeditor::whichPattern == 'H') return;
int i = realpattern(c);
cell *c2 = modelcell[i];
if(c2) {
c->wall = c2->wall;
c->land = c2->land;
c->monst = c2->monst;
c->item = c2->item;
c->landparam = c2->landparam;
c->wparam = c2->wparam;
c->mondir = c2->mondir;
if(c2->mondir != NODIR)
c->mondir = (c2->mondir - patterndir(c2) + patterndir(c) + 7*6*5) % c->type;
}
}
#endif
}
#if CAP_EDIT
namespace mapstream {
std::map<cell*, int> cellids;
vector<cell*> cellbyid;
vector<char> relspin;
FILE *f;
void addToQueue(cell* c) {
if(cellids.count(c)) return;
int numcells = size(cellbyid);
cellbyid.push_back(c);
cellids[c] = numcells;
}
void saveChar(char c) { fwrite(&c, 1, 1, f); }
template<class T> void save(T& c) { fwrite(&c, sizeof(T), 1, f); }
char loadChar() { char c; int i=fread(&c, 1, 1, f); if(i!=1) return 0; else return c; }
template<class T> int load(T& c) { return fread(&c, sizeof(T), 1, f); }
int32_t loadInt() { int i; if(load(i) < 1) return -1; else return i; }
void savePoint(const hyperpoint& h) {
for(int i=0; i<3; i++) { double x = h[i]; save(x); }
}
hyperpoint loadPoint() {
hyperpoint h;
for(int i=0; i<3; i++) { double x; load(x); h[i] = x; }
return h;
}
bool saveMap(const char *fname) {
f = fopen(fname, "wb");
if(!f) return false;
int32_t i = VERNUM; save(i);
save(mapeditor::whichPattern);
addToQueue(cwt.c->master->c7);
for(int i=0; i<size(cellbyid); i++) {
cell *c = cellbyid[i];
if(i) {
for(int j=0; j<c->type; j++) if(c->mov[j] && cellids.count(c->mov[j]) &&
cellids[c->mov[j]] < i) {
int32_t i = cellids[c->mov[j]];
save(i);
saveChar(c->spn(j));
saveChar(j);
break;
}
}
saveChar(c->land);
saveChar(c->mondir);
saveChar(c->monst);
saveChar(c->wall);
// saveChar(c->barleft);
// saveChar(c->barright);
saveChar(c->item);
saveChar(c->mpdist);
// saveChar(c->bardir);
save(c->wparam); save(c->landparam);
saveChar(c->stuntime); saveChar(c->hitpoints);
for(int j=0; j<c->type; j++) {
cell *c2 = c->mov[j];
if(c2 && c2->land != laNone) addToQueue(c2);
}
}
int32_t n = -1; save(n);
int32_t id = cellids.count(cwt.c) ? cellids[cwt.c] : -1;
save(id);
for(int i=0; i<USERSHAPEGROUPS; i++) for(int j=0; j<USERSHAPEIDS; j++) {
usershape *us = usershapes[i][j];
if(!us) continue;
for(int l=0; l<USERLAYERS; l++) if(size(us->d[l].list)) {
usershapelayer& ds(us->d[l]);
save(i); save(j); save(l); save(ds.sym); save(ds.rots); save(ds.color);
n = size(ds.list); save(n);
savePoint(ds.shift);
savePoint(ds.spin);
for(int i=0; i<size(ds.list); i++) savePoint(ds.list[i]);
}
}
n = -1; save(n);
fclose(f);
cellids.clear();
cellbyid.clear();
return true;
}
int fixspin(int rspin, int dir, int t) {
if(dir >= 0 && dir < t)
return (dir + rspin) % t;
else
return dir;
}
bool loadMap(const char *fname) {
f = fopen(fname, "rb");
if(!f) return false;
int vernum = loadInt();
printf("vernum = %d\n", vernum);
if(vernum >= 7400) load(mapeditor::whichPattern);
clearMemory();
initcells();
if(shmup::on) shmup::init();
while(true) {
cell *c;
int rspin;
if(size(cellbyid) == 0) {
c = currentmap->gamestart();
rspin = 0;
}
else {
int32_t parent = loadInt();
if(parent<0 || parent >= size(cellbyid)) break;
int dir = loadChar();
cell *c2 = cellbyid[parent];
dir = fixspin(dir, relspin[parent], c2->type);
c = createMov(c2, dir);
// printf("%p:%d,%d -> %p\n", c2, dir, c);
// spinval becomes xspinval
rspin = (c2->spn(dir) - loadChar() + 42) % c->type;
}
cellbyid.push_back(c);
relspin.push_back(rspin);
c->land = (eLand) loadChar();
c->mondir = fixspin(rspin, loadChar(), c->type);
c->monst = (eMonster) loadChar();
c->wall = (eWall) loadChar();
// c->barleft = (eLand) loadChar();
// c->barright = (eLand) loadChar();
c->item = (eItem) loadChar();
c->mpdist = loadChar();
c->bardir = NOBARRIERS;
// fixspin(rspin, loadChar(), c->type);
if(vernum < 7400) {
load(c->aitmp);
c->wparam = c->aitmp;
}
else load(c->wparam);
load(c->landparam);
// backward compatibility
if(vernum < 7400 && !isIcyLand(c->land)) c->landparam = HEAT(c);
c->stuntime = loadChar();
c->hitpoints = loadChar();
if(mapeditor::whichPattern)
mapeditor::modelcell[mapeditor::realpattern(c)] = c;
}
int32_t whereami = loadInt();
if(whereami >= 0 && whereami < size(cellbyid))
cwt.c = cellbyid[whereami];
else cwt.c = currentmap->gamestart();
for(int i=0; i<size(cellbyid); i++) {
cell *c = cellbyid[i];
if(c->bardir != NODIR && c->bardir != NOBARRIERS)
extendBarrier(c);
}
for(int d=BARLEV-1; d>=0; d--)
for(int i=0; i<size(cellbyid); i++) {
cell *c = cellbyid[i];
if(c->mpdist <= d)
for(int j=0; j<c->type; j++) {
cell *c2 = createMov(c, j);
setdist(c2, d+1, c);
}
}
cellbyid.clear();
relspin.clear();
if(shmup::on) shmup::init();
timerstart = time(NULL); turncount = 0;
sagephase = 0; hardcoreAt = 0;
timerstopped = false;
savecount = 0; savetime = 0;
cheater = 1;
if(vernum >= 7400) while(true) {
int i = loadInt();
if(i == -1) break;
int j = loadInt(), l = loadInt();
if(i<0 || i >= USERSHAPEGROUPS) break;
if(j<0 || j >= USERSHAPEIDS) break;
if(l<0 || l >= USERLAYERS) break;
initShape(i, j);
usershapelayer& ds(usershapes[i][j]->d[l]);
load(ds.sym); load(ds.rots); load(ds.color);
ds.list.clear();
int siz = loadInt();
ds.shift = loadPoint();
ds.spin = loadPoint();
for(int i=0; i<siz; i++)
ds.list.push_back(loadPoint());
}
buildpolys();
bfs();
restartGraph();
return true;
}
}
#endif
namespace mapeditor {
bool drawplayer = true;
char whichPattern = 0;
char whichShape = 0;
char whichCanvas = 0;
int nopattern(cell *c) {
if(isWarped(c) && !euclid) {
int u = ishept(c)?1:0;
int qhex = 0;
for(int v=0; v<c->type; v++) if(c->mov[v] && !isWarped(c->mov[v])) {
u += 2;
if(!ishept(c->mov[v])) qhex++;
}
if(u == 2 && qhex == 1) return 8;
if(u == 6 && qhex == 2) return 10;
return u;
}
return ishept(c) ? 1 : ishex1(c) ? 2 : 0; // 0 to 1
}
bool reflectPatternAt(cell *c, char p = whichPattern) {
if(p == 'p' && polarb50(c)) return true;
if(p == 0 && nopattern(c) == 4) {
int d = patterndir(c);
return !isWarped(createMov(c, (d+1)%6));
}
return false;
}
int downdir(cell *c, cellfunction *cf = coastvalEdge) {
cell *c2 = chosenDown(c, 1, 1, cf);
if(!c2) return 0;
return neighborId(c, c2);
}
int patterndir(cell *c, char w) {
switch(w) {
case 'z': {
int t = zebra40(c);
if(euclid) return (t*4) % 6;
int t4 = t>>2, tcdir = 0;
if(purehepta) tcdir = t^1;
else if(t4 == 10) tcdir = t-20;
else if(t4 >= 4 && t4 < 7) tcdir = 40 + (t&3);
else if(t4 >= 1 && t4 < 4) tcdir = t+12;
else if(t4 >= 7 && t4 < 10) tcdir = t-24;
for(int i=0; i<c->type; i++) if(c->mov[i] && zebra40(c->mov[i]) == tcdir)
return i;
// printf("fail to fintd %d -> %d\n", t, tcdir);
return 0;
}
case 'f': {
int t = emeraldval(c);
if(euclid) return 0;
int tcdir = 0, tbest = (t&3);
for(int i=0; i<c->type; i++) {
cell *c2 = c->mov[i];
if(c2) {
int t2 = emeraldval(c2);
if((t&3) == (t2&3) && t2 > tbest)
tbest = t2, tcdir = i;
}
}
return tcdir;
}
case 'p': {
int tcdir = -1, tbest = -1;
int pa = polara50(c);
int pb = polarb50(c);
for(int i=0; i<c->type; i++) {
cell *c2 = c->mov[i];
if(c2 && polara50(c2) == pa && polarb50(c2) == pb) {
int t2 = fiftyval049(c2);
if(t2 > tbest) tbest = t2, tcdir = i;
}
}
return tcdir;
}
case 'H':
return downdir(c);
case 0: {
if(euclid) return 0;
int u = nopattern(c);
if(u == 6)
for(int i=1; i<c->type; i+=2) if(!isWarped(createMov(c,i)))
return i;
if(u == 2 || u == 3 || u == 8)
for(int i=0; i<c->type; i++) if(!isWarped(createMov(c,i)))
return i;
if(u == 4 || u == 10)
for(int i=0; i<c->type; i+=2) if(!isWarped(createMov(c,i)))
return i;
if(u == 6)
for(int i=1; i<c->type; i+=2) if(!isWarped(createMov(c,i)))
return i;
if(u == 5)
for(int i=0; i<c->type; i++) if(!isWarped(createMov(c,(i+3)%7)) && !isWarped(createMov(c,(i+4)%7)))
return i;
if(u == 9)
for(int i=0; i<c->type; i++) if(!isWarped(createMov(c,(i+2)%7)) && !isWarped(createMov(c,(i+5)%7)))
return i;
if(u == 7)
for(int i=0; i<c->type; i++) if(!isWarped(createMov(c,(i+1)%7)) && !isWarped(createMov(c,(i+6)%7)))
return i;
}
}
return 0;
}
string infix;
bool hasInfix(const string &s) {
if(infix == "") return true;
string t = "";
for(int i=0; i<size(s); i++) {
char c = s[i];
char tt = 0;
if(c >= 'a' && c <= 'z') tt += c - 32;
else if(c >= 'A' && c <= 'Z') tt += c;
else if(c == '@') tt += c;
if(tt) t += tt;
}
return t.find(infix) != string::npos;
}
bool editInfix(int uni) {
if(uni >= 'A' && uni <= 'Z') infix += uni;
else if(uni >= 'a' && uni <= 'z') infix += uni-32;
else if(infix != "" && uni == 8) infix = infix.substr(0, size(infix)-1);
else if(infix != "" && uni != 0) infix = "";
else return false;
return true;
}
cell *drawcell;
#if CAP_EDIT
int paintwhat = 0;
int painttype = 0;
int radius = 0;
string paintwhat_str = "clear monster";
cell *copywhat = NULL; int copydir; bool copyflip;
bool symRotation, sym01, sym02, sym03;
int whichpart;
const char *mapeditorhelp =
"This mode allows you to edit the map.\n\n"
"NOTE: Use at your own risk. Combinations which never "
"appear in the real game may work in an undefined way "
"(do not work, look strangely, give strange messages, or crash the game).\n\n"
"To get the most of this editor, "
"some knowledge of inner workings of HyperRogue is required. "
"Each cell has four main fields: land type, wall type, monster type, item type. "
"The same wall type (especially \"none\", \"sea\", or \"bonfire\") may look or "
"work a bit differently, based on the land it is in. Sometimes an object may "
"appear twice on the list due to subtle differences (for example, Demons could "
"move next turn or not).\n\n"
"Press w, i, l, or m to choose which aspect of cells to change, "
"then just click on the cells and they will change. Press 'c' while "
"hovering over a cell to copy that cell, this copies all information about it. "
"When copying large areas or placing multi-tile monsters, it might be important where "
"on the cell you are clicking.\n\n"
"You can also press 0-9 to apply your changes to a greater radius. "
"This also affects the copy/paste feature, allowing to copy a larger area.\n\n"
"Press F2 to save the current map (and F3 to load it). If you try this after "
"a long game of HyperRogue (without using Orbs of Safety), the filesize will "
"be very large! "
"Note however that large structures, such as "
"Great Walls, large circles and horocycles, are destroyed by this.\n\n"
"Press 'b' to mark cells as boundaries. Such cells, and cells beyond "
"them, are not copied by the copy/paste feature, nor saved by the "
"save feature.\n\n";
const char* patthelp =
"Press 'r' to choose a regular pattern. When a pattern is on, "
"editing a cell automatically edits all cells which are "
"equivalent according to this pattern. You can choose from "
"several patterns, and choose which symmetries matter "
"for equivalence. Also, you can press Space to switch between "
"the map and graphics editor quickly -- note that editing floors "
"with the graphics editor also adheres to the pattern.";
string mehelptext() {
return XLAT(mapeditorhelp) + XLAT(patthelp);
}
vector<pair<string, int> > v;
struct undo_info {
cell *c;
eWall w;
eItem i;
eMonster m;
eLand l;
char wparam;
int32_t lparam;
char dir;
};
vector<undo_info> undo;
bool checkEq(undo_info& u) {
return u.w == u.c->wall && u.i == u.c->item && u.m == u.c->monst && u.l == u.c->land &&
u.dir == u.c->mondir && u.lparam == u.c->landparam && u.wparam == u.c->wparam;
}
void saveUndo(cell *c) {
undo_info u;
u.c=c; u.w = c->wall; u.i = c->item; u.m = c->monst; u.l = c->land; u.dir = c->mondir;
u.wparam = c->wparam; u.lparam = c->landparam;
undo.push_back(u);
}
undo_info& lastUndo() { return undo[size(undo)-1]; }
void undoLock() {
if(!size(undo) || lastUndo().c) {
undo_info i; i.c = NULL; undo.push_back(i);
}
}
void applyUndo() {
while(size(undo) && !lastUndo().c) undo.pop_back();
while(size(undo)) {
undo_info& i(lastUndo());
if(!i.c) break;
i.c->wall = i.w;
i.c->item = i.i;
i.c->monst = i.m;
i.c->land = i.l;
i.c->mondir = i.dir;
i.c->wparam = i.wparam;
i.c->landparam = i.lparam;
undo.pop_back();
}
}
void checkUndo() {
if(checkEq(undo[size(undo)-1])) undo.pop_back();
}
int itc(int k) {
if(k == 0) return 0;
if(k == 1) return 0x40;
if(k == 2) return 0x80;
if(k == 3) return 0xFF;
return 0x20;
}
bool choosefile = false;
bool editext = false;
#define CDIR 0xC0C0C0
#define CFILE forecolor
bool filecmp(const pair<string,int> &f1, const pair<string,int> &f2) {
if(f1.first == "../") return true;
if(f2.first == "../") return false;
if(f1.second != f2.second)
return f1.second == CDIR;
return f1.first < f2.first;
}
string filecaption, cfileext;
string *cfileptr;
void drawFileDialog() {
displayfr(vid.xres/2, 30 + vid.fsize, 2, vid.fsize,
filecaption, forecolor, 8);
string& cfile = *cfileptr;
displayfr(vid.xres/2, 34 + vid.fsize * 2, 2, vid.fsize,
cfile, editext ? 0xFF00FF : 0xFFFF00, 8);
displayButton(vid.xres*1/5, 38+vid.fsize * 3,
"F2 = save", 2000+SDLK_F2, 8);
displayButton(vid.xres*2/5, 38+vid.fsize * 3,
"F3 = load", 2000+SDLK_F3, 8);
displayButton(vid.xres*3/5, 38+vid.fsize * 3,
"F4 = extension", 2000+SDLK_F4, 8);
displayButton(vid.xres*4/5, 38+vid.fsize * 3,
"Enter = back", 2000+SDLK_RETURN, 8);
v.clear();
DIR *d;
struct dirent *dir;
string where = ".";
for(int i=0; i<size(cfile); i++)
if(cfile[i] == '/' || cfile[i] == '\\')
where = cfile.substr(0, i+1);
d = opendir(where.c_str());
if (d) {
while ((dir = readdir(d)) != NULL) {
string s = dir->d_name;
if(s != ".." && s[0] == '.') ;
else if(size(s) > 4 && s.substr(size(s)-4) == cfileext)
v.push_back(make_pair(s, CFILE));
else if(dir->d_type & DT_DIR)
v.push_back(make_pair(s+"/", CDIR));
}
closedir(d);
}
sort(v.begin(), v.end(), filecmp);
int q = v.size();
int percolumn = (vid.yres-38) / (vid.fsize+5) - 4;
int columns = 1 + (q-1) / percolumn;
for(int i=0; i<q; i++) {
int x = 16 + (vid.xres * (i/percolumn)) / columns;
int y = 42 + vid.fsize * 4 + (vid.fsize+5) * (i % percolumn);
displayColorButton(x, y, v[i].first, 1000 + i, 0, 0, v[i].second, 0xFFFF00);
}
keyhandler = handleKeyFile;
}
void displayFunctionKeys() {
int fs = min(vid.fsize + 5, vid.yres/26);
displayButton(8, vid.yres-8-fs*11, XLAT("F1 = help"), SDLK_F1, 0);
displayButton(8, vid.yres-8-fs*10, XLAT("F2 = save"), SDLK_F2, 0);
displayButton(8, vid.yres-8-fs*9, XLAT("F3 = load"), SDLK_F3, 0);
displayButton(8, vid.yres-8-fs*8, XLAT("F4 = file"), SDLK_F3, 0);
displayButton(8, vid.yres-8-fs*7, XLAT("F5 = restart"), SDLK_F5, 0);
displayButton(8, vid.yres-8-fs*6, XLAT("F6 = HQ shot"), SDLK_F6, 0);
displayButton(8, vid.yres-8-fs*5, XLAT("F7 = player on/off"), SDLK_F7, 0);
#if CAP_SVG
displayButton(8, vid.yres-8-fs*4, XLAT("F8 = SVG shot"), SDLK_F8, 0);
#endif
displayButton(8, vid.yres-8-fs*3, XLAT("SPACE = map/graphics"), ' ', 0);
displayButton(8, vid.yres-8-fs*2, XLAT("ESC = return to the game"), SDLK_ESCAPE, 0);
}
void vpush(int i, const char *name) {
string s = XLATN(name);
if(!hasInfix(s)) return;
v.push_back(make_pair(s, i));
}
void showPrePattern() {
dialog::init("predesigned patterns");
dialog::addItem(XLAT("Gameboard"), 'g');
dialog::addItem(XLAT("random colors"), 'r');
dialog::addItem(XLAT("rainbow landscape"), 'l');
dialog::addItem(XLAT("dark rainbow landscape"), 'd');
dialog::addItem(XLAT("football"), 'F');
dialog::addSelItem(XLAT("emerald pattern"), "emerald", 'e');
dialog::addSelItem(XLAT("four elements"), "palace", 'b');
dialog::addSelItem(XLAT("eight domains"), "palace", 'a');
dialog::addSelItem(XLAT("zebra pattern"), "zebra", 'z');
dialog::addSelItem(XLAT("four triangles"), "zebra", 't');
dialog::addSelItem(XLAT("three stripes"), "zebra", 'x');
dialog::addSelItem(XLAT("random black-and-white"), "current", 'w');
dialog::addSelItem(XLAT("field pattern C"), "field", 'C');
dialog::addSelItem(XLAT("field pattern D"), "field", 'D');
dialog::addSelItem(XLAT("field pattern N"), "field", 'N');
dialog::addSelItem(XLAT("field pattern S"), "field", 'S');
dialog::display();
keyhandler = [] (int sym, int uni) {
dialog::handleNavigation(sym, uni);
if((uni >= 'a' && uni <= 'z') || (uni >= 'A' && uni <= 'Z')) {
whichCanvas = uni;
subcanvas = rand();
firstland = laCanvas; randomPatternsMode = false;
restartGame();
}
else if(doexiton(sym, uni)) popScreen();
};
}
void showPattern() {
dialog::init();
dialog::addBoolItem(XLAT(euclid ? "three colors" : "Emerald Pattern"), (whichPattern == 'f'), 'f');
dialog::addBoolItem(XLAT("Palace Pattern"), (whichPattern == 'p'), 'p');
dialog::addBoolItem(XLAT(euclid ? "three colors rotated" : "Zebra Pattern"), (whichPattern == 'z'), 'z');
dialog::addBoolItem(XLAT("field pattern"), (whichPattern == 'F'), 'F');
if(whichPattern == 'f') symRotation = true;
if(whichPattern == 'F') ;
else if(!euclid) {
dialog::addBoolItem(XLAT("rotational symmetry"), (symRotation), '0');
dialog::addBoolItem(XLAT("symmetry 0-1"), (sym01), '1');
dialog::addBoolItem(XLAT("symmetry 0-2"), (sym02), '2');
dialog::addBoolItem(XLAT("symmetry 0-3"), (sym03), '3');
}
else
dialog::addBoolItem(XLAT("edit all three colors"), (symRotation), '0');
dialog::addBoolItem(XLAT("display pattern codes (full)"), (displaycodes == 1), 'd');
dialog::addBoolItem(XLAT("display pattern codes (simplified)"), (displaycodes == 2), 's');
dialog::addBoolItem(XLAT("display only hexagons"), (whichShape == '6'), '6');
dialog::addBoolItem(XLAT("display only heptagons"), (whichShape == '7'), '7');
dialog::addBoolItem(XLAT("display the triheptagonal grid"), (whichShape == '8'), '8');
dialog::addItem(XLAT("line patterns"), 'l');
dialog::addItem(XLAT("predesigned patterns"), 'r');
dialog::display();
keyhandler = [] (int sym, int uni) {
dialog::handleNavigation(sym, uni);
if(uni == 'f' || uni == 'p' || uni == 'z' || uni == 'H' || uni == 'F') {
if(whichPattern == uni) whichPattern = 0;
else whichPattern = uni;
modelcell.clear();
}
else if(uni == '0') symRotation = !symRotation;
else if(uni == '1') sym01 = !sym01;
else if(uni == '2') sym02 = !sym02;
else if(uni == '3') sym03 = !sym03;
else if(uni == '6' || uni == '7' || uni == '8') {
if(whichShape == uni) whichShape = 0;
else whichShape = uni;
}
else if(uni == '3') sym03 = !sym03;
else if(uni == 'd') displaycodes = displaycodes == 1 ? 0 : 1;
else if(uni == 's') displaycodes = displaycodes == 2 ? 0 : 2;
else if(uni == 'l')
pushScreen(linepatterns::showMenu);
else if(uni == 'r') pushScreen(showPrePattern);
else if(doexiton(sym, uni)) popScreen();
};
}
void showList() {
v.clear();
if(painttype == 4) painttype = 0;
switch(painttype) {
case 0:
for(int i=0; i<motypes; i++) {
eMonster m = eMonster(i);
if(
m == moTongue || m == moPlayer || m == moFireball || m == moBullet ||
m == moFlailBullet || m == moShadow || m == moAirball ||
m == moWolfMoved || m == moGolemMoved ||
m == moTameBomberbirdMoved || m == moKnightMoved ||
m == moDeadBug || m == moLightningBolt || m == moDeadBird ||
m == moMouseMoved || m == moPrincessMoved || m == moPrincessArmedMoved) ;
else vpush(i, minf[i].name);
}
break;
case 1:
for(int i=0; i<ittypes; i++) vpush(i, iinf[i].name);
break;
case 2:
for(int i=0; i<landtypes; i++) vpush(i, linf[i].name);
break;
case 3:
for(int i=0; i<walltypes; i++) if(i != waChasmD) vpush(i, winf[i].name);
break;
}
// sort(v.begin(), v.end());
if(infix != "") mouseovers = infix;
int q = v.size();
int percolumn = vid.yres / (vid.fsize+5) - 4;
int columns = 1 + (q-1) / percolumn;
for(int i=0; i<q; i++) {
int x = 16 + (vid.xres * (i/percolumn)) / columns;
int y = (vid.fsize+5) * (i % percolumn) + vid.fsize*2;
int actkey = 1000 + i;
string vv = v[i].first;
if(i < 9) { vv += ": "; vv += ('1' + i); }
displayButton(x, y, vv, actkey, 0);
}
keyhandler = [] (int sym, int uni) {
if(uni >= '1' && uni <= '9') uni = 1000 + uni - '1';
if(sym == SDLK_RETURN || sym == SDLK_KP_ENTER || sym == '-' || sym == SDLK_KP_MINUS) uni = 1000;
for(int z=0; z<size(v); z++) if(1000 + z == uni) {
paintwhat = v[z].second;
paintwhat_str = v[z].first;
mousepressed = false;
popScreen();
return;
}
if(editInfix(uni)) ;
else if(doexiton(sym, uni)) popScreen();
};
}
void showMapEditor() {
cmode = sm::MAP;
gamescreen(0);
int fs = min(vid.fsize + 5, vid.yres/26);
getcstat = '-';
displayfr(8, 8 + fs, 2, vid.fsize, paintwhat_str, forecolor, 0);
displayfr(8, 8+fs*2, 2, vid.fsize, XLAT("use at your own risk!"), 0x800000, 0);
displayButton(8, 8+fs*4, XLAT("0-9 = radius (%1)", its(radius)), ('0' + (radius+1)%10), 0);
displayButton(8, 8+fs*5, XLAT("b = boundary"), 'b', 0);
displayButton(8, 8+fs*6, XLAT("m = monsters"), 'm', 0);
displayButton(8, 8+fs*7, XLAT("w = walls"), 'w', 0);
displayButton(8, 8+fs*8, XLAT("i = items"), 'i', 0);
displayButton(8, 8+fs*9, XLAT("l = lands"), 'l', 0);
displayfr(8, 8+fs*10, 2, vid.fsize, XLAT("c = copy"), 0xC0C0C0, 0);
displayButton(8, 8+fs*11, XLAT("u = undo"), 'u', 0);
if(painttype == 4)
displayButton(8, 8+fs*12, XLAT("f = flip %1", ONOFF(copyflip)), 'u', 0);
displayButton(8, 8+fs*13, XLAT("r = regular"), 'r', 0);
displayButton(8, 8+fs*14, XLAT("p = paint"), 'p', 0);
displayFunctionKeys();
keyhandler = handleKeyMap;
}
int spillinc() {
if(radius>=2) return 0;
if(anyshiftclick) return -1;
return 1;
}
void spillCopy(cell *c1, int d1, cell *c2, int d2, int r) {
saveUndo(c1);
int cf = copyflip ? -1 : 1;
if(c2->land == laNone) return;
c1->wall = c2->wall;
c1->item = c2->item;
c1->land = c2->land;
c1->monst = c2->monst;
c1->landparam = c2->landparam;
c1->wparam = c2->wparam;
// c1->tmp = c2->tmp;
if(c2->mondir == NODIR) c1->mondir = NODIR;
else c1->mondir = (cf * (c2->mondir - d2) + d1 + 42) % c1->type;
checkUndo();
if(r) for(int i=0; i<c1->type; i++) {
if(c1 != mouseover && (i == 0 || i == 1 || i == c1->type-1)) continue;
createMov(c1, i);
int i0 = (42+cf*i+d1) % c1->type;
int i1 = (i + d2) % c2->type;
spillCopy(c1->mov[i0], c1->spn(i0), c2->mov[i1], c2->spn(i1), r-1);
}
}
int subpatternEmerald(int i) {
if(euclid) return (symRotation && (i<3)) ? 0 : i;
if((sym01?1:0)+(sym02?1:0)+(sym03?1:0) >= 2) i &= ~3;
if(sym01 && (i&1)) i ^= 1;
if(sym02 && (i&2)) i ^= 2;
if(sym03 && (i&2)) i ^= 3;
return i;
}
int subpatternZebra(int i) {
if(euclid) return (symRotation && (i<3)) ? 0 : i;
i = subpatternEmerald(i);
if(symRotation) {
if(i >= 8 && i < 12) i -= 4;
if(i >= 12 && i < 16) i -= 8;
if(i >= 20 && i < 24) i -= 4;
if(i >= 24 && i < 28) i -= 8;
if(i >= 32 && i < 36) i -= 4;
if(i >= 36 && i < 40) i -= 8;
}
return i;
}
int subpatternPalace(int i) {
if(euclid) return i;
i = subpatternEmerald(i);
if(symRotation && i >= 3) i -= ((i/4-1) % 7) * 4;
return i;
}
int subpattern(cell *c) {
switch(whichPattern) {
case 'z':
return subpatternZebra(zebra40(c)); // 4 to 43
case 'f':
return subpatternEmerald(emeraldval(c)); // 44 to 99
case 'p': {
int i = fiftyval049(c);
i *= 4;
if(polara50(c)) i|=1;
if(polarb50(c)) i|=2;
return subpatternPalace(i);
}
case 'P':
return fiftyval(c);
case 'H':
return realpattern(c);
case 'F':
return realpattern(c);
}
return nopattern(c);
}
int realpattern(cell *c) {
switch(whichPattern) {
case 'z':
return zebra40(c); // 4 to 43
case 'f':
return emeraldval(c); // 44 to 99
case 'p': {
int i = fiftyval049(c);
i *= 4;
if(polara50(c)) i|=1;
if(polarb50(c)) i|=2;
return i;
}
case 'H':
return towerval(c);
case 'F': {
pair<int, bool> p = fieldpattern::fieldval(c);
return 10*p.first + (p.second?6:7);
}
}
return nopattern(c);
}
int realpatternsh(cell *c) {
if(whichPattern == 'F') return nopattern(c);
else return realpattern(c);
}
int cellShapeGroup() {
if(whichPattern == 'f') return 4;
if(whichPattern == 'p') return 5;
if(whichPattern == 'z') return 6;
if(whichPattern == 'H') return 7;
return 3;
}
int drawcellShapeGroup() {
if(drawcell == cwt.c) return 0;
if(drawcell->monst) return 1;
if(drawcell->item) return 2;
return cellShapeGroup();
}
int drawcellShapeID() {
if(drawcell == cwt.c) return vid.cs.charid;
if(drawcell->monst) return drawcell->monst;
if(drawcell->item) return drawcell->item;
return subpattern(drawcell);
}
int subpatternShape(int i) {
if(whichPattern == 'z') return subpatternZebra(i);
if(whichPattern == 'f') return subpatternEmerald(i);
if(whichPattern == 'p') return subpatternPalace(i);
return i;
}
bool editingShape(int group, int id) {
if(group != mapeditor::drawcellShapeGroup()) return false;
if(group < 3) return id == drawcellShapeID();
return subpatternShape(id) == subpattern(drawcell);
}
void spill(cell *c, int r, int cdir) {
if(painttype == 4 && radius) {
if(mouseover->type != copywhat->type) return;
if(cdir<0) cdir=0;
if(mouseover->type == 6 && ((cdir^copydir)&1)) {
cdir++; cdir %= 6;
}
spillCopy(mouseover, cdir, copywhat, copydir, radius);
}
saveUndo(c);
switch(painttype) {
case 0:
c->monst = eMonster(paintwhat);
c->hitpoints = 3;
c->stuntime = 0;
c->mondir = cdir;
if((isWorm(c) || isIvy(c) || isMutantIvy(c)) && c->mov[cdir] &&
!isWorm(c->mov[cdir]) && !isIvy(c->mov[cdir]))
c->mondir = NODIR;
break;
case 1:
c->item = eItem(paintwhat);
if(c->item == itBabyTortoise)
tortoise::babymap[c] = getBits(c) ^ tortoise::getRandomBits();
break;
case 2: {
eLand last = c->land;
c->land = eLand(paintwhat);