def consume_operation(self, op): if len(op) > 0: arg = op[0] if arg.consume_type == "graze": # The plant should specify how much mass it wants to absorb with each "bite" mass_arg = arg.mass if not mass_arg: print("Graze consume op without mass specified") return server.OPERATION_BLOCKED nourish_ent = Entity() nourish_ent.consume_type = "plant" terrain_prop = self.props.terrain # If there's a terrain prop, check that the surface has dirt, otherwise just return a nourish op if terrain_prop: material = terrain_prop.get_surface_name( arg.pos[0], arg.pos[2]) if material != "grass": # print("Could not graze because there's no grass.") # No earth here return server.OPERATION_BLOCKED else: # Check the slope normal = terrain_prop.get_normal( arg.pos[0], arg.pos[2]) slope = normal.dot(Vector3D(1, 0, 0)) / normal.mag() # The mass received is dependent on the slope nourish_ent.mass = mass_arg * (1 - slope) else: # Just supply the same mass as was requested nourish_ent.mass = mass_arg # Note that we don't change our own status in this version. # Future work might be needed to mark areas as "grazed", but it might not be needed in this level of simulation. nourish_op = Operation("nourish", nourish_ent, to=op.from_) return server.OPERATION_BLOCKED, nourish_op return server.OPERATION_IGNORED
def consume_operation(self, op): if len(op) > 0: arg = op[0] if arg.consume_type == "soil": # The plant should specify how much mass it wants to absorb with each "bite" mass_arg = arg.mass if not mass_arg: print("Plant consume op without mass specified") return server.OPERATION_BLOCKED nourish_ent = Entity() nourish_ent.consume_type = arg.consume_type terrain_prop = self.props.terrain # If there's a terrain prop, check that the surface has dirt, otherwise just return a nourish op if terrain_prop: material = terrain_prop.get_surface_name( arg.pos[0], arg.pos[2]) if material != "grass": # No earth here return server.OPERATION_BLOCKED else: # Check the slope normal = terrain_prop.get_normal( arg.pos[0], arg.pos[2]) slope = normal.dot(Vector3D(1, 0, 0)) / normal.mag() # The mass received is dependent on the slope nourish_ent.mass = mass_arg * (1 - slope) else: # Just supply the same mass as was requested nourish_ent.mass = mass_arg # Note that we don't change our own status; # unlike creatures being "eaten" soil doesn't lose status in this simulation nourish_op = Operation("nourish", nourish_ent, to=op.from_) return server.OPERATION_BLOCKED, nourish_op return server.OPERATION_IGNORED
def open(instance): appear_op = Operation("appearance", to=instance.actor.id) nourish_ent = Entity() # Check if there's a conversion rate for mass->biomass if instance.tool.props.mass and instance.tool.props._consume_mass_conversion: nourish_ent.mass = instance.tool.props.mass * instance.tool.props._consume_mass_conversion if instance.tool.props.consumable_type: nourish_ent.consume_type = instance.tool.props.consumable_type return server.OPERATION_BLOCKED, Operation("nourish", nourish_ent, to=instance.actor), Operation("delete", Entity(instance.tool.id), to=instance.tool)
def consume(instance): # Delete ourselves, and send a Nourish to the eater nourish_ent = Entity() # Check if there's a conversion rate for mass->biomass if instance.tool.props.mass and instance.tool.props._consume_mass_conversion: nourish_ent.mass = instance.tool.props.mass * instance.tool.props._consume_mass_conversion if instance.tool.props.consumable_type: nourish_ent.consume_type = instance.tool.props.consumable_type return server.OPERATION_BLOCKED, \ Operation("nourish", nourish_ent, to=instance.actor), \ Operation("delete", Entity(instance.tool.id), to=instance.tool)