-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTileMap.hpp
executable file
·108 lines (96 loc) · 3.18 KB
/
TileMap.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
#pragma once
#include <cstring>
#include <cstdlib>
#include <vector>
#include <iostream>
#include <string>
#include <cxxabi.h>
#include "MapObject.hpp"
#include "RedBlackTree.hpp"
typedef vector<Tile *> Row;
typedef vector<Row> SGTilesList;
using namespace std;
using namespace abi;
class Map{
public:
SGTilesList * map;
void Linker(int fy, int fx, int dir, int ty, int tx, LinkerParam lp = Normal){
dir = dir%6;
if(lp == PolarSud){
this->map->at(fy)[fx]->border[dir] = map->at(ty)[tx];
this->map->at(ty)[tx]->border[dir-1] = map->at(fy)[fx];
}
else if(lp == PolarNord){
this->map->at(fy)[fx]->border[dir] = map->at(ty)[tx];
this->map->at(ty)[tx]->border[dir+1] = map->at(fy)[fx];
}
else{
this->map->at(fy)[fx]->border[dir] = this->map->at(ty)[tx];
this->map->at(ty)[tx]->border[dir + 3 == 6 ? 0 : dir] = this->map->at(fy)[fx];
}
}
};
class TileRowCreator : public Map{
Tree tileList;
int w;
int dimension;
int curRow;
int curPos;
bool inlac;
public:
TileRowCreator(int inW, int inDimension, int treeDimension, SGTilesList* context) : tileList(treeDimension){
this->w = inW;
this->dimension = inDimension;
this->map = context;
}
void newRow(int row, bool inlac){
this->inlac = inlac;
this->curPos = 1;
this->curRow = row;
this->map->operator[](curRow).push_back(tileList.emplace_back(curRow, 0));
if(!inlac){
Map::Linker(curRow,0,1,curRow-1,0);
}
else{
Map::Linker(curRow,0,2,curRow-1,0);
Map::Linker(curRow,0,1,curRow-1,1);
}
emplaceSection(curPos+(w));
}
void emplaceSection(int target){
for(int l = curPos; l < target; l++){
curPos++;
this->map->operator[](curRow).push_back(tileList.emplace_back(curRow,l));
//linker
Map::Linker(curRow,l,3,curRow,l-1);
Map::Linker(curRow,l,2,curRow-1,l-1);
Map::Linker(curRow,l,1,curRow-1,l);
//sprintf_s(errorMessage, "colonna %d done", l);
//puts(errorMessage);
if(curPos == dimension){
//finalize the raw
Map::Linker(curRow,dimension-1,0,curRow,0);
if(inlac){
Linker(curRow,dimension-1,1,curRow-1,0);
}
}
}
}
};
class TileBoard : public MapObject, public Map{
public:
int len = 0;
int hei = 0;
Tree fullTileList;
TileBoard(int dimension) : fullTileList(dimension*(dimension/2)){
Naming(this);
char errorMessage[50];
puts("Naming done");
//Variables initialization
len = dimension;
hei = dimension/2;
map = new SGTilesList();
map->reserve(hei);
puts("Vectors initialization Done");
}
};