public bool PlaceNestedObject(NestedObject objInstance) { if (objInstance == null) { return(UnplaceNestedObject()); } if (objInstance.IsValidPosition(this) == false) { Debug.ULogErrorChannel("Tile", "Trying to assign a NestedObject to a tile that isn't valid!"); return(false); } for (int x_off = X; x_off < X + objInstance.Width; x_off++) { for (int y_off = Y; y_off < Y + objInstance.Height; y_off++) { Tile t = World.Current.GetTileAt(x_off, y_off, Z); t.NestedObject = objInstance; } } return(true); }
/// <summary> /// Used to place NestedObject in a certain position. /// </summary> /// <param name="proto">The prototype NestedObject to place.</param> /// <param name="tile">The base tile to place the NestedObject on, The tile will be the bottom left corner of the NestedObject (to check).</param> /// <returns>NestedObject object.</returns> public static NestedObject PlaceInstance(NestedObject proto, Tile tile) { if (proto.IsValidPosition(tile) == false) { Debug.ULogErrorChannel("NestedObject", "PlaceInstance -- Position Validity Function returned FALSE. " + proto.Name + " " + tile.X + ", " + tile.Y + ", " + tile.Z); return(null); } // We know our placement destination is valid. NestedObject nestObj = proto.Clone(); nestObj.Tile = tile; if (tile.PlaceNestedObject(nestObj) == false) { // For some reason, we weren't able to place our object in this tile. // (Probably it was already occupied.) // Do NOT return our newly instantiated object. // (It will be garbage collected.) return(null); } // plug-in NestedObject only when it is placed in world if (nestObj.PowerConnection != null) { World.Current.PowerNetwork.PlugIn(nestObj.PowerConnection); } // need to update reference to NestedObject and call Initialize (so components can place hooks on events there) foreach (var comp in nestObj.components) { comp.Initialize(nestObj); } if (nestObj.LinksToNeighbour != string.Empty) { // This type of NestedObject links itself to its neighbours, // so we should inform our neighbours that they have a new // buddy. Just trigger their OnChangedCallback. int x = tile.X; int y = tile.Y; for (int xpos = x - 1; xpos < x + proto.Width + 1; xpos++) { for (int ypos = y - 1; ypos < y + proto.Height + 1; ypos++) { Tile tileAt = World.Current.GetTileAt(xpos, ypos, tile.Z); if (tileAt != null && tileAt.NestedObject != null && tileAt.NestedObject.Changed != null) { tileAt.NestedObject.Changed(tileAt.NestedObject); } } } } // Let our workspot tile know it is reserved for us World.Current.ReserveTileAsWorkSpot(nestObj); // Call LUA install scripts nestObj.EventActions.Trigger("OnInstall", nestObj); // Update thermalDiffusivity using coefficient float thermalDiffusivity = Temperature.defaultThermalDiffusivity; if (nestObj.Parameters.ContainsKey("thermal_diffusivity")) { thermalDiffusivity = nestObj.Parameters["thermal_diffusivity"].ToFloat(); } World.Current.temperature.SetThermalDiffusivity(tile.X, tile.Y, tile.Z, thermalDiffusivity); return(nestObj); }