Logo Search packages:      
Sourcecode: matrem version File versions  Download package

milkacow.cpp

#include "milkacow.h"

milkacow::milkacow(milkacow *parent=NULL) : creature(parent)
{
  species=MILKACOW;
  hitpoints=410;
  power=10;
  health=100;
  speed=300;
  diet=atdiet[GRASS];
  terrain=atterrain[VOID];
  preparecreature(parent);
}  

void milkacow::choosejob()
{
  job=TAKE;
  if (load!=VOID)
    {
      if (load==GRASS)
      job=EAT;
      else if (!random(2))
      {dir=random(4);job=RUN;}
    }
  else if (p[xcoor-1][ycoor]==GRASS) dir=WEST;
  else if (p[xcoor+1][ycoor]==GRASS) dir=EAST;
  else if (p[xcoor][ycoor-1]==GRASS) dir=NORTH;
  else if (p[xcoor][ycoor+1]==GRASS) dir=SOUTH;
  else
    {
      if (!random(100)||!(terrain&atterrain[p[xcoor+dx[dir]][ycoor+dy[dir]]]))
      {
        dir=random(4);
        for (int prut=1;prut<4;prut++)
          if (terrain&atterrain[p[xcoor+dx[(prut+dir)%4]][ycoor+dy[(prut+dir)%4]]])
            {dir=(dir+prut)%4;}
      }
      job=RUN;
    }
  if (job==RUN&&food>weight*2.5&&random(10))
    job=MULTIPLY;
  if (!random(50)) {dir=random(4);job=RUN;}
}













Generated by  Doxygen 1.6.0   Back to index