public void Respawn() { planet = GameObject.FindGameObjectWithTag("Planet"); ship = planet.GetComponent <Teams>().ship; if (partOfPlanet.GetNeighbors()[0].teamIndex == -1) { partOfPlanetForSpawn = partOfPlanet.GetNeighbors()[0]; } else { if (partOfPlanet.GetNeighbors()[1].teamIndex == -1) { partOfPlanetForSpawn = partOfPlanet.GetNeighbors()[1]; } else { partOfPlanetForSpawn = partOfPlanet.GetNeighbors()[2]; } } ship = Instantiate(ship, partOfPlanetForSpawn.GetPart().transform.position, Quaternion.identity); carrier = ship.GetComponent <Ship>(); carrier.teamIndex = teamIndex; ship.GetComponent <Ship>().Spawn(partOfPlanetForSpawn, this); planet.GetComponent <Teams>().teams[teamIndex].carriers.Add(carrier); carrier.rngMoveCooldown = Random.Range(1, 20); }
public void RemovePartOfPlanet(PartOfPlanet partOfPlanet) { if (partsOfPlanet.Contains(partOfPlanet)) { partsOfPlanet.Remove(partOfPlanet); } }
private void Update() { currentCooldown += Time.deltaTime; rngMoveCooldown -= Time.deltaTime; if (GetComponent <Move>().target == Vector3.zero && toMove.Count != 0) { PartOfPlanet nextPartOfPlanet = toMove[toMove.Count - 1]; toMove.RemoveAt(toMove.Count - 1); GetComponent <Move>().SetDirection(nextPartOfPlanet.GetPart().transform.position); currentPart = nextPartOfPlanet; } if (currentCooldown < cooldown) { airplaneOwn.SetActive(false); } else { airplaneOwn.SetActive(true); } if (teamIndex != 0 && rngMoveCooldown < 0) { MoveToTarget(planet.GetComponent <Teams>().Mix(planet.GetComponent <Teams>().water) [Random.Range(0, planet.GetComponent <Teams>().water.Count)].GetPart()); rngMoveCooldown = Random.Range(1, 20); } }
public void SetPartsOfPlanet(PartOfPlanet startPart, List <PartOfPlanet> mainland, int partCount, int teamIndex) { mainland.Remove(startPart); partsOfPlanet.Add(startPart); startPart.teamIndex = teamIndex; startPoint = startPart.GetPart().transform.position; Dictionary <float, PartOfPlanet> distanceAndParts = new Dictionary <float, PartOfPlanet>(); float[] parts = new float[mainland.Count]; for (int t = 0; t < mainland.Count; t++) { float distance = MyMath.sqrDistanceFromPointToPoint(startPart.GetPart().transform.position, mainland[t].GetPart().transform.position); if (distanceAndParts.ContainsKey(distance)) { distance = distance + 0.00101f; } parts[t] = distance; distanceAndParts.Add(distance, mainland[t]); } Array.Sort(parts); for (int t = 0; t < partCount; t++) { partsOfPlanet.Add(distanceAndParts[parts[t]]); distanceAndParts[parts[t]].teamIndex = teamIndex; mainland.Remove(distanceAndParts[parts[t]]); } }
public void MoveToTarget(GameObject target) { toMove.Clear(); PartOfPlanet partOfPlanetOfTarget = new PartOfPlanet(); GameObject planet = GameObject.FindGameObjectWithTag("Planet"); List <PartOfPlanet> water = planet.GetComponent <Teams>().water; Dictionary <PartOfPlanet, PartOfPlanet> roads = new Dictionary <PartOfPlanet, PartOfPlanet>(); List <PartOfPlanet> passed = new List <PartOfPlanet>(); Queue <PartOfPlanet> qp = new Queue <PartOfPlanet>(); qp.Enqueue(currentPart); bool alreadyFind = false; PartOfPlanet currentPartAtQP = qp.Peek(); passed.Add(currentPartAtQP); while (qp.Count > 0) { currentPartAtQP = qp.Dequeue(); for (int t = 0; t < 3; t++) { if (currentPartAtQP.GetNeighbors()[t].GetPart() == target) { alreadyFind = true; partOfPlanetOfTarget = currentPartAtQP.GetNeighbors()[t]; roads.Add(currentPartAtQP.GetNeighbors()[t], currentPartAtQP); break; } else { if (currentPartAtQP.GetNeighbors()[t].teamIndex == -1 && passed.IndexOf(currentPartAtQP.GetNeighbors()[t]) == -1) { qp.Enqueue(currentPartAtQP.GetNeighbors()[t]); roads.Add(currentPartAtQP.GetNeighbors()[t], currentPartAtQP); passed.Add(currentPartAtQP.GetNeighbors()[t]); } } } if (alreadyFind) { break; } } if (alreadyFind) { while (true) { if (roads.ContainsKey(partOfPlanetOfTarget) && roads[partOfPlanetOfTarget] != null) { toMove.Add(roads[partOfPlanetOfTarget]); partOfPlanetOfTarget = roads[partOfPlanetOfTarget]; } else { break; } } } }
public void Attack(PartOfPlanet partOfPlanet) { if (cooldown < currentCooldown) { if (MyMath.sqrDistanceFromPointToPoint(partOfPlanet.GetPart().transform.position, transform.position) < Range * Range) { currentCooldown = 0; GameObject newAirplane = Instantiate(airplane, transform.position, Quaternion.identity); newAirplane.GetComponent <Airplain>().partOfPlanet = partOfPlanet; newAirplane.GetComponent <Airplain>().teamIndex = teamIndex; newAirplane.GetComponent <Move>().SetDirection(partOfPlanet.GetPart().gameObject.transform.position); } } }
void Awake() { planet = gameObject; for (int t = 0; t < planet.transform.childCount; t++) { PartOfPlanet partOfPlanet = new PartOfPlanet(); planet.transform.GetChild(t).gameObject.AddComponent <MeshCollider>(); partOfPlanet.SetPart(planet.transform.GetChild(t).gameObject); partsOfPlanet.Add(partOfPlanet); } for (int t = 0; t < partsOfPlanet.Count; t++) { partsOfPlanet[t].FindANeighbors(partsOfPlanet); } }
public override void Create(PartOfPlanet partOfPlanet, int teamIndex) { GameObject planet = GameObject.FindGameObjectWithTag("Planet"); if (planet.GetComponent <Teams>().teams[partOfPlanet.teamIndex].money >= 50000) { planet.GetComponent <Teams>().teams[partOfPlanet.teamIndex].money -= 50000; aeroportFull = planet.GetComponent <Teams>().aeroPortFull; GameObject created = Instantiate(aeroportFull, partOfPlanet.GetPart().transform.position, Quaternion.identity); planet.GetComponent <Teams>().teams[partOfPlanet.teamIndex].buildings.Add(created.GetComponent <Building>()); partOfPlanet.full = true; partOfPlanet.building = created.GetComponent <Building>(); created.GetComponent <Building>().partOfPlanet = partOfPlanet; created.GetComponent <Building>().teamIndex = teamIndex; } }
public void TakeDamage(int damage, PartOfPlanet partOfPlanet, int aggressorTeamIndex) { int countryId = countries.IndexOf(partOfPlanet.country); if (countries[countryId].population < damage) { population -= countries[countryId].population; } else { population -= damage; } countries[countryId].population -= damage; countries[countryId].ChallengersUpdate(damage, aggressorTeamIndex); if (countries[countryId].population <= 0) { countries[countryId].LossCountry(); } }
public void UpdateCountriesDFS(List <PartOfPlanet> partsOfPlanetPast, Country newCountry, PartOfPlanet current) { newCountry.parts.Add(current); current.country = newCountry; partsOfPlanetPast.Add(current); for (int t = 0; t < current.GetNeighbors().Count; t++) { if (partsOfPlanetPast.IndexOf(current.GetNeighbors()[t]) == -1 && partsOfPlanet.IndexOf(current.GetNeighbors()[t]) != -1) { UpdateCountriesDFS(partsOfPlanetPast, newCountry, current.GetNeighbors()[t]); } } }
public void Spawn(PartOfPlanet partOfPlanet, Port myPort) { currentPart = partOfPlanet; transform.position = currentPart.GetPart().transform.position; port = myPort; }
public abstract void Attack(PartOfPlanet partOfPlanet);
public override void Attack(PartOfPlanet partOfPlanet) { }
public void AddPartOfPlanet(PartOfPlanet newPartOfPlanet) { partsOfPlanet.Add(newPartOfPlanet); }
void Update() { if (!gameEnd) { if (planet.GetComponent <Teams>().teams[0].countries.Count <= 0) { youSuck.SetActive(true); gameEnd = true; } bool endTest = true; for (int t = 0; t < planet.GetComponent <Teams>().teams.Length; t++) { if (planet.GetComponent <Teams>().teams[t].countries.Count > 0) { endTest = false; break; } } if (endTest) { perfect.SetActive(true); gameEnd = true; } } else { if (timer > 0) { timer -= Time.deltaTime; } } if (timer <= 0) { perfect.SetActive(false); youSuck.SetActive(false); } money.text = "Money: " + planet.GetComponent <Teams>().teams[teamIndex].money; selectedCountryPopulation.text = "Selected Country Population: "; if (countrySelect) { RaycastHit hit; Ray ray = cam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, Mathf.Infinity, layer)) { GameObject target = hit.transform.gameObject; PartOfPlanet targetPartOfPlanet = planet.GetComponent <PlanetFormer>().FindPartsOfPlanet(target); if (targetPartOfPlanet != null && targetPartOfPlanet.teamIndex >= 0) { if (currentSelectedObject != null) { selectedCountryPopulation.text = "Selected Country Population: " + (int)currentSelectedObject.population; } if (currentSelectedObject != null && currentSelectedObject.parts.Contains(targetPartOfPlanet)) { } else { if (selectedCountry != null) { for (int t = 0; t < selectedCountry.Count; t++) { selectedCountry[t].GetPart().GetComponent <MeshRenderer>().sharedMaterial = planet.GetComponent <Teams>().teams[selectedCountry[t].teamIndex].material; } } currentSelectedObject = targetPartOfPlanet.country; selectedCountry = currentSelectedObject.parts; currentSelectedMaterial = target.GetComponent <MeshRenderer>().sharedMaterial; Vector4 newColor = new Vector4(0, 0, 0, 1); newColor.x = currentSelectedMaterial.color.r + countrySelectColorShift; newColor.y = currentSelectedMaterial.color.g + countrySelectColorShift; newColor.z = currentSelectedMaterial.color.b + countrySelectColorShift; selectedMaterial.SetColor("_BaseColor", newColor); selectedMaterial.SetColor("_Color", newColor); for (int t = 0; t < selectedCountry.Count; t++) { selectedCountry[t].GetPart().GetComponent <MeshRenderer>().sharedMaterial = selectedMaterial; } } } else { currentSelectedObject = null; if (selectedCountry != null) { for (int t = 0; t < selectedCountry.Count; t++) { selectedCountry[t].GetPart().GetComponent <MeshRenderer>().sharedMaterial = planet.GetComponent <Teams>().teams[selectedCountry[t].teamIndex].material; } } } } } if (!Menu.GetComponent <Menu>().activ&& selectedUnit != null) { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; Ray ray = cam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { GameObject target = hit.transform.gameObject; if (target.GetComponentInParent <Teams>() != null) { selectedUnit = null; Destroy(currentWheel); } } } } if (!Menu.GetComponent <Menu>().activ) { if (Input.GetMouseButtonDown(1) && selectedUnit == null) { RaycastHit hit; Ray ray = cam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, Mathf.Infinity, layer)) { GameObject target = hit.transform.gameObject; PartOfPlanet targetPartOfPlanet = planet.GetComponent <PlanetFormer>().FindPartsOfPlanet(target); if (targetPartOfPlanet.teamIndex == 0 && !targetPartOfPlanet.full) { GameObject newWheel = Instantiate(Wheel, targetPartOfPlanet.GetPart().transform.position, Quaternion.identity); if (currentWheel != null) { Destroy(currentWheel); } selectedUnit = null; currentWheel = newWheel; wheelPartOfPlanet = targetPartOfPlanet; } } } } if (!Menu.GetComponent <Menu>().activ&& selectedUnit != null && selectedUnit.GetComponent <Ship>() != null && selectedUnit.GetComponent <Ship>().teamIndex == 0) { if (Input.GetMouseButtonDown(1)) { RaycastHit hit; Ray ray = cam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, Mathf.Infinity, layer)) { GameObject target = hit.transform.gameObject; PartOfPlanet targetPartOfPlanet = planet.GetComponent <PlanetFormer>().FindPartsOfPlanet(target); bool itsAShip = false; if (Physics.Raycast(ray, out hit, Mathf.Infinity) && hit.transform.gameObject.GetComponent <Ship>() != null && hit.transform.gameObject.GetComponent <Ship>().teamIndex == teamIndex) { itsAShip = true; } if (target.GetComponentInParent <Teams>() != null && (targetPartOfPlanet.teamIndex != -1 || itsAShip)) { selectedUnit.GetComponent <Ship>().Attack(targetPartOfPlanet); } } } } if (!Menu.GetComponent <Menu>().activ&& selectedUnit != null && selectedUnit.GetComponent <Ship>() != null && selectedUnit.GetComponent <Ship>().teamIndex == 0) { if (Input.GetMouseButtonDown(2)) { RaycastHit hit; Ray ray = cam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, Mathf.Infinity, layer)) { GameObject target = hit.transform.gameObject; PartOfPlanet targetPartOfPlanet = planet.GetComponent <PlanetFormer>().FindPartsOfPlanet(target); if (target.GetComponentInParent <Teams>() != null) { selectedUnit.GetComponent <Ship>().Attack(targetPartOfPlanet); } } } } if (!Menu.GetComponent <Menu>().activ&& selectedUnit != null && selectedUnit.GetComponent <NukeSetap>() != null && selectedUnit.GetComponent <NukeSetap>().teamIndex == 0) { if (Input.GetMouseButtonDown(1)) { RaycastHit hit; Ray ray = cam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, Mathf.Infinity, layer)) { GameObject target = hit.transform.gameObject; if (target.GetComponentInParent <Teams>() != null) { PartOfPlanet targetPartOfPlanet = planet.GetComponent <PlanetFormer>().FindPartsOfPlanet(target); selectedUnit.GetComponent <NukeSetap>().Attack(targetPartOfPlanet); } } } } if (!Menu.GetComponent <Menu>().activ&& selectedUnit != null && selectedUnit.GetComponent <Aeroport>() != null && selectedUnit.GetComponent <Aeroport>().teamIndex == 0) { if (Input.GetMouseButtonDown(1)) { RaycastHit hit; Ray ray = cam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, Mathf.Infinity, layer)) { GameObject target = hit.transform.gameObject; if (target.GetComponentInParent <Teams>() != null) { PartOfPlanet targetPartOfPlanet = planet.GetComponent <PlanetFormer>().FindPartsOfPlanet(target); selectedUnit.GetComponent <Aeroport>().Attack(targetPartOfPlanet); } } } } if (!Menu.GetComponent <Menu>().activ&& currentWheel != null) { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; Ray ray = cam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { GameObject target = hit.transform.gameObject; if (target.GetComponent <wheel>() != null && wheelPartOfPlanet != null) { Destroy(currentWheel); target.GetComponent <wheel>().Create(wheelPartOfPlanet, teamIndex); wheelPartOfPlanet = null; } } } } if (!Menu.GetComponent <Menu>().activ&& selectedUnit != null && selectedUnit.GetComponent <Ship>() != null) { if (Input.GetMouseButtonDown(1)) { RaycastHit hit; Ray ray = cam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, Mathf.Infinity, layer)) { GameObject target = hit.transform.gameObject; PartOfPlanet targetPartOfPlanet = planet.GetComponent <PlanetFormer>().FindPartsOfPlanet(target); if (targetPartOfPlanet.teamIndex == -1 && selectedUnit.GetComponent <Ship>().currentPart != targetPartOfPlanet) { selectedUnit.GetComponent <Ship>().MoveToTarget(target); } } } } if (!Menu.GetComponent <Menu>().activ) { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; Ray ray = cam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, Mathf.Infinity, unitsLayer)) { GameObject target = hit.transform.gameObject; if ((target.GetComponent <Building>() != null && target.GetComponent <Building>().teamIndex == teamIndex) || (target.GetComponent <Ship>() != null && target.GetComponent <Ship>().teamIndex == teamIndex)) { selectedUnit = target; } } } } if (selectedUnit != null) { activAttackRangeSphire.transform.position = selectedUnit.transform.position; activAttackRangeSphire.transform.localScale = new Vector3(1, 1, 1); activAttackRangeSphire.GetComponent <AutoRotate>().enabled = true; if (selectedUnit.GetComponent <Aeroport>() != null) { activAttackRangeSphire.transform.localScale = new Vector3( selectedUnit.GetComponent <Aeroport>().Range, selectedUnit.GetComponent <Aeroport>().Range *rangeScale, selectedUnit.GetComponent <Aeroport>().Range) * 2; } if (selectedUnit.GetComponent <Ship>() != null) { activAttackRangeSphire.transform.localScale = new Vector3( selectedUnit.GetComponent <Ship>().Range, selectedUnit.GetComponent <Ship>().Range *rangeScale, selectedUnit.GetComponent <Ship>().Range) * 2; } if (selectedUnit.GetComponent <NukeSetap>() != null) { activAttackRangeSphire.transform.localScale = new Vector3( selectedUnit.GetComponent <NukeSetap>().Range, selectedUnit.GetComponent <NukeSetap>().Range *rangeScale, selectedUnit.GetComponent <NukeSetap>().Range) * 2; } } else { activAttackRangeSphire.GetComponent <AutoRotate>().enabled = false; activAttackRangeSphire.transform.localScale = new Vector3(1, 1, 1); activAttackRangeSphire.transform.position = Vector3.zero; } //if (!Menu.GetComponent<Menu>().activ) //{ // if (Input.GetMouseButtonDown(0)) // { // RaycastHit hit; // Ray ray = cam.ScreenPointToRay(Input.mousePosition); // if (Physics.Raycast(ray, out hit)) // { // GameObject target = hit.transform.gameObject; // if (target.GetComponentInParent<Teams>() != null) { // selectedUnit = null; // } // } // } //} }
void Start() { for (int t = 0; t < teams.Length; t++) { teams[t].material.SetColor("o", teams[t].color); teams[t].teamIndex = t; } PlanetFormer planetFormer = gameObject.GetComponent <PlanetFormer>(); mainland = new List <PartOfPlanet>(); water = new List <PartOfPlanet>(); for (int t = 0; t < planetFormer.partsOfPlanet.Count; t++) { water.Add(planetFormer.partsOfPlanet[t]); } Queue <PartOfPlanet> qp = new Queue <PartOfPlanet>(); for (int t = 0; t < startPartsCount; t++) { int newIndex = Random.Range(0, planetFormer.partsOfPlanet.Count); if (mainland.IndexOf(planetFormer.partsOfPlanet[newIndex]) == -1) { mainland.Add(planetFormer.partsOfPlanet[newIndex]); water.Remove(planetFormer.partsOfPlanet[newIndex]); qp.Enqueue(planetFormer.partsOfPlanet[newIndex]); } else { t--; } } for (int t = 0; t < mainlandCount - startPartsCount; t++) { if (qp.Count > 0) { PartOfPlanet partOfPlanet = qp.Dequeue(); bool neighborsCheck = false; for (int i = 0; i < partOfPlanet.GetNeighbors().Count; i++) { if (mainland.IndexOf(partOfPlanet.GetNeighbors()[i]) == -1) { neighborsCheck = true; if (Random.Range(0, 2) == 0) { mainland.Add(partOfPlanet.GetNeighbors()[i]); water.Remove(partOfPlanet.GetNeighbors()[i]); qp.Enqueue(partOfPlanet.GetNeighbors()[i]); } else { t--; } qp.Enqueue(partOfPlanet); break; } } if (!neighborsCheck) { t--; } } else { break; } } for (int t = 0; t < teams.Length; t++) { teams[t].population = 0; int rngIndex = Random.Range(0, mainland.Count); PartOfPlanet startPartOfPlanet = mainland[rngIndex]; teams[t].SetPartsOfPlanet(startPartOfPlanet, mainland, mainlandCount / teams.Length - 1, t); } for (int t = 0; t < teams.Length; t++) { for (int i = 0; i < teams[t].GetPartsOfPlanet().Count; i++) { teams[t].GetPartsOfPlanet()[i].GetPart().GetComponent <MeshRenderer>().sharedMaterial = teams[t].material; } } for (int t = 0; t < teams.Length; t++) { teams[t].UpdateCountries(teams); teams[t].countries.Clear(); } for (int t = 0; t < teams.Length; t++) { teams[t].UpdateCountries(teams); teams[t].countries.Clear(); } for (int t = 0; t < teams.Length; t++) { teams[t].UpdateCountries(teams); } for (int t = 0; t < teams.Length; t++) { teams[t].money = startMoney; if (t != 0) { teams[t].money -= Random.Range(1000, 15000); } for (int i = 0; i < teams[t].countries.Count; i++) { teams[t].countries[i].population = startPopulationAtPart * teams[t].countries[i].parts.Count; teams[t].population += startPopulationAtPart * teams[t].countries[i].parts.Count; } } for (int t = 0; t < teams.Length; t++) { teams[t].UpdateColor(); } }
public abstract void Create(PartOfPlanet partOfPlanet, int teamIndex);