コード例 #1
0
        private void SetCellDataField(IHexCell cell)
        {
            string cellDataString = cell.Terrain.ToString();

            if (cell.Shape != CellShape.Flatlands)
            {
                cellDataString += ", " + cell.Shape.ToString();
            }

            if (cell.Vegetation != CellVegetation.None)
            {
                cellDataString += ", " + cell.Vegetation.ToString();
            }

            if (cell.Feature != CellFeature.None)
            {
                cellDataString += ", " + cell.Feature.ToString();
            }

            if (EncampmentLocationCanon.GetPossessionsOfOwner(cell).Any())
            {
                cellDataString += ", Encampment";
            }

            cellDataString += GetImprovementString(cell);

            CellDataField.text = cellDataString;
        }
コード例 #2
0
        public float GetUtilityForUnit(IUnit unit, InfluenceMaps maps)
        {
            var unitPosition = UnitPositionCanon.GetOwnerOfPossession(unit);

            if (EncampmentLocationCanon.GetPossessionsOfOwner(unitPosition).Any())
            {
                return(BarbarianConfig.StayInEncampmentUtility);
            }
            else if (Grid.GetCellsInRadius(unitPosition, BarbarianConfig.DefendEncampmentRadius).Any(HasUndefendedEncampment))
            {
                return(BarbarianConfig.HeadTowardsEncampmentUtility);
            }
            else
            {
                return(0f);
            }
        }
コード例 #3
0
        public override bool TryPlaceFeatureAtLocation(IHexCell cell, Vector3 location, int locationIndex, HexHash hash)
        {
            var encampmentOnCell = EncampmentLocationCanon.GetPossessionsOfOwner(cell).FirstOrDefault();

            if (encampmentOnCell == null || (hash.A >= Config.EncampmentAppearanceChance && locationIndex % Config.GuaranteedEncampmentModulo != 0))
            {
                return(false);
            }

            int encampmentIndex = (int)(hash.C * Config.EncampmentPrefabs.Count);

            AddFeature(Config.EncampmentPrefabs[encampmentIndex], location, hash);

            return(true);
        }
コード例 #4
0
        protected override void EditCell(IHexCell cell)
        {
            if (AddingOrRemoving)
            {
                if (EncampmentFactory.CanCreateEncampment(cell))
                {
                    EncampmentFactory.CreateEncampment(cell);
                }
            }
            else
            {
                var encampmentOn = EncampmentLocationCanon.GetPossessionsOfOwner(cell).FirstOrDefault();

                if (encampmentOn != null)
                {
                    EncampmentFactory.DestroyEncampment(encampmentOn);
                }
            }
        }
コード例 #5
0
        private void OnUnitEnteredLocation(Tuple <IUnit, IHexCell> data)
        {
            var unit        = data.Item1;
            var newLocation = data.Item2;

            var encampmentAtLocation = EncampmentLocationCanon.GetPossessionsOfOwner(newLocation).FirstOrDefault();

            if (encampmentAtLocation != null)
            {
                var unitOwner = UnitPossessionCanon.GetOwnerOfPossession(unit);

                if (!unitOwner.Template.IsBarbaric)
                {
                    float modifier = CivModifiers.GoldBountyFromEncampments.GetValueForCiv(unitOwner);

                    unitOwner.GoldStockpile += Mathf.RoundToInt(BarbarianConfig.EncampmentBounty * modifier);

                    EncampmentFactory.DestroyEncampment(encampmentAtLocation);
                }
            }
        }
コード例 #6
0
        public List <IUnitCommand> GetCommandsForUnit(IUnit unit, InfluenceMaps maps)
        {
            var retval = new List <IUnitCommand>();

            var unitPosition = UnitPositionCanon.GetOwnerOfPossession(unit);

            Dictionary <IHexCell, float> cellsByCost = HexPathfinder.GetCostToAllCells(
                unitPosition, (current, next) => UnitPositionCanon.GetTraversalCostForUnit(unit, current, next, false),
                Grid.Cells
                );

            IHexCell bestCandidate = null;
            float    lowestCost    = float.MaxValue;

            foreach (var candidate in cellsByCost.Keys)
            {
                if (!EncampmentLocationCanon.GetPossessionsOfOwner(candidate).Any())
                {
                    continue;
                }

                if (bestCandidate == null || lowestCost > cellsByCost[candidate])
                {
                    bestCandidate = candidate;
                    lowestCost    = cellsByCost[candidate];
                }
            }

            if (bestCandidate != null)
            {
                var moveCommand = Container.Instantiate <MoveUnitCommand>();

                moveCommand.UnitToMove      = unit;
                moveCommand.DesiredLocation = bestCandidate;

                retval.Add(moveCommand);
            }

            return(retval);
        }