Files
Christopher Wiebe b451f83174 Initial commit: Theriapolis baseline at port/godot branch point
Captures the pre-Godot-port state of the codebase. This is the rollback
anchor for the Godot port (M0 of theriapolis-rpg-implementation-plan-godot-port.md).
All Phase 0 through Phase 6.5 work is included; Phase 7 is in flight.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-30 20:40:51 -07:00

42 lines
1.8 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
namespace Theriapolis.Core.Tactical;
/// <summary>
/// Integer (cx, cy) key for a tactical chunk. The chunk covers world-pixel
/// rectangle [cx*CHUNK_SIZE, cy*CHUNK_SIZE, (cx+1)*CHUNK_SIZE, (cy+1)*CHUNK_SIZE).
/// At the current constants (CHUNK_SIZE = 64, TACTICAL_PER_WORLD_TILE = 32),
/// each chunk covers 2×2 world tiles.
/// </summary>
public readonly struct ChunkCoord : IEquatable<ChunkCoord>
{
public readonly int X;
public readonly int Y;
public ChunkCoord(int x, int y) { X = x; Y = y; }
/// <summary>Chunk that contains the given tactical-tile (world-pixel) coordinate.</summary>
public static ChunkCoord ForTactical(int tx, int ty)
=> new(FloorDiv(tx, C.TACTICAL_CHUNK_SIZE), FloorDiv(ty, C.TACTICAL_CHUNK_SIZE));
/// <summary>Chunk that contains the given world-tile coordinate.</summary>
public static ChunkCoord ForWorldTile(int wx, int wy)
{
// 1 world tile = TACTICAL_PER_WORLD_TILE world pixels = TACTICAL_PER_WORLD_TILE
// tactical tiles. One chunk covers CHUNK_SIZE / TACTICAL_PER_WORLD_TILE world tiles.
int worldTilesPerChunk = C.TACTICAL_CHUNK_SIZE / C.TACTICAL_PER_WORLD_TILE;
return new(FloorDiv(wx, worldTilesPerChunk), FloorDiv(wy, worldTilesPerChunk));
}
private static int FloorDiv(int a, int b)
{
int q = a / b;
if ((a ^ b) < 0 && q * b != a) q--;
return q;
}
public bool Equals(ChunkCoord other) => X == other.X && Y == other.Y;
public override bool Equals(object? obj) => obj is ChunkCoord c && Equals(c);
public override int GetHashCode() => HashCode.Combine(X, Y);
public static bool operator ==(ChunkCoord a, ChunkCoord b) => a.Equals(b);
public static bool operator !=(ChunkCoord a, ChunkCoord b) => !a.Equals(b);
public override string ToString() => $"({X},{Y})";
}