Round 6 fixes: held tools, headlamp glare, ladder openings, level horizon, roof hulls, rain hits, idle motion, belt packs, meadow variety

- Held tools sit lower and further right; the hammer faces forward and strikes about the camera's right
- Headlamp leaves held items, treats and vending machines alone (rendering layer NoLamp); other lights keep lighting them
- Hay grounded on the floor in world space (it floated)
- Deck fence opens at each ladder, rail colliders split around it; ladders moved to 2 m off the edge middle, clear of the intakes; climbing goes over a rail only if one is in the way
- Crew stand to the soil's up (Planet.Level): flat round the base, the ball's up past it, so the horizon stays level on a small planet
- Convex roof hulls for the crew cabin, garage, pitched roof and windmill tower; cabin box lowered to the eaves
- Rain and acid rain hits differ by surface: soil, grass, wood, metal
- Idle motion: dishes pan, sways sway, sensors turn, eyes blink, windmill turns in the breeze, reels and parked rotors tick over
- Belt: take tools off at the supply wall; hold E at a vending machine for a pack of 3 on the belt, LMB has one
- New meadow pieces: boulders, slab stones, crystals, mushrooms, stump, bulb plants
- -demofix checks for all of the above; loc rows in all 11 tables

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
NiemandKG
2026-12-01 22:52:05 +06:00
parent fd20af06ae
commit 36e4bb2a10
88 changed files with 7588 additions and 4926 deletions

View File

@ -9,6 +9,113 @@ namespace GrassCutter
/// -demofix: close looks at the base furniture people asked about: a deck ladder where it meets the railing, the hay
/// bale on the deck, the foot of the loading ramp and the back of the upgrade console.
/// </summary>
/// <summary>The second round: intakes beside the ladders, a body dropped on the roofs, the new meadow pieces, a pack on
/// the belt, acid rain on the deck and the meadow, and the headlamp at night on a tool in hand and on a vending machine.</summary>
IEnumerator FixMore()
{
// the north side from the meadow: ladders in their openings, intakes clear of them
Me.Teleport(new Vector3(-4f, 1.4f - 1.6f, 16f));
yield return new WaitForSeconds(0.6f);
Me.LookAt(new Vector3(-4f, 0.4f, 9.5f));
yield return new WaitForSeconds(0.6f);
yield return Shot("fix_intakes_n");
Me.Teleport(new Vector3(12f, 1.4f - 1.6f, -14f));
yield return new WaitForSeconds(0.6f);
Me.LookAt(new Vector3(4f, 0.4f, -9.5f));
yield return new WaitForSeconds(0.6f);
yield return Shot("fix_intakes_s");
// dropped from above the crew cabin's ridge: where does the body come to rest?
Me.SetFlying(false);
foreach (var probe in new[] { new Vector3(-6f, 9f, 7f), new Vector3(-6.8f, 9f, 6.2f) })
{
Me.Teleport(probe);
yield return new WaitForSeconds(3f);
Log($"roof probe from {probe}: rests at y {Me.transform.position.y:0.00}, grounded {Me.Grounded}");
foreach (var h in Physics.RaycastAll(probe + Vector3.up * 5f, Vector3.down, 20f, ~0, QueryTriggerInteraction.Ignore))
Log($" ray hits {h.collider.name} ({h.collider.GetType().Name}, layer {h.collider.gameObject.layer}, enabled {h.collider.enabled}) at y {h.point.y:0.00}");
}
Me.SetFlying(true);
// the new meadow pieces, the nearest of each
var ground = FindAnyObjectByType<Ground>();
if (ground)
{
foreach (var kind in new[] { "SM_Boulders", "SM_SlabStones", "SM_Crystals", "SM_Shrooms", "SM_Stump", "SM_BulbPlants" })
{
Transform best = null;
float bd = float.MaxValue;
foreach (var t in ground.GetComponentsInChildren<Transform>(true))
{
if (!t.name.StartsWith(kind) || t.parent == null || t.parent.name.StartsWith("SM_")) continue;
float d = (t.position - Me.transform.position).sqrMagnitude;
if (d < bd) { bd = d; best = t; }
}
if (!best) { Log($"no {kind} on the ball"); continue; }
var up = Planet.Up(best.position);
var side = Vector3.Cross(up, Vector3.forward).normalized;
Me.Teleport(best.position + side * 7f + up * 1.2f);
yield return new WaitForSeconds(1.2f);
Me.LookAt(best.position + up * 1f);
yield return new WaitForSeconds(0.8f);
yield return Shot("fix_decor_" + kind.Substring(3).ToLowerInvariant());
}
}
// a pack on the belt, in hand, and one had from it
Me.BeltSlots.Value = 4;
Cheats.Run("tool all");
yield return new WaitForSeconds(0.5f);
Me.Tools.Unequip(ToolId.Hammer);
Me.Tools.Unequip(ToolId.LongScythe);
Me.Tools.AddPack(TreatId.Beer, Treats.PackSize);
Me.Teleport(new Vector3(2f, 0.05f, 2f));
yield return new WaitForSeconds(0.5f);
Me.LookAt(new Vector3(2f, 1.2f, 12f));
Me.Tools.Select(ToolId.BeerPack);
yield return new WaitForSeconds(0.6f);
yield return Shot("fix_pack_belt");
Ctl.BotUsePressed = true;
yield return null;
Ctl.BotUsePressed = false;
yield return new WaitForSeconds(1.4f);
yield return Shot("fix_pack_drink");
Log($"pack: {Me.Tools.PackLeft(TreatId.Beer)} left, belt {string.Join(", ", Me.Tools.Belt)}");
yield return new WaitForSeconds(3f);
// acid rain on the deck rail, a machine and the meadow
Cheats.Run("weather acidrain 5");
yield return new WaitForSeconds(9f);
Me.Teleport(new Vector3(-2f, 0.05f, 6f));
yield return new WaitForSeconds(0.5f);
Me.LookAt(new Vector3(-2f, -0.4f, 11f));
yield return new WaitForSeconds(1.5f);
yield return Shot("fix_acid_edge");
Me.LookAt(new Vector3(0f, 0f, 3f));
yield return new WaitForSeconds(1.5f);
yield return Shot("fix_acid_deck");
Cheats.Run("weather clear");
// night: the headlamp on the tool in hand, and on a vending machine's own lights
float pinned = Sun.Pinned;
Sun.Pinned = Mathf.Repeat(pinned + 0.5f, 1f);
yield return new WaitForSeconds(4f);
Me.Tools.Select(ToolId.Scythe);
Me.LookAt(Me.transform.position + Me.transform.forward * 5f - Me.transform.up * 1.5f);
yield return new WaitForSeconds(1f);
yield return Shot("fix_night_tool");
var vm = VendingMachine.All.Count > 0 ? VendingMachine.All[0] : null;
if (vm)
{
Me.Teleport(vm.transform.position + vm.transform.forward * 1.6f + Vector3.up * 0.05f);
yield return new WaitForSeconds(0.6f);
Me.LookAt(vm.transform.position + Vector3.up * 1.1f);
yield return new WaitForSeconds(1f);
yield return Shot("fix_night_vending");
}
Sun.Pinned = pinned;
}
IEnumerator FixLook()
{
BotCapture.From = null;
@ -20,10 +127,10 @@ namespace GrassCutter
Me.SetFlying(true);
var spots = new (string name, Vector3 eye, Vector3 at)[]
{
("fix_ladder_a", new Vector3(-1.5f + 0.0f, 1.2f, 0f), new Vector3(-1.5f, 0.2f, 9f)),
("fix_ladder_b", new Vector3(-0.5f, 0.6f, 12f), new Vector3(-1.5f, 0.3f, 9f)),
("fix_ladder_c", new Vector3(-3.5f, 1.8f, 11.5f), new Vector3(-1.5f, 0f, 9f)),
("fix_ladder_d", new Vector3(-1.5f, -0.6f, 10.5f), new Vector3(-1.5f, 0.9f, 9f)),
("fix_ladder_a", new Vector3(-2f, 1.2f, 0f), new Vector3(-2f, 0.2f, 9f)),
("fix_ladder_b", new Vector3(-1f, 0.6f, 12f), new Vector3(-2f, 0.3f, 9f)),
("fix_ladder_c", new Vector3(-4f, 1.8f, 11.5f), new Vector3(-2f, 0f, 9f)),
("fix_ladder_d", new Vector3(-2f, -0.6f, 10.5f), new Vector3(-2f, 0.9f, 9f)),
("fix_hay", new Vector3(5.5f, 1.4f, -5.2f), new Vector3(7.8f, 0.2f, -7.6f)),
("fix_hay_side", new Vector3(10.5f, 0.3f, -7.6f), new Vector3(7.8f, 0.1f, -7.6f)),
("fix_yard", new Vector3(0f, 2.2f, -9f), new Vector3(0f, -1.2f, -20f)),
@ -40,6 +147,7 @@ namespace GrassCutter
yield return new WaitForSeconds(0.6f);
yield return Shot(s.name);
}
yield return FixMore();
Log("demofix done");
Application.Quit();
}

View File

@ -2355,6 +2355,17 @@ namespace GrassCutter
Me.LookAt(at + new Vector3(-6f, 1.4f, 9f));
yield return new WaitForSeconds(1f);
yield return Shot($"{i}_{tool}_rest");
if (tool == ToolId.Hammer)
{
// which way the head faces, turned about the handle a quarter at a time
for (int q = 1; q < 4; q++)
{
ViewModel.Spin(tool, q * 90f);
yield return new WaitForSeconds(0.3f);
yield return Shot($"{i}_{tool}_spin{q * 90}");
}
ViewModel.Spin(tool, 0f);
}
Me.LookAt(ground);
yield return new WaitForSeconds(0.6f);
yield return Shot($"{i}_{tool}_rest_down");

View File

@ -303,6 +303,51 @@ namespace GrassCutter
Emit(i._drops, pos + side * s * 0.5f, (side * s * 1.8f + Planet.LocalUp * 2.4f) * (0.6f + speed01), Random.Range(0.05f, 0.09f), Clip(), 0.8f);
}
public enum Surface { Ground, Grass, Wood, Metal }
/// <summary>
/// A raindrop landing, as the thing it lands on takes it. Soil throws up a brown fleck and a dull ring; grass shakes off
/// a spray of beads; wood beads up; metal rings out with a hard bright bounce. Acid adds its own: a fizz of steam on
/// metal, a thin brown smoke off wood, scorched flecks and a yellow puff off grass, a yellow froth on soil.
/// </summary>
public static void RainHit(Vector3 pos, Vector3 up, Surface on, Color tint, float acid)
{
var i = I;
if (!i || !i.Budget(1)) return;
var drop = new Color(tint.r, tint.g, tint.b, 0.55f);
switch (on)
{
case Surface.Ground:
Emit(i._ring, pos + up * 0.03f, Vector3.zero, Random.Range(0.12f, 0.22f), new Color(0.42f, 0.33f, 0.22f, 0.5f), 0.6f);
for (int k = 0; k < 2; k++)
Emit(i._drops, pos + up * 0.03f, up * Random.Range(1.2f, 2f) + Random.insideUnitSphere * 0.9f, Random.Range(0.025f, 0.04f), new Color(0.36f, 0.27f, 0.17f, 1f), 0.35f);
if (acid > 0.5f) Emit(i._puff, pos + up * 0.04f, up * 0.25f, Random.Range(0.1f, 0.18f), new Color(0.85f, 0.9f, 0.35f, 0.5f), 0.9f);
break;
case Surface.Grass:
for (int k = 0; k < 3; k++)
Emit(i._drops, pos + up * 0.25f + Random.insideUnitSphere * 0.1f, up * Random.Range(0.8f, 1.6f) + Random.insideUnitSphere * 1.2f, Random.Range(0.02f, 0.035f),
acid > 0.5f ? new Color(0.55f, 0.5f, 0.15f, 1f) : new Color(0.7f, 0.9f, 0.75f, 0.9f), 0.4f);
if (acid > 0.5f && Random.value < 0.4f) Emit(i._puff, pos + up * 0.3f, up * 0.35f, Random.Range(0.12f, 0.2f), new Color(0.8f, 0.85f, 0.4f, 0.4f), 1.1f);
break;
case Surface.Wood:
Emit(i._puff, pos + up * 0.02f, up * 0.3f, Random.Range(0.06f, 0.1f), drop, 0.4f);
for (int k = 0; k < 2; k++)
Emit(i._drops, pos + up * 0.02f, up * Random.Range(0.8f, 1.4f) + Random.insideUnitSphere * 0.6f, Random.Range(0.02f, 0.03f), drop, 0.3f);
if (acid > 0.5f && Random.value < 0.5f) Emit(i._puff, pos + up * 0.05f, up * Random.Range(0.4f, 0.7f), Random.Range(0.15f, 0.25f), new Color(0.35f, 0.3f, 0.2f, 0.45f), 1.4f);
break;
case Surface.Metal:
for (int k = 0; k < 4; k++)
Emit(i._drops, pos + up * 0.02f, up * Random.Range(2.2f, 3.4f) + Random.insideUnitSphere * 1.6f, Random.Range(0.018f, 0.028f), new Color(0.9f, 0.95f, 1f, 1f), 0.3f);
Emit(i._sparkle, pos + up * 0.03f, up * 0.4f, Random.Range(0.06f, 0.1f), new Color(1f, 1f, 1f, 0.8f), 0.25f);
if (acid > 0.5f)
{
Emit(i._steam, pos + up * 0.05f, up * Random.Range(0.6f, 1f), Random.Range(0.12f, 0.2f), new Color(0.88f, 1f, 0.6f, 0.45f), 0.5f);
if (Random.value < 0.25f) Emit(i._sparkle, pos + up * 0.05f, up * 1.2f + Random.insideUnitSphere, 0.05f, new Color(0.8f, 1f, 0.3f, 1f), 0.3f);
}
break;
}
}
/// <summary>Vaporizer / hot vent: big soft white billows.</summary>
public static void Steam(Vector3 pos, float amount)
{

View File

@ -99,6 +99,7 @@ namespace GrassCutter
public override void OnNetworkSpawn()
{
All.Add(this);
IdleMotion.Attach(gameObject);
_run = GetComponentInChildren<BeltRun>();
if (_run) _run.Lay(transform.position, To.Value);
// grass doesn't grow through a machine

View File

@ -155,7 +155,7 @@ namespace GrassCutter
float lean = leg == 1 || leg == 5 ? Mathf.Sin(k * Mathf.PI) * 14f : 0f;
float sway = trip.w >= 0f ? Mathf.Sin(Time.time * 2.1f + i) * 2.5f : 0f;
d.SetPositionAndRotation(at, face * Quaternion.Euler(lean, 0f, sway));
float spin = trip.w >= 0f ? 1900f : 0f;
float spin = trip.w >= 0f ? 1900f : 70f;
foreach (var r in _rotors[i]) if (r) r.Rotate(up, spin * Time.deltaTime, Space.World);
if (_hum[i]) _hum[i].volume = trip.w >= 0f ? 0.3f * Sfx.SfxVolume : 0f;
}

View File

@ -5,7 +5,9 @@ namespace GrassCutter
{
/// <summary>What a player can hold: six hand tools from nail scissors to the two-handed scythe, each with its own
/// grass container, and the hammer that opens the build menu.</summary>
public enum ToolId : byte { NailScissors = 0, GardenShears = 1, Sickle = 2, Scythe = 3, LongScythe = 4, WideScythe = 5, Hammer = 6, LawnMower = 7, None = 255 }
public enum ToolId : byte { NailScissors = 0, GardenShears = 1, Sickle = 2, Scythe = 3, LongScythe = 4, WideScythe = 5, Hammer = 6, LawnMower = 7,
/// <summary>Not tools: a pack of treats from a vending machine, taking up a belt slot until it is used up.</summary>
BeerPack = 100, CigarPack = 101, None = 255 }
/// <summary>Personal gear on the supply wall; shares the owned mask with the tools.</summary>
public enum GearId : byte { Jetpack = 8, Boots = 9, NightVision = 10 }
@ -206,6 +208,10 @@ namespace GrassCutter
public static bool IsBlade(ToolId t) => t <= ToolId.WideScythe || t == ToolId.LawnMower;
/// <summary>Pushed along the ground instead of swung: cuts under its deck while you walk.</summary>
public static bool IsMower(ToolId t) => t == ToolId.LawnMower;
public static bool IsPack(ToolId t) => t == ToolId.BeerPack || t == ToolId.CigarPack;
public static bool IsTool(ToolId t) => (int)t < ToolCount;
public static TreatId PackTreat(ToolId t) => t == ToolId.BeerPack ? TreatId.Beer : TreatId.Cigar;
public static ToolId PackOf(TreatId k) => k == TreatId.Beer ? ToolId.BeerPack : ToolId.CigarPack;
/// <summary>Scythes and shears have a basket perk each; the mower's bag only grows with the compactor.</summary>
public static bool HasBinPerk(ToolId t) => t <= ToolId.WideScythe;
public static PerkId BinPerk(ToolId t) => (PerkId)((int)PerkId.BinScissors + (int)t);

View File

@ -18,6 +18,7 @@ namespace GrassCutter
go.transform.SetParent(transform, false);
go.transform.localPosition = new Vector3(0f, 2.35f, 0f);
_light = go.AddComponent<Light>();
_light.renderingLayerMask = -1;
_light.type = LightType.Point;
_light.color = Warm;
_light.range = 9f;

View File

@ -168,7 +168,8 @@ namespace GrassCutter
if (spin)
{
if (_spinAxis < 0) _spinAxis = BaseRot.LocalAxisFor(spin, transform.forward);
_spun += _pace * 300f * Time.deltaTime;
float idle = Piece.piece == PieceId.Dryer ? 18f + WeatherFx.Wind * 140f : 10f;
_spun += (_pace * 300f + idle * (1f - Mathf.Clamp01(_pace * 4f))) * Time.deltaTime;
var axis = _spinAxis == 0 ? Vector3.right : _spinAxis == 1 ? Vector3.up : Vector3.forward;
spin.localRotation = BaseRot.Of(spin) * Quaternion.Euler(axis * _spun);
}

View File

@ -57,9 +57,9 @@ namespace GrassCutter
void LateUpdate()
{
if (!reel || !Mowing.Value) return;
if (!reel) return;
if (_reelAxis < 0) _reelAxis = BaseRot.LocalAxisFor(reel, transform.right);
_spun += ReelSpeed * Time.deltaTime;
_spun += (Mowing.Value ? ReelSpeed : 14f) * Time.deltaTime;
var axis = _reelAxis == 0 ? Vector3.right : _reelAxis == 1 ? Vector3.up : Vector3.forward;
reel.localRotation = BaseRot.Of(reel) * Quaternion.Euler(axis * _spun);
}

View File

@ -6,6 +6,8 @@ namespace GrassCutter
public class StationTerminal : MonoBehaviour, IInteractable
{
public string Prompt => Loc.T("Travel terminal");
void Start() => IdleMotion.Attach(gameObject);
public bool CanInteract => TeamState.Instance;
public void Interact()

View File

@ -12,6 +12,8 @@ namespace GrassCutter
public static class Treats
{
public const float CostKg = 1f;
/// <summary>A pack for the belt: this many at once (for as many kilos), and a slot holds at most PackMost.</summary>
public const int PackSize = 3, PackMost = 6;
public const float Seconds = 150f;
/// <summary>Grass Beer: the blade cuts this much wider.</summary>
public const float BeerMow = 1.4f;

View File

@ -521,7 +521,7 @@ namespace GrassCutter
if (reel)
{
if (_reelAxis < 0) _reelAxis = BaseRot.LocalAxisFor(reel, transform.right);
reel.localRotation = BaseRot.Of(reel) * Quaternion.Euler(Axis(_reelAxis) * (Time.time * (slurp ? 260f : HasDriver ? 90f : 0f)));
reel.localRotation = BaseRot.Of(reel) * Quaternion.Euler(Axis(_reelAxis) * (Time.time * (slurp ? 260f : HasDriver ? 90f : 9f)));
}
if (wheels != null && wheels.Length > 0)
{

View File

@ -30,7 +30,15 @@ namespace GrassCutter
static readonly Color BeerGlow = new Color(1f, 0.82f, 0.32f), CigarGlow = new Color(1f, 0.55f, 0.22f), Deny = new Color(1f, 0.15f, 0.1f);
public string Prompt => Loc.F("{0}: 1 kg of grass from your tool. {1}, {2} for 2½ minutes", Treats.Name(kind), Treats.Boost(kind), Treats.Effect(kind));
public string Prompt
{
get
{
var line = Loc.F("{0}: 1 kg of grass from your tool. {1}, {2} for 2½ minutes", Treats.Name(kind), Treats.Boost(kind), Treats.Effect(kind));
var me = PlayerAgent.Local;
return me && me.Tools.PackRoom(kind) ? line + "\n" + Loc.F("Hold {0}: a pack of {1} for your belt ({1} kg)", Binds.Cap(Act.Interact), Treats.PackSize) : line;
}
}
public bool CanInteract => TeamState.Instance && !_busy && !TreatHand.Busy;
void OnEnable() => All.Add(this);
@ -38,6 +46,8 @@ namespace GrassCutter
void Start()
{
// its own lit sign and display: the headlamp on top of them only burnt them out
DayNight.KeepOutOfLamp(gameObject);
_mpb = new MaterialPropertyBlock();
_signBase = kind == TreatId.Beer ? new Color(0.25f, 1f, 0.5f) : CigarGlow;
_displayBase = kind == TreatId.Beer ? new Color(0.45f, 1f, 0.55f) : new Color(1f, 0.72f, 0.4f);
@ -64,12 +74,40 @@ namespace GrassCutter
Hud.Toast(Loc.T("Bring 1 kg of grass in your tool: mow a little first"), Hud.ToastKind.Warn);
return;
}
StartCoroutine(Choose(me));
}
/// <summary>A tap has it now; held a moment, it's a pack for the belt (if there's room and grass enough).</summary>
IEnumerator Choose(PlayerAgent me)
{
_busy = true;
float held = 0f;
while (Ctl.InteractHeld && held < 0.4f) { held += Time.deltaTime; yield return null; }
_busy = false;
var from = me.Tools.Nozzle;
if (held >= 0.4f && me.Tools.PackRoom(kind))
{
float cost = Treats.CostKg * Treats.PackSize;
if (me.Tools.Carried < cost - 0.001f)
{
_deny = 1f;
Sfx.PlayAt("error", transform.position, 0.7f);
Hud.Toast(Loc.F("A pack takes {0} kg of grass from your tools", Treats.PackSize), Hud.ToastKind.Warn);
yield break;
}
me.Tools.Spend(cost);
me.TreatRpc((byte)kind, transform.position, from);
_pack = true;
Play(true, from);
yield break;
}
me.Tools.Spend(Treats.CostKg);
me.TreatRpc((byte)kind, transform.position, from);
Play(true, from);
}
bool _pack;
/// <summary>Run the machine's show: for the buyer it ends with the treat in their hand, for everyone else it's just the show.</summary>
public void Play(bool mine, Vector3 from)
{
@ -168,7 +206,18 @@ namespace GrassCutter
yield return null;
}
Destroy(item.gameObject);
TreatHand.I?.Play(kind);
if (_pack)
{
_pack = false;
var me = PlayerAgent.Local;
if (me && me.Tools.AddPack(kind, Treats.PackSize))
{
Sfx.Play("plastic_grab", 0.6f, 0.9f);
Hud.Toast(Loc.F("{0} ×{1} on your belt: pick the slot and click to have one", Treats.Name(kind), me.Tools.PackLeft(kind)), Hud.ToastKind.Info);
}
else TreatHand.I?.Play(kind);
}
else TreatHand.I?.Play(kind);
}
else if (item)
{

View File

@ -34,7 +34,8 @@ namespace GrassCutter
public void Move(Vector3 delta)
{
var pos = transform.position;
var up = Planet.Up(pos);
// the body stands the way the crew member stands (the soil's up: see Planet.Level)
var up = transform.up;
float rise = Vector3.Dot(delta, up);
var flat = delta - up * rise;
bool was = isGrounded;

View File

@ -61,6 +61,7 @@ namespace GrassCutter
var bank = AssetBank.I;
var phone = Instantiate(bank.Model("SM_Phone"), _pivot);
phone.name = "PhoneBody";
DayNight.KeepOutOfLamp(phone);
foreach (var r in phone.GetComponentsInChildren<Renderer>(true))
{
if (r.name == "Screen") { _screenR = r; r.sharedMaterial = bank.Mat("M_PhoneScreen"); }

View File

@ -341,9 +341,8 @@ namespace GrassCutter
/// </summary>
void KeepUpright(bool snap = false)
{
var want = Planet.Up(transform.position);
var ts = Ts;
if (ts && !Flying && !_vehicle && ts.OnDeck(transform.position)) want = Vector3.up;
// the soil's own up (the deck stands on the flat round the base, so it is straight up there too)
var want = Planet.Level(transform.position);
_stand = snap || _stand == Vector3.zero ? want : Vector3.Slerp(_stand, want, 1f - Mathf.Exp(-6f * Time.deltaTime)).normalized;
_frame = Quaternion.FromToRotation(_frame * Vector3.up, _stand) * _frame;
}
@ -543,7 +542,9 @@ namespace GrassCutter
_climbFrom = transform.position;
_climbTo = hit.point + up * 0.05f + fwd * 0.45f;
_climbT = 0f;
_climbOver = true;
// over the railing if there is one in the way; up through the opening at a ladder there isn't
var waist = up * 0.5f;
_climbOver = Physics.Linecast(transform.position + Vector3.Project(_climbTo - transform.position, up) + waist, _climbTo + waist, 1 << Physics.IgnoreRaycastLayer, QueryTriggerInteraction.Ignore);
Body.enabled = false;
Sfx.Play("splash_small", 0.5f, 1.3f);
Sfx.Play("jump", 0.5f, 0.85f);

View File

@ -58,7 +58,70 @@ namespace GrassCutter
void Awake() { _p = GetComponent<PlayerAgent>(); }
public bool Owns(ToolId t) => _p.Owns(t);
public bool Owns(ToolId t) => GameDefs.IsTool(t) && _p.Owns(t);
// ───────────────────────── treat packs ─────────────────────────
readonly int[] _packs = new int[2];
/// <summary>How many are left in the pack of this treat on the belt (0: none there).</summary>
public int PackLeft(TreatId k) => _packs[(int)k];
/// <summary>Room for a pack of this treat: a free slot, or the one already on the belt not yet full.</summary>
public bool PackRoom(TreatId k) => _belt.Contains(GameDefs.PackOf(k)) ? _packs[(int)k] + Treats.PackSize <= Treats.PackMost : _belt.Count < _p.BeltSlots.Value;
/// <summary>A pack from a vending machine goes on the belt (onto the one there, or into a free slot).</summary>
public bool AddPack(TreatId k, int n)
{
if (!PackRoom(k)) return false;
var id = GameDefs.PackOf(k);
if (!_belt.Contains(id)) _belt.Add(id);
_packs[(int)k] = Mathf.Min(Treats.PackMost, _packs[(int)k] + n);
_changed = true;
BeltChanged?.Invoke();
return true;
}
/// <summary>The belt's contents changed without the hand changing (a pack topped up or used).</summary>
public event Action BeltChanged;
/// <summary>One from the pack in hand: the can or the cigar comes up, the boost starts, the pack runs down.</summary>
void UsePack()
{
var k = GameDefs.PackTreat(Current);
if (_packs[(int)k] <= 0 || TreatHand.Busy || !TreatHand.I) return;
_packs[(int)k]--;
_changed = true;
// far from any machine: the others see the boost, not a machine's show
_p.TreatRpc((byte)k, new Vector3(0f, -100000f, 0f), Nozzle);
TreatHand.I.Play(k);
if (_packs[(int)k] <= 0)
{
int i = _belt.IndexOf(Current);
_belt.Remove(Current);
var next = ToolId.None;
foreach (var t in _belt) if (GameDefs.IsTool(t)) { next = t; break; }
if (next == ToolId.None && _belt.Count > 0) next = _belt[Mathf.Clamp(i, 0, _belt.Count - 1)];
Current = ToolId.None;
Select(next);
}
BeltChanged?.Invoke();
}
/// <summary>Take a tool off the belt: it stays yours (the supply wall has it), the slot is free for something else.</summary>
public void Unequip(ToolId t)
{
if (!_belt.Remove(t)) return;
_changed = true;
if (Current == t)
{
var next = ToolId.None;
foreach (var b in _belt) if (GameDefs.IsTool(b)) { next = b; break; }
if (next == ToolId.None && _belt.Count > 0) next = _belt[0];
Select(next);
}
BeltChanged?.Invoke();
}
public float Bin(ToolId t) => GameDefs.IsBlade(t) ? _bins[(int)t] : 0f;
public float CurrentCap => Ts && GameDefs.IsBlade(Current) ? Ts.ToolCap(Current) : 0f;
@ -100,12 +163,13 @@ namespace GrassCutter
public void Select(ToolId t)
{
if (t == Current || (t != ToolId.None && !Owns(t))) return;
if (t == Current || (t != ToolId.None && !Owns(t) && !(GameDefs.IsPack(t) && _belt.Contains(t)))) return;
Current = t;
_changed = true;
if (_p.IsOwner)
{
_p.ToolNet.Value = (byte)t;
// a pack in hand shows as empty hands to the others: the can or cigar comes up when it is used
_p.ToolNet.Value = (byte)(GameDefs.IsPack(t) ? ToolId.None : t);
_p.Tank.Value = Bin(t);
}
StopCut();
@ -138,6 +202,7 @@ namespace GrassCutter
HandleSwitching();
if (_changed && Time.time >= _reportAt) ReportNow();
if (GameDefs.IsPack(Current) && Ctl.UsePressed && !_p.Driving.Value && !_p.Grab.Holding && !Ctl.UIOpen) UsePack();
bool blocked = _p.Driving.Value || _p.Grab.Holding || Ctl.UIOpen || !GameDefs.IsBlade(Current) || TreatHand.Busy;
if (blocked) { BladeOn = false; StopCut(); return; }
@ -161,7 +226,9 @@ namespace GrassCutter
_changed = false;
_reportAt = Time.time + 5f;
var belt = new int[_belt.Count];
for (int i = 0; i < belt.Length; i++) belt[i] = (int)_belt[i];
// a pack is kept as 1000 + 100 x its treat + how many are left in it
for (int i = 0; i < belt.Length; i++)
belt[i] = GameDefs.IsPack(_belt[i]) ? 1000 + 100 * (int)GameDefs.PackTreat(_belt[i]) + _packs[(int)GameDefs.PackTreat(_belt[i])] : (int)_belt[i];
_p.ReportToolsRpc(_bins, belt, (int)Current);
}
@ -176,8 +243,18 @@ namespace GrassCutter
_ownedSeen = _p.Owned.Value;
for (int i = 0; i < bins.Length && i < _bins.Length; i++) _bins[i] = bins[i];
_belt.Clear();
_packs[0] = _packs[1] = 0;
foreach (int t in belt)
if (_belt.Count < _p.BeltSlots.Value && Owns((ToolId)t) && !_belt.Contains((ToolId)t)) _belt.Add((ToolId)t);
{
if (_belt.Count >= _p.BeltSlots.Value) break;
if (t >= 1000)
{
int k = Mathf.Clamp((t - 1000) / 100, 0, 1), n = Mathf.Clamp((t - 1000) % 100, 0, Treats.PackMost);
var id = GameDefs.PackOf((TreatId)k);
if (n > 0 && !_belt.Contains(id)) { _belt.Add(id); _packs[k] = n; }
}
else if (Owns((ToolId)t) && !_belt.Contains((ToolId)t)) _belt.Add((ToolId)t);
}
var hand = _belt.Contains((ToolId)current) ? (ToolId)current : _belt.Count > 0 ? _belt[0] : ToolId.None;
Current = ToolId.None;
Select(hand);

View File

@ -57,6 +57,7 @@ namespace GrassCutter
if (src)
{
go = Instantiate(src, r.pivot);
DayNight.KeepOutOfLamp(go);
go.transform.localPosition = Vector3.zero;
go.transform.localRotation = Flip * src.transform.localRotation;
}

View File

@ -22,12 +22,28 @@ namespace GrassCutter
// a sweep turns the whole rig around this point, by this much either way of the middle of the stroke
public Vector3 pivot;
public float arc, middle;
// the model turned about its own handle, so the business end faces where it should
public float spin;
}
class Rig
{
public Hold hold;
public Transform root, bladeA, bladeB;
public Transform mesh;
public Quaternion meshRot;
public Vector3 handle;
}
/// <summary>Every tool sits this much lower and further right than its pose says: out of the middle of the view.</summary>
static readonly Vector3 Shift = new Vector3(0.045f, -0.05f, 0f);
/// <summary>Turns a tool about its handle (the longest side of its mesh), on top of its pose's own spin.</summary>
public static void Spin(ToolId id, float degrees)
{
var vm = FindAnyObjectByType<ViewModel>();
if (vm && vm._rigs.TryGetValue(id, out var r) && r.mesh)
r.mesh.localRotation = r.meshRot * Quaternion.AngleAxis(r.hold.spin + degrees, r.handle);
}
static readonly Hold[] Holds =
@ -57,8 +73,8 @@ namespace GrassCutter
pos = new Vector3(0.32f, -0.1f, 0.36f), euler = new Vector3(9f, -22f, 0f),
usePos = new Vector3(0.32f, -0.11f, 0.36f), useEuler = new Vector3(11f, -22f, 0f),
pivot = new Vector3(0.1f, -0.6f, -0.1f), arc = 28f, middle = 5f },
// the hammer stands up beside the view, face to the left, ready to come down on what's being built
new Hold { id = ToolId.Hammer, motion = Motion.Strike, scale = 0.42f,
// the hammer stands up beside the view, face forward, ready to come down on what's being built
new Hold { id = ToolId.Hammer, motion = Motion.Strike, scale = 0.42f, spin = 270f,
pos = new Vector3(0.27f, -0.2f, 0.42f), euler = new Vector3(-68f, -10f, -8f),
usePos = new Vector3(0.27f, -0.2f, 0.42f), useEuler = new Vector3(-68f, -10f, -8f) },
};
@ -102,7 +118,17 @@ namespace GrassCutter
if (t.name == "BladeA") r.bladeA = t;
else if (t.name == "BladeB") r.bladeB = t;
}
var mf = model ? model.GetComponentInChildren<MeshFilter>() : null;
if (mf && mf.sharedMesh)
{
var size = mf.sharedMesh.bounds.size;
r.mesh = mf.transform;
r.meshRot = mf.transform.localRotation;
r.handle = size.x >= size.y && size.x >= size.z ? Vector3.right : size.y >= size.z ? Vector3.up : Vector3.forward;
if (h.spin != 0f) r.mesh.localRotation = r.meshRot * Quaternion.AngleAxis(h.spin, r.handle);
}
SetLayer(r.root, Layers.ViewModel);
DayNight.KeepOutOfLamp(r.root.gameObject);
r.root.gameObject.SetActive(false);
}
}
@ -266,8 +292,8 @@ namespace GrassCutter
: _strike < 0.12f ? Mathf.Lerp(-26f, 50f, Mathf.Pow((_strike - 0.06f) / 0.06f, 2f))
: _strike < 0.2f ? 50f + Mathf.Sin((_strike - 0.12f) / 0.08f * Mathf.PI * 3f) * 4f * (1f - (_strike - 0.12f) / 0.08f)
: Mathf.Lerp(50f, 0f, Mathf.SmoothStep(0f, 1f, (_strike - 0.2f) / 0.36f));
rot = Quaternion.AngleAxis(a, Vector3.forward) * rot;
pos += new Vector3(-0.05f, -0.035f, 0.06f) * (Mathf.Max(0f, a) / 50f) + new Vector3(0.015f, 0.03f, -0.02f) * (Mathf.Max(0f, -a) / 26f);
rot = Quaternion.AngleAxis(a, Vector3.right) * rot;
pos += new Vector3(0f, -0.04f, 0.06f) * (Mathf.Max(0f, a) / 50f) + new Vector3(0f, 0.03f, -0.03f) * (Mathf.Max(0f, -a) / 26f);
}
// a new tool comes up from below with a turn of the wrist, and settles with a little overshoot
@ -275,7 +301,7 @@ namespace GrassCutter
float away = Mathf.Max(low, _hide);
pos += new Vector3(0.04f * low, -0.35f * away, 0f);
rot = Quaternion.Euler(25f * away, -10f * low, -35f * low) * rot;
rig.root.localPosition = pos;
rig.root.localPosition = pos + Shift;
rig.root.localRotation = rot;
rig.root.gameObject.SetActive(_hide < 0.99f);
}

View File

@ -415,7 +415,7 @@ namespace GrassCutter
var belt = _local.Tools.Belt;
bool rebuilt = false;
int slots = _local.BeltSlots.Value;
foreach (var t in belt) key.Append((int)t).Append(',');
foreach (var t in belt) key.Append((int)t).Append(GameDefs.IsPack(t) ? "x" + _local.Tools.PackLeft(GameDefs.PackTreat(t)) : "").Append(',');
key.Append('/').Append(slots);
if (key.ToString() != _beltKey)
{
@ -428,9 +428,19 @@ namespace GrassCutter
var slot = UIK.El("slot", _hotbar);
UIK.Text((n + 1).ToString(), "slot-key t-outline", slot);
if (n >= belt.Count) { slot.AddToClassList("slot-empty"); continue; }
var d = GameDefs.Tool(belt[n]);
UIK.Img(AssetBank.I.Tex(d.icon), "slot-icon", slot);
slot.tooltip = d.name;
if (GameDefs.IsPack(belt[n]))
{
var k = GameDefs.PackTreat(belt[n]);
UIK.Img(AssetBank.I.Tex(Treats.Icon(k)), "slot-icon", slot);
UIK.Text("×" + _local.Tools.PackLeft(k), "slot-count t-outline", slot);
slot.tooltip = Treats.Name(k);
}
else
{
var d = GameDefs.Tool(belt[n]);
UIK.Img(AssetBank.I.Tex(d.icon), "slot-icon", slot);
slot.tooltip = d.name;
}
_slots[belt[n]] = slot;
if (animate) UIK.PopIn(slot);
}
@ -555,7 +565,7 @@ namespace GrassCutter
float kg = v ? v.Load : tools.Bin(tools.Current);
float cap = v ? v.Capacity : tools.CurrentCap;
bool bin = cap > 0f;
_toolName.text = v ? v.Def.name : GameDefs.Tool(tools.Current).name;
_toolName.text = v ? v.Def.name : GameDefs.IsPack(tools.Current) ? Treats.Name(GameDefs.PackTreat(tools.Current)) + " ×" + tools.PackLeft(GameDefs.PackTreat(tools.Current)) : GameDefs.Tool(tools.Current).name;
_gauge.style.display = bin ? DisplayStyle.Flex : DisplayStyle.None;
_toolKg.style.display = bin ? DisplayStyle.Flex : DisplayStyle.None;
if (!bin) { _toolRate.text = ""; return; }
@ -847,7 +857,7 @@ namespace GrassCutter
string hint = null, voice = null;
var tools = _local.Tools;
float cap = tools.CurrentCap;
if (tools.Belt.Count == 0)
if (!tools.Belt.Exists(GameDefs.IsTool))
{
hint = Loc.F("Empty hands! Walk to the SUPPLY WALL on the west side of the deck and take the nail scissors ({0}).", Binds.Cap(Act.Interact));
voice = "asst_tools";

View File

@ -165,6 +165,14 @@ namespace GrassCutter
if (animate) UIK.SlideIn(_detail, new Vector2(40, 0), 0.05f, 0.3f);
}
/// <summary>Hang a tool back on the wall: the slot is free for another tool or a pack of treats.</summary>
void OffBelt(PlayerTools tools, ToolId t)
{
var b = UIK.Btn(Loc.T("TAKE OFF BELT"), () => { tools.Unequip(t); Sfx.Play("plastic_grab", 0.5f, 0.8f); Rebuild(false); }, "btn btn-small", _detail);
b.style.alignSelf = Align.Stretch;
b.style.marginTop = 8;
}
/// <summary>The button of the selected item: buy it, put it on the belt, or take it in hand.</summary>
void Action()
{
@ -193,11 +201,16 @@ namespace GrassCutter
double price = ts.ToolPrice(GameDefs.Tool(t));
Buy(price <= 0d ? Loc.T("TAKE IT") : Loc.F("BUY {0}", UIK.Money(price)), price, () => ts.BuyToolRpc((byte)t));
}
else if (tools.Current == t) Done(Loc.T("IN YOUR HANDS"));
else if (tools.Current == t)
{
Done(Loc.T("IN YOUR HANDS"));
OffBelt(tools, t);
}
else
{
var b = UIK.Btn(tools.Belt.Contains(t) ? Loc.T("TAKE IN HAND") : Loc.T("PUT ON BELT"), () => { tools.Equip(t); Sfx.Play("plastic_grab", 0.6f); Rebuild(false); }, "btn btn-green", _detail);
b.style.alignSelf = Align.Stretch;
if (tools.Belt.Contains(t)) OffBelt(tools, t);
}
}
}

View File

@ -72,6 +72,17 @@ namespace GrassCutter
static readonly Color NightSky = new Color(0.13f, 0.17f, 0.3f), NightMid = new Color(0.09f, 0.12f, 0.21f), NightLow = new Color(0.05f, 0.07f, 0.11f);
Light _sun, _lamp;
/// <summary>Rendering layer of things the headlamp leaves alone: whatever is held right in front of the eyes
/// and machines with lights of their own, which it only blew out to white. The sun and the lampposts still light them.</summary>
public const int NoLamp = 1 << 1;
public static void KeepOutOfLamp(GameObject root)
{
foreach (var r in root.GetComponentsInChildren<Renderer>(true)) r.renderingLayerMask = NoLamp;
// a machine's own lights still light it
foreach (var l in root.GetComponentsInChildren<Light>(true)) l.renderingLayerMask |= NoLamp;
}
float _sunPower;
Color _sunColor, _fog, _sky, _mid, _low;
ColorAdjustments _grade;
@ -153,7 +164,12 @@ namespace GrassCutter
_lamp.range = LampRange;
_lamp.color = new Color(1f, 0.95f, 0.85f);
_lamp.shadows = LightShadows.None;
_lamp.renderingLayerMask = ~NoLamp;
// every other light keeps lighting what the headlamp leaves alone
foreach (var l in FindObjectsByType<Light>(FindObjectsInactive.Include))
if (l != _lamp) l.renderingLayerMask |= NoLamp;
}
if (_sun && _sun.renderingLayerMask != -1) _sun.renderingLayerMask = -1;
var from = Rig ? Rig : cam.transform;
_lamp.transform.SetParent(from, false);
// a machine's floodlights join in while you drive it

View File

@ -8,6 +8,9 @@ namespace GrassCutter
{
public static DeckManager Instance { get; private set; }
public GameObject tileModel, ladderModel;
/// <summary>How far along each open edge from its middle the ladder hangs: clear of the intakes at the middle of
/// the edge tiles, in the opening the fence model leaves for it.</summary>
public const float LadderAt = 2.0f;
/// <summary>Deck-edge points that must stay open (the dock): the railing on that side of the tile is left out.</summary>
public Vector3[] gaps;
readonly Dictionary<int, DeckTileView> _views = new Dictionary<int, DeckTileView>();
@ -129,10 +132,26 @@ namespace GrassCutter
return bc;
}
float h = 1.0f, e = S * 0.5f - 0.12f;
v.colN = Rail("RailN", new Vector3(0, h * 0.5f, e), new Vector3(S, h, 0.1f));
v.colS = Rail("RailS", new Vector3(0, h * 0.5f, -e), new Vector3(S, h, 0.1f));
v.colE = Rail("RailE", new Vector3(e, h * 0.5f, 0), new Vector3(0.1f, h, S));
v.colW = Rail("RailW", new Vector3(-e, h * 0.5f, 0), new Vector3(0.1f, h, S));
// each railing stops either side of its ladder: the opening the fence model leaves there. The part of the rail
// beside the opening (the short piece out to the corner) is its own child of the main one, so SetEdges toggles both
float gapMid = LadderAt, gapHalf = 0.48f;
float lenA = S * 0.5f + gapMid - gapHalf, lenB = S * 0.5f - gapMid - gapHalf;
BoxCollider Split(string n, Vector3 normal, Vector3 along)
{
// `along` points from the corner at -S/2 to the one at +S/2; the ladder sits at +gapMid along it
var a = Rail(n, normal * e + Vector3.up * h * 0.5f + along * (-S * 0.5f + lenA * 0.5f), Abs(along * lenA) + Abs(normal) * 0.1f + Vector3.up * h);
var b = new GameObject(n + "_b") { layer = Physics.IgnoreRaycastLayer };
b.transform.SetParent(a.transform, false);
b.transform.position = a.transform.parent.TransformPoint(normal * e + Vector3.up * h * 0.5f + along * (S * 0.5f - lenB * 0.5f));
b.AddComponent<BoxCollider>().size = Abs(along * lenB) + Abs(normal) * 0.1f + Vector3.up * h;
return a;
}
static Vector3 Abs(Vector3 v) => new Vector3(Mathf.Abs(v.x), Mathf.Abs(v.y), Mathf.Abs(v.z));
// ladder spots: N at x = -LadderAt, S at x = +LadderAt, E at z = +LadderAt, W at z = -LadderAt
v.colN = Split("RailN", Vector3.forward, Vector3.left);
v.colS = Split("RailS", Vector3.back, Vector3.right);
v.colE = Split("RailE", Vector3.right, Vector3.forward);
v.colW = Split("RailW", Vector3.left, Vector3.back);
// ladders down to the meadow on every open edge (shown by SetEdges)
if (ladderModel)
{
@ -146,10 +165,10 @@ namespace GrassCutter
l.transform.localRotation = Quaternion.Euler(0, yaw, 0) * ladderModel.transform.localRotation;
}
// front of the ladder model hangs toward -Y Blender = +Z Unity (yaw 0 → toward +Z)
L(new Vector3(-1.5f, 0f, S * 0.5f), 0f);
L(new Vector3(1.5f, 0f, -S * 0.5f), 180f);
L(new Vector3(S * 0.5f, 0f, 1.5f), 90f);
L(new Vector3(-S * 0.5f, 0f, -1.5f), 270f);
L(new Vector3(-LadderAt, 0f, S * 0.5f), 0f);
L(new Vector3(LadderAt, 0f, -S * 0.5f), 180f);
L(new Vector3(S * 0.5f, 0f, LadderAt), 90f);
L(new Vector3(-S * 0.5f, 0f, -LadderAt), 270f);
}
foreach (var t in go.GetComponentsInChildren<Transform>(true)) t.gameObject.isStatic = false;
_views[packed] = v;

View File

@ -16,7 +16,7 @@ namespace GrassCutter
void Set(GameObject rail, BoxCollider col, bool open)
{
if (rail) rail.SetActive(open);
if (col) col.enabled = open;
if (col) col.gameObject.SetActive(open); // the rail's collider and the short piece past the ladder opening
}
Set(railN, colN, n); Set(railS, colS, s); Set(railE, colE, e); Set(railW, colW, w);
if (ladderRoot)

View File

@ -18,6 +18,9 @@ namespace GrassCutter
public GameObject[] spires = new GameObject[3];
public GameObject[] trees = new GameObject[3];
public GameObject bush;
/// <summary>More than trees and spires: field stones, slabs and crystals (they stay), and mushrooms, a stump and
/// bulb plants (they come down with the trees when their sector is mown clean).</summary>
public GameObject[] stones = new GameObject[0], growths = new GameObject[0];
const int Rings = 112, Spokes = 192, WildRocks = 800, Groves = 110;
const float FirstRing = 1f, RingGrowth = 1.06f, RockDraw = 1800f;
@ -352,6 +355,49 @@ namespace GrassCutter
Place(trees[rng.Next(3)], at, R(0f, 360f), R(1.2f, 2.2f), true, true);
}
}
Scatter();
}
/// <summary>Stones and odd growths over the meadow: a few round the clearing, the rest anywhere on the ball. A separate
/// sequence of its own, so the spires and the trees stand where they always have.</summary>
void Scatter()
{
var rng = new System.Random(9311);
float R(float a, float b) => a + (float)rng.NextDouble() * (b - a);
bool any = false;
foreach (var g in stones) any |= g;
foreach (var g in growths) any |= g;
if (!any) return;
GameObject Pick(GameObject[] set) => set.Length > 0 ? set[rng.Next(set.Length)] : null;
// close by, where the crew sees them from the first minute
for (int i = 0; i < 26; i++)
{
float a = R(0f, Mathf.PI * 2f), d = R(55f, 150f);
var dir = Planet.FromBase(Mathf.Cos(a) * d, Mathf.Sin(a) * d);
bool stone = rng.NextDouble() < 0.5;
var p = Pick(stone ? stones : growths);
if (!p) continue;
// the bulb plants are walked through; everything else is solid
Place(p, dir, R(0f, 360f), stone ? R(0.8f, 1.6f) : R(0.9f, 1.5f), p.name != "SM_BulbPlants", !stone);
}
int far = Mathf.Max(40, Mathf.RoundToInt(420 * Planet.Scale * Planet.Scale));
for (int i = 0; i < far; i++)
{
var dir = new Vector3(R(-1f, 1f), R(-1f, 1f), R(-1f, 1f)).normalized;
if (dir.y > 0.985f) continue;
bool stone = rng.NextDouble() < 0.55;
var p = Pick(stone ? stones : growths);
if (!p) continue;
// they come in little clusters of two or three
var e1 = Vector3.Cross(dir, Vector3.right).normalized;
var e2 = Vector3.Cross(dir, e1);
int n = rng.Next(1, 4);
for (int k = 0; k < n; k++)
{
var at = (dir + (e1 * R(-9f, 9f) + e2 * R(-9f, 9f)) / Planet.Radius).normalized;
Place(p, at, R(0f, 360f), stone ? R(0.7f, 2.2f) : R(0.8f, 1.7f), p.name != "SM_BulbPlants", !stone);
}
}
}
/// <summary>70 m round each far station, on any ball.</summary>

View File

@ -0,0 +1,83 @@
using System.Collections.Generic;
using UnityEngine;
namespace GrassCutter
{
/// <summary>
/// The small life of things standing about: a dish panning slowly over the sky, a windsock or a whip aerial swaying (more
/// in a wind), a sensor turning, robot eyes blinking now and then. Parts are found by the names the models give them
/// (Dish, Sway*, SpinSensor, Blink*); anything another script already drives is left to it.
/// </summary>
public class IdleMotion : MonoBehaviour
{
struct Part
{
public Transform t;
public int kind; // 0 dish, 1 sway, 2 spin, 3 blink
public Vector3 axis, scale;
public float phase;
}
readonly List<Part> _parts = new List<Part>();
float _blinkAt;
/// <summary>Adds the motion to whatever under root has parts for it; nothing if there are none.</summary>
public static void Attach(GameObject root)
{
if (root && !root.GetComponent<IdleMotion>()) root.AddComponent<IdleMotion>();
}
void Start()
{
// a mowbot looks after its own spinning, swaying and blinking
bool bot = GetComponentInChildren<Mowbot>(true);
var up = transform.up;
foreach (var t in GetComponentsInChildren<Transform>(true))
{
var n = t.name;
int kind = n == "Dish" ? 0 : n.StartsWith("Sway") ? 1 : n == "SpinSensor" ? 2 : n.StartsWith("Blink") ? 3 : -1;
if (kind < 0 || (bot && kind != 0)) continue;
int ax = BaseRot.LocalAxisFor(t, kind == 1 ? transform.right : up);
var axis = ax == 0 ? Vector3.right : ax == 1 ? Vector3.up : Vector3.forward;
BaseRot.Of(t);
_parts.Add(new Part { t = t, kind = kind, axis = axis, scale = t.localScale, phase = Random.value * 20f });
}
if (_parts.Count == 0) { enabled = false; return; }
_blinkAt = Time.time + Random.Range(2f, 6f);
}
void LateUpdate()
{
float time = Time.time;
float wind = WeatherFx.Wind;
bool blink = false;
if (time >= _blinkAt)
{
blink = time < _blinkAt + 0.14f;
if (!blink) _blinkAt = time + Random.Range(2.5f, 7f);
}
foreach (var p in _parts)
{
if (!p.t) continue;
switch (p.kind)
{
case 0:
// a slow look round the sky, resting a while at each end
float pan = Mathf.SmoothStep(-1f, 1f, Mathf.PingPong((time + p.phase) / 9f, 1f)) * 22f;
p.t.localRotation = BaseRot.Of(p.t) * Quaternion.AngleAxis(pan, p.axis);
break;
case 1:
float a = (Mathf.Sin(time * 1.7f + p.phase) * 0.6f + Mathf.Sin(time * 2.9f + p.phase * 1.3f) * 0.4f) * (3f + wind * 14f);
p.t.localRotation = BaseRot.Of(p.t) * Quaternion.AngleAxis(a, p.axis);
break;
case 2:
p.t.localRotation = BaseRot.Of(p.t) * Quaternion.AngleAxis((time + p.phase) * 45f, p.axis);
break;
case 3:
p.t.localScale = blink ? Vector3.Scale(p.scale, Vector3.one - p.axis * 0.85f) : p.scale;
break;
}
}
}
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 51865f698a1604544a299f2935db2195

View File

@ -69,6 +69,20 @@ namespace GrassCutter
public static Quaternion Frame { get; private set; } = Quaternion.identity;
public static Vector3 Up(Vector3 p) => (p - Center).normalized;
/// <summary>
/// Which way the soil itself faces: straight up on the flat the base stands on, the ball's own up out past it, blended
/// across the ring where the flat bends down onto the ball. Standing to this keeps the horizon level: on a small
/// ball the flat's far side leans tens of degrees off the ball's up, and a head stood to the ball saw it tilted.
/// </summary>
public static Vector3 Level(Vector3 p)
{
var up = Up(p);
float s = Mathf.Sqrt(Mathf.Max(0f, 2f - 2f * up.y)) * Radius;
if (s >= ClearB) return up;
if (s <= ClearA) return Vector3.up;
return Vector3.Slerp(Vector3.up, up, Mathf.SmoothStep(0f, 1f, (s - ClearA) / (ClearB - ClearA))).normalized;
}
public static Vector3 OnSurface(Vector3 dir) => Center + dir * (Radius + HeightAt(dir));
public static Vector3 Surface(Vector3 p) => OnSurface(Up(p));
public static bool InNorthCap(Vector3 p) => p.y > NorthCapY;

View File

@ -1,3 +1,4 @@
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
@ -186,18 +187,64 @@ namespace GrassCutter
var at = ground + Planet.Frame * new Vector3(o.x, 0f, o.y) + up * (lift + Random.Range(0f, 6f)) - windDir * 4f;
Fx.Emit(_drops, at, fall * Random.Range(0.9f, 1.1f), Random.Range(0.045f, 0.07f), tint, (lift + 3f) / 24f);
}
_splashDue += dt * 70f * r;
_splashDue += dt * 110f * r;
for (; _splashDue >= 1f; _splashDue -= 1f)
{
// where a drop lands: on whatever stands there (deck, roof, machine), else on the soil
var o = Random.insideUnitCircle * 12f;
var at = Planet.Surface(eye + Planet.Frame * new Vector3(o.x, 0f, o.y));
if (Vector3.Dot(eye - at, up) > 25f) break;
var on = Fx.Surface.Ground;
if (Physics.Raycast(at + up * 30f, -up, out var hit, 31f, HitMask, QueryTriggerInteraction.Ignore) && Vector3.Dot(hit.point - at, up) > -0.05f)
{
at = hit.point;
on = SurfaceOf(hit.collider);
}
else if (MowMap.Yield(at) > 0.3f) on = Fx.Surface.Grass;
Fx.Emit(_splash, at + up * 0.05f, up * 0.4f, Random.Range(0.08f, 0.16f), new Color(tint.r, tint.g, tint.b, 0.5f));
Fx.RainHit(at, up, on, tint, Acid);
}
}
Volume(ref _rainLoop, "rain_loop", r * (0.55f + Storm * 0.25f));
}
const int HitMask = (1 << Layers.Default) | (1 << Layers.Build) | (1 << Layers.Vehicle) | (1 << Layers.Prop);
static readonly Dictionary<Collider, Fx.Surface> s_surface = new Dictionary<Collider, Fx.Surface>();
/// <summary>What a collider is made of, as far as rain can tell: machines and vehicles are metal, the deck and what is
/// built of planks is wood, anything else by its material's name.</summary>
static Fx.Surface SurfaceOf(Collider c)
{
if (s_surface.TryGetValue(c, out var k)) return k;
k = Fx.Surface.Ground;
if (c.gameObject.layer == Layers.Vehicle || c.GetComponentInParent<Vehicle>()) k = Fx.Surface.Metal;
else if (c.GetComponentInParent<DeckTileView>()) k = Fx.Surface.Wood;
else if (c.GetComponentInParent<BuildPiece>() is BuildPiece bp)
{
switch (bp.piece)
{
case PieceId.Wall: case PieceId.WindowWall: case PieceId.DoorWall: case PieceId.Railing: case PieceId.Fence:
case PieceId.Floor: case PieceId.FlatRoof: case PieceId.Roof: case PieceId.Stairs: case PieceId.Steps:
case PieceId.Pillar: case PieceId.Planter: case PieceId.Bench: case PieceId.Crates: case PieceId.Square: case PieceId.Hex:
k = Fx.Surface.Wood; break;
default: k = Fx.Surface.Metal; break;
}
}
else
{
var r = c.GetComponent<Renderer>();
if (!r) r = c.GetComponentInParent<Renderer>();
if (!r && c.transform.parent) r = c.transform.parent.GetComponentInChildren<Renderer>();
var n = r && r.sharedMaterial ? r.sharedMaterial.name.ToLowerInvariant() : c.name.ToLowerInvariant();
if (n.Contains("metal") || n.Contains("iron") || n.Contains("steel") || n.Contains("hull") || n.Contains("tin") || n.Contains("chrome") || n.Contains("paint")) k = Fx.Surface.Metal;
else if (n.Contains("wood") || n.Contains("plank") || n.Contains("timber") || n.Contains("log") || n.Contains("bark") || n.Contains("tree") || n.Contains("hay") || n.Contains("deck")) k = Fx.Surface.Wood;
}
if (s_surface.Count > 4000) s_surface.Clear();
s_surface[c] = k;
return k;
}
void TickWind(Vector3 eye, Vector3 up, Vector3 windDir, float dt)
{
float w = Mathf.Max(Wind, Storm * 0.6f);