private void AddEmptyConnection(LocationNode targetNode) { LocationNodeEdge edge = new LocationNodeEdge(targetNode, null, -1); targetNode.edges.Add(edge); AddExitPoints(targetNode); }
public override void update() { // Fix existing barcode values CswNbtMetaDataObjectClass LocationOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( NbtObjectClass.LocationClass ); foreach( CswNbtMetaDataNodeType LocationNT in LocationOC.getNodeTypes() ) { foreach( CswNbtObjClassLocation LocationNode in LocationNT.getNodes( false, false ) ) { if( false == LocationNode.Barcode.Barcode.StartsWith( "LS" ) ) { LocationNode.Barcode.setBarcodeValue( OverrideExisting: true ); } if( LocationNode.Barcode.SequenceNumber == Int32.MinValue ) { LocationNode.Barcode.resetSequenceNumber(); } if( LocationNode.Barcode.Barcode.Length < 8 ) { string NewBarcodeValue = "LS" + CswTools.PadInt( CswConvert.ToInt32( LocationNode.Barcode.SequenceNumber ), 6 ); LocationNode.Barcode.setBarcodeValueOverride( NewBarcodeValue, false ); } LocationNode.postChanges( false ); } // foreach( CswNbtObjClassLocation LocationNode in LocationNT.getNodes( false, false ) ) } // foreach( CswNbtMetaDataNodeType LocationNT in LocationOC.getNodeTypes() ) } //Update()
public void Connect(LocationNode n) { if (!ConnectedNodes.Contains(n)) { ConnectedNodes.Add(n); } }
//private void UpdateVRTKDestinations(LocationNode targetNode) //{ // for (int index = 0; index < targetNode.edges.Count; index++) // { // //Update the VRTKDestination based on the edge connection end point // targetNode.VRTKDestinations[index].destinationLocation = targetNode.edges[index].endNode.teleportLocation; // targetNode.VRTKDestinations[index].name = "ExitPoint_" + targetNode.edges[index].endNode.name; // } //} //private void UpdateVRTKDestinations(LocationNode targetNode, int index) //{ // //Update the VRTKDestination based on the edge connection end point // targetNode.VRTKDestinations[index].destinationLocation = targetNode.edges[index].endNode.teleportLocation; // targetNode.VRTKDestinations[index].name = "ExitPoint_" + targetNode.edges[index].endNode.name; //} private void UpdateOppositeLocationNodes(LocationNodeEdge targetEdge) { LocationNode oppositeLocationNode = targetEdge.endNode; LocationNode currentNode = targetEdge.startNode; bool hasCorrospondingExitPoint = false; //Does the opposite location node have a corrosponding exitpoint to this current node for (int x = 0; x < oppositeLocationNode.edges.Count; x++) { if (oppositeLocationNode.edges[x].endNode == currentNode) { hasCorrospondingExitPoint = true; oppositeLocationNode.edges[x].weight = targetEdge.weight; } } if (!hasCorrospondingExitPoint) { LocationNodeEdge corrospondingEdge = new LocationNodeEdge(oppositeLocationNode, currentNode, targetEdge.weight); oppositeLocationNode.edges.Add(corrospondingEdge); AddExitPoints(oppositeLocationNode); //UpdateVRTKDestinations(oppositeLocationNode); } }
public void PrintBoard() { tiledisplay = new WorldMapTileGameObject[currWorldMap.sizeX, currWorldMap.sizeY]; locationDisplay = new WorldMapLocationGameObject[currWorldMap.sizeX, currWorldMap.sizeY]; locationDictionary = new Dictionary <string, WorldMapLocationGameObject>(); locationNameDict = new Dictionary <string, WorldMapLocationGameObject>(); for (int x = 0; x < currWorldMap.sizeX; x++) { for (int y = 0; y < currWorldMap.sizeY; y++) { if (currWorldMap.worldMapDisplayData[x, y] != null) { WorldMapTileGameObject tilego = Instantiate <WorldMapTileGameObject>(tileGOPrefab, tileContainer); tilego.InitWorldMapObject(currWorldMap.worldMapDisplayData[x, y]); tiledisplay[x, y] = tilego; tilego.name = x + " " + y; if (currWorldMap.locations[x, y] != null) { //spawn the location LocationNode currNode = currWorldMap.locations[x, y]; WorldMapLocationGameObject go = Instantiate <WorldMapLocationGameObject>(locationPrefab, tileContainer); go.InitGameObject(currNode); locationDisplay[x, y] = go; go.name = x + " " + y; locationDictionary.Add(currNode.MapKey, go); locationNameDict.Add(currNode.AreaName, go); DrawNeighbors(currNode); } } } } }
private LocationNode PopulateTree( LocationNode node, IList <Location> source, IList <MeUser> sourceUsers, IList <UserItem> allUsers) { var sourceChildren = source.Where(l => l.ParentId == node.LocationId).ToList(); var sourceUser = sourceUsers .Where(u => sourceChildren .Any(l => u.Permissions != null && u.Permissions.Any(p => p.LocationId == l.LocationId))) .Select(u => u.UserId); node.Users = sourceUser .Select(u => allUsers.First(a => a.UserId == u)) .ToList(); node.Children = sourceChildren.Select(l => PopulateTree(new LocationNode() { LocationId = l.LocationId, IsMeOffice = l.IsMeOffice, Parent = node, Name = l.Name, }, source, sourceUsers, allUsers)); return(node); }
private LocationNode FindLocation(string name) { if (LocationRootNode == null) { LocationRootNode = this.FindRootNode <LocationNode>(); } return(FindNode(LocationRootNode, node => node.Name.Trim().Equals(name.Trim(), StringComparison.CurrentCultureIgnoreCase))); }
private void AddExitPoints(LocationNode targetNode) { GameObject exitPoint = (GameObject)PrefabUtility.InstantiatePrefab(ExitPointPrefab, targetNode.transform); targetNode.VRTKDestinations.Add(exitPoint.GetComponent <VRTK_DestinationPoint>()); exitPoint.name = "NO_DESTINATION"; exitPoint.transform.localPosition = new Vector3(UnityEngine.Random.Range(-1.0f, 1.0f), 0, UnityEngine.Random.Range(-1.0f, 1.0f));; }
public LocationNode DequeueNode() { LocationNode temp = priorityQueue[0]; priorityQueue.RemoveAt(0); return(temp); }
public void InitGameObject(LocationNode location) { this.location = location; missions = new List <Mission>(); sr.sprite = Resources.Load <SpriteAtlas>(FilePath.TileSetAtlas).GetSprite(location.filepath); transform.position = new Vector3(location.coords.X, location.coords.Y, 0); }
private void UpdateVRTKDestinations(LocationNode targetNode) { for (int index = 0; index < targetNode.edges.Count; index++) { //Update the VRTKDestination based on the edge connection end point targetNode.VRTKDestinations[index].destinationLocation = targetNode.edges[index].endNode.teleportLocation; targetNode.VRTKDestinations[index].name = "ExitPoint_" + targetNode.edges[index].endNode.name; } }
/// <summary> /// Validates the Location Node argument /// </summary> /// <param name="LocationNode">The Location Node to validate</param> /// <param name="Culture">The culture in which any exception messages should be thrown</param> internal static void ValidateLocationNode(LocationNode LocationNode, CultureInfo Culture) { ResourceManager ExceptionMessageResources = new ResourceManager("GroundFrame.Core.Resources.ExceptionResources", Assembly.GetExecutingAssembly()); if (LocationNode == null) { throw new ArgumentNullException(ExceptionMessageResources.GetString("InvalidLocationNodeArgument", Culture)); } }
/// <summary> /// Builds a new scene containing a location dungeon. /// </summary> /// <param name="regionName">Region name.</param> /// <param name="locationName">Location name.</param> public void CreateDungeonLocationScene(string regionName, string locationName) { // Check if resulting scene will be the same if (this.location.RegionName == regionName && this.location.Name == locationName && this.sceneType == SceneTypes.Dungeon) { return; } // Create location node host.Core.Scene.ResetScene(); host.Core.Renderer.BackgroundColor = generalBackgroundColor; LocationNode node = host.Core.SceneBuilder.CreateDungeonLocationNode(regionName, locationName); if (node == null) { return; } // Store data this.location = node.Location; this.sceneType = SceneTypes.Dungeon; base.Climate = null; // Add node to scene host.Core.Scene.AddNode(null, node); // Update scene so bounds are correct host.Core.Scene.Update(TimeSpan.MinValue); // Set custom movement bounds Vector3 center = host.Core.Scene.Root.TransformedBounds.Center; float radius = host.Core.Scene.Root.TransformedBounds.Radius; BoundingBox movementBounds = new BoundingBox( new Vector3(center.X - radius, center.Y - radius, center.Z - radius), new Vector3(center.X + radius, center.Y + radius, center.Z + radius)); topDownCamera.MovementBounds = movementBounds; freeCamera.MovementBounds = movementBounds; // Position top-down camera topDownCamera.CentreInBounds(topDownCameraStartHeight); // Position free camera freeCamera.Reference = Vector3.Forward; freeCamera.Position = new Vector3( center.X + SceneBuilder.RDBSide / 2, center.Y, movementBounds.Max.Z - SceneBuilder.RDBSide / 2); // Update camera UpdateCamera(); // Set status message currentStatus = string.Format("Exploring {0} (Dungeon).", locationName); }
private void ImportLocation(Stream input) { var collection = this.GetMonCollection <LocationNode>(); var package = new ExcelPackage(input); var sheet = package.Workbook.Worksheets.FirstOrDefault(); if (sheet == null) { throw new InvalidOperationException("There is no sheet in excel file!"); } var values = (object[, ])sheet.Cells.Value; var rows = values.GetUpperBound(0) + 1; var columns = values.GetUpperBound(1) + 1; var account = this.CurrentAccount(); var root = new LocationNode() { Account = account, Name = "root" }; for (var row = 1; row <= rows; ++row) { var parent = root; for (var column = 1; column <= columns; ++column) { var cell = sheet.Cells[row, column]; var value = cell.Value; var name = value?.ToString(); if (name == null) { parent = parent.Children.Last(); continue; } var node = new LocationNode() { Account = account, Name = name }; parent.Children.Add(node); } } var found = collection.FindOne(x => x.Account.Id.Equals(account.Id)); if (found == null) { collection.InsertOne(root); } else { root.Id = found.Id; collection.ReplaceOne(x => x.Id.Equals(found.Id), root); } }
private void BuildLocationList(Story story, LocationNode node, List <int> locationList) { if (node.Id != -1) { locationList.Add(node.Id); } foreach (LocationNode childNode in node.Children) { BuildLocationList(story, childNode, locationList); } }
//If a ExitPoint containing the VRTKDestination was deleted, remove the corrosponding edge private void RemoveNulls(LocationNode targetNode) { for (int x = targetNode.VRTKDestinations.Count - 1; x >= 0; x--) { if (targetNode.VRTKDestinations[x] == null) { targetNode.VRTKDestinations.RemoveAt(x); targetNode.edges.RemoveAt(x); } } }
/// <summary> /// Creates all the path edges from the list of LocationMappers /// </summary> /// <returns></returns> private async Task CreatePathEdgesFromMap(SimulationExtension SimExt) { await Task.Run(() => { //SimSig.SimulationExtension SimExt = new SimulationExtension(this._Simulation.ID, this._SQLConnector); foreach (MapperLocationNode MappedLocNode in this._LocationNodeMapper) { LocationNode FromLocationNode = null; //Check the MappedLocNode has a next location node to create if (string.IsNullOrEmpty(MappedLocNode.NextLocationNode.SimSigCode) == false) { //Get a list of MapperLocationNode objects with a location node created List <MapperLocationNode> MappersWithLocationNodes = this._LocationNodeMapper.Where(y => y.LocationNode != null).ToList(); //Get the From Location Node if (MappedLocNode.LocationNode == null) { //If not already tagged in the MapperLocationNode search through the list to find it FromLocationNode = MappersWithLocationNodes.Find(x => x.LocationNode.SimID == this._Simulation.ID && x.LocationNode.EraID == this._TemplateSimEra.ID && x.LocationNode.Version.ID == this._Version.ID && String.CompareOrdinal(x.LocationNode.LocationSimSigCode, MappedLocNode.SimSigCode) == 0 && String.CompareOrdinal(x.LocationNode.Platform, MappedLocNode.Platform) == 0 && String.CompareOrdinal(x.LocationNode.Path, MappedLocNode.Path) == 0 && String.CompareOrdinal(x.LocationNode.Line, MappedLocNode.Line) == 0).LocationNode; } else { FromLocationNode = MappedLocNode.LocationNode; } //Get the to location node LocationNode ToNodeLocation = MappersWithLocationNodes.FirstOrDefault(x => x.LocationNode.SimID == this._Simulation.ID && x.LocationNode.EraID == this._TemplateSimEra.ID && x.LocationNode.Version.ID == this._Version.ID && String.CompareOrdinal(x.LocationNode.LocationSimSigCode, MappedLocNode.NextLocationNode.SimSigCode) == 0 && String.CompareOrdinal(x.LocationNode.Platform, MappedLocNode.NextLocationNode.Platform) == 0 && String.CompareOrdinal(x.LocationNode.Path, MappedLocNode.NextLocationNode.Path) == 0 && String.CompareOrdinal(x.LocationNode.Line, MappedLocNode.NextLocationNode.Line) == 0).LocationNode; //Create the path edge if (ToNodeLocation != null) { //Build new LocationNode SimSig.PathEdge NewPathEdge = new PathEdge(FromLocationNode, ToNodeLocation, this._SQLConnector); NewPathEdge.SaveToSQLDB(); } } } }).ConfigureAwait(false); }
public override LocationNode AccessLocal(Function function, LocationNode stackFrame) { if (function == _owningFunction) { return(new MemoryNode(new SubOperatorNode(stackFrame, new ConstantNode <long>(_offsetFromStackFrame)))); } else { return(AccessLocal(function.EnclosedIn, function.GetEnclosingFunctionStackFrame())); } }
private static bool TryFindPlace(string name, out LocationNode outNode) { outNode = ( 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(); return(outNode != null); }
public void Enqueue(LocationNode node) { for (int i = 0; i < priorityQueue.Count; i++) { if (node.priority < priorityQueue[i].priority) { priorityQueue.Insert(i, node); return; } } priorityQueue.Add(node); }
private void AddNewConnection() { GameObject newLocation = new GameObject("RENAME_ME"); LocationNode newNode = newLocation.AddComponent <LocationNode>(); LocationNodeEdge edge = new LocationNodeEdge(targetNode, newNode, -1); LocationNodeEdge edgeReversed = new LocationNodeEdge(newNode, targetNode, -1); targetNode.edges.Add(edge); newNode.edges.Add(edgeReversed); }
public LocationResponse GetTree() { var sourceUsers = _userStore.Query().ToList(); var permissedLocations = sourceUsers .Where(u => u.Permissions != null) .SelectMany(u => u.Permissions.Select(p => p.LocationId)).Distinct().ToList(); var offices = _locationStore .Query() .Where(l => l.IsMeOffice || // Is office permissedLocations.Contains(l.LocationId)) // Or user has it assigned via permission .ToList(); var allLocations = GetPath(offices); var allUsers = sourceUsers.Select(u => new UserItem() { UserId = u.UserId, FullName = u.FullName() }).ToList(); var result = new LocationResponse(); var roots = new List <LocationNode>(); result.Roots = roots; var sourceRoots = allLocations.Where(l => l.ParentId == null).ToList(); foreach (var sourceRoot in sourceRoots) { var rootNode = new LocationNode() { LocationId = sourceRoot.LocationId, Name = sourceRoot.Name, }; PopulateTree(rootNode, allLocations, sourceUsers, allUsers); roots.Add(rootNode); } /*result.Locations = allLocations.Select(l => new LocationNode() * { * LocationId = l.LocationId, * Name = l.Name * }).ToList();*/ return(result); }
public void readEdgeTable(LocationNode graph, Location[] locArray) { command.CommandText = "select * from EdgeTable"; conn.Close(); conn.Open(); command.Connection = conn; OleDbDataReader reader = command.ExecuteReader(); while (reader.Read()) { graph.addEdge(Convert.ToInt32(reader[0]), Convert.ToInt32(reader[1]), locArray); } }
// Draws the lines between all the neighboring nodes // private void DrawNeighbors(LocationNode currNode) { List <MapCoords> neighbors = currNode.neighbors; foreach (MapCoords loc in neighbors) { if (locationDisplay[loc.X, loc.Y] != null) { LineTest line = Instantiate <LineTest>(linePrefab); line.SetEndPoints(locationDisplay[currNode.coords.X, currNode.coords.Y].gameObject, locationDisplay[loc.X, loc.Y].gameObject); line.InitLine(); } } }
public void UpdataLocationNodeInfo(WorldMapLocationGameObject node) { if (node == null) { gameObject.SetActive(false); return; } gameObject.SetActive(true); currentNodeGO = node; currentNode = node.location; PrintInfo(); }
public List <LocationData> GetLocation() { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(HttpContext.Current.Server.MapPath("../../Data/Locations.xml")); List <LocationData> data = new List <LocationData>(); foreach (XmlNode LocationNode in xmlDoc.SelectNodes("Locations/location")) { string Code = LocationNode.SelectSingleNode("Code").InnerText; string Name = LocationNode.SelectSingleNode("Name").InnerText; data.Add(new LocationData(Code, Name)); } return(data); }
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; }
// Token: 0x06000149 RID: 329 RVA: 0x0000ECD0 File Offset: 0x0000CED0 public static LocationNode GetClosestLocation(Vector3 pos) { float num = 1337420f; LocationNode result = null; foreach (LocationNode locationNode in (from n in LevelNodes.nodes where n.type == ENodeType.LOCATION select(LocationNode) n).ToArray <LocationNode>()) { float num2 = Vector3.Distance(pos, locationNode.point); if (num2 < num) { num = num2; result = locationNode; } } return(result); }
public override void update() { // Fix bugs introduced in Othello's CswUpdateSchemaCase25981.cs // Remove erroneous extra value string Sql = @"delete from jct_nodes_props where jctnodepropid in (select j.jctnodepropid from jct_nodes_props j join nodetype_props p on j.nodetypepropid = p.nodetypepropid join nodes n on j.nodeid = n.nodeid join nodetypes t1 on p.nodetypeid = t1.nodetypeid join nodetypes t2 on n.nodetypeid = t2.nodetypeid where t1.nodetypeid <> t2.nodetypeid)"; _CswNbtSchemaModTrnsctn.execArbitraryPlatformNeutralSql( Sql ); // Set up Lab 2 correctly CswNbtMetaDataObjectClass LocationOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( CswNbtMetaDataObjectClass.NbtObjectClass.LocationClass ); Collection<CswNbtNode> LocationNodes = LocationOC.getNodes( false, true ); CswNbtObjClassLocation LocationNRL = null; foreach( CswNbtObjClassLocation LocationNode in LocationNodes ) { if( LocationNode.Name.Text == "North Research Lab" ) { LocationNRL = LocationNode; } } // foreach( CswNbtObjClassLocation LocationNode in LocationNodes ) if( LocationNRL != null ) { foreach( CswNbtObjClassLocation LocationNode in LocationNodes ) { if( LocationNode.Name.Text == string.Empty && LocationNode.IsDemo ) { LocationNode.Name.Text = "Lab 2"; LocationNode.Location.SelectedNodeId = LocationNRL.NodeId; LocationNode.postChanges( true ); } } // foreach( CswNbtObjClassLocation LocationNode in LocationNodes ) } // if( LocationNRL != null ) }//Update()
public override void update() { // Set 'Allow Inventory' on Room location and below CswNbtMetaDataObjectClass LocationOC = _CswNbtSchemaModTrnsctn.MetaData.getObjectClass( CswNbtMetaDataObjectClass.NbtObjectClass.LocationClass ); CswNbtMetaDataObjectClassProp LocationAllowInvOCP = LocationOC.getObjectClassProp( CswNbtObjClassLocation.AllowInventoryPropertyName); // Make it required _CswNbtSchemaModTrnsctn.MetaData.UpdateObjectClassProp( LocationAllowInvOCP, CswNbtMetaDataObjectClassProp.ObjectClassPropAttributes.isrequired, true ); // Default values on nodetypes foreach( CswNbtMetaDataNodeType LocationNT in LocationOC.getNodeTypes() ) { CswNbtMetaDataNodeTypeProp LocationAllowInvNTP = LocationNT.getNodeTypePropByObjectClassProp( CswNbtObjClassLocation.AllowInventoryPropertyName ); if( LocationNT.NodeTypeName == "Room" || LocationNT.NodeTypeName == "Cabinet" || LocationNT.NodeTypeName == "Shelf" || LocationNT.NodeTypeName == "Box" ) { LocationAllowInvNTP.DefaultValue.AsLogical.Checked = Tristate.True; } else { LocationAllowInvNTP.DefaultValue.AsLogical.Checked = Tristate.False; } } // Values for existing nodes foreach(CswNbtObjClassLocation LocationNode in LocationOC.getNodes(false, true)) { if( LocationNode.NodeType.NodeTypeName == "Room" || LocationNode.NodeType.NodeTypeName == "Cabinet" || LocationNode.NodeType.NodeTypeName == "Shelf" || LocationNode.NodeType.NodeTypeName == "Box" ) { LocationNode.AllowInventory.Checked = Tristate.True; } else { LocationNode.AllowInventory.Checked = Tristate.False; } LocationNode.postChanges(false); } // foreach(CswNbtObjClassLocation in LocationOC.getNodes(false, true)) }//Update()
public static LocationNode GetClosestLocation(Vector3 pos) { double num = 1337420.0; LocationNode result = null; foreach (LocationNode locationNode in (from n in LevelNodes.nodes where n.type == ENodeType.LOCATION select(LocationNode) n).ToArray <LocationNode>()) { double distance = VectorUtilities.GetDistance(pos, locationNode.point); bool flag = distance < num; if (flag) { num = distance; result = locationNode; } } return(result); }
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; }
public SWCStackData(LocationNode node, SWCType type, long ParentID, List<long> KnownLocations) { this.node = node; this.Type = type; this.ParentID = ParentID; this.KnownLocations = KnownLocations; }
//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); } }
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; }
public void AddNode(LocationNode n) { m_nodes[n.Name] = n; }
public void BiConnect(LocationNode fromNode, LocationNode toNode) { fromNode.Connect(toNode); toNode.Connect(fromNode); }
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(); }
public SWCStackData(LocationNode node, SWCType type, long ParentID) { this.node = node; this.Type = type; this.ParentID = ParentID; }
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; }
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); } }
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)); } }