Example #1
0
        public ObjectTypeManager(string objFileName)
        {
            string ObjFileName = System.IO.Path.ChangeExtension(objFileName, "pak");

            this.objPakFile = new PakFile(MCGExtensions.PathCombine(new string[] { MechCommanderUnity.Instance.MCGPath, "objects", ObjFileName }));

            ObjectTypeList = new Dictionary <int, ObjectType>();
        }
        public AppearanceTypeManager(string spriteFileName)
        {
            spriteFileName = System.IO.Path.ChangeExtension(spriteFileName, "pak");

            this.spritePakFile = new PakFile(MCGExtensions.PathCombine(new string[] { MechCommanderUnity.Instance.MCGPath, "sprites", spriteFileName }));


            AppearanceTypeList = new Dictionary <int, AppearanceType>();
        }
Example #3
0
        public MapBlockManager(string terrainFileName, int BlocksMapSide, int VerticesBlockSide)
        {
            string ElvFileName = System.IO.Path.ChangeExtension(terrainFileName, "elv");

            this.VerticesBlockSide = VerticesBlockSide;
            MapElvFile terrainElvFile = new MapElvFile(MechCommanderUnity.Instance.FileManager.File(MCGExtensions.PathCombine(new string[] { "terrain", ElvFileName })), BlocksMapSide, VerticesBlockSide);

            blocks = terrainElvFile.GetVertices();
        }
Example #4
0
        public Terrain(string terrainFileName)//FITFile terrainFitFile)
        {
            terrainName = terrainFileName;

            string TerrainFileName = System.IO.Path.ChangeExtension(terrainFileName, "fit");

            FITFile terrainFitFile = new FITFile(MechCommanderUnity.Instance.FileManager.File(MCGExtensions.PathCombine(new string[] { "terrain", TerrainFileName })));

            terrainFitFile.SeekSection("TerrainData");

            terrainFitFile.GetInt("VerticesBlockSide", out this.verticesBlockSide);
            terrainFitFile.GetInt("BlocksMapSide", out this.blocksMapSide);

            terrainFitFile.GetFloat("MetersPerElevLevel", out this.MetersPerElevLevel);
            terrainFitFile.GetFloat("MetersPerVertex", out this.MetersPerVertex);

            terrainFitFile.GetInt("VisibleVerticesPerSide", out this.visibleVerticesPerSide);

            terrainFitFile.SeekSection("TileData");

            string TerrainTileFile;

            terrainFitFile.GetString("TerrainTileFile", out TerrainTileFile);

            this.realVerticesMapSide = this.verticesBlockSide * this.blocksMapSide;
            this.halfVerticesMapSide = this.realVerticesMapSide / 2;

            this.worldUnitsMapSide = this.realVerticesMapSide * MetersPerVertex;

            this.numObjBlocks   = this.blocksMapSide * this.blocksMapSide;
            this.numObjVertices = this.verticesBlockSide * this.verticesBlockSide;

            //Init TerrainTiles
            TerrainTiles = new TerrainTiles(terrainFileName, TerrainTileFile, (int)this.blocksMapSide, (int)this.verticesBlockSide);

            //Init MapBlockManager
            MapBlock = new MapBlockManager(terrainFileName, (int)this.blocksMapSide, (int)this.verticesBlockSide);

            //Init VertexManager

            //Init TerrainTileManager

            //Init ObjectManager
            ObjBlock = new ObjectBlockManager(terrainFileName);

            //Init TacticalMap
        }
Example #5
0
        public TerrainTiles(string terrainFileName, string TerrainTileFile, int NumBlocks, int NumVertices)
        {
            this.terrainFileName = terrainFileName;
            this.TerrainTileFile = TerrainTileFile;



            /*  string PreFileName = System.IO.Path.ChangeExtension(terrainFileName, "pre");
             *
             * MapPreFile terrainPreFile = new MapPreFile(MCGExtensions.PathCombine(new string[] { MechCommanderUnity.Instance.MCGPath, "terrain", PreFileName }));
             *
             * var lstPreloadTiles = terrainPreFile.GetLstTileIndex();*/

            string ElvFileName = Path.ChangeExtension(terrainFileName, "elv");

            MapElvFile terrainElvFile = new MapElvFile(MechCommanderUnity.Instance.FileManager.File(MCGExtensions.PathCombine(new string[]
                                                                                                                              { "terrain", ElvFileName })), NumBlocks, NumVertices);

            LstTileIndexes = terrainElvFile.GetDifferentTileIds();



            /*
             * MCBitmap atlas;
             * Dictionary<string, Rect> rects;
             * var result = ImageProcessing.CreateAtlas(LstTiles.Values.ToArray(), out atlas, out rects);
             *
             * if (result)
             * {
             *     UnityMainThreadDispatcher.Instance().Enqueue(() =>
             *     {
             *         var packed = ImageProcessing.MakeTexture2D(ref atlas, pak.Palette);
             *         ImageProcessing.SaveTextureAsPng(packed, "prefiles");
             *     });
             * }
             */
        }
Example #6
0
        public bool GetMapPreview(string Mapname, out Texture2D preview)
        {
            preview = new Texture2D(1, 1);
            if (!isReady || Mapname == "")
            {
                return(false);
            }

            var mapPreviewPath = Path.Combine(MapFitPath, Mapname + ".tga").ToUpper();
            var fileData       = MechCommanderUnity.Instance.FileManager.File(mapPreviewPath);

            if (fileData != null)
            {
                MechCommanderUnity.LogMessage("TGA file " + mapPreviewPath);
                preview = TGALoader.LoadTGA(new MemoryStream(fileData));
                return(true);
            }
            else
            {
                var missionFile = new FITFile(MechCommanderUnity.Instance.FileManager.File(MCGExtensions.PathCombine(new string[] { "missions", Mapname + ".fit" })));
                missionFile.SeekSection("TerrainSystem");
                missionFile.GetString("TerrainFileName", out string terrainFileName);
                mapPreviewPath = Path.Combine(MapFitPath, terrainFileName + ".tga").ToUpper();
                fileData       = MechCommanderUnity.Instance.FileManager.File(mapPreviewPath);
                if (fileData != null)
                {
                    MechCommanderUnity.LogMessage("TGA file DIFFERENT NAME " + mapPreviewPath);
                    preview = TGALoader.LoadTGA(new MemoryStream(fileData));
                    return(true);
                }
            }

            MechCommanderUnity.LogMessage("Can´t Find TGA file " + mapPreviewPath);
            return(false);
        }
Example #7
0
        public ObjectBlockManager(string terrainFileName)
        {
            string ObjFileName = System.IO.Path.ChangeExtension(terrainFileName, "obj");

            MapObjFile terrainObjFile = new MapObjFile(MechCommanderUnity.Instance.FileManager.File(MCGExtensions.PathCombine(new string[] { "terrain", ObjFileName })));

            objDataBlock = terrainObjFile.GetLstObjs();
        }
Example #8
0
        public void Init(string missionName, MissionLoadType loadType)
        //public Mission(string missionName, MissionLoadType loadType)
        {
            this.Init();
            float loadProgress = 0f;

            MechCommanderUnity.LogMessage("Loading Mission: " + missionName);

            var auxStr = "";


            //LoadType mission SP (quick or logistic) and MP
            //define team relations

            loadProgress = 4.0f;

            //--------------------------
            // Load Game System stuff...
            //Define General Game Settings

            var generalFitFile = new FITFile(MechCommanderUnity.Instance.FileManager.File(MCGExtensions.PathCombine(new string[] { "missions", "gamesys.fit" })));

            if (generalFitFile.SectionNumber == 0)
            {
                MechCommanderUnity.LogMessage("Error Loading General FitFile :" + MCGExtensions.PathCombine(new string[] { MechCommanderUnity.Instance.MCGPath, "missions", "gamesys.fit" }));
                return;
            }

            //----------------------------------------------------------------------
            // Now that we have some base values, load the master component table...



            //---------------------------------------
            // Read in difficulty here if it exits.
            //InitDifficultySettings(gameSystemFile);


            //---------------------------------------
            // Read Mission File
            missionFileName = Path.ChangeExtension(missionName, "fit");

            //Read Mission Fit File
            missionFile = new FITFile(MechCommanderUnity.Instance.FileManager.File(MCGExtensions.PathCombine(new string[] { "missions", missionFileName })));
            if (missionFile.SectionNumber == 0)
            {
                MechCommanderUnity.LogMessage("Error Loading Mission FitFile :" + MCGExtensions.PathCombine(new string[] { MechCommanderUnity.Instance.MCGPath, "missions", missionFileName }));
            }
            //-----------------------------------------
            // Begin Setting up Teams and Commanders...
            loadProgress = 10.0f;

            //NULL ANY TEAMS & COMMANDERS

            //------------------------------------------------------------
            // First, let's see how many teams and commanders there are...
            long maxTeamID      = -1;
            long maxCommanderID = -1;

            if (loadType == MissionLoadType.MISSION_LOAD_MP_LOGISTICS)
            {
                //MP TEAMS & COMMANDERS
            }
            else
            {
                missionFile.SeekSection("Parts");
                int numParts;

                missionFile.GetInt("NumParts", out numParts);

                if (numParts > 0)
                {
                    for (int i = 1; i < (long)numParts + 1; i++)
                    {
                        //SP TEAMS & COMMANDERS



                        //------------------------------------------------------------------
                        // Find the object to load
                        missionFile.SeekSection("Part" + i);

                        int teamID = -1;
                        missionFile.GetInt("TeamId", out teamID);

                        int commanderID = -1;

                        if (missionFile.GetInt("CommanderId", out commanderID))
                        {
                            int cID;
                            missionFile.GetInt("CommanderId", out cID);
                            commanderID = (sbyte)cID;
                        }

                        //if (MPlayer && dropZoneList)
                        //{
                        //    //-------------------------------------------------------------
                        //    // Since dropZoneList is not NULL, we know this was not started
                        //    // from the command-line...
                        //    long origCommanderID = commanderID;
                        //    commanderID = commandersToLoad[origCommanderID][0];
                        //    teamID = commandersToLoad[origCommanderID][1];
                        //}

                        if (commanderID > maxCommanderID)
                        {
                            maxCommanderID = commanderID;
                        }
                        if (teamID > maxTeamID)
                        {
                            maxTeamID = teamID;
                        }
                    }
                }
            }

            missionFile.SeekSection("PaletteSystem");
            missionFile.GetString("PaletteSystem", out string paletteName);

            ContentReader.PaletteXpansion = paletteName == "palettex";

            //----------------------------------------------
            // Now, init the teams and commanders we need...

            //INIT TEAMS & COMMANDERS

            //-----------------------------
            // Init Trigger Area Manager...

            //-----------------------------------
            // Setup the Sensor System Manager...

            //INIT SENSOR MANAGER

            //INITIAL DROPZONE FROM missionFIle

            missionFile.SeekSection("DropZone0");
            missionFile.GetFloat("PositionX", out dropZone.x);
            missionFile.GetFloat("PositionY", out dropZone.y);

            //-----------------------------------------------------------------
            // Load the names of the scenario tunes.
            missionFile.SeekSection("Music");
            missionFile.GetInt("scenarioTuneNum", out missionTuneNum);
            //auxStr = "";
            //missionFile.getKeyValueBySection("Music", "scenarioTuneNum", out auxStr);
            //missionTuneNum=int.Parse(auxStr);

            //INIT CRATER MANAGER!!?¿?
            //result = craterManager->init(1000,20479,"feet");

//            MechCommanderUnity.LogMessage("Starting ObjectManager");
            //-----------------------------------------------------------------
            // Start the object system next.
            ObjectManager = GameObjectManager.Instance;
//            MechCommanderUnity.LogMessage("Finished ObjectManager");


            //-----------------------------------------------------------------
            // Start the collision detection system. -- Doesn't need objects?

            //------------------------------------------------------------
            // Start the Terrain System

            missionFile.SeekSection("TerrainSystem");
            string terrainFileName;

            missionFile.GetString("TerrainFileName", out terrainFileName);//System.IO.Path.ChangeExtension(missionName, "fit");
            //Read Terrain Fit File
            //INIT TERRAIN FILE
//            MechCommanderUnity.LogMessage("Starting Terrain");
            Terrain = new Terrain(terrainFileName);
            var Map = new GameObject();

            this.MapGO = Map;
//            MechCommanderUnity.LogMessage("Finished Terrain");

            loadProgress = 15.0f;

            //INIT TERRAIN GENERATION
//            MechCommanderUnity.LogMessage("Starting TerrainTiles");
            StartCoroutine(Terrain.InitTerrainTiles(GenerateMapIsoMeshes));
//            MechCommanderUnity.LogMessage("Finished TerrainTiles");
            //long terrainInitResult = land->init(&pakFile, 0, GameVisibleVertices, loadProgress, 20.0 );


            loadProgress = 35.0f;


            // land->load(missionFile);

            loadProgress = 36.0f;


            //----------------------------------------------------
            // Start GameMap for Movement System


            // PathManager = new MovePathManager;

            loadProgress = 40.0f;


            //----------------------
            // Load ABL Libraries...


            //---------------------------
            // Load the mission script...
            //-----------------------------------------------------------------
            // We now read in the mission Script File Name


            loadProgress = 41.0f;

            //-------------------------------------------
            // Load all MechWarriors for this mission...

            //Get Num Warrior from missionFile
            //foreach warrior
            //-------------------------
            // Find the warrior to load
            //--------------------------------------
            // Load the mechwarrior into the mech...
            //----------------------------
            // Read in the Brain module...
            //------------------------------------------------------------
            // For now, all mplayer brains are pbrain. Need to change when
            // we allow ai brains in mplayer...

            //---------------------------------------------------------------
            // Load the brain parameter file and load 'em for each warrior...


            loadProgress = 43.0f;

            //-----------------------------------------------------------------
            // All systems are GO if we reach this point.  Now we need to
            // parse the scenario file for the Objects we need for this scenario
            // We then create each object and place it in the world at the
            // position we read in with the frame we read in.



            //--------------------------------------------------------------------------------
            // IMPORTANT NOTE: mission parts should always start with Part 1.
            // Part 0 is reserved as a "NULL" id for routines that reference the mission
            // parts. AI routines, Brain keywords, etc. use PART ID 0 as an "object not found"
            // error code. DO NOT USE PART 0!!!!!!! Start with Part 1...


            loadProgress = 43.5f;

            //READ SPECIAL PARTS & LOAD THEM

            loadProgress = 48.5f;
            //--------------------------------------------------------------------------
            // Now that the parts data has been loaded, let's prep the ObjectManager for
            // the real things. First, count the number of objects we need...
            long numMechs    = 0;
            long numVehicles = 0;

            //foreach part load in Objectmanager calculate total nummechs & vehicles

            loadProgress = 55.0f;

            //pakFile.seekPacket(1);
            //ObjectManager->countTerrainObjects(&pakFile, (numMechs + MAX_TEAMS * MAX_REINFORCEMENTS_PER_TEAM) + (numVehicles + MAX_TEAMS * MAX_REINFORCEMENTS_PER_TEAM)/* + ObjectManager->maxElementals*/ + 1);
            loadProgress = 58.0f;
            //ObjectManager->setNumObjects(numMechs, numVehicles, 0, -1, -1, -1, 100, 50, 0, 130, -1);

            //-------------------------
            // Load the mech objects...


            loadProgress = 68.0f;

            //  ObjectManager->loadTerrainObjects(&pakFile, loadProgress, 30);
            ObjectManager.terrain = Terrain;
            StartCoroutine(ObjectManager.LoadTerrainObjects(Terrain.ObjBlock.objDataBlock, GenerateMapObj));
            //Terrain.InitTerrainObjects();

            loadProgress = 98.0f;

            //----------------------------------------------
            // Read in the Mission Time Limit.


            //----------------------------------------------
            // Read in the Objectives.  Safe to have none.

            //----------------------------
            // Read in Commander Groups...

            //-----------------------------------------------------------------------
            // Now that the parts are loaded, let's build the roster for each team...

            //---------------------------------------------------------------------------------
            // If we're not playing multiplayer, make sure all home commander movers have their
            // localMoverId set to 0, so the iface can at least check if a mover is player
            // controlled...

            //-----------------------------------------------------
            // This tracks time since scenario started in seconds.

            //----------------------------
            // Create and load the Weather

            //---------------------------------------------------------------
            // Start the Camera and Lists


            //----------------------------------------------------------------------------
            // Start the Mission GUI


            //--------------------------------------------------
            // Close all walls and open gates and landbridges...

//            MechCommanderUnity.LogMessage(loadProgress.ToString());
        }