File size: 2,124 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
/**@class	BotGuardBase
 * @brief	represents guard on a transition from state to state
 **/
class BotGuardBase
{
	/**@fn		GuardCondition
	 * @brief enable or disable transition based on condition
	 * the guard is a boolean operation executed first and which can prevent the transition from firing by returning false
	 * @return	true if transition is allowed
	 **/
	bool GuardCondition (BotEventBase e) { return true; }
};

class BotGuardAnd extends BotGuardBase
{
	ref BotGuardBase m_arg0;
	ref BotGuardBase m_arg1;

	void BotGuardAnd (BotGuardBase arg0 = NULL, BotGuardBase arg1 = NULL) { m_arg0 = arg0; m_arg1 = arg1; }

	override bool GuardCondition (BotEventBase e)
	{
		bool result = m_arg0.GuardCondition(e) && m_arg1.GuardCondition(e);
		botDebugPrint("[botfsm] guard - " + m_arg0.Type() + " && " + m_arg1.Type() + " = " + result);
		return result;
	}
};

class BotGuardNot extends BotGuardBase
{
	ref BotGuardBase m_arg0;

	void BotGuardNot (BotGuardBase arg0 = NULL) { m_arg0 = arg0; }

	override bool GuardCondition (BotEventBase e)
	{
		bool result = !m_arg0.GuardCondition(e);
		botDebugPrint("[botfsm] guard - ! " + m_arg0.Type() + " = " + result);
		return result;
	}
};

class BotGuardOr extends BotGuardBase
{
	ref BotGuardBase m_arg0;
	ref BotGuardBase m_arg1;

	void BotGuardOr (BotGuardBase arg0 = NULL, BotGuardBase arg1 = NULL) { m_arg0 = arg0; m_arg1 = arg1; }

	override bool GuardCondition (BotEventBase e)
	{
		bool result = m_arg0.GuardCondition(e) || m_arg1.GuardCondition(e);
		botDebugPrint("[botfsm] guard - " + m_arg0.Type() + " || " + m_arg1.Type() + " = " + result);
		return result;
	}
};

class BotGuardHasItemInHands extends HandGuardBase
{
	protected Man m_Player;
	void BotGuardHasItemInHands (Man p = NULL) { m_Player = p; }

	override bool GuardCondition (HandEventBase e)
	{
		if (m_Player.GetHumanInventory().GetEntityInHands())
		{
			if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[botfsm] guard - has valid entity in hands");
			return true;
		}

		if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[botfsm] guard - no entity in hands");
		return false;
	}
};