Ejemplo n.º 1
0
//-----------------------------------------------------------------------------
// setSlotOutTheWindow() -- Sets a list of Out-The-Window subsystems
//-----------------------------------------------------------------------------
bool Station::setSlotOutTheWindow(Otw* const p)
{
    Basic::PairStream* list = new Basic::PairStream();
    list->put( new Basic::Pair("1",p) );
    bool ok = setSlotOutTheWindow(list);
    list->unref();
    return ok;
}
Ejemplo n.º 2
0
//------------------------------------------------------------------------------
// build() -- build the table in our components list
//------------------------------------------------------------------------------
void Table::build()
{
   Basic::PairStream* newList = 0;

   if (rows > 0 && columns != 0) {

      newList = new Basic::PairStream();

      // For each row: create a TableRow containing all the items in 'columns'
      for (unsigned int i = 1; i <= rows; i++) {

         // new row
         TableRow* row = new TableRow(); 
         row->container(this);

         const Basic::List::Item* item = columns->getFirstItem();
         while (item != 0) {
            const Basic::Pair* pair = static_cast<const Basic::Pair*>(item->getValue());
            const Basic::Object* obj = pair->object();
            if (obj->isClassType(typeid(BasicGL::Graphic))) {
               Basic::Pair* pp = pair->clone();
               BasicGL::Graphic* gobj = static_cast<BasicGL::Graphic*>(pp->object());
               gobj->container(row);
               row->put(pp);
               pp->unref();
            }

            item = item->getNext();
         }

         // put the row on our components list with a slotname equal to its row number
         {
            char cbuf[8];
            sprintf(cbuf,"%d",i);
            Basic::Pair* pp = new Basic::Pair(cbuf,row);
            newList->put(pp);
            pp->unref();
         }

         row->unref();
      }

      // Position our subcomponents
      position();
   }

   // These are new our subcomponents ...
   processComponents(newList,typeid(Basic::Component));
   if (newList != 0) newList->unref();
}
Ejemplo n.º 3
0
bool Station::setSlotOutTheWindow(Basic::PairStream* const list)
{
   Basic::PairStream* newList = 0;

   // Make sure the new list only has OTW type objects
   if (list != 0) {
      for (Basic::List::Item* item = list->getFirstItem(); item != 0; item = item->getNext()) {
            Basic::Pair* pair = (Basic::Pair*)(item->getValue());
            Otw* p = dynamic_cast<Otw*>( pair->object() );
            if (p != 0) {
            if (newList == 0) {
               newList = new Basic::PairStream();
            }
            newList->put(pair);  // Add this OTW to our new OTW list
                p->container(this);
            }
         else if (isMessageEnabled(MSG_WARNING)) {
                // Not of the proper type
                std::cerr << "Player::setOutTheWindow: OTW at slot \"" << pair->slot() << "\" is not of type Otw" << std::endl;
            }
        }
    }

   // Remove the old OTW interfaces
   if (otw != 0) {

      SPtr<Basic::PairStream> oldList( otw );
      otw = 0;

      // we are no longer the container for these old OTW interfaces
      for (Basic::List::Item* item = oldList->getFirstItem(); item != 0; item = item->getNext()) {
         Basic::Pair* pair = (Basic::Pair*)(item->getValue());
         Component* p = (Component*)( pair->object() );
         p->container(0);
      }
   }

   // Set the pointer to the list of OTW interfaces
   otw = newList;

   return true;
}
Ejemplo n.º 4
0
bool Table::setSlotColumns(Basic::PairStream* const msg)
{
   if (columns != 0) { columns->unref(); columns = 0; }
   if (msg != 0) {
      // Make a copy of the list and Make sure we have only Field objexts
      Basic::PairStream* newColumns = new Basic::PairStream();
      Basic::List::Item* item = msg->getFirstItem();
      while (item != 0) {
          Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue());
          BasicGL::Field* g = dynamic_cast<BasicGL::Field*>(pair->object());
          if (g != 0) {
              // We have a Field object, so add it to the new columns list
              newColumns->put(pair);
          }
          item = item->getNext();
      }
      columns = newColumns;
   }
   build();
   return true;
}
Ejemplo n.º 5
0
//------------------------------------------------------------------------------
// 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;

}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
0
//-----------------------------------------------------------------------------
// setSlotIoHandler() -- Sets a list of I/O handlers
//-----------------------------------------------------------------------------
bool Station::setSlotIoHandler(Basic::IoHandler* const p)
{
    Basic::PairStream* list = new Basic::PairStream();
    list->put( new Basic::Pair("1",p) );
    return setSlotIoHandler(list);
}