Beispiel #1
0
    public void DisplayCityInfo(int x)
    {
        City thisCity = world.GetCityFromTilePosX(x);

        if (thisCity != null)
        {
            cityName.text   = thisCity.name;
            cityHeal.text   = thisCity.cityStats.health.ToString();
            cityEd.text     = thisCity.cityStats.education.ToString();
            cityEnt.text    = thisCity.cityStats.entertainment.ToString();
            cityEcon.text   = thisCity.cityStats.economy.ToString();
            cityDef.text    = thisCity.cityStats.defense.ToString();
            cityTech.text   = thisCity.cityStats.technology.ToString();
            citySpirit.text = thisCity.cityStats.spirituality.ToString();
            cityRating.text = thisCity.cityStats.average.ToString();
            cityPop.text    = thisCity.population.ToString();
            cityAgri.text   = thisCity.cityStats.agriculture.ToString();

            if (!cityStatsPanel.activeSelf)
            {
                cityStatsPanel.SetActive(true);
            }
        }
    }
Beispiel #2
0
    void LineEndFollowMouse(LineRenderer lineR)
    {
        var distance = (transform.position - Mouse_Controller.instance.mousePosition).sqrMagnitude;

        // Set the second position to the mouse but limited to the max wire length
        if (distance <= maxWireLength)
        {
            lineR.SetPosition(1, Mouse_Controller.instance.mousePosition);
        }


        if (Input.GetKeyDown(KeyCode.Space))
        {
            // This cancels a connection by pooling the connection game object (lineR)
            isConnecting = false;
            ObjectPool.instance.PoolObject(lineR.gameObject);
        }

        if (Input.GetMouseButtonDown(0) && mouse.GetTileUnderMouse().tileType == TileType.CITY)
        {
            // CONNECTION HAS BEEN MADE!
            // Charge the Money Manager for its wire purchase. Later I will add a wire type (basic, advanced, etc.) that will have a different cost and different features.

            if (Money_Manager.instance.Purchase("Basic Connection"))
            {
                Tile curTile = mouse.GetTileUnderMouse();
                if (curTile != null)
                {
                    if (curTile.tileType == TileType.CITY)
                    {
                        // Connecting to a City Behavior:
                        Connection newConnect = new Connection(Mathf.RoundToInt(mouse.mousePosition.x), curChoseConnectionType,
                                                               curChosenConnectionMode, Connector.City, myPole, 1, 30f);

                        // All input connections should know their source! and all Output connections should know their input's source!
                        if (newConnect.connectionMode == ConnectionMode.INPUT)
                        {
                            newConnect.sourceCity = world.GetCityFromTilePosX(curTile.posX);
                            //Debug.Log("POLE: Source city set to " + newConnect.sourceCity.name);
                        }
                        else
                        {
                            newConnect.outputCity = world.GetCityFromTilePosX(curTile.posX);
                            //Debug.Log("POLE: Output city set to " + newConnect.outputCity.name);
                        }

                        //Debug.Log("POLE: Made a new " + newConnect.connectionMode + " connection of type " + newConnect.connectionType);


                        isConnecting = false;

                        // Here we have to tell the city handler at the end of the connection that it's receiving a new connnection of this type from this pole
                        Guid id = Guid.NewGuid();

                        //Debug.Log("New ID = " + id);

                        world.GameObjectFromTileXCoord(curTile.posX).GetComponent <City_Handler>().AddNewConnection(id, newConnect);

                        // Register the connection with this pole to keep track of its current connections
                        RegisterConnectionFromMe(id, newConnect);

                        // Set this new connection's Connection Handler
                        connectionGObj.GetComponent <Connection_Handler>().Init(id, newConnect);

                        /*
                         * // THIS LINE BELOW, will cause the connection to stick to a position in the center of the city sprite.
                         * // Could FIX THIS to make the connections look tidier but they can't all connect to the same Vector3, if they do they look like one
                         * // continous line instead of multiple connections.
                         *
                         * lineR.SetPosition(1, world.GetCityFromTilePosX(curTile.posX).connectorPosition);
                         */
                    }
                    else if (curTile.tileType == TileType.POLE)
                    {
                        // Connecting to a Pole Behavior:
                        Connection newConnect = new Connection(Mathf.RoundToInt(mouse.mousePosition.x), curChoseConnectionType,
                                                               curChosenConnectionMode, Connector.Pole, myPole, 1, 30f);

                        // All input connections need its source. In this case, with a new Pole to Pole connection, find the corresponding input connection on this Pole
                        if (newConnect.connectionMode == ConnectionMode.INPUT)
                        {
                            if (inputConnections.ContainsKey(newConnect.connectionType))
                            {
                                newConnect.sourceCity = inputConnections[newConnect.connectionType].sourceCity;
                            }
                        }
                        else
                        {
                            // check this pole for outputs. There's a big chance that the player hasn't set any outputs yet of this type so this will need to be check again!
                            // Check the connector poles outputs
                            if (world.GameObjectFromTileXCoord(curTile.posX).GetComponent <Pole_Handler>().outputConnections.
                                ContainsKey(newConnect.connectionType))
                            {
                                newConnect.outputCity = world.GameObjectFromTileXCoord(curTile.posX).GetComponent <Pole_Handler>().
                                                        outputConnections[newConnect.connectionType].outputCity;
                            }
                        }

                        //Debug.Log("POLE: Made a new " + newConnect.connectionMode + " connection of type " + newConnect.connectionType);

                        isConnecting = false;

                        Guid id = Guid.NewGuid();


                        // Register the connection with this pole to keep track of its current connections
                        RegisterConnectionFromMe(id, newConnect);

                        // Set this new connection's Connection Handler
                        connectionGObj.GetComponent <Connection_Handler>().Init(id, newConnect);

                        // Register the connection on the pole on the end of this connection (reverse the connection mode!)
                        world.GameObjectFromTileXCoord(curTile.posX).GetComponent <Pole_Handler>().RegisterConnectionToMe(id, newConnect);
                    }
                }
            }
            else
            {
                // Money Manager doesn't have enough capital to make this connection purchase
                isConnecting = false;
                // Pool the connection since it was a fail
                ObjectPool.instance.PoolObject(lineR.gameObject);
            }
        }
    }
Beispiel #3
0
    // Input connections Receive Data from their connector
    void ReceiveData()
    {
        Debug.Log("CONNECTION: Receiving Data!");

        // This is a POLE to CITY connection. This means we are Inputting from the connector CITY.

        // First make sure that my pole has an output connection of my connection type
        if (originPole_handler == null)
        {
            Debug.LogError("New Connection could not find it's origin pole from the Connection Manager! Was it not set? Is the X coordinate incorrect?");
        }
        //originPole_handler = world.GameObjectFromTileXCoord(Mathf.RoundToInt(transform.parent.position.x)).GetComponent<Pole_Handler>();

        if (originPole_handler.outputConnections.ContainsKey(myConnection.connectionType))
        {
            // Make sure that the connector City has a stat of this connectionType that is HIGHER than the receiver
            City myCity = world.GetCityFromTilePosX(myConnection.end_x_position);

            City receiverCity = originPole_handler.outputConnections[myConnection.connectionType].outputCity;

            if (receiverCity == null)
            {
                // if this is null it is probably because the Player set added an output connection to a pole that had no output connections
                // get the output city of my output connection's connector pole
                receiverCity = connection_manager.GetPoleHandler(originPole_handler.outputConnections[myConnection.connectionType].end_x_position).
                               outputConnections[myConnection.connectionType].outputCity;

                //receiverCity = world.GameObjectFromTileXCoord(originPole_handler.outputConnections[myConnection.connectionType].
                //    end_x_position).GetComponent<Pole_Handler>().outputConnections[myConnection.connectionType].outputCity;
                if (receiverCity == null)
                {
                    Debug.LogError("CONNECTION: Could not find the output city!");
                }
            }

            if (CompareCityStats(myCity, receiverCity, myConnection.connectionType))
            {
                // This connection can receive data of its type.
                // Since this Connection is connected directly to a city we can just add to its stat here
                SendData(receiverCity, myConnection.connectionType, myConnection.dataPacketSize);

                // If the city stats panel is on, update its information through the Cities Manager
                Cities_Manager.instance.UpdateCityInfoPanel(receiverCity.worldX);
            }
            else
            {
                Debug.Log("CONNECTION: Can't send data because receiver city has the higher " + myConnection.connectionType + " stat!");
            }
        }
        else
        {
            Debug.Log("CONNECTION: Could not find an Output connection in my origin pole handler! Did you forget to add one? Is the pole handler returning null?");
        }


        //else
        //{
        //    //// This is a POLE to POLE connection. This means we are Inputting from another Input connection on the origin pole

        //    //// Check that my origin pole has Output connections of this type
        //    //if (originPole_handler == null)
        //    //    originPole_handler = world.GameObjectFromTileXCoord(Mathf.RoundToInt(transform.parent.position.x)).GetComponent<Pole_Handler>();

        //    //// If the origin pole has inputConnections of this type then we have no receiver to send data to
        //    //if (originPole_handler.outputConnections.ContainsKey(myConnection.connectionType))
        //    //{
        //    //    // Check if this connector Pole has output connections of this type through my connector's Pole handler
        //    //    Pole_Handler pole_handler = world.GameObjectFromTileXCoord(myConnection.end_x_position).GetComponent<Pole_Handler>();

        //    //    if (pole_handler.outputConnections.ContainsKey(myConnection.connectionType))
        //    //    {
        //    //        // it contains a connection of this type

        //    //        // Since this is a POLE to POLE connection my city will be found through my origin Pole's input connections
        //    //        City myCity = myConnection.sourceCity;

        //    //        City receiverCity = world.GetCityFromTilePosX(pole_handler.outputConnections[myConnection.connectionType].end_x_position);

        //    //        // Make sure that the connector City has a stat of this connectionType that is HIGHER than the receiver
        //    //        if (CompareCityStats(myCity, receiverCity, myConnection.connectionType))
        //    //        {
        //    //            // This connection can receive data of its type.
        //    //            // Since this is connected to a pole we have to transfer stat data through the output connection to the city its connected to
        //    //            SendData(receiverCity, myConnection.connectionType, myConnection.dataPacketSize);
        //    //        }

        //    //    }
        //    //}


        //}
    }