public void NullifyExtensionLink(PlaneExtension e) { if (extension == e) { extension = null; } }
public static Plane Load(System.IO.Stream fs, IPlanable host) { var data = new byte[9]; fs.Read(data, 0, data.Length); int materialID = System.BitConverter.ToInt32(data, 2); Plane p; if (data[0] == BASIC_PLANE_CODE) { p = new Plane(host, (MeshType)data[1], materialID, data[6], data[7]); } else { p = new MultimaterialPlane(host, (MeshType)data[1], data[6], data[7]); } switch (data[8]) { case 1: PlaneExtension.Load(fs, p); break; case 2: Structure.LoadStructure(fs, p); break; } return(p); }
public PlaneExtension FORCED_GetExtension() { if (extension == null) { extension = new PlaneExtension(this, mainStructure); } return(extension); }
public override bool Equals(object obj) { // Check for null values and compare run-time types. if (obj == null || GetType() != obj.GetType()) { return(false); } PlaneExtension pe = (PlaneExtension)obj; return(pe.myPlane == myPlane && map == pe.map); }
public static PlaneExtension Load(System.IO.Stream fs, Plane p) { var pe = new PlaneExtension(p, null); var data = new byte[4]; fs.Read(data, 0, data.Length); int structuresCount = System.BitConverter.ToInt32(data, 0); if (structuresCount > INNER_RESOLUTION * INNER_RESOLUTION || structuresCount < 0) { Debug.Log("surface block load error - incorrect structures count"); GameMaster.LoadingFail(); return(null); } else { if (structuresCount > 0) { Structure.LoadStructures(structuresCount, fs, p); } } return(pe); }
override protected void LabourResult(int iterations) { if (iterations < 1) { return; } workflow -= iterations; actionLabel = ""; int length = PlaneExtension.INNER_RESOLUTION / ScalableHarvestableResource.RESOURCE_STICK_RECT_SIZE; bool?[,] pillarsMap = new bool?[length, length]; // true - full pillar, false - unfinished, null - no pillar for (int a = 0; a < length; a++) { for (int b = 0; b < length; b++) { pillarsMap[a, b] = null; } } int maxPillarsCount = length * length; int emptyPositions = maxPillarsCount; int finishedPillarsCount = 0, totalResourcesCount = 0, deletedStructures = 0; var unfinishedPillarsList = new List <ScalableHarvestableResource>(); ScalableHarvestableResource shr = null; PlaneExtension pe = workplace.FORCED_GetExtension(); // создаем запросом, так как все равно понадобится while (iterations > 0) { iterations--; if (pe.fulfillStatus != FullfillStatus.Empty) { // на поверхности есть какие-то структуры byte maxVolume = ScalableHarvestableResource.MAX_STICK_VOLUME; int i = 0; var strs = pe.GetStructuresList(); while (i < strs.Count) { shr = strs[i] as ScalableHarvestableResource; if (shr != null) { if (shr.mainResource != rtype) { shr.Harvest(); } else { if (shr.resourceCount == maxVolume) { finishedPillarsCount++; pillarsMap[shr.surfaceRect.x / ScalableHarvestableResource.RESOURCE_STICK_RECT_SIZE, shr.surfaceRect.z / ScalableHarvestableResource.RESOURCE_STICK_RECT_SIZE] = true; } else { unfinishedPillarsList.Add(shr); pillarsMap[shr.surfaceRect.x / ScalableHarvestableResource.RESOURCE_STICK_RECT_SIZE, shr.surfaceRect.z / ScalableHarvestableResource.RESOURCE_STICK_RECT_SIZE] = false; totalResourcesCount += shr.resourceCount; } } } else { Structure s = strs[i]; if (s.isArtificial) { s.Annihilate(StructureAnnihilationOrder.GrindedByWorksite); return; } else { if (s.ID == Structure.PLANT_ID) { (s as Plant).Harvest(false); } else { s.Annihilate(StructureAnnihilationOrder.GrindedByWorksite); } deletedStructures++; if (deletedStructures >= 4) { break; // не больше 4-х удалений за тик } } } i++; } } shr = null; if (finishedPillarsCount == maxPillarsCount) { if (iterations == 0) { actionLabel = Localization.GetActionLabel(LocalizationActionLabels.BlockCompleted); } var cpos = workplace.pos; switch (workplace.faceIndex) { case Block.FWD_FACE_INDEX: cpos = new ChunkPos(cpos.x, cpos.y, cpos.z + 1); break; case Block.RIGHT_FACE_INDEX: cpos = new ChunkPos(cpos.x + 1, cpos.y, cpos.z); break; case Block.BACK_FACE_INDEX: cpos = new ChunkPos(cpos.x, cpos.y, cpos.z - 1); break; case Block.LEFT_FACE_INDEX: cpos = new ChunkPos(cpos.x - 1, cpos.y, cpos.z); break; case Block.UP_FACE_INDEX: cpos = new ChunkPos(cpos.x, cpos.y + 1, cpos.z); break; case Block.DOWN_FACE_INDEX: cpos = new ChunkPos(cpos.x, cpos.y - 1, cpos.z); break; } workplace.myChunk.AddBlock(cpos, rtype.ID, false, true); pe.ClearSurface(PlaneAnnihilationOrder.BlockbuildingPartsReplacement); StopWork(true); return; } else { totalResourcesCount += finishedPillarsCount * ScalableHarvestableResource.MAX_STICK_VOLUME; int unfinishedCount = unfinishedPillarsList.Count; byte resourceNeeded = ScalableHarvestableResource.RESOURCES_PER_LEVEL; float resourceTaken = colony.storage.GetResources(rtype, resourceNeeded); bool newContainerCreated = false; if (unfinishedCount + finishedPillarsCount < maxPillarsCount) { if (Random.value > 0.5f && resourceTaken == resourceNeeded) // creating new container { var emptyPositionsIndexes = new List <int>(); for (int x = 0; x < length; x++) { for (int z = 0; z < length; z++) { if (pillarsMap[x, z] == null) { emptyPositionsIndexes.Add(x * length + z); } } } int epcount = emptyPositionsIndexes.Count; if (epcount > 0) { int combinedIndex = emptyPositionsIndexes[Random.Range(0, epcount)]; ScalableHarvestableResource.Create(rtype, resourceNeeded, workplace, new PixelPosByte( (combinedIndex / length) * ScalableHarvestableResource.RESOURCE_STICK_RECT_SIZE, (combinedIndex % length) * ScalableHarvestableResource.RESOURCE_STICK_RECT_SIZE) ); newContainerCreated = true; } emptyPositionsIndexes = null; } } // докидываем в существующий if (unfinishedCount > 0) { if (newContainerCreated) { resourceTaken = colony.storage.GetResources(rtype, resourceNeeded); } if (resourceTaken > 1) { shr = unfinishedPillarsList[Random.Range(0, unfinishedCount)]; resourceTaken = shr.AddResource(rtype, resourceTaken); if (resourceTaken > 0) { colony.storage.AddResource(rtype, resourceTaken); } } else { if (showOnGUI && iterations == 0) { actionLabel = Localization.GetAnnouncementString(GameAnnouncements.NotEnoughResources); } } } } } }