summaryrefslogtreecommitdiffstats
path: root/lib/colonial_twilight/actions/fln/rally.rb
blob: c9ed4895417665fe493704e0b72318460cf5f4c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# frozen_string_literal: true

require_relative 'fln_action'
require_relative 'agitate'

module ColonialTwilight
  module Actions
    module FLN
      # Rally 3.3.1
      class Rally < FlnAction
        def initialize(space, mode)
          super(space, mode)
          @agitate = nil
        end

        def cost
          super + (@agitate.nil? ? 0 : @agitate.cost)
        end

        def validate!
          super
          raise 'select 1 mode' if mode.keys.size != 1
          raise 'flip all Guerrillas' if mode.key?(:underground) && mode[:underground] != space.fln_active
        end

        # France track: shift 1 level toward "F"
        # in space place 1 underground Guerrilla, or replace 2 Guerrillas with 1 Base
        # or in space with FLN Base: add underground Guerrillas equal to population + Bases,
        # or flip all Guerrillas underground
        def apply!(board)
          raise NotImplementedError
        end

        def agitate!(mode)
          raise 'agitate! called twice' unless @agitate.nil?

          @agitate = Agitate.new(@data[:space], mode)
          self
        end

        class << self
          def op?
            true
          end

          # Sectors, Cities not at Support, Independent Countries, France track
          def applicable?(space)
            return space.name == 'France track' && !space.max? if space.track?

            space.sector? || (space.city? && !space.support?) || (space.country? && space.independent?)
          end

          def available_modes(space)
            modes = { place_guerilla: 1 }
            modes[:place_base] = 1 if space.guerrillas > 1 && space.bases < space.max_bases
            unless space.fln_bases.zero?
              modes[:place_guerilla] = space.fln_bases + space.pop
              modes[:underground] = space.fln_active if space.fln_active.positive?
            end
            modes
          end
        end
      end
    end
  end
end