Changeset 3dcc27d7d496d4bdf4b9329acec09d11d077da7d
- Timestamp:
- 05/20/07 12:47:08
(2 years ago)
- Author:
- Christopher Jung <bktheg@web.de>
- git-committer:
- Christopher Jung <bktheg@web.de> 1179658028 +0200
- git-parent:
[5b2bf669f1f869829e390eabfc26aa967ec02fbd]
- git-author:
- Christopher Jung <bktheg@web.de> 1179658028 +0200
- Message:
Naechster Versuch die Exceptions beim Kapern in den Griff zu bekommen
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r73f311b |
r3dcc27d |
|
| 457 | 457 | |
|---|
| 458 | 458 | /** |
|---|
| | 459 | * Prueft, ob das aktuell ausgewaehlte gegnerische Schiff ein gueltiges Ziel ist |
|---|
| | 460 | * (das Schiff also existiert). Bei gueltigen Zielen ist ein aufruf von {@link #getEnemyShip()} |
|---|
| | 461 | * gefahrlos moeglich. |
|---|
| | 462 | * @return <code>true</code>, falls das Ziel gueltig ist |
|---|
| | 463 | */ |
|---|
| | 464 | public boolean isValidTarget() { |
|---|
| | 465 | if( this.activeSEnemy >= this.enemyShips.size() ) { |
|---|
| | 466 | return false; |
|---|
| | 467 | } |
|---|
| | 468 | if( this.activeSEnemy < 0 ) { |
|---|
| | 469 | return false; |
|---|
| | 470 | } |
|---|
| | 471 | return true; |
|---|
| | 472 | } |
|---|
| | 473 | |
|---|
| | 474 | /** |
|---|
| 459 | 475 | * Liefert den Index des naechsten feindlichen Schiffes nach dem aktuell ausgewaehlten. |
|---|
| 460 | 476 | * Bevorzugt werden Schiffe gleichen Typs |
|---|
| … | … | |
| 462 | 478 | */ |
|---|
| 463 | 479 | public int getNewTargetIndex() { |
|---|
| 464 | | if( this.activeSEnemy < this.enemyShips.size() ) { |
|---|
| 465 | | boolean foundOld = false; |
|---|
| 466 | | |
|---|
| 467 | | SQLResultRow enemyShip = this.enemyShips.get(this.activeSEnemy); |
|---|
| 468 | | |
|---|
| 469 | | // Schiff gleichen Typs hinter dem aktuellen Schiff suchen |
|---|
| 470 | | List<SQLResultRow> enemyShips = getEnemyShips(); |
|---|
| | 480 | // Falls das aktuelle Schiff ungueltig, dann das erstbeste in der Liste zurueckgeben |
|---|
| | 481 | if( !this.isValidTarget() ) { |
|---|
| 471 | 482 | for( int i=0; i < enemyShips.size(); i++ ) { |
|---|
| 472 | 483 | SQLResultRow aship = enemyShips.get(i); |
|---|
| 473 | | if( !foundOld && (aship.getInt("id") == enemyShip.getInt("id")) ) { |
|---|
| 474 | | foundOld = true; |
|---|
| 475 | | } |
|---|
| 476 | | else if( foundOld && (aship.getInt("type") == enemyShip.getInt("type")) && ((aship.getString("docked").length() == 0) || (aship.getString("docked").charAt(0) != 'l')) && (aship.getInt("action") & Battle.BS_DESTROYED) == 0 && (aship.getInt("action") & Battle.BS_SECONDROW) == 0 ) { |
|---|
| | 484 | |
|---|
| | 485 | if( ((aship.getString("docked").length() == 0) || (aship.getString("docked").charAt(0) != 'l')) && (aship.getInt("action") & Battle.BS_DESTROYED) == 0 && (aship.getInt("action") & Battle.BS_SECONDROW) == 0 ) { |
|---|
| 477 | 486 | return i; |
|---|
| 478 | 487 | } |
|---|
| 479 | 488 | } |
|---|
| 480 | | |
|---|
| 481 | | // Schiff gleichen Typs vor dem aktuellen Schiff suchen |
|---|
| 482 | | for( int i=0; i < enemyShips.size(); i++ ) { |
|---|
| 483 | | SQLResultRow aship = enemyShips.get(i); |
|---|
| 484 | | if( aship.getInt("id") == enemyShip.getInt("id") ) { |
|---|
| 485 | | break; |
|---|
| 486 | | } |
|---|
| 487 | | if( (aship.getInt("type") == enemyShip.getInt("type")) && ((aship.getString("docked").length() == 0) || (aship.getString("docked").charAt(0) != 'l')) && (aship.getInt("action") & Battle.BS_DESTROYED) == 0 && (aship.getInt("action") & Battle.BS_SECONDROW) == 0 ) { |
|---|
| 488 | | return i; |
|---|
| 489 | | } |
|---|
| | 489 | |
|---|
| | 490 | return 0; |
|---|
| | 491 | } |
|---|
| | 492 | |
|---|
| | 493 | boolean foundOld = false; |
|---|
| | 494 | |
|---|
| | 495 | SQLResultRow enemyShip = this.enemyShips.get(this.activeSEnemy); |
|---|
| | 496 | |
|---|
| | 497 | // Schiff gleichen Typs hinter dem aktuellen Schiff suchen |
|---|
| | 498 | List<SQLResultRow> enemyShips = getEnemyShips(); |
|---|
| | 499 | for( int i=0; i < enemyShips.size(); i++ ) { |
|---|
| | 500 | SQLResultRow aship = enemyShips.get(i); |
|---|
| | 501 | if( !foundOld && (aship.getInt("id") == enemyShip.getInt("id")) ) { |
|---|
| | 502 | foundOld = true; |
|---|
| | 503 | } |
|---|
| | 504 | else if( foundOld && (aship.getInt("type") == enemyShip.getInt("type")) && ((aship.getString("docked").length() == 0) || (aship.getString("docked").charAt(0) != 'l')) && (aship.getInt("action") & Battle.BS_DESTROYED) == 0 && (aship.getInt("action") & Battle.BS_SECONDROW) == 0 ) { |
|---|
| | 505 | return i; |
|---|
| | 506 | } |
|---|
| | 507 | } |
|---|
| | 508 | |
|---|
| | 509 | // Schiff gleichen Typs vor dem aktuellen Schiff suchen |
|---|
| | 510 | for( int i=0; i < enemyShips.size(); i++ ) { |
|---|
| | 511 | SQLResultRow aship = enemyShips.get(i); |
|---|
| | 512 | if( aship.getInt("id") == enemyShip.getInt("id") ) { |
|---|
| | 513 | break; |
|---|
| | 514 | } |
|---|
| | 515 | if( (aship.getInt("type") == enemyShip.getInt("type")) && ((aship.getString("docked").length() == 0) || (aship.getString("docked").charAt(0) != 'l')) && (aship.getInt("action") & Battle.BS_DESTROYED) == 0 && (aship.getInt("action") & Battle.BS_SECONDROW) == 0 ) { |
|---|
| | 516 | return i; |
|---|
| 490 | 517 | } |
|---|
| 491 | 518 | } |
|---|
| … | … | |
| 494 | 521 | for( int i=0; i < enemyShips.size(); i++ ) { |
|---|
| 495 | 522 | SQLResultRow aship = enemyShips.get(i); |
|---|
| | 523 | if( aship.getInt("id") == enemyShip.getInt("id") ) { |
|---|
| | 524 | continue; |
|---|
| | 525 | } |
|---|
| | 526 | |
|---|
| 496 | 527 | if( ((aship.getString("docked").length() == 0) || (aship.getString("docked").charAt(0) != 'l')) && (aship.getInt("action") & Battle.BS_DESTROYED) == 0 && (aship.getInt("action") & Battle.BS_SECONDROW) == 0 ) { |
|---|
| 497 | 528 | return i; |
|---|
| r887b91b |
r3dcc27d |
|
| 292 | 292 | sid.free(); |
|---|
| 293 | 293 | |
|---|
| | 294 | // TODO: Das Entfernen eines Schiffes aus der Liste sollte in Battle |
|---|
| | 295 | // durchgefuehrt werden und den Zielindex automatisch anpassen |
|---|
| | 296 | // (durch das Entfernen von Schiffen kann der Zielindex ungueltig geworden sein) |
|---|
| | 297 | |
|---|
| 294 | 298 | // Ein neues Ziel auswaehlen |
|---|
| 295 | 299 | battle.setEnemyShipIndex(battle.getNewTargetIndex()); |
|---|
| … | … | |
| 313 | 317 | return RESULT_HALT; |
|---|
| 314 | 318 | } |
|---|
| 315 | | |
|---|
| | 319 | |
|---|
| | 320 | if( !battle.isValidTarget() ) { |
|---|
| | 321 | battle.setEnemyShipIndex(battle.getNewTargetIndex()); |
|---|
| | 322 | } |
|---|
| | 323 | |
|---|
| 316 | 324 | Ships.recalculateShipStatus(enemyShip.getInt("id")); |
|---|
| 317 | 325 | |
|---|