2022-02-14 23:22:52 +00:00
|
|
|
#include <cinttypes>
|
|
|
|
#include <cstdio> // sscanf
|
2011-07-08 23:09:06 +00:00
|
|
|
|
|
|
|
#include <engine/console.h>
|
|
|
|
#include <engine/shared/linereader.h>
|
2020-09-26 19:41:58 +00:00
|
|
|
#include <engine/storage.h>
|
2011-07-08 23:09:06 +00:00
|
|
|
|
2023-08-28 16:22:01 +00:00
|
|
|
#include <game/mapitems.h>
|
|
|
|
|
2011-07-08 23:09:06 +00:00
|
|
|
#include "auto_map.h"
|
2023-08-28 16:22:01 +00:00
|
|
|
#include "editor.h" // TODO: only needs CLayerTiles
|
2011-07-08 23:09:06 +00:00
|
|
|
|
2018-10-03 16:16:58 +00:00
|
|
|
// Based on triple32inc from https://github.com/skeeto/hash-prospector/tree/79a6074062a84907df6e45b756134b74e2956760
|
|
|
|
static uint32_t HashUInt32(uint32_t Num)
|
|
|
|
{
|
|
|
|
Num++;
|
|
|
|
Num ^= Num >> 17;
|
|
|
|
Num *= 0xed5ad4bbu;
|
|
|
|
Num ^= Num >> 11;
|
|
|
|
Num *= 0xac4c1b51u;
|
|
|
|
Num ^= Num >> 15;
|
|
|
|
Num *= 0x31848babu;
|
|
|
|
Num ^= Num >> 14;
|
|
|
|
return Num;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define HASH_MAX 65536
|
|
|
|
|
|
|
|
static int HashLocation(uint32_t Seed, uint32_t Run, uint32_t Rule, uint32_t X, uint32_t Y)
|
|
|
|
{
|
|
|
|
const uint32_t Prime = 31;
|
|
|
|
uint32_t Hash = 1;
|
|
|
|
Hash = Hash * Prime + HashUInt32(Seed);
|
|
|
|
Hash = Hash * Prime + HashUInt32(Run);
|
|
|
|
Hash = Hash * Prime + HashUInt32(Rule);
|
|
|
|
Hash = Hash * Prime + HashUInt32(X);
|
|
|
|
Hash = Hash * Prime + HashUInt32(Y);
|
|
|
|
Hash = HashUInt32(Hash * Prime); // Just to double-check that values are well-distributed
|
|
|
|
return Hash % HASH_MAX;
|
|
|
|
}
|
|
|
|
|
2011-07-08 23:09:06 +00:00
|
|
|
CAutoMapper::CAutoMapper(CEditor *pEditor)
|
|
|
|
{
|
2023-08-28 16:22:01 +00:00
|
|
|
Init(pEditor);
|
2011-07-08 23:09:06 +00:00
|
|
|
}
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
void CAutoMapper::Load(const char *pTileName)
|
2011-07-08 23:09:06 +00:00
|
|
|
{
|
2023-06-13 15:44:30 +00:00
|
|
|
char aPath[IO_MAX_PATH_LENGTH];
|
2023-08-19 08:36:29 +00:00
|
|
|
str_format(aPath, sizeof(aPath), "editor/automap/%s.rules", pTileName);
|
2023-08-28 16:22:01 +00:00
|
|
|
IOHANDLE RulesFile = Storage()->OpenFile(aPath, IOFLAG_READ | IOFLAG_SKIP_BOM, IStorage::TYPE_ALL);
|
2011-07-08 23:09:06 +00:00
|
|
|
if(!RulesFile)
|
2023-08-19 08:36:29 +00:00
|
|
|
{
|
|
|
|
char aBuf[IO_MAX_PATH_LENGTH + 32];
|
|
|
|
str_format(aBuf, sizeof(aBuf), "failed to load %s", aPath);
|
|
|
|
Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "editor/automap", aBuf);
|
2011-07-08 23:09:06 +00:00
|
|
|
return;
|
2023-08-19 08:36:29 +00:00
|
|
|
}
|
2011-08-11 08:59:14 +00:00
|
|
|
|
2011-07-08 23:09:06 +00:00
|
|
|
CLineReader LineReader;
|
|
|
|
LineReader.Init(RulesFile);
|
2011-08-11 08:59:14 +00:00
|
|
|
|
2022-06-13 16:28:13 +00:00
|
|
|
CConfiguration *pCurrentConf = nullptr;
|
|
|
|
CRun *pCurrentRun = nullptr;
|
|
|
|
CIndexRule *pCurrentIndex = nullptr;
|
2011-08-11 08:59:14 +00:00
|
|
|
|
2011-07-08 23:09:06 +00:00
|
|
|
// read each line
|
|
|
|
while(char *pLine = LineReader.Get())
|
|
|
|
{
|
|
|
|
// skip blank/empty lines as well as comments
|
2020-09-26 19:41:58 +00:00
|
|
|
if(str_length(pLine) > 0 && pLine[0] != '#' && pLine[0] != '\n' && pLine[0] != '\r' && pLine[0] != '\t' && pLine[0] != '\v' && pLine[0] != ' ')
|
2011-07-08 23:09:06 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
if(pLine[0] == '[')
|
2011-07-08 23:09:06 +00:00
|
|
|
{
|
|
|
|
// new configuration, get the name
|
|
|
|
pLine++;
|
|
|
|
CConfiguration NewConf;
|
2020-05-23 16:11:32 +00:00
|
|
|
NewConf.m_aName[0] = '\0';
|
2018-10-04 13:26:41 +00:00
|
|
|
NewConf.m_StartX = 0;
|
|
|
|
NewConf.m_StartY = 0;
|
|
|
|
NewConf.m_EndX = 0;
|
|
|
|
NewConf.m_EndY = 0;
|
2022-06-11 19:38:18 +00:00
|
|
|
m_vConfigs.push_back(NewConf);
|
|
|
|
int ConfigurationID = m_vConfigs.size() - 1;
|
|
|
|
pCurrentConf = &m_vConfigs[ConfigurationID];
|
2023-06-13 15:44:30 +00:00
|
|
|
str_copy(pCurrentConf->m_aName, pLine, minimum<int>(sizeof(pCurrentConf->m_aName), str_length(pLine)));
|
2015-02-19 23:15:09 +00:00
|
|
|
|
|
|
|
// add start run
|
|
|
|
CRun NewRun;
|
2018-07-19 15:09:29 +00:00
|
|
|
NewRun.m_AutomapCopy = true;
|
2022-06-11 19:38:18 +00:00
|
|
|
pCurrentConf->m_vRuns.push_back(NewRun);
|
|
|
|
int RunID = pCurrentConf->m_vRuns.size() - 1;
|
|
|
|
pCurrentRun = &pCurrentConf->m_vRuns[RunID];
|
2011-07-08 23:09:06 +00:00
|
|
|
}
|
2020-10-12 16:50:23 +00:00
|
|
|
else if(str_startswith(pLine, "NewRun") && pCurrentConf)
|
2011-07-08 23:09:06 +00:00
|
|
|
{
|
2015-02-19 23:15:09 +00:00
|
|
|
// add new run
|
|
|
|
CRun NewRun;
|
2018-07-19 15:09:29 +00:00
|
|
|
NewRun.m_AutomapCopy = true;
|
2022-06-11 19:38:18 +00:00
|
|
|
pCurrentConf->m_vRuns.push_back(NewRun);
|
|
|
|
int RunID = pCurrentConf->m_vRuns.size() - 1;
|
|
|
|
pCurrentRun = &pCurrentConf->m_vRuns[RunID];
|
2015-02-19 23:15:09 +00:00
|
|
|
}
|
2018-07-25 08:29:05 +00:00
|
|
|
else if(str_startswith(pLine, "Index") && pCurrentRun)
|
2015-02-19 23:15:09 +00:00
|
|
|
{
|
|
|
|
// new index
|
|
|
|
int ID = 0;
|
|
|
|
char aOrientation1[128] = "";
|
|
|
|
char aOrientation2[128] = "";
|
|
|
|
char aOrientation3[128] = "";
|
2011-08-11 08:59:14 +00:00
|
|
|
|
2015-02-19 23:15:09 +00:00
|
|
|
sscanf(pLine, "Index %d %127s %127s %127s", &ID, aOrientation1, aOrientation2, aOrientation3);
|
2013-12-27 17:32:58 +00:00
|
|
|
|
2015-02-19 23:15:09 +00:00
|
|
|
CIndexRule NewIndexRule;
|
|
|
|
NewIndexRule.m_ID = ID;
|
|
|
|
NewIndexRule.m_Flag = 0;
|
2019-07-08 21:08:42 +00:00
|
|
|
NewIndexRule.m_RandomProbability = 1.0f;
|
2015-02-19 23:15:09 +00:00
|
|
|
NewIndexRule.m_DefaultRule = true;
|
2019-04-26 19:36:49 +00:00
|
|
|
NewIndexRule.m_SkipEmpty = false;
|
2018-08-11 01:01:25 +00:00
|
|
|
NewIndexRule.m_SkipFull = false;
|
2014-09-27 08:11:28 +00:00
|
|
|
|
2015-02-19 23:15:09 +00:00
|
|
|
if(str_length(aOrientation1) > 0)
|
|
|
|
{
|
|
|
|
if(!str_comp(aOrientation1, "XFLIP"))
|
2022-12-19 17:28:08 +00:00
|
|
|
NewIndexRule.m_Flag |= TILEFLAG_XFLIP;
|
2015-02-19 23:15:09 +00:00
|
|
|
else if(!str_comp(aOrientation1, "YFLIP"))
|
2022-12-19 17:28:08 +00:00
|
|
|
NewIndexRule.m_Flag |= TILEFLAG_YFLIP;
|
2015-02-19 23:15:09 +00:00
|
|
|
else if(!str_comp(aOrientation1, "ROTATE"))
|
|
|
|
NewIndexRule.m_Flag |= TILEFLAG_ROTATE;
|
|
|
|
}
|
2011-08-11 08:59:14 +00:00
|
|
|
|
2015-02-19 23:15:09 +00:00
|
|
|
if(str_length(aOrientation2) > 0)
|
|
|
|
{
|
|
|
|
if(!str_comp(aOrientation2, "XFLIP"))
|
2022-12-19 17:28:08 +00:00
|
|
|
NewIndexRule.m_Flag |= TILEFLAG_XFLIP;
|
2015-02-19 23:15:09 +00:00
|
|
|
else if(!str_comp(aOrientation2, "YFLIP"))
|
2022-12-19 17:28:08 +00:00
|
|
|
NewIndexRule.m_Flag |= TILEFLAG_YFLIP;
|
2015-02-19 23:15:09 +00:00
|
|
|
else if(!str_comp(aOrientation2, "ROTATE"))
|
|
|
|
NewIndexRule.m_Flag |= TILEFLAG_ROTATE;
|
2011-07-08 23:09:06 +00:00
|
|
|
}
|
2015-02-19 23:15:09 +00:00
|
|
|
|
|
|
|
if(str_length(aOrientation3) > 0)
|
2011-07-08 23:09:06 +00:00
|
|
|
{
|
2015-02-19 23:15:09 +00:00
|
|
|
if(!str_comp(aOrientation3, "XFLIP"))
|
2022-12-19 17:28:08 +00:00
|
|
|
NewIndexRule.m_Flag |= TILEFLAG_XFLIP;
|
2015-02-19 23:15:09 +00:00
|
|
|
else if(!str_comp(aOrientation3, "YFLIP"))
|
2022-12-19 17:28:08 +00:00
|
|
|
NewIndexRule.m_Flag |= TILEFLAG_YFLIP;
|
2015-02-19 23:15:09 +00:00
|
|
|
else if(!str_comp(aOrientation3, "ROTATE"))
|
|
|
|
NewIndexRule.m_Flag |= TILEFLAG_ROTATE;
|
|
|
|
}
|
2011-08-11 08:59:14 +00:00
|
|
|
|
2015-02-19 23:15:09 +00:00
|
|
|
// add the index rule object and make it current
|
2022-06-11 19:38:18 +00:00
|
|
|
pCurrentRun->m_vIndexRules.push_back(NewIndexRule);
|
|
|
|
int IndexRuleID = pCurrentRun->m_vIndexRules.size() - 1;
|
|
|
|
pCurrentIndex = &pCurrentRun->m_vIndexRules[IndexRuleID];
|
2015-02-19 23:15:09 +00:00
|
|
|
}
|
2018-07-25 08:29:05 +00:00
|
|
|
else if(str_startswith(pLine, "Pos") && pCurrentIndex)
|
2015-02-19 23:15:09 +00:00
|
|
|
{
|
|
|
|
int x = 0, y = 0;
|
|
|
|
char aValue[128];
|
|
|
|
int Value = CPosRule::NORULE;
|
2022-06-15 17:34:41 +00:00
|
|
|
std::vector<CIndexInfo> vNewIndexList;
|
2011-08-11 08:59:14 +00:00
|
|
|
|
2015-02-19 23:15:09 +00:00
|
|
|
sscanf(pLine, "Pos %d %d %127s", &x, &y, aValue);
|
2015-02-19 21:54:47 +00:00
|
|
|
|
2015-02-19 23:15:09 +00:00
|
|
|
if(!str_comp(aValue, "EMPTY"))
|
|
|
|
{
|
2015-03-04 15:03:52 +00:00
|
|
|
Value = CPosRule::INDEX;
|
2018-08-09 21:45:04 +00:00
|
|
|
CIndexInfo NewIndexInfo = {0, 0, false};
|
2022-06-15 17:34:41 +00:00
|
|
|
vNewIndexList.push_back(NewIndexInfo);
|
2015-02-19 23:15:09 +00:00
|
|
|
}
|
|
|
|
else if(!str_comp(aValue, "FULL"))
|
|
|
|
{
|
2015-03-04 15:03:52 +00:00
|
|
|
Value = CPosRule::NOTINDEX;
|
2018-08-09 21:45:04 +00:00
|
|
|
CIndexInfo NewIndexInfo1 = {0, 0, false};
|
2015-07-09 17:17:46 +00:00
|
|
|
//CIndexInfo NewIndexInfo2 = {-1, 0};
|
2022-06-15 17:34:41 +00:00
|
|
|
vNewIndexList.push_back(NewIndexInfo1);
|
|
|
|
//vNewIndexList.push_back(NewIndexInfo2);
|
2015-02-19 23:15:09 +00:00
|
|
|
}
|
|
|
|
else if(!str_comp(aValue, "INDEX") || !str_comp(aValue, "NOTINDEX"))
|
|
|
|
{
|
|
|
|
if(!str_comp(aValue, "INDEX"))
|
|
|
|
Value = CPosRule::INDEX;
|
|
|
|
else
|
|
|
|
Value = CPosRule::NOTINDEX;
|
|
|
|
|
|
|
|
int pWord = 4;
|
2020-09-26 19:41:58 +00:00
|
|
|
while(true)
|
|
|
|
{
|
2015-02-19 23:15:09 +00:00
|
|
|
int ID = 0;
|
|
|
|
char aOrientation1[128] = "";
|
|
|
|
char aOrientation2[128] = "";
|
|
|
|
char aOrientation3[128] = "";
|
|
|
|
char aOrientation4[128] = "";
|
|
|
|
sscanf(str_trim_words(pLine, pWord), "%d %127s %127s %127s %127s", &ID, aOrientation1, aOrientation2, aOrientation3, aOrientation4);
|
|
|
|
|
|
|
|
CIndexInfo NewIndexInfo;
|
|
|
|
NewIndexInfo.m_ID = ID;
|
2018-08-09 21:45:04 +00:00
|
|
|
NewIndexInfo.m_Flag = 0;
|
|
|
|
NewIndexInfo.m_TestFlag = false;
|
2015-02-19 23:15:09 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(!str_comp(aOrientation1, "OR"))
|
|
|
|
{
|
2022-06-15 17:34:41 +00:00
|
|
|
vNewIndexList.push_back(NewIndexInfo);
|
2015-02-19 23:15:09 +00:00
|
|
|
pWord += 2;
|
|
|
|
continue;
|
2020-09-26 19:41:58 +00:00
|
|
|
}
|
|
|
|
else if(str_length(aOrientation1) > 0)
|
|
|
|
{
|
2018-08-09 21:45:04 +00:00
|
|
|
NewIndexInfo.m_TestFlag = true;
|
2015-02-19 23:15:09 +00:00
|
|
|
if(!str_comp(aOrientation1, "XFLIP"))
|
2022-12-19 17:28:08 +00:00
|
|
|
NewIndexInfo.m_Flag = TILEFLAG_XFLIP;
|
2015-02-19 23:15:09 +00:00
|
|
|
else if(!str_comp(aOrientation1, "YFLIP"))
|
2022-12-19 17:28:08 +00:00
|
|
|
NewIndexInfo.m_Flag = TILEFLAG_YFLIP;
|
2015-02-19 23:15:09 +00:00
|
|
|
else if(!str_comp(aOrientation1, "ROTATE"))
|
2018-07-26 12:49:43 +00:00
|
|
|
NewIndexInfo.m_Flag = TILEFLAG_ROTATE;
|
2018-07-19 15:09:29 +00:00
|
|
|
else if(!str_comp(aOrientation1, "NONE"))
|
|
|
|
NewIndexInfo.m_Flag = 0;
|
2018-08-09 21:45:04 +00:00
|
|
|
else
|
|
|
|
NewIndexInfo.m_TestFlag = false;
|
2020-09-26 19:41:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-06-15 17:34:41 +00:00
|
|
|
vNewIndexList.push_back(NewIndexInfo);
|
2015-02-19 23:15:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-02-19 21:54:47 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(!str_comp(aOrientation2, "OR"))
|
|
|
|
{
|
2022-06-15 17:34:41 +00:00
|
|
|
vNewIndexList.push_back(NewIndexInfo);
|
2015-02-19 23:15:09 +00:00
|
|
|
pWord += 3;
|
|
|
|
continue;
|
2020-09-26 19:41:58 +00:00
|
|
|
}
|
|
|
|
else if(str_length(aOrientation2) > 0 && NewIndexInfo.m_Flag != 0)
|
|
|
|
{
|
2015-02-19 23:15:09 +00:00
|
|
|
if(!str_comp(aOrientation2, "XFLIP"))
|
2022-12-19 17:28:08 +00:00
|
|
|
NewIndexInfo.m_Flag |= TILEFLAG_XFLIP;
|
2015-02-19 23:15:09 +00:00
|
|
|
else if(!str_comp(aOrientation2, "YFLIP"))
|
2022-12-19 17:28:08 +00:00
|
|
|
NewIndexInfo.m_Flag |= TILEFLAG_YFLIP;
|
2015-02-19 23:15:09 +00:00
|
|
|
else if(!str_comp(aOrientation2, "ROTATE"))
|
|
|
|
NewIndexInfo.m_Flag |= TILEFLAG_ROTATE;
|
2020-09-26 19:41:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-06-15 17:34:41 +00:00
|
|
|
vNewIndexList.push_back(NewIndexInfo);
|
2015-02-19 23:15:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-02-19 21:54:47 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(!str_comp(aOrientation3, "OR"))
|
|
|
|
{
|
2022-06-15 17:34:41 +00:00
|
|
|
vNewIndexList.push_back(NewIndexInfo);
|
2015-02-19 23:15:09 +00:00
|
|
|
pWord += 4;
|
|
|
|
continue;
|
2020-09-26 19:41:58 +00:00
|
|
|
}
|
|
|
|
else if(str_length(aOrientation3) > 0 && NewIndexInfo.m_Flag != 0)
|
|
|
|
{
|
2015-02-19 23:15:09 +00:00
|
|
|
if(!str_comp(aOrientation3, "XFLIP"))
|
2022-12-19 17:28:08 +00:00
|
|
|
NewIndexInfo.m_Flag |= TILEFLAG_XFLIP;
|
2015-02-19 23:15:09 +00:00
|
|
|
else if(!str_comp(aOrientation3, "YFLIP"))
|
2022-12-19 17:28:08 +00:00
|
|
|
NewIndexInfo.m_Flag |= TILEFLAG_YFLIP;
|
2015-02-19 23:15:09 +00:00
|
|
|
else if(!str_comp(aOrientation3, "ROTATE"))
|
|
|
|
NewIndexInfo.m_Flag |= TILEFLAG_ROTATE;
|
2020-09-26 19:41:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-06-15 17:34:41 +00:00
|
|
|
vNewIndexList.push_back(NewIndexInfo);
|
2015-02-19 23:15:09 +00:00
|
|
|
break;
|
2015-02-19 21:54:47 +00:00
|
|
|
}
|
2011-07-08 23:09:06 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(!str_comp(aOrientation4, "OR"))
|
|
|
|
{
|
2022-06-15 17:34:41 +00:00
|
|
|
vNewIndexList.push_back(NewIndexInfo);
|
2015-02-19 23:15:09 +00:00
|
|
|
pWord += 5;
|
|
|
|
continue;
|
2020-09-26 19:41:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-06-15 17:34:41 +00:00
|
|
|
vNewIndexList.push_back(NewIndexInfo);
|
2015-02-19 23:15:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-02-19 21:54:47 +00:00
|
|
|
}
|
2011-07-08 23:09:06 +00:00
|
|
|
}
|
2015-02-19 23:15:09 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(Value != CPosRule::NORULE)
|
|
|
|
{
|
2022-06-15 17:34:41 +00:00
|
|
|
CPosRule NewPosRule = {x, y, Value, vNewIndexList};
|
2022-06-11 19:38:18 +00:00
|
|
|
pCurrentIndex->m_vRules.push_back(NewPosRule);
|
2018-08-11 01:01:25 +00:00
|
|
|
|
2019-04-26 19:36:49 +00:00
|
|
|
pCurrentConf->m_StartX = minimum(pCurrentConf->m_StartX, NewPosRule.m_X);
|
|
|
|
pCurrentConf->m_StartY = minimum(pCurrentConf->m_StartY, NewPosRule.m_Y);
|
|
|
|
pCurrentConf->m_EndX = maximum(pCurrentConf->m_EndX, NewPosRule.m_X);
|
|
|
|
pCurrentConf->m_EndY = maximum(pCurrentConf->m_EndY, NewPosRule.m_Y);
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(x == 0 && y == 0)
|
|
|
|
{
|
2022-06-15 17:34:41 +00:00
|
|
|
for(const auto &Index : vNewIndexList)
|
2019-04-26 19:36:49 +00:00
|
|
|
{
|
2022-05-24 09:24:33 +00:00
|
|
|
if(Value == CPosRule::INDEX && Index.m_ID == 0)
|
2019-04-26 19:36:49 +00:00
|
|
|
pCurrentIndex->m_SkipFull = true;
|
|
|
|
else
|
|
|
|
pCurrentIndex->m_SkipEmpty = true;
|
|
|
|
}
|
2018-08-11 01:01:25 +00:00
|
|
|
}
|
2014-09-20 18:57:29 +00:00
|
|
|
}
|
2011-07-08 23:09:06 +00:00
|
|
|
}
|
2018-07-25 08:29:05 +00:00
|
|
|
else if(str_startswith(pLine, "Random") && pCurrentIndex)
|
2015-02-19 23:15:09 +00:00
|
|
|
{
|
2018-07-24 18:41:36 +00:00
|
|
|
float Value;
|
|
|
|
char Specifier = ' ';
|
|
|
|
sscanf(pLine, "Random %f%c", &Value, &Specifier);
|
|
|
|
if(Specifier == '%')
|
|
|
|
{
|
2019-07-08 21:08:42 +00:00
|
|
|
pCurrentIndex->m_RandomProbability = Value / 100.0f;
|
2018-07-24 18:41:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-08 21:08:42 +00:00
|
|
|
pCurrentIndex->m_RandomProbability = 1.0f / Value;
|
2018-07-24 18:41:36 +00:00
|
|
|
}
|
2015-02-19 23:15:09 +00:00
|
|
|
}
|
2018-07-25 08:29:05 +00:00
|
|
|
else if(str_startswith(pLine, "NoDefaultRule") && pCurrentIndex)
|
2015-02-19 23:15:09 +00:00
|
|
|
{
|
|
|
|
pCurrentIndex->m_DefaultRule = false;
|
|
|
|
}
|
2019-07-31 19:19:25 +00:00
|
|
|
else if(str_startswith(pLine, "NoLayerCopy") && pCurrentRun)
|
2018-07-19 15:09:29 +00:00
|
|
|
{
|
|
|
|
pCurrentRun->m_AutomapCopy = false;
|
|
|
|
}
|
2011-07-08 23:09:06 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-11 08:59:14 +00:00
|
|
|
|
2013-12-28 00:09:47 +00:00
|
|
|
// add default rule for Pos 0 0 if there is none
|
2022-06-11 19:38:18 +00:00
|
|
|
for(auto &Config : m_vConfigs)
|
2013-12-28 00:09:47 +00:00
|
|
|
{
|
2022-06-11 19:38:18 +00:00
|
|
|
for(auto &Run : Config.m_vRuns)
|
2013-12-28 00:09:47 +00:00
|
|
|
{
|
2022-06-11 19:38:18 +00:00
|
|
|
for(auto &IndexRule : Run.m_vIndexRules)
|
2013-12-28 00:09:47 +00:00
|
|
|
{
|
2015-02-19 23:15:09 +00:00
|
|
|
bool Found = false;
|
2022-06-11 19:38:18 +00:00
|
|
|
for(const auto &Rule : IndexRule.m_vRules)
|
2013-12-28 12:59:14 +00:00
|
|
|
{
|
2022-05-24 09:24:33 +00:00
|
|
|
if(Rule.m_X == 0 && Rule.m_Y == 0)
|
2015-02-19 23:15:09 +00:00
|
|
|
{
|
|
|
|
Found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-05-24 09:24:33 +00:00
|
|
|
if(!Found && IndexRule.m_DefaultRule)
|
2015-02-19 23:15:09 +00:00
|
|
|
{
|
2022-06-15 17:34:41 +00:00
|
|
|
std::vector<CIndexInfo> vNewIndexList;
|
2018-08-09 21:45:04 +00:00
|
|
|
CIndexInfo NewIndexInfo = {0, 0, false};
|
2022-06-15 17:34:41 +00:00
|
|
|
vNewIndexList.push_back(NewIndexInfo);
|
|
|
|
CPosRule NewPosRule = {0, 0, CPosRule::NOTINDEX, vNewIndexList};
|
2022-06-11 19:38:18 +00:00
|
|
|
IndexRule.m_vRules.push_back(NewPosRule);
|
2019-04-26 19:36:49 +00:00
|
|
|
|
2022-05-24 09:24:33 +00:00
|
|
|
IndexRule.m_SkipEmpty = true;
|
|
|
|
IndexRule.m_SkipFull = false;
|
2019-04-26 19:36:49 +00:00
|
|
|
}
|
2022-05-24 09:24:33 +00:00
|
|
|
if(IndexRule.m_SkipEmpty && IndexRule.m_SkipFull)
|
2019-04-26 19:36:49 +00:00
|
|
|
{
|
2022-05-24 09:24:33 +00:00
|
|
|
IndexRule.m_SkipEmpty = false;
|
|
|
|
IndexRule.m_SkipFull = false;
|
2013-12-28 12:59:14 +00:00
|
|
|
}
|
2013-12-28 00:09:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-08 23:09:06 +00:00
|
|
|
io_close(RulesFile);
|
2011-08-11 08:59:14 +00:00
|
|
|
|
2023-06-13 15:44:30 +00:00
|
|
|
char aBuf[IO_MAX_PATH_LENGTH + 16];
|
2020-09-26 19:41:58 +00:00
|
|
|
str_format(aBuf, sizeof(aBuf), "loaded %s", aPath);
|
2023-08-28 16:22:01 +00:00
|
|
|
Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "editor/automap", aBuf);
|
2011-08-11 08:59:14 +00:00
|
|
|
|
2011-07-08 23:09:06 +00:00
|
|
|
m_FileLoaded = true;
|
|
|
|
}
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
const char *CAutoMapper::GetConfigName(int Index)
|
2011-07-08 23:09:06 +00:00
|
|
|
{
|
2022-06-11 19:38:18 +00:00
|
|
|
if(Index < 0 || Index >= (int)m_vConfigs.size())
|
2011-07-08 23:09:06 +00:00
|
|
|
return "";
|
|
|
|
|
2022-06-11 19:38:18 +00:00
|
|
|
return m_vConfigs[Index].m_aName;
|
2011-07-08 23:09:06 +00:00
|
|
|
}
|
|
|
|
|
2018-10-04 13:26:41 +00:00
|
|
|
void CAutoMapper::ProceedLocalized(CLayerTiles *pLayer, int ConfigID, int Seed, int X, int Y, int Width, int Height)
|
|
|
|
{
|
2022-06-11 19:38:18 +00:00
|
|
|
if(!m_FileLoaded || pLayer->m_Readonly || ConfigID < 0 || ConfigID >= (int)m_vConfigs.size())
|
2018-10-04 13:26:41 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if(Width < 0)
|
|
|
|
Width = pLayer->m_Width;
|
|
|
|
|
|
|
|
if(Height < 0)
|
|
|
|
Height = pLayer->m_Height;
|
|
|
|
|
2022-06-11 19:38:18 +00:00
|
|
|
CConfiguration *pConf = &m_vConfigs[ConfigID];
|
2018-10-04 13:26:41 +00:00
|
|
|
|
2019-01-10 14:39:11 +00:00
|
|
|
int CommitFromX = clamp(X + pConf->m_StartX, 0, pLayer->m_Width);
|
|
|
|
int CommitFromY = clamp(Y + pConf->m_StartY, 0, pLayer->m_Height);
|
|
|
|
int CommitToX = clamp(X + Width + pConf->m_EndX, 0, pLayer->m_Width);
|
|
|
|
int CommitToY = clamp(Y + Height + pConf->m_EndY, 0, pLayer->m_Height);
|
|
|
|
|
|
|
|
int UpdateFromX = clamp(X + 3 * pConf->m_StartX, 0, pLayer->m_Width);
|
|
|
|
int UpdateFromY = clamp(Y + 3 * pConf->m_StartY, 0, pLayer->m_Height);
|
|
|
|
int UpdateToX = clamp(X + Width + 3 * pConf->m_EndX, 0, pLayer->m_Width);
|
|
|
|
int UpdateToY = clamp(Y + Height + 3 * pConf->m_EndY, 0, pLayer->m_Height);
|
2018-10-04 13:26:41 +00:00
|
|
|
|
2023-09-05 13:16:41 +00:00
|
|
|
CLayerTiles *pUpdateLayer = new CLayerTiles(Editor(), UpdateToX - UpdateFromX, UpdateToY - UpdateFromY);
|
2018-10-04 13:26:41 +00:00
|
|
|
|
2021-03-11 19:31:43 +00:00
|
|
|
for(int y = UpdateFromY; y < UpdateToY; y++)
|
|
|
|
{
|
|
|
|
for(int x = UpdateFromX; x < UpdateToX; x++)
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
2022-06-30 22:36:32 +00:00
|
|
|
CTile *pIn = &pLayer->m_pTiles[y * pLayer->m_Width + x];
|
|
|
|
CTile *pOut = &pUpdateLayer->m_pTiles[(y - UpdateFromY) * pUpdateLayer->m_Width + x - UpdateFromX];
|
|
|
|
pOut->m_Index = pIn->m_Index;
|
|
|
|
pOut->m_Flags = pIn->m_Flags;
|
2018-10-04 13:26:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Proceed(pUpdateLayer, ConfigID, Seed, UpdateFromX, UpdateFromY);
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
for(int y = CommitFromY; y < CommitToY; y++)
|
|
|
|
{
|
2018-10-04 13:26:41 +00:00
|
|
|
for(int x = CommitFromX; x < CommitToX; x++)
|
|
|
|
{
|
2022-06-30 22:36:32 +00:00
|
|
|
CTile *pIn = &pUpdateLayer->m_pTiles[(y - UpdateFromY) * pUpdateLayer->m_Width + x - UpdateFromX];
|
|
|
|
CTile *pOut = &pLayer->m_pTiles[y * pLayer->m_Width + x];
|
|
|
|
pOut->m_Index = pIn->m_Index;
|
|
|
|
pOut->m_Flags = pIn->m_Flags;
|
2018-10-04 13:26:41 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-12 13:25:46 +00:00
|
|
|
|
2021-03-11 19:31:43 +00:00
|
|
|
delete pUpdateLayer;
|
2018-10-04 13:26:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CAutoMapper::Proceed(CLayerTiles *pLayer, int ConfigID, int Seed, int SeedOffsetX, int SeedOffsetY)
|
2011-07-08 23:09:06 +00:00
|
|
|
{
|
2022-06-11 19:38:18 +00:00
|
|
|
if(!m_FileLoaded || pLayer->m_Readonly || ConfigID < 0 || ConfigID >= (int)m_vConfigs.size())
|
2011-07-08 23:09:06 +00:00
|
|
|
return;
|
2011-08-11 08:59:14 +00:00
|
|
|
|
2018-10-03 16:16:58 +00:00
|
|
|
if(Seed == 0)
|
|
|
|
Seed = rand();
|
|
|
|
|
2022-06-11 19:38:18 +00:00
|
|
|
CConfiguration *pConf = &m_vConfigs[ConfigID];
|
2011-08-11 08:59:14 +00:00
|
|
|
|
2015-02-19 23:15:09 +00:00
|
|
|
// for every run: copy tiles, automap, overwrite tiles
|
2022-06-11 19:38:18 +00:00
|
|
|
for(size_t h = 0; h < pConf->m_vRuns.size(); ++h)
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
2022-06-11 19:38:18 +00:00
|
|
|
CRun *pRun = &pConf->m_vRuns[h];
|
2013-12-28 00:09:47 +00:00
|
|
|
|
2018-07-26 16:26:12 +00:00
|
|
|
// don't make copy if it's requested
|
2018-07-26 16:59:29 +00:00
|
|
|
CLayerTiles *pReadLayer;
|
2018-10-04 13:26:41 +00:00
|
|
|
if(pRun->m_AutomapCopy)
|
2018-07-26 20:58:05 +00:00
|
|
|
{
|
2023-09-05 13:16:41 +00:00
|
|
|
pReadLayer = new CLayerTiles(Editor(), pLayer->m_Width, pLayer->m_Height);
|
2013-12-28 00:09:47 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
for(int y = 0; y < pLayer->m_Height; y++)
|
|
|
|
{
|
2018-07-26 16:26:12 +00:00
|
|
|
for(int x = 0; x < pLayer->m_Width; x++)
|
|
|
|
{
|
2022-06-30 22:36:32 +00:00
|
|
|
CTile *pIn = &pLayer->m_pTiles[y * pLayer->m_Width + x];
|
|
|
|
CTile *pOut = &pReadLayer->m_pTiles[y * pLayer->m_Width + x];
|
|
|
|
pOut->m_Index = pIn->m_Index;
|
|
|
|
pOut->m_Flags = pIn->m_Flags;
|
2018-07-26 16:26:12 +00:00
|
|
|
}
|
2015-02-19 23:15:09 +00:00
|
|
|
}
|
2013-12-28 00:09:47 +00:00
|
|
|
}
|
2018-10-04 13:26:41 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
pReadLayer = pLayer;
|
|
|
|
}
|
2013-12-28 00:09:47 +00:00
|
|
|
|
2015-02-19 23:15:09 +00:00
|
|
|
// auto map
|
2020-09-26 19:41:58 +00:00
|
|
|
for(int y = 0; y < pLayer->m_Height; y++)
|
|
|
|
{
|
2015-02-19 23:15:09 +00:00
|
|
|
for(int x = 0; x < pLayer->m_Width; x++)
|
2011-07-08 23:09:06 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
CTile *pTile = &(pLayer->m_pTiles[y * pLayer->m_Width + x]);
|
2023-08-28 16:22:01 +00:00
|
|
|
Editor()->m_Map.OnModify();
|
2011-08-11 08:59:14 +00:00
|
|
|
|
2022-06-11 19:38:18 +00:00
|
|
|
for(size_t i = 0; i < pRun->m_vIndexRules.size(); ++i)
|
2015-02-19 23:15:09 +00:00
|
|
|
{
|
2022-06-11 19:38:18 +00:00
|
|
|
CIndexRule *pIndexRule = &pRun->m_vIndexRules[i];
|
2019-04-26 19:36:49 +00:00
|
|
|
if(pIndexRule->m_SkipEmpty && pTile->m_Index == 0) // skip empty tiles
|
|
|
|
continue;
|
|
|
|
if(pIndexRule->m_SkipFull && pTile->m_Index != 0) // skip full tiles
|
2018-08-11 01:01:25 +00:00
|
|
|
continue;
|
|
|
|
|
2015-02-19 23:15:09 +00:00
|
|
|
bool RespectRules = true;
|
2022-06-11 19:38:18 +00:00
|
|
|
for(size_t j = 0; j < pIndexRule->m_vRules.size() && RespectRules; ++j)
|
2011-07-08 23:09:06 +00:00
|
|
|
{
|
2022-06-11 19:38:18 +00:00
|
|
|
CPosRule *pRule = &pIndexRule->m_vRules[j];
|
2015-03-04 15:03:52 +00:00
|
|
|
|
|
|
|
int CheckIndex, CheckFlags;
|
|
|
|
int CheckX = x + pRule->m_X;
|
|
|
|
int CheckY = y + pRule->m_Y;
|
2020-09-26 19:41:58 +00:00
|
|
|
if(CheckX >= 0 && CheckX < pLayer->m_Width && CheckY >= 0 && CheckY < pLayer->m_Height)
|
|
|
|
{
|
2015-03-04 15:03:52 +00:00
|
|
|
int CheckTile = CheckY * pLayer->m_Width + CheckX;
|
2018-07-26 20:58:05 +00:00
|
|
|
CheckIndex = pReadLayer->m_pTiles[CheckTile].m_Index;
|
2022-12-19 17:28:08 +00:00
|
|
|
CheckFlags = pReadLayer->m_pTiles[CheckTile].m_Flags & (TILEFLAG_ROTATE | TILEFLAG_XFLIP | TILEFLAG_YFLIP);
|
2020-09-26 19:41:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-04 15:03:52 +00:00
|
|
|
CheckIndex = -1;
|
|
|
|
CheckFlags = 0;
|
|
|
|
}
|
2015-07-09 00:08:14 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(pRule->m_Value == CPosRule::INDEX)
|
2015-02-19 21:54:47 +00:00
|
|
|
{
|
2018-07-27 05:51:16 +00:00
|
|
|
RespectRules = false;
|
Declare variables as `const` when possible
According to cppcheck's `constVariable` error:
```
src\engine\client\backend\opengl\opengl_sl.cpp:74:43: style: Variable 'Define' can be declared as reference to const [constVariable]
for(CGLSLCompiler::SGLSLCompilerDefine &Define : pCompiler->m_vDefines)
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:2149:12: style: Variable 'GraphicThreadCommandBuffer' can be declared as reference to const [constVariable]
auto &GraphicThreadCommandBuffer = m_vvThreadDrawCommandBuffers[i + 1][m_CurImageIndex];
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:3192:9: style: Variable 'BufferObject' can be declared as reference to const [constVariable]
auto &BufferObject = m_vBufferObjects[BufferObjectIndex];
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:3200:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable]
auto &DescrSet = m_vTextures[State.m_Texture].m_VKStandard3DTexturedDescrSet;
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:3810:13: style: Variable 'Mode' can be declared as reference to const [constVariable]
for(auto &Mode : vPresentModeList)
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:3818:13: style: Variable 'Mode' can be declared as reference to const [constVariable]
for(auto &Mode : vPresentModeList)
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6511:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable]
auto &DescrSet = m_vTextures[pCommand->m_State.m_Texture].m_aVKStandardTexturedDescrSets[AddressModeIndex];
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6555:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable]
auto &DescrSet = m_vTextures[pCommand->m_State.m_Texture].m_VKStandard3DTexturedDescrSet;
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6660:9: style: Variable 'MemBlock' can be declared as reference to const [constVariable]
auto &MemBlock = m_vBufferObjects[BufferIndex].m_BufferObject.m_Mem;
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6799:9: style: Variable 'BufferObject' can be declared as reference to const [constVariable]
auto &BufferObject = m_vBufferObjects[BufferObjectIndex];
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6808:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable]
auto &DescrSet = m_vTextures[pCommand->m_State.m_Texture].m_aVKStandardTexturedDescrSets[AddressModeIndex];
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6902:9: style: Variable 'BufferObject' can be declared as reference to const [constVariable]
auto &BufferObject = m_vBufferObjects[BufferObjectIndex];
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6907:9: style: Variable 'TextTextureDescr' can be declared as reference to const [constVariable]
auto &TextTextureDescr = m_vTextures[pCommand->m_TextTextureIndex].m_VKTextDescrSet;
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6961:9: style: Variable 'BufferObject' can be declared as reference to const [constVariable]
auto &BufferObject = m_vBufferObjects[BufferObjectIndex];
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6970:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable]
auto &DescrSet = m_vTextures[State.m_Texture].m_aVKStandardTexturedDescrSets[AddressModeIndex];
^
src\game\client\components\hud.cpp:178:8: style: Variable 'aFlagCarrier' can be declared as const array [constVariable]
int aFlagCarrier[2] = {
^
src\game\client\components\hud.cpp:519:16: style: Variable 's_aTextWidth' can be declared as const array [constVariable]
static float s_aTextWidth[5] = {s_TextWidth0, s_TextWidth00, s_TextWidth000, s_TextWidth0000, s_TextWidth00000};
^
src\game\client\components\killmessages.cpp:305:30: style: Variable 'Client' can be declared as reference to const [constVariable]
CGameClient::CClientData &Client = GameClient()->m_aClients[m_aKillmsgs[r].m_KillerID];
^
src\game\client\components\killmessages.cpp:314:30: style: Variable 'Client' can be declared as reference to const [constVariable]
CGameClient::CClientData &Client = GameClient()->m_aClients[m_aKillmsgs[r].m_VictimID];
^
src\game\client\components\menus_ingame.cpp:243:12: style: Variable 'pInfoByName' can be declared as reference to const [constVariable]
for(auto &pInfoByName : m_pClient->m_Snap.m_apInfoByName)
^
src\game\client\components\menus_ingame.cpp:530:12: style: Variable 'pInfoByName' can be declared as reference to const [constVariable]
for(auto &pInfoByName : m_pClient->m_Snap.m_apInfoByName)
^
src\game\client\components\players.cpp:767:44: style: Variable 'CharacterInfo' can be declared as reference to const [constVariable]
CGameClient::CSnapState::CCharacterInfo &CharacterInfo = m_pClient->m_Snap.m_aCharacters[i];
^
src\game\client\components\spectator.cpp:122:27: style: Variable 'Snap' can be declared as reference to const [constVariable]
CGameClient::CSnapState &Snap = pSelf->m_pClient->m_Snap;
^
src\game\client\components\spectator.cpp:221:12: style: Variable 'pInfo' can be declared as reference to const [constVariable]
for(auto &pInfo : m_pClient->m_Snap.m_apInfoByDDTeamName)
^
src\game\client\gameclient.cpp:2220:15: style: Variable 'OwnClientData' can be declared as reference to const [constVariable]
CClientData &OwnClientData = m_aClients[ownID];
^
src\game\client\gameclient.cpp:2227:16: style: Variable 'cData' can be declared as reference to const [constVariable]
CClientData &cData = m_aClients[i];
^
src\game\client\prediction\entities\character.cpp:397:11: style: Variable 'aSpreading' can be declared as const array [constVariable]
float aSpreading[] = {-0.185f, -0.070f, 0, 0.070f, 0.185f};
^
src\game\client\prediction\entities\laser.cpp:53:9: style: Variable 'HitPos' can be declared as reference to const [constVariable]
vec2 &HitPos = pHit->Core()->m_Pos;
^
src\game\editor\auto_map.cpp:507:18: style: Variable 'Index' can be declared as reference to const [constVariable]
for(auto &Index : pRule->m_vIndexList)
^
src\game\editor\auto_map.cpp:518:18: style: Variable 'Index' can be declared as reference to const [constVariable]
for(auto &Index : pRule->m_vIndexList)
^
src\game\editor\editor.cpp:118:12: style: Variable 'Item' can be declared as reference to const [constVariable]
for(auto &Item : vList)
^
src\game\editor\editor.cpp:2983:11: style: Variable 'aAspects' can be declared as const array [constVariable]
float aAspects[] = {4.0f / 3.0f, 16.0f / 10.0f, 5.0f / 4.0f, 16.0f / 9.0f};
^
src\game\editor\editor.cpp:3141:15: style: Variable 's_aShift' can be declared as const array [constVariable]
static int s_aShift[] = {24, 16, 8, 0};
^
src\engine\server\server.cpp:2807:14: style: Variable 'Client' can be declared as reference to const [constVariable]
for(auto &Client : m_aClients)
^
src\engine\server\sql_string_helpers.cpp:51:6: style: Variable 'aTimes' can be declared as const array [constVariable]
int aTimes[7] =
^
src\test\secure_random.cpp:24:6: style: Variable 'BOUNDS' can be declared as const array [constVariable]
int BOUNDS[] = {2, 3, 4, 5, 10, 100, 127, 128, 129};
^
```
2022-11-13 15:29:13 +00:00
|
|
|
for(const auto &Index : pRule->m_vIndexList)
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
2022-05-24 09:24:33 +00:00
|
|
|
if(CheckIndex == Index.m_ID && (!Index.m_TestFlag || CheckFlags == Index.m_Flag))
|
2018-07-27 05:51:16 +00:00
|
|
|
{
|
|
|
|
RespectRules = true;
|
|
|
|
break;
|
|
|
|
}
|
2015-02-19 23:15:09 +00:00
|
|
|
}
|
2015-03-04 15:03:52 +00:00
|
|
|
}
|
2020-09-26 19:41:58 +00:00
|
|
|
else if(pRule->m_Value == CPosRule::NOTINDEX)
|
2015-03-04 15:03:52 +00:00
|
|
|
{
|
Declare variables as `const` when possible
According to cppcheck's `constVariable` error:
```
src\engine\client\backend\opengl\opengl_sl.cpp:74:43: style: Variable 'Define' can be declared as reference to const [constVariable]
for(CGLSLCompiler::SGLSLCompilerDefine &Define : pCompiler->m_vDefines)
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:2149:12: style: Variable 'GraphicThreadCommandBuffer' can be declared as reference to const [constVariable]
auto &GraphicThreadCommandBuffer = m_vvThreadDrawCommandBuffers[i + 1][m_CurImageIndex];
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:3192:9: style: Variable 'BufferObject' can be declared as reference to const [constVariable]
auto &BufferObject = m_vBufferObjects[BufferObjectIndex];
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:3200:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable]
auto &DescrSet = m_vTextures[State.m_Texture].m_VKStandard3DTexturedDescrSet;
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:3810:13: style: Variable 'Mode' can be declared as reference to const [constVariable]
for(auto &Mode : vPresentModeList)
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:3818:13: style: Variable 'Mode' can be declared as reference to const [constVariable]
for(auto &Mode : vPresentModeList)
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6511:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable]
auto &DescrSet = m_vTextures[pCommand->m_State.m_Texture].m_aVKStandardTexturedDescrSets[AddressModeIndex];
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6555:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable]
auto &DescrSet = m_vTextures[pCommand->m_State.m_Texture].m_VKStandard3DTexturedDescrSet;
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6660:9: style: Variable 'MemBlock' can be declared as reference to const [constVariable]
auto &MemBlock = m_vBufferObjects[BufferIndex].m_BufferObject.m_Mem;
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6799:9: style: Variable 'BufferObject' can be declared as reference to const [constVariable]
auto &BufferObject = m_vBufferObjects[BufferObjectIndex];
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6808:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable]
auto &DescrSet = m_vTextures[pCommand->m_State.m_Texture].m_aVKStandardTexturedDescrSets[AddressModeIndex];
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6902:9: style: Variable 'BufferObject' can be declared as reference to const [constVariable]
auto &BufferObject = m_vBufferObjects[BufferObjectIndex];
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6907:9: style: Variable 'TextTextureDescr' can be declared as reference to const [constVariable]
auto &TextTextureDescr = m_vTextures[pCommand->m_TextTextureIndex].m_VKTextDescrSet;
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6961:9: style: Variable 'BufferObject' can be declared as reference to const [constVariable]
auto &BufferObject = m_vBufferObjects[BufferObjectIndex];
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6970:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable]
auto &DescrSet = m_vTextures[State.m_Texture].m_aVKStandardTexturedDescrSets[AddressModeIndex];
^
src\game\client\components\hud.cpp:178:8: style: Variable 'aFlagCarrier' can be declared as const array [constVariable]
int aFlagCarrier[2] = {
^
src\game\client\components\hud.cpp:519:16: style: Variable 's_aTextWidth' can be declared as const array [constVariable]
static float s_aTextWidth[5] = {s_TextWidth0, s_TextWidth00, s_TextWidth000, s_TextWidth0000, s_TextWidth00000};
^
src\game\client\components\killmessages.cpp:305:30: style: Variable 'Client' can be declared as reference to const [constVariable]
CGameClient::CClientData &Client = GameClient()->m_aClients[m_aKillmsgs[r].m_KillerID];
^
src\game\client\components\killmessages.cpp:314:30: style: Variable 'Client' can be declared as reference to const [constVariable]
CGameClient::CClientData &Client = GameClient()->m_aClients[m_aKillmsgs[r].m_VictimID];
^
src\game\client\components\menus_ingame.cpp:243:12: style: Variable 'pInfoByName' can be declared as reference to const [constVariable]
for(auto &pInfoByName : m_pClient->m_Snap.m_apInfoByName)
^
src\game\client\components\menus_ingame.cpp:530:12: style: Variable 'pInfoByName' can be declared as reference to const [constVariable]
for(auto &pInfoByName : m_pClient->m_Snap.m_apInfoByName)
^
src\game\client\components\players.cpp:767:44: style: Variable 'CharacterInfo' can be declared as reference to const [constVariable]
CGameClient::CSnapState::CCharacterInfo &CharacterInfo = m_pClient->m_Snap.m_aCharacters[i];
^
src\game\client\components\spectator.cpp:122:27: style: Variable 'Snap' can be declared as reference to const [constVariable]
CGameClient::CSnapState &Snap = pSelf->m_pClient->m_Snap;
^
src\game\client\components\spectator.cpp:221:12: style: Variable 'pInfo' can be declared as reference to const [constVariable]
for(auto &pInfo : m_pClient->m_Snap.m_apInfoByDDTeamName)
^
src\game\client\gameclient.cpp:2220:15: style: Variable 'OwnClientData' can be declared as reference to const [constVariable]
CClientData &OwnClientData = m_aClients[ownID];
^
src\game\client\gameclient.cpp:2227:16: style: Variable 'cData' can be declared as reference to const [constVariable]
CClientData &cData = m_aClients[i];
^
src\game\client\prediction\entities\character.cpp:397:11: style: Variable 'aSpreading' can be declared as const array [constVariable]
float aSpreading[] = {-0.185f, -0.070f, 0, 0.070f, 0.185f};
^
src\game\client\prediction\entities\laser.cpp:53:9: style: Variable 'HitPos' can be declared as reference to const [constVariable]
vec2 &HitPos = pHit->Core()->m_Pos;
^
src\game\editor\auto_map.cpp:507:18: style: Variable 'Index' can be declared as reference to const [constVariable]
for(auto &Index : pRule->m_vIndexList)
^
src\game\editor\auto_map.cpp:518:18: style: Variable 'Index' can be declared as reference to const [constVariable]
for(auto &Index : pRule->m_vIndexList)
^
src\game\editor\editor.cpp:118:12: style: Variable 'Item' can be declared as reference to const [constVariable]
for(auto &Item : vList)
^
src\game\editor\editor.cpp:2983:11: style: Variable 'aAspects' can be declared as const array [constVariable]
float aAspects[] = {4.0f / 3.0f, 16.0f / 10.0f, 5.0f / 4.0f, 16.0f / 9.0f};
^
src\game\editor\editor.cpp:3141:15: style: Variable 's_aShift' can be declared as const array [constVariable]
static int s_aShift[] = {24, 16, 8, 0};
^
src\engine\server\server.cpp:2807:14: style: Variable 'Client' can be declared as reference to const [constVariable]
for(auto &Client : m_aClients)
^
src\engine\server\sql_string_helpers.cpp:51:6: style: Variable 'aTimes' can be declared as const array [constVariable]
int aTimes[7] =
^
src\test\secure_random.cpp:24:6: style: Variable 'BOUNDS' can be declared as const array [constVariable]
int BOUNDS[] = {2, 3, 4, 5, 10, 100, 127, 128, 129};
^
```
2022-11-13 15:29:13 +00:00
|
|
|
for(const auto &Index : pRule->m_vIndexList)
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
2022-05-24 09:24:33 +00:00
|
|
|
if(CheckIndex == Index.m_ID && (!Index.m_TestFlag || CheckFlags == Index.m_Flag))
|
2018-07-27 05:51:16 +00:00
|
|
|
{
|
|
|
|
RespectRules = false;
|
|
|
|
break;
|
|
|
|
}
|
2015-02-19 21:54:47 +00:00
|
|
|
}
|
2011-07-08 23:09:06 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-11 08:59:14 +00:00
|
|
|
|
2015-02-19 23:15:09 +00:00
|
|
|
if(RespectRules &&
|
2019-07-08 21:08:42 +00:00
|
|
|
(pIndexRule->m_RandomProbability >= 1.0f || HashLocation(Seed, h, i, x + SeedOffsetX, y + SeedOffsetY) < HASH_MAX * pIndexRule->m_RandomProbability))
|
2015-02-19 23:15:09 +00:00
|
|
|
{
|
2019-04-26 19:36:49 +00:00
|
|
|
pTile->m_Index = pIndexRule->m_ID;
|
2018-08-11 01:01:25 +00:00
|
|
|
pTile->m_Flags = pIndexRule->m_Flag;
|
2015-02-19 23:15:09 +00:00
|
|
|
}
|
2011-07-08 23:09:06 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-28 00:09:47 +00:00
|
|
|
}
|
2018-07-26 16:26:12 +00:00
|
|
|
|
|
|
|
// clean-up
|
2022-05-27 14:41:14 +00:00
|
|
|
if(pRun->m_AutomapCopy && pReadLayer != pLayer)
|
2018-07-26 16:26:12 +00:00
|
|
|
delete pReadLayer;
|
2015-02-19 23:15:09 +00:00
|
|
|
}
|
2011-07-08 23:09:06 +00:00
|
|
|
}
|