Package horizons :: Package world :: Package building :: Module nature
[hide private]
[frames] | no frames]

Source Code for Module horizons.world.building.nature

  1  from horizons.constants import BUILDINGS, LAYERS 
  2  from horizons.scheduler import Scheduler 
  3  from horizons.world.building.buildable import BuildableRect, BuildableSingleEverywhere 
  4  from horizons.world.building.building import BasicBuilding 
  5  from horizons.world.building.buildingresourcehandler import BuildingResourceHandler 
  6  from horizons.world.production.producer import Producer 
  7   
  8  # ################################################### 
  9  # Copyright (C) 2008-2017 The Unknown Horizons Team 
 10  # team@unknown-horizons.org 
 11  # This file is part of Unknown Horizons. 
 12  # 
 13  # Unknown Horizons is free software; you can redistribute it and/or modify 
 14  # it under the terms of the GNU General Public License as published by 
 15  # the Free Software Foundation; either version 2 of the License, or 
 16  # (at your option) any later version. 
 17  # 
 18  # This program is distributed in the hope that it will be useful, 
 19  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 20  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 21  # GNU General Public License for more details. 
 22  # 
 23  # You should have received a copy of the GNU General Public License 
 24  # along with this program; if not, write to the 
 25  # Free Software Foundation, Inc., 
 26  # 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
 27  # ################################################### 
 28   
 29   
30 -class NatureBuilding(BuildableRect, BasicBuilding):
31 """Class for objects that are part of the environment, the nature""" 32 walkable = True 33 layer = LAYERS.OBJECTS
34 35
36 -class NatureBuildingResourceHandler(BuildingResourceHandler, NatureBuilding):
37 # sorry, but this class is to be removed soon anyway 38 pass
39 40
41 -class Field(NatureBuildingResourceHandler):
42 walkable = False 43 layer = LAYERS.OBJECTS 44
45 - def initialize(self, **kwargs):
46 super().initialize(**kwargs) 47 48 if self.owner.is_local_player: 49 # make sure to have a farm nearby when we can reasonably assume that the crops are fully grown 50 prod_comp = self.get_component(Producer) 51 productions = prod_comp.get_productions() 52 if not productions: 53 print("Warning: Field is assumed to always produce, but doesn't.", self) 54 else: 55 run_in = Scheduler().get_ticks(productions[0].get_production_time()) 56 Scheduler().add_new_object(self._check_covered_by_farm, self, run_in=run_in)
57
58 - def _check_covered_by_farm(self):
59 """Warn in case there is no farm nearby to cultivate the field""" 60 farm_in_range = any((farm.position.distance(self.position) <= farm.radius) for farm in 61 self.settlement.buildings_by_id[BUILDINGS.FARM]) 62 if not farm_in_range and self.owner.is_local_player: 63 pos = self.position.origin 64 self.session.ingame_gui.message_widget.add(point=pos, string_id="FIELD_NEEDS_FARM", 65 check_duplicate=True)
66 67
68 -class Tree(NatureBuildingResourceHandler):
69 buildable_upon = True 70 layer = LAYERS.OBJECTS
71 72
73 -class ResourceDeposit(NatureBuilding):
74 """Class for stuff like clay deposits.""" 75 tearable = False 76 layer = LAYERS.OBJECTS 77 walkable = False
78 79
80 -class Fish(BuildableSingleEverywhere, BuildingResourceHandler, BasicBuilding):
81 - def __init__(self, *args, **kwargs):
82 super().__init__(*args, **kwargs) 83 self.last_usage_tick = -1000000 # a long time ago 84 85 # Make the fish run at different speeds 86 multiplier = 0.7 + self.session.random.random() * 0.6 87 self._instance.setTimeMultiplier(multiplier)
88
89 - def load(self, db, worldid):
90 super().load(db, worldid) 91 self.last_usage_tick = db.get_last_fish_usage_tick(worldid)
92
93 - def save(self, db):
94 super().save(db) 95 translated_tick = self.last_usage_tick - Scheduler().cur_tick # pre-translate for the loading process 96 db("INSERT INTO fish_data(rowid, last_usage_tick) VALUES(?, ?)", self.worldid, translated_tick)
97
98 - def remove_incoming_collector(self, collector):
99 super().remove_incoming_collector(collector) 100 self.last_usage_tick = Scheduler().cur_tick
101 102
103 -class Ambient(NatureBuilding):
104 """Class for ambient graphics such as rocks and flowers.""" 105 buildable_upon = True 106 layer = LAYERS.OBJECTS
107