Exemplo n.º 1
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);
        }
Exemplo n.º 2
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
        }
Exemplo n.º 3
0
        public ObjectType(FITFile objFitFile)
        {
            objFitFile.SeekSection("ObjectType");
            objFitFile.GetString("Name", out name);


            objFitFile.GetInt("Appearance", out appearName);
            objFitFile.GetInt("ExplosionObject", out int obj);
            ExplosionObject = obj;
            objFitFile.GetInt("DestroyedObject", out obj);
            DestroyedObject = obj;
            objFitFile.GetFloat("ExtentRadius", out extentRadius);



            keepMe = true;              //Never cache out anymore!
            teamId = -1;                //Everything starts out Neutral now.
        }
Exemplo n.º 4
0
        public AppearanceType(FITFile spriteFile)
        {
            spriteFile.SeekSection("Main Info");

            spriteFile.GetString("Name", out name);

            if (!spriteFile.GetInt("Delta", out delta))
            {
                delta = 0;
            }

            if (spriteFile.SeekSection("Bounds"))
            {
                designerTypeBounds = true;

                spriteFile.GetInt("UpperLeftX", out boundsUpperLeftX);
                spriteFile.GetInt("UpperLeftY", out boundsUpperLeftY);
                spriteFile.GetInt("LowerRightX", out boundsLowerRightX);
                spriteFile.GetInt("LowerRightY", out boundsLowerRightY);
            }
        }
Exemplo n.º 5
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());
        }