Jump to content
SSForum.net is back!

Recommended Posts

Posted

-*BAD WORD*-o everybody,

 

I got a problem. I am trying to make a bot which is able to write a .lvl file. I have found the .lvl file format here. ( <-- Click on 'here')

 

This is what I got so far and I thought would work

 

 	if (c->check("makefile")) {
   int tile = 5;
   int x = 5;
   int y = 5;

   fstream myFile ("test.lvl", ios::in | ios::out | ios::binary);
   myFile.write ((char *)&tile, 8);
   myFile.write ((char *)&y, 12);
   myFile.write ((char *)&x, 12);
   myFile.close();
 	}

 

but SSME doesn't accept it.

 

http://home.hccnet.nl/ton.werdler/ssme%20error.png

 

 

 

Can someone help me with this?

 

Thanks

-MMaverick B)

Check out your zone population statistics at stats.sshq.net!

 

 

Maverick

Subspace Statistics Administrator

Retired SSCU Trench Wars Super Moderator

TWCore Coordinator Administrator

Posted

Hmmm. 50% Packetloss told me of this link:

http://www.forumhq.net/forums/index.php?showtopic=548

 

Though it only has a piece of code on how to read a .lvl file, not to write them. He also informed me of the map.h file of Mervbot, it has the following functions:

 

Uint32 getLinear(Uint32 x, Uint32 y);       	 // Convert rectangular coords to linear coords

struct tileData
{
Uint16 x, y;              // Coordinates
BYTE type;             	 // Type
};

Sint32 getNumeric(Sint32 y);
char getAlpha(Sint32 x);
String getCoords(Sint32 x, Sint32 y);

tileData makeTileData(Uint32 raw);          // File data is in blocks of 32 bits
Uint32 makeTileData(Uint16 x, Uint16 y, BYTE type);      // Produce just such a block

void convertFileToMatrix(char *fileData, char *mapData, Uint32 len);	// Convert from disk to memory format

Uint32 getMapSize(char *mapData);          // Retrieve the length of the map on disk
void convertMatrixToFile(char *mapData, char *_fileData);    // Convert the map to disk format

 

I don't know how to do the job with these functions.

 

Any help is appreciated

 

-MMaverick B)

Check out your zone population statistics at stats.sshq.net!

 

 

Maverick

Subspace Statistics Administrator

Retired SSCU Trench Wars Super Moderator

TWCore Coordinator Administrator

Posted

The problem is that the lengths are supposed to be in bits but your writing code has them in bytes. Either do some bit-shifting or stick em in a bit-ized struct.

By the way, did you notice that your { accidentally got on the first line instaed of the second one? :wub:

Posted
#include <fstream.h>
typedef unsigned long  Uint32;

int main ()
{ 
char buf[4];//the char array
Uint32 *data=(Uint32*)buf;//pointer to the array

int tile=1;//info we want in file
int x=5;
int y=5;

ofstream file("test.lvl", ios::binary);//open a file in binary mode

if (file.good())//if the file open was successful
{
 *data = ((tile & 0xFF) << 24) | ((y & 0x3FF) << 12) | (x & 0x3FF);
//^^^^--pushes data into the array, If you know the data is good then you dont need the bitwise &
 file.write(buf, 4);//write
}

file.close();
return 0;
}

Guest
This topic is now closed to further replies.
×
×
  • Create New...