-
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 #10100 from philcampeau/1826-updates
[1826] various updates
- Loading branch information
Showing
5 changed files
with
148 additions
and
18 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
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,21 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../../step/base' | ||
require_relative '../../../step/buy_train' | ||
|
||
module Engine | ||
module Game | ||
module G1826 | ||
module Step | ||
class BuyTrain < Engine::Step::BuyTrain | ||
def buyable_trains(entity) | ||
# Can't buy trains from other corporations until phase 6H | ||
return super if @game.phase.status.include?('can_buy_trains') | ||
|
||
super.select(&:from_depot?) | ||
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,29 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../../step/dividend' | ||
require_relative '../../../step/half_pay' | ||
|
||
module Engine | ||
module Game | ||
module G1826 | ||
module Step | ||
class Dividend < Engine::Step::Dividend | ||
DIVIDEND_TYPES = %i[payout half withhold].freeze | ||
include Engine::Step::HalfPay | ||
|
||
def share_price_change(entity, revenue = 0) | ||
price = entity.share_price.price | ||
|
||
if revenue.zero? | ||
{ share_direction: :left, share_times: 1 } | ||
elsif revenue < price | ||
{} | ||
elsif revenue >= price | ||
{ share_direction: :right, share_times: 1 } | ||
end | ||
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,51 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../../step/token' | ||
|
||
module Engine | ||
module Game | ||
module G1826 | ||
module Step | ||
class Token < Engine::Step::Token | ||
def process_place_token(action) | ||
entity = action.entity | ||
token = action.token | ||
city = action.city | ||
hex = city.hex | ||
|
||
if @game.loading | ||
token.price = action.cost | ||
else | ||
# Verify there is a route before spending the time to find the shortest path | ||
check_connected(entity, city, hex) | ||
token.price = token_cost(entity, token, hex) | ||
action.cost = token.price | ||
end | ||
|
||
if token.price > entity.cash | ||
raise GameError, "#{entity.name} has #{@game.format_currency(entity.cash)} and cannot spend " \ | ||
"#{@game.format_currency(token.price)} to lay token" | ||
end | ||
|
||
super(action) | ||
end | ||
|
||
def token_cost(entity, token, hex) | ||
min_distance = 999 | ||
|
||
tokened_hexes = entity.tokens.select(&:used).map(&:hex) | ||
hex.tile.nodes.first&.walk(corporation: entity) do |path, visited_paths, _visited| | ||
min_distance = [min_distance, distance(visited_paths) - 1].min if tokened_hexes.include?(path.nodes&.first&.hex) | ||
end | ||
|
||
token.price * min_distance | ||
end | ||
|
||
def distance(path) | ||
path.keys.map(&:hex).uniq.count | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |