-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnit.cs
324 lines (297 loc) · 5.54 KB
/
Unit.cs
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
using System;
using System.Runtime.InteropServices;
/// <summary>
/// Represents a single unit on the map.
/// </summary>
public class Unit: Mappable
{
public Unit()
{
}
public Unit(IntPtr p)
{
ptr = p;
ID = Client.unitGetId(ptr);
iteration = BaseAI.iteration;
}
public override bool validify()
{
if(iteration == BaseAI.iteration) return true;
for(int i = 0; i < BaseAI.units.Length; i++)
{
if(BaseAI.units[i].ID == ID)
{
ptr = BaseAI.units[i].ptr;
iteration = BaseAI.iteration;
return true;
}
}
throw new ExistentialError();
}
public override int GetHashCode()
{
return Y * 20 + X;
}
public override bool Equals(object obj)
{
Unit other = (Unit)obj;
return (X == other.X) && (Y == other.Y);
}
#region Commands
/// <summary>
/// Make the unit move to the respective x and y location.
/// </summary>
public bool move(int x, int y)
{
validify();
return (Client.unitMove(ptr, x, y) == 0) ? false : true;
}
/// <summary>
/// Put dirt in a hole!
/// </summary>
public bool fill(Tile tile)
{
validify();
tile.validify();
return (Client.unitFill(ptr, tile.ptr) == 0) ? false : true;
}
/// <summary>
/// Dig out a tile
/// </summary>
public bool dig(Tile tile)
{
validify();
tile.validify();
return (Client.unitDig(ptr, tile.ptr) == 0) ? false : true;
}
/// <summary>
/// Command to attack another Unit.
/// </summary>
public bool attack(Unit target)
{
validify();
target.validify();
return (Client.unitAttack(ptr, target.ptr) == 0) ? false : true;
}
#endregion
#region Getters
/// <summary>
/// Unique Identifier
/// </summary>
public new int Id
{
get
{
validify();
int value = Client.unitGetId(ptr);
return value;
}
}
/// <summary>
/// X position of the object
/// </summary>
public new int X
{
get
{
validify();
int value = Client.unitGetX(ptr);
return value;
}
}
/// <summary>
/// Y position of the object
/// </summary>
public new int Y
{
get
{
validify();
int value = Client.unitGetY(ptr);
return value;
}
}
/// <summary>
/// The owner of this unit.
/// </summary>
public int Owner
{
get
{
validify();
int value = Client.unitGetOwner(ptr);
return value;
}
}
/// <summary>
/// The type of this unit. This type refers to list of UnitTypes.
/// </summary>
public int Type
{
get
{
validify();
int value = Client.unitGetType(ptr);
return value;
}
}
/// <summary>
/// Whether current unit has attacked or not.
/// </summary>
public bool HasAttacked
{
get
{
validify();
int value = Client.unitGetHasAttacked(ptr);
return value == 1;
}
}
/// <summary>
/// Whether the current unit has dug or not.
/// </summary>
public bool HasDug
{
get
{
validify();
int value = Client.unitGetHasDug(ptr);
return value == 1;
}
}
/// <summary>
/// Whether the current unit has filled or not.
/// </summary>
public bool HasFilled
{
get
{
validify();
int value = Client.unitGetHasFilled(ptr);
return value == 1;
}
}
/// <summary>
/// The current amount health this unit has remaining.
/// </summary>
public int HealthLeft
{
get
{
validify();
int value = Client.unitGetHealthLeft(ptr);
return value;
}
}
/// <summary>
/// The maximum amount of this health this unit can have
/// </summary>
public int MaxHealth
{
get
{
validify();
int value = Client.unitGetMaxHealth(ptr);
return value;
}
}
/// <summary>
/// The number of moves this unit has remaining.
/// </summary>
public int MovementLeft
{
get
{
validify();
int value = Client.unitGetMovementLeft(ptr);
return value;
}
}
/// <summary>
/// The maximum number of moves this unit can move.
/// </summary>
public int MaxMovement
{
get
{
validify();
int value = Client.unitGetMaxMovement(ptr);
return value;
}
}
/// <summary>
/// The range of this unit's attack.
/// </summary>
public int Range
{
get
{
validify();
int value = Client.unitGetRange(ptr);
return value;
}
}
/// <summary>
/// The power of the unit's offensive siege ability.
/// </summary>
public int OffensePower
{
get
{
validify();
int value = Client.unitGetOffensePower(ptr);
return value;
}
}
/// <summary>
/// The power of the unit's defensive siege ability.
/// </summary>
public int DefensePower
{
get
{
validify();
int value = Client.unitGetDefensePower(ptr);
return value;
}
}
/// <summary>
/// The power of this unit types's digging ability.
/// </summary>
public int DigPower
{
get
{
validify();
int value = Client.unitGetDigPower(ptr);
return value;
}
}
/// <summary>
/// The power of this unit type's filling ability.
/// </summary>
public int FillPower
{
get
{
validify();
int value = Client.unitGetFillPower(ptr);
return value;
}
}
/// <summary>
/// The power of this unit type's attack.
/// </summary>
public int AttackPower
{
get
{
validify();
int value = Client.unitGetAttackPower(ptr);
return value;
}
}
#endregion
#region Properties
#endregion
}