def tick_operation(self, op): res = Oplist() if verify_tick(self, op, res, self.tick_interval): # Default to 1.0 for max scale, unless something is set. max_scale = 1.0 if self.props.maxscale: max_scale = self.props.maxscale if self.props.mass and self.props.density and self.props.bbox and self.props._nutrients and self.props._nutrients > 0: # Use half of the nutrients to grow new_mass = self.props.mass + (self.props._nutrients * 0.5) bbox_unscaled = self.props.bbox volume_vector = bbox_unscaled.high_corner - bbox_unscaled.low_corner volume_unscaled = volume_vector.x * volume_vector.y * volume_vector.z volume_new = new_mass / self.props.density new_scale = min(pow(volume_new / volume_unscaled, 0.33333), max_scale) if not self.props.scale or new_scale != self.props.scale: set_ent = Entity(scale=[new_scale]) # check how much nutrient really was used final_new_mass = new_scale * volume_new * self.props.density set_ent._nutrients = self.props._nutrients - ( final_new_mass - self.props.mass) res += Operation("set", set_ent, to=self) return server.OPERATION_BLOCKED, res return server.OPERATION_IGNORED
def tick_operation(self, op): res = Oplist() if verify_tick(self, op, res, self.tick_interval): # The simple case is that nutrient will only be consumed to fill up status if self.props.status: status = self.props.status nutrients = 0 if self.props._nutrients: nutrients = self.props._nutrients # If no nutrient, we're starving and should decrease status if nutrients <= 0: res += Operation("set", Entity(status=status - 0.01), to=self) else: # Else we'll see if we can increase status by consuming nutrient if status < 1.0: # We need to know the mass to know the mass-to-status ratio if self.props.mass: set_ent = Entity() # Consuming 5% of the total mass as nutrient will increase status from 0 to 1. mass_to_status_ratio = 0.05 # Convert that into actual mass mass_for_full_status = self.props.mass * mass_to_status_ratio # Then we define that we'll only increase status by a certain step each tick status_increase_per_tick = 0.1 # Which gives us the total mass we can consume this tick nutrient_consumed = min( status_increase_per_tick * mass_for_full_status, nutrients) set_ent._nutrients = nutrients - nutrient_consumed set_ent.status = status + (nutrient_consumed / mass_for_full_status) res += Operation("set", set_ent, to=self) return server.OPERATION_BLOCKED, res return server.OPERATION_IGNORED