CGE2: Some rework in Map.

This commit is contained in:
uruk 2014-06-08 12:42:05 +02:00
parent 1d8536e6df
commit acbd19bec4
2 changed files with 30 additions and 28 deletions

View File

@ -36,53 +36,54 @@ Map::~Map() {
_container.clear();
}
int Map::convertCoord(int coord) {
return (coord + (kMapGrid >> 1)) & kMapMask;
void Map::clear() {
_container.clear();
}
void Map::load(int cave) {
char fname[] = "%.2d.MAP\0";
Common::String filename = Common::String::format(fname, cave);
void Map::load(int scene) {
clear();
if (!_vm->_resman->exist(filename.c_str()))
char fname[] = "%.2d.MAP\0";
Common::String fileName = Common::String::format(fname, scene);
if (!_vm->_resman->exist(fileName.c_str()))
return;
EncryptedStream file(_vm, filename.c_str());
EncryptedStream file(_vm, fileName.c_str());
char tmpStr[kLineMax + 1];
Common::String line;
for (line = file.readLine(); !file.eos(); line = file.readLine()) {
if (line.size() == 0)
continue;
char tmpStr[kLineMax + 1];
Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr));
char *currPos = tmpStr;
currPos = strtok(currPos, " (),");
int x = atoi(currPos);
currPos = strtok(nullptr, " (),");
int y = atoi(currPos);
_container.push_back(V2D(_vm, convertCoord(x), convertCoord(y)));
int x = nextNum(currPos);
while (true) {
currPos = strtok(nullptr, " (),");
if (currPos == nullptr)
break;
int x = atoi(currPos);
currPos = strtok(nullptr, " (),");
int y = atoi(currPos);
int y = nextNum(nullptr);
_container.push_back(V2D(_vm, convertCoord(x), convertCoord(y)));
x = nextNum(nullptr);
if (x == -1) // We stop if there are no more data left to process in the current line.
break;
}
}
}
int Map::size() {
return _container.size();
int Map::nextNum(char *currPos) {
currPos = strtok(currPos, " (),");
if (currPos == nullptr)
return -1;
int num = atoi(currPos);
return num;
}
void Map::clear() {
_container.clear();
int Map::convertCoord(int coord) {
return (coord + (kMapGrid >> 1)) & kMapMask;
}
int Map::size() {
return _container.size();
}
V2D &Map::operator[](int idx) {

View File

@ -39,13 +39,14 @@ class Map {
CGE2Engine *_vm;
Common::Array<V2D> _container;
int convertCoord(int coord);
int convertCoord(int coord);
int nextNum(char *currPos);
public:
Map(CGE2Engine *vm);
~Map();
void load(int cave);
int size();
void clear();
void load(int scene);
int size();
V2D &operator[](int idx);
};