Colobot
lightning.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 "math/point.h"
28 #include "math/vector.h"
29 
30 #include <vector>
31 
32 class CObject;
33 class CSoundInterface;
34 struct Event;
35 
36 
37 // Graphics module namespace
38 namespace Gfx
39 {
40 
41 class CEngine;
42 class CTerrain;
43 class CCamera;
44 
46 const float LTNG_PROTECTION_RADIUS = 200.0f;
47 
48 
56 {
57 public:
58  CLightning(CEngine* engine);
59  ~CLightning();
60 
62  bool Create(float sleep, float delay, float magnetic);
63 
65  void Flush();
66 
68  bool GetStatus(float &sleep, float &delay, float &magnetic, float &progress);
70  bool SetStatus(float sleep, float delay, float magnetic, float progress);
71 
73  bool EventProcess(const Event &event);
74 
76  void Draw();
77 
79  void StrikeAtPos(Math::Vector pos);
80 
81 protected:
83  bool EventFrame(const Event &event);
86 
87 protected:
88  CEngine* m_engine = nullptr;
89  CTerrain* m_terrain = nullptr;
90  CCamera* m_camera = nullptr;
91  CSoundInterface* m_sound = nullptr;
92 
93  bool m_lightningExists = false;
94  float m_sleep = 0.0f;
95  float m_delay = 0.0f;
96  float m_magnetic = 0.0f;
97 
98  float m_speed = 0.0f;
99  float m_progress = 0.0f;
100  Math::Vector m_pos;
101 
102  enum class LightningPhase
103  {
104  Wait,
105  Flash,
106  };
107  LightningPhase m_phase = LightningPhase::Wait;
108 
110  {
111  Math::Point shift;
112  float width = 0.0f;
113  };
114  std::vector<LightningSegment> m_segments;
115 };
116 
117 
118 } // namespace Gfx
119 
void Flush()
Removes lightning.
Definition: lightning.cpp:65
Point struct and related functions.
void StrikeAtPos(Math::Vector pos)
Shoots lightning strike at given position.
Definition: lightning.cpp:355
bool GetStatus(float &sleep, float &delay, float &magnetic, float &progress)
Gives the status of lightning.
Definition: lightning.cpp:193
Lightning effect renderer.
Definition: lightning.h:55
Definition: lightning.h:109
2D point
Definition: point.h:50
Camera moving in 3D scene.
Definition: camera.h:128
const float LTNG_PROTECTION_RADIUS
Radius of lightning protection.
Definition: lightning.h:46
Terrain loader/generator and manager.
Definition: terrain.h:147
bool EventFrame(const Event &event)
Updates lightning.
Definition: lightning.cpp:83
Namespace for (new) graphics code.
Definition: app.h:49
void Draw()
Draws lightning.
Definition: lightning.cpp:219
Vector struct and related functions.
The graphics engine.
Definition: engine.h:585
CObject * SearchObject(Math::Vector pos)
Seeks for the object closest to the lightning.
Definition: lightning.cpp:298
3D (3x1) vector
Definition: vector.h:53
Event sent by system, interface or game.
Definition: event.h:735
Base class for all 3D in-game objects.
Definition: object.h:63
bool SetStatus(float sleep, float delay, float magnetic, float progress)
Specifies the status of lightning.
Definition: lightning.cpp:205
bool EventProcess(const Event &event)
Management of an event.
Definition: lightning.cpp:75
Sound plugin interface.
Definition: sound.h:60
bool Create(float sleep, float delay, float magnetic)
Triggers lightning.
Definition: lightning.cpp:178