Grass Cutters Together: the project as of moon-sweepers f3666f0

A clean start for the shared repository: the Unity project (Assets, Packages, ProjectSettings), ArtSource, Docs and
Tools as they stood at f3666f0 in the old local repository, with its generated prefabs and scene brought up to date.
Images, audio, models and binaries go through Git LFS (.gitattributes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
NiemandKG
2026-11-06 18:44:40 +06:00
parent 0f0467cd0c
commit d1c3761e58
4190 changed files with 270757 additions and 1 deletions

View File

@ -0,0 +1,77 @@
using UnityEngine;
namespace GrassCutter
{
public enum Crop : byte { Grass, Wheat, Oats, Corn, Sunflowers }
/// <summary>
/// Most of Herbaria-7 is grass, but wild stands of wheat, oats, corn and sunflowers grow up through it. The grass under
/// them is the same grass as everywhere. They cut and count like grass, and a field sector pays more when it's mown clean. Which sector grows what follows from where it
/// is, so every peer sees the same fields and nothing has to be saved. Four fields stand near the base.
/// </summary>
public static class Crops
{
const float FieldSize = 190f, Rare = 0.69f, BaseClear = 115f, FirstRadius = 48f, StationClear = 0.99985f;
static readonly (Crop crop, float x, float z)[] First =
{
(Crop.Wheat, 165f, 40f), (Crop.Sunflowers, -150f, 105f), (Crop.Oats, 40f, -180f), (Crop.Corn, -125f, -150f),
};
public static Crop At(int id) => At(HexGrid.Get(id));
public static Crop At(HexGrid.Sector s)
{
if (s.crop < 0) s.crop = (sbyte)Grows(s.c);
return (Crop)s.crop;
}
/// <summary>The middle of the first field of this kind, near the base.</summary>
public static Vector3 FirstField(Crop crop)
{
foreach (var f in First) if (f.crop == crop) return Planet.FromBase(f.x, f.z);
return Planet.FromBase(0f, 0f);
}
public static string Name(Crop crop) => crop switch
{
Crop.Wheat => Loc.T("Wheat"), Crop.Oats => Loc.T("Oats"), Crop.Corn => Loc.T("Corn"), Crop.Sunflowers => Loc.T("Sunflowers"), _ => Loc.T("Sector"),
};
/// <summary>The sector bonus is worth this many times more.</summary>
public static double Pays(Crop crop) => crop == Crop.Sunflowers ? 3d : crop == Crop.Corn ? 2d : crop == Crop.Grass ? 1d : 1.5d;
static Crop Grows(Vector3 dir)
{
foreach (var f in First)
if ((dir - Planet.FromBase(f.x, f.z)).magnitude * Planet.Radius < FirstRadius) return f.crop;
if ((dir - Planet.FromBase(0f, 0f)).magnitude * Planet.Radius < BaseClear) return Crop.Grass;
for (int i = 1; i < Stations.Count; i++) if (Vector3.Dot(dir, Stations.Dir(i)) > StationClear) return Crop.Grass;
var at = dir * (Planet.Radius / FieldSize);
if (Noise(at) < Rare) return Crop.Grass;
float kind = Noise(at * 0.37f + new Vector3(41f, 7f, 23f));
return kind < 0.42f ? Crop.Wheat : kind < 0.5f ? Crop.Oats : kind < 0.58f ? Crop.Corn : Crop.Sunflowers;
}
static float Noise(Vector3 p)
{
int x = Mathf.FloorToInt(p.x), y = Mathf.FloorToInt(p.y), z = Mathf.FloorToInt(p.z);
float fx = Smooth(p.x - x), fy = Smooth(p.y - y), fz = Smooth(p.z - z);
float a = Mathf.Lerp(Mathf.Lerp(Hash(x, y, z), Hash(x + 1, y, z), fx), Mathf.Lerp(Hash(x, y + 1, z), Hash(x + 1, y + 1, z), fx), fy);
float b = Mathf.Lerp(Mathf.Lerp(Hash(x, y, z + 1), Hash(x + 1, y, z + 1), fx), Mathf.Lerp(Hash(x, y + 1, z + 1), Hash(x + 1, y + 1, z + 1), fx), fy);
return Mathf.Lerp(a, b, fz);
}
static float Smooth(float t) => t * t * (3f - 2f * t);
static float Hash(int x, int y, int z)
{
unchecked
{
uint h = (uint)x * 374761393u + (uint)y * 668265263u + (uint)z * 2147483647u;
h = (h ^ (h >> 13)) * 1274126177u;
return (h ^ (h >> 16)) / (float)uint.MaxValue;
}
}
}
}