static Node *bypass() { Node *bypass = getNode(path); Node *next = NULL; Arc *arc; PassageMarkerI nextMarker; // Remove unwanted arcs while (getArc(bypass) != NULL) destroyArc(getArc(bypass), graph); // Update extensive variables (length + descriptors + passage markers) while (!isTerminal(path)) { nextMarker = getNextInSequence(path); next = getNode(nextMarker); while (next == bypass) { disconnectNextPassageMarker(path, graph); destroyPassageMarker(nextMarker); nextMarker = getNextInSequence(path); next = getNode(nextMarker); } if (next == NULL) return bypass; // Overall node update if (!getUniqueness(next)) { adjustShortReads(bypass, getNextInSequence(path)); appendSequence(bypass, sequences, getNextInSequence(path), graph); } else { concatenateReadStarts(bypass, next, graph); #ifndef SINGLE_COV_CAT Category cat; for (cat = 0; cat < CATEGORIES; cat++) { // Update virtual coverage incrementVirtualCoverage(bypass, cat, getVirtualCoverage(next, cat)); // Update original virtual coverage incrementOriginalVirtualCoverage(bypass, cat, getOriginalVirtualCoverage(next, cat)); } #else incrementVirtualCoverage(bypass, getVirtualCoverage(next)); #endif appendDescriptors(bypass, next); } // Members updateMembers(bypass, next); // Termination if (isTerminal(path) || getUniqueness(next)) break; } // Remove unique groupies from arrival admitGroupies(next, bypass); // Copy destination arcs for (arc = getArc(next); arc != NULL; arc = getNextArc(arc)) { if (getDestination(arc) == next) continue; else if (getDestination(arc) == getTwinNode(next)) createAnalogousArc(bypass, getTwinNode(bypass), arc, graph); else createAnalogousArc(bypass, getDestination(arc), arc, graph); } destroyNode(next, graph); return bypass; }
void Virus::update() { double maxSpeed = 0.2; double maxAccel = 0.1; switch (virusData->getBodyType()) { case VIRUS_BODYTYPE_WORM: maxSpeed = virusData->getMovementSpeed(); maxAccel = 0.012; if (gotDestination && state == VIRUSSTATE_MOVING) { Vector direction = Vector(position, destination); direction = direction.normalize(); double angle = atan2(direction.y, direction.x) - atan2(0.0, 1.0); angle = angle * 180.0 / M_PI; double turnSpeed = 0.0; double turnTo = angle; double distanceAdd; double distanceSub; if (orientation < turnTo) { distanceAdd = turnTo - orientation; distanceSub = turnTo + 360.0 - orientation; } else { distanceAdd = turnTo + 360.0 - orientation; distanceSub = orientation - turnTo; } double distance = std::min(distanceAdd, distanceSub); if (fabs(distance) > 50.0) { turnSpeed = 10.0; } else if (fabs(distance) > 10.0) { turnSpeed = 5.0; } else if (fabs(distance) > 5.0) { turnSpeed = 2.5; } else if (fabs(distance) > 1.0) { turnSpeed = 1.0; } else { turnSpeed = 0.0; } if (distanceSub < distanceAdd) { orientation -= turnSpeed; } else { orientation += turnSpeed; } if (orientation >= 360.0) { orientation -= 360.0; } } break; case VIRUS_BODYTYPE_AMOEBA: maxSpeed = virusData->getMovementSpeed(); maxAccel = 0.008; orientation += (rotateSpeed / 2.0); if (orientation >= 360.0) { orientation -= 360.0; } break; case VIRUS_BODYTYPE_SPHERE: maxSpeed = virusData->getMovementSpeed(); maxAccel = 0.2; orientation += rotateSpeed; if (orientation >= 360.0) { orientation -= 360.0; } break; } frame++; // Virus being cloned inside cell if (state == VIRUSSTATE_INACTIVE) { Vector speed = Vector(position, destination); if (speed.length() > getBoundingCircle().getRadius() / 5.0) { speed = speed.normalize(); speed = speed.mult(0.1); position = position.translate(speed); } return; } // Virus entering cell if (state == VIRUSSTATE_TAKINGCELL) { Vector speed = Vector(position, destination); if (speed.length() > getBoundingCircle().getRadius() / 5.0) { speed = speed.normalize(); speed = speed.mult(0.05); position = position.translate(speed); } else { dead = true; takenCell->startCloning(owner, id); } return; } // Virus moving if (state == VIRUSSTATE_MOVING) { if (!gotDestination) { getDestination(); } else if (reachedDestination()) { if (!moveDelay) { currentPath.pop_front(); if (!currentPath.empty()) { getDestination(); } else { gotDestination = false; state = VIRUSSTATE_IDLE; } } else { gotDestination = false; destination = position; } } } Vector accel = Vector(0.0, 0.0, 0.0); if (gotDestination) { accel = Vector(position, destination); accel = accel.normalize(); accel = accel.mult(maxAccel); } else { speed = Vector(0.0, 0.0, 0.0); } if (timeOnDestination) { double t = (double)timeOnDestination / 60.0; maxSpeed *= (0.5) * (1.0 - t); } speed = speed.translate(accel); if (speed.length() > maxSpeed) { speed = speed.normalize(); speed = speed.mult(maxSpeed); } setPosition(position.translate(speed)); if (moveDelay) { moveDelay--; } if (attackCooldown) { attackCooldown--; } if (flash) { flash--; } if (reproduceCooldown) { reproduceCooldown--; } }
//单击“开始”按钮,获取用户输入信息 void Widget::startButtonClicked() { QDateTime startDateTime; //对于当前旅客,初次点击开始按钮 if (startclicked[ui->TravelerComboBox->currentIndex()] == false) { qDebug() << "StartButton clicked 1st time for CurrentTraveler"; strategy = getStrategy(); start = getStart(); destination = getDestination(); //始发地和目的地相同则弹框报错,不作操作 if (start == destination) { qDebug() << "Start and Dedtination is the same one, wait for another command"; QMessageBox::information(this, "Error", QString::fromWCharArray(L"出发地和目的地相同")); return; } //(策略三的情况下)截止时间早于当前时间报错,不作操作 if (!(ui->StartDateTimeEdit->dateTime() < ui->DeadlineDateTimeEdit->dateTime())) { qDebug() << "Deadline ahead of StratTime, wait for another command"; QMessageBox::information(this, "Error", QString::fromWCharArray(L"截止时间早于当前时间")); return; } startDateTime = getStartTime(); travelers[ui->TravelerComboBox->currentIndex()] = (Traveler(addtravelertimes-1, startDateTime, getDeadline(), strategy, start, destination, ui->ThroughCityCheckBox->isChecked(), throughcity)); std::vector<Attribute> path = travelers[ui->TravelerComboBox->currentIndex()].getPlan(); if (path.size() == 0) { qDebug() << "No legal path"; QMessageBox::information(this, "Error", QString::fromWCharArray(L"无有效路径")); startclicked[ui->TravelerComboBox->currentIndex()] = false; return; } startclicked[ui->TravelerComboBox->currentIndex()] = true; currentTraveler = ui->TravelerComboBox->currentIndex(); displayTotalTime(); displayFare(path); displayPath(path); qDebug() << "StartButton rename as ChangePlan for CurrentTraveler"; ui->StartButton->setText(QString::fromWCharArray(L"更改")); ui->StartComboBox->setEnabled(false); ui->StartDateTimeEdit->setEnabled(false); startclickedtimes += 1; startclicked[ui->TravelerComboBox->currentIndex()] = true; return; } //对于当前旅客,执行更改计划操作 if (startclicked[ui->TravelerComboBox->currentIndex()] == true) { qDebug() << "StartButton clicked for CurrentTraveler"; strategy = getStrategy(); destination = getDestination(); if (!(ui->StartDateTimeEdit->dateTime() < ui->DeadlineDateTimeEdit->dateTime())) { qDebug() << "Deadline ahead of StartTime, reset the DeadlineDateTimeEdit,wait for another command"; QMessageBox::information(this, "Error", QString::fromWCharArray(L"截止时间早于当前时间")); int deaDay = ui->StartDateTimeEdit->dateTime().date().day(); deaDay += 1; QDateTime deadlineDateTime; deadlineDateTime.setDate(QDate(ui->StartDateTimeEdit->dateTime().date().year(), ui->StartDateTimeEdit->dateTime().date().month(), deaDay)); deadlineDateTime.setTime(QTime(ui->StartDateTimeEdit->dateTime().time())); ui->DeadlineDateTimeEdit->setDateTime(deadlineDateTime); return; } //获得新计划的始发地,即原计划的当前停留地/运行途中即将到达地 int nextCity2Arrive = ui->LeftWidget->nextCity(); if (nextCity2Arrive != -1) { std::vector<Attribute> path = travelers[ui->TravelerComboBox->currentIndex()].changePlan(nextCity2Arrive, strategy, destination, getDeadline(), ui->ThroughCityCheckBox->isChecked(),throughcity); if (path.size() == 0) { qDebug() << "No legal path"; QMessageBox::information(this, "Error", QString::fromWCharArray(L"无有效路径")); return; } qDebug() << "Change plan success."; currentTraveler = ui->TravelerComboBox->currentIndex(); displayTotalTime(); displayFare(path); displayPath(path); } } }