-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMap.class.cpp
115 lines (99 loc) · 2.87 KB
/
Map.class.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
// ************************************************************************** //
// //
// ::: :::::::: //
// Map.class.cpp :+: :+: :+: //
// +:+ +:+ +:+ //
// By: jmoiroux <[email protected]> +#+ +:+ +#+ //
// +#+#+#+#+#+ +#+ //
// Created: 2015/01/22 15:27:46 by jmoiroux #+# #+# //
// Updated: 2015/01/22 15:27:47 by jmoiroux ### ########.fr //
// //
// ************************************************************************** //
#include "Map.class.hpp"
Map::Map() {
int y = 0;
int x;
this->_d = getData();
while ( y < TAB_SIZE ) {
x = 0;
while ( x < TAB_SIZE ) {
this->_d->map2d[y][x].type = EMPTY;
this->_d->map2d[y][x].z = 0;
this->_d->originMAp[y][x].type = EMPTY;
this->_d->originMAp[y][x].z = 0;
x++;
}
y++;
}
}
Map::Map( Map const & rSource ) {
*this = rSource;
}
Map & Map::operator=( Map const & rSource ) {
if ( this != &rSource ) {
this->_d = getData();
}
return *this;
}
void Map::doCircle( t_data * d, int z, int startY, int startX ) {
int rayon = RADIUS;
int i;
int j;
while ( z > 0) {
i = startX - rayon;
while ( i <= startX + rayon ) {
j = startY - rayon;
while ( j <= startY + rayon ) {
if ( ((i - startX) * (i - startX)) + ((j - startY) * (j - startY))
<= (rayon * rayon)
&& i < TAB_SIZE && i >= 0
&& j < TAB_SIZE && j >= 0
&& (d->map2d[j][i].type != HILL
|| d->map2d[j][i].z <= z)) {
d->map2d[j][i].type = HILL;
d->map2d[j][i].z = z;
}
j++;
}
i++;
}
z--;
rayon++;
}
}
void Map::doMapHill( void ) {
std::list<t_pts *>::iterator it = this->_d->randomPts.begin();
std::list<t_pts *>::iterator end = this->_d->randomPts.end();
while ( it != end ) {
doCircle( this->_d, static_cast<int>((*it)->z), static_cast<int>((*it)->y), static_cast<int>((*it)->x) );
it++;
}
}
Map::~Map() {}
void Map::putRandomTo2dMap( void ) {
std::list<t_pts *>::iterator it = this->_d->randomPts.begin();
std::list<t_pts *>::iterator end = this->_d->randomPts.end();
while ( it != end ) {
this->_d->map2d[static_cast<int>( (*it)->y) ]
[static_cast<int>( (*it)->x) ].z = (*it)->z;
it++;
}
}
void Map::print2Dmap( void ) { // print Z from 2dmap used for debugg only
if ( DEBUGG == true ) {
int y = 0;
int x;
while( y < TAB_SIZE ) {
x = 0;
while ( x < TAB_SIZE ) {
if (this->_d->map2d[y][x].z == 0)
std::cout << " ";
else
std::cout << "@";
x++;
}
std::cout << std::endl;
y++;
}
}
}