示例#1
0
文件: ubuild.cpp 项目: Gepard/spring
	string CUBuild::GetASSAULT(){
		NLOG("CUBuild::GetASSAULT");
		const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);
		if(di == 0) return string("");
		list<string> possibles;
		float best_score = 0;
		string best = "";
		for(vector<CommandDescription>::const_iterator is = di->begin(); is != di->end();++is){
			if(is->id<0){
				CUnitTypeData* p = G->UnitDefLoader->GetUnitTypeDataByName(is->name);

				if(G->Pl->feasable(p,utd)==false){
					continue;
				}
				if(p->IsAttacker()){
					float temp = G->efficiency->GetEfficiency(p->GetName());
					temp /= (p->GetUnitDef()->energyCost+(p->GetUnitDef()->metalCost*45));
					temp -= (G->mrand()%max(int(temp/4),1));
					if(temp > best_score){
						best_score = temp;
						best = p->GetName();
					}
				}
			}
		}
		if(best_score < 30){
			return GetRAND_ASSAULT();
		}
		return best;
	}
示例#2
0
文件: ubuild.cpp 项目: Gepard/spring
	string CUBuild::GetRAND_ASSAULT(){
		NLOG("CUBuild::GetRAND_ASSAULT");
		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){

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

				if(G->Pl->feasable(p,utd)==false) continue;
				if(p->IsAttacker()){
					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();
		}else{
			return string("");
		}
	}