Guest User

Untitled

a guest
Feb 15th, 2014
384
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void TWorld::SpawnShips(TPlanet& from, TPlanet& to, float energyPercents, size_t playerId, size_t maxShips) {
  2.     float totalShipsEnergy = from.Energy * energyPercents;
  3.     from.Energy -= totalShipsEnergy;
  4.     size_t shipsCount = std::min(1 + (int)(totalShipsEnergy / 7.0), int(maxShips));
  5.     float energyPerShip = totalShipsEnergy / shipsCount;
  6.     QPointF direction;
  7.     direction.setX(to.Position.x() - from.Position.x());
  8.     direction.setY(to.Position.y() - from.Position.y());
  9.     Normalize(direction);
  10.  
  11.     QPointF shipPosition = from.Position;
  12.     shipPosition.setX(shipPosition.x() + direction.x() * (from.Radius + 6.0));
  13.     shipPosition.setY(shipPosition.y() + direction.y() * (from.Radius + 6.0));
  14.     QPointF shipSpeed = direction;
  15.     shipSpeed.setX(shipSpeed.x() * 2.5);
  16.     shipSpeed.setY(shipSpeed.y() * 2.5);
  17.  
  18.     for (size_t i = 0; i < shipsCount; ++i) {
  19.         TShip ship;
  20.         ship.Position = shipPosition;
  21.         ship.Position.setX(ship.Position.x() + rand() % 6 - 3);
  22.         ship.Position.setY(ship.Position.y() + rand() % 6 - 3);
  23.         ship.Energy = energyPerShip;
  24.         ship.PlayerId = playerId;
  25.         ship.Speed = shipSpeed;
  26.         ship.Target = to.Position;
  27.         from.SpawnQueue.push_back(ship);
  28.     }
  29. }
RAW Paste Data