2000-11-17 22:36:13 +01:00
|
|
|
/*****************/
|
2000-11-02 16:46:17 +01:00
|
|
|
/*** Map Stuph ***/
|
|
|
|
/*****************/
|
|
|
|
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
2000-12-04 17:47:34 +01:00
|
|
|
#include <Vector3.h>
|
2000-11-03 23:40:41 +01:00
|
|
|
#include <gl\gl.h>
|
|
|
|
#include <gl\glu.h>
|
|
|
|
|
2000-11-02 16:46:17 +01:00
|
|
|
#include "Map.h"
|
|
|
|
|
|
|
|
|
2000-11-20 21:33:42 +01:00
|
|
|
/*****************************************************************************/
|
2001-01-23 22:53:48 +01:00
|
|
|
void CMap::Load(CFile *File,int Version)
|
2000-11-20 21:33:42 +01:00
|
|
|
{
|
|
|
|
// Version 1
|
|
|
|
int Width;
|
|
|
|
int Height;
|
2001-03-05 21:49:46 +01:00
|
|
|
int VFix=0; // Fix for New tileset shash
|
2001-01-23 22:53:48 +01:00
|
|
|
|
|
|
|
if (Version<2) VFix=1;
|
2000-11-20 21:33:42 +01:00
|
|
|
|
|
|
|
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));
|
2001-01-23 22:53:48 +01:00
|
|
|
ThisElem.Set+=VFix;
|
2001-03-05 21:49:46 +01:00
|
|
|
if (Version==3)
|
|
|
|
{
|
|
|
|
ThisElem.Set--;
|
|
|
|
if (ThisElem.Set<0)
|
|
|
|
{
|
|
|
|
ThisElem.Set=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-11 22:29:59 +01:00
|
|
|
Set(X,Y,ThisElem,TRUE);
|
2000-11-20 21:33:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
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()
|
|
|
|
{
|
2001-01-02 15:34:02 +01:00
|
|
|
int Width=GetWidth();
|
|
|
|
int Height=GetHeight();
|
2000-11-17 22:36:13 +01:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2000-12-29 23:20:38 +01:00
|
|
|
void CMap::Set(CMap &Src,CRect &Rect,BOOL Force)
|
|
|
|
{
|
|
|
|
Set(Src,Rect.left,Rect.top,Rect.Width(),Rect.Height(),Force);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
void CMap::MirrorX(int Flag,CRect *R)
|
2000-11-17 22:36:13 +01:00
|
|
|
{
|
|
|
|
CMap Old=*this;
|
|
|
|
|
2000-12-29 23:20:38 +01:00
|
|
|
if (!R)
|
|
|
|
{ // No rect, use full
|
|
|
|
R=new CRect(0,0,GetWidth(),GetHeight());
|
|
|
|
}
|
2000-11-17 22:36:13 +01:00
|
|
|
|
2000-12-29 23:20:38 +01:00
|
|
|
int Ofs=(R->right+R->left)-1;
|
|
|
|
for (int Y=R->top; Y<R->bottom; Y++)
|
2000-11-17 22:36:13 +01:00
|
|
|
{
|
2000-12-29 23:20:38 +01:00
|
|
|
for (int X=R->left; X<R->right; X++)
|
2000-11-17 22:36:13 +01:00
|
|
|
{
|
|
|
|
sMapElem &ThisElem=Old.Get(X,Y);
|
|
|
|
ThisElem.Flags^=Flag;
|
2000-12-29 23:20:38 +01:00
|
|
|
Set(Ofs-X,Y,ThisElem,true);
|
2000-11-17 22:36:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2000-12-29 23:20:38 +01:00
|
|
|
void CMap::MirrorY(int Flag,CRect *R)
|
2000-11-17 22:36:13 +01:00
|
|
|
{
|
|
|
|
CMap Old=*this;
|
|
|
|
|
2000-12-29 23:20:38 +01:00
|
|
|
if (!R)
|
|
|
|
{ // No rect, use full
|
|
|
|
R=new CRect(0,0,GetWidth(),GetHeight());
|
|
|
|
}
|
2000-11-17 22:36:13 +01:00
|
|
|
|
2000-12-29 23:20:38 +01:00
|
|
|
int Ofs=(R->bottom+R->top)-1;
|
|
|
|
for (int Y=R->top; Y<R->bottom; Y++)
|
2000-11-17 22:36:13 +01:00
|
|
|
{
|
2000-12-29 23:20:38 +01:00
|
|
|
for (int X=R->left; X<R->right; X++)
|
2000-11-17 22:36:13 +01:00
|
|
|
{
|
|
|
|
sMapElem &ThisElem=Old.Get(X,Y);
|
|
|
|
ThisElem.Flags^=Flag;
|
2000-12-29 23:20:38 +01:00
|
|
|
Set(X,Ofs-Y,ThisElem,true);
|
2000-11-17 22:36:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-20 16:57:03 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
void CMap::SetFlags(int Flags,int Mask,CRect *R)
|
|
|
|
{
|
|
|
|
if (!R)
|
|
|
|
{ // No rect, use full
|
|
|
|
R=new CRect(0,0,GetWidth(),GetHeight());
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int Y=R->top; Y<R->bottom; Y++)
|
|
|
|
{
|
|
|
|
for (int X=R->left; X<R->right; X++)
|
|
|
|
{
|
|
|
|
sMapElem &ThisElem=Get(X,Y);
|
|
|
|
ThisElem.Flags&=Mask;
|
|
|
|
ThisElem.Flags|=Flags;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-01-02 15:34:02 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
void CMap::Paste(CMap &Src,CRect *R)
|
|
|
|
{
|
|
|
|
if (!R)
|
|
|
|
{ // No rect, use full
|
|
|
|
R=new CRect(0,0,GetWidth(),GetHeight());
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int Y=0; Y<R->Height(); Y++)
|
|
|
|
{
|
|
|
|
for (int X=0; X<R->Width(); X++)
|
|
|
|
{
|
|
|
|
int SrcX=X % Src.GetWidth();
|
|
|
|
int SrcY=Y % Src.GetHeight();
|
|
|
|
sMapElem &ThisElem=Src.Get(SrcX,SrcY);
|
|
|
|
|
|
|
|
Set(X+R->left,Y+R->top,ThisElem,true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-11-17 22:36:13 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
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
|
|
|
|
|
|
|
/*****************************************************************************/
|
2001-03-05 21:49:46 +01:00
|
|
|
void CMap::RemoveSet(int Set)
|
2000-11-29 18:07:57 +01:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|