Ejemplo n.º 1
0
        private static int GetRandomNpcAmountByLevel(int level)
        {
            var min = GetRandomNpcMinimum(level);
            var max = GetRandomNpcMaximum(level);

            return(FastRandom.NextInt(min, max));
        }
        public void SetRandomName()
        {
            var nameString = FastRandom.NextString(3);
            var nameNumber = FastRandom.NextInt(0, 999);

            Name = $"{nameString.ToUpper()}-{nameNumber}";
        }
Ejemplo n.º 3
0
        private static LootGeneratorItemInfo CreateNpcLootInfoFromRecord(IDataRecord record)
        {
            var definition = record.GetValue <int>(k.lootDefinition.ToLower());
            var minq       = record.GetValue <int>("minquantity");
            var maxq       = record.GetValue <int>(k.quantity);
            var item       = new ItemInfo(definition, FastRandom.NextInt(minq, maxq))
            {
                IsRepackaged = record.GetValue <bool>(k.repackaged)
            };

            var damageit = !record.GetValue <bool>(k.dontdamage);
            var damaged  = false;

            if (!item.EntityDefault.AttributeFlags.Repackable)
            {
                //force false
                item.IsRepackaged = false;
                damageit          = false;
            }

            //is it forced to be repacked from config AND damageable?
            if (!item.IsRepackaged && damageit)
            {
                //no, so damage it!
                damaged = true;
            }

            var probability = record.GetValue <double>(k.probability);

            return(new LootGeneratorItemInfo(item, damaged, probability));
        }
        protected override void OnUpdate(TimeSpan time)
        {
            base.OnUpdate(time);

            _updateInterval.Update(time);

            if (!_updateInterval.Passed)
            {
                return;
            }

            _updateInterval.Interval = TimeSpan.FromMilliseconds(CycleTime + FastRandom.NextInt(-2, 2));
            _updateInterval.Reset();

            var onlineStatus = OnlineStatus;

            if (!this.IsFullyConstructed() || !onlineStatus)
            {
                return;
            }

            var zone = Zone;

            if (zone == null)
            {
                return;
            }

            if (Interlocked.CompareExchange(ref _inProgress, 1, 0) == 1)
            {
                return;
            }

            Task.Run(() => { PBSActiveObjectAction(zone); }).ContinueWith(t => { Interlocked.Exchange(ref _inProgress, 0); }).LogExceptions();
        }
        private void GenerateFakeInfoWithSearchOriginAndRandom(int radius = 20)
        {
            var x = _missionInProgress.SearchOrigin.intX + FastRandom.NextInt(-1 * radius, radius);
            var y = _missionInProgress.SearchOrigin.intY + FastRandom.NextInt(-1 * radius, radius);

            _missionTargetInProgress.SetSuccessInfo(_zoneId, x, y);
        }
Ejemplo n.º 6
0
 //Roll random
 public int randomQuantity()
 {
     if (this.MinQty != this.MaxQty)
     {
         return(FastRandom.NextInt(this.MinQty, this.MaxQty));
     }
     return(this.MinQty);
 }
        public void DoTerraform(IZone zone)
        {
            var x = FastRandom.NextInt(_workArea.Width - 1);
            var y = FastRandom.NextInt(_workArea.Height - 1);
            var p = new Position(x, y);

            PBSHelper.DegradeTowardsOriginal(zone, p);
        }
        public void Visit(DockingBase dockingBase)
        {
            var minRange = dockingBase.Size;
            var maxRange = minRange + dockingBase.SpawnRange;

            var radius = FastRandom.NextInt(minRange, maxRange);
            var angle  = FastRandom.NextDouble();

            _spawnPosition = dockingBase.CurrentPosition.OffsetInDirection(angle, radius);
        }
        private void PlaceConcreteOrThrow(IZone zone)
        {
            var posList = new List <KeyValuePair <int, int> >();

            var iX = _targetPosition.intX;
            var iY = _targetPosition.intY;

            for (var j = iY - 2; j <= iY + 2; j++)
            {
                for (var i = iX - 2; i <= iX + 2; i++)
                {
                    posList.Add(new KeyValuePair <int, int>(i, j));
                }
            }

            var counter = 0;

            while (posList.Count > 0)
            {
                var index = FastRandom.NextInt(0, posList.Count - 1);

                var pair = posList.ElementAt(index);
                posList.RemoveAt(index);

                var i = pair.Key;
                var j = pair.Value;

                if (i < 0 || i >= zone.Size.Width || j < 0 || j >= zone.Size.Height)
                {
                    continue;
                }

                try
                {
                    PutPlantOrThrow(zone, i, j);
                    counter++;
                }
                catch (Exception ex)
                {
                    if (ex is PerpetuumException)
                    {
                        continue;
                    }
                    throw;
                }

                if (FastRandom.NextDouble() < 0.5)
                {
                    Thread.Sleep(FastRandom.NextInt(0, 150));
                }
            }

            counter.ThrowIfZero(ErrorCodes.NoConcreteWasPlaced);
        }
Ejemplo n.º 10
0
        public virtual int GetProbeInterval()
        {
            var config = EntityDefault.Get(Definition).Config;

            if (config.cycle_time == null)
            {
                Logger.Error("consistency error in proximityProbe. interval not defined. " + Definition + " " + ED.Name);
                return(150000);
            }

            return(((int)config.cycle_time) + FastRandom.NextInt(0, 250));
        }
Ejemplo n.º 11
0
        public IEnumerable <LootGeneratorItemInfo> GetIntrusionLootInfos(Outpost outpost, SAP sap)
        {
            var stability = outpost.GetIntrusionSiteInfo().Stability;
            var loots     = _intrusionLootInfos.Where(i => i.siteDefinition == outpost.Definition &&
                                                      i.sapDefinition == sap.Definition &&
                                                      i.stabilityThreshold.Min <= stability && i.stabilityThreshold.Max >= stability);

            foreach (var loot in loots)
            {
                var item = new ItemInfo(loot.itemDefinition, FastRandom.NextInt(loot.quantity));
                yield return(new LootGeneratorItemInfo(item, false, loot.probability));
            }
        }
Ejemplo n.º 12
0
        void generationalChampionTrain(object sender, EventArgs e)
        {
            foreach (var student in _agents)
            {
                if (_world.Agents.Contains(student))
                {
                    continue;
                }

                var teacher = _world.Agents.ElementAt(_random.NextInt() % _world.Agents.Count());

                TeachAgent(teacher, student, 0.05);
            }
        }
Ejemplo n.º 13
0
        public Item Open(Container targetContainer, Character character)
        {
            var randomLoot = _loots.RandomElement();
            var randomItem = (Item)Factory.CreateWithRandomEID(randomLoot.definition);

            randomItem.Owner    = character.Eid;
            randomItem.Quantity = FastRandom.NextInt(randomLoot.quantity);
            targetContainer.AddItem(randomItem, false);

            character.LogTransaction(TransactionLogEvent.Builder().SetTransactionType(TransactionType.GiftOpen).SetCharacter(character).SetContainer(targetContainer).SetItem(this));
            character.LogTransaction(TransactionLogEvent.Builder().SetTransactionType(TransactionType.GiftRandomItemCreated).SetCharacter(character).SetContainer(targetContainer).SetItem(randomItem));

            return(randomItem);
        }
        public static void TestRandomGeneratorFastRandom()
        {
            byte[] randomValue = null;
            Console.WriteLine("Test Random generator Fast Random: ");
            dh.StartWatch();
            FastRandom fastRandom = new FastRandom();
            ulong      n          = (ulong)1024 * (ulong)1024 * (ulong)1024;

            for (ulong i = 0; i < n; i++)
            {
                randomValue = Encoding.ASCII.GetBytes(fastRandom.NextInt().ToString());
            }
            dh.StoptWatch();
            Console.WriteLine(dh.GetMessage());
        }
        /// <summary>
        /// Generates required item's list for the specimen processing SAP
        /// </summary>
        private static IList <ItemInfo> GenerateSpecimenProcessingItemList(int count = 5)
        {
            var result = new Dictionary <int, ItemInfo>();

            while (count > 0)
            {
                var randomItemInfo = _specimenProcessingItems.Where(d => !result.ContainsKey(d.Key)).RandomElement();

                var siegeItem = randomItemInfo.Value;
                var randomQty = FastRandom.NextInt(siegeItem.quantity);

                var itemInfo = new ItemInfo(siegeItem.definition, randomQty);
                result.Add(randomItemInfo.Key, itemInfo);
                count--;
            }

            return(result.Values.ToArray());
        }
Ejemplo n.º 16
0
        private static Position FindPositionWithinIsland(IZone zone)
        {
            var counter = 0;

            while (true)
            {
                var xo = FastRandom.NextInt(0, zone.Size.Width - 1);
                var yo = FastRandom.NextInt(0, zone.Size.Height - 1);
                var p  = new Position(xo, yo);

                if (!zone.Terrain.Blocks[xo, yo].Island)
                {
                    return(p);
                }

                counter++;
                if (counter % 50 == 0)
                {
                    Thread.Sleep(1);
                }
            }
        }
        private static Position GetRandomIslandPosition(this IZone zone)
        {
            var counter = 0;

            while (true)
            {
                var xo = FastRandom.NextInt(0, zone.Size.Width - 1);
                var yo = FastRandom.NextInt(0, zone.Size.Height - 1);
                var p  = new Position(xo, yo);

                var blockingInfo = zone.Terrain.Blocks.GetValue(xo, yo);
                if (!blockingInfo.Island)
                {
                    return(p);
                }

                counter++;
                if (counter % 50 == 0)
                {
                    Thread.Sleep(1);
                }
            }
        }
Ejemplo n.º 18
0
        public void UnHealPlant()
        {
            var amount = FastRandom.NextInt(3, 5);

            health = (byte)(health - amount).Clamp(0, 255);
        }
        public void WriteToSql(Container container, Dictionary <int, int> randomComponentResults)
        {
            var logQuantity = _item.Quantity;

            //delete source item
            if (_wasDeleted)
            {
                _insuranceHelper.DeleteAndInform(_item);
                Entity.Repository.Delete(_item);
            }
            else
            {
                logQuantity    = _item.Quantity - _resultQuantity;
                _item.Quantity = _resultQuantity;
            }

            _character.LogTransaction(TransactionLogEvent.Builder().SetTransactionType(TransactionType.ReprocessDeleted).SetCharacter(_character).SetItem(_item.Definition, logQuantity));

            if (!randomizeComponents)
            {
                //make the resulting components
                foreach (var component in _components)
                {
                    if (component.realAmount <= 0)
                    {
                        continue;
                    }

                    var resultItem = (Item)Entity.Factory.CreateWithRandomEID(component.definition);
                    resultItem.Owner    = _item.Owner;
                    resultItem.Quantity = component.realAmount;

                    container.AddItem(resultItem, true);

                    var b = TransactionLogEvent.Builder().SetTransactionType(TransactionType.ReprocessCreated).SetCharacter(_character).SetItem(resultItem);
                    _character.LogTransaction(b);
                }
            }
            else
            {
                //pick random components and add them to the container

                Logger.Info("creating random components for " + _item.Eid);

                var configComponents = ProductionComponentCollector.Collect(_item);
                if (configComponents.Count == 0)
                {
                    return;
                }

                var sumAmount  = configComponents.Sum(r => r.Amount);
                var randomPool = new List <int>(sumAmount);

                foreach (var productionComponent in configComponents)
                {
                    for (var i = 0; i < productionComponent.Amount; i++)
                    {
                        randomPool.Add(productionComponent.EntityDefault.Definition);
                    }
                }

                var chosenDefinition = randomPool.ElementAt(FastRandom.NextInt(0, randomPool.Count - 1));

                var chosenComponent = configComponents.First(r => r.EntityDefault.Definition == chosenDefinition);

                var resultItem = (Item)Entity.Factory.CreateWithRandomEID(chosenComponent.EntityDefault.Definition);
                resultItem.Owner    = _item.Owner;
                resultItem.Quantity = chosenComponent.Amount * _item.Quantity;

                container.AddItem(resultItem, true);

                _character.WriteItemTransactionLog(TransactionType.ReprocessCreated, resultItem);

                if (randomComponentResults.ContainsKey(resultItem.Definition))
                {
                    randomComponentResults[resultItem.Definition] += resultItem.Quantity;
                }
                else
                {
                    randomComponentResults.Add(resultItem.Definition, resultItem.Quantity);
                }
            }
        }
 internal LootContainerBuilder()
 {
     _containerType = LootContainerType.LootOnly;
     _pinCode       = FastRandom.NextInt(1, 9999);
     _enterBeamType = BeamType.undefined;
 }
Ejemplo n.º 21
0
        private void PlaceOneType(List <MissionSpot> spotInfos, MissionSpotType type, int targetAmount, Dictionary <MissionSpotType, int> distanceInfos, Dictionary <MissionSpotType, List <Position> > staticObjects, AccuracyInfo accuracyInfo)
        {
            var distanceToMyType = distanceInfos[type];
            var zoneWidth        = _zone.Size.Width;
            var borderWidthMax   = zoneWidth;

            //to make it fast
            //border increase 200
            //start border 200

            var borderIncrease = accuracyInfo.borderIncrease;
            var currentBorder  = accuracyInfo.initialBorder;
            var foundTotal     = 0;

            var freePoints = new List <Point>(_zone.Configuration.Size.Width * _zone.Configuration.Size.Height);

            InitPoints(spotInfos, distanceInfos, staticObjects, freePoints);

            while (true)
            {
                if (currentBorder > borderWidthMax)
                {
                    Logger.Info("Max border reached " + type);
                    return;
                }

                Logger.Info("border:" + currentBorder);

                var maxAttempts = freePoints.Count;
                var attempts    = 0;
                while (true)
                {
                    if (freePoints.Count == 0)
                    {
                        Logger.Info("no more free points");
                        return;
                    }

                    attempts++;
                    if (attempts > maxAttempts)
                    {
                        currentBorder += borderIncrease;
                        Logger.Info("MAX attempts reached!");
                        break;
                    }

                    if (attempts % 50000 == 0)
                    {
                        Logger.Info(type + " working " + attempts);
                    }

                    var pickedIndex    = FastRandom.NextInt(freePoints.Count - 1);
                    var pickedPosition = freePoints[pickedIndex].ToPosition();



                    //super turbo mode, skips border check when it generates random points
                    //if (type != MissionSpotType.randompoint)
                    //{ is keep distance }


                    //good if the distance is kept
                    if (!IsKeepDistance(pickedPosition, spotInfos, distanceInfos, staticObjects, 0, currentBorder))
                    {
                        continue;
                    }


                    if (!CheckConditionsAroundPosition(pickedPosition, accuracyInfo.blockRadius, accuracyInfo.islandRadius))
                    {
                        freePoints.Remove(pickedPosition);
                        continue;
                    }

                    //--- yay! position found!

                    var si = new MissionSpot(type, pickedPosition, _zone.Id);

                    spotInfos.Add(si);
                    SaveInfoAsync(si);

                    foundTotal++;
                    if (foundTotal >= targetAmount)
                    {
                        Logger.Info(foundTotal + " " + type + " was found successfully. Target amount reached!");
                        return;
                    }

                    CleanUpOneSpot(pickedPosition, distanceToMyType, ref freePoints);
                    //MakeSnap(type,freeKeys);
                    Logger.Info(type + "\t\t" + foundTotal + "\tattempts:" + attempts);
                    break;
                }
            }
        }
        private void ProcessEnquedAreas(List <HighwaySegmentInfo> segments)
        {
            var areas = _areaQueue.TakeAll().ToList();

            Logger.DebugInfo($"processing {areas.Count} highway areas");

            areas = areas.Distinct().ToList();

            Logger.DebugInfo($"processing {areas.Count} unique areas");


            using (new TerrainUpdateMonitor(_zone))
            {
                foreach (var eArea in areas)
                {
                    //clamp to current zone
                    var zArea = eArea.Clamp(_zone.Configuration.Size);

                    //get the original data
                    var data = _zone.Terrain.Controls.GetArea(zArea);

                    //clear highway bit
                    for (var i = 0; i < data.Length; i++)
                    {
                        var tc = data[i];
                        tc.PBSHighway = false;
                        tc.ConcreteA  = false;
                        tc.ConcreteB  = false;
                        data[i]       = tc;
                    }

                    //set highway if in any segment
                    for (var j = zArea.Y1; j <= zArea.Y2; j++)
                    {
                        for (var i = zArea.X1; i <= zArea.X2; i++)
                        {
                            if (segments.Any(s => s.IsPointWithinRange(i + 0.5, j + 0.5)))
                            {
                                var xo = i - zArea.X1;
                                var yo = j - zArea.Y1;

                                var offset = xo + yo * zArea.Width;

                                var tc = data[offset];

                                //do highway
                                tc.PBSHighway = true;

                                //draw concrete
                                if (FastRandom.NextInt() % 2 == 1)
                                {
                                    tc.ConcreteA = true;
                                }
                                else
                                {
                                    tc.ConcreteB = true;
                                }

                                data[offset] = tc;
                            }
                        }
                    }

                    _zone.Terrain.Controls.SetArea(zArea, data);
                }
            }
        }
Ejemplo n.º 23
0
        private void DoSummon(IZone zone)
        {
            Logger.Info("DoSummon starts on zone:" + zone.Id + " " + this);
            if (DeployerPlayer == null)
            {
                Logger.Error("no deployer player " + this);
                return;
            }

            var corporation = DeployerPlayer.Character.GetPrivateCorporation();

            if (corporation == null)
            {
                Logger.Error("no private corporation was found. Deployer character: " + DeployerPlayer.Character);
                DeployerPlayer.Character.SendErrorMessage(new Command("pbsDeployItem"), ErrorCodes.PrivateCorporationAllowedOnly);
                return;
            }

            var            centerTile = CurrentPosition.Center;
            PBSDockingBase dockingBase;

            using (var scope = Db.CreateTransaction())
            {
                try
                {
                    var deployableItem = (Unit)_entityServices.Factory.CreateWithRandomEID(TargetPBSNodeDefault);
                    var zoneStorage    = zone.Configuration.GetStorage();

                    zoneStorage.AddChild(deployableItem);
                    SetStartCore(deployableItem);

                    dockingBase = deployableItem as PBSDockingBase;
                    if (dockingBase != null)
                    {
                        PBSHelper.CreatePBSDockingBase(dockingBase);
                    }

                    deployableItem.Owner           = corporation.Eid;
                    deployableItem.Orientation     = FastRandom.NextInt(0, 3) * 0.25;
                    deployableItem.CurrentPosition = CurrentPosition.Center;

                    if (deployableItem is PBSTurret turret)
                    {
                        // csak a turret kell, gyerekek nem
                        Repository.Insert(turret);
                    }
                    else
                    {
                        // itt mindent insertalunk
                        deployableItem.Save();
                    }

                    Logger.Info("node saved to sql " + deployableItem);

                    Logger.Info("pbs insert start in zoneuser entities: " + deployableItem);
                    zone.UnitService.AddUserUnit(deployableItem, centerTile);

                    Logger.Info("pbs log starting " + deployableItem);
                    PBSHelper.WritePBSLog(PBSLogType.deployed, deployableItem.Eid, deployableItem.Definition, deployableItem.Owner, DeployerPlayer.Character.Id, background: false, zoneId: zone.Id);

                    Transaction.Current.OnCompleted((completed) =>
                    {
                        if (!completed)
                        {
                            Logger.Error("DoSummon rollback " + this);
                            return;
                        }

                        Logger.Info("starting zone enter: " + deployableItem);
                        deployableItem.AddToZone(zone, centerTile);
                        Logger.Info("added to zone " + deployableItem);

                        dockingBase?.OnDockingBaseDeployed();

                        //draw terrain stuff
                        PBSHelper.OnPBSObjectDeployed(zone, deployableItem, true, true, true);
                        Logger.Info("terrain stuff done, sending update. " + deployableItem);

                        //send update
                        ((IPBSObject)deployableItem).SendNodeUpdate();

                        zone.CreateBeam(BeamType.red_20sec,
                                        builder =>
                                        builder.WithPosition(CurrentPosition.Center)
                                        .WithState(BeamState.Hit)
                                        .WithDuration(15000));

                        Logger.Info("pbs node successfully deployed.");
                        _successfulSummon = true;
                    });

                    scope.Complete();
                }
                catch (Exception ex)
                {
                    Logger.Exception(ex);
                }
            }
        }
Ejemplo n.º 24
0
 public IBuilder <LootItem> GetLootItemBuilder()
 {
     return(LootItemBuilder.Create(Definition)
            .SetQuantity(FastRandom.NextInt(Quantity))
            .SetRepackaged(Packed));
 }
        public SpecimenProcessingSAP() : base(BeamType.attackpoint_item_enter, BeamType.attackpoint_item_out)
        {
            var itemsCount = FastRandom.NextInt(_requiredItems);

            _itemInfos = GenerateSpecimenProcessingItemList(itemsCount);
        }
Ejemplo n.º 26
0
 public Impulse()
 {
     privateHashCode = _fstRnd.NextInt();
 }
Ejemplo n.º 27
0
        private void SpawnPlants()
        {
            var plantAmount  = _plantInfos.CountPlants();
            var plantsInCube = 0;

            foreach (var kvp in plantAmount)
            {
                var currentPlantType = kvp.Key;
                var currentAmount    = kvp.Value;

                var rule = _zone.Configuration.PlantRules.GetPlantRule(currentPlantType);

                if (rule.HasBlockingState)
                {
                    plantsInCube += currentAmount;
                }
            }

            var tilesInCube = _area.Ground;

            var fertilityFactor = _zone.Configuration.Fertility / 100.0;

            var availablePlaces = (int)(tilesInCube * fertilityFactor);

            availablePlaces -= plantsInCube;

            var cubeFertilityState = plantsInCube / (double)tilesInCube;

            //zone fertility check
            if (cubeFertilityState > fertilityFactor)
            {
                //ok, cube is fulfilling the fertility condition
                return;
            }

            for (var i = 0; i < tilesInCube; i++)
            {
                var x = FastRandom.NextInt(_area.Width - 1);
                var y = FastRandom.NextInt(_area.Height - 1);

                var globalX = x + _area.X1;
                var globalY = y + _area.Y1;

                var plantInfo = GetPlantInfo(x, y);
                var blockInfo = GetBlockInfo(x, y);

                var plantType = plantInfo.type;

                if (plantType != 0 || blockInfo.Flags != BlockingFlags.Undefined)
                {
                    continue;
                }

                //per tile random chance
                if (FastRandom.NextByte() >= plantInfo.spawn)
                {
                    continue;
                }

                var newPlantRule = GetNewPlantRule(globalX, globalY);

                if (newPlantRule == null)
                {
                    plantInfo.Clear();
                    blockInfo.Height = 0;
                    blockInfo.Plant  = false;

                    SetPlantInfo(x, y, plantInfo);
                    SetBlockInfo(x, y, blockInfo);
                    continue;
                }

                //is there a max amount defined for the current type?
                if (newPlantRule.MaxAmount > 0)
                {
                    //have we planted enough?
                    var amount = plantAmount.GetOrDefault(newPlantRule.Type);
                    if (amount > newPlantRule.MaxAmount)
                    {
                        continue;
                    }
                }

                if (!CheckKillDistance(newPlantRule, x, y, this))
                {
                    plantInfo.Clear();
                    blockInfo.Plant  = false;
                    blockInfo.Height = 0;

                    SetPlantInfo(x, y, plantInfo);
                    SetBlockInfo(x, y, blockInfo);
                    continue;
                }

                plantInfo.type     = newPlantRule.Type;
                plantInfo.state    = 0;
                plantInfo.material = 0;                                    //no material at state0
                plantInfo.health   = newPlantRule.Health[plantInfo.state]; //set health

                blockInfo.Height = newPlantRule.GetBlockingHeight(plantInfo.state);

                if (blockInfo.Height > 0)
                {
                    blockInfo.Plant = true;
                }

                SetPlantInfo(x, y, plantInfo);
                SetBlockInfo(x, y, blockInfo);

                if (--availablePlaces <= 0)
                {
                    return;
                }
            }
        }
Ejemplo n.º 28
0
        private void KillOnDistance()
        {
            var size = _zone.Size;

            for (var i = 0; i < _area.Ground * 2; i++)
            {
                var x = FastRandom.NextInt(_area.Width - 1);
                var y = FastRandom.NextInt(_area.Height - 1);

                var globalX = x + _area.X1;
                var globalY = y + _area.Y1;

                var plantInfo = GetPlantInfo(x, y);

                var plantRule = _zone.Configuration.PlantRules.GetPlantRule(plantInfo.type);
                if (plantRule == null)
                {
                    continue;
                }

                if (plantRule.KillDistance <= 0)
                {
                    continue;
                }

                for (var sy = globalY - plantRule.KillDistance; sy < globalY + plantRule.KillDistance; sy++)
                {
                    for (var sx = globalX - plantRule.KillDistance; sx < globalX + plantRule.KillDistance; sx++)
                    {
                        if (sx < 0 || sx >= size.Width || sy < 0 || sy >= size.Height)
                        {
                            continue;
                        }

                        //not itself
                        if (sx - _area.X1 == x && sy - _area.Y1 == y)
                        {
                            continue;
                        }

                        var searchPlantType = _area.Contains(sx, sy)
                            ? GetPlantInfo(sx - _area.X1, sy - _area.Y1).type //sample from the cube
                            : _zone.Terrain.Plants.GetValue(sx, sy).type;     //sample from the real map

                        //is there a plant we are looking for?
                        if (plantInfo.type != searchPlantType)
                        {
                            continue;
                        }

                        if (!IsCloserThan(globalX, globalY, sx, sy, plantRule.KillDistance))
                        {
                            continue;
                        }

                        //we found a plant which is too close
                        //kill the original
                        var blockInfo = GetBlockInfo(x, y);

                        plantInfo.Clear();
                        blockInfo.Height = 0;
                        blockInfo.Plant  = false;

                        SetPlantInfo(x, y, plantInfo);
                        SetBlockInfo(x, y, blockInfo);
                    }
                }
            }
        }
Ejemplo n.º 29
0
 /// <summary>
 /// Returns the plants next growing state
 /// </summary>
 /// <param name="state">current state</param>
 /// <param name="nextState">the next calculated state</param>
 /// <param name="nextAction">the next calculated type</param>
 public void GetNextState(byte state, out byte nextState, out PlantType nextAction)
 {
     nextState  = GrowingStates[state].state[FastRandom.NextInt(GrowingStates[state].state.Length - 1)];
     nextAction = GrowingStates[state].action[FastRandom.NextInt(GrowingStates[state].action.Length - 1)];
 }