2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 2 of the License, or
5
* (at your option) any later version.
6
* This program is distributed in the hope that it will be useful,
7
* but WITHOUT ANY WARRANTY; without even the implied warranty of
8
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
* GNU General Public License for more details.
10
* You should have received a copy of the GNU General Public License
11
* along with this program; if not, write to the Free Software
12
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
package games.strategy.triplea.Dynamix_AI.CommandCenter;
17
import games.strategy.engine.data.GameData;
18
import games.strategy.engine.data.NamedAttachable;
19
import games.strategy.engine.data.PlayerID;
20
import games.strategy.engine.data.ProductionFrontier;
21
import games.strategy.engine.data.ProductionRule;
22
import games.strategy.engine.data.Resource;
23
import games.strategy.engine.data.UnitType;
24
import games.strategy.triplea.Constants;
25
import games.strategy.triplea.Dynamix_AI.DUtils;
26
import games.strategy.triplea.Dynamix_AI.Others.PhaseType;
27
import games.strategy.triplea.attatchments.UnitAttachment;
28
import games.strategy.util.IntegerMap;
29
import java.util.ArrayList;
30
import java.util.HashMap;
31
import java.util.List;
37
public class GlobalCenter
39
public static boolean IsPaused = false;
40
public static final Object IsPaused_Object = new Object();
42
public static PhaseType FirstDynamixPhase;
43
public static PlayerID FirstDynamixPlayer;
44
public static int GameRound;
45
private static Resource PUResource;
46
public static Resource GetPUResource()
50
public static void Initialize(GameData data)
52
//This part just resets all the static variables to their default value so that other code will be able to fill in the real info
53
//(For example, the Dynamix_AI class sets the FirstDynamixPhase variable)
54
FirstDynamixPhase = PhaseType.Unknown;
55
FirstDynamixPlayer = null;
60
MapTerCountScale = 1.0F;
61
CurrentPhaseType = PhaseType.Unknown;
63
FastestUnitMovement = 0;
64
FastestLandUnitMovement = 0;
65
HighestTerProduction = -1;
66
PUsAtEndOfLastTurn = 0;
67
MergedAndAveragedProductionFronter = null;
68
AllMapUnitTypes = null;
70
//Now we 'initialize' by filling in some of the values (the rest are filled in somewhere else)
71
PUResource = data.getResourceList().getResource(Constants.PUS);
72
MapTerCount = data.getMap().getTerritories().size();
73
//75 is considered the 'base' map ter count (For comparison, Great Lakes War has 90)
74
MapTerCountScale = ((float)data.getMap().getTerritories().size() / 75.0F);
77
for(String alliance : data.getAllianceTracker().getAlliances())
79
List<PlayerID> playersInAlliance = DUtils.ToList(data.getAllianceTracker().getPlayersInAlliance(alliance));
80
if(playersInAlliance.size() > 1)
86
HighestTerProduction = DUtils.GetHighestTerProduction(data);
88
GenerateMergedAndAveragedProductionFrontier(data);
90
public static PlayerID CurrentPlayer;
91
public static int MapTerCount;
92
/**Please use this for all hard-coded values. (Multiply the hard-coded value by this float, and the hard-coded value will scale up or down with the maps*/
93
public static float MapTerCountScale;
94
public static PhaseType CurrentPhaseType;
95
public static boolean IsFFAGame;
96
public static int FastestUnitMovement;
97
public static int FastestLandUnitMovement;
98
public static int HighestTerProduction;
99
public static int PUsAtEndOfLastTurn;
101
private static ProductionFrontier MergedAndAveragedProductionFronter;
102
public static List<UnitType> AllMapUnitTypes;
104
* Generates a merged and averaged production frontier that can be used to determine TUV of units even when player is neutral or unknown.
105
* This method also sets the global FastestUnitMovement value and the AllMapUnitTypes list.
107
private static void GenerateMergedAndAveragedProductionFrontier(GameData data)
109
MergedAndAveragedProductionFronter = new ProductionFrontier("Merged and averaged global production frontier", data);
110
AllMapUnitTypes = new ArrayList<UnitType>();
112
HashMap<UnitType, Integer> purchaseCountsForUnit = new HashMap<UnitType, Integer>();
113
HashMap<UnitType, List<Integer>> differentCosts = new HashMap<UnitType, List<Integer>>();
114
for(PlayerID player : data.getPlayerList().getPlayers())
116
if(player.getProductionFrontier() == null)
118
for(ProductionRule rule : player.getProductionFrontier())
120
UnitType ut = (UnitType)rule.getResults().keySet().iterator().next();
121
UnitAttachment ua = UnitAttachment.get(ut);
122
DUtils.AddObjToListValueForKeyInMap(differentCosts, ut, rule.getCosts().getInt(PUResource));
123
purchaseCountsForUnit.put(ut, rule.getResults().keySet().size());
125
int movement = ua.getMovement(player);
126
if(movement > FastestUnitMovement)
127
FastestUnitMovement = movement;
128
if(movement > FastestLandUnitMovement && !ua.isSea() && !ua.isAir())
129
FastestLandUnitMovement = movement;
131
AllMapUnitTypes.add(ut);
135
for(UnitType unitType : differentCosts.keySet())
138
List<Integer> costs = differentCosts.get(unitType);
139
for(int cost : costs)
143
int averagedCost = (int)((float)totalCosts / (float)costs.size());
145
IntegerMap<NamedAttachable> results = new IntegerMap<NamedAttachable>();
146
results.put(unitType, purchaseCountsForUnit.get(unitType));
147
IntegerMap<Resource> cost = new IntegerMap<Resource>();
148
cost.put(PUResource, averagedCost);
149
ProductionRule rule = new ProductionRule("Averaged production rule for unit " + unitType.getName(), data, results, cost);
150
MergedAndAveragedProductionFronter.addRule(rule);
153
public static ProductionFrontier GetMergedAndAveragedProductionFrontier()
155
return MergedAndAveragedProductionFronter;