SuperTuxKart
Loading...
Searching...
No Matches
item_event_info.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2018 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_ITEM_EVENT_INFO_HPP
20#define HEADER_ITEM_EVENT_INFO_HPP
21
22#include "items/item.hpp"
23#include "utils/vec3.hpp"
24#include "utils/types.hpp"
25
26#include <assert.h>
27
29
30// ------------------------------------------------------------------------
36{
37private:
39 enum EventType {IEI_COLLECT, IEI_NEW, IEI_SWITCH} m_type;
40
43
47
51
54
57
61
62public:
69 ItemEventInfo(int ticks, int index, int kart_id, int16_t ttr)
70 : m_ticks(ticks), m_index(index), m_kart_id(kart_id),
72 {
73 m_type = IEI_COLLECT;
74 } // ItemEventInfo(collected existing item)
75
76 // --------------------------------------------------------------------
81 ItemEventInfo(int ticks, ItemState::ItemType type, int index,
82 int kart_id, const Vec3 &xyz, const Vec3 &normal)
83 : m_ticks(ticks), m_index(index), m_kart_id(kart_id), m_xyz(xyz),
85 {
86 m_type = IEI_NEW;
87 } // ItemEventInfo(new item)
88
89 // --------------------------------------------------------------------
92 {
93 m_type = IEI_SWITCH;
94 } // ItemEventInfo(switch)
95
96 // --------------------------------------------------------------------
97 ItemEventInfo(BareNetworkString *buffer, int *count);
98 void saveState(BareNetworkString *buffer);
99
100 // --------------------------------------------------------------------
102 bool isNewItem() const { return m_type == IEI_NEW; }
103 // --------------------------------------------------------------------
105 bool isItemCollection() const { return m_type == IEI_COLLECT; }
106 // --------------------------------------------------------------------
108 bool isSwitch() const { return m_type == IEI_SWITCH; }
109 // --------------------------------------------------------------------
111 int getIndex() const { return m_index; }
112 // --------------------------------------------------------------------
114 int getTicks() const { return m_ticks; }
115 // --------------------------------------------------------------------
118 int getKartId() const
119 {
120 return m_kart_id;
121 } // getKartId
122 // --------------------------------------------------------------------
125 const Vec3& getXYZ() const
126 {
127 assert(isNewItem());
128 return m_xyz;
129 } // getXYZ
130 // --------------------------------------------------------------------
132 const Vec3& getNormal() const
133 {
134 assert(isNewItem());
135 return m_normal;
136 } // getNormal
137 // --------------------------------------------------------------------
140 // --------------------------------------------------------------------
144 {
145 return ItemState::ITEM_BUBBLEGUM;
146 } // getNewItemType
147
148}; // class ItemEventInfo
149
150
151#endif
Describes a chain of 8-bit unsigned integers.
Definition: network_string.hpp:53
This class stores a delta, i.e.
Definition: item_event_info.hpp:36
int m_ticks
Time at which this event happens.
Definition: item_event_info.hpp:42
int getIndex() const
Returns the index of this item.
Definition: item_event_info.hpp:111
bool isItemCollection() const
Returns true if this event represents collection of an item.
Definition: item_event_info.hpp:105
int getTicksTillReturn() const
Returns the ticks till return, used only by collection events.
Definition: item_event_info.hpp:139
int16_t m_ticks_till_return
Ticks for the item to return, atm used by collecting banana with bomb to delay the return for banana.
Definition: item_event_info.hpp:60
int m_kart_id
The kart id that collected an item if >=0; if -1 it indicates a new item, and a -2 indicates a switch...
Definition: item_event_info.hpp:50
bool isNewItem() const
Returns if this event represents a new item.
Definition: item_event_info.hpp:102
Vec3 m_xyz
In case of new items the position of the new item.
Definition: item_event_info.hpp:53
const Vec3 & getXYZ() const
Returns the location of a new item.
Definition: item_event_info.hpp:125
bool isSwitch() const
Returns true if this event represent a switch usage.
Definition: item_event_info.hpp:108
EventType
Type of this event.
Definition: item_event_info.hpp:39
const Vec3 & getNormal() const
Returns the normal of a new item only.
Definition: item_event_info.hpp:132
ItemEventInfo(int ticks, int index, int kart_id, int16_t ttr)
Constructor for collecting an existing item.
Definition: item_event_info.hpp:69
Vec3 m_normal
The normal of an item.
Definition: item_event_info.hpp:56
int m_index
Index of this item in the item list.
Definition: item_event_info.hpp:46
ItemEventInfo(int ticks)
Constructor for switching items.
Definition: item_event_info.hpp:91
ItemState::ItemType getNewItemType() const
Returns the type of this item.
Definition: item_event_info.hpp:143
int getKartId() const
Returns the id of the kart that collected an item.
Definition: item_event_info.hpp:118
void saveState(BareNetworkString *buffer)
Stores this event into a network string.
Definition: item_event_info.cpp:67
int getTicks() const
Returns the time of the event in ticks.
Definition: item_event_info.hpp:114
ItemEventInfo(int ticks, ItemState::ItemType type, int index, int kart_id, const Vec3 &xyz, const Vec3 &normal)
Constructor for creating a new item (i.e.
Definition: item_event_info.hpp:81
ItemType
The list of all items.
Definition: item.hpp:62
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.