/// <summary> /// returns a "delta" list, containing lost troops when comparing the current and the "remaining" lists /// </summary> /// <param name="remainingTroops"></param> public TroopList GetLossesList(TroopList remainingTroops) { int troopIndexInAfter; int troopsOfCurTypeLost; TroopList resultingList = new TroopList(); for (int i = 0; i < Count; i++) { troopIndexInAfter = remainingTroops.IndexOfTroopInThisList(this[i].troopTypeID); if (troopIndexInAfter != -1) { troopsOfCurTypeLost = (remainingTroops[troopIndexInAfter].troopAmount - this[i].troopAmount) * -1; if (troopsOfCurTypeLost > 0) { resultingList.AddTroop(this[i].troopTypeID, troopsOfCurTypeLost); } } else { //all troops of that type have been lost, probably resultingList.AddTroop(this[i].troopTypeID, this[i].troopAmount); } } return(resultingList); }
/// <summary> /// returns a new troopList of the combination of both troopLists /// </summary> /// <param name="theOtherContainerTroops"></param> /// <returns></returns> public TroopList GetCombinedTroops(TroopList theOtherContainerTroops) { TroopList returnedList = new TroopList(); returnedList.AddRange(this); int testedTroopIndex = -1; TroopNumberPair checkedTNP; foreach (TroopNumberPair tnp in theOtherContainerTroops) { testedTroopIndex = IndexOfTroopInThisList(tnp.troopTypeID); if (testedTroopIndex >= 0) { checkedTNP = returnedList[testedTroopIndex]; checkedTNP.troopAmount += tnp.troopAmount; returnedList[testedTroopIndex] = checkedTNP; } else { returnedList.Add(tnp); } } return(returnedList); }
public override int GetCreditWithPosition(Troop source, out Point?position) { //position = 0; position = new Point(0, 0); TroopList hostileTroopsInView = source.GetHostileTroopsInView(); TroopList list2 = new TroopList(); foreach (Troop troop in hostileTroopsInView) { if ((troop.IsInArchitecture || !troop.DaysToReachPosition(source.Position, 1)) || (troop.Army.Kind.Type == MilitaryType.水军)) { list2.Add(troop); } } foreach (Troop troop in list2) { hostileTroopsInView.Remove(troop); } if (hostileTroopsInView.Count == 0) { return(0); } List <Point> orientations = new List <Point>(); int num = 0; foreach (Troop troop in hostileTroopsInView) { orientations.Add(troop.Position); num += troop.FightingForce; } int num2 = 0; int fightingForce = source.FightingForce; int num4 = source.TroopIntelligence + source.ChanceIncrementOfStratagem; if (num4 > 100) { num4 = 100; } num2 = (((GameObject.Square(num4) / 60) * num) / fightingForce) / 100; if (num2 > 0) { GameArea area = new GameArea(); foreach (Point point in source.GetStratagemArea(source.Position).Area) { if (!source.Scenario.PositionIsOnFire(point) && (source.Scenario.IsPositionEmpty(point) && source.Scenario.IsFireVaild(point, false, MilitaryType.步兵))) { area.Area.Add(point); } } if (area.Count > 0) { position = source.Scenario.GetClosestPosition(area, orientations); } else { num2 = 0; } } return(num2); }
public void SetupAndOpen(TroopList attackerForces, TroopList defenderForces) { attackerPanel.representedTroops = attackerForces; defenderPanel.representedTroops = defenderForces; gameObject.SetActive(true); }
public void OpenImportOps() { List <KeyValuePair <string, UnityAction> > importOptions = new List <KeyValuePair <string, UnityAction> >(); GameInterface GI = GameInterface.instance; importOptions.Add(new KeyValuePair <string, UnityAction>("JSON Array - Don't use if attackers and defenders share troop types", () => { GI.textInputPanel.SetPanelInfo("JSON Text to Import", "insert the JSON string here", "", "Import", () => { SerializedTroop[] readTroops = JsonHandlingUtils.JsonToSerializedTroopArray (GI.textInputPanel.theInputField.text); if (readTroops == null) { ModalPanel.Instance().OkBox("Json Import Failed", "Please check your JSON string, it must be something like [{'name':'troop', 'amount':5}]"); return; } TroopList attackersRemaining = new TroopList(), defendersRemaining = new TroopList(); foreach (SerializedTroop tnp in readTroops) { //Debug.Log("got this kvp: " + tnp.name + " : " + tnp.amount); TroopNumberPair convertedTNP = JsonHandlingUtils.SerializedTroopToTroopNumberPair(tnp); if (convertedTNP.troopAmount > 0) { if (battlePhase.battleData.defenderSideInfo.sideArmy.IndexOfTroopInThisList(convertedTNP.troopTypeID) != -1) { defendersRemaining.Add(convertedTNP); } else if (battlePhase.battleData.attackerSideInfo.sideArmy.IndexOfTroopInThisList(convertedTNP.troopTypeID) != -1) { attackersRemaining.Add(convertedTNP); } } } battlePhase.battleData.defenderSideInfo.SetPostBattleArmyData_RemainingArmy(defendersRemaining); battlePhase.battleData.attackerSideInfo.SetPostBattleArmyData_RemainingArmy(attackersRemaining); if (!battlePhase.battleData.BattleEndCheck()) { //we only need to update side info displays if the battle hasn't ended yet, //because the delegate would take care of it otherwise UpdateArmyDisplays(); } GI.textInputPanel.Close(); }); GI.textInputPanel.Open(); GI.exportOpsPanel.gameObject.SetActive(false); })); //when done preparing options, open the import ops panel GI.exportOpsPanel.Open("Remaining Armies: Import Options", importOptions); }
public Commander(int ownerFactionID, int zoneStartingLocation) { this.ID = GameController.GetUnusedCmderID(); this.ownerFaction = ownerFactionID; this.zoneIAmIn = zoneStartingLocation; troopsContained = new TroopList(); GameController.instance.curData.deployedCommanders.Add(this); }
public void ShowTooltipForZone(Zone targetZone, Vector3 basePos, bool showGarrInfo = true, bool refreshCanvasesBeforeGetSize = false) { baseTooltipPos = basePos; Faction ownerFaction = GameController.GetFactionByID(targetZone.ownerFaction); if (ownerFaction != null) { ChangeBackgroundAccordingToFactionRelations(ownerFaction); AddTooltipTitleEntry(targetZone.name, ownerFaction.color, 70); AddTooltipTitleEntry("(" + ownerFaction.name + ")", ownerFaction.color); AddTooltipTitleEntry("Garrison: " + targetZone.troopsContained.TotalTroopAmount + "/" + targetZone.MaxTroopsInGarrison, Color.white, 55); foreach (TroopNumberPair tnp in targetZone.troopsContained) { AddTooltipTroopEntry(GameController.GetTroopTypeByID(tnp.troopTypeID).name, tnp.troopAmount.ToString()); } List <Commander> cmdersInZone = GameController.GetCommandersOfFactionAndAlliesInZone(targetZone, ownerFaction); if (cmdersInZone.Count > 0) { TroopList totalArmy = GameController.GetCombinedTroopsInZoneFromFactionAndAllies(targetZone, ownerFaction); AddTooltipTitleEntry("Commanders: " + cmdersInZone.Count.ToString(), ownerFaction.color, 60); AddTooltipTitleEntry("Combined Army: " + totalArmy.TotalTroopAmount, Color.white, 50); foreach (TroopNumberPair tnp in totalArmy) { AddTooltipTroopEntry(GameController.GetTroopTypeByID(tnp.troopTypeID).name, tnp.troopAmount.ToString()); } } } else { backgroundImg.color = defaultColor; AddTooltipTitleEntry(targetZone.name, Color.white, 70); AddTooltipTitleEntry("(" + Rules.NO_FACTION_NAME + ")", Color.white); } AddTooltipInfoEntry(targetZone.multRecruitmentPoints.ToString("0%"), targetZone.multTrainingPoints.ToString("0%")); MercCaravan localCaravan = GameController.GetMercCaravanInZone(targetZone.ID); if (localCaravan != null) { AddTooltipInfoEntry("Merc Caravan Troop", GameController.GetTroopTypeByID(localCaravan.containedTroopType).name); } ContextualTooltipUpdate(refreshCanvasesBeforeGetSize); }
/// <summary> /// returns a "delta" list, containing lost troops according to the percentage of remaining troops provided /// </summary> /// <param name="remainingTroops"></param> public TroopList GetLossesListByPercentage(float remainingPercent) { TroopList resultingList = new TroopList(); float lossPercent = 1.0f - remainingPercent; for (int i = 0; i < Count; i++) { resultingList.AddTroop(this[i].troopTypeID, Mathf.RoundToInt(this[i].troopAmount * lossPercent)); } return(resultingList); }
/// <summary> /// returns a new list with subtracted troop amounts according to the lossesList /// </summary> /// <param name="lossesList">defines how many troops of each type should be removed</param> /// <returns></returns> public TroopList GetListWithAppliedLosses(TroopList lossesList) { TroopList returnedList = new TroopList(); returnedList.AddRange(this); for (int i = 0; i < lossesList.Count; i++) { returnedList.RemoveTroop(lossesList[i].troopTypeID, lossesList[i].troopAmount); } return(returnedList); }
public Zone(string name, Vector3 zonePos) { this.ID = GameController.GetUnusedZoneID(); this.name = name; this.ownerFaction = -1; this.coords = new Vector2(zonePos.x, zonePos.z); troopsContained = new TroopList(); linkedZones = new List <int>(); while (GameController.GetZoneByName(this.name) != null) { this.name = name + " copy"; } GameController.instance.curData.zones.Add(this); }
/// <summary> /// returns a troopNumberPair list with entries using the provided amounts /// </summary> /// <returns></returns> public TroopList BakeIntoArmy() { TroopList returnedList = new TroopList(); for (int i = 0; i < listContainer.childCount; i++) { Transform entry = listContainer.GetChild(i); BattleResolutionRemainingTroopListEntry entryScript = entry.GetComponent <BattleResolutionRemainingTroopListEntry>(); if (entryScript) { returnedList.Add(entryScript.BakeIntoNewPair()); } } return(returnedList); }
/// <summary> /// sets the displayed and stored army data, such as autocalc power and numbers. /// providing the zone separated from the rest of our containers will affect the description /// of forces only /// </summary> /// <param name="sideFactions"></param> /// <param name="ourZone"></param> /// <param name="containers"></param> /// <param name="postBattle"></param> public void SetupArmyData(List <Faction> sideFactions, Zone ourZone, List <TroopContainer> containers) { totalBattleLosses.Clear(); ourContainers.Clear(); ourContainers.AddRange(containers); sideArmy.Clear(); this.sideFactions = sideFactions; pointsAwardedToVictor = 0; int armyNumbers = 0; int armyCmders = 0; float armyPower = 0; if (ourZone != null) { if (!ourContainers.Contains(ourZone)) //if our zone wasn't added in ourContainers already... { ourContainers.Add(ourZone); armyCmders--; } } foreach (TroopContainer cont in ourContainers) { armyCmders++; armyNumbers += cont.troopsContained.TotalTroopAmount; armyPower += cont.troopsContained.TotalAutocalcPower; sideArmy = cont.troopsContained.GetCombinedTroops(sideArmy); } //clamp the side's forces according to the maxTroopsInvolvedInBattlePerTurn rule int maxTroops = GameController.CurGameData.rules.maxTroopsInvolvedInBattlePerTurn; sideArmy = GameController.GetRandomSampleArmyFromArmy(sideArmy, maxTroops); curArmyNumbers = Mathf.Min(armyNumbers, maxTroops); if (curArmyNumbers != armyNumbers) { armyPower = sideArmy.TotalAutocalcPower; } initialArmyPower = armyPower; curArmyPower = armyPower; }
/// <summary> /// variation used for getting info from all owned commanders in the zone where the selected cmder is in /// </summary> /// <param name="cmdersArmy"></param> /// <param name="cmdersCount"></param> /// <param name="sampleCmder"></param> public void SetContent(TroopList cmdersArmy, int cmdersCount, Commander sampleCmder) { //clear troop entries first ClearTroopEntries(); numTroopsTxt.text = "Troops: " + cmdersArmy.TotalTroopAmount + "/" + sampleCmder.MaxTroopsCommanded * cmdersCount; foreach (TroopNumberPair tnp in cmdersArmy) { AddTroopEntry(tnp); } //and the zone info Zone curZone = GameController.GetZoneByID(sampleCmder.zoneIAmIn); zoneInfoEntry.leftTxt.text = curZone.multRecruitmentPoints.ToString("0%"); zoneInfoEntry.rightTxt.text = curZone.multTrainingPoints.ToString("0%"); }
/// <summary> /// updates the army's "power" and "numbers" data according to the provided losses list. /// calls the "onSideDefeated" delegate if it's not null and the army's numbers got to 0 /// </summary> public void UpdatePostBattleArmy(TroopList lossesList) { totalBattleLosses = totalBattleLosses.GetCombinedTroops(lossesList); int armyNumbers; sideArmy = sideArmy.GetListWithAppliedLosses(lossesList); armyNumbers = sideArmy.TotalTroopAmount; curArmyNumbers = armyNumbers; curArmyPower = sideArmy.TotalAutocalcPower; if (armyNumbers <= 0) { if (onSideDefeated != null) { onSideDefeated(); onSideDefeated = null; } } }
public void ShowTooltipForCmder(Commander targetCmder, Vector3 basePos, bool refreshCanvasesBeforeGetSize = false) { baseTooltipPos = basePos; Faction ownerFaction = GameController.GetFactionByID(targetCmder.ownerFaction); ChangeBackgroundAccordingToFactionRelations(ownerFaction); AddTooltipTitleEntry("Commander", ownerFaction.color, 50); AddTooltipTitleEntry("(" + ownerFaction.name + ")", ownerFaction.color); AddTooltipTitleEntry("Troops: " + targetCmder.troopsContained.TotalTroopAmount + "/" + targetCmder.MaxTroopsCommanded, Color.white); foreach (TroopNumberPair tnp in targetCmder.troopsContained) { AddTooltipTroopEntry(GameController.GetTroopTypeByID(tnp.troopTypeID).name, tnp.troopAmount.ToString()); } List <Commander> cmdersInZone = GameController.GetCommandersOfFactionAndAlliesInZone( GameController.GetZoneByID(targetCmder.zoneIAmIn), ownerFaction); if (cmdersInZone.Count > 1) { TroopList totalCmderArmy = new TroopList(); foreach (Commander c in cmdersInZone) { totalCmderArmy = c.troopsContained.GetCombinedTroops(totalCmderArmy); } AddTooltipTitleEntry("Combined Cmd. Army: " + totalCmderArmy.TotalTroopAmount, Color.white, 50); foreach (TroopNumberPair tnp in totalCmderArmy) { AddTooltipTroopEntry(GameController.GetTroopTypeByID(tnp.troopTypeID).name, tnp.troopAmount.ToString()); } } ContextualTooltipUpdate(refreshCanvasesBeforeGetSize); }
private PathResult conflictionPathSearcher_OnCheckPosition(Point position, List <Point> middlePath, MilitaryKind kind) { TroopList list = new TroopList(); TroopList list2 = new TroopList(); foreach (Troop troop in this.troop.BelongedFaction.KnownTroops.Values) { if (!troop.IsFriendly(this.troop.BelongedFaction)) { switch (this.troop.HostileAction) { case HostileActionKind.EvadeEffect: if (troop.OffenceArea.HasPoint(position)) { list.Add(troop); } break; case HostileActionKind.EvadeView: if (troop.ViewArea.HasPoint(position)) { list.Add(troop); } break; } } else if (troop.Position == position) { list2.Add(troop); } } if ((list.Count > 0) || (list2.Count > 0)) { bool flag = false; foreach (Troop troop in list) { switch (this.troop.HostileAction) { case HostileActionKind.NotCare: Session.Current.Scenario.SetPenalizedMapDataByPosition(troop.Position, 0xdac); break; case HostileActionKind.Attack: Session.Current.Scenario.SetPenalizedMapDataByPosition(troop.Position, 0xdac); break; case HostileActionKind.EvadeEffect: Session.Current.Scenario.SetPenalizedMapDataByArea(troop.OffenceArea, 1); break; case HostileActionKind.EvadeView: Session.Current.Scenario.SetPenalizedMapDataByArea(troop.ViewArea, 1); break; } } /*foreach (Troop troop in list2) * { * switch (this.troop.FriendlyAction) * { * } * }*/ flag = this.ModifyFirstTierPath(this.troop.Position, this.troop.FirstTierDestination, middlePath, kind); foreach (Troop troop in list) { switch (this.troop.HostileAction) { case HostileActionKind.NotCare: Session.Current.Scenario.ClearPenalizedMapDataByPosition(troop.Position); break; case HostileActionKind.Attack: Session.Current.Scenario.ClearPenalizedMapDataByPosition(troop.Position); break; case HostileActionKind.EvadeEffect: Session.Current.Scenario.ClearPenalizedMapDataByArea(troop.OffenceArea); break; case HostileActionKind.EvadeView: Session.Current.Scenario.ClearPenalizedMapDataByArea(troop.ViewArea); break; } } /*foreach (Troop troop in list2) * { * switch (this.troop.FriendlyAction) * { * } * }*/ if (flag) { return(PathResult.Found); } return(PathResult.NotFound); } return(PathResult.Aborted); }
/// <summary> /// distributes losses among troop containers, returning a "losses" list /// </summary> /// <param name="remainingArmy"></param> public void SetPostBattleArmyData_RemainingArmy(TroopList remainingArmy) { UpdatePostBattleArmy(sideArmy.GetLossesList(remainingArmy)); }