-
Notifications
You must be signed in to change notification settings - Fork 0
/
Data.as
258 lines (227 loc) · 6.99 KB
/
Data.as
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
package com.brockw.stickwar.campaign.controllers.EasyController
{
import com.brockw.stickwar.*;
import com.brockw.stickwar.campaign.*;
import com.brockw.stickwar.engine.*;
import com.brockw.stickwar.engine.Ai.*;
import com.brockw.stickwar.engine.Ai.command.*;
import com.brockw.stickwar.engine.Team.*;
import com.brockw.stickwar.engine.multiplayer.moves.*;
import com.brockw.stickwar.engine.units.*;
import flash.utils.*;
public class Data
{
public static const T_NOT_RESEARCHED:int = 0;
public static const T_RESEARCHING:int = 1;
public static const T_RESEARCHED:int = 2;
private var _gameScreen:GameScreen;
public function Data(gameScreen:GameScreen)
{
super();
this._gameScreen = gameScreen;
}
public function timer(type:String = "frames") : Number
{
return this._gameScreen.game.frame;
}
public function center(pos:String = "x") : Number
{
pos = pos.toLowerCase();
if(pos == "x" || pos == "px")
{
return this._gameScreen.game.map.width / 2;
}
else if(pos == "y" || pos == "py")
{
return this._gameScreen.game.map.height / 2;
}
return 0;
}
public function unitAmount(team:Team, unitName:String = "") : int
{
var rUnit:Unit = null;
var unitType:int = 0;
var unitNum:int = 0;
if(unitName != "")
{
rUnit = this._gameScreen.game.unitFactory.getUnit(StringMap.unitNameToType(unitName));
unitType = StringMap.unitNameToType(unitName);
unitNum = team.unitGroup[unitType].length;
}
else
{
for each(rUnit in team.units)
{
if(rUnit.isAlive())
{
unitNum += 1;
}
}
}
return unitNum;
}
public function state(state:int, currState:int) : Boolean
{
return state == currState;
}
public static function isOdd(number:int) : Boolean
{
return number % 2 != 0;
}
public function isTime(num:Number, doafter:Boolean = false) : Boolean
{
// Odd numbers are not devidable by 2
var frames:int = int(num * 30);
var gameFrames:* = this._gameScreen.game.frame;
var result:Boolean = gameFrames == frames;
if(doafter)
{
return gameFrames > frames;
}
if(this._gameScreen.isFastForward)
{
if(isOdd(gameFrames) && isOdd(frames))
{
result = gameFrames == frames;
}
else if(!isOdd(gameFrames) && !isOdd(frames))
{
result = gameFrames == frames;
}
else
{
result = gameFrames - 1 == frames;
}
}
return result;
}
public function statuePosition(team:Team, pos:String = "x") : Number
{
pos = pos.toUpperCase();
if(pos == "X" || pos == "PX")
{
return team.statue.px;
}
else if(pos == "Y" || pos == "PY")
{
return team.statue.py;
}
return 0;
}
public function statueType(team:Team) : String
{
return team.statueType;
}
public function homeX(team:Team) : Number
{
return team.homeX;
}
public function campaignInfo(infType:String) : *
{
infType = infType.toUpperCase();
if(infType == "NAME" || infType == "TITLE")
{
return this._gameScreen.main.campaign.getCurrentLevel().title;
}
else if(infType == "DESC" || infType == "DESCRIPTION")
{
return this._gameScreen.main.campaign.getCurrentLevel().storyName;
}
else if(infType == "NUM" || infType == "NUMBER")
{
return this._gameScreen.team.game.main.campaign.currentLevel;
}
else if(infType == "DIFF" || infType == "DIFFICULTY" || infType == "DIF")
{
return this._gameScreen.team.game.main.campaign.difficultyLevel;
}
else if(infType == "TIP")
{
var prefix:String = "Tip: ";
var tip:String = this._gameScreen.main.campaign.getCurrentLevel().tip;
if (tip.indexOf(prefix) === 0) {
return tip.substring(prefix.length);
}
}
return null;
}
public function researchedMap() : Array
{
var researchedTechs:Array = new Array(61);
var availableTechs:Dictionary = Tech.isResearchedMap;
var i = 0;
for(i = 0; i >= -61; i--)
{
if(availableTechs[i] == true)
{
researchedTechs[Math.abs(i)] = i;
} else {
researchedTechs[Math.abs(i)] = 0;
}
}
return researchedTechs;
}
public function cameraPos() : Number
{
return this._gameScreen.game.screenX;
}
public function techState(techNum:int, team:Team) : int
{
if(team.tech.isResearched(techNum))
{
return T_RESEARCHED;
}
else if(team.tech.isResearching(techNum))
{
return T_RESEARCHING;
}
else if(!team.tech.isResearching(techNum) && !team.tech.isResearched(techNum))
{
return T_NOT_RESEARCHED;
}
return null;
}
public function teamState(team:Team) : int
{
if(team.currentAttackState == Team.G_GARRISON)
{
return Team.G_GARRISON;
}
else if(team.currentAttackState == Team.G_DEFEND)
{
return Team.G_DEFEND;
}
else if(team.currentAttackState == Team.G_ATTACK)
{
return Team.G_ATTACK;
}
return null;
}
public function teamInfo(infType:String, team:Team) : *
{
infType = infType.toUpperCase();
infType = infType.split(" ").join("");
if(infType == "GOLD" || infType == "G")
{
return team.gold;
}
else if(infType == "MANA" || infType == "M")
{
return team.mana;
}
else if(infType == "POPULATION" || infType == "POP" || infType == "P")
{
return team.population;
}
else if(infType == "STATUE")
{
return team.statue.health;
}
return null;
}
public function random(min:Number, max:Number) : *
{
return min + Math.floor(Math.random() * (max - min + 1))
}
}
}