Skip to content

Commit 9ba3286

Browse files
author
nitrocaster
committed
Merge CUsableScriptObject into CGameObject.
1 parent f978f14 commit 9ba3286

File tree

11 files changed

+55
-126
lines changed

11 files changed

+55
-126
lines changed

src/xrGame/Actor.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#include "game_cl_single.h"
4646
#include "xrmessages.h"
4747
#include "string_table.h"
48-
#include "usablescriptobject.h"
4948
#include "xrCDB/Intersect.hpp"
5049

5150
#include "alife_registry_wrappers.h"
@@ -1299,7 +1298,7 @@ void CActor::shedule_Update (u32 DT)
12991298
m_pObjectWeLookingAt = smart_cast<CGameObject*>(RQ.O);
13001299

13011300
CGameObject *game_object = smart_cast<CGameObject*>(RQ.O);
1302-
m_pUsableObject = smart_cast<CUsableScriptObject*>(game_object);
1301+
m_pUsableObject = game_object;
13031302
m_pInvBoxWeLookingAt = smart_cast<CInventoryBox*>(game_object);
13041303
m_pPersonWeLookingAt = smart_cast<CInventoryOwner*>(game_object);
13051304
m_pVehicleWeLookingAt = smart_cast<CHolderCustom*>(game_object);

src/xrGame/Actor.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ class ENGINE_API CBlend;
3535
class CWeaponList;
3636
class CEffectorBobbing;
3737
class CHolderCustom;
38-
class CUsableScriptObject;
39-
4038
struct SShootingEffector;
4139
struct SSleepEffector;
4240
class CSleepEffectorPP;
@@ -344,7 +342,7 @@ struct SDefNewsMsg{
344342
CInventoryOwner* PersonWeLookingAt () {return m_pPersonWeLookingAt;}
345343
LPCSTR GetDefaultActionForObject () {return *m_sDefaultObjAction;}
346344
protected:
347-
CUsableScriptObject* m_pUsableObject;
345+
CGameObject* m_pUsableObject;
348346
// Person we're looking at
349347
CInventoryOwner* m_pPersonWeLookingAt;
350348
CHolderCustom* m_pVehicleWeLookingAt;

src/xrGame/ActorInput.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "Level.h"
1818
#include "game_cl_base.h"
1919
#include "xr_level_controller.h"
20-
#include "UsableScriptObject.h"
2120
#include "actorcondition.h"
2221
#include "actor_input_handler.h"
2322
#include "string_table.h"

src/xrGame/Actor_Feel.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "inventory.h"
66
#include "character_info.h"
77
#include "xr_level_controller.h"
8-
#include "UsableScriptObject.h"
98
#include "customzone.h"
109
#include "xrEngine/GameMtlLib.h"
1110
#include "ui/UIMainIngameWnd.h"
@@ -219,7 +218,7 @@ void CActor::PickupModeUpdate_COD ()
219218

220219
if (pNearestItem && m_bPickupMode)
221220
{
222-
CUsableScriptObject* pUsableObject = smart_cast<CUsableScriptObject*>(pNearestItem);
221+
CGameObject* pUsableObject = smart_cast<CGameObject*>(pNearestItem);
223222
if(pUsableObject && (!m_pUsableObject))
224223
pUsableObject->use(this);
225224

src/xrGame/GameObject.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
#include "magic_box3.h"
3333
#include "animation_movement_controller.h"
3434
#include "xrEngine/xr_collide_form.h"
35+
#include "script_game_object.h"
36+
#include "script_callback_ex.h"
37+
#include "game_object_space.h"
38+
#include "doors_door.h"
39+
#include "doors.h"
40+
3541
extern MagicBox3 MagicMinBox (int iQuantity, const Fvector* akPoint);
3642

3743
#pragma warning(push)
@@ -48,6 +54,10 @@ ENGINE_API bool g_dedicated_server;
4854

4955
CGameObject::CGameObject ()
5056
{
57+
// CUsableScriptObject init
58+
m_bNonscriptUsable = true;
59+
set_tip_text_default();
60+
// ~
5161
m_ai_obstacle = 0;
5262

5363
init ();
@@ -1145,3 +1155,28 @@ void CGameObject::OnRender ()
11451155
}
11461156
}
11471157
#endif // DEBUG
1158+
1159+
using namespace luabind; // XXX: is it required here?
1160+
1161+
bool CGameObject::use(CGameObject* who_use)
1162+
{
1163+
VERIFY(who_use);
1164+
CScriptGameObject *obj = lua_game_object();
1165+
if (obj && obj->m_door)
1166+
{
1167+
if (obj->m_door->is_blocked(doors::door_state_open) || obj->m_door->is_blocked(doors::door_state_closed))
1168+
return false;
1169+
}
1170+
callback(GameObject::eUseObject)(obj, who_use->lua_game_object());
1171+
return true;
1172+
}
1173+
1174+
LPCSTR CGameObject::tip_text() { return *m_sTipText; }
1175+
1176+
void CGameObject::set_tip_text(LPCSTR new_text) { m_sTipText = new_text; }
1177+
1178+
void CGameObject::set_tip_text_default() { m_sTipText = NULL; }
1179+
1180+
bool CGameObject::nonscript_usable() { return m_bNonscriptUsable; }
1181+
1182+
void CGameObject::set_nonscript_usable(bool usable) { m_bNonscriptUsable = usable; }

src/xrGame/GameObject.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "xrEngine/xr_object.h"
1010
#include "xrServer_Space.h"
1111
#include "alife_space.h"
12-
#include "UsableScriptObject.h"
12+
#include "xrScriptEngine/script_space_forward.hpp"
1313
#include "script_binder.h"
1414
#include "Hit.h"
1515
#include "game_object_space.h"
@@ -49,11 +49,13 @@ template <typename _return_type>
4949
class CScriptCallbackEx;
5050

5151
class CGameObject :
52-
public CObject,
53-
public CUsableScriptObject,
52+
public CObject,
5453
public CScriptBinder
5554
{
55+
private:
5656
typedef CObject inherited;
57+
shared_str m_sTipText;
58+
bool m_bNonscriptUsable;
5759
bool m_spawned;
5860
Flags32 m_server_flags;
5961
CAI_ObjectLocation *m_ai_location;
@@ -91,7 +93,6 @@ class CGameObject :
9193

9294
public:
9395
virtual bool feel_touch_on_contact (CObject *) {return TRUE;}
94-
virtual bool use (CGameObject* who_use) {return CUsableScriptObject::use(who_use);};
9596

9697
public:
9798
CInifile *m_ini_file;
@@ -308,6 +309,15 @@ const animation_movement_controller* animation_movement ( ) const { return m_an
308309
}
309310

310311
virtual void on_matrix_change (const Fmatrix &previous);
312+
// UsableScriptObject functions
313+
virtual bool use(CGameObject* who_use);
314+
//ñòðî÷êà ïîÿâëÿþùàÿñÿ ïðè íàâåäåíèè íà îáúåêò (åñëè NULL, òî íåò)
315+
virtual LPCSTR tip_text();
316+
void set_tip_text(LPCSTR new_text);
317+
virtual void set_tip_text_default();
318+
//ìîæíî ëè èñïîëüçîâàòü îáúåêò ñòàíäàðòíûì (íå ñêðèïòîâûì) îáðàçîì
319+
bool nonscript_usable();
320+
void set_nonscript_usable(bool usable);
311321
};
312322

313323
#endif // !defined(AFX_GAMEOBJECT_H__3DA72D03_C759_4688_AEBB_89FA812AA873__INCLUDED_)

src/xrGame/UsableScriptObject.cpp

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/xrGame/UsableScriptObject.h

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/xrGame/script_game_object_use.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "pch_script.h"
22
#include "script_game_object.h"
33
#include "script_game_object_impl.h"
4-
#include "UsableScriptObject.h"
54
#include "GameObject.h"
65
#include "xrScriptEngine/script_engine.hpp"
76
#include "stalker_planner.h"
@@ -20,29 +19,13 @@
2019
#include "doors_manager.h"
2120

2221
void CScriptGameObject::SetTipText (LPCSTR tip_text)
23-
{
24-
CUsableScriptObject *l_tpUseableScriptObject = smart_cast<CUsableScriptObject*>(&object());
25-
if (!l_tpUseableScriptObject)
26-
ai().script_engine().script_log (LuaMessageType::Error,"SetTipText. Reason: the object is not usable");
27-
else l_tpUseableScriptObject->set_tip_text(tip_text);
28-
}
22+
{ object().set_tip_text(tip_text); }
2923

3024
void CScriptGameObject::SetTipTextDefault ()
31-
{
32-
CUsableScriptObject *l_tpUseableScriptObject = smart_cast<CUsableScriptObject*>(&object());
33-
if (!l_tpUseableScriptObject)
34-
ai().script_engine().script_log (LuaMessageType::Error,"SetTipTextDefault . Reason: the object is not usable");
35-
else l_tpUseableScriptObject->set_tip_text_default();
36-
}
25+
{ object().set_tip_text_default(); }
3726

3827
void CScriptGameObject::SetNonscriptUsable(bool nonscript_usable)
39-
{
40-
CUsableScriptObject *l_tpUseableScriptObject = smart_cast<CUsableScriptObject*>(&object());
41-
if (!l_tpUseableScriptObject)
42-
ai().script_engine().script_log (LuaMessageType::Error,"SetNonscriptUsable . Reason: the object is not usable");
43-
else l_tpUseableScriptObject->set_nonscript_usable(nonscript_usable);
44-
}
45-
28+
{ object().set_nonscript_usable(nonscript_usable); }
4629

4730
Fvector CScriptGameObject::GetCurrentDirection()
4831
{

src/xrGame/xrGame.vcxproj

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,6 @@
17451745
<ClInclude Include="ui\xrUIXmlParser.h" />
17461746
<ClInclude Include="ui_base.h" />
17471747
<ClInclude Include="ui_defs.h" />
1748-
<ClInclude Include="UsableScriptObject.h" />
17491748
<ClInclude Include="vertex_allocator_fixed.h" />
17501749
<ClInclude Include="vertex_allocator_fixed_inline.h" />
17511750
<ClInclude Include="vertex_manager_fixed.h" />
@@ -3846,10 +3845,6 @@
38463845
<PrecompiledHeaderFile>pch_script.h</PrecompiledHeaderFile>
38473846
<PrecompiledHeaderOutputFile>$(IntDir)$(ProjectName)_script.pch</PrecompiledHeaderOutputFile>
38483847
</ClCompile>
3849-
<ClCompile Include="UsableScriptObject.cpp">
3850-
<PrecompiledHeaderFile>pch_script.h</PrecompiledHeaderFile>
3851-
<PrecompiledHeaderOutputFile>$(IntDir)$(ProjectName)_script.pch</PrecompiledHeaderOutputFile>
3852-
</ClCompile>
38533848
<ClCompile Include="vision_client.cpp" />
38543849
<ClCompile Include="visual_memory_manager.cpp">
38553850
<PrecompiledHeaderFile>pch_script.h</PrecompiledHeaderFile>

0 commit comments

Comments
 (0)