Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extensions [bitmap]
- breed [humans human]
- humans-own [behavior] ; comportamentul oamenilor (Stau pe loc [0] sau se pot misca [1])
- patches-own [exit-value]
- globals [dead saved c_id]
- breed [sensors sensor]
- sensors-own [isfire x1 y1 x2 y2 isHallway]
- breed [alarms alarm]
- alarms-own [isfire]
- breed [controllers controller]
- controllers-own [isfire]
- to setup-sensors
- create-sensors 7
- [
- set shape "arrow"
- set color yellow
- set heading 180
- set isHallway 0
- ifelse who = 0 [setxy 5 4 set x1 0 set y1 0
- set x2 11 set y2 9]
- [ifelse who = 1 [setxy 5 18 set x1 0 set y1 15
- set x2 11 set y2 21]
- [ifelse who = 2 [setxy 25 4 set x1 19 set y1 0
- set x2 31 set y2 11]
- [ifelse who = 3 [setxy 25 17 set x1 19 set y1 13
- set x2 31 set y2 21]
- [ifelse who = 4 [setxy 5 29 set x1 0 set y1 27
- set x2 11 set y2 31]
- [ifelse who = 5 [setxy 25 27 set x1 19 set y1 23
- set x2 31 set y2 31]
- [ifelse who = 6 [setxy 15 14 set isHallway 1]
- [ifelse who = 7 [setxy 0 15]
- []]]]]]]]
- ]
- end
- to setup-alarms
- create-alarms 7
- [
- set shape "circle"
- set color pink
- set heading 180
- let offset 7
- ifelse who = offset + 0 [setxy 6 4]
- [ifelse who = offset + 1 [setxy 6 18]
- [ifelse who = offset + 2 [setxy 26 4]
- [ifelse who = offset + 3 [setxy 26 17]
- [ifelse who = offset + 4 [setxy 6 29]
- [ifelse who = offset + 5 [setxy 26 27]
- [ifelse who = offset + 6 [setxy 16 14]
- [ifelse who = offset + 7 [setxy 1 15]
- []]]]]]]]
- ]
- end
- to setup-controllers
- create-controllers 1
- [
- set shape "square"
- set color green
- set heading 180
- setxy 12 10
- ]
- end
- to setup
- clear-all
- setup-sensors
- setup-alarms
- setup-controllers
- load-patches
- place-humans
- reset-ticks
- end
- to load-patches
- ; aici incarc culorile patchurilor
- import-pcolors "floor.bmp"
- end
- to place-humans
- create-humans number-humans
- [
- set heading random 360
- set behavior random 2
- set shape "person"
- set color white
- let invalid-location? true
- while [invalid-location?]
- [
- let xcoord random-pxcor
- let ycoord random-pycor
- let patch-color [pcolor] of patch xcoord ycoord
- if patch-color != 0 and patch-color != 64.5
- [
- setxy xcoord ycoord
- set invalid-location? false
- ]
- ]
- ]
- end
- to go
- spread-fire ; raspandirea focului
- move-humans
- death-humans
- detect-fire
- process-exits
- tick-controllers
- tick
- end
- to move-humans
- ask humans
- [
- ifelse count alarms with [color = magenta] != 0
- [
- uphill exit-value
- ]
- [
- if behavior = 1
- [
- if count patches with [pcolor = red] = 0
- [
- let invalid-destination? true
- while [invalid-destination?]
- [
- let destination patch-ahead 1
- ifelse destination = nobody or [pcolor] of destination = 0 or [pcolor] of destination = red
- [set heading random 360]
- [set invalid-destination? false]
- ]
- forward 1
- ]
- ]
- ]
- ]
- end
- to fire-offices
- ask one-of patches with [pcolor = 105]
- [
- set pcolor red
- ]
- end
- to fire-conference
- ask one-of patches with [pcolor = 115.3]
- [
- set pcolor red
- ]
- end
- to spread-fire
- ask patches with [pcolor = red]
- [
- if random-float 100 < fire-speed
- [
- let neighbor one-of neighbors with [position pcolor [red 64.5 0] = false]
- if neighbor != nobody
- [
- ask neighbor [ set pcolor red ]
- ]
- ]
- ]
- end
- to process-exits
- ask patches with [pcolor = 64.5] [ set exit-value exit-value + 10 ]
- diffuse exit-value 0.5
- ask patches [ set exit-value exit-value * 0.9 ]
- ask patches with [ pcolor = 0 ] [ set exit-value 0 ]
- end
- to death-humans
- ask humans
- [
- if pcolor = red
- [
- set dead dead + 1
- die
- ]
- if pcolor = 64.5
- [
- set saved saved + 1
- die
- ]
- ]
- end
- to detect-fire
- ask sensors
- [
- let iisFire 0
- let x11 x1
- let x22 x2
- let y11 y1
- let y22 y2
- let t self
- ifelse isHallway = 1
- [
- ask patches with [pxcor >= 0 and pxcor <= 12 and pycor >= 23 and pycor <= 25]
- [if pcolor = red [set iisFire 1]]
- ask patches with [pxcor >= 3 and pxcor <= 12 and pycor >= 11 and pycor <= 13]
- [if pcolor = red [set iisFire 1]]
- ask patches with [pxcor >= 13 and pxcor <= 17 and pycor >= 0 and pycor <= 28]
- [if pcolor = red [set iisFire 1]]
- ][
- ask patches with [pxcor >= x11 and pxcor <= x22 and pycor >= y11 and pycor <= y22]
- [
- if pcolor = red
- [
- set iisFire 1
- ]
- ]
- ]
- if iisFire = 1
- [
- set color orange
- set isFire 1
- ]
- ]
- end
- to tick-controllers
- ask sensors
- [
- if isFire = 1
- [
- ask alarms[
- set color magenta
- ]
- ]
- ]
- end
- to check-alarm
- ask alarms[
- set color magenta
- ]
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement