made it so that castles appearing in the middle of invalid terrain...

...would have islands placed underneath them.

made it so that random map generator generates more scattered, broken-up maps
This commit is contained in:
Dave White 2004-04-12 16:25:39 +00:00
parent 9163a72271
commit 215ce7596f
3 changed files with 80 additions and 15 deletions

View file

@ -24,8 +24,8 @@ min_lake_height=500
lake_size=150
river_frequency=20
temperature_iterations=40
temperature_size=50
temperature_iterations=1000
temperature_size=10
default_convert=g
@ -35,11 +35,11 @@ road_windiness=3
#list of common terrain types which come in at
#different heights, from highest to lowest
[height]
height=600
height=500
terrain=m
[/height]
[height]
height=500
height=400
terrain=h
[/height]
[height]
@ -62,7 +62,7 @@ road_windiness=3
#water at cold temperatures becomes ice
[convert]
min_height=50
max_temperature=150
max_temperature=20
from=cs
to=i
[/convert]
@ -70,14 +70,14 @@ road_windiness=3
#at low temperatures, snow appears
[convert]
min_height=50
max_temperature=100
max_temperature=50
from=gd
to=S
[/convert]
#hills at low temperatures get snow on them
[convert]
max_temperature=100
max_temperature=50
from=h
to=H
[/convert]

View file

@ -390,6 +390,53 @@ bool is_valid_terrain::operator()(int x, int y) const
return std::find(terrain_.begin(),terrain_.end(),map_[x][y]) != terrain_.end();
}
bool expand_island(std::set<gamemap::location>& res, const is_valid_terrain& valid_terrain)
{
std::set<gamemap::location> new_locs;
for(std::set<gamemap::location>::const_iterator i = res.begin(); i != res.end(); ++i) {
gamemap::location adj[6];
get_adjacent_tiles(*i,adj);
for(size_t n = 0; n != 6; ++n) {
new_locs.insert(adj[n]);
}
}
bool result = false;
for(std::set<gamemap::location>::const_iterator j = new_locs.begin(); j != new_locs.end(); ++j) {
if(valid_terrain(j->x,j->y)) {
result = true;
} else {
res.insert(*j);
}
}
return result;
}
//a function that takes the location of a castle, and builds an 'island' around that castle
//if it is not on valid terrain. It will return a set of all locations on which valid terrain
//must be inserted
std::set<gamemap::location> build_island_for_castle(const is_valid_terrain& valid_terrain,
const gamemap::location& loc, int iterations=20)
{
std::set<gamemap::location> res;
if(valid_terrain(loc.x,loc.y)) {
return res;
}
res.insert(loc);
while(iterations > 0) {
const bool should_return = expand_island(res,valid_terrain);
if(should_return) {
break;
}
--iterations;
}
return res;
}
//a function that takes the locations of castles, villages, and the map border,
//and repositions castles to be better located.
//This function runs the castles through an attraction/repulsion system, where
@ -619,7 +666,7 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
//convert grassland terrain to other types of flat terrain.
//we generate a 'temperature map' which uses the height generation algorithm to
//generate the temperature levels all over the map. Then we can use a combination
//of height and terrain to divide flatland up into more interesting types than the default
//of height and terrain to divide terrain up into more interesting types than the default
const height_map temperature_map = generate_height_map(width,height,
atoi(cfg["temperature_iterations"].c_str()),
atoi(cfg["temperature_size"].c_str()),0,0);
@ -898,6 +945,23 @@ std::string default_generate_map(size_t width, size_t height, size_t island_size
if(placing_bad && ntries < max_tries)
continue;
//make sure castles are on valid terrain
for(c = castles.begin(); c != castles.end(); ++c) {
const std::set<gamemap::location>& locs = build_island_for_castle(terrain_tester,*c);
for(std::set<gamemap::location>::const_iterator i = locs.begin(); i != locs.end(); ++i) {
const int x = i->x;
const int y = i->y;
if(x < 0 || y < 0 || size_t(x) >= terrain.size() || size_t(y) >= terrain.front().size()) {
continue;
}
terrain[x][y] = flatland[0];
}
}
//plonk down the castles.
for(c = castles.begin(); c != castles.end(); ++c) {
const int x = c->x;

View file

@ -27,6 +27,7 @@
#include "sound.hpp"
#include "statistics.hpp"
#include "tooltips.hpp"
#include "unit.hpp"
#include "util.hpp"
#include <cmath>
@ -1671,19 +1672,19 @@ void turn_info::recall()
gui::show_dialog(gui_,NULL,"",msg.str());
} else {
std::vector<std::string> options;
for(std::vector<unit>::const_iterator unit = recall_list.begin(); unit != recall_list.end(); ++unit) {
for(std::vector<unit>::const_iterator u = recall_list.begin(); u != recall_list.end(); ++u) {
std::stringstream option;
const std::string& description = unit->description().empty() ? "-" : unit->description();
option << "&" << unit->type().image() << "," << unit->type().language_name() << "," << description << ","
const std::string& description = u->description().empty() ? "-" : u->description();
option << "&" << u->type().image() << "," << u->type().language_name() << "," << description << ","
<< string_table["level"] << ": "
<< unit->type().level() << ","
<< u->type().level() << ","
<< string_table["xp"] << ": "
<< unit->experience() << "/";
<< u->experience() << "/";
if(unit->type().advances_to().empty())
if(u->type().advances_to().empty())
option << "-";
else
option << unit->max_experience();
option << u->max_experience();
options.push_back(option.str());
}