本文整理汇总了C++中CUnitTypeData::GetUnitDef方法的典型用法代码示例。如果您正苦于以下问题:C++ CUnitTypeData::GetUnitDef方法的具体用法?C++ CUnitTypeData::GetUnitDef怎么用?C++ CUnitTypeData::GetUnitDef使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CUnitTypeData
的用法示例。
在下文中一共展示了CUnitTypeData::GetUnitDef方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetGUNSHIP
string CUBuild::GetGUNSHIP(){
NLOG("CUBuild::GetGUNSHIP");
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->IsGunship()){
float temp = G->efficiency->GetEfficiency(p->GetName());
temp /= (p->GetUnitDef()->energyCost+(p->GetUnitDef()->metalCost*45));
temp = temp - G->mrand()%max(int(temp/4),1);
if(temp > best_score){
best_score = temp;
best = p->GetName();
}
}
}
}
return best;
}
示例2: GetFACTORY
string CUBuild::GetFACTORY(){
NLOG("CUBuild::GetFACTORY");
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(p->IsFactory()){
if(!G->Pl->feasable(p,utd)) continue;
if(p->IsUWStructure()!=(water||G->info->spacemod)) continue;
float temp = G->efficiency->GetEfficiency(p->GetName());
temp /= (p->GetUnitDef()->energyCost+(p->GetUnitDef()->metalCost*45));
int r = G->mrand()%max(int(temp/4),1)+1;
temp += (float)abs(r);
if(temp > best_score){
best_score = temp;
best = p->GetName();
}
}
}
}
return best;
}
示例3: GetGEO
string CUBuild::GetGEO(){
NLOG("CUBuild::GetGEO");
const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);
if(di == 0) return string("");
list<string> possibles;
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->GetUnitDef()->needGeo&&(p->GetUnitDef()->builder == false)) possibles.push_back(p->GetName());
}
}
if(possibles.empty() == false){
return possibles.front();
}
return string("");
}
示例4: GetDEFENCE
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("");
}
示例5: GetPOWER
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("");
}
示例6: GetBUILDER
string CUBuild::GetBUILDER(){
NLOG("CUBuild::GetBUILDER");
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(p->GetUnitDef()->builder&&((p->GetUnitDef()->movedata !=0)||p->GetUnitDef()->canfly)){
if(G->Pl->feasable(p,utd)==false) continue;
if(p->GetUnitDef()->floater){
if(G->info->spacemod||water){
float temp = G->efficiency->GetEfficiency(p->GetUnitDef()->name);
if(!p->GetUnitDef()->buildOptions.empty()){
for(map<int,std::string>::const_iterator i = p->GetUnitDef()->buildOptions.begin(); i != p->GetUnitDef()->buildOptions.end(); ++i){
temp += G->efficiency->GetEfficiency(i->second);
}
}
temp*=p->GetUnitDef()->buildSpeed;
temp /= (p->GetUnitDef()->energyCost+(p->GetUnitDef()->metalCost*45));
temp = temp - G->mrand()%max(int(temp/4),1);
if(temp > best_score){
best_score = temp;
best = p->GetName();
}
}
}
}
}
}
return best;
}
示例7: GetSCOUT
string CUBuild::GetSCOUT(){
NLOG("CUBuild::GetSCOUT");
const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);
if(di == 0) return string("");
list<string> possibles;
for(vector<CommandDescription>::const_iterator is = di->begin(); is != di->end();++is){
if(is->id<0){
CUnitTypeData* p =G->UnitDefLoader->GetUnitTypeDataByName(is->name);
//if(Useless(ud)) continue;
if((p->GetUnitDef()->speed > G->info->scout_speed)&&(p->GetUnitDef()->movedata != 0)&&(p->GetUnitDef()->canfly == false)&&(p->GetUnitDef()->transportCapacity == 0)&&(p->GetUnitDef()->isCommander == false)&&(p->GetUnitDef()->builder == false)) possibles.push_back(p->GetName());
if((p->GetUnitDef()->weapons.empty() == true)&&(p->GetUnitDef()->canfly == true)&&(p->GetUnitDef()->transportCapacity == 0)&&(p->GetUnitDef()->isCommander == false)&&(p->GetUnitDef()->builder == false)) possibles.push_back(p->GetName());
if((p->GetUnitDef()->weapons.empty()==true)&&(p->GetUnitDef()->canResurrect == false)&&(p->GetUnitDef()->canCapture == false)&&(p->GetUnitDef()->builder == false)&& ((p->GetUnitDef()->canfly==true)||(p->GetUnitDef()->movedata != 0)) &&((p->GetUnitDef()->radarRadius > 10)||(p->GetUnitDef()->sonarRadius > 10))) possibles.push_back(p->GetName());
}
}
if(possibles.empty() == false) return possibles.front();
return string("");
}
示例8: GetMSTORE
string CUBuild::GetMSTORE(){
NLOG("CUBuild::GetMSTORE");
list<string> possibles;
const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);
if(di == 0) return string("");
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->metalStorage >100){
if(G->Pl->feasable(p,utd)==false) continue;
if(pd->floater){
if(G->info->spacemod||water){
possibles.push_back(pd->name);
randnum++;
}
} else {
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("");
}
示例9: GetMISSILE_UNIT
string CUBuild::GetMISSILE_UNIT(){
NLOG("CUBuild::GetMISSILE_UNIT");
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(p->GetUnitDef()->metalCost+p->GetUnitDef()->energyCost > (G->cb->GetEnergyStorage()+G->cb->GetMetalStorage())*atof(G->Get_mod_tdf()->SGetValueDef("2.1", "AI\\cheap_multiplier").c_str())) continue;
bool good = true;
if(p->GetUnitDef()->canfly == false) good = false;
if(p->GetUnitDef()->weapons.empty() == true) good = false;
if(p->GetUnitDef()->builder == true) good = false;
if(p->GetUnitDef()->transportCapacity > 0) good = false;
bool found = false;
for(vector<UnitDef::UnitDefWeapon>::const_iterator i = p->GetUnitDef()->weapons.begin(); i != p->GetUnitDef()->weapons.end(); ++i){
if(i->def->interceptor > 0){
continue;
}
if(i->def->type == string("StarburstLauncher")){
found = true;
break;
}
}
if(found == false) good = false;
if(good == true){
float temp = G->efficiency->GetEfficiency(p->GetName());
temp /= (p->GetUnitDef()->energyCost+(p->GetUnitDef()->metalCost*45));
temp = temp - G->mrand()%min((int)(temp/3),1);
if(temp > best_score){
best_score = temp;
best = p->GetName();
}
}
}
}
return best;
}
示例10: GetANTIMISSILE
string CUBuild::GetANTIMISSILE(){
NLOG("CUBuild::GetANTIMISSILE");
list<string> possibles;
const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);
if(di == 0) return string("");
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->weapons.empty() != true){
if(G->Pl->feasable(pd->name,uid)==false) continue;
for(vector<UnitDef::UnitDefWeapon>::const_iterator i = pd->weapons.begin(); i != pd->weapons.end(); ++i){
//
if(i->def->interceptor == 1){
possibles.push_back(pd->name);
randnum++;
break;
}
}
}
}
}
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("");
}
示例11: GetRADAR
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("");
}
示例12: GetFORTIFICATION
string CUBuild::GetFORTIFICATION(){
NLOG("CUBuild::GetFORTIFICATION");
if(G->DTHandler->DTNeeded() == false) return string("");
const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);
if(di == 0) return string("");
list<string> possibles;
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(G->DTHandler->IsDragonsTeeth(pd)){
possibles.push_back(pd->name);
}
}
}
if(possibles.empty() == false){
int randnum = G->mrand()%possibles.size();
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("");
}
示例13: GetMETAL_MAKER
string CUBuild::GetMETAL_MAKER(){
NLOG("CUBuild::GetMETAL_MAKER");
const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);
if(di == 0) return string("");
list<string> possibles;
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->isMetalMaker == true)&&(pd->floater == false)){
possibles.push_back(pd->name);
}
if((pd->isMetalMaker == true)&&(pd->floater == true)&&((G->info->spacemod == true)||(water == true))){
possibles.push_back(pd->name);
}
}
}
if(possibles.empty() == false){
int randnum = G->mrand()%possibles.size();
for(list<string>::iterator k = possibles.begin(); k != possibles.end(); ++k){
if(0 == randnum){
return *k;
}else{
randnum--;
}
}
return possibles.front();
}
return string("");
}
示例14: GetSHIELD
string CUBuild::GetSHIELD(){
NLOG("CUBuild::GetSHIELD");
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)) continue;
if(p->GetUnitDef()->metalCost+p->GetUnitDef()->energyCost > (G->cb->GetEnergyStorage()+G->cb->GetMetalStorage())*atof(G->Get_mod_tdf()->SGetValueDef("2.1", "AI\\cheap_multiplier").c_str())) continue;
bool found = false;
if(p->GetUnitDef()->weapons.empty() == false){
for(vector<UnitDef::UnitDefWeapon>::const_iterator i = p->GetUnitDef()->weapons.begin(); i != p->GetUnitDef()->weapons.end(); ++i){
if(i->def->isShield){
found = true;
break;
}
}
}
if(found == true){
float temp = G->efficiency->GetEfficiency(p->GetName());
temp /= (p->GetUnitDef()->energyCost+(p->GetUnitDef()->metalCost*45));
temp = temp - G->mrand()%max(int(temp/4),1);
if(temp > best_score){
best_score = temp;
best = p->GetName();
}
}
}
}
return best;
}
示例15: RepairNearbyUnfinishedMobileUnits
bool CActions::RepairNearbyUnfinishedMobileUnits(int uid, float radius){
NLOG("CActions::RepairNearbyUnfinishedMobileUnits");
const UnitDef* udi = G->cb->GetUnitDef(uid);
if(udi == 0) return false;
float3 pos = G->GetUnitPos(uid);
int* hn = new int[10000];
int h = G->cb->GetFriendlyUnits(hn, pos, radius);
if( h>0){
for( int i = 0; i<h; i++){
if(G->cb->UnitBeingBuilt(hn[i]) == true){
CUnitTypeData* btd = G->UnitDefLoader->GetUnitTypeDataByUnitId(hn[i]);
if(!btd->IsMobile()){
continue;
}
float Remainder = 1.0f - G->cb->GetUnitHealth(hn[i]) / G->cb->GetUnitMaxHealth(hn[i]);
float RemainingTime = btd->GetUnitDef()->buildTime / udi->buildSpeed * Remainder;
if (RemainingTime < 30.0f){
continue;
}
float EPerS = btd->GetUnitDef()->energyCost / (btd->GetUnitDef()->buildTime / udi->buildSpeed);
float MPerS = btd->GetUnitDef()->metalCost / (btd->GetUnitDef()->buildTime / udi->buildSpeed);
if (G->cb->GetMetal() + (G->Pl->GetMetalIncome() - MPerS) * RemainingTime > 0 && G->cb->GetEnergy() + (G->Pl->GetEnergyIncome() - EPerS) * RemainingTime > 0){
if (RemainingTime > 120.0f || btd->GetUnitDef()->buildSpeed > 0){
int target = hn[i];
delete [] hn;
return Repair(uid, target);
}
}
}
}
}else{
h = G->cb->GetFriendlyUnits(hn);
if(h <1){
return false;
}
for( int i = 0; i<h; i++){
if((G->cb->UnitBeingBuilt(hn[i])||(G->cb->GetUnitMaxHealth(hn[i])*0.6f > G->cb->GetUnitHealth(hn[i])))&&(G->cb->GetUnitTeam(hn[i]) == G->Cached->team)){
CUnitTypeData* btd = G->UnitDefLoader->GetUnitTypeDataByUnitId(hn[i]);
float Remainder = 1.0f - G->cb->GetUnitHealth(hn[i]) / G->cb->GetUnitMaxHealth(hn[i]);
float RemainingTime = btd->GetUnitDef()->buildTime / udi->buildSpeed * Remainder;
if (RemainingTime < 30.0f){
continue;
}
float EPerS = btd->GetUnitDef()->energyCost / (btd->GetUnitDef()->buildTime / udi->buildSpeed);
float MPerS = btd->GetUnitDef()->metalCost / (btd->GetUnitDef()->buildTime / udi->buildSpeed);
if (G->cb->GetMetal() + (G->Pl->GetMetalIncome() - MPerS) * RemainingTime > 0 && G->cb->GetEnergy() + (G->Pl->GetEnergyIncome() - EPerS) * RemainingTime > 0 ){
if (RemainingTime > 120.0f || btd->GetUnitDef()->buildSpeed > 0) {
int target = hn[i];
delete [] hn;
return Repair(uid, target);
}
}
}
}
}
delete [] hn;
return false;
}