Adding Sector Types

Introduction

I wrote this guide to help people add in more sector types to their OLC, which as you can see is pretty simple. Just don't forget to change the number flags any time you add one. This code is written, tested, and works on stock tbaMUD. It may or may not work if your game is heavily modified or from an older version of CWG.

The Code

*** In constants.c scroll down to where it lists the basic sector types.
*** (Inside, City, Field, Forest, etc.) and add to the bottom of the list.

const char *sector_types[] = {
   "Inside",
   "City",
   "Field",
   "Forest",
   "Hills",
   "Mountains",
   "Water (Swim)",
   "Water (No Swim)",
   "In Flight",
   "Underwater",
+  "Desert",
   "\n",
 };

*** Further down in constants.c (under int movement_loss) you'll want to define how much
*** movement is lost per step with your new terrain type. 
*** Note: Make sure the last line doesn't have the comma after the number, but all the previous ones do.

 int movement_loss[] = 
 {
   1,    /* Inside     */
   1,    /* City       */
   2,    /* Field      */
   3,    /* Forest     */
   4,    /* Hills      */
   6,    /* Mountains  */
   4,    /* Swimming   */
   1,    /* Unswimable */
   1,    /* Flying     */
-  5     /* Underwater */
+ 5,    /* Underwater */
+ 3     /* Desert */   
 };

*** In structs.h scroll down to where the list is again, for basic sector types.

  /* Sector types: used in room_data.sector_type */
  #define SECT_INSIDE          0          /**< Indoors, connected to SECT macro. */
  #define SECT_CITY            1          /**< In a city                  */
  #define SECT_FIELD           2          /**< In a field         */
  #define SECT_FOREST          3          /**< In a forest                */
  #define SECT_HILLS           4          /**< In the hills               */
  #define SECT_MOUNTAIN        5          /**< On a mountain              */
  #define SECT_WATER_SWIM      6          /**< Swimmable water            */
  #define SECT_WATER_NOSWIM    7          /**< Water - need a boat        */
  #define SECT_FLYING          8          /**< Flying                     */
  #define SECT_UNDERWATER      9          /**< Underwater                 */
+ #define SECT_DESERT         10          /**< Desert                     */

*** Be sure to bump up NUM_SPELLS by 1
+ #define NUM_ROOM_SECTORS 11

*** In asciimap.c scroll down to the first instance of sector types. 
*** At the next -1 at the bottom fill in your new sector type.

 static struct map_info_type map_info[] =
 {
   { SECT_INSIDE,       "@c[@n.@c]@n" }, /* 0 */
   { SECT_CITY,         "@c[@wC@c]@n" },
   { SECT_FIELD,        "@c[@g,@c]@n" },
   { SECT_FOREST,       "@c[@gY@c]@n" },
   { SECT_HILLS,        "@c[@Mm@c]@n" },
   { SECT_MOUNTAIN,     "@c[@rM@c]@n" }, /* 5 */
   { SECT_WATER_SWIM,   "@c[@c~@c]@n" },
   { SECT_WATER_NOSWIM, "@c[@b=@c]@n" },
   { SECT_FLYING,       "@c[@C^@c]@n" },
   { SECT_UNDERWATER,   "@c[@bU@c]@n" },
-  { -1,                           "" }, /* 10 */
+  { SECT_DESERT,       "@c[@Y-@c]@n" }, /* 10 */

*** Scroll down a bit more to the next set and do the same.
*** Since we used @Y- for the symbol above, use it again here.

 static struct map_info_type world_map_info[] =
 {
   { SECT_INSIDE,       "@n."  }, /* 0 */
   { SECT_CITY,         "@wC"  },
   { SECT_FIELD,        "@g,"  },
   { SECT_FOREST,       "@gY"  },
   { SECT_HILLS,        "@Mm"  },
   { SECT_MOUNTAIN,     "@rM"  }, /* 5 */
   { SECT_WATER_SWIM,   "@c~"  },
   { SECT_WATER_NOSWIM, "@b="  },
   { SECT_FLYING,       "@C^"  },
   { SECT_UNDERWATER,   "@bU"  },
-  { -1,                   ""  }, /* 10 */
+  { SECT_DESERT,       "@y-"  }, /* 10 */

*** Finally, jump down even more to where they're listed again like this, and add your new sector.

   count += sprintf(buf + count, "@n%s Swim\\\\", map_info[SECT_WATER_SWIM].disp);
   count += sprintf(buf + count, "@n%s Boat\\\\", map_info[SECT_WATER_NOSWIM].disp);
   count += sprintf(buf + count, "@n%s Flying\\\\", map_info[SECT_FLYING].disp);
   count += sprintf(buf + count, "@n%s Underwater\\\\", map_info[SECT_UNDERWATER].disp);
+  count += sprintf(buf + count, "@n%s Desert\\\\", map_info[SECT_DESERT].disp);

Comments

Query about sector movements

That part where it says:
*** Be sure to bump up NUM_SPELLS by 1
+ #define NUM_SPELLS 11

Is that supposed to be: #define NUM_ROOM_SECTORS 10 ?

The other thing I'm wondering is: besides maps and names, isn't there anything else that sector types affect? What happens to the other part of constants.c (line 763 in stock):

/** How much movement is lost moving through a particular sector type. */

when there's nothing input? Also, along with movement points, I would think desert should also affect thirst. Would that be hard to do?

My apologies if I seem to be making this more difficult than it should be.

Thanks for the catch!

You're absolutely right. I have no idea where I got that from, I think it was leftover from when I was copying the format from a previous guide I wrote. (Or maybe I shouldn't drink and code...!)

It should read NUM_ROOM_SECTORS (+1 to whatever number was there before because you're adding one to it.)

It's listed as 11 because the last one there was 10. I believe the technical reason for it being one higher than the last is because the first one up there is listed as 0. Some parts of the code are like that.

I'm going to look into the other part of constants.c for your other question.

No, you're absolutely right. I have no idea where I got that from, I think it was leftover from when I was copying the format. (Or maybe I shouldn't drink and code...!)

It should read NUM_ROOM_SECTORS (+1 to whatever number was there before because you're adding one) and I'll get in there and change it right now. Another way to make sure you've got the right number in that particular part of the code is to just add one on top of the last one listed. If it's 15, the NUM_ROOM_SECTORS would be 16, etc. I believe the technical reason for it being one number higher is because the first sector up there is listed as 0. Some parts of the code are like that.

As far as the movement in the other part of constants.c, that was an oversight on my part which I'll rectify here shortly. This is partially why I made this guide, because sometimes with even the simple code changes it's easy to make mistakes and overlook things. I remember the first time I ever changed sectors on Rasputin I was totally lost because I didn't know I was supposed to change a flag number, heh. In any case though, even with that oversight the code should compile and run fine, although I don't recommend it unless you want players running through sectors without movement points being deducted.

Also, no worries at all. It's nice to know someone was paying attention, it helps the guide out when I can fix any errors! Thanks for letting me know so I can adjust them.