create food spell

From: Edward J Glamkowski (eglamkowski@angelfire.com)
Date: 05/16/02


It seemed rather boring to me that the create food spell only ever
created bread, given how many items have type ITEM_FOOD.  So I set
it up to pick a random food per casting :)


First, in db.c create two new variables:
obj_vnum *food_list;
int num_foods;

Add this function:
void init_food_list(void)
{
  obj_rnum i;
  int cnt;

  /* First we have to count how many food items so we can allocate
   * only as much space as need for the food array. */
  for (i = 0; i < top_of_objt; i++) {
    if (GET_OBJ_TYPE(&obj_proto[i]) == ITEM_FOOD)
      num_foods += 1;
  }

  /* Now allocate */
  if (num_foods) {
    CREATE(food_list, obj_vnum, num_foods);

    if (!food_list)
      return;

    /* And now go through and assign the values to the array */
    for (i = 0, cnt = 0; i < top_of_objt; i++) {
      if (GET_OBJ_TYPE(&obj_proto[i]) == ITEM_FOOD)
        food_list[cnt++] = GET_OBJ_VNUM(&obj_proto[i]);
    }
  }
}


at the end of boot_world(), add
  log("Initializing statics.");
  init_food_list();

and in destroy_db(), add
  if (food_list)
    free(food_list);


And then, move on over to magic.c, and at the top, add:
extern int num_foods;
extern obj_vnum *food_list;


then in mag_creations, replace the CREATE_FOOD case with
    case SPELL_CREATE_FOOD:
      if (!food_list)
        z = 10;
      else
        z = food_list[rand_number(0, num_foods - 1)];




Is your boss reading your email? ....Probably
Keep your messages private by using Lycos Mail.
Sign up today at http://mail.lycos.com

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT