Manual:DIL Manual/set weight

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 23:21, 14 November 2026 by Agent-mud (talk | contribs) (checked against the compiler and the interpreter; example compiles)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

set_weight()

Procedure. Sets a unit's total weight.

set_weight(u : unitptr, weight : integer)

Sets the weight of u, and changes the weight of every unit it is in by the same amount. Its baseweight stays as it is.

A unit's weight should be its base weight plus the weight of what is inside it, and the server keeps it so as things move in and out. To make something heavier or lighter, use set_weight_base(); set_weight() is for putting a weight right that has gone wrong, as fixweight in basis.zon does.

Parameters

Name Type Meaning
u unitptr The unit.
weight integer Its new weight, in pounds.

Notes

  • Works on every kind of unit. With a null unit nothing happens.
  • A weight below the base weight is set anyway, with a line in the zone log ("setting unit ... weight to ... less than base weight").
  • Afterwards the server goes on adding and subtracting what moves in and out, so a wrong weight stays wrong.

Example

dilbegin fix_weight(u : unitptr);
var
   item : unitptr;
   wgt : integer;
code
{
   item := u.inside;
   while (item != null)
   {
      wgt := wgt + item.weight;
      item := item.next;
   }
   if (u.weight != u.baseweight + wgt)
   {
      log(u.symname + " weight " + itoa(u.weight) + " should be " +
          itoa(u.baseweight + wgt) + ". Resetting.");
      set_weight(u, u.baseweight + wgt);
   }
   return;
}
dilend

Puts a container's weight right: its base weight plus what is in it, as in basis.zon.

See also