Ejemplo n.º 1
0
            void LoadHandler(MyIni ini)
            {
                int iCount;

                iCount = ini.Get(sOreSection, "count").ToInt32();

                _oreLocs.Clear();
                long     eId           = 0;
                int      oreID         = 0;
                Vector3D position      = new Vector3D(0, 0, 0);
                Vector3D vector        = new Vector3D(0, 0, 0);
                long     detectionType = 0;

                for (int j1 = 0; j1 < iCount; j1++)
                {
                    eId = ini.Get(sOreSection, "AsteroidId" + j1.ToString()).ToInt32(0);

                    oreID = ini.Get(sOreSection, "oreId" + j1.ToString()).ToInt32(0);

                    Vector3D.TryParse(ini.Get(sOreSection, "position" + j1.ToString()).ToString(), out position);
                    Vector3D.TryParse(ini.Get(sOreSection, "vector" + j1.ToString()).ToString(), out vector);
                    detectionType = ini.Get(sOreSection, "detectiontype" + j1.ToString()).ToInt32();

                    OreLocInfo ore = new OreLocInfo
                    {
                        AstEntityId   = eId,
                        oreId         = oreID,
                        position      = position,
                        vector        = vector,
                        detectionType = detectionType
                    };
                    _oreLocs.Add(ore);
                }
            }
Ejemplo n.º 2
0
            void BroadcastHandler(MyIGCMessage msg)
            {
                // NOTE: called on ALL received messages; not just 'our' tag
                if (msg.Tag == sOreTag)
                {
                    if (msg.Data is string)
                    {
                        string[] aMessage = ((string)msg.Data).Trim().Split(':');
                        double   x1, y1, z1;

                        int iOffset = 0;

                        //  antSend("WICO:ORE:" + Me.CubeGrid.EntityId.ToString() + ":" + asteroidId + ":" + OreID + ":" + Vector3DToString(Position) + ":" + Vector3DToString(vVec) + ":" + detectionType.ToString());
                        //  antSend("WICO:ORE:" + asteroidId + ":" + OreID + ":" + Vector3DToString(Position) + ":" + Vector3DToString(vVec) + ":" + detectionType.ToString());

                        long asteroidID = 0;
                        long.TryParse(aMessage[iOffset++], out asteroidID);

                        int oreID = 0;
                        int.TryParse(aMessage[iOffset++], out oreID);

                        x1 = Convert.ToDouble(aMessage[iOffset++]);
                        y1 = Convert.ToDouble(aMessage[iOffset++]);
                        z1 = Convert.ToDouble(aMessage[iOffset++]);
                        Vector3D position = new Vector3D(x1, y1, z1);

                        x1 = Convert.ToDouble(aMessage[iOffset++]);
                        y1 = Convert.ToDouble(aMessage[iOffset++]);
                        z1 = Convert.ToDouble(aMessage[iOffset++]);
                        Vector3D vector = new Vector3D(x1, y1, z1);

                        long detectionType = 0;
                        long.TryParse(aMessage[iOffset++], out detectionType);

                        OreLocInfo ore = new OreLocInfo
                        {
                            AstEntityId   = asteroidID,
                            oreId         = oreID,
                            position      = position,
                            vector        = vector,
                            detectionType = detectionType
                        };
                        _oreLocs.Add(ore);
                    }
                }
            }
Ejemplo n.º 3
0
        void addOreLoc(long asteroidId, int OreID, Vector3D Position, Vector3D vVec, long detectionType)
        {
            OreLocInfo oli = new OreLocInfo();

            oli.oreId         = OreID;
            oli.AstEntityId   = asteroidId;
            oli.position      = Position;
            oli.vector        = vVec;
            oli.detectionType = detectionType;
            //TODO:
            // search by position and only add if NOT 'near' another entry
            oreLocs.Add(oli);
            // transmit found location...
            antSend("WICO:ORE:" + Me.CubeGrid.EntityId.ToString() + ":" + asteroidId + ":" + OreID + ":" + Vector3DToString(Position) + ":" + Vector3DToString(vVec) + ":" + detectionType.ToString());

            // write data back to text panel if changed..
        }
Ejemplo n.º 4
0
        void OreAddLoc(long asteroidId, int OreID, Vector3D Position, Vector3D vVec, long detectionType)
        {
            OreLocInfo oli = new OreLocInfo();

            oli.oreId         = OreID;
            oli.AstEntityId   = asteroidId;
            oli.position      = Position;
            oli.vector        = vVec;
            oli.detectionType = detectionType;
            //TODO:
            // search by position and only add if NOT 'near' another entry
            oreLocs.Add(oli);
            //should be done by caller            OreSerialize();
            // transmit found location...
//            antSend("WICO:ORE:" + Me.CubeGrid.EntityId.ToString() + ":" + asteroidId + ":" + OreID + ":" + Vector3DToString(Position) + ":" + Vector3DToString(vVec) + ":" + detectionType.ToString());
            antSend("ORE", Me.CubeGrid.EntityId.ToString() + ":" + asteroidId + ":" + OreID + ":" + Vector3DToString(Position) + ":" + Vector3DToString(vVec) + ":" + detectionType.ToString());
            //            sInitResults += "\nAdded Ore id=" + OreID + " count=" + oreLocs.Count();
        }
Ejemplo n.º 5
0
        int OreDeserialize()
        {
            if (iniWicoCraftSave == null)
            {
                return(-1);
            }

            int iCount = 0;

            iniWicoCraftSave.GetValue(sOreSection, "count", ref iCount);
//            Echo("OreDeserialize Count=" + iCount);
//            if (iCount > 0) sInitResults += "\nODeserialize count>0";

            oreLocs.Clear();
            long     eId           = 0;
            int      oreID         = 0;
            Vector3D position      = new Vector3D(0, 0, 0);
            Vector3D vector        = new Vector3D(0, 0, 0);
            long     detectionType = 0;

            for (int j1 = 0; j1 < iCount; j1++)
            {
                iniWicoCraftSave.GetValue(sOreSection, "AsteroidId" + j1.ToString(), ref eId);
                iniWicoCraftSave.GetValue(sOreSection, "oreId" + j1.ToString(), ref oreID);
                iniWicoCraftSave.GetValue(sOreSection, "position" + j1.ToString(), ref position);
                iniWicoCraftSave.GetValue(sOreSection, "vector" + j1.ToString(), ref vector);
                iniWicoCraftSave.GetValue(sOreSection, "detectiontype" + j1.ToString(), ref detectionType);

                OreLocInfo ore = new OreLocInfo
                {
                    AstEntityId   = eId,
                    oreId         = oreID,
                    position      = position,
                    vector        = vector,
                    detectionType = detectionType
                };
                oreLocs.Add(ore);
            }
            return(iCount);
        }
Ejemplo n.º 6
0
        int OreDeserialize()
        {
            string sOreSave;

            if (iniWicoCraftSave == null)
            {
                return(-1);
            }

            sOreSave = iniWicoCraftSave.GetSection(sOreSection);
            if (sOreSave == sLastOreLoad)
            {
                return(-2);                          // no changes in saved info.
            }
            if (sOreSave.Length < 1)
            {
                return(-3);
            }

            oreLocs.Clear();
            double x1, y1, z1;

            sLastOreLoad = sOreSave;
            string[] atheStorage = sOreSave.Split('\n');

            int iLine = 0;

            /*
             * // Trick using a "local method", to get the next line from the array `atheStorage`.
             * Func<string> getLine = () =>
             * {
             *  return (iLine >= 0 && atheStorage.Length > iLine ? atheStorage[iLine++] : null);
             * };
             */
            int iCount = -1;

            if (atheStorage.Length < 2)
            {
                return(-4); // nothing to parse
            }
            //            Echo(atheStorage[iLine]);
            iCount = Convert.ToInt32(atheStorage[iLine++]);
            //            Echo("total="+iCount);

            for (int j = 0; j < iCount; j++)
            {
                //                Echo("#="+j);

                //                Echo(atheStorage[iLine]);
                long eId = Convert.ToInt64(atheStorage[iLine++]);

                int oreID = Convert.ToInt32(atheStorage[iLine++]);

                //                Echo(atheStorage[iLine]);
                ParseVector3d(atheStorage[iLine++], out x1, out y1, out z1);
                Vector3D position = new Vector3D(x1, y1, z1);

                //                Echo(atheStorage[iLine]);
                ParseVector3d(atheStorage[iLine++], out x1, out y1, out z1);
                Vector3D vector = new Vector3D(x1, y1, z1);

                //                Echo(atheStorage[iLine]);
                long detectionType = Convert.ToInt64(atheStorage[iLine++]);

                OreLocInfo ore = new OreLocInfo();
                ore.AstEntityId   = eId;
                ore.oreId         = oreID;
                ore.position      = position;
                ore.vector        = vector;
                ore.detectionType = detectionType;
                oreLocs.Add(ore);
                //                Echo("----");
            }
            return(iCount);
        }
Ejemplo n.º 7
0
        bool OreProcessMessage(string sMessage)
        {
            double x1, y1, z1;

            string[] aMessage = sMessage.Trim().Split(':');

            if (aMessage.Length > 1)
            {
                if (aMessage[0] != "WICO")
                {
                    Echo("not wico system message");
                    return(false);
                }
                if (aMessage.Length > 2)
                {
                    if (aMessage[1] == "ORE")
                    {
//                        sInitResults += "Got ORE Message:\n" + sMessage;
                        //           0      1           2                                    3               4                5                                6                                7
                        //  antSend("WICO:ORE:" + Me.CubeGrid.EntityId.ToString() + ":" + asteroidId + ":" + OreID + ":" + Vector3DToString(Position) + ":" + Vector3DToString(vVec) + ":" + detectionType.ToString());

                        int iOffset = 2;

                        long id = 0; // message source
                        long.TryParse(aMessage[iOffset++], out id);

                        long asteroidID = 0;
                        long.TryParse(aMessage[iOffset++], out asteroidID);

                        int oreID = 0;
                        int.TryParse(aMessage[iOffset++], out oreID);

                        x1 = Convert.ToDouble(aMessage[iOffset++]);
                        y1 = Convert.ToDouble(aMessage[iOffset++]);
                        z1 = Convert.ToDouble(aMessage[iOffset++]);
                        Vector3D position = new Vector3D(x1, y1, z1);

                        x1 = Convert.ToDouble(aMessage[iOffset++]);
                        y1 = Convert.ToDouble(aMessage[iOffset++]);
                        z1 = Convert.ToDouble(aMessage[iOffset++]);
                        Vector3D vector = new Vector3D(x1, y1, z1);

                        long detectionType = 0;
                        long.TryParse(aMessage[iOffset++], out detectionType);

                        OreLocInfo ore = new OreLocInfo
                        {
                            AstEntityId   = asteroidID,
                            oreId         = oreID,
                            position      = position,
                            vector        = vector,
                            detectionType = detectionType
                        };
                        oreLocs.Add(ore);
                        //                       sInitResults += "\noreLocs After=" + oreLocs.Count;
//    sInitResults += "\nIncoming ORE  Processed!";
                        return(true); // we processed it
                    }
                    else if (aMessage[1] == "ORE?")
                    { // TODO: process request for known Ore
                    }
                }
            }
            return(false);
        }