Difference between revisions of "Manual:DIL Manual/UNIT ST PC and UNIT ST NPC"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
−
<span id="upcnpc"></span>
+
= UNIT_ST_PC and UNIT_ST_NPC =
−
'''if the type is UNIT_ST_PC or UNIT_ST_NPC '''
+
'''Constants''' (integer, vme.h: 0x02 and 0x01).
  
−
      'speed'        :integer (RO)
+
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>.
−
          The current default combat-speed (as seen by wstat)
 
−
      'fighting'    :unitptr (RO)
 
−
          The unit the PC/NPC is fighting.
 
−
      'master'      :unitptr (RO)
 
−
          The unit the PC/NPC is following.
 
−
      'follower'    :unitptr (RO)
 
−
          The first follower of a PC/NPC. There is currently no way
 
−
          of finding other followers, except using a foreach loop in
 
−
          the local environment.
 
−
      'exp'          :integer (RO)
 
−
          The number of experience points for PC, or experience
 
−
          quality of monster. The exp can be set by the function
 
−
          'experience()'
 
−
      'charflags'    :integer (RW)
 
−
          Bits specifying by spells affects and other PC/NPC affects,
 
−
          and many other things, see CHAR_* in values.h and/or vme.h
 
−
      'lastroom'    :unitptr (RO)
 
−
          The room the player just left.
 
−
      'mana'        :integer (RW)
 
−
          The amount of mana a PC/CHAR has left.
 
−
      'dex_red'      :integer (RO)
 
−
          The amount of DEX reduction the PC/NPC suffers due to
 
−
          encumbrance or otherwise.
 
−
      'endurance'    :integer (RW)
 
−
          The amount of endurance a PC/NPC has left.
 
−
      'attack_type'  :integer (RW)
 
−
          The non-weapon attack type of a PC/NPC.
 
−
      'race'        :integer (RW)
 
−
          The race of a PC/NPC, see RACE_* in values.h and/or vme.h
 
−
      'sex'          :integer (RW)
 
−
          The sex of a PC/NPC, see SEX_* in values.h and/or vme.h
 
−
      'level'        :integer (RO)
 
−
          The level of a PC/NPC.
 
−
      'position'    :integer (RW)
 
−
          The position of a PC/NPC, see POSITION_* in values.h and/or vme.h
 
−
          affected by the 'position_update()' procedure
 
−
      'abilities'[]  :integer (RO)
 
−
          The abilities of a PC/NPC. Index should be ABIL_* in values.h and/or vme.h
 
−
      'weapons'[]    :integer (RO)
 
−
          The weapon skills of a PC/NPC. Index should be WPN_* in values.h and/or vme.h
 
−
<span id="upcnpc"></span>
 
−
'''if the type is UNIT_ST_PC or UNIT_ST_NPC '''
 
  
−
      'speed'        :integer (RO)
+
== Fields ==
−
          The current default combat-speed (as seen by wstat)
+
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]]).
−
      'fighting'    :unitptr (RO)
+
 
−
          The unit the PC/NPC is fighting.
+
== Notes ==
−
      'master'      :unitptr (RO)
+
* 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]].
−
          The unit the PC/NPC is following.
+
* <code>dex_red</code> compiles but has no value: reading it stops the program with "unknown field type" in the log.
−
      'follower'    :unitptr (RO)
+
* <code>spells[]</code> exists on every unit, but holds spell skills only on characters.
−
          The first follower of a PC/NPC. There is currently no way
+
* Reading a field the unit doesn't have fails, and a failed value is false in every comparison: test the type first.
−
          of finding other followers, except using a foreach loop in
+
 
−
          the local environment.
+
== Example ==
−
      'exp'          :integer (RO)
+
<pre>
−
          The number of experience points for PC, or experience
+
dilbegin countchars();
−
          quality of monster. The exp can be set by the function
+
var
−
          'experience()'
+
  u : unitptr;
−
      'charflags'    :integer (RW)
+
  n : integer;
−
          Bits specifying by spells affects and other PC/NPC affects,
+
code
−
          and many other things, see CHAR_* in values.h and/or vme.h
+
{
−
      'lastroom'    :unitptr (RO)
+
  n := 0;
−
          The room the player just left.
+
  foreach (UNIT_ST_PC | UNIT_ST_NPC, u)
−
      'mana'        :integer (RW)
+
      n := n + 1;
−
          The amount of mana a PC/CHAR has left.
+
   log(itoa(n) + " characters around " + self.name);
−
      'dex_red'      :integer (RO)
+
  quit;
−
          The amount of DEX reduction the PC/NPC suffers due to
+
}
−
          encumbrance or otherwise.
+
dilend
−
      'endurance'   :integer (RW)
+
</pre>
−
          The amount of endurance a PC/NPC has left.
+
Counts the players and monsters around the unit.
−
      'attack_type'  :integer (RW)
+
 
−
          The non-weapon attack type of a PC/NPC.
+
== See also ==
−
      'race'        :integer (RW)
+
* [[Manual:DIL Manual/type|type]]
−
          The race of a PC/NPC, see RACE_* in values.h and/or vme.h
+
* [[Manual:DIL Manual/Fields|Fields]]
−
      'sex'          :integer (RW)
+
* [[Manual:DIL Manual/UNIT ST PC|UNIT_ST_PC]]
−
          The sex of a PC/NPC, see SEX_* in values.h and/or vme.h
+
* [[Manual:DIL Manual/UNIT ST NPC|UNIT_ST_NPC]]
−
      'level'        :integer (RO)
+
* [[Manual:DIL Manual/UNIT ST OBJ|UNIT_ST_OBJ]]
−
          The level of a PC/NPC.
+
* [[Manual:DIL Manual/UNIT ST ROOM|UNIT_ST_ROOM]]
−
      'position'    :integer (RW)
 
−
          The position of a PC/NPC, see POSITION_* in values.h and/or vme.h
 
−
          affected by the 'position_update()' procedure
 
−
      'abilities'[]  :integer (RO)
 
−
          The abilities of a PC/NPC. Index should be ABIL_* in values.h and/or vme.h
 
−
      'weapons'[]    :integer (RO)
 
−
          The weapon skills of a PC/NPC. Index should be WPN_* in values.h and/or vme.h
 

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

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.

See also