Permalink
Browse files

move building evaluator classes into the relevant abstract building f…

…iles
  • Loading branch information...
1 parent 39f2864 commit 61093357f802e2ed1205d66d08a9202b77747900 @otinn otinn committed Aug 21, 2011
Showing with 712 additions and 1,158 deletions.
  1. +24 −1 horizons/ai/aiplayer/building/boatbuilder.py
  2. +28 −1 horizons/ai/aiplayer/building/brickyard.py
  3. +31 −1 horizons/ai/aiplayer/building/charcoalburner.py
  4. +18 −1 horizons/ai/aiplayer/building/claypit.py
  5. +39 −1 horizons/ai/aiplayer/building/distillery.py
  6. +235 −2 horizons/ai/aiplayer/building/farm.py
  7. +110 −2 horizons/ai/aiplayer/building/fisher.py
  8. +15 −1 horizons/ai/aiplayer/building/ironmine.py
  9. +74 −1 horizons/ai/aiplayer/building/lumberjack.py
  10. +27 −1 horizons/ai/aiplayer/building/signalfire.py
  11. +30 −1 horizons/ai/aiplayer/building/smeltery.py
  12. +33 −1 horizons/ai/aiplayer/building/toolmaker.py
  13. +38 −1 horizons/ai/aiplayer/building/weaver.py
  14. +10 −14 horizons/ai/aiplayer/{buildingevaluator/__init__.py → buildingevaluator.py}
  15. +0 −53 horizons/ai/aiplayer/buildingevaluator/boatbuilderevaluator.py
  16. +0 −58 horizons/ai/aiplayer/buildingevaluator/brickyardevaluator.py
  17. +0 −61 horizons/ai/aiplayer/buildingevaluator/charcoalburnerevaluator.py
  18. +0 −46 horizons/ai/aiplayer/buildingevaluator/claypitevaluator.py
  19. +0 −69 horizons/ai/aiplayer/buildingevaluator/distilleryevaluator.py
  20. +0 −216 horizons/ai/aiplayer/buildingevaluator/farmevaluator.py
  21. +0 −137 horizons/ai/aiplayer/buildingevaluator/fisherevaluator.py
  22. +0 −43 horizons/ai/aiplayer/buildingevaluator/ironmineevaluator.py
  23. +0 −112 horizons/ai/aiplayer/buildingevaluator/lumberjackevaluator.py
  24. +0 −83 horizons/ai/aiplayer/buildingevaluator/modifiedfieldevaluator.py
  25. +0 −57 horizons/ai/aiplayer/buildingevaluator/signalfireevaluator.py
  26. +0 −61 horizons/ai/aiplayer/buildingevaluator/smelteryevaluator.py
  27. +0 −64 horizons/ai/aiplayer/buildingevaluator/toolmakerevaluator.py
  28. +0 −69 horizons/ai/aiplayer/buildingevaluator/weaverevaluator.py
@@ -20,9 +20,11 @@
# ###################################################
from horizons.ai.aiplayer.building import AbstractBuilding
-from horizons.ai.aiplayer.buildingevaluator.boatbuilderevaluator import BoatBuilderEvaluator
+from horizons.ai.aiplayer.buildingevaluator import BuildingEvaluator
+from horizons.ai.aiplayer.constants import BUILDING_PURPOSE
from horizons.constants import BUILDINGS
from horizons.util.python import decorators
+from horizons.entities import Entities
class AbstractBoatBuilder(AbstractBuilding):
@property
@@ -38,6 +40,27 @@ def producer_building(self):
def register_buildings(cls):
cls.available_buildings[BUILDINGS.BOATBUILDER_CLASS] = cls
+class BoatBuilderEvaluator(BuildingEvaluator):
+ @classmethod
+ def create(cls, area_builder, x, y, orientation):
+ builder = area_builder.make_builder(BUILDINGS.BOATBUILDER_CLASS, x, y, True, orientation)
+ if not builder:
+ return None
+
+ distance_to_collector = cls._distance_to_nearest_collector(area_builder, builder)
+ if distance_to_collector is None:
+ return None # require boat builders to have a collector building in range
+
+ personality = area_builder.owner.personality_manager.get('BoatBuilderEvaluator')
+ alignment = cls._get_alignment(area_builder, builder.position.tuple_iter())
+ value = float(Entities.buildings[BUILDINGS.BOATBUILDER_CLASS].radius) / distance_to_collector + alignment * personality.alignment_importance
+ return BoatBuilderEvaluator(area_builder, builder, value)
+
+ @property
+ def purpose(self):
+ return BUILDING_PURPOSE.BOAT_BUILDER
+
AbstractBoatBuilder.register_buildings()
decorators.bind_all(AbstractBoatBuilder)
+decorators.bind_all(BoatBuilderEvaluator)
@@ -20,9 +20,11 @@
# ###################################################
from horizons.ai.aiplayer.building import AbstractBuilding
-from horizons.ai.aiplayer.buildingevaluator.brickyardevaluator import BrickyardEvaluator
+from horizons.ai.aiplayer.buildingevaluator import BuildingEvaluator
+from horizons.ai.aiplayer.constants import BUILDING_PURPOSE
from horizons.constants import BUILDINGS
from horizons.util.python import decorators
+from horizons.entities import Entities
class AbstractBrickyard(AbstractBuilding):
@property
@@ -33,6 +35,31 @@ def evaluator_class(self):
def register_buildings(cls):
cls.available_buildings[BUILDINGS.BRICKYARD_CLASS] = cls
+class BrickyardEvaluator(BuildingEvaluator):
+ @classmethod
+ def create(cls, area_builder, x, y, orientation):
+ builder = area_builder.make_builder(BUILDINGS.BRICKYARD_CLASS, x, y, True, orientation)
+ if not builder:
+ return None
+
+ distance_to_clay_pit = cls._distance_to_nearest_building(area_builder, builder, BUILDINGS.CLAY_PIT_CLASS)
+ distance_to_collector = cls._distance_to_nearest_collector(area_builder, builder)
+ if distance_to_clay_pit is None and distance_to_collector is None:
+ return None
+
+ personality = area_builder.owner.personality_manager.get('BrickyardEvaluator')
+ distance_penalty = Entities.buildings[BUILDINGS.BRICKYARD_CLASS].radius * personality.distance_penalty
+
+ alignment = cls._get_alignment(area_builder, builder.position.tuple_iter())
+ distance = cls._weighted_distance(distance_to_clay_pit, [(personality.collector_distance_importance, distance_to_collector)], distance_penalty)
+ value = float(Entities.buildings[BUILDINGS.BRICKYARD_CLASS].radius) / distance + alignment * personality.alignment_importance
+ return BrickyardEvaluator(area_builder, builder, value)
+
+ @property
+ def purpose(self):
+ return BUILDING_PURPOSE.BRICKYARD
+
AbstractBrickyard.register_buildings()
decorators.bind_all(AbstractBrickyard)
+decorators.bind_all(BrickyardEvaluator)
@@ -20,7 +20,9 @@
# ###################################################
from horizons.ai.aiplayer.building import AbstractBuilding
-from horizons.ai.aiplayer.buildingevaluator.charcoalburnerevaluator import CharcoalBurnerEvaluator
+from horizons.ai.aiplayer.buildingevaluator import BuildingEvaluator
+from horizons.ai.aiplayer.constants import BUILDING_PURPOSE
+from horizons.entities import Entities
from horizons.constants import BUILDINGS
from horizons.util.python import decorators
@@ -33,6 +35,34 @@ def evaluator_class(self):
def register_buildings(cls):
cls.available_buildings[BUILDINGS.CHARCOAL_BURNER_CLASS] = cls
+class CharcoalBurnerEvaluator(BuildingEvaluator):
+ @classmethod
+ def create(cls, area_builder, x, y, orientation):
+ builder = area_builder.make_builder(BUILDINGS.CHARCOAL_BURNER_CLASS, x, y, True, orientation)
+ if not builder:
+ return None
+
+ distance_to_collector = cls._distance_to_nearest_collector(area_builder, builder)
+ if distance_to_collector is None:
+ return None
+
+ personality = area_builder.owner.personality_manager.get('CharcoalBurnerEvaluator')
+ distance_penalty = Entities.buildings[BUILDINGS.CHARCOAL_BURNER_CLASS].radius * personality.distance_penalty
+
+ distance_to_iron_mine = cls._distance_to_nearest_building(area_builder, builder, BUILDINGS.IRON_MINE_CLASS)
+ distance_to_lumberjack = cls._distance_to_nearest_building(area_builder, builder, BUILDINGS.LUMBERJACK_CLASS)
+ alignment = cls._get_alignment(area_builder, builder.position.tuple_iter())
+
+ distance = cls._weighted_distance(distance_to_collector, [(personality.lumberjack_distance_importance, distance_to_lumberjack), \
+ (personality.iron_mine_distance_importance, distance_to_iron_mine)], distance_penalty)
+ value = float(Entities.buildings[BUILDINGS.CHARCOAL_BURNER_CLASS].radius) / distance + alignment * personality.alignment_importance
+ return CharcoalBurnerEvaluator(area_builder, builder, value)
+
+ @property
+ def purpose(self):
+ return BUILDING_PURPOSE.CHARCOAL_BURNER
+
AbstractCharcoalBurner.register_buildings()
decorators.bind_all(AbstractCharcoalBurner)
+decorators.bind_all(CharcoalBurnerEvaluator)
@@ -20,7 +20,8 @@
# ###################################################
from horizons.ai.aiplayer.building import AbstractBuilding
-from horizons.ai.aiplayer.buildingevaluator.claypitevaluator import ClayPitEvaluator
+from horizons.ai.aiplayer.buildingevaluator import BuildingEvaluator
+from horizons.ai.aiplayer.constants import BUILDING_PURPOSE
from horizons.constants import BUILDINGS
from horizons.util.python import decorators
@@ -38,6 +39,22 @@ def evaluator_class(self):
def register_buildings(cls):
cls.available_buildings[BUILDINGS.CLAY_PIT_CLASS] = cls
+class ClayPitEvaluator(BuildingEvaluator):
+ @classmethod
+ def create(cls, area_builder, x, y, orientation):
+ builder = area_builder.make_builder(BUILDINGS.CLAY_PIT_CLASS, x, y, True, orientation)
+ if not builder:
+ return None
+
+ distance_to_collector = cls._distance_to_nearest_collector(area_builder, builder, False)
+ value = 1.0 / (distance_to_collector + 1)
+ return ClayPitEvaluator(area_builder, builder, value)
+
+ @property
+ def purpose(self):
+ return BUILDING_PURPOSE.CLAY_PIT
+
AbstractClayPit.register_buildings()
decorators.bind_all(AbstractClayPit)
+decorators.bind_all(ClayPitEvaluator)
@@ -20,9 +20,11 @@
# ###################################################
from horizons.ai.aiplayer.building import AbstractBuilding
-from horizons.ai.aiplayer.buildingevaluator.distilleryevaluator import DistilleryEvaluator
+from horizons.ai.aiplayer.buildingevaluator import BuildingEvaluator
+from horizons.ai.aiplayer.constants import BUILDING_PURPOSE
from horizons.constants import BUILDINGS
from horizons.util.python import decorators
+from horizons.entities import Entities
class AbstractDistillery(AbstractBuilding):
@property
@@ -33,6 +35,42 @@ def evaluator_class(self):
def register_buildings(cls):
cls.available_buildings[BUILDINGS.DISTILLERY_CLASS] = cls
+class DistilleryEvaluator(BuildingEvaluator):
+ @classmethod
+ def create(cls, area_builder, x, y, orientation):
+ builder = area_builder.make_builder(BUILDINGS.DISTILLERY_CLASS, x, y, True, orientation)
+ if not builder:
+ return None
+
+ distance_to_farm = None
+ for building in area_builder.settlement.get_buildings_by_id(BUILDINGS.FARM_CLASS):
+ distance = builder.position.distance(building.position)
+ if distance <= Entities.buildings[BUILDINGS.DISTILLERY_CLASS].radius:
+ sugarcane_producer = False
+ for provider in building._get_providers():
+ if isinstance(provider, Entities.buildings[BUILDINGS.SUGARCANE_FIELD_CLASS]):
+ sugarcane_producer = True
+ break
+ if sugarcane_producer:
+ distance_to_farm = distance if distance_to_farm is None or distance < distance_to_farm else distance_to_farm
+
+ distance_to_collector = cls._distance_to_nearest_collector(area_builder, builder)
+ if distance_to_collector is None:
+ return None # require distilleries to have a collector building in range
+
+ personality = area_builder.owner.personality_manager.get('DistilleryEvaluator')
+ distance_penalty = Entities.buildings[BUILDINGS.DISTILLERY_CLASS].radius * personality.distance_penalty
+
+ alignment = cls._get_alignment(area_builder, builder.position.tuple_iter())
+ distance = cls._weighted_distance(distance_to_collector, [(personality.farm_distance_importance, distance_to_farm)], distance_penalty)
+ value = float(Entities.buildings[BUILDINGS.DISTILLERY_CLASS].radius) / distance + alignment * personality.alignment_importance
+ return DistilleryEvaluator(area_builder, builder, value)
+
+ @property
+ def purpose(self):
+ return BUILDING_PURPOSE.DISTILLERY
+
AbstractDistillery.register_buildings()
decorators.bind_all(AbstractDistillery)
+decorators.bind_all(DistilleryEvaluator)
Oops, something went wrong.

0 comments on commit 6109335

Please sign in to comment.