12 : carryCapacity_(carryCapacity), gatherRatePerTick_(gatherRatePerTick),
13 travelTicks_(travelTicks) {
20 if (
node == node_)
return true;
25 if (
node ==
nullptr || !
node->tryOccupySlot()) {
30 type_ =
node->resourceType();
44 if (node_ ==
nullptr) {
55 const int freeSpace = carryCapacity_ - cargo_;
56 const int take = std::min({freeSpace, node_->
amount(), gatherRatePerTick_});
57 if (take > 0) cargo_ += node_->
extract(take);
58 if (cargo_ >= carryCapacity_ || node_->
depleted()) startMoveToDrop();
79 return "moving_to_node";
83 return "moving_to_drop";
100void Collector::startMoveToNode() {
102 travelRemaining_ = travelTicks_;
105void Collector::startMoveToDrop() {
107 travelRemaining_ = travelTicks_;
110void Collector::deposit(
int player) {
EVEngine assertion entry point, backed by zeroerr.
#define EV_PARAM_CHECK(cond,...)
Validate a function parameter / public API precondition.
void tick(int player)
推进一个 tick;卸货时入账到指定玩家的账本。
int carryCapacity() const
单次最大携带量。
bool assign(GatherNode *node)
指派目标节点并占用其采集槽位;无空位时保持待命并返回 false。
std::string resourceType() const
正在采集的资源类型 id。
Collector(int carryCapacity, int gatherRatePerTick, int travelTicks)
int totalGathered() const
累计入账量(不含浪费)。
int trips() const
完成的往返次数。
void clearAssignment()
取消指派并释放槽位。
std::string stateName() const
当前相位的字符串名(脚本友好)。
bool isIdle() const
是否处于待命状态。
static int credit(int player, const std::string &type, int amount)
入账并广播事件。
int extract(int amount)
尝试取出 amount;返回实际取出量(不超过当前储量)。
void releaseSlot()
释放一个采集槽位。
bool depleted() const
是否已采空。