void CheckCorrection() { for (int i = 0; i < Informations.Instance.cityNum; i++) { CityInfo cInfo = Informations.Instance.GetCityInfo(i); if (cInfo.generals.Count <= 10) { continue; } do { ArmyInfo ai = new ArmyInfo(); ai.king = cInfo.king; ai.state = (int)ArmyController.ArmyState.Garrison; if (pathfinding == null) { pathfinding = GameObject.FindWithTag("Pathfinding").GetComponent <MyPathfinding>(); } ai.pos = pathfinding.GetCityPos(i); Informations.Instance.armys.Add(ai); int count = cInfo.generals.Count; int min = count - 5; min = Mathf.Clamp(min, 10, count); for (int j = count - 1; j >= min; j--) { int g = cInfo.generals[j]; ai.generals.Add(g); cInfo.generals.RemoveAt(j); Informations.Instance.GetGeneralInfo(g).city = -1; if (cInfo.prefect == g) { cInfo.prefect = FindCommander(cInfo.generals, cInfo.king); } } ai.commander = FindCommander(ai.generals, ai.king); } while(cInfo.generals.Count > 10); } }
void SetArmy() { Vector3 pos = path.GetCityPos(cityIdx); GameObject go = (GameObject)Instantiate(armyPrefab, pos, transform.rotation); armyCtrl = go.GetComponent <ArmyController>(); ArmyInfo armyInfo = new ArmyInfo(); armyInfo.king = cInfo.king; armyInfo.cityFrom = cityIdx; armyInfo.cityTo = -1; armyInfo.money = moneyTook; armyInfo.armyCtrl = armyCtrl; armyCtrl.armyInfo = armyInfo; Informations.Instance.armys.Add(armyInfo); GameObject root = GameObject.Find("ArmiesRoot"); go.transform.parent = root.transform; armyCtrl.SetArmyKingFlag(); armyCtrl.Pause(); for (int i = cInfo.generals.Count - 1; i >= 0; i--) { if (generalsList[i].GetButtonState() == PushedButton.ButtonState.Pressed) { int gIdx = (int)generalsList[i].GetButtonData(); armyInfo.generals.Add(gIdx); cInfo.generals.Remove(gIdx); Informations.Instance.GetGeneralInfo(gIdx).city = -1; if (selectedCount == 1) { armyInfo.commander = gIdx; } } } if (cInfo.generals.Count == 1) { cInfo.prefect = cInfo.generals[0]; } else if (cInfo.generals.Count == 0) { Informations.Instance.GetKingInfo(cInfo.king).cities.Remove(cityIdx); cInfo.king = -1; flagsCtrl.SetFlag(cityIdx); } if (isSelectedPrefect) { armyInfo.commander = prefectBK; } else { if (state == 4) { armyInfo.commander = selectCommander.GetCommander(); } } if (takePrisonFlag) { takePrisonFlag = false; armyInfo.prisons.AddRange(cInfo.prisons); cInfo.prisons.Clear(); for (int i = 0; i < armyInfo.prisons.Count; i++) { Informations.Instance.GetGeneralInfo(armyInfo.prisons[i]).city = -1; } } selectTargetCity.SetArmy(armyInfo); }
void SetEscapeFromCity(int cIdx) { CityInfo cInfo = Informations.Instance.GetCityInfo(cIdx); do { GameObject go = (GameObject)Instantiate(armyPrefab, pathfinding.GetCityPos(cIdx), transform.rotation); ArmyController ac = go.GetComponent <ArmyController>(); ArmyInfo ai = new ArmyInfo(); ai.king = cInfo.king; ai.money = 0; ai.armyCtrl = ac; ac.armyInfo = ai; ac.SetArmyKingFlag(); Informations.Instance.armys.Add(ai); ai.armyCtrl.SetArmyKingFlag(); go.transform.parent = GameObject.Find("ArmiesRoot").transform; int count = cInfo.generals.Count; int min = count - 5; min = Mathf.Clamp(min, 0, count); for (int i = count - 1; i >= min; i--) { int g = cInfo.generals[i]; ai.generals.Add(g); cInfo.generals.RemoveAt(i); Informations.Instance.GetGeneralInfo(g).city = -1; } ai.commander = -1; ai.armyCtrl.FindArmyCommander(); int cityEscTo = -1; List <int> clist = MyPathfinding.GetCityNearbyIdx(cIdx); List <int> canGoList = new List <int>(); if (clist.Count == 1) { cityEscTo = clist[0]; } else { for (int i = 0; i < clist.Count; i++) { if (Informations.Instance.GetCityInfo(clist[i]).king == ai.king) { canGoList.Add(clist[i]); } } if (canGoList.Count > 0) { cityEscTo = canGoList[Random.Range(0, canGoList.Count)]; } if (cityEscTo == -1) { for (int i = 0; i < clist.Count; i++) { if (Informations.Instance.GetCityInfo(clist[i]).king == -1) { canGoList.Add(clist[i]); } } if (canGoList.Count > 0) { cityEscTo = canGoList[Random.Range(0, canGoList.Count)]; } } if (cityEscTo == -1) { cityEscTo = clist[Random.Range(0, clist.Count)]; } } ai.cityFrom = cIdx; ai.cityTo = cityEscTo; if (pathfinding == null) { pathfinding = GameObject.FindWithTag("Pathfinding").GetComponent <MyPathfinding>(); } ai.armyCtrl.SetRoute(pathfinding.GetRoute(ai.armyCtrl.transform.position, ai.cityTo)); ai.armyCtrl.SetArmyEscape(); } while (cInfo.generals.Count > 0); }