@@ -2092,8 +2092,17 @@ public boolean isVisible() {
20922092 * fog of war will be accessible, but isVisible will still return false.
20932093 * @see #exists
20942094 */
2095- public boolean isVisible (final Player player ) {
2096- return unitData .isVisible (player .getID ());
2095+ public boolean isVisible (Player player ) {
2096+ player = player == null ? game .self () : player ;
2097+ if (player != null ) {
2098+ return player .hasValidId () && unitData .isVisible (player .getID ());
2099+ }
2100+ for (int i = 0 ; i < Player .MAX_VALID_ID ; ++i ) {
2101+ if (unitData .isVisible (i )) {
2102+ return true ;
2103+ }
2104+ }
2105+ return false ;
20972106 }
20982107
20992108 /**
@@ -2107,6 +2116,9 @@ public boolean isTargetable() {
21072116 if (!exists ()) {
21082117 return false ;
21092118 }
2119+ if (!isVisible () && !game .isFlagEnabled (Flag .CompleteMapInformation )) {
2120+ return false ;
2121+ }
21102122 final UnitType ut = getType ();
21112123 if (!isCompleted () &&
21122124 !ut .isBuilding () &&
@@ -2205,7 +2217,7 @@ public boolean attack(final Unit target, final boolean shiftQueueCommand) {
22052217 }
22062218
22072219 public boolean build (final UnitType type ) {
2208- return issueCommand ( UnitCommand . train ( this , type ) );
2220+ return build ( type , TilePosition . None );
22092221 }
22102222
22112223 /**
@@ -2225,6 +2237,9 @@ public boolean build(final UnitType type) {
22252237 * @see Unit#canBuild
22262238 */
22272239 public boolean build (final UnitType type , final TilePosition target ) {
2240+ if (TilePosition .None .equals (target )) {
2241+ return train (type );
2242+ }
22282243 return issueCommand (UnitCommand .build (this , target , type ));
22292244 }
22302245
@@ -2269,7 +2284,23 @@ public boolean buildAddon(final UnitType type) {
22692284 * @see Unit#isTraining
22702285 * @see Unit#canTrain
22712286 */
2272- public boolean train (final UnitType type ) {
2287+ public boolean train () {
2288+ return train (UnitType .None );
2289+ }
2290+
2291+ public boolean train (UnitType type ) {
2292+ if (type == UnitType .None ) {
2293+ switch (getType ()) {
2294+ case Protoss_Carrier :
2295+ case Hero_Gantrithor :
2296+ type = Protoss_Interceptor ;
2297+ break ;
2298+ case Protoss_Reaver :
2299+ case Hero_Warbringer :
2300+ type = Protoss_Scarab ;
2301+ break ;
2302+ }
2303+ }
22732304 return issueCommand (UnitCommand .train (this , type ));
22742305 }
22752306
@@ -2876,6 +2907,9 @@ public boolean useTech(final TechType tech, final Position target) {
28762907 }
28772908
28782909 public boolean useTech (final TechType tech , final Unit target ) {
2910+ if (target == null ) {
2911+ return issueCommand (UnitCommand .useTech (this , tech ));
2912+ }
28792913 return issueCommand (UnitCommand .useTech (this , tech , target ));
28802914 }
28812915
@@ -3506,18 +3540,7 @@ public boolean canIssueCommandTypeGrouped(UnitCommandType ct, boolean checkComma
35063540 }
35073541
35083542 public boolean canTargetUnit (Unit targetUnit ) {
3509- if (targetUnit == null || !targetUnit .exists ()) {
3510- return false ;
3511- }
3512- final UnitType targetType = targetUnit .getType ();
3513- if (!targetUnit .isCompleted () && !targetType .isBuilding () && !targetUnit .isMorphing () &&
3514- targetType != Protoss_Archon && targetType != Protoss_Dark_Archon ) {
3515- return false ;
3516- }
3517- return targetType != Spell_Scanner_Sweep &&
3518- targetType != Spell_Dark_Swarm &&
3519- targetType != Spell_Disruption_Web &&
3520- targetType != Special_Map_Revealer ;
3543+ return canTargetUnit (targetUnit , true );
35213544 }
35223545
35233546 /**
@@ -3534,7 +3557,7 @@ public boolean canTargetUnit(Unit targetUnit, boolean checkCommandibility) {
35343557 if (checkCommandibility && !canCommand ()) {
35353558 return false ;
35363559 }
3537- return canTargetUnit ( targetUnit );
3560+ return targetUnit != null && targetUnit . isTargetable ( );
35383561 }
35393562
35403563 public boolean canAttack () {
@@ -3668,7 +3691,7 @@ public boolean canAttackGrouped(Position target, boolean checkCanTargetUnit, boo
36683691 if (checkCommandibilityGrouped && !canCommandGrouped (false )) {
36693692 return false ;
36703693 }
3671- return canAttackMoveGrouped (false , false ) || canAttackUnitGrouped ( false , false ) ;
3694+ return canAttackMoveGrouped (false , false );
36723695 }
36733696
36743697 public boolean canAttackGrouped (Unit target , boolean checkCanTargetUnit , boolean checkCanIssueCommandType , boolean checkCommandibilityGrouped , boolean checkCommandibility ) {
@@ -4051,7 +4074,7 @@ public boolean canBuildAddon(UnitType uType, boolean checkCanIssueCommandType, b
40514074 if (checkCommandibility && !canCommand ()) {
40524075 return false ;
40534076 }
4054- if (checkCanIssueCommandType && !canBuildAddon (uType , false )) {
4077+ if (checkCanIssueCommandType && !canBuildAddon (false )) {
40554078 return false ;
40564079 }
40574080 if (!game .canMake (uType , this )) {
0 commit comments