/* Thri's extra2_flags.c
 *
 * Thri - cyhawk@comcast.net
 *
 * The Realms of Soulblight:  http://soulblight.slayn.net
 *                            telnet://soulblight.slayn.net:5500
 * Stop in some time =)
 *
 * "An updated approch to extra2 flags."
 *
 */

/*
 * I wrote this using Cygwin, QuickMud (non-unlimited bits obviosuly ;)
 * I did it the first time, and, using my guide i wrote out, added an extra3
 * flags as well. So im pretty sure it works. If you come across any problems,
 * make sure..
 * A) YOU BACKED UP FIRST
 * B) You followed the steps 1-19 in order
 *
 * if all else fails, restore from backup, and try agian.
 */

BACK UP YOUR CODE   BACK UP YOUR CODE   BACK UP YOUR CODE   BACK UP YOUR CODE
BACK UP YOUR CODE   BACK UP YOUR CODE   BACK UP YOUR CODE   BACK UP YOUR CODE
BACK UP YOUR CODE   BACK UP YOUR CODE   BACK UP YOUR CODE   BACK UP YOUR CODE
BACK UP YOUR CODE   BACK UP YOUR CODE   BACK UP YOUR CODE   BACK UP YOUR CODE
BACK UP YOUR CODE   BACK UP YOUR CODE   BACK UP YOUR CODE   BACK UP YOUR CODE
BACK UP YOUR CODE   BACK UP YOUR CODE   BACK UP YOUR CODE   BACK UP YOUR CODE
BACK UP YOUR CODE   BACK UP YOUR CODE   BACK UP YOUR CODE   BACK UP YOUR CODE
BACK UP YOUR CODE   BACK UP YOUR CODE   BACK UP YOUR CODE   BACK UP YOUR CODE
AND AREAS        AND AREAS        AND AREAS        AND AREAS        AND AREAS
=)
Pfiles wouldnt hurt either.


Hello All. I was looking around for an extra2_flags for items, but didn't have
any luck at all. (Well the one i found was writen for merc 2.1, and its very
badly outdated for us Rom users ;)

So, after about 2 hours of Trial and error, i finally got it to work perfectly.
Since i belive in sharing, im donating these 2 (now 3 for the helpfile ;) to
the mudding community.

Files that need changing:
	act_wiz.c
	bit.c
	db2.c
	handler.c
	mem.c
	merc.h
	olc_act.c
	olc_save.c
	save.c

Step 1: lets start with merc.h.

	find:	 struct obj_index_data
	and..	 struct obj_data

 Right under (in obj_index_data)
	'  int extra_flags;'
	put..
	'  int extra2_flags;'
 and do the same for obj_data.

step 2:
	Preferbly near the other ITEM_ stuff, add
#define ITEM2_TEST	(A)


Step 3:
	find 'IS_OBJ_STAT'	(Object macros)

	copy that line, and paste it right underneath and change IS_OBJ_STAT to IS_OBJ2_STAT
	and extra_flags to extra2_flags.

Step 4:
	find 'extra_bit_name'
	copy that one, and paste it underneath agian
	as extra2_bit_name (int extra2_flags)

merc.h is done.
next up, act_wiz.c

step 5:	in do_ostat find the section that deals with showing extra bits..
		and underneath it.. put..

  sprintf (buf, "Extra2 bits: %s\n\r",
	   extra2_bit_name (obj->extra2_flags));
  send_to_char (buf, ch);

next, handler.c

step 6:
	inside handler.c, somewhere (next to the normal extra flags is always good)
	put a table in that looks like this..

char *
extra2_bit_name (int extra2_flags)
{
  static char buf[512];

  buf[0] = '\0';
  if (extra2_flags & ITEM2_TEST)
    strcat (buf, " test flag");

  return (buf[0] != '\0') ? buf + 1 : "none";
}


next, mem.c
step 7:	inside new_obj_index(void) put in

		pObj->extra2_flags = 0;


Step 8: Checking.. you did backup before now right? =)

next tables.h
step 9:
	since OLC complains if things are defined.. somewhere in tables.h
	put
	extern	const	struct	flag_type	extra2_flags[];



next up, olc_save.c

Step 10:

	Now, since we don't ever want to hand edit any sort of area file
	ever. (Thats why Odin invented MZF right?) Were going to convert
	the areas before we will load them via OLC.

	So, open up olc_save.c

	(a side note, for some reason it didnt like all the pretty one line flag things,
	so, i put extra2 above those, and right under material..)

	in save_object
	underneath..
  fprintf (fp, "%s~\n", pObjIndex->material);
  add
  fprintf (fp, "%s\n", fwrite_flag (pObjIndex->extra2_flags, buf));


Step 11: (The moment of Truth)

	Alright, now, clean complie, and start up the mud.
	You shouldnt get any errors at this point, as
	all the basics are in there. When your mud starts up,
	it will be loading the areas as normal. However,
	we need to save them in the new format. So.. once the mud is up,
	asave world, and shutdown.

	(if you get an error during asave world, it will most likely croupt some, if not
	all your area files. As ive stated before, you /DID/ backup right?)
	Some common errors during this stage i found were buffer overflows.
	I ended up just incressing the buffers and recomplining first, but
	you can do what you feel is right here. ;)

	So, agian, thats..

	startup mud
	asave world
	shutdown

Step 12:
	Ok, so all your area files are converted properly via OLC.

	Now, we have to make it so it will read the new field correct? ;)

Open up db2.c
 in load_objects(FILE * fp)

 find where it sets  pObjIndex->material
 and right under it, put..
      pObjIndex->extra2_flags = fread_flag (fp);

 (it has to be here, because OLC saved it here ;)

Step 13:
	Just a check, start back up the mud, make sure everything loads
	properly. If so, execlent (Im paranoid like that)

Step 14: (optional, but a good step anyhow)
	Now, we want these new items to save properly in the pfiles,
	so, open up save.c
	in fwrite_obj
	find where it writes
	fprintf (fp, "ExtF %d\n", obj->extra_flags);

	and right below it, put

  if (obj->extra_flags != obj->pIndexData->extra2_flags)
    fprintf (fp, "ExtF2 %d\n", obj->extra2_flags);

Step 15:
	also in save.c, find
	fread_obj

	down in the big ugly but good case switch, Find
	case 'E':
	and at the bottom
	copy the
	ExtF line, paste it right underneath,and put an extra 2 at the end.
	to make it ExtF2 (you will also need to change the obj->extra_flags to extra2)

Step 16:
	Ok, now, we want OLC to be able to set Extra2 flags right? (unless you LIKE hand
	editing area files every time you want an item to have an extra2 flag :P)

	find
	const struct olc_cmd_type oedit_table[]
	and put
	{"extra2", oedit_extra2},
	in there somewhere. (Under "extra" is good)

step 17:
	in file olc.h
	Somewhere, anywhere really, put
DECLARE_OLC_FUN( oedit_extra2		);

Step 18:
	inside olc_act.c
	find
	const struct olc_help_type help_table[] = {
	put under "extra"
	{"extra2", extra2_flags, "Object2 attributes."},

	in OEDIT (oedit_show)

	Under extra, put

  sprintf (buf, "Extra2 flags: [%s]\n\r",
	   flag_string (extra2_flags, pObj->extra2_flags));
  send_to_char (buf, ch);


and step 19, put somewhere at the end of olc_act.c

OEDIT (oedit_extra2)
{				/* Moved out of oedit() due to naming conflicts -- Hugin */
  OBJ_INDEX_DATA *pObj;
  int value;

  if (argument[0] != '\0')
    {
      EDIT_OBJ (ch, pObj);

      if ((value = flag_value (extra2_flags, argument)) != NO_FLAG)
	{
	  TOGGLE_BIT (pObj->extra2_flags, value);

	  send_to_char ("Extra2 flag toggled.\n\r", ch);
	  return TRUE;
	}
    }

  send_to_char ("Syntax:  extra2 [flag]\n\r"
		"Type '? extra2' for a list of flags.\n\r", ch);
  return FALSE;
}

Now, make, and start up the mud.

Ok, So everything should be set.
edit an item, try to put TEST2 on it, see if it shows up, save it, reboot, load it, save, quit,
reload, make sure it all saves properly, and your set.