Skip to content

Commit

Permalink
New callbacks and more
Browse files Browse the repository at this point in the history
* alife_storage_manager.cpp makes direct engine call to script alife_storage_manager.script to pass the save game filename.
alife_storage_manager.CALifeStorageManager_save
alife_storage_manager.CALifeStorageManager_load
* smooth crouch fix

+ callback.weapon_zoom_in
+ callback.weapon_zoom_out
+ callback.weapon_jammed
+ game_object:get_artefact_health();
+ game_object:get_artefact_radiation();
+ game_object:get_artefact_satiety();
+ game_object:get_artefact_power();
+ game_object:get_artefact_bleeding();
+ game_object:set_artefact_health(float value);
+ game_object:set_artefact_radiation(float value);
+ game_object:set_artefact_satiety(float value);
+ game_object:set_artefact_power(float value);
+ game_object:set_artefact_bleeding(float value);
+ game_object:attach_vehicle(gameobject veh) *actor only*
+ game_object:detach_vehicle() *actor only*
+ game_object:force_set_position(vector3)
  • Loading branch information
revolucas authored and Xottab-DUTY committed Dec 16, 2017
1 parent 8949dd2 commit 0fe21c1
Show file tree
Hide file tree
Showing 13 changed files with 244 additions and 14 deletions.
6 changes: 6 additions & 0 deletions src/xrGame/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ CActor::CActor() : CEntityAlive(), current_ik_cam_shift(0)

m_disabled_hitmarks = false;
m_inventory_disabled = false;

// Alex ADD: for smooth crouch fix
CurrentHeight = 0.f;
}

CActor::~CActor()
Expand Down Expand Up @@ -440,6 +443,9 @@ void CActor::Load(LPCSTR section)
m_sInventoryBoxUseAction = "inventory_box_use";
//---------------------------------------------------------------------
m_sHeadShotParticle = READ_IF_EXISTS(pSettings, r_string, section, "HeadShotParticle", 0);

// Alex ADD: for smooth crouch fix
CurrentHeight = CameraHeight();
}

void CActor::PHHit(SHit& H) { m_pPhysics_support->in_Hit(H, false); }
Expand Down
2 changes: 2 additions & 0 deletions src/xrGame/Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ class CActor : public CEntityAlive,
bool CanJump();
bool CanMove();
float CameraHeight();
// Alex ADD: for smooth crouch fix
float CurrentHeight;
bool CanSprint();
bool CanRun();
void StopAnyMove();
Expand Down
9 changes: 8 additions & 1 deletion src/xrGame/ActorCameras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,14 @@ void CActor::cam_Update(float dt, float fFOV)
else
current_ik_cam_shift = 0;

Fvector point = {0, CameraHeight() + current_ik_cam_shift, 0};
// Alex ADD: smooth crouch fix
float HeightInterpolationSpeed = 4.f;

if (CurrentHeight != CameraHeight())
CurrentHeight = (CurrentHeight * (1.0f - HeightInterpolationSpeed*dt)) + (CameraHeight() * HeightInterpolationSpeed*dt);

Fvector point = { 0, CurrentHeight + current_ik_cam_shift, 0 };

Fvector dangle = {0, 0, 0};
Fmatrix xform;
xform.setXYZ(0, r_torso.yaw, 0);
Expand Down
6 changes: 3 additions & 3 deletions src/xrGame/ActorVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ void CActor::detach_Vehicle()
car->PPhysicsShell()->SplitterHolderActivate();
m_holder->detach_Actor(); //

// Real Wolf: колбек на высадку из машины. 01.08.2014.
this->callback(GameObject::eDetachVehicle)(car->lua_game_object());

character_physics_support()->movement()->SetPosition(m_holder->ExitPosition());
character_physics_support()->movement()->SetVelocity(m_holder->ExitVelocity());

Expand All @@ -106,9 +109,6 @@ void CActor::detach_Vehicle()

//. SetWeaponHideState(whs_CAR, FALSE);
SetWeaponHideState(INV_STATE_CAR, false);

// Real Wolf: колбек на высадку из машины. 01.08.2014.
this->callback(GameObject::eDetachVehicle)(car->lua_game_object());
}

bool CActor::use_Vehicle(CHolderCustom* object)
Expand Down
13 changes: 13 additions & 0 deletions src/xrGame/Artefact.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ class CArtefact : public CHudItemObject, public CPHUpdateObject
virtual void create_physic_shell();

virtual CArtefact* cast_artefact() { return this; }

float GetHealthPower() const { return m_fHealthRestoreSpeed; }
float GetRadiationPower() const { return m_fRadiationRestoreSpeed; }
float GetSatietyPower() const { return m_fSatietyRestoreSpeed; }
float GetPowerPower() const { return m_fPowerRestoreSpeed; }
float GetBleedingPower() const { return m_fBleedingRestoreSpeed; }

void SetHealthPower(const float value) { m_fHealthRestoreSpeed = value; }
void SetRadiationPower(const float value) { m_fRadiationRestoreSpeed = value; }
void SetSatietyPower(const float value) { m_fSatietyRestoreSpeed = value; }
void SetPowerPower(const float value) { m_fPowerRestoreSpeed = value; }
void SetBleedingPower(const float value) { m_fBleedingRestoreSpeed = value; }

protected:
virtual void UpdateCLChild(){};
virtual void CreateArtefactActivation();
Expand Down
18 changes: 18 additions & 0 deletions src/xrGame/WeaponMagazined.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ void CWeaponMagazined::FireStart()
}
else
{ // misfire
//Alundaio
CGameObject *object = smart_cast<CGameObject*>(H_Parent());
if (object)
object->callback(GameObject::eOnWeaponJammed)(object->lua_game_object(), this->lua_game_object());
//-Alundaio

if (smart_cast<CActor*>(this->H_Parent()) && (Level().CurrentViewEntity() == H_Parent()))
CurrentGameUI()->AddCustomStatic("gun_jammed", true);

Expand Down Expand Up @@ -1167,6 +1173,12 @@ void CWeaponMagazined::OnZoomIn()
if (GetState() == eIdle)
PlayAnimIdle();

//Alundaio: callback not sure why vs2013 gives error, it's fine
CGameObject *object = smart_cast<CGameObject*>(H_Parent());
if (object)
object->callback(GameObject::eOnWeaponZoomIn)(object->lua_game_object(),this->lua_game_object());
//-Alundaio

CActor* pActor = smart_cast<CActor*>(H_Parent());
if (pActor)
{
Expand All @@ -1190,6 +1202,12 @@ void CWeaponMagazined::OnZoomOut()
if (GetState() == eIdle)
PlayAnimIdle();

//Alundaio
CGameObject *object = smart_cast<CGameObject*>(H_Parent());
if (object)
object->callback(GameObject::eOnWeaponZoomOut)(object->lua_game_object(), this->lua_game_object());
//-Alundaio

CActor* pActor = smart_cast<CActor*>(H_Parent());

if (pActor)
Expand Down
18 changes: 18 additions & 0 deletions src/xrGame/alife_storage_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include "string_table.h"
#include "xrEngine/IGame_Persistent.h"
#include "autosave_manager.h"
//Alundaio
#include "pch_script.h"
#include "xrScriptEngine/script_engine.hpp"
//-Alundaio

XRCORE_API string_path g_bug_report_file;

Expand Down Expand Up @@ -90,12 +94,26 @@ void CALifeStorageManager::save(LPCSTR save_name_no_check, bool update_name)
Msg("* Game %s is successfully saved to file '%s'", m_save_name, temp);
#endif // DEBUG

//Alundaio: To get the savegame fname to make our own custom save states
luabind::functor<void> funct;
ai().script_engine().functor("alife_storage_manager.CALifeStorageManager_save", funct);
if (funct)
funct(static_cast<pcstr>(m_save_name));
//-Alundaio

if (!update_name)
xr_strcpy(m_save_name, save);
}

void CALifeStorageManager::load(void* buffer, const u32& buffer_size, LPCSTR file_name)
{
//Alundaio: So we can get the fname to make our own custom save states
luabind::functor<void> funct;
ai().script_engine().functor("alife_storage_manager.CALifeStorageManager_load", funct);
if (funct)
funct(file_name);
//-Alundaio

IReader source(buffer, buffer_size);
header().load(source);
time_manager().load(source);
Expand Down
5 changes: 5 additions & 0 deletions src/xrGame/game_object_space.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ enum ECallbackType
eDetachVehicle,
eUseVehicle,

// weapon
eOnWeaponZoomIn,
eOnWeaponZoomOut,
eOnWeaponJammed,

eDummy = u32(-1),
};
};
26 changes: 24 additions & 2 deletions src/xrGame/script_game_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "character_info_defs.h"
#include "xrAICore/Navigation/game_graph_space.h"
#include "game_location_selector.h"
#include "ui/UIWindow.h" //Alundaio

enum EPdaMsg;
enum ESoundTypes;
Expand Down Expand Up @@ -109,6 +110,7 @@ class CScriptGameObject;
class CZoneCampfire;
class CPhysicObject;
class CArtefact;
class CUIWindow; //Alundaio: For ScopeTexture

#ifdef DEBUG
template <typename _object_type>
Expand Down Expand Up @@ -399,8 +401,14 @@ class CScriptGameObject
int Weapon_Scope_Status();
int Weapon_Silencer_Status();

void Weapon_AddonAttach(CScriptGameObject& item); //Alundaio
void Weapon_AddonDetach(pcstr item_section); //Alundaio
//Alundaio
void Weapon_AddonAttach(CScriptGameObject* item);
void Weapon_AddonDetach(pcstr item_section);

void AttachVehicle(CScriptGameObject* veh);
void DetachVehicle();
void ForceSetPosition(Fvector3 pos);
//-Alundaio

LPCSTR ProfileName();
LPCSTR CharacterName();
Expand Down Expand Up @@ -606,6 +614,20 @@ class CScriptGameObject
float GetAnomalyPower();
void SetAnomalyPower(float p);

//Alundaio
float GetArtefactHealthRestoreSpeed();
float GetArtefactRadiationRestoreSpeed();
float GetArtefactSatietyRestoreSpeed();
float GetArtefactPowerRestoreSpeed();
float GetArtefactBleedingRestoreSpeed();

void SetArtefactHealthRestoreSpeed(float value);
void SetArtefactRadiationRestoreSpeed(float value);
void SetArtefactSatietyRestoreSpeed(float value);
void SetArtefactPowerRestoreSpeed(float value);
void SetArtefactBleedingRestoreSpeed(float value);
//-Alundaio

// HELICOPTER
CHelicopter* get_helicopter();
// CAR
Expand Down
118 changes: 118 additions & 0 deletions src/xrGame/script_game_object3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
#include "sound_player.h"
#include "stalker_decision_space.h"
#include "space_restriction_manager.h"
//Alundaio
#include "Artefact.h"
#include "holder_custom.h"
#include "Actor.h"
//-Alundaio

namespace MemorySpace
{
Expand Down Expand Up @@ -924,6 +929,7 @@ float CScriptGameObject::GetAnomalyPower()
THROW(zone);
return zone->GetMaxPower();
}

void CScriptGameObject::SetAnomalyPower(float p)
{
CCustomZone* zone = smart_cast<CCustomZone*>(&object());
Expand Down Expand Up @@ -1214,3 +1220,115 @@ bool CScriptGameObject::is_weapon_going_to_be_strapped(CScriptGameObject const*

return stalker->is_weapon_going_to_be_strapped(&object->object());
}

//Alundaio: Taken from Radium
float CScriptGameObject::GetArtefactHealthRestoreSpeed()
{
CArtefact* artefact = smart_cast<CArtefact*>(&object());
THROW(artefact);

return artefact->GetHealthPower();
}

float CScriptGameObject::GetArtefactRadiationRestoreSpeed()
{
CArtefact* artefact = smart_cast<CArtefact*>(&object());
THROW(artefact);

return artefact->GetRadiationPower();
}

float CScriptGameObject::GetArtefactSatietyRestoreSpeed()
{
CArtefact* artefact = smart_cast<CArtefact*>(&object());
THROW(artefact);

return artefact->GetSatietyPower();
}

float CScriptGameObject::GetArtefactPowerRestoreSpeed()
{
CArtefact* artefact = smart_cast<CArtefact*>(&object());
THROW(artefact);

return artefact->GetPowerPower();
}

float CScriptGameObject::GetArtefactBleedingRestoreSpeed()
{
CArtefact* artefact = smart_cast<CArtefact*>(&object());
THROW(artefact);

return artefact->GetBleedingPower();
}

void CScriptGameObject::SetArtefactHealthRestoreSpeed(float value)
{
CArtefact* artefact = smart_cast<CArtefact*>(&object());
THROW(artefact);

artefact->SetHealthPower(value);
}

void CScriptGameObject::SetArtefactRadiationRestoreSpeed(float value)
{
CArtefact* artefact = smart_cast<CArtefact*>(&object());
THROW(artefact);

artefact->SetRadiationPower(value);
}

void CScriptGameObject::SetArtefactSatietyRestoreSpeed(float value)
{
CArtefact* artefact = smart_cast<CArtefact*>(&object());
THROW(artefact);

artefact->SetSatietyPower(value);
}

void CScriptGameObject::SetArtefactPowerRestoreSpeed(float value)
{
CArtefact* artefact = smart_cast<CArtefact*>(&object());
THROW(artefact);

artefact->SetPowerPower(value);
}

void CScriptGameObject::SetArtefactBleedingRestoreSpeed(float value)
{
CArtefact* artefact = smart_cast<CArtefact*>(&object());
THROW(artefact);

artefact->SetBleedingPower(value);
}

//Alundaio
void CScriptGameObject::AttachVehicle(CScriptGameObject* veh)
{
CActor *actor = smart_cast<CActor*>(&object());
if (actor)
{
CHolderCustom* vehicle = smart_cast<CHolderCustom*>(veh);
if (vehicle)
actor->attach_Vehicle(vehicle);
}
}

void CScriptGameObject::DetachVehicle()
{
CActor *actor = smart_cast<CActor*>(&object());
if (actor)
actor->detach_Vehicle();
}

void CScriptGameObject::ForceSetPosition(Fvector3 pos)
{
CPhysicsShellHolder* P = smart_cast<CPhysicsShellHolder*>(this);
if (!P)
return;

Fmatrix M = P->XFORM();
M.translate(pos);
P->ForceTransform(M);
}
//-Alundaio
7 changes: 4 additions & 3 deletions src/xrGame/script_game_object_inventory_owner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,7 @@ bool CScriptGameObject::is_door_blocked_by_npc() const


//Alundaio: Methods for exporting the ability to detach/attach addons for magazined weapons
void CScriptGameObject::Weapon_AddonAttach(CScriptGameObject& item)
void CScriptGameObject::Weapon_AddonAttach(CScriptGameObject* item)
{
auto weapon = smart_cast<CWeaponMagazined*>(&object());
if (!weapon)
Expand All @@ -1705,8 +1705,9 @@ void CScriptGameObject::Weapon_AddonAttach(CScriptGameObject& item)
return;
}

if (weapon->CanAttach((PIItem)&item))
weapon->Attach((PIItem)&item, true);
auto pItm = smart_cast<PIItem>(item);
if (weapon->CanAttach(pItm))
weapon->Attach(pItm, true);
}

void CScriptGameObject::Weapon_AddonDetach(pcstr item_section)
Expand Down
5 changes: 5 additions & 0 deletions src/xrGame/script_game_object_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ SCRIPT_EXPORT(CScriptGameObject, (), {
value("on_detach_vehicle", int(GameObject::eDetachVehicle)),
value("on_use_vehicle", int(GameObject::eUseVehicle)),

// weapon
value("weapon_jammed", int(GameObject::eOnWeaponJammed)),
value("weapon_zoom_in", int(GameObject::eOnWeaponZoomIn)),
value("weapon_zoom_out", int(GameObject::eOnWeaponZoomOut)),

value("map_location_added", int(GameObject::eMapLocationAdded))],

def("buy_condition", (void (*)(CScriptIniFile*, LPCSTR))(&::buy_condition)),
Expand Down
Loading

0 comments on commit 0fe21c1

Please sign in to comment.