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

@ -133,6 +133,8 @@ namespace GrassCutter
transform.SetPositionAndRotation(at, rot);
var bot = GetComponent<Mowbot>();
if (bot) bot.Moved(at);
var train = GetComponent<Train>();
if (train) train.Moved();
if (Stands && Planet.Altitude(at) < 1f) MowMap.BlockRound(at, Mathf.Max(Def.sizeX, Def.sizeZ) * 0.72f);
Fx.Build(at, new Vector2(Def.sizeX, Def.sizeZ));
Sfx.PlayAt("build_place", at, 0.9f);

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 ─────────────────────────

View File

@ -274,6 +274,35 @@ namespace GrassCutter
// ───────────────────────── physics (owner) ─────────────────────────
readonly float[] _clear = new float[4];
/// <summary>The nose and the tail, along the middle, past the springs: what digs in first on a rise or a hard landing.</summary>
static readonly float[] Ends = { 0.5f, -0.5f, 0f };
/// <summary>
/// A hard floor under the springs. They are soft enough to ride a meadow, so a hard landing, a steep rise or the
/// moment after a hand-over squeezed them right through and a corner (or the nose) went into the ground; nothing
/// else holds a machine up, the ground itself has no collider. Whatever is below the ground comes straight back
/// up, and stops falling.
/// </summary>
void Floor(Vector3 up)
{
float sink = 0f;
for (int i = 0; i < _clear.Length; i++) sink = Mathf.Max(sink, -_clear[i]);
for (int i = 0; i < Ends.Length; i++)
sink = Mathf.Max(sink, -Planet.Altitude(transform.TransformPoint(new Vector3(0f, 0f, Ends[i] * length))));
if (sink < 0.02f || NoFloor) return;
sink = Mathf.Min(sink, 3f);
Body.position += up * sink;
float down = Vector3.Dot(Body.linearVelocity, up);
if (down < 0f) Body.linearVelocity -= up * down;
Sinks++;
}
/// <summary>How often the floor had to catch a machine (the tests read it).</summary>
public static int Sinks;
/// <summary>Tests: the floor off, to see how it was.</summary>
public static bool NoFloor;
static readonly Vector2[] Probes = { new Vector2(-0.5f, 0.42f), new Vector2(0.5f, 0.42f), new Vector2(-0.5f, -0.42f), new Vector2(0.5f, -0.42f) };
void FixedUpdate()
@ -311,6 +340,7 @@ namespace GrassCutter
if (_ghost) clearance = Mathf.Min(clearance, DeckClearance(wp, up, 1.2f + ride + 1.5f));
else if (Physics.Raycast(wp + up * 1.2f, -up, out var sh, 1.2f + ride + 1.5f, groundMask, QueryTriggerInteraction.Ignore))
clearance = Mathf.Min(clearance, sh.distance - 1.2f);
_clear[i] = clearance;
float depth = ride - clearance;
if (depth > 0f)
{
@ -321,6 +351,7 @@ namespace GrassCutter
}
}
bool onGround = wet > 0;
Floor(up);
// drive
var fwd = Vector3.ProjectOnPlane(transform.forward, up).normalized;