Exemplo n.º 1
0
        private void advDraw()
        {
            if (MyAPIGateway.Session == null)
            {
                return;
            }
            if (MyAPIGateway.Session.Player == null)
            {
                return;
            }
            MatrixD      mat   = MatrixD.CreateWorld(adjustvector(panel.WorldMatrix.Translation, panel.WorldMatrix), new Vector3(0, 0, 1), new Vector3(0, 1, 0));
            Vector3D     trans = mat.Translation;
            BoundingBoxD bb    = new BoundingBoxD(new Vector3D(0), new Vector3D(Scale / 2));

            bb = new BoundingBoxD(-bb.Center, bb.Center);
            SortedSet <PointStruct> set = new SortedSet <PointStruct>(new PointComparer());
            Vector3D playerpos          = MyAPIGateway.Session.Player.GetPosition();

            foreach (KeyValuePair <Vector3I, ResultType> kvp in color)
            {
                PointStruct point;
                point.Value = trans + ((Vector3D)kvp.Key * (Scale / 2));
                point.Key   = Vector3D.Distance(point.Value, playerpos);
                point.Color = RadarResult.getColor(kvp.Value);
                set.Add(point);
            }
            //MyAPIGateway.Utilities.ShowMessage("Draw Call", color.Count.ToString());
            foreach (var value in set.Reverse())
            {
                mat.Translation = value.Value;
                Color _color = value.Color;
                MySimpleObjectDraw.DrawTransparentBox(ref mat, ref bb, ref _color, MySimpleObjectRasterizer.Solid, 0, 0, null, null, false, -1);
            }
        }
Exemplo n.º 2
0
        private void advDraw()
        {
            MatrixD  headmatrix         = MyAPIGateway.Session.Player.Controller.ControlledEntity.GetHeadMatrix(true);
            Vector3D playerpos          = headmatrix.Translation;
            MatrixD  forwardtrans       = new MatrixD(cockpit.WorldMatrix);
            Vector3D playerforward      = forwardtrans.Forward;
            SortedSet <PointStruct> set = new SortedSet <PointStruct>(new PointComparer());

            foreach (KeyValuePair <Vector3I, ResultType> kvp in color)
            {
                if (kvp.Value == ResultType.Self_Point || kvp.Value == ResultType.Self_Point_Alt /*|| kvp.Value == ResultType.Voxel*/)
                {
                    //	PointStruct point2;
                    //	point2.Value = playerpos + ((Vector3D)kvp.Key * (0.01d / 4)) + cockpit.WorldMatrix.Forward * 0.25 + cockpit.WorldMatrix.Left * 0.1 + cockpit.WorldMatrix.Up * 0.025;
                    //	point2.Key = Vector3D.Distance(point2.Value, playerpos);
                    //	point2.Color = RadarResult.getColor(kvp.Value);
                    //	set.Add(point2);
                    //	point2.Value = playerpos + ((Vector3D)kvp.Key * (0.01d / 4)) + cockpit.WorldMatrix.Forward * 0.25 + cockpit.WorldMatrix.Right * 0.1 + cockpit.WorldMatrix.Up * 0.025;
                    //	point2.Key = Vector3D.Distance(point2.Value, playerpos);
                    //	point2.Color = RadarResult.getColor(kvp.Value);
                    //	set.Add(point2);
                    continue;
                }
                PointStruct point;
                //Vector3D dotvec = new Vector3D(kvp.Key);
                //if(Vector3D.Dot(playerforward, dotvec) > 0)
                //{
                //	point.Value = playerpos + Vector3D.Transform(((Vector3D)kvp.Key * (0.01d / 4)));
                //	point.Value = playerpos + ((Vector3D)kvp.Key * (0.01d / 4)) + cockpit.WorldMatrix.Forward * 0.25 + cockpit.WorldMatrix.Left * 0.1 + cockpit.WorldMatrix.Up * 0.025;
                //}
                //else
                //	point.Value = playerpos + ((Vector3D)kvp.Key * (0.01d / 4)) + cockpit.WorldMatrix.Forward * 0.25 + cockpit.WorldMatrix.Right * 0.1 + cockpit.WorldMatrix.Up * 0.025;
                point.Value = playerpos + ((Vector3D)kvp.Key * (0.025d / 4));
                point.Key   = Vector3D.Distance(point.Value, playerpos);
                point.Color = RadarResult.getColor(kvp.Value);
                //if(kvp.Value != ResultType.Voxel)
                set.Add(point);
            }
            //var rev = set.Reverse();
            foreach (var value in set)
            {
                //mat.Translation = value.Value;
                Color _color = value.Color;
                _color.A = Convert.ToByte((int)(((double)Convert.ToInt32(_color.A)) / 2d));
                //float size = 0.0008f;
                MyTransparentGeometry.AddPointBillboard(MyStringId.GetOrCompute("WhiteDot"), _color.ToVector4(), value.Value, 0.0008f, 0.0f);
                //MySimpleObjectDraw.DrawTransparentSphere(ref mat, 0.0008f, ref _color, MySimpleObjectRasterizer.Solid, 8, "Square");
            }
        }
Exemplo n.º 3
0
 private void calcComplete()
 {
     //MyAPIGateway.Utilities.ShowMessage("CalcDone", T_result.ColorData.Count.ToString());
     _result = new RadarResult(T_result);
     T_result.Clear();
     if (!Entity.MarkedForClose || Entity.Closed)
     {
         foreach (KeyValuePair <Vector3I, IMySensorBlock> pingblocks in pingResult)
         {
             var radar = CoreHolo.GetRadar(pingblocks.Value.EntityId);
             if (radar != null)
             {
                 radar.Notify(Term.WorldMatrix.Translation, Term);
             }
         }
         pingResult.Clear();
         //projection = p_grid;
     }
 }
Exemplo n.º 4
0
        private void refreshRadar(Dictionary <Vector3D, IMySensorBlock> cache, bool _activeMode)
        {
            //if (CoreHolo.instance.settings.new_scan_method)
            //{
            //	newRefreshRadar(cache, _activeMode);
            //	return;
            //}
            Random m_rand = new Random();

            if (!valid)
            {
                return;
            }
            if (Term == null)
            {
                return;
            }
            var     shipgrid   = (IMyCubeGrid)Term.CubeGrid;
            MatrixD panelWorld = MatrixD.CreateFromQuaternion(Base6Directions.GetOrientation(Base6Directions.Direction.Forward, Base6Directions.Direction.Up));

            panelWorld.Translation = Term.WorldMatrix.Translation;
            MatrixD                               normalizedWorld          = MatrixD.Normalize(panelWorld);
            MatrixD                               panelMatrixNormalizedInv = MatrixD.Invert(normalizedWorld);
            HashSet <Vector3I>                    check        = new HashSet <Vector3I>();
            HashSet <MyPlanet>                    planets      = new HashSet <MyPlanet>();
            HashSet <IMyVoxelBase>                voxels       = new HashSet <IMyVoxelBase>();
            HashSet <Vector3I>                    absolute     = new HashSet <Vector3I>();
            Dictionary <Vector3I, Vector3D>       toWorldCache = new Dictionary <Vector3I, Vector3D>();
            Dictionary <Vector3I, ResultType>     blockCache   = new Dictionary <Vector3I, ResultType>();
            Dictionary <Vector3I, IMySensorBlock> pingCache    = new Dictionary <Vector3I, IMySensorBlock>();
            //pingResult.Clear();
            Dictionary <Vector3I, ResultType> m_ColorData = new Dictionary <Vector3I, ResultType>();
            ResultType blockcolor = ResultType.Self_Point_Alt;

            try
            {
                if (blue && !CoreHolo.instance.settings.show_ship)
                {
                    blockcolor = ResultType.Self_Point;
                    blue       = false;
                }
                else
                {
                    blue = true;
                }
                Color SelfColor = RadarResult.getColor(blockcolor);
                //int NewEntityId = 1;
                check.Add(new Vector3I(0));
                m_ColorData.Add(new Vector3I(0), blockcolor);
                //p_grid.CubeBlocks.Add(whiteblock);
                //if (!_activeMode) Log.DebugWrite(DebugLevel.Info, cache.Count);
                foreach (KeyValuePair <Vector3D, IMySensorBlock> pl in cache)
                {
                    Vector3I plloc = new Vector3I(WorldtoGrid(pl.Value.WorldMatrix.Translation, panelMatrixNormalizedInv));
                    //Log.DebugWrite(DebugLevel.Info, plloc);
                    var owner = pl.Value.OwnerId;
                    blockcolor = ResultType.Enemy;
                    if (owner == Term.OwnerId)
                    {
                        blockcolor = ResultType.Self;
                    }
                    else
                    {
                        var ownerF = MyAPIGateway.Session.Factions.TryGetPlayerFaction(owner);
                        var Tfac   = MyAPIGateway.Session.Factions.TryGetPlayerFaction(Term.OwnerId);
                        if (ownerF != null && Tfac != null)
                        {
                            if (ownerF == Tfac)
                            {
                                blockcolor = ResultType.Faction;                                            //same faction
                            }
                            else
                            {
                                var relation = MyAPIGateway.Session.Factions.GetRelationBetweenFactions(ownerF.FactionId, Tfac.FactionId);
                                if (relation == MyRelationsBetweenFactions.Neutral)
                                {
                                    blockcolor = ResultType.Friend;                                                                                //allied
                                }
                            }
                        }
                        else
                        {
                            blockcolor = ResultType.Neutral;
                        }
                    }
                    if (!check.Contains(plloc))
                    {
                        check.Add(plloc);
                        if (blockCache.ContainsKey(plloc))
                        {
                            blockCache.Remove(plloc);
                        }
                        blockCache.Add(plloc, blockcolor);
                        if (!absolute.Contains(plloc))
                        {
                            absolute.Add(plloc);
                        }
                    }
                    else
                    {
                        if (blockCache.ContainsKey(plloc))
                        {
                            blockCache.Remove(plloc);
                        }
                        blockCache.Add(plloc, blockcolor);
                        if (!absolute.Contains(plloc))
                        {
                            absolute.Add(plloc);
                        }
                    }
                }
                BoundingSphereD sphere = new BoundingSphereD(panelWorld.Translation, 50 * Range * _resMult);
                //var ents = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);
                List <MyEntity> ents = new List <MyEntity>();
                MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref sphere, ents);
                List <IMyEntity> planetcheck = new List <IMyEntity>(ents);
                if (_activeMode)
                {
                    #region planetcache
                    foreach (MyEntity ent in planetcheck)
                    {
                        if (ent is IMyVoxelBase)
                        {
                            var asteroid = (IMyVoxelBase)ent;
                            if (asteroid.LocalAABB.Extents.Length() < Range * _resMult)
                            {
                            }
                            else
                            if (!voxels.Contains(asteroid))
                            {
                                voxels.Add(asteroid);
                            }
                        }
                    }
                    if (voxels.Count > 0)
                    {
                        for (int xmin = -50; xmin <= 50; xmin++)
                        {
                            for (int ymin = -50; ymin <= 50; ymin++)
                            {
                                for (int zmin = -50; zmin < 50; zmin++)
                                {
                                    Vector3I voxPos = new Vector3I(xmin, ymin, zmin);
                                    Vector3D world  = new Vector3D(GridToWorld(voxPos, panelWorld));
                                    bool     ex     = excludeVoxelBase(world, ref voxels);
                                    if (!check.Contains(voxPos) && ex)
                                    {
                                        check.Add(voxPos);
                                    }
                                }
                            }
                        }
                        foreach (Vector3I vpos in check)
                        {
                            Vector3I px, py, pz, mx, my, mz;
                            px = py = pz = mx = my = mz = vpos;
                            px.X++;
                            mx.X--;
                            py.Y++;
                            my.Y--;
                            pz.Z++;
                            mz.Z--;
                            int found = 0;
                            if (check.Contains(px))
                            {
                                found++;
                            }
                            if (check.Contains(mx))
                            {
                                found++;
                            }
                            if (check.Contains(py))
                            {
                                found++;
                            }
                            if (check.Contains(my))
                            {
                                found++;
                            }
                            if (check.Contains(pz))
                            {
                                found++;
                            }
                            if (check.Contains(mz))
                            {
                                found++;
                            }
                            if (found <= 5)
                            {
                                Vector3D world = GridToWorld(vpos, panelWorld);
                                if (sphere.Contains(world) == ContainmentType.Contains)
                                {
                                    if (!blockCache.ContainsKey(vpos))
                                    {
                                        blockCache.Add(vpos, ResultType.Voxel);
                                    }
                                }
                            }
                        }
                    }
                    #endregion
                    #region entityscan
                    Vector3I pos;
                    foreach (MyEntity ent in ents)
                    {
                        bool small = false;
                        //Log.DebugWrite(DebugLevel.Info, ent);
                        if (!ent.Flags.HasFlag(EntityFlags.Save))
                        {
                            //ignore items that dont save.
                            //Log.DebugWrite(DebugLevel.Info, ent);
                            //Log.DebugWrite(DebugLevel.Info, "Has no save flag");
                            continue;
                        }
                        if (ent.Parent != null)
                        {
                            if (ent == Term.Parent)
                            {
                                continue;
                            }
                        }
                        Vector3D worldCenter = ent.WorldMatrix.Translation;
                        Vector3D center      = WorldtoGrid(worldCenter, panelMatrixNormalizedInv);
                        if (ent is MyCubeBlock)
                        {
                            continue;
                        }
                        if (ent is IMySlimBlock)
                        {
                            continue;
                        }
                        blockcolor = ResultType.Unknown;
                        if (ent is IMyVoxelBase)
                        {
                            blockcolor = ResultType.Voxel;                            //add
                            //	continue;
                        }
                        if (ent is MyFloatingObject || ent is MyInventoryBagEntity)
                        {
                            small      = true;
                            blockcolor = ResultType.FloatingObject;
                        }
                        if (ent is IMyCharacter)
                        {
                            small = true;
                            //var character = ent as IMyCharacter;
                            //character.
                            var playa = MyAPIGateway.Multiplayer.Players.GetPlayerControllingEntity(ent);
                            if (playa == null)
                            {
                                continue;
                            }
                            if (playa.Controller == null)
                            {
                                continue;
                            }
                            if (playa.Controller.ControlledEntity == null)
                            {
                                continue;
                            }
                            if (playa.Controller.ControlledEntity.Entity is IMyCharacter)
                            {
                                blockcolor = ResultType.Engineer;
                            }
                        }
                        if (ent is IMyMeteor)
                        {
                            small      = true;
                            blockcolor = ResultType.Meteor;
                        }
                        if (ent is IMyCubeGrid)
                        {
                            blockcolor = ResultType.Enemy;
                            var grid = (IMyCubeGrid)ent;
                            if (grid.EntityId == Entity.Parent.EntityId)
                            {
                                continue;
                            }
                            if (grid.BigOwners.Count > 0)
                            {
                                var idents = grid.BigOwners.GetInternalArray <long>();
                                var ident  = idents[0];
                                if (ident == 0)
                                {
                                    blockcolor = ResultType.Neutral;
                                }
                                if (ident == Term.OwnerId)
                                {
                                    blockcolor = ResultType.Self;
                                }
                                else
                                {
                                    var ownerF = MyAPIGateway.Session.Factions.TryGetPlayerFaction(ident);
                                    var Tfac   = MyAPIGateway.Session.Factions.TryGetPlayerFaction(Term.OwnerId);
                                    if (ownerF != null && Tfac != null)
                                    {
                                        if (ownerF == Tfac)
                                        {
                                            blockcolor = ResultType.Faction;                                                        //same faction
                                        }
                                        else
                                        {
                                            var relation = MyAPIGateway.Session.Factions.GetRelationBetweenFactions(ownerF.FactionId, Tfac.FactionId);
                                            if (relation == MyRelationsBetweenFactions.Neutral)
                                            {
                                                blockcolor = ResultType.Friend;                                                                                            //allied
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                blockcolor = ResultType.Neutral;
                            }
                            worldCenter = grid.WorldAABB.Center;
                            center      = WorldtoGrid(worldCenter, panelMatrixNormalizedInv);
                            //disable for now
                            //var attachedradar = CoreHolo.GetRadarAttachedToGrid(grid.EntityId);
                            //foreach (Radar retRadar in attachedradar)
                            //{
                            //	Vector3D blockWorldCenter = retRadar.Term.WorldMatrix.Translation;
                            //	Vector3D blockCenter = WorldtoGrid(blockWorldCenter, panelMatrixNormalizedInv);
                            //	var centerPing = new Vector3I(blockCenter);
                            //	if (!pingCache.ContainsKey(centerPing)) pingCache.Add(centerPing, retRadar.Term);
                            //}
                        }
                        //if (blockcolor == Color.Gray.ColorToHSV())
                        //{
                        //	Log.DebugWrite( DebugLevel.Info,"Unknown object");
                        //	Log.DebugWrite(DebugLevel.Info, ent);
                        //}
                        pos = new Vector3I(center);
                        if (!check.Contains(pos) && sphere.Contains(worldCenter) == ContainmentType.Contains)
                        {
                            if (!small)
                            {
                                check.Add(pos);
                            }
                            if (!blockCache.ContainsKey(pos))
                            {
                                blockCache.Add(pos, blockcolor);
                            }
                        }
                    }
                    #endregion
                    #region shipdraw
                    if (CoreHolo.instance.settings.show_ship)
                    {
                        List <IMySlimBlock> children = new List <IMySlimBlock>();
                        shipgrid.GetBlocks(children, delegate(IMySlimBlock a)
                        {
                            Vector3I plloc = new Vector3I(WorldtoGrid(shipgrid.GridIntegerToWorld(a.Position), panelMatrixNormalizedInv));
                            if (check.Contains(plloc))
                            {
                                return(false);
                            }
                            if (blockCache.ContainsKey(plloc))
                            {
                                return(false);
                            }
                            if (absolute.Contains(plloc))
                            {
                                return(false);
                            }
                            absolute.Add(plloc);
                            blockCache.Add(plloc, ResultType.Self_Point_Alt);
                            return(false);
                        });
                    }
                    #endregion
                }
                check.Remove(Vector3I.Zero);
                int cnt  = 0;
                int mod  = m_rand.Next(CoreHolo.instance.settings.vox_cnt);
                int hits = 0;
                foreach (KeyValuePair <Vector3I, ResultType> kpair in blockCache)
                {
                    cnt++;
                    bool     skip = false;
                    Vector3I spos = kpair.Key;
                    if (spos == Vector3I.Zero)
                    {
                        continue;
                    }
                    Vector3D trail = new Vector3D(spos);
                    double   dist = trail.Length();
                    double   x = 0.5, y = 0.5, z = 0.5;
                    if (!absolute.Contains(spos))
                    {
                        for (int step = 0; step < dist; step++)
                        {
                            x += trail.X / dist;
                            y += trail.Y / dist;
                            z += trail.Z / dist;
                            Vector3I checkPos   = new Vector3I((int)x, (int)y, (int)z);
                            Vector3I checkPosXp = new Vector3I((int)x + 1, (int)y, (int)z);
                            Vector3I checkPosXm = new Vector3I((int)x - 1, (int)y, (int)z);
                            Vector3I checkPosYp = new Vector3I((int)x, (int)y + 1, (int)z);
                            Vector3I checkPosYm = new Vector3I((int)x, (int)y - 1, (int)z);
                            Vector3I checkPosZp = new Vector3I((int)x, (int)y, (int)z + 1);
                            Vector3I checkPosZm = new Vector3I((int)x, (int)y, (int)z - 1);
                            if (check.Contains(checkPos))
                            {
                                if (checkPos != spos)
                                {
                                    if (x > 0)
                                    {
                                        if (!check.Contains(checkPosXp))
                                        {
                                            break;
                                        }
                                    }
                                    if (x < 0)
                                    {
                                        if (!check.Contains(checkPosXm))
                                        {
                                            break;
                                        }
                                    }
                                    if (y > 0)
                                    {
                                        if (!check.Contains(checkPosYp))
                                        {
                                            break;
                                        }
                                    }
                                    if (y < 0)
                                    {
                                        if (!check.Contains(checkPosYm))
                                        {
                                            break;
                                        }
                                    }
                                    if (z > 0)
                                    {
                                        if (!check.Contains(checkPosZp))
                                        {
                                            break;
                                        }
                                    }
                                    if (z < 0)
                                    {
                                        if (!check.Contains(checkPosZm))
                                        {
                                            break;
                                        }
                                    }
                                    skip = true;
                                }
                                break;
                            }
                        }
                        if (skip)
                        {
                            continue;
                        }
                    }
                    blockcolor = kpair.Value;
                    if (blockcolor == ResultType.Voxel)
                    {
                        hits++;
                        if (hits > 10)
                        {
                            if (cnt % CoreHolo.instance.settings.vox_cnt != mod)
                            {
                                continue;
                            }
                        }
                    }
                    IMySensorBlock result;
                    if (pingCache.TryGetValue(spos, out result))
                    {
                        pingResult.Add(spos, result);
                    }

                    /*MyObjectBuilder_CubeBlock bl = new MyObjectBuilder_CubeBlock()
                     * {
                     *      EntityId = NewEntityId++,
                     *      SubtypeName = "SC_RadarBlip",
                     *      Min = spos,
                     *      ColorMaskHSV = RadarResult.getColor(blockcolor).ColorToHSVDX11(),
                     *      BlockOrientation = new SerializableBlockOrientation(Base6Directions.Direction.Forward, Base6Directions.Direction.Up)
                     * };*/
                    //if(!p_grid.CubeBlocks.Contains(bl)) p_grid.CubeBlocks.Add(bl);
                    if (!m_ColorData.ContainsKey(spos))
                    {
                        m_ColorData.Add(spos, blockcolor);
                    }
                }
                //_result.AddCompleteGrid(p_grid);
                T_result.ColorData = m_ColorData;
            }
            catch (Exception ex)
            {
                //MyAPIGateway.Utilities.ShowMessage("Error", ex.ToString());
                //Log.DebugWrite(DebugLevel.Error, ex);
            }
        }
Exemplo n.º 5
0
 public RadarResult(RadarResult t_result)
 {
     m_ColorData = new Dictionary <Vector3I, ResultType>(t_result.m_ColorData);
 }