25 const float PI = 3.141592f;
33 if (
map.open(QIODevice::ReadOnly | QIODevice::Text) ) {
37 mapSize = (
map.open(QIODevice::ReadOnly | QIODevice::Text) ) ?
44 long * longitude,
long * latitude)
46 QSettings map_info(
home_path+world_name+
"/map.ini", QSettings::IniFormat);
51 map_info.setValue(
"spawn_longitude", qlonglong(*longitude));
52 map_info.setValue(
"spawn_latitude" , qlonglong(*latitude ));
56 size = qMax(size/4, 1);
57 return (qrand()%size) + size;
68 longi >=
mapSize || longi < 0 ||
72 }
else if ( not
map.seek((
mapSize+1)*longi+lati) ) {
81 const float x_cent = x-size/2.f;
82 const float y_cent = y-size/2.f;
84 if ( x_cent > 0 && y_cent >= 0 ) {
85 fi = atanf(y_cent/x_cent);
86 }
else if ( x_cent>0 && y_cent<0 ) {
87 fi = atanf(y_cent/x_cent)+2*
PI;
88 }
else if ( x_cent<0 ) {
89 fi = atanf(y_cent/x_cent)+
PI;
90 }
else if ( qFuzzyCompare(x_cent, 0.f) && y_cent>0 ) {
92 }
else if ( qFuzzyCompare(x_cent, 0.f) && y_cent<0 ) {
97 return 360*fi / 2 /
PI;
101 return sqrtf( (x-size/2.f)*(x-size/2.f)+(y-size/2.f)*(y-size/2.f) );
111 Q_ASSERT(min_rad < max_rad);
112 float maxs[360] = { float(qrand()%(max_rad - min_rad) + min_rad) };
113 for (
int x=1; x<360; ++x) {
114 maxs[x] = ( x > 345 ) ?
115 maxs[x-1] + (maxs[0] - maxs[345]) / 15 :
116 qBound(
float(min_rad),
117 maxs[x-1]+(qrand()%400-200)/200.f,
float(max_rad));
119 for (
int y=0; y<size; ++y)
120 for (
int x=0; x<size; ++x) {
121 if (
R(x, y, size) < maxs[
Round(
Deg(x, y, size))] ) {
128 const QString world_name,
134 size = qMax(10, size);
136 char *
const map =
new char[size*size];
137 memset(map, outer, size*size);
139 const float min_rad = size/3.0f;
140 const float max_rad = size/2.0f;
146 int lakes_number = (qrand() % size) + 5;
147 while ( lakes_number-- ) {
149 switch ( qrand()%4 ) {
154 const float lake_size = qrand() % (size/10) + 1;
155 const int lake_start_x = qrand() % int(size-lake_size);
156 const int lake_start_y = qrand() % int(size-lake_size);
157 const int border = (lake_size-1)*(lake_size-1)/2/2;
158 for (
int x=lake_start_x; x<lake_start_x+lake_size; ++x)
159 for (
int y=lake_start_y; y<lake_start_y+lake_size; ++y) {
160 if ( (x-lake_start_x-lake_size/2)*(x-lake_start_x-lake_size/2)
161 + (y-lake_start_y-lake_size/2)*(y-lake_start_y-lake_size/2)
164 map[x*size+y] = type;
169 long spawn_longitude, spawn_latitude;
171 PieceOfEden(spawn_latitude-1, spawn_longitude-1, map, size);
174 fopen(qPrintable(
home_path + world_name +
"/map.txt"),
"wb");
175 for (
int y=0; y<size; ++y, fputc(
'\n', file))
176 for (
int x=0; x<size; ++x) {
177 fputc(map[x*size+y], file);
184 char *
const map,
const size_t size)
186 if ( (x+5)*size + y+5 > size*size)
return;
195 for (
int j=0; j<6; ++j)
196 for (
int i=0; i<6; ++i) {
197 map[(x+j)*size + y+i] = eden[i][j];
static float Deg(int x, int y, int size)
static void MakeAndSaveSpawn(QString world_name, int size, long *longitude, long *latitude)
static void PieceOfEden(int x, int y, char *map, size_t map_size)
long GetSpawnLongitude() const
static void Circle(int min_rad, int max_rad, char ch, int size, char *map)
long GetSpawnLatitude() const
static void GenerateMap(QString world_name, int size, char outer, int seed)
static float R(int x, int y, int size)
char TypeOfShred(long longi, long lati) const
static int GetSpawnCoordinate(int size)