Permalink
Browse files

Fix bug in stored templates that made commanders not be saved. Also s…

…ave list

to disk for every change, since Cyp prefers to close down the game by killing it.
  • Loading branch information...
1 parent 579e150 commit add866851b5a58e38004a9cb816a22aedc1e10d9 @perim perim committed Dec 18, 2011
Showing with 15 additions and 5 deletions.
  1. +3 −0 src/design.cpp
  2. +11 −5 src/template.cpp
  3. +1 −0 src/template.h
View
@@ -4498,6 +4498,9 @@ static bool saveTemplate(void)
psTempl->multiPlayerID = generateNewObjectId();
sendTemplate(selectedPlayer, psTempl);
+ // store list to disk
+ storeTemplates();
+
return true;
}
View
@@ -60,14 +60,15 @@ static const StringToEnum<DROID_TYPE> map_DROID_TYPE[] =
bool researchedTemplate(DROID_TEMPLATE *psCurr, int player)
{
+ // Note the ugly special case for commanders - their weapon is unavailable
if (apCompLists[player][COMP_BODY][psCurr->asParts[COMP_BODY]] != AVAILABLE
|| (psCurr->asParts[COMP_BRAIN] > 0 && apCompLists[player][COMP_BRAIN][psCurr->asParts[COMP_BRAIN]] != AVAILABLE)
|| apCompLists[player][COMP_PROPULSION][psCurr->asParts[COMP_PROPULSION]] != AVAILABLE
|| (psCurr->asParts[COMP_SENSOR] > 0 && apCompLists[player][COMP_SENSOR][psCurr->asParts[COMP_SENSOR]] != AVAILABLE)
|| (psCurr->asParts[COMP_ECM] > 0 && apCompLists[player][COMP_ECM][psCurr->asParts[COMP_ECM]] != AVAILABLE)
|| (psCurr->asParts[COMP_REPAIRUNIT] > 0 && apCompLists[player][COMP_REPAIRUNIT][psCurr->asParts[COMP_REPAIRUNIT]] != AVAILABLE)
|| (psCurr->asParts[COMP_CONSTRUCT] > 0 && apCompLists[player][COMP_CONSTRUCT][psCurr->asParts[COMP_CONSTRUCT]] != AVAILABLE)
- || (psCurr->numWeaps > 0 && apCompLists[player][COMP_WEAPON][psCurr->asWeaps[0]] != AVAILABLE)
+ || (psCurr->asParts[COMP_BRAIN] == 0 && psCurr->numWeaps > 0 && apCompLists[player][COMP_WEAPON][psCurr->asWeaps[0]] != AVAILABLE)
|| (psCurr->numWeaps > 1 && apCompLists[player][COMP_WEAPON][psCurr->asWeaps[1]] != AVAILABLE))
{
return false;
@@ -80,7 +81,7 @@ bool initTemplates()
WzConfig ini("templates.ini");
if (ini.status() != QSettings::NoError)
{
- debug(LOG_ERROR, "Could not open templates.ini");
+ debug(LOG_FATAL, "Could not open templates.ini");
return false;
}
QStringList list = ini.childGroups();
@@ -113,13 +114,13 @@ bool initTemplates()
return true;
}
-bool shutdownTemplates()
+bool storeTemplates()
{
// Write stored templates (back) to file
WzConfig ini("templates.ini");
- if (ini.status() != QSettings::NoError)
+ if (ini.status() != QSettings::NoError || !ini.isWritable())
{
- debug(LOG_ERROR, "Could not open templates.ini");
+ debug(LOG_FATAL, "Could not open templates.ini");
return false;
}
for (DROID_TEMPLATE *psCurr = apsDroidTemplates[selectedPlayer]; psCurr != NULL; psCurr = psCurr->psNext)
@@ -145,6 +146,11 @@ bool shutdownTemplates()
return true;
}
+bool shutdownTemplates()
+{
+ return storeTemplates();
+}
+
static void initTemplatePoints(DROID_TEMPLATE *pDroidDesign)
{
//calculate the total build points
View
@@ -9,6 +9,7 @@ extern DROID_TEMPLATE *apsStaticTemplates; // for AIs and scripts
bool initTemplates();
bool shutdownTemplates();
+bool storeTemplates();
/** Initialise the template build and power points */
void initTemplatePoints(void);

0 comments on commit add8668

Please sign in to comment.