/*========================================================================= EXPORT.CPP Author: Created: Project: Purpose: Copyright (c) 1998 Climax Development Ltd ===========================================================================*/ /*---------------------------------------------------------------------- Includes -------- */ /* Std Lib ------- */ #include "mapread.h" /* Glib ---- */ #include /* Local ----- */ /* Graphics -------- */ /*---------------------------------------------------------------------- Tyepdefs && Defines ------------------- */ #define TILE_SHIFT 8 /*---------------------------------------------------------------------- Structure defintions -------------------- */ /*---------------------------------------------------------------------- Positional Vars --------------- */ /*---------------------------------------------------------------------- Function Prototypes ------------------- */ /*---------------------------------------------------------------------- Vars ---- */ /*---------------------------------------------------------------------- Data ---- */ /*---------------------------------------------------------------------- Function: Purpose: Params: Returns: ---------------------------------------------------------------------- */ int CMapFile::GetVersion( char * version ) { int ret = 0; int len; char whole[8]; char frac[8]; len = strlen(version); if (len) { int pos = 0; int opos = 0; while (version[pos] != '.') { whole[pos] = version[pos]; pos++; if (pos > len) GObject::Error(ERR_FATAL,"Corrupt Version - %s\n", version); } pos++; while (version[pos]) { frac[opos] = version[pos]; pos++; opos++; if (pos > len) GObject::Error(ERR_FATAL,"Corrupt Version - %s\n", version); } } ret = atoi( whole ); ret *= 100; ret += atoi( frac ); GObject::Error(ERR_WARNING, "Map Version %d\n", ret ); return ret; } /*---------------------------------------------------------------------- Function: Purpose: Params: Returns: ---------------------------------------------------------------------- */ int CMapFile::FindFrame( const char * frame ) { char InFile[_MAX_FNAME]; char CompFile[_MAX_FNAME]; _splitpath( frame, NULL, NULL, InFile, NULL ); for (int f=0;f sizeof(MapCTile)) GObject::Error(ERR_FATAL, "MapCTile STRUCT MISMATCH" ); Tiles = (TILE_PACKET *)malloc( (MapWidth * MapHeight * sizeof( TILE_PACKET )) ); if (!Tiles) GObject::Error(ERR_FATAL, "can't allocate tiles" ); t = Tiles; nbSpawnPoints=0; lowestY = 65536; for (y=0;yframe = tile.frame; t->r = (u8)(tile.r * 255.f); t->g = (u8)(tile.g * 255.f); t->b = (u8)(tile.b * 255.f); t->pad = 0; if (tile.flag&TF_SPAWN) { if (nbSpawnPoints>=MAX_SPAWNING_TILES) { GObject::Error(ERR_FATAL, "Max Spawning Positions exceeded for level" ); } Spawn[nbSpawnPoints].x = x; Spawn[nbSpawnPoints].y = y; nbSpawnPoints++; } t->angle = angle; t->flags = (int)(tile.flag&(~TF_SPAWN)); t->height = (int)tile.py; t->frame = frame; t->xflip = tile.xflip; t->yflip = tile.yflip; t->type = tile.type; // if (t->flags & TF_NO_BUILD) // GObject::Error(ERR_WARNING, "No build flag found\n" ); if (frame < 0) t->flags |= TF_HIDDEN; if (!(tile.flag & TF_HIDDEN) && (x < MapWidth-1) && (y < MapHeight-1)) { if (lowestY > tile.py) lowestY = tile.py; } t++; } } GObject::Error( ERR_WARNING, "Lowest land height = %f\n", lowestY ); t = Tiles; for (y=0;yheight -= (int)lowestY; if (t->height < 0) t->height = 0; // if (t->height > sizeof(u16)) // { // GObject::Error( ERR_FATAL, "Land height overflow - %d\n", t->height ); // } t++; } } // READ OBJECT LIST MapFile.Read( &nbModels ); MapFile.Read( &ModelSize ); if (ModelSize > sizeof(CModel)) GObject::Error(ERR_FATAL, "Struct mismatch in CModel" ); Models = (MODEL_PACKET *)malloc( nbModels * sizeof(MODEL_PACKET) ); if (!Models) GObject::Error(ERR_FATAL, "Can't allocate models\n" ); MODEL_PACKET * m = Models; for (i=0;iAnimAndFlags = animflag; m->xp = (u16)(model.PosX / (1 << TILE_SHIFT)); m->yp = (u16)(model.PosY - lowestY); m->zp = (u16)(model.PosZ / (1 << TILE_SHIFT)); m->ya = (u16)angle; // if (m->yp > sizeof(u16)) // { // GObject::Error( ERR_FATAL, "Object Y position overflow - %d\n", m->yp ); // } m++; } } /*---------------------------------------------------------------------- Function: Purpose: Params: Returns: ---------------------------------------------------------------------- */ int CMapFile::FindFileEquate( char * name ) { strupr( name ); for (int i=0;i SourcePal; vector DestPal; SourcePal.resize(MapWidth*MapHeight*3); TileToPalNum.resize(MapWidth*MapHeight); DestPal.resize(NUM_OF_PAL_ENTRIES*3); MapPal.resize(NUM_OF_PAL_ENTRIES); for (int f=0;fmType = 0; if (T->height<0) { O->ypos = 0; // printf("low height %d\n", T->height); } else if (T->height>255*4.f) { O->ypos = 255; // printf("hi height %d\n", T->height); } else { O->ypos = (T->height/4.f); } O->mNeighbours = 0; O->mDirection = 0; if (T->frame > 4095) GObject::Error(ERR_FATAL, "Tile index overflow" ); O->mTileIndex = T->frame; O->mTileIndex |= (T->angle << 12); // STUFF ANGLE IN TOP BITS OF TILE INDEX O->ColIdx = GetPalNum( x, y ); O->mFlags = T->flags; if (T->xflip) O->mTileIndex |= (1 << 15); // SET X/Y FLIP IN TOP BITS OF TILE INDEX if (T->yflip) O->mTileIndex |= (1 << 14); switch(T->type) { case TT_VOID: O->mType = (u8)CELL_Void; break; case TT_PATH: O->mType = (u8)CELL_Path; break; } } /*---------------------------------------------------------------------- Function: Purpose: Params: Returns: ---------------------------------------------------------------------- */ void CMapFile::Export( const char * file ) { FILE * level; MakeMapPalette(); level = fopen( file, "wb" ); if (level) { WriteMapPalette( level ); fwrite( &MapWidth, sizeof( int ), 1, level ); fwrite( &MapHeight, sizeof( int ), 1, level ); for (int y=0;y