std::vector<Command> CCommandAI::GetOverlapQueued(const Command& c, CCommandQueue& q) { CCommandQueue::iterator ci = q.end(); std::vector<Command> v; BuildInfo cbi(c); if (ci != q.begin()) { do { --ci; //iterate from the end and dont check the current order const Command& t = *ci; if (t.params.size() != c.params.size()) continue; if (t.GetID() == c.GetID() || (c.GetID() < 0 && t.GetID() < 0)) { if (c.params.size() == 1) { // assume the param is a unit or feature id if (t.params[0] == c.params[0]) { v.push_back(t); } } else if (c.params.size() >= 3) { // assume c and t are positional commands // NOTE: uses a BuildInfo structure, but <t> can be ANY command BuildInfo tbi; if (tbi.Parse(t)) { const float dist2X = 2.0f * math::fabs(cbi.pos.x - tbi.pos.x); const float dist2Z = 2.0f * math::fabs(cbi.pos.z - tbi.pos.z); const float addSizeX = SQUARE_SIZE * (cbi.GetXSize() + tbi.GetXSize()); const float addSizeZ = SQUARE_SIZE * (cbi.GetZSize() + tbi.GetZSize()); const float maxSizeX = SQUARE_SIZE * std::max(cbi.GetXSize(), tbi.GetXSize()); const float maxSizeZ = SQUARE_SIZE * std::max(cbi.GetZSize(), tbi.GetZSize()); if (cbi.def == NULL) continue; if (tbi.def == NULL) continue; if (((dist2X > maxSizeX) || (dist2Z > maxSizeZ)) && ((dist2X < addSizeX) && (dist2Z < addSizeZ))) { v.push_back(t); } } else { if ((cbi.pos - tbi.pos).SqLength2D() >= (COMMAND_CANCEL_DIST * COMMAND_CANCEL_DIST)) continue; if ((c.options & SHIFT_KEY) != 0 && (c.options & INTERNAL_ORDER) != 0) continue; v.push_back(t); } } } } while (ci != q.begin()); } return v; }
std::vector<Command> CCommandAI::GetOverlapQueued(const Command &c, CCommandQueue& q) { CCommandQueue::iterator ci = q.end(); std::vector<Command> v; BuildInfo cbi(c); if (ci != q.begin()){ do { ci--; //iterate from the end and dont check the current order const Command& t = *ci; if (((t.id == c.id) || ((c.id < 0) && (t.id < 0))) && (t.params.size() == c.params.size())){ if (c.params.size()==1) { // assume the param is a unit or feature id if (t.params[0] == c.params[0]) { v.push_back(t); } } else if (c.params.size() >= 3) { // assume this means that the first 3 makes a position BuildInfo tbi; if (tbi.Parse(t)) { const float dist2X = 2.0f * fabs(cbi.pos.x - tbi.pos.x); const float dist2Z = 2.0f * fabs(cbi.pos.z - tbi.pos.z); const float addSizeX = SQUARE_SIZE * (cbi.GetXSize() + tbi.GetXSize()); const float addSizeZ = SQUARE_SIZE * (cbi.GetZSize() + tbi.GetZSize()); const float maxSizeX = SQUARE_SIZE * std::max(cbi.GetXSize(), tbi.GetXSize()); const float maxSizeZ = SQUARE_SIZE * std::max(cbi.GetZSize(), tbi.GetZSize()); if (cbi.def && tbi.def && ((dist2X > maxSizeX) || (dist2Z > maxSizeZ)) && ((dist2X < addSizeX) && (dist2Z < addSizeZ))) { v.push_back(t); } } else { if ((cbi.pos - tbi.pos).SqLength2D() < (17.0f * 17.0f)) { v.push_back(t); } } } } } while (ci != q.begin()); } return v; }
/** * @brief Returns commands that overlap c, but will not be canceled by c * @return a vector containing commands that overlap c */ std::vector<Command> CCommandAI::GetOverlapQueued(Command &c){ std::deque<Command>::iterator ci = commandQue.end(); std::vector<Command> v; BuildInfo buildInfo(c); if(ci != commandQue.begin()){ do{ --ci; //iterate from the end and dont check the current order if((ci->id==c.id || (c.id<0 && ci->id<0)) && ci->params.size()==c.params.size()){ if(c.params.size()==1) //we assume the param is a unit or feature id { if(ci->params[0]==c.params[0]) v.push_back(*ci); } else if(c.params.size()>=3) //we assume this means that the first 3 makes a position { BuildInfo other; if(other.Parse(*ci)){ if(buildInfo.def && other.def && (fabs(buildInfo.pos.x-other.pos.x)*2 > max(buildInfo.GetXSize(), other.GetXSize())*SQUARE_SIZE || fabs(buildInfo.pos.z-other.pos.z)*2 > max(buildInfo.GetYSize(), other.GetYSize())*SQUARE_SIZE) && fabs(buildInfo.pos.x-other.pos.x)*2 < (buildInfo.GetXSize() + other.GetXSize())*SQUARE_SIZE && fabs(buildInfo.pos.z-other.pos.z)*2 < (buildInfo.GetYSize() + other.GetYSize())*SQUARE_SIZE) { v.push_back(*ci); } } else { if((buildInfo.pos-other.pos).SqLength2D()<17*17) v.push_back(*ci); } } } }while(ci!=commandQue.begin()); } return v; }