Element palette for automatic element ID/mod mapping
This commit is contained in:
parent
4192a57146
commit
29189693b3
@ -21,11 +21,11 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MINOR_VERSION
|
#ifndef MINOR_VERSION
|
||||||
#define MINOR_VERSION 0
|
#define MINOR_VERSION 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef BUILD_NUM
|
#ifndef BUILD_NUM
|
||||||
#define BUILD_NUM 246
|
#define BUILD_NUM 248
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef SNAPSHOT_ID
|
#ifndef SNAPSHOT_ID
|
||||||
|
@ -23,7 +23,8 @@ airMode(save.airMode),
|
|||||||
signs(save.signs),
|
signs(save.signs),
|
||||||
expanded(save.expanded),
|
expanded(save.expanded),
|
||||||
hasOriginalData(save.hasOriginalData),
|
hasOriginalData(save.hasOriginalData),
|
||||||
originalData(save.originalData)
|
originalData(save.originalData),
|
||||||
|
palette(save.palette)
|
||||||
{
|
{
|
||||||
blockMap = NULL;
|
blockMap = NULL;
|
||||||
blockMapPtr = NULL;
|
blockMapPtr = NULL;
|
||||||
@ -659,6 +660,25 @@ void GameSave::readOPS(char * data, int dataLength)
|
|||||||
fprintf(stderr, "Wrong type for %s\n", bson_iterator_key(&iter));
|
fprintf(stderr, "Wrong type for %s\n", bson_iterator_key(&iter));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(strcmp(bson_iterator_key(&iter), "palette")==0)
|
||||||
|
{
|
||||||
|
palette.clear();
|
||||||
|
if(bson_iterator_type(&iter)==BSON_ARRAY)
|
||||||
|
{
|
||||||
|
bson_iterator subiter;
|
||||||
|
bson_iterator_subiterator(&iter, &subiter);
|
||||||
|
while(bson_iterator_next(&subiter))
|
||||||
|
{
|
||||||
|
if(bson_iterator_type(&subiter)==BSON_INT)
|
||||||
|
{
|
||||||
|
std::string id = std::string(bson_iterator_key(&subiter));
|
||||||
|
int num = bson_iterator_int(&subiter);
|
||||||
|
palette.push_back(PaletteItem(id, num));
|
||||||
|
printf("R P: %s %d\n", id.c_str(), num);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Read wall and fan data
|
//Read wall and fan data
|
||||||
@ -1939,6 +1959,16 @@ char * GameSave::serialiseOPS(int & dataLength)
|
|||||||
bson_append_binary(&b, "fanMap", BSON_BIN_USER, (const char *)fanData, fanDataLen);
|
bson_append_binary(&b, "fanMap", BSON_BIN_USER, (const char *)fanData, fanDataLen);
|
||||||
if(soapLinkData)
|
if(soapLinkData)
|
||||||
bson_append_binary(&b, "soapLinks", BSON_BIN_USER, (const char *)soapLinkData, soapLinkDataLen);
|
bson_append_binary(&b, "soapLinks", BSON_BIN_USER, (const char *)soapLinkData, soapLinkDataLen);
|
||||||
|
if(partsData && palette.size())
|
||||||
|
{
|
||||||
|
bson_append_start_array(&b, "palette");
|
||||||
|
for(std::vector<PaletteItem>::iterator iter = palette.begin(), end = palette.end(); iter != end; ++iter)
|
||||||
|
{
|
||||||
|
bson_append_int(&b, (*iter).first.c_str(), (*iter).second);
|
||||||
|
printf("W P: %s %d\n", (*iter).first.c_str(), (*iter).second);
|
||||||
|
}
|
||||||
|
bson_append_finish_array(&b);
|
||||||
|
}
|
||||||
signsCount = 0;
|
signsCount = 0;
|
||||||
for(i = 0; i < signs.size(); i++)
|
for(i = 0; i < signs.size(); i++)
|
||||||
{
|
{
|
||||||
|
@ -56,6 +56,10 @@ public:
|
|||||||
//Signs
|
//Signs
|
||||||
std::vector<sign> signs;
|
std::vector<sign> signs;
|
||||||
|
|
||||||
|
//Element palette
|
||||||
|
typedef std::pair<std::string, int> PaletteItem;
|
||||||
|
std::vector<PaletteItem> palette;
|
||||||
|
|
||||||
GameSave();
|
GameSave();
|
||||||
GameSave(GameSave & save);
|
GameSave(GameSave & save);
|
||||||
GameSave(int width, int height);
|
GameSave(int width, int height);
|
||||||
|
@ -45,6 +45,29 @@ int Simulation::Load(int fullX, int fullY, GameSave * save)
|
|||||||
fullX = blockX*CELL;
|
fullX = blockX*CELL;
|
||||||
fullY = blockY*CELL;
|
fullY = blockY*CELL;
|
||||||
|
|
||||||
|
int partMap[PT_NUM];
|
||||||
|
for(int i = 0; i < PT_NUM; i++)
|
||||||
|
{
|
||||||
|
partMap[i] = i;
|
||||||
|
}
|
||||||
|
if(save->palette.size())
|
||||||
|
{
|
||||||
|
for(std::vector<GameSave::PaletteItem>::iterator iter = save->palette.begin(), end = save->palette.end(); iter != end; ++iter)
|
||||||
|
{
|
||||||
|
GameSave::PaletteItem pi = *iter;
|
||||||
|
if(pi.second >= 0 && pi.second < PT_NUM)
|
||||||
|
{
|
||||||
|
int myId = 0;//pi.second;
|
||||||
|
for(int i = 0; i < PT_NUM; i++)
|
||||||
|
{
|
||||||
|
if(elements[i].Enabled && elements[i].Identifier == pi.first)
|
||||||
|
myId = i;
|
||||||
|
}
|
||||||
|
partMap[pi.second] = myId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for(int n = 0; n < NPART && n < save->particlesCount; n++)
|
for(int n = 0; n < NPART && n < save->particlesCount; n++)
|
||||||
{
|
{
|
||||||
@ -54,6 +77,9 @@ int Simulation::Load(int fullX, int fullY, GameSave * save)
|
|||||||
x = int(tempPart.x + 0.5f);
|
x = int(tempPart.x + 0.5f);
|
||||||
y = int(tempPart.y + 0.5f);
|
y = int(tempPart.y + 0.5f);
|
||||||
|
|
||||||
|
if(tempPart.type >= 0 && tempPart.type < PT_NUM)
|
||||||
|
tempPart.type = partMap[tempPart.type];
|
||||||
|
|
||||||
if ((player.spwn == 1 && tempPart.type==PT_STKM) || (player2.spwn == 1 && tempPart.type==PT_STKM2))
|
if ((player.spwn == 1 && tempPart.type==PT_STKM) || (player2.spwn == 1 && tempPart.type==PT_STKM2))
|
||||||
continue;
|
continue;
|
||||||
if (!elements[tempPart.type].Enabled)
|
if (!elements[tempPart.type].Enabled)
|
||||||
@ -182,6 +208,9 @@ GameSave * Simulation::Save(int fullX, int fullY, int fullX2, int fullY2)
|
|||||||
|
|
||||||
GameSave * newSave = new GameSave(blockW, blockH);
|
GameSave * newSave = new GameSave(blockW, blockH);
|
||||||
|
|
||||||
|
int storedParts = 0;
|
||||||
|
int elementCount[PT_NUM];
|
||||||
|
std::fill(elementCount, elementCount+PT_NUM, 0);
|
||||||
for(int i = 0; i < NPART; i++)
|
for(int i = 0; i < NPART; i++)
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
@ -193,7 +222,22 @@ GameSave * Simulation::Save(int fullX, int fullY, int fullX2, int fullY2)
|
|||||||
tempPart.x -= fullX;
|
tempPart.x -= fullX;
|
||||||
tempPart.y -= fullY;
|
tempPart.y -= fullY;
|
||||||
if(elements[tempPart.type].Enabled)
|
if(elements[tempPart.type].Enabled)
|
||||||
|
{
|
||||||
*newSave << tempPart;
|
*newSave << tempPart;
|
||||||
|
storedParts++;
|
||||||
|
elementCount[tempPart.type]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(storedParts)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < PT_NUM; i++)
|
||||||
|
{
|
||||||
|
if(elements[i].Enabled && elementCount[i])
|
||||||
|
{
|
||||||
|
newSave->palette.push_back(GameSave::PaletteItem(elements[i].Identifier, i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user