sprintascii() patch for OasisOLC 2.0

From: Carlos Myers (dhstranger@hotmail.com)
Date: 07/01/01


Here is a patch file that I had sent to George eariler about some changes in
OasisOLC 2.0.  What this does is move sprintascii() from genwld.c to
genolc.c and allows genmob.c, genobj.c and genshp.c to use the function in
when they write to file.

I really didn't see the point in limiting the use of sprintascii() to
genwld.c. Especially since CircleMUD can use ASCII bitflags in mob, obj and
shop files as well.

Carlos

diff -upNB src-old/genmob.c src/genmob.c
--- src-old/genmob.c Mon Jun 18 15:47:22 2001
+++ src/genmob.c Mon Jun 18 15:51:22 2001
@@ -369,9 +369,11 @@ int write_mobile_record(mob_vnum mvnum,
  ldesc, STRING_TERMINATOR,
  ddesc, STRING_TERMINATOR
   );
-  fprintf(fd, "%ld %ld %d E\n"
+  sprintascii(buf1, MOB_FLAGS(mob));
+  sprintascii(buf2, AFF_FLAGS(mob));
+  fprintf(fd, "%s %s %d E\n"
   "%d %d %d %dd%d+%d %dd%d+%d\n",
-  MOB_FLAGS(mob), AFF_FLAGS(mob), GET_ALIGNMENT(mob),
+  buf1, buf2, GET_ALIGNMENT(mob),
   GET_LEVEL(mob), 20 - GET_HITROLL(mob), GET_AC(mob) / 10, GET_HIT(mob),
   GET_MANA(mob), GET_MOVE(mob), GET_NDD(mob), GET_SDD(mob),
   GET_DAMROLL(mob)
diff -upNB src-old/genobj.c src/genobj.c
--- src-old/genobj.c Mon Jun 18 15:47:22 2001
+++ src/genobj.c Mon Jun 18 16:40:54 2001
@@ -206,6 +206,7 @@ int save_objects(zone_rnum zone_num)
   FILE *fp;
   struct obj_data *obj;
   struct extra_descr_data *ex_desc;
+  char buf3[MAX_STRING_LENGTH];

   if (zone_num < 0 || zone_num > top_of_zone_table) {
     log("SYSERR: GenOLC: save_objects: Invalid real zone number %d. (0-%d)", zone_num, top_of_zone_table);
@@ -234,17 +235,24 @@ int save_objects(zone_rnum zone_num)
        "%s~\n"
        "%s~\n"
        "%s~\n"
-       "%s~\n"
-       "%d %d %d %ld\n"
-       "%d %d %d %d\n"
-       "%d %d %d %d\n",
+       "%s~\n",

        GET_OBJ_VNUM(obj),
        (obj->name && *obj->name) ? obj->name : "undefined",
        (obj->short_description && *obj->short_description) ? obj->short_description : "undefined",
        (obj->description && *obj->description) ? obj->description : "undefined",
-       buf1,
-       GET_OBJ_TYPE(obj), GET_OBJ_EXTRA(obj), GET_OBJ_WEAR(obj), GET_OBJ_PERM(obj),
+       buf1
+      );
+
+      sprintascii(buf1, GET_OBJ_EXTRA(obj));
+      sprintascii(buf2, GET_OBJ_WEAR(obj));
+      sprintascii(buf3, GET_OBJ_PERM(obj));
+      fprintf(fp,
+       "%d %s %s %s\n"
+       "%d %d %d %d\n"
+       "%d %d %d %d\n",
+
+       GET_OBJ_TYPE(obj), buf1, buf2, buf3,
        GET_OBJ_VAL(obj, 0), GET_OBJ_VAL(obj, 1), GET_OBJ_VAL(obj, 2), GET_OBJ_VAL(obj, 3),
        GET_OBJ_WEIGHT(obj), GET_OBJ_COST(obj), GET_OBJ_RENT(obj), GET_OBJ_LEVEL(obj)
       );
diff -upNB src-old/genolc.c src/genolc.c
--- src-old/genolc.c Mon Jun 18 15:47:22 2001
+++ src/genolc.c Mon Jun 18 15:49:22 2001
@@ -313,3 +313,23 @@ ACMD(do_edit)
     break;
   }
 }
+
+/* -------------------------------------------------------------------------- */
+
+int sprintascii(char *out, bitvector_t bits)
+{
+  int i, j = 0;
+  /* 32 bits, don't just add letters to try to get more unless your bitvector_t is also as large. */
+  char *flags="abcdefghijklmnopqrstuvwxyzABCDEF";
+
+  for (i = 0; flags[i] != '\0'; i++)
+    if (bits & (1 << i))
+      out[j++] = flags[i];
+
+  if (j == 0) /* Didn't write anything. */
+    out[j++] = '0';
+
+  /* NUL terminate the output string. */
+  out[j++] = '\0';
+  return j;
+}
diff -upNB src-old/genolc.h src/genolc.h
--- src-old/genolc.h Mon Jun 18 15:47:22 2001
+++ src/genolc.h Mon Jun 18 15:49:42 2001
@@ -28,6 +28,7 @@ int save_all(void);
 char *str_udup(const char *);
 void copy_ex_descriptions(struct extra_descr_data **to, struct extra_descr_data *from);
 void free_ex_descriptions(struct extra_descr_data *head);
+int sprintascii(char *out, bitvector_t bits);

 struct save_list_data {
   int zone;
diff -upNB src-old/genshp.c src/genshp.c
--- src-old/genshp.c Mon Jun 18 15:47:22 2001
+++ src/genshp.c Mon Jun 18 16:29:08 2001
@@ -457,9 +457,11 @@ int save_shops(zone_rnum zone_num)
        * Save messages'n'stuff.
        * Added some small'n'silly defaults as sanity checks.
        */
+      sprintascii(buf1, S_BITVECTOR(shop));
+      sprintascii(buf2, S_NOTRADE(shop));
       fprintf(shop_file,
        "%s~\n%s~\n%s~\n%s~\n%s~\n%s~\n%s~\n"
-       "%d\n%ld\n%d\n%d\n",
+       "%d\n%s\n%d\n%s\n",
        S_NOITEM1(shop) ? S_NOITEM1(shop) : "%s Ke?!",
        S_NOITEM2(shop) ? S_NOITEM2(shop) : "%s Ke?!",
        S_NOBUY(shop) ? S_NOBUY(shop) : "%s Ke?!",
@@ -468,9 +470,9 @@ int save_shops(zone_rnum zone_num)
        S_BUY(shop) ? S_BUY(shop) : "%s Ke?! %d?",
        S_SELL(shop) ? S_SELL(shop) : "%s Ke?! %d?",
        S_BROKE_TEMPER(shop),
-       S_BITVECTOR(shop),
+       buf1,
        mob_index[S_KEEPER(shop)].vnum,
-       S_NOTRADE(shop)
+       buf2
        );

       /*
diff -upNB src-old/genwld.c src/genwld.c
--- src-old/genwld.c Mon Jun 18 15:47:22 2001
+++ src/genwld.c Mon Jun 18 15:49:20 2001
@@ -25,24 +25,6 @@ extern room_rnum r_mortal_start_room;
 extern room_rnum r_immort_start_room;
 extern room_rnum r_frozen_start_room;

-int sprintascii(char *out, bitvector_t bits)
-{
-  int i, j = 0;
-  /* 32 bits, don't just add letters to try to get more unless your bitvector_t is also as large. */
-  char *flags="abcdefghijklmnopqrstuvwxyzABCDEF";
-
-  for (i = 0; flags[i] != '\0'; i++)
-    if (bits & (1 << i))
-      out[j++] = flags[i];
-
-  if (j == 0) /* Didn't write anything. */
-    out[j++] = '0';
-
-  /* NUL terminate the output string. */
-  out[j++] = '\0';
-  return j;
-}
-
 /*
  * This function will copy the strings so be sure you free your own
  * copies of the description, title, and such.

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



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