150
158
for (int j = 0; j < width; j++)
151
159
d_building[i*width + j] = Maptile::NONE;
153
cout <<_("Making random map") <<endl;
161
debug("Making random map:");
155
163
// create the terrain
156
cout <<_("Flatening Plains ... 10%") <<endl;
164
debug("flatening plains");
157
165
progress.emit(.090, _("flattening plains..."));
159
cout <<_("Raining Water ... 30%") <<endl;
167
debug("raining water");
160
168
progress.emit(.180, _("raining water..."));
161
169
makeTerrain(Tile::WATER, d_pwater, true);
162
170
makeStreamer(Tile::WATER, d_pwater/3, 3);
163
cout <<_("Raising Hills ... 20%") <<endl;
171
rescueLoneTiles(Tile::WATER,Tile::GRASS,true);
174
debug("raising hills");
164
175
progress.emit(.270, _("raising hills..."));
165
176
makeTerrain(Tile::HILLS, d_phills, false);
166
cout <<_("Raising Mountains ... 30%") <<endl;
177
debug("raising mountains");
167
178
progress.emit(.360, _("raising mountains..."));
168
179
makeTerrain(Tile::MOUNTAIN, d_pmountains, false);
169
180
makeStreamer(Tile::MOUNTAIN, d_pmountains/3, 3);
170
cout <<_("Planting Forest ... 40%") <<endl;
181
rescueLoneTiles(Tile::MOUNTAIN,Tile::GRASS,false);
182
surroundMountains(0, d_width, 0, d_height);
183
debug("planting forest");
171
184
progress.emit(.450, _("planting forests..."));
172
185
makeTerrain(Tile::FOREST, d_pforest, false);
173
cout <<_("Watering Swamps ... 50%") <<endl;
186
debug("watering swamps");
174
187
progress.emit(.540, _("watering swamps..."));
175
188
makeTerrain(Tile::SWAMP, d_pswamp, false);
176
cout <<_("Normalizing ... 60%") <<endl;
189
debug("normalizing terrain");
177
190
progress.emit(.630, _("normalizing terrain..."));
180
193
// place buildings
181
cout <<_("Building Cities ... 70%") <<endl;
194
debug("building cities");
182
195
progress.emit(.720, _("building cities..."));
183
196
makeCities(d_nocities);
187
cout <<_("Paving Roads ... 75%") <<endl;
200
debug("paving roads");
188
201
progress.emit(.810, _("paving roads..."));
204
rescueLoneTiles(Tile::MOUNTAIN,Tile::HILLS,false);
192
cout <<_("Ruining Ruins ... 80%") <<endl;
206
debug("ruining ruins");
193
207
progress.emit(.810, _("ruining ruins..."));
194
208
makeBuildings(Maptile::RUIN,d_noruins);
195
cout <<_("Raising Signs ... 88%") <<endl;
196
progress.emit(.900, _("raising signs..."));
209
debug("spawning temples");
210
progress.emit(.900, _("spawning temples..."));
211
makeBuildings(Maptile::TEMPLE,d_notemples);
212
debug("building bridges");
213
progress.emit(.950, _("building bridges..."));
215
debug("raising signs");
216
progress.emit(.990, _("raising signs..."));
197
217
makeBuildings(Maptile::SIGNPOST,d_nosignposts);
198
cout <<_("Spawning temples ... 90%") <<endl;
199
progress.emit(.990, _("spawning temples..."));
200
makeBuildings(Maptile::TEMPLE,d_notemples);
201
cout <<_("Done making map ... 100%") <<endl;
219
debug("Done making map.");
224
#define NORTH_SOUTH_BRIDGE 1
225
#define EAST_WEST_BRIDGE 2
227
void MapGenerator::placeBridge(Vector<int> pos, int type)
229
Bridgelist *bl = Bridgelist::getInstance();
230
if (type == NORTH_SOUTH_BRIDGE)
232
d_building[pos.y*d_width + pos.x] = Maptile::BRIDGE;
233
d_building[(pos.y + 1)*d_width + pos.x] = Maptile::BRIDGE;
234
bl->push_back(new Bridge(Vector<int>(pos.x, pos.y)));
235
bl->push_back(new Bridge(Vector<int>(pos.x+1, pos.y)));
237
else if (type == EAST_WEST_BRIDGE)
239
d_building[pos.y*d_width + pos.x] = Maptile::BRIDGE;
240
d_building[pos.y*d_width + pos.x + 1] = Maptile::BRIDGE;
241
bl->push_back(new Bridge(Vector<int>(pos.x, pos.y)));
242
bl->push_back(new Bridge(Vector<int>(pos.x, pos.y+1)));
244
GameMap::getInstance()->calculateBlockedAvenues();
247
bool MapGenerator::findBridgePurpose(Vector<int> pos, int type,
248
Vector<int> &src, Vector<int> &dest)
250
if (type == EAST_WEST_BRIDGE)
252
src = GameMap::getInstance()->findNearestObjectToTheWest(pos);
253
dest = GameMap::getInstance()->findNearestObjectToTheEast(pos);
255
else if (type == NORTH_SOUTH_BRIDGE)
257
src = GameMap::getInstance()->findNearestObjectToTheNorth(pos);
258
dest = GameMap::getInstance()->findNearestObjectToTheSouth(pos);
260
if (src == Vector<int>(-1,-1) || dest == Vector<int>(-1,-1))
265
bool MapGenerator::canPlaceBridge(Vector<int> pos, int type, Vector<int> &src, Vector<int> &dest)
267
if (d_building[pos.y*d_width + pos.x] == Maptile::NONE &&
268
findBridgePurpose(pos, type, src, dest) == true)
273
void MapGenerator::makeBridges()
275
GameMap::deleteInstance();
276
Citylist::deleteInstance();
277
Roadlist::deleteInstance();
278
Ruinlist::deleteInstance();
279
Templelist::deleteInstance();
280
Portlist::deleteInstance();
281
Bridgelist::deleteInstance();
283
GameMap::setWidth(d_width);
284
GameMap::setHeight(d_height);
285
GameMap::getInstance("default", "default", "default")->fill(this);
287
//the game map class smooths the map, so let's take what it smoothed.
288
for (int y = 0; y < d_height; y++)
289
for (int x = 0; x < d_width; x++)
290
d_terrain[y*d_width + x] =
291
GameMap::getInstance()->getTile(x, y)->getMaptileType();
293
//load up the roadlist, and stuff.
295
for (int y = 0; y < d_height; y++)
296
for (int x = 0; x < d_width; x++)
298
if (d_building[y*d_width + x] == Maptile::CITY)
299
Citylist::getInstance()->push_back(new City(Vector<int>(x,y)));
300
else if (d_building[y*d_width + x] == Maptile::ROAD)
301
Roadlist::getInstance()->push_back(new Road(Vector<int>(x,y)));
302
else if (d_building[y*d_width + x] == Maptile::RUIN)
303
Ruinlist::getInstance()->push_back(new Ruin(Vector<int>(x,y)));
304
else if (d_building[y*d_width + x] == Maptile::TEMPLE)
305
Templelist::getInstance()->push_back(new Temple(Vector<int>(x,y)));
306
else if (d_building[y*d_width + x] == Maptile::PORT)
307
Portlist::getInstance()->push_back(new Port(Vector<int>(x,y)));
309
GameMap::getInstance()->calculateBlockedAvenues();
311
Vector<int> src, dest;
312
std::vector<pair<int , Vector<int> > > bridges;
313
bridges = findBridgePlaces();
314
for (std::vector<pair<int, Vector<int> > >::iterator it = bridges.begin();
315
it != bridges.end(); it++)
317
Vector<int> pos = (*it).second + Vector<int>(1,1);
320
if ((*it).first == NORTH_SOUTH_BRIDGE)
322
edge1 = pos - Vector<int>(0, 1);
323
edge2 = pos + Vector<int>(0, 2);
325
else if ((*it).first == EAST_WEST_BRIDGE)
327
edge1 = pos - Vector<int>(1, 0);
328
edge2 = pos + Vector<int>(2, 0);
330
if (offmap(edge1.x, edge1.y) || offmap(edge2.x, edge2.y))
332
if (canPlaceBridge((*it).second + Vector<int>(1,1), (*it).first, src,
335
int leg1 = tryRoad (src, edge1);
336
int leg2 = tryRoad (dest, edge2);
337
int shortcut = tryRoad (src, dest);
338
bool construct_bridge_and_roads = true;
339
if (leg1 <= 0 || leg2 <= 0)
340
construct_bridge_and_roads = false;
341
if (shortcut > 0 && (leg1 + leg2 + 2) > shortcut)
342
construct_bridge_and_roads = false;
344
if (construct_bridge_and_roads)
346
makeRoad(src, edge1);
347
makeRoad(dest, edge2);
348
placeBridge(pos, (*it).first);
351
progress.emit(.950, _("paving bridges..."));
354
Roadlist::deleteInstance();
355
Ruinlist::deleteInstance();
356
Templelist::deleteInstance();
357
GameMap::deleteInstance();
358
Citylist::deleteInstance();
359
Portlist::deleteInstance();
360
Bridgelist::deleteInstance();
363
void MapGenerator::printMap(int j, int i)
366
bool adom_convention=true; // well, except mountains
367
switch(d_terrain[j*d_width + i])
369
case Tile::MOUNTAIN: ch=adom_convention ? 'M' : 'M';break; // mountains
370
case Tile::HILLS : ch=adom_convention ? '~' : 'h';break; // hills
371
case Tile::WATER : ch=adom_convention ? '=' : '~';break; // water
372
case Tile::FOREST : ch=adom_convention ? '&' : '$';break; // forest
373
case Tile::GRASS : ch=adom_convention ? '.' : '.';break; // plains
374
case Tile::SWAMP : ch=adom_convention ? '"' : '_';break; // swamps
375
case Tile::VOID : ch=adom_convention ? '?' : '?';break;
377
// cannot print those, actually because they don't exist in Tile::Type
378
// ch='C';break; // city/castle
379
// ch='r';break; // ruins
380
// ch='T';break; // temple
381
// ch=' ';break; // nothing
382
// ch='c';break; // part of city/castle
387
void MapGenerator::printMap()
389
for(int j = 0; j < d_height; j++)
391
for(int i = 0; i < d_width; i++)
204
398
const Tile::Type* MapGenerator::getMap(int& width, int& height) const
222
416
d_terrain[j*d_width + i] = Tile::GRASS;
419
void MapGenerator::connectWithWater(Vector<int> from, Vector<int> to)
421
Vector<float> delta = from - to;
422
if (dist<float>(from,to) > (float)(d_width*0.4))
423
// we don't want to mess up whole map with straight lines
427
delta /= length(delta)*2;
428
for(Vector<float>path = Vector<float>(from)+delta*4 ; dist<float>(path,Vector<float>(to)-delta*4) > 0.5 ; path -= delta)
430
int j = (int)(path.x);
431
int i = (int)(path.y);
438
if((!(offmap(i,j))) && (!(offmap(i-1,j-1))))
440
d_terrain[(j )*d_width + i ] = Tile::WATER;
441
d_terrain[(j-1)*d_width + i-1] = Tile::WATER;
442
d_terrain[(j )*d_width + i-1] = Tile::WATER;
443
d_terrain[(j-1)*d_width + i ] = Tile::WATER;
447
if((!(offmap(i,j))) && (!(offmap(i+1,j+1))))
449
d_terrain[(j )*d_width + i ] = Tile::WATER;
450
d_terrain[(j+1)*d_width + i+1] = Tile::WATER;
451
d_terrain[(j )*d_width + i+1] = Tile::WATER;
452
d_terrain[(j+1)*d_width + i ] = Tile::WATER;
456
if((!(offmap(i,j))) && (!(offmap(i-1,j+1))))
458
d_terrain[(j )*d_width + i ] = Tile::WATER;
459
d_terrain[(j+1)*d_width + i-1] = Tile::WATER;
460
d_terrain[(j )*d_width + i-1] = Tile::WATER;
461
d_terrain[(j+1)*d_width + i ] = Tile::WATER;
465
if((!(offmap(i,j))) && (!(offmap(i+1,j-1))))
467
d_terrain[(j )*d_width + i ] = Tile::WATER;
468
d_terrain[(j-1)*d_width + i+1] = Tile::WATER;
469
d_terrain[(j )*d_width + i+1] = Tile::WATER;
470
d_terrain[(j-1)*d_width + i ] = Tile::WATER;
476
void MapGenerator::findAreasOf(Tile::Type THIS_TILE,std::vector<std::vector<int> >& box,int& how_many)
478
box.resize(d_height);
479
for(int j = 0; j < d_height; j++)
480
box[j].resize(d_width,0);
482
// find all enclosed areas by scanning the map
483
// distinct areas have different numbers in box
484
for(int j = 1; j < d_height-1; j++)
485
for(int i = 1; i < d_width-1; i++)
487
d_terrain[j*d_width + i] == THIS_TILE &&
489
(d_terrain[(j-1)*d_width + i-1] == THIS_TILE &&
490
d_terrain[(j )*d_width + i-1] == THIS_TILE &&
491
d_terrain[(j-1)*d_width + i ] == THIS_TILE) ||
493
(d_terrain[(j-1)*d_width + i ] == THIS_TILE &&
494
d_terrain[(j-1)*d_width + i+1] == THIS_TILE &&
495
d_terrain[(j )*d_width + i+1] == THIS_TILE) ||
497
(d_terrain[(j )*d_width + i+1] == THIS_TILE &&
498
d_terrain[(j+1)*d_width + i+1] == THIS_TILE &&
499
d_terrain[(j+1)*d_width + i ] == THIS_TILE) ||
501
(d_terrain[(j+1)*d_width + i ] == THIS_TILE &&
502
d_terrain[(j+1)*d_width + i-1] == THIS_TILE &&
503
d_terrain[(j )*d_width + i-1] == THIS_TILE))
506
box[j][i]=++how_many+3000;
511
for(int J = 1; J < d_height-1; J++)
512
for(int I = 1; I < d_width-1; I++)
514
if(d_terrain[J*d_width + I] == THIS_TILE &&
516
(box[J-1][I ]==how_many+3000 ||
517
box[J ][I-1]==how_many+3000 ||
518
box[J ][I+1]==how_many+3000 ||
519
box[J+1][I ]==how_many+3000))
522
box[J][I]=how_many+2000;
525
for(int J = 0; J < d_height; J++)
526
for(int I = 0; I < d_width; I++)
528
if (box[J][I]==how_many+3000)
530
if (box[J][I]==how_many+2000)
531
box[J][I]=how_many+3000;
537
void MapGenerator::verifyIslands()
540
std::vector<std::vector<int> > box;
541
findAreasOf(Tile::GRASS,box,how_many);
543
// count the size of each area
544
std::vector<float> counts;
545
counts.resize(how_many+2,0);
546
for(int j = 0; j < d_height; j++)
547
for(int i = 0; i < d_width; i++)
549
counts[box[j][i]] += 1;
551
// find four largest land areas
552
std::set<int> largest;largest.clear();
554
for(int z=0 ; z<4 ; ++z)
557
for(size_t i=0 ; i<counts.size() ; ++i)
559
if(counts[i] > max && largest.find(counts[i]) == largest.end())
565
// largest are good. Also one/third of all others is good:
566
std::set<int> good(largest);
567
for(size_t i=0 ; i<counts.size() ; ++i)
568
if(rand()%3 == 0) // that's one/third here
569
good.insert(counts[i]);
571
// now, eliminate all land that is not good
572
for(int I=0 ; I<(int)(counts.size()) ; ++I)
573
if(good.find(counts[I]) == good.end())
574
for(int j = 1; j < d_height-1; j++)
575
for(int i = 1; i < d_width-1; i++)
577
d_terrain[j*d_width + i] = Tile::WATER;
580
void MapGenerator::makeRivers()
583
// 1 - plenty of short rivers and islands
584
// 2 - longer rivers, less islands
585
// 3 - even longer rivers, even less islands
586
int river_style=rand()%3+1;
588
// count how many separate bodies of water were found
591
int iter=0; // avoid deadlocks
596
std::vector<std::vector<int> > box;
598
findAreasOf(Tile::WATER,box,how_many);
600
// this loop allows maximum 3 distinctly separated bodies of water
601
// so no need to continue the algorithm
605
// find two biggest bodies of water, and calculate centers for all of them
606
std::vector< Vector<float> > centers;
607
centers.resize(how_many+2,Vector<float>(0,0));
608
std::vector<float> counts;
609
counts.resize(how_many+2,0);
610
for(int j = 0; j < d_height; j++)
611
for(int i = 0; i < d_width; i++)
614
counts[box[j][i]] += 1;
615
centers[box[j][i]] += Vector<float>(j,i);
617
// divide sum by counts to get a center
618
int max_count=0,max_count_2=0;
619
for(int h = 0; h < how_many+2; ++h)
623
centers[h] /= counts[h];
624
if(max_count < (int)(counts[h]))
625
max_count = (int)(counts[h]);
626
if(max_count_2 < (int)(counts[h]) && (int)(counts[h]) != max_count)
627
max_count_2 = (int)(counts[h]);
628
int J=(int)(centers[h].x), I=(int)(centers[h].y);
630
// center doesn't necessarily fall on water tile, so fix this.
632
// // for debugging...
634
int i_up=0,i_dn=0,j_up=0,j_dn=0;
635
while((I+i_up < d_width-1 ) && (box[J ][I+i_up] != h)) ++i_up;
636
while((I-i_dn > 0 ) && (box[J ][I-i_dn] != h)) ++i_dn;
637
while((J+j_up < d_height-1) && (box[J+j_up][I ] != h)) ++j_up;
638
while((J-j_dn > 0 ) && (box[J-j_dn][I ] != h)) ++j_dn;
640
int shortest = std::min( std::min(i_up,i_dn) , std::min(j_up,j_dn));
642
if(shortest == i_up && I+i_up < d_width)
643
centers[h] = Vector<float>( J , I+i_up );
645
if(shortest == i_dn && I-i_dn >= 0 )
646
centers[h] = Vector<float>( J , I-i_dn );
648
if(shortest == j_up && J+j_up < d_height)
649
centers[h] = Vector<float>( J+j_up , I );
651
if(shortest == j_dn && J-j_dn >= 0 )
652
centers[h] = Vector<float>( J+j_dn , I );
655
std::cout << "Sages are wondering about unforeseen mysteries behind the edge of the world.\n";
656
counts[h] = -1; // that's ok, but an interesting case. I'd like to see a map with such water :)
657
// FIXME - can you make a message box here?
658
//MessageBox("Message from author: this is algorithmically a very interesting map, please make screenshot and send to cosurgi@gmail.com");
661
// // for debugging...
662
// box[(int)(centers[h].x)][(int)(centers[h].y)]+=4000;
666
// determine what are the biggest bodies of water here
667
int the_biggest_area=0,second_biggest_area=0;
668
for(int h = 0; h < how_many+2; ++h)
670
if(counts[h]==max_count && max_count != 0)
671
the_biggest_area = h;
672
if(counts[h]==max_count_2 && max_count_2 != 0)
673
second_biggest_area = h;
676
// find shortest distances between areas
677
std::vector<std::vector<std::pair<float, std::pair<Vector<int>, Vector<int> > > > > distances; // I would prefer boost::tuple, but oh well...
678
distances.resize(how_many+2);
679
for(int h = 0; h < how_many+2; ++h)
681
distances[h].resize(how_many+3,std::make_pair(0,std::make_pair(Vector<int>(0,0),Vector<int>(0,0))));
682
for(int k = h+1; k < how_many+2; ++k)
684
if(counts[h] > 0 && counts[k] > 0) // h and k are two different areas
686
// find tile from area h closest to the center of k
687
float min_dist = d_height*d_height;
688
float min_h_j=0,min_h_i=0;
689
for(int j = 1; j < d_height-1; j++)
690
for(int i = 1; i < d_width-1; i++)
693
float dj = j - centers[k].x;
694
float di = i - centers[k].y;
695
float dist = dj*dj + di*di;
704
// then find tile from area k closest to that tile from h
705
min_dist = d_height * d_height;
706
float min_k_j=0,min_k_i=0;
707
for(int j = 1; j < d_height-1; j++)
708
for(int i = 1; i < d_width-1; i++)
711
float dj = j - min_h_j;
712
float di = i - min_h_i;
713
float dist = dj*dj + di*di;
727
float dj = min_k_j - min_h_j;
728
float di = min_k_i - min_h_i;
729
distances[h][k] = std::make_pair(dj*dj + di*di , std::make_pair(Vector<int>(min_h_j,min_h_i) , Vector<int>(min_k_j,min_k_i)) );
735
for(int connect_some_closest=0; connect_some_closest<14; connect_some_closest+=river_style)
737
// if river_style is 1 then
738
// connect 10 closest to each other, and 4 closest to two biggest bodies of water
739
// otherwise skip some - connect fewer of them.
740
int closest_h=-1,closest_k=-1,min=d_height*d_height;
742
if(connect_some_closest < 2 ) start_h=the_biggest_area;
744
if(connect_some_closest < 4) start_h=second_biggest_area;
745
for(int h = start_h; h < ((connect_some_closest >= 4) ? (how_many+2) : start_h+1); ++h)
746
for(int k = h+1; k < how_many+2; ++k)
747
if(counts[h] > 0 && counts[k] > 0)
748
if(distances[h][k].first > 0 && min > distances[h][k].first)
750
min = distances[h][k].first;
754
if (closest_h != -1 &&
757
connectWithWater(distances[closest_h][closest_k].second.first , distances[closest_h][closest_k].second.second);
759
distances[closest_h][closest_k].first = d_height*d_height;
762
// // for debugging... print whole box
763
// std::cerr << how_many << " separate bodies of water found.\n";
764
// std::cerr << the_biggest_area << " is the biggest\n";
765
// std::cerr << second_biggest_area << " is second in size\n";
766
// std::vector<int> a;
767
// BOOST_FOREACH(a,box)
769
// BOOST_FOREACH(int i,a)
772
// std::cout << i << " ";
775
// std::cout << "X" << " ";
778
// std::cout << "%" << " ";
781
// std::cout << "!" << " ";
783
// std::cout << "|" << " ";
785
// std::cout << "\n";
787
// std::cout << "\n";
791
//std::cout << "There are " << how_many << (how_many<4?(std::string(" seas")):(std::string(" lakes"))) << " on this map.\n";
793
//std::cout << "There is 1 sea on this map.\n";
794
//std::cout << "River style was: " << river_style << "\n";
226
799
* Makes Terrains.
227
800
* The algorithm is as follows :
1527
std::vector<pair<int , Vector<int> > > MapGenerator::findBridgePlaces()
1529
std::vector<pair<int , Vector<int> > > result;
1532
for(int j = 1; j < d_height-5; j++)
1533
for(int i = 1; i < d_width-5; i++)
1536
d_terrain[(j )*d_width + i+1] != Tile::WATER &&
1537
d_terrain[(j+1)*d_width + i+1] == Tile::WATER &&
1538
d_terrain[(j+2)*d_width + i+1] == Tile::WATER &&
1539
d_terrain[(j+3)*d_width + i+1] != Tile::WATER &&
1540
d_terrain[(j+1)*d_width + i ] == Tile::WATER &&
1541
d_terrain[(j+2)*d_width + i ] == Tile::WATER &&
1542
d_terrain[(j+1)*d_width + i+2] == Tile::WATER &&
1543
d_terrain[(j+2)*d_width + i+2] == Tile::WATER
1547
(int)(d_terrain[(j )*d_width + i ] == Tile::WATER) +
1548
(int)(d_terrain[(j+1)*d_width + i ] == Tile::WATER) +
1549
(int)(d_terrain[(j+2)*d_width + i ] == Tile::WATER) +
1550
(int)(d_terrain[(j+3)*d_width + i ] == Tile::WATER) +
1551
(int)(d_terrain[(j )*d_width + i-1] == Tile::WATER) +
1552
(int)(d_terrain[(j+1)*d_width + i-1] == Tile::WATER) +
1553
(int)(d_terrain[(j+2)*d_width + i-1] == Tile::WATER) +
1554
(int)(d_terrain[(j+3)*d_width + i-1] == Tile::WATER);
1556
(int)(d_terrain[(j )*d_width + i+2] == Tile::WATER) +
1557
(int)(d_terrain[(j+1)*d_width + i+2] == Tile::WATER) +
1558
(int)(d_terrain[(j+2)*d_width + i+2] == Tile::WATER) +
1559
(int)(d_terrain[(j+3)*d_width + i+2] == Tile::WATER) +
1560
(int)(d_terrain[(j )*d_width + i+3] == Tile::WATER) +
1561
(int)(d_terrain[(j+1)*d_width + i+3] == Tile::WATER) +
1562
(int)(d_terrain[(j+2)*d_width + i+3] == Tile::WATER) +
1563
(int)(d_terrain[(j+3)*d_width + i+3] == Tile::WATER);
1565
if(count_left > 5 && count_right > 5)
1566
result.push_back(std::make_pair(1, Vector<int>(i,j) ));
1569
d_terrain[(j+1)*d_width + i ] != Tile::WATER &&
1570
d_terrain[(j+1)*d_width + i+1] == Tile::WATER &&
1571
d_terrain[(j+1)*d_width + i+2] == Tile::WATER &&
1572
d_terrain[(j+1)*d_width + i+3] != Tile::WATER &&
1573
d_terrain[(j )*d_width + i+1] == Tile::WATER &&
1574
d_terrain[(j )*d_width + i+2] == Tile::WATER &&
1575
d_terrain[(j+2)*d_width + i+1] == Tile::WATER &&
1576
d_terrain[(j+2)*d_width + i+2] == Tile::WATER
1580
(int)(d_terrain[(j )*d_width + i ] == Tile::WATER) +
1581
(int)(d_terrain[(j )*d_width + i+1] == Tile::WATER) +
1582
(int)(d_terrain[(j )*d_width + i+2] == Tile::WATER) +
1583
(int)(d_terrain[(j )*d_width + i+3] == Tile::WATER) +
1584
(int)(d_terrain[(j-1)*d_width + i ] == Tile::WATER) +
1585
(int)(d_terrain[(j-1)*d_width + i+1] == Tile::WATER) +
1586
(int)(d_terrain[(j-1)*d_width + i+2] == Tile::WATER) +
1587
(int)(d_terrain[(j-1)*d_width + i+3] == Tile::WATER);
1590
(int)(d_terrain[(j+2)*d_width + i ] == Tile::WATER) +
1591
(int)(d_terrain[(j+2)*d_width + i+1] == Tile::WATER) +
1592
(int)(d_terrain[(j+2)*d_width + i+2] == Tile::WATER) +
1593
(int)(d_terrain[(j+2)*d_width + i+3] == Tile::WATER) +
1594
(int)(d_terrain[(j+3)*d_width + i ] == Tile::WATER) +
1595
(int)(d_terrain[(j+3)*d_width + i+1] == Tile::WATER) +
1596
(int)(d_terrain[(j+3)*d_width + i+2] == Tile::WATER) +
1597
(int)(d_terrain[(j+3)*d_width + i+3] == Tile::WATER);
1599
if(count_top > 5 && count_bottom > 5)
1600
result.push_back(std::make_pair(2, Vector<int>(i,j) ));
1604
std::random_shuffle(result.begin(),result.end());
1606
// remove those that are too close to each other
1607
std::set<int> bad;bad.clear();
1608
for(size_t r = 0; r<result.size() ; ++r)
1609
for(size_t s = r+1; s<result.size() ; ++s)
1610
if(dist(Vector<float>(result[r].second),Vector<float>(result[s].second)) < 4.5)
1612
std::vector<pair<int , Vector<int> > > filter;filter.clear();
1613
for(size_t r = 0; r<result.size() ; ++r)
1614
if(bad.find(r) == bad.end())
1615
filter.push_back(result[r]);
891
1621
void MapGenerator::makeRoads()
893
1623
GameMap::deleteInstance();
945
1677
Citylist::deleteInstance();
946
1678
Portlist::deleteInstance();
1681
void MapGenerator::rescueLoneTiles(Tile::Type FIND_THIS, Tile::Type REPLACE, bool grow)
1684
memset (box, 0, sizeof (box));
1688
for(int j = 1; j < d_height-1; j++)
1689
for(int i = 1; i < d_width-1; i++)
1691
if (d_terrain[j*d_width + i] == FIND_THIS &&
1692
(d_terrain[(j-1)*d_width + i-1] == FIND_THIS &&
1693
d_terrain[(j )*d_width + i-1] == FIND_THIS &&
1694
d_terrain[(j-1)*d_width + i ] != FIND_THIS))
1695
d_terrain[(j-1)*d_width + i ] = FIND_THIS;
1699
for(int iteration=0; iteration <8 ;++iteration)
1701
for(int j = 0; j < d_height; j++)
1702
for(int i = 0; i < d_width; i++)
1704
if(d_terrain[j*d_width + i] == FIND_THIS)
1706
for (int I = -1; I <= +1; ++I)
1707
for (int J = -1; J <= +1; ++J)
1708
if (!(offmap(i+I,j+J)))
1709
box[J+1][I+1] = (d_terrain[(j+J)*d_width + (i+I)] == d_terrain[j*d_width + i]);
1713
if (!box[0][2] && !box[1][2] && /***********/
1714
/***********/ box[1][1] && box[2][1] &&
1715
!box[0][0] && !box[1][0] /***********/)
1716
d_terrain[j*d_width + i] = REPLACE;
1717
if (/***********/ !box[1][2] && !box[2][2] &&
1718
box[0][1] && box[1][1] && /***********/
1719
/***********/ !box[1][0] && !box[2][0])
1720
d_terrain[j*d_width + i] = REPLACE;
1721
if (!box[0][2] && /***********/ !box[2][2] &&
1722
!box[0][1] && box[1][1] && !box[2][1] &&
1723
/***********/ box[1][0] /***********/)
1724
d_terrain[j*d_width + i] = REPLACE;
1725
if (/***********/ box[1][2] && /***********/
1726
!box[0][1] && box[1][1] && !box[2][1] &&
1727
!box[0][0] && /***********/ !box[2][0])
1728
d_terrain[j*d_width + i] = REPLACE;
1730
if (/***********/ !box[1][2] && /***********/
1731
/***********/ box[1][1] && box[2][1] &&
1732
!box[0][0] && !box[1][0] /***********/)
1733
d_terrain[j*d_width + i] = REPLACE;
1734
if (/***********/ !box[1][2] && /***********/
1735
box[0][1] && box[1][1] && /***********/
1736
/***********/ !box[1][0] && !box[2][0])
1737
d_terrain[j*d_width + i] = REPLACE;
1738
if (/***********/ /***********/ !box[2][2] &&
1739
!box[0][1] && box[1][1] && !box[2][1] &&
1740
/***********/ box[1][0] /***********/)
1741
d_terrain[j*d_width + i] = REPLACE;
1742
if (/***********/ box[1][2] && /***********/
1743
!box[0][1] && box[1][1] && !box[2][1] &&
1744
/***********/ /***********/ !box[2][0])
1745
d_terrain[j*d_width + i] = REPLACE;
1747
if (!box[0][2] && !box[1][2] && /***********/
1748
/***********/ box[1][1] && box[2][1] &&
1749
/***********/ !box[1][0] /***********/)
1750
d_terrain[j*d_width + i] = REPLACE;
1751
if (/***********/ !box[1][2] && !box[2][2] &&
1752
box[0][1] && box[1][1] && /***********/
1753
/***********/ !box[1][0] /***********/)
1754
d_terrain[j*d_width + i] = REPLACE;
1755
if (!box[0][2] && /***********/ /***********/
1756
!box[0][1] && box[1][1] && !box[2][1] &&
1757
/***********/ box[1][0] /***********/)
1758
d_terrain[j*d_width + i] = REPLACE;
1759
if (/***********/ box[1][2] && /***********/
1760
!box[0][1] && box[1][1] && !box[2][1] &&
1761
!box[0][0] /***********/ /***********/)
1762
d_terrain[j*d_width + i] = REPLACE;
1764
if (/***********/ !box[1][2] && /***********/
1765
!box[0][1] && box[1][1] && box[2][1] &&
1766
/***********/ !box[1][0] /***********/)
1767
d_terrain[j*d_width + i] = REPLACE;
1768
if (/***********/ !box[1][2] && /***********/
1769
box[0][1] && box[1][1] && !box[2][1] &&
1770
/***********/ !box[1][0] /***********/)
1771
d_terrain[j*d_width + i] = REPLACE;
1772
if (/***********/ !box[1][2] && /***********/
1773
!box[0][1] && box[1][1] && !box[2][1] &&
1774
/***********/ box[1][0] /***********/)
1775
d_terrain[j*d_width + i] = REPLACE;
1776
if (/***********/ box[1][2] && /***********/
1777
!box[0][1] && box[1][1] && !box[2][1] &&
1778
/***********/ !box[1][0] /***********/)
1779
d_terrain[j*d_width + i] = REPLACE;
1781
if ( box[0][2] && !box[1][2] && /***********/
1782
!box[0][1] && box[1][1] && !box[2][1] &&
1783
/***********/ !box[1][0] /***********/)
1784
d_terrain[j*d_width + i] = REPLACE;
1785
if (/***********/ !box[1][2] && box[2][2] &&
1786
!box[0][1] && box[1][1] && !box[2][1] &&
1787
/***********/ !box[1][0] /***********/)
1788
d_terrain[j*d_width + i] = REPLACE;
1789
if (/***********/ !box[1][2] && /***********/
1790
!box[0][1] && box[1][1] && !box[2][1] &&
1791
box[0][0] && !box[1][0] /***********/)
1792
d_terrain[j*d_width + i] = REPLACE;
1793
if (/***********/ !box[1][2] && /***********/
1794
!box[0][1] && box[1][1] && !box[2][1] &&
1795
/***********/ !box[1][0] && box[2][0])
1796
d_terrain[j*d_width + i] = REPLACE;
1799
if ( box[0][2] && !box[1][2] && box[2][2] &&
1800
box[0][1] && box[1][1] && box[2][1] &&
1801
box[0][0] && !box[1][0] && box[2][0])
1802
d_terrain[j*d_width + i+(rand()%2?+1:-1)] = FIND_THIS;
1803
if ( box[0][2] && box[1][2] && box[2][2] &&
1804
!box[0][1] && box[1][1] && !box[2][1] &&
1805
box[0][0] && box[1][0] && box[2][0])
1806
d_terrain[(j+(rand()%2?+1:-1))*d_width + i] = FIND_THIS;
1808
if ( box[0][2] && !box[1][2] && !box[2][2] &&
1809
box[0][1] && box[1][1] && !box[2][1] &&
1810
!box[0][0] && box[1][0] && box[2][0])
1811
d_terrain[j*d_width + i] = REPLACE;
1812
if (!box[0][2] && !box[1][2] && box[2][2] &&
1813
!box[0][1] && box[1][1] && box[2][1] &&
1814
box[0][0] && box[1][0] && !box[2][0])
1815
d_terrain[j*d_width + i] = REPLACE;
1816
if ( box[0][2] && box[1][2] && !box[2][2] &&
1817
!box[0][1] && box[1][1] && box[2][1] &&
1818
!box[0][0] && !box[1][0] && box[2][0])
1819
d_terrain[j*d_width + i] = REPLACE;
1820
if (!box[0][2] && box[1][2] && box[2][2] &&
1821
box[0][1] && box[1][1] && !box[2][1] &&
1822
box[0][0] && !box[1][0] && !box[2][0])
1823
d_terrain[j*d_width + i] = REPLACE;
1829
void MapGenerator::surroundMountains(int minx, int maxx, int miny, int maxy)
1831
for(int j = miny; j < maxy; j++)
1832
for(int i = minx; i < maxx; i++)
1833
if(d_terrain[j*d_width + i] == Tile::MOUNTAIN)
1834
for(int J = -1; J <= +1; ++J)
1835
for(int I = -1; I <= +1; ++I)
1836
if((!(offmap(i+I,j+J))) &&
1837
(d_terrain[(j+J)*d_width + (i+I)] != Tile::MOUNTAIN))
1839
if(d_terrain[(j+J)*d_width + (i+I)] != Tile::WATER)
1840
d_terrain[(j+J)*d_width + (i+I)] = Tile::HILLS;
1842
// water has priority here, there was some work done to conenct bodies of water
1843
// so don't break those connections.
1844
d_terrain[(j )*d_width + (i )] = Tile::HILLS;