Пример #1
0
        public void Fire(Vector3 point)
        {
            if (Parent.Parent.TryGetComponent <ShipPhysicsComponent>(out var flight) &&
                (flight.EngineState == EngineStates.Cruise || flight.EngineState == EngineStates.CruiseCharging))
            {
                return;
            }
            if (CurrentCooldown > 0)
            {
                return;
            }
            if (projectiles == null)
            {
                hpfires     = Parent.GetHardpoints().Where((x) => x.Name.StartsWith("hpfire", StringComparison.CurrentCultureIgnoreCase)).ToArray();
                projectiles = Parent.GetWorld().Projectiles;
                toSpawn     = projectiles.GetData(Object);
            }
            var  tr = (Parent.Attachment.Transform * Parent.Parent.WorldTransform);
            uint hp = CrcTool.FLModelCrc(Parent.Attachment.Name);

            for (int i = 0; i < hpfires.Length; i++)
            {
                var pos     = Vector3.Transform(Vector3.Zero, hpfires[i].Transform * tr);
                var normal  = Vector3.TransformNormal(-Vector3.UnitZ, hpfires[i].Transform * tr);
                var heading = (point - pos).Normalized();

                var angle = GetAngle(normal, heading);
                if (angle <= MathHelper.DegreesToRadians(40)) //TODO: MUZZLE_CONE_ANGLE constant
                {
                    projectiles.SpawnProjectile(Parent.Parent, hp, toSpawn, pos, heading);
                    projectiles.QueueProjectile(Parent.Parent.NetID, Object, hp, pos, heading);
                }
            }
            CurrentCooldown = Object.Def.RefireDelay;
        }
        void SetSelfLoadout(NetShipLoadout ld)
        {
            var sh = Game.GameData.GetShip((int)ld.ShipCRC);

            PlayerShip = sh.Nickname;
            var hpcrcs = new Dictionary <uint, string>();

            foreach (var hp in HardpointList(sh.ModelFile.LoadFile(Game.ResourceManager)))
            {
                hpcrcs.Add(CrcTool.FLModelCrc(hp), hp);
            }
            Mounts = new List <EquipMount>();
            foreach (var eq in ld.Equipment)
            {
                string hp;
                if (eq.HardpointCRC == 0)
                {
                    hp = null;
                }
                else
                {
                    hp = hpcrcs[eq.HardpointCRC];
                }
                Mounts.Add(new EquipMount(
                               hp,
                               Game.GameData.GetEquipment(eq.EquipCRC).Nickname
                               ));
            }
        }
Пример #3
0
        public GameObject(string name, RigidModel model, ResourceManager res, string partName, float mass, bool draw)
        {
            RigidModel = model;
            Resources  = res;
            PopulateHardpoints();
            if (draw && RigidModel != null)
            {
                RenderComponent = new ModelRenderer(RigidModel)
                {
                    Name = name
                };
            }
            var path = Path.ChangeExtension(RigidModel.Path, "sur");

            name = Path.GetFileNameWithoutExtension(RigidModel.Path);
            uint plainCrc = 0;

            if (!string.IsNullOrEmpty(partName))
            {
                plainCrc = CrcTool.FLModelCrc(partName);
            }
            if (File.Exists(path))
            {
                PhysicsComponent = new PhysicsComponent(this)
                {
                    SurPath  = path,
                    Mass     = mass,
                    PlainCrc = plainCrc
                };
                Components.Add(PhysicsComponent);
            }
        }
Пример #4
0
        void PlayerEnterBase()
        {
            //fetch news articles
            List <NewsArticle> news = new List <NewsArticle>();

            foreach (var x in Game.GameData.Ini.News.NewsItems.Where(NewsFind))
            {
                news.Add(new NewsArticle()
                {
                    Icon = x.Icon, Category = x.Category, Headline = x.Headline,
                    Logo = x.Logo, Text = x.Text
                });
            }
            //load base
            BaseData = Game.GameData.GetBase(Base);
            //update
            Character.UpdatePosition(Base, System, Position);
            //send to player
            lock (rtcs)
            {
                rpcClient.BaseEnter(Base, rtcs.ToArray(), news.ToArray(), BaseData.SoldGoods.Select(x => new SoldGood()
                {
                    GoodCRC = CrcTool.FLModelCrc(x.Good.Ini.Nickname),
                    Price   = x.Price,
                    Rank    = x.Rank,
                    Rep     = x.Rep,
                    ForSale = x.ForSale
                }).ToArray(), GetSoldShips().ToArray());
            }
        }
Пример #5
0
 public HardpointLookup(IDrawable dr)
 {
     crcTable = new Dictionary <uint, string>();
     crcTable.Add(NetShipCargo.InternalCrc, "internal");
     foreach (var hp in HardpointList(dr))
     {
         crcTable.Add(CrcTool.HardpointCrc(hp), hp);
     }
 }
 public GunOrient[] GetRotations()
 {
     return(Parent.GetChildComponents <WeaponComponent>().Select(x => new GunOrient()
     {
         Hardpoint = CrcTool.FLModelCrc(x.Parent.Attachment.Name),
         AngleRot = x.Angles.X,
         AnglePitch = x.Angles.Y
     }).ToArray());
 }
Пример #7
0
        void InitBaselinePrices()
        {
            var bp = new List <BaselinePrice>();

            foreach (var good in GameData.AllGoods)
            {
                bp.Add(new BaselinePrice()
                {
                    GoodCRC = CrcTool.FLModelCrc(good.Ini.Nickname),
                    Price   = (ulong)good.Ini.Price
                });
            }
            BaselineGoodPrices = bp.ToArray();
        }
Пример #8
0
        public override void Register(PhysicsWorld physics)
        {
            if (pworld == physics)
            {
                return;
            }
            pworld = physics;
            Collider cld = null;

            if (SurPath == null)  //sphere
            {
                cld = new SphereCollider(SphereRadius);
            }
            else
            {
                var mr = (ModelRenderer)Parent.RenderComponent;
                sur = new SurCollider(SurPath);
                cld = sur;
                if (Parent.RigidModel.From3db)
                {
                    sur.AddPart(PlainCrc, Matrix4x4.Identity, null);
                }
                else
                {
                    foreach (var part in Parent.RigidModel.AllParts)
                    {
                        var crc = CrcTool.FLModelCrc(part.Name);
                        if (part.Construct == null)
                        {
                            sur.AddPart(crc, Matrix4x4.Identity, part);
                        }
                        else
                        {
                            sur.AddPart(crc, part.LocalTransform, part);
                        }
                    }
                }
            }
            if (Mass < float.Epsilon)
            {
                Body = physics.AddStaticObject(Parent.GetTransform(), cld);
            }
            else
            {
                Body = physics.AddDynamicObject(Mass, Parent.GetTransform(), cld, Inertia);
            }
            Body.Tag = Parent;
            collider = cld;
        }
 public void SetRotations(GunOrient[] orients)
 {
     foreach (var wp in Parent.GetChildComponents <WeaponComponent>())
     {
         var hp = CrcTool.FLModelCrc(wp.Parent.Attachment.Name);
         foreach (var o in orients)
         {
             if (o.Hardpoint == hp)
             {
                 wp.RotateTowards(o.AngleRot, o.AnglePitch);
                 break;
             }
         }
     }
 }
Пример #10
0
        public NetShipLoadout EncodeLoadout()
        {
            var sl = new NetShipLoadout();

            sl.ShipCRC   = Ship.CRC;
            sl.Equipment = new List <NetShipEquip>(Equipment.Count);
            foreach (var equip in Equipment)
            {
                sl.Equipment.Add(new NetShipEquip(
                                     equip.Hardpoint == null ? 0 : CrcTool.FLModelCrc(equip.Hardpoint),
                                     equip.Equipment.CRC,
                                     (byte)(equip.Health * 255f)));
            }
            return(sl);
        }
Пример #11
0
        public void ChildDebris(GameObject parent, RigidModelPart part, float mass, Vector3 initialforce)
        {
            var cp = new PhysicsComponent(parent)
            {
                SurPath  = this.SurPath,
                Mass     = mass,
                PlainCrc = CrcTool.FLModelCrc(part.Name),
            };

            DisablePart(part);
            parent.PhysicsComponent = cp;
            cp.Register(pworld);
            cp.Body.Impulse(initialforce);
            parent.Components.Add(cp);
        }
Пример #12
0
        public GameObject DoSpawn(string nickname, Loadout loadout, GameData.Pilot pilot, Vector3 position, Quaternion orient)
        {
            NetShipLoadout netLoadout = new NetShipLoadout();

            netLoadout.Items = new List <NetShipCargo>();
            var ship = World.Server.GameData.GetShip(loadout.Archetype);

            netLoadout.ShipCRC = ship.CRC;
            var obj = new GameObject(ship, World.Server.Resources, false, true);

            obj.Name     = $"Bob NPC - {loadout.Nickname}";
            obj.Nickname = nickname;
            obj.SetLocalTransform(Matrix4x4.CreateFromQuaternion(orient) * Matrix4x4.CreateTranslation(position));
            obj.Components.Add(new SHealthComponent(obj)
            {
                CurrentHealth = ship.Hitpoints,
                MaxHealth     = ship.Hitpoints
            });
            foreach (var equipped in loadout.Equip)
            {
                var e = World.Server.GameData.GetEquipment(equipped.Nickname);
                if (e == null)
                {
                    continue;
                }
                EquipmentObjectManager.InstantiateEquipment(obj, World.Server.Resources, EquipmentType.Server,
                                                            equipped.Hardpoint, e);
                var hp = equipped.Hardpoint == null ? NetShipCargo.InternalCrc : CrcTool.FLModelCrc(equipped.Hardpoint);
                netLoadout.Items.Add(new NetShipCargo(0, e.CRC, hp, 255, 1));
            }
            obj.Components.Add(new SNPCComponent(obj, this)
            {
                Loadout = netLoadout, Pilot = pilot
            });
            obj.Components.Add(new ShipPhysicsComponent(obj)
            {
                Ship = ship
            });
            obj.Components.Add(new ShipInputComponent(obj));
            obj.Components.Add(new AutopilotComponent(obj));
            obj.Components.Add(new WeaponControlComponent(obj));
            World.OnNPCSpawn(obj);
            if (nickname != null)
            {
                missionNPCs[nickname] = obj;
            }
            return(obj);
        }
Пример #13
0
        public NetShipLoadout EncodeLoadout()
        {
            var sl = new NetShipLoadout();

            sl.ShipCRC = Ship.CRC;
            sl.Items   = new List <NetShipCargo>(Items.Count);
            foreach (var c in Items)
            {
                sl.Items.Add(new NetShipCargo(
                                 c.ID, c.Equipment.CRC,
                                 CrcTool.HardpointCrc(c.Hardpoint), (byte)(c.Health * 255f),
                                 c.Count
                                 ));
            }
            return(sl);
        }
Пример #14
0
        public Hud(FreelancerGame game, List <GameData.BaseHotspot> hotspots = null)
        {
            manager = new UIManager(game);
            //backgrounds
            contactslist = new HudModelElement(manager, "hud_target.cmp", -0.73f, -0.69f, 2.1f, 2.9f);
            manager.Elements.Add(contactslist);

            shipinfo = new HudModelElement(manager, "hud_shipinfo.cmp", 0.73f, -0.69f, 2.1f, 2.9f);
            manager.Elements.Add(shipinfo);

            numberbox = new HudNumberBoxElement(manager);
            manager.Elements.Add(numberbox);

            gauge = new HudGaugeElement(manager);
            manager.Elements.Add(gauge);

            chatbox = new HudChatBox(manager);
            manager.Elements.Add(chatbox);

            //Maneuvers
            if (hotspots == null)
            {
                mnvs       = game.GameData.GetManeuvers().ToList();
                navbuttons = new HudNavBox(mnvs, manager);
            }
            else
            {
                navbuttons = new HudNavBox(game.GameData.GetBaseNavbarIcons(), hotspots, manager);
            }
            navbuttons.Show();

            manager.Clicked += Manager_OnClick;

            reticle         = game.ResourceManager.GetDrawable(game.GameData.ResolveDataPath("INTERFACE/HUD/hud_reticle.3db"));
            reticle_health  = game.ResourceManager.GetDrawable(game.GameData.ResolveDataPath("INTERFACE/HUD/hud_reticle_health.3db"));
            reticle_shields = game.ResourceManager.GetDrawable(game.GameData.ResolveDataPath("INTERFACE/HUD/hud_reticle_shields.3db"));

            UI_HUD_targetarrow   = game.ResourceManager.FindMaterial(CrcTool.FLModelCrc("UI_HUD_targetarrow")).Render;
            UI_HUD_targetingblue = game.ResourceManager.FindMaterial(CrcTool.FLModelCrc("UI_HUD_targetingblue")).Render;

            TextEntry = false;
        }
Пример #15
0
        void SetSelfLoadout(NetShipLoadout ld)
        {
            var sh = Game.GameData.GetShip((int)ld.ShipCRC);

            sh.LoadResources();
            PlayerShip = sh.Nickname;
            var hpcrcs = new Dictionary <uint, string>();

            foreach (var hp in HardpointList(sh.Drawable))
            {
                hpcrcs.Add(CrcTool.FLModelCrc(hp), hp);
            }
            Mounts = new List <EquipMount>();
            foreach (var eq in ld.Equipment)
            {
                Mounts.Add(new EquipMount(
                               hpcrcs[eq.HardpointCRC],
                               Game.GameData.GetEquipment(eq.EquipCRC).Nickname
                               ));
            }
        }
Пример #16
0
 public GameData.Ship GetShip(int crc)
 {
     return(GetShip(fldata.Ships.Ships.FirstOrDefault((x) => CrcTool.FLModelCrc(x.Nickname) == crc)));
 }
Пример #17
0
        void InitWithDrawable(IDrawable drawable, ResourceManager res, bool staticpos)
        {
            Resources = res;
            dr        = drawable;
            Shape collisionShape = null;
            bool  isCmp          = false;

            if (dr is SphFile)
            {
                var radius = ((SphFile)dr).Radius;
                collisionShape = new SphereShape(radius);
            }
            else if (dr is ModelFile)
            {
                var mdl  = dr as ModelFile;
                var path = Path.ChangeExtension(mdl.Path, "sur");
                if (File.Exists(path))
                {
                    SurFile sur = res.GetSur(path);
                    var     shs = new List <CompoundSurShape.TransformedShape>();
                    foreach (var s in sur.GetShape(0))
                    {
                        shs.Add(new CompoundSurShape.TransformedShape(s, Matrix3.Identity, Vector3.Zero));
                    }
                    collisionShape = new CompoundSurShape(shs);
                }
            }
            else if (dr is CmpFile)
            {
                isCmp = true;
                var cmp = dr as CmpFile;
                CmpParts      = new List <Part>();
                CmpConstructs = cmp.Constructs.CloneAll();
                foreach (var part in cmp.Parts.Values)
                {
                    CmpParts.Add(part.Clone(CmpConstructs));
                }
                if (cmp.Animation != null)
                {
                    AnimationComponent = new AnimationComponent(this, cmp.Animation);
                    Components.Add(AnimationComponent);
                }
                var path = Path.ChangeExtension(cmp.Path, "sur");
                if (File.Exists(path))
                {
                    SurFile sur    = res.GetSur(path);
                    var     shapes = new List <CompoundSurShape.TransformedShape>();
                    foreach (var part in CmpParts)
                    {
                        var crc = CrcTool.FLModelCrc(part.ObjectName);
                        if (!sur.HasShape(crc))
                        {
                            FLLog.Warning("Sur", "No hitbox for " + part.ObjectName);
                            continue;
                        }
                        var colshape = sur.GetShape(crc);
                        if (part.Construct == null)
                        {
                            foreach (var s in colshape)
                            {
                                shapes.Add(new CompoundSurShape.TransformedShape(s, Matrix3.Identity, Vector3.Zero));
                            }
                        }
                        else
                        {
                            var tr  = part.Construct.Transform;
                            var pos = tr.ExtractTranslation();
                            var q   = tr.ExtractRotation(true);
                            var rot = Matrix3.CreateFromQuaternion(q);
                            foreach (var s in colshape)
                            {
                                shapes.Add(new CompoundSurShape.TransformedShape(s, rot, pos)
                                {
                                    Tag = part.Construct
                                });
                            }
                        }
                    }
                    collisionShape = new CompoundSurShape(shapes);
                }
            }
            if (collisionShape != null)
            {
                PhysicsComponent          = new RigidBody(collisionShape);
                PhysicsComponent.Tag      = this;
                PhysicsComponent.IsStatic = staticpos;
                if (staticpos)
                {
                    PhysicsComponent.Material.Restitution = 1;
                }
            }
            PopulateHardpoints(dr);
            if (isCmp)
            {
                RenderComponent = new ModelRenderer(CmpParts, (dr as CmpFile));
            }
            else
            {
                RenderComponent = new ModelRenderer(dr);
            }
        }
Пример #18
0
        public Task <ShipPackageInfo> GetShipPackage(int package)
        {
            var resolved = Game.GameData.GetShipPackage((uint)package);

            if (resolved == null)
            {
                return(Task.FromResult <ShipPackageInfo>(null));
            }
            var spi = new ShipPackageInfo();

            spi.Included = resolved.Addons.Select(x =>
            {
                return(new IncludedGood()
                {
                    EquipCRC = x.Equipment.CRC,
                    HardpointCRC = string.IsNullOrWhiteSpace(x.Hardpoint) ? InternalCRC : CrcTool.FLModelCrc(x.Hardpoint),
                    Amount = x.Amount
                });
            }).ToArray();
            return(Task.FromResult(spi));
        }