|
|
|
@ -2077,61 +2077,42 @@ BOOL droidUpdateDroidRepair(DROID *psRepairDroid)
|
|
|
|
|
/* load the Droid stats for the components from the Access database */
|
|
|
|
|
BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
|
|
|
|
|
{
|
|
|
|
|
const char *pStartDroidData;
|
|
|
|
|
int cnt;
|
|
|
|
|
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;
|
|
|
|
|
unsigned int NumDroids = numCR(pDroidData, bufferSize), line;
|
|
|
|
|
BOOL bDefaultTemplateFound = FALSE;
|
|
|
|
|
|
|
|
|
|
/* init default template */
|
|
|
|
|
memset( &sDefaultDesignTemplate, 0, sizeof(DROID_TEMPLATE) );
|
|
|
|
|
|
|
|
|
|
pStartDroidData = pDroidData;
|
|
|
|
|
|
|
|
|
|
NumDroids = numCR(pDroidData, bufferSize);
|
|
|
|
|
|
|
|
|
|
for (i=0; i < NumDroids; i++)
|
|
|
|
|
for (line = 0; line < NumDroids; line++)
|
|
|
|
|
{
|
|
|
|
|
pDroidDesign = malloc(sizeof(DROID_TEMPLATE));
|
|
|
|
|
char componentName[MAX_STR_LENGTH];
|
|
|
|
|
unsigned int cnt, player;
|
|
|
|
|
DROID_TEMPLATE *pDroidDesign = malloc(sizeof(DROID_TEMPLATE));
|
|
|
|
|
if (pDroidDesign == NULL)
|
|
|
|
|
{
|
|
|
|
|
debug(LOG_ERROR, "loadDroidTemplates: Out of memory");
|
|
|
|
|
debug(LOG_ERROR, "loadDroidTemplates: pDroidDesign: Out of memory");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
memset(pDroidDesign, 0, sizeof(DROID_TEMPLATE));
|
|
|
|
|
|
|
|
|
|
pDroidDesign->pName = NULL;
|
|
|
|
|
|
|
|
|
|
//read the data into the storage - the data is delimited using comma's
|
|
|
|
|
componentName[0] = '\0';
|
|
|
|
|
sscanf(pDroidData, "%[^','],%d,%n", componentName, &templateID, &cnt);
|
|
|
|
|
pDroidData += cnt;
|
|
|
|
|
sscanf(pDroidData, "%[^','],%d,%n", componentName, &pDroidDesign->multiPlayerID, &cnt);
|
|
|
|
|
pDroidData += cnt;
|
|
|
|
|
|
|
|
|
|
/*ALWAYS get the name associated with the resource for PC regardless
|
|
|
|
|
of STORE_RESOURCE_ID or RESOURCE_NAMES! - 25/06/98 AB*/
|
|
|
|
|
if (!strresGetIDNum(psStringRes, componentName, &id))
|
|
|
|
|
// Store unique name in pName
|
|
|
|
|
pDroidDesign->pName = strdup(componentName);
|
|
|
|
|
|
|
|
|
|
// Store translated name in aName
|
|
|
|
|
if (!getDroidResourceName(componentName))
|
|
|
|
|
{
|
|
|
|
|
debug(LOG_ERROR, "Unable to find string resource for %s", componentName);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//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;
|
|
|
|
|
strlcpy(pDroidDesign->aName, componentName, sizeof(pDroidDesign->aName));
|
|
|
|
|
|
|
|
|
|
//read in Body Name
|
|
|
|
|
componentName[0] = '\0';
|
|
|
|
|
sscanf(pDroidData, "%[^','],%n", componentName, &cnt);
|
|
|
|
|
pDroidData += cnt;
|
|
|
|
|
pDroidData += cnt;
|
|
|
|
|
|
|
|
|
|
found = FALSE;
|
|
|
|
|
//get the Body stats pointer
|
|
|
|
|
if (!strcmp(componentName,"0"))
|
|
|
|
|
{
|
|
|
|
@ -2139,14 +2120,17 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pStats = (COMP_BASE_STATS *)asBodyStats;
|
|
|
|
|
size = sizeof(BODY_STATS);
|
|
|
|
|
COMP_BASE_STATS *pStats = (COMP_BASE_STATS *)asBodyStats;
|
|
|
|
|
unsigned int size = sizeof(BODY_STATS);
|
|
|
|
|
unsigned int inc = 0;
|
|
|
|
|
BOOL found = FALSE;
|
|
|
|
|
|
|
|
|
|
if (!getResourceName(componentName))
|
|
|
|
|
{
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (inc=0; inc < numBodyStats; inc++)
|
|
|
|
|
for (inc = 0; inc < numBodyStats; inc++)
|
|
|
|
|
{
|
|
|
|
|
//compare the names
|
|
|
|
|
if (!strcmp(componentName, pStats->pName))
|
|
|
|
@ -2166,10 +2150,8 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//read in Brain Name
|
|
|
|
|
found = FALSE;
|
|
|
|
|
componentName[0] = '\0';
|
|
|
|
|
sscanf(pDroidData, "%[^','],%n", componentName, &cnt);
|
|
|
|
|
pDroidData += cnt;
|
|
|
|
|
pDroidData += cnt;
|
|
|
|
|
|
|
|
|
|
//get the Brain stats pointer
|
|
|
|
|
if (!strcmp(componentName,"0"))
|
|
|
|
@ -2178,8 +2160,11 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pStats = (COMP_BASE_STATS *)asBrainStats;
|
|
|
|
|
size = sizeof(BRAIN_STATS);
|
|
|
|
|
COMP_BASE_STATS *pStats = (COMP_BASE_STATS *)asBrainStats;
|
|
|
|
|
unsigned int size = sizeof(BRAIN_STATS);
|
|
|
|
|
unsigned int inc = 0;
|
|
|
|
|
BOOL found = FALSE;
|
|
|
|
|
|
|
|
|
|
if (!getResourceName(componentName))
|
|
|
|
|
{
|
|
|
|
|
return FALSE;
|
|
|
|
@ -2206,10 +2191,8 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//read in Construct Name
|
|
|
|
|
found = FALSE;
|
|
|
|
|
componentName[0] = '\0';
|
|
|
|
|
sscanf(pDroidData, "%[^','],%n", componentName, &cnt);
|
|
|
|
|
pDroidData += cnt;
|
|
|
|
|
pDroidData += cnt;
|
|
|
|
|
|
|
|
|
|
//get the Construct stats pointer
|
|
|
|
|
if (!strcmp(componentName,"0"))
|
|
|
|
@ -2218,8 +2201,11 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pStats = (COMP_BASE_STATS *)asConstructStats;
|
|
|
|
|
size = sizeof(CONSTRUCT_STATS);
|
|
|
|
|
COMP_BASE_STATS *pStats = (COMP_BASE_STATS *)asConstructStats;
|
|
|
|
|
unsigned int size = sizeof(CONSTRUCT_STATS);
|
|
|
|
|
unsigned int inc = 0;
|
|
|
|
|
BOOL found = FALSE;
|
|
|
|
|
|
|
|
|
|
if (!getResourceName(componentName))
|
|
|
|
|
{
|
|
|
|
|
return FALSE;
|
|
|
|
@ -2244,10 +2230,8 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//read in Ecm Name
|
|
|
|
|
found = FALSE;
|
|
|
|
|
componentName[0] = '\0';
|
|
|
|
|
sscanf(pDroidData, "%[^','],%n", componentName, &cnt);
|
|
|
|
|
pDroidData += cnt;
|
|
|
|
|
pDroidData += cnt;
|
|
|
|
|
|
|
|
|
|
//get the Ecm stats pointer
|
|
|
|
|
if (!strcmp(componentName,"0"))
|
|
|
|
@ -2256,8 +2240,11 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pStats = (COMP_BASE_STATS *)asECMStats;
|
|
|
|
|
size = sizeof(ECM_STATS);
|
|
|
|
|
COMP_BASE_STATS *pStats = (COMP_BASE_STATS *)asECMStats;
|
|
|
|
|
unsigned int size = sizeof(ECM_STATS);
|
|
|
|
|
unsigned int inc = 0;
|
|
|
|
|
BOOL found = FALSE;
|
|
|
|
|
|
|
|
|
|
if (!getResourceName(componentName))
|
|
|
|
|
{
|
|
|
|
|
return FALSE;
|
|
|
|
@ -2283,13 +2270,18 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
|
|
|
|
|
|
|
|
|
|
//read in player id - Access decides the order -crap hey?
|
|
|
|
|
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
|
|
|
|
|
found = FALSE;
|
|
|
|
|
componentName[0] = '\0';
|
|
|
|
|
sscanf(pDroidData, "%[^','],%n", componentName, &cnt);
|
|
|
|
|
pDroidData += cnt;
|
|
|
|
|
pDroidData += cnt;
|
|
|
|
|
|
|
|
|
|
//get the Propulsion stats pointer
|
|
|
|
|
if (!strcmp(componentName,"0"))
|
|
|
|
@ -2298,8 +2290,11 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pStats = (COMP_BASE_STATS *)asPropulsionStats;
|
|
|
|
|
size = sizeof(PROPULSION_STATS);
|
|
|
|
|
COMP_BASE_STATS *pStats = (COMP_BASE_STATS *)asPropulsionStats;
|
|
|
|
|
unsigned int size = sizeof(PROPULSION_STATS);
|
|
|
|
|
unsigned int inc = 0;
|
|
|
|
|
BOOL found = FALSE;
|
|
|
|
|
|
|
|
|
|
if (!getResourceName(componentName))
|
|
|
|
|
{
|
|
|
|
|
return FALSE;
|
|
|
|
@ -2324,10 +2319,8 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//read in Repair Name
|
|
|
|
|
found = FALSE;
|
|
|
|
|
componentName[0] = '\0';
|
|
|
|
|
sscanf(pDroidData, "%[^','],%n", componentName, &cnt);
|
|
|
|
|
pDroidData += cnt;
|
|
|
|
|
pDroidData += cnt;
|
|
|
|
|
|
|
|
|
|
//get the Repair stats pointer
|
|
|
|
|
if (!strcmp(componentName,"0"))
|
|
|
|
@ -2336,8 +2329,11 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pStats = (COMP_BASE_STATS *)asRepairStats;
|
|
|
|
|
size = sizeof(REPAIR_STATS);
|
|
|
|
|
COMP_BASE_STATS *pStats = (COMP_BASE_STATS *)asRepairStats;
|
|
|
|
|
unsigned int size = sizeof(REPAIR_STATS);
|
|
|
|
|
unsigned int inc = 0;
|
|
|
|
|
BOOL found = FALSE;
|
|
|
|
|
|
|
|
|
|
if (!getResourceName(componentName))
|
|
|
|
|
{
|
|
|
|
|
return FALSE;
|
|
|
|
@ -2362,9 +2358,9 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//read in droid type - only interested if set to PERSON
|
|
|
|
|
componentName[0] = '\0';
|
|
|
|
|
sscanf(pDroidData, "%[^','],%n", componentName, &cnt);
|
|
|
|
|
pDroidData += cnt;
|
|
|
|
|
pDroidData += cnt;
|
|
|
|
|
|
|
|
|
|
if (!strcmp(componentName, "PERSON"))
|
|
|
|
|
{
|
|
|
|
|
pDroidDesign->droidType = DROID_PERSON;
|
|
|
|
@ -2394,13 +2390,10 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
|
|
|
|
|
pDroidDesign->droidType = DROID_DEFAULT;
|
|
|
|
|
bDefaultTemplateFound = TRUE;
|
|
|
|
|
}
|
|
|
|
|
//pDroidData += (strlen(componentName)+1);
|
|
|
|
|
|
|
|
|
|
//read in Sensor Name
|
|
|
|
|
found = FALSE;
|
|
|
|
|
componentName[0] = '\0';
|
|
|
|
|
sscanf(pDroidData, "%[^','],%n", componentName, &cnt);
|
|
|
|
|
pDroidData += cnt;
|
|
|
|
|
pDroidData += cnt;
|
|
|
|
|
|
|
|
|
|
//get the Sensor stats pointer
|
|
|
|
|
if (!strcmp(componentName,"0"))
|
|
|
|
@ -2409,8 +2402,11 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pStats = (COMP_BASE_STATS *)asSensorStats;
|
|
|
|
|
size = sizeof(SENSOR_STATS);
|
|
|
|
|
COMP_BASE_STATS *pStats = (COMP_BASE_STATS *)asSensorStats;
|
|
|
|
|
unsigned int size = sizeof(SENSOR_STATS);
|
|
|
|
|
unsigned int inc = 0;
|
|
|
|
|
BOOL found = FALSE;
|
|
|
|
|
|
|
|
|
|
if (!getResourceName(componentName))
|
|
|
|
|
{
|
|
|
|
|
return FALSE;
|
|
|
|
@ -2442,7 +2438,7 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
|
|
|
|
|
//check that not allocating more weapons than allowed
|
|
|
|
|
//Watermelon:disable this check for now
|
|
|
|
|
/* if (((asBodyStats + pDroidDesign->asParts[COMP_BODY])->weaponSlots <
|
|
|
|
|
pDroidDesign->numWeaps) || */
|
|
|
|
|
pDroidDesign->numWeaps) || */
|
|
|
|
|
if (pDroidDesign->numWeaps > DROID_MAXWEAPS)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
pDroidDesign->multiPlayerID = i; // another unique number, just for multiplayer stuff.
|
|
|
|
|
*/
|
|
|
|
|
/* store global default design if found else
|
|
|
|
|
* store in the appropriate array
|
|
|
|
|
*/
|
|
|
|
|
* store in the appropriate array
|
|
|
|
|
*/
|
|
|
|
|
if ( pDroidDesign->droidType == DROID_DEFAULT )
|
|
|
|
|
{
|
|
|
|
|
memcpy( &sDefaultDesignTemplate, pDroidDesign, sizeof(DROID_TEMPLATE) );
|
|
|
|
@ -2473,9 +2469,6 @@ BOOL loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
|
|
|
|
|
pDroidData = strchr(pDroidData,'\n') + 1;
|
|
|
|
|
pDroidDesign++;
|
|
|
|
|
}
|
|
|
|
|
// free(pStartDroidData);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( bDefaultTemplateFound == FALSE )
|
|
|
|
|
{
|
|
|
|
@ -2624,81 +2617,35 @@ DROID_TYPE droidTemplateType(DROID_TEMPLATE *psTemplate)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Load the weapons assigned to Droids in the Access database
|
|
|
|
|
//Watermelon:reads 3 WeaponName for now?
|
|
|
|
|
BOOL loadDroidWeapons(const char *pWeaponData, UDWORD bufferSize)
|
|
|
|
|
{
|
|
|
|
|
const char *pStartWeaponData;
|
|
|
|
|
UDWORD NumWeapons = 0, i, player;
|
|
|
|
|
char WeaponName[MAX_STR_LENGTH], TemplateName[MAX_STR_LENGTH];
|
|
|
|
|
//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];
|
|
|
|
|
unsigned int NumWeapons = numCR(pWeaponData, bufferSize);
|
|
|
|
|
unsigned int SkippedWeaponCount = 0;
|
|
|
|
|
unsigned int line = 0;
|
|
|
|
|
|
|
|
|
|
//initialise the store count variable
|
|
|
|
|
for (player=0; player < MAX_PLAYERS; player++)
|
|
|
|
|
ASSERT(NumWeapons > 0, "template without weapons");
|
|
|
|
|
|
|
|
|
|
for (line = 0; line < NumWeapons; line++)
|
|
|
|
|
{
|
|
|
|
|
for(pTemplate = apsDroidTemplates[player]; pTemplate != NULL;
|
|
|
|
|
pTemplate = pTemplate->psNext)
|
|
|
|
|
{
|
|
|
|
|
//clear the storage flags
|
|
|
|
|
pTemplate->storeCount = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
unsigned int player = 0;
|
|
|
|
|
char WeaponName[DROID_MAXWEAPS][MAX_STR_LENGTH] = {{'\0'}},
|
|
|
|
|
TemplateName[MAX_STR_LENGTH] = {'\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
|
|
|
|
|
TemplateName[0] = '\0';
|
|
|
|
|
WeaponName[0] = '\0';
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
sscanf(pWeaponData, "%[^','],%[^','],%[^','],%[^','],%d",
|
|
|
|
|
TemplateName, WeaponName[0], WeaponName[1], WeaponName[2], &player);
|
|
|
|
|
|
|
|
|
|
if (player < MAX_PLAYERS)
|
|
|
|
|
{
|
|
|
|
|
for(pTemplate = apsDroidTemplates[player]; pTemplate != NULL; pTemplate =
|
|
|
|
|
pTemplate->psNext)
|
|
|
|
|
{
|
|
|
|
|
if (!(strcmp(TemplateName, pTemplate->aName)))
|
|
|
|
|
{
|
|
|
|
|
//Template found
|
|
|
|
|
recFound = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
unsigned int j = 0;
|
|
|
|
|
|
|
|
|
|
DROID_TEMPLATE *pTemplate = getTemplateFromUniqueName(TemplateName, player);
|
|
|
|
|
|
|
|
|
|
/* if Template not found - try default design */
|
|
|
|
|
if (!recFound)
|
|
|
|
|
if (!pTemplate)
|
|
|
|
|
{
|
|
|
|
|
pTemplate = &sDefaultDesignTemplate;
|
|
|
|
|
if ( strcmp(TemplateName, pTemplate->aName) )
|
|
|
|
|
if ( strcmp(TemplateName, pTemplate->pName) != 0 )
|
|
|
|
|
{
|
|
|
|
|
debug( LOG_ERROR, "Unable to find Template - %s", TemplateName );
|
|
|
|
|
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
|
|
|
|
|
if (j == 0)
|
|
|
|
|
int incWpn;
|
|
|
|
|
|
|
|
|
|
if (!getResourceName(WeaponName[j]))
|
|
|
|
|
{
|
|
|
|
|
incW[j] = getCompFromName(COMP_WEAPON, WeaponName);
|
|
|
|
|
}
|
|
|
|
|
else if (j == 1)
|
|
|
|
|
{
|
|
|
|
|
incW[j] = getCompFromName(COMP_WEAPON, WeaponNameA);
|
|
|
|
|
}
|
|
|
|
|
else if (j == 2)
|
|
|
|
|
{
|
|
|
|
|
incW[j] = getCompFromName(COMP_WEAPON, WeaponNameB);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
incWpn = getCompFromName(COMP_WEAPON, WeaponName[j]);
|
|
|
|
|
|
|
|
|
|
//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();
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//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
|
|
|
|
|
if (pTemplate->storeCount >
|
|
|
|
|
pTemplate->numWeaps)
|
|
|
|
|
if (pTemplate->storeCount > pTemplate->numWeaps)
|
|
|
|
|
{
|
|
|
|
|
debug( LOG_ERROR, "Trying to allocate more weapons than allowed for Template - %s", TemplateName );
|
|
|
|
|
abort();
|
|
|
|
@ -2743,7 +2689,6 @@ BOOL loadDroidWeapons(const char *pWeaponData, UDWORD bufferSize)
|
|
|
|
|
//check valid weapon/propulsion
|
|
|
|
|
if (!checkValidWeaponForProp(pTemplate))
|
|
|
|
|
{
|
|
|
|
|
// ffs
|
|
|
|
|
debug( LOG_ERROR, "Weapon is invalid for air propulsion for template %s", pTemplate->aName );
|
|
|
|
|
abort();
|
|
|
|
|
|
|
|
|
@ -2760,37 +2705,38 @@ BOOL loadDroidWeapons(const char *pWeaponData, UDWORD bufferSize)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//increment the pointer to the start of the next record
|
|
|
|
|
pWeaponData = strchr(pWeaponData,'\n') + 1;
|
|
|
|
|
pWeaponData = strchr(pWeaponData, '\n') + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (SkippedWeaponCount > 0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
debug( LOG_ERROR, "Illegal player number in %d droid weapons", SkippedWeaponCount );
|
|
|
|
|
abort();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// free(pStartWeaponData);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//free the storage for the droid templates
|
|
|
|
|
BOOL droidTemplateShutDown(void)
|
|
|
|
|
{
|
|
|
|
|
DROID_TEMPLATE *pTemplate, *pNext;
|
|
|
|
|
UDWORD player;
|
|
|
|
|
unsigned int player;
|
|
|
|
|
|
|
|
|
|
for (player = 0; player < MAX_PLAYERS; player++)
|
|
|
|
|
{
|
|
|
|
|
DROID_TEMPLATE *pTemplate, *pNext;
|
|
|
|
|
|
|
|
|
|
for(pTemplate = apsDroidTemplates[player]; pTemplate != NULL;
|
|
|
|
|
pTemplate = pNext)
|
|
|
|
|
{
|
|
|
|
|
pNext = pTemplate->psNext;
|
|
|
|
|
free(pTemplate->pName);
|
|
|
|
|
free(pTemplate);
|
|
|
|
|
}
|
|
|
|
|
apsDroidTemplates[player] = NULL;
|
|
|
|
|
}
|
|
|
|
|
free(sDefaultDesignTemplate.pName);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -3389,7 +3335,7 @@ void droidSetBits(DROID_TEMPLATE *pTemplate,DROID *psDroid)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
psTemplate->numWeaps = 0;
|
|
|
|
@ -3397,7 +3343,7 @@ static void templateSetParts(DROID *psDroid,DROID_TEMPLATE *psTemplate)
|
|
|
|
|
psTemplate->droidType = psDroid->droidType;
|
|
|
|
|
|
|
|
|
|
//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
|
|
|
|
|
psTemplate->asWeaps[inc] = 0;
|
|
|
|
@ -3800,55 +3746,70 @@ BOOL calcDroidMuzzleLocation(DROID *psDroid, Vector3i *muzzle, int weapon_slot)
|
|
|
|
|
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!! */
|
|
|
|
|
DROID_TEMPLATE * getTemplateFromName(char *pName)
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* 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
|
|
|
|
|
* \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
|
|
|
|
|
name regardless of RESOURCE_NAMES and STORE_RESOURCE_ID! - AB 26/06/98*/
|
|
|
|
|
getDroidResourceName(pName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (player = 0; player < MAX_PLAYERS; player++)
|
|
|
|
|
{
|
|
|
|
|
//OK so we want selectedPlayer's CYBORG templates since they cannot be edited
|
|
|
|
|
//and we don't want to duplicate them for the sake of it! (ha!)
|
|
|
|
|
//don't use selectedPlayer's templates if not multiplayer
|
|
|
|
|
//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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
DROID_TEMPLATE *psCurr;
|
|
|
|
|
// OK so we want selectedPlayer's CYBORG templates since they cannot be edited
|
|
|
|
|
// and we don't want to duplicate them for the sake of it! (ha!)
|
|
|
|
|
// don't use selectedPlayer's templates if not multiplayer
|
|
|
|
|
// 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!
|
|
|
|
|
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 (!bMultiPlayer)
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
//if (player == selectedPlayer && psCurr->droidType != DROID_CYBORG)
|
|
|
|
|
if (player == selectedPlayer &&
|
|
|
|
|
!(psCurr->droidType == DROID_CYBORG ||
|
|
|
|
|
psCurr->droidType == DROID_CYBORG_SUPER ||
|
|
|
|
|
psCurr->droidType == DROID_CYBORG_CONSTRUCT ||
|
|
|
|
|
psCurr->droidType == DROID_CYBORG_REPAIR))
|
|
|
|
|
{
|
|
|
|
|
//ignore
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//if template is selectedPlayers' it must be a CYBORG or we ignore it
|
|
|
|
|
if (!bMultiPlayer &&
|
|
|
|
|
player == selectedPlayer &&
|
|
|
|
|
!(psCurr->droidType == DROID_CYBORG ||
|
|
|
|
|
psCurr->droidType == DROID_CYBORG_SUPER ||
|
|
|
|
|
psCurr->droidType == DROID_CYBORG_CONSTRUCT ||
|
|
|
|
|
psCurr->droidType == DROID_CYBORG_REPAIR))
|
|
|
|
|
{
|
|
|
|
|
//ignore
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
return psCurr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -4595,11 +4556,11 @@ void setUpBuildModule(DROID *psDroid)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *getDroidName(DROID *psDroid)
|
|
|
|
|
const char *getDroidName(const DROID *psDroid)
|
|
|
|
|
{
|
|
|
|
|
DROID_TEMPLATE sTemplate;
|
|
|
|
|
|
|
|
|
|
templateSetParts(psDroid,&sTemplate);
|
|
|
|
|
templateSetParts(psDroid, &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
|
|
|
|
|
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;
|
|
|
|
|
UDWORD id;
|
|
|
|
|
char *pName = NULL;
|
|
|
|
|
const char *pNameID = psTemplate->aName;
|
|
|
|
|
unsigned int id;
|
|
|
|
|
|
|
|
|
|
/*see if the name has a resource associated with it by trying to get
|
|
|
|
|
the ID for the string*/
|
|
|
|
|
if (strresGetIDNum(psStringRes, pNameID, &id))
|
|
|
|
|
{
|
|
|
|
|
//get the string from the id
|
|
|
|
|
pName = strresGetString(psStringRes, id);
|
|
|
|
|
const char *pName = strresGetString(psStringRes, id);
|
|
|
|
|
if (pName)
|
|
|
|
|
{
|
|
|
|
|
return pName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//if haven't found a resource, return the name passed in
|
|
|
|
|
if (!pName)
|
|
|
|
|
{
|
|
|
|
|
return pNameID;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
return pNameID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
|
{
|
|
|
|
|
UDWORD id;
|
|
|
|
|
unsigned int id;
|
|
|
|
|
|
|
|
|
|
//see if the name has a resource associated with it by trying to get the ID for the string
|
|
|
|
|
if (!strresGetIDNum(psStringRes, pName, &id))
|
|
|
|
|