Map sectors show again, clients get their own machines and the train's swath, machines stay out of the ground

- Map: the sectors are wound the screen's way (most were wound the other way and culled, leaving a blank chart),
  kept inside the chart, and drawn as ball, sectors and marks layers; the scale bar is no longer sized mid-draw.
- Players' save keys are replicated, so a client's garage finds its machines and their upgrades; two players under
  one key get separate ones.
- The grass train sends its mowing to the clients; moving the depot or resizing the planet relays its line.
- A hard floor under vehicle springs: hard landings, steep rises and hand-overs no longer sink a machine.
- Tests: -demosink, -demorep host|client.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
NiemandKG
2026-11-12 01:33:03 +06:00
parent 86c8403c2a
commit d61167e22b
10 changed files with 474 additions and 33 deletions

View File

@ -149,6 +149,7 @@ namespace GrassCutter
if (!All.Contains(this)) All.Add(this);
Target.OnValueChanged += (_, __) => Route();
Legs.OnValueChanged += (_, __) => Route();
Planet.Rescaled += Route;
if (IsServer)
{
while (Bins.Count < Stations.Count) Bins.Add(0f);
@ -157,8 +158,24 @@ namespace GrassCutter
Route();
}
/// <summary>Everyone: the depot was picked up and set down elsewhere. The line starts from there now, so it is laid again.</summary>
public void Moved()
{
if (IsServer)
{
Laid.Value = 0f;
At.Value = 0f;
Runs.Value = 0;
_wait = 0f;
_noMore = false;
}
_shown = 0f;
Route();
}
public override void OnNetworkDespawn()
{
Planet.Rescaled -= Route;
All.Remove(this);
if (_track) Destroy(_track);
}
@ -375,6 +392,7 @@ namespace GrassCutter
{
if (!IsSpawned) return;
if (IsServer && _length > 0f) Run(Time.deltaTime);
if (IsServer && _sendW > 0f && Time.time - _sendT > 0.25f) SendCut();
Draw();
}
@ -471,10 +489,32 @@ namespace GrassCutter
Hopper.Value = 0f;
}
/// <summary>Mows along the track from a to b: under it (offset 0), or a strip either side starting this far out.</summary>
/// <summary>Host: mows along the track from a to b into the hopper, and has everyone else mow the same.</summary>
void Cut(float a, float b, float offset, float width)
{
if (width <= 0.05f || Mathf.Abs(b - a) < 1e-4f) return;
Hopper.Value = Mathf.Min(Hold, Hopper.Value + Mow(a, b, offset, width) * GameDefs.GrassDensity);
// each peer cuts its own copy of the meadow: the stroke goes out to the others, joined up into a few a second
if (_sendW > 0f && (_sendOff != offset || _sendW != width || Mathf.Abs(_sendB - a) > 0.01f || (b > a) != (_sendB > _sendA))) SendCut();
if (_sendW <= 0f) { _sendA = a; _sendOff = offset; _sendW = width; _sendT = Time.time; }
_sendB = b;
if (Time.time - _sendT > 0.25f) SendCut();
}
float _sendA, _sendB, _sendOff, _sendW, _sendT;
void SendCut()
{
if (_sendW > 0f && Mathf.Abs(_sendB - _sendA) > 1e-4f) CutRpc(_sendA, _sendB, _sendOff, _sendW);
_sendW = 0f;
}
[Rpc(SendTo.NotServer)]
void CutRpc(float a, float b, float offset, float width) => Mow(a, b, offset, width);
/// <summary>Mows along the track from a to b: under it (offset 0), or a strip either side starting this far out. The kilos cut.</summary>
float Mow(float a, float b, float offset, float width)
{
float kg = 0f;
int n = Mathf.Max(1, Mathf.CeilToInt(Mathf.Abs(b - a) / Step));
for (int k = 0; k < n; k++)
@ -489,7 +529,7 @@ namespace GrassCutter
kg += MowMap.Cut(Planet.Surface(p0 + side * o), Planet.Surface(p1 + side * o), width, 0f, MowMap.PaintFeather);
kg += MowMap.Cut(Planet.Surface(p0 - side * o), Planet.Surface(p1 - side * o), width, 0f, MowMap.PaintFeather);
}
Hopper.Value = Mathf.Min(Hold, Hopper.Value + kg * GameDefs.GrassDensity);
return kg;
}
// ───────────────────────── riding ─────────────────────────