private void TryPopCurrentSkep() { Block skepToPopBlock = Api.World.BlockAccessor.GetBlock(skepToPop); if (skepToPopBlock == null || !(skepToPopBlock is BlockSkep)) { // Skep must have changed since last time we checked, so lets restart this.skepToPop = null; return; } string orient = skepToPopBlock.LastCodePart(); string blockcode = "skep-populated-" + orient; Block fullSkep = Api.World.GetBlock(new AssetLocation(blockcode)); if (fullSkep == null) { Api.World.Logger.Warning("BEBeehive.TryPopSkep() - block with code {0} does not exist?", blockcode); return; } Api.World.BlockAccessor.SetBlock(fullSkep.BlockId, skepToPop); hivePopSize = EnumHivePopSize.Poor; this.skepToPop = null; }
public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldForResolving) { base.FromTreeAttributes(tree, worldForResolving); bool wasHarvestable = Harvestable; scanIteration = tree.GetInt("scanIteration"); quantityNearbyFlowers = tree.GetInt("quantityNearbyFlowers"); quantityNearbyHives = tree.GetInt("quantityNearbyHives"); emptySkeps.Clear(); TreeAttribute emptySkepTree = tree["emptyskeps"] as TreeAttribute; for (int i = 0; i < emptySkepTree.Count / 3; i++) { emptySkeps.Add(new BlockPos( emptySkepTree.GetInt("posX-" + i), emptySkepTree.GetInt("posY-" + i), emptySkepTree.GetInt("posZ-" + i) )); } scanQuantityNearbyFlowers = tree.GetInt("scanQuantityNearbyFlowers"); scanQuantityNearbyHives = tree.GetInt("scanQuantityNearbyHives"); scanEmptySkeps.Clear(); TreeAttribute scanEmptySkepTree = tree["scanEmptySkeps"] as TreeAttribute; for (int i = 0; scanEmptySkepTree != null && i < scanEmptySkepTree.Count / 3; i++) { scanEmptySkeps.Add(new BlockPos( scanEmptySkepTree.GetInt("posX-" + i), scanEmptySkepTree.GetInt("posY-" + i), scanEmptySkepTree.GetInt("posZ-" + i) )); } isWildHive = tree.GetInt("isWildHive") > 0; Harvestable = tree.GetInt("harvestable") > 0; int x = tree.GetInt("skepToPopX"); int y = tree.GetInt("skepToPopY"); int z = tree.GetInt("skepToPopZ"); if (x != 0 || y != 0 || z != 0) { skepToPop = new BlockPos(x, y, z); } else { skepToPop = null; } beginPopStartTotalHours = tree.GetDouble("beginPopStartTotalHours"); popHiveAfterHours = tree.GetFloat("popHiveAfterHours"); cooldownUntilTotalHours = tree.GetDouble("cooldownUntilTotalHours"); harvestableAtTotalHours = tree.GetDouble("harvestableAtTotalHours"); hivePopSize = (EnumHivePopSize)tree.GetInt("hiveHealth"); if (Harvestable != wasHarvestable && Api != null) { MarkDirty(true); } }
private void OnScanComplete() { quantityNearbyFlowers = scanQuantityNearbyFlowers; quantityNearbyHives = scanQuantityNearbyHives; emptySkeps = new List <BlockPos>(scanEmptySkeps); if (emptySkeps.Count == 0) { skepToPop = null; } hivePopSize = (EnumHivePopSize)GameMath.Clamp(quantityNearbyFlowers - 3 * quantityNearbyHives, 0, 2); MarkDirty(); if (3 * quantityNearbyHives + 3 > quantityNearbyFlowers) { skepToPop = null; MarkDirty(false); return; } if (skepToPop != null && Api.World.Calendar.TotalHours > beginPopStartTotalHours + popHiveAfterHours) { TryPopCurrentSkep(); cooldownUntilTotalHours = Api.World.Calendar.TotalHours + 4 / 2 * 24; MarkDirty(false); return; } // Default Spread speed: Once every 4 in game days * factor // Don't spread at all if 3 * livinghives + 3 > flowers // factor = Clamped(livinghives / Math.Sqrt(flowers - 3 * livinghives - 3), 1, 1000) // After spreading: 4 extra days cooldown float swarmability = GameMath.Clamp(quantityNearbyFlowers - 3 - 3 * quantityNearbyHives, 0, 20) / 5f; // We want to translate the swarmability value 0..4 // into swarm days 12..0 float swarmInDays = (4 - swarmability) * 2.5f; if (swarmability <= 0) { skepToPop = null; } if (skepToPop != null) { float newPopHours = 24 * swarmInDays; this.popHiveAfterHours = (float)(0.75 * popHiveAfterHours + 0.25 * newPopHours); if (!emptySkeps.Contains(skepToPop)) { skepToPop = null; MarkDirty(false); return; } } else { popHiveAfterHours = 24 * swarmInDays; beginPopStartTotalHours = Api.World.Calendar.TotalHours; float mindistance = 999; BlockPos closestPos = new BlockPos(); foreach (BlockPos pos in emptySkeps) { float dist = pos.DistanceTo(this.Pos); if (dist < mindistance) { mindistance = dist; closestPos = pos; } } skepToPop = closestPos; } }