NNType Entity::takeEnergy(NNType e) { NNType t = getEnergy(); if (t > e) { setEnergy(t - e); return e; } else { setEnergy(0); return t; } }
ParticleState::ParticleState(int id, double E, Vector3d pos, Vector3d dir, double z) { setId(id); setEnergy(E); setPosition(pos); setDirection(dir); setRedshift(z); }
SXRMB2DMapScanConfiguration::SXRMB2DMapScanConfiguration(QObject *parent) : AMStepScanConfiguration(parent), SXRMBScanConfiguration() { timeOffset_ = 0.8; setName("2D Map"); setUserScanName("2D Map"); setEnergy(3000.0); exportAsAscii_ = false; AMScanAxisRegion *region = new AMScanAxisRegion; AMScanAxis *axis = new AMScanAxis(AMScanAxis::StepAxis, region); appendScanAxis(axis); region = new AMScanAxisRegion; axis = new AMScanAxis(AMScanAxis::StepAxis, region); appendScanAxis(axis); connect(scanAxisAt(0)->regionAt(0), SIGNAL(regionStartChanged(AMNumber)), this, SLOT(computeTotalTime())); connect(scanAxisAt(0)->regionAt(0), SIGNAL(regionStepChanged(AMNumber)), this, SLOT(computeTotalTime())); connect(scanAxisAt(0)->regionAt(0), SIGNAL(regionEndChanged(AMNumber)), this, SLOT(computeTotalTime())); connect(scanAxisAt(0)->regionAt(0), SIGNAL(regionTimeChanged(AMNumber)), this, SLOT(computeTotalTime())); connect(scanAxisAt(1)->regionAt(0), SIGNAL(regionStartChanged(AMNumber)), this, SLOT(computeTotalTime())); connect(scanAxisAt(1)->regionAt(0), SIGNAL(regionStepChanged(AMNumber)), this, SLOT(computeTotalTime())); connect(scanAxisAt(1)->regionAt(0), SIGNAL(regionEndChanged(AMNumber)), this, SLOT(computeTotalTime())); }
void VESPERSEXAFSScanConfigurationView::onLinesComboBoxIndexChanged(int index) { if (lineChoice_->count() == 0 || index == -1) return; energy_->setValue(lineChoice_->itemData(index).toDouble()); setEnergy(); config_->setEdge(elementChoice_->text()+" "+lineChoice_->itemText(index).split(":").first()); }
SGMEnergyPosition::SGMEnergyPosition(const QString &name, double energy, int monoEncoderTarget, int undulatorStepSetpoint, double exitSlitDistance, int sgmGrating) { setName(name); setEnergy(energy); setMonoEncoderTarget(monoEncoderTarget); setUndulatorStepSetpoint(undulatorStepSetpoint); setExitSlitDistance(exitSlitDistance); setSGMGrating(sgmGrating); }
SGMEnergyPosition& SGMEnergyPosition::operator=(const SGMEnergyPosition &other){ if(this != &other){ AMDbObject::operator=(other); setEnergy(other.energy()); setMonoEncoderTarget(other.monoEncoderTarget()); setUndulatorStepSetpoint(other.undulatorStepSetpoint()); setExitSlitDistance(other.exitSlitDistance()); setSGMGrating(other.sgmGrating()); } return *this; }
void Entity::initClone(Entity *entity) { mNeuralNetwork = entity->mNeuralNetwork.clone(true); setEnergy(std::uniform_int_distribution<>(50, 100)(randgen)); setHealth(std::uniform_int_distribution<>(30, 60)(randgen)); setHydration(std::uniform_int_distribution<>(1000, 2000)(randgen)); setValueStore1(0); setValueStore2(0); setValueStore3(0); setValueStore4(0); mGeneration = entity->generation() + 1; }
/** Called when asyn clients call pasynFloat64->write(). * For all parameters it sets the value in the parameter library and calls any registered callbacks. * \param[in] pasynUser pasynUser structure that encodes the reason and address. * \param[in] value Value to write. */ asynStatus mythen::writeFloat64(asynUser *pasynUser, epicsFloat64 value) { int function = pasynUser->reason; int status = asynSuccess; int addr = 0; const char* functionName = "writeFloat64"; status = getAddress(pasynUser, &addr); if (status != asynSuccess) return((asynStatus)status); /* Reject any call to the detector if it is running */ if (acquiring_) { asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, "%s:%s: detector is busy\n", driverName, functionName); return asynError; } /* Set the parameter in the parameter library. */ status = (asynStatus) setDoubleParam(addr, function, value); if (function == ADAcquireTime) { status |= setExposureTime(value); } else if (function == SDDelayTime) { status |= setDelayAfterTrigger(value); } else if (function == SDThreshold) { /* note down user's set value and recover it when settings change */ // threshold = value; status |= setKthresh(value); } else if (function == SDEnergy) { status |= setEnergy(value); } else if (function == SDTau) { status |= setTau(value); } else { /* If this is not a parameter we have handled call the base class */ if (function < NUM_SD_PARAMS) status = ADDriver::writeFloat64(pasynUser, value); } status |= getSettings(); /* Update any changed parameters */ status |= callParamCallbacks(); if (status) asynPrint(pasynUser, ASYN_TRACE_ERROR, "%s:%s: error, status=%d function=%d, value=%g\n", driverName, functionName, status, function, value); else asynPrint(pasynUser, ASYN_TRACEIO_DRIVER, "%s:%s: function=%d, value=%g\n", driverName, functionName, function, value); return((asynStatus)status); }
SGMScanInfo& SGMScanInfo::operator =(const SGMScanInfo &other){ if(this != &other){ AMDbObject::operator=(other); setScanName(other.scanName()); setHasEdge(other.hasEdge()); setEdge(other.edge()); setEnergy(other.energy()); setStart(other.start()); setMiddle(other.middle()); setEnd(other.end()); } return *this; }
// ---------------------------------------------------------------------------- void TrackObjectPresentationLight::update(float dt) { if (m_energy_animation_remaining_duration > 0.0f) { m_energy_animation_remaining_duration -= dt; if (m_energy_animation_remaining_duration < 0.0f) m_energy_animation_remaining_duration = 0.0f; float ratio = m_energy_animation_remaining_duration / m_energy_animation_total_duration; setEnergy(m_energy_animation_from + (m_energy_animation_to - m_energy_animation_from)*(1.0f - ratio)); } }
void Unit::iniciarUnidad(PlayerType tj, PlayerColor cr, PlayerTeam eq, int maxVitalidad, int vitalidad, int maxEnergy, int energy){ const int barWidth = 20; // QPainterPath path; //// path.lineTo(10,0); // path.addEllipse(QRectF(-10, -10, 20, 20)); // setShape(path); // includeBars = false; checkCounter = 0; setBorderWidth(2); setPlayerType(tj); setUnitColor(cr); setEquipo(eq); QRectF rectMA = MovilAgent::boundingRect(); prepareGeometryChange(); setMaxHealth(maxVitalidad); setHealth(vitalidad); setHealthBarPos(rectMA.topLeft() + QPointF(rectMA.width()/2 - barWidth/2, - 20)); setHealthBarWidth(barWidth); setHealthBarHeight(4); setVisibleHealthBar(true); setMaxEnergy(maxEnergy); setEnergy(energy); setEnergyBarPos(rectMA.topLeft() + QPointF(rectMA.width()/2 - barWidth/2, - 10)); setEnergyBarWidth(barWidth); setEnergyBarHeitght(4); setVisibleEnergyBar(true); setAcceptHoverEvents(true); PlayerColor pc; for(int i = 0; i < 8; i++){ pc = (PlayerColor)i; if(pc == getUnitColor()){ diplomacias[pc] = Alied; }else{ diplomacias[pc] = Enemy; } } MovingActuator *actMov = dynamic_cast<MovingActuator*>(getActuator("movement")); connect(actMov, SIGNAL(positionChanged(QPointF)), SLOT(checkAll(QPointF))); // connect(actMov, SIGNAL(llegoADestinoFinal(QPointF)), SLOT(lastCheckPointReached(QPointF))); }
Entity::Entity(Map *map) : mNeuralNetwork(PROPERTY_COUNT, 4 + 4 + 4 + 4), mMap(map), mX(0), mY(0), mAge(1), mGeneration(0) { setEnergy(std::uniform_int_distribution<>(50, 100)(randgen)); setHealth(std::uniform_int_distribution<>(30, 60)(randgen)); setHydration(std::uniform_int_distribution<>(1000, 2000)(randgen)); setValueStore1(0); setValueStore2(0); setValueStore3(0); setValueStore4(0); }
void BioXASSSRLMonochromator::updateEnergy() { BioXASSSRLMonochromatorEnergyControl *newEnergy = 0; switch (int(mode_)) { case Mode::Encoder: newEnergy = encoderEnergy_; break; case Mode::Step: newEnergy = stepEnergy_; break; default: break; } setEnergy(newEnergy); }
HardwareState::HardwareState() { // set initial states and values of modules setEnergy((MIN_PROPER_VOLTAGE + MAX_PROPER_VOLTAGE)/2); setEnergyCurrent(MAX_PROPER_CURRENT); setEnergyStatus(MODULE_ON); setTemperature((MAX_PROPER_TEMPERATURE + MIN_PROPER_TEMPERATURE)/2); setTemperatureStatus(MODULE_ON); setPayload(1); setPayloadStatus(MODULE_STANDBY); setSband(1); setSbandStatus(MODULE_STANDBY); setSolarPanels(1); setSolarPanelsStatus(MODULE_ON); setThermalControl(1); setThermalControlStatus(MODULE_STANDBY); }
SXRMBEXAFSScanConfigurationView::SXRMBEXAFSScanConfigurationView(SXRMBEXAFSScanConfiguration *configuration, QWidget *parent) : SXRMBScanConfigurationView(parent) { SXRMBBeamline *sxrmbBL = SXRMBBeamline::sxrmb(); configuration_ = configuration; regionsView_ = new AMEXAFSScanAxisView("SXRMB Region Configuration", configuration_); autoRegionButton_ = new QPushButton("Auto Set XANES Regions"); connect(autoRegionButton_, SIGNAL(clicked()), this, SLOT(setupDefaultXANESScanRegions())); pseudoXAFSButton_ = new QPushButton("Auto Set EXAFS Regions"); connect(pseudoXAFSButton_, SIGNAL(clicked()), this, SLOT(setupDefaultEXAFSScanRegions())); // Energy (Eo) selection energy_ = new QDoubleSpinBox; energy_->setSuffix(" eV"); energy_->setMinimum(0); energy_->setMaximum(10000); connect(energy_, SIGNAL(editingFinished()), this, SLOT(setEnergy())); elementChoice_ = new QToolButton; connect(elementChoice_, SIGNAL(clicked()), this, SLOT(onElementChoiceClicked())); lineChoice_ = new QComboBox; connect(lineChoice_, SIGNAL(currentIndexChanged(int)), this, SLOT(onLinesComboBoxIndexChanged(int))); if (configuration_->edge().isEmpty()){ elementChoice_->setText("Cl"); fillLinesComboBox(AMPeriodicTable::table()->elementBySymbol("Cl")); lineChoice_->setCurrentIndex(0); } // Resets the view for the view to what it should be. Using the saved for the energy in case it is different from the original line energy. else { elementChoice_->setText(configuration_->edge().split(" ").first()); lineChoice_->blockSignals(true); fillLinesComboBox(AMPeriodicTable::table()->elementBySymbol(elementChoice_->text())); lineChoice_->setCurrentIndex(lineChoice_->findText(configuration_->edge(), Qt::MatchStartsWith | Qt::MatchCaseSensitive)); lineChoice_->blockSignals(false); energy_->setValue(configuration_->energy()); } connect(configuration_, SIGNAL(edgeChanged(QString)), this, SLOT(onEdgeChanged())); QFormLayout *energySetpointLayout = new QFormLayout; energySetpointLayout->addRow("Energy:", energy_); QHBoxLayout *energyLayout = new QHBoxLayout; energyLayout->addLayout(energySetpointLayout); energyLayout->addWidget(elementChoice_); energyLayout->addWidget(lineChoice_); QHBoxLayout *regionsHL = new QHBoxLayout(); regionsHL->addStretch(); regionsHL->addWidget(autoRegionButton_); regionsHL->addWidget(pseudoXAFSButton_); QVBoxLayout *scanRegionConfigurationBoxLayout = new QVBoxLayout; scanRegionConfigurationBoxLayout->addLayout(energyLayout); scanRegionConfigurationBoxLayout->addWidget(regionsView_); scanRegionConfigurationBoxLayout->addLayout(regionsHL); QGroupBox *scanRegionConfigurationGroupBox = new QGroupBox("Scan Region Configuration"); scanRegionConfigurationGroupBox->setLayout(scanRegionConfigurationBoxLayout); // Scan information: scan name selection scanName_ = new QLineEdit(configuration_->userScanName()); scanName_->setAlignment(Qt::AlignCenter); connect(scanName_, SIGNAL(editingFinished()), this, SLOT(onScanNameEdited())); connect(configuration_, SIGNAL(nameChanged(QString)), scanName_, SLOT(setText(QString))); onScanNameEdited(); QFormLayout *scanNameLayout = new QFormLayout; scanNameLayout->addRow("Scan Name:", scanName_); // Scan information: the estimated scan time. estimatedTime_ = new QLabel; connect(configuration_, SIGNAL(totalTimeChanged(double)), this, SLOT(onEstimatedTimeChanged())); onEstimatedTimeChanged(); QVBoxLayout *scanInfoBoxLayout = new QVBoxLayout; scanInfoBoxLayout->addLayout(scanNameLayout); scanInfoBoxLayout->addWidget(estimatedTime_); QGroupBox *scanInfoGroupBox = new QGroupBox("Scan Information"); scanInfoGroupBox->setLayout(scanInfoBoxLayout); // Beamline setting layout QGroupBox *beamlineSettingsGroupBox = createAndLayoutBeamlineSettings(); // Bruker detector setting QGroupBox *detectorSettingGroupBox = createAndLayoutDetectorSettings(configuration_); // layout the contents QGridLayout *contentLayout = new QGridLayout(); contentLayout->addWidget(scanRegionConfigurationGroupBox, 0, 0, 1, 1); contentLayout->addWidget(scanInfoGroupBox, 1, 0, 1, 1); contentLayout->addWidget(beamlineSettingsGroupBox, 0, 4, 1, 1); contentLayout->addWidget(detectorSettingGroupBox, 1, 4, 1, 1); contentLayout->setContentsMargins(20,0,0,20); contentLayout->setSpacing(1); setLayout(contentLayout); connect(configuration_->dbObject(), SIGNAL(xChanged(double)), this, SLOT(onScanConfigurationSampleStageXChanged(double))); connect(configuration_->dbObject(), SIGNAL(zChanged(double)), this, SLOT(onScanConfigurationSampleStageZChanged(double))); connect(configuration_->dbObject(), SIGNAL(yChanged(double)), this, SLOT(onScanConfigurationNormalChanged(double))); connect(configuration_->dbObject(), SIGNAL(rotationChanged(double)), this, SLOT(onScanConfigurationRotationChanged(double))); connect(sxrmbBL, SIGNAL(endstationChanged(SXRMB::Endstation, SXRMB::Endstation)), this, SLOT(onBeamlineEndstationChanged(SXRMB::Endstation, SXRMB::Endstation))); if(sxrmbBL->isConnected()) updateBeamlineSettingWarning(); }
VESPERSEXAFSScanConfigurationView::VESPERSEXAFSScanConfigurationView(VESPERSEXAFSScanConfiguration *config, QWidget *parent) : VESPERSScanConfigurationView(parent) { configuration_ = config; AMTopFrame *frame = new AMTopFrame("VESPERS EXAFS Configuration"); // Regions setup regionsView_ = new AMEXAFSScanAxisView("", configuration_); QVBoxLayout *regionsViewLayout = new QVBoxLayout; regionsViewLayout->addWidget(regionsView_); QGroupBox *regionsViewGroupBox = new QGroupBox("Regions Setup"); regionsViewGroupBox->setLayout(regionsViewLayout); // The fluorescence detector setup fluorescenceDetectorComboBox_ = createFluorescenceComboBox(); connect(fluorescenceDetectorComboBox_, SIGNAL(currentIndexChanged(int)), this, SLOT(onFluorescenceChoiceChanged(int))); connect(configuration_->dbObject(), SIGNAL(fluorescenceDetectorChanged(int)), this, SLOT(updateFluorescenceDetectorComboBox(int))); fluorescenceDetectorComboBox_->setCurrentIndex((int)configuration_->fluorescenceDetector()); // Ion chamber selection itComboBox_ = createIonChamberComboBox(); connect(itComboBox_, SIGNAL(currentIndexChanged(int)), this, SLOT(onItClicked(int))); connect(configuration_->dbObject(), SIGNAL(transmissionChoiceChanged(int)), this, SLOT(updateItComboBox(int))); i0ComboBox_ = createIonChamberComboBox(); connect(i0ComboBox_, SIGNAL(currentIndexChanged(int)), this, SLOT(onI0Clicked(int))); connect(configuration_->dbObject(), SIGNAL(incomingChoiceChanged(int)), this, SLOT(updateI0ComboBox(int))); QHBoxLayout *ionChambersLayout = new QHBoxLayout; ionChambersLayout->addWidget(i0ComboBox_); ionChambersLayout->addWidget(itComboBox_); // Scan name selection scanName_ = createScanNameView(configuration_->name()); connect(scanName_, SIGNAL(editingFinished()), this, SLOT(onScanNameEdited())); connect(configuration_, SIGNAL(nameChanged(QString)), scanName_, SLOT(setText(QString))); onScanNameEdited(); // The estimated scan time. estimatedTime_ = new QLabel; connect(configuration_, SIGNAL(totalTimeChanged(double)), this, SLOT(onEstimatedTimeChanged())); onEstimatedTimeChanged(); QFormLayout *scanNameLayout = new QFormLayout; scanNameLayout->addRow("Scan Name:", scanName_); scanNameLayout->addRow(estimatedTime_); QGroupBox *scanNameGroupBox = new QGroupBox("Scan Name"); scanNameGroupBox->setLayout(scanNameLayout); // Energy (Eo) selection energy_ = new QDoubleSpinBox; energy_->setSuffix(" eV"); energy_->setMinimum(0); energy_->setMaximum(30000); connect(energy_, SIGNAL(editingFinished()), this, SLOT(setEnergy())); elementChoice_ = new QToolButton; connect(elementChoice_, SIGNAL(clicked()), this, SLOT(onElementChoiceClicked())); lineChoice_ = new QComboBox; connect(lineChoice_, SIGNAL(currentIndexChanged(int)), this, SLOT(onLinesComboBoxIndexChanged(int))); if (configuration_->edge().isEmpty()){ elementChoice_->setText("Cu"); fillLinesComboBox(AMPeriodicTable::table()->elementBySymbol("Cu")); lineChoice_->setCurrentIndex(0); } // Resets the view for the view to what it should be. Using the saved for the energy in case it is different from the original line energy. else onEdgeChanged(); connect(configuration_, SIGNAL(edgeChanged(QString)), this, SLOT(onEdgeChanged())); QFormLayout *energySetpointLayout = new QFormLayout; energySetpointLayout->addRow("Energy:", energy_); QHBoxLayout *energyLayout = new QHBoxLayout; energyLayout->addLayout(energySetpointLayout); energyLayout->addWidget(elementChoice_); energyLayout->addWidget(lineChoice_); // Setting the scan position. QGroupBox *goToPositionGroupBox = addGoToPositionView(configuration_->goToPosition(), configuration_->x(), configuration_->y()); connect(configuration_, SIGNAL(gotoPositionChanged(bool)), goToPositionCheckBox_, SLOT(setChecked(bool))); connect(goToPositionCheckBox_, SIGNAL(toggled(bool)), configuration_, SLOT(setGoToPosition(bool))); connect(goToPositionCheckBox_, SIGNAL(toggled(bool)), setCurrentPositionButton_, SLOT(setEnabled(bool))); connect(goToPositionCheckBox_, SIGNAL(toggled(bool)), savedXPosition_, SLOT(setEnabled(bool))); connect(goToPositionCheckBox_, SIGNAL(toggled(bool)), savedYPosition_, SLOT(setEnabled(bool))); connect(goToPositionCheckBox_, SIGNAL(toggled(bool)), positionsSaved_, SLOT(setEnabled(bool))); connect(setCurrentPositionButton_, SIGNAL(clicked()), this, SLOT(setScanPosition())); connect(configuration_->dbObject(), SIGNAL(motorChanged(int)), this, SLOT(onMotorsUpdated(int))); onMotorsUpdated(configuration_->motor()); // Label showing where the data will be saved. QLabel *exportPath = addExportPathLabel(); // Default XANES and EXAFS buttons. QPushButton *defaultXANESButton = new QPushButton("Default XANES"); connect(defaultXANESButton, SIGNAL(clicked()), this, SLOT(setupDefaultXANESScanRegions())); QPushButton *defaultEXAFSButton = new QPushButton("Default EXAFS"); connect(defaultEXAFSButton, SIGNAL(clicked()), this, SLOT(setupDefaultEXAFSScanRegions())); // Setting up the steps to show the time offset for scan time estimation. connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onCustomContextMenuRequested(QPoint))); setContextMenuPolicy(Qt::CustomContextMenu); QGroupBox *timeOffsetBox = addTimeOffsetLabel(configuration_->timeOffset()); connect(timeOffset_, SIGNAL(valueChanged(double)), this, SLOT(setTimeOffset(double))); // Auto-export option. QGroupBox *autoExportGroupBox = addExporterOptionsView(QStringList(), configuration_->exportSpectraSources(), configuration_->exportSpectraInRows()); connect(autoExportSpectra_, SIGNAL(toggled(bool)), configuration_, SLOT(setExportSpectraSources(bool))); connect(autoExportSpectra_, SIGNAL(toggled(bool)), exportSpectraInRows_, SLOT(setEnabled(bool))); connect(exportSpectraInRows_, SIGNAL(toggled(bool)), this, SLOT(updateExportSpectraInRows(bool))); fluorescenceDetectorComboBox_->setCurrentIndex((int)configuration_->fluorescenceDetector()); i0ComboBox_->setCurrentIndex((int)configuration_->incomingChoice()); itComboBox_->setCurrentIndex((int)configuration_->transmissionChoice()); disableStandardI0Options(); disableStandardItOptions(); QVBoxLayout *defaultLayout = new QVBoxLayout; defaultLayout->addSpacing(35); defaultLayout->addWidget(defaultXANESButton); defaultLayout->addWidget(defaultEXAFSButton); defaultLayout->addStretch(); QFormLayout *detectorLayout = new QFormLayout; detectorLayout->addRow("XRF:", fluorescenceDetectorComboBox_); detectorLayout->addRow("I0:", i0ComboBox_); detectorLayout->addRow("It:", itComboBox_); QGroupBox *detectorGroupBox = new QGroupBox("Detectors"); detectorGroupBox->setLayout(detectorLayout); QGroupBox *afterScanBox = createAfterScanOptionsBox(configuration_->closeFastShutter(), configuration_->returnToOriginalPosition(), configuration_->cleanupScaler()); connect(closeFastShutterCheckBox_, SIGNAL(toggled(bool)), this, SLOT(setCloseFastShutter(bool))); // connect(goToPositionCheckBox_, SIGNAL(toggled(bool)), this, SLOT(setReturnToOriginalPosition(bool))); connect(cleanupScalerCheckBox_, SIGNAL(toggled(bool)), this, SLOT(setCleanupScaler(bool))); goToPositionCheckBox_->setDisabled(true); // Setting up the layout. QGridLayout *contentsLayout = new QGridLayout; contentsLayout->addLayout(energyLayout, 0, 0, 1, 3); contentsLayout->addWidget(regionsViewGroupBox, 1, 0, 2, 3); contentsLayout->addWidget(scanNameGroupBox, 3, 0, 1, 2); contentsLayout->addWidget(goToPositionGroupBox, 4, 0, 1, 1); contentsLayout->addWidget(timeOffsetBox, 5, 0, 1, 1); contentsLayout->addWidget(detectorGroupBox, 3, 2, 1, 1); contentsLayout->addWidget(autoExportGroupBox, 4, 1, 1, 2); contentsLayout->addWidget(afterScanBox, 5, 2, 1, 1); QHBoxLayout *squeezeContents = new QHBoxLayout; squeezeContents->addStretch(); squeezeContents->addLayout(defaultLayout); squeezeContents->addLayout(contentsLayout); squeezeContents->addStretch(); QVBoxLayout *configViewLayout = new QVBoxLayout; configViewLayout->addWidget(frame); configViewLayout->addStretch(); configViewLayout->addSpacing(30); configViewLayout->addLayout(squeezeContents); configViewLayout->addSpacing(30); configViewLayout->addWidget(exportPath, 0, Qt::AlignCenter); configViewLayout->addStretch(); setLayout(configViewLayout); }
void Player::apply(int argc, const char *argv[]) { Game& game = Game::getGame(); game.wait(); if (argc>=1) { switch(argv[0][0]) { case 'l': if (isEmbodied()) { look(); //Game::getGame().look(id,*this); } break; case 's': if (isEmbodied()) { char buf[1000]; const char prefix[] = "@broadcast"; int at = 0; for (int i=-1; i<argc; i++) { const char *txt = NULL; if (i==-1) { txt = prefix; } else if (i==0) { txt = getName(); } else { txt = argv[i]; } if (i>=0) { if (at<sizeof(buf)-2) { buf[at] = ' '; at++; } } for (int j=0; j<strlen(txt); j++) if (at<sizeof(buf)-2) { buf[at] = txt[j]; at++; } } buf[at] = '\0'; broadcast(buf); } break; // manage moves "go" (u,d,l,r) case 'g': if (isEmbodied()) { if (argc==2) { switch (argv[1][0]) { case 'l': move(-1,0); //Game::getGame().move(id,*this,-1,0); break; case 'r': move(1,0); //Game::getGame().move(id,*this,1,0); break; case 'u': move(0,-1); //Game::getGame().move(id,*this,0,-1); break; case 'd': move(0,1); //Game::getGame().move(id,*this,0,1); break; } } } break; // manage firing "fire" (u,d,l,r) case 'f': if (isEmbodied()) { if (argc==2) { switch (argv[1][0]) { case 'l': fire(-1,0); break; case 'r': fire(1,0); break; case 'u': fire(0,-1); break; case 'd': fire(0,1); break; } } } break; case 'c': send("Current server implementation ignores password"); { const char *name = "anon"; const char *key = "no-password"; if (argc>=2) { name = argv[1]; } if (argc>=3) { key = argv[2]; } if (argc==3||1) { printf("LOGIN %s %s\n", name, key); bool ok = false; if (!isEmbodied()) { ok = login.apply(name,key); } if (!ok) { send("@error login failed"); } else { id = login.getID(); setName(name); setEnergy(10000); setLife(6000); setFirerange(4); send("@status login 1"); } } } break; default: send("@error command not understood"); //send("Known commands: \"look\" \"fire\" \"go left\" \"go right\" \"go up\" \"go down\""); break; } } game.post(); }
void NounShip::inflictDamage( dword nWhen, Noun * pFrom, int damage, dword type, const Vector3 & direction ) { if ( isDestroyed() ) // don't bother if ship is already destroyed! return; // only increase timer if an enemy is attacking us - we don't want to promote griefing if ( isEnemy( pFrom ) ) setOutOfCombat(); // update combat timer // if we are not the server, then halve the damage applied to avoid over estimatation the damage we are // inflicting on another ship.. if (! isServer() ) damage = damage * CLIENT_SIDE_DAMAGE; Facing eFacing = getFacing( atan2( direction.x, direction.z ), false ); // apply any damage modifiers damage = damage * calculateModifier( MT_DAMAGE_REDUCTION, true ); LOG_DEBUG_LOW( "NounShip", CharString().format("Damaged inflicted, When: %u, From: %s, Damage: %d, Type: 0x%X, Facing: %u", nWhen, pFrom != NULL ? pFrom->name() : "NULL", damage, type, eFacing) ); // callback so AI controlled ships can receive notification that they have been damaged by someone onAttacked( pFrom, damage, type ); // calculate the points we're going to award to the attacker now before shields/armor reduce // the damage applied to the hull. float fDamagePoints = float( damage ) / DAMAGE_POINTS_DIV; // check shields if( damage > 0 ) { for(int i=0;i<m_Shields.size();i++) damage = m_Shields[i]->deflect( type, damage, eFacing, direction ); } // check armor if ( damage > 0 ) { for(int i=0;i<m_Armor.size();i++) damage = m_Armor[i]->deflect( type, damage, eFacing ); } int internalDamage = damage; // inflict internal damage if hull is 50% or less int halfHull = maxDamage() >> 1; if ( damage > 0 && m_Damage > halfHull && (type & DAMAGE_EMP) == 0 ) { // once hull is under 50%, start causing internal damage type |= DAMAGE_EMP; // scale internal damage up based on how much under 50% the hull internalDamage = (damage * (m_Damage - halfHull)) / halfHull; } if ( damage > 0 && (type & (DAMAGE_EMP|DAMAGE_ELF)) ) { // get the radius of this ship float myRadius = radius(); ASSERT( myRadius > 0.0f ); // calculate the hit position in object space of this ship Vector3 hitPosition( direction ); hitPosition.normalize(); // direction is not normalized, it's the delta from the projectile/explosion, to the center of the ship hitPosition *= -(myRadius * 0.5f); // flip the direction so it goes away from the center of the ship if ( isServer() && m_Gadgets.size() > 0 ) { // seed with the time-stamp of the damage so we get the same gadget damaged // on all clients. srand( nWhen ); int nPicked = rand() % m_Gadgets.size(); NounGadget * pDamageGadget = m_Gadgets[ nPicked ]; if ( pDamageGadget != NULL ) { float fDistance = (pDamageGadget->position() - hitPosition).magnitude(); float fScale = (1.0f - (fDistance / myRadius)); if ( fScale > 0.0f ) pDamageGadget->inflictDamage( nWhen, pFrom, fScale * internalDamage, type, direction ); } } } if ( damage > 0 && (type & DAMAGE_ELF) ) { // drain energy from main energy bank int drained = Min( energy(), damage ); setEnergy( energy() - drained ); // give energy to attacking ship if ( WidgetCast<NounShip>( pFrom ) ) ((NounShip *)pFrom)->setEnergy( ((NounShip *)pFrom)->energy() + drained ); } // update the stats if it is another ship - NOTE this needs to happen before the DestroyShip // code below otherwise a player who is damaging this ship may not get credit/loot. if ( WidgetCast<NounShip>( pFrom ) ) { NounShip * pFromShip = (NounShip *)pFrom; ASSERT( pFromShip ); // set combat timer on attacking ship pFromShip->setOutOfCombat(); // non-hull damages gives a lessor percentage of points.. if ( damage <= 0 ) fDamagePoints *= NOHULL_DAMAGE_POINTS_SCALE; if (! isFriend( pFrom ) ) { // if the attacking ship is destroyed, then treat this as kamikaze points if ( pFromShip->isDestroyed() ) gameContext()->gameUser()->onKamikaze( pFrom, 1.0f ); else gameContext()->gameUser()->onDamageShip( pFrom, fDamagePoints, this); } else { gameContext()->gameUser()->onFriendlyFire( pFrom, fDamagePoints ); } } if ( damage > 0 && (type & (DAMAGE_KINETIC|DAMAGE_ENERGY)) ) { ASSERT( context() ); // cap the damage, damage = Min( maxDamage() - m_Damage, damage ); // add the damage to the hull m_Damage = Min( m_Damage + damage, maxDamage() ); // update the damage bits updateDamageBits(); // check if the ship was destroyed if ( isServer() && isDestroyed() ) { // ship is destroyed, send out verb to destroy this ship to all local clients Verb::Ref( new VerbDestroyShip( this, pFrom, false ) ); } } }
virtual Sensor * create ( Actor * a, ID id ) { Q_UNUSED( id ); Sensor * ret = new Sensor( a ); EXPECT_TRUE( setEnergy( ret, 10, 1 ) ); return ret; }
virtual Reflex * create ( Actor * a, ID id ) { Q_UNUSED( id ); Reflex * ret = new Reflex( a ); EXPECT_TRUE( setEnergy( ret, 10, 1 ) ); return ret; }
virtual Brain * create ( Actor * a, ID id ) { Q_UNUSED( id ); Brain * ret = new Brain( a ); EXPECT_TRUE( setEnergy( ret, 100, 5 ) ); return ret; }
VESPERSPersistentView::VESPERSPersistentView(QWidget *parent) : QWidget(parent) { // The shutter buttons. psh1_ = new CLSStopLightButton(qobject_cast<CLSBiStateControl *>(VESPERSBeamline::vespers()->photonShutter1())); connect(psh1_, SIGNAL(clicked()), this, SLOT(onPSH1Clicked())); psh2_ = new CLSStopLightButton(qobject_cast<CLSBiStateControl *>(VESPERSBeamline::vespers()->photonShutter2())); connect(psh2_, SIGNAL(clicked()), this, SLOT(onPSH2Clicked())); ssh1_ = new CLSStopLightButton(qobject_cast<CLSBiStateControl *>(VESPERSBeamline::vespers()->safetyShutter1())); connect(ssh1_, SIGNAL(clicked()), this, SLOT(onSSH1Clicked())); ssh2_ = new CLSStopLightButton(qobject_cast<CLSBiStateControl *>(VESPERSBeamline::vespers()->safetyShutter2())); connect(ssh2_, SIGNAL(clicked()), this, SLOT(onSSH2Clicked())); // Sample stage widget. pseudoMotors_ = new VESPERSSampleStageView(VESPERSBeamline::vespers()->pseudoSampleStage()); pseudoMotors_->setTitle("H & V"); pseudoMotors_->setHorizontalTitle("H"); pseudoMotors_->setVerticalTitle("V"); realMotors_ = new VESPERSSampleStageView(VESPERSBeamline::vespers()->realSampleStage()); realMotors_->setTitle("X & Z"); realMotors_->setHorizontalTitle("X"); realMotors_->setVerticalTitle("Z"); realMotors_->hide(); // PID control view widget. VESPERSPIDLoopControlView *pidView = new VESPERSPIDLoopControlView(VESPERSBeamline::vespers()->sampleStagePID()); connect(VESPERSBeamline::vespers()->sampleStagePID(), SIGNAL(stateChanged(bool)), pseudoMotors_, SLOT(setEnabled(bool))); connect(VESPERSBeamline::vespers()->sampleStagePID(), SIGNAL(stateChanged(bool)), realMotors_, SLOT(setEnabled(bool))); // The temperature control. temperature_ = VESPERSBeamline::vespers()->temperatureSet(); connect(temperature_, SIGNAL(controlSetValuesChanged()), this, SLOT(onTemperatureStateChanged())); // The pressure control. pressure_ = VESPERSBeamline::vespers()->pressureSet(); connect(pressure_, SIGNAL(controlSetValuesChanged()), this, SLOT(onPressureStateChanged())); // The flow switches. flowSwitches_ = VESPERSBeamline::vespers()->flowSwitchSet(); connect(flowSwitches_, SIGNAL(controlSetValuesChanged()), this, SLOT(onWaterStateChanged())); // The flow transducers. flowTransducers_ = VESPERSBeamline::vespers()->flowTransducerSet(); connect(flowTransducers_, SIGNAL(controlSetValuesChanged()), this, SLOT(onWaterStateChanged())); QFont font(this->font()); font.setBold(true); QLabel *pshShutterLabel = new QLabel("Front End Shutters"); pshShutterLabel->setFont(font); QLabel *sshShutterLabel = new QLabel("Beamline Shutters"); sshShutterLabel->setFont(font); QLabel *beamSelectionLabel = new QLabel("Beam Selection"); beamSelectionLabel->setFont(font); QLabel *slitsLabel = new QLabel("Intermediate Slit Gaps"); slitsLabel->setFont(font); QLabel *endstationShutterLabel = new QLabel("Endstation"); endstationShutterLabel->setFont(font); QLabel *statusLabel = new QLabel("Beamline Status"); statusLabel->setFont(font); QLabel *experimentReadyLabel = new QLabel("Experiment Ready Status"); experimentReadyLabel->setFont(font); QLabel *ionChamberLabel = new QLabel("Ion Chamber Calibration"); ionChamberLabel->setFont(font); // Shutter layout. QGridLayout *shutterLayout = new QGridLayout; shutterLayout->addWidget(pshShutterLabel, 0, 0, 1, 2); shutterLayout->addWidget(sshShutterLabel, 0, 2, 1, 2); shutterLayout->addWidget(psh1_); shutterLayout->addWidget(ssh1_); shutterLayout->addWidget(psh2_); shutterLayout->addWidget(ssh2_); // Beam selection and mono energy setting. VESPERSBeamSelectorView *beamSelectorView = new VESPERSBeamSelectorView; connect(VESPERSBeamline::vespers(), SIGNAL(currentBeamChanged(VESPERS::Beam)), this, SLOT(onBeamChanged(VESPERS::Beam))); // Energy (Eo) selection energySetpoint_ = new QDoubleSpinBox; energySetpoint_->setSuffix(" eV"); energySetpoint_->setMinimum(0); energySetpoint_->setMaximum(30000); energySetpoint_->setAlignment(Qt::AlignCenter); connect(energySetpoint_, SIGNAL(editingFinished()), this, SLOT(setEnergy())); connect(VESPERSBeamline::vespers()->mono(), SIGNAL(EoChanged(double)), this, SLOT(onEnergyChanged(double))); energyFeedback_ = new QLabel; energyFeedback_->setAlignment(Qt::AlignCenter); connect(VESPERSBeamline::vespers()->mono(), SIGNAL(energyChanged(double)), this, SLOT(onEnergyFeedbackChanged(double))); QHBoxLayout *energySetpointLayout = new QHBoxLayout; energySetpointLayout->addWidget(new QLabel("Energy:")); energySetpointLayout->addWidget(energySetpoint_); energySetpointLayout->addWidget(energyFeedback_); energySetpointLayout->setContentsMargins(15, 11, 11, 11); QVBoxLayout *beamSelectionLayout = new QVBoxLayout; beamSelectionLayout->addWidget(beamSelectionLabel); beamSelectionLayout->addWidget(beamSelectorView, 0, Qt::AlignCenter); beamSelectionLayout->addLayout(energySetpointLayout); // The intermediate slits. slits_ = VESPERSBeamline::vespers()->intermediateSlits(); xSlit_ = new QDoubleSpinBox; xSlit_->setSuffix(" mm"); xSlit_->setDecimals(3); xSlit_->setSingleStep(0.001); connect(slits_, SIGNAL(gapXChanged(double)), xSlit_, SLOT(setValue(double))); connect(xSlit_, SIGNAL(editingFinished()), this, SLOT(setXGap())); zSlit_ = new QDoubleSpinBox; zSlit_->setSuffix(" mm"); zSlit_->setDecimals(3); zSlit_->setSingleStep(0.001); connect(slits_, SIGNAL(gapZChanged(double)), zSlit_, SLOT(setValue(double))); connect(zSlit_, SIGNAL(editingFinished()), this, SLOT(setZGap())); QHBoxLayout *slitsLayout = new QHBoxLayout; slitsLayout->addWidget(new QLabel("H:"), 0, Qt::AlignRight); slitsLayout->addWidget(xSlit_); slitsLayout->addWidget(new QLabel("V:"), 0, Qt::AlignRight); slitsLayout->addWidget(zSlit_); slitsLayout->setContentsMargins(15, 11, 11, 11); // The Experiment Ready Status experimentReady_ = new QLabel; experimentReady_->setPixmap(QIcon(":/RED.png").pixmap(25)); connect(VESPERSBeamline::vespers()->experimentConfiguration(), SIGNAL(experimentReady(bool)), this, SLOT(onExperimentStatusChanged(bool))); QHBoxLayout *experimentReadyLayout = new QHBoxLayout; experimentReadyLayout->addWidget(experimentReady_); experimentReadyLayout->addWidget(experimentReadyLabel); experimentReadyLayout->setSpacing(10); experimentReadyLayout->setContentsMargins(15, 11, 11, 11); experimentReadyLayout->addStretch(); // Endstation shutter control. filterLowerButton_ = new QPushButton("Open Shutter"); filterLowerButton_->setCheckable(true); connect(filterLowerButton_, SIGNAL(clicked()), this, SLOT(toggleShutterState())); filterLabel_ = new QLabel; filterLabel_->setPixmap(QIcon(":/RED.png").pixmap(25)); connect(VESPERSBeamline::vespers()->endstation(), SIGNAL(shutterChanged(bool)), this, SLOT(onShutterStateChanged(bool))); // Setup the filters. filterComboBox_ = new QComboBox; filterComboBox_->addItem("None"); filterComboBox_->addItem(QString::fromUtf8("50 μm")); filterComboBox_->addItem(QString::fromUtf8("100 μm")); filterComboBox_->addItem(QString::fromUtf8("150 μm")); filterComboBox_->addItem(QString::fromUtf8("200 μm")); filterComboBox_->addItem(QString::fromUtf8("250 μm")); filterComboBox_->addItem(QString::fromUtf8("300 μm")); filterComboBox_->addItem(QString::fromUtf8("350 μm")); filterComboBox_->addItem(QString::fromUtf8("400 μm")); filterComboBox_->addItem(QString::fromUtf8("450 μm")); filterComboBox_->addItem(QString::fromUtf8("500 μm")); filterComboBox_->addItem(QString::fromUtf8("550 μm")); filterComboBox_->addItem(QString::fromUtf8("600 μm")); filterComboBox_->addItem(QString::fromUtf8("650 μm")); filterComboBox_->addItem(QString::fromUtf8("700 μm")); filterComboBox_->addItem(QString::fromUtf8("750 μm")); filterComboBox_->addItem(QString::fromUtf8("800 μm")); connect(filterComboBox_, SIGNAL(currentIndexChanged(int)), VESPERSBeamline::vespers()->endstation(), SLOT(setFilterThickness(int))); connect(VESPERSBeamline::vespers()->endstation(), SIGNAL(filterThicknessChanged(int)), this, SLOT(onFiltersChanged(int))); QHBoxLayout *filterLayout = new QHBoxLayout; filterLayout->addWidget(filterLabel_); filterLayout->addWidget(filterLowerButton_); filterLayout->addWidget(new QLabel("Filters:")); filterLayout->addWidget(filterComboBox_); filterLayout->setSpacing(5); filterLayout->setContentsMargins(15, 11, 11, 11); // The valve control. valvesButton_ = new QPushButton("Open Valves"); connect(valvesButton_, SIGNAL(clicked()), this, SLOT(onValvesButtonPushed())); valvesStatus_ = new QLabel; valvesStatus_->setPixmap(QIcon(":/RED.png").pixmap(25)); connect(VESPERSBeamline::vespers()->valveSet(), SIGNAL(controlSetValuesChanged()), this, SLOT(onValvesStateChanged())); QLabel *valveIcon = new QLabel; valveIcon->setPixmap(QIcon(":/valveIcon.png").pixmap(25)); valveIcon->setToolTip("Valve Indicator"); // Temp, water, and pressure labels. tempLabel_ = new QLabel; tempLabel_->setPixmap(QIcon(":/RED.png").pixmap(25)); QLabel *temperatureIcon = new QLabel; temperatureIcon->setPixmap(QIcon(":/ThermometerIcon.png").pixmap(25)); temperatureIcon->setToolTip("Temperature Indicator"); pressureLabel_ = new QLabel; pressureLabel_->setPixmap(QIcon(":/RED.png").pixmap(25)); QLabel *pressureIcon = new QLabel; pressureIcon->setPixmap(QIcon(":/PressureIcon.png").pixmap(25)); pressureIcon->setToolTip("Pressure Indicator"); waterLabel_ = new QLabel; waterLabel_->setPixmap(QIcon(":/RED.png").pixmap(25)); QLabel *waterIcon = new QLabel; waterIcon->setPixmap(QIcon(":/FaucetIcon.png").pixmap(25)); waterIcon->setToolTip("Water Indicator"); // Ion chambers. QVBoxLayout *ionChamberLayout = new QVBoxLayout; ionChamberLayout->addWidget(new CLSSplitIonChamberView(VESPERSBeamline::vespers()->iSplit())); ionChamberLayout->addWidget(new CLSIonChamberView(VESPERSBeamline::vespers()->iPreKB())); ionChamberLayout->addWidget(new CLSIonChamberView(VESPERSBeamline::vespers()->iMini())); ionChamberLayout->addWidget(new CLSIonChamberView(VESPERSBeamline::vespers()->iPost())); // Layout. QGridLayout *statusLayout = new QGridLayout; statusLayout->addWidget(temperatureIcon, 0, 0); statusLayout->addWidget(pressureIcon, 0, 1); statusLayout->addWidget(waterIcon, 0, 2); statusLayout->addWidget(valveIcon, 0, 3); statusLayout->addWidget(tempLabel_, 1, 0); statusLayout->addWidget(pressureLabel_, 1, 1); statusLayout->addWidget(waterLabel_, 1, 2); statusLayout->addWidget(valvesStatus_, 1, 3); statusLayout->addWidget(valvesButton_, 1, 4, 1, 2); statusLayout->setContentsMargins(15, 7, 11, 7); QHBoxLayout *sampleStageLayout = new QHBoxLayout; sampleStageLayout->addWidget(pseudoMotors_); sampleStageLayout->addWidget(realMotors_); QVBoxLayout *persistentLayout = new QVBoxLayout; persistentLayout->addLayout(shutterLayout); persistentLayout->addLayout(beamSelectionLayout); persistentLayout->addWidget(slitsLabel); persistentLayout->addLayout(slitsLayout); persistentLayout->addLayout(sampleStageLayout); persistentLayout->addWidget(pidView); persistentLayout->addLayout(experimentReadyLayout); persistentLayout->addWidget(endstationShutterLabel); persistentLayout->addLayout(filterLayout); persistentLayout->addWidget(ionChamberLabel); persistentLayout->addLayout(ionChamberLayout); persistentLayout->addWidget(statusLabel); persistentLayout->addLayout(statusLayout); persistentLayout->addStretch(); QGroupBox *vespersBox = new QGroupBox; vespersBox->setLayout(persistentLayout); QVBoxLayout *vespersLayout = new QVBoxLayout; vespersLayout->addWidget(vespersBox); setLayout(vespersLayout); //setFixedSize(325, 1000); setFixedSize(325, 900); // setFixedSize(325, 800); }
void Animal::Eat() { setEnergy(getEnergy() + 5); setWeight(getWeight() + 10); }
void Wizard::handleEvent(const SDL_Event& e) { if (!isAlive()) return; if (e.type == SDL_KEYDOWN && e.key.repeat == 0) { if (m_keep_action) return; SDL_Keycode key = e.key.keysym.sym; if (key == m_action_keys[ACTION_WALKUP]) { if (m_delta_y == 0) { m_delta_y = -m_step; m_state = STATE_WALKUP; } } else if (key == m_action_keys[ACTION_WALKDOWN]) { if (m_delta_y == 0) { m_delta_y = m_step; m_state = STATE_WALKDOWN; } } else if (key == m_action_keys[ACTION_WALKLEFT]) { if (m_delta_x == 0) { m_delta_x = -m_step; m_state = STATE_WALKLEFT; } } else if (key == m_action_keys[ACTION_WALKRIGHT]) { if (m_delta_x == 0) { m_delta_x = m_step; m_state = STATE_WALKRIGHT; } } else if (key == m_action_keys[ACTION_ATTACK]) { if (m_keep_state || getEnergy() < m_attack_cost) return; setEnergy(getEnergy() - m_attack_cost); if (m_state.isUp()) { m_state = STATE_ATTACKUP; } else if (m_state.isDown()) { m_state = STATE_ATTACKDOWN; } else if (m_state.isLeft()) { m_state = STATE_ATTACKLEFT; } else if (m_state.isRight()) { m_state = STATE_ATTACKRIGHT; } m_keep_action = true; m_keep_state = false; m_frame_counter.resetCounter(m_frame_number[m_state.get()], 4); } else if (key == m_action_keys[ACTION_SKILL]) { if (getEnergy() == getEnergyMax()) return; if (m_state.isUp()) { m_state = STATE_LOOKUP_SKILL; } else if (m_state.isDown()) { m_state = STATE_LOOKDOWN_SKILL; } else if (m_state.isLeft()) { m_state = STATE_LOOKLEFT_SKILL; } else if (m_state.isRight()) { m_state = STATE_LOOKRIGHT_SKILL; } m_keep_action = false; m_keep_state = true; m_state_prev = m_state; m_frame_counter.resetCounter(m_frame_number[m_state.get()]); } } else if (e.type == SDL_KEYUP && e.key.repeat == 0) { SDL_Keycode key = e.key.keysym.sym; if (key == m_action_keys[ACTION_WALKUP]) { if (m_delta_y < 0) { m_delta_y = 0; m_state = STATE_LOOKUP; } } else if (key == m_action_keys[ACTION_WALKDOWN]) { if (m_delta_y > 0) { m_delta_y = 0; m_state = STATE_LOOKDOWN; } } else if (key == m_action_keys[ACTION_WALKLEFT]) { if (m_delta_x < 0) { m_delta_x = 0; m_state = STATE_LOOKLEFT; } } else if (key == m_action_keys[ACTION_WALKRIGHT]) { if (m_delta_x > 0) { m_delta_x = 0; m_state = STATE_LOOKRIGHT; } } else if (key == m_action_keys[ACTION_SKILL]) { m_keep_state = false; } } if (m_keep_state) m_state = m_state_prev; }
void Turret::serverProcess (DWORD time) { Parent::serverProcess(time); if (data->isSustained == false) { if (!getControlClient() && getState () == StaticBase::Enabled && isActive()) { targetsTracked = 0; Player *closePlayer = chooseTarget (); if (targetsTracked) sleepTime = manager->getCurrentTime() + 3.0; if (closePlayer) { if (state == EXTENDED) trackAndFire (closePlayer, 0.032); else extend (0.032); } else if (!targetsTracked && manager->getCurrentTime() > sleepTime) { if (state != RETRACTED) { retract (0.032); } } } if (!getControlClient()) updateMove (NULL, 0.032); else updateSkip++; } else { switch (m_fireState) { case Waiting: { serverProcessWaiting(time); } break; case Firing: { serverProcessFiring(time); } break; case Reloading: { serverProcessReloading(time); } break; default: AssertFatal(0, "invalid state"); } if (m_fireState == Firing) { float e = getEnergy(); e -= data->energyRate * 0.032; if(e < 0.0) { unshoot(); e = 0.0; } setEnergy(e); } } }
void Turret::shoot (bool playerControlled, Player* targetPlayer) { if (data && data->isSustained == false) { if (data && data->projectile.type == -1) { if (!isGhost()) if (const char* script = scriptName("onFire")) Console->executef(2, script, scriptThis()); } else { float energy = getEnergy(); if (waitTime <= manager->getCurrentTime() && data && energy >= data->minGunEnergy && data->projectile.type != -1) { TMat3F muzzleTransform; getMuzzleTransform(0, &muzzleTransform); Projectile* bullet = createProjectile(data->projectile); if (!playerControlled && data->deflection) { static Random random; EulerF angles; muzzleTransform.angles (&angles); angles.x += (random.getFloat() - 0.5) * M_2PI * data->deflection; angles.z += (random.getFloat() - 0.5) * M_2PI * data->deflection; muzzleTransform.set (angles, muzzleTransform.p); } else if (playerControlled) { Point3F start = muzzleTransform.p; muzzleTransform = getEyeTransform (); aimedTransform (&muzzleTransform, start); muzzleTransform.p = start; } bullet->initProjectile (muzzleTransform, Point3F (0, 0, 0), getId()); if (bullet->isTargetable() == true) { if (targetPlayer != NULL) { if (GameBase* mo = targetPlayer->getMountObject()) bullet->setTarget(static_cast<ShapeBase*>(mo)); else bullet->setTarget(targetPlayer); } else if (playerControlled) { ShapeBase* pClosest = NULL; Point3F closeHisPos; float closestVal = -2.0f; SimSet::iterator itr; Point3F lookDir; getEyeTransform().getRow(1, &lookDir); lookDir.normalize(); SimContainerQuery collisionQuery; SimCollisionInfo info; collisionQuery.id = getId(); collisionQuery.type = -1; collisionQuery.mask = Projectile::csm_collisionMask; collisionQuery.detail = SimContainerQuery::DefaultDetail; collisionQuery.box.fMin = getEyeTransform().p; SimContainer* pRoot = (SimContainer*)manager->findObject(SimRootContainerId); SimSet* pSet = dynamic_cast<SimSet*>(manager->findObject(PlayerSetId)); AssertFatal(pSet != NULL, "No player set?"); for (itr = pSet->begin(); itr != pSet->end(); itr++) { Player* pPlayer = dynamic_cast<Player*>(*itr); if (!pPlayer || pPlayer->getVisibleToTeam(getTeam()) == false) continue; collisionQuery.box.fMax = pPlayer->getBoxCenter(); if (pRoot->findLOS(collisionQuery, &info, SimCollisionImageQuery::High) == true) { if (info.object != (SimObject*)pPlayer) continue; } Point3F hisPos = pPlayer->getBoxCenter(); hisPos -= getLinearPosition(); hisPos.normalize(); float prod = m_dot(hisPos, lookDir); if (prod > 0.0f && prod > closestVal) { closestVal = prod; pClosest = pPlayer; closeHisPos = hisPos; } } pSet = dynamic_cast<SimSet*>(manager->findObject(MoveableSetId)); AssertFatal(pSet != NULL, "No moveable set?"); for (itr = pSet->begin(); itr != pSet->end(); itr++) { if (((*itr)->getType() & VehicleObjectType) == 0) continue; ShapeBase* pObject = dynamic_cast<ShapeBase*>(*itr); if (pObject->getVisibleToTeam(getTeam()) == false) continue; collisionQuery.box.fMax = pObject->getBoxCenter(); if (pRoot->findLOS(collisionQuery, &info, SimCollisionImageQuery::High) == true) { if (info.object != (SimObject*)pObject) continue; } Point3F hisPos = pObject->getBoxCenter(); hisPos -= getLinearPosition(); hisPos.normalize(); float prod = m_dot(hisPos, lookDir); if (prod > 0.0f && prod > closestVal) { closestVal = prod; closeHisPos = hisPos; pClosest = pObject; } } // We need to find the current FOV, and take the percentage of // it specified in the .dat file for this turret. Only if the // do product is greater than this, do we allow the target to // be set... // float myFov = (fov / 2.0) * data->targetableFovRatio; float compCos = cos(myFov); if (compCos > 0.996f) // hack for single precision math. It's very compCos = 0.996; // hard to get more precise answers from the dot prod. if (pClosest != NULL && closestVal > compCos) bullet->setTarget(pClosest); } } if (data->maxGunEnergy) { float e; e = energy > data->maxGunEnergy ? data->maxGunEnergy : energy; float pofm = e / float(data->maxGunEnergy); bullet->setEnergy (e, pofm); energy -= e; setEnergy (energy); } SimGroup *grp = NULL; if(SimObject *obj = manager->findObject("MissionCleanup")) grp = dynamic_cast<SimGroup*>(obj); if(!manager->registerObject(bullet)) delete bullet; else { if(grp) grp->addObject(bullet); else manager->addObject(bullet); } waitTime = manager->getCurrentTime() + data->reloadDelay; if (animThread) { setFireThread (); animThread->SetPosition (0.0); } fireCount++; setMaskBits (ShootingMask); } } } else { if (data && data->projectile.type == -1) { if (!isGhost()) if (const char* script = scriptName("onFire")) Console->executef(2, script, scriptThis()); } else { float energy = getEnergy(); if (waitTime <= manager->getCurrentTime() && data && energy >= data->minGunEnergy && data->projectile.type != -1) { TMat3F muzzleTransform; getMuzzleTransform(0, &muzzleTransform); Projectile* bullet = createProjectile(data->projectile); if (!playerControlled && data->deflection) { static Random random; EulerF angles; muzzleTransform.angles (&angles); angles.x += (random.getFloat() - 0.5) * M_2PI * data->deflection; angles.z += (random.getFloat() - 0.5) * M_2PI * data->deflection; muzzleTransform.set (angles, muzzleTransform.p); } else if (playerControlled) { Point3F start = muzzleTransform.p; muzzleTransform = getEyeTransform (); aimedTransform (&muzzleTransform, start); muzzleTransform.p = start; } bullet->initProjectile (muzzleTransform, Point3F (0, 0, 0), getId()); AssertFatal(bullet->isSustained() == true, "Error, must be sustained bullet"); SimGroup *grp = NULL; if(SimObject *obj = manager->findObject("MissionCleanup")) grp = dynamic_cast<SimGroup*>(obj); if(!manager->registerObject(bullet)) delete bullet; else { if(grp) grp->addObject(bullet); else manager->addObject(bullet); } if (animThread) { setFireThread (); animThread->SetPosition (0.0); } fireCount++; setMaskBits (ShootingMask); m_fireState = Firing; m_beganState = wg->currentTime; m_pProjectile = bullet; m_pTarget = targetPlayer; if (m_pTarget) deleteNotify(m_pTarget); } } } }
int main() { //Boltzmann constant Units of [eV/K] static const double kB = 8.6173324E-5; //Planck constant Units of [eV s] static const double hbar = 6.58211928E-16; //printf("Value of fracSeed %e.\n",fracSeed); int attempts = 15; int rv; double SiteDistance = 1; //units of [nm] double AttemptToHop = 1E-13; double gamma = 2; //Units of [1/nm] int XElecOn = 1; int YElecOn = 0; int ZElecOn = 0; double reOrgEnergy = 1; double KT = 1; double MarcusJ0 = pow( AttemptToHop*hbar*pow(4*reOrgEnergy*kB*300/M_PI,1/2),1/2); //Calculating full Marcus Coefficient; double MarcusCoeff = pow(MarcusJ0,2)/hbar * pow(M_PI/(4*reOrgEnergy*KT),1/2)*exp(2*gamma*SiteDistance); ///////////////////////////////////////////////////////////////////////////////////////////////// //There should be no clusters //Case Study one clusters in the center Periodic int OrderLT; int OrderHT; int MidPtsTotalT; int PeriodicXT = 1; int PeriodicYT = 1; int PeriodicZT = 1; int XElecOnT = 1; int YElecOnT = 0; int ZElecOnT = 0; SNarray snAT = newSNarray( 3,4,3); //Create an artificial trap in snAT which in increment length is //length 0-2 width 0-3 and height 0-2 SiteNode snT = getSN(snAT,1,1,1); //printSNarray(snAT); rv = setEnergy(snT, -3); assert(rv==0); snT = getSN(snAT,1,2,1); rv = setEnergy(snT, -3); assert(rv==0); //printSNarray(snAT); //Testing Periodic x,y and z 0 biasX 0 biasY 0 biasZ KT=1 and reOrgEnergy=1 printf("\nCase Study T Periodic Conditions\n"); matrix mtxT = CalculateAllHops(snAT, 0,0,0, 1,1, SiteDistance,AttemptToHop,gamma,PeriodicXT, PeriodicYT, PeriodicZT); //printMatrix(mtxT); //Sorts all the data into midpoints ArbArray mpAT = MPsort( &OrderLT, &OrderHT, &MidPtsTotalT, mtxT, snAT, PeriodicXT, PeriodicYT, PeriodicZT); //Sorts midpoints into Nodes in link lists. Each element of mpAT is composed of a //link list all of the same order of magnitude //printf("Order Low %d Order High %d\n",OrderLT, OrderHT); //printf("oooooooooooooooooooooooooooooooooooooooooooo\n"); //printArbArray(mpAT); //printf("oooooooooooooooooooooooooooooooooooooooooooo\n"); ArbArray ArbT2 = SortOrderMag( OrderHT-OrderLT+1, OrderLT, mpAT); assert(ArbT2!=NULL); int TotalOrdersT = OrderHT-OrderLT+1; //Sorts nodes into clusters //printf("********************************************\n"); //printArbArray(ArbT2, OrderLT); //printf("********************************************\n"); ArbArray ArbT = ClusterSort( TotalOrdersT, OrderLT, ArbT2); //printf("TotalOrdersT %d OrderLowT %d Elements used by ArbT2 %d\n",TotalOrdersT, OrderLT, getElementsUsed(ArbT2)); assert(ArbT!=NULL); //Filtering Cluster rv = FilterCluster( TotalOrdersT, OrderLT, mtxT, &ArbT, snAT, PeriodicXT, PeriodicYT, PeriodicZT, XElecOnT, YElecOnT, ZElecOnT); assert(rv==0); //printf("****************CHECK***********************\n"); rv = PrintCheck( TotalOrdersT, OrderLT, ArbT, snAT, mtxT); //Because the cluster is smaller energy than the rest of the nodes the rest //of the nodes are not considered to be a cluster deleteArbArray(&ArbT2); /* //////////////////////////////////////////////////////////////////////////////////////// //Case Study no clusters Periodic int OrderLU; int OrderHU; int MidPtsTotalU; int PeriodicXU = 1; int PeriodicYU = 1; int PeriodicZU = 1; int XElecOnU = 1; int YElecOnU = 0; int ZElecOnU = 0; SNarray snAU = newSNarray( 3,4,3); //Create an artificial trap in snAT which in increment length is //length 0-2 width 0-3 and height 0-2 printSNarray(snAU); //Testing Periodic x,y and z 0 biasX 0 biasY 0 biasZ KT=1 and reOrgEnergy=1 matrix mtxU = CalculateAllHops(snAU, 0,0,0, 1,1, SiteDistance,AttemptToHop,gamma,PeriodicXU, PeriodicYU, PeriodicZU); printMatrix(mtxU); //Sorts all the data into midpoints ArbArray mpAU = MPsort( &OrderLU, &OrderHU, &MidPtsTotalU, mtxU, snAU, PeriodicXU, PeriodicYU, PeriodicZU); //Sorts midpoints into Nodes in link lists. Each element of mpAT is composed of a //link list all of the same order of magnitude printf("Order Low %d Order High %d\n",OrderLU, OrderHU); printf("oooooooooooooooooooooooooooooooooooooooooooo\n"); printArbArray(mpAU); printf("oooooooooooooooooooooooooooooooooooooooooooo\n"); ArbArray ArbU2 = SortOrderMag( OrderHU-OrderLU+1, OrderLU, mpAU); assert(ArbU2!=NULL); int TotalOrdersU = OrderHU-OrderLU+1; //Sorts nodes into clusters printf("********************************************\n"); printArbArray(ArbU2, OrderLU); printf("********************************************\n"); ArbArray ArbU = ClusterSort( TotalOrdersU, OrderLU, ArbU2); printf("TotalOrdersT %d OrderLowT %d Elements used by ArbT2 %d\n",TotalOrdersU, OrderLU, getElementsUsed(ArbU2)); printf("****************STARTING FILTER****************************\n"); assert(ArbU!=NULL); //Filtering Cluster rv = FilterCluster( TotalOrdersU, OrderLU, mtxU, &ArbU, snAU, PeriodicXU, PeriodicYU, PeriodicZU, XElecOnU, YElecOnU, ZElecOnU); assert(rv==0); printf("****************CHECK***********************\n"); rv = PrintCheck( TotalOrdersU, OrderLU, ArbU, snAU, mtxU); deleteArbArray(&ArbU2); deleteArbArray(&ArbU); deleteMatrix(mtxU); deleteSNarray(snAU); deleteAllMidPointArray(&mpAU); //Case Study two clusters in middle non periodic int OrderLS; int OrderHS; int MidPtsTotalS; int PeriodicXS = 0; int PeriodicYS = 0; int PeriodicZS = 0; int XElecOnS = 1; int YElecOnS = 0; int ZElecOnS = 0; SNarray snAS = newSNarray( 4, 3, 3); //Create Trap Sites SiteNode snS = getSN(snAS,2,1,1); printSNarray(snAS); rv = setEnergy(snS, -4); assert(rv==0); snS = getSN(snAS, 1,1,1); rv = setEnergy(snS, -4); assert(rv==0); printSNarray(snAS); //Testing non-periodic x, y and z 0 biasX 0 biasY 0 biasZ KT=0.024, and reOrgEnergy =1 matrix mtxS = CalculateAllHops(snAS, 0,0,0, 1, 1, SiteDistance,AttemptToHop,gamma,PeriodicXS, PeriodicYS, PeriodicZS); printMatrix(mtxS); ArbArray mpAS = MPsort( &OrderLS, &OrderHS, &MidPtsTotalS, mtxS, snAS, PeriodicXS, PeriodicYS, PeriodicZS); printf("Order Low %d Order High %d\n",OrderLS, OrderHS); printf("oooooooooooooooooooooooooooooooooooooooooooo\n"); printArbArray(mpAS); printf("oooooooooooooooooooooooooooooooooooooooooooo\n"); ArbArray ArbS2 = SortOrderMag( OrderHS-OrderLS+1, OrderLS, mpAS); assert(ArbS2!=NULL); int TotalOrdersS = OrderHS-OrderLS+1; printf("********************************************\n"); printArbArray(ArbS2, OrderLS); printf("********************************************\n"); ArbArray ArbS = ClusterSort( TotalOrdersS, OrderLS, ArbS2); printf("TotalOrdersS %d OrderLowS %d Elements used by ArbS2 %d\n",TotalOrdersS, OrderLS, getElementsUsed(ArbS2)); assert(ArbS!=NULL); printf("--------------------------------------------\n"); printArbArray(ArbS, OrderLS); printf("--------------------------------------------\n"); rv = FilterCluster( TotalOrdersS, OrderLS, mtxS, &ArbS, snAS, PeriodicXS, PeriodicYS, PeriodicZS, XElecOnS, YElecOnS, ZElecOnS); assert(rv==0); printf("****************CHECK***********************\n"); rv = PrintCheck( TotalOrdersS, OrderLS, ArbS, snAS, mtxS); deleteMatrix(mtxS); deleteSNarray(snAS); deleteArbArray(&ArbS); deleteAllMidPointArray(&mpAS); deleteArbArray(&ArbS2); //Case Study two cluster on oposite edges non periodic int OrderLR; int OrderHR; int MidPtsTotalR; int PeriodicXR = 0; int PeriodicYR = 0; int PeriodicZR = 0; int XElecOnR = 1; int YElecOnR = 0; int ZElecOnR = 0; SNarray snAR = newSNarray( 4, 3, 3); //Create Trap Sites one at the left electrode //One at the right electrode should not consider //any clusters in the sample SiteNode snR = getSN(snAR,0,1,1); printSNarray(snAR); rv = setEnergy(snR, -4); assert(rv==0); snS = getSN(snAR, 3,1,1); rv = setEnergy(snR, -4); assert(rv==0); printSNarray(snAR); //Testing non-periodic x, y and z 0 biasX 0 biasY 0 biasZ KT=0.024, and reOrgEnergy =1 matrix mtxR = CalculateAllHops(snAR, 0,0,0, 1, 1, SiteDistance,AttemptToHop,gamma,PeriodicXR, PeriodicYR, PeriodicZR); printMatrix(mtxR); ArbArray mpAR = MPsort( &OrderLR, &OrderHR, &MidPtsTotalR, mtxR, snAR, PeriodicXR, PeriodicYR, PeriodicZR); printf("Order Low %d Order High %d\n",OrderLR, OrderHR); printf("oooooooooooooooooooooooooooooooooooooooooooo\n"); printArbArray(mpAR); printf("oooooooooooooooooooooooooooooooooooooooooooo\n"); ArbArray ArbR2 = SortOrderMag( OrderHR-OrderLR+1, OrderLR, mpAR); assert(ArbR2!=NULL); int TotalOrdersR = OrderHR-OrderLR+1; printf("********************************************\n"); printArbArray(ArbR2, OrderLR); printf("********************************************\n"); ArbArray ArbR = ClusterSort( TotalOrdersR, OrderLR, ArbR2); printf("TotalOrdersR %d OrderLowR %d Elements used by ArbR2 %d\n",TotalOrdersR, OrderLR, getElementsUsed(ArbR2)); assert(ArbR!=NULL); printf("--------------------------------------------\n"); printArbArray(ArbR, OrderLR); printf("--------------------------------------------\n"); rv = FilterCluster( TotalOrdersR, OrderLR, mtxR, &ArbR, snAR, PeriodicXR, PeriodicYR, PeriodicZR, XElecOnR, YElecOnR, ZElecOnR); assert(rv==0); printf("****************CHECK***********************\n"); rv = PrintCheck( TotalOrdersR, OrderLR, ArbR, snAR, mtxR); deleteMatrix(mtxR); deleteSNarray(snAR); deleteAllMidPointArray(&mpAR); deleteArbArray(&ArbR2); deleteArbArray(&ArbR); //Case Study two cluster on oposite edges periodic in x int OrderLP; int OrderHP; int MidPtsTotalP; int PeriodicXP = 1; int PeriodicYP = 0; int PeriodicZP = 0; int XElecOnP = 1; int YElecOnP = 0; int ZElecOnP = 0; SNarray snAP = newSNarray( 4, 3, 3); //Create Trap Sites one at the left electrode //One at the right electrode should not consider //any clusters in the sample SiteNode snP = getSN(snAP,0,1,1); printSNarray(snAP); rv = setEnergy(snP, -4); assert(rv==0); snP = getSN(snAP, 3,1,1); rv = setEnergy(snP, -4); assert(rv==0); printSNarray(snAP); //Testing non-periodic x, y and z 0 biasX 0 biasY 0 biasZ KT=0.024, and reOrgEnergy =1 matrix mtxP = CalculateAllHops(snAP, 0,0,0, 1, 1, SiteDistance,AttemptToHop,gamma,PeriodicXP, PeriodicYP, PeriodicZP); printMatrix(mtxP); ArbArray mpAP = MPsort( &OrderLP, &OrderHP, &MidPtsTotalP, mtxP, snAP, PeriodicXP, PeriodicYP, PeriodicZP); printf("Order Low %d Order High %d\n",OrderLP, OrderHP); printf("oooooooooooooooooooooooooooooooooooooooooooo\n"); printArbArray(mpAP); printf("oooooooooooooooooooooooooooooooooooooooooooo\n"); ArbArray ArbP2 = SortOrderMag( OrderHP-OrderLP+1, OrderLP, mpAP); assert(ArbP2!=NULL); int TotalOrdersP = OrderHP-OrderLP+1; printf("********************************************\n"); printArbArray(ArbP2, OrderLP); printf("********************************************\n"); ArbArray ArbP = ClusterSort( TotalOrdersP, OrderLP, ArbP2); printf("TotalOrdersR %d OrderLowR %d Elements used by ArbR2 %d\n",TotalOrdersP, OrderLP, getElementsUsed(ArbP2)); assert(ArbP!=NULL); printf("--------------------------------------------\n"); printArbArray(ArbP, OrderLP); printf("--------------------------------------------\n"); rv = FilterCluster( TotalOrdersP, OrderLP, mtxP, &ArbP, snAP, PeriodicXP, PeriodicYP, PeriodicZP, XElecOnP, YElecOnP, ZElecOnP); assert(rv==0); printf("****************CHECK***********************\n"); rv = PrintCheck( TotalOrdersP, OrderLP, ArbP, snAP, mtxP); deleteArbArray(&ArbP2); //Case Study two cluster on oposite edges periodic in y int OrderLO; int OrderHO; int MidPtsTotalO; int PeriodicXO = 0; int PeriodicYO = 1; int PeriodicZO = 0; int XElecOnO = 1; int YElecOnO = 0; int ZElecOnO = 0; SNarray snAO = newSNarray( 4, 3, 3); //Create Trap Sites one at the left electrode //One at the right electrode should not consider //any clusters in the sample SiteNode snO = getSN(snAO,1,0,1); printSNarray(snAO); rv = setEnergy(snO, -4); assert(rv==0); snO = getSN(snAO, 1,2,1); rv = setEnergy(snO, -4); assert(rv==0); printSNarray(snAO); //Testing non-periodic x, y and z 0 biasX 0 biasY 0 biasZ KT=0.024, and reOrgEnergy =1 matrix mtxO = CalculateAllHops(snAO, 0,0,0, 1, 1, SiteDistance,AttemptToHop,gamma,PeriodicXO, PeriodicYO, PeriodicZO); printMatrix(mtxO); ArbArray mpAO = MPsort( &OrderLO, &OrderHO, &MidPtsTotalO, mtxO, snAO, PeriodicXO, PeriodicYO, PeriodicZO); printf("Order Low %d Order High %d\n",OrderLO, OrderHO); printf("oooooooooooooooooooooooooooooooooooooooooooo\n"); printArbArray(mpAO); printf("oooooooooooooooooooooooooooooooooooooooooooo\n"); ArbArray ArbO2 = SortOrderMag( OrderHO-OrderLO+1, OrderLO, mpAO); assert(ArbO2!=NULL); int TotalOrdersO = OrderHO-OrderLO+1; printf("********************************************\n"); printArbArray(ArbO2, OrderLO); printf("********************************************\n"); ArbArray ArbO = ClusterSort( TotalOrdersO, OrderLO, ArbO2); printf("TotalOrdersR %d OrderLowR %d Elements used by ArbR2 %d\n",TotalOrdersP, OrderLO, getElementsUsed(ArbO2)); assert(ArbO!=NULL); printf("--------------------------------------------\n"); printArbArray(ArbO, OrderLO); printf("--------------------------------------------\n"); rv = FilterCluster( TotalOrdersP, OrderLO, mtxO, &ArbO, snAO, PeriodicXO, PeriodicYO, PeriodicZO, XElecOnO, YElecOnO, ZElecOnO); assert(rv==0); printf("****************CHECK***********************\n"); rv = PrintCheck( TotalOrdersO, OrderLO, ArbO, snAO, mtxO); deleteArbArray(&ArbO2); //Case Study two cluster on oposite edges non-periodic in y int OrderLM; int OrderHM; int MidPtsTotalM; int PeriodicXM = 0; int PeriodicYM = 0; int PeriodicZM = 0; int XElecOnM = 1; int YElecOnM = 0; int ZElecOnM = 0; SNarray snAM = newSNarray( 4, 3, 3); //Create Trap Sites one at the left electrode //One at the right electrode should not consider //any clusters in the sample SiteNode snM = getSN(snAM,1,0,1); printSNarray(snAM); rv = setEnergy(snM, -4); assert(rv==0); snM = getSN(snAM, 1,2,1); rv = setEnergy(snM, -4); assert(rv==0); printSNarray(snAM); //Testing non-periodic x, y and z 0 biasX 0 biasY 0 biasZ, KT=0.024, and reOrgEnergy =1 matrix mtxM = CalculateAllHops(snAM, 0,0,0, 1, 1, SiteDistance,AttemptToHop,gamma,PeriodicXM, PeriodicYM, PeriodicZM); printMatrix(mtxM); ArbArray mpAM = MPsort( &OrderLM, &OrderHM, &MidPtsTotalM, mtxM, snAM, PeriodicXM, PeriodicYM, PeriodicZM); printf("Order Low %d Order High %d\n",OrderLM, OrderHM); printf("oooooooooooooooooooooooooooooooooooooooooooo\n"); printArbArray(mpAM); printf("oooooooooooooooooooooooooooooooooooooooooooo\n"); ArbArray ArbM2 = SortOrderMag( OrderHM-OrderLM+1, OrderLM, mpAM); assert(ArbM2!=NULL); int TotalOrdersM = OrderHM-OrderLM+1; printf("********************************************\n"); printArbArray(ArbM2, OrderLM); printf("********************************************\n"); ArbArray ArbM = ClusterSort( TotalOrdersM, OrderLM, ArbM2); printf("TotalOrdersR %d OrderLowR %d Elements used by ArbR2 %d\n",TotalOrdersM, OrderLM, getElementsUsed(ArbM2)); assert(ArbM!=NULL); printf("--------------------------------------------\n"); printArbArray(ArbM, OrderLM); printf("--------------------------------------------\n"); rv = FilterCluster( TotalOrdersM, OrderLM, mtxM, &ArbM, snAM, PeriodicXM, PeriodicYM, PeriodicZM, XElecOnM, YElecOnM, ZElecOnM); assert(rv==0); printf("****************CHECK M***********************\n"); rv = PrintCheck( TotalOrdersM, OrderLM, ArbM, snAM, mtxM); deleteArbArray(&ArbM2); //Case Study two cluster on oposite edges periodic in z int OrderLN; int OrderHN; int MidPtsTotalN; int PeriodicXN = 0; int PeriodicYN = 0; int PeriodicZN = 0; int XElecOnN = 1; int YElecOnN = 0; int ZElecOnN = 0; SNarray snAN = newSNarray( 4, 3, 3); //Create Trap Sites one at the left electrode //One at the right electrode should not consider //any clusters in the sample SiteNode snN = getSN(snAN,1,1,0); printSNarray(snAN); rv = setEnergy(snN, -4); assert(rv==0); snN = getSN(snAN, 1,1,2); rv = setEnergy(snN, -4); assert(rv==0); printSNarray(snAN); //Testing non-periodic x, y and z 0 biasX, 0 biasY, 0 biasZ KT=0.024, and reOrgEnergy =1 matrix mtxN = CalculateAllHops(snAN, 0,0,0, 1, 1, SiteDistance,AttemptToHop,gamma,PeriodicXN, PeriodicYN, PeriodicZN); printMatrix(mtxN); ArbArray mpAN = MPsort( &OrderLN, &OrderHN, &MidPtsTotalN, mtxN, snAN, PeriodicXN, PeriodicYN, PeriodicZN); printf("Order Low %d Order High %d\n",OrderLN, OrderHN); printf("oooooooooooooooooooooooooooooooooooooooooooo\n"); printArbArray(mpAN); printf("oooooooooooooooooooooooooooooooooooooooooooo\n"); ArbArray ArbN2 = SortOrderMag( OrderHN-OrderLN+1, OrderLN, mpAN); assert(ArbN2!=NULL); int TotalOrdersN = OrderHN-OrderLN+1; printf("********************************************\n"); printArbArray(ArbN2, OrderLN); printf("********************************************\n"); ArbArray ArbN = ClusterSort( TotalOrdersN, OrderLN, ArbN2); printf("TotalOrdersR %d OrderLowR %d Elements used by ArbR2 %d\n",TotalOrdersN, OrderLN, getElementsUsed(ArbN2)); assert(ArbN!=NULL); printf("--------------------------------------------\n"); printArbArray(ArbN, OrderLN); printf("--------------------------------------------\n"); rv = FilterCluster( TotalOrdersN, OrderLN, mtxN, &ArbN, snAN, PeriodicXN, PeriodicYN, PeriodicZN, XElecOnN, YElecOnN, ZElecOnN); assert(rv==0); printf("****************CHECK N***********************\n"); rv = PrintCheck( TotalOrdersN, OrderLN, ArbN, snAN, mtxN); deleteArbArray(&ArbN2); //Case Study two cluster on oposite edges periodic in z int OrderLK; int OrderHK; int MidPtsTotalK; int PeriodicXK = 0; int PeriodicYK = 0; int PeriodicZK = 1; int XElecOnK = 1; int YElecOnK = 0; int ZElecOnK = 0; SNarray snAK = newSNarray( 4, 3, 3); //Create Trap Sites one at the left electrode //One at the right electrode should not consider //any clusters in the sample SiteNode snK = getSN(snAK,1,1,0); printSNarray(snAK); rv = setEnergy(snK, -4); assert(rv==0); snK = getSN(snAK, 1,1,2); rv = setEnergy(snK, -4); assert(rv==0); printSNarray(snAK); //Testing non-periodic x, y and z 0 biasX 0 biasY 0 biasZ KT=0.024, and reOrgEnergy =1 matrix mtxK = CalculateAllHops(snAK, 0,0,0, 1, 1, SiteDistance,AttemptToHop,gamma,PeriodicXK, PeriodicYK, PeriodicZK); printMatrix(mtxK); ArbArray mpAK = MPsort( &OrderLK, &OrderHK, &MidPtsTotalK, mtxK, snAK, PeriodicXK, PeriodicYK, PeriodicZK); printf("Order Low %d Order High %d\n",OrderLK, OrderHK); printf("oooooooooooooooooooooooooooooooooooooooooooo\n"); printArbArray(mpAK); printf("oooooooooooooooooooooooooooooooooooooooooooo\n"); ArbArray ArbK2 = SortOrderMag( OrderHK-OrderLK+1, OrderLK, mpAK); assert(ArbK2!=NULL); int TotalOrdersK = OrderHK-OrderLK+1; printf("********************************************\n"); printArbArray(ArbK2, OrderLK); printf("********************************************\n"); ArbArray ArbK = ClusterSort( TotalOrdersK, OrderLK, ArbK2); printf("TotalOrdersR %d OrderLowR %d Elements used by ArbR2 %d\n",TotalOrdersK, OrderLK, getElementsUsed(ArbK2)); assert(ArbK!=NULL); printf("--------------------------------------------\n"); printArbArray(ArbK, OrderLK); printf("--------------------------------------------\n"); rv = FilterCluster( TotalOrdersK, OrderLK, mtxK, &ArbK, snAK, PeriodicXK, PeriodicYK, PeriodicZK, XElecOnK, YElecOnK, ZElecOnK); assert(rv==0); printf("****************CHECK K***********************\n"); rv = PrintCheck( TotalOrdersK, OrderLK, ArbK, snAK, mtxK); deleteArbArray(&ArbK2); //Case Study periodic conditions percolation pathway across sample int OrderLJ; int OrderHJ; int MidPtsTotalJ; int PeriodicXJ = 1; int PeriodicYJ = 1; int PeriodicZJ = 1; int XElecOnJ = 1; int YElecOnJ = 0; int ZElecOnJ = 0; SNarray snAJ = newSNarray( 4, 3, 3); //Create Trap Sites that cross the sample SiteNode snJ = getSN(snAJ,0,1,1); printSNarray(snAJ); rv = setEnergy(snJ, -4); assert(rv==0); snJ = getSN(snAJ, 1,1,1); rv = setEnergy(snJ, -4); assert(rv==0); snJ = getSN(snAJ, 2,1,1); rv = setEnergy(snJ, -4); assert(rv==0); snJ = getSN(snAJ, 3, 1, 1); rv = setEnergy(snJ, -4); assert(rv==0); printSNarray(snAJ); //Testing non-periodic x, y and z 0 biasX 0 biasY 0 biasZ KT=0.024, and reOrgEnergy =1 matrix mtxJ = CalculateAllHops(snAJ, 0, 0,0,1, 1, SiteDistance,AttemptToHop,gamma,PeriodicXJ, PeriodicYJ, PeriodicZJ); printMatrix(mtxJ); ArbArray mpAJ = MPsort( &OrderLJ, &OrderHJ, &MidPtsTotalJ, mtxJ, snAJ, PeriodicXJ, PeriodicYJ, PeriodicZJ); printf("Order Low %d Order High %d\n",OrderLJ, OrderHJ); printf("oooooooooooooooooooooooooooooooooooooooooooo\n"); printArbArray(mpAJ); printf("oooooooooooooooooooooooooooooooooooooooooooo\n"); ArbArray ArbJ2 = SortOrderMag( OrderHJ-OrderLJ+1, OrderLJ, mpAJ); assert(ArbJ2!=NULL); int TotalOrdersJ = OrderHJ-OrderLJ+1; printf("********************************************\n"); printArbArray(ArbJ2, OrderLJ); printf("********************************************\n"); ArbArray ArbJ = ClusterSort( TotalOrdersJ, OrderLJ, ArbJ2); printf("TotalOrdersR %d OrderLowR %d Elements used by ArbR2 %d\n",TotalOrdersJ, OrderLJ, getElementsUsed(ArbJ2)); assert(ArbJ!=NULL); printf("--------------------------------------------\n"); printArbArray(ArbJ, OrderLJ); printf("--------------------------------------------\n"); rv = FilterCluster( TotalOrdersJ, OrderLJ, mtxJ, &ArbJ, snAJ, PeriodicXJ, PeriodicYJ, PeriodicZJ, XElecOnJ, YElecOnJ, ZElecOnJ); assert(rv==0); printf("****************CHECJ***********************\n"); rv = PrintCheck( TotalOrdersJ, OrderLJ, ArbJ, snAJ, mtxJ); printf("****************CHECK J NeighNodes*********************\n"); rv = CalculateNeighNodes(TotalOrdersJ, OrderLJ, &ArbJ, snAJ, PeriodicXJ, PeriodicYJ, PeriodicZJ); assert(rv==0); rv = PrintCheck( TotalOrdersJ, OrderLJ, ArbJ, snAJ, mtxJ); deleteArbArray(&ArbJ2); printf("****************CHECK K NeighNodes*********************\n"); //SNarray snAK = newSNarray( 4, 3, 3); //int PeriodicXK = 0; //int PeriodicYK = 0; //int PeriodicZK = 1; //SiteNode snK = getSN(snAK,1,1,0); //snK = getSN(snAK, 1,1,2); rv = PrintCheck( TotalOrdersK, OrderLK, ArbK, snAK, mtxK); rv = CalculateNeighNodes(TotalOrdersK, OrderLK, &ArbK, snAK, PeriodicXK, PeriodicYK, PeriodicZK); assert(rv==0); rv = PrintCheck( TotalOrdersK, OrderLK, ArbK, snAK, mtxK); deleteAllMidPointArray(&mpAK); deleteMatrix(mtxK); deleteSNarray(snAK); deleteArbArray(&ArbK); printf("****************CHECK M NeighNodes*********************\n"); //int PeriodicXM = 0; //int PeriodicYM = 0; //int PeriodicZM = 0; //SNarray snAM = newSNarray( 4, 3, 3); //SiteNode snM = getSN(snAM,1,0,1); //snM = getSN(snAM, 1,2,1); rv = PrintCheck( TotalOrdersM, OrderLM, ArbM, snAM, mtxM); rv = CalculateNeighNodes(TotalOrdersM, OrderLM, &ArbM, snAM, PeriodicXM, PeriodicYM, PeriodicZM); assert(rv==0); rv = PrintCheck( TotalOrdersM, OrderLM, ArbM, snAM, mtxM); printf("****************CHECK N NeighNodes*********************\n"); //int PeriodicXN = 0; //int PeriodicYN = 0; //int PeriodicZN = 0; //SNarray snAN = newSNarray( 4, 3, 3); //SiteNode snN = getSN(snAN,1,1,0); //snN = getSN(snAN, 1,1,2); rv = PrintCheck( TotalOrdersN, OrderLN, ArbN, snAN, mtxN); rv = CalculateNeighNodes(TotalOrdersN, OrderLN, &ArbN, snAN, PeriodicXN, PeriodicYN, PeriodicZN); assert(rv==0); rv = PrintCheck( TotalOrdersN, OrderLN, ArbN, snAN, mtxN); printf("****************CHECK O NeighNodes*********************\n"); //int PeriodicXO = 0; //int PeriodicYO = 1; //int PeriodicZO = 0; //SNarray snAO = newSNarray( 4, 3, 3); //SiteNode snO = getSN(snAO,1,0,1); //snO = getSN(snAO, 1,2,1); rv = PrintCheck( TotalOrdersO, OrderLO, ArbO, snAO, mtxO); rv = CalculateNeighNodes(TotalOrdersO, OrderLO, &ArbO, snAO, PeriodicXO, PeriodicYO, PeriodicZO); assert(rv==0); rv = PrintCheck( TotalOrdersO, OrderLO, ArbO, snAO, mtxO); printf("****************CHECK P NeighNodes*********************\n"); //int PeriodicXP = 1; //int PeriodicYP = 0; //int PeriodicZP = 0; //SNarray snAP = newSNarray( 4, 3, 3); //SiteNode snP = getSN(snAP,1,1,1); //snP = getSN(snAP, 1,2,1); rv = PrintCheck( TotalOrdersP, OrderLP, ArbP, snAP, mtxP); rv = CalculateNeighNodes(TotalOrdersP, OrderLP, &ArbP, snAP, PeriodicXP, PeriodicYP, PeriodicZP); assert(rv==0); rv = PrintCheck( TotalOrdersP, OrderLP, ArbP, snAP, mtxP); printf("****************CHECK T NeighNodes*********************\n"); //int PeriodicXT = 1; //int PeriodicYT = 1; //int PeriodicZT = 1; //SNarray snAP = newSNarray( 3, 4, 3); //SiteNode snP = getSN(snAP,0,1,1); //snP = getSN(snAP, 3,1,1); rv = PrintCheck( TotalOrdersT, OrderLT, ArbT, snAT, mtxT); rv = CalculateNeighNodes(TotalOrdersT, OrderLT, &ArbT, snAT, PeriodicXT, PeriodicYT, PeriodicZT); assert(rv==0); rv = PrintCheck( TotalOrdersT, OrderLT, ArbT, snAT, mtxT); printf("****************Calculate Pval J*********************\n"); rv = PrintCheck( TotalOrdersJ, OrderLJ, ArbJ, snAJ, mtxJ); rv = CalculateSumAndP(TotalOrdersJ, snAJ, &ArbJ, mtxJ, attempts, PeriodicXJ, PeriodicYJ, PeriodicZJ); printf("\n** After Run **\n"); rv = PrintCheck( TotalOrdersJ, OrderLJ, ArbJ, snAJ, mtxJ); printf("****************Calculate Pval M*********************\n"); //int PeriodicXM = 0; //int PeriodicYM = 0; //int PeriodicZM = 0; //SNarray snAM = newSNarray( 4, 3, 3); //SiteNode snM = getSN(snAM,1,0,1); //snM = getSN(snAM, 1,2,1); rv = PrintCheck( TotalOrdersM, OrderLM, ArbM, snAM, mtxM); printMatrix(mtxM); rv = CalculateSumAndP(TotalOrdersM, snAM, &ArbM, mtxM, attempts, PeriodicXM, PeriodicYM, PeriodicZM); printf("\n** After Run **\n"); rv = PrintCheck( TotalOrdersM, OrderLM, ArbM, snAM, mtxM); deleteAllMidPointArray(&mpAM); deleteMatrix(mtxM); deleteSNarray(snAM); deleteArbArray(&ArbM); printf("****************Calculate Pval N*********************\n"); //int PeriodicXN = 0; //int PeriodicYN = 0; //int PeriodicZN = 0; //SNarray snAN = newSNarray( 4, 3, 3); //SiteNode snN = getSN(snAN,1,1,0); //snN = getSN(snAN, 1,1,2); rv = PrintCheck( TotalOrdersN, OrderLN, ArbN, snAN, mtxN); printMatrix(mtxN); rv = CalculateSumAndP(TotalOrdersN, snAN, &ArbN, mtxN, attempts, PeriodicXN, PeriodicYN, PeriodicZN); printf("\n** After Run **\n"); rv = PrintCheck( TotalOrdersN, OrderLN, ArbN, snAN, mtxN); deleteAllMidPointArray(&mpAN); deleteMatrix(mtxN); deleteSNarray(snAN); deleteArbArray(&ArbN); printf("****************Calculate Pval O*********************\n"); //int PeriodicXO = 0; //int PeriodicYO = 1; //int PeriodicZO = 0; //SNarray snAO = newSNarray( 4, 3, 3); //SiteNode snO = getSN(snAO,1,0,1); //snO = getSN(snAO, 1,2,1); rv = PrintCheck( TotalOrdersO, OrderLO, ArbO, snAO, mtxO); printMatrix(mtxO); rv = CalculateSumAndP(TotalOrdersO, snAO, &ArbO, mtxO, attempts, PeriodicXO, PeriodicYO, PeriodicZO); printf("\n** After Run **\n"); rv = PrintCheck( TotalOrdersO, OrderLO, ArbO, snAO, mtxO); printf("\nPrintArb Array\n"); printArbArray(ArbO,OrderLO); printf("****************Calculate Pval P*********************\n"); //int PeriodicXP = 1; //int PeriodicYP = 0; //int PeriodicZP = 0; //SNarray snAP = newSNarray( 4, 3, 3); //SiteNode snP = getSN(snAP,0,1,1); //snP = getSN(snAP, 3,1,1); //Periodic in the X rv = PrintCheck( TotalOrdersP, OrderLP, ArbP, snAP, mtxP); printMatrix(mtxP); rv = CalculateSumAndP(TotalOrdersP, snAP, &ArbP, mtxP, attempts, PeriodicXP, PeriodicYP, PeriodicZP); printf("\n** After Run **\n"); rv = PrintCheck( TotalOrdersP, OrderLP, ArbP, snAP, mtxP); printf("****************Calculate Pval T*********************\n"); if(ArbT==NULL){ printf("Arb T is NULL\n"); }else if(snAT==NULL){ printf("snAT is NULL\n"); }else if(mtxT==NULL){ printf("mtxT is NULL\n"); } printf("Total Orders %d OrderL %d\n",TotalOrdersT, OrderLT); rv = PrintCheck( TotalOrdersT, OrderLT, ArbT, snAT, mtxT); printf("Printing Matrix T\n"); printMatrix(mtxT); rv = CalculateSumAndP(TotalOrdersT, snAT, &ArbT, mtxT, attempts, PeriodicXT, PeriodicYT, PeriodicZT); printf("\n** After Run **\n"); rv = PrintCheck( TotalOrdersT, OrderLT, ArbT, snAT, mtxT); printf("PrintArb Array\n"); printArbArray(ArbT,OrderLT); deleteAllMidPointArray(&mpAT); deleteMatrix(mtxT); deleteSNarray(snAT); deleteArbArray(&ArbT); printf("***************Connect Cluster J Check*****************\n"); //int PeriodicXJ = 1; //int PeriodicYJ = 1; //int PeriodicZJ = 1; //SNarray snAJ = newSNarray( 4, 3, 3); //Create Trap Sites that cross the sample //SiteNode snJ = getSN(snAJ,0,1,1); //snJ = getSN(snAJ, 1,1,1); //snJ = getSN(snAJ, 2,1,1); //snJ = getSN(snAJ, 3, 1, 1); rv = ConnectClusterSN( TotalOrdersJ, snAJ, ArbJ); printSNarray(snAJ); printf("***************Connect Cluster O Check*****************\n"); //int PeriodicXO = 0; //int PeriodicYO = 1; //int PeriodicZO = 0; //SNarray snAO = newSNarray( 4, 3, 3); //SiteNode snO = getSN(snAO,1,0,1); //snO = getSN(snAO, 1,2,1); rv = ConnectClusterSN( TotalOrdersO, snAO, ArbO); printSNarray(snAO); deleteAllMidPointArray(&mpAO); deleteMatrix(mtxO); deleteSNarray(snAO); deleteArbArray(&ArbO); printf("***************FindCluster J Check*****************\n"); //int PeriodicXJ = 1; //int PeriodicYJ = 1; //int PeriodicZJ = 1; //SNarray snAJ = newSNarray( 4, 3, 3); //Create Trap Sites that cross the sample //SiteNode snJ = getSN(snAJ,0,1,1); //snJ = getSN(snAJ, 1,1,1); //snJ = getSN(snAJ, 2,1,1); //snJ = getSN(snAJ, 3, 1, 1); ParameterFrame PF = newParamFrame(); PFset_AttemptToHop(PF,AttemptToHop); PFset_gamma(PF,gamma); PFset_Px(PF,PeriodicXJ); PFset_Py(PF,PeriodicYJ); PFset_Pz(PF,PeriodicZJ); PFset_XElecOn(PF,XElecOnJ); PFset_YElecOn(PF,YElecOnJ); PFset_ZElecOn(PF,ZElecOnJ); PFset_Attempts(PF,15); PFset_reOrg(PF,1); PFset_MovieFrames(PF,10); PFset_SiteDist(PF,SiteDistance); ArbArray ClArLLJJ; rv = FindCluster( &OrderLJ, snAJ, 0,0,0, &ClArLLJJ, 1,PF); printf("\nOld\n"); printArbArray(ArbJ,OrderLJ); printf("\nNew\n"); printArbArray(ClArLLJJ, OrderLJ); deleteAllMidPointArray(&mpAJ); deleteMatrix(mtxJ); deleteSNarray(snAJ); deleteArbArray(&ArbJ); deleteArbArray(&ClArLLJJ); printf("***************FindCluster P Check*****************\n"); //int PeriodicXP = 1; //int PeriodicYP = 0; //int PeriodicZP = 0; //SNarray snAP = newSNarray( 4, 3, 3); //SiteNode snP = getSN(snAP,0,1,1); PFset_Px(PF,PeriodicXJ); PFset_Py(PF,PeriodicYJ); PFset_Pz(PF,PeriodicZJ); PFset_XElecOn(PF,XElecOnJ); PFset_YElecOn(PF,YElecOnJ); PFset_ZElecOn(PF,ZElecOnJ); //snP = getSN(snAP, 3,1,1); char FileName[] = "Data"; ArbArray ClArLLPP; rv = FindCluster( &OrderLP, snAP, 0,0,0, &ClArLLPP, 1, PF); printArbArray(ClArLLPP); //rv = SaveCluster( FileName,OrderLP, snAP, 0.0,0.0,0.0, ClArLLPP, 1.0, PF); printf("\nOld\n"); printArbArray(ArbP,OrderLP); printf("\nNew\n"); printArbArray(ClArLLPP, OrderLP); deleteAllMidPointArray(&mpAP); deleteMatrix(mtxP); deleteSNarray(snAP); deleteArbArray(&ArbP); deleteArbArray(&ClArLLPP); deleteParamFrame(&PF); double electricEnergyPx; double electricEnergyPy; double electricEnergyPz; double KbT; LoadCluster( FileName, &OrderLP, &snAP,&electricEnergyPx,&electricEnergyPy,&electricEnergyPz,&ClArLLPP,&KbT,&PF); printSNarray_Detailed(snAP); deleteSNarray(snAP); deleteArbArray(&ClArLLPP); deleteParamFrame(&PF); int OrderLB; int OrderHB; int MidPtsTotalB; int PeriodicXB = 1; int PeriodicYB = 1; int PeriodicZB = 1; int XElecOnB = 1; int YElecOnB = 0; int ZElecOnB = 0; SNarray snAB = newSNarray( 3,4,3); //Create an artificial trap in snAB which in increment length is //length 0-2 width 0-3 and height 0-2 SiteNode snB = getSN(snAB,1,1,1); rv = setEnergy(snB, -3); snB = getSN(snAB,1,2,1); rv = setEnergy(snB, -3); //Testing Periodic x,y and z 0 biasX 0 biasY 0 biasZ KT=1 and reOrgEnergy=1 matrix mtxB = CalculateAllHops(snAB, 0,0,0, 1,1,SiteDistance, AttemptToHop, gamma, PeriodicXB, PeriodicYB, PeriodicZB); //Sorts all the data into midpoints ArbArray mpAB = MPsort( &OrderLB, &OrderHB, &MidPtsTotalB, mtxB, snAB, PeriodicXB, PeriodicYB, PeriodicZB); //Sorts midpoints into Nodes in link lists. Each element of mpAT is composed of a //link list all of the same order of magnitude int TotalOrdersB = OrderHB-OrderLB+1; ArbArray ArbB2 = SortOrderMag( TotalOrdersB, OrderLB, mpAB); //Sorts nodes into clusters printf("Sorting Nodes into Clusters\n"); ArbArray ArbB = ClusterSort( TotalOrdersB, OrderLB, ArbB2); //Filtering Cluster printf("Filtering Clusters\n"); rv = FilterCluster( TotalOrdersB, OrderLB, mtxB, &ArbB, snAB,\ PeriodicXB, PeriodicYB, PeriodicZB,\ XElecOnB, YElecOnB, ZElecOnB); printf("Calculating NeighNodes\n"); CalculateNeighNodes(TotalOrdersB, OrderLB, &ArbB, snAB, PeriodicXB, PeriodicYB, PeriodicZB); printf("Calculating P values\n"); CalculateSumAndP( TotalOrdersB, snAB, &ArbB, mtxB, 15, PeriodicXB, PeriodicYB, PeriodicZB); printf("Connecting nodes to clusters\n"); ConnectClusterSN( TotalOrdersB, snAB, ArbB); //Deleting Every thing printf("Deleting Phase\n"); deleteSNarray(snAB); deleteAllMidPointArray(&mpAB); deleteMatrix(mtxB); deleteArbArray(&ArbB2); deleteArbArray(&ArbB); //atexit(mem_term); */ /* printf("\nCreating Matrix with data to test cluster functions\n"); SNarray snA=newSNarray(SLength,SWidth,SHeight); double electricField; double electricEnergy; electricField = voltage /(SLength*SiteDistance); electricEnergy= SiteDistance*electricField; initSite(electricEnergy, snA); printf("\nCalling FindCluster Function\n"); ArbArray ClArLL; ArbArray NeighClArLL; FindCluster(snA, electricEnergy,0,0, &ClArLL, &NeighClArLL); */ return 0; }
void Animal::Sleep() { setEnergy(getEnergy() + 10); setWeight(getWeight() - 5); }
VESPERSEXAFSScanConfigurationView::VESPERSEXAFSScanConfigurationView(VESPERSEXAFSScanConfiguration *config, QWidget *parent) : VESPERSScanConfigurationView(parent) { config_ = config; AMTopFrame *frame = new AMTopFrame("VESPERS EXAFS Configuration"); // Regions setup regionsView_ = new AMRegionsView(config_->regions()); regionsView_->setMinimumWidth(300); regionsLineView_ = new AMEXAFSLineView(config_->exafsRegions()); // The fluorescence detector setup QGroupBox *fluorescenceDetectorGroupBox = addFluorescenceDetectorSelectionView(); connect(fluorescenceButtonGroup_, SIGNAL(buttonClicked(int)), this, SLOT(onFluorescenceChoiceChanged(int))); connect(config_->dbObject(), SIGNAL(fluorescenceDetectorChanged(int)), this, SLOT(updateFluorescenceDetector(int))); fluorescenceButtonGroup_->button((int)config_->fluorescenceDetector())->setChecked(true); // Ion chamber selection QGroupBox *ItGroupBox = addItSelectionView(); connect(ItGroup_, SIGNAL(buttonClicked(int)), this, SLOT(onItClicked(int))); connect(config_->dbObject(), SIGNAL(transmissionChoiceChanged(int)), this, SLOT(updateItButtons(int))); QGroupBox *I0GroupBox = addI0SelectionView(); connect(I0Group_, SIGNAL(buttonClicked(int)), this, SLOT(onI0Clicked(int))); connect(config_->dbObject(), SIGNAL(incomingChoiceChanged(int)), this, SLOT(updateI0Buttons(int))); I0Group_->button((int)config_->incomingChoice())->click(); ItGroup_->button((int)config_->transmissionChoice())->click(); QHBoxLayout *ionChambersLayout = new QHBoxLayout; ionChambersLayout->addWidget(I0GroupBox); ionChambersLayout->addWidget(ItGroupBox); // Scan name selection scanName_ = addScanNameView(config_->name()); connect(scanName_, SIGNAL(editingFinished()), this, SLOT(onScanNameEdited())); connect(config_, SIGNAL(nameChanged(QString)), scanName_, SLOT(setText(QString))); onScanNameEdited(); QFormLayout *scanNameLayout = new QFormLayout; scanNameLayout->addRow("Scan Name:", scanName_); // Energy (Eo) selection energy_ = new QDoubleSpinBox; energy_->setSuffix(" eV"); energy_->setMinimum(0); energy_->setMaximum(30000); connect(energy_, SIGNAL(editingFinished()), this, SLOT(setEnergy())); elementChoice_ = new QToolButton; connect(elementChoice_, SIGNAL(clicked()), this, SLOT(onElementChoiceClicked())); lineChoice_ = new QComboBox; connect(lineChoice_, SIGNAL(currentIndexChanged(int)), this, SLOT(onLinesComboBoxIndexChanged(int))); if (config_->edge().isEmpty()){ elementChoice_->setText("Cu"); fillLinesComboBox(AMPeriodicTable::table()->elementBySymbol("Cu")); lineChoice_->setCurrentIndex(0); } // Resets the view for the view to what it should be. Using the saved for the energy in case it is different from the original line energy. else onEdgeChanged(); connect(config_, SIGNAL(edgeChanged(QString)), this, SLOT(onEdgeChanged())); QCheckBox *useFixedTime = new QCheckBox("Use fixed time (EXAFS)"); useFixedTime->setEnabled(config_->useFixedTime()); connect(config_->exafsRegions(), SIGNAL(regionsHaveKSpaceChanged(bool)), useFixedTime, SLOT(setEnabled(bool))); connect(useFixedTime, SIGNAL(toggled(bool)), config_, SLOT(setUseFixedTime(bool))); QSpinBox *numberOfScans = new QSpinBox; numberOfScans->setMinimum(1); numberOfScans->setValue(config_->numberOfScans()); numberOfScans->setAlignment(Qt::AlignCenter); connect(numberOfScans, SIGNAL(valueChanged(int)), config_, SLOT(setNumberOfScans(int))); connect(config_, SIGNAL(numberOfScansChanged(int)), this, SLOT(onEstimatedTimeChanged())); QFormLayout *numberOfScansLayout = new QFormLayout; numberOfScansLayout->addRow("Number of Scans:", numberOfScans); QFormLayout *energySetpointLayout = new QFormLayout; energySetpointLayout->addRow("Energy:", energy_); QHBoxLayout *energyLayout = new QHBoxLayout; energyLayout->addLayout(energySetpointLayout); energyLayout->addWidget(elementChoice_); energyLayout->addWidget(lineChoice_); // Setting the scan position. QGroupBox *goToPositionGroupBox = addGoToPositionView(config_->goToPosition(), config_->x(), config_->y()); connect(config_, SIGNAL(gotoPositionChanged(bool)), goToPositionCheckBox_, SLOT(setChecked(bool))); connect(goToPositionCheckBox_, SIGNAL(toggled(bool)), config_, SLOT(setGoToPosition(bool))); connect(goToPositionCheckBox_, SIGNAL(toggled(bool)), setCurrentPositionButton_, SLOT(setEnabled(bool))); connect(goToPositionCheckBox_, SIGNAL(toggled(bool)), savedXPosition_, SLOT(setEnabled(bool))); connect(goToPositionCheckBox_, SIGNAL(toggled(bool)), savedYPosition_, SLOT(setEnabled(bool))); connect(goToPositionCheckBox_, SIGNAL(toggled(bool)), positionsSaved_, SLOT(setEnabled(bool))); connect(setCurrentPositionButton_, SIGNAL(clicked()), this, SLOT(setScanPosition())); setSampleStage(VESPERSBeamline::vespers()->experimentConfiguration()->sampleStageChoice()); // The estimated scan time. estimatedTime_ = new QLabel; estimatedSetTime_ = new QLabel; connect(config_, SIGNAL(totalTimeChanged(double)), this, SLOT(onEstimatedTimeChanged())); onEstimatedTimeChanged(); // The roi text edit. roiText_ = new QTextEdit; roiText_->setReadOnly(true); QPushButton *configureXRFDetectorButton = new QPushButton(QIcon(":/hammer-wrench.png"), "Configure XRF Detector"); connect(configureXRFDetectorButton, SIGNAL(clicked()), this, SLOT(onConfigureXRFDetectorClicked())); QFormLayout *roiTextLayout = new QFormLayout; roiTextLayout->addRow(roiText_); roiTextLayout->addRow(configureXRFDetectorButton); roiTextBox_ = new QGroupBox("Regions Of Interest"); roiTextBox_->setLayout(roiTextLayout); roiTextBox_->setVisible(config_->fluorescenceDetector() == VESPERS::NoXRF ? false : true); // Label showing where the data will be saved. QLabel *exportPath = addExportPathLabel(); // Label with a help message for EXAFS. QLabel *helpMessage = new QLabel("Note when using EXAFS: when using variable integration time, the time column is the maximum time."); // Default XANES and EXAFS buttons. QPushButton *defaultXANESButton = new QPushButton("Default XANES"); connect(defaultXANESButton, SIGNAL(clicked()), this, SLOT(onDefaultXANESScanClicked())); QPushButton *defaultEXAFSButton = new QPushButton("Default EXAFS"); connect(defaultEXAFSButton, SIGNAL(clicked()), this, SLOT(onDefaultEXAFSScanClicked())); // Setting up the steps to show the time offset for scan time estimation. connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onCustomContextMenuRequested(QPoint))); setContextMenuPolicy(Qt::CustomContextMenu); QGroupBox *timeOffsetBox = addTimeOffsetLabel(config_->timeOffset()); connect(timeOffset_, SIGNAL(valueChanged(double)), this, SLOT(setTimeOffset(double))); QVBoxLayout *defaultLayout = new QVBoxLayout; defaultLayout->addSpacing(35); defaultLayout->addWidget(defaultXANESButton); defaultLayout->addWidget(defaultEXAFSButton); defaultLayout->addStretch(); // Auto-export option. QGroupBox *autoExportGroupBox = addExporterOptionsView(QStringList(), config_->exportSpectraSources()); connect(autoExportSpectra_, SIGNAL(toggled(bool)), config_, SLOT(setExportSpectraSources(bool))); // Setting up the layout. QGridLayout *contentsLayout = new QGridLayout; contentsLayout->addWidget(regionsView_, 1, 1, 2, 2); contentsLayout->addWidget(fluorescenceDetectorGroupBox, 1, 3); contentsLayout->addLayout(scanNameLayout, 4, 1); contentsLayout->addLayout(energyLayout, 0, 1, 1, 3); contentsLayout->addWidget(goToPositionGroupBox, 4, 3, 4, 1); contentsLayout->addLayout(ionChambersLayout, 2, 3, 2, 1); contentsLayout->addWidget(roiTextBox_, 1, 4, 2, 2); contentsLayout->addWidget(useFixedTime, 3, 1); contentsLayout->addWidget(estimatedTime_, 6, 1, 1, 2); contentsLayout->addWidget(estimatedSetTime_, 7, 1, 1, 2); contentsLayout->addLayout(numberOfScansLayout, 5, 1); contentsLayout->addWidget(timeOffsetBox, 8, 1, 1, 2); contentsLayout->addWidget(autoExportGroupBox, 4, 5, 2, 3); QHBoxLayout *squeezeContents = new QHBoxLayout; squeezeContents->addStretch(); squeezeContents->addLayout(defaultLayout); squeezeContents->addLayout(contentsLayout); squeezeContents->addStretch(); QVBoxLayout *configViewLayout = new QVBoxLayout; configViewLayout->addWidget(frame); configViewLayout->addStretch(); configViewLayout->addWidget(regionsLineView_, 0, Qt::AlignCenter); configViewLayout->addSpacing(30); configViewLayout->addLayout(squeezeContents); configViewLayout->addSpacing(30); configViewLayout->addWidget(exportPath, 0, Qt::AlignCenter); configViewLayout->addSpacing(30); configViewLayout->addWidget(helpMessage, 0, Qt::AlignCenter); configViewLayout->addStretch(); setLayout(configViewLayout); }
void Animal::SearchingForFood() { setEnergy(getEnergy() - 10); setWeight(getWeight() - 5); }