public bool SetDead(bool sfx) { // check if "alive" if (IsDead || Class.DeadObject < 0 || Class.DeadObject == Class.ID) { return(false); } IsDead = true; NeedDeathSFX = sfx; WasDead = false; // set current class id to deadobject. ObstacleClass deadClass = ObstacleClassLoader.GetObstacleClassById(Class.DeadObject); if (deadClass == null) { return(false); } Class = deadClass; CurrentFrame = 0; CurrentTime = 0; DoUpdateView = true; return(true); }
public bool SetDead(bool sfx) { // check if "alive" if (IsDead || Class.DeadObject < 0 || Class.DeadObject == Class.ID) { return(false); } IsDead = true; // spawn dead sfx. if (sfx) { Server.SpawnProjectileSimple(AllodsProjectile.FireWall, null, X + 0.5f, Y + 0.5f, 0, 1); } // set current class id to deadobject. ObstacleClass deadClass = ObstacleClassLoader.GetObstacleClassById(Class.DeadObject); if (deadClass == null) { return(false); } Class = deadClass; CurrentFrame = 0; CurrentTime = 0; DoUpdateView = true; return(true); }
private ObstacleClass GenerateObstacleData(GameObject obstacle) { ObstacleClass retObstacle = new ObstacleClass(); retObstacle.typeOfObstacle = obstacle.name.Split('(')[0]; retObstacle.tag = obstacle.tag; retObstacle.position = new float[3] { obstacle.transform.position.x, obstacle.transform.position.y, obstacle.transform.position.z }; retObstacle.rotation = new float[4] { obstacle.transform.rotation.x, obstacle.transform.rotation.y, obstacle.transform.rotation.z, obstacle.transform.rotation.w }; retObstacle.scale = new float[3] { obstacle.transform.localScale.x, obstacle.transform.localScale.y, obstacle.transform.localScale.z }; return(retObstacle); }
public MapObstacle(string name) { Class = ObstacleClassLoader.GetObstacleClassByName(name); if (Class == null) { Debug.LogFormat("Invalid obstacle created (name={0})", name); } else { InitObstacle(); } }
public MapObstacle(int typeId) { Class = ObstacleClassLoader.GetObstacleClassById(typeId); if (Class == null) { Debug.LogFormat("Invalid obstacle created (typeId={0})", typeId); } else { InitObstacle(); } }
bool checkThreshold(Collider col) { ObstacleClass obstacle = col.GetComponent <ObstacleClass>(); if (obstacle != null) { if (obstacle.weight < grabThreshold) { return(true); } } return(false); }
private GameObject FindObstacleInstance(ObstacleClass obstacleData) { GameObject tool = null; for (int i = 0; i < toolList.Length; i++) { if (toolList[i].name.Equals(obstacleData.typeOfObstacle)) { tool = toolList[i]; break; } } return(tool); }
public static Obstacle[] allOfClass(ObstacleClass obsClass) { switch (obsClass) { case ObstacleClass.Nature: return(new Obstacle[] { underbrush(), tree() }); case ObstacleClass.Monster: return(new Obstacle[] { hound(), monkey() }); default: return(defaultPackage()); } }
private GameObject GenerateClone(ObstacleClass obstacleData, GameObject instanceOfObstacle) { GameObject obstacle; if (instanceOfObstacle != null) { Vector3 position = new Vector3( obstacleData.position[0], obstacleData.position[1], obstacleData.position[2] ); Quaternion rotation = new Quaternion( obstacleData.rotation[0], obstacleData.rotation[1], obstacleData.rotation[2], obstacleData.rotation[3] ); Vector3 scale = new Vector3( obstacleData.scale[0], obstacleData.scale[1], obstacleData.scale[2] ); obstacle = Instantiate(instanceOfObstacle, position, rotation); DontDestroyOnLoad(obstacle); obstacle.transform.localScale = scale; obstacle.tag = obstacleData.tag; obstacle.GetComponent <MeshRenderer>().enabled = true; return(obstacle); } else { return(null); } }
private Obstacle FindIntersectingCluster(Coordinates pt, ObstacleClass targetClass, List <Obstacle> previousObstacles) { int max_age = 0; double min_area = double.MaxValue; Obstacle best_obs = null; foreach (Obstacle obs in previousObstacles) { // check if we're in the bounding circle and then polygon if (obs.obstacleClass == targetClass && obs.mergePolygon.BoundingCircle.IsInside(pt) && obs.mergePolygon.IsInside(pt)) { // we're inside the polygon // check if this is a better match if (obs.age > max_age || (obs.age == max_age && obs.mergePolygon.GetArea() < min_area)) { best_obs = obs; max_age = obs.age; min_area = obs.mergePolygon.GetArea(); } } } return(best_obs); }
public static void InitClasses() { if (ClassesLoaded) { return; } ClassesLoaded = true; Registry reg = new Registry("graphics/objects/objects.reg"); int ObjectCount = reg.GetInt("Global", "ObjectCount", 0); int FileCount = reg.GetInt("Global", "FileCount", 0); for (int i = 0; i < FileCount; i++) { string filename = reg.GetString("Files", string.Format("File{0}", i), ""); ObstacleFile file = new ObstacleFile(); file.FileName = "graphics/objects/" + filename.Replace('\\', '/'); Files.Add(file); } for (int i = 0; i < ObjectCount; i++) { string on = string.Format("Object{0}", i); ObstacleClass cls = new ObstacleClass(); //cls.DescText = RegistryUtil.GetWithParent<string>(reg, on, "DescText", ""); cls.DescText = reg.GetString(on, "DescText", ""); cls.ID = reg.GetInt(on, "ID", ObstacleClass.MagicIntNull); //int file = RegistryUtil.GetWithParent<int>(reg, on, "File", -1); int file = reg.GetInt(on, "File", ObstacleClass.MagicIntNull); if (file >= 0 && file < Files.Count) { cls.File = Files[file]; } //cls.Index = RegistryUtil.GetWithParent<int>(reg, on, "Index", 0); cls.Index = reg.GetInt(on, "Index", ObstacleClass.MagicIntNull); int centerx = reg.GetInt(on, "CenterX", -1); int centery = reg.GetInt(on, "CenterY", -1); int width = reg.GetInt(on, "Width", 128); int height = reg.GetInt(on, "Height", 128); cls.CenterX = (centerx < 0) ? -2 : (float)centerx / width; cls.CenterY = (centerx < 0) ? -2 : (float)centery / height; cls.DeadObject = reg.GetInt(on, "DeadObject", ObstacleClass.MagicIntNull); cls.Parent = reg.GetInt(on, "Parent", ObstacleClass.MagicIntNull); int phases = reg.GetInt(on, "Phases", ObstacleClass.MagicIntNull); if (phases == 1) { cls.Frames = new ObstacleClass.AnimationFrame[1]; cls.Frames[0].Frame = 0; cls.Frames[0].Time = 0; } else { int[] animationtime = reg.GetArray(on, "AnimationTime", null); int[] animationframe = reg.GetArray(on, "AnimationFrame", null); if (animationtime != null && animationframe != null && animationtime.Length == animationframe.Length) { cls.Frames = new ObstacleClass.AnimationFrame[animationtime.Length]; for (int j = 0; j < cls.Frames.Length; j++) { cls.Frames[j].Time = animationtime[j]; cls.Frames[j].Frame = animationframe[j]; } } else if (phases > 0) { cls.Frames = new ObstacleClass.AnimationFrame[1]; cls.Frames[0].Frame = 0; cls.Frames[0].Time = 0; } else { cls.Frames = null; } } //Debug.Log(string.Format("object {0} ({1}) frames = {2}", on, cls.DescText.Trim(), cls.Frames.Length)); Classes.Add(cls); } foreach (ObstacleClass cls in Classes) { int id = cls.Parent; while (id != -1) { ObstacleClass clsp = null; foreach (ObstacleClass clsp_ in Classes) { if (clsp_.ID == id) { clsp = clsp_; break; } } if (clsp == null) { break; } if (cls.Frames == null) { cls.Frames = clsp.Frames; } if (cls.DeadObject == ObstacleClass.MagicIntNull) { cls.DeadObject = clsp.DeadObject; } if (cls.Index == ObstacleClass.MagicIntNull) { cls.Index = clsp.Index; } if (cls.CenterX == -2) { cls.CenterX = clsp.CenterX; } if (cls.CenterY == -2) { cls.CenterY = clsp.CenterY; } id = clsp.Parent; } } foreach (ObstacleClass cls in Classes) { if (cls.Index == ObstacleClass.MagicIntNull) { cls.Index = 1; } if (cls.DeadObject == ObstacleClass.MagicIntNull) { cls.DeadObject = -1; } if (cls.Frames == null) { cls.Frames = new ObstacleClass.AnimationFrame[1]; cls.Frames[0].Frame = 0; cls.Frames[0].Time = 0; } if (cls.CenterX == -2) { cls.CenterX = 0; } if (cls.CenterY == -2) { cls.CenterY = 0; } } }
private Obstacle FindIntersectingCluster(Coordinates pt, ObstacleClass targetClass, List<Obstacle> previousObstacles) { int max_age = 0; double min_area = double.MaxValue; Obstacle best_obs = null; foreach (Obstacle obs in previousObstacles) { // check if we're in the bounding circle and then polygon if (obs.obstacleClass == targetClass && obs.mergePolygon.BoundingCircle.IsInside(pt) && obs.mergePolygon.IsInside(pt)) { // we're inside the polygon // check if this is a better match if (obs.age > max_age || (obs.age == max_age && obs.mergePolygon.GetArea() < min_area)) { best_obs = obs; max_age = obs.age; min_area = obs.mergePolygon.GetArea(); } } } return best_obs; }
protected void SetPlaceHolderByStreet(int staticNum, int dynamicNum) { List <PlaceHolder> staticList = GetPlaceHolderList(staticNum * streetsList.Count, ObstacleClass.Static); List <PlaceHolder> dynamicList = GetPlaceHolderList(dynamicNum * streetsList.Count, ObstacleClass.Dynamic); int tokenCount = 0; foreach (Token token in streetsList) { ObstacleClass[] obsInToken = new ObstacleClass[staticNum + dynamicNum]; List <int> index = new List <int>(); //static/dynamic per token for (int i = 0; i < obsInToken.Length; i++) { if (i < staticNum) { obsInToken[i] = ObstacleClass.Static; } else { obsInToken[i] = ObstacleClass.Dynamic; } index.Add(i); } //scrumble List <int> rndIndex = new List <int>(); rndIndex.AddRange(index); if (rndIndex.Count > 1) { for (int i = 0; i < rndIndex.Count; i++) { int ri = Random.Range(0, 10000) % index.Count; rndIndex[i] = index[ri]; index.Remove(index[ri]); } } int staticCounter = 0; int dynamicCounter = 0; for (int i = 0; i < obsInToken.Length; i++) { int idx = rndIndex[i]; ObstacleClass obj = obsInToken[idx]; PlaceHolder placeHolder; //float trasversal; if (obj == ObstacleClass.Static) { placeHolder = staticList[(tokenCount * staticNum) + staticCounter]; staticCounter++; } else { placeHolder = dynamicList[(tokenCount * dynamicNum) + dynamicCounter]; dynamicCounter++; } AddPlaceHolderByToken(token, placeHolder); } tokenCount++; } }
protected List <PlaceHolder> GetPlaceHolderList(int num, ObstacleClass oClass) { int maxPercent = 0; int[] indexList = new int[num]; int listBaseIndex = 0; int maxIndex = 0; int maxValue = 0; ObstacleItem[] sources; if (oClass == ObstacleClass.Static) { sources = new ObstacleItem[obstacleSources.Length]; obstacleSources.CopyTo(sources, 0); } else { sources = new ObstacleItem[dinamicSources.Length]; dinamicSources.CopyTo(sources, 0); } for (int obsIndex = 0; obsIndex < sources.Length; obsIndex++) { ObstacleItem item = sources[obsIndex]; if (item.percentage > maxValue) { maxValue = item.percentage; maxIndex = obsIndex; } maxPercent += item.percentage; } //firstpass for (int obsIndex = 0; obsIndex < sources.Length; obsIndex++) { ObstacleItem item = sources[obsIndex]; item.Weight = item.percentage / (float)maxPercent; int firstPassTotal = Mathf.FloorToInt(item.Weight * num); int i = 0; for (i = 0; i < firstPassTotal; i++) { indexList[listBaseIndex + i] = obsIndex; item.TotalInScene++; } listBaseIndex += i; } //secondpass if (listBaseIndex < num) { int difference = num - listBaseIndex; for (int i = 0; i < difference; i++) { indexList[listBaseIndex + i] = maxIndex; sources[maxIndex].TotalInScene++; } } //scrumble List <int> supportList = new List <int>(indexList); List <PlaceHolder> returnList = new List <PlaceHolder>(); for (int i = 0; i < indexList.Length; i++) { int randomIdx = Random.Range(0, supportList.Count); int sourceIndex = supportList[randomIdx]; supportList.RemoveAt(randomIdx); PlaceHolder pl = new PlaceHolder(); ObstacleItem item = sources[sourceIndex]; pl.item = item; returnList.Add(pl); } return(returnList); }
protected void SetPlaceHolderByCity(int staticNum, int dynamicNum) { List <PlaceHolder> staticList = GetPlaceHolderList(staticNum, ObstacleClass.Static); List <PlaceHolder> dynamicList = GetPlaceHolderList(dynamicNum, ObstacleClass.Dynamic); List <int> indexList = new List <int>(); int[] countTokenList = new int[streetsList.Count]; for (int i = 0; i < countTokenList.Length; i++) { countTokenList[i] = 0; } for (int i = 0; i < staticNum + dynamicNum; i++) { if (indexList.Count <= 0) { for (int index = 0; index < streetsList.Count; index++) { indexList.Add(index); } } int randomIdx = Random.Range(0, indexList.Count); countTokenList[indexList[randomIdx]]++; indexList.RemoveAt(randomIdx); } ObstacleClass[] obsInCity = new ObstacleClass[staticNum + dynamicNum]; List <int> indexes = new List <int>(); //static/dynamic per token for (int i = 0; i < obsInCity.Length; i++) { if (i < staticNum) { obsInCity[i] = ObstacleClass.Static; } else { obsInCity[i] = ObstacleClass.Dynamic; } indexes.Add(i); } //scrumble List <int> rndIndex = new List <int>(); rndIndex.AddRange(indexes); if (rndIndex.Count > 1) { for (int i = 0; i < rndIndex.Count; i++) { int ri = Random.Range(0, 10000) % indexes.Count; rndIndex[i] = indexes[ri]; indexes.Remove(indexes[ri]); } } int staticCounter = 0; int dynamicCounter = 0; int counter = 0; for (int i = 0; i < countTokenList.Length; i++) { for (int j = 0; j < countTokenList[i]; j++) { int idx = rndIndex[counter]; counter++; ObstacleClass obj = obsInCity[idx]; PlaceHolder placeHolder; if (obj == ObstacleClass.Static) { placeHolder = staticList[staticCounter]; staticCounter++; } else { placeHolder = dynamicList[dynamicCounter]; dynamicCounter++; } AddPlaceHolderByToken(streetsList[i], placeHolder); } } }
private List <Obstacle> ProcessTrackedClusters(SceneEstimatorTrackedClusterCollection clusters, Rect vehicleBox) { List <Obstacle> obstacles = new List <Obstacle>(clusters.clusters.Length); // get the list of previous id's SortedList <int, Obstacle> previousID; if (processedObstacles != null) { previousID = new SortedList <int, Obstacle>(processedObstacles.obstacles.Count); foreach (Obstacle obs in processedObstacles.obstacles) { if (obs != null && obs.trackID != -1 && !previousID.ContainsKey(obs.trackID)) { previousID.Add(obs.trackID, obs); } } } else { previousID = new SortedList <int, Obstacle>(); } List <Coordinates> goodPoints = new List <Coordinates>(1500); Circle mergeCircle = new Circle(merge_expansion_size, Coordinates.Zero); Polygon mergePolygon = mergeCircle.ToPolygon(24); foreach (SceneEstimatorTrackedCluster cluster in clusters.clusters) { // ignore deleted targets if (cluster.statusFlag == SceneEstimatorTargetStatusFlag.TARGET_STATE_DELETED || cluster.statusFlag == SceneEstimatorTargetStatusFlag.TARGET_STATE_OCCLUDED_FULL || cluster.relativePoints == null || cluster.relativePoints.Length < 3) { continue; } Obstacle obs = new Obstacle(); obs.trackID = cluster.id; obs.speed = cluster.speed; obs.speedValid = cluster.speedValid; obs.occuluded = cluster.statusFlag != SceneEstimatorTargetStatusFlag.TARGET_STATE_ACTIVE; // update the age Obstacle prevTrack = null; previousID.TryGetValue(cluster.id, out prevTrack); goodPoints.Clear(); int numOccupancyDeleted = 0; foreach (Coordinates pt in cluster.relativePoints) { if (!vehicleBox.IsInside(pt)) { if (useOccupancyGrid && Services.OccupancyGrid.GetOccupancy(pt) == OccupancyStatus.Free) { occupancyDeletedCount++; numOccupancyDeleted++; } else { goodPoints.Add(pt); } } } if (goodPoints.Count < 3) { continue; } IList <Polygon> polys; if (obs.occuluded && numOccupancyDeleted > 0) { polys = WrapAndSplit(goodPoints, 1, 2.5); } else { polys = new Polygon[] { Polygon.GrahamScan(goodPoints) }; } obs.absoluteHeadingValid = cluster.headingValid; obs.absoluteHeading = cluster.absoluteHeading; // set the obstacle polygon for calculate obstacle distance Polygon obsPoly = Polygon.GrahamScan(goodPoints); double targetDistance = GetObstacleDistance(obsPoly); ObstacleClass impliedClass = ObstacleClass.DynamicUnknown; switch (cluster.targetClass) { case SceneEstimatorTargetClass.TARGET_CLASS_CARLIKE: if (cluster.isStopped) { impliedClass = ObstacleClass.DynamicStopped; } else { impliedClass = ObstacleClass.DynamicCarlike; } break; case SceneEstimatorTargetClass.TARGET_CLASS_NOTCARLIKE: impliedClass = ObstacleClass.DynamicNotCarlike; break; case SceneEstimatorTargetClass.TARGET_CLASS_UNKNOWN: impliedClass = ObstacleClass.DynamicUnknown; break; } if (prevTrack == null) { obs.age = 1; // we haven't seen this track before, determine what the implied class is if (targetDistance < target_class_ignore_dist) { impliedClass = ObstacleClass.DynamicUnknown; } } else { obs.age = prevTrack.age + 1; // if we've seen this target before and we've labelled it as unknown and it is labelled as car-like now, check the distance if (prevTrack.obstacleClass == ObstacleClass.DynamicUnknown && targetDistance < target_class_ignore_dist && obs.age < target_class_ignore_age) { impliedClass = ObstacleClass.DynamicUnknown; } } // get the off-road percentage double offRoadPercent = GetPercentOffRoad(obs.obstaclePolygon); if (offRoadPercent > 0.65) { obs.offroadAge = obs.age; } // now check if we're labelling the obstacle as car-like if it has been off-road in the last second if ((impliedClass == ObstacleClass.DynamicCarlike || impliedClass == ObstacleClass.DynamicStopped) && (obs.age - obs.offroadAge) > 10 && obs.offroadAge > 0) { // label as not car like impliedClass = ObstacleClass.DynamicNotCarlike; } obs.obstacleClass = impliedClass; foreach (Polygon poly in polys) { Obstacle newObs = obs.ShallowClone(); newObs.obstaclePolygon = poly; // determine what to do with the cluster if (cluster.targetClass == SceneEstimatorTargetClass.TARGET_CLASS_CARLIKE && !cluster.isStopped) { // if the heading is valid, extrude the car polygon and predict forward if (cluster.headingValid) { newObs.extrudedPolygon = ExtrudeCarPolygon(newObs.obstaclePolygon, cluster.relativeheading); } } try { newObs.mergePolygon = Polygon.ConvexMinkowskiConvolution(mergePolygon, newObs.AvoidancePolygon); } catch (Exception) { } obstacles.Add(newObs); } } return(obstacles); }