Manual:DIL Manual/getopponent()
Jump to navigation
Jump to search
getopponent()
Function (unitptr). Gets one of a character's opponents by its place in the list.
getopponent(ch : unitptr, i : integer)
A character in a fight has a list of opponents: everyone fighting it and everyone it fights. The list is in the order they joined the fight, from 0 to ch.opponentcount - 1. Only one of them is the melee target, in fighting.
Parameters
| Name | Type | Meaning |
|---|---|---|
| ch | unitptr | The character in the fight. |
| i | integer | The place in the list, from 0. |
Returns
The opponent at place i, or null when i is negative or not below ch.opponentcount.
Notes
- Check
ch.opponentcountfirst. Whenchis not fighting anyone (opponentcount 0) or is null, the function gives an error instead of null:u := getopponent(ch, 0)then writes "DIL SERIOUS: ... Type error in unit assignemt" to the zone log and the program stops. - When
chis not a character (an object or a room) it fails, and an assignment of it leaves the variable as it was. - A character can have opponents while
fightingis null: someone attacks it from a distance, or its melee target has left. baselook.zon shows such a fighter as fighting "at a distance". - Opponents always come in pairs; see opponent().
Example
dilbegin string opponent_names(u : unitptr);
var
i : integer;
o : unitptr;
s : string;
code
{
if ((u == null) or (u.opponentcount < 1))
return ("nobody");
i := 0;
while (i < u.opponentcount)
{
o := getopponent(u, i);
if (o != null)
{
if (s != "")
s := s + ", ";
s := s + o.name;
}
i := i + 1;
}
return (s);
}
dilend
Lists the names of everyone a character is fighting.