Пример #1
0
bool ReconConfig::Load (CfgList *rootcfg)
{
	CfgList *rinfo = dynamic_cast<CfgList*> (rootcfg->GetValue ("reconinfo"));

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

		updateInterval = rinfo->GetInt ("updateinterval", 4);
		maxForce = rinfo->GetInt ("maxforce", 5);
		minMetal = rinfo->GetNumeric ("minmetal");
		minEnergy = rinfo->GetNumeric ("minenergy");

		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;
}
Пример #2
0
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 SupportConfig::Load (CfgList *sidecfg)
{
	CfgList *scfg = dynamic_cast <CfgList*> (sidecfg->GetValue ("supportinfo"));

	if (scfg)
	{
		basecover = dynamic_cast<CfgBuildOptions*> (scfg->GetValue ("basecover"));
		mapcover = dynamic_cast<CfgBuildOptions*> (scfg->GetValue ("mapcover"));

		if (basecover) 
		{
			MapUDefProperties (basecover, basecoverProps);

			if (!basecover->InitIDs ())
				return false;
		}
		if (mapcover)
		{
			MapUDefProperties (mapcover, mapcoverProps);
			
			if (!mapcover->InitIDs ())
				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 ModConfig::UnitTypeInfo::Load (CfgList *root, BuildTable *tbl)
{
	CfgList *sideinfo = dynamic_cast <CfgList*> (root->GetValue ("sideinfo"));

	if (!sideinfo)
	{
		logPrintf ("No sideinfo node found in config file\n");
		return false;
	}

	CfgList *l = dynamic_cast <CfgList*> (sideinfo->GetValue ("aadefense"));

	for (list<CfgListElem>::iterator i=l->childs.begin();i!=l->childs.end();++i)
	{
		UnitDefID id = tbl->GetDefID (i->name.c_str());
		if (id)
		{
			aadefense.push_back (id);
			BuildTable::UDef* cd = tbl->GetCachedDef (id);
			cd->flags |= CUD_AADefense;
		}
	}

	l = dynamic_cast <CfgList*> (sideinfo->GetValue ("gddefense"));

	for (list<CfgListElem>::iterator i=l->childs.begin();i!=l->childs.end();++i)
	{
		UnitDefID id = tbl->GetDefID (i->name.c_str());
		if (id) {
			gddefense.push_back (id);
			BuildTable::UDef* cd = tbl->GetCachedDef (id);
			cd->flags |= CUD_GroundDefense;
		}
	}

	return true;
}
Пример #6
0
void EditorUI::SerializeConfig (CfgList& cfg, bool store)
{
	// Serialize editor window properties
	int x=window->x(), y=window->y(), width=window->w(), height=window->h();
	string& springTexDir = Texture::textureLoadDir;
	if (store) {
		CFG_STOREN(cfg,x);
		CFG_STOREN(cfg,y);
		CFG_STOREN(cfg,width);
		CFG_STOREN(cfg,height);
		CFG_STORE(cfg,springTexDir);
		CFG_STORE(cfg,optimizeOnLoad);
		bool showTimeline=uiTimeline->window->visible();
		CFG_STORE(cfg,showTimeline);
		bool showTrackEdit=uiAnimTrackEditor->window->visible();
		CFG_STORE(cfg,showTrackEdit);
		bool showIK=uiIK->window->visible();
		CFG_STORE(cfg,showIK);
	} else {
		CFG_LOADN(cfg,x);
		CFG_LOADN(cfg,y);
		CFG_LOADN(cfg,width);
		CFG_LOADN(cfg,height);
		CFG_LOAD(cfg,springTexDir);
		CFG_LOAD(cfg,optimizeOnLoad);

		window->resize(x,y,width,height);
	}
	// Serialize views: first match the number of views specified in the config
	int numViews = viewsGroup->children();
	if (store) {
		CFG_STOREN(cfg,numViews);
	} else {
		CFG_LOADN(cfg,numViews);
		int nv=numViews-viewsGroup->children();
		if (nv > 0) {
			viewsGroup->begin();
			for (int a=0;a<nv;a++) {
				EditorViewWindow *wnd = new EditorViewWindow (0,0,0,0,&callback);
				wnd->SetMode(a%4);
			}
			viewsGroup->end();
		} else {
			for (int a=viewsGroup->children()-1;a>=numViews;a--) {
				EditorViewWindow *wnd = (EditorViewWindow *)viewsGroup->child(a);
				viewsGroup->remove (wnd);
				delete wnd;
			}
		}
	}
	// then serialize view settings for each view in the config
	int viewIndex = 0;
	char viewName[16];
	for (int a=0;a<viewsGroup->children();++a) {
		sprintf (viewName, "View%d", viewIndex++);
		CfgList *viewcfg;
		if (store) {
			viewcfg = new CfgList;
			cfg.AddValue (viewName, viewcfg);
		}else viewcfg=dynamic_cast<CfgList*>(cfg.GetValue(viewName));
		if (viewcfg) 
			((EditorViewWindow *)viewsGroup->child(a))->Serialize (*viewcfg,store);
	}
}