-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProductionManager.java
More file actions
63 lines (57 loc) · 2.13 KB
/
ProductionManager.java
File metadata and controls
63 lines (57 loc) · 2.13 KB
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
import bc.*;
import java.util.ArrayList;
/*
Production Manager (based on StrategyManager and squad requests)
takes into account squad requests to control factory production.
does NOT handle worker replication, WorkerManager does that
*/
public class ProductionManager{
InfoManager infoMan;
GameController gc;
public ProductionManager(){}
public ProductionManager(InfoManager im, GameController g){
infoMan = im;
gc = g;
}
public void update(Strategy strat){
}
public void move(){
// go through the factories (in infoMan) and make them produce stuff
for(Unit factory : infoMan.factories) {
int id = factory.id();
//TODO: pick an intelligent direction
boolean didSomething = false;
while(factory.structureGarrison().size() > 0) {
didSomething = false;
for(Direction dirToUnload : Utils.orderedDirections)
if(gc.canUnload(factory.id(), dirToUnload)) {
gc.unload(id, dirToUnload);
didSomething = true;
MapLocation locUnloaded = factory.location().mapLocation().add(dirToUnload);
//it's occupied now!
infoMan.tiles[locUnloaded.getX()][locUnloaded.getY()].unitID = 0;
}
if(!didSomething)
break;
}
if(gc.karbonite() < infoMan.moneyToSave + 40)
continue;
infoMan.combatSquads.sort(Squad.byUrgency());
infoMan.rocketSquads.sort(Squad.byUrgency());
Squad toFill = null;
if(infoMan.combatSquads.size() > 0 && infoMan.fighters.size() < MagicNumbers.MAX_FIGHTER_COUNT)
toFill = infoMan.combatSquads.get(0);
if(infoMan.rocketSquads.size() > 0 && (toFill == null || infoMan.rocketSquads.get(0).urgency > toFill.urgency))
toFill = infoMan.rocketSquads.get(0);
UnitType toMake = null;
if(toFill != null && toFill.requestedUnits.size() > 0){
toMake = toFill.requestedUnits.get(0);
if(infoMan.workerCount < 1)
toMake = UnitType.Worker;
}
if(toMake != null && gc.canProduceRobot(id,toMake) && gc.round() < MagicNumbers.ROUND_TO_STOP_PRODUCTION) {
gc.produceRobot(id, toMake);
}
}
}
}