| 1 |
#pragma once |
| 2 |
|
| 3 |
#include "Objective.h" |
| 4 |
#include "Logic.h" |
| 5 |
#include "ObjectiveCondition.h" |
| 6 |
|
| 7 |
#include "inode.h" |
| 8 |
#include <memory> |
| 9 |
#include "wxutil/dataview/TreeModel.h" |
| 10 |
|
| 11 |
// FORWARD DECLS |
| 12 |
namespace objectives { class TargetList; } |
| 13 |
class Entity; |
| 14 |
class wxChoice; |
| 15 |
|
| 16 |
namespace objectives |
| 17 |
{ |
| 18 |
|
| 19 |
struct ObjectivesListColumns : |
| 20 |
public wxutil::TreeModel::ColumnRecord |
| 21 |
{ |
| 22 |
ObjectivesListColumns() : |
| 23 |
objNumber(add(wxutil::TreeModel::Column::Integer)), |
| 24 |
description(add(wxutil::TreeModel::Column::String)), |
| 25 |
difficultyLevel(add(wxutil::TreeModel::Column::String)) |
| 26 |
{} |
| 27 |
|
| 28 |
wxutil::TreeModel::Column objNumber; |
| 29 |
wxutil::TreeModel::Column description; |
| 30 |
wxutil::TreeModel::Column difficultyLevel; |
| 31 |
}; |
| 32 |
|
| 33 |
/** |
| 34 |
* Representation of a single objective entity (target_tdm_addobjectives). |
| 35 |
* |
| 36 |
* In the Dark Mod, objectives are stored as numbered spawnargs on an objective |
| 37 |
* entity, e.g. <b>obj3_desc</b>. Each objective entity can contain any number |
| 38 |
* of objectives described in this way. |
| 39 |
* |
| 40 |
* The ObjectiveEntity class provides an object-oriented view of the objective |
| 41 |
* information, by wrapping a pointer to an Entity and providing methods to |
| 42 |
* retrieve and manipulate objective information without seeing the spawnargs |
| 43 |
* directly. When changes are completed, the ObjectiveEntity::writeToEntity() |
| 44 |
* method is invoked to save all changes in the form of spawnargs. |
| 45 |
* |
| 46 |
* @see Entity |
| 47 |
* @see objectives::Objective |
| 48 |
*/ |
| 49 |
class ObjectiveEntity |
| 50 |
{ |
| 51 |
public: |
| 52 |
// Public typedef |
| 53 |
typedef std::map<int, ObjectiveConditionPtr> ConditionMap; |
| 54 |
|
| 55 |
private: |
| 56 |
// The actual entity's world node and entity pointer |
| 57 |
scene::INodeWeakPtr _entityNode; |
| 58 |
|
| 59 |
// Map of numbered Objective objects |
| 60 |
ObjectiveMap _objectives; |
| 61 |
|
| 62 |
// Each difficulty level can have its own mission logic |
| 63 |
// The index -1 is reserved for the default logic |
| 64 |
typedef std::map<int, LogicPtr> LogicMap; |
| 65 |
LogicMap _logics; |
| 66 |
|
| 67 |
// Each objective condition has a certain index |
| 68 |
ConditionMap _objConditions; |
| 69 |
|
| 70 |
private: |
| 71 |
|
| 72 |
// Read the mission success/failure logic from the entity |
| 73 |
void readMissionLogic(Entity& ent); |
| 74 |
|
| 75 |
// Store the mission logic to the entity |
| 76 |
void writeMissionLogic(Entity& ent); |
| 77 |
|
| 78 |
// Read/save objective conditions from/to entity |
| 79 |
void readObjectiveConditions(Entity& ent); |
| 80 |
void writeObjectiveConditions(Entity& ent); |
| 81 |
|
| 82 |
// Write the Components to the underlying entity |
| 83 |
void writeComponents( |
| 84 |
Entity* entity, const std::string& keyPrefix, const Objective& objective |
| 85 |
); |
| 86 |
|
| 87 |
// Removes all objective-related spawnargs from the given entity |
| 88 |
void clearEntity(Entity* entity); |
| 89 |
|
| 90 |
public: |
| 91 |
|
| 92 |
/** |
| 93 |
* Construct an ObjectiveEntity wrapper around the given Node. |
| 94 |
*/ |
| 95 |
ObjectiveEntity(const scene::INodePtr& node); |
| 96 |
|
| 97 |
/** |
| 98 |
* Return an Objective reference by numeric index. |
| 99 |
* |
| 100 |
* @param iIndex |
| 101 |
* The numberic index of the objective to retrieve. |
| 102 |
* |
| 103 |
* @return |
| 104 |
* A non-const reference to an Objective object, corresponding to the |
| 105 |
* given index. If the provided index did not previously exist, a new |
| 106 |
* Objective object will be created and returned. |
| 107 |
*/ |
| 108 |
Objective& getObjective(int iIndex) { |
| 109 |
return _objectives[iIndex]; |
| 110 |
} |
| 111 |
|
| 112 |
// Returns the highest used objective index or -1 if none are present |
| 113 |
int getHighestObjIndex() { |
| 114 |
if (_objectives.empty()) return -1; |
| 115 |
|
| 116 |
return _objectives.rbegin()->first; |
| 117 |
} |
| 118 |
|
| 119 |
// Returns the highest used objective index or -1 if none are present |
| 120 |
int getLowestObjIndex() { |
| 121 |
if (_objectives.empty()) return -1; |
| 122 |
|
| 123 |
return _objectives.begin()->first; |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* Add a new objective, starting from the first unused objective ID. |
| 128 |
*/ |
| 129 |
void addObjective(); |
| 130 |
|
| 131 |
/** |
| 132 |
* greebo: Moves the specified objective by the given amount (e.g. +1/-1). |
| 133 |
* @returns: the new index. |
| 134 |
*/ |
| 135 |
int moveObjective(int index, int delta); |
| 136 |
|
| 137 |
/** |
| 138 |
* Delete a numbered objective. This re-orders all objectives so that the |
| 139 |
* numbering is consistent again (deleting obj 2 will re-number 3 => 2, 4 => 3, etc.) |
| 140 |
*/ |
| 141 |
void deleteObjective(int index); |
| 142 |
|
| 143 |
/** |
| 144 |
* Clear all objectives. |
| 145 |
*/ |
| 146 |
void clearObjectives() { |
| 147 |
_objectives.clear(); |
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* Test whether this entity contains objectives or not. |
| 152 |
*/ |
| 153 |
bool isEmpty() const { |
| 154 |
return _objectives.empty(); |
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* Delete the actual entity node from the map. This will render any further |
| 159 |
* operations on this ObjectiveEntity undefined, and it should immediately |
| 160 |
* be deleted. |
| 161 |
*/ |
| 162 |
void deleteWorldNode(); |
| 163 |
|
| 164 |
/** |
| 165 |
* Test whether this Objective Entity is on the provided TargetList, to |
| 166 |
* determine whether the entity is a target of another entity (e.g. the |
| 167 |
* worldspawn). |
| 168 |
*/ |
| 169 |
bool isOnTargetList(const TargetList& list) const; |
| 170 |
|
| 171 |
/** |
| 172 |
* greebo: Returns the mission logic structure for the given difficulty level. |
| 173 |
* The level -1 refers to the default logic structure. |
| 174 |
* |
| 175 |
* @returns: The logic (is never NULL). The logic object will be created if |
| 176 |
* it isn't already existing, but the logic structure would be empty in that case. |
| 177 |
*/ |
| 178 |
LogicPtr getMissionLogic(int difficultyLevel); |
| 179 |
|
| 180 |
// Returns the full list of objective conditions by value |
| 181 |
ConditionMap getObjectiveConditions() const; |
| 182 |
|
| 183 |
// Replaces the existing set of objective conditions with this new one |
| 184 |
void setObjectiveConditions(const ConditionMap& conditions); |
| 185 |
|
| 186 |
// Returns the number of objective conditions present on this entity |
| 187 |
std::size_t getNumObjectiveConditions() const; |
| 188 |
|
| 189 |
// Returns the given objective condition, will create if not existing yet |
| 190 |
const ObjectiveConditionPtr& getOrCreateObjectiveCondition(int index); |
| 191 |
|
| 192 |
// Remove all objective conditions from this entitiy |
| 193 |
void clearObjectiveConditions(); |
| 194 |
|
| 195 |
/** |
| 196 |
* Populate the given list store with the objectives from this entity. |
| 197 |
* |
| 198 |
* @param store |
| 199 |
* The list store to populate. This must have 2 columns -- an integer |
| 200 |
* column for the objective number, and a text column for the description. |
| 201 |
*/ |
| 202 |
void populateListStore(wxutil::TreeModel& store, |
| 203 |
const ObjectivesListColumns& columns) const; |
| 204 |
|
| 205 |
/** |
| 206 |
* Populate the given choice field. |
| 207 |
*/ |
| 208 |
void populateChoice(wxChoice* choice) const; |
| 209 |
|
| 210 |
/** |
| 211 |
* Write all objective data to keyvals on the underlying entity. |
| 212 |
*/ |
| 213 |
void writeToEntity(); |
| 214 |
}; |
| 215 |
|
| 216 |
/** |
| 217 |
* Objective entity pointer type. |
| 218 |
*/ |
| 219 |
typedef std::shared_ptr<ObjectiveEntity> ObjectiveEntityPtr; |
| 220 |
|
| 221 |
/** |
| 222 |
* Objective entity named map type. |
| 223 |
*/ |
| 224 |
typedef std::map<std::string, ObjectiveEntityPtr> ObjectiveEntityMap; |
| 225 |
|
| 226 |
|
| 227 |
} |