Exemplo n.º 1
0
 /**
  * Determine if the job can be accomodated before the fixed job, without
  * stalling the fixed job.
  * @param Job $job
  * @param Job $fixedJob 
  * @return bool
  */
 public function canAccommodate($job, $fixedJob)
 {
     if ($this->debug || Hatcheries::$debug) {
         tracemsg("Timeline::canAccommodate(" . $job . ", " . $fixedJob . ")");
     }
     // only jobs that could clash
     if ($job->larvaCost() == 0 && $job->energyCost() == 0 && $job->queueTypesExpended() === null) {
         return true;
     }
     if ($fixedJob->larvaCost() == 0 && $fixedJob->energyCost() == 0 && $fixedJob->queueTypesExpended() === null) {
         return true;
     }
     // remember previous queues & spellcasters state
     $holdHatcheries = $this->hatcheries;
     $holdQueues = $this->queues;
     $holdSpellcasters = $this->spellcasters;
     $this->hatcheries = clone $this->hatcheries;
     $this->queues = clone $this->queues;
     $this->spellcasters = clone $this->spellcasters;
     // can we use larvae without delaying fixed job?
     if ($job->larvaCost() > 0) {
         $this->hatcheries->expend($job->timeStarted, $job->larvaCost(), $job->tagsRequired);
     }
     if ($fixedJob->larvaCost() > 0) {
         $larvaeAvailable = $this->hatcheries->when($fixedJob->larvaCost(), $fixedJob->tagsRequired);
     } else {
         $larvaeAvailable = -INF;
     }
     // can we use production queues without delaying fixed job?
     $this->queue($job, $job->timeStarted, true);
     list($queueTypesExpended, $expendAll) = $job->queueTypesExpended();
     if ($queueTypesExpended !== null) {
         list($queuesAvailable, $unused) = $this->queues->when($queueTypesExpended, $expendAll, $fixedJob->tagsRequired);
     } else {
         $queuesAvailable = -INF;
     }
     // can we use spellcaster without delaying fixed job?
     if ($job->energyCost() > 0) {
         $this->spellcasters->update($job->timeStarted);
         $this->spellcasters->expend($job->spellcasterTypeExpended(), $job->energyCost(), $job->timeStarted, $job->tagsRequired);
     }
     if ($fixedJob->energyCost() > 0) {
         $spellcasterAvailable = $this->spellcasters->when($fixedJob->spellcasterTypeExpended(), $fixedJob->energyCost(), $fixedJob->tagsRequired);
     } else {
         $spellcasterAvailable = -INF;
     }
     // reinstate remembered queues & spellcasters state
     $this->hatcheries = $holdHatcheries;
     $this->queues = $holdQueues;
     $this->spellcasters = $holdSpellcasters;
     return $larvaeAvailable <= $fixedJob->timeStarted && $queuesAvailable <= $fixedJob->timeStarted && $spellcasterAvailable <= $fixedJob->timeStarted;
 }