-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10195 from patrikolesen/18_uruguay_pre_alpha_farms
[18Uruguay] farms
- Loading branch information
Showing
5 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |