def action(current_ticks): entities.remove_pending_action(entity, action) blob = create_blob(world, entities.get_name(entity) + " -- blob", entities.get_position(entity), entities.get_rate(entity) // BLOB_RATE_SCALE, current_ticks, i_store) remove_entity(world, entity) worldmodel.add_entity(world, blob) return [entities.get_position(blob)]
def action(current_ticks): entities.remove_pending_action(entity, action) blob = world.create_blob(world, entities.get_name(entity) + " -- blob", entities.get_position(entity), entities.get_rate(entity), current_ticks, i_store) remove_entity(world, entity) add_entity(world, blob) return [entities.get_position(blob)]
def miner_to_ore(world, entity, ore): entity_pt = entities.get_position(entity) if not ore: return ([entity_pt], False) ore_pt = entities.get_position(ore) if adjacent(entity_pt, ore_pt): entities.set_resource_count(entity, 1 + entities.get_resource_count(entity)) remove_entity(world, ore) return ([ore_pt], True) else: new_pt = next_position(world, entity_pt, ore_pt) return (worldmodel.move_entity(world, entity, new_pt), False)
def miner_to_smith(world, entity, smith): entity_pt = entities.get_position(entity) if not smith: return ([entity_pt], False) smith_pt = entities.get_position(smith) if adjacent(entity_pt, smith_pt): entities.set_resource_count(smith, entities.get_resource_count(smith) + entities.get_resource_count(entity)) entities.set_resource_count(entity, 0) return ([], True) else: new_pt = next_position(world, entity_pt, smith_pt) return (worldmodel.move_entity(world, entity, new_pt), False)
def blob_to_vein(world, entity, vein): entity_pt = entities.get_position(entity) if not vein: return ([entity_pt], False) vein_pt = entities.get_position(vein) if adjacent(entity_pt, vein_pt): remove_entity(world, vein) return ([vein_pt], True) else: new_pt = blob_next_position(world, entity_pt, vein_pt) old_entity = worldmodel.get_tile_occupant(world, new_pt) if isinstance(old_entity, entities.Ore): remove_entity(world, old_entity) return (worldmodel.move_entity(world, entity, new_pt), False)
def try_transform_miner_full(world, entity): new_entity = entities.MinerNotFull( entities.get_name(entity), entities.get_resource_limit(entity), entities.get_position(entity), entities.get_rate(entity), entities.get_images(entity), entities.get_animation_rate(entity)) return new_entity
def add_entity(world, entity): pt = entities.get_position(entity) if within_bounds(world, pt): old_entity = occ_grid.get_cell(world.occupancy, pt) if old_entity != None: entities.clear_pending_actions(old_entity) occ_grid.set_cell(world.occupancy, pt, entity) world.entities.append(entity)
def add_entity(self, entity): pt = entities.get_position(entity) if self.within_bounds(pt): old_entity = self.occupancy.occ_grid.get_cell(pt) if old_entity != None: entities.clear_pending_actions(old_entity) self.occupancy.occ_grid.set_cell(pt, entity) self.entities.append(entity)
def try_transform_miner(world, entity, transform): new_entity = transform(world, entity) if entity != new_entity: world.clear_pending_actions(world, entity) remove_entity_at(world, entities.get_position(entity)) add_entity(world, new_entity) world.schedule_animation(world, new_entity) return new_entity
def try_transform_miner_not_full(world, entity): if entity.resource_count < entity.resource_limit: return entity else: new_entity = entities.MinerFull( entities.get_name(entity), entities.get_resource_limit(entity), entities.get_position(entity), entities.get_rate(entity), entities.get_images(entity), entities.get_animation_rate(entity)) return new_entity
def action(current_ticks): entities.remove_pending_action(entity, action) entities.next_image(entity) if repeat_count != 1: schedule_action(world, entity, entity.create_animation_action(world, entity, max(repeat_count - 1, 0)), current_ticks + entities.get_animation_rate(entity)) return [entities.get_position(entity)]
def move_entity(self, entity, pt): tiles = [] if self.within_bounds(pt): old_pt = entities.get_position(entity) self.occupancy.occ_grid.set_cell(old_pt, None) tiles.append(old_pt) self.occupancy.occ_grid.set_cell(pt, entity) tiles.append(pt) entities.set_position(entity, pt) return tiles
def move_entity(world, entity, pt): tiles = [] if within_bounds(world, pt): old_pt = entities.get_position(entity) occ_grid.set_cell(world.occupancy, old_pt, None) tiles.append(old_pt) occ_grid.set_cell(world.occupancy, pt, entity) tiles.append(pt) entities.set_position(entity, pt) return tiles
def action(current_ticks): entities.remove_pending_action(entity, action) entities.next_image(entity) if repeat_count != 1: schedule_action( world, entity, entity.create_animation_action(world, entity, max(repeat_count - 1, 0)), current_ticks + entities.get_animation_rate(entity)) return [entities.get_position(entity)]
def action(current_ticks): entities.remove_pending_action(entity, action) entity_pt = entities.get_position(entity) smith = worldmodel.find_nearest(world, entity_pt, entities.Blacksmith) (tiles, found) = miner_to_smith(world, entity, smith) new_entity = entity if found: new_entity = try_transform_miner(world, entity, try_transform_miner_full) schedule_action(world, new_entity, create_miner_action(world, new_entity, i_store), current_ticks + entities.get_rate(new_entity)) return tiles
def action(current_ticks): entities.remove_pending_action(entity, action) entity_pt = entities.get_position(entity) smith = find_nearest(world, entity_pt, entities.Blacksmith) (tiles, found) = entity.miner_to_smith(world, entity, smith) new_entity = entity if found: new_entity = world.try_transform_miner(world, entity, world.try_transform_miner_full) schedule_action(world, new_entity, world.create_miner_action(world, new_entity, i_store), current_ticks + entities.get_rate(new_entity)) return tiles
def action(current_ticks): entities.remove_pending_action(entity, action) entity_pt = entities.get_position(entity) ore = worldmodel.find_nearest(world, entity_pt, entities.Ore) (tiles, found) = miner_to_ore(world, entity, ore) new_entity = entity if found: new_entity = try_transform_miner(world, entity, try_transform_miner_not_full) schedule_action(world, new_entity, create_miner_action(world, new_entity, i_store), current_ticks + entities.get_rate(new_entity)) return tiles
def action(current_ticks): entities.remove_pending_action(entity, action) entity_pt = entities.get_position(entity) ore = find_nearest(world, entity_pt, entities.Ore) (tiles, found) = entity.miner_to_ore(world, entity, ore) new_entity = entity if found: new_entity = world.try_transform_miner( world, entity, world.try_transform_miner_not_full) schedule_action( world, new_entity, world.create_miner_action(world, new_entity, i_store), current_ticks + entities.get_rate(new_entity)) return tiles
def action(current_ticks): entities.remove_pending_action(entity, action) entity_pt = entities.get_position(entity) vein = worldmodel.find_nearest(world, entity_pt, entities.Vein) (tiles, found) = blob_to_vein(world, entity, vein) next_time = current_ticks + entities.get_rate(entity) if found: quake = create_quake(world, tiles[0], current_ticks, i_store) worldmodel.add_entity(world, quake) next_time = current_ticks + entities.get_rate(entity) * 2 schedule_action(world, entity, create_ore_blob_action(world, entity, i_store), next_time) return tiles
def action(current_ticks): entities.remove_pending_action(entity, action) open_pt = find_open_around(world, entities.get_position(entity), entities.get_resource_distance(entity)) if open_pt: ore = create_ore( world, "ore - " + entities.get_name(entity) + " - " + str(current_ticks), open_pt, current_ticks, i_store) worldmodel.add_entity(world, ore) tiles = [open_pt] else: tiles = [] schedule_action(world, entity, create_vein_action(world, entity, i_store), current_ticks + entities.get_rate(entity)) return tiles
def action(current_ticks): entities.remove_pending_action(entity, action) entity_pt = entities.get_position(entity) vein = find_nearest(world, entity_pt, entities.Vein) (tiles, found) = entity.blob_to_vein(world, entity, vein) next_time = current_ticks + entities.get_rate(entity) if found: quake = world.create_quake(world, tiles[0], current_ticks, i_store) add_entity(world, quake) next_time = current_ticks + entities.get_rate(entity) * 2 schedule_action(world, entity, world.create_ore_blob_action(world, entity, i_store), next_time) return tiles
def action(current_ticks): entities.remove_pending_action(entity, action) open_pt = world.find_open_around(world, entities.get_position(entity), entities.get_resource_distance(entity)) if open_pt: ore = world.create_ore(world, "ore - " + entities.get_name(entity) + " - " + str(current_ticks), open_pt, current_ticks, i_store) add_entity(world, ore) tiles = [open_pt] else: tiles = [] schedule_action(world, entity, world.create_vein_action(world, entity, i_store), current_ticks + entities.get_rate(entity)) return tiles
def action(current_ticks): entities.remove_pending_action(entity, action) pt = entities.get_position(entity) remove_entity(world, entity) return [pt]
def remove_entity(self, entity): self.remove_entity_at(entities.get_position(entity))
def remove_entity(world, entity): remove_entity_at(world, entities.get_position(entity))
def find_nearest(world, pt, type): oftype = [(e, distance_sq(pt, entities.get_position(e))) for e in world.entities if isinstance(e, type)] return nearest_entity(oftype)