예제 #1
0
/************************************************************************************************
 * CRMRandomInstance::CRMRandomInstance
 *	constructs a random instance by choosing one of the sub instances and creating it
 *
 * inputs:
 *  instGroup:  parser group containing infromation about this instance
 *  instFile:   reference to an open instance file for creating sub instances
 *
 * return:
 *	none
 *
 ************************************************************************************************/
CRMRandomInstance::CRMRandomInstance ( CGPGroup *instGroup, CRMInstanceFile& instFile ) 
	: CRMInstance ( instGroup, instFile )
{
	CGPGroup* group;
	CGPGroup* groups[MAX_RANDOM_INSTANCES];
	int		  numGroups;

	// Build a list of the groups one can be chosen
	for ( numGroups = 0, group = instGroup->GetSubGroups ( ); 
		  group; 
		  group = group->GetNext ( ) )
	{
		// If this isnt an instance group then skip it
		if ( stricmp ( group->GetName ( ), "instance" ) )
		{
			continue;
		}

		int multiplier = atoi(group->FindPairValue ( "multiplier", "1" ));
		for ( ; multiplier > 0 && numGroups < MAX_RANDOM_INSTANCES; multiplier -- )
		{ 
			groups[numGroups++] = group;
		}
	}

	// No groups, no instance
	if ( !numGroups )
	{
		// Initialize this now
		mInstance = NULL;

		Com_Printf ( "WARNING: No sub instances specified for random instance '%s'\n", group->FindPairValue ( "name", "unknown" ) );
		return;
	}

	// Now choose a group to parse	
	instGroup = groups[TheRandomMissionManager->GetLandScape()->irand(0,numGroups-1)];

	// Create the child instance now.  If the instance create fails then the
	// IsValid routine will return false and this instance wont be added
	mInstance = instFile.CreateInstance ( instGroup->FindPairValue ( "name", "" ) );
	mInstance->SetFilter(mFilter);
	mInstance->SetTeamFilter(mTeamFilter);

	mAutomapSymbol = mInstance->GetAutomapSymbol();

	SetMessage(mInstance->GetMessage());
	SetDescription(mInstance->GetDescription());
	SetInfo(mInstance->GetInfo());
}
예제 #2
0
/************************************************************************************************
 * CRMGroupInstance::CRMGroupInstance
 *	constructur
 *
 * inputs:
 *  settlementID:  ID of the settlement being created
 *
 * return:
 *	none
 *
 ************************************************************************************************/
CRMGroupInstance::CRMGroupInstance ( CGPGroup *instGroup, CRMInstanceFile& instFile )
	:  CRMInstance ( instGroup, instFile )
{
	// Grab the padding and confine radius
	mPaddingSize   = atof ( instGroup->FindPairValue ( "padding", va("%i", TheRandomMissionManager->GetMission()->GetDefaultPadding() ) ) );
	mConfineRadius = atof ( instGroup->FindPairValue ( "confine", "0" ) );

	const char * automapSymName = instGroup->FindPairValue ( "automap_symbol", "none" );
	if (0 == Q_stricmp(automapSymName, "none"))	   	mAutomapSymbol = AUTOMAP_NONE ;
	else if (0 == Q_stricmp(automapSymName, "building"))  	mAutomapSymbol = AUTOMAP_BLD  ;
	else if (0 == Q_stricmp(automapSymName, "objective")) 	mAutomapSymbol = AUTOMAP_OBJ  ;
	else if (0 == Q_stricmp(automapSymName, "start"))	   	mAutomapSymbol = AUTOMAP_START;
	else if (0 == Q_stricmp(automapSymName, "end"))	   	mAutomapSymbol = AUTOMAP_END  ;
	else if (0 == Q_stricmp(automapSymName, "enemy"))	   	mAutomapSymbol = AUTOMAP_ENEMY;
	else if (0 == Q_stricmp(automapSymName, "friend"))	   	mAutomapSymbol = AUTOMAP_FRIEND;
	else mAutomapSymbol	= atoi( automapSymName );

	// optional instance objective strings
	SetMessage(instGroup->FindPairValue("objective_message",""));
	SetDescription(instGroup->FindPairValue("objective_description",""));
	SetInfo(instGroup->FindPairValue("objective_info",""));

	// Iterate through the sub groups to determine the instances which make up the group
	instGroup = instGroup->GetSubGroups ( );

	while ( instGroup )
	{
		CRMInstance* instance;
		const char*  name;
		int			 mincount;
		int			 maxcount;
		int			 count;
		//float		 minrange;
		//float		 maxrange;

		// Make sure only instances are specified as sub groups
		assert ( 0 == Q_stricmp ( instGroup->GetName ( ), "instance" ) );

		// Grab the name
		name     = instGroup->FindPairValue ( "name", "" );

		// Grab the range information
		//minrange = atof(instGroup->FindPairValue ( "minrange", "0" ) );
		//maxrange = atof(instGroup->FindPairValue ( "maxrange", "0" ) );

		// Grab the count information and randomly generate a count value
		mincount = atoi(instGroup->FindPairValue ( "mincount", "1" ) );
		maxcount = atoi(instGroup->FindPairValue ( "maxcount", "1" ) );
		count	 = mincount;

		if ( maxcount > mincount )
		{
			count += (TheRandomMissionManager->GetLandScape()->irand(0, maxcount-mincount));
		}

		// For each count create and add the instance
		for ( ; count ; count -- )
		{
			// Create the instance
			instance = instFile.CreateInstance ( name );

			// Skip this instance if it couldnt be created for some reason.  The CreateInstance
			// method will report an error so no need to do so here.
			if ( NULL == instance )
			{
				continue;
			}

			// Set the min and max range for the instance
			instance->SetFilter(mFilter);
			instance->SetTeamFilter(mTeamFilter);

			// Add the instance to the list
			mInstances.push_back ( instance );
		}

		// Next sub group
		instGroup = instGroup->GetNext ( );
	}
}