///<summary> ///sets up the game environment from map file ///</summary> ///<param name="filename"></param> ///<param name="mapData"></param> ///<returns></returns> public bool LoadMap(string filename, out MapData mapData) { mapData = null; try { mapData = MyGame.Instance.Content.Load<MapData>(filename); } catch (Exception e) { Assert.Fatal(false, "Map.LoadMap: Bad Map Filename -> " + e.Message); return false; } Clear(); //first of all read and create the navgraph. This must be done //before the entities are read from the map file because many of //the entities will be linked to a graph node (the graph node will //own a pointer to an instance of the entity) NavGraph = new SparseGraph(false); NavGraph.Load(mapData); LogUtil.WriteLineIfLogCreate("NavGraph for " + filename + " loaded okay"); LogUtil.WriteLineIfLogCreate(NavGraph.ToString()); //determine the average distance between graph nodes so that we can //partition them efficiently CellSpaceNeighborhoodRange = GraphUtil.CalculateAverageGraphEdgeLength(NavGraph) + 1; LogUtil.WriteLineIfLogCreate("Average edge length is " + GraphUtil.CalculateAverageGraphEdgeLength(NavGraph)); LogUtil.WriteLineIfLogCreate("Neighborhood range set to " + CellSpaceNeighborhoodRange); //load in the map size SizeX = mapData.SizeX; SizeY = mapData.SizeY; LogUtil.WriteLineIfLogCreate("Partitioning navgraph nodes..."); //partition the graph nodes PartitionNavGraph(); LogUtil.WriteLineIfLogCreate("Loading map..."); foreach (WallData wallData in mapData.WallList) { LogUtil.WriteLineIfLogCreate("Creating a wall <" + wallData.Name + "> between " + wallData.From + " and " + wallData.To); AddWall(wallData); } //note: add triggers before doors (or else!) foreach (DoorTriggerData doorTriggerData in mapData.DoorTriggerList) { LogUtil.WriteLineIfLogCreate("Creating a door trigger <" + doorTriggerData.Name + "> at " + doorTriggerData.Position); AddDoorTrigger(doorTriggerData); } foreach (DoorData doorData in mapData.DoorList) { LogUtil.WriteLineIfLogCreate("Creating a door <" + doorData.Name + "> between " + doorData.From + " and " + doorData.To); AddDoor(doorData); } foreach (SpawnPointData spawnPointData in mapData.SpawnPointList) { LogUtil.WriteLineIfLogCreate("Creating a spawn point <" + spawnPointData.Name + "> at " + spawnPointData.Position); AddSpawnPoint(spawnPointData); } foreach (HealthData healthData in mapData.HealthList) { LogUtil.WriteLineIfLogCreate( "Creating a health giver trigger <" + healthData.Name + "> at " + healthData.Position); AddHealth(healthData); } foreach (RailgunData railgunData in mapData.RailgunList) { LogUtil.WriteLineIfLogCreate( "Creating a rail gun weapon giver trigger <" + railgunData.Name + "> at " + railgunData.Position); AddRailgun(railgunData); } foreach (RocketLauncherData rocketLauncherData in mapData.RocketLauncherList) { LogUtil.WriteLineIfLogCreate( "Creating a rocket launcher weapon giver trigger <" + rocketLauncherData.Name + "> at " + rocketLauncherData.Position); AddRocketLauncher(rocketLauncherData); } foreach (ShotgunData shotgunData in mapData.ShotgunList) { LogUtil.WriteLineIfLogCreate( "Creating a shot gun weapon giver trigger <" + shotgunData.Name + "> at " + shotgunData.Position); AddShotgun(shotgunData); } LogUtil.WriteLineIfLogCreate(filename + " loaded okay"); //calculate the cost lookup table PathCosts = GraphUtil.CreateAllPairsCostsTable(NavGraph); return true; }