// ReserveSpace; ideally the reserver would pass himself in as IBuildMapReserver or something , but object for now (not yet used) // note that destroying a unit over this space wont undo reservation, since not included in buildinginfobyid list // (maybe buildinginfobyowner???) public void ReserveSpace(object owner, int mapx, int mapy, int sizex, int sizey) { if (csai.DebugOn) { DrawingUtils.DrawRectangle( new Float3((mapx - sizex / 2) * 8, 0, (mapy - sizey / 2) * 8), sizex * 8, sizey * 8, 0); // logfile.WriteLine( "marking " + thisx + " " + thisy + " as used by " + owner.ToString() ); // aicallback.DrawUnit( "ARMMINE1", new Float3( thisx * 8, aicallback.GetElevation( thisx * 8, thisy * 8 ), thisy * 8 ), 0.0f, 400, aicallback.GetMyAllyTeam(), true, true); } for (int x = 0; x < sizex; x++) { for (int y = 0; y < sizey; y++) { int thisx = mapx + x - sizex / 2; int thisy = mapy + y - sizey / 2; if (thisx >= 0 && thisy >= 0 && thisx < mapwidth && thisy < mapheight) { SquareAvailable[thisx, thisy] = false; } } } }
// mark squares as used // and keep record of where this unit was, and how big, in case it is destroyed public void UnitCreated(int id, IUnitDef unitdef) { if (!buildinginfobyid.Contains(id) && !unitdefhelp.IsMobile(unitdef)) { Float3 pos = aicallback.GetUnitPos(id); int mapposx = (int)(pos.x / 8); int mapposy = (int)(pos.z / 8); //int unitsizex = (int)Math.Ceiling( unitdef.xsize / 8.0 ); //int unitsizey = (int)Math.Ceiling( unitdef.ysize / 8.0 ); int unitsizex = unitdef.xsize; int unitsizey = unitdef.ysize; logfile.WriteLine("Buildmap unitcreated " + unitdef.name + " mappos " + mapposx + " " + mapposy + " unitsize " + unitsizex + " " + unitsizey); buildinginfobyid.Add(id, new BuildingInfo(mapposx, mapposy, unitsizex, unitsizey)); if (csai.DebugOn) { DrawingUtils.DrawRectangle( new Float3((mapposx - unitdef.xsize / 2) * 8, 0, (mapposy - unitdef.ysize / 2) * 8), unitdef.xsize * 8, unitdef.ysize * 8, 0); } for (int x = 0; x < unitsizex; x++) { for (int y = 0; y < unitsizey; y++) { int thisx = mapposx + x - unitdef.xsize / 2; int thisy = mapposy + y - unitdef.ysize / 2; SquareAvailable[thisx, thisy] = false; //if( csai.DebugOn ) //{ // logfile.WriteLine( "marking " + thisx + " " + thisy + " as used by " + unitdef.name ); // aicallback.DrawUnit( "ARMMINE1", new Float3( thisx * 8, aicallback.GetElevation( thisx * 8, thisy * 8 ), thisy * 8 ), 0.0f, 400, aicallback.GetMyAllyTeam(), true, true); //} } } } }