public bool Register(ref List <Unit>[] allUnits, tempMap gameData, int x, int y, Microsoft.Xna.Framework.Graphics.GraphicsDevice g, int owner, int mode) { //adds building to list (at mouse position (x,y)) //mode 0 for building, mode 1 for unit creation (so they don't conflict) bool success = false; int goldRequired, lumberRequired, foodRequired; //int owner = this.building.owner; //default //Set resource for each building here (I don't know yet) if (this.buildStr != null || this.newUnitStr != null) //we actually have stuff to build { int typeIndex; if (mode == 0) { typeIndex = nameTranslation(this.buildStr); //get index } else { typeIndex = nameTranslation(this.newUnitStr); } goldRequired = SplashScreen.unitData.goldCost[typeIndex]; lumberRequired = SplashScreen.unitData.lumberCost[typeIndex]; foodRequired = SplashScreen.unitData.foodConsumption[typeIndex]; int checkMode = 0; string curBuildStr; int unitW, unitH; if (this.buildStr != null && mode == 0) { curBuildStr = this.buildStr; unitW = this.building.unitTileWidth; unitH = this.building.unitTileHeight; //unitW = this.building.defaultUnitTileW; //unitH = this.building.defaultUnitTileH; checkMode = 0; } else { curBuildStr = this.newUnitStr; unitW = this.newUnit.unitTileWidth; unitH = this.newUnit.unitTileHeight; //unitW = this.newUnit.defaultUnitTileW; //unitH = this.newUnit.defaultUnitTileH; checkMode = 1; } if (gameData.canBuildOn(x, y, curBuildStr) && openSpace(x, y, unitW, unitH, allUnits, gameData, checkMode)) { if (mode == 0 && gameData.gold[owner] >= goldRequired && gameData.lumber[owner] >= lumberRequired && this.building.unitType >= SplashScreen.numUnits) { //checks that we have enough resource Unit temp = new Unit(curBuildStr, x, y, owner, this.findLastID(allUnits[owner]) + 1, ref gameData); //+1 for new id if (temp.unitType >= SplashScreen.numUnits) { temp.setBuildFrame(1); //set to construction frame for building } //Init minimap data for unit Microsoft.Xna.Framework.Color[] uCol = new Microsoft.Xna.Framework.Color[1]; // Unit Color uCol[0] = Microsoft.Xna.Framework.Color.Yellow; //Microsoft.Xna.Framework.Graphics.Texture2D tempImg = getTextureFromBitmap(temp.objectImage, g); //temp.objImg2D = tempImg; //store the img Microsoft.Xna.Framework.Graphics.Texture2D uRec = new Microsoft.Xna.Framework.Graphics.Texture2D(g, 1, 1); uRec.SetData(uCol); temp.uRec = uRec; allUnits[temp.owner].Add(temp); //add unit gameData.gold[owner] -= goldRequired; gameData.lumber[owner] -= lumberRequired; //don't need to subtract/add food as that will be auto updated when unit added to screen this.building = null; this.buildStr = null; success = true; buildCancel(); //finished building so cancel build mode } //else if (mode == 1 && gameData.gold[owner] >= goldRequired && gameData.lumber[owner] >= lumberRequired && (gameData.foodMax[owner] >= foodRequired + gameData.food[owner])) //a unit else if (mode == 1 && (gameData.foodMax[owner] >= foodRequired + gameData.food[owner])) //a unit so only check if enough open population in order to register unit (if not the buffer will make it so we wait for enough population) { //unit creation probably Unit temp = new Unit(curBuildStr, x, y, owner, this.findLastID(allUnits[owner]) + 1, ref gameData); //+1 for new id //Init minimap data for unit Microsoft.Xna.Framework.Color[] uCol = new Microsoft.Xna.Framework.Color[1]; // Unit Color uCol[0] = Microsoft.Xna.Framework.Color.Yellow; //Microsoft.Xna.Framework.Graphics.Texture2D tempImg = getTextureFromBitmap(temp.objectImage, g); //temp.objImg2D = tempImg; //store the img Microsoft.Xna.Framework.Graphics.Texture2D uRec = new Microsoft.Xna.Framework.Graphics.Texture2D(g, 1, 1); uRec.SetData(uCol); temp.uRec = uRec; allUnits[temp.owner].Add(temp); //add unit //Don't subtract resource here, subtracted when queueing //gameData.gold[owner] -= goldRequired; //gameData.lumber[owner] -= lumberRequired; //don't need to subtract/add food as that will be auto updated when unit added to screen this.newUnit = null; this.newUnitStr = null; success = true; } else { if (mode == 0) { this.buildMode = 0; this.buildStr = null; this.building = null; } } } else { if (mode == 0) { this.buildMode = 0; this.buildStr = null; this.building = null; } } } return(success); //if build fails, we have to change menus back (like calling cancel) }