From 2b6a34c67cfa1743652a18901f8820ac3f250a57 Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Tue, 6 Apr 2010 18:57:52 +0000 Subject: [PATCH] Fix crash when `names.txt` does not contain template name. git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@10499 4a71c877-e1ca-e34f-864e-861f7616d084 --- src/droid.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/droid.c b/src/droid.c index 14ad177b6..0611109b2 100644 --- a/src/droid.c +++ b/src/droid.c @@ -83,6 +83,7 @@ #include "research.h" #include "combat.h" #include "scriptfuncs.h" //for ThreatInRange() +#include "design.h" //for GetDefaultTemplateName #define DEFAULT_RECOIL_TIME (GAME_TICKS_PER_SEC/4) #define DROID_DAMAGE_SPREAD (16 - rand()%32) @@ -1550,11 +1551,6 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize) pDroidDesign->pName = templName; sstrcpy(templName, componentName); - // Store translated name in aName - if (!getDroidResourceName(componentName)) - { - return false; - } sstrcpy(pDroidDesign->aName, componentName); //read in Body Name @@ -1816,6 +1812,18 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize) //check that not allocating more weapons than allowed ASSERT_OR_RETURN(false, pDroidDesign->numWeaps <= DROID_MAXWEAPS, "Too many weapons have been allocated for droid Template: %s", pDroidDesign->aName); + // Store translated name in aName + sstrcpy(componentName, pDroidDesign->aName); + if (getDroidResourceName(componentName)) + { + sstrcpy(pDroidDesign->aName, componentName); + } + else + { + sstrcpy(pDroidDesign->aName, GetDefaultTemplateName(pDroidDesign)); + } + + pDroidDesign->ref = REF_TEMPLATE_START + line; // Store global default design if found else store in the appropriate array if ( pDroidDesign->droidType == DROID_DEFAULT )