component.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /**
  2. * \defgroup Components
  3. * \desc Constants for Components
  4. * @{
  5. */
  6. const string COMP_NAME_NONE = "None";
  7. const int COMP_TYPE_UNDEFINED = -1;
  8. const int COMP_TYPE_ETITY_DEBUG = 0;
  9. const int COMP_TYPE_ENERGY_MANAGER = 1;
  10. const int COMP_TYPE_BODY_STAGING = 2;
  11. const int COMP_TYPE_ANIMAL_BLEEDING = 3;
  12. const int COMP_TYPE_COUNT = 4;
  13. /** @}*/
  14. class Component
  15. {
  16. //==========================================
  17. // Variables Private Static
  18. private static string m_CompNames[COMP_TYPE_COUNT];
  19. //==========================================
  20. // Variables Private
  21. protected EntityAI m_ThisEntityAI;
  22. //==========================================
  23. void Event_OnFrame(IEntity other, float timeSlice);
  24. Shape DebugBBoxDraw();
  25. void DebugBBoxSetColor(int color);
  26. void DebugBBoxDelete();
  27. Shape DebugDirectionDraw(float distance = 1);
  28. void DebugDirectionSetColor(int color);
  29. void DebugDirectionDelete();
  30. // Methods Public Static
  31. static void Init()
  32. {
  33. m_CompNames[COMP_TYPE_ETITY_DEBUG] = "ComponentEntityDebug";
  34. m_CompNames[COMP_TYPE_ENERGY_MANAGER] = "ComponentEnergyManager";
  35. m_CompNames[COMP_TYPE_BODY_STAGING] = "ComponentBodyStaging";
  36. m_CompNames[COMP_TYPE_ANIMAL_BLEEDING] = "ComponentAnimalBleeding";
  37. }
  38. ///////////////////////////////////public/static
  39. // GetNameByType
  40. ////////////////////////////////////////////////
  41. static string GetNameByType(int comp_type)
  42. {
  43. if ( IsTypeExist(comp_type) == false )
  44. {
  45. LogErrorBadCompType(comp_type, "Component->GetNameByType()");
  46. return "None";
  47. }
  48. return m_CompNames[comp_type];
  49. }
  50. ///////////////////////////////////public/static
  51. // IsTypeExist
  52. ////////////////////////////////////////////////
  53. static bool IsTypeExist(int comp_type)
  54. {
  55. if ( comp_type < 0 || comp_type >= COMP_TYPE_COUNT )
  56. {
  57. return false;
  58. }
  59. return true;
  60. }
  61. ///////////////////////////////////public/static
  62. // LogErrorBadCompType
  63. ////////////////////////////////////////////////
  64. static void LogErrorBadCompType(int comp_type, string fnc_name)
  65. {
  66. string msg = "Bad parameter comp_type='"+comp_type.ToString()+"'. Parameter must be 0-"+(COMP_TYPE_COUNT - 1).ToString()+". Returning component name 'None'.";
  67. Debug.LogError(msg, "Component", "n/a", fnc_name);
  68. }
  69. ///////////////////////////////////public/static
  70. // LogWarningAlredyExist
  71. ////////////////////////////////////////////////
  72. static void LogWarningAlredyExist(int comp_type, string fnc_name)
  73. {
  74. string msg = "Component '"+Component.GetNameByType(comp_type)+"' already exists!";
  75. Debug.LogError(msg, "Component", "n/a", fnc_name);
  76. }
  77. //=======================================public
  78. // SetParentEntityAI
  79. //=============================================
  80. void SetParentEntityAI(EntityAI e)
  81. {
  82. m_ThisEntityAI = e;
  83. }
  84. //====================================protected
  85. // Awake
  86. //=============================================
  87. void Event_OnAwake()
  88. {
  89. }
  90. //====================================protected
  91. // Init
  92. //=============================================
  93. void Event_OnInit()
  94. {
  95. }
  96. //=======================================public
  97. // Log
  98. //=============================================
  99. void LogThis(string msg, string fnc_name = "n/a")
  100. {
  101. //Debug.Log(msg, GetCompName(), "n/a", fnc_name, m_ThisEntityAI.ToString());
  102. }
  103. //=======================================public
  104. // LogWarning
  105. //=============================================
  106. void LogThisWarning(string msg, string fnc_name = "n/a")
  107. {
  108. Debug.LogWarning(msg, GetCompName(), "n/a", fnc_name, m_ThisEntityAI.ToString());
  109. }
  110. //=======================================public
  111. // LogError
  112. //=============================================
  113. void LogThisError(string msg, string fnc_name = "n/a")
  114. {
  115. Debug.LogError(msg, GetCompName(), "n/a", fnc_name, m_ThisEntityAI.ToString());
  116. }
  117. //=======================================public
  118. // GetType
  119. //=============================================
  120. string GetCompName()
  121. {
  122. return Component.GetNameByType(this.GetCompType());
  123. }
  124. //=======================================public
  125. // GetType
  126. //=============================================
  127. int GetCompType()
  128. {
  129. return COMP_TYPE_UNDEFINED;
  130. }
  131. //=======================================public
  132. // Event_OnItemAttached
  133. //=============================================
  134. void Event_OnItemAttached(EntityAI item, string slot_name)
  135. {
  136. LogThis("" + item + " -> " + slot_name,"Event_OnItemAttached");
  137. //Debug.Log("Component=>Event_OnItemAttached: " + item + " -> " + slot_name, );
  138. }
  139. //=======================================public
  140. // Event_OnItemDetached
  141. //=============================================
  142. void Event_OnItemDetached(EntityAI item, string slot_name)
  143. {
  144. LogThis("" + item + " <- " + slot_name,"Event_OnItemDetached");
  145. //Log("Component=>Event_OnItemDetached: " + item + " <- " + slot_name );
  146. }
  147. }