Re: Bit Flags

From: Daniel A. Koepke (
Date: 06/19/01

On Wed, 20 Jun 2001, Jonathan Syu wrote:

> But is there same way so that we don't have to delete the saved player
> objects?

Only through converting those files.  A rough start with some Mailer

  #include "conf.h"
  #include "sysdep.h"

  #include "structs.h"

  struct old_obj_file_elem {
     * Your old obj_file_elem contents, here.  E.g., the contents as
     * they are in your rent files.

  void convert_old_to_new(const struct old_obj_file_elem *oofe,
                          struct obj_file_elem *nofe)
     nofe->item_number = oofe->item_number;
    nofe->location = oofe->location;
    memcpy(nofe->value, oofe->value, 4*sizeof(int));
    nofe->extra_flags = (bitvector_t) oofe->extra_flags;
    nofe->weight = oofe->weight;
    nofe->timer = oofe->timer;
    nofe->bitvector = (bitvector_t) oofe->bitvector;
    memcpy(nofe->affected, oofe->affected,
           sizeof(struct obj_affected_type) * MAX_OBJ_AFFECT);

    /* Anything you've added that you need to copy over. */

  void make_conversion(FILE *infp, FILE *outfp) {
    struct rent_info tmp;
    struct obj_file_elem newobj;
    struct old_obj_file_elem oldobj;

    fread(&tmp, sizeof(struct rent_info), 1, infp);
    fwrite(&tmp, sizeof(struct rent_info), 1, outfp);

    while (!feof(fp)) {
      fread(&oldobj, sizeof(struct old_obj_file_elem), 1, infp);
      convert_old_to_new(&oldobj, &newobj);
      fwrite(&newobj, sizeof(struct obj_file_elem), 1, outfp);

  int main(int argc, char **argv) {
    char fname[256];
    FILE *outfp;
    FILE *infp;
    int i;

    if (argc < 2) {
      printf("Usage: %s <file1> [<file2> ... <fileN>]\n", argv[0]);
      return (1);

    for (i = 1; i < argc; i++) {
      sprintf(fname, "%s~", argv[i]);
      rename(argv[i], fname);

      if (!(infp = fopen(fname, "rb"))) {
      } else if (!(outfp = fopen(argv[i], "wb"))) {

      make_conversion(infp, outfp);

    return (0);

That's a little bit more rough than I had intended, but it should be
enough to get you started (fill in the blanks, verify that I haven't made
any glaring syntactical or conceptual errors, etc.).

Daniel A. Koepke (dak),
Caveat emptor: I say what I mean and mean what I say.  Listen well.
Caveat venditor: Say what you mean, mean what you say.  Say it well.

   | FAQ: |
   | Archives: |

This archive was generated by hypermail 2b30 : 12/05/01 PST