Missile Attack Evacuation

Missile Attack Evacuation preview image

1 collaborator

Default-person Artem Serdyuk (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 7.0.0 • Viewed 314 times • Downloaded 26 times • Run 0 times
Download the 'Missile Attack Evacuation' modelDownload this modelEmbed this model

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


WHAT IS IT?

This model simulates evacuation from two multi-story buildings during a missile attack after an air raid siren. It explores how reaction timing, building configuration, and attack patterns affect casualties. The model tracks three groups: early evacuees (leaving before first impact), late evacuees (leaving after first impact), and building stayers.

HOW IT WORKS

Two buildings with adjustable floors are populated with agents who have individual speeds and reaction probabilities. When the alarm sounds at tick 10, reacting agents evacuate floor-by-floor through exits to reach one of two shelters. Non-reacting agents may begin evacuating after witnessing the first explosion (reaction percentage increases to 80%).

Missiles launch based on strategy (immediate or delayed) and create explosions with radius 6. Damage depends on distance from epicenter and location: shelter (4-5% base damage), building (40%), or open air (80%). Health below 80% shows as yellow/red; 0% is death (black).

HOW TO USE IT

Setup/Go: Initialize and run the simulation.

Sliders: - initial-people (0-1000): Total occupants - reaction-percentage (0-100): Percent reacting to initial alarm - shelter-capacity (0-200): Max per shelter - number-of-floors (1-10): Building height - number-of-exits (1-5): Exits per floor - number-of-missiles (1-20): Total missiles - missile-delay (10-50): Ticks between missiles (delayed strategy only)

Chooser: - missile-strategy: "immediate" (all at once) or "delayed" (staggered)

Monitors: Track dead, injured, locations, and evacuation timing groups.

Plots: Show outcomes (dead/injured/intact percentages) for early evacuees, late evacuees, and stayers.

THINGS TO NOTICE

Watch congestion at exits, especially ground floors where all evacuees converge. Notice the "stairwell cascade" as upper floor residents join lower floor crowds.

Compare outcomes between early and late evacuees—early evacuees typically reach shelter before most strikes. Observe shelter capacity limits forcing people to wait outside (turning blue) or attempt the alternate shelter.

Notice how delayed missile strategy targets yard areas where evacuees are moving, while immediate strategy creates higher initial building casualties.

THINGS TO TRY

Vary reaction-percentage from 50-100% to find the optimal balance between evacuation and shelter overcrowding.

Test shelter-capacity adequacy: set initial-people to 500 and vary capacity from 50-250.

Compare building configurations with same total people: 10 floors/1 exit vs. 5 floors/2 exits vs. 2 floors/5 exits.

Run paired simulations comparing immediate vs. delayed strategies with same missile count.

Set reaction-percentage to 50% and compare final outcomes for stayers vs. evacuees—are there scenarios where staying is safer?

EXTENDING THE MODEL

Add different building protection levels (reinforced vs. standard structures) with varying base damage percentages.

Implement family units that stay together, moving at the slowest member's pace.

Add missile interception rate representing air defense effectiveness.

Create a communication network where information spreads between nearby agents rather than all reacting simultaneously.

Add stamina that depletes during movement, requiring rest periods.

Track casualties by floor level to identify most vulnerable locations.

Implement multiple smaller shelters instead of two large ones to test distributed vs. centralized shelter strategies.

NETLOGO FEATURES

The model uses dynamic color generation with approximate-rgb to create floor gradients based on number-of-floors slider.

The get-downward-exits procedure ensures agents follow realistic stairwell paths by checking exit connectivity between floors.

A pending-explosions list defers explosion creation to observer context, solving agent-creation context issues.

The shelter-at-capacity? reporter uses filtered patch sets with conditional expressions to distinguish top (pycor > 0) and bottom (pycor < 0) shelter zones.

Multiple overlapping boolean states (in-building?, in-shelter?, reacting?, waiting-at-shelter?) allow complex decision trees rather than single-state variables.

RELATED MODELS

NetLogo Models Library: Fire (patch spread), Traffic Basic (congestion), Virus (health states), Paths (pathfinding).

Almeida, J.E., Kokkinogenis, Z., & Rossetti, R.J.F. (2012). "NetLogo Implementation of an Evacuation Scenario." Demonstrates exit capacity constraints and validates NetLogo for evacuation studies.

EXODUS and BuildingEXODUS (University of Greenwich): Professional evacuation simulation tools.

Fire evacuation models with panic behaviors and stampede dynamics.

CREDITS AND REFERENCES

Key References:

Ponziani, F.A., Tinaburri, A., & Ricci, V. (2018). "A Multi Agent Approach to Analyse Shift in People Behaviour Under Critical Conditions." Int. J. of Safety and Security Eng., 8(1), 1-9.

Almeida, J.E., Rossetti, R., & Coelho, A.L. (2010). "Crowd Simulation Modeling Applied to Emergency and Evacuation Simulations using Multi-Agent Systems." LIACC/FEUP.

Almeida, J.E., Kokkinogenis, Z., & Rossetti, R.J.F. (2012). "NetLogo Implementation of an Evacuation Scenario." DOI: 10.48550/arXiv.1303.4695

Helbing, D., Farkas, I., Molnar, P., & Vicsek, T. (2001). "Simulating of Pedestrian Crowds in Normal and Evacuation Situations." In Pedestrian and Evacuation Dynamics, Springer, 21-58.

Santos, G., & Aguirre, B.E. (2004). "A Critical Review of Emergency Evacuation Simulation Models." NIST Workshop.

Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Northwestern University, Evanston, IL.

Copyright © 2025 Artem Serdyuk
a.serdiuk@ukma.edu.ua, artem.serdyuk@gmail.com

Comments and Questions

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

Click to Run Model

;; ========================================
;; EXTENSIONS AND GLOBAL VARIABLES
;; ========================================

extensions [palette]

globals [
  ;; Building coordinates
  building1-coordinates
  building2-coordinates

  ;; Shelter coordinates and tracking
  shelter-coordinates-top
  shelter-coordinates-bottom
  in-shelter-top-count
  in-shelter-bottom-count
  shelter-top-occupants
  shelter-bottom-occupants

  ;; Missile and explosion tracking
  missile-targets
  explosion-areas
  impact-areas
  missiles-launched
  pending-explosions

  ;; Casualty tracking
  casualties
  injured-count

  ;; Environment
  floor-colors
  exits

  ;; Simulation state
  simulation-complete
  initial-reaction-percentage
  first-hit

  ;; Evacuation decision tracking
  early-evacuees
  late-evacuees
  shelter-reached
  building-stayers
]

;; ========================================
;; BREED DEFINITIONS
;; ========================================

breed [building-occupants building-occupant]
breed [missiles missile]
breed [explosions explosion]
breed [exit-visuals exit-visual]
breed [floor-labels floor-label]

;; Exit visual properties
exit-visuals-own [
  floor-number
  building-number
]

;; Building occupant properties
building-occupants-own [
  ;; Location state
  in-building?
  in-shelter?
  building-number
  floor-number

  ;; Health and movement
  health
  evacuation-speed

  ;; Navigation
  target
  following-who
  next-exit

  ;; Behavioral state
  reacting?
  waiting-time
  switch-chance

  ;; Shelter selection
  chosen-shelter
  shelter-attempt-count
  waiting-at-shelter?

  ;; Decision tracking
  evacuation-decision
  evacuation-timing
]

;; Missile properties
missiles-own [
  impact-point
  explosion-radius
  speed
]

;; Explosion properties
explosions-own [
  duration
  radius
]

;; ========================================
;; MAIN SETUP PROCEDURES
;; ========================================

to setup
  clear-all
  set-colors
  setup-globals
  setup-buildings
  setup-shelter
  setup-people
  set first-hit false
  set initial-reaction-percentage reaction-percentage
  set missiles-launched 0
  set simulation-complete false
  reset-ticks
end 

to set-colors
  ;; Generate dynamic floor colors based on number of floors
  ;; Higher floors are lighter shades of blue
  set floor-colors []
  let base-color 140
  let color-step (255 - base-color) / (number-of-floors - 1)

  let i 0
  repeat number-of-floors [
    let current-color base-color + (i * color-step)
    set floor-colors lput (list current-color current-color 255) floor-colors
    set i i + 1
  ]
end 

to setup-globals
  ;; Initialize all global tracking variables
  set exits []
  set explosion-areas []
  set casualties 0
  set injured-count 0
  set in-shelter-top-count 0
  set in-shelter-bottom-count 0
  set missile-targets []
  set pending-explosions []
  set impact-areas []
end 

;; ========================================
;; BUILDING SETUP PROCEDURES
;; ========================================

to setup-buildings
  ;; Create two buildings with defined dimensions
  let building-width 16
  let building-height 24

  ;; Position buildings on left and right sides
  let b1x (min-pxcor + building-width)
  let b1y 10

  let b2x (max-pxcor - building-width)
  let b2y 10

  create-building b1x b1y building-width building-height 1
  create-building b2x b2y building-width building-height 2

  ;; Store coordinates for later reference
  set building1-coordinates (list b1x b1y building-width building-height)
  set building2-coordinates (list b2x b2y building-width building-height)
end 

to create-building [x y width height building-number1]
  ;; Create a multi-floor building with exits on each floor
  let floor-height height / number-of-floors
  let exits-per-floor number-of-exits

  ;; Create each floor with distinct colors
  foreach range number-of-floors [ floor1 ->
    let floor-color item floor1 floor-colors
    let y-base y - (height / 2) + (floor1 * floor-height)

    ;; Create floor patches
    ask patches with [
      pxcor >= x - (width / 2) and
      pxcor <= x + (width / 2) and
      pycor >= y-base and
      pycor < y-base + floor-height
    ] [
      set pcolor approximate-rgb (item 0 floor-color)
                                (item 1 floor-color)
                                (item 2 floor-color)
    ]

    ;; Create floor number label
    create-floor-labels 1 [
      setxy (x - (width / 2) + 2) (y-base + floor-height / 2)
      set label (floor1 + 1)
      set color black
    ]

    ;; Create exits for this floor
    let exit-spacing width / (exits-per-floor + 1)
    let exit-num 1

    repeat exits-per-floor [
      let exit-x x - (width / 2) + (exit-spacing * exit-num)
      let exit-y y-base
      set exit-num exit-num + 1

      ;; Create door frame
      create-exit-visuals 1 [
        setxy exit-x exit-y
        set color brown - 2
        set shape "square"
        set size 2
        set floor-number floor1
        set building-number building-number1
      ]

      ;; Create door
      create-exit-visuals 1 [
        setxy exit-x exit-y
        set color brown
        set shape "square"
        set size 1.8
        set floor-number floor1
        set building-number building-number1
      ]

      ;; Store exit coordinates
      set exits lput (list exit-x exit-y floor1 building-number1) exits
    ]
  ]
end 

;; ========================================
;; SHELTER SETUP PROCEDURES
;; ========================================

to setup-shelter
  ;; Create two bomb shelters (top and bottom)
  let shelter-width 14
  let shelter-height 6

  ;; Bottom shelter position
  let shelter-bottom-x 0
  let shelter-bottom-y (min-pycor + 8)

  ;; Top shelter position
  let shelter-top-x 0
  let shelter-top-y (max-pycor - 8)

  ;; Store coordinates
  set shelter-coordinates-bottom (list shelter-bottom-x shelter-bottom-y shelter-width shelter-height)
  set shelter-coordinates-top (list shelter-top-x shelter-top-y shelter-width shelter-height)

  ;; Create bottom shelter visual
  ask patches with [
    pxcor >= shelter-bottom-x - (shelter-width / 2) and
    pxcor <= shelter-bottom-x + (shelter-width / 2) and
    pycor >= shelter-bottom-y - (shelter-height / 2) and
    pycor <= shelter-bottom-y + (shelter-height / 2)
  ] [
    set pcolor gray + 2
  ]

  ;; Create top shelter visual
  ask patches with [
    pxcor >= shelter-top-x - (shelter-width / 2) and
    pxcor <= shelter-top-x + (shelter-width / 2) and
    pycor >= shelter-top-y - (shelter-height / 2) and
    pycor <= shelter-top-y + (shelter-height / 2)
  ] [
    set pcolor gray + 2
  ]

  ;; Create shelter labels
  create-floor-labels 1 [
    setxy shelter-bottom-x (shelter-bottom-y + 1)
    set label "SHELTER"
    set color black
  ]

  create-floor-labels 1 [
    setxy shelter-top-x (shelter-top-y + 1)
    set label "SHELTER"
    set color black
  ]
end 

;; ========================================
;; PEOPLE SETUP PROCEDURES
;; ========================================

to setup-people
  ;; Distribute people across both buildings
  let total-occupants initial-people
  let occupants-per-building floor (total-occupants / 2)

  ;; Calculate distribution for building 1
  let base-per-floor floor (occupants-per-building / number-of-floors)
  let remaining-building1 (occupants-per-building - (base-per-floor * number-of-floors))

  let building1-floor-counts []
  repeat number-of-floors [
    set building1-floor-counts lput base-per-floor building1-floor-counts
  ]

  ;; Distribute remaining people randomly across floors
  repeat remaining-building1 [
    let floor-index random number-of-floors
    let current-count item floor-index building1-floor-counts
    set building1-floor-counts replace-item floor-index building1-floor-counts (current-count + 1)
  ]

  ;; Calculate distribution for building 2
  let occupants-building2 (total-occupants - occupants-per-building)
  let base-per-floor2 floor (occupants-building2 / number-of-floors)
  let remaining-building2 (occupants-building2 - (base-per-floor2 * number-of-floors))

  let building2-floor-counts []
  repeat number-of-floors [
    set building2-floor-counts lput base-per-floor2 building2-floor-counts
  ]

  repeat remaining-building2 [
    let floor-index random number-of-floors
    let current-count item floor-index building2-floor-counts
    set building2-floor-counts replace-item floor-index building2-floor-counts (current-count + 1)
  ]

  ;; Create people in both buildings
  foreach range number-of-floors [ floor1 ->
    create-people-for-building floor1 building1-floor-counts building1-coordinates 1
    create-people-for-building floor1 building2-floor-counts building2-coordinates 2
  ]
end 

to create-people-for-building [floor1 floor-counts building-coords building-num]
  ;; Create people on a specific floor of a specific building
  let people-on-floor item floor1 floor-counts
  let x-pos item 0 building-coords
  let y-pos item 1 building-coords
  let width item 2 building-coords
  let height item 3 building-coords

  create-building-occupants people-on-floor [
    ;; Calculate floor position
    let floor-height height / number-of-floors
    let y-base y-pos - (height / 2) + (floor1 * floor-height)

    ;; Random position within floor bounds
    setxy (x-pos - (width / 2) + 1 + random-float (width - 2))
          (y-base + 1 + random-float (floor-height - 2))

    setup-person-properties floor1 building-num
  ]
end 

to setup-person-properties [floor1 building-num]
  ;; Initialize properties for a person
  set shape "person"
  set color green
  set size 1
  set health 100
  set floor-number floor1
  set in-building? true
  set in-shelter? false
  set building-number building-num
  set evacuation-speed 0.5 + random-float 0.5
  set reacting? reaction-percentage >= 100 or random 100 < reaction-percentage
  set waiting-time 0
  set switch-chance random-float 0.5
  set following-who nobody
  set next-exit nobody
  set chosen-shelter ifelse-value (random 2 = 0) ["top"] ["bottom"]
  set shelter-attempt-count 0
  set waiting-at-shelter? false
  set evacuation-decision "none"
  set evacuation-timing "none"
end 

;; ========================================
;; MAIN GO PROCEDURE
;; ========================================

to go
  if simulation-complete [stop]

  ;; Check for first missile hit and adjust reaction
  if not first-hit and any? explosions [
    set first-hit true
    adjust-reaction-percentage
  ]

  record-decisions
  move-people
  handle-missiles
  move-missiles
  handle-explosions
  update-casualties

  ;; Check if simulation is complete
  if missiles-launched >= number-of-missiles and
     not any? missiles and
     not any? explosions [
    set simulation-complete true
  ]

  tick
end 

;; ========================================
;; DECISION RECORDING PROCEDURES
;; ========================================

to record-decisions
  ;; Track evacuation decisions and timing
  ask building-occupants [
    ;; First round - initial decision
    if evacuation-decision = "none" [
      ifelse reacting? [
        set evacuation-decision "shelter"

        ifelse first-hit = false [
          set evacuation-timing "early"
          set early-evacuees early-evacuees + 1
        ][
          set evacuation-timing "late"
          set late-evacuees late-evacuees + 1
        ]
      ][
        set evacuation-decision "stay"
        set building-stayers building-stayers + 1
      ]
    ]

    ;; Changed mind after first explosions
    if evacuation-decision = "stay" and reacting? [
      set evacuation-decision "shelter"
      set evacuation-timing "late"
      set building-stayers building-stayers - 1
      set late-evacuees late-evacuees + 1
    ]
  ]
end 

to adjust-reaction-percentage
  ;; Increase reaction percentage to 80% after first hit
  let new-percentage 80

  ask building-occupants with [not reacting? and health > 0] [
    if random 100 < new-percentage [
      set reacting? true
    ]
  ]
end 

;; ========================================
;; MOVEMENT PROCEDURES
;; ========================================

to move-people
  ;; Move all reacting people
  ask building-occupants with [health > 0 and reacting?] [
    ifelse in-building? [
      handle-exit-movement
    ][
      move-towards-shelter
    ]
  ]
end 

to handle-exit-movement
  ;; Handle movement toward exits within building
  let current-floor-exits filter [exit ->
    item 2 exit = floor-number and
    item 3 exit = building-number
  ] exits

  if not empty? current-floor-exits [
    let nearest-exit get-nearest-exit current-floor-exits

    if nearest-exit != nobody [
      let exit-x item 0 nearest-exit
      let exit-y item 1 nearest-exit

      ;; Move towards exit
      face patch exit-x exit-y

      ;; Check if path is blocked
      let ahead-patch patch-ahead evacuation-speed

      ifelse ahead-patch != nobody and count building-occupants-on ahead-patch > 2 [
        ;; Path blocked - try to move sideways
        ifelse random 2 = 0 [rt 90] [lt 90]
        fd 0.1
      ][
        ;; Path clear - move forward
        fd min (list evacuation-speed 0.3)
      ]

      ;; Handle exit transition when close enough
      if distancexy exit-x exit-y < 1 [
        handle-exit-transition
      ]
    ]
  ]
end 

to handle-exit-transition
  ;; Handle transition between floors or exiting building
  ifelse floor-number > 0 [
    ;; Move to lower floor
    set floor-number floor-number - 1
    move-to-lower-floor
    set next-exit nobody
  ][
    ;; Exit building when on ground floor
    set in-building? false
    let exit-x xcor
    let building-width 16
    if building-number = 1 [
      setxy (exit-x + 2) ycor
    ]
    if building-number = 2 [
      setxy (exit-x - 2) ycor
    ]
    set next-exit nobody
  ]
end 

to move-to-lower-floor
  ;; Move person to exit on lower floor
  let current-building building-number

  let new-floor-exits filter [exit ->
    item 2 exit = floor-number and
    item 3 exit = current-building
  ] exits

  if not empty? new-floor-exits [
    let target-exit one-of new-floor-exits
    setxy (item 0 target-exit + random-float 2 - 1)
          (item 1 target-exit + random-float 2)
  ]
end 

to move-towards-shelter
  ;; Move toward chosen shelter
  if not in-shelter? [
    if not waiting-at-shelter? [
      let target-shelter ifelse-value (chosen-shelter = "top")
        [shelter-coordinates-top]
        [shelter-coordinates-bottom]

      let shelter-x item 0 target-shelter
      let shelter-y item 1 target-shelter
      let target-patch patch shelter-x shelter-y

      if target-patch != nobody [
        ifelse distance target-patch < 3 [
          let is-full? shelter-at-capacity? chosen-shelter

          ifelse not is-full? [
            ;; Enter shelter
            let shelter-patches patches with [
              pcolor = gray + 2 and
              (ifelse-value ([chosen-shelter] of myself = "top")
                [pycor > 0]
                [pycor < 0])
            ]

            if any? shelter-patches [
              move-to one-of shelter-patches
              set in-shelter? true
              set color green
            ]
          ][
            ;; Shelter full - make decision
            rt 90 + random 180
            fd 2
            set waiting-at-shelter? true
            set shelter-attempt-count shelter-attempt-count + 1

            ;; Try other shelter if haven't tried both yet
            if shelter-attempt-count = 1 [
              if random 100 < 50 [
                set chosen-shelter ifelse-value (chosen-shelter = "top") ["bottom"] ["top"]
                set color blue
                set waiting-at-shelter? false
              ]
            ]
          ]
        ][
          ;; Still approaching shelter
          face target-patch
          fd min (list evacuation-speed 0.3)
        ]
      ]
    ]
  ]
end 

;; ========================================
;; EXIT FINDING PROCEDURES
;; ========================================

to-report get-downward-exits [floor-exits]
  ;; Get only exits that lead downward
  let downward-exits []

  foreach floor-exits [ this-exit ->
    let exit-floor item 2 this-exit
    let exit-building item 3 this-exit
    let this-x item 0 this-exit

    ifelse exit-floor = 0 [
      ;; Ground floor exit leads outside
      set downward-exits lput this-exit downward-exits
    ][
      ;; Check if there's an exit below
      let connected-exit nobody
      foreach exits [ lower-exit ->
        let lower-x item 0 lower-exit
        let lower-y item 1 lower-exit
        let lower-floor item 2 lower-exit
        let lower-building item 3 lower-exit

        ;; Exit directly below
        if lower-building = exit-building and
           lower-floor = (exit-floor - 1) and
           abs (lower-x - this-x) < 1 [
          set connected-exit lower-exit
        ]
      ]

      if connected-exit != nobody [
        set downward-exits lput this-exit downward-exits
      ]
    ]
  ]

  report downward-exits
end 

to-report get-nearest-exit [floor-exits]
  ;; Find nearest downward exit
  let downward-exits get-downward-exits floor-exits

  if empty? downward-exits [
    report nobody
  ]

  let closest-exit nobody
  let min-distance 999999

  foreach downward-exits [ this-exit ->
    let dist distance-to-exit self this-exit
    if dist < min-distance [
      set min-distance dist
      set closest-exit this-exit
    ]
  ]

  report closest-exit
end 

;; ========================================
;; MISSILE PROCEDURES
;; ========================================

to handle-missiles
  ;; Launch missiles according to strategy
  if missile-strategy = "immediate" [
    launch-immediate-missiles
  ]
  if missile-strategy = "delayed" [
    launch-delayed-missiles
  ]
end 

to launch-immediate-missiles
  ;; Launch all missiles at once
  if ticks = 10 and missiles-launched < number-of-missiles [
    repeat number-of-missiles [
      create-missile
      set missiles-launched missiles-launched + 1
    ]
  ]
end 

to launch-delayed-missiles
  ;; Launch missiles with delay
  if ticks mod missile-delay = 0 and ticks >= 10 [
    if missiles-launched < number-of-missiles [
      create-missile
      set missiles-launched missiles-launched + 1
    ]
  ]
end 

to create-missile
  ;; Create a missile with target
  create-missiles 1 [
    set shape "arrow"
    set color red
    set size 2

    ;; Create target based on strategy
    let target-patch nobody
    ifelse missile-strategy = "immediate"
    [
      ;; Target buildings
      set target-patch one-of patches with [
        abs pxcor < 35 and
        abs pycor < 15
      ]
    ]
    [
      ;; Alternate between buildings and yard
      ifelse count missiles mod 2 = 0
      [
        set target-patch one-of patches with [
          abs pxcor < 35 and
          abs pycor < 15
        ]
      ]
      [
        set target-patch one-of patches with [
          abs pxcor < 45 and
          abs pycor < 20
        ]
      ]
    ]

    set impact-point target-patch
    setxy max-pxcor random-ycor
    set explosion-radius 6
    set speed 0.5
  ]
end 

to move-missiles
  ;; Move all missiles toward their targets
  ask missiles [
    face impact-point
    fd speed

    ;; Check for impact
    if distance impact-point < 1 [
      set pending-explosions lput (list xcor ycor explosion-radius) pending-explosions
      die
    ]
  ]

  handle-pending-explosions
end 

;; ========================================
;; EXPLOSION PROCEDURES
;; ========================================

to handle-pending-explosions
  ;; Create explosions and damage areas
  foreach pending-explosions [ explosion-info ->
    let x-pos item 0 explosion-info
    let y-pos item 1 explosion-info
    let exp-radius item 2 explosion-info

    ;; Create explosion effect
    create-explosions 1 [
      setxy x-pos y-pos
      set shape "circle"
      set color 27
      set size 2
      set duration 10
      set radius exp-radius
      set explosion-areas lput (list xcor ycor radius) explosion-areas
    ]

    ;; Create permanent impact visualization
    let impact-center patch x-pos y-pos
    let max-distance exp-radius

    ask impact-center [
      ask patches in-radius max-distance [
        let distance-from-center distance impact-center
        let impact-intensity (1 - (distance-from-center / max-distance))

        if impact-intensity > 0.15 [
          let red-component 200 + (55 * (1 - impact-intensity))
          let other-components 100 * (1 - impact-intensity)
          set pcolor approximate-rgb red-component other-components other-components

          if impact-intensity > 0.8 [
            set pcolor approximate-rgb (red-component * 0.7) (other-components * 0.7) (other-components * 0.7)
          ]
        ]
      ]
    ]

    set impact-areas lput (list x-pos y-pos exp-radius) impact-areas
  ]
  set pending-explosions []
end 

to handle-explosions
  ;; Process explosion effects and damage
  ask explosions [
    set duration duration - 1
    if duration <= 0 [ die ]

    let current-radius radius

    ask building-occupants with [health > 0] in-radius current-radius [
      let damage 0

      ;; Calculate damage based on location
      ifelse in-shelter? [
        ifelse chosen-shelter = "top" [
          set damage 4
        ] [
          set damage 5
        ]
      ] [
        if in-building? [ set damage 40 ]
        if (not in-building?) and (not in-shelter?) [ set damage 80 ]
      ]

      ;; Apply distance factor
      let distance-factor 1 - (distance myself / current-radius)
      set damage damage * distance-factor

      set health health - damage
      update-person-color
    ]

    set size size + 0.1
    set color 27 + (1.5 * (10 - duration))
  ]
end 

;; ========================================
;; UPDATE PROCEDURES
;; ========================================

to update-person-color
  ;; Update person color based on health
  if health <= 0 [ set color black ]
  if health > 0 and health < 50 [ set color red ]
  if health >= 50 and health < 80 [ set color yellow ]
  if health >= 80 [ set color green ]
end 

to update-casualties
  ;; Update casualty counts
  set casualties count building-occupants with [health <= 0]
  set injured-count count building-occupants with [health > 0 and health < 80]
end 

;; ========================================
;; UTILITY PROCEDURES
;; ========================================

to-report distance-between [x1 y1 x2 y2]
  ;; Calculate distance between two points
  report sqrt ((x1 - x2) ^ 2 + (y1 - y2) ^ 2)
end 

to-report distance-to-exit [occupant exit-coords]
  ;; Calculate distance to exit
  let exit-x item 0 exit-coords
  let exit-y item 1 exit-coords
  report distancexy exit-x exit-y
end 

to-report get-floor-color [floor-num]
  ;; Get color for floor number
  report item floor-num floor-colors
end 

to-report shelter-at-capacity? [shelter-type]
  ;; Check if shelter is at capacity
  let shelter-patches patches with [
    pcolor = gray + 2 and
    (ifelse-value (shelter-type = "top")
      [pycor > 0]
      [pycor < 0])
  ]

  let current-count count building-occupants with [
    in-shelter? and
    chosen-shelter = shelter-type and
    member? patch-here shelter-patches
  ]

  ;; Update global counters
  ifelse shelter-type = "top"
    [set shelter-top-occupants current-count]
    [set shelter-bottom-occupants current-count]

  report current-count >= shelter-capacity
end 

;; ========================================
;; REPORTER PROCEDURES FOR MONITORING
;; ========================================

to-report death-count
  report casualties
end 

to-report injured-people
  report injured-count
end 

to-report missiles-remaining
  report number-of-missiles - missiles-launched
end 

to-report shelter-status
  report (word
    "Top Shelter: " shelter-top-occupants "/" shelter-capacity
    " | Bottom Shelter: " shelter-bottom-occupants "/" shelter-capacity)
end 

;; ========================================
;; REPORTER PROCEDURES FOR PLOTTING
;; ========================================

;; Early evacuees

to-report early-evacuee-casualties
  report count building-occupants with [
    evacuation-timing = "early" and
    health <= 0
  ]
end 

to-report early-evacuee-injured
  report count building-occupants with [
    evacuation-timing = "early" and
    health > 0 and health < 80
  ]
end 

to-report early-evacuee-intact
  report count building-occupants with [
    evacuation-timing = "early" and
    health >= 80
  ]
end 

to-report early-evacuee-casualty-percent
  ifelse early-evacuees > 0 [
    report (early-evacuee-casualties / early-evacuees) * 100
  ][
    report 0
  ]
end 

to-report early-evacuee-injured-percent
  ifelse early-evacuees > 0 [
    report (early-evacuee-injured / early-evacuees) * 100
  ][
    report 0
  ]
end 

;; Late evacuees

to-report late-evacuee-casualties
  report count building-occupants with [
    evacuation-timing = "late" and
    health <= 0
  ]
end 

to-report late-evacuee-injured
  report count building-occupants with [
    evacuation-timing = "late" and
    health > 0 and health < 80
  ]
end 

to-report late-evacuee-intact
  report count building-occupants with [
    evacuation-timing = "late" and
    health >= 80
  ]
end 

to-report late-evacuee-casualty-percent
  ifelse late-evacuees > 0 [
    report (late-evacuee-casualties / late-evacuees) * 100
  ][
    report 0
  ]
end 

to-report late-evacuee-injured-percent
  ifelse late-evacuees > 0 [
    report (late-evacuee-injured / late-evacuees) * 100
  ][
    report 0
  ]
end 

;; Building stayers

to-report stayer-casualties
  report count building-occupants with [
    evacuation-decision = "stay" and
    health <= 0
  ]
end 

to-report stayer-injured
  report count building-occupants with [
    evacuation-decision = "stay" and
    health > 0 and health < 80
  ]
end 

to-report stayer-intact
  report count building-occupants with [
    evacuation-decision = "stay" and
    health >= 80
  ]
end 

to-report stayer-casualty-percent
  ifelse building-stayers > 0 [
    report (stayer-casualties / building-stayers) * 100
  ][
    report 0
  ]
end 

to-report stayer-injured-percent
  ifelse building-stayers > 0 [
    report (stayer-injured / building-stayers) * 100
  ][
    report 0
  ]
end 

There are 2 versions of this model.

Uploaded by When Description Download
Artem Serdyuk 10 days ago Added info and converted to Netlogo 7.0.0 Download this version
Artem Serdyuk 9 months ago Initial upload Download this version

Attached files

File Type Description Last updated
Missile Attack Evacuation.png preview Preview for 'Missile Attack Evacuation' 9 months ago, by Artem Serdyuk Download
missile strike evacuation.drawio (1).png png Agent Logic in Simulation 9 months ago, by Artem Serdyuk Download

This model does not have any ancestors.

This model does not have any descendants.