コード例 #1
0
        // FLPACKET_SERVER_CREATESHIP
        public byte[] BuildCreateShip(Ship.Ship ship)
        {
            Log.AddLog(LogType.FL_MSG, "tx FLPACKET_SERVER_CREATESHIP objid={0}", ship.Objid);

            byte[] omsg = { 0x04, 0x02 };
            FLMsgType.AddUInt32(ref omsg, ship.Objid);
            FLMsgType.AddUInt16(ref omsg, ship.Arch.SmallID);
            FLMsgType.AddUInt32(ref omsg, 0);
            FLMsgType.AddUInt32(ref omsg, ship.player != null ? ship.player.FLPlayerID : 0);
            FLMsgType.AddUInt32(ref omsg, ship.com_body);
            FLMsgType.AddUInt32(ref omsg, ship.com_head);

            FLMsgType.AddUInt8(ref omsg, (uint)ship.Accessories.Count);
            foreach (uint accessory in ship.Accessories)
            {
                FLMsgType.AddUInt32(ref omsg, accessory);
            }

            FLMsgType.AddUInt32(ref omsg, ship.voiceid);

            FLMsgType.AddFloat(ref omsg, (float)ship.Position.x);
            FLMsgType.AddFloat(ref omsg, (float)ship.Position.y);
            FLMsgType.AddFloat(ref omsg, (float)ship.Position.z);

            Quaternion q = Quaternion.MatrixToQuaternion(ship.Orientation);

            FLMsgType.AddInt8(ref omsg, (int)(q.I * 127));
            FLMsgType.AddInt8(ref omsg, (int)(q.J * 127));
            FLMsgType.AddInt8(ref omsg, (int)(q.K * 127));
            FLMsgType.AddInt8(ref omsg, (int)(q.W * 127));

            FLMsgType.AddUInt8(ref omsg, (uint)(ship.Health * 255));

            FLMsgType.AddUInt16(ref omsg, (uint)(ship.Items.Count));
            foreach (ShipItem item in ship.Items.Values)
            {
                byte flag = 0;

                if (item.mounted)
                {
                    flag |= 0x01;
                }

                if (item.mission)
                {
                    flag |= 0x02;
                }

                if (item.count == 1)
                {
                    flag |= 0x80;
                }
                else
                {
                    flag |= 0x04;
                }

                if (item.health == 1.0f)
                {
                    flag |= 0x40;
                }

                if (item.hpname.Length > 0)
                {
                    flag |= 0x10;
                }
                else
                {
                    flag |= 0x20;
                }

                FLMsgType.AddUInt8(ref omsg, flag);

                if (item.count != 1)
                {
                    FLMsgType.AddUInt32(ref omsg, item.count);
                }

                if (item.health != 1.0f)
                {
                    FLMsgType.AddUInt8(ref omsg, (uint)(item.health * 255));
                }

                FLMsgType.AddUInt16(ref omsg, item.arch.SmallID);
                FLMsgType.AddUInt8(ref omsg, item.hpid);

                if (item.hpname.Length > 0)
                {
                    FLMsgType.AddAsciiStringLen8(ref omsg, item.hpname + "\0");
                }
            }

            FLMsgType.AddUInt8(ref omsg, (uint)(ship.cols.Count));
            foreach (CollisionGroup col in ship.cols)
            {
                FLMsgType.AddUInt8(ref omsg, col.id);
                FLMsgType.AddUInt8(ref omsg, (uint)(col.health * col.max_hit_pts * 255));
            }

            FLMsgType.AddUInt8(ref omsg, (ship.player != null) ? 4u : 0u); // flag
            FLMsgType.AddFloat(ref omsg, 0);                               // x
            FLMsgType.AddFloat(ref omsg, 0);                               // y
            FLMsgType.AddFloat(ref omsg, 0);                               // z
            FLMsgType.AddInt8(ref omsg, 0);
            FLMsgType.AddUInt16(ref omsg, 0);                              // dunno?
            FLMsgType.AddUInt8(ref omsg, ship.Rank);

            if (ship.player != null)
            {
                FLMsgType.AddUInt8(ref omsg, ship.player.FLPlayerID);
                FLMsgType.AddUInt16(ref omsg, 0);
                FLMsgType.AddUnicodeStringLen8(ref omsg, ship.player.Name);
            }
            else
            {
                var patrol_name = new FLFormatString(0x3f20);
                patrol_name.AddString(0x3016b);
                patrol_name.AddString(0x4074);
                patrol_name.AddString(0x30401);
                patrol_name.AddNumber(0x09);
                FLMsgType.AddArray(ref omsg, patrol_name.GetBytes());

                var ship_name = new FLFormatString(0x3f21);
                ship_name.AddString(0x301a4);
                ship_name.AddString(0x37bac);
                ship_name.AddString(0x37c2b);
                FLMsgType.AddArray(ref omsg, ship_name.GetBytes());
            }

            // The faction associated with the ship. For player ships this can be
            // -1 but for NPCs it needs to be set to a faction ID or the NPC will
            // not have a name shown in space or in the radar/scanner
            FLMsgType.AddUInt32(ref omsg, ship.faction.FactionID);

            // The reputation with reference to the faction..but it doesn't seem to
            // do much
            FLMsgType.AddInt8(ref omsg, -127);
            return(omsg);
        }
コード例 #2
0
            public override void HandleTimerEvent(double deltaSeconds)
            {
                if (runner.system == UniverseDB.FindSystem("li01"))
                {
                    //TODO: AI debug here
                    for (int i = 0; i < 1; i++)
                    {
                        var npc = new Ship.Ship(runner);
                        npc.AI   = new AI.DebugAI(npc);
                        npc.Arch = ArchetypeDB.Find(FLUtility.CreateID("dsy_csv"));
                        if (npc.Arch == null)
                        {
                            return;
                        }

                        npc.Position = new Vector(-30000 + i * 300, i * 100, -25000);
                        //npc.orientation = ;
                        npc.Rank    = 20;
                        npc.System  = runner.system;
                        npc.Health  = 1.0f;
                        npc.faction = UniverseDB.FindFaction("fc_wild");
                        Loadout loadout = UniverseDB.FindLoadout("fc_j_ge_csv_loadout01");
                        if (loadout != null)
                        {
                            uint hpid = 34;
                            foreach (ShipItem item in loadout.Items)
                            {
                                var new_item = new ShipItem();
                                new_item.arch    = item.arch;
                                new_item.count   = item.count;
                                new_item.health  = 1.0f;
                                new_item.hpid    = hpid++;
                                new_item.hpname  = item.hpname;
                                new_item.mounted = item.mounted;
                                npc.Items.Add(new_item.hpid, new_item);
                            }
                        }
                        npc.InitialiseEquipmentSimulation();
                        runner.CreateSimObject(npc);
                    }
                }
                //    int total = 0;
                //    if (runner.players.Count > 0)
                //    {
                //        if (delta_seconds > 1.5)
                //            runner.log.AddLog(LogType.FL_MSG, "bad delta " + delta_seconds);

                //        // wow, this'll really suck if there are lots of NPCs
                //        foreach (Zone z in runner.system.zones)
                //        {
                //            if (z.shape != null && z.density > 0)
                //            {
                //                while (z.interference < z.density) // borrow this
                //                {
                //                    Ship npc = new Ship(runner);
                //                    npc.position = z.shape.position;
                //                    npc.orientation = z.shape.orientation;
                //                    npc.rank = 20;
                //                    npc.arch = ArchetypeDB.Find(FLUtility.CreateID("dsy_csv"));
                //                    npc.system = runner.system;
                //                    npc.health = 1.0f;
                //                    runner.CreateSimObject(npc);

                //                    z.interference++;
                //                    total++;
                //                }
                //            }
                //        }

                //        int working_npcs = 0;
                //        foreach (SimObject o in runner.objects.Values)
                //        {
                //            if (o.health > 0)
                //            {
                //                working_npcs++;

                //                foreach (Player player in runner.players.Values)
                //                {
                //                    if (player.ship != o)
                //                    {
                //                        Vector position = player.ship.position;
                //                        position.x += rand.Next(100);
                //                        position.z += rand.Next(100);
                //                        o.SetUpdateObject(position, player.ship.orientation, 1.0f, 0);
                //                    }
                //                }
                //            }
                //        }

                //        runner.log.AddLog(LogType.GENERAL, "system={0} npcs={1} objects={2} running={3}",
                //            runner.system.nickname, total, runner.objects.Count, working_npcs));

                //    }

                //    ExpireAfter(1);
            }