File: Script.c

package info (click to toggle)
openclonk 8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 169,484 kB
  • sloc: cpp: 180,478; ansic: 108,988; xml: 31,371; python: 1,223; php: 767; makefile: 139; sh: 101
file content (54 lines) | stat: -rw-r--r-- 1,556 bytes parent folder | download | duplicates (5)
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
/**
	AI Appearance
	Functionality that helps the AI to display messages, make sounds, etc.
	
	@author Maikel
*/


// AI Settings.
local AttackMessageWaitTime = 36 * 30; // Number of frames between displaying an attack message.
local AttackMessageRate = 80; // Likelihood of displaying an attack message in percent (0 - 100).


public func ExecuteAppearance(effect fx)
{
	// Do a random attack message.
	if (!Random(5) && Random(100) >= 100 - fx->GetControl().AttackMessageRate)
		this->ExecuteAttackMessage(fx);
	return true;
}

// Shows an attack message if in a group of AI and is attacking.
public func ExecuteAttackMessage(effect fx)
{
	// Only if close to the target.
	if (fx.Target->ObjectDistance(fx.target) > 150)
		return true;
	// Find other AI enemies that attack together.
	var group_cnt = 0;
	for (var clonk in fx.Target->FindObjects(Find_OCF(OCF_CrewMember), Find_Distance(40), Find_Owner(fx.Target->GetOwner())))
	{
		var ai = clonk->~GetAI();
		if (!ai)
			continue;
		if (ai.last_message != nil && FrameCounter() - ai.last_message < fx->GetControl().AttackMessageWaitTime)
			continue;
		group_cnt++;
	}
	// Display a message if group is big enough.
	if (group_cnt >= RandomX(3, 6))
	{
		fx.Target->Sound("Clonk::Action::GroupAttack");
		fx.Target->Message(Translate(Format("MsgAttack%d", Random(5))));
		fx.last_message = FrameCounter();
	}
	return true;
}

// Shows a message when an intruder is spotted.
public func ExecuteIntruderMessage(effect fx)
{
	fx.Target->Message(Translate(Format("MsgIntruder%d", Random(3))));
	return true;
}