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   * Sets action target of a unit.
29   */
30  public class SetActionTarget extends DefConCommand {
31      /**
32       * Id of unit to set target of.
33       */
34      private int unitId = 0;
35  
36      /**
37       * Target of the unit.
38       */
39      private int targetUnitId = 0;
40  
41      /**
42       * Attack target of the unit.
43       */
44      private DefConLocation location = null;
45  
46  /**
47                       * Creates new instance of command SetActionTarget.
48                            
49                  Sets action target of a unit. 
50          
51                       @param
52                        unitId Id of unit to set target of.
53                       @param
54                        targetUnitId Target of the unit.
55                       @param
56                        location Attack target of the unit.
57                   */
58      public SetActionTarget(int unitId, int targetUnitId, DefConLocation location) {
59          this.unitId = unitId;
60  
61          this.targetUnitId = targetUnitId;
62  
63          this.location = location;
64      }
65  
66  /**
67                           * Cloning constructor...
68                           * @param original
69                           */
70      public SetActionTarget(SetActionTarget original) {
71          this.unitId = original.unitId;
72  
73          this.targetUnitId = original.targetUnitId;
74  
75          this.location = original.location;
76      }
77  
78      /**
79       * Id of unit to set target of.
80       *
81       * @return int
82       */
83      public int getUnitId() {
84          return this.unitId;
85      }
86  
87      /**
88       * Id of unit to set target of.
89       *
90       * @param unitId
91       *
92       * @return this object, allows you to chain setters
93       */
94      public SetActionTarget setUnitId(int unitId) {
95          this.unitId = unitId;
96  
97          return this;
98      }
99  
100     /**
101      * Target of the unit.
102      *
103      * @return int
104      */
105     public int getTargetUnitId() {
106         return this.targetUnitId;
107     }
108 
109     /**
110      * Target of the unit.
111      *
112      * @param targetUnitId
113      *
114      * @return this object, allows you to chain setters
115      */
116     public SetActionTarget setTargetUnitId(int targetUnitId) {
117         this.targetUnitId = targetUnitId;
118 
119         return this;
120     }
121 
122     /**
123      * Attack target of the unit.
124      *
125      * @return DefConLocation
126      */
127     public DefConLocation getLocation() {
128         return this.location;
129     }
130 
131     /**
132      * Attack target of the unit.
133      *
134      * @param location
135      *
136      * @return this object, allows you to chain setters
137      */
138     public SetActionTarget setLocation(DefConLocation location) {
139         this.location = location;
140 
141         return this;
142     }
143 
144     /**
145      * Performs the command - to be used only by the {@link DefConCommandExecutor}.
146      */
147     @Override
148     public void perform() {
149         DefConLocation location = getLocation();
150 
151         if (location == null) {
152             JBot.SetActionTarget(getUnitId(), getTargetUnitId(), 0f, 0f);
153         } else {
154             JBot.SetActionTarget(getUnitId(), getTargetUnitId(), (float) location.getX(),
155                 (float) location.getY());
156         }
157     }
158 
159     /**
160      * Returns human readable serialization of the message.
161      *
162      * @return human readable string
163      */
164     @Override
165     public String toString() {
166         return "SetActionTarget[" + getStringizedFields() + "; UnitId = " + this.unitId +
167         "; TargetUnitId = " + this.targetUnitId + "; Location = " + this.location + "]";
168     }
169 
170     /**
171      * Returns message in html format.
172      *
173      * @return html message
174      */
175     public String toHtmlString() {
176         return "<p><b>SetActionTarget:</b></p>" + "<p><i>UnitId:</i> " + this.unitId + "</p>" +
177         "<p><i>TargetUnitId:</i> " + this.targetUnitId + "</p>" + "<p><i>Location:</i> " +
178         this.location + "</p>";
179     }
180 }