]>
jfr.im git - irc/gameservirc.git/blob - gameserv/script.cpp
15 script::script(string
&str
)
20 script::script(const char *str
)
30 void script::setString(string
&str
)
35 void script::setString(const char *str
)
40 bool script::executeScript(Player
*p
)
43 string::size_type begin
= 0;
44 string::size_type end
= scriptstr
.find("\n", 0);
45 char *left
, *op
, *right
, *buffer
;
48 while (end
!= string::npos
)
50 // Get the line based on what we just found
51 line
= scriptstr
.substr(begin
, end
- begin
);
53 log("Line: %s", line
.c_str());
55 if (line
.c_str()[0] != '#')
58 buffer
= new char[line
.length()];
60 left
= strtok(buffer
, " ");
61 op
= strtok(NULL
, " ");
62 right
= strtok(NULL
, " ");
64 if (stricmp(left
, "GOLD") == 0)
66 leftptr
= (void*)p
->gold
;
68 else if (stricmp(left
, "STRENGTH") == 0)
70 leftptr
= (void*)p
->strength
;
76 end
= scriptstr
.find("\n", begin
);
81 bool script::loadScript(const char *filename
)
88 infile
.open(filename
, ios::binary
);
92 log("Error opening script %s", filename
);
96 // get length of file:
97 infile
.seekg (0, ios::end
);
98 length
= infile
.tellg();
99 infile
.seekg (0, ios::beg
);
103 buffer
= new char[length
];
104 infile
.read(buffer
, length
);