File: AttackTarget.c

package info (click to toggle)
openclonk 8.1-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 169,520 kB
  • sloc: cpp: 180,479; ansic: 108,988; xml: 31,371; python: 1,223; php: 767; makefile: 145; sh: 101; javascript: 34
file content (31 lines) | stat: -rw-r--r-- 1,414 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
// Used by the AI to find targets to attack.

global func GetRandomAttackTarget(object attacker)
{
	// First let the scenario tell what to do by a gamecall.
	var target = GameCall("GiveRandomAttackTarget", attacker);
	if (target)
		return target;
	// Attack structures owned by the enemy of the attacker.
	var controller = attacker->GetController();
	for (var target in attacker->FindObjects(Find_Category(C4D_Structure), Find_Hostile(controller), attacker->Sort_Distance()))
		if (target && PathFree(attacker->GetX(), attacker->GetY(), target->GetX(), target->GetY()))
			return target;
	// Otherwise return random enemy structure.
	return FindObject(Find_Category(C4D_Structure), Find_Hostile(controller), Sort_Random());
}

global func GetRandomSiegeTarget(object attacker)
{
	// First let the scenario tell what to do by a gamecall.
	var target = GameCall("GiveRandomSiegeTarget", attacker);
	if (target)
		return target;
	// Attack structures owned by the enemy of the attacker.
	var controller = attacker->GetController();
	for (var target in attacker->FindObjects(Find_Category(C4D_Structure), Find_Hostile(controller), attacker->Sort_Distance()))
		if (target && PathFree(attacker->GetX(), attacker->GetY(), target->GetX(), target->GetY()))
			return target;
	// Otherwise return random enemy structure.
	return attacker->FindObject(Find_Category(C4D_Structure), Find_Hostile(controller), Sort_Random());
}