public Person GetNewLiege(int dynasty) { return(dg.GetUnlandedMember(dynasty)); }
void StartGame() { currentState = GameStates.PLAYING; ResetCameraPos(); int CASTLES_ACROSS = 5; int CASTLES_DOWN = 4; dg = new DynastyGen(BannerSprites.GetUpperBound(0)+1); ai_dynasties = dg.GenerateIntertwinedDynasties(3); player_dynasty = dg.GenerateIntertwinedDynasties(1)[0]; string dynDebug = ""; foreach (KeyValuePair<int, List<Person>> dynPair in dg.dynastiesGenerated) { foreach(Person p in dynPair.Value) { dynDebug += p.PrintRelationships() + "\n"; } } Debug.Log(dynDebug); for(int x = 0; x < CASTLES_ACROSS; x++) { for(int y = 0; y < CASTLES_DOWN; y++) { const float PIXEL_SIZE = 1f/16f; Vector2 uc = Random.insideUnitCircle*0.2f; Vector3 pos = new Vector3(x - (float)(CASTLES_ACROSS-1)/2f + uc.x, y - (float)(CASTLES_DOWN-1)/2f + uc.y, 0); pos.x = pos.x * 1.6f - 0.15f; pos.y *= 1.4f; pos.x -= pos.x%PIXEL_SIZE; pos.y -= pos.y%PIXEL_SIZE; GameObject gOb = (GameObject)Instantiate(Resources.Load("Prefabs/Castle_prefab"), pos, Quaternion.identity); gOb.name = "Castle ( " + x + ", " + y + ")"; Castle newCastle= gOb.GetComponent<Castle>(); newCastle.controller = this; if(x == CASTLES_ACROSS -1 && y == CASTLES_DOWN -1) { //Player castle Person p = dg.GetUnlandedMember(player_dynasty); Debug.Assert(p != null); p.holding = newCastle; newCastle.liege = p; } else { int dynasty = Random.Range(0, ai_dynasties.GetUpperBound(0)+1); int count = 0; Person p = null; while(null == p && count <= ai_dynasties.GetUpperBound(0)) { int dynIndex = (dynasty + count) % (ai_dynasties.GetUpperBound(0)+1); p = dg.GetUnlandedMember(ai_dynasties[dynIndex]); if(null != p) { newCastle.max_troops = Random.Range(7 - p.GetRank(), 18 - 2*p.GetRank()); newCastle.troops = newCastle.max_troops; newCastle.liege = p; p.holding = newCastle; Debug.Log("Adding castle(" + x + ", " + y + ") to person " + p.GetName()); } else { Debug.Log("Dynasty " + dynIndex + " has ran out of unlanded members."); } count++; } if(null == p) Destroy(gOb); } } } }
void StartGame() { currentState = GameStates.PLAYING; ResetCameraPos(); int CASTLES_ACROSS = 5; int CASTLES_DOWN = 4; dg = new DynastyGen(BannerSprites.GetUpperBound(0) + 1); ai_dynasties = dg.GenerateIntertwinedDynasties(3); player_dynasty = dg.GenerateIntertwinedDynasties(1)[0]; string dynDebug = ""; foreach (KeyValuePair <int, List <Person> > dynPair in dg.dynastiesGenerated) { foreach (Person p in dynPair.Value) { dynDebug += p.PrintRelationships() + "\n"; } } Debug.Log(dynDebug); for (int x = 0; x < CASTLES_ACROSS; x++) { for (int y = 0; y < CASTLES_DOWN; y++) { const float PIXEL_SIZE = 1f / 16f; Vector2 uc = Random.insideUnitCircle * 0.2f; Vector3 pos = new Vector3(x - (float)(CASTLES_ACROSS - 1) / 2f + uc.x, y - (float)(CASTLES_DOWN - 1) / 2f + uc.y, 0); pos.x = pos.x * 1.6f - 0.15f; pos.y *= 1.4f; pos.x -= pos.x % PIXEL_SIZE; pos.y -= pos.y % PIXEL_SIZE; GameObject gOb = (GameObject)Instantiate(Resources.Load("Prefabs/Castle_prefab"), pos, Quaternion.identity); gOb.name = "Castle ( " + x + ", " + y + ")"; Castle newCastle = gOb.GetComponent <Castle>(); newCastle.controller = this; if (x == CASTLES_ACROSS - 1 && y == CASTLES_DOWN - 1) { //Player castle Person p = dg.GetUnlandedMember(player_dynasty); Debug.Assert(p != null); p.holding = newCastle; newCastle.liege = p; } else { int dynasty = Random.Range(0, ai_dynasties.GetUpperBound(0) + 1); int count = 0; Person p = null; while (null == p && count <= ai_dynasties.GetUpperBound(0)) { int dynIndex = (dynasty + count) % (ai_dynasties.GetUpperBound(0) + 1); p = dg.GetUnlandedMember(ai_dynasties[dynIndex]); if (null != p) { newCastle.max_troops = Random.Range(7 - p.GetRank(), 18 - 2 * p.GetRank()); newCastle.troops = newCastle.max_troops; newCastle.liege = p; p.holding = newCastle; Debug.Log("Adding castle(" + x + ", " + y + ") to person " + p.GetName()); } else { Debug.Log("Dynasty " + dynIndex + " has ran out of unlanded members."); } count++; } if (null == p) { Destroy(gOb); } } } } }