summaryrefslogtreecommitdiff
path: root/src/creature.cpp
diff options
context:
space:
mode:
authormajortom6 <tombarrett@siu.edu>2017-02-19 12:00:52 -0600
committerTom Barrett <tombarrett@siu.edu>2017-03-07 13:23:41 -0600
commit0846d5802965d257f176e033d7a6ac353ed648f3 (patch)
tree1ada2e260970883decd2165d3dd3b74ad34212fd /src/creature.cpp
parentbfdc713b68dd6f8d61e7b26fc2cff15caf24b44d (diff)
-speedcaps now working again
-creatures now randomize target better again -thats enough for today, src is still a mess and main can be cleaned a bit
Diffstat (limited to 'src/creature.cpp')
-rw-r--r--src/creature.cpp102
1 files changed, 49 insertions, 53 deletions
diff --git a/src/creature.cpp b/src/creature.cpp
index 9f8204b..bf0ad43 100644
--- a/src/creature.cpp
+++ b/src/creature.cpp
@@ -2,66 +2,61 @@
Creature::Creature(Rectangle t, DNA D)
{
- rect = t;
- myDNA = D;
-
- if(rect.x == 0 && rect.y == 0){
- rect.x = -30.0 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30-(-30))));
- rect.y = -30.0 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30-(-30))));
- }
+ rect = t;
+ myDNA = D;
- gfxData.sides = 4.0;
- gfxData.x = rect.x;
- gfxData.y = rect.y;
-
- type = CREATURE_TYPE;
- health = myDNA.maxHealth/2;
- gender = rand() % 2;
- age = 0;
- pregnancyTime = 0;
- pregnancyReady = false;
- pregnate = false;
- hasTarget = false;
-
- if(gender){
- gfxData.r = 1.0;
- gfxData.g = 0.0;
- gfxData.b = 0.0;
- }
- else if(pregnate){
- gfxData.r = 1.0;
- gfxData.g = 0.0;
- gfxData.b = 1.0;
- }
- else{
- gfxData.r = 0.0;
- gfxData.g = 0.0;
- gfxData.b = 1.0;
- }
+ if(rect.x == 0 && rect.y == 0){
+ rect.x = getRandom(50);
+ rect.y = getRandom(50);
+ }
+
+ gfxData.sides = 4.0;
+ gfxData.x = rect.x;
+ gfxData.y = rect.y;
+
+ type = CREATURE_TYPE;
+ health = myDNA.maxHealth/2;
+ gender = rand() % 2;
+ age = 0;
+ pregnancyTime = 0;
+ pregnancyReady = false;
+ pregnate = false;
+ hasTarget = false;
+
+ if(gender){
+ gfxData.r = 1.0;
+ gfxData.g = 0.0;
+ gfxData.b = 0.0;
+ }
+ else{
+ gfxData.r = 0.0;
+ gfxData.g = 0.0;
+ gfxData.b = 1.0;
+ }
}
void Creature::Behavior()
{
- health-=1;
+ health-=1;
this->Priority();
- if(!hasTarget)
- this->setTarget();
- else
- this->checkTarget();
+ if(!hasTarget)
+ this->setTarget();
+ else
+ this->checkTarget();
this->Action();
- if(pregnate){
- pregnancyTime++;
- if(pregnancyTime > myDNA.expectedPregnancyTime)
- pregnancyReady = true;
- }
+ if(pregnate){
+ pregnancyTime++;
+ if(pregnancyTime > myDNA.expectedPregnancyTime)
+ pregnancyReady = true;
+ }
- age++;
- if(age > myDNA.expectedAge)
- health = 0;
+ age++;
+ if(age > myDNA.expectedAge)
+ health = 0;
}
void Creature::Priority()
@@ -78,8 +73,9 @@ void Creature::Priority()
void Creature::setTarget()
{
- //std::random_shuffle(N.begin(),N.end());
- for(std::list <Entity*>::iterator it = nearMe.begin(); it!=nearMe.end(); it++){
+ std::random_shuffle(nearMe.begin(),nearMe.end());
+
+ for(std::vector <Entity*>::iterator it = nearMe.begin(); it!=nearMe.end(); it++){
if( (*it)->getType() == RESOURCE_TYPE && hungry){
target = *it;
hasTarget = true;
@@ -96,8 +92,8 @@ void Creature::setTarget()
if(!hasTarget&&!wander){
wander = true;
- float x = -30.0 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30-(-30))));
- float y = -30.0 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30-(-30))));
+ float x = getRandom(50);
+ float y = getRandom(50);
Rectangle tmp;
tmp.x = x;
tmp.y = y;
@@ -107,7 +103,7 @@ void Creature::setTarget()
void Creature::checkTarget()
{
- for(std::list <Entity*>::iterator it = nearMe.begin(); it!=nearMe.end(); it++)
+ for(std::vector <Entity*>::iterator it = nearMe.begin(); it!=nearMe.end(); it++)
if( target == *it )
return;