Package horizons :: Package world :: Package disaster :: Module blackdeathdisaster
[hide private]
[frames] | no frames]

Source Code for Module horizons.world.disaster.blackdeathdisaster

 1  # ################################################### 
 2  # Copyright (C) 2013-2017 The Unknown Horizons Team 
 3  # team@unknown-horizons.org 
 4  # This file is part of Unknown Horizons. 
 5  # 
 6  # Unknown Horizons is free software; you can redistribute it and/or modify 
 7  # it under the terms of the GNU General Public License as published by 
 8  # the Free Software Foundation; either version 2 of the License, or 
 9  # (at your option) any later version. 
10  # 
11  # This program is distributed in the hope that it will be useful, 
12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
14  # GNU General Public License for more details. 
15  # 
16  # You should have received a copy of the GNU General Public License 
17  # along with this program; if not, write to the 
18  # Free Software Foundation, Inc., 
19  # 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
20  # ################################################### 
21   
22  from horizons.constants import BUILDINGS, RES, TIER 
23  from horizons.scheduler import Scheduler 
24  from horizons.util.python.callback import Callback 
25  from horizons.world.disaster.buildinginfluencingdisaster import BuildingInfluencingDisaster 
26  from horizons.world.status import BlackDeathStatusIcon 
27   
28   
29 -class BlackDeathDisaster(BuildingInfluencingDisaster):
30 """Simulates the Black Death. 31 32 """ 33 34 TYPE = "Happy dying." 35 NOTIFICATION_TYPE = 'BUILDING_INFECTED_BY_BLACK_DEATH' 36 37 SEED_CHANCE = 0.015 38 39 EXPANSION_RADIUS = 4 40 41 DISASTER_RES = RES.BLACKDEATH 42 43 BUILDING_TYPE = BUILDINGS.RESIDENTIAL 44 45 MIN_BREAKOUT_TIER = TIER.SETTLERS 46 47 MIN_INHABITANTS_FOR_BREAKOUT = 5 48 49 STATUS_ICON = BlackDeathStatusIcon 50 51 RESCUE_BUILDING_TYPE = BUILDINGS.DOCTOR 52
53 - def __init__(self, settlement, manager):
54 super().__init__(settlement, manager) 55 self.healed_buildings = []
56
57 - def infect(self, building, load=None):
58 """@load: (db, disaster_worldid), set on restoring infected state of savegame""" 59 if building not in self.healed_buildings: 60 super().infect(building, load=load)
61
62 - def wreak_havoc(self, building):
63 """Some inhabitants have to die.""" 64 super() 65 if building.inhabitants > 1: 66 inhabitants_that_will_die = self._manager.session.random.randint(1, building.inhabitants) 67 building.inhabitants -= inhabitants_that_will_die 68 self.log.debug("%s inhabitants dying", inhabitants_that_will_die) 69 Scheduler().add_new_object(Callback(self.wreak_havoc, building), self, run_in=self.TIME_BEFORE_HAVOC) 70 else: 71 self.recover(building)
72
73 - def recover(self, building):
74 self.healed_buildings.append(building) 75 super().recover(building)
76