1
2
3 """Infect action example: a typical zombie infection
4 - random movement
5 - zombie infection
6 - infection range <= 1m
7 - infection duration == immediately
8 - 1 initial zombie and 49 healthy people
9 """
10
11 import sys
12 sys.path.append("..")
13
14 from mosp.core import Simulation, Person, action, start_action
15 from mosp.geo import osm
16 from mosp.impl import movement
17 from mosp.monitors import ChildprocessPlayerChamplainMonitor, SocketPlayerMonitor
18
19 __author__ = "F. Ludwig, P. Tute"
20 __maintainer__ = "B. Henne"
21 __contact__ = "henne@dcsec.uni-hannover.de"
22 __copyright__ = "(c) 2010-2011, DCSec, Leibniz Universitaet Hannover, Germany"
23 __license__ = "GPLv3"
27 """Implements a zombie person doing random movement infecting others.
28 @author: P. Tute
29 @author: F. Ludwig"""
30
32 """Init the zombie."""
33 super(ZombieWiggler, self).__init__(*args, **kwargs)
34 self.p_infected = False
35 if kwargs.get('infected'):
36 self.infect(True)
37
38 next_target = movement.person_next_target_random
39
40 - def infect(self, for_sure=False):
41 """The infection routine itself.
42
43 If not infected, person gets infected and speed is set to its half."""
44 if for_sure or self._random.random() < 0.5:
45 if self.p_infected == False:
46 self.p_infected = True
47 self.p_color = 1
48 self.p_color_rgba = (1.0, 0.1, 0.1, 1.0)
49 self.p_speed = self.p_speed / 2
50 start_action(self.infect_other)
51
52 @action(2, start=False)
54 """The zombie infect action.
55
56 Every 2 ticks this action is called (using the mosp action decorator).
57 This action looks for people in range of 1 meters, and calls their
58 infect() routine. Action is not active at beginning. It is activated by
59 self.infect_other.start() and then is called every 2 ticks."""
60 if self.p_infected == True:
61 self.get_near(1).call(delay=1).infect(True)
62
65 """Defines the zombie infection simulation with random movement.
66
67 map: hannover1.osm, output to socketPlayer or champlain child process player,
68 49 healthy people, 1 zombie, infection using action decorator."""
69 s = Simulation(geo=osm.OSMModel('../data/hannover0.osm'), rel_speed=60)
70 m = s.add_monitor(SocketPlayerMonitor, 2)
71 s.add_persons(ZombieWiggler, 49, monitor=m)
72 s.add_persons(ZombieWiggler, 1, monitor=m, args={"infected":True, "speed":0.7})
73 s.run(until=10000, real_time=True, monitor=True)
74
75
76 if __name__ == '__main__':
77 main()
78