#4559: Commander designs are not loaded
-------------------------------------------------+-------------------------
Reporter: Forgon | Owner:
Type: patch (an actual patch, not | Status: new
a request for one) | Milestone: unspecified
Priority: normal | Version: 3.1 and
Component: other | master
Operating System: All/Non-Specific |
-------------------------------------------------+-------------------------
All Commander templates (example attached) are erroneously treated as
invalid and not loaded. Design names are not printed either:
{{{
never |01:41:05: [openLoadFile:146] Reading...[directory:
/home/x/.warzone2100-master/] userdata/mp/templates.json
save |01:41:05: [WzConfig:123] Opening userdata/mp/templates.json
error |01:41:05: [initTemplates:210] Template from stored templates
cannot be designed
save |01:41:05: [~WzConfig:43] Closing userdata/mp/templates.json
console |01:41:06: [addConsoleMessage:175] (to player -2): Error! (Check
your logs!): [initTemplates:210] Template from stored templates cannot be
designed
never |01:41:14: [openLoadFile:146] Reading...[directory:
/home/x/.warzone2100-master/] userdata/mp/templates.json
save |01:41:14: [WzConfig:123] Opening userdata/mp/templates.json
wz |01:41:14: [saveFile:270] We are to write
(userdata/mp/templates.json) of size 311
wz |01:41:14: [saveFile:298] Successfully wrote to
/home/x/.warzone2100-master//userdata/mp/templates.json with 311 bytes
save |01:41:14: [~WzConfig:43] Saving userdata/mp/templates.json
}}}
My hackish patch of `initTemplates()' in './src/template.cpp' below should
be refactored further.
{{{
bool initTemplates()
{
WzConfig ini("userdata/" + QString(rulesettag) +
"/templates.json", WzConfig::ReadOnly);
if (!ini.status())
{
debug(LOG_WZ, "Could not open %s",
ini.fileName().toUtf8().constData());
return false;
}
int version = ini.value("version", 0).toInt();
if (version == 0)
{
return true; // too old version
}
ini.beginArray("templates");
while (ini.remainingArrayItems())
{
DROID_TEMPLATE design = loadTemplateCommon(ini);
design.multiPlayerID = generateNewObjectId();
design.prefab = false; // not AI template
design.stored = true;
if (!(asBodyStats +
design.asParts[COMP_BODY])->designable)
{
debug(LOG_ERROR, "Body for \"%s\" from stored
templates cannot be designed", design.name.toUtf8().constData());
ini.nextArrayItem();
continue;
}
else if (!(asPropulsionStats +
design.asParts[COMP_PROPULSION])->designable)
{
debug(LOG_ERROR, "Propulsion for \"%s\" from
stored templates cannot be designed", design.name.toUtf8().constData());
ini.nextArrayItem();
continue;
}
else if ((design.asParts[COMP_BRAIN] > 0 && !(asBrainStats
+ design.asParts[COMP_BRAIN])->designable)
|| (design.asParts[COMP_REPAIRUNIT] > 0 &&
!(asRepairStats + design.asParts[COMP_REPAIRUNIT])->designable)
|| (design.asParts[COMP_ECM] > 0 && !(asECMStats +
design.asParts[COMP_ECM])->designable)
|| (design.asParts[COMP_SENSOR] > 0 && !(asSensorStats
+ design.asParts[COMP_SENSOR])->designable) ||
(design.asParts[COMP_CONSTRUCT] > 0 && !(asConstructStats +
design.asParts[COMP_CONSTRUCT])->designable)
//Commanders fail these checks
|| (design.asParts[COMP_BRAIN] == 0
&& ((design.numWeaps > 0 && !(asWeaponStats +
design.asWeaps[0])->designable)
|| (design.numWeaps > 1 && !(asWeaponStats +
design.asWeaps[1])->designable)
|| (design.numWeaps > 2 && !(asWeaponStats +
design.asWeaps[2])->designable))))
{
debug(LOG_ERROR, "Turret for \"%s\" from stored
templates cannot be designed", design.name.toUtf8().constData());
ini.nextArrayItem();
continue;
}
//further lines omitted for the sake of clarity
}}}
--
Ticket URL: <http://developer.wz2100.net/ticket/4559>
Warzone 2100 Trac <http://developer.wz2100.net/>
The Warzone 2100 Project
------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
_______________________________________________
Warzone2100-project mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/warzone2100-project