/* load the Droid stats for the components from the Access database */ bool loadDroidTemplates(const char *pDroidData, UDWORD bufferSize) { bool bDefaultTemplateFound = false; TableView table(pDroidData, bufferSize); for (unsigned i = 0; i < table.size(); ++i) { LineView line(table, i); DROID_TEMPLATE design(line); if (table.isError()) { debug(LOG_ERROR, "%s", table.getError().toUtf8().constData()); return false; } std::string const pNameCache = design.aName; design.pName = const_cast<char *>(pNameCache.c_str()); if (getTemplateFromUniqueName(design.pName, 0)) { debug(LOG_ERROR, "Duplicate template %s", design.pName); continue; } // Store translated name in aName char const *droidResourceName = getDroidResourceName(design.aName); sstrcpy(design.aName, droidResourceName != NULL? droidResourceName : GetDefaultTemplateName(&design)); // Store global default design if found else store in the appropriate array if (design.droidType == DROID_ANY) { design.droidType = DROID_DEFAULT; // NOTE: sDefaultDesignTemplate.pName takes ownership // of the memory allocated to pDroidDesign->pName // here. Which is good because pDroidDesign leaves // scope here anyway. sDefaultDesignTemplate = design; sDefaultDesignTemplate.pName = strdup(design.pName); bDefaultTemplateFound = true; } else { std::string playerType = line.s(6); // Give those meant for humans to all human players. // Also support the old template format, in which those meant // for humans were player 0 (in campaign) or 5 (in multiplayer). if ((!bMultiPlayer && playerType == "0") || ( bMultiPlayer && playerType == "5") || playerType == "YES" ) { for (int i = 0; i < MAX_PLAYERS; ++i) { if (NetPlay.players[i].allocated) // human prototype template { design.prefab = false; addTemplateToList(&design, &apsDroidTemplates[i]); } } localTemplates.push_front(design); localTemplates.front().pName = strdup(localTemplates.front().pName); } // Add all templates to static template list design.prefab = true; // prefabricated templates referenced from VLOs addTemplateToList(&design, &apsStaticTemplates); } debug(LOG_NEVER, "(default) Droid template found, aName: %s, MP ID: %d, ref: %u, pname: %s, prefab: %s, type:%d (loading)", design.aName, design.multiPlayerID, design.ref, design.pName, design.prefab ? "yes":"no", design.droidType); } ASSERT_OR_RETURN(false, bDefaultTemplateFound, "Default template not found"); return true; }
/* load the Droid stats for the components from the Access database */ bool loadDroidTemplates(const char *pDroidData, UDWORD bufferSize) { bool bDefaultTemplateFound = false; TableView table(pDroidData, bufferSize); for (unsigned i = 0; i < table.size(); ++i) { LineView line(table, i); DROID_TEMPLATE design(line); if (table.isError()) { debug(LOG_ERROR, "%s", table.getError().toUtf8().constData()); return false; } std::string const pNameCache = design.aName; design.pName = const_cast<char *>(pNameCache.c_str()); if (getTemplateFromUniqueName(design.pName, 0)) { debug(LOG_ERROR, "Duplicate template %s", design.pName); continue; } // Store translated name in aName char const *droidResourceName = getDroidResourceName(design.aName); sstrcpy(design.aName, droidResourceName != NULL? droidResourceName : GetDefaultTemplateName(&design)); // Store global default design if found else store in the appropriate array if (design.droidType == DROID_ANY) { design.droidType = DROID_DEFAULT; // NOTE: sDefaultDesignTemplate.pName takes ownership // of the memory allocated to pDroidDesign->pName // here. Which is good because pDroidDesign leaves // scope here anyway. sDefaultDesignTemplate = design; sDefaultDesignTemplate.pName = strdup(design.pName); bDefaultTemplateFound = true; } else { std::string playerType = line.s(6); for (int i = 0; i < MAX_PLAYERS; ++i) { // Give those meant for humans to all human players. // Also support the old template format, in which those meant // for humans were player 0 (in campaign) or 5 (in multiplayer), ("YES" is used in MP stats) if (NetPlay.players[i].allocated && ((!bMultiPlayer && playerType == "0") || (bMultiPlayer && playerType == "5") || playerType == "YES")) { debug(LOG_NEVER, "HUMAN (%d): %s id:%d enabled:%d", i, design.aName, design.multiPlayerID, design.enabled); design.prefab = false; addTemplateToList(&design, &apsDroidTemplates[i]); // This sets up the UI templates for display purposes ONLY--we still only use apsDroidTemplates for making them. // FIXME: Why are we doing this here, and not on demmand ? // Only add unique designs to the UI list (Note, perhaps better to use std::map instead?) std::list<DROID_TEMPLATE>::iterator it; for (it = localTemplates.begin(); it != localTemplates.end(); ++it) { DROID_TEMPLATE *psCurr = &*it; if (psCurr->multiPlayerID == design.multiPlayerID) { debug(LOG_NEVER, "Design id:%d (%s) *NOT* added to UI list (duplicate), player= %d", design.multiPlayerID, design.aName, i); break; } } if (it == localTemplates.end()) { debug(LOG_NEVER, "Design id:%d (%s) added to UI list, player =%d", design.multiPlayerID, design.aName, i); localTemplates.push_front(design); localTemplates.front().pName = strdup(localTemplates.front().pName); } } else if (NetPlay.players[i].allocated) //skip the ones not meant for puny humans { continue; } else // assume everything else is for AI { debug(LOG_NEVER, "AI (%d): %s id:%d enabled:%d", i, design.aName, design.multiPlayerID, design.enabled); design.prefab = true; // prefabricated templates referenced from VLOs addTemplateToList(&design, &apsDroidTemplates[i]); } } } debug(LOG_NEVER, "(default) Droid template found, aName: %s, MP ID: %d, ref: %u, pname: %s, prefab: %s, type:%d (loading)", design.aName, design.multiPlayerID, design.ref, design.pName, design.prefab ? "yes":"no", design.droidType); } ASSERT_OR_RETURN(false, bDefaultTemplateFound, "Default template not found"); return true; }