Skip to content

Commit

Permalink
Add Barrens, tweak map generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jt-traub committed Jul 4, 2024
1 parent 9ef8a27 commit 82aa378
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 14 deletions.
4 changes: 4 additions & 0 deletions aregion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3097,6 +3097,10 @@ void placeVolcanoes(ARegionArray* arr, const int w, const int h) {
}
}

void ARegionList::PlaceVolcanos(ARegionArray *arr) {
placeVolcanoes(arr, arr->x, arr->y);
}

int distance(graphs::Location2D a, graphs::Location2D b) {
int dX = std::abs(a.x - b.x);
int dY = std::abs(a.y - b.y);
Expand Down
1 change: 1 addition & 0 deletions aregion.h
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ class ARegionList : public AList
void GrowTerrain(ARegionArray *pArr, int growOcean);
void RandomTerrain(ARegionArray *pArr);
void MakeUWMaze(ARegionArray *pArr);
void PlaceVolcanos(ARegionArray *pArr);
void MakeIslands(ARegionArray *pArr, int nPlayers);
void MakeOneIsland(ARegionArray *pRegs, int xx, int yy);

Expand Down
11 changes: 11 additions & 0 deletions gamedata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4748,6 +4748,17 @@ static TerrainType td[] = {
{-1,-1,-1},
1,I_PIRATES,-1,-1,
5,{O_ISLE,-1,O_OCAVE,-1,-1,-1}},

// Terrain for NO7 (barren)
{"barren", "barrens", "barren", '*', R_BARREN,
TerrainType::BARREN | TerrainType::RIDINGMOUNTS | TerrainType::FLYINGMOUNTS,
0,0,0,1,
{{-1,0,0},{-1,0,0},{-1,0,0},{-1,0,0},
{-1,0,0},{-1,0,0},{-1,0,0}},
{-1,-1,-1,-1},
{-1,-1,-1},
0,-1,-1,-1,
0,{-1,-1,-1,-1,-1,-1}},
};

TerrainType *TerrainDefs = td;
Expand Down
1 change: 1 addition & 0 deletions gamedata.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ enum {
R_CERAN_CHASM1,
R_VOLCANO,
R_LAKE,
R_BARREN,
R_NUM
};

Expand Down
80 changes: 70 additions & 10 deletions neworigins/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1859,8 +1859,19 @@ void ARegionList::CreateIslandRingLevel(int level, int xSize, int ySize, char co
pRegionArrays[level]->SetName(name);
pRegionArrays[level]->levelType = ARegionArray::LEVEL_SURFACE;

MakeRingLand(pRegionArrays[level], 30, 70);
RandomTerrain(pRegionArrays[level]);
MakeRingLand(pRegionArrays[level], 12, 20);

CleanUpWater(pRegionArrays[level]);

SetupAnchors(pRegionArrays[level]);

GrowTerrain(pRegionArrays[level], 0);

AssignTypes(pRegionArrays[level]);

PlaceVolcanos(pRegionArrays[level]);

SeverLandBridges(pRegionArrays[level]);

if (Globals->LAKES) RemoveCoastalLakes(pRegionArrays[level]);
if (Globals->GROW_RACES) GrowRaces(pRegionArrays[level]);
Expand Down Expand Up @@ -2214,19 +2225,68 @@ void ARegionList::MakeRingLand(ARegionArray *pRegs, int minDistance, int maxDist
// By default, everything is ocean
reg->type = R_OCEAN;

// If the regions is between minDistance and maxDistance from the center, default it to land.
// If the regions is between minDistance and maxDistance from the center, 65% chance of being land.
int distance = GetPlanarDistance(center, reg, 1000, -1);
if (distance >= minDistance && distance <= maxDistance) {
bool awayFromEdge = i >= 4 && i <= pRegs->x - 4 && j >= 4 && j <= pRegs->y - 4;
if (distance >= minDistance && distance <= maxDistance && getrandom(100) < 60) {
reg->type = R_NUM;
} else if (distance >= maxDistance && (i > 4 || i <= pRegs->x - 4 || j > 4 || j <= pRegs->y - 4)) {
// If the distance is outside the ring but not too close to the edge, it has a 50% chance of being land.
if (getrandom(100) > 50) reg->type = R_NUM;
} else if (distance < minDistance && distance > 4) {
// If the distance is inside the ring, and not too close to the center, it has a 15% chance of being land.
if (getrandom(100) < 15) reg->type = R_NUM;
} else if (distance >= maxDistance && awayFromEdge && getrandom(100) < 20) {
MakeOneIsland(pRegs, i, j);
} else if (distance < minDistance && distance > 4 && getrandom(100) < 15) {
MakeOneIsland(pRegs, i, j);
}
}
}

Awrite("Perturbing the coastlines");
for (int iter = 0; iter < 10; iter++) {
for (int i = 0; i < pRegs->x; i++) {
for (int j = 0; j < pRegs->y; j++) {
ARegion *reg = pRegs->GetRegion(i, j);
if (!reg) continue;
int distance = GetPlanarDistance(center, reg, 1000, -1);
int different = 0;
for (int d = 0; d < NDIRS; d++) {
ARegion *newreg = reg->neighbors[d];
if (!newreg) continue;
if (newreg->type != reg->type) different++;
}

if (distance <= minDistance + 2 && distance > 3) {
// inner coastline. High chance of land becoming ocean, low chance of ocean becoming land.
// Chance is proportional to neighbors that are different.
if (getrandom(100) < (different * (reg->type == R_NUM ? 2 : 1))) {
reg->wages = -2;
}
} else if (distance >= maxDistance - 1 && i >= 2 && i <= pRegs->x - 2 && j >= 2 && j <= pRegs->y - 2) {
// outer coastline. Moderate chance of ocean becoming land, lower chance of land becoming ocean.
// Chance is proportional to neighbors that are different.
if (getrandom(100) < (different * (reg->type != R_NUM ? 3 : 2))) {
reg->wages = -2;
}
}
}
}
// Apply the changes
for (int i = 0; i < pRegs->x; i++) {
for (int j = 0; j < pRegs->y; j++) {
ARegion *reg = pRegs->GetRegion(i, j);
if (!reg) continue;
// If the region changed type, swap it to the new type and clear the flag.
if (reg->wages == -2) reg->type = (reg->type == R_OCEAN ? R_NUM : R_OCEAN);
reg->wages = -1;
}
}
}

Awrite("Adding the barrens");
center->type = R_BARREN;
for (int d = 0; d < NDIRS; d++) {
ARegion *newreg = center->neighbors[d];
if (!newreg) continue;
newreg->type = R_BARREN;
}

Awrite("");
}

Expand Down
8 changes: 4 additions & 4 deletions neworigins/rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ static GameDefs g = {
100, // TOWNS_NOT_ADJACENT
0, // LESS_ARCTIC_TOWNS
55, // OCEAN
14, // CONTINENT_SIZE
14, // CONTINENT_SIZE
4, // TERRAIN_GRANULARITY
1, // LAKES
5, // LAKES
20, // ARCHIPELAGO
30, // SEVER_LAND_BRIDGES
6, // SEA_LIMIT
6, // SEA_LIMIT
GameDefs::NO_EFFECT, // LAKE_WAGE_EFFECT
0, // LAKESIDE_IS_COASTAL
70, // ODD_TERRAIN
80, // ODD_TERRAIN
1, // IMPROVED_FARSIGHT
1, // GM_REPORT
0, // DECAY
Expand Down

0 comments on commit 82aa378

Please sign in to comment.