bool BuildHandlerConfig::Load(CfgList *sidecfg)
{
	assert (NUM_TASK_TYPES == 4);
	float sum = 0.0f;
	CfgList* cfg = modConfig.root;
	CfgList *weights = dynamic_cast<CfgList*>(cfg->GetValue ("BuildWeights"));
	CfgList *maxtasks = dynamic_cast<CfgList*>(cfg->GetValue ("MaxTasks"));
	for (int a=0;a<NUM_TASK_TYPES;a++)
	{
		BuildWeights[a] = weights ? weights->GetNumeric (handlerStr[a], 1.0f) : 1.0f;
		MaxTasks[a] = maxtasks ? maxtasks->GetInt (handlerStr[a], 1) : 1;
		sum += BuildWeights[a];
	}
	for (int a=0;a<NUM_TASK_TYPES;a++) 
		BuildWeights[a] /= sum;

	logPrintf ("Building weights: Resources=%f, Forces=%f, Defenses=%f\n", 
		BuildWeights [0], BuildWeights[1], BuildWeights [2]);

	BuildSpeedPerMetalIncome = cfg->GetNumeric ("BuildSpeedPerMetalIncome", 33);
	InitialOrders = dynamic_cast<CfgBuildOptions*>(sidecfg->GetValue("InitialBuildOrders"));
	if (InitialOrders) InitialOrders->InitIDs();

	return true;
}
bool ReconConfig::Load (CfgList *rootcfg)
{
	CfgList *rinfo = dynamic_cast<CfgList*> (rootcfg->GetValue ("reconinfo"));

	if (rinfo)
	{
		scouts = dynamic_cast<CfgBuildOptions*> (rinfo->GetValue ("scouts"));
		if (scouts)
		{
			if (!scouts->InitIDs ())
				return false;
		}

		updateInterval = rinfo->GetInt ("updateinterval", 4);
		maxForce = rinfo->GetInt ("maxforce", 5);

		CfgList* hcfg = dynamic_cast<CfgList*> (rinfo->GetValue ("SearchHeuristic"));
		if (hcfg)
		{
			searchHeuristic.DistanceFactor = hcfg->GetNumeric ("DistanceFactor");
			searchHeuristic.ThreatFactor = hcfg->GetNumeric ("ThreatFactor");
			searchHeuristic.TimeFactor = hcfg->GetNumeric ("TimeFactor");
			searchHeuristic.SpreadFactor = hcfg->GetNumeric ("SpreadFactor");
		}
		else {
			logPrintf ("Error: No search heuristic info in recon config node.\n");
			return false;
		}

		return true;
	}
	return false;
}
bool AIConfig::Load (const char *file, IGlobalAICallback *cb)
{
	CfgList *info = 0;

	root = CfgValue::LoadFile (file);
	if (root)
		info = dynamic_cast<CfgList*> (root->GetValue ("info"));

	if (info) 
	{
		infoblocksize=info->GetInt ("infoblocksize", -1);

		if (infoblocksize < 8)
		{
			ChatMsgPrintf (cb->GetAICallback(), "AIConfig: invalid infoblocksize: %d\n", infoblocksize);
			return false;
		}

		debug = info->GetInt ("debug",0)!=0;
		showDebugWindow = info->GetInt ("showdebugwindow",0) != 0;
		showMetalSpots=info->GetInt ("showmetalspots", 0)!=0;
		safeSectorRadius = info->GetInt ("safesectorradius", 15);
		mexSectorRadius = info->GetInt ("mexsectorradius", 15);
		cacheBuildTable = !!info->GetInt ("cachebuildtable", 1);
		builderMoveTimeout = info->GetInt ("buildermovetimeout", 200);
		builderMoveMinDistance = info->GetNumeric("buildermovemindistance", 100);
		threatDecay = info->GetNumeric ("threatdecay", 0.1f);
	}
	else {
		ChatMsgPrintf (cb->GetAICallback(), "Error: Unable to read configuration file %s. Aborting global AI.\n", file);
		return false;
	}

	return true;
}
示例#4
0
bool RUHandlerConfig::Load (CfgList *sidecfg)
{
	CfgList *c = dynamic_cast<CfgList*>(sidecfg->GetValue ("ResourceInfo"));
	BuildTable *tbl = &buildTable;

	if (c)
	{
		EnergyBuildRatio = c->GetNumeric ("EnergyBuildRatio", 1.4);
		MetalBuildRatio = c->GetNumeric ("MetalBuildRatio", 0.8);

		CfgList *ebh = dynamic_cast<CfgList*>(c->GetValue ("EnergyBuildHeuristic"));
		if (ebh) EnergyHeuristic.Load (ebh);

		CfgList *mbh = dynamic_cast<CfgList*>(c->GetValue ("MetalBuildHeuristic"));
		if (mbh) MetalHeuristic.Load (mbh);

		ParseDefList (c->GetValue ("EnergyMakers"), EnergyMakers, tbl);
		ParseDefList (c->GetValue ("MetalMakers"), MetalMakers, tbl);
		ParseDefList (c->GetValue ("MetalExtracters"), MetalExtracters, tbl);

		// Read storage config
		CfgList *st = dynamic_cast<CfgList*>(c->GetValue("Storage"));
		if (st)
		{
			ParseDefList (st->GetValue ("MetalStorage"), StorageConfig.MetalStorage, tbl);
				
			if (StorageConfig.MetalStorage.empty ()) {
				logPrintf ("Error: No metal storage unit type given");
				return false;
			}
			
			ParseDefList (st->GetValue ("EnergyStorage"), StorageConfig.EnergyStorage, tbl);

			if (StorageConfig.EnergyStorage.empty ()) {
				logPrintf ("Error: No energy storage unit type given");
				return false;
			}
		
			StorageConfig.MaxRatio = st->GetNumeric ("MaxRatio", 0.9);
			StorageConfig.MinEnergyIncome = st->GetNumeric ("MinEnergyIncome", 60);
			StorageConfig.MinMetalIncome = st->GetNumeric ("MinMetalIncome", 5);
			StorageConfig.MaxEnergyFactor = st->GetNumeric ("MaxEnergyStorageFactor", 20);
			StorageConfig.MaxMetalFactor = st->GetNumeric ("MaxMetalStorageFactor", 20);
		}

		CfgList *ep = dynamic_cast<CfgList*>(c->GetValue("EnablePolicy"));
		if (ep)
		{
			EnablePolicy.MaxEnergy = ep->GetNumeric ("MaxEnergy");
			EnablePolicy.MinEnergy = ep->GetNumeric ("MinEnergy");
			EnablePolicy.MinUnitEnergyUsage = ep->GetNumeric ("MinUnitEnergyUsage");
		}
	}
	else {
		logPrintf ("Error: No list node named \'ResourceInfo\' was found.\n");
		return false;
	}

	return true;
}
bool ForceConfig::Load (CfgList *cfg)
{
	CfgList *forceinfo = dynamic_cast<CfgList*> (cfg->GetValue ("forceinfo"));

	if (forceinfo)
	{
		defaultSpread = forceinfo->GetNumeric ("defaultspread", 500);

		for (list<CfgListElem>::iterator gr = forceinfo->childs.begin(); gr != forceinfo->childs.end(); ++gr)
		{
			if (dynamic_cast <CfgList*> (gr->value))
				ParseForceGroup ( (CfgList *)gr->value, gr->name );
		}
		return true;
	}
	
	logPrintf ("Error: No force info in config.\n");
	return false;
}