Beispiel #1
0
void GameState::createDollar() {
    std::list<Player*>::const_iterator it_player = Player::s_playerList.begin();
    while (Dollar::s_dollarList.size() < unsigned(Player::alivePlayers)) {
        Dollar* newDollar = new Dollar(config::path + config::D_SRC, 0, 0);
        int newDollar_xPos = 0;
        int newDollar_yPos = 0;
        bool valid = false;
        while(!valid) { //Loop until valid pos is found
            valid = true;
            newDollar_xPos = rand() % (config::W_WIDTH - newDollar->getWidth())   ;
            newDollar_yPos = rand() % (config::W_HEIGHT - newDollar->getHeight()) ;

            while(it_player != Player::s_playerList.end()) {
                if(Entity::collides((*it_player), newDollar)) {
                    valid = false;
                    break;
                }
                it_player++;
            }
        }
        newDollar->setXPos(static_cast<float>(newDollar_xPos));
        newDollar->setYPos(static_cast<float>(newDollar_yPos));
        Dollar::s_dollarList.push_back(newDollar);
    }
}
Beispiel #2
0
void Segment::readyForShipmentIs(bool b) {
	if (b == false || shipmentQ_.empty()) return;
	
	Activity::Manager::Ptr manager = activityManagerInstance();
	string name = "forward shipment #";
	ostringstream oss;
	oss << rand() << rand() << rand();
	name.append(oss.str());
	Activity::Ptr fwd = manager->activityNew(name);

	ShipmentQueue shipments;
	NumVehicles currentVehicles(capacity());
    Fleet::Ptr fleet = engine_->fleet();
	NumPackages vehicleCapacity(fleet->capacity(mode()).value());
	NumPackages totalCapacity(
		currentVehicles.value() * vehicleCapacity.value());
	NumPackages packageCount(0);

	NumVehicles vehicles(0);
    Dollar costPerTrip = this->length().value()*this->difficulty().value()*fleet->speed(mode()).value();

	for (Shipment::Ptr s = shipmentQ_.front(); !shipmentQ_.empty() && packageCount < totalCapacity; ) {
		NumPackages load = s->load();
		if (load.value() > totalCapacity.value()) { // split shipment
			++shipmentsFragmented_;
			s->loadIs(load.value() - totalCapacity.value());
			load = totalCapacity;
			shipmentQ_.push_front( Shipment::ShipmentNew( s->name(), s->source(), s->destination(), s->origSize(), load, s->timeShipped() ));
		}
		// now we're guaranteed to have at least one shipment at the
		// front of the queue that we can send off
        Shipment::Ptr shipment = shipmentQ_.front();
        shipment->costIs(shipment->cost().value() + costPerTrip.value());
		shipments.push_front(shipment);
		shipmentQ_.pop_front();
		packageCount = packageCount.value() + load.value();
		totalCapacity = totalCapacity.value() - load.value();
	}

	vehicles = packageCount.value() / vehicleCapacity.value() +
		((packageCount.value() % vehicleCapacity.value() > 0) ? 1 : 0);
    capacity_ = capacity_.value() - vehicles.value();

	fwd->lastNotifieeIs(new ForwardShipmentReactor(manager,
								fwd.ptr(), 0, this, shipments, vehicles)); 
	Time timeTaken = this->length().value() / fleet->speed(mode()).value();
	fwd->nextTimeIs(manager->now().value() + timeTaken.value());
	fwd->statusIs(Activity::nextTimeScheduled);
}
Beispiel #3
0
void GameState::createDollar()
{
  auto& dollarList = entityManager->getAll<Dollar>();
  Config& config = Config::getInstance();
  while (dollarList.size() < unsigned(Player::getAlivePlayerCount()))
  {
    Dollar* newDollar = entityManager->create<Dollar>(atlas->findRegion(config.getDollarRegion()),
                                                      0.f,
                                                      0.f,
                                                      config.getDollarWidth(),
                                                      config.getDollarHeight());
    int newDollar_xPos = 0;
    int newDollar_yPos = 0;
    bool valid = false;
    while (!valid)
    { //Loop until valid pos is found
      valid = true;
      newDollar_xPos = rand() % (config.getGameWidth() - (int)newDollar->getWidth());
      newDollar_yPos = rand() % (config.getGameHeight() - (int)newDollar->getHeight());
      newDollar->setX((float)newDollar_xPos);
      newDollar->setY((float)newDollar_yPos);

      for (auto& e : entityManager->getAll<Player>())
      {
        Player* p = reinterpret_cast<Player*>(e);
        if (AbstractEntity::collides(p, newDollar))
        {
          valid = false;
          break;
        }
      }
    }

    newDollar->setX((float)newDollar_xPos);
    newDollar->setY((float)newDollar_yPos);
    newDollar->copyDataForInterpolation();
  }
}