Difference between revisions of "Manual:DIL Manual/visible()"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = visible() = | |
| − | + | '''Function''' (integer). Tells whether a character can see a unit. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | visible(ch : unitptr, u : unitptr) | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | The same test the game uses when it decides whether a character sees someone or something: blindness, light, invisibility, wizard invisibility and burial count. It doesn't check where the unit is: a unit in another room can be "visible". | |
| + | |||
| + | == Parameters == | ||
| + | {| class="wikitable" | ||
| + | ! Name !! Type !! Meaning | ||
| + | |- | ||
| + | | ch || unitptr || The character who looks (a player or an NPC). | ||
| + | |- | ||
| + | | u || unitptr || The unit looked at: a character, an object or a room. | ||
| + | |} | ||
| + | |||
| + | == Returns == | ||
| + | TRUE when <code>ch</code> can see <code>u</code>, otherwise FALSE. It fails when <code>ch</code> is null or not a character, or <code>u</code> is null; a failed value is false in an <code>if</code>, so <code>not visible(...)</code> is then true. | ||
| + | |||
| + | == Notes == | ||
| + | <code>ch</code> sees <code>u</code> when all of these hold: | ||
| + | * <code>ch</code> is not blind (<code>CHAR_BLIND</code>). This holds for gods too. | ||
| + | * <code>u</code> is not buried (<code>UNIT_FL_BURIED</code>), unless <code>ch</code> is inside <code>u</code>. | ||
| + | * <code>ch</code>'s level is at least <code>u</code>'s wizard invisibility level ([[Manual:DIL Manual/minv|minv]]). | ||
| + | * <code>ch</code> is a creator (level 230 or more), or else both: the place <code>ch</code> is in is lit, and <code>u</code> is not invisible (<code>UNIT_FL_INVISIBLE</code>) or <code>ch</code> has <code>CHAR_DETECT_INVISIBLE</code>. | ||
| + | The light that counts is where <code>ch</code> is, not where <code>u</code> is. Hiding and sneaking are not part of this test. | ||
| + | |||
| + | == Example == | ||
| + | <pre> | ||
| + | dilbegin unitptr find_evil(); | ||
| + | var | ||
| + | u : unitptr; | ||
| + | found : unitptr; | ||
| + | code | ||
| + | { | ||
| + | foreach (UNIT_ST_PC | UNIT_ST_NPC, u) | ||
| + | { | ||
| + | if ((u != self) and visible(self, u) and (u.alignment <= -350)) | ||
| + | { | ||
| + | found := u; | ||
| + | break; | ||
| + | } | ||
| + | } | ||
| + | return (found); | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | Finds an evil character in the room that the NPC can see, as the guards in justice.zon do. | ||
| + | |||
| + | == See also == | ||
| + | * [[Manual:DIL Manual/minv|minv]] | ||
| + | * [[Manual:DIL Manual/flags|flags]] | ||
| + | * [[Manual:DIL Manual/charflags|charflags]] | ||
| + | * [[Manual:DIL Manual/islight()|islight()]] | ||
| + | * [[Manual:DIL Manual/light|light]] | ||
Latest revision as of 23:08, 14 November 2026
visible()
Function (integer). Tells whether a character can see a unit.
visible(ch : unitptr, u : unitptr)
The same test the game uses when it decides whether a character sees someone or something: blindness, light, invisibility, wizard invisibility and burial count. It doesn't check where the unit is: a unit in another room can be "visible".
Parameters
| Name | Type | Meaning |
|---|---|---|
| ch | unitptr | The character who looks (a player or an NPC). |
| u | unitptr | The unit looked at: a character, an object or a room. |
Returns
TRUE when ch can see u, otherwise FALSE. It fails when ch is null or not a character, or u is null; a failed value is false in an if, so not visible(...) is then true.
Notes
ch sees u when all of these hold:
chis not blind (CHAR_BLIND). This holds for gods too.uis not buried (UNIT_FL_BURIED), unlesschis insideu.ch's level is at leastu's wizard invisibility level (minv).chis a creator (level 230 or more), or else both: the placechis in is lit, anduis not invisible (UNIT_FL_INVISIBLE) orchhasCHAR_DETECT_INVISIBLE.
The light that counts is where ch is, not where u is. Hiding and sneaking are not part of this test.
Example
dilbegin unitptr find_evil();
var
u : unitptr;
found : unitptr;
code
{
foreach (UNIT_ST_PC | UNIT_ST_NPC, u)
{
if ((u != self) and visible(self, u) and (u.alignment <= -350))
{
found := u;
break;
}
}
return (found);
}
dilend
Finds an evil character in the room that the NPC can see, as the guards in justice.zon do.