Skip to content

Commit

Permalink
Merge pull request #10195 from patrikolesen/18_uruguay_pre_alpha_farms
Browse files Browse the repository at this point in the history
[18Uruguay] farms
  • Loading branch information
michaeljb authored Jan 27, 2024
2 parents 6b7bd21 + 11b748c commit ae6ab40
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 0 deletions.
103 changes: 103 additions & 0 deletions lib/engine/game/g_18_uruguay/farm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# frozen_string_literal: true

module Engine
module Game
module G18Uruguay
module Farm
ACTIONS_WITH_PASS = %w[assign pass].freeze
ACTIONS_WITHOUT_PASS = %w[assign].freeze

def setup
@farm_id = nil
end

def farm; end

def goods_type; end

def goods
@game.abilities_ignore_owner(farm, :assign_hexes, time: 'or_start', strict_time: false)
end

def used_this_or?
goods
end

def blocking_for_farm?
return false unless @round.operating?

used_this_or?
end

def actions(_entity)
return [] unless blocking_for_farm?

ACTIONS_WITHOUT_PASS
end

def active_entities
[farm]
end

def active?
blocking_for_farm?
end

def blocks?
active?
end

def neighbor_to_choosen_farm?(farm_id, hex_id)
@game.hex_by_id(farm_id).neighbors.find do |neighbor|
neighbor[1].id == hex_id \
&& neighbor[1].tile.city_towns.size.positive?
end
end

def available_hex(entity, hex)
return unless entity.company?
return true if !@farm_id.nil? && neighbor_to_choosen_farm?(@farm_id, hex.id)
# Is it mine?
return unless entity.abilities[0].hexes&.include?(hex.id)
# Do we have goods?
return false if !@farm_id.nil? || !hex.assignments.keys.find { |a| a.include? goods_type }

@game.hex_by_id(hex.id).neighbors.keys
end

def retreive_goods!(farm_id)
hex = @game.hex_by_id(farm_id)
good = hex.assignments.keys.find { |a| a.include? 'GOODS' }
good + goods.count.to_s
end

def process_assign(action)
if @farm_id.nil?
@farm_id = action.target.id
return
end
target = action.target
good = retreive_goods!(@farm_id)

target.assign!(good)

if (ability = goods)
ability.use!
@log <<
"Goods has been delivered to #{target.name}"
end
@round.start_operating
end

def process_pass(action)
raise GameError, "Not #{action.entity.name}'s turn: #{action.to_h}" unless action.entity == @farm

if (ability = goods)
ability.use!
end
pass!
end
end
end
end
end
41 changes: 41 additions & 0 deletions lib/engine/game/g_18_uruguay/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,47 @@ def after_buy_company(player, company, _price)
end
end
end

def operating_round(round_num)
Round::Operating.new(self, [
Engine::Step::Bankrupt,
Engine::Step::Exchange,
G18Uruguay::Step::CornFarm,
G18Uruguay::Step::SheepFarm,
G18Uruguay::Step::CattleFarm,
Engine::Step::SpecialTrack,
Engine::Step::SpecialToken,
Engine::Step::HomeToken,
Engine::Step::Track,
Engine::Step::Token,
Engine::Step::Route,
Engine::Step::Dividend,
Engine::Step::DiscardTrain,
Engine::Step::BuyTrain,
], round_num: round_num)
end

def abilities_ignore_owner(entity, type = nil, time: nil, on_phase: nil, passive_ok: nil, strict_time: nil)
return nil unless entity

active_abilities = entity.all_abilities.select do |ability|
ability_right_type?(ability, type) &&
ability_usable_this_or?(ability) &&
ability_right_time?(ability,
time,
on_phase,
passive_ok.nil? ? true : passive_ok,
strict_time.nil? ? true : strict_time) &&
ability_usable?(ability)
end

active_abilities.each { |a| yield a, a.owner } if block_given?

return nil if active_abilities.empty?
return active_abilities.first if active_abilities.one?

active_abilities
end
end
end
end
Expand Down
27 changes: 27 additions & 0 deletions lib/engine/game/g_18_uruguay/step/cattle_farm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require_relative '../../../step/assign'

module Engine
module Game
module G18Uruguay
module Step
class CattleFarm < Engine::Step::Assign
include Farm

def farm
@game.cattle_farm
end

def goods_type
'GOODS_CATTLE'
end

def description
'Deliver cattle'
end
end
end
end
end
end
27 changes: 27 additions & 0 deletions lib/engine/game/g_18_uruguay/step/corn_farm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require_relative '../../../step/assign'

module Engine
module Game
module G18Uruguay
module Step
class CornFarm < Engine::Step::Assign
include Farm

def farm
@game.corn_farm
end

def goods_type
'GOODS_CORN'
end

def description
'Deliver corn'
end
end
end
end
end
end
27 changes: 27 additions & 0 deletions lib/engine/game/g_18_uruguay/step/sheep_farm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require_relative '../../../step/assign'

module Engine
module Game
module G18Uruguay
module Step
class SheepFarm < Engine::Step::Assign
include Farm

def farm
@game.sheep_farm
end

def goods_type
'GOODS_SHEEP'
end

def description
'Deliver sheep'
end
end
end
end
end
end

0 comments on commit ae6ab40

Please sign in to comment.