merge successful with staging
[biocity.git] / src / Organism.cpp
bloba33d6afa40f6ac0d80e5bfe15cecd8ee58a57fc5
1 #include <cmath>
2 #include <iostream>
3 #include "Organism.hh"
4 using namespace std;
6 Organism::Organism( int _tp, int _st, double _px, double _py )
8 ident = id;
9 id++;
11 type = _tp;
12 state = _st;
13 pos_x = _px;
14 pos_y = _py;
15 next_x = pos_x;
16 next_y = pos_y;
17 food = 0;
18 age = 0;
19 proximity = 0;
20 next_offspring = 0;
23 int Organism::identify()
25 return ident;
28 void Organism::next_state( )
30 age++;
31 pos_x = next_x;
32 pos_y = next_y;
33 proximity = 0;
36 //sensory functions
37 double Organism::distance_to( const Organism _o )
39 return( sqrt(
40 (pos_x - _o.pos_x)*(pos_x - _o.pos_x) +
41 (pos_y-_o.pos_y)*(pos_y - _o.pos_y)
46 int Organism::get_proximity( )
48 return proximity;
51 void Organism::set_proximity( int _prox )
53 proximity = _prox;
56 void Organism::add_proximity( int _prox )
58 proximity+= _prox;
61 void Organism::set_offspring( int _offspring )
63 next_offspring = _offspring;
66 int Organism::get_offspring( )
68 return next_offspring;
71 double Organism::get_x()
73 return( pos_x );
76 double Organism::get_y()
78 return( pos_y );
81 int Organism::get_type()
83 return( type );
86 int Organism::get_state()
88 return state;
91 void Organism::lifeup()
93 age++;
96 int Organism::get_age()
98 return age;
101 int Organism::set_state( int _st )
103 state = _st;
104 return state;
107 void Organism::change_pos( double _nx, double _ny )
109 next_x = _nx;
110 next_y = _ny;
113 void Organism::eat_food()
115 food++;
118 void Organism::use_food()
120 if (food > 0)
122 food--;
126 int Organism::get_food()
128 return food;
131 void Organism::add_pos( double _nx, double _ny )
133 pos_x += _nx;
134 pos_y += _ny;
137 void Organism::info( )
139 cout<<"(x,y) = ("<<pos_x<<" , "<<pos_y<<") , state = "<<state<<endl;