Colobot
object.h
Go to the documentation of this file.
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 
25 #pragma once
26 
27 #include "object/crash_sphere.h"
28 #include "object/object_create_params.h"
31 
32 #include <vector>
33 
34 namespace Gfx
35 {
36 struct ModelCrashSphere;
37 } // namespace Gfx
38 
39 class CLevelParserLine;
40 
41 namespace CBot
42 {
43 class CBotVar;
44 }
45 
64 {
65 protected:
67  CObject(int id, ObjectType type);
68 
69 public:
70  CObject(const CObject&) = delete;
71  CObject& operator=(const CObject&) = delete;
72 
73  virtual ~CObject();
74 
76  inline ObjectType GetType() const
77  {
78  return m_type;
79  }
81  inline int GetID() const
82  {
83  return m_id;
84  }
85 
87  virtual void Write(CLevelParserLine* line) = 0;
89  virtual void Read(CLevelParserLine* line) = 0;
91  static ObjectCreateParams ReadCreateParams(CLevelParserLine* line);
92 
94  virtual void UpdateInterface() {};
95 
97  inline bool Implements(ObjectInterfaceType type) const
98  {
99  return m_implementedInterfaces[static_cast<int>(type)];
100  }
101 
103  virtual Math::Vector GetPosition() const;
105  virtual void SetPosition(const Math::Vector& pos);
106 
108 
109  virtual Math::Vector GetRotation() const;
111 
112  virtual void SetRotation(const Math::Vector& rotation);
113 
116  void SetRotationX(float angle);
117  void SetRotationY(float angle);
118  void SetRotationZ(float angle);
119  float GetRotationX();
120  float GetRotationY();
121  float GetRotationZ();
123 
125  virtual Math::Vector GetScale() const;
127  virtual void SetScale(const Math::Vector& scale);
129  void SetScale(float scale);
130 
133  void SetScaleX(float angle);
134  void SetScaleY(float angle);
135  void SetScaleZ(float angle);
136  float GetScaleX();
137  float GetScaleY();
138  float GetScaleZ();
140 
142  void SetCrashSpheres(const std::vector<Gfx::ModelCrashSphere>& crashSpheres);
144 
145  void AddCrashSphere(const CrashSphere& crashSphere);
147  int GetCrashSphereCount();
149 
150  CrashSphere GetFirstCrashSphere();
152 
153  std::vector<CrashSphere> GetAllCrashSpheres();
155  void DeleteAllCrashSpheres();
157  bool CanCollideWith(CObject* other);
158 
160  Math::Sphere GetCameraCollisionSphere();
162  // TODO: remove from here once no longer necessary
163  void SetCameraCollisionSphere(const Math::Sphere& sphere);
164 
166  virtual void SetTransparency(float value) = 0;
167 
169  void SetAnimateOnReset(bool animateOnReset);
171  bool GetAnimateOnReset();
172 
174  void SetCollisions(bool collisions);
176  bool GetCollisions();
177 
179  void SetTeam(int team);
181  int GetTeam();
182 
184  void SetProxyActivate(bool activate);
186  bool GetProxyActivate();
187 
189  void SetProxyDistance(float distance);
191  float GetProxyDistance();
192 
194  CBot::CBotVar* GetBotVar();
195 
197  std::string GetTooltipText();
198 
200  void SetLock(bool lock);
202  bool GetLock();
203 
205  virtual bool GetActive() { return true; }
207  virtual bool GetDetectable() { return true; }
208 
209 protected:
211  virtual void TransformCrashSphere(Math::Sphere& crashSphere) = 0;
213  virtual void TransformCameraCollisionSphere(Math::Sphere& collisionSphere) = 0;
214 
215 protected:
216  const int m_id;
218  ObjectInterfaceTypes m_implementedInterfaces;
219  Math::Vector m_position;
220  Math::Vector m_rotation;
221  Math::Vector m_scale;
222  std::vector<CrashSphere> m_crashSpheres;
223  Math::Sphere m_cameraCollisionSphere;
224  bool m_animateOnReset;
225  bool m_collisions;
226  int m_team;
227  bool m_proxyActivate;
228  float m_proxyDistance;
229  CBot::CBotVar* m_botVar;
230  bool m_lock;
231 };
int GetID() const
Returns object&#39;s unique id.
Definition: object.h:81
void SetTransparency(CObject *obj, float value)
Changes the level of transparency of an object and objects transported (battery & cargo) ...
Definition: camera.cpp:56
ObjectInterfaceTypes m_implementedInterfaces
interfaces that the object implements
Definition: object.h:218
std::vector< CrashSphere > m_crashSpheres
crash spheres
Definition: object.h:222
Legacy CObject interface.
Sphere used to detect object collisions.
Definition: crash_sphere.h:33
Definition: parserline.h:37
A CBot variable.
Definition: CBotVar.h:42
ObjectInterfaceType
Type of interface that an object implements.
Definition: object_interface_type.h:34
ObjectType m_type
object type
Definition: object.h:217
ObjectInterfaceType enum.
bool Implements(ObjectInterfaceType type) const
Check if object implements the given type of interface.
Definition: object.h:97
Namespace for (new) graphics code.
Definition: app.h:49
Definition: object_create_params.h:26
virtual bool GetDetectable()
Is this object detectable (not dead and not underground)?
Definition: object.h:207
ObjectType
Type of game object.
Definition: object_type.h:33
Definition: old_object_interface.h:48
3D (3x1) vector
Definition: vector.h:53
virtual void UpdateInterface()
Updates all interface controls.
Definition: object.h:94
ObjectType GetType() const
Returns object type.
Definition: object.h:76
CBot engine.
Definition: CBotCallMethode.cpp:28
Base class for all 3D in-game objects.
Definition: object.h:63
virtual bool GetActive()
Is this object active (not dead)?
Definition: object.h:205
const int m_id
unique identifier
Definition: object.h:216
Definition: sphere.h:27