Colobot
old_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/object.h"
28 
29 #include "object/interface/carrier_object.h"
30 #include "object/interface/controllable_object.h"
31 #include "object/interface/flying_object.h"
32 #include "object/interface/interactive_object.h"
33 #include "object/interface/jet_flying_object.h"
34 #include "object/interface/jostleable_object.h"
35 #include "object/interface/movable_object.h"
36 #include "object/interface/power_container_object.h"
37 #include "object/interface/powered_object.h"
38 #include "object/interface/programmable_object.h"
39 #include "object/interface/ranged_object.h"
40 #include "object/interface/shielded_auto_regen_object.h"
41 #include "object/interface/task_executor_object.h"
42 #include "object/interface/trace_drawing_object.h"
43 #include "object/interface/transportable_object.h"
44 
45 #include "object/implementation/power_container_impl.h"
46 #include "object/implementation/program_storage_impl.h"
47 #include "object/implementation/programmable_impl.h"
48 #include "object/implementation/task_executor_impl.h"
49 
50 // The father of all parts must always be the part number zero!
51 const int OBJECTMAXPART = 40;
52 
53 struct ObjectPart
54 {
55  bool bUsed = false;
56  int object = -1; // number of the object in CEngine
57  int parentPart = -1; // number of father part
58  int masterParti = -1; // master canal of the particle
59  Math::Vector position;
60  Math::Vector angle;
61  Math::Vector zoom;
62  bool bTranslate = false;
63  bool bRotate = false;
64  bool bZoom = false;
65  Math::Matrix matTranslate;
66  Math::Matrix matRotate;
67  Math::Matrix matTransform;
68  Math::Matrix matWorld;
69 };
70 
71 namespace Ui
72 {
73 class CObjectInterface;
74 }
75 
76 
77 class COldObject : public CObject,
78  public CInteractiveObject,
79  public CTransportableObject,
83  public CJostleableObject,
84  public CCarrierObject,
85  public CPoweredObject,
86  public CJetFlyingObject,
87  public CControllableObject,
89  public CRangedObject,
90  public CTraceDrawingObject,
92 {
93  friend class CObjectFactory;
94  friend class CObjectManager;
95 
96 protected:
97  void DeleteObject(bool bAll=false);
98  void SetProgrammable();
99  void SetMovable(std::unique_ptr<CMotion> motion, std::unique_ptr<CPhysics> physics);
100  void SetAuto(std::unique_ptr<CAuto> automat);
101  void SetOption(int option);
102  void SetJostlingSphere(const Math::Sphere& sphere);
103 
104 
105 public:
106  COldObject(int id); // should only be called by CObjectFactory
107  ~COldObject();
108 
109  void Simplify() override;
110 
111  bool DamageObject(DamageType type, float force = std::numeric_limits<float>::infinity()) override;
112  void DestroyObject(DestructionType type) override;
113 
114  bool EventProcess(const Event& event) override;
115  void UpdateMapping();
116 
117  void DeletePart(int part) override;
118  void SetObjectRank(int part, int objRank);
119  int GetObjectRank(int part) override;
120  void SetObjectParent(int part, int parent);
121  void SetType(ObjectType type) override;
122  const char* GetName();
123  int GetOption() override;
124 
125  void Write(CLevelParserLine* line) override;
126  void Read(CLevelParserLine* line) override;
127 
128  void SetDrawFront(bool bDraw) override;
129 
130  int GetShadowLight();
131  int GetEffectLight();
132 
133  void SetFloorHeight(float height);
134  void FloorAdjust() override;
135 
136  void SetLinVibration(Math::Vector dir) override;
137  Math::Vector GetLinVibration();
138  void SetCirVibration(Math::Vector dir) override;
139  Math::Vector GetCirVibration();
140  void SetTilt(Math::Vector dir);
141  Math::Vector GetTilt() override;
142 
143  void SetPartPosition(int part, const Math::Vector &pos);
144  Math::Vector GetPartPosition(int part) const;
145 
146  void SetPartRotation(int part, const Math::Vector &angle);
147  Math::Vector GetPartRotation(int part) const;
148  void SetPartRotationY(int part, float angle);
149  void SetPartRotationX(int part, float angle);
150  void SetPartRotationZ(int part, float angle);
151  float GetPartRotationY(int part);
152  float GetPartRotationX(int part);
153  float GetPartRotationZ(int part);
154 
155  void SetPartScale(int part, float zoom);
156  void SetPartScale(int part, Math::Vector zoom);
157  Math::Vector GetPartScale(int part) const;
158  void SetPartScaleX(int part, float zoom);
159  float GetPartScaleX(int part);
160  void SetPartScaleY(int part, float zoom);
161  float GetPartScaleY(int part);
162  void SetPartScaleZ(int part, float zoom);
163  float GetPartScaleZ(int part);
164 
165  void SetTrainer(bool bEnable) override;
166  bool GetTrainer() override;
167 
168  void SetToy(bool bEnable);
169  bool GetToy();
170 
171  void SetManual(bool bManual);
172  bool GetManual();
173 
174  void SetMasterParticle(int part, int parti) override;
175 
176  void SetPower(CObject* power) override;
177  CObject* GetPower() override;
178  Math::Vector GetPowerPosition() override;
179  void SetPowerPosition(const Math::Vector& powerPosition) override;
180  void SetCargo(CObject* cargo) override;
181  CObject* GetCargo() override;
182  void SetTransporter(CObject* transporter) override;
183  CObject* GetTransporter() override;
184  void SetTransporterPart(int part) override;
185 
186  Math::Matrix* GetRotateMatrix(int part);
187  Math::Matrix* GetWorldMatrix(int part) override;
188 
189  void AdjustCamera(Math::Vector &eye, float &dirH, float &dirV,
190  Math::Vector &lookat, Math::Vector &upVec,
191  Gfx::CameraType type) override;
192 
193  Character* GetCharacter() override;
194 
195  float GetAbsTime();
196 
197  float GetCapacity() override;
198 
199  bool IsRechargeable() override;
200 
201  void SetShield(float level) override;
202  float GetShield() override;
203 
204  void SetRange(float delay) override;
205  float GetRange() override;
206 
207  void SetReactorRange(float reactorRange) override;
208  float GetReactorRange() override;
209 
210  void SetTransparency(float value) override;
211 
212  Math::Sphere GetJostlingSphere() const override;
213  bool JostleObject(float force) override;
214 
215  void SetVirusMode(bool bEnable) override;
216  bool GetVirusMode() override;
217 
218  void SetCameraType(Gfx::CameraType type) override;
219  Gfx::CameraType GetCameraType() override;
220  void SetCameraDist(float dist) override;
221  float GetCameraDist() override;
222  void SetCameraLock(bool lock) override;
223  bool GetCameraLock() override;
224 
225  void SetHighlight(bool highlight) override;
226 
227  void SetSelect(bool select, bool bDisplayError = true) override;
228  bool GetSelect() override;
229 
230  void SetSelectable(bool bMode);
231  bool GetSelectable() override;
232 
233  void SetUnderground(bool underground);
234 
235  void SetCheckToken(bool bMode);
236  bool GetCheckToken();
237 
238  void SetMagnifyDamage(float factor) override;
239  float GetMagnifyDamage() override;
240 
241  void SetDying(DeathType deathType) override;
242  DeathType GetDying() override;
243  bool IsDying() override;
244 
245  bool GetActive() override;
246  bool GetDetectable() override;
247 
248  void SetGunGoalV(float gunGoal);
249  void SetGunGoalH(float gunGoal);
250  float GetGunGoalV();
251  float GetGunGoalH();
252 
253  float GetShowLimitRadius() override;
254 
255  void CreateSelectParticle();
256 
257  CPhysics* GetPhysics() override;
258  CMotion* GetMotion() override;
259  CAuto* GetAuto() override;
260 
261  bool CreateShadowCircle(float radius, float intensity, Gfx::EngineShadowType type = Gfx::ENG_SHADOW_NORM);
262  bool CreateShadowLight(float height, Gfx::Color color);
263  bool CreateEffectLight(float height, Gfx::Color color);
264 
265  void FlatParent() override;
266 
267  void SetPosition(const Math::Vector& pos) override;
268  Math::Vector GetPosition() const override;
269 
270  void SetRotation(const Math::Vector& rotation) override;
271  Math::Vector GetRotation() const override;
272 
273  using CObject::SetScale; // SetScale(float) version
274  void SetScale(const Math::Vector& scale) override;
275  Math::Vector GetScale() const override;
276 
277  void UpdateInterface() override;
278 
279  void StopProgram() override;
280 
281  bool GetTraceDown() override;
282  void SetTraceDown(bool down) override;
283  TraceColor GetTraceColor() override;
284  void SetTraceColor(TraceColor color) override;
285  float GetTraceWidth() override;
286  void SetTraceWidth(float width) override;
287 
288  bool IsRepairable() override;
289  float GetShieldFullRegenTime() override;
290 
291  float GetLightningHitProbability() override;
292 
293 protected:
294  bool EventFrame(const Event &event);
295  void VirusFrame(float rTime);
296  void PartiFrame(float rTime);
297  void InitPart(int part);
298  void UpdateTotalPart();
299  int SearchDescendant(int parent, int n);
300  void UpdateEnergyMapping();
301  bool UpdateTransformObject(int part, bool bForceUpdate);
302  bool UpdateTransformObject();
303  void UpdateSelectParticle();
304  void TransformCrashSphere(Math::Sphere &crashSphere) override;
305  void TransformCameraCollisionSphere(Math::Sphere& collisionSphere) override;
306 
307 protected:
308  Gfx::CEngine* m_engine;
309  Gfx::CLightManager* m_lightMan;
310  Gfx::CTerrain* m_terrain;
311  Gfx::CCamera* m_camera;
312  Gfx::CParticle* m_particle;
313  CRobotMain* m_main;
314  CSoundInterface* m_sound;
315 
316  std::unique_ptr<CPhysics> m_physics;
317  std::unique_ptr<CMotion> m_motion;
318  std::unique_ptr<CAuto> m_auto;
319  std::unique_ptr<Ui::CObjectInterface> m_objectInterface;
320 
321  std::string m_name; // name of the object
322  Character m_character; // characteristic
323  int m_option; // option
324  int m_shadowLight; // number of light from the shadows
325  float m_shadowHeight; // height of light from the shadows
326  int m_effectLight; // number of light effects
327  float m_effectHeight; // height of light effects
328  Math::Vector m_linVibration; // linear vibration
329  Math::Vector m_cirVibration; // circular vibration
330  Math::Vector m_tilt; // tilt
331  CObject* m_power; // battery used by the vehicle
332  Math::Vector m_powerPosition;
333  CObject* m_cargo; // object transported
334  CObject* m_transporter; // object with the latter
335  int m_transporterLink; // part
336  float m_lastEnergy;
337  float m_shield; // shield
338  float m_range; // flight range
339  float m_transparency; // transparency (0..1)
340  float m_aTime;
341  float m_shotTime; // time since last shot
342  bool m_bVirusMode; // virus activated/triggered
343  float m_virusTime; // lifetime of the virus
344  float m_lastVirusParticle;
345  bool m_bSelect; // object selected
346  bool m_bSelectable; // selectable object
347  bool m_bCheckToken; // object with audited tokens
348  bool m_underground; // object active but undetectable
349  bool m_bCargo;
350  DeathType m_dying;
351  bool m_bFlat;
352  bool m_bTrainer; // drive vehicle (without remote)
353  bool m_bToy; // toy key
354  bool m_bManual; // manual control (Scribbler)
355  float m_gunGoalV;
356  float m_gunGoalH;
357  Gfx::CameraType m_cameraType;
358  float m_cameraDist;
359  bool m_bCameraLock;
360  float m_magnifyDamage;
361  float m_param;
362 
363  Math::Sphere m_jostlingSphere;
364  float m_shieldRadius;
365 
366  int m_totalPart;
367  ObjectPart m_objectPart[OBJECTMAXPART];
368 
369  int m_partiSel[4];
370 
371  EventType m_buttonAxe;
372 
373  float m_time;
374  float m_burnTime;
375 
376  float m_reactorRange;
377 
378  bool m_traceDown;
379  TraceColor m_traceColor;
380  float m_traceWidth;
381 };
Interface for transportable objects.
Definition: transportable_object.h:29
Normal shadow.
Definition: engine.h:302
CameraType
Type of camera.
Definition: camera.h:46
Definition: old_object_interface.h:36
bool DeleteObject(CObject *instance)
Deletes the object.
Definition: object_manager.cpp:63
Definition: robotmain.h:107
Definition: programmable_impl.h:47
4x4 matrix
Definition: matrix.h:65
Interface for objects that have a button in UI for showing range.
Definition: ranged_object.h:28
Definition: task_executor_impl.h:28
Definition: old_object.h:77
Interface for interactive objects (objects able to process events from event loop) ...
Definition: interactive_object.h:30
Definition: physics.h:98
Definition: auto.h:56
virtual void SetScale(const Math::Vector &scale)
Sets objects&#39;s scale.
Definition: object.cpp:206
Manager for dynamic lights in 3D scene.
Definition: lightman.h:146
Interface for shielded objects with auto regeneration.
Definition: shielded_auto_regen_object.h:28
Definition: parserline.h:37
Interface for carrier objects.
Definition: carrier_object.h:29
Interface for objects powered using power cells.
Definition: powered_object.h:37
Definition: robotmain.h:151
Particle engine.
Definition: particle.h:223
Interface for objects that can draw wheel trace (at the moment, all movable objects) ...
Definition: trace_drawing_object.h:64
Interface for objects that can be selected and controlled by the player.
Definition: controllable_object.h:30
Interface for objects that can fly using a jet engine.
Definition: jet_flying_object.h:30
Definition: old_object.h:53
Interface for objects that can be jostled.
Definition: jostleable_object.h:30
Camera moving in 3D scene.
Definition: camera.h:134
Terrain loader/generator and manager.
Definition: terrain.h:145
Definition: motion.h:46
CObject - base class for all game objects.
The graphics engine.
Definition: engine.h:620
ObjectType
Type of game object.
Definition: object_type.h:33
Definition: power_container_impl.h:26
3D (3x1) vector
Definition: vector.h:53
Definition: program_storage_impl.h:30
EngineShadowType
Definition: engine.h:299
RGBA color.
Definition: color.h:39
Definition: object_factory.h:48
Manages CObject instances.
Definition: object_manager.h:148
EventType
Type of event message.
Definition: event.h:41
Event sent by system, interface or game.
Definition: event.h:709
Base class for all 3D in-game objects.
Definition: object.h:59
Sound plugin interface.
Definition: sound.h:57
Definition: sphere.h:27