public bool Has(UnitPos pos) { if (Has(Neighbor.Top) && pos == Top) { return(true); } if (Has(Neighbor.Bottom) && pos == Bottom) { return(true); } if (Has(Neighbor.Left) && pos == Left) { return(true); } if (Has(Neighbor.Right) && pos == Right) { return(true); } if (Has(Neighbor.Front) && pos == Front) { return(true); } if (Has(Neighbor.Back) && pos == Back) { return(true); } return(false); }
private void OnMouseDown() { if (Player.menuOpen == 1) { if (NodeMenu.currentNode) { if (NodeMenu.currentNode.GetComponent <Node>().temple != null) { if (Player.human.GetComponent <Player>().upgrades.ContainsKey("Assimilate") && Player.human.GetComponent <Player>().upgrades["Assimilate"].currentLevel >= 2) { print("temple faction: " + NodeMenu.currentNode.GetComponent <Node>().temple.faction); Player.human.GetComponent <Player>().unitBlueprints.Clear(); GameObject.Find("/Unit Buying Menu/Unit Spaces").GetComponent <UnitShopManager>().MakeUnits(NodeMenu.currentNode.GetComponent <Node>().temple.faction, Player.human); GameObject.Find("/Unit Buying Menu/Unit Spaces").GetComponent <UnitShopManager>().AssignUnits(Player.human); print("Units getting updated"); } } //print("occupied = " + NodeMenu.currentNode.GetComponent<Node>().occupied); //if (Tools.GetChildNamed(gameObject, "Name Text").GetComponent<TextMesh>().text != "Temple") { currentUnitSpace = gameObject; currentUnitPos = new UnitPos(position, frontRow); unitBuyingSpaces.GetComponent <UnitShopManager>().EnterMenu(); Player.menuOpen = 2; } } }
public void BuyUnit(GameObject army) { //print("buying unit"); MapUnit unitToBuy = unit.DeepCopy(); if (NodeMenu.currentNode.GetComponent <Node>().temple != null && NodeMenu.currentNode.GetComponent <Node>().temple.name == TempleName.Armaments) { unitToBuy.moneyCost = (int)(unitToBuy.moneyCost * 0.6f); } for (int i = 0; i < 4; i++) { UnitPos unitPos = new UnitPos(i, true); if (army.GetComponent <Army>().IsSpotOpen(unitPos)) { army.GetComponent <Army>().BuyUnit(unitPos, unitToBuy); } } for (int i = 0; i < 4; i++) { UnitPos unitPos = new UnitPos(i, false); if (army.GetComponent <Army>().IsSpotOpen(unitPos)) { army.GetComponent <Army>().BuyUnit(unitPos, unitToBuy); } } LeaveMenu(); }
public void Init(Tool.ShipPart part) { UnitPos posInit = part.Cubes[0]; //X = new Vector2(posInit.x, posInit.x); Y = new Vector2(posInit.y, posInit.y); Z = new Vector2(posInit.z, posInit.z); foreach (UnitPos pos in part.Cubes) { LinkPosList.Add(new LinkPos(pos, ParamAttribut != null ? ParamAttribut.Life : int.MaxValue)); // update min and max X.x = Mathf.Min(X.x, pos.x); X.y = Mathf.Max(X.y, pos.x); Y.x = Mathf.Min(Y.x, pos.y); Y.y = Mathf.Max(Y.y, pos.y); Z.x = Mathf.Min(Z.x, pos.z); Z.y = Mathf.Max(Z.y, pos.z); } // init component // size of cube float size = part.Param.SquareSize; CompMeshGenerator.ParamCubeSize = ScriptableObject.CreateInstance(typeof(Tool.SCROneValue)) as Tool.SCROneValue; CompMeshGenerator.ParamCubeSize.Value = size; CompMaterial.ParamMaterial = ScriptableObject.CreateInstance(typeof(Tool.SCRMaterial)) as Tool.SCRMaterial; CompMaterial.ParamMaterial.Material = part.Param.Material; }
public BBBase(LinkPos init, float sizeCube, Transform owner) { Owner = owner; UnitPos center = init.Center; SizeCube = sizeCube; xMin = center.x - SizeCube; xMax = center.x + SizeCube; yMin = center.y - SizeCube; yMax = center.y + SizeCube; zMin = center.z - SizeCube; zMax = center.z + SizeCube; Vertex1 = new UnitPos(xMin, yMin, zMin); Vertex2 = new UnitPos(xMax, yMin, zMin); Vertex3 = new UnitPos(xMax, yMax, zMin); Vertex4 = new UnitPos(xMin, yMax, zMin); Vertex5 = new UnitPos(xMin, yMin, zMax); Vertex6 = new UnitPos(xMax, yMin, zMax); Vertex7 = new UnitPos(xMax, yMax, zMax); Vertex8 = new UnitPos(xMin, yMax, zMax); ComputeShpereBox(); }
public void BuyUnit(UnitPos unitPos, MapUnit unit) { //print("trying to buy unit"); MapUnit newUnit = unit.DeepCopy(); int unitCost = currentNode.GetComponent <Node>().GetUnitCost(Tools.UnitToIndex(newUnit)); if (unitCost <= owner.GetComponent <Player>().money&& newUnit.zealCost <= owner.GetComponent <Player>().zeal) { if (owner.GetComponent <Player>().upgrades.ContainsKey("Protect the Pure")) { float upgradeLevel = owner.GetComponent <Player>().upgrades["Protect the Pure"].currentLevel; newUnit.SetHealth((int)(newUnit.maxHealth - (0.1f * upgradeLevel * newUnit.maxHealth))); print("Health Lost: " + (int)(newUnit.maxHealth - (0.1f * upgradeLevel * newUnit.maxHealth))); print("Upgrade Level: " + upgradeLevel); //newUnit.currentHealth = newUnit.maxHealth; newUnit.maxShield += (int)upgradeLevel * 2; newUnit.currentShield = newUnit.maxShield; print("Maxshield: " + newUnit.maxShield); print("Currentshield: " + newUnit.currentShield); } owner.GetComponent <Player>().money -= unitCost; owner.GetComponent <Player>().zeal -= newUnit.zealCost; owner.GetComponent <Player>().factionTraits.NewUnit(newUnit); AddUnit(unitPos.position, unitPos.frontRow, newUnit); } //else print("not enough money"); }
public void Add(Neighbor where, UnitPos pos) { if (Has(where)) { Debug.LogError("Linkpos already know this neighbor"); } AddMask(where, pos); }
public void Best(LinkPos pos) { UnitPos center = pos.Center; if (center.x - SizeCube < xMin) { xMin = center.x - SizeCube; Vertex1.x = xMin; Vertex4.x = xMin; Vertex5.x = xMin; Vertex8.x = xMin; } else if (center.x + SizeCube > xMax) { xMax = center.x + SizeCube; Vertex2.x = xMax; Vertex3.x = xMax; Vertex6.x = xMax; Vertex7.x = xMax; } if (center.y - SizeCube < yMin) { yMin = center.y - SizeCube; Vertex1.y = yMin; Vertex2.y = yMin; Vertex5.y = yMin; Vertex6.y = yMin; } else if (center.y + SizeCube > yMax) { yMax = center.y + SizeCube; Vertex3.y = yMax; Vertex4.y = yMax; Vertex7.y = yMax; Vertex8.y = yMax; } if (center.z - SizeCube < zMin) { zMin = center.z - SizeCube; Vertex1.z = zMin; Vertex2.z = zMin; Vertex3.z = zMin; Vertex4.z = zMin; } else if (center.z + SizeCube > zMax) { zMax = center.z + SizeCube; Vertex5.z = zMax; Vertex6.z = zMax; Vertex7.z = zMax; Vertex8.z = zMax; } ComputeShpereBox(); }
public void BuyFakeUnit(UnitPos unitPos, MapUnit unit) { //unit.maxDamage = 0; unit.moneyCost = Mathf.RoundToInt(unit.moneyCost * 0.4f); unit.zealCost = 0; unit.name += " fake"; unit.portraitName += " fake"; unit.fake = true; BuyUnit(unitPos, unit); }
public MapUnit GetUnit(UnitPos pos) { if (pos.frontRow) { return(frontRow[pos.position]); } else { return(backRow[pos.position]); } }
public bool IsSpotOpen(UnitPos pos) { if (pos.frontRow && frontRow[pos.position] == null) { return(true); } else if (!pos.frontRow && backRow[pos.position] == null) { return(true); } return(false); }
public void BuyUnit(GameObject army, UnitPos unitPos) { //print("buying unit"); MapUnit unitToBuy = unit.DeepCopy(); if (NodeMenu.currentNode.GetComponent <Node>().temple != null && NodeMenu.currentNode.GetComponent <Node>().temple.name == TempleName.Armaments) { unitToBuy.moneyCost = (int)(unitToBuy.moneyCost * 0.6f); } army.GetComponent <Army>().BuyUnit(unitPos, unitToBuy); LeaveMenu(); }
public AllocateOption(OptionType replenishOption, float newUtility, int newCost, GameObject armyToReplenish) { node = null; army = armyToReplenish; type = replenishOption; utility = newUtility; cost = newCost; unitIndex = 0; oldUnitIndex = 0; unitPos = new UnitPos(); templeName = TempleName.None; altarName = AltarName.None; }
public AllocateOption(OptionType prophetOption, float newUtility, int newCost) { node = null; army = null; type = prophetOption; utility = newUtility; cost = newCost; unitIndex = 0; oldUnitIndex = 0; unitPos = new UnitPos(); templeName = TempleName.None; altarName = AltarName.None; }
public AllocateOption(OptionType upgradeOption, float newUtility, int newCost, GameObject newArmy, int mapunitIndex, int oldIndex) { node = null; army = newArmy; type = upgradeOption; utility = newUtility; cost = newCost; unitIndex = mapunitIndex; oldUnitIndex = oldIndex; unitPos = new UnitPos(); templeName = TempleName.None; altarName = AltarName.None; }
public AllocateOption(OptionType altarOption, float newUtility, int newCost, GameObject buildingNode, AltarName newname) { node = buildingNode; army = null; type = altarOption; utility = newUtility; cost = newCost; unitIndex = 0; oldUnitIndex = 0; unitPos = new UnitPos(); templeName = TempleName.None; altarName = newname; }
public AllocateOption(OptionType replaceOption, float newUtility, int newCost, GameObject newArmy, int mapunitIndex, UnitPos position) { node = null; army = newArmy; type = replaceOption; utility = newUtility; cost = newCost; unitIndex = mapunitIndex; unitPos = position; oldUnitIndex = 0; templeName = TempleName.None; altarName = AltarName.None; }
bool ShouldDissect(GameObject army, UnitPos position) { MapUnit unit = army.GetComponent <Army>().GetUnit(position); if (unit != null) { print("unit not null"); if (unit.faction != Player.human.GetComponent <Player>().faction) { print("unit of a different faction"); return(true); } } return(false); }
public void ReassembleEnemies(GameObject army) { List <MapUnit> deadUnits = army.GetComponent <Army>().defeatedEnemies; deadUnits.Sort(Tools.SortByPower); while (army.GetComponent <Army>().HasOpenPosition() && deadUnits.Count > 0) { MapUnit nextUnit = deadUnits[deadUnits.Count - 1]; deadUnits.Remove(nextUnit); //If nextUnit.name.Contains("Altar") UnitPos position = army.GetComponent <Army>().GetOpenPosition(); army.GetComponent <Army>().AddUnit(position.position, position.frontRow, nextUnit); } army.GetComponent <Army>().defeatedEnemies.Clear(); }
public int CompareTo(object other) { // A null value means that this object is greater. if (other == null) { return(1); } UnitPos otherUnitPos = other as UnitPos; if (otherUnitPos != null) { return(DistTo0() > otherUnitPos.DistTo0() ? 1 : DistTo0() == otherUnitPos.DistTo0() ? 0 : -1); } return(1); }
public virtual void SearchNeigbhor(UnitPos lfv, int remove, int idx, int delta) { if (idx < 0 || idx >= LinkPosList.Count) { return; } LinkPos link = LinkPosList.ElementAt(idx); if (link.Center == lfv) { link.Remove((LinkPos.Neighbor)remove); } else { SearchNeigbhor(lfv, remove, idx + delta, delta); } }
public override bool Equals(object obj) { if (obj == null) { return(false); } UnitPos o = obj as UnitPos; if (o == null) { return(false); } return(Mathf.Abs(x - o.x) < 0.05f && Mathf.Abs(y - o.y) < 0.05f && Mathf.Abs(z - o.z) < 0.05f); }
private void AddMask(Neighbor where, UnitPos pos) { switch (where) { case Neighbor.Top: Mask |= Face.Top; Top = pos; break; case Neighbor.Bottom: Mask |= Face.Bot; Bottom = pos; break; case Neighbor.Left: Mask |= Face.Left; Left = pos; break; case Neighbor.Right: Mask |= Face.Right; Right = pos; break; case Neighbor.Front: Mask |= Face.Front; Front = pos; break; case Neighbor.Back: Mask |= Face.Back; Back = pos; break; default: break; } }
public void Add(UnitPos pos) { Cubes.Add(pos); }
public LinkPos(UnitPos center) { Center = new UnitPos(center); }
public LinkPos(UnitPos center, int life) { Center = new UnitPos(center); Life = life; }
public void GenerateMesh() { _vertices.Clear(); _triangles.Clear(); if (ParamCubeSize == null) { return; } // we need to determine the outline of the form float size = ParamCubeSize.Value; foreach (LinkPos curr in LinkPosList) { Face mask = curr.Mask; UnitPos currPos = curr.Center; // read mask from linkPos if ((mask & Face.Top) == Face.None) { int deb = _vertices.Count; _vertices.Add(new Vector3(currPos.x, currPos.y + size, currPos.z)); _vertices.Add(new Vector3(currPos.x + size, currPos.y + size, currPos.z)); _vertices.Add(new Vector3(currPos.x + size, currPos.y + size, currPos.z + size)); _vertices.Add(new Vector3(currPos.x, currPos.y + size, currPos.z + size)); AddTriangles(deb); } if ((mask & Face.Bot) == Face.None) { int deb = _vertices.Count; _vertices.Add(new Vector3(currPos.x + size, currPos.y, currPos.z + size)); _vertices.Add(new Vector3(currPos.x + size, currPos.y, currPos.z)); _vertices.Add(new Vector3(currPos.x, currPos.y, currPos.z)); _vertices.Add(new Vector3(currPos.x, currPos.y, currPos.z + size)); AddTriangles(deb); } if ((mask & Face.Right) == Face.None) { int deb = _vertices.Count; _vertices.Add(new Vector3(currPos.x + size, currPos.y, currPos.z + size)); _vertices.Add(new Vector3(currPos.x + size, currPos.y + size, currPos.z + size)); _vertices.Add(new Vector3(currPos.x + size, currPos.y + size, currPos.z)); _vertices.Add(new Vector3(currPos.x + size, currPos.y, currPos.z)); AddTriangles(deb); } if ((mask & Face.Left) == Face.None) { int deb = _vertices.Count; _vertices.Add(new Vector3(currPos.x, currPos.y, currPos.z + size)); _vertices.Add(new Vector3(currPos.x, currPos.y, currPos.z)); _vertices.Add(new Vector3(currPos.x, currPos.y + size, currPos.z)); _vertices.Add(new Vector3(currPos.x, currPos.y + size, currPos.z + size)); AddTriangles(deb); } if ((mask & Face.Front) == Face.None) { int deb = _vertices.Count; _vertices.Add(new Vector3(currPos.x, currPos.y + size, currPos.z)); _vertices.Add(new Vector3(currPos.x, currPos.y, currPos.z)); _vertices.Add(new Vector3(currPos.x + size, currPos.y, currPos.z)); _vertices.Add(new Vector3(currPos.x + size, currPos.y + size, currPos.z)); AddTriangles(deb); } if ((mask & Face.Back) == Face.None) { int deb = _vertices.Count; _vertices.Add(new Vector3(currPos.x + size, currPos.y, currPos.z + size)); _vertices.Add(new Vector3(currPos.x, currPos.y, currPos.z + size)); _vertices.Add(new Vector3(currPos.x, currPos.y + size, currPos.z + size)); _vertices.Add(new Vector3(currPos.x + size, currPos.y + size, currPos.z + size)); AddTriangles(deb); } } CustomMesh.Clear(); CustomMesh.vertices = _vertices.ToArray(); CustomMesh.triangles = _triangles.ToArray(); CustomMesh.RecalculateNormals(); }
public void BuyUnit(GameObject army, UnitPos unitPos) { army.GetComponent <Army>().BuyFakeUnit(unitPos, unit.DeepCopy()); LeaveMenu(); }
public UnitPos(UnitPos aPos) { x = aPos.x; y = aPos.y; z = aPos.z; }