PartContainer::Parts PartContainer::getAttachedParts(Part* part) const { if(attachments.find(part) != attachments.end()) return attachments.at(part); return Parts(); }
//// TEMPORARY float ShipDesign::Defense() const { // accumulate defense from defensive parts in design. double total_defense = 0.0; const PartTypeManager& part_manager = GetPartTypeManager(); std::vector<std::string> all_parts = Parts(); for (std::vector<std::string>::const_iterator it = all_parts.begin(); it != all_parts.end(); ++it) { const PartType* part = part_manager.GetPartType(*it); if (part && (part->Class() == PC_SHIELD || part->Class() == PC_ARMOUR)) total_defense += boost::get<float>(part->Stats()); } return total_defense; }
SynthPartElement * AUInstrumentBase::GetPartElement (AudioUnitElement inPartElement) { AUScope & parts = Parts(); unsigned int numEls = parts.GetNumberOfElements(); for (unsigned int i = 0; i < numEls; ++i) { SynthPartElement* el = reinterpret_cast<SynthPartElement*>(parts.GetElement(i)); if (el->GetIndex() == inPartElement) { return el; } } return NULL; }
float ShipDesign::AdjustedAttack(float shield) const { // total damage against a target with the given shield. // accumulate attack stat from all weapon parts in design const PartTypeManager& manager = GetPartTypeManager(); float total_attack = 0.0f; std::vector<std::string> all_parts = Parts(); for (std::vector<std::string>::const_iterator it = all_parts.begin(); it != all_parts.end(); ++it) { const PartType* part = manager.GetPartType(*it); if (part && (part->Class() == PC_SHORT_RANGE || part->Class() == PC_POINT_DEFENSE || part->Class() == PC_MISSILES || part->Class() == PC_FIGHTERS)) { total_attack += std::max(0.0f, static_cast<float>(part->Capacity()) - shield); } } return total_attack; }
float ShipDesign::Attack() const { // accumulate attack stat from all weapon parts in design const PartTypeManager& manager = GetPartTypeManager(); float total_attack = 0.0f; std::vector<std::string> all_parts = Parts(); for (std::vector<std::string>::const_iterator it = all_parts.begin(); it != all_parts.end(); ++it) { const PartType* part = manager.GetPartType(*it); if (part) { if (part->Class() == PC_SHORT_RANGE || part->Class() == PC_POINT_DEFENSE) total_attack += boost::get<DirectFireStats>(part->Stats()).m_damage; else if (part->Class() == PC_MISSILES) total_attack += boost::get<LRStats>(part->Stats()).m_damage; else if (part->Class() == PC_FIGHTERS) total_attack += boost::get<FighterStats>(part->Stats()).m_anti_ship_damage; } } return total_attack; }
void Listener :: exec ( const QPoint & Loc ) { { const ActList AL = FindActs ( CurrDev ) ; if ( ! AL . isEmpty ( ) ) { setActiveAction ( AL . first ( ) ) ; }//fi } ActPtr Act = QMenu :: exec ( Loc ) ; if ( Act ) { const QString AN = Act -> objectName ( ) ; // Primary key. CurrDev = sect ( AN , 0 ) ; // SysPath. const UdevDev Dev ( UdevContext , CurrDev ) ; QString Node = Dev . DevNode ( ) ; const QString MP = Mounts :: DecodeIFS ( sect ( AN , 1 ) ) ; // Mountpoint/dm-name if any. const bool Cont = isLUKS ( Dev ) , // It's container. MoM = ! MP . isEmpty ( ) ; // It's mounted or mapped. int RC = 0 ; // Return code for command. if ( MoM || ! Suppl ) { // Currently Suppl may be Eject, Remove or UnmountAll. loKey C , T , S ; if ( MoM ) { if ( Cont ) { C = kLockCmd ; T = kLockTO ; S = kLockShow ; } else { C = kUnmntCmd ; T = kUnmntTO ; S = kUnmntShow ; }//fi } else { if ( Cont ) { C = kUnlockCmd ; T = kUnlockTO ; S = kUnlockShow ; } else { C = kMountCmd ; T = kMountTO ; S = kMountShow ; }//fi }//fi RC = ExecCmd ( Opt . toStr ( C ) , MoM ? MP : Node , Opt . toInt ( T ) , Opt . toBool ( S ) ) ; }//fi const UdevDev WD ( WDisk ( Dev ) ) ; // whole disk. bool Show = Opt . toBool ( kEjectShow ) ; RefreshMInfo ( ) ; { const bool A = Opt . toBool ( kAutoEject ) , D = Opt . toStr ( kEjectCmd ) . isEmpty ( ) , L = ( MPoints ( Dev ) + Holders ( Dev ) ) . isEmpty ( ) , S = Suppl == reqEject || Suppl == reqRemove , E = Ejectable ( WD ) ; if ( MoM && ( L || Suppl ) && A && ! D && E && ! S ) { Suppl = reqEject ; Show = Opt . toBool ( kAutoEjShow ) ; }//fi } if ( RC ) { SetActions ( Dev ) ; // workaround for setChecked () } else if ( Suppl == reqUnmtAll ) { UnmntAll ( Dev , Opt . toBool ( kUnmntShow ) ) ; } else if ( Suppl ) { // Eject or Remove. QStringList Msg , NL ; Node = WD . DevNode ( ) ; foreach ( const QString P , Parts ( WD ) << WD . SysPath ( ) ) { const UdevDev D ( UdevContext , P ) ; const QString N = D . DevNode ( ) ; NL += N ; UnmntAll ( D , false ) ; RefreshMInfo ( ) ; foreach ( const QString M , MPoints ( D ) ) { Msg << N + tr ( " mounted on " ) + M ; }//done foreach ( const QString M , Holders ( D ) ) { Msg << N + tr ( " mapped on " ) + M ; }//done UdevEnum En ( UdevContext ) ; En . MatchSubsys ( Subsys_Block ) ; En . MatchSysAttr ( SA_BackFile , N . toLatin1 ( ) ) ; En . ScanDevs ( ) ; foreach ( const UdevPair M , En . GetList ( ) ) { Msg << N + tr ( " mapped on " ) + UdevDev ( UdevContext , M . first ) . DevNode ( ) ; }//done }//done const QStringList F ( "[1-9]*" ) ; foreach ( const QString P , QDir ( "/proc" ) . entryList ( F , Drs ) ) { const QDir D ( "/proc/" + P + "/fd" ) ; foreach ( const QFileInfo I , D . entryInfoList ( QDir :: Files ) ) { const QString N = I . symLinkTarget ( ) ; if ( NL . contains ( N ) ) { Msg << N + tr ( " used by PId " ) + P ; }//fi }//done }//done if ( ! Msg . isEmpty ( ) ) { QMessageBox :: critical ( this , TPref + tr ( "Error" ) , tr ( "Device " ) + Node + tr ( " in use:" ) + "\n" + Msg . join ( "\n" ) ) ; } else { QString Cmd ; int TO ; if ( Suppl == reqEject ) { Cmd = Opt . toStr ( kEjectCmd ) ; TO = Opt . toInt ( kEjectTO ) ; } else { Cmd = Opt . toStr ( kRemoveCmd ) ; TO = Opt . toInt ( kRemoveTO ) ; Show = Opt . toBool ( kRemoveShow ) ; }//fi ExecCmd ( Cmd , Node , TO , Show ) ; }//fi }//fi
void AUInstrumentBase::CreateExtendedElements() { Parts().Initialize(this, kAudioUnitScope_Part, mInitNumPartEls); }