Esempio n. 1
0
        public BorderBattle(VisualArmy armyPrefab, int turn, List <Army> armies) : base(armyPrefab, turn, armies)
        {
            SupportOnly = armies.All(x => x.Type == ArmyType.Support);

            if (armies.Count != 2)
            {
                throw new System.Exception("Border battles can only be fought with exactly 2 armies attack each other");
            }
            Type = BattleType.BorderBattle;

            List <Vector2> army0Path = new List <Vector2>();
            List <Vector2> army1Path = new List <Vector2>();

            army0Path.Add(Armies[0].SourceTerritory.Region.CenterPoi);
            army1Path.Add(Armies[1].SourceTerritory.Region.CenterPoi);
            if (Armies[0].IsWaterArmy)
            {
                IsWaterBattle = true;
                WaterConnection wc = Armies[0].SourceTerritory.Region.GetWaterConnectionTo(Armies[0].TargetTerritory.Region);
                System.Tuple <Vector2, float> center = new System.Tuple <Vector2, float>(wc.Center, wc.FromRegion == Armies[0].SourceTerritory.Region ? wc.Angle - 90 : wc.Angle + 90);
                Vector2 fightPosition    = center.Item1;
                float   fightAngleArmy0  = center.Item2;
                float   fightAngleArmy1  = center.Item2 + 180;
                float   approachDistance = wc.Length / 2f;

                float   xSource0  = Mathf.Sin(Mathf.Deg2Rad * fightAngleArmy0) * approachDistance;
                float   ySource0  = Mathf.Cos(Mathf.Deg2Rad * fightAngleArmy0) * approachDistance;
                Vector2 coastPos0 = fightPosition + new Vector2(xSource0, ySource0);
                army0Path.Add(coastPos0);
                army0Path.Add(fightPosition);

                float   xSource1  = Mathf.Sin(Mathf.Deg2Rad * fightAngleArmy1) * approachDistance;
                float   ySource1  = Mathf.Cos(Mathf.Deg2Rad * fightAngleArmy1) * approachDistance;
                Vector2 coastPos1 = fightPosition + new Vector2(xSource1, ySource1);
                army1Path.Add(coastPos1);
                army1Path.Add(fightPosition);
            }
            else
            {
                IsWaterBattle = false;
                System.Tuple <Vector2, float> center = Armies[0].SourceTerritory.Region.GetBorderCenterPositionTo(Armies[0].TargetTerritory.Region);
                Vector2 fightPosition = center.Item1;
                army0Path.Add(fightPosition);
                army1Path.Add(fightPosition);
            }

            VisualArmy army0 = GameObject.Instantiate(armyPrefab);

            army0.Init(Armies[0], army0Path, ParriskGame.ArmyApproachTime);

            VisualArmy army1 = GameObject.Instantiate(armyPrefab);

            army1.Init(Armies[1], army1Path, ParriskGame.ArmyApproachTime);
        }
Esempio n. 2
0
        public void AddArmyFromBorderBattle(VisualArmy armyPrefab, Army army)
        {
            Armies.Add(army);
            SupportOnly = Armies.All(x => x.Type == ArmyType.Support);

            if (!Territories.Contains(army.TargetTerritory))
            {
                Territories.Add(army.TargetTerritory);
            }
            if (!Players.Contains(army.SourcePlayer))
            {
                Players.Add(army.SourcePlayer);
            }
            if (!Players.Contains(army.TargetPlayer))
            {
                Players.Add(army.TargetPlayer);
            }


            // Visual
            List <Vector2> walkPath = new List <Vector2>();

            if (army.IsWaterArmy)
            {
                WaterConnection wc = army.SourceTerritory.Region.GetWaterConnectionTo(army.TargetTerritory.Region);
                System.Tuple <Vector2, float> center = new System.Tuple <Vector2, float>(wc.Center, wc.FromRegion == army.SourceTerritory.Region ? wc.Angle - 90 : wc.Angle + 90);
                Vector2 borderCenter     = center.Item1;
                float   targetAngle      = center.Item2 + 180;
                float   approachDistance = wc.Length / 2f;
                float   xTarget          = Mathf.Sin(Mathf.Deg2Rad * targetAngle) * approachDistance;
                float   yTarget          = Mathf.Cos(Mathf.Deg2Rad * targetAngle) * approachDistance;
                Vector2 coastPos         = borderCenter + new Vector2(xTarget, yTarget);
                walkPath.Add(borderCenter);
                walkPath.Add(coastPos);
            }
            else
            {
                System.Tuple <Vector2, float> center = army.SourceTerritory.Region.GetBorderCenterPositionTo(army.TargetTerritory.Region);
                Vector2 borderCenter = center.Item1;
                walkPath.Add(borderCenter);
            }
            Vector2 targetPos = army.TargetTerritory.Region.CenterPoi;

            walkPath.Add(targetPos);

            VisualArmy visualArmy = GameObject.Instantiate(armyPrefab);

            visualArmy.Init(army, walkPath, ParriskGame.ArmyApproachTime);
        }
Esempio n. 3
0
        public TerritoryBattle(VisualArmy armyPrefab, int turn, List <Army> armies) : base(armyPrefab, turn, armies)
        {
            Type        = BattleType.TerritoryBattle;
            SupportOnly = armies.All(x => x.Type == ArmyType.Support);

            // Check if all armies have the same target territory
            Army targetArmy = armies.FirstOrDefault();

            if (targetArmy != null && !armies.All(x => x.TargetTerritory == targetArmy.TargetTerritory))
            {
                throw new System.Exception("Not all armies have the same target territory!");
            }

            foreach (Army army in Armies)
            {
                List <Vector2> walkPath  = new List <Vector2>();
                Vector2        sourcePos = army.SourceTerritory.Region.CenterPoi;
                walkPath.Add(sourcePos);
                if (army.IsWaterArmy)
                {
                    WaterConnection wc = army.SourceTerritory.Region.GetWaterConnectionTo(army.TargetTerritory.Region);
                    System.Tuple <Vector2, float> center = new System.Tuple <Vector2, float>(wc.Center, wc.FromRegion == army.SourceTerritory.Region ? wc.Angle - 90 : wc.Angle + 90);
                    Vector2 borderCenter     = center.Item1;
                    float   sourceAngle      = center.Item2;
                    float   targetAngle      = center.Item2 + 180;
                    float   approachDistance = wc.Length / 2f;
                    float   xSource          = Mathf.Sin(Mathf.Deg2Rad * sourceAngle) * approachDistance;
                    float   ySource          = Mathf.Cos(Mathf.Deg2Rad * sourceAngle) * approachDistance;
                    Vector2 coastPosSource   = borderCenter + new Vector2(xSource, ySource);
                    float   xTarget          = Mathf.Sin(Mathf.Deg2Rad * targetAngle) * approachDistance;
                    float   yTarget          = Mathf.Cos(Mathf.Deg2Rad * targetAngle) * approachDistance;
                    Vector2 coastPosTarget   = borderCenter + new Vector2(xTarget, yTarget);
                    walkPath.Add(coastPosSource);
                    walkPath.Add(coastPosTarget);
                }
                else
                {
                    System.Tuple <Vector2, float> center = army.SourceTerritory.Region.GetBorderCenterPositionTo(army.TargetTerritory.Region);
                    Vector2 borderCenter = center.Item1;
                    walkPath.Add(borderCenter);
                }
                Vector2 targetPos = army.TargetTerritory.Region.CenterPoi;
                walkPath.Add(targetPos);

                VisualArmy visualArmy = GameObject.Instantiate(armyPrefab);
                visualArmy.Init(army, walkPath, ParriskGame.ArmyApproachTime * 2);
            }
        }
Esempio n. 4
0
        public bool SupportOnly; // If this is true, only armies from one player are involved

        public Battle(VisualArmy armyPrefab, int turn, List <Army> armies)
        {
            Turn   = turn;
            Armies = armies;

            foreach (Army army in armies)
            {
                if (!Territories.Contains(army.TargetTerritory))
                {
                    Territories.Add(army.TargetTerritory);
                }
                if (!Players.Contains(army.SourcePlayer))
                {
                    Players.Add(army.SourcePlayer);
                }
                if (!Players.Contains(army.TargetPlayer))
                {
                    Players.Add(army.TargetPlayer);
                }
            }
        }