# -*- coding: utf-8 -*- class Buildings (object): def __init__(self): self.Nexus = [] self.Gateway = [] self.Warpgate = [] def build_self(self, resources, current_time): resources.update_minerals(-self.minerals_cost) resources.update_gas(-self.gas_cost) self.time_left = self.build_time self.last_update_time = current_time def build_item(self, item, resources, current_time): if BuildingId.id2name[self.id] == "Warpgate": # TBI print "Building using Warpgate, special procedures used" item.build(resources) else: self.queue.build(item, current_time) item.build(resources) def have_resources(self, resources): return (resources.get_gas() >= self.gas_cost) and (resources.get_minerals() >= self.minerals_cost) def have_requirements(self, base): for req in self.requires: if req not in base.tech: return False return True def ready(self): return self.queue.ready() def update(self, current_time, base): self.queue.update(current_time, base) def dump(self, offset=""): print "%s%s\t%i Minerals\t%i Gas\t%i build time" % (offset, BuildingId.id2name[self.id], self.minerals_cost, self.gas_cost, self.build_time) self.queue.dump(offset+"\t") def building_finished_building_callback(self, base): base.add_building(self) base.buildings_in_progress.remove(self) class Build_Queue (object): """ Build Queue used by almost all buildings. Note that we don't actually make it a queue (or with depth 1), since it's strictly suboptimal to queue units. """ def __init__(self): self.chrono_boost_time_left = 0 self.cooldown = 0 # for Warpgates only self.queue = [] self.base_time_left = 0.0 self.last_update_time = 0 def ready(self): return (self.cooldown == 0 and not self.queue) def build(self, item, current_time): # print "Building %s" % (item.name) if not self.queue: self.base_time_left = item.build_time self.queue.append(item) self.last_update_time = current_time def update(self, current_time, base): delta_t = current_time - self.last_update_time # Update Cooldowns for Warpgates if(self.cooldown > 0): self.cooldown = self.cooldown - delta_t if(self.cooldown <= 0): self.cooldown = 0 # TODO: It is important to note that Chrono Boost also has the effect of reducing the cooldown time on Warpgates it is cast on. if self.queue: # TODO: Verify that chrono boosting actually works if self.chrono_boost_time_left > 0: self.base_time_left = self.base_time_left - (delta_t * 1.50) else: self.base_time_left = self.base_time_left - delta_t if(self.base_time_left <= 0): # print "Finished %s" % self.queue[0].name self.queue[0].unit_finished_building_callback(base) self.queue = [] # Update remaining Chrono Boost time if active if self.chrono_boost_time_left > 0: self.chrono_boost_time_left = self.chrono_boost_time_left - delta_t if self.chrono_boost_time_left <= 0: self.chrono_boost_time_left = 0 self.last_update_time = current_time def dump(self, offset=""): print "%sBase time to next item: %i\tChrono Boost time left: %i\tCooldown: %i" % (offset, self.base_time_left, self.chrono_boost_time_left, self.cooldown) for item in self.queue: item.dump(offset+"\t") class Pylon (Buildings): __slots__ = () def __init__(self): super(Pylon, self).__init__() self.id = BuildingId.PYLON self.minerals_cost = 100 self.build_time = 25 self.food = 8 self.has_queue = False class Nexus (Buildings): __slots__ = () def __init__(self): super(Nexus, self).__init__() self.id = BuildingId.NEXUS self.minerals_cost = 400 self.build_time = 100 self.food = 10 self.energy = 25 # TEST ONLY, start at 0 class Assimilator (Buildings): __slots__ = () def __init__(self): super(Assimilator, self).__init__() self.id = BuildingId.ASSIMILATOR self.requires = [] # No requirement, but max 2 per nexus is reasonable to use self.minerals_cost = 75 self.build_time = 30 def building_finished_building_callback(self, base): base.add_building(self) base.buildings_in_progress.remove(self) base.gas.update_used_geysers(1) class Forge (Buildings): __slots__ = () def __init__(self): super(Forge, self).__init__() self.id = BuildingId.FORGE self.requires = [BuildingId.NEXUS, BuildingId.PYLON] self.minerals_cost = 150 self.build_time = 45 class Photon_Cannon (Buildings): __slots__ = () def __init__(self): super(Photon_Cannon, self).__init__() self.id = BuildingId.PHOTON_CANNON self.requires = [BuildingId.FORGE, BuildingId.PYLON] self.minerals_cost = 150 self.build_time = 40 class Gateway (Buildings): __slots__ = () def __init__(self): super(Gateway, self).__init__() self.id = BuildingId.GATEWAY self.requires = [BuildingId.NEXUS, BuildingId.PYLON] self.minerals_cost = 150 self.build_time = 65 class Cybernetics_Core (Buildings): __slots__ = () def __init__(self): super(Cybernetics_Core, self).__init__() self.id = BuildingId.CYBERNETICS_CORE self.requires = [BuildingId.GATEWAY, BuildingId.PYLON] self.minerals_cost = 150 self.build_time = 50 class Twilight_Council (Buildings): __slots__ = () def __init__(self): super(Twilight_Council, self).__init__() self.id = BuildingId.TWILIGHT_COUNCIL self.requires = [BuildingId.CYBERNETICS_CORE, BuildingId.PYLON] self.minerals_cost = 150 self.gas_cost = 100 self.build_time = 50 class Dark_Shrine (Buildings): __slots__ = () def __init__(self): super(Dark_Shrine, self).__init__() self.id = BuildingId.DARK_SHRINE self.requires = [BuildingId.TWILIGHT_COUNCIL, BuildingId.PYLON] self.minerals_cost = 100 self.gas_cost = 250 self.build_time = 100 class Robotics_Facility (Buildings): __slots__ = () def __init__(self): super(Robotics_Facility, self).__init__() self.id = BuildingId.ROBOTICS_FACILITY self.requires = [BuildingId.CYBERNETICS_CORE, BuildingId.PYLON] self.minerals_cost = 200 self.gas_cost = 100 self.build_time = 65 class Robotics_Bay (Buildings): __slots__ = () def __init__(self): super(Robotics_Bay, self).__init__() self.id = BuildingId.ROBOTICS_BAY self.requires = [BuildingId.ROBOTICS_FACILITY, BuildingId.PYLON] self.minerals_cost = 200 self.gas_cost = 200 self.build_time = 65 class Stargate (Buildings): __slots__ = () def __init__(self): super(Stargate, self).__init__() self.id = BuildingId.STARGATE self.requires = [BuildingId.CYBERNETICS_CORE, BuildingId.PYLON] self.minerals_cost = 150 self.gas_cost = 150 self.build_time = 60