def move_pressed(self): """ This is called when the move button is pressed. """ # Switch out of move mode if we're already in it. if self.mode == Modes.ChooseMove: self.change_mode(Modes.Select) return # If there is no unit selected, nothing happens. if not self.sel_unit: return # If the unit has already moved nothing happens. elif self.sel_unit.turn_state[0] == True: return # Determine where we can move. pos = (self.sel_unit.tile_x, self.sel_unit.tile_y) # These will be used in pathfinding cost = lambda c: ( self.sel_unit.move_cost(self.map.tile_data(c))) passable = lambda c: ( self.sel_unit.is_passable(self.map.tile_data(c), c)) reachable = tiles.reachable_tiles( self.map, pos, self.sel_unit.speed, cost, passable) # Check that the tiles can actually be stopped in for t_pos in reachable: tile = self.map.tile_data(t_pos) # This can be stopped in, so add it if self.sel_unit.is_stoppable(tile, t_pos): self._movable_tiles.add(t_pos) # Highlight those squares self.map.set_highlight( "move", MOVE_COLOR_A, MOVE_COLOR_B, self._movable_tiles) # Set the current GUI mode self.change_mode(Modes.ChooseMove)
def gather_pressed(self): if self.sel_unit is None or self.sel_unit.type != "Transport" \ or self.sel_unit.team != self.cur_team: return sel_pos = (self.sel_unit.tile_x, self.sel_unit.tile_y) if self.sel_unit.carrying: for nbr in self.map.neighbours(sel_pos): if self.sel_unit.pop_front_unit(self.map.tile_data(nbr), nbr): return else: # These will be used in pathfinding cost = lambda c: (self.sel_unit.move_cost(self.map.tile_data(c))) passable = lambda c: (self.sel_unit.is_passable( self.map.tile_data(c), c)) eligible = list() for u in base_unit.BaseUnit.active_units: if self.sel_unit.can_load(u) and not u.turn_state[0]: reachable = tiles.reachable_tiles(self.map, (u.tile_x, u.tile_y), u.speed, cost, passable) if sel_pos in reachable: eligible.append(u) gathered = gather.gather(self.sel_unit, eligible, lambda u: (u.health)) for u in gathered: tmp = self.sel_unit self.sel_unit = u self.sel_unit_move(sel_pos) self.sel_unit = tmp u.in_transport = self.sel_unit