Beispiel #1
0
/* we add an element to the list of blocks, it is either added to an existing block or in a block specifically created if there was none */
static void insert_elem(tmp_block_t **block_list, unsigned abs_i, unsigned abs_j, float val, unsigned c, unsigned r)
{
	/* we are looking for the block that contains (abs_i, abs_j) (abs = absolute) */
	unsigned i,j;

	i = abs_i / c;
	j = abs_j / r;

	tmp_block_t *block;

	block = search_block(*block_list, i, j);

	if (!block) {
		/* the block does not exist yet */
		/* create it */
		block = create_block(c, r);

		block->i = i;
		block->j = j;
		
		//printf("create block %d %d !\n", i, j);

		/* insert it in the block list */
		insert_block(block, block_list, i, j);
	}

	/* now insert the value in the corresponding block */
	unsigned local_i, local_j, local_index;

	local_i = abs_i % c;
	local_j = abs_j % r;
	local_index = local_j * c + local_i;
	
	block->val[local_index] = val;
}
Beispiel #2
0
void do_wear(struct char_data *ch, char *argument, int cmd) {
char arg1[MAX_STRING_LENGTH];
char arg2[MAX_STRING_LENGTH];
char buf[256];
char buffer[MAX_STRING_LENGTH];
struct obj_data *obj_object;
int keyword;
static char *keywords[] = {
	"finger",
	"neck",
	"body",
	"head",
	"legs",
	"feet",
	"hands",
	"arms",
	"about",
	"waist",
	"wrist",
	"shield",
	"\n"
};

	argument_interpreter(argument, arg1, arg2);
	if (*arg1) {
		obj_object = get_obj_in_list_vis(ch, arg1, ch->carrying);
		if (obj_object) {
			if (*arg2) {
				keyword = search_block(arg2, keywords, FALSE); /* Partial Match */
				if (keyword == -1) {
					sprintf(buf, "%s is an unknown body location.\n\r", arg2);
					send_to_char(buf, ch);
				} else {
					wear(ch, obj_object, keyword+1);
				}
			} else {
				keyword = -2;
        if (CAN_WEAR(obj_object,ITEM_WEAR_SHIELD)) keyword = 14;
				if (CAN_WEAR(obj_object,ITEM_WEAR_FINGER)) keyword = 1;
				if (CAN_WEAR(obj_object,ITEM_WEAR_NECK)) keyword = 2;
				if (CAN_WEAR(obj_object,ITEM_WEAR_WRIST)) keyword = 11;
				if (CAN_WEAR(obj_object,ITEM_WEAR_WAISTE)) keyword = 10;
				if (CAN_WEAR(obj_object,ITEM_WEAR_ARMS)) keyword = 8;
				if (CAN_WEAR(obj_object,ITEM_WEAR_HANDS)) keyword = 7;
				if (CAN_WEAR(obj_object,ITEM_WEAR_FEET)) keyword = 6;
				if (CAN_WEAR(obj_object,ITEM_WEAR_LEGS)) keyword = 5;
				if (CAN_WEAR(obj_object,ITEM_WEAR_ABOUT)) keyword = 9;
				if (CAN_WEAR(obj_object,ITEM_WEAR_HEAD)) keyword = 4;
				if (CAN_WEAR(obj_object,ITEM_WEAR_BODY)) keyword = 3;

				wear(ch, obj_object, keyword);
			}
		} else {
			sprintf(buffer, "You do not seem to have the '%s'.\n\r",arg1);
			send_to_char(buffer,ch);
		}
	} else {
		send_to_char("Wear what?\n\r", ch);
	}
}
Beispiel #3
0
/* generic fn for modifying a bitvector */
void olc_bitvector(int *bv, const char **names, char *arg)
{
  int newbv, flagnum, remove = 0;
  char *this_name;

  skip_spaces(&arg);

  if (!*arg) {
    send_to_char("Flag list or flag modifiers required.\r\n", olc_ch);
    return;
  }
  /* determine if this is 'absolute' or 'relative' mode */
  if (*arg == '+' || *arg == '-')
    newbv = *bv;
  else
    newbv = 0;

  while (*arg) {
    arg = one_argument(arg, buf);	/* get next argument */

    /* change to upper-case */
    for (this_name = buf; *this_name; this_name++)
      CAP(this_name);

    /* determine if this is an add or a subtract */
    if (*buf == '+' || *buf == '-') {
      this_name = buf + 1;
      if (*buf == '-')
	remove = TRUE;
      else
	remove = FALSE;
    } else {
      this_name = buf;
      remove = FALSE;
    }

    /* figure out which one we're dealing with */
    if ((flagnum = search_block(this_name, names, TRUE)) < 0) {
      sprintf(buf2, "Unknown flag: %s\r\n", this_name);
      send_to_char(buf2, olc_ch);
    } else {
      if (remove)
	REMOVE_BIT(newbv, (1 << flagnum));
      else
	SET_BIT(newbv, (1 << flagnum));
    }
  }

  *bv = newbv;
  sprintbit(newbv, names, buf);
  sprintf(buf2, "Flags now set to: %s\r\n", buf);
  send_to_char(buf2, olc_ch);
}
Beispiel #4
0
int find_door(struct char_data *ch, const char *type, char *dir, const char *cmdname)
{
  int door;

  if (*dir) {			/* a direction was specified */
    if ((door = search_block(dir, dirs, FALSE)) == -1) {	/* Partial Match */
      send_to_char("That's not a direction.\r\n", ch);
      return (-1);
    }
    if (EXIT(ch, door)) {	/* Braces added according to indent. -gg */
      if (EXIT(ch, door)->keyword) {
	if (isname(type, EXIT(ch, door)->keyword))
	  return (door);
	else {
	  sprintf(buf2, "I see no %s there.\r\n", type);
	  send_to_char(buf2, ch);
	  return (-1);
        }
      } else
	return (door);
    } else {
      sprintf(buf2, "I really don't see how you can %s anything there.\r\n", cmdname);
      send_to_char(buf2, ch);
      return (-1);
    }
  } else {			/* try to locate the keyword */
    if (!*type) {
      sprintf(buf2, "What is it you want to %s?\r\n", cmdname);
      send_to_char(buf2, ch);
      return (-1);
    }
    for (door = 0; door < NUM_OF_DIRS; door++)
      if (EXIT(ch, door))
	if (EXIT(ch, door)->keyword)
	  if (isname(type, EXIT(ch, door)->keyword))
	    return (door);

    sprintf(buf2, "There doesn't seem to be %s %s here.\r\n", AN(type), type);
    send_to_char(buf2, ch);
    return (-1);
  }
}
Beispiel #5
0
static bool_t spi_flash_unregister(struct resource_t * res)
{
	struct block_t * blk;
	char name[64];

	snprintf(name, sizeof(name), "%s.%d", res->name, res->id);

	blk = search_block(name);
	if(!blk)
		return FALSE;

	if(!unregister_block(blk))
		return FALSE;

	spi_device_free(((struct spi_flash_private_data_t *)blk->priv)->dev);
	free(blk->priv);
	free(blk->name);
	free(blk);
	return TRUE;
}
Beispiel #6
0
static bool_t unregister_application(const char * name)
{
	struct block_t * blk;
	struct application_t * app;

	if(!name)
		return FALSE;

	blk = search_block(name);
	if(!blk)
		return FALSE;

	app = (struct application_t *)(blk->priv);
	if(!unregister_block(blk))
		return FALSE;

	free(app->name);
	free(app);
	free(blk);
	return TRUE;
}
Beispiel #7
0
static bool_t unregister_romdisk(const char * name)
{
	struct block_t * blk;
	struct romdisk_t * romdisk;

	if(!name)
		return FALSE;

	blk = search_block(name);
	if(!blk)
		return FALSE;

	romdisk = (struct romdisk_t *)(blk->priv);
	if(!unregister_block(blk))
		return FALSE;

	free(romdisk->name);
	free(romdisk);
	free(blk);
	return TRUE;
}
Beispiel #8
0
int guild(struct char_data *ch, int cmd, char *arg) {

	char arg1[MAX_STRING_LENGTH];
	char buf[MAX_STRING_LENGTH];
	int number, i, percent;

	extern char *spells[];
	extern struct spell_info_type spell_info[MAX_SPL_LIST];
	extern struct int_app_type int_app[26];

	static char *w_skills[] = {
		"kick",  /* No. 50 */
		"bash",
		"rescue",
		"\n"
	};

	static char *t_skills[] = {
		"sneak",   /* No. 45 */
		"hide",
		"steal",
		"backstab",
		"pick",
		"\n"
	};

	if ((cmd != 164) && (cmd != 170)) return(FALSE);

	for(; *arg==' '; arg++);

	switch (GET_CLASS(ch)) {
		case CLASS_MAGIC_USER :{
			if (!*arg) {
				sprintf(buf,"You have got %d practice sessions left.\n\r", ch->specials.spells_to_learn);
				send_to_char(buf, ch);
				send_to_char("You can practise any of these spells:\n\r", ch);
				for(i=0; *spells[i] != '\n'; i++)
					if (spell_info[i+1].spell_pointer &&
					    (spell_info[i+1].min_level_magic <= GET_LEVEL(ch))) {
						send_to_char(spells[i], ch);
						send_to_char(how_good(ch->skills[i+1].learned), ch);
						send_to_char("\n\r", ch);
				}
				return(TRUE);
			}

			number = old_search_block(arg,0,strlen(arg),spells,FALSE);
			if(number == -1) {
				send_to_char("You do not know of this spell...\n\r", ch);
				return(TRUE);
			}
			if (GET_LEVEL(ch) < spell_info[number].min_level_magic) {
				send_to_char("You do not know of this spell...\n\r", ch);
				return(TRUE);
			}
			if (ch->specials.spells_to_learn <= 0) {
				send_to_char("You do not seem to be able to practice now.\n\r", ch);
				return(TRUE);
			}
			if (ch->skills[number].learned >= 95) {
				send_to_char("You are already learned in this area.\n\r", ch);
				return(TRUE);
			}

			send_to_char("You Practice for a while...\n\r", ch);
			ch->specials.spells_to_learn--;

			percent = ch->skills[number].learned+MAX(25,int_app[GET_INT(ch)].learn);
			ch->skills[number].learned = MIN(95, percent);

			if (ch->skills[number].learned >= 95) {
				send_to_char("You are now learned in this area.\n\r", ch);
				return(TRUE);
			}

		} break;

		case CLASS_THIEF: {
			if (!*arg) {
				sprintf(buf,"You have got %d practice sessions left.\n\r", ch->specials.spells_to_learn);
				send_to_char(buf, ch);
				send_to_char("You can practise any of these skills:\n\r", ch);
				for(i=0; *t_skills[i] != '\n';i++) {
					send_to_char(t_skills[i], ch);
					send_to_char(how_good(ch->skills[i+45].learned), ch);
					send_to_char("\n\r", ch);
				}
				return(TRUE);
			}
			number = search_block(arg,t_skills,FALSE);
			if(number == -1) {
				send_to_char("You do not know of this spell...\n\r", ch);
				return(TRUE);
			}
			if (ch->specials.spells_to_learn <= 0) {
				send_to_char("You do not seem to be able to practice now.\n\r", ch);
				return(TRUE);
			}
			if (ch->skills[number+SKILL_SNEAK].learned >= 85) {
				send_to_char("You are already learned in this area.\n\r", ch);
				return(TRUE);
			}
			send_to_char("You Practice for a while...\n\r", ch);
			ch->specials.spells_to_learn--;

			percent = ch->skills[number+SKILL_SNEAK].learned +
			          MIN(int_app[GET_INT(ch)].learn, 12);
			ch->skills[number+SKILL_SNEAK].learned = MIN(85, percent);

			if (ch->skills[number+SKILL_SNEAK].learned >= 85) {
				send_to_char("You are now learned in this area.\n\r", ch);
				return(TRUE);
			}

		} break;

		case CLASS_CLERIC     :{
			if (!*arg) {
				sprintf(buf,"You have got %d practice sessions left.\n\r", ch->specials.spells_to_learn);
				send_to_char(buf, ch);
				send_to_char("You can practise any of these spells:\n\r", ch);
				for(i=0; *spells[i] != '\n'; i++)
					if (spell_info[i+1].spell_pointer &&
					   (spell_info[i+1].min_level_cleric <= GET_LEVEL(ch))) {
						send_to_char(spells[i], ch);
						send_to_char(how_good(ch->skills[i+1].learned), ch);
						send_to_char("\n\r", ch);
				}
				return(TRUE);
			}
			number = old_search_block(arg,0,strlen(arg),spells,FALSE);
			if(number == -1) {
				send_to_char("You do not know of this spell...\n\r", ch);
				return(TRUE);
			}
			if (GET_LEVEL(ch) < spell_info[number].min_level_cleric) {
				send_to_char("You do not know of this spell...\n\r", ch);
				return(TRUE);
			}
			if (ch->specials.spells_to_learn <= 0) {
				send_to_char("You do not seem to be able to practice now.\n\r", ch);
				return(TRUE);
			}
			if (ch->skills[number].learned >= 95) {
				send_to_char("You are already learned in this area.\n\r", ch);
				return(TRUE);
			}
			send_to_char("You Practice for a while...\n\r", ch);
			ch->specials.spells_to_learn--;

			percent = ch->skills[number].learned+MAX(25,int_app[GET_INT(ch)].learn);
			ch->skills[number].learned = MIN(95, percent);

			if (ch->skills[number].learned >= 95) {
				send_to_char("You are now learned in this area.\n\r", ch);
				return(TRUE);
			}
		} break;

		case CLASS_WARRIOR: {
			if (!*arg) {
				sprintf(buf,"You have got %d practice sessions left.\n\r", ch->specials.spells_to_learn);
				send_to_char(buf, ch);
				send_to_char("You can practise any of these skills:\n\r", ch);
				for(i=0; *w_skills[i] != '\n';i++) {
					send_to_char(w_skills[i], ch);
					send_to_char(how_good(ch->skills[i+SKILL_KICK].learned), ch);
					send_to_char("\n\r", ch);
				}
				return(TRUE);
			}
			number = search_block(arg, w_skills, FALSE);
			if(number == -1) {
				send_to_char("You do not have ability to practise this skill!\n\r", ch);
				return(TRUE);
			}
			if (ch->specials.spells_to_learn <= 0) {
				send_to_char("You do not seem to be able to practice now.\n\r", ch);
				return(TRUE);
			}
			if (ch->skills[number+SKILL_KICK].learned >= 80) {
				send_to_char("You are already learned in this area.\n\r", ch);
				return(TRUE);
			}
			send_to_char("You Practice for a while...\n\r", ch);
			ch->specials.spells_to_learn--;

			percent = ch->skills[number+SKILL_KICK].learned +
			          MIN(12, int_app[GET_INT(ch)].learn);
			ch->skills[number+SKILL_KICK].learned = MIN(80, percent);

			if (ch->skills[number+SKILL_KICK].learned >= 80) {
				send_to_char("You are now learned in this area.\n\r", ch);
				return(TRUE);
			}
		} break;
	}
}
Beispiel #9
0
void assemblyBootAssemblies( void )
{
    char         szLine[ MAX_STRING_LENGTH ] = { '\0' };
    char         szTag[ MAX_STRING_LENGTH ] = { '\0' };
    char         szType[ MAX_STRING_LENGTH ] = { '\0' };
    int          iExtract = 0;
    int          iInRoom = 0;
    int          iType = 0;
    long         lLineCount = 0;
    long         lPartVnum = NOTHING;
    long         lVnum = NOTHING;
    FILE         *pFile = NULL;

    if( (pFile = fopen( ASSEMBLIES_FILE, "rt" )) == NULL )
    {
        log( "SYSERR: assemblyBootAssemblies(): Couldn't open file '%s' for "
             "reading.", ASSEMBLIES_FILE );
        return;
    }

    while( !feof( pFile ) )
    {
        lLineCount += get_line( pFile, szLine );
        half_chop( szLine, szTag, szLine );

        if( *szTag == '\0' )
            continue;

        if( str_cmp( szTag, "Component" ) == 0 )
        {
            if( sscanf( szLine, "#%ld %d %d", &lPartVnum, &iExtract, &iInRoom ) != 3
              )
            {
                log( "SYSERR: bootAssemblies(): Invalid format in file %s, line %ld: "
                     "szTag=%s, szLine=%s.", ASSEMBLIES_FILE, lLineCount, szTag, szLine );
            }
            else if( !assemblyAddComponent( lVnum, lPartVnum, iExtract, iInRoom ) )
            {
                log( "SYSERR: bootAssemblies(): Could not add component #%ld to "
                     "assembly #%ld.", lPartVnum, lVnum );
            }
        }
        else if( str_cmp( szTag, "Vnum" ) == 0 )
        {
            if( sscanf( szLine, "#%ld %s", &lVnum, szType ) != 2 )
            {
                log( "SYSERR: bootAssemblies(): Invalid format in file %s, "
                     "line %ld.", ASSEMBLIES_FILE, lLineCount );
                lVnum = NOTHING;
            }
            else if( (iType = search_block( szType, AssemblyTypes, TRUE )) < 0 )
            {
                log( "SYSERR: bootAssemblies(): Invalid type '%s' for assembly "
                     "vnum #%ld at line %ld.", szType, lVnum, lLineCount );
                lVnum = NOTHING;
            }
            else if( !assemblyCreate( lVnum, iType ) )
            {
                log( "SYSERR: bootAssemblies(): Could not create assembly for vnum "
                     "#%ld, type %s.", lVnum, szType );
                lVnum = NOTHING;
            }
        }
        else
        {
            log( "SYSERR: Invalid tag '%s' in file %s, line #%ld.", szTag,
                 ASSEMBLIES_FILE, lLineCount );
        }

        *szLine = '\0';
        *szTag = '\0';
    }

    fclose( pFile );
}
Beispiel #10
0
int
fill_word (char *argument)
{
	return (search_block (argument, fill, true) >= 0);
}
Beispiel #11
0
void hcontrol_build_house(struct char_data * ch, char *arg)
{
  char arg1[MAX_INPUT_LENGTH];
  struct house_control_rec temp_house;
  int virt_house, real_house, real_atrium, virt_atrium, exit_num;
  long owner;

  if (num_of_houses >= MAX_HOUSES) {
    send_to_char("Max houses already defined.\r\n", ch);
    return;
  }

  /* first arg: house's vnum */
  arg = one_argument(arg, arg1);
  if (!*arg1) {
    send_to_char(HCONTROL_FORMAT, ch);
    return;
  }
  virt_house = atoi(arg1);
  if ((real_house = real_room(virt_house)) < 0) {
    send_to_char("No such room exists.\r\n", ch);
    return;
  }
  if ((find_house(virt_house)) >= 0) {
    send_to_char("House already exists.\r\n", ch);
    return;
  }

  /* second arg: direction of house's exit */
  arg = one_argument(arg, arg1);
  if (!*arg1) {
    send_to_char(HCONTROL_FORMAT, ch);
    return;
  }
  if ((exit_num = search_block(arg1, dirs, FALSE)) < 0) {
    sprintf(buf, "'%s' is not a valid direction.\r\n", arg1);
    send_to_char(buf, ch);
    return;
  }
  if (TOROOM(real_house, exit_num) == NOWHERE) {
    sprintf(buf, "There is no exit %s from room %d.\r\n", dirs[exit_num],
	    virt_house);
    send_to_char(buf, ch);
    return;
  }

  real_atrium = TOROOM(real_house, exit_num);
  virt_atrium = world[real_atrium].number;

  if (TOROOM(real_atrium, rev_dir[exit_num]) != real_house) {
    send_to_char("A house's exit must be a two-way door.\r\n", ch);
    return;
  }

  /* third arg: player's name */
  arg = one_argument(arg, arg1);
  if (!*arg1) {
    send_to_char(HCONTROL_FORMAT, ch);
    return;
  }
  if ((owner = get_id_by_name(arg1)) < 0) {
    sprintf(buf, "Unknown player '%s'.\r\n", arg1);
    send_to_char(buf, ch);
    return;
  }

  temp_house.mode = HOUSE_PRIVATE;
  temp_house.vnum = virt_house;
  temp_house.atrium = virt_atrium;
  temp_house.exit_num = exit_num;
  temp_house.built_on = time(0);
  temp_house.last_payment = 0;
  temp_house.owner = owner;
  temp_house.num_of_guests = 0;

  house_control[num_of_houses++] = temp_house;

  SET_BIT_AR(ROOM_FLAGS(real_house), ROOM_HOUSE);
  SET_BIT_AR(ROOM_FLAGS(real_house), ROOM_PRIVATE);
  SET_BIT_AR(ROOM_FLAGS(real_atrium), ROOM_ATRIUM);
  House_crashsave(virt_house);

  send_to_char("House built.  Mazel tov!\r\n", ch);
  House_save_control();
}
Beispiel #12
0
static int find_door(struct char_data *ch, const char *type, char *dir, const char *cmdname)
{
  int door;

  if (*dir) {			/* a direction was specified */
    if ((door = search_block(dir, dirs, FALSE)) == -1) { /* Partial Match */
      if ((door = search_block(dir, autoexits, FALSE)) == -1) { /* Check 'short' dirs too */
        send_to_char(ch, "That's not a direction.\r\n");
        return (-1);
      }
    }
    if (EXIT(ch, door)) {	/* Braces added according to indent. -gg */
      if (EXIT(ch, door)->keyword) {
        if (is_name(type, EXIT(ch, door)->keyword))
          return (door);
        else {
          send_to_char(ch, "I see no %s there.\r\n", type);
          return (-1);
        }
      } else
	return (door);
    } else {
      send_to_char(ch, "I really don't see how you can %s anything there.\r\n", cmdname);
      return (-1);
    }
  } else {			/* try to locate the keyword */
    if (!*type) {
      send_to_char(ch, "What is it you want to %s?\r\n", cmdname);
      return (-1);
    }
    for (door = 0; door < DIR_COUNT; door++)
    {
      if (EXIT(ch, door))
      {
        if (EXIT(ch, door)->keyword)
        {
          if (isname(type, EXIT(ch, door)->keyword))
          {
            if ((!IS_NPC(ch)) && (!PRF_FLAGGED(ch, PRF_AUTODOOR)))
              return door;
            else if (is_abbrev(cmdname, "open"))
            {
              if (IS_SET(EXIT(ch, door)->exit_info, EX_CLOSED))
                return door;
              else if (IS_SET(EXIT(ch, door)->exit_info, EX_LOCKED))
                return door;
            }
            else if ((is_abbrev(cmdname, "close")) && (!(IS_SET(EXIT(ch, door)->exit_info, EX_CLOSED))) )
              return door;
            else if ((is_abbrev(cmdname, "lock")) && (!(IS_SET(EXIT(ch, door)->exit_info, EX_LOCKED))) )
              return door;
            else if ((is_abbrev(cmdname, "unlock")) && (IS_SET(EXIT(ch, door)->exit_info, EX_LOCKED)) )
              return door;
            else if ((is_abbrev(cmdname, "pick")) && (IS_SET(EXIT(ch, door)->exit_info, EX_LOCKED)) )
              return door;
          }
        }
      }
    }

    if ((!IS_NPC(ch)) && (!PRF_FLAGGED(ch, PRF_AUTODOOR)))
      send_to_char(ch, "There doesn't seem to be %s %s here.\r\n", AN(type), type);
    else if (is_abbrev(cmdname, "open"))
      send_to_char(ch, "There doesn't seem to be %s %s that can be opened.\r\n", AN(type), type);
    else if (is_abbrev(cmdname, "close"))
      send_to_char(ch, "There doesn't seem to be %s %s that can be closed.\r\n", AN(type), type);
    else if (is_abbrev(cmdname, "lock"))
      send_to_char(ch, "There doesn't seem to be %s %s that can be locked.\r\n", AN(type), type);
    else if (is_abbrev(cmdname, "unlock"))
      send_to_char(ch, "There doesn't seem to be %s %s that can be unlocked.\r\n", AN(type), type);
    else
      send_to_char(ch, "There doesn't seem to be %s %s that can be picked.\r\n", AN(type), type);

    return (-1);
  }
}
Beispiel #13
0
// top level function to parse the spt netlist and construct the SUBCATCHMENT object
// as well as modifying the Options and Sgraph objects
int read_spt_from_file(FILE* F, Subcatchment *SUB, NameStore *NODE_NAMES, SMap *HASH, FILE* out) {

  FirstDef rc;
  int r_code;
  int line_num, good, node_index;
  source_id src_id;
  unsigned int n_op,n_node, n_seg, n_junc, n_qs, n_ls, n_bdn;
  StrBuffer *Prime, *Second;
  SimpleDblArray dba;
  double *XX=NULL, *YY=NULL;

  FlexVec<int, SHORT_ARRY_LENGTH>  qsources; // we store index only
  FlexVec<int, SHORT_ARRY_LENGTH>  lsources;
  FlexVec<int, SHORT_ARRY_LENGTH>  asources;
  
  ChkSum   mychk;
  char     chktmp[10];

  Prime = new StrBuffer(1023);  // both arrayes can automatically grow if needed
  Second = new StrBuffer(4095);
  r_code = -1;      // by default, the return code indicates failure
  
  /* we first read the option blocks */
  rc = def_not_found;
  line_num = 0;
  
  n_op = n_node = n_seg = n_junc = n_qs = n_ls = n_bdn = 0;
  while (1) { // first do the tally, and a rough check
    rc = search_block(F, &line_num, Spt_Descriptor, DES_SIZE(Spt_Descriptor), Prime, Second, out); 
    switch (rc) {
    case p_options: n_op++; break;
    case p_node:  n_node++; break;
    case p_segment: n_seg++; break;
    case p_junction: n_junc++; break;
    case p_qsource: n_qs++; break;
    case p_lateralsource: n_ls++; break;
    case p_boundarycondition: n_bdn++; break;
    case def_not_found: break;
    case def_error: 
      goto back;
      break;
    default: break;
    }
    if ( rc == def_not_found ) break;
  }
  rewind(F);
  
  if (out) {
    fprintf(out,"[II]: Found %d nodes, %d segmetns, %d junctions, %d q_sources, %d lateral sources, %d bdn condtions, %d options in the netlist\n", 
	    n_node, n_seg, n_junc, n_qs, n_ls, n_bdn, n_op);
  }
  if ( n_node < 2 ) {
    if (out) fprintf(out, "Bummer: not enough node statements, unable to procced\n");
    goto back;
  } else if ( n_seg < 1 ) {
    if (out) fprintf(out, "Bummer: not enough segment statements, unable to procced\n");
    goto back;
  } else if ( n_qs < 1 ) {
    if (out) fprintf(out, "Bummer: not enough Q source statements, unable to procced\n");
    goto back;
  } else if ( n_bdn < 1 ) {
    if (out) fprintf(out, "Bummer: not enough boundary condition statements, unable to procced\n");
    goto back;
  }
  
  // Copy the stat into the STAT object
  STAT.N_Nodes() = n_node;
  STAT.N_Segs() = n_seg;
  STAT.N_Juncs() = n_junc;
  STAT.N_Qsrcs() = n_qs;
  STAT.N_Lsrcs() = n_ls;
  STAT.N_Bnds() = n_bdn;

  // do the memory allocation stuff here
  NODE_NAMES->Init(n_node);
  SUB->InitGraph(n_node, n_seg, n_junc); //Testing

  // allocate memory to store the boundary conditions
  qsources.size(n_node+10);
  lsources.size(n_node+10);
  asources.size(n_node+10);

  for (unsigned int jj=0; jj<n_node+10; jj++) qsources[jj]=-1;
  for (unsigned int jj=0; jj<n_node+10; jj++) lsources[jj]=-1;
  for (unsigned int jj=0; jj<n_node+10; jj++) asources[jj]=-1;

  // we now proess options, otherwise we use default values
  if ( n_op > 0 ) {
    char *tmp;
    double stoptimeunit=1.0, timestepunit=1.0, prtintervalunit=1.0;
    double stoptime=-1.0, timestep=0.0, prtinterval=0.0;
    double prtstartunit = 1.0, prtstart = 0.0;
    double spinuptime = 0.0;

    rewind(F);
    rc = def_not_found;
    line_num = 0;
    while (1) {  
      rc = search_block(F, &line_num, Spt_Descriptor, DES_SIZE(Spt_Descriptor), Prime, Second, NULL); 
      
      if (rc == def_not_found ) break;
      if (rc != p_options ) continue;
      
      // read the options, in particular UseMetric!     
      good = Prime->Separate(out);
      if (good<0) {
	if (out) fprintf(out,"Bummer: Syntax error in netlist specification at line %d\n", line_num);
	goto back;
      }
      tmp = Prime->Find_Value( Op_Descriptor[0]._key); // USEMETRIC
      if (tmp) {
	OPT.UseMetric() = atoi(tmp)>0 ? 1 : 0;
	if (out) fprintf(out,"[II]: Metric set to %d\n", OPT.UseMetric());
      }

      // we process unit first so that we don't have to worry later
      tmp = Prime->Find_Value( Op_Descriptor[2]._key); // TIMESTEPUNIT
      if (tmp) {
	timestepunit = convert_time_scale(tmp, Time_Descriptor);
      }
      if ( timestepunit < 0 ) {
	if (out) fprintf(out,"[WW]: only accept time unit of SECOND, MINUTE, HOUR for statement on line %d. Use default=SECOND. \n", 
			 Prime->LineNumber());
	timestepunit = 1.0;
      }
      
      tmp = Prime->Find_Value( Op_Descriptor[1]._key); // TIMESTEP
      if (tmp) timestep = atof(tmp);

      tmp = Prime->Find_Value( Op_Descriptor[4]._key); // STOPTIMEUNIT
      if (tmp) {
	stoptimeunit = convert_time_scale(tmp, Time_Descriptor);
      }
      if ( stoptimeunit < 0 ) {
	if (out) fprintf(out,"Bummer:only accept time unit of SECOND, MINUTE, HOUR for statement on line %d. Use default=SECOND. \n", 
			 Prime->LineNumber());
	stoptimeunit = 1.0;
      }

      tmp = Prime->Find_Value( Op_Descriptor[3]._key); // STOPTIME
      if (tmp) stoptime = atof(tmp);

      // also deal with print interval first
      tmp = Prime->Find_Value( Op_Descriptor[6]._key); // PRTINTERVALUNIT
      if (tmp) {
	prtintervalunit = convert_time_scale(tmp, Time_Descriptor);
      }
      if ( prtintervalunit < 0 ) {
	if (out) fprintf(out,"[WW]: only accept time unit of SECOND, MINUTE, HOUR for statement on line %d. Use default=SECOND. \n", 
			 Prime->LineNumber());
	prtintervalunit = 1.0;
      }

      
      tmp = Prime->Find_Value( Op_Descriptor[8]._key); // PRTSTARTUNIT
      if (tmp) {
	prtstartunit = convert_time_scale(tmp, Time_Descriptor);
      }
      if ( prtstartunit < 0 ) {
	if (out) fprintf(out,"[WW]: only accept time unit of SECOND, MINUTE, HOUR for statement on line %d. Use default=SECOND. \n", 
			 Prime->LineNumber());
	prtstartunit = 1.0;

      }

      tmp = Prime->Find_Value( Op_Descriptor[7]._key); // PRTSTART
      if (tmp) prtstart = atof(tmp);

      tmp = Prime->Find_Value( Op_Descriptor[5]._key); // PRTINTERVAL
      if (tmp) prtinterval = atof(tmp);
      if ( prtinterval < 0 ) {
	if (out) fprintf(out,"[WW]: negative print interval specified on line %d. Overwritten with zero!\n",
			 Prime->LineNumber());
	prtinterval = 0.0;
      }
      
      tmp = Prime->Find_Value( Op_Descriptor[9]._key); // CHECKONLY
      if (tmp) {
	OPT.CheckOnly() = atoi(tmp) > 0 ? 1 : 0;
	if (out) fprintf(out,"[II]: CheckOnly set to %d\n", OPT.CheckOnly());
      }
      
      tmp = Prime->Find_Value( Op_Descriptor[10]._key); // SSFILE
      if (tmp) {
	STAT.SetSSFile(tmp);
	if (out) fprintf(out, "[II]: SSFile (SteadyState file) set to \"%s\"\n", tmp);
      }

      tmp = Prime->Find_Value( Op_Descriptor[11]._key); // Lmax
      if (tmp) {
	OPT.LMax() = atof(tmp);
	if (out) fprintf(out,"[II]: LMax set to %.4e\n", OPT.LMax() );
      }

      tmp = Prime->Find_Value( Op_Descriptor[12]._key); // Lmin
      if (tmp) {
	OPT.LMin() = atof(tmp);
	if (out) fprintf(out,"[II]: LMin set to %.4e\n", OPT.LMin() );
      }

      tmp = Prime->Find_Value( Op_Descriptor[13]._key); // PrintDepth
      if (tmp) {
	OPT.PrintD() = atoi(tmp) > 0 ? 1 : 0;
	if (out) fprintf(out,"[II]: PrtDepth set to %1d\n", OPT.PrintD() );
      }

      tmp = Prime->Find_Value( Op_Descriptor[14]._key); // PrintSurfElev
      if (tmp) {
	OPT.PrintZ() = atoi(tmp) > 0 ? 1 : 0;
	if (out) fprintf(out,"[II]: PrtSurfElev set to %1d\n", OPT.PrintZ() );
      }

      tmp = Prime->Find_Value( Op_Descriptor[15]._key); // PrintQ
      if (tmp) {
	OPT.PrintQ() = atoi(tmp) > 0 ? 1 : 0;
	if (out) fprintf(out,"[II]: PrtQ set to %1d\n", OPT.PrintQ() );
      }

      tmp = Prime->Find_Value( Op_Descriptor[16]._key); // PrintA
      if (tmp) {
	OPT.PrintA() = atoi(tmp) > 0 ? 1 : 0;
	if (out) fprintf(out,"[II]: PrtA set to %1d\n", OPT.PrintA() );
      }

      tmp = Prime->Find_Value( Op_Descriptor[17]._key); // PrintCoord
      if (tmp) {
	OPT.PrintXY() = atoi(tmp) > 0 ? 1 : 0;
	if (out) fprintf(out,"[II]: PrtCoord set to %1d\n", OPT.PrintXY() );
      }

      tmp = Prime->Find_Value( Op_Descriptor[18]._key); // verbose
      if (tmp) {
	OPT.DebugLevel() = atoi(tmp) > 0 ? atoi(tmp) : 0;
	if (out) fprintf(out,"[II]: Verbose set to %1d\n", OPT.DebugLevel() );
      }

      tmp = Prime->Find_Value( Op_Descriptor[19]._key); // epoch
      if (tmp) {
	STAT.SetEpoch(tmp);
	if (out) fprintf(out, "[II]: Epoch is set to %s\n", STAT.Epoch() );
      }

      tmp = Prime->Find_Value( Op_Descriptor[20]._key); // spinup_time
      if (tmp) spinuptime = atof(tmp);
      if ( spinuptime < 0 ) {
	if (out) fprintf(out,"[WW]: negative spin-up time specified on line %d. Use zero instead (disabled)\n",
			 Prime->LineNumber());
	spinuptime = 0.0;
      }
      
    }

    // check if stoptime is specified (by setting default to 0), 
    // do the scaling,
    // reason: we might have multiple option blocks

    if ( timestep < 0 ) {
      if (out) fprintf(out,"[WW]: negative TimeStep specified. Overwritten with zeor!\n");
    } else if (timestep > 0) {
      timestep *= timestepunit;
      OPT.FixedStep() = timestep;
      if (out) fprintf(out,"[II]: TimeStep set to %.3e second.\n", timestep);
    }
    
    if ( prtinterval < 0 ) {
      if (out) fprintf(out,"[WW]: negative PrInterval specified. Overwritten with zero!\n");
    } else if (prtinterval>0) {
      int tt;
      prtinterval *= prtintervalunit;
      tt = (int) round(prtinterval/60.0);
      tt = tt >=0 ? tt : 0;
      OPT.PrintInterval() = tt;
      if (out) fprintf(out,"[II]: PrtInterval set to %d min\n", tt);
    }

    if (prtstart < 0) {
      if (out) fprintf(out,"[WW]: negative PrtStart specified. Overwritten with zero!\n");
    } else if ( prtstart > 0) {
      int tt;
      prtstart *= prtstartunit;
      tt = (int)round(prtstart/60.0);
      tt = tt>=0 ? tt : 0;
      OPT.PrintStart() = tt;
      if (out) fprintf(out, "[II]: PrtStart set to %d min\n", tt);
    }

    if (stoptime > 0 ) {
      stoptime *= stoptimeunit;
      OPT.StopTime() = stoptime;
      if (out) fprintf(out,"[II]: StopTime set to %.3e second\n", stoptime);
    } else {
      if (out) fprintf(out,"Bummer: a positive StopTime is required in order to run the simulation!\n");
      goto back;
    }

    if ( spinuptime > 0 ) {
      int tt = (int)spinuptime;
      const int min_spin = 300;
      if ( tt > min_spin ) {
	OPT.SpinUpTime() = tt;
	if (out) fprintf(out,"[II]: SpinUpTime set to %d second\n", tt);
      } else {
	OPT.SpinUpTime() = 0;
	if (out) fprintf(out,"[WW]: minimal spinup time is %d seconds. Revert back to zero (spinup disabled)\n", min_spin);
      }
    }
  }
  
  
  // add nodes,  check duplicate
  rewind(F);
  rc = def_not_found;
  line_num = 0;
  while (1) {  
    char node_id[MAX_LINE_LENGTH];
    char *tmp;
    double s0, n, h0, z0, width, slope;
    XsecType xtp;
    int   num_pairs;
    double q0=0, a0=0;  // we will deal with them later
    double x=-1.0, y=-1.0;  // not used 

    rc = search_block(F, &line_num, Spt_Descriptor, DES_SIZE(Spt_Descriptor), Prime, Second, NULL); 
    
    // we don't check on the error flags since we have done it before
    if (rc == def_not_found ) break;   // we added all nodes
    if (rc == def_error ) goto back;  

    width = 0.0;
    slope = 0.0;
    num_pairs = 0;
    switch (rc) {
    case p_node:
      /* intercept and understand node */
      if ( !Second->HasContent()) {
	if (out) fprintf(out,"Bummer: NODE statement on line %d requires a x-section specification\n", Prime->LineNumber() );
	goto back;
      }
      good = Prime->Separate(out);
      good = Second->Separate(out);
      
      if (good <0) {
	if (out) fprintf(out,"Bummer: syntax error in netlist specification in line %d\n", Prime->LineNumber());
	goto back;
      }

      // parse each field one by one
      tmp = Prime->Find_Value( Node_Descriptor[0]._key); // "id"
      if (!tmp) {
	if (out) fprintf(out, "Bummer: unable to locate field %s for the NODE statement on line %d\n", Node_Descriptor[0]._key, 
			 Prime->LineNumber());
	goto back;
      }
      // the clean node id is now in node_id;
      strncpy(node_id, tmp, MAX_WORD_LENGTH);
      node_index = HASH->Check(node_id);
      if ( node_index != -1 ) {
	if (out) fprintf(out,"Bummer: duplicated NODE definition of node \"%s\" on line %d\n", node_id, Prime->LineNumber() );
	goto back;
      }
      node_index = HASH->Create(node_id);
      NODE_NAMES->Insert(node_id, node_index);
      
      tmp = Prime->Find_Value( Node_Descriptor[1]._key);  // "sR"
      if (!tmp) {
	if (out) fprintf(out, "Bummer: unable to locate field %s for the NODE statement on line %d\n", Node_Descriptor[1]._key, 
			 Prime->LineNumber());
	goto back;
      }
      s0 = atof(tmp);
      if ( s0 < 1e-6 ) {
	if (out) fprintf(out, "[WW]: reference slope sR at location %s is nonpositive with value of %.4e. \n", node_id, s0);
#if 0
	goto back;
#endif
      }

      tmp = Prime->Find_Value( Node_Descriptor[2]._key);  // "n"
      if (!tmp) {
	if (out) fprintf(out, "Bummer: unable to locate field %s for the NODE statement on line %d\n", Node_Descriptor[2]._key, 
			 Prime->LineNumber());
	goto back;
      }
      n = atof(tmp);
      if ( n < OPT.MinN() ) {
	if (out) fprintf(out,"[WW]: Manning's N at location %s is %.4e, less than threshold value %.4e. Supercritical flow might occur\n",
			 node_id, n, OPT.MinN());
      }
      
      tmp = Prime->Find_Value( Node_Descriptor[3]._key);  // "zR"
      if (!tmp) {
	if (out) fprintf(out, "Bummer: unable to locate field %s for the NODE statement on line %d\n", Node_Descriptor[3]._key, 
			 Prime->LineNumber());
	goto back;
      }
      z0 = atof(tmp);
      
      
      tmp = Prime->Find_Value( Node_Descriptor[4]._key);  // "hR"
      if (!tmp) {
	if (out) fprintf(out, "Bummer: unable to locate field %s for the NODE statement on line %d\n", Node_Descriptor[4]._key, 
			 Prime->LineNumber());
	goto back;
      }
      h0 = atof(tmp);
      
      tmp = Prime->Find_Value( Node_Descriptor[5]._key); // "xcoord"
      if (tmp) {
	x = atof(tmp);    // this is optional
      }

      tmp = Prime->Find_Value( Node_Descriptor[6]._key); // "ycoord"
      if (tmp) {
	y = atof(tmp);
      }

      if ( Second->Cmp_Head(Node_Descriptor[7]._key)) {   // "Trapezoidal
	tmp = Second->Find_Value(Trap_Descriptor[0]._key);  // "bottomwidth"
	if (!tmp) {
	  if (out) fprintf(out, "Bummer: %s x-section on line %d requires field %s\n", Node_Descriptor[5]._key, 
			   Second->LineNumber(), Trap_Descriptor[0]._key);
	  goto back;
	}
	width = atof(tmp);
	
	tmp = Second->Find_Value(Trap_Descriptor[1]._key);  // "slope"
	if (!tmp) {
	  if (out) fprintf(out, "Bummer: %s x-section on line %d requires field %s\n", Node_Descriptor[5]._key, 
			   Second->LineNumber(), Trap_Descriptor[1]._key);
	  goto back;
	} else {
	  slope = atof(tmp);
	}
	xtp = TRAP;
	
      } else if ( Second->Cmp_Head(Node_Descriptor[8]._key)) {  // "Rectangular"
	tmp = Second->Find_Value(Rect_Descriptor[0]._key);  // "bottomwidth"
	if (!tmp) {
	  if (out) fprintf(out, "Bummer: %s x-section on line %d requires field %s\n", Node_Descriptor[6]._key, 
			   Second->LineNumber(), Rect_Descriptor[0]._key);
	  goto back;
	} else {
	  width = atof(tmp);
	}
	xtp = RECT;
	
      } else if ( Second->Cmp_Head(Node_Descriptor[9]._key)) { // "XY"
	if ( Second->NumPairs() % 2 != 0 ) {
	  if (out) fprintf(out,"Bummer: unbalanced XY pairs for %s statement on line %d\n", 
			   Node_Descriptor[7]._key,Second->LineNumber());
	  goto back;
	  
	} else {  // all good, copy the values
	  dba.Reset();
	  num_pairs = read_2d_arrays(Second, XY_Descriptor, &dba, 0, out);
	  
	  if ( num_pairs <= 0 ) {
	    if (out) fprintf(out,"Bummer: error reading 2D data specified on line %d\n", Second->LineNumber() );
	    goto back;
	  }
	}
	xtp = SPLINE;
	
      } else {
	if (out) fprintf(out,"Bummer: NODE statement on line %d requires at least one of the x-section specification: %s, %s or %s\n",
			 Prime->LineNumber(), Node_Descriptor[5]._key, Node_Descriptor[6]._key, Node_Descriptor[7]._key);
	goto back;
      }
      
      // at this point, all variables are ready, create the node
      // use node_idx, s0, n, h0, z0, dba (good)
      // first do scaling based UseMetric()
      XX = dba.X();
      YY = dba.Y();
      if (OPT.UseMetric() == 0 ) {
	if (xtp == SPLINE) {
	  for (int jj=0; jj<num_pairs; jj++) {
	    XX[jj] *= OPT.FtoM();
	    YY[jj] *= OPT.FtoM();
	  }
	} else {  // RECT or TRAP, only change the bottom width, slope is dimensionless
	  width *= OPT.FtoM();
	}
	z0 *= OPT.FtoM();
	h0 *= OPT.FtoM();
      }
      
      if ( xtp == SPLINE ) {
#ifdef DBGSPLINE
	printf("node name %s, id %d\n", node_id, (unsigned int)node_index); 
#endif
	SUB->MakeNode((unsigned int)node_index, s0, n, x, y, q0, a0, z0, h0, SPLINE, num_pairs, XX, YY);
      } else if (xtp == TRAP) {
	SUB->MakeNode((unsigned int)node_index, s0, n, x, y, q0, a0, z0, h0, TRAP, width, slope);
      } else if (xtp == RECT) {
	SUB->MakeNode((unsigned int)node_index, s0, n, x, y, q0, a0, z0, h0, RECT, width);
      }
      
      break;

    default: break;

    } // end switch
  }   // while loop, find all nodes


  // make SUB happy
  SUB->AssignNodes();


  // records Qsrc, Lsrc and Bdn's
  rewind(F);
  rc = def_not_found;
  line_num = 0;
  while (1) {  
    char node_id[MAX_LINE_LENGTH];
    char *tmp;
    int   num_pairs;
    int loc_index, bnd_is_area;
    Node *node=NULL;
    //    double geo_scale=1.0;

    rc = search_block(F, &line_num, Spt_Descriptor, DES_SIZE(Spt_Descriptor), Prime, Second, NULL); 
    
    // we don't check on the error flags since we have done it before
    if (rc == def_not_found ) break;   // we added all nodes
    if (rc == def_error ) goto back;  

    num_pairs = 0;
    switch (rc) {
    case p_qsource:
      if (!Second->HasContent()) {
	if (out) fprintf(out,"Bummer: QSOURCE statement on line %d requires a time series specification\n", Prime->LineNumber() );
	goto back;
      }
      good = Prime->Separate(out);
      good = Second->Separate(out);
      
      if (good<0) {
	if (out) fprintf(out,"Bummer: syntax error in netlist specification in line %d\n", line_num);
	goto back;
      }

      tmp = Prime->Find_Value( Qsource_Descriptor[0]._key); // "location"
      if (!tmp) {
	if (out) fprintf(out, "Bummer: unable to locate field %s for the QSOURCE statement on line %d\n", Qsource_Descriptor[0]._key, 
			 Prime->LineNumber());
	goto back;
      }
      if ( !Second->Cmp_Head( Qsource_Descriptor[1]._key) ) { // "timeseries"
	if (out) fprintf(out,"Bummer: QSOURCE statement on line %d requires time series specification: %s\n",
			 Prime->LineNumber(), Qsource_Descriptor[1]._key);
	goto back;
      }

      strncpy(node_id, tmp, MAX_WORD_LENGTH);
      loc_index = HASH->Check(node_id);
      if ( loc_index == -1 ) {
	if (out) fprintf(out, "Bummer: cannot find node \"%s\" specified on line %d\n",
			 node_id, Prime->LineNumber());
	goto back;
      }
      
      dba.Reset();
      num_pairs = read_2d_arrays(Second, TS_Descriptor, &dba, 1, out);
      if ( num_pairs <= 0 ) {
	if (out) fprintf(out,"Bummer: error reading 2D data specified on line %d\n", Second->LineNumber() );
	goto back;
      }

      // ready to insert Q source, with node and time series in dba (good), remember the
      // dba.Scale() field, which is the time scale
      XX = dba.X();
      YY = dba.Y();
      src_id = SUB->MakeSource(num_pairs, &XX[0], &YY[0], dba.Scale(), (OPT.UseMetric()==0?OPT.F3toM3():1.0) );
      if (src_id<0) {
	if (out) fprintf(out,"Bummer: problem with QSource at node \"%s\" on line %d\n",
			 node_id, Prime->LineNumber());
	goto back;
      }
      
      if ( qsources[ loc_index] > -1 ) {
	if (out) fprintf(out, "Bummer: duplicated definitino of Qsource at node \"%s\"\n",
			 node_id);
	goto back;
      }

      qsources[ loc_index ] = src_id; // store the index
      break;

    case p_lateralsource:
      if (!Second->HasContent()) {
	if (out) fprintf(out,"Bummer: LATERALSOURCE statement on line %d requires a time series specification\n", Prime->LineNumber() );
	goto back;
      }
      good = Prime->Separate(out);
      good = Second->Separate(out);
      
      if (good<0) {
	if (out) fprintf(out,"Bummer: problem with LateralSource on line %d\n",
			 Prime->LineNumber());
	goto back;
      }

      tmp = Prime->Find_Value( Latsource_Descriptor[0]._key); // "location"
      if (!tmp) {
	if (out) fprintf(out, "Bummer: unable to locate field %s for the LATERALSOURCE statement on line %d\n", Latsource_Descriptor[0]._key, 
			 Prime->LineNumber());
	goto back;
      }
      if ( !Second->Cmp_Head( Latsource_Descriptor[1]._key) ) { // "timeseries"
	if (out) fprintf(out,"Bummer: LATERALSOURCE statement on line %d requires time series specification: %s\n",
			 Prime->LineNumber(), Latsource_Descriptor[1]._key);
	goto back;
      }

      strncpy(node_id, tmp, MAX_WORD_LENGTH);
      loc_index = HASH->Check(node_id);
      if ( loc_index == -1 ) {
	if (out) fprintf(out, "Bummer: cannot find node \"%s\" specified on line %d\n",
			 node_id, Prime->LineNumber());
	goto back;
      }
      
      dba.Reset();
      num_pairs = read_2d_arrays(Second, TS_Descriptor, &dba, 1, out);
      if ( num_pairs <= 0 ) {
	if (out) fprintf(out,"Bummer: error reading 2D data specified on line %d\n", Second->LineNumber() );
	goto back;
      }
      // ready to insert lateral source, with loc_index and time series in dba (good),
      // remember dba.Scale()
      XX = dba.X();
      YY = dba.Y();
      src_id = SUB->MakeSource(num_pairs, &XX[0], &YY[0], dba.Scale(), (OPT.UseMetric()==0?OPT.F3toM3():1.0) );
      if (src_id<0) {
	if (out) fprintf(out,"Bummer: problem with LATERALSOURCE at node \"%s\" on line %d\n",
			 node_id, Prime->LineNumber());
	goto back;
      }

      if ( lsources[ loc_index ] > -1 ) {
	if (out) fprintf(out, "Bummer: duplicated definitino of LATERALSOURCE at node \"%s\"\n",
			 node_id);
	goto back;
      }
      lsources[ loc_index ] = src_id;

      break;

    case p_boundarycondition:

      if (!Second->HasContent()) {
	if (out) fprintf(out,"Bummer: BOUNDARYCONDITION statement on line %d requires a time series specification\n", Prime->LineNumber() );
	goto back;
      }
      good = Prime->Separate(out);
      good = Second->Separate(out);
      if (good<0) {
	if (out) fprintf(out,"Bummer: syntax error in BoundaryCondition Statement in line %d\n", Prime->LineNumber());
	goto back;
      }

      tmp = Prime->Find_Value( Bdn_Descriptor[1]._key); // "type" 
      if (!tmp) {
	if (out) fprintf(out, "Bummer: unable to locate field %s for the BOUNDARYCONDITION statement on line %d\n", Bdn_Descriptor[1]._key, 
			 Prime->LineNumber());
	goto back;
      }
      if ( cmp_string(tmp, BdnType_Descriptor[0]._key) ) { // "AREA"
	bnd_is_area = 1;
      } else if (cmp_string(tmp, BdnType_Descriptor[1]._key) ) { // "DEPTH"
	bnd_is_area = 0;
      } else {
	if (out) fprintf(out, "Bummer: BoundaryCondition has to be either \"%s\" or \"%s\" for statement on line %d\n",
			 BdnType_Descriptor[0]._key, 
			 BdnType_Descriptor[1]._key,
			 Prime->LineNumber() );
	goto back;
      }
      
      tmp = Prime->Find_Value( Bdn_Descriptor[0]._key); // "location"
      if (!tmp) {
	if (out) fprintf(out, "Bummer: unable to locate field %s for the BOUNDARYCONDITION statement on line %d\n", Bdn_Descriptor[0]._key, 
			 Prime->LineNumber());
	goto back;
      }

      strncpy(node_id, tmp, MAX_WORD_LENGTH);
      loc_index = HASH->Check(node_id);
      if ( loc_index == -1 ) {
	if (out) fprintf(out, "Bummer: cannot find node \"%s\" specified on line %d\n",
			 node_id, Prime->LineNumber());
	goto back;
      }
      
      if ( !Second->Cmp_Head( Bdn_Descriptor[2]._key) ) { // "timeseries"
	if (out) fprintf(out,"Bummer: BOUNDARYCONDITION statement on line %d requires time series specification: %s\n",
			 Prime->LineNumber(), Bdn_Descriptor[2]._key);
	goto back;
      }

      dba.Reset();
      num_pairs = read_2d_arrays(Second, TS_Descriptor, &dba, 1, out);
      if ( num_pairs <= 0 ) {
	if (out) fprintf(out,"Bummer: error reading 2D data specified on line %d\n", Second->LineNumber() );
	goto back;
      }

      // ready to insert Bdn condition, with loc_index and time series in dba (good),
      // remember dba.Scale()
      XX = dba.X();
      YY = dba.Y();
      if ( bnd_is_area == 0 ) {
	node = SUB->GetNode( loc_index );
	if ( !node ) {
	  if (out) fprintf(out, "Bummer: node \"%s\" not yet defined!\n", node_id);
	  goto back;
	}
      }
      if ( bnd_is_area) {
	src_id = SUB->MakeSource(num_pairs, &XX[0], &YY[0], dba.Scale(), (OPT.UseMetric()==0?OPT.F2toM2():1.0) );
      } else {
	FlexVec<double> tmp;
	tmp.size(num_pairs);
	node = SUB->GetNode( loc_index);
	for (int jj=0; jj<num_pairs;jj++) { 
	  tmp[jj]= node->GetAbyDepth( YY[jj]*(OPT.UseMetric()==0?OPT.FtoM():1.0) );
	}
	src_id = SUB->MakeSource(num_pairs, &XX[0], &tmp[0], dba.Scale(), 1.0);
      }

      if (src_id < 0) {
	if (out) fprintf(out, "Bummer: problem with BoundaryCondition definition on line %d\n", Prime->LineNumber() );
	goto back;
      }
      if ( asources[ loc_index] >-1 ) {
	if (out) fprintf(out, "Bummer: duplicated definitino of BOUNDARYCONDITION at node \"%s\"\n",
			 node_id);
	goto back;
      }
      asources[ loc_index ] = src_id;
      break;

    default: break;

    } // end switch
  }   // while loop, found all qsource, lsources and asources

  // process the rest, segments, junctions
  rc = def_not_found;
  rewind(F);
  line_num = 0;
  while (1) {  
    int up_idx, down_idx;
    int up1_idx, up2_idx;
    double length, coef1, coef2;
    char *tmp;
    Node *fp, *tp;

    rc = search_block(F, &line_num, Spt_Descriptor, DES_SIZE(Spt_Descriptor), Prime, Second, NULL); 
    
    if (rc == def_error) goto back;
    if (rc == def_not_found) break;

    switch ( rc ) {
    case p_segment:
      good = Prime->Separate(out);
      if (good<0) {
	if (out) fprintf(out,"Bummer: syntax error in netlist specification at line %d\n", Prime->LineNumber());
	goto back;
      }

      tmp = Prime->Find_Value( Segment_Descriptor[0]._key); // "up" 
      if ( !tmp) {
	if (out) fprintf(out, "Bummer: SEGMENT statement on line %d requires the \"%s\" field.\n",
			 Prime->LineNumber(), Segment_Descriptor[0]._key);
	goto back;
      }
      up_idx = HASH->Check(tmp);
      if ( up_idx == -1 ) {
	if (out) fprintf(out, "Bummer: cannot find node \"%s\" specified on line %d\n",
			 tmp, Prime->LineNumber());
	goto back;
      }

      tmp = Prime->Find_Value( Segment_Descriptor[1]._key); // "down:
      if ( !tmp) {
	if (out) fprintf(out, "Bummer: SEGMENT statement on line %d requires the \"%s\" field.\n",
			 Prime->LineNumber(), Segment_Descriptor[1]._key);
	goto back;
      }
      down_idx = HASH->Check(tmp);
      if ( down_idx == -1 ) {
	if (out) fprintf(out, "Bummer: cannot find node \"%s\" specified on line %d\n",
			 tmp, Prime->LineNumber());
	goto back;
      }
      tmp = Prime->Find_Value( Segment_Descriptor[2]._key); // "length"
      if ( !tmp ) {
	if (out) fprintf(out, "Bummer: SEGMENT statement on line %d requires the \"%s\" field.\n",
			 Prime->LineNumber(), Segment_Descriptor[2]._key);
	goto back;
      }
      if ( !is_scientific( tmp ) ) {
	if (out) fprintf(out, "Bummer: invalid real value specification on line %d\n",Prime->LineNumber());
	goto back;
      }
      length = atof(tmp);

      // ready to insert segment, use up_idx, down_idx, length, check length > 0!
      if ( length <= 0.0 ) {
	if (out) fprintf(out,"Bummer: found negative or zero length on line %d\n", Prime->LineNumber() );
	goto back;
      }
      if ( length <= OPT.LMin() ) {
	if (out) fprintf(out,"[WW]: segment length on line %d is %.4e, less than preferred minimal %.4e\n",
			 Prime->LineNumber(), length, OPT.LMin());
      }
      if ( length >= OPT.LMax() ) {
	if (out) fprintf(out,"[WW]: segment length on line %d is %.4e, larger than preferred maxium %.4e\n",
			 Prime->LineNumber(), length, OPT.LMax());
      }

      if (OPT.UseMetric() == 0 ) length *= OPT.FtoM();

      fp = SUB->GetNode( up_idx );
      tp = SUB->GetNode( down_idx );
      if (fp == NULL) {
	if (out) fprintf(out,"Bummer: internal error, unable to locate node at index %d for statement on line %d\n", 
			 up_idx, Prime->LineNumber());
	goto back;
      }      
      if (tp == NULL) {
	if (out) fprintf(out,"Bummer: internal error, unable to locate node at index %d for statement on line %d\n", 
			 down_idx, Prime->LineNumber());
	goto back;
      }

      // in case we have a lateral source
      src_id = lsources[up_idx];
      SUB->MakeStvEquation( up_idx, down_idx, length, src_id );

      break;

    case p_junction:
      good = Prime->Separate(out);
      if (good<0) {
	if (out) fprintf(out,"Bummer: syntax error in netlist specification at line %d\n", Prime->LineNumber());
	goto back;
      }
      
      tmp = Prime->Find_Value( Junc_Descriptor[0]._key); // "up1" 
      if (tmp) {
	up1_idx = HASH->Check(tmp);
	if ( up1_idx == -1 ) {
	  if (out) fprintf(out, "Bummer: cannot find node \"%s\" specified on line %d\n",
			   tmp, Prime->LineNumber());
	  goto back;
	}
      } else up1_idx = -1;


      tmp = Prime->Find_Value( Junc_Descriptor[1]._key); // "up2:
      if (tmp) {
	up2_idx = HASH->Check(tmp);
	if ( up2_idx == -1 ) {
	  if (out) fprintf(out, "Bummer: cannot find node \"%s\" specified on line %d\n",
			   tmp, Prime->LineNumber());
	  goto back;
	}
      } else up2_idx = -1;


      tmp = Prime->Find_Value( Junc_Descriptor[2]._key); // "down"
      if ( !tmp) {
	if (out) fprintf(out, "Bummer: JUNCTION statement on line %d requires the \"%s\" field.\n",
			 Prime->LineNumber(), Junc_Descriptor[2]._key);
	goto back;
      }
      down_idx = HASH->Check(tmp);
      if ( down_idx == -1 ) {
	if (out) fprintf(out, "Bummer: cannot find node \"%s\" specified on line %d\n",
			 tmp, Prime->LineNumber());
	goto back;
      }

      tmp = Prime->Find_Value( Junc_Descriptor[3]._key); // "coeff1"
      if (tmp) {
	if ( !is_scientific( tmp ) ) {
	  if (out) fprintf(out, "Bummer: invalid real value specification on line %d\n",Prime->LineNumber());
	  goto back;
	}
	coef1 = atof(tmp);
	if ( coef1 <= 0.0 ) {
	  if (out) fprintf(out, "Bummer: coefficient should be positive on line %d\n",Prime->LineNumber());
	  goto back;
	}
      } else coef1 = -1.0;

      tmp = Prime->Find_Value( Junc_Descriptor[4]._key); // "coeff2"
      if ( tmp) {
	if ( !is_scientific( tmp ) ) {
	  if (out) fprintf(out, "Bummer: invalid real value specification on line %d\n",Prime->LineNumber());
	  goto back;
	}
	coef2 = atof(tmp);
	if ( coef2 <= 0.0 ) {
	  if (out) fprintf(out, "Bummer: coefficient should be positive on line %d\n",Prime->LineNumber());
	  goto back;
	}
      } else coef2 = -1.0;

      // ready to insert junction, use up1_idx, up2_idx, down_idx, coef1, coef2, check
      if ( up1_idx == -1 && up2_idx == -1 ) {
	if (out) fprintf(out,"Bummer: at least one upstream nodes has to be specified on line %d\n",
			 Prime->LineNumber() );
	goto back;
      }

      if ( coef1 < 0 && coef2 < 0 ) {
	if (out) fprintf(out,"Bummer: at least one upstream coefficients has to be specified on line %d\n",
			 Prime->LineNumber() );
	goto back;
      }

      if ( (up1_idx > 0 && coef1 < 0) || ( up2_idx>0 && coef2<0 ) ) {
	if (out) fprintf(out,"Bummer: mismatch in upstream node and coefficient specifications on line %d\n",
			 Prime->LineNumber());
	goto back;
      }

      /* To add: 
	 distance check among three nodes, use X() and Y() of each node 
       */
      int nn[2];
      double rr[2];

      if ( up1_idx > 0 && up2_idx > 0 ) {  // both
	nn[0] = up1_idx; 
	nn[1] = up2_idx;
	rr[0] = coef1;
	rr[1] = coef2;
	SUB->MakeDepEquation( down_idx, 2, &nn[0], &rr[0]);

      } else if ( up1_idx > 0 ) {    // up1 only
	nn[0] = up1_idx;
	rr[0] = coef1;
	SUB->MakeDepEquation( down_idx, 1, &nn[0], &rr[0]);

      } else {    // up2 only
	nn[0] = up2_idx;
	rr[0] = coef2;
	SUB->MakeDepEquation( down_idx, 1, &nn[0], &rr[0]);

      }

      break;

    default:
      break;
    }
  }
  
  // insert Qsrc, lateral source and Bdn
  for (int jj=0; jj<STAT.N_Nodes(); jj++) {
    if ( qsources[jj] > -1) {
      if ( SUB->GetSource( qsources[jj])->GetParent() >= 0 ) {
	if (out) fprintf(out, "Bummer: trying to re-use qsource at node index %d\n",jj);
	goto back;
      }
      SUB->MakeQrSrcEquation( jj, qsources[jj] );
    }
  }

  
  for (int jj=0; jj<STAT.N_Nodes(); jj++) {
    if ( asources[jj] > -1 ) {
      if ( SUB->GetSource( asources[jj] )->GetParent() >= 0 ) {
	if (out) fprintf(out, "Bummer: trying to re-use asource at node index %d\n",jj);
	goto back;
      }
      SUB->MakeArSrcEquation( jj, asources[jj]);
      break;    // we assume there is only ONE BdnCondition
    }
  }

  r_code = 0; // only at this point we indicate everything is clean

  // calculate the chksum in case we are going to load something from the data
  for (int jj=0; jj<STAT.N_Nodes(); jj++) {
    mychk.add_string( NODE_NAMES->Get(jj) );
  }

  for (int jj=0; jj<STAT.N_Nodes(); jj++) {
    if ( qsources[jj] > -1 ) {
      Source *s = (Source*)SUB->GetSource( qsources[jj] );
      sprintf(chktmp, "%+.1e", s->Evaluate(0.0));
      mychk.add_string(chktmp);
    }
  }
  for (int jj=0; jj<STAT.N_Nodes(); jj++) {
    if ( asources[jj] > -1 ) {
      Source *s = (Source*)SUB->GetSource( asources[jj]);
      sprintf(chktmp, "%+.1e", s->Evaluate(0.0));
      mychk.add_string(chktmp);
    }
  }
  for (int jj=0; jj<STAT.N_Nodes(); jj++) {
    if ( lsources[jj] > -1 ) {
      Source *s = (Source*)SUB->GetSource( lsources[jj] );
      sprintf(chktmp, "%+.1e", s->Evaluate(0.0));
      mychk.add_string(chktmp);
    }
  }
  
  STAT.SetChkSum( mychk.HexCode() );

 back:
  if (Prime) delete Prime;
  if (Second) delete Second;

  return r_code;
}
Beispiel #14
0
int generic_find(char *arg, int bitvector, struct char_data *ch,
		 struct char_data **tar_ch, struct obj_data **tar_obj)
{
  static char *ignore[] = {
    "the",
    "in",
    "on",
    "at",
    "\n" };
  
  int i;
  char name[256];
  bool found;
  
  found = FALSE;
  
  
  /* Eliminate spaces and "ignore" words */
  while (*arg && !found) {
    
    for(; *arg == ' '; arg++)   ;
    
    for(i=0; (name[i] = *(arg+i)) && (name[i]!=' '); i++)   ;
    name[i] = 0;
    arg+=i;
    if (search_block(name, ignore, TRUE) > -1)
      found = TRUE;
    
  }
  
  if (!name[0])
    return(0);
  
  *tar_ch  = 0;
  *tar_obj = 0;
  
  if (IS_SET(bitvector, FIND_CHAR_ROOM)) {      /* Find person in room */
    if (*tar_ch = get_char_room_vis(ch, name)) {
      return(FIND_CHAR_ROOM);
    }
  }
  
  if (IS_SET(bitvector, FIND_CHAR_WORLD)) {
    if (*tar_ch = get_char_vis(ch, name)) {
      return(FIND_CHAR_WORLD);
    }
  }
  
  if (IS_SET(bitvector, FIND_OBJ_EQUIP)) {
    for(found=FALSE, i=0; i<MAX_WEAR && !found; i++)
      if (ch->equipment[i] && str_cmp(name, ch->equipment[i]->name) == 0) {
	*tar_obj = ch->equipment[i];
	found = TRUE;
      }
    if (found) {
      return(FIND_OBJ_EQUIP);
    }
  }
  
  if (IS_SET(bitvector, FIND_OBJ_INV)) {
    if (IS_SET(bitvector, FIND_OBJ_ROOM)) {
      if (*tar_obj = get_obj_vis_accessible(ch, name)) {
	return(FIND_OBJ_INV);
      }
    } else {
      if (*tar_obj = get_obj_in_list_vis(ch, name, ch->carrying)) {
	return(FIND_OBJ_INV);
      }
    }
  }
  
  if (IS_SET(bitvector, FIND_OBJ_ROOM)) {
    if (*tar_obj = get_obj_in_list_vis(ch, name, real_roomp(ch->in_room)->contents)) {
      return(FIND_OBJ_ROOM);
    }
  }
  
  if (IS_SET(bitvector, FIND_OBJ_WORLD)) {
    if (*tar_obj = get_obj_vis(ch, name)) {
      return(FIND_OBJ_WORLD);
    }
  }
  
  return(0);
}
void do_look(struct char_data *ch, char *argument, int cmd)
{
    char buffer[MAX_STRING_LENGTH];
    char arg1[MAX_STRING_LENGTH];
    char arg2[MAX_STRING_LENGTH];
    int keyword_no;
    int j, bits, temp;
    bool found;
    struct obj_data *tmp_object, *found_object;
    struct char_data *tmp_char;
    char *tmp_desc;
    static char *keywords[]= {
        "north",
        "east",
        "south",
        "west",
        "up",
        "down",
        "in",
        "at",
        "",  /* Look at '' case */
        "\n"
    };

    if (!ch->desc)
        return;

    if (GET_POS(ch) < POSITION_SLEEPING)
        send_to_char("You can't see anything but stars!\n\r", ch);
    else if (GET_POS(ch) == POSITION_SLEEPING)
        send_to_char("You can't see anything, you're sleeping!\n\r", ch);
    else if ( IS_AFFECTED(ch, AFF_BLIND) )
        send_to_char("You can't see a damn thing, you're blinded!\n\r", ch);
    else if ( IS_DARK(ch->in_room) )
        send_to_char("It is pitch black...\n\r", ch);
    else {
        argument_split_2(argument,arg1,arg2);
        keyword_no = search_block(arg1, keywords, FALSE); /* Partiel Match */

        if ((keyword_no == -1) && *arg1) {
            keyword_no = 7;
            strcpy(arg2, arg1); /* Let arg2 become the target object (arg1) */
        }

        found = FALSE;
        tmp_object = 0;
        tmp_char	 = 0;
        tmp_desc	 = 0;

        switch(keyword_no) {
        /* look <dir> */
        case 0 :
        case 1 :
        case 2 :
        case 3 :
        case 4 :
        case 5 : {

            if (EXIT(ch, keyword_no)) {

                if (EXIT(ch, keyword_no)->general_description) {
                    send_to_char(EXIT(ch, keyword_no)->
                                 general_description, ch);
                } else {
                    send_to_char("You see nothing special.\n\r", ch);
                }

                if (IS_SET(EXIT(ch, keyword_no)->exit_info, EX_CLOSED) &&
                        (EXIT(ch, keyword_no)->keyword)) {
                    sprintf(buffer, "The %s is closed.\n\r",
                            fname(EXIT(ch, keyword_no)->keyword));
                    send_to_char(buffer, ch);
                }	else {
                    if (IS_SET(EXIT(ch, keyword_no)->exit_info, EX_ISDOOR) &&
                            EXIT(ch, keyword_no)->keyword) {
                        sprintf(buffer, "The %s is open.\n\r",
                                fname(EXIT(ch, keyword_no)->keyword));
                        send_to_char(buffer, ch);
                    }
                }
            } else {
                send_to_char("Nothing special there...\n\r", ch);
            }
        }
        break;

        /* look 'in'	*/
        case 6: {
            if (*arg2) {
                /* Item carried */

                bits = generic_find(arg2, FIND_OBJ_INV | FIND_OBJ_ROOM |
                                    FIND_OBJ_EQUIP, ch, &tmp_char, &tmp_object);

                if (bits) { /* Found something */
                    if (GET_ITEM_TYPE(tmp_object)== ITEM_DRINKCON)
                    {
                        if (tmp_object->obj_flags.value[1] <= 0) {
                            act("It is empty.", FALSE, ch, 0, 0, TO_CHAR);
                        } else {
                            temp=((tmp_object->obj_flags.value[1]*3)/tmp_object->obj_flags.value[0]);
                            sprintf(buffer,"It's %sfull of a %s liquid.\n\r",
                                    fullness[temp],color_liquid[tmp_object->obj_flags.value[2]]);
                            send_to_char(buffer, ch);
                        }
                    } else if (GET_ITEM_TYPE(tmp_object) == ITEM_CONTAINER) {
                        if (!IS_SET(tmp_object->obj_flags.value[1],CONT_CLOSED)) {
                            send_to_char(fname(tmp_object->name), ch);
                            switch (bits) {
                            case FIND_OBJ_INV :
                                send_to_char(" (carried) : \n\r", ch);
                                break;
                            case FIND_OBJ_ROOM :
                                send_to_char(" (here) : \n\r", ch);
                                break;
                            case FIND_OBJ_EQUIP :
                                send_to_char(" (used) : \n\r", ch);
                                break;
                            }
                            list_obj_to_char(tmp_object->contains, ch, 2, TRUE);
                        }
                        else
                            send_to_char("It is closed.\n\r", ch);
                    } else {
                        send_to_char("That is not a container.\n\r", ch);
                    }
                } else { /* wrong argument */
                    send_to_char("You do not see that item here.\n\r", ch);
                }
            } else { /* no argument */
                send_to_char("Look in what?!\n\r", ch);
            }
        }
        break;

        /* look 'at'	*/
        case 7 : {


            if (*arg2) {

                bits = generic_find(arg2, FIND_OBJ_INV | FIND_OBJ_ROOM |
                                    FIND_OBJ_EQUIP | FIND_CHAR_ROOM, ch, &tmp_char, &found_object);

                if (tmp_char) {
                    show_char_to_char(tmp_char, ch, 1);
                    if (ch != tmp_char) {
                        act("$n looks at you.", TRUE, ch, 0, tmp_char, TO_VICT);
                        act("$n looks at $N.", TRUE, ch, 0, tmp_char, TO_NOTVICT);
                    }
                    return;
                }


                /* Search for Extra Descriptions in room and items */

                /* Extra description in room?? */
                if (!found) {
                    tmp_desc = find_ex_description(arg2,
                                                   world[ch->in_room].ex_description);
                    if (tmp_desc) {
                        page_string(ch->desc, tmp_desc, 0);
                        return; /* RETURN SINCE IT WAS A ROOM DESCRIPTION */
                        /* Old system was: found = TRUE; */
                    }
                }

                /* Search for extra descriptions in items */

                /* Equipment Used */

                if (!found) {
                    for (j = 0; j< MAX_WEAR && !found; j++) {
                        if (ch->equipment[j]) {
                            if (CAN_SEE_OBJ(ch,ch->equipment[j])) {
                                tmp_desc = find_ex_description(arg2,
                                                               ch->equipment[j]->ex_description);
                                if (tmp_desc) {
                                    page_string(ch->desc, tmp_desc, 1);
                                    found = TRUE;
                                }
                            }
                        }
                    }
                }

                /* In inventory */

                if (!found) {
                    for(tmp_object = ch->carrying;
                            tmp_object && !found;
                            tmp_object = tmp_object->next_content) {
                        if CAN_SEE_OBJ(ch, tmp_object) {
                            tmp_desc = find_ex_description(arg2,
                                                           tmp_object->ex_description);
                            if (tmp_desc) {
                                page_string(ch->desc, tmp_desc, 1);
                                found = TRUE;
                            }
                        }
                    }
                }

                /* Object In room */

                if (!found) {
                    for(tmp_object = world[ch->in_room].contents;
                            tmp_object && !found;
                            tmp_object = tmp_object->next_content) {
                        if CAN_SEE_OBJ(ch, tmp_object) {
                            tmp_desc = find_ex_description(arg2,
                                                           tmp_object->ex_description);
                            if (tmp_desc) {
                                page_string(ch->desc, tmp_desc, 1);
                                found = TRUE;
                            }
                        }
                    }
                }
                /* wrong argument */

                if (bits) { /* If an object was found */
                    if (!found)
                        show_obj_to_char(found_object, ch, 5); /* Show no-description */
                    else
                        show_obj_to_char(found_object, ch, 6); /* Find hum, glow etc */
                } else if (!found) {
                    send_to_char("You do not see that here.\n\r", ch);
                }
            } else {
                /* no argument */

                send_to_char("Look at what?\n\r", ch);
            }
        }
Beispiel #16
0
struct creature *
load_player_from_file(const char *path)
{
    struct creature *ch = NULL;
    char *txt;

    if (access(path, W_OK)) {
        errlog("Unable to open xml player file '%s': %s", path,
            strerror(errno));
        return NULL;
    }
    xmlDocPtr doc = xmlParseFile(path);
    if (!doc) {
        errlog("XML parse error while loading %s", path);
        return NULL;
    }

    xmlNodePtr root = xmlDocGetRootElement(doc);
    if (!root) {
        xmlFreeDoc(doc);
        errlog("XML file %s is empty", path);
        return NULL;
    }

    /* to save memory, only PC's -- not MOB's -- have player_specials */
    ch = make_creature(true);

    ch->player.name = (char *)xmlGetProp(root, (xmlChar *) "name");
    ch->char_specials.saved.idnum = xmlGetIntProp(root, "idnum", 0);
    set_title(ch, "");

    ch->player.short_descr = NULL;
    ch->player.long_descr = NULL;

    if (ch->points.max_mana < 100)
        ch->points.max_mana = 100;

    ch->char_specials.carry_weight = 0;
    ch->char_specials.carry_items = 0;
    ch->char_specials.worn_weight = 0;
    ch->points.armor = 100;
    ch->points.hitroll = 0;
    ch->points.damroll = 0;
    ch->player_specials->saved.speed = 0;

    // Read in the subnodes
    for (xmlNodePtr node = root->xmlChildrenNode; node; node = node->next) {
        if (xmlMatches(node->name, "points")) {
            ch->points.mana = xmlGetIntProp(node, "mana", 100);
            ch->points.max_mana = xmlGetIntProp(node, "maxmana", 100);
            ch->points.hit = xmlGetIntProp(node, "hit", 100);
            ch->points.max_hit = xmlGetIntProp(node, "maxhit", 100);
            ch->points.move = xmlGetIntProp(node, "move", 100);
            ch->points.max_move = xmlGetIntProp(node, "maxmove", 100);
        } else if (xmlMatches(node->name, "money")) {
            ch->points.gold = xmlGetIntProp(node, "gold", 0);
            ch->points.cash = xmlGetIntProp(node, "cash", 0);
            ch->points.exp = xmlGetIntProp(node, "xp", 0);
        } else if (xmlMatches(node->name, "stats")) {
            ch->player.level = xmlGetIntProp(node, "level", 0);
            ch->player.height = xmlGetIntProp(node, "height", 0);
            ch->player.weight = xmlGetIntProp(node, "weight", 0);
            GET_ALIGNMENT(ch) = xmlGetIntProp(node, "align", 0);
            /***
                Temp fix for negative weights
             ***/

            if (ch->player.weight < 0) {
                calculate_height_weight(ch);
            }

            GET_SEX(ch) = 0;
            char *sex = (char *)xmlGetProp(node, (xmlChar *) "sex");
            if (sex != NULL)
                GET_SEX(ch) = search_block(sex, genders, false);
            free(sex);

            GET_RACE(ch) = 0;
            char *race_name = (char *)xmlGetProp(node, (xmlChar *) "race");
            if (race_name != NULL) {
                struct race *race = race_by_name(race_name, true);
                if (race != NULL) {
                    GET_RACE(ch) = race->idnum;
                }
            }
            free(race_name);

        } else if (xmlMatches(node->name, "class")) {
            GET_OLD_CLASS(ch) = GET_REMORT_CLASS(ch) = GET_CLASS(ch) = -1;

            char *trade = (char *)xmlGetProp(node, (xmlChar *) "name");
            if (trade != NULL) {
                GET_CLASS(ch) = search_block(trade, class_names, false);
                free(trade);
            }

            trade = (char *)xmlGetProp(node, (xmlChar *) "remort");
            if (trade != NULL) {
                GET_REMORT_CLASS(ch) = search_block(trade, class_names, false);
                free(trade);
            }

            if (IS_CYBORG(ch)) {
                char *subclass =
                    (char *)xmlGetProp(node, (xmlChar *) "subclass");
                if (subclass != NULL) {
                    GET_OLD_CLASS(ch) = search_block(subclass,
                        borg_subchar_class_names, false);
                    free(subclass);
                }
            }

            if (GET_CLASS(ch) == CLASS_MAGE) {
                ch->player_specials->saved.mana_shield_low =
                    xmlGetLongProp(node, "manash_low", 0);
                ch->player_specials->saved.mana_shield_pct =
                    xmlGetLongProp(node, "manash_pct", 0);
            }

            GET_REMORT_GEN(ch) = xmlGetIntProp(node, "gen", 0);
            GET_TOT_DAM(ch) = xmlGetIntProp(node, "total_dam", 0);
            GET_BROKE(ch) = xmlGetIntProp(node, "broken", 0);
        } else if (xmlMatches(node->name, "time")) {
            ch->player.time.birth = xmlGetLongProp(node, "birth", 0);
            ch->player.time.death = xmlGetLongProp(node, "death", 0);
            ch->player.time.played = xmlGetLongProp(node, "played", 0);
            ch->player.time.logon = xmlGetLongProp(node, "last", 0);
        } else if (xmlMatches(node->name, "carnage")) {
            GET_PKILLS(ch) = xmlGetIntProp(node, "pkills", 0);
            GET_ARENAKILLS(ch) = xmlGetIntProp(node, "akills", 0);
            GET_MOBKILLS(ch) = xmlGetIntProp(node, "mkills", 0);
            GET_PC_DEATHS(ch) = xmlGetIntProp(node, "deaths", 0);
            RAW_REPUTATION_OF(ch) = xmlGetIntProp(node, "reputation", 0);
            GET_SEVERITY(ch) = xmlGetIntProp(node, "severity", 0);
        } else if (xmlMatches(node->name, "attr")) {
            ch->aff_abils.str = ch->real_abils.str =
                xmlGetIntProp(node, "str", 0);
            ch->aff_abils.str = ch->real_abils.str +=
                xmlGetIntProp(node, "stradd", 0) / 10;
            ch->aff_abils.intel = ch->real_abils.intel =
                xmlGetIntProp(node, "int", 0);
            ch->aff_abils.wis = ch->real_abils.wis =
                xmlGetIntProp(node, "wis", 0);
            ch->aff_abils.dex = ch->real_abils.dex =
                xmlGetIntProp(node, "dex", 0);
            ch->aff_abils.con = ch->real_abils.con =
                xmlGetIntProp(node, "con", 0);
            ch->aff_abils.cha = ch->real_abils.cha =
                xmlGetIntProp(node, "cha", 0);
        } else if (xmlMatches(node->name, "condition")) {
            GET_COND(ch, THIRST) = xmlGetIntProp(node, "thirst", 0);
            GET_COND(ch, FULL) = xmlGetIntProp(node, "hunger", 0);
            GET_COND(ch, DRUNK) = xmlGetIntProp(node, "drunk", 0);
        } else if (xmlMatches(node->name, "player")) {
            GET_WIMP_LEV(ch) = xmlGetIntProp(node, "wimpy", 0);
            GET_LIFE_POINTS(ch) = xmlGetIntProp(node, "lp", 0);
            GET_CLAN(ch) = xmlGetIntProp(node, "clan", 0);
        } else if (xmlMatches(node->name, "home")) {
            GET_HOME(ch) = xmlGetIntProp(node, "town", 0);
            GET_HOMEROOM(ch) = xmlGetIntProp(node, "homeroom", 0);
            GET_LOADROOM(ch) = xmlGetIntProp(node, "loadroom", 0);
        } else if (xmlMatches(node->name, "quest")) {
            GET_QUEST(ch) = xmlGetIntProp(node, "current", 0);
            GET_IMMORT_QP(ch) = xmlGetIntProp(node, "points", 0);
            GET_QUEST_ALLOWANCE(ch) = xmlGetIntProp(node, "allowance", 0);
        } else if (xmlMatches(node->name, "bits")) {
            char *flag = (char *)xmlGetProp(node, (xmlChar *) "flag1");
            ch->char_specials.saved.act = hex2dec(flag);
            free(flag);

            flag = (char *)xmlGetProp(node, (xmlChar *) "flag2");
            ch->player_specials->saved.plr2_bits = hex2dec(flag);
            free(flag);
        } else if (xmlMatches(node->name, "frozen")) {
            ch->player_specials->thaw_time =
                xmlGetIntProp(node, "thaw_time", 0);
            ch->player_specials->freezer_id =
                xmlGetIntProp(node, "freezer_id", 0);
        } else if (xmlMatches(node->name, "prefs")) {
            char *flag = (char *)xmlGetProp(node, (xmlChar *) "flag1");
            ch->player_specials->saved.pref = hex2dec(flag);
            free(flag);

            flag = (char *)xmlGetProp(node, (xmlChar *) "flag2");
            ch->player_specials->saved.pref2 = hex2dec(flag);
            free(flag);

            flag = (char *)xmlGetProp(node, (xmlChar *) "tongue");
            if (flag)
                GET_TONGUE(ch) = find_tongue_idx_by_name(flag);
            free(flag);
        } else if (xmlMatches(node->name, "weaponspec")) {
            int vnum = xmlGetIntProp(node, "vnum", -1);
            int level = xmlGetIntProp(node, "level", 0);
            if (vnum > 0 && level > 0) {
                for (int i = 0; i < MAX_WEAPON_SPEC; i++) {
                    if (GET_WEAP_SPEC(ch, i).level <= 0) {
                        GET_WEAP_SPEC(ch, i).vnum = vnum;
                        GET_WEAP_SPEC(ch, i).level = level;
                        break;
                    }
                }
            }
        } else if (xmlMatches(node->name, "title")) {
            char *txt;

            txt = (char *)xmlNodeGetContent(node);
            set_title(ch, txt);
            free(txt);
        } else if (xmlMatches(node->name, "affect")) {
            struct affected_type af;
            init_affect(&af);
            af.type = xmlGetIntProp(node, "type", 0);
            af.duration = xmlGetIntProp(node, "duration", 0);
            af.modifier = xmlGetIntProp(node, "modifier", 0);
            af.location = xmlGetIntProp(node, "location", 0);
            af.level = xmlGetIntProp(node, "level", 0);
            af.aff_index = xmlGetIntProp(node, "index", 0);
            af.owner = xmlGetIntProp(node, "owner", 0);
            af.next = NULL;
            char *instant = (char *)xmlGetProp(node, (xmlChar *) "instant");
            if (instant != NULL && strcmp(instant, "yes") == 0) {
                af.is_instant = 1;
            }
            free(instant);

            char *bits = (char *)xmlGetProp(node, (xmlChar *) "affbits");
            af.bitvector = hex2dec(bits);
            free(bits);

            affect_to_char(ch, &af);

        } else if (xmlMatches(node->name, "affects")) {
            // PCs shouldn't have ANY perm affects
            if (IS_NPC(ch)) {
                char *flag = (char *)xmlGetProp(node, (xmlChar *) "flag1");
                AFF_FLAGS(ch) = hex2dec(flag);
                free(flag);

                flag = (char *)xmlGetProp(node, (xmlChar *) "flag2");
                AFF2_FLAGS(ch) = hex2dec(flag);
                free(flag);

                flag = (char *)xmlGetProp(node, (xmlChar *) "flag3");
                AFF3_FLAGS(ch) = hex2dec(flag);
                free(flag);
            } else {
                AFF_FLAGS(ch) = 0;
                AFF2_FLAGS(ch) = 0;
                AFF3_FLAGS(ch) = 0;
            }

        } else if (xmlMatches(node->name, "skill")) {
            char *spellName = (char *)xmlGetProp(node, (xmlChar *) "name");
            int index = str_to_spell(spellName);
            if (index >= 0) {
                SET_SKILL(ch, index, xmlGetIntProp(node, "level", 0));
            }
            free(spellName);
        } else if (xmlMatches(node->name, "tongue")) {
            char *tongue = (char *)xmlGetProp(node, (xmlChar *) "name");
            int index = find_tongue_idx_by_name(tongue);
            if (index >= 0)
                SET_TONGUE(ch, index,
                    MIN(100, xmlGetIntProp(node, "level", 0)));
            free(tongue);
        } else if (xmlMatches(node->name, "alias")) {
            struct alias_data *alias;
            CREATE(alias, struct alias_data, 1);
            alias->type = xmlGetIntProp(node, "type", 0);
            alias->alias = (char *)xmlGetProp(node, (xmlChar *) "alias");
            alias->replacement =
                (char *)xmlGetProp(node, (xmlChar *) "replace");
            if (alias->alias == NULL || alias->replacement == NULL) {
                free(alias);
            } else {
                add_alias(ch, alias);
            }
        } else if (xmlMatches(node->name, "description")) {
            txt = (char *)xmlNodeGetContent(node);
            ch->player.description = strdup(tmp_gsub(txt, "\n", "\r\n"));
            free(txt);
        } else if (xmlMatches(node->name, "poofin")) {
            POOFIN(ch) = (char *)xmlNodeGetContent(node);
        } else if (xmlMatches(node->name, "poofout")) {
            POOFOUT(ch) = (char *)xmlNodeGetContent(node);
        } else if (xmlMatches(node->name, "immort")) {
            txt = (char *)xmlGetProp(node, (xmlChar *) "badge");
            strncpy(BADGE(ch), txt, 7);
            BADGE(ch)[7] = '\0';
            free(txt);

            GET_QLOG_LEVEL(ch) = xmlGetIntProp(node, "qlog", 0);
            GET_INVIS_LVL(ch) = xmlGetIntProp(node, "invis", 0);
        } else if (xmlMatches(node->name, "rent")) {
            char *txt;

            ch->player_specials->rentcode = xmlGetIntProp(node, "code", 0);
            ch->player_specials->rent_per_day =
                xmlGetIntProp(node, "perdiem", 0);
            ch->player_specials->rent_currency =
                xmlGetIntProp(node, "currency", 0);
            txt = (char *)xmlGetProp(node, (xmlChar *) "state");
            if (txt)
                ch->player_specials->desc_mode =
                    (enum cxn_state)search_block(txt, desc_modes, false);
            free(txt);
        } else if (xmlMatches(node->name, "recentkill")) {
            struct kill_record *kill;

            CREATE(kill, struct kill_record, 1);
            kill->vnum = xmlGetIntProp(node, "vnum", 0);
            kill->times = xmlGetIntProp(node, "times", 0);
            GET_RECENT_KILLS(ch) = g_list_prepend(GET_RECENT_KILLS(ch), kill);
        } else if (xmlMatches(node->name, "grievance")) {
Beispiel #17
0
void parse_quest(FILE *quest_file, int vnum)
{
  static int i = 0;

  struct char_data *mob = NULL;
  char line[MAX_INPUT_LENGTH];
  char value[MAX_INPUT_LENGTH];
  char field[20];
  int numval = 0;
  int nummsgs = 0;
  int numneeds = 0;
  int mob_rnum = 0;

  i++;
  mob_rnum = real_mobile(vnum);
  if (mob_rnum == -1) {
    stderr_log("Error trying to assign quest to non-existant mob.");
    fflush(NULL);
    exit(1);
  }
  mob = (mob_proto + mob_rnum);
  GET_MOB_QUEST_NUM(mob) = i;
  (mob_quests + i)->maxlevel = 51;
  (mob_quests + i)->qnum = i;
  while (get_line(quest_file, line)) {
    if (line[0] == 'S') {
      return;
    }
    parse_pline(line, field, value);
    numval = atoi(value);

    switch (UPPER(*field)) {
      case 'A':
        if (strcmp(field, "amount") == 0) {
          (mob_quests + i)->needs[numneeds].amount = numval;
          numneeds++;
          (mob_quests + i)->maxneeds = numneeds;
        } else {
          sprintf(buf2, "Unknown Quest field [%s]", field);
          stderr_log(buf2);
        }
        break;
      case 'C':
        if (strcmp(field, "classlist") == 0) {
          (mob_quests + i)->classlist = asciiflag_conv(value);
        } else {
          sprintf(buf2, "Unknown Quest field [%s]", field);
          stderr_log(buf2);
        }
        break;
      case 'D':
        if (strcmp(field, "destroy") == 0) {
          if (strcasecmp(value, "no") == 0) {
            (mob_quests + i)->needs[numneeds].destroy = 0;
          }
        } else {
          sprintf(buf2, "Unknown Quest field [%s]", field);
          stderr_log(buf2);
        }
        break;
      case 'F':
        if (strcmp(field, "flags") == 0) {
          (mob_quests + i)->flags = asciiflag_conv(value);
        } else {
          sprintf(buf2, "Unknown Quest field [%s]", field);
          stderr_log(buf2);
        }
        break;
      case 'G':
        if (strcmp(field, "goal") == 0) {
          (mob_quests + i)->goal = search_block(value, goal_list, FALSE);
        } else {
          sprintf(buf2, "Unknown Quest field [%s]", field);
          stderr_log(buf2);
        }
        break;
      case 'K':
        if (strcmp(field, "keywords") == 0) {
          RECREATE((mob_quests + i)->messages, struct quest_message_data, nummsgs + 1);
          (mob_quests + i)->messages[nummsgs].keywords = strdup(value);
        } else if (strcmp(field, "knowledge") == 0) {
          line[0] = '\0';
          (mob_quests + i)->knowledge = fread_string(quest_file, line);
        } else {
          sprintf(buf2, "Unknown Quest field [%s]", field);
          stderr_log(buf2);
        }
        break;
      case 'M':
        if (strcmp(field, "maxlevel") == 0) {
          (mob_quests + i)->maxlevel = numval;
        } else if (strcmp(field, "message") == 0) {
          line[0] = '\0';
          (mob_quests + i)->messages[nummsgs].message = fread_string(quest_file, line);
          nummsgs++;
          (mob_quests + i)->maxmsgs = nummsgs;
        } else {
          sprintf(buf2, "Unknown Quest field [%s]", field);
          stderr_log(buf2);
        }
        break;
      case 'N':
        if (strcmp(field, "needs") == 0) {
          RECREATE((mob_quests + i)->needs, struct quest_needs_data, numneeds + 1);
          (mob_quests + i)->needs[numneeds].destroy = 1;
          (mob_quests + i)->needs[numneeds].participants = NULL;
          (mob_quests + i)->needs[numneeds].type = search_block(value, needs_list, FALSE);
          (mob_quests + i)->needs[numneeds].complete = 0;
          (mob_quests + i)->needs[numneeds].needs_complete_msg = NULL;
          (mob_quests + i)->needs[numneeds].need_more_msg = NULL;
        } else if (strcmp(field, "need_more_msg") == 0) {
Beispiel #18
0
/* OLC interpreter command; called by do_olc */
void olc_interpreter(void *targ, int mode, char *arg)
{
  int error = 0, command;
  char command_string[MAX_INPUT_LENGTH];
  struct char_data *olc_mob = NULL;
  struct room_data *olc_room = NULL;
  struct obj_data *olc_obj = NULL;

  half_chop(arg, command_string, arg);
  if ((command = search_block(command_string, olc_commands, FALSE)) < 0) {
    sprintf(buf, "Invalid OLC command '%s'.\r\n", command_string);
    send_to_char(buf, olc_ch);
    return;
  }
  switch (mode) {
  case OLC_ROOM:
    olc_room = (struct room_data *) targ;
    break;
  case OLC_MOB:
    olc_mob = (struct char_data *) targ;
    break;
  case OLC_OBJ:
    olc_obj = (struct obj_data *) targ;
    break;
  default:
    log("SYSERR: Invalid OLC mode %d passed to interp.", mode);
    return;
  }


  switch (command) {
  case OLC_COPY:
    switch (mode) {
    case OLC_ROOM:
      break;
    case OLC_MOB:
      break;
    case OLC_OBJ:
      break;
    default:
      error = 1;
      break;
    }
    break;
  case OLC_NAME:
    switch (mode) {
    case OLC_ROOM:
      olc_string(&(olc_room->name), MAX_ROOM_NAME, arg);
      break;
    case OLC_MOB:
      olc_string(&olc_mob->player.short_descr, MAX_MOB_NAME, arg);
      break;
    case OLC_OBJ:
      olc_string(&olc_obj->short_description, MAX_OBJ_NAME, arg);
      break;
    default:
      error = 1;
      break;
    }
    break;

  case OLC_DESC:
    switch (mode) {
    case OLC_ROOM:
      olc_string(&olc_room->description, MAX_ROOM_DESC, arg);
      break;
    case OLC_MOB:
      olc_string(&olc_mob->player.long_descr, MAX_MOB_DESC, arg);
      break;
    case OLC_OBJ:
      olc_string(&olc_obj->description, MAX_OBJ_DESC, arg);
      break;
    default:
      error = 1;
      break;
    }
    break;

  case OLC_ALIASES:
    switch (mode) {
    case OLC_ROOM:
      break;
    case OLC_MOB:
      break;
    case OLC_OBJ:
      break;
    default:
      error = 1;
      break;
    }

  }
}