//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LOAD STATS public void LoadStats(InitLevel level) { Peripheral.Instance.addDreams(level.init_stats.dreams, Vector3.zero, false); Peripheral.Instance.max_dreams = 2000; PathfinderType PathType = PathfinderType.GridBased; Peripheral.Instance.SetInitHealth(level.init_stats.health); Peripheral.Instance.pathf = PathType; Peripheral.Instance.tileSize = 1; // not supported through file if (level.init_stats.map_size_x > 0) { EagleEyes.Instance.setMapSize(level.init_stats.map_size_x, level.init_stats.map_size_y); } else { Debug.LogError("WTF no map size\n"); } /* * LevelMod[] level_mod; * if (level.init_stats.level_mod != null && level.init_stats.level_mod.Length > 0) * { * level_mod = level.init_stats.level_mod; * } * else * { * level_mod = new LevelMod[1]; * level_mod[0] = new LevelMod(); * } * * Peripheral.Instance.level_mod = level_mod; */ Peripheral.Instance.env_type = EnumUtil.EnumFromString <EnvType>(level.init_stats.env, EnvType.Default); }
public Pathfinding(int TilesWide, int TilesHigh, int TileSize, Texture2D pathDisplaySprite, PathfinderType type) { this.tileSize = TileSize; this.TilesHigh = TilesHigh; this.TilesWide = TilesWide; this.pathDisplaySprite = pathDisplaySprite; this.type = type; }
private Node GetOpenNode(PathfinderType pfT) { //ESTA FUNCION VENDRIA A SER LA FUNCION DE VISITAR NODO Node node = null; switch (pfT) { case PathfinderType.BreadthFirst: node = openNodes[0]; break; case PathfinderType.DepthFirst: node = openNodes[openNodes.Count - 1]; break; case PathfinderType.Dijkstra: int index = 0; float lowestValue = 9999999; for (int i = 0; i < openNodes.Count; i++) { if (openNodes[i].GetTotalCost() < lowestValue) { index = i; lowestValue = openNodes[i].GetTotalCost(); } } node = openNodes[index]; break; case PathfinderType.Star: int starIndex = 0; float starLowestValue = 9999999; for (int i = 0; i < openNodes.Count; i++) { float heuristic = Heuristic(openNodes[i]); if (openNodes[i].GetTotalCost() + heuristic < starLowestValue) { starIndex = i; starLowestValue = openNodes[i].GetTotalCost() + heuristic; } } node = openNodes[starIndex]; break; } return(node); }
public List <Node> GetPath(Node start, Node finish, PathfinderType pfT) { CleanNodes(); finishNode = finish; OpenNode(start, null); Node node; while (openNodes.Count > 0) { //Visito el nodo.// node = GetOpenNode(pfT); //---------------// if (node == finish) { path = CreatePath(finish); return(path); } CloseNode(node); OpenAdyNodes(node, pfT); } return(path); }
static void OpenAdyNodes(Node node, PathfinderType pfT) { NodeAdy[] adyNodes = node.GetNodeAdyacents(); for (int i = 0; i < adyNodes.Length; i++) { if (adyNodes[i].node != null) { if (adyNodes[i].node && !adyNodes[i].node.IsObstacle && adyNodes[i].node.nodeState == NodeState.Ok) { OpenNode(adyNodes[i].node, node); if (pfT == PathfinderType.Dijkstra || pfT == PathfinderType.Star) { if (adyNodes[i].node.GetTotalCost() == 0 || adyNodes[i].node.GetTotalCost() > adyNodes[i].node.GetCost() + node.GetTotalCost()) { adyNodes[i].node.SetTotalCost(adyNodes[i].node.GetCost() + node.GetTotalCost()); adyNodes[i].node.Predecesor = node; } } } } } }
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LOAD STATS public string oldLoadStats(bool init) { string line = file.Dequeue(); // Debug.Log("Loading init stats\n"); while (line != null && !line[0].Equals(':')) { JSONParser p = new JSONParser(line); p.parse(); JSONObject points = new JSONObject(); p.root.TryGetValue("points", out points); JSONObject delete_savegames = new JSONObject(); p.root.TryGetValue("delete_savegames", out points); Central.Instance.points = int.Parse(points.value); if (delete_savegames.value == "1") { Central.Instance.game_saver.DeleteAllSaveGames(); } if (!init) { JSONObject health = new JSONObject(); JSONObject dreams = new JSONObject(); JSONObject max_dreams = new JSONObject(); JSONObject type = new JSONObject(); JSONObject tilesize = new JSONObject(); JSONObject mapsize = new JSONObject(); JSONObject pathf = new JSONObject(); p.root.TryGetValue("dreams", out dreams); p.root.TryGetValue("tilesize", out tilesize); p.root.TryGetValue("health", out health); p.root.TryGetValue("max_dreams", out max_dreams); p.root.TryGetValue("pathf", out pathf); p.root.TryGetValue("type", out type); p.root.TryGetValue("map_size", out mapsize); float dreams_points = int.Parse(dreams.value); Peripheral.Instance.addDreams(dreams_points, Vector3.zero, false); //ScoreKeeper.Instance.SetDreams(dreams_points); Peripheral.Instance.max_dreams = int.Parse(max_dreams.value); PathfinderType PathType = PathfinderType.GridBased; Peripheral.Instance.SetHealth(int.Parse(health.value), false); Peripheral.Instance.pathf = PathType; Peripheral.Instance.tileSize = int.Parse(tilesize.value); if (mapsize != null) { EagleEyes.Instance.setMapSize(int.Parse(mapsize.dict["x"].value), int.Parse(mapsize.dict["y"].value)); } else { Debug.Log("WTF no map size\n"); } } line = file.Dequeue(); } return(line); }
protected virtual void Start() { Path = new List <Vector3>(); PathType = PathfinderType.WaypointBased; }
protected virtual void Start() { Path = new List<Vector3>(); PathType = PathfinderType.WaypointBased; }