summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormajortom6 <tombarrett@siu.edu>2017-03-05 13:13:44 -0600
committerTom Barrett <tombarrett@siu.edu>2017-03-07 13:23:42 -0600
commit8f5a73f1daba39c8b0175036cf688f8ce1399a8f (patch)
tree1bd365c1eb41d1b6f19ccac747919b2b762b72c0
parentdfda3f2a5e555d3173359134f4994bcd12d129f8 (diff)
-added carnivores
-removed creature type constant and replaced it with herbavore/carnivore type -replaced resource type with plant type -added eatType to dna (whatever the organism goes for hunger)
-rw-r--r--inc/constants.hpp14
-rw-r--r--inc/dna.hpp1
-rw-r--r--inc/list.hpp1
-rw-r--r--src/dna.cpp39
-rw-r--r--src/list.cpp20
-rw-r--r--src/organism.cpp8
6 files changed, 57 insertions, 26 deletions
diff --git a/inc/constants.hpp b/inc/constants.hpp
index e7d69b4..49b7678 100644
--- a/inc/constants.hpp
+++ b/inc/constants.hpp
@@ -2,15 +2,17 @@
#define constants_h
// General
-const int CREATURES = 100;
-const int RESOURCES = 1000;
-const int MINIMUM_RESOURCES = 5000;
+const int HERBAVORES = 100;
+const int CARNIVORES = 50;;
+const int PLANTS = 5000;
+const int MINIMUM_PLANTS = 4000;
const int WINDOW_X = 1000;
const int WINDOW_Y = 1000;
// Types
-const int CREATURE_TYPE = 1;
-const int RESOURCE_TYPE = 2;
+const int PLANT_TYPE = 1;
+const int HERBAVORE_TYPE = 2;
+const int CARNIVORE_TYPE = 3;
// Creatures
const int CREATURE_MAX_HEALTH = 1000;
@@ -19,9 +21,9 @@ const int CREATURE_BITE = 10;
const int CREATURE_EXP_PREG_TIME = 100;
const int CREATURE_EXP_AGE = 10000;
const float CREATURE_SPEED = .1;
+const float CREATURE_REACH = .1;
const float CREATURE_MUTATION_PERCENT = .25;
const float CREATURE_MUTATION_CHANCE = .05;
-const float CREATURE_REACH = .1;
// Resource
const int RESOURCE_MAX_HEALTH = 200;
diff --git a/inc/dna.hpp b/inc/dna.hpp
index 1126638..01f373b 100644
--- a/inc/dna.hpp
+++ b/inc/dna.hpp
@@ -15,6 +15,7 @@ class DNA
DNA combine(DNA D);
int type;
+ int eatType;
int maxHealth;
int bestSense;
int bite;
diff --git a/inc/list.hpp b/inc/list.hpp
index b5da34c..f43ba07 100644
--- a/inc/list.hpp
+++ b/inc/list.hpp
@@ -12,6 +12,7 @@ class List
{
public:
List();
+
void Behavior();
void Place();
void Remove();
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);
}