ControlTrigger.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //============================================================================================
  2. // Spirenkov Maxim, 2006
  3. //============================================================================================
  4. // ControlTrigger
  5. //============================================================================================
  6. #include "ControlTrigger.h"
  7. ControlTrigger::ControlTrigger()
  8. {
  9. contrrolCode = CST_INACTIVE;
  10. type = CST_ACTIVATED;
  11. repeatWaitTime = 0.1f;
  12. currentTime = 0.0f;
  13. isLookRepeat = false;
  14. }
  15. ControlTrigger::~ControlTrigger()
  16. {
  17. }
  18. //Инициализировать объект
  19. bool ControlTrigger::Create(MOPReader & reader)
  20. {
  21. contrrolCode = Controls().FindControlByName(reader.String().c_str());
  22. const char * mode = reader.Enum().c_str();
  23. if(mode[0] == 'P' || mode[0] == 'p')
  24. {
  25. type = CST_ACTIVATED;
  26. isLookRepeat = false;
  27. if(mode[5] != 0)
  28. {
  29. isLookRepeat = true;
  30. repeatWaitTime = api->Storage().GetFloat("Runtime.System.RepeatWaitTime", 0.1f);
  31. repeatWaitTime = Clampf(repeatWaitTime, 0.001f, 10.0f);
  32. }
  33. }else{
  34. type = CST_INACTIVATED;
  35. }
  36. trigger.Init(reader);
  37. Activate(reader.Bool());
  38. return true;
  39. }
  40. //Активировать
  41. void ControlTrigger::Activate(bool isActive)
  42. {
  43. DetectorObject::Activate(isActive);
  44. if(EditMode_IsOn()) return;
  45. if(isActive)
  46. {
  47. SetUpdate(&ControlTrigger::Work, ML_TRIGGERS);
  48. }else{
  49. DelUpdate(&ControlTrigger::Work);
  50. }
  51. }
  52. //Инициализировать объект
  53. bool ControlTrigger::EditMode_Create(MOPReader & reader)
  54. {
  55. return true;
  56. }
  57. //Работа детектора
  58. void _cdecl ControlTrigger::Work(float dltTime, long level)
  59. {
  60. if(MissionsManager::Ptr())
  61. {
  62. if(!MissionsManager::Ptr()->IsActive(&Mission()))
  63. {
  64. return;
  65. }
  66. }
  67. if(Controls().GetControlStateType(contrrolCode) == type)
  68. {
  69. LogicDebug("Triggering");
  70. trigger.Activate(Mission(), false);
  71. currentTime = 0.0f;
  72. }
  73. if(isLookRepeat && Controls().GetControlStateType(contrrolCode) == CST_ACTIVE)
  74. {
  75. currentTime += dltTime;
  76. if(currentTime >= repeatWaitTime)
  77. {
  78. LogicDebug("Triggering repeat");
  79. trigger.Activate(Mission(), false);
  80. currentTime = 0.0f;
  81. }
  82. }
  83. }
  84. MOP_BEGINLISTCG(ControlTrigger, "Control trigger", '1.00', 0x0fffffff, "Object trigger at default control (key)\nRepeat time get from \"float Runtime.System.RepeatWaitTime\"", "Logic")
  85. MOP_ENUMBEG("KeyMode")
  86. MOP_ENUMELEMENT("Press")
  87. MOP_ENUMELEMENT("Press and repeat")
  88. MOP_ENUMELEMENT("Release")
  89. MOP_ENUMEND
  90. MOP_STRINGC("Control", "", "Control, definition at some resource\\ini\\control\\*.ini")
  91. MOP_ENUM("KeyMode", "Control action")
  92. MOP_MISSIONTRIGGERG("Event", "")
  93. MOP_BOOL("Active", false)
  94. MOP_ENDLIST(ControlTrigger)