]>
jfr.im git - irc/gameservirc.git/blob - gameserv/script.cpp
14 script::script(string
&str
)
19 script::script(const char *str
)
29 void script::setString(string
&str
)
34 void script::setString(const char *str
)
39 bool script::executeScript(Player
*p
)
42 string::size_type begin
= 0;
43 string::size_type end
= scriptstr
.find("\n", 0);
44 char *left
, *op
, *right
, *buffer
;
47 while (end
!= string::npos
)
49 // Get the line based on what we just found
50 line
= scriptstr
.substr(begin
, end
- begin
);
52 log("Line: %s", line
.c_str());
54 if (line
.c_str()[0] != '#')
57 buffer
= new char[line
.length()];
59 left
= strtok(buffer
, " ");
60 op
= strtok(NULL
, " ");
61 right
= strtok(NULL
, " ");
63 if (stricmp(left
, "GOLD") == 0)
65 (int*)leftptr
= p
->gold
;
67 else if (stricmp(left
, "STRENGTH") == 0)
69 (int*)leftptr
= p
->strength
;
75 end
= scriptstr
.find("\n", begin
);
80 bool script::loadScript(const char *filename
)
87 infile
.open(filename
, ios::binary
);
91 log("Error opening script %s", filename
);
95 // get length of file:
96 infile
.seekg (0, ios::end
);
97 length
= infile
.tellg();
98 infile
.seekg (0, ios::beg
);
102 buffer
= new char[length
];
103 infile
.read(buffer
, length
);