def update(self,dt): super(Machinery, self).update(dt) if self.active: if not self.recently_active: self.recently_active = True self.refresh_image() #self.set_active() self.operating_time_since_last_maintenance += dt if random.random() < (dt/util.seconds(1,'month'))*self.operating_time_since_last_maintenance/(100*self.wear*self.maintenance_interval): self.broken = True else: if self.recently_active: self.recently_active = False #self.set_active() self.refresh_image() if self.broken: if not self.maint_task or self.maint_task.name != ''.join(['Repair ',self.name]): self.maint_task = Task(''.join(['Repair ',self.name]), owner = self, timeout=None, task_duration = util.seconds(4,'hours'), severity='MODERATE', fetch_location_method=Searcher(self,self.installed.station).search,logger=self.logger) self.installed.station.tasks.add_task(self.maint_task) if self.operating_time_since_last_maintenance >= self.wear*self.maintenance_interval and ( not self.maint_task or self.maint_task.task_ended() ): self.maint_task = Task(''.join(['Maintain ',self.name]), owner = self, timeout=None, task_duration = util.seconds(1,'hours'), severity='LOW', fetch_location_method=Searcher(self,self.installed.station).search,logger=self.logger) #print self.maint_task.timeout,self.maint_task.task_duration self.installed.station.tasks.add_task(self.maint_task)
def update(self,dt): self.player_nasa_funds += dt*self.yearly_budget/util.seconds(1,'year') if self.time_elapsed//util.seconds(1,'year') != (dt+self.time_elapsed)//util.seconds(1,'year'): #we're at a year boundary. Recompute budget self.yearly_update() self.time_elapsed += dt if self.time_elapsed > self.last_module + util.seconds(6,'months') and not self.module_available: self.module_available = True if self.time_elapsed > self.last_resupply + util.seconds(3,'months') and not self.resupply_available: self.resupply_available = True #check vessel queue for active vessel for v in self.vessel_queue: if v.financing <= 0: if v.design <= 0: if v.construction <= 0: if v.launch_prep <= 0: station = self.scenario.add_station(v.station) self.scenario.stations[v.target_id].position_at_safe_distance(v.station) self.vessel_queue.remove(v) if v.autodock: miss_comp, d, d = self.scenario.stations[v.target_id].search( filtering.EquipmentFilter( target='Mission Computer', is_installed=True ) ) modDock = [m for m in v.station.modules.values() if isinstance(m,DragonCargoModule)][0] miss_comp.generate_mission(selection='New Module', target_id = v.station.id, module_id = modDock.id) else: v.launch_prep -= dt else: v.construction -= dt else: v.design -= dt else: v.financing -= dt
def update(self,dt): #Earthside station is only a placeholder, after all global launch_rate launch_rate *= max(0,1 - dt/util.seconds(1,'year') ) #gov't launches keep the cost down if random.random()/10.0 < dt/util.seconds(1,'year'): launch_rate += 1
def next_alert_time(self, rule, name, timestamp): """ Calculate an 'until' time and exponent based on how much past the last 'until' we are. """ if name in self.silence_cache: last_until, exponent = self.silence_cache[name] else: # If this isn't cached, this is the first alert or writeback_es is down, normal realert return timestamp + rule['realert'], 0 if not rule.get('exponential_realert'): return timestamp + rule['realert'], 0 diff = seconds(timestamp - last_until) # Increase exponent if we've alerted recently if diff < seconds(rule['realert']) * 2 ** exponent: exponent += 1 else: # Continue decreasing exponent the longer it's been since the last alert while diff > seconds(rule['realert']) * 2 ** exponent and exponent > 0: diff -= seconds(rule['realert']) * 2 ** exponent exponent -= 1 wait = datetime.timedelta(seconds=seconds(rule['realert']) * 2 ** exponent) if wait >= rule['exponential_realert']: return timestamp + rule['exponential_realert'], exponent - 1 return timestamp + wait, exponent
def __init__(self): if not hasattr(self,'imgfile'): self.imgfile = "images/placeholder_machinery.tif" super(Machinery, self).__init__() self.idle_draw = 0.001 #kW self.maint_timer = random.randrange(util.seconds(6,'months'), util.seconds(2,'years') ) self.maint_task = None self.wear = 1.0 self.broken = False
def __init__(self, station = None, target_station_id=None, autodock = True): self.financing = util.seconds(30,'seconds') self.design = util.seconds(30,'seconds') self.construction = 0#util.seconds(30,'minutes') self.launch_prep = util.seconds(30,'seconds') self.station = station self.target_id = target_station_id self.autodock = autodock
def update(self,secs): asteroid_odds = self.mass / 1E26 if random.random() < (min(secs,util.seconds(1,'day'))/util.seconds(6,'months'))*(asteroid_odds**0.5): #new 'roid angle = math.pi/4 + random.random()*math.pi/4 if random.random() < 0.5: angle *= -1 rad = self.orbit * (0.9 + random.random()*0.2) primloc = self.primary.location orbit_dist = globalvars.M_TO_AU * rad loc = [float(primloc[0] + math.cos(self.orbit_pos+angle)*orbit_dist), \ float(primloc[1] + math.sin(self.orbit_pos+angle)*orbit_dist)] globalvars.map.event_mgr.new(loc,'asteroid')
def __init__(self,**kwargs): self.recipe = [{'Name':'Charging', 'Inputs':{}, 'Outputs':{}, 'Duration':util.seconds(1,'day')}] Module.__init__(self,**kwargs) self.charge = 0 self.charge_rate = 0.0001 self.img_dict['icon']='img/icon/noun-project/brian-oppenlander-arrows.png' self.img_dict['displaysize'] = False
def update(self,dt): self.labor += 1.*dt/util.seconds(1,'day') #print 'Labor',self.labor self.map.deposit_scent('Goblin',self.pos,dt) self.map.deposit_scent('Wealth',self.pos,max(0,self.wealth)*dt/3600.) self.wander(dt) self.myimage.refresh()
def __init__(self,name): globalvars.map.register(self) self.name = name self.amount = 0 self.supply = 1. self.demand = 1. self.price = 1. self.tc = util.seconds(0.5,'day')
def update(self, dt): self.labor += 1. * dt / util.seconds(1, 'day') #print 'Labor',self.labor self.map.deposit_scent('Goblin', self.pos, dt) self.map.deposit_scent('Wealth', self.pos, max(0, self.wealth) * dt / 3600.) self.wander(dt) self.myimage.refresh()
def task_finished(self,task): #TODO add supply usage super(Machinery, self).task_finished(task) if not task: return if task.name == ''.join(['Maintain ',self.name]) and task.target == self: self.maint_task = None self.wear += (1 - self.wear) / 2 self.maint_timer = random.randrange(int (util.seconds(1,'months') * self.wear), int( util.seconds(6,'months') * self.wear ) ) elif task.name == ''.join(['Repair ',self.name]) and task.target == self: self.broken = False self.wear += (1 - self.wear) / 2
def __init__(self): if not hasattr(self,'imgfile'): self.imgfile = "images/docking_computer.tif" super(DockingComputer, self).__init__() self.idle_draw = 0.200 #kW self.docking_mode = 'DOCK' self.docking_item = None #The thing doing the docking or undocking (THEM) self.docking_target = None #The (module,dock) where it will be docking to (US) self.docking_path = None #The path object that will interpolate its journey self.docking_task = None self.docking_duration = util.seconds(2,'minutes') self.name = "Docking console"
def __init__(self): self.active = False super(Machinery, self).__init__() self.idle_draw = 0.001 #kW #self.maint_timer = random.randrange(util.seconds(6,'months'), util.seconds(2,'years') ) self.maint_task = None self.operating_time_since_last_maintenance = 0 self.maintenance_interval = util.seconds(7,'days') self.wear = 1.0 self.broken = False self.recently_active=False self.type = 'MACHINERY'
def __init__(self): Workshop.__init__(self) Rack.__init__(self) self.name = "Machine shop InnaBox" self.local_parts = clutter.Stowage(3) self.reaction_goal = None self.ready_goal = False self.processing_speed = 0.0001 #m3/s self.min_processing_time = util.seconds(15,'minutes') self.batch_progress = 0.0
def run(job,actor,station,duration): #print job, actor.name, station.name, duration if job not in joblist.keys(): return 0.0 new_dur = duration * actor.skill[job] _eff = station.satisfy_reaction(joblist[job],new_dur) #increase skill of actor tc = util.seconds(1,'year') score = -1.0 * math.log(1 - actor.skill[job]) * tc score += duration actor.skill[job] = 1 - math.exp(-score/tc) return _eff
def __init__(self): self.img=random.choice(["images/glitch-assets/element_green/element_green__x1_1_png_1354832187.png", "images/glitch-assets/element_blue/element_blue__x1_1_png_1354832189.png", "images/glitch-assets/element_red/element_red__x1_1_png_1354832185.png", "images/glitch-assets/element_shiny/element_shiny__x1_1_png_1354832191.png"]) super(Experiment, self).__init__() self.idle_draw = 0.200 #kW self.raw_unfiltered_SCIENCE = 0.0 self.capacity_for_SCIENCE = random.random()*util.seconds(6,'months') self.no_more_SCIENCE = False self.name = "Experiment" self.field = random.choice(util.universe.science.field.keys()) self.level = util.universe.science.field[self.field].level['Knowledge']
def __init__(self,**kwargs): Module.__init__(self,**kwargs) self.asteroid = None self.capacity = 1E6 # a million kg should be enough for anybody self.throughput = 25000 self.recipe = [{'Name':'Processing Asteroid', 'Inputs': {}, 'Outputs': {}, 'Duration' : util.seconds(1,'hour')}] self.img_dict['icon']='img/icon/noun-project/rob-armes-mining-tools.png' self.img_dict['displaysize'] = False
def new_dinner_task(self,timeout,severity): t=Task(''.join(['Satisfy Food']), owner = self, timeout=timeout, task_duration = util.seconds(30,'minutes'), severity=severity, fetch_location_method = Searcher(ClutterFilter('Edible Food',check_storage=True),self.station).search) return t
def __init__(self,**kwargs): Reactor.__init__(self,**kwargs) self.power_supplied = 2 self.recipe =[ {'Name':'Operating', 'Inputs':{'Charged Phlebotinum': 1}, 'Outputs':{'Depleted Phlebotinum':1}, 'Duration':util.seconds(1,'day')}]
def __init__(self,**kwargs): self.name = 'Module' self.ship = kwargs['ship'] self.ship.register(self) self.ship.crew_use[self.id] = 0 self.room = kwargs['room'] if 'room' in kwargs else None #super(Module, self).__init__(**kwargs) self.size = all_modules[type(self).__name__]['Size'] if type(self).__name__ in all_modules else 1 self.power_needed = all_modules[type(self).__name__]['Power'] if type(self).__name__ in all_modules else 0 self.crew_needed = all_modules[type(self).__name__]['Crew'] if type(self).__name__ in all_modules else 0 self.crew = 0 self.crewed = False self.active = False self.toggled = True self.storage = {} if not hasattr(self, 'recipe'): self.recipe = [] self.condition = 1.0 self.maint_reqr = False self.img_dict = {'icon':'img/icon/modules/blank.png', 'sizeloc': [0,0], 'statusloc':[0,0], 'displaysize':True, 'icon color':[0.8,0.8,0.8,1.0]} if not hasattr(self,'idle_activity'): self.idle_activity = {'Name':'Idle', 'Inputs':{}, 'Outputs':{}, 'Duration':util.seconds(1,'hour')} self.activity = self.idle_activity.copy() self.status = 'Module Rebooting...' self.color= [0.5, 0.5, 0.5, 1.0] self.full_activity = {'Name':'Waiting for storage', 'Inputs':{}, 'Outputs':{}, 'Duration':util.seconds(1,'hour')} self.image=None self.module_image()
def __init__(self,**kwargs): Reactor.__init__(self,**kwargs) self.power_supplied = 3 self.recipe = [{'Name':'Operating', 'Inputs':{}, 'Outputs':{}, 'Duration':util.seconds(1,'day')}, {'Name':'Charging', 'Inputs':{'Depleted Phlebotinum': 1}, 'Outputs':{'Charged Phlebotinum': 1}, 'Duration':util.seconds(1,'day')}] self.img_dict['icon']='img/icon/noun-project/ryan-lerch-three-prong-outlet.png'
def __init__(self,**kwargs): self.idle_activity = {'Name':'Beeping Noise', 'Inputs':{}, 'Outputs':{}, 'Duration':util.seconds(1,'hour')} Module.__init__(self,**kwargs) self.active_sens = 100 self.passive_sens = 25 self.img_dict['icon']='img/icon/noun-project/andrejs-kirma-antenna.png' self.img_dict['displaysize'] = False
def update(self,dt): super(Machinery, self).update(dt) if self.broken: if not self.maint_task or self.maint_task.name != ''.join(['Repair ',self.name]): self.maint_task = Task(''.join(['Repair ',self.name]), owner = self, timeout=util.seconds(1,'months'), task_duration = util.seconds(4,'hours'), severity='MODERATE', fetch_location_method=Searcher(self,self.installed.station).search,logger=self.logger) self.installed.station.tasks.add_task(self.maint_task) if self.maint_timer < 0 and ( not self.maint_task or self.maint_task.task_ended() ): self.maint_task = Task(''.join(['Maintain ',self.name]), owner = self, timeout=util.seconds(1,'months'), task_duration = util.seconds(1,'hours'), severity='LOW', fetch_location_method=Searcher(self,self.installed.station).search,logger=self.logger) #print self.maint_task.timeout,self.maint_task.task_duration self.installed.station.tasks.add_task(self.maint_task) self.maint_timer -= dt
def __init__(self,**kwargs): Module.__init__(self,**kwargs) '''self.recipe = [{'Name':'Smelt Metal', 'Inputs': {'Metallics':5000}, 'Outputs': {'Metals':2500,'Slag':2500}, 'Duration' : util.seconds(1,'hour')}, {'Name':'Reclaim Slag', 'Inputs': {'Slag':5000}, 'Outputs': {'Metallics':1000,'Silicates':3000,'Reactives':1000}, 'Duration' : util.seconds(1,'hour')}, {'Name':'Purify Silicon', 'Inputs': {'Silicates':5000, 'Carbon':1600, 'Oxygen':2133}, 'Outputs': {'Silicon':1866,'Reactives':1000,'Carbon Dioxide':5866}, 'Duration' : util.seconds(1,'hour')}]''' self.recipe = [{'Name':'Smelt Duralloy', 'Inputs': {'Ore':1000,'Crystal':500}, 'Outputs': {'Duralloy':1500}, 'Duration' : util.seconds(1,'hour')}] self.img_dict['icon']='img/icon/noun-project/icon54-factory-chimney.png' self.img_dict['displaysize'] = False
def __init__(self,**kwargs): Module.__init__(self,**kwargs) self.multiplier = 1000 self.recipe = [{'Name':'Grow Crops', 'Inputs': {}, 'Outputs': {'Goods':1.*self.multiplier}, 'Duration' : util.seconds(1,'hour')}] #{'Name':'Grow baby grow', 'Inputs': {'Organics':1.*self.multiplier,'Water':0.9*self.multiplier,'Carbon Dioxide':1.1*self.multiplier}, 'Outputs': {'Oxygen':0.8*self.multiplier, 'Biomass':1.3*self.multiplier, 'Organics':0.9*self.multiplier}, 'Duration' : util.seconds(1,'hour')}] #{'Name':'Compost Organics', 'Inputs': {'Organics':100,'Water':10}, 'Outputs': {'Fertilizer':10,'Carbon Dioxide':10}, 'Duration' : util.seconds(1,'hour')}] self.biomass = 0 self.capacity = 1000 self.img_dict['icon']='img/icon/noun-project/arthur-shlain-birch-leaf.png' self.img_dict['displaysize'] = False self.img_dict['icon color'] = [0.6,1.0,0.6,1.0]
def update(self,dt): super(Experiment, self).update(dt) if self.no_more_SCIENCE or self.installed is None or not self.powered: return if not (self.task and self.task.active): self.raw_unfiltered_SCIENCE += dt if self.raw_unfiltered_SCIENCE >= self.capacity_for_SCIENCE: self.no_more_SCIENCE = True if (not self.task or not self.task.active) and random.random() < 0.00005*dt: sev = random.random() if sev < 0.99: self.task = Task('Science: '+random.choice(['push buttons','twiddle knobs','record numbers','adjust display','tweak results']), owner = self, timeout=None, task_duration = util.seconds(20,'minutes'), severity='MODERATE', fetch_location_method=Searcher(self,self.installed.station).search,logger=self.logger) else: self.task = Task(''.join(['Science: extinguish fire!']), owner = self, timeout=util.seconds(30,'minutes'), task_duration = util.seconds(5,'minutes'), severity='HIGH', fetch_location_method=Searcher(self,self.installed.station).search,logger=self.logger) self.installed.station.tasks.add_task(self.task)
def update(self, secs): timeslice = min(1.,secs/util.seconds(1, 'day')) if self.active and self.activity['Name'] != 'Idle': self.color = [0.3, 0.5, 1.0, 1.0] elif self.crewed and not self.maint_reqr: self.color = [0.4, 0.4, 0.2, 1.0] elif self.maint_reqr: self.color = [1.0, 0.5, 0.2, 1.0] else: self.color= [0.5, 0.5, 0.5, 1.0] self.active = False self.ship.demand(self.id,'Power',0) if not self.toggled: self.status = 'Mothballed' return #print self.crew_needed, self.ship.crew_use[self.id], self.ship.crew_available(3, 0) if self.ship.crew_available(self.crew_needed, offset=self.ship.crew_use[self.id]): self.ship.crew_use[self.id] = self.crew_needed self.crewed = True else: self.ship.crew_use[self.id] = 0 self.crewed = False #check repair if self.maint_reqr: #crew have a chance to repair if self.crewed and random.random() < timeslice: #TODO scale with condition - crappy modules take longer to repair self.maint_reqr = False if self.maint_reqr: self.status = 'Offline: Maint' return if not self.crewed: self.status = 'Idling: Need Crew' return if self.activity['Name'] not in ['Idle','Waiting for storage'] and self.activity['Duration'] > 0: self.active = True self.activity['Duration'] -= secs self.status = 'Operational' self.ship.demand(self.id,'Power', self.power_needed) if self.activity['Duration'] <= 0: #end job self.finish_job() else: #idle self.status = 'Idling' self.ship.demand(self.id,'Power', 0) self.active = False if self.active: #reduced crew have a chance for something to break if random.random() < 0.03 * timeslice: #TODO scale with condition - poor modules break more often self.maint_reqr = True else: #pick a new activity #check if we can power up if random.random() > self.ship.demand(self.id, 'Power', self.power_needed): self.status = 'Idling: Low Power' self.activity = self.idle_activity.copy() return #check recipes random.shuffle(self.recipe) for r in self.recipe: begin = self.check_job(r) if begin: self.start_job(r) else: self.activity = self.idle_activity.copy() if len(self.recipe ) == 0: self.activity = self.idle_activity.copy() self.status = 'Ready'#self.activity['Name']
def update(self,secs): for b in self.asteroid_belts: if random.random() < (secs/util.seconds(6,'months')): self.spawn_belt_roid(b)