(no commit message)
[shipsimu.git] / application / ship-simu / main / constructions / yards / class_Shipyard.php
1 <?php
2
3 // Die Werft-Klasse
4 class Shipyard extends BaseConstruction {
5         // Werft-Name
6         private $shipyardName    = "Namenlose Werft";
7
8         // Arbeiter-Liste
9         private $staffList       = null;
10
11         // Queue-Liste fuer zu bauende Schiffe
12         private $queueList       = null;
13
14         // Aktuell im Bau befindliches Schiff
15         private $currShipInConst = null;
16
17         // Liste konstruierbarer Schiffstypen
18         private $shipTypeList = null;
19
20         // Zugewiesener Hafen
21         private $harborInstance = null;
22
23         // Zugewiesene Reederei
24         private $shippingCompany = null;
25
26         // Constructor
27         private function __construct () {
28                 // Eltern-Konstruktor aufrufen
29                 parent::constructor(__CLASS__);
30
31                 // Debug message
32                 if (((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) && (defined('DEBUG_CONSTRUCT'))) {
33                         $this->getDebugInstance()->output(sprintf("[%s:%d] Konstruktor erreicht.<br />\n",
34                                 __CLASS__,
35                                 __LINE__
36                         ));
37                 }
38
39                 // Beschreibung setzen
40                 $this->setPartDescr("Werft");
41
42                 // Staff-Liste/Schiffstyp-Liste erzeugen
43                 $this->createStaffList();
44                 $this->createShipTypeList();
45
46                 // Unique-ID erzeugen
47                 $this->createUniqueID();
48         }
49
50         // Create a shipyard and notify it about it's owner
51         public static function createShipyardNotify (Harbor $harborInstance, $shipyardName, ShippingCompany $companyInstance) {
52                 // Werft-Instanz holen
53                 $shipyardInstance = self::createShipyard($harborInstance, $shipyardName);
54
55                 // Reederei der Werft zuweisen
56                 $shipyardInstance->setCompanyInstance($companyInstance);
57
58                 // Die Reederei ueber ihre Werft informieren
59                 $companyInstance->addNewShipyard($shipyardInstance);
60
61                 // Instanz zurueckgeben
62                 return $shipyardInstance;
63         }
64
65         // Create a shipyard, first we need to create a harbor
66         public final static function createShipyard (Harbor $harborInstance, $shipyardName) {
67                 // Instanz temporaer holen
68                 $shipyardInstance = new Shipyard();
69
70                 // Debug message
71                 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $shipyardInstance->getDebugInstance()->output(sprintf("[%s:%d] Eine Werft mit dem Namen <strong>%s</strong> wird im Hafen <strong>%s</strong> konstruiert.<br />\n",
72                         __CLASS__,
73                         __LINE__,
74                         $shipyardName,
75                         $harborInstance->getHarborName()
76                 ));
77
78                 // Werft-Name setzen
79                 $shipyardInstance->setShipyardName($shipyardName);
80
81                 // Hafen-Instanz setzen
82                 $shipyardInstance->setHarborInstance($harborInstance);
83
84                 // Abmasse setzen in Meter
85                 $shipyardInstance->setWidth(30);
86                 $shipyardInstance->setHeight(30);
87                 $shipyardInstance->setLength(100);
88
89                 // Etwas aufraeumen
90                 $shipyardInstance->removeDraught();
91                 $shipyardInstance->removeSystemArray();
92
93                 // Debug-Meldung
94                 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $shipyardInstance->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> wurde gebaut.<br />\n",
95                         __CLASS__,
96                         __LINE__,
97                         $shipyardName
98                 ));
99
100                 // Instanz zurueckliefern
101                 return $shipyardInstance;
102         }
103
104         // Create staff list
105         private function createStaffList () {
106                 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> erh&auml;lt eine Arbeiterliste.<br />\n",
107                         __CLASS__,
108                         __LINE__,
109                         $this->getShipyardName()
110                 ));
111                 $this->staffList = new FrameworkArrayObject();
112         }
113
114         // Create ship type list
115         private function createShipTypeList () {
116                 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> erh&auml;lt eine Typenliste.<br />\n",
117                         __CLASS__,
118                         __LINE__,
119                         $this->getShipyardName()
120                 ));
121                 $this->shipTypeList = new FrameworkArrayObject();
122         }
123
124         // Setter-Methode fuer Werft-Name
125         public function setShipyardName ($shipyardName) {
126                 $this->shipyardName = (string) $shipyardName;
127         }
128
129         // Getter-Methode fuer Werft-Name
130         public function getShipyardName () {
131                 return $this->shipyardName;
132         }
133
134         // Setter-Methode fuer Hafen-Instanz
135         public function setHarborInstance (Harbor $harborInstance) {
136                 $this->harborInstance = $harborInstance;
137         }
138
139         // Getter-Methode fuer Hafen-Instanz
140         public function getHarborInstance () {
141                 return $this->harborInstance;
142         }
143
144         // Setter fuer Reederei-Instanz
145         public function setCompanyInstance (ShippingCompany $companyInstance) {
146                 $this->shippingCompany = $companyInstance;
147         }
148
149         // Getter fuer Reederei-Instanz
150         public function getCompanyInstance () {
151                 return $this->shippingCompany;
152         }
153
154         // Add new personell
155         public function addNewPersonell ($personell) {
156                 if (is_null($this->staffList)) {
157                         // Opps, not initialized!
158                         ApplicationEntryPoint::app_die("New personell: <pre>".print_r($this, true)."</pre>");
159                 }
160
161                 // Add to list
162                 $this->staffList->append($personell);
163         }
164
165         // Add a new ship type to our list
166         public function addNewConstructableShipType ($shipType) {
167                 // This must be a string!
168                 $shipType = (string) $shipType;
169
170                 // Debug message
171                 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> kann bald Schiffe vom Typ <strong>%s</strong> bauen.<br />\n",
172                         __CLASS__,
173                         __LINE__,
174                         $this->getShipyardName(),
175                         $shipType
176                 ));
177
178                 // Add to list
179                 $this->shipTypeList->append($shipType);
180         }
181
182         // Is the specified ship type in our list?
183         public function isShipTypeConstructable ($shipType) {
184                 // First we can't build this ship
185                 $result = false;
186
187                 // This must be a string!
188                 $shipType = (string) $shipType;
189
190                 // Debug message
191                 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> pr&uuml;ft, ob Schiffe vom Typ <strong>%s</strong> baubar sind.<br />\n",
192                         __CLASS__,
193                         __LINE__,
194                         $this->getShipyardName(),
195                         $shipType
196                 ));
197
198                 // Iterate through all types
199                 for ($idx = $this->shipTypeList->getIterator(); $idx->valid(); $idx->next()) {
200                         // Get current ship type
201                         $type = (string) $idx->current();
202
203                         // Is both the same?
204                         $result = ($type == $shipType);
205
206                         // Type is found?
207                         if ($result) break; // Then abort the search!
208                 }
209
210                 // Debug message
211                 if ((defined('DEBUG_SHIPYARD')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Die Werft <strong>%s</strong> hat die Suche nach dem Schiffstyp <strong>%s</strong> abgeschlossen.<br />\n",
212                         __CLASS__,
213                         __LINE__,
214                         $this->getShipyardName(),
215                         $shipType
216                 ));
217
218                 // Return result
219                 return $result;
220         }
221
222         /**
223          * Stub!
224          */
225         public function saveObjectToDatabase () {
226                 $this->getDebugInstance()->output(sprintf("[%s:] Stub <strong>%s</strong> erreicht.",
227                         $this->__toString(),
228                         __FUNCTION__
229                 ));
230         }
231
232         /**
233          * Limits this object with an ObjectLimits instance
234          */
235         public function limitObject (ObjectLimits $limitInstance) {
236                 ApplicationEntryPoint::app_die("".__METHOD__." reached! Stub!");
237         }
238 }
239
240 // [EOF]
241 ?>