View Javadoc

1   /*
2      IMPORTANT !!!
3   
4      DO NOT EDIT THIS FILE. IT IS GENERATED FROM APPROPRIATE XML FILE
5      BY THE MessagesGenerator.xslt.
6      MODIFY THAT FILE INSTEAD OF THIS ONE.
7   
8    */
9   package cz.cuni.amis.pogamut.defcon.communication.messages.commands;
10  
11  import cz.cuni.amis.pogamut.base.communication.messages.*;
12  import cz.cuni.amis.pogamut.base.communication.worldview.*;
13  import cz.cuni.amis.pogamut.base.communication.worldview.object.*;
14  import cz.cuni.amis.pogamut.defcon.base3d.worldview.object.DefConLocation;
15  import cz.cuni.amis.pogamut.defcon.communication.messages.*;
16  import cz.cuni.amis.pogamut.defcon.communication.messages.commands.*;
17  import cz.cuni.amis.pogamut.defcon.communication.messages.infos.*;
18  import cz.cuni.amis.pogamut.defcon.consts.*;
19  import cz.cuni.amis.pogamut.defcon.consts.state.*;
20  import cz.cuni.amis.utils.exception.*;
21  
22  import java.util.*;
23  
24  import javabot.*;
25  
26  
27  /**
28   * Places a fleet of a specified type to a specified location.
29   */
30  public class PlaceFleet extends DefConCommand {
31      /**
32       * Target location of the new fleet.
33       */
34      private DefConLocation location = null;
35  
36      /**
37       * List of ships to create.
38       */
39      private UnitType[] ships = null;
40  
41  /**
42                       * Creates new instance of command PlaceFleet.
43                            
44                  Places a fleet of a specified type to a specified location. 
45          
46                       @param
47                        location Target location of the new fleet.
48                       @param
49                        ships List of ships to create.
50                   */
51      public PlaceFleet(DefConLocation location, UnitType[] ships) {
52          this.location = location;
53  
54          this.ships = ships;
55      }
56  
57  /**
58                           * Cloning constructor...
59                           * @param original
60                           */
61      public PlaceFleet(PlaceFleet original) {
62          this.location = original.location;
63  
64          this.ships = original.ships;
65      }
66  
67      /**
68       * Target location of the new fleet.
69       *
70       * @return DefConLocation
71       */
72      public DefConLocation getLocation() {
73          return this.location;
74      }
75  
76      /**
77       * Target location of the new fleet.
78       *
79       * @param location
80       *
81       * @return this object, allows you to chain setters
82       */
83      public PlaceFleet setLocation(DefConLocation location) {
84          this.location = location;
85  
86          return this;
87      }
88  
89      /**
90       * List of ships to create.
91       *
92       * @return UnitType[]
93       */
94      public UnitType[] getShips() {
95          return this.ships;
96      }
97  
98      /**
99       * List of ships to create.
100      *
101      * @param ships
102      *
103      * @return this object, allows you to chain setters
104      */
105     public PlaceFleet setShips(UnitType[] ships) {
106         this.ships = ships;
107 
108         return this;
109     }
110 
111     /**
112      * Performs the command - to be used only by the {@link DefConCommandExecutor}.
113      */
114     @Override
115     public void perform() {
116         DefConLocation location = getLocation();
117         UnitType[] types = getShips();
118         int[] intTypes = new int[types.length];
119 
120         for (int i = 0; i < types.length; ++i) {
121             intTypes[i] = types[i].id;
122         }
123 
124         JBot.PlaceFleet((float) location.getX(), (float) location.getY(), intTypes);
125     }
126 
127     /**
128      * Returns human readable serialization of the message.
129      *
130      * @return human readable string
131      */
132     @Override
133     public String toString() {
134         return "PlaceFleet[" + getStringizedFields() + "; Location = " + this.location +
135         "; Ships = " + this.ships + "]";
136     }
137 
138     /**
139      * Returns message in html format.
140      *
141      * @return html message
142      */
143     public String toHtmlString() {
144         return "<p><b>PlaceFleet:</b></p>" + "<p><i>Location:</i> " + this.location + "</p>" +
145         "<p><i>Ships:</i> " + this.ships + "</p>";
146     }
147 }