From 0846d5802965d257f176e033d7a6ac353ed648f3 Mon Sep 17 00:00:00 2001 From: majortom6 Date: Sun, 19 Feb 2017 12:00:52 -0600 Subject: -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 --- src/creature.cpp | 102 ++++++++++++++++++++++++++----------------------------- 1 file changed, 49 insertions(+), 53 deletions(-) (limited to 'src/creature.cpp') 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 (rand()) / (static_cast (RAND_MAX/(30-(-30)))); - rect.y = -30.0 + static_cast (rand()) / (static_cast (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 ::iterator it = nearMe.begin(); it!=nearMe.end(); it++){ + std::random_shuffle(nearMe.begin(),nearMe.end()); + + for(std::vector ::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 (rand()) / (static_cast (RAND_MAX/(30-(-30)))); - float y = -30.0 + static_cast (rand()) / (static_cast (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 ::iterator it = nearMe.begin(); it!=nearMe.end(); it++) + for(std::vector ::iterator it = nearMe.begin(); it!=nearMe.end(); it++) if( target == *it ) return; -- cgit v1.2.3