// 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); }