diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/colonial_twilight/board/forces.rb | 28 | ||||
| -rw-r--r-- | lib/colonial_twilight/board/spaces.rb | 28 |
2 files changed, 28 insertions, 28 deletions
diff --git a/lib/colonial_twilight/board/forces.rb b/lib/colonial_twilight/board/forces.rb index ecf27df..b9bd94e 100644 --- a/lib/colonial_twilight/board/forces.rb +++ b/lib/colonial_twilight/board/forces.rb @@ -10,7 +10,7 @@ module ColonialTwilight attr_reader :french_troops, :french_police attr_reader :fln_underground, :fln_active attr_reader :fln_bases, :gov_bases - attr_reader :max_bases, :control + attr_reader :max_bases def initialize(sym) @name = sym @@ -18,7 +18,6 @@ module ColonialTwilight @french_troops, @french_police, @gov_bases = 0, 0, 0 @fln_underground, @fln_active, @fln_bases = 0, 0, 0 @max_bases = nil - @control = :uncontrolled @max_bases = 2 if %i[Country Sector].include?(sym) _variables_to_remove(sym)&.each do |s| instance_variable_set(s, nil) @@ -33,10 +32,10 @@ module ColonialTwilight def _variables_to_remove(sym) case sym - when :available then %i[@control @fln_active] - when :casualties then %i[@control @fln_active @fln_bases] - when :out_of_play then %i[@control @algerian_troops @algerian_police @fln_active @fln_bases] - when :Country then %i[@control @algerian_troops @algerian_police @french_troops @french_police] + when :available then %i[@fln_active] + when :casualties then %i[@fln_active @fln_bases] + when :out_of_play then %i[@algerian_troops @algerian_police @fln_active @fln_bases] + when :Country then %i[@algerian_troops @algerian_police @french_troops @french_police] when :City then nil when :Sector then nil end @@ -59,7 +58,7 @@ module ColonialTwilight def data h = {} %i[algerian_troops algerian_police french_troops french_police gov_bases - fln_underground fln_active fln_bases control].each do |sym| + fln_underground fln_active fln_bases].each do |sym| h[sym] = send(sym) unless send(sym).nil? end h @@ -115,7 +114,6 @@ module ColonialTwilight else raise "unknown force type : #{type}" end - update_control end def activate(num) @@ -135,19 +133,5 @@ module ColonialTwilight @gov_bases += num if type == :gov_bases @fln_bases += num if type == :fln_bases end - - def update_control - return nil if @control.nil? - - ctr = @control - @control = ( - case gov <=> fln - when 0 then :uncontrolled - when 1 then :GOV - when -1 then :FLN - end - ) - @control != ctr - end end end diff --git a/lib/colonial_twilight/board/spaces.rb b/lib/colonial_twilight/board/spaces.rb index fad3170..183a6a2 100644 --- a/lib/colonial_twilight/board/spaces.rb +++ b/lib/colonial_twilight/board/spaces.rb @@ -36,7 +36,7 @@ module ColonialTwilight BORDER = 4 attr_reader :wilaya, :sector, :name, :resettled - attr_accessor :pop, :terror, :adjacents, :alignment + attr_accessor :pop, :terror, :adjacents, :alignment, :control def initialize(name, wilaya, sector, pop, attrs = 0) @name = name @@ -45,6 +45,7 @@ module ColonialTwilight @pop = pop @attrs = attrs @alignment = :neutral + @control = :uncontrolled @resettled = false @terror = 0 @forces = Forces.new self.class.name.split('::')[-1].to_sym @@ -64,6 +65,18 @@ module ColonialTwilight @descr = "(#{@wilaya}-#{@sector})" end + def update_control + ctr = @control + @control = ( + case @forces.gov <=> @forces.fln + when 0 then :uncontrolled + when 1 then :GOV + when -1 then :FLN + end + ) + @control != ctr + end + public def to_s @@ -73,7 +86,7 @@ module ColonialTwilight def inspect "\n#{@descr} : #{@terrain} population : #{@pop}#{@resettled ? ' resettled' : ''} - control : #{control} + control : #{@control} alignment : #{@alignment} terror : #{@terror} #{@forces} @@ -86,7 +99,7 @@ module ColonialTwilight %i[gov gov_bases gov_cubes french_cubes algerian_cubes troops police french_troops french_police algerian_troops algerian_police - fln fln_bases guerrillas fln_underground fln_active max_bases control].each do |sym| + fln fln_bases guerrillas fln_underground fln_active max_bases].each do |sym| define_method(sym) { @forces.send(sym) } end @@ -131,19 +144,20 @@ module ColonialTwilight end def uncontrolled? - control == :uncontrolled + @control == :uncontrolled end def fln_control? - control == :FLN + @control == :FLN end def gov_control? - control == :GOV + @control == :GOV end def add(type, num = 1) @forces.add(type, num) + update_control end def shift_terror(num = 1) @@ -208,6 +222,8 @@ module ColonialTwilight @descr += ' : French' end + def update_control; end + def sector? false end |
