mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Moved roads and rivers to config files.
This also allows adding new ones via mods.
This commit is contained in:
parent
ebe45d512d
commit
09931b6c9d
30
config/rivers.json
Normal file
30
config/rivers.json
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"waterRiver":
|
||||||
|
{
|
||||||
|
"originalRiverId": 1,
|
||||||
|
"code": "rw", //must be 2 characters
|
||||||
|
"animation": "clrrvr",
|
||||||
|
"delta": "clrdelt"
|
||||||
|
},
|
||||||
|
"iceRiver":
|
||||||
|
{
|
||||||
|
"originalRiverId": 2,
|
||||||
|
"code": "ri",
|
||||||
|
"animation": "icyrvr",
|
||||||
|
"delta": "icedelt"
|
||||||
|
},
|
||||||
|
"mudRiver":
|
||||||
|
{
|
||||||
|
"originalRiverId": 3,
|
||||||
|
"code": "rm",
|
||||||
|
"animation": "mudrvr",
|
||||||
|
"delta": "muddelt"
|
||||||
|
},
|
||||||
|
"lavaRiver":
|
||||||
|
{
|
||||||
|
"originalRiverId": 4,
|
||||||
|
"code": "rl",
|
||||||
|
"animation": "lavrvr",
|
||||||
|
"delta": "lavdelt"
|
||||||
|
}
|
||||||
|
}
|
23
config/roads.json
Normal file
23
config/roads.json
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"dirtRoad":
|
||||||
|
{
|
||||||
|
"originalRoadId": 1,
|
||||||
|
"code": "pd", //must be 2 characters
|
||||||
|
"animation": "dirtrd",
|
||||||
|
"moveCost": 75
|
||||||
|
},
|
||||||
|
"gravelRoad":
|
||||||
|
{
|
||||||
|
"originalRoadId": 2,
|
||||||
|
"code": "pg",
|
||||||
|
"animation": "gravrd",
|
||||||
|
"moveCost": 65
|
||||||
|
},
|
||||||
|
"cobblestoneRoad":
|
||||||
|
{
|
||||||
|
"originalRoadId": 3,
|
||||||
|
"code": "pc",
|
||||||
|
"animation": "cobbrd",
|
||||||
|
"moveCost": 50
|
||||||
|
}
|
||||||
|
}
|
@ -859,7 +859,7 @@ namespace Road
|
|||||||
DIRT_ROAD = 1,
|
DIRT_ROAD = 1,
|
||||||
GRAVEL_ROAD = 2,
|
GRAVEL_ROAD = 2,
|
||||||
COBBLESTONE_ROAD = 3,
|
COBBLESTONE_ROAD = 3,
|
||||||
ORIGINAL_ROAD_COUNT = COBBLESTONE_ROAD
|
ORIGINAL_ROAD_COUNT //+1
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -872,7 +872,7 @@ namespace River
|
|||||||
ICY_RIVER = 2,
|
ICY_RIVER = 2,
|
||||||
MUD_RIVER = 3,
|
MUD_RIVER = 3,
|
||||||
LAVA_RIVER = 4,
|
LAVA_RIVER = 4,
|
||||||
ORIGINAL_RIVER_COUNT = LAVA_RIVER
|
ORIGINAL_RIVER_COUNT //+1
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,30 +196,38 @@ TerrainTypeHandler::TerrainTypeHandler()
|
|||||||
|
|
||||||
void TerrainTypeHandler::initRivers()
|
void TerrainTypeHandler::initRivers()
|
||||||
{
|
{
|
||||||
//TODO: load from file?
|
auto allConfigs = VLC->modh->getActiveMods();
|
||||||
|
allConfigs.insert(allConfigs.begin(), "core");
|
||||||
|
|
||||||
const std::vector<std::string> RIVER_DELTA_TEMPLATE_NAME
|
riverTypes.resize(River::ORIGINAL_RIVER_COUNT, nullptr); //make space for original rivers
|
||||||
{
|
riverTypes[River::NO_RIVER] = new RiverType(); //default
|
||||||
{""},
|
|
||||||
{"clrdelt"},
|
|
||||||
{"icedelt"},
|
|
||||||
{"muddelt"},
|
|
||||||
{"lavdelt"}
|
|
||||||
};
|
|
||||||
|
|
||||||
const std::vector<std::pair<std::string, std::string>> RIVER_CONSTANTS =
|
for (auto & mod : allConfigs)
|
||||||
{
|
{
|
||||||
{"", ""},
|
if (!CResourceHandler::get(mod)->existsResource(ResourceID("config/rivers.json")))
|
||||||
{"clrrvr", "rw"},
|
continue;
|
||||||
{"icyrvr", "ri"},
|
|
||||||
{"mudrvr", "rm"},
|
|
||||||
{"lavrvr", "rl"}
|
|
||||||
};
|
|
||||||
|
|
||||||
for (size_t i = 0; i < std::size(RIVER_CONSTANTS); i++)
|
JsonNode rivs(mod, ResourceID("config/rivers.json"));
|
||||||
{
|
for (auto & river : rivs.Struct())
|
||||||
riverTypes.emplace_back(new RiverType(RIVER_CONSTANTS[i].first, RIVER_CONSTANTS[i].second, i));
|
{
|
||||||
riverTypes[i]->deltaName = RIVER_DELTA_TEMPLATE_NAME[i];
|
auto * info = new RiverType();
|
||||||
|
|
||||||
|
info->fileName = river.second["animation"].String();
|
||||||
|
info->code = river.second["code"].String();
|
||||||
|
info->deltaName = river.second["delta"].String();
|
||||||
|
//info->movementCost = river.second["moveCost"].Integer();
|
||||||
|
|
||||||
|
if (!river.second["originalRiverId"].isNull())
|
||||||
|
{
|
||||||
|
info->id = static_cast<TRiver>(river.second["originalRiverId"].Float());
|
||||||
|
riverTypes[info->id] = info;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
info->id = riverTypes.size();
|
||||||
|
riverTypes.push_back(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
recreateRiverMaps();
|
recreateRiverMaps();
|
||||||
@ -227,24 +235,38 @@ void TerrainTypeHandler::initRivers()
|
|||||||
|
|
||||||
void TerrainTypeHandler::initRoads()
|
void TerrainTypeHandler::initRoads()
|
||||||
{
|
{
|
||||||
//TODO: read from config
|
auto allConfigs = VLC->modh->getActiveMods();
|
||||||
|
allConfigs.insert(allConfigs.begin(), "core");
|
||||||
|
|
||||||
const std::vector<std::pair<std::string, std::string>> ROAD_CONSTANTS =
|
roadTypes.resize(Road::ORIGINAL_ROAD_COUNT, nullptr); //make space for original rivers
|
||||||
{
|
roadTypes[Road::NO_ROAD] = new RoadType(); //default
|
||||||
{"", ""},
|
|
||||||
{"dirtrd", "pd"},
|
|
||||||
{"gravrd", "pg"},
|
|
||||||
{"cobbrd", "pc"}
|
|
||||||
};
|
|
||||||
|
|
||||||
for (size_t i = 0; i < std::size(ROAD_CONSTANTS); i++)
|
for (auto & mod : allConfigs)
|
||||||
{
|
{
|
||||||
roadTypes.emplace_back(new RoadType(ROAD_CONSTANTS[i].first, ROAD_CONSTANTS[i].second, i));
|
if (!CResourceHandler::get(mod)->existsResource(ResourceID("config/roads.json")))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
JsonNode rds(mod, ResourceID("config/roads.json"));
|
||||||
|
for (auto & road : rds.Struct())
|
||||||
|
{
|
||||||
|
auto * info = new RoadType();
|
||||||
|
|
||||||
|
info->fileName = road.second["animation"].String();
|
||||||
|
info->code = road.second["code"].String();
|
||||||
|
info->movementCost = static_cast<ui8>(road.second["moveCost"].Float());
|
||||||
|
|
||||||
|
if (!road.second["originalRoadId"].isNull())
|
||||||
|
{
|
||||||
|
info->id = static_cast<TRoad>(road.second["originalRoadId"].Float());
|
||||||
|
roadTypes[info->id] = info;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
info->id = roadTypes.size();
|
||||||
|
roadTypes.push_back(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
roadTypes[1]->movementCost = 75;
|
|
||||||
roadTypes[2]->movementCost = 65;
|
|
||||||
roadTypes[3]->movementCost = 50;
|
|
||||||
|
|
||||||
recreateRoadMaps();
|
recreateRoadMaps();
|
||||||
}
|
}
|
||||||
@ -263,6 +285,9 @@ void TerrainTypeHandler::recreateRiverMaps()
|
|||||||
{
|
{
|
||||||
for (const RiverType * riverInfo : riverTypes)
|
for (const RiverType * riverInfo : riverTypes)
|
||||||
{
|
{
|
||||||
|
if (riverInfo->id == River::NO_RIVER)
|
||||||
|
continue;
|
||||||
|
|
||||||
riverInfoByName[riverInfo->fileName] = riverInfo;
|
riverInfoByName[riverInfo->fileName] = riverInfo;
|
||||||
riverInfoByCode[riverInfo->code] = riverInfo;
|
riverInfoByCode[riverInfo->code] = riverInfo;
|
||||||
riverInfoById[riverInfo->id] = riverInfo;
|
riverInfoById[riverInfo->id] = riverInfo;
|
||||||
@ -273,6 +298,9 @@ void TerrainTypeHandler::recreateRoadMaps()
|
|||||||
{
|
{
|
||||||
for (const RoadType * roadInfo : roadTypes)
|
for (const RoadType * roadInfo : roadTypes)
|
||||||
{
|
{
|
||||||
|
if (roadInfo->id == Road::NO_ROAD)
|
||||||
|
continue;
|
||||||
|
|
||||||
roadInfoByName[roadInfo->fileName] = roadInfo;
|
roadInfoByName[roadInfo->fileName] = roadInfo;
|
||||||
roadInfoByCode[roadInfo->code] = roadInfo;
|
roadInfoByCode[roadInfo->code] = roadInfo;
|
||||||
roadInfoById[roadInfo->id] = roadInfo;
|
roadInfoById[roadInfo->id] = roadInfo;
|
||||||
|
Loading…
Reference in New Issue
Block a user