protected StringBuilder GetEntityName(MyEntity entity) { if (!string.IsNullOrEmpty(entity.DisplayName)) { return(new StringBuilder(entity.GetCorrectDisplayName())); } else { if (entity is MyPrefabLargeWeapon && (entity as MyPrefabLargeWeapon).GetGun() != null) { MyLargeShipGunBase gun = (entity as MyPrefabLargeWeapon).GetGun(); if (gun is MyLargeShipAutocannon) { return(MyTextsWrapper.Get(MyTextsWrapperEnum.Autocannon)); } else if (gun is MyLargeShipCIWS) { return(MyTextsWrapper.Get(MyTextsWrapperEnum.CIWS)); } else if (gun is MyLargeShipMachineGun) { return(MyTextsWrapper.Get(MyTextsWrapperEnum.MachineGun)); } else if (gun is MyLargeShipMissileLauncherGun) { return(MyTextsWrapper.Get(MyTextsWrapperEnum.MissileLauncher)); } } else if (entity is MyPrefabCamera) { return(MyTextsWrapper.Get(MyTextsWrapperEnum.Camera)); } else if (entity is MyPrefabAlarm) { return(MyTextsWrapper.Get(MyTextsWrapperEnum.Alarm)); } else if (entity is MyPrefabBankNode) { return(MyTextsWrapper.Get(MyTextsWrapperEnum.BankNode)); } else if (entity is MyPrefabGenerator) { return(MyTextsWrapper.Get(MyTextsWrapperEnum.Generator)); } else if (entity is MyPrefabScanner) { return(MyTextsWrapper.Get(MyTextsWrapperEnum.Scanner)); } else if (entity is MyPrefabContainer) { return(MyTextsWrapper.Get(MyTextsWrapperEnum.Alarm)); } else if (entity is MyPrefabKinematic) { MyPrefabKinematic pk = (MyPrefabKinematic)entity; return(MyTextsWrapper.Get(MyTextsWrapperEnum.Door)); } return(new StringBuilder()); } }
public static string GetPreviewFileName(MyPrefabConfiguration config, int prefabId) { if (config.BuildType == BuildTypesEnum.MODULES && config.CategoryType == CategoryTypesEnum.WEAPONRY) { MyModelsEnum baseModelEnum, barelModelEnum; if (MyLargeShipGunBase.GetModelEnums((MyMwcObjectBuilder_PrefabLargeWeapon_TypesEnum)prefabId, out baseModelEnum, out barelModelEnum)) { return(Path.GetFileName(MyModels.GetModelAssetName(baseModelEnum))); } } return(Path.GetFileName(MyModels.GetModelAssetName(config.ModelLod0Enum))); }
protected override void InitPrefab(string displayName, Vector3 relativePosition, Matrix localOrientation, MyMwcObjectBuilder_PrefabBase objectBuilder, MyPrefabConfiguration prefabConfig) { prefabConfiguration = prefabConfig as MyPrefabConfigurationLargeWeapon; MyMwcObjectBuilder_PrefabLargeWeapon largeWeaponBuilder = objectBuilder as MyMwcObjectBuilder_PrefabLargeWeapon; weaponType = largeWeaponBuilder.PrefabLargeWeaponType; UseProperties = new MyUseProperties(MyUseType.FromHUB | MyUseType.Solo, MyUseType.FromHUB); if (largeWeaponBuilder.UseProperties == null) { UseProperties.Init(MyUseType.FromHUB | MyUseType.Solo, MyUseType.FromHUB, 1, 4000, false); } else { UseProperties.Init(largeWeaponBuilder.UseProperties); } // create & initialize weapon: MyLargeShipGunBase.CreateAloneWeapon(ref m_gun, displayName, Vector3.Zero, Matrix.Identity, largeWeaponBuilder, Activated); AddChild(m_gun); m_gun.PrefabParent = this; m_gun.Enabled = IsWorking(); m_gun.SetRandomRotation(); // if (largeWeaponBuilder.SearchingDistance == 2000) // largeWeaponBuilder.SearchingDistance = 1000; this.LocalMatrix = Matrix.CreateWorld(relativePosition, localOrientation.Forward, localOrientation.Up); m_searchingDistance = MathHelper.Clamp(largeWeaponBuilder.SearchingDistance, MyLargeShipWeaponsConstants.MIN_SEARCHING_DISTANCE, MyLargeShipWeaponsConstants.MAX_SEARCHING_DISTANCE); m_targetDetectorCriterias.Add(new MyEntityDetectorCriterium <MySmallShip>(1, IsPossibleTarget, true)); m_targetsDetector = new MyEntityDetector(true); m_potentialTargetsDetector = new MyEntityDetector(true); m_potentialTargetDetectorCriterias.Add(new MyEntityDetectorCriterium <MySmallShip>(1, IsPotentialTarget, true)); //m_targetsDetector.OnEntityEnter += OnTargetDetected; //m_targetsDetector.OnEntityLeave += OnTargetLost; m_targetsDetector.OnNearestEntityChange += OnNearestTargetChange; m_potentialTargetsDetector.OnNearestEntityChange += OnNearestPotentialTargetChange; //m_targetsDetector.OnEntityPositionChange += OnTargetPositionChanged; InitDetector(Activated); }
// Update position, check collisions, etc. // Return false if projectile dies/timeouts in this tick. public bool Update() { // Projectile was killed , but still not last time drawn, so we don't need to do update (we are waiting for last draw) if (m_state == MyProjectileStateEnum.KILLED) { return(true); } // Projectile was killed and last time drawn, so we can finally remove it from buffer if (m_state == MyProjectileStateEnum.KILLED_AND_DRAWN) { if (m_trailEffect != null) { // stop the trail effect m_trailEffect.Stop(); m_trailEffect = null; } return(false); } Vector3 position = m_position; m_position += m_velocity * MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS; m_velocity = m_externalVelocity * m_externalAddition + m_directionNormalized * m_speed; if (m_externalAddition < 1.0f) { m_externalAddition *= 0.5f; } // Distance timeout float trajectoryLength = Vector3.Distance(m_position, m_origin); if (trajectoryLength >= m_maxTrajectory) { if (m_trailEffect != null) { // stop the trail effect m_trailEffect.Stop(); m_trailEffect = null; } m_state = MyProjectileStateEnum.KILLED; return(true); } if (m_trailEffect != null) { m_trailEffect.WorldMatrix = Matrix.CreateTranslation(m_position); } m_checkIntersectionIndex++; m_checkIntersectionIndex = m_checkIntersectionIndex % CHECK_INTERSECTION_INTERVAL; //check only each n-th intersection if (m_checkIntersectionIndex != 0) { return(true); } // Calculate hit point, create decal and throw debris particles Vector3 lineEndPosition = position + CHECK_INTERSECTION_INTERVAL * (m_velocity * MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS); MyLine line = new MyLine(m_positionChecked ? position : m_origin, lineEndPosition, true); m_positionChecked = true; MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyEntities.GetIntersectionWithLine()"); MyIntersectionResultLineTriangleEx?intersection = MyEntities.GetIntersectionWithLine(ref line, m_ignorePhysObject, null, false); MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); MyEntity physObject = intersection != null ? intersection.Value.Entity : null; if (physObject != null) { while (physObject.Physics == null && physObject.Parent != null) { physObject = physObject.Parent; } } if ((intersection != null) && (physObject != null) && (physObject.Physics.CollisionLayer != MyConstants.COLLISION_LAYER_UNCOLLIDABLE) && m_ignorePhysObject != physObject) { MyIntersectionResultLineTriangleEx intersectionValue = intersection.Value; bool isPlayerShip = MySession.PlayerShip == physObject; MyMaterialType materialType = isPlayerShip ? MyMaterialType.PLAYERSHIP : physObject.Physics.MaterialType; //material properties MyMaterialTypeProperties materialProperties = MyMaterialsConstants.GetMaterialProperties(materialType); bool isProjectileGroupKilled = false; if (m_sharedGroup != null) { isProjectileGroupKilled = m_sharedGroup.Killed; m_sharedGroup.Killed = true; } if (!isProjectileGroupKilled) { // Play bullet hit cue MyAudio.AddCue3D(m_ammoProperties.IsExplosive ? materialProperties.ExpBulletHitCue : materialProperties.BulletHitCue, intersectionValue.IntersectionPointInWorldSpace, Vector3.Zero, Vector3.Zero, Vector3.Zero); } float decalAngle = MyMwcUtils.GetRandomRadian(); // If we hit the glass of a miner ship, we need to create special bullet hole decals // drawn from inside the cockpit and change phys object so rest of the code will think we hit the parent // IMPORTANT: Intersection between projectile and glass is calculated only for mining ship in which player sits. So for enemies this will be never calculated. if (intersection.Value.Entity is MyCockpitGlassEntity) { if (!isProjectileGroupKilled) { MyCockpitGlassDecalTexturesEnum bulletHoleDecalTexture; float bulletHoleDecalSize; if (MyMwcUtils.GetRandomBool(3)) { bulletHoleDecalTexture = MyCockpitGlassDecalTexturesEnum.BulletHoleOnGlass; bulletHoleDecalSize = 0.25f; } else { bulletHoleDecalTexture = MyCockpitGlassDecalTexturesEnum.BulletHoleSmallOnGlass; bulletHoleDecalSize = 0.1f; } // Place bullet hole decal on player's cockpit glass (seen from inside the ship) MyCockpitGlassDecals.Add(bulletHoleDecalTexture, bulletHoleDecalSize, decalAngle, 1.0f, ref intersectionValue, false); // Create hit particles throwed into the cockpit (it's simulation of broken glass particles) // IMPORTANT: This particles will be relative to miner ship, so we create them in object space coordinates and update them by object WorldMatrix every time we draw them //MyParticleEffects.CreateHitParticlesGlass(ref intersectionValue.IntersectionPointInObjectSpace, ref intersectionValue.NormalInWorldSpace, ref line.Direction, physObject.Parent); } } // If this was "mine", it must explode else if (physObject is MyMineBase) { m_state = MyProjectileStateEnum.KILLED; if (!IsDummy) { (physObject as MyAmmoBase).Explode(); } return(true); } // If this was missile, cannon shot, it must explode if it is not mine missile else if (physObject is MyAmmoBase) { if (((MyAmmoBase)physObject).OwnerEntity == m_ignorePhysObject) { m_state = MyProjectileStateEnum.KILLED; if (!IsDummy) { (physObject as MyAmmoBase).Explode(); } return(true); } } else if (this.OwnerEntity is MySmallShip && (MySmallShip)this.OwnerEntity == MySession.PlayerShip && physObject is MyStaticAsteroid && !physObject.IsDestructible) { if (this.m_ammoProperties.IsExplosive || (this.m_ammoProperties.AmmoType == MyAmmoType.Explosive && this.m_weapon is Weapons.MyShotGun)) { HUD.MyHud.ShowIndestructableAsteroidNotification(); } } else if (!isProjectileGroupKilled && !isPlayerShip) { // Create smoke and debris particle at the place of voxel/model hit m_ammoProperties.OnHitParticles(ref intersectionValue.IntersectionPointInWorldSpace, ref intersectionValue.Triangle.InputTriangleNormal, ref line.Direction, physObject, m_weapon, OwnerEntity); MySurfaceImpactEnum surfaceImpact; if (intersectionValue.Entity is MyVoxelMap) { var voxelMap = intersectionValue.Entity as MyVoxelMap; var voxelCoord = voxelMap.GetVoxelCenterCoordinateFromMeters(ref intersectionValue.IntersectionPointInWorldSpace); var material = voxelMap.GetVoxelMaterial(ref voxelCoord); if (material == MyMwcVoxelMaterialsEnum.Indestructible_01 || material == MyMwcVoxelMaterialsEnum.Indestructible_02 || material == MyMwcVoxelMaterialsEnum.Indestructible_03 || material == MyMwcVoxelMaterialsEnum.Indestructible_04 || material == MyMwcVoxelMaterialsEnum.Indestructible_05_Craters_01) { surfaceImpact = MySurfaceImpactEnum.INDESTRUCTIBLE; } else { surfaceImpact = MySurfaceImpactEnum.DESTRUCTIBLE; } } else if (intersectionValue.Entity is MyStaticAsteroid) { surfaceImpact = MySurfaceImpactEnum.INDESTRUCTIBLE; } else { surfaceImpact = MySurfaceImpactEnum.METAL; } m_ammoProperties.OnHitMaterialSpecificParticles(ref intersectionValue.IntersectionPointInWorldSpace, ref intersectionValue.Triangle.InputTriangleNormal, ref line.Direction, physObject, surfaceImpact, m_weapon); } if (!(physObject is MyExplosionDebrisBase) && physObject != MySession.PlayerShip) { // Decal size depends on material. But for mining ship create smaller decal as original size looks to large on the ship. float decalSize = MyMwcUtils.GetRandomFloat(materialProperties.BulletHoleSizeMin, materialProperties.BulletHoleSizeMax); // Place bullet hole decal float randomColor = MyMwcUtils.GetRandomFloat(0.5f, 1.0f); MyDecals.Add( materialProperties.BulletHoleDecal, decalSize, decalAngle, new Vector4(randomColor, randomColor, randomColor, 1), false, ref intersectionValue, 0.0f, m_ammoProperties.DecalEmissivity, MyDecalsConstants.DECAL_OFFSET_BY_NORMAL); } if (!(physObject is MyVoxelMap) && !IsDummy) { ApplyProjectileForce(physObject, intersectionValue.IntersectionPointInWorldSpace, m_directionNormalized, isPlayerShip); } // If this object is miner ship, then shake his head little bit if (physObject is MySmallShip && !IsDummy) { MySmallShip minerShip = (MySmallShip)physObject; minerShip.IncreaseHeadShake(MyHeadShakeConstants.HEAD_SHAKE_AMOUNT_AFTER_PROJECTILE_HIT); } //Handle damage MyEntity damagedObject = intersectionValue.Entity; // not a very nice way to damage actual prefab associated with the large ship weapon (if MyPrefabLargeWeapon is reworked, it might change) if (damagedObject is MyLargeShipBarrelBase) { damagedObject = damagedObject.Parent; } if (damagedObject is MyLargeShipGunBase) { MyLargeShipGunBase physObj = damagedObject as MyLargeShipGunBase; if (physObj.PrefabParent != null) { damagedObject = physObj.PrefabParent; } } // Decrease health of stricken object if (!IsDummy) { damagedObject.DoDamage(m_ammoProperties.HealthDamage, m_ammoProperties.ShipDamage, m_ammoProperties.EMPDamage, m_ammoProperties.DamageType, m_ammoProperties.AmmoType, m_ignorePhysObject); if (MyMultiplayerGameplay.IsRunning) { var ammo = MyAmmoConstants.FindAmmo(m_ammoProperties); MyMultiplayerGameplay.Static.ProjectileHit(damagedObject, intersectionValue.IntersectionPointInWorldSpace, this.m_directionNormalized, ammo, this.OwnerEntity); } } if (m_trailEffect != null) { // stop the trail effect m_trailEffect.Stop(); m_trailEffect = null; } // Kill this projectile (set the position to intersection point, so we draw trail polyline only up to this point) m_position = intersectionValue.IntersectionPointInWorldSpace; m_state = MyProjectileStateEnum.KILLED; return(true); } return(true); }
public void Init(StringBuilder hudLabelText, Matrix localMatrix, MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum AmmoType, MyLargeShipGunBase parentObject) { base.Init(hudLabelText, MyModelsEnum.LargeShipCiwsBarrel, null, localMatrix, AmmoType, parentObject); }
public void Init(StringBuilder hudLabelText, MyModelsEnum?modelLod0Enum, MyModelsEnum?modelLod1Enum, Matrix localMatrix, MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum ammoType, MyLargeShipGunBase parentObject) { base.Init(hudLabelText, modelLod0Enum, modelLod1Enum, parentObject, null, null); LocalMatrix = localMatrix; ((MyLargeShipGunBase)parentObject).InitializationBarrelMatrix = LocalMatrix; // Check for the dummy cubes for the muzzle flash positions: if (ModelLod0 != null) { // test for one value: StringBuilder sb = new StringBuilder(); sb.Append(MyLargeShipWeaponsConstants.MUZZLE_FLASH_NAME_ONE); if (ModelLod0.Dummies.Count > 0) { if (ModelLod0.Dummies.ContainsKey(sb.ToString())) { // one muzzle flash value: m_muzzleDummies.Add(ModelLod0.Dummies[sb.ToString()]); } else { // more muzzle flashes values: int num = 0; for (int i = 0; i < ModelLod0.Dummies.Count; ++i) { sb.Clear(); sb.Append(MyLargeShipWeaponsConstants.MUZZLE_FLASH_NAME_MODE); sb.Append(i.ToString()); if (ModelLod0.Dummies.ContainsKey(sb.ToString())) { ++num; } } for (int i = 0; i < ModelLod0.Dummies.Count; ++i) { sb.Clear(); sb.Append(MyLargeShipWeaponsConstants.MUZZLE_FLASH_NAME_MODE); sb.Append(i.ToString()); if (ModelLod0.Dummies.ContainsKey(sb.ToString())) { m_muzzleDummies.Add(ModelLod0.Dummies[sb.ToString()]); } } } } } //base.InitSpherePhysics(MyMaterialType.METAL, ModelLod0, 9999999.0f, 1.0f, MyConstants.COLLISION_LAYER_ALL, RigidBodyFlag.RBF_RBO_STATIC); if (this.Physics != null) { //this.Physics.Enabled = true; this.Physics.Update(); } m_ammoType = ammoType; Save = false; //NeedsUpdate = true; //No, barrel is updated from parent }
/// <summary> /// IMPORTANT: using Lod1Normals here, since this is done in a separate time to normal rendering /// </summary> public Texture RenderPrefabPreview(int prefabId, MyPrefabConfiguration config, MyMwcObjectBuilder_Prefab_AppearanceEnum appearance, int width, int height, float lightsIntensity = 2.5f) { m_fullSizeRT = MyRender.GetRenderTarget(MyRenderTargets.SSAO); if (m_fullSizeRT == null || MyGuiScreenGamePlay.Static == null) { return(null); } MyFakes.RENDER_PREVIEWS_WITH_CORRECT_ALPHA = true; Texture renderTarget = new Texture(MyMinerGame.Static.GraphicsDevice, width, height, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default); PrepareRender(width, height); MyRender.Sun.Intensity = lightsIntensity; foreach (var light in m_setup.LightsToUse) { light.Intensity = lightsIntensity; } if (MySession.PlayerShip != null) { MySession.PlayerShip.Visible = false; } bool weapon = false; if (config.BuildType == BuildTypesEnum.MODULES && config.CategoryType == CategoryTypesEnum.WEAPONRY) { MyModel baseModel = null; MyModel barrelModel = null; Matrix baseMatrix = Matrix.Identity; Matrix barrelMatrix = Matrix.Identity; weapon = MyLargeShipGunBase.GetVisualPreviewData((MyMwcObjectBuilder_PrefabLargeWeapon_TypesEnum)prefabId, ref baseModel, ref barrelModel, ref baseMatrix, ref barrelMatrix); if (weapon) { m_setup.ViewMatrix = Matrix.Identity; SetupRenderElements(baseModel, baseMatrix, (int)appearance); SetupRenderElements(barrelModel, barrelMatrix, (int)appearance); SetupLights(baseModel); MyRender.PushRenderSetup(m_setup); MyRender.Draw(); MyRender.PopRenderSetup(); BlitToThumbnail(MyMinerGame.Static.GraphicsDevice, renderTarget); } } if (!weapon) { //load new model from prefab config MyModel model = MyModels.GetModelForDraw(config.ModelLod0Enum); float distanceMultiplier = 2f; Matrix viewMatrix = Matrix.Identity; m_setup.ViewMatrix = viewMatrix; //generate world matrix Matrix worldMatrix = Matrix.Identity; worldMatrix.Translation = -model.BoundingSphere.Center; worldMatrix *= config.PreviewPointOfView.Transform; worldMatrix *= Matrix.CreateRotationY(-.85f * MathHelper.PiOver4); worldMatrix *= Matrix.CreateRotationX(.35f * MathHelper.PiOver4); worldMatrix.Translation += new Vector3(0, 0, -model.BoundingSphere.Radius * distanceMultiplier); SetupRenderElements(model, worldMatrix, (int)appearance); SetupLights(model); //MyGuiManager.TakeScreenshot(); MyRender.PushRenderSetup(m_setup); MyRender.EnableShadows = false; MyRender.Draw(); MyRender.EnableShadows = true; MyRender.PopRenderSetup(); //MyGuiManager.StopTakingScreenshot(); BlitToThumbnail(MyMinerGame.Static.GraphicsDevice, renderTarget); } if (MySession.PlayerShip != null) { MySession.PlayerShip.Visible = true; } MyFakes.RENDER_PREVIEWS_WITH_CORRECT_ALPHA = false; return(renderTarget); }
/// <summary> /// IMPORTANT: using Lod1Normals here, since this is done in a separate time to normal rendering /// </summary> public RenderTarget2D RenderPreview(MyMwcObjectBuilder_Prefab_TypesEnum enumValue, MyPrefabConfiguration config, int width, int height) { m_fullSizeRT = MyRender.GetRenderTarget(MyRenderTargets.Lod1Normals); if (m_fullSizeRT == null || MyGuiScreenGamePlay.Static == null) { return(null); } m_setup.RenderTargets[0] = new RenderTargetBinding(m_fullSizeRT); if (MySession.PlayerShip != null) { MySession.PlayerShip.Visible = false; } GraphicsDevice device = MyMinerGame.Static.GraphicsDevice; RenderTarget2D renderTarget = new RenderTarget2D(device, width, height, true, SurfaceFormat.Color, DepthFormat.Depth24, 0, RenderTargetUsage.DiscardContents); m_setup.RenderElementsToDraw.Clear(); m_setup.TransparentRenderElementsToDraw.Clear(); // make actual viewport one pixel larger in order to remove the deformed border caused by antialiasing m_setup.Viewport = new Viewport(0, 0, 2 * renderTarget.Width, 2 * renderTarget.Height); m_setup.AspectRatio = 1; m_setup.Fov = MathHelper.ToRadians(70); MyRender.Sun.Direction = new Vector3(.5f, -.3f, -1); MyRender.Sun.Direction.Normalize(); MyRender.Sun.Color = Vector4.One; MyRender.EnableSun = true; float previousSunIntensityMultiplier = MyRender.SunIntensityMultiplier; MyRender.SunIntensityMultiplier = 1.2f; if (config.BuildType == BuildTypesEnum.MODULES && config.CategoryType == CategoryTypesEnum.WEAPONRY) { MyModel baseModel = null; MyModel barrelModel = null; Matrix baseMatrix = Matrix.Identity; Matrix barrelMatrix = Matrix.Identity; bool result = MyLargeShipGunBase.GetVisualPreviewData(enumValue, ref baseModel, ref barrelModel, ref baseMatrix, ref barrelMatrix); if (result) { m_setup.ViewMatrix = Matrix.Identity; setupRenderElement(baseModel, baseMatrix); setupRenderElement(barrelModel, barrelMatrix); setupLights(baseModel); MyRender.PushRenderSetup(m_setup); MyRender.Draw(); MyRender.PopRenderSetup(); BlitToThumbnail(device, renderTarget); } } else { //load new model from prefab config MyModel model = MyModels.GetModelForDraw(config.ModelLod0Enum); float distance = 1.85f; Matrix viewMatrix = Matrix.Identity; m_setup.ViewMatrix = viewMatrix; //generate world matrix Matrix worldMatrix = Matrix.Identity; worldMatrix.Translation = -model.BoundingSphere.Center; worldMatrix *= Matrix.CreateRotationY(-.85f * MathHelper.PiOver4); worldMatrix *= Matrix.CreateRotationX(.35f * MathHelper.PiOver4); worldMatrix.Translation += new Vector3(0, 0, -model.BoundingSphere.Radius * distance); setupRenderElement(model, worldMatrix); setupLights(model); MyRender.PushRenderSetup(m_setup); MyRender.Draw(); MyRender.PopRenderSetup(); BlitToThumbnail(device, renderTarget); } MyRender.SunIntensityMultiplier = previousSunIntensityMultiplier; if (MySession.PlayerShip != null) { MySession.PlayerShip.Visible = true; } return(renderTarget); }
public override bool StartShooting() { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyLargeShipMissileLauncherBarrel::StartShooting"); LastShotId = null; int missileShotInterval = 0; MyLargeShipGunBase.GetMissileAmmoParams(GetAmmoType(), ref missileShotInterval); if ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot) < missileShotInterval) { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); return(false); } m_burstFinish = false; while (!m_burstFinish) { if (!base.StartShooting()) { MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); return(false); } if (m_groupMask == null) { MyPhysics.physicsSystem.GetRigidBodyModule().GetGroupMaskManager().GetGroupMask(ref m_groupMask); } MyEntity target = ((MyLargeShipGunBase)Parent).GetTarget(); List <MyModelDummy> muzzles = GetMuzzleFlashMatrix(); m_activeMuzzle = --m_burstToFire; Matrix worldMatrix = WorldMatrix; Vector3 muzzleFlashPosition = MyUtils.GetTransform(muzzles[m_activeMuzzle].Matrix.Translation, ref worldMatrix); if (IsControlledByPlayer()) { //target = MySession.PlayerShip.TargetEntity as MySmallShip; target = MyEnemyTargeting.SwitchNextTarget(true); } if (target != null || IsControlledByPlayer()) { MySoundCue?shootingSound = GetWeaponBase().UnifiedWeaponCueGet(MySoundCuesEnum.WepMissileLaunch3d); if (shootingSound == null || !shootingSound.Value.IsPlaying) { GetWeaponBase().UnifiedWeaponCueSet(Audio.MySoundCuesEnum.WepMissileLaunch3d, MyAudio.AddCue2dOr3d(this.GetWeaponBase().PrefabParent, Audio.MySoundCuesEnum.WepMissileLaunch3d, muzzleFlashPosition, WorldMatrix.Forward, WorldMatrix.Up, Vector3.Zero)); //MyAudio.AddCue2dOr3d(this.GetWeaponBase().PrefabParent, Audio.MySoundCuesEnum.WepMissileLaunch3d, muzzleFlashPosition, WorldMatrix.Forward, WorldMatrix.Up, Vector3.Zero); } Vector3 deviateVector = GetDeviatedVector(MyAmmoConstants.GetAmmoProperties(GetAmmoType())); var missile = MyMissiles.Add(GetAmmoType(), muzzleFlashPosition + 2 * WorldMatrix.Forward, WorldMatrix.Forward * 2.0f, deviateVector, Vector3.Zero, this, target, SearchingDistance, isLightWeight: true); if (missile.GuidedInMultiplayer) { missile.EntityId = MyEntityIdentifier.AllocateId(); MyEntityIdentifier.AddEntityWithId(missile); LastShotId = missile.EntityId; } } if (m_burstToFire <= 0) { m_burstFireTime_ms = MyMinerGame.TotalGamePlayTimeInMilliseconds; m_burstToFire = m_burstFireCount; m_burstFinish = true; } if ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_burstFireTime_ms) > m_burstFireTimeLoadingIntervalConst_ms) { m_burstFinish = false; } if (!IsControlledByPlayer()) { m_burstFinish = true; } } m_lastTimeShoot = MyMinerGame.TotalGamePlayTimeInMilliseconds; MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(); return(true); }
public void Init(StringBuilder hudLabelText, MyModelsEnum modelEnum, int burstFireCount, Matrix localMatrix, MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum ammoType, MyLargeShipGunBase parentObject) { base.Init(hudLabelText, modelEnum, null, localMatrix, ammoType, parentObject); m_burstFireCount = burstFireCount; m_burstToFire = m_burstFireCount; m_burstFireTime_ms = MyMinerGame.TotalGamePlayTimeInMilliseconds; // User settings: m_burstFireTimeLoadingIntervalConst_ms = 2000; // This is imoprtant for missile launchers (they are not able to lauchching rackets on safe trajectory) //BarrelElevationMin = 0.1571f; BarrelElevationMin = -0.6f; }
public void Init(StringBuilder hudLabelText, Matrix localMatrix, MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum AmmoType, MyLargeShipGunBase parentObject) { base.Init(hudLabelText, MyModelsEnum.LargeShipMachineGunBarrel, null, localMatrix, AmmoType, parentObject); // Muzzle flash position from the dummy on the model: Matrix muzzleFlashDummy = ModelLod0 != null ? ModelLod0.Dummies["MUZZLE_FLASH"].Matrix : Matrix.Identity; m_muzzleFlashStartPosition = muzzleFlashDummy.Translation; }