1 | // Returns an command suitable for ProcessCommand() based on the rally point data.
|
---|
2 | // This assumes that the rally point has a valid position.
|
---|
3 | function getRallyPointCommand(cmpRallyPoint, spawnedEnts)
|
---|
4 | {
|
---|
5 | // Look and see if there is a command in the rally point data, otherwise just walk there.
|
---|
6 | var data = cmpRallyPoint.GetData();
|
---|
7 | var rallyPos = cmpRallyPoint.GetPosition();
|
---|
8 | var command = undefined;
|
---|
9 | if (data && data.command)
|
---|
10 | {
|
---|
11 | command = data.command;
|
---|
12 | }
|
---|
13 | else
|
---|
14 | {
|
---|
15 | command = "walk";
|
---|
16 | }
|
---|
17 |
|
---|
18 | // If a target was set and the target no longer exists them just walk to the rally point.
|
---|
19 | if (data && data.target)
|
---|
20 | {
|
---|
21 | if (! Engine.QueryInterface(data.target, IID_Position))
|
---|
22 | {
|
---|
23 | command = "walk";
|
---|
24 | }
|
---|
25 | }
|
---|
26 |
|
---|
27 | switch (command)
|
---|
28 | {
|
---|
29 | case "gather":
|
---|
30 | return {
|
---|
31 | "type": "gatherNearPosition",
|
---|
32 | "entities": spawnedEnts,
|
---|
33 | "x": rallyPos.x,
|
---|
34 | "z": rallyPos.z,
|
---|
35 | "resourceType": data.resourceType,
|
---|
36 | "queued": false
|
---|
37 | };
|
---|
38 | break;
|
---|
39 | case "repair":
|
---|
40 | case "build":
|
---|
41 | return {
|
---|
42 | "type": "repair",
|
---|
43 | "entities": spawnedEnts,
|
---|
44 | "target": data.target,
|
---|
45 | "queued": false,
|
---|
46 | "autocontinue": true
|
---|
47 | };
|
---|
48 | break;
|
---|
49 | case "garrison":
|
---|
50 | return {
|
---|
51 | "type": "garrison",
|
---|
52 | "entities": spawnedEnts,
|
---|
53 | "target": data.target,
|
---|
54 | "queued": false
|
---|
55 | };
|
---|
56 | }
|
---|
57 |
|
---|
58 | // default return value
|
---|
59 | return {
|
---|
60 | "type": "walk",
|
---|
61 | "entities": spawnedEnts,
|
---|
62 | "x": rallyPos.x,
|
---|
63 | "z": rallyPos.z,
|
---|
64 | "queued": false
|
---|
65 | };
|
---|
66 | }
|
---|
67 |
|
---|
68 | Engine.RegisterGlobal("getRallyPointCommand", getRallyPointCommand);
|
---|