174 Airport->nof_depots = nof_depots; |
174 Airport->nof_depots = nof_depots; |
175 |
175 |
176 |
176 |
177 // build the state machine |
177 // build the state machine |
178 AirportBuildAutomata(Airport, FA); |
178 AirportBuildAutomata(Airport, FA); |
179 DEBUG(misc, 1) ("#Elements %2d; #Terminals %2d in %d group(s); #Helipads %2d in %d group(s); Entry Point %d", Airport->nofelements, |
179 DEBUG(misc, 1) ("#Elements %2d; #Terminals %2d in %d group(s); #Helipads %2d in %d group(s); Entry Point %d", |
180 nofterminals, nofterminalgroups, nofhelipads, nofhelipadgroups, Airport->entry_point); |
180 Airport->nofelements, nofterminals, nofterminalgroups, nofhelipads, nofhelipadgroups, Airport->entry_point |
|
181 ); |
181 |
182 |
182 |
183 |
183 { |
184 { |
184 byte _retval = AirportTestFTA(Airport); |
185 byte ret = AirportTestFTA(Airport); |
185 if (_retval != MAX_ELEMENTS) {printf("ERROR with element: %d\n", _retval-1);} |
186 if (ret != MAX_ELEMENTS) printf("ERROR with element: %d\n", ret - 1); |
186 assert(_retval == MAX_ELEMENTS); |
187 assert(ret == MAX_ELEMENTS); |
187 } |
188 } |
188 // print out full information |
189 // print out full information |
189 // true -- full info including heading, block, etc |
190 // true -- full info including heading, block, etc |
190 // false -- short info, only position and next position |
191 // false -- short info, only position and next position |
191 //AirportPrintOut(Airport, false); |
192 //AirportPrintOut(Airport, false); |
211 static uint16 AirportGetNofElements(const AirportFTAbuildup *FA) |
212 static uint16 AirportGetNofElements(const AirportFTAbuildup *FA) |
212 { |
213 { |
213 int i; |
214 int i; |
214 uint16 nofelements = 0; |
215 uint16 nofelements = 0; |
215 int temp = FA[0].position; |
216 int temp = FA[0].position; |
|
217 |
216 for (i = 0; i < MAX_ELEMENTS; i++) { |
218 for (i = 0; i < MAX_ELEMENTS; i++) { |
217 if (temp != FA[i].position) { |
219 if (temp != FA[i].position) { |
218 nofelements++; |
220 nofelements++; |
219 temp = FA[i].position; |
221 temp = FA[i].position; |
220 } |
222 } |
221 if (FA[i].position == MAX_ELEMENTS) {break;} |
223 if (FA[i].position == MAX_ELEMENTS) break; |
222 } |
224 } |
223 return nofelements; |
225 return nofelements; |
224 } |
226 } |
225 |
227 |
226 static void AirportBuildAutomata(AirportFTAClass *Airport, const AirportFTAbuildup *FA) |
228 static void AirportBuildAutomata(AirportFTAClass *Airport, const AirportFTAbuildup *FA) |
227 { |
229 { |
228 AirportFTA *FAutomata; |
230 AirportFTA *FAutomata; |
229 AirportFTA *current; |
231 AirportFTA *current; |
230 uint16 internalcounter, i; |
232 uint16 internalcounter, i; |
231 FAutomata = (AirportFTA *)malloc(sizeof(AirportFTA) * Airport->nofelements); |
233 FAutomata = malloc(sizeof(AirportFTA) * Airport->nofelements); |
232 Airport->layout = FAutomata; |
234 Airport->layout = FAutomata; |
233 internalcounter = 0; |
235 internalcounter = 0; |
234 |
236 |
235 for (i = 0; i < Airport->nofelements; i++) { |
237 for (i = 0; i < Airport->nofelements; i++) { |
236 current = &Airport->layout[i]; |
238 current = &Airport->layout[i]; |
238 current->heading = FA[internalcounter].heading; |
240 current->heading = FA[internalcounter].heading; |
239 current->block = FA[internalcounter].block; |
241 current->block = FA[internalcounter].block; |
240 current->next_position = FA[internalcounter].next_in_chain; |
242 current->next_position = FA[internalcounter].next_in_chain; |
241 |
243 |
242 // outgoing nodes from the same position, create linked list |
244 // outgoing nodes from the same position, create linked list |
243 while (current->position == FA[internalcounter+1].position) { |
245 while (current->position == FA[internalcounter + 1].position) { |
244 AirportFTA *newNode = (AirportFTA *)malloc(sizeof(AirportFTA)); |
246 AirportFTA* newNode = malloc(sizeof(AirportFTA)); |
245 newNode->position = FA[internalcounter+1].position; |
247 |
246 newNode->heading = FA[internalcounter+1].heading; |
248 newNode->position = FA[internalcounter + 1].position; |
247 newNode->block = FA[internalcounter+1].block; |
249 newNode->heading = FA[internalcounter + 1].heading; |
248 newNode->next_position = FA[internalcounter+1].next_in_chain; |
250 newNode->block = FA[internalcounter + 1].block; |
|
251 newNode->next_position = FA[internalcounter + 1].next_in_chain; |
249 // create link |
252 // create link |
250 current->next_in_chain = newNode; |
253 current->next_in_chain = newNode; |
251 current = current->next_in_chain; |
254 current = current->next_in_chain; |
252 internalcounter++; |
255 internalcounter++; |
253 } // while |
256 } // while |
262 AirportFTA *temp; |
265 AirportFTA *temp; |
263 next_element = 0; |
266 next_element = 0; |
264 |
267 |
265 for (i = 0; i < Airport->nofelements; i++) { |
268 for (i = 0; i < Airport->nofelements; i++) { |
266 position = Airport->layout[i].position; |
269 position = Airport->layout[i].position; |
267 if (position != next_element) {return i;} |
270 if (position != next_element) return i; |
268 temp = &Airport->layout[i]; |
271 temp = &Airport->layout[i]; |
269 |
272 |
270 do { |
273 do { |
271 if (temp->heading > MAX_HEADINGS && temp->heading != 255) {return i;} |
274 if (temp->heading > MAX_HEADINGS && temp->heading != 255) return i; |
272 if (temp->heading == 0 && temp->next_in_chain != 0) {return i;} |
275 if (temp->heading == 0 && temp->next_in_chain != 0) return i; |
273 if (position != temp->position) {return i;} |
276 if (position != temp->position) return i; |
274 if (temp->next_position >= Airport->nofelements) {return i;} |
277 if (temp->next_position >= Airport->nofelements) return i; |
275 temp = temp->next_in_chain; |
278 temp = temp->next_in_chain; |
276 } while (temp != NULL); |
279 } while (temp != NULL); |
277 next_element++; |
280 next_element++; |
278 } |
281 } |
279 return MAX_ELEMENTS; |
282 return MAX_ELEMENTS; |
280 } |
283 } |
281 |
284 |
282 static const char* const _airport_heading_strings[MAX_HEADINGS+2] = { |
285 #if 0 |
|
286 static const char* const _airport_heading_strings[] = { |
283 "TO_ALL", |
287 "TO_ALL", |
284 "HANGAR", |
288 "HANGAR", |
285 "TERM1", |
289 "TERM1", |
286 "TERM2", |
290 "TERM2", |
287 "TERM3", |
291 "TERM3", |
314 temp = &Airport->layout[i]; |
317 temp = &Airport->layout[i]; |
315 if (full_report) { |
318 if (full_report) { |
316 heading = (temp->heading == 255) ? MAX_HEADINGS+1 : temp->heading; |
319 heading = (temp->heading == 255) ? MAX_HEADINGS+1 : temp->heading; |
317 printf("Pos:%2d NPos:%2d Heading:%15s Block:%2d\n", temp->position, temp->next_position, |
320 printf("Pos:%2d NPos:%2d Heading:%15s Block:%2d\n", temp->position, temp->next_position, |
318 _airport_heading_strings[heading], AirportBlockToString(temp->block)); |
321 _airport_heading_strings[heading], AirportBlockToString(temp->block)); |
319 } |
322 } else { |
320 else { printf("P:%2d NP:%2d", temp->position, temp->next_position);} |
323 printf("P:%2d NP:%2d", temp->position, temp->next_position); |
|
324 } |
321 while (temp->next_in_chain != NULL) { |
325 while (temp->next_in_chain != NULL) { |
322 temp = temp->next_in_chain; |
326 temp = temp->next_in_chain; |
323 if (full_report) { |
327 if (full_report) { |
324 heading = (temp->heading == 255) ? MAX_HEADINGS+1 : temp->heading; |
328 heading = (temp->heading == 255) ? MAX_HEADINGS+1 : temp->heading; |
325 printf("Pos:%2d NPos:%2d Heading:%15s Block:%2d\n", temp->position, temp->next_position, |
329 printf("Pos:%2d NPos:%2d Heading:%15s Block:%2d\n", temp->position, temp->next_position, |
326 _airport_heading_strings[heading], AirportBlockToString(temp->block)); |
330 _airport_heading_strings[heading], AirportBlockToString(temp->block)); |
|
331 } else { |
|
332 printf("P:%2d NP:%2d", temp->position, temp->next_position); |
327 } |
333 } |
328 else { printf("P:%2d NP:%2d", temp->position, temp->next_position);} |
|
329 } |
334 } |
330 printf("\n"); |
335 printf("\n"); |
331 } |
336 } |
332 } |
337 } |
333 |
338 |
339 if (block & 0x0000ff00) { block >>= 8; i += 8; } |
344 if (block & 0x0000ff00) { block >>= 8; i += 8; } |
340 if (block & 0x000000f0) { block >>= 4; i += 4; } |
345 if (block & 0x000000f0) { block >>= 4; i += 4; } |
341 if (block & 0x0000000c) { block >>= 2; i += 2; } |
346 if (block & 0x0000000c) { block >>= 2; i += 2; } |
342 if (block & 0x00000002) { i += 1; } |
347 if (block & 0x00000002) { i += 1; } |
343 return i; |
348 return i; |
344 }*/ |
349 } |
|
350 #endif |
345 |
351 |
346 const AirportFTAClass* GetAirport(const byte airport_type) |
352 const AirportFTAClass* GetAirport(const byte airport_type) |
347 { |
353 { |
348 AirportFTAClass *Airport = NULL; |
354 AirportFTAClass *Airport = NULL; |
349 //FIXME -- AircraftNextAirportPos_and_Order -> Needs something nicer, don't like this code |
355 //FIXME -- AircraftNextAirportPos_and_Order -> Needs something nicer, don't like this code |