Skip to content

Commit

Permalink
[Core] Add subsidies to dividend step
Browse files Browse the repository at this point in the history
  • Loading branch information
crericha committed Sep 10, 2024
1 parent c367e8d commit 66acf9b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion assets/app/view/game/dividend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def render
@step.respond_to?(:dividend_name) ? @step.dividend_name(type) : type
end

corp_income = option[:corporation] + option[:divs_to_corporation]
corp_income = option[:corporation] + option[:divs_to_corporation] + @step.total_subsidy

direction =
if (new_share_price = entity.share_price) && option[:share_direction]
Expand Down
7 changes: 5 additions & 2 deletions lib/engine/action/run_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
module Engine
module Action
class RunRoutes < Base
attr_reader :routes, :extra_revenue
attr_reader :routes, :extra_revenue, :subsidy

def initialize(entity, routes:, extra_revenue: 0)
def initialize(entity, routes:, extra_revenue: 0, subsidy: 0)
super(entity)
@routes = routes
@extra_revenue = extra_revenue
@subsidy = subsidy
end

def self.h_to_args(h, game)
Expand Down Expand Up @@ -41,6 +42,7 @@ def self.h_to_args(h, game)
{
routes: routes,
extra_revenue: h['extra_revenue'],
subsidy: h['subsidy'],
}
end

Expand All @@ -62,6 +64,7 @@ def args_to_h
{
'routes' => routes,
'extra_revenue' => extra_revenue,
'subsidy' => subsidy,
}
end
end
Expand Down
12 changes: 9 additions & 3 deletions lib/engine/step/dividend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def variable_max
def process_dividend(action)
entity = action.entity
revenue = total_revenue
subsidy = total_subsidy
kind = action.kind.to_sym
payout = dividend_options(entity)[kind]

Expand All @@ -85,9 +86,9 @@ def process_dividend(action)
@round.routes = []
@round.extra_revenue = 0

log_run_payout(entity, kind, revenue, action, payout)
log_run_payout(entity, kind, revenue, subsidy, action, payout)

payout_corporation(payout[:corporation], entity)
payout_corporation(payout[:corporation] + subsidy, entity)

payout_shares(entity, revenue - payout[:corporation]) if payout[:per_share].positive?

Expand All @@ -100,7 +101,7 @@ def payout_corporation(amount, entity)
@game.bank.spend(amount, entity) if amount.positive?
end

def log_run_payout(entity, kind, revenue, action, payout)
def log_run_payout(entity, kind, revenue, subsidy, action, payout)
unless Dividend::DIVIDEND_TYPES.include?(kind)
@log << "#{entity.name} runs for #{@game.format_currency(revenue)} and pays #{action.kind}"
end
Expand All @@ -110,6 +111,7 @@ def log_run_payout(entity, kind, revenue, action, payout)
elsif payout[:per_share].zero?
@log << "#{entity.name} does not run"
end
@log << "#{entity.name} earns subsidy of #{@game.format_currency(subsidy)}" if subsidy.positive?
end

def share_price_change(_entity, revenue)
Expand Down Expand Up @@ -217,6 +219,10 @@ def total_revenue
@game.routes_revenue(routes) + extra_revenue
end

def total_subsidy
@game.routes_subsidy(routes)
end

def rust_obsolete_trains!(entity, log: true)
rusted_trains = entity.trains.select(&:obsolete).each do |train|
@game.rust(train)
Expand Down

0 comments on commit 66acf9b

Please sign in to comment.