Beispiel #1
0
        public Selection SelectAll(Vec2 pos)
        {
            Selection selection = new Selection();

            foreach (var minion in game.GUISelectMinions(pos))
            {
                selection.minions.Add(minion);
            }

            // TODO:agents

            var tile = game.Tile(pos.Floor());

            if (tile.hasItems)
            {
                selection.items.AddRange(game.GUISelectItemsOnTile(tile));
            }

            if (tile.hasBuilding)
            {
                selection.buildings.Add(tile.building);
            }

            return(selection);
        }
Beispiel #2
0
        public override void OnClick(Vec2 realPos)
        {
            var pos  = realPos.Floor();
            var tile = ctrl.game.Tile(pos);

            if (tile.hasBuilding && selection.ApplicableToBuilding(tile.building))
            {
                selection.AddOrder(tile.building);
            }

            if (tile.hasItems)
            {
                foreach (var item in ctrl.game.GUISelectItemsOnTile(tile))
                {
                    if (selection.ApplicableToItem(item))
                    {
                        selection.AddOrder(item);
                    }
                }
            }

            var agent = ctrl.game.GUISelectMinions(pos).FirstOrDefault();

            if (agent != null && selection.ApplicableToAgent(agent))
            {
                selection.AddOrder(agent);
            }
        }
Beispiel #3
0
        public void Init(Vec2 worldPos, Vec2 scPos, IEnumerable <Minion> minions)
        {
            this.minions = minions.ToList();
            BB.Assert(this.minions.Count > 0);

            this.targetPos = worldPos.Floor();
            this.menuPos   = scPos;
            this.selection = ctrl.SelectAll(worldPos);
        }
Beispiel #4
0
        public override void OnClick(Vec2 realPos)
        {
            Vec2I pos = realPos.Floor();

            if (ctrl.game.CanPlaceBuilding(selection.Bounds(curDir).AsRect(pos)))
            {
                var tile = ctrl.game.Tile(pos);
                builds.CreateBuild(selection, tile, curDir);
                //ctrl.game.AddBuilding(selection.CreateBuilding(tile, curDir));
            }
        }
Beispiel #5
0
        public override void OnUpdate(Vec2 realMouse)
        {
            Vec2I mouse  = realMouse.Floor();
            var   bounds = selection.Bounds(curDir);
            bool  valid  =
                ctrl.game.ValidTile(mouse) &&
                ctrl.game.CanPlaceBuilding(bounds.AsRect(mouse));
            var area = bounds.AsRect(mouse);

            outlineAllow.SetRect(area);
            outlineAllow.enabled = valid;

            outlineDisallow.SetRect(area);
            outlineDisallow.enabled = !valid;
        }
Beispiel #6
0
        public void AssignIdleTask(Minion minion)
        {
            const int   maxTries  = 10;
            const float maxWander = 16;

            for (int i = 0; i < maxTries; ++i)
            {
                float rad  = (float)rand.NextDouble() * maxWander;
                float deg  = (float)rand.NextDouble() * 360;
                var   roto = Quaternion.Euler(0, 0, deg);
                Vec2  vec  = roto * new Vec3(rad, 0, 0);
                Vec2  pt   = minion.pos + Vec2.one * .5f + vec;
                Vec2I tile = pt.Floor();
                if (game.ValidTile(tile) && tile != minion.pos && game.Tile(tile).passable)
                {
                    JobTransient.AssignIdleWork(minion, "IdleWanter", WanderTasks(tile));
                    break;
                }
            }
        }
Beispiel #7
0
        public void OnClick(Vec2 scPos, InputButton button, int clickCount)
        {
            Vec2  realPos = ScreenToWorld(scPos);
            Vec2I pos     = realPos.Floor();

            if (button == InputButton.Left)
            {
                if (game.ValidTile(pos))
                {
                    if (activeTool != null && activeTool.IsClickable())
                    {
                        activeTool.OnClick(realPos);
                    }
                    else
                    {
                        SelectClick(realPos, clickCount % 2);
                    }
                }
            }
            else if (button == InputButton.Right)
            {
                activeTool?.OnRightClick(realPos, scPos);
            }
        }