Enable placeable sun deck attractions and finish project rebrand

This commit is contained in:
josh
2026-11-28 20:33:30 -05:00
parent 56fafba6d9
commit ce0d38c8de
352 changed files with 1523 additions and 552 deletions

View File

@@ -0,0 +1,206 @@
using System;
using UnityEngine;
namespace BigShipTycoon
{
public enum SunPoolStyle { Automatic, None, Compact, Family, Resort }
public enum SunPoolShape { Rectangle, Oval }
public enum SunPoolPosition { Midship, Aft, Forward }
public enum SunAttraction { Automatic, None, MiniGolf, Theater, GoKarts, RollerCoaster, Pool }
[Serializable]
public struct SunDeckPlacement
{
public SunAttraction Kind;
public int Column, Row, Rotation;
[SerializeField] internal bool Included;
public SunDeckPlacement(SunAttraction kind, int column, int row, int rotation = 0)
{
Kind = kind;
Column = column;
Row = row;
Rotation = rotation;
Included = false;
}
}
[Serializable]
public struct SunDeckPlan
{
public SunPoolStyle Pool;
public SunPoolShape Shape;
public SunPoolPosition Position;
public SunAttraction Attraction;
public bool NoShade, ExtraLoungers;
public bool CustomLayout;
public SunDeckPlacement[] Placements;
internal int Code
{
get
{
int code = (int)Pool | (int)Shape << 3 | (int)Position << 4 | (int)Attraction << 6
| (NoShade ? 1 << 9 : 0) | (ExtraLoungers ? 1 << 10 : 0) | (CustomLayout ? 1 << 11 : 0);
if (CustomLayout && Placements != null)
foreach (SunDeckPlacement item in Placements)
code = unchecked(code * 109 + ((int)item.Kind | item.Rotation << 3 | item.Row << 5 | item.Column << 9));
return code;
}
}
internal static int PoolPriceFor(SunPoolStyle pool) => pool switch
{
SunPoolStyle.Compact => 9500, SunPoolStyle.Family => 21000, SunPoolStyle.Resort => 59000, _ => 0
};
internal static int AttractionPrice(SunAttraction kind) => kind switch
{
SunAttraction.MiniGolf => 16000, SunAttraction.Theater => 36000, SunAttraction.GoKarts => 62000,
SunAttraction.RollerCoaster => 145000, _ => 0
};
private static int PoolAdmissions(SunPoolStyle pool) => pool switch
{
SunPoolStyle.Compact => 42, SunPoolStyle.Family => 86, SunPoolStyle.Resort => 172, _ => 0
};
private static int AttractionAdmissions(SunAttraction kind) => kind switch
{
SunAttraction.MiniGolf => 52, SunAttraction.GoKarts => 78, SunAttraction.RollerCoaster => 124, _ => 0
};
internal int AddedAmenities => CustomLayout ? AddedCapacity(false) : PoolAdmissions(Pool) + AttractionAdmissions(Attraction);
internal int AddedShows => CustomLayout ? AddedCapacity(true) : Attraction == SunAttraction.Theater ? 110 : 0;
private int AddedCapacity(bool shows)
{
int count = 0;
if (Placements != null)
foreach (SunDeckPlacement item in Placements)
{
if (item.Included)
continue;
count += shows ? item.Kind == SunAttraction.Theater ? 110 : 0
: item.Kind == SunAttraction.Pool ? PoolAdmissions(Pool) : AttractionAdmissions(item.Kind);
}
return count;
}
internal bool ValidOptions(int hull) => (uint)Pool <= (uint)SunPoolStyle.Resort && (uint)Shape <= (uint)SunPoolShape.Oval
&& (uint)Position <= (uint)SunPoolPosition.Forward && (uint)Attraction <= (uint)SunAttraction.RollerCoaster
&& (Pool != SunPoolStyle.Resort || hull >= Market.Regional) && hull >= RequiredHull(Attraction);
internal static int RequiredHull(SunAttraction attraction) => attraction switch
{
SunAttraction.Theater or SunAttraction.GoKarts => Market.Regional,
SunAttraction.RollerCoaster => Market.Ocean,
_ => 0
};
}
public sealed partial class Ship
{
[SerializeField] private SunDeckPlan sunDeckPlan;
public SunDeckPlan SunDeckPlan => sunDeckPlan;
internal int SunDeckPlanCode => sunDeckPlan.Code;
internal bool HasValidSunDeckPlan => sunDeckPlan.ValidOptions(HullIndex)
&& (!sunDeckPlan.CustomLayout || new SunDeckGrid(this).Valid(sunDeckPlan));
internal void SetSunDeckPlan(SunDeckPlan plan) => sunDeckPlan = plan;
}
public sealed partial class Company
{
internal static int SunDeckCost(Ship ship, SunDeckPlan next)
{
SunDeckPlan current = ship.SunDeckPlan;
if (current.CustomLayout || next.CustomLayout)
{
var grid = new SunDeckGrid(ship);
if (grid.PoolIndex < 0 || next.Pool == grid.SelectedPool)
return 0;
int priorPrice = grid.Existing[grid.PoolIndex].Included ? 0 : SunDeckPlan.PoolPriceFor(grid.SelectedPool);
return Math.Max(0, SunDeckPlan.PoolPriceFor(next.Pool) - priorPrice);
}
int pool = Math.Max(0, SunDeckPlan.PoolPriceFor(next.Pool) - SunDeckPlan.PoolPriceFor(current.Pool));
int attraction = next.Attraction == current.Attraction ? 0
: Math.Max(0, SunDeckPlan.AttractionPrice(next.Attraction) - SunDeckPlan.AttractionPrice(current.Attraction) / 4);
return pool + attraction;
}
public string ChangeSunDeck(Ship ship, SunDeckPlan next)
{
if (ship == null || !Fleet.Contains(ship))
return "Choose a ship from your fleet.";
if (!next.ValidOptions(ship.HullIndex))
return "This fitting requires a larger hull.";
int cost = SunDeckCost(ship, next);
var grid = new SunDeckGrid(ship);
if (ship.SunDeckPlan.CustomLayout || next.CustomLayout)
{
int pool = grid.PoolIndex;
if (next.Pool is SunPoolStyle.None or SunPoolStyle.Automatic)
next.Pool = grid.SelectedPool;
next = grid.Customize(next);
if (pool >= 0 && next.Pool != grid.SelectedPool)
next.Placements[pool].Included = false;
if (!grid.Valid(next))
return "The new pool footprint needs more room. Move or turn the pool first.";
}
if (AvailableCash < cost)
return $"The company needs ${cost:N0} available for this refit.";
Cash -= cost;
ship.SetSunDeckPlan(next);
return null;
}
internal static int SunDeckPlacementPrice(Ship ship, SunDeckPlacement placement, int replacing = -1)
{
if (replacing >= 0)
return 0;
return placement.Kind == SunAttraction.Pool ? SunDeckPlan.PoolPriceFor(new SunDeckGrid(ship).SelectedPool)
: SunDeckPlan.AttractionPrice(placement.Kind);
}
public string SunDeckPlacementBlock(Ship ship, SunDeckPlacement placement, int replacing = -1)
{
if (ship == null || !Fleet.Contains(ship))
return "Choose a ship from your fleet.";
var grid = new SunDeckGrid(ship);
string block = grid.PlacementBlock(placement, grid.SelectedPool, grid.Existing, replacing);
if (block != null)
return block;
return AvailableCash < SunDeckPlacementPrice(ship, placement, replacing) ? "The company needs more cash." : null;
}
public string PlaceSunDeck(Ship ship, SunDeckPlacement placement, int replacing = -1)
{
string block = SunDeckPlacementBlock(ship, placement, replacing);
if (block != null)
return block;
var grid = new SunDeckGrid(ship);
SunDeckPlan next = grid.Customize(ship.SunDeckPlan, replacing < 0 ? 1 : 0);
int index = replacing < 0 ? next.Placements.Length - 1 : replacing;
placement.Included = replacing >= 0 && next.Placements[index].Included;
next.Placements[index] = placement;
Cash -= SunDeckPlacementPrice(ship, placement, replacing);
ship.SetSunDeckPlan(next);
return null;
}
public string RemoveSunDeck(Ship ship, int index)
{
if (ship == null || !Fleet.Contains(ship))
return "Choose a ship from your fleet.";
var grid = new SunDeckGrid(ship);
if ((uint)index >= (uint)grid.Existing.Count)
return "Select a fitted attraction to remove.";
SunDeckPlan next = grid.Customize(ship.SunDeckPlan, omit: index);
SunDeckPlacement removed = grid.Existing[index];
if (!removed.Included)
Cash += SunDeckPlacementPrice(ship, removed) / 4;
ship.SetSunDeckPlan(next);
return null;
}
}
}