Advertisement
dragonbane

[Wreckage] Force Player Stance And Projectile FG Plugins

Feb 23rd, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 15.97 KB | None | 0 0
  1. /////////////////////////////////////////////////////////////////
  2. // Copyright (C), Marwin Misselhorn, 2009
  3. // FGPlugin Source File
  4. //
  5. // FlowProjectile.cpp
  6. //
  7. // Purpose: FG node to check for projectiles in a certain area
  8. //
  9. // History:
  10. //  - 10/21/09: File created - Marwin Misselhorn
  11. /////////////////////////////////////////////////////////////////
  12.  
  13. #include "StdAfx.h"
  14.  
  15. #include "Nodes/G2FlowBaseNode.h"
  16. #include "IEntitySystem.h"
  17. #include <WeaponSystem.h>
  18. #include <Projectile.h>
  19. #include "GameCVars.h"
  20. #include "IItemSystem.h"
  21. #include "Weapon.h"
  22.  
  23.  
  24. /////////////////////////////////////////////////////////////////
  25. class CFlowNode_CheckForProjectiles : public CFlowBaseNode, public ILevelSystemListener
  26. {
  27.     enum EInputPorts
  28.     {
  29.         EIP_Trigger,
  30.         EIP_TargetId,
  31.         EIP_AmmoClass,
  32.         EIP_Range,
  33.     };
  34.  
  35.     enum EOutputPorts
  36.     {
  37.         EOP_ProjectileId,
  38.         EOP_NothingFound,
  39.     };
  40.  
  41. public:
  42.     ////////////////////////////////////////////////////
  43.     CFlowNode_CheckForProjectiles(SActivationInfo *pActInfo)
  44.     {
  45.        
  46.     }
  47.  
  48.     ////////////////////////////////////////////////////
  49.     virtual ~CFlowNode_CheckForProjectiles(void)
  50.     {
  51.        
  52.     }
  53.  
  54.     ////////////////////////////////////////////////////
  55.     virtual void Serialize(SActivationInfo *pActInfo, TSerialize ser)
  56.     {
  57.        
  58.     }
  59.  
  60.     ////////////////////////////////////////////////////
  61.     virtual void GetConfiguration(SFlowNodeConfig& config)
  62.     {
  63.         static const SInputPortConfig inputs[] =
  64.         {
  65.             InputPortConfig_Void("Trigger", _HELP("Triggers the projectile check")),
  66.             InputPortConfig<EntityId>("TargetId", _HELP("The center of the searchbox")),
  67.             InputPortConfig<string> ("Ammo", _HELP("When set, limit projectile check to this ammo"), 0, _UICONFIG("enum_global:ammos")),
  68.             InputPortConfig<float>("Range", _HELP("Range for searchbox")),
  69.             {0}
  70.         };
  71.  
  72.         static const SOutputPortConfig outputs[] =
  73.         {
  74.             OutputPortConfig<EntityId>("ProjectileId", _HELP("Called when the first projectile is found and returns the Id")),
  75.             OutputPortConfig_Void("NothingFound", _HELP("Called when no projectile was found in the whole area")),
  76.             {0}
  77.         };
  78.  
  79.         config.pInputPorts = inputs;
  80.         config.pOutputPorts = outputs;
  81.         config.sDescription = _HELP("Checks for projectiles in a certain area");
  82.         config.SetCategory(EFLN_ADVANCED);
  83.     }
  84.  
  85.     ////////////////////////////////////////////////////
  86.     virtual void ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo)
  87.     {
  88.         switch (event)
  89.         {
  90.             case eFE_Activate:
  91.             {
  92.                 if (IsPortActive(pActInfo, EIP_Trigger))
  93.                 {
  94.                     CGame* pGame = static_cast<CGame*>(g_pGame);
  95.                     if (pGame)
  96.                     {
  97.                         // Get properties
  98.                         EntityId TargetId(  GetPortEntityId(pActInfo,   EIP_TargetId    ));
  99.                         string AmmoClass(   GetPortString(pActInfo,     EIP_AmmoClass   ));
  100.                         float Range(        GetPortFloat(pActInfo,      EIP_Range       ));
  101.    
  102.                         //Check
  103.                         IEntitySystem* pEntitySys = gEnv->pEntitySystem;
  104.                         Vec3 pos = pEntitySys->GetEntity(TargetId)->GetWorldPos();
  105.  
  106.                         SProjectileQuery pquery;
  107.                         pquery.box = AABB(Vec3(pos.x-Range,pos.y-Range,pos.z-Range),Vec3(pos.x+Range,pos.y+Range,pos.z+Range));
  108.                         CWeaponSystem *pWeaponSystem = pGame->GetWeaponSystem();
  109.                         int count = pWeaponSystem->QueryProjectiles(pquery);
  110.                
  111.                         CProjectile* pClosest;
  112.                         for(int i=0;i<pquery.nCount;++i)
  113.                         {
  114.                             IEntity *pEntity = pquery.pResults[i];
  115.                             if (!pEntity)
  116.                                 continue;
  117.  
  118.                             const static IEntityClass* pAmmoClass = pEntitySys->GetClassRegistry()->FindClass(AmmoClass);
  119.  
  120.                             if(pEntity->GetClass() != pAmmoClass) //Ignore projectile if it's not in the Ammo Class the user specified
  121.                                 continue;
  122.                             CProjectile* p = pGame->GetWeaponSystem()->GetProjectile(pEntity->GetId());
  123.                        
  124.                             if(!p)
  125.                                 continue;
  126.  
  127.                             pClosest = p;
  128.  
  129.                         }
  130.                    
  131.                         if(!pClosest || pClosest->GetEntityId() == 0)
  132.                         {
  133.                             ActivateOutput(pActInfo, EOP_NothingFound, true);
  134.                         }
  135.                         else
  136.                         {
  137.                             ActivateOutput(pActInfo, EOP_ProjectileId, pClosest->GetEntityId());
  138.                         }
  139.                     }
  140.                 }
  141.             }
  142.             break;
  143.         }
  144.     }
  145.  
  146.     ////////////////////////////////////////////////////
  147.     virtual void GetMemoryStatistics(ICrySizer *s)
  148.     {
  149.         s->Add(*this);
  150.     }
  151.  
  152.     ////////////////////////////////////////////////////
  153.     virtual IFlowNodePtr Clone(SActivationInfo *pActInfo)
  154.     {
  155.         return new CFlowNode_CheckForProjectiles(pActInfo);
  156.     }
  157.  
  158.  
  159.     // ILevelSystemListener
  160.     virtual void OnLevelNotFound(const char *levelName) {};
  161.     virtual void OnLoadingStart(ILevelInfo *pLevel) {};
  162.     virtual void OnLoadingComplete(ILevel *pLevel) {};
  163.     virtual void OnLoadingError(ILevelInfo *pLevel, const char *error) {};
  164.     virtual void OnLoadingProgress(ILevelInfo *pLevel, int progressAmount) {};
  165.     //~ILevelSystemListener
  166. };
  167.  
  168. /////////////////////////////////////////////////////////////////
  169. class CFlowNode_DestroyProjectile : public CFlowBaseNode
  170. {
  171.     enum EInputPorts
  172.     {
  173.         EIP_Trigger,
  174.         EIP_ProjectileId,
  175.     };
  176.  
  177.     enum EOutputPorts
  178.     {
  179.         EOP_Succeeded,
  180.         EOP_Failed,
  181.     };
  182.  
  183. public:
  184.     ////////////////////////////////////////////////////
  185.     CFlowNode_DestroyProjectile(SActivationInfo *pActInfo)
  186.     {
  187.        
  188.     }
  189.  
  190.     ////////////////////////////////////////////////////
  191.     virtual ~CFlowNode_DestroyProjectile(void)
  192.     {
  193.        
  194.     }
  195.  
  196.     ////////////////////////////////////////////////////
  197.     virtual void Serialize(SActivationInfo *pActInfo, TSerialize ser)
  198.     {
  199.        
  200.     }
  201.  
  202.     ////////////////////////////////////////////////////
  203.     virtual void GetConfiguration(SFlowNodeConfig& config)
  204.     {
  205.         static const SInputPortConfig inputs[] =
  206.         {
  207.             InputPortConfig_Void("Trigger", _HELP("Destroys the projectile")),
  208.             InputPortConfig<EntityId>("ProjectileId", _HELP("Id of the projectile")),
  209.             {0}
  210.         };
  211.  
  212.         static const SOutputPortConfig outputs[] =
  213.         {
  214.             OutputPortConfig_Void("Succeeded", _HELP("Called when job is done")),
  215.             OutputPortConfig_Void("Failed", _HELP("Called when projectile fails to destroy")),
  216.             {0}
  217.         };
  218.  
  219.         config.pInputPorts = inputs;
  220.         config.pOutputPorts = outputs;
  221.         config.sDescription = _HELP("Destroys a projectile on call");
  222.         config.SetCategory(EFLN_ADVANCED);
  223.     }
  224.  
  225.     ////////////////////////////////////////////////////
  226.     virtual void ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo)
  227.     {
  228.         switch (event)
  229.         {
  230.             case eFE_Activate:
  231.             {
  232.                 if (IsPortActive(pActInfo, EIP_Trigger))
  233.                 {
  234.                     CGame* pGame = static_cast<CGame*>(g_pGame);
  235.                     if (pGame)
  236.                     {
  237.                         // Get properties
  238.                         EntityId ProjectileId(GetPortEntityId(pActInfo, EIP_ProjectileId));
  239.                    
  240.                         CProjectile* p = pGame->GetWeaponSystem()->GetProjectile(ProjectileId);
  241.                        
  242.                         if(!p)
  243.                         {
  244.                             ActivateOutput(pActInfo, EOP_Failed, true);
  245.                         }
  246.                         else
  247.                         {
  248.                             // Try to destroy the projectile
  249.                             p->Explode(true,true);
  250.                             ActivateOutput(pActInfo, EOP_Succeeded, true);
  251.                         }
  252.                     }
  253.                 }
  254.             }
  255.             break;
  256.         }
  257.     }
  258.  
  259.     ////////////////////////////////////////////////////
  260.     virtual void GetMemoryStatistics(ICrySizer *s)
  261.     {
  262.         s->Add(*this);
  263.     }
  264.  
  265.     ////////////////////////////////////////////////////
  266.     virtual IFlowNodePtr Clone(SActivationInfo *pActInfo)
  267.     {
  268.         return new CFlowNode_DestroyProjectile(pActInfo);
  269.     }
  270. };
  271.  
  272. ////////////////////////////////////////////////////
  273. ////////////////////////////////////////////////////
  274.  
  275. REGISTER_FLOW_NODE("Projectile:CheckForProjectiles", CFlowNode_CheckForProjectiles);
  276. REGISTER_FLOW_NODE("Projectile:DestroyProjectile", CFlowNode_DestroyProjectile);
  277.  
  278.  
  279.  
  280.  
  281.  
  282. /////////////////////////////////////////////////////////////////
  283. // FlowForcePlayerStance.cpp
  284. //
  285. // Purpose: Flow node for forcing player into a stance
  286. //
  287. // History:
  288. //  - 4/12/11 : File created - Marwin Misselhorn
  289. /////////////////////////////////////////////////////////////////
  290.  
  291. #include "StdAfx.h"
  292. #include "Nodes/G2FlowBaseNode.h"
  293.  
  294. #include "GameCVars.h"
  295. #include "Player.h"
  296. #include "PlayerInput.h"
  297.  
  298. ////////////////////////////////////////////////////
  299. ////////////////////////////////////////////////////
  300. ////////////////////////////////////////////////////
  301. class CFlowNode_ForcePlayerStance : public CFlowBaseNode
  302. {
  303. private:
  304.     SActivationInfo m_actInfo;
  305.  
  306. public:
  307.     ////////////////////////////////////////////////////
  308.     CFlowNode_ForcePlayerStance(SActivationInfo *pActInfo)
  309.     {
  310.     }
  311.  
  312.     ////////////////////////////////////////////////////
  313.     virtual ~CFlowNode_ForcePlayerStance(void)
  314.     {
  315.  
  316.     }
  317.  
  318.     ////////////////////////////////////////////////////
  319.     virtual void GetMemoryStatistics(ICrySizer *s)
  320.     {
  321.         s->Add(*this);
  322.     }
  323.  
  324.     ////////////////////////////////////////////////////
  325.     virtual IFlowNodePtr Clone(SActivationInfo *pActInfo)
  326.     {
  327.         return new CFlowNode_ForcePlayerStance(pActInfo);
  328.     }
  329.  
  330.     ////////////////////////////////////////////////////
  331.     virtual void Serialize(SActivationInfo *pActInfo, TSerialize ser)
  332.     {
  333.         if (ser.IsReading())
  334.         {
  335.             m_actInfo = *pActInfo;
  336.         }
  337.     }
  338.  
  339.     enum EInputPorts
  340.     {
  341.         EIP_Trigger = 0,
  342.         EIP_Stance,
  343.     };
  344.  
  345.     enum EOutputPorts
  346.     {
  347.  
  348.         EOP_Done = 0,
  349.     };
  350.  
  351.     ////////////////////////////////////////////////////
  352.     virtual void GetConfiguration(SFlowNodeConfig& config)
  353.     {
  354.         static const SInputPortConfig inputs[] =
  355.         {
  356.             InputPortConfig_Void  ("Trigger", _HELP("Trigger")),
  357.             InputPortConfig<int>( "Stance", -1, _HELP("Try to set Stance on Player"), 0, _UICONFIG("enum_int:Stand=0,Crouch=1,Prone=2")),
  358.             {0}
  359.         };
  360.         static const SOutputPortConfig outputs[] =
  361.         {
  362.             OutputPortConfig_Void ("Done", _HELP("Set Stance Done")),
  363.             {0}
  364.         };
  365.         config.pInputPorts = inputs;
  366.         config.pOutputPorts = outputs;
  367.         config.sDescription = _HELP("Tries to force the player into a stance");
  368.         config.SetCategory(EFLN_APPROVED);
  369.     }
  370.  
  371.     ////////////////////////////////////////////////////
  372.     virtual void ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo)
  373.     {
  374.         switch (event)
  375.         {
  376.             case eFE_Initialize:
  377.             {
  378.                 m_actInfo = *pActInfo;
  379.             }
  380.             break;
  381.  
  382.             case eFE_Activate:
  383.             {
  384.                 if (IsPortActive(pActInfo, EIP_Trigger))
  385.                 {
  386.                     CActor *pPlayerActor = static_cast<CActor *>(gEnv->pGame->GetIGameFramework()->GetClientActor());
  387.                     if (pPlayerActor)
  388.                     {
  389.                         CPlayer* pPlayer = static_cast<CPlayer*> (pPlayerActor);
  390.                         if (pPlayer)
  391.                         {
  392.                             int stance = GetPortInt(pActInfo, EIP_Stance);
  393.    
  394.                             IPlayerInput* pPlayerInput = pPlayer->GetPlayerInput();
  395.                             if(pPlayerInput)
  396.                                 pPlayerInput->Reset();
  397.  
  398.                             pPlayer->SetStance((EStance) stance);
  399.            
  400.                             IPhysicalEntity *pPhysEnt = pPlayer->GetEntity()->GetPhysics();
  401.                             int result = 0;
  402.                             if (pPhysEnt)
  403.                             {
  404.                                 const SStanceInfo *sInfo = pPlayer->GetStanceInfo((EStance) stance);
  405.  
  406.                                 pe_player_dimensions playerDim;
  407.                                 playerDim.heightEye = 0.0f;
  408.                                 playerDim.heightCollider = sInfo->heightCollider;
  409.                                 playerDim.sizeCollider = sInfo->size;
  410.                                 playerDim.heightPivot = sInfo->heightPivot;
  411.                                 playerDim.maxUnproj = max(0.0f,sInfo->heightPivot);
  412.                                 playerDim.bUseCapsule = sInfo->useCapsule;
  413.  
  414.                                 result = pPhysEnt->SetParams(&playerDim);
  415.                             }
  416.  
  417.                             pPlayer->StanceChanged((EStance) stance);
  418.  
  419.                             // Request new animation stance.
  420.                             // AnimatedCharacter has it's own understanding of stance, which might be in conflict.
  421.                             // Ideally the stance should be maintained only in one place. Currently the Actor (gameplay) rules.
  422.                             if (pPlayer->GetAnimatedCharacter() != NULL)
  423.                                 pPlayer->GetAnimatedCharacter()->RequestStance(stance, pPlayer->GetStanceInfo((EStance) stance)->name);
  424.  
  425.                             if (pPhysEnt != NULL)
  426.                             {
  427.                                 pe_action_awake aa;
  428.                                 aa.bAwake = 1;
  429.                                 pPhysEnt->Action(&aa);
  430.                             }
  431.  
  432.                             if(pPlayerInput && stance == STANCE_PRONE)
  433.                             {
  434.                                 pPlayerInput->OnAction("prone",eAAM_OnPress,1.0f);
  435.                             }
  436.  
  437.                             if(pPlayerInput && stance == STANCE_CROUCH)
  438.                             {
  439.                                 pPlayerInput->OnAction("crouch",eAAM_OnPress,1.0f);
  440.                             }
  441.  
  442.                             ActivateOutput(pActInfo, EOP_Done, true);
  443.                         }
  444.                     }
  445.                     ActivateOutput(pActInfo, EOP_Done, false);
  446.                 }
  447.             }
  448.             break;
  449.         }
  450.     }
  451. };
  452. ////////////////////////////////////////////////////
  453. ////////////////////////////////////////////////////
  454. class CFlowNode_ChangeStanceSpeed : public CFlowBaseNode
  455. {
  456. private:
  457.     SActivationInfo m_actInfo;
  458.  
  459. public:
  460.     ////////////////////////////////////////////////////
  461.     CFlowNode_ChangeStanceSpeed(SActivationInfo *pActInfo)
  462.     {
  463.     }
  464.  
  465.     ////////////////////////////////////////////////////
  466.     virtual ~CFlowNode_ChangeStanceSpeed(void)
  467.     {
  468.  
  469.     }
  470.  
  471.     ////////////////////////////////////////////////////
  472.     virtual void GetMemoryStatistics(ICrySizer *s)
  473.     {
  474.         s->Add(*this);
  475.     }
  476.  
  477.     ////////////////////////////////////////////////////
  478.     virtual IFlowNodePtr Clone(SActivationInfo *pActInfo)
  479.     {
  480.         return new CFlowNode_ChangeStanceSpeed(pActInfo);
  481.     }
  482.  
  483.     ////////////////////////////////////////////////////
  484.     virtual void Serialize(SActivationInfo *pActInfo, TSerialize ser)
  485.     {
  486.         if (ser.IsReading())
  487.         {
  488.             m_actInfo = *pActInfo;
  489.         }
  490.     }
  491.  
  492.     enum EInputPorts
  493.     {
  494.         EIP_Trigger = 0,
  495.         EIP_Stance,
  496.         EIP_NormalSpeed,
  497.         EIP_MaxSpeed,
  498.     };
  499.  
  500.     enum EOutputPorts
  501.     {
  502.         EOP_Done = 0,
  503.     };
  504.  
  505.     ////////////////////////////////////////////////////
  506.     virtual void GetConfiguration(SFlowNodeConfig& config)
  507.     {
  508.         static const SInputPortConfig inputs[] =
  509.         {
  510.             InputPortConfig_Void  ("Trigger", _HELP("Trigger")),
  511.             InputPortConfig<int>( "Stance", -1, _HELP("Player stance"), 0, _UICONFIG("enum_int:Stand=0,Crouch=1,Prone=2")),
  512.             InputPortConfig<float>( "NormalSpeed", 0.0f, _HELP("Normal speed for the stance (walk)")),
  513.             InputPortConfig<float>( "MaxSpeed", 0.0f, _HELP("Max speed for the stance (sprint)")),
  514.             {0}
  515.         };
  516.         static const SOutputPortConfig outputs[] =
  517.         {
  518.             OutputPortConfig_Void ("Done", _HELP("Change stance speed Done")),
  519.             {0}
  520.         };
  521.         config.pInputPorts = inputs;
  522.         config.pOutputPorts = outputs;
  523.         config.sDescription = _HELP("Tries to change the speed of a stance for the player");
  524.         config.SetCategory(EFLN_APPROVED);
  525.     }
  526.  
  527.     ////////////////////////////////////////////////////
  528.     virtual void ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo)
  529.     {
  530.         switch (event)
  531.         {
  532.             case eFE_Initialize:
  533.             {
  534.                 m_actInfo = *pActInfo;
  535.             }
  536.             break;
  537.  
  538.             case eFE_Activate:
  539.             {
  540.                 if (IsPortActive(pActInfo, EIP_Trigger))
  541.                 {
  542.                     CActor *pPlayerActor = static_cast<CActor *>(gEnv->pGame->GetIGameFramework()->GetClientActor());
  543.                     if (pPlayerActor)
  544.                     {
  545.                         CPlayer* pPlayer = static_cast<CPlayer*> (pPlayerActor);
  546.                         if (pPlayer)
  547.                         {
  548.                             int stance = GetPortInt(pActInfo, EIP_Stance);
  549.  
  550.                             float normalSpeed = GetPortFloat(pActInfo, EIP_NormalSpeed);
  551.                             float maxSpeed = GetPortFloat(pActInfo, EIP_MaxSpeed);
  552.  
  553.                             const SStanceInfo *sInfo = pPlayer->GetStanceInfo((EStance)stance);
  554.  
  555.                             SStanceInfo standInfo;
  556.  
  557.                             //Copy old values
  558.                             standInfo.heightCollider = sInfo->heightCollider;
  559.                             standInfo.heightPivot = sInfo->heightPivot;
  560.  
  561.                             standInfo.leanLeftViewOffset = sInfo->leanLeftViewOffset;
  562.                             standInfo.leanLeftWeaponOffset = sInfo->leanLeftWeaponOffset;
  563.                             standInfo.leanRightViewOffset = sInfo->leanRightViewOffset;
  564.                             standInfo.leanRightWeaponOffset = sInfo->leanRightWeaponOffset;
  565.  
  566.                             standInfo.modelOffset = sInfo->modelOffset;
  567.                             strcpy(standInfo.name, sInfo->name);
  568.                             standInfo.size = sInfo->size;
  569.    
  570.                             standInfo.useCapsule = sInfo->useCapsule;
  571.                             standInfo.viewOffset = sInfo->viewOffset;
  572.                             standInfo.weaponOffset = sInfo->weaponOffset;
  573.  
  574.                             //Set new values
  575.                             standInfo.normalSpeed = normalSpeed;
  576.                             standInfo.maxSpeed = maxSpeed;
  577.  
  578.                             pPlayer->SetupStance((EStance)stance, &standInfo);
  579.            
  580.  
  581.                             ActivateOutput(pActInfo, EOP_Done, true);
  582.  
  583.                             break;
  584.                         }
  585.                     }
  586.                     ActivateOutput(pActInfo, EOP_Done, false);
  587.                 }
  588.             }
  589.             break;
  590.         }
  591.     }
  592. };
  593.  
  594.  
  595. ////////////////////////////////////////////////////
  596. ////////////////////////////////////////////////////
  597.  
  598. REGISTER_FLOW_NODE("Game:ForcePlayerStance", CFlowNode_ForcePlayerStance);
  599. REGISTER_FLOW_NODE("Game:ChangePlayerStanceSpeed", CFlowNode_ChangeStanceSpeed);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement