本文整理汇总了C++中CUnitTypeData类的典型用法代码示例。如果您正苦于以下问题:C++ CUnitTypeData类的具体用法?C++ CUnitTypeData怎么用?C++ CUnitTypeData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CUnitTypeData类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NLOG
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("");
}
}
示例2: NLOG
bool CActions::AttackNear(int unit, float LOSmultiplier){
NLOG("CActions::AttackNear");
const UnitDef* ud = G->GetUnitDef(unit);
if(ud == 0) return false;
CUnitTypeData* utd = G->UnitDefLoader->GetUnitTypeDataById(ud->id);
int* en = new int[10000];
int e = G->GetEnemyUnits(en, G->GetUnitPos(unit), max(G->cb->GetUnitMaxRange(unit), ud->losRadius)*LOSmultiplier);
if(e>0){
float best_score = 0;
int best_target = 0;
float tempscore = 0;
bool mobile = true;
for(int i = 0; i < e; i++){
if(en[i] < 1) continue;
const UnitDef* endi = G->GetEnemyDef(en[i]);
if(endi == 0){
continue;
}else{
CUnitTypeData* etd = G->UnitDefLoader->GetUnitTypeDataById(endi->id);
bool tmobile = false;
tempscore = G->GetTargettingWeight(ud->name, endi->name);
//tempscore = G->Ch->ApplyGrudge(en[i], tempscore);
if(etd->IsMobile()){
if(!G->info->hardtarget){
tempscore = tempscore/4;
}
tmobile = true;
}else if(!endi->weapons.empty()){
tempscore /= 2;
}
if(tempscore > best_score){
best_score = tempscore;
best_target = en[i];
mobile = tmobile;
}
tempscore = 0;
}
}
if(ud->highTrajectoryType == 2){
Trajectory(unit, (int)mobile);
}
if(best_target > 0){
delete [] en;
return Attack(unit, best_target, mobile);
}
delete [] en;
return true;
}else{
delete [] en;
return false;
}
}
示例3: NLOG
bool CConfigTaskManager::LoadTaskList(){
NLOG("CConfigTaskManager::LoadTaskList");
CUnit* u = G->unit_array[unit];
CUnitTypeData* utd = u->GetUnitDataType();
vector<string> vl;
string sl;
if(G->Cached->cheating){
sl= G->Get_mod_tdf()->SGetValueMSG(string("TASKLISTS\\CHEAT\\")+utd->GetName());
}else{
sl = G->Get_mod_tdf()->SGetValueMSG(string("TASKLISTS\\NORMAL\\")+utd->GetName());
}
tolowercase(sl);
trim(sl);
string us = utd->GetName();
if(sl != string("")){
CTokenizer<CIsComma>::Tokenize(vl, sl, CIsComma());
if(vl.empty() == false){
int randnum = G->mrand()%vl.size();
us = vl.at(min(randnum,max(int(vl.size()-1),1)));
}
}
string s = G->Get_mod_tdf()->SGetValueMSG(string("TASKLISTS\\LISTS\\")+us);
if(s.empty()){
G->L.print(" error loading tasklist for unit :: \"" + us + "\" :: buffer empty, most likely because of an empty list");
nolist=true;
return false;
}
tolowercase(s);
trim(s);
vector<string> v;
CTokenizer<CIsComma>::Tokenize(v, s, CIsComma());
if(v.empty() == false){
G->L.print("loading contents of tasklist :: " + us + " :: filling tasklist with #" + to_string(v.size()) + " items");
bool polate=false;
bool polation = G->info->rule_extreme_interpolate;
btype bt = G->Manufacturer->GetTaskType(G->Get_mod_tdf()->SGetValueDef("b_na","AI\\interpolate_tag"));
if(utd->IsFactory()){
polation = false;
}
if(bt == B_NA){
polation = false;
}
// TASKS LOADING
for(std::vector<string>::iterator vi = v.begin(); vi != v.end(); ++vi){
if(polation){
if(polate){
boost::shared_ptr<IModule> t(new CKeywordConstructionTask(G,u->GetID(),bt));
tasks.push_back(t);
}
polate = !polate;
}
std::string q = *vi;
trim(q);
tolowercase(q);
CUnitTypeData* b = G->UnitDefLoader->GetUnitTypeDataByName(q);
if(b != 0){
boost::shared_ptr<IModule> t(new CUnitConstructionTask(G,u->GetID(),utd,b));
tasks.push_back(t);
}else if(q == string("")){
continue;
}else if(q == string("b_na")){
continue;
} else if(q == string("no_rule_interpolation")){
polation=false;
} else if(q == string("rule_interpolate")){
polation=true;
}else if(q == string("base_pos")){
G->Map->base_positions.push_back(G->GetUnitPos(u->GetID()));
} else if(q == string("gaia")){
G->info->gaia = true;
} else if(q == string("not_gaia")){
G->info->gaia = false;
} else if(q == string("switch_gaia")){
G->info->gaia = !G->info->gaia;
} else if(q == string("b_factory")){
boost::shared_ptr<IModule> t(new CKeywordConstructionTask(G,u->GetID(),B_FACTORY));
tasks.push_back(t);
} else if(q == string("b_power")){
boost::shared_ptr<IModule> t(new CKeywordConstructionTask(G,u->GetID(),B_POWER));
tasks.push_back(t);
} else if(q == string("b_defence")){
boost::shared_ptr<IModule> t(new CKeywordConstructionTask(G,u->GetID(),B_DEFENCE));
tasks.push_back(t);
//.........这里部分代码省略.........
示例4: CUnitTypeData
CUnitDefLoader::CUnitDefLoader(Global* GL){
// Initialize pointer to the Global class
G = GL;
// retrieve the number of unit definitions
unum = G->cb->GetNumUnitDefs();
// for debugging purposes:
//G->L.iprint("AI interface says this mod has this many units! :: "+to_string(unum));
// Check if a horrific error has occured
if(unum < 1){
// omgwtf this should never happen!
G->L.eprint("URGENT! GetNumUnitDefs returned ZERO!! This means that there are no unit definitions of any kind!!! Unrecoverable error!");
// A horrible event has occurred somewhere in the spring engine for this to have happened.
// Even if the AI could recover from this, the engine could not.
// Exit this method immediatly. A crash is likely but if the crash was fixed, the engine
// or another AI, would crash afterwards anyway.
return;
}
// initialize arrays
// The unitdeflist array will be passed to the engine where it will be filled with pointers
UnitDefList = new const UnitDef*[unum];
// retrieve the list of unit definition pointers from the engine
G->cb->GetUnitDefList(UnitDefList);
// for each definition
for(int n=0; n < unum; n++){
// retrieve the units definition
const UnitDef* pud = UnitDefList[n];
// initialize a UnitTypeData object
CUnitTypeData* cutd = new CUnitTypeData();
// now initialize the newly added object with the unit definition
cutd->Init(G,pud);
// add it into the main array
type_data[pud->id] = cutd;
// check if the unit definition is zero, if so skip
//if(pud == 0) continue;
// make sure the name is in the correct format and add it to the map container
string na = pud->name;
trim(na);
tolowercase(na);
defs[na] = pud->id;
}
}
示例5: OkBuildSelection
bool CUBuild::OkBuildSelection(string name){
CUnitTypeData* u =G->UnitDefLoader->GetUnitTypeDataByName(name);
float emax=1000000000;
string key = "Resource\\MaxEnergy\\";
key += u->GetName();
G->Get_mod_tdf()->GetDef(emax,"3000000",key);// +300k energy per tick by default/**/
if(G->Pl->GetEnergyIncome() > emax){
//G->L.print("Factor::CBuild emax " + name);
return false;
}
//NLOG("CManufacturer::CBuild Resource\\MinEnergy\\");
float emin=1;
key = "Resource\\MinEnergy\\";
key += u->GetName();
G->Get_mod_tdf()->GetDef(emin,"0",key);// +0k energy per tick by default/**/
if(G->Pl->GetEnergyIncome() < emin){
//G->L.print("Factor::CBuild emin " + name);
return false;
}
// Now sort out stuff that can only be built one at a time
if(u->GetSoloBuild()){
if(u->GetSoloBuildActive()){
// One is already being built! We're not supposed to build more than one at any one time.
return false;
}
deque<CBPlan* >* b = G->Manufacturer->BPlans;
if(b->empty() == false){
//
for(deque<CBPlan* >::iterator i = b->begin(); i != b->end(); ++i){
string s = (*i)->utd->GetName();
if(s == u->GetName()){
return false;
}
}
}
}
// Now sort out if it's one of those things that can only be built once
if(u->GetSingleBuild()){
if(u->GetSingleBuildActive()){
return false;
}
deque<CBPlan* >* b = G->Manufacturer->BPlans;
if(b->empty() == false){
//
for(deque<CBPlan* >::iterator i = b->begin(); i != b->end(); ++i){
string s = (*i)->utd->GetName();
if(s == name){
return false;
}
}
}
}
return true;
}