Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Payphones
- Loading branch information
Showing
15 changed files
with
474 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
#include "engine/Payphone.hpp" | ||
|
||
#include <rw/defines.hpp> | ||
|
||
#include "ai/PlayerController.hpp" | ||
|
||
#include "engine/GameState.hpp" | ||
#include "engine/GameWorld.hpp" | ||
|
||
#include "objects/CharacterObject.hpp" | ||
#include "objects/GameObject.hpp" | ||
#include "objects/InstanceObject.hpp" | ||
|
||
Payphone::Payphone(GameWorld* engine_, const int id_, const glm::vec2 coord) | ||
: engine(engine_), id(id_) { | ||
// Find payphone object, original game does this differently | ||
for (const auto& p : engine->instancePool.objects) { | ||
auto o = p.second; | ||
if (!o->getModel()) { | ||
continue; | ||
} | ||
if (o->getModelInfo<BaseModelInfo>()->name != "phonebooth1") { | ||
continue; | ||
} | ||
if (glm::distance(coord, glm::vec2(o->getPosition())) < 2.f) { | ||
object = static_cast<InstanceObject*>(o); | ||
break; | ||
} | ||
} | ||
|
||
message.clear(); | ||
|
||
if (object) { | ||
position = object->getPosition(); | ||
} | ||
} | ||
|
||
void Payphone::enable() { | ||
state = State::Ringing; | ||
} | ||
|
||
void Payphone::disable() { | ||
state = State::Idle; | ||
} | ||
|
||
bool Payphone::isTalking() const { | ||
return state == State::Talking; | ||
} | ||
|
||
void Payphone::setMessageAndStartRinging(const std::string& m) { | ||
state = State::Ringing; | ||
message = m; | ||
} | ||
|
||
void Payphone::tick(float dt) { | ||
RW_UNUSED(dt); | ||
|
||
switch (state) { | ||
case State::Idle: { | ||
break; | ||
} | ||
|
||
case State::Ringing: { | ||
if (glm::distance( | ||
position, | ||
engine->getPlayer()->getCharacter()->getPosition()) < 1.f) { | ||
state = State::PickingUp; | ||
|
||
engine->getPlayer()->pickUpPayphone(); | ||
|
||
engine->state->isCinematic = true; | ||
engine->getPlayer()->prepareForCutscene(); | ||
|
||
engine->getPlayer()->getCharacter()->setHeading(glm::degrees( | ||
glm::atan(position.x, position.y) + glm::half_pi<float>())); | ||
} | ||
|
||
// @todo Do wiggle animation | ||
|
||
break; | ||
} | ||
|
||
case State::PickingUp: { | ||
if (!engine->getPlayer()->isPickingUpPayphone()) { | ||
state = State::Talking; | ||
|
||
if (!message.empty()) { | ||
const auto& text = | ||
ScreenText::format(engine->data->texts.text(message)); | ||
|
||
engine->state->text.clear<ScreenTextType::HighPriority>(); | ||
engine->state->text.addText<ScreenTextType::HighPriority>( | ||
ScreenTextEntry::makeHighPriority(message, text, 3000)); | ||
|
||
message.clear(); | ||
} | ||
|
||
callTimer = engine->getGameTime() + 3.f; | ||
} | ||
|
||
break; | ||
} | ||
|
||
case State::Talking: { | ||
if (callTimer <= engine->getGameTime()) { | ||
state = State::HangingUp; | ||
|
||
engine->getPlayer()->hangUpPayphone(); | ||
} | ||
|
||
break; | ||
} | ||
|
||
case State::HangingUp: { | ||
if (!engine->getPlayer()->isHangingUpPayphone()) { | ||
state = State::Idle; | ||
|
||
engine->state->isCinematic = false; | ||
engine->getPlayer()->freeFromCutscene(); | ||
} | ||
|
||
break; | ||
} | ||
|
||
default: { break; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#ifndef _RWENGINE_PAYPHONE_HPP_ | ||
#define _RWENGINE_PAYPHONE_HPP_ | ||
|
||
#include <glm/glm.hpp> | ||
#include <string> | ||
|
||
class PlayerController; | ||
|
||
class GameWorld; | ||
class GameState; | ||
|
||
class GameObject; | ||
class InstanceObject; | ||
class CharacterObject; | ||
|
||
class Payphone { | ||
private: | ||
InstanceObject* object; | ||
glm::vec3 position; | ||
GameWorld* engine; | ||
float callTimer = 0.f; | ||
std::string message; | ||
|
||
public: | ||
enum class State { Idle, Ringing, PickingUp, Talking, HangingUp }; | ||
|
||
State state = State::Idle; | ||
|
||
int id; | ||
|
||
int getScriptObjectID() const { | ||
return id; | ||
} | ||
|
||
Payphone(GameWorld* engine_, const int id_, const glm::vec2 coord); | ||
~Payphone() = default; | ||
|
||
// Makes a payphone ring | ||
void enable(); | ||
// Disables ringing | ||
void disable(); | ||
// Is currently used by player | ||
bool isTalking() const; | ||
// Sets a message and makes a payphone ring | ||
void setMessageAndStartRinging(const std::string& m); | ||
void tick(float dt); | ||
}; | ||
|
||
#endif |
Oops, something went wrong.