コード例 #1
0
        private void SaveSmartInfo(Agent agent)
        {
            // If this is a Crossing
            if (this.Crossing && agent is SmartElectricSlime smart)
            {
                // Save the Direction the Slime reached the Crossing from
                this.OrigOrientation = smart.Orientation;

                // Save Direction Slime entered component by/left crossing from
                this.WentTo = LevelBoard.GetDirection(smart.Coords, this.ComponentCoords);

                this.RegisteredConnection = smart.CommunicateInfo(this.ChargeCoords, this.OrigOrientation, this.WentTo);
            }
        }
コード例 #2
0
        override public Action Available(Agent agent)
        {
            List<Vector2Int> pathToTarget = agent.PathToNearest(this.TargetCharacteristics, 3);

            if(pathToTarget != null)
            {
                var dir = LevelBoard.GetDirection(pathToTarget[0], pathToTarget[1]);

                var target = agent.PieceAt(pathToTarget[pathToTarget.Count - 1]);

                return new SeekTarget(pathToTarget[1], dir, target);
            }

            return null;
        }
コード例 #3
0
        override public Action Available(Agent agent)
        {
            // If the Agent is a Component
            if (agent is CircuitComponent component)
            {
                // If the Component is connected and has surplus charge
                if (component.Connections.Count > 0 && component.Stats.Food > 0)
                {
                    ElectricSlime charge = null;

                    // If there are Slimes stored
                    if (component.Charges.Count > 0)
                    {
                        charge = component.Charges[component.Charges.Count - 1]; // Get the next Slime to be discharged

                        // Find the approapriate connection to discharge it to
                        var componentExitCoords     = component.Coords + component.Footprint[component.Footprint.Length - 1];
                        LevelBoard.Directions inDir = LevelBoard.GetDirection(charge.Coords, component.Coords);
                        var coords = component.RouteEnergy(inDir);

                        // If an approapriate connection was found
                        if (coords.x != -1)
                        {
                            return(new Discharge(charge, coords)); // Return the potential Action
                        }
                    }

                    // If there are no Slimes stored
                    else
                    {
                        var coords = component.RouteEnergy(LevelBoard.Directions.North);

                        if (coords.x != -1)
                        {
                            return(new Discharge(charge, coords));
                        }
                    }
                }
            }

            return(null);
        }
コード例 #4
0
        public override bool Confirm(Agent agent)
        {
            if (agent is CircuitComponent component)
            {
                if (component.IsFree(this.TargetCoords))
                {
                    if (component.Charges.Count == 0)
                    {
                        var componentFootprint    = component.GetFootprint();
                        LevelBoard.Directions ori = LevelBoard.GetDirection(componentFootprint[componentFootprint.Length - 1], this.TargetCoords);

                        var piece = component.CreatePiece(new Piece.Characteristics(component.GetChargeType()),
                                                          this.TargetCoords, ori, component.Turn + 1);

                        this.Charge = (ElectricSlime)piece;

                        this.NewCharge = true;
                    }
                    else
                    {
                        component.ReleaseCharge(this.Charge, this.TargetCoords);

                        var outDir = LevelBoard.GetDirection(agent.Coords, this.TargetCoords);

                        this.Charge.RotateInBoard(outDir);
                        this.Charge.Rotate(outDir, 1f);
                    }

                    this.Charge.Hide();

                    return(true);
                }
            }

            return(false);
        }
コード例 #5
0
        public Vector2Int RouteEnergy(Vector2Int entryPoint)
        {
            LevelBoard.Directions entryDir = LevelBoard.GetDirection(entryPoint, this.Coords);

            return(this.RouteEnergy(entryDir));
        }