Use the unique, untranslated pName to identify templates, not anything else. (This would create trouble with translations.) Fixes bug #11345.

Cleanup loadDroidTemplates and loadDroidWeapons.


git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@4238 4a71c877-e1ca-e34f-864e-861f7616d084
master
Dennis Schridde 2008-03-23 13:17:30 +00:00
parent 6aa9b6fa35
commit 57afe59782
6 changed files with 183 additions and 228 deletions

View File

@ -272,7 +272,7 @@ extern W_SCREEN *psWScreen;
extern UDWORD objID; // unique ID creation thing.. extern UDWORD objID; // unique ID creation thing..
/* default droid design template */ /* default droid design template */
DROID_TEMPLATE sDefaultDesignTemplate; DROID_TEMPLATE sDefaultDesignTemplate;
extern void intDisplayPlainForm(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours); extern void intDisplayPlainForm(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours);
void desSetupDesignTemplates( void ); void desSetupDesignTemplates( void );

View File

@ -2077,61 +2077,42 @@ BOOL droidUpdateDroidRepair(DROID *psRepairDroid)
/* load the Droid stats for the components from the Access database */ /* load the Droid stats for the components from the Access database */
BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize) BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
{ {
const char *pStartDroidData; unsigned int NumDroids = numCR(pDroidData, bufferSize), line;
int cnt; BOOL bDefaultTemplateFound = FALSE;
UDWORD NumDroids = 0, i, player;
char componentName[MAX_STR_LENGTH];
BOOL found = FALSE; //,EndOfFile;
DROID_TEMPLATE *pDroidDesign;
COMP_BASE_STATS *pStats;
UDWORD size, inc, templateID;
BOOL bDefaultTemplateFound = FALSE;
UDWORD id;
/* init default template */ /* init default template */
memset( &sDefaultDesignTemplate, 0, sizeof(DROID_TEMPLATE) ); memset( &sDefaultDesignTemplate, 0, sizeof(DROID_TEMPLATE) );
pStartDroidData = pDroidData; for (line = 0; line < NumDroids; line++)
NumDroids = numCR(pDroidData, bufferSize);
for (i=0; i < NumDroids; i++)
{ {
pDroidDesign = malloc(sizeof(DROID_TEMPLATE)); char componentName[MAX_STR_LENGTH];
unsigned int cnt, player;
DROID_TEMPLATE *pDroidDesign = malloc(sizeof(DROID_TEMPLATE));
if (pDroidDesign == NULL) if (pDroidDesign == NULL)
{ {
debug(LOG_ERROR, "loadDroidTemplates: Out of memory"); debug(LOG_ERROR, "loadDroidTemplates: pDroidDesign: Out of memory");
return FALSE; return FALSE;
} }
memset(pDroidDesign, 0, sizeof(DROID_TEMPLATE)); memset(pDroidDesign, 0, sizeof(DROID_TEMPLATE));
pDroidDesign->pName = NULL;
//read the data into the storage - the data is delimited using comma's //read the data into the storage - the data is delimited using comma's
componentName[0] = '\0'; sscanf(pDroidData, "%[^','],%d,%n", componentName, &pDroidDesign->multiPlayerID, &cnt);
sscanf(pDroidData, "%[^','],%d,%n", componentName, &templateID, &cnt); pDroidData += cnt;
pDroidData += cnt;
/*ALWAYS get the name associated with the resource for PC regardless // Store unique name in pName
of STORE_RESOURCE_ID or RESOURCE_NAMES! - 25/06/98 AB*/ pDroidDesign->pName = strdup(componentName);
if (!strresGetIDNum(psStringRes, componentName, &id))
// Store translated name in aName
if (!getDroidResourceName(componentName))
{ {
debug(LOG_ERROR, "Unable to find string resource for %s", componentName);
return FALSE; return FALSE;
} }
strlcpy(pDroidDesign->aName, componentName, sizeof(pDroidDesign->aName));
//get the string from the id and copy into the Name space
strlcpy(pDroidDesign->aName, strresGetString(psStringRes, id), sizeof(pDroidDesign->aName));
//store the unique template id
pDroidDesign->multiPlayerID = templateID;
//read in Body Name //read in Body Name
componentName[0] = '\0';
sscanf(pDroidData, "%[^','],%n", componentName, &cnt); sscanf(pDroidData, "%[^','],%n", componentName, &cnt);
pDroidData += cnt; pDroidData += cnt;
found = FALSE;
//get the Body stats pointer //get the Body stats pointer
if (!strcmp(componentName,"0")) if (!strcmp(componentName,"0"))
{ {
@ -2139,14 +2120,17 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
} }
else else
{ {
pStats = (COMP_BASE_STATS *)asBodyStats; COMP_BASE_STATS *pStats = (COMP_BASE_STATS *)asBodyStats;
size = sizeof(BODY_STATS); unsigned int size = sizeof(BODY_STATS);
unsigned int inc = 0;
BOOL found = FALSE;
if (!getResourceName(componentName)) if (!getResourceName(componentName))
{ {
return FALSE; return FALSE;
} }
for (inc=0; inc < numBodyStats; inc++) for (inc = 0; inc < numBodyStats; inc++)
{ {
//compare the names //compare the names
if (!strcmp(componentName, pStats->pName)) if (!strcmp(componentName, pStats->pName))
@ -2166,10 +2150,8 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
} }
//read in Brain Name //read in Brain Name
found = FALSE;
componentName[0] = '\0';
sscanf(pDroidData, "%[^','],%n", componentName, &cnt); sscanf(pDroidData, "%[^','],%n", componentName, &cnt);
pDroidData += cnt; pDroidData += cnt;
//get the Brain stats pointer //get the Brain stats pointer
if (!strcmp(componentName,"0")) if (!strcmp(componentName,"0"))
@ -2178,8 +2160,11 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
} }
else else
{ {
pStats = (COMP_BASE_STATS *)asBrainStats; COMP_BASE_STATS *pStats = (COMP_BASE_STATS *)asBrainStats;
size = sizeof(BRAIN_STATS); unsigned int size = sizeof(BRAIN_STATS);
unsigned int inc = 0;
BOOL found = FALSE;
if (!getResourceName(componentName)) if (!getResourceName(componentName))
{ {
return FALSE; return FALSE;
@ -2206,10 +2191,8 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
} }
//read in Construct Name //read in Construct Name
found = FALSE;
componentName[0] = '\0';
sscanf(pDroidData, "%[^','],%n", componentName, &cnt); sscanf(pDroidData, "%[^','],%n", componentName, &cnt);
pDroidData += cnt; pDroidData += cnt;
//get the Construct stats pointer //get the Construct stats pointer
if (!strcmp(componentName,"0")) if (!strcmp(componentName,"0"))
@ -2218,8 +2201,11 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
} }
else else
{ {
pStats = (COMP_BASE_STATS *)asConstructStats; COMP_BASE_STATS *pStats = (COMP_BASE_STATS *)asConstructStats;
size = sizeof(CONSTRUCT_STATS); unsigned int size = sizeof(CONSTRUCT_STATS);
unsigned int inc = 0;
BOOL found = FALSE;
if (!getResourceName(componentName)) if (!getResourceName(componentName))
{ {
return FALSE; return FALSE;
@ -2244,10 +2230,8 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
} }
//read in Ecm Name //read in Ecm Name
found = FALSE;
componentName[0] = '\0';
sscanf(pDroidData, "%[^','],%n", componentName, &cnt); sscanf(pDroidData, "%[^','],%n", componentName, &cnt);
pDroidData += cnt; pDroidData += cnt;
//get the Ecm stats pointer //get the Ecm stats pointer
if (!strcmp(componentName,"0")) if (!strcmp(componentName,"0"))
@ -2256,8 +2240,11 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
} }
else else
{ {
pStats = (COMP_BASE_STATS *)asECMStats; COMP_BASE_STATS *pStats = (COMP_BASE_STATS *)asECMStats;
size = sizeof(ECM_STATS); unsigned int size = sizeof(ECM_STATS);
unsigned int inc = 0;
BOOL found = FALSE;
if (!getResourceName(componentName)) if (!getResourceName(componentName))
{ {
return FALSE; return FALSE;
@ -2283,13 +2270,18 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
//read in player id - Access decides the order -crap hey? //read in player id - Access decides the order -crap hey?
sscanf(pDroidData, "%d,%n", &player,&cnt); sscanf(pDroidData, "%d,%n", &player,&cnt);
pDroidData += cnt; pDroidData += cnt;
if (getTemplateFromUniqueName(pDroidDesign->pName, player))
{
debug( LOG_ERROR, "Duplicate template %s", pDroidDesign->pName );
abort();
return FALSE;
}
//read in Propulsion Name //read in Propulsion Name
found = FALSE;
componentName[0] = '\0';
sscanf(pDroidData, "%[^','],%n", componentName, &cnt); sscanf(pDroidData, "%[^','],%n", componentName, &cnt);
pDroidData += cnt; pDroidData += cnt;
//get the Propulsion stats pointer //get the Propulsion stats pointer
if (!strcmp(componentName,"0")) if (!strcmp(componentName,"0"))
@ -2298,8 +2290,11 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
} }
else else
{ {
pStats = (COMP_BASE_STATS *)asPropulsionStats; COMP_BASE_STATS *pStats = (COMP_BASE_STATS *)asPropulsionStats;
size = sizeof(PROPULSION_STATS); unsigned int size = sizeof(PROPULSION_STATS);
unsigned int inc = 0;
BOOL found = FALSE;
if (!getResourceName(componentName)) if (!getResourceName(componentName))
{ {
return FALSE; return FALSE;
@ -2324,10 +2319,8 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
} }
//read in Repair Name //read in Repair Name
found = FALSE;
componentName[0] = '\0';
sscanf(pDroidData, "%[^','],%n", componentName, &cnt); sscanf(pDroidData, "%[^','],%n", componentName, &cnt);
pDroidData += cnt; pDroidData += cnt;
//get the Repair stats pointer //get the Repair stats pointer
if (!strcmp(componentName,"0")) if (!strcmp(componentName,"0"))
@ -2336,8 +2329,11 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
} }
else else
{ {
pStats = (COMP_BASE_STATS *)asRepairStats; COMP_BASE_STATS *pStats = (COMP_BASE_STATS *)asRepairStats;
size = sizeof(REPAIR_STATS); unsigned int size = sizeof(REPAIR_STATS);
unsigned int inc = 0;
BOOL found = FALSE;
if (!getResourceName(componentName)) if (!getResourceName(componentName))
{ {
return FALSE; return FALSE;
@ -2362,9 +2358,9 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
} }
//read in droid type - only interested if set to PERSON //read in droid type - only interested if set to PERSON
componentName[0] = '\0';
sscanf(pDroidData, "%[^','],%n", componentName, &cnt); sscanf(pDroidData, "%[^','],%n", componentName, &cnt);
pDroidData += cnt; pDroidData += cnt;
if (!strcmp(componentName, "PERSON")) if (!strcmp(componentName, "PERSON"))
{ {
pDroidDesign->droidType = DROID_PERSON; pDroidDesign->droidType = DROID_PERSON;
@ -2394,13 +2390,10 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
pDroidDesign->droidType = DROID_DEFAULT; pDroidDesign->droidType = DROID_DEFAULT;
bDefaultTemplateFound = TRUE; bDefaultTemplateFound = TRUE;
} }
//pDroidData += (strlen(componentName)+1);
//read in Sensor Name //read in Sensor Name
found = FALSE;
componentName[0] = '\0';
sscanf(pDroidData, "%[^','],%n", componentName, &cnt); sscanf(pDroidData, "%[^','],%n", componentName, &cnt);
pDroidData += cnt; pDroidData += cnt;
//get the Sensor stats pointer //get the Sensor stats pointer
if (!strcmp(componentName,"0")) if (!strcmp(componentName,"0"))
@ -2409,8 +2402,11 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
} }
else else
{ {
pStats = (COMP_BASE_STATS *)asSensorStats; COMP_BASE_STATS *pStats = (COMP_BASE_STATS *)asSensorStats;
size = sizeof(SENSOR_STATS); unsigned int size = sizeof(SENSOR_STATS);
unsigned int inc = 0;
BOOL found = FALSE;
if (!getResourceName(componentName)) if (!getResourceName(componentName))
{ {
return FALSE; return FALSE;
@ -2442,7 +2438,7 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
//check that not allocating more weapons than allowed //check that not allocating more weapons than allowed
//Watermelon:disable this check for now //Watermelon:disable this check for now
/* if (((asBodyStats + pDroidDesign->asParts[COMP_BODY])->weaponSlots < /* if (((asBodyStats + pDroidDesign->asParts[COMP_BODY])->weaponSlots <
pDroidDesign->numWeaps) || */ pDroidDesign->numWeaps) || */
if (pDroidDesign->numWeaps > DROID_MAXWEAPS) if (pDroidDesign->numWeaps > DROID_MAXWEAPS)
{ {
debug( LOG_ERROR, "Too many weapons have been allocated for droid Template: %s", pDroidDesign->aName ); debug( LOG_ERROR, "Too many weapons have been allocated for droid Template: %s", pDroidDesign->aName );
@ -2451,13 +2447,13 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
} }
pDroidDesign->ref = REF_TEMPLATE_START + i; pDroidDesign->ref = REF_TEMPLATE_START + line;
/* Loaded in from the database now AB 29/10/98 /* Loaded in from the database now AB 29/10/98
pDroidDesign->multiPlayerID = i; // another unique number, just for multiplayer stuff. pDroidDesign->multiPlayerID = i; // another unique number, just for multiplayer stuff.
*/ */
/* store global default design if found else /* store global default design if found else
* store in the appropriate array * store in the appropriate array
*/ */
if ( pDroidDesign->droidType == DROID_DEFAULT ) if ( pDroidDesign->droidType == DROID_DEFAULT )
{ {
memcpy( &sDefaultDesignTemplate, pDroidDesign, sizeof(DROID_TEMPLATE) ); memcpy( &sDefaultDesignTemplate, pDroidDesign, sizeof(DROID_TEMPLATE) );
@ -2473,9 +2469,6 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
pDroidData = strchr(pDroidData,'\n') + 1; pDroidData = strchr(pDroidData,'\n') + 1;
pDroidDesign++; pDroidDesign++;
} }
// free(pStartDroidData);
if ( bDefaultTemplateFound == FALSE ) if ( bDefaultTemplateFound == FALSE )
{ {
@ -2624,81 +2617,35 @@ DROID_TYPE droidTemplateType(DROID_TEMPLATE *psTemplate)
} }
//Load the weapons assigned to Droids in the Access database //Load the weapons assigned to Droids in the Access database
//Watermelon:reads 3 WeaponName for now?
BOOL loadDroidWeapons(const char *pWeaponData, UDWORD bufferSize) BOOL loadDroidWeapons(const char *pWeaponData, UDWORD bufferSize)
{ {
const char *pStartWeaponData; unsigned int NumWeapons = numCR(pWeaponData, bufferSize);
UDWORD NumWeapons = 0, i, player; unsigned int SkippedWeaponCount = 0;
char WeaponName[MAX_STR_LENGTH], TemplateName[MAX_STR_LENGTH]; unsigned int line = 0;
//Watermelon:TODO:fix this temp naming one day,WeaponName[DROID_MAXWEAPS][MAX_STR_LENGTH] causes stack corruption
char WeaponNameA[MAX_STR_LENGTH],WeaponNameB[MAX_STR_LENGTH];
UBYTE j;
DROID_TEMPLATE *pTemplate;
BOOL recFound;
UWORD SkippedWeaponCount=0;
SDWORD incW[DROID_MAXWEAPS];
//initialise the store count variable ASSERT(NumWeapons > 0, "template without weapons");
for (player=0; player < MAX_PLAYERS; player++)
for (line = 0; line < NumWeapons; line++)
{ {
for(pTemplate = apsDroidTemplates[player]; pTemplate != NULL; unsigned int player = 0;
pTemplate = pTemplate->psNext) char WeaponName[DROID_MAXWEAPS][MAX_STR_LENGTH] = {{'\0'}},
{ TemplateName[MAX_STR_LENGTH] = {'\0'};
//clear the storage flags
pTemplate->storeCount = 0;
}
}
pStartWeaponData = pWeaponData;
NumWeapons = numCR(pWeaponData, bufferSize);
ASSERT(NumWeapons>0, "template without weapons");
for (i=0; i < NumWeapons; i++)
{
recFound = FALSE;
//read the data into the storage - the data is delimeted using comma's //read the data into the storage - the data is delimeted using comma's
TemplateName[0] = '\0'; sscanf(pWeaponData, "%[^','],%[^','],%[^','],%[^','],%d",
WeaponName[0] = '\0'; TemplateName, WeaponName[0], WeaponName[1], WeaponName[2], &player);
WeaponNameA[0] = '\0';
WeaponNameB[0] = '\0';
//Watermelon:kcah
sscanf(pWeaponData,"%[^','],%[^','],%[^','],%[^','],%d", TemplateName, WeaponName, WeaponNameA, WeaponNameB, &player);
//loop through each droid to compare the name
/*if (!getResourceName(TemplateName))
{
return FALSE;
}*/
if (!getDroidResourceName(TemplateName))
{
return FALSE;
}
if (!getResourceName(WeaponName))
{
return FALSE;
}
if (player < MAX_PLAYERS) if (player < MAX_PLAYERS)
{ {
for(pTemplate = apsDroidTemplates[player]; pTemplate != NULL; pTemplate = unsigned int j = 0;
pTemplate->psNext)
{ DROID_TEMPLATE *pTemplate = getTemplateFromUniqueName(TemplateName, player);
if (!(strcmp(TemplateName, pTemplate->aName)))
{
//Template found
recFound = TRUE;
break;
}
}
/* if Template not found - try default design */ /* if Template not found - try default design */
if (!recFound) if (!pTemplate)
{ {
pTemplate = &sDefaultDesignTemplate; pTemplate = &sDefaultDesignTemplate;
if ( strcmp(TemplateName, pTemplate->aName) ) if ( strcmp(TemplateName, pTemplate->pName) != 0 )
{ {
debug( LOG_ERROR, "Unable to find Template - %s", TemplateName ); debug( LOG_ERROR, "Unable to find Template - %s", TemplateName );
abort(); abort();
@ -2706,35 +2653,34 @@ BOOL loadDroidWeapons(const char *pWeaponData, UDWORD bufferSize)
} }
} }
for (j = 0;j < pTemplate->numWeaps;j++) ASSERT(pTemplate->numWeaps <= DROID_MAXWEAPS, "stack corruption unavoidable");
for (j = 0; j < pTemplate->numWeaps; j++)
{ {
//Watermelon:test int incWpn;
if (j == 0)
if (!getResourceName(WeaponName[j]))
{ {
incW[j] = getCompFromName(COMP_WEAPON, WeaponName); return FALSE;
}
else if (j == 1)
{
incW[j] = getCompFromName(COMP_WEAPON, WeaponNameA);
}
else if (j == 2)
{
incW[j] = getCompFromName(COMP_WEAPON, WeaponNameB);
} }
incWpn = getCompFromName(COMP_WEAPON, WeaponName[j]);
//if weapon not found - error //if weapon not found - error
if (incW[j] == -1) if (incWpn == -1)
{ {
debug( LOG_ERROR, "Unable to find Weapon %s for template %s", WeaponNameA, TemplateName ); debug( LOG_ERROR, "Unable to find Weapon %s for template %s",
WeaponName[j], TemplateName );
abort(); abort();
return FALSE; return FALSE;
} }
else else
{ {
//Weapon found, alloc this to the current Template //Weapon found, alloc this to the current Template
pTemplate->asWeaps[pTemplate->storeCount] = incW[j]; pTemplate->asWeaps[pTemplate->storeCount] = incWpn;
//check not allocating more than allowed //check not allocating more than allowed
if (pTemplate->storeCount > if (pTemplate->storeCount > pTemplate->numWeaps)
pTemplate->numWeaps)
{ {
debug( LOG_ERROR, "Trying to allocate more weapons than allowed for Template - %s", TemplateName ); debug( LOG_ERROR, "Trying to allocate more weapons than allowed for Template - %s", TemplateName );
abort(); abort();
@ -2743,7 +2689,6 @@ BOOL loadDroidWeapons(const char *pWeaponData, UDWORD bufferSize)
//check valid weapon/propulsion //check valid weapon/propulsion
if (!checkValidWeaponForProp(pTemplate)) if (!checkValidWeaponForProp(pTemplate))
{ {
// ffs
debug( LOG_ERROR, "Weapon is invalid for air propulsion for template %s", pTemplate->aName ); debug( LOG_ERROR, "Weapon is invalid for air propulsion for template %s", pTemplate->aName );
abort(); abort();
@ -2760,37 +2705,38 @@ BOOL loadDroidWeapons(const char *pWeaponData, UDWORD bufferSize)
} }
//increment the pointer to the start of the next record //increment the pointer to the start of the next record
pWeaponData = strchr(pWeaponData,'\n') + 1; pWeaponData = strchr(pWeaponData, '\n') + 1;
} }
if (SkippedWeaponCount > 0) if (SkippedWeaponCount > 0)
{ {
debug( LOG_ERROR, "Illegal player number in %d droid weapons", SkippedWeaponCount ); debug( LOG_ERROR, "Illegal player number in %d droid weapons", SkippedWeaponCount );
abort(); abort();
} }
// free(pStartWeaponData);
return TRUE; return TRUE;
} }
//free the storage for the droid templates //free the storage for the droid templates
BOOL droidTemplateShutDown(void) BOOL droidTemplateShutDown(void)
{ {
DROID_TEMPLATE *pTemplate, *pNext; unsigned int player;
UDWORD player;
for (player = 0; player < MAX_PLAYERS; player++) for (player = 0; player < MAX_PLAYERS; player++)
{ {
DROID_TEMPLATE *pTemplate, *pNext;
for(pTemplate = apsDroidTemplates[player]; pTemplate != NULL; for(pTemplate = apsDroidTemplates[player]; pTemplate != NULL;
pTemplate = pNext) pTemplate = pNext)
{ {
pNext = pTemplate->psNext; pNext = pTemplate->psNext;
free(pTemplate->pName);
free(pTemplate); free(pTemplate);
} }
apsDroidTemplates[player] = NULL; apsDroidTemplates[player] = NULL;
} }
free(sDefaultDesignTemplate.pName);
return TRUE; return TRUE;
} }
@ -3389,7 +3335,7 @@ void droidSetBits(DROID_TEMPLATE *pTemplate,DROID *psDroid)
// Sets the parts array in a template given a droid. // Sets the parts array in a template given a droid.
static void templateSetParts(DROID *psDroid,DROID_TEMPLATE *psTemplate) static void templateSetParts(const DROID *psDroid, DROID_TEMPLATE *psTemplate)
{ {
UDWORD inc; UDWORD inc;
psTemplate->numWeaps = 0; psTemplate->numWeaps = 0;
@ -3397,7 +3343,7 @@ static void templateSetParts(DROID *psDroid,DROID_TEMPLATE *psTemplate)
psTemplate->droidType = psDroid->droidType; psTemplate->droidType = psDroid->droidType;
//Watermelon:can only have DROID_MAXWEAPS weapon now //Watermelon:can only have DROID_MAXWEAPS weapon now
for (inc = 0;inc < DROID_MAXWEAPS;inc++) for (inc = 0; inc < DROID_MAXWEAPS; inc++)
{ {
//Watermelon:this should fix the NULL weapon stats for empty weaponslots //Watermelon:this should fix the NULL weapon stats for empty weaponslots
psTemplate->asWeaps[inc] = 0; psTemplate->asWeaps[inc] = 0;
@ -3800,55 +3746,70 @@ BOOL calcDroidMuzzleLocation(DROID *psDroid, Vector3i *muzzle, int weapon_slot)
return TRUE; return TRUE;
} }
/* IF YOU USE THIS FUNCTION - NOTE THAT selectedPlayer's TEMPLATES ARE NOT USED!!!!
gets a template from its name - relies on the name being unique (or it will /*!
return the first one it finds!! */ * Gets a template from its name
DROID_TEMPLATE * getTemplateFromName(char *pName) * relies on the name being unique (or it will return the first one it finds!)
* \param pName Template name
* \param player Player number
* \pre pName has to be the unique, untranslated name!
* \pre player \< MAX_PLAYERS
*/
DROID_TEMPLATE * getTemplateFromUniqueName(const char *pName, unsigned int player)
{ {
UDWORD player; DROID_TEMPLATE *psCurr;
DROID_TEMPLATE *psCurr;
for (psCurr = apsDroidTemplates[player]; psCurr != NULL; psCurr = psCurr->psNext)
{
if (strcmp(psCurr->pName, pName) == 0)
{
return psCurr;
}
}
return NULL;
}
/*!
* Gets a template from its name
* relies on the name being unique (or it will return the first one it finds!)
* \param pName Template name
* \pre pName has to be the unique, untranslated name!
* \post pName will be translated via getDroidResourceName()!
* \warning IF YOU USE THIS FUNCTION - NOTE THAT selectedPlayer's TEMPLATES ARE NOT USED!!!!
*/
DROID_TEMPLATE * getTemplateFromTranslatedNameNoPlayer(char *pName)
{
unsigned int player;
/*all droid and template names are now stored as the translated /*all droid and template names are now stored as the translated
name regardless of RESOURCE_NAMES and STORE_RESOURCE_ID! - AB 26/06/98*/ name regardless of RESOURCE_NAMES and STORE_RESOURCE_ID! - AB 26/06/98*/
getDroidResourceName(pName); getDroidResourceName(pName);
for (player = 0; player < MAX_PLAYERS; player++) for (player = 0; player < MAX_PLAYERS; player++)
{ {
//OK so we want selectedPlayer's CYBORG templates since they cannot be edited DROID_TEMPLATE *psCurr;
//and we don't want to duplicate them for the sake of it! (ha!) // OK so we want selectedPlayer's CYBORG templates since they cannot be edited
//don't use selectedPlayer's templates if not multiplayer // and we don't want to duplicate them for the sake of it! (ha!)
//this was written for use in the scripts and we don't want the scripts to use // don't use selectedPlayer's templates if not multiplayer
//selectedPlayer's templates because we cannot guarentee they will exist! // this was written for use in the scripts and we don't want the scripts to use
/* // selectedPlayer's templates because we cannot guarentee they will exist!
if (!bMultiPlayer)
{
if (player == selectedPlayer)
{
continue;
}
}
*/
for (psCurr = apsDroidTemplates[player]; psCurr != NULL; psCurr = psCurr->psNext) for (psCurr = apsDroidTemplates[player]; psCurr != NULL; psCurr = psCurr->psNext)
{ {
if (!strcmp(psCurr->aName, pName)) if (strcmp(psCurr->aName, pName) == 0)
{ {
//if template is selectedPlayers' it must be a CYBORG or we ignore it //if template is selectedPlayers' it must be a CYBORG or we ignore it
if (!bMultiPlayer &&
if (!bMultiPlayer) player == selectedPlayer &&
!(psCurr->droidType == DROID_CYBORG ||
{ psCurr->droidType == DROID_CYBORG_SUPER ||
//if (player == selectedPlayer && psCurr->droidType != DROID_CYBORG) psCurr->droidType == DROID_CYBORG_CONSTRUCT ||
if (player == selectedPlayer && psCurr->droidType == DROID_CYBORG_REPAIR))
!(psCurr->droidType == DROID_CYBORG || {
psCurr->droidType == DROID_CYBORG_SUPER || //ignore
psCurr->droidType == DROID_CYBORG_CONSTRUCT || continue;
psCurr->droidType == DROID_CYBORG_REPAIR)) }
{
//ignore
continue;
}
}
return psCurr; return psCurr;
} }
} }
@ -4595,11 +4556,11 @@ void setUpBuildModule(DROID *psDroid)
} }
} }
char *getDroidName(DROID *psDroid) const char *getDroidName(const DROID *psDroid)
{ {
DROID_TEMPLATE sTemplate; DROID_TEMPLATE sTemplate;
templateSetParts(psDroid,&sTemplate); templateSetParts(psDroid, &sTemplate);
return getTemplateName(&sTemplate); return getTemplateName(&sTemplate);
} }
@ -4608,29 +4569,24 @@ char *getDroidName(DROID *psDroid)
/*return the name to display for the interface - we don't know if this is /*return the name to display for the interface - we don't know if this is
a string ID or something the user types in*/ a string ID or something the user types in*/
char* getTemplateName(DROID_TEMPLATE *psTemplate) const char* getTemplateName(const DROID_TEMPLATE *psTemplate)
{ {
char *pNameID = psTemplate->aName; const char *pNameID = psTemplate->aName;
UDWORD id; unsigned int id;
char *pName = NULL;
/*see if the name has a resource associated with it by trying to get /*see if the name has a resource associated with it by trying to get
the ID for the string*/ the ID for the string*/
if (strresGetIDNum(psStringRes, pNameID, &id)) if (strresGetIDNum(psStringRes, pNameID, &id))
{ {
//get the string from the id //get the string from the id
pName = strresGetString(psStringRes, id); const char *pName = strresGetString(psStringRes, id);
if (pName) if (pName)
{ {
return pName; return pName;
} }
} }
//if haven't found a resource, return the name passed in //if haven't found a resource, return the name passed in
if (!pName) return pNameID;
{
return pNameID;
}
return NULL;
} }
/* Just returns true if the droid's present body points aren't as high as the original*/ /* Just returns true if the droid's present body points aren't as high as the original*/
@ -4649,7 +4605,7 @@ BOOL droidIsDamaged(DROID *psDroid)
BOOL getDroidResourceName(char *pName) BOOL getDroidResourceName(char *pName)
{ {
UDWORD id; unsigned int id;
//see if the name has a resource associated with it by trying to get the ID for the string //see if the name has a resource associated with it by trying to get the ID for the string
if (!strresGetIDNum(psStringRes, pName, &id)) if (!strresGetIDNum(psStringRes, pName, &id))

View File

@ -235,7 +235,9 @@ extern BOOL activateGroupAndMove(UDWORD playerNumber, UDWORD groupNumber);
extern BOOL calcDroidMuzzleLocation(DROID *psDroid, Vector3i *muzzle, int weapon_slot); extern BOOL calcDroidMuzzleLocation(DROID *psDroid, Vector3i *muzzle, int weapon_slot);
/* gets a template from its name - relies on the name being unique */ /* gets a template from its name - relies on the name being unique */
extern DROID_TEMPLATE* getTemplateFromName(char *pName); extern DROID_TEMPLATE * getTemplateFromUniqueName(const char *pName, unsigned int player);
/* gets a template from its name - relies on the name being unique */
extern DROID_TEMPLATE* getTemplateFromTranslatedNameNoPlayer(char *pName);
/*getTemplateFromSinglePlayerID gets template for unique ID searching one players list */ /*getTemplateFromSinglePlayerID gets template for unique ID searching one players list */
extern DROID_TEMPLATE* getTemplateFromSinglePlayerID(UDWORD multiPlayerID, UDWORD player); extern DROID_TEMPLATE* getTemplateFromSinglePlayerID(UDWORD multiPlayerID, UDWORD player);
/*getTemplateFromMultiPlayerID gets template for unique ID searching all lists */ /*getTemplateFromMultiPlayerID gets template for unique ID searching all lists */
@ -294,11 +296,11 @@ extern BOOL buildModule(STRUCTURE *psStruct);
extern void setUpBuildModule(DROID *psDroid); extern void setUpBuildModule(DROID *psDroid);
/*return the name to display for the interface given a DROID structure*/ /*return the name to display for the interface given a DROID structure*/
extern char* getDroidName(DROID *psDroid); extern const char* getDroidName(const DROID *psDroid) WZ_DECL_UNUSED;
/*return the name to display for the interface - we don't know if this is /*return the name to display for the interface - we don't know if this is
a string ID or something the user types in*/ a string ID or something the user types in*/
extern char* getTemplateName(DROID_TEMPLATE *psTemplate); extern const char* getTemplateName(const DROID_TEMPLATE *psTemplate);
/* Just returns true if the droid's present body points aren't as high as the original*/ /* Just returns true if the droid's present body points aren't as high as the original*/
extern BOOL droidIsDamaged(DROID *psDroid); extern BOOL droidIsDamaged(DROID *psDroid);

View File

@ -35,7 +35,7 @@
#define DROID_MAXCOMP (COMP_NUMCOMPONENTS - 1)//(COMP_NUMCOMPONENTS - 2) #define DROID_MAXCOMP (COMP_NUMCOMPONENTS - 1)//(COMP_NUMCOMPONENTS - 2)
/* The maximum number of droid weapons */ /* The maximum number of droid weapons */
#define DROID_MAXWEAPS 3//Watermelon:its 3 again now #define DROID_MAXWEAPS 3
#define DROID_DAMAGE_SCALING 400 #define DROID_DAMAGE_SCALING 400
// This should really be logarithmic // This should really be logarithmic
#define CALC_DROID_SMOKE_INTERVAL(x) ((((100-x)+10)/10) * DROID_DAMAGE_SCALING) #define CALC_DROID_SMOKE_INTERVAL(x) ((((100-x)+10)/10) * DROID_DAMAGE_SCALING)

View File

@ -394,9 +394,6 @@ BASE_OBJECT **apsListToOrder;
#define ORDERED_LIST_SIZE (NUM_FACTORY_TYPES * MAX_FACTORY) #define ORDERED_LIST_SIZE (NUM_FACTORY_TYPES * MAX_FACTORY)
/* default droid design template */
extern DROID_TEMPLATE sDefaultDesignTemplate;
/* The current design being edited on the design screen */ /* The current design being edited on the design screen */
extern DROID_TEMPLATE sCurrDesign; extern DROID_TEMPLATE sCurrDesign;

View File

@ -507,7 +507,7 @@ var_init: var_entry TYPE var_value
scrv_error("Typemismatch for variable %d", $1); scrv_error("Typemismatch for variable %d", $1);
YYABORT; YYABORT;
} }
data.v.oval = getTemplateFromName($3.pString); /* store pointer to the template */ data.v.oval = getTemplateFromTranslatedNameNoPlayer($3.pString); /* store pointer to the template */
if (data.v.oval == NULL) if (data.v.oval == NULL)
{ {
scrv_error("Template %s not found", $3.pString); scrv_error("Template %s not found", $3.pString);