MCPcopy Create free account
hub / github.com/codereader/DarkRadiant / readObjectiveConditions

Method readObjectiveConditions

plugins/dm.objectives/ObjectiveEntity.cpp:48–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48void ObjectiveEntity::readObjectiveConditions(Entity& ent)
49{
50 _objConditions.clear(); // remove any previously parsed conditions
51
52 Entity::KeyValuePairs condSpawnargs = ent.getKeyValuePairs(OBJ_COND_PREFIX);
53
54 static const std::regex objCondExpr(OBJ_COND_PREFIX + "(\\d+)_(.*)");
55
56 for (Entity::KeyValuePairs::const_iterator kv = condSpawnargs.begin();
57 kv != condSpawnargs.end(); kv++)
58 {
59 std::smatch results;
60
61 if (!std::regex_match(kv->first, results, objCondExpr))
62 {
63 continue; // No match, abort
64 }
65
66 int index = string::convert<int>(results[1].str());
67
68 // Valid indices are [1..infinity)
69 if (index < 1)
70 {
71 continue; // invalid index, continue
72 }
73
74 const ObjectiveConditionPtr& cond = getOrCreateObjectiveCondition(index);
75
76 std::string postfix = results[2];
77
78 if (postfix == "src_mission")
79 {
80 cond->sourceMission = string::convert<int>(kv->second);
81 }
82 else if (postfix == "src_obj")
83 {
84 cond->sourceObjective = string::convert<int>(kv->second);
85 }
86 else if (postfix == "src_state")
87 {
88 int val = string::convert<int>(kv->second);
89
90 if (val >= Objective::INCOMPLETE && val < Objective::NUM_STATES)
91 {
92 cond->sourceState = static_cast<Objective::State>(val);
93 }
94 else
95 {
96 rWarning() << "Unsupported objective condition source state encountered: "
97 << kv->second << std::endl;
98 }
99 }
100 else if (postfix == "target_obj")
101 {
102 cond->targetObjective = string::convert<int>(kv->second);
103 }
104 else if (postfix == "type")
105 {

Callers

nothing calls this directly

Calls 6

rWarningFunction · 0.85
clearMethod · 0.45
getKeyValuePairsMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected