def prepare_actions(self, obs):
    """Keep a list of the past actions so they can be drawn."""
    now = time.time()
    while self._past_actions and self._past_actions[0].deadline < now:
      self._past_actions.pop(0)

    def add_act(ability_id, color, pos, timeout=1):
      if ability_id:
        ability = self._static_data.abilities[ability_id]
        if ability.remaps_to_ability_id:  # Prefer general abilities.
          ability_id = ability.remaps_to_ability_id
      self._past_actions.append(
          PastAction(ability_id, color, pos, now, now + timeout))

    for act in obs.actions:
      if (act.HasField("action_raw") and
          act.action_raw.HasField("unit_command") and
          act.action_raw.unit_command.HasField("target_world_space_pos")):
        pos = point.Point.build(
            act.action_raw.unit_command.target_world_space_pos)
        add_act(act.action_raw.unit_command.ability_id, colors.yellow, pos)
      if act.HasField("action_feature_layer"):
        act_fl = act.action_feature_layer
        if act_fl.HasField("unit_command"):
          if act_fl.unit_command.HasField("target_screen_coord"):
            pos = self._world_to_feature_screen_px.back_pt(
                point.Point.build(act_fl.unit_command.target_screen_coord))
            add_act(act_fl.unit_command.ability_id, colors.cyan, pos)
          elif act_fl.unit_command.HasField("target_minimap_coord"):
            pos = self._world_to_feature_minimap_px.back_pt(
                point.Point.build(act_fl.unit_command.target_minimap_coord))
            add_act(act_fl.unit_command.ability_id, colors.cyan, pos)
          else:
            add_act(act_fl.unit_command.ability_id, None, None)
        if (act_fl.HasField("unit_selection_point") and
            act_fl.unit_selection_point.HasField("selection_screen_coord")):
          pos = self._world_to_feature_screen_px.back_pt(point.Point.build(
              act_fl.unit_selection_point.selection_screen_coord))
          add_act(None, colors.cyan, pos)
        if act_fl.HasField("unit_selection_rect"):
          for r in act_fl.unit_selection_rect.selection_screen_coord:
            rect = point.Rect(
                self._world_to_feature_screen_px.back_pt(
                    point.Point.build(r.p0)),
                self._world_to_feature_screen_px.back_pt(
                    point.Point.build(r.p1)))
            add_act(None, colors.cyan, rect, 0.3)
      if act.HasField("action_render"):
        act_rgb = act.action_render
        if act_rgb.HasField("unit_command"):
          if act_rgb.unit_command.HasField("target_screen_coord"):
            pos = self._world_to_rgb_screen_px.back_pt(
                point.Point.build(act_rgb.unit_command.target_screen_coord))
            add_act(act_rgb.unit_command.ability_id, colors.red, pos)
          elif act_rgb.unit_command.HasField("target_minimap_coord"):
            pos = self._world_to_rgb_minimap_px.back_pt(
                point.Point.build(act_rgb.unit_command.target_minimap_coord))
            add_act(act_rgb.unit_command.ability_id, colors.red, pos)
          else:
            add_act(act_rgb.unit_command.ability_id, None, None)
        if (act_rgb.HasField("unit_selection_point") and
            act_rgb.unit_selection_point.HasField("selection_screen_coord")):
          pos = self._world_to_rgb_screen_px.back_pt(point.Point.build(
              act_rgb.unit_selection_point.selection_screen_coord))
          add_act(None, colors.red, pos)
        if act_rgb.HasField("unit_selection_rect"):
          for r in act_rgb.unit_selection_rect.selection_screen_coord:
            rect = point.Rect(
                self._world_to_rgb_screen_px.back_pt(
                    point.Point.build(r.p0)),
                self._world_to_rgb_screen_px.back_pt(
                    point.Point.build(r.p1)))
            add_act(None, colors.red, rect, 0.3)
Keep a list of the past actions so they can be drawn.