33
33
import java .util .Set ;
34
34
import mindustry .Vars ;
35
35
import mindustry .game .Team ;
36
- import mindustry .gen .Groups ;
37
- import mindustry .world .blocks .storage .CoreBlock ;
38
36
import org .checkerframework .checker .nullness .qual .Nullable ;
39
37
40
38
final class HexedStateImpl implements HexedState {
41
39
42
- // Item requirement to capture a hex
43
- private static final int ITEM_REQUIREMENT = 210 ;
44
-
45
40
private final Map <Hex , Team > controllers = new HashMap <>();
46
41
private final List <Hex > hexes ;
47
42
private final Set <Team > dying = new HashSet <>();
@@ -51,9 +46,15 @@ final class HexedStateImpl implements HexedState {
51
46
private final Duration duration ;
52
47
private float counter = 0f ;
53
48
private final ImmutableSchematic base ;
49
+ private final HexedCaptureProgress calculator ;
54
50
55
- HexedStateImpl (final ImmutableSchematic base , final List <Hex > hexes , final Duration duration ) {
51
+ HexedStateImpl (
52
+ final ImmutableSchematic base ,
53
+ final HexedCaptureProgress calculator ,
54
+ final List <Hex > hexes ,
55
+ final Duration duration ) {
56
56
this .base = base ;
57
+ this .calculator = calculator ;
57
58
this .duration = duration ;
58
59
this .hexes = List .copyOf (hexes );
59
60
for (final var hex : this .hexes ) {
@@ -146,54 +147,21 @@ public float getProgress(final Hex hex, final Team team) {
146
147
}
147
148
148
149
private float getProgress0 (final Hex hex , final Team team ) {
149
- return (this .progress
150
- .get (Point2 .pack (hex .getTileX (), hex .getTileY ()), () -> new IntFloatMap (4 ))
151
- .get (team .id )
152
- / ITEM_REQUIREMENT )
150
+ return this .progress
151
+ .get (Point2 .pack (hex .getTileX (), hex .getTileY ()), () -> new IntFloatMap (4 ))
152
+ .get (team .id )
153
153
* 100F ;
154
154
}
155
155
156
156
public void updateProgress (final Hex hex ) {
157
- final var center = Vars .world .tile (hex .getTileX (), hex .getTileY ());
158
-
159
- if (center .block () instanceof CoreBlock ) {
160
- this .controllers .put (hex , center .team ());
161
- }
162
-
163
157
final var progress = this .progress .get (Point2 .pack (hex .getTileX (), hex .getTileY ()), () -> new IntFloatMap (4 ));
164
158
progress .clear ();
165
- Groups .unit
166
- .intersect (
167
- hex .getX () - hex .getRadius (),
168
- hex .getY () - hex .getRadius (),
169
- hex .getDiameter (),
170
- hex .getDiameter ())
171
- .each (u -> {
172
- if (!u .isPlayer () && hex .contains (u .tileX (), u .tileY ())) {
173
- progress .increment (u .team ().id , u .health () / 10F );
174
- }
175
- });
176
-
177
- for (int cx = hex .getTileX () - hex .getTileRadius (); cx < hex .getTileX () + hex .getTileRadius (); cx ++) {
178
- for (int cy = hex .getTileY () - hex .getTileRadius (); cy < hex .getTileY () + hex .getTileRadius (); cy ++) {
179
- final var tile = Vars .world .tile (cx , cy );
180
- if (tile != null
181
- && tile .synthetic ()
182
- && hex .contains (tile .x , tile .y )
183
- && tile .block ().requirements != null ) {
184
- for (final var stack : tile .block ().requirements ) {
185
- progress .increment (tile .team ().id , stack .amount * stack .item .cost );
186
- }
187
- }
188
- }
189
- }
190
-
159
+ this .calculator .calculate (hex , progress );
191
160
final var data = Vars .state .teams .getActive ().max (t -> progress .get (t .team .id ));
192
- if (data != null && progress .get (data .team .id ) >= ITEM_REQUIREMENT ) {
161
+ if (data != null && progress .get (data .team .id ) >= 1F ) {
193
162
this .controllers .put (hex , data .team );
194
- return ;
163
+ } else {
164
+ this .controllers .put (hex , null );
195
165
}
196
-
197
- this .controllers .put (hex , null );
198
166
}
199
167
}
0 commit comments