BWAPI
|
00001 /* 00002 * SCVAgent.cpp 00003 */ 00004 #include "SCVAgent.h" 00005 #include "GroundAgent.h" 00006 00007 #include "TacticalBuildingPlacer.h" 00008 00009 #include <BWAPI.h> 00010 00011 using namespace BWAPI; 00012 00013 00014 SCVAgent::SCVAgent(Unit &u) 00015 : GroundAgent(u) 00016 , wasConstructing(false) 00017 , constructingStructure(NULL) 00018 { } 00019 00020 void SCVAgent::update() 00021 { 00022 switch (state) { 00023 00024 case IdleState: 00025 // be idle 00026 break; 00027 00028 case GatherState: 00029 // Gather minerals 00030 if (unitTarget->getType().isMineralField()) 00031 { 00032 if (!unit.isGatheringMinerals()) 00033 unit.gather(unitTarget); 00034 } 00035 00036 // Gather gas 00037 else if (unitTarget->getType().isRefinery()) 00038 { 00039 if (!unit.isGatheringGas()) 00040 unit.gather(unitTarget); 00041 } 00042 break; 00043 00044 case BuildState: 00045 // Return cargo 00046 //if (unit.isCarryingGas() || unit.isCarryingMinerals()) { 00047 // unit.returnCargo(); 00048 //} 00049 00050 // Done? 00051 if (!unit.isConstructing() && constructingStructure != NULL) 00052 { 00053 if (constructingStructure->isCompleted()) 00054 { 00055 constructingStructure = NULL; 00056 buildingReserved = false; 00057 state = IdleState; 00058 } 00059 } 00060 00061 // Reserve a build location 00062 else if (!buildingReserved) 00063 { 00064 TacticalBuildingPlacer &tbp = TacticalBuildingPlacer::instance(); 00065 buildingLocation = tbp.instance().reserveBuildLocation(unitTypeTarget, Broodwar->self()->getStartLocation(), &unit); 00066 if (buildingLocation != TilePositions::None) 00067 { 00068 buildingReserved = true; 00069 } 00070 unit.move(Position(buildingLocation)); 00071 } 00072 00073 // Build it 00074 else if (buildingReserved && !unit.isConstructing()) 00075 { 00076 unit.build(buildingLocation, unitTypeTarget); 00077 } 00078 00079 // Building... 00080 else if (unit.isConstructing()) 00081 { 00082 constructingStructure = unit.getBuildUnit(); 00083 } 00084 break; 00085 } 00086 00087 GroundAgent::update(); 00088 }