Debian Codegraph @

plugins/dm.objectives/ComponentType.h

raw
1 #ifndef COMPONENTTYPE_H_
2 #define COMPONENTTYPE_H_
3
4 #include <set>
5 #include <map>
6 #include <string>
7
8 namespace objectives
9 {
10
11 class ComponentType;
12
13 /**
14 * Set of ComponentTypes.
15 */
16 typedef std::set<ComponentType> ComponentTypeSet;
17
18 /**
19 * Enumeration of Component types.
20 *
21 * This is a typesafe enum containing all of the available Component types,
22 * such as COMP_KILL and COMP_KO. Named static instance functions are provided
23 * for all of the types, and a std::map is also available to look up a
24 * ComponentType instance by name (as provided by a spawnarg).
25 */
26 class ComponentType
27 {
28 private:
29 // Static enum count
30 static int enumCount;
31
32 // Static map of named ComponentType instances
33 typedef std::map<std::string, ComponentType> ComponentTypeMap;
34 static ComponentTypeMap& getMap();
35
36 // Integer ID of this ComponentType
37 int _id;
38
39 // Raw name of this type
40 std::string _name;
41
42 // User-friendly display name
43 std::string _displayName;
44
45 private:
46
47 // Construct a named ComponentType
48 ComponentType(const std::string& name, const std::string& displayName);
49
50 public:
51
52 /**
53 * Get the ComponentType identified by the given name.
54 *
55 * @param name
56 * The text name of the ComponentType to retrieve, such as "kill" or "ko".
57 *
58 * @return
59 * The identified ComponentType if it exists.
60 *
61 * @exception ObjectivesException
62 * Thrown if the named ComponentType does not exist.
63 */
64 static ComponentType getComponentType(const std::string& name);
65
66 /**
67 * Get the ComponentType identified by the given ID.
68 *
69 * @param id
70 * The id of the ComponentType.
71 *
72 * @return
73 * The identified ComponentType if it exists.
74 *
75 * @exception ObjectivesException
76 * Thrown if the named ComponentType does not exist.
77 */
78 static ComponentType getComponentType(int id);
79
80 /**
81 * Get the name of this ComponentType.
82 *
83 * This returns the "raw" name of the ComponentType as used in the entity
84 * spawnargs, such as "ai_alert" or "ko".
85 */
86 const std::string& getName() const {
87 return _name;
88 }
89
90 /**
91 * Get the display name of this ComponentType.
92 *
93 * This returns a user-friendly display name which is suitable for
94 * identifying the ComponentType in a dialog, such as "AI is killed".
95 */
96 const std::string& getDisplayName() const {
97 return _displayName;
98 }
99
100 /**
101 * Get the numeric ID of this ComponentType.
102 */
103 int getId() const {
104 return _id;
105 }
106
107 /**
108 * @name ComponentType instances.
109 */
110
111 //@{
112
113 static const ComponentType& COMP_KILL(); // AI is killed
114 static const ComponentType& COMP_KO(); // AI is knocked out.
115 static const ComponentType& COMP_AI_FIND_ITEM(); // AI finds an item.
116 static const ComponentType& COMP_AI_FIND_BODY(); // AI finds a body.
117 static const ComponentType& COMP_ALERT(); // AI is alerted.
118 static const ComponentType& COMP_DESTROY(); // Object is destroyed.
119 static const ComponentType& COMP_ITEM(); // Player possesses a number of items or loot.
120 static const ComponentType& COMP_PICKPOCKET(); // Item is pickpocketed from conscious AI.
121 static const ComponentType& COMP_LOCATION(); // Item is in a particular objective location (defined by a brush).
122 static const ComponentType& COMP_CUSTOM_ASYNC(); // Custom component updated by user script.
123 static const ComponentType& COMP_CUSTOM_CLOCKED(); // Custom component which periodically checks a user script.
124 static const ComponentType& COMP_INFO_LOCATION(); // Item is in a particular <b>info_location</b> area.
125 static const ComponentType& COMP_DISTANCE(); // Two entities are within a radius of each other.
126 static const ComponentType& COMP_READABLE_OPENED(); // Readable is opened
127 static const ComponentType& COMP_READABLE_CLOSED(); // Readable is closed
128 static const ComponentType& COMP_READABLE_PAGE_REACHED(); // A page of a readable is viewed
129
130 //@}
131
132 /**
133 * @name ComponentType convenience sets.
134 */
135
136 //@{
137
138 /** All ComponentTypes. */
139 static const ComponentTypeSet& SET_ALL();
140
141 //@}
142 };
143
144 /**
145 * Operator less for ComponentType objects.
146 *
147 * This is required to allow ComponentTypes to be placed in a map or set.
148 */
149 inline bool operator< (const ComponentType& first, const ComponentType& second)
150 {
151 return first.getId() < second.getId();
152 }
153
154 }
155
156 #endif /*COMPONENTTYPE_H_*/