protected virtual string GetDrawString(BodyInfo item) { if (item == null) return null; return string.Format("{0}. {1}", item.ID, item.Body); }
/// <summary> /// Initializes a new instance of the <see cref="NPCSpawner"/> class. /// </summary> /// <param name="mapSpawnValues">The MapSpawnValues containing the values to use to create this NPCSpawner.</param> /// <param name="map">The Map instance to do the spawning on. The <see cref="MapID"/> of this Map must be equal to the /// <see cref="MapID"/> of the <paramref name="mapSpawnValues"/>.</param> /// <exception cref="ArgumentException">The <paramref name="map"/>'s <see cref="MapID"/> does not match the /// <paramref name="mapSpawnValues"/>'s <see cref="MapID"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="map" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException"><paramref name="mapSpawnValues" /> is <c>null</c>.</exception> public NPCSpawner(IMapSpawnTable mapSpawnValues, Map map) { if (map == null) throw new ArgumentNullException("map"); if (mapSpawnValues == null) throw new ArgumentNullException("mapSpawnValues"); if (map.ID != mapSpawnValues.MapID) throw new ArgumentException("The map's MapID and mapSpawnValues's MapID do not match.", "map"); _map = map; _characterTemplate = _characterTemplateManager[mapSpawnValues.CharacterTemplateID]; _characterTemplateBody = BodyInfoManager.Instance.GetBody(_characterTemplate.TemplateTable.BodyID); _amount = mapSpawnValues.Amount; _area = new MapSpawnRect(mapSpawnValues).ToRectangle(map); _spawnDirection = mapSpawnValues.DirectionId; _respawn = mapSpawnValues.Respawn; if (_characterTemplate == null) { const string errmsg = "Failed to find the CharacterTemplate for CharacterTemplateID `{0}`."; var err = string.Format(errmsg, mapSpawnValues.CharacterTemplateID); if (log.IsFatalEnabled) log.Fatal(err); Debug.Fail(err); throw new ArgumentException(err); } SpawnNPCs(); }
static CelestialBodies() { try { SystemBody = new BodyInfo(PSystemManager.Instance.localBodies.Find(b => b.referenceBody == null || b.referenceBody == b)); String homeCBName = Planetarium.fetch.Home.bodyName; if (!SetSelectedBody(homeCBName)) { SelectedBody = SystemBody; SelectedBody.SetSelected(true); } } catch (Exception ex) { Logger.Exception(ex); } }
/// <summary> /// Gets a random position that fits inside the <see cref="NPCSpawner.Area"/> and does not intersect with any walls. /// </summary> /// <returns>A random position that fits inside the <see cref="NPCSpawner.Area"/>, or null if no valid spawn positions could be found.</returns> public Vector2? RandomSpawnPosition(BodyInfo bodyInfo) { // Try 50 times to find a spawn position for (int i = 0; i < 50; i++) { int x = _rnd.Next(Area.Left, Area.Right + 1); int y = _rnd.Next(Area.Top, Area.Bottom + 1); Rectangle area = new Rectangle(x, y, bodyInfo.Size.X, bodyInfo.Size.Y); if (!Map.Spatial.Contains<WallEntityBase>(area)) { return new Vector2(x, y); } } if (log.IsErrorEnabled) log.ErrorFormat("Failed to place npc NPCSpawner `{0}` because no valid positions could be found. " + " Try having less obstacles in the spawn area or making it larger.", this); return null; }
public static BodyInfo ParseBodyInfo(string partList) { if(string.IsNullOrEmpty(partList)) return null; ZIMapParser parser = new ZIMapParser(partList); if(parser.Length <= 0 || parser[0].Type != ZIMapParser.TokenType.List) return null; BodyInfo info = new BodyInfo(); info.Info = partList; List<BodyPart> plis = new List<BodyPart>(); List<string> pother = new List<string>(); ParseBodyInfo(plis, pother, parser[0], 0); if(plis.Count > 0) info.Parts = plis.ToArray(); if(pother.Count > 0) info.Other = pother.ToArray(); return info; }
public BodyInfo(CelestialBody body, BodyInfo parent = null) { try { // Set the body information. CelestialBody = body; Name = body.bodyName; Gravity = 9.81 * body.GeeASL; Parent = parent; // Set orbiting bodies information. Children = new List<BodyInfo>(); foreach (CelestialBody orbitingBody in body.orbitingBodies) { Children.Add(new BodyInfo(orbitingBody, this)); } SelectedDepth = 0; } catch (Exception ex) { Logger.Exception(ex); } }
internal static void CreateBodies(SimulationStepInput input, NativeList <BodyInfo> bodyInfos, NativeHashMap <int, int> bodyInfoToBodiesIndexMap) { NativeArray <RigidBody> dynamicBodies = input.World.DynamicBodies; NativeArray <RigidBody> staticBodies = input.World.StaticBodies; NativeArray <MotionData> motionDatas = input.World.MotionDatas; NativeArray <MotionVelocity> motionVelocities = input.World.MotionVelocities; int dynamicBodyIndex = 0; int staticBodyIndex = 0; for (int i = 0; i < bodyInfos.Length; i++) { BodyInfo bodyInfo = bodyInfos[i]; var collider = bodyInfo.Collider; if (bodyInfo.IsDynamic) { dynamicBodies[dynamicBodyIndex] = new RigidBody { WorldFromBody = new RigidTransform(bodyInfo.Orientation, bodyInfo.Position), Collider = bodyInfo.Collider, Entity = Entity.Null, CustomTags = 0 }; motionDatas[dynamicBodyIndex] = new MotionData { WorldFromMotion = new RigidTransform( math.mul(bodyInfo.Orientation, collider.Value.MassProperties.MassDistribution.Transform.rot), math.rotate(bodyInfo.Orientation, collider.Value.MassProperties.MassDistribution.Transform.pos) + bodyInfo.Position ), BodyFromMotion = new RigidTransform(collider.Value.MassProperties.MassDistribution.Transform.rot, collider.Value.MassProperties.MassDistribution.Transform.pos), LinearDamping = 0.0f, AngularDamping = 0.0f }; motionVelocities[dynamicBodyIndex] = new MotionVelocity { LinearVelocity = bodyInfo.LinearVelocity, AngularVelocity = bodyInfo.AngularVelocity, InverseInertia = math.rcp(collider.Value.MassProperties.MassDistribution.InertiaTensor * bodyInfo.Mass), InverseMass = math.rcp(bodyInfo.Mass), AngularExpansionFactor = collider.Value.MassProperties.AngularExpansionFactor, GravityFactor = 1.0f }; bodyInfoToBodiesIndexMap.Add(i, dynamicBodyIndex); dynamicBodyIndex++; } else { staticBodies[staticBodyIndex] = new RigidBody { WorldFromBody = new RigidTransform(bodyInfo.Orientation, bodyInfo.Position), Collider = bodyInfo.Collider, Entity = Entity.Null, CustomTags = 0 }; staticBodyIndex++; bodyInfoToBodiesIndexMap.Add(i, -staticBodyIndex); } } for (int i = 0; i < bodyInfos.Length; i++) { if (0 > bodyInfoToBodiesIndexMap[i]) { bodyInfoToBodiesIndexMap[i]++; bodyInfoToBodiesIndexMap[i] = -bodyInfoToBodiesIndexMap[i]; bodyInfoToBodiesIndexMap[i] += dynamicBodyIndex; } } // Create default static body staticBodies[staticBodyIndex] = new RigidBody { WorldFromBody = new RigidTransform(quaternion.identity, float3.zero), Collider = default,
internal static void CreateRigidBodiesAndMotions(SimulationStepInput input, NativeList <BodyInfo> bodies, NativeHashMap <int, int> indexMap) { NativeSlice <RigidBody> dynamicBodies = input.World.DynamicBodies; NativeSlice <RigidBody> staticBodies = input.World.StaticBodies; NativeSlice <MotionData> motionDatas = input.World.MotionDatas; NativeSlice <MotionVelocity> motionVelocities = input.World.MotionVelocities; int dynamicBodyIndex = 0; int staticBodyIndex = 0; for (int i = 0; i < bodies.Length; i++) { BodyInfo bodyInfo = bodies[i]; unsafe { Unity.Physics.Collider *collider = (Unity.Physics.Collider *)bodyInfo.Collider.GetUnsafePtr(); if (bodyInfo.IsDynamic) { dynamicBodies[dynamicBodyIndex] = new RigidBody { WorldFromBody = new RigidTransform(bodyInfo.Orientation, bodyInfo.Position), Collider = bodyInfo.Collider, Entity = Entity.Null, CustomTags = 0 }; motionDatas[dynamicBodyIndex] = new MotionData { WorldFromMotion = new RigidTransform( math.mul(bodyInfo.Orientation, collider->MassProperties.MassDistribution.Transform.rot), math.rotate(bodyInfo.Orientation, collider->MassProperties.MassDistribution.Transform.pos) + bodyInfo.Position ), BodyFromMotion = new RigidTransform(collider->MassProperties.MassDistribution.Transform.rot, collider->MassProperties.MassDistribution.Transform.pos), LinearDamping = 0.0f, AngularDamping = 0.0f, GravityFactor = 1.0f }; motionVelocities[dynamicBodyIndex] = new MotionVelocity { LinearVelocity = bodyInfo.LinearVelocity, AngularVelocity = bodyInfo.AngularVelocity, InverseInertia = math.rcp(collider->MassProperties.MassDistribution.InertiaTensor * bodyInfo.Mass), InverseMass = math.rcp(bodyInfo.Mass), AngularExpansionFactor = collider->MassProperties.AngularExpansionFactor }; indexMap.Add(i, dynamicBodyIndex); dynamicBodyIndex++; } else { staticBodies[staticBodyIndex] = new RigidBody { WorldFromBody = new RigidTransform(bodyInfo.Orientation, bodyInfo.Position), Collider = bodyInfo.Collider, Entity = Entity.Null, CustomTags = 0 }; staticBodyIndex++; } } } // Create default static body unsafe { staticBodies[staticBodyIndex] = new RigidBody { WorldFromBody = new RigidTransform(quaternion.identity, float3.zero), Collider = default,
protected abstract ILoot CreateLoot(BodyInfo bodyInfo);