nightmare3_fluffos_v2/
nightmare3_fluffos_v2/bin/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/ChangeLog.old/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/Win32/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/compat/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/compat/simuls/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/include/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/clone/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/command/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/data/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/etc/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/include/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/inherit/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/inherit/master/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/log/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/single/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/single/tests/compiler/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/single/tests/efuns/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/single/tests/operators/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/u/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/tmp/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/windows/
nightmare3_fluffos_v2/lib/cmds/ambassador/
nightmare3_fluffos_v2/lib/cmds/database/
nightmare3_fluffos_v2/lib/cmds/hm/
nightmare3_fluffos_v2/lib/cmds/soul/
nightmare3_fluffos_v2/lib/daemon/cfg/
nightmare3_fluffos_v2/lib/daemon/cfg/mon_races/
nightmare3_fluffos_v2/lib/daemon/cfg/races/
nightmare3_fluffos_v2/lib/daemon/include/
nightmare3_fluffos_v2/lib/daemon/save/
nightmare3_fluffos_v2/lib/daemon/services/
nightmare3_fluffos_v2/lib/daemon/soul/
nightmare3_fluffos_v2/lib/doc/
nightmare3_fluffos_v2/lib/doc/TestPlans/
nightmare3_fluffos_v2/lib/doc/approval/
nightmare3_fluffos_v2/lib/doc/approval/QC/
nightmare3_fluffos_v2/lib/doc/approval/balance/
nightmare3_fluffos_v2/lib/doc/build/
nightmare3_fluffos_v2/lib/doc/build/armours/
nightmare3_fluffos_v2/lib/doc/build/economy/
nightmare3_fluffos_v2/lib/doc/build/etc/
nightmare3_fluffos_v2/lib/doc/build/monster/
nightmare3_fluffos_v2/lib/doc/build/room/
nightmare3_fluffos_v2/lib/doc/build/virtual/
nightmare3_fluffos_v2/lib/doc/build/weapon/
nightmare3_fluffos_v2/lib/doc/classes/
nightmare3_fluffos_v2/lib/doc/efun/
nightmare3_fluffos_v2/lib/doc/etc/
nightmare3_fluffos_v2/lib/doc/help/creator/
nightmare3_fluffos_v2/lib/doc/help/hm/
nightmare3_fluffos_v2/lib/doc/law/
nightmare3_fluffos_v2/lib/doc/lpc/basic/
nightmare3_fluffos_v2/lib/doc/lpc/data_types/
nightmare3_fluffos_v2/lib/doc/lpc/etc/
nightmare3_fluffos_v2/lib/doc/lpc/intermediate/
nightmare3_fluffos_v2/lib/doc/lpc/types/
nightmare3_fluffos_v2/lib/doc/mudlib/
nightmare3_fluffos_v2/lib/doc/mudlib/features/
nightmare3_fluffos_v2/lib/domains/Examples/etc/
nightmare3_fluffos_v2/lib/domains/Examples/room/
nightmare3_fluffos_v2/lib/domains/Examples/virtual/
nightmare3_fluffos_v2/lib/domains/Examples/virtual/exaA/
nightmare3_fluffos_v2/lib/domains/Examples/virtual/exaB/
nightmare3_fluffos_v2/lib/domains/Examples/weapon/
nightmare3_fluffos_v2/lib/domains/Praxis/
nightmare3_fluffos_v2/lib/domains/Praxis/adm/
nightmare3_fluffos_v2/lib/domains/Praxis/attic/
nightmare3_fluffos_v2/lib/domains/Praxis/cemetary/
nightmare3_fluffos_v2/lib/domains/Praxis/cemetary/mon/
nightmare3_fluffos_v2/lib/domains/Praxis/data/
nightmare3_fluffos_v2/lib/domains/Praxis/death/
nightmare3_fluffos_v2/lib/domains/Praxis/mountains/
nightmare3_fluffos_v2/lib/domains/Praxis/obj/armour/
nightmare3_fluffos_v2/lib/domains/Praxis/obj/magic/
nightmare3_fluffos_v2/lib/domains/Praxis/obj/weapon/
nightmare3_fluffos_v2/lib/domains/Praxis/orc_valley/
nightmare3_fluffos_v2/lib/domains/Praxis/quests/
nightmare3_fluffos_v2/lib/domains/Praxis/standardOld/
nightmare3_fluffos_v2/lib/include/
nightmare3_fluffos_v2/lib/log/
nightmare3_fluffos_v2/lib/log/errors/
nightmare3_fluffos_v2/lib/log/reports/
nightmare3_fluffos_v2/lib/log/watch/
nightmare3_fluffos_v2/lib/news/
nightmare3_fluffos_v2/lib/secure/cfg/
nightmare3_fluffos_v2/lib/secure/cmds/ambassador/
nightmare3_fluffos_v2/lib/secure/cmds/mortal/
nightmare3_fluffos_v2/lib/secure/save/users/d/
nightmare3_fluffos_v2/lib/secure/std/
nightmare3_fluffos_v2/lib/std/hm/
nightmare3_fluffos_v2/lib/std/living/
nightmare3_fluffos_v2/lib/std/room/
nightmare3_fluffos_v2/lib/std/user/
nightmare3_fluffos_v2/lib/std/virtual/
nightmare3_fluffos_v2/lib/www/
nightmare3_fluffos_v2/lib/www/errors/
nightmare3_fluffos_v2/lib/www/gateways/
nightmare3_fluffos_v2/win32/
// File:       /adm/alchemist.c
// Purpose:    Store material properties
//             Setup objects (initialise their properties)
//             This object is also inherited by domain master objects
// Mudlib:     Nightmare
// Author:     Douglas Reay (Pallando @ Ephemeral Dales, Nightmare, etc)
// 93-06-08:   Based on alchemist written by Pallando@FR mud
//             and using the prop_logic seperated by Pallando@TMI-2
// 93-06-16:   Pallando added temperature setting

#include <daemons.h>
#include <materials.h>

inherit "/std/prop_logic";

static string *props;      // Names of properties all objects must have
static int num_props;      // number of properties in the above array
       mapping properties; // Values of those properties for each material
static string save_file;   // place where the data for the above mapping is kept

mixed get( string property )
{
  mixed parts, value, tmp;
  int size, loop;

  parts = explode( property, "/" );
  size = sizeof( parts );
  if( !mapp( value = properties[parts[0]] ) ) return value;
  for( loop = 1 ; ( loop < size ) && mapp( value ) ; loop++ )
  {
    // Allows default values.  Eg: if we are trying to find the density of lead
    // but that hasn't been set, it will use the default metal density instead
    if( undefinedp( tmp = value[parts[loop]] ) &&
        undefinedp( tmp = value["default"]   )   )
      return mapp( value ) ? tmp : value;
    value = tmp;
  }
  return value;
}

mixed query( string property )
{
  mixed value;

  if( !undefinedp( value = get( property ) ) ) return value;
  return ALCHEMIST_D-> get( property );
}

void init_properties()
{
  string file, property;
  mixed value;
  string *lines;
  int size, loop, tmp;

  properties = ([]);
  if( ( 0    > file_size( save_file+".t" ) ) ||
     !( file = read_file( save_file+".t" ) ) ||
     !( lines = explode( file, "\n" )      ) ||
     !( size = sizeof( lines )             )   ) return;
  properties = allocate_mapping( size );
  for( loop = 0 ; loop < size ; loop++ )
  {
    if( sscanf( lines[loop], "%s;%s", property, value ) < 2 ) continue;
    if( sscanf( value, "%d", tmp ) ) value = tmp;
    // Defined in /std/prop_logic
    // Just does properties[property]=value in a heirachic way (see the .o)
    _set( properties, explode( property, "/" ), value );
  }
  save_object( save_file );
}

// During reboots the data is saved in a .o file.
// It only needs to be calculated from the .t when that file is changed
void create()
{
  // Inheriting d_masters use different save files.
  if( !save_file ) save_file = "/data/properties";
  restore_object( save_file );
  if( properties ) return;
  init_properties();
}

// This function is called from set_material() in /std/Object
// Inheriting domain master obs can set props in create or in their
// setup_object function, before doing ::setup_object()
void setup_object( object ob, object pobj )
{
  string material, name, type;
  int mass, temperature, loop;

  if( !props )
  {
    props = MATERIAL_PROPS;
    num_props = sizeof( props );
  }
  type = (string)ob-> query( "material_type" );
  if( !type || -1 == member_array( type, MATERIAL_TYPES ) )
  {
    // Log the event here for QC
    return;
  }
  if( !( name = (string)ob-> query( "material_name" ) ) )
  {
    // Log the event here for QC
    return;
  }
  material = "/"+type+"/"+name;
  for( loop = 0 ; loop < num_props ; loop++ )
    ob-> set( props[loop], query( props[loop] + material ) );
  if( !( mass = (int)ob-> query( "mass" ) ) )
  {
    // Log the event here for QC
    return;
  }
  // Until set_weight() is removed.
  ob-> set_weight( mass );
  ob-> set( "volume", 1000 * mass / ( (int)ob-> query( "density" ) ) );
  if( !pobj ) return;
  if( !function_exists( "query", pobj ) ||
      undefinedp( temperature = pobj-> query( "temperature" ) ) )
    temperature = query( "temperature/default" );
  ob-> set( "temperature", temperature );
}