From a4c804b49ec872b71bd5a0167c3ad45704a3cc30 Mon Sep 17 00:00:00 2001 From: adiblol Date: Thu, 8 Mar 2012 19:32:05 +0100 Subject: Initial commit, Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch --- src/terrain.h | 195 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 src/terrain.h (limited to 'src/terrain.h') diff --git a/src/terrain.h b/src/terrain.h new file mode 100644 index 0000000..f8f7435 --- /dev/null +++ b/src/terrain.h @@ -0,0 +1,195 @@ +// terrain.h + +#ifndef _TERRAIN_H_ +#define _TERRAIN_H_ + + +class CInstanceManager; +class CD3DEngine; +class CWater; + + + +#define FLATLIMIT (5.0f*PI/180.0f) + + +enum TerrainRes +{ + TR_NULL = 0, + TR_STONE = 1, + TR_URANIUM = 2, + TR_POWER = 3, + TR_KEYa = 4, + TR_KEYb = 5, + TR_KEYc = 6, + TR_KEYd = 7, +}; + + +#define MAXBUILDINGLEVEL 100 + +typedef struct +{ + D3DVECTOR center; + float factor; + float min; + float max; + float level; + float height; + float bboxMinX; + float bboxMaxX; + float bboxMinZ; + float bboxMaxZ; +} +BuildingLevel; + + +#define MAXMATTERRAIN 100 + +typedef struct +{ + short id; + char texName[20]; + float u,v; + float hardness; + char mat[4]; // up, right, down, left +} +TerrainMaterial; + +typedef struct +{ + short id; + char mat[4]; // up, right, down, left +} +DotLevel; + + +#define MAXFLYINGLIMIT 10 + +typedef struct +{ + D3DVECTOR center; + float extRadius; + float intRadius; + float maxHeight; +} +FlyingLimit; + + + +class CTerrain +{ +public: + CTerrain(CInstanceManager* iMan); + ~CTerrain(); + + BOOL Generate(int mosaic, int brickP2, float size, float vision, int depth, float hardness); + BOOL InitTextures(char* baseName, int* table, int dx, int dy); + void LevelFlush(); + BOOL LevelMaterial(int id, char* baseName, float u, float v, int up, int right, int down, int left, float hardness); + BOOL LevelInit(int id); + BOOL LevelGenerate(int *id, float min, float max, float slope, float freq, D3DVECTOR center, float radius); + void FlushRelief(); + BOOL ReliefFromBMP(const char* filename, float scaleRelief, BOOL adjustBorder); + BOOL ReliefFromDXF(const char* filename, float scaleRelief); + BOOL ResFromBMP(const char* filename); + BOOL CreateObjects(BOOL bMultiRes); + BOOL Terraform(const D3DVECTOR &p1, const D3DVECTOR &p2, float height); + + void SetWind(D3DVECTOR speed); + D3DVECTOR RetWind(); + + float RetFineSlope(const D3DVECTOR &pos); + float RetCoarseSlope(const D3DVECTOR &pos); + BOOL GetNormal(D3DVECTOR &n, const D3DVECTOR &p); + float RetFloorLevel(const D3DVECTOR &p, BOOL bBrut=FALSE, BOOL bWater=FALSE); + float RetFloorHeight(const D3DVECTOR &p, BOOL bBrut=FALSE, BOOL bWater=FALSE); + BOOL MoveOnFloor(D3DVECTOR &p, BOOL bBrut=FALSE, BOOL bWater=FALSE); + BOOL ValidPosition(D3DVECTOR &p, float marging); + TerrainRes RetResource(const D3DVECTOR &p); + void LimitPos(D3DVECTOR &pos); + + void FlushBuildingLevel(); + BOOL AddBuildingLevel(D3DVECTOR center, float min, float max, float height, float factor); + BOOL UpdateBuildingLevel(D3DVECTOR center); + BOOL DeleteBuildingLevel(D3DVECTOR center); + float RetBuildingFactor(const D3DVECTOR &p); + float RetHardness(const D3DVECTOR &p); + + int RetMosaic(); + int RetBrick(); + float RetSize(); + float RetScaleRelief(); + + void GroundFlat(D3DVECTOR pos); + float RetFlatZoneRadius(D3DVECTOR center, float max); + + void SetFlyingMaxHeight(float height); + float RetFlyingMaxHeight(); + void FlushFlyingLimit(); + BOOL AddFlyingLimit(D3DVECTOR center, float extRadius, float intRadius, float maxHeight); + float RetFlyingLimit(D3DVECTOR pos, BOOL bNoLimit); + +protected: + BOOL ReliefAddDot(D3DVECTOR pos, float scaleRelief); + void AdjustRelief(); + D3DVECTOR RetVector(int x, int y); + D3DVERTEX2 RetVertex(int x, int y, int step); + BOOL CreateMosaic(int ox, int oy, int step, int objRank, const D3DMATERIAL7 &mat, float min, float max); + BOOL CreateSquare(BOOL bMultiRes, int x, int y); + + TerrainMaterial* LevelSearchMat(int id); + void LevelTextureName(int x, int y, char *name, FPOINT &uv); + float LevelRetHeight(int x, int y); + BOOL LevelGetDot(int x, int y, float min, float max, float slope); + int LevelTestMat(char *mat); + void LevelSetDot(int x, int y, int id, char *mat); + BOOL LevelIfDot(int x, int y, int id, char *mat); + BOOL LevelPutDot(int x, int y, int id); + void LevelOpenTable(); + void LevelCloseTable(); + + void AdjustBuildingLevel(D3DVECTOR &p); + +protected: + CInstanceManager* m_iMan; + CD3DEngine* m_engine; + CWater* m_water; + + int m_mosaic; // nb de mosaïque + int m_brick; // nb de briques par mosaïque + float m_size; // taille d'un élément dans une brique + float m_vision; // vision avant un changement de résolution + float* m_relief; // table du relief + int* m_texture; // table des textures + int* m_objRank; // table des rangs des objets + BOOL m_bMultiText; + BOOL m_bLevelText; + float m_scaleMapping; // échelle du mapping + float m_scaleRelief; + int m_subdivMapping; + int m_depth; // nb de résolutions différentes (1,2,3,4) + char m_texBaseName[20]; + char m_texBaseExt[10]; + float m_defHardness; + + TerrainMaterial m_levelMat[MAXMATTERRAIN+1]; + int m_levelMatTotal; + int m_levelMatMax; + int m_levelDotSize; + DotLevel* m_levelDot; + int m_levelID; + + int m_buildingUsed; + BuildingLevel m_buildingTable[MAXBUILDINGLEVEL]; + + unsigned char* m_resources; + D3DVECTOR m_wind; // vitesse du vent + + float m_flyingMaxHeight; + int m_flyingLimitTotal; + FlyingLimit m_flyingLimit[MAXFLYINGLIMIT]; +}; + + +#endif //_TERRAIN_H_ -- cgit v1.2.3-1-g7c22