/*protected virtual void OnHit(Shape shape, Vec3 normal, MapObject obj) * { * if (obj != null) * { * AKunit akunit = obj as AKunit; * if (akunit == null) * { * //impulse * float impulse = Type.Impulse * DamageCoefficient; * if (impulse != 0 && obj.PhysicsModel != null) * { * shape.Body.AddForce(ForceType.GlobalAtGlobalPos, 0, * Rotation.GetForward() * impulse, Position); * } * * //damage * Dynamic dynamic = obj as Dynamic; * if (dynamic != null) * { * float damage = Type.Damage * DamageCoefficient; * if (damage != 0) * dynamic.DoDamage(this, Position, shape, damage, true); * } * } * else * { * //impulse * float impulse = Type.Impulse * DamageCoefficient; * if (impulse != 0 && obj.PhysicsModel != null) * { * shape.Body.AddForce(ForceType.GlobalAtGlobalPos, 0, * Rotation.GetForward() * impulse, Position); * } * * // damage * float damage = Type.Damage * DamageCoefficient; * if (damage != 0) * { * akunit.AKunitDoDamage(shape, damage, akunit); * } * } * } * * Die(); * }*/ protected virtual void OnHit(Shape shape, Vec3 normal, MapObject obj) { if (obj != null) { //impulse float impulse = Type.Impulse * DamageCoefficient; if (impulse != 0 && obj.PhysicsModel != null && shape != null) { shape.Body.AddForce(ForceType.GlobalAtGlobalPos, 0, Rotation.GetForward() * impulse, Position); } //damage Dynamic dynamic = obj as Dynamic; if (dynamic != null) { float damage = Type.Damage * DamageCoefficient; if (damage != 0) { dynamic.DoDamage(this, Position, shape, damage, true); } AKunit ak = obj as AKunit; if (ak != null) { ak.AKunitHeat += Type.HitHeat; } } } HitObjects_Create(); Die(); }
private AKunit.BP GetBodyPart(string bodyPartName) { if (spawner.Spawned as AKunit != null) { return(null); } AKunit ut = spawner.Spawned as AKunit; if (ut == null) { return(null); } AKunit.BP selectedBodyPart = null; foreach (AKunit.BP bp in ut.Bp) { if (bp.GUIDesplayName == bodyPartName) { selectedBodyPart = bp; break; } } if (selectedBodyPart == null) { Log.Error(string.Format("Body part \"{0}\" not found on {1}", bodyPartName, spawner.Spawned.Name)); } return(selectedBodyPart); }
private void cbxVariantList_SelectedIndexChange(ListBox sender) { if (sender.SelectedItem == null) { return; } string varFilePath = string.Format("{0}\\Variants\\{1}\\{2}", VirtualFileSystem.UserDirectoryPath, spawner.Spawned.Type.Name, sender.SelectedItem.ToString()); string error; TextBlock varFile = TextBlockUtils.LoadFromRealFile(varFilePath, out error); if (!string.IsNullOrEmpty(error)) { Log.Error(error); return; } if (varFile != null) { AKunit u = spawner.Spawned as AKunit; u.SetVariant(varFile); } }
private void spawner_UnitSpawned(Unit unit) { AKunit ut = unit as AKunit; cbxWeaponSlots.Items.Clear(); lstWeaponList.Items.Clear(); cbxVariantList.Items.Clear(); btnRA.Enable = btnRA.Active = false; btnRT.Enable = btnRT.Active = false; btnCT.Enable = btnCT.Active = false; btnLT.Enable = btnLT.Active = false; btnLA.Enable = btnLA.Active = false; foreach (AKunit.BP bp in ut.Bp) { if (window.Controls[bp.GUIDesplayName] != null) { window.Controls[bp.GUIDesplayName].Enable = true; } } variant = new TextBlock(); /*foreach (AKunit.BP bp in ut.Bp) * { * TextBlock bpBlock = variant.AddChild(bp.GUIDesplayName); * * foreach (AKunitType.WeaponItem w in bp.Weapons) * { * TextBlock wBlock = bpBlock.AddChild(w.MapObjectAlias); * * wBlock.SetAttribute("Ammo", w.Ammo.ToString()); * wBlock.SetAttribute("MagazineCapacity", w.MagazineCapacity.ToString()); * wBlock.SetAttribute("WeaponType", w.WeaponType.Name); * } * }*/ //load up variant file names string varDir = string.Format("{0}\\Variants\\{1}", VirtualFileSystem.UserDirectoryPath, spawner.Spawned.Type.Name); if (Directory.Exists(varDir)) { DirectoryInfo di = new DirectoryInfo(varDir); FileInfo[] files = di.GetFiles(); foreach (FileInfo file in files) { cbxVariantList.Items.Add(file.Name); } } }
public override bool TryFire(bool alternative) { if (!Ready) { return(false); } Mode mode = alternative ? alternativeMode : normalMode; if (mode.typeMode.BulletType == null) { return(false); } bool permit = mode.BulletCount >= mode.typeMode.BulletExpense; if (mode.typeMode.MagazineCapacity != 0) { if (mode.BulletMagazineCount < mode.typeMode.BulletExpense) { permit = false; } } if (!permit) { //no ammo SoundPlay3D(Type.SoundEmpty, .5f, true); readyTimeRemaining = mode.typeMode.BetweenFireTime; TryReload(); if (EntitySystemWorld.Instance.IsServer() && Type.NetworkType == EntityNetworkTypes.Synchronized) { Server_SendNoAmmoEventToAllClients(); } return(false); } AKunit parentAKunit = GetParentUnit() as AKunit; if (parentAKunit != null && parentAKunit.MechShutDown != true) { Fire(mode); } else if (parentAKunit == null) { Fire(mode); } return(true); }
private void lstWeaponList_SelectedIndexChange(ListBox sender) { if (lstWeaponList.SelectedItem == null) { return; } //get default weaponType on the selected slot AKunit u = spawner.Spawned as AKunit; AKunitType.WeaponItem wi = cbxWeaponSlots.SelectedItem as AKunitType.WeaponItem; AKunitType.AlternateWeaponItem awi = lstWeaponList.SelectedItem as AKunitType.AlternateWeaponItem; string selectedBodyPartName = GetBodyPartNameFromActiveButton(); int selectedBodyPartIndex = GetBodyPartIndex(selectedBodyPartName); string weaponAlias = wi.MapObjectAlias; MapObjectAttachedObject o = u.GetFirstAttachedObjectByAlias(weaponAlias); MapObjectAttachedMapObject mo = o as MapObjectAttachedMapObject; u.Detach(mo); Weapon w = Entities.Instance.Create(awi.WeaponType, Map.Instance) as Weapon; w.PostCreate(); MapObjectAttachedMapObject amo = new MapObjectAttachedMapObject(); amo.MapObject = w; amo.PositionOffset = mo.PositionOffset; amo.Alias = mo.Alias; amo.Body = mo.Body; amo.BoneSlot = mo.BoneSlot; amo.RotationOffset = mo.RotationOffset; amo.ScaleOffset = mo.ScaleOffset; u.Attach(amo); Gun g = w as Gun; float multiplier = 1 / g.Type.NormalMode.BetweenFireTime; float rateOfFire = multiplier; if (g.Type.NormalMode.BulletExpense != 0) { rateOfFire = rateOfFire * g.Type.NormalMode.BulletExpense; } txtWeaponInfo.Text = string.Format( "Weapon Name: {0}\r\nWeapon Type: {1}\r\nDamage: {2}\r\nHeat: {3}\r\nRate of Fire: {4}\r\nPrice: {5}", w.Type.Name, "Not Implemented", g.Type.NormalMode.BulletType.Damage, g.Type.NormalMode.AKGunHeatGeneration, rateOfFire.ToString("F1"), awi.Price); }
private void btnAddWeapon_Click(Button sender) { if (cbxWeaponSlots.SelectedItem == null || lstWeaponList.SelectedItem == null) { return; } AKunit u = spawner.Spawned as AKunit; AKunitType.WeaponItem wi = cbxWeaponSlots.SelectedItem as AKunitType.WeaponItem; AKunitType.AlternateWeaponItem awi = lstWeaponList.SelectedItem as AKunitType.AlternateWeaponItem; string selectedBodyPartName = GetBodyPartNameFromActiveButton(); int selectedBodyPartIndex = GetBodyPartIndex(selectedBodyPartName); int weaponFireGroup = u.Bp[selectedBodyPartIndex].Weapons[cbxWeaponSlots.SelectedIndex].FireGroup; u.Bp[selectedBodyPartIndex].Weapons[cbxWeaponSlots.SelectedIndex].Ammo = awi.Ammo; u.Bp[selectedBodyPartIndex].Weapons[cbxWeaponSlots.SelectedIndex].MagazineCapacity = awi.MagazineCapacity; u.Bp[selectedBodyPartIndex].Weapons[cbxWeaponSlots.SelectedIndex].WeaponType = awi.WeaponType; TextBlock bodyPartBlock = variant.FindChild(selectedBodyPartName); if (bodyPartBlock == null) { bodyPartBlock = variant.AddChild(selectedBodyPartName); } if (bodyPartBlock != null) { TextBlock wBlock = bodyPartBlock.FindChild(wi.MapObjectAlias); if (wBlock == null) { wBlock = bodyPartBlock.AddChild(wi.MapObjectAlias); } if (wBlock != null) { wBlock.SetAttribute("i", lstWeaponList.SelectedIndex.ToString()); wBlock.SetAttribute("g", weaponFireGroup.ToString()); } } UpdateVariantCost(awi.Price); PopulateWeaponSlotsDropDown(selectedBodyPartName); }
private void spawner_UnitSpawned(Unit unit) { AKunit u = unit as AKunit; if (u == null) { return; } lstWeapons.Items.Clear(); foreach (AKunit.WeaponItem item in u.Weapons) { lstWeapons.Items.Add(item.Weapon.Type.Name); } }
private int GetBodyPartIndex(string bodyPartName) { AKunit ut = spawner.Spawned as AKunit; //foreach (AKunitType.BodyPart bp in ut.BodyParts) for (int i = 0; i < ut.Bp.Count; i++) { AKunit.BP bp = ut.Bp[i]; if (bp.GUIDesplayName == bodyPartName) { return(i); } } return(-1); }
private void UpdateAttackTasksControlKeys() { ControlKeyRelease(GameControlKeys.Fire1); ControlKeyRelease(GameControlKeys.Fire2); foreach (AttackTask attackTask in attackTasks) { //Tank specific AKunit Akunit = ControlledObject as AKunit; if (Akunit != null) { if (attackTask.Weapon.Ready) { MissileLauncher msl = attackTask.Weapon as MissileLauncher; if (msl != null) { MissileType mtype = msl.NormalMode.typeMode.BulletType as MissileType; if (mtype == null || attackTask.TaskTime < mtype.LockingTime) { continue; } else { Akunit.CurrentMissileTarget = attackTask.TargetEntity as Unit; } } Akunit.MainGun = (Gun)attackTask.Weapon; Vec3 targetPos = CalculateTargetPosition(attackTask); //turn turret Akunit.SetNeedTurnToPosition(targetPos); //fire if (IsWeaponDirectedToTarget(attackTask)) { ControlKeyPress(GameControlKeys.Fire1, 1); } } } } }
public override bool TryFire(bool alternative) { AKunit mech = this.AttachedMapObjectParent as AKunit; if (mech != null) { if (mech.CurrentMissileTarget == null || mech.CurrentMissileTarget.Died) { return(false); } else { //blast away!! base.TryFire(alternative); return(true); } } return(false); }
public void SpawnNewUnit(UnitType unitType, int[] variant) { Spawner s = FindFirstFreeSpawner(); /*AKunit newUnit = (AKunit)Entities.Instance.Create(unitType, Map.Instance); * * newUnit.Position = s.Position + new Vec3(0, 0, unitType.SpawnHight); * newUnit.Rotation = s.Rotation; * * newUnit.PostCreate();*/ AKunit newUnit = s.CreateUnit(unitType) as AKunit; if (variant != null) { if (EntitySystemWorld.Instance.IsServer() || EntitySystemWorld.Instance.IsSingle()) { newUnit.Server_SetVariant(variant); } } }
private void UpdateTurnToPositionForUnits(Vec3 turnToPosition) { //Character Character character = ControlledObject as Character; if (character != null) { character.SetTurnToPosition(turnToPosition); } //Turret Turret turret = ControlledObject as Turret; if (turret != null) { turret.SetMomentaryTurnToPosition(turnToPosition); } //Tank Tank tank = ControlledObject as Tank; if (tank != null) { tank.SetNeedTurnToPosition(turnToPosition); } //AKunit AKunit akunit = ControlledObject as AKunit; if (akunit != null) { akunit.SetNeedTurnToPosition(turnToPosition); } //if(Damagerball) ---INCIN check here }
private void TickIntellect() { //GUItest(); JetEngineBooster(); VSI = AKJetBody.LinearVelocity.Z - (AKJetBody.LinearVelocity.Z % 1); float speed = GetRealSpeed(); float ControlersRatio; MapObjectAttachedParticle ENBoosterParticle2 = GetFirstAttachedObjectByAlias("JetFire") as MapObjectAttachedParticle; AKunit akunit = GetPlayerUnit() as AKunit; Vec3 dir = AKJetBody.Rotation.GetForward(); AKJetOn = Intellect != null && Intellect.IsActive(); MASS = 0; foreach (Body body in PhysicsModel.Bodies) { MASS += body.Mass; } // controlers Ratio if (speed > 0) { ControlersRatio = speed / 80; if (ControlersRatio > 1) { ControlersRatio = 1; } } else { ControlersRatio = 0; } // controlers Ratio //////////////////////// WING WING WING WING WING WING WING WING WING WING WING ///////////////////////////////// //wing General Angles BodyAngles = Rotation.GetInverse().ToAngles(); float normalizeRoll = BodyAngles.Roll; if (normalizeRoll < 0) { normalizeRoll = -normalizeRoll; } float PitchUp = -BodyAngles.Pitch; if (PitchUp < 0) { PitchUp = 0; } if (PitchUp > 90) { PitchUp = 90 - (PitchUp - 90); } float PitchDown = BodyAngles.Pitch; if (PitchDown < 0) { PitchDown = 0; } if (PitchDown > 90) { PitchDown = 90 - (PitchDown - 90); } //End of Wing GENERAL //Wing Anti Gravity Force & Stall float WingUpForce; if (speed < 40f) { //stall if (VSI < 0 && PitchUp > 35f) { Stall = true; } else { Stall = false; } //force WingUpForce = ((speed / 4f) - 0.2f); } else if (speed > 40f) { WingUpForce = -PhysicsWorld.Instance.MainScene.Gravity.Z; //WingUpForce = 9.8f; //TODO:Incin change to map gravity } else { WingUpForce = 0; } //antigrav AKJetBody.AddForce(ForceType.GlobalAtLocalPos, TickDelta, AKJetBody.Rotation * new Vec3(0, 0, WingUpForce) * MASS, Vec3.Zero); //antivelo AKJetBody.AddForce(ForceType.GlobalAtLocalPos, TickDelta, AKJetBody.Rotation * new Vec3((-WingUpForce * PitchUp / 9) / 4, 0, 0) * MASS, Vec3.Zero); //END oF Wing Anit Gravity Force & Stall //Wing Decenging Force float DecendSpeedForce; if (VSI < 0 && PitchUp == 0) { DecendSpeedForce = (180 - normalizeRoll) + PitchDown; AKJetBody.AddForce(ForceType.GlobalAtLocalPos, TickDelta, AKJetBody.Rotation * new Vec3(DecendSpeedForce / 20, 0, 0) * MASS, Vec3.Zero); } //End of Wing Decenging Force /////// END END END ///OF OF OF/// WING WING WING WING WING WING WING WING WING WING WING ////////////////////////////// //engine force + sound pitch control if (Intellect.IsControlKeyPressed(GameControlKeys.Jump)) { if (akunit != null) { akunit.GunsTryFire(false); } } if (Intellect.IsControlKeyPressed(GameControlKeys.Forward)) { force += forceadd; } if (Intellect.IsControlKeyPressed(GameControlKeys.Backward)) { force -= forceadd; } if (ENBoosterParticle2 != null) { if (force > 85f) { ENBoosterParticle2.Visible = true; } else { ENBoosterParticle2.Visible = false; } } enpitch = (force / 80f); MathFunctions.Clamp(ref force, 0.1f, 100); MathFunctions.Clamp(ref enpitch, 0.8f, 1.3f); //update jet channel position and pitch if (rotorSoundChannel != null) { //update channel rotorSoundChannel.Pitch = enpitch; rotorSoundChannel.Volume = 1; rotorSoundChannel.Position = Position; //rotorSoundChannel.MinDistance = 10; } //end of engine force + sound pitch control //Forces //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //start jet Pitch (Y turn) if (Intellect.IsControlKeyPressed(GameControlKeys.Arrow_Up) || Intellect.IsControlKeyPressed(GameControlKeys.Arrow_Down)) { float AUp = Intellect.GetControlKeyStrength(GameControlKeys.Arrow_Up) / 2; float ADown = Intellect.GetControlKeyStrength(GameControlKeys.Arrow_Down) / 2; Hpitch += (AUp - ADown); MathFunctions.Clamp(ref Hpitch, -10, 10); } else { if (Hpitch != 0) { Hpitch -= Hpitch / 5; if ((Hpitch - (Hpitch % 1)) == 0) { Hpitch = 0; } } else { float mammadpitch = (AKJetBody.AngularVelocity * AKJetBody.Rotation.GetInverse()).Y * 2; MathFunctions.Clamp(ref mammadpitch, -10f, 10); AKJetBody.AddForce(ForceType.GlobalAtLocalPos, TickDelta, AKJetBody.Rotation * new Vec3(0, 0, -mammadpitch) * MASS, new Vec3(-8, 0, 0)); } } if (Hpitch != 0) { AKJetBody.AddForce(ForceType.GlobalTorque, TickDelta, AKJetBody.Rotation * new Vec3(0, ((Hpitch) * ControlersRatio), 0) * MASS, Vec3.Zero); } //end of jet pitch (Y turn) //start jet Z turn if (Intellect.IsControlKeyPressed(GameControlKeys.Right) || Intellect.IsControlKeyPressed(GameControlKeys.Left)) { float right = Intellect.GetControlKeyStrength(GameControlKeys.Right) / 2; float left = Intellect.GetControlKeyStrength(GameControlKeys.Left) / 2; TrunZ += (left - right); MathFunctions.Clamp(ref TrunZ, -10, 10); } else { if (TrunZ != 0) { TrunZ -= TrunZ / 5; if ((TrunZ - (TrunZ % 1)) == 0) { TrunZ = 0; } } } if (TrunZ != 0) { AKJetBody.AddForce(ForceType.GlobalTorque, TickDelta, AKJetBody.Rotation * new Vec3(0, 0, (TrunZ * 2) * ControlersRatio) * MASS, Vec3.Zero); } //end of jet Z turn //start jet X turn if (Intellect.IsControlKeyPressed(GameControlKeys.Arrow_Right) || Intellect.IsControlKeyPressed(GameControlKeys.Arrow_Left)) { float rightX = Intellect.GetControlKeyStrength(GameControlKeys.Arrow_Right) / 2; float leftX = Intellect.GetControlKeyStrength(GameControlKeys.Arrow_Left) / 2; TrunX += (rightX - leftX); MathFunctions.Clamp(ref TrunX, -10, 10); } else { if (TrunX != 0) { TrunX -= TrunX / 5; if ((TrunX - (TrunX % 1)) == 0) { TrunX = 0; } } } if (TrunX != 0) { AKJetBody.AddForce(ForceType.GlobalTorque, TickDelta, AKJetBody.Rotation * new Vec3(((TrunX * 2) * ControlersRatio), 0, 0) * MASS, Vec3.Zero); } //Pitch on Turn Pitch //float TurnPitch = AKJetBody.Rotation.GetInverse().ToAngles().Roll; //1 - Rotation.GetUp().Z; //if (TurnPitch < 0) TurnPitch = -TurnPitch; //if (TurnPitch > 90) TurnPitch = 90 - (TurnPitch - 90); //AKJetBody.AddForce(ForceType.GlobalTorque, TickDelta, // AKJetBody.Rotation * new Vec3(0, ((-TurnPitch /90) * ControlersRatio), 0) * MASS, Vec3.Zero); //End of Pitch on Turn //end of jet X turn //start of adding main Engine force MathFunctions.Clamp(ref force, 0.1f, 100); //if Max Alt is not reached add jet motor force if (AKJetBody.Position.Z < Type.MaxAlt) { float FinalEngineForce = (force / 2f) - ((PitchUp / 90) * 30); AKJetBody.AddForce(ForceType.LocalAtLocalPos, TickDelta, new Vec3(FinalEngineForce, 0, 0) * MASS, Vec3.Zero); } //dampings AKJetBody.AngularDamping = 2f + (speed / 60); AKJetBody.LinearDamping = 0.4f; }
private void TickIntellect() { GUIshit(); MapObjectAttachedParticle JetFire1 = GetFirstAttachedObjectByAlias("JetFire1") as MapObjectAttachedParticle; MapObjectAttachedParticle JetFire2 = GetFirstAttachedObjectByAlias("JetFire2") as MapObjectAttachedParticle; float speed = GetRealSpeed(); AKunit akunit = GetPlayerUnit() as AKunit; Vec3 dir = AKVTOLBody.Rotation.GetForward(); Radian slopeAngle = MathFunctions.ATan(dir.Z, dir.ToVec2().Length()); MASS = 0; foreach (Body body in PhysicsModel.Bodies) { MASS += body.Mass; } ShiftBooster(); AKVTOLOn = Intellect != null && Intellect.IsActive(); // GUItest(); ALTray(); //engine force + sound pitch control if (Intellect.IsControlKeyPressed(GameControlKeys.Jump)) { if (akunit != null) { akunit.GunsTryFire(false); } } if (Intellect.IsControlKeyPressed(GameControlKeys.Forward)) { force += forceadd; } else if (Intellect.IsControlKeyPressed(GameControlKeys.Backward)) { force -= forceadd; } else { } if (Intellect.IsControlKeyPressed(GameControlKeys.VerticleTakeOff_L_EngineUp)) { EngineDir += 2f; } else if (Intellect.IsControlKeyPressed(GameControlKeys.VerticleTakeOff_L_EngineDown)) { EngineDir -= 2f; } else { } MathFunctions.Clamp(ref EngineDir, 0, 90); EngineApp.Instance.ScreenGuiRenderer.AddText("Throttle: " + force, new Vec2(.6f, .1f)); if (JetFire1 != null && JetFire2 != null) { if (force > 85f) { JetFire1.Visible = true; JetFire2.Visible = true; } else { JetFire1.Visible = false; JetFire2.Visible = false; } } enpitch = 0.8f + (0.6f * (force / 100)); MathFunctions.Clamp(ref force, 0.1f, 100); MathFunctions.Clamp(ref enpitch, 0.8f, 1.4f); //update jet channel position and pitch if (rotorSoundChannel != null) { //update channel rotorSoundChannel.Pitch = enpitch; rotorSoundChannel.Volume = 1; rotorSoundChannel.Position = Position; //rotorSoundChannel.MinDistance = 10; } //end of engine force + sound pitch control //Forces //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //start VTOL Pitch (Y turn) if (Intellect.IsControlKeyPressed(GameControlKeys.Arrow_Up) || Intellect.IsControlKeyPressed(GameControlKeys.Arrow_Down)) { float AUp = Intellect.GetControlKeyStrength(GameControlKeys.Arrow_Up) / 2; float ADown = Intellect.GetControlKeyStrength(GameControlKeys.Arrow_Down) / 2; Hpitch += (AUp - ADown); MathFunctions.Clamp(ref Hpitch, -10, 10); } else { if (Hpitch != 0) { Hpitch -= Hpitch / 5; if ((Hpitch - (Hpitch % 1)) == 0) { Hpitch = 0; } } else { float mammadpitch = (AKVTOLBody.AngularVelocity * AKVTOLBody.Rotation.GetInverse()).Y * 2; MathFunctions.Clamp(ref mammadpitch, -10f, 10); AKVTOLBody.AddForce(ForceType.GlobalAtLocalPos, TickDelta, AKVTOLBody.Rotation * new Vec3(0, 0, -mammadpitch) * MASS, new Vec3(-8, 0, 0)); EngineApp.Instance.ScreenGuiRenderer.AddText("MammadPitch: " + mammadpitch.ToString(), new Vec2(.1f, .2f)); } } if (Hpitch != 0) { AKVTOLBody.AddForce(ForceType.GlobalTorque, TickDelta, AKVTOLBody.Rotation * new Vec3(0, Hpitch, 0) * MASS, Vec3.Zero); } //end of VTOL pitch (Y turn) //start jet Z turn if (Intellect.IsControlKeyPressed(GameControlKeys.Right) || Intellect.IsControlKeyPressed(GameControlKeys.Left)) { float right = Intellect.GetControlKeyStrength(GameControlKeys.Right) / 2; float left = Intellect.GetControlKeyStrength(GameControlKeys.Left) / 2; TrunZ += (left - right); MathFunctions.Clamp(ref TrunZ, -10, 10); AKVTOLBody.AddForce(ForceType.LocalTorque, TickDelta, new Vec3(0, 0, TrunZ * 2) * MASS, Vec3.Zero); } else { TrunZ = 0; } //end of jet Z turn //start jet X turn if (Intellect.IsControlKeyPressed(GameControlKeys.Arrow_Right) || Intellect.IsControlKeyPressed(GameControlKeys.Arrow_Left)) { float rightX = Intellect.GetControlKeyStrength(GameControlKeys.Arrow_Right) / 2; float leftX = Intellect.GetControlKeyStrength(GameControlKeys.Arrow_Left) / 2; TrunX += (rightX - leftX); MathFunctions.Clamp(ref TrunX, -10, 10); AKVTOLBody.AddForce(ForceType.GlobalTorque, TickDelta, AKVTOLBody.Rotation * new Vec3(TrunX * 2, 0, 0) * MASS, Vec3.Zero); } else { TrunX = 0; } float SHOOT = AKVTOLBody.Rotation.GetInverse().ToAngles().Roll; //1 - Rotation.GetUp().Z; if (SHOOT < 0) { SHOOT = -SHOOT; } if (SHOOT > 90) { SHOOT = 90 - (SHOOT - 90); } AKVTOLBody.AddForce(ForceType.GlobalAtLocalPos, TickDelta, AKVTOLBody.Rotation * new Vec3(0, 0, -SHOOT / 180) * MASS, new Vec3(-8, 0, 0)); //end of jet X turn ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //adding anty Y movment force float Yshit = (AKVTOLBody.LinearVelocity * Rotation.GetInverse()).Y; EngineApp.Instance.ScreenGuiRenderer.AddText("Yshit: " + Yshit.ToString(), new Vec2(.6f, .3f)); EngineApp.Instance.ScreenGuiRenderer.AddText("roll: " + Rotation.ToAngles().Roll, new Vec2(.6f, .35f)); EngineApp.Instance.ScreenGuiRenderer.AddText("roll: " + (Rotation.GetInverse().ToAngles()).ToString(), new Vec2(.6f, .4f)); EngineApp.Instance.ScreenGuiRenderer.AddText("Edir: " + EngineDir.ToString(), new Vec2(.1f, .6f)); //start of adding force MathFunctions.Clamp(ref force, 0.1f, 100); EngineApp.Instance.ScreenGuiRenderer.AddText("speed: " + GetRealSpeed().ToString(), new Vec2(.6f, .15f)); GUItest(); //anti gravity when jet have speed (wings force) float antyshityforcy = GetRealSpeed() / 10; float slopeangleshit = 1.5f; MathFunctions.Clamp(ref antyshityforcy, 0, 10); if (slopeAngle > 0) { slopeangleshit = 1.5f - slopeAngle; } else { slopeangleshit = 0.5f; } if (GetRealSpeed() > 0) { AKVTOLBody.AddForce(ForceType.LocalAtLocalPos, TickDelta, new Vec3(0, 0, antyshityforcy * slopeangleshit) * MASS, Vec3.Zero); } //if Max Alt is not reached add jet motor force if (AKVTOLBody.Position.Z < Type.MaxAlt) { AKVTOLBody.AddForce(ForceType.GlobalAtLocalPos, TickDelta, AKVTOLBody.Rotation * new Vec3(force / 2f * ((90 - EngineDir) / 90), 0, force / 8f * (EngineDir / 90)) * MASS, Vec3.Zero); } //dampings AKVTOLBody.AngularDamping = 2f + (speed / 60); AKVTOLBody.LinearDamping = 0.6f; ServoMotor Lenginem = PhysicsModel.GetMotor("LEngineM") as ServoMotor; ServoMotor Renginem = PhysicsModel.GetMotor("REngineM") as ServoMotor; if (Lenginem != null && Renginem != null) { float EngingDirRad = EngineDir * MathFunctions.PI / 180; Renginem.DesiredAngle = EngingDirRad; Lenginem.DesiredAngle = EngingDirRad; } }
protected override void OnTick() { base.OnTick(); if (target == null) { return; } if (firstTick) { startDistance = (target.Position - Position).Length(); firstTick = false; // NH & KEEN - if our target is a unit, select a random bodypart to target, otherwise check if there is a physics body to follow AKunit targetUnit = target as AKunit; if (targetUnit != null) { if (targetUnit.PhysicsModel != null && targetUnit.PhysicsModel.Bodies.Length != 0) { string targetBodyName = targetUnit.Type.BodyParts[World.Instance.Random.Next(0, targetUnit.Type.BodyParts.Count)].PhysicsShape; FindTargetShape(targetUnit, targetBodyName, out targetBody, out targetShape); } } else { if (target.PhysicsModel != null && target.PhysicsModel.Bodies.Length != 0) { targetBody = target.PhysicsModel.Bodies[0]; } } } if (currentDelay < Type.HomingDelay) { currentDelay += TickDelta; return; } // NH & KEEN - lose target if it is out of our view angle (stops missiles from doing endless circles around the target) if (Type.HomingAngle < 360.0f) { float homingAngle = Type.HomingAngle / 2; if (CalculateAngleToTarget(target) > new Degree(homingAngle).InRadians()) { target = null; return; } } // NH & KEEN - explode if we get closer than proximityDistance to the target (used for Bluestreak Missiles) if ((target.Position - Position).Length() < Type.ProximityDistance) { HitObjects_Create(); Die(); } if (Type.HomingCorrection > 0) { MomentaryTurnToPositionUpdate(target.Position); } Vec3 velocity = Rotation.GetForward().GetNormalize() * Type.Velocity; base.Velocity = velocity; }
protected virtual void Fire(Mode mode) { bool alternative = mode == AlternativeMode; if (Damaged == true) { SoundPlay3D(Type.SoundEmpty, .5f, true); return; } AKunit parentAKunit = GetParentUnit() as AKunit; if (parentAKunit != null) { parentAKunit.GunHeat(Type.NormalMode.AKGunHeatGeneration); } DoPreFireEvent(alternative); if (Type.NormalMode.BulletType == Type.AlternativeMode.BulletType) { if (normalMode.typeMode.MagazineCapacity != 0) { normalMode.BulletMagazineCount -= normalMode.typeMode.BulletExpense; if (normalMode.BulletMagazineCount < 0) { Log.Fatal("Gun: NormalMode: BulletMagazineCount < 0"); } } normalMode.BulletCount -= normalMode.typeMode.BulletExpense; if (normalMode.BulletCount < 0) { Log.Fatal("Gun: NormalMode: BulletCount < 0"); } if (alternativeMode.typeMode.MagazineCapacity != 0) { alternativeMode.BulletMagazineCount -= alternativeMode.typeMode.BulletExpense; if (normalMode.BulletMagazineCount < 0) { Log.Fatal("Gun: AlternativeMode: BulletMagazineCount < 0"); } } alternativeMode.BulletCount -= alternativeMode.typeMode.BulletExpense; if (normalMode.BulletCount < 0) { Log.Fatal("Gun: AlternativeMode: BulletCount < 0"); } } else { if (mode.typeMode.MagazineCapacity != 0) { mode.BulletMagazineCount -= mode.typeMode.BulletExpense; if (mode.BulletMagazineCount < 0) { Log.Fatal("Gun: {0}Mode: BulletMagazineCount < 0", mode == normalMode ? "Normal" : "Alternative"); } } mode.BulletCount -= mode.typeMode.BulletExpense; if (mode.BulletCount < 0) { Log.Fatal("Gun: {0}Mode: BulletCount < 0", mode == normalMode ? "Normal" : "Alternative"); } } readyTimeRemaining = mode.typeMode.BetweenFireTime; currentFireMode = mode; currentFireTime = 0; fireTimesExecuted = 0; //Create fireObjects if (mode.typeMode.FireTimes.Count == 0) { for (int n = 0; n < mode.typeMode.FireCount; n++) { CreateBullet(mode); } SoundPlay3D(mode.typeMode.SoundFire, .5f, true); mode.typeMode.FireObjects.CreateObjectsOfOneRandomSelectedGroup(this); if (EntitySystemWorld.Instance.IsServer() && Type.NetworkType == EntityNetworkTypes.Synchronized) { Server_SendCreateBulletEventToAllClients(mode); } } OnFire(mode.typeMode); if (EntitySystemWorld.Instance.IsServer() && Type.NetworkType == EntityNetworkTypes.Synchronized) { Server_SendFireEventToAllClients(alternative); } }
private Unit AquireNewTarget() { // NH & KEEN - reset the targetted bodypart targetBody = null; targetShape = null; Unit TempTarget = null; Bounds volume = new Bounds(this.Position); volume.Expand(new Vec3(Type.RadarRange, Type.RadarRange, Type.RadarRange)); Body[] result = PhysicsWorld.Instance.VolumeCast(volume, (int)ContactGroup.CastOnlyDynamic); foreach (Body body in result) { MapObject obj = MapSystemWorld.GetMapObjectByBody(body); if (obj != null) { Unit unit = obj as Unit; if (unit != null) { float Angletounit = CalculateAngleToTarget(unit); //0.8f in radian is 45 Degrees and the absoulote value whould give the missile a window of 90' float targettingAngle = Type.HomingAngle / 2; if (Angletounit > targettingAngle) { continue; } if (TempTarget == null) { TempTarget = unit; } else { float PreTargetDistance = (TempTarget.Position - Position).Length(); float newTargetDistance = (unit.Position - Position).Length(); float DifDis = PreTargetDistance - newTargetDistance; float DiftAngle = CalculateAngleToTarget(TempTarget) - Angletounit; if (DifDis > 0 && DiftAngle > 0) { TempTarget = unit; } } } } } // NH & KEEN - if our target is a unit, select a random bodypart to target, otherwise check if there is a physics body to follow if (TempTarget != null) { AKunit targetUnit = TempTarget as AKunit; if (targetUnit != null) { if (targetUnit.PhysicsModel != null && targetUnit.PhysicsModel.Bodies.Length != 0) { string targetBodyName = targetUnit.Type.BodyParts[World.Instance.Random.Next(0, targetUnit.Type.BodyParts.Count)].PhysicsShape; FindTargetShape(targetUnit, targetBodyName, out targetBody, out targetShape); } } else { if (TempTarget.PhysicsModel != null && TempTarget.PhysicsModel.Bodies.Length != 0) { targetBody = TempTarget.PhysicsModel.Bodies[0]; } } } return(TempTarget); }
public VariantSaveWindow(int variantCost, TextBlock variant, AKunit spawned) { this.spawned = spawned; this.variant = variant; cost = variantCost; }