tweak map randomization
This commit is contained in:
parent
2616c95bf3
commit
e1c16e1ef6
4 changed files with 40 additions and 4 deletions
src
|
@ -402,10 +402,25 @@ static void EditorDestroyAllUnits()
|
|||
}
|
||||
}
|
||||
|
||||
static void RandomizeTransition(int x, int y)
|
||||
{
|
||||
CMapField &mf = *Map.Field(x, y);
|
||||
const CTileset &tileset = *Map.Tileset;
|
||||
int baseTileIndex = tileset.tiles[tileset.findTileIndexByTile(mf.getGraphicTile())].tileinfo.BaseTerrain;
|
||||
int mixTerrainIdx = tileset.tiles[tileset.findTileIndexByTile(mf.getGraphicTile())].tileinfo.MixTerrain;
|
||||
if (mixTerrainIdx != 0) {
|
||||
if (rand() % 8 == 0) {
|
||||
// change only in ~12% of cases
|
||||
const int tileIdx = tileset.findTileIndex(rand() % 2 ? baseTileIndex : mixTerrainIdx, 0);
|
||||
EditorChangeTile(Vec2i(x, y), tileIdx, Vec2i(x, y), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
** Create a random map
|
||||
*/
|
||||
void CEditor::CreateRandomMap() const
|
||||
void CEditor::CreateRandomMap(bool shuffleTranslitions) const
|
||||
{
|
||||
const int mz = std::max(Map.Info.MapHeight, Map.Info.MapWidth);
|
||||
|
||||
|
@ -425,6 +440,27 @@ void CEditor::CreateRandomMap() const
|
|||
UI.Minimap.Update();
|
||||
EditorUpdateDisplay();
|
||||
}
|
||||
|
||||
if (shuffleTranslitions) {
|
||||
// shuffle transitions in all directions
|
||||
// from top left to bottom right
|
||||
for (int x = 0; x < Map.Info.MapWidth; x++) {
|
||||
for (int y = 0; y < Map.Info.MapHeight; y++) {
|
||||
RandomizeTransition(x, y);
|
||||
}
|
||||
}
|
||||
UI.Minimap.Update();
|
||||
EditorUpdateDisplay();
|
||||
// from bottom right to top left
|
||||
for (int x = Map.Info.MapWidth - 1; x >= 0; x--) {
|
||||
for (int y = Map.Info.MapHeight - 1; y >= 0; y--) {
|
||||
RandomizeTransition(x, y);
|
||||
}
|
||||
}
|
||||
UI.Minimap.Update();
|
||||
EditorUpdateDisplay();
|
||||
}
|
||||
|
||||
TileToolRandom = oldRandom;
|
||||
|
||||
for (std::tuple<std::string, int, int, int> t : RandomUnits) {
|
||||
|
|
|
@ -69,7 +69,7 @@ public:
|
|||
void Init();
|
||||
|
||||
/// Make random map
|
||||
void CreateRandomMap() const;
|
||||
void CreateRandomMap(bool shuffleTransitions = false) const;
|
||||
/// Variables for random map creation
|
||||
int BaseTileIndex; /// Tile to fill the map with initially;
|
||||
std::vector<std::tuple<int, int, int>> RandomTiles; /// other tiles to fill randomly. (tile, count, area size)
|
||||
|
|
|
@ -170,10 +170,10 @@ public:
|
|||
void parse(lua_State *l);
|
||||
void buildTable(lua_State *l);
|
||||
int parseTilesetTileFlags(lua_State *l, int *back, int *j);
|
||||
int findTileIndex(unsigned char baseTerrain, unsigned char mixTerrain = 0) const;
|
||||
|
||||
private:
|
||||
unsigned int getOrAddSolidTileIndexByName(const std::string &name);
|
||||
int findTileIndex(unsigned char baseTerrain, unsigned char mixTerrain = 0) const;
|
||||
int getTileIndex(unsigned char baseTerrain, unsigned char mixTerrain, unsigned int quad) const;
|
||||
void buildWallReplacementTable();
|
||||
void parseSlots(lua_State *l, int t);
|
||||
|
|
|
@ -14,7 +14,7 @@ class CEditor
|
|||
const CUnitType *StartUnit;
|
||||
bool WriteCompressedMaps;
|
||||
EditorRunningType Running;
|
||||
void CreateRandomMap() const;
|
||||
void CreateRandomMap(bool shuffleTranslitions) const;
|
||||
};
|
||||
|
||||
extern CEditor Editor;
|
||||
|
|
Loading…
Add table
Reference in a new issue