summaryrefslogtreecommitdiffstats
path: root/lib/colonial_twilight/deck.rb
blob: 747cb2ffea0e24dac2a2c4860a30f42854190233 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#! /usr/bin/env ruby
# frozen_string_literal: true

# rubocop:disable Style/Documentation

require 'colonial_twilight/card_attributes'
module ColonialTwilight
  class Card
    include ColonialTwilight::CardAttributes

    attr_reader :num, :title

    def set(num)
      raise "card #{num} is out of range [1; #{MAX_CARD_NUM}]" if !num.positive? || num > MAX_CARD_NUM

      @num = num
      card = ColonialTwilight::CardAttributes.cards[num] || [nil, nil]
      @title = card[0]
      @attributes = card[1]
      self
    end

    def propaganda?
      @num >= 67
    end

    def dual?
      (@attributes & SINGLE).zero?
    end

    def single?
      (@attributes & SINGLE) == SINGLE
    end

    def fln_marked?
      (@attributes & FLN_MARKED) == FLN_MARKED
    end

    def special?
      (@attributes & FLN_SPECIAL) == FLN_SPECIAL
    end

    def fln_capability?
      (@attributes & FLN_CAPABILITY) == FLN_CAPABILITY
    end

    def gov_capability?
      (@attributes & GOV_CAPABILITY) == GOV_CAPABILITY
    end

    def dual_capability?
      (@attributes & DUAL_CAPABILITY) == DUAL_CAPABILITY
    end

    def fln_momentum?
      (@attributes & FLN_MOMENTUM) == FLN_MOMENTUM
    end

    def gov_momentum?
      (@attributes & GOV_MOMENTUM) == GOV_MOMENTUM
    end

    def dual_momentum?
      (@attributes & DUAL_MOMENTUM) == DUAL_MOMENTUM
    end

    def fln_effective?
      # FIXME: todo
      false
    end

    def fln_effectiveness
      # FIXME: todo
      0
    end

    def fln_playable?
      # reduce GOV support or resources or commitment
      # shift France Track toward F
      # place FLN base or increase FLN resources
      false
    end

    def inspect
      s = @num < 10 ? ' ' : ''
      t = title + ' ' * (38 - title.size)
      s += "#{@num} - #{single? ? 'Single' : 'Dual  '} : #{t} : #{_capability} : #{_momentum}"
      s
    end

    def _capability
      s = ''
      s += ' FLN-capability' if fln_capability?
      s += ' GOV-capability' if gov_capability?
      s += 'DUAL-capability' if dual_capability?
      s = ' ' * 15 if s.empty?
      s
    end

    def _momentum
      s = ''
      s += ' FLN-momentum  ' if fln_momentum?
      s += ' GOV-momentum  ' if gov_momentum?
      s += 'DUAL-momentum  ' if dual_momentum?
      s
    end
  end

  # class CardAction
  #   def initialize(txt, cond)
  #     @txt = txt
  #     @condition = cond
  #   end
  # end

  class Deck
    attr_reader :card

    def initialize
      @card = Card.new
    end

    def pull(num)
      @card.set(num)
    end
  end
  # 1.upto(71) { |n| puts Deck.new.pull(n).inspect }
end