// default constructor Reticle::Reticle(){ setType("Reticle"); setSolidness(df::SPECTRAL); // put above the rest of the objects setAltitude(4); }
Trap::Trap(int x, int y) { LogManager &log_manager = LogManager::getInstance(); #ifdef REGISTER // Need to update fire rate control each step. registerInterest(DF_STEP_EVENT); #endif // Set object type. setType("Trap"); auto& resMgr = ResourceManager::getInstance(); setSprite(resMgr.getSprite("trap")); setSpriteSlowdown(4); setAltitude(1); // Set starting location. WorldManager &world_manager = WorldManager::getInstance(); Position pos(7, world_manager.getBoundary().getVertical() / 2); setPosition(Position(x, y)); setBox(Box(Position(0, 0), getSprite()->getWidth(), getSprite()->getHeight())); //setYVelocity(0.25); // Set firing variables. }
_border::_border() { // Get instances of necessary managers. LogManager &log_manager = LogManager::getInstance(); ResourceManager &resource_manager = ResourceManager::getInstance(); WorldManager &world_manager = WorldManager::getInstance(); // Set up border sprite. Sprite *p_temp_sprite = resource_manager.getSprite("border"); if (!p_temp_sprite) { log_manager.writeLog("_border::_border(): Warning! Sprite '%s' not found", "border"); } else { // If sprite is found, set sprite for this object. setSprite(p_temp_sprite); } // Set type of border. setType("_border"); // Make sure it collides with others so game objects don't pass through message box. setSolidness(HARD); setAltitude(2); // Set position to middle center of the terminal. Position pos(world_manager.getBoundary().getCorner().getX() + world_manager.getBoundary().getHorizontal()/2, ( world_manager.getBoundary().getCorner().getY() + world_manager.getBoundary().getVertical()/2) + 6); setPosition(pos); };
Star::Star() { setType("Star"); setSolidness(SPECTRAL); setXVelocity(-1.0 / (random()%10 + 1)); setAltitude(0); // Make them in the background. WorldManager &world_manager = WorldManager::getInstance(); Position pos(random()%world_manager.getBoundary().getHorizontal(), random()%world_manager.getBoundary().getVertical()); setPosition(pos); }
Star::Star() { setType("Star"); setSolidness(df::SPECTRAL); setVelocity(df::Vector((float) -1.0 /(rand()%9 + 2), 0)); setAltitude(0); // Make Stars in the background. df::WorldManager &world_manager = df::WorldManager::getInstance(); df::Vector p((float) (rand()%(int)world_manager.getBoundary().getHorizontal()), (float) (rand()%(int)world_manager.getBoundary().getVertical())); setPosition(p); }
Star::Star() { setType("Star"); setSolidness(df::SPECTRAL); setXVelocity((float)(-1.0 / (rand() % 10 + 1))); setAltitude(0); df::WorldManager &world_manager = df::WorldManager::getInstance(); df::Position pos(rand() % world_manager.getBoundary().getHorizontal(), rand() % world_manager.getBoundary().getVertical()); setPosition(pos); }
Ghost::Ghost(Position pos) { ghost_velocity = GHOST_VELOCITY; WorldManager &world_manager = WorldManager::getInstance(); setPosition(pos); setType("Ghost"); setSolidness(SOFT); //Ghosts can move through anything setAltitude(MAX_ALTITUDE); //TODO: This takes too long to find, is there a more efficient way? /* ObjectList objects = world_manager.getAllObjects(); ObjectListIterator iterator = objects.createIterator(); bool found = false; while(!iterator.isDone() && !found){ if (iterator.currentObject()->getType() == "Hero"){ hero_pos = iterator.currentObject()->getPosition(); found = true; } } */ // if (!found){ Position h_pos(world_manager.getBoundary().getHorizontal() / 2, world_manager.getBoundary().getVertical() / 2); hero_pos = h_pos; // } LogManager &lm = LogManager::getInstance(); ResourceManager &rm = ResourceManager::getInstance(); Sprite *p_temp_sprite; p_temp_sprite = rm.getSprite("ghost"); if (!p_temp_sprite) { lm.writeLog("Ghost::Ghost(): Warning! Sprite '%s' not found", "ghost"); } else { setSprite(p_temp_sprite); setSpriteSlowdown(15); } max_speed_cooldown = MAX_SPEED_COOLDOWN; speed_cooldown = max_speed_cooldown; registerInterest(HERO_MOVE_EVENT); registerInterest(STEP_EVENT); registerInterest(COLLISION_EVENT); registerInterest(LEVEL_UP_EVENT); }
Reticle::Reticle() { setType("Reticle"); setSolidness(df::SPECTRAL); setAltitude(df::MAX_ALTITUDE); // Make Reticle in the foreground. // Reticle moves with mouse, so register. registerInterest(df::MOUSE_EVENT); // Start reticle in center of window. df::Vector p(WM.getBoundary().getHorizontal()/2, WM.getBoundary().getVertical()/2); setPosition(p); }
Reticle::Reticle() { setType("Reticle"); setSolidness(df::SPECTRAL); setAltitude(df::MAX_ALTTITUDE); // Make Reticle in the foreground. // Reticle moves with mouse, so register. registerInterest(df::_MOUSE_EVENT); // Start reticle in center of window. df::GraphicsManager &graphics_manager = df::GraphicsManager::getInstance(); df::Position pos(graphics_manager.getHorizontal() / 2, graphics_manager.getVertical() / 2); setPosition(pos); }
ViewObject::ViewObject(int on_level){ //Object attributes setSolidness(SPECTRAL); setAltitude(MAX_ALTITUDE); setType("ViewObject"); //ViewObject attributes setValue(0); setBorder(true); setLocation(TOP_CENTER); setColor(COLOR_DEFAULT); //Register interest in view events registerInterest(VIEW_EVENT); }
//Reticle constructor Reticle::Reticle(){ //needed managers df::WorldManager &world_manager = df::WorldManager::getInstance(); //set type and solidness setType("Reticle"); setSolidness(df::SPECTRAL); // Make Reticle in foreground setAltitude(df::MAX_ALTITUDE); //interested in mouse events registerInterest(df::A_MOUSE_EVENT); //start in center of screen int view_h = world_manager.getView().getHorizontal(); int view_v = world_manager.getView().getVertical(); df::Position pos(view_h / 2, view_v / 2); setPosition(df::viewToWorld(pos)); }
Platform::Platform() { setType("Platform"); isItThick = false; size = 50; setSolidness(HARD); setXVelocity(0.0); setYVelocity(0.0); setAltitude(3); // Make them in the background. WorldManager &world_manager = WorldManager::getInstance(); //Position pos(random() % world_manager.getBoundary().getHorizontal(), // random() % world_manager.getBoundary().getVertical()); Position pos(0, 15); setPosition(pos); height = 5; setBox(Box(Position(), size, height)); thecolor = rand() % 7; }
Platform::Platform(bool thickness, int sizee, int heightt, int x, int y, float x_speed, float y_speed) { setType("Platform"); isItThick = thickness; size = sizee; setSolidness(HARD); setXVelocity(x_speed); move_countdown = 10; setYVelocity(y_speed); setAltitude(3); // Make them in the background. WorldManager &world_manager = WorldManager::getInstance(); //Position pos(random() % world_manager.getBoundary().getHorizontal(), // random() % world_manager.getBoundary().getVertical()); Position pos(x, y); setPosition(pos); height = heightt; setBox(Box(Position(), size, height)); thecolor = rand() % 7; }
Weapon::Weapon(df::Position init_pos, Direction init_direction) { df::ResourceManager &rm = df::ResourceManager::getInstance(); df::LogManager &log_manager = df::LogManager::getInstance(); exist_countdown = exist_slowdown; // Setup "hero" sprite. df::Sprite *p_temp_sprite = rm.getSprite("weapon"); if (!p_temp_sprite) { log_manager.writeLog("Weapon::Weapon(): Warning! Sprite '%s' not found", "weapon"); } else { setSprite(p_temp_sprite); setSpriteSlowdown(0); } setSolidness(df::SOFT); setType("Weapon"); direction = init_direction; setWeaponPosition(init_pos, direction); setAltitude(4); }
Reticle::Reticle(){ //dragonfly managers needed for this method df::WorldManager &world_manager = df::WorldManager::getInstance(); //set object type setType("Reticle"); //set solidness setSolidness(df::SPECTRAL); //draw in foreground setAltitude(df::MAX_ALTITUDE); //register for interest registerInterest(df::MOUSE_EVENT); //set intial position int world_horiz = world_manager.getBoundary().getHorizontal(); int world_vert = world_manager.getBoundary().getVertical(); df::Position pos(world_horiz / 2, world_vert / 2); setPosition(pos); }
// overloaded constructor to set initial position and altitude. Bus::Bus(df::Position pos, int alt){ setType("Bus"); setSolidness(df::SOFT); setPosition(pos); setAltitude(alt); }
GlobalReference& GlobalReference::setCurrentAltitude(const State& state, double new_altitude) { State::ConstPositionType position = state.getPosition(); setAltitude(new_altitude - position.z()); return *this; }
/** * Adds a field to the message. Unknown fields are rejected * @return bool if field was known to the message */ bool addField(unsigned char fieldDefNum, unsigned char size, unsigned char baseType, unsigned char arch, char * data) { //TODO: Compare size with expected size //TODO: Compare baseType with expected baseType bool fieldWasAdded = true; switch (fieldDefNum) { case 253: setTimestamp(read0x86(data,arch)); break; case 0: setPositionLat(read0x85(data,arch)); break; case 1: setPositionLong(read0x85(data,arch)); break; case 2: setAltitude(read0x88(data,arch,5,500,0x84)); break; case 3: setHeartRate(read0x02(data,arch)); break; case 4: setCadence(read0x02(data,arch)); break; case 5: setDistance(read0x88(data,arch,100,0,0x86)); break; case 6: setSpeed(read0x88(data,arch,1000,0,0x84)); break; case 7: setPower(read0x84(data,arch)); break; case 9: setGrade(read0x88(data,arch,100,0,0x83)); break; case 10: setResistance(read0x02(data,arch)); break; case 11: setTimeFromCourse(read0x88(data,arch,1000,0,0x85)); break; case 12: setCycleLength(read0x88(data,arch,100,0,0x02)); break; case 13: setTemperature(read0x01(data,arch)); break; case 17: setNumSpeed1s(read0x02(data,arch)); break; case 18: setCycles(read0x02(data,arch)); break; case 19: setTotalCycles(read0x86(data,arch)); break; case 28: setCompressedAccumulatedPower(read0x84(data,arch)); break; case 29: setAccumulatedPower(read0x86(data,arch)); break; case 30: setLeftRightBalance(read0x02(data,arch)); break; case 31: setGpsAccuracy(read0x02(data,arch)); break; case 32: setVerticalSpeed(read0x88(data,arch,1000,0,0x83)); break; case 33: setCalories(read0x84(data,arch)); break; case 43: setLeftTorqueEffectiveness(read0x88(data,arch,2,0,0x02)); break; case 44: setRightTorqueEffectiveness(read0x88(data,arch,2,0,0x02)); break; case 45: setLeftPedalSmoothness(read0x88(data,arch,2,0,0x02)); break; case 46: setRightPedalSmoothness(read0x88(data,arch,2,0,0x02)); break; case 47: setCombinedPedalSmoothness(read0x88(data,arch,2,0,0x02)); break; case 52: setCadence256(read0x88(data,arch,256,0,0x84)); break; default: fieldWasAdded = false; break; } return fieldWasAdded; };
void PlaneState::updateState(const Basic::Component* const actor) { const Simulation::AirVehicle* airVehicle = dynamic_cast<const Simulation::AirVehicle*>(actor); setAlive(false); if (airVehicle != nullptr && airVehicle->isActive()) { setAltitude(airVehicle->getAltitude()); setAlive(airVehicle->getMode() == Simulation::Player::ACTIVE); setHeading(airVehicle->getHeading()); setPitch(airVehicle->getPitch()); setRoll(airVehicle->getRoll()); osg::Vec3d angularVels = airVehicle->getAngularVelocities(); setRollRate(angularVels.x()); setPitchRate(angularVels.y()); setYawRate(angularVels.z()); setTracking(false); setTargetTrack(MAX_TRACKS); // 0 is a valid target track, use MAX_TRACKS to // signal "no tgt track" setSpeed(airVehicle->getCalibratedAirspeed()); setNumEngines(airVehicle->getNumberOfEngines()); setIncomingMissile(false); setMissileFired(false); // determine if we have a missile to fire #if 1 const Simulation::StoresMgr* stores = airVehicle->getStoresManagement(); if (stores == nullptr || stores->getNextMissile() == nullptr) { // either we have no SMS, or we have no more missile setMissileFired(true); } else { // we have an sms, and we have a missile available // loop through player list and attempt to find out if one of our missiles is active // if there is an active missile, then for the time being, we do not have a missile to fire const Simulation::Simulation* sim = airVehicle->getSimulation(); const Basic::PairStream* players = sim->getPlayers(); bool finished = false; for (const Basic::List::Item* item = players->getFirstItem(); item != nullptr && !finished; item = item->getNext()) { // Get the pointer to the target player const Basic::Pair* pair = static_cast<const Basic::Pair*>(item->getValue()); const Simulation::Player* player = static_cast<const Simulation::Player*>(pair->object()); if (player->isMajorType(Simulation::Player::WEAPON) && (player->isActive() || player->isMode(Simulation::Player::PRE_RELEASE)) && (player->getSide() == airVehicle->getSide())) { // our side has a weapon on-the-way/in-the-air; setMissileFired(true); finished=true; } } } #else // this state class has no way to determine whether we've fired a missile other than checking to see if sms is out of missiles to fire. // which means, it will fire all its missiles at first target. const Simulation::StoresMgr* stores = airVehicle->getStoresManagement(); if (stores != 0) { const Simulation::Missile* wpn = stores->getNextMissile(); if (!wpn) setMissileFired(true); } else { // we have no SMS, we can't fire a missile; setMissileFired(true); } #endif //const Basic::String* playerName = airVehicle->getName(); // DH - DOES NOT COMPILE WITH CONST -- ???? Simulation::AirVehicle* airVehicleX = const_cast<Simulation::AirVehicle*>(airVehicle); const Basic::Pair* sensorPair = airVehicleX->getSensorByType(typeid(Simulation::Radar)); if (sensorPair != nullptr) { const Simulation::Radar* radar = static_cast<const Simulation::Radar*>(sensorPair->object()); if (radar != nullptr) { const Simulation::TrackManager* trackManager = radar->getTrackManager(); Basic::safe_ptr<Simulation::Track> trackList[50]; unsigned int nTracks = trackManager->getTrackList(trackList, 50); for (int trackIndex = nTracks -1; trackIndex >= 0; trackIndex--) { setHeadingToTracked(trackIndex, trackList[trackIndex]->getRelAzimuth()); setPitchToTracked(trackIndex, trackList[trackIndex]->getElevation()); setDistanceToTracked(trackIndex, trackList[trackIndex]->getRange()); // do we have a live "target track"? (shootlist is 1-based) if (getTargetTrack()==MAX_TRACKS && (trackList[trackIndex]->getShootListIndex() == 1) && trackList[trackIndex]->getTarget()->isActive() ) { setTargetTrack(trackIndex); } setTracking(true); setNumTracks(nTracks); // hack to implement "missile warning" if (isIncomingMissile() == false) { // is this track a weapon, and if so, is it targeting me? Simulation::Player* target = trackList[trackIndex]->getTarget(); Simulation::Weapon* weapon = dynamic_cast<Simulation::Weapon*> (target); if (weapon!=nullptr && !weapon->isDead()) { Simulation::Player* wpntgt = weapon->getTargetPlayer(); if (wpntgt == airVehicle) { setIncomingMissile(true); } } } } } } const Simulation::OnboardComputer* oc = airVehicle->getOnboardComputer(); if (oc != nullptr) { const Simulation::TrackManager* rtm = oc->getTrackManagerByType(typeid(Simulation::RwrTrkMgr)); if(rtm !=nullptr) { Basic::safe_ptr<Simulation::Track> trackList[50]; unsigned int nTracks = rtm->getTrackList(trackList, 50); int newTracks = 0; for (unsigned int trackIndex = 0; trackIndex < nTracks; trackIndex++) { Simulation::Player* target = trackList[trackIndex]->getTarget(); bool alreadyTracked = false; for (unsigned int currTracks = 0; currTracks>getNumTracks(); currTracks++) { // tracks are the same if the associated players are the same if(trackList[currTracks]->getTarget()==target) { alreadyTracked = true; break; } } if (!alreadyTracked && (getNumTracks() + newTracks) < MAX_TRACKS) { int newTrackIndex = getNumTracks() + newTracks; newTracks++; setHeadingToTracked(newTrackIndex, trackList[trackIndex]->getRelAzimuth()); setPitchToTracked(newTrackIndex, trackList[trackIndex]->getElevation()); setDistanceToTracked(newTrackIndex, trackList[trackIndex]->getRange()); setTracking(true); // update numTracks to new sum of radar + rwr tracks setNumTracks(getNumTracks()+newTracks); } // do we have a live "target track"? (shootlist is 1-based) if (getTargetTrack()==MAX_TRACKS && (trackList[trackIndex]->getShootListIndex() == 1) && trackList[trackIndex]->getTarget()->isActive() ) { setTargetTrack(trackIndex); } // hack to implement "missile warning" if (isIncomingMissile() == false) { // is this track a weapon, and if so, is it targeting me? Simulation::Weapon* weapon = dynamic_cast<Simulation::Weapon*> (target); if (weapon!=nullptr && !weapon->isDead()) { Simulation::Player* wpntgt = weapon->getTargetPlayer(); if (wpntgt == airVehicle) { setIncomingMissile(true); } } } } } } } BaseClass::updateState(actor); }