Exemplo n.º 1
0
 ///<summary>
 ///constructor
 ///</summary>
 ///<param name="source"></param>
 ///<param name="destination"></param>
 ///<param name="behavior"></param>
 public PathEdge(
     Vector2 source,
     Vector2 destination,
     EdgeData.BehaviorTypes behavior)
     : this(source, destination, behavior, 0)
 {
 }
Exemplo n.º 2
0
 ///<summary>
 ///constructor
 ///</summary>
 ///<param name="from"></param>
 ///<param name="to"></param>
 ///<param name="cost"></param>
 ///<param name="behaviorType"></param>
 public NavGraphEdge(
     int from,
     int to,
     float cost,
     EdgeData.BehaviorTypes behaviorType)
     : base(from, to, cost)
 {
     _behaviorType = behaviorType;
     _intersectingEntityId = INVALID_ID;
     _intersectingEntityName = null;
 }
Exemplo n.º 3
0
 ///<summary>
 ///constructor
 ///</summary>
 ///<param name="source"></param>
 ///<param name="destination"></param>
 ///<param name="behavior"></param>
 ///<param name="doorId"></param>
 public PathEdge(
     Vector2 source,
     Vector2 destination,
     EdgeData.BehaviorTypes behavior,
     uint doorId)
 {
     Source = source;
     Destination = destination;
     _behavior = behavior;
     _doorId = doorId;
 }
Exemplo n.º 4
0
 ///<summary>
 ///constructor
 ///</summary>
 ///<param name="edgeData"></param>
 public NavGraphEdge(EdgeData edgeData)
 {
     From = edgeData.FromIndex;
     To = edgeData.ToIndex;
     Cost = edgeData.Cost;
     _behaviorType = edgeData.BehaviorType;
     _intersectingEntityId = INVALID_ID; //to be filled in later
     _intersectingEntityName = edgeData.NameOfIntersectingEntity;
 }
Exemplo n.º 5
0
        ///<summary>
        ///load a map in Raven .map format
        ///</summary>
        ///<param name="ravenMapFilename">the Raven map file</param>
        ///<exception cref="ApplicationException"></exception>
        public void LoadFromRavenMap(string ravenMapFilename)
        {
            //used to find index of edge crossed by entity with given ravenId
            Dictionary<int, List<int>> idEdgeMap =
                new Dictionary<int, List<int>>();

            //used to find the index of door having trigger with given ravenId
            Dictionary<int, int> idDoorMap = new Dictionary<int, int>();

            //used to find the index of the door with the given ravenId
            Dictionary<int, int> doorIdIndexMap = new Dictionary<int, int>();

            DataStreamReader inStream = new DataStreamReader(ravenMapFilename);

            Name = ravenMapFilename;

            int numNodes = inStream.GetIntFromStream();
            NodeList = new List<NodeData>(numNodes);
            for (int i = 0; i < numNodes; i++)
            {
                NodeData nodeData = new NodeData();

                nodeData.Name = "Node_" + i;
                inStream.SkipNextFieldInStream(); //Index:
                nodeData.Index = inStream.GetIntFromStream();
                inStream.SkipNextFieldInStream(); //PosX:
                float x = inStream.GetIntFromStream();
                inStream.SkipNextFieldInStream(); //PosY:
                float y = inStream.GetIntFromStream();
                nodeData.Position = new Vector2(x, y);

                NodeList.Add(nodeData);
            }

            int numEdges = inStream.GetIntFromStream();
            EdgeList = new List<EdgeData>(numEdges);
            for (int i = 0; i < numEdges; i++)
            {
                EdgeData edgeData = new EdgeData();

                edgeData.Name = "Edge_" + i;
                inStream.SkipNextFieldInStream(); //From:
                edgeData.FromIndex = inStream.GetIntFromStream();
                inStream.SkipNextFieldInStream(); //To:
                edgeData.ToIndex = inStream.GetIntFromStream();
                inStream.SkipNextFieldInStream(); //Cost:
                edgeData.Cost = inStream.GetFloatFromStream();
                inStream.SkipNextFieldInStream(); //Flags:
                edgeData.BehaviorType =
                    (EdgeData.BehaviorTypes) inStream.GetIntFromStream();
                inStream.SkipNextFieldInStream(); //ID:
                //we'll save the id and use it later to fill in
                //the object name when we process the enities
                int idOfIntersectingEntity = inStream.GetIntFromStream();
                if (idOfIntersectingEntity > 0) //if valid
                {
                    if (!idEdgeMap.ContainsKey(idOfIntersectingEntity))
                    {
                        idEdgeMap.Add(idOfIntersectingEntity, new List<int>());
                    }
                    idEdgeMap[idOfIntersectingEntity].Add(i);
                }
                edgeData.NameOfIntersectingEntity = ""; //may replace later
                EdgeList.Add(edgeData);
            }

            SizeX = inStream.GetIntFromStream();
            SizeY = inStream.GetIntFromStream();

            WallList = new List<WallData>();
            DoorList = new List<DoorData>();
            DoorTriggerList = new List<DoorTriggerData>();
            SpawnPointList = new List<SpawnPointData>();
            HealthList = new List<HealthData>();
            RailgunList = new List<RailgunData>();
            RocketLauncherList = new List<RocketLauncherData>();
            ShotgunList = new List<ShotgunData>();
            while (inStream.Peek() >= 0)
            {
                EntityTypes entityType = (EntityTypes) inStream.GetIntFromStream();

                float x, y;

                switch (entityType)
                {
                    case EntityTypes.Wall:
                        WallData wallData = new WallData();

                        wallData.Name = "Wall_" + WallList.Count;
                        x = inStream.GetFloatFromStream();
                        y = inStream.GetFloatFromStream();
                        wallData.From = new Vector2(x, y);
                        x = inStream.GetFloatFromStream();
                        y = inStream.GetFloatFromStream();
                        wallData.To = new Vector2(x, y);
                        x = inStream.GetFloatFromStream();
                        y = inStream.GetFloatFromStream();
                        wallData.Normal = new Vector2(x, y);

                        WallList.Add(wallData);
                        break;

                    case EntityTypes.SlidingDoor:
                        DoorData doorData = new DoorData();

                        doorData.Name = "Door_" + DoorList.Count;
                        int ravenDoorId = inStream.GetIntFromStream();
                        doorIdIndexMap.Add(ravenDoorId, DoorList.Count); //save

                        if (idEdgeMap.ContainsKey(ravenDoorId))
                        {
                            foreach (int i in idEdgeMap[ravenDoorId])
                            {
                                EdgeList[i].NameOfIntersectingEntity =
                                    doorData.Name;
                            }
                        }

                        x = inStream.GetFloatFromStream();
                        y = inStream.GetFloatFromStream();
                        doorData.From = new Vector2(x, y);

                        x = inStream.GetFloatFromStream();
                        y = inStream.GetFloatFromStream();
                        doorData.To = new Vector2(x, y);

                        doorData.TriggerList = new List<string>();
                        int numDoorTriggers = inStream.GetIntFromStream();
                        for (int i = 0; i < numDoorTriggers; i++)
                        {
                            //we'll save the trigger id and use it later to
                            //fill in the object name when we process the door
                            //triggers
                            idDoorMap.Add(
                                inStream.GetIntFromStream(),
                                DoorList.Count);
                        }

                        DoorList.Add(doorData);
                        break;

                    case EntityTypes.DoorTrigger:
                        DoorTriggerData doorTriggerData =
                            new DoorTriggerData();

                        doorTriggerData.Name =
                            "DoorTrigger_" + DoorTriggerList.Count;
                        int ravenDoorTriggerId = inStream.GetIntFromStream();
                        DoorList[idDoorMap[ravenDoorTriggerId]].TriggerList.Add(
                            doorTriggerData.Name);
                        int ravenReceiverId = inStream.GetIntFromStream();
                        doorTriggerData.ReceiverName =
                            DoorList[doorIdIndexMap[ravenReceiverId]].Name;
                        doorTriggerData.MessageToSend =
                            (MessageTypes) inStream.GetIntFromStream();
                        x = inStream.GetFloatFromStream();
                        y = inStream.GetFloatFromStream();
                        doorTriggerData.Position = new Vector2(x, y);
                        doorTriggerData.Radius = inStream.GetFloatFromStream();

                        DoorTriggerList.Add(doorTriggerData);
                        break;

                    case EntityTypes.SpawnPoint:
                        SpawnPointData spawnPointData = new SpawnPointData();

                        spawnPointData.Name =
                            "SpawnPoint_" + SpawnPointList.Count;
                        inStream.SkipNextFieldInStream();
                        x = inStream.GetFloatFromStream();
                        y = inStream.GetFloatFromStream();
                        spawnPointData.Position = new Vector2(x, y);
                        inStream.SkipNextFieldInStream();
                        inStream.SkipNextFieldInStream();

                        SpawnPointList.Add(spawnPointData);
                        break;

                    case EntityTypes.Health:
                        HealthData healthData = new HealthData();

                        healthData.Name = "Health_" + HealthList.Count;
                        inStream.SkipNextFieldInStream(); //heathId
                        x = inStream.GetFloatFromStream();
                        y = inStream.GetFloatFromStream();
                        healthData.Position = new Vector2(x, y);
                        healthData.Radius = inStream.GetFloatFromStream();
                        healthData.HealthGiven = inStream.GetIntFromStream();
                        healthData.NodeIndex = inStream.GetIntFromStream();

                        HealthList.Add(healthData);
                        break;

                    case EntityTypes.Shotgun:
                        ShotgunData shotgunData = new ShotgunData();

                        shotgunData.Name = "Shotgun_" + ShotgunList.Count;
                        inStream.SkipNextFieldInStream(); //shotgunId
                        x = inStream.GetFloatFromStream();
                        y = inStream.GetFloatFromStream();
                        shotgunData.Position = new Vector2(x, y);
                        shotgunData.Radius = inStream.GetFloatFromStream();
                        shotgunData.NodeIndex = inStream.GetIntFromStream();

                        ShotgunList.Add(shotgunData);
                        break;

                    case EntityTypes.Railgun:
                        RailgunData railgunData = new RailgunData();

                        railgunData.Name = "Railgun_" + RailgunList.Count;
                        inStream.SkipNextFieldInStream(); //shotgunId
                        x = inStream.GetFloatFromStream();
                        y = inStream.GetFloatFromStream();
                        railgunData.Position = new Vector2(x, y);
                        railgunData.Radius = inStream.GetFloatFromStream();
                        railgunData.NodeIndex = inStream.GetIntFromStream();

                        RailgunList.Add(railgunData);
                        break;

                    case EntityTypes.RocketLauncher:
                        RocketLauncherData rocketLauncherData =
                            new RocketLauncherData();

                        rocketLauncherData.Name =
                            "RocketLauncher_" + RocketLauncherList.Count;
                        inStream.SkipNextFieldInStream(); //shotgunId
                        x = inStream.GetFloatFromStream();
                        y = inStream.GetFloatFromStream();
                        rocketLauncherData.Position = new Vector2(x, y);
                        rocketLauncherData.Radius =
                            inStream.GetFloatFromStream();
                        rocketLauncherData.NodeIndex =
                            inStream.GetIntFromStream();

                        RocketLauncherList.Add(rocketLauncherData);
                        break;

                    default:
                        throw new ApplicationException(
                            "MapData.LoadFromRavenMap: Attempting to load undefined object");
                }
            }
        }