Skip to content

Commit

Permalink
Add more script exports
Browse files Browse the repository at this point in the history
  • Loading branch information
St4lker0k765 committed Dec 1, 2024
1 parent 7b94717 commit 4bf859c
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 21 deletions.
71 changes: 68 additions & 3 deletions src/xrGame/Inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include "Car.h"

using namespace InventoryUtilities;
//Alundaio
#include "../../xrScripts/script_engine.h"
using namespace luabind;
//-Alundaio

// what to block
u16 INV_STATE_LADDER = INV_STATE_BLOCK_ALL;
Expand Down Expand Up @@ -1046,6 +1050,13 @@ bool CInventory::Eat(PIItem pIItem)
Msg( "--- Actor [%d] use or eat [%d][%s]", entity_alive->ID(), pItemToEat->object().ID(), pItemToEat->object().cNameSect().c_str() );
#endif // MP_LOGGING

luabind::functor<bool> funct;
if (ai().script_engine().functor("_G.CInventory__eat", funct))
{
if (!funct(smart_cast<CGameObject*>(pItemToEat->object().H_Parent())->lua_game_object(), (smart_cast<CGameObject*>(pIItem))->lua_game_object()))
return false;
}

if(IsGameTypeSingle() && Actor()->m_inventory == this)
Actor()->callback(GameObject::eUseObject)((smart_cast<CGameObject*>(pIItem))->lua_game_object());

Expand Down Expand Up @@ -1224,17 +1235,39 @@ void CInventory::AddAvailableItems(TIItemContainer& items_container, bool for_t
for(TIItemContainer::const_iterator it = m_ruck.begin(); m_ruck.end() != it; ++it)
{
PIItem pIItem = *it;
if(!for_trade || pIItem->CanTrade())
if (!for_trade || pIItem->CanTrade())
{
if (m_pOwner->is_alive())
{
luabind::functor<bool> funct;
if (ai().script_engine().functor("actor_menu_inventory.CInventory_ItemAvailableToTrade", funct))
{
if (!funct(m_pOwner->cast_game_object()->lua_game_object(), pIItem->cast_game_object()->lua_game_object()))
continue;
}
}
items_container.push_back(pIItem);
}
}

if(m_bBeltUseful)
{
for(TIItemContainer::const_iterator it = m_belt.begin(); m_belt.end() != it; ++it)
{
PIItem pIItem = *it;
if(!for_trade || pIItem->CanTrade())
if (!for_trade || pIItem->CanTrade())
{
if (m_pOwner->is_alive())
{
luabind::functor<bool> funct;
if (ai().script_engine().functor("actor_menu_inventory.CInventory_ItemAvailableToTrade", funct))
{
if (!funct(m_pOwner->cast_game_object()->lua_game_object(), pIItem->cast_game_object()->lua_game_object()))
continue;
}
}
items_container.push_back(pIItem);
}
}
}

Expand All @@ -1245,7 +1278,18 @@ void CInventory::AddAvailableItems(TIItemContainer& items_container, bool for_t
for (; I <= E; ++I) {
PIItem item = ItemFromSlot(I);
if (item && (item->BaseSlot() != BOLT_SLOT))
{
if (pOwner->is_alive())
{
luabind::functor<bool> funct;
if (ai().script_engine().functor("actor_menu_inventory.CInventory_ItemAvailableToTrade", funct))
{
if (!funct(pOwner->cast_game_object()->lua_game_object(), item->cast_game_object()->lua_game_object()))
continue;
}
}
items_container.push_back(item);
}
}
}
else if (m_bSlotsUseful) {
Expand All @@ -1262,9 +1306,30 @@ void CInventory::AddAvailableItems(TIItemContainer& items_container, bool for_t
std::uint32_t slot = item->BaseSlot();

if (slot != INV_SLOT_3 /* && slot != INV_SLOT_2*/)
{
if (pOwner->is_alive())
{
luabind::functor<bool> funct;
if (ai().script_engine().functor("actor_menu_inventory.CInventory_ItemAvailableToTrade", funct))
{
if (!funct(pOwner->cast_game_object()->lua_game_object(), item->cast_game_object()->lua_game_object()))
continue;
}
}
items_container.push_back(item);
}
}
else {
else
{
if (m_pOwner->is_alive())
{
luabind::functor<bool> funct;
if (ai().script_engine().functor("actor_menu_inventory.CInventory_ItemAvailableToTrade", funct))
{
if (!funct(m_pOwner->cast_game_object()->lua_game_object(), item->cast_game_object()->lua_game_object()))
continue;
}
}
items_container.push_back(item);
}
}
Expand Down
38 changes: 25 additions & 13 deletions src/xrGame/ai/stalker/ai_stalker_fire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,23 +395,35 @@ void CAI_Stalker::update_best_item_info ()

void CAI_Stalker::update_best_item_info_impl()
{
luabind::functor<CScriptGameObject*> funct;
if (memory().enemy().selected() && ai().script_engine().functor("ai_stalker.update_best_weapon", funct))
{
CScriptGameObject* GO = funct(this->lua_game_object(), m_best_item_to_kill ? m_best_item_to_kill->cast_game_object()->lua_game_object() : NULL);
if (GO)
{
CInventoryItem* bw = GO->object().cast_inventory_item();
if (bw)
{
m_item_actuality = true;
m_best_item_to_kill = bw;
m_best_ammo = bw;
m_best_item_value = ai().ef_storage().m_pfWeaponEffectiveness->ffGetValue();
}
}
}

ai().ef_storage().alife_evaluation(false);
if (
m_item_actuality &&
m_best_item_to_kill &&
m_best_item_to_kill->can_kill()
) {

if (!memory().enemy().selected())
if (m_item_actuality && m_best_item_to_kill && m_best_item_to_kill->can_kill())
{
if (!memory().enemy().selected())
return;

ai().ef_storage().non_alife().member() = this;
ai().ef_storage().non_alife().enemy() = memory().enemy().selected() ? memory().enemy().selected() : this;
ai().ef_storage().non_alife().member_item() = &m_best_item_to_kill->object();
float value;
value = ai().ef_storage().m_pfWeaponEffectiveness->ffGetValue();
if (fsimilar(value,m_best_item_value))
ai().ef_storage().non_alife().member() = this;
ai().ef_storage().non_alife().enemy() = memory().enemy().selected() ? memory().enemy().selected() : this;
ai().ef_storage().non_alife().member_item() = &m_best_item_to_kill->object();
float value;
value = ai().ef_storage().m_pfWeaponEffectiveness->ffGetValue();
if (fsimilar(value, m_best_item_value))
return;
}

Expand Down
11 changes: 11 additions & 0 deletions src/xrGame/ui/UIInventoryUpgradeWnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
#include "../WeaponRPG7.h"
#include "../CustomOutfit.h"
#include "../ActorHelmet.h"
#include "script_game_object.h" //Alundaio

using namespace luabind; //Alundaio
// -----

const LPCSTR g_inventory_upgrade_xml = "inventory_upgrade.xml";
Expand Down Expand Up @@ -338,6 +340,15 @@ void CUIInventoryUpgradeWnd::OnMesBoxYes()
CUIActorMenu* parent_wnd = smart_cast<CUIActorMenu*>( m_pParentWnd );
if ( parent_wnd )
{
//Alundaio: tell script that item has been upgraded
luabind::functor<void> funct;
ai().script_engine().functor("inventory_upgrades.effect_upgrade_item", funct);
if (funct)
{
CGameObject* GO = m_inv_item->cast_game_object();
funct(GO->lua_game_object(), m_cur_upgrade_id);
}
//-Alundaio
parent_wnd->UpdateActor();
parent_wnd->SeparateUpgradeItem();
}
Expand Down
25 changes: 21 additions & 4 deletions src/xrGame/visual_memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
# include "ai_debug.h"
#endif // MASTER_GOLD

//Alundaio
#include "../../xrScripts/script_engine.h"
#include "script_game_object.h"
using namespace luabind; //Alundaio
//-Alundaio

void SetActorVisibility(u16 who, float value);

struct SRemoveOfflinePredicate {
Expand Down Expand Up @@ -289,7 +295,7 @@ float CVisualMemoryManager::object_visible_distance(const CGameObject *game_obje

float CVisualMemoryManager::object_luminocity (const CGameObject *game_object) const
{
if (!smart_cast<CActor const*>(game_object))
if (!smart_cast<CEntityAlive const*>(game_object)) //Alundaio
return (1.f);
float luminocity = const_cast<CGameObject*>(game_object)->ROS()->get_luminocity();
float power = log(luminocity > .001f ? luminocity : .001f)*current_state().m_luminocity_factor;
Expand All @@ -298,6 +304,11 @@ float CVisualMemoryManager::object_luminocity (const CGameObject *game_object) c

float CVisualMemoryManager::get_object_velocity (const CGameObject *game_object, const CNotYetVisibleObject &not_yet_visible_object) const
{
//Alundaio: no need to check velocity on anything but stalkers, mutants and actor
if (!smart_cast<CEntityAlive const*>(game_object))
return (0.f);
//-Alundaio

if ((game_object->ps_Size() < 2) || (not_yet_visible_object.m_prev_time == game_object->ps_Element(game_object->ps_Size() - 2).dwTime))
return (0.f);

Expand All @@ -313,13 +324,19 @@ float CVisualMemoryManager::get_object_velocity (const CGameObject *game_object,
);
}

float CVisualMemoryManager::get_visible_value (float distance, float object_distance, float time_delta, float object_velocity, float luminocity) const
float CVisualMemoryManager::get_visible_value(const CGameObject *game_object, float distance, float object_distance, float time_delta, float object_velocity, float luminocity) const
{
float always_visible_distance = current_state().m_always_visible_distance;

if (distance <= always_visible_distance + EPS_L)
return (current_state().m_visibility_threshold);

//Alundaio: hijack not_yet_visible_object to lua
luabind::functor<float> funct;
if (ai().script_engine().functor("visual_memory_manager.get_visible_value", funct))
return (funct(m_object ? m_object->lua_game_object() : 0, game_object ? game_object->lua_game_object() : 0, time_delta, current_state().m_time_quant, luminocity, current_state().m_velocity_factor, object_velocity, distance, object_distance, always_visible_distance));
//-Alundaio

return (
time_delta /
current_state().m_time_quant *
Expand Down Expand Up @@ -401,7 +418,7 @@ bool CVisualMemoryManager::visible (const CGameObject *game_object, float tim
CNotYetVisibleObject new_object;
new_object.m_object = game_object;
new_object.m_prev_time = 0;
new_object.m_value = get_visible_value(distance,object_distance,time_delta,get_object_velocity(game_object,new_object),object_luminocity(game_object));
new_object.m_value = get_visible_value(game_object,distance,object_distance,time_delta,get_object_velocity(game_object,new_object),object_luminocity(game_object));
clamp (new_object.m_value,0.f,current_state().m_visibility_threshold + EPS_L);
new_object.m_update_time = Device.dwTimeGlobal;
new_object.m_prev_time = get_prev_time(game_object);
Expand All @@ -410,7 +427,7 @@ bool CVisualMemoryManager::visible (const CGameObject *game_object, float tim
}

object->m_update_time = Device.dwTimeGlobal;
object->m_value += get_visible_value(distance,object_distance,time_delta,get_object_velocity(game_object,*object),object_luminocity(game_object));
object->m_value += get_visible_value(game_object,distance,object_distance,time_delta,get_object_velocity(game_object,*object),object_luminocity(game_object));
clamp (object->m_value,0.f,current_state().m_visibility_threshold + EPS_L);
object->m_prev_time = get_prev_time(game_object);

Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/visual_memory_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class CVisualMemoryManager {
void add_visible_object (const CVisibleObject visible_object);
float object_visible_distance (const CGameObject *game_object, float &object_distance) const;
float object_luminocity (const CGameObject *game_object) const;
float get_visible_value (float distance, float object_distance, float time_delta, float object_velocity, float luminocity) const;
float get_visible_value (const CGameObject *game_object,float distance, float object_distance, float time_delta, float object_velocity, float luminocity) const;
float get_object_velocity (const CGameObject *game_object, const CNotYetVisibleObject &not_yet_visible_object) const;
u32 get_prev_time (const CGameObject *game_object) const;

Expand Down

0 comments on commit 4bf859c

Please sign in to comment.