vector<RotatedRect> CControl::GetRotatedRect(Point2i n_ptcenter) { float n_degreestep; if(nControlOptions.nAngelCout<10) n_degreestep=180/nControlOptions.nAngelCout; else n_degreestep=360/nControlOptions.nAngelCout; vector<RotatedRect> n_rotatedrectvct; for(int i=0;i<nControlOptions.nAngelCout;i++) { float n_degree=i*n_degreestep; RotatedRect n_rotatedrect(Point2f(n_ptcenter.x,n_ptcenter.y),Size2f(nControlOptions.nWidth,nControlOptions.nHeight),n_degree); //检查角点 Point2f n_vertices[4]; n_rotatedrect.points(n_vertices); bool n_inside=true; for(int j=0;j<4;j++) if(!CheckBoundary(n_vertices[j])) n_inside=false; //检查外包矩形是否在图像内(旋转需要) Rect n_boundrect=n_rotatedrect.boundingRect(); Point2f n_pttl=n_boundrect.tl(); Point2f n_ptbr=n_boundrect.br(); if(!CheckBoundary(n_pttl)||!CheckBoundary(n_ptbr)) n_inside=false; if(!n_inside) continue; n_rotatedrectvct.push_back(n_rotatedrect); } return n_rotatedrectvct; }
vector<RotatedRect> CControl::GetRotatedRect(Point2i n_ptcenter,vector<float> n_anglevct) { vector<RotatedRect> n_rotatedrectvct; for(int i=0;i<n_anglevct.size();i++) { float n_degree=n_anglevct.at(i); RotatedRect n_rotatedrect(Point2f(n_ptcenter.x,n_ptcenter.y),Size2f(nControlOptions.nWidth,nControlOptions.nHeight),n_degree); //检查角点 Point2f n_vertices[4]; n_rotatedrect.points(n_vertices); bool n_inside=true; for(int j=0;j<4;j++) if(!CheckBoundary(n_vertices[j])) n_inside=false; /* //检查外包矩形是否在图像内(旋转需要) Rect n_boundrect=n_rotatedrect.boundingRect(); Point2f n_pttl=n_boundrect.tl(); Point2f n_ptbr=n_boundrect.br(); if(!CheckBoundary(n_pttl)||!CheckBoundary(n_ptbr)) n_inside=false; */ if(!n_inside) continue; n_rotatedrectvct.push_back(n_rotatedrect); } return n_rotatedrectvct; }
void BossAI::TeleportCheaters() { float x, y, z; me->GetPosition(x, y, z); std::list<HostileReference*> &m_threatlist = me->getThreatManager().getThreatList(); for (std::list<HostileReference*>::iterator itr = m_threatlist.begin(); itr != m_threatlist.end(); ++itr) if ((*itr)->getTarget()->GetTypeId() == TYPEID_PLAYER && !CheckBoundary((*itr)->getTarget())) (*itr)->getTarget()->NearTeleportTo(x, y, z, 0); }
bool CreatureAI::CheckInRoom() { if (CheckBoundary()) return true; else { EnterEvadeMode(EVADE_REASON_BOUNDARY); return false; } }
void BossAI::TeleportCheaters() { float x, y, z; me->GetPosition(x, y, z); ThreatContainer::StorageType threatList = me->getThreatManager().getThreatList(); for (ThreatContainer::StorageType::const_iterator itr = threatList.begin(); itr != threatList.end(); ++itr) if (Unit* target = (*itr)->getTarget()) if (target->GetTypeId() == TYPEID_PLAYER && !CheckBoundary(target)) target->NearTeleportTo(x, y, z, 0); }
void BossAI::TeleportCheaters() { float x, y, z; me->GetPosition(x, y, z); for (auto const& pair : me->GetCombatManager().GetPvECombatRefs()) { Unit* target = pair.second->GetOther(me); if (target->IsControlledByPlayer() && !CheckBoundary(target)) target->NearTeleportTo(x, y, z, 0); } }
bool BossBloodPrinceValanarAI::CheckRoom() { if (!CheckBoundary(me)) { EnterEvadeMode(); if (Creature* keleseth = ObjectAccessor::GetCreature(*me, instance->GetData64(DATA_PRINCE_KELESETH_GUID))) keleseth->AI()->EnterEvadeMode(); if (Creature* taldaram = ObjectAccessor::GetCreature(*me, instance->GetData64(DATA_PRINCE_TALDARAM_GUID))) taldaram->AI()->EnterEvadeMode(); return false; } return true; }
int32 CreatureAI::VisualizeBoundary(uint32 duration, Unit* owner, bool fill) const { typedef std::pair<int32, int32> coordinate; if (!owner) return -1; if (!_boundary || _boundary->empty()) return LANG_CREATURE_MOVEMENT_NOT_BOUNDED; std::queue<coordinate> Q; std::unordered_set<coordinate> alreadyChecked; std::unordered_set<coordinate> outOfBounds; Position startPosition = owner->GetPosition(); if (!CheckBoundary(&startPosition)) // fall back to creature position { startPosition = me->GetPosition(); if (!CheckBoundary(&startPosition)) { startPosition = me->GetHomePosition(); if (!CheckBoundary(&startPosition)) // fall back to creature home position return LANG_CREATURE_NO_INTERIOR_POINT_FOUND; } } float spawnZ = startPosition.GetPositionZ() + BOUNDARY_VISUALIZE_SPAWN_HEIGHT; bool boundsWarning = false; Q.push({ 0,0 }); while (!Q.empty()) { coordinate front = Q.front(); bool hasOutOfBoundsNeighbor = false; for (coordinate off : std::initializer_list<coordinate>{{1,0}, {0,1}, {-1,0}, {0,-1}}) { coordinate next(front.first + off.first, front.second + off.second); if (next.first > BOUNDARY_VISUALIZE_FAILSAFE_LIMIT || next.first < -BOUNDARY_VISUALIZE_FAILSAFE_LIMIT || next.second > BOUNDARY_VISUALIZE_FAILSAFE_LIMIT || next.second < -BOUNDARY_VISUALIZE_FAILSAFE_LIMIT) { boundsWarning = true; continue; } if (alreadyChecked.find(next) == alreadyChecked.end()) // never check a coordinate twice { Position nextPos(startPosition.GetPositionX() + next.first*BOUNDARY_VISUALIZE_STEP_SIZE, startPosition.GetPositionY() + next.second*BOUNDARY_VISUALIZE_STEP_SIZE, startPosition.GetPositionZ()); if (CheckBoundary(&nextPos)) Q.push(next); else { outOfBounds.insert(next); hasOutOfBoundsNeighbor = true; } alreadyChecked.insert(next); } else if (outOfBounds.find(next) != outOfBounds.end()) hasOutOfBoundsNeighbor = true; } if (fill || hasOutOfBoundsNeighbor) if (TempSummon* point = owner->SummonCreature(BOUNDARY_VISUALIZE_CREATURE, Position(startPosition.GetPositionX() + front.first*BOUNDARY_VISUALIZE_STEP_SIZE, startPosition.GetPositionY() + front.second*BOUNDARY_VISUALIZE_STEP_SIZE, spawnZ), TEMPSUMMON_TIMED_DESPAWN, duration * IN_MILLISECONDS)) { point->SetObjectScale(BOUNDARY_VISUALIZE_CREATURE_SCALE); point->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PC | UNIT_FLAG_STUNNED | UNIT_FLAG_IMMUNE_TO_NPC); if (!hasOutOfBoundsNeighbor) point->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); } Q.pop(); } return boundsWarning ? LANG_CREATURE_MOVEMENT_MAYBE_UNBOUNDED : 0; }
bool BossAI::CanAIAttack(Unit const* target) const { return CheckBoundary(target); }
void DestroyLoop::Check(int dirX, int dirY) { sf::Color color; int matches; // Count of consecutive colors // The possible matches std::list<std::list<Block>::iterator*> possibleMatches; // From left to right to bottom for (int j = 0; j < mMatrix[0].size() ; j ++) { for (int i = 0 ; i < mMatrix.size(); i ++) { if (!mMatrix[i][j]) continue; // NULL pointer, empty cell. possibleMatches.clear(); color = (**mMatrix[i][j]).GetColor(); // Itself possibleMatches.push_back(mMatrix[i][j]); matches = 1; int ii = i+dirX; int jj = j+dirY; // Check for consecutive matching colors in the desired direction while (CheckBoundary(ii, jj) && (mMatrix[ii][jj]) // check for not-NULL iterator && (**mMatrix[ii][jj]).GetColor() == color) { possibleMatches.push_back(mMatrix[ii][jj]); ++ matches; ii += dirX; jj += dirY; } if (matches >= NMATCH) { // Append the new matches, only if it doesn't exists already std::list<std::list<Block>::iterator*>::iterator it; for (std::list<std::list<Block>::iterator*>::iterator ii = possibleMatches.begin(); ii != possibleMatches.end() ; ii++) { it = mList.begin(); // Search if already exists while (*it != *ii && it != mList.end()) ++ it; // If not found if (it == mList.end()) { // Add it mList.push_back(*ii); } } } } } // Play the animation sound if required if (!mList.empty()) mBoard->PlayAnimSound(); }
int lua_field_spots(lua_State *L) { std::vector<RegionProps> props; uint8_t *im_ptr = (uint8_t *) lua_touserdata(L, 1); if ((im_ptr == NULL) || !lua_islightuserdata(L, 1)) { return luaL_error(L, "Input image not light user data"); } int m = luaL_checkint(L, 2); int n = luaL_checkint(L, 3); int nlabel = ConnectRegions(props, im_ptr, m, n, colorSpot); if (nlabel <= 0) { return 0; } std::vector<int> valid; for (int i = 0; i < nlabel; i++) { if (CheckBoundary(props[i], im_ptr, m, n, colorField)) { valid.push_back(i); } } int nvalid = valid.size(); if (nvalid < 1) { return 0; } lua_createtable(L, nvalid, 0); for (int i = 0; i < nvalid; i++) { lua_createtable(L, 0, 3); // area field lua_pushstring(L, "area"); lua_pushnumber(L, props[valid[i]].area); lua_settable(L, -3); // centroid field lua_pushstring(L, "centroid"); double centroidI = (double)props[valid[i]].sumI/props[valid[i]].area; double centroidJ = (double)props[valid[i]].sumJ/props[valid[i]].area; lua_createtable(L, 2, 0); lua_pushnumber(L, centroidI); lua_rawseti(L, -2, 1); lua_pushnumber(L, centroidJ); lua_rawseti(L, -2, 2); lua_settable(L, -3); // boundingBox field lua_pushstring(L, "boundingBox"); lua_createtable(L, 4, 0); lua_pushnumber(L, props[valid[i]].minI); lua_rawseti(L, -2, 1); lua_pushnumber(L, props[valid[i]].maxI); lua_rawseti(L, -2, 2); lua_pushnumber(L, props[valid[i]].minJ); lua_rawseti(L, -2, 3); lua_pushnumber(L, props[valid[i]].maxJ); lua_rawseti(L, -2, 4); lua_settable(L, -3); lua_rawseti(L, -2, i+1); } return 1; }