void msPhysicalInterface::declarePhysicalVariable(double* ptr,double value,const msUnit& unit,string id) { LOGGER_ENTER_FUNCTION_DBG("void msPhysicalInterface::declarePhysicalVariable(double* ptr,double value,const msUnit& unit,string id)", getFullId()); if(id=="") id = "var_"+output::getString<size_t>(PhysicalVariables.size()); *ptr = getUnits()->convert(unit,value); PhysicalVariables[id] = boost::shared_ptr<msPhysicalVariable>(new msPhysicalVariable(id,ptr,unit)); LOGGER_EXIT_FUNCTION2("void msPhysicalInterface::declarePhysicalVariable(double* ptr,double value,const msUnit& unit,string id)"); //PtrOnPhysicalVariables[ptr] = unit; }
boost::shared_ptr<msTreeMapper> msPhysicalInterface::homogenizeUnits() { vector<boost::shared_ptr<msPhysicalInterface> > children = getChildrenDerivedFrom<msPhysicalInterface>("msPhysicalInterface"); vector<boost::shared_ptr<msPhysicalInterface> >::iterator it; for( it = children.begin(); it != children.end();++it){ (*it)->setUnits(getUnits()); } return mySharedPtr(); }
void WeatherPlugin::timeout() { if (!getSocketFactory()->isActive() || m_fetch_id || (*getID() == 0)) return; time_t now; time(&now); if ((unsigned)now < getTime() + CHECK_INTERVAL) return; string url = "http://xoap.weather.com/weather/local/"; url += getID(); url += "?cc=*&prod=xoap&par=1004517364&key=a29796f587f206b2&unit="; url += getUnits() ? "s" : "m"; m_fetch_id = fetch(url.c_str()); }
// passing in a unit type of 0 returns a count of all units size_t UnitInfoManager::getUnitTypeCount(int player, sc2::UnitTypeID type, bool completed) const { size_t count = 0; for (auto & unit : getUnits(player)) { if ((!type || type == unit.unit_type) && (!completed || unit.build_progress == 1.0f)) { count++; } } return count; }
Parameter Parameter::getElementParameter() { Parameter element_parameter; element_parameter.setType(getArrayElementType()); element_parameter.setUnits(getUnits()); if (rangeIsSet()) { element_parameter.setRange(getRangeMin(),getRangeMax()); } if (subsetIsSet()) { element_parameter.setSubset(getSubset()); } return element_parameter; }
ossimProjection* ossimFgdcXmlDoc::getProjection() { if ( m_projection.valid() ) { return m_projection.get(); } ossimDrect rect = getBoundingBox(); ossimString projName (getProjCsn()); if (!projName.empty()) { m_projection = ossimEpsgProjectionFactory::instance()->createProjection(projName); if ( m_projection.valid() ) { ossimDpt gsd(fabs(getXRes()), fabs(getYRes())); ossimMapProjection* mapProj = dynamic_cast<ossimMapProjection*>(m_projection.get()); if (mapProj) { if (mapProj->isGeographic()) { ossimGpt tie(rect.ul().lat, rect.ul().lon); mapProj->setUlTiePoints(tie); mapProj->setDecimalDegreesPerPixel(gsd); } else { ossimDpt tie(rect.ul().x, rect.ul().y); if (getUnits().upcase() == "FEET") { gsd = gsd * METER_PER_FOOT; tie = tie * METER_PER_FOOT; } mapProj->setUlTiePoints(tie); mapProj->setMetersPerPixel(gsd); } } } } return m_projection.get(); }
void WeatherPlugin::timeout() { if (!getSocketFactory()->isActive() || !isDone() || (*getID() == 0)) return; time_t now = time(NULL); if ((unsigned)now < getTime() + CHECK1_INTERVAL) return; m_bForecast = false; if ((unsigned)now >= getForecastTime() + CHECK2_INTERVAL) m_bForecast = true; string url = "http://xoap.weather.com/weather/local/"; url += getID(); url += "?cc=*&prod=xoap&par=1004517364&key=a29796f587f206b2&unit="; url += getUnits() ? "s" : "m"; if (m_bForecast && getForecast()){ url += "&dayf="; url += number(getForecast()); } fetch(url.c_str()); }
void TimelineIndicator::mouseDrag (const MouseEvent& ev) { if (! dragable()) return; Rectangle<int> r (getBoundsInParent()); dragger.dragComponent (this, ev, nullptr); int snap = shouldSnap ? timeline()->pixelSnap (getBoundsInParent().getX()) : getBoundsInParent().getX(); setBounds (r); // reset it back to normal if (snap != lastSnap || ! shouldSnap) { setBounds (snap, 0, 1, timeline()->getHeight()); pos.setValue (getUnits()); lastSnap = snap; } }
void CtrlInfo::show(FILE *f) const { if (getType() == Numeric) { fprintf(f, "CtrlInfo: Numeric\n"); fprintf(f, "Display : %g ... %g\n", getDisplayLow(), getDisplayHigh()); fprintf(f, "Alarm : %g ... %g\n", getLowAlarm(), getHighAlarm()); fprintf(f, "Warning : %g ... %g\n", getLowWarning(), getHighWarning()); fprintf(f, "Prec : %ld '%s'\n", (long)getPrecision(), getUnits()); } else if (getType() == Enumerated) { fprintf(f, "CtrlInfo: Enumerated\n"); fprintf(f, "States:\n"); size_t i, len; for (i=0; i<getNumStates(); ++i) { fprintf(f, "\tstate='%s'\n", getState(i, len)); } } else fprintf(f, "CtrlInfo: Unknown\n"); }
monitoringDataType LH_HWiNFOData::getType() { return getType(getUnits()); }
void DragoonManager::executeMicro(const UnitVector & targets, BWAPI::Position regroup) { const UnitVector & dragoons = getUnits(); // figure out targets UnitVector dragoonTargets; for (size_t i(0); i<targets.size(); i++) { // conditions for targeting if (targets[i]->isVisible()) { dragoonTargets.push_back(targets[i]); } } // for each zealot BOOST_FOREACH(BWAPI::Unit * dragoon, dragoons) { if (DRAW_UALBERTABOT_DEBUG) BWAPI::Broodwar->drawLineMap(dragoon->getPosition().x(), dragoon->getPosition().y(), dragoon->getTargetPosition().x(), dragoon->getTargetPosition().y(), BWAPI::Colors::White); // regroup if we have to regroup and we're not near an enemy if (order.type == order.Attack && regroup != BWAPI::Position(0,0))// && !unitNearEnemy(dragoon)) { if (DRAW_UALBERTABOT_DEBUG) BWAPI::Broodwar->drawCircleMap(dragoon->getPosition().x(), dragoon->getPosition().y(), 3, BWAPI::Colors::Orange, true); // if the zealot is outside the regroup area if (dragoon->getDistance(regroup) > 100) { // regroup it smartMove(dragoon, regroup); } else { smartAttackMove(dragoon, dragoon->getPosition()); } } // otherwise this unit is not regrouping else { // if the order is to attack or defend if (order.type == order.Attack || order.type == order.Defend) { // if there are targets if (!dragoonTargets.empty()) { // find the best target for this zealot BWAPI::Unit * target = getTarget(dragoon, dragoonTargets); // attack it smartAttackUnit(dragoon, target); } // if there are no targets else { // if we're not near the order position if (dragoon->getDistance(order.position) > 100) { // move to it smartAttackMove(dragoon, order.position); } } } } } }
void Parameter::writeApi(Response & response, bool write_name_only, bool is_property, bool write_firmware, bool write_instance_details) { if (response.error()) { return; } const ConstantString & name = getName(); if (write_name_only) { response.write(name); return; } response.beginObject(); response.write(constants::name_constant_string,name); if (write_firmware) { const ConstantString & firmware_name = getFirmwareName(); response.write(constants::firmware_constant_string,firmware_name); } JsonStream::JsonTypes type = getType(); if (write_instance_details) { switch (type) { case JsonStream::LONG_TYPE: { response.write(constants::type_constant_string,JsonStream::LONG_TYPE); if (subsetIsSet()) { response.writeKey(constants::subset_constant_string); response.write(getSubset(),JsonStream::LONG_TYPE); } if (rangeIsSet()) { long min = getRangeMin().l; long max = getRangeMax().l; response.write(constants::min_constant_string,min); response.write(constants::max_constant_string,max); } break; } case JsonStream::DOUBLE_TYPE: { response.write(constants::type_constant_string,JsonStream::DOUBLE_TYPE); if (rangeIsSet()) { double min = getRangeMin().d; double max = getRangeMax().d; response.write(constants::min_constant_string,min); response.write(constants::max_constant_string,max); } break; } case JsonStream::BOOL_TYPE: { response.write(constants::type_constant_string,JsonStream::BOOL_TYPE); break; } case JsonStream::NULL_TYPE: { break; } case JsonStream::STRING_TYPE: { response.write(constants::type_constant_string,JsonStream::STRING_TYPE); if (subsetIsSet()) { response.writeKey(constants::subset_constant_string); response.write(getSubset(),JsonStream::STRING_TYPE); } break; } case JsonStream::OBJECT_TYPE: { response.write(constants::type_constant_string,JsonStream::OBJECT_TYPE); break; } case JsonStream::ARRAY_TYPE: { response.write(constants::type_constant_string,JsonStream::ARRAY_TYPE); JsonStream::JsonTypes array_element_type = getArrayElementType(); switch (array_element_type) { case JsonStream::LONG_TYPE: { response.write(constants::array_element_type_constant_string,JsonStream::LONG_TYPE); if (subsetIsSet()) { response.writeKey(constants::array_element_subset_constant_string); response.write(getSubset(),JsonStream::LONG_TYPE); } if (rangeIsSet()) { long min = getRangeMin().l; long max = getRangeMax().l; response.write(constants::array_element_min_constant_string,min); response.write(constants::array_element_max_constant_string,max); } break; } case JsonStream::DOUBLE_TYPE: { response.write(constants::array_element_type_constant_string,JsonStream::DOUBLE_TYPE); if (rangeIsSet()) { double min = getRangeMin().d; double max = getRangeMax().d; response.write(constants::array_element_min_constant_string,min); response.write(constants::array_element_max_constant_string,max); } break; } case JsonStream::BOOL_TYPE: { response.write(constants::array_element_type_constant_string,JsonStream::BOOL_TYPE); break; } case JsonStream::NULL_TYPE: { break; } case JsonStream::STRING_TYPE: { response.write(constants::array_element_type_constant_string,JsonStream::STRING_TYPE); if (subsetIsSet()) { response.writeKey(constants::array_element_subset_constant_string); response.write(getSubset(),JsonStream::STRING_TYPE); } break; } case JsonStream::OBJECT_TYPE: { response.write(constants::array_element_type_constant_string,JsonStream::OBJECT_TYPE); break; } case JsonStream::ARRAY_TYPE: { response.write(constants::array_element_type_constant_string,JsonStream::ARRAY_TYPE); break; } case JsonStream::ANY_TYPE: { response.write(constants::array_element_type_constant_string,JsonStream::ANY_TYPE); break; } } if (arrayLengthRangeIsSet() && !is_property) { size_t array_length_min = getArrayLengthMin(); size_t array_length_max = getArrayLengthMax(); response.write(constants::array_length_min_constant_string,array_length_min); response.write(constants::array_length_max_constant_string,array_length_max); } break; } case JsonStream::ANY_TYPE: { response.write(constants::type_constant_string,JsonStream::ANY_TYPE); break; } } } else { response.write(constants::type_constant_string,type); if (type == JsonStream::ARRAY_TYPE) { JsonStream::JsonTypes array_element_type = getArrayElementType(); response.write(constants::array_element_type_constant_string,array_element_type); } } if (write_instance_details) { const ConstantString & units = getUnits(); if (units.length() != 0) { response.write(constants::units_constant_string,units); } } if (!is_property) { response.endObject(); } }
void RangedManager::executeMicro(const UnitVector & targets) { const UnitVector & rangedUnits = getUnits(); // figure out targets UnitVector rangedUnitTargets; for (size_t i(0); i<targets.size(); i++) { // conditions for targeting if (targets[i]->isVisible()) { rangedUnitTargets.push_back(targets[i]); } } // for each zealot BOOST_FOREACH(BWAPI::Unit * rangedUnit, rangedUnits) { // train sub units such as scarabs or interceptors //trainSubUnits(rangedUnit); // if the order is to attack or defend if (order.type == order.Attack || order.type == order.Defend || order.type == order.Tanks || order.type == order.Vultures || order.type == order.Goliaths || order.type == order.Marines) { // if there are targets if (!rangedUnitTargets.empty()) { // find the best target for this zealot BWAPI::Unit * target = getTarget(rangedUnit, rangedUnitTargets); // attack it if (!rangedUnit->getType() == BWAPI::UnitTypes::Terran_Siege_Tank_Tank_Mode) { kiteTarget(rangedUnit, target); } else { smartPositionAndDefend(rangedUnit,order.position); } } // if there are no targets else { // if we're not in range of the position if (rangedUnit->getDistance(order.position) > rangedUnit->getInitialType().groundWeapon().maxRange()) { //unsiege tanks if they're sieged if (rangedUnit->getType() == BWAPI::UnitTypes::Terran_Siege_Tank_Siege_Mode) { rangedUnit->unsiege(); } // move to it if (! (order.type == order.Defend)) { smartAttackMove(rangedUnit, order.position); } else { smartPositionAndDefend(rangedUnit,order.position); } } //else if we're in range and we're supposed to s else if (rangedUnit->getType() == BWAPI::UnitTypes::Terran_Siege_Tank_Tank_Mode) { rangedUnit->siege(); } } } if (Options::Debug::DRAW_UALBERTABOT_DEBUG) { BWAPI::Broodwar->drawLineMap(rangedUnit->getPosition().x(), rangedUnit->getPosition().y(), rangedUnit->getTargetPosition().x(), rangedUnit->getTargetPosition().y(), Options::Debug::COLOR_LINE_TARGET); } } }
// Draws a timescale (physical). Note this can fail if the span is short // enough which can happen when we find no events. QString VisWidget::drawTimescale(QPainter * painter, unsigned long long start, unsigned long long span, int margin) { // Draw the scale bar int lineHeight = rect().height() - (timescaleHeight - 1); painter->setPen(QPen(Qt::black, 1, Qt::SolidLine)); painter->drawLine(margin, lineHeight, rect().width() - margin, lineHeight); if (!visProcessed) return ""; painter->setFont(QFont("Helvetica", 10)); QFontMetrics font_metrics = this->fontMetrics(); // Figure out the units and number of ticks ( may handle units later ) QLocale systemlocale = QLocale::system(); QString text = systemlocale.toString(start); int textWidth = font_metrics.width(text) * 1.4; // We can't have more than this and fit text int max_ticks = floor((rect().width() - 2*margin) / 1.0 / textWidth); int y = lineHeight + timescaleTickHeight + font_metrics.xHeight() + 4; // We want a round number unsigned long long tick_span = span / max_ticks; // Not round int power = floor(log10(tick_span)); // How many zeros unsigned long long roundfactor = std::max(1.0, pow(10, power)); tick_span = (tick_span / roundfactor) * roundfactor; // Now round if (tick_span < 1) tick_span = 1; // Now we must find the first number after startTime divisible by // the tick_span. We don't want to just find the same roundness // because then panning doesn't work. unsigned long long tick = (tick_span - start % tick_span) + start; // TODO: MAKE THIS PART OPTIONAL QString seconds = getUnits(trace->units); int tick_divisor = 1; unsigned long long tick_base = 0; if (!options->absoluteTime) { tick_base = tick - tick_span; int span_unit = (int) floor(log10(tick_span)); tick_divisor = pow(3 * floor(span_unit / 3), 10); if (!tick_divisor) tick_divisor = 1; seconds = systemlocale.toString(tick_base / pow((double) trace->units, 10), 'f', trace->units - span_unit) + "s + " + getUnits(trace->units - 3 * floor(span_unit / 3)) + ":"; } // And now we draw while (tick < start + span) { int x = margin + round((tick - start) / 1.0 / span * (rect().width() - 2*margin)); painter->drawLine(x, lineHeight, x, lineHeight + timescaleTickHeight); text = systemlocale.toString((tick - tick_base) / tick_divisor); textWidth = font_metrics.width(text) / 3; painter->drawText(x - textWidth, y, text); tick += tick_span; } return seconds; }
bool ossimAuxXmlSupportData::initializeProjection( const ossimXmlDocument xdoc, const std::string& wkt, ossimProjection* proj ) const { bool result = false; ossimRefPtr<ossimMapProjection> mapProj = dynamic_cast<ossimMapProjection*>( proj ); if ( mapProj.valid() ) { // Find the tie and scale. ossimString path = "/PAMDataset/Metadata/MDI"; std::vector<ossimRefPtr<ossimXmlNode> > xnodes; xdoc.findNodes(path, xnodes); if ( xnodes.size() ) { ossimDpt tie; ossimDpt scale; tie.makeNan(); scale.makeNan(); for ( ossim_uint32 i = 0; i < xnodes.size(); ++i ) { if ( xnodes[i].valid() ) { ossimString value; ossimString attrName = "key"; ossimRefPtr<ossimXmlAttribute> attr = xnodes[i]->findAttribute( attrName ); if ( attr.valid() ) { if (attr->getValue() == "IMAGE__XY_ORIGIN" ) { value = xnodes[i]->getText(); if ( value.size() ) { // Split it: std::vector<ossimString> list; value.split( list, ossimString(","), true ); if ( list.size() == 2 ) { if ( list[0].size() ) { tie.x = list[0].toFloat64(); } if ( list[1].size() ) { tie.y = list[1].toFloat64(); } } } } else if (attr->getValue() == "IMAGE__X_RESOLUTION" ) { value = xnodes[i]->getText(); if ( value.size() ) { scale.x = value.toFloat64(); } } else if (attr->getValue() == "IMAGE__Y_RESOLUTION" ) { value = xnodes[i]->getText(); if ( value.size() ) { scale.y = value.toFloat64(); } } } } // Matches: if ( xnodes[i].valid() ) } // Matches: for ( ossim_uint32 i = 0; i < xnodes.size(); ++i ) if ( !tie.hasNans() && !scale.hasNans() ) { if ( mapProj->isGeographic() ) { // Assuming tie and scale in decimal degrees: mapProj->setDecimalDegreesPerPixel( scale ); ossimGpt gpt(tie.y, tie.x, 0.0); mapProj->setUlTiePoints( ossimGpt( gpt ) ); result = true; } else { // Get the units: ossimUnitType units = getUnits( wkt ); // Convert to meters: result = true; if ( units != OSSIM_METERS ) { if ( units == OSSIM_FEET ) { tie.x = tie.x * MTRS_PER_FT; tie.y = tie.y * MTRS_PER_FT; scale.x = scale.x * MTRS_PER_FT; scale.y = scale.y * MTRS_PER_FT; } else if ( units == OSSIM_US_SURVEY_FEET) { tie.x = tie.x * US_METERS_PER_FT; tie.y = tie.y * US_METERS_PER_FT; scale.x = scale.x * OSSIM_US_SURVEY_FEET; scale.y = scale.y * OSSIM_US_SURVEY_FEET; } else { ossimNotify(ossimNotifyLevel_WARN) << "ossimAuxXmlSupportData::initializeProjection WARNING: " << "Unhandled unit type: " << units << std::endl; result = false; } } if ( result ) { mapProj->setMetersPerPixel( scale ); mapProj->setUlTiePoints( tie ); } } } } // Matches: if ( xnodes.size() ) } return result; } // ossimAuxXmlSupportData::initializeProjection
void RangedManager::executeMicro(const UnitVector & targets) { const UnitVector & rangedUnits = getUnits(); // figure out targets UnitVector rangedUnitTargets; for (size_t i(0); i<targets.size(); i++) { // conditions for targeting if (targets[i]->isVisible()) { rangedUnitTargets.push_back(targets[i]); } } // for each zealot BOOST_FOREACH(BWAPI::Unit * rangedUnit, rangedUnits) { // train sub units such as scarabs or interceptors //trainSubUnits(rangedUnit); // if the order is to attack or defend if (order.type == order.Attack || order.type == order.Defend) { // if there are targets if (!rangedUnitTargets.empty()) { // find the best target for this zealot BWAPI::Unit * target = getTarget(rangedUnit, rangedUnitTargets); /* if ( rangedUnit->getType().groundWeapon().maxRange() < target->getDistance(rangedUnit)) { if(rangedUnit->getType() == BWAPI::UnitTypes::Zerg_Lurker) { //BWAPI::Broodwar->printf("############# Lurker in distance: %d ###############", rangedUnit->getID()); LurkerBurrow(rangedUnit); } } */ // attack it kiteTarget(rangedUnit, target); } // if there are no targets else { // if we're not near the order position if (rangedUnit->getDistance(order.position) > 100) { // move to it smartAttackMove(rangedUnit, order.position); } } } if (Options::Debug::DRAW_UALBERTABOT_DEBUG) { BWAPI::Broodwar->drawLineMap(rangedUnit->getPosition().x(), rangedUnit->getPosition().y(), rangedUnit->getTargetPosition().x(), rangedUnit->getTargetPosition().y(), Options::Debug::COLOR_LINE_TARGET); } } }
bool CUnitValidator::validate() { mVariableUnits = mProvidedVariableUnits; if (mTree.getType() == CEvaluationTree::MassAction) { std::vector< CValidatedUnit >::iterator it = mVariableUnits.begin(); std::vector< CValidatedUnit >::iterator end = mVariableUnits.end(); CValidatedUnit & k1 = *it++; k1 = mTargetUnit; for (; it != end && !(*it == CBaseUnit::undefined); ++it) { it->buildExpression(); k1 = k1 * it->exponentiate(-1.0); } k1.buildExpression(); if (it == end) return k1.conflict(); CValidatedUnit & k2 = *it++; k2 = mTargetUnit; for (; it != end; ++it) { it->buildExpression(); k2 = k2 * it->exponentiate(-1.0); } k2.buildExpression(); if (it == end) return k1.conflict() || k2.conflict(); } CVector< C_FLOAT64 > CurrentValues; if (mApplyIntitialValue) { CurrentValues = mMathContainer.getValues(); mMathContainer.applyInitialValues(); } mObjectUnits.clear(); mNodeUnits.clear(); do { getUnits(); } while (setUnits()); bool conflict = false; std::map < CEvaluationNode * , CValidatedUnit >::const_iterator itMap = mNodeUnits.begin(); std::map < CEvaluationNode * , CValidatedUnit >::const_iterator endMap = mNodeUnits.end(); for (; itMap != endMap && !conflict; ++itMap) if (itMap->second.conflict()) { conflict = true; } std::map < CObjectInterface *, CValidatedUnit >::iterator itObject = mObjectUnits.begin(); std::map < CObjectInterface *, CValidatedUnit >::iterator endObject = mObjectUnits.end(); for (; itObject != endObject; ++itObject) { itObject->second.buildExpression(); if (itObject->second.conflict()) { conflict = true; } } std::vector< CValidatedUnit >::iterator it = mVariableUnits.begin(); std::vector< CValidatedUnit >::iterator end = mVariableUnits.end(); for (; it != end; ++it) { it->buildExpression(); if (it->conflict()) { conflict = true; } } std::map < CEvaluationNode * , CValidatedUnit >::iterator found = mNodeUnits.find(const_cast< CEvaluationNode * >(mTree.getRoot())); if (found != mNodeUnits.end()) { found->second.setConflict(conflict); } if (mApplyIntitialValue) { mMathContainer.setValues(CurrentValues); } return !conflict; }
void msPhysicalInterface::setUnits(boost::shared_ptr<msUnitsManager> units){ LOGGER_ENTER_FUNCTION_DBG("void msPhysicalInterface::setUnits(boost::shared_ptr<msUnitsManager> units)", getFullId()); msUnitsManager old; old.set( Units->getExpression() ); msTreeMapper::update<msUnitsManager>( Units , units); units->addObjectUsingMe( boost::static_pointer_cast<msPhysicalInterface>( mySharedPtr() ) ); LOGGER_WRITE(msLogger::DEBUG, "Number of objects using the units: " + output::getString<size_t>(getUnits()->LinkedObjects.size())); updateUnits(old,*units); LOGGER_EXIT_FUNCTION2("void msPhysicalInterface::setUnits(boost::shared_ptr<msUnitsManager> units)"); }
std::string Inversion::toString() const { return getUnits().second + " to " + getUnits().first + " converter"; }
void WraithManagerExt::executeMicro(const UnitVector & targets) { const UnitVector & selectedUnits = getUnits(); _noTurretTargetsNo = 0; // figure out targets UnitVector selectedUnitTargets; for (size_t i(0); i<targets.size(); i++) { // conditions for targeting if (targets[i]->isVisible()) { selectedUnitTargets.push_back(targets[i]); if (!isTurret(targets[i])) { _noTurretTargetsNo++; } } } setAverageEnemyPosition(selectedUnitTargets); // For each unit BOOST_FOREACH(BWAPI::Unit * selectedUnit, selectedUnits) { // Adjust cloak to the situation manageCloak(selectedUnit, selectedUnitTargets); // if the order is to attack or defend if (order.type == order.Attack || order.type == order.Defend) { // if there are targets if (!selectedUnitTargets.empty()) { // find the best target for this unit BWAPI::Unit * target = getTarget(selectedUnit, selectedUnitTargets); // attack it kiteTarget(selectedUnit, target); } // if there are no targets else { // if we're not near the order position if (selectedUnit->getDistance(order.position) > 100) { // move to it // Border movement BWAPI::Position movePosition; if (order.type == SquadOrder::Attack && (StrategyManager::Instance().getCurrentStrategy() == StrategyManager::Instance().TerranWraithRush1Port)) { movePosition = UnitManagerExt::Instance().getMovePosition(selectedUnit); } else { movePosition = order.position; } // eof Border movement if (!movePosition.isValid()) { movePosition.makeValid(); } smartAttackMove(selectedUnit, movePosition); } } } if (Options::Debug::DRAW_UALBERTABOT_DEBUG) { BWAPI::Broodwar->drawLineMap(selectedUnit->getPosition().x(), selectedUnit->getPosition().y(), selectedUnit->getTargetPosition().x(), selectedUnit->getTargetPosition().y(), Options::Debug::COLOR_LINE_TARGET); } }
int ocs_build_answer(AAAMessage *ccr, AAAMessage *cca, int result_code, int granted_units, int final_unit) { AAA_AVP *avp; AAA_AVP_LIST granted_list, mscc_list, final_list; char x[4]; str granted_group, mscc_group, final_group; int service, group, used; if (!ccr) return 0; if (!cca) return 0; // Set some basic data: Application-ID, CCR-Type, CCR-Request-Number set_4bytes(x, IMS_Ro); ocs_add_avp(cca, x, 4, AVP_Acct_Application_Id, AAA_AVP_FLAG_MANDATORY, 0, AVP_DUPLICATE_DATA, __FUNCTION__); avp = cdpb.AAAFindMatchingAVP(ccr,0,AVP_IMS_CCR_Type,0,0); ocs_add_avp(cca, avp->data.s, avp->data.len, AVP_IMS_CCR_Type, AAA_AVP_FLAG_MANDATORY, 0, AVP_DUPLICATE_DATA, __FUNCTION__); avp = cdpb.AAAFindMatchingAVP(ccr,0,AVP_CC_Request_Number,0,0); ocs_add_avp(cca, avp->data.s, avp->data.len,AVP_CC_Request_Number, AAA_AVP_FLAG_MANDATORY, 0, AVP_DUPLICATE_DATA, __FUNCTION__); // Result-Code: set_4bytes(x, result_code); ocs_add_avp(cca, x, 4, AVP_Result_Code, AAA_AVP_FLAG_MANDATORY, 0, AVP_DUPLICATE_DATA, __FUNCTION__); if (result_code == DIAMETER_SUCCESS) { granted_list.head = 0; granted_list.tail = 0; final_list.head = 0; final_list.tail = 0; mscc_list.head = 0; mscc_list.tail = 0; getUnits(ccr, &used, &service, &group); set_4bytes(x, group); ocs_add_avp_list(&mscc_list, x, 4, AVP_Rating_Group, AAA_AVP_FLAG_MANDATORY, 0, AVP_DUPLICATE_DATA, __FUNCTION__); set_4bytes(x, service); ocs_add_avp_list(&mscc_list, x, 4, AVP_Service_Identifier, AAA_AVP_FLAG_MANDATORY, 0, AVP_DUPLICATE_DATA, __FUNCTION__); if (granted_units > 0) { set_4bytes(x, granted_units); ocs_add_avp_list(&granted_list, x, 4, AVP_CC_Time, AAA_AVP_FLAG_MANDATORY, 0, AVP_DUPLICATE_DATA, __FUNCTION__); granted_group = cdpb.AAAGroupAVPS(granted_list); cdpb.AAAFreeAVPList(&granted_list); ocs_add_avp_list(&mscc_list, granted_group.s, granted_group.len, AVP_Granted_Service_Unit, AAA_AVP_FLAG_MANDATORY, 0, AVP_FREE_DATA, __FUNCTION__); } // Result-Code: set_4bytes(x, result_code); ocs_add_avp_list(&mscc_list, x, 4, AVP_Result_Code, AAA_AVP_FLAG_MANDATORY, 0, AVP_DUPLICATE_DATA, __FUNCTION__); set_4bytes(x, 86400); ocs_add_avp_list(&mscc_list, x, 4, AVP_Validity_Time, AAA_AVP_FLAG_MANDATORY, 0, AVP_DUPLICATE_DATA, __FUNCTION__); if (final_unit > 0) { set_4bytes(x, 0); ocs_add_avp_list(&final_list, x, 4, AVP_Final_Unit_Action, AAA_AVP_FLAG_MANDATORY, 0, AVP_DUPLICATE_DATA, __FUNCTION__); final_group = cdpb.AAAGroupAVPS(final_list); cdpb.AAAFreeAVPList(&final_list); ocs_add_avp_list(&mscc_list, final_group.s, final_group.len, AVP_Final_Unit_Indication, AAA_AVP_FLAG_MANDATORY, 0, AVP_FREE_DATA, __FUNCTION__); } mscc_group = cdpb.AAAGroupAVPS(mscc_list); cdpb.AAAFreeAVPList(&mscc_list); return ocs_add_avp(cca, mscc_group.s, mscc_group.len, AVP_Multiple_Services_Credit_Control, AAA_AVP_FLAG_MANDATORY, 0, AVP_FREE_DATA, __FUNCTION__); } return 1; }
void VultureManagerExt::executeMicro(const UnitVector & targets) { const UnitVector & selectedUnits = getUnits(); // figure out targets UnitVector selectedUnitTargets; UnitVector nearbyTargets; for (size_t i(0); i<targets.size(); i++) { // conditions for targeting if (targets[i]->isVisible() && !targets[i]->getType().isFlyer()) { selectedUnitTargets.push_back(targets[i]); } } //setAverageEnemyPosition(selectedUnitTargets); // For each unit BOOST_FOREACH(BWAPI::Unit * selectedUnit, selectedUnits) { // Avg enemy pos for (size_t i(0); i<targets.size(); i++) { // conditions for targeting if (targets[i]->isVisible() && !targets[i]->getType().isFlyer()) { if (targets[i]->getDistance(selectedUnit) < 500) { nearbyTargets.push_back(targets[i]); } } } if (!nearbyTargets.empty()) { setAverageEnemyPosition(nearbyTargets); } else { setAverageEnemyPosition(selectedUnitTargets); } // eof avg eveeny pos // if the order is to attack or defend if ((StrategyManager::Instance().getCurrentStrategy() == StrategyManager::Instance().TerranWraithRush1Port) && !isAttack()) { executeTerranWraithRush1Port(selectedUnit, selectedUnitTargets); } else if (order.type == order.Attack || order.type == order.Defend) { // if there are targets if (!selectedUnitTargets.empty()) { // find the best target for this Marine BWAPI::Unit * target = getTarget(selectedUnit, selectedUnitTargets); // attack it kiteTarget(selectedUnit, target); } // if there are no targets else { // if we're not near the order position if (selectedUnit->getDistance(order.position) > 100) { // move to it smartAttackMove(selectedUnit, order.position); } } } if (Options::Debug::DRAW_UALBERTABOT_DEBUG) { BWAPI::Broodwar->drawLineMap(selectedUnit->getPosition().x(), selectedUnit->getPosition().y(), selectedUnit->getTargetPosition().x(), selectedUnit->getTargetPosition().y(), Options::Debug::COLOR_LINE_TARGET); } } }