Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BasicMove : MoveWithJump
- {
- /// <summary>
- /// Path dictionary. Contains path list - list of cells - as keys and Tuples with target Cell, normalcy of Cell and if Cell is
- /// accessed via jump
- /// </summary>
- Dictionary<List<Cell>, Tuple<Cell, bool, bool>> pathDict = new Dictionary<List<Cell>, Tuple<Cell, bool, bool>>();
- int strategicActCost;
- public override Dictionary<List<Cell>, Tuple<Cell, bool, bool>> Flood(int distance, int jump, int height,
- int movepoints, int actionpoints, Cell originNode)
- {
- this.distance = distance;
- this.jump = jump;
- this.height = height;
- this.movepoints = movepoints;
- this.actionpoints = actionpoints;
- this.originNode = originNode;
- pathDict.Clear();
- strategicActCost = 0; //put there some function to set action point costs for moving according to Strategic effects
- int actCost = strategicActCost; //yadda yadda
- FloodSegment(originNode, new List<Cell>(), 0f, 0, false);
- return pathDict;
- }
- /// <summary>
- /// A cell that will be the Node, Path to it (not inc itself), access type (i.e. normally unpathable/pathable, switched by ControlMode),
- /// move cost accumulated by the Path, act cost. Uses class variables. Used for operating complete Dictionary of Paths
- /// </summary>
- protected void FloodSegment(Cell current, List<Cell> path1,
- float moveCostSoFar1, int actCostSoFar1,
- bool isJump)
- {
- List<Cell> path = new List<Cell>(path1);
- float moveCostSoFar = moveCostSoFar1;
- int actCostSoFar = actCostSoFar1;
- if (current != originNode) //do not put originNode in path or dict
- {
- path.Add(current);
- // string s = "";
- // foreach (Cell cell in path)
- // {
- // s += cell.transform.position.x.ToString("F2") + cell.transform.position.y.ToString("F2");
- // }
- // Debug.Log("Added"+s);
- pathDict.Add(path, Tuple.Create<Cell, bool, bool>(current, true, isJump)); //create pathDict keyvalue for current
- }
- if (current.adjacentCell.Count != 0) //if at least 1 neighbouring Cell
- {
- foreach (Cell adjacent in current.adjacentCell.Keys) //for every adjacent Cell
- {
- if (adjacent == originNode) continue;
- if (path.Contains(adjacent)) continue;
- int actCost = strategicActCost; //put there some function that changes actCost according to Cell/Occupier effects
- if (moveCostSoFar + adjacent.moveCost > movepoints) continue; //skip if will flood over the limit
- if (actCostSoFar + actCost > actionpoints) continue; //skip if will flood over the limit
- moveCostSoFar += adjacent.moveCost;
- actCostSoFar += actCost;
- //adjacent Cell is occupied, thus normal path is impossible
- //during movement paths will be cut off at this point, if in ControlMode first unnormal Cell will be highlighted
- if (adjacent.occupier != null)
- {
- {
- List<Cell> newPath = new List<Cell>(path);
- newPath.Add(adjacent);
- pathDict.Add(newPath, Tuple.Create<Cell, bool, bool>(adjacent, false, false));
- }
- if (CanJumpOver(current, adjacent, jump, height, 4)) //check for ability to jump over
- { //Borders and such are excluded
- //Find Cell that Unit will jump to if can jump over adjacent cell
- Vector2 vec = adjacent.transform.position;
- vec = GetVectorInDirection(vec, current.adjacentCell[adjacent]);
- string vec2 = (vec.x.ToString("F2")+vec.y.ToString("F2"));
- if (!cellGrid.CellDict.ContainsKey(vec2)) continue;
- for (int i = 0; i < cellGrid.CellDict[vec2].Count; i++)
- {
- //check 3 direction behind
- for (int j = -1; j < 2; j++)
- {
- Vector2 vec3 = GetVectorInDirection(vec, DirectionCorrection(current.adjacentCell[adjacent] + j));
- string vec4 = (vec3.x.ToString("F2")+vec3.y.ToString("F2"));
- if (!cellGrid.CellDict.ContainsKey(vec4)) continue;
- for (int k = 0; k < cellGrid.CellDict[vec4].Count; k++)
- {
- if (CanJumpOn(adjacent, cellGrid.CellDict[vec4][k], jump, height))
- {
- FloodSegment(cellGrid.CellDict[vec4][k], path, moveCostSoFar, actCostSoFar, true);
- }
- }
- }
- }
- }
- }
- //checking for effects that will hurt unit if he uses this Cell for path
- // if (special condition) //Dependant on special effects
- if (adjacent.occupier == null && adjacent.Height + jump < current.Height)
- { //accessible jumps that will hurt Unit - normal hurting condition
- List<Cell> newPath = new List<Cell>(path);
- newPath.Add(adjacent);
- pathDict.Add(newPath, Tuple.Create<Cell, bool, bool>(adjacent, false, true));
- continue;
- }
- FloodSegment(adjacent, path, moveCostSoFar, actCostSoFar, false);
- }
- }
- if (current.jumpNode.jumpDict4.Count != 0) //if at least one jumping adjacent at 4 distances
- {
- foreach (Cell jumpAdjacent in current.jumpNode.jumpDict4.Keys) //for every Cell adjacent via jump
- {
- foreach (var tuple in current.jumpNode.jumpDict4[jumpAdjacent])
- {
- int minJump = tuple.Item1;
- int maxHeight = tuple.Item2;
- if (jump < minJump || height > maxHeight) continue; //is valid for using this jump
- int actCost = strategicActCost; //put there some function that changes actCost according to Cell/Occupier effects
- minJump /= 2; //every 2 heights of jump cost 1 movepoint, 1 minimum; needs to be integer
- if (moveCostSoFar + 4 + minJump > movepoints) continue; //skip if will flood over the limit
- if (actCostSoFar + actCost > actionpoints) continue; //skip if will flood over the limit
- moveCostSoFar += 4 + minJump;
- actCostSoFar += actCost;
- //adjacent Cell is occupied, thus normal path is impossible
- //during movement paths will be cut off at this point, if
- //in ControlMode first unnormal Cell will be highlighted
- if (jumpAdjacent.occupier != null)
- {
- List<Cell> newPath = new List<Cell>(path);
- newPath.Add(jumpAdjacent);
- if (!pathDict.ContainsKey(newPath)) //prevents duplications of paths. Jumps sometimes have multiple possible routes
- {
- pathDict.Add(newPath, Tuple.Create<Cell, bool, bool>(jumpAdjacent, false, true));
- continue;
- }
- }
- //checking for effects that will hurt unit if he uses this Cell for path
- // if (special condition) //Dependant on special effects
- if (jumpAdjacent.occupier == null && jumpAdjacent.Height + jump < current.Height)
- { //accessible jumps that will hurt Unit - normal hurting condition
- List<Cell> newPath = new List<Cell>(path);
- newPath.Add(jumpAdjacent);
- if (!pathDict.ContainsKey(newPath))
- {
- pathDict.Add(newPath, Tuple.Create<Cell, bool, bool>(jumpAdjacent, false, true));
- continue;
- }
- }
- List<Cell> newPath2 = new List<Cell>(path);
- newPath2.Add(jumpAdjacent);
- if (!pathDict.ContainsKey(newPath2))
- {
- FloodSegment(jumpAdjacent, path, moveCostSoFar, actCostSoFar, true);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement