This commit is contained in:
Aerll 2018-07-26 14:49:43 +02:00
parent d235036f7d
commit 3c07a2b35b

View file

@ -159,11 +159,11 @@ void CAutoMapper::Load(const char* pTileName)
continue; continue;
} else if(str_length(aOrientation1) > 0) { } else if(str_length(aOrientation1) > 0) {
if(!str_comp(aOrientation1, "XFLIP")) if(!str_comp(aOrientation1, "XFLIP"))
NewIndexInfo.m_Flag = 0 | TILEFLAG_VFLIP; NewIndexInfo.m_Flag = TILEFLAG_VFLIP;
else if(!str_comp(aOrientation1, "YFLIP")) else if(!str_comp(aOrientation1, "YFLIP"))
NewIndexInfo.m_Flag = 0 | TILEFLAG_HFLIP; NewIndexInfo.m_Flag = TILEFLAG_HFLIP;
else if(!str_comp(aOrientation1, "ROTATE")) else if(!str_comp(aOrientation1, "ROTATE"))
NewIndexInfo.m_Flag = 0 | TILEFLAG_ROTATE; NewIndexInfo.m_Flag = TILEFLAG_ROTATE;
else if(!str_comp(aOrientation1, "NONE")) else if(!str_comp(aOrientation1, "NONE"))
NewIndexInfo.m_Flag = 0; NewIndexInfo.m_Flag = 0;
} else { } else {
@ -237,7 +237,7 @@ void CAutoMapper::Load(const char* pTileName)
{ {
pCurrentIndex->m_DefaultRule = false; pCurrentIndex->m_DefaultRule = false;
} }
else if(!str_comp_num(pLine, "NoLayerCopy", 11)) else if(!str_comp_num(pLine, "NoLayerCopy", 11) && pCurrentRun)
{ {
pCurrentRun->m_AutomapCopy = false; pCurrentRun->m_AutomapCopy = false;
} }
@ -297,149 +297,103 @@ void CAutoMapper::Proceed(CLayerTiles *pLayer, int ConfigID)
CConfiguration *pConf = &m_lConfigs[ConfigID]; CConfiguration *pConf = &m_lConfigs[ConfigID];
// for every run: copy tiles, automap, overwrite tiles // for every run: copy tiles, automap, overwrite tiles
// doesn't make copy if it's requested
for(int h = 0; h < pConf->m_aRuns.size(); ++h) { for(int h = 0; h < pConf->m_aRuns.size(); ++h) {
CRun *pRun = &pConf->m_aRuns[h]; CRun *pRun = &pConf->m_aRuns[h];
if (pRun->m_AutomapCopy) { // don't make copy if it's requested
CLayerTiles newLayer(pLayer->m_Width, pLayer->m_Height); CLayerTiles* readLayer;
if (pRun->m_AutomapCopy) {
// copy tiles readLayer = new CLayerTiles(pLayer->m_Width, pLayer->m_Height);
for(int y = 0; y < pLayer->m_Height; y++) { } else {
for(int x = 0; x < pLayer->m_Width; x++) readLayer = pLayer;
{ }
CTile *in = &pLayer->m_pTiles[y*pLayer->m_Width+x];
CTile *out = &newLayer.m_pTiles[y*pLayer->m_Width+x]; // copy tiles
out->m_Index = in->m_Index; if (pRun->m_AutomapCopy) {
out->m_Flags = in->m_Flags; for(int y = 0; y < pLayer->m_Height; y++) {
} for(int x = 0; x < pLayer->m_Width; x++)
} {
CTile *in = &pLayer->m_pTiles[y*pLayer->m_Width+x];
// auto map CTile *out = &readLayer->m_pTiles[y*pLayer->m_Width+x];
for(int y = 0; y < pLayer->m_Height; y++) out->m_Index = in->m_Index;
for(int x = 0; x < pLayer->m_Width; x++) out->m_Flags = in->m_Flags;
{ }
CTile *pTile = &(newLayer.m_pTiles[y*pLayer->m_Width+x]); }
m_pEditor->m_Map.m_Modified = true; }
for(int i = 0; i < pRun->m_aIndexRules.size(); ++i) // auto map
{ for(int y = 0; y < pLayer->m_Height; y++) {
bool RespectRules = true; for(int x = 0; x < pLayer->m_Width; x++)
for(int j = 0; j < pRun->m_aIndexRules[i].m_aRules.size() && RespectRules; ++j) {
{ CTile *pTile = &(readLayer->m_pTiles[y*pLayer->m_Width+x]);
CPosRule *pRule = &pRun->m_aIndexRules[i].m_aRules[j]; m_pEditor->m_Map.m_Modified = true;
int CheckIndex, CheckFlags; for(int i = 0; i < pRun->m_aIndexRules.size(); ++i)
int CheckX = x + pRule->m_X; {
int CheckY = y + pRule->m_Y; bool RespectRules = true;
if(CheckX >= 0 && CheckX < pLayer->m_Width && CheckY >= 0 && CheckY < pLayer->m_Height) { for(int j = 0; j < pRun->m_aIndexRules[i].m_aRules.size() && RespectRules; ++j)
int CheckTile = CheckY * pLayer->m_Width + CheckX; {
CheckIndex = pLayer->m_pTiles[CheckTile].m_Index; CPosRule *pRule = &pRun->m_aIndexRules[i].m_aRules[j];
CheckFlags = pLayer->m_pTiles[CheckTile].m_Flags;
} else { int CheckIndex, CheckFlags;
CheckIndex = -1; int CheckX = x + pRule->m_X;
CheckFlags = 0; int CheckY = y + pRule->m_Y;
} if(CheckX >= 0 && CheckX < pLayer->m_Width && CheckY >= 0 && CheckY < pLayer->m_Height) {
int CheckTile = CheckY * pLayer->m_Width + CheckX;
if(pRule->m_Value == CPosRule::INDEX) CheckIndex = pLayer->m_pTiles[CheckTile].m_Index;
{ CheckFlags = pLayer->m_pTiles[CheckTile].m_Flags;
bool PosRuleTest = false; } else {
for(int i = 0; i < pRule->m_aIndexList.size(); ++i) { CheckIndex = -1;
if(CheckIndex == pRule->m_aIndexList[i].m_ID && (pRule->m_aIndexList[i].m_Flag == -1 || CheckFlags == pRule->m_aIndexList[i].m_Flag)) CheckFlags = 0;
PosRuleTest = true; }
}
if(!PosRuleTest) if(pRule->m_Value == CPosRule::INDEX)
RespectRules = false; {
} bool PosRuleTest = false;
else if(pRule->m_Value == CPosRule::NOTINDEX) for(int i = 0; i < pRule->m_aIndexList.size(); ++i) {
{ if(CheckIndex == pRule->m_aIndexList[i].m_ID && (pRule->m_aIndexList[i].m_Flag == -1 || CheckFlags == pRule->m_aIndexList[i].m_Flag))
bool PosRuleTest = true; PosRuleTest = true;
for(int i = 0; i < pRule->m_aIndexList.size(); ++i) { }
if(CheckIndex == pRule->m_aIndexList[i].m_ID && (pRule->m_aIndexList[i].m_Flag == -1 || CheckFlags == pRule->m_aIndexList[i].m_Flag)) if(!PosRuleTest)
PosRuleTest = false; RespectRules = false;
} }
if(!PosRuleTest) else if(pRule->m_Value == CPosRule::NOTINDEX)
RespectRules = false; {
} bool PosRuleTest = true;
} for(int i = 0; i < pRule->m_aIndexList.size(); ++i) {
if(CheckIndex == pRule->m_aIndexList[i].m_ID && (pRule->m_aIndexList[i].m_Flag == -1 || CheckFlags == pRule->m_aIndexList[i].m_Flag))
if(RespectRules && PosRuleTest = false;
(pRun->m_aIndexRules[i].m_RandomProbability >= 1.0 || (float)rand() / ((float)RAND_MAX + 1) < pRun->m_aIndexRules[i].m_RandomProbability)) }
{ if(!PosRuleTest)
pTile->m_Index = pRun->m_aIndexRules[i].m_ID; RespectRules = false;
pTile->m_Flags = pRun->m_aIndexRules[i].m_Flag == -1 ? 0 : pRun->m_aIndexRules[i].m_Flag; }
} }
}
} if(RespectRules &&
(pRun->m_aIndexRules[i].m_RandomProbability >= 1.0 || (float)rand() / ((float)RAND_MAX + 1) < pRun->m_aIndexRules[i].m_RandomProbability))
// overwrite tiles {
for(int y = 0; y < pLayer->m_Height; y++) { pTile->m_Index = pRun->m_aIndexRules[i].m_ID;
for(int x = 0; x < pLayer->m_Width; x++) pTile->m_Flags = pRun->m_aIndexRules[i].m_Flag;
{ }
CTile *in = &newLayer.m_pTiles[y*pLayer->m_Width+x]; }
CTile *out = &pLayer->m_pTiles[y*pLayer->m_Width+x]; }
out->m_Index = in->m_Index; }
out->m_Flags = in->m_Flags;
} // overwrite tiles
} if (pRun->m_AutomapCopy) {
} for(int y = 0; y < pLayer->m_Height; y++) {
else { for(int x = 0; x < pLayer->m_Width; x++)
// auto map {
for(int y = 0; y < pLayer->m_Height; y++) CTile *in = &readLayer->m_pTiles[y*pLayer->m_Width+x];
for(int x = 0; x < pLayer->m_Width; x++) CTile *out = &pLayer->m_pTiles[y*pLayer->m_Width+x];
{ out->m_Index = in->m_Index;
CTile *pTile = &(pLayer->m_pTiles[y*pLayer->m_Width+x]); out->m_Flags = in->m_Flags;
m_pEditor->m_Map.m_Modified = true; }
}
for(int i = 0; i < pRun->m_aIndexRules.size(); ++i) }
{
bool RespectRules = true; // clean-up
for(int j = 0; j < pRun->m_aIndexRules[i].m_aRules.size() && RespectRules; ++j) if (pRun->m_AutomapCopy)
{ delete readLayer;
CPosRule *pRule = &pRun->m_aIndexRules[i].m_aRules[j];
int CheckIndex, CheckFlags;
int CheckX = x + pRule->m_X;
int CheckY = y + pRule->m_Y;
if(CheckX >= 0 && CheckX < pLayer->m_Width && CheckY >= 0 && CheckY < pLayer->m_Height) {
int CheckTile = CheckY * pLayer->m_Width + CheckX;
CheckIndex = pLayer->m_pTiles[CheckTile].m_Index;
CheckFlags = pLayer->m_pTiles[CheckTile].m_Flags;
} else {
CheckIndex = -1;
CheckFlags = 0;
}
if(pRule->m_Value == CPosRule::INDEX)
{
bool PosRuleTest = false;
for(int i = 0; i < pRule->m_aIndexList.size(); ++i) {
if(CheckIndex == pRule->m_aIndexList[i].m_ID && (pRule->m_aIndexList[i].m_Flag == -1 || CheckFlags == pRule->m_aIndexList[i].m_Flag))
PosRuleTest = true;
}
if(!PosRuleTest)
RespectRules = false;
}
else if(pRule->m_Value == CPosRule::NOTINDEX)
{
bool PosRuleTest = true;
for(int i = 0; i < pRule->m_aIndexList.size(); ++i) {
if(CheckIndex == pRule->m_aIndexList[i].m_ID && (pRule->m_aIndexList[i].m_Flag == -1 || CheckFlags == pRule->m_aIndexList[i].m_Flag))
PosRuleTest = false;
}
if(!PosRuleTest)
RespectRules = false;
}
}
if(RespectRules &&
(pRun->m_aIndexRules[i].m_RandomProbability >= 1.0 || (float)rand() / ((float)RAND_MAX + 1) < pRun->m_aIndexRules[i].m_RandomProbability))
{
pTile->m_Index = pRun->m_aIndexRules[i].m_ID;
pTile->m_Flags = pRun->m_aIndexRules[i].m_Flag == -1 ? 0 : pRun->m_aIndexRules[i].m_Flag;
}
}
}
}
} }
} }