From 7d7970f777109565c91274a8dea1e47569ebcf18 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Mon, 26 Feb 2018 13:34:33 -0500 Subject: [PATCH] Core/Grid: Fixed error with check if old cell != new cell --- Source/Game/Maps/Cell.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Source/Game/Maps/Cell.cs b/Source/Game/Maps/Cell.cs index 66c708066..de8d3f20d 100644 --- a/Source/Game/Maps/Cell.cs +++ b/Source/Game/Maps/Cell.cs @@ -59,6 +59,29 @@ namespace Game.Maps public bool NoCreate() { return data.nocreate; } public void SetNoCreate() { data.nocreate = true; } + public static bool operator ==(Cell left, Cell right) + { + if (ReferenceEquals(left, right)) + return true; + + if (ReferenceEquals(left, null) || ReferenceEquals(right, null)) + return false; + + return left.data.cell_x == right.data.cell_x && left.data.cell_y == right.data.cell_y + && left.data.grid_x == right.data.grid_x && left.data.grid_y == right.data.grid_y; + } + public static bool operator !=(Cell left, Cell right) { return !(left == right); } + + public override bool Equals(object obj) + { + return obj is Cell && this == (Cell)obj; + } + + public override int GetHashCode() + { + return (int)(data.cell_x ^ data.cell_y ^ data.grid_x ^ data.grid_y); + } + public override string ToString() { return string.Format("grid[{0}, {1}]cell[{2}, {3}]", GetGridX(), GetGridY(), GetCellX(), GetCellY());