84 template <
typename... Args>
95 auto sourceId =
units_[unit];
102 std::piecewise_construct,
103 std::forward_as_tuple(unit),
104 std::forward_as_tuple(sourceId, std::move(upc)));
110 std::unordered_map<Unit*, std::pair<UpcId, std::shared_ptr<UPCTuple>>>
upcs_;
171 virtual bool didFail()
const;
174 void setUpcId(
UpcId id);
225 template <
typename T>
229 std::string name = std::string()) {
230 auto board = state->
board();
231 auto key = std::string(
"controller_") + module->
name() +
"/" + name;
233 board->get<std::shared_ptr<SharedController>>(key,
nullptr);
234 if (controller ==
nullptr) {
235 controller = std::make_shared<T>(module);
236 board->post(key, controller);
238 return std::dynamic_pointer_cast<T>(controller);
251 std::unordered_set<Unit*> units,
253 std::shared_ptr<Controller> controller);
256 virtual void update(
State* state)
override;
257 virtual void cancel(
State* state)
override;
259 std::shared_ptr<Controller> controller()
const;
260 virtual const char*
getName()
const override {
261 return controller()->getName();
282 std::unordered_set<Unit*> units,
284 std::shared_ptr<SharedController> controller);
287 virtual void update(
State* state)
override;
288 virtual void cancel(
State* state)
override;
290 std::shared_ptr<SharedController> controller()
const;
Game state.
Definition: state.h:42
virtual void addUnit(State *state, Unit *unit, UpcId id)
Add a unit to this controller.
Definition: controller.cpp:18
virtual bool didSucceed() const
Implement this to return whether your custom Controller did succeed in its mission (if applicable) an...
Definition: controller.h:164
void postUpcs(State *state)
Posts scheduled UPCs to the Blackboard.
Definition: controller.cpp:56
The primary way for modules to publish their activity.
Definition: task.h:50
virtual void step(State *state)
Advance controller state and produce UPCs.
Definition: controller.cpp:54
ControllerBase(Module *module)
Definition: controller.cpp:16
std::string name()
Definition: module.cpp:41
virtual bool keepUnit(State *state, Unit *unit) const
Decide whether to keep a unit.
Definition: controller.cpp:42
virtual const char * getName() const
A name for this Controller, for debugging purposes.
Definition: controller.h:73
Represents a unit in the game.
Definition: unitsinfo.h:35
std::unordered_map< Unit *, std::pair< UpcId, std::shared_ptr< UPCTuple > > > upcs_
Definition: controller.h:110
static std::shared_ptr< T > globalInstance(State *state, Module *module, std::string name=std::string())
Retrieves the global instance of a shared controller.
Definition: controller.h:226
bool isControllingUnitWith(Unit *unit, UpcId id) const
Checks if the controller is controlling the given unit via the given UPC ID.
Definition: controller.cpp:65
virtual ~ControllerBase()=default
Generic Task for SharedController.
Definition: controller.h:278
std::unordered_map< Unit *, UpcId > units_
Definition: controller.h:109
Generic Task for Controller.
Definition: controller.h:247
std::shared_ptr< SharedController > controller_
Definition: controller.h:293
Blackboard * board() const
Definition: state.h:99
Base class for single-task controllers.
Definition: controller.h:156
std::string unitString(Unit const *unit)
Definition: debugging.h:65
auto makeSharpUPC(Unit *u, Command c)
Definition: upcs.h:17
virtual const char * getName() const override
A name for this task, for debugging purposes.
Definition: controller.h:260
UpcId upcId_
Definition: controller.h:177
Main namespace for bot-related code.
Definition: areainfo.cpp:17
Base class for controllers.
Definition: controller.h:35
virtual void removeUnit(State *state, Unit *unit, UpcId id)
Remove a unit from this controller.
Definition: controller.cpp:22
int UpcId
Definition: basetypes.h:23
std::shared_ptr< Controller > controller_
Definition: controller.h:262
Interface for bot modules.
Definition: module.h:30
void addUpc(Unit *unit, Args &&...args)
Schedules an action (as a UPC) for the given unit which will be posted after doStep().
Definition: controller.h:85
Base class for Controllers shared between multiple tasks.
Definition: controller.h:216
UpcId constexpr kInvalidUpcId
Definition: basetypes.h:25
Module * module_
Definition: controller.h:108