Logo Search packages:      
Sourcecode: matrem version File versions

fish.cpp

#include "fish.h"

fish::fish(fish *parent) : creature(parent)
{
  species=FISH;
  hitpoints=200;
  power=0;
  health=50;
  speed=600;
  diet=atdiet[WATERPLANT];
  terrain=atterrain[RIVER];
  preparecreature(parent);
}  

void fish::choosejob()
{
 int x,y;
 x=xcoor;y=ycoor;
 if (load!=VOID)
 {
  if (atdiet[load]&diet)
   job=EAT;
  else if (!random(2))
  {dir=random(4);job=RUN;}
 }
 else if (p[x-1][y]==WATERPLANT)
 {
  dir=WEST;
  job=TAKE;
 }
 else if (p[x+1][y]==WATERPLANT)
 {
  dir=EAST;
  job=TAKE;
 }
 else if (p[x][y-1]==WATERPLANT)
 {
  dir=NORTH;
  job=TAKE;
 }
 else if (p[x][y+1]==WATERPLANT)
 {
  dir=SOUTH;
  job=TAKE;
 }
 else
 {
 if (!random(10))
  dir=random(4);
 job=RUN;
 }
 if (food>4*weight&&!random(10))
  job=MULTIPLY;
 if (!random(20)) {dir=random(4);job=RUN;}
 if (!random(100)&&load!=VOID) {dir=(random(3)+dir)%4;job=TAKE;}
}

int fish::lookslike()
{
return (dir==EAST)+
       2*(dir==NORTH&&status==ALIVE&&job!=TAKE)+
       3*(dir==SOUTH&&status==ALIVE&&job!=TAKE)+
       4*(status==DEAD)+6*(status==ALIVE&&job==TAKE);
}













Generated by  Doxygen 1.6.0   Back to index