/// <summary>
 /// Load made Battalions into list
 /// </summary>
 /// <param name="read"></param>
 private void LoadBattalions(StreamReader read)
 {
     LoadSoldiersInOptions();
     int.TryParse(read.ReadLine(), out numBat);
     for (int i = 0; i < numBat; i++)
     {
         Battalion gen = gameObject.AddComponent(typeof(Battalion)) as Battalion;
         gen.Name      = read.ReadLine();
         gen.commander = read.ReadLine();
         gen.InitiateCommand(availableChars);
         gen.avaialableSoldiers = availableSoldiers;
         for (int j = 0; j < 4; j++)
         {
             gen.soldiers.Add(CheckAndCreateSoldier(read.ReadLine(), j));
         }
         Battalions.Add(gen);
     }
     Battalions[battalionIndex].LoadCommand();
     StartCoroutine(Battalions[battalionIndex].LoadSoldiers());
     StartCoroutine(DisplayStats(true, availableChars[Battalions[battalionIndex].CharIndex]));
     StartCoroutine(DisplayBattalionName(Battalions[battalionIndex].Name, true));
     StartCoroutine(InitiateParticles(availableChars[Battalions[battalionIndex].CharIndex]));
     StartCoroutine(DisplaySymbol(Battalions[battalionIndex].ComChar, true));
     StartCoroutine(DisplayName(Battalions[battalionIndex].ComChar));
     StartCoroutine(DisplayArrows());
     StartCoroutine(DisplayTeamStat(true, Battalions[battalionIndex]));
 }
    public void updateSelectedObjects(List <SelectableObject> selectedObjs)
    {
        selectedObjects.Clear();
        if (selectedObjs != null)
        {
            foreach (SelectableObject i in selectedObjs)
            {
                Battalion   battalionToAdd = i.GetComponentInParent <Battalion>();
                WorldObject objToAdd       = i.GetComponent <WorldObject>();
                Buildings   buildingToAdd  = i.GetComponent <Buildings> ();

                if (battalionToAdd)                   //add commander, not unit
                {
                    objToAdd = battalionToAdd.GetComponent <WorldObject> ();
                }
                else if (buildingToAdd)                     //open building menu if it has one
                {
                    buildingToAdd.openMenu();
                }

                if (!selectedObjects.Contains(objToAdd))
                {
                    selectedObjects.Add(objToAdd);
                }
            }
        }
        //update HUD here with the selected objects
        HUD.updateSelection(selectedObjects);
    }
示例#3
0
 // This loads the player's battalion composition into the static
 // slots in the battle scene.
 public void load_bat(Battalion b)
 {
     foreach (int type_ID in b.units.Keys)
     {
         load_unit_text(b, type_ID);
         unit_buttons[type_ID].interactable = b.units[type_ID].Count > 0;
     }
     MapUI.I.highlight_discipline(discT, null, b.disc.ID);
 }
示例#4
0
    public void moveUnitOnSpawn(NetworkInstanceId id)      //moves your new battalion out of spawn
    {
        GameObject obj       = ClientScene.FindLocalObject(id);
        Battalion  battalion = obj.GetComponent <Battalion> ();

        battalion.spawnMove(unitFlagStart, unitFlagEnd);
        //move new spawned unit to unit flag start, then get into formation & give player control
        //once in formation(and only when in formation) move to unit flag end (but player can just select them and move them at this point)
    }
示例#5
0
    /*
     * Load unit counts in unit placement sidebar.
     */
    private string build_unit_text(Battalion b, int ID)
    {
        if (!texts.ContainsKey(ID))
        {
            return("");
        }
        string num         = b.count_placeable(ID).ToString();
        int    total_num   = b.units[ID].Count;
        int    num_injured = b.count_injured(ID);

        return(num + " / " + total_num.ToString() + "    " + num_injured);
    }
示例#6
0
 public SBattalion(Battalion bat)
 {
     healthy_types = new List <int>(PlayerUnit.unit_types.Count);
     injured_types = new List <int>(PlayerUnit.unit_types.Count);
     foreach (int type in PlayerUnit.unit_types)
     {
         int injured = bat.count_injured(type);
         int healthy = bat.units[type].Count - injured;
         healthy_types.Add(healthy);
         injured_types.Add(injured);
     }
 }
示例#7
0
 protected override void DeleteInternal()
 {
     if (Engine)
     {
         Engine.Dismiss();
     }
     if (Battalion)
     {
         Battalion.Dismiss();
     }
     if (Rescue)
     {
         Rescue.Dismiss();
     }
     StopAlarm();
 }
示例#8
0
        public void PowerRule()
        {
            string lengaBuruBattalions             = "100 H,50 E,10 AT,5 SG";
            string enemyBattalion                  = "175 H,60 E,10 AT,5 SG";
            Dictionary <int, Battalion> battalion  = Helper.Process(lengaBuruBattalions);
            Dictionary <int, Battalion> ebattalion = Helper.Process(enemyBattalion);

            Battalion current = battalion[1];
            Battalion next    = battalion[3];


            IWarRule warRule = new PowerRule(ebattalion[1]);

            warRule.CalculateUnits(current);
            Assert.AreEqual(88, current.Required);
        }
示例#9
0
 public void createCircle(SelectableObject selectableObject)         //cirlce prefabs should be set to 0.1 and 0.2 higher in y for projection to work
 {
     if (selectableObject.selectionCircle == null)                   //only creates if they haven't got one, this stops us setting all units many times
     {
         if (selectableObject.gameObject.GetComponent <Buildings>()) //if selected is a building, use bigger selection prefab
         {
             selectableObject.selectionCircle = Instantiate(selectionCircleBiggerPrefab);
             selectableObject.selectionCircle.transform.SetParent(selectableObject.transform, false);
         }
         else                                                                                      //its a unit or battalion, make sure to call select on the battalion and give the units circles in the battalion
         {
             Battalion battalion = selectableObject.gameObject.GetComponentInParent <Battalion>(); //get battalion
             battalion.Select(selectionCirclePrefab);
         }
     }
 }
示例#10
0
        public void Like_To_Like_Rule()
        {
            string lengaBuruBattalions             = "100 H,50 E,10 AT,5 SG";
            string enemyBattalion                  = "175 H,60 E,10 AT,5 SG";
            Dictionary <int, Battalion> battalion  = Helper.Process(lengaBuruBattalions);
            Dictionary <int, Battalion> ebattalion = Helper.Process(enemyBattalion);

            Battalion current = battalion[1];

            current.Required = 88;


            IWarRule warRule = new Like_To_Like_Rule();

            warRule.CalculateUnits(current);
            Assert.AreEqual(88, current.Deployed);
        }
示例#11
0
        public void GetHelpFromLowerBattaliion()
        {
            string lengaBuruBattalions            = "100 H,50 E,10 AT,5 SG";
            Dictionary <int, Battalion> battalion = Helper.Process(lengaBuruBattalions);
            Battalion previous = battalion[1];
            Battalion current  = battalion[2];

            current.Previous = previous;

            current.Deployed = 50;
            current.Required = 51;

            IWarRule warRule = new SubstitutionWithLowerBattalionRule();

            warRule.CalculateUnits(battalion[2]);
            Assert.AreEqual(2, previous.Deployed);
        }
示例#12
0
        public async Task <IActionResult> Create(CombatFormationViewModel combatForm)
        {
            Battalion battalion = new Battalion()
            {
                Name                  = combatForm.Name,
                Number                = combatForm.Number,
                TotalStrenght         = combatForm.TotalStrenght,
                AdditionalInformation = combatForm.AdditionalInformation,
                Commanders            = combatForm.Commanders,
                WeekId                = combatForm.WeekId,
                RegimentId            = combatForm.RegimentId,
                Image                 = combatForm.Image,
                Week                  = combatForm.Week,
                CoordinatesXY         = combatForm.Coordinates,
                CoordX                = combatForm.CoordX,
                CoordY                = combatForm.CoordY,
                Adress                = combatForm.Adress
            };

            if (ModelState.IsValid)
            {
                if (combatForm.Coordinates != null)
                {
                    string[] str = combatForm.Coordinates.Split(',', 2, StringSplitOptions.None);
                    battalion.CoordX = str[0];
                    battalion.CoordY = str[1];
                }
                if (combatForm.File != null)
                {
                    byte[] imageData = null;
                    // считываем переданный файл в массив байтов
                    using (var binaryReader = new BinaryReader(combatForm.File.OpenReadStream()))
                    {
                        imageData = binaryReader.ReadBytes((int)combatForm.File.Length);
                    }
                    // установка массива байтов
                    battalion.Image = imageData;
                }
                _context.Add(battalion);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Edit", new { id = battalion.BattalionId }));
            }
            return(View(battalion));
        }
示例#13
0
        public void GetHelpFromHigherBattaliion()
        {
            string lengaBuruBattalions            = "100 H,50 E,10 AT,5 SG";
            Dictionary <int, Battalion> battalion = Helper.Process(lengaBuruBattalions);

            Battalion current = battalion[2];
            Battalion next    = battalion[3];

            current.Next = next;

            current.Deployed = 50;
            current.Required = 54;

            IWarRule warRule = new SubstituteWithHigherBattalionRule();

            warRule.CalculateUnits(current);
            //Assert.AreEqual(0, current.AdditionalUnits);
            Assert.AreEqual(false, current.IsExhausted);
            Assert.AreEqual(2, next.Deployed);
            Assert.AreEqual(8, next.Remaining);
        }
示例#14
0
        //ДОБАВИТЬ БАТАЛЬОН
        private void addBattalion_Click(object sender, EventArgs e)
        {
            using (MillitaryDbContext context = new MillitaryDbContext())
            {
                foreach (Battalion bat in context.Battalions)
                {
                    if (bat.Name == newNameBattalion.Text)
                    {
                        MessageBox.Show("Батальон с такми названием уже существует!\nИзмените название и попробуйте еще раз!");
                        return;
                    }
                }
                Battalion battalion = new Battalion();
                battalion.Name     = newNameBattalion.Text;
                battalion.Load     = false;
                battalion.Officer  = Convert.ToInt32(newOfficer.Text.ToString());
                battalion.Serjant  = Convert.ToInt32(newSerjant.Text);
                battalion.Soldat   = Convert.ToInt32(newSoldat.Text);
                battalion.Civilian = Convert.ToInt32(newCivilan.Text);
                // Определяем ID выбранной бригады
                foreach (Brigade br in context.Brigades)
                {
                    if (br.Name == changeBrig4Batt.Text)
                    {
                        battalion.BrigadeId = br.BrigadeId;
                        break;
                    }
                }
                context.Battalions.Add(battalion);
                context.SaveChanges();
            }
            //// Обновление источника данных
            UpdateDataGridViewBattalions(chooseBrig1.Text);
            UpdatechangeBrig4Equip(changeBrig4Equip.Text);
            newNameBattalion.Text = ""; newOfficer.Text = "0"; newSerjant.Text = "0";
            newSoldat.Text        = "0"; newCivilan.Text = "0";
            UpdateDb update = new UpdateDb();

            MessageBox.Show("Батальон успешно добавлен");
        }
示例#15
0
        // Создание коллекции батальонов выбранных для погрузки
        public List <BuildnUnit> CreateCollectBatt()//List<string> nameOfBatt)
        {
            List <BuildnUnit>  collBatt4Load = new List <BuildnUnit>();
            MillitaryDbContext context       = new MillitaryDbContext();
            int ii = 0;

            foreach (string batt in nameOfBatt)
            {
                var foundBat = from dumb in context.Battalions
                               where dumb.Name == batt
                               select dumb;
                Battalion          battalion = foundBat.First();
                List <EquipInBatt> collEquip = new List <EquipInBatt>();
                //List<EquipInBatt> collEquipSpec = new List<EquipInBatt>();
                //List<EquipInBatt> collEquipUsual = new List<EquipInBatt>();
                int rgb = 1;
                foreach (EquipmentBattalion eq2bat in context.EquipmentBattalions)
                {
                    if (eq2bat.BattalionId == battalion.BattalionId)
                    {
                        //Задаем новый цвет
                        Color newColor = new Color();
                        newColor = DefineColor(rgb++);
                        EquipInBatt equip = new EquipInBatt(eq2bat.Equipments.Name, newColor, eq2bat.Equipments.Lenght,
                                                            eq2bat.Equipments.Mass, eq2bat.Count, eq2bat.Equipments.TypeEquip);
                        //Отделяем специальную технику от обычной
                        //if (eq2bat.Equipments.TypeEquip) collEquipUsual.Add(equip);
                        //else collEquipSpec.Add(equip);
                        collEquip.Add(equip);
                    }
                }
                BuildnUnit newUnit = new BuildnUnit(++ii, battalion.Name, battalion.Brigade.Name,
                                                    battalion.Officer, battalion.Serjant, battalion.Soldat, battalion.Civilian, collEquip); //collEquipSpec, collEquipUsual);
                collBatt4Load.Add(newUnit);
            }
            return(collBatt4Load);
        }
示例#16
0
        //Вывод информаии о батальоне
        private void battalionsDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int changeCell = battalionsDataGridView.CurrentCellAddress.X;

            if (changeCell == 0)
            {
                viewOficer.Text   = Convert.ToString(this.battalionsDataGridView.CurrentRow.Cells[2].Value);
                viewSerjant.Text  = Convert.ToString(this.battalionsDataGridView.CurrentRow.Cells[3].Value);
                viewSoldat.Text   = Convert.ToString(this.battalionsDataGridView.CurrentRow.Cells[4].Value);
                viewCivilian.Text = Convert.ToString(this.battalionsDataGridView.CurrentRow.Cells[5].Value);
                dataGridViewEquip.Rows.Clear();
                MillitaryDbContext context = new MillitaryDbContext();
                string             qwest   = battalionsDataGridView.CurrentRow.Cells[0].Value.ToString();
                var foundBat = from bat in context.Battalions
                               where bat.Name == qwest
                               select bat;
                Battalion battalion = foundBat.First();
                int       ii        = 0;
                foreach (EquipmentBattalion eq2bat in context.EquipmentBattalions)
                {
                    if (eq2bat.BattalionId == battalion.BattalionId)
                    {
                        dataGridViewEquip.Rows.Add();
                        dataGridViewEquip[0, ii].Value = eq2bat.Equipments.Name;
                        dataGridViewEquip[1, ii].Value = eq2bat.Count;
                        ii++;
                    }
                }



                //List<EquipmentBattalion> eqList = new List<EquipmentBattalion>();
                //eqList = context.EquipmentBattalions.Where(x => x.BattalionId == battalion.BattalionId).ToList();
                //dataGridViewEquip.DataSource = eqList.;
            }
        }
示例#17
0
        private void DrawRegiment(DrawingContext dc, int x, int y, int angle, Battalion bn)
        {
            int width     = bn.GetWidthInPaces();
            int halfwidth = width / 2;
            int height    = bn.GetDepthInPaces();

            dc.PushTransform(new RotateTransform(angle, x + halfwidth, y));

            // Create a rectangle and draw it in the DrawingContext.
            Rect rect = new Rect(new System.Windows.Point(x, y), new System.Windows.Size(width, height));

            dc.DrawRectangle(System.Windows.Media.Brushes.Blue, (System.Windows.Media.Pen)null, rect);

            //Rect rect2 = new Rect(new System.Windows.Point(x, y + height), new System.Windows.Size(width, 10));
            //dc.DrawRectangle(System.Windows.Media.Brushes.Black, (System.Windows.Media.Pen)null, rect2);

            /*
             * Rect rect3 = new Rect(new System.Windows.Point(x + (halfwidth - widgetsize) //150
             * , y - widgetsize), new System.Windows.Size(20, 10));
             * dc.DrawRectangle(System.Windows.Media.Brushes.Red, (System.Windows.Media.Pen)null, rect3);
             */

            dc.DrawText(


                new FormattedText(bn.ShortName,
                                  CultureInfo.GetCultureInfo("en-us"),
                                  FlowDirection.LeftToRight,
                                  new Typeface("Verdana"),
                                  12, System.Windows.Media.Brushes.Black),
                new System.Windows.Point(x, y + height));



            dc.Pop();
        }
    private IEnumerator DisplayTeamStat(bool fadeIn, Battalion target)
    {
        float min = 10.6f;

        if (fadeIn)
        {
            while (teamDisplayAtk != 0 || teamDisplayCommand != 0 || teamDisplayDef != 0 || teamDisplayMagic != 0)
            {
                yield return(null);
            }
            teamAtkBar.position     = new Vector3(min, teamAtkBar.position.y);
            teamDefBar.position     = new Vector3(min, teamDefBar.position.y);
            teamMagicBar.position   = new Vector3(min, teamMagicBar.position.y);
            teamCommandBar.position = new Vector3(min, teamCommandBar.position.y);
            float speed = 0.02f;
            float feed = 10f;
            float atkTotal, defTotal, magicTotal, commandTotal;
            atkTotal     = 0;
            defTotal     = 0;
            magicTotal   = 0;
            commandTotal = 0;
            for (int i = 0; i < 4; i++)
            {
                atkTotal   += target.soldiers[i].Attack;
                defTotal   += target.soldiers[i].Defense;
                magicTotal += target.soldiers[i].Magic;
            }
            atkTotal     += target.ComChar.Attack * 2;
            defTotal     += target.ComChar.Defense * 2;
            magicTotal   += target.ComChar.Magic * 2;
            commandTotal += target.ComChar.Attack + target.ComChar.Defense + target.ComChar.Magic + target.ComChar.HP;
            atkTotal     /= 6;
            defTotal     /= 6;
            magicTotal   /= 6;
            commandTotal /= 4;
            yield return(new WaitForSecondsRealtime(0.5f));

            while (teamDisplayAtk < atkTotal || teamDisplayCommand < commandTotal || teamDisplayDef < defTotal || teamDisplayMagic < magicTotal)
            {
                if (teamDisplayAtk < atkTotal)
                {
                    teamDisplayAtk     += Time.deltaTime * feed;
                    teamAtkBar.position = new Vector3(teamAtkBar.position.x - teamDisplayAtk * speed, teamAtkBar.position.y, teamAtkBar.position.z);
                }
                if (teamDisplayDef < defTotal)
                {
                    teamDisplayDef     += Time.deltaTime * feed;
                    teamDefBar.position = new Vector3(teamDefBar.position.x - teamDisplayDef * speed, teamDefBar.position.y, teamDefBar.position.z);
                }
                if (teamDisplayCommand < commandTotal)
                {
                    teamDisplayCommand     += Time.deltaTime * feed;
                    teamCommandBar.position = new Vector3(teamCommandBar.position.x - teamDisplayCommand * speed, teamCommandBar.position.y, teamCommandBar.position.z);
                }
                if (teamDisplayMagic < magicTotal)
                {
                    teamDisplayMagic     += Time.deltaTime * feed;
                    teamMagicBar.position = new Vector3(teamMagicBar.position.x - teamDisplayMagic * speed, teamMagicBar.position.y, teamMagicBar.position.z);
                }
                yield return(null);
            }
        }
        else
        {
            float speed = -0.02f;
            float feed  = 10f;

            while (teamDisplayAtk > 0 || teamDisplayCommand > 0 || teamDisplayDef > 0 || teamDisplayMagic > 0)
            {
                if (teamDisplayAtk > 0)
                {
                    teamDisplayAtk     -= Time.deltaTime * feed;
                    teamAtkBar.position = new Vector3(teamAtkBar.position.x - teamDisplayAtk * speed, teamAtkBar.position.y, teamAtkBar.position.z);
                }
                if (teamDisplayDef > 0)
                {
                    teamDisplayDef     -= Time.deltaTime * feed;
                    teamDefBar.position = new Vector3(teamDefBar.position.x - teamDisplayDef * speed, teamDefBar.position.y, teamDefBar.position.z);
                }
                if (teamDisplayCommand > 0)
                {
                    teamDisplayCommand     -= Time.deltaTime * feed;
                    teamCommandBar.position = new Vector3(teamCommandBar.position.x - teamDisplayCommand * speed, teamCommandBar.position.y, teamCommandBar.position.z);
                }
                if (teamDisplayMagic > 0)
                {
                    teamDisplayMagic     -= Time.deltaTime * feed;
                    teamMagicBar.position = new Vector3(teamMagicBar.position.x - teamDisplayMagic * speed, teamMagicBar.position.y, teamMagicBar.position.z);
                }
                yield return(null);
            }
            teamDisplayDef     = 0;
            teamDisplayMagic   = 0;
            teamDisplayCommand = 0;
            teamDisplayAtk     = 0;
        }
    }
示例#19
0
 public void load_unit_text(Battalion b, int ID)
 {
     texts[ID].text = build_unit_text(b, ID);
 }
示例#20
0
        public async Task <IActionResult> Copy(int id, CombatFormationViewModel combatForm)
        {
            Battalion battalion = new Battalion()
            {
                Name                  = combatForm.Name,
                Number                = combatForm.Number,
                TotalStrenght         = combatForm.TotalStrenght,
                AdditionalInformation = combatForm.AdditionalInformation,
                Commanders            = combatForm.Commanders,
                WeekId                = combatForm.WeekId,
                RegimentId            = combatForm.RegimentId,
                Image                 = combatForm.Image,
                Week                  = combatForm.Week,
                CoordinatesXY         = combatForm.Coordinates,
                CoordX                = combatForm.CoordX,
                CoordY                = combatForm.CoordY,
                Adress                = combatForm.Adress
            };

            if (ModelState.IsValid)
            {
                if (combatForm.OldWeekId != battalion.WeekId)
                {
                    battalion.RegimentId = null;
                    battalion.Commanders = null;
                }
                if (combatForm.Coordinates != null)
                {
                    string[] str = combatForm.Coordinates.Split(',', 2, StringSplitOptions.None);
                    battalion.CoordX = str[0];
                    battalion.CoordY = str[1];
                }
                if (combatForm.File != null)
                {
                    byte[] imageData = null;
                    // считываем переданный файл в массив байтов
                    using (var binaryReader = new BinaryReader(combatForm.File.OpenReadStream()))
                    {
                        imageData = binaryReader.ReadBytes((int)combatForm.File.Length);
                    }
                    // установка массива байтов
                    battalion.Image = imageData;
                    try
                    {
                        _context.Add(battalion);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!BattalionExists(battalion.BattalionId))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
                else if (combatForm.File == null)
                {
                    battalion.Image = combatForm.Image;
                    try
                    {
                        _context.Add(battalion);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!BattalionExists(battalion.BattalionId))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(battalion));
        }
示例#21
0
 public void CalculateUnits(Battalion Battalion)
 {
     Battalion.Deployed += Battalion.IsExhausted ? Battalion.Units : Battalion.Required;
 }