class_BaseSimulator.php

Go to the documentation of this file.
00001 <?php
00024 class BaseSimulator extends BaseFrameworkSystem {
00025         // Schiffsteilinstanz
00026         private $partInstance = null;
00027 
00028         // Abmasse (Breite/Hoehe/Laenge)
00029         private $width  = 0;
00030         private $height = 0;
00031         private $length = 0;
00032 
00033         // Aktuelles Schiff und Schiffsteil
00034         private $currShip = null;
00035         private $currPart = null;
00036 
00037         // Faktoren zur Erweiterung der Masse. Beispielsweise soll der Maschinenraum groesser wie der Motor sein
00038         private $resizeFactorArray = array(
00039                 'width'  => 1,
00040                 'height' => 1,
00041                 'length' => 1
00042         );
00043 
00044         // Konstruktor
00045         protected function __construct ($className) {
00046                 // Call highest constructor
00047                 parent::__construct($className);
00048 
00049                 // Clean up a little, dies sollte ganz zum Schluss erfolgen!
00050                 $this->removeSystemArray();
00051                 $this->removeNumberFormaters();
00052                 $this->removeResizeFactorArray();
00053                 $this->removeCurrPart();
00054                 $this->removeCurrShip();
00055         }
00056 
00057         // Setter-Methode fuer Laenge
00058         public final function setLength ($length) {
00059                 $this->length = (float) $length;
00060         }
00061 
00062         // Setter-Methode fuer Breite
00063         public final function setWidth ($width) {
00064                 $this->width = (float) $width;
00065         }
00066 
00067         // Setter-Methode fuer Hoehe
00068         public final function setHeight ($height) {
00069                 $this->height = (float) $height;
00070         }
00071 
00072         // Getter-Methode fuer Laenge
00073         public final function getLength () {
00074                 return $this->length;
00075         }
00076 
00077         // Getter-Methode fuer Breite
00078         public final function getWidth () {
00079                 return $this->width;
00080         }
00081 
00082         // Getter-Methode fuer Hoehe
00083         public final function getHeight () {
00084                 return $this->height;
00085         }
00086 
00087         // Setter-Methode fuer Teil-Instanz
00088         public final function setPartInstance (ConstructableShipPart $partInstance) {
00089                 $this->partInstance = $partInstance;
00090         }
00091 
00092         // Getter-Methode fuer Teil-Instanz
00093         public final function getPartInstance () {
00094                 if (!isset($this->partInstance)) {
00095                         return null;
00096                 }
00097                 return $this->partInstance;
00098         }
00099 
00100         // Remover-Methode fuer die Teil-Instanz
00101         public final function removePartInstance () {
00102                 unset($this->partInstance);
00103         }
00104 
00105         // Prueft ob all Umberechnungsfaktoren gesetzt sind
00106         private function isResizeFactorValid () {
00107                 return (($this->getResizeFactorElement('width')  > 1)
00108                         || ($this->getResizeFactorElement('height') > 1)
00109                         || ($this->getResizeFactorElement('length') > 1)
00110                 );
00111         }
00112 
00113         // Baut einen Motor in das Schiff ein
00114         public function addShipPartToShip (ConstructableShip $shipInstance, ConstructableShipPart $partInstance) {
00115                 // Schiff/-steil merken
00116                 $this->currShip = $shipInstance;
00117                 $this->currPart = $partInstance;
00118 
00119                 // Passt ueberhaupt das Schiffsteil in's Schiff?
00120                 if ($this->isShipPartSizeValid()) {
00121                         // Muessen die Masse angepasst werden?
00122                         if ($this->isResizeFactorValid()) {
00123                                 // Neue Angaben berechnen (wir lassen etwas Lust fuer Kabelbaeume, Roehren, Maschinisten, etc.)
00124                                 $this->newWidth  = (float) $this->getCurrPart()->getWidth()  * $this->resizeFactorArray['width'];
00125                                 $this->newHeight = (float) $this->getCurrPart()->getHeight() * $this->resizeFactorArray['height'];
00126                                 $this->newLength = (float) $this->getCurrPart()->getLength() * $this->resizeFactorArray['length'];
00127 
00128                                 // Passt dies nun immer noch?
00129                                 if ($this->isNewSizeValid()) {
00130                                         // Das passt auch, dann Werte setzen und Motor-Instanz merken
00131                                         $this->setWidth($this->newWidth);
00132                                         $this->setHeight($this->newHeight);
00133                                         $this->setLength($this->newLength);
00134 
00135                                         // Einige Dinge entfernen...
00136                                         $this->removeAllNewAttr();
00137                                 } else {
00138                                         // Passt nicht! Also wieder Exception werfen...
00139                                         throw new StructureShipMismatchException(sprintf("[%s:] Das Schiffsteil <strong>%s</strong> vom Typ <strong>%s</strong> ist zu gross f&uuml;r das Schiff!",
00140                                                 $this->getCurrPart()->__toString(),
00141                                                 $this->getCurrPart()->getObjectDescription(),
00142                                                 $this->getCurrPart()->__toString()
00143                                         ), 2);
00144                                 }
00145                         } elseif ($this->currPart != null) {
00146                                 // Aktuelle Masse setzen
00147                                 $this->setWidth($this->getCurrPart()->getWidth());
00148                                 $this->setHeight($this->getCurrPart()->getHeight());
00149                                 $this->setLength($this->getCurrPart()->getLength());
00150                         }
00151 
00152                         // Existiert ein Schiffsteil?
00153                         if (!is_null($this->currPart)) {
00154                                 // Schiffsteil-Instanz setzen
00155                                 $this->setPartInstance($this->currPart);
00156 
00157                                 // Instanzen entfernen
00158                                 $this->getCurrPart()->removeCurrShip();
00159                                 $this->getCurrPart()->removeCurrPart();
00160                                 $this->getCurrPart()->removePartInstance();
00161                                 $this->getCurrPart()->removeResizeFactorArray();
00162                         }
00163                 } else {
00164                         // Exception werfen!
00165                         throw new StructureShipMismatchException(sprintf("[%s:] Das Schiffsteil <u>%s</u> vom Typ <u>%s</u> passt nicht in das Schiff!",
00166                                 $this->getCurrPart()->realClass,
00167                                 $this->getCurrPart()->getObjectDescription(),
00168                                 $this->getCurrPart()->__toString()
00169                         ), 1);
00170                 }
00171 
00172                 // Nochmals Clean up a little
00173                 $this->removeResizeFactorArray();
00174                 $this->removeCurrShip();
00175                 $this->removeCurrPart();
00176         }
00177 
00178         // Array fuer Umrechnungstabelle entfernen
00179         public final function removeResizeFactorArray () {
00180                 unset($this->resizeFactorArray);
00181         }
00182 
00188         public final function removeAllNewAttr () {
00189                 unset($this->newWidth);
00190                 unset($this->newHeight);
00191                 unset($this->newLength);
00192         }
00193 
00199         public final function removeCurrShip () {
00200                 unset($this->currShip);
00201         }
00202 
00203         // Aktuelle Schiffsteil-Instanz entfernen
00204         public final function removeCurrPart () {
00205                 unset($this->currPart);
00206         }
00207 
00208         // Breite entfernen
00209         public final function removeWidth () {
00210                 unset($this->width);
00211         }
00212 
00213         // Hoehe entfernen
00214         public final function removeHeight () {
00215                 unset($this->height);
00216         }
00217 
00218         // Laenge entfernen
00219         public final function removeLength () {
00220                 unset($this->length);
00221         }
00222 
00223         // Tiefgang entfernen
00224         public final function removeDraught () {
00225                 unset($this->draught);
00226         }
00227 
00228         // Getter-Methode fuer Element aus resizeFactor
00229         public final function getResizeFactorElement ($el) {
00230                 if (isset($this->resizeFactorArray[$el])) {
00231                         // Element gefunden
00232                         return $this->resizeFactorArray[$el];
00233                 } else {
00234                         // Element nicht gefunden!
00235                         return null;
00236                 }
00237         }
00238 
00239         // Setter-Methode fuer Element in resizeFactor
00240         public final function setResizeFactorElement ($el, $value) {
00241                 $this->resizeFactorArray[$el] = (float) $value;
00242         }
00243 
00244         // Kontrolliert, ob die Abmasse Schiffsteil->Schiff stimmen
00245         public function isShipPartSizeValid () {
00246                 return (
00247                         (
00248                                 ( // Already defined ship messurings
00249                                                  ($this->getCurrPart()->getWidth()  < $this->currShip->getWidth())
00250                                         && ($this->getCurrPart()->getHeight() < $this->currShip->getDraught())
00251                                         && ($this->getCurrPart()->getLength() < $this->currShip->getLength())
00252                                 ) || ( // Ship messurings shall be calculated
00253                                                  ($this->currShip->getWidth()  == 0)
00254                                         && ($this->currShip->getHeight() == 0)
00255                                         && ($this->currShip->getLength() == 0)
00256                                 )
00257                         // The inserted part must be messured!
00258                         ) && ($this->getCurrPart()->getWidth()  > 0)
00259                                 && ($this->getCurrPart()->getHeight() > 0)
00260                                 && ($this->getCurrPart()->getLength() > 0)
00261                 );
00262         }
00263 
00264         // Kontrolliert, ob die Abmasse Maschinenraum->Schiff stimmen
00265         public function isNewSizeValid () {
00266                 return (
00267                         ( // Already defined ship messurings
00268                                          ($this->newWidth  < $this->currShip->getWidth())
00269                                 && ($this->newHeight < $this->currShip->getDraught())
00270                                 && ($this->newLength < $this->currShip->getLength())
00271                         ) || ( // Ship messurings shall be calculated
00272                                          ($this->currShip->getWidth()  == 0)
00273                                 && ($this->currShip->getHeight() == 0)
00274                                 && ($this->currShip->getLength() == 0)
00275                         )
00276                 );
00277         }
00278 
00279         // Masse extrahieren
00280         public function extractDimensions ($dim) {
00281                 // Abmasse setzen
00282                 if ((isset($dim)) && (is_array($dim)) && (count($dim) == 3)) {
00283                         // Abmasse aus Array holen
00284                         $this->setWidth($dim[0]);
00285                         $this->setHeight($dim[1]);
00286                         $this->setLength($dim[2]);
00287                 } else {
00288                         // Nicht gefundene Abmasse!
00289                         throw new DimNotFoundInArrayException($this, self::EXCEPTION_DIMENSION_ARRAY_INVALID);
00290                 }
00291         }
00292 
00298         public final function getCurrPart () {
00299                 return $this->currPart;
00300         }
00301 }
00302 
00303 // [EOF]
00304 ?>

Generated on Mon Dec 8 01:06:44 2008 for Ship-Simulator by  doxygen 1.5.6