Example #1
0
        public AssetData LoadAssetData()
        {
            string    folder = "res"; //resource folder
            AssetData temp   = new AssetData();

            //Init all storage memory
            temp.hitPoints         = new int[assetTypes.Length];
            temp.armor             = new int[assetTypes.Length];
            temp.sight             = new int[assetTypes.Length];
            temp.sightConstruction = new int[assetTypes.Length];
            temp.size              = new int[assetTypes.Length];
            temp.speed             = new int[assetTypes.Length];
            temp.goldCost          = new int[assetTypes.Length];
            temp.lumberCost        = new int[assetTypes.Length];
            temp.foodConsumption   = new int[assetTypes.Length];
            temp.buildTime         = new int[assetTypes.Length];
            temp.attackSteps       = new int[assetTypes.Length];
            temp.reloadSteps       = new int[assetTypes.Length];
            temp.basicDamage       = new int[assetTypes.Length];
            temp.piercingDamage    = new int[assetTypes.Length];
            temp.range             = new int[assetTypes.Length];
            temp.capabilityCount   = new int[assetTypes.Length];
            temp.capabilitiesNames = new List <string> [assetTypes.Length];
            temp.requirementCount  = new int[assetTypes.Length];
            temp.requirementList   = new List <string> [assetTypes.Length];


            for (int i = 0; i < assetTypes.Length; i++)                  //iterate through all assetTypes in above array
            {
                string   curFile = assetTypes[i] + ".dat";               //generate dat file name
                string   imgpath = @"data\" + folder + @"\" + curFile;   //generate full image path
                string[] lines   = System.IO.File.ReadAllLines(imgpath); //read all the lines
                int      index   = 3;                                    //start at index 3 to skip first 3 comment line basically
                //Load all data into data structure for easy readability
                Int32.TryParse(lines[index], out temp.hitPoints[i]);
                index += 2;
                Int32.TryParse(lines[index], out temp.armor[i]);
                index += 2;
                Int32.TryParse(lines[index], out temp.sight[i]);
                index += 2;
                Int32.TryParse(lines[index], out temp.sightConstruction[i]);
                index += 2;
                Int32.TryParse(lines[index], out temp.size[i]);
                index += 2;
                Int32.TryParse(lines[index], out temp.speed[i]);
                index += 2;
                Int32.TryParse(lines[index], out temp.goldCost[i]);
                index += 2;
                Int32.TryParse(lines[index], out temp.lumberCost[i]);
                index += 2;
                Int32.TryParse(lines[index], out temp.foodConsumption[i]);
                index += 2;
                Int32.TryParse(lines[index], out temp.buildTime[i]);
                index += 2;
                Int32.TryParse(lines[index], out temp.attackSteps[i]);
                index += 2;
                Int32.TryParse(lines[index], out temp.reloadSteps[i]);
                index += 2;
                Int32.TryParse(lines[index], out temp.basicDamage[i]);
                index += 2;
                Int32.TryParse(lines[index], out temp.piercingDamage[i]);
                index += 2;
                Int32.TryParse(lines[index], out temp.range[i]);
                index += 2;
                Int32.TryParse(lines[index], out temp.capabilityCount[i]);
                index += 2;
                temp.capabilitiesNames[i] = new List <string>();
                for (int j = 0; j < temp.capabilityCount[i]; j++) //load list of capabilities
                {
                    temp.capabilitiesNames[i].Add(lines[index]);  //add to list
                    index++;
                }
                index++; //to skip comment line
                Int32.TryParse(lines[index], out temp.requirementCount[i]);
                index += 2;
                temp.requirementList[i] = new List <string>();
                for (int j = 0; j < temp.requirementCount[i]; j++) //load list of requirements
                {
                    temp.requirementList[i].Add(lines[index]);     //add to list
                    index++;
                }
            }

            return(temp);
        }
Example #2
0
        static void initAssets()
        {
            //Load background for maplist menu
            //6=black, 1 = blue
            Bitmap backGroundImage = new Bitmap(@"data\img\Texture.png");

            Color[] blueData   = new Color[4];
            Color[] blackData  = new Color[4];
            Color[] blackData2 = new Color[4];

            for (int i = 0; i < 4; i++)
            {
                blueData[i]   = color.GetPixel(i, 1);
                blackData[i]  = color.GetPixel(i, 6);
                blackData2[i] = backGroundImage.GetPixel(i, 0); //using this actually shows that we can't change color, but it's not changing from black (so the provided colors.dat black pixels are wrong?)
            }
            //Iterate through all pixels and change black to blue
            for (int j = 0; j < backGroundImage.Height; j++)
            {
                for (int i = 0; i < backGroundImage.Width; i++)
                {
                    if (backGroundImage.GetPixel(i, j) == blackData[0])
                    {
                        backGroundImage.SetPixel(i, j, blueData[0]);
                    }
                    if (backGroundImage.GetPixel(i, j) == blackData[1])
                    {
                        backGroundImage.SetPixel(i, j, blueData[1]);
                    }
                    if (backGroundImage.GetPixel(i, j) == blackData[2])
                    {
                        backGroundImage.SetPixel(i, j, blueData[2]);
                    }
                    if (backGroundImage.GetPixel(i, j) == blackData[3])
                    {
                        backGroundImage.SetPixel(i, j, blueData[3]);
                    }
                }
            }

            mapListBG = backGroundImage;

            int numFiles = mapObject.mapNames.Length;

            //Asset stuff
            mapUnits = new AssetsOnMap();              //class to hold all loaded data
            PlayerAsset tempAsset = new PlayerAsset(); //the loader

            mapUnits.playerChoice = 1;                 //default as player1 (we can only play as that it seems) (set to nature = 0 for testing)
            mapUnits.numPlayer    = new int[numFiles];
            mapUnits.startGold    = new int[numFiles][];
            mapUnits.startLumber  = new int[numFiles][];
            mapUnits.mapAssets    = new List <Asset> [numFiles][];
            mapUnits.DLumber      = new int[numFiles][];

            for (int i = 0; i < numFiles; i++)
            {
                int      mapY     = mapObject.mapY[i];
                int      mapX     = mapObject.mapX[i];
                string[] curLines = mapObject.mapLines[i];
                Tuple <List <Asset>[], int[], int[], int> tempRet = tempAsset.LoadAsset(curLines, mapY);
                mapUnits.mapAssets[i]   = tempRet.Item1;
                mapUnits.startGold[i]   = tempRet.Item2;
                mapUnits.startLumber[i] = tempRet.Item3;
                mapUnits.numPlayer[i]   = tempRet.Item4;
                //mapObject.mapLines[i] = null; //free data?

                //init global lumber for all maps
                mapUnits.DLumber[i] = new int[(mapX + 1) * (mapY + 1)]; //same size as Dpartials or mapString
                for (int y = 0; y < mapY + 1; y++)
                {
                    for (int x = 0; x < mapX + 1; x++)
                    {
                        if (mapObject.allMapStrings[i][y * (mapX + 1) + x] == "forest")
                        {//is forest so set starting lumber of a tree at a spot to nature's lumber value (should be 400 by default)
                            mapUnits.DLumber[i][y * (mapX + 1) + x] = mapUnits.startLumber[i][0];
                        }
                        else
                        {
                            mapUnits.DLumber[i][y * (mapX + 1) + x] = 0;  //no lumber as it's not forest tile
                        }
                    }
                }
            }
            Tuple <Bitmap[][], string[][], int[], int[]> tempUnit = tempAsset.LoadAssetTiles();

            mapUnits.allUnitTiles       = tempUnit.Item1;
            mapUnits.allUnitLines       = tempUnit.Item2;
            mapUnits.allUnitTileW       = tempUnit.Item3;
            mapUnits.allUnitTileH       = tempUnit.Item4;
            mapUnits.decayTiles         = tempAsset.LoadCorpse();
            mapUnits.buildingDeathTiles = tempAsset.ScaleBuildingDeath(mapUnits.allUnitTiles, mapUnits.decayTiles);
            mapUnits.allProjectiles     = tempAsset.LoadProjectiles();

            unitData        = tempAsset.LoadAssetData();   //load asset .dat
            unitUpgradeData = tempAsset.LoadUpgradeData(); //load upgrade .dat

            mapUnits.miniBevel       = tempAsset.loadMiniBevel();
            mapUnits.droppedResource = tempAsset.loadDroppedResource();

            //free the inited temp stuff?
            initButtons();
        }