File: fish.cpp

package info (click to toggle)
matrem 1.0-10
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 792 kB
  • ctags: 927
  • sloc: cpp: 3,133; makefile: 75
file content (76 lines) | stat: -rw-r--r-- 1,142 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#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);
}