File: UnitDefHelp.java

package info (click to toggle)
spring 104.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 47,512 kB
  • sloc: cpp: 391,093; ansic: 79,943; python: 12,356; java: 12,201; awk: 5,889; sh: 1,826; xml: 655; makefile: 486; perl: 405; php: 211; objc: 194; sed: 2
file content (105 lines) | stat: -rwxr-xr-x 3,043 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// copyright Hugh Perkins 2006, 2009

// Adapted from AF's C++ version 2006, ported to C# 2006, then to Java in 2009

package hughai.unitdata;

import com.springrts.ai.oo.clb.*;

import hughai.PlayerObjects;
import hughai.ResourceManager;
import hughai.*;
import hughai.utils.LogFile;


public class UnitDefHelp
{
   OOAICallback aicallback;
   ResourceManager resourceManager;
   LogFile logfile;

   public UnitDefHelp( PlayerObjects playerObjects )
   {
      this.aicallback = playerObjects.getAicallback();
      this.resourceManager = playerObjects.getResourceManager();
      this.logfile = playerObjects.getLogFile();
   }

   public boolean IsEnergy(UnitDef ud){
      if(ud.isNeedGeo()){
         return false;
      }
      if(ud.getUpkeep(resourceManager.getEnergyResource()) < -1) return true;
      if((ud.getWindResourceGenerator(resourceManager.getEnergyResource()) > 0)
            &&(aicallback.getMap().getMaxWind() > 9 )) return true;
      if(ud.getTidalResourceGenerator(resourceManager.getEnergyResource()) > 0 ) return true;
      if(ud.getMakesResource(resourceManager.getEnergyResource()) > 5) return true;
      return false;
   }

   public boolean IsMobile(UnitDef ud){
      if(ud.getSpeed() < 1) return false;
      if(ud.getMoveData() != null) return true;
      if(ud.isAbleToFly() ) return true;
      return false;
   }

   public boolean IsBoat( UnitDef unitdef )
   {
      if( IsMobile( unitdef ) && unitdef.getMinWaterDepth() > 0 )
      {
         return true;
      }
      return false;
   }

   public boolean IsConstructor( UnitDef unitdef )
   {
      if(unitdef.getBuildOptions().size() == 0) return false;
      return( unitdef.isBuilder() && IsMobile( unitdef ) );
   }

   public boolean IsFactory(UnitDef ud){
      if (ud.getBuildOptions().size() == 0) return false;
      if(ud.getType().toLowerCase() == "factory" ) return true;
      return ud.isBuilder() && !IsMobile(ud);
   }

   public boolean IsGroundMelee( UnitDef ud )
   {
      return IsMobile( ud ) && ud.isAbleToAttack();
   }

   public boolean IsMex(UnitDef ud){
     // logfile.WriteLine( "unitdefhelp.ismex, ud type: " + ud.getType() );
      //ud.
      //if(ud.getType().toLowerCase() == "metalextractor"){
       //  return true;
      //}
      return ( ud.getExtractsResource( resourceManager.getMetalResource() ) > 0 );
      //return false;
   }

   public boolean IsAirCraft(UnitDef ud){
      if(ud.getType().toLowerCase() == "fighter")	return true;
      if(ud.getType().toLowerCase() == "bomber")	return true;
      if(ud.isAbleToFly()&&(ud.getMoveData() == null)) return true;
      return false;
   }

   public boolean IsGunship(UnitDef ud){
      if(IsAirCraft(ud)&&ud.isHoverAttack()) return true;
      return false;
   }

   public boolean IsFighter(UnitDef ud){
      if(IsAirCraft(ud)&& !ud.isHoverAttack()) return true;
      return false;
   }

   public boolean IsBomber(UnitDef ud){
      if(IsAirCraft(ud)&&(ud.getType().toLowerCase() == "bomber" )) return true;
      return false;
   }        
}