File writing of flags


  • retired

    This is a reminder to myself to change the writing and reading of flags, per Nib's request. Currently it just writes the flag field as an integer to file, which works perfectly well, if you're a computer. I want to change it to write the string of flags, in a format such as is seen in the flags fields in OLC editors.

    This has several advantages, as Nib has pointed out:
    [list]
  • [*]People who work on the area files but don't have access to the code (e.g. Nib with the wilderness) won't have to know the bit values for the flags.
  • [*]It will make area files much easier to read and modify manually.
  • [*]"It eliminates the possibility of garbage bits that may or may not have cropped into the number and adding erroneous its, as the output string and loaded flag value only use what bits/stats you give the functions."
  • [/list] ROM has a function to take a long integer and convert it to a string of flags. This is used already to display stuff like strings of flags when editing in OLC.

    In save_room_new, we would make the following modification: [code] ... fprintf(fp, "RoomFlagString %s~", flag_string(room_flags, room->room_flags); ... [/code] There is also a function (flag_value) which eats a string of flags, converts each word into its respective bitmask, and returns a long integer with each of those bits on.

    So we would modify read_room_new thusly: [code] ... if (!str_cmp(word, "RoomFlagString")) { char *flag_string; flag_string = fread_string(fp); room->room_flags = flag_value(room_flags, flag_string); } ... KEY("Room_flags", room->flags, fread_number(fp)); ... [/code] We will have to stick in something which will allow both the old and new versions to be read; as an example we can change the keyword we use for the flag in the file (in this example, I kept Room_flags for the old, integer format and RoomFlagString for the new, string format). This allows both the new and old version to be read.

    Consistent coding dictates that we change any flag related sections in player files, area files, and whatever else to write flags as strings instead of the whole bitfield. This shouldn't be a problem since the functions are written for us already, and we just have to implement them.

Log in to reply