Repository navigation
Expand file tree
/
Copy pathTribesHumanoid.java
More file actions
116 lines (94 loc) · 2.45 KB
/
Copy pathTribesHumanoid.java
File metadata and controls
116 lines (94 loc) · 2.45 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import java.util.ArrayList;
import java.awt.Graphics;
import java.awt.BasicStroke;
import java.util.Random;
class TribesHumanoid extends Humanoid{
ArrayList<int[]> path;
ArrayList<int[]> importantPositions;
public TribesHumanoid(boolean fed){
super();
path=new ArrayList<int[]>();
if(fed)
inventory=InventoryFactory.createHumanoidInventory();
else
inventory=InventoryFactory.createStarvingHumanoidInventory();
}
public void paint(Graphics g, int x, int y, int tilesize){
super.paint(g,x,y,tilesize);
g.drawImage(sprites[0], x*tilesize, y*tilesize, tilesize, tilesize,null);
}
public Inventory updateInventory(){return null;}
public void wantedMove(Isle island){
if(DayCycleClass.isDay() &&inventory.contains(Item.fishnet)){
for(int i=-1; i<2; i++){
for(int j=-1; j<2; j++){
if(island.insideMapPos(getX()+i, getY()+j) && island.isWater(getX()+i, getY()+j)){
action=true;
placex=i;
placey=j;
return;
}
}
}
}
Scout(island);
}
public void Scout(Isle island){
if((new Random()).nextDouble()>0.4)
return;
ArrayList<int[]>possiblemoves=new ArrayList<int[]>();
for(int i=-1; i<2; i++){
for(int j=-1; j<2; j++){
if(island.insideMapPos(i+x, j+y)){
if(!island.isEmpty(i+x, j+y) && island.isBush(i+x, j+y)){
placex=i;
placey=j;
action=true;
return;
}
if(island.validMovePosition(i+x,j+y) && island.isItem(i+x,j+y) && !island.otherPersonClose(i+x,j+y,x,y,4)){
possiblemoves.add(new int[]{i+x,j+y});
}
}
}
}
if(!possiblemoves.isEmpty()){
int[] tmp=possiblemoves.get((new Random()).nextInt(possiblemoves.size()));
x=tmp[0];
y=tmp[1];
return;
}
if(!path.isEmpty()){
int [] nextpos=path.remove(0);
if(Math.abs(x-nextpos[0]+y-nextpos[1])<=2){
if(!(DayCycleClass.positionLit(x,y) && !DayCycleClass.positionLit(nextpos[0],nextpos[1]))){
x=nextpos[0];
y=nextpos[1];
}
return;
}else{
path.clear();
}
}
int xdir=0;
int ydir=0;
do{
if((new Random()).nextInt(3)>0){
xdir=-1+2*(new Random()).nextInt(2);
}else{
xdir=0;
}
if((new Random()).nextInt(3)>0){
ydir=-1+2*(new Random()).nextInt(2);
}else{
ydir=0;
}
}while(xdir==0 && ydir==0);
int dx=xdir, dy=ydir;
while(island.insideMapPos(x+dx, y+dy) && island.validMovePosition(x+dx, y+dy)){
path.add(new int[]{x+dx, y+dy});
dx+=xdir;
dy+=ydir;
}
}
}