From d0323b3a8a8f1858ea34b5947fe9df5d652cdca1 Mon Sep 17 00:00:00 2001 From: revolucas Date: Sat, 13 Jun 2015 01:34:24 -0400 Subject: [PATCH] + Restored method to attach vehicle to actor + added many exported car methods by RayTwitty + Three new actor callbacks! on_attach_vehicle, on_detach_vehicle and on_use_vehicle --- src/xrGame/Actor.cpp | 8 ++- src/xrGame/Actor.h | 2 +- src/xrGame/ActorAnimation.cpp | 20 +++--- src/xrGame/ActorVehicle.cpp | 67 ++++++++++++-------- src/xrGame/Actor_Network.cpp | 2 +- src/xrGame/Car.cpp | 78 +++++++++++++++++++++++- src/xrGame/Car.h | 30 +++++++++ src/xrGame/CarDamageParticles.cpp | 19 ++++++ src/xrGame/CarDamageParticles.h | 6 ++ src/xrGame/CarScript.cpp | 15 +++++ src/xrGame/game_object_space.h | 5 ++ src/xrGame/script_game_object_script.cpp | 5 ++ 12 files changed, 217 insertions(+), 40 deletions(-) diff --git a/src/xrGame/Actor.cpp b/src/xrGame/Actor.cpp index 4246371777b..ad572368084 100644 --- a/src/xrGame/Actor.cpp +++ b/src/xrGame/Actor.cpp @@ -180,7 +180,9 @@ CActor::CActor() : CEntityAlive(), current_ik_cam_shift(0) m_pUsableObject = NULL; m_anims = new SActorMotions(); - //. m_vehicle_anims = new SActorVehicleAnims(); + //Alundaio: Needed for car + m_vehicle_anims = new SActorVehicleAnims(); + //-Alundaio m_entity_condition = NULL; m_iLastHitterID = u16(-1); m_iLastHittingWeaponID = u16(-1); @@ -221,7 +223,9 @@ CActor::~CActor() xr_delete(m_pPhysics_support); xr_delete(m_anims); - //. xr_delete (m_vehicle_anims); + //Alundaio: For car + xr_delete(m_vehicle_anims); + //-Alundaio } void CActor::reinit() diff --git a/src/xrGame/Actor.h b/src/xrGame/Actor.h index e0a334d7da6..7b73c4c29df 100644 --- a/src/xrGame/Actor.h +++ b/src/xrGame/Actor.h @@ -271,7 +271,7 @@ class CActor : public CEntityAlive, public: SActorMotions* m_anims; - //. SActorVehicleAnims* m_vehicle_anims; + SActorVehicleAnims* m_vehicle_anims; CBlend* m_current_legs_blend; CBlend* m_current_torso_blend; diff --git a/src/xrGame/ActorAnimation.cpp b/src/xrGame/ActorAnimation.cpp index 0e7940c341b..4bb8fae2f7f 100644 --- a/src/xrGame/ActorAnimation.cpp +++ b/src/xrGame/ActorAnimation.cpp @@ -272,14 +272,18 @@ void CActor::steer_Vehicle(float angle) { if (!m_holder) return; - /* - CCar* car = smart_cast(m_holder); - u16 anim_type = car->DriverAnimationType(); - SVehicleAnimCollection& anims=m_vehicle_anims->m_vehicles_type_collections[anim_type]; - if(angle==0.f) smart_cast (Visual())->PlayCycle(anims.idles[0]); - else if(angle>0.f) smart_cast (Visual())->PlayCycle(anims.steer_right); - else smart_cast (Visual())->PlayCycle(anims.steer_left); - */ + + //Alundaio: Re-enable Car + CCar* car = smart_cast(m_holder); + u16 anim_type = car->DriverAnimationType(); + SVehicleAnimCollection& anims = m_vehicle_anims->m_vehicles_type_collections[anim_type]; + if (angle == 0.f) + smart_cast(Visual())->PlayCycle(anims.idles[0]); + else if (angle > 0.f) + smart_cast(Visual())->PlayCycle(anims.steer_right); + else + smart_cast(Visual())->PlayCycle(anims.steer_left); + //-Alundaio } void legs_play_callback(CBlend* blend) diff --git a/src/xrGame/ActorVehicle.cpp b/src/xrGame/ActorVehicle.cpp index 3c8d03fbf36..f8322821e23 100644 --- a/src/xrGame/ActorVehicle.cpp +++ b/src/xrGame/ActorVehicle.cpp @@ -20,41 +20,50 @@ #include "CharacterPhysicsSupport.h" #include "inventory.h" +#include "pch_script.h" +#include "game_object_space.h" +#include "script_callback_ex.h" +#include "script_game_object.h" + void CActor::attach_Vehicle(CHolderCustom* vehicle) { - /* - if(!vehicle) return; - if(m_holder) return; + if(!vehicle || m_holder) + return; - PickupModeOff (); - m_holder=vehicle; + //PickupModeOff(); + m_holder=vehicle; - IRenderVisual *pVis = Visual(); - IKinematicsAnimated* V = smart_cast(pVis); R_ASSERT(V); - IKinematics* pK = smart_cast(pVis); + IRenderVisual* pVis = Visual(); + IKinematicsAnimated* V = smart_cast(pVis); + R_ASSERT(V); + IKinematics* pK = smart_cast(pVis); - if(!m_holder->attach_Actor(this)){ - m_holder=NULL; - return; - } - // temp play animation - CCar* car = smart_cast(m_holder); - u16 anim_type = car->DriverAnimationType(); - SVehicleAnimCollection& anims = m_vehicle_anims->m_vehicles_type_collections[anim_type]; - V->PlayCycle (anims.idles[0],FALSE); + if (!m_holder->attach_Actor(this)) + { + m_holder = nullptr; + return; + } + + // temp play animation + CCar* car = smart_cast(m_holder); + u16 anim_type = car->DriverAnimationType(); + SVehicleAnimCollection& anims = m_vehicle_anims->m_vehicles_type_collections[anim_type]; + V->PlayCycle(anims.idles[0], false); + + ResetCallbacks(); + u16 head_bone = pK->LL_BoneID("bip01_head"); + pK->LL_GetBoneInstance(u16(head_bone)).set_callback(bctPhysics, VehicleHeadCallback, this); - ResetCallbacks (); - u16 head_bone = pK->LL_BoneID("bip01_head"); - pK->LL_GetBoneInstance (u16(head_bone)).set_callback (bctPhysics, VehicleHeadCallback,this); + character_physics_support()->movement()->DestroyCharacter(); + mstate_wishful = 0; + m_holderID = car->ID(); - character_physics_support ()->movement()->DestroyCharacter(); - mstate_wishful = 0; - m_holderID=car->ID (); + SetWeaponHideState(INV_STATE_CAR, true); - SetWeaponHideState (INV_STATE_CAR, true); + CStepManager::on_animation_start(MotionID(), nullptr); - CStepManager::on_animation_start(MotionID(), 0); - */ + // Real Wolf: Колбек на посадку в машину. 01.08.2014. + this->callback(GameObject::eAttachVehicle)(car->lua_game_object()); } void CActor::detach_Vehicle() @@ -97,6 +106,9 @@ 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) @@ -131,6 +143,9 @@ bool CActor::use_Vehicle(CHolderCustom* object) attach_Vehicle(vehicle); } + // Real Wolf: колбек на использование машины (но не посадку) без учета расстояния. 01.08.2014. + else if (auto car = smart_cast(vehicle)) + this->callback(GameObject::eUseVehicle)(car->lua_game_object()); return true; } return false; diff --git a/src/xrGame/Actor_Network.cpp b/src/xrGame/Actor_Network.cpp index ce364513209..e03eed8cb35 100644 --- a/src/xrGame/Actor_Network.cpp +++ b/src/xrGame/Actor_Network.cpp @@ -865,7 +865,7 @@ void CActor::OnChangeVisual() CStepManager::reload(cNameSect().c_str()); SetCallbacks(); m_anims->Create(V); - //. m_vehicle_anims->Create (V); + m_vehicle_anims->Create(V); CDamageManager::reload(*cNameSect(), "damage", pSettings); //------------------------------------------------------------------------------- m_head = smart_cast(Visual())->LL_BoneID("bip01_head"); diff --git a/src/xrGame/Car.cpp b/src/xrGame/Car.cpp index 10d8048d1b5..252d7b58aa4 100644 --- a/src/xrGame/Car.cpp +++ b/src/xrGame/Car.cpp @@ -834,7 +834,8 @@ void CCar::CreateSkeleton(CSE_Abstract* po) pK->CalculateBones(TRUE); } phys_shell_verify_object_model(*this); -#pragma todo(" replace below by P_build_Shell or call inherited") + /* Alundaio: p_build_shell + #pragma todo(" replace below by P_build_Shell or call inherited") m_pPhysicsShell = P_create_Shell(); m_pPhysicsShell->build_FromKinematics(pK, &bone_map); m_pPhysicsShell->set_PhysicsRefObject(this); @@ -842,6 +843,9 @@ void CCar::CreateSkeleton(CSE_Abstract* po) m_pPhysicsShell->Activate(true); m_pPhysicsShell->SetAirResistance(0.f, 0.f); m_pPhysicsShell->SetPrefereExactIntegration(); + */ + m_pPhysicsShell = P_build_Shell(this, true, &bone_map); + //-Alundaio ApplySpawnIniToPhysicShell(&po->spawn_ini(), m_pPhysicsShell, false); ApplySpawnIniToPhysicShell(pK->LL_UserData(), m_pPhysicsShell, false); @@ -1975,4 +1979,74 @@ Fvector CCar::ExitVelocity() return v; } -//#endif // #if 0 +/***** added by Ray Twitty (aka Shadows) START *****/ +// получить и задать текущее количество топлива +float CCar::GetfFuel() +{ + return m_fuel; +} + +void CCar::SetfFuel(float fuel) +{ + m_fuel = fuel; +} + +// получить и задать размер топливного бака +float CCar::GetfFuelTank() +{ + return m_fuel_tank; +} + +void CCar::SetfFuelTank(float fuel_tank) +{ + m_fuel_tank = fuel_tank; +} + +// получить и задать величину потребление топлива +float CCar::GetfFuelConsumption() +{ + return m_fuel_consumption; +} + +void CCar::SetfFuelConsumption(float fuel_consumption) +{ + m_fuel_consumption = fuel_consumption; +} + +// прибавить или убавить количество топлива +void CCar::ChangefFuel(float fuel) +{ + if(m_fuel + fuel < 0) + { + m_fuel = 0; + return; + } + + if(fuel < m_fuel_tank - m_fuel) + m_fuel += fuel; + else + m_fuel = m_fuel_tank; +} + +// прибавить или убавить жизней :) +void CCar::ChangefHealth(float health) +{ + float current_health = GetfHealth(); + if(current_health + health < 0) + { + SetfHealth(0); + return; + } + + if(health < 1 - current_health) + SetfHealth(current_health + health); + else + SetfHealth(1); +} + +// активен ли сейчас двигатель +bool CCar::isActiveEngine() +{ + return b_engine_on; +} +/***** added by Ray Twitty (aka Shadows) END *****/ \ No newline at end of file diff --git a/src/xrGame/Car.h b/src/xrGame/Car.h index 65d0251a158..9e0abe014c0 100644 --- a/src/xrGame/Car.h +++ b/src/xrGame/Car.h @@ -434,6 +434,8 @@ class CCar : public CEntity, CCarLights m_lights; //////////////////////////////////////////////////// ///////////////////////////////////////////////// + + public: void InitParabola(); float _stdcall Parabola(float rpm); // float GetSteerAngle(); @@ -503,6 +505,34 @@ class CCar : public CEntity, float AddFuel(float ammount); // ammount - fuel to load, ret - fuel loaded public: void CarExplode(); + /***** added by Ray Twitty (aka Shadows) START *****/ + float GetfFuel(); + void SetfFuel(float fuel); + + float GetfFuelTank(); + void SetfFuelTank(float fuel_tank); + + float GetfFuelConsumption(); + void SetfFuelConsumption (float fuel_consumption); + + void ChangefFuel (float fuel); + void ChangefHealth(float health); + + void PlayDamageParticles() + { + m_damage_particles.Play1(this); + m_damage_particles.Play2(this); + } + + void StopDamageParticles () + { + m_damage_particles.Stop1(this); + m_damage_particles.Stop2(this); + } + + bool isActiveEngine (); + /***** added by Ray Twitty (aka Shadows) END *****/ + private: void OnCameraChange(int type); diff --git a/src/xrGame/CarDamageParticles.cpp b/src/xrGame/CarDamageParticles.cpp index ae8b29ace29..cc024261928 100644 --- a/src/xrGame/CarDamageParticles.cpp +++ b/src/xrGame/CarDamageParticles.cpp @@ -64,6 +64,25 @@ void CCarDamageParticles::Play2(CCar* car) } } +/***** added by Ray Twitty (aka Shadows) START *****/ +// функции для выключения партиклов дыма +void CCarDamageParticles::Stop1(CCar* car) +{ + if(*m_car_damage_particles1) + for (auto bone : bones1) + car->StopParticles(car->ID(), bone, false); +} + +void CCarDamageParticles::Stop2(CCar* car) +{ + VERIFY(!physics_world()->Processing()); + if(*m_car_damage_particles2) + for (auto bone : bones2) + car->StopParticles(car->ID(), bone, false); +} +/***** added by Ray Twitty (aka Shadows) END *****/ + + void CCarDamageParticles::PlayWheel1(CCar* car, u16 bone_id) const { VERIFY(!physics_world()->Processing()); diff --git a/src/xrGame/CarDamageParticles.h b/src/xrGame/CarDamageParticles.h index 5b6f464b159..3727dcd159a 100644 --- a/src/xrGame/CarDamageParticles.h +++ b/src/xrGame/CarDamageParticles.h @@ -17,6 +17,12 @@ struct CCarDamageParticles void Clear(); void Play1(CCar* car); void Play2(CCar* car); + /***** added by Ray Twitty (aka Shadows) START *****/ + // функции для выключения партиклов дыма + void Stop1(CCar* car); + void Stop2(CCar* car); + /***** added by Ray Twitty (aka Shadows) END *****/ + void PlayWheel1(CCar* car, u16 bone_id) const; void PlayWheel2(CCar* car, u16 bone_id) const; }; diff --git a/src/xrGame/CarScript.cpp b/src/xrGame/CarScript.cpp index c35243c6f09..218e53f8d14 100644 --- a/src/xrGame/CarScript.cpp +++ b/src/xrGame/CarScript.cpp @@ -28,5 +28,20 @@ SCRIPT_EXPORT(CCar, (CGameObject, CHolderCustom), { .def("SetExplodeTime", &CCar::SetExplodeTime) .def("ExplodeTime", &CCar::ExplodeTime) .def("CarExplode", &CCar::CarExplode) + /***** added by Ray Twitty (aka Shadows) START *****/ + .def("GetfFuel", &CCar::GetfFuel) + .def("SetfFuel", &CCar::SetfFuel) + .def("GetfFuelTank", &CCar::GetfFuelTank) + .def("SetfFuelTank", &CCar::SetfFuelTank) + .def("GetfFuelConsumption", &CCar::GetfFuelConsumption) + .def("SetfFuelConsumption", &CCar::SetfFuelConsumption) + .def("ChangefFuel", &CCar::ChangefFuel) + .def("ChangefHealth", &CCar::ChangefHealth) + .def("PlayDamageParticles", &CCar::PlayDamageParticles) + .def("StopDamageParticles", &CCar::StopDamageParticles) + .def("StartEngine", &CCar::StartEngine) + .def("StopEngine", &CCar::StopEngine) + .def("IsActiveEngine", &CCar::isActiveEngine) + /***** added by Ray Twitty (aka Shadows) END *****/ .def(constructor<>())]; }); diff --git a/src/xrGame/game_object_space.h b/src/xrGame/game_object_space.h index 549a458573b..49e866ef67a 100644 --- a/src/xrGame/game_object_space.h +++ b/src/xrGame/game_object_space.h @@ -69,6 +69,11 @@ enum ECallbackType eActorBeforeDeath, //-AVO + // vehicle + eAttachVehicle, + eDetachVehicle, + eUseVehicle, + eDummy = u32(-1), }; }; diff --git a/src/xrGame/script_game_object_script.cpp b/src/xrGame/script_game_object_script.cpp index e14b0e8cbd5..917c6fabf52 100644 --- a/src/xrGame/script_game_object_script.cpp +++ b/src/xrGame/script_game_object_script.cpp @@ -98,6 +98,11 @@ SCRIPT_EXPORT(CScriptGameObject, (), { value("actor_before_death", int(GameObject::eActorBeforeDeath)), //-AVO + // vehicle + value("on_attach_vehicle", int(GameObject::eAttachVehicle)), + value("on_detach_vehicle", int(GameObject::eDetachVehicle)), + value("on_use_vehicle", int(GameObject::eUseVehicle)), + value("map_location_added", int(GameObject::eMapLocationAdded))], def("buy_condition", (void (*)(CScriptIniFile*, LPCSTR))(&::buy_condition)),