示例#1
0
        protected override void InternalStart()
        {
            _unitInfoCom = Owner.GetCom <UnitInfoCom>();

            _currentState = State.Seraching;

            _decisionTrees = new Dictionary <State, IDecisionTreeNode>()
            {
                {
                    State.Seraching,
                    new DecisionNode()
                    {
                        Condition = new EnemyInAttackRange(this),
                        TrueNode  = new DecisionTreeEndNode()
                        {
                            Action = new AttackAction(this)
                        },
                        FalseNode = new DecisionNode()
                        {
                            Condition = new EnemyVisible(this),
                            TrueNode  = new DecisionTreeEndNode()
                            {
                                Action = new MoveThenAttackClosestEnemy(this)
                            },
                            FalseNode = new DecisionTreeEndNode()
                            {
                                Action = new DoNothingAction(this)
                            }
                        }
                    }
                }
            };
        }
示例#2
0
        public void GenerateEnemies(int startX, int startY, int endX, int endY, GridCom grid, int difficulty, List <UnitType> accessibleUnits, Faction faction, long seed)
        {
            Debug.Assert(startX < endX);
            Debug.Assert(startY < endY);

            var cells = grid.Cells;

            var unitsToCreate = new Stack <UnitType>();

            var nextSeed = seed;

            while (difficulty > 0)
            {
                nextSeed = Utility.Randomlong(nextSeed);
                var nextUnitType   = Utility.RandomElement(accessibleUnits, nextSeed);
                var tempDifficulty = difficulty - UnitInfoCom.DifficultyRatingForType(nextUnitType);
                if (tempDifficulty >= 0)
                {
                    unitsToCreate.Push(nextUnitType);
                    difficulty = tempDifficulty;
                }
                else
                {
                    accessibleUnits.RemoveAll(i =>
                                              UnitInfoCom.DifficultyRatingForType(i) >= UnitInfoCom.DifficultyRatingForType(nextUnitType)
                                              );

                    if (accessibleUnits.Count <= 0)
                    {
                        break;
                    }
                }
            }

            var xSeed = (seed + ((startX * 576976759) + (endX * 104589539))) % 1828081061;
            int x     = Utility.RandomInt(startX, endX, xSeed);

            var ySeed = (seed + ((startY * 2755125551) + (endY * 1920502651))) % 5291225924533335701;
            int y     = Utility.RandomInt(startY, endY, ySeed);

            while (unitsToCreate.Count > 0)
            {
                if (cells[y, x].SpaceAvailable)
                {
                    var nextUnit = unitsToCreate.Pop();
                    EntFactory.Instance.CreateFootSolider(grid, y, x, faction, nextUnit);
                }

                xSeed = Utility.Randomlong(xSeed);
                x     = Utility.RandomInt(startX, endX, xSeed);

                ySeed = Utility.Randomlong(ySeed);
                y     = Utility.RandomInt(startY, endY, ySeed);
            }
        }