// ObjectManager.h: interface for the ObjectManager class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_OBJECTMANAGER_H__7B09BC09_4B1A_434D_8DF3_6A262CBEA609__INCLUDED_)
#define AFX_OBJECTMANAGER_H__7B09BC09_4B1A_434D_8DF3_6A262CBEA609__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include"GUIObjectList.h"
#include"GUIPath.h"
#include"GUILattice.h"
#include"MissionData.h"
#include<Stuff\Stuff.hpp>
#include <ImageLib\Image.h>

class ObjCreateInfo;
class EdGameObject;
class GUILattice;
class ViewWindowInfo;
class CameraController;
class UndoManager;
class CObjPanelDlg;
class AddCommand;
class CDisperseDlg;
class GUILookUpLight;


namespace Adept
{
	class Entity;
};

class MPGame
{
public:
	int Team,Alignment;
	bool Supported;
	bool AddScenario;
	int ScriptTotal;
	CString ScriptPaths[256];


	MPGame() 
	{
		ScriptTotal=0; Team=2; Alignment=2; Supported=false; AddScenario=false;
	}
	
	
};

class ObjectManager:public GUIObjectList  
{
protected:
	
	
	int DefaultAlignment;
	CString SourceMission;
	GUIObjectList ClipBoard;
	Point3D CopyPos;
	Point3D MapSize;
	GUIBound *MissionBound,*WarningBound;
	GUILattice *Lattice;
	GUILookUpLight *LLight;
	UndoManager *UndoMan;
	CameraController* m_CameraController;
	Image HField,SlopeMap,TerrainTexture;
	CString MapName;
	DWORD TagFlags;
	
	bool MapLoaded;
	ObjCreateInfo *AddInfo;
	EdGUIObject *AddNode(Point3D &pnt,DWORD *show_flag,bool insert=false);
	EdGUIObject *AddGameObject(ObjCreateInfo *inf,EdGameObject *gobj,DWORD *show_flag,Point3D &pnt);
	EdGUIObject *AddCamera(Point3D &pnt);
	EdGUIObject *AddFX(Point3D &pnt);
	EdGUIObject *AddDropZone(Point3D &pnt);
	EdGUIObject *AddLight(int subt,Point3D &pnt);
	void MakeBounds();
	void SaveInstanceTextFile();
	void SaveLightsTextFile();
	void SaveContentsTextFile();
	void SaveDataTextFile();
	void SaveBounds();
	void SaveNameTable();
	void SaveRailGraph();
	void SaveBuildFile();
	
public:
	void CheckScripts();
	void CreateNFOFile();
	void UpdateNFOFile();
	void LoadNFOFile();
	
	GUIObjectList ObjectiveList;
	MissionData MisDat;
	
	enum MPGameTypes
	{
			GT_SinglePlayer	=0,
			GT_StockDestruction ,		
			GT_StockTeamDestruction,	
			GT_StockAttrition	,		
			GT_StockTeamAttrition	,	
			GT_StockCaptureTheFlag,	
			GT_StockKingOfTheHill	,	
			GT_StockTeamKingOfTheHill	,
			GT_StockTerritories	,	
			GT_StockStealTheBacon	,	
			GT_StockCaptureBase	,	
			GT_StockDestroyObjective,	
			GT_StockEscort,			
			GT_StockMasterTrial	,	
			GT_StockSiegeAssault	,
			GT_StockCampaign	,	// [editor-build fix] used by ObjectManager.cpp (string map @1013, int map case 14) but was missing from this enum
			GT_CustomDestruction	,
			GT_CustomTeamDestruction	,
			GT_CustomAttrition	,		
			GT_CustomTeamAttrition,		
			GT_CustomCaptureTheFlag	,
			GT_CustomKingOfTheHill,		
			GT_CustomTeamKingOfTheHill ,
			GT_CustomTerritories	,	
			GT_CustomStealTheBacon,		
			GT_CustomCaptureBase	,	
			GT_CustomDestroyObjective,	
			GT_CustomEscort	,		
			GT_CustomMasterTrial,			
			GT_CustomSiegeAssault,			
			GT_CustomCampaign,			
			GT_CustomUndefined,			
			
			GT_TOTALGAMES
			
	};

	static bool IsTeamGame(MPGameTypes type);
	static CString GTEnumToType(MPGameTypes x);
	static MPGameTypes GTTypeToEnum(int x);
	
	static const char *MPGameTypeNames[];
	MPGame MPGames[GT_TOTALGAMES];
	
	bool AddEssentialObjects(CString &msg);
	void CheckAlternativeScript(CString str);
	void CheckAlternativeScripts();

	void AddObjective();
	void EditObjectives(CWnd *parent);
	void SavePosForUndo();
	void Undo(); 
	void Redo();
	bool CanUndo(); 
	bool CanRedo();
	void SyncToGame(ViewWindowInfo *vinf);
	void SaveToReg();
	void LoadFromReg();
	void LoadTextInfo();
	void SaveTextInfo(NotationFile *not_file);
	void BuildGroup(GUIObjectList *new_list,Page *group_page);
	void DeleteSelection(); 
	void SetName( CString &name);
	void BuildResources();
	void SetTagFlags(unsigned long flags) {TagFlags=flags;}
	void LoadTerrainTexture(Image *img);
	Point3D BuildHFFromMap(Image *img);
	void MakeSlopeMap(Image *img,Point3D map_scale);
	unsigned long GetTagFlags() {return TagFlags;}
	
	CameraController* GetCameraController() {return m_CameraController;}
	void ResetCamera();
	
	ObjectManager *GetMyMission() {return this;}
	
	bool IsLoaded() {return MapLoaded;}
	int GetDefaultAlignment() { return DefaultAlignment;}
	void SetDefaultAlignment(int ang) { DefaultAlignment=ang;}
	void CreateLattice();
	void RecalcLatticeLinks();
	void ResetBounds();
	
	
	EdGUIObject *AttachGameObject(Adept::Entity *entity);
	
	Image *GetHeightField() {return &HField;}
	Image *GetSlopeMap() {return &SlopeMap;}
	Image *GetTerrainTexture() {return &TerrainTexture;}
	void AddToBuildFile();
	bool InBuildFile();
	void SetAddInfo(ObjCreateInfo *inf) {AddInfo=inf;}
	bool AddAt(Point3D &pnt,DWORD *show_flag,bool flag=false);
	EdGUIObject *AddAt(AddCommand **com,DWORD *show_flag,bool flag=false,Point3D pnt=Point3D(0,0,0),YawPitchRoll rot=YawPitchRoll(0,0,0));
	EdGUIObject *AddAt(ObjCreateInfo *inf,AddCommand **com,DWORD *show_flag,bool flag=false,Point3D pnt=Point3D(0,0,0),YawPitchRoll rot=YawPitchRoll(0,0,0));
	void SetProperties(Point3D &pnt,CWnd *parent=NULL);
	void SetProperties(EdGUIObject *gobj,CWnd *parent=NULL);
	void SetPropertiesOfSelected(CWnd *parent);
	void AddPanel(CObjPanelDlg *pnl,UndoCommand **cmd);
	void DeleteObject(int i);
	void DeleteAllObjects();
	void RotateSelection( UnitQuaternion &pnt);
	void SaveUndoCommand(UndoCommand *cmd);
	
	void DrawAllObjects(DrawInfo &dinf,bool drawTags=false)
	{GUIObjectList::DrawAllObjects(dinf,drawTags,TagFlags);}
	
	void DrawSelectedObjects(DrawInfo &dinf,bool drawTags=false) 
	{GUIObjectList::DrawSelectedObjects(dinf,drawTags,TagFlags);}
	
	void DrawUnSelectedObjects(DrawInfo &dinf,bool drawTags=false)
	{GUIObjectList::DrawUnSelectedObjects(dinf,drawTags,TagFlags);}
	
	void NewMission(CString mis_name,CString map_name);
	bool OpenMission(CString fname,bool night=false);
	void SaveMission(bool textout=false);
	void SaveMission(CString fname,bool textout=false);
	bool CloseMission();
	
	Point3D GetMapSize() const;
	
	void SetObjectName(EdGUIObject *gobj,CString &name); 
	
	void Draw(DrawInfo &dinf);
	void DrawTag(DrawInfo &dinf, unsigned long tag_flags);
	int GroupSelected();
	void UnGroupSelected();
	
	void ClearSelection();
	
	void OffsetSelection(Point3D &vct);
	bool CanOffsetSelection(Point3D &vect);
	
	void SaveOverViewMap(CString fname,CSize size);
	bool CutSelection();
	bool CopySelection();
	void PasteClipBoard(Point3D offset=Point3D(10.0f,0.0f,10.0f));
	void PasteClipBoardAt(Point3D pos);
	
	int GetUnSelIcon() {return ICON_MISSION; }
	int GetSelIcon()   {return ICON_MISSION; }
	
	ObjectManager();
	virtual ~ObjectManager();
	
};

#endif // !defined(AFX_OBJECTMANAGER_H__7B09BC09_4B1A_434D_8DF3_6A262CBEA609__INCLUDED_)
