Write out Objectives to entity keyvals
| 525 | |
| 526 | // Write out Objectives to entity keyvals |
| 527 | void ObjectiveEntity::writeToEntity() |
| 528 | { |
| 529 | UndoableCommand cmd("saveObjectives"); |
| 530 | |
| 531 | // Try to convert the weak_ptr reference to a shared_ptr |
| 532 | Entity* entity = Node_getEntity(_entityNode.lock()); |
| 533 | assert(entity != NULL); |
| 534 | |
| 535 | // greebo: Remove all objective-related spawnargs first |
| 536 | clearEntity(entity); |
| 537 | |
| 538 | for (ObjectiveMap::const_iterator i = _objectives.begin(); |
| 539 | i != _objectives.end(); |
| 540 | ++i) |
| 541 | { |
| 542 | // Obtain the Objective and construct the key prefix from the index |
| 543 | const Objective& o = i->second; |
| 544 | std::string prefix = "obj" + string::to_string(i->first) + "_"; |
| 545 | |
| 546 | // Set the entity keyvalues |
| 547 | entity->setKeyValue(prefix + "desc", o.description); |
| 548 | entity->setKeyValue(prefix + "ongoing", o.ongoing ? "1" : "0"); |
| 549 | entity->setKeyValue(prefix + "visible", o.visible ? "1" : "0"); |
| 550 | entity->setKeyValue(prefix + "mandatory", o.mandatory ? "1" : "0"); |
| 551 | entity->setKeyValue(prefix + "irreversible", |
| 552 | o.irreversible ? "1" : "0"); |
| 553 | entity->setKeyValue(prefix + "state", string::to_string(o.state)); |
| 554 | |
| 555 | // Write an empty "objN_difficulty" value when this objective applies to all levels |
| 556 | entity->setKeyValue(prefix + "difficulty", o.difficultyLevels); |
| 557 | |
| 558 | entity->setKeyValue(prefix + "enabling_objs", o.enablingObjs); |
| 559 | |
| 560 | entity->setKeyValue(prefix + "script_complete", o.completionScript); |
| 561 | entity->setKeyValue(prefix + "script_failed", o.failureScript); |
| 562 | |
| 563 | entity->setKeyValue(prefix + "target_complete", o.completionTarget); |
| 564 | entity->setKeyValue(prefix + "target_failed", o.failureTarget); |
| 565 | |
| 566 | entity->setKeyValue(prefix + "logic_success", o.logic.successLogic); |
| 567 | entity->setKeyValue(prefix + "logic_failure", o.logic.failureLogic); |
| 568 | |
| 569 | // Write the Components for this Objective |
| 570 | writeComponents(entity, prefix, o); |
| 571 | } |
| 572 | |
| 573 | // Export the mission success/failure logic |
| 574 | writeMissionLogic(*entity); |
| 575 | |
| 576 | // Export objective conditions |
| 577 | writeObjectiveConditions(*entity); |
| 578 | } |
| 579 | |
| 580 | } // namespace objectives |
no test coverage detected