Infrastruttura: nome «Rail Enterprise», CI e rilasci su Gitea, documentazione
Il progetto adotta il nome «Rail Enterprise» ovunque (codice RailEnterprise.*, variabili RE_*, intestazioni RESV/RECL, immagine rail-enterprise-server) per allinearsi al repository Gitea. Aggiunge Gitea Actions sul modello di Chronos: CI su PR e main, rilascio da tag con gioco Windows (client Godot + server in server/), server Windows/Linux e immagine Docker nel registro Gitea, nightly. Aggiunge i riferimenti visivi 06–09, i modelli di PR e issue, l'ADR 0014 e aggiorna README (comandi locali), STATE e CLAUDE.md. 120 test verdi. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f6c2a17b4d
commit
c1a0049bcf
300 files changed
+1602
-1045
No files matched your search
@@ -0,0 +1,71 @@
|
||||
using RailEnterprise.Core.Common;
|
||||
|
||||
namespace RailEnterprise.Core.Economy;
|
||||
|
||||
/// <summary>Titolare di un conto nel registro a partita doppia.</summary>
|
||||
public enum AccountKind : byte { External = 0, Company = 1, Industry = 2 }
|
||||
|
||||
/// <summary>Conto: il resto del mondo, una compagnia o un'industria.</summary>
|
||||
public readonly record struct Account(AccountKind Kind, int Index)
|
||||
{
|
||||
public static readonly Account External = new(AccountKind.External, 0);
|
||||
public static Account Of(CompanyId id) => new(AccountKind.Company, id.Value);
|
||||
public static Account Of(IndustryId id) => new(AccountKind.Industry, id.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registro a partita doppia: ogni movimento è un trasferimento tra due conti, quindi la
|
||||
/// somma di tutti i saldi (compagnie, industrie e conto Esterno) resta sempre zero.
|
||||
/// Il conto Esterno rappresenta salari pagati alle famiglie, clienti delle tariffe e mercato mondiale.
|
||||
/// </summary>
|
||||
public sealed class MoneyLedger(Func<CompanyId, Company> companies, Func<IndustryId, Industry> industries)
|
||||
{
|
||||
/// <summary>Saldo del conto Esterno.</summary>
|
||||
public Money External { get; set; }
|
||||
|
||||
/// <summary>Totale trasferito dall'inizio (statistica).</summary>
|
||||
public long TransfersCount { get; internal set; }
|
||||
|
||||
public void Transfer(Account from, Account to, Money amount, LedgerEntry entry)
|
||||
{
|
||||
if (amount.Cents == 0 || from == to) return;
|
||||
Adjust(from, -amount, entry);
|
||||
Adjust(to, amount, entry);
|
||||
TransfersCount++;
|
||||
}
|
||||
|
||||
private void Adjust(Account account, Money delta, LedgerEntry entry)
|
||||
{
|
||||
switch (account.Kind)
|
||||
{
|
||||
case AccountKind.External:
|
||||
External += delta;
|
||||
break;
|
||||
case AccountKind.Company:
|
||||
var c = companies(new CompanyId(account.Index));
|
||||
c.Cash += delta;
|
||||
c.MonthEntries[(int)entry] += delta.Cents;
|
||||
c.YearEntries[(int)entry] += delta.Cents;
|
||||
break;
|
||||
case AccountKind.Industry:
|
||||
var i = industries(new IndustryId(account.Index));
|
||||
i.Cash += delta;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contatori dei flussi di merci per bene: la giacenza totale nel mondo deve valere
|
||||
/// prodotto + importato − consumato − deperito − esportato (invariante «nessun bene dal nulla»).
|
||||
/// </summary>
|
||||
public sealed class GoodsCounters(int goodCount)
|
||||
{
|
||||
public long[] Produced { get; } = new long[goodCount];
|
||||
public long[] Consumed { get; } = new long[goodCount];
|
||||
public long[] Decayed { get; } = new long[goodCount];
|
||||
public long[] Imported { get; } = new long[goodCount];
|
||||
public long[] Exported { get; } = new long[goodCount];
|
||||
|
||||
public long ExpectedStock(int good) => Produced[good] + Imported[good] - Consumed[good] - Decayed[good] - Exported[good];
|
||||
}
|
||||
Reference in new issue
Block a user