|
|
@@ -34,20 +34,9 @@ template<>EntityManager *Ogre::Singleton<EntityManager>::msSingleton = nullptr;
|
|
|
ConfigVar cv_debug_grid("debug_grid", "Draw debug grid", "false");
|
|
|
ConfigVar cv_debug_axis("debug_axis", "Draw debug axis", "false");
|
|
|
|
|
|
-/**
|
|
|
- * Calculates the point elevation over a plane.
|
|
|
- *
|
|
|
- * @param[in] point Point to calculate the elevation of.
|
|
|
- * @param[in] a First point of the plane.
|
|
|
- * @param[in] b Second point of the plane.
|
|
|
- * @param[in] c Third point of the plane.
|
|
|
- * @return The elevation of the point.
|
|
|
- */
|
|
|
-float PointElevation(
|
|
|
- const Ogre::Vector2& point,
|
|
|
- const Ogre::Vector3& a, const Ogre::Vector3& b, const Ogre::Vector3& c
|
|
|
+float EntityManager::PointElevation(
|
|
|
+ const Ogre::Vector2& point, const Ogre::Vector3& a, const Ogre::Vector3& b, const Ogre::Vector3& c
|
|
|
){
|
|
|
- // TODO: Declare function in header file.
|
|
|
float _a = a.z * (b.y - c.y) + b.z * (c.y - a.y) + c.z * (a.y - b.y);
|
|
|
float _b = a.y * (b.x - c.x) + b.y * (c.x - a.x) + c.y * (a.x - b.x);
|
|
|
float _c = a.x * (b.z - c.z) + b.x * (c.z - a.z) + c.x * (a.z - b.z);
|
|
|
@@ -57,40 +46,16 @@ float PointElevation(
|
|
|
return (_d - _c * point.y - _a * point.x) / _b;
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * @todo Understand and document.
|
|
|
- *
|
|
|
- * @param[in] point @todo
|
|
|
- * @param[in] p1 @todo
|
|
|
- * @param[in] p2 @todo
|
|
|
- * @return @todo
|
|
|
- */
|
|
|
-float SideOfVector(
|
|
|
- const Ogre::Vector2& point, const Ogre::Vector2& p1, const Ogre::Vector2& p2
|
|
|
-){
|
|
|
- // TODO: Declare function in header file.
|
|
|
+float EntityManager::SideOfVector(const Ogre::Vector2& point, const Ogre::Vector2& p1, const Ogre::Vector2& p2){
|
|
|
Ogre::Vector2 AB = p2 - p1;
|
|
|
Ogre::Vector2 AP = point - p1;
|
|
|
return AB.x * AP.y - AB.y * AP.x;
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * Calculates the square distance between a point and a line.
|
|
|
- *
|
|
|
- * The calculated distance is the vector orthogonal to the line that
|
|
|
- * passes by the point, i.e. the shortest distance.
|
|
|
- *
|
|
|
- * @param[in] point The point.
|
|
|
- * @param[in] point_a First point of the line.
|
|
|
- * @param[in] point_b Second point of the line.
|
|
|
- * @param[out] proj Vector representing the shortest distance.
|
|
|
- * @return The distance from the point to the line.
|
|
|
- */
|
|
|
-float SquareDistanceToLine(
|
|
|
+float EntityManager::SquareDistanceToLine(
|
|
|
const Ogre::Vector3& point, const Ogre::Vector3& point_a, const Ogre::Vector3& point_b,
|
|
|
Ogre::Vector3& proj
|
|
|
){
|
|
|
- // TODO: Declare function in header file.
|
|
|
float temp =
|
|
|
-((point_a.x - point.x) * (point_b.x - point_a.x) + (point_a.y - point.y)
|
|
|
* (point_b.y - point_a.y) + (point_a.z - point.z) * (point_b.z - point_a.z))
|
|
|
@@ -105,33 +70,22 @@ float SquareDistanceToLine(
|
|
|
((point_a.x >= proj.x && point_b.x <= proj.x) || (point_a.x < proj.x && point_b.x >= proj.x))
|
|
|
&& (
|
|
|
(point_a.y >= proj.y && point_b.y <= proj.y) || (point_a.y < proj.y && point_b.y >= proj.y)
|
|
|
- )
|
|
|
- ){
|
|
|
+ )
|
|
|
+ ){
|
|
|
return (proj.x - point.x) * (proj.x - point.x) + (proj.y - point.y)
|
|
|
* (proj.y - point.y) + (proj.z - point.z) * (proj.z - point.z);
|
|
|
}
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * Calculates the direction degree between to points.
|
|
|
- *
|
|
|
- * @param[in] current_point Origin point.
|
|
|
- * @param[in] direction_point Next point in the direction.
|
|
|
- * @return Degrees between the two points
|
|
|
- */
|
|
|
-Ogre::Degree GetDirectionToPoint(
|
|
|
+Ogre::Degree EntityManager::GetDirectionToPoint(
|
|
|
const Ogre::Vector3& current_point, const Ogre::Vector3& direction_point
|
|
|
){
|
|
|
// TODO: Declare function in header file.
|
|
|
Ogre::Vector2 up(0.0f, -1.0f);
|
|
|
- Ogre::Vector2 dir(
|
|
|
- direction_point.x - current_point.x, direction_point.y - current_point.y
|
|
|
- );
|
|
|
+ Ogre::Vector2 dir(direction_point.x - current_point.x, direction_point.y - current_point.y);
|
|
|
// Angle between vectors
|
|
|
- Ogre::Degree angle(
|
|
|
- Ogre::Radian(acosf(dir.dotProduct(up) / (dir.length() * up.length())))
|
|
|
- );
|
|
|
+ Ogre::Degree angle(Ogre::Radian(acosf(dir.dotProduct(up) / (dir.length() * up.length()))));
|
|
|
return (dir.x < 0) ? Ogre::Degree(360) - angle : angle;
|
|
|
}
|
|
|
|
|
|
@@ -151,55 +105,35 @@ EntityManager::EntityManager():
|
|
|
|
|
|
//grid_ = Ogre::Root::getSingleton().getSceneManager("Scene")
|
|
|
// ->createEntity("Grid", "system/grid.mesh");
|
|
|
- grid_ = Ogre::Root::getSingleton().getSceneManager("Scene")
|
|
|
- ->createEntity("Grid", "grid.mesh");
|
|
|
+ grid_ = Ogre::Root::getSingleton().getSceneManager("Scene")->createEntity("Grid", "grid.mesh");
|
|
|
scene_node_->attachObject(grid_);
|
|
|
//axis_ = Ogre::Root::getSingleton().getSceneManager("Scene")
|
|
|
// ->createEntity("Axis", "system/axis.mesh");
|
|
|
- axis_ = Ogre::Root::getSingleton().getSceneManager("Scene")
|
|
|
- ->createEntity("Axis", "axis.mesh");
|
|
|
+ axis_ = Ogre::Root::getSingleton().getSceneManager("Scene")->createEntity("Axis", "axis.mesh");
|
|
|
scene_node_->attachObject(axis_);
|
|
|
}
|
|
|
|
|
|
EntityManager::~EntityManager(){
|
|
|
- if (grid_ != nullptr){
|
|
|
- Ogre::Root::getSingleton().getSceneManager("Scene")->destroyEntity(
|
|
|
- grid_
|
|
|
- );
|
|
|
- }
|
|
|
- if (axis_ != nullptr){
|
|
|
- Ogre::Root::getSingleton().getSceneManager("Scene")->destroyEntity(
|
|
|
- axis_
|
|
|
- );
|
|
|
- }
|
|
|
+ if (grid_ != nullptr) Ogre::Root::getSingleton().getSceneManager("Scene")->destroyEntity(grid_);
|
|
|
+ if (axis_ != nullptr) Ogre::Root::getSingleton().getSceneManager("Scene")->destroyEntity(axis_);
|
|
|
Clear();
|
|
|
- Ogre::Root::getSingleton().getSceneManager("Scene")->getRootSceneNode()
|
|
|
- ->removeAndDestroyChild("EntityManager");
|
|
|
+ Ogre::Root::getSingleton().getSceneManager("Scene")->getRootSceneNode()->removeAndDestroyChild(
|
|
|
+ "EntityManager"
|
|
|
+ );
|
|
|
LOG_TRIVIAL("EntityManager destroyed.");
|
|
|
}
|
|
|
|
|
|
void EntityManager::Input(const VGears::Event& event){
|
|
|
background_2d_.InputDebug(event);
|
|
|
if (paused_ == true) return;
|
|
|
-
|
|
|
if (player_entity_ != NULL && player_lock_ == false){
|
|
|
- if (event.type == VGears::ET_KEY_REPEAT && event.event == "walk_left")
|
|
|
- player_move_.x = -1;
|
|
|
- else if (
|
|
|
- event.type == VGears::ET_KEY_REPEAT && event.event == "walk_right"
|
|
|
- ){
|
|
|
+ if (event.type == VGears::ET_KEY_REPEAT && event.event == "walk_left") player_move_.x = -1;
|
|
|
+ else if (event.type == VGears::ET_KEY_REPEAT && event.event == "walk_right")
|
|
|
player_move_.x = 1;
|
|
|
- }
|
|
|
- if (event.type == VGears::ET_KEY_REPEAT && event.event == "walk_down")
|
|
|
- player_move_.y = -1;
|
|
|
- else if (
|
|
|
- event.type == VGears::ET_KEY_REPEAT && event.event == "walk_up"
|
|
|
- ){
|
|
|
+ if (event.type == VGears::ET_KEY_REPEAT && event.event == "walk_down") player_move_.y = -1;
|
|
|
+ else if (event.type == VGears::ET_KEY_REPEAT && event.event == "walk_up")
|
|
|
player_move_.y = 1;
|
|
|
- }
|
|
|
- if (event.type == VGears::ET_KEY_REPEAT && event.event == "run")
|
|
|
- player_run_ = true;
|
|
|
-
|
|
|
+ if (event.type == VGears::ET_KEY_REPEAT && event.event == "run") player_run_ = true;
|
|
|
if (event.type == VGears::ET_KEY_PRESS && event.event == "interact"){
|
|
|
CheckEntityInteract();
|
|
|
for (unsigned int i = 0; i < entity_triggers_.size(); ++ i){
|
|
|
@@ -207,18 +141,17 @@ void EntityManager::Input(const VGears::Event& event){
|
|
|
entity_triggers_[i]->IsEnabled() == true
|
|
|
&& entity_triggers_[i]->IsActivator(player_entity_) == true
|
|
|
){
|
|
|
- ScriptEntity* scr_entity
|
|
|
- = ScriptManager::getSingleton().GetScriptEntityByName(
|
|
|
- ScriptManager::ENTITY, entity_triggers_[i]->GetName()
|
|
|
- );
|
|
|
+ ScriptEntity* scr_entity = ScriptManager::getSingleton().GetScriptEntityByName(
|
|
|
+ ScriptManager::ENTITY, entity_triggers_[i]->GetName()
|
|
|
+ );
|
|
|
bool added = ScriptManager::getSingleton().ScriptRequest(
|
|
|
scr_entity, "on_interact", 1, "", "", false, false
|
|
|
);
|
|
|
if (added == false){
|
|
|
+ // TODO: This pop's in almost any trigger, but it still works. Check it out.
|
|
|
LOG_WARNING(
|
|
|
- "Script \"on_interact\" for entity \""
|
|
|
- + entity_triggers_[i]->GetName()
|
|
|
- + "\" doesn't exist."
|
|
|
+ "Script 'on_interact' for entity '" + entity_triggers_[i]->GetName()
|
|
|
+ + "' doesn't exist."
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
@@ -243,11 +176,8 @@ void EntityManager::Update(){
|
|
|
Entity::State state = player_entity_->GetState();
|
|
|
if (state == Entity::WALKMESH || state == Entity::NONE){
|
|
|
player_move_
|
|
|
- *= player_entity_->GetMoveWalkSpeed()
|
|
|
- * Timer::getSingleton().GetGameTimeDelta();
|
|
|
- player_entity_->SetMovePosition(
|
|
|
- player_entity_->GetPosition() + player_move_
|
|
|
- );
|
|
|
+ *= player_entity_->GetMoveWalkSpeed() * Timer::getSingleton().GetGameTimeDelta();
|
|
|
+ player_entity_->SetMovePosition(player_entity_->GetPosition() + player_move_);
|
|
|
player_entity_->SetState(Entity::WALKMESH);
|
|
|
}
|
|
|
|
|
|
@@ -265,13 +195,11 @@ void EntityManager::Update(){
|
|
|
// if time is stopped)
|
|
|
if (Timer::getSingleton().GetGameTimeDelta() == 0) continue;
|
|
|
|
|
|
- // update screen scroll
|
|
|
+ // Update screen scroll.
|
|
|
Entity* scroll_entity = background_2d_.GetAutoScrollEntity();
|
|
|
if (scroll_entity == entity_[i]){
|
|
|
CameraManager &camera_manager(CameraManager::getSingleton());
|
|
|
- Ogre::Vector3 view = camera_manager.ProjectPointToScreen(
|
|
|
- scroll_entity->GetPosition()
|
|
|
- );
|
|
|
+ Ogre::Vector3 view = camera_manager.ProjectPointToScreen(scroll_entity->GetPosition());
|
|
|
Ogre::Vector2 pos = background_2d_.GetScreenScroll();
|
|
|
Ogre::Viewport *viewport(camera_manager.getViewport());
|
|
|
float width = float(viewport->getActualWidth());
|
|
|
@@ -280,40 +208,35 @@ void EntityManager::Update(){
|
|
|
view.y = view.y - height / 2 - pos.y;
|
|
|
background_2d_.SetScreenScroll(Ogre::Vector2(-view.x, -view.y));
|
|
|
}
|
|
|
-
|
|
|
- // Update offseting
|
|
|
- if (entity_[i]->GetOffsetType() != AT_NONE)
|
|
|
- SetNextOffsetStep(entity_[i]);
|
|
|
-
|
|
|
- // Update turning
|
|
|
+ // Update offset.
|
|
|
+ if (entity_[i]->GetOffsetType() != AT_NONE) SetNextOffsetStep(entity_[i]);
|
|
|
+ // Update turn.
|
|
|
if (entity_[i]->GetTurnType() != AT_NONE) SetNextTurnStep(entity_[i]);
|
|
|
-
|
|
|
- // Update movement
|
|
|
+ // Update movement.
|
|
|
switch(entity_[i]->GetState()){
|
|
|
case Entity::WALKMESH:
|
|
|
{
|
|
|
- bool is_move = false;
|
|
|
-
|
|
|
- // Try set entity on walkmesh if it's still don't has triangle
|
|
|
+ // Try set entity on walkmesh if it's still don't has triangle.
|
|
|
if (entity_[i]->GetMoveTriangleId() == -1){
|
|
|
if (SetEntityOnWalkmesh(entity_[i]) == false){
|
|
|
LOG_TRIVIAL(
|
|
|
- "Can't set entity \"" + entity_[i]->GetName()
|
|
|
- + "\" on walkmesh. Finish move."
|
|
|
+ "Can't set entity '" + entity_[i]->GetName()
|
|
|
+ + "' on walkmesh. Finish move."
|
|
|
);
|
|
|
entity_[i]->UnsetMove();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
// Perform move
|
|
|
if (entity_[i]->GetState() == Entity::WALKMESH){
|
|
|
float speed = 0;
|
|
|
if (player_lock_ == false && player_entity_ == entity_[i]){
|
|
|
speed = entity_[i]->GetMoveWalkSpeed();
|
|
|
+ // TODO: Set as a constant.
|
|
|
+ // Or even better, as a configurable variable.
|
|
|
if (player_run_ == true) speed *= 4;
|
|
|
}
|
|
|
else speed = entity_[i]->GetMoveAutoSpeed();
|
|
|
- is_move = PerformWalkmeshMove(entity_[i], speed);
|
|
|
+ bool is_move = PerformWalkmeshMove(entity_[i], speed);
|
|
|
if (entity_[i]->GetMoveAutoAnimation() == true){
|
|
|
if (is_move == true){
|
|
|
if (speed >= entity_[i]->GetMoveRunSpeed()){
|
|
|
@@ -328,8 +251,7 @@ void EntityManager::Update(){
|
|
|
}
|
|
|
}
|
|
|
else if (
|
|
|
- entity_[i]->GetAnimationState()
|
|
|
- != Entity::REQUESTED_ANIMATION
|
|
|
+ entity_[i]->GetAnimationState() != Entity::REQUESTED_ANIMATION
|
|
|
){
|
|
|
entity_[i]->PlayAnimationContinue(
|
|
|
entity_[i]->GetDefaultAnimationName()
|
|
|
@@ -339,20 +261,16 @@ void EntityManager::Update(){
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
-
|
|
|
case Entity::LINEAR:
|
|
|
CheckTriggers(entity_[i], entity_[i]->GetPosition());
|
|
|
SetNextLinearStep(entity_[i]);
|
|
|
break;
|
|
|
-
|
|
|
case Entity::JUMP:
|
|
|
SetNextJumpStep(entity_[i]);
|
|
|
break;
|
|
|
-
|
|
|
case Entity::NEEDS_TO_REATTACH:
|
|
|
if (SetEntityOnWalkmesh(entity_[i])) entity_[i]->SetState(Entity::WALKMESH);
|
|
|
else entity_[i]->SetState(Entity::NONE);
|
|
|
-
|
|
|
case Entity::NONE:
|
|
|
CheckTriggers(entity_[i], entity_[i]->GetPosition());
|
|
|
if (entity_[i]->GetAnimationState() != Entity::REQUESTED_ANIMATION)
|
|
|
@@ -360,26 +278,19 @@ void EntityManager::Update(){
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
// Reset player move. It already must be handled in update
|
|
|
player_move_ = Ogre::Vector3::ZERO;
|
|
|
player_run_ = false;
|
|
|
-
|
|
|
- if (background_2d_.GetScrollType() != Background2D::NONE)
|
|
|
- SetNextScrollStep();
|
|
|
+ if (background_2d_.GetScrollType() != Background2D::NONE) SetNextScrollStep();
|
|
|
background_2d_.Update();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
void EntityManager::UpdateDebug(){
|
|
|
grid_->setVisible(cv_debug_grid.GetB());
|
|
|
axis_->setVisible(cv_debug_axis.GetB());
|
|
|
- for (unsigned int i = 0; i < entity_.size(); ++ i)
|
|
|
- entity_[i]->UpdateDebug();
|
|
|
- for (unsigned int i = 0; i < entity_triggers_.size(); ++ i)
|
|
|
- entity_triggers_[i]->UpdateDebug();
|
|
|
- for (unsigned int i = 0; i < entity_points_.size(); ++ i)
|
|
|
- entity_points_[i]->UpdateDebug();
|
|
|
+ for (unsigned int i = 0; i < entity_.size(); ++ i) entity_[i]->UpdateDebug();
|
|
|
+ for (unsigned int i = 0; i < entity_triggers_.size(); ++ i) entity_triggers_[i]->UpdateDebug();
|
|
|
+ for (unsigned int i = 0; i < entity_points_.size(); ++ i) entity_points_[i]->UpdateDebug();
|
|
|
walkmesh_.UpdateDebug();
|
|
|
background_2d_.UpdateDebug();
|
|
|
}
|
|
|
@@ -391,9 +302,7 @@ void EntityManager::Clear(){
|
|
|
background_2d_.Clear();
|
|
|
DialogsManager::getSingleton().Clear();
|
|
|
for (unsigned int i = 0; i < entity_.size(); ++ i){
|
|
|
- ScriptManager::getSingleton().RemoveEntity(
|
|
|
- ScriptManager::ENTITY, entity_[i]->GetName()
|
|
|
- );
|
|
|
+ ScriptManager::getSingleton().RemoveEntity(ScriptManager::ENTITY, entity_[i]->GetName());
|
|
|
delete entity_[i];
|
|
|
}
|
|
|
entity_.clear();
|
|
|
@@ -401,7 +310,6 @@ void EntityManager::Clear(){
|
|
|
player_move_ = Ogre::Vector3::ZERO;
|
|
|
player_move_rotation_ = 0;
|
|
|
player_lock_ = false;
|
|
|
-
|
|
|
for (unsigned int i = 0; i < entity_triggers_.size(); ++ i){
|
|
|
ScriptManager::getSingleton().RemoveEntity(
|
|
|
ScriptManager::ENTITY, entity_triggers_[i]->GetName()
|
|
|
@@ -409,17 +317,10 @@ void EntityManager::Clear(){
|
|
|
delete entity_triggers_[i];
|
|
|
}
|
|
|
entity_triggers_.clear();
|
|
|
-
|
|
|
- for (unsigned int i = 0; i < entity_points_.size(); ++ i)
|
|
|
- delete entity_points_[i];
|
|
|
+ for (unsigned int i = 0; i < entity_points_.size(); ++ i) delete entity_points_[i];
|
|
|
entity_points_.clear();
|
|
|
-
|
|
|
- for (unsigned int i = 0; i < entity_scripts_.size(); ++ i){
|
|
|
- ScriptManager::getSingleton().RemoveEntity(
|
|
|
- ScriptManager::ENTITY, entity_scripts_[i]
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
+ for (unsigned int i = 0; i < entity_scripts_.size(); ++ i)
|
|
|
+ ScriptManager::getSingleton().RemoveEntity(ScriptManager::ENTITY, entity_scripts_[i]);
|
|
|
scene_node_->removeAndDestroyAllChildren();
|
|
|
}
|
|
|
|
|
|
@@ -440,9 +341,9 @@ void EntityManager::AddEntity(
|
|
|
}
|
|
|
|
|
|
void EntityManager::AddEntity(
|
|
|
- const Ogre::String& name, const Ogre::String& file_name,
|
|
|
- const Ogre::Vector3& position, const Ogre::Degree& rotation,
|
|
|
- const Ogre::Vector3& scale, const Ogre::Quaternion& root_orientation, int index
|
|
|
+ const Ogre::String& name, const Ogre::String& file_name, const Ogre::Vector3& position,
|
|
|
+ const Ogre::Degree& rotation, const Ogre::Vector3& scale,
|
|
|
+ const Ogre::Quaternion& root_orientation, int index
|
|
|
){
|
|
|
Ogre::SceneNode* node = scene_node_->createChildSceneNode("Model_" + name);
|
|
|
EntityModel* entity = new EntityModel(name, file_name, node);
|
|
|
@@ -452,17 +353,13 @@ void EntityManager::AddEntity(
|
|
|
entity->SetIndex(index);
|
|
|
entity->setRootOrientation(root_orientation);
|
|
|
entity_.push_back(entity);
|
|
|
- ScriptManager::getSingleton().AddEntity(
|
|
|
- ScriptManager::ENTITY, entity->GetName(), entity
|
|
|
- );
|
|
|
+ ScriptManager::getSingleton().AddEntity(ScriptManager::ENTITY, entity->GetName(), entity);
|
|
|
}
|
|
|
|
|
|
void EntityManager::ScriptAddEntity(
|
|
|
const char* name, const char* file_name,
|
|
|
const float x, const float y, const float z, const float rotation, int index
|
|
|
-){
|
|
|
- AddEntity(name, file_name, Ogre::Vector3(x, y, z), Ogre::Degree(rotation), index);
|
|
|
-}
|
|
|
+){AddEntity(name, file_name, Ogre::Vector3(x, y, z), Ogre::Degree(rotation), index);}
|
|
|
|
|
|
void EntityManager::AddEntityTrigger(
|
|
|
const Ogre::String& name,
|
|
|
@@ -472,9 +369,7 @@ void EntityManager::AddEntityTrigger(
|
|
|
trigger->SetPoints(point1, point2);
|
|
|
trigger->SetEnabled(enabled);
|
|
|
entity_triggers_.push_back(trigger);
|
|
|
- ScriptManager::getSingleton().AddEntity(
|
|
|
- ScriptManager::ENTITY, trigger->GetName(), nullptr
|
|
|
- );
|
|
|
+ ScriptManager::getSingleton().AddEntity(ScriptManager::ENTITY, trigger->GetName(), nullptr);
|
|
|
}
|
|
|
|
|
|
void EntityManager::AddEntityPoint(
|
|
|
@@ -486,37 +381,28 @@ void EntityManager::AddEntityPoint(
|
|
|
entity_points_.push_back(entity_point);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
void EntityManager::AddEntityScript(const Ogre::String& name){
|
|
|
entity_scripts_.push_back(name);
|
|
|
- ScriptManager::getSingleton().AddEntity(
|
|
|
- ScriptManager::ENTITY, name, nullptr
|
|
|
- );
|
|
|
+ ScriptManager::getSingleton().AddEntity(ScriptManager::ENTITY, name, nullptr);
|
|
|
}
|
|
|
|
|
|
-void EntityManager::ScriptAddEntityScript(const char* name){
|
|
|
- AddEntityScript(name);
|
|
|
-}
|
|
|
+void EntityManager::ScriptAddEntityScript(const char* name){AddEntityScript(name);}
|
|
|
|
|
|
Entity* EntityManager::GetEntity(const Ogre::String& name) const{
|
|
|
- for (unsigned int i = 0; i < entity_.size(); ++ i){
|
|
|
+ for (unsigned int i = 0; i < entity_.size(); ++ i)
|
|
|
if (entity_[i]->GetName() == name) return entity_[i];
|
|
|
- }
|
|
|
return nullptr;
|
|
|
}
|
|
|
|
|
|
Entity* EntityManager::GetEntityFromIndex(const int index) const{
|
|
|
- for (unsigned int i = 0; i < entity_.size(); ++ i){
|
|
|
+ for (unsigned int i = 0; i < entity_.size(); ++ i)
|
|
|
if (entity_[i]->GetIndex() == index) return entity_[i];
|
|
|
- }
|
|
|
return nullptr;
|
|
|
}
|
|
|
|
|
|
Entity* EntityManager::GetEntityFromCharacterId(const int id) const{
|
|
|
- for (unsigned int i = 0; i < entity_.size(); ++ i){
|
|
|
- if (entity_[i]->IsCharacter() && entity_[i]->GetCharacterId() == id)
|
|
|
- return entity_[i];
|
|
|
- }
|
|
|
+ for (unsigned int i = 0; i < entity_.size(); ++ i)
|
|
|
+ if (entity_[i]->IsCharacter() && entity_[i]->GetCharacterId() == id) return entity_[i];
|
|
|
return nullptr;
|
|
|
}
|
|
|
|
|
|
@@ -526,16 +412,14 @@ Entity* EntityManager::ScriptGetEntity(const char* name) const{
|
|
|
|
|
|
|
|
|
EntityPoint* EntityManager::ScriptGetEntityPoint(const char* name) const{
|
|
|
- for (unsigned int i = 0; i < entity_points_.size(); ++ i){
|
|
|
+ for (unsigned int i = 0; i < entity_points_.size(); ++ i)
|
|
|
if (entity_points_[i]->GetName() == name) return entity_points_[i];
|
|
|
- }
|
|
|
return nullptr;
|
|
|
}
|
|
|
|
|
|
void EntityManager::ScriptSetPlayerEntity(const char* name){
|
|
|
- for (unsigned int i = 0; i < entity_.size(); ++ i){
|
|
|
+ for (unsigned int i = 0; i < entity_.size(); ++ i)
|
|
|
if (entity_[i]->GetName() == name) player_entity_ = entity_[i];
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
Entity* EntityManager::ScriptGetPlayerEntity() const{return player_entity_;}
|
|
|
@@ -553,9 +437,7 @@ void EntityManager::SetPlayerMoveRotation(const Ogre::Radian rotation){
|
|
|
|
|
|
bool EntityManager::GetRandomEncounters(){return random_encounters_;}
|
|
|
|
|
|
-void EntityManager::SetRandomEncounters(bool active){
|
|
|
- random_encounters_ = active;
|
|
|
-}
|
|
|
+void EntityManager::SetRandomEncounters(bool active){random_encounters_ = active;}
|
|
|
|
|
|
float EntityManager::GetEncounterRate(){return encounter_rate_;}
|
|
|
|
|
|
@@ -575,29 +457,24 @@ void EntityManager::StartBattle(unsigned int formation){
|
|
|
bool EntityManager::IsKeyOn(unsigned int key_code){
|
|
|
// If the player is locked, always false.
|
|
|
// TODO: Maybe this will interfere with something down the road?
|
|
|
- // Some scene where the player can't move but muts press a button?
|
|
|
+ // Some scene where the player can't move but must press a button?
|
|
|
if (player_lock_) return false;
|
|
|
unsigned int code = key_code;
|
|
|
// Translate keycodes to game key codes.
|
|
|
// For example 32 is standard for "Enter", but in game is "Circle/Action".
|
|
|
- // TODO: Finish this list
|
|
|
+ // TODO: Finish this list.
|
|
|
switch (key_code){
|
|
|
case 32: code = OIS::KC_SPACE; break;
|
|
|
}
|
|
|
bool pressed = InputManager::getSingleton().IsButtonPressed(code);
|
|
|
- //std::cout << "[IsKeyOn] Key " << key_code << " pressed: "
|
|
|
- // << std::to_string(pressed) << std::endl;
|
|
|
return pressed;
|
|
|
}
|
|
|
|
|
|
bool EntityManager::IsKeyOff(unsigned int key_code){return !IsKeyOn(key_code);}
|
|
|
|
|
|
void EntityManager::SetEntityToCharacter(const char* entity_name, unsigned int char_id){
|
|
|
- for (unsigned int i = 0; i < entity_.size(); ++ i){
|
|
|
- if (entity_[i]->GetName() == entity_name){
|
|
|
- entity_[i]->SetCharacter(char_id);
|
|
|
- }
|
|
|
- }
|
|
|
+ for (unsigned int i = 0; i < entity_.size(); ++ i)
|
|
|
+ if (entity_[i]->GetName() == entity_name) entity_[i]->SetCharacter(char_id);
|
|
|
}
|
|
|
|
|
|
bool EntityManager::SetEntityOnWalkmesh(Entity* entity){
|
|
|
@@ -606,7 +483,6 @@ bool EntityManager::SetEntityOnWalkmesh(Entity* entity){
|
|
|
position2.x = position3.x;
|
|
|
position2.y = position3.y;
|
|
|
std::vector<std::pair<int, float>> triangles;
|
|
|
-
|
|
|
// Search for possible triangles.
|
|
|
for (int i = 0; i < walkmesh_.GetNumberOfTriangles(); ++ i){
|
|
|
Ogre::Vector3 A3 = walkmesh_.GetA(i);
|
|
|
@@ -615,27 +491,23 @@ bool EntityManager::SetEntityOnWalkmesh(Entity* entity){
|
|
|
Ogre::Vector2 A2(A3.x, A3.y);
|
|
|
Ogre::Vector2 B2(B3.x, B3.y);
|
|
|
Ogre::Vector2 C2(C3.x, C3.y);
|
|
|
-
|
|
|
if (Ogre::Math::pointInTri2D(position2, A2, B2, C2) == true){
|
|
|
triangles.push_back(std::make_pair(i, PointElevation(
|
|
|
position2, walkmesh_.GetA(i), walkmesh_.GetB(i), walkmesh_.GetC(i)
|
|
|
)));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
// If the coordinates doesn't match any triangle, exit.
|
|
|
if (triangles.size() == 0){
|
|
|
LOG_ERROR(
|
|
|
- "Can't find any triangle to place entity \"" + entity->GetName() + "\" on walkmesh."
|
|
|
+ "Can't find any triangle to place entity '" + entity->GetName() + "' on walkmesh."
|
|
|
);
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
// From the possible triangles, select the closest one (on the Z edge).
|
|
|
int closest_z_triangle = -1;
|
|
|
float closest_z_distance = 9999.0f;
|
|
|
float pos_z = position3.z;
|
|
|
- int triangle_id = -1;
|
|
|
for (size_t i = 0; i < triangles.size(); ++ i){
|
|
|
if (std::abs(pos_z - triangles[i].second) < closest_z_distance){
|
|
|
closest_z_triangle = triangles[i].first;
|
|
|
@@ -644,7 +516,7 @@ bool EntityManager::SetEntityOnWalkmesh(Entity* entity){
|
|
|
}
|
|
|
if (closest_z_triangle == -1){
|
|
|
LOG_ERROR(
|
|
|
- "Can't find nearby triangle to place entity \"" + entity->GetName() + "\" on walkmesh."
|
|
|
+ "Can't find nearby triangle to place entity '" + entity->GetName() + "' on walkmesh."
|
|
|
);
|
|
|
return false;
|
|
|
}
|
|
|
@@ -660,20 +532,16 @@ bool EntityManager::PerformWalkmeshMove(Entity* entity, const float speed){
|
|
|
direction.normalise();
|
|
|
direction *= Timer::getSingleton().GetGameTimeDelta();
|
|
|
direction *= speed;
|
|
|
-
|
|
|
- // If movement is still needed but speed or time don't allow it, just
|
|
|
- // return for now.
|
|
|
+ // If movement is still needed but speed or time don't allow it, just return for now.
|
|
|
if (direction.isZeroLength() == true){
|
|
|
CheckTriggers(entity, entity->GetPosition());
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
int current_triangle = entity->GetMoveTriangleId();
|
|
|
if (current_triangle == -1){
|
|
|
- LOG_ERROR("Entity \"" + entity->GetName() + "\" not placed on walkmesh and can't move.");
|
|
|
+ LOG_ERROR("Entity '" + entity->GetName() + "' not placed on walkmesh and can't move.");
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
Ogre::Vector3 rotation(0.0f, 0.0f, 0.0f);
|
|
|
Ogre::Quaternion q1(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
Ogre::Vector3 end_point(0.0f, 0.0f, 0.0f);
|
|
|
@@ -685,21 +553,18 @@ bool EntityManager::PerformWalkmeshMove(Entity* entity, const float speed){
|
|
|
bool first_entity_check = false;
|
|
|
bool second_entity_check = false;
|
|
|
bool third_entity_check = false;
|
|
|
-
|
|
|
// Shorten move vector by triangle angle
|
|
|
end_point.x = start_point.x + direction.x;
|
|
|
end_point.y = start_point.y + direction.y;
|
|
|
Ogre::Vector3 A3 = walkmesh_.GetA(current_triangle);
|
|
|
Ogre::Vector3 B3 = walkmesh_.GetB(current_triangle);
|
|
|
Ogre::Vector3 C3 = walkmesh_.GetC(current_triangle);
|
|
|
-
|
|
|
end_point.z = PointElevation(Ogre::Vector2(end_point.x, end_point.y), A3, B3, C3);
|
|
|
Ogre::Vector3 temp = end_point - start_point;
|
|
|
temp.normalise();
|
|
|
temp = temp * direction.length();
|
|
|
direction.x = temp.x;
|
|
|
direction.y = temp.y;
|
|
|
-
|
|
|
// Set the direction for the entity if it has to move.
|
|
|
if (entity->GetMoveAutoRotation() == true){
|
|
|
Ogre::Vector2 up(0.0f, -1.0f);
|
|
|
@@ -710,12 +575,9 @@ bool EntityManager::PerformWalkmeshMove(Entity* entity, const float speed){
|
|
|
angle = (direction.x < 0) ? Ogre::Degree(360) - angle : angle;
|
|
|
entity->SetRotation(Ogre::Degree(angle));
|
|
|
}
|
|
|
-
|
|
|
float solid = (entity->IsSolid() == true) ? entity->GetSolidRadius() : 0.01f;
|
|
|
-
|
|
|
// Get ending point.
|
|
|
end_point.z = start_point.z;
|
|
|
-
|
|
|
for (
|
|
|
int i = 0;
|
|
|
(entity == player_entity_ && i < 16)
|
|
|
@@ -726,7 +588,6 @@ bool EntityManager::PerformWalkmeshMove(Entity* entity, const float speed){
|
|
|
end_point = Ogre::Vector3(
|
|
|
start_point.x + direction.x, start_point.y + direction.y, start_point.z
|
|
|
);
|
|
|
-
|
|
|
// 1st check.
|
|
|
// Rotate move_vector +45.
|
|
|
q1.FromAngleAxis(Ogre::Radian(Ogre::Degree(45)), Ogre::Vector3::UNIT_Z);
|
|
|
@@ -735,17 +596,13 @@ bool EntityManager::PerformWalkmeshMove(Entity* entity, const float speed){
|
|
|
rotation.z = 0;
|
|
|
rotation.normalise();
|
|
|
rotation = q1 * rotation;
|
|
|
-
|
|
|
// Multiply move_vector by solid range
|
|
|
rotation = rotation * solid;
|
|
|
end_point2.x = end_point.x + rotation.x;
|
|
|
end_point2.y = end_point.y + rotation.y;
|
|
|
-
|
|
|
// Check_triangle.
|
|
|
- first_triangle_check
|
|
|
- = WalkmeshBorderCross(entity, end_point2, direction);
|
|
|
+ first_triangle_check = WalkmeshBorderCross(entity, end_point2, direction);
|
|
|
entity->SetMoveTriangleId(current_triangle);
|
|
|
-
|
|
|
// Model check.
|
|
|
first_entity_check = CheckSolidCollisions(entity, end_point2);
|
|
|
|
|
|
@@ -757,16 +614,13 @@ bool EntityManager::PerformWalkmeshMove(Entity* entity, const float speed){
|
|
|
rotation.z = 0;
|
|
|
rotation.normalise();
|
|
|
rotation = q1 * rotation;
|
|
|
-
|
|
|
// Multiply move_vector by solid range.
|
|
|
rotation = rotation * solid;
|
|
|
end_point2.x = end_point.x + rotation.x;
|
|
|
end_point2.y = end_point.y + rotation.y;
|
|
|
-
|
|
|
// Check triangle.
|
|
|
second_triangle_check = WalkmeshBorderCross(entity, end_point2, direction);
|
|
|
entity->SetMoveTriangleId(current_triangle);
|
|
|
-
|
|
|
// Model check.
|
|
|
second_entity_check = CheckSolidCollisions(entity, end_point2);
|
|
|
|
|
|
@@ -778,11 +632,9 @@ bool EntityManager::PerformWalkmeshMove(Entity* entity, const float speed){
|
|
|
rotation = rotation * solid;
|
|
|
end_point2.x = end_point.x + rotation.x;
|
|
|
end_point2.y = end_point.y + rotation.y;
|
|
|
-
|
|
|
// Check triangle.
|
|
|
third_triangle_check = WalkmeshBorderCross(entity, end_point2, direction);
|
|
|
entity->SetMoveTriangleId(current_triangle);
|
|
|
-
|
|
|
// Model check.
|
|
|
third_entity_check = CheckSolidCollisions(entity, end_point2);
|
|
|
|
|
|
@@ -794,7 +646,6 @@ bool EntityManager::PerformWalkmeshMove(Entity* entity, const float speed){
|
|
|
){
|
|
|
// Only for NPC.
|
|
|
if (entity != player_entity_){
|
|
|
-
|
|
|
// If the entity collides only directly into a triangle border.
|
|
|
if (
|
|
|
first_triangle_check == false
|
|
|
@@ -808,7 +659,6 @@ bool EntityManager::PerformWalkmeshMove(Entity* entity, const float speed){
|
|
|
direction.x = rotation.x;
|
|
|
direction.y = rotation.y;
|
|
|
}
|
|
|
-
|
|
|
// Or if the entity only collides into other entity directly.
|
|
|
else if (
|
|
|
first_entity_check == false && second_entity_check == false
|
|
|
@@ -865,10 +715,7 @@ bool EntityManager::PerformWalkmeshMove(Entity* entity, const float speed){
|
|
|
){
|
|
|
// If not both left and right check failed
|
|
|
if (first_triangle_check == false || second_triangle_check == false){
|
|
|
- if (
|
|
|
- (first_triangle_check == false && first_entity_check != false)
|
|
|
- || (first_triangle_check != false && second_triangle_check == false)
|
|
|
- ){
|
|
|
+ if (first_triangle_check != false && second_triangle_check == false){
|
|
|
q1.FromAngleAxis(
|
|
|
Ogre::Radian(Ogre::Degree(-11.25f)), Ogre::Vector3::UNIT_Z
|
|
|
);
|
|
|
@@ -879,11 +726,7 @@ bool EntityManager::PerformWalkmeshMove(Entity* entity, const float speed){
|
|
|
direction.y = rotation.y;
|
|
|
}
|
|
|
|
|
|
- if (
|
|
|
- first_triangle_check == false
|
|
|
- && first_entity_check == false
|
|
|
- && (second_triangle_check != false || second_entity_check != false)
|
|
|
- ){
|
|
|
+ if (first_triangle_check == false && second_triangle_check != false){
|
|
|
q1.FromAngleAxis(
|
|
|
Ogre::Radian(Ogre::Degree(11.25f)), Ogre::Vector3::UNIT_Z
|
|
|
);
|
|
|
@@ -932,9 +775,7 @@ bool EntityManager::WalkmeshBorderCross(
|
|
|
){
|
|
|
int current_triangle = entity->GetMoveTriangleId();
|
|
|
if (current_triangle == -1) return true;
|
|
|
-
|
|
|
Ogre::Vector2 pos = Ogre::Vector2(position.x, position.y);
|
|
|
-
|
|
|
for (;;){
|
|
|
Ogre::Vector3 A3 = walkmesh_.GetA(current_triangle);
|
|
|
Ogre::Vector3 B3 = walkmesh_.GetB(current_triangle);
|
|
|
@@ -946,19 +787,14 @@ bool EntityManager::WalkmeshBorderCross(
|
|
|
float sign2 = SideOfVector(pos, C, B);
|
|
|
float sign3 = SideOfVector(pos, A, C);
|
|
|
int next_triangle = -1;
|
|
|
-
|
|
|
- if (sign1 < 0)
|
|
|
- next_triangle = walkmesh_.GetAccessSide(current_triangle, 0);
|
|
|
- else if (sign2 < 0)
|
|
|
- next_triangle = walkmesh_.GetAccessSide(current_triangle, 1);
|
|
|
- else if (sign3 < 0)
|
|
|
- next_triangle = walkmesh_.GetAccessSide(current_triangle, 2);
|
|
|
+ if (sign1 < 0) next_triangle = walkmesh_.GetAccessSide(current_triangle, 0);
|
|
|
+ else if (sign2 < 0) next_triangle = walkmesh_.GetAccessSide(current_triangle, 1);
|
|
|
+ else if (sign3 < 0) next_triangle = walkmesh_.GetAccessSide(current_triangle, 2);
|
|
|
else{
|
|
|
position.z = PointElevation(pos, A3, B3, C3);
|
|
|
entity->SetMoveTriangleId(current_triangle);
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
if (next_triangle >= 0){
|
|
|
bool lock = walkmesh_.IsLocked(next_triangle);
|
|
|
if (lock == false){
|
|
|
@@ -966,18 +802,14 @@ bool EntityManager::WalkmeshBorderCross(
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
position.z = PointElevation(pos, A3, B3, C3);
|
|
|
entity->SetMoveTriangleId(current_triangle);
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-bool EntityManager::CheckSolidCollisions(
|
|
|
- Entity* entity, Ogre::Vector3& position
|
|
|
-){
|
|
|
+bool EntityManager::CheckSolidCollisions(Entity* entity, Ogre::Vector3& position){
|
|
|
if (entity->IsSolid() == false) return false;
|
|
|
-
|
|
|
for (size_t i = 0; i < entity_.size(); ++ i){
|
|
|
if (entity_[i]->IsSolid() == false) continue;
|
|
|
if (entity_[i] == entity) continue;
|
|
|
@@ -985,14 +817,12 @@ bool EntityManager::CheckSolidCollisions(
|
|
|
float solid_range = entity_[i]->GetSolidRadius();
|
|
|
solid_range *= solid_range;
|
|
|
float height = (pos1.z < position.z) ? entity_[i]->GetHeight() : entity->GetHeight();
|
|
|
-
|
|
|
if (
|
|
|
((pos1.z - position.z + height) < (height * 2)) && ((pos1.z - position.z + height) >= 0)
|
|
|
){
|
|
|
float distance
|
|
|
= (pos1.x - position.x) * (pos1.x - position.x)
|
|
|
+ (pos1.y - position.y) * (pos1.y - position.y);
|
|
|
-
|
|
|
if (distance < solid_range) return true;
|
|
|
}
|
|
|
}
|
|
|
@@ -1001,7 +831,6 @@ bool EntityManager::CheckSolidCollisions(
|
|
|
|
|
|
void EntityManager::CheckTriggers(Entity* entity, const Ogre::Vector3& position){
|
|
|
if (entity->IsSolid() == false) return;
|
|
|
-
|
|
|
bool is_moving = true;
|
|
|
if (
|
|
|
std::fabs(entity->GetPosition().x - position.x) < 0.01f
|
|
|
@@ -1076,8 +905,8 @@ void EntityManager::CheckTriggers(Entity* entity, const Ogre::Vector3& position)
|
|
|
trigger, "on_cross_line", 1, entity->GetName(), "", true, true
|
|
|
);
|
|
|
// Test on_cross_line_once.
|
|
|
- // Same conditions that on_cross_line, but triggered only once (i.e. if the entity
|
|
|
- // has not been registered as an activator.
|
|
|
+ // Same conditions that on_cross_line, but triggered only once (i.e. if the
|
|
|
+ // entity has not been registered as an activator.
|
|
|
//std::cout << " [TRIGGER] " << entity->GetName()
|
|
|
// << " on_cross_line_once " << entity_triggers_[i]->GetName() << std::endl;
|
|
|
if (entity_triggers_[i]->IsActivator(entity) == false){
|
|
|
@@ -1110,33 +939,26 @@ void EntityManager::CheckTriggers(Entity* entity, const Ogre::Vector3& position)
|
|
|
void EntityManager::CheckEntityInteract(){
|
|
|
if (player_entity_ == NULL || player_lock_ == true || player_entity_->IsSolid() == false)
|
|
|
return;
|
|
|
-
|
|
|
Ogre::Degree angle_pc = player_entity_->GetRotation();
|
|
|
Entity* entity_to_interact = NULL;
|
|
|
Ogre::Degree less_angle(90);
|
|
|
-
|
|
|
for (unsigned int i = 0; i < entity_.size(); ++ i){
|
|
|
if (entity_[i]->IsTalkable() == false) continue;
|
|
|
if (entity_[i] == player_entity_) continue;
|
|
|
-
|
|
|
Ogre::Vector3 pos1 = entity_[i]->GetPosition();
|
|
|
float interact_range = entity_[i]->GetTalkRadius();
|
|
|
Ogre::Vector3 pos2 = player_entity_->GetPosition();
|
|
|
float solid_range = player_entity_->GetSolidRadius();
|
|
|
-
|
|
|
int height = (pos1.z < pos2.z) ? entity_[i]->GetHeight() : player_entity_->GetHeight();
|
|
|
-
|
|
|
if (((pos1.z - pos2.z + height) < (height * 2)) && ((pos1.z - pos2.z + height) >= 0)){
|
|
|
interact_range = (interact_range + solid_range) * (interact_range + solid_range);
|
|
|
float distance
|
|
|
= (pos1.x - pos2.x) * (pos1.x - pos2.x) + (pos1.y - pos2.y) * (pos1.y - pos2.y);
|
|
|
-
|
|
|
if (distance < interact_range + solid_range){
|
|
|
Ogre::Degree angle_to_model = GetDirectionToPoint(pos2, pos1);
|
|
|
Ogre::Degree angle = angle_pc - angle_to_model;
|
|
|
angle = (angle < Ogre::Degree(0)) ? -angle : angle;
|
|
|
angle = (angle >= Ogre::Degree(180)) ? Ogre::Degree(360) - angle : angle;
|
|
|
-
|
|
|
if (angle < less_angle){
|
|
|
angle = less_angle;
|
|
|
entity_to_interact = entity_[i];
|
|
|
@@ -1144,7 +966,6 @@ void EntityManager::CheckEntityInteract(){
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
if (entity_to_interact != NULL && entity_to_interact->IsLine() == false){
|
|
|
Ogre::String name = entity_to_interact->GetName();
|
|
|
ScriptEntity* scr_entity = ScriptManager::getSingleton().GetScriptEntityByName(
|
|
|
@@ -1154,7 +975,7 @@ void EntityManager::CheckEntityInteract(){
|
|
|
scr_entity, "on_interact", 1, "", "", false, false
|
|
|
);
|
|
|
if (added == false){
|
|
|
- LOG_WARNING("Script \"on_interact\" for entity \"" + name + "\" doesn't exist.");
|
|
|
+ LOG_WARNING("Script 'on_interact' for entity '" + name + "' doesn't exist.");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1167,8 +988,8 @@ void EntityManager::SetNextOffsetStep(Entity* entity){
|
|
|
current = (current > total) ? total : current;
|
|
|
Ogre::Vector3 start = entity->GetOffsetPositionStart();
|
|
|
Ogre::Vector3 end = entity->GetOffsetPositionEnd();
|
|
|
+ // TODO: Prevent division by 0:
|
|
|
float x = current / total;
|
|
|
- // Prevent division by 0:
|
|
|
if (std::isnan(x)) x = 0.0f;
|
|
|
float smooth_modifier = (type == AT_SMOOTH) ? -2 * x * x * x + 3 * x * x : x;
|
|
|
Ogre::Vector3 offset = start + (end - start) * smooth_modifier;
|
|
|
@@ -1185,6 +1006,7 @@ void EntityManager::SetNextTurnStep(Entity* entity){
|
|
|
current = (current > total) ? total : current;
|
|
|
Ogre::Degree start = entity->GetTurnDirectionStart();
|
|
|
Ogre::Degree end = entity->GetTurnDirectionEnd();
|
|
|
+ // TODO: Prevent division by 0:
|
|
|
float x = current / total;
|
|
|
float smooth_modifier = (type == AT_SMOOTH) ? -2 * x * x * x + 3 * x * x : x;
|
|
|
Ogre::Degree rotation = start + (end - start) * smooth_modifier;
|
|
|
@@ -1199,7 +1021,6 @@ void EntityManager::SetNextLinearStep(Entity* entity){
|
|
|
Ogre::Vector3 start = entity->GetLinearStart();
|
|
|
Ogre::Vector3 end = entity->GetLinearEnd();
|
|
|
Ogre::Vector3 current = entity->GetPosition();
|
|
|
-
|
|
|
float delta = Timer::getSingleton().GetGameTimeDelta();
|
|
|
if (entity == player_entity_){
|
|
|
LinearMovement move = entity->GetLinearMovement();
|
|
|
@@ -1264,7 +1085,6 @@ void EntityManager::SetNextLinearStep(Entity* entity){
|
|
|
SetEntityOnWalkmesh(entity);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
entity->SetPosition(position);
|
|
|
entity->UpdateAnimation((to_end == true) ? delta : -delta);
|
|
|
}
|