File size: 4,847 Bytes
24b81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/**
 * \defgroup Components
 * \desc Constants for Components
 * @{
 */
const string	COMP_NAME_NONE				= "None";
const int		COMP_TYPE_UNDEFINED			= -1;
const int		COMP_TYPE_ETITY_DEBUG		= 0;
const int		COMP_TYPE_ENERGY_MANAGER	= 1;
const int		COMP_TYPE_BODY_STAGING		= 2;
const int		COMP_TYPE_ANIMAL_BLEEDING	= 3;
const int		COMP_TYPE_COUNT				= 4;
/** @}*/

class Component
{

	//==========================================
	// Variables Private Static
	private static string m_CompNames[COMP_TYPE_COUNT];	
	
	//==========================================
	// Variables Private
	protected EntityAI		m_ThisEntityAI;
	
	//==========================================
	
	void 	Event_OnFrame(IEntity other, float timeSlice);
	Shape 	DebugBBoxDraw();
	void	DebugBBoxSetColor(int color);
	void	DebugBBoxDelete();
	Shape	DebugDirectionDraw(float distance = 1);
	void	DebugDirectionSetColor(int color);
	void	DebugDirectionDelete();
	
	// Methods Public Static
	static void	Init()
	{
		m_CompNames[COMP_TYPE_ETITY_DEBUG]			= "ComponentEntityDebug";
		m_CompNames[COMP_TYPE_ENERGY_MANAGER]		= "ComponentEnergyManager";
		m_CompNames[COMP_TYPE_BODY_STAGING]			= "ComponentBodyStaging";
		m_CompNames[COMP_TYPE_ANIMAL_BLEEDING]		= "ComponentAnimalBleeding";
	}

	///////////////////////////////////public/static
	// GetNameByType
	////////////////////////////////////////////////
	static string GetNameByType(int comp_type)
	{
		if ( IsTypeExist(comp_type) == false )
		{
			LogErrorBadCompType(comp_type, "Component->GetNameByType()");
			return "None";
		}
		
		return m_CompNames[comp_type];
	}

	///////////////////////////////////public/static
	// IsTypeExist
	////////////////////////////////////////////////
	static bool IsTypeExist(int comp_type)
	{
		if ( comp_type < 0 || comp_type >= COMP_TYPE_COUNT )
		{
			return false;
		}
		
		return true;
	}


	///////////////////////////////////public/static
	// LogErrorBadCompType
	////////////////////////////////////////////////
	static void	LogErrorBadCompType(int comp_type, string fnc_name)
	{
		string msg = "Bad parameter comp_type='"+comp_type.ToString()+"'. Parameter must be 0-"+(COMP_TYPE_COUNT - 1).ToString()+". Returning component name 'None'.";
		Debug.LogError(msg, "Component", "n/a", fnc_name);
	}

	///////////////////////////////////public/static
	// LogWarningAlredyExist
	////////////////////////////////////////////////
	static void	LogWarningAlredyExist(int comp_type, string fnc_name)
	{
		string msg = "Component '"+Component.GetNameByType(comp_type)+"' already exists!";
		Debug.LogError(msg, "Component", "n/a", fnc_name);
	}

	//=======================================public
	// SetParentEntityAI
	//=============================================
	void SetParentEntityAI(EntityAI e)
	{
		m_ThisEntityAI = e;
	}

	//====================================protected
	// Awake
	//=============================================
	void Event_OnAwake()
	{
		
	}

	//====================================protected
	// Init
	//=============================================
	void Event_OnInit()
	{
		
	}

	//=======================================public
	// Log
	//=============================================
	void LogThis(string msg, string fnc_name = "n/a")
	{
		//Debug.Log(msg, GetCompName(), "n/a", fnc_name, m_ThisEntityAI.ToString());
	}

	//=======================================public
	// LogWarning
	//=============================================
	void LogThisWarning(string msg, string fnc_name = "n/a")
	{
		Debug.LogWarning(msg, GetCompName(), "n/a", fnc_name, m_ThisEntityAI.ToString());
	}

	//=======================================public
	// LogError
	//=============================================
	void LogThisError(string msg, string fnc_name = "n/a")
	{
		Debug.LogError(msg, GetCompName(), "n/a", fnc_name, m_ThisEntityAI.ToString());
	}

	//=======================================public
	// GetType
	//=============================================
	string GetCompName()
	{
		return Component.GetNameByType(this.GetCompType());
	}

	//=======================================public
	// GetType
	//=============================================
	int GetCompType()
	{
		return COMP_TYPE_UNDEFINED;
	}

	//=======================================public
	// Event_OnItemAttached
	//=============================================
	void Event_OnItemAttached(EntityAI item, string slot_name)
	{
		LogThis("" + item + " -> " + slot_name,"Event_OnItemAttached");
		//Debug.Log("Component=>Event_OnItemAttached: " + item + " -> " + slot_name, );
	}

	//=======================================public
	// Event_OnItemDetached
	//=============================================
	void Event_OnItemDetached(EntityAI item, string slot_name)
	{
		LogThis("" + item + " <- " + slot_name,"Event_OnItemDetached");
		//Log("Component=>Event_OnItemDetached: " + item + " <- " + slot_name );
	}
}