SuperTuxKart
check_structure.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2009-2015 Joerg Henrichs
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 #ifndef HEADER_CHECK_STRUCTURE_HPP
20 #define HEADER_CHECK_STRUCTURE_HPP
21 
22 #include <vector>
23 
24 #include "utils/aligned_array.hpp"
25 #include "utils/vec3.hpp"
26 
27 class BareNetworkString;
28 class CheckManager;
29 class Track;
30 class XMLNode;
31 
52 {
53 public:
68  enum CheckType {CT_NEW_LAP, CT_ACTIVATE, CT_TOGGLE, CT_CANNON,
69  CT_GOAL, CT_AMBIENT_SPHERE, CT_TRIGGER};
70 
71 protected:
75  AlignedArray<Vec3> m_previous_position;
77  std::vector<bool> m_is_active;
78 
81 
84  unsigned int m_index;
85 
87  CheckStructure(unsigned index) : m_active_at_reset(true), m_index(index),
88  m_check_type(CT_TRIGGER) {}
89 private:
92 
96 
102  std::vector<int> m_same_group;
103 
104  enum ChangeState {CS_DEACTIVATE, CS_ACTIVATE, CS_TOGGLE};
105 
106  void changeStatus(const std::vector<int> &indices, int kart_index,
107  ChangeState change_state);
108 
109 public:
110  CheckStructure(const XMLNode &node, unsigned int index);
111  virtual ~CheckStructure() {};
112  virtual void update(float dt);
113  virtual void resetAfterKartMove(unsigned int kart_index) {}
114  virtual void resetAfterRewind(unsigned int kart_index) {}
115  virtual void changeDebugColor(bool is_active) {}
123  virtual bool isTriggered(const Vec3 &old_pos, const Vec3 &new_pos,
124  int indx)=0;
125  virtual void trigger(unsigned int kart_index);
126  virtual void reset(const Track &track);
127 
128  // ------------------------------------------------------------------------
130  CheckType getType() const { return m_check_type; }
131  // ------------------------------------------------------------------------
134  void addSuccessor(unsigned int i)
135  {
137  } // addSuccessor
138  // ------------------------------------------------------------------------
139  virtual bool triggeringCheckline() const { return false; }
140  // ------------------------------------------------------------------------
141  virtual void saveCompleteState(BareNetworkString* bns);
142  // ------------------------------------------------------------------------
143  virtual void restoreCompleteState(const BareNetworkString& b);
144  // ------------------------------------------------------------------------
145  void saveIsActive(int kart_id, BareNetworkString* bns);
146  // ------------------------------------------------------------------------
147  void restoreIsActive(int kart_id, const BareNetworkString& b);
148  // ------------------------------------------------------------------------
149  int getIndex() const { return m_index; }
150 }; // CheckStructure
151 
152 #endif
153 
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:34
std::vector< int > m_same_group
A list of check lines that should be activated/switched when this lines is activated/switched.
Definition: check_structure.hpp:102
std::vector< bool > m_is_active
Stores if this check structure is active (for a given kart).
Definition: check_structure.hpp:77
CheckType m_check_type
The type of this checkline.
Definition: check_structure.hpp:91
CheckStructure(unsigned index)
For CheckTrigger or CheckCylinder.
Definition: check_structure.hpp:87
unsigned int m_index
Stores the index of this check structure.
Definition: check_structure.hpp:84
void addSuccessor(unsigned int i)
Adds the index of a successor check structure which will get triggered by this check structure.
Definition: check_structure.hpp:134
virtual void update(float dt)
Updates all check structures.
Definition: check_structure.cpp:101
void changeStatus(const std::vector< int > &indices, int kart_index, ChangeState change_state)
Changes the status (active/inactive) of all check structures contained in the index list indices.
Definition: check_structure.cpp:133
std::vector< int > m_check_structures_to_change_state
Contains the indices of the corresponding check structures that get their state changed (activated or...
Definition: check_structure.hpp:95
CheckType getType() const
Returns the type of this check structure.
Definition: check_structure.hpp:130
Controls all checks structures of a track.
Definition: check_manager.hpp:39
virtual void reset(const Track &track)
Initialises the 'previous positions' of all karts with the start position defined for this track.
Definition: check_structure.cpp:81
AlignedArray< Vec3 > m_previous_position
Stores the previous position of all karts.
Definition: check_structure.hpp:75
Describes a chain of 8-bit unsigned integers.
Definition: network_string.hpp:52
virtual bool isTriggered(const Vec3 &old_pos, const Vec3 &new_pos, int indx)=0
True if going from old_pos to new_pos crosses this checkline.
bool m_active_at_reset
True if this check structure should be activated at a reset.
Definition: check_structure.hpp:80
virtual void trigger(unsigned int kart_index)
Is called when this check structure is triggered.
Definition: check_structure.cpp:207
utility class used to parse XML files
Definition: xml_node.hpp:47
Virtual base class for a check structure.
Definition: check_structure.hpp:51
CheckType
Different types of check structures: ACTIVATE: Activates another check structure (independent of the ...
Definition: check_structure.hpp:68
Definition: track.hpp:96