} // end method FindHexIDResource public void AddSettlement(string pHexPrefabName, string vertexName) { bool foundHex = false; bool validVertex = true; bool lowVertex = true; string outputString; string settlementName; Vector3 vertexPosition = new Vector3(-100f, 100f, 0f); Vector3 vertexOffset; SettDataScript tempSettlementData; settlementName = "Settlement" + (settList.Count + 1).ToString(); switch (vertexName) { case "TopVertex": vertexOffset = new Vector3(0f, 0.5546875f, 0f); lowVertex = true; break; case "URVertex": vertexOffset = new Vector3(0.5f, 0.3046875f, 0f); lowVertex = false; break; case "LRVertex": vertexOffset = new Vector3(0.5f, -0.3046875f, 0f); lowVertex = true; break; case "BottomVertex": vertexOffset = new Vector3(0f, -0.5546875f, 0f); lowVertex = false; break; case "LLVertex": vertexOffset = new Vector3(-0.5f, -0.3046875f, 0f); lowVertex = true; break; case "ULVertex": vertexOffset = new Vector3(-0.5f, 0.3046875f, 0f); lowVertex = false; break; default: validVertex = false; vertexOffset = new Vector3(-100f, 100f, 0f); outputString = "GameControlScript method AddSettlement was passed " + "the following invalid vertex name: " + vertexName; Debug.Log(outputString); break; } // end switch if (!validVertex) { HelperScript.enableSettlements = true; return; } foreach (HexDataScript hexData in hexList) { if (!foundHex && hexData.hexDataName == pHexPrefabName) { Vector3 newPosition = hexData.hexDataPosition + vertexOffset; if (!SettPositionEmpty(newPosition)) { HelperScript.enableSettlements = true; return; } else if (!CheckAdjacentRoad(newPosition, lowVertex)) { HelperScript.enableSettlements = true; return; } else { GameObject newSettlement = (GameObject)Instantiate(settPrefab, newPosition, Quaternion.Euler(-90, 0, 0)); newSettlement.name = settlementName; newSettlement.GetComponent <SettPrefabData>().SetSettName(newSettlement.name); newSettlement.GetComponent <SettPrefabData>().SetSettNumber(settList.Count + 1); newSettlement.GetComponent <SettPrefabData>().SetSettColor(playerList[0].playerColor); vertexPosition = newSettlement.transform.position; foundHex = true; } } } tempSettlementData = new SettDataScript(); tempSettlementData.settDataName = settlementName; tempSettlementData.settDataNumber = settList.Count + 1; tempSettlementData.settDataColor = playerList[0].playerColor; tempSettlementData.settDataPosition = vertexPosition; tempSettlementData.settDataPlayer = playerList[0].playerName; tempSettlementData.settHexNeighbors = CalcHexNeighbors(vertexPosition, lowVertex); settList.Add(tempSettlementData); tempSettlementData.LogSettlementData(); HelperScript.enableSettlements = false; // turn off settlement adding } // end method AddSettlement
public void AddSettlement(string pHexPrefabName, string vertexName) { bool foundHex = false; bool validVertex = true; bool lowVertex = true; string outputString; string settlementName; Vector3 vertexPosition = new Vector3(-100f, 100f, 0f); Vector3 vertexOffset; SettDataScript tempSettlementData; settlementName = "Settlement" + (settList.Count + 1).ToString(); switch (vertexName) { case "TopVertex": vertexOffset = new Vector3(0f, 0.5546875f, 0f); lowVertex = true; break; case "URVertex": vertexOffset = new Vector3(0.5f, 0.3046875f, 0f); lowVertex = false; break; case "LRVertex": vertexOffset = new Vector3(0.5f, -0.3046875f, 0f); lowVertex = true; break; case "BottomVertex": vertexOffset = new Vector3(0f, -0.5546875f, 0f); lowVertex = false; break; case "LLVertex": vertexOffset = new Vector3(-0.5f, -0.3046875f, 0f); lowVertex = true; break; case "ULVertex": vertexOffset = new Vector3(-0.5f, 0.3046875f, 0f); lowVertex = false; break; default: validVertex = false; vertexOffset = new Vector3(-100f, 100f, 0f); outputString = "GameControlScript method AddSettlement was passed " + "the following invalid vertex name: " + vertexName; Debug.Log(outputString); break; } // end switch if (!validVertex) { HelperScript.enableSettlements = true; return; } foreach (HexDataScript hexData in hexList) { if (!foundHex && hexData.hexDataName == pHexPrefabName) { Vector3 newPosition = hexData.hexDataPosition + vertexOffset; if (!SettPositionEmpty(newPosition)) { HelperScript.enableSettlements = true; return; } else if (!CheckAdjacentRoad(newPosition, lowVertex)) { HelperScript.enableSettlements = true; return; } else { GameObject newSettlement = (GameObject)Instantiate(settPrefab, newPosition, Quaternion.Euler(-90, 0, 0)); newSettlement.name = settlementName; newSettlement.GetComponent<SettPrefabData>().SetSettName(newSettlement.name); newSettlement.GetComponent<SettPrefabData>().SetSettNumber(settList.Count + 1); newSettlement.GetComponent<SettPrefabData>().SetSettColor(playerList[0].playerColor); vertexPosition = newSettlement.transform.position; foundHex = true; } } } tempSettlementData = new SettDataScript(); tempSettlementData.settDataName = settlementName; tempSettlementData.settDataNumber = settList.Count + 1; tempSettlementData.settDataColor = playerList[0].playerColor; tempSettlementData.settDataPosition = vertexPosition; tempSettlementData.settDataPlayer = playerList[0].playerName; tempSettlementData.settHexNeighbors = CalcHexNeighbors(vertexPosition, lowVertex); settList.Add(tempSettlementData); tempSettlementData.LogSettlementData(); HelperScript.enableSettlements = false; // turn off settlement adding }