Colobot
map.h
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
20 #pragma once
21 
22 #include "ui/controls/control.h"
23 
24 #include "common/event.h"
25 
26 #include "object/object_type.h"
27 
28 class CObject;
29 
30 namespace Gfx
31 {
32 class CWater;
33 class CTerrain;
34 }
35 
36 
37 namespace Ui
38 {
39 
40 const int MAPMAXOBJECT = 100;
41 
42 enum MapColor
43 {
44  MAPCOLOR_NULL,
45  MAPCOLOR_BASE,
46  MAPCOLOR_FIX,
47  MAPCOLOR_MOVE,
48  MAPCOLOR_ALIEN,
49  MAPCOLOR_WAYPOINTb,
50  MAPCOLOR_WAYPOINTr,
51  MAPCOLOR_WAYPOINTg,
52  MAPCOLOR_WAYPOINTy,
53  MAPCOLOR_WAYPOINTv,
54  MAPCOLOR_BBOX,
55 };
56 
57 struct MapObject
58 {
59  bool bUsed = false;
60  CObject* object = nullptr;
61  MapColor color = MAPCOLOR_NULL;
62  ObjectType type = OBJECT_NULL;
63  Math::Point pos;
64  float dir = 0.0f;
65 };
66 
67 
68 
69 class CMap : public CControl
70 {
71 public:
72  CMap();
73  ~CMap();
74 
75  bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) override;
76  bool EventProcess(const Event &event) override;
77  void Draw() override;
78 
79  void UpdateTerrain();
80  void UpdateTerrain(int bx, int by, int ex, int ey);
81 
82  void SetFixImage(const std::string& filename);
83  bool GetFixImage();
84 
85  void SetOffset(float ox, float oy);
86  void SetAngle(float angle);
87  void SetMode(int mode);
88  void SetToy(bool bToy);
89  void SetDebug(bool bDebug);
90 
91  void SetZoom(float value);
92  float GetZoom();
93 
94  void SetEnable(bool bEnable);
95  bool GetEnable();
96 
97  void SetFloorColor(Gfx::Color color);
98  void SetWaterColor(Gfx::Color color);
99 
100  void FlushObject();
101  void UpdateObject(CObject* pObj);
102 
103  CObject* DetectObject(Math::Point pos, bool &bInMap);
104  void SetHighlight(CObject* pObj);
105 
106 protected:
107  Math::Point AdjustOffset(Math::Point offset);
108  void SelectObject(Math::Point pos);
109  Math::Point MapInter(Math::Point pos, float dir);
110  void DrawFocus(Math::Point pos, float dir, ObjectType type, MapColor color);
111  void DrawObject(Math::Point pos, float dir, ObjectType type, MapColor color, bool bSelect, bool bHilite);
112  void DrawObjectIcon(Math::Point pos, Math::Point dim, MapColor color, ObjectType type, bool bHilite);
113  void DrawHighlight(Math::Point pos);
114  void DrawTriangle(Math::Point p1, Math::Point p2, Math::Point p3, Math::Point uv1, Math::Point uv2);
115  void DrawPenta(Math::Point p1, Math::Point p2, Math::Point p3, Math::Point p4, Math::Point p5, Math::Point uv1, Math::Point uv2);
116  void DrawVertex(Math::Point uv1, Math::Point uv2, float zoom);
117 
118 protected:
119  Gfx::CTerrain* m_terrain;
120  Gfx::CWater* m_water;
121  CRobotMain* m_main;
122 
123  bool m_bEnable;
124  float m_time;
125  float m_half;
126  float m_zoom;
127  Math::Point m_offset;
128  float m_angle;
129  Gfx::Color m_floorColor;
130  Gfx::Color m_waterColor;
131  MapObject m_map[MAPMAXOBJECT];
132  int m_totalFix;
133  int m_totalMove;
134  int m_highlightRank;
135  Math::Point m_mapPos;
136  Math::Point m_mapDim;
137  bool m_bRadar;
138  std::string m_fixImage;
139  int m_mode;
140  bool m_bToy;
141  bool m_bDebug;
142 };
143 
144 
145 }
Definition: map.h:69
Definition: robotmain.h:108
ObjectType enum.
Definition: robotmain.h:159
Definition: map.h:57
2D point
Definition: point.h:50
Terrain loader/generator and manager.
Definition: terrain.h:147
Namespace for (new) graphics code.
Definition: app.h:49
Event types, structs and event queue.
ObjectType
Type of game object.
Definition: object_type.h:33
Water manager/renderer.
Definition: water.h:72
RGBA color.
Definition: color.h:39
EventType
Type of event message.
Definition: event.h:41
Event sent by system, interface or game.
Definition: event.h:735
Base class for all 3D in-game objects.
Definition: object.h:63
Definition: control.h:65