vMove ChargeMove(Vector3 startXy, Vector3 dir, int dist, vMove previosNode) { int val = 0; Vector3 newSpace = startXy + (dir * (dist)); //create a pos at the end spot Node endNode = m_grid.NodeFromWorldPoint(newSpace); // Get node from new pos if (!endNode.walkable) { Debug.Log("X"); Debug.DrawRay(newSpace, Vector3.up, Color.red, 5f); return(null); } else { Debug.DrawRay(newSpace, -dir * dist, Color.green, 5f); val += CheckPushDanger(endNode); //Check pushablity of endnode //TODO actually check danger val += CheckIfUnitInLine(newSpace, new Vector3(startXy.x, 0, startXy.y)); //TODO finish function if (CheckIfPossibleElim(newSpace, dir)) { val += posElim; } //allows for movement in line in dir based on dist return(new vMove(val, endNode, previosNode)); } }
vMove ChargeMove(Vector3 startXy, Vector3 dir, int dist, vMove previosNode, bool simMove) { bool unitInLine = false; float val = 0; int valUnitLine = 0; Vector3 newSpace = startXy + (dir * (dist)); //create a pos at the end spot Node endNode = m_grid.NodeFromWorldPoint(newSpace); // Get node from new pos if (!endNode.walkable) { //Debug.DrawRay(newSpace, Vector3.up, Color.red, 5f); return(null); } else { for (int i = 1; i <= dist; i++) { //Debug.DrawRay(newSpace, Vector3.up, Color.green, 5f); Vector3 testPos = startXy + (dir * (i)); Node testN = m_grid.NodeFromWorldPoint(testPos); if (!testN.walkable) { //Debug.DrawRay(newSpace, dir, Color.yellow, 5f); //Debug.DrawRay(newSpace, Vector3.up, Color.yellow, 5f); return(null); } } Debug.DrawRay(newSpace, -dir * dist, debugColor, 2f); val += dist * distCoverd; val += CheckPushDanger(endNode); //Check pushablity of endnode //TODO actually check danger valUnitLine += CheckIfUnitInLine(dist, startXy, dir); if (valUnitLine > 0) { unitInLine = true; } if (CheckIfPossibleElim(newSpace, dir) && unitInLine) { val += valUnitLine * posElim; } else { val += valUnitLine; } //Distance to //allows for movement in line in dir based on dist //Test if pushed and update return(new vMove(val, endNode, previosNode)); } }
public override vMove[] EvalFunctForAi(Node nPos, Vector3 tar) { //nodeForEval.Clear(); //Debug.DrawRay(nPos.worldPosition, Vector3.forward * chrgDistance, Color.green, 10f); //Debug.DrawRay(nPos.worldPosition, Vector3.back * chrgDistance, Color.green, 10f); //Debug.DrawRay(nPos.worldPosition, Vector3.right * chrgDistance, Color.green, 10f); //Debug.DrawRay(nPos.worldPosition, Vector3.left * chrgDistance, Color.green, 10f); //Judge Each direction vMove[] finalNodes = new vMove[4]; if (uAi == null) { uAi = GetComponent <AIUnit>(); } finalNodes[0] = chargeDirEval(nPos, Vector3.forward); //finalNodes[0].value += Mathf.RoundToInt(Vector3.Distance(finalNodes[0].endNode.worldPosition, tar)); finalNodes[1] = chargeDirEval(nPos, Vector3.back); //finalNodes[1].value += Mathf.RoundToInt(Vector3.Distance(finalNodes[1].endNode.worldPosition, tar)); finalNodes[2] = chargeDirEval(nPos, Vector3.left); //finalNodes[2].value += Mathf.RoundToInt(Vector3.Distance(finalNodes[2].endNode.worldPosition, tar)); finalNodes[3] = chargeDirEval(nPos, Vector3.right); //finalNodes[3].value += Mathf.RoundToInt(Vector3.Distance(finalNodes[3].endNode.worldPosition, tar)); //Sort by values nodeForEval.Add(finalNodes[0].endNode); nodeForEval.Add(finalNodes[1].endNode); nodeForEval.Add(finalNodes[2].endNode); nodeForEval.Add(finalNodes[3].endNode); float temp = 0; for (int write = 0; write < finalNodes.Length; write++) { for (int sort = 0; sort < finalNodes.Length - 1; sort++) { if (finalNodes[sort].value > finalNodes[sort + 1].value) { temp = finalNodes[sort + 1].value; finalNodes[sort + 1].value = finalNodes[sort].value; finalNodes[sort].value = temp; } } } return(finalNodes); }
IEnumerator NSWEChargeCheck(Vector3 startPos, vMove preMove, List <vMove> vMoves, bool simMove) { checking = true; for (int i = 1; i <= chargeSqrs; i++) { vMove newNodeVal = ChargeMove(startPos, Vector3.forward, i, preMove, simMove); if (newNodeVal != null) { vMoves.Add(newNodeVal); } //yield return null; //Wait frame } for (int i = 1; i <= chargeSqrs; i++) { vMove newNodeVal = ChargeMove(startPos, -Vector3.forward, i, preMove, simMove); if (newNodeVal != null) { vMoves.Add(newNodeVal); } //yield return null; //Wait frame } for (int i = 1; i <= chargeSqrs; i++) { vMove newNodeVal = ChargeMove(startPos, Vector3.right, i, preMove, simMove); if (newNodeVal != null) { vMoves.Add(newNodeVal); } //yield return null; //Wait frame } for (int i = 1; i <= chargeSqrs; i++) { vMove newNodeVal = ChargeMove(startPos, -Vector3.right, i, preMove, simMove); if (newNodeVal != null) { vMoves.Add(newNodeVal); } //yield return null; //Wait frame } checking = false; yield return(null); //Wait frame }
IEnumerator CheckChargeMoves() { for (int i = 1; i <= chargeSqrs; i++) { vMove newNodeVal = ChargeMove(transform.position, Vector3.forward, i, null); if (newNodeVal != null) { nodeWithValues.Add(newNodeVal); } yield return(null); } for (int i = 1; i <= chargeSqrs; i++) { vMove newNodeVal = ChargeMove(transform.position, -Vector3.forward, i, null); if (newNodeVal != null) { nodeWithValues.Add(newNodeVal); } yield return(null); } for (int i = 1; i <= chargeSqrs; i++) { vMove newNodeVal = ChargeMove(transform.position, Vector3.right, i, null); if (newNodeVal != null) { nodeWithValues.Add(newNodeVal); } yield return(null); } for (int i = 1; i <= chargeSqrs; i++) { vMove newNodeVal = ChargeMove(transform.position, -Vector3.right, i, null); if (newNodeVal != null) { nodeWithValues.Add(newNodeVal); } yield return(null); } Debug.Log("Checked Move Number: " + nodeWithValues.Count); yield return(null); }
public int CompareTo(vMove other) //Lets us use .sort { return(value.CompareTo(other.value)); }
public valuedMoves(float val, vMove nde, AIUnit uAi) //Constructs a val node { value = val; node = nde; unit = uAi; }