SBSPSS/Utils/MapEdit/Map.cpp

299 lines
5.7 KiB
C++
Raw Normal View History

2000-11-17 22:36:13 +01:00
/*****************/
2000-11-02 16:46:17 +01:00
/*** Map Stuph ***/
/*****************/
#include "stdafx.h"
2000-11-03 23:40:41 +01:00
#include "gl3d.h"
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glut.h>
2000-11-02 16:46:17 +01:00
#include "Map.h"
2000-11-20 21:33:42 +01:00
/*****************************************************************************/
void CMap::Load(CFile *File,float Version)
{
// Version 1
int Width;
int Height;
File->Read(&Width,sizeof(int));
File->Read(&Height,sizeof(int));
Delete();
SetSize(Width,Height);
for (int Y=0;Y<Height;Y++)
{
for (int X=0;X<Width;X++)
{
sMapElem ThisElem;
File->Read(&ThisElem,sizeof(sMapElem));
Set(X,Y,ThisElem);
}
}
}
/*****************************************************************************/
void CMap::Save(CFile *File)
{
int Width=GetWidth();
int Height=GetHeight();
File->Write(&Width,sizeof(int));
File->Write(&Height,sizeof(int));
for (int Y=0;Y<Height;Y++)
{
for (int X=0;X<Width;X++)
{
sMapElem &ThisElem=Get(X,Y);
File->Write(&ThisElem,sizeof(sMapElem));
}
}
}
2000-11-02 16:46:17 +01:00
/*****************************************************************************/
2000-11-17 22:36:13 +01:00
void CMap::SetSize(int Width,int Height,BOOL ClearFlag)
2000-11-02 16:46:17 +01:00
{
Map.resize(Width);
for (int i=0;i<Width;i++)
{
Map[i].resize(Height);
}
2000-11-17 22:36:13 +01:00
if (ClearFlag) Clear();
}
/*****************************************************************************/
void CMap::Clear()
{
int Width=GetWidth();
int Height=GetHeight();
2000-11-15 22:22:40 +01:00
for (int Y=0;Y<Height;Y++)
2000-11-17 00:08:54 +01:00
{
2000-11-15 22:22:40 +01:00
for (int X=0;X<Width;X++)
{
Map[X][Y].Set=0;
2000-11-17 00:08:54 +01:00
Map[X][Y].Flags=0;
2000-11-15 22:22:40 +01:00
Map[X][Y].Tile=0;
}
2000-11-17 00:08:54 +01:00
}
2000-11-02 16:46:17 +01:00
}
/*****************************************************************************/
void CMap::SetWidth(int Width)
{
}
/*****************************************************************************/
void CMap::SetHeight(int Height)
{
}
2000-11-17 22:36:13 +01:00
/*****************************************************************************/
int CMap::GetWidth()
{
return(Map.size());
}
2000-11-02 16:46:17 +01:00
2000-11-15 22:22:40 +01:00
/*****************************************************************************/
2000-11-17 22:36:13 +01:00
int CMap::GetHeight()
2000-11-15 22:22:40 +01:00
{
2000-11-17 22:36:13 +01:00
if (GetWidth())
{
return(Map[0].size());
}
return(0);
}
2000-11-15 22:22:40 +01:00
2000-11-17 22:36:13 +01:00
/*****************************************************************************/
void CMap::Delete()
{
int Width=GetWidth();
for (int i=0;i<Width;i++)
{
Map[i].clear();
}
Map.clear();
}
2000-11-15 22:22:40 +01:00
2000-11-17 22:36:13 +01:00
/*****************************************************************************/
sMapElem &CMap::Get(int X,int Y)
{
return(Map[X][Y]);
2000-11-15 22:22:40 +01:00
}
/*****************************************************************************/
2000-11-29 18:07:57 +01:00
void CMap::Set(int X,int Y,sMapElem &Blk,BOOL Force)
2000-11-15 22:22:40 +01:00
{
2000-11-17 22:36:13 +01:00
int Width=GetWidth();
int Height=GetHeight();
2000-11-29 18:07:57 +01:00
if (!Force) // if bank or tile invalid
if (Blk.Set==-1 || Blk.Tile==-1) return;
2000-11-17 22:36:13 +01:00
// Make sure within map
if ((X>=0 && X<Width) && (Y>=0 && Y<Height))
{
Map[X][Y]=Blk;
2000-11-28 22:28:47 +01:00
if (Blk.Tile==0)
{ // Only use one zero tile
Map[X][Y].Set=0;
}
2000-11-17 22:36:13 +01:00
}
2000-11-15 22:22:40 +01:00
}
2000-11-02 16:46:17 +01:00
/*****************************************************************************/
2000-11-29 18:07:57 +01:00
void CMap::Set(int StartX,int StartY,CMap &Blk,BOOL Force)
2000-11-15 22:22:40 +01:00
{
2000-11-17 22:36:13 +01:00
int Width=Blk.GetWidth();
int Height=Blk.GetHeight();
for (int Y=0; Y<Height; Y++)
{
for (int X=0; X<Width; X++)
{
2000-11-29 18:07:57 +01:00
Set(StartX+X,StartY+Y,Blk.Get(X,Y),Force);
2000-11-17 22:36:13 +01:00
}
}
2000-11-15 22:22:40 +01:00
}
2000-11-02 16:46:17 +01:00
2000-11-17 22:36:13 +01:00
/*****************************************************************************/
2000-11-29 18:07:57 +01:00
void CMap::Set(CMap &Src,int StartX,int StartY,int Width,int Height,BOOL Force)
2000-11-17 22:36:13 +01:00
{
Delete();
SetSize(Width,Height);
for (int Y=0; Y<Height; Y++)
{
for (int X=0; X<Width; X++)
{
2000-11-29 18:07:57 +01:00
Set(X,Y,Src.Get(StartX+X,StartY+Y),Force);
2000-11-17 22:36:13 +01:00
}
}
}
/*****************************************************************************/
void CMap::MirrorX(int Flag)
{
CMap Old=*this;
int Width=GetWidth();
int Height=GetHeight();
for (int Y=0; Y<Height; Y++)
{
for (int X=0; X<Width; X++)
{
sMapElem &ThisElem=Old.Get(X,Y);
ThisElem.Flags^=Flag;
Set((Width-1)-X,Y,ThisElem);
}
}
}
/*****************************************************************************/
void CMap::MirrorY(int Flag)
{
CMap Old=*this;
int Width=GetWidth();
int Height=GetHeight();
for (int Y=0; Y<Height; Y++)
{
for (int X=0; X<Width; X++)
{
sMapElem &ThisElem=Old.Get(X,Y);
ThisElem.Flags^=Flag;
Set(X,(Height-1)-Y,ThisElem);
}
}
}
/*****************************************************************************/
BOOL CMap::DoesContainTile(sMapElem &Tile)
{
int Width=GetWidth();
int Height=GetHeight();
for (int Y=0; Y<Height; Y++)
{
for (int X=0; X<Width; X++)
{
sMapElem &ThisElem=Get(X,Y);
2000-11-28 22:28:47 +01:00
if (ThisElem.Tile==Tile.Tile)
if (ThisElem.Set==Tile.Set || Tile.Tile==0) return(TRUE);
2000-11-17 22:36:13 +01:00
}
}
return(FALSE);
}
/*****************************************************************************/
2000-11-20 17:21:43 +01:00
void CMap::Resize(int Width,int Height)
{
CMap Old=*this;
int OldWidth=Old.GetWidth();
int OldHeight=Old.GetHeight();
int MinW=min(Width,OldWidth);
int MinH=min(Height,OldHeight);
2000-11-17 22:36:13 +01:00
2000-11-20 17:21:43 +01:00
Delete();
SetSize(Width,Height,TRUE);
for (int Y=0; Y<MinH; Y++)
{
for (int X=0; X<MinW; X++)
{
Set(X,Y,Old.Get(X,Y));
}
}
}
2000-11-29 18:07:57 +01:00
/*****************************************************************************/
void CMap::DeleteSet(int Set)
{
int Width=GetWidth();
int Height=GetHeight();
for (int Y=0; Y<Height; Y++)
{
for (int X=0; X<Width; X++)
{
sMapElem &ThisElem=Get(X,Y);
if (ThisElem.Set==Set)
{
ThisElem.Set=0;
ThisElem.Tile=0;
ThisElem.Flags=0;
}
}
}
}
/*****************************************************************************/
void CMap::RemapSet(int Old,int New)
{
int Width=GetWidth();
int Height=GetHeight();
for (int Y=0; Y<Height; Y++)
{
for (int X=0; X<Width; X++)
{
sMapElem &ThisElem=Get(X,Y);
if (ThisElem.Set==Old)
{
ThisElem.Set=New;
}
}
}
}