Skip to content

Commit

Permalink
+ Now pass game object of initiator using a door to ph_door:use_callback
Browse files Browse the repository at this point in the history
  • Loading branch information
revolucas authored and Xottab-DUTY committed Aug 14, 2017
1 parent c826696 commit 37a70ed
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
8 changes: 8 additions & 0 deletions src/xrGame/doors_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "ai/stalker/ai_stalker.h"
#include "stalker_movement_manager_smart_cover.h"
#include "debug_renderer.h"
#include "script_game_object.h" //Alundaio

using doors::actor;
using doors::door;
Expand Down Expand Up @@ -55,6 +56,13 @@ void actor::revert_states(doors_type& doors, door_state const state)
doors.clear_not_free();
}

//Alundaio: add the ability to get lua game object
CScriptGameObject* actor::lua_game_object() const
{
return m_object.lua_game_object();
}
//Alundaio: END

Fvector const& actor::get_position() const { return m_object.Position(); }
bool actor::need_update() const { return !m_open_doors.empty() && !m_closed_doors.empty(); }
class passed_doors_predicate
Expand Down
2 changes: 2 additions & 0 deletions src/xrGame/doors_actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "doors.h"

class CAI_Stalker;
class CScriptGameObject; //Alundaio: Needed for return type

namespace doors
{
Expand All @@ -24,6 +25,7 @@ class actor : private Noncopyable
bool update_doors(doors_type const& doors, float average_speed);
void on_door_destroy(door& door);
pcstr get_name() const;
CScriptGameObject* lua_game_object() const; //Alundaio
#ifdef DEBUG
void render() const;
#endif // #ifdef DEBUG
Expand Down
12 changes: 7 additions & 5 deletions src/xrGame/doors_door.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ void door::unlock()
#endif // #ifdef DEBUG
}

void door::change_state()
//Alundaio: Modified to pass the initiator to ph_door:use_callback
void door::change_state(actor* initiator)
{
VERIFY(valid(m_state));
VERIFY(valid(m_target_state));
Expand All @@ -156,13 +157,14 @@ void door::change_state()
if (m_state == m_target_state)
return;

m_object.callback(GameObject::eUseObject)(m_object.lua_game_object(), (CScriptGameObject*)0);
m_object.callback(GameObject::eUseObject)(m_object.lua_game_object(), (CScriptGameObject*)initiator->lua_game_object());
#ifdef DEBUG
if (g_debug_doors)
Msg("door[%s] started to change its state to [%s]", m_object.cName().c_str(),
m_target_state == door_state_open ? "open" : "closed");
#endif // #ifdef DEBUG
}
//Alundaio: END

void door::change_state(actor* const initiator, door_state const start_state, door_state const stop_state)
{
Expand All @@ -185,7 +187,7 @@ void door::change_state(actor* const initiator, door_state const start_state, do
// if ( !xr_strcmp( "sim_default_duty_28212", initiator->get_name()) ) {
// int i=0; (void)i;
// }
change_state();
change_state(initiator); //Alundaio: Pass the initiator! We need to know who is trying to open door!
return;
}

Expand Down Expand Up @@ -234,7 +236,7 @@ void door::change_state(actor* const initiator, door_state const start_state, do
// if ( !xr_strcmp( "sim_default_duty_28212", initiator->get_name()) ) {
// int i=0; (void)i;
// }
change_state();
change_state(initiator); //Alundaio: Pass the initiator! We need to know who is trying to open door!
}
else
VERIFY(m_previous_state == stop_state);
Expand Down Expand Up @@ -267,7 +269,7 @@ void door::on_change_state(door_state const state)
return;
}

change_state();
change_state(nullptr); //Alundaio: NULL - no need to know who
}

#ifdef DEBUG
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/doors_door.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class door : private Noncopyable

private:
void change_state(actor* initiator, door_state start_state, door_state stop_state);
void change_state();
void change_state(actor* initiator); //Alundaio: Pass the initiator

private:
typedef xr_vector<actor*> actors_type;
Expand Down
16 changes: 10 additions & 6 deletions src/xrGame/level_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,20 +596,24 @@ void g_send(NET_Packet& P, bool bReliable = false, bool bSequential = true, bool
}

//ability to get the target game_object at crosshair
CGameObject* g_get_target_obj()
CScriptGameObject* g_get_target_obj()
{
collide::rq_result& RQ = HUD().GetCurrentRayQuery();
CGameObject* object = smart_cast<CGameObject*>(RQ.O);
if (object)
return object;
if (RQ.O)
{
CGameObject* game_object = static_cast<CGameObject*>(RQ.O);
if (game_object)
return game_object->lua_game_object();
}
return nullptr;
}

float g_get_target_dist()
{
collide::rq_result& RQ = HUD().GetCurrentRayQuery();
CGameObject* object = smart_cast<CGameObject*>(RQ.O);
if (object)
if (RQ.O)
return RQ.range;
return 0.f;
}

//Alundaio: END
Expand Down

0 comments on commit 37a70ed

Please sign in to comment.