Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

18usa pullman scrapping #7099

Merged
merged 12 commits into from
Feb 23, 2022
Merged

Conversation

ventusignis
Copy link
Collaborator

18USA Pullmans:

  • Can be scrapped any time an owning corporation can act
  • Cannot be bought from the bank during buy_trains, but can be bought from the bank before running
  • A corporation can only own one pullman, owning more than one forces a discard/scrap
  • Do not satisfy the requirement to own a train
  • Count towards train limit
    1:
    image
    2:
    image
    3: Player 2 is acting, so ATSF cannot scrap the pullman
    image
    4:
    image
    5: Over train limit with 2 pullmans, may only discard pullmans
    image
    6: More train limit discard/scrapping
    image
    7: Can scrap a pullman as a corporate SR action
    image
    8:
    image

@ventusignis ventusignis requested a review from crericha February 11, 2022 20:43
lib/engine/game/base.rb Outdated Show resolved Hide resolved
lib/engine/game/base.rb Outdated Show resolved Hide resolved
@ventusignis ventusignis force-pushed the 18usa-pullman-scrapping branch from cfdd92c to 98f33f1 Compare February 13, 2022 22:18
h(:h3, 'Trains to Scrap'),
h(:div, div_props, scrap_trains(scrappable_trains)),
])
if @game.use_compact_scrap_trains_view
Copy link
Collaborator

@crericha crericha Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This choice may vary from step to step. For example, buy_train may want to show the entire scrap train display. Can you add the method to the step instead?

I also recommend calling it something like scrap_train_button_only?.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's now called from the step, I've added the method to the steps in the games that use it instead of the base step

lib/engine/game/base.rb Outdated Show resolved Hide resolved
actions
end

def can_scrap_train?(entity)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use a module, so you don't have to duplicate these methods between here and the scrap_train step?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since can_scrap_train? is the same between buy_sell_par_shares and scrap_train I pulled it into the scrap_train_module but process_scrap_train is slightly different between the two (one calls scrap_train_by_owner, the other calls scrap_train_by_corporation)

@ventusignis ventusignis force-pushed the 18usa-pullman-scrapping branch 5 times, most recently from b546bf5 to a2ac460 Compare February 21, 2022 12:31
@@ -35,7 +35,9 @@ def render
h(:div, trains),
])
end

overflow << h(ScrapTrains, corporation: @current_entity) if @game.round.actions_for(
@game.round.active_step&.current_entity
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

active_step is assigned to step above. Can you use that instead of triggering active_step again?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this block

end

def render_button(scrappable_trains)
step = @game.round.step_for(@corporation, 'scrap_train')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section is a duplicate of line 53 and on. Can you break out into a method both call?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to do it


scrappable_trains = step.scrappable_trains(@corporation)
return nil if scrappable_trains.empty?

if step.scrap_trains_button_only?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use step.respond_to?(:scrap_trains_button_only?) && step.scrap_trains_button_only?, so the other games aren't required to implement the method?

Then you can remove the method from all the other games and not require future games to implement it either.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed this and the related files

@@ -47,6 +47,10 @@ def process_scrap_train(action)
@game.scrap_train(action.train, action.entity)
end

def scrap_trains_button_only?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove from here and other games as per the comment in the scrap_trains view file

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@game.bank.spend(pullman_scrap_value, train.owner)
@game.log << "#{train.owner.name} scraps a pullman for #{@game.format_currency(pullman_scrap_value)}"
@game.depot.reclaim_train(train)
@game.reset_crowded_corps
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this action? In the discard_train step, the reclaim_train action is all that process_discard_train does. Why is this different?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some testing and digging and depot.reclaim_train() invokes @game.remove_train() which clears the @crowded_corps cache so this method is unnecessary so I'm removing it.
I added it originally so that the "have to discard one of two pullmans" case doesn't prevent the subsequent "still over train limit" scenario from triggering

end

def can_scrap_train?(entity)
return false unless entity
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a nice trick here is return false unless entity&.corporation? It will handle both cases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@ventusignis ventusignis force-pushed the 18usa-pullman-scrapping branch 2 times, most recently from cd5e07a to 74d1ce8 Compare February 22, 2022 18:25
@ventusignis ventusignis force-pushed the 18usa-pullman-scrapping branch from 74d1ce8 to aad8f2c Compare February 23, 2022 02:46
@crericha crericha merged commit 3d6e237 into tobymao:master Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants