SBSPSS/Utils/MapEdit/LayerThing.cpp

756 lines
18 KiB
C++
Raw Normal View History

2001-03-22 21:49:58 +01:00
/*******************/
/*** Layer Thing ***/
/*******************/
2001-03-21 00:06:17 +01:00
#include "stdafx.h"
#include <Vector3.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include "GLEnabledView.h"
#include "MapEdit.h"
#include "MapEditDoc.h"
#include "MapEditView.h"
#include "MainFrm.h"
#include "Core.h"
#include "Layer.h"
2001-03-22 21:49:58 +01:00
#include "LayerThing.h"
2001-03-21 00:06:17 +01:00
#include "Utils.h"
#include "Export.h"
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2001-03-26 23:29:09 +02:00
CLayerThing::CLayerThing(sLayerDef &Def)
2001-03-21 00:06:17 +01:00
{
2001-03-26 23:29:09 +02:00
InitLayer(Def);
2001-03-21 00:06:17 +01:00
}
/*****************************************************************************/
2001-03-22 21:49:58 +01:00
CLayerThing::~CLayerThing()
2001-03-21 00:06:17 +01:00
{
2001-03-22 21:49:58 +01:00
ThingBank->CleanUp();
delete ThingBank;
2001-03-21 00:06:17 +01:00
}
2001-03-26 23:29:09 +02:00
/*****************************************************************************/
void CLayerThing::InitLayer(sLayerDef &Def)
{
2001-03-29 19:59:01 +02:00
CLayer::InitLayer(Def);
2001-03-26 23:29:09 +02:00
Mode=MouseModeNormal;
2001-03-29 19:59:01 +02:00
Cursor.XY.resize(1);
Cursor.ElemID=-1;
CurrentDefThing=-1;
2001-03-26 23:29:09 +02:00
CurrentThing=-1;
2001-03-29 19:59:01 +02:00
CurrentThingPoint=0;
2001-03-31 17:40:20 +02:00
DrawPoints=true;
2001-03-26 23:29:09 +02:00
}
2001-03-21 00:06:17 +01:00
/*****************************************************************************/
2001-03-22 21:49:58 +01:00
void CLayerThing::Load(CFile *File,int Version)
2001-03-21 00:06:17 +01:00
{
2001-03-29 19:59:01 +02:00
int i,ListSize;
2001-03-21 00:06:17 +01:00
File->Read(&Mode,sizeof(MouseMode));
2001-03-29 19:59:01 +02:00
File->Read(&CurrentDefThing,sizeof(int));
File->Read(&CurrentThing,sizeof(int));
File->Read(&CurrentThingPoint,sizeof(int));
File->Read(&ListSize,sizeof(int));
ThingList.resize(ListSize);
// Load Data
for (i=0;i<ListSize;i++)
{
sLayerThing &ThisThing=ThingList[i];
LoadThing(File,Version,ThisThing);
File->Read(&ThisThing.Data,sizeof(sLayerThingData));
}
LoadThingNames(File,Version);
2001-04-05 16:20:56 +02:00
2001-03-29 19:59:01 +02:00
}
/*****************************************************************************/
void CLayerThing::LoadThing(CFile *File,int Version,sLayerThing &ThisThing)
{
int i,ListSize;
File->Read(&ListSize,sizeof(int));
ThisThing.XY.resize(ListSize);
for (i=0 ;i<ListSize; i++)
{
2001-04-05 16:20:56 +02:00
CPoint &ThisPoint=ThisThing.XY[i];
File->Read(&ThisPoint,sizeof(CPoint));
2001-03-29 19:59:01 +02:00
}
}
/*****************************************************************************/
void CLayerThing::LoadThingNames(CFile *File,int Version)
{
int i,ListSize=ThingList.size();
for (i=0;i<ListSize;i++)
{
char c=1;
sLayerThing &ThisThing=ThingList[i];
GString &ThisName=ThisThing.Name;
while (c)
{
File->Read(&c,1);
ThisName.Append(c);
}
// Update Gfx ID
int Idx=FindDefThing(ThisName);
ThisThing.ElemID=DefList[Idx].ElemID;
}
2001-03-21 00:06:17 +01:00
}
/*****************************************************************************/
2001-03-22 21:49:58 +01:00
void CLayerThing::Save(CFile *File)
2001-03-21 00:06:17 +01:00
{
2001-03-29 19:59:01 +02:00
int i,ListSize=ThingList.size();
2001-03-21 00:06:17 +01:00
// Always Save current version
File->Write(&Mode,sizeof(MouseMode));
2001-03-29 19:59:01 +02:00
File->Write(&CurrentDefThing,sizeof(int));
File->Write(&CurrentThing,sizeof(int));
File->Write(&CurrentThingPoint,sizeof(int));
File->Write(&ListSize,sizeof(int));
for (i=0;i<ListSize; i++)
{
sLayerThing &ThisThing=ThingList[i];
SaveThing(File,ThisThing);
File->Write(&ThisThing.Data,sizeof(sLayerThingData));
}
SaveThingNames(File);
}
/*****************************************************************************/
void CLayerThing::SaveThing(CFile *File,sLayerThing &ThisThing)
{
int i,ListSize=ThisThing.XY.size();
File->Write(&ListSize,sizeof(int));
for (i=0 ;i<ListSize; i++)
2001-04-05 16:20:56 +02:00
{
CPoint &ThisPoint=ThisThing.XY[i];
File->Write(&ThisPoint,sizeof(CPoint));
2001-03-29 19:59:01 +02:00
}
}
/*****************************************************************************/
void CLayerThing::SaveThingNames(CFile *File)
{
int i,ListSize=ThingList.size();
for (i=0; i<ListSize; i++)
{
char Txt[256];
sprintf(Txt,ThingList[i].Name);
File->Write(Txt,strlen(Txt)+1);
}
2001-03-21 00:06:17 +01:00
}
/*****************************************************************************/
2001-03-22 21:49:58 +01:00
void CLayerThing::InitSubView(CCore *Core)
2001-03-21 00:06:17 +01:00
{
}
2001-03-26 23:29:09 +02:00
/*****************************************************************************/
void CLayerThing::LoadThingScript(const char *Filename)
{
2001-03-31 03:30:53 +02:00
GString ExecPath;
GString ScriptName;
GetExecPath(ExecPath);
ScriptName=ExecPath+Filename;
ThingScript.LoadAndImport(ScriptName);
2001-03-29 19:59:01 +02:00
int i,ListSize=ThingScript.GetGroupCount();
DefList.resize(ListSize);
for (i=0; i<ListSize; i++)
{
sLayerThing &ThisDef=DefList[i];
char *Name=ThingScript.GetGroupName(i);
char *Gfx=ThingScript.GetStr(Name,"gfx");
2001-04-07 23:05:33 +02:00
memset(&ThisDef.Data,0,sizeof(sLayerThingData));
2001-03-29 19:59:01 +02:00
ThisDef.Name=Name;
2001-04-07 23:05:33 +02:00
ThisDef.Data.WaypointCount=ThingScript.GetInt(Name,"WayPoints");
2001-03-29 19:59:01 +02:00
ThisDef.Data.Speed=ThingScript.GetInt(Name,"Speed");
ThisDef.Data.TurnRate=ThingScript.GetInt(Name,"TurnRate");
ThisDef.Data.Health=ThingScript.GetInt(Name,"Health");
ThisDef.Data.AttackStrength=ThingScript.GetInt(Name,"AttackStrength");
ThisDef.Data.PlayerFlag=ThingScript.GetInt(Name,"Player")==1;
ThisDef.Data.CollisionFlag=ThingScript.GetInt(Name,"Collision")==1;
ThisDef.XY.resize(1);
TRACE2("%s\t\t%s\n",Name,Gfx);
if (Gfx)
{
2001-03-31 03:30:53 +02:00
char Filename[512];
GFName::makeabsolute(ExecPath,Gfx,Filename);
ThisDef.ElemID=ThingBank->AddSet(Filename);
2001-03-29 19:59:01 +02:00
}
}
2001-03-26 23:29:09 +02:00
}
2001-03-21 00:06:17 +01:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
2001-03-22 21:49:58 +01:00
void CLayerThing::Render(CCore *Core,Vector3 &CamPos,bool Is3d)
2001-03-21 00:06:17 +01:00
{
Vector3 ThisCam=Core->OffsetCam(CamPos,GetScaleFactor());
2001-03-22 21:49:58 +01:00
int i,ListSize=ThingList.size();
2001-03-29 19:59:01 +02:00
2001-03-22 21:49:58 +01:00
for (i=0; i<ListSize; i++)
2001-03-21 00:06:17 +01:00
{
2001-03-22 21:49:58 +01:00
RenderThing(Core,ThisCam,ThingList[i],Is3d,i==CurrentThing);
2001-03-21 00:06:17 +01:00
}
}
/*****************************************************************************/
2001-03-22 21:49:58 +01:00
void CLayerThing::RenderThing(CCore *Core,Vector3 &ThisCam,sLayerThing &ThisThing,bool Render3d,bool Selected)
2001-03-21 00:06:17 +01:00
{
float ZoomW=Core->GetZoomW();
float ZoomH=Core->GetZoomH();
Vector3 &Scale=Core->GetScaleVector();
2001-03-31 03:30:53 +02:00
Vector3 ScrOfs(ZoomW/2,ZoomH/2,0);
if (Render3d)
{
ScrOfs.z=-4.0f;
}
2001-03-21 00:06:17 +01:00
2001-03-22 21:49:58 +01:00
if (ThingBank->NeedLoad()) ThingBank->LoadAllSets(Core);
2001-03-21 00:06:17 +01:00
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glScalef(Scale.x,Scale.y,Scale.z);
2001-03-22 21:49:58 +01:00
glTranslatef(-ThisCam.x,ThisCam.y,0); // Set scroll offset
2001-03-31 03:30:53 +02:00
glTranslatef(-ScrOfs.x,ScrOfs.y,0); // Bring to top left corner
2001-03-22 21:49:58 +01:00
int ListSize=ThisThing.XY.size();
for (int i=0;i<ListSize; i++)
{
// Render Thing
glPushMatrix();
glTranslatef(ThisThing.XY[i].x,-ThisThing.XY[i].y,0); // Set Pos
if (i==0)
{
glColor4f(1,1,1,1); // Set default Color
2001-03-31 03:30:53 +02:00
glEnable(GL_DEPTH_TEST);
glTranslatef(0,0,ScrOfs.z);
2001-03-29 19:59:01 +02:00
ThingBank->RenderElem(ThisThing.ElemID,0,0,Render3d);
2001-03-31 03:30:53 +02:00
glDisable(GL_DEPTH_TEST);
2001-03-31 17:40:20 +02:00
glTranslatef(0,0,-ScrOfs.z);
if (Selected)
glColor4f(1,1,0,0.8f);
else
glColor4f(1,1,0,0.5f);
if (DrawPoints) Core->RenderNumber(i);
}
else
{
if (Selected)
glColor4f(1,1,1,1); // Set default Color
else
glColor4f(1,1,1,0.5);
if (DrawPoints) Core->RenderNumber(i);
2001-03-22 21:49:58 +01:00
}
glPopMatrix();
}
2001-03-21 00:06:17 +01:00
glPopMatrix();
}
/*****************************************************************************/
/*** Gui *********************************************************************/
/*****************************************************************************/
2001-03-22 21:49:58 +01:00
void CLayerThing::GUIInit(CCore *Core)
2001-03-21 00:06:17 +01:00
{
}
/*****************************************************************************/
2001-03-22 21:49:58 +01:00
void CLayerThing::GUIKill(CCore *Core)
2001-03-21 00:06:17 +01:00
{
}
/*****************************************************************************/
2001-03-22 21:49:58 +01:00
void CLayerThing::GUIUpdate(CCore *Core)
2001-03-21 00:06:17 +01:00
{
}
/*****************************************************************************/
2001-03-22 21:49:58 +01:00
void CLayerThing::GUIChanged(CCore *Core)
2001-03-21 00:06:17 +01:00
{
}
2001-03-31 17:40:20 +02:00
/*****************************************************************************/
void CLayerThing::GUIThingUpdateList(CComboBox &List,bool OnlySel)
{
int i,ListSize;
if (!OnlySel)
{
// Setup ThingList
ListSize=ThingList.size();
List.ResetContent();
for (i=0; i<ListSize; i++)
{
List.AddString(ThingList[i].Name);
}
}
List.SetCurSel(CurrentThing);
}
/*****************************************************************************/
void CLayerThing::GUIThingPointUpdateList(CListBox &List,bool OnlySel)
{
int i,ListSize;
if (!OnlySel)
{
// Setup ThingPointList
List.ResetContent();
if (CurrentThing==-1) return;
sLayerThing &ThisThing=ThingList[CurrentThing];
ListSize=ThisThing.XY.size();
for (i=0; i<ListSize; i++)
{
2001-04-05 16:20:56 +02:00
CPoint &ThisPoint=ThisThing.XY[i];
2001-03-31 17:40:20 +02:00
CString Str;
2001-04-05 16:20:56 +02:00
Str.Format("%i: %i, %i",i,ThisPoint.x,ThisPoint.y);
2001-03-31 17:40:20 +02:00
List.AddString(Str);
}
}
List.SetCurSel(CurrentThingPoint);
2001-04-05 16:20:56 +02:00
2001-03-31 17:40:20 +02:00
}
2001-03-21 00:06:17 +01:00
/*****************************************************************************/
/*** Functions ***************************************************************/
/*****************************************************************************/
2001-03-22 21:49:58 +01:00
bool CLayerThing::LButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag)
2001-03-21 00:06:17 +01:00
{
bool Ret=false;
2001-03-22 21:49:58 +01:00
2001-03-29 19:59:01 +02:00
if (!DownFlag) return(false);
2001-03-21 00:06:17 +01:00
switch(Mode)
{
2001-03-22 21:49:58 +01:00
case MouseModeNormal:
2001-03-29 19:59:01 +02:00
SelectThing(CursorPos);
break;
case MouseModeNew:
AddThing(CursorPos);
2001-03-21 00:06:17 +01:00
break;
2001-03-22 21:49:58 +01:00
case MouseModePoints:
2001-03-29 19:59:01 +02:00
AddThingPoint(CursorPos);
2001-03-21 00:06:17 +01:00
break;
default:
break;
}
2001-03-22 21:49:58 +01:00
return(true);
2001-03-21 00:06:17 +01:00
}
/*****************************************************************************/
2001-03-22 21:49:58 +01:00
bool CLayerThing::RButtonControl(CCore *Core,UINT nFlags, CPoint &CursorPos,bool DownFlag)
2001-03-21 00:06:17 +01:00
{
2001-03-29 19:59:01 +02:00
Cancel();
return(true);
2001-03-21 00:06:17 +01:00
}
/*****************************************************************************/
2001-03-22 21:49:58 +01:00
bool CLayerThing::MouseMove(CCore *Core,UINT nFlags, CPoint &CursorPos)
2001-03-21 00:06:17 +01:00
{
2001-03-22 21:49:58 +01:00
bool Ret=false;
if (CurrentThing!=-1)
2001-03-21 00:06:17 +01:00
{
2001-03-22 21:49:58 +01:00
if (nFlags & MK_LBUTTON) // Drag
{
2001-03-29 19:59:01 +02:00
UpdatePos(CursorPos,CurrentThing,CurrentThingPoint,(nFlags & MK_CONTROL)!=0);
2001-03-22 21:49:58 +01:00
Ret=true;
}
2001-03-21 00:06:17 +01:00
else
2001-03-22 21:49:58 +01:00
if (nFlags & MK_RBUTTON) // Cancel
{
2001-03-29 19:59:01 +02:00
Cancel();
2001-03-22 21:49:58 +01:00
Ret=true;
}
2001-03-21 00:06:17 +01:00
}
return(Ret);
}
2001-03-29 19:59:01 +02:00
/*****************************************************************************/
void CLayerThing::Cancel()
{
switch(Mode)
{
case MouseModeNormal:
CurrentThing=-1;
case MouseModeNew:
case MouseModePoints:
Mode=MouseModeNormal;
CurrentThingPoint=0;
GUIThingDefClear();
GUIThingUpdate();
2001-03-31 17:40:20 +02:00
GUIThingPointUpdate();
2001-03-29 19:59:01 +02:00
break;
default:
break;
}
}
2001-03-21 00:06:17 +01:00
/*****************************************************************************/
2001-03-22 21:49:58 +01:00
bool CLayerThing::Command(int CmdMsg,CCore *Core,int Param0,int Param1)
2001-03-21 00:06:17 +01:00
{
bool Ret=false;
2001-03-29 19:59:01 +02:00
2001-03-21 00:06:17 +01:00
switch(CmdMsg)
{
2001-03-29 19:59:01 +02:00
case CmdMsg_ThingListDelete:
DeleteThing();
break;
2001-04-07 23:05:33 +02:00
case CmdMsg_ThingListGoto:
GotoThing(Core);
break;
2001-03-29 19:59:01 +02:00
case CmdMsg_ThingListSelect:
CurrentDefThing=Param0;
SetCursor(DefList[CurrentDefThing].Name);
Mode=MouseModeNew;
break;
case CmdMsg_ThingLevelSelect:
SelectThing(Param0);
break;
case CmdMsg_ThingPosSelect:
CurrentThingPoint=Param0;
GUIThingPointUpdate();
break;
case CmdMsg_ThingPosUp:
MovePoint(-1);
break;
case CmdMsg_ThingPosDown:
MovePoint(+1);
break;
case CmdMsg_ThingPosDelete:
DeletePoint();
2001-03-21 00:06:17 +01:00
break;
default:
2001-03-22 21:49:58 +01:00
break;
2001-03-21 00:06:17 +01:00
}
2001-03-29 19:59:01 +02:00
2001-03-21 00:06:17 +01:00
return(Ret);
}
2001-03-29 19:59:01 +02:00
/*****************************************************************************/
int CLayerThing::FindDefThing(const char *Name)
{
int i,ListSize=DefList.size();
for (i=0; i<ListSize; i++)
{
if (DefList[i]==Name) return(i);
}
return(-1);
}
/*****************************************************************************/
void CLayerThing::SetCursor(const char *Name)
{
int Idx=FindDefThing(Name);
if (Idx==-1) return;
Cursor=DefList[Idx];
}
2001-03-21 00:06:17 +01:00
/*****************************************************************************/
2001-03-22 21:49:58 +01:00
void CLayerThing::RenderCursor(CCore *Core,Vector3 &CamPos,bool Is3d)
2001-03-21 00:06:17 +01:00
{
Vector3 ThisCam=Core->OffsetCam(CamPos,GetScaleFactor());
CPoint &CursPos=Core->GetCursorPos();
2001-03-29 19:59:01 +02:00
Cursor.XY[0]=CursPos;
2001-03-21 00:06:17 +01:00
2001-03-29 19:59:01 +02:00
if (CursPos.x<0 || CursPos.y<0) return;
if (Mode!=MouseModeNew) return;
if (Cursor.ElemID==-1) return;
2001-03-21 00:06:17 +01:00
2001-03-29 19:59:01 +02:00
RenderThing(Core,ThisCam,Cursor,Is3d,true);
2001-03-21 00:06:17 +01:00
}
/*****************************************************************************/
2001-03-22 21:49:58 +01:00
/*****************************************************************************/
/*****************************************************************************/
int CLayerThing::CheckThing(CPoint &Pos)
2001-03-21 00:06:17 +01:00
{
2001-03-22 21:49:58 +01:00
CList<int> List;
int Idx=-1,i,ListSize=ThingList.size();
int StartIdx=0;
2001-03-21 00:06:17 +01:00
2001-03-22 21:49:58 +01:00
// Build List Of XY Matches
for (i=0; i<ListSize; i++)
{
sLayerThing &ThisThing=ThingList[i];
if (ThisThing.XY[0]==Pos)
{
if (i==CurrentThing) StartIdx=List.size();
List.push_back(i);
}
}
ListSize=List.size();
if (ListSize)
{
StartIdx=(StartIdx+1)%ListSize;
Idx=List[StartIdx];
}
return(Idx);
2001-03-21 00:06:17 +01:00
}
/*****************************************************************************/
2001-03-22 21:49:58 +01:00
void CLayerThing::AddThing(CPoint &Pos)
{
if (Pos.x==-1 || Pos.y==-1) return; // Off Map?
2001-03-29 19:59:01 +02:00
CurrentThing=SelectThing(Pos);
2001-03-22 21:49:58 +01:00
if (CurrentThing!=-1) return;
2001-03-31 17:40:20 +02:00
2001-03-22 21:49:58 +01:00
CurrentThing=ThingList.size();
ThingList.resize(CurrentThing+1);
sLayerThing &ThisThing=ThingList[CurrentThing];
2001-03-29 19:59:01 +02:00
ThisThing=Cursor;
2001-04-07 23:05:33 +02:00
SetThingParams(ThisThing);
2001-03-29 19:59:01 +02:00
SelectThing(CurrentThing);
2001-03-31 17:40:20 +02:00
GUIThingDefClear();
2001-03-22 21:49:58 +01:00
}
/*****************************************************************************/
2001-03-29 19:59:01 +02:00
int CLayerThing::SelectThing(CPoint &Pos)
2001-03-22 21:49:58 +01:00
{
2001-03-29 19:59:01 +02:00
if (Pos.x==-1 || Pos.y==-1) return(-1); // Off Map?
SelectThing(CheckThing(Pos));
return(CurrentThing);
}
/*****************************************************************************/
int CLayerThing::SelectThing(int Idx)
{
CurrentThing=Idx;
CurrentThingPoint=0;
if (CurrentThing!=-1)
{
2001-04-07 23:05:33 +02:00
Mode=MouseModePoints;
GUIThingUpdate();
GUIThingPointUpdate();
2001-03-29 19:59:01 +02:00
}
return(CurrentThing);
}
/*****************************************************************************/
void CLayerThing::DeleteThing()
{
if (!ThingList.size()) return;
ThingList.erase(CurrentThing);
CurrentThing--;
2001-03-31 17:40:20 +02:00
GUIThingUpdate();
2001-03-22 21:49:58 +01:00
}
2001-04-07 23:05:33 +02:00
/*****************************************************************************/
void CLayerThing::GotoThing(CCore *Core)
{
if (CurrentThing==-1) return;
sLayerThing &ThisThing=ThingList[CurrentThing];
Core->SetCamPos(ThisThing.XY[0]);
}
2001-03-22 21:49:58 +01:00
2001-03-26 23:29:09 +02:00
/*****************************************************************************/
2001-03-22 21:49:58 +01:00
/*****************************************************************************/
/*****************************************************************************/
int CLayerThing::CheckThingPoint(CPoint &Pos)
{
CList<int> List;
sLayerThing &ThisThing=ThingList[CurrentThing];
int Idx=-1,i,ListSize=ThisThing.XY.size();
int StartIdx=0;
// Build List Of XY Matches
for (i=0; i<ListSize; i++)
{
if (ThisThing.XY[i]==Pos)
{
if (i==CurrentThing) StartIdx=List.size();
List.push_back(i);
}
}
ListSize=List.size();
if (ListSize)
{
StartIdx=(StartIdx+1)%ListSize;
Idx=List[StartIdx];
}
return(Idx);
}
/*****************************************************************************/
void CLayerThing::AddThingPoint(CPoint &Pos)
{
2001-04-07 23:05:33 +02:00
TRACE1("ADDTHINGPOINT %i\n",CurrentThingPoint);
2001-03-22 21:49:58 +01:00
if (Pos.x==-1 || Pos.y==-1) return; // Off Map?
2001-04-07 23:05:33 +02:00
2001-03-29 19:59:01 +02:00
CurrentThingPoint=SelectThingPoint(Pos);
2001-03-31 17:40:20 +02:00
if (CurrentThingPoint!=-1)
{
GUIThingPointUpdate(true);
return;
}
2001-03-22 21:49:58 +01:00
sLayerThing &ThisThing=ThingList[CurrentThing];
2001-04-07 23:05:33 +02:00
int PntCount=ThisThing.XY.size();
if (PntCount<ThisThing.Data.WaypointCount+1)
{
CurrentThingPoint=ThisThing.XY.size();
ThisThing.XY.resize(CurrentThingPoint+1);
ThisThing.XY[CurrentThingPoint]=Pos;
TRACE0("Add Point\n");
GUIThingPointUpdate();
}
2001-03-22 21:49:58 +01:00
}
/*****************************************************************************/
2001-03-29 19:59:01 +02:00
int CLayerThing::SelectThingPoint(CPoint &Pos)
2001-03-22 21:49:58 +01:00
{
2001-03-29 19:59:01 +02:00
if (Pos.x==-1 || Pos.y==-1) return(-1); // Off Map?
CurrentThingPoint=CheckThingPoint(Pos);
return(CurrentThingPoint);
2001-03-22 21:49:58 +01:00
}
/*****************************************************************************/
void CLayerThing::UpdatePos(CPoint &Pos,int Thing,int PosIdx,bool Recurs)
{
if (Pos.x==-1 || Pos.y==-1) return; // Off Map?
sLayerThing &ThisThing=ThingList[Thing];
CPoint dPos=Pos-ThisThing.XY[PosIdx];
int StartIdx=PosIdx,EndIdx=ThisThing.XY.size();
2001-03-31 17:40:20 +02:00
if (!dPos.x && !dPos.y) return;
2001-03-22 21:49:58 +01:00
if (!Recurs)
{
StartIdx=PosIdx;
2001-03-29 19:59:01 +02:00
EndIdx=StartIdx+1;
2001-03-22 21:49:58 +01:00
}
for (int i=StartIdx; i<EndIdx; i++)
{
ThisThing.XY[i]+=dPos;
}
2001-03-31 17:40:20 +02:00
GUIThingPointUpdate();
2001-03-22 21:49:58 +01:00
}
2001-03-29 19:59:01 +02:00
/*****************************************************************************/
void CLayerThing::MovePoint(int Dir)
{
if (CurrentThing==-1) return;
int NewPos=CurrentThingPoint+Dir;
sLayerThing &ThisThing=ThingList[CurrentThing];
if (NewPos<0 || NewPos>=ThisThing.XY.size()) return;
CPoint Tmp=ThisThing.XY[CurrentThingPoint];
ThisThing.XY[CurrentThingPoint]=ThisThing.XY[NewPos];
ThisThing.XY[NewPos]=Tmp;
CurrentThingPoint=NewPos;
GUIThingPointUpdate();
}
/*****************************************************************************/
void CLayerThing::DeletePoint()
{
if (!CurrentThingPoint) return;
if (CurrentThing==-1) return;
sLayerThing &ThisThing=ThingList[CurrentThing];
ThisThing.XY.erase(CurrentThingPoint);
CurrentThingPoint--;
if (CurrentThingPoint<0) CurrentThingPoint=0;
GUIThingPointUpdate();
}
2001-04-19 17:36:49 +02:00
/*****************************************************************************/
int CLayerThing::GetWidth()
{
return(theApp.GetCurrent()->GetMapWidth());
}
/*****************************************************************************/
int CLayerThing::GetHeight()
{
return(theApp.GetCurrent()->GetMapHeight());
}
2001-03-22 21:49:58 +01:00
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void CLayerThing::Export(CCore *Core,CExport &Exp)
2001-03-21 00:06:17 +01:00
{
2001-03-29 19:59:01 +02:00
int i,ListSize=ThingList.size();
Exp.ExportLayerHeader(LayerDef);
2001-03-21 00:06:17 +01:00
2001-03-29 19:59:01 +02:00
Exp.Write(&ListSize,sizeof(int));
for (i=0;i<ListSize; i++)
2001-03-21 00:06:17 +01:00
{
2001-03-29 19:59:01 +02:00
ExportThing(Exp,ThingList[i]);
}
ExportThingNames(Exp);
}
2001-03-21 00:06:17 +01:00
2001-04-01 22:22:49 +02:00
/*****************************************************************************/
void CLayerThing::ExportThing(CExport &Exp,sLayerThing &ThisThing)
{
int i,ListSize=ThisThing.XY.size();
2001-04-07 23:05:33 +02:00
sLayerThingData OutThing=ThisThing.Data;
OutThing.WaypointCount=ListSize;
Exp.Write(&OutThing,sizeof(sLayerThingData));
2001-04-01 22:22:49 +02:00
// Point List
for (i=0 ;i<ListSize; i++)
{
Exp.Write(&ThisThing.XY[i],sizeof(CPoint));
}
}
2001-03-21 00:06:17 +01:00
2001-03-29 19:59:01 +02:00
/*****************************************************************************/
void CLayerThing::ExportThingNames(CExport &Exp)
{
int i,ListSize=ThingList.size();
for (i=0; i<ListSize; i++)
{
char Txt[256];
sprintf(Txt,ThingList[i].Name);
Exp.Write(Txt,strlen(Txt)+1);
2001-03-21 00:06:17 +01:00
}
}