forked from Whales/Cataclysm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
overmap.cpp
2516 lines (2378 loc) · 74.9 KB
/
overmap.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
#ifdef __TILESET
#include "catacurse.h"
#else
#include <curses.h>
#endif
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <fstream>
#include <vector>
#include <sstream>
#include "overmap.h"
#include "rng.h"
#include "line.h"
#include "settlement.h"
#include "game.h"
#include "npc.h"
#include "keypress.h"
#define STREETCHANCE 2
#define NUM_FOREST 250
#define TOP_HIWAY_DIST 140
#define MIN_ANT_SIZE 8
#define MAX_ANT_SIZE 20
#define MIN_GOO_SIZE 1
#define MAX_GOO_SIZE 2
#define MIN_RIFT_SIZE 6
#define MAX_RIFT_SIZE 16
#define SETTLE_DICE 2
#define SETTLE_SIDES 2
#define HIVECHANCE 180 //Chance that any given forest will be a hive
#define SWAMPINESS 8 //Affects the size of a swamp
#define SWAMPCHANCE 850 // Chance that a swamp will spawn instead of forest
void settlement_building(settlement &set, int x, int y);
double dist(int x1, int y1, int x2, int y2)
{
return sqrt(double(pow(x1-x2, 2.0) + pow(y1-y2, 2.0)));
}
bool is_river(oter_id ter)
{
if (ter == ot_null || (ter >= ot_bridge_ns && ter <= ot_river_nw))
return true;
return false;
}
bool is_ground(oter_id ter)
{
if (ter <= ot_road_nesw_manhole)
return true;
return false;
}
bool is_wall_material(oter_id ter)
{
if (is_ground(ter) ||
(ter >= ot_house_north && ter <= ot_nuke_plant))
return true;
return false;
}
oter_id shop(int dir)
{
oter_id ret = ot_s_lot;
int type = rng(0, 15);
if (one_in(20))
type = 16;
switch (type) {
case 0: ret = ot_s_lot; break;
case 1: ret = ot_s_gas_north; break;
case 2: ret = ot_s_pharm_north; break;
case 3: ret = ot_s_grocery_north; break;
case 4: ret = ot_s_hardware_north; break;
case 5: ret = ot_s_sports_north; break;
case 6: ret = ot_s_liquor_north; break;
case 7: ret = ot_s_gun_north; break;
case 8: ret = ot_s_clothes_north; break;
case 9: ret = ot_s_library_north; break;
case 10: ret = ot_sub_station_north; break;
case 11: ret = ot_bank_north; break;
case 12: ret = ot_bar_north; break;
case 13: ret = ot_s_electronics_north; break;
case 14: ret = ot_pawn_north; break;
case 15: ret = ot_mil_surplus_north; break;
case 16: ret = ot_police_north; break;
}
if (ret == ot_s_lot)
return ret;
if (dir < 0) dir += 4;
switch (dir) {
case 0: break;
case 1: ret = oter_id(ret + 1); break;
case 2: ret = oter_id(ret + 2); break;
case 3: ret = oter_id(ret + 3); break;
default: debugmsg("Bad rotation of shop."); return ot_null;
}
return ret;
}
oter_id house(int dir)
{
bool base = one_in(30);
if (dir < 0) dir += 4;
switch (dir) {
case 0: return base ? ot_house_base_north : ot_house_north;
case 1: return base ? ot_house_base_east : ot_house_east;
case 2: return base ? ot_house_base_south : ot_house_south;
case 3: return base ? ot_house_base_west : ot_house_west;
default: debugmsg("Bad rotation of house."); return ot_null;
}
}
// *** BEGIN overmap FUNCTIONS ***
overmap::overmap()
{
// debugmsg("Warning - null overmap!");
nullret = ot_null;
posx = 999;
posy = 999;
posz = 999;
if (num_ter_types > 256)
debugmsg("More than 256 oterid! Saving won't work!");
}
overmap::overmap(game *g, int x, int y, int z)
{
if (num_ter_types > 256)
debugmsg("More than 256 oterid! Saving won't work!");
nullret = ot_null;
open(g, x, y, z);
}
overmap::~overmap()
{
}
oter_id& overmap::ter(int x, int y)
{
if (x < 0 || x >= OMAPX || y < 0 || y >= OMAPY) {
nullret = ot_null;
return nullret;
}
return t[x][y];
}
std::vector<mongroup*> overmap::monsters_at(int x, int y)
{
std::vector<mongroup*> ret;
if (x < 0 || x >= OMAPX || y < 0 || y >= OMAPY)
return ret;
for (int i = 0; i < zg.size(); i++) {
if (trig_dist(x, y, zg[i].posx, zg[i].posy) <= zg[i].radius)
ret.push_back(&(zg[i]));
}
return ret;
}
bool& overmap::seen(int x, int y)
{
if (x < 0 || x >= OMAPX || y < 0 || y >= OMAPY) {
nullbool = false;
return nullbool;
}
return s[x][y];
}
bool overmap::has_note(int x, int y)
{
for (int i = 0; i < notes.size(); i++) {
if (notes[i].x == x && notes[i].y == y)
return true;
}
return false;
}
std::string overmap::note(int x, int y)
{
for (int i = 0; i < notes.size(); i++) {
if (notes[i].x == x && notes[i].y == y)
return notes[i].text;
}
return "";
}
void overmap::add_note(int x, int y, std::string message)
{
for (int i = 0; i < notes.size(); i++) {
if (notes[i].x == x && notes[i].y == y) {
if (message == "")
notes.erase(notes.begin() + i);
else
notes[i].text = message;
return;
}
}
if (message.length() > 0)
notes.push_back(om_note(x, y, notes.size(), message));
}
point overmap::find_note(point origin, std::string text)
{
int closest = 9999;
point ret(-1, -1);
for (int i = 0; i < notes.size(); i++) {
if (notes[i].text.find(text) != std::string::npos &&
rl_dist(origin.x, origin.y, notes[i].x, notes[i].y) < closest) {
closest = rl_dist(origin.x, origin.y, notes[i].x, notes[i].y);
ret = point(notes[i].x, notes[i].y);
}
}
return ret;
}
void overmap::delete_note(int x, int y)
{
std::vector<om_note>::iterator it;
for (it = notes.begin(); it < notes.end(); it++) {
if (it->x == x && it->y == y){
notes.erase(it);
}
}
}
point overmap::display_notes()
{
std::string title = "Notes:";
WINDOW* w_notes = newwin(25, 80, 0, 0);
const int maxitems = 20; // Number of items to show at one time.
char ch = '.';
int start = 0, cur_it;
mvwprintz(w_notes, 0, 0, c_ltgray, title.c_str());
do{
if (ch == '<' && start > 0) {
for (int i = 1; i < 25; i++)
mvwprintz(w_notes, i, 0, c_black, " ");
start -= maxitems;
if (start < 0)
start = 0;
mvwprintw(w_notes, maxitems + 2, 0, " ");
}
if (ch == '>' && cur_it < notes.size()) {
start = cur_it;
mvwprintw(w_notes, maxitems + 2, 12, " ");
for (int i = 1; i < 25; i++)
mvwprintz(w_notes, i, 0, c_black, " ");
}
int cur_line = 2;
int last_line = -1;
char cur_let = 'a';
for (cur_it = start; cur_it < start + maxitems && cur_line < 23; cur_it++) {
if (cur_it < notes.size()) {
mvwputch (w_notes, cur_line, 0, c_white, cur_let++);
mvwprintz(w_notes, cur_line, 2, c_ltgray, "- %s", notes[cur_it].text.c_str());
} else{
last_line = cur_line - 2;
break;
}
cur_line++;
}
if(last_line == -1)
last_line = 23;
if (start > 0)
mvwprintw(w_notes, maxitems + 4, 0, "< Go Back");
if (cur_it < notes.size())
mvwprintw(w_notes, maxitems + 4, 12, "> More notes");
if(ch >= 'a' && ch <= 't'){
int chosen_line = (int)(ch % (int)'a');
if(chosen_line < last_line)
return point(notes[start + chosen_line].x, notes[start + chosen_line].y);
}
mvwprintz(w_notes, 0, 40, c_white, "Press letter to center on note");
mvwprintz(w_notes, 24, 40, c_white, "Spacebar - Return to map ");
wrefresh(w_notes);
ch = getch();
} while(ch != ' ');
delwin(w_notes);
return point(-1,-1);
}
void overmap::generate(game *g, overmap* north, overmap* east, overmap* south,
overmap* west)
{
erase();
clear();
move(0, 0);
for (int i = 0; i < OMAPY; i++) {
for (int j = 0; j < OMAPX; j++) {
ter(i, j) = ot_field;
seen(i, j) = false;
}
}
std::vector<city> road_points; // cities and roads_out together
std::vector<point> river_start;// West/North endpoints of rivers
std::vector<point> river_end; // East/South endpoints of rivers
// Determine points where rivers & roads should connect w/ adjacent maps
if (north != NULL) {
for (int i = 2; i < OMAPX - 2; i++) {
if (is_river(north->ter(i,OMAPY-1)))
ter(i, 0) = ot_river_center;
if (north->ter(i, OMAPY - 1) == ot_river_center &&
north->ter(i - 1, OMAPY - 1) == ot_river_center &&
north->ter(i + 1, OMAPY - 1) == ot_river_center) {
if (river_start.size() == 0 ||
river_start[river_start.size() - 1].x < i - 6)
river_start.push_back(point(i, 0));
}
}
for (int i = 0; i < north->roads_out.size(); i++) {
if (north->roads_out[i].y == OMAPY - 1)
roads_out.push_back(city(north->roads_out[i].x, 0, 0));
}
}
int rivers_from_north = river_start.size();
if (west != NULL) {
for (int i = 2; i < OMAPY - 2; i++) {
if (is_river(west->ter(OMAPX - 1, i)))
ter(0, i) = ot_river_center;
if (west->ter(OMAPX - 1, i) == ot_river_center &&
west->ter(OMAPX - 1, i - 1) == ot_river_center &&
west->ter(OMAPX - 1, i + 1) == ot_river_center) {
if (river_start.size() == rivers_from_north ||
river_start[river_start.size() - 1].y < i - 6)
river_start.push_back(point(0, i));
}
}
for (int i = 0; i < west->roads_out.size(); i++) {
if (west->roads_out[i].x == OMAPX - 1)
roads_out.push_back(city(0, west->roads_out[i].y, 0));
}
}
if (south != NULL) {
for (int i = 2; i < OMAPX - 2; i++) {
if (is_river(south->ter(i, 0)))
ter(i, OMAPY - 1) = ot_river_center;
if (south->ter(i, 0) == ot_river_center &&
south->ter(i - 1, 0) == ot_river_center &&
south->ter(i + 1, 0) == ot_river_center) {
if (river_end.size() == 0 ||
river_end[river_end.size() - 1].x < i - 6)
river_end.push_back(point(i, OMAPY - 1));
}
if (south->ter(i, 0) == ot_road_nesw)
roads_out.push_back(city(i, OMAPY - 1, 0));
}
for (int i = 0; i < south->roads_out.size(); i++) {
if (south->roads_out[i].y == 0)
roads_out.push_back(city(south->roads_out[i].x, OMAPY - 1, 0));
}
}
int rivers_to_south = river_end.size();
if (east != NULL) {
for (int i = 2; i < OMAPY - 2; i++) {
if (is_river(east->ter(0, i)))
ter(OMAPX - 1, i) = ot_river_center;
if (east->ter(0, i) == ot_river_center &&
east->ter(0, i - 1) == ot_river_center &&
east->ter(0, i + 1) == ot_river_center) {
if (river_end.size() == rivers_to_south ||
river_end[river_end.size() - 1].y < i - 6)
river_end.push_back(point(OMAPX - 1, i));
}
if (east->ter(0, i) == ot_road_nesw)
roads_out.push_back(city(OMAPX - 1, i, 0));
}
for (int i = 0; i < east->roads_out.size(); i++) {
if (east->roads_out[i].x == 0)
roads_out.push_back(city(OMAPX - 1, east->roads_out[i].y, 0));
}
}
// Even up the start and end points of rivers. (difference of 1 is acceptable)
// Also ensure there's at least one of each.
std::vector<point> new_rivers;
if (north == NULL || west == NULL) {
while (river_start.empty() || river_start.size() + 1 < river_end.size()) {
new_rivers.clear();
if (north == NULL)
new_rivers.push_back( point(rng(10, OMAPX - 11), 0) );
if (west == NULL)
new_rivers.push_back( point(0, rng(10, OMAPY - 11)) );
river_start.push_back( new_rivers[rng(0, new_rivers.size() - 1)] );
}
}
if (south == NULL || east == NULL) {
while (river_end.empty() || river_end.size() + 1 < river_start.size()) {
new_rivers.clear();
if (south == NULL)
new_rivers.push_back( point(rng(10, OMAPX - 11), OMAPY - 1) );
if (east == NULL)
new_rivers.push_back( point(OMAPX - 1, rng(10, OMAPY - 11)) );
river_end.push_back( new_rivers[rng(0, new_rivers.size() - 1)] );
}
}
// Now actually place those rivers.
if (river_start.size() > river_end.size() && river_end.size() > 0) {
std::vector<point> river_end_copy = river_end;
int index;
while (!river_start.empty()) {
index = rng(0, river_start.size() - 1);
if (!river_end.empty()) {
place_river(river_start[index], river_end[0]);
river_end.erase(river_end.begin());
} else
place_river(river_start[index],
river_end_copy[rng(0, river_end_copy.size() - 1)]);
river_start.erase(river_start.begin() + index);
}
} else if (river_end.size() > river_start.size() && river_start.size() > 0) {
std::vector<point> river_start_copy = river_start;
int index;
while (!river_end.empty()) {
index = rng(0, river_end.size() - 1);
if (!river_start.empty()) {
place_river(river_start[0], river_end[index]);
river_start.erase(river_start.begin());
} else
place_river(river_start_copy[rng(0, river_start_copy.size() - 1)],
river_end[index]);
river_end.erase(river_end.begin() + index);
}
} else if (river_end.size() > 0) {
if (river_start.size() != river_end.size())
river_start.push_back( point(rng(OMAPX * .25, OMAPX * .75),
rng(OMAPY * .25, OMAPY * .75)));
for (int i = 0; i < river_start.size(); i++)
place_river(river_start[i], river_end[i]);
}
// Cities, forests, and settlements come next.
// These're agnostic of adjacent maps, so it's very simple.
int mincit = 0;
if (north == NULL && east == NULL && west == NULL && south == NULL)
mincit = 1; // The first map MUST have a city, for the player to start in!
place_cities(cities, mincit);
place_forest();
// Ideally we should have at least two exit points for roads, on different sides
if (roads_out.size() < 2) {
std::vector<city> viable_roads;
int tmp;
// Populate viable_roads with one point for each neighborless side.
// Make sure these points don't conflict with rivers.
// TODO: In theory this is a potential infinte loop...
if (north == NULL) {
do
tmp = rng(10, OMAPX - 11);
while (is_river(ter(tmp, 0)) || is_river(ter(tmp - 1, 0)) ||
is_river(ter(tmp + 1, 0)) );
viable_roads.push_back(city(tmp, 0, 0));
}
if (east == NULL) {
do
tmp = rng(10, OMAPY - 11);
while (is_river(ter(OMAPX - 1, tmp)) || is_river(ter(OMAPX - 1, tmp - 1))||
is_river(ter(OMAPX - 1, tmp + 1)));
viable_roads.push_back(city(OMAPX - 1, tmp, 0));
}
if (south == NULL) {
do
tmp = rng(10, OMAPX - 11);
while (is_river(ter(tmp, OMAPY - 1)) || is_river(ter(tmp - 1, OMAPY - 1))||
is_river(ter(tmp + 1, OMAPY - 1)));
viable_roads.push_back(city(tmp, OMAPY - 1, 0));
}
if (west == NULL) {
do
tmp = rng(10, OMAPY - 11);
while (is_river(ter(0, tmp)) || is_river(ter(0, tmp - 1)) ||
is_river(ter(0, tmp + 1)));
viable_roads.push_back(city(0, tmp, 0));
}
while (roads_out.size() < 2 && !viable_roads.empty()) {
tmp = rng(0, viable_roads.size() - 1);
roads_out.push_back(viable_roads[tmp]);
viable_roads.erase(viable_roads.begin() + tmp);
}
}
// Compile our master list of roads; it's less messy if roads_out is first
for (int i = 0; i < roads_out.size(); i++)
road_points.push_back(roads_out[i]);
for (int i = 0; i < cities.size(); i++)
road_points.push_back(cities[i]);
// And finally connect them via "highways"
place_hiways(road_points, ot_road_null);
// Place specials
place_specials();
// Make the roads out road points;
for (int i = 0; i < roads_out.size(); i++)
ter(roads_out[i].x, roads_out[i].y) = ot_road_nesw;
// Clean up our roads and rivers
polish();
// Place the monsters, now that the terrain is laid out
place_mongroups();
place_radios();
}
void overmap::generate_sub(overmap* above)
{
std::vector<city> subway_points;
std::vector<city> sewer_points;
std::vector<city> ant_points;
std::vector<city> goo_points;
std::vector<city> lab_points;
std::vector<point> shaft_points;
std::vector<city> mine_points;
std::vector<point> bunker_points;
std::vector<point> shelter_points;
std::vector<point> triffid_points;
std::vector<point> temple_points;
for (int i = 0; i < OMAPX; i++) {
for (int j = 0; j < OMAPY; j++) {
seen(i, j) = false; // Start by setting all squares to unseen
ter(i, j) = ot_rock; // Start by setting everything to solid rock
}
}
for (int i = 0; i < OMAPX; i++) {
for (int j = 0; j < OMAPY; j++) {
if (above->ter(i, j) >= ot_sub_station_north &&
above->ter(i, j) <= ot_sub_station_west) {
ter(i, j) = ot_subway_nesw;
subway_points.push_back(city(i, j, 0));
} else if (above->ter(i, j) == ot_road_nesw_manhole) {
ter(i, j) = ot_sewer_nesw;
sewer_points.push_back(city(i, j, 0));
} else if (above->ter(i, j) == ot_sewage_treatment) {
for (int x = i-1; x <= i+1; x++) {
for (int y = j-1; y <= j+1; y++) {
ter(x, y) = ot_sewage_treatment_under;
}
}
ter(i, j) = ot_sewage_treatment_hub;
sewer_points.push_back(city(i, j, 0));
} else if (above->ter(i, j) == ot_spider_pit)
ter(i, j) = ot_spider_pit_under;
else if (above->ter(i, j) == ot_cave && posz == -1) {
if (one_in(3))
ter(i, j) = ot_cave_rat;
else
ter(i, j) = ot_cave;
} else if (above->ter(i, j) == ot_cave_rat && posz == -2)
ter(i, j) = ot_cave_rat;
else if (above->ter(i, j) == ot_anthill) {
int size = rng(MIN_ANT_SIZE, MAX_ANT_SIZE);
ant_points.push_back(city(i, j, size));
zg.push_back(mongroup(mcat_ant, i * 2, j * 2, size * 1.5, rng(6000, 8000)));
} else if (above->ter(i, j) == ot_slimepit_down) {
int size = rng(MIN_GOO_SIZE, MAX_GOO_SIZE);
goo_points.push_back(city(i, j, size));
} else if (above->ter(i, j) == ot_forest_water)
ter(i, j) = ot_cavern;
else if (above->ter(i, j) == ot_triffid_grove ||
above->ter(i, j) == ot_triffid_roots)
triffid_points.push_back( point(i, j) );
else if (above->ter(i, j) == ot_temple_stairs)
temple_points.push_back( point(i, j) );
else if (above->ter(i, j) == ot_lab_core ||
(posz == -1 && above->ter(i, j) == ot_lab_stairs))
lab_points.push_back(city(i, j, rng(1, 5 + posz)));
else if (above->ter(i, j) == ot_lab_stairs)
ter(i, j) = ot_lab;
else if (above->ter(i, j) == ot_bunker && posz == -1)
bunker_points.push_back( point(i, j) );
else if (above->ter(i, j) == ot_shelter)
shelter_points.push_back( point(i, j) );
else if (above->ter(i, j) == ot_mine_entrance)
shaft_points.push_back( point(i, j) );
else if (above->ter(i, j) == ot_mine_shaft ||
above->ter(i, j) == ot_mine_down ) {
ter(i, j) = ot_mine;
mine_points.push_back(city(i, j, rng(6 + posz, 10 + posz)));
} else if (above->ter(i, j) == ot_mine_finale) {
for (int x = i - 1; x <= i + 1; x++) {
for (int y = j - 1; y <= j + 1; y++)
ter(x, y) = ot_spiral;
}
ter(i, j) = ot_spiral_hub;
zg.push_back(mongroup(mcat_spiral, i * 2, j * 2, 2, 200));
} else if (above->ter(i, j) == ot_silo) {
if (rng(2, 7) < abs(posz) || rng(2, 7) < abs(posz))
ter(i, j) = ot_silo_finale;
else
ter(i, j) = ot_silo;
}
}
}
for (int i = 0; i < goo_points.size(); i++)
build_slimepit(goo_points[i].x, goo_points[i].y, goo_points[i].s);
place_hiways(sewer_points, ot_sewer_nesw);
polish(ot_sewer_ns, ot_sewer_nesw);
place_hiways(subway_points, ot_subway_nesw);
for (int i = 0; i < subway_points.size(); i++)
ter(subway_points[i].x, subway_points[i].y) = ot_subway_station;
for (int i = 0; i < lab_points.size(); i++)
build_lab(lab_points[i].x, lab_points[i].y, lab_points[i].s);
for (int i = 0; i < ant_points.size(); i++)
build_anthill(ant_points[i].x, ant_points[i].y, ant_points[i].s);
polish(ot_subway_ns, ot_subway_nesw);
polish(ot_ants_ns, ot_ants_nesw);
for (int i = 0; i < above->cities.size(); i++) {
if (one_in(3))
zg.push_back(
mongroup(mcat_chud, above->cities[i].x * 2, above->cities[i].y * 2,
above->cities[i].s, above->cities[i].s * 20));
if (!one_in(8))
zg.push_back(
mongroup(mcat_sewer, above->cities[i].x * 2, above->cities[i].y * 2,
above->cities[i].s * 3.5, above->cities[i].s * 70));
}
place_rifts();
for (int i = 0; i < mine_points.size(); i++)
build_mine(mine_points[i].x, mine_points[i].y, mine_points[i].s);
// Basements done last so sewers, etc. don't overwrite them
for (int i = 0; i < OMAPX; i++) {
for (int j = 0; j < OMAPY; j++) {
if (above->ter(i, j) >= ot_house_base_north &&
above->ter(i, j) <= ot_house_base_west)
ter(i, j) = ot_basement;
}
}
for (int i = 0; i < shaft_points.size(); i++)
ter(shaft_points[i].x, shaft_points[i].y) = ot_mine_shaft;
for (int i = 0; i < bunker_points.size(); i++)
ter(bunker_points[i].x, bunker_points[i].y) = ot_bunker;
for (int i = 0; i < shelter_points.size(); i++)
ter(shelter_points[i].x, shelter_points[i].y) = ot_shelter_under;
for (int i = 0; i < triffid_points.size(); i++) {
if (posz == -1)
ter( triffid_points[i].x, triffid_points[i].y ) = ot_triffid_roots;
else
ter( triffid_points[i].x, triffid_points[i].y ) = ot_triffid_finale;
}
for (int i = 0; i < temple_points.size(); i++) {
if (posz == -5)
ter( temple_points[i].x, temple_points[i].y ) = ot_temple_finale;
else
ter( temple_points[i].x, temple_points[i].y ) = ot_temple_stairs;
}
}
void overmap::make_tutorial()
{
if (posz == 9) {
for (int i = 0; i < OMAPX; i++) {
for (int j = 0; j < OMAPY; j++)
ter(i, j) = ot_rock;
}
}
ter(50, 50) = ot_tutorial;
zg.clear();
}
point overmap::find_closest(point origin, oter_id type, int type_range,
int &dist, bool must_be_seen)
{
int max = (dist == 0 ? OMAPX / 2 : dist);
for (dist = 0; dist <= max; dist++) {
for (int x = origin.x - dist; x <= origin.x + dist; x++) {
for (int y = origin.y - dist; y <= origin.y + dist; y++) {
if (ter(x, y) >= type && ter(x, y) < type + type_range &&
(!must_be_seen || seen(x, y)))
return point(x, y);
}
}
}
return point(-1, -1);
}
std::vector<point> overmap::find_all(point origin, oter_id type, int type_range,
int &dist, bool must_be_seen)
{
std::vector<point> res;
int max = (dist == 0 ? OMAPX / 2 : dist);
for (dist = 0; dist <= max; dist++) {
for (int x = origin.x - dist; x <= origin.x + dist; x++) {
for (int y = origin.y - dist; y <= origin.y + dist; y++) {
if (ter(x, y) >= type && ter(x, y) < type + type_range &&
(!must_be_seen || seen(x, y)))
res.push_back(point(x, y));
}
}
}
return res;
}
std::vector<point> overmap::find_terrain(std::string term, int cursx, int cursy)
{
std::vector<point> found;
for (int x = 0; x < OMAPX; x++) {
for (int y = 0; y < OMAPY; y++) {
if (seen(x, y) && oterlist[ter(x, y)].name.find(term) != std::string::npos)
found.push_back( point(x, y) );
}
}
return found;
}
int overmap::closest_city(point p)
{
int distance = 999, ret = -1;
for (int i = 0; i < cities.size(); i++) {
int dist = rl_dist(p.x, p.y, cities[i].x, cities[i].y);
if (dist < distance || (dist == distance && cities[i].s < cities[ret].s)) {
ret = i;
distance = dist;
}
}
return ret;
}
point overmap::random_house_in_city(int city_id)
{
if (city_id < 0 || city_id >= cities.size()) {
debugmsg("overmap::random_house_in_city(%d) (max %d)", city_id,
cities.size() - 1);
return point(-1, -1);
}
std::vector<point> valid;
int startx = cities[city_id].x - cities[city_id].s,
endx = cities[city_id].x + cities[city_id].s,
starty = cities[city_id].y - cities[city_id].s,
endy = cities[city_id].y + cities[city_id].s;
for (int x = startx; x <= endx; x++) {
for (int y = starty; y <= endy; y++) {
if (ter(x, y) >= ot_house_north && ter(x, y) <= ot_house_west)
valid.push_back( point(x, y) );
}
}
if (valid.empty())
return point(-1, -1);
return valid[ rng(0, valid.size() - 1) ];
}
int overmap::dist_from_city(point p)
{
int distance = 999;
for (int i = 0; i < cities.size(); i++) {
int dist = rl_dist(p.x, p.y, cities[i].x, cities[i].y);
dist -= cities[i].s;
if (dist < distance)
distance = dist;
}
return distance;
}
void overmap::draw(WINDOW *w, game *g, int &cursx, int &cursy,
int &origx, int &origy, char &ch, bool blink)
{
werase(w); // make sure there's no clutter
bool legend = true, note_here = false, npc_here = false;
std::string note_text, npc_name;
int omx, omy;
overmap hori, vert, diag; // Adjacent maps
point target(-1, -1);
if (g->u.active_mission >= 0 &&
g->u.active_mission < g->u.active_missions.size())
target = g->find_mission(g->u.active_missions[g->u.active_mission])->target;
bool see;
oter_id cur_ter;
nc_color ter_color;
long ter_sym;
/* First, determine if we're close enough to the edge to need to load an
* adjacent overmap, and load it/them. */
if (cursx < 25) {
hori = overmap(g, posx - 1, posy, posz);
if (cursy < 12)
diag = overmap(g, posx - 1, posy - 1, posz);
if (cursy > OMAPY - 14)
diag = overmap(g, posx - 1, posy + 1, posz);
}
if (cursx > OMAPX - 26) {
hori = overmap(g, posx + 1, posy, posz);
if (cursy < 12)
diag = overmap(g, posx + 1, posy - 1, posz);
if (cursy > OMAPY - 14)
diag = overmap(g, posx + 1, posy + 1, posz);
}
if (cursy < 12)
vert = overmap(g, posx, posy - 1, posz);
if (cursy > OMAPY - 14)
vert = overmap(g, posx, posy + 1, posz);
// Now actually draw the map
for (int i = -25; i < 25; i++) {
for (int j = -12; j <= (ch == 'j' ? 13 : 12); j++) {
omx = cursx + i;
omy = cursy + j;
see = false;
npc_here = false;
if (omx >= 0 && omx < OMAPX && omy >= 0 && omy < OMAPY) { // It's in-bounds
cur_ter = ter(omx, omy);
see = seen(omx, omy);
if (note_here = has_note(omx, omy))
note_text = note(omx, omy);
for (int n = 0; n < npcs.size(); n++) {
if ((npcs[n].mapx + 1) / 2 == omx && (npcs[n].mapy + 1) / 2 == omy) {
npc_here = true;
npc_name = npcs[n].name;
n = npcs.size();
} else {
npc_here = false;
npc_name = "";
}
}
// <Out of bounds placement>
} else if (omx < 0) {
omx += OMAPX;
if (omy < 0 || omy >= OMAPY) {
omy += (omy < 0 ? OMAPY : 0 - OMAPY);
cur_ter = diag.ter(omx, omy);
see = diag.seen(omx, omy);
if (note_here = diag.has_note(omx, omy))
note_text = diag.note(omx, omy);
} else {
cur_ter = hori.ter(omx, omy);
see = hori.seen(omx, omy);
if (note_here = hori.has_note(omx, omy))
note_text = hori.note(omx, omy);
}
} else if (omx >= OMAPX) {
omx -= OMAPX;
if (omy < 0 || omy >= OMAPY) {
omy += (omy < 0 ? OMAPY : 0 - OMAPY);
cur_ter = diag.ter(omx, omy);
see = diag.seen(omx, omy);
if (note_here = diag.has_note(omx, omy))
note_text = diag.note(omx, omy);
} else {
cur_ter = hori.ter(omx, omy);
see = hori.seen(omx, omy);
if (note_here = hori.has_note(omx, omy))
note_text = hori.note(omx, omy);
}
} else if (omy < 0) {
omy += OMAPY;
cur_ter = vert.ter(omx, omy);
see = vert.seen(omx, omy);
if (note_here = vert.has_note(omx, omy))
note_text = vert.note(omx, omy);
} else if (omy >= OMAPY) {
omy -= OMAPY;
cur_ter = vert.ter(omx, omy);
see = vert.seen(omx, omy);
if (note_here = vert.has_note(omx, omy))
note_text = vert.note(omx, omy);
} else
debugmsg("No data loaded! omx: %d omy: %d", omx, omy);
// </Out of bounds replacement>
if (see) {
if (note_here && blink) {
ter_color = c_yellow;
ter_sym = 'N';
} else if (omx == origx && omy == origy && blink) {
ter_color = g->u.color();
ter_sym = '@';
} else if (npc_here && blink) {
ter_color = c_pink;
ter_sym = '@';
} else if (omx == target.x && omy == target.y && blink) {
ter_color = c_red;
ter_sym = '*';
} else {
if (cur_ter >= num_ter_types || cur_ter < 0)
debugmsg("Bad ter %d (%d, %d)", cur_ter, omx, omy);
ter_color = oterlist[cur_ter].color;
ter_sym = oterlist[cur_ter].sym;
}
} else { // We haven't explored this tile yet
ter_color = c_dkgray;
ter_sym = '#';
}
// if we can draw the tile graphically just go to the next iteration
int tilepos;
if(see) tilepos = active_tileset->name_to_position(oterlist[cur_ter].name.c_str());
else tilepos = active_tileset->name_to_position("fog");
if(note_here || (omx == origx && omy == origy) || npc_here || (omx == target.x && omy == target.y))
tilepos = 0; // some stuff shouldn't be drawn graphically just yet
if(!tilepos || !draw_object(w, 25+i, 12+j, tilepos) ) {
if (j == 0 && i == 0)
mvwputch_hi (w, 12, 25, ter_color, ter_sym);
else
mvwputch (w, 12 + j, 25 + i, ter_color, ter_sym);
}
else {
// see if we can draw stuff ON TOP of the tile
if(j == 0 && i == 0) draw_object(w, 25, 12, active_tileset->name_to_position("cursor"), false, true);
}
}
}
if (target.x != -1 && target.y != -1 && blink &&
(target.x < cursx - 25 || target.x > cursx + 25 ||
target.y < cursy - 12 || target.y > cursy + 12 )) {
switch (direction_from(cursx, cursy, target.x, target.y)) {
case NORTH: mvwputch(w, 0, 25, c_red, '^'); break;
case NORTHEAST: mvwputch(w, 0, 49, c_red, LINE_OOXX); break;
case EAST: mvwputch(w, 12, 49, c_red, '>'); break;
case SOUTHEAST: mvwputch(w, 24, 49, c_red, LINE_XOOX); break;
case SOUTH: mvwputch(w, 24, 25, c_red, 'v'); break;
case SOUTHWEST: mvwputch(w, 24, 0, c_red, LINE_XXOO); break;
case WEST: mvwputch(w, 12, 0, c_red, '<'); break;
case NORTHWEST: mvwputch(w, 0, 0, c_red, LINE_OXXO); break;
}
}
if (has_note(cursx, cursy)) {
note_text = note(cursx, cursy);
for (int i = 0; i < note_text.length(); i++)
mvwputch(w, 1, i, c_white, LINE_OXOX);
mvwputch(w, 1, note_text.length(), c_white, LINE_XOOX);
mvwputch(w, 0, note_text.length(), c_white, LINE_XOXO);
mvwprintz(w, 0, 0, c_yellow, note_text.c_str());
} else if (npc_here) {
for (int i = 0; i < npc_name.length(); i++)
mvwputch(w, 1, i, c_white, LINE_OXOX);
mvwputch(w, 1, npc_name.length(), c_white, LINE_XOOX);
mvwputch(w, 0, npc_name.length(), c_white, LINE_XOXO);
mvwprintz(w, 0, 0, c_yellow, npc_name.c_str());
}
if (legend) {
cur_ter = ter(cursx, cursy);
// Draw the vertical line
for (int j = 0; j < 25; j++)
mvwputch(w, j, 51, c_white, LINE_XOXO);
// Clear the legend
for (int i = 51; i < 80; i++) {
for (int j = 0; j < 25; j++)
mvwputch(w, j, i, c_black, 'x');
}
if (seen(cursx, cursy)) {
mvwputch(w, 1, 51, oterlist[cur_ter].color, oterlist[cur_ter].sym);
mvwprintz(w, 1, 53, oterlist[cur_ter].color, "%s",
oterlist[cur_ter].name.c_str());
} else
mvwprintz(w, 1, 51, c_dkgray, "# Unexplored");
if (target.x != -1 && target.y != -1) {
int distance = rl_dist(origx, origy, target.x, target.y);
mvwprintz(w, 3, 51, c_white, "Distance to target: %d", distance);
}
mvwprintz(w, 17, 51, c_magenta, "Use movement keys to pan. ");
mvwprintz(w, 18, 51, c_magenta, "0 - Center map on character");
mvwprintz(w, 19, 51, c_magenta, "t - Toggle legend ");
mvwprintz(w, 20, 51, c_magenta, "/ - Search ");
mvwprintz(w, 21, 51, c_magenta, "N - Add a note ");
mvwprintz(w, 22, 51, c_magenta, "D - Delete a note ");
mvwprintz(w, 23, 51, c_magenta, "L - List notes ");
mvwprintz(w, 24, 51, c_magenta, "Esc or q - Return to game ");
}
// Done with all drawing!
wrefresh(w);
}
point overmap::choose_point(game *g)
{
WINDOW* w_map = newwin(25, 80, 0, 0);
WINDOW* w_search = newwin(13, 27, 3, 51);
timeout(BLINK_SPEED); // Enable blinking!
bool blink = true;
int cursx = (g->levx + int(MAPSIZE / 2)) / 2,