F6: scheda industria e schermata di connessione definitive
La scheda dell'industria e la schermata di connessione si allineano alle
immagini di riferimento 07 e 09. I dati che mancavano li calcola il Core
con una funzione pura, e viaggiano in blocchi compatibili del protocollo.
Il formato dei salvataggi non cambia (ADR 0021).
- IndustryOutlook calcola la scheda in sola lettura:
- fattori dell'efficienza e quello che la limita;
- ingressi e uscite al mese, con giorni di scorta o di magazzino;
- fornitori e clienti con prezzo, distanza e linea che li collega;
- forza lavoro dai contratti dei pendolari;
- punteggio di crescita del trimestre con le soglie;
- prezzo medio, utile annuo, stazioni che la servono, sblocco
dell'acquisto.
IndustryMath.GrowthScore è ora l'unica formula del punteggio e la usa
anche IndustrySystem: gli hash non cambiano. Nuovi parametri in
balance.json, industry.outlook.
- Protocollo:
- IndustryCard: blocco 1 IndustrySheetInfo;
- Welcome: blocco 1 ServerInfo (versione, sistema, Docker, tempo di
attività, passo del ciclo, client collegati);
- ClientWorld conserva lo stato del server e l'elenco dei salvataggi.
- Client:
- IndustryPanel a tutto schermo, con tre schede, il grafo della
catena, impianti e crescita, e i comandi del proprietario;
- ConnectScreen sostituisce MenuScreen: server locale o in rete,
stato del server, partite salvate, «Connetti e riprendi» e «Nuova
partita sul server» su una sessione di prova;
- testi in strings.csv;
- pilota automatico: schermate 19_scheda_industria e 20_connessione.
- Test:
- IndustryOutlookTests;
- scheda e stato del server via WebSocket;
- campioni del protocollo con i blocchi nuovi.
200 test, 181 senza i lenti.
Refs #42.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7eec322202
commit
45462bf9ec
28 files changed
+2810
-329
No files matched your search
@@ -0,0 +1,279 @@
|
||||
using RailEnterprise.Core.Commands;
|
||||
using RailEnterprise.Core.Common;
|
||||
using RailEnterprise.Core.Data;
|
||||
using RailEnterprise.Core.Economy;
|
||||
using RailEnterprise.Core.Persistence;
|
||||
using RailEnterprise.Core.Rail;
|
||||
using RailEnterprise.Core.Simulation;
|
||||
using RailEnterprise.Core.Simulation.Systems;
|
||||
using RailEnterprise.Protocol;
|
||||
using RailEnterprise.Protocol.Messages;
|
||||
using RailEnterprise.Server;
|
||||
using RailEnterprise.Tests.Harness;
|
||||
using RailEnterprise.Tests.Rail;
|
||||
|
||||
namespace RailEnterprise.Tests.Economy;
|
||||
|
||||
/// <summary>Scheda dell'industria dell'immagine 07 (F6, ADR 0021): catena produttiva, coperture, limite, crescita.</summary>
|
||||
public static class IndustryOutlookTests
|
||||
{
|
||||
private static int GoodIndex(World w, string id) => w.Data.Goods.First(g => g.Id == id).Index;
|
||||
|
||||
/// <summary>Valdoria con la rete merci miniere → acciaieria, un treno sulla linea e 40 giorni di servizio.</summary>
|
||||
private static (RailFixture F, int Line, int MillStation) ServedValdoria()
|
||||
{
|
||||
var f = RailFixture.Valdoria();
|
||||
var (mine, mill, depot) = f.BuildFreightNetwork();
|
||||
int train = f.Train(depot, "Merci 1", ("loco_steam_1850", 1), ("wagon_hopper", 4));
|
||||
int line = f.Ok(new CreateLineCommand("Linea 1", "#e0a526", new[] { new LineStop(new StationId(mine)), new LineStop(new StationId(mill)) }));
|
||||
f.Ok(new AssignTrainCommand(new TrainId(train), new LineId(line)));
|
||||
f.W.RunDays(40);
|
||||
return (f, line, mill);
|
||||
}
|
||||
|
||||
[Test(Description = "Scheda dell'acciaieria di Valdoria: input, output, fornitore collegato dalla linea, clienti, stazione che serve; nessun effetto sul mondo")]
|
||||
public static void SheetOfTheSteelMill()
|
||||
{
|
||||
var (f, line, millStation) = ServedValdoria();
|
||||
var w = f.W;
|
||||
var steel = w.Industries.First(i => i.Def.Id == "steel_mill");
|
||||
ulong hash = StateHasher.Compute(w);
|
||||
var r = IndustryOutlook.Build(w, steel, f.Me);
|
||||
Assert.Equal(hash, StateHasher.Compute(w), "la scheda non cambia il mondo");
|
||||
|
||||
int dpm = w.Calendar.DaysPerMonth;
|
||||
Assert.Equal(steel.Level, r.Level);
|
||||
Assert.Equal(w.Data.Balance.Growth.MaxLevel, r.MaxLevel);
|
||||
Assert.Equal(steel.Efficiency, r.Efficiency);
|
||||
Assert.Equal(steel.Def.StorageDays, r.StorageDays);
|
||||
Assert.Equal(w.Data.Balance.Industry.CoverageWindowDays, r.CoverageWindowDays);
|
||||
|
||||
// input nell'ordine della ricetta: fabbisogno a piena capacità e consumo al ritmo attuale
|
||||
Assert.Equal(2, r.Inputs.Count);
|
||||
int ore = GoodIndex(w, "iron_ore");
|
||||
Assert.Equal(ore, r.Inputs[0].Good);
|
||||
Assert.Equal(GoodIndex(w, "coal"), r.Inputs[1].Good);
|
||||
double cyclesMonth = (double)steel.Def.Capacity(steel.Level) / steel.Def.Recipe.Outputs[0].PerCycle;
|
||||
Assert.Approx(cyclesMonth * 2, r.Inputs[0].FullMonth, 1e-9);
|
||||
Assert.Approx(cyclesMonth * 1, r.Inputs[1].FullMonth, 1e-9);
|
||||
Assert.Approx(r.Inputs[0].FullMonth * steel.Efficiency, r.Inputs[0].CurrentMonth, 1e-9);
|
||||
Assert.Equal(steel.InputStock[0], r.Inputs[0].Stock);
|
||||
Assert.Equal(IndustryMath.InputCapacity(steel, 0, dpm), r.Inputs[0].Storage);
|
||||
|
||||
// output: capacità del livello, produzione al ritmo attuale, magazzino
|
||||
Assert.Equal(1, r.Outputs.Count);
|
||||
Assert.Approx(steel.Def.Capacity(steel.Level), r.Outputs[0].FullMonth, 1e-9);
|
||||
Assert.Approx(r.Outputs[0].FullMonth * steel.Efficiency, r.Outputs[0].CurrentMonth, 1e-9);
|
||||
Assert.Equal(IndustryMath.OutputCapacity(steel, 0, dpm), r.Outputs[0].Storage);
|
||||
if (r.Outputs[0].CurrentMonth > 0)
|
||||
{
|
||||
double perDay = r.Outputs[0].CurrentMonth / dpm;
|
||||
Assert.Approx(Math.Max(0, r.Outputs[0].Storage - r.Outputs[0].Stock) / perDay, r.Outputs[0].Days, 1e-9);
|
||||
}
|
||||
|
||||
// il primo fornitore di minerale è la miniera di Rocca Bruna, collegata dalla linea
|
||||
int perGood = w.Data.Balance.Industry.Outlook.PartnersPerGood;
|
||||
var suppliers = r.Inputs[0].Partners;
|
||||
Assert.True(suppliers.Count is > 0 && suppliers.Count <= perGood, $"fornitori {suppliers.Count}");
|
||||
var mine = w.Industries.First(i => i.Def.Id == "iron_mine");
|
||||
Assert.Equal(ChainPartnerKind.Industry, suppliers[0].Kind);
|
||||
Assert.Equal(mine.Id.Value, suppliers[0].Target);
|
||||
Assert.Equal(line, suppliers[0].Line.Value);
|
||||
Assert.Equal(w.Market.GlobalPrice[ore], suppliers[0].Price);
|
||||
double mineMonth = mine.CyclesPerDayAtFullCapacity(dpm) * dpm * mine.Efficiency;
|
||||
Assert.Approx(mineMonth, suppliers[0].MonthlyUnits, 1e-9);
|
||||
// dopo i collegati, i più vicini
|
||||
for (int i = 1; i < suppliers.Count; i++)
|
||||
{
|
||||
if (suppliers[i - 1].Line.IsValid == suppliers[i].Line.IsValid)
|
||||
Assert.True(suppliers[i - 1].DistanceKm <= suppliers[i].DistanceKm, "ordinati per distanza");
|
||||
else Assert.True(suppliers[i - 1].Line.IsValid, "prima i collegati");
|
||||
}
|
||||
|
||||
// clienti dell'acciaio: la fabbrica di attrezzi al prezzo locale dell'ADR 0004 e il porto, non collegati
|
||||
var customers = r.Outputs[0].Partners;
|
||||
Assert.True(customers.Count is > 0 && customers.Count <= perGood, $"clienti {customers.Count}");
|
||||
Assert.True(customers.All(c => !c.Line.IsValid), "nessun cliente collegato");
|
||||
var tools = w.Industries.First(i => i.Def.Id == "tool_factory");
|
||||
var toolsEntry = customers.FirstOrDefault(c => c.Kind == ChainPartnerKind.Industry && c.Target == tools.Id.Value);
|
||||
Assert.True(toolsEntry.Kind == ChainPartnerKind.Industry && toolsEntry.Target == tools.Id.Value, "la fabbrica di attrezzi compra acciaio");
|
||||
int steelGood = GoodIndex(w, "steel");
|
||||
int slot = tools.InputIndexOf(steelGood);
|
||||
double local = Market.LocalPrice(w.Market.GlobalPrice[steelGood], IndustryMath.InputCapacity(tools, slot, dpm), tools.InputStock[slot], w.Data.Balance.LocalPrice);
|
||||
Assert.Equal(local, toolsEntry.Price);
|
||||
if (customers.FirstOrDefault(c => c.Kind == ChainPartnerKind.Hub) is { Kind: ChainPartnerKind.Hub } port)
|
||||
Assert.Equal(w.Hubs[port.Target].BuyPrice(w.Market.GlobalPrice[steelGood]), port.Price);
|
||||
|
||||
// servita dalla stazione dell'acciaieria con la linea della compagnia
|
||||
Assert.True(r.ServingStations.Contains(new StationId(millStation)), "stazione dell'acciaieria");
|
||||
Assert.Equal(line, r.ServingLine.Value);
|
||||
// per un'altra compagnia nessuna linea collega
|
||||
var other = IndustryOutlook.Build(w, steel, CompanyId.None);
|
||||
Assert.False(other.ServingLine.IsValid);
|
||||
Assert.True(other.Inputs[0].Partners.All(p => !p.Line.IsValid), "senza compagnia nessun collegamento");
|
||||
|
||||
// crescita: punteggio del trimestre dalla stessa funzione della crescita trimestrale
|
||||
var g = w.Data.Balance.Growth;
|
||||
Assert.Equal(IndustryMath.GrowthScore(steel, g), r.Growth.Current);
|
||||
Assert.Equal(g.UpgradeThreshold, r.Growth.UpgradeThreshold);
|
||||
Assert.Equal(g.DowngradeThreshold, r.Growth.DowngradeThreshold);
|
||||
Assert.Equal(steel.QuarterDays, r.Growth.QuarterDay);
|
||||
Assert.Equal(g.QuarterDays, r.Growth.QuarterDays);
|
||||
Assert.True(r.Growth.Served, "servita da un vettore");
|
||||
|
||||
// acquisto: dei privati, livello e avanzamento dai dati (ADR 0018)
|
||||
var tier = w.Data.Tiers.Tiers.First(t => t.Unlocks.BuyIndustry);
|
||||
Assert.True(r.ForSale);
|
||||
Assert.False(r.BuyUnlocked);
|
||||
Assert.Equal(tier.Level, r.BuyTier);
|
||||
Assert.Approx(ClimbOutlook.Requirements(w, w.Player, tier).Progress, r.BuyProgress, 1e-12);
|
||||
Assert.Approx(IndustryMath.AnnualProfit(w, steel), r.AnnualProfit.Cents, 1);
|
||||
}
|
||||
|
||||
[Test(Description = "Forza lavoro della scheda: presenti, quota in sede, posti scoperti e provenienze dai contratti di pendolarismo")]
|
||||
public static void WorkforceComesFromTheCommuteContracts()
|
||||
{
|
||||
var (f, _, _) = ServedValdoria();
|
||||
var w = f.W;
|
||||
var ib = w.Data.Balance.Industry;
|
||||
foreach (var ind in w.Industries.Where(i => !i.Closed))
|
||||
{
|
||||
foreach (var cls in new[] { PaxClass.Worker, PaxClass.Staff })
|
||||
{
|
||||
var o = IndustryOutlook.Workforce(w, ind, cls);
|
||||
bool staff = cls == PaxClass.Staff;
|
||||
int jobs = staff ? ind.JobsStaff : ind.JobsWorkers;
|
||||
double present = staff ? ind.StaffPresent : ind.WorkersPresent;
|
||||
Assert.Equal(jobs, o.Jobs);
|
||||
Assert.Equal(present, o.Present);
|
||||
Assert.Approx(jobs * (staff ? ib.OnSiteStaffShare : ib.OnSiteWorkerShare), o.OnSite, 1e-9);
|
||||
Assert.Equal((int)Math.Max(0, Math.Round(jobs - present, MidpointRounding.AwayFromZero)), o.Missing);
|
||||
var contracts = w.Commutes.Where(c => c.Workplace == WorkplaceRef.Of(ind.Id) && c.Category == cls && c.Headcount > 0).ToList();
|
||||
Assert.True(o.Sources.Count <= ib.Outlook.WorkforceSources && o.Sources.Count <= o.SourceCount, "provenienze entro il limite");
|
||||
if (o.SourceCount <= ib.Outlook.WorkforceSources)
|
||||
Assert.Equal(contracts.Sum(c => c.Headcount), o.Sources.Sum(s => s.Headcount));
|
||||
for (int i = 1; i < o.Sources.Count; i++) Assert.True(o.Sources[i - 1].Headcount >= o.Sources[i].Headcount, "dalle più numerose");
|
||||
var rail = contracts.Where(c => !c.Walking).ToList();
|
||||
if (rail.Count == 0) Assert.Equal(-1.0, o.AverageMinutes);
|
||||
else Assert.Approx(rail.Sum(c => c.ExpectedMinutes * c.Headcount) / rail.Sum(c => c.Headcount), o.AverageMinutes, 1e-9);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test(Description = "Il limite dell'efficienza è il fattore più basso sotto 1; fermo e livello 0 hanno la precedenza")]
|
||||
public static void LimitIsTheLowestFactor()
|
||||
{
|
||||
var f = RailFixture.Valdoria();
|
||||
var w = f.W;
|
||||
w.RunDays(2);
|
||||
var steel = w.Industries.First(i => i.Def.Id == "steel_mill");
|
||||
var m = w.Data.Balance.IndustryMaintenance;
|
||||
|
||||
steel.CovInput = 1;
|
||||
steel.CovWorkers = 1;
|
||||
steel.CovStaff = 1;
|
||||
steel.RevenueEma = 100;
|
||||
steel.CostEma = 100;
|
||||
steel.Condition = 100;
|
||||
Assert.Equal(IndustryLimit.None, IndustryOutlook.Factors(w, steel).Limit);
|
||||
|
||||
steel.CovStaff = 0.4;
|
||||
steel.CovWorkers = 0.6;
|
||||
Assert.Equal(IndustryLimit.Staff, IndustryOutlook.Factors(w, steel).Limit);
|
||||
steel.CovInput = 0.3;
|
||||
Assert.Equal(IndustryLimit.Inputs, IndustryOutlook.Factors(w, steel).Limit);
|
||||
|
||||
// impianti sotto il 20 %: mc al minimo, sotto le coperture
|
||||
steel.CovInput = 0.9;
|
||||
steel.Condition = 10;
|
||||
var factors = IndustryOutlook.Factors(w, steel);
|
||||
Assert.Equal(m.EfficiencyBelow20, factors.ConditionMultiplier);
|
||||
Assert.Equal(m.EfficiencyBelow20 < 0.4 ? IndustryLimit.Condition : IndustryLimit.Staff, factors.Limit);
|
||||
|
||||
// margine negativo: fattore di profitto sotto 1
|
||||
steel.Condition = 100;
|
||||
steel.CovStaff = 1;
|
||||
steel.CovWorkers = 1;
|
||||
steel.CovInput = 1;
|
||||
steel.RevenueEma = 0;
|
||||
steel.CostEma = 100;
|
||||
Assert.Equal(IndustryLimit.Profit, IndustryOutlook.Factors(w, steel).Limit);
|
||||
Assert.Equal(IndustryMath.ProfitFactor(steel, w.Data.Balance.Industry), IndustryOutlook.Factors(w, steel).ProfitFactor);
|
||||
|
||||
// fermo e livello 0
|
||||
steel.StoppedUntilDay = w.Clock.Day + 5;
|
||||
Assert.Equal(IndustryLimit.Stopped, IndustryOutlook.Factors(w, steel).Limit);
|
||||
steel.StoppedUntilDay = -1;
|
||||
steel.Level = 0;
|
||||
Assert.Equal(IndustryLimit.Dormant, IndustryOutlook.Factors(w, steel).Limit);
|
||||
|
||||
// senza input (miniera) l'input non è mai il limite; giacimento sotto la soglia
|
||||
var mine = w.Industries.First(i => i.Def.Id == "iron_mine");
|
||||
mine.CovInput = 0;
|
||||
mine.CovWorkers = 1;
|
||||
mine.CovStaff = 1;
|
||||
mine.RevenueEma = 100;
|
||||
mine.CostEma = 100;
|
||||
mine.Condition = 100;
|
||||
Assert.Equal(IndustryLimit.None, IndustryOutlook.Factors(w, mine).Limit);
|
||||
var site = w.Sites[mine.Site.Value];
|
||||
site.ReserveTonnes = site.InitialReserveTonnes * w.Data.Balance.Industry.DepletionStartFraction / 2;
|
||||
var depleted = IndustryOutlook.Factors(w, mine);
|
||||
Assert.Equal(IndustryLimit.Depletion, depleted.Limit);
|
||||
Assert.Approx(0.5, depleted.Depletion, 1e-9);
|
||||
Assert.Approx(site.ReserveFraction, depleted.ReserveFraction, 1e-12);
|
||||
}
|
||||
|
||||
[Test(Description = "Il punteggio di crescita trimestrale pesa quota trasportata, copertura e redditività come in balance.json")]
|
||||
public static void GrowthScoreUsesTheWeights()
|
||||
{
|
||||
var f = RailFixture.Valdoria();
|
||||
var w = f.W;
|
||||
var g = w.Data.Balance.Growth;
|
||||
var ind = w.Industries.First(i => i.Def.Id == "steel_mill");
|
||||
ind.QuarterProduced = 200;
|
||||
ind.QuarterShipped = 150;
|
||||
ind.QuarterCoverageSum = 30;
|
||||
ind.QuarterDays = 60;
|
||||
ind.RevenueEma = 300;
|
||||
ind.CostEma = 100;
|
||||
var s = IndustryMath.GrowthScore(ind, g);
|
||||
Assert.Approx(0.75, s.Shipped, 1e-12);
|
||||
Assert.Approx(0.5, s.Coverage, 1e-12);
|
||||
Assert.Approx((ind.Margin + 1) / 2, s.Profit, 1e-12);
|
||||
Assert.Approx(g.WeightShipped * 0.75 + g.WeightCoverage * 0.5 + g.WeightProfit * s.Profit, s.Score, 1e-12);
|
||||
// spedito oltre il prodotto (scorte vecchie): la quota resta 1
|
||||
ind.QuarterShipped = 500;
|
||||
Assert.Equal(1.0, IndustryMath.GrowthScore(ind, g).Shipped);
|
||||
ind.QuarterProduced = 0;
|
||||
ind.QuarterDays = 0;
|
||||
Assert.Equal(0.0, IndustryMath.GrowthScore(ind, g).Shipped);
|
||||
Assert.Equal(0.0, IndustryMath.GrowthScore(ind, g).Coverage);
|
||||
}
|
||||
|
||||
[Test(Description = "La scheda viaggia nel blocco 1 di IndustryCard e torna identica; senza blocco il lettore la lascia vuota")]
|
||||
public static void SheetRoundTripsInTheIndustryCard()
|
||||
{
|
||||
var (f, line, _) = ServedValdoria();
|
||||
var w = f.W;
|
||||
var steel = w.Industries.First(i => i.Def.Id == "steel_mill");
|
||||
var card = Projection.IndustryCard(w, steel, f.Me);
|
||||
Assert.True(card.Sheet is not null, "scheda nel blocco 1");
|
||||
var decoded = (IndustryCard)Frame.Decode(Frame.Encode(card));
|
||||
var sheet = decoded.Sheet!;
|
||||
Assert.True(Frame.Encode(card).AsSpan().SequenceEqual(Frame.Encode(decoded)), "stessi byte");
|
||||
Assert.Equal((byte)steel.Level, sheet.Level);
|
||||
Assert.Equal(2, sheet.Inputs.Count);
|
||||
Assert.Equal(line, sheet.ServingLine);
|
||||
Assert.Equal(line, sheet.Inputs[0].Partners[0].Line);
|
||||
Assert.Equal((float)steel.Efficiency, sheet.Efficiency);
|
||||
Assert.Equal(card.Valuation, decoded.Valuation);
|
||||
Assert.Equal(steel.JobsWorkers, sheet.Workers.Jobs);
|
||||
|
||||
// un messaggio senza blocco (server F5) si legge con la scheda assente
|
||||
var old = new IndustryCard { Industry = 3, Valuation = new Money(100) };
|
||||
var back = (IndustryCard)Frame.Decode(Frame.Encode(old));
|
||||
Assert.True(back.Sheet is null, "nessuna scheda");
|
||||
Assert.Equal(new Money(100), back.Valuation);
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ public static class ProtocolTests
|
||||
},
|
||||
DataHash = 12345,
|
||||
Difficulty = "imprenditore",
|
||||
Server = new ServerInfo { Version = "0.6.1", Os = "Linux 6.8", Container = true, UptimeSeconds = 518_400, TickMs = 50, Sessions = 1, MaxSessions = 16, Local = false },
|
||||
};
|
||||
yield return new Reject { Code = RejectCode.BadToken, Reason = "Token errato" };
|
||||
yield return new Pong { Nonce = 7, ServerTick = 123456 };
|
||||
@@ -117,6 +118,36 @@ public static class ProtocolTests
|
||||
MaintenanceSpentYear = new Money(9999), PartsTarget = 9, PartsPerMonth = 3, PartsOrdered = 20, MachineryRequired = 6, UpgradeCost = new Money(3_000_000),
|
||||
Valuation = new Money(4_500_000), Cash = new Money(2_000_000), BreakdownChancePerYear = 0.3f,
|
||||
Stops = [new IndustryStopInfo { Day = 300, Days = 12, Kind = 1 }, new IndustryStopInfo { Day = 500, Days = 30, Kind = 3 }],
|
||||
Sheet = new IndustrySheetInfo
|
||||
{
|
||||
Level = 3, MaxLevel = 5, Efficiency = 0.6f, Limit = 3, CovInput = 0.73f, CovWorkers = 0.8f, CovStaff = 0.6f, CoverageWindowDays = 30,
|
||||
ProfitFactor = 1.05f, Depletion = 1, EventCapacity = 1, ReserveFraction = -1, StorageDays = 30,
|
||||
Inputs =
|
||||
[
|
||||
new IndustryFlowInfo
|
||||
{
|
||||
Good = 2, FullMonth = 480, CurrentMonth = 350, Stock = 105, Storage = 480, Days = 9, Limiting = true,
|
||||
Partners = [new ChainPartnerInfo { Kind = 0, Target = 1, MonthlyUnits = 500, Price = 4_200, Line = 5, DistanceKm = 9.4f }],
|
||||
},
|
||||
],
|
||||
Outputs =
|
||||
[
|
||||
new IndustryFlowInfo
|
||||
{
|
||||
Good = 4, FullMonth = 500, CurrentMonth = 300, Stock = 40, Storage = 500, Days = 46, Limiting = false,
|
||||
Partners = [new ChainPartnerInfo { Kind = 1, Target = 0, MonthlyUnits = 4000, Price = 15_600, Line = -1, DistanceKm = 4.2f }],
|
||||
},
|
||||
],
|
||||
Workers = new WorkforceInfo
|
||||
{
|
||||
Jobs = 200, Present = 160, OnSite = 60, Coverage = 0.8f, Missing = 40, Reason = 5, ReasonLine = 1, AverageMinutes = 38, SourceCount = 2,
|
||||
Sources = [new WorkforceSourceInfo { Town = 0, Headcount = 120, Coverage = 0.95f, Line = 1, Carrier = 0, Minutes = 35, Walking = false }],
|
||||
},
|
||||
Staff = new WorkforceInfo { Jobs = 20, Present = 12, Missing = 8, Reason = 4, ReasonLine = -1, AverageMinutes = -1 },
|
||||
AveragePrice = 15_600, AnnualProfit = new Money(41_000_000), LastScore = 0.62f, Shipped = 0.8f, Coverage = 0.6f, Profit = 0.55f, Score = 0.69f,
|
||||
UpgradeThreshold = 0.75f, DowngradeThreshold = 0.35f, UpgradeQuarters = 2, QuartersAbove = 1, QuarterDay = 45, QuarterDays = 90, Served = true,
|
||||
ServingStations = [2, 7], ServingLine = 1, ForSale = true, BuyUnlocked = false, BuyTier = 3, BuyProgress = 0.58f,
|
||||
},
|
||||
};
|
||||
yield return new Chronicle
|
||||
{
|
||||
|
||||
@@ -404,6 +404,55 @@ public static class ServerTests
|
||||
Assert.Equal(Money.FromLire(5_000), after.Loans);
|
||||
}
|
||||
|
||||
[Test(Description = "F6 in rete: la scheda dell'industria arriva su richiesta con la catena produttiva; il Welcome porta lo stato del server e ListSaves l'elenco (ADR 0021)")]
|
||||
public static void IndustrySheetAndServerStatusOnRequest() => RunIndustrySheet().GetAwaiter().GetResult();
|
||||
|
||||
private static async Task RunIndustrySheet()
|
||||
{
|
||||
var scenario = ScenarioHelper.Load("valdoria");
|
||||
var steel = scenario.World.Industries.First(i => i.Def.Id == "steel_mill");
|
||||
await using var server = ServerFixture.Start(scenario.World);
|
||||
await using var client = await TestClient.ConnectAsync(server);
|
||||
var w = client.World;
|
||||
var data = TestData.Data;
|
||||
|
||||
// stato del server nel blocco 1 del Welcome
|
||||
var info = client.Welcome.Server;
|
||||
Assert.True(info is not null, "stato del server nel Welcome");
|
||||
Assert.Equal(server.Host.GameVersion, info!.Version);
|
||||
Assert.Equal(1f, info.TickMs);
|
||||
Assert.True(info.Sessions >= 1 && info.Sessions <= info.MaxSessions, $"sessioni {info.Sessions} su {info.MaxSessions}");
|
||||
Assert.True(info.Local, "server in processo avviato come locale");
|
||||
Assert.True(info.Os.Length > 0 && info.UptimeSeconds >= 0, "sistema e tempo di attività");
|
||||
Assert.True(w.Server is not null && w.Server.Version == info.Version, "la copia locale tiene lo stato del server");
|
||||
|
||||
// elenco dei salvataggi: risposta a ListSaves, poi a Save con il salvataggio nuovo
|
||||
await client.Connection.SendAsync(new ListSaves());
|
||||
var empty = await client.WaitFor(() => w.Saves, "elenco dei salvataggi");
|
||||
var stale = w.Saves;
|
||||
await client.Connection.SendAsync(new Save { Name = "Valdoria" });
|
||||
var saves = await client.WaitFor(() => ReferenceEquals(w.Saves, stale) ? null : w.Saves, "elenco dopo il salvataggio");
|
||||
Assert.Equal(empty.Saves.Count + 1, saves.Saves.Count);
|
||||
Assert.True(saves.Saves.Any(x => !x.Autosave && (x.Name.Contains("Valdoria", StringComparison.Ordinal) || x.SaveId.Contains("Valdoria", StringComparison.OrdinalIgnoreCase))), "il salvataggio nuovo è nell'elenco");
|
||||
|
||||
// scheda dell'industria: si aspetta la risposta alla richiesta, non una scheda vecchia
|
||||
await client.WaitUntil(() => w.LastDigest is { Day: >= 2 }, "due giorni di partita");
|
||||
var old = w.IndustryCards.GetValueOrDefault(steel.Id.Value);
|
||||
await client.Connection.SendAsync(new RequestDetail { Kind = DetailKind.Industry, Target = steel.Id.Value });
|
||||
var card = await client.WaitFor(() => w.IndustryCards.TryGetValue(steel.Id.Value, out var c) && !ReferenceEquals(c, old) ? c : null, "scheda dell'industria");
|
||||
var sheet = card.Sheet;
|
||||
Assert.True(sheet is not null, "scheda nel blocco 1");
|
||||
Assert.Equal(steel.Def.Recipe.Inputs.Count, sheet!.Inputs.Count);
|
||||
Assert.Equal(steel.Def.Recipe.Outputs.Count, sheet.Outputs.Count);
|
||||
Assert.Equal(data.Goods.First(g => g.Id == "iron_ore").Index, sheet.Inputs[0].Good);
|
||||
Assert.True(sheet.Inputs[0].Partners.Count > 0 && sheet.Inputs[0].Partners.All(p => p.Line == -1), "fornitori, nessuno collegato");
|
||||
Assert.Equal(data.Balance.Growth.MaxLevel, (int)sheet.MaxLevel);
|
||||
Assert.Equal(-1, sheet.ServingLine);
|
||||
Assert.True(sheet.ForSale && !sheet.BuyUnlocked, "in vendita, acquisto non ancora sbloccato");
|
||||
Assert.Equal(data.Tiers.Tiers.First(t => t.Unlocks.BuyIndustry).Level, (int)sheet.BuyTier);
|
||||
Assert.Equal(steel.JobsWorkers, sheet.Workers.Jobs);
|
||||
}
|
||||
|
||||
[Test(Description = "Hello con token errato, dati diversi o protocollo vecchio riceve Reject")]
|
||||
public static void HandshakeRejections() => RunRejections().GetAwaiter().GetResult();
|
||||
|
||||
|
||||
Reference in new issue
Block a user