Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////////////////////////////////////////
- // Copyright (C), Marwin Misselhorn, 2009
- // FGPlugin Source File
- //
- // FlowProjectile.cpp
- //
- // Purpose: FG node to check for projectiles in a certain area
- //
- // History:
- // - 10/21/09: File created - Marwin Misselhorn
- /////////////////////////////////////////////////////////////////
- #include "StdAfx.h"
- #include "Nodes/G2FlowBaseNode.h"
- #include "IEntitySystem.h"
- #include <WeaponSystem.h>
- #include <Projectile.h>
- #include "GameCVars.h"
- #include "IItemSystem.h"
- #include "Weapon.h"
- /////////////////////////////////////////////////////////////////
- class CFlowNode_CheckForProjectiles : public CFlowBaseNode, public ILevelSystemListener
- {
- enum EInputPorts
- {
- EIP_Trigger,
- EIP_TargetId,
- EIP_AmmoClass,
- EIP_Range,
- };
- enum EOutputPorts
- {
- EOP_ProjectileId,
- EOP_NothingFound,
- };
- public:
- ////////////////////////////////////////////////////
- CFlowNode_CheckForProjectiles(SActivationInfo *pActInfo)
- {
- }
- ////////////////////////////////////////////////////
- virtual ~CFlowNode_CheckForProjectiles(void)
- {
- }
- ////////////////////////////////////////////////////
- virtual void Serialize(SActivationInfo *pActInfo, TSerialize ser)
- {
- }
- ////////////////////////////////////////////////////
- virtual void GetConfiguration(SFlowNodeConfig& config)
- {
- static const SInputPortConfig inputs[] =
- {
- InputPortConfig_Void("Trigger", _HELP("Triggers the projectile check")),
- InputPortConfig<EntityId>("TargetId", _HELP("The center of the searchbox")),
- InputPortConfig<string> ("Ammo", _HELP("When set, limit projectile check to this ammo"), 0, _UICONFIG("enum_global:ammos")),
- InputPortConfig<float>("Range", _HELP("Range for searchbox")),
- {0}
- };
- static const SOutputPortConfig outputs[] =
- {
- OutputPortConfig<EntityId>("ProjectileId", _HELP("Called when the first projectile is found and returns the Id")),
- OutputPortConfig_Void("NothingFound", _HELP("Called when no projectile was found in the whole area")),
- {0}
- };
- config.pInputPorts = inputs;
- config.pOutputPorts = outputs;
- config.sDescription = _HELP("Checks for projectiles in a certain area");
- config.SetCategory(EFLN_ADVANCED);
- }
- ////////////////////////////////////////////////////
- virtual void ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo)
- {
- switch (event)
- {
- case eFE_Activate:
- {
- if (IsPortActive(pActInfo, EIP_Trigger))
- {
- CGame* pGame = static_cast<CGame*>(g_pGame);
- if (pGame)
- {
- // Get properties
- EntityId TargetId( GetPortEntityId(pActInfo, EIP_TargetId ));
- string AmmoClass( GetPortString(pActInfo, EIP_AmmoClass ));
- float Range( GetPortFloat(pActInfo, EIP_Range ));
- //Check
- IEntitySystem* pEntitySys = gEnv->pEntitySystem;
- Vec3 pos = pEntitySys->GetEntity(TargetId)->GetWorldPos();
- SProjectileQuery pquery;
- pquery.box = AABB(Vec3(pos.x-Range,pos.y-Range,pos.z-Range),Vec3(pos.x+Range,pos.y+Range,pos.z+Range));
- CWeaponSystem *pWeaponSystem = pGame->GetWeaponSystem();
- int count = pWeaponSystem->QueryProjectiles(pquery);
- CProjectile* pClosest;
- for(int i=0;i<pquery.nCount;++i)
- {
- IEntity *pEntity = pquery.pResults[i];
- if (!pEntity)
- continue;
- const static IEntityClass* pAmmoClass = pEntitySys->GetClassRegistry()->FindClass(AmmoClass);
- if(pEntity->GetClass() != pAmmoClass) //Ignore projectile if it's not in the Ammo Class the user specified
- continue;
- CProjectile* p = pGame->GetWeaponSystem()->GetProjectile(pEntity->GetId());
- if(!p)
- continue;
- pClosest = p;
- }
- if(!pClosest || pClosest->GetEntityId() == 0)
- {
- ActivateOutput(pActInfo, EOP_NothingFound, true);
- }
- else
- {
- ActivateOutput(pActInfo, EOP_ProjectileId, pClosest->GetEntityId());
- }
- }
- }
- }
- break;
- }
- }
- ////////////////////////////////////////////////////
- virtual void GetMemoryStatistics(ICrySizer *s)
- {
- s->Add(*this);
- }
- ////////////////////////////////////////////////////
- virtual IFlowNodePtr Clone(SActivationInfo *pActInfo)
- {
- return new CFlowNode_CheckForProjectiles(pActInfo);
- }
- // ILevelSystemListener
- virtual void OnLevelNotFound(const char *levelName) {};
- virtual void OnLoadingStart(ILevelInfo *pLevel) {};
- virtual void OnLoadingComplete(ILevel *pLevel) {};
- virtual void OnLoadingError(ILevelInfo *pLevel, const char *error) {};
- virtual void OnLoadingProgress(ILevelInfo *pLevel, int progressAmount) {};
- //~ILevelSystemListener
- };
- /////////////////////////////////////////////////////////////////
- class CFlowNode_DestroyProjectile : public CFlowBaseNode
- {
- enum EInputPorts
- {
- EIP_Trigger,
- EIP_ProjectileId,
- };
- enum EOutputPorts
- {
- EOP_Succeeded,
- EOP_Failed,
- };
- public:
- ////////////////////////////////////////////////////
- CFlowNode_DestroyProjectile(SActivationInfo *pActInfo)
- {
- }
- ////////////////////////////////////////////////////
- virtual ~CFlowNode_DestroyProjectile(void)
- {
- }
- ////////////////////////////////////////////////////
- virtual void Serialize(SActivationInfo *pActInfo, TSerialize ser)
- {
- }
- ////////////////////////////////////////////////////
- virtual void GetConfiguration(SFlowNodeConfig& config)
- {
- static const SInputPortConfig inputs[] =
- {
- InputPortConfig_Void("Trigger", _HELP("Destroys the projectile")),
- InputPortConfig<EntityId>("ProjectileId", _HELP("Id of the projectile")),
- {0}
- };
- static const SOutputPortConfig outputs[] =
- {
- OutputPortConfig_Void("Succeeded", _HELP("Called when job is done")),
- OutputPortConfig_Void("Failed", _HELP("Called when projectile fails to destroy")),
- {0}
- };
- config.pInputPorts = inputs;
- config.pOutputPorts = outputs;
- config.sDescription = _HELP("Destroys a projectile on call");
- config.SetCategory(EFLN_ADVANCED);
- }
- ////////////////////////////////////////////////////
- virtual void ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo)
- {
- switch (event)
- {
- case eFE_Activate:
- {
- if (IsPortActive(pActInfo, EIP_Trigger))
- {
- CGame* pGame = static_cast<CGame*>(g_pGame);
- if (pGame)
- {
- // Get properties
- EntityId ProjectileId(GetPortEntityId(pActInfo, EIP_ProjectileId));
- CProjectile* p = pGame->GetWeaponSystem()->GetProjectile(ProjectileId);
- if(!p)
- {
- ActivateOutput(pActInfo, EOP_Failed, true);
- }
- else
- {
- // Try to destroy the projectile
- p->Explode(true,true);
- ActivateOutput(pActInfo, EOP_Succeeded, true);
- }
- }
- }
- }
- break;
- }
- }
- ////////////////////////////////////////////////////
- virtual void GetMemoryStatistics(ICrySizer *s)
- {
- s->Add(*this);
- }
- ////////////////////////////////////////////////////
- virtual IFlowNodePtr Clone(SActivationInfo *pActInfo)
- {
- return new CFlowNode_DestroyProjectile(pActInfo);
- }
- };
- ////////////////////////////////////////////////////
- ////////////////////////////////////////////////////
- REGISTER_FLOW_NODE("Projectile:CheckForProjectiles", CFlowNode_CheckForProjectiles);
- REGISTER_FLOW_NODE("Projectile:DestroyProjectile", CFlowNode_DestroyProjectile);
- /////////////////////////////////////////////////////////////////
- // FlowForcePlayerStance.cpp
- //
- // Purpose: Flow node for forcing player into a stance
- //
- // History:
- // - 4/12/11 : File created - Marwin Misselhorn
- /////////////////////////////////////////////////////////////////
- #include "StdAfx.h"
- #include "Nodes/G2FlowBaseNode.h"
- #include "GameCVars.h"
- #include "Player.h"
- #include "PlayerInput.h"
- ////////////////////////////////////////////////////
- ////////////////////////////////////////////////////
- ////////////////////////////////////////////////////
- class CFlowNode_ForcePlayerStance : public CFlowBaseNode
- {
- private:
- SActivationInfo m_actInfo;
- public:
- ////////////////////////////////////////////////////
- CFlowNode_ForcePlayerStance(SActivationInfo *pActInfo)
- {
- }
- ////////////////////////////////////////////////////
- virtual ~CFlowNode_ForcePlayerStance(void)
- {
- }
- ////////////////////////////////////////////////////
- virtual void GetMemoryStatistics(ICrySizer *s)
- {
- s->Add(*this);
- }
- ////////////////////////////////////////////////////
- virtual IFlowNodePtr Clone(SActivationInfo *pActInfo)
- {
- return new CFlowNode_ForcePlayerStance(pActInfo);
- }
- ////////////////////////////////////////////////////
- virtual void Serialize(SActivationInfo *pActInfo, TSerialize ser)
- {
- if (ser.IsReading())
- {
- m_actInfo = *pActInfo;
- }
- }
- enum EInputPorts
- {
- EIP_Trigger = 0,
- EIP_Stance,
- };
- enum EOutputPorts
- {
- EOP_Done = 0,
- };
- ////////////////////////////////////////////////////
- virtual void GetConfiguration(SFlowNodeConfig& config)
- {
- static const SInputPortConfig inputs[] =
- {
- InputPortConfig_Void ("Trigger", _HELP("Trigger")),
- InputPortConfig<int>( "Stance", -1, _HELP("Try to set Stance on Player"), 0, _UICONFIG("enum_int:Stand=0,Crouch=1,Prone=2")),
- {0}
- };
- static const SOutputPortConfig outputs[] =
- {
- OutputPortConfig_Void ("Done", _HELP("Set Stance Done")),
- {0}
- };
- config.pInputPorts = inputs;
- config.pOutputPorts = outputs;
- config.sDescription = _HELP("Tries to force the player into a stance");
- config.SetCategory(EFLN_APPROVED);
- }
- ////////////////////////////////////////////////////
- virtual void ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo)
- {
- switch (event)
- {
- case eFE_Initialize:
- {
- m_actInfo = *pActInfo;
- }
- break;
- case eFE_Activate:
- {
- if (IsPortActive(pActInfo, EIP_Trigger))
- {
- CActor *pPlayerActor = static_cast<CActor *>(gEnv->pGame->GetIGameFramework()->GetClientActor());
- if (pPlayerActor)
- {
- CPlayer* pPlayer = static_cast<CPlayer*> (pPlayerActor);
- if (pPlayer)
- {
- int stance = GetPortInt(pActInfo, EIP_Stance);
- IPlayerInput* pPlayerInput = pPlayer->GetPlayerInput();
- if(pPlayerInput)
- pPlayerInput->Reset();
- pPlayer->SetStance((EStance) stance);
- IPhysicalEntity *pPhysEnt = pPlayer->GetEntity()->GetPhysics();
- int result = 0;
- if (pPhysEnt)
- {
- const SStanceInfo *sInfo = pPlayer->GetStanceInfo((EStance) stance);
- pe_player_dimensions playerDim;
- playerDim.heightEye = 0.0f;
- playerDim.heightCollider = sInfo->heightCollider;
- playerDim.sizeCollider = sInfo->size;
- playerDim.heightPivot = sInfo->heightPivot;
- playerDim.maxUnproj = max(0.0f,sInfo->heightPivot);
- playerDim.bUseCapsule = sInfo->useCapsule;
- result = pPhysEnt->SetParams(&playerDim);
- }
- pPlayer->StanceChanged((EStance) stance);
- // Request new animation stance.
- // AnimatedCharacter has it's own understanding of stance, which might be in conflict.
- // Ideally the stance should be maintained only in one place. Currently the Actor (gameplay) rules.
- if (pPlayer->GetAnimatedCharacter() != NULL)
- pPlayer->GetAnimatedCharacter()->RequestStance(stance, pPlayer->GetStanceInfo((EStance) stance)->name);
- if (pPhysEnt != NULL)
- {
- pe_action_awake aa;
- aa.bAwake = 1;
- pPhysEnt->Action(&aa);
- }
- if(pPlayerInput && stance == STANCE_PRONE)
- {
- pPlayerInput->OnAction("prone",eAAM_OnPress,1.0f);
- }
- if(pPlayerInput && stance == STANCE_CROUCH)
- {
- pPlayerInput->OnAction("crouch",eAAM_OnPress,1.0f);
- }
- ActivateOutput(pActInfo, EOP_Done, true);
- }
- }
- ActivateOutput(pActInfo, EOP_Done, false);
- }
- }
- break;
- }
- }
- };
- ////////////////////////////////////////////////////
- ////////////////////////////////////////////////////
- class CFlowNode_ChangeStanceSpeed : public CFlowBaseNode
- {
- private:
- SActivationInfo m_actInfo;
- public:
- ////////////////////////////////////////////////////
- CFlowNode_ChangeStanceSpeed(SActivationInfo *pActInfo)
- {
- }
- ////////////////////////////////////////////////////
- virtual ~CFlowNode_ChangeStanceSpeed(void)
- {
- }
- ////////////////////////////////////////////////////
- virtual void GetMemoryStatistics(ICrySizer *s)
- {
- s->Add(*this);
- }
- ////////////////////////////////////////////////////
- virtual IFlowNodePtr Clone(SActivationInfo *pActInfo)
- {
- return new CFlowNode_ChangeStanceSpeed(pActInfo);
- }
- ////////////////////////////////////////////////////
- virtual void Serialize(SActivationInfo *pActInfo, TSerialize ser)
- {
- if (ser.IsReading())
- {
- m_actInfo = *pActInfo;
- }
- }
- enum EInputPorts
- {
- EIP_Trigger = 0,
- EIP_Stance,
- EIP_NormalSpeed,
- EIP_MaxSpeed,
- };
- enum EOutputPorts
- {
- EOP_Done = 0,
- };
- ////////////////////////////////////////////////////
- virtual void GetConfiguration(SFlowNodeConfig& config)
- {
- static const SInputPortConfig inputs[] =
- {
- InputPortConfig_Void ("Trigger", _HELP("Trigger")),
- InputPortConfig<int>( "Stance", -1, _HELP("Player stance"), 0, _UICONFIG("enum_int:Stand=0,Crouch=1,Prone=2")),
- InputPortConfig<float>( "NormalSpeed", 0.0f, _HELP("Normal speed for the stance (walk)")),
- InputPortConfig<float>( "MaxSpeed", 0.0f, _HELP("Max speed for the stance (sprint)")),
- {0}
- };
- static const SOutputPortConfig outputs[] =
- {
- OutputPortConfig_Void ("Done", _HELP("Change stance speed Done")),
- {0}
- };
- config.pInputPorts = inputs;
- config.pOutputPorts = outputs;
- config.sDescription = _HELP("Tries to change the speed of a stance for the player");
- config.SetCategory(EFLN_APPROVED);
- }
- ////////////////////////////////////////////////////
- virtual void ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo)
- {
- switch (event)
- {
- case eFE_Initialize:
- {
- m_actInfo = *pActInfo;
- }
- break;
- case eFE_Activate:
- {
- if (IsPortActive(pActInfo, EIP_Trigger))
- {
- CActor *pPlayerActor = static_cast<CActor *>(gEnv->pGame->GetIGameFramework()->GetClientActor());
- if (pPlayerActor)
- {
- CPlayer* pPlayer = static_cast<CPlayer*> (pPlayerActor);
- if (pPlayer)
- {
- int stance = GetPortInt(pActInfo, EIP_Stance);
- float normalSpeed = GetPortFloat(pActInfo, EIP_NormalSpeed);
- float maxSpeed = GetPortFloat(pActInfo, EIP_MaxSpeed);
- const SStanceInfo *sInfo = pPlayer->GetStanceInfo((EStance)stance);
- SStanceInfo standInfo;
- //Copy old values
- standInfo.heightCollider = sInfo->heightCollider;
- standInfo.heightPivot = sInfo->heightPivot;
- standInfo.leanLeftViewOffset = sInfo->leanLeftViewOffset;
- standInfo.leanLeftWeaponOffset = sInfo->leanLeftWeaponOffset;
- standInfo.leanRightViewOffset = sInfo->leanRightViewOffset;
- standInfo.leanRightWeaponOffset = sInfo->leanRightWeaponOffset;
- standInfo.modelOffset = sInfo->modelOffset;
- strcpy(standInfo.name, sInfo->name);
- standInfo.size = sInfo->size;
- standInfo.useCapsule = sInfo->useCapsule;
- standInfo.viewOffset = sInfo->viewOffset;
- standInfo.weaponOffset = sInfo->weaponOffset;
- //Set new values
- standInfo.normalSpeed = normalSpeed;
- standInfo.maxSpeed = maxSpeed;
- pPlayer->SetupStance((EStance)stance, &standInfo);
- ActivateOutput(pActInfo, EOP_Done, true);
- break;
- }
- }
- ActivateOutput(pActInfo, EOP_Done, false);
- }
- }
- break;
- }
- }
- };
- ////////////////////////////////////////////////////
- ////////////////////////////////////////////////////
- REGISTER_FLOW_NODE("Game:ForcePlayerStance", CFlowNode_ForcePlayerStance);
- REGISTER_FLOW_NODE("Game:ChangePlayerStanceSpeed", CFlowNode_ChangeStanceSpeed);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement