-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTileMap[before RBT].hpp
executable file
·206 lines (190 loc) · 5.97 KB
/
TileMap[before RBT].hpp
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
#pragma once
#include <cstring>
#include <cstdlib>
#include <vector>
#include <iostream>
#include <string>
#include <cxxabi.h>
#include "Native.hpp"
using namespace std;
using namespace abi;
class MapObject{
public:
char name [20];
int id = 0;
MapObject(){
Naming(this);
}
template <typename T>
void Naming(T object){
object->id = (const int)rand();
char hexa[12] = "0x";
int* status = 0;
strcpy(name, __cxa_demangle(typeid(object).name(), 0, 0, status));
strcat(object->name, " - ");
strcat(object->name, To_hex(object->id, hexa));
}
};
class Tile : public MapObject{
Position * position;
//Mass
int land{};
int water{};
public:
Tile *border[6];
Tile(int iy, int ix){
Naming(this);
position = new Position(iy, ix);
}
int GetX(){
return this->position->x;
}
int GetY(){
return this->position->y;
}
};
class Plate : public MapObject{
public:
Plate(){
Naming(this);
}
Cardinals direction;
int size;
vector<Tile*> tiles;
};
class TileBoard : public MapObject{
public:
int len = 0;
int hei = 0;
vector<Tile> fullTileList;
vector<vector<Tile *>> map;
TileBoard(int dimension){
Naming(this);
char errorMessage[50];
puts("Naming done");
//Variables initialization
len = dimension;
hei = dimension/2;
fullTileList.reserve(len*hei);
map.reserve(hei);
int index = 0;
puts("Vectors initialization Done");
//
//Map creation - Polar Sud Row
//
fullTileList.emplace_back(0,0);
vector<Tile *> sudLine;
sudLine.reserve(len);
map.push_back(sudLine);
map[0].push_back(&fullTileList[index]);
index++;
puts("First tile done");
//first raw
for (int l = 1; l < len; l++){
fullTileList.emplace_back(0,l);
map[0].push_back(&fullTileList[index]);
index++;
//linker
Linker(0,l,3,0,l-1);
if(l>=len/2){ //might be improvable
Linker(0,l,2,0,l-len/2, PolarSud);
Linker(0,l-len/2,1,0,l, PolarNord); //We use polarNord only for to use the correct link direction
if(l == len-1){
Linker(0,l,3,0,0);
}
}
}
puts("First Row Linker Done");
//
//main tile map
//
bool inlac;
for(int h = 1; h < hei-1; h++){
inlac = h%2==0;
vector<Tile *> newLine;
newLine.reserve(len);
map.push_back(newLine);
fullTileList.emplace_back(h, 0);
map[h].push_back(&fullTileList[index]);
index++;
if(!inlac){
Linker(h,0,1,h-1,0);
}
else{
Linker(h,0,2,h-1,0);
Linker(h,0,1,h-1,1);
}
sprintf(errorMessage, "row %d initialized", h);
puts(errorMessage);
for (int l = 1; l < len; l++){
fullTileList.emplace_back(h,l);
map[h].push_back(&fullTileList[index]);
index++;
//linker
Linker(h,l,3,h,l-1);
Linker(h,l,2,h-1,l-1);
Linker(h,l,1,h-1,l);
//sprintf_s(errorMessage, "colonna %d done", l);
//puts(errorMessage);
}
//finalize the raw
Linker(h,len-1,0,h,0);
if(inlac){
Linker(h,len-1,1,h-1,0);
}
sprintf(errorMessage, "row %d done", h);
puts(errorMessage);
}
//
// PolarNord row
//
int h = hei-1; //last raw
vector<Tile *> nordLine;
nordLine.reserve(len);
map.push_back(nordLine);
fullTileList.emplace_back(h, 0);
map[h].push_back(&fullTileList[index]);
index++;
if(inlac){
Linker(h,0,1,h-1,0);
}
else{
Linker(h,0,2,h-1,0);
Linker(h,0,1,h-1,1);
}
puts("North Pole row initialized");
for(int pl = 1; pl < len; pl++){
fullTileList.emplace_back(h,pl);
map[h].push_back(&fullTileList[index]);
index++;
//linker
Linker(h,pl,3,h,pl-1);
Linker(h,pl,2,h-1,pl-1);
Linker(h,pl,1,h-1,pl);
if(pl >= len/2){
Linker(h,pl,4,h,pl-len/2, PolarNord);
Linker(h,pl-len/2,5,h,pl, PolarSud); //We use PolarSud only for to use the correct link direction
if(pl == len-1){
Linker(h, pl, 3, h, 0);
}
}
}
sprintf(errorMessage, "Last row done", h);
puts(errorMessage);
}
void Linker(int fy, int fx, int dir, int ty, int tx, LinkerParam lp = Normal){
dir >= 6 ? 0 : dir;
if(lp == PolarSud){
map[fy][fx]->border[dir] = map[ty][tx];
map[ty][tx]->border[dir-1] = map[fy][fx];
}
else if(lp == PolarNord){
map[fy][fx]->border[dir] = map[ty][tx];
map[ty][tx]->border[dir+1] = map[fy][fx];
}
else{
map[fy][fx]->border[dir] = map[ty][tx];
map[ty][tx]->border[dir + 3 == 6 ? 0 : dir] = map[fy][fx];
}
}
};