Skip to content

Commit

Permalink
Merge pull request #10192 from michaeljb/1822CA-token-fixes
Browse files Browse the repository at this point in the history
[1822CA] various token fixes
  • Loading branch information
michaeljb authored Jan 27, 2024
2 parents 2e64e81 + 4cfb88f commit 30d9379
Show file tree
Hide file tree
Showing 15 changed files with 548 additions and 83 deletions.
34 changes: 24 additions & 10 deletions assets/app/view/game/part/city.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ class City < Base
4 => [-SLOT_RADIUS, -SLOT_RADIUS],
5 => [0, -43],
6 => [0, -50],
7 => [0, -50],
7 => [0, -52],
8 => [0, -54],
9 => [0, -55],
}.freeze

BIG_CITY_SLOT_RADIUS = {
7 => 22,
8 => 20.5,
9 => 19,
}.freeze

EDGE_CITY_REGIONS = {
Expand Down Expand Up @@ -109,11 +117,19 @@ class City < Base
fill: 'white',
r: 1.5 * SLOT_DIAMETER,
}],
8 => [:circle, {
fill: 'white',
r: 1.5 * SLOT_DIAMETER,
}],
9 => [:circle, {
fill: 'white',
r: 1.5 * SLOT_DIAMETER,
}],
}.freeze

# index corresponds to number of slots in the city
REVENUE_DISPLACEMENT = {
flat: [nil, 42, 67, 65, 67, 0, 0, 72],
flat: [nil, 42, 67, 65, 67, 0, 0, 0, 0, 0],
pointy: [nil, 42, 62, 57],
}.freeze

Expand Down Expand Up @@ -285,19 +301,17 @@ def load_from_tile
end

def render_part
slots = (0..@city.slots(all: true) - 1).zip(@city.tokens + @city.extra_tokens).map do |slot_index, token|
num_slots = @city.slots(all: true)
slot_radius = num_slots > 6 ? BIG_CITY_SLOT_RADIUS[num_slots] : SLOT_RADIUS

slots = (0..(num_slots - 1)).zip(@city.tokens + @city.extra_tokens).map do |slot_index, token|
slot_rotation = (360 / @city.slots(all: true)) * slot_index

# use the rotation on the outer <g> to position the slot, then use
# -rotation on the Slot so its contents are rendered without
# rotation
x, y = CITY_SLOT_POSITION[@city.slots(all: true)]

# handle 7-slot city
if @city.slots(all: true) == 7
x, y = CITY_SLOT_POSITION[1] if slot_index == 6
slot_rotation = (360 / 6) * slot_index
end
revert_angle = render_location[:angle] + slot_rotation
revert_angle -= angle_for_layout unless @edge
h(:g, { attrs: { transform: "rotate(#{slot_rotation})" } }, [
Expand All @@ -307,7 +321,7 @@ def render_part
token: token,
slot_index: slot_index,
extra_token: @city.extra_tokens.include?(token),
radius: SLOT_RADIUS,
radius: slot_radius,
reservation: @city.reservations[slot_index],
tile: @tile,
city_render_location: render_location,
Expand All @@ -318,7 +332,7 @@ def render_part

children = []
children << render_pass if @city.pass?
children << render_box(slots.size) if slots.size.between?(2, 7)
children << render_box(slots.size) if slots.size.between?(2, 9)
children.concat(slots)

if @show_revenue && @city&.paths&.any? && (revenue = render_revenue)
Expand Down
2 changes: 1 addition & 1 deletion assets/app/view/game/part/city_slot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def render_part
children = [h(:circle, attrs: token_attrs)]
children << reservation if @reservation && !@token
children << render_boom if @city&.boom
children << h(Token, token: @token, radius: radius, game: @game) if @token
children << render_slot_icon if @city&.slot_icons&.[](@slot_index)
children << h(Token, token: @token, radius: radius, game: @game) if @token

props = {
on: { click: ->(event) { on_click(event) } },
Expand Down
13 changes: 8 additions & 5 deletions lib/engine/game/g_1822/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,7 @@ def payoff_player_loan(player)
end
end

def place_destination_token(entity, hex, token, city = nil)
def place_destination_token(entity, hex, token, city = nil, log: true)
city ||= destination_city(hex, entity)
city.place_token(entity, token, free: true, check_tokenable: false, cheater: true)
hex.tile.icons.reject! { |icon| icon.name == "#{entity.id}_destination" }
Expand All @@ -1777,7 +1777,7 @@ def place_destination_token(entity, hex, token, city = nil)

@graph.clear

@log << "#{entity.name} places its destination token on #{hex.name}"
@log << "#{entity.name} places its destination token on #{hex.name}" if log
end

def destination_city(hex, _entity)
Expand Down Expand Up @@ -2056,9 +2056,12 @@ def setup_companies
end

def setup_destinations
@destination_hexes = {}
@corporations.each do |c|
next unless c.destination_coordinates

@destination_hexes[c.destination_coordinates] = c

home_hex = hex_by_id(c.coordinates)
ability = Ability::Base.new(
type: 'base',
Expand All @@ -2073,10 +2076,10 @@ def setup_destinations
)
c.add_ability(ability)

c.tokens << Engine::Token.new(c, logo: "../#{c.destination_icon}.svg",
simple_logo: "../#{c.destination_icon}.svg",
c.tokens << Engine::Token.new(c, logo: "#{c.destination_icon}.svg",
simple_logo: "#{c.destination_icon}.svg",
type: :destination)
icon = Part::Icon.new("../#{c.destination_icon}", "#{c.id}_destination", owner: c, loc: c.destination_loc)
icon = Part::Icon.new(c.destination_icon.to_s, "#{c.id}_destination", owner: c, loc: c.destination_loc)
if c.destination_icon_in_city_slot
city, slot = c.destination_icon_in_city_slot
dest_hex.tile.cities[city].slot_icons[slot] = icon
Expand Down
1 change: 0 additions & 1 deletion lib/engine/game/g_1822_ca/entities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1704,7 +1704,6 @@ module Entities
destination_loc: '3.5',
destination_exits: [0, 1, 2, 3, 4, 5],
destination_icon: '1822_ca/ICR_DEST',
destination_icon_in_city_slot: [2, 0],
},
{
sym: 'NTR',
Expand Down
35 changes: 33 additions & 2 deletions lib/engine/game/g_1822_ca/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ def setup_game_specific
@sawmill_owner = nil

block_detroit_duluth

@pending_destination_tokens = []

@destinated = Hash.new(false)
end

# setup_companies from 1822 has too much 1822-specific stuff that doesn't apply to this game
Expand Down Expand Up @@ -790,12 +794,14 @@ def preprocess_action(action)
old_tile = hex.tile
new_tile = action.tile

city_map = hex.city_map_for(new_tile)

# transfer destination icons
@city_slot_icons ||= Hash.new { |h, k| h[k] = [] }

if ICONS_IN_CITIES_HEXES.include?(hex.id)

new_tile.rotate!(action.rotation)
city_map = hex.city_map_for(new_tile)

old_tile.cities.each do |city|
next if city.slot_icons.empty?
Expand All @@ -805,12 +811,25 @@ def preprocess_action(action)
end
end
end

return unless @destination_hexes.include?(hex.id)

# pick up "cheater" destination tokens to remove the extra slot, put
# them back down in action_processed() so that after the upgrade
# they use an extra slot onlly if they need it
@pending_destination_tokens = old_tile.cities.each_with_object([]) do |city, tokens|
city.tokens.each do |token|
tokens << [token, city_map[city]] if token&.type == :destination && token.cheater
end
end
@pending_destination_tokens.each { |token, _city| token.remove! }
end
end

def action_processed(action)
case action
when Action::LayTile
# transfer destination icons
unless @city_slot_icons.empty?
@city_slot_icons.each do |new_city, icons|
used_slots = {}
Expand All @@ -826,14 +845,26 @@ def action_processed(action)
end
@city_slot_icons.clear
end

# put down destination tokens that were in extra slots
@pending_destination_tokens.each do |token, city|
place_destination_token(token.corporation, city.hex, token, city, log: false)
end
@pending_destination_tokens.clear
end
end

def place_destination_token(entity, hex, token, city = nil)
def place_destination_token(entity, hex, token, city = nil, log: true)
super

city ||= token.city
city.slot_icons.delete_if { |_, icon| icon.owner == entity }

@destinated[entity] = true
end

def destinated?(entity)
@destinated[entity]
end
end
end
Expand Down
Loading

0 comments on commit 30d9379

Please sign in to comment.