CUgopEntity

CustomZone.cpp

Jan 23rd, 2019
17
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include "customzone.h"
  3. #include "actor.h"
  4. #include "hudmanager.h"
  5. #include "..\xr_ioconsole.h"
  6.  
  7. CCustomZone::CCustomZone(void) {
  8.     m_maxPower = 100.f;
  9.     m_attn = 1.f;
  10.     m_period = 1000;
  11.     m_ready = false;
  12.     m_pLocalActor = NULL;
  13. }
  14.  
  15. CCustomZone::~CCustomZone(void) {}
  16.  
  17. BOOL CCustomZone::net_Spawn(LPVOID DC) {
  18.     BOOL res = inherited::net_Spawn(DC);
  19.  
  20.     if(res) {
  21.         CCF_Shape *l_pShape = xr_new<CCF_Shape>(this);
  22.         cfModel = l_pShape;
  23.         xrSE_Zone* Z        = (xrSE_Zone*)DC;
  24.         for (u32 i=0; i < Z->shapes.size(); i++) {
  25.             xrSE_CFormed::shape_def& S = Z->shapes[i];
  26.             switch (S.type) {
  27.                 case 0 : l_pShape->add_sphere(S.data.sphere); break;
  28.                 case 1 : l_pShape->add_box(S.data.box); break;
  29.             }
  30.         }
  31.  
  32.         l_pShape->ComputeBounds();
  33.         pCreator->ObjectSpace.Object_Register(this);
  34.         cfModel->OnMove();
  35.         m_maxPower = Z->m_maxPower;
  36.         m_attn = Z->m_attn;
  37.         m_period = Z->m_period;
  38.  
  39.         Fvector P; clXFORM().transform_tiny(P,cfModel->getSphere().P);
  40.         Sound->PlayAtPos(m_ambient,this, vPosition, true);
  41.  
  42. //      setVisible(true);
  43.         setEnabled(true);
  44.     }
  45.  
  46.     return res;
  47. }
  48.  
  49. void CCustomZone::Load(LPCSTR section) {
  50.     // verify class
  51.     LPCSTR Class = pSettings->ReadSTRING(section,"class");
  52.     CLASS_ID load_cls = TEXT2CLSID(Class);
  53.     R_ASSERT(load_cls==SUB_CLS_ID);
  54.  
  55.     inherited::Load(section);
  56.  
  57.     LPCSTR l_PSnd = pSettings->ReadSTRING(section,"sound");
  58.     SoundCreate(m_ambient, l_PSnd);
  59.  
  60.  
  61. // @@@ WT: !!!!!ВРЕМЕННО!!!!!
  62.     //CRender_target*       T   = ::Render->getTarget();
  63.     //T->set_duality_h      (0);
  64.     //T->set_duality_v      (0);
  65.     //T->set_noise          (0);
  66. // @@@ WT
  67.  
  68. }
  69.  
  70. void CCustomZone::net_Destroy() {
  71.     inherited::net_Destroy();
  72.     SoundDestroy(m_ambient);
  73. }
  74.  
  75. //void CCustomZone::Update(u32 dt) {
  76.     //inherited::Update (dt);
  77. void CCustomZone::UpdateCL() {
  78.     //u32 dt = Device.dwTimeDelta;
  79.     inherited::UpdateCL();
  80.  
  81.     const Fsphere& s        = cfModel->getSphere();
  82.     Fvector                 P;
  83.     clXFORM().transform_tiny(P,s.P);
  84.     feel_touch_update       (P,s.R);
  85.  
  86.     if(m_ready) {
  87.         set<CObject*>::iterator l_it;
  88.         for(l_it = m_inZone.begin(); l_it != m_inZone.end(); l_it++) {
  89.             Affect(*l_it);
  90.         }
  91.         m_ready = false;
  92.     }
  93. }
  94.  
  95.  
  96. void CCustomZone::feel_touch_new(CObject* O) {
  97.     if(bDebug) Level().HUD()->outMessage(0xffffffff,O->cName(),"entering a zone.");
  98.     m_inZone.insert(O);
  99.     if(dynamic_cast<CActor*>(O) && O == Level().CurrentEntity()) m_pLocalActor = dynamic_cast<CActor*>(O);
  100. }
  101.  
  102. void CCustomZone::feel_touch_delete(CObject* O) {
  103.     if(bDebug) Level().HUD()->outMessage(0xffffffff,O->cName(),"leaving a zone.");
  104.     m_inZone.erase(O);
  105.     if(dynamic_cast<CActor*>(O)) m_pLocalActor = NULL;
  106. }
  107.  
  108. BOOL CCustomZone::feel_touch_contact(CObject* O) {
  109.     if(!O->Local() || !((CGameObject*)O)->IsVisibleForZones()) return false;
  110.     return ((CCF_Shape*)cfModel)->Contact(O);
  111. }
  112.  
  113. f32 CCustomZone::Power(f32 dist) {
  114.     f32 l_r = cfModel->getRadius();
  115. //  return l_r < dist ? 0 : m_maxPower * (1.f - m_attn*dist/l_r);
  116.     f32 l_pow = l_r < dist ? 0 : m_maxPower * (1.f - m_attn*(dist/l_r)*(dist/l_r));
  117.     return l_pow < 0 ? 0 : l_pow;
  118. }
  119.  
  120. void CCustomZone::SoundCreate(sound& dest, LPCSTR s_name, int iType, BOOL bCtrlFreq) {
  121.     string256 temp;
  122.     if (Engine.FS.Exist(temp,Path.Sounds,s_name)) {
  123.         Sound->Create(dest,TRUE,s_name,bCtrlFreq,iType);
  124.         return;
  125.     }
  126.     Debug.fatal ("Can't find sound '%s'",s_name,cName());
  127. }
  128.  
  129. void CCustomZone::SoundDestroy(sound& dest) {
  130.     Sound->Delete           (dest);
  131. }
  132.  
  133. //#ifdef DEBUG
  134. void CCustomZone::OnRender() {
  135.     if(!bDebug) return;
  136.     RCache.OnFrameEnd();
  137.     Fvector l_half; l_half.set(.5f, .5f, .5f);
  138.     Fmatrix l_ball, l_box;
  139.     vector<CCF_Shape::shape_def> &l_shapes = ((CCF_Shape*)cfModel)->Shapes();
  140.     vector<CCF_Shape::shape_def>::iterator l_pShape;
  141.     for(l_pShape = l_shapes.begin(); l_pShape != l_shapes.end(); l_pShape++) {
  142.         switch(l_pShape->type) {
  143.             case 0 : {
  144.                 Fsphere &l_sphere = l_pShape->data.sphere;
  145.                 l_ball.scale(l_sphere.R, l_sphere.R, l_sphere.R);
  146.                 //l_ball.scale(1.f, 1.f, 1.f);
  147.                 Fvector l_p; clTransform.transform(l_p, l_sphere.P);
  148.                 l_ball.translate_add(l_p);
  149.                 //l_ball.mul(clTransform, l_ball);
  150.                 //l_ball.mul(l_ball, clTransform);
  151.                 RCache.dbg_DrawEllipse(l_ball, D3DCOLOR_XRGB(0,255,255));
  152.             } break;
  153.             case 1 : {
  154.                 l_box.mul(clTransform, l_pShape->data.box);
  155.                 RCache.dbg_DrawOBB(l_box, l_half, D3DCOLOR_XRGB(0,255,255));
  156.             } break;
  157.         }
  158.     }
  159. }
  160. //#endif
RAW Paste Data