File: WipfAI.c

package info (click to toggle)
openclonk 8.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 169,516 kB
  • sloc: cpp: 180,479; ansic: 108,988; xml: 31,371; python: 1,223; php: 767; makefile: 145; sh: 101; javascript: 34
file content (101 lines) | stat: -rw-r--r-- 2,214 bytes parent folder | download | duplicates (6)
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
// Artificial intelligence for the wipf.

#appendto Wipf

public func EnableTutorialControl(bool friend)
{
	RemoveEffect("IntActivity", this);
	var effect = AddEffect("TutorialWipf", this, 1, 5, this);
	if (!friend)
		effect.sequence = "StayAtGrainField";
	return;
}

public func DisableTutorialControl()
{
	RemoveEffect("TutorialWipf", this);
	AddEffect("IntActivity", this, 1, 10, this);
	return;
}

protected func FxTutorialWipfStart(object target, proplist effect, int temp)
{
	if (temp)
		return FX_OK;
	effect.sequence = "WaitABit";
	this.Collectible = false;	
	return FX_OK;
}

protected func FxTutorialWipfTimer(object target, proplist effect, int time)
{
	// Wait a bit to start walking.
	if (effect.sequence == "WaitABit" && time >= 20)
	{
		SetAction("Walk");
		SetCommand("MoveTo", nil, 700, 388);
		effect.sequence = "WalkToGrainField";
	}
	// Walk to statue and wait there.
	if (effect.sequence == "WalkToGrainField" && Inside(GetX(), 680, 720) && Inside(GetY(), 340, 420))
	{
		effect.sequence = "StayAtGrainField";
	}
	if (effect.sequence == "StayAtGrainField")
	{
		// Don't do anything if contained.
		if (Contained())
			return FX_OK;
		if (IsWalking()) 
		{
			if ((GetDir() == DIR_Left || GetComDir() == COMD_Left) && GetX() < 656)
			{
				SetComDir(COMD_Right);
				return FX_OK;
			}
			if ((GetDir() == DIR_Right || GetComDir() == COMD_Right) && GetX() > 832)
			{
				SetComDir(COMD_Left);
				return FX_OK;
			}
			if (!Random(3))
			{
				SetComDir([COMD_Left, COMD_Right][Random(2)]);
				return FX_OK;
			
			}
			// Stop walking from time to time.
			if (!Random(3) && GetComDir() != COMD_Stop)
			{
				SetComDir(COMD_Stop);
				return FX_OK;
			}
			// Start standing when com dir is stop and speed is zero.
			if (GetComDir() == COMD_Stop && GetXDir() == 0)
			{
				SetAction("Stand");
				return FX_OK;
			}
			return FX_OK;
		}
		if (IsStanding())
		{
			if (!Random(10))
			{
				SetAction("Walk");
				SetComDir([COMD_Left, COMD_Right][Random(2)]);
				return FX_OK;
			}
			return FX_OK;
		}
	}	
	return FX_OK;
}

protected func FxTutorialWipfStop(object target, proplist effect, int reason, bool temp)
{
	if (temp)
		return FX_OK;
	this.Collectible = true;
	return FX_OK;
}