bool BuildingPlacer::canBuildHereWithSpace(BWAPI::TilePosition position, BWAPI::UnitType type) const { if (!this->canBuildHere(position, type)) return false; int width=type.tileWidth(); int height=type.tileHeight(); if (type==BWAPI::UnitTypes::Terran_Command_Center || type==BWAPI::UnitTypes::Terran_Factory || type==BWAPI::UnitTypes::Terran_Starport || type==BWAPI::UnitTypes::Terran_Science_Facility) { width+=2; } int startx = position.x() - buildDistance; if (startx<0) startx=0; int starty = position.y() - buildDistance; if (starty<0) starty=0; int endx = position.x() + width + buildDistance; if (endx>BWAPI::Broodwar->mapWidth()) endx=BWAPI::Broodwar->mapWidth(); int endy = position.y() + height + buildDistance; if (endy>BWAPI::Broodwar->mapHeight()) endy=BWAPI::Broodwar->mapHeight(); for(int x = startx; x < endx; x++) for(int y = starty; y < endy; y++) if (!type.isRefinery()) if (!buildable(x, y)) return false; if (position.x()>3) { int startx2=startx-2; if (startx2<0) startx2=0; for(int x = startx2; x < startx; x++) for(int y = starty; y < endy; y++) { std::set<BWAPI::Unit*> units = BWAPI::Broodwar->unitsOnTile(x, y); for(std::set<BWAPI::Unit*>::iterator i = units.begin(); i != units.end(); i++) { if (!(*i)->isLifted()) { BWAPI::UnitType type=(*i)->getType(); if (type==BWAPI::UnitTypes::Terran_Command_Center || type==BWAPI::UnitTypes::Terran_Factory || type==BWAPI::UnitTypes::Terran_Starport || type==BWAPI::UnitTypes::Terran_Science_Facility) { return false; } } } } } return true; }
void Building::draw_buildable(Map *map){ //set_pos(x,y,z); Display::CubeLight* building_light=new Display::CubeLight(); if(buildable(x,y,z)){ building_light->color=glm::vec3(0,1,0); }else{ building_light->color=glm::vec3(1,0,0); } building_light->cube_size=glm::vec3( Map::CUBE_SIZE*1.05*get_cube_large_size().x, Map::CUBE_SIZE*1.05*get_cube_large_size().y, Map::CUBE_SIZE*1.05*get_cube_large_size().z); building_light->pos=glm::vec3( x*Map::CUBE_SIZE+0.49*building_light->cube_size.x, y*Map::CUBE_SIZE+0.49*building_light->cube_size.y, z*Map::CUBE_SIZE+0.49*building_light->cube_size.z); Display::Draw::get_cur_object()->lightControl->push_temp_light(building_light); draw(); }
bool BuildingPlacer::canBuildHereWithSpace(BWAPI::TilePosition position, BWAPI::UnitType type, int buildDist) const { //returns true if we can build this type of unit here with the specified amount of space. //space value is stored in this->buildDistance. //if we can't build here, we of course can't build here with space if (!this->canBuildHere(position, type)) return false; int width=type.tileWidth(); int height=type.tileHeight(); //make sure we leave space for add-ons. These types of units can have addons: if (type==BWAPI::UnitTypes::Terran_Command_Center || type==BWAPI::UnitTypes::Terran_Factory || type==BWAPI::UnitTypes::Terran_Starport || type==BWAPI::UnitTypes::Terran_Science_Facility) { width+=2; } int startx = position.x() - buildDist; if (startx<0) return false; int starty = position.y() - buildDist; if (starty<0) return false; int endx = position.x() + width + buildDist; if (endx>BWAPI::Broodwar->mapWidth()) return false; int endy = position.y() + height + buildDist; if (endy>BWAPI::Broodwar->mapHeight()) return false; if (!type.isRefinery()) { for(int x = startx; x < endx; x++) for(int y = starty; y < endy; y++) if (!buildable(x, y) || reserveMap[x][y]) return false; } if (position.x()>3) { int startx2=startx-2; if (startx2<0) startx2=0; for(int x = startx2; x < startx; x++) for(int y = starty; y < endy; y++) { std::set<BWAPI::Unit*> units = BWAPI::Broodwar->getUnitsOnTile(x, y); for(std::set<BWAPI::Unit*>::iterator i = units.begin(); i != units.end(); i++) { if (!(*i)->isLifted()) { BWAPI::UnitType type=(*i)->getType(); if (type==BWAPI::UnitTypes::Terran_Command_Center || type==BWAPI::UnitTypes::Terran_Factory || type==BWAPI::UnitTypes::Terran_Starport || type==BWAPI::UnitTypes::Terran_Science_Facility) { return false; } } } } } return true; }