//Returns true if we won, false if we didn't. public bool Attack(Castle target) { if (null == target.liege) { return(true); } controller.DrawAttack(this.transform.position, target.transform.position, new Color(.75f, 0f, 0f)); float my_strength = Strength(); float target_strength = target.Strength(); bool won = my_strength > target_strength; if (won) { target.liege.Kill(); target.troops = target.max_troops; this.troops -= (int)(target_strength / Morale()); target.liege = controller.GetNewLiege(liege.GetDynasty()); if (null != target.liege) { target.liege.holding = target; } } else if (0 == target_strength) { //everybody dies from supreme miserableness. target.liege.Kill(); this.liege.Kill(); target.liege = null; this.liege = null; } else { this.liege.Kill(); this.liege = null; this.troops = 0; target.troops -= (int)(my_strength / target.Morale()); } return(won); }
private void DetectEndCondition() { int player_lieges = 0; int ai_lieges = 0; GameObject[] castles; castles = GameObject.FindGameObjectsWithTag("Castle"); foreach (GameObject go in castles) { Castle c = go.GetComponent <Castle>(); if (null != c.liege && c.liege.IsAlive()) { if (c.liege.GetDynasty() == player_dynasty) { player_lieges++; } else { ai_lieges++; } } } if (0 == player_lieges) { //Defeat! Debug.Log("Defeat!"); currentState = GameStates.DEFEAT; } else if (0 == ai_lieges) { //Victory! Debug.Log("Victory!"); currentState = GameStates.VICTORY; } }
public bool CastleIsSelected(Castle c) { return(c == selectedCastle); }
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); } } } } }