summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-11-12 10:22:16 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-11-12 10:22:16 (GMT)
commit29189693b381ce7b31095fb2ae2ffb01bd8a221e (patch)
tree7448f71a551365459d68dcaec60ba9ffbb9bfa46 /src
parent4192a5714661dfc9c04552957f3dd36e5c902f37 (diff)
downloadpowder-29189693b381ce7b31095fb2ae2ffb01bd8a221e.zip
powder-29189693b381ce7b31095fb2ae2ffb01bd8a221e.tar.gz
Element palette for automatic element ID/mod mapping
Diffstat (limited to 'src')
-rw-r--r--src/Config.h4
-rw-r--r--src/client/GameSave.cpp34
-rw-r--r--src/client/GameSave.h4
-rw-r--r--src/simulation/Simulation.cpp44
4 files changed, 82 insertions, 4 deletions
diff --git a/src/Config.h b/src/Config.h
index e810221..5d2a1a5 100644
--- a/src/Config.h
+++ b/src/Config.h
@@ -21,11 +21,11 @@
#endif
#ifndef MINOR_VERSION
-#define MINOR_VERSION 0
+#define MINOR_VERSION 2
#endif
#ifndef BUILD_NUM
-#define BUILD_NUM 246
+#define BUILD_NUM 248
#endif
#ifndef SNAPSHOT_ID
diff --git a/src/client/GameSave.cpp b/src/client/GameSave.cpp
index 9072921..0b94c1f 100644
--- a/src/client/GameSave.cpp
+++ b/src/client/GameSave.cpp
@@ -23,7 +23,8 @@ airMode(save.airMode),
signs(save.signs),
expanded(save.expanded),
hasOriginalData(save.hasOriginalData),
-originalData(save.originalData)
+originalData(save.originalData),
+palette(save.palette)
{
blockMap = 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));
}
}
+ 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
@@ -1622,7 +1642,7 @@ char * GameSave::serialiseOPS(int & dataLength)
int x, y, i, wallDataFound = 0;
int posCount, signsCount;
bson b;
-
+
std::fill(elementCount, elementCount+PT_NUM, 0);
//Get coords in blocks
@@ -1939,6 +1959,16 @@ char * GameSave::serialiseOPS(int & dataLength)
bson_append_binary(&b, "fanMap", BSON_BIN_USER, (const char *)fanData, fanDataLen);
if(soapLinkData)
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;
for(i = 0; i < signs.size(); i++)
{
diff --git a/src/client/GameSave.h b/src/client/GameSave.h
index 62adc17..8ac1fce 100644
--- a/src/client/GameSave.h
+++ b/src/client/GameSave.h
@@ -55,6 +55,10 @@ public:
//Signs
std::vector<sign> signs;
+
+ //Element palette
+ typedef std::pair<std::string, int> PaletteItem;
+ std::vector<PaletteItem> palette;
GameSave();
GameSave(GameSave & save);
diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp
index ee4634c..a7f3750 100644
--- a/src/simulation/Simulation.cpp
+++ b/src/simulation/Simulation.cpp
@@ -45,6 +45,29 @@ int Simulation::Load(int fullX, int fullY, GameSave * save)
fullX = blockX*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;
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);
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))
continue;
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);
+ int storedParts = 0;
+ int elementCount[PT_NUM];
+ std::fill(elementCount, elementCount+PT_NUM, 0);
for(int i = 0; i < NPART; i++)
{
int x, y;
@@ -193,7 +222,22 @@ GameSave * Simulation::Save(int fullX, int fullY, int fullX2, int fullY2)
tempPart.x -= fullX;
tempPart.y -= fullY;
if(elements[tempPart.type].Enabled)
+ {
*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));
+ }
}
}