コード例 #1
0
        bool TickQueue(ProductionQueue queue)
        {
            var currentBuilding = queue.CurrentItem();

            // Waiting to build something
            if (currentBuilding == null)
            {
                var item = ChooseBuildingToBuild(queue);
                if (item == null)
                {
                    return(false);
                }

                HackyAI.BotDebug("AI: {0} is starting production of {1}".F(player, item.Name));
                world.IssueOrder(Order.StartProduction(queue.Actor, item.Name, 1));
            }

            // Production is complete
            else if (currentBuilding.Done)
            {
                // Choose the placement logic
                // HACK: HACK HACK HACK
                var type = BuildingType.Building;
                if (world.Map.Rules.Actors[currentBuilding.Item].Traits.Contains <AttackBaseInfo>())
                {
                    type = BuildingType.Defense;
                }
                else if (world.Map.Rules.Actors[currentBuilding.Item].Traits.Contains <OreRefineryInfo>())
                {
                    type = BuildingType.Refinery;
                }

                var location = ai.ChooseBuildLocation(currentBuilding.Item, true, type);
                if (location == null)
                {
                    HackyAI.BotDebug("AI: {0} has nowhere to place {1}".F(player, currentBuilding.Item));
                    world.IssueOrder(Order.CancelProduction(queue.Actor, currentBuilding.Item, 1));
                }
                else
                {
                    world.IssueOrder(new Order("PlaceBuilding", player.PlayerActor, false)
                    {
                        TargetLocation         = location.Value,
                        TargetString           = currentBuilding.Item,
                        TargetActor            = queue.Actor,
                        SuppressVisualFeedback = true
                    });

                    return(true);
                }
            }

            return(true);
        }
コード例 #2
0
ファイル: BaseBuilder.cs プロジェクト: test71/OpenRA
        public void Tick()
        {
            // Pick a free queue
            var queue = ai.FindQueues(category).FirstOrDefault();

            if (queue == null)
            {
                return;
            }

            var currentBuilding = queue.CurrentItem();

            switch (state)
            {
            case BuildState.ChooseItem:
            {
                var item = chooseItem(queue);
                if (item == null)
                {
                    state         = BuildState.WaitForFeedback;
                    lastThinkTick = ai.ticks;
                }
                else
                {
                    HackyAI.BotDebug("AI: Starting production of {0}".F(item.Name));
                    state = BuildState.WaitForProduction;
                    ai.world.IssueOrder(Order.StartProduction(queue.self, item.Name, 1));
                }
            }
            break;

            case BuildState.WaitForProduction:
                if (currentBuilding == null)
                {
                    return;                                                     /* let it happen.. */
                }
                else if (currentBuilding.Paused)
                {
                    ai.world.IssueOrder(Order.PauseProduction(queue.self, currentBuilding.Item, false));
                }
                else if (currentBuilding.Done)
                {
                    state         = BuildState.WaitForFeedback;
                    lastThinkTick = ai.ticks;

                    /* place the building */
                    var location = ai.ChooseBuildLocation(currentBuilding.Item);
                    if (location == null)
                    {
                        HackyAI.BotDebug("AI: Nowhere to place {0}".F(currentBuilding.Item));
                        ai.world.IssueOrder(Order.CancelProduction(queue.self, currentBuilding.Item, 1));
                    }
                    else
                    {
                        ai.world.IssueOrder(new Order("PlaceBuilding", ai.p.PlayerActor, false)
                        {
                            TargetLocation = location.Value,
                            TargetString   = currentBuilding.Item
                        });
                    }
                }
                break;

            case BuildState.WaitForFeedback:
                if (ai.ticks - lastThinkTick > HackyAI.feedbackTime)
                {
                    state = BuildState.ChooseItem;
                }
                break;
            }
        }
コード例 #3
0
        public void Tick()
        {
            // Pick a free queue
            var queue = ai.FindQueues(category).FirstOrDefault();

            if (queue == null)
            {
                return;
            }

            var currentBuilding = queue.CurrentItem();

            switch (state)
            {
            case BuildState.ChooseItem:
                var item = chooseItem(queue);
                if (item == null)
                {
                    state         = BuildState.WaitForFeedback;
                    lastThinkTick = ai.ticks;
                }
                else
                {
                    HackyAI.BotDebug("AI: Starting production of {0}".F(item.Name));
                    state = BuildState.WaitForProduction;
                    ai.world.IssueOrder(Order.StartProduction(queue.self, item.Name, 1));
                }
                break;

            case BuildState.WaitForProduction:
                if (currentBuilding == null)
                {
                    return;
                }

                if (currentBuilding.Paused)
                {
                    ai.world.IssueOrder(Order.PauseProduction(queue.self, currentBuilding.Item, false));
                }
                else if (currentBuilding.Done)
                {
                    state         = BuildState.WaitForFeedback;
                    lastThinkTick = ai.ticks;

                    // Place the building
                    var type = BuildingType.Building;
                    if (ai.Map.Rules.Actors[currentBuilding.Item].Traits.Contains <AttackBaseInfo>())
                    {
                        type = BuildingType.Defense;
                    }
                    else if (ai.Map.Rules.Actors[currentBuilding.Item].Traits.Contains <OreRefineryInfo>())
                    {
                        type = BuildingType.Refinery;
                    }

                    var location = ai.ChooseBuildLocation(currentBuilding.Item, type);
                    if (location == null)
                    {
                        HackyAI.BotDebug("AI: Nowhere to place {0}".F(currentBuilding.Item));
                        ai.world.IssueOrder(Order.CancelProduction(queue.self, currentBuilding.Item, 1));
                    }
                    else
                    {
                        ai.world.IssueOrder(new Order("PlaceBuilding", ai.p.PlayerActor, false)
                        {
                            TargetLocation = location.Value,
                            TargetString   = currentBuilding.Item
                        });
                    }
                }

                break;

            case BuildState.WaitForFeedback:
                if (ai.ticks - lastThinkTick > HackyAI.feedbackTime)
                {
                    state = BuildState.ChooseItem;
                }
                break;
            }
        }