-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJobs.py
More file actions
132 lines (99 loc) · 3.21 KB
/
Jobs.py
File metadata and controls
132 lines (99 loc) · 3.21 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import SorterRobot
import EntityTreasure
class Job(object):
def __init__(self):
self.jobDone = False
def doneJob(self):
self.jobDone = True
def checkHasDone(self,worker):
return False
def doJob(self,worker):
worker.currentJob = self
#print "doing job"
class JobIdle(Job):
def __init__(self):
super(JobIdle,self).__init__()
def checkHasDone(self,worker):
if len(worker.jobs) > 1:
self.jobDone = True
def doJob(self,worker):
super(JobIdle,self).doJob(worker)
class JobGoTo(Job):
def __init__(self,index):
super(JobGoTo,self).__init__()
self.index = index
def doJob(self,worker):
super(JobGoTo,self).doJob(worker)
self.goTo(worker,self.index)
def goTo(self,worker,index):
x = (index * 2 + 2)
if x>10:x=x-10
y = ((index / 5)+1) * 3
worker.dest = (x,y)
#print "Gone to",x,y
class JobPlaceTreasure(Job):
def __init__(self,index,treasure=None):
super(JobPlaceTreasure,self).__init__()
self.treasure = treasure
self.index = index
def doJob(self,worker):
super(JobPlaceTreasure,self).doJob(worker)
if self.treasure == None:self.treasure=worker.inHand
self.place(worker,self.treasure,self.index)
def place(self,worker,treasureValue,index):
x = (index * 2 + 2)
y = ((index / 5)+1) * 3
if x>10:
x-=10
y+=1
else:
y-=1
worker.level.entities.append(EntityTreasure.EntityTreasure(worker.level,x<<5,y<<5,treasureValue))
self.jobDone = True
worker.inHand = None
print "placed t at",index
class JobPickUpTreasure(Job):
def __init__(self,index):
super(JobPickUpTreasure,self).__init__()
self.index = index
def doJob(self,worker):
super(JobPickUpTreasure,self).doJob(worker)
self.pickUp(worker,self.index)
def pickUp(self,worker,index):
x = (index * 2 + 2)
y = ((index / 5)+1) * 3
if x>10:
x-=10
y+=1
else:
y-=1
for e in worker.level.entities:
if e==worker:continue
if e.x >>5 == x and e.y >>5 == y:
worker.inHand = e.value
worker.level.entities.remove(e)
self.jobDone = True
print "Picked up at",index
class JobSwapHandWithContainer(Job):
def __init__(self):
super(JobSwapHandWithContainer,self).__init__()
def doJob(self,worker):
super(JobSwapHandWithContainer,self).doJob(worker)
self.swap(worker)
def swap(self,worker):
temp = worker.inHand
worker.inHand = worker.inContainer
worker.inContainer = temp
self.jobDone = True
#print "Swapped"
class JobStoreTreasure(Job):
def __init__(self):
super(JobStoreTreasure,self).__init__()
def doJob(self,worker):
super(JobStoreTreasure,self).doJob(worker)
self.store(worker)
def store(self,worker):
worker.inContainer = worker.inHand
worker.inHand = None
self.jobDone = True
#print "stored"