2010-07-04 08:43:34 +00:00
|
|
|
#ifndef GAME_SCRIPT_GLOBALSCRIPTS_H
|
|
|
|
#define GAME_SCRIPT_GLOBALSCRIPTS_H
|
|
|
|
|
2020-05-10 12:57:06 +00:00
|
|
|
#include <boost/variant/variant.hpp>
|
|
|
|
|
2010-07-04 08:43:34 +00:00
|
|
|
#include <string>
|
|
|
|
#include <map>
|
2020-05-10 12:57:06 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
2010-07-04 08:43:34 +00:00
|
|
|
|
2014-03-05 16:08:58 +00:00
|
|
|
#include <stdint.h>
|
2013-12-15 15:16:50 +00:00
|
|
|
|
2010-07-04 08:43:34 +00:00
|
|
|
#include "locals.hpp"
|
|
|
|
|
2020-05-10 12:57:06 +00:00
|
|
|
#include "../mwworld/ptr.hpp"
|
|
|
|
|
2013-12-15 15:16:50 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
class ESMWriter;
|
|
|
|
class ESMReader;
|
2020-05-10 12:57:06 +00:00
|
|
|
struct RefNum;
|
2013-12-15 15:16:50 +00:00
|
|
|
}
|
|
|
|
|
2014-04-28 09:29:57 +00:00
|
|
|
namespace Loading
|
|
|
|
{
|
|
|
|
class Listener;
|
|
|
|
}
|
|
|
|
|
2013-12-12 12:15:38 +00:00
|
|
|
namespace MWWorld
|
2010-07-04 08:43:34 +00:00
|
|
|
{
|
2015-03-06 08:36:42 +00:00
|
|
|
class ESMStore;
|
2010-07-04 08:43:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace MWScript
|
|
|
|
{
|
2014-07-15 10:59:02 +00:00
|
|
|
struct GlobalScriptDesc
|
|
|
|
{
|
|
|
|
bool mRunning;
|
|
|
|
Locals mLocals;
|
2020-05-10 12:57:06 +00:00
|
|
|
boost::variant<MWWorld::Ptr, std::pair<ESM::RefNum, std::string> > mTarget; // Used to start targeted script
|
2014-07-15 10:59:02 +00:00
|
|
|
|
|
|
|
GlobalScriptDesc();
|
2020-05-10 12:57:06 +00:00
|
|
|
|
|
|
|
const MWWorld::Ptr* getPtrIfPresent() const; // Returns a Ptr if one has been resolved
|
|
|
|
|
|
|
|
MWWorld::Ptr getPtr(); // Resolves mTarget to a Ptr and caches the (potentially empty) result
|
2014-07-15 10:59:02 +00:00
|
|
|
};
|
|
|
|
|
2010-07-04 08:43:34 +00:00
|
|
|
class GlobalScripts
|
|
|
|
{
|
2012-10-01 15:17:04 +00:00
|
|
|
const MWWorld::ESMStore& mStore;
|
2020-05-10 12:57:06 +00:00
|
|
|
std::map<std::string, std::shared_ptr<GlobalScriptDesc> > mScripts;
|
2012-04-23 13:27:03 +00:00
|
|
|
|
2010-07-04 08:43:34 +00:00
|
|
|
public:
|
2012-04-23 13:27:03 +00:00
|
|
|
|
2012-10-01 15:17:04 +00:00
|
|
|
GlobalScripts (const MWWorld::ESMStore& store);
|
2012-04-23 13:27:03 +00:00
|
|
|
|
2020-05-10 12:57:06 +00:00
|
|
|
void addScript (const std::string& name, const MWWorld::Ptr& target = MWWorld::Ptr());
|
2012-04-23 13:27:03 +00:00
|
|
|
|
2010-07-04 14:00:32 +00:00
|
|
|
void removeScript (const std::string& name);
|
2012-04-23 13:27:03 +00:00
|
|
|
|
2010-07-04 14:00:32 +00:00
|
|
|
bool isRunning (const std::string& name) const;
|
2012-04-23 13:27:03 +00:00
|
|
|
|
|
|
|
void run();
|
2010-07-04 14:00:32 +00:00
|
|
|
///< run all active global scripts
|
2013-12-12 12:15:38 +00:00
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
void addStartup();
|
|
|
|
///< Add startup script
|
2013-12-15 15:16:50 +00:00
|
|
|
|
|
|
|
int countSavedGameRecords() const;
|
|
|
|
|
2014-04-28 09:29:57 +00:00
|
|
|
void write (ESM::ESMWriter& writer, Loading::Listener& progress) const;
|
2013-12-15 15:16:50 +00:00
|
|
|
|
2015-01-22 18:04:59 +00:00
|
|
|
bool readRecord (ESM::ESMReader& reader, uint32_t type);
|
2013-12-15 15:16:50 +00:00
|
|
|
///< Records for variables that do not exist are dropped silently.
|
|
|
|
///
|
|
|
|
/// \return Known type?
|
2014-02-10 13:45:55 +00:00
|
|
|
|
|
|
|
Locals& getLocals (const std::string& name);
|
|
|
|
///< If the script \a name has not been added as a global script yet, it is added
|
|
|
|
/// automatically, but is not set to running state.
|
2020-05-10 12:57:06 +00:00
|
|
|
|
2020-07-29 16:43:56 +00:00
|
|
|
const Locals* getLocalsIfPresent (const std::string& name) const;
|
|
|
|
|
2020-05-10 12:57:06 +00:00
|
|
|
void updatePtrs(const MWWorld::Ptr& base, const MWWorld::Ptr& updated);
|
|
|
|
///< Update the Ptrs stored in mTarget. Should be called after the reference has been moved to a new cell.
|
2010-07-04 08:43:34 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|