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