static public bool UpdateLocation(ZDObject Caller) { //Update location only if caller is inside the map and it's registered. if (IsWorldInMap(Caller.transform.position) && IsRegistered(Caller)) { (uint, uint)NewMapLoc = WorldToMap(Caller.transform.position); (uint, uint)PrevMapLoc = Recorder[Caller].Location; ZDGridBlock PrevBlock = RecordGrid[PrevMapLoc.Item1, PrevMapLoc.Item2]; ZDGridBlock NewBlock = RecordGrid[NewMapLoc.Item1, NewMapLoc.Item2]; if (NewMapLoc == PrevMapLoc) { //location remains, no need to update. return(false); } else if (!RemoveFromRecordGrids(Recorder[Caller])) { //TODO: Error Log: This should not happen in general. Debug.LogError("Cannot Remove From Record Grids"); return(false); } else { //Update Position. Recorder[Caller].Location = NewMapLoc; AddToRecordGrids(Recorder[Caller]); } return(true); } return(false); }
static void InitializeMap() { RecordGrid = new ZDGridBlock[ZDGameRule.MAP_WIDTH_UNIT, ZDGameRule.MAP_HEIGHT_UNIT]; Recorder = new Dictionary <ZDObject, ZDObjectRecord>(); //Initilize Record Grid for (int i = 0; i < ZDGameRule.MAP_WIDTH_UNIT; ++i) { for (int j = 0; j < ZDGameRule.MAP_HEIGHT_UNIT; ++j) { RecordGrid[i, j] = new ZDGridBlock(); } } }