Skip to content

Commit 37a70ed

Browse files
revolucasXottab-DUTY
authored andcommitted
+ Now pass game object of initiator using a door to ph_door:use_callback
1 parent c826696 commit 37a70ed

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

src/xrGame/doors_actor.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "ai/stalker/ai_stalker.h"
1111
#include "stalker_movement_manager_smart_cover.h"
1212
#include "debug_renderer.h"
13+
#include "script_game_object.h" //Alundaio
1314

1415
using doors::actor;
1516
using doors::door;
@@ -55,6 +56,13 @@ void actor::revert_states(doors_type& doors, door_state const state)
5556
doors.clear_not_free();
5657
}
5758

59+
//Alundaio: add the ability to get lua game object
60+
CScriptGameObject* actor::lua_game_object() const
61+
{
62+
return m_object.lua_game_object();
63+
}
64+
//Alundaio: END
65+
5866
Fvector const& actor::get_position() const { return m_object.Position(); }
5967
bool actor::need_update() const { return !m_open_doors.empty() && !m_closed_doors.empty(); }
6068
class passed_doors_predicate

src/xrGame/doors_actor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "doors.h"
1212

1313
class CAI_Stalker;
14+
class CScriptGameObject; //Alundaio: Needed for return type
1415

1516
namespace doors
1617
{
@@ -24,6 +25,7 @@ class actor : private Noncopyable
2425
bool update_doors(doors_type const& doors, float average_speed);
2526
void on_door_destroy(door& door);
2627
pcstr get_name() const;
28+
CScriptGameObject* lua_game_object() const; //Alundaio
2729
#ifdef DEBUG
2830
void render() const;
2931
#endif // #ifdef DEBUG

src/xrGame/doors_door.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ void door::unlock()
147147
#endif // #ifdef DEBUG
148148
}
149149

150-
void door::change_state()
150+
//Alundaio: Modified to pass the initiator to ph_door:use_callback
151+
void door::change_state(actor* initiator)
151152
{
152153
VERIFY(valid(m_state));
153154
VERIFY(valid(m_target_state));
@@ -156,13 +157,14 @@ void door::change_state()
156157
if (m_state == m_target_state)
157158
return;
158159

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

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

@@ -234,7 +236,7 @@ void door::change_state(actor* const initiator, door_state const start_state, do
234236
// if ( !xr_strcmp( "sim_default_duty_28212", initiator->get_name()) ) {
235237
// int i=0; (void)i;
236238
// }
237-
change_state();
239+
change_state(initiator); //Alundaio: Pass the initiator! We need to know who is trying to open door!
238240
}
239241
else
240242
VERIFY(m_previous_state == stop_state);
@@ -267,7 +269,7 @@ void door::on_change_state(door_state const state)
267269
return;
268270
}
269271

270-
change_state();
272+
change_state(nullptr); //Alundaio: NULL - no need to know who
271273
}
272274

273275
#ifdef DEBUG

src/xrGame/doors_door.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class door : private Noncopyable
4040

4141
private:
4242
void change_state(actor* initiator, door_state start_state, door_state stop_state);
43-
void change_state();
43+
void change_state(actor* initiator); //Alundaio: Pass the initiator
4444

4545
private:
4646
typedef xr_vector<actor*> actors_type;

src/xrGame/level_script.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -596,20 +596,24 @@ void g_send(NET_Packet& P, bool bReliable = false, bool bSequential = true, bool
596596
}
597597

598598
//ability to get the target game_object at crosshair
599-
CGameObject* g_get_target_obj()
599+
CScriptGameObject* g_get_target_obj()
600600
{
601601
collide::rq_result& RQ = HUD().GetCurrentRayQuery();
602-
CGameObject* object = smart_cast<CGameObject*>(RQ.O);
603-
if (object)
604-
return object;
602+
if (RQ.O)
603+
{
604+
CGameObject* game_object = static_cast<CGameObject*>(RQ.O);
605+
if (game_object)
606+
return game_object->lua_game_object();
607+
}
608+
return nullptr;
605609
}
606610

607611
float g_get_target_dist()
608612
{
609613
collide::rq_result& RQ = HUD().GetCurrentRayQuery();
610-
CGameObject* object = smart_cast<CGameObject*>(RQ.O);
611-
if (object)
614+
if (RQ.O)
612615
return RQ.range;
616+
return 0.f;
613617
}
614618

615619
//Alundaio: END

0 commit comments

Comments
 (0)