diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/dna.cpp | 39 | ||||
| -rw-r--r-- | src/list.cpp | 20 | ||||
| -rw-r--r-- | src/organism.cpp | 8 | 
3 files changed, 47 insertions, 20 deletions
| diff --git a/src/dna.cpp b/src/dna.cpp index ac2d500..4e22d7a 100644 --- a/src/dna.cpp +++ b/src/dna.cpp @@ -2,8 +2,9 @@  DNA::DNA(std::string s)  { -        if(s == "creature"){ -                type                    = CREATURE_TYPE; +        if(s == "herbavore"){ +                type                    = HERBAVORE_TYPE; +                eatType                 = PLANT_TYPE;                  maxHealth               = CREATURE_MAX_HEALTH;                  bestSense               = CREATURE_BEST_SENSE;                  bite                    = CREATURE_BITE; @@ -16,11 +17,30 @@ DNA::DNA(std::string s)                  mutationChance          = CREATURE_MUTATION_CHANCE;                  appearance.sides        = CREATURE_SIDES;                  appearance.red          = 0; -                appearance.green        = 1; +                appearance.green        = 0.5;                  appearance.blue         = 1;          } -        else if(s == "resource"){ -                type                    = RESOURCE_TYPE; +        else if(s == "carnivore"){ +                type                    = CARNIVORE_TYPE; +                eatType                 = HERBAVORE_TYPE; +                maxHealth               = CREATURE_MAX_HEALTH * 2; +                bestSense               = CREATURE_BEST_SENSE * 2; +                bite                    = CREATURE_BITE * 2; +                expectedPregnancyTime   = CREATURE_EXP_PREG_TIME; +                expectedAge             = CREATURE_EXP_AGE * 2; +                growAmount              = 0; +                reach                   = CREATURE_REACH * 2; +                speed                   = CREATURE_SPEED * 2; +                mutationPercent         = CREATURE_MUTATION_PERCENT; +                mutationChance          = CREATURE_MUTATION_CHANCE; +                appearance.sides        = CREATURE_SIDES; +                appearance.red          = 1; +                appearance.green        = 0; +                appearance.blue         = 0; +        } +        else if(s == "plant"){ +                type                    = PLANT_TYPE; +                eatType                 = 0;                  maxHealth               = RESOURCE_MAX_HEALTH;                  bestSense               = 0;                  bite                    = 0; @@ -41,7 +61,8 @@ DNA::DNA(std::string s)  DNA DNA::combine(DNA D)  {          DNA N; -        N.type                  = CREATURE_TYPE;  +        N.type                  = type;  +        N.eatType               = eatType;          N.maxHealth             = (maxHealth                    + D.maxHealth)/2;           N.bestSense             = (bestSense                    + D.bestSense)/2;           N.bite                  = (bite                         + D.bite)/2;  @@ -53,9 +74,9 @@ DNA DNA::combine(DNA D)          N.mutationPercent       = (mutationPercent              + D.mutationPercent)/2;          N.mutationChance        = (mutationChance               + D.mutationChance)/2;          N.appearance.sides      = CREATURE_SIDES; -        N.appearance.red        = 0; -        N.appearance.green      = 1; -        N.appearance.blue       = 1;   +        N.appearance.red        = appearance.red; +        N.appearance.green      = appearance.green; +        N.appearance.blue       = appearance.blue;          if(roll(mutationChance)){                  float pn; diff --git a/src/list.cpp b/src/list.cpp index d4b9529..9d32b21 100644 --- a/src/list.cpp +++ b/src/list.cpp @@ -3,15 +3,21 @@  List::List()  {          int i; -        DNA d = DNA("creature"); +        DNA d = DNA("herbavore");          Rectangle tmp; -        for(i=0;i<CREATURES;i++){ +        for(i=0;i<HERBAVORES;i++){                  Organism X(tmp,d);                  creatures.push_back(X);          } -        d = DNA("resource"); -        for(i=0;i<RESOURCES;i++){ +        d = DNA("carnivore"); +        for(i=0;i<CARNIVORES;i++){ +                Organism X(tmp, d); +                creatures.push_back(X); +        } +         +        d = DNA("plant"); +        for(i=0;i<PLANTS;i++){                  Organism X(tmp, d);                  resources.push_back(X);          } @@ -24,7 +30,7 @@ void List::Remove()  {          for(std::list<Organism>::iterator it = creatures.begin(); it!= creatures.end(); it++)                      if(it->getHealth()<=0){ -                        DNA d = DNA("resource"); +                        DNA d = DNA("plant");                          Organism X(it->getRectangle(), d);                          resources.push_back(X);                          creatures.erase(it--); @@ -58,8 +64,8 @@ void List::Place()          tree.clear();          Rectangle tmp; -        DNA d = DNA("resource"); -        while(resources.size() < MINIMUM_RESOURCES){ +        DNA d = DNA("plant"); +        while(resources.size() < MINIMUM_PLANTS){                  Organism X(tmp, d);                  resources.push_back(X);          } diff --git a/src/organism.cpp b/src/organism.cpp index ee9f849..93e2041 100644 --- a/src/organism.cpp +++ b/src/organism.cpp @@ -61,13 +61,13 @@ void Organism::setTarget()          std::random_shuffle(nearMe.begin(),nearMe.end());          for(std::vector<Organism*>::iterator it = nearMe.begin(); it!=nearMe.end(); it++){ -                if( (*it)->getType() == RESOURCE_TYPE && hungry){  +                if( (*it)->getType() == myDNA.eatType && hungry){                           target = *it;                          hasTarget = true;                          wander = false;                          break;                  }  -                if( (*it)->getType() == CREATURE_TYPE && able && (*it)->getGender() != gender ){ +                if( (*it)->getType() == myDNA.type && able && (*it)->getGender() != gender ){                          target = *it;                          hasTarget = true;                          wander = false; @@ -95,13 +95,13 @@ void Organism::Action()  {	          if(hasTarget){                   if(Distance(rect,target->getRectangle()) < myDNA.reach){ -                        if(target->getType() == RESOURCE_TYPE){ +                        if(target->getType() == myDNA.eatType){                                  target->takeBite(myDNA.bite);                                  health+=myDNA.bite;                                  if(target->getHealth()<=0)                                          hasTarget = false;                          } -                        else if (target->getType() == CREATURE_TYPE){ +                        else if (target->getType() == myDNA.type){                                  if(target->getGender() != gender){                                          target->passDNA(myDNA);                                  } | 
