void EntertainmentBuilding::deliverService()
{
  // we need all trainees types for the show
  if( !mayWork() )
  {
    _animationRef().stop();
    return;
  }

  bool isWalkerReady = _isWalkerReady();

  int decreaseLevel = idleDecreaseLevel;
  // all trainees are there for the show!
  if( isWalkerReady )
  {
    if( _specificWorkers().empty() )
    {
      ServiceBuilding::deliverService();

      if( !_specificWorkers().empty() )
      {
        _d->showCounter++;
        _animationRef().start();
        decreaseLevel = workDecreaseLevel;
      }
    }
  }

  if( _specificWorkers().empty() )
  {
    _animationRef().stop(); //have no actors for the show
  }

  for( auto& item : _d->necWalkers )
  {
    int level = traineeValue( item );
    setTraineeValue( item, math::clamp( level - decreaseLevel, 0, 100) );
  }
}
Esempio n. 2
0
void Factory::timeStep(const unsigned long time)
{
   WorkingBuilding::timeStep(time);

   //try get good from storage building for us
   if( time % 22 == 1 && getWorkers() > 0 && getWalkerList().size() == 0 )
   {
     receiveGood(); 
     deliverGood();      
   }

   //start/stop animation when workers found
   bool mayAnimate = mayWork();

   if( mayAnimate && _getAnimation().isStopped() )
   {
     _getAnimation().start();
   }

   if( !mayAnimate && _getAnimation().isRunning() )
   {
     _getAnimation().stop();
   }

   //no workers or no good in stock... stop animate
   if( !mayAnimate )
   {
     return;
   }  
  
   if( _d->progress >= 100.0 )
   {
     _d->produceGood = false;
     
     if( _d->goodStore.getCurrentQty( _d->outGoodType ) < _d->goodStore.getMaxQty( _d->outGoodType )  )
     {
       _d->progress -= 100.f;
       //gcc fix for temporaly ref object
       GoodStock tmpStock( _d->outGoodType, 100, 100 );
       _d->goodStore.store( tmpStock, 100 );
     }
   }
   else
   {
     //ok... factory is work, produce goods
     float workersRatio = float(getWorkers()) / float(getMaxWorkers());  // work drops if not enough workers
     // 1080: number of seconds in a year, 0.67: number of timeSteps per second
     float work = 100.f / 1080.f / 0.67f * _d->productionRate * workersRatio * workersRatio;  // work is proportional to time and factory speed
     if( _d->produceGood )
     {
       _d->progress += work;

       _getAnimation().update( time );
       const Picture& pic = _getAnimation().getCurrentPicture();
       if( pic.isValid() )
       {
         // animation of the working factory
         int level = _fgPictures.size()-1;
         _fgPictures[level] = _getAnimation().getCurrentPicture();
       }
     }
   }  

   if( !_d->produceGood )
   {
     if( _d->inGoodType == G_NONE ) //raw material
     {
       _d->produceGood = true;
     }
     else if( _d->goodStore.getCurrentQty( _d->inGoodType ) >= 100 && _d->goodStore.getCurrentQty( _d->outGoodType ) < 100 )
     {
       _d->produceGood = true;
       //gcc fix temporaly ref object error
       GoodStock tmpStock( _d->inGoodType, 100, 0 );
       _d->goodStore.retrieve( tmpStock, 100  );
     }     
   }
}
Esempio n. 3
0
bool Factory::standIdle() const
{
  return !mayWork();
}