Ejemplo n.º 1
0
	string CUBuild::GetPOWER(){
		NLOG("CUBuild::GetPOWER");
		const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);
		if(di == 0) return string("");
		list<string> possibles;
		// Find all energy generators this unit can build and add them to a list.
		list<const UnitDef*> possibles_u;
		for(vector<CommandDescription>::const_iterator is = di->begin(); is != di->end();++is){
			if(is->id<0){
				CUnitTypeData* p = G->UnitDefLoader->GetUnitTypeDataByName(is->name);
				if(p->IsEnergy()) possibles_u.push_back(p->GetUnitDef());
			}
		}

		string best_energy = "";
		if(possibles_u.empty() == false){
			float bestpoint = 0;
			for(list<const UnitDef*>::iterator pd = possibles_u.begin();pd != possibles_u.end(); ++pd){
				float temp_energy = 0;
				if((*pd)->energyUpkeep <0) temp_energy += -(*pd)->energyUpkeep;
				if((*pd)->windGenerator>1) temp_energy += (G->cb->GetMaxWind()+G->cb->GetMinWind())/2;
				if((*pd)->energyMake > 1) temp_energy += (*pd)->energyMake;
				if((*pd)->tidalGenerator >0) temp_energy += G->cb->GetTidalStrength();
				temp_energy /= ((*pd)->energyCost+((*pd)->metalCost*45));
				if(temp_energy/(((*pd)->metalCost+(*pd)->energyCost)/2) > bestpoint){
					bestpoint = temp_energy;
					best_energy = (*pd)->name;
				}
			}
		}
		
		return best_energy;
		//return string("");
	}