From e7cac5098145d75a680e35787f7c504caf16965b Mon Sep 17 00:00:00 2001 From: tom Date: Mon, 2 May 2016 22:02:25 -0500 Subject: fixed issue, was related to erasing nodes within vectors while using iterators --- src/creature.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/creature.cpp') diff --git a/src/creature.cpp b/src/creature.cpp index 24508bf..3ae02ce 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -13,14 +13,12 @@ Creature::Creature(Window m, std::string s) type = 1; hasTarget = false; - wandering = false; able = true; - n=0; } void Creature::Behavior() { - //health-=1; + health-=1; this->Priority(); @@ -29,11 +27,10 @@ void Creature::Behavior() void Creature::Priority() { - for(vector ::iterator it = N.begin(); it!=N.end(); it++){ - if((*it)->getType() == 2){ + for(list ::iterator it = N.begin(); it!=N.end(); it++){ + if((*it)->getType() == 2){ if(!hasTarget){ target = *it; - wandering = false; hasTarget = true; } else @@ -44,14 +41,18 @@ void Creature::Priority() void Creature::Action() { + //cout << "My coords:" << L.x << "," << L.y << endl; + cout << "Mytcoords:" << target->getLocation().x << "," << target->getLocation().y << endl << endl; if(hasTarget){ if(Distance(L,target->getLocation())<5){ target->eat(); health+=1000; } - if(target->getAmount()==0) + if(target->getAmount()==0){ hasTarget = false; + cout << "done\n"; + } } //Makes moves towards target coordinates -- cgit v1.2.3