static void tank_set_temp(double temp) { int i; int low_set; int high_set; double low_energy; double high_energy; low_set = 0; high_set = 0; tank_energy = 32768; i = 0; while (!low_set || !high_set || !converged(temp)) { tank_temperature = temp; tank(); if (n2o_thermo_error == TOO_HOT) { high_energy = tank_energy; high_set = 1; if (!low_set) tank_temperature -= 1; } else if (n2o_thermo_error == TOO_COLD) { low_energy = tank_energy; low_set= 1; if (!high_set) tank_temperature += 1; } else if (tank_temperature < temp) { low_energy = tank_energy; low_set= 1; } else { high_energy = tank_energy; high_set = 1; } if (!low_set) tank_energy /= 1.125; else if (!high_set) tank_energy *= 1.125; else tank_energy = (low_energy + high_energy) / 2.; if (tank_energy < 1.) { printf("FAILED: energy == 0\n"); break; } else if (tank_energy > 1e8) { printf("FAILED: energy > 100,000,000\n"); break; } if (i++ > 1000) { printf("FAILED %d iterations\n", i); break; } } }
task main() { while(true) { tank(); //arcade(); lift(); inTake(); } }
int main(void) { int selection; //User input for tank float volume; //Calculated volume for tank selection = input(); volume = tank(selection); results(volume); return(0); }
void Lieutenant::AttackTarget(Unit& target) { for (size_t i(0); i < marines.size(); ++i) { Unit & marine(marines[i]); marine.Attack(target); } for (size_t j(0); j < tanks.size(); ++j) { Unit & tank(tanks[j]); tank.Attack(target); } }
Vector<Unit> Lieutenant::TransferSquad() { Vector<Unit> units; for (size_t i(0); i < marines.size(); ++i) { Unit & marine(marines[i]); units.push_back(marine); } for (size_t j(0); j < tanks.size(); ++j) { Unit & tank(tanks[j]); units.push_back(tank); } marines.clear(); tanks.clear(); return units; }
void Robot::arcade(float straight, float turn) { float aStraight = abs(straight); float aTurn = abs(turn); float left = max(aStraight, aTurn); float right = aStraight - aTurn; if (aTurn != turn) { float temp = right; right = left; left = temp; } if(aStraight != straight){ left *= -1.0f; right *= -1.0f; } tank(left, right); }
/** * Micromanages each unit in the squad, checking if they are at risk of dying and moving them away from danger * This behavior is similar to unit dancing in standard RTS strategies, as it improves unit preservation * and impedes enemy focus firing. */ void Lieutenant::PullBackWounded() { for (size_t i(0); i < marines.size(); ++i) { Unit & marine(marines[i]); real8 hp = marine.GetHitpoints(); real8 maxHp = marine.GetMaxHitpoints(); real8 health = (hp/maxHp); if (health < EXPECTED_DEATH && marine.InCombat()) { //move the opposite way that the damage is coming vec2 pullBack = vec2(-PULL_BACK_BUFFER*marine.DmgDirection().rX,-PULL_BACK_BUFFER*marine.DmgDirection().rY); //calculate where the unit should move and //create a goal. Pass it to the units movement. (*(marine.GetTask())).cancel(); marine.SetGoal(Movement::Vec2D((marine.GetPosition().x + pullBack.rX),(marine.GetPosition().y + pullBack.rY))); marine.SetTask(mc->moveUnit(marine.GetGameObj(), marine.GetGoal())); //std::cout << "MARINE PULLING BACK: "<< marine.GetVector().x - marine.GetPosition().x << "," << marine.GetVector().y - marine.GetPosition().y << std::endl; } } for (size_t i(0); i < tanks.size(); ++i) { Unit & tank(tanks[i]); real8 hp = tank.GetHitpoints(); real8 maxHp = tank.GetMaxHitpoints(); real8 health = (hp/maxHp); if (health < EXPECTED_DEATH && tank.InCombat()) { //move the opposite way that the damage is coming vec2 pullBack = vec2(-PULL_BACK_BUFFER*tank.DmgDirection().rX,-PULL_BACK_BUFFER*tank.DmgDirection().rY); //calculate where the unit should move and //create a goal. Pass it to the units movement (*(tank.GetTask())).cancel(); tank.SetGoal(Movement::Vec2D((tank.GetPosition().x + pullBack.rX),(tank.GetPosition().y + pullBack.rY))); tank.SetTask(mc->moveUnit(tank.GetGameObj(), tank.GetGoal())); //std::cout << "TANK PULLING BACK : "<< tank.GetVector().x - tank.GetPosition().x << "," << tank.GetVector().y - tank.GetPosition().y << std::endl; } } }
double ITank::gunLength() const { return tank().virtual_gun_length(); }
double ITank::mass() const { return tank().mass(); }
double ITank::turretAngleTo(const model::Unit &unit) const { return tank().GetTurretAngleTo(unit); }
int ITank::premiumShellCount() const { return tank().premium_shell_count(); }
int ITank::rearArmour() const { return tank().rear_armor(); }
double ITank::turretAngleTo(const Point &point) const { return tank().GetTurretAngleTo(point.x(), point.y()); }
int main(int argc, char **argv) { ros::init(argc, argv, "epos2_driver"); ros::NodeHandle roshandle; ros::Rate loopRate = 50; Epos2MotorController* epos[2]; if (readParameterServer()) { ROS_ERROR("maxMPS: %.4lf, wheelBase: %.4lf, axisLength: %.4lf, wheelPerimeter: %.4lf", parameter.maxMeterPerSecond, parameter.wheelBase, parameter.axisLength, parameter.wheelPerimeter); //ROS_ERROR("port: %s", parameter.port); Epos2MotorController leftEpos(parameter.node[TankSteering::left], parameter.reverse[TankSteering::left], parameter.port, parameter.timeout, parameter.baudrate); leftEpos.nodeStr = (char*) "left EPOS2"; if (leftEpos.devhandle != 0) { Epos2MotorController rightEpos(parameter.node[TankSteering::right], parameter.reverse[TankSteering::right], leftEpos.devhandle); rightEpos.nodeStr = (char*) "right EPOS2"; epos[TankSteering::left] = &leftEpos; epos[TankSteering::right] = &rightEpos; bond::Bond driverBond("epos2_bond", "motorController"); //new local bond driverBond.setConnectTimeout(90); signal(SIGTERM, &killCallback); signal(SIGABRT, &killCallback); signal(SIGBUS, &killCallback); signal(SIGHUP, &killCallback); signal(SIGILL, &killCallback); signal(SIGINT, &killCallback); signal(SIGSEGV, &killCallback); TankSteering tank(roshandle, epos, parameter.wheelPerimeter, parameter.axisLength, parameter.maxMeterPerSecond); tank.initLaserscanner(120, 0.15, 1.0); //example how to read and edit regulator- and motor-data Epos2MotorController::regulator controlParameter[2]; Epos2MotorController::motorData motorParameter[2]; Epos2MotorController::gearData gearParameter[2]; Epos2MotorController::accelerationData accelerationParameter[2]; double maxRobotRPM[2]; for (int i=TankSteering::left; i<=TankSteering::right; i++) { epos[i]->disableEpos2(); epos[i]->getRegulatorParameter( &(controlParameter[i]) ); //controlParameter[i].positionGain.i++; ROS_ERROR("[main %s] (position)-> P: %i, I: %i, D: %i",(i==TankSteering::left)?"left":"right", controlParameter[i].positionGain.p, controlParameter[i].positionGain.i, controlParameter[i].positionGain.d); ROS_ERROR("[main %s] (feedforward)-> posFF-velo: %i, posFF-acc: %i, velFF-vel: %i, velFF-acc: %i",(i==TankSteering::left)?"left":"right", controlParameter[i].positionFF.Velocity, controlParameter[i].positionFF.Acceleration, controlParameter[i].velocityFF.Velocity, controlParameter[i].velocityFF.Acceleration); ROS_ERROR("[main %s] (velocity)-> P: %i, I: %i",(i==TankSteering::left)?"left":"right", controlParameter[i].velocityGain.p, controlParameter[i].velocityGain.i); ROS_ERROR("[main %s] (current)-> P: %i, I: %i",(i==TankSteering::left)?"left":"right", controlParameter[i].currentGain.p, controlParameter[i].currentGain.i); //epos[i]->setRegulatorParameter( &(controlParameter[i]) ); epos[i]->getMotorData( &(motorParameter[i]) ); ROS_ERROR("[main %s] (motor) maxCurrent: %i, PeakCurrent: %i, ThermalTimeConstant: %i, maxMotorSpeed: %li",(i==TankSteering::left)?"left":"right", motorParameter[i].continuousCurrent, motorParameter[i].maxPeakCurrent, motorParameter[i].thermalTimeConstantWinding, motorParameter[i].maxRPM); //motorParameter[i].thermalTimeConstantWinding = 10; //epos[i]->setMotorData( &(motorParameter[i]) ); epos[i]->getGearData( &(gearParameter[i]) ); ROS_ERROR("[main %s] (Gear)-> maxRPM: %li, numerator: %li, denominator: %i",(i==TankSteering::left)?"left":"right", gearParameter[i].maxRPM, gearParameter[i].numerator, gearParameter[i].denominator); epos[i]->getMaxRPM( &(maxRobotRPM[i]) ); ROS_ERROR("[main %s] maxRobotRPM: %.4lf",(i==TankSteering::left)?"left":"right", maxRobotRPM[i]); epos[i]->getAccelerationData( &(accelerationParameter[i]) ); ROS_ERROR("[main %s] (acceleration) maxAcc: %.3lf m/s^2, profileAcc: %.3lf m/s^2, profileDec: %.3lf m/s^2, quickstopDec: %.3lf m/s^2",(i==TankSteering::left)?"left":"right", accelerationParameter[i].maxAcceleration, accelerationParameter[i].profileAcceleration, accelerationParameter[i].profileDeceleration, accelerationParameter[i].quickstopDeceleration); epos[i]->enableEpos2(); }//end of: example how to read and edit regulator- and motor-data driverBond.start(); while(!gotSignal && ros::ok()) { loopRate.sleep(); ros::spinOnce(); } driverBond.breakBond(); if (gotSignal == 0) {ROS_INFO("EPOS2-Driver finished successful\n");} return gotSignal; } else { ROS_FATAL("can't connect to the EPOS2 - if the EPOS2 is plugged, disconnected it and plug it in again. Retry."); return 1; } } else { ROS_FATAL("unable to read all necessary roboter parameter - EPS2-Driver will be closed\n"); return 1; } }
ITank::operator model::Tank() const { return tank(); }
model::TankType ITank::type() const { return tank().type(); }
int ITank::reloadTime() const { return tank().reloading_time(); }
int ITank::teammateIndex() const { return tank().teammate_index(); }
bool ITank::isTeammate() const { return tank().teammate(); }
int ITank::sideArmour() const { return tank().side_armor(); }
double ITank::enginePower() const { return tank().engine_power(); }
int ITank::armour() const { return tank().hull_durability(); }
double ITank::rearFactor() const { return tank().engine_rear_power_factor(); }
int ITank::maxHealth() const { return tank().hull_max_durability(); }
double ITank::turretAngleTo(double x, double y) const { return tank().GetTurretAngleTo(x, y); }
int ITank::frontArmour() const { return tank().frontal_armor(); }
double ITank::turretMaxRelativeAngle() const { return tank().turret_max_relative_angle(); }
int ITank::maxArmour() const { return tank().crew_max_health(); }
int main(int argc, char** argv) { // Starting game window size. height = 960; width = 1000; //Initialize Object Data srand(time(NULL)); // Initialize Tank float randomAngle = (float)random(0, 200) / 10; artillery = tank(random(-width * 24, width * 24), random(-height * 24, height * 24), 1500, 15, randomAngle); player = Rocket(0,0, 100, 0.8f, 10); player.follow(artillery); //Sets initial Position to tank UI = new UIManager(); moonLand = random(0, numMoons-1); seed = random(-123456, 123456); // Level seed to randomize each level creation between min and max value. int sizeOfMoonLoc = -1; artillery.colRadius = artillery.radius * distanceFromStartMult; for (int i = 0; i < numMoons; i++) { sizeOfMoonLoc++; moonLocation[i] = vector(random(-width * 24, width * 24), random(-height * 24, height * 24)); float moonRadius = random(300, 500); moons[i] = Moon(moonLocation[i], moonRadius, 0, 0, 0, 60); for (int z = 0; z < sizeOfMoonLoc; z++) { if (z != i) { while (moons[i].checkCollision(moons[z]) || moons[i].checkCollision(artillery)) { moonLocation[i] = vector(random(-width * 24, width * 24), random(-height * 24, height * 24)); moons[i] = Moon(moonLocation[i], moonRadius, 0, 0, 0, round(moonRadius / 10)); } } } } artillery.colRadius = artillery.radius; for (int i = 0; i < numStars; i++) { star[i] = new Star(vector(random(-width*24,width*24), random(-height*24,height*24)), vector(0.8f, 0.8f, 0.0f), random(3, 15), random(0,100)); } //End of Initialization glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); glutInitWindowPosition(0,0); glutInitWindowSize(width, height); glutCreateWindow("IchyMoo the LunarLunar"); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glClearColor(0.05, 0.05, 0.05, 0.0); glutReshapeFunc(reshape); glutDisplayFunc(renderScene); glutKeyboardFunc(keyDown); glutKeyboardUpFunc(keyUp); glutTimerFunc(41,idle,0); glutMainLoop(); }
double ITank::turretTurnSpeed() const { return tank().turret_turn_speed(); }