Difference between revisions of "Manual:DIL Manual/UNIT ST PC and UNIT ST NPC"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = UNIT_ST_PC and UNIT_ST_NPC = | |
| − | + | '''Constants''' (integer, vme.h: 0x02 and 0x01). | |
| − | + | Characters: players (<code>UNIT_ST_PC</code>) and monsters (<code>UNIT_ST_NPC</code>). Test for both with <code>u.type & (UNIT_ST_PC | UNIT_ST_NPC)</code>; the same mask works in <code>foreach</code> and <code>findunit()</code>. The type of a unit is in its <code>type</code> field; the four unit types are bits, so they can be combined with <code>|</code>. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | < | ||
| − | |||
| − | + | == Fields == | |
| − | + | Every character has: [[Manual:DIL Manual/abilities|abilities]], [[Manual:DIL Manual/attack type|attack_type]], [[Manual:DIL Manual/charflags|charflags]], [[Manual:DIL Manual/defensive|defensive]], [[Manual:DIL Manual/endurance|endurance]], [[Manual:DIL Manual/exp|exp]], [[Manual:DIL Manual/exptol|exptol]], [[Manual:DIL Manual/fighting|fighting]], [[Manual:DIL Manual/follower|follower]], [[Manual:DIL Manual/followercount|followercount]], [[Manual:DIL Manual/level|level]], [[Manual:DIL Manual/mana|mana]], [[Manual:DIL Manual/master|master]], [[Manual:DIL Manual/max endurance|max_endurance]], [[Manual:DIL Manual/max mana|max_mana]], [[Manual:DIL Manual/natural armour|natural_armour]], [[Manual:DIL Manual/offensive|offensive]], [[Manual:DIL Manual/opponentcount|opponentcount]], [[Manual:DIL Manual/position|position]], [[Manual:DIL Manual/race|race]], [[Manual:DIL Manual/sex|sex]], [[Manual:DIL Manual/speed|speed]], [[Manual:DIL Manual/switched|switched]], [[Manual:DIL Manual/weapons|weapons]]. Players have more fields (see [[Manual:DIL Manual/UNIT ST PC|UNIT_ST_PC]]), and monsters two of their own (see [[Manual:DIL Manual/UNIT ST NPC|UNIT_ST_NPC]]). | |
| − | + | ||
| − | + | == Notes == | |
| − | + | * Every unit, whatever its type, has the general fields: [[Manual:DIL Manual/name|name]], [[Manual:DIL Manual/names|names]], [[Manual:DIL Manual/title|title]], [[Manual:DIL Manual/descr|descr]], [[Manual:DIL Manual/outside descr|outside_descr]], [[Manual:DIL Manual/inside descr|inside_descr]], [[Manual:DIL Manual/extra|extra]], [[Manual:DIL Manual/type|type]], [[Manual:DIL Manual/symname|symname]], [[Manual:DIL Manual/nameidx|nameidx]], [[Manual:DIL Manual/zoneidx|zoneidx]], [[Manual:DIL Manual/zone|zone]], [[Manual:DIL Manual/key|key]], [[Manual:DIL Manual/outside|outside]], [[Manual:DIL Manual/inside|inside]], [[Manual:DIL Manual/next|next]], [[Manual:DIL Manual/gnext|gnext]], [[Manual:DIL Manual/gprevious|gprevious]], [[Manual:DIL Manual/flags|flags]], [[Manual:DIL Manual/manipulate|manipulate]], [[Manual:DIL Manual/openflags|openflags]], [[Manual:DIL Manual/opendiff|opendiff]], [[Manual:DIL Manual/weight|weight]], [[Manual:DIL Manual/baseweight|baseweight]], [[Manual:DIL Manual/capacity|capacity]], [[Manual:DIL Manual/height|height]], [[Manual:DIL Manual/light|light]], [[Manual:DIL Manual/bright|bright]], [[Manual:DIL Manual/illum|illum]], [[Manual:DIL Manual/minv|minv]], [[Manual:DIL Manual/alignment|alignment]], [[Manual:DIL Manual/hp|hp]], [[Manual:DIL Manual/max hp|max_hp]], [[Manual:DIL Manual/loadcount|loadcount]], [[Manual:DIL Manual/hasfunc|hasfunc]], [[Manual:DIL Manual/spells|spells]]. | |
| − | + | * <code>dex_red</code> compiles but has no value: reading it stops the program with "unknown field type" in the log. | |
| − | + | * <code>spells[]</code> exists on every unit, but holds spell skills only on characters. | |
| − | + | * Reading a field the unit doesn't have fails, and a failed value is false in every comparison: test the type first. | |
| − | + | ||
| − | + | == Example == | |
| − | + | <pre> | |
| − | + | dilbegin countchars(); | |
| − | + | var | |
| − | + | u : unitptr; | |
| − | + | n : integer; | |
| − | + | code | |
| − | + | { | |
| − | + | n := 0; | |
| − | + | foreach (UNIT_ST_PC | UNIT_ST_NPC, u) | |
| − | + | n := n + 1; | |
| − | + | log(itoa(n) + " characters around " + self.name); | |
| − | + | quit; | |
| − | + | } | |
| − | + | dilend | |
| − | + | </pre> | |
| − | + | Counts the players and monsters around the unit. | |
| − | + | ||
| − | + | == See also == | |
| − | + | * [[Manual:DIL Manual/type|type]] | |
| − | + | * [[Manual:DIL Manual/Fields|Fields]] | |
| − | + | * [[Manual:DIL Manual/UNIT ST PC|UNIT_ST_PC]] | |
| − | + | * [[Manual:DIL Manual/UNIT ST NPC|UNIT_ST_NPC]] | |
| − | + | * [[Manual:DIL Manual/UNIT ST OBJ|UNIT_ST_OBJ]] | |
| − | + | * [[Manual:DIL Manual/UNIT ST ROOM|UNIT_ST_ROOM]] | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
Latest revision as of 23:24, 14 November 2026
UNIT_ST_PC and UNIT_ST_NPC
Constants (integer, vme.h: 0x02 and 0x01).
Characters: players (UNIT_ST_PC) and monsters (UNIT_ST_NPC). Test for both with u.type & (UNIT_ST_PC | UNIT_ST_NPC); the same mask works in foreach and findunit(). The type of a unit is in its type field; the four unit types are bits, so they can be combined with |.
Fields
Every character has: abilities, attack_type, charflags, defensive, endurance, exp, exptol, fighting, follower, followercount, level, mana, master, max_endurance, max_mana, natural_armour, offensive, opponentcount, position, race, sex, speed, switched, weapons. Players have more fields (see UNIT_ST_PC), and monsters two of their own (see UNIT_ST_NPC).
Notes
- Every unit, whatever its type, has the general fields: name, names, title, descr, outside_descr, inside_descr, extra, type, symname, nameidx, zoneidx, zone, key, outside, inside, next, gnext, gprevious, flags, manipulate, openflags, opendiff, weight, baseweight, capacity, height, light, bright, illum, minv, alignment, hp, max_hp, loadcount, hasfunc, spells.
dex_redcompiles but has no value: reading it stops the program with "unknown field type" in the log.spells[]exists on every unit, but holds spell skills only on characters.- Reading a field the unit doesn't have fails, and a failed value is false in every comparison: test the type first.
Example
dilbegin countchars();
var
u : unitptr;
n : integer;
code
{
n := 0;
foreach (UNIT_ST_PC | UNIT_ST_NPC, u)
n := n + 1;
log(itoa(n) + " characters around " + self.name);
quit;
}
dilend
Counts the players and monsters around the unit.