-
Notifications
You must be signed in to change notification settings - Fork 3
/
mappane.cpp
4023 lines (3374 loc) · 124 KB
/
mappane.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This source file is part of the Atlantis Little Helper program.
* Copyright (C) 2001 Maxim Shariy.
*
* Atlantis Little Helper 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 2 of the License, or
* (at your option) any later version.
*
* Atlantis Little Helper 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 Atlantis Little Helper; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "stdhdr.h"
#include "wx/listctrl.h"
#include "wx/spinctrl.h"
#include "wx/dialog.h"
#include "wx/textdlg.h"
#if wxCHECK_VERSION(2, 6, 0)
#include "wx/numdlg.h"
#endif
#include "cstr.h"
#include "collection.h"
#include "cfgfile.h"
#include "files.h"
#include "atlaparser.h"
#include "consts.h"
#include "consts_ah.h"
#include "hash.h"
#include "ahapp.h"
#include "ahframe.h"
#include "data.h"
#include "mappane.h"
#include "editpane.h"
#include "listpane.h"
#include "unitpane.h"
#include "atlaparser.h"
#include "flagsdlg.h"
#include "hexfilterdlg.h"
#include <math.h>
const double cos30 = sqrt(3.0)/2;
const double tan30 = 1/sqrt(3.0);
static wxPoint glb_PopupPoint;
CLand * glb_pPopupLand = NULL;
#define MAX_DP_BORDER 1
#define COORD_PANE_WIDTH 24
#define COORD_PANE_HEIGHT 24
enum { EDGE_SHAPE_BORDER, EDGE_SHAPE_ROAD, EDGE_SHAPE_BRIDGE, EDGE_SHAPE_ANCHOR, EDGE_SHAPE_ROCKS,
EDGE_SHAPE_IGNORE };
// Detail levels govern what is shown at what scale
enum { MIN_DETAIL, UNIT_DETAIL, BATTLE_DETAIL,
TOWN_DETAIL, ROAD_DETAIL, NAME_DETAIL,
FLAG_DETAIL, WEATHER_DETAIL, EDGE_DETAIL,
MILITARY_DETAIL, SPECIAL_DETAIL, ECONOMIC_DETAIL,
//BUILDING_DETAIL,
MAX_DETAIL };
const int SizeForDetail[] =
{ 0, // MIN_DETAIL
8, // UNIT_DETAIL
8, // BATTLE_DETAIL
9, // TOWN_DETAIL
10, // ROAD_DETAIL
11, // NAME_DETAIL
12, // FLAG_DETAIL
14, // WEATHER_DETAIL
16, // EDGE_DETAIL
20, // MILITARY_DETAIL
21, // SPECIAL_DETAIL
22, // ECONOMIC_DETAIL
// 28, // BUILDING_DETAIL
56};// MAX_DETAIL
#define ICON_SIZE 8
#define ICON_SIZE_SMALL 6
BEGIN_EVENT_TABLE(CMapPane, wxWindow)
EVT_PAINT ( CMapPane::OnPaint )
EVT_ERASE_BACKGROUND ( CMapPane::OnEraseBackground )
EVT_LEFT_DOWN ( CMapPane::OnMouseEvent )
EVT_LEFT_UP ( CMapPane::OnMouseEvent )
EVT_MOTION ( CMapPane::OnMouseEvent )
EVT_LEAVE_WINDOW ( CMapPane::OnMouseEvent )
EVT_ENTER_WINDOW ( CMapPane::OnMouseEvent )
EVT_RIGHT_DOWN ( CMapPane::OnMouseEvent )
EVT_LEFT_DCLICK ( CMapPane::OnMouseEvent )
EVT_MENU (menu_Popup_Flag , CMapPane::OnPopupMenuFlag )
EVT_MENU (menu_Popup_Center , CMapPane::OnPopupMenuCenter )
EVT_MENU (menu_Popup_Battles , CMapPane::OnPopupMenuBattles )
EVT_MENU (menu_Popup_WhoMovesHere , CMapPane::OnPopupWhoMovesHere )
EVT_MENU (menu_Popup_Financial , CMapPane::OnPopupFinancial )
EVT_MENU (menu_Popup_New_Hex , CMapPane::OnPopupNewHex )
EVT_MENU (menu_Popup_Del_Hex , CMapPane::OnPopupDeleteHex )
EVT_MENU (menu_Popup_DistanceRing , CMapPane::OnPopupDistanceRing )
END_EVENT_TABLE()
//--------------------------------------------------------------------------
CMapPane::CMapPane(wxWindow * parent, wxWindowID id, int layout)
:wxWindow(parent, id, wxDefaultPosition, wxDefaultSize,
(AH_LAYOUT_3_WIN==layout)?wxSUNKEN_BORDER:0 )
{
int i;
m_pPen = new wxPen;
m_pPenWall = new wxPen;
m_pPenSel = new wxPen;
m_pPenTropic = new wxPen;
m_pPenRing = new wxPen;
m_pPenRoad = new wxPen;
m_pPenRoadBad = new wxPen;
m_pPenBlack = new wxPen(*wxBLACK, 1, wxSOLID);
m_pPenRed2 = new wxPen(*wxRED , 2, wxSOLID);
m_pPenRed = new wxPen(*wxRED , 1, wxSOLID);
wxColor * grey = new wxColor(98,109,112);
m_pPenGrey = new wxPen(*grey , 1, wxSOLID);
m_pPenCoastline = new wxPen;
for (i=0; i<LAND_FLAG_COUNT; i++)
m_pPenFlag[i] = new wxPen;
m_pBrushBlack = new wxBrush(*wxBLACK, wxSOLID);
m_pBrushWhite = new wxBrush(*wxWHITE, wxSOLID);
m_pBrushRed = new wxBrush(*wxRED , wxSOLID);
for(i=0; i<ATT_UNDECLARED; i++)
{
m_pUnitColor[i] = new wxColour;
m_pDarkColor[i] = new wxColour;
}
m_HexSizeIdx = -1;
m_HexSizeIdxOld = -1;
m_ShowState = 0;
m_MinSelMen = 0;
m_pCities = new CBaseCollById(32);
m_pTrackHexes = new CLongColl(8);
m_pPopupLand = NULL;
m_UnknownColorIdx = -1;
m_Hatch = FALSE;
m_Rect_IsPaused = false;
m_Rect_IsDragging = false;
m_Rect_x1 = 0;
m_Rect_y1 = 0;
m_Rect_x2 = 0;
m_Rect_y2 = 0;
m_RingRadius = 0;
m_bAdvancedIcons = FALSE;
}
//--------------------------------------------------------------------------
CMapPane::~CMapPane()
{
int i;
delete m_pPen;
delete m_pPenWall;
delete m_pPenSel;
delete m_pPenTropic;
delete m_pPenRing;
delete m_pPenRoad;
delete m_pPenRoadBad;
delete m_pPenBlack;
delete m_pPenRed2;
delete m_pPenRed;
delete m_pPenGrey;
delete m_pPenCoastline;
for(i=0; i<ATT_UNDECLARED; i++)
{
delete m_pUnitColor[i];
delete m_pDarkColor[i];
}
for (i=0; i<LAND_FLAG_COUNT; i++)
delete m_pPenFlag[i];
delete m_pBrushBlack;
delete m_pBrushWhite;
delete m_pBrushRed ;
m_pCities->DeleteAll();
delete m_pCities;
delete m_pTrackHexes;
m_TerrainBrushes.FreeAll();
m_TerrainNames .FreeAll();
m_EdgeProps .FreeAll();
}
//--------------------------------------------------------------------------
void CMapPane::Init(CAhFrame * pParentFrame)
{
const char * p;
long x;
CStr S;
m_pFrame = pParentFrame;
m_ShowState = atol(gpApp->GetConfig(SZ_SECT_MAP_PANE, SZ_KEY_STATE));
m_MinSelMen = atol(gpApp->GetConfig(SZ_SECT_COMMON , SZ_KEY_MIN_SEL_MEN));
p = gpApp->GetConfig(SZ_SECT_COMMON, SZ_KEY_HEX_SIZE_LIST);
while (p && *p)
{
p = SkipSpaces(S.GetToken(p, ','));
x = atol(S.GetData());
x = (x/2)*2; // make it even!
if (x>0)
m_HexSizes.Insert((void*)x);
}
if (0==m_HexSizes.Count())
m_HexSizes.Insert((void*)24);
m_SelPlane = atol(gpApp->GetConfig(SZ_SECT_MAP_PANE , SZ_KEY_PLANE_SEL ));
LoadPlaneConfig();
ApplyIcons();
ApplyColors();
//UpdateEditPane();
gpApp->OnMapSelectionChange();
}
//--------------------------------------------------------------------------
void CMapPane::Done()
{
gpApp->SetConfig(SZ_SECT_MAP_PANE , SZ_KEY_STATE , m_ShowState);
gpApp->SetConfig(SZ_SECT_MAP_PANE , SZ_KEY_PLANE_SEL , m_SelPlane );
SavePlaneConfig();
}
//--------------------------------------------------------------------------
void CMapPane::SavePlaneConfig()
{
CStr sSection;
sSection << "PLANE_" << m_SelPlane;
gpApp->SetConfig(sSection.GetData(), SZ_KEY_HEX_SIZE , m_HexSizeIdx );
gpApp->SetConfig(sSection.GetData(), SZ_KEY_HEX_SIZE_OLD , m_HexSizeIdxOld );
gpApp->SetConfig(sSection.GetData(), SZ_KEY_ATLA_X0 , m_AtlaX0 );
gpApp->SetConfig(sSection.GetData(), SZ_KEY_ATLA_Y0 , m_AtlaY0 );
gpApp->SetConfig(sSection.GetData(), SZ_KEY_HEX_SEL_X , m_SelHexX );
gpApp->SetConfig(sSection.GetData(), SZ_KEY_HEX_SEL_Y , m_SelHexY );
}
//-------------------------------------------------------------------------
void CMapPane::LoadPlaneConfig()
{
CStr sSection;
long x;
sSection << "PLANE_" << m_SelPlane;
x = atol(gpApp->GetConfig(sSection.GetData(), SZ_KEY_HEX_SIZE ));
SetHexSize(x);
m_HexSizeIdxOld = atol(gpApp->GetConfig(sSection.GetData(), SZ_KEY_HEX_SIZE_OLD ));
m_AtlaX0 = atol(gpApp->GetConfig(sSection.GetData(), SZ_KEY_ATLA_X0 ));
m_AtlaY0 = atol(gpApp->GetConfig(sSection.GetData(), SZ_KEY_ATLA_Y0 ));
m_SelHexX = atol(gpApp->GetConfig(sSection.GetData(), SZ_KEY_HEX_SEL_X ));
m_SelHexY = atol(gpApp->GetConfig(sSection.GetData(), SZ_KEY_HEX_SEL_Y ));
}
//-------------------------------------------------------------------------
void CMapPane::ApplyFonts()
{
Refresh(FALSE);
}
//-------------------------------------------------------------------------
//void CMapPane::ApplyOneEdgeColor(const char * name, const char * value)
//{
// wxColour cr;
// const char * p;
// CStr S;
// int n;
// CEdgeStructProperties * pEdgeProp = new CEdgeStructProperties;
//
// // Name
// pEdgeProp->name = name;
//
// // Orientation
// p = value;
// p = SkipSpaces(S.GetToken(p, ','));
// pEdgeProp->orientation = atol(S.GetData());
//
// // Thickness
// p = SkipSpaces(S.GetToken(p, ','));
// n = atol(S.GetData());
// if (n<=0)
// n = 1;
//
// // Color
// S = SZ_KEY_MAP_PREFIX;
// S << name;
// StrToColor(&cr, gpApp->GetConfig(SZ_SECT_COLORS, S.GetData()));
// pEdgeProp->pen = new wxPen(cr, n, wxSOLID);
//
// if (!m_EdgeProps.Insert(pEdgeProp))
// delete pEdgeProp;
//}
//-------------------------------------------------------------------------
void CMapPane::ApplyOneColor(wxColour & cr, const char * name)
{
wxBrush * pBrush = NULL;
wxBitmap bmp;
CStr S;
CFileReader F;
wxColour cr2;
m_TerrainNames.Insert(strdup(name));
if (0==stricmp(SZ_KEY_MAP_UNKNOWN, name))
m_UnknownColorIdx = m_TerrainBrushes.Count();
#ifndef __WXMAC_OSX__
S << name << ".bmp";
if (F.Open(S.GetData()))
{
F.Close();
if (bmp.LoadFile(wxString::FromAscii(S.GetData()), wxBITMAP_TYPE_BMP ))
{
pBrush = new wxBrush(bmp);
}
}
#endif
if (!pBrush)
pBrush = new wxBrush(cr, wxSOLID);
m_TerrainBrushes.Insert(pBrush);
cr2.Set(cr.Red() >> 1, cr.Green() >> 1, cr.Blue() >> 1);
pBrush = new wxBrush(cr2, wxCROSSDIAG_HATCH);
m_TerrainBrushes.Insert(pBrush);
}
//-------------------------------------------------------------------------
void CMapPane::ApplyIcons()
{
m_bAdvancedIcons = (0==stricmp(gpApp->GetConfig(SZ_SECT_COMMON, SZ_KEY_ICONS), SZ_ICONS_ADVANCED));
}
//-------------------------------------------------------------------------
void CMapPane::ApplyColors()
{
static const char * FlagColorName[LAND_FLAG_COUNT] = {SZ_KEY_MAP_FLAG_1, SZ_KEY_MAP_FLAG_2, SZ_KEY_MAP_FLAG_3};
static wxDash dash[2];
wxColour cr;
long x;
// int idx;
// const char * name;
// const char * value;
int i,n;
int flagwidth;
CLand * pLand;
CPlane * pPlane;
delete m_pPen;
StrToColor(&cr, gpApp->GetConfig(SZ_SECT_COLORS, SZ_KEY_MAP_GRID) );
m_pPen = new wxPen(cr, 1, wxSOLID);
x = atol(gpApp->GetConfig(SZ_SECT_MAP_PANE, SZ_KEY_WALL_WIDTH));
if (x<1) x=1;
if (x>5) x=5;
delete m_pPenWall;
m_pPenWall = new wxPen(*wxBLACK, x, wxSOLID);
delete m_pPenSel;
StrToColor(&cr, gpApp->GetConfig(SZ_SECT_COLORS, SZ_KEY_MAP_GRID_SEL) );
m_pPenSel = new wxPen(cr, 2, wxSOLID);
delete m_pPenTropic;
StrToColor(&cr, gpApp->GetConfig(SZ_SECT_COLORS, SZ_KEY_MAP_TROPIC_LINE) );
m_pPenTropic = new wxPen(cr, 1, wxSOLID);
delete m_pPenRing;
StrToColor(&cr, gpApp->GetConfig(SZ_SECT_COLORS, SZ_KEY_MAP_RING) );
m_pPenRing = new wxPen(cr, 1, wxSOLID);
x = atol(gpApp->GetConfig(SZ_SECT_MAP_PANE, SZ_KEY_ROAD_WIDTH));
if (x<1) x=1;
if (x>6) x=6;
delete m_pPenRoad;
StrToColor(&cr, gpApp->GetConfig(SZ_SECT_COLORS, SZ_KEY_MAP_ROAD) );
m_pPenRoad = new wxPen(cr, x, wxSOLID);
delete m_pPenRoadBad;
i = atol(gpApp->GetConfig(SZ_SECT_MAP_PANE, SZ_KEY_DASH_BAD_ROADS));
if (i)
{
m_pPenRoadBad = new wxPen(cr, x, wxUSER_DASH); //wxSOLID);
dash[0] = 1; dash[1] = 2;
m_pPenRoadBad->SetDashes(2, dash);
}
else
{
StrToColor(&cr, gpApp->GetConfig(SZ_SECT_COLORS, SZ_KEY_MAP_ROAD_BAD) );
m_pPenRoadBad = new wxPen(cr, x, wxSOLID);
}
flagwidth = atoi(gpApp->GetConfig(SZ_SECT_MAP_PANE, SZ_KEY_FLAG_WIDTH));
for (i=0; i<LAND_FLAG_COUNT; i++)
{
delete m_pPenFlag[i];
StrToColor(&cr, gpApp->GetConfig(SZ_SECT_COLORS, FlagColorName[i]) );
m_pPenFlag[i] = new wxPen(cr, flagwidth, wxSOLID);
}
delete m_pPenCoastline;
StrToColor(&cr, gpApp->GetConfig(SZ_SECT_COLORS, SZ_KEY_MAP_COASTLINE) );
m_pPenCoastline = new wxPen(cr, 6, wxSOLID);
for (i=0; i<ATT_UNDECLARED; i++)
{
delete m_pUnitColor[i];
delete m_pDarkColor[i];
switch(i)
{
case ATT_FRIEND1:
StrToColor(&cr, gpApp->GetConfig(SZ_SECT_COLORS, SZ_KEY_MAP_TRUSTED));
break;
case ATT_FRIEND2:
StrToColor(&cr, gpApp->GetConfig(SZ_SECT_COLORS, SZ_KEY_MAP_PREFERRED));
break;
case ATT_NEUTRAL:
StrToColor(&cr, gpApp->GetConfig(SZ_SECT_COLORS, SZ_KEY_MAP_TOLERATED));
break;
case ATT_ENEMY:
StrToColor(&cr, gpApp->GetConfig(SZ_SECT_COLORS, SZ_KEY_MAP_ENEMY));
break;
default: // shouldn't be used
StrToColor(&cr, "255,255,255");
}
m_pUnitColor[i] = new wxColour(cr);
m_pDarkColor[i] = new wxColor((char) (cr.Red()*.66),(char) (cr.Green()*.66),(char) (cr.Blue()*.66));
}
m_TerrainBrushes.FreeAll();
m_TerrainNames .FreeAll();
m_UnknownColorIdx = -1;
for (n=0; n<gpApp->m_pAtlantis->m_Planes.Count(); n++)
{
pPlane = (CPlane*)gpApp->m_pAtlantis->m_Planes.At(n);
for (i=0; i<pPlane->Lands.Count(); i++)
{
pLand = (CLand*)pPlane->Lands.At(i);
pLand->guiColor = -1;
}
}
m_Hatch = atol(gpApp->GetConfig(SZ_SECT_COMMON, SZ_KEY_HATCH_UNVISITED));
// idx = gpApp->GetSectionFirst(SZ_SECT_COLORS, name, value);
// while (idx>=0)
// {
// StrToColor(&cr, value);
// ApplyOneColor(cr, name);
//
// idx = gpApp->GetSectionNext (idx, SZ_SECT_COLORS, name, value);
// }
// load edge structures colors
m_EdgeProps.FreeAll();
// idx = gpApp->GetSectionFirst(SZ_SECT_EDGE_STRUCTS, name, value);
// while (idx>=0)
// {
// // There is a bug here - function calls GetConfig, which creates a new config entry,T
// // making idx point to a wrong location.
// // Though it seems not dangerous under current conditions.... maybe fix later
// ApplyOneEdgeColor(name, value);
//
// idx = gpApp->GetSectionNext (idx, SZ_SECT_EDGE_STRUCTS, name, value);
// }
Refresh(FALSE);
}
//--------------------------------------------------------------------------
wxBrush * CMapPane::GetLandBrush(CLand * pLand, BOOL GetHatched)
{
int idx, i;
const char * name;
wxColour cr;
// int Hatch;
idx = pLand?pLand->guiColor:m_UnknownColorIdx;
if (idx<0 || idx>=m_TerrainBrushes.Count())
{
idx = -1;
name = pLand?pLand->TerrainType.GetData():SZ_KEY_MAP_UNKNOWN;
for (i=0; i<m_TerrainNames.Count(); i++)
if (0==stricmp(name, (const char*)m_TerrainNames.At(i)))
{
idx = i*2;
break;
}
if (idx<0)
{
// totally new color, but try to read it, so it gets into config file
StrToColor(&cr, gpApp->GetConfig(SZ_SECT_COLORS, name) );
//Hatch = atol(gpApp->GetConfig(SZ_SECT_COMMON, SZ_KEY_HATCH_UNVISITED));
idx = m_TerrainBrushes.Count();
ApplyOneColor(cr, name);
}
if (pLand)
pLand->guiColor = idx;
else
m_UnknownColorIdx = idx; // should be set by this moment, but just in case.
}
if (GetHatched)
idx++;
return (wxBrush*)m_TerrainBrushes.At(idx);
}
//--------------------------------------------------------------------------
CEdgeStructProperties * CMapPane::GetEdgeProps(const char * name)
{
wxColour cr;
const char * p;
CStr S;
int n;
CEdgeStructProperties * pEdgeProp; //
CEdgeStructProperties Dummy;
int idx;
Dummy.name = name;
if (m_EdgeProps.Search(&Dummy, idx))
pEdgeProp = (CEdgeStructProperties*)m_EdgeProps.At(idx);
else
{
pEdgeProp = new CEdgeStructProperties;
// Name
pEdgeProp->name = name;
// Shape
p = gpApp->GetConfig(SZ_SECT_EDGE_STRUCTS, name);
if (!p || !*p)
{
p = "border,1";
gpApp->SetConfig(SZ_SECT_EDGE_STRUCTS, name, p);
}
p = SkipSpaces(S.GetToken(p, ','));
if (0==stricmp(S.GetData(), "border"))
pEdgeProp->shape = EDGE_SHAPE_BORDER;
else if (0==stricmp(S.GetData(), "road"))
pEdgeProp->shape = EDGE_SHAPE_ROAD;
else if (0==stricmp(S.GetData(), "bridge"))
pEdgeProp->shape = EDGE_SHAPE_BRIDGE;
else if (0==stricmp(S.GetData(), "anchor"))
pEdgeProp->shape = EDGE_SHAPE_ANCHOR;
else if (0==stricmp(S.GetData(), "rocks"))
pEdgeProp->shape = EDGE_SHAPE_ROCKS;
else
pEdgeProp->shape = EDGE_SHAPE_IGNORE;
// Thickness
p = SkipSpaces(S.GetToken(p, ','));
n = atol(S.GetData());
if (n<=0)
n = 1;
// Color
S = SZ_KEY_MAP_PREFIX;
S << name;
StrToColor(&cr, gpApp->GetConfig(SZ_SECT_COLORS, S.GetData()));
pEdgeProp->pen = new wxPen(cr, n, wxSOLID);
m_EdgeProps.Insert(pEdgeProp);
}
return pEdgeProp;
}
//--------------------------------------------------------------------------
inline BOOL CMapPane::ValidHexNo(int NoX, int NoY)
{
// sum of coordinates must be even
int x = abs(NoX) + abs(NoY);
return x == ((x>>1)<<1);
}
//--------------------------------------------------------------------------
int CMapPane::NormalizeHexX(int NoX, CPlane * pPlane)
{
if (pPlane && pPlane->Width>0)
{
while (NoX < pPlane->WestEdge)
NoX += pPlane->Width;
while (NoX > pPlane->EastEdge)
NoX -= pPlane->Width;
}
return NoX;
}
//--------------------------------------------------------------------------
void CMapPane::GetHexNo(int & NoX, int & NoY, int WinX, int WinY)
{
// center of (0,0) hex has 0,0 Atla coordinates
long AtlaX, AtlaY;
int ApprX, ApprY; //approximite hex no
int x, y;
int x0, y0, x1, y1, x2, y2;
WinToAtla(WinX, WinY, AtlaX, AtlaY);
ApprX = AtlaX / (m_HexSize * 3 / 2); // m_HexSize must be even!
ApprY = AtlaY / m_HexHalfHeight;
for (x = ApprX-1; x <= ApprX+1; x++)
for (y = ApprY-2; y <= ApprY+2; y++)
if ( ValidHexNo(x,y) &&
(AtlaY >= y*m_HexHalfHeight - m_HexHalfHeight) &&
(AtlaY <= y*m_HexHalfHeight + m_HexHalfHeight) )
{
// hex center
x0 = x * m_HexSize * 3 / 2;
y0 = y * m_HexHalfHeight;
x1 = x0 - m_HexSize;
y1 = y0;
x2 = x0 - m_HexHalfSize;
y2 = y0 - m_HexHalfHeight;
if (AtlaY < y1 + (double)(y2-y1)/(x2-x1)*(AtlaX-x1))
continue;
x1 = x0 + m_HexSize;
y1 = y0;
x2 = x0 + m_HexHalfSize;
y2 = y0 - m_HexHalfHeight;
if (AtlaY < y1 + (double)(y2-y1)/(x2-x1)*(AtlaX-x1))
continue;
x1 = x0 - m_HexSize;
y1 = y0;
x2 = x0 - m_HexHalfSize;
y2 = y0 + m_HexHalfHeight;
if (AtlaY > y1 + (double)(y2-y1)/(x2-x1)*(AtlaX-x1))
continue;
x1 = x0 + m_HexSize;
y1 = y0;
x2 = x0 + m_HexHalfSize;
y2 = y0 + m_HexHalfHeight;
if (AtlaY > y1 + (double)(y2-y1)/(x2-x1)*(AtlaX-x1))
continue;
NoX = x;
NoY = y;
return;
}
}
//--------------------------------------------------------------------------
void CMapPane::GetHexCenter(int NoX, int NoY, int & WinX, int & WinY)
{
// center of (0,0) hex has 0,0 Atla coordinates
long AtlaX, AtlaY;
AtlaX = NoX * m_HexSize * 3 / 2;
AtlaY = NoY * m_HexHalfHeight;
AtlaToWin(WinX, WinY, AtlaX, AtlaY);
}
//--------------------------------------------------------------------------
inline void CMapPane::WinToAtla(int WinX, int WinY, long & AtlaX, long & AtlaY)
{
AtlaX = WinX + m_AtlaX0;
AtlaY = WinY + m_AtlaY0;
}
//--------------------------------------------------------------------------
inline void CMapPane::AtlaToWin(int & WinX, int & WinY, long AtlaX, long AtlaY)
{
WinX = AtlaX - m_AtlaX0;
WinY = AtlaY - m_AtlaY0;
}
//--------------------------------------------------------------------------
BOOL CMapPane::SetHexSize(int HexSizeIdx)
{
// wxRect rect;
long CX, CY;
long CXOld, CYOld;
BOOL Changed;
int width, height;
int OldIdx = m_HexSizeIdx;
int OldSize = m_HexSize; //(long)m_HexSizes.At(m_HexSizeIdx);
int OldHalfHeight = m_HexHalfHeight;
m_HexSizeIdx = HexSizeIdx;
if (m_HexSizeIdx < 0)
m_HexSizeIdx = 0;
if (m_HexSizeIdx >= m_HexSizes.Count())
m_HexSizeIdx = m_HexSizes.Count()-1;
Changed = (OldIdx != m_HexSizeIdx);
if (Changed)
{
m_HexSizeIdxOld = OldIdx;
if (m_HexSizeIdxOld < 0)
m_HexSizeIdxOld = m_HexSizeIdx;
m_HexSize = (long)m_HexSizes.At(m_HexSizeIdx);
m_HexHalfSize = m_HexSize / 2;
m_HexHalfHeight = (int)(m_HexSize * cos30 + 0.5);
m_HexHeight = m_HexHalfHeight * 2;
if (OldIdx>=0)
{
GetClientSize(&width, &height);
WinToAtla(width/2, height/2, CXOld, CYOld);
CX = (long)( (double)CXOld * (double)m_HexSize / (double)OldSize + 0.5);
CY = (long)( (double)CYOld * (double)m_HexHalfHeight / (double)OldHalfHeight + 0.5);
m_AtlaX0 = CX - width/2;
m_AtlaY0 = CY - height/2;
//m_AtlaX0 += CXOld*((double)m_HexSize/(double)OldSize - 1);
//m_AtlaY0 += CYOld*((double)m_HexSize/(double)OldSize - 1);;
}
for (int sidx=0; sidx<MAX_DETAIL; sidx++)
{
if(m_HexSize >= SizeForDetail[sidx]) m_Detail = sidx;
}
}
return Changed;
}
//--------------------------------------------------------------------------
void CMapPane::DrawHexTest(int NoX, int NoY, wxDC * pDC, CLand * pLand)
{
/*
if (!ValidHexNo(NoX, NoY))
return;
int x0, y0; // hex center
GetHexCenter(NoX, NoY, x0, y0);
pDC->Ellipse(x0-6, y0-6, x0+6, y0+6);
*/
}
//--------------------------------------------------------------------------
void CMapPane::DrawEdge(wxDC * pDC, CPlane * pPlane)
{
}
void CMapPane::DrawCoastalLine(wxDC * pDC, wxPoint * point, int direction)
{
int x1=0, y1=0, x2=0, y2=0;
int scale = m_HexHalfHeight / 4;
if(scale%2) scale +=1;
if(scale < 6) scale = 6;
if(m_Detail<EDGE_DETAIL) scale -= 2;
if(m_Detail<UNIT_DETAIL) scale = 2;
switch (direction)
{
case North:
x1 = point[1].x+1;
y1 = point[1].y+(scale/2);
x2 = point[2].x-1;
y2 = point[2].y+(scale/2);
break;
case Northeast:
x1 = point[2].x-(scale/2)+1;
y1 = point[2].y+3;
x2 = point[3].x-(scale/2);
y2 = point[3].y;
break;
case Southeast:
x1 = point[3].x-(scale/2);
y1 = point[3].y;
x2 = point[4].x-(scale/2)+1;
y2 = point[4].y-2;
break;
case South:
x1 = point[4].x-1;
y1 = point[4].y-(scale/2);
x2 = point[5].x+1;
y2 = point[5].y-(scale/2);
break;
case Southwest:
x1 = point[5].x+(scale/2)-1;
y1 = point[5].y-2;
x2 = point[0].x+(scale/2);
y2 = point[0].y;
break;
case Northwest:
x1 = point[0].x+(scale/2);
y1 = point[0].y;
x2 = point[1].x+(scale/2)-1;
y2 = point[1].y+3;
break;
}
m_pPenCoastline->SetWidth(scale);
pDC->SetPen(*m_pPenCoastline);
pDC->DrawLine(x1, y1, x2, y2);
}
void CMapPane::DrawEdgeStructures(wxDC * pDC, CLand * pLand, wxPoint * point, int x0, int y0)
{
int i;
int scale = m_HexHalfHeight / 4;
if(scale%2) scale +=1;
if(scale < 6) scale = 6;
if (m_Detail >= UNIT_DETAIL && pLand)
{
for (i=0; i<pLand->EdgeStructs.Count(); i++)
{
int x1=0, y1=0, x2=0, y2=0;
int xa1, ya1, xb1, yb1;
int xa2, ya2, xb2, yb2;
CStruct * pEdge = (CStruct*)pLand->EdgeStructs.At(i);
CEdgeStructProperties * pProps = GetEdgeProps(pEdge->Kind.GetData());
wxPen * pPen = pProps->pen;
int offset = 1;
if (m_Detail < EDGE_DETAIL)
{
if ((pProps->shape != EDGE_SHAPE_BORDER)
&& (pProps->shape != EDGE_SHAPE_ROAD)) continue;
if ((m_Detail<ROAD_DETAIL) && (pProps->shape == EDGE_SHAPE_ROAD))
continue;
pPen = new wxPen(pPen->GetColour(), 1, pPen->GetStyle());
offset = 0;
}
pDC->SetPen(*pPen);
switch (pProps->shape)
{
case EDGE_SHAPE_BORDER:
// parallel
if(pLand->Flags&LAND_IS_WATER) break;
switch (pEdge->Location)
{
case North:
x1 = point[1].x + offset; y1 = point[1].y + offset;
x2 = point[2].x - offset; y2 = point[2].y + offset;
break;
case Northeast:
x1 = point[2].x - offset; y1 = point[2].y + offset + 1;
x2 = point[3].x - offset; y2 = point[3].y;
break;
case Southeast:
x1 = point[3].x - offset; y1 = point[3].y;
x2 = point[4].x - offset; y2 = point[4].y - offset - 1;
break;
case South:
x1 = point[4].x - offset; y1 = point[4].y - offset;
x2 = point[5].x + offset; y2 = point[5].y - offset;
break;
case Southwest:
x1 = point[5].x + offset; y1 = point[5].y - offset - 1;
x2 = point[0].x + offset; y2 = point[0].y;
break;
case Northwest:
x1 = point[0].x + offset; y1 = point[0].y;
x2 = point[1].x + offset; y2 = point[1].y + offset + 1;
break;
}
pDC->DrawLine(x1, y1, x2, y2);
break;
case EDGE_SHAPE_ROAD:
// perpendiculars (roads)
switch (pEdge->Location)
{
case North:
x1 = x0;
y1 = y0-m_HexHalfHeight;
break;
case Northeast:
x1 = x0+m_HexHalfSize*3/2;
y1 = y0-m_HexHalfHeight/2;
break;
case Southeast:
x1 = x0+m_HexHalfSize*3/2;
y1 = y0+m_HexHalfHeight/2;
break;
case South:
x1 = x0;
y1 = y0+m_HexHalfHeight;
break;
case Southwest:
x1 = x0-m_HexHalfSize*3/2;
y1 = y0+m_HexHalfHeight/2;
break;
case Northwest:
x1 = x0-m_HexHalfSize*3/2;
y1 = y0-m_HexHalfHeight/2;
break;
}
pDC->DrawLine(x0, y0, x1, y1);
break;
case EDGE_SHAPE_BRIDGE:
// Bridge
switch (pEdge->Location)
{
case North:
xa1 = (point[1].x + point[2].x)/2 - 2; xb1 = xa1+4;
ya1 = yb1 = point[1].y;
xa2 = xa1; xb2 = xb1;
ya2 = yb2 = point[1].y + m_HexHalfHeight/2;
break;
case Northeast:
x1 = (point[2].x + point[3].x)/2;
y1 = (point[2].y + point[3].y)/2;
xa1 = x1-1; xb1 = x1+1;
ya1 = y1-2; yb1 = y1+2;
x1 = (x1+x0)/2;
y1 = (y1+y0)/2;
xa2 = x1-1; xb2 = x1+1;
ya2 = y1-2; yb2 = y1+2;
break;
case Southeast:
x1 = (point[3].x + point[4].x)/2;
y1 = (point[3].y + point[4].y)/2;
xa1 = x1+1; xb1 = x1-1;