Skip to content
Permalink
Browse files

Rework sky definition parsing

This also adds a broken SetSky() script function which was the main
motivation for the rework. See #1827
  • Loading branch information
lluchs committed Oct 15, 2016
1 parent 44b2fda commit 59b5525a410dd223796923ba19a2f566549fe96f
Showing with 28 additions and 14 deletions.
  1. +9 −0 src/game/C4GameScript.cpp
  2. +18 −13 src/landscape/C4Sky.cpp
  3. +1 −1 src/landscape/C4Sky.h
@@ -1667,6 +1667,14 @@ static C4String *FnMaterialName(C4PropList * _this, long iMat)
return String(::MaterialMap.Map[iMat].Name);
}

static bool FnSetSky(C4PropList * _this, C4String * name)
{
if (!name) return false;
auto& sky = ::Landscape.GetSky();
sky.Clear();
return sky.Init(false, name->GetCStr());
}

static bool FnSetSkyAdjust(C4PropList * _this, long dwAdjust, long dwBackClr)
{
// set adjust
@@ -2800,6 +2808,7 @@ void InitGameFunctionMap(C4AulScriptEngine *pEngine)
F(DrawDefMap);
F(CreateParticle);
F(ClearParticles);
F(SetSky);
F(SetSkyAdjust);
F(SetMatAdjust);
F(GetSkyAdjust);
@@ -43,10 +43,8 @@ void C4Sky::SetFadePalette(int32_t *ipColors)
}
}

bool C4Sky::Init(bool fSavegame)
bool C4Sky::Init(bool fSavegame, std::string names)
{
int32_t skylistn;

// reset scrolling pos+speed
// not in savegame, because it will have been loaded from game data there
if (!fSavegame)
@@ -56,25 +54,32 @@ bool C4Sky::Init(bool fSavegame)

// Check for sky bitmap in scenario file
Surface = new C4Surface();
bool loaded = !!Surface->LoadAny(Game.ScenarioFile,C4CFN_Sky,true,true, C4SF_Tileable | C4SF_MipMap);
bool loaded = false;
if (names.empty())
{
loaded = !!Surface->LoadAny(Game.ScenarioFile,C4CFN_Sky,true,true, C4SF_Tileable | C4SF_MipMap);
}

// Else, evaluate scenario core landscape sky default list
if (!loaded)
{
// Scan list sections
SReplaceChar(Game.C4S.Landscape.SkyDef,',',';'); // modifying the C4S here...!
skylistn=SCharCount(';',Game.C4S.Landscape.SkyDef)+1;
char str[402];
SCopySegment(Game.C4S.Landscape.SkyDef,SeededRandom(Game.RandomSeed,skylistn),str,';');
SClearFrontBack(str);
if (names.empty()) names = Game.C4S.Landscape.SkyDef;
static std::regex separator(R"([,;\s]+)");
std::vector<std::string> parts;
std::copy(
std::sregex_token_iterator(names.begin(), names.end(), separator, -1),
std::sregex_token_iterator(),
std::back_inserter(parts));

auto name = parts.at(SeededRandom(Game.RandomSeed, parts.size()));
// Sky tile specified, try load
if (*str && !SEqual(str,"Default"))
if (name != "Default")
{
// Check for sky tile in scenario file
loaded = !!Surface->LoadAny(Game.ScenarioFile,str,true,true, C4SF_Tileable | C4SF_MipMap);
loaded = !!Surface->LoadAny(Game.ScenarioFile, name.c_str(), true, true, C4SF_Tileable | C4SF_MipMap);
if (!loaded)
{
loaded = !!Surface->LoadAny(::GraphicsResource.Files, str, true, false, C4SF_Tileable | C4SF_MipMap);
loaded = !!Surface->LoadAny(::GraphicsResource.Files, name.c_str(), true, false, C4SF_Tileable | C4SF_MipMap);
}
}
}
@@ -33,7 +33,7 @@ class C4Sky
~C4Sky();
void Default(); // zero fields

bool Init(bool fSavegame);
bool Init(bool fSavegame, std::string names = "");
void Clear();
void SetColor(int32_t iIndex, int32_t iRed, int32_t iGreen, int32_t iBlue);
void SetFadePalette(int32_t *ipColors);

0 comments on commit 59b5525

Please sign in to comment.
You can’t perform that action at this time.