Exemplo n.º 1
0
/*loads the corner stat to use for a particular wall stat */
static bool loadWallFunction(const char *pData)
{
	WALL_FUNCTION			*psFunction;
	char					functionName[MAX_STR_LENGTH];
	char					structureName[MAX_STR_LENGTH];

	//allocate storage
	psFunction = (WALL_FUNCTION *)malloc(sizeof(WALL_FUNCTION));
	memset(psFunction, 0, sizeof(WALL_FUNCTION));

	//store the pointer in the Function Array
	*asFunctions = (FUNCTION *)psFunction;
	psFunction->ref = REF_FUNCTION_START + numFunctions;
	numFunctions++;
	asFunctions++;

	//set the type of function
	psFunction->type = WALL_TYPE;

	//read the data in
	functionName[0] = '\0';
	structureName[0] = '\0';
	sscanf(pData, "%255[^,'\r\n],%255[^,'\r\n],%*d", functionName, structureName);

	//allocate storage for the name
	storeName((FUNCTION *)psFunction, functionName);

	//store the structure name - cannot set the stat pointer here because structures
	//haven't been loaded in yet!
	psFunction->pStructName = allocateName(structureName);
	if (!psFunction->pStructName)
	{
		debug(LOG_ERROR, "Structure Stats Invalid for function - %s", functionName);

		return false;
	}
	psFunction->pCornerStat = NULL;

	return true;
}
Exemplo n.º 2
0
/* Load the feature stats */
BOOL loadFeatureStats(const char *pFeatureData, UDWORD bufferSize)
{
	FEATURE_STATS		*psFeature;
	unsigned int		i;
	char				featureName[MAX_STR_LENGTH], GfxFile[MAX_STR_LENGTH],
						type[MAX_STR_LENGTH];

	numFeatureStats = numCR(pFeatureData, bufferSize);

	// Skip descriptive header
	if (strncmp(pFeatureData,"Feature ",8)==0)
	{
		pFeatureData = strchr(pFeatureData,'\n') + 1;
		numFeatureStats--;
	}
	
	asFeatureStats = (FEATURE_STATS*)malloc(sizeof(FEATURE_STATS) * numFeatureStats);

	if (asFeatureStats == NULL)
	{
		debug( LOG_FATAL, "Feature Stats - Out of memory" );
		abort();
		return false;
	}

	psFeature = asFeatureStats;

	for (i = 0; i < numFeatureStats; i++)
	{
		UDWORD Width, Breadth;
		int damageable = 0, tileDraw = 0, allowLOS = 0, visibleAtStart = 0;

		memset(psFeature, 0, sizeof(FEATURE_STATS));

		featureName[0] = '\0';
		GfxFile[0] = '\0';
		type[0] = '\0';

		//read the data into the storage - the data is delimeted using comma's
		sscanf(pFeatureData, "%[^','],%d,%d,%d,%d,%d,%[^','],%[^','],%d,%d,%d",
			featureName, &Width, &Breadth,
			&damageable, &psFeature->armourValue, &psFeature->body,
			GfxFile, type, &tileDraw, &allowLOS,
			&visibleAtStart);

		psFeature->damageable = damageable;
		psFeature->tileDraw = tileDraw;
		psFeature->allowLOS = allowLOS;
		psFeature->visibleAtStart = visibleAtStart;

		// These are now only 16 bits wide - so we need to copy them
		psFeature->baseWidth = Width;
		psFeature->baseBreadth = Breadth;

		psFeature->pName = allocateName(featureName);
		if (!psFeature->pName)
		{
			return false;
		}

		if (psFeature->damageable && psFeature->body == 0)
		{
			debug(LOG_ERROR, "The feature %s, ref %d, is damageable, but has no body points!  The files need to be updated / fixed.  " \
							 "Assigning 1 body point to feature.", psFeature->pName, psFeature->ref);
			psFeature->body = 1;
		}
		//determine the feature type
		featureType(psFeature, type);

		//and the oil resource - assumes only one!
		if (psFeature->subType == FEAT_OIL_RESOURCE)
		{
			oilResFeature = psFeature;
		}

		//get the IMD for the feature
		psFeature->psImd = (iIMDShape *) resGetData("IMD", GfxFile);
		if (psFeature->psImd == NULL)
		{
			debug( LOG_ERROR, "Cannot find the feature PIE for record %s",  getName( psFeature->pName ) );
			return false;
		}

		psFeature->ref = REF_FEATURE_START + i;

		//increment the pointer to the start of the next record
		pFeatureData = strchr(pFeatureData,'\n') + 1;
		//increment the list to the start of the next storage block
		psFeature++;
	}

	return true;
}