| 129 | } |
| 130 | |
| 131 | void ObjectiveEntity::writeObjectiveConditions(Entity& ent) |
| 132 | { |
| 133 | // No need to clear previous set of obj_condition_ spawnargs, |
| 134 | // as they've been removed by clearEntity() already |
| 135 | |
| 136 | // Spawnargs are numbered starting with 1 as first index |
| 137 | std::size_t index = 1; |
| 138 | |
| 139 | // Go through all the conditions and save them. Skip invalid ones such that the |
| 140 | // set of conditions will be "compressed" in terms of their indices. |
| 141 | for (ObjectiveEntity::ConditionMap::const_iterator i = _objConditions.begin(); |
| 142 | i != _objConditions.end(); ++i) |
| 143 | { |
| 144 | const ObjectiveCondition& cond = *i->second; |
| 145 | |
| 146 | if (!cond.isValid()) |
| 147 | { |
| 148 | continue; // skip invalid conditions without increasing the index |
| 149 | } |
| 150 | |
| 151 | std::string prefix = fmt::format(OBJ_COND_PREFIX + "{0:d}_", index); |
| 152 | |
| 153 | ent.setKeyValue(prefix + "src_mission", string::to_string(cond.sourceMission)); |
| 154 | ent.setKeyValue(prefix + "src_obj", string::to_string(cond.sourceObjective)); |
| 155 | ent.setKeyValue(prefix + "src_state", string::to_string(cond.sourceState)); |
| 156 | ent.setKeyValue(prefix + "target_obj", string::to_string(cond.targetObjective)); |
| 157 | |
| 158 | std::string typeKey = prefix + "type"; |
| 159 | |
| 160 | switch (cond.type) |
| 161 | { |
| 162 | case ObjectiveCondition::CHANGE_STATE: |
| 163 | ent.setKeyValue(typeKey, "changestate"); |
| 164 | break; |
| 165 | case ObjectiveCondition::CHANGE_VISIBILITY: |
| 166 | ent.setKeyValue(typeKey, "changevisibility"); |
| 167 | break; |
| 168 | case ObjectiveCondition::CHANGE_MANDATORY: |
| 169 | ent.setKeyValue(typeKey, "changemandatory"); |
| 170 | break; |
| 171 | default: |
| 172 | ent.setKeyValue(typeKey, ""); // empty value to be sure |
| 173 | rWarning() << "Invalid objective condition type encountered on saving." << std::endl; |
| 174 | break; |
| 175 | }; |
| 176 | |
| 177 | ent.setKeyValue(prefix + "value", string::to_string(cond.value)); |
| 178 | |
| 179 | ++index; // next index |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | void ObjectiveEntity::readMissionLogic(Entity& ent) |
| 184 | { |