From 1ddb996ac4a4fc78e5484acdadac2df95006b632 Mon Sep 17 00:00:00 2001 From: Tom Date: Sat, 1 Aug 2015 12:56:55 -0500 Subject: pushing before format --- src/creature.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++------ src/list.cpp | 28 ++++++++++++++++++++++++---- 2 files changed, 69 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/creature.cpp b/src/creature.cpp index 9590dde..d43bc2a 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -4,13 +4,16 @@ Creature::Creature(Window m, std::string s) //Constructor { texture = loadTexture(s, m); renderer = m.getRenderer(); - health = 100; + health = 500; + maxHealth = 1000; hunger = 0; //initializes random start coordinates for creature, target position is equivalent to it's position yPosition=yTarget=rand()%800; xPosition=xTarget=rand()%1200; hasTarget = false; + wandering = false; + able = true; n=0; } @@ -25,7 +28,7 @@ int Creature::Behavior() if(nR.size()) { nR[n]->eat(); - if(health<500) + if(healthgetLocation(),nR[0]->getLocation()); + n = 0; + continue; + } if(d>Distance(this->getLocation(),nR[i]->getLocation())) { @@ -49,14 +57,37 @@ void Creature::Priority() } } - if(nR.size()) + if(nR.size()==0) + hasTarget=false; + + // If there is available targets and the unit doesnt have a target, assign the closest one. + //cout << "size: " << nR.size() << endl; + //cout << "hastarget: "<< hasTarget << endl; + if(nR.size()>0&&!hasTarget) { xTarget = nR[n]->getLocation().x; yTarget = nR[n]->getLocation().y; hasTarget = true; + wandering = false; + } + // If there is not available targets and doesnt have a target, set a random location as a target + else if(nR.size()==0&&!hasTarget) + { + if(!wandering) + { + xTarget = rand()%1200; + yTarget = rand()%800; + wandering = true; + hasTarget = false; + } + else + { + Location L(xTarget,yTarget,1); + if(Distance(this->getLocation(),L)<5) + wandering = false; + hasTarget = false; + } } - else - hasTarget = false; } bool Creature::Action() @@ -69,7 +100,10 @@ bool Creature::Action() if(5 > Distance(this->getLocation(),nR[n]->getLocation())) { if(hasTarget) + { + hasTarget = false; return true; + } else return false; } @@ -136,3 +170,8 @@ double Creature::Distance(Location A, Location B) //computes distance between two points return sqrt(pow(A.x - B.x, 2) + pow(A.y - B.y, 2)); } + +bool Creature::doesItHaveTarget() +{ + return hasTarget; +} diff --git a/src/list.cpp b/src/list.cpp index 93d2312..379a113 100644 --- a/src/list.cpp +++ b/src/list.cpp @@ -4,7 +4,7 @@ List::List(Window m) //Constructor { int i; - for(i=0;i<25;i++) + for(i=0;i<3;i++) { Creature X(m,"img/Cbasic.png"); C.push_back(X); @@ -25,6 +25,14 @@ void List::Place() for(vector::iterator it = C.begin(); it!=C.end(); it++) it->Place(); + /* + if(R.size()<15) + { + Resource Y(m,"img/Rbasic.png"); + R.push_back(Y); + } + */ + //places all resources for(int j = 0; j N; for(int j = 0; j < R.size(); j++) - if(250>Distance(C[i].getLocation(),R[j].getLocation())) + if(C[i].getBestSense()>Distance(C[i].getLocation(),R[j].getLocation())) N.push_back(&R[j]); - - C[i].give(N); + + C[i].giveR(N); N.clear(); + vector M; + for(int j = 0; j < C.size(); j++) + { + if(j==i) + continue; + else if(C[i].getBestSense()>Distance(C[i].getLocation(),C[j].getLocation())) + M.push_back(&C[j]); + } + + C[i].giveC(M); + M.clear(); + // This kills the creature if(C[i].getHealth()<=0) { -- cgit v1.2.3