Esempio n. 1
0
    /// <summary>
    /// Add a new Module next to the Module this Connector is attached to with 0 inhabitants and 0 infected people
    /// </summary>
    /// <param name="moduleType">The desired Module Type to create</param>
    public void AddModule(Modules moduleType)
    {
        GameObject newModule;

        newModule = Instantiate(pm.modules[(int)moduleType]); //, transform.parent.position + direction, Quaternion.identity
        //newModule.transform.position = transform.parent.position + direction;
        newModule.transform.position = transform.parent.position + direction * (transform.position - transform.parent.position).magnitude * 2;

        PhysNode newPhysNode = newModule.GetComponent <PhysNode>();

        if (newPhysNode.energyCreatingCost > GameData.Energy)
        {
            //Not enough Energy; somehow tell the Player via UI
            Debug.Log("Not enough Energy to create the Module");
            return;
        }
        else
        {
            GameData.Energy -= newPhysNode.energyCreatingCost;
        }

        //Insert Graph Node
        int newID = graph.GetNewId();
        int myID  = this.transform.parent.GetComponent <PhysNode>().id;

        newPhysNode.setupNode(newID, 0, 0);

        graph.AddNode(newPhysNode);

        //Set the Connection between the 2 involved Connectors
        //TODO: Set Connections to other adjacent Modules (maybe via graph?)

        //Set Graph Connection
        graph.SetConnection(newID, myID);

        try
        {
            neighbor          = newModule.GetComponent <PhysNode>().getConnectorByDirection(-direction);
            neighbor.Neighbor = this;

            //Set Level and Bottom Connector
            if (direction.y >= 1.0f)
            {
                //This is a connector at the Top
                neighbor.gameObject.SetActive(true);
                newPhysNode.level = transform.parent.gameObject.GetComponent <PhysNode>().level + 1; //The new Node is one level higher -> increase level
            }
            else
            {
                newPhysNode.level = transform.parent.gameObject.GetComponent <PhysNode>().level; //Same level as this module
            }
        } catch (System.NullReferenceException e)
        {
            Debug.Log("Connection konnte nicht gesetzt werden." + e.StackTrace);
        }

        graph.PrintConnMatr();
    }
Esempio n. 2
0
    public void refreshPeopleFlow(PhysNode newNode)
    {
        //Insert new Node
        if (newNode.inhabitable)
        {
            if (habList.Count == 0)
            {
                firstNodeUnemployed = newNode.Inhab;
            }
            habList.Add(newNode.id);
        }
        else
        {
            workList.Add(newNode.id);
        }

        //Refresh Inhabs + People Flow
        while (habList.Count > 0 && workList.Count > 0)
        {
            PhysNode habNode  = physNodeList[habList[0]];
            PhysNode workNode = physNodeList[workList[0]];

            int peopleFlow = 0;

            if ((workNode.maxInhab - workNode.Inhab) < firstNodeUnemployed) //work Node is Full
            {
                peopleFlow           = workNode.maxInhab - workNode.Inhab;
                firstNodeUnemployed -= peopleFlow;
                workNode.Inhab       = workNode.maxInhab;
                workList.RemoveAt(0);
            }
            else if (firstNodeUnemployed < (workNode.maxInhab - workNode.Inhab))  //hab Node is Full
            {
                peopleFlow      = firstNodeUnemployed;
                workNode.Inhab += peopleFlow;
                habList.RemoveAt(0);
                if (habList.Count > 0)
                {
                    firstNodeUnemployed = physNodeList[habList[0]].Inhab;
                }
            }
            else   //both full
            {
                peopleFlow     = firstNodeUnemployed;
                workNode.Inhab = workNode.maxInhab;
                habList.RemoveAt(0);
                workList.RemoveAt(0);
                if (habList.Count > 0)
                {
                    firstNodeUnemployed = physNodeList[habList[0]].Inhab;
                }
            }

            this.peopleFlow[habNode.id, workNode.id] = peopleFlow;
            this.peopleFlow[workNode.id, habNode.id] = peopleFlow;
        }
    }
Esempio n. 3
0
    public void AddNode(PhysNode newNode)
    {
        //Extend connection Matrix
        int[,] oldConnMatr = connectionMatrix;
        int[,] newConnMatr = InsertNodeToMatrix(oldConnMatr, 1);
        connectionMatrix   = newConnMatr;

        //Extend peopleFlow Matrix
        int[,] oldPeopleFlowMatr = peopleFlow;
        int[,] newPeopleFlowMatr = InsertNodeToMatrix(oldPeopleFlowMatr, 1);
        peopleFlow = newPeopleFlowMatr;


        //Add PhysNode
        physNodeList.Add(newNode);
        setAllShortestPathArrayLength(physNodeList.Count);
    }