Exemple #1
0
//------------------------------------------------------------------------------
// shutdownNotification() -- We're shutting down
//------------------------------------------------------------------------------
bool StoresMgr::shutdownNotification()
{
   // Notify the external stores that we're shutting down
   Basic::PairStream* list = getStores();
   if (list != 0) {
      Basic::List::Item* item = list->getFirstItem();
      while (item != 0) {
         Basic::Pair* pair = (Basic::Pair*)(item->getValue());
         Basic::Component* p = (Basic::Component*)( pair->object() );
         p->event(SHUTDOWN_EVENT);
         item = item->getNext();
      }
      list->unref();
      list = 0;
   }

   // Clear our stores
   setSlotStores(0);

   return BaseClass::shutdownNotification();
}
//------------------------------------------------------------------------------
// updateData() -- update non-time critical stuff here
//------------------------------------------------------------------------------
void Stores::updateData(const LCreal dt)
{
   // Update our non-weapon, external stores, which need to act as
   // active systems attached to our ownship player.
   {
      Basic::PairStream* list = getStores();
      if (list != nullptr) {
         Basic::List::Item* item = list->getFirstItem();
         while (item != nullptr) {
            Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
            ExternalStore* p = dynamic_cast<ExternalStore*>( pair->object() );
            if (p != nullptr) p->updateData(dt);
            item = item->getNext();
         }
         list->unref();
         list = nullptr;
      }
   }

   BaseClass::updateData(dt);
}
Exemple #3
0
//------------------------------------------------------------------------------
// copyData() -- copy member data
//------------------------------------------------------------------------------
void SymbolLoader::copyData(const SymbolLoader& org, const bool cc)
{
   BaseClass::copyData(org);
   if (cc) initData();

   // Clear the symbols; the user will need to
   // create these with the new template list.
   clearLoader();

   {
      Basic::PairStream* copy = 0;
      if (org.templates != 0) {
         copy = (Basic::PairStream*) org.templates->clone();
      }
      setSlotTemplates(copy);
      if (copy != 0) copy->unref();
   }

   showInRangeOnly = org.showInRangeOnly;
   interconnect = org.interconnect;
}
Exemple #4
0
//------------------------------------------------------------------------------
// setSlotJustification() -- 
//------------------------------------------------------------------------------                          
bool Field::setSlotJustification(const Basic::String* const sjobj)
{
    bool ok = true;
    if (sjobj != 0) {

        // Set our justification
        if ( *sjobj == "none" )
            justification(Basic::String::NONE);
        else if ( *sjobj == "left" )
            justification(Basic::String::LEFT);
        else if ( *sjobj == "center" )
            justification(Basic::String::CENTER);
        else if ( *sjobj == "right" )
            justification(Basic::String::RIGHT);
        else {
              if (isMessageEnabled(MSG_ERROR)) {
            std::cerr << "Field::setJustification: No proper inputs" << std::endl;
              }
            ok = false;
        }

        // Set our children's justification
        Basic::PairStream* subcomponents = getComponents();
        if (subcomponents != 0) {

            const Basic::List::Item* item = subcomponents->getFirstItem();
            while (item != 0) {
                Basic::Pair* p = (Basic::Pair*) item->getValue();
                Field* child = dynamic_cast<Field*>(p->object());
                if (child != 0) child->setSlotJustification(sjobj);
                item = item->getNext();
            }

            subcomponents->unref();
            subcomponents = 0;
        }
    }
    return ok;
}
//------------------------------------------------------------------------------
// getAllSteerpoints() -- Get all of the steerpoints in the route
//------------------------------------------------------------------------------
unsigned int Route::getAllSteerpoints(Basic::safe_ptr<Steerpoint>* const stptList, const unsigned int max)
{
    unsigned int i = 0;
    Basic::PairStream* steerpoints = getComponents();
    if (stptList != nullptr && max > 0 && steerpoints != nullptr) {
        Basic::List::Item* item = steerpoints->getFirstItem();
        while (item != nullptr && i < max) {
            Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
            Steerpoint* p = dynamic_cast<Steerpoint*>(pair->object());
            if (p != nullptr) {
                stptList[i++] = p;
            }
            item = item->getNext();
        }
    }

    if (steerpoints != nullptr) {
       steerpoints->unref();
       steerpoints = nullptr;
    }

    return i;
}
Exemple #6
0
Missile* SimpleStoresMgr::getNextMissileImp()
{
   Missile* msl = 0;

   Basic::PairStream* list = getWeapons();
   if (list != 0) {

      Basic::List::Item* item = list->getFirstItem();
      while (item != 0 && msl == 0) {
         Basic::Pair* pair = (Basic::Pair*) item->getValue();
         Missile* p = dynamic_cast<Missile*>( pair->object() );
         if (p != 0) {
            if (p->isInactive() || p->isReleaseHold()) {
               msl = (Missile*) p->getPointer();
            }
         }
         item = item->getNext();
      }
      list->unref();
   }

   return msl;
}
Exemple #7
0
// set our slot values via a pairstream
bool ColorRotary::setSlotValues(const Basic::PairStream* const newStream)
{
    bool ok = false;
    numVals = 0;
    if (newStream != nullptr) {
        Basic::PairStream* a = newStream->clone();
        Basic::List::Item* item = a->getFirstItem();
        while (item != nullptr) {
            Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
            if (pair != nullptr) {
                Basic::Number* n = dynamic_cast<Basic::Number*>(pair->object());
                if (n != nullptr) {
                    myValues[numVals] = n->getReal();
                    numVals++;
                }
            }
            item = item->getNext();
        }
        ok = true;
        a->unref();
    }
    return ok;
}
Exemple #8
0
Decoy* SimpleStoresMgr::getNextDecoyImp()
{
   Decoy* decoy = 0;

   Basic::PairStream* list = getWeapons();
   if (list != 0) {

      Basic::List::Item* item = list->getFirstItem();
      while (item != 0 && decoy == 0) {
         Basic::Pair* pair = (Basic::Pair*) item->getValue();
         Decoy* p = dynamic_cast<Decoy*>( pair->object() );
         if (p != 0) {
            if (p->isInactive() || p->isReleaseHold()) {
               decoy = (Decoy*) p->getPointer();
            }
         }
         item = item->getNext();
      }

      list->unref();
   }

   return decoy;
}
Exemple #9
0
Flare* SimpleStoresMgr::getNextFlareImp()
{
   Flare* flare = 0;

   Basic::PairStream* list = getWeapons();
   if (list != 0) {

      Basic::List::Item* item = list->getFirstItem();
      while (item != 0 && flare == 0) {
         Basic::Pair* pair = (Basic::Pair*) item->getValue();
         Flare* p = dynamic_cast<Flare*>( pair->object() );
         if (p != 0) {
            if (p->isInactive() || p->isReleaseHold()) {
               flare = (Flare*) p->getPointer();
            }
         }
         item = item->getNext();
      }

      list->unref();
   }

   return flare;
}
Exemple #10
0
Chaff* SimpleStoresMgr::getNextChaffImp()
{
   Chaff* chaff = 0;

   Basic::PairStream* list = getWeapons();
   if (list != 0) {

      Basic::List::Item* item = list->getFirstItem();
      while (item != 0 && chaff == 0) {
         Basic::Pair* pair = (Basic::Pair*) item->getValue();
         Chaff* p = dynamic_cast<Chaff*>( pair->object() );
         if (p != 0) {
            if (p->isInactive() || p->isReleaseHold()) {
               chaff = (Chaff*) p->getPointer();
            }
         }
         item = item->getNext();
      }

      list->unref();
   }

   return chaff;
}
Exemple #11
0
Bomb* SimpleStoresMgr::getNextBombImp()
{
   Bomb* bomb = 0;

   Basic::PairStream* list = getWeapons();
   if (list != 0) {

      Basic::List::Item* item = list->getFirstItem();
      while (item != 0 && bomb == 0) {
         Basic::Pair* pair = (Basic::Pair*) item->getValue();
         Bomb* p = dynamic_cast<Bomb*>( pair->object() );
         if (p != 0) {
            if (p->isInactive() || p->isReleaseHold()) {
               bomb = (Bomb*) p->getPointer();
            }
         }
         item = item->getNext();
      }

      list->unref();
   }

   return bomb;
}
void TableRow::position()
{
   // position the fields in this table item
   Basic::PairStream* subcomponents = getComponents();
   if (subcomponents != 0) {
   
      int ln = line();
      int cp = column();
      
      Basic::List::Item* item = subcomponents->getFirstItem();
      while (item != 0) {
         Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
         BasicGL::Field* ti = static_cast<BasicGL::Field*>(pair->object());
        
         ti->line(ln);
         ti->column(cp);
         cp += static_cast<int>(ti->width());
         
         item = item->getNext();
      }
      subcomponents->unref();
      subcomponents = 0;
   }
}
//------------------------------------------------------------------------------
// position() -- position the rows in this table
//------------------------------------------------------------------------------
void Table::position()
{
   Basic::PairStream* subcomponents = getComponents();
   if (subcomponents != 0) {
   
      int ln = line();
      int cp = column();

      // Position our subcomponents, which are all TableRow objects (see build())
      Basic::List::Item* item = subcomponents->getFirstItem();
      while (item != 0) {
         Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
         TableRow* row = static_cast<TableRow*>(pair->object());

         row->line(ln);
         row->column(cp);
         ln += spacing;

         item = item->getNext();
      }
      subcomponents->unref();
      subcomponents = 0;
   }
}
void LifeForm::look(const LCreal up, const LCreal sdws)
{
    if (getDamage() < 1) {
        if (lockMode != LOCKED) {
            lockMode = SEARCHING;
            // our up and sideways come in as -5 to 5, which is a rate to adjust heading
            const osg::Vec3 old = getEulerAngles();
            LCreal hdg = old.z();
            LCreal ptc = lookAngle;
            LCreal tempSdws = sdws;
            LCreal tempUp = up;
            if (lcAbs(tempSdws) < 0.00005) tempSdws = 0;
            if (lcAbs(tempUp) < 0.05) tempUp = 0;
            hdg += tempSdws;
            hdg = lcAepcRad(hdg);
            // we don't change our pitch when we look up and down, we only change our look angle, so we have to keep
            // that separate.  WE do, however, change our heading based on where we are looking, so that is correct
            ptc += tempUp;
            if (ptc > 90) ptc = 90;
            else if (ptc < -90) ptc = -90;
            //std::cout << "HEADING = " << hdg << std::endl;
            setLookAngle(ptc);
            osg::Vec3 eul(0, 0, hdg);
            setEulerAngles(eul);
            // now based on this we need to know if we have a target in our crosshairs...
            tgtAquired = false;
            if (tgtPlayer != nullptr) tgtPlayer->unref();
            tgtPlayer = nullptr;
            const osg::Vec3 myPos = getPosition();
            osg::Vec3 tgtPos;
            osg::Vec3 vecPos;
            LCreal az = 0.0, el = 0.0, range = 0.0, diffAz = 0.0, diffEl = 0.0;
            const LCreal maxAz = (0.7f * static_cast<LCreal>(Basic::Angle::D2RCC));
            const LCreal maxEl = (0.7f * static_cast<LCreal>(Basic::Angle::D2RCC));
            //LCreal maxRange = 1500.0f; // long range right now
            const LCreal la = lookAngle * static_cast<LCreal>(Basic::Angle::D2RCC);
            Simulation* sim = getSimulation();
            if (sim != nullptr) {
                Basic::PairStream* players = sim->getPlayers();
                if (players != nullptr) {
                    Basic::List::Item* item = players->getFirstItem();
                    while (item != nullptr && !tgtAquired) {
                        Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
                        if (pair != nullptr) {
                            Player* player = dynamic_cast<Player*>(pair->object());
                            if (player != nullptr && player != this && !player->isMajorType(WEAPON) && !player->isDestroyed()) {
                                // ok, calculate our position from this guy
                                tgtPos = player->getPosition();
                                vecPos = tgtPos - myPos;
                                az = lcAtan2(vecPos.y(), vecPos.x());
                                range = (vecPos.x() * vecPos.x() + vecPos.y() * vecPos.y());
                                range = std::sqrt(range);
                                // now get our elevation
                                el = lcAtan2(-vecPos.z(), range);
                                diffAz = lcAbs(lcAepcRad(az - static_cast<LCreal>(getHeadingR())));
                                diffEl = lcAbs(lcAepcRad(la - el));
                                if ((diffAz <= maxAz) && (diffEl <= maxEl)) {
                                    lockMode = TGT_IN_SIGHT;
                                    tgtAquired = true;
                                    if (tgtPlayer != player) {
                                        if (tgtPlayer != nullptr) tgtPlayer->unref();
                                        tgtPlayer = player;
                                        tgtPlayer->ref();
                                    }
                                }
                            }
                        }
                        item = item->getNext();
                    }
                    players->unref();
                    players = nullptr;
                }
            }
        }
        // else we are locking on target, and need to follow our target player
        else {
            if (tgtPlayer == nullptr) lockMode = SEARCHING;
            else {
                const osg::Vec3 vecPos = tgtPlayer->getPosition() - getPosition();
                const LCreal az = lcAtan2(vecPos.y(), vecPos.x());
                LCreal range = (vecPos.x() * vecPos.x() + vecPos.y() * vecPos.y());
                range = std::sqrt(range);
                // now get our elevation
                const LCreal el = lcAtan2(-vecPos.z(), range);
                // now force that on us
                setLookAngle(el * static_cast<LCreal>(Basic::Angle::R2DCC));
                setEulerAngles(0, 0, az);
            }
        }
    }
}
void  TableRow::put(Basic::Pair* pp)
{
   Basic::PairStream* subcomponents = getComponents();
   BaseClass::processComponents(subcomponents, typeid(BasicGL::Field), pp);
   if (subcomponents != 0) subcomponents->unref();
}
Exemple #16
0
//------------------------------------------------------------------------------
// Initializes the channel array
//------------------------------------------------------------------------------
void QuadMap::findDataFiles()
{
   // Clear out the old ones
   clearData();

   // Find the DataFile objects
   {
      Basic::PairStream* subcomponents = getComponents();
      if (subcomponents != nullptr) {
         unsigned int count = 0;
         Basic::List::Item* item = subcomponents->getFirstItem();
         while (item != nullptr && count < MAX_DATA_FILES) {
            Basic::Pair* pair = static_cast<Basic::Pair*>( item->getValue() );
            Basic::Terrain* dataFile = dynamic_cast<Basic::Terrain*>( pair->object() );
            if (dataFile != nullptr && dataFile->isDataLoaded()) {
               dataFile->ref();
               dataFiles[count] = dataFile;
               count++;
            }
            item = item->getNext();
         }
         numDataFiles = count;
         subcomponents->unref();
         subcomponents = nullptr;
      }
   }

   // Find the max/min elevations and the corner points
   if (numDataFiles > 0) {
      LCreal elevMin =  999999.0;
      LCreal elevMax = -999999.0;
      double lowerLat = 90.0;
      double lowerLon = 180.0;
      double upperLat = -90.0;
      double upperLon = -180.0;
      for (unsigned int i = 0; i < numDataFiles; i++) {

         if (dataFiles[i]->getMinElevation() < elevMin)
            elevMin = dataFiles[i]->getMinElevation();

         if (dataFiles[i]->getMaxElevation() > elevMax)
            elevMax = dataFiles[i]->getMaxElevation();

         if (dataFiles[i]->getLatitudeSW() < lowerLat)
            lowerLat = dataFiles[i]->getLatitudeSW();

         if (dataFiles[i]->getLongitudeSW() < lowerLon)
            lowerLon = dataFiles[i]->getLongitudeSW();

         if (dataFiles[i]->getLatitudeNE() > upperLat)
            upperLat = dataFiles[i]->getLatitudeNE();

         if (dataFiles[i]->getLongitudeNE() > upperLon)
            upperLon = dataFiles[i]->getLongitudeNE();

      }

      setMinElevation(elevMin);
      setMaxElevation(elevMax);
      setLatitudeSW(lowerLat);
      setLongitudeSW(lowerLon);
      setLatitudeNE(upperLat);
      setLongitudeNE(upperLon);

   }
   else {
      setMinElevation(0);
      setMaxElevation(0);
      setLatitudeSW(0);
      setLongitudeSW(0);
      setLatitudeNE(0);
      setLongitudeNE(0);
   }

}
Exemple #17
0
//------------------------------------------------------------------------------
// updateTC() -- update time critical stuff here
//------------------------------------------------------------------------------
void Station::updateTC(const LCreal dt)
{
   // Update the Basic::Timers
   if (isUpdateTimersEnabled()) {
      Basic::Timer::updateTimers(dt);
   }

   // The I/O handers
   if (ioHandlers != 0) {
      Basic::List::Item* item = ioHandlers ->getFirstItem();
      while (item != 0) {
         Basic::Pair* pair = (Basic::Pair*)(item->getValue());
         Basic::IoHandler* p = (Basic::IoHandler*)( pair->object() );
         p->tcFrame(dt);
         item = item->getNext();
      }
   }

   // Process station inputs
   inputDevices(dt);

   // Update the simulation 
   if (sim != 0) sim->tcFrame(dt);

   // Process station outputs
   outputDevices(dt);

   // Our major subsystems
   if (sim != 0 && otw != 0) {
      Basic::PairStream* playerList = sim->getPlayers();
      Basic::List::Item* item = otw->getFirstItem();
      while (item != 0) {

         Basic::Pair* pair = (Basic::Pair*)(item->getValue());
         Otw* p = (Otw*)( pair->object() );

         // Set ownship & player list
         p->setOwnship(ownship);
         p->setPlayerList(playerList);

         // TC frame
         p->tcFrame(dt);

         item = item->getNext();
      }
      if (playerList != 0) playerList->unref();
   }

   // Startup RESET timer --
   //    Sends an initial RESET pulse after timeout
   //    (Some simulation may need this)
   if (startupResetTimer >= 0) {
      startupResetTimer -= dt;
      if (startupResetTimer < 0) {
         this->event(RESET_EVENT);
      }
   }

   // Update the base class data
   BaseClass::updateTC(dt);
}
Exemple #18
0
//------------------------------------------------------------------------------
// emitterBeamsManager()
//    -- (Output) Manages the emitter beam for this NIB(Player)
//------------------------------------------------------------------------------
bool Nib::emitterBeamsManager(const LCreal curExecTime)
{
   // ---
   // First, find all of our player's RfSensor systems and setup their handlers
   // ---
   if ( numEmissionSystems == 0 ) {

      // Check for the single-beam RADAR
      {
         // (DPG -- #### only a simple, single-beam Radar)
         const Basic::Pair * pair = getPlayer()->getSensorByType(typeid(Simulation::Radar));
         if (pair != nullptr) {
            Simulation::RfSensor* rs = (Simulation::RfSensor*) pair->object();

            // When we have a R/F sensor, create a handler for it
            EmissionPduHandler* handler = nullptr;

            // First, try to find an Emission PDU handler for this type system.
            // If we find one, then clone it for our use.
            NetIO* const disIO = static_cast<NetIO*>(getNetIO());
            const EmissionPduHandler* tmp = disIO->findEmissionPduHandler(rs);
            if (tmp != nullptr) {
               handler = tmp->clone();
            }

            // Handler wasn't found? Then just create a simple, default emission handler
            if (handler == nullptr) {
               handler = new EmissionPduHandler();
            }

            handler->setSensor( rs );
            handler->setEmitterIdNumber( numEmissionSystems + 1 );
            emitterSysHandler[numEmissionSystems] = handler;
            numEmissionSystems++;
         }
      } // end radar check

      // Check for a Jammer
      {
         const Basic::Pair * pair = getPlayer()->getSensorByType(typeid(Simulation::Jammer));
         if (pair != nullptr) {
            Simulation::RfSensor* js = (Simulation::RfSensor*) pair->object();

            bool singleBeam = true;
            Basic::PairStream* subcomponents = js->getComponents();
            if (subcomponents != nullptr) {

               // Check for multi-beam jammer (each beam is a subcomponent Jammer)
               Basic::List::Item* item = subcomponents->getFirstItem();
               while (item != nullptr && numEmissionSystems < MAX_EM_SYSTEMS) {

                  Basic::Pair* pair = static_cast<Basic::Pair*>( item->getValue() );
                  Simulation::Jammer* jam = dynamic_cast<Simulation::Jammer*>( pair->object() );
                  if (jam != nullptr) {
                     singleBeam = false;

                     // When we have a R/F sensor, create a handler for it
                     EmissionPduHandler* handler = nullptr;

                     // First, try to find an Emission PDU handler for this type system.
                     // If we find one, then clone it for our use.
                     NetIO* const disIO = static_cast<NetIO*>(getNetIO());
                     const EmissionPduHandler* tmp = disIO->findEmissionPduHandler(jam);
                     if (tmp != nullptr) {
                        handler = tmp->clone();
                     }

                     // Handler wasn't found? Then just create a simple, default handler
                     if (handler == nullptr) {
                        handler = new EmissionPduHandler();
                        handler->setEmitterFunction(EmissionPduHandler::ESF_JAMMING);
                     }

                     handler->setSensor( jam );
                     handler->setEmitterIdNumber( numEmissionSystems + 1 );
                     emitterSysHandler[numEmissionSystems] = handler;
                     numEmissionSystems++;

                  }
                  item = item->getNext();
               }

               subcomponents->unref();
               subcomponents = nullptr;
            }

            // Single beam jammer
            if (singleBeam && numEmissionSystems < MAX_EM_SYSTEMS) {

               // When we have a R/F sensor, create a handler for it
               EmissionPduHandler* handler = nullptr;

               // First, try to find an Emission PDU handler for this type system.
               // If we find one, then clone it for our use.
               NetIO* const disIO = static_cast<NetIO*>(getNetIO());
               const EmissionPduHandler* tmp = disIO->findEmissionPduHandler(js);
               if (tmp != nullptr) {
                  handler = tmp->clone();
               }

               // Handler wasn't found? Then just create a simple, default jammer handler
               if (handler == nullptr) {
                  handler = new EmissionPduHandler();
                  handler->setEmitterFunction(EmissionPduHandler::ESF_JAMMING);
               }

               handler->setSensor( js );
               handler->setEmitterIdNumber( numEmissionSystems + 1 );
               emitterSysHandler[numEmissionSystems] = handler;
               numEmissionSystems++;

            }

         }

      }  // end jammer check

   }  // end (numEmissionSystems == 0)

   // ---
   // Have the handlers check their electromagnetic emission systems
   // and generate the PDUs as needed.
   // ---
   for (emissionSystemsIndex = 0; emissionSystemsIndex < numEmissionSystems; emissionSystemsIndex++) {
      if (emitterSysHandler[emissionSystemsIndex] != nullptr) {
         emitterSysHandler[emissionSystemsIndex]->updateOutgoing(curExecTime, this);
      }
   }

   return true;
}
Exemple #19
0
//------------------------------------------------------------------------------
// sendMessage() -- send the datalink message out to the world.
//------------------------------------------------------------------------------
bool Datalink::sendMessage(Basic::Object* const msg)
{
   bool sent = false;

   // If we can send to our local players directly (or via radio)
   if (sendLocal) {
      // ---
      // Have a comm radio -- then we'll just let our companion radio system handle this
      // ---
      if (radio != 0) {
         sent = radio->transmitDataMessage(msg);
      }

      // ---
      // No comm radio -- then we'll send this out to the other players ourself.
      // ---
      else if (getOwnship() != 0) {
         Simulation* sim = getSimulation();
         if (sim != 0) {

            Basic::PairStream* players = sim->getPlayers();
            if (players != 0) {

            Basic::List::Item* playerItem = players->getFirstItem();
            while (playerItem != 0) {

               Basic::Pair* playerPair = static_cast<Basic::Pair*>(playerItem->getValue());
               Player* player = static_cast<Player*>(playerPair->object());

               if (player->isLocalPlayer()) {
                  // Send to active, local players only (and not to ourself)
                     if ((player->isActive() || player->isMode(Player::PRE_RELEASE)) && player != getOwnship() ) {
                     player->event(DATALINK_MESSAGE, msg);
                  }
                  playerItem = playerItem->getNext();
               }
               else {
                  // Networked players are at the end of the list,
                  // so we can stop now.
                  playerItem = 0;
               }

            }

               players->unref();
               players = 0;
            }
         }
         sent = true;
      }
   }

   // ---
   // and let any (optional) outgoing queue know about this.
   // ---
   if (queueForNetwork) {
      Player* ownship = getOwnship();
      if (ownship != 0) {
         if (ownship->isLocalPlayer()) {
            queueOutgoingMessage(msg);
         }
      }
   }

   return sent;
}
Exemple #20
0
//------------------------------------------------------------------------------
// copyData() -- copy member data
//------------------------------------------------------------------------------
void Station::copyData(const Station& org, const bool cc)
{
   BaseClass::copyData(org);
   if (cc) initData();

   // Terminate any old threads
   setTcThread(0);
   setNetThread(0);
   setBgThread(0);

   // Set the simulation exec
   if (org.sim != 0) {
      Simulation* copy = (Simulation*) org.sim->clone();
      setSlotSimulation( copy );
      copy->unref();
   }
   else {
      setSlotSimulation(0);
   }

   // Copy the OTW handlers
   if (org.otw != 0) {
      Basic::PairStream* copy = (Basic::PairStream*) org.otw->clone();
      setSlotOutTheWindow( copy );
      copy->unref();
   }
   else {
      setSlotOutTheWindow((Basic::PairStream*)0);
   }

   // Copy the networks
   if (org.networks != 0) {
      Basic::PairStream* copy = (Basic::PairStream*) org.networks->clone();
      setSlotNetworks( copy );
      copy->unref();
   }
   else {
      setSlotNetworks((Basic::PairStream*)0);
   }

   // Copy the I/O handlers
   if (org.ioHandlers != 0) {
      Basic::PairStream* copy = (Basic::PairStream*) org.ioHandlers->clone();
      setSlotIoHandler( copy );
      copy->unref();
   }
   else {
      setSlotIoHandler((Basic::PairStream*)0);
   }

   tcRate = org.tcRate;
   tcPri = org.tcPri;
   fastForwardRate = org.fastForwardRate;

   netRate = org.netRate;
   netPri = org.netPri;

   bgRate = org.bgRate;
   bgPri = org.bgPri;

   tmrUpdateEnbl = org.tmrUpdateEnbl;

   if (org.startupResetTimer0!= 0) {
      Basic::Time* copy = (Basic::Time*) org.startupResetTimer0->clone();
      setSlotStartupResetTime( copy );
      copy->unref();
   }
   else {
      setSlotStartupResetTime(0);
   }

   startupResetTimer = org.startupResetTimer;

   // Unref our old stuff (if any)
   if (ownshipName != 0) { ownshipName->unref(); ownshipName = 0; }
   if (ownship != 0)     { ownship->unref(); ownship = 0; }

   // Copy own ownship name
   if (org.ownshipName != 0) {
      ownshipName = dynamic_cast<Basic::String*> (org.ownshipName->clone() );
   }

   // Attach our ownship
   setOwnshipByName( *ownshipName );
}
Exemple #21
0
// Set the stores
bool Stores::setSlotStores(const Basic::PairStream* const msg)
{
   // ---
   // Quick out if the number of stations hasn't been set.
   // ---
   if (ns == 0 && msg != 0) {
      std::cerr << "Stores::setSlotStation() Number of stations is not set!" << std::endl;
      return false;
   }

   // ---
   // Clear the previous stores and assigned weapons
   // ---
   storesList = 0;
   for (unsigned int s = 1; s <= ns; s++) {
      assignWeaponToStation(s,0);
      assignExtStoreToStation(s,0);
   }
   numWpn = 0;
   numEs = 0;

   // ---
   // Quick out if 'msg' is zero 
   // ---
   if (msg == 0) return true;

   bool ok = true;

   // ---
   // Create the new external stores list
   //
   // For all items in the 'msg' list ...
   //   -- Make sure that it's a weapon or other type of external store, and
   //      that it has a valid station number.
   //   -- Clone the store and if it's a weapon then assign it to the station.
   // ---
   Basic::PairStream* newStores = new Basic::PairStream();

   const Basic::List::Item* item = msg->getFirstItem();
   while (item != 0) {

      const Basic::Pair* pair = static_cast<const Basic::Pair*>(item->getValue());
      const Basic::Component* p = static_cast<const Basic::Component*>(pair->object());
      if (p != 0) {

         // get the station number from the stores' slot name
         int stationNumber = 0;
         const Basic::Identifier* stationName = pair->slot();
         if (stationName->isInteger()) {
            stationNumber = stationName->getInteger();
         }

         if (stationNumber > 0 && stationNumber <= static_cast<int>(ns)) {

            // check the type of component
            bool isWpn = p->isClassType(typeid(Weapon));
            bool isEE  = p->isClassType(typeid(ExternalStore));

            if ( isWpn || isEE ) {
               // Clone the weapon pair and set us as its container
               Basic::Pair* cpair = pair->clone();
               Component* cp = static_cast<Component*>(cpair->object());
               cp->container(this);

               if ( isWpn ) {
                  // Weapon types ...

                  // Assign the weapon to the station
                  Weapon* cwpn = static_cast<Weapon*>( cpair->object() );
                  assignWeaponToStation(stationNumber, cwpn);

               }

               if ( isEE ) {
                  // External stores types ...

                  // Assign the external store to the station
                  ExternalStore* cwpn = static_cast<ExternalStore*>( cpair->object() );
                  assignExtStoreToStation(stationNumber, cwpn);
               }

               if (cpair != 0) {
                  // Add to the new stores list
                  newStores->put(cpair);
                  cpair->unref(); // the new list has it.
               }
            }
            else {
               std::cerr << "Stores::setSlotStores(): invalid external stores type; use Weapon or Stores classes" << std::endl;
               ok = false;
            }

         }
         else {
            std::cerr << "Stores::setSlotStores(): invalid station number from the store's slot name." << std::endl;
            ok = false;
         }
      }

      item = item->getNext();
   }

   // Make the new stores list the active list
   if (ok && newStores->entries() > 0) {
      storesList = newStores;
   }
   else {
      for (unsigned int s = 1; s <= ns; s++) {
         assignWeaponToStation(s,0);
      }
      numWpn = 0;
   }

   newStores->unref();

   return ok;
}
//------------------------------------------------------------------------------
// insertSteerpoint() -
//------------------------------------------------------------------------------
bool Route::insertSteerpoint(Steerpoint* const newStpt, const int pos)
{
    bool ok = false;
    unsigned int num = getNumberOfSteerpoints();
    // make a new character string
    char numString[10];

    // this tells us the number of the next steerpoint to be created in the slot list
    std::sprintf(numString,"%i",(num+1));

    // now we have the slot name, which is the next number in the steerpoint list
    // now create a new pair, and if we have a component list, add it to it, if
    // not, then create a new component list
    Basic::Pair* p = new Basic::Pair(numString, newStpt);
    if (p != nullptr) {

        // We're its container
        newStpt->container(this);

        // Get our steerpoints
        Basic::PairStream* steerpoints = getComponents();

        // now we have to add it to our component list
        if (steerpoints != nullptr && num != 0) {

            // Copy the current steerpoint list
            Basic::PairStream* tempList = new Basic::PairStream();
            {
               Basic::List::Item* item = steerpoints->getFirstItem();
               while (item != nullptr) {
                  Basic::Pair* pair = (Basic::Pair*) item->getValue();
                  tempList->put(pair);
                  item = item->getNext();
               }
            }

            if (pos == -1) {
               tempList->addHead(p);
               ok = true;
            }

            else if (pos == 0 || pos > num) {
               tempList->addTail(p);
               ok = true;
            }

            else if (pos > 0 && pos <= static_cast<int>(num)) {

                // count to our position, then insert it
                int counter = 1;
                Basic::List::Item* item = tempList->getFirstItem();
                while (counter < pos && item != nullptr) {
                    item = item->getNext();
                    counter++;
                }

                // now we should have the reference pair at the 'pos' position
                if (item != nullptr) {
                    Basic::List::Item* newItem = new Basic::List::Item;
                    newItem->value = p;
                    p->ref();
                    // insert 'newItem' just before 'item'
                    ok = tempList->insert(newItem, item);
                }
            }

            // swap our current steerpoint (components) list for this new one
            if (ok) {
               Basic::Component::processComponents(tempList,typeid(Steerpoint));
            }

            tempList->unref();
            tempList = nullptr;

        }

        // if we have no components, we need to start a new component list
        else {
            Basic::Component::processComponents(nullptr, typeid(Steerpoint), p);
            ok = true;
        }

        // Unref the original steerpoint list
        if (steerpoints != nullptr) {
            steerpoints->unref();
            steerpoints = nullptr;
        }

        p->unref();  // Our component list has it now.
    }

    // ---
    // Call directTo() to reset the steerpoint index, or if we were going nowhere
    // then go direct-to steerpoint one.
    // ---
    if (ok) {
       if (to != nullptr) {
         Steerpoint* sp = static_cast<Steerpoint*>(to->object());
         directTo(sp);
       }
       else {
         directTo(1);
       }
    }

    return ok;

}
Exemple #23
0
//------------------------------------------------------------------------------
// checkForTargetHit() -- check to see if we hit anything
//------------------------------------------------------------------------------
bool Bullet::checkForTargetHit()
{
   Player* ownship = getLaunchVehicle();
   Player* tgt = getTargetPlayer();
   if (ownship != nullptr && tgt != nullptr) {
      osg::Vec3 osPos = tgt->getPosition();

      // For all active bursts ...
      for (int i = 0; i < nbt; i++) {
         if (bursts[i].bStatus == Burst::ACTIVE) {

            // Check if we're within range of the target
            osg::Vec3 rPos = bursts[i].bPos - osPos;
            LCreal rng = rPos.length();
            if (rng < 10.0) {
               // Yes -- it's a hit!
               bursts[i].bStatus = Burst::HIT;
               setHitPlayer(tgt);
               setLocationOfDetonation();
               tgt->processDetonation(rng,this);
            }

         }
      }
   }
   // if we are just flying along, check our range to the nearest player and tell him we killed it
   else {
        //osg::Vec3 old = getEulerAngles();
        osg::Vec3 myPos = getPosition();
        osg::Vec3 tgtPos;
        osg::Vec3 vecPos;
        //LCreal az = 0;
        //LCreal el = 0;
        LCreal range = 0;
        //LCreal diffAz = 0;
        //LCreal diffEl = 0;
        LCreal maxRange = 1; // close range of detonation
        Simulation* sim = getSimulation();
        if (sim != nullptr) {
            Basic::PairStream* players = sim->getPlayers();
            if (players != nullptr) {
                Basic::List::Item* item = players->getFirstItem();
                while (item != nullptr) {
                    Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
                    if (pair != nullptr) {
                        Player* player = dynamic_cast<Player*>(pair->object());
                        if (player != nullptr && player != ownship && player->isMajorType(LIFE_FORM) && !player->isDestroyed()) {
                            // ok, calculate our position from this guy
                            tgtPos = player->getPosition();
                            vecPos = tgtPos - myPos;
                            //az = lcAtan2(vecPos.y(), vecPos.x());
                            range = (vecPos.x() * vecPos.x() + vecPos.y() * vecPos.y());
                            range = std::sqrt(range);
                            if (range < maxRange) {
                                // tell this target we hit it
                                player->processDetonation(range, this);
                            }
                        }
                    }
                    item = item->getNext();
                }
                players->unref();
                players = nullptr;
            }
        }

   }
   return false;
}