Example #1
0
void BuildOperation::requestBuildWhenNothingInTheWay(const MapCoords& mapCoords, const MapObjectType* mapObjectType,
                                                     const FourthDirection& view) {

    assert (mapObjectsToBuildMode == MapObjectToBuild::EMPTY ||
            mapObjectsToBuildMode == MapObjectToBuild::BUILD);

    // Überprüfen. ob auf der Karte alles frei is,...
    if (!isBuildAllowed({ mapCoords, mapObjectType, view })) {
        return;
    }

    // ...dann requestBuild() übergeben
    requestBuild(mapCoords, mapObjectType, view);
}
Example #2
0
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    
void CapacityRegion::handleTick(int time)
{
  // Overwriting RegionModel's handleTick
  // We loop through each facility that exists in the to_build_map_
  map <string, queue <pair <int,int> > >::iterator fac;

  for (fac = to_build_map_.begin(); fac != to_build_map_.end(); ++fac){
    // Define a few parameters
    /* !!!! This method is not full proof... what if multiple facilities need
			 to be built and some fail and some succeed...? !!!! */
    bool built = false; 
    string fac_name = fac->first;
    queue<pair <int,int> > fac_build_queue = fac->second;
    pair<int,int> next_fac_build = fac_build_queue.front();
    int next_build_time = next_fac_build.first;

    // Continue to loop until the facility is built
    while (built!=true){
      // If the current time = the next build time for a facility, 
      // build said facility
      if (time == next_build_time) {
	Model* inst;
	Model* fac_to_build = Model::getModelByName(fac_name);
	int num_facs_to_build = next_fac_build.second;
	int i;
	// Build the prescribed number of facilities for this time step
	for (i=0;i!=num_facs_to_build;i++){
	  inst = chooseInstToBuildFac();
	  built = requestBuild(fac_to_build,dynamic_cast<InstModel*>(inst));
	}
      }
      // If there is nothing to build at this time, consider 0 facilities built
      else {
	built=true;
      }
      
      // For now, catch any situation for which no facility is built.
      // ************* This should eventually be changed
      if (built!=true){
	std::stringstream ss1, ss2;
	ss1 << fac_name;
	ss2 << time;
	throw CycException("Facility " + ss1.str()
			   + " could not be built at time " + ss2.str() + ".");	
      }
      
    } // end build loop
    
  } // end facility loop
  
  // check current capacity
  for (int i=0;i<nCapacities();i++){
    bool build_facility = true;
    bool built = false;
    while (build_facility){
      double current_capacity = checkCurrentCapcity(capacity_type(i));
      build_facility = current_capacity < nominal_value(i);
      Model* fac_to_build;
      if (build_facility){
	Model* inst = chooseInstToBuildFac();
	fac_to_build = chooseFacToBuild( allReplacementFacs_[i] );
	built = requestBuild(fac_to_build,dynamic_cast<InstModel*>(inst));
      }
      // For now, catch any situation for which no facility is built.
      // ************* This should eventually be changed
      if (build_facility && !built){
	string fac_name = (dynamic_cast<FacilityModel*>(fac_to_build))->facName();
	std::stringstream ss1, ss2;
	ss1 << fac_name;
	ss2 << time;
	throw CycException("Facility " + ss1.str()
			   + " could not be built at time " + ss2.str() + ".");	
      }
    }
  }

  // After we finish building, call the normal handleTick for a region
  RegionModel::handleTick(time);
}