1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
#include "ComponentType.h"
#include "util/ObjectivesException.h"
#include "i18n.h"
#include <algorithm>
#include "string/convert.h"
namespace objectives
{
// Enum count
int ComponentType::enumCount = 0;
// Static map
ComponentType::ComponentTypeMap& ComponentType::getMap() {
static ComponentTypeMap _instance;
return _instance;
}
// Static instances
const ComponentType& ComponentType::COMP_KILL() {
static ComponentType _instance("kill", _("AI is killed"));
return _instance;
}
const ComponentType& ComponentType::COMP_KO() {
static ComponentType _instance("ko", _("AI is knocked out"));
return _instance;
}
const ComponentType& ComponentType::COMP_AI_FIND_ITEM() {
static ComponentType _instance("ai_find_item", _("AI finds an item"));
return _instance;
}
const ComponentType& ComponentType::COMP_AI_FIND_BODY() {
static ComponentType _instance("ai_find_body", _("AI finds a body"));
return _instance;
}
const ComponentType& ComponentType::COMP_ALERT() {
static ComponentType _instance("alert", _("AI is alerted")); // sic
return _instance;
}
const ComponentType& ComponentType::COMP_DESTROY() {
static ComponentType _instance("destroy", _("Object is destroyed"));
return _instance;
}
const ComponentType& ComponentType::COMP_ITEM() {
static ComponentType _instance("item", _("Player possesses item"));
return _instance;
}
const ComponentType& ComponentType::COMP_PICKPOCKET() {
static ComponentType _instance("pickpocket", _("Player pickpockets AI"));
return _instance;
}
const ComponentType& ComponentType::COMP_LOCATION() {
static ComponentType _instance("location", _("Item is in location"));
return _instance;
}
const ComponentType& ComponentType::COMP_INFO_LOCATION() {
static ComponentType _instance("info_location", _("Item is in info_location"));
return _instance;
}
const ComponentType& ComponentType::COMP_CUSTOM_ASYNC() {
static ComponentType _instance("custom", _("Custom script")); // sic
return _instance;
}
const ComponentType& ComponentType::COMP_CUSTOM_CLOCKED() {
static ComponentType _instance(
"custom_clocked", _("Custom script queried periodically")
);
return _instance;
}
const ComponentType& ComponentType::COMP_DISTANCE() {
static ComponentType _instance(
"distance", _("Two entities are within a radius of each other")
);
return _instance;
}
const ComponentType& ComponentType::COMP_READABLE_OPENED()
{
static ComponentType _instance(
"readable_opened", _("Readable is opened.")
);
return _instance;
}
const ComponentType& ComponentType::COMP_READABLE_CLOSED()
{
static ComponentType _instance(
"readable_closed", _("Readable is closed.")
);
return _instance;
}
const ComponentType& ComponentType::COMP_READABLE_PAGE_REACHED()
{
static ComponentType _instance(
"readable_page_reached", _("A certain page of a readable is reached.")
);
return _instance;
}
// Static sets
const ComponentTypeSet& ComponentType::SET_ALL() {
static ComponentTypeSet _instance;
if (_instance.empty()) {
_instance.insert(COMP_KILL());
_instance.insert(COMP_KO());
_instance.insert(COMP_AI_FIND_ITEM());
_instance.insert(COMP_AI_FIND_BODY());
_instance.insert(COMP_ALERT());
_instance.insert(COMP_DESTROY());
_instance.insert(COMP_ITEM());
_instance.insert(COMP_PICKPOCKET());
_instance.insert(COMP_LOCATION());
_instance.insert(COMP_INFO_LOCATION());
_instance.insert(COMP_CUSTOM_ASYNC());
_instance.insert(COMP_CUSTOM_CLOCKED());
_instance.insert(COMP_DISTANCE());
_instance.insert(COMP_READABLE_OPENED());
_instance.insert(COMP_READABLE_CLOSED());
_instance.insert(COMP_READABLE_PAGE_REACHED());
}
return _instance;
}
// Construct a named ComponentType
ComponentType::ComponentType(const std::string& name,
const std::string& displayName)
: _id(enumCount++),
_name(name),
_displayName(displayName)
{
// Register self in map
getMap().insert(ComponentTypeMap::value_type(name, *this));
}
// Lookup a named type in map
ComponentType ComponentType::getComponentType(const std::string& name)
{
ComponentTypeMap::const_iterator i = getMap().find(name);
if (i != getMap().end())
return i->second;
else
throw ObjectivesException("Invalid ComponentType: " + name);
}
ComponentType ComponentType::getComponentType(int id)
{
ComponentTypeMap::const_iterator i = std::find_if(getMap().begin(), getMap().end(),
[=] (const ComponentTypeMap::value_type& pair)->bool
{
return pair.second.getId() == id;
});
if (i != getMap().end())
return i->second;
else
throw ObjectivesException("Invalid ComponentType ID: " + string::to_string(id));
}
}
|