summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorProgramerus <alcadeias95@gmail.com>2012-06-25 16:37:03 +0200
committerProgramerus <alcadeias95@gmail.com>2012-06-25 16:37:03 +0200
commitf58918031c001a0159eaf8f18d4e451e70089d30 (patch)
tree9b85fe09213b364d837fbd9aeefe3f63b9418f83
parent3478978c21ddc905ceb01f5ffc9c22bbf19bc288 (diff)
downloadcolobot-f58918031c001a0159eaf8f18d4e451e70089d30.tar.gz
colobot-f58918031c001a0159eaf8f18d4e451e70089d30.tar.bz2
colobot-f58918031c001a0159eaf8f18d4e451e70089d30.zip
Declarations for graphics/common
-rw-r--r--src/CMakeLists.txt3
-rw-r--r--src/graphics/common/camera.h249
-rw-r--r--src/graphics/common/cloud.h69
-rw-r--r--src/graphics/common/lightning.h60
-rw-r--r--src/graphics/common/model.h117
-rw-r--r--src/graphics/common/modfile.cpp23
-rw-r--r--src/graphics/common/modfile.h114
-rw-r--r--src/graphics/common/particle.h313
-rw-r--r--src/graphics/common/planet.h56
-rw-r--r--src/graphics/common/pyro.h148
-rw-r--r--src/graphics/common/terrain.h186
-rw-r--r--src/graphics/common/text.h88
-rw-r--r--src/graphics/common/water.h109
-rw-r--r--src/object/motion/motionant.cpp2
-rw-r--r--src/object/motion/motionbee.cpp2
-rw-r--r--src/object/motion/motionhuman.cpp2
-rw-r--r--src/object/motion/motionmother.cpp2
-rw-r--r--src/object/motion/motionspider.cpp2
-rw-r--r--src/object/motion/motiontoto.cpp2
-rw-r--r--src/object/motion/motionvehicle.cpp2
-rw-r--r--src/object/motion/motionworm.cpp2
-rw-r--r--src/object/object.cpp2
-rw-r--r--src/object/robotmain.cpp2
-rw-r--r--src/old/model.cpp2
-rw-r--r--src/old/model.h2
-rw-r--r--src/old/modfile.cpp695
-rw-r--r--src/old/modfile.h115
-rw-r--r--src/old/terrain.cpp2
28 files changed, 2347 insertions, 24 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 34ed7df..024489d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -22,12 +22,12 @@ old/d3dtextr.cpp
old/d3dutil.cpp
old/d3dmath.cpp
old/math3d.cpp
+old/modfile.cpp
app/app.cpp
common/event.cpp
common/iman.cpp
common/metafile.cpp
common/misc.cpp
-common/modfile.cpp
common/profile.cpp
common/restext.cpp
graphics/common/camera.cpp
@@ -37,6 +37,7 @@ graphics/common/engine.cpp
graphics/common/light.cpp
graphics/common/lightning.cpp
graphics/common/model.cpp
+graphics/common/modfile.cpp
graphics/common/particle.cpp
graphics/common/planet.cpp
graphics/common/pyro.cpp
diff --git a/src/graphics/common/camera.h b/src/graphics/common/camera.h
index 14838ba..59e7609 100644
--- a/src/graphics/common/camera.h
+++ b/src/graphics/common/camera.h
@@ -19,9 +19,256 @@
#pragma once
+#include "engine.h"
+#include "common/struct.h"
+#include "common/event.h"
+
+
+class CInstanceManager;
+class Gfx::CEngine;
+class Gfx::CTerrain;
+class Gfx::CWater;
+class CObject;
namespace Gfx {
-// TODO CCamera
+
+enum CameraType
+{
+ CAMERA_NULL = 0, // camera undefined
+ CAMERA_FREE = 1, // camera free (never in principle)
+ CAMERA_EDIT = 2, // camera while editing a program
+ CAMERA_ONBOARD = 3, // camera on board a robot
+ CAMERA_BACK = 4, // camera behind a robot
+ CAMERA_FIX = 5, // static camera following robot
+ CAMERA_EXPLO = 6, // camera steady after explosion
+ CAMERA_SCRIPT = 7, // camera during a film script
+ CAMERA_INFO = 8, // camera for displaying information
+ CAMERA_VISIT = 9, // visit instead of an error
+ CAMERA_DIALOG = 10, // camera for dialogue
+ CAMERA_PLANE = 11, // static camera height
+};
+
+enum CameraSmooth
+{
+ CS_NONE = 0, // sharp
+ CS_NORM = 1, // normal
+ CS_HARD = 2, // hard
+ CS_SPEC = 3, // special
+};
+
+enum CenteringPhase
+{
+ CP_NULL = 0,
+ CP_START = 1,
+ CP_WAIT = 2,
+ CP_STOP = 3,
+};
+
+enum CameraEffect
+{
+ CE_NULL = 0, // no effect
+ CE_TERRAFORM = 1, // digging in
+ CE_CRASH = 2, // Vehicle driving is severely
+ CE_EXPLO = 3, // explosion
+ CE_SHOT = 4, // not mortal shot
+ CE_VIBRATION = 5, // vibration during construction
+ CE_PET = 6, // spleen reactor
+};
+
+enum OverEffect
+{
+ OE_NULL = 0, // no effect
+ OE_BLOOD = 1, // flash red
+ OE_FADEINw = 2, // white -> nothing
+ OE_FADEOUTw = 3, // nothing -> white
+ OE_FADEOUTb = 4, // nothing -> blue
+ OE_BLITZ = 5, // lightning
+};
+
+
+
+class CCamera {
+
+ public:
+ CCamera(CInstanceManager* iMan);
+ ~CCamera();
+
+ bool EventProcess(const Event &event);
+
+ void Init(Math::Vector eye, Math::Vector lookat, float delay);
+
+ void SetObject(CObject* object);
+ CObject* RetObject();
+
+ void SetType(CameraType type);
+ CameraType RetType();
+
+ void SetSmooth(CameraSmooth type);
+ CameraSmooth RetSmoth();
+
+ void SetDist(float dist);
+ float RetDist();
+
+ void SetFixDirection(float angle);
+ float RetFixDirection();
+
+ void SetRemotePan(float value);
+ float RetRemotePan();
+
+ void SetRemoteZoom(float value);
+ float RetRemoteZoom();
+
+ void StartVisit(Math::Vector goal, float dist);
+ void StopVisit();
+
+ void RetCamera(Math::Vector &eye, Math::Vector &lookat);
+
+ bool StartCentering(CObject *object, float angleH, float angleV, float dist, float time);
+ bool StopCentering(CObject *object, float time);
+ void AbortCentering();
+
+ void FlushEffect();
+ void StartEffect(CameraEffect effect, Math::Vector pos, float force);
+
+ void FlushOver();
+ void SetOverBaseColor(Gfx::Color color);
+ void StartOver(OverEffect effect, Math::Vector pos, float force);
+
+ void FixCamera();
+ void SetScriptEye(Math::Vector eye);
+ void SetScriptLookat(Math::Vector lookat);
+
+ void SetEffect(bool bEnable);
+ void SetCameraScroll(bool bScroll);
+ void SetCameraInvertX(bool bInvert);
+ void SetCameraInvertY(bool bInvert);
+
+ float RetMotorTurn();
+ Gfx::MouseType RetMouseDef(Math::Point pos);
+
+protected:
+ bool EventMouseMove(const Event &event);
+ void EventMouseWheel(int dir);
+ bool EventFrame(const Event &event);
+ bool EventFrameFree(const Event &event);
+ bool EventFrameEdit(const Event &event);
+ bool EventFrameDialog(const Event &event);
+ bool EventFrameBack(const Event &event);
+ bool EventFrameFix(const Event &event);
+ bool EventFrameExplo(const Event &event);
+ bool EventFrameOnBoard(const Event &event);
+ bool EventFrameInfo(const Event &event);
+ bool EventFrameVisit(const Event &event);
+ bool EventFrameScript(const Event &event);
+
+ void SetViewTime(const Math::Vector &vEyePt, const Math::Vector &vLookatPt, float rTime);
+ bool IsCollision(Math::Vector &eye, Math::Vector lookat);
+ bool IsCollisionBack(Math::Vector &eye, Math::Vector lookat);
+ bool IsCollisionFix(Math::Vector &eye, Math::Vector lookat);
+
+ Math::Vector ExcludeTerrain(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV);
+ Math::Vector ExcludeObject(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV);
+
+ void SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, const Math::Vector &up);
+ void EffectFrame(const Event &event);
+ void OverFrame(const Event &event);
+
+protected:
+ CInstanceManager* m_iMan;
+ Gfx::CEngine* m_engine;
+ CTerrain* m_terrain;
+ CWater* m_water;
+
+ CameraType m_type; // the type of camera (CAMERA *)
+ CameraSmooth m_smooth; // type of smoothing
+ CObject* m_cameraObj; // object linked to the camera
+
+ float m_eyeDistance; // distance between the eyes
+ float m_initDelay; // time of initial centering
+
+ Math::Vector m_actualEye; // current eye
+ Math::Vector m_actualLookat; // aim current
+ Math::Vector m_finalEye; // final eye
+ Math::Vector m_finalLookat; // aim final
+ Math::Vector m_normEye; // normal eye
+ Math::Vector m_normLookat; // aim normal
+ float m_focus;
+
+ bool m_bRightDown;
+ Math::Point m_rightPosInit;
+ Math::Point m_rightPosCenter;
+ Math::Point m_rightPosMove;
+
+ Math::Vector m_eyePt; // CAMERA_FREE: eye
+ float m_directionH; // CAMERA_FREE: horizontal direction
+ float m_directionV; // CAMERA_FREE: vertical direction
+ float m_heightEye; // CAMERA_FREE: height above the ground
+ float m_heightLookat; // CAMERA_FREE: height above the ground
+ float m_speed; // CAMERA_FREE: speed of movement
+
+ float m_backDist; // CAMERA_BACK: distance
+ float m_backMin; // CAMERA_BACK: distance minimal
+ float m_addDirectionH; // CAMERA_BACK: additional direction
+ float m_addDirectionV; // CAMERA_BACK: additional direction
+ bool m_bTransparency;
+
+ float m_fixDist; // CAMERA_FIX: distance
+ float m_fixDirectionH; // CAMERA_FIX: direction
+ float m_fixDirectionV; // CAMERA_FIX: direction
+
+ Math::Vector m_visitGoal; // CAMERA_VISIT: target position
+ float m_visitDist; // CAMERA_VISIT: distance
+ float m_visitTime; // CAMERA_VISIT: relative time
+ CameraType m_visitType; // CAMERA_VISIT: initial type
+ float m_visitDirectionH; // CAMERA_VISIT: direction
+ float m_visitDirectionV; // CAMERA_VISIT: direction
+
+ float m_editHeight; // CAMERA_EDIT: height
+
+ float m_remotePan;
+ float m_remoteZoom;
+
+ Math::Point m_mousePos;
+ float m_mouseDirH;
+ float m_mouseDirV;
+ float m_mouseMarging;
+
+ float m_motorTurn;
+
+ CenteringPhase m_centeringPhase;
+ float m_centeringAngleH;
+ float m_centeringAngleV;
+ float m_centeringDist;
+ float m_centeringCurrentH;
+ float m_centeringCurrentV;
+ float m_centeringTime;
+ float m_centeringProgress;
+
+ CameraEffect m_effectType;
+ Math::Vector m_effectPos;
+ float m_effectForce;
+ float m_effectProgress;
+ Math::Vector m_effectOffset;
+
+ OverEffect m_overType;
+ float m_overForce;
+ float m_overTime;
+ Gfx::Color m_overColorBase;
+ Gfx::Color m_overColor;
+ int m_overMode;
+ float m_overFadeIn;
+ float m_overFadeOut;
+
+ Math::Vector m_scriptEye;
+ Math::Vector m_scriptLookat;
+
+ bool m_bEffect; // shocks if explosion?
+ bool m_bCameraScroll; // scroll in the edges?
+ bool m_bCameraInvertX; // X inversion in the edges?
+ bool m_bCameraInvertY; // Y inversion in the edges?
+
+};
+
}; // namespace Gfx
diff --git a/src/graphics/common/cloud.h b/src/graphics/common/cloud.h
index 3e190ec..579eb9a 100644
--- a/src/graphics/common/cloud.h
+++ b/src/graphics/common/cloud.h
@@ -19,9 +19,76 @@
#pragma once
+#include "common/struct.h"
+#include "common/event.h"
+#include "graphics/common/color.h"
+#include "math/point.h"
+
+
+
+class CInstanceManager;
+
namespace Gfx {
-// TODO CCloud
+class CEngine;
+class CTerrain;
+
+const short MAXCLOUDLINE = 100;
+
+struct CloudLine
+{
+ short x, y; // beginning
+ short len; // in length x
+ float px1, px2, pz;
+};
+
+
+class CCloud
+{
+public:
+ CCloud(CInstanceManager* iMan, CEngine* engine);
+ ~CCloud();
+
+ bool EventProcess(const Event &event);
+ void Flush();
+ bool Create(const char *filename, Gfx::Color diffuse, Gfx::Color ambient, float level);
+ void Draw();
+
+ bool SetLevel(float level);
+ float RetLevel();
+
+ void SetEnable(bool bEnable);
+ bool RetEnable();
+
+protected:
+ bool EventFrame(const Event &event);
+ void AdjustLevel(Math::Vector &pos, Math::Vector &eye, float deep, Math::Point &uv1, Math::Point &uv2);
+ bool CreateLine(int x, int y, int len);
+
+protected:
+ CInstanceManager* m_iMan;
+ CEngine* m_engine;
+ CTerrain* m_terrain;
+
+ char m_filename[100];
+ float m_level; // overall level
+ Math::Point m_speed; // feedrate (wind)
+ Gfx::Color m_diffuse; // diffuse color
+ Gfx::Color m_ambient; // ambient color
+ float m_time;
+ float m_lastTest;
+ int m_subdiv;
+
+ Math::Vector m_wind; // wind speed
+ int m_brick; // brick mosaic
+ float m_size; // size of a brick element
+
+ int m_lineUsed;
+ CloudLine m_line[MAXCLOUDLINE];
+
+ bool m_bEnable;
+};
+
}; // namespace Gfx
diff --git a/src/graphics/common/lightning.h b/src/graphics/common/lightning.h
index a7fab45..2077954 100644
--- a/src/graphics/common/lightning.h
+++ b/src/graphics/common/lightning.h
@@ -19,9 +19,67 @@
#pragma once
+#include "common/misc.h"
+#include "common/struct.h"
+#include "object/object.h"
+
+
+class CInstanceManager;
+class CSound;
+
namespace Gfx {
-// TODO CLightning (aka CBlitz)
+class CEngine;
+class CTerrain;
+class CCamera;
+
+
+const float BLITZPARA = 200.0f; // radius of lightning protection
+const short BLITZMAX = 50;
+
+enum BlitzPhase
+{
+ BPH_WAIT,
+ BPH_BLITZ,
+};
+
+
+class CLightning
+{
+public:
+ CLightning(CInstanceManager* iMan, CEngine* engine);
+ ~CLightning();
+
+ void Flush();
+ bool EventProcess(const Event &event);
+ bool Create(float sleep, float delay, float magnetic);
+ bool GetStatus(float &sleep, float &delay, float &magnetic, float &progress);
+ bool SetStatus(float sleep, float delay, float magnetic, float progress);
+ void Draw();
+
+protected:
+ bool EventFrame(const Event &event);
+ CObject* SearchObject(Math::Vector pos);
+
+protected:
+ CInstanceManager* m_iMan;
+ CEngine* m_engine;
+ CTerrain* m_terrain;
+ CCamera* m_camera;
+ CSound* m_sound;
+
+ bool m_bBlitzExist;
+ float m_sleep;
+ float m_delay;
+ float m_magnetic;
+ BlitzPhase m_phase;
+ float m_time;
+ float m_speed;
+ float m_progress;
+ Math::Vector m_pos;
+ Math::Point m_shift[BLITZMAX];
+ float m_width[BLITZMAX];
+};
}; // namespace Gfx
diff --git a/src/graphics/common/model.h b/src/graphics/common/model.h
index a086c73..d67c71a 100644
--- a/src/graphics/common/model.h
+++ b/src/graphics/common/model.h
@@ -19,9 +19,124 @@
#pragma once
+#include "engine.h"
+#include "common/struct.h"
+#include "common/event.h"
+#include "modfile.h"
+#include "vertex.h"
+#include "math/point.h"
+
+
+class CInstanceManager;
+class CModFile;
+class CInterface;
+
namespace Gfx {
-// TODO CModel
+class CEngine;
+
+
+class CModel {
+ public:
+ CModel(CInstanceManager* iMan);
+ ~CModel();
+
+ void StartUserAction();
+ void StopUserAction();
+
+ bool EventProcess(const Event &event);
+
+ void InitView();
+ void InitViewFromSelect();
+ void UpdateView();
+ void ViewMove(const Event &event, float speed);
+
+ protected:
+ bool EventFrame(const Event &event);
+ bool GetVertex(int rank, Gfx::VertexTex2 &vertex);
+ bool SetVertex(int rank, Gfx::VertexTex2 &vertex);
+ Math::Vector RetSelectCDG();
+ Math::Vector RetSelectNormal();
+ void SmoothSelect();
+ void PlaneSelect();
+ void ColorSelect();
+ void StateSelect();
+ void MoveSelect(Math::Vector move);
+ void OperSelect(Math::Vector move, char oper);
+ void ReadScript(char *filename);
+ void BBoxCompute(Math::Vector &min, Math::Vector &max);
+ bool IsMappingSelectPlausible(Gfx::Mapping D3Dmode);
+ void MappingSelect(int mode, int rotate, bool bMirrorX, bool bMirrorY, Math::Point ti, Math::Point ts, char *texName);
+ void MappingSelectSpherical(int mode, int rotate, bool bMirrorX, bool bMirrorY, Math::Point ti, Math::Point ts, char *texName);
+ Math::Vector RetMappingCenter(Math::Vector pos, Math::Vector min);
+ void MappingSelectCylindrical(int mode, int rotate, bool bMirrorX, bool bMirrorY, Math::Point ti, Math::Point ts, char *texName);
+ void MappingSelectFace(int mode, int rotate, bool bMirrorX, bool bMirrorY, Math::Point ti, Math::Point ts, char *texName);
+ void MappingSelect2(int texNum2, int subdiv, int offsetU, int offsetV, bool bMirrorX, bool bMirrorY);
+ void MappingSelectPlane2(int mode, bool bMirrorX, bool bMirrorY);
+ void MappingSelectSpherical2(bool bMirrorX, bool bMirrorY);
+ void MappingSelectMagic2(bool bMirrorX, bool bMirrorY);
+ int SearchNext(int rank, int step);
+ int SearchSamePlane(int first, int step);
+ void CurrentSearchNext(int step, bool bControl);
+ void CurrentInit();
+ void CurrentSelect(bool bSelect);
+ void DeselectAll();
+ void SelectAll();
+ void SelectZone(int first, int last);
+ void SelectTerm();
+ void DefaultSelect();
+ void SelectDelete();
+ void Compress();
+ void MinMaxSelect();
+ void MinMaxChange();
+ void UpdateInfoText();
+ int* RetTextureTable();
+ void TexturePartUpdate();
+ void TextureRankChange(int step);
+ void TexturePartChange(int step);
+ void PutTextureValues();
+ void GetTextureValues();
+ void GetModelName(char *buffer);
+ void GetDXFName(char *buffer);
+ void GetScriptName(char *buffer);
+ bool IsEditFocus();
+
+ protected:
+ CInstanceManager* m_iMan;
+ Gfx::CEngine* m_engine;
+ CModFile* m_modFile;
+ CInterface* m_interface;
+
+ float m_time;
+ ModelTriangle* m_triangleTable;
+ int m_triangleSel1;
+ int m_triangleSel2;
+ int m_mode;
+ int m_textureMode;
+ int m_textureRotate;
+ bool m_bTextureMirrorX;
+ bool m_bTextureMirrorY;
+ Math::Point m_textureInf;
+ Math::Point m_textureSup;
+ int m_texturePart;
+ int m_textureRank;
+ char m_textureName[20];
+ bool m_bDisplayTransparent;
+ bool m_bDisplayOnlySelection;
+ float m_viewHeight;
+ float m_viewDist;
+ float m_viewAngleH;
+ float m_viewAngleV;
+ int m_color;
+ int m_state;
+ int m_secondTexNum;
+ int m_secondSubdiv;
+ int m_secondOffsetU;
+ int m_secondOffsetV;
+ char m_oper;
+ float m_min;
+ float m_max;
+};
}; // namespace Gfx
diff --git a/src/graphics/common/modfile.cpp b/src/graphics/common/modfile.cpp
new file mode 100644
index 0000000..6f80be7
--- /dev/null
+++ b/src/graphics/common/modfile.cpp
@@ -0,0 +1,23 @@
+// * This file is part of the COLOBOT source code
+// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
+// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
+// *
+// * This program is free software: you can redistribute it and/or modify
+// * it under the terms of the GNU General Public License as published by
+// * the Free Software Foundation, either version 3 of the License, or
+// * (at your option) any later version.
+// *
+// * This program is distributed in the hope that it will be useful,
+// * but WITHOUT ANY WARRANTY; without even the implied warranty of
+// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// * GNU General Public License for more details.
+// *
+// * You should have received a copy of the GNU General Public License
+// * along with this program. If not, see http://www.gnu.org/licenses/.
+
+// modfile.cpp
+
+#include "graphics/common/modfile.h"
+
+
+// TODO implementation \ No newline at end of file
diff --git a/src/graphics/common/modfile.h b/src/graphics/common/modfile.h
new file mode 100644
index 0000000..84b5456
--- /dev/null
+++ b/src/graphics/common/modfile.h
@@ -0,0 +1,114 @@
+// * This file is part of the COLOBOT source code
+// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
+// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
+// *
+// * This program is free software: you can redistribute it and/or modify
+// * it under the terms of the GNU General Public License as published by
+// * the Free Software Foundation, either version 3 of the License, or
+// * (at your option) any later version.
+// *
+// * This program is distributed in the hope that it will be useful,
+// * but WITHOUT ANY WARRANTY; without even the implied warranty of
+// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// * GNU General Public License for more details.
+// *
+// * You should have received a copy of the GNU General Public License
+// * along with this program. If not, see http://www.gnu.org/licenses/.
+
+// modfile.h
+
+#include "engine.h"
+#include "vertex.h"
+#include "material.h"
+#include "math/vector.h"
+
+
+class CInstanceManager;
+
+
+namespace Gfx {
+
+struct OldModelTriangle1
+{
+ char bUsed; // TRUE -> using
+ char bSelect; // TRUE -> selected
+ Vertex p1;
+ Vertex p2;
+ Vertex p3;
+ Material material;
+ char texName[20];
+ float min;
+ float max;
+}; // length = 196 bytes
+
+struct OldModelTriangle2
+{
+ char bUsed; // TRUE -> used
+ char bSelect; // TRUE -> selected
+ Vertex p1;
+ Vertex p2;
+ Vertex p3;
+ Material material;
+ char texName[20];
+ float min;
+ float max;
+ long state;
+ short reserve1;
+ short reserve2;
+ short reserve3;
+ short reserve4;
+};
+
+struct ModelTriangle
+{
+ char bUsed; // TRUE -> used
+ char bSelect; // TRUE -> selected
+ VertexTex2 p1;
+ VertexTex2 p2;
+ VertexTex2 p3;
+ Material material;
+ char texName[20];
+ float min;
+ float max;
+ long state;
+ short texNum2;
+ short reserve2;
+ short reserve3;
+ short reserve4;
+}; // length = 208 bytes
+
+
+
+
+class CModFile {
+public:
+ CModFile(CInstanceManager* iMan);
+ ~CModFile();
+
+ bool ReadDXF(char *filename, float min, float max);
+ bool AddModel(char *filename, int first, bool bEdit=false, bool bMeta=true);
+ bool ReadModel(char *filename, bool bEdit=false, bool bMeta=true);
+ bool WriteModel(char *filename);
+
+ bool CreateEngineObject(int objRank, int addState=0);
+ void Mirror();
+
+ void SetTriangleUsed(int total);
+ int RetTriangleUsed();
+ int RetTriangleMax();
+ ModelTriangle* RetTriangleList();
+
+ float RetHeight(Math::Vector pos);
+
+protected:
+ bool CreateTriangle(Math::Vector p1, Math::Vector p2, Math::Vector p3, float min, float max);
+
+protected:
+ CInstanceManager* m_iMan;
+ CEngine* m_engine;
+
+ ModelTriangle* m_triangleTable;
+ int m_triangleUsed;
+};
+
+};
diff --git a/src/graphics/common/particle.h b/src/graphics/common/particle.h
index f550399..9e9fd36 100644
--- a/src/graphics/common/particle.h
+++ b/src/graphics/common/particle.h
@@ -19,9 +19,320 @@
#pragma once
+#include "engine.h"
+#include "sound/sound.h"
+
+
+class CInstanceManager;
+class CRobotMain;
+class Gfx::CTerrain;
+class Gfx::CWater;
+class CObject;
+
+
namespace Gfx {
-// TODO CParticle (aka CParticule)
+const short MAXPARTICULE = 500;
+const short MAXPARTITYPE = 5;
+const short MAXTRACK = 100;
+const short MAXTRACKLEN = 10;
+const short MAXPARTIFOG = 100;
+const short MAXWHEELTRACE = 1000;
+
+const short SH_WORLD = 0; // particle in the world in the interface
+const short SH_FRONT = 1; // particle in the world on the interface
+const short SH_INTERFACE = 2; // particle in the interface
+const short SH_MAX = 3;
+
+// type == 0 -> triangles
+// type == 1 -> effect00 (black background)
+// type == 2 -> effect01 (black background)
+// type == 3 -> effect02 (black background)
+// type == 4 -> text (white background)
+
+
+enum ParticuleType
+{
+ PARTIEXPLOT = 1, // technology explosion
+ PARTIEXPLOO = 2, // organic explosion
+ PARTIMOTOR = 3, // the engine exhaust gas
+ PARTIGLINT = 4, // reflection
+ PARTIBLITZ = 5, // lightning recharging battery
+ PARTICRASH = 6, // dust after fall
+ PARTIGAS = 7, // gas from the reactor
+ PARTIFIRE = 9, // fireball shrinks
+ PARTIFIREZ = 10, // fireball grows
+ PARTIBLUE = 11, // blue ball
+ PARTISELY = 12, // yellow selection
+ PARTISELR = 13, // red selection
+ PARTIGUN1 = 18, // a bullet (fireball)
+ PARTIGUN2 = 19, // bullet 2 (ant)
+ PARTIGUN3 = 20, // bullet 3 (spider)
+ PARTIGUN4 = 21, // bullet 4 (orgaball)
+ PARTIFRAG = 22, // triangular fragment
+ PARTIQUEUE = 23, // inflamed tail
+ PARTIORGANIC1 = 24, // organic ball mother
+ PARTIORGANIC2 = 25, // organic ball daughter
+ PARTISMOKE1 = 26, // black smoke
+ PARTISMOKE2 = 27, // black smoke
+ PARTISMOKE3 = 28, // black smoke
+ PARTISMOKE4 = 29, // black smoke
+ PARTIBLOOD = 30, // human blood
+ PARTIBLOODM = 31, // blood laying
+ PARTIVAPOR = 32, // steam
+ PARTIVIRUS1 = 33, // virus 1
+ PARTIVIRUS2 = 34, // virus 2
+ PARTIVIRUS3 = 35, // virus 3
+ PARTIVIRUS4 = 36, // virus 4
+ PARTIVIRUS5 = 37, // virus 5
+ PARTIVIRUS6 = 38, // virus 6
+ PARTIVIRUS7 = 39, // virus 7
+ PARTIVIRUS8 = 40, // virus 8
+ PARTIVIRUS9 = 41, // virus 9
+ PARTIVIRUS10 = 42, // virus 10
+ PARTIRAY1 = 43, // ray 1 (turn)
+ PARTIRAY2 = 44, // ray 2 (electric arc)
+ PARTIRAY3 = 45, // ray 3
+ PARTIRAY4 = 46, // ray 4
+ PARTIFLAME = 47, // flame
+ PARTIBUBBLE = 48, // bubble
+ PARTIFLIC = 49, // circles in the water
+ PARTIEJECT = 50, // ejection from the reactor
+ PARTISCRAPS = 51, // waste from the reactor
+ PARTITOTO = 52, // reactor of tot
+ PARTIERROR = 53, // toto says no
+ PARTIWARNING = 54, // foo says blah
+ PARTIINFO = 54, // toto says yes
+ PARTIQUARTZ = 55, // reflection crystal
+ PARTISPHERE0 = 56, // explosion sphere
+ PARTISPHERE1 = 57, // energy sphere
+ PARTISPHERE2 = 58, // analysis sphere
+ PARTISPHERE3 = 59, // shield sphere
+ PARTISPHERE4 = 60, // information sphere (emit)
+ PARTISPHERE5 = 61, // botanical sphere (gravity root)
+ PARTISPHERE6 = 62, // information sphere (receive)
+ PARTISPHERE7 = 63, // sphere
+ PARTISPHERE8 = 64, // sphere
+ PARTISPHERE9 = 65, // sphere
+ PARTIGUNDEL = 66, // bullet destroyed by shield
+ PARTIPART = 67, // object part
+ PARTITRACK1 = 68, // drag 1
+ PARTITRACK2 = 69, // drag 2
+ PARTITRACK3 = 70, // drag 3
+ PARTITRACK4 = 71, // drag 4
+ PARTITRACK5 = 72, // drag 5
+ PARTITRACK6 = 73, // drag 6
+ PARTITRACK7 = 74, // drag 7
+ PARTITRACK8 = 75, // drag 8
+ PARTITRACK9 = 76, // drag 9
+ PARTITRACK10 = 77, // drag 10
+ PARTITRACK11 = 78, // drag 11
+ PARTITRACK12 = 79, // drag 12
+ PARTITRACK13 = 80, // drag 13
+ PARTITRACK14 = 81, // drag 14
+ PARTITRACK15 = 82, // drag 15
+ PARTITRACK16 = 83, // drag 16
+ PARTITRACK17 = 84, // drag 17
+ PARTITRACK18 = 85, // drag 18
+ PARTITRACK19 = 86, // drag 19
+ PARTITRACK20 = 87, // drag 20
+ PARTIGLINTb = 88, // blue reflection
+ PARTIGLINTr = 89, // red reflection
+ PARTILENS1 = 90, // brilliance 1 (orange)
+ PARTILENS2 = 91, // brilliance 2 (yellow)
+ PARTILENS3 = 92, // brilliance 3 (red)
+ PARTILENS4 = 93, // brilliance 4 (violet)
+ PARTICONTROL = 94, // reflection on button
+ PARTISHOW = 95, // shows a place
+ PARTICHOC = 96, // shock wave
+ PARTIGFLAT = 97, // shows if the ground is flat
+ PARTIRECOVER = 98, // blue ball recycler
+ PARTIROOT = 100, // gravity root smoke
+ PARTIPLOUF0 = 101, // splash
+ PARTIPLOUF1 = 102, // splash
+ PARTIPLOUF2 = 103, // splash
+ PARTIPLOUF3 = 104, // splash
+ PARTIPLOUF4 = 105, // splash
+ PARTIDROP = 106, // drop
+ PARTIFOG0 = 107, // fog 0
+ PARTIFOG1 = 108, // fog 1
+ PARTIFOG2 = 109, // fog 2
+ PARTIFOG3 = 110, // fog 3
+ PARTIFOG4 = 111, // fog 4
+ PARTIFOG5 = 112, // fog 5
+ PARTIFOG6 = 113, // fog 6
+ PARTIFOG7 = 114, // fog 7
+ PARTIFOG8 = 115, // fog 8
+ PARTIFOG9 = 116, // fog 9
+ PARTILIMIT1 = 117, // shows the limits 1
+ PARTILIMIT2 = 118, // shows the limits 2
+ PARTILIMIT3 = 119, // shows the limits 3
+ PARTILIMIT4 = 120, // shows the limits 4
+ PARTIWATER = 121, // drop of water
+ PARTIEXPLOG1 = 122, // ball explosion 1
+ PARTIEXPLOG2 = 123, // ball explosion 2
+ PARTIBASE = 124, // gases of spaceship
+ PARTITRACE0 = 140, // trace
+ PARTITRACE1 = 141, // trace
+ PARTITRACE2 = 142, // trace
+ PARTITRACE3 = 143, // trace
+ PARTITRACE4 = 144, // trace
+ PARTITRACE5 = 145, // trace
+ PARTITRACE6 = 146, // trace
+ PARTITRACE7 = 147, // trace
+ PARTITRACE8 = 148, // trace
+ PARTITRACE9 = 149, // trace
+ PARTITRACE10 = 150, // trace
+ PARTITRACE11 = 151, // trace
+ PARTITRACE12 = 152, // trace
+ PARTITRACE13 = 153, // trace
+ PARTITRACE14 = 154, // trace
+ PARTITRACE15 = 155, // trace
+ PARTITRACE16 = 156, // trace
+ PARTITRACE17 = 157, // trace
+ PARTITRACE18 = 158, // trace
+ PARTITRACE19 = 159, // trace
+};
+
+enum ParticulePhase
+{
+ PARPHSTART = 0,
+ PARPHEND = 1,
+};
+
+struct Particule
+{
+ char bUsed; // TRUE -> particle used
+ char bRay; // TRUE -> ray with goal
+ unsigned short uniqueStamp; // unique mark
+ short sheet; // sheet (0..n)
+ ParticuleType type; // type PARTI*
+ ParticulePhase phase; // phase PARPH*
+ float mass; // mass of the particle (in rebounding)
+ float weight; // weight of the particle (for noise)
+ float duration; // length of life
+ Math::Vector pos; // absolute position (relative if object links)
+ Math::Vector goal; // goal position (if bRay)
+ Math::Vector speed; // speed of displacement
+ float windSensitivity;
+ short bounce; // number of rebounds
+ Math::Point dim; // dimensions of the rectangle
+ float zoom; // zoom (0..1)
+ float angle; // angle of rotation
+ float intensity; // intensity
+ Math::Point texSup; // coordinated upper texture
+ Math::Point texInf; // coordinated lower texture
+ float time; // age of the particle (0..n)
+ float phaseTime; // age at the beginning of phase
+ float testTime; // time since last test
+ CObject* objLink; // father object (for example reactor)
+ CObject* objFather; // father object (for example reactor)
+ short objRank; // rank of the object, or -1
+ short trackRank; // rank of the drag
+};
+
+struct Track
+{
+ char bUsed; // TRUE -> drag used
+ char bDrawParticule;
+ float step; // duration of not
+ float last; // increase last not memorized
+ float intensity; // intensity at starting (0..1)
+ float width; // tail width
+ int used; // number of positions in "pos"
+ int head; // head to write index
+ Math::Vector pos[MAXTRACKLEN];
+ float len[MAXTRACKLEN];
+};
+
+struct WheelTrace
+{
+ ParticuleType type; // type PARTI*
+ Math::Vector pos[4]; // rectangle positions
+ float startTime; // beginning of life
+};
+
+
+
+class CParticle
+{
+public:
+ CParticle(CInstanceManager* iMan, CEngine* engine);
+ ~CParticle();
+
+ void SetGLDevice(CDevice device);
+
+ void FlushParticule();
+ void FlushParticule(int sheet);
+ int CreateParticule(Math::Vector pos, Math::Vector speed, Math::Point dim, ParticuleType type, float duration=1.0f, float mass=0.0f, float windSensitivity=1.0f, int sheet=0);
+ int CreateFrag(Math::Vector pos, Math::Vector speed, Triangle *triangle, ParticuleType type, float duration=1.0f, float mass=0.0f, float windSensitivity=1.0f, int sheet=0);
+ int CreatePart(Math::Vector pos, Math::Vector speed, ParticuleType type, float duration=1.0f, float mass=0.0f, float weight=0.0f, float windSensitivity=1.0f, int sheet=0);
+ int CreateRay(Math::Vector pos, Math::Vector goal, ParticuleType type, Math::Point dim, float duration=1.0f, int sheet=0);
+ int CreateTrack(Math::Vector pos, Math::Vector speed, Math::Point dim, ParticuleType type, float duration=1.0f, float mass=0.0f, float length=10.0f, float width=1.0f);
+ void CreateWheelTrace(const Math::Vector &p1, const Math::Vector &p2, const Math::Vector &p3, const Math::Vector &p4, ParticuleType type);
+ void DeleteParticule(ParticuleType type);
+ void DeleteParticule(int channel);
+ void SetObjectLink(int channel, CObject *object);
+ void SetObjectFather(int channel, CObject *object);
+ void SetPosition(int channel, Math::Vector pos);
+ void SetDimension(int channel, Math::Point dim);
+ void SetZoom(int channel, float zoom);
+ void SetAngle(int channel, float angle);
+ void SetIntensity(int channel, float intensity);
+ void SetParam(int channel, Math::Vector pos, Math::Point dim, float zoom, float angle, float intensity);
+ void SetPhase(int channel, ParticulePhase phase, float duration);
+ bool GetPosition(int channel, Math::Vector &pos);
+
+ Gfx::Color RetFogColor(Math::Vector pos);
+
+ void SetFrameUpdate(int sheet, bool bUpdate);
+ void FrameParticule(float rTime);
+ void DrawParticule(int sheet);
+
+ bool WriteWheelTrace(char *filename, int width, int height, Math::Vector dl, Math::Vector ur);
+
+protected:
+ void DeleteRank(int rank);
+ bool CheckChannel(int &channel);
+ void DrawParticuleTriangle(int i);
+ void DrawParticuleNorm(int i);
+ void DrawParticuleFlat(int i);
+ void DrawParticuleFog(int i);
+ void DrawParticuleRay(int i);
+ void DrawParticuleSphere(int i);
+ void DrawParticuleCylinder(int i);
+ void DrawParticuleWheel(int i);
+ CObject* SearchObjectGun(Math::Vector old, Math::Vector pos, ParticuleType type, CObject *father);
+ CObject* SearchObjectRay(Math::Vector pos, Math::Vector goal, ParticuleType type, CObject *father);
+ void Play(Sound sound, Math::Vector pos, float amplitude);
+ bool TrackMove(int i, Math::Vector pos, float progress);
+ void TrackDraw(int i, ParticuleType type);
+
+protected:
+ CInstanceManager* m_iMan;
+ CEngine* m_engine;
+ CDevice* m_pDevice;
+ CRobotMain* m_main;
+ CTerrain* m_terrain;
+ CWater* m_water;
+ CSound* m_sound;
+
+ Particule m_particule[MAXPARTICULE*MAXPARTITYPE];
+ Gfx::Triangle m_triangle[MAXPARTICULE]; // triangle if PartiType == 0
+ Track m_track[MAXTRACK];
+ int m_wheelTraceTotal;
+ int m_wheelTraceIndex;
+ WheelTrace m_wheelTrace[MAXWHEELTRACE];
+ int m_totalInterface[MAXPARTITYPE][SH_MAX];
+ bool m_bFrameUpdate[SH_MAX];
+ int m_fogTotal;
+ int m_fog[MAXPARTIFOG];
+ int m_uniqueStamp;
+ int m_exploGunCounter;
+ float m_lastTimeGunDel;
+ float m_absTime;
+};
+
}; // namespace Gfx
diff --git a/src/graphics/common/planet.h b/src/graphics/common/planet.h
index 537ca0b..2bf4d99 100644
--- a/src/graphics/common/planet.h
+++ b/src/graphics/common/planet.h
@@ -19,9 +19,63 @@
#pragma once
+#include "common/struct.h"
+#include "common/event.h"
+#include "math/point.h"
+
+
+class CInstanceManager;
+
namespace Gfx {
-// TODO CPlanet
+class CEngine;
+
+
+const short MAXPLANET = 10;
+
+struct Planet
+{
+ char bUsed; // TRUE -> planet exists
+ Math::Point start; // initial position in degrees
+ Math::Point angle; // current position in degrees
+ float dim; // dimensions (0..1)
+ float speed; // speed
+ float dir; // direction in the sky
+ char name[20]; // name of the texture
+ Math::Point uv1, uv2; // texture mapping
+ char bTGA; // texture .TGA
+};
+
+
+
+
+class CPlanet {
+public:
+ CPlanet(CInstanceManager* iMan, CEngine* engine);
+ ~CPlanet();
+
+ void Flush();
+ bool EventProcess(const Event &event);
+ bool Create(int mode, Math::Point start, float dim, float speed, float dir, char *name, Math::Point uv1, Math::Point uv2);
+ bool PlanetExist();
+ void LoadTexture();
+ void Draw();
+ void SetMode(int mode);
+ int RetMode();
+
+protected:
+ bool EventFrame(const Event &event);
+
+protected:
+ CInstanceManager* m_iMan;
+ CEngine* m_engine;
+
+ float m_time;
+ int m_mode;
+ Planet m_planet[2][MAXPLANET];
+ bool m_bPlanetExist;
+};
+
}; // namespace Gfx
diff --git a/src/graphics/common/pyro.h b/src/graphics/common/pyro.h
index 4c5c318..704febf 100644
--- a/src/graphics/common/pyro.h
+++ b/src/graphics/common/pyro.h
@@ -19,9 +19,155 @@
#pragma once
+#include "graphics/common/engine.h"
+#include "object/object.h"
+#include "common/misc.h"
+
+
+class CInstanceManager;
+class CObject;
+class CDisplayText;
+class CRobotMain;
+class CSound;
+
namespace Gfx {
-// TODO CPyro
+class CEngine;
+class CTerrain;
+class CCamera;
+class CParticle;
+class CLight;
+
+
+enum PyroType
+{
+ PT_NULL = 0,
+ PT_FRAGT = 1, // fragmentation of technical object
+ PT_FRAGO = 2, // fragmentation of organic object
+ PT_FRAGW = 4, // fragmentation of object under water
+ PT_EXPLOT = 5, // explosion of technical object
+ PT_EXPLOO = 6, // explosion of organic object
+ PT_EXPLOW = 8, // explosion of object under water
+ PT_SHOTT = 9, // hit technical object
+ PT_SHOTH = 10, // hit human
+ PT_SHOTM = 11, // hit queen
+ PT_SHOTW = 12, // hit under water
+ PT_EGG = 13, // break the egg
+ PT_BURNT = 14, // burning of technical object
+ PT_BURNO = 15, // burning of organic object
+ PT_SPIDER = 16, // spider explosion
+ PT_FALL = 17, // cargo falling
+ PT_WPCHECK = 18, // indicator reaches
+ PT_FLCREATE = 19, // flag create
+ PT_FLDELETE = 20, // flag destroy
+ PT_RESET = 21, // reset position of the object
+ PT_WIN = 22, // fireworks
+ PT_LOST = 23, // black smoke
+ PT_DEADG = 24, // shooting death
+ PT_DEADW = 25, // drowning death
+ PT_FINDING = 26, // object discovered
+};
+
+
+struct PyroBurnPart
+{
+ int part;
+ Math::Vector initialPos;
+ Math::Vector finalPos;
+ Math::Vector initialAngle;
+ Math::Vector finalAngle;
+};
+
+struct PyroLightOper
+{
+ float progress;
+ float intensity;
+ Gfx::Color color;
+};
+
+
+
+class CPyro {
+public:
+ CPyro(CInstanceManager* iMan);
+ ~CPyro();
+
+ void DeleteObject(bool bAll=FALSE);
+ bool Create(PyroType type, CObject* pObj, float force=1.0f);
+ bool EventProcess(const Event &event);
+ Error IsEnded();
+ void CutObjectLink(CObject* pObj);
+
+protected:
+ void DisplayError(PyroType type, CObject* pObj);
+ bool CreateLight(Math::Vector pos, float height);
+ void DeleteObject(bool bPrimary, bool bSecondary);
+
+ void CreateTriangle(CObject* pObj, ObjectType oType, int part);
+
+ void ExploStart();
+ void ExploTerminate();
+
+ void BurnStart();
+ void BurnAddPart(int part, Math::Vector pos, Math::Vector angle);
+ void BurnProgress();
+ bool BurnIsKeepPart(int part);
+ void BurnTerminate();
+
+ void FallStart();
+ CObject* FallSearchBeeExplo();
+ void FallProgress(float rTime);
+ Error FallIsEnded();
+
+ void LightOperFlush();
+ void LightOperAdd(float progress, float intensity, float r, float g, float b);
+ void LightOperFrame(float rTime);
+
+protected:
+ CInstanceManager* m_iMan;
+ CEngine* m_engine;
+ CTerrain* m_terrain;
+ CCamera* m_camera;
+ CParticle* m_particule;
+ CLight* m_light;
+ CObject* m_object;
+ CDisplayText* m_displayText;
+ CRobotMain* m_main;
+ CSound* m_sound;
+
+ Math::Vector m_pos; // center of the effect
+ Math::Vector m_posPower; // center of the battery
+ bool m_bPower; // battery exists?
+ PyroType m_type;
+ float m_force;
+ float m_size;
+ float m_progress;
+ float m_speed;
+ float m_time;
+ float m_lastParticule;
+ float m_lastParticuleSmoke;
+ int m_soundChannel;
+
+ int m_lightRank;
+ int m_lightOperTotal;
+ PyroLightOper m_lightOper[10];
+ float m_lightHeight;
+
+ ObjectType m_burnType;
+ int m_burnPartTotal;
+ PyroBurnPart m_burnPart[10];
+ int m_burnKeepPart[10];
+ float m_burnFall;
+
+ float m_fallFloor;
+ float m_fallSpeed;
+ float m_fallBulletTime;
+ bool m_bFallEnding;
+
+ int m_crashSphereUsed; // number of spheres used
+ Math::Vector m_crashSpherePos[50];
+ float m_crashSphereRadius[50];
+};
}; // namespace Gfx
diff --git a/src/graphics/common/terrain.h b/src/graphics/common/terrain.h
index b527735..5ccc992 100644
--- a/src/graphics/common/terrain.h
+++ b/src/graphics/common/terrain.h
@@ -19,9 +19,193 @@
#pragma once
+#include "graphics/common/engine.h"
+
+
+class CInstanceManager;
+
namespace Gfx {
-// TODO CTerrain
+class CEngine;
+class CWater;
+
+
+const short FLATLIMIT = (5.0f*Math::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,
+};
+
+
+const short MAXBUILDINGLEVEL = 100;
+
+struct BuildingLevel
+{
+ Math::Vector center;
+ float factor;
+ float min;
+ float max;
+ float level;
+ float height;
+ float bboxMinX;
+ float bboxMaxX;
+ float bboxMinZ;
+ float bboxMaxZ;
+};
+
+
+const short MAXMATTERRAIN = 100;
+
+struct TerrainMaterial
+{
+ short id;
+ char texName[20];
+ float u,v;
+ float hardness;
+ char mat[4]; // up, right, down, left
+};
+
+struct DotLevel
+{
+ short id;
+ char mat[4]; // up, right, down, left
+};
+
+
+const short MAXFLYINGLIMIT = 10;
+
+struct FlyingLimit
+{
+ Math::Vector center;
+ float extRadius;
+ float intRadius;
+ float maxHeight;
+};
+
+
+
+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, Math::Vector 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 Math::Vector &p1, const Math::Vector &p2, float height);
+
+ void SetWind(Math::Vector speed);
+ Math::Vector RetWind();
+
+ float RetFineSlope(const Math::Vector &pos);
+ float RetCoarseSlope(const Math::Vector &pos);
+ bool GetNormal(Math::Vector &n, const Math::Vector &p);
+ float RetFloorLevel(const Math::Vector &p, bool bBrut=false, bool bWater=false);
+ float RetFloorHeight(const Math::Vector &p, bool bBrut=false, bool bWater=false);
+ bool MoveOnFloor(Math::Vector &p, bool bBrut=false, bool bWater=false);
+ bool ValidPosition(Math::Vector &p, float marging);
+ TerrainRes RetResource(const Math::Vector &p);
+ void LimitPos(Math::Vector &pos);
+
+ void FlushBuildingLevel();
+ bool AddBuildingLevel(Math::Vector center, float min, float max, float height, float factor);
+ bool UpdateBuildingLevel(Math::Vector center);
+ bool DeleteBuildingLevel(Math::Vector center);
+ float RetBuildingFactor(const Math::Vector &p);
+ float RetHardness(const Math::Vector &p);
+
+ int RetMosaic();
+ int RetBrick();
+ float RetSize();
+ float RetScaleRelief();
+
+ void GroundFlat(Math::Vector pos);
+ float RetFlatZoneRadius(Math::Vector center, float max);
+
+ void SetFlyingMaxHeight(float height);
+ float RetFlyingMaxHeight();
+ void FlushFlyingLimit();
+ bool AddFlyingLimit(Math::Vector center, float extRadius, float intRadius, float maxHeight);
+ float RetFlyingLimit(Math::Vector pos, bool bNoLimit);
+
+protected:
+ bool ReliefAddDot(Math::Vector pos, float scaleRelief);
+ void AdjustRelief();
+ Math::Vector RetVector(int x, int y);
+ Gfx::VertexTex2 RetVertex(int x, int y, int step);
+ bool CreateMosaic(int ox, int oy, int step, int objRank, const Gfx::Material &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, Math::Point &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(Math::Vector &p);
+
+protected:
+ CInstanceManager* m_iMan;
+ CEngine* m_engine;
+ CWater* m_water;
+
+ int m_mosaic; // number of mosaics
+ int m_brick; // number of bricks per mosaics
+ float m_size; // size of an item in an brick
+ float m_vision; // vision before a change of resolution
+ float* m_relief; // table of the relief
+ int* m_texture; // table of textures
+ int* m_objRank; // table of rows of objects
+ bool m_bMultiText;
+ bool m_bLevelText;
+ float m_scaleMapping; // scale of the mapping
+ float m_scaleRelief;
+ int m_subdivMapping;
+ int m_depth; // number of different resolutions (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;
+ Math::Vector m_wind; // wind speed
+
+ float m_flyingMaxHeight;
+ int m_flyingLimitTotal;
+ FlyingLimit m_flyingLimit[MAXFLYINGLIMIT];
+};
}; // namespace Gfx
diff --git a/src/graphics/common/text.h b/src/graphics/common/text.h
index 08fc6dd..65b6772 100644
--- a/src/graphics/common/text.h
+++ b/src/graphics/common/text.h
@@ -19,9 +19,95 @@
#pragma once
+#include "graphics/common/engine.h"
+#include "graphics/common/device.h"
+#include "math/point.h"
+
+
+class CInstanceManager;
+
namespace Gfx {
-// TODO CText
+const float SMALLFONT = 10.0f;
+const float BIGFONT = 15.0f;
+
+const float NORMSTRETCH = 0.8f;
+
+
+
+enum FontType
+{
+ FONT_COLOBOT = 0,
+ FONT_COURIER = 1,
+ FONT_BUTTON = 2,
+};
+
+enum FontTitle
+{
+ TITLE_BIG = 0x04,
+ TITLE_NORM = 0x08,
+ TITLE_LITTLE = 0x0c,
+};
+
+enum FontColor
+{
+ COLOR_LINK = 0x10,
+ COLOR_TOKEN = 0x20,
+ COLOR_TYPE = 0x30,
+ COLOR_CONST = 0x40,
+ COLOR_REM = 0x50,
+ COLOR_KEY = 0x60,
+ COLOR_TABLE = 0x70,
+};
+
+const short FONT_MASK = 0x03;
+const short TITLE_MASK = 0x0c;
+const short COLOR_MASK = 0x70;
+const short IMAGE_MASK = 0x80;
+
+
+
+class CText {
+public:
+ CText(CInstanceManager *iMan, Gfx::CEngine* engine);
+ ~CText();
+
+ void SetGLDevice(Gfx::CDevice device);
+
+ void DrawText(char *string, char *format, int len, Math::Point pos, float width, int justif, float size, float stretch, int eol);
+ void DrawText(char *string, char *format, Math::Point pos, float width, int justif, float size, float stretch, int eol);
+ void DrawText(char *string, int len, Math::Point pos, float width, int justif, float size, float stretch, FontType font, int eol);
+ void DrawText(char *string, Math::Point pos, float width, int justif, float size, float stretch, FontType font, int eol);
+ void DimText(char *string, char *format, int len, Math::Point pos, int justif, float size, float stretch, Math::Point &start, Math::Point &end);
+ void DimText(char *string, char *format, Math::Point pos, int justif, float size, float stretch, Math::Point &start, Math::Point &end);
+ void DimText(char *string, int len, Math::Point pos, int justif, float size, float stretch, FontType font, Math::Point &start, Math::Point &end);
+ void DimText(char *string, Math::Point pos, int justif, float size, float stretch, FontType font, Math::Point &start, Math::Point &end);
+
+ float RetAscent(float size, FontType font);
+ float RetDescent(float size, FontType font);
+ float RetHeight(float size, FontType font);
+
+ float RetStringWidth(char *string, char *format, int len, float size, float stretch);
+ float RetStringWidth(char *string, int len, float size, float stretch, FontType font);
+ float RetCharWidth(int character, float offset, float size, float stretch, FontType font);
+
+ int Justif(char *string, char *format, int len, float width, float size, float stretch);
+ int Justif(char *string, int len, float width, float size, float stretch, FontType font);
+ int Detect(char *string, char *format, int len, float offset, float size, float stretch);
+ int Detect(char *string, int len, float offset, float size, float stretch, FontType font);
+
+protected:
+ void DrawString(char *string, char *format, int len, Math::Point pos, float width, float size, float stretch, int eol);
+ void DrawString(char *string, int len, Math::Point pos, float width, float size, float stretch, FontType font, int eol);
+ void DrawColor(Math::Point pos, float size, float width, int color);
+ void DrawChar(int character, Math::Point pos, float size, float stretch, FontType font);
+
+protected:
+ CInstanceManager* m_iMan;
+ Gfx::CEngine* m_engine;
+ Gfx::CDevice m_pDevice;
+
+};
}; // namespace Gfx
diff --git a/src/graphics/common/water.h b/src/graphics/common/water.h
index 239b1b2..aaf5ec9 100644
--- a/src/graphics/common/water.h
+++ b/src/graphics/common/water.h
@@ -19,9 +19,116 @@
#pragma once
+#include "graphics/common/engine.h"
+#include "graphics/common/particle.h"
+#include "common/event.h"
+
+
+class CInstanceManager;
+class CSound;
+
namespace Gfx {
-// TODO CWater
+class CTerrain;
+
+
+const short MAXWATERLINE = 500;
+
+struct WaterLine
+{
+ short x, y; // beginning
+ short len; // length by x
+ float px1, px2, pz;
+};
+
+
+const short MAXWATVAPOR = 10;
+
+struct WaterVapor
+{
+ bool bUsed;
+ ParticuleType type;
+ Math::Vector pos;
+ float delay;
+ float time;
+ float last;
+};
+
+
+enum WaterType
+{
+ WATER_NULL = 0, // no water
+ WATER_TT = 1, // transparent texture
+ WATER_TO = 2, // opaque texture
+ WATER_CT = 3, // transparent color
+ WATER_CO = 4, // opaque color
+};
+
+
+class CWater
+{
+public:
+ CWater(CInstanceManager* iMan, Gfx::CEngine* engine);
+ ~CWater();
+
+ void SetGLDevice(Gfx::CDevice device);
+ bool EventProcess(const Event &event);
+ void Flush();
+ bool Create(WaterType type1, WaterType type2, const char *filename, Gfx::Color diffuse, Gfx::Color ambient, float level, float glint, Math::Vector eddy);
+ void DrawBack();
+ void DrawSurf();
+
+ bool SetLevel(float level);
+ float RetLevel();
+ float RetLevel(CObject* object);
+
+ void SetLava(bool bLava);
+ bool RetLava();
+
+ void AdjustEye(Math::Vector &eye);
+
+protected:
+ bool EventFrame(const Event &event);
+ void LavaFrame(float rTime);
+ void AdjustLevel(Math::Vector &pos, Math::Vector &norm, Math::Point &uv1, Math::Point &uv2);
+ bool RetWater(int x, int y);
+ bool CreateLine(int x, int y, int len);
+
+ void VaporFlush();
+ bool VaporCreate(ParticuleType type, Math::Vector pos, float delay);
+ void VaporFrame(int i, float rTime);
+
+protected:
+ CInstanceManager* m_iMan;
+ CEngine* m_engine;
+ CDevice* m_pDevice;
+ CTerrain* m_terrain;
+ CParticle* m_particule;
+ CSound* m_sound;
+
+ WaterType m_type[2];
+ char m_filename[100];
+ float m_level; // overall level
+ float m_glint; // amplitude of reflections
+ Math::Vector m_eddy; // amplitude of swirls
+ Gfx::Color m_diffuse; // diffuse color
+ Gfx::Color m_ambient; // ambient color
+ float m_time;
+ float m_lastLava;
+ int m_subdiv;
+
+ int m_brick; // number of brick*mosaics
+ float m_size; // size of a item in an brick
+
+ int m_lineUsed;
+ WaterLine m_line[MAXWATERLINE];
+
+ WaterVapor m_vapor[MAXWATVAPOR];
+
+ bool m_bDraw;
+ bool m_bLava;
+ long m_color;
+};
}; // namespace Gfx
diff --git a/src/object/motion/motionant.cpp b/src/object/motion/motionant.cpp
index 7c01c8a..c85a631 100644
--- a/src/object/motion/motionant.cpp
+++ b/src/object/motion/motionant.cpp
@@ -21,7 +21,7 @@
#include "object/motion/motionant.h"
-#include "common/modfile.h"
+#include "old/modfile.h"
#include "old/particule.h"
#include "physics/physics.h"
diff --git a/src/object/motion/motionbee.cpp b/src/object/motion/motionbee.cpp
index 0a84662..c5d9ed2 100644
--- a/src/object/motion/motionbee.cpp
+++ b/src/object/motion/motionbee.cpp
@@ -21,7 +21,7 @@
#include "object/motion/motionbee.h"
-#include "common/modfile.h"
+#include "old/modfile.h"
#include "physics/physics.h"
diff --git a/src/object/motion/motionhuman.cpp b/src/object/motion/motionhuman.cpp
index 3b04378..6bdcf7e 100644
--- a/src/object/motion/motionhuman.cpp
+++ b/src/object/motion/motionhuman.cpp
@@ -21,7 +21,7 @@
#include "object/motion/motionhuman.h"
-#include "common/modfile.h"
+#include "old/modfile.h"
#include "old/terrain.h"
#include "old/water.h"
#include "math/geometry.h"
diff --git a/src/object/motion/motionmother.cpp b/src/object/motion/motionmother.cpp
index 4c2e68c..26e28d5 100644
--- a/src/object/motion/motionmother.cpp
+++ b/src/object/motion/motionmother.cpp
@@ -21,7 +21,7 @@
#include "object/motion/motionmother.h"
-#include "common/modfile.h"
+#include "old/modfile.h"
#include "physics/physics.h"
diff --git a/src/object/motion/motionspider.cpp b/src/object/motion/motionspider.cpp
index 93ba7e6..fa5d649 100644
--- a/src/object/motion/motionspider.cpp
+++ b/src/object/motion/motionspider.cpp
@@ -21,7 +21,7 @@
#include "object/motion/motionspider.h"
-#include "common/modfile.h"
+#include "old/modfile.h"
#include "old/particule.h"
#include "physics/physics.h"
diff --git a/src/object/motion/motiontoto.cpp b/src/object/motion/motiontoto.cpp
index d6a8f6b..71e872a 100644
--- a/src/object/motion/motiontoto.cpp
+++ b/src/object/motion/motiontoto.cpp
@@ -24,7 +24,7 @@
#include "math/geometry.h"
#include "old/terrain.h"
#include "old/water.h"
-#include "common/modfile.h"
+#include "old/modfile.h"
#include "object/robotmain.h"
diff --git a/src/object/motion/motionvehicle.cpp b/src/object/motion/motionvehicle.cpp
index d4e3007..6f96991 100644
--- a/src/object/motion/motionvehicle.cpp
+++ b/src/object/motion/motionvehicle.cpp
@@ -21,7 +21,7 @@
#include "object/motion/motionvehicle.h"
-#include "common/modfile.h"
+#include "old/modfile.h"
#include "old/particule.h"
#include "old/terrain.h"
#include "math/geometry.h"
diff --git a/src/object/motion/motionworm.cpp b/src/object/motion/motionworm.cpp
index 8409fc6..a18b7c4 100644
--- a/src/object/motion/motionworm.cpp
+++ b/src/object/motion/motionworm.cpp
@@ -21,7 +21,7 @@
#include "object/motion/motionworm.h"
-#include "common/modfile.h"
+#include "old/modfile.h"
#include "old/particule.h"
#include "old/terrain.h"
#include "math/geometry.h"
diff --git a/src/object/object.cpp b/src/object/object.cpp
index e6c2663..10cc190 100644
--- a/src/object/object.cpp
+++ b/src/object/object.cpp
@@ -53,7 +53,7 @@
#include "object/motion/motionspider.h"
#include "object/motion/motionbee.h"
#include "object/motion/motionworm.h"
-#include "common/modfile.h"
+#include "old/modfile.h"
#include "object/auto/auto.h"
#include "object/auto/autobase.h"
#include "object/auto/autoportico.h"
diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp
index 66a613e..a897349 100644
--- a/src/object/robotmain.cpp
+++ b/src/object/robotmain.cpp
@@ -50,7 +50,7 @@
#include "physics/physics.h"
#include "object/brain.h"
#include "old/pyro.h"
-#include "common/modfile.h"
+#include "old/modfile.h"
#include "old/model.h"
#include "old/camera.h"
#include "object/task/task.h"
diff --git a/src/old/model.cpp b/src/old/model.cpp
index 3570df4..23ea6f5 100644
--- a/src/old/model.cpp
+++ b/src/old/model.cpp
@@ -36,7 +36,7 @@
#include "ui/edit.h"
#include "ui/button.h"
#include "script/cmdtoken.h"
-#include "common/modfile.h"
+#include "old/modfile.h"
#include "old/model.h"
diff --git a/src/old/model.h b/src/old/model.h
index 74914f0..9acfbbc 100644
--- a/src/old/model.h
+++ b/src/old/model.h
@@ -20,7 +20,7 @@
#include "common/event.h"
-#include "common/modfile.h"
+#include "old/modfile.h"
#include "math/point.h"
diff --git a/src/old/modfile.cpp b/src/old/modfile.cpp
new file mode 100644
index 0000000..fa0b0be
--- /dev/null
+++ b/src/old/modfile.cpp
@@ -0,0 +1,695 @@
+// * This file is part of the COLOBOT source code
+// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
+// *
+// * This program is free software: you can redistribute it and/or modify
+// * it under the terms of the GNU General Public License as published by
+// * the Free Software Foundation, either version 3 of the License, or
+// * (at your option) any later version.
+// *
+// * This program is distributed in the hope that it will be useful,
+// * but WITHOUT ANY WARRANTY; without even the implied warranty of
+// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// * GNU General Public License for more details.
+// *
+// * You should have received a copy of the GNU General Public License
+// * along with this program. If not, see http://www.gnu.org/licenses/.
+
+// modfile.cpp
+
+
+#include <windows.h>
+#include <stdio.h>
+#include <d3d.h>
+
+#include "common/struct.h"
+#include "math/geometry.h"
+#include "old/d3dengine.h"
+#include "old/d3dmath.h"
+#include "common/language.h"
+#include "common/event.h"
+#include "common/misc.h"
+#include "common/iman.h"
+#include "old/math3d.h"
+#include "modfile.h"
+
+
+
+const int MAX_VERTICES = 2000;
+
+
+
+// Object's constructor.
+
+CModFile::CModFile(CInstanceManager* iMan)
+{
+ m_iMan = iMan;
+
+ m_engine = (CD3DEngine*)m_iMan->SearchInstance(CLASS_ENGINE);
+
+ m_triangleUsed = 0;
+ m_triangleTable = (ModelTriangle*)malloc(sizeof(ModelTriangle)*MAX_VERTICES);
+ ZeroMemory(m_triangleTable, sizeof(ModelTriangle)*MAX_VERTICES);
+}
+
+// Object's destructor.
+
+CModFile::~CModFile()
+{
+ free(m_triangleTable);
+}
+
+
+
+
+// Creates a triangle in the internal structure.
+
+bool CModFile::CreateTriangle(Math::Vector p1, Math::Vector p2, Math::Vector p3,
+ float min, float max)
+{
+ Math::Vector n;
+ int i;
+
+ if ( m_triangleUsed >= MAX_VERTICES )
+ {
+ OutputDebugString("ERROR: CreateTriangle::Too many triangles\n");
+ return false;
+ }
+
+ i = m_triangleUsed++;
+
+ ZeroMemory(&m_triangleTable[i], sizeof(ModelTriangle));
+
+ m_triangleTable[i].bUsed = true;
+ m_triangleTable[i].bSelect = false;
+
+ n = Math::NormalToPlane(p3, p2, p1);
+ m_triangleTable[i].p1 = D3DVERTEX2( p1, n);
+ m_triangleTable[i].p2 = D3DVERTEX2( p2, n);
+ m_triangleTable[i].p3 = D3DVERTEX2( p3, n);
+
+ m_triangleTable[i].material.diffuse.r = 1.0f;
+ m_triangleTable[i].material.diffuse.g = 1.0f;
+ m_triangleTable[i].material.diffuse.b = 1.0f; // white
+ m_triangleTable[i].material.ambient.r = 0.5f;
+ m_triangleTable[i].material.ambient.g = 0.5f;
+ m_triangleTable[i].material.ambient.b = 0.5f;
+
+ m_triangleTable[i].min = min;
+ m_triangleTable[i].max = max;
+
+ return true;
+}
+
+// Reads a DXF file.
+
+bool CModFile::ReadDXF(char *filename, float min, float max)
+{
+ FILE* file = NULL;
+ char line[100];
+ int command, rankSommet, nbSommet, nbFace;
+ Math::Vector table[MAX_VERTICES];
+ bool bWaitNbSommet;
+ bool bWaitNbFace;
+ bool bWaitSommetX;
+ bool bWaitSommetY;
+ bool bWaitSommetZ;
+ bool bWaitFaceX;
+ bool bWaitFaceY;
+ bool bWaitFaceZ;
+ float x,y,z;
+ int p1,p2,p3;
+
+ file = fopen(filename, "r");
+ if ( file == NULL ) return false;
+
+ m_triangleUsed = 0;
+
+ rankSommet = 0;
+ bWaitNbSommet = false;
+ bWaitNbFace = false;
+ bWaitSommetX = false;
+ bWaitSommetY = false;
+ bWaitSommetZ = false;
+ bWaitFaceX = false;
+ bWaitFaceY = false;
+ bWaitFaceZ = false;
+
+ while ( fgets(line, 100, file) != NULL )
+ {
+ sscanf(line, "%d", &command);
+ if ( fgets(line, 100, file) == NULL ) break;
+
+ if ( command == 66 )
+ {
+ bWaitNbSommet = true;
+ }
+
+ if ( command == 71 && bWaitNbSommet )
+ {
+ bWaitNbSommet = false;
+ sscanf(line, "%d", &nbSommet);
+ if ( nbSommet > MAX_VERTICES ) nbSommet = MAX_VERTICES;
+ rankSommet = 0;
+ bWaitNbFace = true;
+
+//? sprintf(s, "Waiting for %d sommets\n", nbSommet);
+//? OutputDebugString(s);
+ }
+
+ if ( command == 72 && bWaitNbFace )
+ {
+ bWaitNbFace = false;
+ sscanf(line, "%d", &nbFace);
+ bWaitSommetX = true;
+
+//? sprintf(s, "Waiting for %d faces\n", nbFace);
+//? OutputDebugString(s);
+ }
+
+ if ( command == 10 && bWaitSommetX )
+ {
+ bWaitSommetX = false;
+ sscanf(line, "%f", &x);
+ bWaitSommetY = true;
+ }
+
+ if ( command == 20 && bWaitSommetY )
+ {
+ bWaitSommetY = false;
+ sscanf(line, "%f", &y);
+ bWaitSommetZ = true;
+ }
+
+ if ( command == 30 && bWaitSommetZ )
+ {
+ bWaitSommetZ = false;
+ sscanf(line, "%f", &z);
+
+ nbSommet --;
+ if ( nbSommet >= 0 )
+ {
+ Math::Vector p(x,z,y); // permutation of Y and Z!
+ table[rankSommet++] = p;
+ bWaitSommetX = true;
+
+//? sprintf(s, "Sommet[%d]=%f;%f;%f\n", rankSommet, p.x,p.y,p.z);
+//? OutputDebugString(s);
+ }
+ else
+ {
+ bWaitFaceX = true;
+ }
+ }
+
+ if ( command == 71 && bWaitFaceX )
+ {
+ bWaitFaceX = false;
+ sscanf(line, "%d", &p1);
+ if ( p1 < 0 ) p1 = -p1;
+ bWaitFaceY = true;
+ }
+
+ if ( command == 72 && bWaitFaceY )
+ {
+ bWaitFaceY = false;
+ sscanf(line, "%d", &p2);
+ if ( p2 < 0 ) p2 = -p2;
+ bWaitFaceZ = true;
+ }
+
+ if ( command == 73 && bWaitFaceZ )
+ {
+ bWaitFaceZ = false;
+ sscanf(line, "%d", &p3);
+ if ( p3 < 0 ) p3 = -p3;
+
+ nbFace --;
+ if ( nbFace >= 0 )
+ {
+ CreateTriangle( table[p3-1], table[p2-1], table[p1-1], min,max );
+ bWaitFaceX = true;
+
+//? sprintf(s, "Face=%d;%d;%d\n", p1,p2,p3);
+//? OutputDebugString(s);
+ }
+ }
+
+ }
+
+ fclose(file);
+ return true;
+}
+
+
+
+struct InfoMOD
+{
+ int rev;
+ int vers;
+ int total;
+ int reserve[10];
+};
+
+
+// Change nom.bmp to nom.tga
+
+void ChangeBMPtoTGA(char *filename)
+{
+ char* p;
+
+ p = strstr(filename, ".bmp");
+ if ( p != 0 ) strcpy(p, ".tga");
+}
+
+
+// Reads a MOD file.
+
+bool CModFile::AddModel(char *filename, int first, bool bEdit, bool bMeta)
+{
+ FILE* file;
+ InfoMOD info;
+ float limit[2];
+ int i, nb, err;
+ char* p;
+
+ if ( m_engine->RetDebugMode() )
+ {
+ bMeta = false;
+ }
+
+ if ( bMeta )
+ {
+ p = strchr(filename, '\\');
+ if ( p == 0 )
+ {
+#if _SCHOOL
+ err = g_metafile.Open("ceebot2.dat", filename);
+#else
+ err = g_metafile.Open("colobot2.dat", filename);
+#endif
+ }
+ else
+ {
+#if _SCHOOL
+ err = g_metafile.Open("ceebot2.dat", p+1);
+#else
+ err = g_metafile.Open("colobot2.dat", p+1);
+#endif
+ }
+ if ( err != 0 ) bMeta = false;
+ }
+ if ( !bMeta )
+ {
+ file = fopen(filename, "rb");
+ if ( file == NULL ) return false;
+ }
+
+ if ( bMeta )
+ {
+ g_metafile.Read(&info, sizeof(InfoMOD));
+ }
+ else
+ {
+ fread(&info, sizeof(InfoMOD), 1, file);
+ }
+ nb = info.total;
+ m_triangleUsed += nb;
+
+ if ( info.rev == 1 && info.vers == 0 )
+ {
+ OldModelTriangle1 old;
+
+ for ( i=first ; i<m_triangleUsed ; i++ )
+ {
+ if ( bMeta )
+ {
+ g_metafile.Read(&old, sizeof(OldModelTriangle1));
+ }
+ else
+ {
+ fread(&old, sizeof(OldModelTriangle1), 1, file);
+ }
+
+ ZeroMemory(&m_triangleTable[i], sizeof(ModelTriangle));
+ m_triangleTable[i].bUsed = old.bUsed;
+ m_triangleTable[i].bSelect = old.bSelect;
+
+ m_triangleTable[i].p1.x = old.p1.x;
+ m_triangleTable[i].p1.y = old.p1.y;
+ m_triangleTable[i].p1.z = old.p1.z;
+ m_triangleTable[i].p1.nx = old.p1.nx;
+ m_triangleTable[i].p1.ny = old.p1.ny;
+ m_triangleTable[i].p1.nz = old.p1.nz;
+ m_triangleTable[i].p1.tu = old.p1.tu;
+ m_triangleTable[i].p1.tv = old.p1.tv;
+
+ m_triangleTable[i].p2.x = old.p2.x;
+ m_triangleTable[i].p2.y = old.p2.y;
+ m_triangleTable[i].p2.z = old.p2.z;
+ m_triangleTable[i].p2.nx = old.p2.nx;
+ m_triangleTable[i].p2.ny = old.p2.ny;
+ m_triangleTable[i].p2.nz = old.p2.nz;
+ m_triangleTable[i].p2.tu = old.p2.tu;
+ m_triangleTable[i].p2.tv = old.p2.tv;
+
+ m_triangleTable[i].p3.x = old.p3.x;
+ m_triangleTable[i].p3.y = old.p3.y;
+ m_triangleTable[i].p3.z = old.p3.z;
+ m_triangleTable[i].p3.nx = old.p3.nx;
+ m_triangleTable[i].p3.ny = old.p3.ny;
+ m_triangleTable[i].p3.nz = old.p3.nz;
+ m_triangleTable[i].p3.tu = old.p3.tu;
+ m_triangleTable[i].p3.tv = old.p3.tv;
+
+ m_triangleTable[i].material = old.material;
+ strcpy(m_triangleTable[i].texName, old.texName);
+ m_triangleTable[i].min = old.min;
+ m_triangleTable[i].max = old.max;
+ }
+ }
+ else if ( info.rev == 1 && info.vers == 1 )
+ {
+ OldModelTriangle2 old;
+
+ for ( i=first ; i<m_triangleUsed ; i++ )
+ {
+ if ( bMeta )
+ {
+ g_metafile.Read(&old, sizeof(OldModelTriangle2));
+ }
+ else
+ {
+ fread(&old, sizeof(OldModelTriangle2), 1, file);
+ }
+
+ ZeroMemory(&m_triangleTable[i], sizeof(ModelTriangle));
+ m_triangleTable[i].bUsed = old.bUsed;
+ m_triangleTable[i].bSelect = old.bSelect;
+
+ m_triangleTable[i].p1.x = old.p1.x;
+ m_triangleTable[i].p1.y = old.p1.y;
+ m_triangleTable[i].p1.z = old.p1.z;
+ m_triangleTable[i].p1.nx = old.p1.nx;
+ m_triangleTable[i].p1.ny = old.p1.ny;
+ m_triangleTable[i].p1.nz = old.p1.nz;
+ m_triangleTable[i].p1.tu = old.p1.tu;
+ m_triangleTable[i].p1.tv = old.p1.tv;
+
+ m_triangleTable[i].p2.x = old.p2.x;
+ m_triangleTable[i].p2.y = old.p2.y;
+ m_triangleTable[i].p2.z = old.p2.z;
+ m_triangleTable[i].p2.nx = old.p2.nx;
+ m_triangleTable[i].p2.ny = old.p2.ny;
+ m_triangleTable[i].p2.nz = old.p2.nz;
+ m_triangleTable[i].p2.tu = old.p2.tu;
+ m_triangleTable[i].p2.tv = old.p2.tv;
+
+ m_triangleTable[i].p3.x = old.p3.x;
+ m_triangleTable[i].p3.y = old.p3.y;
+ m_triangleTable[i].p3.z = old.p3.z;
+ m_triangleTable[i].p3.nx = old.p3.nx;
+ m_triangleTable[i].p3.ny = old.p3.ny;
+ m_triangleTable[i].p3.nz = old.p3.nz;
+ m_triangleTable[i].p3.tu = old.p3.tu;
+ m_triangleTable[i].p3.tv = old.p3.tv;
+
+ m_triangleTable[i].material = old.material;
+ strcpy(m_triangleTable[i].texName, old.texName);
+ m_triangleTable[i].min = old.min;
+ m_triangleTable[i].max = old.max;
+ m_triangleTable[i].state = old.state;
+ m_triangleTable[i].reserve2 = old.reserve2;
+ m_triangleTable[i].reserve3 = old.reserve3;
+ m_triangleTable[i].reserve4 = old.reserve4;
+ }
+ }
+ else
+ {
+ if ( bMeta )
+ {
+ g_metafile.Read(m_triangleTable+first, sizeof(ModelTriangle)*nb);
+ }
+ else
+ {
+ fread(m_triangleTable+first, sizeof(ModelTriangle), nb, file);
+ }
+ }
+
+ for ( i=first ; i<m_triangleUsed ; i++ )
+ {
+ ChangeBMPtoTGA(m_triangleTable[i].texName);
+ }
+
+ if ( !bEdit )
+ {
+ limit[0] = m_engine->RetLimitLOD(0); // frontier AB as config
+ limit[1] = m_engine->RetLimitLOD(1); // frontier BC as config
+
+ // Standard frontiers -> config.
+ for ( i=first ; i<m_triangleUsed ; i++ )
+ {
+ if ( m_triangleTable[i].min == 0.0f &&
+ m_triangleTable[i].max == 100.0f ) // resolution A ?
+ {
+ m_triangleTable[i].max = limit[0];
+ }
+ else if ( m_triangleTable[i].min == 100.0f &&
+ m_triangleTable[i].max == 200.0f ) // resolution B ?
+ {
+ m_triangleTable[i].min = limit[0];
+ m_triangleTable[i].max = limit[1];
+ }
+ else if ( m_triangleTable[i].min == 200.0f &&
+ m_triangleTable[i].max == 1000000.0f ) // resolution C ?
+ {
+ m_triangleTable[i].min = limit[1];
+ }
+ }
+ }
+
+ if ( bMeta )
+ {
+ g_metafile.Close();
+ }
+ else
+ {
+ fclose(file);
+ }
+ return true;
+}
+
+// Reads a MOD file.
+
+bool CModFile::ReadModel(char *filename, bool bEdit, bool bMeta)
+{
+ m_triangleUsed = 0;
+ return AddModel(filename, 0, bEdit, bMeta);
+}
+
+
+// Writes a MOD file.
+
+bool CModFile::WriteModel(char *filename)
+{
+ FILE* file;
+ InfoMOD info;
+
+ if ( m_triangleUsed == 0 ) return false;
+
+ file = fopen(filename, "wb");
+ if ( file == NULL ) return false;
+
+ ZeroMemory(&info, sizeof(InfoMOD));
+ info.rev = 1;
+ info.vers = 2;
+ info.total = m_triangleUsed;
+ fwrite(&info, sizeof(InfoMOD), 1, file);
+
+ fwrite(m_triangleTable, sizeof(ModelTriangle), m_triangleUsed, file);
+
+ fclose(file);
+ return true;
+}
+
+
+// Creates the object in the 3D engine.
+
+bool CModFile::CreateEngineObject(int objRank, int addState)
+{
+#if 0
+ char texName2[20];
+ int texNum, i, state;
+
+ for ( i=0 ; i<m_triangleUsed ; i++ )
+ {
+ if ( !m_triangleTable[i].bUsed ) continue;
+
+ state = m_triangleTable[i].state;
+ texName2[0] = 0;
+
+ if ( m_triangleTable[i].texNum2 != 0 )
+ {
+ if ( m_triangleTable[i].texNum2 == 1 )
+ {
+ texNum = m_engine->RetSecondTexture();
+ }
+ else
+ {
+ texNum = m_triangleTable[i].texNum2;
+ }
+
+ if ( texNum >= 1 && texNum <= 10 )
+ {
+ state = m_triangleTable[i].state|D3DSTATEDUALb;
+ }
+ if ( texNum >= 11 && texNum <= 20 )
+ {
+ state = m_triangleTable[i].state|D3DSTATEDUALw;
+ }
+ sprintf(texName2, "dirty%.2d.bmp", texNum);
+ }
+
+ m_engine->AddTriangle(objRank, &m_triangleTable[i].p1, 3,
+ m_triangleTable[i].material,
+ state+addState,
+ m_triangleTable[i].texName, texName2,
+ m_triangleTable[i].min,
+ m_triangleTable[i].max, false);
+ }
+ return true;
+#else
+ char texName1[20];
+ char texName2[20];
+ int texNum, i, state;
+
+ for ( i=0 ; i<m_triangleUsed ; i++ )
+ {
+ if ( !m_triangleTable[i].bUsed ) continue;
+
+ state = m_triangleTable[i].state;
+ strcpy(texName1, m_triangleTable[i].texName);
+ texName2[0] = 0;
+
+ if ( strcmp(texName1, "plant.tga") == 0 )
+ {
+ state |= D3DSTATEALPHA;
+ }
+
+ if ( m_triangleTable[i].texNum2 != 0 )
+ {
+ if ( m_triangleTable[i].texNum2 == 1 )
+ {
+ texNum = m_engine->RetSecondTexture();
+ }
+ else
+ {
+ texNum = m_triangleTable[i].texNum2;
+ }
+
+ if ( texNum >= 1 && texNum <= 10 )
+ {
+ state |= D3DSTATEDUALb;
+ }
+ if ( texNum >= 11 && texNum <= 20 )
+ {
+ state |= D3DSTATEDUALw;
+ }
+ sprintf(texName2, "dirty%.2d.tga", texNum);
+ }
+
+ m_engine->AddTriangle(objRank, &m_triangleTable[i].p1, 3,
+ m_triangleTable[i].material,
+ state+addState,
+ texName1, texName2,
+ m_triangleTable[i].min,
+ m_triangleTable[i].max, false);
+ }
+ return true;
+#endif
+}
+
+
+// Performs a mirror according to Z.
+
+void CModFile::Mirror()
+{
+ D3DVERTEX2 t;
+ int i;
+
+ for ( i=0 ; i<m_triangleUsed ; i++ )
+ {
+ t = m_triangleTable[i].p1;
+ m_triangleTable[i].p1 = m_triangleTable[i].p2;
+ m_triangleTable[i].p2 = t;
+
+ m_triangleTable[i].p1.z = -m_triangleTable[i].p1.z;
+ m_triangleTable[i].p2.z = -m_triangleTable[i].p2.z;
+ m_triangleTable[i].p3.z = -m_triangleTable[i].p3.z;
+
+ m_triangleTable[i].p1.nz = -m_triangleTable[i].p1.nz;
+ m_triangleTable[i].p2.nz = -m_triangleTable[i].p2.nz;
+ m_triangleTable[i].p3.nz = -m_triangleTable[i].p3.nz;
+ }
+}
+
+
+// Returns the pointer to the list of triangles.
+
+void CModFile::SetTriangleUsed(int total)
+{
+ m_triangleUsed = total;
+}
+
+int CModFile::RetTriangleUsed()
+{
+ return m_triangleUsed;
+}
+
+int CModFile::RetTriangleMax()
+{
+ return MAX_VERTICES;
+}
+
+ModelTriangle* CModFile::RetTriangleList()
+{
+ return m_triangleTable;
+}
+
+
+// Returns the height according to a position (x - z);
+
+float CModFile::RetHeight(Math::Vector pos)
+{
+ Math::Vector p1, p2, p3;
+ float limit;
+ int i;
+
+ limit = 5.0f;
+
+ for ( i=0 ; i<m_triangleUsed ; i++ )
+ {
+ if ( !m_triangleTable[i].bUsed ) continue;
+
+ if ( fabs(pos.x-m_triangleTable[i].p1.x) < limit &&
+ fabs(pos.z-m_triangleTable[i].p1.z) < limit )
+ {
+ return m_triangleTable[i].p1.y;
+ }
+
+ if ( fabs(pos.x-m_triangleTable[i].p2.x) < limit &&
+ fabs(pos.z-m_triangleTable[i].p2.z) < limit )
+ {
+ return m_triangleTable[i].p2.y;
+ }
+
+ if ( fabs(pos.x-m_triangleTable[i].p3.x) < limit &&
+ fabs(pos.z-m_triangleTable[i].p3.z) < limit )
+ {
+ return m_triangleTable[i].p3.y;
+ }
+ }
+
+ return 0.0f;
+}
+
+
diff --git a/src/old/modfile.h b/src/old/modfile.h
new file mode 100644
index 0000000..1422687
--- /dev/null
+++ b/src/old/modfile.h
@@ -0,0 +1,115 @@
+// * This file is part of the COLOBOT source code
+// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
+// *
+// * This program is free software: you can redistribute it and/or modify
+// * it under the terms of the GNU General Public License as published by
+// * the Free Software Foundation, either version 3 of the License, or
+// * (at your option) any later version.
+// *
+// * This program is distributed in the hope that it will be useful,
+// * but WITHOUT ANY WARRANTY; without even the implied warranty of
+// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// * GNU General Public License for more details.
+// *
+// * You should have received a copy of the GNU General Public License
+// * along with this program. If not, see http://www.gnu.org/licenses/.
+
+// modfile.h
+
+#pragma once
+
+
+#include "math/vector.h"
+#include "old/d3dengine.h"
+
+
+class CInstanceManager;
+
+
+
+
+struct OldModelTriangle1
+{
+ char bUsed; // true -> using
+ char bSelect; // true -> selected
+ D3DVERTEX p1;
+ D3DVERTEX p2;
+ D3DVERTEX p3;
+ D3DMATERIAL7 material;
+ char texName[20];
+ float min;
+ float max;
+}; // length = 196 bytes
+
+struct OldModelTriangle2
+{
+ char bUsed; // true -> used
+ char bSelect; // true -> selected
+ D3DVERTEX p1;
+ D3DVERTEX p2;
+ D3DVERTEX p3;
+ D3DMATERIAL7 material;
+ char texName[20];
+ float min;
+ float max;
+ long state;
+ short reserve1;
+ short reserve2;
+ short reserve3;
+ short reserve4;
+};
+
+struct ModelTriangle
+{
+ char bUsed; // true -> used
+ char bSelect; // true -> selected
+ D3DVERTEX2 p1;
+ D3DVERTEX2 p2;
+ D3DVERTEX2 p3;
+ D3DMATERIAL7 material;
+ char texName[20];
+ float min;
+ float max;
+ long state;
+ short texNum2;
+ short reserve2;
+ short reserve3;
+ short reserve4;
+}; // length = 208 bytes
+
+
+
+
+class CModFile
+{
+public:
+ CModFile(CInstanceManager* iMan);
+ ~CModFile();
+
+ bool ReadDXF(char *filename, float min, float max);
+ bool AddModel(char *filename, int first, bool bEdit=false, bool bMeta=true);
+ bool ReadModel(char *filename, bool bEdit=false, bool bMeta=true);
+ bool WriteModel(char *filename);
+
+ bool CreateEngineObject(int objRank, int addState=0);
+ void Mirror();
+
+ void SetTriangleUsed(int total);
+ int RetTriangleUsed();
+ int RetTriangleMax();
+ ModelTriangle* RetTriangleList();
+
+ float RetHeight(Math::Vector pos);
+
+protected:
+ bool CreateTriangle(Math::Vector p1, Math::Vector p2, Math::Vector p3, float min, float max);
+
+protected:
+ CInstanceManager* m_iMan;
+ CD3DEngine* m_engine;
+
+ ModelTriangle* m_triangleTable;
+ int m_triangleUsed;
+};
+
+
diff --git a/src/old/terrain.cpp b/src/old/terrain.cpp
index c426883..b558e71 100644
--- a/src/old/terrain.cpp
+++ b/src/old/terrain.cpp
@@ -32,7 +32,7 @@
#include "common/misc.h"
#include "common/iman.h"
#include "old/math3d.h"
-#include "common/modfile.h"
+#include "old/modfile.h"
#include "old/water.h"
#include "old/terrain.h"