diff options
| -rw-r--r-- | engines/cge/cge_main.cpp | 85 | ||||
| -rw-r--r-- | engines/cge/vga13h.cpp | 71 | 
2 files changed, 66 insertions, 90 deletions
| diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index d3c88845c2..e56fad5d91 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -477,11 +477,11 @@ void CGEEngine::tooFar() {  void CGEEngine::loadHeroXY() {  	debugC(1, kCGEDebugEngine, "CGEEngine::loadHeroXY()"); -	VFile cf("CGE.HXY"); +	EncryptedStream cf("CGE.HXY");  	uint16 x, y;  	memset(_heroXY, 0, sizeof(_heroXY)); -	if (!cf._error) { +	if (!cf.err()) {  		for (int i = 0; i < kCaveMax; ++i) {  			cf.read((byte *)&x, 2);  			cf.read((byte *)&y, 2); @@ -496,8 +496,8 @@ void CGEEngine::loadMapping() {  	debugC(1, kCGEDebugEngine, "CGEEngine::loadMapping()");  	if (_now <= kCaveMax) { -		VFile cf("CGE.TAB"); -		if (!cf._error) { +		EncryptedStream cf("CGE.TAB"); +		if (!cf.err()) {  			// Move to the data for the given room  			cf.seek((_now - 1) * kMapArrSize); @@ -1030,23 +1030,24 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int  	bool tran = false;  	int i, lcnt = 0; -	char line[kLineMax]; -	mergeExt(line, fname, kSprExt); +	char tmpStr[kLineMax + 1]; +	Common::String line; +	mergeExt(tmpStr, fname, kSprExt); -	if (_cat->exist(line)) {      // sprite description file exist -		VFile sprf(line); -		if (sprf._error) -			error("Bad SPR [%s]", line); +	if (_cat->exist(tmpStr)) {      // sprite description file exist +		EncryptedStream sprf(tmpStr); +		if (sprf.err()) +			error("Bad SPR [%s]", tmpStr);  		uint16 len; -		while ((len = sprf.read((uint8 *)line)) != 0) { +		for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()) { +			len = line.size();			  			lcnt++; -			if (len && line[len - 1] == '\n') -				line[--len] = '\0'; -			if (len == 0 || *line == '.') +			strcpy(tmpStr, line.c_str()); +			if (len == 0 || *tmpStr == '.')  				continue; -			if ((i = takeEnum(Comd, strtok(line, " =\t"))) < 0) +			if ((i = takeEnum(Comd, strtok(tmpStr, " =\t"))) < 0)  				error("Bad line %d [%s]", lcnt, fname); @@ -1073,7 +1074,8 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int  		}  		if (! shpcnt)  			error("No shapes [%s]", fname); -	} else { // no sprite description: mono-shaped sprite with only .BMP file +	} else { +		// no sprite description: mono-shaped sprite with only .BMP file  		++shpcnt;  	} @@ -1084,7 +1086,6 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int  		_sprite = new Sprite(this, NULL);  		if (_sprite) {  			_sprite->gotoxy(col, row); -			//Sprite->Time = 1;//-----------$$$$$$$$$$$$$$$$  		}  		break;  	case 2: @@ -1099,45 +1100,14 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int  		_sprite = w;  		break;  		} -	/* -	case 3 : // NEWTON -	NEWTON * n = new NEWTON(NULL); -	if (n) -	{ -	   n->Ay = (bottom-n->H); -	   n->By = 90; -	   n->Cy = 3; -	   n->Bx = 99; -	   n->Cx = 3; -	   n->Goto(col, row); -	 } -	     _sprite = n; -	     break; -	     */ -	case 4: -		// LISSAJOUS +	case 3:  // NEWTON +	case 4:  // LISSAJOUS  		error("Bad type [%s]", fname); -		/* -		LISSAJOUS * l = new LISSAJOUS(NULL); -		if (l) -		{ -		   l->Ax = SCR_WID/2; -		   l->Ay = SCR_HIG/2; -		   l->Bx = 7; -		   l->By = 13; -		   l->Cx = 300; -		   l->Cy = 500; -		   *(long *) &l->Dx = 0; // movex * cnt -		   l->Goto(col, row); -		 } -		     _sprite = l; -		     */  		break;  	case 5:  		{ // FLY  		Fly *f = new Fly(this, NULL);  		_sprite = f; -		//////Sprite->Time = 1;//-----------$$$$$$$$$$$$$$  		break;  		}  	default: @@ -1170,26 +1140,29 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int  }  void CGEEngine::loadScript(const char *fname) { -	VFile scrf(fname); +	EncryptedStream scrf(fname); -	if (scrf._error) +	if (scrf.err())  		return;  	bool ok = true;  	int lcnt = 0; -	char line[kLineMax]; -	while (scrf.read((uint8 *)line) != 0) { +	char tmpStr[kLineMax+1]; +	Common::String line; + +	for (line = scrf.readLine(); !scrf.eos(); line = scrf.readLine()) {  		char *p;  		lcnt++; -		if (*line == 0 || *line == '\n' || *line == '.') +		strcpy(tmpStr, line.c_str()); +		if ((line.size() == 0) || (*tmpStr == '.'))  			continue;  		ok = false;   // not OK if break  		// sprite ident number -		if ((p = strtok(line, " \t\n")) == NULL) +		if ((p = strtok(tmpStr, " \t\n")) == NULL)  			break;  		int SpI = atoi(p); diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 727cc72e39..ef085359a7 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -209,37 +209,40 @@ Sprite *Sprite::expand() {  		return this;  	static const char *Comd[] = { "Name", "Phase", "Seq", "Near", "Take", NULL }; -	char line[kLineMax], fname[kPathMax]; +	char fname[kPathMax];  	Common::Array<BitmapPtr> shplist;  	for (int i = 0; i < _shpCnt + 1; ++i)  		shplist.push_back(NULL);  	Seq *seq = NULL; -	int shpcnt = 0, -	    seqcnt = 0, -	    neacnt = 0, -	    takcnt = 0, +	int shapeCount = 0, +	    seqCount = 0, +	    nearCount = 0, +	    takeCount = 0,  	    maxnow = 0,  	    maxnxt = 0; -	Snail::Com *nea = NULL; -	Snail::Com *tak = NULL; +	Snail::Com *near = NULL; +	Snail::Com *take = NULL;  	mergeExt(fname, _file, kSprExt);  	if (_cat->exist(fname)) { // sprite description file exist -		VFile sprf(fname); -		if (!(sprf._error==0)) +		EncryptedStream sprf(fname); +		if (sprf.err())  			error("Bad SPR [%s]", fname); +		Common::String line; +		char tmpStr[kLineMax + 1];  		int len = 0, lcnt = 0; -		while ((len = sprf.read((uint8 *)line)) != 0) { + +		for (line = sprf.readLine(); !sprf.eos(); line = sprf.readLine()) { +			len = line.size(); +			strcpy(tmpStr, line.c_str());  			lcnt++; -			if (len && line[len - 1] == '\n') -				line[--len] = '\0'; -			if (len == 0 || *line == '.') +			if (len == 0 || *tmpStr == '.')  				continue;  			Snail::Com *c; -			switch (takeEnum(Comd, strtok(line, " =\t"))) { +			switch (takeEnum(Comd, strtok(tmpStr, " =\t"))) {  			case 0:  				// Name  				setName(strtok(NULL, "")); @@ -247,28 +250,28 @@ Sprite *Sprite::expand() {  			case 1:  				// Phase  				// In case the shape index gets too high, increase the array size -				while ((shpcnt + 1) >= (int)shplist.size()) { +				while ((shapeCount + 1) >= (int)shplist.size()) {  					shplist.push_back(NULL);  					++_shpCnt;  				} -				shplist[shpcnt++] = new Bitmap(strtok(NULL, " \t,;/")); +				shplist[shapeCount++] = new Bitmap(strtok(NULL, " \t,;/"));  				break;  			case 2:  				// Seq -				seq = (Seq *) realloc(seq, (seqcnt + 1) * sizeof(*seq)); +				seq = (Seq *)realloc(seq, (seqCount + 1) * sizeof(*seq));  				assert(seq != NULL);  				Seq *s; -				s = &seq[seqcnt++]; +				s = &seq[seqCount++];  				s->_now = atoi(strtok(NULL, " \t,;/"));  				if (s->_now > maxnow)  					maxnow = s->_now;  				s->_next = atoi(strtok(NULL, " \t,;/"));  				switch (s->_next) {  				case 0xFF: -					s->_next = seqcnt; +					s->_next = seqCount;  					break;  				case 0xFE: -					s->_next = seqcnt - 1; +					s->_next = seqCount - 1;  					break;  				}  				if (s->_next > maxnxt) @@ -281,9 +284,9 @@ Sprite *Sprite::expand() {  				// Near  				if (_nearPtr == kNoPtr)  					break; -				nea = (Snail::Com *) realloc(nea, (neacnt + 1) * sizeof(*nea)); -				assert(nea != NULL); -				c = &nea[neacnt++]; +				near = (Snail::Com *)realloc(near, (nearCount + 1) * sizeof(*near)); +				assert(near != NULL); +				c = &near[nearCount++];  				if ((c->_com = (SnCom)takeEnum(Snail::_comText, strtok(NULL, " \t,;/"))) < 0)  					error("Bad NEAR in %d [%s]", lcnt, fname);  				c->_ref = atoi(strtok(NULL, " \t,;/")); @@ -294,9 +297,9 @@ Sprite *Sprite::expand() {  				// Take  				if (_takePtr == kNoPtr)  					break; -				tak = (Snail::Com *) realloc(tak, (takcnt + 1) * sizeof(*tak)); -				assert(tak != NULL); -				c = &tak[takcnt++]; +				take = (Snail::Com *)realloc(take, (takeCount + 1) * sizeof(*take)); +				assert(take != NULL); +				c = &take[takeCount++];  				if ((c->_com = (SnCom)takeEnum(Snail::_comText, strtok(NULL, " \t,;/"))) < 0)  					error("Bad NEAR in %d [%s]", lcnt, fname);  				c->_ref = atoi(strtok(NULL, " \t,;/")); @@ -307,14 +310,14 @@ Sprite *Sprite::expand() {  		}  	} else {  		// no sprite description: try to read immediately from .BMP -		shplist[shpcnt++] = new Bitmap(_file); +		shplist[shapeCount++] = new Bitmap(_file);  	} -	shplist[shpcnt] = NULL; +	shplist[shapeCount] = NULL;  	if (seq) { -		if (maxnow >= shpcnt) +		if (maxnow >= shapeCount)  			error("Bad PHASE in SEQ [%s]", fname); -		if (maxnxt >= seqcnt) +		if (maxnxt >= seqCount)  			error("Bad JUMP in SEQ [%s]", fname);  		setSeq(seq);  	} else @@ -327,12 +330,12 @@ Sprite *Sprite::expand() {  	setShapeList(shapeList); -	if (nea) -		nea[neacnt - 1]._ptr = _ext->_near = nea; +	if (near) +		near[nearCount - 1]._ptr = _ext->_near = near;  	else  		_nearPtr = kNoPtr; -	if (tak) -		tak[takcnt - 1]._ptr = _ext->_take = tak; +	if (take) +		take[takeCount - 1]._ptr = _ext->_take = take;  	else  		_takePtr = kNoPtr; | 
