Permalink
Browse files

Fix long-standing bug where we did not reset our default components b…

…etween games.

Fix template store on removing store-ness. Do not store default values.
  • Loading branch information...
perim committed Dec 18, 2011
1 parent add8668 commit 4e66209506342112987b9085358dd1835a31c7f3
Showing with 32 additions and 9 deletions.
  1. +0 −3 src/design.cpp
  2. +4 −0 src/multiplay.cpp
  3. +3 −0 src/research.cpp
  4. +25 −6 src/template.cpp
View
@@ -4498,9 +4498,6 @@ static bool saveTemplate(void)
psTempl->multiPlayerID = generateNewObjectId();
sendTemplate(selectedPlayer, psTempl);
- // store list to disk
- storeTemplates();
-
return true;
}
View
@@ -1402,6 +1402,10 @@ bool recvTemplate(NETQUEUE queue)
addTemplateBack(player, &t); // Add to back of list, to avoid game state templates being in wrong order, which matters when saving games.
debug(LOG_SYNC, "Creating MP template %d (stored=%s)", (int)t.multiPlayerID, t.stored ? "yes" : "no");
}
+ if (!t.prefab && player == selectedPlayer)
+ {
+ storeTemplates();
+ }
return true;
}
View
@@ -100,6 +100,9 @@ bool researchInitVars(void)
for (int i = 0; i < MAX_PLAYERS; i++)
{
bSelfRepair[i] = false;
+ aDefaultSensor[i] = 0;
+ aDefaultECM[i] = 0;
+ aDefaultRepair[i] = 0;
}
return true;
View
@@ -106,7 +106,11 @@ bool initTemplates()
design.prefab = false; // not AI template
design.stored = true;
bool valid = intValidTemplate(&design, ini.value("name").toString().toUtf8().constData());
- ASSERT_OR_RETURN(false, valid, "Invalid template %d", i);
+ if (!valid)
+ {
+ debug(LOG_ERROR, "Invalid template %d / %s from stored templates", i, list[i].toUtf8().constData());
+ continue;
+ }
addTemplateToList(&design, &apsDroidTemplates[selectedPlayer]);
localTemplates.push_back(design);
ini.endGroup();
@@ -131,11 +135,26 @@ bool storeTemplates()
ini.setValue("droidType", psCurr->droidType);
ini.setValue("body", (asBodyStats + psCurr->asParts[COMP_BODY])->pName);
ini.setValue("propulsion", (asPropulsionStats + psCurr->asParts[COMP_PROPULSION])->pName);
- ini.setValue("brain", (asBrainStats + psCurr->asParts[COMP_BRAIN])->pName);
- ini.setValue("repair", (asRepairStats + psCurr->asParts[COMP_REPAIRUNIT])->pName);
- ini.setValue("ecm", (asECMStats + psCurr->asParts[COMP_ECM])->pName);
- ini.setValue("sensor", (asSensorStats + psCurr->asParts[COMP_SENSOR])->pName);
- ini.setValue("construct", (asConstructStats + psCurr->asParts[COMP_CONSTRUCT])->pName);
+ if (psCurr->asParts[COMP_BRAIN] != 0)
+ {
+ ini.setValue("brain", (asBrainStats + psCurr->asParts[COMP_BRAIN])->pName);
+ }
+ if ((asRepairStats + psCurr->asParts[COMP_REPAIRUNIT])->location == LOC_TURRET) // avoid auto-repair...
+ {
+ ini.setValue("repair", (asRepairStats + psCurr->asParts[COMP_REPAIRUNIT])->pName);
+ }
+ if ((asECMStats + psCurr->asParts[COMP_ECM])->location == LOC_TURRET)
+ {
+ ini.setValue("ecm", (asECMStats + psCurr->asParts[COMP_ECM])->pName);
+ }
+ if ((asSensorStats + psCurr->asParts[COMP_SENSOR])->location == LOC_TURRET)
+ {
+ ini.setValue("sensor", (asSensorStats + psCurr->asParts[COMP_SENSOR])->pName);
+ }
+ if (psCurr->asParts[COMP_CONSTRUCT] != 0)
+ {
+ ini.setValue("construct", (asConstructStats + psCurr->asParts[COMP_CONSTRUCT])->pName);
+ }
ini.setValue("weapons", psCurr->numWeaps);
for (int j = 0; j < psCurr->numWeaps; j++)
{

0 comments on commit 4e66209

Please sign in to comment.