colobot-data/help/cbot/E/radar.txt

83 lines
4.5 KiB
Plaintext

\b;Instruction \c;radar\n;
With the instruction \c;radar();\n;, you can look for objects like \l;enemies\u object\mother;, bots, buildings or raw materials.
\b;Basic use
Write in brackets the \l;name of the object\u cbot\category; that you look for. Put the result in a variable of the \l;type\u cbot\type; \c;object\n;. Here is an example that looks for the closest ant:
\c;
\s;// At the beginning of the program:
\s;object item; // variable declaration
\s;
\s;// Look for the closest ant
\s;item = radar(AlienAnt);
\n;
\b;For specialists
Syntax:
\s;\c;radar ( cat, angle, focus, min, max, sens, filter );\n;
Detects an object according to several parameters.
\image radar1 8 8;
Seen from above, the purple zone corresponds to the zone where objects will be detected.
\t;cat: \c;\l;int\u cbot\int;\n;
o \l;Category\u cbot\category; of the objects that should be detected. For example, when you are looking for an ant, write \c;radar(AlienAnt)\n;.
o \l;Array\u cbot\array; of categories of the objects that should be detected. For example, when you are looking only for grabbers:
\c;\s;int bots[4];
\s;bots[0] = WheeledGrabber;
\s;bots[1] = TrackedGrabber;
\s;bots[2] = WingedGrabber;
\s;bots[3] = LeggedGrabber;
\s;object nearestGrabber = radar(bots);\n;
o Keyword \const;Any\norm; if you are looking for any object (including even plants and so on). Filters may be useful to use with this keyword.
\t;angle: \c;\l;float\u cbot\float;\n; (default value: \c;0\n;)
Direction that the radar is facing, in degrees.
\c; 0\n; -> radar is facing straight ahead
\c;-90\n; -> radar is facing a quarter turn right
\c; 90\n; -> radar is facing a quarter turn left
\t;focus: \c;\l;float\u cbot\float;\n; (default value: \c;360\n;)
Opening angle of the radar, in degrees.
\t;min: \c;\l;float\u cbot\float;\n; (default value: \c;0\n;)
Minimum detection distance, in meters. Objects that are closer than the minimum distance will not be detected.
\t;max: \c;\l;float\u cbot\float;\n; (default value: \c;1000\n;)
Maximum detection distance, in meters. Objects that are farther away than the maximum distance will not be detected.
\t;sens: \c;\l;float\u cbot\float;\n; (default value: \c;1\n;)
Determines which way the objects are detected. With value \c;1\n;, returns the closest object found in the specified zone. With value \c;-1\n;, the farthest object in the zone will be returned.
\t;filter: \c;\l;int\u cbot\int;\n; (default value: \c;\const;FilterNone\norm;\n;)
Determines which type of objects should be detected. Especially useful in use with an \l;array\u cbot\array; or \const;Any\norm;. The following filters are available:
\c;\const;FilterNone\norm; \n;Detects everything (default)
\c;\const;FilterOnlyLanding\norm; \n;Detects only objects being on the ground
\c;\const;FilterOnlyFlying\norm; \n;Detects only objects not being on the ground
\c;\const;FilterFriendly\norm; \n;Detects only allies (objects in the same team)
\c;\const;FilterEnemy\norm; \n;Detects only enemies (objects in an other team except neutral)
\c;\const;FilterNeutral\norm; \n;Detects only neutral objects (e.g. resources)
The last three are mainly useful in \l;code battles\u battles;. You can also pass a team ID to search only for objects from a specific team. Attention: you should use \const;FilterNeutral\norm; instead of \c;0\n; or else it will not work.
Filters and IDs can be mixed using bitwise OR operator \c;|\n;, for example \c;radar(Any, 0, 360, 0, 1000, 1, 2 | FilterOnlyLanding);\n; will only detect an object from team \c;2\n; that is on the ground. Attention: you can specify only one team ID at once, but you can specify several filters at once.
\t;Return value: \c;\l;object\u cbot\object;\n;
Returns the first object found that corresponds to the specified category in the specified zone. If no object was found, returns the value \c;\l;null\u cbot\null;\n;.
\t;Remark
You do not have to give all the parameters. Here are two examples of instructions that are equivalent:
\c;
\s; radar(Titanium, 0, 360, 0, 1000);
\s; radar(Titanium); // equivalent
\s; radar(Titanium, 0, 90, 0, 1000);
\s; radar(Titanium, 0, 90); // equivalent
\n;
When one or more parameters are not specified, the default values indicated above are used instead; only the first parameter is compulsory.
Generally, only the first parameter is specified: f. ex. \c;radar (AlienAnt)\n; detects the closest ant, wherever it may be.
\t;See also
\c;\l;radarall\u cbot\radarall;();\n;, \l;programming\u cbot;, \l;types\u cbot\type; and \l;categories\u cbot\category;.