CitySCAPE Critical Systems

CitySCAPE Critical Systems preview image

1 collaborator

Tags

airplane 

Tagged by George-Alexandru Serea over 2 years ago

crash 

Tagged by George-Alexandru Serea over 2 years ago

critical systems 

Tagged by George-Alexandru Serea over 2 years ago

critical systems protocols 

Tagged by George-Alexandru Serea over 2 years ago

critical systems@ 

Tagged by George-Alexandru Serea over 2 years ago

disasters 

Tagged by George-Alexandru Serea over 2 years ago

earthquake 

Tagged by George-Alexandru Serea over 2 years ago

fire 

Tagged by George-Alexandru Serea over 2 years ago

traffic 

Tagged by George-Alexandru Serea over 2 years ago

trains 

Tagged by George-Alexandru Serea over 2 years ago

Visible to everyone | Changeable by the author
Model was written in NetLogo 5.1.0 • Viewed 539 times • Downloaded 48 times • Run 0 times
Download the 'CitySCAPE Critical Systems' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

;; Author: George-Alexandru Serea, Univeristy Politehnica of Bucharest, Romania, 2013
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;start
globals 
[
  ; butoane pentru interfata
  butoane
  ; cladiri monitorizate
  cladiri-monitorizate
  ; agenti pentru monitorizarea cladirilor => senzori
  senzori-monitorizare ;=> senzori
  ; elemente de monitorizare pentru interfata
  elemente-afisare
  ; cladiri
  cladiri
  spital
  baraj
  hidrocentrala
  centrala-nucleara
  gara-periferie
  gara-oras
  aeroport pista-aeroport pozitie-spawn-avioane
  ; sine si trenuri
  sina-1 sina-2 sina-3 sina-4 sine-tren
  tren-1 tren-2 tren-3 tren-4 ; trenuri ; nu este necesar deoarece toate au categoria feroviar
  
  ;setari pentru interfata
  limita-dreapta
  limita-jos
  ; variabile pentru trenuri
  timp-stationare-trenuri
  ; viteze:
  v-oameni v-masini v-autobuze v-camioane v-trenuri v-avioane 
  ; acceleratii:
  a-oameni a-masini a-autobuze a-camioane a-trenuri a-avioane
  ; distante dintre agenti
  d-oameni d-masini d-autobuze d-camioane d-trenuri d-avioane
  ; distante de franare
  df-oameni df-masini df-autobuze df-camioane df-trenuri df-avioane
  ; indici de virare
  vir-oameni vir-masini vir-autobuze vir-camioane vir-trenuri vir-avioane
  ; categorie
  cat-oameni cat-masini cat-autobuze cat-camioane cat-trenuri cat-avioane
  ; dimensiune
  dim-oameni dim-masini dim-autobuze dim-camioane dim-trenuri dim-avioane
  ; setari harta
  culoare-sosea culoare-trotuar latime-trotuar ; spatiu-cladiri marime-cladiri
  ; variabile plotare
  masini-plotate
  ; zona epicentru
  zona-epicentru
  ; pentru afisarea timpului de rulare
  timer-running
  timer-dummy
  last-tick-running
]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;breeds
; mobile agent types
breed [oameni om]
breed [masini masina]
breed [camioane camion]
breed [autobuze autobus]
breed [trenuri tren]
breed [avioane avion]
breed [copaci copac]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;agenti statici
; static agent types
breed [semafoare semafor]
breed [fiz-cladiri fiz-cladire] ;;overlay peste patch-uri?
breed [senzori senzor] ;; verifica starea unei anume cladiri

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;variabile agenti
; custom variables
patches-own
[
  nivel tip benzi id safe id-cladire stare alerta
  ; tip poate fi: interfata, iarba, cladire, aeroport, pista, sosea, trotuar
  ; safe va fi folosit pentru a restrictiona acesul masinilor pe anumite drumuri, i.e. drumurile de langa cladirile care ard
  ; id cladire este folosit de catre elementele din interfata pentru a identifica corect indicatorul
  ; stare este folosit pentru a detalia si mai mult indicatorul; exemple pentru campul stare: cutremur, incendiu, functional, etc...
  ; alerta este setat de catre senzori si este folosit pentru a aprinde 
]
turtles-own
[
  viteza acceleratie distanta distanta-franare virare categorie 
]
masini-own
[
  ales-viraj virez-stanga
]
autobuze-own
[
  ales-viraj virez-stanga
]
camioane-own
[
  ales-viraj virez-stanga
]
trenuri-own
[
  tren-id ; folosit pentru a identifica trenul. Locomotivele si vagoanele au id-ul acesta egal pentru fiecare tren in parte.
  timp-stationare ; exprimat in secunde, va fi folosit pentru oprirea trenului in gara
  timp-ajuns-gara ; momentul in care trenul a oprit in gara
  locomotiva ; este locomotiva?
  ;; pentru miscare se va folosi forward 1 sau forward -1. Heading ramane neschimbat.
]
avioane-own
[
  altitudine
  aterizeaza
  prabuseste
  tinta
]
senzori-own
[
  cladire-id
  eveniment-urmarit
  intensitate
  prag
  id-senzor
]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;setup;;

to setup
  clear-all  
  ; global variables setup:
  set butoane []
  set cladiri-monitorizate []
  set senzori-monitorizare []
  set-default-shape senzori "senzor"
  set-default-shape copaci "tree"
  set elemente-afisare []
  set cladiri []
  setup-globals
  ; environmental setup:
  setup-harta
  ; interface setup:
  setup-interfata
  ; agents setup:
  setup-agenti
  
  ;user-message (word "Nota: Trenurile sunt setate sa stationeze in gara " timp-stationare-trenuri " secunde si vor porni din starea de 'stationat'.\n\nTimpul se poate modifica pentru fiecare tren in parte folosind comanda in consola:\n\task tren-N [ set timp-stationare T ]")
  reset-timer
  reset-ticks
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;go;;

to go
  ; agent motion:
  orienteaza-agenti
  misca-agenti
  ; actualizeaza-monitorizarea ; ==> va fi apelat de catre functia generatoare de evenimente!
  tick
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;variabile globale
__includes ["_globals.nls"] ;; to setup-globals...

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;setup interfata;;

to setup-interfata
  
  ;adauga-elemente-monitorizare [ start-x-em start-y-em X-em Y-em dim-em spatiu-em id-em cladire-parinte stari-urmarite ]
  adauga-elemente-monitorizare -100 -36 6 1 3 2 ( [id] of one-of aeroport ) "Airport" [ "operating" "quarantine" "fire" "earthquake" "blackout" "threat" ]
  adauga-elemente-monitorizare  -60 -36 6 1 3 2 ( [id] of one-of gara-periferie ) "Railroad Station" [ "operating" "quarantine" "fire" "earthquake" "blackout" "threat" ]
  adauga-elemente-monitorizare  -20 -36 6 1 3 2 ( [id] of one-of gara-oras ) "City Train Station" [ "operating" "quarantine" "fire" "earthquake" "blackout" "threat" ]
  adauga-elemente-monitorizare   20 -36 5 1 3 2 ( [id] of one-of centrala-nucleara ) "Nuclear Plant" [ "operating" "quarantine" "fire" "earthquake" "threat" ]
  adauga-elemente-monitorizare   60 -36 5 1 3 2 ( [id] of one-of hidrocentrala ) "Hydro-electric Plant" [ "operating" "quarantine" "fire" "earthquake" "threat" ]
  adauga-elemente-monitorizare  100 -36 7 1 3 2 ( [id] of one-of spital ) "Hospital (yellow)" [ "operating" "quarantine" "fire" "earthquake" "robbery" "threat" "blackout" ]
  
  ;adauga-senzori-monitorizare [ cladire-parinte stari-urmarite praguri ]
  adauga-senzori-monitorizare ( [id] of one-of aeroport ) [ "quarantine" "fire" "earthquake" "blackout" "threat" ] [ 1 1 4 1 1 ]
  adauga-senzori-monitorizare ( [id] of one-of gara-periferie ) [ "quarantine" "fire" "earthquake" "blackout" "threat" ] [ 1 1 4 1 1 ]
  adauga-senzori-monitorizare ( [id] of one-of gara-oras ) [ "quarantine" "fire" "earthquake" "blackout" "threat" ] [ 1 1 4 1 1 ]
  adauga-senzori-monitorizare ( [id] of one-of centrala-nucleara ) [ "quarantine" "fire" "earthquake" "threat" ] [ 1 1 5.5 1 ]
  adauga-senzori-monitorizare ( [id] of one-of hidrocentrala ) [ "quarantine" "fire" "earthquake" "threat" ] [ 1 1 5 1 ]
  adauga-senzori-monitorizare ( [id] of one-of spital ) [ "operating" "quarantine" "fire" "earthquake" "robbery" "threat" "blackout" ] [ 1 1 1 6 1 1 1 ]
end 

to actualizeaza-monitorizarea
  ; Din punct de vedere al cladirilor monitorizate:
  ;    - pentru fiecare cladire in parte actualizam senzorii si in functie de modificarile aduse setam alarma si starea de functionare
  ;
  ; Functionarea si alarma se seteaza in functie de citirile senzorilor astfel:
  ;    - functionarea inceteaza pentru orice eveniment ( jaf cutremur incendiu inundatie etc )
  ;    - alarma se activeaza pentru evenimente care necesita prezenta echipajelor de interventie ( jaf incendiu etc )
  foreach cladiri-monitorizate
  [
    let cladire-curenta ?
    let senzori-activi 0
    let senzori-interventie 0
    ask senzori with [ cladire-id = ( [id] of ( one-of ? ) ) ] ; ? este agentset de patch-uri
    [
      let senzor-curent self
      let element-afisare ( patches with [ ( tip = "interfata" ) and ( id-cladire = ( [cladire-id] of senzor-curent ) ) and ( stare = ( [eveniment-urmarit] of senzor-curent ) ) ] )
      ifelse ( intensitate >= prag )
      [
        ask element-afisare [ set pcolor red ]
        set senzori-activi ( senzori-activi + 1 )
        if ( position ( eveniment-urmarit ) [ "robbery" "fire" "quarantine" "threat" ] != false )
        [
          set senzori-interventie 1
        ]
      ]
      [
        ask element-afisare [ set pcolor green ]
      ]
    ]
    ;show (word "S-au activat " senzori-activi " senzori ")
    ifelse ( senzori-activi > 0 )
    [
      ask ( patches with [ ( tip = "interfata" ) and ( id-cladire = ( [id] of ( one-of cladire-curenta ) ) ) and ( stare = "operating" ) ] )
      [
        set pcolor red
        ;; verificari pentru trenuri!
        if ( [id] of one-of cladire-curenta = [id] of one-of aeroport )
        [
          ask trenuri with [ id = 1 or id = 2 ] [ set viteza 0 ]
        ]
        if ( [id] of one-of cladire-curenta = [id] of one-of gara-periferie )
        [
          ask trenuri [ set viteza 0 ]
        ]
        if ( [id] of one-of cladire-curenta = [id] of one-of gara-oras )
        [
          ask trenuri with [ id = 3 or id = 4 ] [ set viteza 0 ]
        ]
      ]
    ]
    [
      ask ( patches with [ ( tip = "interfata" ) and ( id-cladire = ( [id] of ( one-of cladire-curenta ) ) ) and ( stare = "operating" ) ] )
      [
        set pcolor green
        let g-p one-of ( patches with [ ( tip = "interfata" ) and ( id-cladire = ( [id] of ( one-of gara-periferie ) ) ) and ( stare = "operating" ) ] )
        let g-o one-of ( patches with [ ( tip = "interfata" ) and ( id-cladire = ( [id] of ( one-of gara-oras ) ) ) and ( stare = "operating" ) ] )
        let ae one-of ( patches with [ ( tip = "interfata" ) and ( id-cladire = ( [id] of ( one-of aeroport ) ) ) and ( stare = "operating" ) ] )
        ;; verificari pentru trenuri
        if ( ( [pcolor] of ae = green ) and ( [pcolor] of g-p = green ) )
        [
          ask tren-1 [ set viteza ( v-trenuri ) ]
          ask tren-2 [ set viteza ( - v-trenuri ) ]
        ]
        if ( ( [pcolor] of g-p = green ) and ( [pcolor] of g-o = green ) )
        [
          ask tren-3 [ set viteza ( v-trenuri ) ]
          ask tren-4 [ set viteza ( - v-trenuri ) ]
        ]
      ]
    ]
    ;show senzori-interventie
    ifelse ( senzori-interventie > 0 )
    [
      ask ( patches with [ ( tip = "interfata" ) and ( id-cladire = ( [id] of ( one-of cladire-curenta ) ) ) and ( stare = "quarantine" ) ] )
      [
        set pcolor red
      ]
      ; trebuie sa delimitez perimetrul
      seteaza-perimetru-cladire ( [id] of ( one-of cladire-curenta ) ) ( [tip] of ( one-of cladire-curenta ) )
    ]
    [
      ask ( patches with [ ( tip = "interfata" ) and ( id-cladire = ( [id] of ( one-of cladire-curenta ) ) ) and ( stare = "quarantine" ) ] )
      [
        set pcolor green
      ]
    ] 
  ]
  
  ; efect grafic pentru epicentru
  let magnitudine-actuala ( max [intensitate] of ( senzori with [ eveniment-urmarit = "earthquake" ] ) )
  ifelse ( magnitudine-actuala > 0 )
  [
    ask zona-epicentru [ set pcolor ( 65 - ( magnitudine-actuala / 2 ) ) ]
  ]
  [
    ask zona-epicentru [ set pcolor 65 ]
  ]
end 

to actualizeaza-cutremur [ mag-cutremur ]
  ask senzori with [ eveniment-urmarit = "earthquake" ]
  [
    set intensitate ( mag-cutremur )
  ]
  ifelse ( mag-cutremur > 4 ) ; de la 4 grade un cutremur este simtit de catre toata lumea
  [
    ask turtles with [ categorie = "pietoni" or categorie = "rutier" or categorie = "feroviar" ]
    [
      set viteza 0
    ]
  ]
  [
    ; re-seteaza vitezele stabilite
    ; oameni
    ask oameni [ set viteza v-oameni ]
    ask masini [ set viteza v-masini ]
    ask autobuze [ set viteza v-autobuze ]
    ask camioane [ set viteza v-camioane ]
    ; fiecare tren in parte
    ask tren-1 [ set viteza ( v-trenuri ) ]
    ask tren-2 [ set viteza ( - v-trenuri ) ]
    ask tren-3 [ set viteza ( v-trenuri ) ]
    ask tren-4 [ set viteza ( - v-trenuri ) ]
  ]
  actualizeaza-monitorizarea
  print (word floor timer "s: Seismic Activity or magnitude set to " mag-cutremur " on the Richter Scale")
end 

to reseteaza-lume
  ; elimina toate pericolele si readuce lumea la starea "pasnica"
  ; 1) elimina evenimentele din senzori
  ask senzori [ set intensitate 0 ]
  ; 2) refa soselele si trotuarele
  ask patches with [ tip = "sosea" ]
  [
    set pcolor culoare-sosea
    set safe true
  ]
  ask patches with [ tip = "trotuar" ]
  [
    set pcolor culoare-trotuar
    set safe true
  ]
  ; 3) oamenii nu mai sunt forte de interventie
  ask oameni [ set color black ]
  ; 4) anuleaza cutremurul
  actualizeaza-cutremur 0 ; actualizeaza si interfata
  ; 5) actualizeaza interfata
  ;actualizeaza-monitorizarea  
end 

to aplica-eveniment-cladire [ cladire-tinta eveniment-propus ]
  ; selctia cladirii tinta
  if ( cladire-tinta = "The Airport" ) [ set cladire-tinta ( [id] of ( one-of aeroport ) ) ]
  if ( cladire-tinta = "The Railroad Station" ) [ set cladire-tinta ( [id] of ( one-of gara-periferie ) ) ]
  if ( cladire-tinta = "The city Train Station" ) [ set cladire-tinta ( [id] of ( one-of gara-oras ) ) ]
  if ( cladire-tinta = "The Hospital" ) [ set cladire-tinta ( [id] of ( one-of spital ) ) ]
  if ( cladire-tinta = "The Nuclear Plant" ) [ set cladire-tinta ( [id] of ( one-of centrala-nucleara ) ) ]
  if ( cladire-tinta = "The Hydro-electric Plant" ) [ set cladire-tinta ( [id] of ( one-of hidrocentrala ) ) ]
  
  let senzor-exista ( senzori with [ cladire-id = ( cladire-tinta ) and eveniment-urmarit = ( eveniment-propus ) ] )
  ifelse ( count senzor-exista < 1 )
  [
    user-message (word "Sorry, the selected building doesn't have a sensor for the " eveniment-propus " event.\n\nPlease select another event or building." )
    ;user-message (word "Imi pare rau, dar cladirea selectata nu are senzor pentru " eveniment-propus ".\n\nVa rog selectati alta cladire sau alt eveniment." )
  ]
  [
    ask senzor-exista [
      set intensitate prag
    ]
    actualizeaza-monitorizarea
  ]
end 
  
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ADAUGAREA AGENTILOR
;; Adaugarea agentiilor ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;setup agenti;;

to setup-agenti
  create-oameni numpeople [
    set viteza v-oameni ;; viteza initiala acum este nula
    set acceleratie a-oameni
    set distanta d-oameni
    set distanta-franare df-oameni
    set virare vir-oameni
    set categorie cat-oameni
    set size dim-oameni
    set shape "person"
    set color brown - 3
    move-to one-of ( patches with [ tip = "trotuar" ] )
  ]
  create-masini numcars [
    set viteza v-masini ;; viteza initiala acum este nula
    set acceleratie a-masini
    set distanta d-masini
    set distanta-franare df-masini
    set virare vir-masini
    set categorie cat-masini
    set size dim-masini
    set shape "car"
    set color one-of [ red orange brown yellow green lime turquoise cyan sky blue violet magenta pink ]
    ;let pozitii ( patches with [ tip = "sosea"] )
    move-to one-of ( patches with [ tip = "sosea" and ( count turtles-here ) < 1 ] )
  ]
  create-autobuze numbuses [
    set viteza v-autobuze ;; viteza initiala acum este nula
    set acceleratie a-autobuze
    set distanta d-autobuze
    set distanta-franare df-autobuze
    set virare vir-autobuze
    set categorie cat-autobuze
    set size dim-autobuze
    set shape "bus"
    set color one-of [ red orange brown yellow green lime turquoise cyan sky blue violet magenta pink ]
    move-to one-of ( patches with [ tip = "sosea" and ( count turtles-here ) < 1 ] )
  ]
  create-camioane numtrucks [
    set viteza v-camioane ;; viteza initiala acum este nula
    set acceleratie a-camioane
    set distanta d-camioane
    set distanta-franare df-camioane
    set virare vir-camioane
    set categorie cat-camioane
    set size dim-camioane
    set shape "truck"
    set color one-of [ red orange brown yellow green lime turquoise cyan sky blue violet magenta pink ]
    move-to one-of ( patches with [ tip = "sosea" and ( count turtles-here ) < 1 ] )
  ]

  adauga-avioane 1 false false
  
  ;; creeaza trenurile:
  ; trenul 1:
  let start-x ([pxcor] of min-one-of sina-1 [pxcor] ) ; pozitie start X
  let start-y ([pycor] of min-one-of sina-1 [pycor] ) ; pozitie start Y
  set start-x ( start-x + floor ( v-trenuri * dim-trenuri ) )
  create-trenuri 8 [
    set tren-id 1
    set heading 90
    set viteza ( v-trenuri )
    move-to patch start-x ( start-y )
    set start-x ( start-x + dim-trenuri )
  ]
  set tren-1 ( trenuri with [ tren-id = 1 ] )
  ; trenul 2:
  set start-x ([pxcor] of max-one-of sina-2 [pxcor] ) ; pozitie start X
  set start-y ([pycor] of max-one-of sina-2 [pycor] ) ; pozitie start Y
  set start-x ( start-x - floor ( v-trenuri * dim-trenuri ) )
  create-trenuri 8 [
    set tren-id 2
    set heading 90
    set viteza ( - v-trenuri )
    move-to patch start-x ( start-y )
    set start-x ( start-x - dim-trenuri )
  ]
  set tren-2 ( trenuri with [ tren-id = 2 ] )
  ; trenul 3:
  set start-x ([pxcor] of max-one-of sina-3 [pxcor] ) ; pozitie start X
  set start-y ([pycor] of max-one-of sina-3 [pycor] ) ; pozitie start Y
  set start-y ( start-y - floor ( v-trenuri * dim-trenuri ) )
  create-trenuri 6 [
    set tren-id 3
    set heading 180
    set viteza ( v-trenuri )
    move-to patch start-x ( start-y )
    set start-y ( start-y - dim-trenuri )
  ]
  set tren-3 ( trenuri with [ tren-id = 3 ] )
  ; trenul 4:
  set start-x ([pxcor] of min-one-of sina-4 [pxcor] ) ; pozitie start X
  set start-y ([pycor] of min-one-of sina-4 [pycor] ) ; pozitie start Y
  set start-y ( start-y + floor ( v-trenuri * dim-trenuri ) )
  create-trenuri 6 [
    set tren-id 4
    set heading 180
    set viteza ( - v-trenuri )
    move-to patch start-x ( start-y )
    set start-y ( start-y + dim-trenuri )
  ]
  set tren-4 ( trenuri with [ tren-id = 4 ] )
  ;; seteaza locomitvele si trenurile
  ask trenuri [ 
    set locomotiva false 
    set shape "vagon"
    set categorie "feroviar"
    set color 95
    set size dim-trenuri
    set timp-stationare timp-stationare-trenuri
  ]
  ;; trenurile mai mari se incarca mai greu => 
  ask trenuri with [ tren-id = 1 or tren-id = 2 ] [ set timp-stationare ( timp-stationare + 1 ) ]
  ask tren-1 with [ xcor = max [xcor] of tren-1 or xcor = min [xcor] of tren-1 ] [ set locomotiva true ]
  ask tren-2 with [ xcor = max [xcor] of tren-2 or xcor = min [xcor] of tren-2 ] [ set locomotiva true ]
  ask tren-3 with [ ycor = max [ycor] of tren-3 or ycor = min [ycor] of tren-3 ] [ set locomotiva true ]
  ask tren-4 with [ ycor = max [ycor] of tren-4 or ycor = min [ycor] of tren-4 ] [ set locomotiva true ]
  ask trenuri with [ locomotiva = true ]
  [
    set shape "locomotiva"
    set color 137
  ]
  ; orientare
  orienteaza-agenti-spawn ; rezolva toate directiile posibile
end 

to adauga-avioane [ nr ater prabu ] ; pot fi false false
  create-avioane nr [ ; numariplanes
    set viteza v-avioane ;; viteza ini tiala acum este nula
    set acceleratie a-avioane
    set distanta d-avioane
    set distanta-franare df-avioane
    set virare vir-avioane
    set categorie cat-avioane
    ;set size one-of n-values 4 [ ( 0.15 * ( ? + 6 )) * dim-avioane ]
    set size dim-avioane
    set shape "airplane"
    set color white
    set hidden? true
    set heading -90
    ;setxy random-xcor random-ycor
    ; move-to one-of ( patches with [ ( count turtles-here ) < 1 and tip != "interfata" ] ) ; avioanele apar doar in zona activa a lumii
    move-to pozitie-spawn-avioane
    ;speciale
    set altitudine ( floor size * 1000 )
    set aterizeaza ater
    set prabuseste prabu
    set tinta nobody
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;orienteaza agenti spawn;;

to orienteaza-agenti-spawn
  orienteaza-agenti-pietoni-spawn
  orienteaza-agenti-rutieri-spawn
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;orienteaza pietoni spawn;;

to orienteaza-agenti-pietoni-spawn
  ask turtles with [ categorie = "pietoni" ]
  [
    set color red
    let curent ( tip )
    let directie ( one-of neighbors4 with [ tip = curent ] )
    face directie
    set color black
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;orienteaza rutieri spawn;;

to orienteaza-agenti-rutieri-spawn
  ;ask one-of turtles [ setxy -22 -47 ] ;test and debug
  ask turtles with [ categorie = "rutier" ] [
    set color red ; neprelucrat
    let bun ( tip ) ; agent pe sosea, trotuar, iarba, etc ?
    
    let t1 ( [tip] of patch-at-heading-and-distance ( 0 ) ( benzi ) ) 
    let t2 ( [tip] of patch-at-heading-and-distance ( 0 ) ( benzi * 2 ) ) 
    let t3 ( [tip] of patch-at-heading-and-distance (   90 ) ( benzi ) ) 
    let t4 ( [tip] of patch-at-heading-and-distance (  -90 ) ( benzi ) ) 
    
    ifelse ( t1 = t2 and t2 = t3 and t3 = t4 and t4 = bun )
    [
      ;suntem in intersectie: => ne uitam la diagonale
      set t1 ( [tip] of patch-at-heading-and-distance (  -45 ) ( benzi ) ) 
      set t2 ( [tip] of patch-at-heading-and-distance (   45 ) ( benzi ) ) 
      set t3 ( [tip] of patch-at-heading-and-distance ( -135 ) ( benzi ) ) 
      set t4 ( [tip] of patch-at-heading-and-distance (  135 ) ( benzi ) )
      if ( t1 != bun )
      [
        set heading (  -90 )
        set color green
      ]
      if ( t2 != bun )
      [
        set heading (    0 )
        set color green
      ]
      if ( t3 != bun )
      [
        set heading (  180 )
        set color green
      ]
      if ( t4 != bun )
      [
        set heading (   90 )
        set color green
      ]
    ]
    [
      ; cazurile generale:
      if ( t1 = bun and t2 = bun ) ; drum vertical bun
      [
        ; sosea verticala
        if ( t4 = bun )
        [
          set heading (    0 )
          set color green
        ]
        if ( t3 = bun ) 
        [
          set heading (  180 )
          set color green
        ]
        if ( [tip] of ( patch-ahead 1 ) != tip ) ; rezolva coltul din stanga-jos
        [
          set heading (   90 )
        ]
      ]
      if ( t1 != bun and t2 != bun ) ;colt, trebuie sa virez la dreapta
      [
        ifelse ( t4 = bun ) ; orice colt mai putin stanga sus
        [
          set heading (  -90 )
          set color green
        ]
        [
          set heading (  180 )
          set color green
        ]
      ]
      if ( t1 = bun and t2 != bun ) ;va trebui sa viram la stanga ori la dreapta
      [
        if ( t3 != bun or t3 != t4 ) ; curba exterioara,inca nu am ajuns la curba
        [
          set heading 0
          set color green
        ]
        if ( t3 = t4 and t4 = bun ) ; putem fi in drum orizontal, ori curba interioara si orientati invers ori intersectie si trebuie sa facem dreapta
        [
          set t1 ( [tip] of patch-at-heading-and-distance (  -45 ) ( benzi ) ) 
          set t2 ( [tip] of patch-at-heading-and-distance (  -90 ) ( benzi ) ) 
          set t3 ( [tip] of patch-at-heading-and-distance (  135 ) ( benzi ) )
          ; t1, t2, t3 = tipul drumului de sub agent
          ifelse ( t1 != bun and t2 = t3 and t3 = bun ) ; interior intersectie
          [
            set heading (  180 )
            set color green
          ]
          [
            ;intersectie si facem dreapta sau drum orizontal si mergem spre dreapta
            set heading (  90 )
            set color green
          ]
        ]
      ]
    ]
  ]
end 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;orienteaza agenti;;

to orienteaza-agenti
  ; rezolva toate directiile rezultate
  ask turtles with [ categorie = "pietoni" ]
  [
    if ( [ tip ] of ( patch-ahead viteza ) != tip )
    [
      set heading ( heading + ( one-of [ 90 180 270 ] ) )
    ]
  ]
  
  ask turtles with [categorie = "rutier" and ales-viraj < 1 ]
  [
    let curent ( tip )
    ifelse ( [tip] of patch-ahead 1 != curent or ( ( safe = true ) and ([safe] of patch-ahead 1 != safe) ) ) ; nu vreau sa ies de pe un drum safe pe unul nesafe!
    [
      ; virez fortat stanga
      set heading ( heading - 90 )
      set ales-viraj 1
    ]
    [
      ; debugging pentru ambuteliaje frontale: daca cel din fata are heading = heading actual -180, fac stanga
      let orientare ( heading )
      let masina-din-fata one-of ( ( turtles-on patch-ahead 1 ) with [ ( categorie = "rutier" ) and ( heading != orientare  ) and ( ales-viraj < 1 ) ] )
      if ( masina-din-fata != nobody )
      [
        ask masina-din-fata
        [
          let turn one-of [ 90 -90 ]
          set heading ( heading + turn )
          set ales-viraj 1
        ]
      ]
        
      let t1 patch-at-heading-and-distance ( heading ) ( benzi * 2 )        ; 2 mai sus
      let t2 patch-at-heading-and-distance ( heading - 60 ) ( benzi * 2 )   ; 1 mai sus si 2 la stanga
      let t3 patch-at-heading-and-distance ( heading + 90 ) ( benzi )       ; 1 la dreapta
      
      ; verific drumurile posibile
      if ( [tip] of t1 != curent ) [ set t1 false ]
      if ( [tip] of t2 != curent ) [ set t2 false ]
      if ( [tip] of t3 != curent ) [ set t3 false ]
      
      ; verific drumurile safe 
      ifelse ( is-patch? t1 and ([safe] of t1 = true ) or ( is-patch? t2 and [safe] of t2 = true ) or ( is-patch? t3 and [safe] of t3 = true ) )
      [
        ; cel putin 1 drum este safe. Drumurile safe sunt true, cele nesafe sunt false
        ifelse ( is-patch? t1 and [safe] of t1 = true )
        [
          set t1 true
        ]
        [
          set t1 false
        ]
        ifelse ( is-patch? t2 and [safe] of t2 = true )
        [
          set t2 true
        ]
        [
          set t2 false
        ]
        ifelse ( is-patch? t3 and [safe] of t3 = true )
        [
          set t3 true
        ]
        [
          set t3 false
        ]
      ]
      [
        ; nici un drum dintre cele 3 nu este safe. Setez directia posibila dupa prioriatea: inainte-dreapta-stanga ; stanga oricum se face pentru evitari
        if ( is-patch? t1 )
        [
          set t1 true
          set t2 false
          set t3 false
        ]
        if ( is-patch? t3 )
        [
          set t1 false
          set t3 true
          ifelse ( is-patch? t2 ) [ set t2 true ]
                                  [ set t2 false ]
        ]
        if ( is-patch? t2 )
        [
          set t1 false
          ifelse ( is-patch? t3 ) [ set t3 true ]
                                  [ set t3 false ]
          set t2 true
        ]
      ]
      
      ifelse ( t1 = true and t2 = true and t3 = true )
      [
        ; toate cele 3 cazuri sunt posibile
        let intentie-viraj random 100
        ifelse ( intentie-viraj <= 33 )
        [
          ;merg inainte
          orienteaza-pentru-inainte
        ]
        [
          ifelse ( intentie-viraj <= 66 )
          [
            ; stanga
            orienteaza-pentru-stanga
          ]
          [
            ; dreapta
            orienteaza-pentru-dreapta
          ]
        ]
      ]
      [
        ; doar 2 din 3 sunt posibile
        ifelse ( t1 = true and t2 = true and t3 = false )
        [
          let intentie-viraj random 100
          ifelse ( intentie-viraj <= 50 )
          [
            orienteaza-pentru-stanga
          ]
          [
            orienteaza-pentru-inainte
          ]
        ]
        [
          ifelse ( t1 = false and t2 = true and t3 = true )
          [
            let intentie-viraj random 100
            ifelse ( intentie-viraj <= 50 )
            [
              ;orienteaza-pentru-stanga
              set virez-stanga ( benzi - 1 )
              set ales-viraj 3
            ]
            [
              orienteaza-pentru-dreapta
            ]
          ]
          [
            ifelse ( t1 = true and t2 = false and t3 = true )
            [
              let  intentie-viraj random 100
              ifelse ( intentie-viraj <= 50 )
              [
                orienteaza-pentru-inainte
              ]
              [
                orienteaza-pentru-dreapta
              ]
            ]
            [
              ;doar un caz posibil
              ifelse ( t2 = true )
              [
                orienteaza-pentru-stanga
              ]
              [
                if ( t3 = true )
                [
                  orienteaza-pentru-dreapta
                ]
              ]
            ]
          ]
        ]
      ]
    ]
  ]
  
  ;; pentru optimizare, trenurile au orientarea setata in miscare!
  ;; cod in misca-tren 
  
  
  ask avioane
  [
    ifelse ( prabuseste = false )
    [ ; ATERIZARE: 
      let da 1.5 ; multiplicator distanta aterizare
      ifelse ( tinta = nobody )
      [
        let teren-aterizare ( patches in-cone ( 44 * da ) 0 with [ tip = "pista" ] )
        if ( count teren-aterizare > 0 )
        [
          set tinta min-one-of teren-aterizare [ distance myself ]
          ifelse ( ( [pcolor] of ( one-of ( patches with [ tip = "interfata" and id-cladire = ( [id] of one-of aeroport ) and stare = "operating" ] ) ) ) != red )
          [
            set aterizeaza true
          ]
          [
            set aterizeaza false
          ]
        ]
      ]
      [
        ifelse ( aterizeaza = false )
        [
          set color pink
        ]
        [
          let pana-aterizez distance tinta
          ifelse ( altitudine <= 0 )
          [
            die
          ]
          [
            ; daca a inceput cutremurul, vrem sa ne ridicam iar la 1200m 
            ifelse ( ( [pcolor] of ( one-of ( patches with [ tip = "interfata" and id-cladire = ( [id] of one-of aeroport ) and stare = "operating" ] ) ) ) != red )
            [
              set size ( size - ( 0.2 * ( 1 / da ) ) )
              set altitudine floor ( altitudine - ( 300 * ( 1 / da ) ) )
              set viteza ( viteza  - ( 2 / ( da * 100 ) ) )
              if ( altitudine < 0 ) [ set altitudine 0 ]
            ]
            [
              if ( color != pink ) [ set color pink ]
              ; ne intereseaza dim!
              if ( altitudine < dim-avioane * 1000 ) [ set altitudine floor ( altitudine + ( 300 * ( 1 / da ) ) ) ]
              if ( altitudine > dim-avioane * 1000 ) [ set altitudine ( floor size * 1000 ) ]
              if ( viteza < v-avioane ) [ set viteza ( viteza  + ( 2 / ( da * 100 ) ) ) ]
              if ( viteza > v-avioane ) [ set viteza v-avioane ]
              if ( size < dim-avioane ) [ set size ( size + ( 0.2 * ( 1 / da ) ) ) ]
              if ( size > dim-avioane ) 
              [ 
                set size dim-avioane
                set altitudine ( dim-avioane * 1000 )
                set tinta nobody
              ]
            ]  
          ]
        ]
      ]
    ]
    [
      ; PRABUSIRE!
      set heading ( heading - 2 )
      set size ( size - 0.1 )
      set altitudine ( altitudine - 150 )
      if ( size < 6.5 ) [ set altitudine 0 ]
      if ( altitudine <= 0 )
      [ 
        let victime one-of ( patches with [ id >= 0 and ( tip != "interfata" and tip != "lac" and tip != "iarba" )] ) in-radius 2
        
        ;; caut cladirea sau soseaua cea mai apropiata ( in radius de 2 )
        ifelse ( any? patches with [ tip = "gara" or tip = "cladire" or tip = "aeroport" or tip = "centrala-nucleara" or tip = "hidrocentrala" or tip = "spital" ] in-radius 10 )
        [
          set victime min-one-of ( patches with [ tip = "gara" or tip = "cladire" or tip = "aeroport" or tip = "centrala-nucleara" or tip = "hidrocentrala" or tip = "spital" ] in-radius 10 ) [ distance myself ]
          ;print (word "distanta este " distance victime " si tipul este " [tip] of victime )          
          ;; avem o cladire sau structura :
          let id-victime [id] of victime
          seteaza-perimetru-cladire id-victime ( [tip] of one-of item id-victime cladiri )
          let senzor-incendiu ( senzori with [ eveniment-urmarit = "fire" and cladire-id = id-victime ] )
          if ( count senzor-incendiu > 0 )
          [
            ask senzor-incendiu [ set intensitate prag ] ; activez senzorul de incendiu
          ]
          ;wait 0.3
          actualizeaza-monitorizarea
        ]
        [
          ;; verificam soseaua
          set victime min-one-of ( patches with [ tip = "sosea" ] in-radius 10 ) [ distance myself ]
          if ( victime != nobody )
          [
            ask victime
            [
              ask patches in-radius 5 with [ tip = "sosea" ]
              [
                set safe false
                set pcolor red
              ]
            ]
          ]
        ]
        ask copaci in-radius 4 [ die ]
        die
      ]
    ]
  ]
  
  if ( count avioane < 1 ) [ adauga-avioane 1 false false ] ; adauga un nou avion pe ruta 
end 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cazuri orientare agenti;;
; cazuri de orientare

to orienteaza-pentru-inainte
  set ales-viraj ( benzi * 2 + 1 )
end 

to orienteaza-pentru-stanga
  set virez-stanga ( benzi * 2 + 1 )
  set ales-viraj ( benzi * 2 + 2 )
end 

to orienteaza-pentru-dreapta
  set heading ( heading + 90 )
  set ales-viraj ( benzi + 1 )
end 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;miscare agenti;;

to misca-agenti 
  ask turtles with [ categorie = "rutier" ]
  [
    if (ales-viraj > 0 )
    [
      set ( ales-viraj ) ( ales-viraj - 1)
      if ( virez-stanga > 0 )
      [
        if ( virez-stanga = ( benzi * 2 - 1 ) )
        [
          set heading ( heading - 90 )
        ]
        set virez-stanga ( virez-stanga - 1 )
      ]
    ]
    if ( [tip] of patch-ahead 1 = tip and count turtles-on patch-ahead 1 < 1 )
    [
      
      if ( ( [safe] of patch-ahead 1 = true ) or ( [safe] of patch-ahead 1 = safe ) )
      [
        forward viteza
      ]
    ]
  ]
  ask oameni 
  [
    if ( [tip] of patch-ahead viteza = tip and [safe] of patch-ahead viteza = true )
    [
      forward viteza
    ]
  ]
  
  ; trenurile au o alta abordare: orientarea e inclusa in miscare si se face miscarea pentru fiecare tren in parte
  misca-tren tren-1
  misca-tren tren-2
  misca-tren tren-3
  misca-tren tren-4
  
  ask avioane
  [
    forward viteza
    ifelse (([tip] of patch-at-heading-and-distance ( heading  ) 2  = "interfata") and ([tip] of patch-at-heading-and-distance ( heading - 180 ) 2 = "interfata"))
    [
      hide-turtle
      if ( color = pink ) 
      [ 
        die
      ]
    ]
    [
      show-turtle
    ]
  ]
end 

to misca-tren [ tren-x ]
  ask one-of tren-x with [ locomotiva = true ]
  [
    ifelse ( ( all? ( tren-x with [ locomotiva = true ] ) [ [tip] of patch-ahead ( viteza * size ) = "sina" ] )  )
    [
      if ( timer-running > ( timp-ajuns-gara + timp-stationare ) )
      [
        ask tren-x [ forward viteza ]
      ]
    ]
    [
      ask tren-x
      [
        set timp-ajuns-gara timer-running
        set viteza ( - viteza )
      ]
    ]
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CREAREA LUMII
;; Generarea spatiului modelat ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;setup HARTA;;

to setup-harta
  ;; relief intai:
  ask patches 
  [ 
    set pcolor 65
    set nivel 0
    set tip "iarba"
    set id -1
    set id-cladire -1
  ]
  ; lac acumulare
  let t1 -106
  let t2 32
  let lim-t1 ( 16 + t1 )
  ask patches with [ pxcor < t1 and abs ( pycor - t2 ) < 2 ]
  [
    set pcolor 87
    set tip "apa"
  ]
  while [ t1 <= lim-t1 ]
  [
    ask patch t1 t2
    [
      ask patches in-radius 10
      [
        set pcolor 87
        set tip "lac"
        set id 1
      ]
    ]
    set t1 ( t1 + 1 )
  ]
  ; lac varsare
  set t1 -38
  set t2 0
  set lim-t1 ( 16 + t1 )
  while [ t1 <= lim-t1 ]
  [
    ask patch t1 t2
    [
      ask patches in-radius 10
      [
        set pcolor 87
        set tip "lac"
        set id 2
      ]
    ]
    set t1 ( t1 + 1 )
  ]

  ;; interfata
  ask patches with [ pycor <= limita-jos or pxcor >= limita-dreapta ]
  [
    set pcolor white
    set nivel 0
    set tip "interfata"
    set id -2
  ]
  ;; pista aeroport
  set pista-aeroport patches with [((pycor >= 52 and pycor <= 60 ))and (pxcor >= -126 and pxcor <= -104)]
  ask pista-aeroport
  [
    set pcolor white
    set nivel 0
    set tip "iluminare-pista"
  ]
  ask pista-aeroport with [ pxcor <= -112 ]
  [
    set tip "pista"
  ]
  ;; gari si sine de tren
  ask patches with [(pycor >= 58) and (pxcor >= 50 and pxcor < limita-dreapta - 2)]
  [
    set pcolor 36
    set nivel 0
    set tip "gara"
    set id 1
  ]
  ask patches with [(pycor >= 44) and (pxcor >= 66 and pxcor < limita-dreapta - 2)]
  [
    set pcolor 36
    set nivel 0
    set tip "gara"
    set id 1
  ]
  set sina-1 patches with [(( pycor = 66 ) and (( pxcor >= -124 ) and ( pxcor <= limita-dreapta - 8 )))]
  ask sina-1
  [
    set pcolor 33
    set nivel 0
    set tip "sina"
    set id 1
  ]
  set sina-2 patches with [(( pycor = 64 ) and (( pxcor >= -124 ) and ( pxcor <= limita-dreapta - 8 )))]
  ask sina-2
  [
    set pcolor 33
    set nivel 0
    set tip "sina"
    set id 2
  ]
  ; aeroport
  set aeroport patches with [(pycor >= 50 and pxcor <= -100) and tip = "iarba"]
  ask aeroport
  [
    set pcolor 85
    set nivel 0
    set tip "aeroport"
    set id 0
  ]
  set sina-3 patches with [(( pxcor = 73) and (( pycor <= 60 ) and ( pycor >= limita-jos + 18 )))]
  ask sina-3
  [
    set pcolor 33
    set nivel 0
    set tip "sina"
    set id 3
  ]
  set sina-4 patches with [(( pxcor = 75 ) and (( pycor <= 60 ) and ( pycor >= limita-jos + 18 )))]
  ask sina-4
  [
    set pcolor 33
    set nivel 0
    set tip "sina"
    set id 4
  ]
  set sine-tren patches with [ tip = "sina" ]
  set gara-periferie patches with [ tip = "gara" ] ; doar gara asta s-a construit pana acum
  set gara-oras patches with [(pycor <= 4 and pycor > limita-jos + 14) and (pxcor >= 66 and pxcor < limita-dreapta - 2) and tip != "sina"]
  ask gara-oras 
  [
    set pcolor 36
    set nivel 0
    set tip "gara"
    set id 2
  ]
  set cladiri lput aeroport cladiri
  set cladiri lput gara-periferie cladiri
  set cladiri lput gara-oras cladiri
  ;; cartiere ( clustere de cladiri inconjurate de sosele de dimensiune data - 2 - si trotuare de latime 1 )
  let start-x 62  ;; Nota: Se precizeaza coltul din dreapta-sus al primei cladiri!
  let start-y 21  ;;       Prima cladire este tot in coltul din dreapta-sus!
  let size-x 7
  let size-y 4
  let latime-drum 2 ; cate benzi are drumul?
  let last-id 3 ; de la cat incep alocarea de id-uri => 0 = aeroport, 1 si 2 = gari, deci de la 3 incep cladirile
  ;set last-id construieste-cartier start-x start-y size-x size-y 6 4 latime-drum 1 id-cladiri ; apel cu parametrii
  set last-id construieste-cartier "cladire" start-x start-y size-x size-y 6 4 latime-drum 1 last-id
  set start-x 72
  set start-y -19
  set size-x 8
  set size-y 1
  set last-id construieste-cartier "cladire" start-x start-y size-x size-y 6 4 latime-drum 1 ( last-id + 1 )
  ;; 3 case langa gara ca sa fie incercuita
  set start-x 68
  set start-y 21
  set size-x 1
  set size-y 3
  set last-id construieste-cartier "cladire" start-x start-y size-x size-y 2 4 latime-drum 1 ( last-id + 1 )
  ;; centrala nucleara
  set start-x -104  ;; Nota: Se precizeaza coltul din dreapta-sus al primei cladiri!
  set start-y -5  ;;       Prima cladire este tot in coltul din dreapta-sus!
  set size-x 1
  set size-y 1
  set last-id construieste-cartier "centrala-nucleara" start-x start-y size-x size-y 20 4 latime-drum 1 ( last-id + 1 );
  ;print (word "Centrala are id-ul " last-id )
  set centrala-nucleara patches with [ tip = "centrala-nucleara" and id = last-id ]
  ;; spitalul
  let id-spital random ( length cladiri - 4 - 3 ) ; sad cladirile critice si cladirile mici ( vilele )
  set id-spital ( id-spital + 3 ) ; se sar primele cladiri
  set spital patches with [ tip = "cladire" and id = id-spital  ]
  ask spital [ set tip "spital" ]
  ;; barajul
  ask patches with [ ( pxcor >= -81 and pxcor <= -80 ) and ( pycor >= 26 and pycor <= 38 ) ]
  [
    set tip "baraj"
    set id length cladiri
    set pcolor ( gray + 3 )
    set safe false
  ]
  set baraj patches with [ tip = "baraj" ]
  set cladiri lput baraj cladiri
  ;; rauri de legatura intre lacuri si care ies din model
  set t1 -35
  set t2 32
  set lim-t1 ( -79 )
  ask patches with [ ( pxcor >= lim-t1 and pxcor <= t1 ) and abs ( pycor - t2 ) < 2 ]
  [
    set pcolor 87
    set tip "apa"
  ]
  set t1 -36
  set t2 11
  let lim-t2 ( 30 )
  ask patches with [ ( abs ( pxcor - t1 ) < 2 ) and ( pycor >= t2 and pycor <= lim-t2 ) ]
  [
    set pcolor 87
    set tip "apa"
  ]
  ; iesirea din lacul 2
  set t1 -20
  set t2 -10
  set lim-t1 ( 16 + t1 )
  ask patches with [ ( abs ( pxcor - t1 ) < 2 ) and ( pycor > limita-jos and pycor <= t2 ) ]
  [
    set pcolor 87
    set tip "apa"
  ]
  ;; hidrocentrala
  ask patches with [ ( pxcor >= -79 and pxcor <= -56 ) and ( pycor >= 20 and pycor <= 36 ) and tip != "apa" ]
  [
    set tip "hidrocentrala"
    set id length cladiri
    set pcolor ( 115 )
  ]
  ask patch -57 26 [ set plabel "Hydro-electric Plant" set plabel-color white ]
  set hidrocentrala patches with [ tip = "hidrocentrala" ]
  set cladiri lput hidrocentrala cladiri
  ;; drumuri de legatura
  construieste-drum "strada" -7 -16 -100 -16 2 ; caz x1 y1 x2 y2 latime
  construieste-drum "strada" 65 25 65 57 2
  construieste-drum "strada" 63 57 -99 57 2
  construieste-drum "strada" -98 55 -98 48 2
  construieste-drum "strada" -100 49 -120 49 2
  construieste-drum "strada" -119 47 -119 -1 2
  ; drumuri legatura cu hidrocentrala
  construieste-drum "strada" -50 19 -50 -16 2
  construieste-drum "strada" -119 19 -52 19 2
  
  ;; denumiri
  ask patch -110 62 [ set plabel "Airport" set plabel-color 9.9 ]
  ask patch 70 60 [ set plabel "Railroad Station" ]
  ask patch 72 -2 [ set plabel "City" ]
  ask patch 72 -5 [ set plabel "Train" ]
  ask patch 72 -8 [ set plabel "Station" ]
  ask patch -107 -14 [ set plabel "Nuclear Plant" set plabel-color 9.9 ] ; 9.9 = white
  ask spital [ set pcolor yellow ]
  ;; desenarea dungilor perpediculare pentru spital
  let spital-x-cord ( mean ( [pxcor] of spital ) )
  let spital-y-cord ( mean ( [pycor] of spital ) )
  ifelse ( floor spital-x-cord = spital-x-cord )
  [
    ask spital with [ pxcor = spital-x-cord ]
    [
      set pcolor red
    ]
  ]
  [
    ask spital with [ ( pxcor = floor spital-x-cord ) or ( pxcor = ( floor spital-x-cord ) + 1 ) ]
    [
      set pcolor red
    ]
  ]
  ifelse ( floor spital-y-cord = spital-y-cord )
  [
    ask spital with [ pycor = spital-y-cord ]
    [
      set pcolor red
    ]
  ]
  [
    ask spital with [ ( pycor = floor spital-y-cord ) or ( pycor = ( floor spital-y-cord ) + 1 ) ]
    [
      set pcolor red
    ]
  ]
  
  ;; copaci
  let nr-copaci ( floor ( ( count patches with [ tip = "iarba" and ( any? neighbors with [ tip = "sosea" ] ) and pycor <= 50 ] ) / 4 ) )
  create-copaci nr-copaci
  [
    move-to one-of ( patches with [ tip = "iarba" and ( any? neighbors with [ tip = "sosea" ] and pycor <= 50 ) and ( count copaci in-radius 2 < 1 ) ] )
    set color one-of [ 54 64 66 67 ]
  ]
  
  let padure ( patches with [ tip = "iarba" and ( count turtles-here < 1 ) and ( ( pxcor >= -119 and pxcor <= -54  ) and ( pycor >= -16 and pycor <= 19 ) ) ] )
  set nr-copaci ( floor ( ( count padure ) / 2 ) )
  create-copaci nr-copaci 
  [
    move-to one-of ( padure )
    set color one-of [ 54 64 66 67 ]
  ]
  
  ; zona epicentru
  set t1 -16
  set t2  36
  let latime 14
  ask patch t1 t2
  [
    set tip "zona-epicentru"
    ask patches in-radius latime
    [
      if ( random 6 < 1 ) ;and ( one-of neighbors with [ tip = "zona-epicentru" ] ) != nobody )
      [
        set tip "zona-epicentru"
      ]
    ]
  ]
  
  set zona-epicentru ( patches with [ tip = "zona-epicentru" ] )
end 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;construieste cartier;;

to-report construieste-cartier [ tip-cladiri start-x start-y size-x size-y marime-cladiri spatiu-cladiri latime-drum marime-trotuar id-cladiri]
  let last-id construieste-cladiri tip-cladiri start-x start-y size-x size-y marime-cladiri spatiu-cladiri id-cladiri
  ;; drumuri
  let x1-drum ( start-x + ( latime-drum + latime-trotuar )) 
  let y1-drum ( start-y + ( latime-drum + latime-trotuar ))
  let x2-drum ( x1-drum - (( size-x * marime-cladiri ) + (( size-x - 1 ) * spatiu-cladiri ) + ( 2 * ( latime-drum + latime-trotuar )) - 1 ))
  let y2-drum y1-drum
  ; construieste drumurile orizontale
  repeat ( size-y + 1 )
  [
    construieste-drum "strada" x1-drum y1-drum x2-drum y2-drum latime-drum
    set y1-drum ( y1-drum - ( marime-cladiri + spatiu-cladiri ))
    set y2-drum ( y2-drum - ( marime-cladiri + spatiu-cladiri ))
  ] 
  
  set x1-drum ( start-x + ( latime-drum + latime-trotuar ))
  
  set y1-drum ( start-y + ( latime-drum + latime-trotuar ))
  
  set x2-drum x1-drum
  
  set y2-drum ( y1-drum - (( size-y * marime-cladiri ) + (( size-y - 1) * spatiu-cladiri) + ( 2 * ( latime-drum + latime-trotuar )) - 1 ))
  ; construieste drumurile verticale
  repeat ( size-x + 1 )
  [
    construieste-drum "strada" x1-drum y1-drum x2-drum y2-drum latime-drum
    set x1-drum ( x1-drum - ( marime-cladiri + spatiu-cladiri ))
    set x2-drum ( x2-drum - ( marime-cladiri + spatiu-cladiri ))
  ]
  
  ;; trotuar
  ask patches [ if (( any? neighbors with [ tip = "sosea" ] ) and ( any? neighbors with [ tip = tip-cladiri ] )) [
      set pcolor ( culoare-trotuar )
      set tip "trotuar"
      set nivel 0
      set benzi 1
      set safe true
  ]]  
  
  report last-id ; returneaza ultimul id generat.
end 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;construieste cladiri;;

to-report construieste-cladiri [ tip-cladiri start-x-cladiri start-y-cladiri X-cladiri Y-cladiri marime-cladiri spatiu-cladiri id-start]
  let id-c id-start
  let i 0
  let dim marime-cladiri - 1     ; corectie !
  let spatiu spatiu-cladiri + 1  ; corectie !
  while [ i < Y-cladiri ]
  [
    ; fiecare rand in parte
   let j 0
   while [ j < X-cladiri ]
   [
     let t1 0
     let t2 0
     ; fiecare cladire in parte
     let cladire ( patches with [ (pxcor <= ( start-x-cladiri - ( j * dim )) and pxcor >= ( start-x-cladiri - ( ( j + 1 ) * dim )))
                  and   (pycor <= ( start-y-cladiri - ( i * dim )) and pycor >= ( start-y-cladiri - ( ( i + 1 ) * dim ))) ] )
     ask cladire
     [
       set pcolor blue
       set nivel 1
       set tip tip-cladiri
       set id id-c
     ]
     set cladiri lput cladire cladiri
     set id-c ( id-c + 1 )
     set j ( j + 1 )
     set start-x-cladiri ( start-x-cladiri - spatiu )
   ]
   set i ( i + 1 )
   set start-y-cladiri ( start-y-cladiri - spatiu)
   set start-x-cladiri ( start-x-cladiri + ( X-cladiri * spatiu ))
  ]
  report ( id-c - 1 ) ; returneaza ultimul id adaugat!
end 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;construieste drum;;

to construieste-drum [ caz x1 y1 x2 y2 latime]
  ;; DRUMUL construit contine extremitatile!
  ifelse (( x1 = x2 ) or ( y1 = y2 ))
  [
    let cale no-patches
    set latime ( latime - 1 ) ; trebuie modificat si corectat in calcule! :=> set latime ( latime / 2 )
    ifelse x1 = x2
    [
      ; luam patch-urile intre y1 si y2
      if y1 > y2 
      [
        let temp y1
        set y1 y2
        set y2 temp
      ]
      set cale ( patches with [( pxcor >= x1 - 1 ) and ( pxcor <= x1 + latime - 1 ) and ( pycor >= y1 ) and ( pycor <= y2 )])
      
    ]
    [
      ; luam patch-urile intre x1 si x2
      if x1 > x2 
      [
        let temp x1
        set x1 x2
        set x2 temp
      ]
      set cale ( patches with [( pycor >= y1 - latime ) and ( pycor <= y1 ) and ( pxcor >= x1 ) and ( pxcor <= x2 )])
    ]
    let construit 0
    if caz = "strada"
    [
      ask cale
      [
        set pcolor ( culoare-sosea )
        set nivel 0
        set tip "sosea"
        set benzi ( ( latime + 1 ) / 2 )
        set safe true
      ]
      set construit 1
    ]
    if caz = "trotuar"
    [
      ask cale [
        set pcolor ( culoare-trotuar )
        set nivel 0
        set tip "trotuar"
        set benzi ( ( latime + 1 ) / 2 )
        set safe true
      ]
      set construit 1
    ]
    if construit = 0
    [
      show "!Primul parametru trebuie sa fie ori <> ori <>!"
    ]
  ]
  [
    show "!Un drum poate fi construit doar pe o abscisa sau ordonata!"
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SITUATII CRITICE
;; Gestiunea situatiilor critice ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;activeaza alarma;;

to activeaza-alarma
  if ( quarantine = "A Random Building" )
  [
    let target-cladire random ( length cladiri - 6 ) ; se scad cele 6 cladiri speciale: aeroportul, gara perif, gara oras, centrala nucleara, barajul si hidrocentrala
    set target-cladire ( target-cladire + 3 ) ; se adauga 3 ca sa se sara aeroportul si garile. Nu se adauga 4 pentru ca ultima e centrala!
    seteaza-perimetru-cladire target-cladire ( one-of [tip] of item target-cladire cladiri )
    show (word floor timer "s: The Building with the id " target-cladire " has been armed!" )
  ]
  if ( quarantine = "The Airport" )
  [
    seteaza-perimetru-cladire ( one-of [id] of aeroport ) ( one-of [tip] of aeroport )
    show (word floor timer "s: The Airport has been armed!" )
  ]
  if ( quarantine = "The Railroad Station" )
  [
    seteaza-perimetru-cladire ( one-of [id] of gara-periferie ) ( one-of [tip] of gara-periferie )
    show (word floor timer "s: The Railroad Station has been armed!" )
  ]
  if ( quarantine = "The city Train Station" )
  [
    seteaza-perimetru-cladire ( one-of [id] of gara-oras ) ( one-of [tip] of gara-oras )
    show (word floor timer "s: The city Train Station has been armed!" )
  ]
  if ( quarantine = "The Nuclear Plant" )
  [
    seteaza-perimetru-cladire ( one-of [id] of centrala-nucleara ) ( one-of [tip] of centrala-nucleara )
    show (word floor timer "s: The Nuclear Plant has been armed!" )
  ]
  if ( quarantine = "The Hydro-electric Plant" )
  [
    seteaza-perimetru-cladire ( one-of [id] of hidrocentrala ) ( one-of [tip] of hidrocentrala )
    show (word floor timer "s: The Hydro-electric Plant has been armed!" )
  ]
  if ( quarantine = "The Hospital" )
  [
    seteaza-perimetru-cladire ( one-of [id] of spital ) ( one-of [tip] of spital )
    show (word floor timer "s: The Hospital has been armed!" )
  ]
  if ( quarantine = "The City" )
  [
    let cladiri-oras ( length cladiri - 3 )
    let cladire-curenta 2
    user-message ( "Quarantining the City should take longer because of the large number of buildings.\nPlease be patient and refraim from issuing any other commands until you receive the confirmation notice!\n\nThe button will remain pressed during the command's execution." )
    ;user-message ( "Armarea orasului va dura datorita numarului mare de cladiri.\nNu alegeti alta comanda pana nu primiti mesajul de confirmare!\n\nButonul va fi apasat cat timp se executa comanda." )
    show (word "Quarantining the City:")
    while [ cladire-curenta < cladiri-oras ]
    [
      seteaza-perimetru-cladire cladire-curenta ( one-of [tip] of item cladire-curenta cladiri )
      set cladire-curenta ( cladire-curenta + 1 )
      show (word floor ( ( cladire-curenta / cladiri-oras ) * 100 ) "% quarantined" )
    ]
    show (word floor timer "s: The City has been completely quarantined!!! Evacuation has starded!")
  ]
  if ( quarantine = "Everything" )
  [
    let cladiri-oras ( length cladiri )
    let cladire-curenta 0
    user-message ( "Quarantining Everything should take longer because of the large number of buildings.\nPlease be patient and refraim from issuing any other commands until you receive the confirmation notice!\n\nThe button will remain pressed during the command's execution." )
    ;user-message ( "Armarea LUMII va dura datorita numarului mare de cladiri.\nNu alegeti alta comanda pana nu primiti mesajul de confirmare!\n\nButonul va fi apasat cat timp se executa comanda." )
    show (word "Quarantining every building present in the World Model:")
    while [ cladire-curenta < cladiri-oras ]
    [
      seteaza-perimetru-cladire cladire-curenta ( one-of [tip] of item cladire-curenta cladiri )
      set cladire-curenta ( cladire-curenta + 1 )
      show (word floor ( ( cladire-curenta / cladiri-oras ) * 100 ) "% quarantined" )
    ]
    show (word floor timer "s: Every building has been quarantined!")
  ]
  ; update pt senzori:
  actualizeaza-monitorizarea
end 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;seteaza perimetru cladire;;

to seteaza-perimetru-cladire [ id-cladire-tinta tip-cladire ]
  ask patches with [ id = id-cladire-tinta and ( tip = tip-cladire ) ]
  [
    ask patches at-points [[ 3 3 ][ -3 -3 ][ 3 -3 ][ -3 3 ]] with [ tip = "sosea" or tip = "trotuar" ] ; colturile
    [
      ifelse ( tip = "sosea" )
      [
        set pcolor red
      ]
      [
        set pcolor pink
      ]
      set safe false
      ask oameni-here [ set color 25 ] ;portocaliu => echipaj interventie!
    ]
    ask patches with [ distance myself < 4 and ( tip = "sosea" or tip = "trotuar" )]
    [
      ifelse ( tip = "sosea" )
      [
        set pcolor red
      ]
      [
        set pcolor pink
      ]
      set safe false
      ask oameni-here [ set color 25 ] ; portocaliu => echipaj interventie!
    ] 
  ]
  ; actualizeaza senzor
  ask senzori with [ eveniment-urmarit = "quarantine" and cladire-id = id-cladire-tinta ]
  [
    set intensitate 1
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;INTERFATA
;; INTERFATA: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;adauga butoane;;

to adauga-butoane [ start-x-butoane start-y-butoane X-butoane Y-butoane dim-butoane spatiu-butoane id-butoane ] 
  let i 0
  let dim dim-butoane - 1     ; corectie !
  let spatiu spatiu-butoane + 1  ; corectie !
  while [ i < X-butoane ]
  [
    ; fiecare rand in parte
   let j 0
   while [ j < Y-butoane ]
   [
     ; fiecare buton in parte
     let buton ( patches with [ (pxcor <= ( start-x-butoane - ( j * dim )) and pxcor >= ( start-x-butoane - ( ( j + 1 ) * dim )))
                  and   (pycor <= ( start-y-butoane - ( i * dim )) and pycor >= ( start-y-butoane - ( ( i + 1 ) * dim ))) ] )
     ask buton
     [
       set pcolor red
       set nivel 1
       set tip "interfata"
       set id id-butoane
     ]
     set butoane lput buton butoane
     set id-butoane ( id-butoane + 1 )
     set j ( j + 1 )
     set start-x-butoane ( start-x-butoane - spatiu )
   ]
   set i ( i + 1 )
   set start-y-butoane ( start-y-butoane - spatiu)
   set start-x-butoane ( start-x-butoane + ( Y-butoane * spatiu ))
  ]
end 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;adauga elemente de monitorizare;;

to adauga-elemente-monitorizare [ start-x-em start-y-em X-em Y-em dim-em spatiu-em cladire-parinte nume-cladire-parinte stari-urmarite ] ; stari-urmarite este o lista cu starile, in ordine
  let i 0
  set dim-em dim-em - 1     ; corectie !
  let spatiu spatiu-em + 1  ; corectie !
  let id-em length elemente-afisare ; actualizare id curent
  ask patch ( start-x-em + 1 ) ( start-y-em + 3 )
  [
    set plabel nume-cladire-parinte
    set plabel-color black
  ]
  while [ i < X-em ]
  [
    ; fiecare rand in parte
   let j 0
   while [ j < Y-em ]
   [
     ; fiecare buton in parte
     let element-monitorizare ( patches with [ (pxcor <= ( start-x-em - ( j * dim-em )) and pxcor >= ( start-x-em - ( ( j + 1 ) * dim-em )))
                  and   (pycor <= ( start-y-em - ( i * dim-em )) and pycor >= ( start-y-em - ( ( i + 1 ) * dim-em ))) ] )
     ask element-monitorizare
     [
       set pcolor green
       set nivel 1
       set tip "interfata"
       set id id-em
       set stare ( item ( i * Y-em + j ) stari-urmarite )
       set id-cladire cladire-parinte
     ]
     set elemente-afisare lput element-monitorizare elemente-afisare
     set id-em ( id-em + 1 )
     set j ( j + 1 )
     set start-x-em ( start-x-em - spatiu )
     ; adaugare label
     ask element-monitorizare with [ ( pycor = (([pycor] of min-one-of element-monitorizare [pycor]) + 1 ) ) and ( pxcor = [pxcor] of min-one-of element-monitorizare [pxcor] ) ]
     [
       let eveniment stare
       ask patch-at-heading-and-distance -90 ( 2 ) 
       [
         set plabel eveniment
         set plabel-color black
       ] 
     ]
   ]
   set i ( i + 1 )
   set start-y-em ( start-y-em - spatiu)
   set start-x-em ( start-x-em + ( Y-em * spatiu ))
  ]
end 

to adauga-senzori-monitorizare [ cladire-parinte stari-urmarite praguri ]
  let id-num length senzori-monitorizare
  let index-prag 0
  foreach stari-urmarite
  [
    let target-building item cladire-parinte cladiri
    create-senzori 1 [
      set hidden? true
      move-to one-of target-building with [ count turtles-here < 1 ]
      set id-senzor id-num
      set ( id-num ) ( id-num + 1 )
      set eveniment-urmarit ( ? )
      set cladire-id ( cladire-parinte )
      set intensitate 0
      set prag item index-prag praguri
      set color ( pcolor + 20 )
      set senzori-monitorizare lput ( self ) senzori-monitorizare
      set index-prag ( index-prag + 1 )
    ]
  ]
  ; adauga id-ul cladirea in lista
  set cladiri-monitorizate lput ( item cladire-parinte cladiri ) cladiri-monitorizate
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;RUNTIME
;; Slowmotion si teste: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;incetineste tickuri;;

to slow-down-time
  wait 0.2
end 

to-report afiseaza-timp-rulare
  ifelse ( ticks > last-tick-running )
  [
    set ( timer-running ) ( timer-running + ( timer - timer-dummy ) )
    set last-tick-running ticks
    set timer-dummy timer
    ;show "ON"
  ]
  [
    set timer-dummy timer
    ;show "OFF"
  ]
  report (word floor ( timer-running / 3600 ) " hours, " floor ( timer-running / 60 ) " minutes and " floor ( timer-running mod 60 ) " seconds ")
  ;report (word floor ( timer / 3600 ) " ore, " floor ( timer / 60 ) " minute si " floor ( timer mod 60 ) " secunde ")
end 

to-report masini-in-oras
  report (word "There are " masini-plotate " vehicles in the City" )
end 

to test-iduri-cladiri
  let maxt length cladiri
  let t 0
  while [ t < maxt ]
  [
    print (word "Building " t ": " mean [id] of item t cladiri )
    set t ( t + 1)
  ]
end 

There is only one version of this model, created over 2 years ago by George-Alexandru Serea.

Attached files

File Type Description Last updated
_globals.nls data initialization file needed for the simulation!!! over 2 years ago, by George-Alexandru Serea Download
CitySCAPE Critical Systems.png preview Preview for 'CitySCAPE Critical Systems' over 2 years ago, by George-Alexandru Serea Download

This model does not have any ancestors.

This model does not have any descendants.