summaryrefslogtreecommitdiff
path: root/src/simulation
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/simulation
parent4192a5714661dfc9c04552957f3dd36e5c902f37 (diff)
downloadpowder-29189693b381ce7b31095fb2ae2ffb01bd8a221e.zip
powder-29189693b381ce7b31095fb2ae2ffb01bd8a221e.tar.gz
Element palette for automatic element ID/mod mapping
Diffstat (limited to 'src/simulation')
-rw-r--r--src/simulation/Simulation.cpp44
1 files changed, 44 insertions, 0 deletions
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));
+ }
}
}