Exemplo n.º 1
0
//------------------------------------------------------------------------------
// mapPlayers2ElevTable() - Map the player list to the model table
//------------------------------------------------------------------------------
void Otw::mapPlayers2ElevTable()
{
   // Set all entries as unciecked
   for (unsigned int i = 0; i < getElevationTableSize(); i++) {
      hotTbl[i]->setCheckedFlag(false);
   }

   // When we have a player list ...
   if (playerList != 0) {

      // ---
      // Find players that are alive and require terrain elevation from the visual system ...
      // ---
      Basic::List::Item* item = playerList->getFirstItem();
      while (item != 0) {

         // Get a pointer to the player, 'p'
         Basic::Pair* pair = dynamic_cast<Basic::Pair*>(item->getValue());
         Player* p = (Player*) pair->object();

         // Check if this player is alive and within range.
         if ( p->isActive() && p->isTerrainElevationRequired() ) {

            // Check if in-range
            bool inRange = computeRangeToPlayer(p) <= maxRange;
            
            if (inRange) {
            
               // Find the player's model entry (if any)
               OtwModel* model = findModel(p, HOT_TABLE);

               if (model != 0) {
                  // The player has a valid entry.
                  model->incReqCount();
               }
               else {
                  // Player doesn't have an entry, so create one.
                  model = newElevEntry(p);
               }
               if (model != 0) model->setCheckedFlag(true);
            }

         }

         //completed  = p->isNetworkedPlayer();
         item = item->getNext(); // Next player
      }
   }

   // ---
   // Remove unmatched model entries; their players are inactive or no longer
   // require terrain elevation
   // ---
   for (int i = getElevationTableSize(); i > 0; --i) {
      if ( hotTbl[i-1]->isNotChecked() ) {
         // Deleting this entry
         removeModelFromList( (i-1), HOT_TABLE);
      }
   }
}
Exemplo n.º 2
0
//------------------------------------------------------------------------------
// newElevEntry() -- Generates a new elevation entry for this player
//                    Returns a pointer to the new entry, else zero(0)
//------------------------------------------------------------------------------
OtwModel* Otw::newElevEntry(models::Player* const ip)
{
   OtwModel* model = nullptr;

   // Only if we have a player pointer ...
   if (ip != nullptr && (getElevationTableSize() < getMaxElevations())) {

      // Create a model entry for this player
      model = hotFactory();
      if (model != nullptr) {
         // Yes, initialize the model entry
         model->initialize(ip);
         addModelToList(model, HOT_TABLE);
      }
   }
   return model;
}