Exemplo n.º 1
0
	string CUBuild::GetDEFENCE(){
		NLOG("CUBuild::GetDEFENCE");

		const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);

		if(di == 0) return string("");

		list<string> possibles;

		int defnum = 0;

		for(vector<CommandDescription>::const_iterator is = di->begin(); is != di->end();++is){

			if(is->id<0){

				// retrieve the unit type information
				CUnitTypeData* p =G->UnitDefLoader->GetUnitTypeDataByName(is->name);
				const UnitDef* pd = p->GetUnitDef();

				if(Useless(p)) continue;

				if((p->GetUnitDef()->weapons.empty() == false)&&(!p->GetUnitDef()->isFeature)&&(!p->IsMobile())){
					if((G->info->spacemod == true)||(water == true)){
						if(G->Pl->feasable(p,utd)==false) continue;
						possibles.push_back(p->GetName());
						defnum++;
					} else if (pd->floater == false){
						if(G->Pl->feasable(p,utd)==false) continue;
						possibles.push_back(p->GetName());
						defnum++;
					}
				}
			}
		}

		if(possibles.empty() == false){
			defnum = G->mrand()%defnum;
			int j = 0;
			for(list<string>::iterator k = possibles.begin(); k != possibles.end(); ++k){
				if(j == defnum){
					return *k;
				}else{
					j++;
				}
			}
			return possibles.front();
		}
		
		return string("");
	}
Exemplo n.º 2
0
	string CUBuild::GetMEX(){
		NLOG("CUBuild::GetMEX");
		// Find all metal extractors this unit can build and add them to a list.
		float highscore= 0;
		string highest="";
		for(map<int,string>::const_iterator is = utd->GetUnitDef()->buildOptions.begin(); is != utd->GetUnitDef()->buildOptions.end();++is){

			CUnitTypeData* p = G->UnitDefLoader->GetUnitTypeDataByName(is->second);

			if(p->IsMex()){
				if(Useless(p)){
					continue;
				}

				float score = (p->GetUnitDef()->extractsMetal+1)*1000;
				if(p->GetUnitDef()->weapons.empty()==false){
					score *= 1.2f;
				}

				if(p->GetUnitDef()->canCloak==true){
					score *= 1.2f;
				}

				score /= (p->GetUnitDef()->energyCost+(p->GetUnitDef()->metalCost*45));
				if(score > highscore){
					highscore = score;
					highest = p->GetUnitDef()->name;
				}

				continue;
			}

			if((p->GetUnitDef()->metalMake > 5)&&(p->GetUnitDef()->builder == false)&&(p->GetUnitDef()->movedata == 0 )&&(p->GetUnitDef()->canfly == false)){
				float score = p->GetUnitDef()->metalMake;
				if(p->GetUnitDef()->weapons.empty()==false){
					score *= 1.2f;
				}
				if(p->GetUnitDef()->canCloak==true){
					score *= 1.2f;
				}
				score /= (p->GetUnitDef()->energyCost+(p->GetUnitDef()->metalCost*45));
				if(score > highscore){
					highscore = score;
					highest = p->GetUnitDef()->name;
				}
				continue;
			}
		}
		return highest;
	}
Exemplo n.º 3
0
string CUBuild::GetMEX(){
	NLOG("CUBuild::GetMEX");
	// Find all metal extractors this unit can build and add them to a list.
	float highscore= 0;
	string highest="";
	for(map<int,string>::const_iterator is = ud->buildOptions.begin(); is != ud->buildOptions.end();++is){
		const UnitDef* pd = G->GetUnitDef(is->second);
		if(pd == 0) continue;
		if(pd->type == string("MetalExtractor")){
			if(Useless(pd)==true) continue;
			float score = (pd->extractsMetal+1)*1000;
			if(pd->weapons.empty()==false){
				score *= 1.2f;
			}
			if(pd->canCloak==true){
				score *= 1.2f;
			}
			if(score > highscore){
				highscore = score;
				highest = pd->name;
			}
			continue;
		}
		if((pd->metalMake > 5)&&(pd->builder == false)&&(pd->movedata == 0 )&&(pd->canfly == false)){
			float score = pd->metalMake;
			if(pd->weapons.empty()==false){
				score *= 1.2f;
			}
			if(pd->canCloak==true){
				score *= 1.2f;
			}
			if(score > highscore){
				highscore = score;
				highest = pd->name;
			}
			continue;
		}
	}
	return highest;
}
Exemplo n.º 4
0
	string CUBuild::GetRADAR(){
		NLOG("CUBuild::GetRADAR");
		const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);
		if(di == 0) return string("");
		list<string> possibles;

		int randnum = 0;
		for(vector<CommandDescription>::const_iterator is = di->begin(); is != di->end();++is){
			if(is->id<0){

				// retrieve the unit type information
				CUnitTypeData* p =G->UnitDefLoader->GetUnitTypeDataByName(is->name);
				const UnitDef* pd = p->GetUnitDef();

				if(pd == 0) continue;
				if(Useless(p)) continue;
				if((pd->radarRadius >10)&&(pd->floater == false)&&(pd->builder == false)){
					possibles.push_back(pd->name);
					randnum++;
				}else if((pd->radarRadius >10)&&(pd->floater == false)&&(pd->builder == false)&&(pd->floater == true)&&((G->info->spacemod == true)||(water == true))){
					possibles.push_back(pd->name);
					randnum++;
				}
			}
		}

		if(possibles.empty() == false){
			randnum = G->mrand()%randnum;
			int j = 0;
			for(list<string>::iterator k = possibles.begin(); k != possibles.end(); ++k){
				if(j == randnum){
					return *k;
				}else{
					j++;
				}
			}
			return possibles.front();
		}
		return string("");
	}
Exemplo n.º 5
0
string CUBuild::GetRANDOM(){
	NLOG("CUBuild::GetRANDOM");
	const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);
	if(di == 0) return string("");
	list<string> possibles;
	int randnum = 0;
	for(vector<CommandDescription>::const_iterator is = di->begin(); is != di->end();++is){
		if(is->id<0){
			const UnitDef* pd = G->GetUnitDef(is->name);
			if(pd == 0) continue;
			if((pd->canKamikaze)&&((pd->canfly == false)&&(pd->movedata == 0))) continue; // IT'S A MINE!!!! We dont want nonblocking mines built ontop of eachother next to the factory!!!!!!!!!!!
			if((pd->radarRadius > 10)&&((pd->builder == false)||(pd->isAirBase == true))) continue; // no radar towers!!!!
			if((pd->energyStorage > 100)||(pd->metalStorage > 100)) continue; // no resource storage!!!!!!!!
			if(pd->isMetalMaker == true) continue; // no metal makers
			if(Useless(pd)==true) continue;
			if((pd->metalCost+pd->energyCost < (G->cb->GetEnergy()+G->cb->GetMetal())*0.9)&&(((pd->floater == false)&&(water == false)&&(G->info->spacemod == false))||((G->info->spacemod == true)||(water == true)))){
				if(G->Pl->feasable(pd->name,uid)==false) continue;
				possibles.push_back(pd->name);
				randnum++;
			}
		}
	}
	if(possibles.empty() == false){
		srand(uint(time(NULL) +G->Cached->team +  G->Cached->randadd));
		G->Cached->randadd++;
		randnum = rand()%randnum;
		int j = 0;
		for(list<string>::iterator k = possibles.begin(); k != possibles.end(); ++k){
			if(j == randnum){
				return *k;
			}else{
				j++;
			}
		}
		return possibles.front();
	}
	return string("");
}
Exemplo n.º 6
0
	string CUBuild::GetRANDOM(){
		NLOG("CUBuild::GetRANDOM");
		const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);
		if(di == 0) return string("");
		list<string> possibles;
		int randnum = 0;

		// for each possible build command the unit could do
		for(vector<CommandDescription>::const_iterator is = di->begin(); is != di->end();++is){

			if(is->id<0){

				// retrieve the unit type information
				CUnitTypeData* p =G->UnitDefLoader->GetUnitTypeDataByName(is->name);
				
				// no mine fields
				if(p->GetUnitDef()->canKamikaze &&((!p->GetUnitDef()->canfly)&&(p->GetUnitDef()->movedata == 0))){
					// IT'S AN EXPLOSIVE MINE!!!!
					// We dont want nonblocking mines built ontop of eachother next to the factory!!!!!!!!!!!
					continue;
				}
				
				// no radar towers!!!!
				if((p->GetUnitDef() ->radarRadius > 10)&&((!p->GetUnitDef()->builder)||p->GetUnitDef()->isAirBase)){
					continue;
				}
				
				// no resource storage!!!!!!!!
				if((p->GetUnitDef()->energyStorage > 100)||(p->GetUnitDef()->metalStorage > 100)){
					continue;
				}

				// no metal makers
				if(p->GetUnitDef()->isMetalMaker){
					continue;
				}
				
				// remove 'useless' or 'irrelevant' items
				if(Useless(p)){
					continue;
				}
				
				if((p->GetUnitDef()->metalCost+p->GetUnitDef()->energyCost < (G->cb->GetEnergy()+G->cb->GetMetal())*0.9)&&(((!p->GetUnitDef()->floater)&&(!water)&&(!G->info->spacemod))||(G->info->spacemod||water))){
					
					// check the antistall algorithm if it's ok
					if(!G->Pl->feasable(p,utd)){
						continue;
					}
					
					possibles.push_back(p->GetName());
					randnum++;
				}
			}
		}

		// if potential items where found
		if(!possibles.empty()){

			// randomly pick one of the
			randnum = G->mrand()%randnum;

			// remove entries from the beginning of the list of potential items
			// so that the randnum'th entry is at the begining of the list
			while(randnum > 0){
				possibles.pop_front();
			}
			
			// now that we've removed all those entries our random selection
			// is at the front of the list, so lets return it
			return possibles.front();
		}

		return string("");
	}