forked from 0ad/0ad
Adds GetCivData to map generator API (to replace the hardcoded starting entities in rmgen).
Adds some starting entities to unfinished civs. This was SVN commit r9901.
This commit is contained in:
parent
17d8807566
commit
813fed5b9e
@ -80,6 +80,20 @@
|
||||
],
|
||||
"StartEntities":
|
||||
[
|
||||
{
|
||||
"Template": "structures/cart_civil_centre"
|
||||
},
|
||||
{
|
||||
"Template": "units/cart_support_female_citizen",
|
||||
"Count": 4
|
||||
},
|
||||
{
|
||||
"Template": "units/cart_infantry_spearman_b",
|
||||
"Count": 4
|
||||
},
|
||||
{
|
||||
"Template": "units/cart_cavalry_swordsman_b"
|
||||
}
|
||||
],
|
||||
"SelectableInGameSetup": false
|
||||
}
|
||||
|
@ -86,6 +86,9 @@
|
||||
],
|
||||
"StartEntities":
|
||||
[
|
||||
{
|
||||
"Template": "structures/pers_civil_centre"
|
||||
}
|
||||
],
|
||||
"SelectableInGameSetup": false
|
||||
}
|
||||
|
@ -91,6 +91,9 @@
|
||||
],
|
||||
"StartEntities":
|
||||
[
|
||||
{
|
||||
"Template": "structures/rome_civil_centre"
|
||||
}
|
||||
],
|
||||
"SelectableInGameSetup": false
|
||||
}
|
||||
|
@ -91,6 +91,7 @@ bool CMapGeneratorWorker::Run()
|
||||
m_ScriptInterface->RegisterFunction<void, CScriptValRooted, CMapGeneratorWorker::ExportMap>("ExportMap");
|
||||
m_ScriptInterface->RegisterFunction<void, int, CMapGeneratorWorker::SetProgress>("SetProgress");
|
||||
m_ScriptInterface->RegisterFunction<void, CMapGeneratorWorker::MaybeGC>("MaybeGC");
|
||||
m_ScriptInterface->RegisterFunction<std::vector<std::string>, CMapGeneratorWorker::GetCivData>("GetCivData");
|
||||
|
||||
// Parse settings
|
||||
CScriptValRooted settingsVal = m_ScriptInterface->ParseJSON(m_Settings);
|
||||
@ -172,6 +173,43 @@ void CMapGeneratorWorker::MaybeGC(void* cbdata)
|
||||
self->m_ScriptInterface->MaybeGC();
|
||||
}
|
||||
|
||||
std::vector<std::string> CMapGeneratorWorker::GetCivData(void* UNUSED(cbdata))
|
||||
{
|
||||
VfsPath path(L"civs/");
|
||||
VfsPaths pathnames;
|
||||
|
||||
std::vector<std::string> data;
|
||||
|
||||
// Load all JSON files in civs directory
|
||||
Status ret = vfs::GetPathnames(g_VFS, path, L"*.json", pathnames);
|
||||
if (ret == INFO::OK)
|
||||
{
|
||||
for (VfsPaths::iterator it = pathnames.begin(); it != pathnames.end(); ++it)
|
||||
{
|
||||
// Load JSON file
|
||||
CVFSFile file;
|
||||
PSRETURN ret = file.Load(g_VFS, *it);
|
||||
if (ret != PSRETURN_OK)
|
||||
{
|
||||
LOGERROR(L"CMapGeneratorWorker::GetCivData: Failed to load file '%ls': %hs", path.string().c_str(), GetErrorString(ret));
|
||||
}
|
||||
else
|
||||
{
|
||||
data.push_back(std::string(file.GetBuffer(), file.GetBuffer() + file.GetBufferSize()));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Some error reading directory
|
||||
wchar_t error[200];
|
||||
LOGERROR(L"CMapGeneratorWorker::GetCivData: Error reading directory '%ls': %ls", path.string().c_str(), StatusDescription(ret, error, ARRAY_SIZE(error)));
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
bool CMapGeneratorWorker::LoadScripts(const std::wstring& libraryName)
|
||||
{
|
||||
// Ignore libraries that are already loaded
|
||||
|
@ -123,6 +123,7 @@ private:
|
||||
static void ExportMap(void* cbdata, CScriptValRooted data);
|
||||
static void SetProgress(void* cbdata, int progress);
|
||||
static void MaybeGC(void* cbdata);
|
||||
static std::vector<std::string> GetCivData(void* cbdata);
|
||||
|
||||
std::set<std::wstring> m_LoadedLibraries;
|
||||
shared_ptr<ScriptInterface::StructuredClone> m_MapData;
|
||||
|
Loading…
Reference in New Issue
Block a user