Commit Description:
Fix code style.
Commit Description:
Fix code style.
Show/Diff file:
Action:
isometric-park-fna/Engines/Spawners/GameSpawner.cs
143 lines | 5.1 KiB | text/x-csharp | CSharpLexer
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using isometricparkfna.Messages;
using isometricparkfna.Components;
using static isometricparkfna.CellMap;
using isometricparkfna.UI;
using Encompass;
using TraceryNet;
namespace isometricparkfna.Spawners {
[Receives(typeof(SpawnGameMessage))]
[Sends(typeof(SpawnContractMessage),
typeof(SpawnOrganizationtMessage),
typeof(ToggleWindowMessage),
typeof(SpawnDialogMessage))]
[Writes(typeof(WindowTypeComponent)
//, typeof(DialogComponent)
)]
class GameSpawner : Spawner<SpawnGameMessage>
{
private Simulation simulation;
Random random_generator;
FNAGame game;
Grammar grammar;
public GameSpawner(Simulation simulation, FNAGame game, Grammar grammar)
{
this.simulation = simulation;
this.random_generator = new Random();
this.game = game;
this.grammar = grammar;
}
protected override void Spawn(in SpawnGameMessage message)
{
#region generate_trees
foreach (List<Cell> row in this.simulation.map.cells)
{
foreach (Cell cell in row)
{
if (this.random_generator.NextDouble() > 0.75)
{
int random_year = (int)MathHelper.Clamp((float)MathUtils.NextNormal(random_generator, 2010.0f, 40.0f), 1800, Simulation.START_YEAR);
int random_month = random_generator.Next(1, 13);
DateTime random_date = new DateTime(random_year, random_month, 1);
int random_type = random_generator.Next(0, 4);
cell.AddTree(random_date, (TreeType)random_type);
}
}
}
#endregion
#region create_contracts
var area = CreateEntity();
var size = 5;
var squares = new Vector2[size * size];
var start_x = 10;
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
squares[i * size + j] = new Vector2(i + start_x, j);
}
}
SendMessage(new SpawnContractMessage
{
squares = squares,
name = "Northshore Logging"
});
SendMessage(new SpawnContractMessage
{
name = "Aeres Maximalis Ltd."
});
#endregion
#region create_organizations
for (int i = 0; i < 3; i++)
{
SendMessage(new SpawnOrganizationtMessage { offersContracts = true,
name = "#family_company.capitalizeAll#",
description = "#family_company_description#",
type = OrganizationType.Family
});
SendMessage(new SpawnOrganizationtMessage { offersContracts = true,
name = "#large_company.capitalizeAll#",
description = "#large_company_description#",
type = OrganizationType.LargeCorporation
});
}
SendMessage(new SpawnOrganizationtMessage { offersContracts = true,
name = "#logging_company.capitalizeAll#",
description = "#company_description#"
});
SendMessage(new SpawnOrganizationtMessage { offersContracts = true,
name = "#coop_company.capitalizeAll#",
description = "#coop_company_description#",
type = OrganizationType.Cooperative
});
SendMessage(new SpawnOrganizationtMessage { offersContracts = true,
name = "#coop_company.capitalizeAll#",
description = "#coop_company_description#",
type = OrganizationType.Cooperative
});
#endregion
#region dialog
SendMessage(new SpawnDialogMessage { Path = "IntroGovernor"});
// SendMessage(new SpawnDialogMessage { Path = "Once"});
SendMessage(new SpawnDialogMessage { Path = "IntroAssistant"});
#endregion
this.simulation.Subsidy = message.Difficulty switch {
DifficultyLevel.Hard => 0M,
DifficultyLevel.Medium => 12_550M,
DifficultyLevel.Easy => 15_000M,
_ => 1000M
};
this.simulation.SubsidyDelta = message.Difficulty switch {
DifficultyLevel.Hard => 0M,
DifficultyLevel.Medium => -50M,
DifficultyLevel.Easy => 0M,
_ => 1000M
};
Logging.Success("Spawned new game.");
}
}
}