public static void Start() { Clear(); IsActive = true; startTime = MyMinerGame.TotalGamePlayTimeInMilliseconds; ambientSound = MyAudio.AddCue3D(MySoundCuesEnum.SfxSolarWind, MyCamera.Position + MyCamera.ForwardVector * MaxSoundDistance, Vector3.Forward, Vector3.Up, Vector3.Zero, 0); sphereCenter = MyCamera.Position + MyCamera.ForwardVector * 400; for (int i = 0; i < SmokeCount; i++) { Vector3 pos = sphereCenter + MyMwcUtils.GetRandomVector3Normalized() * MyMwcUtils.GetRandomFloat(0, SmokeSphereRadius); var smokePart = new SmokeParticle { Angle = MyMwcUtils.GetRandomRadian(), Color = Vector4.Zero, AngularVelocity = MyMwcUtils.GetRandomFloat(-0.15f, 0.15f), Pos = pos, Velocity = MyMwcUtils.GetRandomVector3Normalized() * MyMwcUtils.GetRandomFloat(0, 30f) }; smokeParticles.Add(smokePart); } }
public override bool Draw(MyRenderObject renderObject) { base.Draw(renderObject); // Draw muzzle flash int deltaTime = MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot; if (deltaTime <= MyMachineGunConstants.MUZZLE_FLASH_MACHINE_GUN_LIFESPAN) { float FAKE_RADIUS = MyMwcUtils.GetRandomFloat(0.5f, 1.5f); float FAKE_THICKNESS = MyMwcUtils.GetRandomFloat(FAKE_RADIUS - 0.1f, FAKE_RADIUS); float FAKE_LENGTH = MyMwcUtils.GetRandomFloat(7, 8); float FAKE_ANGLE = MyMwcUtils.GetRandomFloat(0, MathHelper.PiOver2); //float colorComponent = 1; float colorComponent = 1 - (float)deltaTime / (float)MyMachineGunConstants.MUZZLE_FLASH_MACHINE_GUN_LIFESPAN; colorComponent = 1 - (float)Math.Pow(colorComponent, 5); colorComponent *= 1.3f; //Vector4 color = new Vector4(1.0f, 1.0f, 1.0f, 1); Vector4 color = new Vector4(colorComponent, colorComponent, colorComponent, 1); Vector3 muzzleInWorldSpace = m_positionMuzzleInWorldSpace + WorldMatrix.Up * 0.2f; MyTransparentGeometry.AddLineBillboard(MyTransparentMaterialEnum.MuzzleFlashMachineGunSide, color, muzzleInWorldSpace - WorldMatrix.Forward * 1.0f, WorldMatrix.Forward, FAKE_LENGTH, FAKE_THICKNESS); MyTransparentGeometry.AddPointBillboard(MyTransparentMaterialEnum.MuzzleFlashMachineGunFront, color, muzzleInWorldSpace, FAKE_RADIUS, FAKE_ANGLE); } return(true); }
public void Start(Vector3 direction, int?trailEffectId) { this.Physics.LinearVelocity = direction; this.Physics.AngularVelocity = new Vector3(MyMwcUtils.GetRandomFloat(0.2f, 1.5f), MyMwcUtils.GetRandomFloat(0.2f, 1.5f), 0); if (m_size == 0) { m_size = this.WorldVolume.Radius; } if (trailEffectId != null) { m_trailEffect = MyParticlesManager.CreateParticleEffect(trailEffectId.Value); m_trailEffect.AutoDelete = true; m_trailEffect.UserScale = this.WorldVolume.Radius / 10; m_trailEffect.UserBirthMultiplier /= 2; m_trailEffect.WorldMatrix = this.WorldMatrix;// worldMatrix; } m_burningCue = MyAudio.AddCue3D(MySoundCuesEnum.SfxMeteorFly, this.GetPosition(), this.GetForward(), Vector3.Up, direction); m_startTime = MyMinerGame.TotalGamePlayTimeInMilliseconds; if (MyMultiplayerGameplay.IsHosting) { MyMultiplayerGameplay.Static.NewEntity(GetObjectBuilder(true), WorldMatrix); } }
// I used this method only when we didn't have real persistant sectors... for fly-through animations List <MyVoxelMapImpostor> CreateFakeImpostors() { List <MyVoxelMapImpostor> ret = new List <MyVoxelMapImpostor>(ImpostorProperties.ImpostorsCount); for (int i = 0; i < ImpostorProperties.ImpostorsCount; i++) { Vector3 sectorCenter = Vector3.Zero; float randomDistance = MyMwcUtils.GetRandomFloat(ImpostorProperties.MinDistance, ImpostorProperties.MaxDistance); Vector3 randomPositionWithinSector = MyMwcUtils.GetRandomVector3Normalized() * randomDistance; float radius = MyMwcUtils.GetRandomFloat(ImpostorProperties.MinRadius, ImpostorProperties.MaxRadius); Vector3 position = sectorCenter + randomPositionWithinSector; float angle = MyMwcUtils.GetRandomRadian(); ret.Add(new MyVoxelMapImpostor(position, radius, angle)); } // Sort by distance (back-to-front) so alpha won't make problems on overlapping quads ret.Sort(); return(ret); }
void SwitchToAttack(MySmallShipBot bot) { m_state = StateEnum.ATTACKING; m_attackTimer = MyMwcUtils.GetRandomFloat(2, 4); MyBotCoordinator.AddAttacker(bot, m_target); }
static void UpdateExplosionLines() { foreach (LinkedListNode <ExplosionLine> explosionLine in m_preallocatedExplosionLines) { explosionLine.Value.ActualTime += MyConstants.PHYSICS_STEP_SIZE_IN_MILLISECONDS; if (explosionLine.Value.ActualTime > explosionLine.Value.TotalTime) { m_preallocatedExplosionLines.MarkForDeallocate(explosionLine); continue; } explosionLine.Value.ActualDir = Vector3.Lerp(explosionLine.Value.StartDir, explosionLine.Value.EndDir, explosionLine.Value.ActualTime / (float)explosionLine.Value.TotalTime); } m_preallocatedExplosionLines.DeallocateAllMarked(); if (m_State == NuclearState.FADE_IN && MyMwcUtils.GetRandomFloat(0, 1) > 0.75f) { ExplosionLine line = m_preallocatedExplosionLines.Allocate(true); if (line != null) { line.TotalTime = 5000; line.ActualTime = 0; line.StartDir = MyMwcUtils.GetRandomVector3Normalized(); Vector3 rotDir = MyMwcUtils.GetRandomVector3Normalized(); Matrix rotMatrix = Matrix.CreateFromAxisAngle(rotDir, 0.3f); line.EndDir = Vector3.Transform(line.StartDir, rotMatrix); } } }
// Update an explosion objects // Explosions blinks and then wait some time // After the explosion dissapears, it will move to a nearby location and // repeat private void updateExplosion() { if (m_fading && !m_IsWaiting) { Color.W -= MyDistantObjectsImpostorsConstants.EXPLOSION_FADE * m_blinkMultiplierDown; } else if (m_exploding) { Color.W += MyDistantObjectsImpostorsConstants.EXPLOSION_FADE * m_blinkMultiplierUp; } Radius = MathHelper.Lerp(m_startingRadius / 4f, m_startingRadius, Color.W); if (Color.W <= 0) { m_IsWaiting = true; Color.W = MathHelper.Clamp(Color.W, 0, 1); Color.X = 0; Color.Y = 0; Color.Z = 0; if (m_glowTime > m_explosionDelay) { float minNewHorizontal = m_targetHorizontal - (MyDistantObjectsImpostorsConstants.EXPLOSION_MOVE_DISTANCE * MyMwcUtils.GetRandomInt(4, 7)); float maxNewHorizontal = m_targetHorizontal + (MyDistantObjectsImpostorsConstants.EXPLOSION_MOVE_DISTANCE * MyMwcUtils.GetRandomInt(4, 7)); float minNewVertical = m_targetVertical - (MyDistantObjectsImpostorsConstants.EXPLOSION_MOVE_DISTANCE * MyMwcUtils.GetRandomInt(4, 7)); float maxNewVertical = m_targetVertical + (MyDistantObjectsImpostorsConstants.EXPLOSION_MOVE_DISTANCE * MyMwcUtils.GetRandomInt(4, 7)); Color.X = MyMwcUtils.GetRandomFloat(170.0f / 255f, 1.0f); Color.Y = MyMwcUtils.GetRandomFloat(100.0f / 255f, 1.0f); Color.Z = MyMwcUtils.GetRandomFloat(0.0f, 40.0f / 255f); m_angleHorizontal = MyMwcUtils.GetRandomFloat(minNewHorizontal, maxNewHorizontal); m_angleVertical = MyMwcUtils.GetRandomFloat(minNewVertical, maxNewVertical); m_IsWaiting = false; m_exploding = true; m_fading = false; } } if (m_IsWaiting) { m_glowTime += MyConstants.PHYSICS_STEP_SIZE_IN_MILLISECONDS; } else { m_glowTime = 0; } if (Color.W >= 1f) { m_fading = true; m_exploding = false; Color.W = MathHelper.Clamp(Color.W, 0, 1); // We set delay time here to avoid unnecessarry logic for it m_explosionDelay = MyMwcUtils.GetRandomInt((int)(MyDistantObjectsImpostorsConstants.EXPLOSION_WAIT_MILLISECONDS / 3f), (int)(MyDistantObjectsImpostorsConstants.EXPLOSION_WAIT_MILLISECONDS * 3f)); } }
// This method will start sun wind. Or if there is one coming, this will reset it so it will start again. public static void Start() { IsActive = true; //m_burningCue = MyAudio.AddCue3D(MySoundCuesEnum.SfxSolarWind, m_initialSunWindPosition, m_directionFromSunNormalized, Vector3.Up, Vector3.Zero); const int meteorsCount = 5; //const int frontDistance = 1000; //const int sideDistance = 3000; const int minSpeed = 1000; const int maxSpeed = 4000; //Vector3 sphereCenter = MyCamera.Position + MyCamera.ForwardVector * frontDistance - MyCamera.LeftVector * sideDistance; Vector3 sphereCenter = MyCamera.Position + MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized() * 10000; //Vector3 windForwardDirection = MyCamera.LeftVector ; int i = 0; while (i < meteorsCount) { //float distance = MyMwcUtils.GetRandomFloat(0, sphereRadius); //Vector3 position = sphereCenter + MyMwcUtils.GetRandomVector3Normalized() * new Vector3(distance, distance, distance); //Vector3 meteorDirection = (windForwardDirection + (MyMwcUtils.GetRandomVector3Normalized() * 0.05f)) * MyMwcUtils.GetRandomInt(minSpeed, maxSpeed); //Vector3 meteorDirection = -MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized();// MyMwcUtils.GetRandomVector3HemisphereNormalized(-MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized()); Vector3 meteorDirection = MyMwcUtils.GetRandomVector3HemisphereNormalized(-MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized()); Vector3 position = sphereCenter + meteorDirection * MyMwcUtils.GetRandomInt(100, 5000); //float normalizedDistance = distance / sphereRadius; float size = MyMwcUtils.GetRandomInt(minSize, maxSize); MyLine line = new MyLine(position, position + meteorDirection * 100); MyIntersectionResultLineBoundingSphere?result = MyEntities.GetIntersectionWithLineAndBoundingSphere(ref line, null, null, 1, null, true); if (result != null) { //Do not create meteors colliding with base if (!(result.Value.PhysObject is MyMeteor)) { continue; } } Matrix worldMatrix = Matrix.CreateFromAxisAngle(MyMwcUtils.GetRandomVector3Normalized(), MyMwcUtils.GetRandomFloat(0, MathHelper.Pi)); worldMatrix.Translation = position; MyMeteor meteor = MyMeteor.GenerateMeteor(size, worldMatrix, position, m_fireMeteorMaterials[MyMwcUtils.GetRandomInt(0, m_fireMeteorMaterials.Count)]); float speed = MyMwcUtils.GetRandomInt(minSpeed, maxSpeed); meteor.Start(meteorDirection * speed, MyMwcUtils.GetRandomFloat(0, 1) > 0.92f ? 101 : 100); i++; } }
public override void ApplyVariance(ref float interpolatedValue, ref float variance, float multiplier, out float value) { if ((variance != 0) || (multiplier != 1)) { interpolatedValue = MyMwcUtils.GetRandomFloat(interpolatedValue - variance, interpolatedValue + variance) * multiplier; } value = interpolatedValue; }
private void Erupt(MyEntityDetector sender, MyEntity entity, int meetCriterias) { if (entity == MySession.PlayerShip) { MyScriptWrapper.AddExplosion(sender, MyExplosionTypeEnum.BOMB_EXPLOSION, MyMwcUtils.GetRandomFloat(40f, 60f), MyMwcUtils.GetRandomFloat(25f, 40f), true); MyScriptWrapper.IncreaseHeadShake(MyMwcUtils.GetRandomFloat(5f, 15f)); sender.Off(); } }
public override void ApplyVariance(ref Vector4 interpolatedValue, ref float variance, float multiplier, out Vector4 value) { float rnd = MyMwcUtils.GetRandomFloat(1 - variance, 1 + variance); value.X = interpolatedValue.X * rnd; value.Y = interpolatedValue.Y * rnd; value.Z = interpolatedValue.Z * rnd; value.W = interpolatedValue.W * rnd; }
private void PlayBehindDialogue() { if (MyMwcUtils.GetRandomFloat(0, 1) < DialogPorobability) { if (BehindDialogs != null) { MyScriptWrapper.PlayDialogue(BehindDialogs[MyMwcUtils.GetRandomInt(0, BehindDialogs.Count - 1)]); } } }
static Vector3 GetRandomScale(float randomSize) { float basisScale = MathHelper.Lerp(0.3f, 0.7f, randomSize); Vector3 ret = new Vector3(basisScale + MyMwcUtils.GetRandomFloat(-0.1f, +0.1f), basisScale + MyMwcUtils.GetRandomFloat(-0.1f, +0.1f), basisScale + MyMwcUtils.GetRandomFloat(-0.1f, +0.1f)); ret.X = MathHelper.Clamp(ret.X, 0, 1); ret.Y = MathHelper.Clamp(ret.Y, 0, 1); ret.Z = MathHelper.Clamp(ret.Z, 0, 1); return(ret); }
public override void Update() { base.Update(); if (MyMwcUtils.GetRandomFloat(0, 1) > 0.97f) { Vector3 position = MySession.PlayerShip.GetPosition() + MyMwcUtils.GetRandomFloat(0, 10) * MySession.PlayerShip.WorldMatrix.Forward * 500 + Vector3.Up * 2000 + MyMwcUtils.GetRandomFloat(0, 1) * MySession.PlayerShip.WorldMatrix.Right * 4000 - MyMwcUtils.GetRandomFloat(0, 1) * MySession.PlayerShip.WorldMatrix.Right * 4000; MyScriptWrapper.GenerateMeteor(MyMwcUtils.GetRandomFloat(0.0001f, 2) * 100, position, MyMwcVoxelMaterialsEnum.Lava_01, -800 * Vector3.Up * MyMwcUtils.GetRandomFloat(0.7f, 1.0f), MyParticleEffectsIDEnum.MeteorTrail_FireAndSmoke); } }
public static void Draw() { if (!IsActive) { return; } // main smoke foreach (SmokeParticle part in smokeParticles) { MyTransparentGeometry.AddPointBillboard(MyTransparentMaterialEnum.Smoke, part.Color, part.Pos, 900, part.Angle, 0, true); } float darkeningPhase; float dt; GetDarkeningPhase(out darkeningPhase, out dt); // small pieces of debris if (darkeningPhase > 0.2) { var color = new Vector4(1, 1, 1, darkeningPhase); for (int i = 0; i < 100; i++) { Vector3 pos = MyCamera.Position + GetRandomVector3CircleNormalizedFixed(MyCamera.ForwardVector) * MyMwcUtils.GetRandomFloat(0, 500) + MyCamera.ForwardVector * 20; MyTransparentGeometry.AddPointBillboard(MyTransparentMaterialEnum.particle_stone, color, pos, MyMwcUtils.GetRandomFloat(0.008f, 0.05f), MyMwcUtils.GetRandomRadian()); } for (int i = 0; i < 100; i++) { Vector3 pos = MyCamera.Position + GetRandomVector3CircleNormalizedFixed(MyCamera.ForwardVector) * MyMwcUtils.GetRandomFloat(0, 500) + MyCamera.ForwardVector * 20; MyTransparentGeometry.AddPointBillboard(MyTransparentMaterialEnum.Sparks_b, color, pos, MyMwcUtils.GetRandomFloat(0.008f, 0.05f), MyMwcUtils.GetRandomRadian()); } } // storm aftersparks foreach (ElectricStorm storm in storms) { MyTransparentGeometry.AddPointBillboard(MyTransparentMaterialEnum.Sparks_a, new Vector4(1f, 1f, 1f, 1f), storm.Position + MyMwcUtils.GetRandomVector3Normalized() * MyMwcUtils.GetRandomFloat(0, 50), MyMwcUtils.GetRandomFloat(10, 20), MyMwcUtils.GetRandomRadian()); } }
public override void ApplyVariance(ref Vector3 interpolatedValue, ref Vector3 variance, float multiplier, out Vector3 value) { if ((variance != Vector3.Zero) || (multiplier != 1)) { value.X = MyMwcUtils.GetRandomFloat(interpolatedValue.X - variance.X, interpolatedValue.X + variance.X) * multiplier; value.Y = MyMwcUtils.GetRandomFloat(interpolatedValue.Y - variance.Y, interpolatedValue.Y + variance.Y) * multiplier; value.Z = MyMwcUtils.GetRandomFloat(interpolatedValue.Z - variance.Z, interpolatedValue.Z + variance.Z) * multiplier; } value = interpolatedValue; }
public static void GenerateMuzzleFlash(Vector3 position, Vector3 dir, float radius, float length, bool near = false) { float angle = MyMwcUtils.GetRandomFloat(0, MathHelper.PiOver2); float colorComponent = 1.3f; Vector4 color = new Vector4(colorComponent, colorComponent, colorComponent, 1); MyTransparentGeometry.AddLineBillboard(MyTransparentMaterialEnum.MuzzleFlashMachineGunSide, color, position, dir, length * 2, 0.3f, 0, near); MyTransparentGeometry.AddPointBillboard(MyTransparentMaterialEnum.MuzzleFlashMachineGunFront, color, position, radius, angle, 0, false, near); }
// This method will start sun wind. Or if there is one coming, this will reset it so it will start again. public static void Start() { // Activate sun wind IsActive = true; m_smallBillboardsStarted = false; m_timeLastUpdate = MyMinerGame.TotalGamePlayTimeInMilliseconds; // Place sun wind at farest possible negative Z position //Vector3 directionToSunNormalized = MyMwcUtils.Normalize(MyGuiScreenGameBase.Static.SunPosition - MyCamera.Position); MyMwcSectorGroups.Get(MyGuiScreenGameBase.Static.Sector.SectorGroup).GetDirectionToSunNormalized(); Vector3 directionToSunNormalized = MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized(); m_initialSunWindPosition = MyCamera.Position + directionToSunNormalized * MySunWindConstants.SUN_WIND_LENGTH_HALF; m_directionFromSunNormalized = -directionToSunNormalized; // Start the sound of burning (looping) StopCue(); m_burningCue = MyAudio.AddCue3D(MySoundCuesEnum.SfxSolarWind, m_initialSunWindPosition, m_directionFromSunNormalized, Vector3.Up, Vector3.Zero); //MySounds.UpdateCuePitch(m_burningCue, MyMwcUtils.GetRandomFloat(-1, +1)); m_speed = MyMwcUtils.GetRandomFloat(MySunWindConstants.SPEED_MIN, MySunWindConstants.SPEED_MAX); m_strength = MyMwcUtils.GetRandomFloat(0, 1); MyUtils.GetPerpendicularVector(ref m_directionFromSunNormalized, out m_rightVector); m_downVector = MyMwcUtils.Normalize(Vector3.Cross(m_directionFromSunNormalized, m_rightVector)); StartBillboards(); // Reinit computed max distances, they'll be computed in update m_computedMaxDistances = 0; m_deltaTime = 0; // Collect entities m_sunwindEntities.Clear(); foreach (var entity in MyEntities.GetEntities()) { if (!(entity is MySmallShip)) { continue; } // Do not move with indestructibles (NPCs etc) if (!entity.IsDestructible) { continue; } m_sunwindEntities.Add(entity); } }
public virtual void Init(List <MyRBElementDesc> collisionPrimitives, MyModelsEnum modelEnum) { float randomSize = MyMwcUtils.GetRandomFloat(0, 1); float mass = MathHelper.Lerp(2500, 5000, randomSize); // The mass can't be too low, because then debris objects are too fast. This values aren't real, but works. base.Init(modelEnum, null, MODEL_DEBRIS_MATERIAL_TYPE, 1.0f, collisionPrimitives, mass); Physics.MaxLinearVelocity = 200.0f; Physics.CollisionLayer = MyConstants.COLLISION_LAYER_MODEL_DEBRIS; MyModels.OnContentLoaded += InitDrawTechniques; }
private void PlayInFrontDialogue() { var rand = MyMwcUtils.GetRandomFloat(0, 1); if (rand < DialogPorobability) { if (FrontDialogs != null) { MyScriptWrapper.PlayDialogue(FrontDialogs[MyMwcUtils.GetRandomInt(0, FrontDialogs.Count - 1)]); } } }
// Create random vector, whose direction is 'originalVector', but deviated by random angle (whose interval is 0..maxAngle). // Use if you want deviate vector by a smal amount (e.g. debris thrown from projectile hit point) public Vector3 GetNext(float maxAngle) { float resultTheta = MyMwcUtils.GetRandomFloat(-maxAngle, maxAngle); float resultPhi = MyMwcUtils.GetRandomFloat(0, MathHelper.TwoPi); // Convert to cartezian coordinates (XYZ) Vector3 result = -new Vector3( MyMath.FastSin(resultTheta) * MyMath.FastCos(resultPhi), MyMath.FastSin(resultTheta) * MyMath.FastSin(resultPhi), MyMath.FastCos(resultTheta) ); return(Vector3.TransformNormal(result, m_matrix)); }
static void StartBillboards() { // Initialize LARGE billboards for (int x = 0; x < MySunWindConstants.LARGE_BILLBOARDS_SIZE.X; x++) { for (int y = 0; y < MySunWindConstants.LARGE_BILLBOARDS_SIZE.Y; y++) { MySunWindBillboard billboard = m_largeBillboards[x][y]; Vector3 positionRandomDelta = new Vector3( MyMwcUtils.GetRandomFloat(MySunWindConstants.LARGE_BILLBOARD_POSITION_DELTA_MIN, MySunWindConstants.LARGE_BILLBOARD_POSITION_DELTA_MAX), MyMwcUtils.GetRandomFloat(MySunWindConstants.LARGE_BILLBOARD_POSITION_DELTA_MIN, MySunWindConstants.LARGE_BILLBOARD_POSITION_DELTA_MAX), MyMwcUtils.GetRandomFloat(MySunWindConstants.LARGE_BILLBOARD_POSITION_DELTA_MIN, MySunWindConstants.LARGE_BILLBOARD_POSITION_DELTA_MAX)); Vector3 positionRelative = new Vector3( (x - MySunWindConstants.LARGE_BILLBOARDS_SIZE_HALF.X) * MySunWindConstants.LARGE_BILLBOARD_DISTANCE, (y - MySunWindConstants.LARGE_BILLBOARDS_SIZE_HALF.Y) * MySunWindConstants.LARGE_BILLBOARD_DISTANCE, (x - MySunWindConstants.LARGE_BILLBOARDS_SIZE_HALF.X) * MySunWindConstants.LARGE_BILLBOARD_DISTANCE * 0.2f); billboard.InitialAbsolutePosition = m_initialSunWindPosition + m_rightVector * (positionRandomDelta.X + positionRelative.X) + m_downVector * (positionRandomDelta.Y + positionRelative.Y) + -1 * m_directionFromSunNormalized * (positionRandomDelta.Z + positionRelative.Z); } } Vector3 initialPositionOnCameraLine = MyCamera.Position - m_directionFromSunNormalized * MySunWindConstants.SUN_WIND_LENGTH_HALF; for (int x = 0; x < MySunWindConstants.SMALL_BILLBOARDS_SIZE.X; x++) { for (int y = 0; y < MySunWindConstants.SMALL_BILLBOARDS_SIZE.Y; y++) { MySunWindBillboardSmall billboard = m_smallBillboards[x][y]; Vector2 positionRandomDelta = new Vector2( MyMwcUtils.GetRandomFloat(MySunWindConstants.SMALL_BILLBOARD_POSITION_DELTA_MIN, MySunWindConstants.SMALL_BILLBOARD_POSITION_DELTA_MAX), MyMwcUtils.GetRandomFloat(MySunWindConstants.SMALL_BILLBOARD_POSITION_DELTA_MIN, MySunWindConstants.SMALL_BILLBOARD_POSITION_DELTA_MAX)); Vector2 positionRelative = new Vector2( (x - MySunWindConstants.SMALL_BILLBOARDS_SIZE_HALF.X) * MySunWindConstants.SMALL_BILLBOARD_DISTANCE, (y - MySunWindConstants.SMALL_BILLBOARDS_SIZE_HALF.Y) * MySunWindConstants.SMALL_BILLBOARD_DISTANCE); billboard.InitialAbsolutePosition = initialPositionOnCameraLine + m_rightVector * (positionRandomDelta.X + positionRelative.X) + m_downVector * (positionRandomDelta.Y + positionRelative.Y); } } }
bool TrySwitchToAttackSearch(MySmallShipBot bot) { Vector3 newFlyToTarget = m_target.WorldVolume.Center + m_target.WorldMatrix.Forward * (MyMwcUtils.GetRandomFloat(ATTACK_DISTANCE_MIN, ATTACK_DISTANCE_MAX) + m_target.WorldVolume.Radius) + m_target.WorldMatrix.Up * MyMwcUtils.GetRandomFloat(-50, 50) + m_target.WorldMatrix.Left * MyMwcUtils.GetRandomFloat(-50, 50); if (bot.TryTestPosition(newFlyToTarget, bot.GetPosition())) { m_state = StateEnum.ATACKING_SEARCHING; return(true); } return(false); }
/// <summary> /// udpate flashing /// </summary> protected override void UpdatePrefabBeforeSimulation() { base.UpdatePrefabBeforeSimulation(); switch (m_effect) { case MyLightEffectTypeEnum.CONSTANT_FLASHING: case MyLightEffectTypeEnum.DISTANT_GLARE_FLASHING: { m_light.Intensity = m_IntensityMax * MathHelper.Clamp(1.5f + 1.5f * (float)Math.Sin(6.0f * (float)MyMinerGame.TotalGamePlayTimeInMilliseconds / 1000.0f + MathHelper.TwoPi * this.FlashOffset), 0.0f, 1.0f); m_light.ReflectorIntensity = ReflectorIntensityMax * MathHelper.Clamp(1.5f + 1.5f * (float)Math.Sin(6.0f * (float)MyMinerGame.TotalGamePlayTimeInMilliseconds / 1000.0f + MathHelper.TwoPi * this.FlashOffset), 0.0f, 1.0f); m_light.Glare.Intensity = MathHelper.Max(m_light.Intensity / m_IntensityMax, m_light.ReflectorIntensity / ReflectorIntensityMax); break; } case MyLightEffectTypeEnum.RANDOM_FLASHING: case MyLightEffectTypeEnum.DISTANT_GLARE_RANDOM_FLASHING: { int period = 100; //in ms if (MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastBlickChange > period) { m_lastBlickChange = MyMinerGame.TotalGamePlayTimeInMilliseconds; float size = MyMwcUtils.GetRandomFloat(-1.00f, 1.00f); m_light.Intensity = MathHelper.Clamp(m_light.Intensity + size * m_IntensityMax / 2.0f, 0, m_IntensityMax); m_light.ReflectorIntensity = MathHelper.Clamp(m_light.ReflectorIntensity + size * ReflectorIntensityMax / 2.0f, 0, ReflectorIntensityMax); m_light.Glare.Intensity = MathHelper.Max(m_light.Intensity / m_IntensityMax, m_light.ReflectorIntensity / ReflectorIntensityMax); } break; } case MyLightEffectTypeEnum.NORMAL: case MyLightEffectTypeEnum.DISTANT_GLARE: { m_light.Intensity = m_IntensityMax; m_light.ReflectorIntensity = ReflectorIntensityMax; //m_light.Glare.Intensity = m_light.Intensity; m_light.Glare.Intensity = 1f; break; } } }
// Start shooting on the presented target in the queue: public override bool StartShooting() { // start shooting this kind of ammo ... if (!base.StartShooting()) { return(false); } if ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot) < (MyMachineGunConstants.SHOT_INTERVAL_IN_MILISECONDS /* * 0.75f*/)) { return(false); } // Set muzzle flashes: m_muzzleFlashLength = MyMwcUtils.GetRandomFloat(4, 6); m_muzzleFlashRadius = MyMwcUtils.GetRandomFloat(1.2f, 2.0f); // Increse smoke to generate IncreaseSmoke(); // Make random trajectories for the bullet: Matrix worldMatrix = WorldMatrix; // get muzzel flash positions: List <MyModelDummy> muzzles = GetMuzzleFlashMatrix(); m_activeMuzzle = muzzles.Count == 1 ? 0 : MyMwcUtils.GetRandomInt(muzzles.Count); m_muzzleFlashPosition = MyUtils.GetTransform(muzzles[m_activeMuzzle].Matrix.Translation, ref worldMatrix); if (m_shotSmoke == null) { m_shotSmoke = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_LargeGunShot); m_shotSmoke.AutoDelete = false; } m_shotSmoke.UserEmitterScale = m_smokeToGenerate; m_shotSmoke.WorldMatrix = Matrix.CreateTranslation(m_muzzleFlashPosition); m_shotSmoke.UserScale = 5; GetWeaponBase().PlayShootingSound(); // Shoot projectiles AddProjectile(MyAmmoConstants.GetAmmoProperties(GetAmmoType()), m_muzzleFlashPosition); // dont decrease ammo count ... m_lastTimeShoot = MyMinerGame.TotalGamePlayTimeInMilliseconds; return(true); }
public virtual void Init(List <MyRBElementDesc> collisionPrimitives) { float randomSize = MyMwcUtils.GetRandomFloat(0, 1); float mass = MathHelper.Lerp(2400, 3700, randomSize); // The mass can't be too low, because then debris objects are too fast. This values aren't real, but works. mass /= 2.0f; base.Init(VOXEL_DEBRIS_MODEL_ENUM, null, MyMaterialType.ROCK, 1.0f, collisionPrimitives, mass); this.Physics.MaxLinearVelocity = 200.0f;//added 0001003: Bug A - pool (7-8 Missile Basic) this.Physics.CollisionLayer = MyConstants.COLLISION_LAYER_VOXEL_DEBRIS; m_randomizedTextureCoordRandomPositionOffset = MathHelper.Lerp(5, 15, randomSize); m_randomizedTextureCoordScale = MathHelper.Lerp(8f, 12f, randomSize); MyModels.OnContentLoaded += InitDrawTechniques; }
public override void Init(StringBuilder hudLabelText, MySmallShip parentObject, Vector3 position, Vector3 forwardVector, Vector3 upVector, MyMwcObjectBuilder_SmallShip_Weapon objectBuilder) { base.Init(hudLabelText, MyModelsEnum.Autocannon_Base, MyMaterialType.METAL, parentObject, position, forwardVector, upVector, objectBuilder); m_rotationAngle = MyMwcUtils.GetRandomRadian(); m_lastTimeShoot = MyConstants.FAREST_TIME_IN_PAST; m_smokeLastTime = MyConstants.FAREST_TIME_IN_PAST; m_smokesToGenerate = 0; m_cannonMotorEndPlayed = true; m_rotationTimeout = (float)MyAutocanonConstants.ROTATION_TIMEOUT + MyMwcUtils.GetRandomFloat(-500, +500); m_barrelMatrix = ModelLod0.Dummies["BARREL_POSITION"].Matrix; m_barrel = new MyAutocannonBarrel(); m_barrel.Init(null, m_barrelMatrix, this); }
internal override void Init(MySmallShipBot bot) { base.Init(bot); m_isInvalid = false; m_target = SourceDesire.GetEnemy(); if (m_target != null) { Debug.Assert(m_target != bot); } findSmallship = new MyFindSmallshipHelper(); m_visibilityCheckTimer = 0; // force visibility test m_closingTimer = 0; m_forcedClosingTimer = 0; m_hologramTargetTimer = 0; SwitchToClosing(); PlanNextMissile(); m_timeToAlarmCheck = 2; m_playerAttackDecisionTimer = 0; MyScriptWrapper.OnEntityAttackedByBot(bot, m_target); m_canShootWithAutocanon = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.Primary); m_canShootWithShotGun = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.Secondary); m_canShootWithSniper = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.Third); m_canShootMissile = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.Fourth); m_canShootCannon = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.Fifth); m_canShootFlash = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.FlashBombFront) && MyFakes.BOT_USE_FLASH_BOMBS; m_canShootSmoke = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.SmokeBombFront) && MyFakes.BOT_USE_SMOKE_BOMBS; m_canShootHologram = bot.CanShootWith(MyMwcObjectBuilder_FireKeyEnum.HologramFront) && MyFakes.BOT_USE_HOLOGRAMS; m_weaponChangeTimer = 0; m_currentWeapon = SelectWeapon((bot.GetPosition() - m_target.GetPosition()).Length()); m_smokeBombTimer = MyMwcUtils.GetRandomFloat(0.5f, 3.0f); m_flashBombTimer = MyMwcUtils.GetRandomFloat(0.5f, 3.0f); m_hologramTimer = MyMwcUtils.GetRandomFloat(0.5f, 3.0f); }
public static void CreateExplosionDebris(ref BoundingSphere explosionSphere, MyGroupMask groupMask, MyEntity entity, MyVoxelMap voxelMap, ref BoundingBox bb) { // Number of debris is random, but not more than size of the offset array float scaleMul = explosionSphere.Radius / 4.0f; GeneratePositions(bb); foreach (Vector3 positionInLocalSpace in m_positions) { var positionInWorldSpace = Vector3.Transform(positionInLocalSpace, entity.WorldMatrix); MyExplosionDebrisModel newObj = m_objectPool.Allocate(true); if (newObj == null) { continue; } // Check if new object won't intersect any existing triangle - because if yes, then it will decrease JLX performace a lot float randomNewScale = MyMwcUtils.GetRandomFloat(scaleMul / 4, scaleMul); var sphere = new BoundingSphere(positionInWorldSpace, newObj.m_modelLod0.BoundingSphere.Radius * randomNewScale); MyEntity myEntitiesGetIntersectionWithSphere = MyEntities.GetIntersectionWithSphere(ref sphere); if ((myEntitiesGetIntersectionWithSphere == null || myEntitiesGetIntersectionWithSphere == entity) && (voxelMap == null || !voxelMap.DoOverlapSphereTest(sphere.Radius, sphere.Center))) { if (Vector3.DistanceSquared(positionInWorldSpace, explosionSphere.Center) > MyMwcMathConstants.EPSILON_SQUARED) { newObj.Start(positionInWorldSpace, randomNewScale, groupMask, true); newObj.Physics.LinearVelocity = GetDirection(positionInWorldSpace, explosionSphere.Center) * MyExplosionsConstants.EXPLOSION_DEBRIS_SPEED; MyEntities.Add(newObj); if (MyExplosion.DEBUG_EXPLOSIONS) { m_debugVoxelSpheres.Add(sphere); } } } else { // Put back to object pool newObj.Close(); } } }
void TrySwitchToExplore(MySmallShipBot bot) { Vector3?result = null; if (bot.TryGetTestPositionResult(ref result)) { if (result.HasValue) { m_exploreTarget = result.Value; m_exploreTargetTimer = MyMwcUtils.GetRandomFloat(2, 3); m_state = CuriousState.EXPLORE; } else { bool success = TrySwitchExploreSearch(bot); Debug.Assert(success); } } }