10 #include "buildtype.h" 18 #include <unordered_map> 19 #include <unordered_set> 39 return type == n.
type && pos == n.
pos;
42 return type != n.
type || pos != n.
pos;
59 double mineralsPerFramePerGatherer = 0;
60 double gasPerFramePerGatherer = 0;
61 std::array<double, 3> usedSupply{};
62 std::array<double, 3> maxSupply{};
63 std::array<double, 3> inprodSupply{};
64 std::unordered_map<const BuildType*, std::vector<BuildStateUnit>>
units;
72 int availableGases = 0;
74 bool autoBuildRefineries =
true;
75 bool autoBuildHatcheries =
true;
76 bool isExpanding =
false;
84 template <
class Archive>
86 template <
class Archive>
88 template <
class Archive>
90 template <
class Archive>
92 template <
class Archive>
94 template <
class Archive>
110 Module* module_ =
nullptr;
113 int lastEvaluate = 0;
120 bool isSimulation =
false;
123 std::unordered_map<UpcId, std::tuple<autobuild::BuildEntry, float>>
125 std::function<bool(autobuild::BuildState&)>
queue;
127 void postBlackboardKey(std::string
const& key,
Blackboard::Data const& data);
136 virtual void update(
State* state)
override;
197 std::function<
void()> builtCallback);
203 void build(
const BuildType* type, std::function<
void()> builtCallback);
218 bool buildN(
const BuildType* type,
int n);
224 bool buildN(
const BuildType* type,
int n,
int simultaneous);
238 return initialBuildState;
241 return targetBuildState;
245 std::string frameToString(
State* state);
246 std::vector<std::vector<std::string>> unitsToString(
State* state);
247 std::vector<std::vector<std::string>> productionToString(
State* state);
248 std::vector<std::vector<std::string>> queueToString(
State* state);
249 std::vector<std::string> upgradesToString(
State* state);
250 std::vector<std::string> describeState(
State* state);
251 int logInvocations = 0;
252 void log(
State* state);
258 virtual void draw(
State* state);
265 virtual std::shared_ptr<AutoBuildTask>
266 createTask(
State* state,
int srcUpcId, std::shared_ptr<UPCTuple> srcUpc);
268 virtual void checkForNewUPCs(
State* state);
270 virtual void step(
State* state)
override;
294 std::vector<Target> targets)
299 for (
auto& target : targets) {
300 if (target.n == -1) {
303 buildN(target.type, target.n);
309 namespace autobuild {
BuildType const * type
Definition: autobuild.h:282
BuildState getMyState(State *state)
Definition: autobuild.cpp:212
Game state.
Definition: state.h:42
Definition: autobuild.h:26
bool operator!=(BuildEntry n) const
Definition: autobuild.h:41
std::unordered_map< UpcId, std::tuple< autobuild::BuildEntry, float > > scheduledUpcs
Each of these UPCs is being proxied by this task.
Definition: autobuild.h:124
int FrameNum
Definition: basetypes.h:22
Target(BuildType const *type, int n=-1)
Definition: autobuild.h:285
autobuild::BuildState initialBuildState
Definition: autobuild.h:115
DefaultAutoBuildTask(int upcId, State *state, Module *module, std::vector< Target > targets)
Definition: autobuild.h:290
int busyUntil
Definition: autobuild.h:28
Represents and holds information about buildable types (units, upgrades, techs).
Definition: buildtype.h:36
int larvaCount(const autobuild::BuildState &st, const autobuild::BuildStateUnit &u)
Returns the number of Larva at this Hatchery/Lair/Hive in this BuildState.
Definition: autobuild.cpp:160
bool has(const BuildState &st, const BuildType *type)
Returns true if we have any of this BuildType completed in this BuildState.
Definition: autobuild.cpp:77
Task is currently ongoing.
A very simple build order which builds a fixed list of targets and then stops.
Definition: autobuild.h:279
std::vector< BuildStateUnit > morphingHatcheries
Definition: autobuild.h:68
int larvaTimer
Definition: autobuild.h:30
void load(Archive &ar, BuildStateUnit &stu)
Definition: autobuild.cpp:1696
autobuild::BuildState & lastEvaluateTargetState()
Definition: autobuild.h:240
const BuildType * type
Definition: autobuild.h:27
Describes a state of the game, either now or in a hypothetical future, for use in AutoBuilds...
Definition: autobuild.h:54
virtual void buildStep(autobuild::BuildState &st)
The meat of a build order lives in buildStep().
Definition: autobuild.h:182
bool isInProduction(const BuildState &st, const BuildType *type)
Returns true if we are currently producing this BuildType in this BuildState.
Definition: autobuild.cpp:106
mapbox::util::variant< bool, int, float, double, std::string, Position, std::shared_ptr< SharedController >, std::unordered_map< int, int >> Data
A variant of types that are allowed in the Blackboard's key-value storage.
Definition: blackboard.h:99
std::function< bool(autobuild::BuildState &)> queue
Definition: autobuild.h:125
bool operator==(BuildEntry n) const
Definition: autobuild.h:38
A task that tracks execution of multiple other tasks.
Definition: task.h:173
bool hasUnit(const BuildState &st, const BuildType *type)
Returns true if we have this unit in this BuildState.
Definition: autobuild.cpp:61
std::unordered_map< const BuildType *, std::vector< BuildStateUnit > > units
Definition: autobuild.h:64
bool hasTech(const BuildState &st, const BuildType *type)
Returns true if we have this tech in this BuildState.
Definition: autobuild.cpp:73
std::function< void()> builtCallback
Definition: autobuild.h:36
const BuildType * addon
Definition: autobuild.h:29
int countPlusProduction(const BuildState &st, const BuildType *type)
Returns the number of this BuildType this BuildState, either complete or in production.
Definition: autobuild.cpp:140
Definition: autobuild.h:33
virtual ~AutoBuildTask() override
Definition: autobuild.h:134
virtual void postBuild(autobuild::BuildState &st)
The final step of processing a build order.
Definition: autobuild.h:188
int n
Definition: autobuild.h:283
virtual ~DefaultAutoBuildTask() override
Definition: autobuild.h:296
Definition: autobuild.h:261
int countUnits(const BuildState &st, const BuildType *type)
Returns the number of completed units of this BuildType in this BuildState.
Definition: autobuild.cpp:85
AutoBuildTask(int upcId, State *state, Module *module)
Definition: autobuild.h:130
AutoBuildTasks are "build orders" in the colloquial sense.
Definition: autobuild.h:107
void save(Archive &ar, BuildStateUnit const &stu)
Definition: autobuild.cpp:1688
std::vector< std::pair< int, BuildEntry > > buildOrder
Definition: autobuild.h:67
virtual void preBuild(autobuild::BuildState &st)
One of the three steps of processing a build order.
Definition: autobuild.h:151
autobuild::BuildState currentBuildState
Definition: autobuild.h:116
Definition: autobuild.h:281
Position pos
Definition: autobuild.h:35
bool hasOrInProduction(const BuildState &st, const BuildType *type)
Returns true if we have this BuildType in this BuildState, either complete or in production.
Definition: autobuild.cpp:115
int countProduction(const BuildState &st, const BuildType *type)
Returns the number of this BuildType in production in this BuildState.
Definition: autobuild.cpp:131
Main namespace for bot-related code.
Definition: areainfo.cpp:17
virtual void buildStep(autobuild::BuildState &st) override
The meat of a build order lives in buildStep().
Definition: autobuild.h:298
std::unordered_set< const BuildType * > upgradesAndTech
Definition: autobuild.h:65
std::deque< std::pair< int, const BuildType * > > production
Definition: autobuild.h:66
autobuild::BuildState & lastEvaluateCurrentState()
Definition: autobuild.h:237
int framesUntil(const BuildState &st, const BuildType *type)
Returns how many frames before a type will be available Defaults to kForever if the type isn't comple...
Definition: autobuild.cpp:119
bool hasUpgrade(const BuildState &st, const BuildType *type)
Returns true if we have this upgrade in this BuildState.
Definition: autobuild.cpp:69
std::vector< Target > targets
Definition: autobuild.h:288
Interface for bot modules.
Definition: module.h:30
const BuildType * type
Definition: autobuild.h:34