1 #include "spring_api.h" 2 CSpringMapFeature(springai::OOAICallback * callback,springai::Feature * f,IGame * game)3CSpringMapFeature::CSpringMapFeature(springai::OOAICallback* callback, springai::Feature* f, IGame* game) 4 :feature(f),callback(callback),game(game), def(f->GetDef()) { 5 // 6 } 7 ~CSpringMapFeature()8CSpringMapFeature::~CSpringMapFeature(){ 9 delete feature; 10 feature = NULL; 11 callback = NULL; 12 game = NULL; 13 delete def; 14 } 15 ID()16int CSpringMapFeature::ID(){ 17 if (feature==NULL) { 18 return -1; 19 } 20 return feature->GetFeatureId(); 21 } 22 Name()23std::string CSpringMapFeature::Name(){ 24 if ((feature == NULL) || (def==NULL)) { 25 return ""; 26 } 27 return def->GetName(); 28 } 29 GetPosition()30Position CSpringMapFeature::GetPosition(){ 31 if (feature == NULL) 32 return Position(0.0f,0.0f,0.0f); 33 const springai::AIFloat3 pos = feature->GetPosition(); 34 Position p; 35 p.x = pos.x; 36 p.y = pos.y; 37 p.z = pos.z; 38 return p; 39 } 40 ResourceValue(int idx)41float CSpringMapFeature::ResourceValue(int idx){ 42 std::vector<springai::Resource*> resources = callback->GetResources(); 43 float res = -1; 44 if(!resources.empty()){ 45 std::vector<springai::Resource*>::iterator i = resources.begin(); 46 for(;i != resources.end();++i){ 47 springai::Resource* r = *i; 48 if(r->GetResourceId() == idx){ 49 res = def->GetContainedResource(r); 50 } 51 delete r; 52 } 53 } 54 return res; 55 } 56 Reclaimable()57bool CSpringMapFeature::Reclaimable(){ 58 if (feature==NULL || def == NULL) 59 return false; 60 return def->IsReclaimable(); 61 } 62