Beispiel #1
0
  /**
   * Updates the game state to the next tick. First applies the messages past in as arguments, then
   * updates the nodes, then the lanes, then checks for a winning player.
   *
   * @param messages the messages to apply for this game state tick
   */
  public void update(Message[] messages) {
    this.validateLock();

    for (Message m : messages) m.apply(this);

    this.validateLock();

    for (Node n : map.getNodes()) n.update();

    this.validateLock();

    for (Lane l : map.getLanes()) l.update();

    this.validateLock();

    double energyToAdd = ENERGY_INCREMENT_RATE * this.getLastLoopTime();
    for (Player p : players.values()) {
      p.setPlayerEnergy(p.getPlayerEnergy() + energyToAdd);
      if (p.getPlayerEnergy() > MAX_PLAYER_ENERGY) p.setPlayerEnergy(MAX_PLAYER_ENERGY);
    }

    timerTick++;

    lastLoopTime = this.getTime() - timeAtEndOfLastLoop;
    timeAtEndOfLastLoop = this.getTime();

    this.validateLock();

    // check for win
    Node n1 = map.getNodes()[0];
    for (Node n : map.getNodes())
      if (n1.getOwner() == null || !n1.getOwner().equals(n.getOwner())) return;
    winningPlayer = n1.getOwner();
  }
Beispiel #2
0
  /** @return all the units in the game state */
  public List<Unit> getUnits() {
    List<Unit> units = new ArrayList<Unit>();
    Lane[] lanes = map.getLanes();
    for (Lane l : lanes) {
      Wave[] waves = l.getWaves();
      for (Wave w : waves) {
        Unit[] us = w.getUnits();
        for (Unit u : us) {
          units.add(u);
        }
      }
    }

    Collections.sort(
        units,
        new Comparator<Unit>() {

          @Override
          public int compare(Unit o1, Unit o2) {
            if (o1.getCollisionStrategy() instanceof Ground
                && o2.getCollisionStrategy() instanceof Flying) return -1;
            else if (o2.getCollisionStrategy() instanceof Ground
                && o1.getCollisionStrategy() instanceof Flying) return 1;
            else return 0;
          }
        });

    return units;
  }
 public void update(double timeInterval) {
   super.resetAvSpeedStats();
   for (Road r : getOutgoingRoads()) {
     if (r != null) {
       r.handleLC(this, false);
     }
   }
   // Tom : Do le normal lane update Cliff: ME GUSTA
   for (Road r : getIncomingRoads()) {
     if (r != null) {
       r.handleLC(this, false);
       for (Lane l : r.getLanes()) {
         if (l.getCars().size() > 0) {
           Car fCar = l.getCars().getFirst();
           if (!fCar.isIsGate()
               && fCar.getPosition() + fCar.getLength() >= (l.getLength() - fCar.getMinSpace())) {
             // The front of the car reaches the end of the road within its minimal spacing
             if (fCar.getPath().isEmpty()) {
               l.deleteCar(fCar);
             } else {
               super.updateFirst(timeInterval, r, l, getNextRoadForCar(fCar), fCar);
             }
           } else {
             fCar.drive(0, 0, true, timeInterval);
           }
           super.updateLane(timeInterval, l, r);
         }
       }
     }
   }
 }
Beispiel #4
0
  /** @return all the projectiles in the game state */
  public List<Projectile> getProjectiles() {
    List<Projectile> projectiles = new ArrayList<Projectile>();
    Lane[] lanes = map.getLanes();
    for (Lane l : lanes) {
      Projectile[] ps = l.getProjectiles();
      for (Projectile p : ps) projectiles.add(p);
    }

    return projectiles;
  }
  /**
   * Gets a Line from the HoldingArea and provides it to the sim-process to use it. As not enough
   * lanes are available at the moment the sim-process has to wait in a queue until a lane is
   * available again.
   *
   * @return <code>Lane</code>: The available lane of this HoldingArea.
   */
  public Lane getLane() {

    // check if there're available lanes
    if (!this.lanes.provide(1)) return null;

    // get the lane from the queue of the lanes
    Lane lane = this.laneQueue.first();

    // trace that a lane was taken from this HO
    if (currentlySendTraceNotes())
      sendTraceNote("takes " + lane.getName() + " from the " + this.getName());

    // remove lane from the Queue
    this.laneQueue.remove(lane);

    return lane;
  }
  /**
   * A process is using this method to put lane it has used back in the HoldingArea.
   *
   * @param l <code>Lane</code>: The lane which should be returned to the HoldingArea.
   */
  public void takeBack(Lane l) {

    // take back the lane as Res
    this.lanes.takeBack(1);

    // insert the line to the lanes queue
    this.laneQueue.insert(l);
    if (currentlySendTraceNotes())
      sendTraceNote("releases " + l.getName() + " to the " + this.getName());
  }
Beispiel #7
0
 @Override
 /** This will set the correct MidiDevice when the project is reloaded */
 public void onLoad() {
   super.onLoad();
   ftw.setMidiChannel(midiChannel);
   if (midiDeviceIndex != null) {
     try {
       ftw.setMidiDevice(project.getSequencer().listMidiOutDevices().get(midiDeviceIndex));
     } catch (Exception e) {
       System.out.println("WARNING: Was unable to connect to external midi device");
     }
   }
   setUpKeys();
 }
Beispiel #8
0
 public void addToModel() {
   super.addToModel();
   onLoad();
 }