public static bool HasTax(char type, SpaceTradersModule module) { KMBombInfo bombInfo = module.BombInfo; switch (type) { case '-': return(false); case 'X': return(true); case 'B': return(bombInfo.GetBatteryCount() < 4); case 'P': return(!bombInfo.IsPortPresent(Port.Serial) && !bombInfo.IsPortPresent(Port.Parallel)); case 'I': return(bombInfo.GetIndicators().Count() % 2 == 0); case 'S': return(bombInfo.GetSerialNumberNumbers().Count() == 2); case 'T': return(module.startingMinutes % 2 == 1); case 'M': return(bombInfo.GetModuleIDs().Count() % 2 == 1); case 'R': return(module.remainingMinutesCount % 2 == 1); case 'C': return(bombInfo.GetSolvedModuleIDs().Count() % 2 == 0); case 'E': return(bombInfo.GetStrikes() == 0); case 'F': return(bombInfo.GetTwoFactorCodes().Any((code) => code % 2 == 0)); default: throw new UnityException(string.Format("Unknown system code {0}", (int)type)); } }
public static bool HasTaxOnGeneration(MapGenerator.CellStar star, char type, SpaceTradersModule module) { if (type == 'R') { return(false); } if (type == 'F') { return(module.BombInfo.IsTwoFactorPresent()); } if (type == 'C' || type == 'E') { return(true); } return(HasTaxAt(star, module)); }
public static void GenerateMaxTaxAndGoodsToSoldCount( HashSet <CellStar> starsSet, SpaceTradersModule module, out int maxTax, out int goodsToBeSoldCount ) { CellStar[] stars = starsSet.Where((cell) => cell.edge).ToArray(); int[] maxPathsTaxes = stars.Select((s) => ( s.path.Where((p) => StarData.HasTaxOnGenerationAt(p, module)).Select((p) => p.tax).Sum()) ).ToArray(); System.Array.Sort(maxPathsTaxes); int i = maxPathsTaxes.Length / 2; int _maxTax = maxPathsTaxes[i]; while (_maxTax == maxPathsTaxes[maxPathsTaxes.Length - 1] && i > 0) { _maxTax = maxPathsTaxes[i--]; } maxTax = _maxTax; goodsToBeSoldCount = maxPathsTaxes.Where((tax) => tax <= _maxTax).Count(); if (goodsToBeSoldCount == stars.Count()) { goodsToBeSoldCount -= 1; } }
public static HashSet <CellStar> Generate(SpaceTradersModule module) { HashSet <string> unusedStarNames = new HashSet <string>(StarData.starNames); HashSet <CellStar> result = new HashSet <CellStar>(); Cell[][] grid = new Cell[GRID_WIDHT][]; for (int x = 0; x < GRID_WIDHT; x++) { grid[x] = new int[GRID_HEIGHT].Select((_) => new Cell()).ToArray(); } for (int x = 1; x <= 2; x++) { for (int y = 1; y <= 2; y++) { grid[GRID_WIDHT - x][GRID_HEIGHT - y].status = CellStatus.ADJACENT; } } for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { grid[x][y].status = CellStatus.ADJACENT; } } Vector2Int startPosition = new Vector2Int(Random.Range(3, GRID_WIDHT - 3), Random.Range(3, GRID_HEIGHT - 3)); grid[startPosition.x][startPosition.y].status = CellStatus.CANDIDATE; Vector <Vector2Int> queue = new Vector <Vector2Int>(startPosition); while (queue.length > 0) { Vector2Int pos = queue.RemoveRandom(); Cell cell = grid[pos.x][pos.y]; if (cell.status != CellStatus.CANDIDATE) { continue; } cell.status = CellStatus.STAR; foreach (Vector2Int adjacentCell in ADJACENT_CELLS.Select((diff) => pos + diff)) { if (!IsOnTheGrid(adjacentCell)) { continue; } grid[adjacentCell.x][adjacentCell.y].status = CellStatus.ADJACENT; } Vector <CellStar> adjacentStars = new Vector <CellStar>(); foreach (Vector2Int hypercorridorCell in HYPERCORRIDOR_CELLS.Select((diff) => pos + diff)) { if (!IsOnTheGrid(hypercorridorCell)) { continue; } Cell hyperCell = grid[hypercorridorCell.x][hypercorridorCell.y]; if (hyperCell.status == CellStatus.STAR) { adjacentStars.Append(hyperCell.star); } if (hyperCell.status != CellStatus.EMPTY) { continue; } hyperCell.status = CellStatus.CANDIDATE; queue.Append(hypercorridorCell); } cell.star = new CellStar(pos, unusedStarNames.PickRandom()); result.Add(cell.star); unusedStarNames.Remove(cell.star.name); if (adjacentStars.length == 0) { continue; } CellStar adjacentStar = adjacentStars.RemoveRandom(); cell.star.adjacentStars.Add(adjacentStar); adjacentStar.adjacentStars.Add(cell.star); cell.star.path = new List <CellStar>(adjacentStar.path); cell.star.path.Add(cell.star); } CellStar sun = grid[startPosition.x][startPosition.y].star; sun.name = SUN_NAME; sun.race = "Humans"; sun.regime = "Democracy"; MarkEdges(result); GenerateTaxes(result); return(result); }
public static bool HasTaxOnGenerationAt(MapGenerator.CellStar star, SpaceTradersModule module) { return(HasTaxOnGeneration(star, GetRaceType(star), module) || HasTaxOnGeneration(star, GetRegimeType(star), module)); }