コード例 #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)
		{
			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;
}
コード例 #2
0
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;
}
コード例 #3
0
ファイル: CfgParser.cpp プロジェクト: jcnossen/ncrobot
CfgList* CfgValue::LoadFile (std::string name)
{
	InputBuffer buf;

	FILE *f = fopen (name.c_str(), "rb");
	if (!f) 
		throw ContentException(SPrintf("Failed to open file %s\n", name.c_str()));

	fseek (f, 0, SEEK_END);
	buf.len = ftell(f);
	buf.data = new char [buf.len];
	fseek (f, 0, SEEK_SET);
	if (!fread (buf.data, buf.len, 1, f))
	{
		fclose (f);
		delete[] buf.data;
		throw ContentException(SPrintf("Failed to read file %s\n", name.c_str()));
	}
	buf.filename = name.c_str();

	fclose (f);

	CfgList *nlist = new CfgList;
	try {
		nlist->Parse (buf, true);
	}  catch (const ContentException &e) {
		delete[] buf.data;
		delete nlist;
		throw e;
	}
	delete[] buf.data;
    return nlist;
}
コード例 #4
0
ファイル: View.cpp プロジェクト: SpliFF/upspring
void EditorViewWindow::Serialize(CfgList& cfg, bool store)
{
	ViewWindow::Serialize (cfg, store);

	Camera::CtlMode& camCtlMode=cam.ctlmode;
	if (store) {
		CFG_STOREN(cfg,mode);
		CFG_STOREN(cfg,rendermode);
		cfg.AddNumeric ("camCtlMode", (int)camCtlMode);
		CFG_STORE(cfg, bDrawCenters);
		CFG_STORE(cfg, bCullFaces);
		CFG_STORE(cfg, bLighting);
		CFG_STORE(cfg, bHideGrid);
		CFG_STORE(cfg, bDrawRadius);
	} else {
		CFG_LOADN(cfg,mode);
		SetMode(mode);
		CFG_LOADN(cfg,rendermode);
		camCtlMode=(Camera::CtlMode)cfg.GetInt ("camCtlMode",0);
		CFG_LOAD(cfg, bDrawCenters);
		CFG_LOAD(cfg, bCullFaces);
		CFG_LOAD(cfg, bLighting);
		CFG_LOAD(cfg, bHideGrid);
		CFG_LOAD(cfg, bDrawRadius);
	}
}
コード例 #5
0
ファイル: CfgParser.cpp プロジェクト: jcnossen/ncrobot
void CfgList::Add(const char* name, Vector2 v)
{
	CfgList* l = new CfgList();

	l->Add("x", v.x);
	l->Add("y", v.y);

	Add(name, l);
}
コード例 #6
0
bool BuildHandler::DoInitialBuildOrders ()
{
    // initial build orders completed?
	assert (config.InitialOrders);

	if (initialBuildOrderTask)
		return true;

	for (int a=0;a<initialBuildOrderState.size();a++) {
		int &state = initialBuildOrderState[a];
		if (state < config.InitialOrders->builds[a]->count) {
			int type=-1;
			int id=config.InitialOrders->builds[a]->def;
			BuildTable::UDef *cd = buildTable.GetCachedDef(id);

			CfgList* info = config.InitialOrders->builds[a]->info;
			const char *handler = info ? info->GetLiteral ("Handler") : 0;
			if (handler) {
				for (int h=0;h<NUM_TASK_TYPES;h++) {
					if(!STRCASECMP(handler, handlerStr[h])) {
						type=h;
						break;
					}
				}
				
				if (h == BTF_Force) {
					ChatMsgPrintf (ai->cb, "Error: No force units possible in the initial build orders.\n");
					state=config.InitialOrders->builds[a]->count;
					return false;
				}
			} else {
				if(!cd->IsBuilder())  {
					ChatMsgPrintf (ai->cb, "Error in initial buildorder list: unit %s is not a builder\n", cd->name.c_str());
					state=config.InitialOrders->builds[a]->count;
					return false;
				}
			}

			aiTask *t = initialBuildOrderTask = AddTask (buildTable.GetDef(id), type);
			t->MarkAllocated ();
			state ++;

			return true;
		}
	}

	// all initial build tasks are done
	if (!initialBuildOrdersFinished) {
		ChatDebugPrintf (ai->cb,"Initial build orders finished.");

		DistributeResources ();
		initialBuildOrdersFinished=true;
	}
	return false;
}
コード例 #7
0
ファイル: Editor.cpp プロジェクト: Neoniet/upspring
void EditorUI::SaveSettings()
{
	string path=applicationPath + ViewSettingsFile;
	CfgWriter writer(path.c_str());
	if (writer.IsFailed ()) {
		fltk::message ("Failed to open %s for writing view settings", path.c_str());
		return;
	}
	CfgList cfg;
	SerializeConfig (cfg, true);
	cfg.Write(writer,true);
}
コード例 #8
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;
}
コード例 #9
0
ファイル: Texture.cpp プロジェクト: SpliFF/upspring
CfgList* TextureGroupHandler::MakeConfig (TextureGroup *tg)
{
	CfgList *gc = new CfgList;
	char n [10];

	CfgList *texlist=new CfgList;
	int index=0;
	for (set<Texture*>::iterator t=tg->textures.begin();t!=tg->textures.end();++t) {
		sprintf (n,"tex%d", index++);
		texlist->AddLiteral (n, (*t)->name.c_str());
	}
	gc->AddValue ("textures", texlist);
	gc->AddLiteral ("name", tg->name.c_str());
	return gc;
}
コード例 #10
0
ファイル: Editor.cpp プロジェクト: Neoniet/upspring
bool ArchiveList::Save () {
	string fn=applicationPath + ArchiveListFile;
	CfgWriter writer (fn.c_str());
	if (writer.IsFailed())
		return false;

	CfgList cfg;
	CfgList *archs=new CfgList;
	cfg.AddValue ("Archives", archs);
	int index=0;
	for (set<string>::iterator s=archives.begin();s!=archives.end();++s, index++) {
		char tmp[20];
		sprintf (tmp, "arch%d", index);
		archs->AddLiteral (tmp,s->c_str());
	}
	cfg.Write (writer,true);
	return true;
}
コード例 #11
0
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;
}
コード例 #12
0
ファイル: Texture.cpp プロジェクト: SpliFF/upspring
bool TextureGroupHandler::Save(const char *fn)
{
	// open a cfg writer
	CfgWriter writer(fn);
	if (writer.IsFailed()) {
		fltk::message ("Unable to save texture groups to %s\n", fn);
		return false;
	}

	// create a config list and save it
	CfgList cfg;

	for (uint a=0;a<groups.size();a++) {
		CfgList *gc=MakeConfig(groups[a]);

		char n [10];
		sprintf (n, "group%d", a);
		cfg.AddValue (n, gc);
	}

	cfg.Write(writer,true);
	return true;
}
コード例 #13
0
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;
}
コード例 #14
0
ファイル: CfgParser.cpp プロジェクト: SpliFF/upspring
CfgList* CfgValue::LoadFile (const char *name)
{
	InputBuffer buf;

	FILE *f = fopen (name, "rb");
	if (!f) {
		logger.Trace (NL_Debug, "Failed to open file %s\n", name);
		return 0;
	}

	fseek (f, 0, SEEK_END);
	buf.len = ftell(f);
	buf.data = new char [buf.len];
	fseek (f, 0, SEEK_SET);
	if (!fread (buf.data, buf.len, 1, f))
	{
		logger.Trace (NL_Debug, "Failed to read file %s\n", name);
		fclose (f);
		delete[] buf.data;
		return 0;
	}
	buf.filename = name;

	fclose (f);

	CfgList *nlist = new CfgList;
	if (!nlist->Parse (buf,true))
	{
		delete nlist;
		delete[] buf.data;
		return 0;
	}

	delete[] buf.data;
    return nlist;
}
コード例 #15
0
ファイル: Editor.cpp プロジェクト: Neoniet/upspring
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);
	}
}
コード例 #16
0
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;
}
コード例 #17
0
ファイル: Genome.cpp プロジェクト: jcnossen/hmmgenefinder
Genome::Genome(std::string file)
{
	filename = file;
	CfgList* d = CfgList::LoadFile(file);

	// read sequence data
	const char* seqfile = d->GetLiteral("SequenceFile");
	std::string seqPath = GetDirPath(file) + seqfile;
	sequence = ReadTextFile(seqPath);
	std::transform(sequence.begin(), sequence.end(), sequence.begin(), ::tolower);

	// load global properties

	name = d->GetLiteral("LocusName");
	topology = d->GetLiteral("LocusTopology");
	modificationDate = d->GetLiteral("LocusModificationDate");
	definition = d->GetLiteral("Definition");
	source = d->GetLiteral("Source");

	// load features
	CfgList* features = d->GetList("features");
	mvec<FeatureProtein*> proteins = LoadFeatureList<FeatureProtein>(features->GetList("CDS"));
	members_ptr(proteins, &FeatureProtein::type) |= FeatureProtein::Type_Protein;
	
	mvec<Feature*> tRNA = LoadFeatureList<Feature>(features->GetList("tRNA"));
	members_ptr(tRNA, &Feature::type) |= Feature::Type_tRNA;

	mvec<Feature*> rRNA = LoadFeatureList<Feature>(features->GetList("rRNA"));
	members_ptr(rRNA, &Feature::type) |= Feature::Type_rRNA;

	mvec<Feature*> misc_RNA = LoadFeatureList<Feature>(features->GetList("misc_RNA"));
	members_ptr(misc_RNA, &Feature::type) |= Feature::Type_MiscRNA;

	mvec<Feature*> misc_feature = LoadFeatureList<Feature>(features->GetList("misc_feature"));
	members_ptr(misc_feature, &Feature::type) |= Feature::Type_MiscFeature;

	genes = tRNA & rRNA & misc_RNA & misc_feature & proteins;

	// sort genes
	std::sort(genes.begin(), genes.end(), GeneComparer);

	delete d;
}
コード例 #18
0
ファイル: ResourceUnitHandler.cpp プロジェクト: achoum/spring
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;
}