Example #1
0
 public void Connect(LocationNode n)
 {
     if (!ConnectedNodes.Contains(n))
     {
         ConnectedNodes.Add(n);
     }
 }
Example #2
0
        private List<long> AddKnownBranchesToList(LocationNode loc, List<long> AddedLocations)
        {
            List<long> listKnownBranches = new List<long>(loc.Location.Links.Length);

            listKnownBranches.Add(loc.Location.ID);
            foreach (long locID in loc.Location.Links)
            {
                if (AddedLocations.Contains(locID))
                {
                    listKnownBranches.Add(locID);
                    continue;
                }

            }

            return listKnownBranches;
        }
Example #3
0
    IEnumerator HandleEvent(GameObject goTarget)
    {
        //Debug.Log("Starting event!");
        goTarget.SetActive(true);               //We enable the frogs.

        yield return new WaitForSeconds(5.0f);  //We wait for a moment.

        int layerMask = 1 << 11;
        // This would cast rays only against colliders in layer 11, the Memory Layer.
        // But instead we want to collide against everything except layer 11. The ~ operator does this, it inverts a bitmask.
        layerMask = ~layerMask;

        //Creating the event within the shared event graph.
        //1. We create the core event node.
        //2. We add all the large enemy frogs to the graph, and link them to the event.
        //3. We add the location of the event to the graph, and link it to the event.
        //4. We create the sub-event, and add it to the graph.
        //5. We link the sub-event to the location.
        //6. We add all the small enemy frogs to the graph, and link them to the sub event.
        //7. We then generate the personalised memories for all agents in the area.

        EventNode coreSharedEvent = new EventNode("FrogAttack", new int[] { 3 }, new string[] { "EVN_FrogAttack" });
        MemoryGraphNode coreSharedEventNode = EventManager.Instance.SharedEventGraph.AddNamedNodeToGraph(coreSharedEvent);

        //We populate the shared event graph with info about the event.
        for (int i = 0; i < tLargeFrogs.Length; i++)
        {
            CharacterNode frogNode = new CharacterNode(tLargeFrogs[i].Tag);
            MemoryGraphNode frogEventNode = EventManager.Instance.SharedEventGraph.AddNamedNodeToGraph(frogNode);

            EventManager.Instance.SharedEventGraph.AddUndirectedEdge(coreSharedEventNode, frogEventNode, 11.0f);
        }

        LocationNode lNode = new LocationNode(Locations.SouthernPinnusula);
        MemoryGraphNode locationGraphNode = EventManager.Instance.SharedEventGraph.AddNamedNodeToGraph(lNode);
        EventManager.Instance.SharedEventGraph.AddUndirectedEdge(coreSharedEventNode, locationGraphNode, 11.0f);

        EventNode coreSharedSubEvent = new EventNode("SmallFrogEvent", new int[] { 17 }, new string[] { "Monsters" });
        MemoryGraphNode coreSharedSubEventNode = EventManager.Instance.SharedEventGraph.AddNamedNodeToGraph(coreSharedSubEvent);
        EventManager.Instance.SharedEventGraph.AddUndirectedEdge(coreSharedEventNode, coreSharedSubEventNode, 11.0f);
        EventManager.Instance.SharedEventGraph.AddUndirectedEdge(coreSharedSubEventNode, locationGraphNode, 11.0f);

        for (int i = 0; i < tSmallFrogs.Length; i++)
        {
            CharacterNode frogNode = new CharacterNode(tSmallFrogs[i].Tag);
            MemoryGraphNode frogEventNode = EventManager.Instance.SharedEventGraph.AddNamedNodeToGraph(frogNode);

            EventManager.Instance.SharedEventGraph.AddUndirectedEdge(coreSharedSubEventNode, frogEventNode, 11.0f);
        }

        for (int i = 0; i < AgentManager.Instance.GetAgentCount(); i++)
        {
            CharacterDetails charDetails = AgentManager.Instance.GetAgent(i);
            MemoryGraph charGraph = charDetails.IsPlayer ? charDetails.PlayerAgent.MindsEye.MemoryGraph : charDetails.CognitiveAgent.MindsEye.MemoryGraph;

            EventNode coreEvent = new EventNode("FrogAttack", null, new string[] { "EVN_FrogAttack" });
            MemoryGraphNode coreEventNode = charGraph.AddNamedNodeToGraph(coreEvent);

            string eventLocation = Locations.SouthernPinnusula.ToString();

            bool sawEvent = false;
            int frogCount = 0;
            for (int x = 0; x < tLargeFrogs.Length; x++)
            {
                RaycastHit hit;
                Vector3 direction = tLargeFrogs[x].cTransform.position - charDetails.HeadTarget.position;
                if (Physics.Raycast(charDetails.HeadTarget.position, direction, out hit, Mathf.Infinity, layerMask))
                {
                    //Debug.Log(charDetails.CharCue.UniqueNodeID + " - " + hit.transform.name);
                    EventTag eTag = hit.transform.GetComponent<EventTag>();
                    if (eTag != null && eTag.Tag == tLargeFrogs[x].Tag)
                        ++frogCount;
                }
            }

            MemoryGraphNode largeFrogNode = null;
            if (frogCount > 0)
            {
                sawEvent = true;
                //Create Large Frogs sub-event!
                EventNode largeFrogEvent = new EventNode("LargeFrogEvent", new int[] { frogCount }, new string[] { "Monsters" });
                largeFrogNode = charGraph.AddNamedNodeToGraph(largeFrogEvent);
                charGraph.AddUndirectedEdge(coreEventNode, largeFrogNode, 11.0f, 1.0f);        //Creates a strong connection between the core event and the optional sub-event.  

            }

            //Debug.Log(charDetails.name + " - I saw " + frogCount + " huge frogs!");

            frogCount = 0;
            for (int x = 0; x < tSmallFrogs.Length; x++)
            {
                RaycastHit hit;
                Vector3 direction = tSmallFrogs[x].cTransform.position - charDetails.HeadTarget.position;
                if (Physics.Raycast(charDetails.HeadTarget.position, direction, out hit, direction.magnitude, layerMask))
                {
                    //Debug.Log(charDetails.CharCue.UniqueNodeID + " - " + hit.transform.name);
                    EventTag eTag = hit.transform.GetComponent<EventTag>();

                    //if(eTag != null)
                    //Debug.Log(charDetails.CharCue.UniqueNodeID + " : " + eTag.Tag);

                    if (eTag != null && eTag.Tag == tSmallFrogs[x].Tag)
                        ++frogCount;
                }
            }

            MemoryGraphNode smallFrogNode = null;
            if (frogCount > 0)
            {
                sawEvent = true;
                //Create small frogs sub-event!
                EventNode smallFrogEvent = new EventNode("SmallFrogEvent", new int[] { frogCount }, new string[] { "Monsters" });
                smallFrogNode = charGraph.AddNamedNodeToGraph(smallFrogEvent);
                charGraph.AddUndirectedEdge(coreEventNode, smallFrogNode, 11.0f, 1.0f);        //Creates a strong connection between the core event and the optional sub-event.

            }

            if (sawEvent)
            {
                MemoryGraphNode retainedMemory;
                if (charGraph.Contains(eventLocation) == false)
                    retainedMemory = charGraph.AddNamedNodeToGraph(new LocationNode(Locations.SouthernPinnusula));  //This is a new memory! Add it to our memory graph.
                else
                    retainedMemory = charGraph.GetNamedNodeFromGraph(eventLocation);

                charGraph.UpdateCueOpinion(retainedMemory.MemoryNode, -5.0f);               //The agent will have a strong negative opinion about the area where they attack.
                charGraph.AddUndirectedEdge(coreEventNode, retainedMemory, 11.0f, 1.0f);     //They will also make a strong connection between the area and the frogs.

                if (largeFrogNode != null)
                    charGraph.AddDirectedEdge(largeFrogNode, retainedMemory, 11.0f, 1.0f);          //Creates a strong (but one-way, since we already connect the core event) connection to the location.

                if (smallFrogNode != null)
                    charGraph.AddDirectedEdge(smallFrogNode, retainedMemory, 11.0f, 1.0f);          //Creates a strong (but one-way, since we already connect the core event) connection to the location.
            }
        }

        //We broadcast the Frog Sight Event and create the Shared Events and personalised Sub Events.
        //We also broadcast the start of the event (so people flee).

        yield return new WaitForSeconds(5.0f);

        //We broadcast the end of the event, and hide the frogs again.
        goTarget.SetActive(false);
        //Debug.Log("Ending event!");

        //EventManager.Instance.SharedEventGraph.PrintGraph();
    }
Example #4
0
 public SWCStackData(LocationNode node, SWCType type, long ParentID)
 {
     this.node = node;
     this.Type = type;
     this.ParentID = ParentID;
 }
Example #5
0
        private int WriteLocationEntry(StringBuilder sb, LocationNode node, SWCType Type, long parent)
        {
            const string FormatString = "{0} {1} {2} {3} {4} {5} {6}";

            string outString = string.Format(FormatString, new object[] {NextLineNumber,
                                                      Type.ToString("D"),
                                                      node.Location.VolumePosition.X * 2.18,
                                                      node.Location.VolumePosition.Y * 2.18,
                                                      node.Location.VolumePosition.Z * 90,
                                                      node.Location.Radius,
                                                      parent});
            sb.AppendLine(outString);

            NextLineNumber++;

            return NextLineNumber - 1;
        }
Example #6
0
        private void TraceLocation(StructureGraph graph, LocationNode loc, SWCType Type, long ParentID)
        {
            MasterKnownLocationList.Add(loc.Location.ID);

            int SWCID;

            if (loc.Edges.Count == 1)
            {
                SWCID = WriteLocationEntry(sb, loc, SWCType.END_POINT, ParentID);
            }
            else if (loc.Edges.Count == 2)
            {
                SWCID = WriteLocationEntry(sb, loc, Type, ParentID);
                AddLinks(graph, loc, Type, SWCID);
            }
            else
            {
                SWCID = WriteLocationEntry(sb, loc, SWCType.FORK_POINT, ParentID);

                List<long> NewAddedLocations = AddKnownBranchesToList(loc);
                AddLinks(graph, loc, SWCType.AXON, SWCID);
            }
        }
Example #7
0
        private void AddLinks(StructureGraph graph, LocationNode loc, SWCType Type, long SWCID)
        {
            foreach(long locID in loc.Location.Links)
            {
                if (MasterKnownLocationList.Contains(locID))
                    continue;

                LocationNode node = graph.Nodes[locID];

                queue.Enqueue(new SWCStackData(node, Type, SWCID));
            }
        }
Example #8
0
        private static bool TryFindPlace( string name, out LocationNode outNode  )
        {
            outNode = null;

            var locationNode = (
                from node in LevelNodes.Nodes
                where node.type == ENodeType.LOCATION
                let locNode = node as LocationNode
                where locNode.Name.ToLower().Contains( name.ToLower() )
                select locNode
            ).FirstOrDefault();

            if ( locationNode == null )
                return false;

            outNode = locationNode;
            return true;
        }
Example #9
0
 public void BiConnect(LocationNode fromNode, LocationNode toNode)
 {
     fromNode.Connect(toNode);
     toNode.Connect(fromNode);
 }
Example #10
0
 public void AddNode(LocationNode n)
 {
     m_nodes[n.Name] = n;
 }
Example #11
0
        static public LocationGraph GenerateRouteGraph(String startName,LocationValue startLocation, String endName, LocationValue endLocation, List<WaypointRoute> routes)
        {
            LocationGraph result = new LocationGraph();

            double distanceThreshold = 1.0;

            //List<String> routeNames = new List<string>(this.Keys);
            String name;
            for (int i = 0; i < routes.Count; i++)
            {
                name = routes[i].Name;
                WaypointRoute route = routes[i];
                LocationGraph.LocationNode lastNode = null;
                foreach (Waypoint wp in route)
                {
                    LocationGraph.LocationNode node = new LocationGraph.LocationNode(wp.Name, wp.Location);
                    result.AddNode(node);
                    if (lastNode != null)
                    {
                        result.BiConnect(lastNode, node);
                    }
                    lastNode = node;
                }

                if (i > 0)
                {
                    WaypointRoute lastRoute = routes[i - 1];
                    Boolean done = false;
                    for (int j = 1; j < lastRoute.Count; j++)
                    {
                        if (done) break;
                        for (int k = 1; k < route.Count; k++)
                        {
                            if (done) break;
                            Waypoint lastRouteP1 = lastRoute[j - 1];
                            Waypoint lastRouteP2 = lastRoute[j];
                            Waypoint nextRouteP1 = route[k - 1];
                            Waypoint nextRouteP2 = route[k];
                            LocationValue intersect = BehaviorHelper.LineIntersect(lastRouteP1.Location, lastRouteP2.Location,
                                                                                   nextRouteP1.Location, nextRouteP2.Location);
                            /*if (intersect != null)
                            {
                                string newName = String.Format("Intersection_{0}_{1}_{2}_{3}", lastRouteP1.Name, lastRouteP2.Name, nextRouteP1.Name, nextRouteP2.Name);
                                LocationGraph.LocationNode intersectNode = new LocationGraph.LocationNode(newName, intersect);
                                result.AddNode(intersectNode);
                                result.BiConnect(intersectNode.Name, lastRouteP1.Name);
                                result.BiConnect(intersectNode.Name, lastRouteP2.Name);
                                result.BiConnect(intersectNode.Name, nextRouteP1.Name);
                                result.BiConnect(intersectNode.Name, nextRouteP2.Name);
                            }
                            else*/ 
                            if (BehaviorHelper.Distance(lastRouteP1.Location, nextRouteP1.Location) < distanceThreshold)
                            {
                                result.BiConnect(lastRouteP1.Name, nextRouteP1.Name);
                                done = true;
                            }
                            else if (BehaviorHelper.Distance(lastRouteP1.Location, nextRouteP2.Location) < distanceThreshold)
                            {
                                result.BiConnect(lastRouteP1.Name, nextRouteP2.Name);
                                done = true;
                            }
                            else if (BehaviorHelper.Distance(lastRouteP2.Location, nextRouteP1.Location) < distanceThreshold)
                            {
                                result.BiConnect(lastRouteP2.Name, nextRouteP1.Name);
                                done = true;
                            }
                            else if (BehaviorHelper.Distance(lastRouteP2.Location, nextRouteP2.Location) < distanceThreshold)
                            {
                                result.BiConnect(lastRouteP2.Name, nextRouteP2.Name);
                                done = true;
                            }
                        }
                    }
                }
            }
            

            //result.ProximityConnect(10);
            //result.IntersectConnect();

            LocationNode startNode = new LocationNode(startName, startLocation);
            LocationNode endNode = new LocationNode(endName, endLocation);

            result.InsertByProximity(startNode);
            result.InsertByProximity(endNode);

            return result;
        }
Example #12
0
        //public void ProximityConnect(Double distanceThreshold)
        //{
        //    List<String> workingList = new List<string>(m_nodes.Keys);

        //    while (workingList.Count > 0)
        //    {
        //        String currentNodeName = workingList[0];

        //        workingList.Remove(currentNodeName);
        //        foreach (String workingNodeName in workingList)
        //        {
        //            if (BehaviorHelper.LocationIsEqual(m_nodes[currentNodeName].Location, m_nodes[workingNodeName].Location, distanceThreshold))
        //            {
        //                BiConnect(currentNodeName, workingNodeName);
        //            }
        //        }
        //    }
        //}

        //public void IntersectConnect()
        //{
        //    List<String> workingList = new List<string>(m_nodes.Keys);
        //    while (workingList.Count > 0)
        //    {
        //        String currentNodeName = workingList[0];
        //        LocationNode currentNode = m_nodes[currentNodeName];
        //        workingList.Remove(currentNodeName);
        //        List<LocationNode> connectedNodes = new List<LocationNode>(currentNode.ConnectedNodes);
        //        foreach (LocationNode connectedNode in connectedNodes)
        //        {
        //            foreach (String workingNodeName in workingList)
        //            {
        //                LocationNode workingNode = m_nodes[workingNodeName];
        //                List<LocationNode> connectedNodes2 = new List<LocationNode>(workingNode.ConnectedNodes);
        //                foreach (LocationNode workingConnectedNode in connectedNodes2)
        //                {
        //                    LocationValue intersectLoc = BehaviorHelper.LineIntersect(currentNode.Location, connectedNode.Location,
        //                                                                              workingNode.Location, workingConnectedNode.Location);
        //                    if (intersectLoc != null)
        //                    {
        //                        LocationNode newNode = new LocationNode(String.Format("{0}_{1}_{2}_{3}",currentNode.Name,connectedNode.Name,
        //                                                                workingNode.Name, workingConnectedNode.Name), 
        //                                                                intersectLoc);
        //                        AddNode(newNode);
        //                        BiConnect(currentNode, newNode);
        //                        BiConnect(connectedNode, newNode);
        //                        BiConnect(workingNode, newNode);
        //                        BiConnect(workingConnectedNode, newNode);
        //                    }
        //                }

        //            }
        //        }

                
        //    }
        //}

        void InsertByProximity(LocationNode newNode)
        {
            //find closest node
            List<String> workingList = new List<string>(m_nodes.Keys);
            String closest = workingList[0];
            double distance = BehaviorHelper.Distance(newNode.Location, m_nodes[closest].Location);
            workingList.Remove(closest);

            foreach (String n in workingList)
            {
                double thisDistance = BehaviorHelper.Distance(newNode.Location, m_nodes[n].Location);
                if (thisDistance < distance)
                {
                    closest = n;
                    distance = thisDistance;
                }
            }
            LocationNode closestNode = m_nodes[closest];

            LocationNode otherNode = null;
            LocationValue pointOnLine = null;
            double distanceToPointOnLine = -1;
            foreach (LocationNode node in closestNode.ConnectedNodes)
            {
                if (pointOnLine == null)
                {
                    otherNode = node;
                    pointOnLine = BehaviorHelper.ClosestPointOnLine(newNode.Location, closestNode.Location, node.Location);
                    distanceToPointOnLine = BehaviorHelper.Distance(newNode.Location, pointOnLine);
                }
                else
                {
                    LocationValue l = BehaviorHelper.ClosestPointOnLine(newNode.Location, closestNode.Location, node.Location);
                    double d = BehaviorHelper.Distance(newNode.Location, l);
                    if (d < distanceToPointOnLine)
                    {
                        otherNode = node;
                        pointOnLine = l;
                        distanceToPointOnLine = d;
                    }
                }
            }

            if (distanceToPointOnLine > 5 || true)
            {

                LocationNode insertNode = new LocationNode(String.Format("{0}_{1}_{2}", newNode.Name, closestNode.Name, otherNode.Name),
                                                           pointOnLine);
                AddNode(insertNode);
                BiConnect(insertNode.Name, closestNode.Name);
                BiConnect(insertNode.Name, otherNode.Name);
                AddNode(newNode);
                BiConnect(newNode.Name, insertNode.Name);
            }
            else
            {
                AddNode(newNode);
                BiConnect(newNode.Name, closestNode.Name);
                BiConnect(newNode.Name, otherNode.Name);
            }

        }
Example #13
0
 public SWCStackData(LocationNode node, SWCType type, long ParentID, List<long> KnownLocations)
 {
     this.node = node;
     this.Type = type;
     this.ParentID = ParentID;
     this.KnownLocations = KnownLocations;
 }