feat: Implement running OnExit trigger scripts

This commit is contained in:
Vsevolod Kremianskii 2020-11-15 20:36:43 +07:00
parent 7cc49a7a6e
commit 3c4b1c87f9
3 changed files with 12 additions and 0 deletions

View file

@ -35,6 +35,7 @@ void TriggerBlueprint::load(const GffStruct &utt) {
boost::to_lower(_tag);
_onEnter = utt.getString("ScriptOnEnter");
_onExit = utt.getString("ScriptOnExit");
}
const string &TriggerBlueprint::tag() const {
@ -45,6 +46,10 @@ const string &TriggerBlueprint::onEnter() const {
return _onEnter;
}
const string &TriggerBlueprint::onExit() const {
return _onExit;
}
} // namespace resource
} // namespace reone

View file

@ -33,11 +33,13 @@ public:
const std::string &tag() const;
const std::string &onEnter() const;
const std::string &onExit() const;
private:
std::string _resRef;
std::string _tag;
std::string _onEnter;
std::string _onExit;
TriggerBlueprint(const TriggerBlueprint &) = delete;
TriggerBlueprint &operator=(const TriggerBlueprint &) = delete;

View file

@ -24,6 +24,7 @@
#include "../../resource/resources.h"
#include "../blueprint/blueprints.h"
#include "../script/util.h"
using namespace std;
@ -77,6 +78,10 @@ void Trigger::update(float dt) {
if (isIn(position2d)) continue;
tenantsToRemove.insert(tenant);
if (!_blueprint->onExit().empty()) {
runScript(_blueprint->onExit(), id(), tenant->id(), -1);
}
}
for (auto &tenant : tenantsToRemove) {
_tenants.erase(tenant);