From 6d8fc52d3bff7a36092763f152e4daaba4dcd858 Mon Sep 17 00:00:00 2001 From: vylion Date: Sat, 29 Oct 2016 11:48:31 +0200 Subject: [PATCH] Created different unit lists by map position and team --- Assets/Generator.cs | 20 ++++++----- Assets/TurnManagerScript.cs | 2 +- Assets/UnitBehaviour.cs | 3 +- Assets/UnitCreator.cs | 66 ++++++++++++++++++++++++------------- 4 files changed, 58 insertions(+), 33 deletions(-) diff --git a/Assets/Generator.cs b/Assets/Generator.cs index 84abce8..3395d50 100644 --- a/Assets/Generator.cs +++ b/Assets/Generator.cs @@ -18,15 +18,15 @@ public class Generator : MonoBehaviour { GameObject turnMan = Instantiate (tmanager); GameObject mapCreator = Instantiate (mcreator); GameObject unitCreator = Instantiate (ucreator); - tScript = turnMan.GetComponent(); - mScript = mapCreator.GetComponent(); - uScript = unitCreator.GetComponent(); + tScript = turnMan.GetComponent (); + mScript = mapCreator.GetComponent (); + uScript = unitCreator.GetComponent (); uScript.mapSize = new Vector2 (20, 40); - int[,] map = new int [x,y]; - for(int i = 0; i < x; ++i) { - for(int j = 0; j < y; ++j) { - if (i == 0 || i == x-1 || j == 0 || j == y-1) + int[,] map = new int [x, y]; + for (int i = 0; i < x; ++i) { + for (int j = 0; j < y; ++j) { + if (i == 0 || i == x - 1 || j == 0 || j == y - 1) map [i, j] = -1; else map [i, j] = 0; @@ -35,9 +35,11 @@ public class Generator : MonoBehaviour { //just to test map [10, 10] = -1; map [10, 20] = -1; - mScript.setMatrix (map,x,y); + mScript.setMatrix (map, x, y); - turnMan.GetComponent ().charMap = uScript.tutorialUnits (x, y); + uScript.tutorialUnits (); + turnMan.GetComponent ().charMap = uScript.getUnitMap (); + turnMan.GetComponent ().charList = uScript.getUnitLists (); } // Update is called once per frame diff --git a/Assets/TurnManagerScript.cs b/Assets/TurnManagerScript.cs index ba3061d..4e95b0f 100644 --- a/Assets/TurnManagerScript.cs +++ b/Assets/TurnManagerScript.cs @@ -9,7 +9,7 @@ public class TurnManagerScript : MonoBehaviour { public int playerNum = 2; public int iaNum = 0; public bool inTurn = true; - //public List > charList; + public List > charList; public List terrain; public List charMap; diff --git a/Assets/UnitBehaviour.cs b/Assets/UnitBehaviour.cs index fb0e809..a4b90ef 100644 --- a/Assets/UnitBehaviour.cs +++ b/Assets/UnitBehaviour.cs @@ -38,9 +38,10 @@ public class UnitBehaviour : MonoBehaviour { public int attackActions = 2; public Elemental attackElem = Elemental.None; - public void SetupStats (int pX, int pZ, int actions = 2, int steps = 5, int p = 50, int crit = 10, int pRange = 20, int critRange = 10) { + public void SetupStats (int pX, int pZ, Team id, int actions = 2, int steps = 5, int p = 50, int crit = 10, int pRange = 20, int critRange = 10) { posX = pX; posZ = pZ; + teamID = id; actionsPerTurn = actions; stepLength = steps; if (pRange > 0) { diff --git a/Assets/UnitCreator.cs b/Assets/UnitCreator.cs index 746cabf..f422ba2 100644 --- a/Assets/UnitCreator.cs +++ b/Assets/UnitCreator.cs @@ -6,10 +6,14 @@ public class UnitCreator : MonoBehaviour { public GameObject lichObject; public GameObject skeletonObject; - public List units; + public List unitsByMap; public Vector2 mapSize; + public List> unitsByTeam; private UnitBehaviour playerLichScript; + private List teamNone; + private List teamPlayer; + private List teamEnemy1; public enum UnitType { Lich = 0, @@ -30,14 +34,14 @@ public class UnitCreator : MonoBehaviour { } void createUnit(int posX, int posZ, UnitBehaviour.Team team, UnitType type = UnitType.Skeleton) { - GameObject unit; + GameObject unit = null; if (type == UnitType.Lich) { unit = Instantiate (lichObject, new Vector3(posX, lichObject.transform.lossyScale.y/2f, posZ), Quaternion.identity) as GameObject; unit.transform.localScale = new Vector3 (unit.transform.lossyScale.y/unit.transform.lossyScale.y, 1, unit.transform.lossyScale.z/unit.transform.lossyScale.y); - unit.GetComponent ().SetupStats (posX, posZ, 3, 3, 100, 0, 0, 0); + unit.GetComponent ().SetupStats (posX, posZ, team, 3, 3, 100, 0, 0, 0); unit.GetComponent ().SetupBaseAttack (4, 2, 3); - units.Insert(posX*(int)mapSize.x+posZ, unit); + unitsByMap.Insert(posX*(int)mapSize.x+posZ, unit); if (team == UnitBehaviour.Team.Player && playerLichScript == null ) playerLichScript = unit.GetComponent (); @@ -45,27 +49,36 @@ public class UnitCreator : MonoBehaviour { } else if (type == UnitType.Skeleton) { unit = Instantiate (skeletonObject, new Vector3(posX, 0f, posZ), Quaternion.identity) as GameObject; unit.transform.localScale = new Vector3 (unit.transform.localScale.x*0.3f, unit.transform.localScale.y*0.3f, unit.transform.localScale.z*0.3f); - unit.GetComponent ().SetupStats (posX, posZ); - units.Insert(posX*(int)mapSize.x+posZ, unit); - - - if (team == UnitBehaviour.Team.Enemy1) { - unit.transform.Rotate (new Vector3 (0, 180, 0)); - } - - //units.Add (unit); + unit.GetComponent ().SetupStats (posX, posZ, team); + unitsByMap.Insert(posX*(int)mapSize.x+posZ, unit); } - + + if (team == UnitBehaviour.Team.Player) { + teamPlayer.Add (unit); + } else if (team == UnitBehaviour.Team.Enemy1) { + unit.transform.Rotate (new Vector3 (0, 180, 0)); + teamEnemy1.Add (unit); + } + } + + void setMap(int x, int y) { + unitsByMap = new List(x * y); + for (int i = 0; i < y; i++) { + for (int j = 0; j < x; j++) { + unitsByMap.Insert(i * x + j, null); + } + } + + unitsByTeam = new List> (); + + teamNone = new List (); + teamPlayer = new List (); + teamEnemy1 = new List (); } - public List tutorialUnits(int x, int y) { - units = new List(x * y); - for (int i = 0; i < y; i++) { - for (int j = 0; j < x; j++) { - units.Insert(i * x + j, null); - } - } + public void tutorialUnits() { + setMap (20, 40); createUnit (9, 5, UnitBehaviour.Team.Player, UnitType.Lich); @@ -84,6 +97,15 @@ public class UnitCreator : MonoBehaviour { createUnit (16, 24, UnitBehaviour.Team.Enemy1); createUnit (17, 26, UnitBehaviour.Team.Enemy1); - return units; + unitsByTeam.Add (teamPlayer); + unitsByTeam.Add (teamEnemy1); + } + + public List> getUnitLists() { + return unitsByTeam; + } + + public List getUnitMap() { + return unitsByMap; } }