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-2015, 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"
30 #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 class CBotVar;
41 
60 {
61 protected:
63  CObject(int id, ObjectType type);
64 
65 public:
66  CObject(const CObject&) = delete;
67  CObject& operator=(const CObject&) = delete;
68 
69  virtual ~CObject();
70 
72  inline ObjectType GetType() const
73  {
74  return m_type;
75  }
77  inline int GetID() const
78  {
79  return m_id;
80  }
81 
83  virtual void Write(CLevelParserLine* line) = 0;
85  virtual void Read(CLevelParserLine* line) = 0;
87  static ObjectCreateParams ReadCreateParams(CLevelParserLine* line);
88 
90  virtual void UpdateInterface() {};
91 
93  inline bool Implements(ObjectInterfaceType type) const
94  {
95  return m_implementedInterfaces[static_cast<int>(type)];
96  }
97 
99  virtual Math::Vector GetPosition() const;
101  virtual void SetPosition(const Math::Vector& pos);
102 
104 
105  virtual Math::Vector GetRotation() const;
107 
108  virtual void SetRotation(const Math::Vector& rotation);
109 
112  void SetRotationX(float angle);
113  void SetRotationY(float angle);
114  void SetRotationZ(float angle);
115  float GetRotationX();
116  float GetRotationY();
117  float GetRotationZ();
119 
121  virtual Math::Vector GetScale() const;
123  virtual void SetScale(const Math::Vector& scale);
125  void SetScale(float scale);
126 
129  void SetScaleX(float angle);
130  void SetScaleY(float angle);
131  void SetScaleZ(float angle);
132  float GetScaleX();
133  float GetScaleY();
134  float GetScaleZ();
136 
138  void SetCrashSpheres(const std::vector<Gfx::ModelCrashSphere>& crashSpheres);
140 
141  void AddCrashSphere(const CrashSphere& crashSphere);
143  int GetCrashSphereCount();
145 
146  CrashSphere GetFirstCrashSphere();
148 
149  std::vector<CrashSphere> GetAllCrashSpheres();
151  void DeleteAllCrashSpheres();
153  bool CanCollideWith(CObject* other);
154 
156  Math::Sphere GetCameraCollisionSphere();
158  // TODO: remove from here once no longer necessary
159  void SetCameraCollisionSphere(const Math::Sphere& sphere);
160 
162  virtual void SetTransparency(float value) = 0;
163 
165  void SetAnimateOnReset(bool animateOnReset);
167  bool GetAnimateOnReset();
168 
170  void SetCollisions(bool collisions);
172  bool GetCollisions();
173 
175  void SetTeam(int team);
177  int GetTeam();
178 
180  void SetProxyActivate(bool activate);
182  bool GetProxyActivate();
183 
185  void SetProxyDistance(float distance);
187  float GetProxyDistance();
188 
190  CBotVar* GetBotVar();
191 
193  std::string GetTooltipText();
194 
196  void SetLock(bool lock);
198  bool GetLock();
199 
201  virtual bool GetActive() { return true; }
203  virtual bool GetDetectable() { return true; }
204 
205 protected:
207  virtual void TransformCrashSphere(Math::Sphere& crashSphere) = 0;
209  virtual void TransformCameraCollisionSphere(Math::Sphere& collisionSphere) = 0;
210 
211 protected:
212  const int m_id;
214  ObjectInterfaceTypes m_implementedInterfaces;
215  Math::Vector m_position;
216  Math::Vector m_rotation;
217  Math::Vector m_scale;
218  std::vector<CrashSphere> m_crashSpheres;
219  Math::Sphere m_cameraCollisionSphere;
220  bool m_animateOnReset;
221  bool m_collisions;
222  int m_team;
223  bool m_proxyActivate;
224  float m_proxyDistance;
225  CBotVar* m_botVar;
226  bool m_lock;
227 };
int GetID() const
Returns object&#39;s unique id.
Definition: object.h:77
void SetTransparency(CObject *obj, float value)
Changes the level of transparency of an object and objects transported (battery & cargo) ...
Definition: camera.cpp:53
ObjectInterfaceTypes m_implementedInterfaces
interfaces that the object implements
Definition: object.h:214
std::vector< CrashSphere > m_crashSpheres
crash spheres
Definition: object.h:218
Legacy CObject interface.
Sphere used to detect object collisions.
Definition: crash_sphere.h:31
Definition: parserline.h:37
ObjectInterfaceType
Type of interface that an object implements.
Definition: object_interface_type.h:34
ObjectType m_type
object type
Definition: object.h:213
ObjectInterfaceType enum.
bool Implements(ObjectInterfaceType type) const
Check if object implements the given type of interface.
Definition: object.h:93
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:203
ObjectType
Type of game object.
Definition: object_type.h:33
Definition: old_object_interface.h:45
3D (3x1) vector
Definition: vector.h:53
Definition: CBotDll.h:557
virtual void UpdateInterface()
Updates all interface controls.
Definition: object.h:90
ObjectType GetType() const
Returns object type.
Definition: object.h:72
Base class for all 3D in-game objects.
Definition: object.h:59
virtual bool GetActive()
Is this object active (not dead)?
Definition: object.h:201
const int m_id
unique identifier
Definition: object.h:212
Definition: sphere.h:27