int CGXDLMSObject::SetDataType(int index, DLMS_DATA_TYPE type) { for(CGXAttributeCollection::iterator it = m_Attributes.begin(); it != m_Attributes.end(); ++it) { if ((*it).GetIndex() == index) { (*it).SetDataType(type); return ERROR_CODES_OK; } } CGXDLMSAttribute att(index); att.SetDataType(type); m_Attributes.push_back(att); return ERROR_CODES_OK; }
/****************************************************************************** * Called when the radio button states have been changed. * Updates the appropriate edit box. */ void AlarmTimeWidget::slotButtonSet(QAbstractButton*) { bool at = mAtTimeRadio->isChecked(); mDateEdit->setEnabled(at); mTimeEdit->setEnabled(at && (!mAnyTimeAllowed || !mAnyTimeCheckBox || !mAnyTimeCheckBox->isChecked())); if (mAnyTimeCheckBox) mAnyTimeCheckBox->setEnabled(at && mAnyTimeAllowed); // Ensure that the value of the delay edit box is > 0. KDateTime att(mDateEdit->date(), mTimeEdit->time(), mTimeSpec); int minutes = (KDateTime::currentUtcDateTime().secsTo(att) + 59) / 60; if (minutes <= 0) mDelayTimeEdit->setValid(true); mDelayTimeEdit->setEnabled(!at); setAnyTime(); }
EXPORT_C void CPartContainerXml::HandleAttributesL(const XML_Char *name, const XML_Char **atts) { TUint part; const XML_Char** ap=&atts[0]; while ( *ap && *(ap+1)) { TPtrC att((const TUint16*)*ap), val((const TUint16*)*(ap+1)); if (att.Compare(KAttModule) && att.Compare(KAttId) && att.Compare(KAttMajorVersion) && att.Compare(KAttMinorVersion)) { MBBData *p=iCompoundValue.GetPart(att, KNoType, part); if (p) p->FromStringL(val); } ap+=2; } }
GLight::operator Any() const { Any a(Any::TABLE, "GLight"); a.set("position", position.operator Any()); a.set("rightDirection", rightDirection.operator Any()); a.set("spotDirection", spotDirection.operator Any()); a.set("spotCutoff", spotCutoff); a.set("spotSquare", spotSquare); Any att(Any::ARRAY); att.append(attenuation[0], attenuation[1], attenuation[2]); a.set("attenuation", att); a.set("color", color.operator Any()); a.set("enabled", enabled); a.set("specular", specular); a.set("diffuse", diffuse); return a; }
void MergeAbbrev::writeAbbrev( MergeFile * outFile ) //-------------------------------------------------- { int i; outFile->writeULEB128( _code ); outFile->writeULEB128( _tag ); outFile->writeByte( _children ); for( i = 0; i < _attribs->entries(); i += 1 ) { MergeAttrib& att( (*_attribs)[ i ] ); outFile->writeULEB128( att.attrib() ); outFile->writeULEB128( att.form() ); } outFile->writeULEB128( 0 ); // zero attrib / zero form marks end of abbrev outFile->writeULEB128( 0 ); }
TEST(MEKFGyroAccMagTestGroup, vect_measurement_jacobian) { Eigen::Quaternionf att(Eigen::AngleAxisf(M_PI/2, Eigen::Vector3f::UnitZ())); Eigen::Vector3f v_i(0, 1, 0); // expectation of v in inertial frame // expectation of v is along [0,1,0] in inertial and [1,0,0] in body frame, // because the body frame is oriented +90deg yaw k.reset(att); Eigen::Vector3f v_b = att.conjugate()._transformVector(v_i); // [1,0,0] Eigen::Matrix3f b_to_m = k.vect_measurement_basis_b_frame(v_i); //std::cout << std::endl << v_b << std::endl; Eigen::Matrix<float, 2, 3> Ha = MEKFGyroAccMag::vect_measurement_jacobian(b_to_m, v_b); Eigen::Matrix<float, 2, 3> Ha_exp; // sensitivity of z (= last 2 components of v_m) with respect to a: // with respect to a1 (=roll right) = [0, 0]' (v_b is [1, 0, 0], along roll axis) // with respect to a2 (=pitch up) = [0, 1]' (v_b goes down (positive)) // with respect to a3 (=yaw right) = [-1, 0]' (v_b goes left (negative)) Ha_exp << 0, 0, -1, 0, 1, 0; //std::cout << std::endl << Ha << std::endl; CHECK_TRUE(Ha.isApprox(Ha_exp)); }
// [[Rcpp::export]] Rcpp::List ukf_nlg(const arma::mat& y, SEXP Z, SEXP H, SEXP T, SEXP R, SEXP Zg, SEXP Tg, SEXP a1, SEXP P1, const arma::vec& theta, SEXP log_prior_pdf, const arma::vec& known_params, const arma::mat& known_tv_params, const unsigned int n_states, const unsigned int n_etas, const arma::uvec& time_varying, const double alpha, const double beta, const double kappa) { Rcpp::XPtr<nvec_fnPtr> xpfun_Z(Z); Rcpp::XPtr<nmat_fnPtr> xpfun_H(H); Rcpp::XPtr<nvec_fnPtr> xpfun_T(T); Rcpp::XPtr<nmat_fnPtr> xpfun_R(R); Rcpp::XPtr<nmat_fnPtr> xpfun_Zg(Zg); Rcpp::XPtr<nmat_fnPtr> xpfun_Tg(Tg); Rcpp::XPtr<a1_fnPtr> xpfun_a1(a1); Rcpp::XPtr<P1_fnPtr> xpfun_P1(P1); Rcpp::XPtr<prior_fnPtr> xpfun_prior(log_prior_pdf); nlg_ssm model(y, *xpfun_Z, *xpfun_H, *xpfun_T, *xpfun_R, *xpfun_Zg, *xpfun_Tg, *xpfun_a1, *xpfun_P1, theta, *xpfun_prior, known_params, known_tv_params, n_states, n_etas, time_varying, 1); arma::mat at(model.m, model.n + 1); arma::mat att(model.m, model.n); arma::cube Pt(model.m, model.m, model.n + 1); arma::cube Ptt(model.m, model.m, model.n); double logLik = model.ukf(at, att, Pt, Ptt, alpha, beta, kappa); arma::inplace_trans(at); arma::inplace_trans(att); return Rcpp::List::create( Rcpp::Named("at") = at, Rcpp::Named("att") = att, Rcpp::Named("Pt") = Pt, Rcpp::Named("Ptt") = Ptt, Rcpp::Named("logLik") = logLik); }
//#define DEBUG blobtype best_blob(double alpha_0, double alpha_F, double inc_alpha, double a_0, double a_F, double inc_a, double w, double *target_att, int target_length) { blobtype retval; retval.order = 2; int alpha_size = FLOOR((alpha_F - alpha_0) / inc_alpha + 1); int a_size = FLOOR((a_F - a_0) / inc_a + 1); Image<double> att, ops; att().resize(alpha_size, a_size); ops().resize(alpha_size, a_size); int i, j; double a, alpha, best_a = -1, best_alpha = -1; double best_ops = 1e10, best_att = 0; for (i = 0, alpha = alpha_0; i < alpha_size; alpha += inc_alpha, i++) for (j = 0, a = a_0; j < a_size; a += inc_a, j++) { retval.radius = a; retval.alpha = alpha; A2D_ELEM(att(), i, j) = blob_att(w, retval); A2D_ELEM(ops(), i, j) = blob_ops(w, retval); if (j > 0) for (int n = target_length - 1; n >= 0; n--) if (A2D_ELEM(att(), i, j - 1) > target_att[n] && A2D_ELEM(att(), i, j) < target_att[n]) { A2D_ELEM(att(), i, j) = 0; if (A2D_ELEM(ops(), i, j - 1) < best_ops && A2D_ELEM(att(), i, j - 1) >= best_att) { best_alpha = alpha; best_a = a - inc_a; best_ops = A2D_ELEM(ops(), i, j - 1); best_att = target_att[n]; } } } #ifdef DEBUG att.write((std::string)"att" + floatToString(w) + ".xmp"); ops.write((std::string)"ops" + floatToString(w) + ".xmp"); #endif retval.radius = best_a; retval.alpha = best_alpha; return retval; }
// ----------------------------------------------------------------------------- // CCommonTestClass::MpxAttConst() // Returns: Symbian OS errors. // ----------------------------------------------------------------------------- TInt CCommonTestClass::MpxAttConst(CStifItemParser& aItem) { FTRACE(FPrint(_L("CCommonTestClass::MpxAttConst testing TMPXAttribute::TMPXAttribute(TInt aContentId, TUint aAttributeId) begin"))); iLog->Log(_L("CCommonTestClass::MpxAttConst testing TMPXAttribute::TMPXAttribute(TInt aContentId, TUint aAttributeId) begin")); TInt err=KErrNone; TInt contentId; TUint attId; // read in parameters if ( aItem.GetNextInt(contentId) ) { iLog->Log(_L("Missing Parameter: content ID.")); return KErrBadTestParameter; } if ( aItem.GetNextInt(attId) ) { iLog->Log(_L("Missing Parameter: attribute ID.")); return KErrBadTestParameter; } TMPXAttribute att(contentId, attId); err = iMPXAttArray.Append(att); return err; }
XMLFile::Tag::Tag(const Flux::string n, Flux::string conts) { Name = n; Content = conts; for(unsigned i = 0; i < conts.size(); i++) { char c = conts.at(i); if(c == '<' && conts.at(i + 1) != '/' && conts.at(i + 1) != ' ') { bool SelfContained = false; std::string tag = ""; std::string contents = ""; for(unsigned j = 1; conts.at(i + j) != '>' && conts.at(i + j) != ' '; j++) { tag += conts.at(i + j); } for(unsigned o = 1; conts.at(i + o) != '>'; o++) { if((conts.at(i + o) == '/' || conts.at(i + o) == '?') && conts.at(i + o + 1) == '>') { SelfContained = true; break; } } if(!SelfContained) { for(unsigned k = conts.find('>', i) + 1; k < conts.find("</" + tag, i); k++) { contents += conts.at(k); } } Tag t(tag, contents); for(unsigned l = 1; conts.at(i + l) != '>'; l++) { char cc = conts.at(i + l); if(cc == '=' && conts.at(i + l + 1) == '"') { std::string attribName = ""; std::string attribVal = ""; for(int m = -1; conts.at(i + l + m) != ' '; m--) { attribName.insert(0, 1, conts.at(i + l + m)); } for(unsigned nn = 2; conts.at(i + l + nn) != '"'; nn++) { attribVal += conts.at(i + l + nn); } Tag::Attribute att(attribVal); t.Attributes[attribName] = att; } } Tags[tag] = t; i += contents.size(); } } }
XMLFile::XMLFile(const Flux::string fn): TextFile(fn) { for(unsigned i = 0; i < SingleLineBuffer.size(); i++) { char c = SingleLineBuffer.at(i); if(c == '<' && SingleLineBuffer.at(i + 1) != '/') { bool SelfContained = false; std::string tag = ""; std::string contents = ""; for(unsigned j = 1; SingleLineBuffer.at(i + j) != '>' && SingleLineBuffer.at(i + j) != ' '; j++) { tag += SingleLineBuffer.at(i + j); } for(unsigned o = 1; SingleLineBuffer.at(i + o) != '>'; o++) { if((SingleLineBuffer.at(i + o) == '/' || SingleLineBuffer.at(i + o) == '?') && SingleLineBuffer.at(i + o + 1) == '>') { SelfContained = true; break; } } if(!SelfContained) { for(unsigned k = SingleLineBuffer.find('>', i) + 1; k < SingleLineBuffer.find("</" + tag, i); k++) { contents += SingleLineBuffer.at(k); } } Tag t(tag, contents); for(unsigned l = 1; SingleLineBuffer.at(i + l) != '>'; l++) { char cc = SingleLineBuffer.at(i + l); if(cc == '=' && SingleLineBuffer.at(i + l + 1) == '"') { std::string attribName = ""; std::string attribVal = ""; for(int m = -1; SingleLineBuffer.at(i + l + m) != ' '; m--) { attribName.insert(0, 1, SingleLineBuffer.at(i + l + m)); } for(unsigned n = 2; SingleLineBuffer.at(i + l + n) != '"'; n++) { attribVal += SingleLineBuffer.at(i + l + n); } Tag::Attribute att(attribVal); t.Attributes[attribName] = att; } } Tags[tag] = t; i += contents.size(); } } }
void MergeInfoPP::doFile( MergeInfoSection * sect, MergeFile & outFile, MergeFile & inFile, uint fileIdx, InfoPPReqNode ** reqs, uint numReqs ) //------------------------------------------------------------------ { MergeAbbrevSection & abbrevs( sect->getAbbrev() ); MergeLineSection & line( sect->getLine() ); MergeAbbrev * abbrev; uint_32 abbcode; uint_32 offset; uint attribIdx; uint index; uint_8 addrSize; uint_8 relFile; InfoPPReqNode * node; MergeOffset ref( (uint_8) fileIdx, 0 ); MergeRelocate & reloc( sect->getReloc() ); MergeDIE * referredTo; addrSize = sect->getAddrSize(); for( index = 0; index < numReqs; index += 1 ) { node = reqs[ index ]; offset = node->inOff; outFile.seekSect( DR_DEBUG_INFO, node->outOff ); if( offset == 0 ) { outFile.writeULEB128( 0 ); continue; // <----------- unusual flow } abbcode = inFile.readULEB128( DR_DEBUG_INFO, offset ); if( abbcode == 0 ) { outFile.writeULEB128( 0 ); continue; // <----------- unusual flow } abbrev = abbrevs.getAbbrev( abbcode ); outFile.writeULEB128( abbcode ); for( attribIdx = 0; attribIdx < abbrev->entries(); attribIdx += 1 ) { MergeAttrib & att( (*abbrev)[ attribIdx ] ); switch( att.attrib() ) { case DW_AT_sibling: inFile.skipForm( DR_DEBUG_INFO, offset, att.form(), addrSize ); outFile.writeForm( att.form(), node->sibOff, addrSize ); break; case DW_AT_decl_file: relFile = (uint_8) inFile.readForm( DR_DEBUG_INFO, offset, att.form(), addrSize ); outFile.writeForm( att.form(), line.getNewFileIdx( (uint_8) fileIdx, relFile ), addrSize ); break; case DW_AT_macro_info: // NYI case DW_AT_WATCOM_references_start: // NYI inFile.copyFormTo( outFile, DR_DEBUG_INFO, offset, att.form(), addrSize ); break; default: switch( att.form() ) { case DW_FORM_ref4: case DW_FORM_ref2: case DW_FORM_ref1: case DW_FORM_ref_addr: case DW_FORM_ref_udata: ref.offset = inFile.readForm( DR_DEBUG_INFO, offset, att.form(), addrSize ); if( ref.offset == 0 ) { outFile.writeForm( att.form(), 0, addrSize ); } else { referredTo = reloc.getReloc( ref ); #if INSTRUMENTS if( referredTo == NULL ) { Log.printf( "Ack -- can't find a replacement" ); Log.printf( " for %#x %s!\n", att.attrib(), ref.getString() ); } #endif outFile.writeForm( att.form(), referredTo->getNewOff(), addrSize ); } break; case DW_FORM_ref8: /* can't handle 8-byte references */ default: inFile.copyFormTo( outFile, DR_DEBUG_INFO, offset, att.form(), addrSize ); } } } } }
void RClipboardOperation::copy( RDocument& src, RDocument& dest, const RVector& offset, double scale, double rotation, bool flipHorizontal, bool flipVertical, bool toCurrentLayer, bool toCurrentBlock, bool overwriteLayers, bool overwriteBlocks, const QString& blockName, const QString& layerName, RTransaction& transaction, bool selectionOnly, bool clear, bool toModelSpaceBlock, bool preview, const RQMapQStringQString& attributes) const { bool overwriteLinetypes = false; double unitScale; if (src.getUnit()==RS::None) { unitScale = 1.0; } else { unitScale = RUnit::convert(1.0, src.getUnit(), dest.getUnit()); } if (clear) { dest.clear(); } QSet<REntity::Id> entityIdsSet; if (selectionOnly) { entityIdsSet = src.querySelectedEntities(); } else { entityIdsSet = src.queryAllEntities(); } QList<REntity::Id> entityIdsList = src.getStorage().orderBackToFront(entityIdsSet); // Non-const offset. reset to 0/0/0 if copying to block // (offset implemented as block reference offset). RVector off = offset; bool hasBlock = false; QSet<REntity::Id> attributeIds; // this part is used to insert ('paste') blocks from the part library // as new blocks: QSharedPointer<RBlockReferenceEntity> refp; if (!blockName.isNull()) { QSharedPointer<RBlock> block; hasBlock = dest.hasBlock(blockName); // block does not exist in dest - or - // block exists in dest and must be overwritten: if (!hasBlock || overwriteBlocks) { block = QSharedPointer<RBlock> (new RBlock(&dest, blockName, RVector(0, 0, 0))); transaction.overwriteBlock(block); } // block exists and must not be overwritten: else { block = dest.queryBlock(blockName); } Q_ASSERT(!block.isNull()); // create new block reference that references new, overwritten or existing block // (insert later, when block is complete, so we have bounding box for spatial index): RBlockReferenceEntity* ref = new RBlockReferenceEntity(&dest, RBlockReferenceData(block->getId(), RVector(0,0,0), RVector(1.0, 1.0, 1.0), 0.0)); refp = QSharedPointer<RBlockReferenceEntity>(ref); refp->setBlockId(dest.getCurrentBlockId()); off = RVector(0, 0, 0); if (flipHorizontal) { refp->flipHorizontal(); } if (flipVertical) { refp->flipVertical(); } //ref->scale(scale * unitScale); refp->scale(scale); refp->rotate(rotation); refp->move(offset); // create attribute for each attribute definition in block with // invalid parent ID (fixed later, when block reference ID is known): QSet<REntity::Id> ids = src.queryAllEntities(); QSet<REntity::Id>::iterator it; for (it=ids.begin(); it!=ids.end(); it++) { REntity::Id id = *it; QSharedPointer<RAttributeDefinitionEntity> attDef = src.queryEntity(id).dynamicCast<RAttributeDefinitionEntity>(); if (attDef.isNull()) { continue; } QSharedPointer<RAttributeEntity> att( new RAttributeEntity( &dest, RAttributeData(attDef->getData(), REntity::INVALID_ID, attDef->getTag()) ) ); att->scale(unitScale); refp->applyTransformationTo(*att); // assign values to attributes: QString tag = att->getTag(); if (attributes.contains(tag)) { att->setText(attributes[tag]); } // make sure the attribute has the correct layer ID of the // corresponding layer in dest: QSharedPointer<RLayer> destLayer = copyEntityLayer(*attDef, src, dest, overwriteLayers, transaction); att->setLayerId(destLayer->getId()); QSharedPointer<RLinetype> destLinetype = copyEntityLinetype(*attDef, src, dest, overwriteLinetypes, transaction); att->setLinetypeId(destLinetype->getId()); transaction.addObject(att, false); attributeIds.insert(att->getId()); } scale = 1.0; rotation = 0.0; flipHorizontal = false; flipVertical = false; toCurrentLayer = false; //toCurrentBlock = false; } // copy entities from src to dest: // if the block existed already in dest and is not overwritten, // there's nothing to do here: if (!hasBlock || overwriteBlocks || preview) { copiedLayers.clear(); copiedLinetypes.clear(); copiedBlocks.clear(); int counter = 0; QList<REntity::Id>::iterator it; for (it=entityIdsList.begin(); it!=entityIdsList.end(); ++it) { if (preview && ++counter>RSettings::getPreviewEntities()) { break; } QSharedPointer<REntity> entity = src.queryEntityDirect(*it); if (entity.isNull() || entity->isUndone()) { continue; } copyEntity( *entity.data(), src, dest, off, scale, unitScale, rotation, flipHorizontal, flipVertical, toCurrentLayer, toCurrentBlock, overwriteLayers, overwriteBlocks, blockName, transaction, toModelSpaceBlock // to model space: true for copy // (allow copy from inside any block definition), // false for paste ); } } // only overwrite layers: else if (overwriteLayers) { copiedLayers.clear(); int counter = 0; QList<REntity::Id>::iterator it; for (it=entityIdsList.begin(); it!=entityIdsList.end(); ++it) { if (preview && ++counter>RSettings::getPreviewEntities()) { break; } QSharedPointer<REntity> entity = src.queryEntityDirect(*it); if (entity.isNull() || entity->isUndone()) { continue; } copyEntityLayer( *entity.data(), src, dest, overwriteLayers, transaction ); } } // copying of entire block complete, insert block reference now since // we now have the bounding box for the spatial index: if (!refp.isNull()) { bool useCurrentAttributes = true; if (!layerName.isEmpty()) { useCurrentAttributes = false; refp->setLayerId(dest.getLayerId(layerName)); } transaction.addObject(refp, useCurrentAttributes); // fix parent ID of attributes created by the new inserted block: REntity::Id refId = refp->getId(); //QSet<REntity::Id> ids = dest.queryAllEntities(); QSet<REntity::Id>::iterator it; for (it=attributeIds.begin(); it!=attributeIds.end(); it++) { REntity::Id id = *it; QSharedPointer<RAttributeEntity> e = dest.queryEntityDirect(id).dynamicCast<RAttributeEntity>(); if (e.isNull()) { continue; } if (e->getParentId()==REntity::INVALID_ID) { e->setParentId(refId); } } } transaction.endCycle(); }
ATTR_TYPE getPlugAttrType(MPlug plug) { MStatus stat = MS::kSuccess; MPlug p = plug; while (p.isChild()) p = p.parent(); plug = p; MObject attObj = plug.attribute(&stat); MFnAttribute att(attObj); if (!stat) return ATTR_TYPE::ATTR_TYPE_NONE; MString attName = att.name(); // all 3 child attributes are vectors for osl if (p.numChildren() == 3) return ATTR_TYPE::ATTR_TYPE_VECTOR; if (attName == "input1") { if (plug.node().hasFn(MFn::kMultiplyDivide)) return ATTR_TYPE::ATTR_TYPE_VECTOR; } if (attName == "input2") { if (plug.node().hasFn(MFn::kMultiplyDivide)) return ATTR_TYPE::ATTR_TYPE_VECTOR; } if (attName == "output") { if (plug.node().hasFn(MFn::kMultiplyDivide)) return ATTR_TYPE::ATTR_TYPE_VECTOR; } if (attName == "outValue") { if (plug.node().hasFn(MFn::kGammaCorrect)) return ATTR_TYPE::ATTR_TYPE_COLOR; } if (attName == "outDPdu") return ATTR_TYPE::ATTR_TYPE_VECTOR; if (attName == "outDPdv") return ATTR_TYPE::ATTR_TYPE_VECTOR; if (attName == "outColor") return ATTR_TYPE::ATTR_TYPE_COLOR; if (attName == "uvCoord") return ATTR_TYPE::ATTR_TYPE_VECTOR; if (attName == "outUV") return ATTR_TYPE::ATTR_TYPE_VECTOR; if (attName == "color") return ATTR_TYPE::ATTR_TYPE_COLOR; if (attName == "normalCamera") return ATTR_TYPE::ATTR_TYPE_VECTOR; if (attName == "pointWorld") return ATTR_TYPE::ATTR_TYPE_VECTOR; if (attName == "rayDirection") return ATTR_TYPE::ATTR_TYPE_VECTOR; if (att.isUsedAsColor()) return ATTR_TYPE::ATTR_TYPE_COLOR; if (attObj.apiType() == MFn::kNumericAttribute) { MFnNumericAttribute na(attObj, &stat); if (!stat) return ATTR_TYPE::ATTR_TYPE_NONE; if (na.unitType() == MFnNumericData::Type::kFloat) return ATTR_TYPE::ATTR_TYPE_FLOAT; } if (attObj.apiType() == MFn::kAttribute3Float) { return ATTR_TYPE::ATTR_TYPE_VECTOR; } return ATTR_TYPE::ATTR_TYPE_NONE; }
void MergeInfoSection::readDIE( MergeFile * file, MergeOffset startOff, MergeDIE * prt, MergeOffset& moff, uint_32 abbCode ) //------------------------------------------------------------------- // read a die and all its children, adding to _dies. return false when // the abbrev code is zero (recursive) { MergeDIE * die; // one we read MergeAbbrev * abbrev; MergeOffset child; // offset of first child MergeOffset sibling; bool ext = TRUE; // external or static? bool defn = TRUE; // is a definition? const char * name = NULL; int i; DIELen_T length; int lenDelta = 0; // delta from changing file idx if( abbCode == 0 ) { length = (DIELen_T) (moff.offset - startOff.offset); MergeNameKey nmKey( abbCode, ext, NULL, 0 ); die = new MergeDIE( prt, startOff, nmKey, child, sibling, defn, length ); die = die->collision( _diesByName ); #if INSTRUMENTS if( abbrev == NULL ) { Log.printf( "zoiks! %s\n", startOff.getString() ); } #endif return; //<------------------- early return } abbrev = _abbrevs.getAbbrev( abbCode ); #if INSTRUMENTS if( abbrev == NULL ) { Log.printf( "ABBREV == NULL! offset is %s, %s\n", startOff.getString(), moff.getString() ); } #endif InfoAssert( abbrev != NULL ); // NYI throw for( i = 0; i < abbrev->entries(); i += 1 ) { MergeAttrib & att( (*abbrev)[ i ] ); switch( att.attrib() ) { case DW_AT_name: name = file->readString( DR_DEBUG_INFO, moff.offset ); if( abbrev->tag() == DW_TAG_compile_unit ) { name = MagicCompunitName; } break; case DW_AT_sibling: sibling.fileIdx = moff.fileIdx; sibling.offset = file->readDWord( DR_DEBUG_INFO, moff.offset ); break; case DW_AT_external: ext = file->readByte( DR_DEBUG_INFO, moff.offset ); break; case DW_AT_declaration: defn = !file->readByte( DR_DEBUG_INFO, moff.offset ); break; case DW_AT_decl_file: lenDelta = getFileLenDelta( file, moff, att.form() ); break; default: file->skipForm( DR_DEBUG_INFO, moff.offset, att.form(), getAddrSize() ); } } if( abbrev->hasChildren() ) { child = moff; } length = (DIELen_T)(moff.offset - startOff.offset + lenDelta); MergeNameKey nmKey( abbrev->tag(), ext, name, 0 ); die = new MergeDIE( prt, startOff, nmKey, child, sibling, defn, length ); die = die->collision( _diesByName ); getReloc().addReloc( startOff, die ); if( abbrev->hasChildren() ) { while( 1 ) { startOff = moff; abbCode = file->readULEB128( DR_DEBUG_INFO, moff.offset ); if( abbCode == 0 ) break; readDIE( file, startOff, die, moff, abbCode ); } } if( !die->siblingSet() ) { die->setSibling( moff ); } }
MString getAttributeNameFromPlug(const MPlug& plug) { MFnAttribute att(plug.attribute()); return att.name(); }
/** * There is no real hope for us: we should try to do some damage to the enemy. * We can spend some cycles here, since it's rare. */ bool ai_default::desperate_attack(const map_location &loc) { const unit &u = units_.find(loc)->second; LOG_AI << "desperate attack by '" << u.type_id() << "' " << loc << "\n"; map_location adj[6]; get_adjacent_tiles(loc, adj); double best_kill_prob = 0.0; unsigned int best_weapon = 0; unsigned best_dir = 0; for (unsigned n = 0; n != 6; ++n) { const unit *enemy = get_visible_unit(units_, adj[n], current_team()); if (!enemy || !current_team().is_enemy(enemy->side()) || enemy->incapacitated()) continue; const std::vector<attack_type> &attacks = u.attacks(); for (unsigned i = 0; i != attacks.size(); ++i) { // Skip weapons with attack_weight=0 if (attacks[i].attack_weight() == 0) continue; battle_context bc(units_, loc, adj[n], i); combatant att(bc.get_attacker_stats()); combatant def(bc.get_defender_stats()); att.fight(def); if (def.hp_dist[0] <= best_kill_prob) continue; best_kill_prob = def.hp_dist[0]; best_weapon = i; best_dir = n; } } if (best_kill_prob > 0.0) { attack_result_ptr attack_res = execute_attack_action(loc, adj[best_dir], best_weapon); if (!attack_res->is_ok()) { ERR_AI << "desperate attack failed"<<std::endl; } return attack_res->is_gamestate_changed(); } double least_hp = u.hitpoints() + 1; // Who would do most damage to us when they attack? (approximate: may be different ToD) for (unsigned n = 0; n != 6; ++n) { const unit *enemy = get_visible_unit(units_, adj[n], current_team()); if (!enemy || !current_team().is_enemy(enemy->side()) || enemy->incapacitated()) continue; const std::vector<attack_type> &attacks = enemy->attacks(); for (unsigned i = 0; i != attacks.size(); ++i) { // SKip weapons with attack_weight=0 if (attacks[i].attack_weight() == 0) continue; battle_context bc(units_, adj[n], loc, i); combatant att(bc.get_attacker_stats()); combatant def(bc.get_defender_stats()); att.fight(def); if (def.average_hp() < least_hp) { least_hp = def.average_hp(); best_dir = n; } } } // It is possible that there were no adjacent units to attack... if (least_hp != u.hitpoints() + 1) { battle_context bc(units_, loc, adj[best_dir], -1, -1, 0.5); attack_result_ptr attack_res = execute_attack_action(loc, adj[best_dir], bc.get_attacker_stats().attack_num); if (!attack_res->is_ok()) { ERR_AI << "desperate attack failed" << std::endl; } return attack_res->is_gamestate_changed(); } return false; }