Beispiel #1
0
        public override void Init(GameObject hand, Vector3 axis_in, WhichHands whichHand)
        {
            if (transform != null)
            {
                axis = axis_in;

                phalanges    = new Phalanx[3];
                phalanges[0] = new Phalanx(transform);
                if (phalanges[0].transform.childCount == 1)
                {
                    phalanges[1] = new Phalanx(phalanges[0].transform.GetChild(0).transform);
                    if (phalanges[1].transform.childCount == 1)
                    {
                        phalanges[2] = new Phalanx(phalanges[1].transform.GetChild(0).transform);
                        nPhalanges   = 3;
                    }
                    else
                    {
                        phalanges[2] = null;
                        nPhalanges   = 2;
                    }
                }
                else
                {
                    phalanges[1] = null;
                    nPhalanges   = 1;
                }
            }
        }
Beispiel #2
0
        public NetworkManager(Phalanx phalanx)
        {
            _phalanx = phalanx;

            // Initialize ENet.
            Library.Initialize();
        }
Beispiel #3
0
    /////////////////////////////////////
    /// PUBLIC PROPERTIES ///////////////
    /////////////////////////////////////


    /////////////////////////////////////
    /// PUBLIC METHODS //////////////////
    /////////////////////////////////////

    //////////////////////////////////////
    /// PRIVATE METHODS AND PROPERTIES ///
    //////////////////////////////////////
    private void Awake()
    {
        terrainMask      = LayerMask.GetMask("Terrain");
        selectedEntities = new List <Entity>();
        phalanxes        = new List <Phalanx>();
        selectedPhalanx  = null;
        selectionArea.gameObject.SetActive(false);
    }
Beispiel #4
0
    private void Update()
    {
        // Left mouse button pressed
        if (Input.GetMouseButtonDown(0))
        {
            mouseStartPosition = Utilities.GetMouseWorldPosition();
            selectionArea.gameObject.SetActive(true);

            // Clears list of selected units
            foreach (Entity entity in selectedEntities)
            {
                entity.SelectEntity(false);
            }
            selectedEntities.Clear();

            // Clears selected phalanx
            if (selectedPhalanx != null)
            {
                selectedPhalanx.SetSelectedStatus(false);
            }
            selectedPhalanx = null;
        }

        // While left mouse button pressed
        if (Input.GetMouseButton(0))
        {
            Vector3 currentMousePosition = Utilities.GetMouseWorldPosition();
            Vector3 lowerLeft            = new Vector3(
                Mathf.Min(mouseStartPosition.x, currentMousePosition.x),
                Mathf.Min(mouseStartPosition.y, currentMousePosition.y)
                );
            Vector3 upperRight = new Vector3(
                Mathf.Max(mouseStartPosition.x, currentMousePosition.x),
                Mathf.Max(mouseStartPosition.y, currentMousePosition.y)
                );

            selectionArea.position   = lowerLeft;
            selectionArea.localScale = upperRight - lowerLeft;
        }


        // Left mouse button released
        if (Input.GetMouseButtonUp(0))
        {
            // Turns off selected area indicator
            selectionArea.gameObject.SetActive(false);

            // Gathers all colliders in selected area and adds all entities to selected entities
            Collider2D[] colliders = Physics2D.OverlapAreaAll(mouseStartPosition, Utilities.GetMouseWorldPosition());
            // TODO: Implement max entity selected limit
            foreach (Collider2D c in colliders)
            {
                Entity e = c.GetComponent <Entity>();
                if (e && e.faction == playerFaction && e.ActivePhalanx == null)
                {
                    selectedEntities.Add(e);
                    e.SelectEntity(true);
                }
            }
        }

        // Right mouse button pressed
        if (Input.GetMouseButtonDown(1))
        {
            Vector3        targetPosition = Utilities.GetMouseWorldPosition();
            List <Vector3> formation;

            // If phalanx is selected
            if (selectedPhalanx != null)
            {
                // formation = fGen.GetPhalanxFormation(targetPosition, formationDirection, selectedPhalanx.links.Count);
                // for (int i = 0; i < selectedPhalanx.links.Count; i++)
                // {
                //     selectedPhalanx.links[i].GetComponent<IMovePosition>().SetMovePosition(formation[i]);
                //     selectedPhalanx.links[i].phalanxDirection = formationDirection;
                // }

                selectedPhalanx.EstablishFormationAt(targetPosition, formationDirection);
            }

            // No phalanx selected
            else
            {
                formation = fGen.GetCircleFormation(targetPosition);
                int targetPositionsIndex = 0;

                foreach (Entity entity in selectedEntities)
                {
                    entity.MoveTo(formation[targetPositionsIndex]);
                    targetPositionsIndex = (targetPositionsIndex + 1) % formation.Count;
                }
            }
        }

        // Clears old formation indication
        HideFormationIndication();

        // Draws new formation indication if there is entities selected
        if (selectedEntities.Count > 0 || selectedPhalanx != null)
        {
            DrawFormationIndication();
        }

        // Rotating formation
        if (Input.GetKeyDown(KeyCode.R))
        {
            int nextVal = (int)formationDirection + 1;
            formationDirection = (Direction)(nextVal % Enum.GetNames(typeof(Direction)).Length);
        }

        // Grouping entities
        if (Input.GetKeyDown(KeyCode.G))
        {
            if (selectedPhalanx != null)
            {
                selectedPhalanx.Disband();
                phalanxes.Remove(selectedPhalanx);
                selectedPhalanx = null;
            }
            else if (selectedEntities.Count > 0)
            {
                // Create new phalanx
                // Add selected entities as phalanx links

                Phalanx newPhalanx = new Phalanx(settings);
                foreach (Entity entity in selectedEntities)
                {
                    entity.SelectEntity(false);
                    newPhalanx.AddEntity(entity);
                    entity.ActivePhalanx = newPhalanx;
                }

                selectedEntities.Clear();

                selectedPhalanx = newPhalanx;
                selectedPhalanx.SetSelectedStatus(true);
                phalanxes.Add(newPhalanx);
            }
        }

        // Cycles selected phalanx
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            if (selectedPhalanx == null)
            {
                if (phalanxes.Count > 0)
                {
                    selectedPhalanx = phalanxes[lastSelectedPhalanxIndex % phalanxes.Count];
                    selectedPhalanx.SetSelectedStatus(true);
                }
            }
            else
            {
                selectedPhalanx.SetSelectedStatus(false);
                lastSelectedPhalanxIndex = (phalanxes.FindIndex(item => item == selectedPhalanx) + 1) % phalanxes.Count;
                selectedPhalanx          = phalanxes[lastSelectedPhalanxIndex];
                selectedPhalanx.SetSelectedStatus(true);
            }
        }
    }
Beispiel #5
0
        internal static void CityProduction(City city)
        {
            if (city == null || city.Size == 0 || city.Tile == null)
            {
                return;
            }

            Player      player     = Game.GetPlayer(city.Owner);
            IProduction production = null;

            // Create 2 defensive units per city
            if (player.HasAdvance <LaborUnion>())
            {
                if (city.Tile.Units.Count(x => x is MechInf) < 2)
                {
                    production = new MechInf();
                }
            }
            else if (player.HasAdvance <Conscription>())
            {
                if (city.Tile.Units.Count(x => x is Riflemen) < 2)
                {
                    production = new Riflemen();
                }
            }
            else if (player.HasAdvance <Gunpowder>())
            {
                if (city.Tile.Units.Count(x => x is Musketeers) < 2)
                {
                    production = new Musketeers();
                }
            }
            else if (player.HasAdvance <BronzeWorking>())
            {
                if (city.Tile.Units.Count(x => x is Phalanx) < 2)
                {
                    production = new Phalanx();
                }
            }
            else
            {
                if (city.Tile.Units.Count(x => x is Militia) < 2)
                {
                    production = new Militia();
                }
            }

            // Create city improvements
            if (production == null)
            {
                if (!city.HasBuilding <Barracks>())
                {
                    production = new Barracks();
                }
                else if (player.HasAdvance <Pottery>() && !city.HasBuilding <Granary>())
                {
                    production = new Granary();
                }
                else if (player.HasAdvance <CeremonialBurial>() && !city.HasBuilding <Temple>())
                {
                    production = new Temple();
                }
                else if (player.HasAdvance <Masonry>() && !city.HasBuilding <CityWalls>())
                {
                    production = new CityWalls();
                }
            }

            // Create Settlers
            if (production == null)
            {
                if (city.Size > 3 && !city.Units.Any(x => x is Settlers) && player.Cities.Length < 10)
                {
                    production = new Settlers();
                }
            }

            // Create some other unit
            if (production == null)
            {
                if (city.Units.Length < 4)
                {
                    if (player.Government is Republic || player.Government is Democratic)
                    {
                        if (player.HasAdvance <Writing>())
                        {
                            production = new Diplomat();
                        }
                    }
                    else
                    {
                        if (player.HasAdvance <Automobile>())
                        {
                            production = new Armor();
                        }
                        else if (player.HasAdvance <Metallurgy>())
                        {
                            production = new Cannon();
                        }
                        else if (player.HasAdvance <Chivalry>())
                        {
                            production = new Knights();
                        }
                        else if (player.HasAdvance <TheWheel>())
                        {
                            production = new Chariot();
                        }
                        else if (player.HasAdvance <HorsebackRiding>())
                        {
                            production = new Cavalry();
                        }
                        else if (player.HasAdvance <IronWorking>())
                        {
                            production = new Legion();
                        }
                    }
                }
                else
                {
                    if (player.HasAdvance <Trade>())
                    {
                        production = new Caravan();
                    }
                }
            }

            // Set random production
            if (production == null)
            {
                IProduction[] items = city.AvailableProduction.ToArray();
                production = items[Common.Random.Next(items.Length)];
            }

            city.SetProduction(production);
        }
Beispiel #6
0
        private static IUnit CreateUnit(UnitType type, int x, int y)
        {
            IUnit unit;

            switch (type)
            {
            case UnitType.Settlers: unit = new Settlers(); break;

            case UnitType.Militia: unit = new Militia(); break;

            case UnitType.Phalanx: unit = new Phalanx(); break;

            case UnitType.Legion: unit = new Legion(); break;

            case UnitType.Musketeers: unit = new Musketeers(); break;

            case UnitType.Riflemen: unit = new Riflemen(); break;

            case UnitType.Cavalry: unit = new Cavalry(); break;

            case UnitType.Knights: unit = new Knights(); break;

            case UnitType.Catapult: unit = new Catapult(); break;

            case UnitType.Cannon: unit = new Cannon(); break;

            case UnitType.Chariot: unit = new Chariot(); break;

            case UnitType.Armor: unit = new Armor(); break;

            case UnitType.MechInf: unit = new MechInf(); break;

            case UnitType.Artillery: unit = new Artillery(); break;

            case UnitType.Fighter: unit = new Fighter(); break;

            case UnitType.Bomber: unit = new Bomber(); break;

            case UnitType.Trireme: unit = new Trireme(); break;

            case UnitType.Sail: unit = new Sail(); break;

            case UnitType.Frigate: unit = new Frigate(); break;

            case UnitType.Ironclad: unit = new Ironclad(); break;

            case UnitType.Cruiser: unit = new Cruiser(); break;

            case UnitType.Battleship: unit = new Battleship(); break;

            case UnitType.Submarine: unit = new Submarine(); break;

            case UnitType.Carrier: unit = new Carrier(); break;

            case UnitType.Transport: unit = new Transport(); break;

            case UnitType.Nuclear: unit = new Nuclear(); break;

            case UnitType.Diplomat: unit = new Diplomat(); break;

            case UnitType.Caravan: unit = new Caravan(); break;

            default: return(null);
            }
            unit.X         = x;
            unit.Y         = y;
            unit.MovesLeft = unit.Move;
            return(unit);
        }
        public override void Init(GameObject hand, Vector3 fingerAxis, Vector3 armAxis, bool bodySideLeft, int fingerIndex) {
            if (transform != null) {
                this.fingerIndex = fingerIndex;
				this.axis1 = fingerAxis;
                this.axis2 = Vector3.Cross(fingerAxis, armAxis);
				
				phalanges = new Phalanx[3];
				phalanges[0] = new Phalanx(transform);
				if (phalanges[0].transform.childCount == 1) {
					phalanges[1] = new Phalanx(phalanges[0].transform.GetChild(0).transform);
					if (phalanges[1].transform.childCount == 1) {
						phalanges[2] = new Phalanx(phalanges[1].transform.GetChild(0).transform);
						nPhalanges = 3;
					} else {
						phalanges[2] = null;
						nPhalanges = 2;
					}
				} else {
					phalanges[1] = null;
					nPhalanges = 1;
				}
			}
		}
        public override void Init(GameObject hand, Vector3 axis_in, WhichHands whichHand)
        {
            if (transform != null) {
                axis = axis_in;

                phalanges = new Phalanx[3];
                phalanges[0] = new Phalanx(transform);
                if (phalanges[0].transform.childCount == 1) {
                    phalanges[1] = new Phalanx(phalanges[0].transform.GetChild(0).transform);
                    if (phalanges[1].transform.childCount == 1) {
                        phalanges[2] = new Phalanx(phalanges[1].transform.GetChild(0).transform);
                        nPhalanges = 3;
                    } else {
                        phalanges[2] = null;
                        nPhalanges = 2;
                    }
                } else {
                    phalanges[1] = null;
                    nPhalanges = 1;
                }
            }
        }
Beispiel #9
0
    public Hand(string type, Vector3 pos)
    {
        _palm   = new Palm(type, pos);
        _thumb  = new Phalanx[2];
        _index  = new Phalanx[3];
        _middle = new Phalanx[3];
        _ring   = new Phalanx[3];
        _little = new Phalanx[3];

        var dir = 0;

        if (type == "left")
        {
            dir = 1;
        }
        else if (type == "right")
        {
            dir = -1;
        }

        for (var i = 0; i < _thumb.Length; ++i)
        {
            var name       = "thumb" + (i + 1);
            var phalanxPos = new Vector3(0, 0, 1);
            var parent     = _palm.Body;
            if (i == 0)
            {
                phalanxPos += _palm.LocalFingerPoints[0] + new Vector3(dir * 0.5f, 0, -0.5f);
            }
            else
            {
                parent = _thumb[i - 1].Body;
            }
            _thumb[i] = new Phalanx(type, name, phalanxPos, parent);
        }
        for (var i = 0; i < _index.Length; ++i)
        {
            var name       = "index" + (i + 1);
            var phalanxPos = new Vector3(0, 0, 1);
            var parent     = _palm.Body;
            if (i == 0)
            {
                phalanxPos += _palm.LocalFingerPoints[1] + new Vector3(0, 0, -0.5f);
            }
            else
            {
                parent = _index[i - 1].Body;
            }
            _index[i] = new Phalanx(type, name, phalanxPos, parent);
        }
        for (var i = 0; i < _middle.Length; ++i)
        {
            var name       = "middle" + (i + 1);
            var phalanxPos = new Vector3(0, 0, 1);
            var parent     = _palm.Body;
            if (i == 0)
            {
                phalanxPos += _palm.LocalFingerPoints[2] + new Vector3(0, 0, -0.5f);
            }
            else
            {
                parent = _middle[i - 1].Body;
            }
            _middle[i] = new Phalanx(type, name, phalanxPos, parent);
        }
        for (var i = 0; i < _ring.Length; ++i)
        {
            var name       = "ring" + (i + 1);
            var phalanxPos = new Vector3(0, 0, 1);
            var parent     = _palm.Body;
            if (i == 0)
            {
                phalanxPos += _palm.LocalFingerPoints[3] + new Vector3(0, 0, -0.5f);
            }
            else
            {
                parent = _ring[i - 1].Body;
            }
            _ring[i] = new Phalanx(type, name, phalanxPos, parent);
        }
        for (var i = 0; i < _little.Length; ++i)
        {
            var name       = "little" + (i + 1);
            var phalanxPos = new Vector3(0, 0, 1);
            var parent     = _palm.Body;
            if (i == 0)
            {
                phalanxPos += _palm.LocalFingerPoints[4] + new Vector3(0, 0, -0.5f);
            }
            else
            {
                parent = _little[i - 1].Body;
            }
            _little[i] = new Phalanx(type, name, phalanxPos, parent);
        }

        var parentArray = new[]
        {
            _thumb[1], _index[2], _index[0], _middle[2], _middle[0], _little[2], _little[0], _ring[2], _ring[0]
        };

        _pressure = new GameObject[12];
        for (var i = 0; i < _pressure.Length; ++i)
        {
            _pressure[i]      = GameObject.CreatePrimitive(PrimitiveType.Quad);
            _pressure[i].name = "P" + (i + 1);
            if (i < parentArray.Length)
            {
                _pressure[i].transform.parent        = parentArray[i].Body.transform;
                _pressure[i].transform.localPosition = new Vector3(0, -0.4001f, 0);
                _pressure[i].transform.localScale    = new Vector3(0.6f, 0.6f, 1);
            }
            else
            {
                _pressure[i].transform.parent     = _palm.Body.transform;
                _pressure[i].transform.localScale = new Vector3(1.8f, 1.8f, 1);
            }
            _pressure[i].transform.localEulerAngles = new Vector3(-90, -90, 0);
        }
        _pressure[9].transform.localPosition  = new Vector3(dir * 1, -0.4001f, -1);
        _pressure[10].transform.localPosition = new Vector3(dir * 1, -0.4001f, 1);
        _pressure[11].transform.localPosition = new Vector3(dir * -1, -0.4001f, 1);
    }