#include "Creep.hpp" #include "ConstructionSite.hpp" #include "JSON.hpp" #include "RoomPosition.hpp" #include "Source.hpp" #include "Store.hpp" #include "StructureController.hpp" #include namespace Screeps { Creep::Creep(JS::Value creep) : RoomObject(std::move(creep)) { } std::vector Creep::body() const { std::vector list; for (const auto& part : JS::jsArrayToVector(value()["body"])) { Body body; if (!part["boost"].isUndefined()) body.boost = part["boost"].as(); body.type = part["type"].as(); body.hits = part["hits"].as(); list.push_back(std::move(body)); } return list; } int Creep::fatigue() const { return value()["fatigue"].as(); } int Creep::hits() const { return value()["hits"].as(); } int Creep::hitsMax() const { return value()["hitsMax"].as(); } std::string Creep::id() const { return value()["id"].as(); } JSON Creep::memory() const { return JS::toJSON(value()["memory"]); } void Creep::setMemory(const JSON& memory) { value().set("memory", JS::fromJSON(memory)); } bool Creep::my() const { return value()["my"].as(); } std::string Creep::name() const { return value()["name"].as(); } std::string Creep::owner() const { return value()["owner"]["username"].as(); } std::string Creep::saying() const { return value()["saying"].as(); } bool Creep::spawning() const { return value()["spawning"].as(); } Store Creep::store() const { return Store(value()["store"]); } int Creep::ticksToLive() const { return value()["ticksToLive"].as(); } int Creep::attack(const RoomObject& target) { return value().call("attack", target.value()); } int Creep::attackController(const StructureController& target) { return value().call("attackController", target.value()); } int Creep::build(const ConstructionSite& target) { return value().call("build", target.value()); } int Creep::cancelOrder(const std::string& methodName) { return value().call("cancelOrder", methodName); } int Creep::claimController(const StructureController& target) { return value().call("claimController", target.value()); } int Creep::dismantle(const Structure& target) { return value().call("dismantle", target.value()); } int Creep::drop(std::string resourceType, std::optional amount) { if (amount) return value().call("drop", resourceType, *amount); else return value().call("drop", resourceType); } int Creep::generateSafeMode(const StructureController& target) { return value().call("generateSafeMode", target); } int Creep::getActiveBodyParts(const std::string& type) { return value().call("getActiveBodyParts", type); } int Creep::harvest(const Source& target) { return value().call("harvest", target.value()); } int Creep::heal(const Creep& target) { return value().call("heal", target.value()); } int Creep::move(const Creep& direction) { return value().call("move", direction.value()); } int Creep::move(int direction) { return value().call("move", direction); } int Creep::moveTo(int x, int y, const std::optional& options) { if (options) return value().call("moveTo", x, y, JS::fromJSON(*options)); else return value().call("moveTo", x, y); } int Creep::moveTo(const RoomPosition& target, const std::optional& options) { if (options) return value().call("moveTo", target.value(), JS::fromJSON(*options)); else return value().call("moveTo", target.value()); } int Creep::moveTo(const RoomObject& target, const std::optional& options) { if (options) return value().call("moveTo", target.value(), JS::fromJSON(*options)); else return value().call("moveTo", target.value()); } int Creep::notifyWhenAttacked(bool enabled) { return value().call("notifyWhenAttacked", enabled); } int Creep::pickup(const Resource& target) { return value().call("pickup", target.value()); } int Creep::pull(const Creep& target) { return value().call("pull", target.value()); } int Creep::rangedAttack(const Creep& target) { return value().call("rangedAttack", target.value()); } int Creep::rangedAttack(const Structure& target) { return value().call("rangedAttack", target.value()); } int Creep::rangedHeal(const Creep& target) { return value().call("rangedHeal", target.value()); } int Creep::rangedMassAttack() { return value().call("rangedMassAttack"); } int Creep::repair(const Structure& target) { return value().call("repair", target.value()); } int Creep::reserveController(const StructureController& target) { return value().call("reserveController", target.value()); } int Creep::say(const std::string& message, bool visibleToAll) { return value().call("say", message, visibleToAll); } int Creep::signController(const StructureController& target, const std::string& text) { return value().call("signController", target.value(), text); } int Creep::suicide() { return value().call("suicide"); } int Creep::transfer(const Creep& target, std::string resourceType, std::optional amount) { if (amount) return value().call("transfer", target.value(), resourceType, *amount); else return value().call("transfer", target.value(), resourceType); } int Creep::transfer(const Structure& target, std::string resourceType, std::optional amount) { if (amount) return value().call("transfer", target.value(), resourceType, *amount); else return value().call("transfer", target.value(), resourceType); } int Creep::upgradeController(const StructureController& target) { return value().call("upgradeController", target.value()); } int Creep::withdraw(const RoomObject& target, std::string resourceType, std::optional amount) { if (amount) return value().call("withdraw", target.value(), resourceType, *amount); else return value().call("withdraw", target.value(), resourceType); } } // namespace Screeps