mirror of
https://github.com/UltraCoderRU/screepsxx.git
synced 2026-01-28 01:55:12 +00:00
Add Deposit, Flag, Resource, StructureExtractor, StructureLink classes.
Completed StructureController, StructureExtension, StructureRampart, StructureRoad, StructureSpawn classes.
This commit is contained in:
parent
5dacd83b0f
commit
3fad4634e9
28 changed files with 624 additions and 43 deletions
|
|
@ -9,6 +9,7 @@
|
||||||
namespace Screeps {
|
namespace Screeps {
|
||||||
|
|
||||||
class ConstructionSite;
|
class ConstructionSite;
|
||||||
|
class Resource;
|
||||||
class Source;
|
class Source;
|
||||||
class Store;
|
class Store;
|
||||||
class Structure;
|
class Structure;
|
||||||
|
|
@ -53,7 +54,7 @@ public:
|
||||||
|
|
||||||
int ticksToLive() const;
|
int ticksToLive() const;
|
||||||
|
|
||||||
int attack(const Object& target);
|
int attack(const RoomObject& target);
|
||||||
|
|
||||||
int attackController(const StructureController& target);
|
int attackController(const StructureController& target);
|
||||||
|
|
||||||
|
|
@ -86,7 +87,7 @@ public:
|
||||||
|
|
||||||
int notifyWhenAttacked(bool enabled);
|
int notifyWhenAttacked(bool enabled);
|
||||||
|
|
||||||
// int pickup(const Resource& target);
|
int pickup(const Resource& target);
|
||||||
|
|
||||||
int pull(const Creep& target);
|
int pull(const Creep& target);
|
||||||
|
|
||||||
|
|
|
||||||
26
include/Screeps/Deposit.hpp
Normal file
26
include/Screeps/Deposit.hpp
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
#ifndef SCREEPS_DEPOSIT_HPP
|
||||||
|
#define SCREEPS_DEPOSIT_HPP
|
||||||
|
|
||||||
|
#include "RoomObject.hpp"
|
||||||
|
|
||||||
|
namespace Screeps {
|
||||||
|
|
||||||
|
class Deposit : public RoomObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit Deposit(JS::Value value);
|
||||||
|
|
||||||
|
int cooldown() const;
|
||||||
|
|
||||||
|
std::string depositType() const;
|
||||||
|
|
||||||
|
std::string id() const;
|
||||||
|
|
||||||
|
int lastCooldown() const;
|
||||||
|
|
||||||
|
int ticksToDecay() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Screeps
|
||||||
|
|
||||||
|
#endif // SCREEPS_DEPOSIT_HPP
|
||||||
33
include/Screeps/Flag.hpp
Normal file
33
include/Screeps/Flag.hpp
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
#ifndef SCREEPS_FLAG_HPP
|
||||||
|
#define SCREEPS_FLAG_HPP
|
||||||
|
|
||||||
|
#include "RoomObject.hpp"
|
||||||
|
|
||||||
|
namespace Screeps {
|
||||||
|
|
||||||
|
class Flag : public RoomObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit Flag(JS::Value value);
|
||||||
|
|
||||||
|
int color() const;
|
||||||
|
|
||||||
|
JSON memory() const;
|
||||||
|
void setMemory(const JSON&);
|
||||||
|
|
||||||
|
std::string name() const;
|
||||||
|
|
||||||
|
int secondaryColor() const;
|
||||||
|
|
||||||
|
void remove();
|
||||||
|
|
||||||
|
int setColor(int color, std::optional<int> secondaryColor);
|
||||||
|
|
||||||
|
int setPosition(int x, int y);
|
||||||
|
int setPosition(const RoomPosition& pos);
|
||||||
|
int setPosition(const RoomObject& pos);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Screeps
|
||||||
|
|
||||||
|
#endif // SCREEPS_FLAG_HPP
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include <nlohmann/json_fwd.hpp>
|
#include <nlohmann/json_fwd.hpp>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using JSON = nlohmann::json;
|
using JSON = nlohmann::json;
|
||||||
|
|
@ -25,8 +26,30 @@ Value getConstant(const std::string& name);
|
||||||
|
|
||||||
bool isInstanceOf(const Value& val, const char* name);
|
bool isInstanceOf(const Value& val, const char* name);
|
||||||
|
|
||||||
std::vector<Value> jsArrayToVector(const Value& array);
|
template <typename T = Value>
|
||||||
std::map<std::string, Value> jsObjectToMap(const Value& object);
|
std::vector<T> jsArrayToVector(const Value& array)
|
||||||
|
{
|
||||||
|
std::vector<T> result;
|
||||||
|
int size = array["length"].as<int>();
|
||||||
|
result.reserve(size);
|
||||||
|
for (int i = 0; i < size; ++i)
|
||||||
|
result.emplace_back(array[i].as<T>());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T = Value>
|
||||||
|
std::map<std::string, T> jsObjectToMap(const Value& object)
|
||||||
|
{
|
||||||
|
std::map<std::string, T> result;
|
||||||
|
Value keys = gObject.call<Value>("keys", object);
|
||||||
|
int size = keys["length"].as<int>();
|
||||||
|
for (int i = 0; i < size; ++i)
|
||||||
|
{
|
||||||
|
auto key = keys[i].as<std::string>();
|
||||||
|
result.emplace_hint(result.end(), key, object[key].as<T>());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
Value vectorToJSArray(const std::vector<T>& vector)
|
Value vectorToJSArray(const std::vector<T>& vector)
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ namespace Screeps {
|
||||||
class Object
|
class Object
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
using Error = int;
|
||||||
|
|
||||||
JS::Value& value();
|
JS::Value& value();
|
||||||
const JS::Value& value() const;
|
const JS::Value& value() const;
|
||||||
void setValue(JS::Value value);
|
void setValue(JS::Value value);
|
||||||
|
|
|
||||||
22
include/Screeps/Resource.hpp
Normal file
22
include/Screeps/Resource.hpp
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef SCREEPS_RESOURCE_HPP
|
||||||
|
#define SCREEPS_RESOURCE_HPP
|
||||||
|
|
||||||
|
#include "RoomObject.hpp"
|
||||||
|
|
||||||
|
namespace Screeps {
|
||||||
|
|
||||||
|
class Resource : public RoomObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit Resource(JS::Value value);
|
||||||
|
|
||||||
|
int amount() const;
|
||||||
|
|
||||||
|
std::string id() const;
|
||||||
|
|
||||||
|
std::string resourceType() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Screeps
|
||||||
|
|
||||||
|
#endif // SCREEPS_RESOURCE_HPP
|
||||||
|
|
@ -12,7 +12,7 @@ class Room;
|
||||||
class RoomObject : public Object
|
class RoomObject : public Object
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RoomObject(JS::Value value);
|
explicit RoomObject(JS::Value value);
|
||||||
|
|
||||||
virtual ~RoomObject();
|
virtual ~RoomObject();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#include "Object.hpp"
|
#include "Object.hpp"
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace Screeps {
|
namespace Screeps {
|
||||||
|
|
||||||
class Store : public Object
|
class Store : public Object
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,55 @@
|
||||||
|
|
||||||
#include "OwnedStructure.hpp"
|
#include "OwnedStructure.hpp"
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace Screeps {
|
namespace Screeps {
|
||||||
|
|
||||||
class StructureController : public OwnedStructure
|
class StructureController : public OwnedStructure
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
struct Reservation
|
||||||
|
{
|
||||||
|
std::string username;
|
||||||
|
int ticksToEnd;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Sign
|
||||||
|
{
|
||||||
|
std::string username;
|
||||||
|
std::string text;
|
||||||
|
int time;
|
||||||
|
std::int64_t datetime; // ms since epoch (UTC)
|
||||||
|
};
|
||||||
|
|
||||||
explicit StructureController(JS::Value value);
|
explicit StructureController(JS::Value value);
|
||||||
|
|
||||||
|
bool isPowerEnabled() const;
|
||||||
|
|
||||||
|
int level() const;
|
||||||
|
|
||||||
|
int progress() const;
|
||||||
|
|
||||||
|
int progressTotal() const;
|
||||||
|
|
||||||
|
std::optional<Reservation> reservation() const;
|
||||||
|
|
||||||
|
std::optional<int> safeMode() const;
|
||||||
|
|
||||||
|
int safeModeAvailable() const;
|
||||||
|
|
||||||
|
std::optional<int> safeModeCooldown() const;
|
||||||
|
|
||||||
|
std::optional<Sign> sign() const;
|
||||||
|
|
||||||
|
int ticksToDowngrade() const;
|
||||||
|
|
||||||
|
int upgradeBlocked() const;
|
||||||
|
|
||||||
|
int activateSafeMode();
|
||||||
|
|
||||||
|
int unclaim();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Screeps
|
} // namespace Screeps
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,14 @@
|
||||||
|
|
||||||
namespace Screeps {
|
namespace Screeps {
|
||||||
|
|
||||||
|
class Store;
|
||||||
|
|
||||||
class StructureExtension : public Structure
|
class StructureExtension : public Structure
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit StructureExtension(JS::Value value);
|
explicit StructureExtension(JS::Value value);
|
||||||
|
|
||||||
|
Store store() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Screeps
|
} // namespace Screeps
|
||||||
|
|
|
||||||
18
include/Screeps/StructureExtractor.hpp
Normal file
18
include/Screeps/StructureExtractor.hpp
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
#ifndef SCREEPS_STRUCTURE_EXTRACTOR_HPP
|
||||||
|
#define SCREEPS_STRUCTURE_EXTRACTOR_HPP
|
||||||
|
|
||||||
|
#include "OwnedStructure.hpp"
|
||||||
|
|
||||||
|
namespace Screeps {
|
||||||
|
|
||||||
|
class StructureExtractor : public OwnedStructure
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit StructureExtractor(JS::Value value);
|
||||||
|
|
||||||
|
int cooldown() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Screeps
|
||||||
|
|
||||||
|
#endif // SCREEPS_STRUCTURE_EXTRACTOR_HPP
|
||||||
24
include/Screeps/StructureLink.hpp
Normal file
24
include/Screeps/StructureLink.hpp
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
#ifndef SCREEPS_STRUCTURE_LINK_HPP
|
||||||
|
#define SCREEPS_STRUCTURE_LINK_HPP
|
||||||
|
|
||||||
|
#include "OwnedStructure.hpp"
|
||||||
|
|
||||||
|
namespace Screeps {
|
||||||
|
|
||||||
|
class Store;
|
||||||
|
|
||||||
|
class StructureLink : public OwnedStructure
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit StructureLink(JS::Value value);
|
||||||
|
|
||||||
|
int cooldown() const;
|
||||||
|
|
||||||
|
Store store() const;
|
||||||
|
|
||||||
|
int transferEnergy(const StructureLink& target, std::optional<int> amount = std::nullopt);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Screeps
|
||||||
|
|
||||||
|
#endif // SCREEPS_STRUCTURE_LINK_HPP
|
||||||
|
|
@ -9,6 +9,12 @@ class StructureRampart : public Structure
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit StructureRampart(JS::Value value);
|
explicit StructureRampart(JS::Value value);
|
||||||
|
|
||||||
|
bool isPublic() const;
|
||||||
|
|
||||||
|
int ticksToDecay() const;
|
||||||
|
|
||||||
|
int setPublic(bool isPublic);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Screeps
|
} // namespace Screeps
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ class StructureRoad : public Structure
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit StructureRoad(JS::Value value);
|
explicit StructureRoad(JS::Value value);
|
||||||
|
|
||||||
|
int ticksToDecay() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Screeps
|
} // namespace Screeps
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,59 @@
|
||||||
#ifndef SPAWN_HPP
|
#ifndef SCREEPS_STRUCTURE_SPAWN_HPP
|
||||||
#define SPAWN_HPP
|
#define SCREEPS_STRUCTURE_SPAWN_HPP
|
||||||
|
|
||||||
#include "OwnedStructure.hpp"
|
#include "OwnedStructure.hpp"
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace Screeps {
|
namespace Screeps {
|
||||||
|
|
||||||
|
class Creep;
|
||||||
class Store;
|
class Store;
|
||||||
|
|
||||||
class StructureSpawn : public OwnedStructure
|
class StructureSpawn : public OwnedStructure
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
class Spawning;
|
||||||
|
|
||||||
explicit StructureSpawn(JS::Value obj);
|
explicit StructureSpawn(JS::Value obj);
|
||||||
|
|
||||||
Store store() const;
|
JSON memory() const;
|
||||||
|
void setMemory(const JSON&);
|
||||||
|
|
||||||
std::string name() const;
|
std::string name() const;
|
||||||
|
|
||||||
|
std::optional<Spawning> spawning() const;
|
||||||
|
|
||||||
|
Store store() const;
|
||||||
|
|
||||||
int spawnCreep(const std::vector<std::string>& body, const std::string& name);
|
int spawnCreep(const std::vector<std::string>& body, const std::string& name);
|
||||||
int spawnCreep(const std::vector<std::string>& body, const std::string& name, const JSON& options);
|
int spawnCreep(const std::vector<std::string>& body, const std::string& name, const JSON& options);
|
||||||
|
|
||||||
|
int recycleCreep(const Creep& target);
|
||||||
|
|
||||||
|
int renewCreep(const Creep& target);
|
||||||
|
};
|
||||||
|
|
||||||
|
class StructureSpawn::Spawning : public Object
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit Spawning(JS::Value value);
|
||||||
|
|
||||||
|
std::vector<int> directions() const;
|
||||||
|
|
||||||
|
std::string name() const;
|
||||||
|
|
||||||
|
int needTime() const;
|
||||||
|
|
||||||
|
int remainingTime() const;
|
||||||
|
|
||||||
|
StructureSpawn spawn();
|
||||||
|
|
||||||
|
int cancel();
|
||||||
|
|
||||||
|
int setDirections(std::vector<int> directions);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Screeps
|
} // namespace Screeps
|
||||||
|
|
||||||
#endif // SPAWN_HPP
|
#endif // SCREEPS_STRUCTURE_SPAWN_HPP
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@
|
||||||
#include "Store.hpp"
|
#include "Store.hpp"
|
||||||
#include "StructureController.hpp"
|
#include "StructureController.hpp"
|
||||||
|
|
||||||
|
#include <Resource.hpp>
|
||||||
|
|
||||||
namespace Screeps {
|
namespace Screeps {
|
||||||
|
|
||||||
Creep::Creep(JS::Value creep) : RoomObject(std::move(creep))
|
Creep::Creep(JS::Value creep) : RoomObject(std::move(creep))
|
||||||
|
|
@ -93,7 +95,7 @@ int Creep::ticksToLive() const
|
||||||
return value()["ticksToLive"].as<int>();
|
return value()["ticksToLive"].as<int>();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Creep::attack(const Object& target)
|
int Creep::attack(const RoomObject& target)
|
||||||
{
|
{
|
||||||
return value().call<int>("attack", target.value());
|
return value().call<int>("attack", target.value());
|
||||||
}
|
}
|
||||||
|
|
@ -190,6 +192,11 @@ int Creep::notifyWhenAttacked(bool enabled)
|
||||||
return value().call<int>("notifyWhenAttacked", enabled);
|
return value().call<int>("notifyWhenAttacked", enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Creep::pickup(const Resource& target)
|
||||||
|
{
|
||||||
|
return value().call<int>("pickup", target.value());
|
||||||
|
}
|
||||||
|
|
||||||
int Creep::pull(const Creep& target)
|
int Creep::pull(const Creep& target)
|
||||||
{
|
{
|
||||||
return value().call<int>("pull", target.value());
|
return value().call<int>("pull", target.value());
|
||||||
|
|
|
||||||
34
src/Deposit.cpp
Normal file
34
src/Deposit.cpp
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
#include "Deposit.hpp"
|
||||||
|
|
||||||
|
namespace Screeps {
|
||||||
|
|
||||||
|
Deposit::Deposit(JS::Value value) : RoomObject(std::move(value))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int Deposit::cooldown() const
|
||||||
|
{
|
||||||
|
return value()["cooldown"].as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Deposit::depositType() const
|
||||||
|
{
|
||||||
|
return value()["depositType"].as<std::string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Deposit::id() const
|
||||||
|
{
|
||||||
|
return value()["id"].as<std::string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
int Deposit::lastCooldown() const
|
||||||
|
{
|
||||||
|
return value()["lastCooldown"].as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
int Deposit::ticksToDecay() const
|
||||||
|
{
|
||||||
|
return value()["ticksToDecay"].as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Screeps
|
||||||
65
src/Flag.cpp
Normal file
65
src/Flag.cpp
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
#include "Flag.hpp"
|
||||||
|
|
||||||
|
#include "JSON.hpp"
|
||||||
|
#include "RoomPosition.hpp"
|
||||||
|
|
||||||
|
namespace Screeps {
|
||||||
|
|
||||||
|
Flag::Flag(JS::Value value) : RoomObject(std::move(value))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int Flag::color() const
|
||||||
|
{
|
||||||
|
return value()["color"].as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
JSON Flag::memory() const
|
||||||
|
{
|
||||||
|
return JS::toJSON(value()["memory"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Flag::setMemory(const JSON& memory)
|
||||||
|
{
|
||||||
|
value().set("memory", JS::fromJSON(memory));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Flag::name() const
|
||||||
|
{
|
||||||
|
return value()["name"].as<std::string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
int Flag::secondaryColor() const
|
||||||
|
{
|
||||||
|
return value()["secondaryColor"].as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Flag::remove()
|
||||||
|
{
|
||||||
|
value().call<void>("remove");
|
||||||
|
}
|
||||||
|
|
||||||
|
int Flag::setColor(int color, std::optional<int> secondaryColor)
|
||||||
|
{
|
||||||
|
if (secondaryColor)
|
||||||
|
return value().call<int>("setColor", color, *secondaryColor);
|
||||||
|
else
|
||||||
|
return value().call<int>("setColor", color);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Flag::setPosition(int x, int y)
|
||||||
|
{
|
||||||
|
return value().call<int>("setPosition", x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Flag::setPosition(const RoomPosition& pos)
|
||||||
|
{
|
||||||
|
return value().call<int>("setPosition", pos.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
int Flag::setPosition(const RoomObject& pos)
|
||||||
|
{
|
||||||
|
return value().call<int>("setPosition", pos.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Screeps
|
||||||
33
src/JS.cpp
33
src/JS.cpp
|
|
@ -2,10 +2,6 @@
|
||||||
|
|
||||||
#include "JSON.hpp"
|
#include "JSON.hpp"
|
||||||
|
|
||||||
#include <emscripten/bind.h>
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace JS {
|
namespace JS {
|
||||||
|
|
||||||
Value getGlobal(char const* name)
|
Value getGlobal(char const* name)
|
||||||
|
|
@ -28,35 +24,6 @@ bool isInstanceOf(const Value& value, const char* name)
|
||||||
return value.instanceof (JS::Value::global(name));
|
return value.instanceof (JS::Value::global(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Value> jsArrayToVector(const Value& array)
|
|
||||||
{
|
|
||||||
std::vector<Value> result;
|
|
||||||
|
|
||||||
int size = array["length"].as<int>();
|
|
||||||
result.reserve(size);
|
|
||||||
|
|
||||||
for (int i = 0; i < size; ++i)
|
|
||||||
result.emplace_back(array[i]);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::map<std::string, Value> jsObjectToMap(const Value& object)
|
|
||||||
{
|
|
||||||
std::map<std::string, Value> result;
|
|
||||||
|
|
||||||
Value keys = gObject.call<Value>("keys", object);
|
|
||||||
int size = keys["length"].as<int>();
|
|
||||||
|
|
||||||
for (int i = 0; i < size; ++i)
|
|
||||||
{
|
|
||||||
auto key = keys[i].as<std::string>();
|
|
||||||
result.emplace_hint(result.end(), key, object[key]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Value fromJSONArray(const JSON& array)
|
Value fromJSONArray(const JSON& array)
|
||||||
{
|
{
|
||||||
Value value = Value::array();
|
Value value = Value::array();
|
||||||
|
|
|
||||||
24
src/Resource.cpp
Normal file
24
src/Resource.cpp
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
#include "Resource.hpp"
|
||||||
|
|
||||||
|
namespace Screeps {
|
||||||
|
|
||||||
|
Resource::Resource(JS::Value value) : RoomObject(std::move(value))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int Resource::amount() const
|
||||||
|
{
|
||||||
|
return value()["amount"].as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Resource::id() const
|
||||||
|
{
|
||||||
|
return value()["id"].as<std::string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Resource::resourceType() const
|
||||||
|
{
|
||||||
|
return value()["resourceType"].as<std::string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Screeps
|
||||||
|
|
@ -2,7 +2,10 @@
|
||||||
|
|
||||||
#include "ConstructionSite.hpp"
|
#include "ConstructionSite.hpp"
|
||||||
#include "Creep.hpp"
|
#include "Creep.hpp"
|
||||||
|
#include "Deposit.hpp"
|
||||||
#include "Effect.hpp"
|
#include "Effect.hpp"
|
||||||
|
#include "Flag.hpp"
|
||||||
|
#include "Resource.hpp"
|
||||||
#include "Room.hpp"
|
#include "Room.hpp"
|
||||||
#include "RoomPosition.hpp"
|
#include "RoomPosition.hpp"
|
||||||
#include "Ruin.hpp"
|
#include "Ruin.hpp"
|
||||||
|
|
@ -10,6 +13,8 @@
|
||||||
#include "StructureContainer.hpp"
|
#include "StructureContainer.hpp"
|
||||||
#include "StructureController.hpp"
|
#include "StructureController.hpp"
|
||||||
#include "StructureExtension.hpp"
|
#include "StructureExtension.hpp"
|
||||||
|
#include "StructureExtractor.hpp"
|
||||||
|
#include "StructureLink.hpp"
|
||||||
#include "StructureRampart.hpp"
|
#include "StructureRampart.hpp"
|
||||||
#include "StructureRoad.hpp"
|
#include "StructureRoad.hpp"
|
||||||
#include "StructureSpawn.hpp"
|
#include "StructureSpawn.hpp"
|
||||||
|
|
@ -76,6 +81,8 @@ std::unique_ptr<RoomObject> createRoomObject(JS::Value object)
|
||||||
return std::make_unique<ConstructionSite>(std::move(object));
|
return std::make_unique<ConstructionSite>(std::move(object));
|
||||||
else if (is("StructureTower"))
|
else if (is("StructureTower"))
|
||||||
return std::make_unique<StructureTower>(std::move(object));
|
return std::make_unique<StructureTower>(std::move(object));
|
||||||
|
else if (is("StructureLink"))
|
||||||
|
return std::make_unique<StructureLink>(std::move(object));
|
||||||
else if (is("StructureSpawn"))
|
else if (is("StructureSpawn"))
|
||||||
return std::make_unique<StructureSpawn>(std::move(object));
|
return std::make_unique<StructureSpawn>(std::move(object));
|
||||||
else if (is("Ruin"))
|
else if (is("Ruin"))
|
||||||
|
|
@ -84,6 +91,14 @@ std::unique_ptr<RoomObject> createRoomObject(JS::Value object)
|
||||||
return std::make_unique<StructureController>(std::move(object));
|
return std::make_unique<StructureController>(std::move(object));
|
||||||
else if (is("StructureStorage"))
|
else if (is("StructureStorage"))
|
||||||
return std::make_unique<StructureStorage>(std::move(object));
|
return std::make_unique<StructureStorage>(std::move(object));
|
||||||
|
else if (is("StructureExtractor"))
|
||||||
|
return std::make_unique<StructureExtractor>(std::move(object));
|
||||||
|
else if (is("Deposit"))
|
||||||
|
return std::make_unique<Deposit>(std::move(object));
|
||||||
|
else if (is("Flag"))
|
||||||
|
return std::make_unique<Flag>(std::move(object));
|
||||||
|
else if (is("Resource"))
|
||||||
|
return std::make_unique<Resource>(std::move(object));
|
||||||
else
|
else
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,4 +6,95 @@ StructureController::StructureController(JS::Value value) : OwnedStructure(std::
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool StructureController::isPowerEnabled() const
|
||||||
|
{
|
||||||
|
return value()["isPowerEnabled"].as<bool>();
|
||||||
|
}
|
||||||
|
|
||||||
|
int StructureController::level() const
|
||||||
|
{
|
||||||
|
return value()["level"].as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
int StructureController::progress() const
|
||||||
|
{
|
||||||
|
return value()["progress"].as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
int StructureController::progressTotal() const
|
||||||
|
{
|
||||||
|
return value()["progressTotal"].as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<StructureController::Reservation> StructureController::reservation() const
|
||||||
|
{
|
||||||
|
auto obj = value()["reservation"];
|
||||||
|
if (obj.isUndefined())
|
||||||
|
return std::nullopt;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Reservation result;
|
||||||
|
result.username = obj["username"].as<std::string>();
|
||||||
|
result.ticksToEnd = obj["ticksToEnd"].as<int>();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<int> StructureController::safeMode() const
|
||||||
|
{
|
||||||
|
auto result = value()["safeMode"];
|
||||||
|
if (result.isUndefined())
|
||||||
|
return std::nullopt;
|
||||||
|
return result.as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
int StructureController::safeModeAvailable() const
|
||||||
|
{
|
||||||
|
return value()["safeModeAvailable"].as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<int> StructureController::safeModeCooldown() const
|
||||||
|
{
|
||||||
|
auto result = value()["safeModeCooldown"];
|
||||||
|
if (result.isUndefined())
|
||||||
|
return std::nullopt;
|
||||||
|
return result.as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<StructureController::Sign> StructureController::sign() const
|
||||||
|
{
|
||||||
|
auto obj = value()["sign"];
|
||||||
|
if (obj.isUndefined())
|
||||||
|
return std::nullopt;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Sign result;
|
||||||
|
result.username = obj["username"].as<std::string>();
|
||||||
|
result.text = obj["text"].as<std::string>();
|
||||||
|
result.time = obj["time"].as<int>();
|
||||||
|
result.datetime = obj["datetime"].call<double>("valueOf");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int StructureController::ticksToDowngrade() const
|
||||||
|
{
|
||||||
|
return value()["ticksToDowngrade"].as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
int StructureController::upgradeBlocked() const
|
||||||
|
{
|
||||||
|
return value()["upgradeBlocked"].as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
int StructureController::activateSafeMode()
|
||||||
|
{
|
||||||
|
return value().call<int>("activateSafeMode");
|
||||||
|
}
|
||||||
|
|
||||||
|
int StructureController::unclaim()
|
||||||
|
{
|
||||||
|
return value().call<int>("unclaim");
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Screeps
|
} // namespace Screeps
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,16 @@
|
||||||
#include "StructureExtension.hpp"
|
#include "StructureExtension.hpp"
|
||||||
|
|
||||||
|
#include "Store.hpp"
|
||||||
|
|
||||||
namespace Screeps {
|
namespace Screeps {
|
||||||
|
|
||||||
StructureExtension::StructureExtension(JS::Value value) : Structure(std::move(value))
|
StructureExtension::StructureExtension(JS::Value value) : Structure(std::move(value))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Store StructureExtension::store() const
|
||||||
|
{
|
||||||
|
return Store(value()["store"]);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Screeps
|
} // namespace Screeps
|
||||||
|
|
|
||||||
14
src/StructureExtractor.cpp
Normal file
14
src/StructureExtractor.cpp
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#include "StructureExtractor.hpp"
|
||||||
|
|
||||||
|
namespace Screeps {
|
||||||
|
|
||||||
|
StructureExtractor::StructureExtractor(JS::Value value) : OwnedStructure(std::move(value))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int StructureExtractor::cooldown() const
|
||||||
|
{
|
||||||
|
return value()["cooldown"].as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Screeps
|
||||||
29
src/StructureLink.cpp
Normal file
29
src/StructureLink.cpp
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
#include "StructureLink.hpp"
|
||||||
|
|
||||||
|
#include "Store.hpp"
|
||||||
|
|
||||||
|
namespace Screeps {
|
||||||
|
|
||||||
|
StructureLink::StructureLink(JS::Value value) : OwnedStructure(std::move(value))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int StructureLink::cooldown() const
|
||||||
|
{
|
||||||
|
return value()["cooldown"].as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
Store StructureLink::store() const
|
||||||
|
{
|
||||||
|
return Store(value()["store"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int StructureLink::transferEnergy(const StructureLink& target, std::optional<int> amount)
|
||||||
|
{
|
||||||
|
if (amount)
|
||||||
|
return value().call<int>("transferEnergy", target.value(), *amount);
|
||||||
|
else
|
||||||
|
return value().call<int>("transferEnergy", target.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Screeps
|
||||||
|
|
@ -6,4 +6,19 @@ StructureRampart::StructureRampart(JS::Value value) : Structure(std::move(value)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool StructureRampart::isPublic() const
|
||||||
|
{
|
||||||
|
return value()["isPublic"].as<bool>();
|
||||||
|
}
|
||||||
|
|
||||||
|
int StructureRampart::ticksToDecay() const
|
||||||
|
{
|
||||||
|
return value()["ticksToDecay"].as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
int StructureRampart::setPublic(bool isPublic)
|
||||||
|
{
|
||||||
|
return value().call<int>("setPublic", isPublic);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Screeps
|
} // namespace Screeps
|
||||||
|
|
|
||||||
|
|
@ -6,4 +6,9 @@ StructureRoad::StructureRoad(JS::Value value) : Structure(std::move(value))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int StructureRoad::ticksToDecay() const
|
||||||
|
{
|
||||||
|
return value()["ticksToDecay"].as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Screeps
|
} // namespace Screeps
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#include "StructureSpawn.hpp"
|
#include "StructureSpawn.hpp"
|
||||||
|
|
||||||
|
#include "Creep.hpp"
|
||||||
#include "JSON.hpp"
|
#include "JSON.hpp"
|
||||||
#include "Store.hpp"
|
#include "Store.hpp"
|
||||||
|
|
||||||
|
|
@ -9,6 +10,25 @@ StructureSpawn::StructureSpawn(JS::Value obj) : OwnedStructure(std::move(obj))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JSON StructureSpawn::memory() const
|
||||||
|
{
|
||||||
|
return JS::toJSON(value()["memory"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StructureSpawn::setMemory(const JSON& memory)
|
||||||
|
{
|
||||||
|
value().set("memory", JS::fromJSON(memory));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<StructureSpawn::Spawning> StructureSpawn::spawning() const
|
||||||
|
{
|
||||||
|
auto obj = value()["spawning"];
|
||||||
|
if (obj.isUndefined())
|
||||||
|
return std::nullopt;
|
||||||
|
else
|
||||||
|
return Spawning(std::move(obj));
|
||||||
|
}
|
||||||
|
|
||||||
Store StructureSpawn::store() const
|
Store StructureSpawn::store() const
|
||||||
{
|
{
|
||||||
return Store(value()["store"]);
|
return Store(value()["store"]);
|
||||||
|
|
@ -35,4 +55,53 @@ int StructureSpawn::spawnCreep(const std::vector<std::string>& body,
|
||||||
return value().call<int>("spawnCreep", JS::vectorToJSArray(body), name, JS::fromJSON(options));
|
return value().call<int>("spawnCreep", JS::vectorToJSArray(body), name, JS::fromJSON(options));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int StructureSpawn::recycleCreep(const Creep& target)
|
||||||
|
{
|
||||||
|
return value().call<int>("recycleCreep", target.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
int StructureSpawn::renewCreep(const Creep& target)
|
||||||
|
{
|
||||||
|
return value().call<int>("renewCreep", target.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
StructureSpawn::Spawning::Spawning(JS::Value value) : Object(std::move(value))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<int> StructureSpawn::Spawning::directions() const
|
||||||
|
{
|
||||||
|
return JS::jsArrayToVector<int>(value()["directions"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string StructureSpawn::Spawning::name() const
|
||||||
|
{
|
||||||
|
return value()["name"].as<std::string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
int StructureSpawn::Spawning::needTime() const
|
||||||
|
{
|
||||||
|
return value()["needTime"].as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
int StructureSpawn::Spawning::remainingTime() const
|
||||||
|
{
|
||||||
|
return value()["remainingTime"].as<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
StructureSpawn StructureSpawn::Spawning::spawn()
|
||||||
|
{
|
||||||
|
return StructureSpawn(value()["spawn"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int StructureSpawn::Spawning::cancel()
|
||||||
|
{
|
||||||
|
return value().call<int>("cancel");
|
||||||
|
}
|
||||||
|
|
||||||
|
int StructureSpawn::Spawning::setDirections(std::vector<int> directions)
|
||||||
|
{
|
||||||
|
return value().call<int>("setDirections", JS::vectorToJSArray(directions));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Screeps
|
} // namespace Screeps
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue