-
Notifications
You must be signed in to change notification settings - Fork 4
/
child-gangster.nls
262 lines (202 loc) · 5.35 KB
/
child-gangster.nls
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
breed [ child-gangsters child-gangster ]
child-gangsters-own [
homeAdress
next-task
schoolAdress
hideoutAdress
stash-houseAdress
status
recruits
child-to-recruit
adult-gangster-drugs
tickStandStill
speed
leavingOffset
directionOffset
randomGreyPatch
stoppedByPolice
sick?
followedByPolice?
skipAttempt?
carriesDrug?
slinging?
already-recruited?
adult-gangster-order
]
to setup-agent-child-gangster
set-default-shape child-gangsters "person"
create-ordered-child-gangsters number-of-child-gangsters [ ; number-of-child-gangsters changed to integer
set homeAdress one-of houses
setxy [ xcor ] of homeAdress [ ycor ] of homeAdress
set schoolAdress min-one-of schools [ distance myself ]
;set birthDay 1 + random 9
;set age 5 + random 5
set color yellow
set status 10 + random 10
;set label age
set recruits 0
set skipAttempt? false
set carriesDrug? false
set slinging? false
set followedByPolice? false
set already-recruited? false
set hidden? true
set leavingOffset random 25
set speed 0.25
set next-task [ -> child-gangster-at-home ]
set sick? false
]
end
to child-gangster-walk-around
right random 45
left random 45
forward 0.25
let temp-child-gangster self
let temp-child-to-recruit one-of children with [recruitAttempt? = false] in-radius 2
get-sick
ifelse(sick? = true)[
set next-task [-> child-gangster-go-home]
][
ifelse(slinging? = true)[
set next-task [-> child-gangster-go-to-stash-house]
]
[
ifelse(temp-child-to-recruit != nobody and ( time > 650 or time < 550 ) and ( time > 250 or time < 150 ))[
ask temp-child-to-recruit[
set recruiter temp-child-gangster
set recruitAttempt? true
set-next-task[-> child-turn-to-child-gangster]
ask temp-child-gangster [
set child-to-recruit temp-child-to-recruit
set next-task [-> child-gangster-recruit-attempt]
]
]
] [
if (time + leavingOffset > 1000 or time + leavingOffset < 200)[
set next-task [-> child-gangster-go-home]
]
]
]
]
end
to set-next-task [next]
set previous-task next-task
set next-task next
end
to child-gangster-at-home
if (time + leavingOffset = 800)[
set hidden? false
set next-task[-> child-gangster-walk-around]
]
if(time = 0)[ set already-recruited? false ]
if (time + leavingOffset = 200)[
set hidden? false
set skipAttempt? false
set next-task[-> child-gangster-go-to-school]
]
get-sick
end
to child-gangster-go-to-school
face schoolAdress
set directionOffset random 100 + random -100
set heading heading + directionOffset
forward speed
if (distance schoolAdress < speed)[
set hidden? true
set followedByPolice? false
set next-task[-> child-gangster-in-school]
]
let currentPatch patch-here
let roll random 10
ifelse(roll < status and skipAttempt? = false)[
set next-task[-> child-gangster-walk-around]
][
set skipAttempt? true
]
end
to child-gangster-in-school
if (time + leavingOffset = 600)[
set hidden? false
set next-task[-> child-gangster-go-home]
]
end
to child-gangster-recruit-attempt
face child-to-recruit
ifelse(distance child-to-recruit > 1)[
forward 0.1
] [
set tickStandStill tickStandStill + 1
if (tickStandStill = 25)[
if(status > ([time-in-school] of child-to-recruit / 20) and ticks > 1200 and already-recruited? = false )[
; link-agents self child-to-recruit
set status status + 10
set already-recruited? true
ask child-to-recruit[
set breed child-gangsters
set color yellow
set status 10 + random 5
set recruits 0
set next-task [-> child-gangster-walk-around]
]
]
set tickStandStill 0
set next-task [-> child-gangster-walk-around]
]
]
end
to child-gangster-go-home
face homeAdress
set directionOffset random 100 + random -100
set heading heading + directionOffset
forward speed
if (distance homeAdress < speed)[
set hidden? true
set followedByPolice? false
set next-task[-> child-gangster-at-home]
]
end
to child-gangster-go-to-stash-house
face stash-houseAdress
forward 0.25
if(distance stash-houseAdress < 1)[
set carriesDrug? true
set next-task [-> child-gangster-transport-drugs]
]
end
to child-gangster-transport-drugs
face hideoutAdress
forward 0.25
if(distance hideoutAdress < 1)[
ask hideoutAdress [
set drugs drugs + 1
]
set status status + 10
set carriesDrug? false
set slinging? false
let tempHideOutAdress hideoutAdress
ask adult-gangster-order [
set pickup-place tempHideOutAdress
set adult-gangster-drugs-delivered? true
]
set next-task [-> child-gangster-walk-around]
]
end
to recieve-delivery-instructions
set stash-houseAdress min-one-of stash-houses [distance myself]
set next-task [-> child-gangster-go-to-stash-house]
end
to get-sick
if sick? = true[
if(random 100 = 1)[
set sick? false
;print (word "child " who " got healthy.")
]
]
if sick? = false[
ifelse(random 300 = 1)
[set sick? true
;print (word "child " who " got sick.")
]
[set sick? false]
]
end