Exemplo n.º 1
0
    /// <summary>
    /// Adds a numbered component to the circuit.
    /// The same component can't be added more than once.
    /// Also 2 components with the same type and id can not exist concurrently.
    /// </summary>
    /// <param name="component">The component to add.</param>
    /// <param name="id">The id of the component to add.</param>
    /// <exception cref="System.ArgumentException">Thrown if the component has already been added
    /// or a component with this id already exists
    /// or the component is not of a type that can be numbered</exception>
    public void AddNumberedComponent(LogicComponent component, uint id)
    {
        var inputComponent  = component as InputComponent;
        var outputComponent = component as Output;

        if (inputComponent != null)
        {
            if (NumberedInputs.ContainsKey(id))
            {
                throw new ArgumentException("id already in use");
            }
            this.graph.AddNode(component);
            NumberedInputs.Add(id, inputComponent);
        }
        else if (outputComponent != null)
        {
            if (NumberedOutputs.ContainsKey(id))
            {
                throw new ArgumentException("id already in use");
            }
            this.graph.AddNode(component);
            NumberedOutputs.Add(id, outputComponent);
        }
        else
        {
            throw new ArgumentException("component is of a type that can't be numbered");
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Creates a Logic Graph from the data in this Class
    /// </summary>
    public LogicChip getLogicGraph()
    {
        LogicChip result = new LogicChip(this.Width, this.Height, this.Name);

        foreach (GraphComponentData gcd in this.Components)
        {
            Type           type           = Type.GetType(gcd.Type);
            LightComponent lightComponent = null;

            if (type.IsSubclassOf(typeof(LightComponent)))
            {
                if (!type.IsSubclassOf(typeof(LinkComponent)))
                {
                    lightComponent = (LightComponent)Activator.CreateInstance(
                        type, new object[] {
                        new Vector2Int(gcd.Position[0], gcd.Position[1]),
                        gcd.Rotaiton,
                        gcd.Flipped
                    });
                }
                else
                {
                    if (type == typeof(GraphOutput))
                    {
                        lightComponent = new GraphOutput(new Vector2Int(gcd.Position[0], gcd.Position[1]),
                                                         gcd.Rotaiton,
                                                         gcd.Flipped, new ExtensionNode("Blank", ExtensionNode.ExtensionState.SEND));
                    }
                    else if (type == typeof(GraphInput))
                    {
                        lightComponent = new GraphInput(new Vector2Int(gcd.Position[0], gcd.Position[1]),
                                                        gcd.Rotaiton,
                                                        gcd.Flipped, new ExtensionNode("Blank", ExtensionNode.ExtensionState.RECEIVE));
                    }
                    else
                    {
                        throw new Exception(type + " is not supported when loading data");
                    }
                }

                if (type.IsSubclassOf(typeof(LogicComponent)))
                {
                    LogicComponent logic = (LogicComponent)lightComponent;
                    logic.setState();
                }
            }
            else
            {
                throw new Exception("Type " + type + " is not accepted from LogicGraphData");
            }

            if (lightComponent != null)
            {
                lightComponent.setValues(gcd.Values);
                result.LightGraph.addComponent(lightComponent);
            }
        }

        return(result);
    }
Exemplo n.º 3
0
    public static void ConnectComponents(LogicComponent input, LogicGate output, int outputPort, Layer puzzleLayer, List <GridPosition> positionsHorizontal, List <GridPosition> positionsVertical)
    {
        var line = new Line(output, outputPort);

        line.AddGridPositions(puzzleLayer, positionsHorizontal, positionsVertical);
        input.lines.Add(line);
    }
Exemplo n.º 4
0
    public void RemoveEdge(LogicComponent out_component, int out_id,
                           LogicComponent in_component, int in_id)
    {
        var out_node = Nodes[out_component];
        var in_node  = Nodes[in_component];

        this.RemoveCircuitEdge(new CircuitEdge(out_node, out_id, in_node, in_id));
    }
Exemplo n.º 5
0
    public IEnumerable <ConnectionEndpoint> GetInputs(LogicComponent component)
    {
        var node = Nodes[component];

        return(node.AdjListIn.Select(
                   edge => new ConnectionEndpoint(edge)
                   ));
    }
Exemplo n.º 6
0
 public void AddNode(LogicComponent component)
 {
     if (Nodes.ContainsKey(component))
     {
         throw new ArgumentException("Component already exists in circuit");
     }
     Nodes[component] = new CircuitNode(component);
 }
 public CircuitNode(LogicComponent component)
 {
     this.Component = component;
     this.AdjListIn = Enumerable.Repeat <CircuitEdge>(null, component.NumInputs)
                      .ToList();
     this.AdjListOut = Enumerable.Repeat <CircuitEdge>(null, component.NumOutputs)
                       .ToList();
 }
Exemplo n.º 8
0
        /// <summary>
        ///     Enable the specified component.
        /// </summary>
        public void EnableComponent(int componentType, bool enable)
        {
            LogicComponent component = this._components[componentType];

            if (component != null)
            {
                component.SetEnabled(enable);
            }
        }
Exemplo n.º 9
0
    public void AddEdge(LogicComponent out_component, int out_id,
                        LogicComponent in_component, int in_id)
    {
        var out_node = Nodes[out_component];
        var in_node  = Nodes[in_component];
        var edge     = new CircuitEdge(out_node, out_id, in_node, in_id);

        out_node.AddEdgeOut(edge);
        in_node.AddEdgeIn(edge);
    }
Exemplo n.º 10
0
        /// <summary>
        ///     Gets the specified component.
        /// </summary>
        public LogicComponent GetComponent(int componentType)
        {
            LogicComponent component = this._components[componentType];

            if (component != null && component.IsEnabled())
            {
                return(component);
            }

            return(null);
        }
Exemplo n.º 11
0
        /// <summary>
        ///     Test the specified gameobject.
        /// </summary>
        public override bool TestGameObject(LogicGameObject gameObject)
        {
            LogicComponent component = gameObject.GetComponent(this._componentType);

            if (component != null && component.IsEnabled())
            {
                return(base.TestGameObject(gameObject));
            }

            return(false);
        }
Exemplo n.º 12
0
        private string CheckProvidedAgainstRequired()
        {
            var result = new StringBuilder();

            AppendIfNotEmpty(result, FlowConfiguration.Check());
            AppendIfNotEmpty(result, BookingTypes.Check());
            AppendIfNotEmpty(result, StatusDefinition.Check());
            AppendIfNotEmpty(result, Dependency.Check());
            AppendIfNotEmpty(result, LogicComponent.Check());
            return(result.ToString());
        }
Exemplo n.º 13
0
 /// <summary>
 /// Tests whether a component has a specified truth table.
 /// </summary>
 /// <param name="component">The component to test</param>
 /// <param name="truth_table">
 /// A 2*2 truth table, where truth_table[f][s] is the expected value
 /// when the first input is f and the second input is s.</param>
 public static void Test_TruthTable(LogicComponent component, bool[,] truth_table)
 {
     for (int f = 0; f < 2; f++)
     {
         for (int s = 0; s < 2; s++)
         {
             Assert.AreEqual(component.Simulate(new [] {f != 0, s != 0}), new List<bool>() { truth_table[f, s] },
                             "Failed to simulate component with inputs: " + f + " and " + s);
         }
     }
 }
    private void clickOnComponent(RaycastHit2D hit)
    {
        Transform hitTrans = hit.collider.transform;

        if (!hitTrans.name.Equals("BasicLogicComponent"))
        {
            hitTrans = hitTrans.parent;
        }

        LogicComponentController logicComponentController = hitTrans.GetComponent <LogicComponentController>();
        LogicComponent           logicComponent           = logicComponentController.LogicComponent;
    }
        public virtual void LoadingFinished()
        {
            for (int i = 0; i < LogicComponent.COMPONENT_TYPE_COUNT; i++)
            {
                LogicComponent component = this.m_components[i];

                if (component != null)
                {
                    component.LoadingFinished();
                }
            }
        }
        public virtual void SaveToSnapshot(LogicJSONObject jsonObject, int layoutId)
        {
            for (int i = 0; i < LogicComponent.COMPONENT_TYPE_COUNT; i++)
            {
                LogicComponent component = this.m_components[i];

                if (component != null)
                {
                    component.SaveToSnapshot(jsonObject, layoutId);
                }
            }
        }
        public virtual void FastForwardTime(int secs)
        {
            for (int i = 0; i < LogicComponent.COMPONENT_TYPE_COUNT; i++)
            {
                LogicComponent component = this.m_components[i];

                if (component != null && component.IsEnabled())
                {
                    component.FastForwardTime(secs);
                }
            }
        }
Exemplo n.º 18
0
/*
 *  /// <summary>
 *  /// Changes the assigned id of a component.
 *  /// Works for both input and output components.
 *  /// </summary>
 *  /// <param name="component">The component to change the id of.</param>
 *  /// <param name="newid">The new id of the component.</param>
 *  /// <exception cref="System.ArgumentException">Thrown if the component does not already have an id. </exception>
 *  public void RenumberComponent(LogicComponent component, uint newid)
 *  {
 *      bool found = false;
 *      var inputComponent = component as InputComponent;
 *      var outputComponent = component as OutputComponent;
 *      if (inputComponent != null)
 *      {
 *          try {
 *              // Throws if the component doesn't exist in the dictionary.
 *              var item = NumberedInputs.First(kvp => kvp.Value == component);
 *              NumberedInputs.Remove(item.Key);
 *              NumberedInputs.Add(newid, item.Value);
 *              found = true;
 *          }
 *          catch
 *          {
 *          }
 *      }
 *      if (outputComponent != null)
 *      {
 *          Assert.IsFalse(found);
 *          try {
 *              // Throws if the component doesn't exist in the dictionary.
 *              var item = NumberedOutputs.First(kvp => kvp.Value == component);
 *              NumberedOutputs.Remove(item.Key);
 *              NumberedOutputs.Add(newid, item.Value);
 *              found = true;
 *          }
 *          catch
 *          {
 *          }
 *      }
 *      if (!found)
 *      {
 *          throw new ArgumentException("component doesn't already have an id");
 *      }
 *  }
 */


    /// <summary>
    /// Removes a component.
    /// Will also free its id automatically if it is a numbered component.
    /// </summary>
    /// <param name="component">The component to remove.</param>
    /// <exception cref="System.Collections.Generic.KeyNotFoundException">Thrown if component does not exist</exception>
    public void RemoveComponent(LogicComponent component)
    {
        this.graph.RemoveNode(component);
        foreach (var item in NumberedInputs.Where(kvp => kvp.Value == component).ToList())
        {
            NumberedInputs.Remove(item.Key);
        }
        foreach (var item in NumberedOutputs.Where(kvp => kvp.Value == component).ToList())
        {
            NumberedOutputs.Remove(item.Key);
        }
    }
Exemplo n.º 19
0
    public void disconnectGraph()
    {
        //disconnects all the components from each other

        for (int c = 0; c < this.lightGraph.getLogicComponentCount(); c++)
        {
            LogicComponent l = this.lightGraph.getLogicComponentAt(c);
            for (int s = 0; s < l.senderCount(); s++)
            {
                l.getSenderAt(s).clearTargets();
            }
        }
    }
Exemplo n.º 20
0
    public override void setUp(GraphComponent logicComponent)
    {
        this.graphComponent = logicComponent;

        this.logicComponent = (LogicComponent)logicComponent;


        //updates the sprite of the logic component
        string gateName = "";

        if (logicComponent.GetType() == typeof(AndGate))
        {
            gateName = "And";
        }
        else if (logicComponent.GetType() == typeof(NotGate))
        {
            gateName = "Not";
        }
        else if (logicComponent.GetType() == typeof(OrGate))
        {
            gateName = "Or";
        }
        else if (logicComponent.GetType() == typeof(XorGate))
        {
            gateName = "Xor";
        }
        else if (logicComponent.GetType() == typeof(XnorGate))
        {
            gateName = "Xnor";
        }
        else if (logicComponent.GetType() == typeof(BufferGate))
        {
            gateName = "Buffer";
        }
        else if (logicComponent.GetType() == typeof(NorGate))
        {
            gateName = "Nor";
        }
        else if (logicComponent.GetType() == typeof(NandGate))
        {
            gateName = "Nand";
        }

        if (gateName.Equals(""))
        {
            throw new System.Exception(logicComponent.GetType() + " could not be found amoung the sprites");
        }

        this.formBasicShape(this.logicComponent);
        this.displaySprite(gateName);
    }
Exemplo n.º 21
0
        /// <summary>
        ///     Adds the specified component.
        /// </summary>
        public void AddComponent(LogicComponent component)
        {
            int componentType = component.GetComponentType();

            if (this._components[componentType] == null)
            {
                this._level.GetComponentManagerAt(this._villageType).AddComponent(component);
                this._components[componentType] = component;
            }
            else
            {
                Debugger.Error("LogicGameObject::addComponent - Component is already added.");
            }
        }
Exemplo n.º 22
0
    public void RemoveNode(LogicComponent component)
    {
        var node = Nodes[component];

        for (int i = 0; i < node.AdjListIn.Count; i++)
        {
            this.RemoveCircuitEdge(node.AdjListIn[i]);
        }
        for (int i = 0; i < node.AdjListOut.Count; i++)
        {
            this.RemoveCircuitEdge(node.AdjListOut[i]);
        }
        Nodes.Remove(component);
    }
        public virtual void Load(LogicJSONObject jsonObject)
        {
            this.LoadPosition(jsonObject);

            for (int i = 0; i < LogicComponent.COMPONENT_TYPE_COUNT; i++)
            {
                LogicComponent component = this.m_components[i];

                if (component != null)
                {
                    component.Load(jsonObject);
                }
            }
        }
        public virtual void Save(LogicJSONObject jsonObject, int villageType)
        {
            jsonObject.Put("x", new LogicJSONNumber(this.GetTileX() & 63));
            jsonObject.Put("y", new LogicJSONNumber(this.GetTileY() & 63));

            for (int i = 0; i < LogicComponent.COMPONENT_TYPE_COUNT; i++)
            {
                LogicComponent component = this.m_components[i];

                if (component != null)
                {
                    component.Save(jsonObject, villageType);
                }
            }
        }
Exemplo n.º 25
0
        /// <summary>
        ///     Saves this instance to json.
        /// </summary>
        public virtual void Save(LogicJSONObject jsonObject)
        {
            jsonObject.Put("x", new LogicJSONNumber(this.GetTileX()));
            jsonObject.Put("y", new LogicJSONNumber(this.GetTileY()));

            for (int i = 0; i < this._components.Count; i++)
            {
                LogicComponent component = this._components[i];

                if (component != null)
                {
                    component.Save(jsonObject);
                }
            }
        }
Exemplo n.º 26
0
        /// <summary>
        ///     Creates a fast forward of time.
        /// </summary>
        public virtual void FastForwardTime(int secs)
        {
            for (int i = 0; i < this._components.Count; i++)
            {
                LogicComponent component = this._components[i];

                if (component != null)
                {
                    if (component.IsEnabled())
                    {
                        component.FastForwardTime(secs);
                    }
                }
            }
        }
        public virtual void LoadFromSnapshot(LogicJSONObject jsonObject)
        {
            LogicJSONNumber xNumber = jsonObject.GetJSONNumber("x");
            LogicJSONNumber yNumber = jsonObject.GetJSONNumber("y");

            if (xNumber == null || yNumber == null)
            {
                Debugger.Error("LogicGameObject::load - x or y is NULL!");
            }

            this.SetInitialPosition(xNumber.GetIntValue() << 9, yNumber.GetIntValue() << 9);

            for (int i = 0; i < LogicComponent.COMPONENT_TYPE_COUNT; i++)
            {
                LogicComponent component = this.m_components[i];

                if (component != null)
                {
                    component.LoadFromSnapshot(jsonObject);
                }
            }
        }
Exemplo n.º 28
0
        /// <summary>
        ///     Loads this instance from json.
        /// </summary>
        public virtual void Load(LogicJSONObject jsonObject)
        {
            LogicJSONNumber xNumber = jsonObject.GetJSONNumber("x");
            LogicJSONNumber yNumber = jsonObject.GetJSONNumber("y");

            for (int i = 0; i < this._components.Count; i++)
            {
                LogicComponent component = this._components[i];

                if (component != null)
                {
                    component.Load(jsonObject);
                }
            }

            if (xNumber == null || yNumber == null)
            {
                Debugger.Error("LogicGameObject::load - x or y is NULL!");
            }

            this.SetInitialPosition(xNumber.GetIntValue() << 9, yNumber.GetIntValue() << 9);
        }
Exemplo n.º 29
0
 public void Unload()
 {
     this.aslEngine = null;
     this.aslScript = null;
 }
Exemplo n.º 30
0
        /// <summary>
        ///     Called when the clearing of this <see cref="LogicObstacle"/> instance is finished.
        /// </summary>
        public void ClearingFinished(bool ignoreState)
        {
            int state = this._level.GetState();

            if (state == 1 || !LogicDataTables.GetGlobals().CompleteConstructionOnlyHome() && ignoreState)
            {
                if (this._level.GetHomeOwnerAvatar().IsClientAvatar())
                {
                    LogicClientAvatar homeOwnerAvatar  = (LogicClientAvatar)this._level.GetHomeOwnerAvatar();
                    LogicObstacleData obstacleData     = this.GetObstacleData();
                    LogicResourceData lootResourceData = obstacleData.GetLootResourceData();
                    int lootCount = obstacleData.GetLootCount();

                    if (obstacleData.IsLootCart())
                    {
                        LogicComponent component     = this.GetComponent(14);
                        LogicDataTable resourceTable = LogicDataTables.GetTable(2);

                        if (component != null && resourceTable.GetItemCount() > 0)
                        {
                            for (int i = 0; i < resourceTable.GetItemCount(); i++)
                            {
                                // TODO: Implement LootCart.
                            }
                        }
                    }

                    if (!obstacleData.IsTombstone && !obstacleData.IsLootCart())
                    {
                        this._level.GetAchievementManager().ObstacleCleared();
                    }

                    this._level.GetWorkerManagerAt(this._villageType).DeallocateWorker(this);
                    this.XpGainHelper(LogicGamePlayUtil.TimeToExp(obstacleData.GetClearTime()), homeOwnerAvatar, ignoreState || state == 1);

                    if (lootResourceData != null && lootCount > 0)
                    {
                        if (homeOwnerAvatar != null)
                        {
                            if (lootResourceData.PremiumCurrency)
                            {
                                int lootMultipler = 1;

                                if (this._lootMultiplyVersion >= 2)
                                {
                                    lootMultipler = obstacleData.GetLootMultiplierVersion2();
                                }

                                int diamondsCount = obstacleData.GetName().Equals("Bonus Gembox")
                                    ? lootCount * lootMultipler
                                    : this._level.GetGameObjectManagerAt(this._villageType).IncreaseObstacleClearCounter(lootMultipler);

                                if (diamondsCount > 0)
                                {
                                    Debugger.Print("LogicObstacle::clearingFinished diamonds reward: " + diamondsCount);

                                    homeOwnerAvatar.SetDiamonds(homeOwnerAvatar.GetDiamonds() + diamondsCount);
                                    homeOwnerAvatar.SetFreeDiamonds(homeOwnerAvatar.GetFreeDiamonds() + diamondsCount);
                                    homeOwnerAvatar.GetChangeListener().FreeDiamondsAdded(diamondsCount);
                                }
                            }
                            else
                            {
                                int gainCount = LogicMath.Min(homeOwnerAvatar.GetUnusedResourceCap(lootResourceData), lootCount);

                                if (gainCount > 0)
                                {
                                    homeOwnerAvatar.CommodityCountChangeHelper(0, lootResourceData, gainCount);
                                }
                            }
                        }
                        else
                        {
                            Debugger.Error("LogicObstacle::clearingFinished - Home owner avatar is NULL!");
                        }
                    }

                    if (obstacleData.GetVillageType() == this._level.GetVillageType())
                    {
                        // ?
                    }

                    if (this._clearTimer != null)
                    {
                        this._clearTimer.Destruct();
                        this._clearTimer = null;
                    }

                    this._fadeTime = 1;
                }
            }
        }
        public static LogicComponent CreateComponent()
        {
            LogicComponent component = new LogicComponent();

            return component;
        }