Ejemplo n.º 1
0
ConstructionExtensionPtr FactoryProgressUpdater::uniqueTo(FactoryPtr factory, float value, int week2finish, const std::string& name)
{
  if( !factory.isValid() )
  {
    Logger::warning( "WARNING!!! Factory not initialized" );
    crashhandler::printstack();
    return ConstructionExtensionPtr();
  }

  if( name.empty() )
  {
    Logger::warning( "WARNING!!! Cant assigned named extension without name" );
    return ConstructionExtensionPtr();
  }

  ConstructionExtensionList exts = factory->extensions();
  foreach( it, exts )
  {
    if( (*it)->name() == name )
      return ConstructionExtensionPtr();
  }

  ConstructionExtensionPtr ret = assignTo( factory, value, week2finish );
  ret->setName( name );

  return ret;
}
Ejemplo n.º 2
0
void FactoryProgressUpdater::timeStep( ConstructionPtr parent, unsigned int time)
{
  if( game::Date::isWeekChanged() )
  {
    FactoryPtr factory = ptr_cast<Factory>( parent );
    if( factory.isValid() )
    {
      factory->updateProgress( _options["value"] );
    }    
  }

  ConstructionExtension::timeStep( parent, time );
}
Ejemplo n.º 3
0
void CartPusher::_reachedPathway()
{
    Walker::_reachedPathway();
    _d->anim = CartAnimation();

    if( _d->consumerBuilding != NULL )
    {
        GranaryPtr granary = ptr_cast<Granary>(_d->consumerBuilding);
        WarehousePtr warehouse = ptr_cast<Warehouse>(_d->consumerBuilding);
        FactoryPtr factory = ptr_cast<Factory>(_d->consumerBuilding);

        good::Store* goodStore = 0;
        if( granary.isValid() ) {
            goodStore = &granary->store();
        }
        else if( warehouse.isValid() ) {
            goodStore = &warehouse->store();
        }
        else if( factory.isValid() ) {
            goodStore = &factory->store();
        }

        if( goodStore )
        {
            int saveQty = _d->stock.qty();
            wait( _d->stock.qty() );
            goodStore->applyStorageReservation(_d->stock, _d->reservationID);
            _d->reservationID = 0;
            _d->cantUnloadGoods = (saveQty == _d->stock.qty());
        }
    }
    //
    if( !_pathway().isReverse() )
    {
        _pathway().toggleDirection();
        _centerTile();
        go();
        _d->consumerBuilding = NULL;
    }
    else
    {
        deleteLater();
    }
}
Ejemplo n.º 4
0
void CartPusher::onDestination()
{
  Walker::onDestination();
  _d->cartPicture = NULL;

  if( _d->consumerBuilding != NULL )
  {
    GranaryPtr granary = _d->consumerBuilding.as<Granary>();
    WarehousePtr warehouse = _d->consumerBuilding.as<Warehouse>();
    FactoryPtr factory = _d->consumerBuilding.as<Factory>(); 
    if( granary != NULL )
    {
       granary->getGoodStore().applyStorageReservation(_d->stock, _d->reservationID);
       granary->computePictures();
       _d->reservationID = 0;
    }
    else if ( warehouse != NULL )
    {
       warehouse->getGoodStore().applyStorageReservation(_d->stock, _d->reservationID);
       warehouse->computePictures();
       _d->reservationID = 0;
    }
    else if( factory != NULL )
    {
       factory->getGoodStore().applyStorageReservation(_d->stock, _d->reservationID);
       // factory->computePictures();
       _d->reservationID = 0;
    }
  }
  //
  if( !_pathWay.isReverse() )
  {
    _pathWay.toggleDirection();
    _action._action=WA_MOVE;
    computeDirection();
    _d->consumerBuilding = 0;
  }
  else
  {
    deleteLater();
  }
}
Ejemplo n.º 5
0
ConstructionExtensionPtr FactoryProgressUpdater::assignTo(FactoryPtr factory, float value, int week2finish)
{
  FactoryProgressUpdater* updater = new FactoryProgressUpdater();
  updater->_options[ "value" ] = value;

  updater->_finishDate = game::Date::current();
  updater->_finishDate.appendWeek( week2finish );

  ConstructionExtensionPtr ret( updater );
  ret->drop();

  if( factory.isValid() ) { factory->addExtension( ret );  }
  else
  {
    crashhandler::printstack();
    Logger::warning( "WARNING!!! Factory not initialized" );
  }

  return ret;
}
    ConcurrentEdgeAlgorithm(const size_t nthreads, Graph& graph, FactoryPtr factory)
        : nthreads_(nthreads), graph_(graph), factory_(factory) {

        TRACE("Run in " << nthreads_ << " threads")

        GluedVertexGraph glued_vertex_graph (graph);
        DevisibleTree<GluedVertexGraph> tree (glued_vertex_graph);

        const size_t component_size = tree.GetSize() / nthreads;

        for (size_t thread = 0; thread < nthreads_; ++thread) {
            vector<VertexId> vertices;
            if (thread == nthreads_ - 1) {
                tree.SeparateVertices(vertices, tree.GetSize());
            } else {
                tree.SeparateVertices(vertices, component_size);
            }

            size_t actual_size = vertices.size();
            for (size_t i = 0; i < actual_size; ++i) {
                vertices.push_back(graph.conjugate(vertices[i]));
            }

            ComponentPtr ptr (
                new ConjugateComponent(
                    graph,
                    restricted::PeriodicIdDistributor(graph.GetGraphIdDistributor(),
                            graph.GetGraphIdDistributor()->GetId(),
                            nthreads
                                                     ),
                    vertices.begin(),
                    vertices.end()
                )
            );

            components_.push_back(ptr);
        }

        for (size_t i = 0; i < nthreads_; ++i) {
            RunnerPtr ptr (new Runner(*components_[i], factory->CreateAlgorithm(*components_[i])));
            runners_.push_back(ptr);
        }
    }