]>
Commit | Line | Data |
---|---|---|
22ea56df | 1 | #include "script.h" |
0b71e6c2 | 2 | #include "extern.h" |
3 | #include <fstream> | |
4 | #include <string> | |
5 | ||
6 | using namespace std; | |
22ea56df | 7 | |
8 | script::script() | |
9 | { | |
10 | scriptstr = ""; | |
11 | } | |
12 | ||
13 | script::script(string &str) | |
14 | { | |
15 | scriptstr = str; | |
16 | } | |
17 | ||
18 | script::script(const char *str) | |
19 | { | |
20 | scriptstr = str; | |
21 | } | |
22 | ||
23 | script::~script() | |
24 | { | |
25 | scriptstr = ""; | |
26 | } | |
27 | ||
28 | void script::setString(string &str) | |
29 | { | |
30 | scriptstr = str; | |
31 | } | |
32 | ||
33 | void script::setString(const char *str) | |
34 | { | |
35 | scriptstr = str; | |
36 | } | |
37 | ||
38 | bool script::executeScript(Player *p) | |
39 | { | |
40 | return true; | |
41 | } | |
0b71e6c2 | 42 | |
43 | bool script::loadScript(const char *filename) | |
44 | { | |
45 | char *buffer; | |
46 | int length; | |
47 | ifstream infile; | |
48 | bool result; | |
49 | ||
50 | infile.open(filename, ios::binary); | |
51 | ||
52 | if (infile.fail()) | |
53 | { | |
54 | log("Error opening script %s", filename); | |
55 | return false; | |
56 | } | |
57 | ||
58 | // get length of file: | |
59 | infile.seekg (0, ios::end); | |
60 | length = infile.tellg(); | |
61 | infile.seekg (0, ios::beg); | |
62 | ||
63 | if (length > 0) | |
64 | { | |
65 | buffer = new char[length]; | |
66 | infile.read(buffer, length); | |
67 | scriptstr = buffer; | |
68 | delete [] buffer; | |
69 | result = true; | |
70 | } | |
71 | else | |
72 | { | |
73 | result = false; | |
74 | } | |
75 | infile.close(); | |
76 | return result; | |
77 | } |