Counter.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. //===========================================================================================================================
  2. // Spirenkov Maxim, 2003
  3. //===========================================================================================================================//
  4. // Mission objects
  5. //===========================================================================================================================
  6. // Counter
  7. //============================================================================================
  8. #include "Counter.h"
  9. #include "MissionReloader.h"
  10. //============================================================================================
  11. Counter::Counter()
  12. {
  13. counter = 0;
  14. maxCount = 0;
  15. lastTick = false;
  16. }
  17. Counter::~Counter()
  18. {
  19. }
  20. //============================================================================================
  21. //Инициализировать объект
  22. bool Counter::Create(MOPReader & reader)
  23. {
  24. counter = 0;
  25. maxCount = reader.Long();
  26. lastTick = reader.Bool();
  27. Activate(reader.Bool());
  28. eventTick.Init(reader);
  29. eventCount.Init(reader);
  30. return true;
  31. }
  32. //Обработчик команд для объекта
  33. void Counter::Command(const char * id, dword numParams, const char ** params)
  34. {
  35. if(!id) id = "";
  36. if(string::IsEqual(id, "reset"))
  37. {
  38. counter = 0;
  39. eventTick.Reset();
  40. eventCount.Reset();
  41. LogicDebug("Reseting...");
  42. return;
  43. }
  44. if(!IsActive())
  45. {
  46. LogicDebug("Skip command \"%s\", counter now is't active...", id);
  47. return;
  48. }
  49. if(counter >= maxCount)
  50. {
  51. LogicDebug("Skip command \"%s\", counter already done (%i of %i)...", id, counter, maxCount);
  52. return;
  53. }
  54. if(string::IsEqual(id, "tick"))
  55. {
  56. long delta = 1;
  57. if(numParams > 0)
  58. {
  59. char * chr = null;
  60. long delta = abs(strtol(params[0], &chr, 10));
  61. }
  62. counter += delta;
  63. bool isEnableTick = true;
  64. if(counter >= maxCount)
  65. {
  66. isEnableTick = lastTick;
  67. }
  68. LogicDebug("Tick %i of %i (step = %i)", counter, maxCount, delta);
  69. if(isEnableTick)
  70. {
  71. LogicDebug("Tick event");
  72. eventTick.Activate(Mission(), false);
  73. }
  74. if(counter >= maxCount)
  75. {
  76. LogicDebug("End count event");
  77. eventCount.Activate(Mission(), false);
  78. }
  79. return;
  80. }
  81. if(string::IsEqual(id, "tickdown"))
  82. {
  83. long delta = 1;
  84. if(numParams > 0)
  85. {
  86. char * chr = null;
  87. long delta = abs(strtol(params[0], &chr, 10));
  88. }
  89. counter -= delta;
  90. if(counter < 0) counter = 0;
  91. LogicDebug("Tickdown %i of %i (step = %i)", counter, maxCount, delta);
  92. }
  93. LogicDebug("Unknow command \"%s\"", id);
  94. }
  95. //Активировать
  96. void Counter::Activate(bool isActive)
  97. {
  98. MissionObject::Activate(isActive);
  99. if(IsActive())
  100. {
  101. LogicDebug("Activate");
  102. }else{
  103. LogicDebug("Deactivate");
  104. }
  105. }
  106. //Инициализировать объект
  107. bool Counter::EditMode_Create(MOPReader & reader)
  108. {
  109. return true;
  110. }
  111. //Обновить параметры
  112. bool Counter::EditMode_Update(MOPReader & reader)
  113. {
  114. return true;
  115. }
  116. //Получить размеры описывающего ящика
  117. void Counter::EditMode_GetSelectBox(Vector & min, Vector & max)
  118. {
  119. min = max = 0.0f;
  120. }
  121. //============================================================================================
  122. //Описание
  123. //============================================================================================
  124. const char * Counter::comment =
  125. "Counter use for count some events...\n"
  126. "\n"
  127. "Commands list:\n"
  128. "----------------------------------------\n"
  129. " Command tick - increase counter\n"
  130. "----------------------------------------\n"
  131. " command: tick\n"
  132. " \n"
  133. "----------------------------------------\n"
  134. " Command tick count - increase counter\n"
  135. "----------------------------------------\n"
  136. " command: tick\n"
  137. " param: count\n"
  138. " \n"
  139. "----------------------------------------\n"
  140. " Command tickdown - decrease counter\n"
  141. "----------------------------------------\n"
  142. " command: tickdown\n"
  143. " \n"
  144. "----------------------------------------\n"
  145. " Command tickdown count - decrease counter\n"
  146. "----------------------------------------\n"
  147. " command: tickdown\n"
  148. " param: count\n"
  149. " \n"
  150. "----------------------------------------\n"
  151. " Reset counter\n"
  152. "----------------------------------------\n"
  153. " command: reset\n"
  154. " ";
  155. //============================================================================================
  156. //Параметры инициализации
  157. //============================================================================================
  158. MOP_BEGINLISTCG(Counter, "Counter", '1.00', 0x0fffffff, Counter::comment, "Logic")
  159. MOP_LONGEXC("Repeat count", 5, 1, 1000000000, "Count\nFor repeat activate need command \"reset\".");
  160. MOP_BOOLC("Last tick", true, "Enable last \"Tick event\" before \"End count event\"")
  161. MOP_BOOLC("Active", true, "Active trigger in start mission time")
  162. MOP_MISSIONTRIGGER("Tick event")
  163. MOP_MISSIONTRIGGER("End count event")
  164. MOP_ENDLIST(Counter)