SuperTuxKart
Loading...
Searching...
No Matches
check_trigger.hpp
1// SuperTuxKart - a fun racing game with go-kart
2// Copyright (C) 2019 SuperTuxKart-Team
3//
4// This program is free software; you can redistribute it and/or
5// modify it under the terms of the GNU General Public License
6// as published by the Free Software Foundation; either version 3
7// of the License, or (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18#ifndef HEADER_CHECK_TRIGGER_HPP
19#define HEADER_CHECK_TRIGGER_HPP
20
21#include "tracks/check_structure.hpp"
22#include "utils/cpp2011.hpp"
23#include "utils/types.hpp"
24
25#include <functional>
26
32{
33private:
36
38 const float m_distance2;
39
41 std::function<void(int)> m_triggering_function;
42
46
47public:
48 CheckTrigger(const Vec3& center, float distance,
49 std::function<void(int)> triggering_function);
50 // ------------------------------------------------------------------------
51 virtual ~CheckTrigger() {}
52 // ------------------------------------------------------------------------
53 virtual bool isTriggered(const Vec3 &old_pos, const Vec3 &new_pos,
54 int kart_id) OVERRIDE;
55 // ------------------------------------------------------------------------
56 virtual void trigger(unsigned int kart_index) OVERRIDE
57 {
58 if (!m_triggering_function) return;
59 m_triggering_function(kart_index);
60 CheckStructure::trigger(kart_index);
61 }
62 // ------------------------------------------------------------------------
63 virtual CheckStructure* clone() OVERRIDE
64 {
65 CheckTrigger* ct = new CheckTrigger(*this);
66 // Drop unneeded stuff ( trigger function is not supported in server,
67 // no scripting atm)
68 ct->m_triggering_function = nullptr;
69 return ct;
70 }
71}; // CheckTrigger
72
73#endif
74
Virtual base class for a check structure.
Definition: check_structure.hpp:52
virtual void trigger(unsigned int kart_index)
Is called when this check structure is triggered.
Definition: check_structure.cpp:220
This class implements a check point like item, but used only for scripting or sound trigger.
Definition: check_trigger.hpp:32
std::function< void(int)> m_triggering_function
Function to call when triggered.
Definition: check_trigger.hpp:41
virtual CheckStructure * clone() OVERRIDE
Clone to child process for server usage (atm no sound or scripting).
Definition: check_trigger.hpp:63
virtual void trigger(unsigned int kart_index) OVERRIDE
Is called when this check structure is triggered.
Definition: check_trigger.hpp:56
const Vec3 m_center
Center of the trigger.
Definition: check_trigger.hpp:35
virtual bool isTriggered(const Vec3 &old_pos, const Vec3 &new_pos, int kart_id) OVERRIDE
Copied from item state.
Definition: check_trigger.cpp:40
uint64_t m_last_triggered_time
Time since last trigger, if any triggering between 2 seconds ignored (like items).
Definition: check_trigger.hpp:45
const float m_distance2
Squared of the triggering distance.
Definition: check_trigger.hpp:38
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35
Declares the general types that are used by the network.