RigsofRods
Soft-body Physics Simulation
Main Page
Related Pages
Modules
Namespaces
Namespace List
Namespace Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
Functions
_
a
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
Variables
a
b
c
d
e
f
g
i
k
l
m
n
p
r
s
t
u
v
w
Typedefs
a
c
d
e
f
g
l
m
n
o
p
r
s
t
v
w
Enumerations
a
b
c
d
e
f
g
h
i
k
l
m
n
p
r
s
t
u
v
w
Enumerator
a
b
c
d
e
f
g
h
i
l
m
n
o
p
r
s
t
u
v
Data Structures
Data Structures
Data Structure Index
Class Hierarchy
Data Fields
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
y
~
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
Enumerations
a
b
c
d
g
h
l
m
n
o
p
r
s
t
v
Enumerator
a
b
c
d
f
g
h
l
m
n
o
r
s
t
v
Related Functions
Files
File List
Globals
All
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
_
a
b
c
d
e
f
g
h
i
l
m
n
o
p
q
r
s
t
u
v
w
Variables
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
v
w
x
y
z
Typedefs
Enumerations
Enumerator
k
o
Macros
_
a
b
c
d
e
f
h
i
l
m
n
o
p
r
s
t
x
•
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Modules
Pages
source
main
gameplay
RepairMode.cpp
Go to the documentation of this file.
1
/*
2
This source file is part of Rigs of Rods
3
Copyright 2005-2012 Pierre-Michel Ricordel
4
Copyright 2007-2012 Thomas Fischer
5
Copyright 2015-2020 Petr Ohlidal
6
7
For more information, see http://www.rigsofrods.org/
8
9
Rigs of Rods is free software: you can redistribute it and/or modify
10
it under the terms of the GNU General Public License version 3, as
11
published by the Free Software Foundation.
12
13
Rigs of Rods is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
17
18
You should have received a copy of the GNU General Public License
19
along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20
*/
21
22
#include "
RepairMode.h
"
23
24
#include "
Actor.h
"
25
#include "
GameContext.h
"
26
#include "
InputEngine.h
"
27
28
using namespace
RoR
;
29
30
void
RepairMode::UpdateInputEvents
(
float
dt)
31
{
32
if
(
App::sim_state
->getEnum<SimState>() !=
SimState::RUNNING
&&
33
App::GetGameContext
()->GetPlayerActor() &&
34
App::GetGameContext
()->GetPlayerActor()->ar_state !=
ActorState::NETWORKED_OK
&&
35
App::GetGameContext
()->GetPlayerActor()->ar_state !=
ActorState::LOCAL_REPLAY
)
36
{
37
return
;
38
}
39
40
if
(!
App::GetGameContext
()->GetPlayerActor())
41
{
42
m_quick_repair_active
=
false
;
43
m_live_repair_active
=
false
;
44
m_live_repair_timer
= 0.0f;
45
return
;
46
}
47
48
if
(
App::GetInputEngine
()->getEventBoolValue(
EV_COMMON_LIVE_REPAIR_MODE
))
49
{
50
m_live_repair_active
=
true
;
51
// Hack to bypass the timer - because EV_COMMON_REPAIR_TRUCK (default Backspace) may not be 'EXPL' so the below condition may execute.
52
m_live_repair_timer
=
App::sim_live_repair_interval
->
getFloat
() + 0.1f;
53
}
54
55
// Update LiveRepair timer
56
m_quick_repair_active
=
App::GetInputEngine
()->
getEventBoolValue
(
EV_COMMON_REPAIR_TRUCK
);
57
if
(
m_quick_repair_active
)
58
{
59
if
(
App::sim_live_repair_interval
->getFloat() > 0)
60
m_live_repair_active
=
m_live_repair_timer
>
App::sim_live_repair_interval
->
getFloat
();
61
}
62
else
63
{
64
m_live_repair_timer
= 0.f;
65
}
66
67
// Handle repair controls
68
if
(
m_quick_repair_active
||
m_live_repair_active
)
69
{
70
Ogre::Vector3 translation = Ogre::Vector3::ZERO;
71
float
rotation = 0.0f;
72
73
if
(
App::GetInputEngine
()->getEventBoolValue(
EV_TRUCK_ACCELERATE
))
74
{
75
translation += 2.0f * Ogre::Vector3::UNIT_Y * dt;
76
}
77
else
if
(
App::GetInputEngine
()->getEventBoolValue(
EV_TRUCK_BRAKE
))
78
{
79
translation -= 2.0f * Ogre::Vector3::UNIT_Y * dt;
80
}
81
if
(
App::GetInputEngine
()->getEventBoolValue(
EV_TRUCK_STEER_LEFT
))
82
{
83
rotation += 0.5f * dt;
84
}
85
else
if
(
App::GetInputEngine
()->getEventBoolValue(
EV_TRUCK_STEER_RIGHT
))
86
{
87
rotation -= 0.5f * dt;
88
}
89
if
(
App::GetInputEngine
()->getEventBoolValue(
EV_CHARACTER_FORWARD
))
90
{
91
float
curRot =
App::GetGameContext
()->
GetPlayerActor
()->
getRotation
();
92
translation.x += 2.0f * cos(curRot - Ogre::Math::HALF_PI) * dt;
93
translation.z += 2.0f * sin(curRot - Ogre::Math::HALF_PI) * dt;
94
}
95
else
if
(
App::GetInputEngine
()->getEventBoolValue(
EV_CHARACTER_BACKWARDS
))
96
{
97
float
curRot =
App::GetGameContext
()->
GetPlayerActor
()->
getRotation
();
98
translation.x -= 2.0f * cos(curRot - Ogre::Math::HALF_PI) * dt;
99
translation.z -= 2.0f * sin(curRot - Ogre::Math::HALF_PI) * dt;
100
}
101
if
(
App::GetInputEngine
()->getEventBoolValue(
EV_CHARACTER_SIDESTEP_RIGHT
))
102
{
103
float
curRot =
App::GetGameContext
()->
GetPlayerActor
()->
getRotation
();
104
translation.x += 2.0f * cos(curRot) * dt;
105
translation.z += 2.0f * sin(curRot) * dt;
106
}
107
else
if
(
App::GetInputEngine
()->getEventBoolValue(
EV_CHARACTER_SIDESTEP_LEFT
))
108
{
109
float
curRot =
App::GetGameContext
()->
GetPlayerActor
()->
getRotation
();
110
translation.x -= 2.0f * cos(curRot) * dt;
111
translation.z -= 2.0f * sin(curRot) * dt;
112
}
113
114
if
(translation != Ogre::Vector3::ZERO || rotation != 0.0f)
115
{
116
float
scale =
App::GetInputEngine
()->
isKeyDown
(OIS::KC_LMENU) ? 0.1f : 1.0f;
117
scale *=
App::GetInputEngine
()->
isKeyDown
(
OIS::KC_LSHIFT
) ? 3.0f : 1.0f;
118
scale *=
App::GetInputEngine
()->
isKeyDown
(OIS::KC_LCONTROL) ? 10.0f : 1.0f;
119
120
Ogre::Vector3 rotation_center =
App::GetGameContext
()->
GetPlayerActor
()->
getRotationCenter
();
121
122
rotation *= Ogre::Math::Clamp(scale, 0.1f, 10.0f);
123
translation *= scale;
124
125
App::GetGameContext
()->
GetPlayerActor
()->
requestRotation
(rotation, rotation_center);
126
App::GetGameContext
()->
GetPlayerActor
()->
requestTranslation
(translation);
127
128
if
(
App::sim_soft_reset_mode
->getBool())
129
{
130
for
(
ActorPtr
& actor :
App::GetGameContext
()->GetPlayerActor()->ar_linked_actors)
131
{
132
actor->requestRotation(rotation, rotation_center);
133
actor->requestTranslation(translation);
134
}
135
}
136
137
m_live_repair_timer
= 0.0f;
138
}
139
else
if
(
App::GetInputEngine
()->isKeyDownValueBounce(
OIS::KC_SPACE
))
140
{
141
App::GetGameContext
()->
GetPlayerActor
()->
requestAngleSnap
(45);
142
if
(
App::sim_soft_reset_mode
->getBool())
143
{
144
for
(
ActorPtr
& actor :
App::GetGameContext
()->GetPlayerActor()->ar_linked_actors)
145
{
146
actor->requestAngleSnap(45);
147
}
148
}
149
}
150
else
151
{
152
m_live_repair_timer
+= dt;
153
}
154
155
auto
reset_type =
ActorModifyRequest::Type::RESET_ON_SPOT
;
156
if
(
App::sim_soft_reset_mode
->getBool())
157
{
158
reset_type =
ActorModifyRequest::Type::SOFT_RESET
;
159
for
(
ActorPtr
& actor :
App::GetGameContext
()->GetPlayerActor()->ar_linked_actors)
160
{
161
ActorModifyRequest
* rq =
new
ActorModifyRequest
;
162
rq->
amr_actor
= actor->ar_instance_id;
163
rq->
amr_type
= reset_type;
164
App::GetGameContext
()->
PushMessage
(
Message
(
MSG_SIM_MODIFY_ACTOR_REQUESTED
, (
void
*)rq));
165
}
166
}
167
168
ActorModifyRequest
* rq =
new
ActorModifyRequest
;
169
rq->
amr_actor
=
App::GetGameContext
()->
GetPlayerActor
()->
ar_instance_id
;
170
rq->
amr_type
= reset_type;
171
App::GetGameContext
()->
PushMessage
(
Message
(
MSG_SIM_MODIFY_ACTOR_REQUESTED
, (
void
*)rq));
172
}
173
}
GameContext.h
Game state manager and message-queue provider.
RoR::MSG_SIM_MODIFY_ACTOR_REQUESTED
@ MSG_SIM_MODIFY_ACTOR_REQUESTED
Payload = RoR::ActorModifyRequest* (owner)
Definition:
Application.h:122
RoR::EV_COMMON_REPAIR_TRUCK
@ EV_COMMON_REPAIR_TRUCK
repair truck to original condition
Definition:
InputEngine.h:249
RoR::App::sim_soft_reset_mode
CVar * sim_soft_reset_mode
Definition:
Application.cpp:109
RoR::Actor::ar_instance_id
ActorInstanceID_t ar_instance_id
Static attr; session-unique ID.
Definition:
Actor.h:376
RoR::ActorState::LOCAL_REPLAY
@ LOCAL_REPLAY
RoR::App::sim_live_repair_interval
CVar * sim_live_repair_interval
Hold EV_COMMON_REPAIR_TRUCK to enter LiveRepair mode. 0 or negative interval disables.
Definition:
Application.cpp:111
RoR::EV_CHARACTER_BACKWARDS
@ EV_CHARACTER_BACKWARDS
step backwards with the character
Definition:
InputEngine.h:128
RoR::EV_COMMON_LIVE_REPAIR_MODE
@ EV_COMMON_LIVE_REPAIR_MODE
toggles live repair and recovery mode, controlled by keyboard
Definition:
InputEngine.h:250
RoR::App::sim_state
CVar * sim_state
Definition:
Application.cpp:96
RefCountingObjectPtr< Actor >
Actor.h
RoR::InputEngine::isKeyDown
bool isKeyDown(OIS::KeyCode mod)
Asks OIS directly.
Definition:
InputEngine.cpp:1177
RoR::Actor::requestAngleSnap
void requestAngleSnap(int division)
Definition:
Actor.h:106
RoR::ActorModifyRequest::amr_actor
ActorInstanceID_t amr_actor
Definition:
SimData.h:870
RoR::EV_TRUCK_STEER_LEFT
@ EV_TRUCK_STEER_LEFT
steer left
Definition:
InputEngine.h:359
Script2Game::KC_LSHIFT
enum Script2Game::inputEvents KC_LSHIFT
RoR::RepairMode::m_quick_repair_active
bool m_quick_repair_active
Definition:
RepairMode.h:47
RoR::ActorModifyRequest
Definition:
SimData.h:852
RoR::EV_CHARACTER_SIDESTEP_RIGHT
@ EV_CHARACTER_SIDESTEP_RIGHT
sidestep to the right
Definition:
InputEngine.h:137
RoR::GameContext::PushMessage
void PushMessage(Message m)
Doesn't guarantee order! Use ChainMessage() if order matters.
Definition:
GameContext.cpp:66
RoR::Actor::requestRotation
void requestRotation(float rotation, Ogre::Vector3 center)
Definition:
Actor.h:105
Script2Game::KC_SPACE
enum Script2Game::inputEvents KC_SPACE
RoR::InputEngine::getEventBoolValue
bool getEventBoolValue(int eventID)
Definition:
InputEngine.cpp:764
RoR::App::GetGameContext
GameContext * GetGameContext()
Definition:
Application.cpp:284
RoR::EV_CHARACTER_FORWARD
@ EV_CHARACTER_FORWARD
step forward with the character
Definition:
InputEngine.h:129
RoR::EV_TRUCK_ACCELERATE
@ EV_TRUCK_ACCELERATE
accelerate the truck
Definition:
InputEngine.h:296
RoR::Actor::getRotation
float getRotation()
Definition:
Actor.cpp:356
RoR::Message
Unified game event system - all requests and state changes are reported using a message.
Definition:
GameContext.h:51
RoR::EV_TRUCK_STEER_RIGHT
@ EV_TRUCK_STEER_RIGHT
steer right
Definition:
InputEngine.h:360
RoR::ActorModifyRequest::Type::SOFT_RESET
@ SOFT_RESET
RoR::RepairMode::m_live_repair_timer
float m_live_repair_timer
Definition:
RepairMode.h:49
RoR::Actor::getRotationCenter
Ogre::Vector3 getRotationCenter()
Definition:
Actor.cpp:1461
RoR::Actor::requestTranslation
void requestTranslation(Ogre::Vector3 translation)
Definition:
Actor.h:107
RoR::App::GetInputEngine
InputEngine * GetInputEngine()
Definition:
Application.cpp:275
RoR::EV_CHARACTER_SIDESTEP_LEFT
@ EV_CHARACTER_SIDESTEP_LEFT
sidestep to the left
Definition:
InputEngine.h:136
RoR::SimState::RUNNING
@ RUNNING
RepairMode.h
Actor feat - interactive recovery and repair mode.
InputEngine.h
Handles controller inputs from player. Defines input events and binding mechanism,...
RoR::CVar::getFloat
float getFloat() const
Definition:
CVar.h:96
RoR::RepairMode::UpdateInputEvents
void UpdateInputEvents(float dt)
Definition:
RepairMode.cpp:30
RoR::ActorState::NETWORKED_OK
@ NETWORKED_OK
not simulated (remote) actor
RoR::GameContext::GetPlayerActor
const ActorPtr & GetPlayerActor()
Definition:
GameContext.h:134
RoR::ActorModifyRequest::amr_type
Type amr_type
Definition:
SimData.h:871
RoR
Definition:
AppContext.h:36
RoR::EV_TRUCK_BRAKE
@ EV_TRUCK_BRAKE
brake
Definition:
InputEngine.h:305
RoR::RepairMode::m_live_repair_active
bool m_live_repair_active
Definition:
RepairMode.h:48
RoR::ActorModifyRequest::Type::RESET_ON_SPOT
@ RESET_ON_SPOT
Generated by
1.8.17