File: ComponentType.h

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (156 lines) | stat: -rw-r--r-- 4,217 bytes parent folder | download | duplicates (6)
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
#ifndef COMPONENTTYPE_H_
#define COMPONENTTYPE_H_

#include <set>
#include <map>
#include <string>

namespace objectives
{

class ComponentType;

/**
 * Set of ComponentTypes.
 */
typedef std::set<ComponentType> ComponentTypeSet;

/**
 * Enumeration of Component types.
 *
 * This is a typesafe enum containing all of the available Component types,
 * such as COMP_KILL and COMP_KO. Named static instance functions are provided
 * for all of the types, and a std::map is also available to look up a
 * ComponentType instance by name (as provided by a spawnarg).
 */
class ComponentType
{
private:
	// Static enum count
	static int enumCount;

	// Static map of named ComponentType instances
	typedef std::map<std::string, ComponentType> ComponentTypeMap;
	static ComponentTypeMap& getMap();

	// Integer ID of this ComponentType
	int _id;

	// Raw name of this type
	std::string _name;

	// User-friendly display name
	std::string _displayName;

private:

	// Construct a named ComponentType
	ComponentType(const std::string& name, const std::string& displayName);

public:

	/**
	 * Get the ComponentType identified by the given name.
	 *
	 * @param name
	 * The text name of the ComponentType to retrieve, such as "kill" or "ko".
	 *
	 * @return
	 * The identified ComponentType if it exists.
	 *
	 * @exception ObjectivesException
	 * Thrown if the named ComponentType does not exist.
	 */
	static ComponentType getComponentType(const std::string& name);

	/**
	 * Get the ComponentType identified by the given ID.
	 *
	 * @param id
	 * The id of the ComponentType.
	 *
	 * @return
	 * The identified ComponentType if it exists.
	 *
	 * @exception ObjectivesException
	 * Thrown if the named ComponentType does not exist.
	 */
	static ComponentType getComponentType(int id);

	/**
	 * Get the name of this ComponentType.
	 *
	 * This returns the "raw" name of the ComponentType as used in the entity
	 * spawnargs, such as "ai_alert" or "ko".
	 */
	const std::string& getName() const {
		return _name;
	}

	/**
	 * Get the display name of this ComponentType.
	 *
	 * This returns a user-friendly display name which is suitable for
	 * identifying the ComponentType in a dialog, such as "AI is killed".
	 */
	const std::string& getDisplayName() const {
		return _displayName;
	}

	/**
	 * Get the numeric ID of this ComponentType.
	 */
	int getId() const {
		return _id;
	}

	/**
	 * @name ComponentType instances.
	 */

	//@{

	static const ComponentType& COMP_KILL();			// AI is killed
	static const ComponentType& COMP_KO();				// AI is knocked out.
	static const ComponentType& COMP_AI_FIND_ITEM();	// AI finds an item.
	static const ComponentType& COMP_AI_FIND_BODY();	// AI finds a body.
	static const ComponentType& COMP_ALERT();			// AI is alerted.
	static const ComponentType& COMP_DESTROY();		// Object is destroyed.
	static const ComponentType& COMP_ITEM();			// Player possesses a number of items or loot.
	static const ComponentType& COMP_PICKPOCKET();		// Item is pickpocketed from conscious AI.
	static const ComponentType& COMP_LOCATION();		// Item is in a particular objective location (defined by a brush).
	static const ComponentType& COMP_CUSTOM_ASYNC();	// Custom component updated by user script.
	static const ComponentType& COMP_CUSTOM_CLOCKED();	// Custom component which periodically checks a user script.
	static const ComponentType& COMP_INFO_LOCATION();	// Item is in a particular <b>info_location</b> area.
	static const ComponentType& COMP_DISTANCE();		// Two entities are within a radius of each other.
	static const ComponentType& COMP_READABLE_OPENED();		// Readable is opened
	static const ComponentType& COMP_READABLE_CLOSED();		// Readable is closed
	static const ComponentType& COMP_READABLE_PAGE_REACHED();	// A page of a readable is viewed

	//@}

	/**
	 * @name ComponentType convenience sets.
	 */

	//@{

	/** All ComponentTypes. */
	static const ComponentTypeSet& SET_ALL();

	//@}
};

/**
 * Operator less for ComponentType objects.
 *
 * This is required to allow ComponentTypes to be placed in a map or set.
 */
inline bool operator< (const ComponentType& first, const ComponentType& second)
{
	return first.getId() < second.getId();
}

}

#endif /*COMPONENTTYPE_H_*/