blob: cd70f4e6674dbb2cffe5607dba038ae66bda2f34 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
#ifndef GAME_SCRIPT_GLOBALSCRIPTS_H
#define GAME_SCRIPT_GLOBALSCRIPTS_H
#include <boost/variant/variant.hpp>
#include <string>
#include <map>
#include <memory>
#include <utility>
#include <stdint.h>
#include "locals.hpp"
#include "../mwworld/ptr.hpp"
namespace ESM
{
class ESMWriter;
class ESMReader;
struct RefNum;
}
namespace Loading
{
class Listener;
}
namespace MWWorld
{
class ESMStore;
}
namespace MWScript
{
struct GlobalScriptDesc
{
bool mRunning;
Locals mLocals;
boost::variant<MWWorld::Ptr, std::pair<ESM::RefNum, std::string> > mTarget; // Used to start targeted script
GlobalScriptDesc();
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
std::string getId() const; // Returns the target's ID -- if any
};
class GlobalScripts
{
const MWWorld::ESMStore& mStore;
std::map<std::string, std::shared_ptr<GlobalScriptDesc> > mScripts;
public:
GlobalScripts (const MWWorld::ESMStore& store);
void addScript (const std::string& name, const MWWorld::Ptr& target = MWWorld::Ptr());
void removeScript (const std::string& name);
bool isRunning (const std::string& name) const;
void run();
///< run all active global scripts
void clear();
void addStartup();
///< Add startup script
int countSavedGameRecords() const;
void write (ESM::ESMWriter& writer, Loading::Listener& progress) const;
bool readRecord (ESM::ESMReader& reader, uint32_t type, const std::map<int, int>& contentFileMap);
///< Records for variables that do not exist are dropped silently.
///
/// \return Known type?
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.
const Locals* getLocalsIfPresent (const std::string& name) const;
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.
};
}
#endif
|